8
8
"""
9
9
10
10
import os
11
+ import subprocess
12
+ import tempfile
11
13
12
14
REPO_BASE = os .path .abspath (os .path .join (__file__ , os .pardir , os .pardir ,
13
15
os .pardir , os .pardir ))
@@ -26,5 +28,31 @@ def import_llvm_dataformatters(debugger):
26
28
print ("Loaded LLVM data formatters." )
27
29
28
30
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
+
29
55
def __lldb_init_module (debugger , internal_dict ):
30
56
import_llvm_dataformatters (debugger )
57
+ debugger .HandleCommand ('command script add disassemble-asm-cfg '
58
+ '-f lldbToolBox.create_swift_disassemble_viewcfg' )
0 commit comments