Thu Aug 7 13:39:31 1997 Geoffrey Noer <noer@cygnus.com>
[deliverable/binutils-gdb.git] / gdb / cp-valprint.c
index f68b7530138216b6434af166c30a5a84138a385c..e6790a4dd8ec100c130901677893dc4176d995e5 100644 (file)
@@ -1,5 +1,5 @@
 /* Support for printing C++ values for GDB, the GNU debugger.
-   Copyright 1986, 1988, 1989, 1991, 1994, 1995
+   Copyright 1986, 1988, 1989, 1991, 1994, 1995, 1996
    Free Software Foundation, Inc.
 
 This file is part of GDB.
@@ -30,6 +30,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 #include "annotate.h"
 #include "gdb_string.h"
 #include "c-lang.h"
+#include "target.h"
 
 int vtblprint;                 /* Controls printing of vtbl's */
 int objectprint;               /* Controls looking up an object's derived type
@@ -86,6 +87,8 @@ cp_print_class_method (valaddr, type, stream)
              QUIT;
              if (TYPE_FN_FIELD_VOFFSET (f, j) == offset)
                {
+                 if (TYPE_FN_FIELD_STUB (f, j))
+                   check_stub_method (domain, i, j);
                  kind = "virtual ";
                  goto common;
                }
@@ -120,21 +123,19 @@ cp_print_class_method (valaddr, type, stream)
   common:
   if (i < len)
     {
+      char *demangled_name;
+
       fprintf_filtered (stream, "&");
-      c_type_print_varspec_prefix (TYPE_FN_FIELD_TYPE (f, j), stream, 0, 0);
-      fprintf_unfiltered (stream, kind);
-      if (TYPE_FN_FIELD_PHYSNAME (f, j)[0] == '_'
-         && TYPE_FN_FIELD_PHYSNAME (f, j)[1] == CPLUS_MARKER)
-       {
-         cp_type_print_method_args (TYPE_FN_FIELD_ARGS (f, j) + 1, "~",
-                                    TYPE_FN_FIELDLIST_NAME (domain, i),
-                                    0, stream);
-       }
+      fprintf_filtered (stream, kind);
+      demangled_name = cplus_demangle (TYPE_FN_FIELD_PHYSNAME (f, j),
+                                      DMGL_ANSI | DMGL_PARAMS);
+      if (demangled_name == NULL)
+       fprintf_filtered (stream, "<badly mangled name %s>",
+                         TYPE_FN_FIELD_PHYSNAME (f, j));
       else
        {
-         cp_type_print_method_args (TYPE_FN_FIELD_ARGS (f, j), "",
-                                    TYPE_FN_FIELDLIST_NAME (domain, i),
-                                    0, stream);
+         fputs_filtered (demangled_name, stream);
+         free (demangled_name);
        }
     }
   else
@@ -332,26 +333,20 @@ cp_print_value_fields (type, valaddr, address, stream, format, recurse, pretty,
                }
              else if (TYPE_FIELD_STATIC (type, i))
                {
-                 value_ptr v;
-                 char *phys_name = TYPE_FIELD_STATIC_PHYSNAME (type, i);
-                 struct symbol *sym =
-                     lookup_symbol (phys_name, 0, VAR_NAMESPACE, 0, NULL);
-                 if (sym == NULL)
+                 value_ptr v = value_static_field (type, i);
+                 if (v == NULL)
                    fputs_filtered ("<optimized out>", stream);
                  else
-                   {
-                     v = value_at (TYPE_FIELD_TYPE (type, i),
-                                   (CORE_ADDR)SYMBOL_BLOCK_VALUE (sym));
-                     cp_print_static_field (TYPE_FIELD_TYPE (type, i), v,
-                                            stream, format, recurse + 1,
-                                            pretty);
-                   }
+                   cp_print_static_field (TYPE_FIELD_TYPE (type, i), v,
+                                          stream, format, recurse + 1,
+                                          pretty);
                }
              else
                {
                   val_print (TYPE_FIELD_TYPE (type, i), 
                              valaddr + TYPE_FIELD_BITPOS (type, i) / 8,
-                             0, stream, format, 0, recurse + 1, pretty);
+                             address + TYPE_FIELD_BITPOS (type, i) / 8,
+                             stream, format, 0, recurse + 1, pretty);
                }
            }
          annotate_field_end ();
@@ -409,6 +404,7 @@ cp_print_value (type, valaddr, address, stream, format, recurse, pretty,
       int boffset;
       struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i));
       char *basename = TYPE_NAME (baseclass);
+      char *base_valaddr;
 
       if (BASETYPE_VIA_VIRTUAL (type, i))
        {
@@ -437,10 +433,25 @@ cp_print_value (type, valaddr, address, stream, format, recurse, pretty,
         baseclass name.  */
       fputs_filtered (basename ? basename : "", stream);
       fputs_filtered ("> = ", stream);
+
+      /* The virtual base class pointer might have been clobbered by the
+        user program. Make sure that it still points to a valid memory
+        location.  */
+
+      if (boffset != -1 && (boffset < 0 || boffset >= TYPE_LENGTH (type)))
+       {
+         base_valaddr = (char *) alloca (TYPE_LENGTH (baseclass));
+         if (target_read_memory (address + boffset, base_valaddr,
+                                 TYPE_LENGTH (baseclass)) != 0)
+           boffset = -1;
+       }
+      else
+       base_valaddr = valaddr + boffset;
+
       if (boffset == -1)
        fprintf_filtered (stream, "<invalid address>");
       else
-       cp_print_value_fields (baseclass, valaddr + boffset, address + boffset,
+       cp_print_value_fields (baseclass, base_valaddr, address + boffset,
                               stream, format, recurse, pretty,
                               (struct type **) obstack_base (&dont_print_vb_obstack),
                               0);
@@ -499,7 +510,7 @@ cp_print_static_field (type, val, stream, format, recurse, pretty)
            }
        }
 
-      obstack_grow (&dont_print_statmem_obstack, &VALUE_ADDRESS (val),
+      obstack_grow (&dont_print_statmem_obstack, (char *) &VALUE_ADDRESS (val),
                    sizeof (CORE_ADDR));
 
       CHECK_TYPEDEF (type);
This page took 0.036126 seconds and 4 git commands to generate.