Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 
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])
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.vtstring
def vtstring(self)
Definition: pointerprint.py:43
python.pointerprint.VPointerPrinter.__init__
def __init__(self, val)
Definition: pointerprint.py:13
python.pointerprint.VPointerPrinter.vtstring1
def vtstring1(self, vt)
Definition: pointerprint.py:17
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45
python.pointerprint.lookup_vpointer_function
def lookup_vpointer_function(val)
Definition: pointerprint.py:62
python.pointerprint.VPointerPrinter.val
val
Definition: pointerprint.py:14
python.pointerprint.VPointerPrinter.to_string
def to_string(self)
Definition: pointerprint.py:55
python.pointerprint.VPointerPrinter
Definition: pointerprint.py:12