From: Hannes Domani <ssbssa@yahoo.de>
To: Jonathan Wakely <jwakely.gcc@gmail.com>,
Paul Smith <paul@mad-scientist.net>
Cc: gcc-help <gcc-help@gcc.gnu.org>
Subject: Re: Help using the GDB C++ STL pretty-printers / xmethods
Date: Mon, 9 May 2022 10:52:40 +0000 (UTC) [thread overview]
Message-ID: <1603624112.1639754.1652093560089@mail.yahoo.com> (raw)
In-Reply-To: <50961608.1629009.1652093269873@mail.yahoo.com>
Am Montag, 9. Mai 2022, 12:47:49 MESZ hat Hannes Domani <ssbssa@yahoo.de> Folgendes geschrieben:
> Am Sonntag, 8. Mai 2022, 22:26:37 MESZ hat Paul Smith <paul@mad-scientist.net> Folgendes geschrieben:
>
> > On Sun, 2022-05-08 at 15:44 -0400, Paul Smith wrote:
> > > On Sun, 2022-05-08 at 09:16 +0100, Jonathan Wakely wrote:
> > > > > gdb.set_convenience_variable('mgr', val['mgr'])
> > > > > init = gdb.parse_and_eval('$mgr->initialized')
> > > > >
> > > > > This will use the xmethod to evaluate the expression.
> > > >
> > > > And then:
> > > >
> > > > if init:
> > > > return gdb.parse_and_eval('*$mgr')
> > >
> > > Unfortunately, this doesn't work :(. I can't do it from the GDB
> > > command line or python (I have tried both with the same results).
> > > Something about convenience variables doesn't play well with xmethods
> > > (or maybe this xmethod implementation specifically?)
> >
> > Hm. I have done a fair amount of work writing GDB Python convenience
> > functions and commands, but I've only done a small amount of pretty-
> > printer work and no xmethod implementations.
> >
> > But I don't understand this from the C++ STL xmethods.py:
> >
> > class UniquePtrGetWorker(gdb.xmethod.XMethodWorker):
> > ...
> > def __call__(self, obj):
> > impl_type = obj.dereference().type.fields()[0].type.tag
> >
> > Why are we using dereference() here? Aren't we expecting to receive a
> > gdb.Value of type std::unique_ptr here, not _pointer to_
> >
> > std::unique_ptr?
> >
> >
> > But, it definitely doesn't work to remove the dereference(), and also
> > the value we get normally IS a pointer; adding debugging above I see:
> >
> > type: 'std::unique_ptr<Foo, std::default_delete<Foo> > *'
> >
> > I don't really grok xmethods so I'm not sure how calling "foo->val"
> > when "foo" is std::unique_ptr<> results in the __call__ method being
> > invoked with a gdb.Value of type std::unique_ptr<>*.
> >
> > My suspicion (not based on anything) is that whatever the reason is, is
> > why I can't use these xmethods with a convenience variable.
>
>
> This is documented in the XMethod API, see XMethodWorker.__call__ in [1]:
>
> The first element is always the this pointer value.
>
>
> Why don't you just set the convenience variable to the address?:
>
> (gdb) set $xx=&foo
> (gdb) p (*$xx)->val
> $7 = 0
I forgot to add the link.
[1] https://sourceware.org/gdb/current/onlinedocs/gdb/Xmethod-API.html#index-XMethodWorker_002e_005f_005fcall_005f_005f
next prev parent reply other threads:[~2022-05-09 10:52 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
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 [this message]
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=1603624112.1639754.1652093560089@mail.yahoo.com \
--to=ssbssa@yahoo.de \
--cc=gcc-help@gcc.gnu.org \
--cc=jwakely.gcc@gmail.com \
--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).