gdb/
[deliverable/binutils-gdb.git] / gdb / c-valprint.c
index 0c23c7e1ecab4cc335b9315b2db76af723c6eaa4..76579d2116c1a016fdb14f516ed2d57503c53629 100644 (file)
@@ -142,13 +142,9 @@ c_textual_element_type (struct type *type, char format)
   return 0;
 }
 
-
-/* Print data of type TYPE located at VALADDR (within GDB), which came
-   from the inferior at address ADDRESS, onto stdio stream STREAM
-   according to OPTIONS.  The data at VALADDR is in target byte order.
-
-   If the data are a string pointer, returns the number of string
-   characters printed.  */
+/* See val_print for a description of the various parameters of this
+   function; they are identical.  The semantics of the return value is
+   also identical to val_print.  */
 
 int
 c_val_print (struct type *type, const gdb_byte *valaddr,
@@ -191,6 +187,8 @@ c_val_print (struct type *type, const gdb_byte *valaddr,
             long as the entire array is valid.  */
           if (c_textual_element_type (unresolved_elttype,
                                      options->format)
+             && value_bytes_available (original_value, embedded_offset,
+                                       TYPE_LENGTH (type))
              && value_bits_valid (original_value,
                                   TARGET_CHAR_BIT * embedded_offset,
                                   TARGET_CHAR_BIT * TYPE_LENGTH (type)))
@@ -233,24 +231,23 @@ c_val_print (struct type *type, const gdb_byte *valaddr,
                {
                  i = 0;
                }
-             val_print_array_elements (type, valaddr + embedded_offset,
-                                       address + embedded_offset,
-                                       stream, recurse,
-                                       original_value, options, i);
+             val_print_array_elements (type, valaddr, embedded_offset,
+                                       address, stream,
+                                       recurse, original_value, options, i);
              fprintf_filtered (stream, "}");
            }
          break;
        }
       /* Array of unspecified length: treat like pointer to first
         elt.  */
-      addr = address;
+      addr = address + embedded_offset;
       goto print_unpacked_pointer;
 
     case TYPE_CODE_MEMBERPTR:
       if (options->format)
        {
-         print_scalar_formatted (valaddr + embedded_offset, type,
-                                 options, 0, stream);
+         val_print_scalar_formatted (type, valaddr, embedded_offset,
+                                     original_value, options, 0, stream);
          break;
        }
       cp_print_class_member (valaddr + embedded_offset, type, stream, "&");
@@ -263,8 +260,8 @@ c_val_print (struct type *type, const gdb_byte *valaddr,
     case TYPE_CODE_PTR:
       if (options->format && options->format != 's')
        {
-         print_scalar_formatted (valaddr + embedded_offset, type,
-                                 options, 0, stream);
+         val_print_scalar_formatted (type, valaddr, embedded_offset,
+                                     original_value, options, 0, stream);
          break;
        }
       if (options->vtblprint && cp_is_vtbl_ptr_type (type))
@@ -433,8 +430,8 @@ c_val_print (struct type *type, const gdb_byte *valaddr,
     case TYPE_CODE_ENUM:
       if (options->format)
        {
-         print_scalar_formatted (valaddr + embedded_offset, type,
-                                 options, 0, stream);
+         val_print_scalar_formatted (type, valaddr, embedded_offset,
+                                     original_value, options, 0, stream);
          break;
        }
       len = TYPE_NFIELDS (type);
@@ -459,8 +456,8 @@ c_val_print (struct type *type, const gdb_byte *valaddr,
 
     case TYPE_CODE_FLAGS:
       if (options->format)
-         print_scalar_formatted (valaddr + embedded_offset, type,
-                                 options, 0, stream);
+       val_print_scalar_formatted (type, valaddr, embedded_offset,
+                                   original_value, options, 0, stream);
       else
        val_print_type_code_flags (type, valaddr + embedded_offset,
                                   stream);
@@ -470,8 +467,8 @@ c_val_print (struct type *type, const gdb_byte *valaddr,
     case TYPE_CODE_METHOD:
       if (options->format)
        {
-         print_scalar_formatted (valaddr + embedded_offset, type,
-                                 options, 0, stream);
+         val_print_scalar_formatted (type, valaddr, embedded_offset,
+                                     original_value, options, 0, stream);
          break;
        }
       /* FIXME, we should consider, at least for ANSI C language,
@@ -490,8 +487,8 @@ c_val_print (struct type *type, const gdb_byte *valaddr,
          struct value_print_options opts = *options;
          opts.format = (options->format ? options->format
                         : options->output_format);
-         print_scalar_formatted (valaddr + embedded_offset, type,
-                                 &opts, 0, stream);
+         val_print_scalar_formatted (type, valaddr, embedded_offset,
+                                     original_value, &opts, 0, stream);
        }
       else
        {
@@ -522,8 +519,8 @@ c_val_print (struct type *type, const gdb_byte *valaddr,
 
          opts.format = (options->format ? options->format
                         : options->output_format);
-         print_scalar_formatted (valaddr + embedded_offset, type,
-                                 &opts, 0, stream);
+         val_print_scalar_formatted (type, valaddr, embedded_offset,
+                                     original_value, &opts, 0, stream);
        }
       else
        {
@@ -536,9 +533,7 @@ c_val_print (struct type *type, const gdb_byte *valaddr,
          if (c_textual_element_type (unresolved_type, options->format))
            {
              fputs_filtered (" ", stream);
-             LA_PRINT_CHAR ((unsigned char) unpack_long (type,
-                                                         valaddr
-                                                         + embedded_offset),
+             LA_PRINT_CHAR (unpack_long (type, valaddr + embedded_offset),
                             unresolved_type, stream);
            }
        }
@@ -550,8 +545,8 @@ c_val_print (struct type *type, const gdb_byte *valaddr,
          struct value_print_options opts = *options;
          opts.format = (options->format ? options->format
                         : options->output_format);
-         print_scalar_formatted (valaddr + embedded_offset, type,
-                                 &opts, 0, stream);
+         val_print_scalar_formatted (type, valaddr, embedded_offset,
+                                     original_value, &opts, 0, stream);
        }
       else
        {
@@ -561,15 +556,15 @@ c_val_print (struct type *type, const gdb_byte *valaddr,
          else
            fprintf_filtered (stream, "%d", (int) val);
          fputs_filtered (" ", stream);
-         LA_PRINT_CHAR ((unsigned char) val, unresolved_type, stream);
+         LA_PRINT_CHAR (val, unresolved_type, stream);
        }
       break;
 
     case TYPE_CODE_FLT:
       if (options->format)
        {
-         print_scalar_formatted (valaddr + embedded_offset, type,
-                                 options, 0, stream);
+         val_print_scalar_formatted (type, valaddr, embedded_offset,
+                                     original_value, options, 0, stream);
        }
       else
        {
@@ -579,8 +574,8 @@ c_val_print (struct type *type, const gdb_byte *valaddr,
 
     case TYPE_CODE_DECFLOAT:
       if (options->format)
-       print_scalar_formatted (valaddr + embedded_offset, type,
-                               options, 0, stream);
+       val_print_scalar_formatted (type, valaddr, embedded_offset,
+                                   original_value, options, 0, stream);
       else
        print_decimal_floating (valaddr + embedded_offset,
                                type, stream);
@@ -604,19 +599,21 @@ c_val_print (struct type *type, const gdb_byte *valaddr,
 
     case TYPE_CODE_COMPLEX:
       if (options->format)
-       print_scalar_formatted (valaddr + embedded_offset,
-                               TYPE_TARGET_TYPE (type),
-                               options, 0, stream);
+       val_print_scalar_formatted (TYPE_TARGET_TYPE (type),
+                                   valaddr, embedded_offset,
+                                   original_value, options, 0, stream);
       else
        print_floating (valaddr + embedded_offset,
                        TYPE_TARGET_TYPE (type),
                        stream);
       fprintf_filtered (stream, " + ");
       if (options->format)
-       print_scalar_formatted (valaddr + embedded_offset
-                               + TYPE_LENGTH (TYPE_TARGET_TYPE (type)),
-                               TYPE_TARGET_TYPE (type),
-                               options, 0, stream);
+       val_print_scalar_formatted (TYPE_TARGET_TYPE (type),
+                                   valaddr,
+                                   embedded_offset
+                                   + TYPE_LENGTH (TYPE_TARGET_TYPE (type)),
+                                   original_value,
+                                   options, 0, stream);
       else
        print_floating (valaddr + embedded_offset
                        + TYPE_LENGTH (TYPE_TARGET_TYPE (type)),
@@ -689,30 +686,33 @@ c_value_print (struct value *val, struct ui_file *stream,
            }
          /* Pointer to class, check real type of object.  */
          fprintf_filtered (stream, "(");
-          real_type = value_rtti_target_type (val, &full,
-                                             &top, &using_enc);
-          if (real_type)
-           {
-             /* RTTI entry found.  */
-              if (TYPE_CODE (type) == TYPE_CODE_PTR)
-                {
-                  /* Create a pointer type pointing to the real
-                    type.  */
-                  type = lookup_pointer_type (real_type);
-                }
-              else
-                {
-                  /* Create a reference type referencing the real
-                    type.  */
-                  type = lookup_reference_type (real_type);
-                }
-             /* JYG: Need to adjust pointer value.  */
-             /* NOTE: cagney/2005-01-02: THIS IS BOGUS.  */
-              value_contents_writeable (val)[0] -= top;
-
-              /* Note: When we look up RTTI entries, we don't get any 
-                 information on const or volatile attributes.  */
-            }
+
+         if (value_entirely_available (val))
+           {
+             real_type = value_rtti_target_type (val, &full, &top, &using_enc);
+             if (real_type)
+               {
+                 /* RTTI entry found.  */
+                 if (TYPE_CODE (type) == TYPE_CODE_PTR)
+                   {
+                     /* Create a pointer type pointing to the real
+                        type.  */
+                     type = lookup_pointer_type (real_type);
+                   }
+                 else
+                   {
+                     /* Create a reference type referencing the real
+                        type.  */
+                     type = lookup_reference_type (real_type);
+                   }
+                 /* Need to adjust pointer value.  */
+                 val = value_from_pointer (type, value_as_address (val) - top);
+
+                 /* Note: When we look up RTTI entries, we don't get
+                    any information on const or volatile
+                    attributes.  */
+               }
+           }
           type_print (type, "", stream, -1);
          fprintf_filtered (stream, ") ");
          val_type = type;
This page took 0.039705 seconds and 4 git commands to generate.