8

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
1
  • The code base is large and heavily templated, so reproduction of the bug might be difficult :(. Hence any tips to narrow down the problem are welcome.
    – JP19
    Jan 12, 2011 at 9:19

3 Answers 3

0

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.

4
  • Yes, I did use -g flags. Also, unfortunately, I keep encountering two kinds of issues with gdb (1) break points in header files 2) templates). Our code is heavily templated [deep nesting of templates] (and is very large - hundreds of K's of lines) - so I must accept that the errors may not be easily reconstructible.
    – JP19
    Jan 12, 2011 at 8:57
  • @JP19 "hundreds of K's of lines" - thats WTF on its own. Maybe gdb have problems with large files? The largest file I tried was 10k, and it was fine. Jan 12, 2011 at 9:00
  • Sorry, I meant total number of lines. The point I was trying to convey is that reproduction of the bug might be difficult :(. Hence any tips to nail the problem are welcome. Most files are less than 10K lines for sure.
    – JP19
    Jan 12, 2011 at 9:17
  • I will try 6.8 to see if it helps.
    – JP19
    Jan 12, 2011 at 9:22
0

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.

1
  • This is interesting. I think the 7.1 version I tried was built with same G++ as our code, but not sure. I will check this out.
    – JP19
    Jan 14, 2011 at 15:05
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.