public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Hannes Domani <ssbssa@yahoo.de>
To: "gcc-help@gcc.gnu.org" <gcc-help@gcc.gnu.org>,
	 Paul Smith <paul@mad-scientist.net>
Subject: Re: Help using the GDB C++ STL pretty-printers / xmethods
Date: Sat, 7 May 2022 11:19:35 +0000 (UTC)	[thread overview]
Message-ID: <453082091.802975.1651922375216@mail.yahoo.com> (raw)
In-Reply-To: <5568db74d0acb198a3e8121ee75e3cfa02ea0c6f.camel@mad-scientist.net>

 Am Samstag, 7. Mai 2022, 03:23:46 MESZ hat Paul Smith <paul@mad-scientist.net> Folgendes geschrieben:

> 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?

I'm assuming you installed the pretty printers with a call to
register_libstdcxx_printers() somewhere.
For access to C++ STL objects there is another set of gdb helpers,
called xmethods, which you need to install with a call to
register_libstdcxx_xmethods().


> 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?

Depends on what you want to do with it, but you can get access to the pretty
printers in gdb with a call to gdb.default_visualizer() [1].

[1] https://sourceware.org/gdb/onlinedocs/gdb/Pretty-Printing-API.html#index-gdb_002edefault_005fvisualizer


Hannes

  reply	other threads:[~2022-05-07 11:15 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-07  1:23 Paul Smith
2022-05-07 11:19 ` Hannes Domani [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=453082091.802975.1651922375216@mail.yahoo.com \
    --to=ssbssa@yahoo.de \
    --cc=gcc-help@gcc.gnu.org \
    --cc=paul@mad-scientist.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).