xref: /aoo41x/main/solenv/inc/lldb4aoo.py (revision aec0f987)
1# to activate the AOO-LLDB helper script run 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
20# local functions for use by the AOO-type summary providers
21
22def walk_ptrchain( v, info):
23	while v.TypeIsPointerType():
24		n = v.GetValueAsUnsigned()
25		if n == 0:
26			info += 'NULL'
27			return (None, info)
28		else:
29			info += '0x%04X-> ' % (n)
30			v = v.Dereference()
31	return (v, info)
32
33def ret_strdata_info( v, refvar, lenvar, aryvar):
34	info = ''
35	(v, info) = walk_ptrchain( v, info)
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, '')
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)
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
74
75