加载符号后,GDB自动执行命令

时间:2019-03-15 15:09:55

标签: arm gdb embedded elf gdbinit

我正在调试具有GDB远程功能的微控制器。 我有多个构建目标,并且我想拥有一个通用的.gdbinit文件来刷新和/或调试所有不同的目标。

我正在使用BAT脚本启动GDB,其中将可调试的.elf文件作为GDB的参数。这样,GDB将加载符号,并且我的.gdbinit也将正确运行。

我的gdbinit:

define target hookpost-remote
    echo POST TARGET REMOTE\n
    # do stuff
    #load ./path/to/foo.elf # I don't want this
    load # This works if and only if the .elf has been loaded already
    monitor reset
    quit
end

target remote tcp:localhost:2331

问题是在加载二进制文件之前,运行了gdbinit并发出了“ target remote”命令,并且GDB会产生错误:

.gdbinit:15: Error in sourced command file: No executable file specified. Use the "file" or "exec-file" command.

然后直接:

Reading symbols from path/to/foo.elf

如果我从gdbinit中删除“目标远程”命令并在GDB控制台中手动调用它,那么一切都会起作用,但是我不想这样做,我想使一切自动化。

在加载符号后如何自动执行命令?在GDB完成初始化之后和运行gdbinit之后,是否会触发某种挂钩?我可以挂钩张贴阅读符号吗?

1 个答案:

答案 0 :(得分:2)

您可能出于某些目的使用.gdbinit,其中包括一些可以通过-x [cmds_file]命令行选项传递的命令文件来更好地实现的目的。

一些实验表明,.gdbinit在加载程序文件之前运行,而-x文件在加载程序之后运行。