0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-11-09 12:48:43 +00:00

GDB: Added more pretty printers for filters

This commit is contained in:
Maria Matejka 2019-02-18 14:56:10 +01:00
parent ea4f55e3dc
commit d4bf74816f

View File

@ -59,6 +59,19 @@ class BIRDFValPrinter(BIRDPrinter):
def display_hint(self): def display_hint(self):
return "map" 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): class BIRDFInstPrinter(BIRDPrinter):
"Print BIRD's struct f_inst" "Print BIRD's struct f_inst"
typeCode = gdb.TYPE_CODE_STRUCT typeCode = gdb.TYPE_CODE_STRUCT
@ -68,16 +81,72 @@ class BIRDFInstPrinter(BIRDPrinter):
code = self.val['fi_code'] code = self.val['fi_code']
if str(code) == "FI_NOP": 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.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 children(self): # children iterator
def display_hint(self): def display_hint(self):
return "map" 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): def register_printers(objfile):
objfile.pretty_printers.append(BIRDFInstPrinter.lookup) objfile.pretty_printers.append(BIRDFInstPrinter.lookup)
objfile.pretty_printers.append(BIRDFValPrinter.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()) register_printers(gdb.current_objfile())