181712d15SHerbert 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 206f79f796SHerbert Dürr # add info about specific helper methods 216f79f796SHerbert Dürr # assume functions with docstrings are available for general consumption 226f79f796SHerbert Dürr helper_funcs = [v for (k,v) in globals().iteritems() if( not k.startswith('_') and callable(v) and v.__doc__)] 236f79f796SHerbert Dürr if helper_funcs: 246f79f796SHerbert Dürr print( 'Available AOO-specific helper functions:') 256f79f796SHerbert Dürr for hfunc in helper_funcs: 266f79f796SHerbert Dürr shortdesc = hfunc.__doc__.splitlines()[0] 276f79f796SHerbert Dürr print( '\t%s\t# "%s"' %(hfunc.__name__, shortdesc)) 286f79f796SHerbert Dürr print( 'Run them with:') 296f79f796SHerbert Dürr for hfunc in helper_funcs[:4]: 306f79f796SHerbert Dürr print( '\tscript %s.%s()' %(__name__, hfunc.__name__)) 316f79f796SHerbert Dürr 326f79f796SHerbert Dürr# some helpers for use from interactive LLDB sessions 336f79f796SHerbert Dürr 346f79f796SHerbert Dürrimport lldb 356f79f796SHerbert Dürr 366f79f796SHerbert Dürrdef add_breakpoints(): 376f79f796SHerbert Dürr 'Setup breakpoints useful for AOO debugging' 386f79f796SHerbert Dürr dbg = lldb.debugger 396f79f796SHerbert Dürr if dbg.GetNumTargets() == 0: 406f79f796SHerbert Dürr return 416f79f796SHerbert Dürr # the list of interesting function breakpoints 426f79f796SHerbert Dürr aoo_breakfn = ['main', '__cxa_call_unexpected', 'objc_exception_throw'] 436f79f796SHerbert Dürr aoo_breakfn += ['__cxa_throw'] 446f79f796SHerbert Dürr # register breakpoints for function basenames 456f79f796SHerbert Dürr for b in aoo_breakfn: 466f79f796SHerbert Dürr dbg.HandleCommand( 'breakpoint set -b ' + b) 476f79f796SHerbert Dürr 4881712d15SHerbert Dürr 49aec0f987SHerbert Dürr# local functions for use by the AOO-type summary providers 50f174ccd1SHerbert Dürr 5181712d15SHerbert Dürrdef walk_ptrchain( v): 5281712d15SHerbert Dürr info = '' 53aec0f987SHerbert Dürr while v.TypeIsPointerType(): 54aec0f987SHerbert Dürr n = v.GetValueAsUnsigned() 55aec0f987SHerbert Dürr if n == 0: 56aec0f987SHerbert Dürr info += 'NULL' 57aec0f987SHerbert Dürr return (None, info) 5881712d15SHerbert Dürr info += '0x%04X-> ' % (n) 5981712d15SHerbert Dürr v = v.Dereference() 60aec0f987SHerbert Dürr return (v, info) 61f174ccd1SHerbert Dürr 6280e5b736SHerbert Dürrdef ret_strdata_info( v, refvar, lenvar, aryvar): 6381712d15SHerbert Dürr (v, info) = walk_ptrchain( v) 64aec0f987SHerbert Dürr if not v: 65aec0f987SHerbert Dürr return info 6680e5b736SHerbert Dürr r = v.GetChildMemberWithName( refvar).GetValueAsSigned() 6780e5b736SHerbert Dürr l = v.GetChildMemberWithName( lenvar).GetValueAsSigned() 6880e5b736SHerbert Dürr c = v.GetChildMemberWithName( aryvar) 69*f4289c07SHerbert Dürr if (r < 0) or (l < 0): 70*f4289c07SHerbert Dürr info += 'CORRUPT_STR={refs=%d, len=%d}' % (r,l) 71*f4289c07SHerbert Dürr return info 72aec0f987SHerbert Dürr L = min(l,128) 73aec0f987SHerbert Dürr d = c.AddressOf().GetPointeeData( 0, L) 7480e5b736SHerbert Dürr if c.GetByteSize() == 1: # assume UTF-8 7580e5b736SHerbert Dürr s = ''.join([chr(x) for x in d.uint8s]) 76a54092f6SHerbert Dürr else: # assume UTF-16 7780e5b736SHerbert Dürr s = (u''.join([unichr(x) for x in d.uint16s])).encode('utf-8') 78aec0f987SHerbert Dürr info += ('{refs=%d, len=%d, str="%s"%s}' % (r, l, s.encode('string_escape'), '...'if(l!=L)else'')) 7980e5b736SHerbert Dürr return info 8080e5b736SHerbert Dürr 81aec0f987SHerbert Dürr# definitions for our individual LLDB type summary providers 82aec0f987SHerbert Dürr 83aec0f987SHerbert Dürrdef get_pimpl_info( valobj, dict): 8481712d15SHerbert Dürr (v, info) = walk_ptrchain( valobj) 85aec0f987SHerbert Dürr p = v.GetChildAtIndex(0) 8681712d15SHerbert Dürr pname = p.GetName() 8781712d15SHerbert Dürr n = p.GetValueAsUnsigned() 8881712d15SHerbert Dürr if n == 0: 8981712d15SHerbert Dürr return '%s(%s==NULL)' % (info, pname) 9081712d15SHerbert Dürr info = '%s(%s=0x%04X)-> ' % (info, pname, n) 91aec0f987SHerbert Dürr return info + p.Dereference().GetSummary() 9280e5b736SHerbert Dürr 93a54092f6SHerbert Dürr 94f174ccd1SHerbert Dürrdef getinfo_for_rtl_String( valobj, dict): 9580e5b736SHerbert Dürr return ret_strdata_info( valobj, 'refCount', 'length', 'buffer') 96f174ccd1SHerbert Dürr 97f174ccd1SHerbert Dürrdef getinfo_for_rtl_uString( valobj, dict): 9880e5b736SHerbert Dürr return ret_strdata_info( valobj, 'refCount', 'length', 'buffer') 99f174ccd1SHerbert Dürr 1000d72dfe8SHerbert Dürrdef getinfo_for__ByteStringData( valobj, dict): 10180e5b736SHerbert Dürr return ret_strdata_info( valobj, 'mnRefCount', 'mnLen', 'maStr') 102f174ccd1SHerbert Dürr 1030d72dfe8SHerbert Dürrdef getinfo_for__UniStringData( valobj, dict): 10480e5b736SHerbert Dürr return ret_strdata_info( valobj, 'mnRefCount', 'mnLen', 'maStr') 105f174ccd1SHerbert Dürr 106