【发布时间】:2020-10-25 06:30:05
【问题描述】:
我使用.gdbinit 文件运行gdb,其中包含一些不会扩展的便利变量。
1。我的设置
我编写了以下.gdbinit 文件以通过 blackmagic 探针将可执行文件闪存到微控制器(请参阅https://github.com/blacksphere/blackmagic/wiki):
# .gdbinit file:
# ------------------------------------------- #
# GDB commands #
# FOR STM32F767ZI #
# ------------------------------------------- #
target extended-remote $com
monitor version
monitor swdp_scan
attach 1
file mcu_application.elf
load
start
detach
quit
blackmagic 探针将自己连接到一个 COM 端口,该端口在一台计算机上与另一台计算机上可能不同。因此,我不想在.gdbinit 文件中对其进行硬编码。 GDB 便利变量看起来是最优雅的解决方案:
https://ftp.gnu.org/old-gnu/Manuals/gdb/html_node/gdb_59.html
所以我在.gdbinit 文件中使用便利变量$com,并在调用GDB 时在命令行中定义它:
arm-none-eabi-gdb -x .gdbinit -ex "set $com = \"COM9\""
2。错误
GDB 启动但抛出错误消息:
.gdbinit:6: Error in sourced command file:
$com: No such file or directory.
看起来 GDB 无法识别 $com 便利变量。所以我检查 GDB 是否真的存储了变量:
(gdb) show convenience
$com = "COM9"
$trace_file = void
$trace_func = void
$trace_line = -1
$tracepoint = -1
$trace_frame = -1
$_inferior = 1
...
这证明 GDB 正确地将其存储为"COM9"。因此,问题在于无法扩展它。
3。更多试验
当我观察到在执行.gdbinit 时无法扩展$com,我认为直接在 GDB 中发出命令可能会起作用:
(gdb) set $com = "COM9"
(gdb) show convenience
$com = "COM9"
$trace_file = void
$trace_func = void
...
(gdb) target extended-remote $com
$com: No such file or directory.
但错误仍然存在。
4。问题
您知道一种使 GDB 中的便利变量起作用的方法吗?或者您知道实现相同目标的另一种机制吗?
5。解决方案
感谢@Mark Plotnick 的回答!正如你所建议的,我给我的.gdbinit 文件提供了以下内容:
define flash-remote
target extended-remote $arg0
monitor version
monitor swdp_scan
attach 1
file mcu_application.elf
load
start
detach
quit
end
但是,在调用 GDB 时,我必须删除参数 COM9 周围的引号。所以而不是:
arm-none-eabi-gdb -x .gdbinit -ex "flash-remote \"COM9\""
我以这种方式调用 GDB:
arm-none-eabi-gdb -x .gdbinit -ex "flash-remote COM9"
现在可以了!你拯救了我的一天!
【问题讨论】:
标签: debugging gdb arm-none-eabi-gcc