all code except of pst_function & pst_handler rewritten on C language.

Logger nad Allocator decided to be a global for all library
This commit is contained in:
2020-02-01 15:19:55 +04:00
parent fcdb15ba95
commit 8251ba526f
30 changed files with 2073 additions and 2068 deletions
+17 -28
View File
@@ -15,51 +15,40 @@
#include <elfutils/libdwfl.h>
#include "logger/log.h"
#include "allocator.h"
extern pst_log logger; // logger for whole PST library
extern pst_allocator allocator; // custom allocator for PS library
typedef struct __pst_context {
__pst_context(ucontext_t* hctx) : hcontext(hctx)
{
clean_print();
base_addr = 0;
sp = 0;
cfa = 0;
curr_frame = NULL;
frame = NULL;
dwfl = NULL;
module = NULL;
}
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);
void print_stack(int max, uint64_t next_cfa);
void clean_print() {
buff[0] = 0;
offset = 0;
}
const char* get_print() {
return buff;
}
// methods
void (*clean_print) (__pst_context* ctx);
bool (*print) (__pst_context* ctx, const char* fmt, ...);
void (*log) (SC_LogSeverity severity, const char*fmt, ...);
bool (*print_expr) (__pst_context* ctx, Dwarf_Op *exprs, int exprlen, Dwarf_Attribute* attr);
void (*print_registers) (__pst_context* ctx, int from, int to);
void (*print_stack) (__pst_context* ctx, int max, uint64_t next_cfa);
// fields
ucontext_t* hcontext; // context of signal handler
unw_context_t context; // context of stack trace
unw_cursor_t cursor;
unw_cursor_t cursor; // libunwind stack frame storage
unw_cursor_t* curr_frame; // callee libunwind frame
Dwarf_Addr base_addr; // base address where process loaded
Dwarf_Addr sp; // stack pointer of currently processed stack frame
Dwarf_Addr cfa; // CFA (Canonical Frame Address) of currently processed stack
Dwarf_Addr cfa; // CFA (Canonical Frame Address) of currently processed stack frame
Dwarf_Frame* frame; // currently examined libdwfl frame
Dwfl* dwfl; // DWARF context
Dwfl_Module* module; // currently processed CU
protected:
// print buffer
char buff[8192]; // stack trace buffer
uint32_t offset; // offset in the 'buff'
} pst_context;
void pst_context_init(pst_context* ctx, ucontext_t* hctx);
void pst_context_fini(pst_context* ctx);
#endif /* FRAMEWORK_CONTEXT_H_ */