4

When I try stepping through a program, gdb throws this error

std::ostream::operator<< (this=0x6013c0 <std::cout@@GLIBCXX_3.4>, __n=2)
at /build/gcc/src/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/include/bits/ostream.tcc:110
110     /build/gcc/src/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/include/bits/ostream.tcc: No such file or directory.

This is the program I am trying to debug.

#include <iostream>

int printPrime(int, int);

int main()
{
    int t, c;
    std::cin >> t;
    c = t;
    int m[t], n[t];
    while (t--) {
        std::cin >> m[t] >> n[t];
    }
    while (c--) {
        printPrime(m[c], n[c]);
        std::cout << std::endl;
    }
    return 0;
}

int printPrime(int m, int n)
{
    do {
        int c = m;
        int lim = c>>2;
        if (c <= 1)  continue;
        while (c-- && c>lim) {
            if (m%c == 0) {
                if (c == 1) {
                    std::cout << m << std::endl;
                    break;
                }
                break;
            }
        }
    } while(m++ && m<=n);
}

There is no problem with the program code as it runs correctly. I guess it is a problem with my install of GDB on Arch. The error is shown when it encounters cin or cout.

This error doesn't show when I tried running it in my Ubuntu VM

3

I've filled a bug report against this issue: https://bugs.archlinux.org/task/47220

This happens because the ostream source file cannot be found.

Workaround 1

You can strip the libstdc++ library:

sudo strip /usr/lib/libstdc++.so.6

And then gdb will not try to open the source file and the error will not appear anymore.

You can switch back to the unstripped version by reinstalling it with:

sudo pacman -S gcc-libs

Workaround 2

You can add a substitution rule in gdb:

gdb tst
(gdb) set substitute-path /build/gcc/src/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/include /usr/include/c++/5.2.0
| improve this answer | |
1

2017 Update - Note you can now in launch.json

"setupCommands": [
  {
    "description": "Enable pretty-printing for gdb",
    "text": "-enable-pretty-printing",
    "ignoreFailures": true
  },
  {
    "text": "set substitute-path /build/gcc/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include /usr/include/c++/7.2.0"
  }
 ],
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.