From eddc22c47f9a22ade6adf973c7fef5facee2fffc Mon Sep 17 00:00:00 2001 From: xuxingliang Date: Sat, 23 Nov 2024 01:54:25 +0800 Subject: [PATCH] gdb/wdog: add basic wdog dump command (gdb) wdog WDog@0x404864e8: tick: 4294978078 0x402e36b0 arg: 0x40462500 WDog@0x40462ef8: tick: 4294978078 0x402c7900 arg: 0x40462e70 WDog@0x40462d88: tick: 4294978078 0x402c7900 arg: 0x40462d00 WDog@0x4046e488: tick: 4294978079 0x402e36b0 arg: 0x40462440 WDog@0x40462658: tick: 4294978079 0x402c7900 arg: 0x404625d0 (gdb) Signed-off-by: xuxingliang --- tools/gdb/nuttxgdb/protocols/wdog.py | 35 +++++++++++++++ tools/gdb/nuttxgdb/wdog.py | 67 ++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 tools/gdb/nuttxgdb/protocols/wdog.py create mode 100644 tools/gdb/nuttxgdb/wdog.py diff --git a/tools/gdb/nuttxgdb/protocols/wdog.py b/tools/gdb/nuttxgdb/protocols/wdog.py new file mode 100644 index 00000000000..dc8cecfc665 --- /dev/null +++ b/tools/gdb/nuttxgdb/protocols/wdog.py @@ -0,0 +1,35 @@ +############################################################################ +# tools/gdb/nuttxgdb/protocols/wdog.py +# +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################ + +from __future__ import annotations + +from .value import Value + + +class WDog(Value): + """struct wdog_s""" + + node: Value + arg: Value + func: Value + picbase: Value + expired: Value diff --git a/tools/gdb/nuttxgdb/wdog.py b/tools/gdb/nuttxgdb/wdog.py new file mode 100644 index 00000000000..f25d3c26b65 --- /dev/null +++ b/tools/gdb/nuttxgdb/wdog.py @@ -0,0 +1,67 @@ +############################################################################ +# tools/gdb/nuttxgdb/wdog.py +# +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################ + +from __future__ import annotations + +from typing import List + +import gdb + +from . import lists, utils +from .protocols import wdog as p +from .utils import Value + + +class WDog(Value, p.WDog): + def __init__(self, wdog: p.WDog): + if wdog.type.code == gdb.TYPE_CODE_PTR: + wdog = wdog.dereference() + super().__init__(wdog) + + def __repr__(self) -> str: + return ( + f"WDog@{self.address:#x}: tick: {self.expired: <16}" + f" {self.func.format_string(styling=True)} arg: {self.arg:#x}" + ) + + def __str__(self) -> str: + return self.__repr__() + + +def get_wdog_list() -> List[WDog]: + wdogs = [] + active = utils.parse_and_eval("g_wdactivelist") + for wdog in lists.NxList(active, "struct wdog_s", "node"): + wdogs.append(WDog(wdog)) + + return wdogs + + +class WDogDump(gdb.Command): + """Show wdog timer information""" + + def __init__(self): + super().__init__("wdog", gdb.COMMAND_USER) + + def invoke(self, arg, from_tty): + for wdog in get_wdog_list(): + print(wdog)