xref: /aoo41x/main/solenv/inc/lldb4aoo.py (revision f174ccd1)
1# to activate 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 getinfo_for_rtl_String( valobj, dict):
30	while valobj.TypeIsPointerType():
31		valobj = valobj.Dereference()
32	r = valobj.GetChildMemberWithName('refCount').GetValueAsSigned()
33	l = valobj.GetChildMemberWithName('length').GetValueAsSigned()
34	a = valobj.GetChildMemberWithName('buffer').AddressOf().GetPointeeData(0,l)
35	s = ''.join([chr(x) for x in a.uint8s])
36	return '{refs=%d, len=%d, str="%s"}'%(r,l,s)
37	return info
38
39def getinfo_for_rtl_uString( valobj, dict):
40	while valobj.TypeIsPointerType():
41		valobj = valobj.Dereference()
42	r = valobj.GetChildMemberWithName('refCount').GetValueAsSigned()
43	l = valobj.GetChildMemberWithName('length').GetValueAsSigned()
44	a = valobj.GetChildMemberWithName('buffer').AddressOf().GetPointeeData(0,l)
45	s = (u''.join([unichr(x) for x in a.uint16s])).encode('utf-8')
46	return '{refs=%d, len=%d, str="%s"}'%(r,l,s)
47
48def getinfo_for_rtl__ByteStringData( valobj, dict):
49	while valobj.TypeIsPointerType():
50		valobj = valobj.Dereference()
51	r = valobj.GetChildMemberWithName('mnRefCount').GetValueAsSigned()
52	l = valobj.GetChildMemberWithName('mnLen').GetValueAsSigned()
53	a = valobj.GetChildMemberWithName('maStr').AddressOf().GetPointeeData(0,l)
54	s = ''.join([chr(x) for x in a.uint8s])
55	return '{refs=%d, len=%d, str="%s"}'%(r,l,s)
56
57def getinfo_for_rtl__UniStringData( valobj, dict):
58	while valobj.TypeIsPointerType():
59		valobj = valobj.Dereference()
60	r = valobj.GetChildMemberWithName('mnRefCount').GetValueAsSigned()
61	l = valobj.GetChildMemberWithName('mnLen').GetValueAsSigned()
62	a = valobj.GetChildMemberWithName('maStr').AddressOf().GetPointeeData(0,l)
63	s = (u''.join([unichr(x) for x in a.uint16s])).encode('utf-8')
64	return '{refs=%d, len=%d, str="%s"}'%(r,l,s)
65
66
67def getinfo_for_rtl_OString( valobj, dict):
68	d = valobj.GetChildMemberWithName('pData')
69	return d.Dereference()
70
71def getinfo_for_rtl_OUString( valobj, dict):
72	d = valobj.GetChildMemberWithName('pData')
73	return d.Dereference()
74
75def getinfo_for_rtl_ByteString( valobj, dict):
76	d = valobj.GetChildMemberWithName('mpData')
77	return d.Dereference()
78
79def getinfo_for_rtl_UniString( valobj, dict):
80	d = valobj.GetChildMemberWithName('mpData')
81	return d.Dereference()
82
83