haide frame storage from user and introduce separate method

pst_get_register() to obtain register value within function's stack
frame
This commit is contained in:
2020-05-02 13:51:31 +04:00
parent 1825515ca0
commit d1441b3b6f
6 changed files with 33 additions and 9 deletions
+3 -3
View File
@@ -271,7 +271,7 @@ bool function_handle_dwarf(pst_function * fn, Dwarf_Die* d)
// }
unw_proc_info_t info;
unw_get_proc_info(&fn->info.context, &info);
unw_get_proc_info(&fn->context, &info);
fn->ctx->clean_print(fn->ctx);
pst_log(SEVERITY_INFO, "Function %s(...): LOW_PC = %#lX, HIGH_PC = %#lX, offset from base address: 0x%lX, START_PC = 0x%lX, offset from start of function: 0x%lX",
@@ -429,7 +429,7 @@ void pst_function_init(pst_function* fn, pst_context* _ctx, pst_function* _paren
fn->info.pc = 0;
fn->info.lowpc = 0;
fn->info.highpc = 0;
bzero(&fn->info.context, sizeof(fn->info.context));
bzero(&fn->context, sizeof(fn->context));
fn->info.name = NULL;
fn->info.line = -1;
fn->info.file = NULL;
@@ -440,7 +440,7 @@ void pst_function_init(pst_function* fn, pst_context* _ctx, pst_function* _paren
list_head_init(&fn->params);
pst_call_site_storage_init(&fn->call_sites, _ctx);
memcpy(&fn->info.context, &_ctx->cursor, sizeof(fn->info.context));
memcpy(&fn->context, &_ctx->cursor, sizeof(fn->context));
fn->parent = _parent;
fn->frame = NULL;
fn->ctx = _ctx;
+1
View File
@@ -30,6 +30,7 @@ typedef struct pst_function {
pst_function* parent; // parent function in call trace (caller)
Dwarf_Frame* frame; // function's stack frame
pst_context* ctx; // context of unwinding
unw_cursor_t context; ///< Function's frame including register's values
bool allocated; // whether this object was allocated or not
} pst_function;
void pst_function_init(pst_function* fn, pst_context* _ctx, pst_function* _parent);
+2 -5
View File
@@ -61,19 +61,16 @@ bool get_dwarf_function(pst_handler* h, pst_function* fun)
return false;
}
bool nret = false;
do {
int tag = dwarf_tag(&result);
if(tag == DW_TAG_subprogram || tag == DW_TAG_entry_point || tag == DW_TAG_inlined_subroutine) {
//ctx.log(SEVERITY_DEBUG, "function die name %s", dwarf_diename(&result));
if(!strcmp(fun->info.name, dwarf_diename(&result))) {
return function_handle_dwarf(fun, &result);
}
}
} while(dwarf_siblingof(&result, &result) == 0);
return nret;
return false;
}
static pst_function* add_function(pst_handler* h, pst_function* parent)
@@ -152,7 +149,7 @@ bool pst_handler_handle_dwarf(pst_handler* h)
// setup context
h->ctx.module = dwfl_addrmodule(h->ctx.dwfl, fun->info.pc);
h->ctx.base_addr = (uint64_t)info.dli_fbase;
h->ctx.curr_frame = &fun->info.context;
h->ctx.curr_frame = &fun->context;
h->ctx.sp = fun->info.sp;
h->ctx.cfa = fun->info.cfa;
+5
View File
@@ -68,6 +68,11 @@ pst_function* pst_function_next(pst_handler* handler, pst_function* current)
return pst_handler_next_function(handler, current);
}
int pst_get_register(pst_function* fn, int regno, unw_word_t* val)
{
return unw_get_reg(&fn->context, regno, val);
}
pst_parameter* pst_parameter_next(pst_function* function, pst_parameter* current)
{
return function_next_parameter(function, current);