1*81712d15SHerbert Dürr# to activate the AOO-LLDB helper script type the line below into LLDB 2aec0f987SHerbert Dürr# command script import path-to-script/lldb4aoo.py 3aec0f987SHerbert 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 7aec0f987SHerbert Dürr aoo_types = ['rtl_String', 'rtl_uString', '_ByteStringData', '_UniStringData'] 8aec0f987SHerbert Dürr pimpl_types = ['rtl::OString', 'rtl::OUString', 'ByteString', 'UniString'] 9aec0f987SHerbert 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(): 13aec0f987SHerbert Dürr dbg.HandleCommand( 'type summary add %s -v -C yes -F %s.%s' % (t,__name__,f)) 14f174ccd1SHerbert Dürr else: 15aec0f987SHerbert Dürr print( 'AOO-LLDB helper function "%s" is not yet defined: ' 16aec0f987SHerbert Dürr '"%s" types cannot be displayed properly!' % (f,t)) 17aec0f987SHerbert Dürr # register a generic helper function for pimpl types 18aec0f987SHerbert 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*81712d15SHerbert Dürr 21aec0f987SHerbert Dürr# local functions for use by the AOO-type summary providers 22f174ccd1SHerbert Dürr 23*81712d15SHerbert Dürrdef walk_ptrchain( v): 24*81712d15SHerbert Dürr info = '' 25aec0f987SHerbert Dürr while v.TypeIsPointerType(): 26aec0f987SHerbert Dürr n = v.GetValueAsUnsigned() 27aec0f987SHerbert Dürr if n == 0: 28aec0f987SHerbert Dürr info += 'NULL' 29aec0f987SHerbert Dürr return (None, info) 30*81712d15SHerbert Dürr info += '0x%04X-> ' % (n) 31*81712d15SHerbert Dürr v = v.Dereference() 32aec0f987SHerbert Dürr return (v, info) 33f174ccd1SHerbert Dürr 3480e5b736SHerbert Dürrdef ret_strdata_info( v, refvar, lenvar, aryvar): 35*81712d15SHerbert Dürr (v, info) = walk_ptrchain( v) 36aec0f987SHerbert Dürr if not v: 37aec0f987SHerbert 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) 41aec0f987SHerbert Dürr L = min(l,128) 42aec0f987SHerbert 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') 47aec0f987SHerbert 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 50aec0f987SHerbert Dürr# definitions for our individual LLDB type summary providers 51aec0f987SHerbert Dürr 52aec0f987SHerbert Dürrdef get_pimpl_info( valobj, dict): 53*81712d15SHerbert Dürr (v, info) = walk_ptrchain( valobj) 54aec0f987SHerbert Dürr p = v.GetChildAtIndex(0) 55*81712d15SHerbert Dürr pname = p.GetName() 56*81712d15SHerbert Dürr n = p.GetValueAsUnsigned() 57*81712d15SHerbert Dürr if n == 0: 58*81712d15SHerbert Dürr return '%s(%s==NULL)' % (info, pname) 59*81712d15SHerbert Dürr info = '%s(%s=0x%04X)-> ' % (info, pname, n) 60aec0f987SHerbert Dürr return info + p.Dereference().GetSummary() 6180e5b736SHerbert Dürr 62a54092f6SHerbert Dürr 63f174ccd1SHerbert Dürrdef getinfo_for_rtl_String( valobj, dict): 6480e5b736SHerbert Dürr return ret_strdata_info( valobj, 'refCount', 'length', 'buffer') 65f174ccd1SHerbert Dürr 66f174ccd1SHerbert Dürrdef getinfo_for_rtl_uString( valobj, dict): 6780e5b736SHerbert Dürr return ret_strdata_info( valobj, 'refCount', 'length', 'buffer') 68f174ccd1SHerbert Dürr 690d72dfe8SHerbert Dürrdef getinfo_for__ByteStringData( valobj, dict): 7080e5b736SHerbert Dürr return ret_strdata_info( valobj, 'mnRefCount', 'mnLen', 'maStr') 71f174ccd1SHerbert Dürr 720d72dfe8SHerbert Dürrdef getinfo_for__UniStringData( valobj, dict): 7380e5b736SHerbert Dürr return ret_strdata_info( valobj, 'mnRefCount', 'mnLen', 'maStr') 74f174ccd1SHerbert Dürr 75