]> git.ipfire.org Git - thirdparty/bird.git/blob - bird-gdb.py
Filter: split the constructors to a separate file
[thirdparty/bird.git] / bird-gdb.py
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",
33 "T_IP": "ip",
34 "T_NET": "net",
35 "T_STRING": "s",
36 "T_PATH_MASK": "path_mask",
37 "T_PATH": "ad",
38 "T_CLIST": "ad",
39 "T_EC": "ec",
40 "T_ECLIST": "ad",
41 "T_LC": "lc",
42 "T_LCLIST": "ad",
43 "T_RD": "ec",
44 "T_PATH_MASK_ITEM": "pmi",
45 "T_SET": "t",
46 "T_PREFIX_SET": "ti",
47 }
48
49 def to_string(self):
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")
53
54 if str(code) == "T_VOID":
55 return "T_VOID"
56 else:
57 return "(%(c)s) %(v)s" % { "c": code, "v": self.val['val'][self.codemap[str(code)]] }
58
59 def display_hint(self):
60 return "map"
61
62 class BIRDFInstPrinter(BIRDPrinter):
63 "Print BIRD's struct f_inst"
64 typeCode = gdb.TYPE_CODE_STRUCT
65 typeTag = "f_inst"
66
67 def to_string(self):
68 code = self.val['fi_code']
69 if str(code) == "FI_NOP":
70 return str(code) + ": " + str(self.val.cast(gdb.lookup_type("const char [%(siz)d]" % { "siz": self.val.type.sizeof })))
71 return str(code) + ": " + str(self.val['i_' + str(code)])
72
73 # def children(self): # children iterator
74 def display_hint(self):
75 return "map"
76
77
78 def register_printers(objfile):
79 objfile.pretty_printers.append(BIRDFInstPrinter.lookup)
80 objfile.pretty_printers.append(BIRDFValPrinter.lookup)
81
82 register_printers(gdb.current_objfile())
83
84 print("BIRD pretty printers loaded OK.")