Stackdb
Stackdb is a stackable, multi-target and -level source debugger and memory forensics library.
|
#include "config.h"
#include "common.h"
#include "object.h"
#include "arch.h"
#include "list.h"
#include "evloop.h"
#include "dwdebug.h"
#include "target_event.h"
#include "probe_api.h"
#include <glib.h>
Go to the source code of this file.
Data Structures | |
struct | target_decoder_lib |
struct | target_decoder_binding |
struct | target_thread |
struct | target_spec |
struct | target_argp_parser_state |
struct | target_location_ctxt |
struct | target_location_ctxt_frame |
struct | target |
struct | target_ops |
struct | target_personality_ops |
struct | value |
Macros | |
#define | TID_GLOBAL INT32_MAX |
#define | TARGET_TYPE_BITS 5 |
#define | TARGET_TYPE_MASK_BASE (TARGET_TYPE_PTRACE | TARGET_TYPE_XEN | TARGET_TYPE_GDB) |
#define | TARGET_TYPE_MASK_OVERLAY (TARGET_TYPE_PHP | TARGET_TYPE_OS_PROCESS) |
#define | TSTATUS_MAX TSTATUS_STOPPED |
#define | TSTATUS(n) (((n) <= TSTATUS_MAX) ? TSTATUS_STRINGS[(n)] : NULL) |
#define | THREAD_STATUS_MAX THREAD_STATUS_RETURNING_KERNEL |
#define | THREAD_STATUS_BITS 5 |
#define | THREAD_SPECIFIC_STATUS(status) ((thread_status_t)(status) >= THREAD_STATUS_SLEEPING) |
#define | THREAD_STATUS(n) |
#define | THREAD_CTXT_DEFAULT 0 |
#define | REGION_TYPE(n) (((n) < __REGION_TYPE_MAX) ? REGION_TYPE_STRINGS[(n)] : NULL) |
#define | POLL(n) |
#define | APF_WILD (APF_THREAD_ENTRY | APF_THREAD_EXIT | APF_MEMORY | APF_OTHER) |
#define | APF_OS |
#define | APF_PROCESS |
#define | APF_APP |
#define | APF_ALL (APF_WILD | APF_OS | APF_PROCESS | APF_APP) |
#define | VLS(target, tlctxt, varstr, loadflags, outvarptr, outvalueptr, errlabel) |
#define | VL(target, tlctxt, invalue, varstr, loadflags, outvalueptr, errlabel) |
#define | VLV(target, tlctxt, invalue, varstr, loadflags, outvarptr, outvalueptr, errlabel) |
#define | VLVAR(target, tlctxt, invalue, varstr, loadflags, outvarptr, errlabel) |
#define | VLVAL(target, tlctxt, invalue, varstr, loadflags, outvalueptr, errlabel) |
#define | VLA(target, addr, loadflags, outbufptr, outbuflen, outvalueptr, errlabel) |
#define | value_to_u64(v) (*((uint64_t *)(v)->buf)) |
#define | value_to_u32(v) (*((uint32_t *)(v)->buf)) |
#define | value_to_u16(v) (*((uint16_t *)(v)->buf)) |
#define | value_to_u8(v) (*((uint8_t *)(v)->buf)) |
#define | value_to_i64(v) (*((int64_t *)(v)->buf)) |
#define | value_to_i32(v) (*((int32_t *)(v)->buf)) |
#define | value_to_i16(v) (*((int16_t *)(v)->buf)) |
#define | value_to_i8(v) (*((int8_t *)(v)->buf)) |
#define | value_to_unsigned_long value_to_u32 |
#define | value_to_long value_to_i32 |
#define | value_to_int value_to_i32 |
#define | value_to_unsigned_int value_to_u32 |
#define | value_to_char(v) ((char)value_to_i8((v))) |
#define | value_to_unsigned_char(v) ((unsigned char)value_to_i8((v))) |
#define | value_to_string(v) ((v)->buf) |
#define | value_to_num(v) value_to_i32((v)) |
Typedefs | |
typedef unsigned int | thread_ctxt_t |
typedef uintptr_t | value_hash_t |
typedef int(* | target_decoder_t )(struct target *target, void *data, struct value *value, char *buf, int buflen) |
typedef target_status_t(* | target_exception_handler_t )(struct target *target, target_exception_flags_t flags, int *again, void *priv) |
typedef result_t(* | target_debug_bp_handler_t )(struct target *target, struct target_thread *tthread, struct probepoint *probepoint, int was_stepping) |
typedef result_t(* | target_debug_handler_t )(struct target *target, struct target_thread *tthread, struct probepoint *probepoint) |
Variables | |
char * | TSTATUS_STRINGS [] |
char * | THREAD_STATUS_STRINGS [] |
char * | REGION_TYPE_STRINGS [] |
char * | POLL_STRINGS [] |
#define APF_ALL (APF_WILD | APF_OS | APF_PROCESS | APF_APP) |
Definition at line 463 of file target_api.h.
#define APF_APP |
Definition at line 461 of file target_api.h.
#define APF_OS |
Definition at line 457 of file target_api.h.
#define APF_PROCESS |
Definition at line 459 of file target_api.h.
#define APF_WILD (APF_THREAD_ENTRY | APF_THREAD_EXIT | APF_MEMORY | APF_OTHER) |
Definition at line 456 of file target_api.h.
#define POLL | ( | n | ) |
Definition at line 403 of file target_api.h.
#define REGION_TYPE | ( | n | ) | (((n) < __REGION_TYPE_MAX) ? REGION_TYPE_STRINGS[(n)] : NULL) |
Definition at line 384 of file target_api.h.
#define TARGET_TYPE_BITS 5 |
Definition at line 171 of file target_api.h.
#define TARGET_TYPE_MASK_BASE (TARGET_TYPE_PTRACE | TARGET_TYPE_XEN | TARGET_TYPE_GDB) |
Definition at line 172 of file target_api.h.
#define TARGET_TYPE_MASK_OVERLAY (TARGET_TYPE_PHP | TARGET_TYPE_OS_PROCESS) |
Definition at line 174 of file target_api.h.
#define THREAD_CTXT_DEFAULT 0 |
Definition at line 301 of file target_api.h.
#define THREAD_SPECIFIC_STATUS | ( | status | ) | ((thread_status_t)(status) >= THREAD_STATUS_SLEEPING) |
Definition at line 284 of file target_api.h.
#define THREAD_STATUS | ( | n | ) |
Definition at line 288 of file target_api.h.
#define THREAD_STATUS_BITS 5 |
Definition at line 282 of file target_api.h.
#define THREAD_STATUS_MAX THREAD_STATUS_RETURNING_KERNEL |
Definition at line 280 of file target_api.h.
#define TID_GLOBAL INT32_MAX |
Definition at line 145 of file target_api.h.
#define TSTATUS | ( | n | ) | (((n) <= TSTATUS_MAX) ? TSTATUS_STRINGS[(n)] : NULL) |
Definition at line 252 of file target_api.h.
#define TSTATUS_MAX TSTATUS_STOPPED |
Definition at line 249 of file target_api.h.
#define value_to_char | ( | v | ) | ((char)value_to_i8((v))) |
Definition at line 1931 of file target_api.h.
#define value_to_i16 | ( | v | ) | (*((int16_t *)(v)->buf)) |
Definition at line 1917 of file target_api.h.
#define value_to_i32 | ( | v | ) | (*((int32_t *)(v)->buf)) |
Definition at line 1916 of file target_api.h.
#define value_to_i64 | ( | v | ) | (*((int64_t *)(v)->buf)) |
Definition at line 1915 of file target_api.h.
#define value_to_i8 | ( | v | ) | (*((int8_t *)(v)->buf)) |
Definition at line 1918 of file target_api.h.
#define value_to_int value_to_i32 |
Definition at line 1928 of file target_api.h.
#define value_to_long value_to_i32 |
Definition at line 1925 of file target_api.h.
#define value_to_num | ( | v | ) | value_to_i32((v)) |
Definition at line 1937 of file target_api.h.
#define value_to_string | ( | v | ) | ((v)->buf) |
Definition at line 1933 of file target_api.h.
#define value_to_u16 | ( | v | ) | (*((uint16_t *)(v)->buf)) |
Definition at line 1912 of file target_api.h.
#define value_to_u32 | ( | v | ) | (*((uint32_t *)(v)->buf)) |
Definition at line 1911 of file target_api.h.
#define value_to_u64 | ( | v | ) | (*((uint64_t *)(v)->buf)) |
Definition at line 1910 of file target_api.h.
#define value_to_u8 | ( | v | ) | (*((uint8_t *)(v)->buf)) |
Definition at line 1913 of file target_api.h.
#define value_to_unsigned_char | ( | v | ) | ((unsigned char)value_to_i8((v))) |
Definition at line 1932 of file target_api.h.
#define value_to_unsigned_int value_to_u32 |
Definition at line 1929 of file target_api.h.
#define value_to_unsigned_long value_to_u32 |
Definition at line 1924 of file target_api.h.
#define VL | ( | target, | |
tlctxt, | |||
invalue, | |||
varstr, | |||
loadflags, | |||
outvalueptr, | |||
errlabel | |||
) |
Definition at line 1708 of file target_api.h.
#define VLA | ( | target, | |
addr, | |||
loadflags, | |||
outbufptr, | |||
outbuflen, | |||
outvalueptr, | |||
errlabel | |||
) |
Definition at line 1840 of file target_api.h.
#define VLS | ( | target, | |
tlctxt, | |||
varstr, | |||
loadflags, | |||
outvarptr, | |||
outvalueptr, | |||
errlabel | |||
) |
Value macros.
Definition at line 1677 of file target_api.h.
#define VLV | ( | target, | |
tlctxt, | |||
invalue, | |||
varstr, | |||
loadflags, | |||
outvarptr, | |||
outvalueptr, | |||
errlabel | |||
) |
Definition at line 1739 of file target_api.h.
#define VLVAL | ( | target, | |
tlctxt, | |||
invalue, | |||
varstr, | |||
loadflags, | |||
outvalueptr, | |||
errlabel | |||
) |
Definition at line 1814 of file target_api.h.
#define VLVAR | ( | target, | |
tlctxt, | |||
invalue, | |||
varstr, | |||
loadflags, | |||
outvarptr, | |||
errlabel | |||
) |
Definition at line 1782 of file target_api.h.
typedef result_t(* target_debug_bp_handler_t)(struct target *target, struct target_thread *tthread, struct probepoint *probepoint, int was_stepping) |
Definition at line 2308 of file target_api.h.
typedef result_t(* target_debug_handler_t)(struct target *target, struct target_thread *tthread, struct probepoint *probepoint) |
Definition at line 2312 of file target_api.h.
typedef int(* target_decoder_t)(struct target *target, void *data, struct value *value, char *buf, int buflen) |
Definition at line 1977 of file target_api.h.
typedef target_status_t(* target_exception_handler_t)(struct target *target, target_exception_flags_t flags, int *again, void *priv) |
Definition at line 2304 of file target_api.h.
typedef unsigned int thread_ctxt_t |
Definition at line 300 of file target_api.h.
typedef uintptr_t value_hash_t |
Definition at line 1641 of file target_api.h.
enum active_probe_flags_t |
Definition at line 432 of file target_api.h.
enum load_flags_t |
Definition at line 406 of file target_api.h.
enum region_type_t |
Definition at line 372 of file target_api.h.
Enumerator | |
---|---|
EXCEPTION_NONE | |
EXCEPTION_SINGLESTEP | |
EXCEPTION_SINGLESTEP_BOGUS | |
EXCEPTION_SINGLESTEP_CMD | |
EXCEPTION_BREAKPOINT |
Definition at line 386 of file target_api.h.
Enumerator | |
---|---|
TLCTXT_NONE | |
TLCTXT_AUTOLOAD_ARGS | |
TLCTXT_AUTOLOAD_LOCALS | |
TLCTXT_AUTOLOAD_INSCOPE | |
TLCTXT_FOLLOW_OVERLAYS |
Definition at line 2356 of file target_api.h.
enum target_mode_t |
Enumerator | |
---|---|
TARGET_MODE_NONE | |
TARGET_MODE_LIVE | |
TARGET_MODE_RECORD | |
TARGET_MODE_REPLAY |
Definition at line 187 of file target_api.h.
enum target_personality_t |
Enumerator | |
---|---|
TARGET_PERSONALITY_NONE | |
TARGET_PERSONALITY_OS | |
TARGET_PERSONALITY_PROCESS | |
TARGET_PERSONALITY_APPLICATION |
Definition at line 180 of file target_api.h.
Enumerator | |
---|---|
POLL_NOTHING | |
POLL_ERROR | |
POLL_SUCCESS | |
POLL_UNKNOWN | |
__POLL_MAX |
Definition at line 394 of file target_api.h.
enum target_status_t |
Enumerator | |
---|---|
TSTATUS_UNKNOWN | |
TSTATUS_RUNNING | |
TSTATUS_PAUSED | |
TSTATUS_ERROR | |
TSTATUS_DONE | |
TSTATUS_EXITING | |
TSTATUS_DEAD | |
TSTATUS_STOPPED | |
TSTATUS_INTERRUPTED |
Definition at line 197 of file target_api.h.
enum target_type_t |
Enumerator | |
---|---|
TARGET_TYPE_NONE | |
TARGET_TYPE_PTRACE | |
TARGET_TYPE_XEN | |
TARGET_TYPE_OS_PROCESS | |
TARGET_TYPE_PHP | |
TARGET_TYPE_GDB |
Definition at line 163 of file target_api.h.
Enumerator | |
---|---|
TARGET_UNWIND_STYLE_GDB | |
TARGET_UNWIND_STYLE_PROG | |
TARGET_UNWIND_STYLE_PROG_KEYS |
Definition at line 2432 of file target_api.h.
enum thread_bpmode_t |
Enumerator | |
---|---|
THREAD_BPMODE_STRICT | |
THREAD_BPMODE_SEMI_STRICT | |
THREAD_BPMODE_LOOSE |
Definition at line 366 of file target_api.h.
enum thread_resumeat_t |
The primary target data structures.
Enumerator | |
---|---|
THREAD_RESUMEAT_NONE | |
THREAD_RESUMEAT_BPH | |
THREAD_RESUMEAT_SSR | |
THREAD_RESUMEAT_NA | |
THREAD_RESUMEAT_PH |
Definition at line 2069 of file target_api.h.
enum thread_status_t |
Definition at line 254 of file target_api.h.
enum value_diff_t |
Enumerator | |
---|---|
VALUE_DIFF_SAME | |
VALUE_DIFF_DIFF | |
VALUE_DIFF_MAYBE | |
VALUE_DIFF_UNKNOWN |
Definition at line 1634 of file target_api.h.
char* bsymbol_get_name | ( | struct bsymbol * | bsymbol | ) |
void bsymbol_hold | ( | struct bsymbol * | bsymbol | ) |
Definition at line 1072 of file target_api.c.
ADDR target_addressof_symbol | ( | struct target * | target, |
struct target_location_ctxt * | tlctxt, | ||
struct bsymbol * | bsymbol, | ||
load_flags_t | flags, | ||
struct memrange ** | range_saveptr | ||
) |
Load functions. Everything that gets loaded is loaded as a value struct.
Each load function can handle a bsymbol that contains a nested symbol chain. Members may nest in either 1) functions, or 2) struct/unions. Obviously, once you are in a struct/union, the only members of those can be variables. Thus, all functions must come first in the chain. So, here are some examples of nested symbols that can be followed by these functions: function.subfunc.param1, function.local, function.localstructinst.x, structinst.x.y.z, structinst->x.y.z, structinst->x->y->z Now, since we support automatic pointer dereferencing, you don't have to worry about actually using -> or .; you just use . . If the final symbol is itself a pointer to something, if the AUTO_DEREF or AUTO_STRING load flags are set, the pointer will be dereferenced as much as possible before loading. Otherwise, it won't be. The AUTO_DEREF flags do not affect the behavior of intermediate pointer symbols in the chain; those are always autoloaded if possible. If you don't like this intermediate pointer autoloading behavior, don't use it!
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 | ||
) |
Parses possibly multiple target specification objects by parsing command line arguments provided in the standard argc, argv pair. The caller should be a StackDB program who wants to build a target_spec object containing the details about one or more targets (and perhaps one or more stacks of overlay targets built atop them) to instantiate. This program may also require its own arguments, which it can retrieve and parse after any StackDB-relevant arguments have been extracted (see the User Guide section on standard StackDB arguments).
driver_parser | A fully-specified GNU argp parser struct (see http://www.gnu.org/software/libc/manual/html_node/Argp.html). May be NULL, if your program doesn't require any arguments. | |
driver_state | A pointer to an object that will be passed to your driver_parser when driver_parser->parser is invoked. May always be NULL; it's up to you. | |
argc | A count of the arguments in argv; usually is main()'s first argument. | |
argv | An argument vector; usually is main()'s second argument. | |
target_types | A mask of allowed target types (drivers) that your program can be applied to. | |
filter_quoted | If set non-zero, the StackDB argp wrapper will catch any arguments after the "--" characters on the command line, and save them to be processed. The Ptrace driver will process any arguments after "--" and use them to launch a program that StackDB will attach to). | |
[out] | primary_target_spec | The primary target_spec. This should be a pointer to a target_spec * that is set to NULL; this function will allocate a target_spec * according to the argv parameter. |
[out] | base_target_specs | A GList * of base target_specs. This should be a pointer to a GList * that is set to NULL. This function will allocate a GList * of target_spec * structs based on any –base '...' argv members. The primary target_spec object is not in this list! |
[out] | overlay_target_specs | A GList * of overlay target_specs. This should be a pointer to a GList * that is set to NULL. This function will allocate a GList * of target_spec * structs based on any –overlay '...' argv members. |
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 | ||
) |
Returns a single target specification object by parsing command line arguments provided in the standard argc, argv pair. The caller should be a StackDB program who wants to build a target_spec object containing the details about a target (and perhaps its overlay targets) to instantiate. This program may also require its own arguments, which it can retrieve and parse after any StackDB-relevant arguments have been extracted (see the User Guide section on standard StackDB arguments).
driver_parser | A fully-specified GNU argp parser struct (see http://www.gnu.org/software/libc/manual/html_node/Argp.html). May be NULL, if your program doesn't require any arguments. |
driver_state | A pointer to an object that will be passed to your driver_parser when driver_parser->parser is invoked. May always be NULL; it's up to you. |
argc | A count of the arguments in argv; usually is main()'s first argument. |
argv | An argument vector; usually is main()'s second argument. |
target_types | A mask of allowed target types (drivers) that your program can be applied to. |
filter_quoted | If set non-zero, the StackDB argp wrapper will catch any arguments after the "--" characters on the command line, and save them to be processed. The Ptrace driver will process any arguments after "--" and use them to launch a program that StackDB will attach to). |
void* target_argp_driver_state | ( | struct argp_state * | state | ) |
struct target_spec* target_argp_target_spec | ( | struct argp_state * | state | ) |
Definition at line 834 of file target_api.c.
int target_bsymbol_resolve_base | ( | struct target * | target, |
struct target_location_ctxt * | tlctxt, | ||
struct bsymbol * | bsymbol, | ||
ADDR * | o_addr, | ||
struct memrange ** | o_range | ||
) |
struct target_spec* target_build_default_overlay_spec | ( | struct target * | target, |
tid_t | tid | ||
) |
Definition at line 734 of file target_api.c.
struct target_spec* target_build_spec | ( | target_type_t | type, |
target_mode_t | mode | ||
) |
Definition at line 410 of file target_api.c.
int target_change_sw_breakpoint | ( | struct target * | target, |
tid_t | tid, | ||
struct target_memmod * | mmod, | ||
unsigned char * | code, | ||
unsigned long | code_len | ||
) |
Definition at line 1800 of file target_api.c.
int target_close | ( | struct target * | target | ) |
Closes a target and releases all its live resources.
(Internally, this calls the following target_ops: detach(), kill() (if target->kill_on_close is set).)
Definition at line 1511 of file target_api.c.
Definition at line 1203 of file target_api.c.
int target_cregno | ( | struct target * | target, |
common_reg_t | creg, | ||
REG * | reg | ||
) |
Definition at line 1126 of file target_api.c.
int target_decoder_binding_add | ( | struct target_decoder_binding * | tdb, |
struct bsymbol * | bsymbol, | ||
target_decoder_t | dfn | ||
) |
int target_decoder_lib_bind | ( | struct target * | target, |
char * | decoder_lib, | ||
char * | decoder_lib_lib | ||
) |
int target_decoder_lib_register | ( | struct target_decoder_lib * | lib | ) |
int target_decoder_lookup | ( | struct target * | target, |
struct value * | value, | ||
target_decoder_t * | decoder, | ||
void ** | decoder_data | ||
) |
void target_default_cleanup | ( | void | ) |
A function that pauses, closes, and finalizes all targets the target library knows of. If any of the target objects was handling an exception, it schedules an interrupt for that target — and the user (the caller of target_monitor() or target_monitor_evloop() must call target_default_cleanup() if the returned target status is TSTATUS_INTERRUPTED. The user must also identify if the signal was a fatal signal, or a simple interruption; this is up to the user.
void target_default_sighandler | ( | int | signo, |
siginfo_t * | siginfo, | ||
void * | x | ||
) |
The default signal handler for the target library. Saves off the signal information into a global variable (accessible via target_monitor_was_interrupted()); calls the user sighandler if specified; pauses all target objects if the signal was supposed to result in an interrupt of the target_monitor_evloop() function (and pauses them safely by employing target_monitor_schedule_interrupt() on any target that is currently handling an exception); OR calls the target_default_cleanup() function if the signal is fatal.
int target_detach_evloop | ( | struct target * | target | ) |
Definition at line 846 of file target_api.c.
int target_disable_feature | ( | struct target * | target, |
int | feature | ||
) |
Definition at line 1957 of file target_api.c.
Definition at line 1877 of file target_api.c.
Definition at line 1865 of file target_api.c.
int target_disable_sw_breakpoint | ( | struct target * | target, |
tid_t | tid, | ||
struct target_memmod * | mmod | ||
) |
Definition at line 1786 of file target_api.c.
void target_driver_argp_init_children | ( | struct argp_state * | state | ) |
void target_dump_all_threads | ( | struct target * | target, |
FILE * | stream, | ||
int | detail | ||
) |
Definition at line 1500 of file target_api.c.
Definition at line 1484 of file target_api.c.
int target_enable_feature | ( | struct target * | target, |
int | feature, | ||
void * | arg | ||
) |
Definition at line 1950 of file target_api.c.
Definition at line 1884 of file target_api.c.
Definition at line 1871 of file target_api.c.
int target_enable_sw_breakpoint | ( | struct target * | target, |
tid_t | tid, | ||
struct target_memmod * | mmod | ||
) |
Definition at line 1773 of file target_api.c.
int target_finalize | ( | struct target * | target | ) |
Finalizes a target. This means the library drops its internal reference to the target — and thus, the user did not call target_hold() after target_open(), this will also have the effect of freeing the target struct – because the target library will remove the target struct from its internal structs, and drop a ref. Unless some other caller had held a ref to it for some other reason, this will deallocate it. Thus – if you want to hold onto the struct for subsequent calls, hold onto it first!
NB: the library will never drop its ref to the target struct object unless the user calls target_finalize() – or target_fini(). It may detach (on your behalf) from an exiting target, but that does not perform the work of target_finalize() by itself – you still get to do that so you can handle the exiting/exited target.
void target_fini | ( | void | ) |
This function should be called by the StackDB user when the user is done using StackDB, or when their program is about to exit. It cleans up global StackDB state. One way to do this is to to schedule it to be called via atexit(3) — although note that will not work in the case where the program is terminated by signal delivery.
target_fini() can safely be called at any point in your program, except from within a probe or action handler! It will result in any active, open target objects being closed and freed. After calling this function, you cannot use any other StackDB library target_* functions until you call target_init() again.
int target_flush_all_threads | ( | struct target * | target | ) |
Definition at line 1340 of file target_api.c.
int target_flush_current_thread | ( | struct target * | target | ) |
Definition at line 1329 of file target_api.c.
Definition at line 1334 of file target_api.c.
void target_free_spec | ( | struct target_spec * | spec | ) |
Definition at line 453 of file target_api.c.
int target_gc_threads | ( | struct target * | target | ) |
Definition at line 1368 of file target_api.c.
uint64_t target_get_counter | ( | struct target * | target | ) |
Definition at line 1943 of file target_api.c.
uint64_t target_get_time | ( | struct target * | target | ) |
Definition at line 1936 of file target_api.c.
uint64_t target_get_tsc | ( | struct target * | target | ) |
Definition at line 1929 of file target_api.c.
Definition at line 1822 of file target_api.c.
Definition at line 1918 of file target_api.c.
struct target_location_ctxt* target_global_tlctxt | ( | struct target * | target | ) |
Target location contexts (unwinding, symbol loading/address resolution).
We use a target_location_ctxt struct that wraps location_ctxt in dwdebug. Thus, you can lookup/load symbols in the current thread, or in an unwind context. You must supply a context, however – loading symbols is meaningless if you don't have a thread context and a memory context binding the symbol to an execution context.
A context keeps a notion of current frame, which it shares with its underlying location_ctxt (i.e., with the dwdebug library). This enables these two libraries to unwind cooperatively (dwdebug handles location resolution/computation and saved register resolution/computation; target caches restored registers and keeps a stack of frames and their metadata).
GHashTable* target_hash_available_tids | ( | struct target * | target | ) |
Definition at line 1277 of file target_api.c.
GHashTable* target_hash_threads | ( | struct target * | target | ) |
Definition at line 1253 of file target_api.c.
void target_hold | ( | struct target * | target | ) |
Definition at line 1657 of file target_api.c.
int target_id | ( | struct target * | target | ) |
Definition at line 509 of file target_api.c.
void target_init | ( | void | ) |
This file describes the publicly-accessible target API. The target library is really a library of debug routines that supports multiple backends. It is built atop the dwdebug library, which is a library for parsing DWARF debug information. It provides two backends: a Linux ptrace userspace backend, and a Xen virtual machine (assumes a Linux guest) backend. Both backends are x86-only at the moment. The linux ptrace backend supports 32/64-bit targets, but not 32-bit emulated atop 64-bit host. The Xen VM/Linux guest backend supports 32-bit Xen/guest; it has partial, nonfunctional support for 64-bit-ness. Right now, the backend code does not separate the logic for dealing with a target in an architecture-independent way – the arch stuff is jammed in with the target code. This should not be this way; eventually, hopefully, it will change into a target backend that supports different arch/machine ops. Also, there are probably some x86-isms that have leaked into the "generic" target and probe code :(.
The target library supports two modes of dealing with threads inside a target. Some targets provide control over executing threads (i.e., can the library pause random threads at will, or not); the Linux ptrace target of course supports this; the Xen VM target does not (it could mostly support "pausing" all non-current threads in a single CPU guest, BUT even this requires that the debug lib handle NMIs, asynch interrupts, and some synchronous exceptions – overloading the kernel's IDT – but right now we don't do this).
Targets that do not provide control over thread scheduling must still provide thread identification. This is important for shared (i.e., memory-based) breakpoints, which any thread could hit at any time – not just the thread the user is interested in. Our handling of such breakpoints must be context-aware, so that we maintain handling information on a per-thread basis.
So the library supports two kinds of targets: ones that provide thread control (ptrace), and ones that provide thread awareness (Xen).
The intent is that the target library provides a library above the dwdebug library, so you should never (or rarely) have to call into dwdebug to deal with symbol information. The reason for this attempted restriction is as follows. First, an in-memory representation of DWARF debug data that facilitates fast lookups is big. So, we want to share it between targets (or between all target library users) as much as possible (possible when targets use the same debuginfo, or a subset thereof). Second, memory locations are, naturally, virtual addresses in debuginfo. For the statically-linked core of an executable, there is no difference between virtual/physical; the core is mmap'd at the static addresses. But shared objects/libs may be mmap'd anywhere in the address space, so we have to translate. Rather than smacking the details of physical translation into the debuginfo data structures, for each target instance, we build this translation into the target library. This is perhaps annoying, but facilitates better sharing.
The target library is described via the API functions listed below. To build a new target backend, you must implement the target_ops operations; see the documentation for struct target_ops
below.
For information on how to probe a target, see probe_api.h . This function must be called by StackDB user before using any library functions.
struct target_memmod* target_insert_sw_breakpoint | ( | struct target * | target, |
tid_t | tid, | ||
ADDR | addr | ||
) |
Definition at line 1729 of file target_api.c.
int target_install_custom_sighandlers | ( | sigset_t * | ignored, |
sigset_t * | interrupt, | ||
sigset_t * | exit, | ||
void(*)(int signo, siginfo_t *siginfo, void *x) | sighandler | ||
) |
Install the library's default signal handler, but customize which signals it is set for!
ignored | A pointer to a sigset_t (see man 3 sigset) of signals to be ignored. |
interrupt | A pointer to a sigset_t of signals to cause target_monitor or target_monitor_evloop to be interrupted so that you can handle a signal synchronously with respect to target exception handling (i.e., safely!). |
exit | A pointer to a sigset_t of signals that will cause your program to be exit. Remember, if one of your targets is being handled when the handler is invoked, the library cannot free that target — and you must call target_default_cleanup() again yourself to finish the cleanup! |
sighandler | A signal handler function in your program (see man sigaction) that will be called by the target library's default signal handler. This function is called immediately after the handler saves off the siginfo into a global variable for later retrieval by your program, to give you notice that the target library is about to handle a signal for you. Usually, the only thing that your handler should do is clean up any state that the default handler is unaware of (i.e., remove any probes you placed on targets). Note that when your handler is called, the default handler has not yet paused all targets — so if you are going to modify any targets, you must pause them first. |
int target_install_default_sighandlers | ( | void(*)(int signo, siginfo_t *siginfo, void *x) | sighandler | ) |
Install some default signal handlers for the target library. It is very important to handle signals that would be fatal, because you must remove any probes placed on any targets — otherwise those programs will very likely crash when they hit the probes — because nothing is attached to them any longer.
This function installs the target_default_sighandler() on the following signals: SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGABRT, SIGFPE, SIGSEGV, SIGPIPE, SIGTERM, SIGBUS, SIGXCPU, and SIGXFSZ. It sets up SIGUSR1, SIGUSR2, and SIGALRM to be ignored. If you want to change those signal sets, see target_install_custom_sighandlers().
sighandler | A signal handler function in your program (see man sigaction) that will be called by the target library's default signal handler. This function is called immediately after the handler saves off the siginfo into a global variable for later retrieval by your program, to give you notice that the target library is about to handle a signal for you. Usually, the only thing that your handler should do is clean up any state that the default handler is unaware of (i.e., remove any probes you placed on targets). Note that when your handler is called, the default handler has not yet paused all targets — so if you are going to modify any targets, you must pause them first. |
struct target* target_instantiate | ( | struct target_spec * | spec, |
struct evloop * | evloop | ||
) |
Instantiates a target object according to the configuration provided in spec. The returned target object is configured and prepared to be passed to target_open(), at which point it will be attached to the target program. Once instantiated, it is recorded in the library's global data structures, so calls like target_lookup_target_id() will succeed. It remains in the library's global structures until target_close() is called, at which point it is removed. If you pass an event loop evloop, the target object will be attached to the given evloop.
Event loops are our homegrown, powerful wrapper around select(). Most StackDB drivers are capable of turning debug exceptions into notifications on file descriptors, and those descriptors can be passed to the event loop. Moreover, event loops allow you to integrate your program's own event-driven main loop with StackDB's event-driven paradigm. You can pass your own FDs and handlers to StackDB's event loop, and evloop_run() or evloop_handleone() can be called to do the event loop work for you. However, many people won't need a separate event loop, and can simple use target_monitor() to control target execution — because all of their program's work is done in reacting to StackDB probes. Moreover, target_monitor() is interruptible, so you need not use a polling strategy — you can interrupt it from your own signal handlers.
spec | A target_spec, describing the kind of target object to instantiate. |
evloop | An evloop that will "run" this target object via evloop_run() or evloop_handleone(); see evloop_create(). |
The generic target API!
Definition at line 55 of file target_api.c.
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 | ||
) |
Instantiates and opens target objects according to the target_spec objects in the primary_target_spec, base_target_specs, and overlay_target_specs params. The returned target objects are already opened, since if there are overlay target specs, we would need to open the corresponding base target in order to instantiate the overlay — and to be consistent, we just open all the targets. Once instantiated, the targets are recorded in global data structures, so calls like target_lookup_target_id() will succeed. The targets remain in the library's global structures until target_finalize() is called, at which point it is removed. If you pass an event loop evloop, the target object will be attached to the given evloop. You'll almost certainly want to use an evloop with this function, and then invoke target_monitor_evloop() to monitor your targets.
This function will handle both base and overlay target specs, and does not require that the lists are ordered by dependency.
If you pass a valid error_specs pointer, if a target_spec in the list cannot be instantiated and opened, that target_spec will be appended to the error_specs list, but this function will still return a list of successfully opened target objects. If you don't pass a valid error_specs pointer, if any target_spec fails to be instantiated and opened, this function will abort, close and finalize any just-opened targets, and return NULL.
primary_target_specs | A struct target_spec, describing the "primary" target object to instantiate. |
base_target_specs | A GList of struct target_spec, describing the base target objects to instantiate. |
overlay_target_specs | A GList of struct target_spec, describing the overlay target objects to instantiate. |
evloop | An evloop that will "run" these target objects via evloop_run() or evloop_handleone(); see evloop_create() and target_monitor_evloop(). |
error_specs | A pointer to a GList that, if set, will be filled with target_spec objects that were not successfully instantiated and opened. |
Definition at line 92 of file target_api.c.
GList* target_instantiate_and_open_list | ( | GList * | target_specs, |
struct evloop * | evloop, | ||
GList ** | error_specs | ||
) |
Instantiates and opens target objects according to the target_spec objects in the target_specs param. The returned target objects are already opened, since if there are overlay target specs, we would need to open the corresponding base target in order to instantiate the overlay — and to be consistent, we just open all the targets. Once instantiated, the targets are recorded in global data structures, so calls like target_lookup_target_id() will succeed. The targets remain in the library's global structures until target_finalize() is called, at which point it is removed. If you pass an event loop evloop, the target object will be attached to the given evloop. You'll almost certainly want to use an evloop with this function, and then invoke target_monitor_evloop() to monitor your targets.
This function will handle both base and overlay target specs, and does not require that the lists are ordered by dependency.
If you pass a valid error_specs pointer, if a target_spec in the list cannot be instantiated and opened, that target_spec will be appended to the error_specs list, but this function will still return a list of successfully opened target objects. If you don't pass a valid error_specs pointer, if any target_spec fails to be instantiated and opened, this function will abort, close and finalize any just-opened targets, and return NULL.
target_specs | A GList of struct target_spec, describing the kind of target objects to instantiate. |
evloop | An evloop that will "run" these target objects via evloop_run() or evloop_handleone(); see evloop_create() and target_monitor_evloop(). |
error_specs | A pointer to a GList that, if set, will be filled with target_spec objects that were not successfully instantiated and opened. |
Definition at line 287 of file target_api.c.
struct target* target_instantiate_overlay | ( | struct target * | target, |
tid_t | tid, | ||
struct target_spec * | spec | ||
) |
Definition at line 757 of file target_api.c.
Definition at line 863 of file target_api.c.
int target_is_open | ( | struct target * | target | ) |
Definition at line 1042 of file target_api.c.
int target_kill | ( | struct target * | target, |
int | sig | ||
) |
Definition at line 1652 of file target_api.c.
struct array_list* target_list_available_overlay_tids | ( | struct target * | target, |
target_type_t | type | ||
) |
Definition at line 656 of file target_api.c.
struct array_list* target_list_available_tids | ( | struct target * | target | ) |
Definition at line 1272 of file target_api.c.
struct array_list* target_list_overlays | ( | struct target * | target | ) |
Definition at line 686 of file target_api.c.
struct array_list* target_list_threads | ( | struct target * | target | ) |
Definition at line 1233 of file target_api.c.
struct array_list* target_list_tids | ( | struct target * | target | ) |
Definition at line 1210 of file target_api.c.
struct value* target_load_addr_obj | ( | struct target * | target, |
struct memregion * | region, | ||
ADDR | obj_addr, | ||
load_flags_t | flags, | ||
int | len | ||
) |
struct value* target_load_addr_real | ( | struct target * | target, |
ADDR | addr, | ||
load_flags_t | flags, | ||
int | len | ||
) |
int target_load_all_threads | ( | struct target * | target, |
int | force | ||
) |
Definition at line 1318 of file target_api.c.
int target_load_available_threads | ( | struct target * | target, |
int | force | ||
) |
Definition at line 1300 of file target_api.c.
struct target_thread* target_load_current_thread | ( | struct target * | target, |
int | force | ||
) |
Definition at line 1305 of file target_api.c.
struct value* target_load_symbol | ( | struct target * | target, |
struct target_location_ctxt * | tlctxt, | ||
struct bsymbol * | bsymbol, | ||
load_flags_t | flags | ||
) |
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 | ||
) |
struct target_thread* target_load_thread | ( | struct target * | target, |
tid_t | tid, | ||
int | force | ||
) |
Definition at line 1311 of file target_api.c.
struct value* target_load_type | ( | struct target * | target, |
struct symbol * | type, | ||
ADDR | addr, | ||
load_flags_t | flags | ||
) |
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 | ||
) |
struct target_location_ctxt* target_location_ctxt_create | ( | struct target * | target, |
tid_t | tid, | ||
struct memregion * | region | ||
) |
struct target_location_ctxt* target_location_ctxt_create_from_bsymbol | ( | struct target * | target, |
tid_t | tid, | ||
struct bsymbol * | bsymbol | ||
) |
struct target_location_ctxt_frame* target_location_ctxt_current_frame | ( | struct target_location_ctxt * | tlctxt | ) |
void target_location_ctxt_free | ( | struct target_location_ctxt * | tlctxt | ) |
struct target_location_ctxt_frame* target_location_ctxt_get_frame | ( | struct target_location_ctxt * | tlctxt, |
int | frame | ||
) |
struct target_location_ctxt_frame* target_location_ctxt_prev | ( | struct target_location_ctxt * | tlctxt | ) |
int target_location_ctxt_read_reg | ( | struct target_location_ctxt * | tlctxt, |
REG | reg, | ||
REGVAL * | o_regval | ||
) |
void target_location_ctxt_retarget_bsymbol | ( | struct target_location_ctxt * | tlctxt, |
struct bsymbol * | bsymbol | ||
) |
int target_location_ctxt_unwind | ( | struct target_location_ctxt * | tlctxt | ) |
Definition at line 1671 of file target_api.c.
Definition at line 693 of file target_api.c.
Definition at line 713 of file target_api.c.
Definition at line 1666 of file target_api.c.
int target_lookup_safe_disasm_range | ( | struct target * | target, |
ADDR | addr, | ||
ADDR * | start, | ||
ADDR * | end, | ||
void ** | data | ||
) |
Functions to deal with "widest range" lookup, text code loading and caching, and safe disassembly. We want to be sure we always start disassembly at a safe place in the text bytes we load – not wherever the library use requests (which might be in some weird place). Plus, we want to cache well-defined chunks of code to avoid fragmentation in the cache.
struct bsymbol* target_lookup_sym | ( | struct target * | target, |
const char * | name, | ||
const char * | delim, | ||
char * | srcfile, | ||
symbol_type_flag_t | ftype | ||
) |
target_status_t target_monitor | ( | struct target * | target | ) |
Monitors a target for debug/exception events and, when such events occur, handles any probes attached to the target. This is a synchronous, blocking monitor style: it only returns if it can't handle some condition that arises; if an error occurs while handling an expected debug exception; or if the user scheduled an interrupt via target_monitor_schedule_interrupt() (so to schedule an interrupt when using target_monitor(), call target_monitor_schedule_interrupt() followed by alarm(0) or kill(getpid(),SIGALRM), if you've ignored or setup a handler for SIGALRM!).
target | The target object to monitor. |
Definition at line 869 of file target_api.c.
void target_monitor_clear_global_interrupt | ( | void | ) |
int target_monitor_evloop | ( | struct evloop * | evloop, |
struct timeval * | timeout, | ||
struct target ** | target, | ||
target_status_t * | status | ||
) |
Monitors an evloop (with target objects attached to it!) for debug/exception events and, when such events occur, handles any probes attached to the target. This is a synchronous, blocking monitor style: it only returns if it can't handle some condition that arises; if an error occurs while handling an expected debug exception; or if the user scheduled an interrupt via target_monitor_schedule_global_interrupt() or on a particular target via target_monitor_schedule_interrupt() (so to schedule an interrupt when using target_monitor_evloop(), call target_monitor_schedule_interrupt() followed by alarm(0) or kill(getpid(),SIGALRM), if you've ignored or setup a handler for SIGALRM!).
evloop | The evloop object to monitor (via evloop_handleone()). | |
timeout | A timeout object that will be passed to select(). | |
[out] | target | A pointer to a target object that will be filled in with the target just handled. |
[out] | status | A pointer to a target_status_t that will be filled in with the status of the target just handled. |
Definition at line 880 of file target_api.c.
int target_monitor_handling_exception | ( | struct target * | target | ) |
This function is useful only when using target_monitor() and employing your own custom signal handling. It may be useful to call it from your signal handler to see if the target you are monitoring is handling an exception. If it is handling an exception, it is unsafe to call any target_*() operations on it — for instance, you cannot attempt to remove a probe. In this case, the best thing to do is call target_monitor_schedule_interrupt(target), and wait for target_monitor() to return with a status of TSTATUS_INTERRUPTED. So, part of your signal handler might look like this:
if (target_monitor_handling_exception(t)) { needtodosomething = 1; target_monitor_schedule_interrupt(t); } else { target_pause(t); cleanup(); }
void target_monitor_schedule_global_interrupt | ( | void | ) |
int target_monitor_schedule_interrupt | ( | struct target * | target | ) |
Schedules an an interrupt to happen after target_monitor() finishes handling the current exception, if any. See target_monitor_handling_exception().
int target_monitor_was_interrupted | ( | siginfo_t * | last_siginfo | ) |
char* target_name | ( | struct target * | target | ) |
Definition at line 505 of file target_api.c.
target_status_t target_notify_overlay | ( | struct target * | overlay, |
target_exception_flags_t | flags, | ||
tid_t | tid, | ||
ADDR | ipval, | ||
int * | again | ||
) |
Definition at line 1891 of file target_api.c.
int target_open | ( | struct target * | target | ) |
Definition at line 513 of file target_api.c.
int target_open_all | ( | struct target * | target | ) |
int target_pause | ( | struct target * | target | ) |
Definition at line 1027 of file target_api.c.
Definition at line 1323 of file target_api.c.
target_status_t target_poll | ( | struct target * | target, |
struct timeval * | tv, | ||
target_poll_outcome_t * | outcome, | ||
int * | pstatus | ||
) |
Definition at line 1001 of file target_api.c.
unsigned char* target_read_addr | ( | struct target * | target, |
ADDR | addr, | ||
unsigned long | length, | ||
unsigned char * | buf | ||
) |
Definition at line 1053 of file target_api.c.
REGVAL target_read_creg | ( | struct target * | target, |
tid_t | tid, | ||
common_reg_t | reg | ||
) |
Definition at line 1178 of file target_api.c.
unsigned char* target_read_physaddr | ( | struct target * | target, |
ADDR | paddr, | ||
unsigned long | length, | ||
unsigned char * | buf | ||
) |
Definition at line 1083 of file target_api.c.
Definition at line 1132 of file target_api.c.
REGVAL target_read_reg_ctxt | ( | struct target * | target, |
tid_t | tid, | ||
thread_ctxt_t | tidctxt, | ||
REG | reg | ||
) |
Definition at line 1157 of file target_api.c.
Definition at line 1114 of file target_api.c.
Definition at line 1120 of file target_api.c.
void target_release | ( | struct target * | target | ) |
Definition at line 1661 of file target_api.c.
int target_remove_sw_breakpoint | ( | struct target * | target, |
tid_t | tid, | ||
struct target_memmod * | mmod | ||
) |
Definition at line 1760 of file target_api.c.
int target_resume | ( | struct target * | target | ) |
Definition at line 1012 of file target_api.c.
int target_set_active_probing | ( | struct target * | target, |
active_probe_flags_t | flags | ||
) |
Definition at line 633 of file target_api.c.
Definition at line 1836 of file target_api.c.
int target_set_hw_watchpoint | ( | struct target * | target, |
tid_t | tid, | ||
REG | reg, | ||
ADDR | addr, | ||
probepoint_whence_t | whence, | ||
int | watchsize | ||
) |
Definition at line 1843 of file target_api.c.
Definition at line 1903 of file target_api.c.
Definition at line 1909 of file target_api.c.
int target_snprintf | ( | struct target * | target, |
char * | buf, | ||
int | bufsiz | ||
) |
Definition at line 829 of file target_api.c.
int target_spec_to_argv | ( | struct target_spec * | spec, |
char * | arg0, | ||
int * | argc, | ||
char *** | argv | ||
) |
target_status_t target_status | ( | struct target * | target | ) |
Definition at line 1046 of file target_api.c.
int target_thread_snprintf | ( | struct target * | target, |
tid_t | tid, | ||
char * | buf, | ||
int | bufsiz, | ||
int | detail, | ||
char * | sep, | ||
char * | key_val_sep | ||
) |
Definition at line 1425 of file target_api.c.
thread_status_t target_thread_status | ( | struct target * | target, |
tid_t | tid | ||
) |
Definition at line 1964 of file target_api.c.
target_type_t target_type | ( | struct target * | target | ) |
Definition at line 501 of file target_api.c.
int target_unchange_sw_breakpoint | ( | struct target * | target, |
tid_t | tid, | ||
struct target_memmod * | mmod | ||
) |
Definition at line 1814 of file target_api.c.
Definition at line 1851 of file target_api.c.
Definition at line 1858 of file target_api.c.
struct target_location_ctxt* target_unwind | ( | struct target * | target, |
tid_t | tid | ||
) |
int target_unwind_snprintf | ( | char * | buf, |
int | buflen, | ||
struct target * | target, | ||
tid_t | tid, | ||
target_unwind_style_t | fstyle, | ||
char * | frame_sep, | ||
char * | ksep | ||
) |
unsigned long target_write_addr | ( | struct target * | target, |
ADDR | addr, | ||
unsigned long | length, | ||
unsigned char * | buf | ||
) |
Definition at line 1060 of file target_api.c.
int target_write_creg | ( | struct target * | target, |
tid_t | tid, | ||
common_reg_t | reg, | ||
REGVAL | value | ||
) |
Definition at line 1187 of file target_api.c.
unsigned long target_write_physaddr | ( | struct target * | target, |
ADDR | paddr, | ||
unsigned long | length, | ||
unsigned char * | buf | ||
) |
Definition at line 1096 of file target_api.c.
Definition at line 1141 of file target_api.c.
int target_write_reg_ctxt | ( | struct target * | target, |
tid_t | tid, | ||
thread_ctxt_t | tidctxt, | ||
REG | reg, | ||
REGVAL | value | ||
) |
Definition at line 1165 of file target_api.c.
int value_refresh_diff | ( | struct value * | value, |
int | recurse, | ||
value_diff_t * | vdiff, | ||
char ** | old_buf, | ||
int * | old_bufsiz, | ||
value_hash_t * | old_vhash | ||
) |
int value_snprintf | ( | struct value * | value, |
char * | buf, | ||
int | buflen | ||
) |
int value_update | ( | struct value * | value, |
const char * | buf, | ||
int | bufsiz | ||
) |
int value_update_uc | ( | struct value * | value, |
unsigned char | v | ||
) |
int value_update_zero | ( | struct value * | value, |
const char * | buf, | ||
int | bufsiz | ||
) |