GDB (API)
/home/stan/gdb/src/gdb/valprint.c
Go to the documentation of this file.
00001 /* Print values for GDB, the GNU debugger.
00002 
00003    Copyright (C) 1986-2013 Free Software Foundation, Inc.
00004 
00005    This file is part of GDB.
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 3 of the License, or
00010    (at your option) any later version.
00011 
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00019 
00020 #include "defs.h"
00021 #include "gdb_string.h"
00022 #include "symtab.h"
00023 #include "gdbtypes.h"
00024 #include "value.h"
00025 #include "gdbcore.h"
00026 #include "gdbcmd.h"
00027 #include "target.h"
00028 #include "language.h"
00029 #include "annotate.h"
00030 #include "valprint.h"
00031 #include "floatformat.h"
00032 #include "doublest.h"
00033 #include "exceptions.h"
00034 #include "dfp.h"
00035 #include "python/python.h"
00036 #include "ada-lang.h"
00037 #include "gdb_obstack.h"
00038 #include "charset.h"
00039 #include <ctype.h>
00040 
00041 #include <errno.h>
00042 
00043 /* Maximum number of wchars returned from wchar_iterate.  */
00044 #define MAX_WCHARS 4
00045 
00046 /* A convenience macro to compute the size of a wchar_t buffer containing X
00047    characters.  */
00048 #define WCHAR_BUFLEN(X) ((X) * sizeof (gdb_wchar_t))
00049 
00050 /* Character buffer size saved while iterating over wchars.  */
00051 #define WCHAR_BUFLEN_MAX WCHAR_BUFLEN (MAX_WCHARS)
00052 
00053 /* A structure to encapsulate state information from iterated
00054    character conversions.  */
00055 struct converted_character
00056 {
00057   /* The number of characters converted.  */
00058   int num_chars;
00059 
00060   /* The result of the conversion.  See charset.h for more.  */
00061   enum wchar_iterate_result result;
00062 
00063   /* The (saved) converted character(s).  */
00064   gdb_wchar_t chars[WCHAR_BUFLEN_MAX];
00065 
00066   /* The first converted target byte.  */
00067   const gdb_byte *buf;
00068 
00069   /* The number of bytes converted.  */
00070   size_t buflen;
00071 
00072   /* How many times this character(s) is repeated.  */
00073   int repeat_count;
00074 };
00075 
00076 typedef struct converted_character converted_character_d;
00077 DEF_VEC_O (converted_character_d);
00078 
00079 /* Command lists for set/show print raw.  */
00080 struct cmd_list_element *setprintrawlist;
00081 struct cmd_list_element *showprintrawlist;
00082 
00083 /* Prototypes for local functions */
00084 
00085 static int partial_memory_read (CORE_ADDR memaddr, gdb_byte *myaddr,
00086                                 int len, int *errptr);
00087 
00088 static void show_print (char *, int);
00089 
00090 static void set_print (char *, int);
00091 
00092 static void set_radix (char *, int);
00093 
00094 static void show_radix (char *, int);
00095 
00096 static void set_input_radix (char *, int, struct cmd_list_element *);
00097 
00098 static void set_input_radix_1 (int, unsigned);
00099 
00100 static void set_output_radix (char *, int, struct cmd_list_element *);
00101 
00102 static void set_output_radix_1 (int, unsigned);
00103 
00104 void _initialize_valprint (void);
00105 
00106 #define PRINT_MAX_DEFAULT 200   /* Start print_max off at this value.  */
00107 
00108 struct value_print_options user_print_options =
00109 {
00110   Val_prettyformat_default,     /* prettyformat */
00111   0,                            /* prettyformat_arrays */
00112   0,                            /* prettyformat_structs */
00113   0,                            /* vtblprint */
00114   1,                            /* unionprint */
00115   1,                            /* addressprint */
00116   0,                            /* objectprint */
00117   PRINT_MAX_DEFAULT,            /* print_max */
00118   10,                           /* repeat_count_threshold */
00119   0,                            /* output_format */
00120   0,                            /* format */
00121   0,                            /* stop_print_at_null */
00122   0,                            /* print_array_indexes */
00123   0,                            /* deref_ref */
00124   1,                            /* static_field_print */
00125   1,                            /* pascal_static_field_print */
00126   0,                            /* raw */
00127   0,                            /* summary */
00128   1                             /* symbol_print */
00129 };
00130 
00131 /* Initialize *OPTS to be a copy of the user print options.  */
00132 void
00133 get_user_print_options (struct value_print_options *opts)
00134 {
00135   *opts = user_print_options;
00136 }
00137 
00138 /* Initialize *OPTS to be a copy of the user print options, but with
00139    pretty-formatting disabled.  */
00140 void
00141 get_no_prettyformat_print_options (struct value_print_options *opts)
00142 {  
00143   *opts = user_print_options;
00144   opts->prettyformat = Val_no_prettyformat;
00145 }
00146 
00147 /* Initialize *OPTS to be a copy of the user print options, but using
00148    FORMAT as the formatting option.  */
00149 void
00150 get_formatted_print_options (struct value_print_options *opts,
00151                              char format)
00152 {
00153   *opts = user_print_options;
00154   opts->format = format;
00155 }
00156 
00157 static void
00158 show_print_max (struct ui_file *file, int from_tty,
00159                 struct cmd_list_element *c, const char *value)
00160 {
00161   fprintf_filtered (file,
00162                     _("Limit on string chars or array "
00163                       "elements to print is %s.\n"),
00164                     value);
00165 }
00166 
00167 
00168 /* Default input and output radixes, and output format letter.  */
00169 
00170 unsigned input_radix = 10;
00171 static void
00172 show_input_radix (struct ui_file *file, int from_tty,
00173                   struct cmd_list_element *c, const char *value)
00174 {
00175   fprintf_filtered (file,
00176                     _("Default input radix for entering numbers is %s.\n"),
00177                     value);
00178 }
00179 
00180 unsigned output_radix = 10;
00181 static void
00182 show_output_radix (struct ui_file *file, int from_tty,
00183                    struct cmd_list_element *c, const char *value)
00184 {
00185   fprintf_filtered (file,
00186                     _("Default output radix for printing of values is %s.\n"),
00187                     value);
00188 }
00189 
00190 /* By default we print arrays without printing the index of each element in
00191    the array.  This behavior can be changed by setting PRINT_ARRAY_INDEXES.  */
00192 
00193 static void
00194 show_print_array_indexes (struct ui_file *file, int from_tty,
00195                           struct cmd_list_element *c, const char *value)
00196 {
00197   fprintf_filtered (file, _("Printing of array indexes is %s.\n"), value);
00198 }
00199 
00200 /* Print repeat counts if there are more than this many repetitions of an
00201    element in an array.  Referenced by the low level language dependent
00202    print routines.  */
00203 
00204 static void
00205 show_repeat_count_threshold (struct ui_file *file, int from_tty,
00206                              struct cmd_list_element *c, const char *value)
00207 {
00208   fprintf_filtered (file, _("Threshold for repeated print elements is %s.\n"),
00209                     value);
00210 }
00211 
00212 /* If nonzero, stops printing of char arrays at first null.  */
00213 
00214 static void
00215 show_stop_print_at_null (struct ui_file *file, int from_tty,
00216                          struct cmd_list_element *c, const char *value)
00217 {
00218   fprintf_filtered (file,
00219                     _("Printing of char arrays to stop "
00220                       "at first null char is %s.\n"),
00221                     value);
00222 }
00223 
00224 /* Controls pretty printing of structures.  */
00225 
00226 static void
00227 show_prettyformat_structs (struct ui_file *file, int from_tty,
00228                           struct cmd_list_element *c, const char *value)
00229 {
00230   fprintf_filtered (file, _("Pretty formatting of structures is %s.\n"), value);
00231 }
00232 
00233 /* Controls pretty printing of arrays.  */
00234 
00235 static void
00236 show_prettyformat_arrays (struct ui_file *file, int from_tty,
00237                          struct cmd_list_element *c, const char *value)
00238 {
00239   fprintf_filtered (file, _("Pretty formatting of arrays is %s.\n"), value);
00240 }
00241 
00242 /* If nonzero, causes unions inside structures or other unions to be
00243    printed.  */
00244 
00245 static void
00246 show_unionprint (struct ui_file *file, int from_tty,
00247                  struct cmd_list_element *c, const char *value)
00248 {
00249   fprintf_filtered (file,
00250                     _("Printing of unions interior to structures is %s.\n"),
00251                     value);
00252 }
00253 
00254 /* If nonzero, causes machine addresses to be printed in certain contexts.  */
00255 
00256 static void
00257 show_addressprint (struct ui_file *file, int from_tty,
00258                    struct cmd_list_element *c, const char *value)
00259 {
00260   fprintf_filtered (file, _("Printing of addresses is %s.\n"), value);
00261 }
00262 
00263 static void
00264 show_symbol_print (struct ui_file *file, int from_tty,
00265                    struct cmd_list_element *c, const char *value)
00266 {
00267   fprintf_filtered (file,
00268                     _("Printing of symbols when printing pointers is %s.\n"),
00269                     value);
00270 }
00271 
00272 
00273 
00274 /* A helper function for val_print.  When printing in "summary" mode,
00275    we want to print scalar arguments, but not aggregate arguments.
00276    This function distinguishes between the two.  */
00277 
00278 int
00279 val_print_scalar_type_p (struct type *type)
00280 {
00281   CHECK_TYPEDEF (type);
00282   while (TYPE_CODE (type) == TYPE_CODE_REF)
00283     {
00284       type = TYPE_TARGET_TYPE (type);
00285       CHECK_TYPEDEF (type);
00286     }
00287   switch (TYPE_CODE (type))
00288     {
00289     case TYPE_CODE_ARRAY:
00290     case TYPE_CODE_STRUCT:
00291     case TYPE_CODE_UNION:
00292     case TYPE_CODE_SET:
00293     case TYPE_CODE_STRING:
00294       return 0;
00295     default:
00296       return 1;
00297     }
00298 }
00299 
00300 /* See its definition in value.h.  */
00301 
00302 int
00303 valprint_check_validity (struct ui_file *stream,
00304                          struct type *type,
00305                          int embedded_offset,
00306                          const struct value *val)
00307 {
00308   CHECK_TYPEDEF (type);
00309 
00310   if (TYPE_CODE (type) != TYPE_CODE_UNION
00311       && TYPE_CODE (type) != TYPE_CODE_STRUCT
00312       && TYPE_CODE (type) != TYPE_CODE_ARRAY)
00313     {
00314       if (!value_bits_valid (val, TARGET_CHAR_BIT * embedded_offset,
00315                              TARGET_CHAR_BIT * TYPE_LENGTH (type)))
00316         {
00317           val_print_optimized_out (val, stream);
00318           return 0;
00319         }
00320 
00321       if (value_bits_synthetic_pointer (val, TARGET_CHAR_BIT * embedded_offset,
00322                                         TARGET_CHAR_BIT * TYPE_LENGTH (type)))
00323         {
00324           fputs_filtered (_("<synthetic pointer>"), stream);
00325           return 0;
00326         }
00327 
00328       if (!value_bytes_available (val, embedded_offset, TYPE_LENGTH (type)))
00329         {
00330           val_print_unavailable (stream);
00331           return 0;
00332         }
00333     }
00334 
00335   return 1;
00336 }
00337 
00338 void
00339 val_print_optimized_out (const struct value *val, struct ui_file *stream)
00340 {
00341   if (val != NULL && value_lval_const (val) == lval_register)
00342     fprintf_filtered (stream, _("<not saved>"));
00343   else
00344     fprintf_filtered (stream, _("<optimized out>"));
00345 }
00346 
00347 void
00348 val_print_unavailable (struct ui_file *stream)
00349 {
00350   fprintf_filtered (stream, _("<unavailable>"));
00351 }
00352 
00353 void
00354 val_print_invalid_address (struct ui_file *stream)
00355 {
00356   fprintf_filtered (stream, _("<invalid address>"));
00357 }
00358 
00359 /* A generic val_print that is suitable for use by language
00360    implementations of the la_val_print method.  This function can
00361    handle most type codes, though not all, notably exception
00362    TYPE_CODE_UNION and TYPE_CODE_STRUCT, which must be implemented by
00363    the caller.
00364    
00365    Most arguments are as to val_print.
00366    
00367    The additional DECORATIONS argument can be used to customize the
00368    output in some small, language-specific ways.  */
00369 
00370 void
00371 generic_val_print (struct type *type, const gdb_byte *valaddr,
00372                    int embedded_offset, CORE_ADDR address,
00373                    struct ui_file *stream, int recurse,
00374                    const struct value *original_value,
00375                    const struct value_print_options *options,
00376                    const struct generic_val_print_decorations *decorations)
00377 {
00378   struct gdbarch *gdbarch = get_type_arch (type);
00379   unsigned int i = 0;   /* Number of characters printed.  */
00380   unsigned len;
00381   struct type *elttype, *unresolved_elttype;
00382   struct type *unresolved_type = type;
00383   LONGEST val;
00384   CORE_ADDR addr;
00385 
00386   CHECK_TYPEDEF (type);
00387   switch (TYPE_CODE (type))
00388     {
00389     case TYPE_CODE_ARRAY:
00390       unresolved_elttype = TYPE_TARGET_TYPE (type);
00391       elttype = check_typedef (unresolved_elttype);
00392       if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (unresolved_elttype) > 0)
00393         {
00394           LONGEST low_bound, high_bound;
00395 
00396           if (!get_array_bounds (type, &low_bound, &high_bound))
00397             error (_("Could not determine the array high bound"));
00398 
00399           if (options->prettyformat_arrays)
00400             {
00401               print_spaces_filtered (2 + 2 * recurse, stream);
00402             }
00403 
00404           fprintf_filtered (stream, "{");
00405           val_print_array_elements (type, valaddr, embedded_offset,
00406                                     address, stream,
00407                                     recurse, original_value, options, 0);
00408           fprintf_filtered (stream, "}");
00409           break;
00410         }
00411       /* Array of unspecified length: treat like pointer to first
00412          elt.  */
00413       addr = address + embedded_offset;
00414       goto print_unpacked_pointer;
00415 
00416     case TYPE_CODE_MEMBERPTR:
00417       val_print_scalar_formatted (type, valaddr, embedded_offset,
00418                                   original_value, options, 0, stream);
00419       break;
00420 
00421     case TYPE_CODE_PTR:
00422       if (options->format && options->format != 's')
00423         {
00424           val_print_scalar_formatted (type, valaddr, embedded_offset,
00425                                       original_value, options, 0, stream);
00426           break;
00427         }
00428       unresolved_elttype = TYPE_TARGET_TYPE (type);
00429       elttype = check_typedef (unresolved_elttype);
00430         {
00431           addr = unpack_pointer (type, valaddr + embedded_offset);
00432         print_unpacked_pointer:
00433 
00434           if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
00435             {
00436               /* Try to print what function it points to.  */
00437               print_function_pointer_address (options, gdbarch, addr, stream);
00438               return;
00439             }
00440 
00441           if (options->symbol_print)
00442             print_address_demangle (options, gdbarch, addr, stream, demangle);
00443           else if (options->addressprint)
00444             fputs_filtered (paddress (gdbarch, addr), stream);
00445         }
00446       break;
00447 
00448     case TYPE_CODE_REF:
00449       elttype = check_typedef (TYPE_TARGET_TYPE (type));
00450       if (options->addressprint)
00451         {
00452           CORE_ADDR addr
00453             = extract_typed_address (valaddr + embedded_offset, type);
00454 
00455           fprintf_filtered (stream, "@");
00456           fputs_filtered (paddress (gdbarch, addr), stream);
00457           if (options->deref_ref)
00458             fputs_filtered (": ", stream);
00459         }
00460       /* De-reference the reference.  */
00461       if (options->deref_ref)
00462         {
00463           if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF)
00464             {
00465               struct value *deref_val;
00466 
00467               deref_val = coerce_ref_if_computed (original_value);
00468               if (deref_val != NULL)
00469                 {
00470                   /* More complicated computed references are not supported.  */
00471                   gdb_assert (embedded_offset == 0);
00472                 }
00473               else
00474                 deref_val = value_at (TYPE_TARGET_TYPE (type),
00475                                       unpack_pointer (type,
00476                                                       (valaddr
00477                                                        + embedded_offset)));
00478 
00479               common_val_print (deref_val, stream, recurse, options,
00480                                 current_language);
00481             }
00482           else
00483             fputs_filtered ("???", stream);
00484         }
00485       break;
00486 
00487     case TYPE_CODE_ENUM:
00488       if (options->format)
00489         {
00490           val_print_scalar_formatted (type, valaddr, embedded_offset,
00491                                       original_value, options, 0, stream);
00492           break;
00493         }
00494       len = TYPE_NFIELDS (type);
00495       val = unpack_long (type, valaddr + embedded_offset);
00496       for (i = 0; i < len; i++)
00497         {
00498           QUIT;
00499           if (val == TYPE_FIELD_ENUMVAL (type, i))
00500             {
00501               break;
00502             }
00503         }
00504       if (i < len)
00505         {
00506           fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
00507         }
00508       else if (TYPE_FLAG_ENUM (type))
00509         {
00510           int first = 1;
00511 
00512           /* We have a "flag" enum, so we try to decompose it into
00513              pieces as appropriate.  A flag enum has disjoint
00514              constants by definition.  */
00515           fputs_filtered ("(", stream);
00516           for (i = 0; i < len; ++i)
00517             {
00518               QUIT;
00519 
00520               if ((val & TYPE_FIELD_ENUMVAL (type, i)) != 0)
00521                 {
00522                   if (!first)
00523                     fputs_filtered (" | ", stream);
00524                   first = 0;
00525 
00526                   val &= ~TYPE_FIELD_ENUMVAL (type, i);
00527                   fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
00528                 }
00529             }
00530 
00531           if (first || val != 0)
00532             {
00533               if (!first)
00534                 fputs_filtered (" | ", stream);
00535               fputs_filtered ("unknown: ", stream);
00536               print_longest (stream, 'd', 0, val);
00537             }
00538 
00539           fputs_filtered (")", stream);
00540         }
00541       else
00542         print_longest (stream, 'd', 0, val);
00543       break;
00544 
00545     case TYPE_CODE_FLAGS:
00546       if (options->format)
00547         val_print_scalar_formatted (type, valaddr, embedded_offset,
00548                                     original_value, options, 0, stream);
00549       else
00550         val_print_type_code_flags (type, valaddr + embedded_offset,
00551                                    stream);
00552       break;
00553 
00554     case TYPE_CODE_FUNC:
00555     case TYPE_CODE_METHOD:
00556       if (options->format)
00557         {
00558           val_print_scalar_formatted (type, valaddr, embedded_offset,
00559                                       original_value, options, 0, stream);
00560           break;
00561         }
00562       /* FIXME, we should consider, at least for ANSI C language,
00563          eliminating the distinction made between FUNCs and POINTERs
00564          to FUNCs.  */
00565       fprintf_filtered (stream, "{");
00566       type_print (type, "", stream, -1);
00567       fprintf_filtered (stream, "} ");
00568       /* Try to print what function it points to, and its address.  */
00569       print_address_demangle (options, gdbarch, address, stream, demangle);
00570       break;
00571 
00572     case TYPE_CODE_BOOL:
00573       if (options->format || options->output_format)
00574         {
00575           struct value_print_options opts = *options;
00576           opts.format = (options->format ? options->format
00577                          : options->output_format);
00578           val_print_scalar_formatted (type, valaddr, embedded_offset,
00579                                       original_value, &opts, 0, stream);
00580         }
00581       else
00582         {
00583           val = unpack_long (type, valaddr + embedded_offset);
00584           if (val == 0)
00585             fputs_filtered (decorations->false_name, stream);
00586           else if (val == 1)
00587             fputs_filtered (decorations->true_name, stream);
00588           else
00589             print_longest (stream, 'd', 0, val);
00590         }
00591       break;
00592 
00593     case TYPE_CODE_RANGE:
00594       /* FIXME: create_range_type does not set the unsigned bit in a
00595          range type (I think it probably should copy it from the
00596          target type), so we won't print values which are too large to
00597          fit in a signed integer correctly.  */
00598       /* FIXME: Doesn't handle ranges of enums correctly.  (Can't just
00599          print with the target type, though, because the size of our
00600          type and the target type might differ).  */
00601 
00602       /* FALLTHROUGH */
00603 
00604     case TYPE_CODE_INT:
00605       if (options->format || options->output_format)
00606         {
00607           struct value_print_options opts = *options;
00608 
00609           opts.format = (options->format ? options->format
00610                          : options->output_format);
00611           val_print_scalar_formatted (type, valaddr, embedded_offset,
00612                                       original_value, &opts, 0, stream);
00613         }
00614       else
00615         val_print_type_code_int (type, valaddr + embedded_offset, stream);
00616       break;
00617 
00618     case TYPE_CODE_CHAR:
00619       if (options->format || options->output_format)
00620         {
00621           struct value_print_options opts = *options;
00622 
00623           opts.format = (options->format ? options->format
00624                          : options->output_format);
00625           val_print_scalar_formatted (type, valaddr, embedded_offset,
00626                                       original_value, &opts, 0, stream);
00627         }
00628       else
00629         {
00630           val = unpack_long (type, valaddr + embedded_offset);
00631           if (TYPE_UNSIGNED (type))
00632             fprintf_filtered (stream, "%u", (unsigned int) val);
00633           else
00634             fprintf_filtered (stream, "%d", (int) val);
00635           fputs_filtered (" ", stream);
00636           LA_PRINT_CHAR (val, unresolved_type, stream);
00637         }
00638       break;
00639 
00640     case TYPE_CODE_FLT:
00641       if (options->format)
00642         {
00643           val_print_scalar_formatted (type, valaddr, embedded_offset,
00644                                       original_value, options, 0, stream);
00645         }
00646       else
00647         {
00648           print_floating (valaddr + embedded_offset, type, stream);
00649         }
00650       break;
00651 
00652     case TYPE_CODE_DECFLOAT:
00653       if (options->format)
00654         val_print_scalar_formatted (type, valaddr, embedded_offset,
00655                                     original_value, options, 0, stream);
00656       else
00657         print_decimal_floating (valaddr + embedded_offset,
00658                                 type, stream);
00659       break;
00660 
00661     case TYPE_CODE_VOID:
00662       fputs_filtered (decorations->void_name, stream);
00663       break;
00664 
00665     case TYPE_CODE_ERROR:
00666       fprintf_filtered (stream, "%s", TYPE_ERROR_NAME (type));
00667       break;
00668 
00669     case TYPE_CODE_UNDEF:
00670       /* This happens (without TYPE_FLAG_STUB set) on systems which
00671          don't use dbx xrefs (NO_DBX_XREFS in gcc) if a file has a
00672          "struct foo *bar" and no complete type for struct foo in that
00673          file.  */
00674       fprintf_filtered (stream, _("<incomplete type>"));
00675       break;
00676 
00677     case TYPE_CODE_COMPLEX:
00678       fprintf_filtered (stream, "%s", decorations->complex_prefix);
00679       if (options->format)
00680         val_print_scalar_formatted (TYPE_TARGET_TYPE (type),
00681                                     valaddr, embedded_offset,
00682                                     original_value, options, 0, stream);
00683       else
00684         print_floating (valaddr + embedded_offset,
00685                         TYPE_TARGET_TYPE (type),
00686                         stream);
00687       fprintf_filtered (stream, "%s", decorations->complex_infix);
00688       if (options->format)
00689         val_print_scalar_formatted (TYPE_TARGET_TYPE (type),
00690                                     valaddr,
00691                                     embedded_offset
00692                                     + TYPE_LENGTH (TYPE_TARGET_TYPE (type)),
00693                                     original_value,
00694                                     options, 0, stream);
00695       else
00696         print_floating (valaddr + embedded_offset
00697                         + TYPE_LENGTH (TYPE_TARGET_TYPE (type)),
00698                         TYPE_TARGET_TYPE (type),
00699                         stream);
00700       fprintf_filtered (stream, "%s", decorations->complex_suffix);
00701       break;
00702 
00703     case TYPE_CODE_UNION:
00704     case TYPE_CODE_STRUCT:
00705     case TYPE_CODE_METHODPTR:
00706     default:
00707       error (_("Unhandled type code %d in symbol table."),
00708              TYPE_CODE (type));
00709     }
00710   gdb_flush (stream);
00711 }
00712 
00713 /* Print using the given LANGUAGE the data of type TYPE located at
00714    VALADDR + EMBEDDED_OFFSET (within GDB), which came from the
00715    inferior at address ADDRESS + EMBEDDED_OFFSET, onto stdio stream
00716    STREAM according to OPTIONS.  VAL is the whole object that came
00717    from ADDRESS.  VALADDR must point to the head of VAL's contents
00718    buffer.
00719 
00720    The language printers will pass down an adjusted EMBEDDED_OFFSET to
00721    further helper subroutines as subfields of TYPE are printed.  In
00722    such cases, VALADDR is passed down unadjusted, as well as VAL, so
00723    that VAL can be queried for metadata about the contents data being
00724    printed, using EMBEDDED_OFFSET as an offset into VAL's contents
00725    buffer.  For example: "has this field been optimized out", or "I'm
00726    printing an object while inspecting a traceframe; has this
00727    particular piece of data been collected?".
00728 
00729    RECURSE indicates the amount of indentation to supply before
00730    continuation lines; this amount is roughly twice the value of
00731    RECURSE.  */
00732 
00733 void
00734 val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
00735            CORE_ADDR address, struct ui_file *stream, int recurse,
00736            const struct value *val,
00737            const struct value_print_options *options,
00738            const struct language_defn *language)
00739 {
00740   volatile struct gdb_exception except;
00741   int ret = 0;
00742   struct value_print_options local_opts = *options;
00743   struct type *real_type = check_typedef (type);
00744 
00745   if (local_opts.prettyformat == Val_prettyformat_default)
00746     local_opts.prettyformat = (local_opts.prettyformat_structs
00747                                ? Val_prettyformat : Val_no_prettyformat);
00748 
00749   QUIT;
00750 
00751   /* Ensure that the type is complete and not just a stub.  If the type is
00752      only a stub and we can't find and substitute its complete type, then
00753      print appropriate string and return.  */
00754 
00755   if (TYPE_STUB (real_type))
00756     {
00757       fprintf_filtered (stream, _("<incomplete type>"));
00758       gdb_flush (stream);
00759       return;
00760     }
00761 
00762   if (!valprint_check_validity (stream, real_type, embedded_offset, val))
00763     return;
00764 
00765   if (!options->raw)
00766     {
00767       ret = apply_val_pretty_printer (type, valaddr, embedded_offset,
00768                                       address, stream, recurse,
00769                                       val, options, language);
00770       if (ret)
00771         return;
00772     }
00773 
00774   /* Handle summary mode.  If the value is a scalar, print it;
00775      otherwise, print an ellipsis.  */
00776   if (options->summary && !val_print_scalar_type_p (type))
00777     {
00778       fprintf_filtered (stream, "...");
00779       return;
00780     }
00781 
00782   TRY_CATCH (except, RETURN_MASK_ERROR)
00783     {
00784       language->la_val_print (type, valaddr, embedded_offset, address,
00785                               stream, recurse, val,
00786                               &local_opts);
00787     }
00788   if (except.reason < 0)
00789     fprintf_filtered (stream, _("<error reading variable>"));
00790 }
00791 
00792 /* Check whether the value VAL is printable.  Return 1 if it is;
00793    return 0 and print an appropriate error message to STREAM according to
00794    OPTIONS if it is not.  */
00795 
00796 static int
00797 value_check_printable (struct value *val, struct ui_file *stream,
00798                        const struct value_print_options *options)
00799 {
00800   if (val == 0)
00801     {
00802       fprintf_filtered (stream, _("<address of value unknown>"));
00803       return 0;
00804     }
00805 
00806   if (value_entirely_optimized_out (val))
00807     {
00808       if (options->summary && !val_print_scalar_type_p (value_type (val)))
00809         fprintf_filtered (stream, "...");
00810       else
00811         val_print_optimized_out (val, stream);
00812       return 0;
00813     }
00814 
00815   if (TYPE_CODE (value_type (val)) == TYPE_CODE_INTERNAL_FUNCTION)
00816     {
00817       fprintf_filtered (stream, _("<internal function %s>"),
00818                         value_internal_function_name (val));
00819       return 0;
00820     }
00821 
00822   return 1;
00823 }
00824 
00825 /* Print using the given LANGUAGE the value VAL onto stream STREAM according
00826    to OPTIONS.
00827 
00828    This is a preferable interface to val_print, above, because it uses
00829    GDB's value mechanism.  */
00830 
00831 void
00832 common_val_print (struct value *val, struct ui_file *stream, int recurse,
00833                   const struct value_print_options *options,
00834                   const struct language_defn *language)
00835 {
00836   if (!value_check_printable (val, stream, options))
00837     return;
00838 
00839   if (language->la_language == language_ada)
00840     /* The value might have a dynamic type, which would cause trouble
00841        below when trying to extract the value contents (since the value
00842        size is determined from the type size which is unknown).  So
00843        get a fixed representation of our value.  */
00844     val = ada_to_fixed_value (val);
00845 
00846   val_print (value_type (val), value_contents_for_printing (val),
00847              value_embedded_offset (val), value_address (val),
00848              stream, recurse,
00849              val, options, language);
00850 }
00851 
00852 /* Print on stream STREAM the value VAL according to OPTIONS.  The value
00853    is printed using the current_language syntax.  */
00854 
00855 void
00856 value_print (struct value *val, struct ui_file *stream,
00857              const struct value_print_options *options)
00858 {
00859   if (!value_check_printable (val, stream, options))
00860     return;
00861 
00862   if (!options->raw)
00863     {
00864       int r = apply_val_pretty_printer (value_type (val),
00865                                         value_contents_for_printing (val),
00866                                         value_embedded_offset (val),
00867                                         value_address (val),
00868                                         stream, 0,
00869                                         val, options, current_language);
00870 
00871       if (r)
00872         return;
00873     }
00874 
00875   LA_VALUE_PRINT (val, stream, options);
00876 }
00877 
00878 /* Called by various <lang>_val_print routines to print
00879    TYPE_CODE_INT's.  TYPE is the type.  VALADDR is the address of the
00880    value.  STREAM is where to print the value.  */
00881 
00882 void
00883 val_print_type_code_int (struct type *type, const gdb_byte *valaddr,
00884                          struct ui_file *stream)
00885 {
00886   enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
00887 
00888   if (TYPE_LENGTH (type) > sizeof (LONGEST))
00889     {
00890       LONGEST val;
00891 
00892       if (TYPE_UNSIGNED (type)
00893           && extract_long_unsigned_integer (valaddr, TYPE_LENGTH (type),
00894                                             byte_order, &val))
00895         {
00896           print_longest (stream, 'u', 0, val);
00897         }
00898       else
00899         {
00900           /* Signed, or we couldn't turn an unsigned value into a
00901              LONGEST.  For signed values, one could assume two's
00902              complement (a reasonable assumption, I think) and do
00903              better than this.  */
00904           print_hex_chars (stream, (unsigned char *) valaddr,
00905                            TYPE_LENGTH (type), byte_order);
00906         }
00907     }
00908   else
00909     {
00910       print_longest (stream, TYPE_UNSIGNED (type) ? 'u' : 'd', 0,
00911                      unpack_long (type, valaddr));
00912     }
00913 }
00914 
00915 void
00916 val_print_type_code_flags (struct type *type, const gdb_byte *valaddr,
00917                            struct ui_file *stream)
00918 {
00919   ULONGEST val = unpack_long (type, valaddr);
00920   int bitpos, nfields = TYPE_NFIELDS (type);
00921 
00922   fputs_filtered ("[ ", stream);
00923   for (bitpos = 0; bitpos < nfields; bitpos++)
00924     {
00925       if (TYPE_FIELD_BITPOS (type, bitpos) != -1
00926           && (val & ((ULONGEST)1 << bitpos)))
00927         {
00928           if (TYPE_FIELD_NAME (type, bitpos))
00929             fprintf_filtered (stream, "%s ", TYPE_FIELD_NAME (type, bitpos));
00930           else
00931             fprintf_filtered (stream, "#%d ", bitpos);
00932         }
00933     }
00934   fputs_filtered ("]", stream);
00935 }
00936 
00937 /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
00938    according to OPTIONS and SIZE on STREAM.  Format i is not supported
00939    at this level.
00940 
00941    This is how the elements of an array or structure are printed
00942    with a format.  */
00943 
00944 void
00945 val_print_scalar_formatted (struct type *type,
00946                             const gdb_byte *valaddr, int embedded_offset,
00947                             const struct value *val,
00948                             const struct value_print_options *options,
00949                             int size,
00950                             struct ui_file *stream)
00951 {
00952   gdb_assert (val != NULL);
00953   gdb_assert (valaddr == value_contents_for_printing_const (val));
00954 
00955   /* If we get here with a string format, try again without it.  Go
00956      all the way back to the language printers, which may call us
00957      again.  */
00958   if (options->format == 's')
00959     {
00960       struct value_print_options opts = *options;
00961       opts.format = 0;
00962       opts.deref_ref = 0;
00963       val_print (type, valaddr, embedded_offset, 0, stream, 0, val, &opts,
00964                  current_language);
00965       return;
00966     }
00967 
00968   /* A scalar object that does not have all bits available can't be
00969      printed, because all bits contribute to its representation.  */
00970   if (!value_bits_valid (val, TARGET_CHAR_BIT * embedded_offset,
00971                               TARGET_CHAR_BIT * TYPE_LENGTH (type)))
00972     val_print_optimized_out (val, stream);
00973   else if (!value_bytes_available (val, embedded_offset, TYPE_LENGTH (type)))
00974     val_print_unavailable (stream);
00975   else
00976     print_scalar_formatted (valaddr + embedded_offset, type,
00977                             options, size, stream);
00978 }
00979 
00980 /* Print a number according to FORMAT which is one of d,u,x,o,b,h,w,g.
00981    The raison d'etre of this function is to consolidate printing of 
00982    LONG_LONG's into this one function.  The format chars b,h,w,g are 
00983    from print_scalar_formatted().  Numbers are printed using C
00984    format.
00985 
00986    USE_C_FORMAT means to use C format in all cases.  Without it, 
00987    'o' and 'x' format do not include the standard C radix prefix
00988    (leading 0 or 0x). 
00989    
00990    Hilfinger/2004-09-09: USE_C_FORMAT was originally called USE_LOCAL
00991    and was intended to request formating according to the current
00992    language and would be used for most integers that GDB prints.  The
00993    exceptional cases were things like protocols where the format of
00994    the integer is a protocol thing, not a user-visible thing).  The
00995    parameter remains to preserve the information of what things might
00996    be printed with language-specific format, should we ever resurrect
00997    that capability.  */
00998 
00999 void
01000 print_longest (struct ui_file *stream, int format, int use_c_format,
01001                LONGEST val_long)
01002 {
01003   const char *val;
01004 
01005   switch (format)
01006     {
01007     case 'd':
01008       val = int_string (val_long, 10, 1, 0, 1); break;
01009     case 'u':
01010       val = int_string (val_long, 10, 0, 0, 1); break;
01011     case 'x':
01012       val = int_string (val_long, 16, 0, 0, use_c_format); break;
01013     case 'b':
01014       val = int_string (val_long, 16, 0, 2, 1); break;
01015     case 'h':
01016       val = int_string (val_long, 16, 0, 4, 1); break;
01017     case 'w':
01018       val = int_string (val_long, 16, 0, 8, 1); break;
01019     case 'g':
01020       val = int_string (val_long, 16, 0, 16, 1); break;
01021       break;
01022     case 'o':
01023       val = int_string (val_long, 8, 0, 0, use_c_format); break;
01024     default:
01025       internal_error (__FILE__, __LINE__,
01026                       _("failed internal consistency check"));
01027     } 
01028   fputs_filtered (val, stream);
01029 }
01030 
01031 /* This used to be a macro, but I don't think it is called often enough
01032    to merit such treatment.  */
01033 /* Convert a LONGEST to an int.  This is used in contexts (e.g. number of
01034    arguments to a function, number in a value history, register number, etc.)
01035    where the value must not be larger than can fit in an int.  */
01036 
01037 int
01038 longest_to_int (LONGEST arg)
01039 {
01040   /* Let the compiler do the work.  */
01041   int rtnval = (int) arg;
01042 
01043   /* Check for overflows or underflows.  */
01044   if (sizeof (LONGEST) > sizeof (int))
01045     {
01046       if (rtnval != arg)
01047         {
01048           error (_("Value out of range."));
01049         }
01050     }
01051   return (rtnval);
01052 }
01053 
01054 /* Print a floating point value of type TYPE (not always a
01055    TYPE_CODE_FLT), pointed to in GDB by VALADDR, on STREAM.  */
01056 
01057 void
01058 print_floating (const gdb_byte *valaddr, struct type *type,
01059                 struct ui_file *stream)
01060 {
01061   DOUBLEST doub;
01062   int inv;
01063   const struct floatformat *fmt = NULL;
01064   unsigned len = TYPE_LENGTH (type);
01065   enum float_kind kind;
01066 
01067   /* If it is a floating-point, check for obvious problems.  */
01068   if (TYPE_CODE (type) == TYPE_CODE_FLT)
01069     fmt = floatformat_from_type (type);
01070   if (fmt != NULL)
01071     {
01072       kind = floatformat_classify (fmt, valaddr);
01073       if (kind == float_nan)
01074         {
01075           if (floatformat_is_negative (fmt, valaddr))
01076             fprintf_filtered (stream, "-");
01077           fprintf_filtered (stream, "nan(");
01078           fputs_filtered ("0x", stream);
01079           fputs_filtered (floatformat_mantissa (fmt, valaddr), stream);
01080           fprintf_filtered (stream, ")");
01081           return;
01082         }
01083       else if (kind == float_infinite)
01084         {
01085           if (floatformat_is_negative (fmt, valaddr))
01086             fputs_filtered ("-", stream);
01087           fputs_filtered ("inf", stream);
01088           return;
01089         }
01090     }
01091 
01092   /* NOTE: cagney/2002-01-15: The TYPE passed into print_floating()
01093      isn't necessarily a TYPE_CODE_FLT.  Consequently, unpack_double
01094      needs to be used as that takes care of any necessary type
01095      conversions.  Such conversions are of course direct to DOUBLEST
01096      and disregard any possible target floating point limitations.
01097      For instance, a u64 would be converted and displayed exactly on a
01098      host with 80 bit DOUBLEST but with loss of information on a host
01099      with 64 bit DOUBLEST.  */
01100 
01101   doub = unpack_double (type, valaddr, &inv);
01102   if (inv)
01103     {
01104       fprintf_filtered (stream, "<invalid float value>");
01105       return;
01106     }
01107 
01108   /* FIXME: kettenis/2001-01-20: The following code makes too much
01109      assumptions about the host and target floating point format.  */
01110 
01111   /* NOTE: cagney/2002-02-03: Since the TYPE of what was passed in may
01112      not necessarily be a TYPE_CODE_FLT, the below ignores that and
01113      instead uses the type's length to determine the precision of the
01114      floating-point value being printed.  */
01115 
01116   if (len < sizeof (double))
01117       fprintf_filtered (stream, "%.9g", (double) doub);
01118   else if (len == sizeof (double))
01119       fprintf_filtered (stream, "%.17g", (double) doub);
01120   else
01121 #ifdef PRINTF_HAS_LONG_DOUBLE
01122     fprintf_filtered (stream, "%.35Lg", doub);
01123 #else
01124     /* This at least wins with values that are representable as
01125        doubles.  */
01126     fprintf_filtered (stream, "%.17g", (double) doub);
01127 #endif
01128 }
01129 
01130 void
01131 print_decimal_floating (const gdb_byte *valaddr, struct type *type,
01132                         struct ui_file *stream)
01133 {
01134   enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
01135   char decstr[MAX_DECIMAL_STRING];
01136   unsigned len = TYPE_LENGTH (type);
01137 
01138   decimal_to_string (valaddr, len, byte_order, decstr);
01139   fputs_filtered (decstr, stream);
01140   return;
01141 }
01142 
01143 void
01144 print_binary_chars (struct ui_file *stream, const gdb_byte *valaddr,
01145                     unsigned len, enum bfd_endian byte_order)
01146 {
01147 
01148 #define BITS_IN_BYTES 8
01149 
01150   const gdb_byte *p;
01151   unsigned int i;
01152   int b;
01153 
01154   /* Declared "int" so it will be signed.
01155      This ensures that right shift will shift in zeros.  */
01156 
01157   const int mask = 0x080;
01158 
01159   /* FIXME: We should be not printing leading zeroes in most cases.  */
01160 
01161   if (byte_order == BFD_ENDIAN_BIG)
01162     {
01163       for (p = valaddr;
01164            p < valaddr + len;
01165            p++)
01166         {
01167           /* Every byte has 8 binary characters; peel off
01168              and print from the MSB end.  */
01169 
01170           for (i = 0; i < (BITS_IN_BYTES * sizeof (*p)); i++)
01171             {
01172               if (*p & (mask >> i))
01173                 b = 1;
01174               else
01175                 b = 0;
01176 
01177               fprintf_filtered (stream, "%1d", b);
01178             }
01179         }
01180     }
01181   else
01182     {
01183       for (p = valaddr + len - 1;
01184            p >= valaddr;
01185            p--)
01186         {
01187           for (i = 0; i < (BITS_IN_BYTES * sizeof (*p)); i++)
01188             {
01189               if (*p & (mask >> i))
01190                 b = 1;
01191               else
01192                 b = 0;
01193 
01194               fprintf_filtered (stream, "%1d", b);
01195             }
01196         }
01197     }
01198 }
01199 
01200 /* VALADDR points to an integer of LEN bytes.
01201    Print it in octal on stream or format it in buf.  */
01202 
01203 void
01204 print_octal_chars (struct ui_file *stream, const gdb_byte *valaddr,
01205                    unsigned len, enum bfd_endian byte_order)
01206 {
01207   const gdb_byte *p;
01208   unsigned char octa1, octa2, octa3, carry;
01209   int cycle;
01210 
01211   /* FIXME: We should be not printing leading zeroes in most cases.  */
01212 
01213 
01214   /* Octal is 3 bits, which doesn't fit.  Yuk.  So we have to track
01215    * the extra bits, which cycle every three bytes:
01216    *
01217    * Byte side:       0            1             2          3
01218    *                         |             |            |            |
01219    * bit number   123 456 78 | 9 012 345 6 | 78 901 234 | 567 890 12 |
01220    *
01221    * Octal side:   0   1   carry  3   4  carry ...
01222    *
01223    * Cycle number:    0             1            2
01224    *
01225    * But of course we are printing from the high side, so we have to
01226    * figure out where in the cycle we are so that we end up with no
01227    * left over bits at the end.
01228    */
01229 #define BITS_IN_OCTAL 3
01230 #define HIGH_ZERO     0340
01231 #define LOW_ZERO      0016
01232 #define CARRY_ZERO    0003
01233 #define HIGH_ONE      0200
01234 #define MID_ONE       0160
01235 #define LOW_ONE       0016
01236 #define CARRY_ONE     0001
01237 #define HIGH_TWO      0300
01238 #define MID_TWO       0070
01239 #define LOW_TWO       0007
01240 
01241   /* For 32 we start in cycle 2, with two bits and one bit carry;
01242      for 64 in cycle in cycle 1, with one bit and a two bit carry.  */
01243 
01244   cycle = (len * BITS_IN_BYTES) % BITS_IN_OCTAL;
01245   carry = 0;
01246 
01247   fputs_filtered ("0", stream);
01248   if (byte_order == BFD_ENDIAN_BIG)
01249     {
01250       for (p = valaddr;
01251            p < valaddr + len;
01252            p++)
01253         {
01254           switch (cycle)
01255             {
01256             case 0:
01257               /* No carry in, carry out two bits.  */
01258 
01259               octa1 = (HIGH_ZERO & *p) >> 5;
01260               octa2 = (LOW_ZERO & *p) >> 2;
01261               carry = (CARRY_ZERO & *p);
01262               fprintf_filtered (stream, "%o", octa1);
01263               fprintf_filtered (stream, "%o", octa2);
01264               break;
01265 
01266             case 1:
01267               /* Carry in two bits, carry out one bit.  */
01268 
01269               octa1 = (carry << 1) | ((HIGH_ONE & *p) >> 7);
01270               octa2 = (MID_ONE & *p) >> 4;
01271               octa3 = (LOW_ONE & *p) >> 1;
01272               carry = (CARRY_ONE & *p);
01273               fprintf_filtered (stream, "%o", octa1);
01274               fprintf_filtered (stream, "%o", octa2);
01275               fprintf_filtered (stream, "%o", octa3);
01276               break;
01277 
01278             case 2:
01279               /* Carry in one bit, no carry out.  */
01280 
01281               octa1 = (carry << 2) | ((HIGH_TWO & *p) >> 6);
01282               octa2 = (MID_TWO & *p) >> 3;
01283               octa3 = (LOW_TWO & *p);
01284               carry = 0;
01285               fprintf_filtered (stream, "%o", octa1);
01286               fprintf_filtered (stream, "%o", octa2);
01287               fprintf_filtered (stream, "%o", octa3);
01288               break;
01289 
01290             default:
01291               error (_("Internal error in octal conversion;"));
01292             }
01293 
01294           cycle++;
01295           cycle = cycle % BITS_IN_OCTAL;
01296         }
01297     }
01298   else
01299     {
01300       for (p = valaddr + len - 1;
01301            p >= valaddr;
01302            p--)
01303         {
01304           switch (cycle)
01305             {
01306             case 0:
01307               /* Carry out, no carry in */
01308 
01309               octa1 = (HIGH_ZERO & *p) >> 5;
01310               octa2 = (LOW_ZERO & *p) >> 2;
01311               carry = (CARRY_ZERO & *p);
01312               fprintf_filtered (stream, "%o", octa1);
01313               fprintf_filtered (stream, "%o", octa2);
01314               break;
01315 
01316             case 1:
01317               /* Carry in, carry out */
01318 
01319               octa1 = (carry << 1) | ((HIGH_ONE & *p) >> 7);
01320               octa2 = (MID_ONE & *p) >> 4;
01321               octa3 = (LOW_ONE & *p) >> 1;
01322               carry = (CARRY_ONE & *p);
01323               fprintf_filtered (stream, "%o", octa1);
01324               fprintf_filtered (stream, "%o", octa2);
01325               fprintf_filtered (stream, "%o", octa3);
01326               break;
01327 
01328             case 2:
01329               /* Carry in, no carry out */
01330 
01331               octa1 = (carry << 2) | ((HIGH_TWO & *p) >> 6);
01332               octa2 = (MID_TWO & *p) >> 3;
01333               octa3 = (LOW_TWO & *p);
01334               carry = 0;
01335               fprintf_filtered (stream, "%o", octa1);
01336               fprintf_filtered (stream, "%o", octa2);
01337               fprintf_filtered (stream, "%o", octa3);
01338               break;
01339 
01340             default:
01341               error (_("Internal error in octal conversion;"));
01342             }
01343 
01344           cycle++;
01345           cycle = cycle % BITS_IN_OCTAL;
01346         }
01347     }
01348 
01349 }
01350 
01351 /* VALADDR points to an integer of LEN bytes.
01352    Print it in decimal on stream or format it in buf.  */
01353 
01354 void
01355 print_decimal_chars (struct ui_file *stream, const gdb_byte *valaddr,
01356                      unsigned len, enum bfd_endian byte_order)
01357 {
01358 #define TEN             10
01359 #define CARRY_OUT(  x ) ((x) / TEN)     /* extend char to int */
01360 #define CARRY_LEFT( x ) ((x) % TEN)
01361 #define SHIFT( x )      ((x) << 4)
01362 #define LOW_NIBBLE(  x ) ( (x) & 0x00F)
01363 #define HIGH_NIBBLE( x ) (((x) & 0x0F0) >> 4)
01364 
01365   const gdb_byte *p;
01366   unsigned char *digits;
01367   int carry;
01368   int decimal_len;
01369   int i, j, decimal_digits;
01370   int dummy;
01371   int flip;
01372 
01373   /* Base-ten number is less than twice as many digits
01374      as the base 16 number, which is 2 digits per byte.  */
01375 
01376   decimal_len = len * 2 * 2;
01377   digits = xmalloc (decimal_len);
01378 
01379   for (i = 0; i < decimal_len; i++)
01380     {
01381       digits[i] = 0;
01382     }
01383 
01384   /* Ok, we have an unknown number of bytes of data to be printed in
01385    * decimal.
01386    *
01387    * Given a hex number (in nibbles) as XYZ, we start by taking X and
01388    * decemalizing it as "x1 x2" in two decimal nibbles.  Then we multiply
01389    * the nibbles by 16, add Y and re-decimalize.  Repeat with Z.
01390    *
01391    * The trick is that "digits" holds a base-10 number, but sometimes
01392    * the individual digits are > 10.
01393    *
01394    * Outer loop is per nibble (hex digit) of input, from MSD end to
01395    * LSD end.
01396    */
01397   decimal_digits = 0;           /* Number of decimal digits so far */
01398   p = (byte_order == BFD_ENDIAN_BIG) ? valaddr : valaddr + len - 1;
01399   flip = 0;
01400   while ((byte_order == BFD_ENDIAN_BIG) ? (p < valaddr + len) : (p >= valaddr))
01401     {
01402       /*
01403        * Multiply current base-ten number by 16 in place.
01404        * Each digit was between 0 and 9, now is between
01405        * 0 and 144.
01406        */
01407       for (j = 0; j < decimal_digits; j++)
01408         {
01409           digits[j] = SHIFT (digits[j]);
01410         }
01411 
01412       /* Take the next nibble off the input and add it to what
01413        * we've got in the LSB position.  Bottom 'digit' is now
01414        * between 0 and 159.
01415        *
01416        * "flip" is used to run this loop twice for each byte.
01417        */
01418       if (flip == 0)
01419         {
01420           /* Take top nibble.  */
01421 
01422           digits[0] += HIGH_NIBBLE (*p);
01423           flip = 1;
01424         }
01425       else
01426         {
01427           /* Take low nibble and bump our pointer "p".  */
01428 
01429           digits[0] += LOW_NIBBLE (*p);
01430           if (byte_order == BFD_ENDIAN_BIG)
01431             p++;
01432           else
01433             p--;
01434           flip = 0;
01435         }
01436 
01437       /* Re-decimalize.  We have to do this often enough
01438        * that we don't overflow, but once per nibble is
01439        * overkill.  Easier this way, though.  Note that the
01440        * carry is often larger than 10 (e.g. max initial
01441        * carry out of lowest nibble is 15, could bubble all
01442        * the way up greater than 10).  So we have to do
01443        * the carrying beyond the last current digit.
01444        */
01445       carry = 0;
01446       for (j = 0; j < decimal_len - 1; j++)
01447         {
01448           digits[j] += carry;
01449 
01450           /* "/" won't handle an unsigned char with
01451            * a value that if signed would be negative.
01452            * So extend to longword int via "dummy".
01453            */
01454           dummy = digits[j];
01455           carry = CARRY_OUT (dummy);
01456           digits[j] = CARRY_LEFT (dummy);
01457 
01458           if (j >= decimal_digits && carry == 0)
01459             {
01460               /*
01461                * All higher digits are 0 and we
01462                * no longer have a carry.
01463                *
01464                * Note: "j" is 0-based, "decimal_digits" is
01465                *       1-based.
01466                */
01467               decimal_digits = j + 1;
01468               break;
01469             }
01470         }
01471     }
01472 
01473   /* Ok, now "digits" is the decimal representation, with
01474      the "decimal_digits" actual digits.  Print!  */
01475 
01476   for (i = decimal_digits - 1; i >= 0; i--)
01477     {
01478       fprintf_filtered (stream, "%1d", digits[i]);
01479     }
01480   xfree (digits);
01481 }
01482 
01483 /* VALADDR points to an integer of LEN bytes.  Print it in hex on stream.  */
01484 
01485 void
01486 print_hex_chars (struct ui_file *stream, const gdb_byte *valaddr,
01487                  unsigned len, enum bfd_endian byte_order)
01488 {
01489   const gdb_byte *p;
01490 
01491   /* FIXME: We should be not printing leading zeroes in most cases.  */
01492 
01493   fputs_filtered ("0x", stream);
01494   if (byte_order == BFD_ENDIAN_BIG)
01495     {
01496       for (p = valaddr;
01497            p < valaddr + len;
01498            p++)
01499         {
01500           fprintf_filtered (stream, "%02x", *p);
01501         }
01502     }
01503   else
01504     {
01505       for (p = valaddr + len - 1;
01506            p >= valaddr;
01507            p--)
01508         {
01509           fprintf_filtered (stream, "%02x", *p);
01510         }
01511     }
01512 }
01513 
01514 /* VALADDR points to a char integer of LEN bytes.
01515    Print it out in appropriate language form on stream.
01516    Omit any leading zero chars.  */
01517 
01518 void
01519 print_char_chars (struct ui_file *stream, struct type *type,
01520                   const gdb_byte *valaddr,
01521                   unsigned len, enum bfd_endian byte_order)
01522 {
01523   const gdb_byte *p;
01524 
01525   if (byte_order == BFD_ENDIAN_BIG)
01526     {
01527       p = valaddr;
01528       while (p < valaddr + len - 1 && *p == 0)
01529         ++p;
01530 
01531       while (p < valaddr + len)
01532         {
01533           LA_EMIT_CHAR (*p, type, stream, '\'');
01534           ++p;
01535         }
01536     }
01537   else
01538     {
01539       p = valaddr + len - 1;
01540       while (p > valaddr && *p == 0)
01541         --p;
01542 
01543       while (p >= valaddr)
01544         {
01545           LA_EMIT_CHAR (*p, type, stream, '\'');
01546           --p;
01547         }
01548     }
01549 }
01550 
01551 /* Print function pointer with inferior address ADDRESS onto stdio
01552    stream STREAM.  */
01553 
01554 void
01555 print_function_pointer_address (const struct value_print_options *options,
01556                                 struct gdbarch *gdbarch,
01557                                 CORE_ADDR address,
01558                                 struct ui_file *stream)
01559 {
01560   CORE_ADDR func_addr
01561     = gdbarch_convert_from_func_ptr_addr (gdbarch, address,
01562                                           &current_target);
01563 
01564   /* If the function pointer is represented by a description, print
01565      the address of the description.  */
01566   if (options->addressprint && func_addr != address)
01567     {
01568       fputs_filtered ("@", stream);
01569       fputs_filtered (paddress (gdbarch, address), stream);
01570       fputs_filtered (": ", stream);
01571     }
01572   print_address_demangle (options, gdbarch, func_addr, stream, demangle);
01573 }
01574 
01575 
01576 /* Print on STREAM using the given OPTIONS the index for the element
01577    at INDEX of an array whose index type is INDEX_TYPE.  */
01578     
01579 void  
01580 maybe_print_array_index (struct type *index_type, LONGEST index,
01581                          struct ui_file *stream,
01582                          const struct value_print_options *options)
01583 {
01584   struct value *index_value;
01585 
01586   if (!options->print_array_indexes)
01587     return; 
01588     
01589   index_value = value_from_longest (index_type, index);
01590 
01591   LA_PRINT_ARRAY_INDEX (index_value, stream, options);
01592 }
01593 
01594 /*  Called by various <lang>_val_print routines to print elements of an
01595    array in the form "<elem1>, <elem2>, <elem3>, ...".
01596 
01597    (FIXME?)  Assumes array element separator is a comma, which is correct
01598    for all languages currently handled.
01599    (FIXME?)  Some languages have a notation for repeated array elements,
01600    perhaps we should try to use that notation when appropriate.  */
01601 
01602 void
01603 val_print_array_elements (struct type *type,
01604                           const gdb_byte *valaddr, int embedded_offset,
01605                           CORE_ADDR address, struct ui_file *stream,
01606                           int recurse,
01607                           const struct value *val,
01608                           const struct value_print_options *options,
01609                           unsigned int i)
01610 {
01611   unsigned int things_printed = 0;
01612   unsigned len;
01613   struct type *elttype, *index_type;
01614   unsigned eltlen;
01615   /* Position of the array element we are examining to see
01616      whether it is repeated.  */
01617   unsigned int rep1;
01618   /* Number of repetitions we have detected so far.  */
01619   unsigned int reps;
01620   LONGEST low_bound, high_bound;
01621 
01622   elttype = TYPE_TARGET_TYPE (type);
01623   eltlen = TYPE_LENGTH (check_typedef (elttype));
01624   index_type = TYPE_INDEX_TYPE (type);
01625 
01626   if (get_array_bounds (type, &low_bound, &high_bound))
01627     {
01628       /* The array length should normally be HIGH_BOUND - LOW_BOUND + 1.
01629          But we have to be a little extra careful, because some languages
01630          such as Ada allow LOW_BOUND to be greater than HIGH_BOUND for
01631          empty arrays.  In that situation, the array length is just zero,
01632          not negative!  */
01633       if (low_bound > high_bound)
01634         len = 0;
01635       else
01636         len = high_bound - low_bound + 1;
01637     }
01638   else
01639     {
01640       warning (_("unable to get bounds of array, assuming null array"));
01641       low_bound = 0;
01642       len = 0;
01643     }
01644 
01645   annotate_array_section_begin (i, elttype);
01646 
01647   for (; i < len && things_printed < options->print_max; i++)
01648     {
01649       if (i != 0)
01650         {
01651           if (options->prettyformat_arrays)
01652             {
01653               fprintf_filtered (stream, ",\n");
01654               print_spaces_filtered (2 + 2 * recurse, stream);
01655             }
01656           else
01657             {
01658               fprintf_filtered (stream, ", ");
01659             }
01660         }
01661       wrap_here (n_spaces (2 + 2 * recurse));
01662       maybe_print_array_index (index_type, i + low_bound,
01663                                stream, options);
01664 
01665       rep1 = i + 1;
01666       reps = 1;
01667       /* Only check for reps if repeat_count_threshold is not set to
01668          UINT_MAX (unlimited).  */
01669       if (options->repeat_count_threshold < UINT_MAX)
01670         {
01671           while (rep1 < len
01672                  && value_available_contents_eq (val,
01673                                                  embedded_offset + i * eltlen,
01674                                                  val,
01675                                                  (embedded_offset
01676                                                   + rep1 * eltlen),
01677                                                  eltlen))
01678             {
01679               ++reps;
01680               ++rep1;
01681             }
01682         }
01683 
01684       if (reps > options->repeat_count_threshold)
01685         {
01686           val_print (elttype, valaddr, embedded_offset + i * eltlen,
01687                      address, stream, recurse + 1, val, options,
01688                      current_language);
01689           annotate_elt_rep (reps);
01690           fprintf_filtered (stream, " <repeats %u times>", reps);
01691           annotate_elt_rep_end ();
01692 
01693           i = rep1 - 1;
01694           things_printed += options->repeat_count_threshold;
01695         }
01696       else
01697         {
01698           val_print (elttype, valaddr, embedded_offset + i * eltlen,
01699                      address,
01700                      stream, recurse + 1, val, options, current_language);
01701           annotate_elt ();
01702           things_printed++;
01703         }
01704     }
01705   annotate_array_section_end ();
01706   if (i < len)
01707     {
01708       fprintf_filtered (stream, "...");
01709     }
01710 }
01711 
01712 /* Read LEN bytes of target memory at address MEMADDR, placing the
01713    results in GDB's memory at MYADDR.  Returns a count of the bytes
01714    actually read, and optionally a target_xfer_error value in the
01715    location pointed to by ERRPTR if ERRPTR is non-null.  */
01716 
01717 /* FIXME: cagney/1999-10-14: Only used by val_print_string.  Can this
01718    function be eliminated.  */
01719 
01720 static int
01721 partial_memory_read (CORE_ADDR memaddr, gdb_byte *myaddr,
01722                      int len, int *errptr)
01723 {
01724   int nread;                    /* Number of bytes actually read.  */
01725   int errcode;                  /* Error from last read.  */
01726 
01727   /* First try a complete read.  */
01728   errcode = target_read_memory (memaddr, myaddr, len);
01729   if (errcode == 0)
01730     {
01731       /* Got it all.  */
01732       nread = len;
01733     }
01734   else
01735     {
01736       /* Loop, reading one byte at a time until we get as much as we can.  */
01737       for (errcode = 0, nread = 0; len > 0 && errcode == 0; nread++, len--)
01738         {
01739           errcode = target_read_memory (memaddr++, myaddr++, 1);
01740         }
01741       /* If an error, the last read was unsuccessful, so adjust count.  */
01742       if (errcode != 0)
01743         {
01744           nread--;
01745         }
01746     }
01747   if (errptr != NULL)
01748     {
01749       *errptr = errcode;
01750     }
01751   return (nread);
01752 }
01753 
01754 /* Read a string from the inferior, at ADDR, with LEN characters of WIDTH bytes
01755    each.  Fetch at most FETCHLIMIT characters.  BUFFER will be set to a newly
01756    allocated buffer containing the string, which the caller is responsible to
01757    free, and BYTES_READ will be set to the number of bytes read.  Returns 0 on
01758    success, or a target_xfer_error on failure.
01759 
01760    If LEN > 0, reads exactly LEN characters (including eventual NULs in
01761    the middle or end of the string).  If LEN is -1, stops at the first
01762    null character (not necessarily the first null byte) up to a maximum
01763    of FETCHLIMIT characters.  Set FETCHLIMIT to UINT_MAX to read as many
01764    characters as possible from the string.
01765 
01766    Unless an exception is thrown, BUFFER will always be allocated, even on
01767    failure.  In this case, some characters might have been read before the
01768    failure happened.  Check BYTES_READ to recognize this situation.
01769 
01770    Note: There was a FIXME asking to make this code use target_read_string,
01771    but this function is more general (can read past null characters, up to
01772    given LEN).  Besides, it is used much more often than target_read_string
01773    so it is more tested.  Perhaps callers of target_read_string should use
01774    this function instead?  */
01775 
01776 int
01777 read_string (CORE_ADDR addr, int len, int width, unsigned int fetchlimit,
01778              enum bfd_endian byte_order, gdb_byte **buffer, int *bytes_read)
01779 {
01780   int found_nul;                /* Non-zero if we found the nul char.  */
01781   int errcode;                  /* Errno returned from bad reads.  */
01782   unsigned int nfetch;          /* Chars to fetch / chars fetched.  */
01783   unsigned int chunksize;       /* Size of each fetch, in chars.  */
01784   gdb_byte *bufptr;             /* Pointer to next available byte in
01785                                    buffer.  */
01786   gdb_byte *limit;              /* First location past end of fetch buffer.  */
01787   struct cleanup *old_chain = NULL;     /* Top of the old cleanup chain.  */
01788 
01789   /* Decide how large of chunks to try to read in one operation.  This
01790      is also pretty simple.  If LEN >= zero, then we want fetchlimit chars,
01791      so we might as well read them all in one operation.  If LEN is -1, we
01792      are looking for a NUL terminator to end the fetching, so we might as
01793      well read in blocks that are large enough to be efficient, but not so
01794      large as to be slow if fetchlimit happens to be large.  So we choose the
01795      minimum of 8 and fetchlimit.  We used to use 200 instead of 8 but
01796      200 is way too big for remote debugging over a serial line.  */
01797 
01798   chunksize = (len == -1 ? min (8, fetchlimit) : fetchlimit);
01799 
01800   /* Loop until we either have all the characters, or we encounter
01801      some error, such as bumping into the end of the address space.  */
01802 
01803   found_nul = 0;
01804   *buffer = NULL;
01805 
01806   old_chain = make_cleanup (free_current_contents, buffer);
01807 
01808   if (len > 0)
01809     {
01810       *buffer = (gdb_byte *) xmalloc (len * width);
01811       bufptr = *buffer;
01812 
01813       nfetch = partial_memory_read (addr, bufptr, len * width, &errcode)
01814         / width;
01815       addr += nfetch * width;
01816       bufptr += nfetch * width;
01817     }
01818   else if (len == -1)
01819     {
01820       unsigned long bufsize = 0;
01821 
01822       do
01823         {
01824           QUIT;
01825           nfetch = min (chunksize, fetchlimit - bufsize);
01826 
01827           if (*buffer == NULL)
01828             *buffer = (gdb_byte *) xmalloc (nfetch * width);
01829           else
01830             *buffer = (gdb_byte *) xrealloc (*buffer,
01831                                              (nfetch + bufsize) * width);
01832 
01833           bufptr = *buffer + bufsize * width;
01834           bufsize += nfetch;
01835 
01836           /* Read as much as we can.  */
01837           nfetch = partial_memory_read (addr, bufptr, nfetch * width, &errcode)
01838                     / width;
01839 
01840           /* Scan this chunk for the null character that terminates the string
01841              to print.  If found, we don't need to fetch any more.  Note
01842              that bufptr is explicitly left pointing at the next character
01843              after the null character, or at the next character after the end
01844              of the buffer.  */
01845 
01846           limit = bufptr + nfetch * width;
01847           while (bufptr < limit)
01848             {
01849               unsigned long c;
01850 
01851               c = extract_unsigned_integer (bufptr, width, byte_order);
01852               addr += width;
01853               bufptr += width;
01854               if (c == 0)
01855                 {
01856                   /* We don't care about any error which happened after
01857                      the NUL terminator.  */
01858                   errcode = 0;
01859                   found_nul = 1;
01860                   break;
01861                 }
01862             }
01863         }
01864       while (errcode == 0       /* no error */
01865              && bufptr - *buffer < fetchlimit * width   /* no overrun */
01866              && !found_nul);    /* haven't found NUL yet */
01867     }
01868   else
01869     {                           /* Length of string is really 0!  */
01870       /* We always allocate *buffer.  */
01871       *buffer = bufptr = xmalloc (1);
01872       errcode = 0;
01873     }
01874 
01875   /* bufptr and addr now point immediately beyond the last byte which we
01876      consider part of the string (including a '\0' which ends the string).  */
01877   *bytes_read = bufptr - *buffer;
01878 
01879   QUIT;
01880 
01881   discard_cleanups (old_chain);
01882 
01883   return errcode;
01884 }
01885 
01886 /* Return true if print_wchar can display W without resorting to a
01887    numeric escape, false otherwise.  */
01888 
01889 static int
01890 wchar_printable (gdb_wchar_t w)
01891 {
01892   return (gdb_iswprint (w)
01893           || w == LCST ('\a') || w == LCST ('\b')
01894           || w == LCST ('\f') || w == LCST ('\n')
01895           || w == LCST ('\r') || w == LCST ('\t')
01896           || w == LCST ('\v'));
01897 }
01898 
01899 /* A helper function that converts the contents of STRING to wide
01900    characters and then appends them to OUTPUT.  */
01901 
01902 static void
01903 append_string_as_wide (const char *string,
01904                        struct obstack *output)
01905 {
01906   for (; *string; ++string)
01907     {
01908       gdb_wchar_t w = gdb_btowc (*string);
01909       obstack_grow (output, &w, sizeof (gdb_wchar_t));
01910     }
01911 }
01912 
01913 /* Print a wide character W to OUTPUT.  ORIG is a pointer to the
01914    original (target) bytes representing the character, ORIG_LEN is the
01915    number of valid bytes.  WIDTH is the number of bytes in a base
01916    characters of the type.  OUTPUT is an obstack to which wide
01917    characters are emitted.  QUOTER is a (narrow) character indicating
01918    the style of quotes surrounding the character to be printed.
01919    NEED_ESCAPE is an in/out flag which is used to track numeric
01920    escapes across calls.  */
01921 
01922 static void
01923 print_wchar (gdb_wint_t w, const gdb_byte *orig,
01924              int orig_len, int width,
01925              enum bfd_endian byte_order,
01926              struct obstack *output,
01927              int quoter, int *need_escapep)
01928 {
01929   int need_escape = *need_escapep;
01930 
01931   *need_escapep = 0;
01932   if (gdb_iswprint (w) && (!need_escape || (!gdb_iswdigit (w)
01933                                             && w != LCST ('8')
01934                                             && w != LCST ('9'))))
01935     {
01936       gdb_wchar_t wchar = w;
01937 
01938       if (w == gdb_btowc (quoter) || w == LCST ('\\'))
01939         obstack_grow_wstr (output, LCST ("\\"));
01940       obstack_grow (output, &wchar, sizeof (gdb_wchar_t));
01941     }
01942   else
01943     {
01944       switch (w)
01945         {
01946         case LCST ('\a'):
01947           obstack_grow_wstr (output, LCST ("\\a"));
01948           break;
01949         case LCST ('\b'):
01950           obstack_grow_wstr (output, LCST ("\\b"));
01951           break;
01952         case LCST ('\f'):
01953           obstack_grow_wstr (output, LCST ("\\f"));
01954           break;
01955         case LCST ('\n'):
01956           obstack_grow_wstr (output, LCST ("\\n"));
01957           break;
01958         case LCST ('\r'):
01959           obstack_grow_wstr (output, LCST ("\\r"));
01960           break;
01961         case LCST ('\t'):
01962           obstack_grow_wstr (output, LCST ("\\t"));
01963           break;
01964         case LCST ('\v'):
01965           obstack_grow_wstr (output, LCST ("\\v"));
01966           break;
01967         default:
01968           {
01969             int i;
01970 
01971             for (i = 0; i + width <= orig_len; i += width)
01972               {
01973                 char octal[30];
01974                 ULONGEST value;
01975 
01976                 value = extract_unsigned_integer (&orig[i], width,
01977                                                   byte_order);
01978                 /* If the value fits in 3 octal digits, print it that
01979                    way.  Otherwise, print it as a hex escape.  */
01980                 if (value <= 0777)
01981                   xsnprintf (octal, sizeof (octal), "\\%.3o",
01982                              (int) (value & 0777));
01983                 else
01984                   xsnprintf (octal, sizeof (octal), "\\x%lx", (long) value);
01985                 append_string_as_wide (octal, output);
01986               }
01987             /* If we somehow have extra bytes, print them now.  */
01988             while (i < orig_len)
01989               {
01990                 char octal[5];
01991 
01992                 xsnprintf (octal, sizeof (octal), "\\%.3o", orig[i] & 0xff);
01993                 append_string_as_wide (octal, output);
01994                 ++i;
01995               }
01996 
01997             *need_escapep = 1;
01998           }
01999           break;
02000         }
02001     }
02002 }
02003 
02004 /* Print the character C on STREAM as part of the contents of a
02005    literal string whose delimiter is QUOTER.  ENCODING names the
02006    encoding of C.  */
02007 
02008 void
02009 generic_emit_char (int c, struct type *type, struct ui_file *stream,
02010                    int quoter, const char *encoding)
02011 {
02012   enum bfd_endian byte_order
02013     = gdbarch_byte_order (get_type_arch (type));
02014   struct obstack wchar_buf, output;
02015   struct cleanup *cleanups;
02016   gdb_byte *buf;
02017   struct wchar_iterator *iter;
02018   int need_escape = 0;
02019 
02020   buf = alloca (TYPE_LENGTH (type));
02021   pack_long (buf, type, c);
02022 
02023   iter = make_wchar_iterator (buf, TYPE_LENGTH (type),
02024                               encoding, TYPE_LENGTH (type));
02025   cleanups = make_cleanup_wchar_iterator (iter);
02026 
02027   /* This holds the printable form of the wchar_t data.  */
02028   obstack_init (&wchar_buf);
02029   make_cleanup_obstack_free (&wchar_buf);
02030 
02031   while (1)
02032     {
02033       int num_chars;
02034       gdb_wchar_t *chars;
02035       const gdb_byte *buf;
02036       size_t buflen;
02037       int print_escape = 1;
02038       enum wchar_iterate_result result;
02039 
02040       num_chars = wchar_iterate (iter, &result, &chars, &buf, &buflen);
02041       if (num_chars < 0)
02042         break;
02043       if (num_chars > 0)
02044         {
02045           /* If all characters are printable, print them.  Otherwise,
02046              we're going to have to print an escape sequence.  We
02047              check all characters because we want to print the target
02048              bytes in the escape sequence, and we don't know character
02049              boundaries there.  */
02050           int i;
02051 
02052           print_escape = 0;
02053           for (i = 0; i < num_chars; ++i)
02054             if (!wchar_printable (chars[i]))
02055               {
02056                 print_escape = 1;
02057                 break;
02058               }
02059 
02060           if (!print_escape)
02061             {
02062               for (i = 0; i < num_chars; ++i)
02063                 print_wchar (chars[i], buf, buflen,
02064                              TYPE_LENGTH (type), byte_order,
02065                              &wchar_buf, quoter, &need_escape);
02066             }
02067         }
02068 
02069       /* This handles the NUM_CHARS == 0 case as well.  */
02070       if (print_escape)
02071         print_wchar (gdb_WEOF, buf, buflen, TYPE_LENGTH (type),
02072                      byte_order, &wchar_buf, quoter, &need_escape);
02073     }
02074 
02075   /* The output in the host encoding.  */
02076   obstack_init (&output);
02077   make_cleanup_obstack_free (&output);
02078 
02079   convert_between_encodings (INTERMEDIATE_ENCODING, host_charset (),
02080                              (gdb_byte *) obstack_base (&wchar_buf),
02081                              obstack_object_size (&wchar_buf),
02082                              sizeof (gdb_wchar_t), &output, translit_char);
02083   obstack_1grow (&output, '\0');
02084 
02085   fputs_filtered (obstack_base (&output), stream);
02086 
02087   do_cleanups (cleanups);
02088 }
02089 
02090 /* Return the repeat count of the next character/byte in ITER,
02091    storing the result in VEC.  */
02092 
02093 static int
02094 count_next_character (struct wchar_iterator *iter,
02095                       VEC (converted_character_d) **vec)
02096 {
02097   struct converted_character *current;
02098 
02099   if (VEC_empty (converted_character_d, *vec))
02100     {
02101       struct converted_character tmp;
02102       gdb_wchar_t *chars;
02103 
02104       tmp.num_chars
02105         = wchar_iterate (iter, &tmp.result, &chars, &tmp.buf, &tmp.buflen);
02106       if (tmp.num_chars > 0)
02107         {
02108           gdb_assert (tmp.num_chars < MAX_WCHARS);
02109           memcpy (tmp.chars, chars, tmp.num_chars * sizeof (gdb_wchar_t));
02110         }
02111       VEC_safe_push (converted_character_d, *vec, &tmp);
02112     }
02113 
02114   current = VEC_last (converted_character_d, *vec);
02115 
02116   /* Count repeated characters or bytes.  */
02117   current->repeat_count = 1;
02118   if (current->num_chars == -1)
02119     {
02120       /* EOF  */
02121       return -1;
02122     }
02123   else
02124     {
02125       gdb_wchar_t *chars;
02126       struct converted_character d;
02127       int repeat;
02128 
02129       d.repeat_count = 0;
02130 
02131       while (1)
02132         {
02133           /* Get the next character.  */
02134           d.num_chars
02135             = wchar_iterate (iter, &d.result, &chars, &d.buf, &d.buflen);
02136 
02137           /* If a character was successfully converted, save the character
02138              into the converted character.  */
02139           if (d.num_chars > 0)
02140             {
02141               gdb_assert (d.num_chars < MAX_WCHARS);
02142               memcpy (d.chars, chars, WCHAR_BUFLEN (d.num_chars));
02143             }
02144 
02145           /* Determine if the current character is the same as this
02146              new character.  */
02147           if (d.num_chars == current->num_chars && d.result == current->result)
02148             {
02149               /* There are two cases to consider:
02150 
02151                  1) Equality of converted character (num_chars > 0)
02152                  2) Equality of non-converted character (num_chars == 0)  */
02153               if ((current->num_chars > 0
02154                    && memcmp (current->chars, d.chars,
02155                               WCHAR_BUFLEN (current->num_chars)) == 0)
02156                   || (current->num_chars == 0
02157                       && current->buflen == d.buflen
02158                       && memcmp (current->buf, d.buf, current->buflen) == 0))
02159                 ++current->repeat_count;
02160               else
02161                 break;
02162             }
02163           else
02164             break;
02165         }
02166 
02167       /* Push this next converted character onto the result vector.  */
02168       repeat = current->repeat_count;
02169       VEC_safe_push (converted_character_d, *vec, &d);
02170       return repeat;
02171     }
02172 }
02173 
02174 /* Print the characters in CHARS to the OBSTACK.  QUOTE_CHAR is the quote
02175    character to use with string output.  WIDTH is the size of the output
02176    character type.  BYTE_ORDER is the the target byte order.  OPTIONS
02177    is the user's print options.  */
02178 
02179 static void
02180 print_converted_chars_to_obstack (struct obstack *obstack,
02181                                   VEC (converted_character_d) *chars,
02182                                   int quote_char, int width,
02183                                   enum bfd_endian byte_order,
02184                                   const struct value_print_options *options)
02185 {
02186   unsigned int idx;
02187   struct converted_character *elem;
02188   enum {START, SINGLE, REPEAT, INCOMPLETE, FINISH} state, last;
02189   gdb_wchar_t wide_quote_char = gdb_btowc (quote_char);
02190   int need_escape = 0;
02191 
02192   /* Set the start state.  */
02193   idx = 0;
02194   last = state = START;
02195   elem = NULL;
02196 
02197   while (1)
02198     {
02199       switch (state)
02200         {
02201         case START:
02202           /* Nothing to do.  */
02203           break;
02204 
02205         case SINGLE:
02206           {
02207             int j;
02208 
02209             /* We are outputting a single character
02210                (< options->repeat_count_threshold).  */
02211 
02212             if (last != SINGLE)
02213               {
02214                 /* We were outputting some other type of content, so we
02215                    must output and a comma and a quote.  */
02216                 if (last != START)
02217                   obstack_grow_wstr (obstack, LCST (", "));
02218                 obstack_grow (obstack, &wide_quote_char, sizeof (gdb_wchar_t));
02219               }
02220             /* Output the character.  */
02221             for (j = 0; j < elem->repeat_count; ++j)
02222               {
02223                 if (elem->result == wchar_iterate_ok)
02224                   print_wchar (elem->chars[0], elem->buf, elem->buflen, width,
02225                                byte_order, obstack, quote_char, &need_escape);
02226                 else
02227                   print_wchar (gdb_WEOF, elem->buf, elem->buflen, width,
02228                                byte_order, obstack, quote_char, &need_escape);
02229               }
02230           }
02231           break;
02232 
02233         case REPEAT:
02234           {
02235             int j;
02236             char *s;
02237 
02238             /* We are outputting a character with a repeat count
02239                greater than options->repeat_count_threshold.  */
02240 
02241             if (last == SINGLE)
02242               {
02243                 /* We were outputting a single string.  Terminate the
02244                    string.  */
02245                 obstack_grow (obstack, &wide_quote_char, sizeof (gdb_wchar_t));
02246               }
02247             if (last != START)
02248               obstack_grow_wstr (obstack, LCST (", "));
02249 
02250             /* Output the character and repeat string.  */
02251             obstack_grow_wstr (obstack, LCST ("'"));
02252             if (elem->result == wchar_iterate_ok)
02253               print_wchar (elem->chars[0], elem->buf, elem->buflen, width,
02254                            byte_order, obstack, quote_char, &need_escape);
02255             else
02256               print_wchar (gdb_WEOF, elem->buf, elem->buflen, width,
02257                            byte_order, obstack, quote_char, &need_escape);
02258             obstack_grow_wstr (obstack, LCST ("'"));
02259             s = xstrprintf (_(" <repeats %u times>"), elem->repeat_count);
02260             for (j = 0; s[j]; ++j)
02261               {
02262                 gdb_wchar_t w = gdb_btowc (s[j]);
02263                 obstack_grow (obstack, &w, sizeof (gdb_wchar_t));
02264               }
02265             xfree (s);
02266           }
02267           break;
02268 
02269         case INCOMPLETE:
02270           /* We are outputting an incomplete sequence.  */
02271           if (last == SINGLE)
02272             {
02273               /* If we were outputting a string of SINGLE characters,
02274                  terminate the quote.  */
02275               obstack_grow (obstack, &wide_quote_char, sizeof (gdb_wchar_t));
02276             }
02277           if (last != START)
02278             obstack_grow_wstr (obstack, LCST (", "));
02279 
02280           /* Output the incomplete sequence string.  */
02281           obstack_grow_wstr (obstack, LCST ("<incomplete sequence "));
02282           print_wchar (gdb_WEOF, elem->buf, elem->buflen, width, byte_order,
02283                        obstack, 0, &need_escape);
02284           obstack_grow_wstr (obstack, LCST (">"));
02285 
02286           /* We do not attempt to outupt anything after this.  */
02287           state = FINISH;
02288           break;
02289 
02290         case FINISH:
02291           /* All done.  If we were outputting a string of SINGLE
02292              characters, the string must be terminated.  Otherwise,
02293              REPEAT and INCOMPLETE are always left properly terminated.  */
02294           if (last == SINGLE)
02295             obstack_grow (obstack, &wide_quote_char, sizeof (gdb_wchar_t));
02296 
02297           return;
02298         }
02299 
02300       /* Get the next element and state.  */
02301       last = state;
02302       if (state != FINISH)
02303         {
02304           elem = VEC_index (converted_character_d, chars, idx++);
02305           switch (elem->result)
02306             {
02307             case wchar_iterate_ok:
02308             case wchar_iterate_invalid:
02309               if (elem->repeat_count > options->repeat_count_threshold)
02310                 state = REPEAT;
02311               else
02312                 state = SINGLE;
02313               break;
02314 
02315             case wchar_iterate_incomplete:
02316               state = INCOMPLETE;
02317               break;
02318 
02319             case wchar_iterate_eof:
02320               state = FINISH;
02321               break;
02322             }
02323         }
02324     }
02325 }
02326 
02327 /* Print the character string STRING, printing at most LENGTH
02328    characters.  LENGTH is -1 if the string is nul terminated.  TYPE is
02329    the type of each character.  OPTIONS holds the printing options;
02330    printing stops early if the number hits print_max; repeat counts
02331    are printed as appropriate.  Print ellipses at the end if we had to
02332    stop before printing LENGTH characters, or if FORCE_ELLIPSES.
02333    QUOTE_CHAR is the character to print at each end of the string.  If
02334    C_STYLE_TERMINATOR is true, and the last character is 0, then it is
02335    omitted.  */
02336 
02337 void
02338 generic_printstr (struct ui_file *stream, struct type *type, 
02339                   const gdb_byte *string, unsigned int length, 
02340                   const char *encoding, int force_ellipses,
02341                   int quote_char, int c_style_terminator,
02342                   const struct value_print_options *options)
02343 {
02344   enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
02345   unsigned int i;
02346   int width = TYPE_LENGTH (type);
02347   struct obstack wchar_buf, output;
02348   struct cleanup *cleanup;
02349   struct wchar_iterator *iter;
02350   int finished = 0;
02351   struct converted_character *last;
02352   VEC (converted_character_d) *converted_chars;
02353 
02354   if (length == -1)
02355     {
02356       unsigned long current_char = 1;
02357 
02358       for (i = 0; current_char; ++i)
02359         {
02360           QUIT;
02361           current_char = extract_unsigned_integer (string + i * width,
02362                                                    width, byte_order);
02363         }
02364       length = i;
02365     }
02366 
02367   /* If the string was not truncated due to `set print elements', and
02368      the last byte of it is a null, we don't print that, in
02369      traditional C style.  */
02370   if (c_style_terminator
02371       && !force_ellipses
02372       && length > 0
02373       && (extract_unsigned_integer (string + (length - 1) * width,
02374                                     width, byte_order) == 0))
02375     length--;
02376 
02377   if (length == 0)
02378     {
02379       fputs_filtered ("\"\"", stream);
02380       return;
02381     }
02382 
02383   /* Arrange to iterate over the characters, in wchar_t form.  */
02384   iter = make_wchar_iterator (string, length * width, encoding, width);
02385   cleanup = make_cleanup_wchar_iterator (iter);
02386   converted_chars = NULL;
02387   make_cleanup (VEC_cleanup (converted_character_d), &converted_chars);
02388 
02389   /* Convert characters until the string is over or the maximum
02390      number of printed characters has been reached.  */
02391   i = 0;
02392   while (i < options->print_max)
02393     {
02394       int r;
02395 
02396       QUIT;
02397 
02398       /* Grab the next character and repeat count.  */
02399       r = count_next_character (iter, &converted_chars);
02400 
02401       /* If less than zero, the end of the input string was reached.  */
02402       if (r < 0)
02403         break;
02404 
02405       /* Otherwise, add the count to the total print count and get
02406          the next character.  */
02407       i += r;
02408     }
02409 
02410   /* Get the last element and determine if the entire string was
02411      processed.  */
02412   last = VEC_last (converted_character_d, converted_chars);
02413   finished = (last->result == wchar_iterate_eof);
02414 
02415   /* Ensure that CONVERTED_CHARS is terminated.  */
02416   last->result = wchar_iterate_eof;
02417 
02418   /* WCHAR_BUF is the obstack we use to represent the string in
02419      wchar_t form.  */
02420   obstack_init (&wchar_buf);
02421   make_cleanup_obstack_free (&wchar_buf);
02422 
02423   /* Print the output string to the obstack.  */
02424   print_converted_chars_to_obstack (&wchar_buf, converted_chars, quote_char,
02425                                     width, byte_order, options);
02426 
02427   if (force_ellipses || !finished)
02428     obstack_grow_wstr (&wchar_buf, LCST ("..."));
02429 
02430   /* OUTPUT is where we collect `char's for printing.  */
02431   obstack_init (&output);
02432   make_cleanup_obstack_free (&output);
02433 
02434   convert_between_encodings (INTERMEDIATE_ENCODING, host_charset (),
02435                              (gdb_byte *) obstack_base (&wchar_buf),
02436                              obstack_object_size (&wchar_buf),
02437                              sizeof (gdb_wchar_t), &output, translit_char);
02438   obstack_1grow (&output, '\0');
02439 
02440   fputs_filtered (obstack_base (&output), stream);
02441 
02442   do_cleanups (cleanup);
02443 }
02444 
02445 /* Print a string from the inferior, starting at ADDR and printing up to LEN
02446    characters, of WIDTH bytes a piece, to STREAM.  If LEN is -1, printing
02447    stops at the first null byte, otherwise printing proceeds (including null
02448    bytes) until either print_max or LEN characters have been printed,
02449    whichever is smaller.  ENCODING is the name of the string's
02450    encoding.  It can be NULL, in which case the target encoding is
02451    assumed.  */
02452 
02453 int
02454 val_print_string (struct type *elttype, const char *encoding,
02455                   CORE_ADDR addr, int len,
02456                   struct ui_file *stream,
02457                   const struct value_print_options *options)
02458 {
02459   int force_ellipsis = 0;       /* Force ellipsis to be printed if nonzero.  */
02460   int errcode;                  /* Errno returned from bad reads.  */
02461   int found_nul;                /* Non-zero if we found the nul char.  */
02462   unsigned int fetchlimit;      /* Maximum number of chars to print.  */
02463   int bytes_read;
02464   gdb_byte *buffer = NULL;      /* Dynamically growable fetch buffer.  */
02465   struct cleanup *old_chain = NULL;     /* Top of the old cleanup chain.  */
02466   struct gdbarch *gdbarch = get_type_arch (elttype);
02467   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
02468   int width = TYPE_LENGTH (elttype);
02469 
02470   /* First we need to figure out the limit on the number of characters we are
02471      going to attempt to fetch and print.  This is actually pretty simple.  If
02472      LEN >= zero, then the limit is the minimum of LEN and print_max.  If
02473      LEN is -1, then the limit is print_max.  This is true regardless of
02474      whether print_max is zero, UINT_MAX (unlimited), or something in between,
02475      because finding the null byte (or available memory) is what actually
02476      limits the fetch.  */
02477 
02478   fetchlimit = (len == -1 ? options->print_max : min (len,
02479                                                       options->print_max));
02480 
02481   errcode = read_string (addr, len, width, fetchlimit, byte_order,
02482                          &buffer, &bytes_read);
02483   old_chain = make_cleanup (xfree, buffer);
02484 
02485   addr += bytes_read;
02486 
02487   /* We now have either successfully filled the buffer to fetchlimit,
02488      or terminated early due to an error or finding a null char when
02489      LEN is -1.  */
02490 
02491   /* Determine found_nul by looking at the last character read.  */
02492   found_nul = extract_unsigned_integer (buffer + bytes_read - width, width,
02493                                         byte_order) == 0;
02494   if (len == -1 && !found_nul)
02495     {
02496       gdb_byte *peekbuf;
02497 
02498       /* We didn't find a NUL terminator we were looking for.  Attempt
02499          to peek at the next character.  If not successful, or it is not
02500          a null byte, then force ellipsis to be printed.  */
02501 
02502       peekbuf = (gdb_byte *) alloca (width);
02503 
02504       if (target_read_memory (addr, peekbuf, width) == 0
02505           && extract_unsigned_integer (peekbuf, width, byte_order) != 0)
02506         force_ellipsis = 1;
02507     }
02508   else if ((len >= 0 && errcode != 0) || (len > bytes_read / width))
02509     {
02510       /* Getting an error when we have a requested length, or fetching less
02511          than the number of characters actually requested, always make us
02512          print ellipsis.  */
02513       force_ellipsis = 1;
02514     }
02515 
02516   /* If we get an error before fetching anything, don't print a string.
02517      But if we fetch something and then get an error, print the string
02518      and then the error message.  */
02519   if (errcode == 0 || bytes_read > 0)
02520     {
02521       LA_PRINT_STRING (stream, elttype, buffer, bytes_read / width,
02522                        encoding, force_ellipsis, options);
02523     }
02524 
02525   if (errcode != 0)
02526     {
02527       char *str;
02528 
02529       str = memory_error_message (errcode, gdbarch, addr);
02530       make_cleanup (xfree, str);
02531 
02532       fprintf_filtered (stream, "<error: ");
02533       fputs_filtered (str, stream);
02534       fprintf_filtered (stream, ">");
02535     }
02536 
02537   gdb_flush (stream);
02538   do_cleanups (old_chain);
02539 
02540   return (bytes_read / width);
02541 }
02542 
02543 
02544 /* The 'set input-radix' command writes to this auxiliary variable.
02545    If the requested radix is valid, INPUT_RADIX is updated; otherwise,
02546    it is left unchanged.  */
02547 
02548 static unsigned input_radix_1 = 10;
02549 
02550 /* Validate an input or output radix setting, and make sure the user
02551    knows what they really did here.  Radix setting is confusing, e.g.
02552    setting the input radix to "10" never changes it!  */
02553 
02554 static void
02555 set_input_radix (char *args, int from_tty, struct cmd_list_element *c)
02556 {
02557   set_input_radix_1 (from_tty, input_radix_1);
02558 }
02559 
02560 static void
02561 set_input_radix_1 (int from_tty, unsigned radix)
02562 {
02563   /* We don't currently disallow any input radix except 0 or 1, which don't
02564      make any mathematical sense.  In theory, we can deal with any input
02565      radix greater than 1, even if we don't have unique digits for every
02566      value from 0 to radix-1, but in practice we lose on large radix values.
02567      We should either fix the lossage or restrict the radix range more.
02568      (FIXME).  */
02569 
02570   if (radix < 2)
02571     {
02572       input_radix_1 = input_radix;
02573       error (_("Nonsense input radix ``decimal %u''; input radix unchanged."),
02574              radix);
02575     }
02576   input_radix_1 = input_radix = radix;
02577   if (from_tty)
02578     {
02579       printf_filtered (_("Input radix now set to "
02580                          "decimal %u, hex %x, octal %o.\n"),
02581                        radix, radix, radix);
02582     }
02583 }
02584 
02585 /* The 'set output-radix' command writes to this auxiliary variable.
02586    If the requested radix is valid, OUTPUT_RADIX is updated,
02587    otherwise, it is left unchanged.  */
02588 
02589 static unsigned output_radix_1 = 10;
02590 
02591 static void
02592 set_output_radix (char *args, int from_tty, struct cmd_list_element *c)
02593 {
02594   set_output_radix_1 (from_tty, output_radix_1);
02595 }
02596 
02597 static void
02598 set_output_radix_1 (int from_tty, unsigned radix)
02599 {
02600   /* Validate the radix and disallow ones that we aren't prepared to
02601      handle correctly, leaving the radix unchanged.  */
02602   switch (radix)
02603     {
02604     case 16:
02605       user_print_options.output_format = 'x';   /* hex */
02606       break;
02607     case 10:
02608       user_print_options.output_format = 0;     /* decimal */
02609       break;
02610     case 8:
02611       user_print_options.output_format = 'o';   /* octal */
02612       break;
02613     default:
02614       output_radix_1 = output_radix;
02615       error (_("Unsupported output radix ``decimal %u''; "
02616                "output radix unchanged."),
02617              radix);
02618     }
02619   output_radix_1 = output_radix = radix;
02620   if (from_tty)
02621     {
02622       printf_filtered (_("Output radix now set to "
02623                          "decimal %u, hex %x, octal %o.\n"),
02624                        radix, radix, radix);
02625     }
02626 }
02627 
02628 /* Set both the input and output radix at once.  Try to set the output radix
02629    first, since it has the most restrictive range.  An radix that is valid as
02630    an output radix is also valid as an input radix.
02631 
02632    It may be useful to have an unusual input radix.  If the user wishes to
02633    set an input radix that is not valid as an output radix, he needs to use
02634    the 'set input-radix' command.  */
02635 
02636 static void
02637 set_radix (char *arg, int from_tty)
02638 {
02639   unsigned radix;
02640 
02641   radix = (arg == NULL) ? 10 : parse_and_eval_long (arg);
02642   set_output_radix_1 (0, radix);
02643   set_input_radix_1 (0, radix);
02644   if (from_tty)
02645     {
02646       printf_filtered (_("Input and output radices now set to "
02647                          "decimal %u, hex %x, octal %o.\n"),
02648                        radix, radix, radix);
02649     }
02650 }
02651 
02652 /* Show both the input and output radices.  */
02653 
02654 static void
02655 show_radix (char *arg, int from_tty)
02656 {
02657   if (from_tty)
02658     {
02659       if (input_radix == output_radix)
02660         {
02661           printf_filtered (_("Input and output radices set to "
02662                              "decimal %u, hex %x, octal %o.\n"),
02663                            input_radix, input_radix, input_radix);
02664         }
02665       else
02666         {
02667           printf_filtered (_("Input radix set to decimal "
02668                              "%u, hex %x, octal %o.\n"),
02669                            input_radix, input_radix, input_radix);
02670           printf_filtered (_("Output radix set to decimal "
02671                              "%u, hex %x, octal %o.\n"),
02672                            output_radix, output_radix, output_radix);
02673         }
02674     }
02675 }
02676 
02677 
02678 static void
02679 set_print (char *arg, int from_tty)
02680 {
02681   printf_unfiltered (
02682      "\"set print\" must be followed by the name of a print subcommand.\n");
02683   help_list (setprintlist, "set print ", -1, gdb_stdout);
02684 }
02685 
02686 static void
02687 show_print (char *args, int from_tty)
02688 {
02689   cmd_show_list (showprintlist, from_tty, "");
02690 }
02691 
02692 static void
02693 set_print_raw (char *arg, int from_tty)
02694 {
02695   printf_unfiltered (
02696      "\"set print raw\" must be followed by the name of a \"print raw\" subcommand.\n");
02697   help_list (setprintrawlist, "set print raw ", -1, gdb_stdout);
02698 }
02699 
02700 static void
02701 show_print_raw (char *args, int from_tty)
02702 {
02703   cmd_show_list (showprintrawlist, from_tty, "");
02704 }
02705 
02706 
02707 void
02708 _initialize_valprint (void)
02709 {
02710   add_prefix_cmd ("print", no_class, set_print,
02711                   _("Generic command for setting how things print."),
02712                   &setprintlist, "set print ", 0, &setlist);
02713   add_alias_cmd ("p", "print", no_class, 1, &setlist);
02714   /* Prefer set print to set prompt.  */
02715   add_alias_cmd ("pr", "print", no_class, 1, &setlist);
02716 
02717   add_prefix_cmd ("print", no_class, show_print,
02718                   _("Generic command for showing print settings."),
02719                   &showprintlist, "show print ", 0, &showlist);
02720   add_alias_cmd ("p", "print", no_class, 1, &showlist);
02721   add_alias_cmd ("pr", "print", no_class, 1, &showlist);
02722 
02723   add_prefix_cmd ("raw", no_class, set_print_raw,
02724                   _("\
02725 Generic command for setting what things to print in \"raw\" mode."),
02726                   &setprintrawlist, "set print raw ", 0, &setprintlist);
02727   add_prefix_cmd ("raw", no_class, show_print_raw,
02728                   _("Generic command for showing \"print raw\" settings."),
02729                   &showprintrawlist, "show print raw ", 0, &showprintlist);
02730 
02731   add_setshow_uinteger_cmd ("elements", no_class,
02732                             &user_print_options.print_max, _("\
02733 Set limit on string chars or array elements to print."), _("\
02734 Show limit on string chars or array elements to print."), _("\
02735 \"set print elements unlimited\" causes there to be no limit."),
02736                             NULL,
02737                             show_print_max,
02738                             &setprintlist, &showprintlist);
02739 
02740   add_setshow_boolean_cmd ("null-stop", no_class,
02741                            &user_print_options.stop_print_at_null, _("\
02742 Set printing of char arrays to stop at first null char."), _("\
02743 Show printing of char arrays to stop at first null char."), NULL,
02744                            NULL,
02745                            show_stop_print_at_null,
02746                            &setprintlist, &showprintlist);
02747 
02748   add_setshow_uinteger_cmd ("repeats", no_class,
02749                             &user_print_options.repeat_count_threshold, _("\
02750 Set threshold for repeated print elements."), _("\
02751 Show threshold for repeated print elements."), _("\
02752 \"set print repeats unlimited\" causes all elements to be individually printed."),
02753                             NULL,
02754                             show_repeat_count_threshold,
02755                             &setprintlist, &showprintlist);
02756 
02757   add_setshow_boolean_cmd ("pretty", class_support,
02758                            &user_print_options.prettyformat_structs, _("\
02759 Set pretty formatting of structures."), _("\
02760 Show pretty formatting of structures."), NULL,
02761                            NULL,
02762                            show_prettyformat_structs,
02763                            &setprintlist, &showprintlist);
02764 
02765   add_setshow_boolean_cmd ("union", class_support,
02766                            &user_print_options.unionprint, _("\
02767 Set printing of unions interior to structures."), _("\
02768 Show printing of unions interior to structures."), NULL,
02769                            NULL,
02770                            show_unionprint,
02771                            &setprintlist, &showprintlist);
02772 
02773   add_setshow_boolean_cmd ("array", class_support,
02774                            &user_print_options.prettyformat_arrays, _("\
02775 Set pretty formatting of arrays."), _("\
02776 Show pretty formatting of arrays."), NULL,
02777                            NULL,
02778                            show_prettyformat_arrays,
02779                            &setprintlist, &showprintlist);
02780 
02781   add_setshow_boolean_cmd ("address", class_support,
02782                            &user_print_options.addressprint, _("\
02783 Set printing of addresses."), _("\
02784 Show printing of addresses."), NULL,
02785                            NULL,
02786                            show_addressprint,
02787                            &setprintlist, &showprintlist);
02788 
02789   add_setshow_boolean_cmd ("symbol", class_support,
02790                            &user_print_options.symbol_print, _("\
02791 Set printing of symbol names when printing pointers."), _("\
02792 Show printing of symbol names when printing pointers."),
02793                            NULL, NULL,
02794                            show_symbol_print,
02795                            &setprintlist, &showprintlist);
02796 
02797   add_setshow_zuinteger_cmd ("input-radix", class_support, &input_radix_1,
02798                              _("\
02799 Set default input radix for entering numbers."), _("\
02800 Show default input radix for entering numbers."), NULL,
02801                              set_input_radix,
02802                              show_input_radix,
02803                              &setlist, &showlist);
02804 
02805   add_setshow_zuinteger_cmd ("output-radix", class_support, &output_radix_1,
02806                              _("\
02807 Set default output radix for printing of values."), _("\
02808 Show default output radix for printing of values."), NULL,
02809                              set_output_radix,
02810                              show_output_radix,
02811                              &setlist, &showlist);
02812 
02813   /* The "set radix" and "show radix" commands are special in that
02814      they are like normal set and show commands but allow two normally
02815      independent variables to be either set or shown with a single
02816      command.  So the usual deprecated_add_set_cmd() and [deleted]
02817      add_show_from_set() commands aren't really appropriate.  */
02818   /* FIXME: i18n: With the new add_setshow_integer command, that is no
02819      longer true - show can display anything.  */
02820   add_cmd ("radix", class_support, set_radix, _("\
02821 Set default input and output number radices.\n\
02822 Use 'set input-radix' or 'set output-radix' to independently set each.\n\
02823 Without an argument, sets both radices back to the default value of 10."),
02824            &setlist);
02825   add_cmd ("radix", class_support, show_radix, _("\
02826 Show the default input and output number radices.\n\
02827 Use 'show input-radix' or 'show output-radix' to independently show each."),
02828            &showlist);
02829 
02830   add_setshow_boolean_cmd ("array-indexes", class_support,
02831                            &user_print_options.print_array_indexes, _("\
02832 Set printing of array indexes."), _("\
02833 Show printing of array indexes"), NULL, NULL, show_print_array_indexes,
02834                            &setprintlist, &showprintlist);
02835 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines