]>
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",
38 "T_PATH_MASK": "path_mask",
46 "T_PATH_MASK_ITEM": "pmi",
52 code
= self
.val
['type']
53 if code
.type.code
!= gdb
.TYPE_CODE_ENUM
or code
.type.tag
!= "f_type":
54 raise Exception("Strange 'type' element in f_val")
56 if str(code
) == "T_VOID":
59 return "(%(c)s) %(v)s" % { "c": code
, "v": self
.val
['val'][self
.codemap
[str(code
)]] }
61 def display_hint(self
):
64 class BIRDFValStackPrinter(BIRDPrinter
):
65 "Print BIRD's struct f_val_stack"
66 typeCode
= gdb
.TYPE_CODE_STRUCT
67 typeTag
= "f_val_stack"
71 return ("Value stack (%(cnt)d):\n\t" % { "cnt": cnt
}) + \
72 "\n\t".join([ (".val[%(n) 3d] = " % { "n": n
}) + str(self
.val
['val'][n
]) for n
in range(cnt
-1, -1, -1) ])
74 def display_hint(self
):
77 class BIRDFInstPrinter(BIRDPrinter
):
78 "Print BIRD's struct f_inst"
79 typeCode
= gdb
.TYPE_CODE_STRUCT
83 code
= self
.val
['fi_code']
84 if str(code
) == "FI_NOP":
85 return str(code
) + ": " + str(self
.val
.cast(gdb
.lookup_type("const char [%(siz)d]" % { "siz": self
.val
.type.sizeof
})))
86 return "%(code)s:\t%(lineno) 6dL\t%(size)6dS\tnext = %(next)s: .i_%(code)s = %(union)s" % {
88 "lineno": self
.val
['lineno'],
89 "size": self
.val
['size'],
90 "next": str(self
.val
['next']),
91 "union": str(self
.val
['i_' + str(code
)])
94 # def children(self): # children iterator
95 def display_hint(self
):
98 class BIRDFLineItemPrinter(BIRDPrinter
):
99 "Print BIRD's struct f_line_item"
100 typeCode
= gdb
.TYPE_CODE_STRUCT
101 typeTag
= "f_line_item"
104 code
= self
.val
['fi_code']
105 if str(code
) == "FI_NOP":
106 return str(code
) + ": " + str(self
.val
.cast(gdb
.lookup_type("const char [%(siz)d]" % { "siz": self
.val
.type.sizeof
})))
107 return "%(code)s:\t%(lineno) 6dL\t%(flags)2dF: .i_%(code)s = %(union)s" % {
109 "lineno": self
.val
['lineno'],
110 "flags": self
.val
['flags'],
111 "union": str(self
.val
['i_' + str(code
)])
114 class BIRDFLinePrinter(BIRDPrinter
):
115 "Print BIRD's struct f_line"
116 typeCode
= gdb
.TYPE_CODE_STRUCT
120 cnt
= self
.val
['len']
121 return ("FLine (%(cnt)d, args=%(args)d): " % { "cnt": cnt
, "args" : self
.val
['args'] } + \
123 ".items[%(n) 3d] = %(code)s" % {
125 "code": str(self
.val
['items'][n
]['fi_code']),
126 } if n
% 8 == 0 else str(self
.val
['items'][n
]['fi_code']) for n
in range(cnt
)]))
129 class BIRDFExecStackPrinter(BIRDPrinter
):
130 "Print BIRD's struct f_exec_stack"
131 typeCode
= gdb
.TYPE_CODE_STRUCT
132 typeTag
= "f_exec_stack"
135 cnt
= self
.val
['cnt']
136 return ("Exec stack (%(cnt)d):\n\t" % { "cnt": cnt
}) + \
137 "\n\t".join([ ".item[%(n) 3d] = %(retflag)d V%(ventry) 3d P%(pos) 4d %(line)s" % {
138 "retflag": self
.val
['item'][n
]['emask'],
139 "ventry": self
.val
['item'][n
]['ventry'],
140 "pos": self
.val
['item'][n
]['pos'],
141 "line": str(self
.val
['item'][n
]['line'].dereference()),
143 } for n
in range(cnt
-1, -1, -1) ])
145 def register_printers(objfile
):
146 objfile
.pretty_printers
.append(BIRDFInstPrinter
.lookup
)
147 objfile
.pretty_printers
.append(BIRDFValPrinter
.lookup
)
148 objfile
.pretty_printers
.append(BIRDFValStackPrinter
.lookup
)
149 objfile
.pretty_printers
.append(BIRDFLineItemPrinter
.lookup
)
150 objfile
.pretty_printers
.append(BIRDFLinePrinter
.lookup
)
151 objfile
.pretty_printers
.append(BIRDFExecStackPrinter
.lookup
)
153 register_printers(gdb
.current_objfile())
155 print("BIRD pretty printers loaded OK.")