From 1aa19cd3ec09571c9baba0b83625231adcde07bb Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Wed, 12 Nov 2014 12:06:37 +0100 Subject: [PATCH] KDL disassembler: implement symbol lookup The new udis makes it possible to hook a symbol lookup function, so we can get symbol names and offsets instead of raw addresses in call and jump instrucitons. --- .../debugger/disasm/x86/disasm_arch.cpp | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/add-ons/kernel/debugger/disasm/x86/disasm_arch.cpp b/src/add-ons/kernel/debugger/disasm/x86/disasm_arch.cpp index 902ce7d50c..a5b027343d 100644 --- a/src/add-ons/kernel/debugger/disasm/x86/disasm_arch.cpp +++ b/src/add-ons/kernel/debugger/disasm/x86/disasm_arch.cpp @@ -9,6 +9,7 @@ #include #include "disasm_arch.h" +#include "elf.h" #include "udis86.h" @@ -33,6 +34,30 @@ read_next_byte(struct ud*) } +static const char* +resolve_symbol(struct ud*, uint64_t address, int64_t* offset) +{ + const char* symbolName; + addr_t baseAddress; + status_t error; + + if (IS_KERNEL_ADDRESS(address)) { + error = elf_debug_lookup_symbol_address(address, &baseAddress, + &symbolName, NULL, NULL); + } else { + error = elf_debug_lookup_user_symbol_address( + debug_get_debugged_thread()->team, address, &baseAddress, + &symbolName, NULL, NULL); + } + + if (error != B_OK) + return NULL; + + *offset = address - baseAddress; + return symbolName; +} + + static void setup_disassembler(addr_t where) { @@ -42,6 +67,7 @@ setup_disassembler(addr_t where) ud_set_pc(&sUDState, (uint64_t)where); ud_set_syntax(&sUDState, sSyntax); ud_set_vendor(&sUDState, sVendor); + ud_set_sym_resolver(&sUDState, resolve_symbol); } @@ -114,6 +140,7 @@ disasm_arch_init() return B_OK; } + status_t disasm_arch_fini() {