Fix PR c++/23373: GDB hangs when printing a struct with a static member of itself
authorSergio Durigan Junior <sergiodj@redhat.com>
Sat, 7 Jul 2018 21:16:55 +0000 (17:16 -0400)
committerSergio Durigan Junior <sergiodj@redhat.com>
Wed, 11 Jul 2018 18:53:44 +0000 (14:53 -0400)
commit16ff70ddd430b63ca4dd68bf1d52828f2ed4f030
tree4c395a03f14336687f735b71bc86a31319e58a53
parentcb19713281c69c3625dd447a0c2ce539761989e2
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  <sergiodj@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  <sergiodj@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.
gdb/ChangeLog
gdb/c-typeprint.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/ptype-offsets.cc
gdb/testsuite/gdb.base/ptype-offsets.exp
This page took 0.025671 seconds and 4 git commands to generate.