DWARF debug info version on macOS and 'std::' namespace (and pretty-printers)
Philippe Blain
levraiphilippeblain@gmail.com
Thu Mar 4 22:51:22 GMT 2021
Hello,
I'm trying to understand why a 'std::vector<double>' appears in GDB as
'type = vector<double, std::allocator<double> >' instead of 'std::vector<...>'
I have this simple program:
~~~cpp
#include <vector>
void here() {};
int main() {
std::vector<double> array(4);
here();
return 0;
}
~~~
I'm using GCC 7.3 from Homebrew on my macOS 10.11.6 system, but I have similar
behaviour with GCC 10.2 on macOS 10.15.7 in GitHub Actions.
I compile with:
g++-7 -g -O0 -std=c++11 test.cpp -o test
and run GDB (self-compiled, 11.0.50.20210223-git) with:
gdb test --batch -ex 'b here' -ex run -ex up -ex 'whatis array'
I get 'type = vector<double, std::allocator<double> >'.
If I compile with '-gdwarf-3' instead of just '-g', then I get
'type = std::vector<double>'.
From the documentation [1], I understand that '-g' defaults to dwarf-2 on macOS,
but I do not understand what the DWARF version has to do with the fact that 'vector'
is seen by GDB in the global or 'std::' namespace...
The behaviour is similar when debugging with LLDB:
lldb --batch -o 'b 7' -o r -o 'p array' test
shows '(vector<double, allocator<double> >) $0 = { ...' for DWARF-2
and '(std::vector<double, std::allocator<double> >) $0 = ...' for DWARF-3.
Incidentally, it seems that defaulting to DWARF-2 on macOS is a decision taken in 2009
(stemming from 047a3193bd729475182a438d9929ec923f484481, From-SVN: r152127 [2])
and I'm wondering if it's still the best thing to do ?
Finally, I was dragged down this hole trying to understand why the Python pretty-printers
were not working on my machine. Having 'vector' correctly identified in the 'std::' namespace
was one part of the solution, but I also had to create a symlink named
/usr/local/Cellar/gcc/7.3.0_1/lib/gcc/7/libstdc++.6.dylib-gdb.py
pointing to the existing /usr/local/Cellar/gcc/7.3.0_1/lib/gcc/7/libstdc++.a-gdb.py
for the pretty printers to be loaded automatically. Looking at gcc/libstdc++-v3/python/Makefile.am
it seems that a file named 'libstdc++.6.dylib-gdb.py' *should* have been created
(at least from what I understand), but it seems this is not the case...
I'm not sure why either. I also verified that on the GitHub Actions VM, for
GCC 8, 9 and 10, only libstdc++.a-gdb.py exists...
This is my first post here so I'm sorry if it's not the right forum.
I searched the archives but could not find anything about this.
Also, I am not subscribed to the list so if I could be CC'ed in the replies
this would be ideal.
Cheers!
Philippe.
[1] https://gcc.gnu.org/onlinedocs/gcc/Debugging-Options.html
[2] https://github.com/gcc-mirror/gcc/commit/047a3193bd729475182a438d9929ec923f484481
More information about the Libstdc++
mailing list