[gdb/testsuite] Fix use of verbose in gdb/jit-*.exp
[deliverable/binutils-gdb.git] / gdb / valprint.c
index 108a21b684964eda724e34d141cd1c5c8910447e..d678ad3091a46848f47b86a4e0f0b51480a76955 100644 (file)
@@ -276,7 +276,7 @@ val_print_scalar_type_p (struct type *type)
       type = TYPE_TARGET_TYPE (type);
       type = check_typedef (type);
     }
-  switch (TYPE_CODE (type))
+  switch (type->code ())
     {
     case TYPE_CODE_ARRAY:
     case TYPE_CODE_STRUCT:
@@ -323,9 +323,9 @@ valprint_check_validity (struct ui_file *stream,
       return 0;
     }
 
-  if (TYPE_CODE (type) != TYPE_CODE_UNION
-      && TYPE_CODE (type) != TYPE_CODE_STRUCT
-      && TYPE_CODE (type) != TYPE_CODE_ARRAY)
+  if (type->code () != TYPE_CODE_UNION
+      && type->code () != TYPE_CODE_STRUCT
+      && type->code () != TYPE_CODE_ARRAY)
     {
       if (value_bits_any_optimized_out (val,
                                        TARGET_CHAR_BIT * embedded_offset,
@@ -338,7 +338,7 @@ valprint_check_validity (struct ui_file *stream,
       if (value_bits_synthetic_pointer (val, TARGET_CHAR_BIT * embedded_offset,
                                        TARGET_CHAR_BIT * TYPE_LENGTH (type)))
        {
-         const int is_ref = TYPE_CODE (type) == TYPE_CODE_REF;
+         const int is_ref = type->code () == TYPE_CODE_REF;
          int ref_is_addressable = 0;
 
          if (is_ref)
@@ -408,7 +408,7 @@ print_unpacked_pointer (struct type *type, struct type *elttype,
 {
   struct gdbarch *gdbarch = get_type_arch (type);
 
-  if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
+  if (elttype->code () == TYPE_CODE_FUNC)
     {
       /* Try to print what function it points to.  */
       print_function_pointer_address (options, gdbarch, address, stream);
@@ -441,11 +441,6 @@ generic_val_print_array (struct value *val,
       if (!get_array_bounds (type, &low_bound, &high_bound))
        error (_("Could not determine the array high bound"));
 
-      if (options->prettyformat_arrays)
-       {
-         print_spaces_filtered (2 + 2 * recurse, stream);
-       }
-
       fputs_filtered (decorations->array_start, stream);
       value_print_array_elements (val, stream, recurse, options, 0);
       fputs_filtered (decorations->array_end, stream);
@@ -532,7 +527,7 @@ generic_val_print_ref (struct type *type,
                                    TARGET_CHAR_BIT * TYPE_LENGTH (type));
   const int must_coerce_ref = ((options->addressprint && value_is_synthetic)
                               || options->deref_ref);
-  const int type_is_defined = TYPE_CODE (elttype) != TYPE_CODE_UNDEF;
+  const int type_is_defined = elttype->code () != TYPE_CODE_UNDEF;
   const gdb_byte *valaddr = value_contents_for_printing (original_value);
 
   if (must_coerce_ref && type_is_defined)
@@ -592,7 +587,7 @@ generic_val_print_enum_1 (struct type *type, LONGEST val,
   unsigned int i;
   unsigned int len;
 
-  len = TYPE_NFIELDS (type);
+  len = type->num_fields ();
   for (i = 0; i < len; i++)
     {
       QUIT;
@@ -811,16 +806,11 @@ generic_value_print_complex (struct value *val, struct ui_file *stream,
 {
   fprintf_filtered (stream, "%s", decorations->complex_prefix);
 
-  struct type *type = check_typedef (value_type (val));
-  struct value *real_part
-    = value_from_component (val, TYPE_TARGET_TYPE (type), 0);
+  struct value *real_part = value_real_part (val);
   value_print_scalar_formatted (real_part, options, 0, stream);
   fprintf_filtered (stream, "%s", decorations->complex_infix);
 
-  struct value *imag_part
-    = value_from_component (val, TYPE_TARGET_TYPE (type),
-                           TYPE_LENGTH (TYPE_TARGET_TYPE (type)));
-
+  struct value *imag_part = value_imaginary_part (val);
   value_print_scalar_formatted (imag_part, options, 0, stream);
   fprintf_filtered (stream, "%s", decorations->complex_suffix);
 }
@@ -835,7 +825,7 @@ generic_value_print (struct value *val, struct ui_file *stream, int recurse,
   struct type *type = value_type (val);
 
   type = check_typedef (type);
-  switch (TYPE_CODE (type))
+  switch (type->code ())
     {
     case TYPE_CODE_ARRAY:
       generic_val_print_array (val, stream, recurse, options, decorations);
@@ -934,7 +924,7 @@ generic_value_print (struct value *val, struct ui_file *stream, int recurse,
     case TYPE_CODE_METHODPTR:
     default:
       error (_("Unhandled type code %d in symbol table."),
-            TYPE_CODE (type));
+            type->code ());
     }
 }
 
@@ -1053,7 +1043,7 @@ value_check_printable (struct value *val, struct ui_file *stream,
       return 0;
     }
 
-  if (TYPE_CODE (value_type (val)) == TYPE_CODE_INTERNAL_FUNCTION)
+  if (value_type (val)->code () == TYPE_CODE_INTERNAL_FUNCTION)
     {
       fprintf_styled (stream, metadata_style.style (),
                      _("<internal function %s>"),
@@ -1145,7 +1135,7 @@ val_print_type_code_flags (struct type *type, struct value *original_value,
   const gdb_byte *valaddr = (value_contents_for_printing (original_value)
                             + embedded_offset);
   ULONGEST val = unpack_long (type, valaddr);
-  int field, nfields = TYPE_NFIELDS (type);
+  int field, nfields = type->num_fields ();
   struct gdbarch *gdbarch = get_type_arch (type);
   struct type *bool_type = builtin_type (gdbarch)->builtin_bool;
 
@@ -1180,7 +1170,7 @@ val_print_type_code_flags (struct type *type, struct value *original_value,
              fprintf_filtered (stream, " %ps=",
                                styled_string (variable_name_style.style (),
                                               TYPE_FIELD_NAME (type, field)));
-             if (TYPE_CODE (field_type) == TYPE_CODE_ENUM)
+             if (field_type->code () == TYPE_CODE_ENUM)
                generic_val_print_enum_1 (field_type, field_val, stream);
              else
                print_longest (stream, 'd', 0, field_val);
@@ -1861,14 +1851,10 @@ maybe_print_array_index (struct type *index_type, LONGEST index,
                          struct ui_file *stream,
                         const struct value_print_options *options)
 {
-  struct value *index_value;
-
   if (!options->print_array_indexes)
     return; 
     
-  index_value = value_from_longest (index_type, index);
-
-  LA_PRINT_ARRAY_INDEX (index_value, stream, options);
+  LA_PRINT_ARRAY_INDEX (index_type, index, stream, options);
 }
 
 /* See valprint.h.  */
@@ -1881,7 +1867,7 @@ value_print_array_elements (struct value *val, struct ui_file *stream,
 {
   unsigned int things_printed = 0;
   unsigned len;
-  struct type *elttype, *index_type, *base_index_type;
+  struct type *elttype, *index_type;
   unsigned eltlen;
   /* Position of the array element we are examining to see
      whether it is repeated.  */
@@ -1889,43 +1875,26 @@ value_print_array_elements (struct value *val, struct ui_file *stream,
   /* Number of repetitions we have detected so far.  */
   unsigned int reps;
   LONGEST low_bound, high_bound;
-  LONGEST low_pos, high_pos;
 
   struct type *type = check_typedef (value_type (val));
 
   elttype = TYPE_TARGET_TYPE (type);
   eltlen = type_length_units (check_typedef (elttype));
   index_type = TYPE_INDEX_TYPE (type);
+  if (index_type->code () == TYPE_CODE_RANGE)
+    index_type = TYPE_TARGET_TYPE (index_type);
 
   if (get_array_bounds (type, &low_bound, &high_bound))
     {
-      if (TYPE_CODE (index_type) == TYPE_CODE_RANGE)
-       base_index_type = TYPE_TARGET_TYPE (index_type);
-      else
-       base_index_type = index_type;
-
-      /* Non-contiguous enumerations types can by used as index types
-        in some languages (e.g. Ada).  In this case, the array length
-        shall be computed from the positions of the first and last
-        literal in the enumeration type, and not from the values
-        of these literals.  */
-      if (!discrete_position (base_index_type, low_bound, &low_pos)
-         || !discrete_position (base_index_type, high_bound, &high_pos))
-       {
-         warning (_("unable to get positions in array, use bounds instead"));
-         low_pos = low_bound;
-         high_pos = high_bound;
-       }
-
-      /* The array length should normally be HIGH_POS - LOW_POS + 1.
-         But we have to be a little extra careful, because some languages
-        such as Ada allow LOW_POS to be greater than HIGH_POS for
-        empty arrays.  In that situation, the array length is just zero,
-        not negative!  */
-      if (low_pos > high_pos)
+      /* The array length should normally be HIGH_BOUND - LOW_BOUND +
+         1.  But we have to be a little extra careful, because some
+         languages such as Ada allow LOW_BOUND to be greater than
+         HIGH_BOUND for empty arrays.  In that situation, the array
+         length is just zero, not negative!  */
+      if (low_bound > high_bound)
        len = 0;
       else
-       len = high_pos - low_pos + 1;
+       len = high_bound - low_bound + 1;
     }
   else
     {
@@ -1950,6 +1919,11 @@ value_print_array_elements (struct value *val, struct ui_file *stream,
          else
            fprintf_filtered (stream, ", ");
        }
+      else if (options->prettyformat_arrays)
+       {
+         fprintf_filtered (stream, "\n");
+         print_spaces_filtered (2 + 2 * recurse, stream);
+       }
       wrap_here (n_spaces (2 + 2 * recurse));
       maybe_print_array_index (index_type, i + low_bound,
                                stream, options);
@@ -1993,6 +1967,11 @@ value_print_array_elements (struct value *val, struct ui_file *stream,
   annotate_array_section_end ();
   if (i < len)
     fprintf_filtered (stream, "...");
+  if (options->prettyformat_arrays)
+    {
+      fprintf_filtered (stream, "\n");
+      print_spaces_filtered (2 * recurse, stream);
+    }
 }
 
 /* Read LEN bytes of target memory at address MEMADDR, placing the
@@ -2947,34 +2926,6 @@ show_radix (const char *arg, int from_tty)
 }
 \f
 
-static void
-set_print (const char *arg, int from_tty)
-{
-  printf_unfiltered (
-     "\"set print\" must be followed by the name of a print subcommand.\n");
-  help_list (setprintlist, "set print ", all_commands, gdb_stdout);
-}
-
-static void
-show_print (const char *args, int from_tty)
-{
-  cmd_show_list (showprintlist, from_tty, "");
-}
-
-static void
-set_print_raw (const char *arg, int from_tty)
-{
-  printf_unfiltered (
-     "\"set print raw\" must be followed by the name of a \"print raw\" subcommand.\n");
-  help_list (setprintrawlist, "set print raw ", all_commands, gdb_stdout);
-}
-
-static void
-show_print_raw (const char *args, int from_tty)
-{
-  cmd_show_list (showprintrawlist, from_tty, "");
-}
-
 /* Controls printing of vtbl's.  */
 static void
 show_vtblprint (struct ui_file *file, int from_tty,
@@ -3166,30 +3117,30 @@ _initialize_valprint ()
 {
   cmd_list_element *cmd;
 
-  add_prefix_cmd ("print", no_class, set_print,
-                 _("Generic command for setting how things print."),
-                 &setprintlist, "set print ", 0, &setlist);
+  add_basic_prefix_cmd ("print", no_class,
+                       _("Generic command for setting how things print."),
+                       &setprintlist, "set print ", 0, &setlist);
   add_alias_cmd ("p", "print", no_class, 1, &setlist);
   /* Prefer set print to set prompt.  */
   add_alias_cmd ("pr", "print", no_class, 1, &setlist);
 
-  add_prefix_cmd ("print", no_class, show_print,
-                 _("Generic command for showing print settings."),
-                 &showprintlist, "show print ", 0, &showlist);
+  add_show_prefix_cmd ("print", no_class,
+                      _("Generic command for showing print settings."),
+                      &showprintlist, "show print ", 0, &showlist);
   add_alias_cmd ("p", "print", no_class, 1, &showlist);
   add_alias_cmd ("pr", "print", no_class, 1, &showlist);
 
-  cmd = add_prefix_cmd ("raw", no_class, set_print_raw,
-                       _("\
+  cmd = add_basic_prefix_cmd ("raw", no_class,
+                             _("\
 Generic command for setting what things to print in \"raw\" mode."),
-                       &setprintrawlist, "set print raw ", 0,
-                       &setprintlist);
+                             &setprintrawlist, "set print raw ", 0,
+                             &setprintlist);
   deprecate_cmd (cmd, nullptr);
 
-  cmd = add_prefix_cmd ("raw", no_class, show_print_raw,
-                       _("Generic command for showing \"print raw\" settings."),
-                       &showprintrawlist, "show print raw ", 0,
-                       &showprintlist);
+  cmd = add_show_prefix_cmd ("raw", no_class,
+                            _("Generic command for showing \"print raw\" settings."),
+                            &showprintrawlist, "show print raw ", 0,
+                            &showprintlist);
   deprecate_cmd (cmd, nullptr);
 
   gdb::option::add_setshow_cmds_for_options
This page took 0.02969 seconds and 4 git commands to generate.