From f48bf41cbb421af05cc4b9a3cb3dcea7e51cbbdf Mon Sep 17 00:00:00 2001 From: Nikolai Nosov Date: Fri, 24 Jan 2020 14:43:43 +0400 Subject: [PATCH] added print_registers() to context --- framework/common.cpp | 14 ++++++++++++++ framework/common.h | 1 + framework/dwarf_operations.cpp | 2 ++ 3 files changed, 17 insertions(+) diff --git a/framework/common.cpp b/framework/common.cpp index 335669c..3f1e470 100644 --- a/framework/common.cpp +++ b/framework/common.cpp @@ -19,6 +19,8 @@ #include "dwarf_operations.h" extern SC_LogBase* logger; +extern dwarf_reg_map reg_map[]; +extern int regnum; bool dwarf_value::get_int(int64_t& v) { @@ -81,6 +83,18 @@ bool dwarf_value::get_generic(uint64_t& v) return true; } +void __pst_context::print_registers(int from, int to) +{ + for(int i = from; i < regnum && i <= to; ++i) { + unw_word_t regval; + if(!unw_get_reg(curr_frame, reg_map[i].regno, ®val)) { + log(SEVERITY_DEBUG, "%s = %#lX%s", reg_map[i].regname, regval, i != to ? "," : ""); + } else { + log(SEVERITY_DEBUG, "%s = ", reg_map[i].regname); + } + } +} + bool __pst_context::print(const char* fmt, ...) { bool nret = true; diff --git a/framework/common.h b/framework/common.h index 43be94c..4f44715 100644 --- a/framework/common.h +++ b/framework/common.h @@ -23,6 +23,7 @@ typedef struct __pst_context { bool print(const char* fmt, ...); void log(SC_LogSeverity severity, const char*fmt, ...); uint32_t print_expr_block(Dwarf_Op *exprs, int len, char* buff, uint32_t buff_size, Dwarf_Attribute* attr = 0); + void print_registers(int from, int to); ucontext_t* hcontext; // context of signal handler unw_context_t context; // context of stack trace diff --git a/framework/dwarf_operations.cpp b/framework/dwarf_operations.cpp index 80a4df3..dd33ce2 100644 --- a/framework/dwarf_operations.cpp +++ b/framework/dwarf_operations.cpp @@ -85,6 +85,8 @@ dwarf_reg_map reg_map[] = { {0x1f, "XMM14", DW_OP_breg31}, }; +int regnum = sizeof(reg_map) / sizeof(dwarf_reg_map); + // not implemented operations bool dw_op_notimpl(dwarf_stack* stack, const dwarf_op_map* map, Dwarf_Word op1, Dwarf_Word op2) {