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);
90 gdb_lookup_overlay_thread_by_id(
struct target *
target,
int id);
93 static int gdb_attach_overlay_thread(
struct target *base,
struct target *overlay,
95 static int gdb_detach_overlay_thread(
struct target *base,
struct target *overlay,
100 static int __gdb_resume(
struct target *
target,
int detaching);
108 unsigned long length,
unsigned char *buf);
110 unsigned long length,
unsigned char *buf);
114 unsigned long length,
unsigned char *buf);
116 unsigned long length,
unsigned char *buf);
125 static int gdb_load_all_threads(
struct target *
target,
int force);
126 static int gdb_load_available_threads(
struct target *
target,
int force);
133 static int gdb_flush_current_thread(
struct target *
target);
134 static int gdb_flush_all_threads(
struct target *
target);
139 char *buf,
int bufsiz,
140 int detail,
char *sep,
char *key_val_sep);
154 unsigned char *code,
unsigned long code_len);
171 struct target *overlay);
173 struct target *overlay);
198 .attach = gdb_attach_internal,
199 .detach = gdb_detach,
204 .loadspaces = gdb_loadspaces,
205 .loadregions = gdb_loadregions,
206 .loaddebugfiles = gdb_loaddebugfiles,
207 .postloadinit = gdb_postloadinit,
208 .postopened = gdb_postopened,
209 .set_active_probing = gdb_set_active_probing,
211 .handle_exception = gdb_handle_exception,
218 .instantiate_overlay = gdb_instantiate_overlay,
219 .lookup_overlay_thread_by_id = gdb_lookup_overlay_thread_by_id,
220 .lookup_overlay_thread_by_name = gdb_lookup_overlay_thread_by_name,
221 .attach_overlay_thread = gdb_attach_overlay_thread,
222 .detach_overlay_thread = gdb_detach_overlay_thread,
224 .status = gdb_status,
226 .resume = gdb_resume,
227 .monitor = gdb_monitor,
232 .addr_v2p = gdb_addr_v2p,
233 .read_phys = gdb_read_phys,
234 .write_phys = gdb_write_phys,
236 .gettid = gdb_gettid,
237 .free_thread_state = gdb_free_thread_state,
238 .list_available_tids = gdb_list_available_tids,
239 .load_available_threads = gdb_load_available_threads,
240 .load_thread = gdb_load_thread,
241 .load_current_thread = gdb_load_current_thread,
242 .load_all_threads = gdb_load_all_threads,
243 .pause_thread = NULL,
244 .flush_thread = gdb_flush_thread,
245 .flush_current_thread = gdb_flush_current_thread,
246 .flush_all_threads = gdb_flush_all_threads,
247 .invalidate_thread = gdb_invalidate_thread,
248 .thread_snprintf = gdb_thread_snprintf,
250 .attach_evloop = gdb_attach_evloop,
251 .detach_evloop = gdb_detach_evloop,
259 .insert_sw_breakpoint = gdb_insert_sw_breakpoint,
260 .remove_sw_breakpoint = gdb_remove_sw_breakpoint,
261 .change_sw_breakpoint = gdb_change_sw_breakpoint,
262 .unchange_sw_breakpoint = gdb_unchange_sw_breakpoint,
263 .enable_sw_breakpoint = gdb_enable_sw_breakpoint,
264 .disable_sw_breakpoint = gdb_disable_sw_breakpoint,
266 .set_hw_breakpoint = gdb_set_hw_breakpoint,
267 .set_hw_watchpoint = gdb_set_hw_watchpoint,
268 .unset_hw_breakpoint = gdb_unset_hw_breakpoint,
269 .unset_hw_watchpoint = gdb_unset_hw_watchpoint,
270 .disable_hw_breakpoints = gdb_disable_hw_breakpoints,
271 .enable_hw_breakpoints = gdb_enable_hw_breakpoints,
272 .disable_hw_breakpoint = gdb_disable_hw_breakpoint,
273 .enable_hw_breakpoint = gdb_enable_hw_breakpoint,
275 .singlestep = gdb_singlestep,
276 .singlestep_end = gdb_singlestep_end,
282 #define GDB_ARGP_HOST 0x650001
283 #define GDB_ARGP_PORT 0x650002
284 #define GDB_ARGP_UDP 0x650003
285 #define GDB_ARGP_SOCKFILE 0x650004
286 #define GDB_ARGP_IS_KVM 0x650005
287 #define GDB_ARGP_IS_QEMU 0x650006
288 #define GDB_ARGP_QEMU_QMP_HOST 0x650007
289 #define GDB_ARGP_QEMU_MEM_PATH 0x650008
290 #define GDB_ARGP_QEMU_QMP_PORT 0x650009
291 #define GDB_ARGP_CLEAR_MEM_CACHES 0x65000a
292 #define GDB_ARGP_MEMCACHE_MMAP_SIZE 0x65000b
293 #define GDB_ARGP_LIBVIRT_DOMAIN 0x65000c
298 "The hostname the GDB stub is listening on (default localhost).",-4 },
300 "The port the GDB stub is listening on (default 1234).",-4 },
302 "Use UDP instead of TCP (default TCP).",-4 },
304 "The UNIX domain socket filename the GDB stub is listening on.",-4 },
305 {
"main-filename",
'M',
"FILE",0,
306 "Set main binary's filepath for target.",-4 },
308 "Clear mem caches on each debug exception.",-4 },
310 "Enable QEMU GDB stub support",-4 },
312 "Attach to QEMU QMP on the given host (default localhost).",-4 },
314 "Attach to QEMU QMP on the given port (default 1235).",-4 },
316 "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 },
317 #ifdef ENABLE_LIBVIRT
319 "Access QEMU QMP over libvirt proxy.",-4 },
322 "Enable QEMU GDB KVM stub support.",-4 },
324 "Max size (bytes) of the mmap cache (default 128MB).",-4 },
364 #ifdef ENABLE_LIBVIRT
373 av = calloc(ac + 1,
sizeof(
char *));
376 av[j++] = strdup(
"--gdb-host");
379 if (xspec->
port > -1) {
380 av[j++] = strdup(
"--gdb-port");
382 snprintf(av[j],16,
"%d",xspec->
port);
386 av[j++] = strdup(
"--gdb-udp");
389 av[j++] = strdup(
"--gdb-sockfile");
393 av[j++] = strdup(
"-M");
397 av[j++] = strdup(
"--clear-mem-caches-each-exception");
400 av[j++] = strdup(
"--qemu");
402 av[j++] = strdup(
"--qemu-qmp-host");
406 av[j++] = strdup(
"--qemu-qmp-port");
412 av[j++] = strdup(
"--qemu-mem-path");
415 #ifdef ENABLE_LIBVIRT
417 av[j++] = strdup(
"--qemu-libvirt-domain");
422 av[j++] = strdup(
"--kvm");
424 av[j++] = strdup(
"--memcache-mmap-size");
444 struct argp_option *opti;
447 if (key == ARGP_KEY_INIT)
449 else if (!state->input)
450 return ARGP_ERR_UNKNOWN;
463 if (key == opti->key) {
476 verror(
"cannot mix arguments for GDB target (%c) with non-GDB"
484 xspec = calloc(1,
sizeof(*xspec));
488 verror(
"cannot mix arguments for GDB target with non-GDB target!\n");
494 xspec = (
struct gdb_spec *)spec->backend_spec;
502 return ARGP_ERR_UNKNOWN;
505 case ARGP_KEY_NO_ARGS:
508 case ARGP_KEY_SUCCESS:
515 xspec->hostname = strdup(arg);
518 xspec->port = atoi(arg);
524 xspec->sockfile = strdup(arg);
527 xspec->main_filename = strdup(arg);
530 xspec->clear_mem_caches_each_exception = 1;
536 xspec->qemu_qmp_hostname = strdup(arg);
539 xspec->qemu_qmp_port = atoi(arg);
542 xspec->qemu_mem_path = strdup(arg);
544 #ifdef ENABLE_LIBVIRT
546 xspec->qemu_libvirt_domain = strdup(arg);
553 xspec->memcache_mmap_size = atoi(arg);
556 return ARGP_ERR_UNKNOWN;
574 xspec = calloc(1,
sizeof(*xspec));
593 return gdb_attach(spec,evloop);
614 if (!(xstate = (
struct gdb_state *)malloc(
sizeof(*xstate)))) {
618 memset(xstate,0,
sizeof(*xstate));
620 xstate->need_ack = 1;
622 xstate->fd = xstate->wfd = -1;
626 xstate->evloop_fd = -1;
629 g_hash_table_insert(
target->
config,strdup(
"MAIN_FILENAME"),
645 "autoinitialized the os_linux_generic personality!\n");
648 verror(
"failed to autoinitialize the os_linux_generic personality!\n");
653 vwarn(
"cannot initialize a personality!\n");
666 if (!xstate->hops && xspec->
is_qemu)
668 else if (!xstate->hops)
671 if (xstate->hops->init) {
672 if (xstate->hops->init(
target)) {
673 verror(
"failed to init hops!\n");
681 if (evloop && xstate->evloop_fd < 0) {
693 if (xstate->ostype) {
694 free(xstate->ostype);
695 xstate->ostype = NULL;
708 static int gdb_snprintf(
struct target *
target,
char *buf,
int bufsiz) {
713 return snprintf(buf,bufsiz,
"gdbstub@udp(%s::%d)",
716 return snprintf(buf,bufsiz,
"gdbstub@unix(%s)",
719 return snprintf(buf,bufsiz,
"gdbstub@tcp(%s::%d)",
722 return snprintf(buf,bufsiz,
"gdbstub@unknown");
725 static int gdb_init(
struct target *target) {
732 vwarn(
"auto-enabling SEMI_STRICT bpmode on GDB target %s\n",target->
name);
745 g_hash_table_new_full(g_str_hash,g_str_equal,free,free);
761 static int gdb_attach_internal(
struct target *target) {
772 if (gdb_pause(target,0)) {
773 vwarn(
"could not pause target before attaching; continuing anyway!\n");
781 verror(
"could not attach hops!\n");
787 gdb_attach_evloop(target,target->
evloop);
793 static int gdb_detach(
struct target *target,
int stay_paused) {
797 "preparing to detach from GDB stub (target %s)\n",target->
name);
812 gdb_detach_evloop(target);
816 verror(
"failed to fini hops; continuing anyway (target %s)!\n",
834 verror(
"failed to detach from GDB stub (target %s)!\n",target->
name);
841 static int gdb_fini(
struct target *target) {
869 static int gdb_loadspaces(
struct target *target) {
883 static int gdb_loadregions(
struct target *target,
struct addrspace *space) {
891 (
char *)g_hash_table_lookup(target->
config,
"MAIN_FILENAME");
908 static int gdb_loaddebugfiles(
struct target *target,
struct addrspace *space,
927 if (!region->
name || strlen(region->
name) == 0)
975 static int gdb_postloadinit(
struct target *target) {
999 char *start = (
char *)g_hash_table_lookup(target->
config,
1000 "OS_KERNEL_START_ADDR");
1009 static int gdb_postopened(
struct target *target) {
1015 static int gdb_set_active_probing(
struct target *target,
1022 static struct target *
1023 gdb_instantiate_overlay(
struct target *target,
1027 struct target *overlay;
1056 verror(
"could not load group_leader for thread %d; BUG?!\n",tthread->
tid);
1059 else if (leader != tthread) {
1061 "using group_leader %d instead of user-supplied overlay thread %d\n",
1062 leader->
tid,tthread->
tid);
1075 gdb_lookup_overlay_thread_by_id(
struct target *target,
int id) {
1078 retval = gdb_load_thread(target,
id,0);
1087 "found overlay thread %d\n",
id);
1091 verror(
"tid %d matched %d, but is a kernel thread!\n",retval->
tid,
id);
1098 gdb_lookup_overlay_thread_by_name(
struct target *target,
char *
name) {
1103 GHashTableIter iter;
1105 if ((rc = gdb_load_available_threads(target,0)))
1106 vwarn(
"could not load %d threads; continuing anyway!\n",-rc);
1108 g_hash_table_iter_init(&iter,target->
threads);
1109 while (g_hash_table_iter_next(&iter,NULL,(gpointer)&tthread)) {
1113 if (!tthread->name) {
1114 vwarn(
"tid %d does not have a name; continuing!\n",
1119 slen = strlen(tthread->name);
1121 "checking task with name '%*s' against '%s'\n",
1122 slen,tthread->name,name);
1123 if (strncmp(name,tthread->name,slen) == 0) {
1131 verror(
"tid %d matched '%s', but is a kernel thread!\n",
1138 "found overlay thread %"PRIiTID"\n",retval->
tid);
1148 static int gdb_attach_overlay_thread(
struct target *base,
struct target *overlay,
1155 if (nltid == -1 || cltid == -1)
1165 static int gdb_detach_overlay_thread(
struct target *base,
struct target *overlay,
1170 static int __gdb_in_userspace(
struct target *target,
int cpl,
REGVAL ipval) {
1194 static int __gdb_get_cpl_thread(
struct target *target,
1208 verror(
"could not read CS register to find CPL!\n");
1215 static int __gdb_get_cpl(
struct target *target,
tid_t tid) {
1218 if (!(tthread = __gdb_load_cached_thread(target,tid))) {
1225 return __gdb_get_cpl_thread(target,tthread);
1230 int *again,
void *priv) {
1242 tstatus = gdb_status(target);
1244 vwarn(
"failed to load status for GDB stub (target %s);"
1245 " returning to user!\n",target->
name);
1249 vwarn(
"unknown status for GDB stub (target %s);"
1250 " returning to user!\n",target->
name);
1254 vwarn(
"%s is running; ignoring\n",target->
name);
1271 if (!__gdb_load_current_thread(target,0,1)) {
1272 verror(
"could not load global thread!\n");
1283 verror(
"could not read CPL while checking debug event: %s\n",
1289 verror(
"could not read EIP while checking debug event: %s\n",
1311 gdb_load_current_thread(target,0);
1316 verror(
"could not load current thread!\n");
1322 if (__gdb_in_userspace(target,cpl,ipval)) {
1325 "; will try to handle it!\n",ipval,tid);
1329 "thread %d at IP 0x%"PRIxADDR"\n",tid,ipval);
1332 verror(
"bad GDB status %d; aborting!\n",tstatus);
1339 switch (ss->reason) {
1344 if (ss->signal == SIGTRAP) {
1359 "found hw break on 0x%"PRIxADDR"\n",ipval);
1367 "found sw break on 0x%"PRIxADDR"\n",ipval);
1371 "did not find hw/sw break; must be step!\n");
1400 vwarn(
"could not find hardware bp and not sstep'ing;"
1401 " letting user handle fault at 0x%"PRIxADDR"!\n",ipval);
1405 vwarn(
"target %s signaled unexpectedly with %lu; ignoring!\n",
1406 target->
name,ss->signal);
1427 verror(
"bad GDB stop status %d; aborting!\n",ss->reason);
1468 "current GDB stub (%s) status is valid\n",target->
name);
1474 verror(
"could not load status for target %s\n",target->
name);
1485 static int gdb_pause(
struct target *target,
int nowait) {
1487 struct timeval check_tv = { 0,0};
1494 status = gdb_status(target);
1496 vwarn(
"failed to load status for GDB stub (target %s);"
1497 " trying to pause anyway!\n",target->
name);
1499 vwarn(
"unknown status for GDB stub (target %s);"
1500 " trying to pause anyway!\n",target->
name);
1503 verror(
"could not pause target %s!\n",target->
name);
1519 vwarn(
"could not reload GDB stub status target %s after pause!\n",
1539 gdb_poll(target,&check_tv,&outcome,&pstatus);
1544 static int __gdb_resume(
struct target *target,
int detaching) {
1551 status = gdb_status(target);
1553 vwarn(
"failed to load status for GDB stub (target %s);"
1554 " trying to resume anyway!\n",target->
name);
1556 vwarn(
"unknown status for GDB stub (target %s);"
1557 " trying to resume anyway!\n",target->
name);
1560 vwarn(
"not paused; not invalidating and resuming; BUG?\n");
1589 "machine dirty; writing %d regs!\n",rc);
1593 verror(
"could not write CPU regs!\n");
1600 "machine state not dirty; not writing regs!\n");
1612 if (gstate->
fd < 0) {
1613 verror(
"cannot resume; disconnected!\n");
1624 static int gdb_resume(
struct target *target) {
1625 return __gdb_resume(target,0);
1637 if (gstate->
fd < 0) {
1638 verror(
"server disconnected!\n");
1645 FD_SET(gstate->
fd,&inset);
1648 ret = select(gstate->
fd + 1,&inset,NULL,NULL,&tv);
1652 if (!FD_ISSET(gstate->
fd,&inset))
1659 retval = gdb_handle_exception(target,0,&again,NULL);
1669 __gdb_resume(target,0);
1690 static target_status_t gdb_poll(
struct target *target,
struct timeval *tv,
1709 ret = select(
fd+1,&inset,NULL,NULL,tv);
1716 if (!FD_ISSET(
fd, &inset)) {
1723 retval = gdb_handle_exception(target,0,&again,NULL);
1731 struct target *target = (
struct target *)state;
1736 retval = gdb_handle_exception(target,0,&again,NULL);
1746 __gdb_resume(target,0);
1751 int gdb_attach_evloop(
struct target *target,
struct evloop *evloop) {
1755 verror(
"no evloop attached!\n");
1765 "added evloop readfd %d event channel\n",xstate->
evloop_fd);
1770 static int gdb_detach_evloop(
struct target *target) {
1783 tid_t gdb_gettid(
struct target *target) {
1789 tthread = gdb_load_current_thread(target,0);
1791 verror(
"could not load current thread to get TID!\n");
1795 return tthread->
tid;
1798 void gdb_free_thread_state(
struct target *target,
void *
state) {
1803 static struct target_thread *__gdb_load_cached_thread(
struct target *target,
1812 return gdb_load_thread(target,tid,0);
1817 static struct target_thread *__gdb_load_current_thread(
struct target *target,
1834 if (globalonly && !force
1841 else if (!globalonly && !force
1846 verror(
"target not paused; cannot load current thread!\n");
1860 verror(
"could not read CPU regs!\n");
1872 vwarn(
"helper ops load_machine failed!\n");
1909 verror(
"could not read IP from machine state!\n");
1914 verror(
"could not read IP from machine state!\n");
1922 if (__gdb_in_userspace(target,cpl,ipval))
1943 vwarn(
"not supported yet!!!\n");
2001 vwarn(
"personality set current thread context to %d; global thread"
2002 " context is %d; forcing current to global!\n",
2013 tthread->
state = tstate = \
2038 vwarn(
"error loading current thread; trying to use default thread\n");
2044 static struct target_thread *gdb_load_current_thread(
struct target *target,
2046 return __gdb_load_current_thread(target,force,0);
2049 static struct target_thread *gdb_load_thread(
struct target *target,
2050 tid_t tid,
int force) {
2069 gdb_load_current_thread(target,force);
2080 if (!gdb_load_current_thread(target,force)) {
2081 vwarn(
"could not load current thread to compare with"
2092 return gdb_load_current_thread(target,force);
2100 "did not need to load thread; copy is valid\n");
2119 static struct array_list *gdb_list_available_tids(
struct target *target) {
2125 static int gdb_load_all_threads(
struct target *target,
int force) {
2133 for (i = 0; i < array_list_len(cthreads); ++i) {
2134 tthread = (
struct target_thread *)array_list_item(cthreads,i);
2137 "tid %"PRIiTID" (%p)\n",tthread->
tid,tthread);
2139 if (!gdb_load_thread(target,tthread->
tid,force)) {
2156 static int gdb_load_available_threads(
struct target *target,
int force) {
2164 if (!__gdb_load_current_thread(target,force,1)) {
2165 verror(
"could not load current thread!\n");
2178 static int gdb_flush_global_thread(
struct target *target,
2189 verror(
"global thread not loaded; BUG!!!\n");
2198 "%s tid %"PRIiTID" not valid (%d) or not dirty (%d)\n",
2206 ipval,target->
name,tid);
2213 verror(
"failed to copy dirty regs from %s tid %d tidctxt %d to machine!\n",
2220 vwarn(
"failed to mark %s tid %d tidctxt %d flushed!\n",
2230 static int gdb_flush_current_thread(
struct target *target) {
2237 verror(
"current thread not loaded!\n");
2253 "%s tid %"PRIiTID" not valid (%d) or not dirty (%d)\n",
2267 verror(
"failed to copy dirty regs from %s tid %d tidctxt %d to machine!\n",
2274 vwarn(
"failed to mark %s tid %d tidctxt %d flushed!\n",
2282 static int gdb_flush_thread(
struct target *target,
tid_t tid) {
2293 return gdb_flush_current_thread(target);
2309 "current thread not loaded to compare with"
2310 " tid %"PRIiTID
"; exiting, user-mode EIP, or BUG?\n",
2315 "current thread not valid to compare with"
2316 " tid %"PRIiTID
"; exiting, user-mode EIP, or BUG?\n",
2325 return gdb_flush_current_thread(target);
2333 verror(
"cannot flush unknown thread %"PRIiTID
"; you forgot to load?\n",
2340 return gdb_flush_current_thread(target);
2344 "%s tid %"PRIiTID
" not valid (%d) or not dirty (%d)\n",
2361 static int gdb_flush_all_threads(
struct target *target) {
2363 GHashTableIter iter;
2367 g_hash_table_iter_init(&iter,target->
threads);
2368 while (g_hash_table_iter_next(&iter,NULL,(gpointer)&tthread)) {
2373 rc = gdb_flush_thread(target,tthread->tid);
2375 verror(
"could not flush thread %"PRIiTID
"\n",tthread->tid);
2396 rc = gdb_flush_current_thread(target);
2398 verror(
"could not flush current thread %"PRIiTID
"\n",
2426 rc = gdb_flush_global_thread(target,current_thread);
2435 static int gdb_invalidate_thread(
struct target *target,
2442 static int gdb_thread_snprintf(
struct target *target,
2444 char *buf,
int bufsiz,
2445 int detail,
char *sep,
char *kvsep) {
2451 buf,bufsiz,detail,sep,kvsep,0);
2457 (rc >= bufsiz) ? NULL : buf + rc,
2458 (rc >= bufsiz) ? 0 : bufsiz - rc,
2461 verror(
"could not snprintf personality info for thread %d!\n",
2469 static unsigned char *gdb_read(
struct target *target,
ADDR addr,
2470 unsigned long length,
unsigned char *buf) {
2489 static unsigned long gdb_write(
struct target *target,
ADDR addr,
2490 unsigned long length,
unsigned char *buf) {
2518 static int __gdb_pgd(
struct target *target,
tid_t tid,uint64_t *pgd) {
2523 REGVAL cr0 = 0,cr3 = 0,cr4 = 0,msr_efer = 0,cpuid_edx = 0;
2529 tthread = __gdb_load_current_thread(target,0,1);
2531 verror(
"could not load global thread!\n");
2576 verror(
"could not determine v2p_flags! pgd walks might fail;"
2577 " assuming 64-bit long mode and paging!\n");
2581 verror(
"could not determine v2p_flags! pgd walks might fail;"
2582 " assuming 32-bit mode and PAE (and auto-PSE)!\n");
2600 tthread = gdb_load_thread(target,tid,0);
2602 verror(
"could not load tid %"PRIiTID
"!\n",tid);
2607 verror(
"could not get phys pgd for tid %"PRIiTID
": %s!\n",
2608 tid,strerror(errno));
2614 "tid %"PRIiTID
" pgd (phys) = 0x%"PRIx64
"\n",tid,*pgd);
2619 static int gdb_addr_v2p(
struct target *target,
tid_t tid,
2626 if (__gdb_pgd(target,tid,&pgd)) {
2627 verror(
"could not read pgd for tid %"PRIiTID
"!\n",tid);
2636 return xstate->
hops->
addr_v2p(target,tid,pgd,vaddr,paddr);
2639 static unsigned char *gdb_read_phys(
struct target *target,
ADDR paddr,
2640 unsigned long length,
unsigned char *buf) {
2653 static unsigned long gdb_write_phys(
struct target *target,
ADDR paddr,
2654 unsigned long length,
unsigned char *buf) {
2667 static struct target_memmod *gdb_insert_sw_breakpoint(
struct target *target,
2679 verror(
"could not insert breakpoint!\n");
2687 static int gdb_remove_sw_breakpoint(
struct target *target,
tid_t tid,
2690 verror(
"could not remove breakpoint!\n");
2698 static int gdb_enable_sw_breakpoint(
struct target *target,
tid_t tid,
2701 verror(
"could not insert breakpoint!\n");
2708 static int gdb_disable_sw_breakpoint(
struct target *target,
tid_t tid,
2711 verror(
"could not remove breakpoint!\n");
2718 int gdb_change_sw_breakpoint(
struct target *target,
tid_t tid,
2720 unsigned char *code,
unsigned long code_len) {
2726 vwarn(
"could not remove breakpoint before change;"
2727 " it may quit working!\n");
2735 int gdb_unchange_sw_breakpoint(
struct target *target,
tid_t tid,
2742 verror(
"could not insert breakpoint!\n");
2749 #define CHECKTIDGLOBAL(tid) \
2750 if ((tid) != TID_GLOBAL) { \
2751 verror("only TID_GLOBAL supported, not tid %d!\n",tid); \
2756 #define CHECKTIDGLOBALORCURRENT(_T) \
2757 if ((_T) != TID_GLOBAL \
2758 && (!target->current_thread || target->current_thread->tid != (_T))) { \
2759 verror("only TID_GLOBAL/current tid supported, not tid %d!\n",(_T)); \
2764 static int gdb_set_hw_breakpoint(
struct target *target,
tid_t tid,
2768 verror(
"could not insert breakpoint!\n");
2775 static int gdb_set_hw_watchpoint(
struct target *target,
tid_t tid,
2793 verror(
"could not insert breakpoint!\n");
2800 static int gdb_unset_hw_breakpoint(
struct target *target,
tid_t tid,
REG num) {
2804 static int gdb_unset_hw_watchpoint(
struct target *target,
tid_t tid,
REG num) {
2808 static int gdb_disable_hw_breakpoints(
struct target *target,
tid_t tid) {
2812 static int gdb_enable_hw_breakpoints(
struct target *target,
tid_t tid) {
2816 static int gdb_disable_hw_breakpoint(
struct target *target,
tid_t tid,
REG dreg) {
2820 static int gdb_enable_hw_breakpoint(
struct target *target,
tid_t tid,
REG dreg) {
2825 static int gdb_singlestep(
struct target *target,
tid_t tid,
int isbp,
2826 struct target *overlay) {
2832 tthread = __gdb_load_cached_thread(target,tid);
2839 static int gdb_singlestep_end(
struct target *target,
tid_t tid,
2840 struct target *overlay) {
2846 tthread = __gdb_load_cached_thread(target,tid);
2853 vwarn(
"was told to clear sstep flag for tid %d, but tid %d was stepping;"
2857 vwarn(
"was told to clear sstep flag for tid %d, but no tid was stepping;"
2858 " 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
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
void target_memmod_set_writeable(struct target *target, struct target_memmod *mmod, int writeable)
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)
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 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(* 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
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)