tools/gdb: fix thread command not working

`thread` is a GDB prefix command. Use `define` can only change it to a
user prefix command. In this case, `thread 3` is unable to pass
the argument 3 to python.

Use python code to register command to overwrite this behavior. It may
not work with future GDB, but all is good for now.

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
This commit is contained in:
xuxingliang 2024-09-18 15:25:29 +08:00 committed by Xiang Xiao
parent efb890abd3
commit 9881fbae28

View file

@ -52,8 +52,6 @@ class Registers:
# Switch to second inferior to get the original remote-register layout
state = utils.suppress_cli_notifications(True)
utils.switch_inferior(2)
arch = gdb.selected_inferior().architecture()
registers = arch.registers()
natural_size = gdb.lookup_type("long").sizeof
tcb_info = gdb.parse_and_eval("g_tcbinfo")
@ -306,9 +304,10 @@ class Nxthread(gdb.Command):
"""Switch to a specified thread"""
def __init__(self):
super().__init__("nxthread", gdb.COMMAND_USER)
if not is_thread_command_supported():
gdb.execute("define thread\n nxthread \n end\n")
super().__init__("thread", gdb.COMMAND_USER)
else:
super().__init__("nxthread", gdb.COMMAND_USER)
def invoke(self, args, from_tty):
npidhash = gdb.parse_and_eval("g_npidhash")