Skip to content

Commit 9163277

Browse files
authored
Merge pull request #34202 from gottesmm/pr-a0fd6cbd3a716a3d0da4a2673fee297132b16b8d
[lldb-toolbox] Add the ability to disassemble-to-file a specific function from a target without running the target.
2 parents 8b452ac + d3e6ffd commit 9163277

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

utils/lldb/lldbToolBox.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,26 @@ def disassemble_to_file(debugger, command, exec_ctx, result, internal_dict):
7373
by the user.
7474
"""
7575
parser = argparse.ArgumentParser(prog='disassemble-to-file', description="""
76-
Dump the disassembly of the current frame to the specified file.
76+
Dump the disassembly of the current frame or specified function to the
77+
specified file.
7778
""")
7879
parser.add_argument('file', type=argparse.FileType('w'),
7980
default=sys.stdout)
81+
parser.add_argument('-n', dest='func_name', help="""
82+
Function name to disassembly. Frame used if unset.""")
8083
args = parser.parse_args(shlex.split(command))
81-
args.file.write(exec_ctx.frame.disassembly)
84+
if args.func_name is None:
85+
args.file.write(exec_ctx.frame.disassembly)
86+
else:
87+
name = args.func_name
88+
result = exec_ctx.target.FindFunctions(name)
89+
if result is None:
90+
raise RuntimeError('No function with name: {}'.format(name))
91+
if len(result) > 1:
92+
errorStr = 'Matched multiple functions to name: {}'
93+
raise RuntimeError(errorStr.format(name))
94+
f = result[0].GetFunction()
95+
args.file.write(str(f.GetInstructions(exec_ctx.target)) + "\n")
8296

8397

8498
def sequence(debugger, command, exec_ctx, result, internal_dict):

0 commit comments

Comments
 (0)