15796c8dcSSimon Schubert /* Print values for GDB, the GNU debugger. 25796c8dcSSimon Schubert 3*a45ae5f8SJohn Marino Copyright (C) 1986, 1988-2012 Free Software Foundation, Inc. 45796c8dcSSimon Schubert 55796c8dcSSimon Schubert This file is part of GDB. 65796c8dcSSimon Schubert 75796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify 85796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by 95796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or 105796c8dcSSimon Schubert (at your option) any later version. 115796c8dcSSimon Schubert 125796c8dcSSimon Schubert This program is distributed in the hope that it will be useful, 135796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of 145796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 155796c8dcSSimon Schubert GNU General Public License for more details. 165796c8dcSSimon Schubert 175796c8dcSSimon Schubert You should have received a copy of the GNU General Public License 185796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */ 195796c8dcSSimon Schubert 205796c8dcSSimon Schubert #include "defs.h" 215796c8dcSSimon Schubert #include "gdb_string.h" 225796c8dcSSimon Schubert #include "symtab.h" 235796c8dcSSimon Schubert #include "gdbtypes.h" 245796c8dcSSimon Schubert #include "value.h" 255796c8dcSSimon Schubert #include "gdbcore.h" 265796c8dcSSimon Schubert #include "gdbcmd.h" 275796c8dcSSimon Schubert #include "target.h" 285796c8dcSSimon Schubert #include "language.h" 295796c8dcSSimon Schubert #include "annotate.h" 305796c8dcSSimon Schubert #include "valprint.h" 315796c8dcSSimon Schubert #include "floatformat.h" 325796c8dcSSimon Schubert #include "doublest.h" 335796c8dcSSimon Schubert #include "exceptions.h" 345796c8dcSSimon Schubert #include "dfp.h" 355796c8dcSSimon Schubert #include "python/python.h" 36cf7f2e2dSJohn Marino #include "ada-lang.h" 37*a45ae5f8SJohn Marino #include "gdb_obstack.h" 38*a45ae5f8SJohn Marino #include "charset.h" 39*a45ae5f8SJohn Marino #include <ctype.h> 405796c8dcSSimon Schubert 415796c8dcSSimon Schubert #include <errno.h> 425796c8dcSSimon Schubert 435796c8dcSSimon Schubert /* Prototypes for local functions */ 445796c8dcSSimon Schubert 455796c8dcSSimon Schubert static int partial_memory_read (CORE_ADDR memaddr, gdb_byte *myaddr, 465796c8dcSSimon Schubert int len, int *errnoptr); 475796c8dcSSimon Schubert 485796c8dcSSimon Schubert static void show_print (char *, int); 495796c8dcSSimon Schubert 505796c8dcSSimon Schubert static void set_print (char *, int); 515796c8dcSSimon Schubert 525796c8dcSSimon Schubert static void set_radix (char *, int); 535796c8dcSSimon Schubert 545796c8dcSSimon Schubert static void show_radix (char *, int); 555796c8dcSSimon Schubert 565796c8dcSSimon Schubert static void set_input_radix (char *, int, struct cmd_list_element *); 575796c8dcSSimon Schubert 585796c8dcSSimon Schubert static void set_input_radix_1 (int, unsigned); 595796c8dcSSimon Schubert 605796c8dcSSimon Schubert static void set_output_radix (char *, int, struct cmd_list_element *); 615796c8dcSSimon Schubert 625796c8dcSSimon Schubert static void set_output_radix_1 (int, unsigned); 635796c8dcSSimon Schubert 645796c8dcSSimon Schubert void _initialize_valprint (void); 655796c8dcSSimon Schubert 665796c8dcSSimon Schubert #define PRINT_MAX_DEFAULT 200 /* Start print_max off at this value. */ 675796c8dcSSimon Schubert 685796c8dcSSimon Schubert struct value_print_options user_print_options = 695796c8dcSSimon Schubert { 705796c8dcSSimon Schubert Val_pretty_default, /* pretty */ 715796c8dcSSimon Schubert 0, /* prettyprint_arrays */ 725796c8dcSSimon Schubert 0, /* prettyprint_structs */ 735796c8dcSSimon Schubert 0, /* vtblprint */ 745796c8dcSSimon Schubert 1, /* unionprint */ 755796c8dcSSimon Schubert 1, /* addressprint */ 765796c8dcSSimon Schubert 0, /* objectprint */ 775796c8dcSSimon Schubert PRINT_MAX_DEFAULT, /* print_max */ 785796c8dcSSimon Schubert 10, /* repeat_count_threshold */ 795796c8dcSSimon Schubert 0, /* output_format */ 805796c8dcSSimon Schubert 0, /* format */ 815796c8dcSSimon Schubert 0, /* stop_print_at_null */ 825796c8dcSSimon Schubert 0, /* inspect_it */ 835796c8dcSSimon Schubert 0, /* print_array_indexes */ 845796c8dcSSimon Schubert 0, /* deref_ref */ 855796c8dcSSimon Schubert 1, /* static_field_print */ 865796c8dcSSimon Schubert 1, /* pascal_static_field_print */ 875796c8dcSSimon Schubert 0, /* raw */ 885796c8dcSSimon Schubert 0 /* summary */ 895796c8dcSSimon Schubert }; 905796c8dcSSimon Schubert 915796c8dcSSimon Schubert /* Initialize *OPTS to be a copy of the user print options. */ 925796c8dcSSimon Schubert void 935796c8dcSSimon Schubert get_user_print_options (struct value_print_options *opts) 945796c8dcSSimon Schubert { 955796c8dcSSimon Schubert *opts = user_print_options; 965796c8dcSSimon Schubert } 975796c8dcSSimon Schubert 985796c8dcSSimon Schubert /* Initialize *OPTS to be a copy of the user print options, but with 995796c8dcSSimon Schubert pretty-printing disabled. */ 1005796c8dcSSimon Schubert void 1015796c8dcSSimon Schubert get_raw_print_options (struct value_print_options *opts) 1025796c8dcSSimon Schubert { 1035796c8dcSSimon Schubert *opts = user_print_options; 1045796c8dcSSimon Schubert opts->pretty = Val_no_prettyprint; 1055796c8dcSSimon Schubert } 1065796c8dcSSimon Schubert 1075796c8dcSSimon Schubert /* Initialize *OPTS to be a copy of the user print options, but using 1085796c8dcSSimon Schubert FORMAT as the formatting option. */ 1095796c8dcSSimon Schubert void 1105796c8dcSSimon Schubert get_formatted_print_options (struct value_print_options *opts, 1115796c8dcSSimon Schubert char format) 1125796c8dcSSimon Schubert { 1135796c8dcSSimon Schubert *opts = user_print_options; 1145796c8dcSSimon Schubert opts->format = format; 1155796c8dcSSimon Schubert } 1165796c8dcSSimon Schubert 1175796c8dcSSimon Schubert static void 1185796c8dcSSimon Schubert show_print_max (struct ui_file *file, int from_tty, 1195796c8dcSSimon Schubert struct cmd_list_element *c, const char *value) 1205796c8dcSSimon Schubert { 121c50c785cSJohn Marino fprintf_filtered (file, 122c50c785cSJohn Marino _("Limit on string chars or array " 123c50c785cSJohn Marino "elements to print is %s.\n"), 1245796c8dcSSimon Schubert value); 1255796c8dcSSimon Schubert } 1265796c8dcSSimon Schubert 1275796c8dcSSimon Schubert 1285796c8dcSSimon Schubert /* Default input and output radixes, and output format letter. */ 1295796c8dcSSimon Schubert 1305796c8dcSSimon Schubert unsigned input_radix = 10; 1315796c8dcSSimon Schubert static void 1325796c8dcSSimon Schubert show_input_radix (struct ui_file *file, int from_tty, 1335796c8dcSSimon Schubert struct cmd_list_element *c, const char *value) 1345796c8dcSSimon Schubert { 135c50c785cSJohn Marino fprintf_filtered (file, 136c50c785cSJohn Marino _("Default input radix for entering numbers is %s.\n"), 1375796c8dcSSimon Schubert value); 1385796c8dcSSimon Schubert } 1395796c8dcSSimon Schubert 1405796c8dcSSimon Schubert unsigned output_radix = 10; 1415796c8dcSSimon Schubert static void 1425796c8dcSSimon Schubert show_output_radix (struct ui_file *file, int from_tty, 1435796c8dcSSimon Schubert struct cmd_list_element *c, const char *value) 1445796c8dcSSimon Schubert { 145c50c785cSJohn Marino fprintf_filtered (file, 146c50c785cSJohn Marino _("Default output radix for printing of values is %s.\n"), 1475796c8dcSSimon Schubert value); 1485796c8dcSSimon Schubert } 1495796c8dcSSimon Schubert 1505796c8dcSSimon Schubert /* By default we print arrays without printing the index of each element in 1515796c8dcSSimon Schubert the array. This behavior can be changed by setting PRINT_ARRAY_INDEXES. */ 1525796c8dcSSimon Schubert 1535796c8dcSSimon Schubert static void 1545796c8dcSSimon Schubert show_print_array_indexes (struct ui_file *file, int from_tty, 1555796c8dcSSimon Schubert struct cmd_list_element *c, const char *value) 1565796c8dcSSimon Schubert { 1575796c8dcSSimon Schubert fprintf_filtered (file, _("Printing of array indexes is %s.\n"), value); 1585796c8dcSSimon Schubert } 1595796c8dcSSimon Schubert 1605796c8dcSSimon Schubert /* Print repeat counts if there are more than this many repetitions of an 1615796c8dcSSimon Schubert element in an array. Referenced by the low level language dependent 1625796c8dcSSimon Schubert print routines. */ 1635796c8dcSSimon Schubert 1645796c8dcSSimon Schubert static void 1655796c8dcSSimon Schubert show_repeat_count_threshold (struct ui_file *file, int from_tty, 1665796c8dcSSimon Schubert struct cmd_list_element *c, const char *value) 1675796c8dcSSimon Schubert { 1685796c8dcSSimon Schubert fprintf_filtered (file, _("Threshold for repeated print elements is %s.\n"), 1695796c8dcSSimon Schubert value); 1705796c8dcSSimon Schubert } 1715796c8dcSSimon Schubert 1725796c8dcSSimon Schubert /* If nonzero, stops printing of char arrays at first null. */ 1735796c8dcSSimon Schubert 1745796c8dcSSimon Schubert static void 1755796c8dcSSimon Schubert show_stop_print_at_null (struct ui_file *file, int from_tty, 1765796c8dcSSimon Schubert struct cmd_list_element *c, const char *value) 1775796c8dcSSimon Schubert { 178c50c785cSJohn Marino fprintf_filtered (file, 179c50c785cSJohn Marino _("Printing of char arrays to stop " 180c50c785cSJohn Marino "at first null char is %s.\n"), 1815796c8dcSSimon Schubert value); 1825796c8dcSSimon Schubert } 1835796c8dcSSimon Schubert 1845796c8dcSSimon Schubert /* Controls pretty printing of structures. */ 1855796c8dcSSimon Schubert 1865796c8dcSSimon Schubert static void 1875796c8dcSSimon Schubert show_prettyprint_structs (struct ui_file *file, int from_tty, 1885796c8dcSSimon Schubert struct cmd_list_element *c, const char *value) 1895796c8dcSSimon Schubert { 1905796c8dcSSimon Schubert fprintf_filtered (file, _("Prettyprinting of structures is %s.\n"), value); 1915796c8dcSSimon Schubert } 1925796c8dcSSimon Schubert 1935796c8dcSSimon Schubert /* Controls pretty printing of arrays. */ 1945796c8dcSSimon Schubert 1955796c8dcSSimon Schubert static void 1965796c8dcSSimon Schubert show_prettyprint_arrays (struct ui_file *file, int from_tty, 1975796c8dcSSimon Schubert struct cmd_list_element *c, const char *value) 1985796c8dcSSimon Schubert { 1995796c8dcSSimon Schubert fprintf_filtered (file, _("Prettyprinting of arrays is %s.\n"), value); 2005796c8dcSSimon Schubert } 2015796c8dcSSimon Schubert 2025796c8dcSSimon Schubert /* If nonzero, causes unions inside structures or other unions to be 2035796c8dcSSimon Schubert printed. */ 2045796c8dcSSimon Schubert 2055796c8dcSSimon Schubert static void 2065796c8dcSSimon Schubert show_unionprint (struct ui_file *file, int from_tty, 2075796c8dcSSimon Schubert struct cmd_list_element *c, const char *value) 2085796c8dcSSimon Schubert { 209c50c785cSJohn Marino fprintf_filtered (file, 210c50c785cSJohn Marino _("Printing of unions interior to structures is %s.\n"), 2115796c8dcSSimon Schubert value); 2125796c8dcSSimon Schubert } 2135796c8dcSSimon Schubert 2145796c8dcSSimon Schubert /* If nonzero, causes machine addresses to be printed in certain contexts. */ 2155796c8dcSSimon Schubert 2165796c8dcSSimon Schubert static void 2175796c8dcSSimon Schubert show_addressprint (struct ui_file *file, int from_tty, 2185796c8dcSSimon Schubert struct cmd_list_element *c, const char *value) 2195796c8dcSSimon Schubert { 2205796c8dcSSimon Schubert fprintf_filtered (file, _("Printing of addresses is %s.\n"), value); 2215796c8dcSSimon Schubert } 2225796c8dcSSimon Schubert 2235796c8dcSSimon Schubert 2245796c8dcSSimon Schubert /* A helper function for val_print. When printing in "summary" mode, 2255796c8dcSSimon Schubert we want to print scalar arguments, but not aggregate arguments. 2265796c8dcSSimon Schubert This function distinguishes between the two. */ 2275796c8dcSSimon Schubert 2285796c8dcSSimon Schubert static int 2295796c8dcSSimon Schubert scalar_type_p (struct type *type) 2305796c8dcSSimon Schubert { 2315796c8dcSSimon Schubert CHECK_TYPEDEF (type); 2325796c8dcSSimon Schubert while (TYPE_CODE (type) == TYPE_CODE_REF) 2335796c8dcSSimon Schubert { 2345796c8dcSSimon Schubert type = TYPE_TARGET_TYPE (type); 2355796c8dcSSimon Schubert CHECK_TYPEDEF (type); 2365796c8dcSSimon Schubert } 2375796c8dcSSimon Schubert switch (TYPE_CODE (type)) 2385796c8dcSSimon Schubert { 2395796c8dcSSimon Schubert case TYPE_CODE_ARRAY: 2405796c8dcSSimon Schubert case TYPE_CODE_STRUCT: 2415796c8dcSSimon Schubert case TYPE_CODE_UNION: 2425796c8dcSSimon Schubert case TYPE_CODE_SET: 2435796c8dcSSimon Schubert case TYPE_CODE_STRING: 2445796c8dcSSimon Schubert case TYPE_CODE_BITSTRING: 2455796c8dcSSimon Schubert return 0; 2465796c8dcSSimon Schubert default: 2475796c8dcSSimon Schubert return 1; 2485796c8dcSSimon Schubert } 2495796c8dcSSimon Schubert } 2505796c8dcSSimon Schubert 251cf7f2e2dSJohn Marino /* Helper function to check the validity of some bits of a value. 252cf7f2e2dSJohn Marino 253cf7f2e2dSJohn Marino If TYPE represents some aggregate type (e.g., a structure), return 1. 254cf7f2e2dSJohn Marino 255cf7f2e2dSJohn Marino Otherwise, any of the bytes starting at OFFSET and extending for 256cf7f2e2dSJohn Marino TYPE_LENGTH(TYPE) bytes are invalid, print a message to STREAM and 257cf7f2e2dSJohn Marino return 0. The checking is done using FUNCS. 258cf7f2e2dSJohn Marino 259cf7f2e2dSJohn Marino Otherwise, return 1. */ 260cf7f2e2dSJohn Marino 261cf7f2e2dSJohn Marino static int 262cf7f2e2dSJohn Marino valprint_check_validity (struct ui_file *stream, 263cf7f2e2dSJohn Marino struct type *type, 264c50c785cSJohn Marino int embedded_offset, 265cf7f2e2dSJohn Marino const struct value *val) 266cf7f2e2dSJohn Marino { 267cf7f2e2dSJohn Marino CHECK_TYPEDEF (type); 268cf7f2e2dSJohn Marino 269cf7f2e2dSJohn Marino if (TYPE_CODE (type) != TYPE_CODE_UNION 270cf7f2e2dSJohn Marino && TYPE_CODE (type) != TYPE_CODE_STRUCT 271cf7f2e2dSJohn Marino && TYPE_CODE (type) != TYPE_CODE_ARRAY) 272cf7f2e2dSJohn Marino { 273c50c785cSJohn Marino if (!value_bits_valid (val, TARGET_CHAR_BIT * embedded_offset, 274cf7f2e2dSJohn Marino TARGET_CHAR_BIT * TYPE_LENGTH (type))) 275cf7f2e2dSJohn Marino { 276c50c785cSJohn Marino val_print_optimized_out (stream); 277c50c785cSJohn Marino return 0; 278c50c785cSJohn Marino } 279c50c785cSJohn Marino 280c50c785cSJohn Marino if (value_bits_synthetic_pointer (val, TARGET_CHAR_BIT * embedded_offset, 281c50c785cSJohn Marino TARGET_CHAR_BIT * TYPE_LENGTH (type))) 282c50c785cSJohn Marino { 283c50c785cSJohn Marino fputs_filtered (_("<synthetic pointer>"), stream); 284c50c785cSJohn Marino return 0; 285c50c785cSJohn Marino } 286c50c785cSJohn Marino 287c50c785cSJohn Marino if (!value_bytes_available (val, embedded_offset, TYPE_LENGTH (type))) 288c50c785cSJohn Marino { 289c50c785cSJohn Marino val_print_unavailable (stream); 290cf7f2e2dSJohn Marino return 0; 291cf7f2e2dSJohn Marino } 292cf7f2e2dSJohn Marino } 293cf7f2e2dSJohn Marino 294cf7f2e2dSJohn Marino return 1; 295cf7f2e2dSJohn Marino } 296cf7f2e2dSJohn Marino 297c50c785cSJohn Marino void 298c50c785cSJohn Marino val_print_optimized_out (struct ui_file *stream) 299c50c785cSJohn Marino { 300c50c785cSJohn Marino fprintf_filtered (stream, _("<optimized out>")); 301c50c785cSJohn Marino } 3025796c8dcSSimon Schubert 303c50c785cSJohn Marino void 304c50c785cSJohn Marino val_print_unavailable (struct ui_file *stream) 305c50c785cSJohn Marino { 306c50c785cSJohn Marino fprintf_filtered (stream, _("<unavailable>")); 307c50c785cSJohn Marino } 3085796c8dcSSimon Schubert 309c50c785cSJohn Marino void 310c50c785cSJohn Marino val_print_invalid_address (struct ui_file *stream) 311c50c785cSJohn Marino { 312c50c785cSJohn Marino fprintf_filtered (stream, _("<invalid address>")); 313c50c785cSJohn Marino } 3145796c8dcSSimon Schubert 315c50c785cSJohn Marino /* Print using the given LANGUAGE the data of type TYPE located at 316c50c785cSJohn Marino VALADDR + EMBEDDED_OFFSET (within GDB), which came from the 317c50c785cSJohn Marino inferior at address ADDRESS + EMBEDDED_OFFSET, onto stdio stream 318c50c785cSJohn Marino STREAM according to OPTIONS. VAL is the whole object that came 319c50c785cSJohn Marino from ADDRESS. VALADDR must point to the head of VAL's contents 320c50c785cSJohn Marino buffer. 321c50c785cSJohn Marino 322c50c785cSJohn Marino The language printers will pass down an adjusted EMBEDDED_OFFSET to 323c50c785cSJohn Marino further helper subroutines as subfields of TYPE are printed. In 324c50c785cSJohn Marino such cases, VALADDR is passed down unadjusted, as well as VAL, so 325c50c785cSJohn Marino that VAL can be queried for metadata about the contents data being 326c50c785cSJohn Marino printed, using EMBEDDED_OFFSET as an offset into VAL's contents 327c50c785cSJohn Marino buffer. For example: "has this field been optimized out", or "I'm 328c50c785cSJohn Marino printing an object while inspecting a traceframe; has this 329c50c785cSJohn Marino particular piece of data been collected?". 330c50c785cSJohn Marino 331c50c785cSJohn Marino RECURSE indicates the amount of indentation to supply before 332c50c785cSJohn Marino continuation lines; this amount is roughly twice the value of 333c50c785cSJohn Marino RECURSE. 334c50c785cSJohn Marino 335c50c785cSJohn Marino If the data is printed as a string, returns the number of string 336c50c785cSJohn Marino characters printed. */ 3375796c8dcSSimon Schubert 3385796c8dcSSimon Schubert int 3395796c8dcSSimon Schubert val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, 3405796c8dcSSimon Schubert CORE_ADDR address, struct ui_file *stream, int recurse, 341cf7f2e2dSJohn Marino const struct value *val, 3425796c8dcSSimon Schubert const struct value_print_options *options, 3435796c8dcSSimon Schubert const struct language_defn *language) 3445796c8dcSSimon Schubert { 3455796c8dcSSimon Schubert volatile struct gdb_exception except; 3465796c8dcSSimon Schubert int ret = 0; 3475796c8dcSSimon Schubert struct value_print_options local_opts = *options; 3485796c8dcSSimon Schubert struct type *real_type = check_typedef (type); 3495796c8dcSSimon Schubert 3505796c8dcSSimon Schubert if (local_opts.pretty == Val_pretty_default) 3515796c8dcSSimon Schubert local_opts.pretty = (local_opts.prettyprint_structs 3525796c8dcSSimon Schubert ? Val_prettyprint : Val_no_prettyprint); 3535796c8dcSSimon Schubert 3545796c8dcSSimon Schubert QUIT; 3555796c8dcSSimon Schubert 3565796c8dcSSimon Schubert /* Ensure that the type is complete and not just a stub. If the type is 3575796c8dcSSimon Schubert only a stub and we can't find and substitute its complete type, then 3585796c8dcSSimon Schubert print appropriate string and return. */ 3595796c8dcSSimon Schubert 3605796c8dcSSimon Schubert if (TYPE_STUB (real_type)) 3615796c8dcSSimon Schubert { 362cf7f2e2dSJohn Marino fprintf_filtered (stream, _("<incomplete type>")); 3635796c8dcSSimon Schubert gdb_flush (stream); 3645796c8dcSSimon Schubert return (0); 3655796c8dcSSimon Schubert } 3665796c8dcSSimon Schubert 367cf7f2e2dSJohn Marino if (!valprint_check_validity (stream, real_type, embedded_offset, val)) 368cf7f2e2dSJohn Marino return 0; 369cf7f2e2dSJohn Marino 3705796c8dcSSimon Schubert if (!options->raw) 3715796c8dcSSimon Schubert { 3725796c8dcSSimon Schubert ret = apply_val_pretty_printer (type, valaddr, embedded_offset, 373cf7f2e2dSJohn Marino address, stream, recurse, 374cf7f2e2dSJohn Marino val, options, language); 3755796c8dcSSimon Schubert if (ret) 3765796c8dcSSimon Schubert return ret; 3775796c8dcSSimon Schubert } 3785796c8dcSSimon Schubert 3795796c8dcSSimon Schubert /* Handle summary mode. If the value is a scalar, print it; 3805796c8dcSSimon Schubert otherwise, print an ellipsis. */ 3815796c8dcSSimon Schubert if (options->summary && !scalar_type_p (type)) 3825796c8dcSSimon Schubert { 3835796c8dcSSimon Schubert fprintf_filtered (stream, "..."); 3845796c8dcSSimon Schubert return 0; 3855796c8dcSSimon Schubert } 3865796c8dcSSimon Schubert 3875796c8dcSSimon Schubert TRY_CATCH (except, RETURN_MASK_ERROR) 3885796c8dcSSimon Schubert { 3895796c8dcSSimon Schubert ret = language->la_val_print (type, valaddr, embedded_offset, address, 390cf7f2e2dSJohn Marino stream, recurse, val, 391cf7f2e2dSJohn Marino &local_opts); 3925796c8dcSSimon Schubert } 3935796c8dcSSimon Schubert if (except.reason < 0) 3945796c8dcSSimon Schubert fprintf_filtered (stream, _("<error reading variable>")); 3955796c8dcSSimon Schubert 3965796c8dcSSimon Schubert return ret; 3975796c8dcSSimon Schubert } 3985796c8dcSSimon Schubert 3995796c8dcSSimon Schubert /* Check whether the value VAL is printable. Return 1 if it is; 400*a45ae5f8SJohn Marino return 0 and print an appropriate error message to STREAM according to 401*a45ae5f8SJohn Marino OPTIONS if it is not. */ 4025796c8dcSSimon Schubert 4035796c8dcSSimon Schubert static int 404*a45ae5f8SJohn Marino value_check_printable (struct value *val, struct ui_file *stream, 405*a45ae5f8SJohn Marino const struct value_print_options *options) 4065796c8dcSSimon Schubert { 4075796c8dcSSimon Schubert if (val == 0) 4085796c8dcSSimon Schubert { 4095796c8dcSSimon Schubert fprintf_filtered (stream, _("<address of value unknown>")); 4105796c8dcSSimon Schubert return 0; 4115796c8dcSSimon Schubert } 4125796c8dcSSimon Schubert 413cf7f2e2dSJohn Marino if (value_entirely_optimized_out (val)) 4145796c8dcSSimon Schubert { 415*a45ae5f8SJohn Marino if (options->summary && !scalar_type_p (value_type (val))) 416*a45ae5f8SJohn Marino fprintf_filtered (stream, "..."); 417*a45ae5f8SJohn Marino else 418c50c785cSJohn Marino val_print_optimized_out (stream); 4195796c8dcSSimon Schubert return 0; 4205796c8dcSSimon Schubert } 4215796c8dcSSimon Schubert 4225796c8dcSSimon Schubert if (TYPE_CODE (value_type (val)) == TYPE_CODE_INTERNAL_FUNCTION) 4235796c8dcSSimon Schubert { 4245796c8dcSSimon Schubert fprintf_filtered (stream, _("<internal function %s>"), 4255796c8dcSSimon Schubert value_internal_function_name (val)); 4265796c8dcSSimon Schubert return 0; 4275796c8dcSSimon Schubert } 4285796c8dcSSimon Schubert 4295796c8dcSSimon Schubert return 1; 4305796c8dcSSimon Schubert } 4315796c8dcSSimon Schubert 4325796c8dcSSimon Schubert /* Print using the given LANGUAGE the value VAL onto stream STREAM according 4335796c8dcSSimon Schubert to OPTIONS. 4345796c8dcSSimon Schubert 4355796c8dcSSimon Schubert If the data are a string pointer, returns the number of string characters 4365796c8dcSSimon Schubert printed. 4375796c8dcSSimon Schubert 4385796c8dcSSimon Schubert This is a preferable interface to val_print, above, because it uses 4395796c8dcSSimon Schubert GDB's value mechanism. */ 4405796c8dcSSimon Schubert 4415796c8dcSSimon Schubert int 4425796c8dcSSimon Schubert common_val_print (struct value *val, struct ui_file *stream, int recurse, 4435796c8dcSSimon Schubert const struct value_print_options *options, 4445796c8dcSSimon Schubert const struct language_defn *language) 4455796c8dcSSimon Schubert { 446*a45ae5f8SJohn Marino if (!value_check_printable (val, stream, options)) 4475796c8dcSSimon Schubert return 0; 4485796c8dcSSimon Schubert 449cf7f2e2dSJohn Marino if (language->la_language == language_ada) 450cf7f2e2dSJohn Marino /* The value might have a dynamic type, which would cause trouble 451cf7f2e2dSJohn Marino below when trying to extract the value contents (since the value 452cf7f2e2dSJohn Marino size is determined from the type size which is unknown). So 453cf7f2e2dSJohn Marino get a fixed representation of our value. */ 454cf7f2e2dSJohn Marino val = ada_to_fixed_value (val); 455cf7f2e2dSJohn Marino 456cf7f2e2dSJohn Marino return val_print (value_type (val), value_contents_for_printing (val), 4575796c8dcSSimon Schubert value_embedded_offset (val), value_address (val), 458cf7f2e2dSJohn Marino stream, recurse, 459cf7f2e2dSJohn Marino val, options, language); 4605796c8dcSSimon Schubert } 4615796c8dcSSimon Schubert 462cf7f2e2dSJohn Marino /* Print on stream STREAM the value VAL according to OPTIONS. The value 463cf7f2e2dSJohn Marino is printed using the current_language syntax. 464cf7f2e2dSJohn Marino 465cf7f2e2dSJohn Marino If the object printed is a string pointer, return the number of string 466cf7f2e2dSJohn Marino bytes printed. */ 4675796c8dcSSimon Schubert 4685796c8dcSSimon Schubert int 4695796c8dcSSimon Schubert value_print (struct value *val, struct ui_file *stream, 4705796c8dcSSimon Schubert const struct value_print_options *options) 4715796c8dcSSimon Schubert { 472*a45ae5f8SJohn Marino if (!value_check_printable (val, stream, options)) 4735796c8dcSSimon Schubert return 0; 4745796c8dcSSimon Schubert 4755796c8dcSSimon Schubert if (!options->raw) 4765796c8dcSSimon Schubert { 4775796c8dcSSimon Schubert int r = apply_val_pretty_printer (value_type (val), 478cf7f2e2dSJohn Marino value_contents_for_printing (val), 4795796c8dcSSimon Schubert value_embedded_offset (val), 4805796c8dcSSimon Schubert value_address (val), 481cf7f2e2dSJohn Marino stream, 0, 482cf7f2e2dSJohn Marino val, options, current_language); 483cf7f2e2dSJohn Marino 4845796c8dcSSimon Schubert if (r) 4855796c8dcSSimon Schubert return r; 4865796c8dcSSimon Schubert } 4875796c8dcSSimon Schubert 4885796c8dcSSimon Schubert return LA_VALUE_PRINT (val, stream, options); 4895796c8dcSSimon Schubert } 4905796c8dcSSimon Schubert 4915796c8dcSSimon Schubert /* Called by various <lang>_val_print routines to print 4925796c8dcSSimon Schubert TYPE_CODE_INT's. TYPE is the type. VALADDR is the address of the 4935796c8dcSSimon Schubert value. STREAM is where to print the value. */ 4945796c8dcSSimon Schubert 4955796c8dcSSimon Schubert void 4965796c8dcSSimon Schubert val_print_type_code_int (struct type *type, const gdb_byte *valaddr, 4975796c8dcSSimon Schubert struct ui_file *stream) 4985796c8dcSSimon Schubert { 4995796c8dcSSimon Schubert enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type)); 5005796c8dcSSimon Schubert 5015796c8dcSSimon Schubert if (TYPE_LENGTH (type) > sizeof (LONGEST)) 5025796c8dcSSimon Schubert { 5035796c8dcSSimon Schubert LONGEST val; 5045796c8dcSSimon Schubert 5055796c8dcSSimon Schubert if (TYPE_UNSIGNED (type) 5065796c8dcSSimon Schubert && extract_long_unsigned_integer (valaddr, TYPE_LENGTH (type), 5075796c8dcSSimon Schubert byte_order, &val)) 5085796c8dcSSimon Schubert { 5095796c8dcSSimon Schubert print_longest (stream, 'u', 0, val); 5105796c8dcSSimon Schubert } 5115796c8dcSSimon Schubert else 5125796c8dcSSimon Schubert { 5135796c8dcSSimon Schubert /* Signed, or we couldn't turn an unsigned value into a 5145796c8dcSSimon Schubert LONGEST. For signed values, one could assume two's 5155796c8dcSSimon Schubert complement (a reasonable assumption, I think) and do 5165796c8dcSSimon Schubert better than this. */ 5175796c8dcSSimon Schubert print_hex_chars (stream, (unsigned char *) valaddr, 5185796c8dcSSimon Schubert TYPE_LENGTH (type), byte_order); 5195796c8dcSSimon Schubert } 5205796c8dcSSimon Schubert } 5215796c8dcSSimon Schubert else 5225796c8dcSSimon Schubert { 5235796c8dcSSimon Schubert print_longest (stream, TYPE_UNSIGNED (type) ? 'u' : 'd', 0, 5245796c8dcSSimon Schubert unpack_long (type, valaddr)); 5255796c8dcSSimon Schubert } 5265796c8dcSSimon Schubert } 5275796c8dcSSimon Schubert 5285796c8dcSSimon Schubert void 5295796c8dcSSimon Schubert val_print_type_code_flags (struct type *type, const gdb_byte *valaddr, 5305796c8dcSSimon Schubert struct ui_file *stream) 5315796c8dcSSimon Schubert { 5325796c8dcSSimon Schubert ULONGEST val = unpack_long (type, valaddr); 5335796c8dcSSimon Schubert int bitpos, nfields = TYPE_NFIELDS (type); 5345796c8dcSSimon Schubert 5355796c8dcSSimon Schubert fputs_filtered ("[ ", stream); 5365796c8dcSSimon Schubert for (bitpos = 0; bitpos < nfields; bitpos++) 5375796c8dcSSimon Schubert { 5385796c8dcSSimon Schubert if (TYPE_FIELD_BITPOS (type, bitpos) != -1 5395796c8dcSSimon Schubert && (val & ((ULONGEST)1 << bitpos))) 5405796c8dcSSimon Schubert { 5415796c8dcSSimon Schubert if (TYPE_FIELD_NAME (type, bitpos)) 5425796c8dcSSimon Schubert fprintf_filtered (stream, "%s ", TYPE_FIELD_NAME (type, bitpos)); 5435796c8dcSSimon Schubert else 5445796c8dcSSimon Schubert fprintf_filtered (stream, "#%d ", bitpos); 5455796c8dcSSimon Schubert } 5465796c8dcSSimon Schubert } 5475796c8dcSSimon Schubert fputs_filtered ("]", stream); 548c50c785cSJohn Marino 549c50c785cSJohn Marino /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR, 550c50c785cSJohn Marino according to OPTIONS and SIZE on STREAM. Format i is not supported 551c50c785cSJohn Marino at this level. 552c50c785cSJohn Marino 553c50c785cSJohn Marino This is how the elements of an array or structure are printed 554c50c785cSJohn Marino with a format. */ 555c50c785cSJohn Marino } 556c50c785cSJohn Marino 557c50c785cSJohn Marino void 558c50c785cSJohn Marino val_print_scalar_formatted (struct type *type, 559c50c785cSJohn Marino const gdb_byte *valaddr, int embedded_offset, 560c50c785cSJohn Marino const struct value *val, 561c50c785cSJohn Marino const struct value_print_options *options, 562c50c785cSJohn Marino int size, 563c50c785cSJohn Marino struct ui_file *stream) 564c50c785cSJohn Marino { 565c50c785cSJohn Marino gdb_assert (val != NULL); 566c50c785cSJohn Marino gdb_assert (valaddr == value_contents_for_printing_const (val)); 567c50c785cSJohn Marino 568c50c785cSJohn Marino /* If we get here with a string format, try again without it. Go 569c50c785cSJohn Marino all the way back to the language printers, which may call us 570c50c785cSJohn Marino again. */ 571c50c785cSJohn Marino if (options->format == 's') 572c50c785cSJohn Marino { 573c50c785cSJohn Marino struct value_print_options opts = *options; 574c50c785cSJohn Marino opts.format = 0; 575c50c785cSJohn Marino opts.deref_ref = 0; 576c50c785cSJohn Marino val_print (type, valaddr, embedded_offset, 0, stream, 0, val, &opts, 577c50c785cSJohn Marino current_language); 578c50c785cSJohn Marino return; 579c50c785cSJohn Marino } 580c50c785cSJohn Marino 581c50c785cSJohn Marino /* A scalar object that does not have all bits available can't be 582c50c785cSJohn Marino printed, because all bits contribute to its representation. */ 583c50c785cSJohn Marino if (!value_bits_valid (val, TARGET_CHAR_BIT * embedded_offset, 584c50c785cSJohn Marino TARGET_CHAR_BIT * TYPE_LENGTH (type))) 585c50c785cSJohn Marino val_print_optimized_out (stream); 586c50c785cSJohn Marino else if (!value_bytes_available (val, embedded_offset, TYPE_LENGTH (type))) 587c50c785cSJohn Marino val_print_unavailable (stream); 588c50c785cSJohn Marino else 589c50c785cSJohn Marino print_scalar_formatted (valaddr + embedded_offset, type, 590c50c785cSJohn Marino options, size, stream); 5915796c8dcSSimon Schubert } 5925796c8dcSSimon Schubert 5935796c8dcSSimon Schubert /* Print a number according to FORMAT which is one of d,u,x,o,b,h,w,g. 5945796c8dcSSimon Schubert The raison d'etre of this function is to consolidate printing of 5955796c8dcSSimon Schubert LONG_LONG's into this one function. The format chars b,h,w,g are 5965796c8dcSSimon Schubert from print_scalar_formatted(). Numbers are printed using C 5975796c8dcSSimon Schubert format. 5985796c8dcSSimon Schubert 5995796c8dcSSimon Schubert USE_C_FORMAT means to use C format in all cases. Without it, 6005796c8dcSSimon Schubert 'o' and 'x' format do not include the standard C radix prefix 6015796c8dcSSimon Schubert (leading 0 or 0x). 6025796c8dcSSimon Schubert 6035796c8dcSSimon Schubert Hilfinger/2004-09-09: USE_C_FORMAT was originally called USE_LOCAL 6045796c8dcSSimon Schubert and was intended to request formating according to the current 6055796c8dcSSimon Schubert language and would be used for most integers that GDB prints. The 6065796c8dcSSimon Schubert exceptional cases were things like protocols where the format of 6075796c8dcSSimon Schubert the integer is a protocol thing, not a user-visible thing). The 6085796c8dcSSimon Schubert parameter remains to preserve the information of what things might 6095796c8dcSSimon Schubert be printed with language-specific format, should we ever resurrect 6105796c8dcSSimon Schubert that capability. */ 6115796c8dcSSimon Schubert 6125796c8dcSSimon Schubert void 6135796c8dcSSimon Schubert print_longest (struct ui_file *stream, int format, int use_c_format, 6145796c8dcSSimon Schubert LONGEST val_long) 6155796c8dcSSimon Schubert { 6165796c8dcSSimon Schubert const char *val; 6175796c8dcSSimon Schubert 6185796c8dcSSimon Schubert switch (format) 6195796c8dcSSimon Schubert { 6205796c8dcSSimon Schubert case 'd': 6215796c8dcSSimon Schubert val = int_string (val_long, 10, 1, 0, 1); break; 6225796c8dcSSimon Schubert case 'u': 6235796c8dcSSimon Schubert val = int_string (val_long, 10, 0, 0, 1); break; 6245796c8dcSSimon Schubert case 'x': 6255796c8dcSSimon Schubert val = int_string (val_long, 16, 0, 0, use_c_format); break; 6265796c8dcSSimon Schubert case 'b': 6275796c8dcSSimon Schubert val = int_string (val_long, 16, 0, 2, 1); break; 6285796c8dcSSimon Schubert case 'h': 6295796c8dcSSimon Schubert val = int_string (val_long, 16, 0, 4, 1); break; 6305796c8dcSSimon Schubert case 'w': 6315796c8dcSSimon Schubert val = int_string (val_long, 16, 0, 8, 1); break; 6325796c8dcSSimon Schubert case 'g': 6335796c8dcSSimon Schubert val = int_string (val_long, 16, 0, 16, 1); break; 6345796c8dcSSimon Schubert break; 6355796c8dcSSimon Schubert case 'o': 6365796c8dcSSimon Schubert val = int_string (val_long, 8, 0, 0, use_c_format); break; 6375796c8dcSSimon Schubert default: 638c50c785cSJohn Marino internal_error (__FILE__, __LINE__, 639c50c785cSJohn Marino _("failed internal consistency check")); 6405796c8dcSSimon Schubert } 6415796c8dcSSimon Schubert fputs_filtered (val, stream); 6425796c8dcSSimon Schubert } 6435796c8dcSSimon Schubert 6445796c8dcSSimon Schubert /* This used to be a macro, but I don't think it is called often enough 6455796c8dcSSimon Schubert to merit such treatment. */ 6465796c8dcSSimon Schubert /* Convert a LONGEST to an int. This is used in contexts (e.g. number of 6475796c8dcSSimon Schubert arguments to a function, number in a value history, register number, etc.) 6485796c8dcSSimon Schubert where the value must not be larger than can fit in an int. */ 6495796c8dcSSimon Schubert 6505796c8dcSSimon Schubert int 6515796c8dcSSimon Schubert longest_to_int (LONGEST arg) 6525796c8dcSSimon Schubert { 653c50c785cSJohn Marino /* Let the compiler do the work. */ 6545796c8dcSSimon Schubert int rtnval = (int) arg; 6555796c8dcSSimon Schubert 656c50c785cSJohn Marino /* Check for overflows or underflows. */ 6575796c8dcSSimon Schubert if (sizeof (LONGEST) > sizeof (int)) 6585796c8dcSSimon Schubert { 6595796c8dcSSimon Schubert if (rtnval != arg) 6605796c8dcSSimon Schubert { 6615796c8dcSSimon Schubert error (_("Value out of range.")); 6625796c8dcSSimon Schubert } 6635796c8dcSSimon Schubert } 6645796c8dcSSimon Schubert return (rtnval); 6655796c8dcSSimon Schubert } 6665796c8dcSSimon Schubert 6675796c8dcSSimon Schubert /* Print a floating point value of type TYPE (not always a 6685796c8dcSSimon Schubert TYPE_CODE_FLT), pointed to in GDB by VALADDR, on STREAM. */ 6695796c8dcSSimon Schubert 6705796c8dcSSimon Schubert void 6715796c8dcSSimon Schubert print_floating (const gdb_byte *valaddr, struct type *type, 6725796c8dcSSimon Schubert struct ui_file *stream) 6735796c8dcSSimon Schubert { 6745796c8dcSSimon Schubert DOUBLEST doub; 6755796c8dcSSimon Schubert int inv; 6765796c8dcSSimon Schubert const struct floatformat *fmt = NULL; 6775796c8dcSSimon Schubert unsigned len = TYPE_LENGTH (type); 6785796c8dcSSimon Schubert enum float_kind kind; 6795796c8dcSSimon Schubert 6805796c8dcSSimon Schubert /* If it is a floating-point, check for obvious problems. */ 6815796c8dcSSimon Schubert if (TYPE_CODE (type) == TYPE_CODE_FLT) 6825796c8dcSSimon Schubert fmt = floatformat_from_type (type); 6835796c8dcSSimon Schubert if (fmt != NULL) 6845796c8dcSSimon Schubert { 6855796c8dcSSimon Schubert kind = floatformat_classify (fmt, valaddr); 6865796c8dcSSimon Schubert if (kind == float_nan) 6875796c8dcSSimon Schubert { 6885796c8dcSSimon Schubert if (floatformat_is_negative (fmt, valaddr)) 6895796c8dcSSimon Schubert fprintf_filtered (stream, "-"); 6905796c8dcSSimon Schubert fprintf_filtered (stream, "nan("); 6915796c8dcSSimon Schubert fputs_filtered ("0x", stream); 6925796c8dcSSimon Schubert fputs_filtered (floatformat_mantissa (fmt, valaddr), stream); 6935796c8dcSSimon Schubert fprintf_filtered (stream, ")"); 6945796c8dcSSimon Schubert return; 6955796c8dcSSimon Schubert } 6965796c8dcSSimon Schubert else if (kind == float_infinite) 6975796c8dcSSimon Schubert { 6985796c8dcSSimon Schubert if (floatformat_is_negative (fmt, valaddr)) 6995796c8dcSSimon Schubert fputs_filtered ("-", stream); 7005796c8dcSSimon Schubert fputs_filtered ("inf", stream); 7015796c8dcSSimon Schubert return; 7025796c8dcSSimon Schubert } 7035796c8dcSSimon Schubert } 7045796c8dcSSimon Schubert 7055796c8dcSSimon Schubert /* NOTE: cagney/2002-01-15: The TYPE passed into print_floating() 7065796c8dcSSimon Schubert isn't necessarily a TYPE_CODE_FLT. Consequently, unpack_double 7075796c8dcSSimon Schubert needs to be used as that takes care of any necessary type 7085796c8dcSSimon Schubert conversions. Such conversions are of course direct to DOUBLEST 7095796c8dcSSimon Schubert and disregard any possible target floating point limitations. 7105796c8dcSSimon Schubert For instance, a u64 would be converted and displayed exactly on a 7115796c8dcSSimon Schubert host with 80 bit DOUBLEST but with loss of information on a host 7125796c8dcSSimon Schubert with 64 bit DOUBLEST. */ 7135796c8dcSSimon Schubert 7145796c8dcSSimon Schubert doub = unpack_double (type, valaddr, &inv); 7155796c8dcSSimon Schubert if (inv) 7165796c8dcSSimon Schubert { 7175796c8dcSSimon Schubert fprintf_filtered (stream, "<invalid float value>"); 7185796c8dcSSimon Schubert return; 7195796c8dcSSimon Schubert } 7205796c8dcSSimon Schubert 7215796c8dcSSimon Schubert /* FIXME: kettenis/2001-01-20: The following code makes too much 7225796c8dcSSimon Schubert assumptions about the host and target floating point format. */ 7235796c8dcSSimon Schubert 7245796c8dcSSimon Schubert /* NOTE: cagney/2002-02-03: Since the TYPE of what was passed in may 7255796c8dcSSimon Schubert not necessarily be a TYPE_CODE_FLT, the below ignores that and 7265796c8dcSSimon Schubert instead uses the type's length to determine the precision of the 7275796c8dcSSimon Schubert floating-point value being printed. */ 7285796c8dcSSimon Schubert 7295796c8dcSSimon Schubert if (len < sizeof (double)) 7305796c8dcSSimon Schubert fprintf_filtered (stream, "%.9g", (double) doub); 7315796c8dcSSimon Schubert else if (len == sizeof (double)) 7325796c8dcSSimon Schubert fprintf_filtered (stream, "%.17g", (double) doub); 7335796c8dcSSimon Schubert else 7345796c8dcSSimon Schubert #ifdef PRINTF_HAS_LONG_DOUBLE 7355796c8dcSSimon Schubert fprintf_filtered (stream, "%.35Lg", doub); 7365796c8dcSSimon Schubert #else 7375796c8dcSSimon Schubert /* This at least wins with values that are representable as 7385796c8dcSSimon Schubert doubles. */ 7395796c8dcSSimon Schubert fprintf_filtered (stream, "%.17g", (double) doub); 7405796c8dcSSimon Schubert #endif 7415796c8dcSSimon Schubert } 7425796c8dcSSimon Schubert 7435796c8dcSSimon Schubert void 7445796c8dcSSimon Schubert print_decimal_floating (const gdb_byte *valaddr, struct type *type, 7455796c8dcSSimon Schubert struct ui_file *stream) 7465796c8dcSSimon Schubert { 7475796c8dcSSimon Schubert enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type)); 7485796c8dcSSimon Schubert char decstr[MAX_DECIMAL_STRING]; 7495796c8dcSSimon Schubert unsigned len = TYPE_LENGTH (type); 7505796c8dcSSimon Schubert 7515796c8dcSSimon Schubert decimal_to_string (valaddr, len, byte_order, decstr); 7525796c8dcSSimon Schubert fputs_filtered (decstr, stream); 7535796c8dcSSimon Schubert return; 7545796c8dcSSimon Schubert } 7555796c8dcSSimon Schubert 7565796c8dcSSimon Schubert void 7575796c8dcSSimon Schubert print_binary_chars (struct ui_file *stream, const gdb_byte *valaddr, 7585796c8dcSSimon Schubert unsigned len, enum bfd_endian byte_order) 7595796c8dcSSimon Schubert { 7605796c8dcSSimon Schubert 7615796c8dcSSimon Schubert #define BITS_IN_BYTES 8 7625796c8dcSSimon Schubert 7635796c8dcSSimon Schubert const gdb_byte *p; 7645796c8dcSSimon Schubert unsigned int i; 7655796c8dcSSimon Schubert int b; 7665796c8dcSSimon Schubert 7675796c8dcSSimon Schubert /* Declared "int" so it will be signed. 768c50c785cSJohn Marino This ensures that right shift will shift in zeros. */ 769c50c785cSJohn Marino 7705796c8dcSSimon Schubert const int mask = 0x080; 7715796c8dcSSimon Schubert 7725796c8dcSSimon Schubert /* FIXME: We should be not printing leading zeroes in most cases. */ 7735796c8dcSSimon Schubert 7745796c8dcSSimon Schubert if (byte_order == BFD_ENDIAN_BIG) 7755796c8dcSSimon Schubert { 7765796c8dcSSimon Schubert for (p = valaddr; 7775796c8dcSSimon Schubert p < valaddr + len; 7785796c8dcSSimon Schubert p++) 7795796c8dcSSimon Schubert { 7805796c8dcSSimon Schubert /* Every byte has 8 binary characters; peel off 781c50c785cSJohn Marino and print from the MSB end. */ 782c50c785cSJohn Marino 7835796c8dcSSimon Schubert for (i = 0; i < (BITS_IN_BYTES * sizeof (*p)); i++) 7845796c8dcSSimon Schubert { 7855796c8dcSSimon Schubert if (*p & (mask >> i)) 7865796c8dcSSimon Schubert b = 1; 7875796c8dcSSimon Schubert else 7885796c8dcSSimon Schubert b = 0; 7895796c8dcSSimon Schubert 7905796c8dcSSimon Schubert fprintf_filtered (stream, "%1d", b); 7915796c8dcSSimon Schubert } 7925796c8dcSSimon Schubert } 7935796c8dcSSimon Schubert } 7945796c8dcSSimon Schubert else 7955796c8dcSSimon Schubert { 7965796c8dcSSimon Schubert for (p = valaddr + len - 1; 7975796c8dcSSimon Schubert p >= valaddr; 7985796c8dcSSimon Schubert p--) 7995796c8dcSSimon Schubert { 8005796c8dcSSimon Schubert for (i = 0; i < (BITS_IN_BYTES * sizeof (*p)); i++) 8015796c8dcSSimon Schubert { 8025796c8dcSSimon Schubert if (*p & (mask >> i)) 8035796c8dcSSimon Schubert b = 1; 8045796c8dcSSimon Schubert else 8055796c8dcSSimon Schubert b = 0; 8065796c8dcSSimon Schubert 8075796c8dcSSimon Schubert fprintf_filtered (stream, "%1d", b); 8085796c8dcSSimon Schubert } 8095796c8dcSSimon Schubert } 8105796c8dcSSimon Schubert } 8115796c8dcSSimon Schubert } 8125796c8dcSSimon Schubert 8135796c8dcSSimon Schubert /* VALADDR points to an integer of LEN bytes. 814c50c785cSJohn Marino Print it in octal on stream or format it in buf. */ 815c50c785cSJohn Marino 8165796c8dcSSimon Schubert void 8175796c8dcSSimon Schubert print_octal_chars (struct ui_file *stream, const gdb_byte *valaddr, 8185796c8dcSSimon Schubert unsigned len, enum bfd_endian byte_order) 8195796c8dcSSimon Schubert { 8205796c8dcSSimon Schubert const gdb_byte *p; 8215796c8dcSSimon Schubert unsigned char octa1, octa2, octa3, carry; 8225796c8dcSSimon Schubert int cycle; 8235796c8dcSSimon Schubert 8245796c8dcSSimon Schubert /* FIXME: We should be not printing leading zeroes in most cases. */ 8255796c8dcSSimon Schubert 8265796c8dcSSimon Schubert 8275796c8dcSSimon Schubert /* Octal is 3 bits, which doesn't fit. Yuk. So we have to track 8285796c8dcSSimon Schubert * the extra bits, which cycle every three bytes: 8295796c8dcSSimon Schubert * 8305796c8dcSSimon Schubert * Byte side: 0 1 2 3 8315796c8dcSSimon Schubert * | | | | 8325796c8dcSSimon Schubert * bit number 123 456 78 | 9 012 345 6 | 78 901 234 | 567 890 12 | 8335796c8dcSSimon Schubert * 8345796c8dcSSimon Schubert * Octal side: 0 1 carry 3 4 carry ... 8355796c8dcSSimon Schubert * 8365796c8dcSSimon Schubert * Cycle number: 0 1 2 8375796c8dcSSimon Schubert * 8385796c8dcSSimon Schubert * But of course we are printing from the high side, so we have to 8395796c8dcSSimon Schubert * figure out where in the cycle we are so that we end up with no 8405796c8dcSSimon Schubert * left over bits at the end. 8415796c8dcSSimon Schubert */ 8425796c8dcSSimon Schubert #define BITS_IN_OCTAL 3 8435796c8dcSSimon Schubert #define HIGH_ZERO 0340 8445796c8dcSSimon Schubert #define LOW_ZERO 0016 8455796c8dcSSimon Schubert #define CARRY_ZERO 0003 8465796c8dcSSimon Schubert #define HIGH_ONE 0200 8475796c8dcSSimon Schubert #define MID_ONE 0160 8485796c8dcSSimon Schubert #define LOW_ONE 0016 8495796c8dcSSimon Schubert #define CARRY_ONE 0001 8505796c8dcSSimon Schubert #define HIGH_TWO 0300 8515796c8dcSSimon Schubert #define MID_TWO 0070 8525796c8dcSSimon Schubert #define LOW_TWO 0007 8535796c8dcSSimon Schubert 8545796c8dcSSimon Schubert /* For 32 we start in cycle 2, with two bits and one bit carry; 855c50c785cSJohn Marino for 64 in cycle in cycle 1, with one bit and a two bit carry. */ 856c50c785cSJohn Marino 8575796c8dcSSimon Schubert cycle = (len * BITS_IN_BYTES) % BITS_IN_OCTAL; 8585796c8dcSSimon Schubert carry = 0; 8595796c8dcSSimon Schubert 8605796c8dcSSimon Schubert fputs_filtered ("0", stream); 8615796c8dcSSimon Schubert if (byte_order == BFD_ENDIAN_BIG) 8625796c8dcSSimon Schubert { 8635796c8dcSSimon Schubert for (p = valaddr; 8645796c8dcSSimon Schubert p < valaddr + len; 8655796c8dcSSimon Schubert p++) 8665796c8dcSSimon Schubert { 8675796c8dcSSimon Schubert switch (cycle) 8685796c8dcSSimon Schubert { 8695796c8dcSSimon Schubert case 0: 870c50c785cSJohn Marino /* No carry in, carry out two bits. */ 871c50c785cSJohn Marino 8725796c8dcSSimon Schubert octa1 = (HIGH_ZERO & *p) >> 5; 8735796c8dcSSimon Schubert octa2 = (LOW_ZERO & *p) >> 2; 8745796c8dcSSimon Schubert carry = (CARRY_ZERO & *p); 8755796c8dcSSimon Schubert fprintf_filtered (stream, "%o", octa1); 8765796c8dcSSimon Schubert fprintf_filtered (stream, "%o", octa2); 8775796c8dcSSimon Schubert break; 8785796c8dcSSimon Schubert 8795796c8dcSSimon Schubert case 1: 880c50c785cSJohn Marino /* Carry in two bits, carry out one bit. */ 881c50c785cSJohn Marino 8825796c8dcSSimon Schubert octa1 = (carry << 1) | ((HIGH_ONE & *p) >> 7); 8835796c8dcSSimon Schubert octa2 = (MID_ONE & *p) >> 4; 8845796c8dcSSimon Schubert octa3 = (LOW_ONE & *p) >> 1; 8855796c8dcSSimon Schubert carry = (CARRY_ONE & *p); 8865796c8dcSSimon Schubert fprintf_filtered (stream, "%o", octa1); 8875796c8dcSSimon Schubert fprintf_filtered (stream, "%o", octa2); 8885796c8dcSSimon Schubert fprintf_filtered (stream, "%o", octa3); 8895796c8dcSSimon Schubert break; 8905796c8dcSSimon Schubert 8915796c8dcSSimon Schubert case 2: 892c50c785cSJohn Marino /* Carry in one bit, no carry out. */ 893c50c785cSJohn Marino 8945796c8dcSSimon Schubert octa1 = (carry << 2) | ((HIGH_TWO & *p) >> 6); 8955796c8dcSSimon Schubert octa2 = (MID_TWO & *p) >> 3; 8965796c8dcSSimon Schubert octa3 = (LOW_TWO & *p); 8975796c8dcSSimon Schubert carry = 0; 8985796c8dcSSimon Schubert fprintf_filtered (stream, "%o", octa1); 8995796c8dcSSimon Schubert fprintf_filtered (stream, "%o", octa2); 9005796c8dcSSimon Schubert fprintf_filtered (stream, "%o", octa3); 9015796c8dcSSimon Schubert break; 9025796c8dcSSimon Schubert 9035796c8dcSSimon Schubert default: 9045796c8dcSSimon Schubert error (_("Internal error in octal conversion;")); 9055796c8dcSSimon Schubert } 9065796c8dcSSimon Schubert 9075796c8dcSSimon Schubert cycle++; 9085796c8dcSSimon Schubert cycle = cycle % BITS_IN_OCTAL; 9095796c8dcSSimon Schubert } 9105796c8dcSSimon Schubert } 9115796c8dcSSimon Schubert else 9125796c8dcSSimon Schubert { 9135796c8dcSSimon Schubert for (p = valaddr + len - 1; 9145796c8dcSSimon Schubert p >= valaddr; 9155796c8dcSSimon Schubert p--) 9165796c8dcSSimon Schubert { 9175796c8dcSSimon Schubert switch (cycle) 9185796c8dcSSimon Schubert { 9195796c8dcSSimon Schubert case 0: 9205796c8dcSSimon Schubert /* Carry out, no carry in */ 921c50c785cSJohn Marino 9225796c8dcSSimon Schubert octa1 = (HIGH_ZERO & *p) >> 5; 9235796c8dcSSimon Schubert octa2 = (LOW_ZERO & *p) >> 2; 9245796c8dcSSimon Schubert carry = (CARRY_ZERO & *p); 9255796c8dcSSimon Schubert fprintf_filtered (stream, "%o", octa1); 9265796c8dcSSimon Schubert fprintf_filtered (stream, "%o", octa2); 9275796c8dcSSimon Schubert break; 9285796c8dcSSimon Schubert 9295796c8dcSSimon Schubert case 1: 9305796c8dcSSimon Schubert /* Carry in, carry out */ 931c50c785cSJohn Marino 9325796c8dcSSimon Schubert octa1 = (carry << 1) | ((HIGH_ONE & *p) >> 7); 9335796c8dcSSimon Schubert octa2 = (MID_ONE & *p) >> 4; 9345796c8dcSSimon Schubert octa3 = (LOW_ONE & *p) >> 1; 9355796c8dcSSimon Schubert carry = (CARRY_ONE & *p); 9365796c8dcSSimon Schubert fprintf_filtered (stream, "%o", octa1); 9375796c8dcSSimon Schubert fprintf_filtered (stream, "%o", octa2); 9385796c8dcSSimon Schubert fprintf_filtered (stream, "%o", octa3); 9395796c8dcSSimon Schubert break; 9405796c8dcSSimon Schubert 9415796c8dcSSimon Schubert case 2: 9425796c8dcSSimon Schubert /* Carry in, no carry out */ 943c50c785cSJohn Marino 9445796c8dcSSimon Schubert octa1 = (carry << 2) | ((HIGH_TWO & *p) >> 6); 9455796c8dcSSimon Schubert octa2 = (MID_TWO & *p) >> 3; 9465796c8dcSSimon Schubert octa3 = (LOW_TWO & *p); 9475796c8dcSSimon Schubert carry = 0; 9485796c8dcSSimon Schubert fprintf_filtered (stream, "%o", octa1); 9495796c8dcSSimon Schubert fprintf_filtered (stream, "%o", octa2); 9505796c8dcSSimon Schubert fprintf_filtered (stream, "%o", octa3); 9515796c8dcSSimon Schubert break; 9525796c8dcSSimon Schubert 9535796c8dcSSimon Schubert default: 9545796c8dcSSimon Schubert error (_("Internal error in octal conversion;")); 9555796c8dcSSimon Schubert } 9565796c8dcSSimon Schubert 9575796c8dcSSimon Schubert cycle++; 9585796c8dcSSimon Schubert cycle = cycle % BITS_IN_OCTAL; 9595796c8dcSSimon Schubert } 9605796c8dcSSimon Schubert } 9615796c8dcSSimon Schubert 9625796c8dcSSimon Schubert } 9635796c8dcSSimon Schubert 9645796c8dcSSimon Schubert /* VALADDR points to an integer of LEN bytes. 965c50c785cSJohn Marino Print it in decimal on stream or format it in buf. */ 966c50c785cSJohn Marino 9675796c8dcSSimon Schubert void 9685796c8dcSSimon Schubert print_decimal_chars (struct ui_file *stream, const gdb_byte *valaddr, 9695796c8dcSSimon Schubert unsigned len, enum bfd_endian byte_order) 9705796c8dcSSimon Schubert { 9715796c8dcSSimon Schubert #define TEN 10 9725796c8dcSSimon Schubert #define CARRY_OUT( x ) ((x) / TEN) /* extend char to int */ 9735796c8dcSSimon Schubert #define CARRY_LEFT( x ) ((x) % TEN) 9745796c8dcSSimon Schubert #define SHIFT( x ) ((x) << 4) 9755796c8dcSSimon Schubert #define LOW_NIBBLE( x ) ( (x) & 0x00F) 9765796c8dcSSimon Schubert #define HIGH_NIBBLE( x ) (((x) & 0x0F0) >> 4) 9775796c8dcSSimon Schubert 9785796c8dcSSimon Schubert const gdb_byte *p; 9795796c8dcSSimon Schubert unsigned char *digits; 9805796c8dcSSimon Schubert int carry; 9815796c8dcSSimon Schubert int decimal_len; 9825796c8dcSSimon Schubert int i, j, decimal_digits; 9835796c8dcSSimon Schubert int dummy; 9845796c8dcSSimon Schubert int flip; 9855796c8dcSSimon Schubert 9865796c8dcSSimon Schubert /* Base-ten number is less than twice as many digits 987c50c785cSJohn Marino as the base 16 number, which is 2 digits per byte. */ 988c50c785cSJohn Marino 9895796c8dcSSimon Schubert decimal_len = len * 2 * 2; 9905796c8dcSSimon Schubert digits = xmalloc (decimal_len); 9915796c8dcSSimon Schubert 9925796c8dcSSimon Schubert for (i = 0; i < decimal_len; i++) 9935796c8dcSSimon Schubert { 9945796c8dcSSimon Schubert digits[i] = 0; 9955796c8dcSSimon Schubert } 9965796c8dcSSimon Schubert 9975796c8dcSSimon Schubert /* Ok, we have an unknown number of bytes of data to be printed in 9985796c8dcSSimon Schubert * decimal. 9995796c8dcSSimon Schubert * 10005796c8dcSSimon Schubert * Given a hex number (in nibbles) as XYZ, we start by taking X and 10015796c8dcSSimon Schubert * decemalizing it as "x1 x2" in two decimal nibbles. Then we multiply 10025796c8dcSSimon Schubert * the nibbles by 16, add Y and re-decimalize. Repeat with Z. 10035796c8dcSSimon Schubert * 10045796c8dcSSimon Schubert * The trick is that "digits" holds a base-10 number, but sometimes 10055796c8dcSSimon Schubert * the individual digits are > 10. 10065796c8dcSSimon Schubert * 10075796c8dcSSimon Schubert * Outer loop is per nibble (hex digit) of input, from MSD end to 10085796c8dcSSimon Schubert * LSD end. 10095796c8dcSSimon Schubert */ 10105796c8dcSSimon Schubert decimal_digits = 0; /* Number of decimal digits so far */ 10115796c8dcSSimon Schubert p = (byte_order == BFD_ENDIAN_BIG) ? valaddr : valaddr + len - 1; 10125796c8dcSSimon Schubert flip = 0; 10135796c8dcSSimon Schubert while ((byte_order == BFD_ENDIAN_BIG) ? (p < valaddr + len) : (p >= valaddr)) 10145796c8dcSSimon Schubert { 10155796c8dcSSimon Schubert /* 10165796c8dcSSimon Schubert * Multiply current base-ten number by 16 in place. 10175796c8dcSSimon Schubert * Each digit was between 0 and 9, now is between 10185796c8dcSSimon Schubert * 0 and 144. 10195796c8dcSSimon Schubert */ 10205796c8dcSSimon Schubert for (j = 0; j < decimal_digits; j++) 10215796c8dcSSimon Schubert { 10225796c8dcSSimon Schubert digits[j] = SHIFT (digits[j]); 10235796c8dcSSimon Schubert } 10245796c8dcSSimon Schubert 10255796c8dcSSimon Schubert /* Take the next nibble off the input and add it to what 10265796c8dcSSimon Schubert * we've got in the LSB position. Bottom 'digit' is now 10275796c8dcSSimon Schubert * between 0 and 159. 10285796c8dcSSimon Schubert * 10295796c8dcSSimon Schubert * "flip" is used to run this loop twice for each byte. 10305796c8dcSSimon Schubert */ 10315796c8dcSSimon Schubert if (flip == 0) 10325796c8dcSSimon Schubert { 1033c50c785cSJohn Marino /* Take top nibble. */ 1034c50c785cSJohn Marino 10355796c8dcSSimon Schubert digits[0] += HIGH_NIBBLE (*p); 10365796c8dcSSimon Schubert flip = 1; 10375796c8dcSSimon Schubert } 10385796c8dcSSimon Schubert else 10395796c8dcSSimon Schubert { 1040c50c785cSJohn Marino /* Take low nibble and bump our pointer "p". */ 1041c50c785cSJohn Marino 10425796c8dcSSimon Schubert digits[0] += LOW_NIBBLE (*p); 10435796c8dcSSimon Schubert if (byte_order == BFD_ENDIAN_BIG) 10445796c8dcSSimon Schubert p++; 10455796c8dcSSimon Schubert else 10465796c8dcSSimon Schubert p--; 10475796c8dcSSimon Schubert flip = 0; 10485796c8dcSSimon Schubert } 10495796c8dcSSimon Schubert 10505796c8dcSSimon Schubert /* Re-decimalize. We have to do this often enough 10515796c8dcSSimon Schubert * that we don't overflow, but once per nibble is 10525796c8dcSSimon Schubert * overkill. Easier this way, though. Note that the 10535796c8dcSSimon Schubert * carry is often larger than 10 (e.g. max initial 10545796c8dcSSimon Schubert * carry out of lowest nibble is 15, could bubble all 10555796c8dcSSimon Schubert * the way up greater than 10). So we have to do 10565796c8dcSSimon Schubert * the carrying beyond the last current digit. 10575796c8dcSSimon Schubert */ 10585796c8dcSSimon Schubert carry = 0; 10595796c8dcSSimon Schubert for (j = 0; j < decimal_len - 1; j++) 10605796c8dcSSimon Schubert { 10615796c8dcSSimon Schubert digits[j] += carry; 10625796c8dcSSimon Schubert 10635796c8dcSSimon Schubert /* "/" won't handle an unsigned char with 10645796c8dcSSimon Schubert * a value that if signed would be negative. 10655796c8dcSSimon Schubert * So extend to longword int via "dummy". 10665796c8dcSSimon Schubert */ 10675796c8dcSSimon Schubert dummy = digits[j]; 10685796c8dcSSimon Schubert carry = CARRY_OUT (dummy); 10695796c8dcSSimon Schubert digits[j] = CARRY_LEFT (dummy); 10705796c8dcSSimon Schubert 10715796c8dcSSimon Schubert if (j >= decimal_digits && carry == 0) 10725796c8dcSSimon Schubert { 10735796c8dcSSimon Schubert /* 10745796c8dcSSimon Schubert * All higher digits are 0 and we 10755796c8dcSSimon Schubert * no longer have a carry. 10765796c8dcSSimon Schubert * 10775796c8dcSSimon Schubert * Note: "j" is 0-based, "decimal_digits" is 10785796c8dcSSimon Schubert * 1-based. 10795796c8dcSSimon Schubert */ 10805796c8dcSSimon Schubert decimal_digits = j + 1; 10815796c8dcSSimon Schubert break; 10825796c8dcSSimon Schubert } 10835796c8dcSSimon Schubert } 10845796c8dcSSimon Schubert } 10855796c8dcSSimon Schubert 10865796c8dcSSimon Schubert /* Ok, now "digits" is the decimal representation, with 1087c50c785cSJohn Marino the "decimal_digits" actual digits. Print! */ 1088c50c785cSJohn Marino 10895796c8dcSSimon Schubert for (i = decimal_digits - 1; i >= 0; i--) 10905796c8dcSSimon Schubert { 10915796c8dcSSimon Schubert fprintf_filtered (stream, "%1d", digits[i]); 10925796c8dcSSimon Schubert } 10935796c8dcSSimon Schubert xfree (digits); 10945796c8dcSSimon Schubert } 10955796c8dcSSimon Schubert 10965796c8dcSSimon Schubert /* VALADDR points to an integer of LEN bytes. Print it in hex on stream. */ 10975796c8dcSSimon Schubert 10985796c8dcSSimon Schubert void 10995796c8dcSSimon Schubert print_hex_chars (struct ui_file *stream, const gdb_byte *valaddr, 11005796c8dcSSimon Schubert unsigned len, enum bfd_endian byte_order) 11015796c8dcSSimon Schubert { 11025796c8dcSSimon Schubert const gdb_byte *p; 11035796c8dcSSimon Schubert 11045796c8dcSSimon Schubert /* FIXME: We should be not printing leading zeroes in most cases. */ 11055796c8dcSSimon Schubert 11065796c8dcSSimon Schubert fputs_filtered ("0x", stream); 11075796c8dcSSimon Schubert if (byte_order == BFD_ENDIAN_BIG) 11085796c8dcSSimon Schubert { 11095796c8dcSSimon Schubert for (p = valaddr; 11105796c8dcSSimon Schubert p < valaddr + len; 11115796c8dcSSimon Schubert p++) 11125796c8dcSSimon Schubert { 11135796c8dcSSimon Schubert fprintf_filtered (stream, "%02x", *p); 11145796c8dcSSimon Schubert } 11155796c8dcSSimon Schubert } 11165796c8dcSSimon Schubert else 11175796c8dcSSimon Schubert { 11185796c8dcSSimon Schubert for (p = valaddr + len - 1; 11195796c8dcSSimon Schubert p >= valaddr; 11205796c8dcSSimon Schubert p--) 11215796c8dcSSimon Schubert { 11225796c8dcSSimon Schubert fprintf_filtered (stream, "%02x", *p); 11235796c8dcSSimon Schubert } 11245796c8dcSSimon Schubert } 11255796c8dcSSimon Schubert } 11265796c8dcSSimon Schubert 1127c50c785cSJohn Marino /* VALADDR points to a char integer of LEN bytes. 1128c50c785cSJohn Marino Print it out in appropriate language form on stream. 11295796c8dcSSimon Schubert Omit any leading zero chars. */ 11305796c8dcSSimon Schubert 11315796c8dcSSimon Schubert void 11325796c8dcSSimon Schubert print_char_chars (struct ui_file *stream, struct type *type, 11335796c8dcSSimon Schubert const gdb_byte *valaddr, 11345796c8dcSSimon Schubert unsigned len, enum bfd_endian byte_order) 11355796c8dcSSimon Schubert { 11365796c8dcSSimon Schubert const gdb_byte *p; 11375796c8dcSSimon Schubert 11385796c8dcSSimon Schubert if (byte_order == BFD_ENDIAN_BIG) 11395796c8dcSSimon Schubert { 11405796c8dcSSimon Schubert p = valaddr; 11415796c8dcSSimon Schubert while (p < valaddr + len - 1 && *p == 0) 11425796c8dcSSimon Schubert ++p; 11435796c8dcSSimon Schubert 11445796c8dcSSimon Schubert while (p < valaddr + len) 11455796c8dcSSimon Schubert { 11465796c8dcSSimon Schubert LA_EMIT_CHAR (*p, type, stream, '\''); 11475796c8dcSSimon Schubert ++p; 11485796c8dcSSimon Schubert } 11495796c8dcSSimon Schubert } 11505796c8dcSSimon Schubert else 11515796c8dcSSimon Schubert { 11525796c8dcSSimon Schubert p = valaddr + len - 1; 11535796c8dcSSimon Schubert while (p > valaddr && *p == 0) 11545796c8dcSSimon Schubert --p; 11555796c8dcSSimon Schubert 11565796c8dcSSimon Schubert while (p >= valaddr) 11575796c8dcSSimon Schubert { 11585796c8dcSSimon Schubert LA_EMIT_CHAR (*p, type, stream, '\''); 11595796c8dcSSimon Schubert --p; 11605796c8dcSSimon Schubert } 11615796c8dcSSimon Schubert } 11625796c8dcSSimon Schubert } 11635796c8dcSSimon Schubert 11645796c8dcSSimon Schubert /* Print on STREAM using the given OPTIONS the index for the element 11655796c8dcSSimon Schubert at INDEX of an array whose index type is INDEX_TYPE. */ 11665796c8dcSSimon Schubert 11675796c8dcSSimon Schubert void 11685796c8dcSSimon Schubert maybe_print_array_index (struct type *index_type, LONGEST index, 11695796c8dcSSimon Schubert struct ui_file *stream, 11705796c8dcSSimon Schubert const struct value_print_options *options) 11715796c8dcSSimon Schubert { 11725796c8dcSSimon Schubert struct value *index_value; 11735796c8dcSSimon Schubert 11745796c8dcSSimon Schubert if (!options->print_array_indexes) 11755796c8dcSSimon Schubert return; 11765796c8dcSSimon Schubert 11775796c8dcSSimon Schubert index_value = value_from_longest (index_type, index); 11785796c8dcSSimon Schubert 11795796c8dcSSimon Schubert LA_PRINT_ARRAY_INDEX (index_value, stream, options); 11805796c8dcSSimon Schubert } 11815796c8dcSSimon Schubert 11825796c8dcSSimon Schubert /* Called by various <lang>_val_print routines to print elements of an 11835796c8dcSSimon Schubert array in the form "<elem1>, <elem2>, <elem3>, ...". 11845796c8dcSSimon Schubert 11855796c8dcSSimon Schubert (FIXME?) Assumes array element separator is a comma, which is correct 11865796c8dcSSimon Schubert for all languages currently handled. 11875796c8dcSSimon Schubert (FIXME?) Some languages have a notation for repeated array elements, 1188c50c785cSJohn Marino perhaps we should try to use that notation when appropriate. */ 11895796c8dcSSimon Schubert 11905796c8dcSSimon Schubert void 1191c50c785cSJohn Marino val_print_array_elements (struct type *type, 1192c50c785cSJohn Marino const gdb_byte *valaddr, int embedded_offset, 11935796c8dcSSimon Schubert CORE_ADDR address, struct ui_file *stream, 11945796c8dcSSimon Schubert int recurse, 1195cf7f2e2dSJohn Marino const struct value *val, 11965796c8dcSSimon Schubert const struct value_print_options *options, 11975796c8dcSSimon Schubert unsigned int i) 11985796c8dcSSimon Schubert { 11995796c8dcSSimon Schubert unsigned int things_printed = 0; 12005796c8dcSSimon Schubert unsigned len; 12015796c8dcSSimon Schubert struct type *elttype, *index_type; 12025796c8dcSSimon Schubert unsigned eltlen; 12035796c8dcSSimon Schubert /* Position of the array element we are examining to see 12045796c8dcSSimon Schubert whether it is repeated. */ 12055796c8dcSSimon Schubert unsigned int rep1; 12065796c8dcSSimon Schubert /* Number of repetitions we have detected so far. */ 12075796c8dcSSimon Schubert unsigned int reps; 1208c50c785cSJohn Marino LONGEST low_bound, high_bound; 12095796c8dcSSimon Schubert 12105796c8dcSSimon Schubert elttype = TYPE_TARGET_TYPE (type); 12115796c8dcSSimon Schubert eltlen = TYPE_LENGTH (check_typedef (elttype)); 12125796c8dcSSimon Schubert index_type = TYPE_INDEX_TYPE (type); 12135796c8dcSSimon Schubert 1214c50c785cSJohn Marino if (get_array_bounds (type, &low_bound, &high_bound)) 12155796c8dcSSimon Schubert { 1216c50c785cSJohn Marino /* The array length should normally be HIGH_BOUND - LOW_BOUND + 1. 1217c50c785cSJohn Marino But we have to be a little extra careful, because some languages 1218c50c785cSJohn Marino such as Ada allow LOW_BOUND to be greater than HIGH_BOUND for 1219c50c785cSJohn Marino empty arrays. In that situation, the array length is just zero, 1220c50c785cSJohn Marino not negative! */ 1221c50c785cSJohn Marino if (low_bound > high_bound) 1222c50c785cSJohn Marino len = 0; 1223c50c785cSJohn Marino else 1224c50c785cSJohn Marino len = high_bound - low_bound + 1; 1225c50c785cSJohn Marino } 12265796c8dcSSimon Schubert else 12275796c8dcSSimon Schubert { 12285796c8dcSSimon Schubert warning (_("unable to get bounds of array, assuming null array")); 1229c50c785cSJohn Marino low_bound = 0; 12305796c8dcSSimon Schubert len = 0; 12315796c8dcSSimon Schubert } 12325796c8dcSSimon Schubert 12335796c8dcSSimon Schubert annotate_array_section_begin (i, elttype); 12345796c8dcSSimon Schubert 12355796c8dcSSimon Schubert for (; i < len && things_printed < options->print_max; i++) 12365796c8dcSSimon Schubert { 12375796c8dcSSimon Schubert if (i != 0) 12385796c8dcSSimon Schubert { 12395796c8dcSSimon Schubert if (options->prettyprint_arrays) 12405796c8dcSSimon Schubert { 12415796c8dcSSimon Schubert fprintf_filtered (stream, ",\n"); 12425796c8dcSSimon Schubert print_spaces_filtered (2 + 2 * recurse, stream); 12435796c8dcSSimon Schubert } 12445796c8dcSSimon Schubert else 12455796c8dcSSimon Schubert { 12465796c8dcSSimon Schubert fprintf_filtered (stream, ", "); 12475796c8dcSSimon Schubert } 12485796c8dcSSimon Schubert } 12495796c8dcSSimon Schubert wrap_here (n_spaces (2 + 2 * recurse)); 1250c50c785cSJohn Marino maybe_print_array_index (index_type, i + low_bound, 12515796c8dcSSimon Schubert stream, options); 12525796c8dcSSimon Schubert 12535796c8dcSSimon Schubert rep1 = i + 1; 12545796c8dcSSimon Schubert reps = 1; 1255c50c785cSJohn Marino /* Only check for reps if repeat_count_threshold is not set to 1256c50c785cSJohn Marino UINT_MAX (unlimited). */ 1257c50c785cSJohn Marino if (options->repeat_count_threshold < UINT_MAX) 1258c50c785cSJohn Marino { 1259c50c785cSJohn Marino while (rep1 < len 1260c50c785cSJohn Marino && value_available_contents_eq (val, 1261c50c785cSJohn Marino embedded_offset + i * eltlen, 1262c50c785cSJohn Marino val, 1263c50c785cSJohn Marino (embedded_offset 1264c50c785cSJohn Marino + rep1 * eltlen), 1265c50c785cSJohn Marino eltlen)) 12665796c8dcSSimon Schubert { 12675796c8dcSSimon Schubert ++reps; 12685796c8dcSSimon Schubert ++rep1; 12695796c8dcSSimon Schubert } 1270c50c785cSJohn Marino } 12715796c8dcSSimon Schubert 12725796c8dcSSimon Schubert if (reps > options->repeat_count_threshold) 12735796c8dcSSimon Schubert { 1274c50c785cSJohn Marino val_print (elttype, valaddr, embedded_offset + i * eltlen, 1275c50c785cSJohn Marino address, stream, recurse + 1, val, options, 1276c50c785cSJohn Marino current_language); 12775796c8dcSSimon Schubert annotate_elt_rep (reps); 12785796c8dcSSimon Schubert fprintf_filtered (stream, " <repeats %u times>", reps); 12795796c8dcSSimon Schubert annotate_elt_rep_end (); 12805796c8dcSSimon Schubert 12815796c8dcSSimon Schubert i = rep1 - 1; 12825796c8dcSSimon Schubert things_printed += options->repeat_count_threshold; 12835796c8dcSSimon Schubert } 12845796c8dcSSimon Schubert else 12855796c8dcSSimon Schubert { 1286c50c785cSJohn Marino val_print (elttype, valaddr, embedded_offset + i * eltlen, 1287c50c785cSJohn Marino address, 1288cf7f2e2dSJohn Marino stream, recurse + 1, val, options, current_language); 12895796c8dcSSimon Schubert annotate_elt (); 12905796c8dcSSimon Schubert things_printed++; 12915796c8dcSSimon Schubert } 12925796c8dcSSimon Schubert } 12935796c8dcSSimon Schubert annotate_array_section_end (); 12945796c8dcSSimon Schubert if (i < len) 12955796c8dcSSimon Schubert { 12965796c8dcSSimon Schubert fprintf_filtered (stream, "..."); 12975796c8dcSSimon Schubert } 12985796c8dcSSimon Schubert } 12995796c8dcSSimon Schubert 13005796c8dcSSimon Schubert /* Read LEN bytes of target memory at address MEMADDR, placing the 13015796c8dcSSimon Schubert results in GDB's memory at MYADDR. Returns a count of the bytes 13025796c8dcSSimon Schubert actually read, and optionally an errno value in the location 13035796c8dcSSimon Schubert pointed to by ERRNOPTR if ERRNOPTR is non-null. */ 13045796c8dcSSimon Schubert 13055796c8dcSSimon Schubert /* FIXME: cagney/1999-10-14: Only used by val_print_string. Can this 13065796c8dcSSimon Schubert function be eliminated. */ 13075796c8dcSSimon Schubert 13085796c8dcSSimon Schubert static int 1309c50c785cSJohn Marino partial_memory_read (CORE_ADDR memaddr, gdb_byte *myaddr, 1310c50c785cSJohn Marino int len, int *errnoptr) 13115796c8dcSSimon Schubert { 13125796c8dcSSimon Schubert int nread; /* Number of bytes actually read. */ 13135796c8dcSSimon Schubert int errcode; /* Error from last read. */ 13145796c8dcSSimon Schubert 13155796c8dcSSimon Schubert /* First try a complete read. */ 13165796c8dcSSimon Schubert errcode = target_read_memory (memaddr, myaddr, len); 13175796c8dcSSimon Schubert if (errcode == 0) 13185796c8dcSSimon Schubert { 13195796c8dcSSimon Schubert /* Got it all. */ 13205796c8dcSSimon Schubert nread = len; 13215796c8dcSSimon Schubert } 13225796c8dcSSimon Schubert else 13235796c8dcSSimon Schubert { 13245796c8dcSSimon Schubert /* Loop, reading one byte at a time until we get as much as we can. */ 13255796c8dcSSimon Schubert for (errcode = 0, nread = 0; len > 0 && errcode == 0; nread++, len--) 13265796c8dcSSimon Schubert { 13275796c8dcSSimon Schubert errcode = target_read_memory (memaddr++, myaddr++, 1); 13285796c8dcSSimon Schubert } 13295796c8dcSSimon Schubert /* If an error, the last read was unsuccessful, so adjust count. */ 13305796c8dcSSimon Schubert if (errcode != 0) 13315796c8dcSSimon Schubert { 13325796c8dcSSimon Schubert nread--; 13335796c8dcSSimon Schubert } 13345796c8dcSSimon Schubert } 13355796c8dcSSimon Schubert if (errnoptr != NULL) 13365796c8dcSSimon Schubert { 13375796c8dcSSimon Schubert *errnoptr = errcode; 13385796c8dcSSimon Schubert } 13395796c8dcSSimon Schubert return (nread); 13405796c8dcSSimon Schubert } 13415796c8dcSSimon Schubert 13425796c8dcSSimon Schubert /* Read a string from the inferior, at ADDR, with LEN characters of WIDTH bytes 13435796c8dcSSimon Schubert each. Fetch at most FETCHLIMIT characters. BUFFER will be set to a newly 13445796c8dcSSimon Schubert allocated buffer containing the string, which the caller is responsible to 13455796c8dcSSimon Schubert free, and BYTES_READ will be set to the number of bytes read. Returns 0 on 13465796c8dcSSimon Schubert success, or errno on failure. 13475796c8dcSSimon Schubert 13485796c8dcSSimon Schubert If LEN > 0, reads exactly LEN characters (including eventual NULs in 13495796c8dcSSimon Schubert the middle or end of the string). If LEN is -1, stops at the first 13505796c8dcSSimon Schubert null character (not necessarily the first null byte) up to a maximum 13515796c8dcSSimon Schubert of FETCHLIMIT characters. Set FETCHLIMIT to UINT_MAX to read as many 13525796c8dcSSimon Schubert characters as possible from the string. 13535796c8dcSSimon Schubert 13545796c8dcSSimon Schubert Unless an exception is thrown, BUFFER will always be allocated, even on 13555796c8dcSSimon Schubert failure. In this case, some characters might have been read before the 13565796c8dcSSimon Schubert failure happened. Check BYTES_READ to recognize this situation. 13575796c8dcSSimon Schubert 13585796c8dcSSimon Schubert Note: There was a FIXME asking to make this code use target_read_string, 13595796c8dcSSimon Schubert but this function is more general (can read past null characters, up to 13605796c8dcSSimon Schubert given LEN). Besides, it is used much more often than target_read_string 13615796c8dcSSimon Schubert so it is more tested. Perhaps callers of target_read_string should use 13625796c8dcSSimon Schubert this function instead? */ 13635796c8dcSSimon Schubert 13645796c8dcSSimon Schubert int 13655796c8dcSSimon Schubert read_string (CORE_ADDR addr, int len, int width, unsigned int fetchlimit, 13665796c8dcSSimon Schubert enum bfd_endian byte_order, gdb_byte **buffer, int *bytes_read) 13675796c8dcSSimon Schubert { 13685796c8dcSSimon Schubert int found_nul; /* Non-zero if we found the nul char. */ 13695796c8dcSSimon Schubert int errcode; /* Errno returned from bad reads. */ 13705796c8dcSSimon Schubert unsigned int nfetch; /* Chars to fetch / chars fetched. */ 13715796c8dcSSimon Schubert unsigned int chunksize; /* Size of each fetch, in chars. */ 1372c50c785cSJohn Marino gdb_byte *bufptr; /* Pointer to next available byte in 1373c50c785cSJohn Marino buffer. */ 13745796c8dcSSimon Schubert gdb_byte *limit; /* First location past end of fetch buffer. */ 13755796c8dcSSimon Schubert struct cleanup *old_chain = NULL; /* Top of the old cleanup chain. */ 13765796c8dcSSimon Schubert 13775796c8dcSSimon Schubert /* Decide how large of chunks to try to read in one operation. This 13785796c8dcSSimon Schubert is also pretty simple. If LEN >= zero, then we want fetchlimit chars, 13795796c8dcSSimon Schubert so we might as well read them all in one operation. If LEN is -1, we 13805796c8dcSSimon Schubert are looking for a NUL terminator to end the fetching, so we might as 13815796c8dcSSimon Schubert well read in blocks that are large enough to be efficient, but not so 13825796c8dcSSimon Schubert large as to be slow if fetchlimit happens to be large. So we choose the 13835796c8dcSSimon Schubert minimum of 8 and fetchlimit. We used to use 200 instead of 8 but 13845796c8dcSSimon Schubert 200 is way too big for remote debugging over a serial line. */ 13855796c8dcSSimon Schubert 13865796c8dcSSimon Schubert chunksize = (len == -1 ? min (8, fetchlimit) : fetchlimit); 13875796c8dcSSimon Schubert 13885796c8dcSSimon Schubert /* Loop until we either have all the characters, or we encounter 13895796c8dcSSimon Schubert some error, such as bumping into the end of the address space. */ 13905796c8dcSSimon Schubert 13915796c8dcSSimon Schubert found_nul = 0; 13925796c8dcSSimon Schubert *buffer = NULL; 13935796c8dcSSimon Schubert 13945796c8dcSSimon Schubert old_chain = make_cleanup (free_current_contents, buffer); 13955796c8dcSSimon Schubert 13965796c8dcSSimon Schubert if (len > 0) 13975796c8dcSSimon Schubert { 13985796c8dcSSimon Schubert *buffer = (gdb_byte *) xmalloc (len * width); 13995796c8dcSSimon Schubert bufptr = *buffer; 14005796c8dcSSimon Schubert 14015796c8dcSSimon Schubert nfetch = partial_memory_read (addr, bufptr, len * width, &errcode) 14025796c8dcSSimon Schubert / width; 14035796c8dcSSimon Schubert addr += nfetch * width; 14045796c8dcSSimon Schubert bufptr += nfetch * width; 14055796c8dcSSimon Schubert } 14065796c8dcSSimon Schubert else if (len == -1) 14075796c8dcSSimon Schubert { 14085796c8dcSSimon Schubert unsigned long bufsize = 0; 14095796c8dcSSimon Schubert 14105796c8dcSSimon Schubert do 14115796c8dcSSimon Schubert { 14125796c8dcSSimon Schubert QUIT; 14135796c8dcSSimon Schubert nfetch = min (chunksize, fetchlimit - bufsize); 14145796c8dcSSimon Schubert 14155796c8dcSSimon Schubert if (*buffer == NULL) 14165796c8dcSSimon Schubert *buffer = (gdb_byte *) xmalloc (nfetch * width); 14175796c8dcSSimon Schubert else 14185796c8dcSSimon Schubert *buffer = (gdb_byte *) xrealloc (*buffer, 14195796c8dcSSimon Schubert (nfetch + bufsize) * width); 14205796c8dcSSimon Schubert 14215796c8dcSSimon Schubert bufptr = *buffer + bufsize * width; 14225796c8dcSSimon Schubert bufsize += nfetch; 14235796c8dcSSimon Schubert 14245796c8dcSSimon Schubert /* Read as much as we can. */ 14255796c8dcSSimon Schubert nfetch = partial_memory_read (addr, bufptr, nfetch * width, &errcode) 14265796c8dcSSimon Schubert / width; 14275796c8dcSSimon Schubert 14285796c8dcSSimon Schubert /* Scan this chunk for the null character that terminates the string 14295796c8dcSSimon Schubert to print. If found, we don't need to fetch any more. Note 14305796c8dcSSimon Schubert that bufptr is explicitly left pointing at the next character 14315796c8dcSSimon Schubert after the null character, or at the next character after the end 14325796c8dcSSimon Schubert of the buffer. */ 14335796c8dcSSimon Schubert 14345796c8dcSSimon Schubert limit = bufptr + nfetch * width; 14355796c8dcSSimon Schubert while (bufptr < limit) 14365796c8dcSSimon Schubert { 14375796c8dcSSimon Schubert unsigned long c; 14385796c8dcSSimon Schubert 14395796c8dcSSimon Schubert c = extract_unsigned_integer (bufptr, width, byte_order); 14405796c8dcSSimon Schubert addr += width; 14415796c8dcSSimon Schubert bufptr += width; 14425796c8dcSSimon Schubert if (c == 0) 14435796c8dcSSimon Schubert { 14445796c8dcSSimon Schubert /* We don't care about any error which happened after 14455796c8dcSSimon Schubert the NUL terminator. */ 14465796c8dcSSimon Schubert errcode = 0; 14475796c8dcSSimon Schubert found_nul = 1; 14485796c8dcSSimon Schubert break; 14495796c8dcSSimon Schubert } 14505796c8dcSSimon Schubert } 14515796c8dcSSimon Schubert } 14525796c8dcSSimon Schubert while (errcode == 0 /* no error */ 14535796c8dcSSimon Schubert && bufptr - *buffer < fetchlimit * width /* no overrun */ 14545796c8dcSSimon Schubert && !found_nul); /* haven't found NUL yet */ 14555796c8dcSSimon Schubert } 14565796c8dcSSimon Schubert else 14575796c8dcSSimon Schubert { /* Length of string is really 0! */ 14585796c8dcSSimon Schubert /* We always allocate *buffer. */ 14595796c8dcSSimon Schubert *buffer = bufptr = xmalloc (1); 14605796c8dcSSimon Schubert errcode = 0; 14615796c8dcSSimon Schubert } 14625796c8dcSSimon Schubert 14635796c8dcSSimon Schubert /* bufptr and addr now point immediately beyond the last byte which we 14645796c8dcSSimon Schubert consider part of the string (including a '\0' which ends the string). */ 14655796c8dcSSimon Schubert *bytes_read = bufptr - *buffer; 14665796c8dcSSimon Schubert 14675796c8dcSSimon Schubert QUIT; 14685796c8dcSSimon Schubert 14695796c8dcSSimon Schubert discard_cleanups (old_chain); 14705796c8dcSSimon Schubert 14715796c8dcSSimon Schubert return errcode; 14725796c8dcSSimon Schubert } 14735796c8dcSSimon Schubert 1474*a45ae5f8SJohn Marino /* Return true if print_wchar can display W without resorting to a 1475*a45ae5f8SJohn Marino numeric escape, false otherwise. */ 1476*a45ae5f8SJohn Marino 1477*a45ae5f8SJohn Marino static int 1478*a45ae5f8SJohn Marino wchar_printable (gdb_wchar_t w) 1479*a45ae5f8SJohn Marino { 1480*a45ae5f8SJohn Marino return (gdb_iswprint (w) 1481*a45ae5f8SJohn Marino || w == LCST ('\a') || w == LCST ('\b') 1482*a45ae5f8SJohn Marino || w == LCST ('\f') || w == LCST ('\n') 1483*a45ae5f8SJohn Marino || w == LCST ('\r') || w == LCST ('\t') 1484*a45ae5f8SJohn Marino || w == LCST ('\v')); 1485*a45ae5f8SJohn Marino } 1486*a45ae5f8SJohn Marino 1487*a45ae5f8SJohn Marino /* A helper function that converts the contents of STRING to wide 1488*a45ae5f8SJohn Marino characters and then appends them to OUTPUT. */ 1489*a45ae5f8SJohn Marino 1490*a45ae5f8SJohn Marino static void 1491*a45ae5f8SJohn Marino append_string_as_wide (const char *string, 1492*a45ae5f8SJohn Marino struct obstack *output) 1493*a45ae5f8SJohn Marino { 1494*a45ae5f8SJohn Marino for (; *string; ++string) 1495*a45ae5f8SJohn Marino { 1496*a45ae5f8SJohn Marino gdb_wchar_t w = gdb_btowc (*string); 1497*a45ae5f8SJohn Marino obstack_grow (output, &w, sizeof (gdb_wchar_t)); 1498*a45ae5f8SJohn Marino } 1499*a45ae5f8SJohn Marino } 1500*a45ae5f8SJohn Marino 1501*a45ae5f8SJohn Marino /* Print a wide character W to OUTPUT. ORIG is a pointer to the 1502*a45ae5f8SJohn Marino original (target) bytes representing the character, ORIG_LEN is the 1503*a45ae5f8SJohn Marino number of valid bytes. WIDTH is the number of bytes in a base 1504*a45ae5f8SJohn Marino characters of the type. OUTPUT is an obstack to which wide 1505*a45ae5f8SJohn Marino characters are emitted. QUOTER is a (narrow) character indicating 1506*a45ae5f8SJohn Marino the style of quotes surrounding the character to be printed. 1507*a45ae5f8SJohn Marino NEED_ESCAPE is an in/out flag which is used to track numeric 1508*a45ae5f8SJohn Marino escapes across calls. */ 1509*a45ae5f8SJohn Marino 1510*a45ae5f8SJohn Marino static void 1511*a45ae5f8SJohn Marino print_wchar (gdb_wint_t w, const gdb_byte *orig, 1512*a45ae5f8SJohn Marino int orig_len, int width, 1513*a45ae5f8SJohn Marino enum bfd_endian byte_order, 1514*a45ae5f8SJohn Marino struct obstack *output, 1515*a45ae5f8SJohn Marino int quoter, int *need_escapep) 1516*a45ae5f8SJohn Marino { 1517*a45ae5f8SJohn Marino int need_escape = *need_escapep; 1518*a45ae5f8SJohn Marino 1519*a45ae5f8SJohn Marino *need_escapep = 0; 1520*a45ae5f8SJohn Marino if (gdb_iswprint (w) && (!need_escape || (!gdb_iswdigit (w) 1521*a45ae5f8SJohn Marino && w != LCST ('8') 1522*a45ae5f8SJohn Marino && w != LCST ('9')))) 1523*a45ae5f8SJohn Marino { 1524*a45ae5f8SJohn Marino gdb_wchar_t wchar = w; 1525*a45ae5f8SJohn Marino 1526*a45ae5f8SJohn Marino if (w == gdb_btowc (quoter) || w == LCST ('\\')) 1527*a45ae5f8SJohn Marino obstack_grow_wstr (output, LCST ("\\")); 1528*a45ae5f8SJohn Marino obstack_grow (output, &wchar, sizeof (gdb_wchar_t)); 1529*a45ae5f8SJohn Marino } 1530*a45ae5f8SJohn Marino else 1531*a45ae5f8SJohn Marino { 1532*a45ae5f8SJohn Marino switch (w) 1533*a45ae5f8SJohn Marino { 1534*a45ae5f8SJohn Marino case LCST ('\a'): 1535*a45ae5f8SJohn Marino obstack_grow_wstr (output, LCST ("\\a")); 1536*a45ae5f8SJohn Marino break; 1537*a45ae5f8SJohn Marino case LCST ('\b'): 1538*a45ae5f8SJohn Marino obstack_grow_wstr (output, LCST ("\\b")); 1539*a45ae5f8SJohn Marino break; 1540*a45ae5f8SJohn Marino case LCST ('\f'): 1541*a45ae5f8SJohn Marino obstack_grow_wstr (output, LCST ("\\f")); 1542*a45ae5f8SJohn Marino break; 1543*a45ae5f8SJohn Marino case LCST ('\n'): 1544*a45ae5f8SJohn Marino obstack_grow_wstr (output, LCST ("\\n")); 1545*a45ae5f8SJohn Marino break; 1546*a45ae5f8SJohn Marino case LCST ('\r'): 1547*a45ae5f8SJohn Marino obstack_grow_wstr (output, LCST ("\\r")); 1548*a45ae5f8SJohn Marino break; 1549*a45ae5f8SJohn Marino case LCST ('\t'): 1550*a45ae5f8SJohn Marino obstack_grow_wstr (output, LCST ("\\t")); 1551*a45ae5f8SJohn Marino break; 1552*a45ae5f8SJohn Marino case LCST ('\v'): 1553*a45ae5f8SJohn Marino obstack_grow_wstr (output, LCST ("\\v")); 1554*a45ae5f8SJohn Marino break; 1555*a45ae5f8SJohn Marino default: 1556*a45ae5f8SJohn Marino { 1557*a45ae5f8SJohn Marino int i; 1558*a45ae5f8SJohn Marino 1559*a45ae5f8SJohn Marino for (i = 0; i + width <= orig_len; i += width) 1560*a45ae5f8SJohn Marino { 1561*a45ae5f8SJohn Marino char octal[30]; 1562*a45ae5f8SJohn Marino ULONGEST value; 1563*a45ae5f8SJohn Marino 1564*a45ae5f8SJohn Marino value = extract_unsigned_integer (&orig[i], width, 1565*a45ae5f8SJohn Marino byte_order); 1566*a45ae5f8SJohn Marino /* If the value fits in 3 octal digits, print it that 1567*a45ae5f8SJohn Marino way. Otherwise, print it as a hex escape. */ 1568*a45ae5f8SJohn Marino if (value <= 0777) 1569*a45ae5f8SJohn Marino sprintf (octal, "\\%.3o", (int) (value & 0777)); 1570*a45ae5f8SJohn Marino else 1571*a45ae5f8SJohn Marino sprintf (octal, "\\x%lx", (long) value); 1572*a45ae5f8SJohn Marino append_string_as_wide (octal, output); 1573*a45ae5f8SJohn Marino } 1574*a45ae5f8SJohn Marino /* If we somehow have extra bytes, print them now. */ 1575*a45ae5f8SJohn Marino while (i < orig_len) 1576*a45ae5f8SJohn Marino { 1577*a45ae5f8SJohn Marino char octal[5]; 1578*a45ae5f8SJohn Marino 1579*a45ae5f8SJohn Marino sprintf (octal, "\\%.3o", orig[i] & 0xff); 1580*a45ae5f8SJohn Marino append_string_as_wide (octal, output); 1581*a45ae5f8SJohn Marino ++i; 1582*a45ae5f8SJohn Marino } 1583*a45ae5f8SJohn Marino 1584*a45ae5f8SJohn Marino *need_escapep = 1; 1585*a45ae5f8SJohn Marino } 1586*a45ae5f8SJohn Marino break; 1587*a45ae5f8SJohn Marino } 1588*a45ae5f8SJohn Marino } 1589*a45ae5f8SJohn Marino } 1590*a45ae5f8SJohn Marino 1591*a45ae5f8SJohn Marino /* Print the character C on STREAM as part of the contents of a 1592*a45ae5f8SJohn Marino literal string whose delimiter is QUOTER. ENCODING names the 1593*a45ae5f8SJohn Marino encoding of C. */ 1594*a45ae5f8SJohn Marino 1595*a45ae5f8SJohn Marino void 1596*a45ae5f8SJohn Marino generic_emit_char (int c, struct type *type, struct ui_file *stream, 1597*a45ae5f8SJohn Marino int quoter, const char *encoding) 1598*a45ae5f8SJohn Marino { 1599*a45ae5f8SJohn Marino enum bfd_endian byte_order 1600*a45ae5f8SJohn Marino = gdbarch_byte_order (get_type_arch (type)); 1601*a45ae5f8SJohn Marino struct obstack wchar_buf, output; 1602*a45ae5f8SJohn Marino struct cleanup *cleanups; 1603*a45ae5f8SJohn Marino gdb_byte *buf; 1604*a45ae5f8SJohn Marino struct wchar_iterator *iter; 1605*a45ae5f8SJohn Marino int need_escape = 0; 1606*a45ae5f8SJohn Marino 1607*a45ae5f8SJohn Marino buf = alloca (TYPE_LENGTH (type)); 1608*a45ae5f8SJohn Marino pack_long (buf, type, c); 1609*a45ae5f8SJohn Marino 1610*a45ae5f8SJohn Marino iter = make_wchar_iterator (buf, TYPE_LENGTH (type), 1611*a45ae5f8SJohn Marino encoding, TYPE_LENGTH (type)); 1612*a45ae5f8SJohn Marino cleanups = make_cleanup_wchar_iterator (iter); 1613*a45ae5f8SJohn Marino 1614*a45ae5f8SJohn Marino /* This holds the printable form of the wchar_t data. */ 1615*a45ae5f8SJohn Marino obstack_init (&wchar_buf); 1616*a45ae5f8SJohn Marino make_cleanup_obstack_free (&wchar_buf); 1617*a45ae5f8SJohn Marino 1618*a45ae5f8SJohn Marino while (1) 1619*a45ae5f8SJohn Marino { 1620*a45ae5f8SJohn Marino int num_chars; 1621*a45ae5f8SJohn Marino gdb_wchar_t *chars; 1622*a45ae5f8SJohn Marino const gdb_byte *buf; 1623*a45ae5f8SJohn Marino size_t buflen; 1624*a45ae5f8SJohn Marino int print_escape = 1; 1625*a45ae5f8SJohn Marino enum wchar_iterate_result result; 1626*a45ae5f8SJohn Marino 1627*a45ae5f8SJohn Marino num_chars = wchar_iterate (iter, &result, &chars, &buf, &buflen); 1628*a45ae5f8SJohn Marino if (num_chars < 0) 1629*a45ae5f8SJohn Marino break; 1630*a45ae5f8SJohn Marino if (num_chars > 0) 1631*a45ae5f8SJohn Marino { 1632*a45ae5f8SJohn Marino /* If all characters are printable, print them. Otherwise, 1633*a45ae5f8SJohn Marino we're going to have to print an escape sequence. We 1634*a45ae5f8SJohn Marino check all characters because we want to print the target 1635*a45ae5f8SJohn Marino bytes in the escape sequence, and we don't know character 1636*a45ae5f8SJohn Marino boundaries there. */ 1637*a45ae5f8SJohn Marino int i; 1638*a45ae5f8SJohn Marino 1639*a45ae5f8SJohn Marino print_escape = 0; 1640*a45ae5f8SJohn Marino for (i = 0; i < num_chars; ++i) 1641*a45ae5f8SJohn Marino if (!wchar_printable (chars[i])) 1642*a45ae5f8SJohn Marino { 1643*a45ae5f8SJohn Marino print_escape = 1; 1644*a45ae5f8SJohn Marino break; 1645*a45ae5f8SJohn Marino } 1646*a45ae5f8SJohn Marino 1647*a45ae5f8SJohn Marino if (!print_escape) 1648*a45ae5f8SJohn Marino { 1649*a45ae5f8SJohn Marino for (i = 0; i < num_chars; ++i) 1650*a45ae5f8SJohn Marino print_wchar (chars[i], buf, buflen, 1651*a45ae5f8SJohn Marino TYPE_LENGTH (type), byte_order, 1652*a45ae5f8SJohn Marino &wchar_buf, quoter, &need_escape); 1653*a45ae5f8SJohn Marino } 1654*a45ae5f8SJohn Marino } 1655*a45ae5f8SJohn Marino 1656*a45ae5f8SJohn Marino /* This handles the NUM_CHARS == 0 case as well. */ 1657*a45ae5f8SJohn Marino if (print_escape) 1658*a45ae5f8SJohn Marino print_wchar (gdb_WEOF, buf, buflen, TYPE_LENGTH (type), 1659*a45ae5f8SJohn Marino byte_order, &wchar_buf, quoter, &need_escape); 1660*a45ae5f8SJohn Marino } 1661*a45ae5f8SJohn Marino 1662*a45ae5f8SJohn Marino /* The output in the host encoding. */ 1663*a45ae5f8SJohn Marino obstack_init (&output); 1664*a45ae5f8SJohn Marino make_cleanup_obstack_free (&output); 1665*a45ae5f8SJohn Marino 1666*a45ae5f8SJohn Marino convert_between_encodings (INTERMEDIATE_ENCODING, host_charset (), 1667*a45ae5f8SJohn Marino obstack_base (&wchar_buf), 1668*a45ae5f8SJohn Marino obstack_object_size (&wchar_buf), 1669*a45ae5f8SJohn Marino 1, &output, translit_char); 1670*a45ae5f8SJohn Marino obstack_1grow (&output, '\0'); 1671*a45ae5f8SJohn Marino 1672*a45ae5f8SJohn Marino fputs_filtered (obstack_base (&output), stream); 1673*a45ae5f8SJohn Marino 1674*a45ae5f8SJohn Marino do_cleanups (cleanups); 1675*a45ae5f8SJohn Marino } 1676*a45ae5f8SJohn Marino 1677*a45ae5f8SJohn Marino /* Print the character string STRING, printing at most LENGTH 1678*a45ae5f8SJohn Marino characters. LENGTH is -1 if the string is nul terminated. TYPE is 1679*a45ae5f8SJohn Marino the type of each character. OPTIONS holds the printing options; 1680*a45ae5f8SJohn Marino printing stops early if the number hits print_max; repeat counts 1681*a45ae5f8SJohn Marino are printed as appropriate. Print ellipses at the end if we had to 1682*a45ae5f8SJohn Marino stop before printing LENGTH characters, or if FORCE_ELLIPSES. 1683*a45ae5f8SJohn Marino QUOTE_CHAR is the character to print at each end of the string. If 1684*a45ae5f8SJohn Marino C_STYLE_TERMINATOR is true, and the last character is 0, then it is 1685*a45ae5f8SJohn Marino omitted. */ 1686*a45ae5f8SJohn Marino 1687*a45ae5f8SJohn Marino void 1688*a45ae5f8SJohn Marino generic_printstr (struct ui_file *stream, struct type *type, 1689*a45ae5f8SJohn Marino const gdb_byte *string, unsigned int length, 1690*a45ae5f8SJohn Marino const char *encoding, int force_ellipses, 1691*a45ae5f8SJohn Marino int quote_char, int c_style_terminator, 1692*a45ae5f8SJohn Marino const struct value_print_options *options) 1693*a45ae5f8SJohn Marino { 1694*a45ae5f8SJohn Marino enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type)); 1695*a45ae5f8SJohn Marino unsigned int i; 1696*a45ae5f8SJohn Marino unsigned int things_printed = 0; 1697*a45ae5f8SJohn Marino int in_quotes = 0; 1698*a45ae5f8SJohn Marino int need_comma = 0; 1699*a45ae5f8SJohn Marino int width = TYPE_LENGTH (type); 1700*a45ae5f8SJohn Marino struct obstack wchar_buf, output; 1701*a45ae5f8SJohn Marino struct cleanup *cleanup; 1702*a45ae5f8SJohn Marino struct wchar_iterator *iter; 1703*a45ae5f8SJohn Marino int finished = 0; 1704*a45ae5f8SJohn Marino int need_escape = 0; 1705*a45ae5f8SJohn Marino gdb_wchar_t wide_quote_char = gdb_btowc (quote_char); 1706*a45ae5f8SJohn Marino 1707*a45ae5f8SJohn Marino if (length == -1) 1708*a45ae5f8SJohn Marino { 1709*a45ae5f8SJohn Marino unsigned long current_char = 1; 1710*a45ae5f8SJohn Marino 1711*a45ae5f8SJohn Marino for (i = 0; current_char; ++i) 1712*a45ae5f8SJohn Marino { 1713*a45ae5f8SJohn Marino QUIT; 1714*a45ae5f8SJohn Marino current_char = extract_unsigned_integer (string + i * width, 1715*a45ae5f8SJohn Marino width, byte_order); 1716*a45ae5f8SJohn Marino } 1717*a45ae5f8SJohn Marino length = i; 1718*a45ae5f8SJohn Marino } 1719*a45ae5f8SJohn Marino 1720*a45ae5f8SJohn Marino /* If the string was not truncated due to `set print elements', and 1721*a45ae5f8SJohn Marino the last byte of it is a null, we don't print that, in 1722*a45ae5f8SJohn Marino traditional C style. */ 1723*a45ae5f8SJohn Marino if (c_style_terminator 1724*a45ae5f8SJohn Marino && !force_ellipses 1725*a45ae5f8SJohn Marino && length > 0 1726*a45ae5f8SJohn Marino && (extract_unsigned_integer (string + (length - 1) * width, 1727*a45ae5f8SJohn Marino width, byte_order) == 0)) 1728*a45ae5f8SJohn Marino length--; 1729*a45ae5f8SJohn Marino 1730*a45ae5f8SJohn Marino if (length == 0) 1731*a45ae5f8SJohn Marino { 1732*a45ae5f8SJohn Marino fputs_filtered ("\"\"", stream); 1733*a45ae5f8SJohn Marino return; 1734*a45ae5f8SJohn Marino } 1735*a45ae5f8SJohn Marino 1736*a45ae5f8SJohn Marino /* Arrange to iterate over the characters, in wchar_t form. */ 1737*a45ae5f8SJohn Marino iter = make_wchar_iterator (string, length * width, encoding, width); 1738*a45ae5f8SJohn Marino cleanup = make_cleanup_wchar_iterator (iter); 1739*a45ae5f8SJohn Marino 1740*a45ae5f8SJohn Marino /* WCHAR_BUF is the obstack we use to represent the string in 1741*a45ae5f8SJohn Marino wchar_t form. */ 1742*a45ae5f8SJohn Marino obstack_init (&wchar_buf); 1743*a45ae5f8SJohn Marino make_cleanup_obstack_free (&wchar_buf); 1744*a45ae5f8SJohn Marino 1745*a45ae5f8SJohn Marino while (!finished && things_printed < options->print_max) 1746*a45ae5f8SJohn Marino { 1747*a45ae5f8SJohn Marino int num_chars; 1748*a45ae5f8SJohn Marino enum wchar_iterate_result result; 1749*a45ae5f8SJohn Marino gdb_wchar_t *chars; 1750*a45ae5f8SJohn Marino const gdb_byte *buf; 1751*a45ae5f8SJohn Marino size_t buflen; 1752*a45ae5f8SJohn Marino 1753*a45ae5f8SJohn Marino QUIT; 1754*a45ae5f8SJohn Marino 1755*a45ae5f8SJohn Marino if (need_comma) 1756*a45ae5f8SJohn Marino { 1757*a45ae5f8SJohn Marino obstack_grow_wstr (&wchar_buf, LCST (", ")); 1758*a45ae5f8SJohn Marino need_comma = 0; 1759*a45ae5f8SJohn Marino } 1760*a45ae5f8SJohn Marino 1761*a45ae5f8SJohn Marino num_chars = wchar_iterate (iter, &result, &chars, &buf, &buflen); 1762*a45ae5f8SJohn Marino /* We only look at repetitions when we were able to convert a 1763*a45ae5f8SJohn Marino single character in isolation. This makes the code simpler 1764*a45ae5f8SJohn Marino and probably does the sensible thing in the majority of 1765*a45ae5f8SJohn Marino cases. */ 1766*a45ae5f8SJohn Marino while (num_chars == 1 && things_printed < options->print_max) 1767*a45ae5f8SJohn Marino { 1768*a45ae5f8SJohn Marino /* Count the number of repetitions. */ 1769*a45ae5f8SJohn Marino unsigned int reps = 0; 1770*a45ae5f8SJohn Marino gdb_wchar_t current_char = chars[0]; 1771*a45ae5f8SJohn Marino const gdb_byte *orig_buf = buf; 1772*a45ae5f8SJohn Marino int orig_len = buflen; 1773*a45ae5f8SJohn Marino 1774*a45ae5f8SJohn Marino if (need_comma) 1775*a45ae5f8SJohn Marino { 1776*a45ae5f8SJohn Marino obstack_grow_wstr (&wchar_buf, LCST (", ")); 1777*a45ae5f8SJohn Marino need_comma = 0; 1778*a45ae5f8SJohn Marino } 1779*a45ae5f8SJohn Marino 1780*a45ae5f8SJohn Marino while (num_chars == 1 && current_char == chars[0]) 1781*a45ae5f8SJohn Marino { 1782*a45ae5f8SJohn Marino num_chars = wchar_iterate (iter, &result, &chars, 1783*a45ae5f8SJohn Marino &buf, &buflen); 1784*a45ae5f8SJohn Marino ++reps; 1785*a45ae5f8SJohn Marino } 1786*a45ae5f8SJohn Marino 1787*a45ae5f8SJohn Marino /* Emit CURRENT_CHAR according to the repetition count and 1788*a45ae5f8SJohn Marino options. */ 1789*a45ae5f8SJohn Marino if (reps > options->repeat_count_threshold) 1790*a45ae5f8SJohn Marino { 1791*a45ae5f8SJohn Marino if (in_quotes) 1792*a45ae5f8SJohn Marino { 1793*a45ae5f8SJohn Marino if (options->inspect_it) 1794*a45ae5f8SJohn Marino obstack_grow_wstr (&wchar_buf, LCST ("\\")); 1795*a45ae5f8SJohn Marino obstack_grow (&wchar_buf, &wide_quote_char, 1796*a45ae5f8SJohn Marino sizeof (gdb_wchar_t)); 1797*a45ae5f8SJohn Marino obstack_grow_wstr (&wchar_buf, LCST (", ")); 1798*a45ae5f8SJohn Marino in_quotes = 0; 1799*a45ae5f8SJohn Marino } 1800*a45ae5f8SJohn Marino obstack_grow_wstr (&wchar_buf, LCST ("'")); 1801*a45ae5f8SJohn Marino need_escape = 0; 1802*a45ae5f8SJohn Marino print_wchar (current_char, orig_buf, orig_len, width, 1803*a45ae5f8SJohn Marino byte_order, &wchar_buf, '\'', &need_escape); 1804*a45ae5f8SJohn Marino obstack_grow_wstr (&wchar_buf, LCST ("'")); 1805*a45ae5f8SJohn Marino { 1806*a45ae5f8SJohn Marino /* Painful gyrations. */ 1807*a45ae5f8SJohn Marino int j; 1808*a45ae5f8SJohn Marino char *s = xstrprintf (_(" <repeats %u times>"), reps); 1809*a45ae5f8SJohn Marino 1810*a45ae5f8SJohn Marino for (j = 0; s[j]; ++j) 1811*a45ae5f8SJohn Marino { 1812*a45ae5f8SJohn Marino gdb_wchar_t w = gdb_btowc (s[j]); 1813*a45ae5f8SJohn Marino obstack_grow (&wchar_buf, &w, sizeof (gdb_wchar_t)); 1814*a45ae5f8SJohn Marino } 1815*a45ae5f8SJohn Marino xfree (s); 1816*a45ae5f8SJohn Marino } 1817*a45ae5f8SJohn Marino things_printed += options->repeat_count_threshold; 1818*a45ae5f8SJohn Marino need_comma = 1; 1819*a45ae5f8SJohn Marino } 1820*a45ae5f8SJohn Marino else 1821*a45ae5f8SJohn Marino { 1822*a45ae5f8SJohn Marino /* Saw the character one or more times, but fewer than 1823*a45ae5f8SJohn Marino the repetition threshold. */ 1824*a45ae5f8SJohn Marino if (!in_quotes) 1825*a45ae5f8SJohn Marino { 1826*a45ae5f8SJohn Marino if (options->inspect_it) 1827*a45ae5f8SJohn Marino obstack_grow_wstr (&wchar_buf, LCST ("\\")); 1828*a45ae5f8SJohn Marino obstack_grow (&wchar_buf, &wide_quote_char, 1829*a45ae5f8SJohn Marino sizeof (gdb_wchar_t)); 1830*a45ae5f8SJohn Marino in_quotes = 1; 1831*a45ae5f8SJohn Marino need_escape = 0; 1832*a45ae5f8SJohn Marino } 1833*a45ae5f8SJohn Marino 1834*a45ae5f8SJohn Marino while (reps-- > 0) 1835*a45ae5f8SJohn Marino { 1836*a45ae5f8SJohn Marino print_wchar (current_char, orig_buf, 1837*a45ae5f8SJohn Marino orig_len, width, 1838*a45ae5f8SJohn Marino byte_order, &wchar_buf, 1839*a45ae5f8SJohn Marino quote_char, &need_escape); 1840*a45ae5f8SJohn Marino ++things_printed; 1841*a45ae5f8SJohn Marino } 1842*a45ae5f8SJohn Marino } 1843*a45ae5f8SJohn Marino } 1844*a45ae5f8SJohn Marino 1845*a45ae5f8SJohn Marino /* NUM_CHARS and the other outputs from wchar_iterate are valid 1846*a45ae5f8SJohn Marino here regardless of which branch was taken above. */ 1847*a45ae5f8SJohn Marino if (num_chars < 0) 1848*a45ae5f8SJohn Marino { 1849*a45ae5f8SJohn Marino /* Hit EOF. */ 1850*a45ae5f8SJohn Marino finished = 1; 1851*a45ae5f8SJohn Marino break; 1852*a45ae5f8SJohn Marino } 1853*a45ae5f8SJohn Marino 1854*a45ae5f8SJohn Marino switch (result) 1855*a45ae5f8SJohn Marino { 1856*a45ae5f8SJohn Marino case wchar_iterate_invalid: 1857*a45ae5f8SJohn Marino if (!in_quotes) 1858*a45ae5f8SJohn Marino { 1859*a45ae5f8SJohn Marino if (options->inspect_it) 1860*a45ae5f8SJohn Marino obstack_grow_wstr (&wchar_buf, LCST ("\\")); 1861*a45ae5f8SJohn Marino obstack_grow (&wchar_buf, &wide_quote_char, 1862*a45ae5f8SJohn Marino sizeof (gdb_wchar_t)); 1863*a45ae5f8SJohn Marino in_quotes = 1; 1864*a45ae5f8SJohn Marino } 1865*a45ae5f8SJohn Marino need_escape = 0; 1866*a45ae5f8SJohn Marino print_wchar (gdb_WEOF, buf, buflen, width, byte_order, 1867*a45ae5f8SJohn Marino &wchar_buf, quote_char, &need_escape); 1868*a45ae5f8SJohn Marino break; 1869*a45ae5f8SJohn Marino 1870*a45ae5f8SJohn Marino case wchar_iterate_incomplete: 1871*a45ae5f8SJohn Marino if (in_quotes) 1872*a45ae5f8SJohn Marino { 1873*a45ae5f8SJohn Marino if (options->inspect_it) 1874*a45ae5f8SJohn Marino obstack_grow_wstr (&wchar_buf, LCST ("\\")); 1875*a45ae5f8SJohn Marino obstack_grow (&wchar_buf, &wide_quote_char, 1876*a45ae5f8SJohn Marino sizeof (gdb_wchar_t)); 1877*a45ae5f8SJohn Marino obstack_grow_wstr (&wchar_buf, LCST (",")); 1878*a45ae5f8SJohn Marino in_quotes = 0; 1879*a45ae5f8SJohn Marino } 1880*a45ae5f8SJohn Marino obstack_grow_wstr (&wchar_buf, 1881*a45ae5f8SJohn Marino LCST (" <incomplete sequence ")); 1882*a45ae5f8SJohn Marino print_wchar (gdb_WEOF, buf, buflen, width, 1883*a45ae5f8SJohn Marino byte_order, &wchar_buf, 1884*a45ae5f8SJohn Marino 0, &need_escape); 1885*a45ae5f8SJohn Marino obstack_grow_wstr (&wchar_buf, LCST (">")); 1886*a45ae5f8SJohn Marino finished = 1; 1887*a45ae5f8SJohn Marino break; 1888*a45ae5f8SJohn Marino } 1889*a45ae5f8SJohn Marino } 1890*a45ae5f8SJohn Marino 1891*a45ae5f8SJohn Marino /* Terminate the quotes if necessary. */ 1892*a45ae5f8SJohn Marino if (in_quotes) 1893*a45ae5f8SJohn Marino { 1894*a45ae5f8SJohn Marino if (options->inspect_it) 1895*a45ae5f8SJohn Marino obstack_grow_wstr (&wchar_buf, LCST ("\\")); 1896*a45ae5f8SJohn Marino obstack_grow (&wchar_buf, &wide_quote_char, 1897*a45ae5f8SJohn Marino sizeof (gdb_wchar_t)); 1898*a45ae5f8SJohn Marino } 1899*a45ae5f8SJohn Marino 1900*a45ae5f8SJohn Marino if (force_ellipses || !finished) 1901*a45ae5f8SJohn Marino obstack_grow_wstr (&wchar_buf, LCST ("...")); 1902*a45ae5f8SJohn Marino 1903*a45ae5f8SJohn Marino /* OUTPUT is where we collect `char's for printing. */ 1904*a45ae5f8SJohn Marino obstack_init (&output); 1905*a45ae5f8SJohn Marino make_cleanup_obstack_free (&output); 1906*a45ae5f8SJohn Marino 1907*a45ae5f8SJohn Marino convert_between_encodings (INTERMEDIATE_ENCODING, host_charset (), 1908*a45ae5f8SJohn Marino obstack_base (&wchar_buf), 1909*a45ae5f8SJohn Marino obstack_object_size (&wchar_buf), 1910*a45ae5f8SJohn Marino 1, &output, translit_char); 1911*a45ae5f8SJohn Marino obstack_1grow (&output, '\0'); 1912*a45ae5f8SJohn Marino 1913*a45ae5f8SJohn Marino fputs_filtered (obstack_base (&output), stream); 1914*a45ae5f8SJohn Marino 1915*a45ae5f8SJohn Marino do_cleanups (cleanup); 1916*a45ae5f8SJohn Marino } 1917*a45ae5f8SJohn Marino 19185796c8dcSSimon Schubert /* Print a string from the inferior, starting at ADDR and printing up to LEN 19195796c8dcSSimon Schubert characters, of WIDTH bytes a piece, to STREAM. If LEN is -1, printing 19205796c8dcSSimon Schubert stops at the first null byte, otherwise printing proceeds (including null 19215796c8dcSSimon Schubert bytes) until either print_max or LEN characters have been printed, 1922c50c785cSJohn Marino whichever is smaller. ENCODING is the name of the string's 1923c50c785cSJohn Marino encoding. It can be NULL, in which case the target encoding is 1924c50c785cSJohn Marino assumed. */ 19255796c8dcSSimon Schubert 19265796c8dcSSimon Schubert int 1927c50c785cSJohn Marino val_print_string (struct type *elttype, const char *encoding, 1928c50c785cSJohn Marino CORE_ADDR addr, int len, 19295796c8dcSSimon Schubert struct ui_file *stream, 19305796c8dcSSimon Schubert const struct value_print_options *options) 19315796c8dcSSimon Schubert { 19325796c8dcSSimon Schubert int force_ellipsis = 0; /* Force ellipsis to be printed if nonzero. */ 19335796c8dcSSimon Schubert int errcode; /* Errno returned from bad reads. */ 1934c50c785cSJohn Marino int found_nul; /* Non-zero if we found the nul char. */ 19355796c8dcSSimon Schubert unsigned int fetchlimit; /* Maximum number of chars to print. */ 19365796c8dcSSimon Schubert int bytes_read; 19375796c8dcSSimon Schubert gdb_byte *buffer = NULL; /* Dynamically growable fetch buffer. */ 19385796c8dcSSimon Schubert struct cleanup *old_chain = NULL; /* Top of the old cleanup chain. */ 19395796c8dcSSimon Schubert struct gdbarch *gdbarch = get_type_arch (elttype); 19405796c8dcSSimon Schubert enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 19415796c8dcSSimon Schubert int width = TYPE_LENGTH (elttype); 19425796c8dcSSimon Schubert 19435796c8dcSSimon Schubert /* First we need to figure out the limit on the number of characters we are 19445796c8dcSSimon Schubert going to attempt to fetch and print. This is actually pretty simple. If 19455796c8dcSSimon Schubert LEN >= zero, then the limit is the minimum of LEN and print_max. If 19465796c8dcSSimon Schubert LEN is -1, then the limit is print_max. This is true regardless of 19475796c8dcSSimon Schubert whether print_max is zero, UINT_MAX (unlimited), or something in between, 19485796c8dcSSimon Schubert because finding the null byte (or available memory) is what actually 19495796c8dcSSimon Schubert limits the fetch. */ 19505796c8dcSSimon Schubert 1951c50c785cSJohn Marino fetchlimit = (len == -1 ? options->print_max : min (len, 1952c50c785cSJohn Marino options->print_max)); 19535796c8dcSSimon Schubert 19545796c8dcSSimon Schubert errcode = read_string (addr, len, width, fetchlimit, byte_order, 19555796c8dcSSimon Schubert &buffer, &bytes_read); 19565796c8dcSSimon Schubert old_chain = make_cleanup (xfree, buffer); 19575796c8dcSSimon Schubert 19585796c8dcSSimon Schubert addr += bytes_read; 19595796c8dcSSimon Schubert 1960c50c785cSJohn Marino /* We now have either successfully filled the buffer to fetchlimit, 1961c50c785cSJohn Marino or terminated early due to an error or finding a null char when 1962c50c785cSJohn Marino LEN is -1. */ 19635796c8dcSSimon Schubert 19645796c8dcSSimon Schubert /* Determine found_nul by looking at the last character read. */ 19655796c8dcSSimon Schubert found_nul = extract_unsigned_integer (buffer + bytes_read - width, width, 19665796c8dcSSimon Schubert byte_order) == 0; 19675796c8dcSSimon Schubert if (len == -1 && !found_nul) 19685796c8dcSSimon Schubert { 19695796c8dcSSimon Schubert gdb_byte *peekbuf; 19705796c8dcSSimon Schubert 19715796c8dcSSimon Schubert /* We didn't find a NUL terminator we were looking for. Attempt 19725796c8dcSSimon Schubert to peek at the next character. If not successful, or it is not 19735796c8dcSSimon Schubert a null byte, then force ellipsis to be printed. */ 19745796c8dcSSimon Schubert 19755796c8dcSSimon Schubert peekbuf = (gdb_byte *) alloca (width); 19765796c8dcSSimon Schubert 19775796c8dcSSimon Schubert if (target_read_memory (addr, peekbuf, width) == 0 19785796c8dcSSimon Schubert && extract_unsigned_integer (peekbuf, width, byte_order) != 0) 19795796c8dcSSimon Schubert force_ellipsis = 1; 19805796c8dcSSimon Schubert } 19815796c8dcSSimon Schubert else if ((len >= 0 && errcode != 0) || (len > bytes_read / width)) 19825796c8dcSSimon Schubert { 19835796c8dcSSimon Schubert /* Getting an error when we have a requested length, or fetching less 19845796c8dcSSimon Schubert than the number of characters actually requested, always make us 19855796c8dcSSimon Schubert print ellipsis. */ 19865796c8dcSSimon Schubert force_ellipsis = 1; 19875796c8dcSSimon Schubert } 19885796c8dcSSimon Schubert 19895796c8dcSSimon Schubert /* If we get an error before fetching anything, don't print a string. 19905796c8dcSSimon Schubert But if we fetch something and then get an error, print the string 19915796c8dcSSimon Schubert and then the error message. */ 19925796c8dcSSimon Schubert if (errcode == 0 || bytes_read > 0) 19935796c8dcSSimon Schubert { 19945796c8dcSSimon Schubert if (options->addressprint) 19955796c8dcSSimon Schubert { 19965796c8dcSSimon Schubert fputs_filtered (" ", stream); 19975796c8dcSSimon Schubert } 1998cf7f2e2dSJohn Marino LA_PRINT_STRING (stream, elttype, buffer, bytes_read / width, 1999c50c785cSJohn Marino encoding, force_ellipsis, options); 20005796c8dcSSimon Schubert } 20015796c8dcSSimon Schubert 20025796c8dcSSimon Schubert if (errcode != 0) 20035796c8dcSSimon Schubert { 20045796c8dcSSimon Schubert if (errcode == EIO) 20055796c8dcSSimon Schubert { 20065796c8dcSSimon Schubert fprintf_filtered (stream, " <Address "); 20075796c8dcSSimon Schubert fputs_filtered (paddress (gdbarch, addr), stream); 20085796c8dcSSimon Schubert fprintf_filtered (stream, " out of bounds>"); 20095796c8dcSSimon Schubert } 20105796c8dcSSimon Schubert else 20115796c8dcSSimon Schubert { 20125796c8dcSSimon Schubert fprintf_filtered (stream, " <Error reading address "); 20135796c8dcSSimon Schubert fputs_filtered (paddress (gdbarch, addr), stream); 20145796c8dcSSimon Schubert fprintf_filtered (stream, ": %s>", safe_strerror (errcode)); 20155796c8dcSSimon Schubert } 20165796c8dcSSimon Schubert } 20175796c8dcSSimon Schubert 20185796c8dcSSimon Schubert gdb_flush (stream); 20195796c8dcSSimon Schubert do_cleanups (old_chain); 20205796c8dcSSimon Schubert 20215796c8dcSSimon Schubert return (bytes_read / width); 20225796c8dcSSimon Schubert } 20235796c8dcSSimon Schubert 20245796c8dcSSimon Schubert 20255796c8dcSSimon Schubert /* The 'set input-radix' command writes to this auxiliary variable. 20265796c8dcSSimon Schubert If the requested radix is valid, INPUT_RADIX is updated; otherwise, 20275796c8dcSSimon Schubert it is left unchanged. */ 20285796c8dcSSimon Schubert 20295796c8dcSSimon Schubert static unsigned input_radix_1 = 10; 20305796c8dcSSimon Schubert 20315796c8dcSSimon Schubert /* Validate an input or output radix setting, and make sure the user 20325796c8dcSSimon Schubert knows what they really did here. Radix setting is confusing, e.g. 20335796c8dcSSimon Schubert setting the input radix to "10" never changes it! */ 20345796c8dcSSimon Schubert 20355796c8dcSSimon Schubert static void 20365796c8dcSSimon Schubert set_input_radix (char *args, int from_tty, struct cmd_list_element *c) 20375796c8dcSSimon Schubert { 20385796c8dcSSimon Schubert set_input_radix_1 (from_tty, input_radix_1); 20395796c8dcSSimon Schubert } 20405796c8dcSSimon Schubert 20415796c8dcSSimon Schubert static void 20425796c8dcSSimon Schubert set_input_radix_1 (int from_tty, unsigned radix) 20435796c8dcSSimon Schubert { 20445796c8dcSSimon Schubert /* We don't currently disallow any input radix except 0 or 1, which don't 20455796c8dcSSimon Schubert make any mathematical sense. In theory, we can deal with any input 20465796c8dcSSimon Schubert radix greater than 1, even if we don't have unique digits for every 20475796c8dcSSimon Schubert value from 0 to radix-1, but in practice we lose on large radix values. 20485796c8dcSSimon Schubert We should either fix the lossage or restrict the radix range more. 20495796c8dcSSimon Schubert (FIXME). */ 20505796c8dcSSimon Schubert 20515796c8dcSSimon Schubert if (radix < 2) 20525796c8dcSSimon Schubert { 20535796c8dcSSimon Schubert input_radix_1 = input_radix; 20545796c8dcSSimon Schubert error (_("Nonsense input radix ``decimal %u''; input radix unchanged."), 20555796c8dcSSimon Schubert radix); 20565796c8dcSSimon Schubert } 20575796c8dcSSimon Schubert input_radix_1 = input_radix = radix; 20585796c8dcSSimon Schubert if (from_tty) 20595796c8dcSSimon Schubert { 2060c50c785cSJohn Marino printf_filtered (_("Input radix now set to " 2061c50c785cSJohn Marino "decimal %u, hex %x, octal %o.\n"), 20625796c8dcSSimon Schubert radix, radix, radix); 20635796c8dcSSimon Schubert } 20645796c8dcSSimon Schubert } 20655796c8dcSSimon Schubert 20665796c8dcSSimon Schubert /* The 'set output-radix' command writes to this auxiliary variable. 20675796c8dcSSimon Schubert If the requested radix is valid, OUTPUT_RADIX is updated, 20685796c8dcSSimon Schubert otherwise, it is left unchanged. */ 20695796c8dcSSimon Schubert 20705796c8dcSSimon Schubert static unsigned output_radix_1 = 10; 20715796c8dcSSimon Schubert 20725796c8dcSSimon Schubert static void 20735796c8dcSSimon Schubert set_output_radix (char *args, int from_tty, struct cmd_list_element *c) 20745796c8dcSSimon Schubert { 20755796c8dcSSimon Schubert set_output_radix_1 (from_tty, output_radix_1); 20765796c8dcSSimon Schubert } 20775796c8dcSSimon Schubert 20785796c8dcSSimon Schubert static void 20795796c8dcSSimon Schubert set_output_radix_1 (int from_tty, unsigned radix) 20805796c8dcSSimon Schubert { 20815796c8dcSSimon Schubert /* Validate the radix and disallow ones that we aren't prepared to 20825796c8dcSSimon Schubert handle correctly, leaving the radix unchanged. */ 20835796c8dcSSimon Schubert switch (radix) 20845796c8dcSSimon Schubert { 20855796c8dcSSimon Schubert case 16: 20865796c8dcSSimon Schubert user_print_options.output_format = 'x'; /* hex */ 20875796c8dcSSimon Schubert break; 20885796c8dcSSimon Schubert case 10: 20895796c8dcSSimon Schubert user_print_options.output_format = 0; /* decimal */ 20905796c8dcSSimon Schubert break; 20915796c8dcSSimon Schubert case 8: 20925796c8dcSSimon Schubert user_print_options.output_format = 'o'; /* octal */ 20935796c8dcSSimon Schubert break; 20945796c8dcSSimon Schubert default: 20955796c8dcSSimon Schubert output_radix_1 = output_radix; 2096c50c785cSJohn Marino error (_("Unsupported output radix ``decimal %u''; " 2097c50c785cSJohn Marino "output radix unchanged."), 20985796c8dcSSimon Schubert radix); 20995796c8dcSSimon Schubert } 21005796c8dcSSimon Schubert output_radix_1 = output_radix = radix; 21015796c8dcSSimon Schubert if (from_tty) 21025796c8dcSSimon Schubert { 2103c50c785cSJohn Marino printf_filtered (_("Output radix now set to " 2104c50c785cSJohn Marino "decimal %u, hex %x, octal %o.\n"), 21055796c8dcSSimon Schubert radix, radix, radix); 21065796c8dcSSimon Schubert } 21075796c8dcSSimon Schubert } 21085796c8dcSSimon Schubert 21095796c8dcSSimon Schubert /* Set both the input and output radix at once. Try to set the output radix 21105796c8dcSSimon Schubert first, since it has the most restrictive range. An radix that is valid as 21115796c8dcSSimon Schubert an output radix is also valid as an input radix. 21125796c8dcSSimon Schubert 21135796c8dcSSimon Schubert It may be useful to have an unusual input radix. If the user wishes to 21145796c8dcSSimon Schubert set an input radix that is not valid as an output radix, he needs to use 21155796c8dcSSimon Schubert the 'set input-radix' command. */ 21165796c8dcSSimon Schubert 21175796c8dcSSimon Schubert static void 21185796c8dcSSimon Schubert set_radix (char *arg, int from_tty) 21195796c8dcSSimon Schubert { 21205796c8dcSSimon Schubert unsigned radix; 21215796c8dcSSimon Schubert 21225796c8dcSSimon Schubert radix = (arg == NULL) ? 10 : parse_and_eval_long (arg); 21235796c8dcSSimon Schubert set_output_radix_1 (0, radix); 21245796c8dcSSimon Schubert set_input_radix_1 (0, radix); 21255796c8dcSSimon Schubert if (from_tty) 21265796c8dcSSimon Schubert { 2127c50c785cSJohn Marino printf_filtered (_("Input and output radices now set to " 2128c50c785cSJohn Marino "decimal %u, hex %x, octal %o.\n"), 21295796c8dcSSimon Schubert radix, radix, radix); 21305796c8dcSSimon Schubert } 21315796c8dcSSimon Schubert } 21325796c8dcSSimon Schubert 21335796c8dcSSimon Schubert /* Show both the input and output radices. */ 21345796c8dcSSimon Schubert 21355796c8dcSSimon Schubert static void 21365796c8dcSSimon Schubert show_radix (char *arg, int from_tty) 21375796c8dcSSimon Schubert { 21385796c8dcSSimon Schubert if (from_tty) 21395796c8dcSSimon Schubert { 21405796c8dcSSimon Schubert if (input_radix == output_radix) 21415796c8dcSSimon Schubert { 2142c50c785cSJohn Marino printf_filtered (_("Input and output radices set to " 2143c50c785cSJohn Marino "decimal %u, hex %x, octal %o.\n"), 21445796c8dcSSimon Schubert input_radix, input_radix, input_radix); 21455796c8dcSSimon Schubert } 21465796c8dcSSimon Schubert else 21475796c8dcSSimon Schubert { 2148c50c785cSJohn Marino printf_filtered (_("Input radix set to decimal " 2149c50c785cSJohn Marino "%u, hex %x, octal %o.\n"), 21505796c8dcSSimon Schubert input_radix, input_radix, input_radix); 2151c50c785cSJohn Marino printf_filtered (_("Output radix set to decimal " 2152c50c785cSJohn Marino "%u, hex %x, octal %o.\n"), 21535796c8dcSSimon Schubert output_radix, output_radix, output_radix); 21545796c8dcSSimon Schubert } 21555796c8dcSSimon Schubert } 21565796c8dcSSimon Schubert } 21575796c8dcSSimon Schubert 21585796c8dcSSimon Schubert 21595796c8dcSSimon Schubert static void 21605796c8dcSSimon Schubert set_print (char *arg, int from_tty) 21615796c8dcSSimon Schubert { 21625796c8dcSSimon Schubert printf_unfiltered ( 21635796c8dcSSimon Schubert "\"set print\" must be followed by the name of a print subcommand.\n"); 21645796c8dcSSimon Schubert help_list (setprintlist, "set print ", -1, gdb_stdout); 21655796c8dcSSimon Schubert } 21665796c8dcSSimon Schubert 21675796c8dcSSimon Schubert static void 21685796c8dcSSimon Schubert show_print (char *args, int from_tty) 21695796c8dcSSimon Schubert { 21705796c8dcSSimon Schubert cmd_show_list (showprintlist, from_tty, ""); 21715796c8dcSSimon Schubert } 21725796c8dcSSimon Schubert 21735796c8dcSSimon Schubert void 21745796c8dcSSimon Schubert _initialize_valprint (void) 21755796c8dcSSimon Schubert { 21765796c8dcSSimon Schubert add_prefix_cmd ("print", no_class, set_print, 21775796c8dcSSimon Schubert _("Generic command for setting how things print."), 21785796c8dcSSimon Schubert &setprintlist, "set print ", 0, &setlist); 21795796c8dcSSimon Schubert add_alias_cmd ("p", "print", no_class, 1, &setlist); 2180c50c785cSJohn Marino /* Prefer set print to set prompt. */ 21815796c8dcSSimon Schubert add_alias_cmd ("pr", "print", no_class, 1, &setlist); 21825796c8dcSSimon Schubert 21835796c8dcSSimon Schubert add_prefix_cmd ("print", no_class, show_print, 21845796c8dcSSimon Schubert _("Generic command for showing print settings."), 21855796c8dcSSimon Schubert &showprintlist, "show print ", 0, &showlist); 21865796c8dcSSimon Schubert add_alias_cmd ("p", "print", no_class, 1, &showlist); 21875796c8dcSSimon Schubert add_alias_cmd ("pr", "print", no_class, 1, &showlist); 21885796c8dcSSimon Schubert 21895796c8dcSSimon Schubert add_setshow_uinteger_cmd ("elements", no_class, 21905796c8dcSSimon Schubert &user_print_options.print_max, _("\ 21915796c8dcSSimon Schubert Set limit on string chars or array elements to print."), _("\ 21925796c8dcSSimon Schubert Show limit on string chars or array elements to print."), _("\ 21935796c8dcSSimon Schubert \"set print elements 0\" causes there to be no limit."), 21945796c8dcSSimon Schubert NULL, 21955796c8dcSSimon Schubert show_print_max, 21965796c8dcSSimon Schubert &setprintlist, &showprintlist); 21975796c8dcSSimon Schubert 21985796c8dcSSimon Schubert add_setshow_boolean_cmd ("null-stop", no_class, 21995796c8dcSSimon Schubert &user_print_options.stop_print_at_null, _("\ 22005796c8dcSSimon Schubert Set printing of char arrays to stop at first null char."), _("\ 22015796c8dcSSimon Schubert Show printing of char arrays to stop at first null char."), NULL, 22025796c8dcSSimon Schubert NULL, 22035796c8dcSSimon Schubert show_stop_print_at_null, 22045796c8dcSSimon Schubert &setprintlist, &showprintlist); 22055796c8dcSSimon Schubert 22065796c8dcSSimon Schubert add_setshow_uinteger_cmd ("repeats", no_class, 22075796c8dcSSimon Schubert &user_print_options.repeat_count_threshold, _("\ 22085796c8dcSSimon Schubert Set threshold for repeated print elements."), _("\ 22095796c8dcSSimon Schubert Show threshold for repeated print elements."), _("\ 22105796c8dcSSimon Schubert \"set print repeats 0\" causes all elements to be individually printed."), 22115796c8dcSSimon Schubert NULL, 22125796c8dcSSimon Schubert show_repeat_count_threshold, 22135796c8dcSSimon Schubert &setprintlist, &showprintlist); 22145796c8dcSSimon Schubert 22155796c8dcSSimon Schubert add_setshow_boolean_cmd ("pretty", class_support, 22165796c8dcSSimon Schubert &user_print_options.prettyprint_structs, _("\ 22175796c8dcSSimon Schubert Set prettyprinting of structures."), _("\ 22185796c8dcSSimon Schubert Show prettyprinting of structures."), NULL, 22195796c8dcSSimon Schubert NULL, 22205796c8dcSSimon Schubert show_prettyprint_structs, 22215796c8dcSSimon Schubert &setprintlist, &showprintlist); 22225796c8dcSSimon Schubert 22235796c8dcSSimon Schubert add_setshow_boolean_cmd ("union", class_support, 22245796c8dcSSimon Schubert &user_print_options.unionprint, _("\ 22255796c8dcSSimon Schubert Set printing of unions interior to structures."), _("\ 22265796c8dcSSimon Schubert Show printing of unions interior to structures."), NULL, 22275796c8dcSSimon Schubert NULL, 22285796c8dcSSimon Schubert show_unionprint, 22295796c8dcSSimon Schubert &setprintlist, &showprintlist); 22305796c8dcSSimon Schubert 22315796c8dcSSimon Schubert add_setshow_boolean_cmd ("array", class_support, 22325796c8dcSSimon Schubert &user_print_options.prettyprint_arrays, _("\ 22335796c8dcSSimon Schubert Set prettyprinting of arrays."), _("\ 22345796c8dcSSimon Schubert Show prettyprinting of arrays."), NULL, 22355796c8dcSSimon Schubert NULL, 22365796c8dcSSimon Schubert show_prettyprint_arrays, 22375796c8dcSSimon Schubert &setprintlist, &showprintlist); 22385796c8dcSSimon Schubert 22395796c8dcSSimon Schubert add_setshow_boolean_cmd ("address", class_support, 22405796c8dcSSimon Schubert &user_print_options.addressprint, _("\ 22415796c8dcSSimon Schubert Set printing of addresses."), _("\ 22425796c8dcSSimon Schubert Show printing of addresses."), NULL, 22435796c8dcSSimon Schubert NULL, 22445796c8dcSSimon Schubert show_addressprint, 22455796c8dcSSimon Schubert &setprintlist, &showprintlist); 22465796c8dcSSimon Schubert 22475796c8dcSSimon Schubert add_setshow_zuinteger_cmd ("input-radix", class_support, &input_radix_1, 22485796c8dcSSimon Schubert _("\ 22495796c8dcSSimon Schubert Set default input radix for entering numbers."), _("\ 22505796c8dcSSimon Schubert Show default input radix for entering numbers."), NULL, 22515796c8dcSSimon Schubert set_input_radix, 22525796c8dcSSimon Schubert show_input_radix, 22535796c8dcSSimon Schubert &setlist, &showlist); 22545796c8dcSSimon Schubert 22555796c8dcSSimon Schubert add_setshow_zuinteger_cmd ("output-radix", class_support, &output_radix_1, 22565796c8dcSSimon Schubert _("\ 22575796c8dcSSimon Schubert Set default output radix for printing of values."), _("\ 22585796c8dcSSimon Schubert Show default output radix for printing of values."), NULL, 22595796c8dcSSimon Schubert set_output_radix, 22605796c8dcSSimon Schubert show_output_radix, 22615796c8dcSSimon Schubert &setlist, &showlist); 22625796c8dcSSimon Schubert 22635796c8dcSSimon Schubert /* The "set radix" and "show radix" commands are special in that 22645796c8dcSSimon Schubert they are like normal set and show commands but allow two normally 22655796c8dcSSimon Schubert independent variables to be either set or shown with a single 22665796c8dcSSimon Schubert command. So the usual deprecated_add_set_cmd() and [deleted] 22675796c8dcSSimon Schubert add_show_from_set() commands aren't really appropriate. */ 22685796c8dcSSimon Schubert /* FIXME: i18n: With the new add_setshow_integer command, that is no 22695796c8dcSSimon Schubert longer true - show can display anything. */ 22705796c8dcSSimon Schubert add_cmd ("radix", class_support, set_radix, _("\ 22715796c8dcSSimon Schubert Set default input and output number radices.\n\ 22725796c8dcSSimon Schubert Use 'set input-radix' or 'set output-radix' to independently set each.\n\ 22735796c8dcSSimon Schubert Without an argument, sets both radices back to the default value of 10."), 22745796c8dcSSimon Schubert &setlist); 22755796c8dcSSimon Schubert add_cmd ("radix", class_support, show_radix, _("\ 22765796c8dcSSimon Schubert Show the default input and output number radices.\n\ 22775796c8dcSSimon Schubert Use 'show input-radix' or 'show output-radix' to independently show each."), 22785796c8dcSSimon Schubert &showlist); 22795796c8dcSSimon Schubert 22805796c8dcSSimon Schubert add_setshow_boolean_cmd ("array-indexes", class_support, 22815796c8dcSSimon Schubert &user_print_options.print_array_indexes, _("\ 22825796c8dcSSimon Schubert Set printing of array indexes."), _("\ 22835796c8dcSSimon Schubert Show printing of array indexes"), NULL, NULL, show_print_array_indexes, 22845796c8dcSSimon Schubert &setprintlist, &showprintlist); 22855796c8dcSSimon Schubert } 2286