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