2019-12-08 14:46:48 -08:00
# i f def S W I G P Y T H O N
2019-02-27 14:16:48 +00:00
% p y t h o n c o d e % {
# = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
# H e l p e r function for S B M o d u l e class
# = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
def i n _ r a n g e ( s y m b o l , section ) :
"" "Test whether a symbol is within the range of a section." ""
s y m S A = s y m b o l . G e t S t a r t A d d r e s s ( ) . G e t F i l e A d d r e s s ( )
s y m E A = s y m b o l . G e t E n d A d d r e s s ( ) . G e t F i l e A d d r e s s ( )
s e c S A = section . G e t F i l e A d d r e s s ( )
s e c E A = s e c S A + section . G e t B y t e S i z e ( )
if s y m E A ! = L L D B _ I N V A L I D _ A D D R E S S :
if s e c S A < = s y m S A and s y m E A < = s e c E A :
return True
else :
return False
else :
if s e c S A < = s y m S A and s y m S A < s e c E A :
return True
else :
return False
% }
2019-12-08 14:46:48 -08:00
# e n d i f
2019-02-27 14:16:48 +00:00
2023-01-26 17:33:33 -08:00
S T R I N G _ E X T E N S I O N _ O U T S I D E ( S B M o d u l e )
2020-01-08 16:13:03 -08:00
2023-01-26 17:33:33 -08:00
% e x t e n d l l d b : : S B M o d u l e {
2019-12-08 14:46:48 -08:00
# i f def S W I G P Y T H O N
2012-01-29 06:07:39 +00:00
% p y t h o n c o d e % {
2023-08-31 20:34:56 +01:00
# o p e r a t o r = = is a f r e e function , w h i c h s w i g d o e s not handle , s o w e i n j e c t
# o u r o w n e q u a l i t y o p e r a t o r h e r e
def _ _ e q _ _ ( self , o t h e r ) :
return not self . _ _ n e _ _ ( o t h e r )
2019-04-04 10:13:59 +00:00
def _ _ l e n _ _ ( self ) :
'''Return the number of symbols in a lldb.SBModule object.'''
return self . G e t N u m S y m b o l s ( )
def _ _ i t e r _ _ ( self ) :
'''Iterate over all symbols in a lldb.SBModule object.'''
return l l d b _ i t e r ( self , 'GetNumSymbols', 'GetSymbolAtIndex' )
def s e c t i o n _ i t e r ( self ) :
'''Iterate over all sections in a lldb.SBModule object.'''
return l l d b _ i t e r ( self , 'GetNumSections', 'GetSectionAtIndex' )
def c o m p i l e _ u n i t _ i t e r ( self ) :
'''Iterate over all compile units in a lldb.SBModule object.'''
return l l d b _ i t e r ( self , 'GetNumCompileUnits', 'GetCompileUnitAtIndex' )
def s y m b o l _ i n _ s e c t i o n _ i t e r ( self , section ) :
''' G i v e n a m o d u l e and i t s c o n t a i n e d section , returns a n i t e r a t o r on t h e
s y m b o l s w i t h i n t h e section . '''
for s y m in self :
if i n _ r a n g e ( s y m , section ) :
y i e l d s y m
2012-02-01 08:09:32 +00:00
class s y m b o l s _ a c c e s s ( o b j e c t ) :
2012-02-03 03:22:53 +00:00
r e _ c o m p i l e _ t y p e = type ( r e . compile ( '.' ) )
2013-03-07 03:25:11 +00:00
'''A helper object that will lazily hand out lldb.SBSymbol objects for a module when supplied an index, name, or regular expression.'''
2012-02-01 08:09:32 +00:00
def _ _ i n i t _ _ ( self , s b m o d u l e ) :
self . s b m o d u l e = s b m o d u l e
2019-04-18 16:23:33 +00:00
2012-02-01 08:09:32 +00:00
def _ _ l e n _ _ ( self ) :
if self . s b m o d u l e :
2012-05-11 20:39:42 +00:00
return int ( self . s b m o d u l e . G e t N u m S y m b o l s ( ) )
2012-02-01 08:09:32 +00:00
return 0
2019-04-18 16:23:33 +00:00
2012-02-01 08:09:32 +00:00
def _ _ g e t i t e m _ _ ( self , key ) :
2012-02-03 03:22:53 +00:00
count = l e n ( self )
2012-02-01 08:09:32 +00:00
if type ( key ) is int :
2023-02-03 08:45:44 -08:00
if - c o u n t < = key < count :
key % = count
2012-02-01 08:09:32 +00:00
return self . s b m o d u l e . G e t S y m b o l A t I n d e x ( key )
e l i f type ( key ) is s t r :
matches = [ ]
2012-12-04 02:22:16 +00:00
s c _ l i s t = self . s b m o d u l e . F i n d S y m b o l s ( key )
for s c in s c _ l i s t :
s y m b o l = s c . s y m b o l
if s y m b o l :
2012-02-01 08:09:32 +00:00
matches . append ( s y m b o l )
2012-02-03 03:22:53 +00:00
return matches
e l i f i s i n s t a n c e ( key , self . r e _ c o m p i l e _ t y p e ) :
2012-02-01 08:09:32 +00:00
matches = [ ]
for i d x in r a n g e ( count ) :
s y m b o l = self . s b m o d u l e . G e t S y m b o l A t I n d e x ( i d x )
a d d e d = False
name = s y m b o l . name
if name :
r e _ m a t c h = key . search ( name )
if r e _ m a t c h :
matches . append ( s y m b o l )
a d d e d = True
if not a d d e d :
m a n g l e d = s y m b o l . m a n g l e d
if m a n g l e d :
r e _ m a t c h = key . search ( m a n g l e d )
if r e _ m a t c h :
matches . append ( s y m b o l )
2012-02-03 03:22:53 +00:00
return matches
2012-02-01 08:09:32 +00:00
else :
2015-10-16 17:52:32 +00:00
p r i n t ( "error: unsupported item type: %s" % type ( key ) )
2012-02-01 08:09:32 +00:00
return None
2019-04-18 16:23:33 +00:00
2012-02-01 08:09:32 +00:00
def g e t _ s y m b o l s _ a c c e s s _ o b j e c t ( self ) :
2012-02-03 03:22:53 +00:00
'''An accessor function that returns a symbols_access() object which allows lazy symbol access from a lldb.SBModule object.'''
2012-02-01 08:09:32 +00:00
return self . s y m b o l s _ a c c e s s ( self )
2019-04-18 16:23:33 +00:00
2013-03-07 03:25:11 +00:00
def g e t _ c o m p i l e _ u n i t s _ a c c e s s _ o b j e c t ( self ) :
'''An accessor function that returns a compile_units_access() object which allows lazy compile unit access from a lldb.SBModule object.'''
return self . c o m p i l e _ u n i t s _ a c c e s s ( self )
2019-04-18 16:23:33 +00:00
2012-02-01 08:09:32 +00:00
def g e t _ s y m b o l s _ a r r a y ( self ) :
2012-02-03 03:22:53 +00:00
'''An accessor function that returns a list() that contains all symbols in a lldb.SBModule object.'''
2012-02-01 08:09:32 +00:00
s y m b o l s = [ ]
2012-02-03 03:22:53 +00:00
for i d x in r a n g e ( self . n u m _ s y m b o l s ) :
2012-02-01 08:09:32 +00:00
s y m b o l s . append ( self . G e t S y m b o l A t I n d e x ( i d x ) )
return s y m b o l s
2012-02-03 03:22:53 +00:00
class s e c t i o n s _ a c c e s s ( o b j e c t ) :
r e _ c o m p i l e _ t y p e = type ( r e . compile ( '.' ) )
2013-03-07 03:25:11 +00:00
'''A helper object that will lazily hand out lldb.SBSection objects for a module when supplied an index, name, or regular expression.'''
2012-02-03 03:22:53 +00:00
def _ _ i n i t _ _ ( self , s b m o d u l e ) :
self . s b m o d u l e = s b m o d u l e
2019-04-18 16:23:33 +00:00
2012-02-03 03:22:53 +00:00
def _ _ l e n _ _ ( self ) :
if self . s b m o d u l e :
2012-05-11 20:39:42 +00:00
return int ( self . s b m o d u l e . G e t N u m S e c t i o n s ( ) )
2012-02-03 03:22:53 +00:00
return 0
2019-04-18 16:23:33 +00:00
2012-02-03 03:22:53 +00:00
def _ _ g e t i t e m _ _ ( self , key ) :
count = l e n ( self )
if type ( key ) is int :
2023-02-03 08:45:44 -08:00
if - c o u n t < = key < count :
key % = count
2012-02-03 03:22:53 +00:00
return self . s b m o d u l e . G e t S e c t i o n A t I n d e x ( key )
e l i f type ( key ) is s t r :
for i d x in r a n g e ( count ) :
section = self . s b m o d u l e . G e t S e c t i o n A t I n d e x ( i d x )
if section . name = = key :
2012-02-04 02:58:17 +00:00
return section
2012-02-03 03:22:53 +00:00
e l i f i s i n s t a n c e ( key , self . r e _ c o m p i l e _ t y p e ) :
matches = [ ]
for i d x in r a n g e ( count ) :
section = self . s b m o d u l e . G e t S e c t i o n A t I n d e x ( i d x )
name = section . name
if name :
r e _ m a t c h = key . search ( name )
if r e _ m a t c h :
matches . append ( section )
return matches
else :
2015-10-16 17:52:32 +00:00
p r i n t ( "error: unsupported item type: %s" % type ( key ) )
2012-02-03 03:22:53 +00:00
return None
2013-03-07 03:25:11 +00:00
class c o m p i l e _ u n i t s _ a c c e s s ( o b j e c t ) :
r e _ c o m p i l e _ t y p e = type ( r e . 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 _ _ i n i t _ _ ( self , s b m o d u l e ) :
self . s b m o d u l e = s b m o d u l e
2019-04-18 16:23:33 +00:00
2013-03-07 03:25:11 +00:00
def _ _ l e n _ _ ( self ) :
if self . s b m o d u l e :
return int ( self . s b m o d u l e . G e t N u m C o m p i l e U n i t s ( ) )
return 0
2019-04-18 16:23:33 +00:00
2013-03-07 03:25:11 +00:00
def _ _ g e t i t e m _ _ ( self , key ) :
count = l e n ( self )
if type ( key ) is int :
2023-02-03 08:45:44 -08:00
if - c o u n t < = key < count :
key % = count
2013-03-07 03:25:11 +00:00
return self . s b m o d u l e . G e t C o m p i l e U n i t A t I n d e x ( key )
e l i f type ( key ) is s t r :
i s _ f u l l _ p a t h = key [ 0 ] = = '/'
for i d x in r a n g e ( count ) :
c o m p _ u n i t = self . s b m o d u l e . G e t C o m p i l e U n i t A t I n d e x ( i d x )
if i s _ f u l l _ p a t h :
if c o m p _ u n i t . file . f u l l p a t h = = key :
return c o m p _ u n i t
else :
if c o m p _ u n i t . file . b a s e n a m e = = key :
return c o m p _ u n i t
e l i f i s i n s t a n c e ( key , self . r e _ c o m p i l e _ t y p e ) :
matches = [ ]
for i d x in r a n g e ( count ) :
c o m p _ u n i t = self . s b m o d u l e . G e t C o m p i l e U n i t A t I n d e x ( i d x )
f u l l p a t h = c o m p _ u n i t . file . f u l l p a t h
if f u l l p a t h :
r e _ m a t c h = key . search ( f u l l p a t h )
if r e _ m a t c h :
matches . append ( c o m p _ u n i t )
return matches
else :
2015-10-16 17:52:32 +00:00
p r i n t ( "error: unsupported item type: %s" % type ( key ) )
2013-03-07 03:25:11 +00:00
return None
2012-02-03 03:22:53 +00:00
def g e t _ s e c t i o n s _ a c c e s s _ o b j e c t ( self ) :
'''An accessor function that returns a sections_access() object which allows lazy section array access.'''
return self . s e c t i o n s _ a c c e s s ( self )
2019-04-18 16:23:33 +00:00
2012-02-03 03:22:53 +00:00
def g e t _ s e c t i o n s _ a r r a y ( self ) :
'''An accessor function that returns an array object that contains all sections in this module object.'''
2013-02-25 21:53:07 +00:00
if not h a s a t t r ( self , 'sections_array' ) :
self . s e c t i o n s _ a r r a y = [ ]
2012-02-03 03:22:53 +00:00
for i d x in r a n g e ( self . n u m _ s e c t i o n s ) :
2013-02-25 21:53:07 +00:00
self . s e c t i o n s _ a r r a y . append ( self . G e t S e c t i o n A t I n d e x ( i d x ) )
return self . s e c t i o n s _ a r r a y
2012-02-03 03:22:53 +00:00
2013-03-07 03:25:11 +00:00
def g e t _ c o m p i l e _ u n i t s _ a r r a y ( self ) :
'''An accessor function that returns an array object that contains all compile_units in this module object.'''
if not h a s a t t r ( self , 'compile_units_array' ) :
self . c o m p i l e _ u n i t s _ a r r a y = [ ]
for i d x in r a n g e ( self . G e t N u m C o m p i l e U n i t s ( ) ) :
self . c o m p i l e _ u n i t s _ a r r a y . append ( self . G e t C o m p i l e U n i t A t I n d e x ( i d x ) )
return self . c o m p i l e _ u n i t s _ a r r a y
2019-07-02 22:18:35 +00:00
s y m b o l s = property ( g e t _ s y m b o l s _ a r r a y , None , d o c = '''A read only property that returns a list() of lldb.SBSymbol objects contained in this module.''' )
s y m b o l = property ( g e t _ s y m b o l s _ a c c e s s _ o b j e c t , None , d o c = ''' A r e a d o n l y property t h a t c a n b e u s e d to a c c e s s s y m b o l s by index ( "symbol = module.symbol[0]" ) , name ( "symbols = module.symbol['main']" ) , or using a r e g u l a r e x p r e s s i o n ( "symbols = module.symbol[re.compile(...)]" ) . T h e return value is a single l l d b . S B S y m b o l o b j e c t for a r r a y a c c e s s , and a l i s t ( ) of l l d b . S B S y m b o l o b j e c t s for name and r e g u l a r e x p r e s s i o n a c c e s s ''' )
s e c t i o n s = property ( g e t _ s e c t i o n s _ a r r a y , None , d o c = '''A read only property that returns a list() of lldb.SBSection objects contained in this module.''' )
c o m p i l e _ u n i t s = property ( g e t _ c o m p i l e _ u n i t s _ a r r a y , None , d o c = '''A read only property that returns a list() of lldb.SBCompileUnit objects contained in this module.''' )
section = property ( g e t _ s e c t i o n s _ a c c e s s _ o b j e c t , None , d o c = ''' A r e a d o n l y property t h a t c a n b e u s e d to a c c e s s s y m b o l s by index ( "section = module.section[0]" ) , name ( "sections = module.section[\'main\']" ) , or using a r e g u l a r e x p r e s s i o n ( "sections = module.section[re.compile(...)]" ) . T h e return value is a single l l d b . S B S e c t i o n o b j e c t for a r r a y a c c e s s , and a l i s t ( ) of l l d b . S B S e c t i o n o b j e c t s for name and r e g u l a r e x p r e s s i o n a c c e s s ''' )
section = property ( g e t _ s e c t i o n s _ a c c e s s _ o b j e c t , None , d o c = ''' A r e a d o n l y property t h a t c a n b e u s e d to a c c e s s compile u n i t s by index ( "compile_unit = module.compile_unit[0]" ) , name ( "compile_unit = module.compile_unit[\'main.cpp\']" ) , or using a r e g u l a r e x p r e s s i o n ( "compile_unit = module.compile_unit[re.compile(...)]" ) . T h e return value is a single l l d b . S B C o m p i l e U n i t o b j e c t for a r r a y a c c e s s or by f u l l or p a r t i a l p a t h , and a l i s t ( ) of l l d b . S B C o m p i l e U n i t o b j e c t s r e g u l a r e x p r e s s i o n s . ''' )
2013-03-07 03:25:11 +00:00
2012-02-01 08:09:32 +00:00
def g e t _ u u i d ( self ) :
return u u i d . U U I D ( self . G e t U U I D S t r i n g ( ) )
2019-04-18 16:23:33 +00:00
2019-07-02 22:18:35 +00:00
u u i d = property ( g e t _ u u i d , None , d o c = '''A read only property that returns a standard python uuid.UUID object that represents the UUID of this module.''' )
file = property ( G e t F i l e S p e c , None , d o c = '''A read only property that returns an lldb object that represents the file (lldb.SBFileSpec) for this object file for this module as it is represented where it is being debugged.''' )
p l a t f o r m _ f i l e = property ( G e t P l a t f o r m F i l e S p e c , None , d o c = '''A read only property that returns an lldb object that represents the file (lldb.SBFileSpec) for this object file for this module as it is represented on the current host system.''' )
b y t e _ o r d e r = property ( G e t B y t e O r d e r , None , d o c = '''A read only property that returns an lldb enumeration value (lldb.eByteOrderLittle, lldb.eByteOrderBig, lldb.eByteOrderInvalid) that represents the byte order for this module.''' )
a d d r _ s i z e = property ( G e t A d d r e s s B y t e S i z e , None , d o c = '''A read only property that returns the size in bytes of an address for this module.''' )
t r i p l e = property ( G e t T r i p l e , None , d o c = '''A read only property that returns the target triple (arch-vendor-os) for this module.''' )
n u m _ s y m b o l s = property ( G e t N u m S y m b o l s , None , d o c = '''A read only property that returns number of symbols in the module symbol table as an integer.''' )
n u m _ s e c t i o n s = property ( G e t N u m S e c t i o n s , None , d o c = '''A read only property that returns number of sections in the module as an integer.''' )
2019-04-18 16:23:33 +00:00
2012-01-29 06:07:39 +00:00
% }
2019-12-08 14:46:48 -08:00
# e n d i f
2023-01-26 17:33:33 -08:00
}