public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Help using the GDB C++ STL pretty-printers / xmethods
@ 2022-05-07  1:23 Paul Smith
  2022-05-07 11:19 ` Hannes Domani
  2022-05-07 15:25 ` Jonathan Wakely
  0 siblings, 2 replies; 21+ messages in thread
From: Paul Smith @ 2022-05-07  1:23 UTC (permalink / raw)
  To: gcc-help

Are there any docs or other information about how to use the GDB
pretty-printers for C++ STL that come with GCC?

I have them installed and they work for displaying data, but they don't
work for accessing data.

Just as one very simple example, is there a way to dereference a
unique_ptr?  I see xmethods defined but nothing I've tried works. 
Suppose I have:

  (gdb) p $mp->mgr
  $6 = std::unique_ptr<class Mgr> = {
    get() = 0x7f519a24e000
  }

(so you can see the pretty-printers are installed).  Now, how do I
extract out this object pointer so I can see what's in it?  These don't
work:

  (gdb) p *$mp->mgr
  One of the arguments you tried to pass to operator* could not be
  converted to what the function wants.

  (gdb) p $mp->mgr->initialized
  One of the arguments you tried to pass to operator-> could not be
  converted to what the function wants.

It used to work in GCC 10.2 / GDB 10.1 to access the pointer directly
if you knew, or deciphered, the internal structor of unique_ptr:

  (gdb) p $mp->mgr._M_t._M_t._M_head_impl

However, with GCC 11.3 / GDB 12.1 this no longer works: I get this
error:

  Request for member '_M_head_impl' is ambiguous in type
'std::tuple<Mgr*, std::default_delete<Mgr> >'.
  Candidates are:
    'std::default_delete<Mgr> std::_Head_base<1ul,
std::default_delete<Mgr>, true>::_M_head_impl' (std::tuple<Mgr*,
std::default_delete<Mgr> > -> std::_Tuple_impl<0ul, Mgr*,
std::default_delete<Mgr> > -> std::_Tuple_impl<1ul,
std::default_delete<Mgr> > -> std::_Head_base<1ul,
std::default_delete<Mgr>, true>)
    '<unnamed type> std::_Head_base<0ul, Mgr*, false>::_M_head_impl'
(std::tuple<Mgr*, std::default_delete<Mgr> > -> std::_Tuple_impl<0ul,
Mgr*, std::default_delete<Mgr> > -> std::_Head_base<0ul, Mgr*, false>)

I have found no way to resolve this ambiguity to GDB's satisfaction.

The only thing I've found that works is just to access the pointer
value directly by cutting and pasting it with a cast:

  (gdb) p *((Mgr*)0x7f519a24e000)
  $8 = {
    ...
    initialized = true
  }

  (gdb) p ((Mgr*)0x7f519a24e000)->initialized
  $9 = true

Is that really what we have to do?


Secondly, is there some interface that is defined by the libstdcxx.v6
Python macros for GDB that people who are doing their own python
scripting for their own C++ programs can take advantage of to avoid too
much groveling through the depths of the C++ STL implementation?

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

end of thread, other threads:[~2022-05-09 14:40 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-07  1:23 Help using the GDB C++ STL pretty-printers / xmethods Paul Smith
2022-05-07 11:19 ` Hannes Domani
2022-05-07 15:07   ` Paul Smith
2022-05-07 15:35     ` Jonathan Wakely
2022-05-07 19:07       ` Paul Smith
2022-05-07 19:51         ` Jonathan Wakely
2022-05-07 23:08           ` Paul Smith
2022-05-08  8:13             ` Jonathan Wakely
2022-05-08  8:16               ` Jonathan Wakely
2022-05-08 14:09                 ` Paul Smith
2022-05-08 14:36                   ` Jonathan Wakely
2022-05-08 19:44                 ` Paul Smith
2022-05-08 20:26                   ` Paul Smith
2022-05-09 10:47                     ` Hannes Domani
2022-05-09 10:52                       ` Hannes Domani
2022-05-09  9:32                   ` Jonathan Wakely
2022-05-09 11:23                     ` Jonathan Wakely
2022-05-09 14:05                       ` Paul Smith
2022-05-09 14:40                         ` Paul Smith
2022-05-07 15:44     ` Hannes Domani
2022-05-07 15:25 ` Jonathan Wakely

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).