tools/gdb: register NuttX commands when loading the first elf file

Make sure elf exists before registering our commands. If no elf at the moment, register event to GDB to get notified when user adds the first object file.

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
This commit is contained in:
xuxingliang
2024-08-31 18:14:15 +08:00
committed by Xiang Xiao
parent 444396ee37
commit 58cd81ea46
+23 -9
View File
@@ -34,13 +34,27 @@ sys.path.insert(1, python_dir)
py_files = glob.glob(f"{python_dir}/*.py")
py_files.remove(os.path.abspath(__file__))
gdb.execute("set pagination off")
gdb.write("set pagination off\n")
gdb.execute("set python print-stack full")
gdb.write("set python print-stack full\n")
for py_file in py_files:
gdb.execute(f"source {py_file}")
gdb.write(f"source {py_file}\n")
gdb.execute('handle SIGUSR1 "nostop" "pass" "noprint"')
gdb.write('"handle SIGUSR1 "nostop" "pass" "noprint"\n')
def register_commands(event):
if getattr(register_commands, "registered", False):
return
register_commands.registered = True
gdb.write("Registering NuttX GDB commands...\n")
gdb.execute("set pagination off")
gdb.write("set pagination off\n")
gdb.execute("set python print-stack full")
gdb.write("set python print-stack full\n")
for py_file in py_files:
gdb.execute(f"source {py_file}")
gdb.write(f"source {py_file}\n")
gdb.execute('handle SIGUSR1 "nostop" "pass" "noprint"')
gdb.write('"handle SIGUSR1 "nostop" "pass" "noprint"\n')
if len(gdb.objfiles()) == 0:
gdb.events.new_objfile.connect(register_commands)
else:
register_commands(None)