2010-10-08 Bernd Schmidt <bernds@codesourcery.com>
[deliverable/binutils-gdb.git] / gdb / c-valprint.c
index c20bfa78450e641c11346deed6788bba839adbb6..521460b21fca98113ac5a3692f068b7c306c0973 100644 (file)
@@ -1,7 +1,7 @@
 /* Support for printing C values for GDB, the GNU debugger.
 
    Copyright (C) 1986, 1988, 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
-   1998, 1999, 2000, 2001, 2003, 2005, 2006, 2007, 2008, 2009
+   1998, 1999, 2000, 2001, 2003, 2005, 2006, 2007, 2008, 2009, 2010
    Free Software Foundation, Inc.
 
    This file is part of GDB.
@@ -150,6 +150,7 @@ c_textual_element_type (struct type *type, char format)
 int
 c_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
             CORE_ADDR address, struct ui_file *stream, int recurse,
+            const struct value *original_value,
             const struct value_print_options *options)
 {
   struct gdbarch *gdbarch = get_type_arch (type);
@@ -177,8 +178,12 @@ c_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
              print_spaces_filtered (2 + 2 * recurse, stream);
            }
 
-         /* Print arrays of textual chars with a string syntax.  */
-          if (c_textual_element_type (unresolved_elttype, options->format))
+         /* Print arrays of textual chars with a string syntax, as
+            long as the entire array is valid.  */
+          if (c_textual_element_type (unresolved_elttype, options->format)
+             && value_bits_valid (original_value,
+                                  TARGET_CHAR_BIT * embedded_offset,
+                                  TARGET_CHAR_BIT * TYPE_LENGTH (type)))
            {
              /* If requested, look for the first null char and only print
                 elements up to it.  */
@@ -191,14 +196,15 @@ c_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
                        && temp_len < options->print_max
                        && extract_unsigned_integer (valaddr + embedded_offset
                                                     + temp_len * eltlen,
-                                                    eltlen, byte_order) == 0);
+                                                    eltlen, byte_order) != 0);
                       ++temp_len)
                    ;
                  len = temp_len;
                }
 
              LA_PRINT_STRING (stream, unresolved_elttype,
-                              valaddr + embedded_offset, len, 0, options);
+                              valaddr + embedded_offset, len,
+                              NULL, 0, options);
              i = len;
            }
          else
@@ -215,8 +221,9 @@ c_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
                {
                  i = 0;
                }
-             val_print_array_elements (type, valaddr + embedded_offset, address, stream,
-                                       recurse, options, i);
+             val_print_array_elements (type, valaddr + embedded_offset,
+                                       address + embedded_offset, stream,
+                                       recurse, original_value, options, i);
              fprintf_filtered (stream, "}");
            }
          break;
@@ -253,6 +260,7 @@ c_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
             -fvtable_thunks.  (Otherwise, look under TYPE_CODE_STRUCT.) */
          CORE_ADDR addr
            = extract_typed_address (valaddr + embedded_offset, type);
+
          print_function_pointer_address (gdbarch, addr, stream,
                                          options->addressprint);
          break;
@@ -291,8 +299,8 @@ c_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
 
              struct minimal_symbol *msymbol =
              lookup_minimal_symbol_by_pc (vt_address);
-             if ((msymbol != NULL) &&
-                 (vt_address == SYMBOL_VALUE_ADDRESS (msymbol)))
+             if ((msymbol != NULL)
+                 && (vt_address == SYMBOL_VALUE_ADDRESS (msymbol)))
                {
                  fputs_filtered (" <", stream);
                  fputs_filtered (SYMBOL_PRINT_NAME (msymbol), stream);
@@ -342,6 +350,7 @@ c_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
        {
          CORE_ADDR addr
            = extract_typed_address (valaddr + embedded_offset, type);
+
          fprintf_filtered (stream, "@");
          fputs_filtered (paddress (gdbarch, addr), stream);
          if (options->deref_ref)
@@ -353,9 +362,10 @@ c_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
          if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF)
            {
              struct value *deref_val =
-             value_at
-             (TYPE_TARGET_TYPE (type),
-              unpack_pointer (type, valaddr + embedded_offset));
+               value_at
+               (TYPE_TARGET_TYPE (type),
+                unpack_pointer (type, valaddr + embedded_offset));
+
              common_val_print (deref_val, stream, recurse, options,
                                current_language);
            }
@@ -388,8 +398,9 @@ c_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
                                          options->addressprint);
        }
       else
-       cp_print_value_fields (type, type, valaddr, embedded_offset, address, stream,
-                              recurse, options, NULL, 0);
+       cp_print_value_fields_rtti (type, valaddr,
+                                   embedded_offset, address, stream,
+                                   recurse, original_value, options, NULL, 0);
       break;
 
     case TYPE_CODE_ENUM:
@@ -479,6 +490,7 @@ c_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
       if (options->format || options->output_format)
        {
          struct value_print_options opts = *options;
+
          opts.format = (options->format ? options->format
                         : options->output_format);
          print_scalar_formatted (valaddr + embedded_offset, type,
@@ -546,7 +558,7 @@ c_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
       break;
 
     case TYPE_CODE_ERROR:
-      fprintf_filtered (stream, _("<error type>"));
+      fprintf_filtered (stream, "%s", TYPE_ERROR_NAME (type));
       break;
 
     case TYPE_CODE_UNDEF:
@@ -689,9 +701,9 @@ c_value_print (struct value *val, struct ui_file *stream,
                            full ? "" : _(" [incomplete object]"));
          /* Print out object: enclosing type is same as real_type if full */
          return val_print (value_enclosing_type (val),
-                           value_contents_all (val), 0,
+                           value_contents_for_printing (val), 0,
                            value_address (val), stream, 0,
-                           &opts, current_language);
+                           val, &opts, current_language);
           /* Note: When we look up RTTI entries, we don't get any information on
              const or volatile attributes */
        }
@@ -701,15 +713,16 @@ c_value_print (struct value *val, struct ui_file *stream,
          fprintf_filtered (stream, "(%s ?) ",
                            TYPE_NAME (value_enclosing_type (val)));
          return val_print (value_enclosing_type (val),
-                           value_contents_all (val), 0,
+                           value_contents_for_printing (val), 0,
                            value_address (val), stream, 0,
-                           &opts, current_language);
+                           val, &opts, current_language);
        }
       /* Otherwise, we end up at the return outside this "if" */
     }
 
-  return val_print (val_type, value_contents_all (val),
+  return val_print (val_type, value_contents_for_printing (val),
                    value_embedded_offset (val),
                    value_address (val),
-                   stream, 0, &opts, current_language);
+                   stream, 0,
+                   val, &opts, current_language);
 }
This page took 0.029414 seconds and 4 git commands to generate.