* blockframe.c (inside_main_func): No longer use symbol_lookup()
[deliverable/binutils-gdb.git] / gdb / c-valprint.c
index 784cbc8bbdc4f2fda9f86adc01d5878ef59e3ed6..62ad59fe4bce3a1e41defdf5963ddca801601065 100644 (file)
@@ -1,6 +1,7 @@
 /* Support for printing C values for GDB, the GNU debugger.
-   Copyright 1986, 1988, 1989, 1991-1997, 2000
-   Free Software Foundation, Inc.
+
+   Copyright 1986, 1988, 1989, 1991, 1992, 1993, 1994, 1995, 1996,
+   1997, 1998, 1999, 2000, 2001, 2003 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
    Boston, MA 02111-1307, USA.  */
 
 #include "defs.h"
+#include "gdb_string.h"
 #include "symtab.h"
 #include "gdbtypes.h"
 #include "expression.h"
 #include "value.h"
-#include "demangle.h"
 #include "valprint.h"
 #include "language.h"
 #include "c-lang.h"
+#include "cp-abi.h"
 \f
 
+/* Print function pointer with inferior address ADDRESS onto stdio
+   stream STREAM.  */
+
+static void
+print_function_pointer_address (CORE_ADDR address, struct ui_file *stream)
+{
+  CORE_ADDR func_addr = CONVERT_FROM_FUNC_PTR_ADDR (address);
+
+  /* If the function pointer is represented by a description, print the
+     address of the description.  */
+  if (addressprint && func_addr != address)
+    {
+      fputs_filtered ("@", stream);
+      print_address_numeric (address, 1, stream);
+      fputs_filtered (": ", stream);
+    }
+  print_address_demangle (func_addr, stream, demangle);
+}
+
+
 /* Print data of type TYPE located at VALADDR (within GDB), which came from
    the inferior at address ADDRESS, onto stdio stream STREAM according to
    FORMAT (a letter or 0 for natural format).  The data at VALADDR is in
@@ -48,7 +70,7 @@ c_val_print (struct type *type, char *valaddr, int embedded_offset,
             CORE_ADDR address, struct ui_file *stream, int format,
             int deref_ref, int recurse, enum val_prettyprint pretty)
 {
-  register unsigned int i = 0; /* Number of characters printed */
+  unsigned int i = 0;  /* Number of characters printed */
   unsigned len;
   struct type *elttype;
   unsigned eltlen;
@@ -129,7 +151,7 @@ c_val_print (struct type *type, char *valaddr, int embedded_offset,
             -fvtable_thunks.  (Otherwise, look under TYPE_CODE_STRUCT.) */
          CORE_ADDR addr
            = extract_typed_address (valaddr + embedded_offset, type);
-         print_address_demangle (addr, stream, demangle);
+         print_function_pointer_address (addr, stream);
          break;
        }
       elttype = check_typedef (TYPE_TARGET_TYPE (type));
