1

I am trying to make pretty printing to work on Ubuntu 18.04 from visual studio code 1.64.2.

I tried to follow instructions initially from here and then the answer by Devymex as detailed in here.

Then further digging up revealed that the gdb pretty printing itself is not working as I tried to build, make, and run my code outside of VSCode. I had gcc 7.5 preinstalled on Ubuntu 18.04 and then I installed 11.2. But nothing worked.

The code I am trying to run

#include <string>    
#include <iostream>
std::string str = "hello world";
int main ()
{
  std::cout << str << std::endl;
  return 0;
}

The output I get while debugging with gdb

Pretty Printing not working

Additionally, I tried to check which pretty-printer is configured or set up by typing info pretty-printer from within (gdb). But it appears that the appropriate pretty printer is not configured.

pretty printer info

I tried reinstalling gcc 11.2 from the source by configuring with python using both python 2.7 and python 3.6.9 using the command ./configure --with-python and ./configure --with-python3. But nothing worked!

Can anyone please help me out?

neoceph
  • 75
  • 11

1 Answers1

4

I found a solution as posted here. The gdb was not able to find the location where the python printers.py was located. The file was located under /usr/share/gcc/python/libstdcxx/v6/printers.py.

What I needed to do is create a .gdbinit file on my home directory including the following lines of code

python
import sys
sys.path.insert(0, '/usr/share/gcc/python')
from libstdcxx.v6.printers import register_libstdcxx_printers
register_libstdcxx_printers (None)
end

Next source the file with source .gdbinit and then try again the info pretty-print. All the alternate options are now available. Subsequently, gdb debugging and vscode was able to show the contents of the C++ STL containers.

neoceph
  • 75
  • 11