Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
225 views
in Technique[技术] by (71.8m points)

c++ - breakpoints in GDB

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..?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
  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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...