36 lines · python
1import lldb2 3 4def disassemble(debugger, command, result, dict):5 if lldb.frame.function:6 instructions = lldb.frame.function.instructions7 start_addr = lldb.frame.function.addr.load_addr8 name = lldb.frame.function.name9 elif lldb.frame.symbol:10 instructions = lldb.frame.symbol.instructions11 start_addr = lldb.frame.symbol.addr.load_addr12 name = lldb.frame.symbol.name13 14 for inst in instructions:15 inst_addr = inst.addr.load_addr16 inst_offset = inst_addr - start_addr17 comment = inst.comment18 if comment:19 print(20 "<%s + %-4u> 0x%x %8s %s ; %s"21 % (name, inst_offset, inst_addr, inst.mnemonic, inst.operands, comment)22 )23 else:24 print(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 imported31def __lldb_init_module(debugger, internal_dict):32 debugger.HandleCommand(33 "command script add -o -f gdb_disassemble.disassemble gdb-disassemble"34 )35 print('Installed "gdb-disassemble" command for disassembly')36