Skip to content

Commit 8414005

Browse files
authored
Merge pull request #14784 from gottesmm/pr-16daafb7b75dbb6b33a774234c44412855965db1
2 parents 4e84693 + e1cc84d commit 8414005

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

utils/lldb/lldb-with-tools.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/bin/bash
22

3-
lldb -O 'command script import "@SWIFT_SOURCE_DIR@/utils/lldb/lldbToolBox.py"' -- $@
3+
lldb -O 'command script import "@SWIFT_SOURCE_DIR@/utils/lldb/lldbToolBox.py"' $@

utils/lldb/lldbToolBox.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
"""
99

1010
import os
11+
import subprocess
12+
import tempfile
1113

1214
REPO_BASE = os.path.abspath(os.path.join(__file__, os.pardir, os.pardir,
1315
os.pardir, os.pardir))
@@ -26,5 +28,31 @@ def import_llvm_dataformatters(debugger):
2628
print("Loaded LLVM data formatters.")
2729

2830

31+
VIEWCFG_PATH = os.path.join(SWIFT_REPO, "utils", "viewcfg")
32+
BLOCKIFYASM_PATH = os.path.join(SWIFT_REPO, "utils", "dev-scripts",
33+
"blockifyasm")
34+
35+
36+
def create_swift_disassemble_viewcfg(debugger, command, exec_ctx, result,
37+
internal_dict):
38+
"""
39+
This function disassembles the current assembly frame into a temporary file
40+
and then uses that temporary file as input to blockifyasm | viewcfg. This
41+
will cause a pdf of the cfg to be opened on Darwin.
42+
"""
43+
d = exec_ctx.frame.Disassemble()
44+
45+
with tempfile.TemporaryFile() as f:
46+
f.write(d)
47+
f.flush()
48+
f.seek(0)
49+
p1 = subprocess.Popen([BLOCKIFYASM_PATH], stdin=f,
50+
stdout=subprocess.PIPE)
51+
subprocess.Popen([VIEWCFG_PATH], stdin=p1.stdout)
52+
p1.stdout.close() # Allow p1 to receive a SIGPIPE if p2 exits.
53+
54+
2955
def __lldb_init_module(debugger, internal_dict):
3056
import_llvm_dataformatters(debugger)
57+
debugger.HandleCommand('command script add disassemble-asm-cfg '
58+
'-f lldbToolBox.create_swift_disassemble_viewcfg')

0 commit comments

Comments
 (0)