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