Remove redundant WIFSTOPPED check
[deliverable/binutils-gdb.git] / gdb / c-valprint.c
index 48535759c6db30129cf90100d5b4872a6caf047d..62552ec7fd9090fb03c5f33f39fd8ba61e12f780 100644 (file)
@@ -1,6 +1,6 @@
 /* Support for printing C values for GDB, the GNU debugger.
 
-   Copyright (C) 1986-2015 Free Software Foundation, Inc.
+   Copyright (C) 1986-2016 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -193,9 +193,9 @@ print_unpacked_pointer (struct type *type, struct type *elttype,
       if (vt_address && options->vtblprint)
        {
          struct value *vt_val;
-         struct symbol *wsym = (struct symbol *) NULL;
+         struct symbol *wsym = NULL;
          struct type *wtype;
-         struct block *block = (struct block *) NULL;
+         struct block *block = NULL;
          struct field_of_this_result is_this_fld;
 
          if (want_space)
@@ -203,7 +203,7 @@ print_unpacked_pointer (struct type *type, struct type *elttype,
 
          if (msymbol.minsym != NULL)
            wsym = lookup_symbol (MSYMBOL_LINKAGE_NAME(msymbol.minsym), block,
-                                 VAR_DOMAIN, &is_this_fld);
+                                 VAR_DOMAIN, &is_this_fld).symbol;
 
          if (wsym)
            {
@@ -236,6 +236,8 @@ c_val_print_array (struct type *type, const gdb_byte *valaddr,
 {
   struct type *unresolved_elttype = TYPE_TARGET_TYPE (type);
   struct type *elttype = check_typedef (unresolved_elttype);
+  struct gdbarch *arch = get_type_arch (type);
+  int unit_size = gdbarch_addressable_memory_unit_size (arch);
 
   if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (unresolved_elttype) > 0)
     {
@@ -276,7 +278,8 @@ c_val_print_array (struct type *type, const gdb_byte *valaddr,
              for (temp_len = 0;
                   (temp_len < len
                    && temp_len < options->print_max
-                   && extract_unsigned_integer (valaddr + embedded_offset
+                   && extract_unsigned_integer (valaddr
+                                                + embedded_offset * unit_size
                                                 + temp_len * eltlen,
                                                 eltlen, byte_order) != 0);
                   ++temp_len)
@@ -288,7 +291,8 @@ c_val_print_array (struct type *type, const gdb_byte *valaddr,
              if (temp_len == options->print_max && temp_len < len)
                {
                  ULONGEST val
-                   = extract_unsigned_integer (valaddr + embedded_offset
+                   = extract_unsigned_integer (valaddr
+                                               + embedded_offset * unit_size
                                                + temp_len * eltlen,
                                                eltlen, byte_order);
                  if (val != 0)
@@ -299,7 +303,7 @@ c_val_print_array (struct type *type, const gdb_byte *valaddr,
            }
 
          LA_PRINT_STRING (stream, unresolved_elttype,
-                          valaddr + embedded_offset, len,
+                          valaddr + embedded_offset * unit_size, len,
                           NULL, force_ellipses, options);
          i = len;
        }
@@ -342,6 +346,9 @@ c_val_print_ptr (struct type *type, const gdb_byte *valaddr,
                 const struct value *original_value,
                 const struct value_print_options *options)
 {
+  struct gdbarch *arch = get_type_arch (type);
+  int unit_size = gdbarch_addressable_memory_unit_size (arch);
+
   if (options->format && options->format != 's')
     {
       val_print_scalar_formatted (type, valaddr, embedded_offset,
@@ -363,13 +370,124 @@ c_val_print_ptr (struct type *type, const gdb_byte *valaddr,
     {
       struct type *unresolved_elttype = TYPE_TARGET_TYPE (type);
       struct type *elttype = check_typedef (unresolved_elttype);
-      CORE_ADDR addr = unpack_pointer (type, valaddr + embedded_offset);
+      CORE_ADDR addr = unpack_pointer (type,
+                                      valaddr + embedded_offset * unit_size);
 
       print_unpacked_pointer (type, elttype, unresolved_elttype, valaddr,
                              embedded_offset, addr, stream, recurse, options);
     }
 }
 
+/* c_val_print helper for TYPE_CODE_STRUCT.  */
+
+static void
+c_val_print_struct (struct type *type, const gdb_byte *valaddr,
+                   int embedded_offset, CORE_ADDR address,
+                   struct ui_file *stream, int recurse,
+                   const struct value *original_value,
+                   const struct value_print_options *options)
+{
+  if (options->vtblprint && cp_is_vtbl_ptr_type (type))
+    {
+      /* Print the unmangled name if desired.  */
+      /* Print vtable entry - we only get here if NOT using
+        -fvtable_thunks.  (Otherwise, look under
+        TYPE_CODE_PTR.)  */
+      struct gdbarch *gdbarch = get_type_arch (type);
+      int offset = (embedded_offset
+                   + TYPE_FIELD_BITPOS (type,
+                                        VTBL_FNADDR_OFFSET) / 8);
+      struct type *field_type = TYPE_FIELD_TYPE (type, VTBL_FNADDR_OFFSET);
+      CORE_ADDR addr = extract_typed_address (valaddr + offset, field_type);
+
+      print_function_pointer_address (options, gdbarch, addr, stream);
+    }
+  else
+    cp_print_value_fields_rtti (type, valaddr,
+                               embedded_offset, address,
+                               stream, recurse,
+                               original_value, options,
+                               NULL, 0);
+}
+
+/* c_val_print helper for TYPE_CODE_UNION.  */
+
+static void
+c_val_print_union (struct type *type, const gdb_byte *valaddr,
+                  int embedded_offset, CORE_ADDR address,
+                  struct ui_file *stream, int recurse,
+                  const struct value *original_value,
+                  const struct value_print_options *options)
+{
+  if (recurse && !options->unionprint)
+    {
+      fprintf_filtered (stream, "{...}");
+     }
+  else
+    {
+      c_val_print_struct (type, valaddr, embedded_offset, address, stream,
+                         recurse, original_value, options);
+    }
+}
+
+/* c_val_print helper for TYPE_CODE_INT.  */
+
+static void
+c_val_print_int (struct type *type, struct type *unresolved_type,
+                const gdb_byte *valaddr, int embedded_offset,
+                struct ui_file *stream, const struct value *original_value,
+                const struct value_print_options *options)
+{
+  struct gdbarch *arch = get_type_arch (type);
+  int unit_size = gdbarch_addressable_memory_unit_size (arch);
+
+  if (options->format || options->output_format)
+    {
+      struct value_print_options opts = *options;
+
+      opts.format = (options->format ? options->format
+                    : options->output_format);
+      val_print_scalar_formatted (type, valaddr, embedded_offset,
+                                 original_value, &opts, 0, stream);
+    }
+  else
+    {
+      val_print_type_code_int (type, valaddr + embedded_offset * unit_size,
+                              stream);
+      /* C and C++ has no single byte int type, char is used
+        instead.  Since we don't know whether the value is really
+        intended to be used as an integer or a character, print
+        the character equivalent as well.  */
+      if (c_textual_element_type (unresolved_type, options->format))
+       {
+         fputs_filtered (" ", stream);
+         LA_PRINT_CHAR (unpack_long (type,
+                                     valaddr + embedded_offset * unit_size),
+                        unresolved_type, stream);
+       }
+    }
+}
+
+/* c_val_print helper for TYPE_CODE_MEMBERPTR.  */
+
+static void
+c_val_print_memberptr (struct type *type, const gdb_byte *valaddr,
+                      int embedded_offset, CORE_ADDR address,
+                      struct ui_file *stream, int recurse,
+                      const struct value *original_value,
+                      const struct value_print_options *options)
+{
+  if (!options->format)
+    {
+      cp_print_class_member (valaddr + embedded_offset, type, stream, "&");
+    }
+  else
+    {
+      generic_val_print (type, valaddr, embedded_offset, address, stream,
+                        recurse, original_value, options, &c_decorations);
+    }
+}
+
 /* See val_print for a description of the various parameters of this
    function; they are identical.  */
 
