This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[commit/Ada] crash when printing type of tagged type


If the debugging info is incorrect or incomplete, printing the
type description of a variable that's a variant tagged type can
trigger a crash.  The crash comes from us trying print a NULL
string which was supposed to be the parent type name.

We observed this behavior on bareboard targets where a-tags is
not always linked in, as is the case for native platforms, for
instance. Coupled with -feliminate-unused-debug-types, this leads
to GDB being unable to find type ada__tags__type_specific_data,
without which printing the type description above cannot be done
acurately.  There is an easy workaround for this limitation,
which is to compile at least 1 unit with
-fno-eliminate-unused-debug-types, but GDB should also be made
resilient to this situation.

gdb/ChangeLog:

        * ada-typeprint.c (print_record_type): If unable to decode
        the name of the parent type, use the encoded name.

Tested on x86_64-linux, as well as in the "faulty" situation.
No test, since you'd need a buggy runtime to reproduce the problem.
Checked in.

---
 gdb/ChangeLog       |    5 +++++
 gdb/ada-typeprint.c |   13 +++++++++++--
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 1d1eef5..773f887 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2011-07-01  Joel Brobecker  <brobecker@adacore.com>
+
+	* ada-typeprint.c (print_record_type): If unable to decode
+	the name of the parent type, use the encoded name.
+
 2011-07-01  Jean-Charles Delay  <delay@adacore.com>
 
 	* ada-typeprint.c (ada_print_type): Fix both PAD type and
diff --git a/gdb/ada-typeprint.c b/gdb/ada-typeprint.c
index 6bae634..bbcef55 100644
--- a/gdb/ada-typeprint.c
+++ b/gdb/ada-typeprint.c
@@ -621,8 +621,17 @@ print_record_type (struct type *type0, struct ui_file *stream, int show,
 
   parent_type = ada_parent_type (type);
   if (ada_type_name (parent_type) != NULL)
-    fprintf_filtered (stream, "new %s with record",
-		      decoded_type_name (parent_type));
+    {
+      const char *parent_name = decoded_type_name (parent_type);
+
+      /* If we fail to decode the parent type name, then use the parent
+	 type name as is.  Not pretty, but should never happen except
+	 when the debugging info is incomplete or incorrect.  This
+	 prevents a crash trying to print a NULL pointer.  */
+      if (parent_name == NULL)
+	parent_name = ada_type_name (parent_type);
+      fprintf_filtered (stream, "new %s with record", parent_name);
+    }
   else if (parent_type == NULL && ada_is_tagged_type (type, 0))
     fprintf_filtered (stream, "tagged record");
   else
-- 
1.7.1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]