lldb4aoo.py (aec0f987) lldb4aoo.py (81712d15)
1# to activate the AOO-LLDB helper script run the line below into LLDB
1# to activate the AOO-LLDB helper script type 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
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():
13 dbg.HandleCommand( 'type summary add %s -v -C yes -F %s.%s' % (t,__name__,f))
14 else:
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)))
19
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
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():
13 dbg.HandleCommand( 'type summary add %s -v -C yes -F %s.%s' % (t,__name__,f))
14 else:
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)))
19
20
20# local functions for use by the AOO-type summary providers
21
21# local functions for use by the AOO-type summary providers
22
22def walk_ptrchain( v, info):
23def walk_ptrchain( v):
24 info = ''
23 while v.TypeIsPointerType():
24 n = v.GetValueAsUnsigned()
25 if n == 0:
26 info += 'NULL'
27 return (None, info)
25 while v.TypeIsPointerType():
26 n = v.GetValueAsUnsigned()
27 if n == 0:
28 info += 'NULL'
29 return (None, info)
28 else:
29 info += '0x%04X-> ' % (n)
30 v = v.Dereference()
30 info += '0x%04X-> ' % (n)
31 v = v.Dereference()
31 return (v, info)
32
33def ret_strdata_info( v, refvar, lenvar, aryvar):
32 return (v, info)
33
34def ret_strdata_info( v, refvar, lenvar, aryvar):
34 info = ''
35 (v, info) = walk_ptrchain( v, info)
35 (v, info) = walk_ptrchain( v)
36 if not v:
37 return info
38 r = v.GetChildMemberWithName( refvar).GetValueAsSigned()
39 l = v.GetChildMemberWithName( lenvar).GetValueAsSigned()
40 c = v.GetChildMemberWithName( aryvar)
41 L = min(l,128)
42 d = c.AddressOf().GetPointeeData( 0, L)
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')
47 info += ('{refs=%d, len=%d, str="%s"%s}' % (r, l, s.encode('string_escape'), '...'if(l!=L)else''))
48 return info
49
50# definitions for our individual LLDB type summary providers
51
52def get_pimpl_info( valobj, dict):
36 if not v:
37 return info
38 r = v.GetChildMemberWithName( refvar).GetValueAsSigned()
39 l = v.GetChildMemberWithName( lenvar).GetValueAsSigned()
40 c = v.GetChildMemberWithName( aryvar)
41 L = min(l,128)
42 d = c.AddressOf().GetPointeeData( 0, L)
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')
47 info += ('{refs=%d, len=%d, str="%s"%s}' % (r, l, s.encode('string_escape'), '...'if(l!=L)else''))
48 return info
49
50# definitions for our individual LLDB type summary providers
51
52def get_pimpl_info( valobj, dict):
53 v = walk_ptrchain( valobj, '')
53 (v, info) = walk_ptrchain( valobj)
54 p = v.GetChildAtIndex(0)
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)
55 pname = p.GetName()
56 n = p.GetValueAsUnsigned()
57 if n == 0:
58 return '%s(%s==NULL)' % (info, pname)
59 info = '%s(%s=0x%04X)-> ' % (info, pname, n)
59 return info + p.Dereference().GetSummary()
60
61
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
60 return info + p.Dereference().GetSummary()
61
62
63def getinfo_for_rtl_String( valobj, dict):
64 return ret_strdata_info( valobj, 'refCount', 'length', 'buffer')
65
66def getinfo_for_rtl_uString( valobj, dict):
67 return ret_strdata_info( valobj, 'refCount', 'length', 'buffer')
68
69def getinfo_for__ByteStringData( valobj, dict):
70 return ret_strdata_info( valobj, 'mnRefCount', 'mnLen', 'maStr')
71
72def getinfo_for__UniStringData( valobj, dict):
73 return ret_strdata_info( valobj, 'mnRefCount', 'mnLen', 'maStr')
74
74