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