@@ -147,12 +169,11 @@ c_val_print (struct type *type, char *valaddr, int embedded_offset,
        {
          addr = unpack_pointer (type, valaddr + embedded_offset);
        print_unpacked_pointer:
-         elttype = check_typedef (TYPE_TARGET_TYPE (type));
 
          if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
            {
              /* Try to print what function it points to.  */
-             print_address_demangle (addr, stream, demangle);
+             print_function_pointer_address (addr, stream);
              /* Return value is irrelevant except for string pointers.  */
              return (0);
            }
@@ -184,21 +205,20 @@ c_val_print (struct type *type, char *valaddr, int embedded_offset,
                  (vt_address == SYMBOL_VALUE_ADDRESS (msymbol)))
                {
                  fputs_filtered (" <", stream);
-                 fputs_filtered (SYMBOL_SOURCE_NAME (msymbol), stream);
+                 fputs_filtered (SYMBOL_PRINT_NAME (msymbol), stream);
                  fputs_filtered (">", stream);
                }
              if (vt_address && vtblprint)
                {
-                 value_ptr vt_val;
+                 struct value *vt_val;
                  struct symbol *wsym = (struct symbol *) NULL;
                  struct type *wtype;
-                 struct symtab *s;
                  struct block *block = (struct block *) NULL;
                  int is_this_fld;
 
                  if (msymbol != NULL)
-                   wsym = lookup_symbol (SYMBOL_NAME (msymbol), block,
-                                         VAR_NAMESPACE, &is_this_fld, &s);
+                   wsym = lookup_symbol (DEPRECATED_SYMBOL_NAME (msymbol), block,
+                                         VAR_DOMAIN, &is_this_fld, NULL);
 
                  if (wsym)
                    {
@@ -254,7 +274,7 @@ c_val_print (struct type *type, char *valaddr, int embedded_offset,
        {
          if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF)
            {
-             value_ptr deref_val =
+             struct value *deref_val =
              value_at
              (TYPE_TARGET_TYPE (type),
               unpack_pointer (lookup_pointer_type (builtin_type_void),
@@ -283,6 +303,7 @@ c_val_print (struct type *type, char *valaddr, int embedded_offset,
        }
       /* Fall through.  */
     case TYPE_CODE_STRUCT:
+      /*FIXME: Abstract this away */
       if (vtblprint && cp_is_vtbl_ptr_type (type))
        {
          /* Print the unmangled name if desired.  */
@@ -294,7 +315,7 @@ c_val_print (struct type *type, char *valaddr, int embedded_offset,
          CORE_ADDR addr
            = extract_typed_address (valaddr + offset, field_type);
 
-         print_address_demangle (addr, stream, demangle);
+         print_function_pointer_address (addr, stream);
        }
       else
        cp_print_value_fields (type, type, valaddr, embedded_offset, address, stream, format,
@@ -420,8 +441,12 @@ c_val_print (struct type *type, char *valaddr, int embedded_offset,
       break;
 
     case TYPE_CODE_METHOD:
-      cp_print_class_method (valaddr + embedded_offset, lookup_pointer_type (type), stream);
-      break;
+      {
+       struct value *v = value_at (type, address, NULL);
+       cp_print_class_method (VALUE_CONTENTS (value_addr (v)),
+                              lookup_pointer_type (type), stream);
+       break;
+      }
 
     case TYPE_CODE_VOID:
       fprintf_filtered (stream, "void");
@@ -438,6 +463,28 @@ c_val_print (struct type *type, char *valaddr, int embedded_offset,
       fprintf_filtered (stream, "<incomplete type>");
       break;
 
+    case TYPE_CODE_COMPLEX:
+      if (format)
+       print_scalar_formatted (valaddr + embedded_offset,
+                               TYPE_TARGET_TYPE (type),
+                               format, 0, stream);
+      else
+       print_floating (valaddr + embedded_offset, TYPE_TARGET_TYPE (type),
+                       stream);
+      fprintf_filtered (stream, " + ");
+      if (format)
+       print_scalar_formatted (valaddr + embedded_offset
+                               + TYPE_LENGTH (TYPE_TARGET_TYPE (type)),
+                               TYPE_TARGET_TYPE (type),
+                               format, 0, stream);
+      else
+       print_floating (valaddr + embedded_offset
+                       + TYPE_LENGTH (TYPE_TARGET_TYPE (type)),
+                       TYPE_TARGET_TYPE (type),
+                       stream);
+      fprintf_filtered (stream, " * I");
+      break;
+
     default:
       error ("Invalid C/C++ type code %d in symbol table.", TYPE_CODE (type));
     }
@@ -446,7 +493,7 @@ c_val_print (struct type *type, char *valaddr, int embedded_offset,
 }
 \f
 int
-c_value_print (value_ptr val, struct ui_file *stream, int format,
+c_value_print (struct value *val, struct ui_file *stream, int format,
               enum val_prettyprint pretty)
 {
   struct type *type = VALUE_TYPE (val);
@@ -467,7 +514,7 @@ c_value_print (value_ptr val, struct ui_file *stream, int format,
       if (TYPE_CODE (type) == TYPE_CODE_PTR &&
          TYPE_NAME (type) == NULL &&
          TYPE_NAME (TYPE_TARGET_TYPE (type)) != NULL &&
-         STREQ (TYPE_NAME (TYPE_TARGET_TYPE (type)), "char"))
+         strcmp (TYPE_NAME (TYPE_TARGET_TYPE (type)), "char") == 0)
        {
          /* Print nothing */
        }
@@ -479,7 +526,7 @@ c_value_print (value_ptr val, struct ui_file *stream, int format,
              /* Copy value, change to pointer, so we don't get an
               * error about a non-pointer type in value_rtti_target_type
               */
-             value_ptr temparg;
+             struct value *temparg;
              temparg=value_copy(val);
              VALUE_TYPE (temparg) = lookup_pointer_type(TYPE_TARGET_TYPE(type));
              val=temparg;
@@ -545,7 +592,8 @@ c_value_print (value_ptr val, struct ui_file *stream, int format,
       /* Otherwise, we end up at the return outside this "if" */
     }
 
-  return val_print (type, VALUE_CONTENTS_ALL (val), VALUE_EMBEDDED_OFFSET (val),
-                   VALUE_ADDRESS (val),
+  return val_print (type, VALUE_CONTENTS_ALL (val),
+                   VALUE_EMBEDDED_OFFSET (val),
+                   VALUE_ADDRESS (val) + VALUE_OFFSET (val),
                    stream, format, 1, 0, pretty);
 }
This page took 0.026594 seconds and 4 git commands to generate.