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_api.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011, 2012, 2013, 2014 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 #ifndef __TARGET_API_H__
20 #define __TARGET_API_H__
21 
22 #include "config.h"
23 #include "common.h"
24 #include "object.h"
25 #include "arch.h"
26 #include "list.h"
27 #include "evloop.h"
28 #include "dwdebug.h"
29 #include "target_event.h"
30 #include "probe_api.h"
31 #include <glib.h>
32 
98 void target_init(void);
99 
113 void target_fini(void);
114 
115 /*
116  * The thread identifier type (tid_t) is declared in include/common.h .
117  */
118 
119 /*
120  * Each target must support operations on the "global" thread. The
121  * intent is that library users can use TID_GLOBAL to probe and access
122  * per-thread state, without having to deal with each thread
123  * individually. How this is actually implemented *is* target
124  * backend-specific.
125  *
126  * In the Xen target, TID_GLOBAL will allow you to access the hardware
127  * state for the current executing thread (or interrupt context, if not
128  * in process context). This means that if you ask for a hardware
129  * probepoint, you'll set a debug register in the current thread. In
130  * the Linux kernel guest, this means that as long as no other thread in
131  * the guest is using debug registers, that setting will be truly global
132  * -- any running thread could be stopped with a debug exception at that
133  * probepoint. If you mix TID_GLOBAL and per-tid hardware probepoints,
134  * however, your global probepoints will likely be stomped. So, don't
135  * do that. (Actually, right now, the Xen target does not support
136  * per-thread hardware breakpoints anyway -- but the behavior will be as
137  * described in the previous sentence once it does.)
138  *
139  * In the Linux ptrace target, TID_GLOBAL gets you access only to the
140  * primary thread of a process. We probaby should, in the future, make
141  * global truly global, in that if you ask for a hardware probepoint
142  * with TID_GLOBAL, that all threads add a per-thread hardware
143  * probepoint. But not yet.
144  */
145 #define TID_GLOBAL INT32_MAX
146 
147 struct target;
148 struct target_thread;
149 struct target_ops;
150 struct target_os_ops;
151 struct target_process_ops;
152 struct target_spec;
153 struct target_location_ctxt;
154 struct target_memmod;
155 struct regfile;
156 struct addrspace;
157 struct memregion;
158 struct memrange;
159 
160 /*
161  * These are flags; we need to create masks of them sometimes.
162  */
163 typedef enum {
166  TARGET_TYPE_XEN = 1 << 1,
168  TARGET_TYPE_PHP = 1 << 3,
169  TARGET_TYPE_GDB = 1 << 4,
170 } target_type_t;
171 #define TARGET_TYPE_BITS 5
172 #define TARGET_TYPE_MASK_BASE \
173  (TARGET_TYPE_PTRACE | TARGET_TYPE_XEN | TARGET_TYPE_GDB)
174 #define TARGET_TYPE_MASK_OVERLAY \
175  (TARGET_TYPE_PHP | TARGET_TYPE_OS_PROCESS)
176 
177 /*
178  * Order of these is important!
179  */
180 typedef enum {
186 
187 typedef enum {
192 } target_mode_t;
193 
194 /*
195  * NB: make sure these align with THREAD_STATUS_* and ASTATUS_* !
196  */
197 typedef enum {
199  /*
200  * The normal state of affairs; it can be returned regardless of if
201  * target_is_open() or not.
202  */
204  /*
205  * A target can only be paused if target_is_open() is true.
206  */
208  /*
209  * A severe error has occured; user should cleanup. There are
210  * exactly zero guarantees about the target's status at this point.
211  * The only guarantee is that the target libraries should not crash,
212  * no matter what the user tries to do to cleanup -- removing
213  * probes, freeing probes, closing the target, freeing the target.
214  */
216  /*
217  * The target has either exited, or we have detached from it.
218  */
220  /*
221  * This is a temporary state to be returned when the target library
222  * knows the target will exit, but is still live enough to examine
223  * its runtime state, remove probes, etc. Not all backends may
224  * provide this state.
225  *
226  * It implies TSTATUS_PAUSED.
227  *
228  * If it is uncaught, that is ok; the user can just catch
229  * TSTATUS_DONE.
230  */
232 
233  /*
234  * These states can only be returned when target_is_open() is
235  * false. DEAD corresponds to a zombie target; STOPPED corresponds
236  * to a target that is SIGSTOP'd, or the backend equivalent to
237  * that.
238  */
241 
242  /*
243  * Currently used to return from target_monitor if the user called
244  * target_monitor_interrupt()
245  */
248 
249 #define TSTATUS_MAX TSTATUS_STOPPED
250 
251 extern char *TSTATUS_STRINGS[];
252 #define TSTATUS(n) (((n) <= TSTATUS_MAX) ? TSTATUS_STRINGS[(n)] : NULL)
253 
254 typedef enum {
255  /*
256  * The first few status bits are deliberately the same as the target
257  * status bits.
258  */
265 
268 
269  /*
270  * These are thread-specific.
271  */
279 
280 #define THREAD_STATUS_MAX THREAD_STATUS_RETURNING_KERNEL
281 
282 #define THREAD_STATUS_BITS 5
283 
284 #define THREAD_SPECIFIC_STATUS(status) \
285  ((thread_status_t)(status) >= THREAD_STATUS_SLEEPING)
286 
287 extern char *THREAD_STATUS_STRINGS[];
288 #define THREAD_STATUS(n) (((n) <= THREAD_STATUS_RETURNING_KERNEL) \
289  ? THREAD_STATUS_STRINGS[(n)] : NULL)
290 
291 /*
292  * Thread contexts are a bit funny. They exist so that threads can have
293  * different contexts; right now only registers are per-context.
294  * Targets need not provide multiple contexts; but they can make use of
295  * them if desired. We don't make thread_ctxt_t an enum because we want
296  * to leave context numbering/naming to personalities as possible (i.e.,
297  * THREAD_CTXT_KERNEL and THREAD_CTXT_USER for the OS personality), and
298  * to backends where necessary (but personalities are more abstract...).
299  */
300 typedef unsigned int thread_ctxt_t;
301 #define THREAD_CTXT_DEFAULT 0
302 
303 /*
304  * When we handle a breakpoint, we *have* to single step some
305  * instruction(s) to get us past the breakpoint (unless it's a hardware
306  * BP and there are no actions nor post handlers). If there are no
307  * complex actions that replace the original instruction's effect
308  * (obviate), it's the original instruction; otherwise it might have
309  * been (part of) a non-boosted complex action running at the
310  * probepoint. BUT, since hardware probepoints are per-thread, we only
311  * have to worry about shared software probepoints. These are embedded
312  * in memory shared amidst multiple threads, so before changing memory
313  * (i.e., to single step the original instruction, or a complex action),
314  * we technically must stop all other threads that share the memory.
315  * However, this is expensive, may be undesireable, or may be impossible
316  * (i.e., if the target does not support thread control, but only
317  * supports thread observation/detection).
318  *
319  * So we support different modes for handling shared probepoints. In
320  * THREAD_BPMODE_STRICT, we *require* that the target pause all other
321  * threads before handling a probepoint at all. The handling thread
322  * blocks all other threads until handling is done.
323  *
324  * In THREAD_BPMODE_SEMI_STRICT, we allow a probepoint to change memory
325  * and single step one instruction, and immediately change memory back.
326  * This means we assume/trust that there won't be a thread collision at
327  * the probepoint where thread A hits the probepoint, changes mem, and
328  * invokes a single step -- but is interrupted before it executes that,
329  * and thread B hits the probepoint (but it won't actually hit it; it
330  * would hit wahtever we put in place of the breakpoint -- either the
331  * orig instruction, or a complex action (the former would be a missed
332  * breakpoint hit; the latter could completely screw up thread B)).
333  * There are other cases. But we assume in this mode that the memory
334  * change/single step of a single instruction is "atomic". This is the
335  * only way the Xen VM target can work right now (we could disable
336  * interrupts, kind of, but we can't disable NMIs... so we would have to
337  * override at least the NMI handler... and we have to deal with things
338  * like page faults sanely -- it's perfectly legit for a breakpointed
339  * instruction to page fault).
340  *
341  * Finally, in THREAD_BPMODE_LOOSE, we allow anything to happen at the
342  * probepoint without requiring that threads be paused; the handling
343  * process is free to allow as many memory changes and single steps as
344  * it likes. This mode is dangerous!!!
345  *
346  * We permit multiple instructions to be inserted here, but this is
347  * dangerous. For a multithreaded target, we're already at risk as
348  * soon as we hit the breakpoint and change it into another real
349  * instruction, because another thread could hit the changed real
350  * instruction if the first thread is interrupted before it can
351  * single step. So technically, in BPMODE_STRICT, we have to pause
352  * all other threads before changing the breakpoint at all. But,
353  * some targets can't really do this (or can't do it well, or it's
354  * hard -- for instnace, for a Xen VM with a Linux guest, we can
355  * disable interrupts while we handle, but even that doesn't disable
356  * NMIs, so we would have to override the guest's NMI handler... and
357  * what exactly we would do in the override code is questionable
358  * anyway!). So we invent another mode, BPMODE_SEMI_STRICT that
359  * says if we have only a single real instruction to single step, we
360  * "trust" that it won't be interrupted; in this mode, if there are
361  * multiple instructions to step, we try to pause all other threads
362  * before handling the breakpoint. Finally, in BPMODE_LOOSE, we
363  * allow endless single steps at the breakpoint without attempting
364  * to pause threads.
365  */
366 typedef enum {
371 
372 typedef enum {
382 } region_type_t;
383 extern char *REGION_TYPE_STRINGS[];
384 #define REGION_TYPE(n) (((n) < __REGION_TYPE_MAX) ? REGION_TYPE_STRINGS[(n)] : NULL)
385 
386 typedef enum {
387  EXCEPTION_NONE = 1 << 0,
393 
394 typedef enum {
401 
402 extern char *POLL_STRINGS[];
403 #define POLL(n) (((n) < sizeof(POLL_STRINGS)/sizeof(char *)) \
404  ? POLL_STRINGS[(n)] : NULL)
405 
406 typedef enum {
415 } load_flags_t;
416 
417 /*
418  * We have flags for each level -- because some backends/personalities
419  * might actively probe at a level they are not natively providing --
420  * for instance, an OS personality might as well actively probe process
421  * mmap regions; why bother splitting that out into a process-level
422  * personality's job? The knowledge is about the OS's process
423  * structures.
424  *
425  * Anyway, that's why we have the "default" flags -- a user can specify
426  * those no matter what personality level their backend is providing,
427  * and the backend will enable those flags *at its level*. Or, for
428  * instance, if you have an OS personality that can provide active
429  * probing of process-level entities, you can enable those too with the
430  * APF_PROCESS_* flags.
431  */
432 typedef enum {
433  AFP_NONE = 0,
434 
436  APF_THREAD_EXIT = 1 << 1,
437  APF_MEMORY = 1 << 2,
438  APF_OTHER = 1 << 3,
439 
442  APF_OS_MEMORY = 1 << 10,
443  APF_OS_OTHER = 1 << 11,
444 
448  APF_PROCESS_OTHER = 1 << 19,
449 
452  APF_APP_MEMORY = 1 << 26,
453  APF_APP_OTHER = 1 << 27,
455 
456 #define APF_WILD (APF_THREAD_ENTRY | APF_THREAD_EXIT | APF_MEMORY | APF_OTHER)
457 #define APF_OS (APF_OS_THREAD_ENTRY | APF_OS_THREAD_EXIT | APF_OS_MEMORY \
458  | APF_OS_OTHER)
459 #define APF_PROCESS (APF_PROCESS_THREAD_ENTRY | APF_PROCESS_THREAD_EXIT \
460  | APF_PROCESS_MEMORY | APF_PROCESS_OTHER)
461 #define APF_APP (APF_APP_THREAD_ENTRY | APF_APP_THREAD_EXIT \
462  | APF_APP_MEMORY | APF_APP_OTHER)
463 #define APF_ALL (APF_WILD | APF_OS | APF_PROCESS | APF_APP)
464 
465 /*
466  * The following functions form the target API.
467  */
468 
504 struct target_spec *target_argp_driver_parse_one(struct argp *driver_parser,
505  void *driver_state,
506  int argc,char **argv,
507  target_type_t target_types,
508  int filter_quoted);
557 int target_argp_driver_parse(struct argp *driver_parser,void *driver_state,
558  int argc,char **argv,
559  target_type_t target_types,int filter_quoted,
560  struct target_spec **primary_target_spec,
561  GList **base_target_specs,
562  GList **overlay_target_specs);
563 struct target_spec *target_argp_target_spec(struct argp_state *state);
564 void *target_argp_driver_state(struct argp_state *state);
565 void target_driver_argp_init_children(struct argp_state *state);
566 int target_spec_to_argv(struct target_spec *spec,char *arg0,
567  int *argc,char ***argv);
569 void target_free_spec(struct target_spec *spec);
570 
604 struct target *target_instantiate(struct target_spec *spec,
605  struct evloop *evloop);
648 GList *target_instantiate_and_open(struct target_spec *primary_target_spec,
649  GList *base_target_specs,
650  GList *overlay_target_specs,
651  struct evloop *evloop,
652  GList **error_specs);
691 GList *target_instantiate_and_open_list(GList *target_specs,
692  struct evloop *evloop,
693  GList **error_specs);
694 
695 /*
696  * Look up an existing target by its id.
697  */
698 struct target *target_lookup_target_id(int id);
699 
701 
702 /*
703  * Get the name of a target. The name will be initially filled in after
704  * target_ops->init is called (by target_open).
705  */
706 char *target_name(struct target *target);
707 
708 /*
709  * Simple accessor to get the target's ID.
710  */
711 int target_id(struct target *target);
712 
713 /*
714  * Opens a target. If returns 0, the target is paused and ready for API
715  * calls. If it returns nonzero, it failed.
716  *
717  * (Internally, it calls the following target_ops: init(), loadspaces(),
718  * loadregions(space), loaddebugfiles(space,region), postloadinit(),
719  * attach().)
720  */
721 int target_open(struct target *target);
722 
723 int target_open_all(struct target *target);
724 
725 /*
726  * Prints a string representation of the given target to @buf. Behaves
727  * according to and assumes a C99 implementation of snprintf (man sprintf).
728  */
729 int target_snprintf(struct target *target,char *buf,int bufsiz);
730 
731 /*
732  * Populates an evloop with any select()able file descriptors that this
733  * target needs monitored, and with their evloop callback functions.
734  * This way, the user can use a single evloop to handle multiple
735  * different kinds of blocking waiting, as well as multiple targets,
736  * instead of directly poll()ing or monitor()ing a single target.
737  *
738  * If a file descriptor closes or exhibits error conditions, the
739  * target's evloop callback function *must* remove the descriptor from
740  * the @evloop -- there is no mechanism for the evloop to clean up
741  * garbage.
742  */
743 int target_attach_evloop(struct target *target,struct evloop *evloop);
744 
745 /*
746  * Removes the selectable file descriptors for @target from @target->evloop.
747  */
748 int target_detach_evloop(struct target *target);
749 
750 /*
751  * Returns 1 if @evloop is already attached to @target; 0 if not.
752  */
754 
755 /*
756  * Returns > 0 if @base is a base ancestor of @overlay. The exact
757  * number is how many levels separate the two: 1 if overlay->base ==
758  * base; 2 if overlay->base->base == base; and so on.
759  */
760 int target_has_base(struct target *overlay,struct target *base);
761 
762 /*
763  * Enables/disables active probing techniques based on bits set in
764  * @flags.
765  *
766  * NB: sometimes it may not be possible to enable certain bits (backend
767  * may not support it); or disable certain bits (backend may require
768  * them, or an overlay target requires them). No good way to help the
769  * user navigate this for now; it's basically best-effort; and if you
770  * use an overlay target, the overlay target's requirements for active
771  * probing *will* override yours.
772  */
774 
775 /*
776  *
777  * If @evloop is specified, the target *must* add a select()able fd,
778  * handler, and state to @evloop. @evloop must be specified if the user
779  * is going to use evloop_* instead of target_monitor or target_poll to
780  * wait on one or more targets from a single
781  */
782 
828 int target_monitor_evloop(struct evloop *evloop,struct timeval *timeout,
829  struct target **target,target_status_t *status);
830 
831 /*
832  * These two functions are only useful when using target_monitor(). If
833  * your program needs to handle a signal, what you should do in the
834  * handler is
835  *
836  * if (target_monitor_handling_exception(t)) {
837  * needtodosomething = 1;
838  * target_monitor_schedule_interrupt(t);
839  * }
840  * else {
841  * target_pause(t);
842  * cleanup();
843  * }
844  *
845  * Then, if you set needtodosomething, when target_monitor() returns,
846  * you can dosomething as safely as possible.
847  *
848  * These functions are not thread-safe; they should only be called from
849  * within a signal handler!
850  */
851 
882 
891 
897 int target_monitor_was_interrupted(siginfo_t *last_siginfo);
898 
926  (void (*sighandler)(int signo,siginfo_t *siginfo,void *x));
956  (sigset_t *ignored,sigset_t *interrupt,sigset_t *exit,
957  void (*sighandler)(int signo,siginfo_t *siginfo,void *x));
967 void target_default_cleanup(void);
978 void target_default_sighandler(int signo,siginfo_t *siginfo,void *x);
979 
980 /*
981  * Polls a target for debug/exception events, and *will* try to handle
982  * any probes if it gets an event. It saves the outcome in @outcome if
983  * you provide a non-NULL value. @pstatus is mostly a legacy of the
984  * linux userspace target; in any case, its value is target-specific,
985  * and the target backend may populate it however it wishes. Finally,
986  * like target_monitor, target_poll will return control to the user for
987  * any exceptions it encounters that it can't handle.
988  *
989  * You must always call target_resume() following a poll, if you choose
990  * to continue.
991  *
992  * NOTE: @tv may be modified during the poll, as described in the
993  * select(2) manual page. This gives you a hint of how long the poll
994  * had to wait.
995  *
996  * ALSO NOTE: the behavior of @tv is different that described in
997  * select(2). If you pass NULL, we auto-fill a struct timeval with 0s,
998  * meaning that select and thus target_poll() will return immediately if
999  * nothing is pending; select blocks if you pass NULL. We don't need
1000  * that behavior, since target_monitor() sort of provides it.
1001  */
1002 target_status_t target_poll(struct target *target,struct timeval *tv,
1003  target_poll_outcome_t *outcome,int *pstatus);
1004 
1005 /*
1006  * Resumes a target from a user-visible pause. This will resume all of
1007  * the resumable threads, and guarantees that the user can call
1008  * target_poll or target_monitor again. If the user does not call
1009  * target_resume before invoking those functions, the target may not be
1010  * running.
1011  */
1012 int target_resume(struct target *target);
1013 
1014 /*
1015  * Pauses a target. This completely pauses a target, and all its
1016  * threads.
1017  */
1018 int target_pause(struct target *target);
1019 
1020 /*
1021  * Returns 1 if the target is open; 0 otherwise. Most target
1022  * operations only make sense if the target is open (i.e., reading
1023  * mem, reading CPU state, pausing/resuming/monitoring/probing, etc).
1024  */
1025 int target_is_open(struct target *target);
1026 
1027 /*
1028  * Returns the target's status.
1029  */
1031 
1038 int target_close(struct target *target);
1039 
1056 int target_finalize(struct target *target);
1057 
1058 /*
1059  * Destroys a target.
1060  */
1061 int target_kill(struct target *target,int sig);
1062 
1063 /*
1064  * Holds a ref to, or releases, a target object. Most users can just
1065  * get away with the normal target_open/target_close pattern; but if you
1066  * need to keep the target struct around after calling target_close,
1067  * you'll need to keep a ref to it!
1068  */
1069 void target_hold(struct target *target);
1070 void target_release(struct target *target);
1071 
1072 /*
1073  * Overlay support.
1074  */
1076  target_type_t type);
1077 struct array_list *target_list_overlays(struct target *target);
1081  tid_t tid);
1083  struct target_spec *spec);
1086  tid_t tid,ADDR ipval,int *again);
1087 
1088 /*
1089  * Returns the probe attached to this target with ID @probe_id, if any.
1090  */
1091 struct probe *target_lookup_probe(struct target *target,int probe_id);
1092 
1093 /*
1094  * Returns the action attached to this target with ID @probe_id, if any.
1095  */
1096 struct action *target_lookup_action(struct target *target,int action_id);
1097 
1098 /*
1099  * Reads a block of memory from the target. If @buf is non-NULL, we
1100  * assume it is at least @length bytes long; the result is placed into
1101  * @buf and @buf is returned. If @buf is NULL, we allocate a buffer
1102  * large enough to hold the result (@length if @length >0; if @length is
1103  * 0 we attempt to read a string at that address; we stop when we hit a
1104  * NULL byte).
1105  *
1106  * On error, returns NULL, and sets errno.
1107  */
1108 unsigned char *target_read_addr(struct target *target,ADDR addr,
1109  unsigned long length,unsigned char *buf);
1110 
1111 /*
1112  * Writes @length bytes from @buf to @addr. Returns the number of bytes
1113  * written (and sets errno nonzero if there is an error). Successful if
1114  * @return == @length.
1115  */
1116 unsigned long target_write_addr(struct target *target,ADDR addr,
1117  unsigned long length,unsigned char *buf);
1118 
1119 int target_addr_v2p(struct target *target,tid_t tid,ADDR vaddr,ADDR *paddr);
1120 unsigned char *target_read_physaddr(struct target *target,ADDR paddr,
1121  unsigned long length,unsigned char *buf);
1122 unsigned long target_write_physaddr(struct target *target,ADDR paddr,
1123  unsigned long length,unsigned char *buf);
1124 
1125 /*
1126  * Returns a string representation for the DWARF register number on this
1127  * particular target type. Will (likely) differ between targets/archs.
1128  */
1129 const char *target_regname(struct target *target,REG reg);
1130 
1131 /*
1132  * Returns the target-specific DWARF register number for the
1133  * target-specific register name @name.
1134  */
1135 int target_regno(struct target *target,char *name,REG *reg);
1136 
1137 /*
1138  * Returns the target-specific DWARF register number for the common
1139  * register @reg.
1140  */
1141 int target_cregno(struct target *target,common_reg_t creg,REG *reg);
1142 
1143 /*
1144  * Reads the DWARF register @reg from thread @tid in @target. Returns 0
1145  * and sets errno nonzero on error.
1146  */
1147 REGVAL target_read_reg(struct target *target,tid_t tid,REG reg);
1148 
1149 /*
1150  * Writes @value to the DWARF register @reg. Returns 0 on success;
1151  * nonzero on failure.
1152  */
1153 int target_write_reg(struct target *target,tid_t tid,REG reg,REGVAL value);
1154 
1155 /*
1156  * Reads the DWARF register @reg from thread @tid in @target. Returns 0
1157  * and sets errno nonzero on error.
1158  */
1160  REG reg);
1161 
1162 /*
1163  * Writes @value to the DWARF register @reg. Returns 0 on success;
1164  * nonzero on failure.
1165  */
1166 int target_write_reg_ctxt(struct target *target,tid_t tid,thread_ctxt_t tidctxt,
1167  REG reg,REGVAL value);
1168 
1169 /*
1170  * Reads the common register @reg in thread @tid in target @target.
1171  * Returns 0 and sets errno on failure.
1172  */
1174 
1175 /*
1176  * Writes @value to the common register @reg. Returns 0 on success;
1177  * nonzero on failure.
1178  */
1179 int target_write_creg(struct target *target,tid_t tid,common_reg_t reg,
1180  REGVAL value);
1181 
1182 /*
1183  * @return a copy of current values of @target/@tid's registers.
1184  *
1185  * Keys are strings corresponding to the target's register names; values
1186  * are REGVAL *'s.
1187  */
1188 GHashTable *target_copy_registers(struct target *target,tid_t tid);
1189 
1190 /*
1191  * Returns the currently executing thread's TID. Only valid when the
1192  * target's current thread is paused; returns 0 and sets errno EBUSY if
1193  * that is not true.
1194  */
1195 tid_t target_gettid(struct target *target);
1196 
1197 /*
1198  * @return: an array_list of TIDs that are in our cache. In this case,
1199  * use (tid_t)array_list_item(list,i) to get the value.
1200  */
1201 struct array_list *target_list_tids(struct target *target);
1202 
1203 /*
1204  * @return: an array_list of target_thread structs that are in our
1205  * cache.
1206  */
1207 struct array_list *target_list_threads(struct target *target);
1208 
1209 /*
1210  * @return: a GHashTable of TIDs->threads that are in our cache. The
1211  * hashtable keys are tid_t types, not ptr_t types!
1212  *
1213  * You might wonder why you need to call this; after all,
1214  * target->threads is a perfectly good hashtable. But, if you ever need
1215  * to loop over the keys in the hash and maybe delete a thread, you need
1216  * to be really careful. This eliminates the need for such caution by
1217  * basically duplicating the hashtable.
1218  */
1219 GHashTable *target_hash_threads(struct target *target);
1220 
1221 /*
1222  * @return: an array_list of TIDs that are part of the target, whether
1223  * they are loaded or not.
1224  */
1226 
1227 /*
1228  * @return: a GHashTable of TIDs that are part of the target, whether
1229  * they are loaded or not. Just a map of tid_t to tid_t .
1230  */
1231 GHashTable *target_hash_available_tids(struct target *target);
1232 
1233 /*
1234  * Load the currently executing thread (may also load the "global"
1235  * thread, depending on the target backend).
1236  */
1238  int force);
1239 
1240 /*
1241  * Load a specific thread's context from the target. If the thread does
1242  * not exist in the target, we return NULL. If it exists in our cache
1243  * and is valid, we do not re-read its state unless @force is nonzero.
1244  */
1246  int force);
1247 /*
1248  * (Re)load all our cached threads' contexts. Only invalid threads are
1249  * loaded unless @force is set nonzero. This function does not attempt
1250  * to discover other threads in the target that are unknown; it only
1251  * tries to reload those it has been told about.
1252  */
1253 int target_load_all_threads(struct target *target,int force);
1254 
1255 /*
1256  * Loads all threads that are part of the target. May evict cached
1257  * threads that no longer exist or whose tids have been reused for other
1258  * threads. Only reloads invalid threads if @force is nonzero.
1259  */
1260 int target_load_available_threads(struct target *target,int force);
1261 
1262 /*
1263  * Pauses a thread (if the target supports thread control). If @nowait
1264  * is set, it will not wait for the pause signal to hit the thread.
1265  *
1266  * XXX: at this point, @nowait is not supported!
1267  */
1268 int target_pause_thread(struct target *target,tid_t tid,int nowait);
1269 
1270 /*
1271  * Flush the currently executing thread's context. Context is only
1272  * written if it is dirty.
1273  */
1275 
1276 /*
1277  * Flush a specific thread's context back to the target. Context is
1278  * only written if it is dirty.
1279  */
1281 /*
1282  * Flush all our cached threads' contexts back to target.
1283  */
1285 
1286 /*
1287  * Garbage collects cached threads. If !target->ops->gc_threads, it
1288  * grabs the list of available thread ids, and compares those to the
1289  * current cache, evicting any stale members of the cache and destroying
1290  * those threads.
1291  *
1292  * @return the number of threads evicted/destroyed, or < 0 on error.
1293  */
1294 int target_gc_threads(struct target *target);
1295 
1296 /*
1297  * Prints a representation of @tid to @buf. Behaves according to and
1298  * assumes a C99 implementation of snprintf (man sprintf).
1299  */
1301  char *buf,int bufsiz,
1302  int detail,char *sep,char *key_val_sep);
1303 void target_dump_thread(struct target *target,tid_t tid,FILE *stream,int detail);
1304 void target_dump_all_threads(struct target *target,FILE *stream,int detail);
1305 
1307  ADDR addr);
1309  struct target_memmod *mmod);
1311  struct target_memmod *mmod);
1313  struct target_memmod *mmod);
1315  struct target_memmod *mmod,
1316  unsigned char *code,unsigned long code_len);
1318  struct target_memmod *mmod);
1319 
1321 int target_set_hw_breakpoint(struct target *target,tid_t tid,REG reg,ADDR addr);
1323  probepoint_whence_t whence,int watchsize);
1324 int target_unset_hw_breakpoint(struct target *target,tid_t tid,REG reg);
1325 int target_unset_hw_watchpoint(struct target *target,tid_t tid,REG reg);
1326 
1329 
1330 int target_disable_hw_breakpoint(struct target *target,tid_t tid,REG dreg);
1331 int target_enable_hw_breakpoint(struct target *target,tid_t tid,REG dreg);
1332 
1334  int notification);
1335 int target_singlestep(struct target *target,tid_t tid,int isbp);
1336 int target_singlestep_end(struct target *target,tid_t tid);
1337 
1338 uint64_t target_get_tsc(struct target *target);
1339 uint64_t target_get_time(struct target *target);
1340 uint64_t target_get_counter(struct target *target);
1341 
1342 /*
1343  * Feature functions. Enable/disable a specific feature on a target.
1344  * Feature flags are target-specific.
1345  */
1346 int target_enable_feature(struct target *target,int feature,void *arg);
1347 int target_disable_feature(struct target *target,int feature);
1348 
1349 /*
1350  * @return: the thread's status if it exists in our cache, or
1351  * THREAD_STATUS_UNKNOWN if the thread does not exist or if the status
1352  * is actually unknown.
1353  */
1355 
1356 
1366  ADDR *start,ADDR *end,void **data);
1368  ADDR *start,ADDR *end,void **data);
1369 unsigned char *target_load_code(struct target *target,
1370  ADDR start,unsigned int len,
1371  int nocache,int force_copy,int *caller_free);
1372 
1376 /*
1377  * Find the symbol table corresponding to the supplied PC.
1378  */
1379 struct scope *target_lookup_addr(struct target *target,uint64_t addr);
1380 
1381 /*
1382  * Looks up a symbol, or hierarchy of nested symbols. Users shouldn't
1383  * need to know the details of the bsymbol struct; it largely functions
1384  * as a placeholder that saves the result of a nested lookup so that it
1385  * is available for a later load. The single symbol, or deepest-nested
1386  * symbol, is in .symbol. The chain of nested symbols (possibly
1387  * including anonymous symbols), which includes the deepest-nested
1388  * symbol itself, is in .chain.
1389  *
1390  * The bsymbol struct should be passed to _load functions, where it may
1391  * be further annotated with load information.
1392  *
1393  * Each symbol chain member is either a SYMBOL_TYPE_VAR or a
1394  * SYMBOL_TYPE_FUNCTION -- unless the first member in your @name string
1395  * resolves to a SYMBOL_TYPE_TYPE. In this case, the first member will
1396  * be a SYMBOL_TYPE_TYPE!
1397  *
1398  * This function takes a ref to its return value on the user's behalf;
1399  * call bsymbol_release() to release (and maybe free) it.
1400  */
1401 
1402 struct bsymbol *target_lookup_sym(struct target *target,
1403  const char *name,const char *delim,
1404  char *srcfile,symbol_type_flag_t ftype);
1406  struct bsymbol *bsymbol,
1407  const char *name,const char *delim);
1408 
1409 struct bsymbol *target_lookup_sym_addr(struct target *target,ADDR addr);
1410 
1412  char *filename,int line,
1413  SMOFFSET *offset,ADDR *addr);
1415  char *filename,ADDR addr);
1416 
1420 int target_contains_real(struct target *target,ADDR addr);
1421 int target_find_memory_real(struct target *target,ADDR addr,
1422  struct addrspace **space_saveptr,
1423  struct memregion **region_saveptr,
1424  struct memrange **range_saveptr);
1426  struct target_location_ctxt *tlctxt,
1427  struct bsymbol *bsymbol,ADDR *o_addr,
1428  struct memrange **o_range);
1452  struct target_location_ctxt *tlctxt,
1453  struct bsymbol *bsymbol,load_flags_t flags,
1454  struct memrange **range_saveptr);
1456  char *member,const char *delim);
1457 struct value *target_load_symbol(struct target *target,
1458  struct target_location_ctxt *tlctxt,
1459  struct bsymbol *bsymbol,load_flags_t flags);
1460 /*
1461  * You can ask for *any* nesting of variables, given some bound symbol.
1462  * If @bsymbol is a function, you can ask for its args or locals. If
1463  * the locals or args are structs, you can directly ask for members --
1464  * but make sure that if you want pointers followed, you set the
1465  * LOAD_FLAG_AUTO_DEREF flag; otherwise a nested load across a pointer
1466  * (i.e., if the current member we're working on is a pointer, and you
1467  * have specified another nested member within that thing, we won't be
1468  * able to follow the pointer, and hence will fail to find the next
1469  * member) will fail. If @bsymbol is a struct/union var, you can of
1470  * course ask for any of its (nested) members.
1471  *
1472  * Your top-level @bsymbol must be either a function or a struct/union
1473  * var; nothing else makes sense as far as loading memory.
1474  */
1476  struct target_location_ctxt *tlctxt,
1477  struct bsymbol *bsymbol,
1478  const char *member,const char *delim,
1479  load_flags_t flags);
1481  struct target_location_ctxt *tlctxt,
1482  struct value *old_value,
1483  const char *member,const char *delim,
1484  load_flags_t flags);
1485 /*
1486  * This function creates a value by loading the number of bytes
1487  * specified by @type from a real @addr.
1488  */
1489 struct value *target_load_type(struct target *target,struct symbol *type,
1490  ADDR addr,load_flags_t flags);
1491 /*
1492  * This function creates a value by loading the number of bytes
1493  * specified by @type from @tid's register @reg.
1494  */
1495 struct value *target_load_type_reg(struct target *target,struct symbol *type,
1496  tid_t tid,REG reg,load_flags_t flags);
1497 /* Or if you've already read the register, this one. */
1498 struct value *target_load_type_regval(struct target *target,struct symbol *type,
1499  tid_t tid,REG reg,REGVAL regval,
1500  load_flags_t flags);
1501 /*
1502  * Load a raw value (i.e., no symbol or type info) using an object
1503  * file-based location (i.e., a fixed object-relative address) and a
1504  * specific region.
1505  *
1506  * Note: you cannot mmap raw values; they must be copied from target memory.
1507  */
1508 struct value *target_load_addr_obj(struct target *target,struct memregion *region,
1509  ADDR obj_addr,load_flags_t flags,int len);
1510 /*
1511  * Load a raw value (i.e., no symbol or type info) using a real address.
1512  *
1513  * Note: you cannot mmap raw values; they must be copied from target memory.
1514  */
1516  load_flags_t flags,int len);
1517 
1518 /*
1519  * Starting at @addr, which is of type @datatype, load as many pointers
1520  * as specified by our @flags (if @flags does not have
1521  * LOAD_FLAG_AUTO_DEREF or LOAD_FLAG_AUTO_STRING set, or @datatype is
1522  * not a pointer type symbol, this function will immediately return, and
1523  * will return @addr without setting @datatype_saveptr and
1524  * @range_saveptr).
1525  *
1526  * This function will keep loading pointers as long as @datatype and its
1527  * pointed-to type (recursively) are pointers. Once @datatype is no
1528  * longer a pointer, we stop, return the last pointer value, save the
1529  * non-pointer type in @datatype_saveptr, and save the memrange
1530  * containing the last pointer in @range_saveptr.
1531  *
1532  * You can set @datatype_saveptr and/or @range_saveptr to NULL safely.
1533  *
1534  * If an error occurs (i.e., attempt to deref a NULL pointer), we return
1535  * 0 and set errno appropriately.
1536  */
1537 ADDR target_autoload_pointers(struct target *target,struct symbol *datatype,
1538  ADDR addr,load_flags_t flags,
1539  struct symbol **datatype_saveptr,
1540  struct memrange **range_saveptr);
1541 /*
1542  * Load @count void pointers. Save off the range containing the final
1543  * pointer (not the final pointed-to value!) in @range_saveptr if
1544  * supplied. If an intermediate pointer is NULL, we set errno to EFAULT
1545  * and return 0.
1546  */
1547 ADDR target_load_pointers(struct target *target,ADDR addr,int count,
1548  struct memrange **range_saveptr);
1549 
1553 /*
1554  * If you have the type of symbol you're interested in, but you need to
1555  * load a pointer to a chunk of memory of that type, you can create a
1556  * synthetic type symbol that points to your "base" type.
1557  *
1558  * Synthetic symbols are the only kind of symbols that hold refs to other
1559  * symbols (in this case, the return value holds a ref to @type). This
1560  * function also holds a ref to the symbol it returns, since it is
1561  * anticipated that only users will call this function.
1562  */
1564  struct symbol *type);
1565 
1570 char *bsymbol_get_name(struct bsymbol *bsymbol);
1571 struct symbol *bsymbol_get_symbol(struct bsymbol *bsymbol);
1572 struct lsymbol *bsymbol_get_lsymbol(struct bsymbol *bsymbol);
1573 int bsymbol_is_inline(struct bsymbol *bsymbol);
1574 /*
1575  * Creates a bsymbol that basically is the deepest non-inline instance
1576  * part of @bsymbol.
1577  *
1578  * This function does not take a reference to the returned bsymbol;
1579  * (call bsymbol_hold() to get that ref if you need it; otherwise free
1580  * it as soon as you are done with it and don't pass it to anyone).
1581  */
1583 void bsymbol_dump(struct bsymbol *bsymbol,struct dump_info *ud);
1584 /*
1585  * Takes a reference to the bsymbol. Users should not call this; target
1586  * lookup functions will do this for you.
1587  */
1588 void bsymbol_hold(struct bsymbol *bsymbol);
1589 /*
1590  * Releases a reference to the bsymbol and tries to free it.
1591  */
1593 
1597 /*
1598  * Creates a fully independent value with a copy of whatever was in
1599  * @in's value buffer; also holds refs to in->type and in->lsymbol if
1600  * they exist -- so you must free it with value_free like normal.
1601  *
1602  * Note that if you clone a value that is sharing a parent value's
1603  * buffer space, the clone does not maintain this relationship; clones
1604  * always have their own private buffer.
1605  */
1606 struct value *value_clone(struct value *in);
1607 /*
1608  * Returns the resolved address of the value; if the value is a register
1609  * value, it returns 0 and sets errno to EINVAL.
1610  */
1611 ADDR value_addr(struct value *value);
1612 void value_free(struct value *value);
1613 int value_snprintf(struct value *value,char *buf,int buflen);
1614 void value_dump(struct value *value,struct dump_info *ud);
1615 void value_dump_simple(struct value *value,struct dump_info *ud);
1616 
1617 /*
1618  * Refreshes @value if necessary. If @value is a child of another
1619  * value, we will try to force a refresh of its parent (and upwards
1620  * recursively). Be careful of @recursive -- this might make values
1621  * change unexpectedly for you! You must only use value_refresh if you
1622  * are fine with "live" values.
1623  */
1624 int value_refresh(struct value *value,int recursive);
1625 
1626 typedef enum {
1631 } value_diff_t;
1632 
1633 typedef uintptr_t value_hash_t;
1634 
1635 /*
1636  * Reloads the content of @value and recomputes its new hash, setting
1637  * @vdiff accordingly if supplied. If @vdiff is VALUE_DIFF_DIFF, and if
1638  * @old_* are supplied, they are set to the old values, if any.
1639  * @old_buf and @old_bufsiz can only be set if the value was not mmap'd
1640  * (if it was, the value has already changed in the buffer and we don't
1641  * know what it was; so if this is important, then make sure to load the
1642  * value with LOAD_FLAG_NO_MMAP). @old_vhash will always be set if
1643  * VALUE_DIFF_DIFF.
1644  *
1645  * If there was an error loading the value, -1 is returned. This is the
1646  * only case an error can (realistically) occur.
1647  */
1648 int value_refresh_diff(struct value *value,int recurse,value_diff_t *vdiff,
1649  char **old_buf,int *old_bufsiz,value_hash_t *old_vhash);
1650 
1654 /*
1655  * Load a value. If @invalue is specified, load @varstr as a member.
1656  * If @invalue is not specified, lookup @varstr on @target as a symbol,
1657  * and load it! Load with @loadflags. If @outvarptr is specified, copy
1658  * the raw value's bytes into it -- if sizeof(*@outvarptr) < value->buflen
1659  * (poor man's C type "equivalence" check). If @outvalueptr is not
1660  * NULL, save the loaded struct value into *@outvalueptr and don't free
1661  * it (otherwise it is freed).
1662 
1663  * (NB: initially we had supported this (If *@outvalueptr == @invalue,
1664  * value_free(*@outvalueptr) first!), but not now -- it is not good.)
1665  *
1666  * This encapsulates the common ways we use VMI to load values, and
1667  * saves the user a lot of code.
1668  */
1669 #define VLS(target,tlctxt,varstr,loadflags,outvarptr,outvalueptr,errlabel) \
1670  do { \
1671  struct value *_outvalue; \
1672  void *__outvar = (outvarptr); \
1673  struct bsymbol *_varsym; \
1674  _varsym = target_lookup_sym((target),(varstr),NULL,NULL, \
1675  SYMBOL_TYPE_NONE); \
1676  if (!_varsym) { \
1677  goto errlabel; \
1678  } \
1679  _outvalue = target_load_symbol((target),(tlctxt),_varsym, \
1680  (loadflags)); \
1681  bsymbol_release(_varsym); \
1682  if (!_outvalue) \
1683  goto errlabel; \
1684  if (__outvar) { \
1685  if ((int)sizeof(*(outvarptr)) < _outvalue->bufsiz) { \
1686  verror("outvar size %u smaller than outvalue len %d\n", \
1687  (unsigned)sizeof(*(outvarptr)),_outvalue->bufsiz); \
1688  value_free(_outvalue); \
1689  goto errlabel; \
1690  } \
1691  memcpy(outvarptr,_outvalue->buf, \
1692  ((int)sizeof(*(outvarptr))) > _outvalue->bufsiz \
1693  ? _outvalue->bufsiz : (int)sizeof(*(outvarptr)));\
1694  } \
1695  if (outvalueptr) \
1696  *(struct value **)(outvalueptr) = _outvalue; \
1697  else \
1698  value_free(_outvalue); \
1699  } while (0);
1700 #define VL(target,tlctxt,invalue,varstr,loadflags,outvalueptr,errlabel) \
1701  do { \
1702  struct value *_outvalue; \
1703  \
1704  if ((invalue) != NULL) { \
1705  _outvalue = target_load_value_member((target),(tlctxt),(invalue),(varstr), \
1706  NULL,(loadflags)); \
1707  } \
1708  else { \
1709  struct bsymbol *_varsym; \
1710  _varsym = target_lookup_sym((target),(varstr),NULL,NULL, \
1711  SYMBOL_TYPE_NONE); \
1712  if (!_varsym) { \
1713  goto errlabel; \
1714  } \
1715  _outvalue = target_load_symbol((target),(tlctxt),_varsym, \
1716  (loadflags)); \
1717  bsymbol_release(_varsym); \
1718  } \
1719  if (!_outvalue) \
1720  goto errlabel; \
1721  if (outvalueptr) { \
1722  if (0 && *(struct value **)(outvalueptr) == invalue) { \
1723  value_free(*(struct value **)(outvalueptr)); \
1724  } \
1725  *(struct value **)(outvalueptr) = _outvalue; \
1726  } \
1727  else { \
1728  value_free(_outvalue); \
1729  } \
1730  } while (0);
1731 #define VLV(target,tlctxt,invalue,varstr,loadflags,outvarptr,outvalueptr,errlabel) \
1732  do { \
1733  struct value *_outvalue; \
1734  void *__outvar = (outvarptr); \
1735  \
1736  if ((invalue) != NULL) { \
1737  _outvalue = target_load_value_member((target),(tlctxt),(invalue),(varstr), \
1738  NULL,(loadflags)); \
1739  } \
1740  else { \
1741  struct bsymbol *_varsym; \
1742  _varsym = target_lookup_sym((target),(varstr),NULL,NULL, \
1743  SYMBOL_TYPE_NONE); \
1744  if (!_varsym) { \
1745  goto errlabel; \
1746  } \
1747  _outvalue = target_load_symbol((target),(tlctxt),_varsym, \
1748  (loadflags)); \
1749  bsymbol_release(_varsym); \
1750  } \
1751  if (!_outvalue) \
1752  goto errlabel; \
1753  if (__outvar) { \
1754  if ((int)sizeof(*(outvarptr)) < _outvalue->bufsiz) { \
1755  verror("outvar size %u smaller than outvalue len %d\n", \
1756  (unsigned)sizeof(*(outvarptr)),_outvalue->bufsiz); \
1757  value_free(_outvalue); \
1758  goto errlabel; \
1759  } \
1760  memcpy(outvarptr,_outvalue->buf, \
1761  ((int)sizeof(*(outvarptr))) > _outvalue->bufsiz \
1762  ? _outvalue->bufsiz : (int)sizeof(*(outvarptr)));\
1763  } \
1764  if (outvalueptr) { \
1765  if (0 && *(struct value **)(outvalueptr) == invalue) { \
1766  value_free(*(struct value **)(outvalueptr)); \
1767  } \
1768  *(struct value **)(outvalueptr) = _outvalue; \
1769  } \
1770  else { \
1771  value_free(_outvalue); \
1772  } \
1773  } while (0);
1774 #define VLVAR(target,tlctxt,invalue,varstr,loadflags,outvarptr,errlabel) \
1775  do { \
1776  struct value *_outvalue; \
1777  \
1778  if ((invalue) != NULL) { \
1779  _outvalue = target_load_value_member((target),(tlctxt),(invalue),(varstr), \
1780  NULL,(loadflags)); \
1781  } \
1782  else { \
1783  struct bsymbol *_varsym; \
1784  _varsym = target_lookup_sym((target),(varstr),NULL,NULL, \
1785  SYMBOL_TYPE_NONE); \
1786  if (!_varsym) { \
1787  goto errlabel; \
1788  } \
1789  _outvalue = target_load_symbol((target),(tlctxt),_varsym, \
1790  (loadflags)); \
1791  bsymbol_release(_varsym); \
1792  } \
1793  if (!_outvalue) \
1794  goto errlabel; \
1795  if ((int)sizeof(*(outvarptr)) < _outvalue->bufsiz) { \
1796  verror("outvar size %u smaller than outvalue len %d\n", \
1797  (unsigned)sizeof(*(outvarptr)),_outvalue->bufsiz); \
1798  value_free(_outvalue); \
1799  goto errlabel; \
1800  } \
1801  memcpy(outvarptr,_outvalue->buf, \
1802  ((int)sizeof(*(outvarptr))) > _outvalue->bufsiz \
1803  ? _outvalue->bufsiz : (int)sizeof(*(outvarptr))); \
1804  value_free(_outvalue); \
1805  } while (0);
1806 #define VLVAL(target,tlctxt,invalue,varstr,loadflags,outvalueptr,errlabel) \
1807  do { \
1808  struct value *_outvalue; \
1809  \
1810  if ((invalue) != NULL) { \
1811  _outvalue = target_load_value_member((target),(tlctxt),(invalue),(varstr), \
1812  NULL,(loadflags)); \
1813  } \
1814  else { \
1815  struct bsymbol *_varsym; \
1816  _varsym = target_lookup_sym((target),(varstr),NULL,NULL, \
1817  SYMBOL_TYPE_NONE); \
1818  if (!_varsym) { \
1819  goto errlabel; \
1820  } \
1821  _outvalue = target_load_symbol((target),(tlctxt),_varsym, \
1822  (loadflags)); \
1823  bsymbol_release(_varsym); \
1824  } \
1825  if (!_outvalue) \
1826  goto errlabel; \
1827  if (0 && *(struct value **)(outvalueptr) == invalue) { \
1828  value_free(*(struct value **)(outvalueptr)); \
1829  } \
1830  *(struct value **)(outvalueptr) = _outvalue; \
1831  } while (0);
1832 #define VLA(target,addr,loadflags,outbufptr,outbuflen,outvalueptr,errlabel) \
1833  do { \
1834  struct value *_outvalue; \
1835  \
1836  _outvalue = target_load_addr_real((target),(addr),(loadflags), \
1837  outbuflen); \
1838  if (!_outvalue) \
1839  goto errlabel; \
1840  if (!*outbufptr) { \
1841  *outbufptr = malloc(outbuflen); \
1842  } \
1843  memcpy(*outbufptr,_outvalue->buf,outbuflen); \
1844  if (outvalueptr) { \
1845  *(struct value **)(outvalueptr) = _outvalue; \
1846  } \
1847  else { \
1848  value_free(_outvalue); \
1849  } \
1850  } while (0);
1851 
1855 signed char v_c(struct value *v);
1856 unsigned char v_uc(struct value *v);
1857 wchar_t v_wc(struct value *v);
1858 uint8_t v_u8(struct value *v);
1859 uint16_t v_u16(struct value *v);
1860 uint32_t v_u32(struct value *v);
1861 uint64_t v_u64(struct value *v);
1862 int8_t v_i8(struct value *v);
1863 int16_t v_i16(struct value *v);
1864 int32_t v_i32(struct value *v);
1865 int64_t v_i64(struct value *v);
1866 num_t v_num(struct value *v);
1867 unum_t v_unum(struct value *v);
1868 float v_f(struct value *v);
1869 double v_d(struct value *v);
1870 long double v_dd(struct value *v);
1871 ADDR v_addr(struct value *v);
1872 char * v_string(struct value *v);
1873 
1877 int value_update(struct value *value,const char *buf,int bufsiz);
1878 int value_update_zero(struct value *value,const char *buf,int bufsiz);
1879 int value_update_c(struct value *value,signed char v);
1880 int value_update_uc(struct value *value,unsigned char v);
1881 int value_update_wc(struct value *value,wchar_t v);
1882 int value_update_u8(struct value *value,uint8_t v);
1883 int value_update_u16(struct value *value,uint16_t v);
1884 int value_update_u32(struct value *value,uint32_t v);
1885 int value_update_u64(struct value *value,uint64_t v);
1886 int value_update_i8(struct value *value,int8_t v);
1887 int value_update_i16(struct value *value,int16_t v);
1888 int value_update_i32(struct value *value,int32_t v);
1889 int value_update_i64(struct value *value,int64_t v);
1890 int value_update_f(struct value *value,float v);
1891 int value_update_d(struct value *value,double v);
1892 int value_update_dd(struct value *value,long double v);
1893 int value_update_addr(struct value *value,ADDR v);
1894 int value_update_num(struct value *value,num_t v);
1895 int value_update_unum(struct value *value,unum_t v);
1896 
1900 int target_store_value(struct target *target,struct value *value);
1901 
1902 #define value_to_u64(v) (*((uint64_t *)(v)->buf))
1903 #define value_to_u32(v) (*((uint32_t *)(v)->buf))
1904 #define value_to_u16(v) (*((uint16_t *)(v)->buf))
1905 #define value_to_u8(v) (*((uint8_t *)(v)->buf))
1906 
1907 #define value_to_i64(v) (*((int64_t *)(v)->buf))
1908 #define value_to_i32(v) (*((int32_t *)(v)->buf))
1909 #define value_to_i16(v) (*((int16_t *)(v)->buf))
1910 #define value_to_i8(v) (*((int8_t *)(v)->buf))
1911 
1912 #if __WORDSIZE == 64
1913 #define value_to_unsigned_long value_to_u64
1914 #define value_to_long value_to_i64
1915 #else
1916 #define value_to_unsigned_long value_to_u32
1917 #define value_to_long value_to_i32
1918 #endif
1919 
1920 #define value_to_int value_to_i32
1921 #define value_to_unsigned_int value_to_u32
1922 
1923 #define value_to_char(v) ((char)value_to_i8((v)))
1924 #define value_to_unsigned_char(v) ((unsigned char)value_to_i8((v)))
1925 #define value_to_string(v) ((v)->buf)
1926 #if __WORDSIZE == 64
1927 #define value_to_num(v) value_to_i64((v))
1928 #else
1929 #define value_to_num(v) value_to_i32((v))
1930 #endif
1931 
1935 signed char rv_c(void *buf);
1936 unsigned char rv_uc(void *buf);
1937 wchar_t rv_wc(void *buf);
1938 uint8_t rv_u8(void *buf);
1939 uint16_t rv_u16(void *buf);
1940 uint32_t rv_u32(void *buf);
1941 uint64_t rv_u64(void *buf);
1942 int8_t rv_i8(void *buf);
1943 int16_t rv_i16(void *buf);
1944 int32_t rv_i32(void *buf);
1945 int64_t rv_i64(void *buf);
1946 float rv_f(void *buf);
1947 double rv_d(void *buf);
1948 long double rv_dd(void *buf);
1949 ADDR rv_addr(void *buf);
1950 
1955 /*
1956  * For now, targets can support multiple threads. However, these
1957  * threads should share their address spaces; if they do not, use a
1958  * separate target to track them.
1959  *
1960  * XXX: we really need to have each thread "own" its own addrspace --
1961  * even if that addrspace is shared throughout a group of threads. This
1962  * isn't too hard to fix; BUT all access to memory would then need to go
1963  * through a thread id. That's a fundamental API change, throughout the
1964  * library.
1965  *
1966  * Targets can support either single-thread mode or multi-thread mode
1967  * (or may only support one or the other). To support single-thread
1968  * mode, each target should supply a "default thread" that either really
1969  * is the single thread of the target, or somehow abstracts around the
1970  * fact that there are multiple threads running.
1971  *
1972  * In single thread mode, only the default thread is used; hardware
1973  * state of the machine is always in this thread's context. So, if the
1974  * user/library calls target_load_current_thread, the default thread is
1975  * always populated with current hardware state and returned.
1976  * target_load_thread(tid) will always fail in single-thread mode.
1977  * Summary: single-thread mode exists so that the user doesn't have to
1978  * worry about which thread context they are executing in, if they don't
1979  * care.
1980  *
1981  * In thread-aware mode, the user is unaware that there are multiple
1982  * threads, but the VMI library knows there are; it detects these
1983  * threads as separate execution contexts so that it can maintain
1984  * probepoint state amongst multiple threads. However, they are not
1985  * exposed to the user (i.e., the user sees only the def
1986  *
1987  * In multi-thread mode, target_load_current_thread should load the
1988  * current thread's hardware context into a thread that is truly
1989  * associated with the thread's real TID (unlike loading the current
1990  * thread in single-thread mode). Hence, in multi-thread mode, the
1991  * default thread is never used.
1992  *
1993  * When setting probes, if your target is single threaded, probes are
1994  * always "global" -- that is, if they manifest as hardware debug
1995  * register probes, the debug registers are set globally; if they
1996  * manifest as software probes, the software probes will cause
1997  * interrupts no matter what thread hits them, and the probes will
1998  * always be notified no matter which thread is executing.
1999  *
2000  * When setting probes on a multi threaded target, you have two options:
2001  * set the probes per-thread, or to be TID_GLOBAL. The idea is that if
2002  * a probe is per-thread, the probe will only be notified if the thread
2003  * named hits the probe. If you have set TID_GLOBAL for your probe, the
2004  * probe will be notified for any thread that triggers the probe. Why
2005  * is the distinction important? If you set software probes, they will
2006  * cause interrupts in any thread in the target (since they are embedded
2007  * in the shared text pages). BUT, if you set the probes per-thread,
2008  * the probes will only be notified in the thread they were associated
2009  * with.
2010  *
2011  * When setting a hardware probe per-thread or with TID_GLOBAL, the
2012  * behavior is target-dependent, because it depends on the model for
2013  * using/sharing the hardware debug registers. On x86 architectures,
2014  * there is no hardware support for sharing the debug registers, so
2015  * things are tricky.
2016  *
2017  * For our two existing targets, these are the rules:
2018  *
2019  * xen_vm -- you should either set all your hardware probes with
2020  * TID_GLOBAL, or per-thread. Do not mix them. Why? Because once you
2021  * set a per-thread probe, the Linux kernel running in the guest VM will
2022  * modify the contents of the debug registers when a process is context
2023  * switched. This will wipe out any registers set with TID_GLOBAL, and
2024  * your TID_GLOBAL probes may not work anymore. We recommend that you
2025  * only probe with TID_GLOBAL for this target.
2026  *
2027  * linux_userspace_process -- TID_GLOBAL is meaningless on this target.
2028  * You can only set per-thread hardware debug registers.
2029  *
2030  */
2031 
2032 typedef enum {
2039 
2041  struct target *target;
2044  int8_t resumeat:4,
2045  attached:1,
2046  exiting:1;
2049 
2053 
2054  /*
2055  * Target backends may or may not set these fields when they load
2056  * threads. If @name is set, it will be freed when the thread is
2057  * freed. @ptid is the parent thread, or -1. @tgid is the thread
2058  * group id (on Linux, it's the process id). @uid and @gid are the
2059  * user id and group id of this thread; or -1 if not
2060  * available/meaningless.
2061  */
2062  char *name;
2065  int uid;
2066  int gid;
2067 
2068  void *state;
2070 
2071  /*
2072  * Built-in support for regcache. We do expect most target backends
2073  * to use it!
2074  */
2076 
2077  /*
2078  * A hashtable of addresses to probe points.
2079  */
2080  GHashTable *hard_probepoints;
2081 
2082  /*
2083  * Info about the probepoint we are handling. A single thread can
2084  * only be directly handling one probepoint at once. The only case
2085  * where we could stack up two breakpoints is when we single step
2086  * after hitting a breakpoint, and we trigger a watchpoint. This
2087  * is a special case, and for x86 targets, the x86 guarantees that
2088  * the watchpoint exception will happen first, then the single step
2089  * exception. But in any case, we know what is happening, so we can
2090  * handle it.
2091  *
2092  * The other case where it could happen is if an interrupt fires
2093  * before the single step following a breakpoint can run, or if an
2094  * exception occurs during the single step, which triggers control
2095  * flow to divert to another path involving another probepoint. In
2096  * the interrupt case, the thread could be preempted by another
2097  * thread. This is bad, because when we handled the breakpoint, we
2098  * replaced the breakpoint instruction with either an action
2099  * instruction or the original instruction and were about to single
2100  * step it. The only way we could handle this is to snoop on
2101  * higher-prio interrupts; see if the interrupt preempted our
2102  * handling of a breakpoint, and put the breakpoint instruction back
2103  * in (or reenable the hw breakpoint in question) before the
2104  * interrupt is handled. Then, when the other thread resumes, we're
2105  * going to single step the breakpoint instruction, and we need to
2106  * recognize this and basically try the single step again.
2107  *
2108  * For the case where an exception fires during the single
2109  * step... actually I think the x86 will not fire the single step
2110  * trap until the exception has been handled, because the single
2111  * step trap cannot happen until the instruction pointer can be
2112  * moved past the instruction... ?
2113  *
2114  * The other case where this can happen is when one of the actions
2115  * is one or more custom code actions, and we have to execute more
2116  * instructions that just the one single step following a
2117  * breakpoint. In this case, our thread might get interrupted while
2118  * handling actions, and we must therefore remember which action for
2119  * which probepoint we are handling later when the thread resumes.
2120  *
2121  * So, anyway, for these reasons at least, we have to keep
2122  * per-probepoint, per-action state for each thread. We push a new
2123  * context each time we hit a breakpoint. When a debug event
2124  * happens for a thread, we continue operating with the context atop
2125  * the stack. This doesn't solve the problems of interrupts and
2126  * exceptions during or before the single step of the breakpoint,
2127  * but it solves the problem of running multiple actions within the
2128  * thread. If we didn't have the stack, we would no longer know
2129  * which probepoint we were handling...
2130  */
2133 
2134  /*
2135  * If this target supports an underlying physical address space, and
2136  * that address space can be shared amongst the target's threads, we
2137  * might place breakpoints in shared pages. So -- if we hit a
2138  * breakpoint at such a page in a thread that is not registered on
2139  * the breakpoint, we have to emulate the breakpoint's behavior. See
2140  * target_memmod_emulate_bp_handler() and target_memmod_ss_handler().
2141  */
2143 
2144  /* See target->interrupted_ss_handler. */
2146 
2147  /*
2148  * Any single step actions that are executing in this thread. We
2149  * might have more than one at a single probepoint, or we might have
2150  * accumulated one or more from previous probepoints that are still
2151  * being handled. They each have per-thread state, since an action
2152  * for a probe attached to TID_GLOBAL could be fired in any thread.
2153  * If it wasn't for that case, action state would be per-thread
2154  * only, but able to be kept entirely within the action struct.
2155  */
2157 
2158  /*
2159  * A simple key/value store for generic target thread state that is
2160  * specific to this target thread instance.
2161  */
2162  GHashTable *gkv_store;
2163 };
2164 
2165 struct target_spec {
2167 
2172 
2176  uint8_t spec_was_base:1,
2177  spec_was_overlay:1,
2178  start_paused:1,
2179  kill_on_close:1,
2180  stay_paused:1;
2181 
2183 
2184  /*
2185  * All personalities have unique string IDs. The user can force a
2186  * specific one to be used here if they like, although that is
2187  * likely to be a bad idea, unless they've implemented a custom
2188  * personality that is outside the VMI install tree.
2189  */
2191  /*
2192  * If the personality is to be loaded from a specific shared
2193  * library, this is the filename.
2194  */
2196 
2198  /* struct array_list of struct debugfile_load_opts * */
2200 
2201  /*
2202  * If kill_on_close, call kill() during close() with this signal.
2203  */
2205 
2206  /*
2207  * I/O behavior is a bit complicated. We want a couple things -- to
2208  * support the target library by itself (i.e., user code calling
2209  * directly into the library); and to support the XML SOAP server
2210  * calling into the library on behalf of the user. In both cases,
2211  * we might want I/O logged to a file; we might want I/O callbacks
2212  * to the user (we might want it buffered too, but forget that for
2213  * now).
2214  *
2215  * So, if the caller wants stdio interaction, the backend must open
2216  * the I/O devices and expose them to the caller as an FD -- the
2217  * caller specifies this by providing evloop_handler_ts for the
2218  * stdio descriptor types it cares about. If the user does not
2219  * specify one of these, but instead specifies a filename, the
2220  * backend must auto-write/-read the output/input to/from the named
2221  * file.
2222  *
2223  * (If handlers are provided, the caller *must* call
2224  * target_attach_evloop() sometime -- otherwise if the target does
2225  * i/o on those descriptors, they will probably fill up and block it!)
2226  *
2227  *
2228  * Only the backend knows how to deal with I/O, for each backend.
2229  * So, we have to rely on the backend to give us file descriptors
2230  * for the target I/Os we care about. We assume stdin, stdout, and
2231  * an optional stderr. The problem is, some backends might provide
2232  * stdio access only if we launch a new target (Ptrace); others
2233  * might provide access anytime (Xen); but we can't know until the
2234  * backend parses the spec and figures out what to do.
2235  *
2236  * (Even if the backend opens one of these files, it must not remove
2237  * it! That is the user or caller's job.)
2238  *
2239  * This kind of sucks... but we'll just warn the client if it tries
2240  * to do something the backend doesn't support. Later we can do
2241  * something better, like warning a priori.
2242  *
2243  */
2247 
2248  char *infile;
2249  char *outfile;
2250  char *errfile;
2251 
2253 };
2254 
2261  char **quoted_argv;
2264 };
2265 
2268  int *again,void *priv);
2269 
2270 typedef result_t (*target_debug_bp_handler_t)(struct target *target,
2271  struct target_thread *tthread,
2272  struct probepoint *probepoint,
2273  int was_stepping);
2274 typedef result_t (*target_debug_handler_t)(struct target *target,
2275  struct target_thread *tthread,
2276  struct probepoint *probepoint);
2277 
2294 struct target_location_ctxt *target_global_tlctxt(struct target *target);
2295 
2296 struct target_location_ctxt *
2297 target_location_ctxt_create(struct target *target,tid_t tid,
2298  struct memregion *region);
2299 struct target_location_ctxt *
2300 target_location_ctxt_create_from_bsymbol(struct target *target,tid_t tid,
2301  struct bsymbol *bsymbol);
2302 void
2304  struct bsymbol *bsymbol);
2305 void target_location_ctxt_free(struct target_location_ctxt *tlctxt);
2306 
2307 /*
2308  * Thread stack unwind support. Not all targets need to support this.
2309  *
2310  * A user calls target_unwind to set up an unwinding context. Then they
2311  * can call target_unw_getframe repeatedly until they get no more
2312  * frames. If it returns NULL and errno is set, there was an error; if
2313  * errno is not set, there are no more frames on the call stack. Then
2314  * the user must call target_unw_free to clean up the unwinding
2315  * context. This will free all values, register caches, etc. It is not
2316  * safe to reuse any of those pointers.
2317  */
2318 typedef enum {
2325 
2326 /*
2327  * We pass one of these to the dwdebug location functions as the
2328  * location_ops priv data; thus it gets back to us. We need to be able
2329  * to pass this when we have
2330  */
2332  /*
2333  * We pass a pointer to this to the location_* functions; they pass
2334  * us a pointer to the containing struct (target_location_ctxt). In
2335  * other words, lctxt->priv points to the containing struct. This
2336  * means we don't always have to malloc a location_ctxt struct; and
2337  * then lctxt is the only keeper of current_frame.
2338  */
2340 
2341  /*
2342  * A location context is always pinned to a specific target thread.
2343  * This makes sure we access the correct registers.
2344  */
2346  /*
2347  * On the other hand, the region it is bound to changes as the
2348  * *frame* context changes (i.e., if @unw is set below, @region will
2349  * correspond to the region associated with the symbol
2350  *
2351  * These are dynamically set according @unw, if it is in use!
2352  */
2354 
2355  /*
2356  * If we've attached unwinding state to this context, this is it.
2357  */
2359 };
2360 
2361 /*
2362  * A stack frame (activation).
2363  */
2366  int frame;
2368 
2369  /*
2370  * The function symbol associated with this frame. Ok, now we have
2371  * an "alternate" symbol -- the primary is the one associated with
2372  * the debuginfo; the alternate is the binfile symbol. Sometimes
2373  * the best debuginfo symbol we can get is the file symbol; but
2374  * usually the binfile has more fine-grained symbols we can use
2375  * instead; they just might not be in debuginfo.
2376  */
2377  struct bsymbol *bsymbol;
2379 
2380  /*
2381  * This contains the restored registers.
2382  *
2383  * NB: this is NULL if @frame == 0, because we want to support live
2384  * edits to the base registers, and don't want to cache them.
2385  */
2386  GHashTable *registers;
2387 
2388  /*
2389  * Backend-specific extra state.
2390  */
2391  void *priv;
2392 };
2393 
2394 typedef enum {
2399 
2400 /*
2401  * This is a very simple unwinding API.
2402  */
2403 struct target_location_ctxt *target_unwind(struct target *target,tid_t tid);
2404 int target_unwind_snprintf(char *buf,int buflen,struct target *target,tid_t tid,
2405  target_unwind_style_t fstyle,
2406  char *frame_sep,char *ksep);
2411  REG reg,REGVAL *o_regval);
2416 
2417 /*
2418  * A target is the top-level entity a user creates or associates with to
2419  * start a debugging session. Targets bind state and type metadata to
2420  * an execution context and at least one address space.
2421  */
2422 struct target {
2426 
2427  uint32_t live:1,
2428  writeable:1,
2430  threadctl:1,
2431  mmapable:1,
2432  opened:1,
2433  kill_on_close:1,
2434  monitorhandling:1,
2437  no_adjust_bp_ip:1;
2438 
2440 
2441  /*
2442  * How we track status is a little funny. Basically, we want the
2443  * target's event handlers (monitor, poll, an evloop handler) to set
2444  * status before leaving the handling code (to return into the rest
2445  * of the library, or to the user code). This avoids lots of
2446  * (potentially, depending on backend) expensive calls to
2447  * @ops->status.
2448  *
2449  * The backend must only set target and thread status via
2450  * target(_thread)_set_status or similar, so that we can track and
2451  * debug the changes. The backend must set status corresponding to
2452  * whatever state it leaves the target in. That means, for
2453  * instance, for the ptrace target, if it resumes tracing on behalf
2454  * of the user, it sets status to RUNNING. The backend should only
2455  * set status to _ERROR if the error is a fatal, final error, and
2456  * the target API cannot continue. monitor/poll can return _ERROR,
2457  * *but* only if they are temporary errors that the backend feels
2458  * safe continuing with. In reality, the backend author must
2459  * minimize these; the user cannot deal with them very well, other
2460  * than cleaning up as best they can.
2461  *
2462  * When the target is not opened, we always call into the backend to
2463  * set the status field each time target_status is called.
2464  */
2466 
2467  unsigned int max_thread_ctxt;
2471 
2472  /*
2473  * Each target has a unique integer ID; this is the key into the
2474  * target hashtable, for instance.
2475  */
2476  int id;
2478 
2479  /*
2480  * Each target has a unique name; this is generated by
2481  * target_ops->snprintf during target_init.
2482  */
2483  char *name;
2484 
2485  /*
2486  * state is for, and owned, by the backend providing this target.
2487  */
2488  void *state;
2489  /*
2490  * Right now, personality_state is owned by the personality -- and
2491  * the personality_ops and
2492  * (os_ops|process_ops|application_ops|runtime_ops) own that state
2493  * together. No need to separate those things for now.
2494  */
2496 
2497  /*
2498  * These are the primary target operations, provided by the backend
2499  * as necessary/applicable. The backend need not provide all
2500  * operations, especially if it is counting on a personality to fill
2501  * them in, as described below. Target backends may be designed to
2502  * require a personality; utilize a personality; or to block any
2503  * personality ops from ever being called (i.e., if the personality
2504  * is effectively integrated fully into the target ops -- sometimes
2505  * a target backend cannot be separated into a generic control
2506  * interface, or there might not be an available personality, or
2507  * whatever -- the abstraction is deliberately designed to be
2508  * flexible). Read more below...
2509  */
2510  struct target_ops *ops;
2512  /*
2513  * Ok, these ops structures are for personalities. A personality
2514  * can "overload" the target with more information. For instance,
2515  * some targets may provide low-level machine control/read/write;
2516  * but a *personality* might be able to fill in more info by
2517  * reading/writing symbols in the target to obtain a richer
2518  * representation of the target, or to enable more functionality.
2519  *
2520  * By abstracting it this way, we allow a target backend to be
2521  * written in a minimal style, and to be enriched by a personality.
2522  * This supports writing, for instance, a bare-bones xen vm backend
2523  * that supports minimal x86 machine control/read/write via the Xen
2524  * control interface; but allows that same backend to be enriched by
2525  * the os_linux_generic personality; a customized version for
2526  * specific linux kernel versions; or a windows personality.
2527  *
2528  * The reason we reuse a full struct target_ops for personality ops,
2529  * instead of creating a struct target_personality_ops, is because
2530  * many of the operations could legitimately be provided by either
2531  * the target backend, or by the personality, depending on the
2532  * target in question. A PHP target backend might not support a
2533  * separate personality; it might just be all integrated into the
2534  * backend. It may be impossible to disentangle the primary backend
2535  * from the personality.
2536  *
2537  * So here's how the Target API/library work this all out.
2538  * Everything goes through the target API or library wrapper
2539  * functions; they are the only things that call through the ops
2540  * structs. Basically, if the target backend implements one of the
2541  * target ops, the implementation should call the
2542  * target_personality_[op] wrapper function for the op in question.
2543  * If the target backend does *not* implement an op, but the
2544  * personality does; the target library will call that op instead of
2545  * the target op.
2546  */
2548  /*
2549  * OS/Process/Application ops will probably also be provided by the
2550  * same library providing the personality, but this need not be the
2551  * case.
2552  */
2553  union {
2557  };
2558 
2559  /*
2560  * Each target *must* have an architecture. This pointer must be
2561  * set by the target backend factory functions.
2562  */
2563  struct arch *arch;
2564 
2566 
2568 
2569  /*
2570  * If the spec specified stdio interactions via handlers, these are
2571  * the file descriptors.
2572  */
2573  int infd;
2574  int outfd;
2575  int errfd;
2576 
2577  /*
2578  * A simple key/value store for generic target configuration
2579  * options. Anything keys/values placed in it will be free()d when
2580  * the hashtable is freed, so be careful!
2581  */
2582  GHashTable *config;
2583 
2584  /*
2585  * A simple key/value store for generic target state that is
2586  * specific to this target instance. This is useful for probe
2587  * libraries that store per-target info -- but don't want to manage
2588  * a per-target cache themselves.
2589  *
2590  * It's also useful for any state that is per-target that must be
2591  * automatically destroyed on target close or free.
2592  */
2593  GHashTable *gkv_store;
2594 
2595  /*
2596  * If the target is attached to an evloop, this is that evloop.
2597  */
2598  struct evloop *evloop;
2599 
2600  /* Targets can have multiple address spaces, but not sure how we're
2601  * going to use this yet.
2602  */
2603  GList *spaces;
2604 
2605  /*
2606  * Each target has a primary binfile associated with it; think
2607  * "main" for userspace, the kernel for kernels.
2608  */
2609  struct binfile *binfile;
2610 
2611  /*
2612  * If this is an overlay, this is the underlying "base" target info.
2613  */
2614  struct target *base;
2616  int base_id;
2618 
2619  /*
2620  * Any live overlay targets are placed here. There can only be a
2621  * single overlay per thread, at the moment.
2622  */
2623  GHashTable *overlays;
2624  /*
2625  * Once an overlay has attached to one of this target's threads, it
2626  * can can "alias" other threads in the underlying target to point
2627  * to the overlay. For instance, this can help to map all threads
2628  * in a thread group into a single overlay process target.
2629  */
2630  GHashTable *overlay_aliases;
2631 
2632  GHashTable *threads;
2633  /*
2634  * For single-threaded targets, this will always be the global
2635  * thread. For multi-threaded targets, it will be the
2636  * currently-executing thread (and if there is no thread context,
2637  * i.e., the machine is in interrupt context, it will be the global
2638  * thread).
2639  */
2641  /*
2642  * This is the thread that should be used for any TID_GLOBAL
2643  * operations. Its state should always be loaded
2644  */
2646 
2647  /*
2648  * If we have to pause all threads in the target while we handle a
2649  * breakpoint for one thread, we always make sure to waitpid() for
2650  * this blocking thread first, and handle it first, before handling
2651  * any others.
2652  */
2654 
2655  /*
2656  * This should be a load context corresponding to TID_GLOBAL.
2657  * Target backends should create it in their init() functions. If
2658  * they set the global_tlctxt_is_dynamic bit above, as well,
2659  * target_global_tlctxt() will attempt to replace the value of the
2660  * ->region member with the region associated with the current IP.
2661  * This supports backends that create a single static region
2662  * spanning the entire target.
2663  *
2664  * target_global_tlctxt() will return this structure; it should never
2665  * be freed.
2666  */
2668 
2669  /*
2670  * This is for target backends to use if they wish.
2671  *
2672  * The idea is, each time we single step a thread, we make a note of
2673  * it here; each time we run the monitor loop looking for debug
2674  * exceptions, after we find one, clear this variable after checking
2675  * any state related to it, so that we know how to handle the debug
2676  * exception -- but then CLEAR it before handling the exception via
2677  * the probe library. The Xen target does this; the linux ptrace
2678  * target does not.
2679  *
2680  * This is not completely trustworthy on targets that do not provide
2681  * good thread control. It is here for the case in which we single
2682  * step an instruction that might switch contexts. If we have just
2683  * done that, and this var is set, a target's monitor loop should
2684  * notice and try to "handle" the singlestep in the previous thread,
2685  * even though the thread is no longer running.
2686  */
2688  /*
2689  * Also, if the overlay target uses the underlay's single step
2690  * mechanism, provide a place to mark that it did, so that the
2691  * overlay can handle the resulting single steps if it needs to.
2692  */
2693  struct target *sstep_thread_overlay;
2694 
2695  GHashTable *soft_probepoints;
2696 
2697  /*
2698  * A table of memory modifications, and their states. We use this
2699  * to support software probepoints.
2700  */
2701  GHashTable *mmods;
2702 
2703  /*
2704  * A table of physical memory modifications, and their states. We
2705  * use this to support software probepoints.
2706  *
2707  * Phys mmods are global to a target because it supports MMU-based
2708  * multiple address spaces -- i.e., addrs are fundamentally virt
2709  * addrs in a target. This allows a target to be aware of physical
2710  * addrs below virt addrs. So, it can support the case where a
2711  * memmod might have been made in the VMM of a userspace process,
2712  * but that this memmod might also manifest in the VMM of another
2713  * userspace process at a different virt addr; but at the same phys
2714  * addr.
2715  */
2716  GHashTable *phys_mmods;
2717 
2718  /*
2719  * A hashtable of probe IDs to probes that were created on this
2720  * target.
2721  *
2722  * Probes may be attached to specific threads, but we track them
2723  * globally here, mostly for the XML RPC server.
2724  */
2725  GHashTable *probes;
2726 
2727  /*
2728  * A hashtable of (scheduled) action IDs to actions.
2729  *
2730  * Although (scheduled) actions are attached to probepoints, we
2731  * track them by ID on a per-target basis. Right now, this is only
2732  * used for XML RPCs; internally, the IDs are unused.
2733  *
2734  * Also note that we do not explicitly "free" actions; users
2735  */
2736  GHashTable *actions;
2737 
2738  /*
2739  * Counters for the IDs for probes/actions.
2740  */
2743 
2744  /*
2745  * If we cache any of the target's v2p mappings or mmap its memory,
2746  * this is the struct the backends should initialize, populate, and
2747  * use. See memcache.h... For now, backends interact with the
2748  * memcache, and the target API does not. Backends should control
2749  * it for now.
2750  */
2752 
2753  /* Cache of loaded code, by address range. */
2755 };
2756 
2757 struct target_ops {
2758  int (*snprintf)(struct target *target,char *buf,int bufsiz);
2759 
2760  /*
2761  * init any target state, like a private per-target state struct.
2762  *
2763  * If the backend needs to attach to the target and pause it now so
2764  * that it can initialize, that is allowed -- but we don't expect
2765  * it.
2766  *
2767  * XXX: what about personalities that might try to read the target's
2768  * reg/mem to initialize???
2769  */
2770  int (*init)(struct target *target);
2771  /*
2772  * Destroy any target state and perform any final cleanup specific
2773  * to the backend.
2774  */
2775  int (*fini)(struct target *target);
2776  /*
2777  * Actually connect to the target to enable read/write.
2778  */
2779  int (*attach)(struct target *target);
2780  /* detach from target, but don't unload */
2781  int (*detach)(struct target *target,int stay_paused);
2782  /* destroy the target */
2783  int (*kill)(struct target *target,int sig);
2784 
2785  /* Divide the target into address spaces with different IDs, that
2786  * might contain multiple subregions.
2787  */
2788  int (*loadspaces)(struct target *target);
2789  /* divide the address space into regions, each containing one
2790  * or more ranges, with different protection flags, that might come
2791  * from different source binary files.
2792  */
2793  int (*loadregions)(struct target *target,
2794  struct addrspace *space);
2795  /* for each loaded region, load one or more debugfiles and associate
2796  * them with the region.
2797  */
2798  int (*loaddebugfiles)(struct target *target,
2799  struct addrspace *space,
2800  struct memregion *region);
2801  /* Once regions and debugfiles are loaded, we call this -- it's a
2802  * second-pass init, basically.
2803  */
2804  int (*postloadinit)(struct target *target);
2805  /* Once @attach has been called and has succeeded, we call this --
2806  * primarily it's a chance for the target to register probes on
2807  * itself.
2808  *
2809  * We initially call it with @target->spec->active_probe_flags; but
2810  * users may later call target_set_active_probing() to fine-tune
2811  * settings.
2812  */
2813  int (*set_active_probing)(struct target *target,active_probe_flags_t flags);
2814  /* Once @attach has been called and has succeeded, the target is
2815  * opened. This is the final function we call in target_open.
2816  */
2817  int (*postopened)(struct target *target);
2818 
2819  /* Single step and breakpoint handlers. Since we control
2820  * single-step mode, we report *any* single step stop events to the
2821  * handler, and do nothing with them ourselves.
2822  *
2823  * For breakpoints, if we don't have a probepoint matching the
2824  * breaking EIP, target_monitor will return to the library user, and
2825  * they'll have to handle the exception themselves (i.e., this would
2826  * happen if their code had a software breakpoint in it).
2827  */
2831  /*
2832  * If a thread was supposed to be stepping, but it steps into a new
2833  * context, this handler should be called to abort the single step;
2834  * save the probepoint in thread->interrupted_ss_probepoint; restore
2835  * the breakpoint. We save off the breakpoint so we can know that
2836  * when the breakpoint is hit again, we shouldn't run pre-handlers
2837  * again. This is definitely a dicey strategy -- how can we know
2838  * that we'll be at the interrupted context when we hit the
2839  * breakpoint next in this thread? For instance, the only place
2840  * this is used right now is the Xen target. Consider: a
2841  * xen-process target breakpoint is hit; we single step using HVM
2842  * MTF; instead of stepping in userspace, we find ourselves stepping
2843  * in that thread, but in the kernel. That means the singlestep of
2844  * the breakpoint didn't happen; thus we need to reset the
2845  * breakpoint. BUT, then, what happens on return from the kernel?
2846  * Normally, the breakpoint would be immediately hit again, and the
2847  * single step would work. Unfortunately, kernels don't guarantee
2848  * this behavior... the userspace EIP could be adjusted to deliver a
2849  * signal, or whatever. But all we can do is assume it, unless we
2850  * want to get into the heavyweight business of tracking context
2851  * switches.
2852  */
2854 
2855  /*
2856  * A single function that allows a target backend to be notified of
2857  * key target events. This allows a backend to be notified of
2858  * changes that its personality makes; or for an overlay target
2859  * backend to be notified when the underlying target senses an event
2860  * that is relevant to the overlay.
2861  */
2862  void (*handle_event)(struct target *target,struct target_event *event);
2863 
2864  int (*obj_flags_propagate)(struct target *target,
2865  obj_flags_t orf,obj_flags_t nandf);
2866 
2867  /*
2868  * "Underlay" targets (that support overlays) must define these
2869  * functions.
2870  */
2871  struct target_spec *(*build_default_overlay_spec)(struct target *target,
2872  tid_t tid);
2873  struct target *(*instantiate_overlay)(struct target *target,
2874  struct target_thread *tthread,
2875  struct target_spec *spec,
2876  struct target_thread **ntthread);
2877  struct target_thread *(*lookup_overlay_thread_by_id)(struct target *target,
2878  int id);
2879  struct target_thread *(*lookup_overlay_thread_by_name)(struct target *target,
2880  char *name);
2881  int (*attach_overlay_thread)(struct target *base,struct target *overlay,
2882  tid_t newtid);
2883  int (*detach_overlay_thread)(struct target *base,struct target *overlay,
2884  tid_t tid);
2885  /*
2886  * Overlay targets must support this if their exceptions come from
2887  * the underlying target.
2888  */
2889  target_status_t (*handle_overlay_exception)(struct target *overlay,
2891  tid_t tid,ADDR ipval,int *again);
2892 
2893  /* get target status. */
2894  target_status_t (*status)(struct target *target);
2895  /* pause a target */
2896  int (*pause)(struct target *target,int nowait);
2897  /* resume from a paused state */
2898  int (*resume)(struct target *target);
2899  /* wait for something to happen to the target */
2900  target_status_t (*monitor)(struct target *target);
2901  target_status_t (*poll)(struct target *target,struct timeval *tv,
2902  target_poll_outcome_t *outcome,int *pstatus);
2903 
2904  /*
2905  * NB, driver developers: target_monitor_evloop() assumes that you
2906  * will set the void *state param to evloop_set_fd to the target
2907  * argument!!! Make sure to follow that convention.
2908  */
2909  int (*attach_evloop)(struct target *target,struct evloop *evloop);
2910  int (*detach_evloop)(struct target *target);
2911 
2912  /* read some memory, potentially into a supplied buffer. */
2913  unsigned char *(*read) (struct target *target,ADDR addr,
2914  unsigned long length,unsigned char *buf);
2915  /* write some memory */
2916  unsigned long (*write)(struct target *target,ADDR addr,
2917  unsigned long length,unsigned char *buf);
2918 
2919  /* Some targets only support symbol reads/writes; support them! */
2920  struct value *(*read_symbol)(struct target *target,
2921  struct target_location_ctxt *tlctxt,
2922  struct bsymbol *bsymbol,load_flags_t flags);
2923  int (*write_symbol)(struct target *target,struct value *value);
2924 
2925  /*
2926  * Some targets might support threads that have their own virtual
2927  * address spaces, but an underlying system (like the kernel) might
2928  * share phys memory amongst separate thread virtual address
2929  * spaces.
2930  *
2931  * (The Xen target uses this to provide shared-page breakpoint
2932  * support to Xen Process overlay targets.)
2933  */
2934 
2935  int (*addr_v2p)(struct target *target,tid_t tid,ADDR vaddr,ADDR *paddr);
2936 
2937  /* read some phys memory, potentially into a supplied buffer. */
2938  unsigned char *(*read_phys)(struct target *target,ADDR paddr,
2939  unsigned long length,unsigned char *buf);
2940  /* write some phys memory */
2941  unsigned long (*write_phys)(struct target *target,ADDR paddr,
2942  unsigned long length,unsigned char *buf);
2943 
2948  /* Context stuff so that we can handle multithreaded targets, and
2949  * infinite single stepping in their presence.
2950  */
2951  tid_t (*gettid)(struct target *target);
2952  void (*free_thread_state)(struct target *target,void *state);
2953  struct array_list *(*list_available_tids)(struct target *target);
2954  struct target_thread *(*load_thread)(struct target *target,tid_t tid,
2955  int force);
2956  struct target_thread *(*load_current_thread)(struct target *target,
2957  int force);
2958  int (*load_all_threads)(struct target *target,int force);
2959  int (*load_available_threads)(struct target *target,int force);
2960  int (*pause_thread)(struct target *target,tid_t tid,int nowait);
2961  /* flush target(:tid) machine state */
2962  int (*flush_thread)(struct target *target,tid_t tid);
2963  int (*flush_current_thread)(struct target *target);
2964  int (*flush_all_threads)(struct target *target);
2965  int (*invalidate_thread)(struct target *target,struct target_thread *tthread);
2966  int (*gc_threads)(struct target *target);
2967  int (*thread_snprintf)(struct target *target,struct target_thread *tthread,
2968  char *buf,int bufsiz,
2969  int detail,char *sep,char *key_val_sep);
2970 
2971  /*
2972  * Register stuff.
2973  *
2974  * A backend can use several strategies to implement register handling.
2975  *
2976  * 1) Implement the methods below, and handle caching itself. This
2977  * would be more suitable to on-demand register loading (i.e., if
2978  * you're not going to load all registers in the thread load
2979  * methods).
2980  *
2981  * 2) Use the regcache, and set all these methods to the
2982  * target_regcache_* versions. Then you must load all registers in
2983  * the thread loader methods, and flush all dirty registers in the
2984  * thread flush methods. In some ways, this is currently the
2985  * preferred style, because then there is some linkage that a user
2986  * could/should expect between the backend and the arch's registers
2987  * (in that the backend should load all the arch registers!). But
2988  * the downside is the double buffering and copying
2989  * overhead... because backends that can load multiple registers
2990  * from a single copy in memory might well just copy that whole
2991  * section and write it out once. However, the regcache also helps
2992  * you track dirty registers on a more fine-grained level.
2993  *
2994  * If the target backend is going to use our
2995  * generic regcache support, these should all be set to the
2996  * target_regcache_* functions, or to NULL! If it does not use
2997  * regcache, all of these must be set to custom functions.
2998  *
2999  * If it does use regcache, its thread-loading functions *must* call
3000  * the target_regcache_init_reg functions to load registers.
3001  *
3002  * This may seem a bit weird, and it does force the thread loaders
3003  * to pre-populate the cache. BUT, that is why we have the
3004  * initreg_tidctxt method below. The target_init_reg_tidctxt
3005  * function calls that backend function if it is defined; else, it
3006  * sticks the reg into the regcache. So, as a backend developer, if
3007  * you want to make sure you control your own register caching, and
3008  * want to support the target_init_reg_tidctxt backend/personality
3009  * helper function, you must define initreg_tidctxt.
3010  *
3011  * That is the guts of the compromise of supporting an optional
3012  * regcache, or allowing the backend to support its own caching --
3013  * while still allowing a personality to *not* manage its own
3014  * caching.
3015  *
3016  * (Realistically, these functions need to be implemented; it's just
3017  * a matter of how the backend wants to flush a cache of pending
3018  * register writes at target_resume as it flushes its threads. Many
3019  * backends may implement readreg/writereg as calls to
3020  * readreg/writereg_tidctxt, where the tidctxt is the thread's
3021  * current context).
3022  */
3023  REGVAL (*readreg)(struct target *target,tid_t tid,REG reg);
3024  int (*writereg)(struct target *target,tid_t tid,REG reg,REGVAL value);
3025  GHashTable *(*copy_registers)(struct target *target,tid_t tid);
3026 
3027  REGVAL (*readreg_tidctxt)(struct target *target,
3028  tid_t tid,thread_ctxt_t tidctxt,REG reg);
3029  int (*writereg_tidctxt)(struct target *target,
3030  tid_t tid,thread_ctxt_t tidctxt,REG reg,REGVAL value);
3031 
3032  /* unwind support */
3033  struct target_location_ctxt *(*unwind)(struct target *target,tid_t tid);
3034  int (*unwind_read_reg)(struct target_location_ctxt *tlctxt,
3035  REG reg,REGVAL *o_regval);
3037  (*unwind_prev)(struct target_location_ctxt *tlctxt);
3038 
3039  /* breakpoint/watchpoint stuff */
3040  int (*probe_register_symbol)(struct target *target,tid_t tid,
3041  struct probe *probe,struct bsymbol *bsymbol,
3042  probepoint_style_t style,
3043  probepoint_whence_t whence,
3044  probepoint_watchsize_t watchsize);
3045  struct target_memmod *(*insert_sw_breakpoint)(struct target *target,tid_t tid,
3046  ADDR addr);
3047  int (*remove_sw_breakpoint)(struct target *target,tid_t tid,
3048  struct target_memmod *mmod);
3049  int (*enable_sw_breakpoint)(struct target *target,tid_t tid,
3050  struct target_memmod *mmod);
3051  int (*disable_sw_breakpoint)(struct target *target,tid_t tid,
3052  struct target_memmod *mmod);
3053  int (*change_sw_breakpoint)(struct target *target,tid_t tid,
3054  struct target_memmod *mmod,
3055  unsigned char *code,unsigned long code_len);
3056  int (*unchange_sw_breakpoint)(struct target *target,tid_t tid,
3057  struct target_memmod *mmod);
3058  REG (*get_unused_debug_reg)(struct target *target,tid_t tid);
3059  int (*set_hw_breakpoint)(struct target *target,tid_t tid,REG reg,ADDR addr);
3060  int (*set_hw_watchpoint)(struct target *target,tid_t tid,REG reg,ADDR addr,
3061  probepoint_whence_t whence,
3062  probepoint_watchsize_t watchsize);
3063  int (*unset_hw_breakpoint)(struct target *target,tid_t tid,REG reg);
3064  int (*unset_hw_watchpoint)(struct target *target,tid_t tid,REG reg);
3065  int (*disable_hw_breakpoints)(struct target *target,tid_t tid);
3066  int (*enable_hw_breakpoints)(struct target *target,tid_t tid);
3067  int (*disable_hw_breakpoint)(struct target *target,tid_t tid,REG dreg);
3068  int (*enable_hw_breakpoint)(struct target *target,tid_t tid,REG dreg);
3069  int (*notify_sw_breakpoint)(struct target *target,ADDR addr,
3070  int notification);
3071  int (*singlestep)(struct target *target,tid_t tid,int isbp,
3072  struct target *overlay);
3073  int (*singlestep_end)(struct target *target,tid_t tid,
3074  struct target *overlay);
3075 
3076  /* Instruction-specific stuff for stepping. */
3077  /*
3078  * Returns > 0 if the instruction might switch contexts; 0
3079  * if not; -1 on error.
3080  */
3081  int (*instr_can_switch_context)(struct target *target,ADDR addr);
3082 
3083  /*
3084  * Stuff for counters. Each target should provide its TSC
3085  * timestamp, an internal notion of time since boot in nanoseconds,
3086  * and if they support indexed execution, a "cycle counter" or
3087  * something.
3088  */
3089  uint64_t (*get_tsc)(struct target *target);
3090  uint64_t (*get_time)(struct target *target);
3091  uint64_t (*get_counter)(struct target *target);
3092 
3093  int (*enable_feature)(struct target *target,int feature,void *arg);
3094  int (*disable_feature)(struct target *target,int feature);
3095 };
3096 
3098  int (*snprintf)(struct target *target,char *buf,int bufsiz);
3099 
3100  int (*attach)(struct target *target);
3101  int (*init)(struct target *target);
3102  int (*fini)(struct target *target);
3103 
3104  int (*loadspaces)(struct target *target);
3105  int (*loadregions)(struct target *target,
3106  struct addrspace *space);
3107  int (*loaddebugfiles)(struct target *target,
3108  struct addrspace *space,
3109  struct memregion *region);
3110 
3111  int (*postloadinit)(struct target *target);
3112 
3113  int (*set_active_probing)(struct target *target,active_probe_flags_t flags);
3114 
3115  int (*postopened)(struct target *target);
3116 
3117  void (*handle_event)(struct target *target,struct target_event *event);
3118  int (*obj_flags_propagate)(struct target *target,
3119  obj_flags_t orf,obj_flags_t nandf);
3120 
3121  int (*handle_exception)(struct target *target,
3122  target_exception_flags_t flags);
3123 
3124  unsigned char *(*read)(struct target *target,ADDR addr,
3125  unsigned long length,unsigned char *buf);
3126  unsigned long (*write)(struct target *target,ADDR addr,
3127  unsigned long length,unsigned char *buf);
3128  int (*addr_v2p)(struct target *target,tid_t tid,ADDR vaddr,ADDR *paddr);
3129  unsigned char *(*read_phys)(struct target *target,ADDR paddr,
3130  unsigned long length,unsigned char *buf);
3131  unsigned long (*write_phys)(struct target *target,ADDR paddr,
3132  unsigned long length,unsigned char *buf);
3133 
3134  void (*free_thread_state)(struct target *target,void *state);
3135  struct array_list *(*list_available_tids)(struct target *target);
3136  struct target_thread *(*load_thread)(struct target *target,tid_t tid,
3137  int force);
3138  struct target_thread *(*load_current_thread)(struct target *target,
3139  int force);
3140  int (*load_available_threads)(struct target *target,int force);
3141  int (*pause_thread)(struct target *target,tid_t tid,int nowait);
3142  /* flush target(:tid) machine state */
3143  int (*flush_thread)(struct target *target,tid_t tid);
3144  int (*flush_current_thread)(struct target *target);
3145  int (*invalidate_thread)(struct target *target,struct target_thread *tthread);
3146  int (*gc_threads)(struct target *target);
3147  int (*thread_snprintf)(struct target *target,struct target_thread *tthread,
3148  char *buf,int bufsiz,
3149  int detail,char *sep,char *key_val_sep);
3150 
3151  /* get/set contents of a register */
3152  REGVAL (*readreg)(struct target *target,tid_t tid,REG reg);
3153  int (*writereg)(struct target *target,tid_t tid,REG reg,REGVAL value);
3154  GHashTable *(*copy_registers)(struct target *target,tid_t tid);
3155 
3156  REGVAL (*readreg_tidctxt)(struct target *target,
3157  tid_t tid,thread_ctxt_t tidctxt,REG reg);
3158  int (*writereg_tidctxt)(struct target *target,
3159  tid_t tid,thread_ctxt_t tidctxt,REG reg,REGVAL value);
3160 
3161  /* unwind support */
3162  struct target_location_ctxt *(*unwind)(struct target *target,tid_t tid);
3163  int (*unwind_read_reg)(struct target_location_ctxt *tlctxt,
3164  REG reg,REGVAL *o_regval);
3166  (*unwind_prev)(struct target_location_ctxt *tlctxt);
3167 
3168  /* breakpoint/watchpoint stuff */
3169  int (*probe_register_symbol)(struct target *target,tid_t tid,
3170  struct probe *probe,struct bsymbol *bsymbol,
3171  probepoint_style_t style,
3172  probepoint_whence_t whence,
3173  probepoint_watchsize_t watchsize);
3174  struct target_memmod *(*insert_sw_breakpoint)(struct target *target,tid_t tid,
3175  ADDR addr);
3176  int (*remove_sw_breakpoint)(struct target *target,tid_t tid,
3177  struct target_memmod *mmod);
3178  int (*enable_sw_breakpoint)(struct target *target,tid_t tid,
3179  struct target_memmod *mmod);
3180  int (*disable_sw_breakpoint)(struct target *target,tid_t tid,
3181  struct target_memmod *mmod);
3182  int (*change_sw_breakpoint)(struct target *target,tid_t tid,
3183  struct target_memmod *mmod,
3184  unsigned char *code,unsigned long code_len);
3185  int (*unchange_sw_breakpoint)(struct target *target,tid_t tid,
3186  struct target_memmod *mmod);
3187  REG (*get_unused_debug_reg)(struct target *target,tid_t tid);
3188  int (*set_hw_breakpoint)(struct target *target,tid_t tid,REG reg,ADDR addr);
3189  int (*set_hw_watchpoint)(struct target *target,tid_t tid,REG reg,ADDR addr,
3190  probepoint_whence_t whence,
3191  probepoint_watchsize_t watchsize);
3192  int (*unset_hw_breakpoint)(struct target *target,tid_t tid,REG reg);
3193  int (*unset_hw_watchpoint)(struct target *target,tid_t tid,REG reg);
3194  int (*disable_hw_breakpoints)(struct target *target,tid_t tid);
3195  int (*enable_hw_breakpoints)(struct target *target,tid_t tid);
3196  int (*disable_hw_breakpoint)(struct target *target,tid_t tid,REG dreg);
3197  int (*enable_hw_breakpoint)(struct target *target,tid_t tid,REG dreg);
3198  int (*notify_sw_breakpoint)(struct target *target,ADDR addr,
3199  int notification);
3200  int (*singlestep)(struct target *target,tid_t tid,int isbp,
3201  struct target *overlay);
3202  int (*singlestep_end)(struct target *target,tid_t tid,
3203  struct target *overlay);
3204 
3205  /* Instruction-specific stuff for stepping. */
3206  /*
3207  * Returns > 0 if the instruction might switch contexts; 0
3208  * if not; -1 on error.
3209  */
3210  int (*instr_can_switch_context)(struct target *target,ADDR addr);
3211 
3212  /*
3213  * Stuff for counters. Each target should provide its TSC
3214  * timestamp, an internal notion of time since boot in nanoseconds,
3215  * and if they support indexed execution, a "cycle counter" or
3216  * something.
3217  */
3218  uint64_t (*get_tsc)(struct target *target);
3219  uint64_t (*get_time)(struct target *target);
3220  uint64_t (*get_counter)(struct target *target);
3221 
3222  int (*enable_feature)(struct target *target,int feature,void *arg);
3223  int (*disable_feature)(struct target *target,int feature);
3224 };
3225 
3226 struct value {
3227  /*
3228  * We keep a reference to the target thread that resolved this
3229  * value. Why? Because although memory is thread-independent, the
3230  * location of variables is thread-dependent; it may depend on CPU
3231  * register state (i.e., a DWARF location expression that involves
3232  * reading the contents of registers).
3233  *
3234  * When a thread doesn't matter, @thread will be
3235  * target->global_thread (i.e., for loading values by type).
3236  */
3238 
3239  /*
3240  * The type of value -- it may NOT be the primary type of the
3241  * bsymbol! i.e., it may be the pointed-to type, or we may have
3242  * stripped off the const/vol qualifiers.
3243  *
3244  * We could also save the load flags so we always know what type of
3245  * memory this object is pointing to, but we'll skip that for now.
3246  */
3247  struct symbol *type;
3248 
3249  /*
3250  * A backreference to the symbol this value is associated with.
3251  */
3252  struct lsymbol *lsymbol;
3253 
3254  /* The memrange this value exists in. */
3255  struct memrange *range;
3256 
3257  int bufsiz;
3258  char *buf;
3259 
3260  uint8_t ismmap:1,
3261  isreg:1,
3262  isstring:1,
3263  isconst:1;
3264 
3265  /*
3266  * The location of the value.
3267  */
3268  union {
3271  } res;
3272 
3273  /*
3274  * The value of the PC when we last loaded this symbol.
3275  */
3277 
3279 };
3280 
3281 #endif
struct target * target_instantiate_overlay(struct target *target, tid_t tid, struct target_spec *spec)
Definition: target_api.c:724
int target_thread_snprintf(struct target *target, tid_t tid, char *buf, int bufsiz, int detail, char *sep, char *kvsep)
Definition: target_api.c:1360
uint64_t(* get_time)(struct target *target)
Definition: target_api.h:3219
int infd
Definition: target_api.h:2573
struct value * target_load_symbol(struct target *target, struct target_location_ctxt *tlctxt, struct bsymbol *bsymbol, load_flags_t flags)
Definition: target.c:3234
int target_flush_all_threads(struct target *target)
Definition: target_api.c:1275
tid_t target_lookup_overlay_thread_by_name(struct target *target, char *name)
Definition: target_api.c:690
uint16_t rv_u16(void *buf)
Definition: value.c:1209
struct value * target_load_type(struct target *target, struct symbol *type, ADDR addr, load_flags_t flags)
Definition: target.c:2618
char * THREAD_STATUS_STRINGS[]
Definition: target.c:6626
char * TSTATUS_STRINGS[]
Definition: target.c:6614
GHashTable * config
Definition: target_api.h:2582
int(* singlestep)(struct target *target, tid_t tid, int isbp, struct target *overlay)
Definition: target_api.h:3071
int(* fini)(struct target *target)
Definition: target_api.h:3102
int16_t v_i16(struct value *v)
Definition: value.c:335
int(* fini)(struct target *target)
Definition: target_api.h:2775
int target_change_sw_breakpoint(struct target *target, tid_t tid, struct target_memmod *mmod, unsigned char *code, unsigned long code_len)
Definition: target_api.c:1735
int(* flush_current_thread)(struct target *target)
Definition: target_api.h:2963
#define THREAD_STATUS_BITS
Definition: target_api.h:282
target_mode_t target_mode
Definition: target_api.h:2173
int value_update_i16(struct value *value, int16_t v)
Definition: value.c:471
struct target * base
Definition: target_api.h:2614
struct bsymbol * target_lookup_sym_line(struct target *target, char *filename, int line, SMOFFSET *offset, ADDR *addr)
Definition: target.c:2237
void * state
Definition: target_api.h:2488
void target_monitor_schedule_global_interrupt(void)
Definition: target.c:314
int value_snprintf(struct value *value, char *buf, int buflen)
Definition: value.c:581
int value_update_i32(struct value *value, int32_t v)
Definition: value.c:479
int action_id_counter
Definition: target_api.h:2742
int(* enable_hw_breakpoint)(struct target *target, tid_t tid, REG dreg)
Definition: target_api.h:3197
void * backend_spec
Definition: target_api.h:2252
int(* attach)(struct target *target)
Definition: target_api.h:2779
int(* handle_exception)(struct target *target, target_exception_flags_t flags)
Definition: target_api.h:3121
thread_bpmode_t bpmode
Definition: target_api.h:2174
void target_default_sighandler(int signo, siginfo_t *siginfo, void *x)
Definition: target.c:167
int value_update_f(struct value *value, float v)
Definition: value.c:495
int32_t tid_t
Definition: common.h:36
target_personality_t personality
Definition: target_api.h:2477
struct array_list * frames
Definition: target_api.h:2358
int(* addr_v2p)(struct target *target, tid_t tid, ADDR vaddr, ADDR *paddr)
Definition: target_api.h:2935
void * target_argp_driver_state(struct argp_state *state)
Definition: target.c:703
int(* attach)(struct target *target)
Definition: target_api.h:3100
target_status_t
Definition: target_api.h:197
struct value * target_load_type_reg(struct target *target, struct symbol *type, tid_t tid, REG reg, load_flags_t flags)
Definition: target.c:2875
void value_dump_simple(struct value *value, struct dump_info *ud)
Definition: value.c:1158
int(* disable_hw_breakpoints)(struct target *target, tid_t tid)
Definition: target_api.h:3065
int target_unwind_snprintf(char *buf, int buflen, struct target *target, tid_t tid, target_unwind_style_t fstyle, char *frame_sep, char *ksep)
Definition: target.c:5424
int target_load_available_threads(struct target *target, int force)
Definition: target_api.c:1235
common_reg_t
Definition: arch.h:73
int bsymbol_is_inline(struct bsymbol *bsymbol)
Definition: symbol.c:74
tid_t target_lookup_overlay_thread_by_id(struct target *target, int id)
Definition: target_api.c:670
int(* flush_all_threads)(struct target *target)
Definition: target_api.h:2964
uint64_t target_get_tsc(struct target *target)
Definition: target_api.c:1864
uint32_t no_adjust_bp_ip
Definition: target_api.h:2427
uint8_t isreg
Definition: target_api.h:3260
struct memregion * region
Definition: target_api.h:2353
struct target_location_ctxt * target_unwind(struct target *target, tid_t tid)
Definition: target.c:5298
GHashTable * overlays
Definition: target_api.h:2623
Definition: probe.h:392
int8_t v_i8(struct value *v)
Definition: value.c:334
int target_set_hw_watchpoint(struct target *target, tid_t tid, REG reg, ADDR addr, probepoint_whence_t whence, int watchsize)
Definition: target_api.c:1778
int(* unchange_sw_breakpoint)(struct target *target, tid_t tid, struct target_memmod *mmod)
Definition: target_api.h:3056
GHashTable * soft_probepoints
Definition: target_api.h:2695
sigset_t interrupt
Definition: spf.c:211
struct bsymbol * target_lookup_sym(struct target *target, const char *name, const char *delim, char *srcfile, symbol_type_flag_t ftype)
Definition: target.c:2169
tid_t(* gettid)(struct target *target)
Definition: target_api.h:2951
int target_monitor_evloop(struct evloop *evloop, struct timeval *timeout, struct target **target, target_status_t *status)
Definition: target_api.c:841
struct target_personality_ops * personality_ops
Definition: target_api.h:2547
struct target * sstep_thread_overlay
Definition: target_api.h:2693
struct target_thread * sstep_thread
Definition: target_api.h:2687
OFFSET target_offsetof_symbol(struct target *target, struct bsymbol *bsymbol, char *member, const char *delim)
Definition: target.c:3449
int(* unset_hw_breakpoint)(struct target *target, tid_t tid, REG reg)
Definition: target_api.h:3192
thread_resumeat_t
Definition: target_api.h:2032
int target_remove_sw_breakpoint(struct target *target, tid_t tid, struct target_memmod *mmod)
Definition: target_api.c:1695
int(* set_active_probing)(struct target *target, active_probe_flags_t flags)
Definition: target_api.h:3113
char * POLL_STRINGS[]
Definition: target.c:6645
evloop_handler_t in_evh
Definition: target_api.h:2244
struct target_process_ops * process_ops
Definition: target_api.h:2556
GHashTable * actions
Definition: target_api.h:2736
void target_init(void)
Definition: target.c:67
uint8_t rv_u8(void *buf)
Definition: value.c:1208
int target_bsymbol_resolve_base(struct target *target, struct target_location_ctxt *tlctxt, struct bsymbol *bsymbol, ADDR *o_addr, struct memrange **o_range)
Definition: target.c:2583
GHashTable * target_copy_registers(struct target *target, tid_t tid)
Definition: target_api.c:1138
int target_has_base(struct target *overlay, struct target *base)
struct action * target_lookup_action(struct target *target, int action_id)
Definition: target_api.c:1606
int target_resume(struct target *target)
Definition: target_api.c:973
long double v_dd(struct value *v)
Definition: value.c:370
uint8_t spec_was_base
Definition: target_api.h:2176
int(* pause_thread)(struct target *target, tid_t tid, int nowait)
Definition: target_api.h:3141
struct target_location_ctxt * target_location_ctxt_create_from_bsymbol(struct target *target, tid_t tid, struct bsymbol *bsymbol)
Definition: target.c:5269
int target_is_evloop_attached(struct target *target, struct evloop *evloop)
Definition: target_api.c:824
int target_disable_feature(struct target *target, int feature)
Definition: target_api.c:1892
probepoint_whence_t
Definition: probe_api.h:234
obj_flags_t obj_flags
Definition: target_api.h:2425
uint8_t kill_on_close
Definition: target_api.h:2176
void target_dump_thread(struct target *target, tid_t tid, FILE *stream, int detail)
Definition: target_api.c:1419
target_debug_bp_handler_t handle_break
Definition: target_api.h:2829
ADDR target_addressof_symbol(struct target *target, struct target_location_ctxt *tlctxt, struct bsymbol *bsymbol, load_flags_t flags, struct memrange **o_range)
Definition: target.c:3454
struct target_thread * base_thread
Definition: target_api.h:2615
wchar_t rv_wc(void *buf)
Definition: value.c:1207
struct target_location_ctxt * tlctxt
Definition: target_api.h:2365
active_probe_flags_t ap_flags
Definition: target_api.h:2439
probepoint_style_t style
Definition: target_api.h:2175
int(* unset_hw_breakpoint)(struct target *target, tid_t tid, REG reg)
Definition: target_api.h:3063
int(* flush_thread)(struct target *target, tid_t tid)
Definition: target_api.h:3143
REFCNT refcntw
Definition: target_api.h:2424
int target_pause(struct target *target)
Definition: target_api.c:988
union value::@27 res
int target_pause_thread(struct target *target, tid_t tid, int nowait)
Definition: target_api.c:1258
int64_t num_t
Definition: common.h:87
int32_t SMOFFSET
Definition: common.h:100
int(* init)(struct target *target)
Definition: target_api.h:3101
int kill_on_close_sig
Definition: target_api.h:2567
void value_dump(struct value *value, struct dump_info *ud)
Definition: value.c:1163
struct scope * target_lookup_addr(struct target *target, uint64_t addr)
Definition: target.c:2023
int target_cregno(struct target *target, common_reg_t creg, REG *reg)
Definition: target_api.c:1077
int64_t v_i64(struct value *v)
Definition: value.c:337
int(* unset_hw_watchpoint)(struct target *target, tid_t tid, REG reg)
Definition: target_api.h:3193
int(* unwind_read_reg)(struct target_location_ctxt *tlctxt, REG reg, REGVAL *o_regval)
Definition: target_api.h:3034
tid_t target_gettid(struct target *target)
Definition: target_api.c:1853
evloop_handler_t out_evh
Definition: target_api.h:2245
struct target_thread * global_thread
Definition: target_api.h:2645
target_status_t(* target_exception_handler_t)(struct target *target, target_exception_flags_t flags, int *again, void *priv)
Definition: target_api.h:2266
uint32_t monitorhandling
Definition: target_api.h:2427
int target_open_all(struct target *target)
int(* disable_sw_breakpoint)(struct target *target, tid_t tid, struct target_memmod *mmod)
Definition: target_api.h:3051
int(* obj_flags_propagate)(struct target *target, obj_flags_t orf, obj_flags_t nandf)
Definition: target_api.h:3118
ADDR addr
Definition: target_api.h:3269
int(* load_available_threads)(struct target *target, int force)
Definition: target_api.h:2959
int(* set_hw_breakpoint)(struct target *target, tid_t tid, REG reg, ADDR addr)
Definition: target_api.h:3059
int(* set_hw_breakpoint)(struct target *target, tid_t tid, REG reg, ADDR addr)
Definition: target_api.h:3188
int target_flush_thread(struct target *target, tid_t tid)
Definition: target_api.c:1269
char * bsymbol_get_name(struct bsymbol *bsymbol)
Definition: symbol.c:62
struct target_os_ops * os_ops
Definition: target_api.h:2555
Pvoid_t clrange_t
Definition: clfit.h:34
int value_update_addr(struct value *value, ADDR v)
Definition: value.c:519
int target_unchange_sw_breakpoint(struct target *target, tid_t tid, struct target_memmod *mmod)
Definition: target_api.c:1749
int value_update_num(struct value *value, num_t v)
Definition: value.c:528
evloop_handler_t err_evh
Definition: target_api.h:2246
int32_t OFFSET
Definition: common.h:65
GHashTable * target_hash_threads(struct target *target)
Definition: target_api.c:1188
int target_close(struct target *target)
Definition: target_api.c:1446
uint8_t stay_paused
Definition: target_api.h:2176
target_status_t(* status)(struct target *target)
Definition: target_api.h:2894
struct bsymbol * alt_bsymbol
Definition: target_api.h:2378
int(* writereg)(struct target *target, tid_t tid, REG reg, REGVAL value)
Definition: target_api.h:3024
int(* postopened)(struct target *target)
Definition: target_api.h:2817
int value_update(struct value *value, const char *buf, int bufsiz)
Definition: value.c:374
struct list_head probe
Definition: probe.h:379
struct bsymbol * bsymbol_create_noninline(struct bsymbol *bsymbol)
Definition: symbol.c:80
ADDR target_autoload_pointers(struct target *target, struct symbol *datatype, ADDR addr, load_flags_t flags, struct symbol **datatype_saveptr, struct memrange **range_saveptr)
Definition: target.c:3626
struct target_thread * thread
Definition: target_api.h:3237
signed char rv_c(void *buf)
Definition: value.c:1205
uint8_t spec_was_overlay
Definition: target_api.h:2176
int base_target_id
Definition: target_api.h:2169
int target_install_default_sighandlers(void(*sighandler)(int signo, siginfo_t *siginfo, void *x))
Definition: target.c:233
unsigned char * target_read_addr(struct target *target, ADDR addr, unsigned long length, unsigned char *buf)
Definition: target_api.c:1014
int bufsiz
Definition: target_api.h:3257
Definition: list.h:51
int target_singlestep(struct target *target, tid_t tid, int isbp)
Definition: target_api.c:1838
uint64_t(* get_tsc)(struct target *target)
Definition: target_api.h:3218
GHashTable * phys_mmods
Definition: target_api.h:2716
int target_install_custom_sighandlers(sigset_t *ignored, sigset_t *interrupt, sigset_t *exit, void(*sighandler)(int signo, siginfo_t *siginfo, void *x))
Definition: target.c:263
int target_find_memory_real(struct target *target, ADDR addr, struct addrspace **space_saveptr, struct memregion **region_saveptr, struct memrange **range_saveptr)
Definition: target.c:3536
int target_is_open(struct target *target)
Definition: target_api.c:1003
int target_regno(struct target *target, char *name, REG *reg)
Definition: target_api.c:1071
int(* obj_flags_propagate)(struct target *target, obj_flags_t orf, obj_flags_t nandf)
Definition: target_api.h:2864
int(* notify_sw_breakpoint)(struct target *target, ADDR addr, int notification)
Definition: target_api.h:3198
GHashTable * gkv_store
Definition: target_api.h:2593
void target_location_ctxt_retarget_bsymbol(struct target_location_ctxt *tlctxt, struct bsymbol *bsymbol)
Definition: target.c:5287
wchar_t v_wc(struct value *v)
Definition: value.c:329
int(* writereg_tidctxt)(struct target *target, tid_t tid, thread_ctxt_t tidctxt, REG reg, REGVAL value)
Definition: target_api.h:3029
symbol_type_t type
Definition: dwdebug_priv.h:833
Definition: evloop.h:66
uint32_t mmapable
Definition: target_api.h:2427
void target_fini(void)
Definition: target.c:84
GHashTable * mmods
Definition: target_api.h:2701
char * base_thread_name
Definition: target_api.h:2171
int(* pause)(struct target *target, int nowait)
Definition: target_api.h:2896
GList * target_instantiate_and_open_list(GList *target_specs, struct evloop *evloop, GList **error_specs)
Definition: target_api.c:271
int(* remove_sw_breakpoint)(struct target *target, tid_t tid, struct target_memmod *mmod)
Definition: target_api.h:3176
int(* snprintf)(struct target *target, char *buf, int bufsiz)
Definition: target_api.h:3098
thread_status_t status
Definition: target_api.h:2047
unsigned char * target_read_physaddr(struct target *target, ADDR paddr, unsigned long length, unsigned char *buf)
Definition: target_api.c:1039
uint32_t threadctl
Definition: target_api.h:2427
struct evloop * evloop
Definition: target_api.h:2598
int target_snprintf(struct target *target, char *buf, int bufsiz)
Definition: target_api.c:790
REGVAL target_read_reg(struct target *target, tid_t tid, REG reg)
Definition: target_api.c:1083
struct target_location_ctxt_frame * target_location_ctxt_get_frame(struct target_location_ctxt *tlctxt, int frame)
Definition: target.c:5645
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:2967
uint8_t isconst
Definition: target_api.h:3260
result_t(* target_debug_bp_handler_t)(struct target *target, struct target_thread *tthread, struct probepoint *probepoint, int was_stepping)
Definition: target_api.h:2270
uint64_t(* get_tsc)(struct target *target)
Definition: target_api.h:3089
int8_t rv_i8(void *buf)
Definition: value.c:1212
REG target_get_unused_debug_reg(struct target *target, tid_t tid)
Definition: target_api.c:1757
int value_refresh_diff(struct value *value, int recurse, value_diff_t *vdiff, char **old_buf, int *old_bufsiz, value_hash_t *old_vhash)
Definition: value.c:320
unsigned char v_uc(struct value *v)
Definition: value.c:328
int target_write_reg_ctxt(struct target *target, tid_t tid, thread_ctxt_t tidctxt, REG reg, REGVAL value)
Definition: target_api.c:1111
int value_update_c(struct value *value, signed char v)
Definition: value.c:407
struct target_thread * target_load_thread(struct target *target, tid_t tid, int force)
Definition: target_api.c:1246
int(* instr_can_switch_context)(struct target *target, ADDR addr)
Definition: target_api.h:3081
int target_singlestep_end(struct target *target, tid_t tid)
Definition: target_api.c:1844
struct regcache ** regcaches
Definition: target_api.h:2075
int target_attach_evloop(struct target *target, struct evloop *evloop)
Definition: target_api.c:795
int(* write_symbol)(struct target *target, struct value *value)
Definition: target_api.h:2923
target_location_ctxt_flag_t
Definition: target_api.h:2318
void * personality_state
Definition: target_api.h:2495
int(* loaddebugfiles)(struct target *target, struct addrspace *space, struct memregion *region)
Definition: target_api.h:3107
#define TARGET_TYPE_BITS
Definition: target_api.h:171
void target_monitor_clear_global_interrupt(void)
Definition: target.c:228
int target_flush_current_thread(struct target *target)
Definition: target_api.c:1264
int outfd
Definition: target_api.h:2574
void target_default_cleanup()
Definition: target.c:121
thread_status_t target_thread_status(struct target *target, tid_t tid)
Definition: target_api.c:1899
uint64_t target_get_time(struct target *target)
Definition: target_api.c:1871
struct array_list * target_list_available_overlay_tids(struct target *target, target_type_t type)
Definition: target_api.c:633
uintptr_t value_hash_t
Definition: target_api.h:1633
long double rv_dd(void *buf)
Definition: value.c:1218
struct target_thread * target_load_current_thread(struct target *target, int force)
Definition: target_api.c:1240
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:3147
uint8_t isstring
Definition: target_api.h:3260
int value_update_u8(struct value *value, uint8_t v)
Definition: value.c:431
struct probepoint * interrupted_ss_probepoint
Definition: target_api.h:2145
REFCNT bsymbol_release(struct bsymbol *bsymbol)
Definition: symbol.c:90
REG(* get_unused_debug_reg)(struct target *target, tid_t tid)
Definition: target_api.h:3187
ADDR res_ip
Definition: target_api.h:3276
struct target_thread * current_thread
Definition: target_api.h:2640
int(* change_sw_breakpoint)(struct target *target, tid_t tid, struct target_memmod *mmod, unsigned char *code, unsigned long code_len)
Definition: target_api.h:3182
void(* handle_event)(struct target *target, struct target_event *event)
Definition: target_api.h:3117
int target_argp_driver_parse(struct argp *driver_parser, void *driver_state, int argc, char **argv, target_type_t target_types, int filter_quoted, struct target_spec **primary_target_spec, GList **base_target_specs, GList **overlay_target_specs)
Definition: target.c:900
int target_monitor_was_interrupted(siginfo_t *last_siginfo)
Definition: target.c:219
struct probe * target_lookup_probe(struct target *target, int probe_id)
Definition: target_api.c:1601
int target_enable_hw_breakpoint(struct target *target, tid_t tid, REG dreg)
Definition: target_api.c:1819
int(* enable_hw_breakpoints)(struct target *target, tid_t tid)
Definition: target_api.h:3195
region_type_t
double rv_d(void *buf)
Definition: value.c:1217
struct array_list * target_list_tids(struct target *target)
Definition: target_api.c:1145
ADDR rv_addr(void *buf)
Definition: value.c:1219
float rv_f(void *buf)
Definition: value.c:1216
void(* handle_event)(struct target *target, struct target_event *event)
Definition: target_api.h:2862
int(* unwind_read_reg)(struct target_location_ctxt *tlctxt, REG reg, REGVAL *o_regval)
Definition: target_api.h:3163
probepoint_watchsize_t
Definition: probe_api.h:241
int target_location_ctxt_read_reg(struct target_location_ctxt *tlctxt, REG reg, REGVAL *o_regval)
Definition: target.c:5659
uint64_t(* get_time)(struct target *target)
Definition: target_api.h:3090
tid_t base_tid
Definition: target_api.h:2617
int value_update_i64(struct value *value, int64_t v)
Definition: value.c:487
int(* probe_register_symbol)(struct target *target, tid_t tid, struct probe *probe, struct bsymbol *bsymbol, probepoint_style_t style, probepoint_whence_t whence, probepoint_watchsize_t watchsize)
Definition: target_api.h:3169
int(* detach)(struct target *target, int stay_paused)
Definition: target_api.h:2781
struct target_location_ctxt_frame * target_location_ctxt_prev(struct target_location_ctxt *tlctxt)
Definition: target.c:5715
int(* load_available_threads)(struct target *target, int force)
Definition: target_api.h:3140
int(* enable_feature)(struct target *target, int feature, void *arg)
Definition: target_api.h:3222
char * buf
Definition: target_api.h:3258
void target_free_spec(struct target_spec *spec)
Definition: target_api.c:436
int value_refresh(struct value *value, int recursive)
Definition: value.c:271
int(* disable_hw_breakpoints)(struct target *target, tid_t tid)
Definition: target_api.h:3194
int(* loaddebugfiles)(struct target *target, struct addrspace *space, struct memregion *region)
Definition: target_api.h:2798
int target_set_active_probing(struct target *target, active_probe_flags_t flags)
Definition: target_api.c:616
void(* free_thread_state)(struct target *target, void *state)
Definition: target_api.h:3134
struct target_location_ctxt * global_tlctxt
Definition: target_api.h:2667
clrange_t code_ranges
Definition: target_api.h:2754
int target_spec_to_argv(struct target_spec *spec, char *arg0, int *argc, char ***argv)
Definition: target.c:407
unsigned long(* write_phys)(struct target *target, ADDR paddr, unsigned long length, unsigned char *buf)
Definition: target_api.h:3131
unsigned char * buf
Definition: probe.h:418
int value_update_dd(struct value *value, long double v)
Definition: value.c:511
thread_bpmode_t
Definition: target_api.h:366
int(* flush_thread)(struct target *target, tid_t tid)
Definition: target_api.h:2962
uint32_t live
Definition: target_api.h:2427
unsigned long target_write_physaddr(struct target *target, ADDR paddr, unsigned long length, unsigned char *buf)
Definition: target_api.c:1052
struct target_spec * target_build_default_overlay_spec(struct target *target, tid_t tid)
Definition: target_api.c:711
target_mode_t
Definition: target_api.h:187
char * target_name(struct target *target)
Definition: target_api.c:488
int value_update_wc(struct value *value, wchar_t v)
Definition: value.c:423
struct value * parent_value
Definition: target_api.h:3278
const char * target_regname(struct target *target, REG reg)
Definition: target_api.c:1065
int(* set_hw_watchpoint)(struct target *target, tid_t tid, REG reg, ADDR addr, probepoint_whence_t whence, probepoint_watchsize_t watchsize)
Definition: target_api.h:3060
REG(* get_unused_debug_reg)(struct target *target, tid_t tid)
Definition: target_api.h:3058
struct memrange * range
Definition: target_api.h:3255
result_t(* target_debug_handler_t)(struct target *target, struct target_thread *tthread, struct probepoint *probepoint)
Definition: target_api.h:2274
int(* disable_hw_breakpoint)(struct target *target, tid_t tid, REG dreg)
Definition: target_api.h:3196
int(* postopened)(struct target *target)
Definition: target_api.h:3115
int value_update_uc(struct value *value, unsigned char v)
Definition: value.c:415
GHashTable * threads
Definition: target_api.h:2632
int value_update_i8(struct value *value, int8_t v)
Definition: value.c:463
int(* writereg)(struct target *target, tid_t tid, REG reg, REGVAL value)
Definition: target_api.h:3153
obj_flags_t obj_flags
Definition: target_api.h:2050
struct memcache * memcache
Definition: target_api.h:2751
int(* resume)(struct target *target)
Definition: target_api.h:2898
void value_free(struct value *value)
Definition: value.c:224
unsigned char rv_uc(void *buf)
Definition: value.c:1206
struct target_location_ctxt * target_global_tlctxt(struct target *target)
Definition: target.c:5243
struct target_spec * spec
Definition: target_api.h:2258
struct value * target_load_value_member(struct target *target, struct target_location_ctxt *tlctxt, struct value *old_value, const char *member, const char *delim, load_flags_t flags)
Definition: target.c:2907
int(* load_all_threads)(struct target *target, int force)
Definition: target_api.h:2958
uint64_t(* get_counter)(struct target *target)
Definition: target_api.h:3220
struct bsymbol * target_lookup_sym_addr(struct target *target, ADDR addr)
Definition: target.c:2063
int target_location_ctxt_unwind(struct target_location_ctxt *tlctxt)
Definition: target.c:5361
char * REGION_TYPE_STRINGS[]
Definition: target.c:6652
int len
Definition: dumptarget.c:52
struct value * value_clone(struct value *in)
Definition: value.c:195
struct value * target_load_type_regval(struct target *target, struct symbol *type, tid_t tid, REG reg, REGVAL regval, load_flags_t flags)
Definition: target.c:2727
ADDR addr
Definition: target.h:381
struct target_memmod * emulating_debug_mmod
Definition: target_api.h:2142
int target_enable_feature(struct target *target, int feature, void *arg)
Definition: target_api.c:1885
int(* disable_hw_breakpoint)(struct target *target, tid_t tid, REG dreg)
Definition: target_api.h:3067
target_poll_outcome_t
Definition: target_api.h:394
Definition: probe.h:308
target_type_t target_type
Definition: target_api.h:2166
GList * spaces
Definition: target_api.h:2603
int value_update_u16(struct value *value, uint16_t v)
Definition: value.c:439
REGVAL(* readreg_tidctxt)(struct target *target, tid_t tid, thread_ctxt_t tidctxt, REG reg)
Definition: target_api.h:3027
target_unwind_style_t
Definition: target_api.h:2394
int target_store_value(struct target *target, struct value *value)
Definition: target.c:3512
REGVAL target_read_creg(struct target *target, tid_t tid, common_reg_t reg)
Definition: target_api.c:1119
ADDR target_load_pointers(struct target *target, ADDR addr, int count, struct memrange **range_saveptr)
Definition: target.c:3575
struct binfile * binfile
Definition: target_api.h:2609
unsigned long(* write)(struct target *target, ADDR addr, unsigned long length, unsigned char *buf)
Definition: target_api.h:3126
int(* remove_sw_breakpoint)(struct target *target, tid_t tid, struct target_memmod *mmod)
Definition: target_api.h:3047
struct array_list * tpc_stack
Definition: target_api.h:2132
int(* attach_overlay_thread)(struct target *base, struct target *overlay, tid_t newtid)
Definition: target_api.h:2881
GHashTable * gkv_store
Definition: target_api.h:2162
int target_notify_sw_breakpoint(struct target *target, ADDR addr, int notification)
Definition: target_api.c:1826
int(* gc_threads)(struct target *target)
Definition: target_api.h:2966
int base_thread_id
Definition: target_api.h:2170
int(* unchange_sw_breakpoint)(struct target *target, tid_t tid, struct target_memmod *mmod)
Definition: target_api.h:3185
int(* set_active_probing)(struct target *target, active_probe_flags_t flags)
Definition: target_api.h:2813
obj_flags_t
Definition: object.h:43
ADDR v_addr(struct value *v)
Definition: value.c:371
GHashTable * target_hash_available_tids(struct target *target)
Definition: target_api.c:1212
int target_load_all_threads(struct target *target, int force)
Definition: target_api.c:1253
struct thread_probepoint_context * tpc
Definition: target_api.h:2131
int(* attach_evloop)(struct target *target, struct evloop *evloop)
Definition: target_api.h:2909
struct array_list * target_list_available_tids(struct target *target)
Definition: target_api.c:1207
int(* enable_sw_breakpoint)(struct target *target, tid_t tid, struct target_memmod *mmod)
Definition: target_api.h:3049
int target_detach_evloop(struct target *target)
Definition: target_api.c:807
int(* loadregions)(struct target *target, struct addrspace *space)
Definition: target_api.h:2793
int(* singlestep_end)(struct target *target, tid_t tid, struct target *overlay)
Definition: target_api.h:3202
int(* postloadinit)(struct target *target)
Definition: target_api.h:2804
int(* notify_sw_breakpoint)(struct target *target, ADDR addr, int notification)
Definition: target_api.h:3069
struct arch * arch
Definition: target_api.h:2563
struct target_location_ctxt_frame * target_location_ctxt_current_frame(struct target_location_ctxt *tlctxt)
Definition: target.c:5651
num_t v_num(struct value *v)
Definition: value.c:338
void(* free_thread_state)(struct target *target, void *state)
Definition: target_api.h:2952
int(* unset_hw_watchpoint)(struct target *target, tid_t tid, REG reg)
Definition: target_api.h:3064
REFCNT refcnt
Definition: target_api.h:2423
struct array_list * debugfile_load_opts_list
Definition: target_api.h:2199
int value_update_unum(struct value *value, unum_t v)
Definition: value.c:543
unsigned int thread_ctxt_t
Definition: target_api.h:300
int target_disable_hw_breakpoints(struct target *target, tid_t tid)
Definition: target_api.c:1800
int(* addr_v2p)(struct target *target, tid_t tid, ADDR vaddr, ADDR *paddr)
Definition: target_api.h:3128
REGVAL(* readreg_tidctxt)(struct target *target, tid_t tid, thread_ctxt_t tidctxt, REG reg)
Definition: target_api.h:3156
int(* disable_feature)(struct target *target, int feature)
Definition: target_api.h:3223
struct target * target
Definition: target_api.h:2041
GHashTable * overlay_aliases
Definition: target_api.h:2630
REFCNT refcntw
Definition: target_api.h:2052
result_t
Definition: common.h:25
double v_d(struct value *v)
Definition: value.c:369
target_exception_handler_t handle_exception
Definition: target_api.h:2828
uint32_t REGVAL
Definition: common.h:66
int probe_id_counter
Definition: target_api.h:2741
int16_t rv_i16(void *buf)
Definition: value.c:1213
struct list_head ss_actions
Definition: target_api.h:2156
uint32_t rv_u32(void *buf)
Definition: value.c:1210
struct target * target_lookup_target_id(int id)
Definition: target.c:325
void * personality_state
Definition: target_api.h:2069
int(* probe_register_symbol)(struct target *target, tid_t tid, struct probe *probe, struct bsymbol *bsymbol, probepoint_style_t style, probepoint_whence_t whence, probepoint_watchsize_t watchsize)
Definition: target_api.h:3040
uint32_t needmonitorinterrupt
Definition: target_api.h:2427
int64_t rv_i64(void *buf)
Definition: value.c:1215
target_status_t target_status(struct target *target)
Definition: target_api.c:1007
int target_disable_sw_breakpoint(struct target *target, tid_t tid, struct target_memmod *mmod)
Definition: target_api.c:1721
target_location_ctxt_flag_t flags
Definition: target_api.h:2367
int(* invalidate_thread)(struct target *target, struct target_thread *tthread)
Definition: target_api.h:2965
struct value * target_load_addr_obj(struct target *target, struct memregion *region, ADDR obj_addr, load_flags_t flags, int len)
Definition: target.c:3700
int(* singlestep)(struct target *target, tid_t tid, int isbp, struct target *overlay)
Definition: target_api.h:3200
void target_hold(struct target *target)
Definition: target_api.c:1592
sigset_t ignored
Definition: spf.c:211
struct target_spec * target_build_spec(target_type_t type, target_mode_t mode)
Definition: target_api.c:394
int target_write_creg(struct target *target, tid_t tid, common_reg_t reg, REGVAL value)
Definition: target_api.c:1128
char * v_string(struct value *v)
Definition: value.c:372
int8_t exiting
Definition: target_api.h:2044
int target_kill(struct target *target, int sig)
Definition: target_api.c:1587
uint16_t v_u16(struct value *v)
Definition: value.c:331
int8_t REG
Definition: common.h:93
target_type_t
Definition: target_api.h:163
int target_disable_hw_breakpoint(struct target *target, tid_t tid, REG dreg)
Definition: target_api.c:1812
uint64_t(* get_counter)(struct target *target)
Definition: target_api.h:3091
struct lsymbol * bsymbol_get_lsymbol(struct bsymbol *bsymbol)
Definition: symbol.c:70
probepoint_style_t
Definition: probe_api.h:228
uint32_t opened
Definition: target_api.h:2427
struct target_location_ctxt * target_location_ctxt_create(struct target *target, tid_t tid, struct memregion *region)
Definition: target.c:5248
int target_finalize(struct target *target)
Definition: target.c:1925
struct lsymbol * lsymbol
Definition: target_api.h:3252
unsigned long(* write_phys)(struct target *target, ADDR paddr, unsigned long length, unsigned char *buf)
Definition: target_api.h:2941
GHashTable * hard_probepoints
Definition: target_api.h:2080
struct symbol * bsymbol_get_symbol(struct bsymbol *bsymbol)
Definition: symbol.c:66
int(* enable_feature)(struct target *target, int feature, void *arg)
Definition: target_api.h:3093
int8_t attached
Definition: target_api.h:2044
target_personality_t
Definition: target_api.h:180
int(* loadspaces)(struct target *target)
Definition: target_api.h:3104
uint32_t ADDR
Definition: common.h:64
Definition: arch.h:116
char * name
Definition: target_api.h:2483
void * __personality_specific_ops
Definition: target_api.h:2554
struct target_ops * ops
Definition: target_api.h:2510
struct symbol * type
Definition: target_api.h:3247
char * infile
Definition: target_api.h:2248
REGVAL target_read_reg_ctxt(struct target *target, tid_t tid, thread_ctxt_t tidctxt, REG reg)
Definition: target_api.c:1103
target_exception_flags_t
Definition: target_api.h:386
uint64_t v_u64(struct value *v)
Definition: value.c:333
int(* gc_threads)(struct target *target)
Definition: target_api.h:3146
struct target_memmod * target_insert_sw_breakpoint(struct target *target, tid_t tid, ADDR addr)
Definition: target_api.c:1664
uint64_t rv_u64(void *buf)
Definition: value.c:1211
struct value * target_load_addr_real(struct target *target, ADDR addr, load_flags_t flags, int len)
Definition: target.c:3716
target_status_t target_poll(struct target *target, struct timeval *tv, target_poll_outcome_t *outcome, int *pstatus)
Definition: target_api.c:962
target_status_t target_notify_overlay(struct target *overlay, target_exception_flags_t flags, tid_t tid, ADDR ipval, int *again)
Definition: target.c:4449
REG spregno
Definition: target_api.h:2469
int value_update_u64(struct value *value, uint64_t v)
Definition: value.c:455
int(* detach_overlay_thread)(struct target *base, struct target *overlay, tid_t tid)
Definition: target_api.h:2883
thread_ctxt_t tidctxt
Definition: target_api.h:2043
int(* invalidate_thread)(struct target *target, struct target_thread *tthread)
Definition: target_api.h:3145
GList * target_instantiate_and_open(struct target_spec *primary_target_spec, GList *base_target_specs, GList *overlay_target_specs, struct evloop *evloop, GList **error_specs)
Definition: target_api.c:92
int(* set_hw_watchpoint)(struct target *target, tid_t tid, REG reg, ADDR addr, probepoint_whence_t whence, probepoint_watchsize_t watchsize)
Definition: target_api.h:3189
int32_t rv_i32(void *buf)
Definition: value.c:1214
int target_open(struct target *target)
Definition: target_api.c:496
thread_status_t
Definition: target_api.h:254
void target_release(struct target *target)
Definition: target_api.c:1596
target_status_t status
Definition: target_api.h:2465
REGVAL(* readreg)(struct target *target, tid_t tid, REG reg)
Definition: target_api.h:3152
int target_unset_hw_breakpoint(struct target *target, tid_t tid, REG reg)
Definition: target_api.c:1786
void target_dump_all_threads(struct target *target, FILE *stream, int detail)
Definition: target_api.c:1435
int target_lookup_line_addr(struct target *target, char *srcfile, ADDR addr)
Definition: target.c:2289
int32_t v_i32(struct value *v)
Definition: value.c:336
target_status_t target_monitor(struct target *target)
Definition: target_api.c:830
struct target_spec * target_argp_target_spec(struct argp_state *state)
Definition: target.c:696
uint32_t global_tlctxt_is_dynamic
Definition: target_api.h:2427
char * personality
Definition: target_api.h:2190
struct value * target_load_symbol_member(struct target *target, struct target_location_ctxt *tlctxt, struct bsymbol *bsymbol, const char *member, const char *delim, load_flags_t flags)
Definition: target.c:2885
REG fbregno
Definition: target_api.h:2468
uint32_t REFCNT
Definition: common.h:124
int target_contains_real(struct target *target, ADDR addr)
Definition: target.c:3560
int target_id(struct target *target)
Definition: target_api.c:492
void target_location_ctxt_free(struct target_location_ctxt *tlctxt)
Definition: target.c:5292
int(* snprintf)(struct target *target, char *buf, int bufsiz)
Definition: target_api.h:2758
int kill_on_close_sig
Definition: target_api.h:2204
int(* detach_evloop)(struct target *target)
Definition: target_api.h:2910
struct symbol * target_create_synthetic_type_pointer(struct target *target, struct symbol *type)
Definition: symbol.c:27
struct target_spec * spec
Definition: target_api.h:2565
int target_monitor_schedule_interrupt(struct target *target)
Definition: target.c:318
uint8_t v_u8(struct value *v)
Definition: value.c:330
signed char v_c(struct value *v)
Definition: value.c:327
int(* writereg_tidctxt)(struct target *target, tid_t tid, thread_ctxt_t tidctxt, REG reg, REGVAL value)
Definition: target_api.h:3158
load_flags_t
Definition: target_api.h:406
int(* enable_sw_breakpoint)(struct target *target, tid_t tid, struct target_memmod *mmod)
Definition: target_api.h:3178
uint32_t nodisablehwbponss
Definition: target_api.h:2427
void bsymbol_hold(struct bsymbol *bsymbol)
struct bsymbol * bsymbol
Definition: target_api.h:2377
struct target_spec * target_argp_driver_parse_one(struct argp *driver_parser, void *driver_state, int argc, char **argv, target_type_t target_types, int filter_quoted)
Definition: target.c:789
int value_update_u32(struct value *value, uint32_t v)
Definition: value.c:447
value_diff_t
Definition: target_api.h:1626
struct target * target_instantiate(struct target_spec *spec, struct evloop *evloop)
Definition: target_api.c:55
REGVAL(* readreg)(struct target *target, tid_t tid, REG reg)
Definition: target_api.h:3023
int(* instr_can_switch_context)(struct target *target, ADDR addr)
Definition: target_api.h:3210
int(* disable_sw_breakpoint)(struct target *target, tid_t tid, struct target_memmod *mmod)
Definition: target_api.h:3180
active_probe_flags_t
Definition: target_api.h:432
int target_set_hw_breakpoint(struct target *target, tid_t tid, REG reg, ADDR addr)
Definition: target_api.c:1771
struct location_ops * location_ops
Definition: target_api.h:2511
int id
Definition: target_api.h:2476
int value_update_zero(struct value *value, const char *buf, int bufsiz)
Definition: value.c:389
char * debugfile_root_prefix
Definition: target_api.h:2197
uint8_t ismmap
Definition: target_api.h:3260
unsigned int max_thread_ctxt
Definition: target_api.h:2467
int target_gc_threads(struct target *target)
Definition: target_api.c:1303
GHashTable * probes
Definition: target_api.h:2725
int target_enable_hw_breakpoints(struct target *target, tid_t tid)
Definition: target_api.c:1806
struct target_thread * thread
Definition: target_api.h:2345
symbol_type_flag_t
Definition: dwdebug.h:190
uint64_t unum_t
Definition: common.h:88
int(* disable_feature)(struct target *target, int feature)
Definition: target_api.h:3094
unsigned long(* write)(struct target *target, ADDR addr, unsigned long length, unsigned char *buf)
Definition: target_api.h:2916
target_type_t target_type(struct target *target)
Definition: target_api.c:484
unsigned long target_write_addr(struct target *target, ADDR addr, unsigned long length, unsigned char *buf)
Definition: target_api.c:1021
uint32_t v_u32(struct value *v)
Definition: value.c:332
char * errfile
Definition: target_api.h:2250
struct target_thread * blocking_thread
Definition: target_api.h:2653
int target_lookup_safe_disasm_range(struct target *target, ADDR addr, ADDR *start, ADDR *end, void **data)
Definition: target.c:3783
target_status_t(* handle_overlay_exception)(struct target *overlay, target_exception_flags_t flags, tid_t tid, ADDR ipval, int *again)
Definition: target_api.h:2889
target_debug_handler_t handle_step
Definition: target_api.h:2830
int(* singlestep_end)(struct target *target, tid_t tid, struct target *overlay)
Definition: target_api.h:3073
REG reg
Definition: target_api.h:3270
struct bsymbol * target_lookup_sym_member(struct target *target, struct bsymbol *bsymbol, const char *name, const char *delim)
Definition: target.c:2218
uint64_t target_get_counter(struct target *target)
Definition: target_api.c:1878
int(* flush_current_thread)(struct target *target)
Definition: target_api.h:3144
float v_f(struct value *v)
Definition: value.c:368
char * outfile
Definition: target_api.h:2249
int target_monitor_handling_exception(struct target *target)
Definition: target.c:310
int8_t resumeat
Definition: target_api.h:2044
int(* loadregions)(struct target *target, struct addrspace *space)
Definition: target_api.h:3105
int target_addr_v2p(struct target *target, tid_t tid, ADDR vaddr, ADDR *paddr)
Definition: target_api.c:1028
int target_lookup_next_safe_disasm_range(struct target *target, ADDR addr, ADDR *start, ADDR *end, void **data)
Definition: target.c:3818
int(* change_sw_breakpoint)(struct target *target, tid_t tid, struct target_memmod *mmod, unsigned char *code, unsigned long code_len)
Definition: target_api.h:3053
int(* init)(struct target *target)
Definition: target_api.h:2770
int base_id
Definition: target_api.h:2616
int target_enable_sw_breakpoint(struct target *target, tid_t tid, struct target_memmod *mmod)
Definition: target_api.c:1708
int target_unset_hw_watchpoint(struct target *target, tid_t tid, REG reg)
Definition: target_api.c:1793
int(* pause_thread)(struct target *target, tid_t tid, int nowait)
Definition: target_api.h:2960
int(* postloadinit)(struct target *target)
Definition: target_api.h:3111
unum_t v_unum(struct value *v)
Definition: value.c:353
uint8_t start_paused
Definition: target_api.h:2176
ADDR value_addr(struct value *value)
Definition: value.c:244
struct array_list * target_list_threads(struct target *target)
Definition: target_api.c:1168
int errfd
Definition: target_api.h:2575
int(* enable_hw_breakpoint)(struct target *target, tid_t tid, REG dreg)
Definition: target_api.h:3068
REG ipregno
Definition: target_api.h:2470
int target_write_reg(struct target *target, tid_t tid, REG reg, REGVAL value)
Definition: target_api.c:1092
int(* kill)(struct target *target, int sig)
Definition: target_api.h:2783
struct location_ctxt * lctxt
Definition: target_api.h:2339
target_status_t(* poll)(struct target *target, struct timeval *tv, target_poll_outcome_t *outcome, int *pstatus)
Definition: target_api.h:2901
target_debug_handler_t handle_interrupted_step
Definition: target_api.h:2853
void target_driver_argp_init_children(struct argp_state *state)
Definition: target.c:1044
int(* evloop_handler_t)(int fd, int fdtype, void *state)
Definition: evloop.h:62
int(* loadspaces)(struct target *target)
Definition: target_api.h:2788
void bsymbol_dump(struct bsymbol *bsymbol, struct dump_info *ud)
Definition: symbol.c:120
active_probe_flags_t ap_flags
Definition: target_api.h:2182
uint32_t kill_on_close
Definition: target_api.h:2427
int(* enable_hw_breakpoints)(struct target *target, tid_t tid)
Definition: target_api.h:3066
struct array_list * target_list_overlays(struct target *target)
Definition: target_api.c:663
uint32_t writeable
Definition: target_api.h:2427
target_type_t supported_overlay_types
Definition: target_api.h:2048
char * personality_lib
Definition: target_api.h:2195
unsigned char * target_load_code(struct target *target, ADDR start, unsigned int len, int nocache, int force_copy, int *caller_free)
Definition: target.c:3867
int value_update_d(struct value *value, double v)
Definition: value.c:503