[Lldb-commits] [lldb] r176613 - Added new properties to lldb.SBModule classes:
Greg Clayton
gclayton at apple.com
Wed Mar 6 19:25:11 PST 2013
Author: gclayton
Date: Wed Mar 6 21:25:11 2013
New Revision: 176613
URL: http://llvm.org/viewvc/llvm-project?rev=176613&view=rev
Log:
Added new properties to lldb.SBModule classes:
"compile_units" returns an array of all compile units in a module as a list() of lldb.SBCompileUnit objects.
"compile_unit" returns a compile unit accessor object that allows indexed access, search by full or partial path, or by regex:
(lldb) script
comp_unit = lldb.target.module['TextEdit'].compile_unit['Document.m']
comp_unit = lldb.target.module['TextEdit'].compile_unit['/path/to/Document.m']
comp_unit = lldb.target.module['TextEdit'].compile_unit[0]
comp_unit = lldb.target.module['TextEdit'].compile_unit[1]
for comp_unit in lldb.target.module['TextEdit'].compile_unit[re.compile("\.m$")]
print comp_unit
This helps do quick searches and scripting while debugging.
Modified:
lldb/trunk/scripts/Python/interface/SBModule.i
Modified: lldb/trunk/scripts/Python/interface/SBModule.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBModule.i?rev=176613&r1=176612&r2=176613&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/interface/SBModule.i (original)
+++ lldb/trunk/scripts/Python/interface/SBModule.i Wed Mar 6 21:25:11 2013
@@ -282,7 +282,7 @@ public:
%pythoncode %{
class symbols_access(object):
re_compile_type = type(re.compile('.'))
- '''A helper object that will lazily hand out lldb.SBModule objects for a target when supplied an index, or by full or partial path.'''
+ '''A helper object that will lazily hand out lldb.SBSymbol objects for a module when supplied an index, name, or regular expression.'''
def __init__(self, sbmodule):
self.sbmodule = sbmodule
@@ -330,6 +330,10 @@ public:
'''An accessor function that returns a symbols_access() object which allows lazy symbol access from a lldb.SBModule object.'''
return self.symbols_access (self)
+ def get_compile_units_access_object (self):
+ '''An accessor function that returns a compile_units_access() object which allows lazy compile unit access from a lldb.SBModule object.'''
+ return self.compile_units_access (self)
+
def get_symbols_array(self):
'''An accessor function that returns a list() that contains all symbols in a lldb.SBModule object.'''
symbols = []
@@ -339,7 +343,7 @@ public:
class sections_access(object):
re_compile_type = type(re.compile('.'))
- '''A helper object that will lazily hand out lldb.SBModule objects for a target when supplied an index, or by full or partial path.'''
+ '''A helper object that will lazily hand out lldb.SBSection objects for a module when supplied an index, name, or regular expression.'''
def __init__(self, sbmodule):
self.sbmodule = sbmodule
@@ -371,7 +375,47 @@ public:
else:
print "error: unsupported item type: %s" % type(key)
return None
+
+ class compile_units_access(object):
+ re_compile_type = type(re.compile('.'))
+ '''A helper object that will lazily hand out lldb.SBCompileUnit objects for a module when supplied an index, full or partial path, or regular expression.'''
+ def __init__(self, sbmodule):
+ self.sbmodule = sbmodule
+ def __len__(self):
+ if self.sbmodule:
+ return int(self.sbmodule.GetNumCompileUnits())
+ return 0
+
+ def __getitem__(self, key):
+ count = len(self)
+ if type(key) is int:
+ if key < count:
+ return self.sbmodule.GetCompileUnitAtIndex(key)
+ elif type(key) is str:
+ is_full_path = key[0] == '/'
+ for idx in range(count):
+ comp_unit = self.sbmodule.GetCompileUnitAtIndex(idx)
+ if is_full_path:
+ if comp_unit.file.fullpath == key:
+ return comp_unit
+ else:
+ if comp_unit.file.basename == key:
+ return comp_unit
+ elif isinstance(key, self.re_compile_type):
+ matches = []
+ for idx in range(count):
+ comp_unit = self.sbmodule.GetCompileUnitAtIndex(idx)
+ fullpath = comp_unit.file.fullpath
+ if fullpath:
+ re_match = key.search(fullpath)
+ if re_match:
+ matches.append(comp_unit)
+ return matches
+ else:
+ print "error: unsupported item type: %s" % type(key)
+ return None
+
def get_sections_access_object(self):
'''An accessor function that returns a sections_access() object which allows lazy section array access.'''
return self.sections_access (self)
@@ -384,6 +428,14 @@ public:
self.sections_array.append(self.GetSectionAtIndex(idx))
return self.sections_array
+ def get_compile_units_array(self):
+ '''An accessor function that returns an array object that contains all compile_units in this module object.'''
+ if not hasattr(self, 'compile_units_array'):
+ self.compile_units_array = []
+ for idx in range(self.GetNumCompileUnits()):
+ self.compile_units_array.append(self.GetCompileUnitAtIndex(idx))
+ return self.compile_units_array
+
__swig_getmethods__["symbols"] = get_symbols_array
if _newclass: symbols = property(get_symbols_array, None, doc='''A read only property that returns a list() of lldb.SBSymbol objects contained in this module.''')
@@ -392,10 +444,16 @@ public:
__swig_getmethods__["sections"] = get_sections_array
if _newclass: sections = property(get_sections_array, None, doc='''A read only property that returns a list() of lldb.SBSection objects contained in this module.''')
-
+
+ __swig_getmethods__["compile_units"] = get_compile_units_array
+ if _newclass: compile_units = property(get_compile_units_array, None, doc='''A read only property that returns a list() of lldb.SBCompileUnit objects contained in this module.''')
+
__swig_getmethods__["section"] = get_sections_access_object
if _newclass: section = property(get_sections_access_object, None, doc='''A read only property that can be used to access symbols by index ("section = module.section[0]"), name ("sections = module.section[\'main\']"), or using a regular expression ("sections = module.section[re.compile(...)]"). The return value is a single lldb.SBSection object for array access, and a list() of lldb.SBSection objects for name and regular expression access''')
+ __swig_getmethods__["compile_unit"] = get_compile_units_access_object
+ if _newclass: section = property(get_sections_access_object, None, doc='''A read only property that can be used to access compile units by index ("compile_unit = module.compile_unit[0]"), name ("compile_unit = module.compile_unit[\'main.cpp\']"), or using a regular expression ("compile_unit = module.compile_unit[re.compile(...)]"). The return value is a single lldb.SBCompileUnit object for array access or by full or partial path, and a list() of lldb.SBCompileUnit objects regular expressions.''')
+
def get_uuid(self):
return uuid.UUID (self.GetUUIDString())
More information about the lldb-commits
mailing list