@@ -380,10 +498,9 @@ c_val_print (struct type *type, const gdb_byte *valaddr,
             const struct value *original_value,
             const struct value_print_options *options)
 {
-  struct gdbarch *gdbarch = get_type_arch (type);
   struct type *unresolved_type = type;
 
-  CHECK_TYPEDEF (type);
+  type = check_typedef (type);
   switch (TYPE_CODE (type))
     {
     case TYPE_CODE_ARRAY:
@@ -401,72 +518,24 @@ c_val_print (struct type *type, const gdb_byte *valaddr,
       break;
 
     case TYPE_CODE_UNION:
-      if (recurse && !options->unionprint)
-       {
-         fprintf_filtered (stream, "{...}");
-         break;
-       }
-      /* Fall through.  */
+      c_val_print_union (type, valaddr, embedded_offset, address, stream,
+                        recurse, original_value, options);
+      break;
+
     case TYPE_CODE_STRUCT:
-      /*FIXME: Abstract this away.  */
-      if (options->vtblprint && cp_is_vtbl_ptr_type (type))
-       {
-         /* Print the unmangled name if desired.  */
-         /* Print vtable entry - we only get here if NOT using
-            -fvtable_thunks.  (Otherwise, look under
-            TYPE_CODE_PTR.)  */
-         int offset = (embedded_offset
-                       + TYPE_FIELD_BITPOS (type,
-                                            VTBL_FNADDR_OFFSET) / 8);
-         struct type *field_type = TYPE_FIELD_TYPE (type,
-                                                    VTBL_FNADDR_OFFSET);
-         CORE_ADDR addr
-           = extract_typed_address (valaddr + offset, field_type);
-
-         print_function_pointer_address (options, gdbarch, addr, stream);
-       }
-      else
-       cp_print_value_fields_rtti (type, valaddr,
-                                   embedded_offset, address,
-                                   stream, recurse,
-                                   original_value, options,
-                                   NULL, 0);
+      c_val_print_struct (type, valaddr, embedded_offset, address, stream,
+                         recurse, original_value, options);
       break;
 
     case TYPE_CODE_INT:
-      if (options->format || options->output_format)
-       {
-         struct value_print_options opts = *options;
-
-         opts.format = (options->format ? options->format
-                        : options->output_format);
-         val_print_scalar_formatted (type, valaddr, embedded_offset,
-                                     original_value, &opts, 0, stream);
-       }
-      else
-       {
-         val_print_type_code_int (type, valaddr + embedded_offset,
-                                  stream);
-         /* C and C++ has no single byte int type, char is used
-            instead.  Since we don't know whether the value is really
-            intended to be used as an integer or a character, print
-            the character equivalent as well.  */
-         if (c_textual_element_type (unresolved_type, options->format))
-           {
-             fputs_filtered (" ", stream);
-             LA_PRINT_CHAR (unpack_long (type, valaddr + embedded_offset),
-                            unresolved_type, stream);
-           }
-       }
+      c_val_print_int (type, unresolved_type, valaddr, embedded_offset, stream,
+                      original_value, options);
       break;
 
     case TYPE_CODE_MEMBERPTR:
-      if (!options->format)
-       {
-         cp_print_class_member (valaddr + embedded_offset, type, stream, "&");
-         break;
-       }
-      /* FALLTHROUGH */
+      c_val_print_memberptr (type, valaddr, embedded_offset, address, stream,
+                            recurse, original_value, options);
+      break;
 
     case TYPE_CODE_REF:
     case TYPE_CODE_ENUM:
This page took 0.02793 seconds and 4 git commands to generate.