c++ - GDB:在头文件中的模板类函数中设置断点时出错

标签 c++ templates gdb breakpoints header-files

我使用了两个不同版本的 GDB,都在以下代码中出现问题:

MyFile.h 中的精简代码:

template<class T>
struct ABC: PQR<T> {
  void flow(PP pp) {
    const QX qx = XYZ<Z>::foo(pp); // Trying to set a breakpoint here, line no. 2533
    ASSERTp(qx >= last_qx());
   }
}

GDB 7.1:

Reading symbols from /path_to_exec/exec...done.
(gdb) break MyFile.h:2533
Note: breakpoint 1 also set at pc 0x121.
Note: breakpoint 1 also set at pc 0x121.
Note: breakpoint 1 also set at pc 0x121.
Note: breakpoint 1 also set at pc 0x156.
Note: breakpoint 1 also set at pc 0x156.
Note: breakpoint 1 also set at pc 0x121.
Note: breakpoint 1 also set at pc 0x121.
Note: breakpoint 1 also set at pc 0x121.
Note: breakpoint 1 also set at pc 0x121.
Note: breakpoint 1 also set at pc 0x121.
Note: breakpoint 1 also set at pc 0x121.
Note: breakpoint 1 also set at pc 0x156.
Note: breakpoint 1 also set at pc 0x156.
Note: breakpoint 1 also set at pc 0x121.
Breakpoint 1 at 0x44e5c4: file PacketEngine.h, line 2533. (23 locations)
(gdb) run
Starting program: /path_to_exec/exec -options
Warning:
Cannot insert breakpoint 1.
Error accessing memory address 0x121: Input/output error.
Cannot insert breakpoint 1.
Error accessing memory address 0x156: Input/output error.

为什么要为一个设置23个断点?再往下,它在 run

上出错

GDB 6.3:

 This GDB was configured as "x86_64-redhat-linux-gnu"...Using host libthread_db library "/lib64/tls/libthread_db.so.1".

(gdb) break MyFile.h:2533
No line 2533 in file "MyFile.h".

在程序开始时,它甚至不接受断点 如果我中断函数 ASSERTp,它就会中断。然后。如果我转到“UP”并键入 break,它会成功插入断点 (break MyFile.h:2533)。 [因此它以某种方式在程序实际运行后找到文件/行]。 但是,尽管设置了断点,但在重新运行程序时它不会在第 2533 行停止,而只会在第 2534 行停止(函数 ASSERTp 中的断点)。

我的问题:

1) 有人可以帮我解决这个问题吗?

2) 我经常遇到模板代码和 GDB 的问题。是否有任何好的和免费的模板 C++ 调试器?

3) 不是很重要,但如果重要的话,还有一个附带问题:哪个版本更可取? 7.1 似乎有更多错误,但我记得在某些运行中,它出现的问题较少。


系统信息:

uname -a
Linux ... 2.6.9-67.ELsmp #1 SMP Fri Nov 16 12:49:06 EST 2007 x86_64 x86_64 x86_64 GNU/Linux

file /usr/bin/gdb   #### GDB 6.3
/usr/bin/gdb: ELF 64-bit LSB executable, AMD x86-64, version 1 (SYSV), for GNU/Linux 2.4.0, dynamically linked (uses shared libs), stripped

file ~/local/bin/gdb  #### GDB 7.1
/home/user/local/bin/gdb: ELF 64-bit LSB executable, AMD x86-64, version 1 (SYSV), for GNU/Linux 2.4.0, dynamically linked (uses shared libs), not stripped

file /path_to_exec/exec
/path_to_exec/exec: ELF 64-bit LSB executable, AMD x86-64, version 1 (SYSV), for GNU/Linux 2.4.0, dynamically linked (uses shared libs), not stripped

最佳答案

我不是任何其他 linux 调试器,但我从未遇到过您所解释的此类问题。

您的问题表述得非常好(您可能做到了),但是您是否使用调试符号编译了源代码?

编辑

顺便说一句,我还没有尝试过 gdb 7.1 - 只有 6.8 版本。如果您认为它非常有问题,请尝试使用 6 版本的最新版本。

关于c++ - GDB:在头文件中的模板类函数中设置断点时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4666767/

相关文章:

c++ - 如何让gdb在标准库C/C++函数中单步运行?

c++ - LLDB 中 GDB 的 “define” 是什么?

c++ - 为什么这两种输入字符串的方法都有效?

c++ - 在全局单例对象中存储 COM 指针的问题

c++ - libconfig 未定义对 libconfig::Config::Config() 的引用

c# - TemplateBuilder 和 SideWaffle。项目模板。更改默认根命名空间

c++ - vector 元素分配中较早计算的内容

c++ - 创建一个包含不同驱动类元素的元组,其构造函数接收一个 int 类型,由其在元组中的索引确定

c++ - 为什么匹配模板类上的部分类模板特化与没有模板匹配的另一个部分特化不明确?

android ndk-gdb 无法加载符号