feat(exception_handler): use single stack_trace instance (#979)
This commit is contained in:
parent
04bae0bc93
commit
0701f63ccf
@ -13,7 +13,8 @@ namespace big
|
||||
{
|
||||
RemoveVectoredExceptionHandler(m_exception_handler);
|
||||
}
|
||||
|
||||
|
||||
inline static stack_trace trace;
|
||||
LONG vectored_exception_handler(EXCEPTION_POINTERS* exception_info)
|
||||
{
|
||||
const auto exception_code = exception_info->ExceptionRecord->ExceptionCode;
|
||||
@ -22,17 +23,14 @@ namespace big
|
||||
exception_code == DBG_PRINTEXCEPTION_WIDE_C)
|
||||
return EXCEPTION_CONTINUE_SEARCH;
|
||||
|
||||
stack_trace stack_trace(exception_info);
|
||||
LOG(FATAL) << stack_trace;
|
||||
trace.new_stack_trace(exception_info);
|
||||
LOG(FATAL) << trace;
|
||||
|
||||
ZyanU64 opcode_address = exception_info->ContextRecord->Rip;
|
||||
ZydisDisassembledInstruction instruction;
|
||||
ZydisDisassembleIntel(ZYDIS_MACHINE_MODE_LONG_64, opcode_address, reinterpret_cast<void*>(opcode_address), 32, &instruction);
|
||||
|
||||
if(stack_trace.m_ret_context.Rip)
|
||||
*exception_info->ContextRecord = stack_trace.m_ret_context;
|
||||
else
|
||||
exception_info->ContextRecord->Rip += instruction.info.length;
|
||||
exception_info->ContextRecord->Rip += instruction.info.length;
|
||||
|
||||
return EXCEPTION_CONTINUE_EXECUTION;
|
||||
}
|
||||
|
@ -5,20 +5,10 @@
|
||||
|
||||
namespace big
|
||||
{
|
||||
stack_trace::stack_trace(EXCEPTION_POINTERS* exception_info) :
|
||||
m_exception_info(exception_info),
|
||||
stack_trace::stack_trace() :
|
||||
m_frame_pointers(32)
|
||||
{
|
||||
static std::mutex m;
|
||||
std::lock_guard lock(m);
|
||||
|
||||
SymInitialize(GetCurrentProcess(), nullptr, true);
|
||||
|
||||
m_dump << exception_code_to_string(exception_info->ExceptionRecord->ExceptionCode) << '\n';
|
||||
dump_module_info();
|
||||
dump_registers();
|
||||
dump_stacktrace();
|
||||
m_dump << "\n--------End of exception--------\n";
|
||||
}
|
||||
|
||||
stack_trace::~stack_trace()
|
||||
@ -26,6 +16,20 @@ namespace big
|
||||
SymCleanup(GetCurrentProcess());
|
||||
}
|
||||
|
||||
void stack_trace::new_stack_trace(EXCEPTION_POINTERS *exception_info)
|
||||
{
|
||||
static std::mutex m;
|
||||
std::lock_guard lock(m);
|
||||
|
||||
m_exception_info = exception_info;
|
||||
|
||||
m_dump << exception_code_to_string(exception_info->ExceptionRecord->ExceptionCode) << '\n';
|
||||
dump_module_info();
|
||||
dump_registers();
|
||||
dump_stacktrace();
|
||||
m_dump << "\n--------End of exception--------\n";
|
||||
}
|
||||
|
||||
std::string stack_trace::str() const
|
||||
{
|
||||
return m_dump.str();
|
||||
@ -172,9 +176,6 @@ namespace big
|
||||
break;
|
||||
}
|
||||
m_frame_pointers[i] = frame.AddrPC.Offset;
|
||||
|
||||
if (i == 1)
|
||||
m_ret_context = context;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,11 +6,10 @@ namespace big
|
||||
class stack_trace
|
||||
{
|
||||
public:
|
||||
stack_trace(EXCEPTION_POINTERS* exception_info);
|
||||
stack_trace();
|
||||
virtual ~stack_trace();
|
||||
|
||||
CONTEXT m_ret_context{};
|
||||
|
||||
void new_stack_trace(EXCEPTION_POINTERS* exception_info);
|
||||
std::string str() const;
|
||||
|
||||
friend std::ostream& operator<< (std::ostream& os, const stack_trace& st);
|
||||
|
Reference in New Issue
Block a user