public inbox for archer-commits@sourceware.org
help / color / mirror / Atom feed
* [SCM]  archer-tromey-charset: avoid some typedef-stripping when printing a value
@ 2009-01-13 22:20 tromey
  0 siblings, 0 replies; only message in thread
From: tromey @ 2009-01-13 22:20 UTC (permalink / raw)
  To: archer-commits

The branch, archer-tromey-charset has been updated
       via  f0fab6ed91c0d78127a52afc1965003efe5e64f5 (commit)
      from  55fb85b195ef23a2ddba4e81337b32d3c2554e3e (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit f0fab6ed91c0d78127a52afc1965003efe5e64f5
Author: Tom Tromey <tromey@redhat.com>
Date:   Tue Jan 13 15:19:43 2009 -0700

    avoid some typedef-stripping when printing a value
    handle DW_TAG_typedef more nicely
    incorporate some code from Julian Brown

-----------------------------------------------------------------------

Summary of changes:
 gdb/ChangeLog    |    7 ++++++-
 gdb/c-valprint.c |   45 +++++++++++++++++++++++++--------------------
 gdb/dwarf2read.c |    1 +
 3 files changed, 32 insertions(+), 21 deletions(-)

First 500 lines of diff:
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 2835327..f36b5ef 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,8 @@
-2009-01-12  Tom Tromey  <tromey@redhat.com>
+2009-01-13  Tom Tromey  <tromey@redhat.com>
+	    Julian Brown  <julian@codesourcery.com>
 
+	* dwarf2read.c (process_die) <DW_TAG_typedef>: Call read_type_die
+	before calling new_symbol.
 	* value.h (value_typed_string): Declare.
 	(val_print_string): Update.
 	* valprint.h (print_char_chars): Update.
@@ -77,6 +80,8 @@
 	(textual_element_type): Handle wide character types.
 	(c_val_print): Pass original type to textual_element_type.  Handle
 	wide character types.
+	(c_value_print): Use textual_element_type.  Pass original type of
+	value to val_print.
 	* c-lang.h (enum c_string_type): New type.
 	(c_printchar, c_printstr): Update.
 	* c-lang.c (classify_type): New function.
diff --git a/gdb/c-valprint.c b/gdb/c-valprint.c
index 9e661c5..00fcc58 100644
--- a/gdb/c-valprint.c
+++ b/gdb/c-valprint.c
@@ -136,7 +136,8 @@ c_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
 {
   unsigned int i = 0;	/* Number of characters printed */
   unsigned len;
-  struct type *elttype, *orig_type = type;
+  struct type *elttype, *unresolved_elttype;
+  struct type *unresolved_type = type;
   unsigned eltlen;
   LONGEST val;
   CORE_ADDR addr;
@@ -145,8 +146,9 @@ c_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
   switch (TYPE_CODE (type))
     {
     case TYPE_CODE_ARRAY:
-      elttype = check_typedef (TYPE_TARGET_TYPE (type));
-      if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0)
+      unresolved_elttype = TYPE_TARGET_TYPE (type);
+      elttype = check_typedef (unresolved_elttype);
+      if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (unresolved_elttype) > 0)
 	{
 	  eltlen = TYPE_LENGTH (elttype);
 	  len = TYPE_LENGTH (type) / eltlen;
@@ -156,7 +158,7 @@ c_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
 	    }
 
 	  /* Print arrays of textual chars with a string syntax.  */
-          if (textual_element_type (TYPE_TARGET_TYPE (type), options->format))
+          if (textual_element_type (unresolved_elttype, options->format))
 	    {
 	      /* If requested, look for the first null char and only print
 	         elements up to it.  */
@@ -175,7 +177,7 @@ c_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
 		  len = temp_len;
 		}
 
-	      LA_PRINT_STRING (stream, TYPE_TARGET_TYPE (type),
+	      LA_PRINT_STRING (stream, unresolved_elttype,
 			       valaddr + embedded_offset, len, 0, options);
 	      i = len;
 	    }
@@ -234,7 +236,8 @@ c_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
 	  print_function_pointer_address (addr, stream, options->addressprint);
 	  break;
 	}
