Skip to content

Commit 8798084

Browse files
committed
[lldb-with-tools] Add disassemble-to-file.
Sometimes it is really useful to be able to dump the disassembly from lldb into a file so that one can work with the disassembly in an editor. The disassemble command in lldb does not provide such facility today. So this lldb function in the lldb toolbox provides such a facility.
1 parent d3f6b87 commit 8798084

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

utils/lldb/lldbToolBox.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77
to the swift checkout.
88
"""
99

10+
import argparse
1011
import os
12+
import shlex
1113
import subprocess
14+
import sys
1215
import tempfile
1316

1417
REPO_BASE = os.path.abspath(os.path.join(__file__, os.pardir, os.pardir,
@@ -52,7 +55,22 @@ def create_swift_disassemble_viewcfg(debugger, command, exec_ctx, result,
5255
p1.stdout.close() # Allow p1 to receive a SIGPIPE if p2 exits.
5356

5457

58+
def disassemble_to_file(debugger, command, exec_ctx, result, internal_dict):
59+
"""This function disassembles the current assembly frame into a file specified
60+
by the user.
61+
"""
62+
parser = argparse.ArgumentParser(prog='disassemble-to-file', description="""
63+
Dump the disassembly of the current frame to the specified file.
64+
""")
65+
parser.add_argument('file', type=argparse.FileType('w'),
66+
default=sys.stdout)
67+
args = parser.parse_args(shlex.split(command))
68+
args.file.write(exec_ctx.frame.disassembly)
69+
70+
5571
def __lldb_init_module(debugger, internal_dict):
5672
import_llvm_dataformatters(debugger)
5773
debugger.HandleCommand('command script add disassemble-asm-cfg '
5874
'-f lldbToolBox.create_swift_disassemble_viewcfg')
75+
debugger.HandleCommand('command script add disassemble-to-file '
76+
'-f lldbToolBox.disassemble_to_file')

0 commit comments

Comments
 (0)