tools/gdb: register commands gracefully

Report any error and continue to try to register next command.

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
This commit is contained in:
xuxingliang 2024-09-26 18:11:32 +08:00 committed by Xiang Xiao
parent 65a93e972c
commit db9b5c4cee

View file

@ -49,10 +49,18 @@ def register_commands(event):
gdb.write('"handle SIGUSR1 "nostop" "pass" "noprint"\n')
def init_gdb_commands(m: str):
module = importlib.import_module(f"{__package__}.{m}")
try:
module = importlib.import_module(f"{__package__}.{m}")
except Exception:
gdb.write(f"\x1b[31;1mIgnore module: {m}\n\x1b[m")
return
for c in module.__dict__.values():
if isinstance(c, type) and issubclass(c, gdb.Command):
c()
try:
c()
except Exception:
gdb.write(f"\x1b[31;1mIgnore command: {c}\n\x1b[m")
# import utils module
utils = importlib.import_module(f"{__package__}.utils")