]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
GDB: Added more pretty printers for filters
authorMaria Matejka <mq@ucw.cz>
Mon, 18 Feb 2019 13:56:10 +0000 (14:56 +0100)
committerMaria Matejka <mq@ucw.cz>
Wed, 20 Feb 2019 21:30:55 +0000 (22:30 +0100)
bird-gdb.py

index e91a633fa715a9d0de1802e08e9c5bc1e7cda100..a85ef8c666c28d419db60939495f8bb815293107 100644 (file)
@@ -59,6 +59,19 @@ class BIRDFValPrinter(BIRDPrinter):
     def display_hint(self):
         return "map"
 
+class BIRDFValStackPrinter(BIRDPrinter):
+    "Print BIRD's struct f_val_stack"
+    typeCode = gdb.TYPE_CODE_STRUCT
+    typeTag = "f_val_stack"
+
+    def to_string(self):
+        cnt = self.val['cnt']
+        return ("Value stack (%(cnt)d):\n\t" % { "cnt": cnt }) + \
+                "\n\t".join([ (".val[%(n) 3d] = " % { "n": n}) + str(self.val['val'][n]) for n in range(cnt-1, -1, -1) ])
+
+    def display_hint(self):
+        return "map"
+
 class BIRDFInstPrinter(BIRDPrinter):
     "Print BIRD's struct f_inst"
     typeCode = gdb.TYPE_CODE_STRUCT
@@ -68,16 +81,72 @@ class BIRDFInstPrinter(BIRDPrinter):
         code = self.val['fi_code']
         if str(code) == "FI_NOP":
             return str(code) + ": " + str(self.val.cast(gdb.lookup_type("const char [%(siz)d]" % { "siz": self.val.type.sizeof })))
-        return str(code) + ": " + str(self.val['i_' + str(code)])
+        return "%(code)s:\t%(lineno) 6dL\t%(size)6dS\tnext = %(next)s: .i_%(code)s = %(union)s" % {
+                "code": str(code),
+                "lineno": self.val['lineno'],
+                "size": self.val['size'],
+                "next": str(self.val['next']),
+                "union": str(self.val['i_' + str(code)])
+                }
 
 # def children(self): # children iterator
     def display_hint(self):
         return "map"
 
+class BIRDFLineItemPrinter(BIRDPrinter):
+    "Print BIRD's struct f_line_item"
+    typeCode = gdb.TYPE_CODE_STRUCT
+    typeTag = "f_line_item"
+
+    def to_string(self):
+        code = self.val['fi_code']
+        if str(code) == "FI_NOP":
+            return str(code) + ": " + str(self.val.cast(gdb.lookup_type("const char [%(siz)d]" % { "siz": self.val.type.sizeof })))
+        return "%(code)s:\t%(lineno) 6dL\t%(flags)2dF: .i_%(code)s = %(union)s" % {
+                "code": str(code),
+                "lineno": self.val['lineno'],
+                "flags": self.val['flags'],
+                "union": str(self.val['i_' + str(code)])
+                }
+
+class BIRDFLinePrinter(BIRDPrinter):
+    "Print BIRD's struct f_line"
+    typeCode = gdb.TYPE_CODE_STRUCT
+    typeTag = "f_line"
+
+    def to_string(self):
+        cnt = self.val['len']
+        return ("FLine (%(cnt)d, args=%(args)d): " % { "cnt": cnt, "args" : self.val['args'] } + \
+                ", ".join([
+                    ".items[%(n) 3d] = %(code)s" % {
+                        "n": n,
+                        "code": str(self.val['items'][n]['fi_code']),
+                    } if n % 8 == 0 else str(self.val['items'][n]['fi_code']) for n in range(cnt)]))
+        
+
+class BIRDFExecStackPrinter(BIRDPrinter):
+    "Print BIRD's struct f_exec_stack"
+    typeCode = gdb.TYPE_CODE_STRUCT
+    typeTag = "f_exec_stack"
+
+    def to_string(self):
+        cnt = self.val['cnt']
+        return ("Exec stack (%(cnt)d):\n\t" % { "cnt": cnt }) + \
+                "\n\t".join([ ".item[%(n) 3d] = %(retflag)d V%(ventry) 3d P%(pos) 4d %(line)s" % {
+                    "retflag": self.val['item'][n]['emask'],
+                    "ventry": self.val['item'][n]['ventry'],
+                    "pos": self.val['item'][n]['pos'],
+                    "line": str(self.val['item'][n]['line'].dereference()),
+                    "n": n
+                        } for n in range(cnt-1, -1, -1) ])
 
 def register_printers(objfile):
     objfile.pretty_printers.append(BIRDFInstPrinter.lookup)
     objfile.pretty_printers.append(BIRDFValPrinter.lookup)
+    objfile.pretty_printers.append(BIRDFValStackPrinter.lookup)
+    objfile.pretty_printers.append(BIRDFLineItemPrinter.lookup)
+    objfile.pretty_printers.append(BIRDFLinePrinter.lookup)
+    objfile.pretty_printers.append(BIRDFExecStackPrinter.lookup)
 
 register_printers(gdb.current_objfile())