开发者

GDB: error setting break point in template class functions in header files

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 hos开发者_如何学运维t 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


I am not of any other debugger for linux, but I never experienced such problems as you explained.

You formulated your question really nice (so you probably did), but did you compile your sources with debug symbols?

EDIT

btw I haven't tried gdb 7.1 - only 6.8 version. If you think it is very buggy, try using the last version of the 6 version.


I have seen something similar (using GDB 7.0) where a breakpoint set in a template function is never hit.

Our project is built using an old version of G++ (much older than the version shipped in my distro). I found that by building a version of GDB using the same compiler we develop with that the problem was solved.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