c++ - GDB 不会在 C++ 中创建对象时设置的断点处中断

标签 c++ gdb

我有一个 C++ 应用程序,包含以下 main.cpp:

1:  #include <stdio.h>
2:  #include "HeatMap.h"
3:  #include <iostream>
4:
5:  int main (int argc, char * const argv[])
6:  {
7:    HeatMap heatMap();
8:    printf("message");
9:    return 0;
10: }

一切编译都没有错误,我正在使用 gdb (GNU gdb 6.3.50-20050815 (Apple 版本 gdb-1346) (Fri Sep 18 20:40:51 UTC 2009)),并且使用 gcc(gcc 版本 4.2.1(Apple Inc. build 5646)(点 1))以及命令“-c -g”编译应用程序。

当我向第 7、8 和 9 行添加断点并运行 gdb 时,我得到以下结果...

(gdb) break main.cpp:7
Breakpoint 1 at 0x10000177f: file src/main.cpp, line 8.
(gdb) break main.cpp:8
Note: breakpoint 1 also set at pc 0x10000177f.
Breakpoint 2 at 0x10000177f: file src/main.cpp, line 8.
(gdb) break main.cpp:9
Breakpoint 3 at 0x100001790: file src/main.cpp, line 9.
(gdb) run
Starting program: /DevProjects/DataManager/build/DataManager 
Reading symbols for shared libraries ++. done

Breakpoint 1, main (argc=1, argv=0x7fff5fbff960) at src/main.cpp:8
8       printf("message");
(gdb) 

那么,为什么为什么,有谁知道,为什么我的应用程序不会在对象创建的断点处中断,但会在 printf 行处中断?

德鲁·J·索恩。

编辑:答案 - GDB skips over my code!

最佳答案

您需要将 HeatMap 实例化为:

HeatMap heatMap;

HeatMap heatMap(); 声明一个返回 HeatMap 的函数。

关于c++ - GDB 不会在 C++ 中创建对象时设置的断点处中断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2582001/

相关文章:

Golang 解释 gdb SIGILL,非法指令

c - 将字符附加到 C 字符串时,Valgrind 无效读/写

c++ - 输出函数调用到日志文件

c - 使用GDB远程调试多线程C程序

c++ - 无限循环的 "for(;;)"习语是否正确归因于 PDP-11 C 编译器?

c++ - AVL 树插入 - 段错误

gdb - 在 gdb 中, 'where' 、 'bt' 和 'i frame' 命令之间有什么区别?

c++ - 如何在 linux 上编译 libserial?

c++ - shrink_to_fit 会导致搬迁吗?

c++ - 使用 boost_any 时是否可以避免开销?