This is an automated email from the ASF dual-hosted git repository. xiaoxiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit aa74ba5ace9793cd20376916c69fee71175d4b40 Author: Zhe Weng <[email protected]> AuthorDate: Wed Sep 25 17:23:44 2024 +0800 tools/gdb: Add command 'netcheck' for checks on network stack The diagnostics result looks like: { "title": "Netcheck Report", "command": "netcheck", "result": "PASS", "message": [] } or { "title": "Netcheck Report", "command": "netcheck", "result": "WARN", "message": [ "[WARNING] IOB used up: free -1 throttle 0" ] } The netcheck command reports like: IOB check: WARN [WARNING] IOB used up: free -1 throttle 0 Signed-off-by: Zhe Weng <[email protected]> --- tools/gdb/nuttxgdb/net.py | 65 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/tools/gdb/nuttxgdb/net.py b/tools/gdb/nuttxgdb/net.py index 96fa9d25fb..e10ce82321 100644 --- a/tools/gdb/nuttxgdb/net.py +++ b/tools/gdb/nuttxgdb/net.py @@ -20,6 +20,8 @@ # ############################################################################ +from enum import Enum + import gdb from . import utils @@ -251,3 +253,66 @@ class NetStats(gdb.Command): if utils.get_symbol_value("CONFIG_NET_UDP") and "udp" in args: self.udp_stats() gdb.write("\n") + + +class NetCheckResult(Enum): + PASS = 0 + WARN = 1 + FAILED = 2 + + def __lt__(self, other): + return self.value < other.value + + +class NetCheck(gdb.Command): + """Network check""" + + def __init__(self): + if utils.get_symbol_value("CONFIG_NET"): + super().__init__("netcheck", gdb.COMMAND_USER) + + def diagnose(self, *args, **kwargs): + result, message = NetCheckResult.PASS, [] + + if utils.get_symbol_value("CONFIG_MM_IOB"): + ret, msg = self.check_iob() + result = max(result, ret) + message.extend(msg) + + return { + "title": "Netcheck Report", + "summary": "Net status check", + "result": "pass" if result else "fail", + "command": "netcheck", + "data": message, + } + + def check_iob(self): + result = NetCheckResult.PASS + message = [] + try: + nfree = gdb.parse_and_eval("g_iob_sem")["semcount"] + nthrottle = ( + gdb.parse_and_eval("g_throttle_sem")["semcount"] + if utils.get_symbol_value("CONFIG_IOB_THROTTLE") > 0 + else 0 + ) + + if nfree < 0 or nthrottle < 0: + result = max(result, NetCheckResult.WARN) + message.append( + "[WARNING] IOB used up: free %d throttle %d" % (nfree, nthrottle) + ) + + except gdb.error as e: + result = max(result, NetCheckResult.FAILED) + message.append("[FAILED] Failed to check IOB: %s" % e) + + finally: + return result, message + + def invoke(self, args, from_tty): + if utils.get_symbol_value("CONFIG_MM_IOB"): + result, message = self.check_iob() + gdb.write("IOB check: %s\n" % result.name) + gdb.write("\n".join(message))
