1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 23:07:35 +00:00

UserspaceEmulator: Use the base address of instructions in backtraces

Instead of using SoftCPU::eip() which points at the *next* instruction
most of the time, stash away a "base EIP" so we can use it when making
backtraces. This makes the correct line number show up! :^)
This commit is contained in:
Andreas Kling 2020-07-21 19:00:03 +02:00
parent 5c29f4e326
commit abebec0e04
2 changed files with 8 additions and 6 deletions

View file

@ -167,14 +167,12 @@ int Emulator::exec()
bool trace = false;
while (!m_shutdown) {
u32 base_eip = 0;
if (trace)
base_eip = m_cpu.eip();
m_cpu.save_base_eip();
auto insn = X86::Instruction::from_stream(m_cpu, true, true);
if (trace)
out() << (const void*)base_eip << " \033[33;1m" << insn.to_string(base_eip, &symbol_provider) << "\033[0m";
out() << (const void*)m_cpu.base_eip() << " \033[33;1m" << insn.to_string(m_cpu.base_eip(), &symbol_provider) << "\033[0m";
(m_cpu.*insn.handler())(insn);
@ -190,13 +188,13 @@ int Emulator::exec()
bool Emulator::is_in_malloc_or_free() const
{
return (m_cpu.eip() >= m_malloc_symbol_start && m_cpu.eip() < m_malloc_symbol_end) || (m_cpu.eip() >= m_free_symbol_start && m_cpu.eip() < m_free_symbol_end);
return (m_cpu.base_eip() >= m_malloc_symbol_start && m_cpu.base_eip() < m_malloc_symbol_end) || (m_cpu.base_eip() >= m_free_symbol_start && m_cpu.base_eip() < m_free_symbol_end);
}
Vector<FlatPtr> Emulator::raw_backtrace()
{
Vector<FlatPtr> backtrace;
backtrace.append(m_cpu.eip());
backtrace.append(m_cpu.base_eip());
// FIXME: Maybe do something if the backtrace has uninitialized data in the frame chain.