]>
Commit | Line | Data |
---|---|---|
71365879 MM |
1 | class BIRDPrinter: |
2 | def __init__(self, val): | |
3 | self.val = val | |
4 | ||
5 | @classmethod | |
6 | def lookup(cls, val): | |
7 | if val.type.code != cls.typeCode: | |
8 | return None | |
9 | if val.type.tag != cls.typeTag: | |
10 | return None | |
11 | ||
12 | return cls(val) | |
13 | ||
14 | ||
15 | class BIRDFValPrinter(BIRDPrinter): | |
16 | "Print BIRD\s struct f_val" | |
17 | typeCode = gdb.TYPE_CODE_STRUCT | |
18 | typeTag = "f_val" | |
19 | ||
20 | codemap = { | |
21 | "T_INT": "i", | |
22 | "T_BOOL": "i", | |
23 | "T_PAIR": "i", | |
24 | "T_QUAD": "i", | |
25 | "T_ENUM_RTS": "i", | |
26 | "T_ENUM_BGP_ORIGIN": "i", | |
27 | "T_ENUM_SCOPE": "i", | |
28 | "T_ENUM_RTC": "i", | |
29 | "T_ENUM_RTD": "i", | |
30 | "T_ENUM_ROA": "i", | |
31 | "T_ENUM_NETTYPE": "i", | |
32 | "T_ENUM_RA_PREFERENCE": "i", | |
0edf0c8c | 33 | "T_ENUM_AF": "i", |
71365879 MM |
34 | "T_IP": "ip", |
35 | "T_NET": "net", | |
36 | "T_STRING": "s", | |
37 | "T_PATH_MASK": "path_mask", | |
38 | "T_PATH": "ad", | |
39 | "T_CLIST": "ad", | |
40 | "T_EC": "ec", | |
41 | "T_ECLIST": "ad", | |
42 | "T_LC": "lc", | |
43 | "T_LCLIST": "ad", | |
44 | "T_RD": "ec", | |
45 | "T_PATH_MASK_ITEM": "pmi", | |
46 | "T_SET": "t", | |
47 | "T_PREFIX_SET": "ti", | |
48 | } | |
49 | ||
50 | def to_string(self): | |
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") | |
54 | ||
55 | if str(code) == "T_VOID": | |
56 | return "T_VOID" | |
57 | else: | |
58 | return "(%(c)s) %(v)s" % { "c": code, "v": self.val['val'][self.codemap[str(code)]] } | |
59 | ||
60 | def display_hint(self): | |
61 | return "map" | |
62 | ||
d4bf7481 MM |
63 | class BIRDFValStackPrinter(BIRDPrinter): |
64 | "Print BIRD's struct f_val_stack" | |
65 | typeCode = gdb.TYPE_CODE_STRUCT | |
66 | typeTag = "f_val_stack" | |
67 | ||
68 | def to_string(self): | |
69 | cnt = self.val['cnt'] | |
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) ]) | |
72 | ||
73 | def display_hint(self): | |
74 | return "map" | |
75 | ||
71365879 MM |
76 | class BIRDFInstPrinter(BIRDPrinter): |
77 | "Print BIRD's struct f_inst" | |
78 | typeCode = gdb.TYPE_CODE_STRUCT | |
79 | typeTag = "f_inst" | |
80 | ||
81 | def to_string(self): | |
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 }))) | |
d4bf7481 MM |
85 | return "%(code)s:\t%(lineno) 6dL\t%(size)6dS\tnext = %(next)s: .i_%(code)s = %(union)s" % { |
86 | "code": str(code), | |
87 | "lineno": self.val['lineno'], | |
88 | "size": self.val['size'], | |
89 | "next": str(self.val['next']), | |
90 | "union": str(self.val['i_' + str(code)]) | |
91 | } | |
71365879 MM |
92 | |
93 | # def children(self): # children iterator | |
94 | def display_hint(self): | |
95 | return "map" | |
96 | ||
d4bf7481 MM |
97 | class BIRDFLineItemPrinter(BIRDPrinter): |
98 | "Print BIRD's struct f_line_item" | |
99 | typeCode = gdb.TYPE_CODE_STRUCT | |
100 | typeTag = "f_line_item" | |
101 | ||
102 | def to_string(self): | |
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" % { | |
107 | "code": str(code), | |
108 | "lineno": self.val['lineno'], | |
109 | "flags": self.val['flags'], | |
110 | "union": str(self.val['i_' + str(code)]) | |
111 | } | |
112 | ||
113 | class BIRDFLinePrinter(BIRDPrinter): | |
114 | "Print BIRD's struct f_line" | |
115 | typeCode = gdb.TYPE_CODE_STRUCT | |
116 | typeTag = "f_line" | |
117 | ||
118 | def to_string(self): | |
119 | cnt = self.val['len'] | |
120 | return ("FLine (%(cnt)d, args=%(args)d): " % { "cnt": cnt, "args" : self.val['args'] } + \ | |
121 | ", ".join([ | |
122 | ".items[%(n) 3d] = %(code)s" % { | |
123 | "n": n, | |
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)])) | |
126 | ||
127 | ||
128 | class BIRDFExecStackPrinter(BIRDPrinter): | |
129 | "Print BIRD's struct f_exec_stack" | |
130 | typeCode = gdb.TYPE_CODE_STRUCT | |
131 | typeTag = "f_exec_stack" | |
132 | ||
133 | def to_string(self): | |
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()), | |
141 | "n": n | |
142 | } for n in range(cnt-1, -1, -1) ]) | |
71365879 MM |
143 | |
144 | def register_printers(objfile): | |
145 | objfile.pretty_printers.append(BIRDFInstPrinter.lookup) | |
146 | objfile.pretty_printers.append(BIRDFValPrinter.lookup) | |
d4bf7481 MM |
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) | |
71365879 MM |
151 | |
152 | register_printers(gdb.current_objfile()) | |
153 | ||
154 | print("BIRD pretty printers loaded OK.") |