feat: Improved exception handling (#969)

This commit is contained in:
Aure7138 2023-02-10 02:18:12 +08:00 committed by GitHub
parent 94b1917796
commit 53061a98c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 2 deletions

View File

@ -22,13 +22,17 @@ namespace big
exception_code == DBG_PRINTEXCEPTION_WIDE_C) exception_code == DBG_PRINTEXCEPTION_WIDE_C)
return EXCEPTION_CONTINUE_SEARCH; return EXCEPTION_CONTINUE_SEARCH;
LOG(FATAL) << stack_trace(exception_info); stack_trace stack_trace(exception_info);
LOG(FATAL) << stack_trace;
ZyanU64 opcode_address = exception_info->ContextRecord->Rip; ZyanU64 opcode_address = exception_info->ContextRecord->Rip;
ZydisDisassembledInstruction instruction; ZydisDisassembledInstruction instruction;
ZydisDisassembleIntel(ZYDIS_MACHINE_MODE_LONG_64, opcode_address, reinterpret_cast<void*>(opcode_address), 32, &instruction); ZydisDisassembleIntel(ZYDIS_MACHINE_MODE_LONG_64, opcode_address, reinterpret_cast<void*>(opcode_address), 32, &instruction);
exception_info->ContextRecord->Rip += instruction.info.length; if(stack_trace.m_ret_context.Rip)
*exception_info->ContextRecord = stack_trace.m_ret_context;
else
exception_info->ContextRecord->Rip += instruction.info.length;
return EXCEPTION_CONTINUE_EXECUTION; return EXCEPTION_CONTINUE_EXECUTION;
} }

View File

@ -172,6 +172,9 @@ namespace big
break; break;
} }
m_frame_pointers[i] = frame.AddrPC.Offset; m_frame_pointers[i] = frame.AddrPC.Offset;
if (i == 1)
m_ret_context = context;
} }
} }

View File

@ -9,9 +9,12 @@ namespace big
stack_trace(EXCEPTION_POINTERS* exception_info); stack_trace(EXCEPTION_POINTERS* exception_info);
virtual ~stack_trace(); virtual ~stack_trace();
CONTEXT m_ret_context{};
std::string str() const; std::string str() const;
friend std::ostream& operator<< (std::ostream& os, const stack_trace& st); friend std::ostream& operator<< (std::ostream& os, const stack_trace& st);
friend std::ostream& operator<< (std::ostream& os, const stack_trace* st);
private: private:
struct module_info struct module_info
@ -57,4 +60,11 @@ namespace big
return os; return os;
} }
inline std::ostream& operator<< (std::ostream& os, const stack_trace* st)
{
os << st->str();
return os;
}
} }