public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: gdb-patches@sourceware.org
Subject: [patch+7.8] Fix 7.8 regression: resolve_dynamic_struct: Assertion `TYPE_NFIELDS (type) > 0' (PR 17642)
Date: Tue, 25 Nov 2014 19:54:00 -0000	[thread overview]
Message-ID: <20141125195444.GA3400@host2.jankratochvil.net> (raw)

[-- Attachment #1: Type: text/plain, Size: 1126 bytes --]

Hi,

https://sourceware.org/bugzilla/show_bug.cgi?id=17642
------------------------------------------------------------------------------
cat >2.c <<EOH
struct b;
struct c {
  struct b *bp;
} c;
int main(void) { return 0; }
EOH
cat >2b.c <<EOH
struct b {
  int a[0];
} use_b;
EOH
gcc -o 2 2.c 2b.c -Wall -g
# gcc-4.9.2-1.fc21.x86_64
gdb ./2 -ex 'p *c.bp'
# 520c7b56ac91e91120c59d7a85466ec9394277cf
gdbtypes.c:1811: internal-error: resolve_dynamic_struct: Assertion `TYPE_NFIELDS (type) > 0' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.

Regression since:
commit 012370f6818657a816df1463ee71ca4e4ee40b33
Author: Tom Tromey <tromey@redhat.com>
Date:   Thu May 8 11:26:44 2014 -0600
    handle VLA in a struct or union

Bugreport:
Regression with gdb scripts for Linux kernel
https://sourceware.org/ml/gdb/2014-08/msg00127.html

It is another missing check_typedef().
------------------------------------------------------------------------------

No regressions on {x86_64,x86_64-m32,i686}-fedora21pre-linux-gnu.

That big change after "else" is just reindentation.


Thanks,
Jan

