diff options
author | Andreas Kling <kling@serenityos.org> | 2020-07-21 19:00:03 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-07-21 19:08:01 +0200 |
commit | abebec0e04512254fffe79584066b75077456984 (patch) | |
tree | 76469503cd35a2326024b4d7f43831785192b046 /DevTools/UserspaceEmulator | |
parent | 5c29f4e32612740cdc67537ae5c4ac620f22ac36 (diff) | |
download | serenity-abebec0e04512254fffe79584066b75077456984.zip |
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! :^)
Diffstat (limited to 'DevTools/UserspaceEmulator')
-rw-r--r-- | DevTools/UserspaceEmulator/Emulator.cpp | 10 | ||||
-rw-r--r-- | DevTools/UserspaceEmulator/SoftCPU.h | 4 |
2 files changed, 8 insertions, 6 deletions
diff --git a/DevTools/UserspaceEmulator/Emulator.cpp b/DevTools/UserspaceEmulator/Emulator.cpp index b07aa15e1a..1a2aaee0a7 100644 --- a/DevTools/UserspaceEmulator/Emulator.cpp +++ b/DevTools/UserspaceEmulator/Emulator.cpp @@ -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. diff --git a/DevTools/UserspaceEmulator/SoftCPU.h b/DevTools/UserspaceEmulator/SoftCPU.h index 925a8d46b2..e954873edf 100644 --- a/DevTools/UserspaceEmulator/SoftCPU.h +++ b/DevTools/UserspaceEmulator/SoftCPU.h @@ -56,6 +56,9 @@ public: explicit SoftCPU(Emulator&); void dump() const; + u32 base_eip() const { return m_base_eip; } + void save_base_eip() { m_base_eip = m_eip; } + u32 eip() const { return m_eip; } void set_eip(u32 eip) { @@ -981,6 +984,7 @@ private: bool m_flags_tainted { false }; u32 m_eip { 0 }; + u32 m_base_eip { 0 }; const u8* m_cached_code_ptr { nullptr }; const u8* m_cached_code_end { nullptr }; |