public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* DWARF debug info version on macOS and 'std::' namespace (and pretty-printers)
@ 2021-03-04 22:51 Philippe Blain
  2021-03-05  0:06 ` Iain Sandoe
  2021-03-05 18:19 ` Jonathan Wakely
  0 siblings, 2 replies; 11+ messages in thread
From: Philippe Blain @ 2021-03-04 22:51 UTC (permalink / raw)
  To: libstdc++; +Cc: iain.sandoe

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

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2021-04-03 19:36 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-04 22:51 DWARF debug info version on macOS and 'std::' namespace (and pretty-printers) Philippe Blain
2021-03-05  0:06 ` Iain Sandoe
2021-03-05 18:19 ` Jonathan Wakely
2021-03-07  4:34   ` Philippe Blain
2021-03-07  8:09     ` Jonathan Wakely
2021-03-07 12:23       ` Iain Sandoe
2021-03-07 16:07         ` Jonathan Wakely
2021-04-03 19:16           ` Philippe Blain
2021-04-03 19:36             ` Iain Sandoe
2021-03-07 16:08       ` Jonathan Wakely
2021-03-07 23:10         ` Philippe Blain

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).