Discussion:
[Bug c++/23373] New: ptype/o is broken by static "empty" member
vladimir.gubarev at techstories dot ru
2018-07-06 09:42:33 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=23373

Bug ID: 23373
Summary: ptype/o is broken by static "empty" member
Product: gdb
Version: 8.1
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
Assignee: unassigned at sourceware dot org
Reporter: vladimir.gubarev at techstories dot ru
Target Milestone: ---

In the following code we define a static member of type A in the A type itself.
The command hangs when it tries to recursively traverse the static member.

Example code:
struct A
{
static A Empty;
int a;
};

int main(void) {
A a;
return 0;
}

Output:
(gdb) ptype/o A
/* offset | size */ type = struct A {
static struct A {
static struct A {
static struct A {
static struct A {
static struct A {
static struct A {


Version:
gdb-8.1.tar.xz from 2018-01-30 22:43 https://ftp.gnu.org/gnu/gdb/
--
You are receiving this mail because:
You are on the CC list for the bug.
vladimir.gubarev at techstories dot ru
2018-07-06 09:45:46 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=23373

Vladimir Gubarev <vladimir.gubarev at techstories dot ru> changed:

What |Removed |Added
----------------------------------------------------------------------------
Summary|ptype/o is broken by static |ptype/o is hanged on static
|"empty" member |struct member of the same
| |type as struct is
--
You are receiving this mail because:
You are on the CC list for the bug.
vladimir.gubarev at techstories dot ru
2018-07-06 09:46:22 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=23373

Vladimir Gubarev <vladimir.gubarev at techstories dot ru> changed:

What |Removed |Added
----------------------------------------------------------------------------
CC| |***@techstorie
| |s.ru
--
You are receiving this mail because:
You are on the CC list for the bug.
sergiodj at redhat dot com
2018-07-06 21:06:14 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=23373

Sergio Durigan Junior <sergiodj at redhat dot com> changed:

What |Removed |Added
----------------------------------------------------------------------------
CC| |sergiodj at redhat dot com
--
You are receiving this mail because:
You are on the CC list for the bug.
sergiodj at redhat dot com
2018-07-07 21:27:17 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=23373

Sergio Durigan Junior <sergiodj at redhat dot com> changed:

What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |ASSIGNED
Last reconfirmed| |2018-07-07
Assignee|unassigned at sourceware dot org |sergiodj at redhat dot com
Ever confirmed|0 |1

--- Comment #1 from Sergio Durigan Junior <sergiodj at redhat dot com> ---
Patch posted: https://sourceware.org/ml/gdb-patches/2018-07/msg00179.html
--
You are receiving this mail because:
You are on the CC list for the bug.
sergiodj at redhat dot com
2018-07-09 19:23:20 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=23373

Sergio Durigan Junior <sergiodj at redhat dot com> changed:

What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |8.2
--
You are receiving this mail because:
You are on the CC list for the bug.
cvs-commit at gcc dot gnu.org
2018-07-11 18:54:36 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=23373

--- Comment #2 from cvs-commit at gcc dot gnu.org <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Sergio Durigan Junior
<***@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=16ff70ddd430b63ca4dd68bf1d52828f2ed4f030

commit 16ff70ddd430b63ca4dd68bf1d52828f2ed4f030
Author: Sergio Durigan Junior <***@redhat.com>
Date: Sat Jul 7 17:16:55 2018 -0400

Fix PR c++/23373: GDB hangs when printing a struct with a static member of
itself

This patch fixes a failure that happens when a structure has a static
member whose type is the same as itself. From the bug report:

Example code:
struct A
{
static A Empty;
int a;
};

int main(void) {
A a;
return 0;
}

Output:
(gdb) ptype/o A
/* offset | size */ type = struct A {
static struct A {
static struct A {
static struct A {
static struct A {
static struct A {
static struct A {
... # infinite loop

The problem here is that GDB is not taking into account the fact that
static members inside a class/struct are not stored in the
class/struct, and therefore they should not be accounted for during
the display of the offsets/sizes. The fix is simple: we just check if
the field we're dealing with (on
c-typeprint.c:c_type_print_base_struct_union) is static, and if it is
then we don't iterate over it.

This patch also adds a new test for this case, and doesn't introduce
any regressions. I believe it is important enough to be included in
the 8.2 branch.

OK?

gdb/ChangeLog:
2018-07-11 Sergio Durigan Junior <***@redhat.com>

PR c++/23373
* c-typeprint.c (c_type_print_base_struct_union): Don't print
offsets/sizes for static members of a class/struct.

gdb/testsuite/ChangeLog:
2018-07-11 Sergio Durigan Junior <***@redhat.com>

PR c++/23373
* gdb.base/ptype-offsets.cc (struct static_member): New
struct.
(main) <stmember>: New variable.
* gdb.base/ptype-offsets.exp: Add test for printing a struct
with a static member in it.
--
You are receiving this mail because:
You are on the CC list for the bug.
cvs-commit at gcc dot gnu.org
2018-07-11 18:56:05 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=23373

--- Comment #3 from cvs-commit at gcc dot gnu.org <cvs-commit at gcc dot gnu.org> ---
The gdb-8.2-branch branch has been updated by Sergio Durigan Junior
<***@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=ad3c631a762734c39b85086d20ba28940c2fc9b8

commit ad3c631a762734c39b85086d20ba28940c2fc9b8
Author: Sergio Durigan Junior <***@redhat.com>
Date: Sat Jul 7 17:16:55 2018 -0400

Fix PR c++/23373: GDB hangs when printing a struct with a static member of
itself

This patch fixes a failure that happens when a structure has a static
member whose type is the same as itself. From the bug report:

Example code:
struct A
{
static A Empty;
int a;
};

int main(void) {
A a;
return 0;
}

Output:
(gdb) ptype/o A
/* offset | size */ type = struct A {
static struct A {
static struct A {
static struct A {
static struct A {
static struct A {
static struct A {
... # infinite loop

The problem here is that GDB is not taking into account the fact that
static members inside a class/struct are not stored in the
class/struct, and therefore they should not be accounted for during
the display of the offsets/sizes. The fix is simple: we just check if
the field we're dealing with (on
c-typeprint.c:c_type_print_base_struct_union) is static, and if it is
then we don't iterate over it.

This patch also adds a new test for this case, and doesn't introduce
any regressions. I believe it is important enough to be included in
the 8.2 branch.

OK?

gdb/ChangeLog:
2018-07-11 Sergio Durigan Junior <***@redhat.com>

PR c++/23373
* c-typeprint.c (c_type_print_base_struct_union): Don't print
offsets/sizes for static members of a class/struct.

gdb/testsuite/ChangeLog:
2018-07-11 Sergio Durigan Junior <***@redhat.com>

PR c++/23373
* gdb.base/ptype-offsets.cc (struct static_member): New
struct.
(main) <stmember>: New variable.
* gdb.base/ptype-offsets.exp: Add test for printing a struct
with a static member in it.
--
You are receiving this mail because:
You are on the CC list for the bug.
sergiodj at redhat dot com
2018-07-11 13:27:11 UTC
Permalink
https://sourceware.org/bugzilla/show_bug.cgi?id=23373

Sergio Durigan Junior <sergiodj at redhat dot com> changed:

What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED

--- Comment #4 from Sergio Durigan Junior <sergiodj at redhat dot com> ---
Fix pushed to both master and 8.2.
--
You are receiving this mail because:
You are on the CC list for the bug.
Loading...