1import lldb 2 3 4def disassemble(debugger, command, result, dict): 5 if lldb.frame.function: 6 instructions = lldb.frame.function.instructions 7 start_addr = lldb.frame.function.addr.load_addr 8 name = lldb.frame.function.name 9 elif lldb.frame.symbol: 10 instructions = lldb.frame.symbol.instructions 11 start_addr = lldb.frame.symbol.addr.load_addr 12 name = lldb.frame.symbol.name 13 14 for inst in instructions: 15 inst_addr = inst.addr.load_addr 16 inst_offset = inst_addr - start_addr 17 comment = inst.comment 18 if comment: 19 print("<%s + %-4u> 0x%x %8s %s ; %s" % (name, inst_offset, inst_addr, inst.mnemonic, inst.operands, comment)) 20 else: 21 print("<%s + %-4u> 0x%x %8s %s" % (name, inst_offset, inst_addr, inst.mnemonic, inst.operands)) 22 23# Install the command when the module gets imported 24lldb.debugger.HandleCommand( 25 'command script add -f gdb_disassemble.disassemble gdb-disassemble') 26print('Installed "gdb-disassemble" command for disassembly') 27