define pst_log macro to use global log
This commit is contained in:
@@ -25,7 +25,7 @@ void clean_print(pst_context* ctx) {
|
||||
|
||||
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);
|
||||
int i = 0;
|
||||
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, ...)
|
||||
{
|
||||
logger.log(&logger, severity, fmt);
|
||||
pst_log(severity, fmt);
|
||||
}
|
||||
|
||||
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);
|
||||
} else if(map->op_num == DW_OP_GNU_entry_value) {
|
||||
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;
|
||||
}
|
||||
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(ctx, ") ");
|
||||
} 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;
|
||||
}
|
||||
} 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;
|
||||
}
|
||||
} else if(map->op_num == DW_OP_stack_value) {
|
||||
|
||||
@@ -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
|
||||
attr = dwarf_attr(child, DW_AT_location, &attr_mem);
|
||||
if(!handle_location(site->ctx, attr, ¶m->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);
|
||||
return false;
|
||||
}
|
||||
@@ -127,9 +127,9 @@ bool site_handle_dwarf(pst_call_site* site, Dwarf_Die* child)
|
||||
pst_dwarf_expr_init(&loc);
|
||||
if(handle_location(site->ctx, attr, &loc, pc, NULL)) {
|
||||
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 {
|
||||
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);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -197,7 +197,7 @@ bool __pst_function::handle_lexical_block(Dwarf_Die* result)
|
||||
{
|
||||
case DW_TAG_variable:
|
||||
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;
|
||||
// Also handle DW_TAG_unspecified_parameters (unknown number of arguments i.e. fun(arg1, ...);
|
||||
default:
|
||||
@@ -210,7 +210,7 @@ bool __pst_function::handle_lexical_block(Dwarf_Die* result)
|
||||
if(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;
|
||||
if(dwarf_child (result, &child) == 0) {
|
||||
do {
|
||||
@@ -229,10 +229,10 @@ bool __pst_function::handle_lexical_block(Dwarf_Die* result)
|
||||
handle_call_site(&child);
|
||||
break;
|
||||
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;
|
||||
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;
|
||||
}
|
||||
}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;
|
||||
|
||||
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
|
||||
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) {
|
||||
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
|
||||
@@ -274,13 +274,13 @@ bool __pst_function::handle_call_site(Dwarf_Die* result)
|
||||
pst_dwarf_expr expr(ctx->alloc);
|
||||
if(handle_location(ctx, &attr_mem, expr, pc, this)) {
|
||||
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) {
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -309,7 +309,7 @@ bool __pst_function::handle_dwarf(Dwarf_Die* d)
|
||||
dwarf_lowpc(d, &lowpc);
|
||||
dwarf_highpc(d, &highpc);
|
||||
// } 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;
|
||||
// }
|
||||
|
||||
@@ -317,11 +317,11 @@ bool __pst_function::handle_dwarf(Dwarf_Die* d)
|
||||
unw_get_proc_info(&cursor, &info);
|
||||
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);
|
||||
ctx->print_registers(ctx, 0x0, 0x10);
|
||||
ctx->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(...): CFA: %#lX %s", dwarf_diename(d), parent ? parent->sp : 0, ctx->buff);
|
||||
pst_log(SEVERITY_INFO, "Function %s(...): %s", dwarf_diename(d), ctx->buff);
|
||||
|
||||
// determine function's stack frame base
|
||||
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)) {
|
||||
uint64_t 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 {
|
||||
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 {
|
||||
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);
|
||||
} 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);
|
||||
if(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);
|
||||
}
|
||||
} 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_AT_inline
|
||||
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;
|
||||
}
|
||||
} 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);
|
||||
char* function_name = NULL;
|
||||
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;
|
||||
}
|
||||
ctx->print(ctx, " --> %s", function_name);
|
||||
@@ -479,14 +479,14 @@ bool __pst_function::get_frame()
|
||||
cfi = dwfl_module_dwarf_cfi(ctx->module, &mod_bias);
|
||||
}
|
||||
if(!cfi) {
|
||||
ctx->log(SEVERITY_ERROR, "Cannot find CFI for module");
|
||||
pst_log(SEVERITY_ERROR, "Cannot find CFI for module");
|
||||
return false;
|
||||
}
|
||||
|
||||
// get frame of CFI for address
|
||||
int result = dwarf_cfi_addrframe (cfi, pc - mod_bias, &frame);
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -503,10 +503,10 @@ bool __pst_function::get_frame()
|
||||
end += mod_bias;
|
||||
reginfo info; info.regno = ra_regno;
|
||||
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");
|
||||
} 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)
|
||||
@@ -516,7 +516,7 @@ bool __pst_function::get_frame()
|
||||
Dwarf_Op *cfa_ops = &dummy;
|
||||
size_t 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;
|
||||
}
|
||||
|
||||
@@ -524,12 +524,12 @@ bool __pst_function::get_frame()
|
||||
pst_decl(pst_dwarf_stack, stack, ctx);
|
||||
if(stack.calc(&stack, cfa_ops, cfa_nops, NULL, this) && stack.get_value(&stack, &cfa)) {
|
||||
//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
|
||||
ctx->cfa = cfa;
|
||||
} else {
|
||||
ctx->log(SEVERITY_ERROR, "Failed to calculate CFA expression");
|
||||
pst_log(SEVERITY_ERROR, "Failed to calculate CFA expression");
|
||||
}
|
||||
|
||||
pst_dwarf_stack_fini(&stack);
|
||||
|
||||
@@ -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);
|
||||
if(value1 && value2) {
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -618,7 +618,7 @@ bool dw_op_call_frame_cfa(pst_dwarf_stack* stack, const dwarf_op_map* map, Dwarf
|
||||
// unw_word_t sp;
|
||||
// int ret = unw_get_reg(stack->ctx->curr_frame, UNW_REG_SP, &sp);
|
||||
// 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;
|
||||
// }
|
||||
|
||||
@@ -635,7 +635,7 @@ bool dw_op_fbreg(pst_dwarf_stack* stack, const dwarf_op_map* map, Dwarf_Word op1
|
||||
unw_word_t sp;
|
||||
// int ret = unw_get_reg(stack->ctx->curr_frame, UNW_REG_SP, &sp);
|
||||
// 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;
|
||||
// }
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ bool param_handle_type(pst_parameter* param, Dwarf_Attribute* base)
|
||||
Dwarf_Die 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;
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ bool param_handle_type(pst_parameter* param, Dwarf_Attribute* base)
|
||||
if(attr) {
|
||||
dwarf_formudata(attr, ¶m->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->type = DW_TAG_base_type;
|
||||
|
||||
@@ -100,42 +100,42 @@ bool param_handle_type(pst_parameter* param, Dwarf_Attribute* base)
|
||||
break;
|
||||
}
|
||||
case DW_TAG_array_type:
|
||||
logger.log(SEVERITY_DEBUG, "array type");
|
||||
pst_log(SEVERITY_DEBUG, "array type");
|
||||
param->add_type("[]", DW_TAG_array_type);
|
||||
break;
|
||||
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);
|
||||
break;
|
||||
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);
|
||||
break;
|
||||
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);
|
||||
break;
|
||||
case DW_TAG_pointer_type:
|
||||
logger.log(SEVERITY_DEBUG, "pointer type");
|
||||
pst_log(SEVERITY_DEBUG, "pointer type");
|
||||
param->add_type("*", DW_TAG_pointer_type);
|
||||
break;
|
||||
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);
|
||||
break;
|
||||
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);
|
||||
break;
|
||||
case DW_TAG_subroutine_type:
|
||||
logger.log(SEVERITY_DEBUG, "Skipping subroutine type");
|
||||
pst_log(SEVERITY_DEBUG, "Skipping subroutine type");
|
||||
break;
|
||||
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);
|
||||
break;
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ bool param_handle_dwarf(pst_parameter* param, Dwarf_Die* result, pst_function* f
|
||||
dwarf_decl_line(result, (int*)¶m->line);
|
||||
// Get reference to attribute type of the parameter/variable
|
||||
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) {
|
||||
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, ¶m->location, pc, fun)) {
|
||||
param->has_value = true;
|
||||
} 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;
|
||||
}
|
||||
} 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)) {
|
||||
case DW_FORM_string:
|
||||
// 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;
|
||||
case DW_FORM_data1:
|
||||
case DW_FORM_data2:
|
||||
@@ -231,7 +231,7 @@ bool param_handle_dwarf(pst_parameter* param, Dwarf_Die* result, pst_function* f
|
||||
break;
|
||||
}
|
||||
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
@@ -148,7 +148,7 @@ bool stack_get_value(pst_dwarf_stack* st, uint64_t* value)
|
||||
// dereference register location
|
||||
int ret = unw_get_reg(st->ctx->curr_frame, v->value.uint64, value);
|
||||
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;
|
||||
}
|
||||
} 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++) {
|
||||
const dwarf_op_map* map = find_op_map(exprs[i].atom);
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
int ret = unw_get_reg(st->ctx->curr_frame, regno, &value);
|
||||
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;
|
||||
}
|
||||
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
|
||||
if(map->op_num == DW_OP_GNU_entry_value) {
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
// 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) {
|
||||
pst_call_site* cs = fun->parent->find_call_site(fun);
|
||||
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;
|
||||
}
|
||||
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_dwarf_expr_fini(&loc);
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -239,18 +239,18 @@ bool stack_calc(pst_dwarf_stack* st, Dwarf_Op *exprs, int expr_len, Dwarf_Attrib
|
||||
|
||||
continue;
|
||||
} 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;
|
||||
break;
|
||||
}
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
} else {
|
||||
// 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 {
|
||||
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);
|
||||
|
||||
@@ -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));
|
||||
dwarf_stack st(ctx);
|
||||
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;
|
||||
} 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;
|
||||
}
|
||||
} 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;
|
||||
}
|
||||
} 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;
|
||||
}
|
||||
|
||||
} 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;
|
||||
|
||||
@@ -60,7 +60,7 @@ void FatalSignalHandler(int sig, siginfo_t* info, void* context)
|
||||
|
||||
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;
|
||||
pst_handler handler((ucontext_t*)context);
|
||||
|
||||
@@ -70,12 +70,12 @@ void FatalSignalHandler(int sig, siginfo_t* info, void* context)
|
||||
}
|
||||
|
||||
if(ret) {
|
||||
logger.log(&logger, SEVERITY_INFO, "%s", handler.ctx.buff);
|
||||
pst_log(SEVERITY_INFO, "%s", handler.ctx.buff);
|
||||
handler.handle_dwarf();
|
||||
handler.print_dwarf();
|
||||
logger.log(&logger, SEVERITY_INFO, "%s", handler.ctx.buff);
|
||||
pst_log(SEVERITY_INFO, "%s", handler.ctx.buff);
|
||||
} 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
|
||||
@@ -98,9 +98,9 @@ void SignalHandler(int sig)
|
||||
// const char* str_sig = strsignal(sig);
|
||||
// logger->Log(SEVERITY_INFO, "%s received.", str_sig);
|
||||
if(sig == SIGUSR1) {
|
||||
logger.log(&logger, SEVERITY_INFO, "Maintenance mode enabled.");
|
||||
pst_log(SEVERITY_INFO, "Maintenance mode enabled.");
|
||||
} else if(sig == SIGUSR2) {
|
||||
logger.log(&logger, SEVERITY_INFO, "Maintenance mode disabled.");
|
||||
pst_log(SEVERITY_INFO, "Maintenance mode disabled.");
|
||||
}
|
||||
// signal (sig, SIG_DFL);
|
||||
// raise(sig);
|
||||
@@ -177,7 +177,7 @@ void SetSignalHandler(sig_handler_t handler)
|
||||
limit.rlim_max = 1073741824;
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user