Search code examples
c++gdbfstream

using gdb on fstream of c++


I have a std::fstream object in my code, say std::fstream input for reading values from files. How can I check the status of input inside the gdb debugger? I tried print input.fail(), but it says:

couldn't find method std::ifstream::fail

Solution

  • This is most likely because you have not installed debug symbols for libstdc++ (this is where std::fstream resides).

    If you will just try to print input variable you will get something like this without debug symbols for libstdc++:

    (gdb) p input
    $1 = <incomplete type>
    

    I've reproduced this issue on Fedora and the issue gone (input variable was successfully printed and input.fail() was called) after I installed debug info with this command:

    sudo debuginfo-install libstdc++
    

    See also the similar issue for std::stringstream here:
    https://www.reddit.com/r/learnprogramming/comments/5dwtbb/gdb_looking_into_streams/