Question

I think this may have been asked earlier but i can't find one that satisfied my requirements.

I am debugging(infact trying to understand) a large project by trying to analyze the code flow in various testsuites. But when i try to set breakpoints at some files, i get the error "no source file named filename found".
So my question is:

  1. Can gdb only accept breakpoints for the source files where the code flow enters.?
  2. Can I set breakpoints over entire lines of a file with something like b filename:*
  3. Will a breakpoint at header file be accepted as header files are just appended at compile time?

Any insights are more than welcome.

Edit
I checked these issues with some hello world code and found same results as pointed out in one of the answers.but my issue in the actual project still remains on. I still get the same error even when i can see the edited output of the same line which is not accepted as a breakpoint.

Edit 2
I got it working but don't understand how and why it works..??


(gdb) b /home/neeraj/BTP/trunk/include/header.h:872
No source file named /home/neeraj/BTP/trunk/include/header.h:872
Make breakpoint pending on future shared library load? (y or [n]) n
(gdb) b /home/neeraj/BTP/trunk/src/driver.cpp:2
Breakpoint 1 at 0x806c61a: file ../../../trunk/src/driver.cpp, line 2.
(gdb) b /home/neeraj/BTP/trunk/include/header.h:872
Breakpoint 2 at 0x8052fa0: file ../../../trunk/include/header.h:872, line 872.
(gdb)

Any deeper insights..?

Was it helpful?

Solution

The other thing to beware of besides shared libraries is that gdb source file names are relative to the directory where the code was compiled. If you haven't compiled with absolute pathnames, use the dir command to add the compilation directory to the list of places gdb searches for source code.

And a hint: I find I am wildly more productive when I use the Data Display Debugger (DDD) graphical front end to gdb.

OTHER TIPS

  1. No.
  2. No.
  3. Yes.

Make sure you compile with -g (debug) option. Make sure the sourcepaths are set correctly. Use directory, show directories and dir commands to see/set.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top