[Lldb-commits] [lldb] r140669 - in /lldb/trunk/test: lldbutil.py python_api/module_section/TestModuleAndSection.py

Johnny Chen johnny.chen at apple.com
Tue Sep 27 17:51:00 PDT 2011


Author: johnny
Date: Tue Sep 27 19:51:00 2011
New Revision: 140669

URL: http://llvm.org/viewvc/llvm-project?rev=140669&view=rev
Log:
Add a test sequence of iterating through a module's symbols belonging to a section.
Add the relevant utility functions to the lldbutil.py file.

Modified:
    lldb/trunk/test/lldbutil.py
    lldb/trunk/test/python_api/module_section/TestModuleAndSection.py

Modified: lldb/trunk/test/lldbutil.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lldbutil.py?rev=140669&r1=140668&r2=140669&view=diff
==============================================================================
--- lldb/trunk/test/lldbutil.py (original)
+++ lldb/trunk/test/lldbutil.py Tue Sep 27 19:51:00 2011
@@ -44,6 +44,26 @@
         print >> buf, i
     return buf.getvalue()
 
+# ======================================================
+# Utilities for iterating a module's section for symbols
+# ======================================================
+
+def in_range(symbol, section):
+    symSA = symbol.GetStartAddress().GetFileAddress()
+    symEA = symbol.GetEndAddress().GetFileAddress()
+    secSA = section.GetFileAddress()
+    secEA = secSA + section.GetByteSize()
+    if (secSA <= symSA and symEA < secEA):
+        return True
+    else:
+        return False
+
+def symbol_iter(module, section):
+    """Given a module and its contained section, returns an iterator on the
+    symbols within the section."""
+    for sym in module:
+        if in_range(sym, section):
+            yield sym
 
 # ==========================================================
 # Integer (byte size 1, 2, 4, and 8) to bytearray conversion
@@ -184,6 +204,59 @@
     else:
         raise Exception("Unknown StopReason enum")
 
+def symbol_type_to_str(enum):
+    """Returns the symbolType string given an enum."""
+    if enum == lldb.eSymbolTypeInvalid:
+        return "invalid"
+    elif enum == lldb.eSymbolTypeAbsolute:
+        return "absolute"
+    elif enum == lldb.eSymbolTypeExtern:
+        return "extern"
+    elif enum == lldb.eSymbolTypeCode:
+        return "code"
+    elif enum == lldb.eSymbolTypeData:
+        return "data"
+    elif enum == lldb.eSymbolTypeTrampoline:
+        return "trampoline"
+    elif enum == lldb.eSymbolTypeRuntime:
+        return "runtime"
+    elif enum == lldb.eSymbolTypeException:
+        return "exception"
+    elif enum == lldb.eSymbolTypeSourceFile:
+        return "sourcefile"
+    elif enum == lldb.eSymbolTypeHeaderFile:
+        return "headerfile"
+    elif enum == lldb.eSymbolTypeObjectFile:
+        return "objectfile"
+    elif enum == lldb.eSymbolTypeCommonBlock:
+        return "commonblock"
+    elif enum == lldb.eSymbolTypeBlock:
+        return "block"
+    elif enum == lldb.eSymbolTypeLocal:
+        return "local"
+    elif enum == lldb.eSymbolTypeParam:
+        return "param"
+    elif enum == lldb.eSymbolTypeVariable:
+        return "variable"
+    elif enum == lldb.eSymbolTypeVariableType:
+        return "variabletype"
+    elif enum == lldb.eSymbolTypeLineEntry:
+        return "lineentry"
+    elif enum == lldb.eSymbolTypeLineHeader:
+        return "lineheader"
+    elif enum == lldb.eSymbolTypeScopeBegin:
+        return "scopebegin"
+    elif enum == lldb.eSymbolTypeScopeEnd:
+        return "scopeend"
+    elif enum == lldb.eSymbolTypeAdditional:
+        return "additional"
+    elif enum == lldb.eSymbolTypeCompiler:
+        return "compiler"
+    elif enum == lldb.eSymbolTypeInstrumentation:
+        return "instrumentation"
+    elif enum == lldb.eSymbolTypeUndefined:
+        return "undefined"
+
 def value_type_to_str(enum):
     """Returns the valueType string given an enum."""
     if enum == lldb.eValueTypeInvalid:

Modified: lldb/trunk/test/python_api/module_section/TestModuleAndSection.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/module_section/TestModuleAndSection.py?rev=140669&r1=140668&r2=140669&view=diff
==============================================================================
--- lldb/trunk/test/python_api/module_section/TestModuleAndSection.py (original)
+++ lldb/trunk/test/python_api/module_section/TestModuleAndSection.py Tue Sep 27 19:51:00 2011
@@ -7,6 +7,7 @@
 import unittest2
 import lldb
 from lldbtest import *
+from lldbutil import symbol_iter, symbol_type_to_str
 
 class ModuleAndSectionAPIsTestCase(TestBase):
 
@@ -39,12 +40,17 @@
         print "Exe module: %s" % repr(exe_module)
         print "Number of sections: %d" % exe_module.GetNumSections()
         INDENT = ' ' * 4
+        INDENT2 = INDENT * 2
         for sec in exe_module.section_iter():
             print sec
             if sec.GetName() == "__TEXT":
                 print INDENT + "Number of subsections: %d" % sec.GetNumSubSections()
                 for subsec in sec:
                     print INDENT + repr(subsec)
+                    # Now print the symbols belonging to the subsection....
+                    for sym in symbol_iter(exe_module, subsec):
+                        print INDENT2 + repr(sym)
+                        print INDENT2 + "symbol type: %s" % symbol_type_to_str(sym.GetType())
 
 
 if __name__ == '__main__':





More information about the lldb-commits mailing list