Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I get an <incomplete type> message for a ifstream object in gdb?

Tags:

c++

gdb

If I run the following code in the gdb debugger and type in print inFile, I get the message "incomplete type".

#include <fstream>
#include <iostream>
int main() {
  std::ifstream inFile;
  inFile.open("testFile.txt");
  std::cout<<"In the debugger if I print the inFile variable at this point I get the incomplete type message";
  inFile.close();
}

This makes it rather difficult to debug. Anyone knows what the reason for this might be?


This is how I compile the file:

g++ -g -std=c++11 main.cpp -o main

Here is the complete GDB output:

>> gdb main
GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from main...done.
(gdb) break main
Breakpoint 1 at 0x400ac2: file main.cpp, line 3.
(gdb) run
Starting program: ~/main

Breakpoint 1, main () at main.cpp:3
3   int main() {
(gdb) n
4     std::ifstream inFile;
(gdb) 
5     inFile.open("testFile.txt");
(gdb) print inFile
$1 = <incomplete type>
(gdb) 

I used the approach ks1322 described in his post and got the following message for

dpkg --list | grep libstdc++

ii  libstdc++-5-dev:amd64                      5.4.0-6ubuntu1~16.04.5                       amd64        GNU Standard C++ Library v3 (development files)
ii  libstdc++6:amd64                           5.4.0-6ubuntu1~16.04.5                       amd64        GNU Standard C++ Library v3

The sudo apt-get install libstdc++

displays

libstdc++6                         libstdc++6-5-dbg-m68k-cross
libstdc++6-4.7-dbg                 libstdc++6-5-dbg-mips64-cross
libstdc++6-4.7-dbg-armel-cross     libstdc++6-5-dbg-mips64el-cross
libstdc++6-4.7-dbg-armhf-cross     libstdc++6-5-dbg-mips-cross
libstdc++6-4.7-dev                 libstdc++6-5-dbg-mipsel-cross
libstdc++6-4.7-dev-armel-cross     libstdc++6-5-dbg-powerpc-cross
libstdc++6-4.7-dev-armhf-cross     libstdc++6-5-dbg-powerpcspe-cross
libstdc++6-4.7-doc                 libstdc++6-5-dbg-ppc64-cross
libstdc++6-4.7-pic                 libstdc++6-5-dbg-ppc64el-cross
libstdc++6-4.7-pic-armel-cross     libstdc++6-5-dbg-s390x-cross
libstdc++6-4.7-pic-armhf-cross     libstdc++6-5-dbg-sh4-cross
libstdc++6-4.8-dbg                 libstdc++6-5-dbg-sparc64-cross
libstdc++6-4.8-dbg-arm64-cross     libstdc++6-alpha-cross
libstdc++6-4.8-dbg-armhf-cross     libstdc++6-arm64-cross
libstdc++6-4.8-dbg-powerpc-cross   libstdc++6-armel-cross
libstdc++6-4.8-dbg-ppc64el-cross   libstdc++6-armhf-cross
libstdc++6-4.9-dbg                 libstdc++6-hppa-cross
libstdc++6-4.9-dbg-arm64-cross     libstdc++6-m68k-cross
libstdc++6-4.9-dbg-armel-cross     libstdc++6-mips64-cross
libstdc++6-4.9-dbg-armhf-cross     libstdc++6-mips64el-cross
libstdc++6-4.9-dbg-powerpc-cross   libstdc++6-mips-cross
libstdc++6-4.9-dbg-ppc64el-cross   libstdc++6-mipsel-cross
libstdc++6-4.9-dbg-s390x-cross     libstdc++6-powerpc-cross
libstdc++6-5-dbg                   libstdc++6-powerpcspe-cross
libstdc++6-5-dbg-alpha-cross       libstdc++6-ppc64-cross
libstdc++6-5-dbg-arm64-cross       libstdc++6-ppc64el-cross
libstdc++6-5-dbg-armel-cross       libstdc++6-s390x-cross
libstdc++6-5-dbg-armhf-cross       libstdc++6-sh4-cross
libstdc++6-5-dbg-hppa-cross        libstdc++6-sparc64-cross
like image 262
Razvan Avatar asked Nov 18 '17 20:11

Razvan


1 Answers

You need to install debug symbols for libstdc++ (this is where std::ifstream resides). See here the similar issue for std::stringstream:

That's caused by gdb not having debug information for your standard library. It's not enough to compile your program with -g, because it's the code in your standard library that defines those types. For example, if you're using gcc with a Debian based system, there's a -dbg version of libstdc++ that you can install. Example:

So you need to install this package libstdc++<your version>-dbg with apt-get:

sudo apt-get install libstdc++<your version>-dbg

Replace <your version> with your version of libstdc++.

like image 110
ks1322 Avatar answered Oct 17 '22 21:10

ks1322