lldb-disasm.py revision b66b112452ea0fc3b920f244912eae2790cfa8b1
1afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen#!/usr/bin/env python
2afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen
3afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen"""
4afd19042fa577feabe14c1b97dd5653e3af567d6Johnny ChenRun lldb to disassemble all the available functions for an executable image.
5afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen
6afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen"""
7afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen
8afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chenimport os
98ddc8020b9ce98a426cc1bc6a1a56d3a3baeb94cJohnny Chenimport re
10afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chenimport sys
11afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chenfrom optparse import OptionParser
12afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen
13afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chendef setupSysPath():
14afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    """
152efc7c6c4e791ed64adf037e4908b598d1f0ec8bJohnny Chen    Add LLDB.framework/Resources/Python and the test dir to the sys.path.
16afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    """
17afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    # Get the directory containing the current script.
18afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    scriptPath = sys.path[0]
19afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    if not scriptPath.endswith(os.path.join('utils', 'test')):
20afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen        print "This script expects to reside in lldb's utils/test directory."
21afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen        sys.exit(-1)
22afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen
23afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    # This is our base name component.
24afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    base = os.path.abspath(os.path.join(scriptPath, os.pardir, os.pardir))
25afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen
26afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    # This is for the goodies in the test directory under base.
27afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    sys.path.append(os.path.join(base,'test'))
28afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen
29afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    # These are for xcode build directories.
30afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    xcode3_build_dir = ['build']
31afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    xcode4_build_dir = ['build', 'lldb', 'Build', 'Products']
32afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    dbg = ['Debug']
33afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    rel = ['Release']
34afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    bai = ['BuildAndIntegration']
35afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    python_resource_dir = ['LLDB.framework', 'Resources', 'Python']
36afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen
37afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    dbgPath  = os.path.join(base, *(xcode3_build_dir + dbg + python_resource_dir))
38afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    dbgPath2 = os.path.join(base, *(xcode4_build_dir + dbg + python_resource_dir))
39afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    relPath  = os.path.join(base, *(xcode3_build_dir + rel + python_resource_dir))
40afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    relPath2 = os.path.join(base, *(xcode4_build_dir + rel + python_resource_dir))
41afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    baiPath  = os.path.join(base, *(xcode3_build_dir + bai + python_resource_dir))
42afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    baiPath2 = os.path.join(base, *(xcode4_build_dir + bai + python_resource_dir))
43afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen
44afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    lldbPath = None
45afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    if os.path.isfile(os.path.join(dbgPath, 'lldb.py')):
46afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen        lldbPath = dbgPath
47afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    elif os.path.isfile(os.path.join(dbgPath2, 'lldb.py')):
48afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen        lldbPath = dbgPath2
49afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    elif os.path.isfile(os.path.join(relPath, 'lldb.py')):
50afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen        lldbPath = relPath
51afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    elif os.path.isfile(os.path.join(relPath2, 'lldb.py')):
52afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen        lldbPath = relPath2
53afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    elif os.path.isfile(os.path.join(baiPath, 'lldb.py')):
54afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen        lldbPath = baiPath
55afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    elif os.path.isfile(os.path.join(baiPath2, 'lldb.py')):
56afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen        lldbPath = baiPath2
57afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen
58afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    if not lldbPath:
59afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen        print 'This script requires lldb.py to be in either ' + dbgPath + ',',
60afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen        print relPath + ', or ' + baiPath
61afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen        sys.exit(-1)
62afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen
63afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    # This is to locate the lldb.py module.  Insert it right after sys.path[0].
64afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    sys.path[1:1] = [lldbPath]
65afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    print "sys.path:", sys.path
66afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen
67afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen
689aaceb1bed6a4f83389c76b1cb7a71f8d22db547Johnny Chendef run_command(ci, cmd, res, echoInput=True, echoOutput=True):
699aaceb1bed6a4f83389c76b1cb7a71f8d22db547Johnny Chen    if echoInput:
709aaceb1bed6a4f83389c76b1cb7a71f8d22db547Johnny Chen        print "run command:", cmd
71afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    ci.HandleCommand(cmd, res)
72afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    if res.Succeeded():
739aaceb1bed6a4f83389c76b1cb7a71f8d22db547Johnny Chen        if echoOutput:
749aaceb1bed6a4f83389c76b1cb7a71f8d22db547Johnny Chen            print "run_command output:", res.GetOutput()
75afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    else:
769aaceb1bed6a4f83389c76b1cb7a71f8d22db547Johnny Chen        if echoOutput:
779aaceb1bed6a4f83389c76b1cb7a71f8d22db547Johnny Chen            print "run command failed!"
789aaceb1bed6a4f83389c76b1cb7a71f8d22db547Johnny Chen            print "run_command error:", res.GetError()
79afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen
808ddc8020b9ce98a426cc1bc6a1a56d3a3baeb94cJohnny Chendef do_lldb_disassembly(lldb_commands, exe, disassemble_options, num_symbols,
818ddc8020b9ce98a426cc1bc6a1a56d3a3baeb94cJohnny Chen                        symbols_to_disassemble,
828ddc8020b9ce98a426cc1bc6a1a56d3a3baeb94cJohnny Chen                        re_symbol_pattern,
838ddc8020b9ce98a426cc1bc6a1a56d3a3baeb94cJohnny Chen                        quiet_disassembly):
847df6fc423f1922ba0700d38e990d8422493184c2Johnny Chen    import lldb, atexit, re
85afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen
86afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    # Create the debugger instance now.
87afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    dbg = lldb.SBDebugger.Create()
88234ebabe6218127a39cbe98dbad7b53f06907becJohnny Chen    if not dbg:
89afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen            raise Exception('Invalid debugger instance')
90afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen
91afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    # Register an exit callback.
92afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    atexit.register(lambda: lldb.SBDebugger.Terminate())
93afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen
94afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    # We want our debugger to be synchronous.
95afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    dbg.SetAsync(False)
96afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen
97afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    # Get the command interpreter from the debugger.
98afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    ci = dbg.GetCommandInterpreter()
99afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    if not ci:
100afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen        raise Exception('Could not get the command interpreter')
101afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen
102afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    # And the associated result object.
103afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    res = lldb.SBCommandReturnObject()
104afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen
105afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    # See if there any extra command(s) to execute before we issue the file command.
106afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    for cmd in lldb_commands:
107afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen        run_command(ci, cmd, res)
108afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen
109563ce6abb47005e3829e5d8fb33c4ed45bda6430Johnny Chen    # Now issue the file command.
110563ce6abb47005e3829e5d8fb33c4ed45bda6430Johnny Chen    run_command(ci, 'file %s' % exe, res)
111563ce6abb47005e3829e5d8fb33c4ed45bda6430Johnny Chen
1127df6fc423f1922ba0700d38e990d8422493184c2Johnny Chen    # Create a target.
113563ce6abb47005e3829e5d8fb33c4ed45bda6430Johnny Chen    #target = dbg.CreateTarget(exe)
114563ce6abb47005e3829e5d8fb33c4ed45bda6430Johnny Chen    target = dbg.GetSelectedTarget()
1157df6fc423f1922ba0700d38e990d8422493184c2Johnny Chen    stream = lldb.SBStream()
1167df6fc423f1922ba0700d38e990d8422493184c2Johnny Chen
117563ce6abb47005e3829e5d8fb33c4ed45bda6430Johnny Chen    def IsCodeType(symbol):
118563ce6abb47005e3829e5d8fb33c4ed45bda6430Johnny Chen        """Check whether an SBSymbol represents code."""
119563ce6abb47005e3829e5d8fb33c4ed45bda6430Johnny Chen        return symbol.GetType() == lldb.eSymbolTypeCode
120563ce6abb47005e3829e5d8fb33c4ed45bda6430Johnny Chen
1217df6fc423f1922ba0700d38e990d8422493184c2Johnny Chen    # Define a generator for the symbols to disassemble.
1228ddc8020b9ce98a426cc1bc6a1a56d3a3baeb94cJohnny Chen    def symbol_iter(num, symbols, re_symbol_pattern, target, verbose):
1237df6fc423f1922ba0700d38e990d8422493184c2Johnny Chen        # If we specify the symbols to disassemble, ignore symbol table dump.
1247df6fc423f1922ba0700d38e990d8422493184c2Johnny Chen        if symbols:
1257df6fc423f1922ba0700d38e990d8422493184c2Johnny Chen            for i in range(len(symbols)):
1267df6fc423f1922ba0700d38e990d8422493184c2Johnny Chen                print "symbol:", symbols[i]
1277df6fc423f1922ba0700d38e990d8422493184c2Johnny Chen                yield symbols[i]
1287df6fc423f1922ba0700d38e990d8422493184c2Johnny Chen        else:
1297df6fc423f1922ba0700d38e990d8422493184c2Johnny Chen            limited = True if num != -1 else False
1307df6fc423f1922ba0700d38e990d8422493184c2Johnny Chen            if limited:
1317df6fc423f1922ba0700d38e990d8422493184c2Johnny Chen                count = 0
132b66b112452ea0fc3b920f244912eae2790cfa8b1Johnny Chen            if re_symbol_pattern:
133b66b112452ea0fc3b920f244912eae2790cfa8b1Johnny Chen                pattern = re.compile(re_symbol_pattern)
1347df6fc423f1922ba0700d38e990d8422493184c2Johnny Chen            stream = lldb.SBStream()
135a3cd9479fb6ffca90d335cb4ca802f4686dd0e10Johnny Chen            for m in target.module_iter():
1367df6fc423f1922ba0700d38e990d8422493184c2Johnny Chen                print "module:", m
137a3cd9479fb6ffca90d335cb4ca802f4686dd0e10Johnny Chen                for s in m:
1387df6fc423f1922ba0700d38e990d8422493184c2Johnny Chen                    if limited and count >= num:
1397df6fc423f1922ba0700d38e990d8422493184c2Johnny Chen                        return
1408ddc8020b9ce98a426cc1bc6a1a56d3a3baeb94cJohnny Chen                    # If a regexp symbol pattern is supplied, consult it.
1418ddc8020b9ce98a426cc1bc6a1a56d3a3baeb94cJohnny Chen                    if re_symbol_pattern:
1428ddc8020b9ce98a426cc1bc6a1a56d3a3baeb94cJohnny Chen                        # If the pattern does not match, look for the next symbol.
1438ddc8020b9ce98a426cc1bc6a1a56d3a3baeb94cJohnny Chen                        if not pattern.match(s.GetName()):
1448ddc8020b9ce98a426cc1bc6a1a56d3a3baeb94cJohnny Chen                            continue
1458ddc8020b9ce98a426cc1bc6a1a56d3a3baeb94cJohnny Chen
1468ddc8020b9ce98a426cc1bc6a1a56d3a3baeb94cJohnny Chen                    # If we come here, we're ready to disassemble the symbol.
1477df6fc423f1922ba0700d38e990d8422493184c2Johnny Chen                    print "symbol:", s.GetName()
1487df6fc423f1922ba0700d38e990d8422493184c2Johnny Chen                    if IsCodeType(s):
1497df6fc423f1922ba0700d38e990d8422493184c2Johnny Chen                        if limited:
1507df6fc423f1922ba0700d38e990d8422493184c2Johnny Chen                            count = count + 1
151d7e532921a938378cceea96a60d4235abe719a1fJohnny Chen                            if verbose:
152d7e532921a938378cceea96a60d4235abe719a1fJohnny Chen                                print "returning symbol:", s.GetName()
1537df6fc423f1922ba0700d38e990d8422493184c2Johnny Chen                        yield s.GetName()
154d7e532921a938378cceea96a60d4235abe719a1fJohnny Chen                    if verbose:
155d7e532921a938378cceea96a60d4235abe719a1fJohnny Chen                        print "start address:", s.GetStartAddress()
156d7e532921a938378cceea96a60d4235abe719a1fJohnny Chen                        print "end address:", s.GetEndAddress()
157d7e532921a938378cceea96a60d4235abe719a1fJohnny Chen                        s.GetDescription(stream)
158d7e532921a938378cceea96a60d4235abe719a1fJohnny Chen                        print "symbol description:", stream.GetData()
159d7e532921a938378cceea96a60d4235abe719a1fJohnny Chen                        stream.Clear()
1607df6fc423f1922ba0700d38e990d8422493184c2Johnny Chen
161337836bbe11dd3543b6c6e236fa161d072181328Johnny Chen    # Disassembly time.
1628ddc8020b9ce98a426cc1bc6a1a56d3a3baeb94cJohnny Chen    for symbol in symbol_iter(num_symbols, symbols_to_disassemble, re_symbol_pattern, target, not quiet_disassembly):
163337836bbe11dd3543b6c6e236fa161d072181328Johnny Chen        cmd = "disassemble %s '%s'" % (disassemble_options, symbol)
164d7e532921a938378cceea96a60d4235abe719a1fJohnny Chen        run_command(ci, cmd, res, True, not quiet_disassembly)
1659aaceb1bed6a4f83389c76b1cb7a71f8d22db547Johnny Chen
166afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen
167afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chendef main():
168afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    # This is to set up the Python path to include the pexpect-2.4 dir.
169afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    # Remember to update this when/if things change.
170afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    scriptPath = sys.path[0]
171afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    sys.path.append(os.path.join(scriptPath, os.pardir, os.pardir, 'test', 'pexpect-2.4'))
172afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen
173afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    parser = OptionParser(usage="""\
174afd19042fa577feabe14c1b97dd5653e3af567d6Johnny ChenRun lldb to disassemble all the available functions for an executable image.
175afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen
176afd19042fa577feabe14c1b97dd5653e3af567d6Johnny ChenUsage: %prog [options]
177afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen""")
178afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    parser.add_option('-C', '--lldb-command',
179afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen                      type='string', action='append', metavar='COMMAND',
180afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen                      default=[], dest='lldb_commands',
181afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen                      help='Command(s) lldb executes after starting up (can be empty)')
182afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    parser.add_option('-e', '--executable',
183afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen                      type='string', action='store',
184afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen                      dest='executable',
1859aaceb1bed6a4f83389c76b1cb7a71f8d22db547Johnny Chen                      help="""Mandatory: the executable to do disassembly on.""")
1869aaceb1bed6a4f83389c76b1cb7a71f8d22db547Johnny Chen    parser.add_option('-o', '--options',
1879aaceb1bed6a4f83389c76b1cb7a71f8d22db547Johnny Chen                      type='string', action='store',
1889aaceb1bed6a4f83389c76b1cb7a71f8d22db547Johnny Chen                      dest='disassemble_options',
1899aaceb1bed6a4f83389c76b1cb7a71f8d22db547Johnny Chen                      help="""Mandatory: the options passed to lldb's 'disassemble' command.""")
190d7e532921a938378cceea96a60d4235abe719a1fJohnny Chen    parser.add_option('-q', '--quiet-disassembly',
191d7e532921a938378cceea96a60d4235abe719a1fJohnny Chen                      action='store_true', default=False,
192d7e532921a938378cceea96a60d4235abe719a1fJohnny Chen                      dest='quiet_disassembly',
193d7e532921a938378cceea96a60d4235abe719a1fJohnny Chen                      help="""The symbol(s) to invoke lldb's 'disassemble' command on, if specified.""")
1948ddc8020b9ce98a426cc1bc6a1a56d3a3baeb94cJohnny Chen    parser.add_option('-n', '--num-symbols',
1958ddc8020b9ce98a426cc1bc6a1a56d3a3baeb94cJohnny Chen                      type='int', action='store', default=-1,
1968ddc8020b9ce98a426cc1bc6a1a56d3a3baeb94cJohnny Chen                      dest='num_symbols',
1978ddc8020b9ce98a426cc1bc6a1a56d3a3baeb94cJohnny Chen                      help="""The number of symbols to disassemble, if specified.""")
1988ddc8020b9ce98a426cc1bc6a1a56d3a3baeb94cJohnny Chen    parser.add_option('-p', '--symbol_pattern',
1998ddc8020b9ce98a426cc1bc6a1a56d3a3baeb94cJohnny Chen                      type='string', action='store',
2008ddc8020b9ce98a426cc1bc6a1a56d3a3baeb94cJohnny Chen                      dest='re_symbol_pattern',
2018ddc8020b9ce98a426cc1bc6a1a56d3a3baeb94cJohnny Chen                      help="""The regular expression of symbols to invoke lldb's 'disassemble' command.""")
202337836bbe11dd3543b6c6e236fa161d072181328Johnny Chen    parser.add_option('-s', '--symbol',
203337836bbe11dd3543b6c6e236fa161d072181328Johnny Chen                      type='string', action='append', metavar='SYMBOL', default=[],
204337836bbe11dd3543b6c6e236fa161d072181328Johnny Chen                      dest='symbols_to_disassemble',
205337836bbe11dd3543b6c6e236fa161d072181328Johnny Chen                      help="""The symbol(s) to invoke lldb's 'disassemble' command on, if specified.""")
206337836bbe11dd3543b6c6e236fa161d072181328Johnny Chen
207afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    opts, args = parser.parse_args()
208afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen
209afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    lldb_commands = opts.lldb_commands
210afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen
2119aaceb1bed6a4f83389c76b1cb7a71f8d22db547Johnny Chen    if not opts.executable or not opts.disassemble_options:
212afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen        parser.print_help()
213afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen        sys.exit(1)
2149aaceb1bed6a4f83389c76b1cb7a71f8d22db547Johnny Chen
215afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    executable = opts.executable
2169aaceb1bed6a4f83389c76b1cb7a71f8d22db547Johnny Chen    disassemble_options = opts.disassemble_options
217d7e532921a938378cceea96a60d4235abe719a1fJohnny Chen    quiet_disassembly = opts.quiet_disassembly
2188ddc8020b9ce98a426cc1bc6a1a56d3a3baeb94cJohnny Chen    num_symbols = opts.num_symbols
219337836bbe11dd3543b6c6e236fa161d072181328Johnny Chen    symbols_to_disassemble = opts.symbols_to_disassemble
2208ddc8020b9ce98a426cc1bc6a1a56d3a3baeb94cJohnny Chen    re_symbol_pattern = opts.re_symbol_pattern
221afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen
222afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    # We have parsed the options.
223afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    print "lldb commands:", lldb_commands
224afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    print "executable:", executable
2259aaceb1bed6a4f83389c76b1cb7a71f8d22db547Johnny Chen    print "disassemble options:", disassemble_options
226d7e532921a938378cceea96a60d4235abe719a1fJohnny Chen    print "quiet disassembly output:", quiet_disassembly
2278ddc8020b9ce98a426cc1bc6a1a56d3a3baeb94cJohnny Chen    print "num of symbols to disassemble:", num_symbols
228337836bbe11dd3543b6c6e236fa161d072181328Johnny Chen    print "symbols to disassemble:", symbols_to_disassemble
2298ddc8020b9ce98a426cc1bc6a1a56d3a3baeb94cJohnny Chen    print "regular expression of symbols to disassemble:", re_symbol_pattern
230afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen
231afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    setupSysPath()
232d7e532921a938378cceea96a60d4235abe719a1fJohnny Chen    do_lldb_disassembly(lldb_commands, executable, disassemble_options,
233d7e532921a938378cceea96a60d4235abe719a1fJohnny Chen                        num_symbols,
234d7e532921a938378cceea96a60d4235abe719a1fJohnny Chen                        symbols_to_disassemble,
2358ddc8020b9ce98a426cc1bc6a1a56d3a3baeb94cJohnny Chen                        re_symbol_pattern,
236d7e532921a938378cceea96a60d4235abe719a1fJohnny Chen                        quiet_disassembly)
237afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen
238afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chenif __name__ == '__main__':
239afd19042fa577feabe14c1b97dd5653e3af567d6Johnny Chen    main()
240