【发布时间】:2021-02-15 15:24:24
【问题描述】:
当我使用 gdb 运行程序并有一个命令列表时,第一次命中断点时不会调用这些命令。我设置了一个小测试程序来演示。
test.c:
#include <stdio.h>
void incrementI(){
static int i = 0;
i++;
printf("i: %d\n", i);
sleep(10);
}
int main() {
int i = 0;
while(1){
incrementI();
}
return 0;
}
命令列表:testgdbBreakpoint
set breakpoint pending on
b incrementI
commands
backtrace
continue
end
运行 gdb 的 shell 脚本:testgdbinvoke.sh
#!/bin/sh
gdb -x testGDBBreakpoint -ex=r --args testGDB
我在运行 testgdbinvoke.sh 时看到的输出是:
GNU gdb (GDB) 7.12.1
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from testGDB...done.
Breakpoint 1 at 0x10478
Starting program: /data/config/testGDB
Breakpoint 1, 0x00010478 in incrementI ()
(gdb) c
Continuing.
i: 1
Breakpoint 1, 0x00010478 in incrementI ()
#0 0x00010478 in incrementI ()
#1 0x000104d8 in main ()
i: 2
Breakpoint 1, 0x00010478 in incrementI ()
#0 0x00010478 in incrementI ()
#1 0x000104d8 in main ()
i: 3
第一次遇到断点时,我没有看到回溯,而是必须手动继续。 是否必须在命令列表中设置特定选项才能让它们在每次遇到断点时运行?
【问题讨论】:
标签: gdb embedded-linux