* C++ nested class bug/questions
@ 2021-06-22 11:27 Willgerodt, Felix
2021-06-22 19:01 ` Simon Marchi
0 siblings, 1 reply; 3+ messages in thread
From: Willgerodt, Felix @ 2021-06-22 11:27 UTC (permalink / raw)
To: gdb
[-- Attachment #1: Type: text/plain, Size: 1813 bytes --]
Hello everyone,
I was debugging a program similar to the one attached and noticed a couple
of unexpected things happening. I compiled it with ”-g -O0” and g++ 11.1.0
(clang showed similar behaviour) and saw this:
(gdb) bt
#0 DF::vvv (this=0x7fffffffd120) at foo.cc:11
#1 0x0000555555555180 in foo () at foo.cc:16
#2 0x00005555555551a7 in main () at foo.cc:20
(gdb) ptype abcd
type = class DF::FFFF {
private:
int ffff;
}
(gdb) ptype FFFF
No symbol "FFFF" in current context.
(gdb) ptype DF::
FFFF vvv()
(gdb) ptype DF::FFFF
There is no field named FFFF
(gdb) ptype 'DF::FFFF'
type = class DF::FFFF {
private:
int ffff;
}
(gdb)
(The fourth command shows tab completion.)
The problems I see are:
1) I think it shouldn’t be DF::FFFF.
2) 'ptype FFFF’ should just work as it is in the current scope.
3) There shouldn’t be a need to quote DF:FFFF, right? Although that might just be a side-effect here.
4) The fact that a suggestion from tab completion doesn’t work is annoying. This is probably also be a side-effect.
Before debugging this further, I wanted to see if there are any comments/suggestions.
Am I even right about point 1? I couldn’t really find anything definitive
in my favourite cpp reference on this type of nesting. g++ and clang output FFFF as
foo()::DF::vvv()::FFFF as far as I can see.
I don’t see any obvious problems in the dwarf that is produced.
Thanks,
Felix
Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928
[-- Attachment #2: foo.cc --]
[-- Type: application/octet-stream, Size: 227 bytes --]
void foo(void) {
class DF {
public:
int a;
int b;
int vvv() {
class FFFF {
int ffff;
};
FFFF abcd;
return 1;
}
};
DF x;
int a = x.vvv();
}
int main(void) {
foo();
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: C++ nested class bug/questions
2021-06-22 11:27 C++ nested class bug/questions Willgerodt, Felix
@ 2021-06-22 19:01 ` Simon Marchi
2021-06-23 13:59 ` Willgerodt, Felix
0 siblings, 1 reply; 3+ messages in thread
From: Simon Marchi @ 2021-06-22 19:01 UTC (permalink / raw)
To: Willgerodt, Felix, gdb
On 2021-06-22 7:27 a.m., Willgerodt, Felix via Gdb wrote:
> Hello everyone,
>
> I was debugging a program similar to the one attached and noticed a couple
> of unexpected things happening. I compiled it with ”-g -O0” and g++ 11.1.0
> (clang showed similar behaviour) and saw this:
>
> (gdb) bt
> #0 DF::vvv (this=0x7fffffffd120) at foo.cc:11
> #1 0x0000555555555180 in foo () at foo.cc:16
> #2 0x00005555555551a7 in main () at foo.cc:20
> (gdb) ptype abcd
> type = class DF::FFFF {
> private:
> int ffff;
> }
> (gdb) ptype FFFF
> No symbol "FFFF" in current context.
> (gdb) ptype DF::
> FFFF vvv()
> (gdb) ptype DF::FFFF
> There is no field named FFFF
> (gdb) ptype 'DF::FFFF'
> type = class DF::FFFF {
> private:
> int ffff;
> }
> (gdb)
>
> (The fourth command shows tab completion.)
>
> The problems I see are:
> 1) I think it shouldn’t be DF::FFFF.
> 2) 'ptype FFFF’ should just work as it is in the current scope.
> 3) There shouldn’t be a need to quote DF:FFFF, right? Although that might just be a side-effect here.
> 4) The fact that a suggestion from tab completion doesn’t work is annoying. This is probably also be a side-effect.
>
> Before debugging this further, I wanted to see if there are any comments/suggestions.
> Am I even right about point 1? I couldn’t really find anything definitive
> in my favourite cpp reference on this type of nesting. g++ and clang output FFFF as
> foo()::DF::vvv()::FFFF as far as I can see.
>
> I don’t see any obvious problems in the dwarf that is produced.
>
> Thanks,
> Felix
I'm not a reference on this topic, but at first glance I agree with you.
Simon
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: C++ nested class bug/questions
2021-06-22 19:01 ` Simon Marchi
@ 2021-06-23 13:59 ` Willgerodt, Felix
0 siblings, 0 replies; 3+ messages in thread
From: Willgerodt, Felix @ 2021-06-23 13:59 UTC (permalink / raw)
To: Simon Marchi, gdb
> -----Original Message-----
> From: Simon Marchi <simon.marchi@polymtl.ca>
> Sent: Dienstag, 22. Juni 2021 21:01
> To: Willgerodt, Felix <felix.willgerodt@intel.com>; gdb@sourceware.org
> Subject: Re: C++ nested class bug/questions
>
> On 2021-06-22 7:27 a.m., Willgerodt, Felix via Gdb wrote:
> > Hello everyone,
> >
> > I was debugging a program similar to the one attached and noticed a
> > couple of unexpected things happening. I compiled it with ”-g -O0” and
> > g++ 11.1.0 (clang showed similar behaviour) and saw this:
> >
> > (gdb) bt
> > #0 DF::vvv (this=0x7fffffffd120) at foo.cc:11
> > #1 0x0000555555555180 in foo () at foo.cc:16
> > #2 0x00005555555551a7 in main () at foo.cc:20
> > (gdb) ptype abcd
> > type = class DF::FFFF {
> > private:
> > int ffff;
> > }
> > (gdb) ptype FFFF
> > No symbol "FFFF" in current context.
> > (gdb) ptype DF::
> > FFFF vvv()
> > (gdb) ptype DF::FFFF
> > There is no field named FFFF
> > (gdb) ptype 'DF::FFFF'
> > type = class DF::FFFF {
> > private:
> > int ffff;
> > }
> > (gdb)
> >
> > (The fourth command shows tab completion.)
> >
> > The problems I see are:
> > 1) I think it shouldn’t be DF::FFFF.
> > 2) 'ptype FFFF’ should just work as it is in the current scope.
> > 3) There shouldn’t be a need to quote DF:FFFF, right? Although that might
> just be a side-effect here.
> > 4) The fact that a suggestion from tab completion doesn’t work is annoying.
> This is probably also be a side-effect.
> >
> > Before debugging this further, I wanted to see if there are any
> comments/suggestions.
> > Am I even right about point 1? I couldn’t really find anything
> > definitive in my favourite cpp reference on this type of nesting. g++
> > and clang output FFFF as foo()::DF::vvv()::FFFF as far as I can see.
> >
> > I don’t see any obvious problems in the dwarf that is produced.
> >
> > Thanks,
> > Felix
>
> I'm not a reference on this topic, but at first glance I agree with you.
>
> Simon
I looked into this a bit today, and this patch seems to solve it for me:
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 57bcfb713db..fbff05ac153 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -22589,7 +22589,7 @@ determine_prefix (struct die_info *die, struct dwarf2_cu *cu)
&& (dwarf2_name (parent, cu) != NULL))
return dwarf2_name (parent, cu);
}
- return determine_prefix (parent, cu);
+ return "";
case DW_TAG_enumeration_type:
parent_type = read_type_die (parent, cu);
if (parent_type->is_declared_class ())
With this patch I see no regressions in gdb.cp and gdb.fortran.
But I am wondering why the current code even tries to go to the parent of the
subprogram (which is the "first level" parent) to get a prefix? I don't really see a use case for it.
But I am certainly not an expert in all languages that GDB understands and fear that I am
just missing the point. Does anyone have an idea?
I will try to test this more thoroughly and write a regression test in the meantime.
Regards,
Felix
Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-06-23 13:59 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-22 11:27 C++ nested class bug/questions Willgerodt, Felix
2021-06-22 19:01 ` Simon Marchi
2021-06-23 13:59 ` Willgerodt, Felix
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).