GDB:错误设置头文件中模板类函数的中断点 [英] GDB: error setting break point in template class functions in header files

查看:378
本文介绍了GDB:错误设置头文件中模板类函数的中断点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



MyFile.h code>:

 模板< class T> 
struct ABC:PQR< T> {
void flow(PP pp){
const QX qx = XYZ< Z> :: foo(pp); //试着在这里设置一个断点,第一行。 2533
ASSERTp(qx> = last_qx());


$ / code $ / pre
$ b $ GDB 7.1:

 读取/path_to_exec/exec...done中的符号。 
(gdb)break MyFile.h:2533
注意:断点1也设置为pc 0x121。
注意:断点1也设置为pc 0x121。
注意:断点1也设置为pc 0x121。
注意:断点1也设置在pc 0x156。
注意:断点1也设置在pc 0x156。
注意:断点1也设置为pc 0x121。
注意:断点1也设置为pc 0x121。
注意:断点1也设置为pc 0x121。
注意:断点1也设置为pc 0x121。
注意:断点1也设置为pc 0x121。
注意:断点1也设置为pc 0x121。
注意:断点1也设置在pc 0x156。
注意:断点1也设置在pc 0x156。
注意:断点1也设置为pc 0x121。
在0x44e5c4处的断点1:文件PacketEngine.h,第2533行。(23个位置)
(gdb)运行
启动程序:/ path_to_exec / exec -options
警告:
无法插入断点1.
访问内存地址错误0x121:输入/输出错误。
无法插入断点1.
访问内存地址0x156时出错:输入/输出错误。

为什么要设置23个断点?更进一步,它给出 run



GDB 6.3错误:

 这个GDB被配置为x86_64-redhat-linux-gnu...使用主机libthread_db库/lib64/tls/libthread_db.so。 1\" 。 

(gdb)break MyFile.h:2533
文件MyFile.h中没有第2533行。



是在该程序的开始,它甚至不接受断点
如果我在函数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

文件/ usr / bin / gdb #### GDB 6.3
/ usr / bin / gdb:ELF 64位LSB可执行文件,AMD x86-64,版本1(SYSV),用于GNU / Linux 2.4.0,动态链接(使用共享库),剥离

file〜/ local / bin / gdb ### #GDB 7.1
/ home / user / local / bin / gdb:ELF 64位LSB可执行文件,AMD x86-64,版本1(SYSV),用于GNU / Linux 2.4.0,动态链接(使用共享库),未剥离

file / path_to_exec / exec
/ path_to_exec / exec:ELF 64位LSB可执行文件,AMD x86-64,版本1(SYSV),用于GNU / Linux 2.4。 0,动态链接(使用共享库),不剥离


解决方案

gdb为每个实例化的模板设置了一个不同的断点,即每个断点T(也许是Z)在你的程序中假设的不同类型。但是,它试图在0x121设置断点的地址似乎太低,可能对应于某些系统位置。这可能是为什么gdb无法设置断点。

你应该试试gdb 7.2,这可能会有所帮助。

另外,e2dbg是Linux的一种不同类型的调试器,但它并不像gdb那么成熟。
http://www.eresi-project.org/wiki/TheEmbeddedELFDebugger

I have used two different versions of GDB, both give problems in the following code:

Trimmed down code in 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.

Why is it trying to set 23 breakpoints for one? And further down, it is giving error on 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".

At start of the program, it doesn't even accept the breakpoint If I break in function ASSERTp, it breaks. Then. if I go "UP", and type break, it successfully inserts breakpoint (break MyFile.h:2533). [thus somehow it finds the file/line after the program actually runs]. However, despite the breakpoint being set, on rerunning the program it does not stop at line 2533 but 2534 only (breakpoint in function ASSERTp).

My questions:

1) Can someone please help me solve this?

2) I have often had problems with template code and GDB. Is there any good & free C++ debugger for templates?

3) Not really important, but a side question if it matters: Which version is preferable? The 7.1 seems to be more buggy, but I remember on some runs, it gives less problems.


System info:

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

解决方案

gdb sets a different breakpoint for each instantiated template, i.e for each different type assumed by T (and perhaps Z) in your program. However, the addresses that it is trying to set breakpoints at 0x121 seem to be too low and probably correspond to some system locations. This is probably why gdb can't set the breakpoints.

You should try gdb 7.2, perhaps that will help.

Also, e2dbg is a different type of debugger for Linux, but it is not as mature as gdb. http://www.eresi-project.org/wiki/TheEmbeddedELFDebugger

这篇关于GDB:错误设置头文件中模板类函数的中断点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