33#include "gdbsupport/pathstuff.h"
34#include "gdbsupport/gdb_tilde_expand.h"
42#include "readline/readline.h"
73 N_(
"Kernel memory interface"),
74 N_(
"Use a kernel virtual memory image as a target.\n\
75Optionally specify the filename of a core dump.")
86 void close ()
override;
92 const gdb_byte *writebuf,
93 ULONGEST offset, ULONGEST len,
94 ULONGEST *xfered_len)
override;
111 char errbuf[_POSIX2_LINE_MAX];
112 const char *execfile = NULL;
114 std::string filename;
120 filename = gdb_tilde_expand (arg);
121 if (!IS_ABSOLUTE_PATH (filename))
122 filename = gdb_abspath (filename.c_str ());
126 temp_kd = kvm_openfiles (execfile, filename.c_str (), NULL,
129 error ((
"%s"), errbuf);
151 warning ((
"%s"), kvm_geterr(
core_kd));
162 gdb_byte *readbuf,
const gdb_byte *writebuf)
164 ssize_t nbytes = len;
167 nbytes = kvm_read (
core_kd, addr, readbuf, nbytes);
168 if (writebuf && nbytes > 0)
169 nbytes = kvm_write (
core_kd, addr, writebuf, nbytes);
175 const char *annex, gdb_byte *readbuf,
176 const gdb_byte *writebuf,
177 ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
191 *xfered_len = (ULONGEST) ret;
205 gdb_printf (_(
"\tUsing the kernel crash dump %s.\n"),
208 gdb_printf (_(
"\tUsing the currently running kernel.\n"));
218 if (kvm_read (
core_kd, (
unsigned long) paddr, &pcb,
sizeof pcb) == -1)
219 error ((
"%s"), kvm_geterr (
core_kd));
238 memset (nl, 0,
sizeof nl);
239 nl[0].n_name = (
char *)
"_dumppcb";
241 if (kvm_nlist (
core_kd, nl) == -1)
242 error ((
"%s"), kvm_geterr (
core_kd));
244 if (nl[0].n_value != 0)
256 memset (nl, 0,
sizeof nl);
257 nl[0].n_name = (
char *)
"_proc0paddr";
259 if (kvm_nlist (
core_kd, nl) == -1)
260 error ((
"%s"), kvm_geterr (
core_kd));
262 if (nl[0].n_value != 0)
267 if (kvm_read (
core_kd, nl[0].n_value, &paddr,
sizeof paddr) == -1)
268 error ((
"%s"), kvm_geterr (
core_kd));
274#ifdef HAVE_STRUCT_THREAD_TD_PCB
280 memset (nl, 0,
sizeof nl);
281 nl[0].n_name = (
char *)
"_thread0";
283 if (kvm_nlist (
core_kd, nl) == -1)
284 error ((
"%s"), kvm_geterr (
core_kd));
286 if (nl[0].n_value != 0)
291 nl[0].n_value += offsetof (
struct thread, td_pcb);
292 if (kvm_read (
core_kd, nl[0].n_value, &paddr,
sizeof paddr) == -1)
293 error ((
"%s"), kvm_geterr (
core_kd));
301 error (_(
"Cannot find a valid PCB"));
314#ifndef HAVE_STRUCT_THREAD_TD_PCB
325 error (_(
"No kernel memory image."));
328#ifdef HAVE_STRUCT_LWP
329 addr += offsetof (
struct lwp, l_addr);
331 addr += offsetof (
struct proc, p_addr);
335 error ((
"%s"), kvm_geterr (
core_kd));
353 error (_(
"No kernel memory image."));
388Generic command for manipulating the kernel memory interface."),
391#ifndef HAVE_STRUCT_THREAD_TD_PCB
static int(* bsd_kvm_supply_pcb)(struct regcache *regcache, struct pcb *pcb)
static void bsd_kvm_proc_cmd(const char *arg, int fromtty)
static std::string bsd_kvm_corefile
static LONGEST bsd_kvm_xfer_memory(CORE_ADDR addr, ULONGEST len, gdb_byte *readbuf, const gdb_byte *writebuf)
static int bsd_kvm_fetch_pcb(struct regcache *regcache, struct pcb *paddr)
void bsd_kvm_add_target(int(*supply_pcb)(struct regcache *, struct pcb *))
static ptid_t bsd_kvm_ptid
struct cmd_list_element * bsd_kvm_cmdlist
static const target_info bsd_kvm_target_info
static void bsd_kvm_cmd(const char *arg, int fromtty)
static void bsd_kvm_pcb_cmd(const char *arg, int fromtty)
static bsd_kvm_target bsd_kvm_ops
static struct pcb * bsd_kvm_paddr
static void bsd_kvm_target_open(const char *arg, int from_tty)
const target_info & info() const override
bool thread_alive(ptid_t ptid) override
void files_info() override
void fetch_registers(struct regcache *, int) override
bool has_stack() override
std::string pid_to_str(ptid_t) override
bool has_memory() override
enum target_xfer_status xfer_partial(enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len) override
bool has_registers() override
int unpush_target(struct target_ops *t)
void push_target(struct target_ops *t)
void error_no_arg(const char *why)
struct cmd_list_element * cmdlist
struct cmd_list_element * add_cmd(const char *name, enum command_class theclass, const char *doc, struct cmd_list_element **list)
struct cmd_list_element * add_prefix_cmd(const char *name, enum command_class theclass, cmd_simple_func_ftype *fun, const char *doc, struct cmd_list_element **subcommands, int allow_unknown, struct cmd_list_element **list)
const char * get_exec_file(int err)
CORE_ADDR parse_and_eval_address(const char *exp)
void reinit_frame_cache(void)
frame_info_ptr get_selected_frame(const char *message)
void print_stack_frame(frame_info_ptr, int print_level, enum print_what print_what, int set_current_sal)
struct thread_info * add_thread_silent(process_stratum_target *targ, ptid_t ptid)
void switch_to_thread(struct thread_info *thr)
void switch_to_no_thread()
struct inferior * current_inferior(void)
void exit_inferior(struct inferior *inf)
struct regcache * get_current_regcache(void)
void target_fetch_registers(struct regcache *regcache, int regno)
void add_target(const target_info &t, target_open_ftype *func, completer_ftype *completer)
void target_preopen(int from_tty)
void gdb_printf(struct ui_file *stream, const char *format,...)