Fix crash with DW_FORM_implicit_const
[binutils-gdb.git] / gdb / valprint.c
index ba62d3af41c6979f1b3579542b7312fa5e7e60d6..9489662168086d4ab8e71871ce1b96b365fa42c7 100644 (file)
@@ -373,9 +373,8 @@ valprint_check_validity (struct ui_file *stream,
       && type->code () != TYPE_CODE_STRUCT
       && type->code () != TYPE_CODE_ARRAY)
     {
-      if (value_bits_any_optimized_out (val,
-                                       TARGET_CHAR_BIT * embedded_offset,
-                                       TARGET_CHAR_BIT * type->length ()))
+      if (val->bits_any_optimized_out (TARGET_CHAR_BIT * embedded_offset,
+                                      TARGET_CHAR_BIT * type->length ()))
        {
          val_print_optimized_out (val, stream);
          return 0;
@@ -403,7 +402,7 @@ valprint_check_validity (struct ui_file *stream,
          return is_ref;
        }
 
-      if (!value_bytes_available (val, embedded_offset, type->length ()))
+      if (!val->bytes_available (embedded_offset, type->length ()))
        {
          val_print_unavailable (stream);
          return 0;
@@ -567,7 +566,7 @@ generic_val_print_ref (struct type *type,
 {
   struct type *elttype = check_typedef (type->target_type ());
   struct value *deref_val = NULL;
-  const int value_is_synthetic
+  const bool value_is_synthetic
     = original_value->bits_synthetic_pointer (TARGET_CHAR_BIT * embedded_offset,
                                              TARGET_CHAR_BIT * type->length ());
   const int must_coerce_ref = ((options->addressprint && value_is_synthetic)
@@ -857,7 +856,7 @@ generic_val_print_fixed_point (struct value *val, struct ui_file *stream,
                          type->fixed_point_scaling_factor ());
 
       const char *fmt = type->length () < 4 ? "%.11Fg" : "%.17Fg";
-      std::string str = gmp_string_printf (fmt, f.val);
+      std::string str = f.str (fmt);
       gdb_printf (stream, "%s", str.c_str ());
     }
 }
@@ -1131,7 +1130,7 @@ value_check_printable (struct value *val, struct ui_file *stream,
       return 0;
     }
 
-  if (value_entirely_optimized_out (val))
+  if (val->entirely_optimized_out ())
     {
       if (options->summary && !val_print_scalar_type_p (val->type ()))
        gdb_printf (stream, "...");
@@ -1140,7 +1139,7 @@ value_check_printable (struct value *val, struct ui_file *stream,
       return 0;
     }
 
-  if (value_entirely_unavailable (val))
+  if (val->entirely_unavailable ())
     {
       if (options->summary && !val_print_scalar_type_p (val->type ()))
        gdb_printf (stream, "...");
@@ -1304,10 +1303,10 @@ value_print_scalar_formatted (struct value *val,
 
   /* A scalar object that does not have all bits available can't be
      printed, because all bits contribute to its representation.  */
-  if (value_bits_any_optimized_out (val, 0,
-                                   TARGET_CHAR_BIT * type->length ()))
+  if (val->bits_any_optimized_out (0,
+                                  TARGET_CHAR_BIT * type->length ()))
     val_print_optimized_out (val, stream);
-  else if (!value_bytes_available (val, 0, type->length ()))
+  else if (!val->bytes_available (0, type->length ()))
     val_print_unavailable (stream);
   else
     print_scalar_formatted (valaddr, type, options, size, stream);
@@ -2008,29 +2007,29 @@ value_print_array_elements (struct value *val, struct ui_file *stream,
       maybe_print_array_index (index_type, i + low_bound,
                               stream, options);
 
-      struct value *element = value_from_component_bitsize (val, elttype,
-                                                           bit_stride * i,
-                                                           bit_stride);
+      struct value *element = val->from_component_bitsize (elttype,
+                                                          bit_stride * i,
+                                                          bit_stride);
       rep1 = i + 1;
       reps = 1;
       /* Only check for reps if repeat_count_threshold is not set to
         UINT_MAX (unlimited).  */
       if (options->repeat_count_threshold < UINT_MAX)
        {
-         bool unavailable = value_entirely_unavailable (element);
-         bool available = value_entirely_available (element);
+         bool unavailable = element->entirely_unavailable ();
+         bool available = element->entirely_available ();
 
          while (rep1 < len)
            {
              struct value *rep_elt
-               = value_from_component_bitsize (val, elttype,
-                                               rep1 * bit_stride,
-                                               bit_stride);
+               = val->from_component_bitsize (elttype,
+                                              rep1 * bit_stride,
+                                              bit_stride);
              bool repeated = ((available
-                               && value_entirely_available (rep_elt)
+                               && rep_elt->entirely_available ()
                                && element->contents_eq (rep_elt))
                               || (unavailable
-                                  && value_entirely_unavailable (rep_elt)));
+                                  && rep_elt->entirely_unavailable ()));
              if (!repeated)
                break;
              ++reps;
@@ -2357,23 +2356,27 @@ count_next_character (wchar_iterator *iter,
 /* Print the characters in CHARS to the OBSTACK.  QUOTE_CHAR is the quote
    character to use with string output.  WIDTH is the size of the output
    character type.  BYTE_ORDER is the target byte order.  OPTIONS
-   is the user's print options.  */
+   is the user's print options.  *FINISHED is set to 0 if we didn't print
+   all the elements in CHARS.  */
 
 static void
 print_converted_chars_to_obstack (struct obstack *obstack,
                                  const std::vector<converted_character> &chars,
                                  int quote_char, int width,
                                  enum bfd_endian byte_order,
-                                 const struct value_print_options *options)
+                                 const struct value_print_options *options,
+                                 int *finished)
 {
-  unsigned int idx;
+  unsigned int idx, num_elements;
   const converted_character *elem;
   enum {START, SINGLE, REPEAT, INCOMPLETE, FINISH} state, last;
   gdb_wchar_t wide_quote_char = gdb_btowc (quote_char);
   bool need_escape = false;
+  const int print_max = options->print_max_chars > 0
+      ? options->print_max_chars : options->print_max;
 
   /* Set the start state.  */
-  idx = 0;
+  idx = num_elements = 0;
   last = state = START;
   elem = NULL;
 
@@ -2401,7 +2404,13 @@ print_converted_chars_to_obstack (struct obstack *obstack,
                obstack_grow (obstack, &wide_quote_char, sizeof (gdb_wchar_t));
              }
            /* Output the character.  */
-           for (j = 0; j < elem->repeat_count; ++j)
+           int repeat_count = elem->repeat_count;
+           if (print_max < repeat_count + num_elements)
+             {
+               repeat_count = print_max - num_elements;
+               *finished = 0;
+             }
+           for (j = 0; j < repeat_count; ++j)
              {
                if (elem->result == wchar_iterate_ok)
                  print_wchar (elem->chars[0], elem->buf, elem->buflen, width,
@@ -2409,6 +2418,7 @@ print_converted_chars_to_obstack (struct obstack *obstack,
                else
                  print_wchar (gdb_WEOF, elem->buf, elem->buflen, width,
                               byte_order, obstack, quote_char, &need_escape);
+               num_elements += 1;
              }
          }
          break;
@@ -2440,6 +2450,7 @@ print_converted_chars_to_obstack (struct obstack *obstack,
            obstack_grow_wstr (obstack, LCST ("'"));
            std::string s = string_printf (_(" <repeats %u times>"),
                                           elem->repeat_count);
+           num_elements += elem->repeat_count;
            for (j = 0; s[j]; ++j)
              {
                gdb_wchar_t w = gdb_btowc (s[j]);
@@ -2464,6 +2475,7 @@ print_converted_chars_to_obstack (struct obstack *obstack,
          print_wchar (gdb_WEOF, elem->buf, elem->buflen, width, byte_order,
                       obstack, 0, &need_escape);
          obstack_grow_wstr (obstack, LCST (">"));
+         num_elements += 1;
 
          /* We do not attempt to output anything after this.  */
          state = FINISH;
@@ -2598,7 +2610,7 @@ generic_printstr (struct ui_file *stream, struct type *type,
 
   /* Print the output string to the obstack.  */
   print_converted_chars_to_obstack (&wchar_buf, converted_chars, quote_char,
-                                   width, byte_order, options);
+                                   width, byte_order, options, &finished);
 
   if (force_ellipses || !finished)
     obstack_grow_wstr (&wchar_buf, LCST ("..."));