Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
libCore.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
15import gdb.printing
16
18 "Print TObjects"
19
20 def __init__(self, val):
21 self.__val = val
22
23 def children(self):
24 yield "fUniqueID", self.__val['fUniqueID']
25 yield "fBits", self.__val['fBits']
26
27 def to_string(self):
28 return self.__val.dynamic_type.name
29
30
31
33 "Print TNamed"
34
35 def __init__(self, val):
36 self.__val = val
37
38 def children(self):
39 yield "<TObject>", self.__val[self.__val.type.fields()[0]]
40
41 def to_string(self):
42 return "(" + str(self.__val['fName']) + ", " + str(self.__val['fTitle']) + ")"
43
44
45
47 "Print TStrings"
48
49 def __init__(self, val):
50 self.__val = val
51 typeAndAddr = "(*(TString*)"+str(val.address)+")"
52 query = typeAndAddr + ".fRep.fShort.fSize & TString::kShortMask"
53 self.isLong = bool(gdb.parse_and_eval(query))
54
55 def display_hint(self):
56 return 'string'
57
58 def to_string(self):
59 theStr = self.__val['fRep']['fLong']['fData'] if self.isLong else self.__val['fRep']['fShort']['fData']
60 return theStr.string()
61
62
63
64
66 pp = gdb.printing.RegexpCollectionPrettyPrinter("libCore.so")
67 pp.add_printer('TObject', '^TObject$', TObjectPrinter)
68 pp.add_printer('TNamed', '^TNamed$', TNamedPrinter)
69 pp.add_printer('TString', '^TString$', TStringPrinter)
70
71 return pp
72
73
74gdb.printing.register_pretty_printer(gdb.current_objfile(),
build_pretty_printer()