19 #include <sys/types.h>
47 static int os_process_snprintf(
struct target *
target,
char *buf,
int bufsiz);
49 static int os_process_postloadinit(
struct target *
target);
51 static int os_process_detach(
struct target *
target,
int stay_paused);
55 static int os_process_loaddebugfiles(
struct target *
target,
59 os_process_handle_overlay_exception(
struct target *overlay,
62 static void os_process_handle_event(
struct target *
target,
70 os_process_lookup_overlay_thread_by_id(
struct target *
target,
int id);
75 static int os_process_pause(
struct target *
target,
int nowait);
78 unsigned long length,
unsigned char *buf);
80 unsigned long length,
unsigned char *buf);
89 static int os_process_load_all_threads(
struct target *
target,
int force);
90 static int os_process_load_available_threads(
struct target *
target,
int force);
92 static int os_process_flush_current_thread(
struct target *
target);
93 static int os_process_flush_all_threads(
struct target *
target);
94 static int os_process_thread_snprintf(
struct target *
target,
97 int detail,
char *sep,
char *kvsep);
114 unsigned long code_len);
135 struct target *overlay);
137 struct target *overlay);
142 .init = os_process_init,
143 .fini = os_process_fini,
144 .attach = os_process_attach,
145 .detach = os_process_detach,
147 .loadspaces = os_process_loadspaces,
148 .loadregions = os_process_loadregions,
149 .loaddebugfiles = os_process_loaddebugfiles,
150 .postloadinit = os_process_postloadinit,
152 .set_active_probing = NULL,
154 .instantiate_overlay = os_process_instantiate_overlay,
155 .lookup_overlay_thread_by_id = os_process_lookup_overlay_thread_by_id,
156 .lookup_overlay_thread_by_name = os_process_lookup_overlay_thread_by_name,
158 .handle_overlay_exception = os_process_handle_overlay_exception,
162 .handle_event = os_process_handle_event,
164 .status = os_process_status,
165 .pause = os_process_pause,
166 .resume = os_process_resume,
169 .read = os_process_read,
170 .write = os_process_write,
172 .gettid = os_process_gettid,
173 .free_thread_state = os_process_free_thread_state,
178 .load_available_threads = os_process_load_all_threads,
179 .load_thread = os_process_load_thread,
180 .load_current_thread = os_process_load_current_thread,
181 .load_all_threads = os_process_load_all_threads,
182 .pause_thread = NULL,
183 .flush_thread = os_process_flush_thread,
184 .flush_current_thread = os_process_flush_current_thread,
185 .flush_all_threads = os_process_flush_all_threads,
186 .thread_snprintf = os_process_thread_snprintf,
188 .attach_evloop = NULL,
189 .detach_evloop = NULL,
191 .readreg = os_process_read_reg,
192 .writereg = os_process_write_reg,
193 .insert_sw_breakpoint = os_process_insert_sw_breakpoint,
194 .remove_sw_breakpoint = os_process_remove_sw_breakpoint,
195 .enable_sw_breakpoint = os_process_enable_sw_breakpoint,
196 .disable_sw_breakpoint = os_process_disable_sw_breakpoint,
197 .change_sw_breakpoint = os_process_change_sw_breakpoint,
198 .get_unused_debug_reg = os_process_get_unused_debug_reg,
213 char *buf,
int bufsiz) {
223 verror(
"OS Process driver cannot leave target process closed on exit!\n");
247 verror(
"could not load base tid %d!\n",base_tid);
257 vwarn(
"target->base_thread does not match with just-loaded thread"
258 " for %d; pid wraparound caused stale thread??\n",base_tid);
266 vwarn(
"auto-enabling SEMI_STRICT bpmode on Xen Process target.\n");
281 static int os_process_fini(
struct target *target) {
287 static int os_process_attach(
struct target *target) {
307 static int os_process_detach(
struct target *target,
int stay_paused) {
314 static int os_process_loadspaces(
struct target *target) {
336 verror(
"could not load process from underlying OS; not updating!\n");
340 snprintf(nbuf,
sizeof(nbuf),
"os_process(%d)",target->
base_tid);
347 static int os_process_loadregions(
struct target *target,
351 GList *t1,*t2,*t11,*t22,*t2x,*t22x;
365 verror(
"could not load process from underlying OS; not updating!\n");
395 && ((region1->
name == NULL && region2->
name == NULL)
397 && strcmp(region1->
name,region2->
name) == 0)))
403 #warning "generate MOD events"
405 if (region2 == NULL) {
421 if (range2 == NULL) {
428 else if (range1->
end != range2->
end
478 static int os_process_loaddebugfiles(
struct target *target,
498 if (!region->
name || strlen(region->
name) == 0)
509 NULL,NULL,rbuf,PATH_MAX)) {
510 verror(
"could not find debugfile for region '%s': %s\n",
511 region->
name,strerror(errno));
520 verror(
"still could not find debugfile for region '%s': %s\n",
521 region->
name,strerror(errno));
580 static int os_process_postloadinit(
struct target *target) {
585 static int os_process_set_active_probing(
struct target *target,
590 verror(
"target %s not writeable!\n",target->
name);
599 flags &= ~APF_THREAD_ENTRY;
608 flags &= ~APF_THREAD_EXIT;
617 flags &= ~APF_MEMORY;
634 static struct target *
635 os_process_instantiate_overlay(
struct target *target,
639 struct target *overlay;
660 os_process_lookup_overlay_thread_by_id(
struct target *target,
int id) {
666 retval = os_process_load_thread(target,
id,0);
677 os_process_lookup_overlay_thread_by_name(
struct target *target,
char *
name) {
683 if ((rc = os_process_load_all_threads(target,0)))
684 vwarn(
"could not load %d threads; continuing anyway!\n",-rc);
686 g_hash_table_iter_init(&iter,target->
threads);
687 while (g_hash_table_iter_next(&iter,NULL,(gpointer)&tthread)) {
690 else if (tthread->name && strcmp(tthread->name,name) == 0) {
698 "found overlay thread %"PRIiTID"\n",retval->
tid);
708 os_process_handle_overlay_exception(
struct target *overlay,
714 struct os_state *xstate;
716 xstate = (
struct os_state *)overlay->
base->
state;
737 os_process_loadregions(overlay,(
struct addrspace *) \
738 g_list_nth_data(overlay->
spaces,0));
781 "single step event in overlay tid %"PRIiTID" INTO KERNEL"
782 " (at 0x%"PRIxADDR"); aborting breakpoint singlestep;"
783 " will be hit again!\n",
809 verror(
"unhandled overlay exception; will return ERROR!\n");
827 static void os_process_handle_event(
struct target *target,
834 tthread =
event->thread;
845 os_process_loadregions(target,space);
850 verror(
"malformed THREAD_CREATED event without thread set!\n");
859 "underlying target tid %d is new; but already have it!\n",
875 verror(
"malformed THREAD_EXIT(ED|ING) event without thread set!\n");
885 "underlying target tid %d is exit(ed|ing);"
886 " but we do not have it!\n",tthread->
tid);
904 static int os_process_pause(
struct target *target,
int nowait) {
915 static int os_process_resume(
struct target *target) {
934 static int __is_our_tid(
struct target *target,
tid_t tid) {
935 if (g_hash_table_lookup(target->
threads,(gpointer)(uintptr_t)tid))
941 static int __we_are_current(
struct target *target) {
949 static unsigned char *os_process_read(
struct target *target,
ADDR addr,
950 unsigned long length,
unsigned char *buf) {
951 ADDR paddr = 0,raddr,offset;
952 unsigned long clen,tlen;
963 if (__we_are_current(target))
975 while (clen < length) {
984 tlen = (tlen < (length - clen)) ? tlen : (length - clen);
987 " len %ld in tid %"PRIiTID"!\n",
999 static unsigned long os_process_write(
struct target *target,
ADDR addr,
1000 unsigned long length,
unsigned char *buf) {
1001 ADDR paddr = 0,raddr,offset;
1002 unsigned long clen,tlen;
1006 verror(
"target %s not writeable!\n",target->
name);
1011 if (__we_are_current(target))
1032 while (clen < length) {
1041 tlen = (tlen < (length - clen)) ? tlen : (length - clen);
1044 " len %ld in tid %"PRIiTID"!\n",
1054 while (clen < length) {
1063 tlen = (tlen < (length - clen)) ? tlen : (length - clen);
1066 " len %ld in tid %"PRIiTID"!\n",
1067 paddr,raddr,tlen,target->
base_tid);
1078 static tid_t os_process_gettid(
struct target *target) {
1087 tthread = os_process_load_current_thread(target,0);
1089 verror(
"could not load current thread to get TID!\n");
1093 return tthread->
tid;
1096 static void os_process_free_thread_state(
struct target *target,
void *
state) {
1103 os_process_list_available_tids(
struct target *target) {
1106 retval = array_list_create(1);
1107 array_list_append(retval,(
void *)(uintptr_t)target->
base_tid);
1113 os_process_load_thread(
struct target *target,
tid_t tid,
int force) {
1114 if (!__is_our_tid(target,tid)) {
1127 os_process_load_current_thread(
struct target *target,
int force) {
1132 verror(
"could not load base target current thread: %s\n",
1139 if (!__is_our_tid(target,uthread->
tid)) {
1141 "base target current tid %d is not in tgid %d!\n",
1154 static int os_process_load_all_threads(
struct target *target,
int force) {
1155 if (os_process_load_thread(target,target->
base_tid,force))
1160 static int os_process_load_available_threads(
struct target *target,
1162 if (os_process_load_thread(target,target->
base_tid,force))
1167 static int os_process_flush_thread(
struct target *target,
tid_t tid) {
1176 verror(
"target %s not writeable!\n",target->
name);
1181 if (!__is_our_tid(target,tid)) {
1189 verror(
"could not flush base target tid %d: %s\n",tid,strerror(errno));
1198 static int os_process_flush_current_thread(
struct target *target) {
1204 static int os_process_flush_all_threads(
struct target *target) {
1212 rc += os_process_flush_thread(target,(
tid_t)(uintptr_t)tid);
1218 static int os_process_thread_snprintf(
struct target *target,
1220 char *buf,
int bufsiz,
1221 int detail,
char *sep,
char *kvsep) {
1222 if (!__is_our_tid(target,tthread->
tid)) {
1223 verror(
"tid %d is not in tgid %d!\n",
1230 buf,bufsiz,detail,sep,kvsep);
1233 static REGVAL os_process_read_reg(
struct target *target,
tid_t tid,
REG reg) {
1236 if (!__is_our_tid(target,tid)) {
1251 static int os_process_write_reg(
struct target *target,
tid_t tid,
REG reg,
1256 if (!__is_our_tid(target,tid)) {
1263 verror(
"target %s not writeable!\n",target->
name);
1284 os_process_insert_sw_breakpoint(
struct target *target,
1290 verror(
"target %s not writeable!\n",target->
name);
1319 static int os_process_remove_sw_breakpoint(
struct target *target,
tid_t tid,
1322 verror(
"target %s not writeable!\n",target->
name);
1330 static int os_process_enable_sw_breakpoint(
struct target *target,
tid_t tid,
1333 verror(
"target %s not writeable!\n",target->
name);
1341 static int os_process_disable_sw_breakpoint(
struct target *target,
tid_t tid,
1344 verror(
"target %s not writeable!\n",target->
name);
1352 static int os_process_change_sw_breakpoint(
struct target *target,
tid_t tid,
1354 unsigned char *code,
1355 unsigned long code_len) {
1357 verror(
"target %s not writeable!\n",target->
name);
1365 static REG os_process_get_unused_debug_reg(
struct target *target,
tid_t tid) {
1376 struct target *overlay) {
1378 verror(
"target %s not writeable!\n",target->
name);
1387 struct target *overlay) {
1389 verror(
"target %s not writeable!\n",target->
name);
#define vwarnopt(level, area, flags, format,...)
#define T_EVENT_IS_RANGE(event, ttype)
int os_process_disable_hw_breakpoint(struct target *target, tid_t tid, REG dreg)
void target_broadcast_event(struct target *target, struct target_event *event)
struct debugfile * debugfile_from_file(char *filename, char *root_prefix, struct array_list *debugfile_load_opts_list)
REFCNT lsymbol_release(struct lsymbol *lsymbol)
result_t probepoint_ss_handler(struct target *target, struct target_thread *tthread, struct probepoint *probepoint)
GHashTable * soft_probepoints
static uint64_t unsigned int i
#define T_EVENT_IS_REGION(event, ttype)
#define v_g_list_foreach_remove(glhead, glcur, glnext)
int target_resume(struct target *target)
#define v_g_list_foreach(glhead, glcur, elm)
#define OBJSLIVE(obj, type)
target_debug_bp_handler_t handle_break
struct target_thread * base_thread
struct os_process_spec * os_process_build_spec(void)
active_probe_flags_t ap_flags
char * debugfile_search_path(char *filename, char *root_prefix, char *debug_postfix, const char *DFPATH[], char *buf, int buflen)
int target_pause(struct target *target)
struct target_thread * global_thread
struct target * target_create(char *type, struct target_spec *spec)
struct target_ops os_process_ops
int target_associate_debugfile(struct target *target, struct memregion *region, struct debugfile *debugfile)
int(* writereg)(struct target *target, tid_t tid, REG reg, REGVAL value)
#define verror(format,...)
unsigned char * target_read_addr(struct target *target, ADDR addr, unsigned long length, unsigned char *buf)
void target_detach_thread(struct target *target, struct target_thread *tthread)
int(* writereg_tidctxt)(struct target *target, tid_t tid, thread_ctxt_t tidctxt, REG reg, REGVAL value)
struct memregion * memregion_create(struct addrspace *space, region_type_t type, char *name)
#define vwarn(format,...)
unsigned char * target_read_physaddr(struct target *target, ADDR paddr, unsigned long length, unsigned char *buf)
int(* thread_snprintf)(struct target *target, struct target_thread *tthread, char *buf, int bufsiz, int detail, char *sep, char *key_val_sep)
result_t probepoint_bp_handler(struct target *target, struct target_thread *tthread, struct probepoint *probepoint, int was_stepping)
struct target_thread * target_load_thread(struct target *target, tid_t tid, int force)
#define array_list_foreach(alist, lpc, placeholder)
struct memrange * memrange_create(struct memregion *region, ADDR start, ADDR end, OFFSET offset, unsigned int prot_flags)
struct target_thread * target_load_current_thread(struct target *target, int force)
struct target_thread * current_thread
int os_process_singlestep_end(struct target *target, tid_t tid, struct target *overlay)
struct array_list * target_list_tids(struct target *target)
int os_process_enable_hw_breakpoints(struct target *target, tid_t tid)
int target_attach_overlay_thread(struct target *base, struct target *overlay, tid_t newtid)
int target_set_active_probing(struct target *target, active_probe_flags_t flags)
int(* flush_thread)(struct target *target, tid_t tid)
unsigned long target_write_physaddr(struct target *target, ADDR paddr, unsigned long length, unsigned char *buf)
int target_memmod_unset(struct target *target, tid_t tid, struct target_memmod *mmod)
#define THREAD_CTXT_KERNEL
target_type_t target_type
REGVAL(* readreg_tidctxt)(struct target *target, tid_t tid, thread_ctxt_t tidctxt, REG reg)
int os_process_disable_hw_breakpoints(struct target *target, tid_t tid)
#define v_g_list_foreach_safe(glhead, glcur, glnext, elm)
#define vdebug(devel, areas, flags, format,...)
int target_notify_sw_breakpoint(struct target *target, ADDR addr, int notification)
struct thread_probepoint_context * tpc
struct target_process * target_os_process_get(struct target *target, tid_t tid)
unsigned int isdeclaration
struct lsymbol * debugfile_lookup_sym(struct debugfile *debugfile, char *name, const char *delim, struct rfilter *srcfile_filter, symbol_type_flag_t flags)
#define T_EVENT_IS_SPACE(event, ttype)
void os_process_free_spec(struct os_process_spec *spec)
void * calloc(size_t nmemb, size_t size)
struct array_list * debugfile_load_opts_list
void target_thread_set_status(struct target_thread *tthread, thread_status_t status)
int os_process_notify_sw_breakpoint(struct target *target, ADDR addr, int notification)
target_status_t target_status(struct target *target)
struct binfile * binfile_pointing
void target_reuse_thread_as_global(struct target *target, struct target_thread *thread)
unsigned int breakpoint_instrs_len
int os_process_enable_hw_breakpoint(struct target *target, tid_t tid, REG dreg)
int _target_remove_sw_breakpoint(struct target *target, tid_t tid, struct target_memmod *mmod)
int target_memmod_set(struct target *target, tid_t tid, struct target_memmod *mmod)
int os_process_singlestep(struct target *target, tid_t tid, int isbp, struct target *overlay)
int target_os_thread_singlestep(struct target *target, tid_t tid, int isbp, struct target *overlay, int force_emulate)
int binfile_get_root_scope_sizes(struct binfile *binfile, int *named, int *duplicated, int *anon, int *numscopes)
int(* snprintf)(struct target *target, char *buf, int bufsiz)
struct target_spec * spec
int target_memmod_set_tmp(struct target *target, tid_t tid, struct target_memmod *mmod, unsigned char *code, unsigned long code_len)
uint32_t nodisablehwbponss
#define RPUT(x, objtype, hx, rc)
REGVAL(* readreg)(struct target *target, tid_t tid, REG reg)
char * debugfile_root_prefix
struct target_thread * target_lookup_thread(struct target *target, tid_t tid)
void target_set_status(struct target *target, target_status_t status)
struct target_event * target_create_event(struct target *target, struct target_thread *thread, target_event_t type, void *priv)
unsigned long target_write_addr(struct target *target, ADDR addr, unsigned long length, unsigned char *buf)
struct target_memmod * _target_insert_sw_breakpoint(struct target *target, tid_t tid, ADDR addr, int is_phys, int nowrite)
target_debug_handler_t handle_step
result_t probepoint_interrupted_ss_handler(struct target *target, struct target_thread *tthread, struct probepoint *probepoint)
int target_addr_v2p(struct target *target, tid_t tid, ADDR vaddr, ADDR *paddr)
struct target_thread * target_create_thread(struct target *target, tid_t tid, void *tstate, void *tpstate)
#define T_EVENT_IS_OS_PROCESS(event)
target_debug_handler_t handle_interrupted_step
int target_os_thread_singlestep_end(struct target *target, tid_t tid, struct target *overlay, int force_emulate)
struct probepoint * probepoint
#define OBJSDEAD(obj, type)
struct addrspace * addrspace_create(struct target *target, char *name, ADDR tag)