* value.h (value_print): Return void.
[deliverable/binutils-gdb.git] / gdb / c-valprint.c
index baad597cf023a4977af6763ca6b90ae2a02e699b..98901ce5a8eb1a5f3b237d1898872542ca60c941 100644 (file)
@@ -1,8 +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, 2010, 2011
-   Free Software Foundation, Inc.
+   Copyright (C) 1986, 1988-1989, 1991-2001, 2003, 2005-2012 Free
+   Software Foundation, Inc.
 
    This file is part of GDB.
 
 #include "target.h"
 \f
 
-/* Print function pointer with inferior address ADDRESS onto stdio
-   stream STREAM.  */
-
-static void
-print_function_pointer_address (struct gdbarch *gdbarch,
-                               CORE_ADDR address,
-                               struct ui_file *stream,
-                               int addressprint)
-{
-  CORE_ADDR func_addr
-    = gdbarch_convert_from_func_ptr_addr (gdbarch, address,
-                                         &current_target);
-
-  /* If the function pointer is represented by a description, print
-     the address of the description.  */
-  if (addressprint && func_addr != address)
-    {
-      fputs_filtered ("@", stream);
-      fputs_filtered (paddress (gdbarch, address), stream);
-      fputs_filtered (": ", stream);
-    }
-  print_address_demangle (gdbarch, func_addr, stream, demangle);
-}
-
-
 /* A helper for c_textual_element_type.  This checks the name of the
    typedef.  This is bogus but it isn't apparent that the compiler
    provides us the help we may need.  */
@@ -187,6 +161,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)))
@@ -238,7 +214,7 @@ c_val_print (struct type *type, const gdb_byte *valaddr,
        }
       /* Array of unspecified length: treat like pointer to first
         elt.  */
-      addr = address;
+      addr = address + embedded_offset;
       goto print_unpacked_pointer;
 
     case TYPE_CODE_MEMBERPTR:
@@ -378,10 +354,19 @@ c_val_print (struct type *type, const gdb_byte *valaddr,
        {
          if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF)
            {
-             struct value *deref_val =
-               value_at
-               (TYPE_TARGET_TYPE (type),
-                unpack_pointer (type, valaddr + embedded_offset));
+             struct value *deref_val;
+
+             deref_val = coerce_ref_if_computed (original_value);
+             if (deref_val != NULL)
+               {
+                 /* More complicated computed references are not supported.  */
+                 gdb_assert (embedded_offset == 0);
+               }
+             else
+               deref_val = value_at (TYPE_TARGET_TYPE (type),
+                                     unpack_pointer (type,
+                                                     (valaddr
+                                                      + embedded_offset)));
 
              common_val_print (deref_val, stream, recurse, options,
                                current_language);
@@ -446,10 +431,41 @@ c_val_print (struct type *type, const gdb_byte *valaddr,
        {
          fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
        }
-      else
+      else if (TYPE_FLAG_ENUM (type))
        {
-         print_longest (stream, 'd', 0, val);
+         int first = 1;
+
+         /* We have a "flag" enum, so we try to decompose it into
+            pieces as appropriate.  A flag enum has disjoint
+            constants by definition.  */
+         fputs_filtered ("(", stream);
+         for (i = 0; i < len; ++i)
+           {
+             QUIT;
+
+             if ((val & TYPE_FIELD_BITPOS (type, i)) != 0)
+               {
+                 if (!first)
+                   fputs_filtered (" | ", stream);
+                 first = 0;
+
+                 val &= ~TYPE_FIELD_BITPOS (type, i);
+                 fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
+               }
+           }
+
+         if (first || val != 0)
+           {
+             if (!first)
+               fputs_filtered (" | ", stream);
+             fputs_filtered ("unknown: ", stream);
+             print_longest (stream, 'd', 0, val);
+           }
+
+         fputs_filtered (")", stream);
        }
+      else
+       print_longest (stream, 'd', 0, val);
       break;
 
     case TYPE_CODE_FLAGS:
@@ -628,7 +644,7 @@ c_val_print (struct type *type, const gdb_byte *valaddr,
   return (0);
 }
 \f
-int
+void
 c_value_print (struct value *val, struct ui_file *stream, 
               const struct value_print_options *options)
 {
@@ -684,29 +700,24 @@ 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.  */
-             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.  */
-            }
+
+         if (value_entirely_available (val))
+           {
+             real_type = value_rtti_indirect_type (val, &full, &top,
+                                                   &using_enc);
+             if (real_type)
+               {
+                 /* RTTI entry found.  */
+                 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;
@@ -737,10 +748,11 @@ 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_for_printing (val), 0,
-                           value_address (val), stream, 0,
-                           val, &opts, current_language);
+         val_print (value_enclosing_type (val),
+                    value_contents_for_printing (val), 0,
+                    value_address (val), stream, 0,
+                    val, &opts, current_language);
+         return;
           /* Note: When we look up RTTI entries, we don't get any
              information on const or volatile attributes.  */
        }
@@ -749,17 +761,18 @@ c_value_print (struct value *val, struct ui_file *stream,
          /* No RTTI information, so let's do our best.  */
          fprintf_filtered (stream, "(%s ?) ",
                            TYPE_NAME (value_enclosing_type (val)));
-         return val_print (value_enclosing_type (val),
-                           value_contents_for_printing (val), 0,
-                           value_address (val), stream, 0,
-                           val, &opts, current_language);
+         val_print (value_enclosing_type (val),
+                    value_contents_for_printing (val), 0,
+                    value_address (val), stream, 0,
+                    val, &opts, current_language);
+         return;
        }
       /* Otherwise, we end up at the return outside this "if".  */
     }
 
-  return val_print (val_type, value_contents_for_printing (val),
-                   value_embedded_offset (val),
-                   value_address (val),
-                   stream, 0,
-                   val, &opts, current_language);
+  val_print (val_type, value_contents_for_printing (val),
+            value_embedded_offset (val),
+            value_address (val),
+            stream, 0,
+            val, &opts, current_language);
 }
This page took 0.026034 seconds and 4 git commands to generate.