Fix a crash with maintenance print type for GNAT stuff

Message ID 551BC260.30308@adacore.com
State New, archived
Headers

Commit Message

Pierre-Marie de Rodat April 1, 2015, 10:03 a.m. UTC
  Hello,

The attached patch fixes a crash in GDB when running the "maintenance 
print type" command on a type tree that includes "GNAT stuff" (i.e. GNAT 
descriptive types). This occurs only with AdaCore's version of GDB 
because our dwarf2read.c:need_gnat_info's implementation sometimes 
returns true.

As a consequence I cannot write a meaningful regression testcase for 
this. The patch does not trigger regressions on x86_64-linux, though. Ok 
for master?

Thank you in advance!

gdb/ChangeLog:
2015-04-01  Pierre-Marie de Rodat  <derodat@adacore.com>

         * gdbtypes.c (print_gnat_stuff): Do not recurse on the
         descriptive type when there is none.
  

Comments

Joel Brobecker April 1, 2015, 2:25 p.m. UTC | #1
> The attached patch fixes a crash in GDB when running the
> "maintenance print type" command on a type tree that includes "GNAT
> stuff" (i.e. GNAT descriptive types). This occurs only with
> AdaCore's version of GDB because our dwarf2read.c:need_gnat_info's
> implementation sometimes returns true.
> 
> As a consequence I cannot write a meaningful regression testcase for
> this. The patch does not trigger regressions on x86_64-linux,
> though. Ok for master?

I was telling Pierre-Marie at the time that I thought the patch
to be sufficiently self-evident that we could submit it without
a testcase.

> gdb/ChangeLog:
> 2015-04-01  Pierre-Marie de Rodat  <derodat@adacore.com>
> 
>         * gdbtypes.c (print_gnat_stuff): Do not recurse on the
>         descriptive type when there is none.

Give it a week, and if no one objects, then go ahead and push.
Thanks!

Patch intentionally left below for easy reference, but no further
comment below (so, no need to keep scrolling down unless you're
looking for the patch).

> >From 96121045f9c03f36893fde658136d840be22aa1b Mon Sep 17 00:00:00 2001
> From: Pierre-Marie de Rodat <derodat@adacore.com>
> Date: Tue, 10 Mar 2015 15:43:09 +0100
> Subject: [PATCH] Fix printing for GNAT stuff for types that do not have descr.
>  types
> 
> gdb/ChangeLog:
> 2015-04-01  Pierre-Marie de Rodat  <derodat@adacore.com>
> 
> 	* gdbtypes.c (print_gnat_stuff): Do not recurse on the
> 	descriptive type when there is none.
> ---
>  gdb/gdbtypes.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
> index 217ec70..103b4e2 100644
> --- a/gdb/gdbtypes.c
> +++ b/gdb/gdbtypes.c
> @@ -3888,7 +3888,13 @@ print_gnat_stuff (struct type *type, int spaces)
>  {
>    struct type *descriptive_type = TYPE_DESCRIPTIVE_TYPE (type);
>  
> -  recursive_dump_type (descriptive_type, spaces + 2);
> +  if (descriptive_type == NULL)
> +    printfi_filtered (spaces + 2, "no descriptive type\n");
> +  else
> +    {
> +      printfi_filtered (spaces + 2, "descriptive type\n");
> +      recursive_dump_type (descriptive_type, spaces + 4);
> +    }
>  }
>  
>  static struct obstack dont_print_type_obstack;
> -- 
> 2.3.4
>
  
Pierre-Marie de Rodat April 24, 2015, 2:14 p.m. UTC | #2
On 04/01/2015 04:25 PM, Joel Brobecker wrote:
> Give it a week, and if no one objects, then go ahead and push.
> Thanks!

Finally pushed. Thank you for the review!
  

Patch

From 96121045f9c03f36893fde658136d840be22aa1b Mon Sep 17 00:00:00 2001
From: Pierre-Marie de Rodat <derodat@adacore.com>
Date: Tue, 10 Mar 2015 15:43:09 +0100
Subject: [PATCH] Fix printing for GNAT stuff for types that do not have descr.
 types

gdb/ChangeLog:
2015-04-01  Pierre-Marie de Rodat  <derodat@adacore.com>

	* gdbtypes.c (print_gnat_stuff): Do not recurse on the
	descriptive type when there is none.
---
 gdb/gdbtypes.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 217ec70..103b4e2 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -3888,7 +3888,13 @@  print_gnat_stuff (struct type *type, int spaces)
 {
   struct type *descriptive_type = TYPE_DESCRIPTIVE_TYPE (type);
 
-  recursive_dump_type (descriptive_type, spaces + 2);
+  if (descriptive_type == NULL)
+    printfi_filtered (spaces + 2, "no descriptive type\n");
+  else
+    {
+      printfi_filtered (spaces + 2, "descriptive type\n");
+      recursive_dump_type (descriptive_type, spaces + 4);
+    }
 }
 
 static struct obstack dont_print_type_obstack;
-- 
2.3.4