【问题标题】:gdb Commands List - the first time a breakpoint is hit, commands aren't invokedgdb 命令列表 - 第一次命中断点时,不调用命令
【发布时间】: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


    【解决方案1】:

    使用 GDB-10.0 复制。

    在使用多个 -x-ex 参数之间似乎存在某种意外交互。这不起作用:
    gdb -x testgdbBreakpoint -ex run ./a.out
    gdb -ex 'source testgdbBreakpoint' -ex run ./a.out

    但在 testgdbBreakpoint 末尾添加 run 可以正常工作:

    gdb -q -x 'testgdbBreakpoint' ./a.out
    
    Breakpoint 1 at 0x401136: file test.c, line 4.
    
    Breakpoint 1, incrementI () at test.c:4
    4            i++;
    #0  incrementI () at test.c:4
    #1  0x0000000000401189 in main () at test.c:11
    i: 1
    
    Breakpoint 1, incrementI () at test.c:4
    4            i++;
    #0  incrementI () at test.c:4
    #1  0x0000000000401189 in main () at test.c:11
    i: 2
    ^C
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-03-23
      • 2019-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-20
      • 2016-07-04
      相关资源
      最近更新 更多