tools/gdb: add foreach prefixed command

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
This commit is contained in:
xuxingliang 2024-09-17 12:51:50 +08:00 committed by Xiang Xiao
parent 04b35a2e8f
commit a2da6b94f0
4 changed files with 43 additions and 12 deletions

View file

@ -47,18 +47,21 @@ def register_commands(event):
gdb.execute('handle SIGUSR1 "nostop" "pass" "noprint"')
gdb.write('"handle SIGUSR1 "nostop" "pass" "noprint"\n')
# Register all modules
for m in modules:
if m == "__init__":
continue
def init_gdb_commands(m: str):
module = importlib.import_module(f"{__package__}.{m}")
# Get all classes inherited from gdb.Command
for c in module.__dict__.values():
if isinstance(c, type) and issubclass(c, gdb.Command):
c()
# Register prefix commands firstly
init_gdb_commands("prefix")
modules.remove("prefix")
modules.remove("__init__")
# Register all other modules
for m in modules:
init_gdb_commands(m)
utils = importlib.import_module(f"{__package__}.utils")
utils.check_version()

View file

@ -241,7 +241,7 @@ class ForeachInode(gdb.Command):
"""Dump each inode info"""
def __init__(self):
super().__init__("foreach_inode", gdb.COMMAND_USER)
super().__init__("foreach inode", gdb.COMMAND_USER)
self.level = 4096
def get_root_inode(self, addr_or_expr):
@ -253,7 +253,7 @@ class ForeachInode(gdb.Command):
return utils.gdb_eval_or_none(addr_or_expr)
def parse_arguments(self, argv):
parser = argparse.ArgumentParser(description="foreach_inode command")
parser = argparse.ArgumentParser(description="foreach inode command")
parser.add_argument(
"-L",
"--level",

View file

@ -293,9 +293,7 @@ class ForeachListEntry(gdb.Command):
"""Dump list members for a given list"""
def __init__(self):
super().__init__(
"foreach_list_entry", gdb.COMMAND_DATA, gdb.COMPLETE_EXPRESSION
)
super().__init__("foreach list", gdb.COMMAND_DATA, gdb.COMPLETE_EXPRESSION)
def invoke(self, arg, from_tty):
argv = gdb.string_to_argv(arg)

View file

@ -0,0 +1,30 @@
############################################################################
# tools/gdb/nuttx_gdb/prefix.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.
#
############################################################################
import gdb
class ForeachPrefix(gdb.Command):
"""foreach commands prefix."""
def __init__(self):
super(ForeachPrefix, self).__init__("foreach", gdb.COMMAND_USER, prefix=True)