Skip to content

Commit

Permalink
Debugger: Compile on x86_64
Browse files Browse the repository at this point in the history
This is not guaranteed to work at all
  • Loading branch information
Hendiadyoin1 authored and awesomekling committed Jun 30, 2021
1 parent 59eea93 commit 8e575d2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
23 changes: 17 additions & 6 deletions Userland/Applications/Debugger/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,15 @@ static void handle_sigint(int)

static void handle_print_registers(const PtraceRegisters& regs)
{
#if ARCH(I386)
outln("eax={:08x} ebx={:08x} ecx={:08x} edx={:08x}", regs.eax, regs.ebx, regs.ecx, regs.edx);
outln("esp={:08x} ebp={:08x} esi={:08x} edi={:08x}", regs.esp, regs.ebp, regs.esi, regs.edi);
outln("eip={:08x} eflags={:08x}", regs.eip, regs.eflags);
#else
outln("rax={:016x} rbx={:016x} rcx={:016x} rdx={:016x}", regs.rax, regs.rbx, regs.rcx, regs.rdx);
outln("rsp={:016x} rbp={:016x} rsi={:016x} rdi={:016x}", regs.rsp, regs.rbp, regs.rsi, regs.rdi);
outln("rip={:016x} rflags={:08x}", regs.rip, regs.rflags);
#endif
}

static bool handle_disassemble_command(const String& command, void* first_instruction)
Expand Down Expand Up @@ -174,7 +180,7 @@ static bool handle_examine_command(const String& command)
if (!(argument.starts_with("0x"))) {
return false;
}
u32 address = strtoul(argument.characters() + 2, nullptr, 16);
FlatPtr address = strtoul(argument.characters() + 2, nullptr, 16);
auto res = g_debug_session->peek((u32*)address);
if (!res.has_value()) {
outln("Could not examine memory at address {:p}", address);
Expand Down Expand Up @@ -237,10 +243,15 @@ int main(int argc, char** argv)

VERIFY(optional_regs.has_value());
const PtraceRegisters& regs = optional_regs.value();
#if ARCH(I686)
const FlatPtr ip = regs.eip;
#else
const FlatPtr ip = regs.rip;
#endif

auto symbol_at_ip = g_debug_session->symbolicate(regs.eip);
auto symbol_at_ip = g_debug_session->symbolicate(ip);

auto source_position = g_debug_session->get_source_position(regs.eip);
auto source_position = g_debug_session->get_source_position(ip);

if (in_step_line) {
bool no_source_info = !source_position.has_value();
Expand All @@ -254,9 +265,9 @@ int main(int argc, char** argv)
}

if (symbol_at_ip.has_value())
outln("Program is stopped at: {:p} ({}:{})", regs.eip, symbol_at_ip.value().library_name, symbol_at_ip.value().symbol);
outln("Program is stopped at: {:p} ({}:{})", ip, symbol_at_ip.value().library_name, symbol_at_ip.value().symbol);
else
outln("Program is stopped at: {:p}", regs.eip);
outln("Program is stopped at: {:p}", ip);

if (source_position.has_value()) {
previous_source_position = source_position.value();
Expand Down Expand Up @@ -298,7 +309,7 @@ int main(int argc, char** argv)
success = true;

} else if (command.starts_with("dis")) {
success = handle_disassemble_command(command, reinterpret_cast<void*>(regs.eip));
success = handle_disassemble_command(command, reinterpret_cast<void*>(ip));

} else if (command.starts_with("bp")) {
success = handle_breakpoint_command(command);
Expand Down
8 changes: 4 additions & 4 deletions Userland/Libraries/LibX86/Instruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,20 +278,20 @@ enum MMXRegisterIndex {
class LogicalAddress {
public:
LogicalAddress() { }
LogicalAddress(u16 selector, u32 offset)
LogicalAddress(u16 selector, FlatPtr offset)
: m_selector(selector)
, m_offset(offset)
{
}

u16 selector() const { return m_selector; }
u32 offset() const { return m_offset; }
FlatPtr offset() const { return m_offset; }
void set_selector(u16 selector) { m_selector = selector; }
void set_offset(u32 offset) { m_offset = offset; }
void set_offset(FlatPtr offset) { m_offset = offset; }

private:
u16 m_selector { 0 };
u32 m_offset { 0 };
FlatPtr m_offset { 0 };
};

class InstructionStream {
Expand Down

0 comments on commit 8e575d2

Please sign in to comment.