]>
git.ipfire.org Git - thirdparty/bird.git/blob - bird-gdb.py
2 def __init__(self
, val
):
7 if val
.type.code
!= cls
.typeCode
:
9 if val
.type.tag
!= cls
.typeTag
:
15 class BIRDFValPrinter(BIRDPrinter
):
16 "Print BIRD\s struct f_val"
17 typeCode
= gdb
.TYPE_CODE_STRUCT
26 "T_ENUM_BGP_ORIGIN": "i",
31 "T_ENUM_NETTYPE": "i",
32 "T_ENUM_RA_PREFERENCE": "i",
37 "T_PATH_MASK": "path_mask",
45 "T_PATH_MASK_ITEM": "pmi",
51 code
= self
.val
['type']
52 if code
.type.code
!= gdb
.TYPE_CODE_ENUM
or code
.type.tag
!= "f_type":
53 raise Exception("Strange 'type' element in f_val")
55 if str(code
) == "T_VOID":
58 return "(%(c)s) %(v)s" % { "c": code
, "v": self
.val
['val'][self
.codemap
[str(code
)]] }
60 def display_hint(self
):
63 class BIRDFValStackPrinter(BIRDPrinter
):
64 "Print BIRD's struct f_val_stack"
65 typeCode
= gdb
.TYPE_CODE_STRUCT
66 typeTag
= "f_val_stack"
70 return ("Value stack (%(cnt)d):\n\t" % { "cnt": cnt
}) + \
71 "\n\t".join([ (".val[%(n) 3d] = " % { "n": n
}) + str(self
.val
['val'][n
]) for n
in range(cnt
-1, -1, -1) ])
73 def display_hint(self
):
76 class BIRDFInstPrinter(BIRDPrinter
):
77 "Print BIRD's struct f_inst"
78 typeCode
= gdb
.TYPE_CODE_STRUCT
82 code
= self
.val
['fi_code']
83 if str(code
) == "FI_NOP":
84 return str(code
) + ": " + str(self
.val
.cast(gdb
.lookup_type("const char [%(siz)d]" % { "siz": self
.val
.type.sizeof
})))
85 return "%(code)s:\t%(lineno) 6dL\t%(size)6dS\tnext = %(next)s: .i_%(code)s = %(union)s" % {
87 "lineno": self
.val
['lineno'],
88 "size": self
.val
['size'],
89 "next": str(self
.val
['next']),
90 "union": str(self
.val
['i_' + str(code
)])
93 # def children(self): # children iterator
94 def display_hint(self
):
97 class BIRDFLineItemPrinter(BIRDPrinter
):
98 "Print BIRD's struct f_line_item"
99 typeCode
= gdb
.TYPE_CODE_STRUCT
100 typeTag
= "f_line_item"
103 code
= self
.val
['fi_code']
104 if str(code
) == "FI_NOP":
105 return str(code
) + ": " + str(self
.val
.cast(gdb
.lookup_type("const char [%(siz)d]" % { "siz": self
.val
.type.sizeof
})))
106 return "%(code)s:\t%(lineno) 6dL\t%(flags)2dF: .i_%(code)s = %(union)s" % {
108 "lineno": self
.val
['lineno'],
109 "flags": self
.val
['flags'],
110 "union": str(self
.val
['i_' + str(code
)])
113 class BIRDFLinePrinter(BIRDPrinter
):
114 "Print BIRD's struct f_line"
115 typeCode
= gdb
.TYPE_CODE_STRUCT
119 cnt
= self
.val
['len']
120 return ("FLine (%(cnt)d, args=%(args)d): " % { "cnt": cnt
, "args" : self
.val
['args'] } + \
122 ".items[%(n) 3d] = %(code)s" % {
124 "code": str(self
.val
['items'][n
]['fi_code']),
125 } if n
% 8 == 0 else str(self
.val
['items'][n
]['fi_code']) for n
in range(cnt
)]))
128 class BIRDFExecStackPrinter(BIRDPrinter
):
129 "Print BIRD's struct f_exec_stack"
130 typeCode
= gdb
.TYPE_CODE_STRUCT
131 typeTag
= "f_exec_stack"
134 cnt
= self
.val
['cnt']
135 return ("Exec stack (%(cnt)d):\n\t" % { "cnt": cnt
}) + \
136 "\n\t".join([ ".item[%(n) 3d] = %(retflag)d V%(ventry) 3d P%(pos) 4d %(line)s" % {
137 "retflag": self
.val
['item'][n
]['emask'],
138 "ventry": self
.val
['item'][n
]['ventry'],
139 "pos": self
.val
['item'][n
]['pos'],
140 "line": str(self
.val
['item'][n
]['line'].dereference()),
142 } for n
in range(cnt
-1, -1, -1) ])
144 def register_printers(objfile
):
145 objfile
.pretty_printers
.append(BIRDFInstPrinter
.lookup
)
146 objfile
.pretty_printers
.append(BIRDFValPrinter
.lookup
)
147 objfile
.pretty_printers
.append(BIRDFValStackPrinter
.lookup
)
148 objfile
.pretty_printers
.append(BIRDFLineItemPrinter
.lookup
)
149 objfile
.pretty_printers
.append(BIRDFLinePrinter
.lookup
)
150 objfile
.pretty_printers
.append(BIRDFExecStackPrinter
.lookup
)
152 register_printers(gdb
.current_objfile())
154 print("BIRD pretty printers loaded OK.")