diff options
| author | Johnny Chen <johnny.chen@apple.com> | 2011-03-31 01:06:28 +0000 | 
|---|---|---|
| committer | Johnny Chen <johnny.chen@apple.com> | 2011-03-31 01:06:28 +0000 | 
| commit | 0e43f321b6dd79d522aec2af33f3f793c99ba881 (patch) | |
| tree | 46b00d020a83ed9f0093607892ea5776921008f5 | |
| parent | 47e1e54343db0ea84cafadf31a86cedeea18e031 (diff) | |
| download | bcm5719-llvm-0e43f321b6dd79d522aec2af33f3f793c99ba881.tar.gz bcm5719-llvm-0e43f321b6dd79d522aec2af33f3f793c99ba881.zip  | |
Add a generator to iterate through the code symbols for a given target.
To be modified to take advantage of the new SBSymbol API which checks a symbol for its type.
llvm-svn: 128601
| -rwxr-xr-x | lldb/utils/test/lldb-disasm.py | 39 | 
1 files changed, 38 insertions, 1 deletions
diff --git a/lldb/utils/test/lldb-disasm.py b/lldb/utils/test/lldb-disasm.py index 5f8a8594b8f..4bafc7c2901 100755 --- a/lldb/utils/test/lldb-disasm.py +++ b/lldb/utils/test/lldb-disasm.py @@ -76,8 +76,13 @@ def run_command(ci, cmd, res, echoInput=True, echoOutput=True):              print "run command failed!"              print "run_command error:", res.GetError() +def IsCodeType(symbol): +    """Check whether an SBSymbol represents code.""" +    return True +  def do_lldb_disassembly(lldb_commands, exe, disassemble_options, num_symbols, symbols_to_disassemble): -    import lldb, lldbutil, atexit, re +    import lldb, atexit, re +    from lldbutil import lldb_iter      # Create the debugger instance now.      dbg = lldb.SBDebugger.Create() @@ -102,6 +107,38 @@ def do_lldb_disassembly(lldb_commands, exe, disassemble_options, num_symbols, sy      for cmd in lldb_commands:          run_command(ci, cmd, res) +    # Create a target. +    target = dbg.CreateTarget(exe) +    stream = lldb.SBStream() + +    # Define a generator for the symbols to disassemble. +    def symbol_iter_2(num, symbols, target): +        # If we specify the symbols to disassemble, ignore symbol table dump. +        if symbols: +            for i in range(len(symbols)): +                print "symbol:", symbols[i] +                yield symbols[i] +        else: +            limited = True if num != -1 else False +            if limited: +                count = 0 +            stream = lldb.SBStream() +            for m in lldb_iter(target, 'GetNumModules', 'GetModuleAtIndex'): +                print "module:", m +                for s in lldb_iter(m, 'GetNumSymbols', 'GetSymbolAtIndex'): +                    if limited and count >= num: +                        return +                    print "symbol:", s.GetName() +                    if IsCodeType(s): +                        if limited: +                            count = count + 1 +                        yield s.GetName() +                    #print "start address:", s.GetStartAddress() +                    #print "end address:", s.GetEndAddress() +                    #s.GetDescription(stream) +                    #print "symbol description:", stream.GetData() +                    #stream.Clear() +      # Now issue the file command.      run_command(ci, 'file %s' % exe, res)  | 

