feat: Improved exception handling (#969)

This commit is contained in:
Aure7138 2023-02-10 02:18:12 +08:00 committed by GitHub
parent e1dd616733
commit 37a10a7181
3 changed files with 19 additions and 2 deletions

View File

@ -22,13 +22,17 @@ namespace big
exception_code == DBG_PRINTEXCEPTION_WIDE_C)
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;
ZydisDisassembledInstruction 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;
}

View File

@ -172,6 +172,9 @@ namespace big
break;
}
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);
virtual ~stack_trace();
CONTEXT m_ret_context{};
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);
private:
struct module_info
@ -57,4 +60,11 @@ namespace big
return os;
}
inline std::ostream& operator<< (std::ostream& os, const stack_trace* st)
{
os << st->str();
return os;
}
}