DynamoRIO
Callstack Walking

The drcallstack DynamoRIO Callstack Walker provides clients with walking of the application callstack.

Setup

To use drcallstack with your client simply include this line in your client's CMakeLists.txt file:

use_DynamoRIO_extension(clientname drcallstack)

That will automatically set up the include path and library dependence.

The initialization routine drcallstack_init() must be called prior to any of the other routines. Additional calls to drcallstack_init() are allowed (so long as they are paired with corresponding calls to drcallstack_exit()).

Usage

To produce a callstack, first a dr_mcontext_t with the PC field and all general-purpose registers filled in with application values (i.e., DR_MC_CONTROL | DR_MC_INTEGER) must be obtained. When using a custom clean call, the PC field must be explicitly set by the client (typically by passing the application address of the next instruction to the clean call) as it is not set in that case by dr_get_mcontext().

Next, call drcallstack_init_walk() to set up for a walk. Then repeatedly call drcallstack_next_frame() to iterate over the frames of the callstack. When DRCALLSTACK_NO_MORE_FRAMES or an error code is returned, clean up with drcallstack_cleanup_walk().

Here is some example code:

sizeof(frame),
};
int count = 0;
symbolize_pc(drwrap_get_func(wrapcxt));
do {
res = drcallstack_next_frame(walk, &frame);
if (res != DRCALLSTACK_SUCCESS)
break;
symbolize_pc(frame.pc);
++count;
} while (res == DRCALLSTACK_SUCCESS);

Limitations

Currently, drcallstack is only implemented for Linux.

Definition: dr_defines.h:803
struct _drcallstack_walk_t drcallstack_walk_t
Definition: drcallstack.h:85
#define DR_ASSERT(x)
Definition: dr_tools.h:99
DR_EXPORT drcallstack_status_t drcallstack_init_walk(dr_mcontext_t *mc, OUT drcallstack_walk_t **walk)
Definition: drcallstack.h:73
drcallstack_status_t
Definition: drcallstack.h:53
app_pc pc
Definition: drcallstack.h:77
DR_EXPORT dr_mcontext_t * drwrap_get_mcontext(void *wrapcxt)
@ DRCALLSTACK_SUCCESS
Definition: drcallstack.h:54
@ DRCALLSTACK_NO_MORE_FRAMES
Definition: drcallstack.h:55
DR_EXPORT drcallstack_status_t drcallstack_next_frame(drcallstack_walk_t *walk, OUT drcallstack_frame_t *frame)
DR_EXPORT drcallstack_status_t drcallstack_cleanup_walk(drcallstack_walk_t *walk)
DR_EXPORT app_pc drwrap_get_func(void *wrapcxt)