mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 09:27:34 +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:
parent
5c29f4e326
commit
abebec0e04
2 changed files with 8 additions and 6 deletions
|
@ -167,14 +167,12 @@ int Emulator::exec()
|
||||||
bool trace = false;
|
bool trace = false;
|
||||||
|
|
||||||
while (!m_shutdown) {
|
while (!m_shutdown) {
|
||||||
u32 base_eip = 0;
|
m_cpu.save_base_eip();
|
||||||
if (trace)
|
|
||||||
base_eip = m_cpu.eip();
|
|
||||||
|
|
||||||
auto insn = X86::Instruction::from_stream(m_cpu, true, true);
|
auto insn = X86::Instruction::from_stream(m_cpu, true, true);
|
||||||
|
|
||||||
if (trace)
|
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);
|
(m_cpu.*insn.handler())(insn);
|
||||||
|
|
||||||
|
@ -190,13 +188,13 @@ int Emulator::exec()
|
||||||
|
|
||||||
bool Emulator::is_in_malloc_or_free() const
|
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> Emulator::raw_backtrace()
|
||||||
{
|
{
|
||||||
Vector<FlatPtr> 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.
|
// FIXME: Maybe do something if the backtrace has uninitialized data in the frame chain.
|
||||||
|
|
||||||
|
|
|
@ -56,6 +56,9 @@ public:
|
||||||
explicit SoftCPU(Emulator&);
|
explicit SoftCPU(Emulator&);
|
||||||
void dump() const;
|
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; }
|
u32 eip() const { return m_eip; }
|
||||||
void set_eip(u32 eip)
|
void set_eip(u32 eip)
|
||||||
{
|
{
|
||||||
|
@ -981,6 +984,7 @@ private:
|
||||||
bool m_flags_tainted { false };
|
bool m_flags_tainted { false };
|
||||||
|
|
||||||
u32 m_eip { 0 };
|
u32 m_eip { 0 };
|
||||||
|
u32 m_base_eip { 0 };
|
||||||
|
|
||||||
const u8* m_cached_code_ptr { nullptr };
|
const u8* m_cached_code_ptr { nullptr };
|
||||||
const u8* m_cached_code_end { nullptr };
|
const u8* m_cached_code_end { nullptr };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue