diff options
Diffstat (limited to 'lldb')
| -rw-r--r-- | lldb/test/lldbutil.py | 73 | ||||
| -rw-r--r-- | lldb/test/python_api/module_section/TestModuleAndSection.py | 6 |
2 files changed, 79 insertions, 0 deletions
diff --git a/lldb/test/lldbutil.py b/lldb/test/lldbutil.py index bdb0290141d..2143b93469b 100644 --- a/lldb/test/lldbutil.py +++ b/lldb/test/lldbutil.py @@ -44,6 +44,26 @@ def disassemble(target, function_or_symbol): 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 @@ def stop_reason_to_str(enum): 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: diff --git a/lldb/test/python_api/module_section/TestModuleAndSection.py b/lldb/test/python_api/module_section/TestModuleAndSection.py index 98a8d08ef05..66f46b8bc97 100644 --- a/lldb/test/python_api/module_section/TestModuleAndSection.py +++ b/lldb/test/python_api/module_section/TestModuleAndSection.py @@ -7,6 +7,7 @@ import re import unittest2 import lldb from lldbtest import * +from lldbutil import symbol_iter, symbol_type_to_str class ModuleAndSectionAPIsTestCase(TestBase): @@ -39,12 +40,17 @@ class ModuleAndSectionAPIsTestCase(TestBase): 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__': |