[-- Attachment #2: vlatypes.patch --]
[-- Type: text/plain, Size: 6222 bytes --]

gdb/
2014-11-25  Jan Kratochvil  <jan.kratochvil@redhat.com>

	Fix internal error on stubs of dynamic types.
	* gdbtypes.c (resolve_dynamic_type_internal): Apply check_typedef to
	TYPE if not TYPE_CODE_TYPEDEF.

gdb/testsuite/
2014-11-25  Jan Kratochvil  <jan.kratochvil@redhat.com>

	Fix internal error on stubs of dynamic types.
	* gdb.base/vla-stub-define.c: New file.
	* gdb.base/vla-stub.c: New file.
	* gdb.base/vla-stub.exp: New file.

diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 61d259d..aa76604 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -1875,41 +1875,48 @@ resolve_dynamic_type_internal (struct type *type, CORE_ADDR addr,
   if (!is_dynamic_type_internal (real_type, top_level))
     return type;
 
-  switch (TYPE_CODE (type))
+  if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
     {
-    case TYPE_CODE_TYPEDEF:
       resolved_type = copy_type (type);
       TYPE_TARGET_TYPE (resolved_type)
 	= resolve_dynamic_type_internal (TYPE_TARGET_TYPE (type), addr,
 					 top_level);
-      break;
+    }
+  else 
+    {
+      /* Typedefs do not need to be preserved here but we need
+	 to resolve any possible stub types.  */
+      type = real_type;
 
-    case TYPE_CODE_REF:
-      {
-	CORE_ADDR target_addr = read_memory_typed_address (addr, type);
+      switch (TYPE_CODE (type))
+	{
+	case TYPE_CODE_REF:
+	  {
+	    CORE_ADDR target_addr = read_memory_typed_address (addr, type);
 
-	resolved_type = copy_type (type);
-	TYPE_TARGET_TYPE (resolved_type)
-	  = resolve_dynamic_type_internal (TYPE_TARGET_TYPE (type),
-					   target_addr, top_level);
-	break;
-      }
+	    resolved_type = copy_type (type);
+	    TYPE_TARGET_TYPE (resolved_type)
+	      = resolve_dynamic_type_internal (TYPE_TARGET_TYPE (type),
+					       target_addr, top_level);
+	    break;
+	  }
 
-    case TYPE_CODE_ARRAY:
-      resolved_type = resolve_dynamic_array (type, addr);
-      break;
+	case TYPE_CODE_ARRAY:
+	  resolved_type = resolve_dynamic_array (type, addr);
+	  break;
 
-    case TYPE_CODE_RANGE:
-      resolved_type = resolve_dynamic_range (type, addr);
-      break;
+	case TYPE_CODE_RANGE:
+	  resolved_type = resolve_dynamic_range (type, addr);
+	  break;
 
-    case TYPE_CODE_UNION:
-      resolved_type = resolve_dynamic_union (type, addr);
-      break;
+	case TYPE_CODE_UNION:
+	  resolved_type = resolve_dynamic_union (type, addr);
+	  break;
 
-    case TYPE_CODE_STRUCT:
-      resolved_type = resolve_dynamic_struct (type, addr);
-      break;
+	case TYPE_CODE_STRUCT:
+	  resolved_type = resolve_dynamic_struct (type, addr);
+	  break;
+	}
     }
 
   /* Resolve data_location attribute.  */
diff --git a/gdb/testsuite/gdb.base/vla-stub-define.c b/gdb/testsuite/gdb.base/vla-stub-define.c
new file mode 100644
index 0000000..7445a4f
--- /dev/null
+++ b/gdb/testsuite/gdb.base/vla-stub-define.c
@@ -0,0 +1,21 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2014 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+struct dynamic_struct
+{
+  int dynamic_field[0];
+} use_dynamic_struct;
diff --git a/gdb/testsuite/gdb.base/vla-stub.c b/gdb/testsuite/gdb.base/vla-stub.c
new file mode 100644
index 0000000..b7ccf041
--- /dev/null
+++ b/gdb/testsuite/gdb.base/vla-stub.c
@@ -0,0 +1,37 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2014 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+struct dynamic_struct;
+typedef struct dynamic_struct dynamic_struct_t;
+
+struct static_struct
+{
+  int field;
+};
+typedef struct static_struct static_struct_t;
+
+struct local_struct
+{
+  static_struct_t here;
+  dynamic_struct_t *ptr;
+} local_struct;
+
+int
+main (void)
+{
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.base/vla-stub.exp b/gdb/testsuite/gdb.base/vla-stub.exp
new file mode 100644
index 0000000..f8c9a91
--- /dev/null
+++ b/gdb/testsuite/gdb.base/vla-stub.exp
@@ -0,0 +1,25 @@
+# Copyright 2014 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+standard_testfile .c vla-stub-define.c
+if { [prepare_for_testing "failed to prepare for vla-stub.exp" \
+      ${testfile} [list ${srcfile} ${srcfile2}]] } {
+    return -1
+}
+
+gdb_test "p *local_struct.ptr" { = {dynamic_field = 0x0}}
+
+gdb_test "whatis local_struct.here" "type = static_struct_t"
+gdb_test "whatis *local_struct.ptr" "type = dynamic_struct_t"

             reply	other threads:[~2014-11-25 19:54 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-25 19:54 Jan Kratochvil [this message]
2014-12-13 14:23 ` Joel Brobecker
2014-12-13 14:39   ` [commit] " Jan Kratochvil
2014-12-13 18:18   ` Doug Evans
2014-12-15 15:06   ` Joel Brobecker
2014-12-15 15:21     ` Jan Kratochvil
2014-12-15 19:12     ` [commit 7.8] " Jan Kratochvil
2014-12-15 19:23       ` H.J. Lu
2014-12-15 19:37         ` Joel Brobecker
2014-12-15 20:02           ` H.J. Lu
2014-12-15 20:41             ` Joel Brobecker
2014-12-15 21:09               ` H.J. Lu
2014-12-15 22:11                 ` H.J. Lu
2014-12-15 22:44                   ` Joel Brobecker
2014-12-15 22:53                     ` H.J. Lu

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=20141125195444.GA3400@host2.jankratochvil.net \
    --to=jan.kratochvil@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /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).