1

I am a noob learning c++ and using gdb for debugging.

In a Makefile, I compile my individual objs using:

g++ -Wall -g -O0 -c foo.cc
g++ -Wall -g -O0 -c bar.cc
...

then compile the entire executable using:

g++ -Wall -g -O0 foo.o bar.o -lncursesw 

Then I use gdb to step through my code. It keeps stepping into the standard lib so I followed this script recommendation to skip over absolute file names that are prefixed with /usr/include/c++/*.

Now my issue

gdb tries to list files that are not on my machine. If from inside gdb (after start command) I execute info sources, there are a bunch of files that are prefixed with /build/gcc/* which are not on my machine. Why did GDB try to access them?

When stepping through, I cannot skip over the files since gdb will tell me "No such file or directory"

std::basic_ifstream<wchar_t, std::char_traits<wchar_t> >::basic_ifstream (this=0x7fffffffc680, __in_chrg=<optimized out>,
__vtt_parm=<optimized out>) at /build/gcc/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/fstream:518

/build/gcc/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/fstream: No such file or directory.
Employed Russian
  • 199,314
  • 34
  • 295
  • 362
brother-bilo
  • 490
  • 4
  • 11

1 Answers1

1

Why did GDB source them?

When you execute start command, gdb starts running the program and stops at the beginning of main. Among other things, gdb loads all dynamically linked libraries that your program is linked with. One of them is libstdc++, standard C++ library. When it is loaded, gdb also loads it's debug info where files with /build/gcc/* prefix are present. If you are not going to debug libstdc++, there is no need to keep them on your machine.

ks1322
  • 33,961
  • 14
  • 109
  • 164
  • A better answer is probably "don't step into standard library routines if you don't intend to look there". – Employed Russian May 01 '20 at 14:00
  • @ks1322 `/build/gcc/*` are debug info files for libstdc++? If so, they are not on my machine and I do not want to debug the stdlib. So I am perplexed why gdb tries to source them and what is telling gdb they exist at `/build/gcc/*` directory. – brother-bilo May 01 '20 at 14:34
  • @EmployedRussian exactly. I do not want to look in the standard library routines. I would like to skip over them. I managed to skip over `/usr/include/c++/*` but since `/build/gcc/*` directories dont exit on my machine, gdb warns me at each step that it cannot find the file. **I would like to know where gdb gets the idea to list `/build/gcc/*` headers**. – brother-bilo May 01 '20 at 14:40
  • When you step into libstdc++ code, gdb tries to show it for you because it has debug info loaded for libstdc++. If you don't want this either do not step into libstdc++ code or skip files with `/build/gcc/*` prefix as you do it for `/usr/include/c++/*` or remove libstdc++ debug info with `strip`. – ks1322 May 01 '20 at 18:13
  • "I would like to know where gdb gets the idea to list /build/gcc/* headers" It gets this idea by looking at the debug symbols of the standard library, which was built on some computer from sources in `/build/gcc`. gcc does not and cannot have any idea whether this computer is the same computer it is now running on, and whether your intent is to debug the standard library or something else. – n. m. could be an AI May 01 '21 at 06:42