[Lldb-commits] [lldb] r138002 - /lldb/trunk/utils/test/lldb-disasm.py

Johnny Chen johnny.chen at apple.com
Thu Aug 18 15:46:50 PDT 2011


Author: johnny
Date: Thu Aug 18 17:46:50 2011
New Revision: 138002

URL: http://llvm.org/viewvc/llvm-project?rev=138002&view=rev
Log:
Add an option (-p regexp-pattern) to specify the regular expression symbol pattern we're interested in disassembling.

An example:

utils/test/lldb-disasm.py -C "platform select remote-ios" -o "-b -n" -e '~/CoreFoundation' -n 20 -p '-\[NSArray .+\]'

disassembles the first 20 NSArray instance methods found in the CoreFoundation module.

Modified:
    lldb/trunk/utils/test/lldb-disasm.py

Modified: lldb/trunk/utils/test/lldb-disasm.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/utils/test/lldb-disasm.py?rev=138002&r1=138001&r2=138002&view=diff
==============================================================================
--- lldb/trunk/utils/test/lldb-disasm.py (original)
+++ lldb/trunk/utils/test/lldb-disasm.py Thu Aug 18 17:46:50 2011
@@ -6,6 +6,7 @@
 """
 
 import os
+import re
 import sys
 from optparse import OptionParser
 
@@ -76,7 +77,10 @@
             print "run command failed!"
             print "run_command error:", res.GetError()
 
-def do_lldb_disassembly(lldb_commands, exe, disassemble_options, num_symbols, symbols_to_disassemble, quiet_disassembly):
+def do_lldb_disassembly(lldb_commands, exe, disassemble_options, num_symbols,
+                        symbols_to_disassemble,
+                        re_symbol_pattern,
+                        quiet_disassembly):
     import lldb, atexit, re
 
     # Create the debugger instance now.
@@ -115,7 +119,7 @@
         return symbol.GetType() == lldb.eSymbolTypeCode
 
     # Define a generator for the symbols to disassemble.
-    def symbol_iter(num, symbols, target, verbose):
+    def symbol_iter(num, symbols, re_symbol_pattern, target, verbose):
         # If we specify the symbols to disassemble, ignore symbol table dump.
         if symbols:
             for i in range(len(symbols)):
@@ -125,12 +129,20 @@
             limited = True if num != -1 else False
             if limited:
                 count = 0
+            pattern = re.compile(re_symbol_pattern)
             stream = lldb.SBStream()
             for m in target.module_iter():
                 print "module:", m
                 for s in m:
                     if limited and count >= num:
                         return
+                    # If a regexp symbol pattern is supplied, consult it.
+                    if re_symbol_pattern:
+                        # If the pattern does not match, look for the next symbol.
+                        if not pattern.match(s.GetName()):
+                            continue
+
+                    # If we come here, we're ready to disassemble the symbol.
                     print "symbol:", s.GetName()
                     if IsCodeType(s):
                         if limited:
@@ -146,7 +158,7 @@
                         stream.Clear()
 
     # Disassembly time.
-    for symbol in symbol_iter(num_symbols, symbols_to_disassemble, target, not quiet_disassembly):
+    for symbol in symbol_iter(num_symbols, symbols_to_disassemble, re_symbol_pattern, target, not quiet_disassembly):
         cmd = "disassemble %s '%s'" % (disassemble_options, symbol)
         run_command(ci, cmd, res, True, not quiet_disassembly)
 
@@ -174,14 +186,18 @@
                       type='string', action='store',
                       dest='disassemble_options',
                       help="""Mandatory: the options passed to lldb's 'disassemble' command.""")
-    parser.add_option('-n', '--num-symbols',
-                      type='int', action='store', default=-1,
-                      dest='num_symbols',
-                      help="""The number of symbols to disassemble, if specified.""")
     parser.add_option('-q', '--quiet-disassembly',
                       action='store_true', default=False,
                       dest='quiet_disassembly',
                       help="""The symbol(s) to invoke lldb's 'disassemble' command on, if specified.""")
+    parser.add_option('-n', '--num-symbols',
+                      type='int', action='store', default=-1,
+                      dest='num_symbols',
+                      help="""The number of symbols to disassemble, if specified.""")
+    parser.add_option('-p', '--symbol_pattern',
+                      type='string', action='store',
+                      dest='re_symbol_pattern',
+                      help="""The regular expression of symbols to invoke lldb's 'disassemble' command.""")
     parser.add_option('-s', '--symbol',
                       type='string', action='append', metavar='SYMBOL', default=[],
                       dest='symbols_to_disassemble',
@@ -197,22 +213,25 @@
 
     executable = opts.executable
     disassemble_options = opts.disassemble_options
-    num_symbols = opts.num_symbols
     quiet_disassembly = opts.quiet_disassembly
+    num_symbols = opts.num_symbols
     symbols_to_disassemble = opts.symbols_to_disassemble
+    re_symbol_pattern = opts.re_symbol_pattern
 
     # We have parsed the options.
     print "lldb commands:", lldb_commands
     print "executable:", executable
     print "disassemble options:", disassemble_options
-    print "num of symbols to disassemble:", num_symbols
     print "quiet disassembly output:", quiet_disassembly
+    print "num of symbols to disassemble:", num_symbols
     print "symbols to disassemble:", symbols_to_disassemble
+    print "regular expression of symbols to disassemble:", re_symbol_pattern
 
     setupSysPath()
     do_lldb_disassembly(lldb_commands, executable, disassemble_options,
                         num_symbols,
                         symbols_to_disassemble,
+                        re_symbol_pattern,
                         quiet_disassembly)
 
 if __name__ == '__main__':





More information about the lldb-commits mailing list