24 #include <sys/types.h>
26 #include <sys/select.h>
65 static int gdb_snprintf(
struct target *
target,
char *buf,
int bufsiz);
68 static int gdb_detach(
struct target *
target,
int stay_paused);
82 int *again,
void *priv);
92 gdb_lookup_overlay_thread_by_id(
struct target *
target,
int id);
95 static int gdb_attach_overlay_thread(
struct target *base,
struct target *overlay,
97 static int gdb_detach_overlay_thread(
struct target *base,
struct target *overlay,
102 static int __gdb_resume(
struct target *
target,
int detaching);
110 unsigned long length,
unsigned char *buf);
112 unsigned long length,
unsigned char *buf);
116 unsigned long length,
unsigned char *buf);
118 unsigned long length,
unsigned char *buf);
127 static int gdb_load_all_threads(
struct target *
target,
int force);
128 static int gdb_load_available_threads(
struct target *
target,
int force);
135 static int gdb_flush_current_thread(
struct target *
target);
136 static int gdb_flush_all_threads(
struct target *
target);
141 char *buf,
int bufsiz,
142 int detail,
char *sep,
char *key_val_sep);
156 unsigned char *code,
unsigned long code_len);
173 struct target *overlay);
175 struct target *overlay);
200 .attach = gdb_attach_internal,
201 .detach = gdb_detach,
206 .loadspaces = gdb_loadspaces,
207 .loadregions = gdb_loadregions,
208 .loaddebugfiles = gdb_loaddebugfiles,
209 .postloadinit = gdb_postloadinit,
210 .postopened = gdb_postopened,
211 .set_active_probing = gdb_set_active_probing,
213 .handle_exception = gdb_handle_exception,
220 .build_default_overlay_spec = gdb_build_default_overlay_spec,
221 .instantiate_overlay = gdb_instantiate_overlay,
222 .lookup_overlay_thread_by_id = gdb_lookup_overlay_thread_by_id,
223 .lookup_overlay_thread_by_name = gdb_lookup_overlay_thread_by_name,
224 .attach_overlay_thread = gdb_attach_overlay_thread,
225 .detach_overlay_thread = gdb_detach_overlay_thread,
227 .status = gdb_status,
229 .resume = gdb_resume,
230 .monitor = gdb_monitor,
235 .addr_v2p = gdb_addr_v2p,
236 .read_phys = gdb_read_phys,
237 .write_phys = gdb_write_phys,
239 .gettid = gdb_gettid,
240 .free_thread_state = gdb_free_thread_state,
241 .list_available_tids = gdb_list_available_tids,
242 .load_available_threads = gdb_load_available_threads,
243 .load_thread = gdb_load_thread,
244 .load_current_thread = gdb_load_current_thread,
245 .load_all_threads = gdb_load_all_threads,
246 .pause_thread = NULL,
247 .flush_thread = gdb_flush_thread,
248 .flush_current_thread = gdb_flush_current_thread,
249 .flush_all_threads = gdb_flush_all_threads,
250 .invalidate_thread = gdb_invalidate_thread,
251 .thread_snprintf = gdb_thread_snprintf,
253 .attach_evloop = gdb_attach_evloop,
254 .detach_evloop = gdb_detach_evloop,
262 .insert_sw_breakpoint = gdb_insert_sw_breakpoint,
263 .remove_sw_breakpoint = gdb_remove_sw_breakpoint,
264 .change_sw_breakpoint = gdb_change_sw_breakpoint,
265 .unchange_sw_breakpoint = gdb_unchange_sw_breakpoint,
266 .enable_sw_breakpoint = gdb_enable_sw_breakpoint,
267 .disable_sw_breakpoint = gdb_disable_sw_breakpoint,
269 .set_hw_breakpoint = gdb_set_hw_breakpoint,
270 .set_hw_watchpoint = gdb_set_hw_watchpoint,
271 .unset_hw_breakpoint = gdb_unset_hw_breakpoint,
272 .unset_hw_watchpoint = gdb_unset_hw_watchpoint,
273 .disable_hw_breakpoints = gdb_disable_hw_breakpoints,
274 .enable_hw_breakpoints = gdb_enable_hw_breakpoints,
275 .disable_hw_breakpoint = gdb_disable_hw_breakpoint,
276 .enable_hw_breakpoint = gdb_enable_hw_breakpoint,
278 .singlestep = gdb_singlestep,
279 .singlestep_end = gdb_singlestep_end,
285 #define GDB_ARGP_HOST 0x650001
286 #define GDB_ARGP_PORT 0x650002
287 #define GDB_ARGP_UDP 0x650003
288 #define GDB_ARGP_SOCKFILE 0x650004
289 #define GDB_ARGP_IS_KVM 0x650005
290 #define GDB_ARGP_IS_QEMU 0x650006
291 #define GDB_ARGP_QEMU_QMP_HOST 0x650007
292 #define GDB_ARGP_QEMU_MEM_PATH 0x650008
293 #define GDB_ARGP_QEMU_QMP_PORT 0x650009
294 #define GDB_ARGP_CLEAR_MEM_CACHES 0x65000a
295 #define GDB_ARGP_MEMCACHE_MMAP_SIZE 0x65000b
296 #define GDB_ARGP_LIBVIRT_DOMAIN 0x65000c
301 "The hostname the GDB stub is listening on (default localhost).",-4 },
303 "The port the GDB stub is listening on (default 1234).",-4 },
305 "Use UDP instead of TCP (default TCP).",-4 },
307 "The UNIX domain socket filename the GDB stub is listening on.",-4 },
308 {
"main-filename",
'M',
"FILE",0,
309 "Set main binary's filepath for target.",-4 },
311 "Clear mem caches on each debug exception.",-4 },
313 "Enable QEMU GDB stub support",-4 },
315 "Attach to QEMU QMP on the given host (default localhost).",-4 },
317 "Attach to QEMU QMP on the given port (default 1235).",-4 },
319 "Read/write QEMU's physical memory via this filename (see QEMU's -mem-path option; also preload libnunlink.so and set NUNLINK_PREFIX accordingly).",-4 },
320 #ifdef ENABLE_LIBVIRT
322 "Access QEMU QMP over libvirt proxy.",-4 },
325 "Enable QEMU GDB KVM stub support.",-4 },
327 "Max size (bytes) of the mmap cache (default 128MB).",-4 },
367 #ifdef ENABLE_LIBVIRT
376 av =
calloc(ac + 1,
sizeof(
char *));
379 av[j++] = strdup(
"--gdb-host");
382 if (xspec->
port > -1) {
383 av[j++] = strdup(
"--gdb-port");
385 snprintf(av[j],16,
"%d",xspec->
port);
389 av[j++] = strdup(
"--gdb-udp");
392 av[j++] = strdup(
"--gdb-sockfile");
396 av[j++] = strdup(
"-M");
400 av[j++] = strdup(
"--clear-mem-caches-each-exception");
403 av[j++] = strdup(
"--qemu");
405 av[j++] = strdup(
"--qemu-qmp-host");
409 av[j++] = strdup(
"--qemu-qmp-port");
415 av[j++] = strdup(
"--qemu-mem-path");
418 #ifdef ENABLE_LIBVIRT
420 av[j++] = strdup(
"--qemu-libvirt-domain");
425 av[j++] = strdup(
"--kvm");
427 av[j++] = strdup(
"--memcache-mmap-size");
447 struct argp_option *opti;
450 if (key == ARGP_KEY_INIT)
452 else if (!state->input)
453 return ARGP_ERR_UNKNOWN;
466 if (key == opti->key) {
479 verror(
"cannot mix arguments for GDB target (%c) with non-GDB"
487 xspec =
calloc(1,
sizeof(*xspec));
491 verror(
"cannot mix arguments for GDB target with non-GDB target!\n");
497 xspec = (
struct gdb_spec *)spec->backend_spec;
505 return ARGP_ERR_UNKNOWN;
508 case ARGP_KEY_NO_ARGS:
511 case ARGP_KEY_SUCCESS:
518 xspec->hostname = strdup(arg);
521 xspec->port = atoi(arg);
527 xspec->sockfile = strdup(arg);
530 xspec->main_filename = strdup(arg);
533 xspec->clear_mem_caches_each_exception = 1;
539 xspec->qemu_qmp_hostname = strdup(arg);
542 xspec->qemu_qmp_port = atoi(arg);
545 xspec->qemu_mem_path = strdup(arg);
547 #ifdef ENABLE_LIBVIRT
549 xspec->qemu_libvirt_domain = strdup(arg);
556 xspec->memcache_mmap_size = atoi(arg);
559 return ARGP_ERR_UNKNOWN;
577 xspec =
calloc(1,
sizeof(*xspec));
596 return gdb_attach(spec,evloop);
621 memset(xstate,0,
sizeof(*xstate));
623 xstate->need_ack = 1;
625 xstate->fd = xstate->wfd = -1;
629 xstate->evloop_fd = -1;
632 g_hash_table_insert(
target->
config,strdup(
"MAIN_FILENAME"),
648 "autoinitialized the os_linux_generic personality!\n");
651 verror(
"failed to autoinitialize the os_linux_generic personality!\n");
656 vwarn(
"cannot initialize a personality!\n");
668 if (!xstate->hops && xspec->
is_qemu)
670 else if (!xstate->hops)
673 if (xstate->hops->init) {
674 if (xstate->hops->init(
target)) {
675 verror(
"failed to init hops!\n");
683 if (evloop && xstate->evloop_fd < 0) {
695 if (xstate->ostype) {
696 free(xstate->ostype);
697 xstate->ostype = NULL;
710 static int gdb_snprintf(
struct target *
target,
char *buf,
int bufsiz) {
715 return snprintf(buf,bufsiz,
"gdbstub@udp(%s::%d)",
718 return snprintf(buf,bufsiz,
"gdbstub@unix(%s)",
721 return snprintf(buf,bufsiz,
"gdbstub@tcp(%s::%d)",
724 return snprintf(buf,bufsiz,
"gdbstub@unknown");
727 static int gdb_init(
struct target *target) {
734 vwarn(
"auto-enabling SEMI_STRICT bpmode on GDB target %s\n",target->
name);
747 g_hash_table_new_full(g_str_hash,g_str_equal,
free,
free);
763 static int gdb_attach_internal(
struct target *target) {
774 if (gdb_pause(target,0)) {
775 vwarn(
"could not pause target before attaching; continuing anyway!\n");
783 verror(
"could not attach hops!\n");
789 gdb_attach_evloop(target,target->
evloop);
795 static int gdb_detach(
struct target *target,
int stay_paused) {
799 "preparing to detach from GDB stub (target %s)\n",target->
name);
814 gdb_detach_evloop(target);
818 verror(
"failed to fini hops; continuing anyway (target %s)!\n",
836 verror(
"failed to detach from GDB stub (target %s)!\n",target->
name);
843 static int gdb_fini(
struct target *target) {
871 static int gdb_loadspaces(
struct target *target) {
885 static int gdb_loadregions(
struct target *target,
struct addrspace *space) {
893 (
char *)g_hash_table_lookup(target->
config,
"MAIN_FILENAME");
910 static int gdb_loaddebugfiles(
struct target *target,
struct addrspace *space,
929 if (!region->
name || strlen(region->
name) == 0)
977 static int gdb_postloadinit(
struct target *target) {
1001 char *start = (
char *)g_hash_table_lookup(target->
config,
1002 "OS_KERNEL_START_ADDR");
1011 static int gdb_postopened(
struct target *target) {
1017 static int gdb_set_active_probing(
struct target *target,
1025 gdb_build_default_overlay_spec(
struct target *target,
tid_t tid) {
1034 static struct target *
1035 gdb_instantiate_overlay(
struct target *target,
1039 struct target *overlay;
1068 verror(
"could not load group_leader for thread %d; BUG?!\n",tthread->
tid);
1071 else if (leader != tthread) {
1073 "using group_leader %d instead of user-supplied overlay thread %d\n",
1074 leader->
tid,tthread->
tid);
1087 gdb_lookup_overlay_thread_by_id(
struct target *target,
int id) {
1090 retval = gdb_load_thread(target,
id,0);
1099 "found overlay thread %d\n",
id);
1103 verror(
"tid %d matched %d, but is a kernel thread!\n",retval->
tid,
id);
1110 gdb_lookup_overlay_thread_by_name(
struct target *target,
char *
name) {
1115 GHashTableIter iter;
1117 if ((rc = gdb_load_available_threads(target,0)))
1118 vwarn(
"could not load %d threads; continuing anyway!\n",-rc);
1120 g_hash_table_iter_init(&iter,target->
threads);
1121 while (g_hash_table_iter_next(&iter,NULL,(gpointer)&tthread)) {
1125 if (!tthread->name) {
1126 vwarn(
"tid %d does not have a name; continuing!\n",
1131 slen = strlen(tthread->name);
1133 "checking task with name '%*s' against '%s'\n",
1134 slen,tthread->name,name);
1135 if (strncmp(name,tthread->name,slen) == 0) {
1143 verror(
"tid %d matched '%s', but is a kernel thread!\n",
1150 "found overlay thread %"PRIiTID"\n",retval->
tid);
1160 static int gdb_attach_overlay_thread(
struct target *base,
struct target *overlay,
1167 if (nltid == -1 || cltid == -1)
1177 static int gdb_detach_overlay_thread(
struct target *base,
struct target *overlay,
1182 static int __gdb_in_userspace(
struct target *target,
int cpl,
REGVAL ipval) {
1206 static int __gdb_get_cpl_thread(
struct target *target,
1220 verror(
"could not read CS register to find CPL!\n");
1227 static int __gdb_get_cpl(
struct target *target,
tid_t tid) {
1230 if (!(tthread = __gdb_load_cached_thread(target,tid))) {
1237 return __gdb_get_cpl_thread(target,tthread);
1242 int *again,
void *priv) {
1254 tstatus = gdb_status(target);
1256 vwarn(
"failed to load status for GDB stub (target %s);"
1257 " returning to user!\n",target->
name);
1261 vwarn(
"unknown status for GDB stub (target %s);"
1262 " returning to user!\n",target->
name);
1266 vwarn(
"%s is running; ignoring\n",target->
name);
1283 if (!__gdb_load_current_thread(target,0,1)) {
1284 verror(
"could not load global thread!\n");
1295 verror(
"could not read CPL while checking debug event: %s\n",
1301 verror(
"could not read EIP while checking debug event: %s\n",
1323 gdb_load_current_thread(target,0);
1328 verror(
"could not load current thread!\n");
1334 if (__gdb_in_userspace(target,cpl,ipval)) {
1337 "; will try to handle it!\n",ipval,tid);
1341 "thread %d at IP 0x%"PRIxADDR"\n",tid,ipval);
1344 verror(
"bad GDB status %d; aborting!\n",tstatus);
1351 switch (ss->reason) {
1356 if (ss->signal == SIGTRAP) {
1371 "found hw break on 0x%"PRIxADDR"\n",ipval);
1379 "found sw break on 0x%"PRIxADDR"\n",ipval);
1383 "did not find hw/sw break; must be step!\n");
1412 vwarn(
"could not find hardware bp and not sstep'ing;"
1413 " letting user handle fault at 0x%"PRIxADDR"!\n",ipval);
1417 vwarn(
"target %s signaled unexpectedly with %lu; ignoring!\n",
1418 target->
name,ss->signal);
1439 verror(
"bad GDB stop status %d; aborting!\n",ss->reason);
1480 "current GDB stub (%s) status is valid\n",target->
name);
1486 verror(
"could not load status for target %s\n",target->
name);
1497 static int gdb_pause(
struct target *target,
int nowait) {
1499 struct timeval check_tv = { 0,0};
1506 status = gdb_status(target);
1508 vwarn(
"failed to load status for GDB stub (target %s);"
1509 " trying to pause anyway!\n",target->
name);
1511 vwarn(
"unknown status for GDB stub (target %s);"
1512 " trying to pause anyway!\n",target->
name);
1515 verror(
"could not pause target %s!\n",target->
name);
1561 gdb_poll(target,&check_tv,&outcome,&pstatus);
1566 static int __gdb_resume(
struct target *target,
int detaching) {
1573 status = gdb_status(target);
1575 vwarn(
"failed to load status for GDB stub (target %s);"
1576 " trying to resume anyway!\n",target->
name);
1578 vwarn(
"unknown status for GDB stub (target %s);"
1579 " trying to resume anyway!\n",target->
name);
1582 vwarn(
"not paused; not invalidating and resuming; BUG?\n");
1611 "machine dirty; writing %d regs!\n",rc);
1615 verror(
"could not write CPU regs!\n");
1622 "machine state not dirty; not writing regs!\n");
1634 if (gstate->
fd < 0) {
1635 verror(
"cannot resume; disconnected!\n");
1646 static int gdb_resume(
struct target *target) {
1647 return __gdb_resume(target,0);
1659 if (gstate->
fd < 0) {
1660 verror(
"server disconnected!\n");
1667 FD_SET(gstate->
fd,&inset);
1670 ret = select(gstate->
fd + 1,&inset,NULL,NULL,&tv);
1674 if (!FD_ISSET(gstate->
fd,&inset))
1681 retval = gdb_handle_exception(target,0,&again,NULL);
1691 __gdb_resume(target,0);
1712 static target_status_t gdb_poll(
struct target *target,
struct timeval *tv,
1731 ret = select(
fd+1,&inset,NULL,NULL,tv);
1738 if (!FD_ISSET(
fd, &inset)) {
1745 retval = gdb_handle_exception(target,0,&again,NULL);
1753 struct target *target = (
struct target *)state;
1762 retval = gdb_handle_exception(target,0,&again,NULL);
1772 __gdb_resume(target,0);
1777 int gdb_attach_evloop(
struct target *target,
struct evloop *evloop) {
1781 verror(
"no evloop attached!\n");
1791 "added evloop readfd %d event channel\n",xstate->
evloop_fd);
1796 static int gdb_detach_evloop(
struct target *target) {
1809 tid_t gdb_gettid(
struct target *target) {
1815 tthread = gdb_load_current_thread(target,0);
1817 verror(
"could not load current thread to get TID!\n");
1821 return tthread->
tid;
1824 void gdb_free_thread_state(
struct target *target,
void *
state) {
1829 static struct target_thread *__gdb_load_cached_thread(
struct target *target,
1838 return gdb_load_thread(target,tid,0);
1843 static struct target_thread *__gdb_load_current_thread(
struct target *target,
1860 if (globalonly && !force
1867 else if (!globalonly && !force
1872 verror(
"target not paused; cannot load current thread!\n");
1886 verror(
"could not read CPU regs!\n");
1898 vwarn(
"helper ops load_machine failed!\n");
1935 verror(
"could not read IP from machine state!\n");
1940 verror(
"could not read IP from machine state!\n");
1948 if (__gdb_in_userspace(target,cpl,ipval))
1969 vwarn(
"not supported yet!!!\n");
2027 vwarn(
"personality set current thread context to %d; global thread"
2028 " context is %d; forcing current to global!\n",
2039 tthread->
state = tstate = \
2064 vwarn(
"error loading current thread; trying to use default thread\n");
2070 static struct target_thread *gdb_load_current_thread(
struct target *target,
2072 return __gdb_load_current_thread(target,force,0);
2075 static struct target_thread *gdb_load_thread(
struct target *target,
2076 tid_t tid,
int force) {
2095 gdb_load_current_thread(target,force);
2106 if (!gdb_load_current_thread(target,force)) {
2107 vwarn(
"could not load current thread to compare with"
2118 return gdb_load_current_thread(target,force);
2126 "did not need to load thread; copy is valid\n");
2145 static struct array_list *gdb_list_available_tids(
struct target *target) {
2151 static int gdb_load_all_threads(
struct target *target,
int force) {
2159 for (i = 0; i < array_list_len(cthreads); ++
i) {
2160 tthread = (
struct target_thread *)array_list_item(cthreads,i);
2163 "tid %"PRIiTID" (%p)\n",tthread->
tid,tthread);
2165 if (!gdb_load_thread(target,tthread->
tid,force)) {
2182 static int gdb_load_available_threads(
struct target *target,
int force) {
2190 if (!__gdb_load_current_thread(target,force,1)) {
2191 verror(
"could not load current thread!\n");
2204 static int gdb_flush_global_thread(
struct target *target,
2215 verror(
"global thread not loaded; BUG!!!\n");
2224 "%s tid %"PRIiTID" not valid (%d) or not dirty (%d)\n",
2230 verror(
"target %s not writeable!\n",target->
name);
2238 ipval,target->
name,tid);
2245 verror(
"failed to copy dirty regs from %s tid %d tidctxt %d to machine!\n",
2252 vwarn(
"failed to mark %s tid %d tidctxt %d flushed!\n",
2262 static int gdb_flush_current_thread(
struct target *target) {
2269 verror(
"current thread not loaded!\n");
2285 "%s tid %"PRIiTID" not valid (%d) or not dirty (%d)\n",
2291 verror(
"target %s not writeable!\n",target->
name);
2305 verror(
"failed to copy dirty regs from %s tid %d tidctxt %d to machine!\n",
2312 vwarn(
"failed to mark %s tid %d tidctxt %d flushed!\n",
2320 static int gdb_flush_thread(
struct target *target,
tid_t tid) {
2331 return gdb_flush_current_thread(target);
2347 "current thread not loaded to compare with"
2348 " tid %"PRIiTID
"; exiting, user-mode EIP, or BUG?\n",
2353 "current thread not valid to compare with"
2354 " tid %"PRIiTID
"; exiting, user-mode EIP, or BUG?\n",
2363 return gdb_flush_current_thread(target);
2371 verror(
"cannot flush unknown thread %"PRIiTID
"; you forgot to load?\n",
2378 return gdb_flush_current_thread(target);
2382 "%s tid %"PRIiTID
" not valid (%d) or not dirty (%d)\n",
2388 verror(
"target %s not writeable!\n",target->
name);
2405 static int gdb_flush_all_threads(
struct target *target) {
2407 GHashTableIter iter;
2411 g_hash_table_iter_init(&iter,target->
threads);
2412 while (g_hash_table_iter_next(&iter,NULL,(gpointer)&tthread)) {
2417 rc = gdb_flush_thread(target,tthread->tid);
2419 verror(
"could not flush thread %"PRIiTID
"\n",tthread->tid);
2440 rc = gdb_flush_current_thread(target);
2442 verror(
"could not flush current thread %"PRIiTID
"\n",
2470 rc = gdb_flush_global_thread(target,current_thread);
2479 static int gdb_invalidate_thread(
struct target *target,
2486 static int gdb_thread_snprintf(
struct target *target,
2488 char *buf,
int bufsiz,
2489 int detail,
char *sep,
char *kvsep) {
2495 buf,bufsiz,detail,sep,kvsep,0);
2501 (rc >= bufsiz) ? NULL : buf + rc,
2502 (rc >= bufsiz) ? 0 : bufsiz - rc,
2505 verror(
"could not snprintf personality info for thread %d!\n",
2513 static unsigned char *gdb_read(
struct target *target,
ADDR addr,
2514 unsigned long length,
unsigned char *buf) {
2533 static unsigned long gdb_write(
struct target *target,
ADDR addr,
2534 unsigned long length,
unsigned char *buf) {
2546 verror(
"target %s not writeable!\n",target->
name);
2568 static int __gdb_pgd(
struct target *target,
tid_t tid,uint64_t *pgd) {
2573 REGVAL cr0 = 0,cr3 = 0,cr4 = 0,msr_efer = 0,cpuid_edx = 0;
2579 tthread = __gdb_load_current_thread(target,0,1);
2581 verror(
"could not load global thread!\n");
2626 verror(
"could not determine v2p_flags! pgd walks might fail;"
2627 " assuming 64-bit long mode and paging!\n");
2631 verror(
"could not determine v2p_flags! pgd walks might fail;"
2632 " assuming 32-bit mode and PAE (and auto-PSE)!\n");
2650 tthread = gdb_load_thread(target,tid,0);
2652 verror(
"could not load tid %"PRIiTID
"!\n",tid);
2657 verror(
"could not get phys pgd for tid %"PRIiTID
": %s!\n",
2658 tid,strerror(errno));
2664 "tid %"PRIiTID
" pgd (phys) = 0x%"PRIx64
"\n",tid,*pgd);
2669 static int gdb_addr_v2p(
struct target *target,
tid_t tid,
2676 if (__gdb_pgd(target,tid,&pgd)) {
2677 verror(
"could not read pgd for tid %"PRIiTID
"!\n",tid);
2686 return xstate->
hops->
addr_v2p(target,tid,pgd,vaddr,paddr);
2689 static unsigned char *gdb_read_phys(
struct target *target,
ADDR paddr,
2690 unsigned long length,
unsigned char *buf) {
2703 static unsigned long gdb_write_phys(
struct target *target,
ADDR paddr,
2704 unsigned long length,
unsigned char *buf) {
2715 verror(
"target %s not writeable!\n",target->
name);
2723 static struct target_memmod *gdb_insert_sw_breakpoint(
struct target *target,
2728 verror(
"target %s not writeable!\n",target->
name);
2741 verror(
"could not insert breakpoint!\n");
2749 static int gdb_remove_sw_breakpoint(
struct target *target,
tid_t tid,
2752 verror(
"target %s not writeable!\n",target->
name);
2758 verror(
"could not remove breakpoint!\n");
2766 static int gdb_enable_sw_breakpoint(
struct target *target,
tid_t tid,
2769 verror(
"target %s not writeable!\n",target->
name);
2775 verror(
"could not insert breakpoint!\n");
2782 static int gdb_disable_sw_breakpoint(
struct target *target,
tid_t tid,
2785 verror(
"target %s not writeable!\n",target->
name);
2791 verror(
"could not remove breakpoint!\n");
2798 int gdb_change_sw_breakpoint(
struct target *target,
tid_t tid,
2800 unsigned char *code,
unsigned long code_len) {
2802 verror(
"target %s not writeable!\n",target->
name);
2812 vwarn(
"could not remove breakpoint before change;"
2813 " it may quit working!\n");
2821 int gdb_unchange_sw_breakpoint(
struct target *target,
tid_t tid,
2824 verror(
"target %s not writeable!\n",target->
name);
2834 verror(
"could not insert breakpoint!\n");
2841 #define CHECKTIDGLOBAL(tid) \
2842 if ((tid) != TID_GLOBAL) { \
2843 verror("only TID_GLOBAL supported, not tid %d!\n",tid); \
2848 #define CHECKTIDGLOBALORCURRENT(_T) \
2849 if ((_T) != TID_GLOBAL \
2850 && (!target->current_thread || target->current_thread->tid != (_T))) { \
2851 verror("only TID_GLOBAL/current tid supported, not tid %d!\n",(_T)); \
2856 static int gdb_set_hw_breakpoint(
struct target *target,
tid_t tid,
2860 verror(
"could not insert breakpoint!\n");
2867 static int gdb_set_hw_watchpoint(
struct target *target,
tid_t tid,
2885 verror(
"could not insert breakpoint!\n");
2892 static int gdb_unset_hw_breakpoint(
struct target *target,
tid_t tid,
REG num) {
2896 static int gdb_unset_hw_watchpoint(
struct target *target,
tid_t tid,
REG num) {
2900 static int gdb_disable_hw_breakpoints(
struct target *target,
tid_t tid) {
2904 static int gdb_enable_hw_breakpoints(
struct target *target,
tid_t tid) {
2908 static int gdb_disable_hw_breakpoint(
struct target *target,
tid_t tid,
REG dreg) {
2912 static int gdb_enable_hw_breakpoint(
struct target *target,
tid_t tid,
REG dreg) {
2917 static int gdb_singlestep(
struct target *target,
tid_t tid,
int isbp,
2918 struct target *overlay) {
2923 verror(
"target %s not writeable!\n",target->
name);
2930 tthread = __gdb_load_cached_thread(target,tid);
2937 static int gdb_singlestep_end(
struct target *target,
tid_t tid,
2938 struct target *overlay) {
2943 verror(
"target %s not writeable!\n",target->
name);
2950 tthread = __gdb_load_cached_thread(target,tid);
2957 vwarn(
"was told to clear sstep flag for tid %d, but tid %d was stepping;"
2961 vwarn(
"was told to clear sstep flag for tid %d, but no tid was stepping;"
2962 " clearing anyway!\n",tid);
uint8_t * breakpoint_instrs
#define GDB_ARGP_MEMCACHE_MMAP_SIZE
int target_flush_all_threads(struct target *target)
REGVAL target_regcache_readreg_tidctxt(struct target *target, tid_t tid, thread_ctxt_t tidctxt, REG reg)
int target_arch_x86_v2p_flags_snprintf(struct target *target, arch_x86_v2p_flags_t flags, char *buf, unsigned int bufsiz)
void regcache_mark_flushed(struct regcache *regcache)
#define SAFE_PERSONALITY_OP_WARN(op, outvar, expoutval, target,...)
int evloop_unset_fd(struct evloop *evloop, int fd, int fdtype)
#define SAFE_PERSONALITY_OP_WARN_NORET(op, outvar, expoutval, target,...)
struct debugfile * debugfile_from_file(char *filename, char *root_prefix, struct array_list *debugfile_load_opts_list)
target_personality_t personality
int gdb_rsp_step(struct target *target)
result_t probepoint_ss_handler(struct target *target, struct target_thread *tthread, struct probepoint *probepoint)
struct memregion * region
int gdb_spec_to_argv(struct target_spec *spec, int *argc, char ***argv)
int target_regcache_copy_all(struct target_thread *sthread, thread_ctxt_t stidctxt, struct target_thread *dthread, thread_ctxt_t dtidctxt)
int gdb_rsp_remove_break(struct target *target, ADDR addr, gdb_rsp_break_t bt, int kind)
int gdb_rsp_recv(struct target *target, int blocking, int only_one, gdb_ptype_t *o_ptype)
int target_regcache_copy_dirty_to(struct target_thread *sthread, thread_ctxt_t stidctxt, struct regcache *dregcache)
GHashTable * soft_probepoints
#define GDB_ARGP_SOCKFILE
#define GDB_ARGP_QEMU_QMP_HOST
static uint64_t unsigned int i
struct target_personality_ops * personality_ops
struct target_thread * sstep_thread
GHashTable * target_regcache_copy_registers(struct target *target, tid_t tid)
#define GDB_ARGP_CLEAR_MEM_CACHES
unsigned long int memcache_mmap_size
unsigned long(* write_tid)(struct target *target, tid_t tid, ADDR pgd, ADDR addr, unsigned long length, unsigned char *buf)
int target_os_thread_is_user(struct target *target, tid_t tid)
target_debug_bp_handler_t handle_break
struct target_ops gdb_ops
#define SAFE_PERSONALITY_OP(op, outvar, defoutval, target,...)
struct target_thread * base_thread
int target_regcache_copy_from(struct target_thread *dthread, thread_ctxt_t dtidctxt, struct regcache *sregcache)
struct argp_option gdb_argp_opts[]
struct target_memmod * target_memmod_create(struct target *target, tid_t tid, ADDR addr, int is_phys, target_memmod_type_t mmt, unsigned char *code, unsigned int code_len, int nowrite)
int gdb_instr_can_switch_context(struct target *target, ADDR addr)
int _target_unchange_sw_breakpoint(struct target *target, tid_t tid, struct target_memmod *mmod)
struct target_thread * global_thread
struct target * target_create(char *type, struct target_spec *spec)
unsigned long(* write_phys)(struct target *target, ADDR paddr, unsigned long length, unsigned char *buf)
int target_regcache_writereg_tidctxt(struct target *target, tid_t tid, thread_ctxt_t tidctxt, REG reg, REGVAL value)
int target_associate_debugfile(struct target *target, struct memregion *region, struct debugfile *debugfile)
#define verror(format,...)
tid_t target_os_thread_get_leader(struct target *target, tid_t tid)
arch_x86_v2p_flags_t v2p_flags
int gdb_rsp_close(struct target *target, int stay_paused)
int gdb_rsp_resume(struct target *target)
#define GDB_ARGP_QEMU_QMP_PORT
struct memregion * memregion_create(struct addrspace *space, region_type_t type, char *name)
int target_personality_attach(struct target *target, char *personality, char *personality_lib)
#define vwarn(format,...)
REGVAL target_read_reg(struct target *target, tid_t tid, REG reg)
void regcache_invalidate(struct regcache *regcache)
result_t probepoint_bp_handler(struct target *target, struct target_thread *tthread, struct probepoint *probepoint, int was_stepping)
int(* addr_v2p)(struct target *target, tid_t tid, ADDR pgd, ADDR vaddr, ADDR *paddr)
int(* load_machine)(struct target *target, struct regcache *regcache)
int gdb_evloop_handler(int readfd, int fdtype, void *state)
struct memrange * memrange_create(struct memregion *region, ADDR start, ADDR end, OFFSET offset, unsigned int prot_flags)
int target_os_thread_get_pgd_phys(struct target *target, tid_t tid, ADDR *pgdp)
target_status_t gdb_rsp_load_status(struct target *target)
int gdb_rsp_connect(struct target *target)
struct target_thread * current_thread
unsigned int clear_mem_caches_each_exception
struct target_location_ctxt * global_tlctxt
void gdb_free_spec(struct gdb_spec *xspec)
int target_arch_x86_v2p_get_flags(struct target *target, REGVAL cr0, REGVAL cr4, REGVAL msr_efer, REGVAL cpuid_edx, arch_x86_v2p_flags_t *flags)
struct target_spec * spec
struct gdb_helper_ops gdb_helper_ops_builtin
#define THREAD_CTXT_KERNEL
#define REG_X86_64_MSR_EFER
int target_regcache_snprintf(struct target *target, struct target_thread *tthread, thread_ctxt_t tctxt, char *buf, int bufsiz, int detail, char *sep, char *kvsep, int flags)
target_type_t target_type
#define vdebug(devel, areas, flags, format,...)
int gdb_rsp_read_regs(struct target *target, struct regcache *regcache)
int evloop_set_fd(struct evloop *evloop, int fd, int fdtype, evloop_handler_t handler, void *state)
struct thread_probepoint_context * tpc
int _target_enable_sw_breakpoint(struct target *target, tid_t tid, struct target_memmod *mmod)
#define EVLOOP_HRET_ERROR
int regcache_read_reg(struct regcache *regcache, REG reg, REGVAL *regval)
int gdb_rsp_write_regs(struct target *target, struct regcache *regcache)
struct gdb_helper_ops gdb_helper_ops_qemu
struct memregion * region
unsigned int rsp_status_valid
int gdb_rsp_pause(struct target *target)
int(* handle_exception_ours)(struct target *target)
void * calloc(size_t nmemb, size_t size)
int unlink(const char *pathname)
struct array_list * debugfile_load_opts_list
int target_regcache_mark_flushed(struct target *target, struct target_thread *tthread, thread_ctxt_t tctxt)
unsigned int machine_valid
error_t gdb_argp_parse_opt(int key, char *arg, struct argp_state *state)
void target_thread_set_status(struct target_thread *tthread, thread_status_t status)
void regcache_destroy(struct regcache *regcache)
int(* attach)(struct target *target)
#define CHECKTIDGLOBAL(tid)
int target_memmod_release(struct target *target, tid_t tid, struct target_memmod *mmod)
uint32_t needmonitorinterrupt
#define EVLOOP_HRET_SUCCESS
target_status_t target_status(struct target *target)
int target_invalidate_all_threads(struct target *target)
struct target_spec * target_build_spec(target_type_t type, target_mode_t mode)
struct gdb_rsp_stop_status last_stop_status
char * qemu_libvirt_domain
struct binfile * binfile_pointing
struct target_location_ctxt * target_location_ctxt_create(struct target *target, tid_t tid, struct memregion *region)
int target_finalize(struct target *target)
unsigned int breakpoint_instrs_len
GHashTable * hard_probepoints
int _target_remove_sw_breakpoint(struct target *target, tid_t tid, struct target_memmod *mmod)
int _target_disable_sw_breakpoint(struct target *target, tid_t tid, struct target_memmod *mmod)
struct target * gdb_instantiate(struct target_spec *spec, struct evloop *evloop)
unsigned char *(* read_tid)(struct target *target, tid_t tid, ADDR pgd, ADDR addr, unsigned long target_length, unsigned char *buf)
int target_memmod_set_writeable(struct target *target, struct target_memmod *mmod, int writeable)
int(* handle_pause)(struct target *target)
struct gdb_helper_ops * hops
int binfile_get_root_scope_sizes(struct binfile *binfile, int *named, int *duplicated, int *anon, int *numscopes)
REGVAL target_regcache_readreg(struct target *target, tid_t tid, REG reg)
#define GDB_ARGP_QEMU_MEM_PATH
int(* snprintf)(struct target *target, char *buf, int bufsiz)
struct target_spec * spec
struct regcache * machine
uint32_t nodisablehwbponss
void * malloc(size_t size)
char * debugfile_root_prefix
struct regcache * regcache_create(struct arch *arch)
unsigned int max_thread_ctxt
struct target_thread * target_lookup_thread(struct target *target, tid_t tid)
void target_set_status(struct target *target, target_status_t status)
#define CHECKTIDGLOBALORCURRENT(_T)
struct gdb_spec * gdb_build_spec(void)
target_debug_handler_t handle_step
unsigned char *(* read_phys)(struct target *target, ADDR paddr, unsigned long length, unsigned char *buf)
int(* fini)(struct target *target)
int vdebug_is_on(int level, log_areas_t areas, log_flags_t flags)
struct target_thread * target_create_thread(struct target *target, tid_t tid, void *tstate, void *tpstate)
struct array_list * target_list_threads(struct target *target)
int _target_change_sw_breakpoint(struct target *target, tid_t tid, struct target_memmod *mmod, unsigned char *code, unsigned long code_len)
int target_regcache_writereg(struct target *target, tid_t tid, REG reg, REGVAL value)
int regcache_isdirty(struct regcache *regcache)
GHashTable * stubfeatures
#define GDB_ARGP_LIBVIRT_DOMAIN
struct probepoint * probepoint
struct addrspace * addrspace_create(struct target *target, char *name, ADDR tag)
int gdb_rsp_insert_break(struct target *target, ADDR addr, gdb_rsp_break_t bt, int kind)