1061da546Spatrickimport lldb
2061da546Spatrick
3061da546Spatrick
4061da546Spatrickdef disassemble(debugger, command, result, dict):
5061da546Spatrick    if lldb.frame.function:
6061da546Spatrick        instructions = lldb.frame.function.instructions
7061da546Spatrick        start_addr = lldb.frame.function.addr.load_addr
8061da546Spatrick        name = lldb.frame.function.name
9061da546Spatrick    elif lldb.frame.symbol:
10061da546Spatrick        instructions = lldb.frame.symbol.instructions
11061da546Spatrick        start_addr = lldb.frame.symbol.addr.load_addr
12061da546Spatrick        name = lldb.frame.symbol.name
13061da546Spatrick
14061da546Spatrick    for inst in instructions:
15061da546Spatrick        inst_addr = inst.addr.load_addr
16061da546Spatrick        inst_offset = inst_addr - start_addr
17061da546Spatrick        comment = inst.comment
18061da546Spatrick        if comment:
19061da546Spatrick            print("<%s + %-4u> 0x%x %8s  %s ; %s" % (name, inst_offset, inst_addr, inst.mnemonic, inst.operands, comment))
20061da546Spatrick        else:
21061da546Spatrick            print("<%s + %-4u> 0x%x %8s  %s" % (name, inst_offset, inst_addr, inst.mnemonic, inst.operands))
22061da546Spatrick
23061da546Spatrick# Install the command when the module gets imported
24*f6aab3d8Srobertdef __lldb_init_module(debugger, internal_dict):
25*f6aab3d8Srobert    debugger.HandleCommand(
26*f6aab3d8Srobert        'command script add -o -f gdb_disassemble.disassemble gdb-disassemble')
27061da546Spatrick    print('Installed "gdb-disassemble" command for disassembly')
28