xref: /aoo42x/main/solenv/inc/lldb4aoo.py (revision 6f79f796)
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
20*6f79f796SHerbert Dürr	# add info about specific helper methods
21*6f79f796SHerbert Dürr	# assume functions with docstrings are available for general consumption
22*6f79f796SHerbert Dürr	helper_funcs = [v for (k,v) in globals().iteritems() if( not k.startswith('_') and callable(v) and v.__doc__)]
23*6f79f796SHerbert Dürr	if helper_funcs:
24*6f79f796SHerbert Dürr		print( 'Available AOO-specific helper functions:')
25*6f79f796SHerbert Dürr		for hfunc in helper_funcs:
26*6f79f796SHerbert Dürr			shortdesc = hfunc.__doc__.splitlines()[0]
27*6f79f796SHerbert Dürr			print( '\t%s\t# "%s"' %(hfunc.__name__, shortdesc))
28*6f79f796SHerbert Dürr		print( 'Run them with:')
29*6f79f796SHerbert Dürr		for hfunc in helper_funcs[:4]:
30*6f79f796SHerbert Dürr			print( '\tscript %s.%s()' %(__name__, hfunc.__name__))
31*6f79f796SHerbert Dürr
32*6f79f796SHerbert Dürr# some helpers for use from interactive LLDB sessions
33*6f79f796SHerbert Dürr
34*6f79f796SHerbert Dürrimport lldb
35*6f79f796SHerbert Dürr
36*6f79f796SHerbert Dürrdef add_breakpoints():
37*6f79f796SHerbert Dürr	'Setup breakpoints useful for AOO debugging'
38*6f79f796SHerbert Dürr	dbg = lldb.debugger
39*6f79f796SHerbert Dürr	if dbg.GetNumTargets() == 0:
40*6f79f796SHerbert Dürr		return
41*6f79f796SHerbert Dürr	# the list of interesting function breakpoints
42*6f79f796SHerbert Dürr	aoo_breakfn = ['main', '__cxa_call_unexpected', 'objc_exception_throw']
43*6f79f796SHerbert Dürr	aoo_breakfn += ['__cxa_throw']
44*6f79f796SHerbert Dürr	# register breakpoints for function basenames
45*6f79f796SHerbert Dürr	for b in aoo_breakfn:
46*6f79f796SHerbert Dürr		dbg.HandleCommand( 'breakpoint set -b ' + b)
47*6f79f796SHerbert 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)
69aec0f987SHerbert Dürr	L = min(l,128)
70aec0f987SHerbert Dürr	d = c.AddressOf().GetPointeeData( 0, L)
7180e5b736SHerbert Dürr	if c.GetByteSize() == 1: # assume UTF-8
7280e5b736SHerbert Dürr		s = ''.join([chr(x) for x in d.uint8s])
73a54092f6SHerbert Dürr	else: # assume UTF-16
7480e5b736SHerbert Dürr		s = (u''.join([unichr(x) for x in d.uint16s])).encode('utf-8')
75aec0f987SHerbert Dürr	info += ('{refs=%d, len=%d, str="%s"%s}' % (r, l, s.encode('string_escape'), '...'if(l!=L)else''))
7680e5b736SHerbert Dürr	return info
7780e5b736SHerbert Dürr
78aec0f987SHerbert Dürr# definitions for our individual LLDB type summary providers
79aec0f987SHerbert Dürr
80aec0f987SHerbert Dürrdef get_pimpl_info( valobj, dict):
8181712d15SHerbert Dürr	(v, info) = walk_ptrchain( valobj)
82aec0f987SHerbert Dürr	p = v.GetChildAtIndex(0)
8381712d15SHerbert Dürr	pname = p.GetName()
8481712d15SHerbert Dürr	n = p.GetValueAsUnsigned()
8581712d15SHerbert Dürr	if n == 0:
8681712d15SHerbert Dürr		return '%s(%s==NULL)' % (info, pname)
8781712d15SHerbert Dürr	info = '%s(%s=0x%04X)-> ' % (info, pname, n)
88aec0f987SHerbert Dürr	return info + p.Dereference().GetSummary()
8980e5b736SHerbert Dürr
90a54092f6SHerbert Dürr
91f174ccd1SHerbert Dürrdef getinfo_for_rtl_String( valobj, dict):
9280e5b736SHerbert Dürr	return ret_strdata_info( valobj, 'refCount', 'length', 'buffer')
93f174ccd1SHerbert Dürr
94f174ccd1SHerbert Dürrdef getinfo_for_rtl_uString( valobj, dict):
9580e5b736SHerbert Dürr	return ret_strdata_info( valobj, 'refCount', 'length', 'buffer')
96f174ccd1SHerbert Dürr
970d72dfe8SHerbert Dürrdef getinfo_for__ByteStringData( valobj, dict):
9880e5b736SHerbert Dürr	return ret_strdata_info( valobj, 'mnRefCount', 'mnLen', 'maStr')
99f174ccd1SHerbert Dürr
1000d72dfe8SHerbert Dürrdef getinfo_for__UniStringData( valobj, dict):
10180e5b736SHerbert Dürr	return ret_strdata_info( valobj, 'mnRefCount', 'mnLen', 'maStr')
102f174ccd1SHerbert Dürr
103