diff options
author | Maria Matejka <mq@ucw.cz> | 2019-01-23 17:08:27 +0100 |
---|---|---|
committer | Maria Matejka <mq@ucw.cz> | 2019-02-20 22:30:54 +0100 |
commit | 713658798dfafabcd0a74f510c1639f6e3c9c820 (patch) | |
tree | fa18519b2a5b7684bb22d557ea9c836e63d6b5aa | |
parent | 9b46748d5b50d1e8c242a571e80fe1f9f33aeb73 (diff) |
GDB pretty printers: f_inst and f_val.
-rw-r--r-- | bird-gdb.py | 84 | ||||
-rw-r--r-- | lib/birdlib.h | 9 |
2 files changed, 93 insertions, 0 deletions
diff --git a/bird-gdb.py b/bird-gdb.py new file mode 100644 index 00000000..e91a633f --- /dev/null +++ b/bird-gdb.py @@ -0,0 +1,84 @@ +class BIRDPrinter: + def __init__(self, val): + self.val = val + + @classmethod + def lookup(cls, val): + if val.type.code != cls.typeCode: + return None + if val.type.tag != cls.typeTag: + return None + + return cls(val) + + +class BIRDFValPrinter(BIRDPrinter): + "Print BIRD\s struct f_val" + typeCode = gdb.TYPE_CODE_STRUCT + typeTag = "f_val" + + codemap = { + "T_INT": "i", + "T_BOOL": "i", + "T_PAIR": "i", + "T_QUAD": "i", + "T_ENUM_RTS": "i", + "T_ENUM_BGP_ORIGIN": "i", + "T_ENUM_SCOPE": "i", + "T_ENUM_RTC": "i", + "T_ENUM_RTD": "i", + "T_ENUM_ROA": "i", + "T_ENUM_NETTYPE": "i", + "T_ENUM_RA_PREFERENCE": "i", + "T_IP": "ip", + "T_NET": "net", + "T_STRING": "s", + "T_PATH_MASK": "path_mask", + "T_PATH": "ad", + "T_CLIST": "ad", + "T_EC": "ec", + "T_ECLIST": "ad", + "T_LC": "lc", + "T_LCLIST": "ad", + "T_RD": "ec", + "T_PATH_MASK_ITEM": "pmi", + "T_SET": "t", + "T_PREFIX_SET": "ti", + } + + def to_string(self): + code = self.val['type'] + if code.type.code != gdb.TYPE_CODE_ENUM or code.type.tag != "f_type": + raise Exception("Strange 'type' element in f_val") + + if str(code) == "T_VOID": + return "T_VOID" + else: + return "(%(c)s) %(v)s" % { "c": code, "v": self.val['val'][self.codemap[str(code)]] } + + def display_hint(self): + return "map" + +class BIRDFInstPrinter(BIRDPrinter): + "Print BIRD's struct f_inst" + typeCode = gdb.TYPE_CODE_STRUCT + typeTag = "f_inst" + + 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 str(code) + ": " + str(self.val['i_' + str(code)]) + +# def children(self): # children iterator + def display_hint(self): + return "map" + + +def register_printers(objfile): + objfile.pretty_printers.append(BIRDFInstPrinter.lookup) + objfile.pretty_printers.append(BIRDFValPrinter.lookup) + +register_printers(gdb.current_objfile()) + +print("BIRD pretty printers loaded OK.") diff --git a/lib/birdlib.h b/lib/birdlib.h index 7cd78032..6fcc202f 100644 --- a/lib/birdlib.h +++ b/lib/birdlib.h @@ -164,6 +164,15 @@ void debug(const char *msg, ...); /* Printf to debug output */ #define ASSERT(x) do { if (!(x)) log(L_BUG "Assertion '%s' failed at %s:%d", #x, __FILE__, __LINE__); } while(0) #endif +#ifdef DEBUGGING +asm( + ".pushsection \".debug_gdb_scripts\", \"MS\",@progbits,1\n" + ".byte 1\n" /* Python */ + ".asciz \"bird-gdb.py\"\n" + ".popsection\n" + ); +#endif + /* Pseudorandom numbers */ u32 random_u32(void); |