llvm-project
35 строк · 1.2 Кб
1import lldb2
3
4def disassemble(debugger, command, result, dict):5if lldb.frame.function:6instructions = lldb.frame.function.instructions7start_addr = lldb.frame.function.addr.load_addr8name = lldb.frame.function.name9elif lldb.frame.symbol:10instructions = lldb.frame.symbol.instructions11start_addr = lldb.frame.symbol.addr.load_addr12name = lldb.frame.symbol.name13
14for inst in instructions:15inst_addr = inst.addr.load_addr16inst_offset = inst_addr - start_addr17comment = inst.comment18if comment:19print(20"<%s + %-4u> 0x%x %8s %s ; %s"21% (name, inst_offset, inst_addr, inst.mnemonic, inst.operands, comment)22)23else:24print(25"<%s + %-4u> 0x%x %8s %s"26% (name, inst_offset, inst_addr, inst.mnemonic, inst.operands)27)28
29
30# Install the command when the module gets imported
31def __lldb_init_module(debugger, internal_dict):32debugger.HandleCommand(33"command script add -o -f gdb_disassemble.disassemble gdb-disassemble"34)35print('Installed "gdb-disassemble" command for disassembly')36