define pst_log macro to use global log

This commit is contained in:
2020-02-01 18:11:50 +04:00
parent 7c13dfa9e1
commit dbd8e31129
9 changed files with 77 additions and 77 deletions
+5 -5
View File
@@ -25,7 +25,7 @@ void clean_print(pst_context* ctx) {
void print_stack(pst_context* ctx, int max, uint64_t next_cfa) void print_stack(pst_context* ctx, int max, uint64_t next_cfa)
{ {
ctx->log(SEVERITY_DEBUG, "CFA = %#lX, NEXT_CFA = %#lX, SP = %#lX", ctx->cfa, next_cfa, ctx->sp); pst_log(SEVERITY_DEBUG, "CFA = %#lX, NEXT_CFA = %#lX, SP = %#lX", ctx->cfa, next_cfa, ctx->sp);
ctx->clean_print(ctx); ctx->clean_print(ctx);
int i = 0; int i = 0;
if(ctx->cfa > ctx->sp) { if(ctx->cfa > ctx->sp) {
@@ -74,7 +74,7 @@ bool print(pst_context* ctx, const char* fmt, ...)
void log(SC_LogSeverity severity, const char* fmt, ...) void log(SC_LogSeverity severity, const char* fmt, ...)
{ {
logger.log(&logger, severity, fmt); pst_log(severity, fmt);
} }
bool print_expr_block (pst_context* ctx, Dwarf_Op *exprs, int exprlen, Dwarf_Attribute* attr) bool print_expr_block (pst_context* ctx, Dwarf_Op *exprs, int exprlen, Dwarf_Attribute* attr)
@@ -97,7 +97,7 @@ bool print_expr_block (pst_context* ctx, Dwarf_Op *exprs, int exprlen, Dwarf_Att
ctx->print(ctx, "%s(*%s) value: 0x%lX", map->op_name, unw_regname(regno), value); ctx->print(ctx, "%s(*%s) value: 0x%lX", map->op_name, unw_regname(regno), value);
} else if(map->op_num == DW_OP_GNU_entry_value) { } else if(map->op_num == DW_OP_GNU_entry_value) {
if(!attr) { if(!attr) {
ctx->log(SEVERITY_ERROR, "No attribute of DW_OP_GNU_entry_value provided"); pst_log(SEVERITY_ERROR, "No attribute of DW_OP_GNU_entry_value provided");
return false; return false;
} }
uint32_t value = decode_uleb128((unsigned char*)&exprs[i].number); uint32_t value = decode_uleb128((unsigned char*)&exprs[i].number);
@@ -110,11 +110,11 @@ bool print_expr_block (pst_context* ctx, Dwarf_Op *exprs, int exprlen, Dwarf_Att
ctx->print_expr(ctx, expr, exprlen, &attr_mem); ctx->print_expr(ctx, expr, exprlen, &attr_mem);
ctx->print(ctx, ") "); ctx->print(ctx, ") ");
} else { } else {
ctx->log(SEVERITY_ERROR, "Failed to get DW_OP_GNU_entry_value attr location"); pst_log(SEVERITY_ERROR, "Failed to get DW_OP_GNU_entry_value attr location");
return false; return false;
} }
} else { } else {
ctx->log(SEVERITY_ERROR, "Failed to get DW_OP_GNU_entry_value attr expression"); pst_log(SEVERITY_ERROR, "Failed to get DW_OP_GNU_entry_value attr expression");
return false; return false;
} }
} else if(map->op_num == DW_OP_stack_value) { } else if(map->op_num == DW_OP_stack_value) {
+3 -3
View File
@@ -113,7 +113,7 @@ bool site_handle_dwarf(pst_call_site* site, Dwarf_Die* child)
// determine location of parameter in stack/heap or CPU registers // determine location of parameter in stack/heap or CPU registers
attr = dwarf_attr(child, DW_AT_location, &attr_mem); attr = dwarf_attr(child, DW_AT_location, &attr_mem);
if(!handle_location(site->ctx, attr, &param->location, pc, NULL)) { if(!handle_location(site->ctx, attr, &param->location, pc, NULL)) {
site->ctx->log(SEVERITY_ERROR, "Failed to calculate DW_AT_location expression: %s", site->ctx->buff); pst_log(SEVERITY_ERROR, "Failed to calculate DW_AT_location expression: %s", site->ctx->buff);
site->del_param(site, param); site->del_param(site, param);
return false; return false;
} }
@@ -127,9 +127,9 @@ bool site_handle_dwarf(pst_call_site* site, Dwarf_Die* child)
pst_dwarf_expr_init(&loc); pst_dwarf_expr_init(&loc);
if(handle_location(site->ctx, attr, &loc, pc, NULL)) { if(handle_location(site->ctx, attr, &loc, pc, NULL)) {
param->value = loc.value; param->value = loc.value;
site->ctx->log(SEVERITY_DEBUG, "\tDW_AT_GNU_call_site_value:\"%s\" ==> 0x%lX", site->ctx->buff, param->value); pst_log(SEVERITY_DEBUG, "\tDW_AT_GNU_call_site_value:\"%s\" ==> 0x%lX", site->ctx->buff, param->value);
} else { } else {
site->ctx->log(SEVERITY_ERROR, "Failed to calculate DW_AT_location expression: %s", site->ctx->buff); pst_log(SEVERITY_ERROR, "Failed to calculate DW_AT_location expression: %s", site->ctx->buff);
site->del_param(site, param); site->del_param(site, param);
return false; return false;
} }
+26 -26
View File
@@ -197,7 +197,7 @@ bool __pst_function::handle_lexical_block(Dwarf_Die* result)
{ {
case DW_TAG_variable: case DW_TAG_variable:
case DW_TAG_formal_parameter: case DW_TAG_formal_parameter:
ctx->log(SEVERITY_DEBUG, "Abstract origin: %s('%s')", dwarf_diename(&origin), dwarf_diename (&child)); pst_log(SEVERITY_DEBUG, "Abstract origin: %s('%s')", dwarf_diename(&origin), dwarf_diename (&child));
break; break;
// Also handle DW_TAG_unspecified_parameters (unknown number of arguments i.e. fun(arg1, ...); // Also handle DW_TAG_unspecified_parameters (unknown number of arguments i.e. fun(arg1, ...);
default: default:
@@ -210,7 +210,7 @@ bool __pst_function::handle_lexical_block(Dwarf_Die* result)
if(dwarf_diename(result)) { if(dwarf_diename(result)) {
die_name = dwarf_diename(result); die_name = dwarf_diename(result);
} }
ctx->log(SEVERITY_DEBUG, "Lexical block with name '%s', tag 0x%X and origin '%s' found. lowpc = 0x%lX, highpc = 0x%lX", die_name, dwarf_tag (result), origin_name, lowpc, highpc); pst_log(SEVERITY_DEBUG, "Lexical block with name '%s', tag 0x%X and origin '%s' found. lowpc = 0x%lX, highpc = 0x%lX", die_name, dwarf_tag (result), origin_name, lowpc, highpc);
Dwarf_Die child; Dwarf_Die child;
if(dwarf_child (result, &child) == 0) { if(dwarf_child (result, &child) == 0) {
do { do {
@@ -229,10 +229,10 @@ bool __pst_function::handle_lexical_block(Dwarf_Die* result)
handle_call_site(&child); handle_call_site(&child);
break; break;
case DW_TAG_inlined_subroutine: case DW_TAG_inlined_subroutine:
ctx->log(SEVERITY_DEBUG, "Skipping Lexical block tag 'DW_TAG_inlined_subroutine'"); pst_log(SEVERITY_DEBUG, "Skipping Lexical block tag 'DW_TAG_inlined_subroutine'");
break; break;
default: default:
ctx->log(SEVERITY_DEBUG, "Unknown Lexical block tag 0x%X", dwarf_tag(&child)); pst_log(SEVERITY_DEBUG, "Unknown Lexical block tag 0x%X", dwarf_tag(&child));
break; break;
} }
}while (dwarf_siblingof (&child, &child) == 0); }while (dwarf_siblingof (&child, &child) == 0);
@@ -257,12 +257,12 @@ bool __pst_function::handle_call_site(Dwarf_Die* result)
Dwarf_Attribute attr_mem; Dwarf_Attribute attr_mem;
Dwarf_Attribute* attr; Dwarf_Attribute* attr;
ctx->log(SEVERITY_DEBUG, "***** DW_TAG_GNU_call_site contents:"); pst_log(SEVERITY_DEBUG, "***** DW_TAG_GNU_call_site contents:");
// reference to DIE which represents callee's parameter if compiler knows where it is at compile time // reference to DIE which represents callee's parameter if compiler knows where it is at compile time
const char* oname = NULL; const char* oname = NULL;
if(dwarf_hasattr (result, DW_AT_abstract_origin) && dwarf_formref_die (dwarf_attr (result, DW_AT_abstract_origin, &attr_mem), &origin) != NULL) { if(dwarf_hasattr (result, DW_AT_abstract_origin) && dwarf_formref_die (dwarf_attr (result, DW_AT_abstract_origin, &attr_mem), &origin) != NULL) {
oname = dwarf_diename(&origin); oname = dwarf_diename(&origin);
ctx->log(SEVERITY_DEBUG, "\tDW_AT_abstract_origin: '%s'", oname); pst_log(SEVERITY_DEBUG, "\tDW_AT_abstract_origin: '%s'", oname);
} }
// The call site may have a DW_AT_call_site_target attribute which is a DWARF expression. For indirect calls or jumps where it is unknown at // The call site may have a DW_AT_call_site_target attribute which is a DWARF expression. For indirect calls or jumps where it is unknown at
@@ -274,13 +274,13 @@ bool __pst_function::handle_call_site(Dwarf_Die* result)
pst_dwarf_expr expr(ctx->alloc); pst_dwarf_expr expr(ctx->alloc);
if(handle_location(ctx, &attr_mem, expr, pc, this)) { if(handle_location(ctx, &attr_mem, expr, pc, this)) {
target = expr.value; target = expr.value;
ctx->log(SEVERITY_DEBUG, "\tDW_AT_GNU_call_site_target: %#lX", target); pst_log(SEVERITY_DEBUG, "\tDW_AT_GNU_call_site_target: %#lX", target);
} }
} }
} }
if(target == 0 && oname == NULL) { if(target == 0 && oname == NULL) {
ctx->log(SEVERITY_ERROR, "Cannot determine both call-site target and origin"); pst_log(SEVERITY_ERROR, "Cannot determine both call-site target and origin");
return false; return false;
} }
@@ -309,7 +309,7 @@ bool __pst_function::handle_dwarf(Dwarf_Die* d)
dwarf_lowpc(d, &lowpc); dwarf_lowpc(d, &lowpc);
dwarf_highpc(d, &highpc); dwarf_highpc(d, &highpc);
// } else { // } else {
// ctx->log(SEVERITY_ERROR, "Function's '%s' DIE hasn't definitions of memory offsets of function's code", dwarf_diename(d)); // pst_log(SEVERITY_ERROR, "Function's '%s' DIE hasn't definitions of memory offsets of function's code", dwarf_diename(d));
// return false; // return false;
// } // }
@@ -317,11 +317,11 @@ bool __pst_function::handle_dwarf(Dwarf_Die* d)
unw_get_proc_info(&cursor, &info); unw_get_proc_info(&cursor, &info);
ctx->clean_print(ctx); ctx->clean_print(ctx);
ctx->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", 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",
dwarf_diename(d), lowpc, highpc, pc - ctx->base_addr, info.start_ip, info.start_ip - ctx->base_addr); dwarf_diename(d), lowpc, highpc, pc - ctx->base_addr, info.start_ip, info.start_ip - ctx->base_addr);
ctx->print_registers(ctx, 0x0, 0x10); ctx->print_registers(ctx, 0x0, 0x10);
ctx->log(SEVERITY_INFO, "Function %s(...): CFA: %#lX %s", dwarf_diename(d), parent ? parent->sp : 0, ctx->buff); pst_log(SEVERITY_INFO, "Function %s(...): CFA: %#lX %s", dwarf_diename(d), parent ? parent->sp : 0, ctx->buff);
ctx->log(SEVERITY_INFO, "Function %s(...): %s", dwarf_diename(d), ctx->buff); pst_log(SEVERITY_INFO, "Function %s(...): %s", dwarf_diename(d), ctx->buff);
// determine function's stack frame base // determine function's stack frame base
attr = dwarf_attr(die, DW_AT_frame_base, &attr_mem); attr = dwarf_attr(die, DW_AT_frame_base, &attr_mem);
@@ -335,16 +335,16 @@ bool __pst_function::handle_dwarf(Dwarf_Die* d)
if(stack.calc(&stack, expr, exprlen, attr, this)) { if(stack.calc(&stack, expr, exprlen, attr, this)) {
uint64_t value; uint64_t value;
if(stack.get_value(&stack, &value)) { if(stack.get_value(&stack, &value)) {
ctx->log(SEVERITY_DEBUG, "DW_AT_framebase expression: \"%s\" ==> 0x%lX", ctx->buff, value); pst_log(SEVERITY_DEBUG, "DW_AT_framebase expression: \"%s\" ==> 0x%lX", ctx->buff, value);
} else { } else {
ctx->log(SEVERITY_ERROR, "Failed to get value of calculated DW_AT_framebase expression: %s", ctx->buff); pst_log(SEVERITY_ERROR, "Failed to get value of calculated DW_AT_framebase expression: %s", ctx->buff);
} }
} else { } else {
ctx->log(SEVERITY_ERROR, "Failed to calculate DW_AT_framebase expression: %s", ctx->buff); pst_log(SEVERITY_ERROR, "Failed to calculate DW_AT_framebase expression: %s", ctx->buff);
} }
pst_dwarf_stack_fini(&stack); pst_dwarf_stack_fini(&stack);
} else { } else {
ctx->log(SEVERITY_WARNING, "Unknown attribute form = 0x%X, code = 0x%X", attr->form, attr->code); pst_log(SEVERITY_WARNING, "Unknown attribute form = 0x%X, code = 0x%X", attr->form, attr->code);
} }
} }
} }
@@ -355,7 +355,7 @@ bool __pst_function::handle_dwarf(Dwarf_Die* d)
attr = dwarf_attr(die, DW_AT_type, &attr_mem); attr = dwarf_attr(die, DW_AT_type, &attr_mem);
if(attr) { if(attr) {
if(!ret_p->handle_type(attr)) { if(!ret_p->handle_type(attr)) {
ctx->log(SEVERITY_ERROR, "Failed to handle return parameter type for function %s(...)", name.c_str()); pst_log(SEVERITY_ERROR, "Failed to handle return parameter type for function %s(...)", name.c_str());
del_param(ret_p); del_param(ret_p);
} }
} else { } else {
@@ -410,7 +410,7 @@ bool __pst_function::handle_dwarf(Dwarf_Die* d)
// DW_TAG_unspecified_parameters (unknown number of arguments i.e. fun(arg1, ...); // DW_TAG_unspecified_parameters (unknown number of arguments i.e. fun(arg1, ...);
// DW_AT_inline // DW_AT_inline
default: default:
ctx->log(SEVERITY_DEBUG, "Unknown TAG of function: 0x%X", dwarf_tag(&result)); pst_log(SEVERITY_DEBUG, "Unknown TAG of function: 0x%X", dwarf_tag(&result));
break; break;
} }
} while(dwarf_siblingof(&result, &result) == 0); } while(dwarf_siblingof(&result, &result) == 0);
@@ -449,7 +449,7 @@ bool __pst_function::unwind(Dwarf_Addr addr)
demangle_name = abi::__cxa_demangle(addrname, NULL, NULL, &status); demangle_name = abi::__cxa_demangle(addrname, NULL, NULL, &status);
char* function_name = NULL; char* function_name = NULL;
if(asprintf(&function_name, "%s%s", demangle_name ? demangle_name : addrname, demangle_name ? "" : "()") == -1) { if(asprintf(&function_name, "%s%s", demangle_name ? demangle_name : addrname, demangle_name ? "" : "()") == -1) {
ctx->log(SEVERITY_ERROR, "Failed to allocate memory"); pst_log(SEVERITY_ERROR, "Failed to allocate memory");
return false; return false;
} }
ctx->print(ctx, " --> %s", function_name); ctx->print(ctx, " --> %s", function_name);
@@ -479,14 +479,14 @@ bool __pst_function::get_frame()
cfi = dwfl_module_dwarf_cfi(ctx->module, &mod_bias); cfi = dwfl_module_dwarf_cfi(ctx->module, &mod_bias);
} }
if(!cfi) { if(!cfi) {
ctx->log(SEVERITY_ERROR, "Cannot find CFI for module"); pst_log(SEVERITY_ERROR, "Cannot find CFI for module");
return false; return false;
} }
// get frame of CFI for address // get frame of CFI for address
int result = dwarf_cfi_addrframe (cfi, pc - mod_bias, &frame); int result = dwarf_cfi_addrframe (cfi, pc - mod_bias, &frame);
if (result != 0) { if (result != 0) {
ctx->log(SEVERITY_ERROR, "Failed to find CFI frame for module"); pst_log(SEVERITY_ERROR, "Failed to find CFI frame for module");
return false; return false;
} }
@@ -503,10 +503,10 @@ bool __pst_function::get_frame()
end += mod_bias; end += mod_bias;
reginfo info; info.regno = ra_regno; reginfo info; info.regno = ra_regno;
dwfl_module_register_names(ctx->module, regname_callback, &info); dwfl_module_register_names(ctx->module, regname_callback, &info);
ctx->log(SEVERITY_INFO, "Function %s(...): '.eh/debug frame' info: PC range: => [%#" PRIx64 ", %#" PRIx64 "], return register: %s, in_signal = %s", pst_log(SEVERITY_INFO, "Function %s(...): '.eh/debug frame' info: PC range: => [%#" PRIx64 ", %#" PRIx64 "], return register: %s, in_signal = %s",
name.c_str(), start, end, info.regname, signalp ? "true" : "false"); name.c_str(), start, end, info.regname, signalp ? "true" : "false");
} else { } else {
ctx->log(SEVERITY_WARNING, "Return address register info unavailable (%s)", dwarf_errmsg(0)); pst_log(SEVERITY_WARNING, "Return address register info unavailable (%s)", dwarf_errmsg(0));
} }
// finally get CFA (Canonical Frame Address) // finally get CFA (Canonical Frame Address)
@@ -516,7 +516,7 @@ bool __pst_function::get_frame()
Dwarf_Op *cfa_ops = &dummy; Dwarf_Op *cfa_ops = &dummy;
size_t cfa_nops; size_t cfa_nops;
if(dwarf_frame_cfa(frame, &cfa_ops, &cfa_nops)) { if(dwarf_frame_cfa(frame, &cfa_ops, &cfa_nops)) {
ctx->log(SEVERITY_ERROR, "Failed to get CFA for frame"); pst_log(SEVERITY_ERROR, "Failed to get CFA for frame");
return false; return false;
} }
@@ -524,12 +524,12 @@ bool __pst_function::get_frame()
pst_decl(pst_dwarf_stack, stack, ctx); pst_decl(pst_dwarf_stack, stack, ctx);
if(stack.calc(&stack, cfa_ops, cfa_nops, NULL, this) && stack.get_value(&stack, &cfa)) { if(stack.calc(&stack, cfa_ops, cfa_nops, NULL, this) && stack.get_value(&stack, &cfa)) {
//ctx.sp = v; //ctx.sp = v;
ctx->log(SEVERITY_INFO, "Function %s(...): CFA expression: %s ==> %#lX", name.c_str(), ctx->buff, cfa); pst_log(SEVERITY_INFO, "Function %s(...): CFA expression: %s ==> %#lX", name.c_str(), ctx->buff, cfa);
// setup context to match CFA for frame // setup context to match CFA for frame
ctx->cfa = cfa; ctx->cfa = cfa;
} else { } else {
ctx->log(SEVERITY_ERROR, "Failed to calculate CFA expression"); pst_log(SEVERITY_ERROR, "Failed to calculate CFA expression");
} }
pst_dwarf_stack_fini(&stack); pst_dwarf_stack_fini(&stack);
+3 -3
View File
@@ -389,7 +389,7 @@ bool dw_op_mul(pst_dwarf_stack* stack, const dwarf_op_map* map, Dwarf_Word op1,
pst_dwarf_value* value2 = stack->get(stack, 1); pst_dwarf_value* value2 = stack->get(stack, 1);
if(value1 && value2) { if(value1 && value2) {
if(!(value1->type & value2->type)) { if(!(value1->type & value2->type)) {
stack->ctx->log(SEVERITY_ERROR, "Different types of two stack values for operation: %s(%0x%X, %0x%X)", map->op_name, value1->type, value2->type); pst_log(SEVERITY_ERROR, "Different types of two stack values for operation: %s(%0x%X, %0x%X)", map->op_name, value1->type, value2->type);
return false; return false;
} }
@@ -618,7 +618,7 @@ bool dw_op_call_frame_cfa(pst_dwarf_stack* stack, const dwarf_op_map* map, Dwarf
// unw_word_t sp; // unw_word_t sp;
// int ret = unw_get_reg(stack->ctx->curr_frame, UNW_REG_SP, &sp); // int ret = unw_get_reg(stack->ctx->curr_frame, UNW_REG_SP, &sp);
// if(ret) { // if(ret) {
// stack->ctx->log(SEVERITY_ERROR, "%s: failed to get register 0x%X value. Error: %d", __PRETTY_FUNCTION__, UNW_REG_SP, ret); // pst_log(SEVERITY_ERROR, "%s: failed to get register 0x%X value. Error: %d", __PRETTY_FUNCTION__, UNW_REG_SP, ret);
// return false; // return false;
// } // }
@@ -635,7 +635,7 @@ bool dw_op_fbreg(pst_dwarf_stack* stack, const dwarf_op_map* map, Dwarf_Word op1
unw_word_t sp; unw_word_t sp;
// int ret = unw_get_reg(stack->ctx->curr_frame, UNW_REG_SP, &sp); // int ret = unw_get_reg(stack->ctx->curr_frame, UNW_REG_SP, &sp);
// if(ret) { // if(ret) {
// stack->ctx->log(SEVERITY_ERROR, "Failed to get register 0x%X value. Error: %d", __PRETTY_FUNCTION__, UNW_REG_SP, ret); // pst_log(SEVERITY_ERROR, "Failed to get register 0x%X value. Error: %d", __PRETTY_FUNCTION__, UNW_REG_SP, ret);
// return false; // return false;
// } // }
+16 -16
View File
@@ -76,7 +76,7 @@ bool param_handle_type(pst_parameter* param, Dwarf_Attribute* base)
Dwarf_Die ret_die; Dwarf_Die ret_die;
if(!dwarf_formref_die(base, &ret_die)) { if(!dwarf_formref_die(base, &ret_die)) {
logger.log(SEVERITY_ERROR, "Failed to get parameter DIE"); pst_log(SEVERITY_ERROR, "Failed to get parameter DIE");
return false; return false;
} }
@@ -88,7 +88,7 @@ bool param_handle_type(pst_parameter* param, Dwarf_Attribute* base)
if(attr) { if(attr) {
dwarf_formudata(attr, &param->size); dwarf_formudata(attr, &param->size);
} }
logger.log(SEVERITY_DEBUG, "base type '%s'(%lu)", dwarf_diename(&ret_die), param->size); pst_log(SEVERITY_DEBUG, "base type '%s'(%lu)", dwarf_diename(&ret_die), param->size);
param->add_type(dwarf_diename(&ret_die), DW_TAG_base_type); param->add_type(dwarf_diename(&ret_die), DW_TAG_base_type);
param->type = DW_TAG_base_type; param->type = DW_TAG_base_type;
@@ -100,42 +100,42 @@ bool param_handle_type(pst_parameter* param, Dwarf_Attribute* base)
break; break;
} }
case DW_TAG_array_type: case DW_TAG_array_type:
logger.log(SEVERITY_DEBUG, "array type"); pst_log(SEVERITY_DEBUG, "array type");
param->add_type("[]", DW_TAG_array_type); param->add_type("[]", DW_TAG_array_type);
break; break;
case DW_TAG_structure_type: case DW_TAG_structure_type:
logger.log(SEVERITY_DEBUG, "structure type"); pst_log(SEVERITY_DEBUG, "structure type");
param->add_type("struct", DW_TAG_structure_type); param->add_type("struct", DW_TAG_structure_type);
break; break;
case DW_TAG_union_type: case DW_TAG_union_type:
logger.log(SEVERITY_DEBUG, "union type"); pst_log(SEVERITY_DEBUG, "union type");
param->add_type("union", DW_TAG_union_type); param->add_type("union", DW_TAG_union_type);
break; break;
case DW_TAG_class_type: case DW_TAG_class_type:
logger.log(SEVERITY_DEBUG, "class type"); pst_log(SEVERITY_DEBUG, "class type");
param->add_type("class", DW_TAG_class_type); param->add_type("class", DW_TAG_class_type);
break; break;
case DW_TAG_pointer_type: case DW_TAG_pointer_type:
logger.log(SEVERITY_DEBUG, "pointer type"); pst_log(SEVERITY_DEBUG, "pointer type");
param->add_type("*", DW_TAG_pointer_type); param->add_type("*", DW_TAG_pointer_type);
break; break;
case DW_TAG_enumeration_type: case DW_TAG_enumeration_type:
logger.log(SEVERITY_DEBUG, "enumeration type"); pst_log(SEVERITY_DEBUG, "enumeration type");
param->add_type("enum", DW_TAG_enumeration_type); param->add_type("enum", DW_TAG_enumeration_type);
break; break;
case DW_TAG_const_type: case DW_TAG_const_type:
logger.log(SEVERITY_DEBUG, "constant type"); pst_log(SEVERITY_DEBUG, "constant type");
param->add_type("const", DW_TAG_const_type); param->add_type("const", DW_TAG_const_type);
break; break;
case DW_TAG_subroutine_type: case DW_TAG_subroutine_type:
logger.log(SEVERITY_DEBUG, "Skipping subroutine type"); pst_log(SEVERITY_DEBUG, "Skipping subroutine type");
break; break;
case DW_TAG_typedef: case DW_TAG_typedef:
logger.log(SEVERITY_DEBUG, "typedef '%s' type", dwarf_diename(&ret_die)); pst_log(SEVERITY_DEBUG, "typedef '%s' type", dwarf_diename(&ret_die));
param->add_type(dwarf_diename(&ret_die), DW_TAG_typedef); param->add_type(dwarf_diename(&ret_die), DW_TAG_typedef);
break; break;
default: default:
logger.log(SEVERITY_WARNING, "Unknown 0x%X tag type", dwarf_tag(&ret_die)); pst_log(SEVERITY_WARNING, "Unknown 0x%X tag type", dwarf_tag(&ret_die));
break; break;
} }
@@ -189,7 +189,7 @@ bool param_handle_dwarf(pst_parameter* param, Dwarf_Die* result, pst_function* f
dwarf_decl_line(result, (int*)&param->line); dwarf_decl_line(result, (int*)&param->line);
// Get reference to attribute type of the parameter/variable // Get reference to attribute type of the parameter/variable
attr = dwarf_attr(result, DW_AT_type, &attr_mem); attr = dwarf_attr(result, DW_AT_type, &attr_mem);
logger.log(SEVERITY_DEBUG, "---> Handle '%s' %s", param->name, dwarf_tag(result) == DW_TAG_formal_parameter ? "parameter" : "variable"); pst_log(SEVERITY_DEBUG, "---> Handle '%s' %s", param->name, dwarf_tag(result) == DW_TAG_formal_parameter ? "parameter" : "variable");
if(attr) { if(attr) {
param->handle_type(param, attr); param->handle_type(param, attr);
} }
@@ -203,7 +203,7 @@ bool param_handle_dwarf(pst_parameter* param, Dwarf_Die* result, pst_function* f
if(handle_location(param->ctx, attr, &param->location, pc, fun)) { if(handle_location(param->ctx, attr, &param->location, pc, fun)) {
param->has_value = true; param->has_value = true;
} else { } else {
logger.log(SEVERITY_ERROR, "Failed to calculate DW_AT_location expression: %s", param->ctx->buff); pst_log(SEVERITY_ERROR, "Failed to calculate DW_AT_location expression: %s", param->ctx->buff);
return false; return false;
} }
} else if(dwarf_hasattr(result, DW_AT_const_value)) { } else if(dwarf_hasattr(result, DW_AT_const_value)) {
@@ -212,7 +212,7 @@ bool param_handle_dwarf(pst_parameter* param, Dwarf_Die* result, pst_function* f
switch (dwarf_whatform(attr)) { switch (dwarf_whatform(attr)) {
case DW_FORM_string: case DW_FORM_string:
// do nothing for now // do nothing for now
logger.log(SEVERITY_WARNING, "Const value form DW_FORM_string value = %s.", dwarf_formstring(attr)); pst_log(SEVERITY_WARNING, "Const value form DW_FORM_string value = %s.", dwarf_formstring(attr));
break; break;
case DW_FORM_data1: case DW_FORM_data1:
case DW_FORM_data2: case DW_FORM_data2:
@@ -231,7 +231,7 @@ bool param_handle_dwarf(pst_parameter* param, Dwarf_Die* result, pst_function* f
break; break;
} }
if(param->has_value) { if(param->has_value) {
logger.log(SEVERITY_DEBUG, "Parameter constant value: 0x%lX", param->location.value); pst_log(SEVERITY_DEBUG, "Parameter constant value: 0x%lX", param->location.value);
} }
} }
+10 -10
View File
@@ -148,7 +148,7 @@ bool stack_get_value(pst_dwarf_stack* st, uint64_t* value)
// dereference register location // dereference register location
int ret = unw_get_reg(st->ctx->curr_frame, v->value.uint64, value); int ret = unw_get_reg(st->ctx->curr_frame, v->value.uint64, value);
if(ret) { if(ret) {
st->ctx->log(SEVERITY_ERROR, "Failed to get value of register 0x%X. Error: %d", v->value.uint64, ret); pst_log(SEVERITY_ERROR, "Failed to get value of register 0x%X. Error: %d", v->value.uint64, ret);
return false; return false;
} }
} else if(v->type & DWARF_TYPE_MEMORY_LOC) { } else if(v->type & DWARF_TYPE_MEMORY_LOC) {
@@ -183,7 +183,7 @@ bool stack_calc(pst_dwarf_stack* st, Dwarf_Op *exprs, int expr_len, Dwarf_Attrib
for (int i = 0; i < expr_len; i++) { for (int i = 0; i < expr_len; i++) {
const dwarf_op_map* map = find_op_map(exprs[i].atom); const dwarf_op_map* map = find_op_map(exprs[i].atom);
if(!map) { if(!map) {
st->ctx->log(SEVERITY_ERROR, "Unknown operation type 0x%hhX(0x%lX, 0x%lX)", exprs[i].atom, exprs[i].number, exprs[i].number2); pst_log(SEVERITY_ERROR, "Unknown operation type 0x%hhX(0x%lX, 0x%lX)", exprs[i].atom, exprs[i].number, exprs[i].number2);
return false; return false;
} }
@@ -197,7 +197,7 @@ bool stack_calc(pst_dwarf_stack* st, Dwarf_Op *exprs, int expr_len, Dwarf_Attrib
uint64_t regno = *((uint64_t*)v->value.uint64); uint64_t regno = *((uint64_t*)v->value.uint64);
int ret = unw_get_reg(st->ctx->curr_frame, regno, &value); int ret = unw_get_reg(st->ctx->curr_frame, regno, &value);
if(ret) { if(ret) {
st->ctx->log(SEVERITY_ERROR, "Failed to ger value of register 0x%X. Error: %d", regno, ret); pst_log(SEVERITY_ERROR, "Failed to ger value of register 0x%X. Error: %d", regno, ret);
return false; return false;
} }
v->set(v, &value, sizeof(value), DWARF_TYPE_GENERIC); v->set(v, &value, sizeof(value), DWARF_TYPE_GENERIC);
@@ -206,11 +206,11 @@ bool stack_calc(pst_dwarf_stack* st, Dwarf_Op *exprs, int expr_len, Dwarf_Attrib
// handle there because it contains sub-expression of a Location in caller's frame // handle there because it contains sub-expression of a Location in caller's frame
if(map->op_num == DW_OP_GNU_entry_value) { if(map->op_num == DW_OP_GNU_entry_value) {
if(!fun) { if(!fun) {
st->ctx->log(SEVERITY_ERROR, "Cannot calculate DW_OP_GNU_entry_value expression while function is undefined"); pst_log(SEVERITY_ERROR, "Cannot calculate DW_OP_GNU_entry_value expression while function is undefined");
return false; return false;
} }
if(!fun->parent) { if(!fun->parent) {
st->ctx->log(SEVERITY_ERROR, "Function has not parent while calculate DW_OP_GNU_entry_value expression"); pst_log(SEVERITY_ERROR, "Function has not parent while calculate DW_OP_GNU_entry_value expression");
return false; return false;
} }
// This opcode has two operands, the first one is uleb128 length and the second is block of that length, containing either a // This opcode has two operands, the first one is uleb128 length and the second is block of that length, containing either a
@@ -222,7 +222,7 @@ bool stack_calc(pst_dwarf_stack* st, Dwarf_Op *exprs, int expr_len, Dwarf_Attrib
if (dwarf_getlocation(&attr_mem, &expr, &exprlen) == 0) { if (dwarf_getlocation(&attr_mem, &expr, &exprlen) == 0) {
pst_call_site* cs = fun->parent->find_call_site(fun); pst_call_site* cs = fun->parent->find_call_site(fun);
if(!cs) { if(!cs) {
st->ctx->log(SEVERITY_ERROR, "Failed to find call site while calculate DW_OP_GNU_entry_value expression"); pst_log(SEVERITY_ERROR, "Failed to find call site while calculate DW_OP_GNU_entry_value expression");
return false; return false;
} }
pst_dwarf_expr loc; pst_dwarf_expr loc;
@@ -231,7 +231,7 @@ bool stack_calc(pst_dwarf_stack* st, Dwarf_Op *exprs, int expr_len, Dwarf_Attrib
pst_call_site_param* param = cs->find_param(loc); pst_call_site_param* param = cs->find_param(loc);
pst_dwarf_expr_fini(&loc); pst_dwarf_expr_fini(&loc);
if(!param) { if(!param) {
st->ctx->log(SEVERITY_ERROR, "Failed to find call site parameter while calculate DW_OP_GNU_entry_value expression"); pst_log(SEVERITY_ERROR, "Failed to find call site parameter while calculate DW_OP_GNU_entry_value expression");
return false; return false;
} }
@@ -239,18 +239,18 @@ bool stack_calc(pst_dwarf_stack* st, Dwarf_Op *exprs, int expr_len, Dwarf_Attrib
continue; continue;
} else { } else {
st->ctx->log(SEVERITY_ERROR, "Failed to get DW_OP_GNU_entry_value attr location"); pst_log(SEVERITY_ERROR, "Failed to get DW_OP_GNU_entry_value attr location");
nret = false; nret = false;
break; break;
} }
} else { } else {
st->ctx->log(SEVERITY_ERROR, "Failed to get DW_OP_GNU_entry_value attr expression"); pst_log(SEVERITY_ERROR, "Failed to get DW_OP_GNU_entry_value attr expression");
return false; return false;
} }
} }
if(!map->operation(st, map, exprs[i].number, exprs[i].number2)) { if(!map->operation(st, map, exprs[i].number, exprs[i].number2)) {
st->ctx->log(SEVERITY_ERROR, "Failed to calculate %s(0x%lX, 0x%lX) operation", map->op_name, exprs[i].number, exprs[i].number2); pst_log(SEVERITY_ERROR, "Failed to calculate %s(0x%lX, 0x%lX) operation", map->op_name, exprs[i].number, exprs[i].number2);
return false; return false;
} }
+2 -2
View File
@@ -50,12 +50,12 @@ bool handle_location(pst_context* ctx, Dwarf_Attribute* attr, pst_dwarf_expr* lo
ret = stack.calc(&stack, expr, exprlen, attr, fun); ret = stack.calc(&stack, expr, exprlen, attr, fun);
} else { } else {
// Location skipped due to don't match current PC offset // Location skipped due to don't match current PC offset
ctx->log(SEVERITY_DEBUG, "Skip Location list expression: [%d] (low_offset: 0x%" PRIx64 ", high_offset: 0x%" PRIx64 "), \"%s\"", i, start, end, ctx->buff); pst_log(SEVERITY_DEBUG, "Skip Location list expression: [%d] (low_offset: 0x%" PRIx64 ", high_offset: 0x%" PRIx64 "), \"%s\"", i, start, end, ctx->buff);
} }
} }
} else { } else {
ctx->log(SEVERITY_WARNING, "Unknown location attribute form = 0x%X, code = 0x%X, ", attr->form, attr->code); pst_log(SEVERITY_WARNING, "Unknown location attribute form = 0x%X, code = 0x%X, ", attr->form, attr->code);
} }
pst_dwarf_stack_fini(&stack); pst_dwarf_stack_fini(&stack);
+5 -5
View File
@@ -129,23 +129,23 @@ pst_reg_error pst_get_reg(pst_context* ctx, int regno, uint64_t& regval)
ctx->print_expr_block(ops, nops, str, sizeof(str)); ctx->print_expr_block(ops, nops, str, sizeof(str));
dwarf_stack st(ctx); dwarf_stack st(ctx);
if(st.calc_expression(ops, nops, NULL) && st.get_value(regval)) { if(st.calc_expression(ops, nops, NULL) && st.get_value(regval)) {
ctx->log(SEVERITY_DEBUG, "CFI register 0x%X(%s) expression: %s ==> %#lX", regno, reg_map[regno].regname, str, regval); pst_log(SEVERITY_DEBUG, "CFI register 0x%X(%s) expression: %s ==> %#lX", regno, reg_map[regno].regname, str, regval);
return REG_OK; return REG_OK;
} else { } else {
ctx->log(SEVERITY_ERROR, "Failed to calculate register 0x%X(%s) CFI expression %s", regno, reg_map[regno].regname, str); pst_log(SEVERITY_ERROR, "Failed to calculate register 0x%X(%s) CFI expression %s", regno, reg_map[regno].regname, str);
return REG_EXPR_ERROR; return REG_EXPR_ERROR;
} }
} else { } else {
ctx->log(SEVERITY_DEBUG, "CFI expression for register 0x%X(%s) is SAME VALUE", regno, reg_map[regno].regname); pst_log(SEVERITY_DEBUG, "CFI expression for register 0x%X(%s) is SAME VALUE", regno, reg_map[regno].regname);
return REG_SAME; return REG_SAME;
} }
} else { } else {
ctx->log(SEVERITY_DEBUG, "CFI expression for register 0x%X(%s) is UNDEFINED", regno, reg_map[regno].regname); pst_log(SEVERITY_DEBUG, "CFI expression for register 0x%X(%s) is UNDEFINED", regno, reg_map[regno].regname);
return REG_UNDEFINED; return REG_UNDEFINED;
} }
} else { } else {
ctx->log(SEVERITY_ERROR, "Failed to get CFI expression for register 0x%X", regno); pst_log(SEVERITY_ERROR, "Failed to get CFI expression for register 0x%X", regno);
} }
return REG_CFI_ERROR; return REG_CFI_ERROR;
+7 -7
View File
@@ -60,7 +60,7 @@ void FatalSignalHandler(int sig, siginfo_t* info, void* context)
fatal_error_in_progress = 1; fatal_error_in_progress = 1;
logger.log(&logger, SEVERITY_ERROR, "%s signal handled", strsignal(sig)); pst_log(SEVERITY_ERROR, "%s signal handled", strsignal(sig));
bool ret = false; bool ret = false;
pst_handler handler((ucontext_t*)context); pst_handler handler((ucontext_t*)context);
@@ -70,12 +70,12 @@ void FatalSignalHandler(int sig, siginfo_t* info, void* context)
} }
if(ret) { if(ret) {
logger.log(&logger, SEVERITY_INFO, "%s", handler.ctx.buff); pst_log(SEVERITY_INFO, "%s", handler.ctx.buff);
handler.handle_dwarf(); handler.handle_dwarf();
handler.print_dwarf(); handler.print_dwarf();
logger.log(&logger, SEVERITY_INFO, "%s", handler.ctx.buff); pst_log(SEVERITY_INFO, "%s", handler.ctx.buff);
} else { } else {
logger.log(&logger, SEVERITY_ERROR, "No stack trace obtained"); pst_log(SEVERITY_ERROR, "No stack trace obtained");
} }
// comment out line below to prevent coredump // comment out line below to prevent coredump
@@ -98,9 +98,9 @@ void SignalHandler(int sig)
// const char* str_sig = strsignal(sig); // const char* str_sig = strsignal(sig);
// logger->Log(SEVERITY_INFO, "%s received.", str_sig); // logger->Log(SEVERITY_INFO, "%s received.", str_sig);
if(sig == SIGUSR1) { if(sig == SIGUSR1) {
logger.log(&logger, SEVERITY_INFO, "Maintenance mode enabled."); pst_log(SEVERITY_INFO, "Maintenance mode enabled.");
} else if(sig == SIGUSR2) { } else if(sig == SIGUSR2) {
logger.log(&logger, SEVERITY_INFO, "Maintenance mode disabled."); pst_log(SEVERITY_INFO, "Maintenance mode disabled.");
} }
// signal (sig, SIG_DFL); // signal (sig, SIG_DFL);
// raise(sig); // raise(sig);
@@ -177,7 +177,7 @@ void SetSignalHandler(sig_handler_t handler)
limit.rlim_max = 1073741824; limit.rlim_max = 1073741824;
if (setrlimit(RLIMIT_CORE, &limit)) if (setrlimit(RLIMIT_CORE, &limit))
{ {
logger.log(&logger, SEVERITY_DEBUG, "Failed to set limit for core dump file size"); pst_log(SEVERITY_DEBUG, "Failed to set limit for core dump file size");
} }
} }