1# to activate LLDB helper script run the command below when inside LLDB 2# command script import /tools/lldb4aoo.py 3# or add the line to ~/.lldbinit to always activate it
| 1# to activate the AOO-LLDB helper script run the line below into LLDB 2# command script import path-to-script/lldb4aoo.py 3# or activate it automatically by adding the line to ~/.lldbinit
|
4 5def __lldb_init_module( dbg, dict): 6 # the list of AOO specific types
| 4 5def __lldb_init_module( dbg, dict): 6 # the list of AOO specific types
|
7 aoo_types = ['rtl_String', 'rtl::OString', 'rtl_uString', 'rtl::OUString', 8 '_ByteStringData', '_UniStringData', 'ByteString', 'UniString'] 9 # register a helper function for each type
| 7 aoo_types = ['rtl_String', 'rtl_uString', '_ByteStringData', '_UniStringData'] 8 pimpl_types = ['rtl::OString', 'rtl::OUString', 'ByteString', 'UniString'] 9 # register a helper function for each non-trivial type
|
10 for t in aoo_types: 11 f = 'getinfo_for_' + t.replace( '::', '_') 12 if f in globals():
| 10 for t in aoo_types: 11 f = 'getinfo_for_' + t.replace( '::', '_') 12 if f in globals():
|
13 dbg.HandleCommand( 'type summary add %s -F %s.%s' % (t,__name__,f))
| 13 dbg.HandleCommand( 'type summary add %s -v -C yes -F %s.%s' % (t,__name__,f))
|
14 else:
| 14 else:
|
15 print( 'AOO-LLDB helper function "%s" is not yet defined: "%s" types cannot be displayed properly!' % (f,t))
| 15 print( 'AOO-LLDB helper function "%s" is not yet defined: ' 16 '"%s" types cannot be displayed properly!' % (f,t)) 17 # register a generic helper function for pimpl types 18 dbg.HandleCommand( 'type summary add -F %s.%s -v -C yes -n PIMPL %s' % ( __name__,'get_pimpl_info', ' '.join(pimpl_types)))
|
16
| 19
|
17 # perform some goodies if the process is ready to run or already running 18 if dbg.GetNumTargets() > 0: 19 # the list of interesting function breakpoints 20 aoo_breakfn = ['main', '__cxa_call_unexpected', 'objc_exception_throw'] 21 aoo_breakfn += ['__cxa_throw'] 22 # register the function breakpoints 23 for t in aoo_breakfn: 24 dbg.HandleCommand( 'breakpoint set -n ' + t)
| 20# local functions for use by the AOO-type summary providers
|
25
| 21
|
| 22def walk_ptrchain( v, info): 23 while v.TypeIsPointerType(): 24 n = v.GetValueAsUnsigned() 25 if n == 0: 26 info += 'NULL' 27 return (None, info) 28 else: 29 info += '0x%04X-> ' % (n) 30 v = v.Dereference() 31 return (v, info)
|
26
| 32
|
27# definitions for individual LLDB type summary helpers 28
| |
29def ret_strdata_info( v, refvar, lenvar, aryvar):
| 33def ret_strdata_info( v, refvar, lenvar, aryvar):
|
30 while v.TypeIsPointerType(): 31 if v.GetValueAsUnsigned() == 0: 32 return 'NULL-Pointer!' 33 v = v.Dereference()
| 34 info = '' 35 (v, info) = walk_ptrchain( v, info) 36 if not v: 37 return info
|
34 r = v.GetChildMemberWithName( refvar).GetValueAsSigned() 35 l = v.GetChildMemberWithName( lenvar).GetValueAsSigned() 36 c = v.GetChildMemberWithName( aryvar)
| 38 r = v.GetChildMemberWithName( refvar).GetValueAsSigned() 39 l = v.GetChildMemberWithName( lenvar).GetValueAsSigned() 40 c = v.GetChildMemberWithName( aryvar)
|
37 d = c.AddressOf().GetPointeeData( 0, l)
| 41 L = min(l,128) 42 d = c.AddressOf().GetPointeeData( 0, L)
|
38 if c.GetByteSize() == 1: # assume UTF-8 39 s = ''.join([chr(x) for x in d.uint8s]) 40 else: # assume UTF-16 41 s = (u''.join([unichr(x) for x in d.uint16s])).encode('utf-8')
| 43 if c.GetByteSize() == 1: # assume UTF-8 44 s = ''.join([chr(x) for x in d.uint8s]) 45 else: # assume UTF-16 46 s = (u''.join([unichr(x) for x in d.uint16s])).encode('utf-8')
|
42 info = ('{refs=%d, len=%d, str="%s"}' % (r, l, s.encode('string_escape')))
| 47 info += ('{refs=%d, len=%d, str="%s"%s}' % (r, l, s.encode('string_escape'), '...'if(l!=L)else''))
|
43 return info 44
| 48 return info 49
|
45def ret_strobject_info( v, ptrvar): 46 while v.TypeIsPointerType(): 47 if v.GetValueAsUnsigned() == 0: 48 return 'NULL-Pointer!' 49 v = v.Dereference() 50 p = v.GetChildMemberWithName( ptrvar) 51 return p.Dereference()
| 50# definitions for our individual LLDB type summary providers
|
52
| 51
|
| 52def get_pimpl_info( valobj, dict): 53 v = walk_ptrchain( valobj, '') 54 p = v.GetChildAtIndex(0) 55 info = v.GetName() 56 if v.GetValueAsUnsigned() == 0: 57 return '(%s==NULL)' % (info) 58 info = '(%s=0x%04X)-> ' % (info,n) 59 return info + p.Dereference().GetSummary()
|
53
| 60
|
| 61
|
54def getinfo_for_rtl_String( valobj, dict): 55 return ret_strdata_info( valobj, 'refCount', 'length', 'buffer') 56 57def getinfo_for_rtl_uString( valobj, dict): 58 return ret_strdata_info( valobj, 'refCount', 'length', 'buffer') 59 60def getinfo_for__ByteStringData( valobj, dict): 61 return ret_strdata_info( valobj, 'mnRefCount', 'mnLen', 'maStr') 62 63def getinfo_for__UniStringData( valobj, dict): 64 return ret_strdata_info( valobj, 'mnRefCount', 'mnLen', 'maStr') 65 66
| 62def getinfo_for_rtl_String( valobj, dict): 63 return ret_strdata_info( valobj, 'refCount', 'length', 'buffer') 64 65def getinfo_for_rtl_uString( valobj, dict): 66 return ret_strdata_info( valobj, 'refCount', 'length', 'buffer') 67 68def getinfo_for__ByteStringData( valobj, dict): 69 return ret_strdata_info( valobj, 'mnRefCount', 'mnLen', 'maStr') 70 71def getinfo_for__UniStringData( valobj, dict): 72 return ret_strdata_info( valobj, 'mnRefCount', 'mnLen', 'maStr') 73 74
|
67def getinfo_for_rtl_OString( valobj, dict): 68 return ret_strobject_info( valobj, 'pData') 69 70def getinfo_for_rtl_OUString( valobj, dict): 71 return ret_strobject_jinfo( valobj, 'pData') 72 73def getinfo_for_ByteString( valobj, dict): 74 return ret_strobject_jinfo( valobj, 'mpData') 75 76def getinfo_for_UniString( valobj, dict): 77 return ret_strobject_info( valobj, 'mpData') 78
| |
| |