* Re: [PATCH] PR59170 make pretty printers check for singular iterators
[not found] ` <20161216123352.GB895@redhat.com>
@ 2016-12-16 13:07 ` Jan Kratochvil
2016-12-16 13:17 ` Jonathan Wakely
0 siblings, 1 reply; 3+ messages in thread
From: Jan Kratochvil @ 2016-12-16 13:07 UTC (permalink / raw)
To: Jonathan Wakely; +Cc: libstdc++, gcc-patches, Keith Seitz, Pedro Alves, gdb
On Fri, 16 Dec 2016 13:33:52 +0100, Jonathan Wakely wrote:
> We don't do auto-deref for std::shared_ptr or std::unique_ptr, even
> though we know the object they point to definitely is live and safe to
> access, and that's because those types have pointer semantics not
> reference semantics.
This is wrong std::shared_ptr or std::unique_ptr is not auto-dereferenced for
GDB printing. But it may be more a GDB problem, not libstdc++ pretty printers
problem.
For example glib pretty printers already auto-dereference data structures:
5 GList* list = NULL;
(gdb) p/r list
$1 = (GList *) 0x607a00
(gdb) p list
$2 = 0x607a00 = {0x400810}
/usr/share/glib-2.0/gdb/glib.py
if type.code == gdb.TYPE_CODE_PTR:
type = type.target().unqualified()
t = str(type)
if t == "GList":
return GListPrinter(val, "GList")
But that is more a GDB bug that should be solved even for generic pointers.
Currently while traversing through data structures one has to randomly add or
remove '*' from the beginning of the GDB print expression:
1 class E { int a[1000]; int i=42; } ee;
2 class D { E *e=ⅇ } dd;
3 class C { D &d=dd; } cc;
4 class B { C *c=&cc; } bb;
5 int main() {}
(gdb) p bb
$1 = {c = 0x601030 <cc>}
(gdb) p bb.c
$2 = (C *) 0x601030 <cc>
Oops, I need to add a dereference:
(gdb) p *bb.c
$3 = {d = @0x601028}
(gdb) p *bb.c.d
No symbol "operator*" in current context.
Oops, I need to remove a dereference:
(gdb) p bb.c.d
$4 = (D &) @0x601028: {e = 0x601060 <ee>}
(gdb) p bb.c.d.e
$5 = (E *) 0x601060 <ee>
Oops, I need to add a dereference:
(gdb) p *bb.c.d.e
$6 = {a = {0 <repeats 1000 times>}, i = 42}
(gdb) p *bb.c.d.e.i
Cannot access memory at address 0x2a
Oops, I need to remove a dereference:
(gdb) p bb.c.d.e.i
$7 = 42
This is probably solved in some clickable front-end interfaces.
Jan
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] PR59170 make pretty printers check for singular iterators
2016-12-16 13:07 ` [PATCH] PR59170 make pretty printers check for singular iterators Jan Kratochvil
@ 2016-12-16 13:17 ` Jonathan Wakely
2016-12-16 13:32 ` Jan Kratochvil
0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Wakely @ 2016-12-16 13:17 UTC (permalink / raw)
To: Jan Kratochvil; +Cc: libstdc++, gcc-patches, Keith Seitz, Pedro Alves, gdb
On 16/12/16 14:06 +0100, Jan Kratochvil wrote:
>On Fri, 16 Dec 2016 13:33:52 +0100, Jonathan Wakely wrote:
>> We don't do auto-deref for std::shared_ptr or std::unique_ptr, even
>> though we know the object they point to definitely is live and safe to
>> access, and that's because those types have pointer semantics not
>> reference semantics.
>
>This is wrong std::shared_ptr or std::unique_ptr is not auto-dereferenced for
>GDB printing. But it may be more a GDB problem, not libstdc++ pretty printers
>problem.
>
>For example glib pretty printers already auto-dereference data structures:
> 5 GList* list = NULL;
> (gdb) p/r list
> $1 = (GList *) 0x607a00
> (gdb) p list
> $2 = 0x607a00 = {0x400810}
> /usr/share/glib-2.0/gdb/glib.py
> if type.code == gdb.TYPE_CODE_PTR:
> type = type.target().unqualified()
> t = str(type)
> if t == "GList":
> return GListPrinter(val, "GList")
>
>But that is more a GDB bug that should be solved even for generic pointers.
>Currently while traversing through data structures one has to randomly add or
>remove '*' from the beginning of the GDB print expression:
>
> 1 class E { int a[1000]; int i=42; } ee;
> 2 class D { E *e=ⅇ } dd;
> 3 class C { D &d=dd; } cc;
> 4 class B { C *c=&cc; } bb;
> 5 int main() {}
> (gdb) p bb
> $1 = {c = 0x601030 <cc>}
> (gdb) p bb.c
> $2 = (C *) 0x601030 <cc>
>Oops, I need to add a dereference:
> (gdb) p *bb.c
> $3 = {d = @0x601028}
> (gdb) p *bb.c.d
> No symbol "operator*" in current context.
>Oops, I need to remove a dereference:
> (gdb) p bb.c.d
> $4 = (D &) @0x601028: {e = 0x601060 <ee>}
Wat?
bb.c.d is not a valid expression.
B::c is a pointer, it should be bb.c->d
Is it GDB policy to make invalid expressions like that "work"?
Because I'm not comfortable emulating that in the libstdc++ printers.
> (gdb) p bb.c.d.e
> $5 = (E *) 0x601060 <ee>
>Oops, I need to add a dereference:
> (gdb) p *bb.c.d.e
> $6 = {a = {0 <repeats 1000 times>}, i = 42}
> (gdb) p *bb.c.d.e.i
> Cannot access memory at address 0x2a
>Oops, I need to remove a dereference:
> (gdb) p bb.c.d.e.i
> $7 = 42
I had no idea this even worked, I'd have used bb.c->d.e->i because
that's the correct expression for accessing that variable.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] PR59170 make pretty printers check for singular iterators
2016-12-16 13:17 ` Jonathan Wakely
@ 2016-12-16 13:32 ` Jan Kratochvil
0 siblings, 0 replies; 3+ messages in thread
From: Jan Kratochvil @ 2016-12-16 13:32 UTC (permalink / raw)
To: Jonathan Wakely; +Cc: libstdc++, gcc-patches, Keith Seitz, Pedro Alves, gdb
On Fri, 16 Dec 2016 14:17:32 +0100, Jonathan Wakely wrote:
> On 16/12/16 14:06 +0100, Jan Kratochvil wrote:
> > (gdb) p bb.c.d
> > $4 = (D &) @0x601028: {e = 0x601060 <ee>}
>
> Wat?
>
> bb.c.d is not a valid expression.
>
> B::c is a pointer, it should be bb.c->d
>
> Is it GDB policy to make invalid expressions like that "work"?
Yes, this is a GDB extension from the times of plain C. In C++ it became
a problem. That was not the topic of this example for the initial
dereferencing operator.
> I had no idea this even worked, I'd have used bb.c->d.e->i because
> that's the correct expression for accessing that variable.
There was a plan to make the 'compile' project backward compatible with these
confusing GDB universal dot operators.
Jan
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-12-16 13:32 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <20161215141817.GA22699@redhat.com>
[not found] ` <20161215211903.GA22897@host1.jankratochvil.net>
[not found] ` <20161216010707.GF22266@redhat.com>
[not found] ` <20161216075136.GA21305@host1.jankratochvil.net>
[not found] ` <20161216123352.GB895@redhat.com>
2016-12-16 13:07 ` [PATCH] PR59170 make pretty printers check for singular iterators Jan Kratochvil
2016-12-16 13:17 ` Jonathan Wakely
2016-12-16 13:32 ` Jan Kratochvil
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox