[PowerPC] Collect some CallLowering arguments into a struct. [NFC]
[llvm-project.git] / lldb / utils / test / run-dis.py
blob5df65e85ba1bb7a21fbc1fa4fd472072acbf2f9d
1 #!/usr/bin/env python
3 """
4 Run lldb disassembler on all the binaries specified by a combination of root dir
5 and path pattern.
6 """
8 from __future__ import print_function
10 import os
11 import sys
12 import subprocess
13 import re
14 from optparse import OptionParser
16 # The directory of this Python script as well as the lldb-disasm.py workhorse.
17 scriptPath = None
19 # The root directory for the SDK symbols.
20 root_dir = None
22 # The regular expression pattern to match the desired pathname to the binaries.
23 path_pattern = None
25 # And the re-compiled regular expression object.
26 path_regexp = None
28 # If specified, number of symbols to disassemble for each qualified binary.
29 num_symbols = -1
31 # Command template of the invocation of lldb disassembler.
32 template = '%s/lldb-disasm.py -C "platform select remote-ios" -o "-n" -q -e %s -n %s'
34 # Regular expression for detecting file output for Mach-o binary.
35 mach_o = re.compile('\sMach-O.+binary')
38 def isbinary(path):
39 file_output = subprocess.Popen(["file", path],
40 stdout=subprocess.PIPE).stdout.read()
41 return (mach_o.search(file_output) is not None)
44 def walk_and_invoke(sdk_root, path_regexp, suffix, num_symbols):
45 """Look for matched file and invoke lldb disassembly on it."""
46 global scriptPath
48 for root, dirs, files in os.walk(sdk_root, topdown=False):
49 for name in files:
50 path = os.path.join(root, name)
52 # We're not interested in .h file.
53 if name.endswith(".h"):
54 continue
55 # Neither a symbolically linked file.
56 if os.path.islink(path):
57 continue
59 # We'll be pattern matching based on the path relative to the SDK
60 # root.
61 replaced_path = path.replace(root_dir, "", 1)
62 # Check regular expression match for the replaced path.
63 if not path_regexp.search(replaced_path):
64 continue
65 # If a suffix is specified, check it, too.
66 if suffix and not name.endswith(suffix):
67 continue
68 if not isbinary(path):
69 continue
71 command = template % (
72 scriptPath, path, num_symbols if num_symbols > 0 else 1000)
73 print("Running %s" % (command))
74 os.system(command)
77 def main():
78 """Read the root dir and the path spec, invoke lldb-disasm.py on the file."""
79 global scriptPath
80 global root_dir
81 global path_pattern
82 global path_regexp
83 global num_symbols
85 scriptPath = sys.path[0]
87 parser = OptionParser(usage="""\
88 Run lldb disassembler on all the binaries specified by a combination of root dir
89 and path pattern.
90 """)
91 parser.add_option(
92 '-r',
93 '--root-dir',
94 type='string',
95 action='store',
96 dest='root_dir',
97 help='Mandatory: the root directory for the SDK symbols.')
98 parser.add_option(
99 '-p',
100 '--path-pattern',
101 type='string',
102 action='store',
103 dest='path_pattern',
104 help='Mandatory: regular expression pattern for the desired binaries.')
105 parser.add_option('-s', '--suffix',
106 type='string', action='store', default=None,
107 dest='suffix',
108 help='Specify the suffix of the binaries to look for.')
109 parser.add_option(
110 '-n',
111 '--num-symbols',
112 type='int',
113 action='store',
114 default=-1,
115 dest='num_symbols',
116 help="""The number of symbols to disassemble, if specified.""")
118 opts, args = parser.parse_args()
119 if not opts.root_dir or not opts.path_pattern:
120 parser.print_help()
121 sys.exit(1)
123 # Sanity check the root directory.
124 root_dir = opts.root_dir
125 root_dir = os.path.abspath(root_dir)
126 if not os.path.isdir(root_dir):
127 parser.print_help()
128 sys.exit(1)
130 path_pattern = opts.path_pattern
131 path_regexp = re.compile(path_pattern)
132 suffix = opts.suffix
133 num_symbols = opts.num_symbols
135 print("Root directory for SDK symbols:", root_dir)
136 print("Regular expression for the binaries:", path_pattern)
137 print("Suffix of the binaries to look for:", suffix)
138 print("num of symbols to disassemble:", num_symbols)
140 walk_and_invoke(root_dir, path_regexp, suffix, num_symbols)
143 if __name__ == '__main__':
144 main()