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