Centralize printing "<optimized out>".
[deliverable/binutils-gdb.git] / gdb / cp-valprint.c
index a55255f9311236d9447833be6f02d9558fa5da9a..fff41d80f087cbb39ff2b4caeccda928dd08ccbb 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,
-   2000, 2001, 2002, 2003, 2005, 2006, 2007, 2008, 2009, 2010
+   2000, 2001, 2002, 2003, 2005, 2006, 2007, 2008, 2009, 2010, 2011
    Free Software Foundation, Inc.
 
    This file is part of GDB.
@@ -316,7 +316,7 @@ cp_print_value_fields (struct type *type, struct type *real_type,
                                          TYPE_FIELD_BITPOS (type, i),
                                          TYPE_FIELD_BITSIZE (type, i)))
                {
-                 fputs_filtered (_("<value optimized out>"), stream);
+                 val_print_optimized_out (stream);
                }
              else
                {
@@ -343,7 +343,7 @@ cp_print_value_fields (struct type *type, struct type *real_type,
                  struct value *v = value_static_field (type, i);
 
                  if (v == NULL)
-                   fputs_filtered ("<optimized out>", stream);
+                   val_print_optimized_out (stream);
                  else
                    cp_print_static_field (TYPE_FIELD_TYPE (type, i),
                                           v, stream, recurse + 1,
@@ -488,6 +488,7 @@ cp_print_value (struct type *type, struct type *real_type,
       struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i));
       char *basename = TYPE_NAME (baseclass);
       const gdb_byte *base_valaddr;
+      const struct value *base_val;
 
       if (BASETYPE_VIA_VIRTUAL (type, i))
        {
@@ -509,7 +510,7 @@ cp_print_value (struct type *type, struct type *real_type,
 
       boffset = baseclass_offset (type, i, valaddr + offset,
                                  address + offset);
-      skip = ((boffset == -1) || (boffset + offset) < 0) ? 1 : -1;
+      skip = ((boffset == -1) || (boffset + offset) < 0);
 
       if (BASETYPE_VIA_VIRTUAL (type, i))
        {
@@ -525,20 +526,28 @@ cp_print_value (struct type *type, struct type *real_type,
                 large.  */
              gdb_byte *buf = alloca (TYPE_LENGTH (baseclass));
 
-             base_valaddr = buf;
              if (target_read_memory (address + boffset, buf,
                                      TYPE_LENGTH (baseclass)) != 0)
                skip = 1;
-             address = address + boffset;
+             base_val = value_from_contents_and_address (baseclass,
+                                                         buf,
+                                                         address + boffset);
              thisoffset = 0;
              boffset = 0;
              thistype = baseclass;
+             base_valaddr = value_contents_for_printing_const (base_val);
            }
          else
-           base_valaddr = valaddr;
+           {
+             base_valaddr = valaddr;
+             base_val = val;
+           }
        }
       else
-       base_valaddr = valaddr;
+       {
+         base_valaddr = valaddr;
+         base_val = val;
+       }
 
       /* Now do the printing.  */
       if (options->pretty)
@@ -553,7 +562,7 @@ cp_print_value (struct type *type, struct type *real_type,
       fputs_filtered ("> = ", stream);
 
 
-      if (skip >= 1)
+      if (skip)
        fprintf_filtered (stream, "<invalid address>");
       else
        {
@@ -564,15 +573,17 @@ cp_print_value (struct type *type, struct type *real_type,
          if (!options->raw)
            result = apply_val_pretty_printer (baseclass, base_valaddr,
                                               thisoffset + boffset,
-                                              address,
-                                              stream, recurse,
-                                              val, options,
-                                              current_language);
+                                              value_address (base_val),
+                                              stream, recurse, base_val,
+                                              options, current_language);
+
+
                  
          if (!result)
            cp_print_value_fields (baseclass, thistype, base_valaddr,
-                                  thisoffset + boffset, address,
-                                  stream, recurse, val, options,
+                                  thisoffset + boffset,
+                                  value_address (base_val),
+                                  stream, recurse, base_val, options,
                                   ((struct type **)
                                    obstack_base (&dont_print_vb_obstack)),
                                   0);
This page took 0.027228 seconds and 4 git commands to generate.