1*aec0f987SHerbert Dürr# to activate the AOO-LLDB helper script run the line below into LLDB 2*aec0f987SHerbert Dürr# command script import path-to-script/lldb4aoo.py 3*aec0f987SHerbert Dürr# or activate it automatically by adding the line to ~/.lldbinit 4f174ccd1SHerbert Dürr 5f174ccd1SHerbert Dürrdef __lldb_init_module( dbg, dict): 6f174ccd1SHerbert Dürr # the list of AOO specific types 7*aec0f987SHerbert Dürr aoo_types = ['rtl_String', 'rtl_uString', '_ByteStringData', '_UniStringData'] 8*aec0f987SHerbert Dürr pimpl_types = ['rtl::OString', 'rtl::OUString', 'ByteString', 'UniString'] 9*aec0f987SHerbert Dürr # register a helper function for each non-trivial type 10f174ccd1SHerbert Dürr for t in aoo_types: 11f174ccd1SHerbert Dürr f = 'getinfo_for_' + t.replace( '::', '_') 12f174ccd1SHerbert Dürr if f in globals(): 13*aec0f987SHerbert Dürr dbg.HandleCommand( 'type summary add %s -v -C yes -F %s.%s' % (t,__name__,f)) 14f174ccd1SHerbert Dürr else: 15*aec0f987SHerbert Dürr print( 'AOO-LLDB helper function "%s" is not yet defined: ' 16*aec0f987SHerbert Dürr '"%s" types cannot be displayed properly!' % (f,t)) 17*aec0f987SHerbert Dürr # register a generic helper function for pimpl types 18*aec0f987SHerbert Dürr dbg.HandleCommand( 'type summary add -F %s.%s -v -C yes -n PIMPL %s' % ( __name__,'get_pimpl_info', ' '.join(pimpl_types))) 19f174ccd1SHerbert Dürr 20*aec0f987SHerbert Dürr# local functions for use by the AOO-type summary providers 21f174ccd1SHerbert Dürr 22*aec0f987SHerbert Dürrdef walk_ptrchain( v, info): 23*aec0f987SHerbert Dürr while v.TypeIsPointerType(): 24*aec0f987SHerbert Dürr n = v.GetValueAsUnsigned() 25*aec0f987SHerbert Dürr if n == 0: 26*aec0f987SHerbert Dürr info += 'NULL' 27*aec0f987SHerbert Dürr return (None, info) 28*aec0f987SHerbert Dürr else: 29*aec0f987SHerbert Dürr info += '0x%04X-> ' % (n) 30*aec0f987SHerbert Dürr v = v.Dereference() 31*aec0f987SHerbert Dürr return (v, info) 32f174ccd1SHerbert Dürr 3380e5b736SHerbert Dürrdef ret_strdata_info( v, refvar, lenvar, aryvar): 34*aec0f987SHerbert Dürr info = '' 35*aec0f987SHerbert Dürr (v, info) = walk_ptrchain( v, info) 36*aec0f987SHerbert Dürr if not v: 37*aec0f987SHerbert Dürr return info 3880e5b736SHerbert Dürr r = v.GetChildMemberWithName( refvar).GetValueAsSigned() 3980e5b736SHerbert Dürr l = v.GetChildMemberWithName( lenvar).GetValueAsSigned() 4080e5b736SHerbert Dürr c = v.GetChildMemberWithName( aryvar) 41*aec0f987SHerbert Dürr L = min(l,128) 42*aec0f987SHerbert Dürr d = c.AddressOf().GetPointeeData( 0, L) 4380e5b736SHerbert Dürr if c.GetByteSize() == 1: # assume UTF-8 4480e5b736SHerbert Dürr s = ''.join([chr(x) for x in d.uint8s]) 45a54092f6SHerbert Dürr else: # assume UTF-16 4680e5b736SHerbert Dürr s = (u''.join([unichr(x) for x in d.uint16s])).encode('utf-8') 47*aec0f987SHerbert Dürr info += ('{refs=%d, len=%d, str="%s"%s}' % (r, l, s.encode('string_escape'), '...'if(l!=L)else'')) 4880e5b736SHerbert Dürr return info 4980e5b736SHerbert Dürr 50*aec0f987SHerbert Dürr# definitions for our individual LLDB type summary providers 51*aec0f987SHerbert Dürr 52*aec0f987SHerbert Dürrdef get_pimpl_info( valobj, dict): 53*aec0f987SHerbert Dürr v = walk_ptrchain( valobj, '') 54*aec0f987SHerbert Dürr p = v.GetChildAtIndex(0) 55*aec0f987SHerbert Dürr info = v.GetName() 56*aec0f987SHerbert Dürr if v.GetValueAsUnsigned() == 0: 57*aec0f987SHerbert Dürr return '(%s==NULL)' % (info) 58*aec0f987SHerbert Dürr info = '(%s=0x%04X)-> ' % (info,n) 59*aec0f987SHerbert Dürr return info + p.Dereference().GetSummary() 6080e5b736SHerbert Dürr 61a54092f6SHerbert Dürr 62f174ccd1SHerbert Dürrdef getinfo_for_rtl_String( valobj, dict): 6380e5b736SHerbert Dürr return ret_strdata_info( valobj, 'refCount', 'length', 'buffer') 64f174ccd1SHerbert Dürr 65f174ccd1SHerbert Dürrdef getinfo_for_rtl_uString( valobj, dict): 6680e5b736SHerbert Dürr return ret_strdata_info( valobj, 'refCount', 'length', 'buffer') 67f174ccd1SHerbert Dürr 680d72dfe8SHerbert Dürrdef getinfo_for__ByteStringData( valobj, dict): 6980e5b736SHerbert Dürr return ret_strdata_info( valobj, 'mnRefCount', 'mnLen', 'maStr') 70f174ccd1SHerbert Dürr 710d72dfe8SHerbert Dürrdef getinfo_for__UniStringData( valobj, dict): 7280e5b736SHerbert Dürr return ret_strdata_info( valobj, 'mnRefCount', 'mnLen', 'maStr') 73f174ccd1SHerbert Dürr 74f174ccd1SHerbert Dürr 75