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.
git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@128601 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/utils/test/lldb-disasm.py b/utils/test/lldb-disasm.py
index 5f8a859..4bafc7c 100755
--- a/utils/test/lldb-disasm.py
+++ b/utils/test/lldb-disasm.py
@@ -76,8 +76,13 @@
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 @@
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)