diff --git a/tools/gdb/net.py b/tools/gdb/net.py index d361a211a1..c2f2e3ca31 100644 --- a/tools/gdb/net.py +++ b/tools/gdb/net.py @@ -52,9 +52,44 @@ class NetStats(gdb.Command): except gdb.error as e: gdb.write("Failed to get IOB stats: %s\n" % e) + def pkt_stats(self): + try: + netstats = gdb.parse_and_eval("g_netstats") + gdb.write( + "Packets:%7s%7s%7s%7s%7s%7s\n" + % ("IPv4", "IPv6", "TCP", "UDP", "ICMP", "ICMPv6") + ) + + def stats_line(title, member): + gdb.write("%-8s" % title) + for proto in ("ipv4", "ipv6", "tcp", "udp", "icmp", "icmpv6"): + gdb.write( + "%7s" + % utils.get_field(utils.get_field(netstats, proto), member, "-") + ) + gdb.write("\n") + + stats_line("Received", "recv") + stats_line("Dropped", "drop") + stats_line(" VHL", "vhlerr") + stats_line(" Frag", "fragerr") + stats_line(" Chksum", "chkerr") + stats_line(" Type", "typeerr") + stats_line(" Proto", "protoerr") + # TODO: Maybe print TCP's ackerr, rst, syndrop, synrst here + stats_line("Sent", "sent") + stats_line(" Rexmit", "rexmit") + + except gdb.error as e: + gdb.write("Failed to get Net Stats: %s\n" % e) + def invoke(self, args, from_tty): if utils.get_symbol_value("CONFIG_MM_IOB"): self.iob_stats() + gdb.write("\n") + if utils.get_symbol_value("CONFIG_NET_STATISTICS"): + self.pkt_stats() + gdb.write("\n") if utils.get_symbol_value("CONFIG_NET"): diff --git a/tools/gdb/utils.py b/tools/gdb/utils.py index 51dbd01958..1f130893e9 100644 --- a/tools/gdb/utils.py +++ b/tools/gdb/utils.py @@ -169,6 +169,14 @@ def get_symbol_value(name, locspec="nx_start", cacheable=True): return value +def get_field(val, key, default=None): + """Get a field from a gdb.Value, return default if key not found""" + try: + return val[key] if val else default + except gdb.error: + return default + + def import_check(module, name="", errmsg=""): try: module = __import__(module, fromlist=[name])