Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
libRooFitCore.so-gdb.py
Go to the documentation of this file.
1# Pretty printers for gdb
2# \author: Stephan Hageboeck, CERN
3# These pretty printers will make ROOT objects more readable when printed in gdb.
4# If the pretty-printed output is not sufficient, one can always use "print /r <object>"
5# for raw printing.
6#
7# When a debug build is used, they will be installed next to the ROOT libraries.
8# gdb will load them automatically if the auto-load-safe-path is set to ROOT's library directory.
9# For this, one has to add `add-auto-load-safe-path <ROOT lib dir>` to .gdbinit
10#
11# If loaded successfully, typing `info pretty-printer` at the gdb prompt should list the
12# printers registered at the end of this file.
13
14import gdb
15
16
18 "Print a RooAbsCollection"
19
20 def __init__(self, val):
21 self.val = val
22 self.viz = gdb.default_visualizer(self.val['_list'])
23
24 def to_string(self):
25 ret = "{" + str(self.val.dynamic_type) + " " + str(self.val['_name']) +": "
26 try:
27 for name,val in self.viz.children():
28 itemName = val.referenced_value()['fName']
29 ret += str(itemName) + ","
30 except:
31 ret += "<exception " + str(sys.exc_info()[0]) + ">,"
32
33 ret += "}"
34 return ret
35
36 def children(self):
37 for name,val in self.viz.children():
38 try:
39 itemName = val.referenced_value()['fName']
40 key = name + " " + str(val.address) + " (" + str(val.dynamic_type) +") " + str(itemName)
41 yield key, val.referenced_value()
42 except:
43# print("<exception " + str(sys.exc_info()[0]) + ">,")
44 raise
45
46 def display_hint(self):
47 return 'RooAbsCollection printer'
48
49
50
52 "Print a RooAbsArg"
53
54 def __init__(self, val):
55 self.val = val
56
57 def children(self):
58 for name,item in self.val.fields():
59 yield name, item
60
61 def to_string(self):
62 ret += str(self.val.address) + " " + str(self.val.dynamic_type)
63 itemName = self.val['fName']
64 ret += " = { <fName> = {" + str(itemName) + "} }"
65 return ret
66
67 def display_hint(self):
68 return 'RooAbsArg printer'
69
70
71
73 "Print ref count lists"
74
75 def __init__(self, val):
76 self.val = val
77
78 def to_string(self):
79 ret = "{"
80 viz = gdb.default_visualizer(self.val['_storage'])
81 vizRC = gdb.default_visualizer(self.val['_refCount'])
82 for (name,val), (name2,val2) in zip(viz.children(), vizRC.children()):
83 ret += str(val['fName']) + ": " + str(val2) + ", "
84 return ret + "}"
85
86
87
89 "Prevent printing an object"
90
91 def __init__(self, val):
92 self.val = val
93
94 def to_string(self):
95 return ""
96
97 def display_hint(self):
98 return 'Disables printing'
99
100
101
102
104 pp = gdb.printing.RegexpCollectionPrettyPrinter("libRooFitCore")
105 pp.add_printer('Collections', '^Roo(AbsCollection|ArgList|ArgSet)$', RooCollectionPrinter)
106 pp.add_printer('RooSTLRefCountList', '^RooSTLRefCountList.*$', RooSTLRefCountListPrinter)
107 pp.add_printer('RooPrintable', '^RooPrintable$', NonePrinter)
108
109 return pp
110
111
112gdb.printing.register_pretty_printer(gdb.current_objfile(),