Stackdb
Stackdb is a stackable, multi-target and -level source debugger and memory forensics library.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
target_os_process.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013, 2014, 2015, 2016 The University of Utah
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of
7  * the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 
19 #include <sys/types.h>
20 #include <sys/stat.h>
21 #include <unistd.h>
22 #include <glib.h>
23 
24 #include "common.h"
25 #include "glib_wrapper.h"
26 #include "object.h"
27 #include "binfile.h"
28 #include "target.h"
29 #include "target_api.h"
30 #include "target_event.h"
31 #include "target_os.h"
33 #include "target_os.h"
34 #include "target_os_process.h"
35 
37  return NULL;
38 }
39 
41  return;
42 }
43 
44 /*
45  * Prototypes.
46  */
47 static int os_process_snprintf(struct target *target,char *buf,int bufsiz);
48 static int os_process_init(struct target *target);
49 static int os_process_postloadinit(struct target *target);
50 static int os_process_attach(struct target *target);
51 static int os_process_detach(struct target *target,int stay_paused);
52 static int os_process_fini(struct target *target);
53 static int os_process_loadspaces(struct target *target);
54 static int os_process_loadregions(struct target *target,struct addrspace *space);
55 static int os_process_loaddebugfiles(struct target *target,
56  struct addrspace *space,
57  struct memregion *region);
58 static target_status_t
59 os_process_handle_overlay_exception(struct target *overlay,
61  tid_t tid,ADDR ipval,int *again);
62 static void os_process_handle_event(struct target *target,
63  struct target_event *event);
64 static struct target *
65 os_process_instantiate_overlay(struct target *target,
66  struct target_thread *tthread,
67  struct target_spec *spec,
68  struct target_thread **ntthread);
69 static struct target_thread *
70 os_process_lookup_overlay_thread_by_id(struct target *target,int id);
71 static struct target_thread *
72 os_process_lookup_overlay_thread_by_name(struct target *target,char *name);
73 
74 static target_status_t os_process_status(struct target *target);
75 static int os_process_pause(struct target *target,int nowait);
76 static int os_process_resume(struct target *target);
77 static unsigned char *os_process_read(struct target *target,ADDR addr,
78  unsigned long length,unsigned char *buf);
79 static unsigned long os_process_write(struct target *target,ADDR addr,
80  unsigned long length,unsigned char *buf);
81 
82 static tid_t os_process_gettid(struct target *target);
83 static void os_process_free_thread_state(struct target *target,void *state);
84 static struct array_list *os_process_list_available_tids(struct target *target);
85 static struct target_thread *os_process_load_thread(struct target *target,
86  tid_t tid,int force);
87 static struct target_thread *os_process_load_current_thread(struct target *target,
88  int force);
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);
91 static int os_process_flush_thread(struct target *target,tid_t tid);
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,
95  struct target_thread *tthread,
96  char *buf,int bufsiz,
97  int detail,char *sep,char *kvsep);
98 
99 static REGVAL os_process_read_reg(struct target *target,tid_t tid,REG reg);
100 static int os_process_write_reg(struct target *target,tid_t tid,REG reg,
101  REGVAL value);
102 static struct target_memmod *
103 os_process_insert_sw_breakpoint(struct target *target,
104  tid_t tid,ADDR addr);
105 static int os_process_remove_sw_breakpoint(struct target *target,tid_t tid,
106  struct target_memmod *mmod);
107 static int os_process_enable_sw_breakpoint(struct target *target,tid_t tid,
108  struct target_memmod *mmod);
109 static int os_process_disable_sw_breakpoint(struct target *target,tid_t tid,
110  struct target_memmod *mmod);
111 static int os_process_change_sw_breakpoint(struct target *target,tid_t tid,
112  struct target_memmod *mmod,
113  unsigned char *code,
114  unsigned long code_len);
115 static REG os_process_get_unused_debug_reg(struct target *target,tid_t tid);
116 static int os_process_set_hw_breakpoint(struct target *target,tid_t tid,
117  REG num,ADDR addr);
118 static int os_process_set_hw_watchpoint(struct target *target,tid_t tid,
119  REG num,ADDR addr,
120  probepoint_whence_t whence,
121  probepoint_watchsize_t watchsize);
122 static int os_process_unset_hw_breakpoint(struct target *target,tid_t tid,
123  REG num);
124 static int os_process_unset_hw_watchpoint(struct target *target,tid_t tid,
125  REG num);
129  REG dreg);
131  REG dreg);
133  int notification);
134 int os_process_singlestep(struct target *target,tid_t tid,int isbp,
135  struct target *overlay);
137  struct target *overlay);
138 
140  .snprintf = os_process_snprintf,
141 
142  .init = os_process_init,
143  .fini = os_process_fini,
144  .attach = os_process_attach,
145  .detach = os_process_detach,
146  .kill = NULL,
147  .loadspaces = os_process_loadspaces,
148  .loadregions = os_process_loadregions,
149  .loaddebugfiles = os_process_loaddebugfiles,
150  .postloadinit = os_process_postloadinit,
151 
152  .set_active_probing = NULL,
153 
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,
157 
158  .handle_overlay_exception = os_process_handle_overlay_exception,
159  .handle_break = probepoint_bp_handler,
160  .handle_step = probepoint_ss_handler,
161  .handle_interrupted_step = probepoint_interrupted_ss_handler,
162  .handle_event = os_process_handle_event,
163 
164  .status = os_process_status,
165  .pause = os_process_pause,
166  .resume = os_process_resume,
167  .monitor = NULL,
168  .poll = NULL,
169  .read = os_process_read,
170  .write = os_process_write,
171 
172  .gettid = os_process_gettid,
173  .free_thread_state = os_process_free_thread_state,
174 
175  /* There are never any untracked threads in this target. */
176  .list_available_tids = target_list_tids,
177  /* There are never any untracked threads in this target. */
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,
187 
188  .attach_evloop = NULL,
189  .detach_evloop = NULL,
190 
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,
199  //.set_hw_breakpoint = os_process_set_hw_breakpoint,
200  //.set_hw_watchpoint = os_process_set_hw_watchpoint,
201  //.unset_hw_breakpoint = os_process_unset_hw_breakpoint,
202  //.unset_hw_watchpoint = os_process_unset_hw_watchpoint,
203  //.disable_hw_breakpoints = os_process_disable_hw_breakpoints,
204  //.enable_hw_breakpoints = os_process_enable_hw_breakpoints,
205  //.disable_hw_breakpoint = os_process_disable_hw_breakpoint,
206  //.enable_hw_breakpoint = os_process_enable_hw_breakpoint,
207  .notify_sw_breakpoint = os_process_notify_sw_breakpoint,
208  .singlestep = os_process_singlestep,
209  .singlestep_end = os_process_singlestep_end,
210 };
211 
212 static int os_process_snprintf(struct target *target,
213  char *buf,int bufsiz) {
214  return snprintf(buf,bufsiz,"task(%d)",target->base_tid);
215 }
216 
217 static int os_process_init(struct target *target) {
218  struct target_thread *base_thread = target->base_thread;
219  struct target *base = target->base;
220  tid_t base_tid = target->base_tid;
221 
222  if (target->spec->stay_paused) {
223  verror("OS Process driver cannot leave target process closed on exit!\n");
224  errno = EINVAL;
225  return -1;
226  }
227 
228  /*
229  * Setup target mode stuff.
230  */
231  target->threadctl = base->threadctl;
232  target->nodisablehwbponss = base->nodisablehwbponss;
233  target->live = base->live;
234  target->mmapable = base->mmapable;
235  target->no_adjust_bp_ip = 0;
236  /* NB: only native arch supported! i.e., no 32-bit emu on 64-bit host. */
237  target->arch = base->arch;
238 
239  target->fbregno = base->fbregno;
240  target->spregno = base->spregno;
241  target->ipregno = base->ipregno;
242 
243  /*
244  * Make sure the base thread is loaded.
245  */
246  if (!(base_thread = target_load_thread(base,base_tid,0))) {
247  verror("could not load base tid %d!\n",base_tid);
248  return -1;
249  }
250  else if (base_thread != target->base_thread) {
251  /*
252  * Catch stale threads; if there is a huge delay between
253  * target_instantiate and target_open, this could potentially
254  * happen -- but PID wraparound in the kernel would have to
255  * happen mighty fast! Unlikely.
256  */
257  vwarn("target->base_thread does not match with just-loaded thread"
258  " for %d; pid wraparound caused stale thread??\n",base_tid);
259  target->base_thread = base_thread;
260  }
261 
262  /*
263  * Just adjust for the user, don't error :)
264  */
265  if (target->spec->bpmode == THREAD_BPMODE_STRICT) {
266  vwarn("auto-enabling SEMI_STRICT bpmode on Xen Process target.\n");
268  }
269 
270  /*
271  * Initialize our state.
272  */
273  target->state = calloc(1,sizeof(struct os_process_state));
274 
275  /*
276  * Don't do anything else here; do it in attach().
277  */
278  return 0;
279 }
280 
281 static int os_process_fini(struct target *target) {
282  if (target->state)
283  free(target->state);
284  return 0;
285 }
286 
287 static int os_process_attach(struct target *target) {
288  if (target_pause(target->base)) {
289  verror("could not pause base target %s!\n",target->base->name);
290  return -1;
291  }
292 
294 
295  /*
296  * Just grab all the threads in the thread group and create them.
297  */
298  target->current_thread = target_create_thread(target,target->base_tid,
299  NULL,NULL);
301 
303 
304  return 0;
305 }
306 
307 static int os_process_detach(struct target *target,int stay_paused) {
308  /*
309  * Just detach all our threads.
310  */
311  return 0;
312 }
313 
314 static int os_process_loadspaces(struct target *target) {
315  struct os_process_state *ospstate;
316  struct target_process *process;
317  char nbuf[32];
318 
319  ospstate = (struct os_process_state *)target->state;
320  /*
321  * NB: between os_process_handle_event, os_process_loadregions, and
322  * target_os_process_get(), there is a loop! Break it by not
323  * allowing any memory events that are bubbled up into
324  * os_process_handle_event() to cause os_process_loadregions() to
325  * get called multiple times -- or in this case, right here, we
326  * don't want os_process_loadregions() to get called until after
327  * os_process_loadspaces() finishes.
328  */
329  if (ospstate->loading_memory)
330  return 0;
331  else
332  ospstate->loading_memory = 1;
333 
334  process = target_os_process_get(target->base,target->base_tid);
335  if (!process) {
336  verror("could not load process from underlying OS; not updating!\n");
337  ospstate->loading_memory = 0;
338  return -1;
339  }
340  snprintf(nbuf,sizeof(nbuf),"os_process(%d)",target->base_tid);
341  addrspace_create(target,nbuf,process->space->tag);
342  ospstate->loading_memory = 0;
343 
344  return 0;
345 }
346 
347 static int os_process_loadregions(struct target *target,
348  struct addrspace *space) {
349  struct os_process_state *ospstate;
350  struct target_process *process;
351  GList *t1,*t2,*t11,*t22,*t2x,*t22x;
352  struct memregion *region1,*region2;
353  struct memrange *range1,*range2;
354  struct target_event *event;
355  REFCNT trefcnt;
356 
357  ospstate = (struct os_process_state *)target->state;
358  if (ospstate->loading_memory)
359  return 0;
360  else
361  ospstate->loading_memory = 1;
362 
363  process = target_os_process_get(target->base,target->base_tid);
364  if (!process) {
365  verror("could not load process from underlying OS; not updating!\n");
366  ospstate->loading_memory = 0;
367  return -1;
368  }
369 
370  /*
371  * Take process->space, and update our target->space to mirror it!
372  */
373 
374  /* Mark our existing space, regions, and ranges as dead. */
375  OBJSDEAD(space,addrspace);
376 
377  if (process->space->tag != space->tag) {
378  /*
379  * NB: necessary to catch processes whose VM is replaced,
380  * i.e. on exec(). Just update our tag; not much else we can
381  * do.
382  */
383  space->tag = process->space->tag;
384  }
385 
386  /*
387  * Now, update, add, or mark live the ones that match.
388  */
389 
390  /* Now compare the regions and ranges in the spaces: */
391  v_g_list_foreach(process->space->regions,t1,region1) {
392  v_g_list_foreach(space->regions,t2,region2) {
393  if (region1->type == region2->type
394  && region1->base_load_addr == region2->base_load_addr
395  && ((region1->name == NULL && region2->name == NULL)
396  || (region1->name && region2->name
397  && strcmp(region1->name,region2->name) == 0)))
398  break;
399  else
400  region2 = NULL;
401  }
402 
403 #warning "generate MOD events"
404 
405  if (region2 == NULL) {
406  region2 = memregion_create(space,region1->type,region1->name);
407  event = target_create_event(target,NULL,
409  target_broadcast_event(target,event);
410  }
411 
412  /* Now compare the ranges. */
413  v_g_list_foreach(region1->ranges,t11,range1) {
414  v_g_list_foreach(region2->ranges,t22,range2) {
415  if (range1->start == range2->start)
416  break;
417  else
418  range2 = NULL;
419  }
420 
421  if (range2 == NULL) {
422  range2 = memrange_create(region2,range1->start,range1->end,
423  range1->offset,range1->prot_flags);
424  event = target_create_event(target,NULL,
426  target_broadcast_event(target,event);
427  }
428  else if (range1->end != range2->end
429  || range1->prot_flags != range2->prot_flags
430  || range1->offset != range2->offset) {
431  event = target_create_event(target,NULL,
433  target_broadcast_event(target,event);
434  OBJSMOD(range2);
435  }
436 
437  OBJSLIVE(range2,memrange);
438  }
439 
440  /* Now delete any dead ranges: */
441  v_g_list_foreach_safe(region2->ranges,t22,t22x,range2) {
442  if (!OBJLIVE(range2)) {
443  event = target_create_event(target,NULL,
445  target_broadcast_event(target,event);
446 
447  v_g_list_foreach_remove(region2->ranges,t22,t22x);
448  RPUT(range2,memrange,region2,trefcnt);
449  }
450  }
451 
452  /* Mark the region (and all its ranges) as live. */
453  OBJSLIVE(region2,memregion);
454  }
455 
456  /* Now delete any dead regions: */
457  v_g_list_foreach_safe(space->regions,t2,t2x,region2) {
458  if (!OBJLIVE(region2)) {
459  event = target_create_event(target,NULL,
461  target_broadcast_event(target,event);
462 
463  v_g_list_foreach_remove(space->regions,t2,t2x);
464  RPUT(region2,memregion,space,trefcnt);
465  }
466  }
467 
468  /*
469  * Finally, mark it all as live.
470  */
471  OBJSLIVE(space,addrspace);
472 
473  ospstate->loading_memory = 0;
474 
475  return 0;
476 }
477 
478 static int os_process_loaddebugfiles(struct target *target,
479  struct addrspace *space,
480  struct memregion *region) {
481  int retval = -1;
482  struct debugfile *debugfile = NULL;
483  char rbuf[PATH_MAX];
484  char *file;
485  struct lsymbol *mainsymbol;
486  int bfn = 0;
487  int bfpn = 0;
488 
489  vdebug(5,LA_TARGET,LF_OSP,"tid %d\n",target->base_tid);
490 
491  if (!(region->type == REGION_TYPE_MAIN
492  || region->type == REGION_TYPE_LIB)) {
493  vdebug(4,LA_TARGET,LF_OSP,"region %s is not MAIN nor LIB; skipping!\n",
494  region->name);
495  return 0;
496  }
497 
498  if (!region->name || strlen(region->name) == 0)
499  return -1;
500 
501  /* Try to find it, given all our paths and prefixes... */
502  file = region->name;
503  debugfile = debugfile_from_file(file,
504  target->spec->debugfile_root_prefix,
505  target->spec->debugfile_load_opts_list);
506  if (!debugfile) {
507  if (!debugfile_search_path(region->name,
508  target->spec->debugfile_root_prefix,
509  NULL,NULL,rbuf,PATH_MAX)) {
510  verror("could not find debugfile for region '%s': %s\n",
511  region->name,strerror(errno));
512  return -1;
513  }
514 
515  file = rbuf;
516  debugfile = debugfile_from_file(file,
517  target->spec->debugfile_root_prefix,
518  target->spec->debugfile_load_opts_list);
519  if (!debugfile) {
520  verror("still could not find debugfile for region '%s': %s\n",
521  region->name,strerror(errno));
522  return -1;
523  }
524  }
525 
526  if (target_associate_debugfile(target,region,debugfile)) {
527  goto out;
528  }
529 
530  /*
531  * Try to figure out which binfile has the info we need. On
532  * different distros, they're stripped different ways.
533  */
534  if (debugfile->binfile_pointing) {
535  binfile_get_root_scope_sizes(debugfile->binfile,&bfn,NULL,NULL,NULL);
537  NULL,NULL,NULL);
538  if (bfpn > bfn) {
539  RHOLD(debugfile->binfile_pointing,region);
540  region->binfile = debugfile->binfile_pointing;
541  }
542  }
543 
544  if (!region->binfile) {
545  RHOLD(debugfile->binfile,region);
546  region->binfile = debugfile->binfile;
547  }
548 
549  if (!target->arch) {
550  target->arch = debugfile->binfile->arch;
551  }
552 
553  /*
554  * Change type to REGION_TYPE_MAIN if it had a main() function.
555  */
556  if (region->type == REGION_TYPE_LIB) {
557  mainsymbol = debugfile_lookup_sym(debugfile,"main",NULL,NULL,SYMBOL_TYPE_FUNC);
558  if (mainsymbol) {
559  if (!mainsymbol->symbol->isdeclaration)
560  region->type = REGION_TYPE_MAIN;
561  lsymbol_release(mainsymbol);
562  }
563  }
564 
565  /*
566  * Propagate some binfile info...
567  */
568  region->base_phys_addr = region->binfile->base_phys_addr;
569  region->base_virt_addr = region->binfile->base_virt_addr;
570 
571  retval = 0;
572 
573  out:
574  return retval;
575 
576 }
577  /* Once regions and debugfiles are loaded, we call this -- it's a
578  * second-pass init, basically.
579  */
580 static int os_process_postloadinit(struct target *target) {
581 
582  return 0;
583 }
584 
585 static int os_process_set_active_probing(struct target *target,
586  active_probe_flags_t flags) {
587  active_probe_flags_t baseflags = 0;
588 
589  if (!target->writeable && flags != AFP_NONE) {
590  verror("target %s not writeable!\n",target->name);
591  errno = EROFS;
592  return -1;
593  }
594 
595  /*
596  * Filter out the default flags according to our personality.
597  */
598  if (flags & APF_THREAD_ENTRY) {
599  flags &= ~APF_THREAD_ENTRY;
600  flags |= APF_PROCESS_THREAD_ENTRY;
601  /*
602  * Just use the OS thread tracking; it's the same (at least for
603  * Linux -- probably shouldn't assume it in general...
604  */
605  baseflags |= APF_OS_THREAD_ENTRY;
606  }
607  if (flags & APF_THREAD_EXIT) {
608  flags &= ~APF_THREAD_EXIT;
609  flags |= APF_PROCESS_THREAD_EXIT;
610  /*
611  * Just use the OS thread tracking; it's the same (at least for
612  * Linux -- probably shouldn't assume it in general...
613  */
614  baseflags |= APF_OS_THREAD_EXIT;
615  }
616  if (flags & APF_MEMORY) {
617  flags &= ~APF_MEMORY;
618  flags |= APF_PROCESS_MEMORY;
619  }
620 
621  /*
622  * XXX: only allow user to set/unset process flags; we're going to
623  * pass this to underlying target; so the user should not be able to
624  * disable anything. This isn't really good enough... we should
625  * track who needs which flags.
626  */
627  flags &= APF_PROCESS | APF_OS;
628 
629  /* XXX: should we pass baseflags | target->base->ap_flags ? */
630  return target_set_active_probing(target->base,baseflags);
631 
632 }
633 
634 static struct target *
635 os_process_instantiate_overlay(struct target *target,
636  struct target_thread *tthread,
637  struct target_spec *spec,
638  struct target_thread **ntthread) {
639  struct target *overlay;
640 
641  if (!spec) {
642  errno = EINVAL;
643  return NULL;
644  }
645 
646  if (spec->target_type != TARGET_TYPE_PHP) {
647  errno = EINVAL;
648  return NULL;
649  }
650 
651  /*
652  * All we want to do here is create the overlay target.
653  */
654  overlay = target_create("php",spec);
655 
656  return overlay;
657 }
658 
659 static struct target_thread *
660 os_process_lookup_overlay_thread_by_id(struct target *target,int id) {
661  struct target_thread *retval;
662 
663  if (id < 0)
664  id = TID_GLOBAL;
665 
666  retval = os_process_load_thread(target,id,0);
667  if (!retval) {
668  if (!errno)
669  errno = ESRCH;
670  return NULL;
671  }
672 
673  return retval;
674 }
675 
676 static struct target_thread *
677 os_process_lookup_overlay_thread_by_name(struct target *target,char *name) {
678  struct target_thread *retval = NULL;
679  struct target_thread *tthread;
680  int rc;
681  GHashTableIter iter;
682 
683  if ((rc = os_process_load_all_threads(target,0)))
684  vwarn("could not load %d threads; continuing anyway!\n",-rc);
685 
686  g_hash_table_iter_init(&iter,target->threads);
687  while (g_hash_table_iter_next(&iter,NULL,(gpointer)&tthread)) {
688  if (tthread == target->global_thread)
689  continue;
690  else if (tthread->name && strcmp(tthread->name,name) == 0) {
691  retval = tthread;
692  break;
693  }
694  }
695 
696  if (retval) {
698  "found overlay thread %"PRIiTID"\n",retval->tid);
699  return tthread;
700  }
701  else {
702  errno = ESRCH;
703  return NULL;
704  }
705 }
706 
707 static target_status_t
708 os_process_handle_overlay_exception(struct target *overlay,
710  tid_t tid,ADDR ipval,int *again) {
711  struct target_thread *tthread;
712  struct target_thread *uthread;
713  struct probepoint *dpp;
714  struct os_state *xstate;
715 
716  xstate = (struct os_state *)overlay->base->state;
717 
718  tthread = target_lookup_thread(overlay,tid);
719  if (!tthread) {
720  /*
721  * This is a new thread the overlay is insisting we manage!
722  * Just Do It.
723  */
724  tthread = target_create_thread(overlay,tid,NULL,NULL);
726  target_attach_overlay_thread(overlay->base,overlay,tid);
727  }
728 
729  /*
730  * If not active probing memory, we kind of want to update our
731  * addrspaces aggressively (by checking the underlying OS target's
732  * process addrspace) so that if a user lookups a module symbol, we
733  * already have it. Really we should do this more lazily, like if a
734  * lookup failed, maybe.
735  */
736  if (!(overlay->ap_flags & APF_PROCESS_MEMORY)) {
737  os_process_loadregions(overlay,(struct addrspace *) \
738  g_list_nth_data(overlay->spaces,0));
739  }
740 
741  if (flags & EXCEPTION_BREAKPOINT) {
742  vdebug(3,LA_TARGET,LF_OSP,"new (breakpoint?) debug event\n");
743 
744  dpp = (struct probepoint *) \
745  g_hash_table_lookup(overlay->soft_probepoints,
746  (gpointer)(ipval - overlay->arch->breakpoint_instrs_len));
747  if (dpp) {
748  /* Run the breakpoint handler. */
749  overlay->ops->handle_break(overlay,tthread,dpp,
750  (flags & EXCEPTION_SINGLESTEP)
751  | (flags & EXCEPTION_SINGLESTEP_CMD));
752 
753  OBJSDIRTY(tthread);
754  vdebug(5,LA_TARGET,LF_OSP,"cleared status debug reg 6\n");
755 
756  goto out_bp_again;
757  }
758  }
759 
760  /* It will be loaded and valid; so just read regs and handle. */
761  if (flags & EXCEPTION_SINGLESTEP || flags & EXCEPTION_SINGLESTEP_CMD) {
762  vdebug(3,LA_TARGET,LF_OSP,"new single step debug event\n");
763 
764  if (!tthread->tpc) {
765  verror("unexpected singlestep event at ip 0x%"PRIxADDR
766  " in tid %"PRIiTID"!\n",
767  ipval,tid);
768  goto out_err;
769  }
770 
771  /*
772  * If this was supposed to be a single step in userspace, but
773  * instead we have stepped into the kernel, we have to abort the
774  * single step. This can only happen in the HVM case when we
775  * use the Monitor Trap Flag.
776  */
777  if (flags & EXCEPTION_SINGLESTEP_BOGUS) {
778  /*xstate->hvm && xstate->hvm_monitor_trap_flag_set
779  && ipval >= xstate->kernel_start_addr*/
781  "single step event in overlay tid %"PRIiTID" INTO KERNEL"
782  " (at 0x%"PRIxADDR"); aborting breakpoint singlestep;"
783  " will be hit again!\n",
784  tid,ipval);
785  overlay->ops->handle_interrupted_step(overlay,tthread,
786  tthread->tpc->probepoint);
787  }
788  else
789  overlay->ops->handle_step(overlay,tthread,tthread->tpc->probepoint);
790 
791  OBJSDIRTY(tthread);
792  /*
793  * MUST DO THIS. If we are going to modify both the
794  * current thread's CPU state possibly, and possibly
795  * operate on the global thread's CPU state, we need
796  * to clear the global thread's debug reg status
797  * here; this also has the important side effect of
798  * forcing a merge of the global thread's debug reg
799  * state; see flush_global_thread !
800  */
801  /*
802  gtstate->context.debugreg[6] = 0;
803  target->global_thread->dirty = 1;
804  vdebug(5,LA_TARGET,LF_XV,"cleared status debug reg 6\n");
805  */
806  goto out_ss_again;
807  }
808 
809  verror("unhandled overlay exception; will return ERROR!\n");
810 
811  out_err:
812  if (again)
813  *again = 0;
814  return TSTATUS_ERROR;
815 
816  out_bp_again:
817  if (again)
818  *again = 1;
819  return TSTATUS_PAUSED;
820 
821  out_ss_again:
822  if (again)
823  *again = 2;
824  return TSTATUS_PAUSED;
825 }
826 
827 static void os_process_handle_event(struct target *target,
828  struct target_event *event) {
829  struct addrspace *space;
830  target_event_t et;
831  struct target_thread *tthread,*othread;
832 
833  et = event->type;
834  tthread = event->thread;
835  space = (struct addrspace *)g_list_nth_data(target->spaces,0);
836 
837  if (T_EVENT_IS_OS_PROCESS(event)
838  && (T_EVENT_IS_SPACE(event,OS_PROCESS)
839  || T_EVENT_IS_REGION(event,OS_PROCESS)
840  || T_EVENT_IS_RANGE(event,OS_PROCESS))) {
841  /*
842  * We definitely could optimize this, and only handle the
843  * specific change in the event... but eh.
844  */
845  os_process_loadregions(target,space);
846  }
847  else if (et == T_EVENT_OS_THREAD_CREATED
849  if (!tthread) {
850  verror("malformed THREAD_CREATED event without thread set!\n");
851  return;
852  }
853  if (tthread->tid == target->base_tid)
854  /* Ignore our main thread; we already created it. */
855  return;
856  if (target_lookup_thread(target,tthread->tid)) {
857  /* Ignore; we already have it (somehow?) */
859  "underlying target tid %d is new; but already have it!\n",
860  tthread->tid);
861  return;
862  }
863  else {
864  /*
865  * Create a new thread.
866  */
867  target_create_thread(target,tthread->tid,NULL,NULL);
868  }
869  }
870  else if (et == T_EVENT_OS_THREAD_EXITED
874  if (!tthread) {
875  verror("malformed THREAD_EXIT(ED|ING) event without thread set!\n");
876  return;
877  }
878  if (tthread->tid == target->base_tid)
879  /* Ignore our main thread; let it get detached with target */
880  return;
881  othread = target_lookup_thread(target,tthread->tid);
882  if (!othread) {
883  /* Ignore; we never hda it (somehow?) */
885  "underlying target tid %d is exit(ed|ing);"
886  " but we do not have it!\n",tthread->tid);
887  return;
888  }
889  else {
890  /*
891  * Detach this thread from the target.
892  */
893  target_detach_thread(target,othread);
894  }
895  }
896 
897  return;
898 }
899 
900 static target_status_t os_process_status(struct target *target) {
901  return target_status(target->base);
902 }
903 
904 static int os_process_pause(struct target *target,int nowait) {
905  int rc;
906 
907  rc = target_pause(target->base);
908  if (rc)
909  return rc;
910  target_set_status(target,target->base->status);
911 
912  return 0;
913 }
914 
915 static int os_process_resume(struct target *target) {
916  int rc;
917 
918  rc = target_resume(target->base);
919  if (rc)
920  return rc;
921  target_set_status(target,target->base->status);
922 
923  return 0;
924 }
925 
926 /*
927  * XXX:
928  *
929  * Need to load/unload any new/stale threads in this function;
930  * everything calls it, basically. We need to keep a state bit in the
931  * os_process_state struct saying if we scanned the list this pass
932  * yet or not (and we can replace this with active probing, of course).
933  */
934 static int __is_our_tid(struct target *target,tid_t tid) {
935  if (g_hash_table_lookup(target->threads,(gpointer)(uintptr_t)tid))
936  return 1;
937  else
938  return 0;
939 }
940 
941 static int __we_are_current(struct target *target) {
942  if (target->base->current_thread
943  && __is_our_tid(target,target->base->current_thread->tid))
944  return 1;
945  else
946  return 0;
947 }
948 
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;
953 
954  /*
955  * If we are the current thread in the base target, this is easy --
956  * just read the current thread in the base. Otherwise, do v2p
957  * translation and read phys.
958  *
959  * XXX: for future, backend API read/write calls probably should
960  * have just been parameterized by tid! But this is what the
961  * underlying target would have to do anyway...
962  */
963  if (__we_are_current(target))
964  return target_read_addr(target->base,addr,length,buf);
965  else {
966  /*
967  * Resolve the phys page.
968  *
969  * We do not know the v2p mapping, so we must translate each
970  * virt page the user wishes to read into a physical page, and
971  * read whatever chunks they want. Sigh.
972  */
973  clen = 0;
974  raddr = addr;
975  while (clen < length) {
976  if (target_addr_v2p(target->base,target->base_tid,raddr,&paddr)) {
977  verror("could not translate vaddr 0x%"PRIxADDR
978  " in tid %"PRIiTID"!\n",
979  raddr,target->base_tid);
980  return NULL;
981  }
982  offset = raddr & (PAGE_SIZE - 1);
983  tlen = PAGE_SIZE - offset;
984  tlen = (tlen < (length - clen)) ? tlen : (length - clen);
985  if (!target_read_physaddr(target->base,paddr,tlen,buf + clen)) {
986  verror("could not read paddr %"PRIxADDR" for vaddr %"PRIxADDR
987  " len %ld in tid %"PRIiTID"!\n",
988  paddr,raddr,tlen,target->base_tid);
989  return NULL;
990  }
991  clen += tlen;
992  raddr += tlen;
993  }
994 
995  return buf;
996  }
997 }
998 
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;
1003  unsigned char byte;
1004 
1005  if (!target->writeable) {
1006  verror("target %s not writeable!\n",target->name);
1007  errno = EROFS;
1008  return 0;
1009  }
1010 
1011  if (__we_are_current(target))
1012  return target_write_addr(target->base,addr,length,buf);
1013  else {
1014  /*
1015  * Resolve the phys page.
1016  *
1017  * We do not know the v2p mapping, so we must translate each
1018  * virt page the user wishes to read into a physical page, and
1019  * read whatever chunks they want. Sigh.
1020  *
1021  * In an effort to ensure safety, we assume that if we can
1022  * resolve all the v2p mappings and read a byte from each page,
1023  * that the page is present. So we actually do all those checks
1024  * before writing anything. These checks of course are racy if
1025  * the VM is not paused, but right now it's the best we can do.
1026  * The only other solution would be to hack the hypervisor page
1027  * protection bits, which would be super-heavyweight. And we're
1028  * not going to do that anytime soon!
1029  */
1030  clen = 0;
1031  raddr = addr;
1032  while (clen < length) {
1033  if (target_addr_v2p(target->base,target->base_tid,raddr,&paddr)) {
1034  verror("could not translate vaddr 0x%"PRIxADDR
1035  " in tid %"PRIiTID"!\n",
1036  raddr,target->base_tid);
1037  return 0;
1038  }
1039  offset = raddr & (PAGE_SIZE - 1);
1040  tlen = PAGE_SIZE - offset;
1041  tlen = (tlen < (length - clen)) ? tlen : (length - clen);
1042  if (!target_read_physaddr(target->base,paddr,1,&byte)) {
1043  verror("could not test-read paddr %"PRIxADDR" for vaddr %"PRIxADDR
1044  " len %ld in tid %"PRIiTID"!\n",
1045  paddr,raddr,1L,target->base_tid);
1046  return 0;
1047  }
1048  clen += tlen;
1049  raddr += tlen;
1050  }
1051 
1052  clen = 0;
1053  raddr = addr;
1054  while (clen < length) {
1055  if (target_addr_v2p(target->base,target->base_tid,raddr,&paddr)) {
1056  verror("could not translate vaddr 0x%"PRIxADDR
1057  " in tid %"PRIiTID"!\n",
1058  raddr,target->base_tid);
1059  return 0;
1060  }
1061  offset = raddr & (PAGE_SIZE - 1);
1062  tlen = PAGE_SIZE - offset;
1063  tlen = (tlen < (length - clen)) ? tlen : (length - clen);
1064  if (!target_write_physaddr(target->base,paddr,tlen,buf + clen)) {
1065  verror("could not write paddr %"PRIxADDR" for vaddr %"PRIxADDR
1066  " len %ld in tid %"PRIiTID"!\n",
1067  paddr,raddr,tlen,target->base_tid);
1068  return 0;
1069  }
1070  clen += tlen;
1071  raddr += tlen;
1072  }
1073 
1074  return clen;
1075  }
1076 }
1077 
1078 static tid_t os_process_gettid(struct target *target) {
1079  struct target_thread *tthread;
1080 
1081  // XXX: fix!
1082  return target->base_tid;
1083 
1084  if (target->current_thread && OBJVALID(target->current_thread))
1085  return target->current_thread->tid;
1086 
1087  tthread = os_process_load_current_thread(target,0);
1088  if (!tthread) {
1089  verror("could not load current thread to get TID!\n");
1090  return 0;
1091  }
1092 
1093  return tthread->tid;
1094 }
1095 
1096 static void os_process_free_thread_state(struct target *target,void *state) {
1097  if (state)
1098  free(state);
1099 }
1100 
1101 /* XXX: obviously, need to reload the tgid list. */
1102 static struct array_list *
1103 os_process_list_available_tids(struct target *target) {
1104  struct array_list *retval;
1105 
1106  retval = array_list_create(1);
1107  array_list_append(retval,(void *)(uintptr_t)target->base_tid);
1108 
1109  return retval;
1110 }
1111 
1112 static struct target_thread *
1113 os_process_load_thread(struct target *target,tid_t tid,int force) {
1114  if (!__is_our_tid(target,tid)) {
1115  verror("tid %d is not in tgid %d!\n",tid,target->base_tid);
1116  errno = ESRCH;
1117  return NULL;
1118  }
1119 
1120  if (!target_load_thread(target->base,tid,force))
1121  return NULL;
1122 
1123  return target_lookup_thread(target,tid);
1124 }
1125 
1126 static struct target_thread *
1127 os_process_load_current_thread(struct target *target,int force) {
1128  struct target_thread *uthread;
1129 
1130  uthread = target_load_current_thread(target->base,force);
1131  if (!uthread) {
1132  verror("could not load base target current thread: %s\n",
1133  strerror(errno));
1134  target->current_thread = NULL;
1135  return NULL;
1136  }
1137 
1138  /* XXX: should we return the primary thread, or NULL? */
1139  if (!__is_our_tid(target,uthread->tid)) {
1141  "base target current tid %d is not in tgid %d!\n",
1142  uthread->tid,target->base_tid);
1143  errno = ESRCH;
1144  target->current_thread = NULL;
1145  return NULL;
1146  }
1147 
1148  target->current_thread = target_lookup_thread(target,uthread->tid);
1149 
1150  return target->current_thread;
1151 }
1152 
1153 /* XXX: need to actually do them all! */
1154 static int os_process_load_all_threads(struct target *target,int force) {
1155  if (os_process_load_thread(target,target->base_tid,force))
1156  return 0;
1157  return 1;
1158 }
1159 
1160 static int os_process_load_available_threads(struct target *target,
1161  int force) {
1162  if (os_process_load_thread(target,target->base_tid,force))
1163  return 0;
1164  return -1;
1165 }
1166 
1167 static int os_process_flush_thread(struct target *target,tid_t tid) {
1168  struct target_thread *tthread;
1169  int rc;
1170 
1171  tthread = target_lookup_thread(target,tid);
1172  if (!OBJDIRTY(tthread))
1173  return 0;
1174 
1175  if (!target->writeable) {
1176  verror("target %s not writeable!\n",target->name);
1177  errno = EROFS;
1178  return -1;
1179  }
1180 
1181  if (!__is_our_tid(target,tid)) {
1182  verror("tid %d is not in tgid %d!\n",tid,target->base_tid);
1183  errno = ESRCH;
1184  return -1;
1185  }
1186 
1187  rc = target->base->ops->flush_thread(target->base,tid);
1188  if (rc) {
1189  verror("could not flush base target tid %d: %s\n",tid,strerror(errno));
1190  return rc;
1191  }
1192 
1193  OBJSCLEAN(tthread);
1194 
1195  return 0;
1196 }
1197 
1198 static int os_process_flush_current_thread(struct target *target) {
1199  if (target->current_thread)
1200  return os_process_flush_thread(target,target->current_thread->tid);
1201  return 0;
1202 }
1203 
1204 static int os_process_flush_all_threads(struct target *target) {
1205  struct array_list *tlist;
1206  void *tid;
1207  int i;
1208  int rc = 0;
1209 
1210  tlist = target_list_tids(target);
1211  array_list_foreach(tlist,i,tid) {
1212  rc += os_process_flush_thread(target,(tid_t)(uintptr_t)tid);
1213  }
1214 
1215  return rc;
1216 }
1217 
1218 static int os_process_thread_snprintf(struct target *target,
1219  struct target_thread *tthread,
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",
1224  tthread->tid,tthread->target->base_tid);
1225  errno = ESRCH;
1226  return -1;
1227  }
1228 
1229  return target->base->ops->thread_snprintf(target->base,target->base_thread,
1230  buf,bufsiz,detail,sep,kvsep);
1231 }
1232 
1233 static REGVAL os_process_read_reg(struct target *target,tid_t tid,REG reg) {
1234  struct target_thread *base_tthread;
1235 
1236  if (!__is_our_tid(target,tid)) {
1237  verror("tid %d is not in tgid %d!\n",tid,target->base_tid);
1238  errno = ESRCH;
1239  return -1;
1240  }
1241 
1242  base_tthread = target_load_thread(target->base,tid,0);
1243  if (base_tthread->tidctxt == THREAD_CTXT_KERNEL
1244  && target->base->ops->readreg_tidctxt)
1245  return target->base->ops->readreg_tidctxt(target->base,tid,
1246  THREAD_CTXT_USER,reg);
1247  else
1248  return target->base->ops->readreg(target->base,tid,reg);
1249 }
1250 
1251 static int os_process_write_reg(struct target *target,tid_t tid,REG reg,
1252  REGVAL value) {
1253  struct target_thread *tthread;
1254  struct target_thread *base_tthread;
1255 
1256  if (!__is_our_tid(target,tid)) {
1257  verror("tid %d is not in tgid %d!\n",tid,target->base_tid);
1258  errno = ESRCH;
1259  return -1;
1260  }
1261 
1262  if (!target->writeable) {
1263  verror("target %s not writeable!\n",target->name);
1264  errno = EROFS;
1265  return -1;
1266  }
1267 
1268  tthread = target_lookup_thread(target,tid);
1269  OBJSDIRTY(tthread);
1270 
1271  base_tthread = target_load_thread(target->base,tid,0);
1272  if (base_tthread->tidctxt == THREAD_CTXT_KERNEL
1273  && target->base->ops->readreg_tidctxt)
1274  return target->base->ops->writereg_tidctxt(target->base,tid,
1275  THREAD_CTXT_USER,reg,value);
1276  else
1277  return target->base->ops->writereg(target->base,tid,reg,value);
1278 }
1279 
1280 /*
1281  * NB: we return mmods bound to the underlying target -- not to us!
1282  */
1283 static struct target_memmod *
1284 os_process_insert_sw_breakpoint(struct target *target,
1285  tid_t tid,ADDR addr) {
1286  struct target_thread *tthread;
1287  ADDR paddr = 0;
1288 
1289  if (!target->writeable) {
1290  verror("target %s not writeable!\n",target->name);
1291  errno = EROFS;
1292  return NULL;
1293  }
1294 
1295  tthread = target_lookup_thread(target,tid);
1296  if (!tthread) {
1297  verror("tid %"PRIiTID" does not exist!\n",tid);
1298  errno = ESRCH;
1299  return NULL;
1300  }
1301 
1302  /*
1303  * XXX NB: assume for now that anytime we put a breakpoint into a
1304  * text page in userspace, that this page might be shared between
1305  * processes. We could check if the page is writeable, and then not
1306  * do this, but that will be a rare occurence, so don't bother for
1307  * now.
1308  */
1309 
1310  /* Resolve the phys page. */
1311  if (target_addr_v2p(target->base,tid,addr,&paddr)) {
1312  verror("could not translate vaddr 0x%"PRIxADDR" in tid %"PRIiTID"!\n",
1313  addr,tid);
1314  return NULL;
1315  }
1316 
1317  return _target_insert_sw_breakpoint(target->base,tid,paddr,1,0);
1318 }
1319 static int os_process_remove_sw_breakpoint(struct target *target,tid_t tid,
1320  struct target_memmod *mmod) {
1321  if (!target->writeable) {
1322  verror("target %s not writeable!\n",target->name);
1323  errno = EROFS;
1324  return -1;
1325  }
1326 
1327  return _target_remove_sw_breakpoint(target->base,tid,mmod);
1328 }
1329 
1330 static int os_process_enable_sw_breakpoint(struct target *target,tid_t tid,
1331  struct target_memmod *mmod) {
1332  if (!target->writeable) {
1333  verror("target %s not writeable!\n",target->name);
1334  errno = EROFS;
1335  return -1;
1336  }
1337 
1338  return target_memmod_set(target->base,tid,mmod);
1339 }
1340 
1341 static int os_process_disable_sw_breakpoint(struct target *target,tid_t tid,
1342  struct target_memmod *mmod) {
1343  if (!target->writeable) {
1344  verror("target %s not writeable!\n",target->name);
1345  errno = EROFS;
1346  return -1;
1347  }
1348 
1349  return target_memmod_unset(target->base,tid,mmod);
1350 }
1351 
1352 static int os_process_change_sw_breakpoint(struct target *target,tid_t tid,
1353  struct target_memmod *mmod,
1354  unsigned char *code,
1355  unsigned long code_len) {
1356  if (!target->writeable) {
1357  verror("target %s not writeable!\n",target->name);
1358  errno = EROFS;
1359  return -1;
1360  }
1361 
1362  return target_memmod_set_tmp(target->base,tid,mmod,code,code_len);
1363 }
1364 
1365 static REG os_process_get_unused_debug_reg(struct target *target,tid_t tid) {
1366  errno = ENOTSUP;
1367  return -1;
1368 }
1369 
1370 int os_process_notify_sw_breakpoint(struct target *target,ADDR addr,
1371  int notification) {
1372  return target_notify_sw_breakpoint(target->base,addr,notification);
1373 }
1374 
1375 int os_process_singlestep(struct target *target,tid_t tid,int isbp,
1376  struct target *overlay) {
1377  if (!target->writeable) {
1378  verror("target %s not writeable!\n",target->name);
1379  errno = EROFS;
1380  return -1;
1381  }
1382 
1383  return target_os_thread_singlestep(target->base,tid,isbp,target,0);
1384 }
1385 
1386 int os_process_singlestep_end(struct target *target,tid_t tid,
1387  struct target *overlay) {
1388  if (!target->writeable) {
1389  verror("target %s not writeable!\n",target->name);
1390  errno = EROFS;
1391  return -1;
1392  }
1393 
1394  return target_os_thread_singlestep_end(target->base,tid,target,0);
1395 }
#define OBJSCLEAN(obj)
Definition: object.h:116
target_event_t
Definition: target_event.h:28
ADDR base_virt_addr
Definition: binfile.h:286
#define vwarnopt(level, area, flags, format,...)
Definition: log.h:37
#define T_EVENT_IS_RANGE(event, ttype)
Definition: target_event.h:106
struct addrspace * space
int os_process_disable_hw_breakpoint(struct target *target, tid_t tid, REG dreg)
struct target * base
Definition: target_api.h:2654
void * state
Definition: target_api.h:2526
void target_broadcast_event(struct target *target, struct target_event *event)
Definition: target_event.c:56
struct debugfile * debugfile_from_file(char *filename, char *root_prefix, struct array_list *debugfile_load_opts_list)
Definition: debug.c:1584
thread_bpmode_t bpmode
Definition: target_api.h:2211
int32_t tid_t
Definition: common.h:36
REFCNT lsymbol_release(struct lsymbol *lsymbol)
Definition: debug.c:4805
target_status_t
Definition: target_api.h:197
result_t probepoint_ss_handler(struct target *target, struct target_thread *tthread, struct probepoint *probepoint)
Definition: probe.c:3023
uint32_t no_adjust_bp_ip
Definition: target_api.h:2465
struct symbol * symbol
Definition: dwdebug.h:1010
GHashTable * soft_probepoints
Definition: target_api.h:2735
static uint64_t unsigned int i
#define T_EVENT_IS_REGION(event, ttype)
Definition: target_event.h:103
#define v_g_list_foreach_remove(glhead, glcur, glnext)
Definition: glib_wrapper.h:55
int target_resume(struct target *target)
Definition: target_api.c:1012
ADDR end
Definition: target.h:995
#define v_g_list_foreach(glhead, glcur, elm)
Definition: glib_wrapper.h:34
probepoint_whence_t
Definition: probe_api.h:234
#define OBJSLIVE(obj, type)
Definition: object.h:121
target_debug_bp_handler_t handle_break
Definition: target_api.h:2869
struct target_thread * base_thread
Definition: target_api.h:2655
struct os_process_spec * os_process_build_spec(void)
active_probe_flags_t ap_flags
Definition: target_api.h:2477
char * debugfile_search_path(char *filename, char *root_prefix, char *debug_postfix, const char *DFPATH[], char *buf, int buflen)
Definition: debug.c:1510
int target_pause(struct target *target)
Definition: target_api.c:1027
struct target_thread * global_thread
Definition: target_api.h:2685
struct target * target_create(char *type, struct target_spec *spec)
Definition: target.c:1875
char * name
Definition: target.h:939
struct target_ops os_process_ops
int target_associate_debugfile(struct target *target, struct memregion *region, struct debugfile *debugfile)
Definition: target.c:1993
ADDR start
Definition: target.h:994
uint8_t stay_paused
Definition: target_api.h:2213
int(* writereg)(struct target *target, tid_t tid, REG reg, REGVAL value)
Definition: target_api.h:3064
#define verror(format,...)
Definition: log.h:30
unsigned char * target_read_addr(struct target *target, ADDR addr, unsigned long length, unsigned char *buf)
Definition: target_api.c:1053
void target_detach_thread(struct target *target, struct target_thread *tthread)
Definition: target.c:4115
int(* writereg_tidctxt)(struct target *target, tid_t tid, thread_ctxt_t tidctxt, REG reg, REGVAL value)
Definition: target_api.h:3069
uint32_t mmapable
Definition: target_api.h:2465
struct memregion * memregion_create(struct addrspace *space, region_type_t type, char *name)
Definition: memory.c:242
ADDR base_phys_addr
Definition: target.h:977
#define vwarn(format,...)
Definition: log.h:33
unsigned char * target_read_physaddr(struct target *target, ADDR paddr, unsigned long length, unsigned char *buf)
Definition: target_api.c:1083
uint32_t threadctl
Definition: target_api.h:2465
void free(void *ptr)
Definition: debugserver.c:207
int(* thread_snprintf)(struct target *target, struct target_thread *tthread, char *buf, int bufsiz, int detail, char *sep, char *key_val_sep)
Definition: target_api.h:3007
result_t probepoint_bp_handler(struct target *target, struct target_thread *tthread, struct probepoint *probepoint, int was_stepping)
Definition: probe.c:2593
Definition: log.h:173
struct target_thread * target_load_thread(struct target *target, tid_t tid, int force)
Definition: target_api.c:1311
#define OBJLIVE(obj)
Definition: object.h:84
#define array_list_foreach(alist, lpc, placeholder)
Definition: alist.h:371
struct arch * arch
Definition: binfile.h:216
struct memrange * memrange_create(struct memregion *region, ADDR start, ADDR end, OFFSET offset, unsigned int prot_flags)
Definition: memory.c:538
struct target_thread * target_load_current_thread(struct target *target, int force)
Definition: target_api.c:1305
struct target_thread * current_thread
Definition: target_api.h:2680
#define OBJDIRTY(obj)
Definition: object.h:80
int os_process_singlestep_end(struct target *target, tid_t tid, struct target *overlay)
struct array_list * target_list_tids(struct target *target)
Definition: target_api.c:1210
int os_process_enable_hw_breakpoints(struct target *target, tid_t tid)
probepoint_watchsize_t
Definition: probe_api.h:241
tid_t base_tid
Definition: target_api.h:2657
int target_attach_overlay_thread(struct target *base, struct target *overlay, tid_t newtid)
Definition: target.c:4530
int target_set_active_probing(struct target *target, active_probe_flags_t flags)
Definition: target_api.c:633
int(* flush_thread)(struct target *target, tid_t tid)
Definition: target_api.h:3002
uint32_t live
Definition: target_api.h:2465
unsigned long target_write_physaddr(struct target *target, ADDR paddr, unsigned long length, unsigned char *buf)
Definition: target_api.c:1096
#define THREAD_CTXT_USER
Definition: target_os.h:33
GHashTable * threads
Definition: target_api.h:2672
int target_memmod_unset(struct target *target, tid_t tid, struct target_memmod *mmod)
Definition: target.c:5102
ADDR tag
Definition: target.h:897
#define THREAD_CTXT_KERNEL
Definition: target_os.h:32
#define RHOLD(x, hx)
Definition: common.h:622
ADDR addr
Definition: target.h:392
target_type_t target_type
Definition: target_api.h:2203
GList * spaces
Definition: target_api.h:2643
REGVAL(* readreg_tidctxt)(struct target *target, tid_t tid, thread_ctxt_t tidctxt, REG reg)
Definition: target_api.h:3067
int os_process_disable_hw_breakpoints(struct target *target, tid_t tid)
#define APF_OS
Definition: target_api.h:457
#define v_g_list_foreach_safe(glhead, glcur, glnext, elm)
Definition: glib_wrapper.h:46
#define vdebug(devel, areas, flags, format,...)
Definition: log.h:302
int target_notify_sw_breakpoint(struct target *target, ADDR addr, int notification)
Definition: target_api.c:1891
struct thread_probepoint_context * tpc
Definition: target_api.h:2168
#define OBJSMOD(obj)
Definition: object.h:137
struct target_process * target_os_process_get(struct target *target, tid_t tid)
Definition: target_os.c:392
unsigned int isdeclaration
Definition: dwdebug_priv.h:839
struct lsymbol * debugfile_lookup_sym(struct debugfile *debugfile, char *name, const char *delim, struct rfilter *srcfile_filter, symbol_type_flag_t flags)
Definition: debug.c:1021
#define T_EVENT_IS_SPACE(event, ttype)
Definition: target_event.h:100
#define OBJVALID(obj)
Definition: object.h:76
struct arch * arch
Definition: target_api.h:2603
#define OBJSDIRTY(obj)
Definition: object.h:111
ADDR offset
Definition: target.h:996
unsigned int prot_flags
Definition: target.h:997
void os_process_free_spec(struct os_process_spec *spec)
void * calloc(size_t nmemb, size_t size)
Definition: debugserver.c:200
struct array_list * debugfile_load_opts_list
Definition: target_api.h:2237
struct binfile * binfile
Definition: dwdebug.h:808
void target_thread_set_status(struct target_thread *tthread, thread_status_t status)
Definition: target.c:4041
struct target * target
Definition: target_api.h:2078
int os_process_notify_sw_breakpoint(struct target *target, ADDR addr, int notification)
Definition: log.h:70
GList * ranges
Definition: target.h:947
uint32_t REGVAL
Definition: common.h:66
target_status_t target_status(struct target *target)
Definition: target_api.c:1046
#define PRIiTID
Definition: common.h:37
struct binfile * binfile_pointing
Definition: dwdebug.h:830
void target_reuse_thread_as_global(struct target *target, struct target_thread *thread)
Definition: target.c:4105
int8_t REG
Definition: common.h:93
unsigned int breakpoint_instrs_len
Definition: arch.h:150
uint32_t ADDR
Definition: common.h:64
int os_process_enable_hw_breakpoint(struct target *target, tid_t tid, REG dreg)
#define PAGE_SIZE
char * name
Definition: target_api.h:2521
struct target_ops * ops
Definition: target_api.h:2548
int _target_remove_sw_breakpoint(struct target *target, tid_t tid, struct target_memmod *mmod)
Definition: target_api.c:1738
target_exception_flags_t
Definition: target_api.h:386
int target_memmod_set(struct target *target, tid_t tid, struct target_memmod *mmod)
Definition: target.c:5021
REG spregno
Definition: target_api.h:2507
thread_ctxt_t tidctxt
Definition: target_api.h:2080
target_status_t status
Definition: target_api.h:2503
int os_process_singlestep(struct target *target, tid_t tid, int isbp, struct target *overlay)
REG fbregno
Definition: target_api.h:2506
uint32_t REFCNT
Definition: common.h:124
#define PRIxADDR
Definition: common.h:67
int target_os_thread_singlestep(struct target *target, tid_t tid, int isbp, struct target *overlay, int force_emulate)
Definition: target_os.c:73
int binfile_get_root_scope_sizes(struct binfile *binfile, int *named, int *duplicated, int *anon, int *numscopes)
Definition: binfile.c:326
int(* snprintf)(struct target *target, char *buf, int bufsiz)
Definition: target_api.h:2798
struct target_spec * spec
Definition: target_api.h:2605
int target_memmod_set_tmp(struct target *target, tid_t tid, struct target_memmod *mmod, unsigned char *code, unsigned long code_len)
Definition: target.c:5179
uint32_t nodisablehwbponss
Definition: target_api.h:2465
#define RPUT(x, objtype, hx, rc)
Definition: common.h:624
ADDR base_virt_addr
Definition: target.h:978
REGVAL(* readreg)(struct target *target, tid_t tid, REG reg)
Definition: target_api.h:3063
active_probe_flags_t
Definition: target_api.h:432
char * debugfile_root_prefix
Definition: target_api.h:2235
region_type_t type
Definition: target.h:940
#define APF_PROCESS
Definition: target_api.h:459
struct target_thread * target_lookup_thread(struct target *target, tid_t tid)
Definition: target.c:4023
void target_set_status(struct target *target, target_status_t status)
Definition: target.c:4035
ADDR base_load_addr
Definition: target.h:968
struct target_event * target_create_event(struct target *target, struct target_thread *thread, target_event_t type, void *priv)
Definition: target_event.c:26
unsigned long target_write_addr(struct target *target, ADDR addr, unsigned long length, unsigned char *buf)
Definition: target_api.c:1060
struct target_memmod * _target_insert_sw_breakpoint(struct target *target, tid_t tid, ADDR addr, int is_phys, int nowrite)
Definition: target_api.c:1676
target_debug_handler_t handle_step
Definition: target_api.h:2870
result_t probepoint_interrupted_ss_handler(struct target *target, struct target_thread *tthread, struct probepoint *probepoint)
Definition: probe.c:3359
ADDR base_phys_addr
Definition: binfile.h:285
int target_addr_v2p(struct target *target, tid_t tid, ADDR vaddr, ADDR *paddr)
Definition: target_api.c:1072
struct binfile * binfile
Definition: target.h:961
struct target_thread * target_create_thread(struct target *target, tid_t tid, void *tstate, void *tpstate)
Definition: target.c:4063
#define T_EVENT_IS_OS_PROCESS(event)
Definition: target_event.h:94
REG ipregno
Definition: target_api.h:2508
#define TID_GLOBAL
Definition: target_api.h:145
target_debug_handler_t handle_interrupted_step
Definition: target_api.h:2893
int target_os_thread_singlestep_end(struct target *target, tid_t tid, struct target *overlay, int force_emulate)
Definition: target_os.c:79
GList * regions
Definition: target.h:909
struct probepoint * probepoint
Definition: probe.h:207
#define OBJSDEAD(obj, type)
Definition: object.h:127
struct addrspace * addrspace_create(struct target *target, char *name, ADDR tag)
Definition: memory.c:41
uint32_t writeable
Definition: target_api.h:2465