ATLAS Offline Software
Loading...
Searching...
No Matches
Tools
GdbUtils
python
pointerprint.py
Go to the documentation of this file.
1
# Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
2
#
3
# File: GdbUtils/python/findlib.py
4
# Created: A while ago, sss
5
# Purpose: When printing a pointer, try to look up its dynamic type.
6
#
7
8
import
gdb
9
from
findlib
import
findlib
10
11
12
class
VPointerPrinter
:
13
def
__init__
(self, val):
14
self.
val
= val
15
16
17
def
vtstring1
(self, vt):
18
olddem = gdb.parameter(
'print asm-demangle'
)
19
out =
''
20
try
:
21
try
:
22
gdb.execute (
'set print asm-demangle on'
)
23
out = gdb.execute (
'x/x 0x%x'
% int(vt), to_string =
True
)
24
except
:
# noqa: E722 B001
25
# Suppress errors
26
pass
27
finally
:
28
if
not
olddem:
29
gdb.execute (
'set print asm-demangle off'
)
30
i = out.find (
'<vtable for '
)
31
if
i >= 0:
32
i += 12
33
j = out.rfind (
'>'
)
34
if
j >= 0:
35
jj = out.rfind (
'+'
, i, j)
36
if
jj >= 0:
37
j = jj
38
return
'<'
+ out[i:j] +
'>'
39
40
return
''
41
42
43
def
vtstring
(self):
44
if
self.
val
== 0:
return
''
45
vpptype = gdb.lookup_type(
'void'
).pointer().pointer()
46
vt = self.
val
.cast(vpptype).dereference()
47
out = self.
vtstring1
(vt)
48
if
not
out:
49
# FIXME: Cache somehow to prevent many calls to findlib.
50
findlib (int(vt),
True
)
51
out = self.
vtstring1
(vt)
52
return
out
53
54
55
def
to_string
(self):
56
return
"(%s) 0x%x%s"
% (self.
val
.type, int(self.
val
), self.
vtstring
())
57
58
59
#_vpointer_types = ['IAddressProvider',
60
# 'pool::IPersistencySvc']
61
#_vpointer_dict = dict([('class ' + v,1) for v in _vpointer_types])
62
def
lookup_vpointer_function
(val):
63
"Look-up and return a pretty-printer that can print val."
64
65
# Get the type.
66
type = val.type
67
68
# If it points to a reference, get the reference.
69
if
type.code == gdb.TYPE_CODE_REF:
70
type = type.target ()
71
72
# Get the unqualified type, stripped of typedefs.
73
type = type.unqualified ().strip_typedefs ()
74
75
if
type.code != gdb.TYPE_CODE_PTR:
76
return
77
78
#if str(type.target()).startswith ('class '):
79
if
type.target().code == gdb.TYPE_CODE_STRUCT:
80
return
VPointerPrinter
(val)
81
82
# Cannot find a pretty printer. Return None.
83
return
None
84
85
86
gdb.pretty_printers.insert (0, lookup_vpointer_function)
python.pointerprint.VPointerPrinter
Definition
pointerprint.py:12
python.pointerprint.VPointerPrinter.val
int val
Definition
pointerprint.py:14
python.pointerprint.VPointerPrinter.vtstring
vtstring(self)
Definition
pointerprint.py:43
python.pointerprint.VPointerPrinter.__init__
__init__(self, val)
Definition
pointerprint.py:13
python.pointerprint.VPointerPrinter.to_string
to_string(self)
Definition
pointerprint.py:55
python.pointerprint.VPointerPrinter.vtstring1
vtstring1(self, vt)
Definition
pointerprint.py:17
python.pointerprint.lookup_vpointer_function
lookup_vpointer_function(val)
Definition
pointerprint.py:62
Generated on
for ATLAS Offline Software by
1.14.0