move out value retrieval from expression evaluation. add get_value()

This commit is contained in:
2020-01-14 11:48:08 +04:00
parent 6b43827894
commit 5ee3935dc2
3 changed files with 59 additions and 28 deletions
+22 -19
View File
@@ -180,6 +180,27 @@ uint32_t __pst_context::print_expr_block (Dwarf_Op *exprs, int len, char* buff,
return offset;
}
bool __pst_context::get_value(uint64_t& value)
{
if(!stack.Size()) {
return false;
}
value = 0;
dwarf_value* v = stack.get();
v->get_uint(value);
if(v->type & DWARF_TYPE_REGISTER_LOC) {
// dereference register location
uint64_t regno = value;
if(unw_get_reg(&cursor, regno, &value)) {
log(SEVERITY_ERROR, "Failed to get value of register 0x%lX", regno);
return false;
}
}
return true;
}
bool __pst_context::calc_expression(Dwarf_Op *exprs, int expr_len, Dwarf_Attribute* attr)
{
stack.clear();
@@ -217,6 +238,7 @@ bool __pst_context::calc_expression(Dwarf_Op *exprs, int expr_len, Dwarf_Attribu
log(SEVERITY_ERROR, "Failed to calculate sub-expression for operation %s(0x%lX, 0x%lX)", map->op_name, exprs[i].number, exprs[i].number2);
return false;
}
continue;
} else {
log(SEVERITY_ERROR, "Failed to get DW_OP_GNU_entry_value attr location");
}
@@ -232,25 +254,6 @@ bool __pst_context::calc_expression(Dwarf_Op *exprs, int expr_len, Dwarf_Attribu
}
if(stack.Size()) {
unw_word_t value = 0;
dwarf_value* v = stack.get();
v->get_uint(value);
if(v->type & DWARF_TYPE_REGISTER_LOC) {
// dereference register location
uint64_t regno = value;
if(unw_get_reg(&cursor, regno, &value)) {
log(SEVERITY_ERROR, "Failed to get value of register 0x%lX", regno);
return false;
}
}
log(SEVERITY_INFO, "Found 0x%X value of location expression", value);
return true;
} else {
log(SEVERITY_ERROR, "No value found for location expression");
return false;
}
return true;
}