]>
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",
36 "T_PATH_MASK": "path_mask",
44 "T_PATH_MASK_ITEM": "pmi",
50 code
= self
.val
['type']
51 if code
.type.code
!= gdb
.TYPE_CODE_ENUM
or code
.type.tag
!= "f_type":
52 raise Exception("Strange 'type' element in f_val")
54 if str(code
) == "T_VOID":
57 return "(%(c)s) %(v)s" % { "c": code
, "v": self
.val
['val'][self
.codemap
[str(code
)]] }
59 def display_hint(self
):
62 class BIRDFValStackPrinter(BIRDPrinter
):
63 "Print BIRD's struct f_val_stack"
64 typeCode
= gdb
.TYPE_CODE_STRUCT
65 typeTag
= "f_val_stack"
69 return ("Value stack (%(cnt)d):\n\t" % { "cnt": cnt
}) + \
70 "\n\t".join([ (".val[%(n) 3d] = " % { "n": n
}) + str(self
.val
['val'][n
]) for n
in range(cnt
-1, -1, -1) ])
72 def display_hint(self
):
75 class BIRDFInstPrinter(BIRDPrinter
):
76 "Print BIRD's struct f_inst"
77 typeCode
= gdb
.TYPE_CODE_STRUCT
81 code
= self
.val
['fi_code']
82 if str(code
) == "FI_NOP":
83 return str(code
) + ": " + str(self
.val
.cast(gdb
.lookup_type("const char [%(siz)d]" % { "siz": self
.val
.type.sizeof
})))
84 return "%(code)s:\t%(lineno) 6dL\t%(size)6dS\tnext = %(next)s: .i_%(code)s = %(union)s" % {
86 "lineno": self
.val
['lineno'],
87 "size": self
.val
['size'],
88 "next": str(self
.val
['next']),
89 "union": str(self
.val
['i_' + str(code
)])
92 # def children(self): # children iterator
93 def display_hint(self
):
96 class BIRDFLineItemPrinter(BIRDPrinter
):
97 "Print BIRD's struct f_line_item"
98 typeCode
= gdb
.TYPE_CODE_STRUCT
99 typeTag
= "f_line_item"
102 code
= self
.val
['fi_code']
103 if str(code
) == "FI_NOP":
104 return str(code
) + ": " + str(self
.val
.cast(gdb
.lookup_type("const char [%(siz)d]" % { "siz": self
.val
.type.sizeof
})))
105 return "%(code)s:\t%(lineno) 6dL\t%(flags)2dF: .i_%(code)s = %(union)s" % {
107 "lineno": self
.val
['lineno'],
108 "flags": self
.val
['flags'],
109 "union": str(self
.val
['i_' + str(code
)])
112 class BIRDFLinePrinter(BIRDPrinter
):
113 "Print BIRD's struct f_line"
114 typeCode
= gdb
.TYPE_CODE_STRUCT
118 cnt
= self
.val
['len']
119 return ("FLine (%(cnt)d, args=%(args)d): " % { "cnt": cnt
, "args" : self
.val
['args'] } + \
121 ".items[%(n) 3d] = %(code)s" % {
123 "code": str(self
.val
['items'][n
]['fi_code']),
124 } if n
% 8 == 0 else str(self
.val
['items'][n
]['fi_code']) for n
in range(cnt
)]))
127 class BIRDFExecStackPrinter(BIRDPrinter
):
128 "Print BIRD's struct f_exec_stack"
129 typeCode
= gdb
.TYPE_CODE_STRUCT
130 typeTag
= "f_exec_stack"
133 cnt
= self
.val
['cnt']
134 return ("Exec stack (%(cnt)d):\n\t" % { "cnt": cnt
}) + \
135 "\n\t".join([ ".item[%(n) 3d] = %(retflag)d V%(ventry) 3d P%(pos) 4d %(line)s" % {
136 "retflag": self
.val
['item'][n
]['emask'],
137 "ventry": self
.val
['item'][n
]['ventry'],
138 "pos": self
.val
['item'][n
]['pos'],
139 "line": str(self
.val
['item'][n
]['line'].dereference()),
141 } for n
in range(cnt
-1, -1, -1) ])
143 def register_printers(objfile
):
144 objfile
.pretty_printers
.append(BIRDFInstPrinter
.lookup
)
145 objfile
.pretty_printers
.append(BIRDFValPrinter
.lookup
)
146 objfile
.pretty_printers
.append(BIRDFValStackPrinter
.lookup
)
147 objfile
.pretty_printers
.append(BIRDFLineItemPrinter
.lookup
)
148 objfile
.pretty_printers
.append(BIRDFLinePrinter
.lookup
)
149 objfile
.pretty_printers
.append(BIRDFExecStackPrinter
.lookup
)
151 register_printers(gdb
.current_objfile())
153 print("BIRD pretty printers loaded OK.")