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");
248 verror(
"could not load base tid %d!\n",base_tid);
258 vwarn(
"target->base_thread does not match with just-loaded thread"
259 " for %d; pid wraparound caused stale thread??\n",base_tid);
267 vwarn(
"auto-enabling SEMI_STRICT bpmode on Xen Process target.\n");
282 static int os_process_fini(
struct target *target) {
288 static int os_process_attach(
struct target *target) {
308 static int os_process_detach(
struct target *target,
int stay_paused) {
315 static int os_process_loadspaces(
struct target *target) {
337 verror(
"could not load process from underlying OS; not updating!\n");
341 snprintf(nbuf,
sizeof(nbuf),
"os_process(%d)",target->
base_tid);
348 static int os_process_loadregions(
struct target *target,
352 GList *t1,*t2,*t11,*t22,*t2x,*t22x;
366 verror(
"could not load process from underlying OS; not updating!\n");
396 && ((region1->
name == NULL && region2->
name == NULL)
398 && strcmp(region1->
name,region2->
name) == 0)))
404 #warning "generate MOD events"
406 if (region2 == NULL) {
422 if (range2 == NULL) {
429 else if (range1->
end != range2->
end
479 static int os_process_loaddebugfiles(
struct target *target,
499 if (!region->
name || strlen(region->
name) == 0)
510 NULL,NULL,rbuf,PATH_MAX)) {
511 verror(
"could not find debugfile for region '%s': %s\n",
512 region->
name,strerror(errno));
521 verror(
"still could not find debugfile for region '%s': %s\n",
522 region->
name,strerror(errno));
581 static int os_process_postloadinit(
struct target *target) {
586 static int os_process_set_active_probing(
struct target *target,
594 flags &= ~APF_THREAD_ENTRY;
603 flags &= ~APF_THREAD_EXIT;
612 flags &= ~APF_MEMORY;
629 static struct target *
630 os_process_instantiate_overlay(
struct target *target,
634 struct target *overlay;
655 os_process_lookup_overlay_thread_by_id(
struct target *target,
int id) {
661 retval = os_process_load_thread(target,
id,0);
672 os_process_lookup_overlay_thread_by_name(
struct target *target,
char *
name) {
678 if ((rc = os_process_load_all_threads(target,0)))
679 vwarn(
"could not load %d threads; continuing anyway!\n",-rc);
681 g_hash_table_iter_init(&iter,target->
threads);
682 while (g_hash_table_iter_next(&iter,NULL,(gpointer)&tthread)) {
685 else if (tthread->name && strcmp(tthread->name,name) == 0) {
693 "found overlay thread %"PRIiTID"\n",retval->
tid);
703 os_process_handle_overlay_exception(
struct target *overlay,
709 struct os_state *xstate;
711 xstate = (
struct os_state *)overlay->
base->
state;
732 os_process_loadregions(overlay,(
struct addrspace *) \
733 g_list_nth_data(overlay->
spaces,0));
776 "single step event in overlay tid %"PRIiTID" INTO KERNEL"
777 " (at 0x%"PRIxADDR"); aborting breakpoint singlestep;"
778 " will be hit again!\n",
804 verror(
"unhandled overlay exception; will return ERROR!\n");
822 static void os_process_handle_event(
struct target *target,
829 tthread =
event->thread;
840 os_process_loadregions(target,space);
845 verror(
"malformed THREAD_CREATED event without thread set!\n");
854 "underlying target tid %d is new; but already have it!\n",
870 verror(
"malformed THREAD_EXIT(ED|ING) event without thread set!\n");
880 "underlying target tid %d is exit(ed|ing);"
881 " but we do not have it!\n",tthread->
tid);
899 static int os_process_pause(
struct target *target,
int nowait) {
910 static int os_process_resume(
struct target *target) {
929 static int __is_our_tid(
struct target *target,
tid_t tid) {
930 if (g_hash_table_lookup(target->
threads,(gpointer)(uintptr_t)tid))
936 static int __we_are_current(
struct target *target) {
944 static unsigned char *os_process_read(
struct target *target,
ADDR addr,
945 unsigned long length,
unsigned char *buf) {
957 if (__we_are_current(target))
971 static unsigned long os_process_write(
struct target *target,
ADDR addr,
972 unsigned long length,
unsigned char *buf) {
975 if (__we_are_current(target))
989 static tid_t os_process_gettid(
struct target *target) {
998 tthread = os_process_load_current_thread(target,0);
1000 verror(
"could not load current thread to get TID!\n");
1004 return tthread->
tid;
1007 static void os_process_free_thread_state(
struct target *target,
void *
state) {
1014 os_process_list_available_tids(
struct target *target) {
1017 retval = array_list_create(1);
1018 array_list_append(retval,(
void *)(uintptr_t)target->
base_tid);
1024 os_process_load_thread(
struct target *target,
tid_t tid,
int force) {
1025 if (!__is_our_tid(target,tid)) {
1038 os_process_load_current_thread(
struct target *target,
int force) {
1043 verror(
"could not load base target current thread: %s\n",
1050 if (!__is_our_tid(target,uthread->
tid)) {
1052 "base target current tid %d is not in tgid %d!\n",
1065 static int os_process_load_all_threads(
struct target *target,
int force) {
1066 if (os_process_load_thread(target,target->
base_tid,force))
1071 static int os_process_load_available_threads(
struct target *target,
1073 if (os_process_load_thread(target,target->
base_tid,force))
1078 static int os_process_flush_thread(
struct target *target,
tid_t tid) {
1086 if (!__is_our_tid(target,tid)) {
1094 verror(
"could not flush base target tid %d: %s\n",tid,strerror(errno));
1103 static int os_process_flush_current_thread(
struct target *target) {
1109 static int os_process_flush_all_threads(
struct target *target) {
1117 rc += os_process_flush_thread(target,(
tid_t)(uintptr_t)tid);
1123 static int os_process_thread_snprintf(
struct target *target,
1125 char *buf,
int bufsiz,
1126 int detail,
char *sep,
char *kvsep) {
1127 if (!__is_our_tid(target,tthread->
tid)) {
1128 verror(
"tid %d is not in tgid %d!\n",
1135 buf,bufsiz,detail,sep,kvsep);
1138 static REGVAL os_process_read_reg(
struct target *target,
tid_t tid,
REG reg) {
1141 if (!__is_our_tid(target,tid)) {
1156 static int os_process_write_reg(
struct target *target,
tid_t tid,
REG reg,
1161 if (!__is_our_tid(target,tid)) {
1183 os_process_insert_sw_breakpoint(
struct target *target,
1212 static int os_process_remove_sw_breakpoint(
struct target *target,
tid_t tid,
1217 static int os_process_enable_sw_breakpoint(
struct target *target,
tid_t tid,
1222 static int os_process_disable_sw_breakpoint(
struct target *target,
tid_t tid,
1227 static int os_process_change_sw_breakpoint(
struct target *target,
tid_t tid,
1229 unsigned char *code,
1230 unsigned long code_len) {
1234 static REG os_process_get_unused_debug_reg(
struct target *target,
tid_t tid) {
1245 struct target *overlay) {
1250 struct target *overlay) {
#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
#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)
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)