-      elttype = check_typedef (TYPE_TARGET_TYPE (type));
+      unresolved_elttype = TYPE_TARGET_TYPE (type);
+      elttype = check_typedef (unresolved_elttype);
 	{
 	  addr = unpack_pointer (type, valaddr + embedded_offset);
 	print_unpacked_pointer:
@@ -254,10 +257,10 @@ c_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
 	  /* For a pointer to a textual type, also print the string
 	     pointed to, unless pointer is null.  */
 
-	  if (textual_element_type (TYPE_TARGET_TYPE (type), options->format)
+	  if (textual_element_type (unresolved_elttype, options->format)
 	      && addr != 0)
 	    {
-	      i = val_print_string (TYPE_TARGET_TYPE (type), addr, -1, stream,
+	      i = val_print_string (unresolved_elttype, addr, -1, stream,
 				    options);
 	    }
 	  else if (cp_is_vtbl_member (type))
@@ -292,7 +295,7 @@ c_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
 		    }
 		  else
 		    {
-		      wtype = TYPE_TARGET_TYPE (type);
+		      wtype = unresolved_elttype;
 		    }
 		  vt_val = value_at (wtype, vt_address);
 		  common_val_print (vt_val, stream, recurse + 1, options,
@@ -466,11 +469,11 @@ c_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
 	     Since we don't know whether the value is really intended to
 	     be used as an integer or a character, print the character
 	     equivalent as well.  */
-	  if (textual_element_type (type, options->format))
+	  if (textual_element_type (unresolved_type, options->format))
 	    {
 	      fputs_filtered (" ", stream);
 	      LA_PRINT_CHAR ((unsigned char) unpack_long (type, valaddr + embedded_offset),
-			     orig_type, stream);
+			     unresolved_type, stream);
 	    }
 	}
       break;
@@ -492,7 +495,7 @@ c_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
 	  else
 	    fprintf_filtered (stream, "%d", (int) val);
 	  fputs_filtered (" ", stream);
-	  LA_PRINT_CHAR ((unsigned char) val, orig_type, stream);
+	  LA_PRINT_CHAR ((unsigned char) val, unresolved_type, stream);
 	}
       break;
 
@@ -564,7 +567,7 @@ int
 c_value_print (struct value *val, struct ui_file *stream, 
 	       const struct value_print_options *options)
 {
-  struct type *type, *real_type;
+  struct type *type, *real_type, *val_type;
   int full, top, using_enc;
   struct value_print_options opts = *options;
 
@@ -577,19 +580,20 @@ c_value_print (struct value *val, struct ui_file *stream,
      C++: if it is a member pointer, we will take care
      of that when we print it.  */
 
-  type = check_typedef (value_type (val));
+  /* Preserve the original type before stripping typedefs.  We prefer
+     to pass down the original type when possible, but for local
+     checks it is better to look past the typedefs.  */
+  val_type = value_type (val);
+  type = check_typedef (val_type);
 
   if (TYPE_CODE (type) == TYPE_CODE_PTR
       || TYPE_CODE (type) == TYPE_CODE_REF)
     {
       /* Hack:  remove (char *) for char strings.  Their
-         type is indicated by the quoted string anyway.
-         (Don't use textual_element_type here; quoted strings
-         are always exactly (char *).  */
+         type is indicated by the quoted string anyway.  */
       if (TYPE_CODE (type) == TYPE_CODE_PTR
 	  && TYPE_NAME (type) == NULL
-	  && TYPE_NAME (TYPE_TARGET_TYPE (type)) != NULL
-	  && strcmp (TYPE_NAME (TYPE_TARGET_TYPE (type)), "char") == 0)
+	  && textual_element_type (val_type, opts.format))
 	{
 	  /* Print nothing */
 	}
@@ -632,6 +636,7 @@ c_value_print (struct value *val, struct ui_file *stream,
             }
           type_print (type, "", stream, -1);
 	  fprintf_filtered (stream, ") ");
+	  val_type = type;
 	}
       else
 	{
@@ -677,7 +682,7 @@ c_value_print (struct value *val, struct ui_file *stream,
       /* Otherwise, we end up at the return outside this "if" */
     }
 
-  return val_print (type, value_contents_all (val),
+  return val_print (val_type, value_contents_all (val),
 		    value_embedded_offset (val),
 		    VALUE_ADDRESS (val) + value_offset (val),
 		    stream, 0, &opts, current_language);
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 4f2f7fb..0d30abc 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -2809,6 +2809,7 @@ process_die (struct die_info *die, struct dwarf2_cu *cu)
 
     case DW_TAG_base_type:
     case DW_TAG_subrange_type:
+    case DW_TAG_typedef:
       /* Add a typedef symbol for the type definition, if it has a
          DW_AT_name.  */
       new_symbol (die, read_type_die (die, cu), cu);


hooks/post-receive
--
Repository for Project Archer.


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2009-01-13 22:20 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-01-13 22:20 [SCM] archer-tromey-charset: avoid some typedef-stripping when printing a value tromey

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).