* printcmd.c (print_address_demangle): Remove special case for 0.
[deliverable/binutils-gdb.git] / gdb / valprint.c
CommitLineData
c906108c 1/* Print values for GDB, the GNU debugger.
5c1c87f0 2
c5a57081 3 Copyright (C) 1986, 1988-2012 Free Software Foundation, Inc.
c906108c 4
c5aa993b 5 This file is part of GDB.
c906108c 6
c5aa993b
JM
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
a9762ec7 9 the Free Software Foundation; either version 3 of the License, or
c5aa993b 10 (at your option) any later version.
c906108c 11
c5aa993b
JM
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
c906108c 16
c5aa993b 17 You should have received a copy of the GNU General Public License
a9762ec7 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c
SS
19
20#include "defs.h"
21#include "gdb_string.h"
22#include "symtab.h"
23#include "gdbtypes.h"
24#include "value.h"
25#include "gdbcore.h"
26#include "gdbcmd.h"
27#include "target.h"
c906108c 28#include "language.h"
c906108c
SS
29#include "annotate.h"
30#include "valprint.h"
39424bef 31#include "floatformat.h"
d16aafd8 32#include "doublest.h"
19ca80ba 33#include "exceptions.h"
7678ef8f 34#include "dfp.h"
a6bac58e 35#include "python/python.h"
0c3acc09 36#include "ada-lang.h"
3b2b8fea
TT
37#include "gdb_obstack.h"
38#include "charset.h"
39#include <ctype.h>
c906108c
SS
40
41#include <errno.h>
42
43/* Prototypes for local functions */
44
777ea8f1 45static int partial_memory_read (CORE_ADDR memaddr, gdb_byte *myaddr,
917317f4
JM
46 int len, int *errnoptr);
47
a14ed312 48static void show_print (char *, int);
c906108c 49
a14ed312 50static void set_print (char *, int);
c906108c 51
a14ed312 52static void set_radix (char *, int);
c906108c 53
a14ed312 54static void show_radix (char *, int);
c906108c 55
a14ed312 56static void set_input_radix (char *, int, struct cmd_list_element *);
c906108c 57
a14ed312 58static void set_input_radix_1 (int, unsigned);
c906108c 59
a14ed312 60static void set_output_radix (char *, int, struct cmd_list_element *);
c906108c 61
a14ed312 62static void set_output_radix_1 (int, unsigned);
c906108c 63
a14ed312 64void _initialize_valprint (void);
c906108c 65
581e13c1 66#define PRINT_MAX_DEFAULT 200 /* Start print_max off at this value. */
79a45b7d
TT
67
68struct value_print_options user_print_options =
69{
70 Val_pretty_default, /* pretty */
71 0, /* prettyprint_arrays */
72 0, /* prettyprint_structs */
73 0, /* vtblprint */
74 1, /* unionprint */
75 1, /* addressprint */
76 0, /* objectprint */
77 PRINT_MAX_DEFAULT, /* print_max */
78 10, /* repeat_count_threshold */
79 0, /* output_format */
80 0, /* format */
81 0, /* stop_print_at_null */
82 0, /* inspect_it */
83 0, /* print_array_indexes */
84 0, /* deref_ref */
85 1, /* static_field_print */
a6bac58e
TT
86 1, /* pascal_static_field_print */
87 0, /* raw */
88 0 /* summary */
79a45b7d
TT
89};
90
91/* Initialize *OPTS to be a copy of the user print options. */
92void
93get_user_print_options (struct value_print_options *opts)
94{
95 *opts = user_print_options;
96}
97
98/* Initialize *OPTS to be a copy of the user print options, but with
99 pretty-printing disabled. */
100void
101get_raw_print_options (struct value_print_options *opts)
102{
103 *opts = user_print_options;
104 opts->pretty = Val_no_prettyprint;
105}
106
107/* Initialize *OPTS to be a copy of the user print options, but using
108 FORMAT as the formatting option. */
109void
110get_formatted_print_options (struct value_print_options *opts,
111 char format)
112{
113 *opts = user_print_options;
114 opts->format = format;
115}
116
920d2a44
AC
117static void
118show_print_max (struct ui_file *file, int from_tty,
119 struct cmd_list_element *c, const char *value)
120{
3e43a32a
MS
121 fprintf_filtered (file,
122 _("Limit on string chars or array "
123 "elements to print is %s.\n"),
920d2a44
AC
124 value);
125}
126
c906108c
SS
127
128/* Default input and output radixes, and output format letter. */
129
130unsigned input_radix = 10;
920d2a44
AC
131static void
132show_input_radix (struct ui_file *file, int from_tty,
133 struct cmd_list_element *c, const char *value)
134{
3e43a32a
MS
135 fprintf_filtered (file,
136 _("Default input radix for entering numbers is %s.\n"),
920d2a44
AC
137 value);
138}
139
c906108c 140unsigned output_radix = 10;
920d2a44
AC
141static void
142show_output_radix (struct ui_file *file, int from_tty,
143 struct cmd_list_element *c, const char *value)
144{
3e43a32a
MS
145 fprintf_filtered (file,
146 _("Default output radix for printing of values is %s.\n"),
920d2a44
AC
147 value);
148}
c906108c 149
e79af960
JB
150/* By default we print arrays without printing the index of each element in
151 the array. This behavior can be changed by setting PRINT_ARRAY_INDEXES. */
152
e79af960
JB
153static void
154show_print_array_indexes (struct ui_file *file, int from_tty,
155 struct cmd_list_element *c, const char *value)
156{
157 fprintf_filtered (file, _("Printing of array indexes is %s.\n"), value);
158}
159
c906108c
SS
160/* Print repeat counts if there are more than this many repetitions of an
161 element in an array. Referenced by the low level language dependent
581e13c1 162 print routines. */
c906108c 163
920d2a44
AC
164static void
165show_repeat_count_threshold (struct ui_file *file, int from_tty,
166 struct cmd_list_element *c, const char *value)
167{
168 fprintf_filtered (file, _("Threshold for repeated print elements is %s.\n"),
169 value);
170}
c906108c 171
581e13c1 172/* If nonzero, stops printing of char arrays at first null. */
c906108c 173
920d2a44
AC
174static void
175show_stop_print_at_null (struct ui_file *file, int from_tty,
176 struct cmd_list_element *c, const char *value)
177{
3e43a32a
MS
178 fprintf_filtered (file,
179 _("Printing of char arrays to stop "
180 "at first null char is %s.\n"),
920d2a44
AC
181 value);
182}
c906108c 183
581e13c1 184/* Controls pretty printing of structures. */
c906108c 185
920d2a44
AC
186static void
187show_prettyprint_structs (struct ui_file *file, int from_tty,
188 struct cmd_list_element *c, const char *value)
189{
190 fprintf_filtered (file, _("Prettyprinting of structures is %s.\n"), value);
191}
c906108c
SS
192
193/* Controls pretty printing of arrays. */
194
920d2a44
AC
195static void
196show_prettyprint_arrays (struct ui_file *file, int from_tty,
197 struct cmd_list_element *c, const char *value)
198{
199 fprintf_filtered (file, _("Prettyprinting of arrays is %s.\n"), value);
200}
c906108c
SS
201
202/* If nonzero, causes unions inside structures or other unions to be
581e13c1 203 printed. */
c906108c 204
920d2a44
AC
205static void
206show_unionprint (struct ui_file *file, int from_tty,
207 struct cmd_list_element *c, const char *value)
208{
3e43a32a
MS
209 fprintf_filtered (file,
210 _("Printing of unions interior to structures is %s.\n"),
920d2a44
AC
211 value);
212}
c906108c 213
581e13c1 214/* If nonzero, causes machine addresses to be printed in certain contexts. */
c906108c 215
920d2a44
AC
216static void
217show_addressprint (struct ui_file *file, int from_tty,
218 struct cmd_list_element *c, const char *value)
219{
220 fprintf_filtered (file, _("Printing of addresses is %s.\n"), value);
221}
c906108c 222\f
c5aa993b 223
a6bac58e
TT
224/* A helper function for val_print. When printing in "summary" mode,
225 we want to print scalar arguments, but not aggregate arguments.
226 This function distinguishes between the two. */
227
228static int
229scalar_type_p (struct type *type)
230{
231 CHECK_TYPEDEF (type);
232 while (TYPE_CODE (type) == TYPE_CODE_REF)
233 {
234 type = TYPE_TARGET_TYPE (type);
235 CHECK_TYPEDEF (type);
236 }
237 switch (TYPE_CODE (type))
238 {
239 case TYPE_CODE_ARRAY:
240 case TYPE_CODE_STRUCT:
241 case TYPE_CODE_UNION:
242 case TYPE_CODE_SET:
243 case TYPE_CODE_STRING:
244 case TYPE_CODE_BITSTRING:
245 return 0;
246 default:
247 return 1;
248 }
249}
250
a72c8f6a 251/* See its definition in value.h. */
0e03807e 252
a72c8f6a 253int
0e03807e
TT
254valprint_check_validity (struct ui_file *stream,
255 struct type *type,
4e07d55f 256 int embedded_offset,
0e03807e
TT
257 const struct value *val)
258{
259 CHECK_TYPEDEF (type);
260
261 if (TYPE_CODE (type) != TYPE_CODE_UNION
262 && TYPE_CODE (type) != TYPE_CODE_STRUCT
263 && TYPE_CODE (type) != TYPE_CODE_ARRAY)
264 {
4e07d55f
PA
265 if (!value_bits_valid (val, TARGET_CHAR_BIT * embedded_offset,
266 TARGET_CHAR_BIT * TYPE_LENGTH (type)))
0e03807e 267 {
585fdaa1 268 val_print_optimized_out (stream);
0e03807e
TT
269 return 0;
270 }
8cf6f0b1 271
4e07d55f 272 if (value_bits_synthetic_pointer (val, TARGET_CHAR_BIT * embedded_offset,
8cf6f0b1
TT
273 TARGET_CHAR_BIT * TYPE_LENGTH (type)))
274 {
275 fputs_filtered (_("<synthetic pointer>"), stream);
276 return 0;
277 }
4e07d55f
PA
278
279 if (!value_bytes_available (val, embedded_offset, TYPE_LENGTH (type)))
280 {
281 val_print_unavailable (stream);
282 return 0;
283 }
0e03807e
TT
284 }
285
286 return 1;
287}
288
585fdaa1
PA
289void
290val_print_optimized_out (struct ui_file *stream)
291{
292 fprintf_filtered (stream, _("<optimized out>"));
293}
294
4e07d55f
PA
295void
296val_print_unavailable (struct ui_file *stream)
297{
298 fprintf_filtered (stream, _("<unavailable>"));
299}
300
8af8e3bc
PA
301void
302val_print_invalid_address (struct ui_file *stream)
303{
304 fprintf_filtered (stream, _("<invalid address>"));
305}
306
e88acd96
TT
307/* A generic val_print that is suitable for use by language
308 implementations of the la_val_print method. This function can
309 handle most type codes, though not all, notably exception
310 TYPE_CODE_UNION and TYPE_CODE_STRUCT, which must be implemented by
311 the caller.
312
313 Most arguments are as to val_print.
314
315 The additional DECORATIONS argument can be used to customize the
316 output in some small, language-specific ways. */
317
318void
319generic_val_print (struct type *type, const gdb_byte *valaddr,
320 int embedded_offset, CORE_ADDR address,
321 struct ui_file *stream, int recurse,
322 const struct value *original_value,
323 const struct value_print_options *options,
324 const struct generic_val_print_decorations *decorations)
325{
326 struct gdbarch *gdbarch = get_type_arch (type);
327 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
328 unsigned int i = 0; /* Number of characters printed. */
329 unsigned len;
330 struct type *elttype, *unresolved_elttype;
331 struct type *unresolved_type = type;
332 unsigned eltlen;
333 LONGEST val;
334 CORE_ADDR addr;
335
336 CHECK_TYPEDEF (type);
337 switch (TYPE_CODE (type))
338 {
339 case TYPE_CODE_ARRAY:
340 unresolved_elttype = TYPE_TARGET_TYPE (type);
341 elttype = check_typedef (unresolved_elttype);
342 if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (unresolved_elttype) > 0)
343 {
344 LONGEST low_bound, high_bound;
345
346 if (!get_array_bounds (type, &low_bound, &high_bound))
347 error (_("Could not determine the array high bound"));
348
349 if (options->prettyprint_arrays)
350 {
351 print_spaces_filtered (2 + 2 * recurse, stream);
352 }
353
354 fprintf_filtered (stream, "{");
355 val_print_array_elements (type, valaddr, embedded_offset,
356 address, stream,
357 recurse, original_value, options, 0);
358 fprintf_filtered (stream, "}");
359 break;
360 }
361 /* Array of unspecified length: treat like pointer to first
362 elt. */
363 addr = address + embedded_offset;
364 goto print_unpacked_pointer;
365
366 case TYPE_CODE_MEMBERPTR:
367 val_print_scalar_formatted (type, valaddr, embedded_offset,
368 original_value, options, 0, stream);
369 break;
370
371 case TYPE_CODE_PTR:
372 if (options->format && options->format != 's')
373 {
374 val_print_scalar_formatted (type, valaddr, embedded_offset,
375 original_value, options, 0, stream);
376 break;
377 }
378 unresolved_elttype = TYPE_TARGET_TYPE (type);
379 elttype = check_typedef (unresolved_elttype);
380 {
381 addr = unpack_pointer (type, valaddr + embedded_offset);
382 print_unpacked_pointer:
383
384 if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
385 {
386 /* Try to print what function it points to. */
edf0c1b7 387 print_function_pointer_address (options, gdbarch, addr, stream);
e88acd96
TT
388 return;
389 }
390
391 if (options->addressprint)
392 fputs_filtered (paddress (gdbarch, addr), stream);
393 }
394 break;
395
396 case TYPE_CODE_REF:
397 elttype = check_typedef (TYPE_TARGET_TYPE (type));
398 if (options->addressprint)
399 {
400 CORE_ADDR addr
401 = extract_typed_address (valaddr + embedded_offset, type);
402
403 fprintf_filtered (stream, "@");
404 fputs_filtered (paddress (gdbarch, addr), stream);
405 if (options->deref_ref)
406 fputs_filtered (": ", stream);
407 }
408 /* De-reference the reference. */
409 if (options->deref_ref)
410 {
411 if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF)
412 {
413 struct value *deref_val;
414
415 deref_val = coerce_ref_if_computed (original_value);
416 if (deref_val != NULL)
417 {
418 /* More complicated computed references are not supported. */
419 gdb_assert (embedded_offset == 0);
420 }
421 else
422 deref_val = value_at (TYPE_TARGET_TYPE (type),
423 unpack_pointer (type,
424 (valaddr
425 + embedded_offset)));
426
427 common_val_print (deref_val, stream, recurse, options,
428 current_language);
429 }
430 else
431 fputs_filtered ("???", stream);
432 }
433 break;
434
435 case TYPE_CODE_ENUM:
436 if (options->format)
437 {
438 val_print_scalar_formatted (type, valaddr, embedded_offset,
439 original_value, options, 0, stream);
440 break;
441 }
442 len = TYPE_NFIELDS (type);
443 val = unpack_long (type, valaddr + embedded_offset);
444 for (i = 0; i < len; i++)
445 {
446 QUIT;
14e75d8e 447 if (val == TYPE_FIELD_ENUMVAL (type, i))
e88acd96
TT
448 {
449 break;
450 }
451 }
452 if (i < len)
453 {
454 fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
455 }
456 else if (TYPE_FLAG_ENUM (type))
457 {
458 int first = 1;
459
460 /* We have a "flag" enum, so we try to decompose it into
461 pieces as appropriate. A flag enum has disjoint
462 constants by definition. */
463 fputs_filtered ("(", stream);
464 for (i = 0; i < len; ++i)
465 {
466 QUIT;
467
14e75d8e 468 if ((val & TYPE_FIELD_ENUMVAL (type, i)) != 0)
e88acd96
TT
469 {
470 if (!first)
471 fputs_filtered (" | ", stream);
472 first = 0;
473
14e75d8e 474 val &= ~TYPE_FIELD_ENUMVAL (type, i);
e88acd96
TT
475 fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
476 }
477 }
478
479 if (first || val != 0)
480 {
481 if (!first)
482 fputs_filtered (" | ", stream);
483 fputs_filtered ("unknown: ", stream);
484 print_longest (stream, 'd', 0, val);
485 }
486
487 fputs_filtered (")", stream);
488 }
489 else
490 print_longest (stream, 'd', 0, val);
491 break;
492
493 case TYPE_CODE_FLAGS:
494 if (options->format)
495 val_print_scalar_formatted (type, valaddr, embedded_offset,
496 original_value, options, 0, stream);
497 else
498 val_print_type_code_flags (type, valaddr + embedded_offset,
499 stream);
500 break;
501
502 case TYPE_CODE_FUNC:
503 case TYPE_CODE_METHOD:
504 if (options->format)
505 {
506 val_print_scalar_formatted (type, valaddr, embedded_offset,
507 original_value, options, 0, stream);
508 break;
509 }
510 /* FIXME, we should consider, at least for ANSI C language,
511 eliminating the distinction made between FUNCs and POINTERs
512 to FUNCs. */
513 fprintf_filtered (stream, "{");
514 type_print (type, "", stream, -1);
515 fprintf_filtered (stream, "} ");
516 /* Try to print what function it points to, and its address. */
edf0c1b7 517 print_address_demangle (options, gdbarch, address, stream, demangle);
e88acd96
TT
518 break;
519
520 case TYPE_CODE_BOOL:
521 if (options->format || options->output_format)
522 {
523 struct value_print_options opts = *options;
524 opts.format = (options->format ? options->format
525 : options->output_format);
526 val_print_scalar_formatted (type, valaddr, embedded_offset,
527 original_value, &opts, 0, stream);
528 }
529 else
530 {
531 val = unpack_long (type, valaddr + embedded_offset);
532 if (val == 0)
533 fputs_filtered (decorations->false_name, stream);
534 else if (val == 1)
535 fputs_filtered (decorations->true_name, stream);
536 else
537 print_longest (stream, 'd', 0, val);
538 }
539 break;
540
541 case TYPE_CODE_RANGE:
542 /* FIXME: create_range_type does not set the unsigned bit in a
543 range type (I think it probably should copy it from the
544 target type), so we won't print values which are too large to
545 fit in a signed integer correctly. */
546 /* FIXME: Doesn't handle ranges of enums correctly. (Can't just
547 print with the target type, though, because the size of our
548 type and the target type might differ). */
549
550 /* FALLTHROUGH */
551
552 case TYPE_CODE_INT:
553 if (options->format || options->output_format)
554 {
555 struct value_print_options opts = *options;
556
557 opts.format = (options->format ? options->format
558 : options->output_format);
559 val_print_scalar_formatted (type, valaddr, embedded_offset,
560 original_value, &opts, 0, stream);
561 }
562 else
563 val_print_type_code_int (type, valaddr + embedded_offset, stream);
564 break;
565
566 case TYPE_CODE_CHAR:
567 if (options->format || options->output_format)
568 {
569 struct value_print_options opts = *options;
570
571 opts.format = (options->format ? options->format
572 : options->output_format);
573 val_print_scalar_formatted (type, valaddr, embedded_offset,
574 original_value, &opts, 0, stream);
575 }
576 else
577 {
578 val = unpack_long (type, valaddr + embedded_offset);
579 if (TYPE_UNSIGNED (type))
580 fprintf_filtered (stream, "%u", (unsigned int) val);
581 else
582 fprintf_filtered (stream, "%d", (int) val);
583 fputs_filtered (" ", stream);
584 LA_PRINT_CHAR (val, unresolved_type, stream);
585 }
586 break;
587
588 case TYPE_CODE_FLT:
589 if (options->format)
590 {
591 val_print_scalar_formatted (type, valaddr, embedded_offset,
592 original_value, options, 0, stream);
593 }
594 else
595 {
596 print_floating (valaddr + embedded_offset, type, stream);
597 }
598 break;
599
600 case TYPE_CODE_DECFLOAT:
601 if (options->format)
602 val_print_scalar_formatted (type, valaddr, embedded_offset,
603 original_value, options, 0, stream);
604 else
605 print_decimal_floating (valaddr + embedded_offset,
606 type, stream);
607 break;
608
609 case TYPE_CODE_VOID:
610 fputs_filtered (decorations->void_name, stream);
611 break;
612
613 case TYPE_CODE_ERROR:
614 fprintf_filtered (stream, "%s", TYPE_ERROR_NAME (type));
615 break;
616
617 case TYPE_CODE_UNDEF:
618 /* This happens (without TYPE_FLAG_STUB set) on systems which
619 don't use dbx xrefs (NO_DBX_XREFS in gcc) if a file has a
620 "struct foo *bar" and no complete type for struct foo in that
621 file. */
622 fprintf_filtered (stream, _("<incomplete type>"));
623 break;
624
625 case TYPE_CODE_COMPLEX:
626 fprintf_filtered (stream, "%s", decorations->complex_prefix);
627 if (options->format)
628 val_print_scalar_formatted (TYPE_TARGET_TYPE (type),
629 valaddr, embedded_offset,
630 original_value, options, 0, stream);
631 else
632 print_floating (valaddr + embedded_offset,
633 TYPE_TARGET_TYPE (type),
634 stream);
635 fprintf_filtered (stream, "%s", decorations->complex_infix);
636 if (options->format)
637 val_print_scalar_formatted (TYPE_TARGET_TYPE (type),
638 valaddr,
639 embedded_offset
640 + TYPE_LENGTH (TYPE_TARGET_TYPE (type)),
641 original_value,
642 options, 0, stream);
643 else
644 print_floating (valaddr + embedded_offset
645 + TYPE_LENGTH (TYPE_TARGET_TYPE (type)),
646 TYPE_TARGET_TYPE (type),
647 stream);
648 fprintf_filtered (stream, "%s", decorations->complex_suffix);
649 break;
650
651 case TYPE_CODE_UNION:
652 case TYPE_CODE_STRUCT:
653 case TYPE_CODE_METHODPTR:
654 default:
655 error (_("Unhandled type code %d in symbol table."),
656 TYPE_CODE (type));
657 }
658 gdb_flush (stream);
659}
660
32b72a42
PA
661/* Print using the given LANGUAGE the data of type TYPE located at
662 VALADDR + EMBEDDED_OFFSET (within GDB), which came from the
663 inferior at address ADDRESS + EMBEDDED_OFFSET, onto stdio stream
664 STREAM according to OPTIONS. VAL is the whole object that came
665 from ADDRESS. VALADDR must point to the head of VAL's contents
666 buffer.
667
668 The language printers will pass down an adjusted EMBEDDED_OFFSET to
669 further helper subroutines as subfields of TYPE are printed. In
670 such cases, VALADDR is passed down unadjusted, as well as VAL, so
671 that VAL can be queried for metadata about the contents data being
672 printed, using EMBEDDED_OFFSET as an offset into VAL's contents
673 buffer. For example: "has this field been optimized out", or "I'm
674 printing an object while inspecting a traceframe; has this
675 particular piece of data been collected?".
676
677 RECURSE indicates the amount of indentation to supply before
678 continuation lines; this amount is roughly twice the value of
35c0084b 679 RECURSE. */
32b72a42 680
35c0084b 681void
fc1a4b47 682val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
79a45b7d 683 CORE_ADDR address, struct ui_file *stream, int recurse,
0e03807e 684 const struct value *val,
79a45b7d 685 const struct value_print_options *options,
d8ca156b 686 const struct language_defn *language)
c906108c 687{
19ca80ba
DJ
688 volatile struct gdb_exception except;
689 int ret = 0;
79a45b7d 690 struct value_print_options local_opts = *options;
c906108c 691 struct type *real_type = check_typedef (type);
79a45b7d
TT
692
693 if (local_opts.pretty == Val_pretty_default)
694 local_opts.pretty = (local_opts.prettyprint_structs
695 ? Val_prettyprint : Val_no_prettyprint);
c5aa993b 696
c906108c
SS
697 QUIT;
698
699 /* Ensure that the type is complete and not just a stub. If the type is
700 only a stub and we can't find and substitute its complete type, then
701 print appropriate string and return. */
702
74a9bb82 703 if (TYPE_STUB (real_type))
c906108c 704 {
0e03807e 705 fprintf_filtered (stream, _("<incomplete type>"));
c906108c 706 gdb_flush (stream);
35c0084b 707 return;
c906108c 708 }
c5aa993b 709
0e03807e 710 if (!valprint_check_validity (stream, real_type, embedded_offset, val))
35c0084b 711 return;
0e03807e 712
a6bac58e
TT
713 if (!options->raw)
714 {
715 ret = apply_val_pretty_printer (type, valaddr, embedded_offset,
0e03807e
TT
716 address, stream, recurse,
717 val, options, language);
a6bac58e 718 if (ret)
35c0084b 719 return;
a6bac58e
TT
720 }
721
722 /* Handle summary mode. If the value is a scalar, print it;
723 otherwise, print an ellipsis. */
724 if (options->summary && !scalar_type_p (type))
725 {
726 fprintf_filtered (stream, "...");
35c0084b 727 return;
a6bac58e
TT
728 }
729
19ca80ba
DJ
730 TRY_CATCH (except, RETURN_MASK_ERROR)
731 {
d3eab38a
TT
732 language->la_val_print (type, valaddr, embedded_offset, address,
733 stream, recurse, val,
734 &local_opts);
19ca80ba
DJ
735 }
736 if (except.reason < 0)
737 fprintf_filtered (stream, _("<error reading variable>"));
c906108c
SS
738}
739
806048c6 740/* Check whether the value VAL is printable. Return 1 if it is;
6501578c
YQ
741 return 0 and print an appropriate error message to STREAM according to
742 OPTIONS if it is not. */
c906108c 743
806048c6 744static int
6501578c
YQ
745value_check_printable (struct value *val, struct ui_file *stream,
746 const struct value_print_options *options)
c906108c
SS
747{
748 if (val == 0)
749 {
806048c6 750 fprintf_filtered (stream, _("<address of value unknown>"));
c906108c
SS
751 return 0;
752 }
806048c6 753
0e03807e 754 if (value_entirely_optimized_out (val))
c906108c 755 {
6501578c
YQ
756 if (options->summary && !scalar_type_p (value_type (val)))
757 fprintf_filtered (stream, "...");
758 else
759 val_print_optimized_out (stream);
c906108c
SS
760 return 0;
761 }
806048c6 762
bc3b79fd
TJB
763 if (TYPE_CODE (value_type (val)) == TYPE_CODE_INTERNAL_FUNCTION)
764 {
765 fprintf_filtered (stream, _("<internal function %s>"),
766 value_internal_function_name (val));
767 return 0;
768 }
769
806048c6
DJ
770 return 1;
771}
772
d8ca156b 773/* Print using the given LANGUAGE the value VAL onto stream STREAM according
79a45b7d 774 to OPTIONS.
806048c6 775
806048c6
DJ
776 This is a preferable interface to val_print, above, because it uses
777 GDB's value mechanism. */
778
a1f5dd1b 779void
79a45b7d
TT
780common_val_print (struct value *val, struct ui_file *stream, int recurse,
781 const struct value_print_options *options,
d8ca156b 782 const struct language_defn *language)
806048c6 783{
6501578c 784 if (!value_check_printable (val, stream, options))
a1f5dd1b 785 return;
806048c6 786
0c3acc09
JB
787 if (language->la_language == language_ada)
788 /* The value might have a dynamic type, which would cause trouble
789 below when trying to extract the value contents (since the value
790 size is determined from the type size which is unknown). So
791 get a fixed representation of our value. */
792 val = ada_to_fixed_value (val);
793
a1f5dd1b
TT
794 val_print (value_type (val), value_contents_for_printing (val),
795 value_embedded_offset (val), value_address (val),
796 stream, recurse,
797 val, options, language);
806048c6
DJ
798}
799
7348c5e1 800/* Print on stream STREAM the value VAL according to OPTIONS. The value
8e069a98 801 is printed using the current_language syntax. */
7348c5e1 802
8e069a98 803void
79a45b7d
TT
804value_print (struct value *val, struct ui_file *stream,
805 const struct value_print_options *options)
806048c6 806{
6501578c 807 if (!value_check_printable (val, stream, options))
8e069a98 808 return;
806048c6 809
a6bac58e
TT
810 if (!options->raw)
811 {
812 int r = apply_val_pretty_printer (value_type (val),
0e03807e 813 value_contents_for_printing (val),
a6bac58e
TT
814 value_embedded_offset (val),
815 value_address (val),
0e03807e
TT
816 stream, 0,
817 val, options, current_language);
a109c7c1 818
a6bac58e 819 if (r)
8e069a98 820 return;
a6bac58e
TT
821 }
822
8e069a98 823 LA_VALUE_PRINT (val, stream, options);
c906108c
SS
824}
825
826/* Called by various <lang>_val_print routines to print
827 TYPE_CODE_INT's. TYPE is the type. VALADDR is the address of the
828 value. STREAM is where to print the value. */
829
830void
fc1a4b47 831val_print_type_code_int (struct type *type, const gdb_byte *valaddr,
fba45db2 832 struct ui_file *stream)
c906108c 833{
50810684 834 enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
d44e8473 835
c906108c
SS
836 if (TYPE_LENGTH (type) > sizeof (LONGEST))
837 {
838 LONGEST val;
839
840 if (TYPE_UNSIGNED (type)
841 && extract_long_unsigned_integer (valaddr, TYPE_LENGTH (type),
e17a4113 842 byte_order, &val))
c906108c
SS
843 {
844 print_longest (stream, 'u', 0, val);
845 }
846 else
847 {
848 /* Signed, or we couldn't turn an unsigned value into a
849 LONGEST. For signed values, one could assume two's
850 complement (a reasonable assumption, I think) and do
851 better than this. */
852 print_hex_chars (stream, (unsigned char *) valaddr,
d44e8473 853 TYPE_LENGTH (type), byte_order);
c906108c
SS
854 }
855 }
856 else
857 {
c906108c
SS
858 print_longest (stream, TYPE_UNSIGNED (type) ? 'u' : 'd', 0,
859 unpack_long (type, valaddr));
c906108c
SS
860 }
861}
862
4f2aea11
MK
863void
864val_print_type_code_flags (struct type *type, const gdb_byte *valaddr,
865 struct ui_file *stream)
866{
befae759 867 ULONGEST val = unpack_long (type, valaddr);
4f2aea11
MK
868 int bitpos, nfields = TYPE_NFIELDS (type);
869
870 fputs_filtered ("[ ", stream);
871 for (bitpos = 0; bitpos < nfields; bitpos++)
872 {
316703b9
MK
873 if (TYPE_FIELD_BITPOS (type, bitpos) != -1
874 && (val & ((ULONGEST)1 << bitpos)))
4f2aea11
MK
875 {
876 if (TYPE_FIELD_NAME (type, bitpos))
877 fprintf_filtered (stream, "%s ", TYPE_FIELD_NAME (type, bitpos));
878 else
879 fprintf_filtered (stream, "#%d ", bitpos);
880 }
881 }
882 fputs_filtered ("]", stream);
19c37f24 883}
ab2188aa
PA
884
885/* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
886 according to OPTIONS and SIZE on STREAM. Format i is not supported
887 at this level.
888
889 This is how the elements of an array or structure are printed
890 with a format. */
ab2188aa
PA
891
892void
893val_print_scalar_formatted (struct type *type,
894 const gdb_byte *valaddr, int embedded_offset,
895 const struct value *val,
896 const struct value_print_options *options,
897 int size,
898 struct ui_file *stream)
899{
900 gdb_assert (val != NULL);
901 gdb_assert (valaddr == value_contents_for_printing_const (val));
902
903 /* If we get here with a string format, try again without it. Go
904 all the way back to the language printers, which may call us
905 again. */
906 if (options->format == 's')
907 {
908 struct value_print_options opts = *options;
909 opts.format = 0;
910 opts.deref_ref = 0;
911 val_print (type, valaddr, embedded_offset, 0, stream, 0, val, &opts,
912 current_language);
913 return;
914 }
915
916 /* A scalar object that does not have all bits available can't be
917 printed, because all bits contribute to its representation. */
918 if (!value_bits_valid (val, TARGET_CHAR_BIT * embedded_offset,
919 TARGET_CHAR_BIT * TYPE_LENGTH (type)))
920 val_print_optimized_out (stream);
4e07d55f
PA
921 else if (!value_bytes_available (val, embedded_offset, TYPE_LENGTH (type)))
922 val_print_unavailable (stream);
ab2188aa
PA
923 else
924 print_scalar_formatted (valaddr + embedded_offset, type,
925 options, size, stream);
4f2aea11
MK
926}
927
c906108c
SS
928/* Print a number according to FORMAT which is one of d,u,x,o,b,h,w,g.
929 The raison d'etre of this function is to consolidate printing of
581e13c1 930 LONG_LONG's into this one function. The format chars b,h,w,g are
bb599908 931 from print_scalar_formatted(). Numbers are printed using C
581e13c1 932 format.
bb599908
PH
933
934 USE_C_FORMAT means to use C format in all cases. Without it,
935 'o' and 'x' format do not include the standard C radix prefix
936 (leading 0 or 0x).
937
938 Hilfinger/2004-09-09: USE_C_FORMAT was originally called USE_LOCAL
939 and was intended to request formating according to the current
940 language and would be used for most integers that GDB prints. The
941 exceptional cases were things like protocols where the format of
942 the integer is a protocol thing, not a user-visible thing). The
943 parameter remains to preserve the information of what things might
944 be printed with language-specific format, should we ever resurrect
581e13c1 945 that capability. */
c906108c
SS
946
947void
bb599908 948print_longest (struct ui_file *stream, int format, int use_c_format,
fba45db2 949 LONGEST val_long)
c906108c 950{
2bfb72ee
AC
951 const char *val;
952
c906108c
SS
953 switch (format)
954 {
955 case 'd':
bb599908 956 val = int_string (val_long, 10, 1, 0, 1); break;
c906108c 957 case 'u':
bb599908 958 val = int_string (val_long, 10, 0, 0, 1); break;
c906108c 959 case 'x':
bb599908 960 val = int_string (val_long, 16, 0, 0, use_c_format); break;
c906108c 961 case 'b':
bb599908 962 val = int_string (val_long, 16, 0, 2, 1); break;
c906108c 963 case 'h':
bb599908 964 val = int_string (val_long, 16, 0, 4, 1); break;
c906108c 965 case 'w':
bb599908 966 val = int_string (val_long, 16, 0, 8, 1); break;
c906108c 967 case 'g':
bb599908 968 val = int_string (val_long, 16, 0, 16, 1); break;
c906108c
SS
969 break;
970 case 'o':
bb599908 971 val = int_string (val_long, 8, 0, 0, use_c_format); break;
c906108c 972 default:
3e43a32a
MS
973 internal_error (__FILE__, __LINE__,
974 _("failed internal consistency check"));
bb599908 975 }
2bfb72ee 976 fputs_filtered (val, stream);
c906108c
SS
977}
978
c906108c
SS
979/* This used to be a macro, but I don't think it is called often enough
980 to merit such treatment. */
981/* Convert a LONGEST to an int. This is used in contexts (e.g. number of
982 arguments to a function, number in a value history, register number, etc.)
983 where the value must not be larger than can fit in an int. */
984
985int
fba45db2 986longest_to_int (LONGEST arg)
c906108c 987{
581e13c1 988 /* Let the compiler do the work. */
c906108c
SS
989 int rtnval = (int) arg;
990
581e13c1 991 /* Check for overflows or underflows. */
c906108c
SS
992 if (sizeof (LONGEST) > sizeof (int))
993 {
994 if (rtnval != arg)
995 {
8a3fe4f8 996 error (_("Value out of range."));
c906108c
SS
997 }
998 }
999 return (rtnval);
1000}
1001
a73c86fb
AC
1002/* Print a floating point value of type TYPE (not always a
1003 TYPE_CODE_FLT), pointed to in GDB by VALADDR, on STREAM. */
c906108c
SS
1004
1005void
fc1a4b47 1006print_floating (const gdb_byte *valaddr, struct type *type,
c84141d6 1007 struct ui_file *stream)
c906108c
SS
1008{
1009 DOUBLEST doub;
1010 int inv;
a73c86fb 1011 const struct floatformat *fmt = NULL;
c906108c 1012 unsigned len = TYPE_LENGTH (type);
20389057 1013 enum float_kind kind;
c5aa993b 1014
a73c86fb
AC
1015 /* If it is a floating-point, check for obvious problems. */
1016 if (TYPE_CODE (type) == TYPE_CODE_FLT)
1017 fmt = floatformat_from_type (type);
20389057 1018 if (fmt != NULL)
39424bef 1019 {
20389057
DJ
1020 kind = floatformat_classify (fmt, valaddr);
1021 if (kind == float_nan)
1022 {
1023 if (floatformat_is_negative (fmt, valaddr))
1024 fprintf_filtered (stream, "-");
1025 fprintf_filtered (stream, "nan(");
1026 fputs_filtered ("0x", stream);
1027 fputs_filtered (floatformat_mantissa (fmt, valaddr), stream);
1028 fprintf_filtered (stream, ")");
1029 return;
1030 }
1031 else if (kind == float_infinite)
1032 {
1033 if (floatformat_is_negative (fmt, valaddr))
1034 fputs_filtered ("-", stream);
1035 fputs_filtered ("inf", stream);
1036 return;
1037 }
7355ddba 1038 }
c906108c 1039
a73c86fb
AC
1040 /* NOTE: cagney/2002-01-15: The TYPE passed into print_floating()
1041 isn't necessarily a TYPE_CODE_FLT. Consequently, unpack_double
1042 needs to be used as that takes care of any necessary type
1043 conversions. Such conversions are of course direct to DOUBLEST
1044 and disregard any possible target floating point limitations.
1045 For instance, a u64 would be converted and displayed exactly on a
1046 host with 80 bit DOUBLEST but with loss of information on a host
1047 with 64 bit DOUBLEST. */
c2f05ac9 1048
c906108c
SS
1049 doub = unpack_double (type, valaddr, &inv);
1050 if (inv)
1051 {
1052 fprintf_filtered (stream, "<invalid float value>");
1053 return;
1054 }
1055
39424bef
MK
1056 /* FIXME: kettenis/2001-01-20: The following code makes too much
1057 assumptions about the host and target floating point format. */
1058
a73c86fb 1059 /* NOTE: cagney/2002-02-03: Since the TYPE of what was passed in may
c41b8590 1060 not necessarily be a TYPE_CODE_FLT, the below ignores that and
a73c86fb
AC
1061 instead uses the type's length to determine the precision of the
1062 floating-point value being printed. */
c2f05ac9 1063
c906108c 1064 if (len < sizeof (double))
c5aa993b 1065 fprintf_filtered (stream, "%.9g", (double) doub);
c906108c 1066 else if (len == sizeof (double))
c5aa993b 1067 fprintf_filtered (stream, "%.17g", (double) doub);
c906108c
SS
1068 else
1069#ifdef PRINTF_HAS_LONG_DOUBLE
1070 fprintf_filtered (stream, "%.35Lg", doub);
1071#else
39424bef
MK
1072 /* This at least wins with values that are representable as
1073 doubles. */
c906108c
SS
1074 fprintf_filtered (stream, "%.17g", (double) doub);
1075#endif
1076}
1077
7678ef8f
TJB
1078void
1079print_decimal_floating (const gdb_byte *valaddr, struct type *type,
1080 struct ui_file *stream)
1081{
e17a4113 1082 enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
7678ef8f
TJB
1083 char decstr[MAX_DECIMAL_STRING];
1084 unsigned len = TYPE_LENGTH (type);
1085
e17a4113 1086 decimal_to_string (valaddr, len, byte_order, decstr);
7678ef8f
TJB
1087 fputs_filtered (decstr, stream);
1088 return;
1089}
1090
c5aa993b 1091void
fc1a4b47 1092print_binary_chars (struct ui_file *stream, const gdb_byte *valaddr,
d44e8473 1093 unsigned len, enum bfd_endian byte_order)
c906108c
SS
1094{
1095
1096#define BITS_IN_BYTES 8
1097
fc1a4b47 1098 const gdb_byte *p;
745b8ca0 1099 unsigned int i;
c5aa993b 1100 int b;
c906108c
SS
1101
1102 /* Declared "int" so it will be signed.
581e13c1
MS
1103 This ensures that right shift will shift in zeros. */
1104
c5aa993b 1105 const int mask = 0x080;
c906108c
SS
1106
1107 /* FIXME: We should be not printing leading zeroes in most cases. */
1108
d44e8473 1109 if (byte_order == BFD_ENDIAN_BIG)
c906108c
SS
1110 {
1111 for (p = valaddr;
1112 p < valaddr + len;
1113 p++)
1114 {
c5aa993b 1115 /* Every byte has 8 binary characters; peel off
581e13c1
MS
1116 and print from the MSB end. */
1117
c5aa993b
JM
1118 for (i = 0; i < (BITS_IN_BYTES * sizeof (*p)); i++)
1119 {
1120 if (*p & (mask >> i))
1121 b = 1;
1122 else
1123 b = 0;
1124
1125 fprintf_filtered (stream, "%1d", b);
1126 }
c906108c
SS
1127 }
1128 }
1129 else
1130 {
1131 for (p = valaddr + len - 1;
1132 p >= valaddr;
1133 p--)
1134 {
c5aa993b
JM
1135 for (i = 0; i < (BITS_IN_BYTES * sizeof (*p)); i++)
1136 {
1137 if (*p & (mask >> i))
1138 b = 1;
1139 else
1140 b = 0;
1141
1142 fprintf_filtered (stream, "%1d", b);
1143 }
c906108c
SS
1144 }
1145 }
c906108c
SS
1146}
1147
1148/* VALADDR points to an integer of LEN bytes.
581e13c1
MS
1149 Print it in octal on stream or format it in buf. */
1150
c906108c 1151void
fc1a4b47 1152print_octal_chars (struct ui_file *stream, const gdb_byte *valaddr,
d44e8473 1153 unsigned len, enum bfd_endian byte_order)
c906108c 1154{
fc1a4b47 1155 const gdb_byte *p;
c906108c 1156 unsigned char octa1, octa2, octa3, carry;
c5aa993b
JM
1157 int cycle;
1158
c906108c
SS
1159 /* FIXME: We should be not printing leading zeroes in most cases. */
1160
1161
1162 /* Octal is 3 bits, which doesn't fit. Yuk. So we have to track
1163 * the extra bits, which cycle every three bytes:
1164 *
1165 * Byte side: 0 1 2 3
1166 * | | | |
1167 * bit number 123 456 78 | 9 012 345 6 | 78 901 234 | 567 890 12 |
1168 *
1169 * Octal side: 0 1 carry 3 4 carry ...
1170 *
1171 * Cycle number: 0 1 2
1172 *
1173 * But of course we are printing from the high side, so we have to
1174 * figure out where in the cycle we are so that we end up with no
1175 * left over bits at the end.
1176 */
1177#define BITS_IN_OCTAL 3
1178#define HIGH_ZERO 0340
1179#define LOW_ZERO 0016
1180#define CARRY_ZERO 0003
1181#define HIGH_ONE 0200
1182#define MID_ONE 0160
1183#define LOW_ONE 0016
1184#define CARRY_ONE 0001
1185#define HIGH_TWO 0300
1186#define MID_TWO 0070
1187#define LOW_TWO 0007
1188
1189 /* For 32 we start in cycle 2, with two bits and one bit carry;
581e13c1
MS
1190 for 64 in cycle in cycle 1, with one bit and a two bit carry. */
1191
c906108c
SS
1192 cycle = (len * BITS_IN_BYTES) % BITS_IN_OCTAL;
1193 carry = 0;
c5aa993b 1194
bb599908 1195 fputs_filtered ("0", stream);
d44e8473 1196 if (byte_order == BFD_ENDIAN_BIG)
c906108c
SS
1197 {
1198 for (p = valaddr;
1199 p < valaddr + len;
1200 p++)
1201 {
c5aa993b
JM
1202 switch (cycle)
1203 {
1204 case 0:
581e13c1
MS
1205 /* No carry in, carry out two bits. */
1206
c5aa993b
JM
1207 octa1 = (HIGH_ZERO & *p) >> 5;
1208 octa2 = (LOW_ZERO & *p) >> 2;
1209 carry = (CARRY_ZERO & *p);
1210 fprintf_filtered (stream, "%o", octa1);
1211 fprintf_filtered (stream, "%o", octa2);
1212 break;
1213
1214 case 1:
581e13c1
MS
1215 /* Carry in two bits, carry out one bit. */
1216
c5aa993b
JM
1217 octa1 = (carry << 1) | ((HIGH_ONE & *p) >> 7);
1218 octa2 = (MID_ONE & *p) >> 4;
1219 octa3 = (LOW_ONE & *p) >> 1;
1220 carry = (CARRY_ONE & *p);
1221 fprintf_filtered (stream, "%o", octa1);
1222 fprintf_filtered (stream, "%o", octa2);
1223 fprintf_filtered (stream, "%o", octa3);
1224 break;
1225
1226 case 2:
581e13c1
MS
1227 /* Carry in one bit, no carry out. */
1228
c5aa993b
JM
1229 octa1 = (carry << 2) | ((HIGH_TWO & *p) >> 6);
1230 octa2 = (MID_TWO & *p) >> 3;
1231 octa3 = (LOW_TWO & *p);
1232 carry = 0;
1233 fprintf_filtered (stream, "%o", octa1);
1234 fprintf_filtered (stream, "%o", octa2);
1235 fprintf_filtered (stream, "%o", octa3);
1236 break;
1237
1238 default:
8a3fe4f8 1239 error (_("Internal error in octal conversion;"));
c5aa993b
JM
1240 }
1241
1242 cycle++;
1243 cycle = cycle % BITS_IN_OCTAL;
c906108c
SS
1244 }
1245 }
1246 else
1247 {
1248 for (p = valaddr + len - 1;
1249 p >= valaddr;
1250 p--)
1251 {
c5aa993b
JM
1252 switch (cycle)
1253 {
1254 case 0:
1255 /* Carry out, no carry in */
581e13c1 1256
c5aa993b
JM
1257 octa1 = (HIGH_ZERO & *p) >> 5;
1258 octa2 = (LOW_ZERO & *p) >> 2;
1259 carry = (CARRY_ZERO & *p);
1260 fprintf_filtered (stream, "%o", octa1);
1261 fprintf_filtered (stream, "%o", octa2);
1262 break;
1263
1264 case 1:
1265 /* Carry in, carry out */
581e13c1 1266
c5aa993b
JM
1267 octa1 = (carry << 1) | ((HIGH_ONE & *p) >> 7);
1268 octa2 = (MID_ONE & *p) >> 4;
1269 octa3 = (LOW_ONE & *p) >> 1;
1270 carry = (CARRY_ONE & *p);
1271 fprintf_filtered (stream, "%o", octa1);
1272 fprintf_filtered (stream, "%o", octa2);
1273 fprintf_filtered (stream, "%o", octa3);
1274 break;
1275
1276 case 2:
1277 /* Carry in, no carry out */
581e13c1 1278
c5aa993b
JM
1279 octa1 = (carry << 2) | ((HIGH_TWO & *p) >> 6);
1280 octa2 = (MID_TWO & *p) >> 3;
1281 octa3 = (LOW_TWO & *p);
1282 carry = 0;
1283 fprintf_filtered (stream, "%o", octa1);
1284 fprintf_filtered (stream, "%o", octa2);
1285 fprintf_filtered (stream, "%o", octa3);
1286 break;
1287
1288 default:
8a3fe4f8 1289 error (_("Internal error in octal conversion;"));
c5aa993b
JM
1290 }
1291
1292 cycle++;
1293 cycle = cycle % BITS_IN_OCTAL;
c906108c
SS
1294 }
1295 }
1296
c906108c
SS
1297}
1298
1299/* VALADDR points to an integer of LEN bytes.
581e13c1
MS
1300 Print it in decimal on stream or format it in buf. */
1301
c906108c 1302void
fc1a4b47 1303print_decimal_chars (struct ui_file *stream, const gdb_byte *valaddr,
d44e8473 1304 unsigned len, enum bfd_endian byte_order)
c906108c
SS
1305{
1306#define TEN 10
c5aa993b 1307#define CARRY_OUT( x ) ((x) / TEN) /* extend char to int */
c906108c
SS
1308#define CARRY_LEFT( x ) ((x) % TEN)
1309#define SHIFT( x ) ((x) << 4)
c906108c
SS
1310#define LOW_NIBBLE( x ) ( (x) & 0x00F)
1311#define HIGH_NIBBLE( x ) (((x) & 0x0F0) >> 4)
1312
fc1a4b47 1313 const gdb_byte *p;
c906108c 1314 unsigned char *digits;
c5aa993b
JM
1315 int carry;
1316 int decimal_len;
1317 int i, j, decimal_digits;
1318 int dummy;
1319 int flip;
1320
c906108c 1321 /* Base-ten number is less than twice as many digits
581e13c1
MS
1322 as the base 16 number, which is 2 digits per byte. */
1323
c906108c 1324 decimal_len = len * 2 * 2;
3c37485b 1325 digits = xmalloc (decimal_len);
c906108c 1326
c5aa993b
JM
1327 for (i = 0; i < decimal_len; i++)
1328 {
c906108c 1329 digits[i] = 0;
c5aa993b 1330 }
c906108c 1331
c906108c
SS
1332 /* Ok, we have an unknown number of bytes of data to be printed in
1333 * decimal.
1334 *
1335 * Given a hex number (in nibbles) as XYZ, we start by taking X and
1336 * decemalizing it as "x1 x2" in two decimal nibbles. Then we multiply
1337 * the nibbles by 16, add Y and re-decimalize. Repeat with Z.
1338 *
1339 * The trick is that "digits" holds a base-10 number, but sometimes
581e13c1 1340 * the individual digits are > 10.
c906108c
SS
1341 *
1342 * Outer loop is per nibble (hex digit) of input, from MSD end to
1343 * LSD end.
1344 */
c5aa993b 1345 decimal_digits = 0; /* Number of decimal digits so far */
d44e8473 1346 p = (byte_order == BFD_ENDIAN_BIG) ? valaddr : valaddr + len - 1;
c906108c 1347 flip = 0;
d44e8473 1348 while ((byte_order == BFD_ENDIAN_BIG) ? (p < valaddr + len) : (p >= valaddr))
c5aa993b 1349 {
c906108c
SS
1350 /*
1351 * Multiply current base-ten number by 16 in place.
1352 * Each digit was between 0 and 9, now is between
1353 * 0 and 144.
1354 */
c5aa993b
JM
1355 for (j = 0; j < decimal_digits; j++)
1356 {
1357 digits[j] = SHIFT (digits[j]);
1358 }
1359
c906108c
SS
1360 /* Take the next nibble off the input and add it to what
1361 * we've got in the LSB position. Bottom 'digit' is now
1362 * between 0 and 159.
1363 *
1364 * "flip" is used to run this loop twice for each byte.
1365 */
c5aa993b
JM
1366 if (flip == 0)
1367 {
581e13c1
MS
1368 /* Take top nibble. */
1369
c5aa993b
JM
1370 digits[0] += HIGH_NIBBLE (*p);
1371 flip = 1;
1372 }
1373 else
1374 {
581e13c1
MS
1375 /* Take low nibble and bump our pointer "p". */
1376
c5aa993b 1377 digits[0] += LOW_NIBBLE (*p);
d44e8473
MD
1378 if (byte_order == BFD_ENDIAN_BIG)
1379 p++;
1380 else
1381 p--;
c5aa993b
JM
1382 flip = 0;
1383 }
c906108c
SS
1384
1385 /* Re-decimalize. We have to do this often enough
1386 * that we don't overflow, but once per nibble is
1387 * overkill. Easier this way, though. Note that the
1388 * carry is often larger than 10 (e.g. max initial
1389 * carry out of lowest nibble is 15, could bubble all
1390 * the way up greater than 10). So we have to do
1391 * the carrying beyond the last current digit.
1392 */
1393 carry = 0;
c5aa993b
JM
1394 for (j = 0; j < decimal_len - 1; j++)
1395 {
1396 digits[j] += carry;
1397
1398 /* "/" won't handle an unsigned char with
1399 * a value that if signed would be negative.
1400 * So extend to longword int via "dummy".
1401 */
1402 dummy = digits[j];
1403 carry = CARRY_OUT (dummy);
1404 digits[j] = CARRY_LEFT (dummy);
1405
1406 if (j >= decimal_digits && carry == 0)
1407 {
1408 /*
1409 * All higher digits are 0 and we
1410 * no longer have a carry.
1411 *
1412 * Note: "j" is 0-based, "decimal_digits" is
1413 * 1-based.
1414 */
1415 decimal_digits = j + 1;
1416 break;
1417 }
1418 }
1419 }
c906108c
SS
1420
1421 /* Ok, now "digits" is the decimal representation, with
581e13c1
MS
1422 the "decimal_digits" actual digits. Print! */
1423
c5aa993b
JM
1424 for (i = decimal_digits - 1; i >= 0; i--)
1425 {
1426 fprintf_filtered (stream, "%1d", digits[i]);
1427 }
b8c9b27d 1428 xfree (digits);
c906108c
SS
1429}
1430
1431/* VALADDR points to an integer of LEN bytes. Print it in hex on stream. */
1432
6b9acc27 1433void
fc1a4b47 1434print_hex_chars (struct ui_file *stream, const gdb_byte *valaddr,
d44e8473 1435 unsigned len, enum bfd_endian byte_order)
c906108c 1436{
fc1a4b47 1437 const gdb_byte *p;
c906108c
SS
1438
1439 /* FIXME: We should be not printing leading zeroes in most cases. */
1440
bb599908 1441 fputs_filtered ("0x", stream);
d44e8473 1442 if (byte_order == BFD_ENDIAN_BIG)
c906108c
SS
1443 {
1444 for (p = valaddr;
1445 p < valaddr + len;
1446 p++)
1447 {
1448 fprintf_filtered (stream, "%02x", *p);
1449 }
1450 }
1451 else
1452 {
1453 for (p = valaddr + len - 1;
1454 p >= valaddr;
1455 p--)
1456 {
1457 fprintf_filtered (stream, "%02x", *p);
1458 }
1459 }
c906108c
SS
1460}
1461
3e43a32a 1462/* VALADDR points to a char integer of LEN bytes.
581e13c1 1463 Print it out in appropriate language form on stream.
6b9acc27
JJ
1464 Omit any leading zero chars. */
1465
1466void
6c7a06a3
TT
1467print_char_chars (struct ui_file *stream, struct type *type,
1468 const gdb_byte *valaddr,
d44e8473 1469 unsigned len, enum bfd_endian byte_order)
6b9acc27 1470{
fc1a4b47 1471 const gdb_byte *p;
6b9acc27 1472
d44e8473 1473 if (byte_order == BFD_ENDIAN_BIG)
6b9acc27
JJ
1474 {
1475 p = valaddr;
1476 while (p < valaddr + len - 1 && *p == 0)
1477 ++p;
1478
1479 while (p < valaddr + len)
1480 {
6c7a06a3 1481 LA_EMIT_CHAR (*p, type, stream, '\'');
6b9acc27
JJ
1482 ++p;
1483 }
1484 }
1485 else
1486 {
1487 p = valaddr + len - 1;
1488 while (p > valaddr && *p == 0)
1489 --p;
1490
1491 while (p >= valaddr)
1492 {
6c7a06a3 1493 LA_EMIT_CHAR (*p, type, stream, '\'');
6b9acc27
JJ
1494 --p;
1495 }
1496 }
1497}
1498
132c57b4
TT
1499/* Print function pointer with inferior address ADDRESS onto stdio
1500 stream STREAM. */
1501
1502void
edf0c1b7
TT
1503print_function_pointer_address (const struct value_print_options *options,
1504 struct gdbarch *gdbarch,
132c57b4 1505 CORE_ADDR address,
edf0c1b7 1506 struct ui_file *stream)
132c57b4
TT
1507{
1508 CORE_ADDR func_addr
1509 = gdbarch_convert_from_func_ptr_addr (gdbarch, address,
1510 &current_target);
1511
1512 /* If the function pointer is represented by a description, print
1513 the address of the description. */
edf0c1b7 1514 if (options->addressprint && func_addr != address)
132c57b4
TT
1515 {
1516 fputs_filtered ("@", stream);
1517 fputs_filtered (paddress (gdbarch, address), stream);
1518 fputs_filtered (": ", stream);
1519 }
edf0c1b7 1520 print_address_demangle (options, gdbarch, func_addr, stream, demangle);
132c57b4
TT
1521}
1522
1523
79a45b7d 1524/* Print on STREAM using the given OPTIONS the index for the element
e79af960
JB
1525 at INDEX of an array whose index type is INDEX_TYPE. */
1526
1527void
1528maybe_print_array_index (struct type *index_type, LONGEST index,
79a45b7d
TT
1529 struct ui_file *stream,
1530 const struct value_print_options *options)
e79af960
JB
1531{
1532 struct value *index_value;
1533
79a45b7d 1534 if (!options->print_array_indexes)
e79af960
JB
1535 return;
1536
1537 index_value = value_from_longest (index_type, index);
1538
79a45b7d
TT
1539 LA_PRINT_ARRAY_INDEX (index_value, stream, options);
1540}
e79af960 1541
c906108c 1542/* Called by various <lang>_val_print routines to print elements of an
c5aa993b 1543 array in the form "<elem1>, <elem2>, <elem3>, ...".
c906108c 1544
c5aa993b
JM
1545 (FIXME?) Assumes array element separator is a comma, which is correct
1546 for all languages currently handled.
1547 (FIXME?) Some languages have a notation for repeated array elements,
581e13c1 1548 perhaps we should try to use that notation when appropriate. */
c906108c
SS
1549
1550void
490f124f
PA
1551val_print_array_elements (struct type *type,
1552 const gdb_byte *valaddr, int embedded_offset,
a2bd3dcd 1553 CORE_ADDR address, struct ui_file *stream,
79a45b7d 1554 int recurse,
0e03807e 1555 const struct value *val,
79a45b7d 1556 const struct value_print_options *options,
fba45db2 1557 unsigned int i)
c906108c
SS
1558{
1559 unsigned int things_printed = 0;
1560 unsigned len;
e79af960 1561 struct type *elttype, *index_type;
c906108c
SS
1562 unsigned eltlen;
1563 /* Position of the array element we are examining to see
1564 whether it is repeated. */
1565 unsigned int rep1;
1566 /* Number of repetitions we have detected so far. */
1567 unsigned int reps;
dbc98a8b 1568 LONGEST low_bound, high_bound;
c5aa993b 1569
c906108c
SS
1570 elttype = TYPE_TARGET_TYPE (type);
1571 eltlen = TYPE_LENGTH (check_typedef (elttype));
e79af960 1572 index_type = TYPE_INDEX_TYPE (type);
c906108c 1573
dbc98a8b 1574 if (get_array_bounds (type, &low_bound, &high_bound))
75be741b
JB
1575 {
1576 /* The array length should normally be HIGH_BOUND - LOW_BOUND + 1.
1577 But we have to be a little extra careful, because some languages
1578 such as Ada allow LOW_BOUND to be greater than HIGH_BOUND for
1579 empty arrays. In that situation, the array length is just zero,
1580 not negative! */
1581 if (low_bound > high_bound)
1582 len = 0;
1583 else
1584 len = high_bound - low_bound + 1;
1585 }
e936309c
JB
1586 else
1587 {
dbc98a8b
KW
1588 warning (_("unable to get bounds of array, assuming null array"));
1589 low_bound = 0;
1590 len = 0;
168de233
JB
1591 }
1592
c906108c
SS
1593 annotate_array_section_begin (i, elttype);
1594
79a45b7d 1595 for (; i < len && things_printed < options->print_max; i++)
c906108c
SS
1596 {
1597 if (i != 0)
1598 {
79a45b7d 1599 if (options->prettyprint_arrays)
c906108c
SS
1600 {
1601 fprintf_filtered (stream, ",\n");
1602 print_spaces_filtered (2 + 2 * recurse, stream);
1603 }
1604 else
1605 {
1606 fprintf_filtered (stream, ", ");
1607 }
1608 }
1609 wrap_here (n_spaces (2 + 2 * recurse));
dbc98a8b 1610 maybe_print_array_index (index_type, i + low_bound,
79a45b7d 1611 stream, options);
c906108c
SS
1612
1613 rep1 = i + 1;
1614 reps = 1;
35bef4fd
TT
1615 /* Only check for reps if repeat_count_threshold is not set to
1616 UINT_MAX (unlimited). */
1617 if (options->repeat_count_threshold < UINT_MAX)
c906108c 1618 {
35bef4fd
TT
1619 while (rep1 < len
1620 && value_available_contents_eq (val,
1621 embedded_offset + i * eltlen,
1622 val,
1623 (embedded_offset
1624 + rep1 * eltlen),
1625 eltlen))
1626 {
1627 ++reps;
1628 ++rep1;
1629 }
c906108c
SS
1630 }
1631
79a45b7d 1632 if (reps > options->repeat_count_threshold)
c906108c 1633 {
490f124f
PA
1634 val_print (elttype, valaddr, embedded_offset + i * eltlen,
1635 address, stream, recurse + 1, val, options,
1636 current_language);
c906108c
SS
1637 annotate_elt_rep (reps);
1638 fprintf_filtered (stream, " <repeats %u times>", reps);
1639 annotate_elt_rep_end ();
1640
1641 i = rep1 - 1;
79a45b7d 1642 things_printed += options->repeat_count_threshold;
c906108c
SS
1643 }
1644 else
1645 {
490f124f
PA
1646 val_print (elttype, valaddr, embedded_offset + i * eltlen,
1647 address,
0e03807e 1648 stream, recurse + 1, val, options, current_language);
c906108c
SS
1649 annotate_elt ();
1650 things_printed++;
1651 }
1652 }
1653 annotate_array_section_end ();
1654 if (i < len)
1655 {
1656 fprintf_filtered (stream, "...");
1657 }
1658}
1659
917317f4
JM
1660/* Read LEN bytes of target memory at address MEMADDR, placing the
1661 results in GDB's memory at MYADDR. Returns a count of the bytes
1662 actually read, and optionally an errno value in the location
581e13c1 1663 pointed to by ERRNOPTR if ERRNOPTR is non-null. */
917317f4
JM
1664
1665/* FIXME: cagney/1999-10-14: Only used by val_print_string. Can this
1666 function be eliminated. */
1667
1668static int
3e43a32a
MS
1669partial_memory_read (CORE_ADDR memaddr, gdb_byte *myaddr,
1670 int len, int *errnoptr)
917317f4 1671{
581e13c1
MS
1672 int nread; /* Number of bytes actually read. */
1673 int errcode; /* Error from last read. */
917317f4 1674
581e13c1 1675 /* First try a complete read. */
917317f4
JM
1676 errcode = target_read_memory (memaddr, myaddr, len);
1677 if (errcode == 0)
1678 {
581e13c1 1679 /* Got it all. */
917317f4
JM
1680 nread = len;
1681 }
1682 else
1683 {
581e13c1 1684 /* Loop, reading one byte at a time until we get as much as we can. */
917317f4
JM
1685 for (errcode = 0, nread = 0; len > 0 && errcode == 0; nread++, len--)
1686 {
1687 errcode = target_read_memory (memaddr++, myaddr++, 1);
1688 }
581e13c1 1689 /* If an error, the last read was unsuccessful, so adjust count. */
917317f4
JM
1690 if (errcode != 0)
1691 {
1692 nread--;
1693 }
1694 }
1695 if (errnoptr != NULL)
1696 {
1697 *errnoptr = errcode;
1698 }
1699 return (nread);
1700}
1701
ae6a3a4c
TJB
1702/* Read a string from the inferior, at ADDR, with LEN characters of WIDTH bytes
1703 each. Fetch at most FETCHLIMIT characters. BUFFER will be set to a newly
1704 allocated buffer containing the string, which the caller is responsible to
1705 free, and BYTES_READ will be set to the number of bytes read. Returns 0 on
1706 success, or errno on failure.
1707
1708 If LEN > 0, reads exactly LEN characters (including eventual NULs in
1709 the middle or end of the string). If LEN is -1, stops at the first
1710 null character (not necessarily the first null byte) up to a maximum
1711 of FETCHLIMIT characters. Set FETCHLIMIT to UINT_MAX to read as many
1712 characters as possible from the string.
1713
1714 Unless an exception is thrown, BUFFER will always be allocated, even on
1715 failure. In this case, some characters might have been read before the
1716 failure happened. Check BYTES_READ to recognize this situation.
1717
1718 Note: There was a FIXME asking to make this code use target_read_string,
1719 but this function is more general (can read past null characters, up to
581e13c1 1720 given LEN). Besides, it is used much more often than target_read_string
ae6a3a4c
TJB
1721 so it is more tested. Perhaps callers of target_read_string should use
1722 this function instead? */
c906108c
SS
1723
1724int
ae6a3a4c 1725read_string (CORE_ADDR addr, int len, int width, unsigned int fetchlimit,
e17a4113 1726 enum bfd_endian byte_order, gdb_byte **buffer, int *bytes_read)
c906108c 1727{
ae6a3a4c
TJB
1728 int found_nul; /* Non-zero if we found the nul char. */
1729 int errcode; /* Errno returned from bad reads. */
1730 unsigned int nfetch; /* Chars to fetch / chars fetched. */
1731 unsigned int chunksize; /* Size of each fetch, in chars. */
3e43a32a
MS
1732 gdb_byte *bufptr; /* Pointer to next available byte in
1733 buffer. */
ae6a3a4c
TJB
1734 gdb_byte *limit; /* First location past end of fetch buffer. */
1735 struct cleanup *old_chain = NULL; /* Top of the old cleanup chain. */
1736
1737 /* Decide how large of chunks to try to read in one operation. This
c906108c
SS
1738 is also pretty simple. If LEN >= zero, then we want fetchlimit chars,
1739 so we might as well read them all in one operation. If LEN is -1, we
ae6a3a4c 1740 are looking for a NUL terminator to end the fetching, so we might as
c906108c
SS
1741 well read in blocks that are large enough to be efficient, but not so
1742 large as to be slow if fetchlimit happens to be large. So we choose the
1743 minimum of 8 and fetchlimit. We used to use 200 instead of 8 but
1744 200 is way too big for remote debugging over a serial line. */
1745
1746 chunksize = (len == -1 ? min (8, fetchlimit) : fetchlimit);
1747
ae6a3a4c
TJB
1748 /* Loop until we either have all the characters, or we encounter
1749 some error, such as bumping into the end of the address space. */
c906108c
SS
1750
1751 found_nul = 0;
b5096abe
PM
1752 *buffer = NULL;
1753
1754 old_chain = make_cleanup (free_current_contents, buffer);
c906108c
SS
1755
1756 if (len > 0)
1757 {
ae6a3a4c
TJB
1758 *buffer = (gdb_byte *) xmalloc (len * width);
1759 bufptr = *buffer;
c906108c 1760
917317f4 1761 nfetch = partial_memory_read (addr, bufptr, len * width, &errcode)
c906108c
SS
1762 / width;
1763 addr += nfetch * width;
1764 bufptr += nfetch * width;
1765 }
1766 else if (len == -1)
1767 {
1768 unsigned long bufsize = 0;
ae6a3a4c 1769
c906108c
SS
1770 do
1771 {
1772 QUIT;
1773 nfetch = min (chunksize, fetchlimit - bufsize);
1774
ae6a3a4c
TJB
1775 if (*buffer == NULL)
1776 *buffer = (gdb_byte *) xmalloc (nfetch * width);
c906108c 1777 else
b5096abe
PM
1778 *buffer = (gdb_byte *) xrealloc (*buffer,
1779 (nfetch + bufsize) * width);
c906108c 1780
ae6a3a4c 1781 bufptr = *buffer + bufsize * width;
c906108c
SS
1782 bufsize += nfetch;
1783
ae6a3a4c 1784 /* Read as much as we can. */
917317f4 1785 nfetch = partial_memory_read (addr, bufptr, nfetch * width, &errcode)
ae6a3a4c 1786 / width;
c906108c 1787
ae6a3a4c 1788 /* Scan this chunk for the null character that terminates the string
c906108c
SS
1789 to print. If found, we don't need to fetch any more. Note
1790 that bufptr is explicitly left pointing at the next character
ae6a3a4c
TJB
1791 after the null character, or at the next character after the end
1792 of the buffer. */
c906108c
SS
1793
1794 limit = bufptr + nfetch * width;
1795 while (bufptr < limit)
1796 {
1797 unsigned long c;
1798
e17a4113 1799 c = extract_unsigned_integer (bufptr, width, byte_order);
c906108c
SS
1800 addr += width;
1801 bufptr += width;
1802 if (c == 0)
1803 {
1804 /* We don't care about any error which happened after
ae6a3a4c 1805 the NUL terminator. */
c906108c
SS
1806 errcode = 0;
1807 found_nul = 1;
1808 break;
1809 }
1810 }
1811 }
c5aa993b 1812 while (errcode == 0 /* no error */
ae6a3a4c
TJB
1813 && bufptr - *buffer < fetchlimit * width /* no overrun */
1814 && !found_nul); /* haven't found NUL yet */
c906108c
SS
1815 }
1816 else
ae6a3a4c
TJB
1817 { /* Length of string is really 0! */
1818 /* We always allocate *buffer. */
1819 *buffer = bufptr = xmalloc (1);
c906108c
SS
1820 errcode = 0;
1821 }
1822
1823 /* bufptr and addr now point immediately beyond the last byte which we
1824 consider part of the string (including a '\0' which ends the string). */
ae6a3a4c
TJB
1825 *bytes_read = bufptr - *buffer;
1826
1827 QUIT;
1828
1829 discard_cleanups (old_chain);
1830
1831 return errcode;
1832}
1833
3b2b8fea
TT
1834/* Return true if print_wchar can display W without resorting to a
1835 numeric escape, false otherwise. */
1836
1837static int
1838wchar_printable (gdb_wchar_t w)
1839{
1840 return (gdb_iswprint (w)
1841 || w == LCST ('\a') || w == LCST ('\b')
1842 || w == LCST ('\f') || w == LCST ('\n')
1843 || w == LCST ('\r') || w == LCST ('\t')
1844 || w == LCST ('\v'));
1845}
1846
1847/* A helper function that converts the contents of STRING to wide
1848 characters and then appends them to OUTPUT. */
1849
1850static void
1851append_string_as_wide (const char *string,
1852 struct obstack *output)
1853{
1854 for (; *string; ++string)
1855 {
1856 gdb_wchar_t w = gdb_btowc (*string);
1857 obstack_grow (output, &w, sizeof (gdb_wchar_t));
1858 }
1859}
1860
1861/* Print a wide character W to OUTPUT. ORIG is a pointer to the
1862 original (target) bytes representing the character, ORIG_LEN is the
1863 number of valid bytes. WIDTH is the number of bytes in a base
1864 characters of the type. OUTPUT is an obstack to which wide
1865 characters are emitted. QUOTER is a (narrow) character indicating
1866 the style of quotes surrounding the character to be printed.
1867 NEED_ESCAPE is an in/out flag which is used to track numeric
1868 escapes across calls. */
1869
1870static void
1871print_wchar (gdb_wint_t w, const gdb_byte *orig,
1872 int orig_len, int width,
1873 enum bfd_endian byte_order,
1874 struct obstack *output,
1875 int quoter, int *need_escapep)
1876{
1877 int need_escape = *need_escapep;
1878
1879 *need_escapep = 0;
1880 if (gdb_iswprint (w) && (!need_escape || (!gdb_iswdigit (w)
1881 && w != LCST ('8')
1882 && w != LCST ('9'))))
1883 {
1884 gdb_wchar_t wchar = w;
1885
1886 if (w == gdb_btowc (quoter) || w == LCST ('\\'))
1887 obstack_grow_wstr (output, LCST ("\\"));
1888 obstack_grow (output, &wchar, sizeof (gdb_wchar_t));
1889 }
1890 else
1891 {
1892 switch (w)
1893 {
1894 case LCST ('\a'):
1895 obstack_grow_wstr (output, LCST ("\\a"));
1896 break;
1897 case LCST ('\b'):
1898 obstack_grow_wstr (output, LCST ("\\b"));
1899 break;
1900 case LCST ('\f'):
1901 obstack_grow_wstr (output, LCST ("\\f"));
1902 break;
1903 case LCST ('\n'):
1904 obstack_grow_wstr (output, LCST ("\\n"));
1905 break;
1906 case LCST ('\r'):
1907 obstack_grow_wstr (output, LCST ("\\r"));
1908 break;
1909 case LCST ('\t'):
1910 obstack_grow_wstr (output, LCST ("\\t"));
1911 break;
1912 case LCST ('\v'):
1913 obstack_grow_wstr (output, LCST ("\\v"));
1914 break;
1915 default:
1916 {
1917 int i;
1918
1919 for (i = 0; i + width <= orig_len; i += width)
1920 {
1921 char octal[30];
1922 ULONGEST value;
1923
1924 value = extract_unsigned_integer (&orig[i], width,
1925 byte_order);
1926 /* If the value fits in 3 octal digits, print it that
1927 way. Otherwise, print it as a hex escape. */
1928 if (value <= 0777)
1929 sprintf (octal, "\\%.3o", (int) (value & 0777));
1930 else
1931 sprintf (octal, "\\x%lx", (long) value);
1932 append_string_as_wide (octal, output);
1933 }
1934 /* If we somehow have extra bytes, print them now. */
1935 while (i < orig_len)
1936 {
1937 char octal[5];
1938
1939 sprintf (octal, "\\%.3o", orig[i] & 0xff);
1940 append_string_as_wide (octal, output);
1941 ++i;
1942 }
1943
1944 *need_escapep = 1;
1945 }
1946 break;
1947 }
1948 }
1949}
1950
1951/* Print the character C on STREAM as part of the contents of a
1952 literal string whose delimiter is QUOTER. ENCODING names the
1953 encoding of C. */
1954
1955void
1956generic_emit_char (int c, struct type *type, struct ui_file *stream,
1957 int quoter, const char *encoding)
1958{
1959 enum bfd_endian byte_order
1960 = gdbarch_byte_order (get_type_arch (type));
1961 struct obstack wchar_buf, output;
1962 struct cleanup *cleanups;
1963 gdb_byte *buf;
1964 struct wchar_iterator *iter;
1965 int need_escape = 0;
1966
1967 buf = alloca (TYPE_LENGTH (type));
1968 pack_long (buf, type, c);
1969
1970 iter = make_wchar_iterator (buf, TYPE_LENGTH (type),
1971 encoding, TYPE_LENGTH (type));
1972 cleanups = make_cleanup_wchar_iterator (iter);
1973
1974 /* This holds the printable form of the wchar_t data. */
1975 obstack_init (&wchar_buf);
1976 make_cleanup_obstack_free (&wchar_buf);
1977
1978 while (1)
1979 {
1980 int num_chars;
1981 gdb_wchar_t *chars;
1982 const gdb_byte *buf;
1983 size_t buflen;
1984 int print_escape = 1;
1985 enum wchar_iterate_result result;
1986
1987 num_chars = wchar_iterate (iter, &result, &chars, &buf, &buflen);
1988 if (num_chars < 0)
1989 break;
1990 if (num_chars > 0)
1991 {
1992 /* If all characters are printable, print them. Otherwise,
1993 we're going to have to print an escape sequence. We
1994 check all characters because we want to print the target
1995 bytes in the escape sequence, and we don't know character
1996 boundaries there. */
1997 int i;
1998
1999 print_escape = 0;
2000 for (i = 0; i < num_chars; ++i)
2001 if (!wchar_printable (chars[i]))
2002 {
2003 print_escape = 1;
2004 break;
2005 }
2006
2007 if (!print_escape)
2008 {
2009 for (i = 0; i < num_chars; ++i)
2010 print_wchar (chars[i], buf, buflen,
2011 TYPE_LENGTH (type), byte_order,
2012 &wchar_buf, quoter, &need_escape);
2013 }
2014 }
2015
2016 /* This handles the NUM_CHARS == 0 case as well. */
2017 if (print_escape)
2018 print_wchar (gdb_WEOF, buf, buflen, TYPE_LENGTH (type),
2019 byte_order, &wchar_buf, quoter, &need_escape);
2020 }
2021
2022 /* The output in the host encoding. */
2023 obstack_init (&output);
2024 make_cleanup_obstack_free (&output);
2025
2026 convert_between_encodings (INTERMEDIATE_ENCODING, host_charset (),
2027 obstack_base (&wchar_buf),
2028 obstack_object_size (&wchar_buf),
2029 1, &output, translit_char);
2030 obstack_1grow (&output, '\0');
2031
2032 fputs_filtered (obstack_base (&output), stream);
2033
2034 do_cleanups (cleanups);
2035}
2036
2037/* Print the character string STRING, printing at most LENGTH
2038 characters. LENGTH is -1 if the string is nul terminated. TYPE is
2039 the type of each character. OPTIONS holds the printing options;
2040 printing stops early if the number hits print_max; repeat counts
2041 are printed as appropriate. Print ellipses at the end if we had to
2042 stop before printing LENGTH characters, or if FORCE_ELLIPSES.
2043 QUOTE_CHAR is the character to print at each end of the string. If
2044 C_STYLE_TERMINATOR is true, and the last character is 0, then it is
2045 omitted. */
2046
2047void
2048generic_printstr (struct ui_file *stream, struct type *type,
2049 const gdb_byte *string, unsigned int length,
2050 const char *encoding, int force_ellipses,
2051 int quote_char, int c_style_terminator,
2052 const struct value_print_options *options)
2053{
2054 enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
2055 unsigned int i;
2056 unsigned int things_printed = 0;
2057 int in_quotes = 0;
2058 int need_comma = 0;
2059 int width = TYPE_LENGTH (type);
2060 struct obstack wchar_buf, output;
2061 struct cleanup *cleanup;
2062 struct wchar_iterator *iter;
2063 int finished = 0;
2064 int need_escape = 0;
2065 gdb_wchar_t wide_quote_char = gdb_btowc (quote_char);
2066
2067 if (length == -1)
2068 {
2069 unsigned long current_char = 1;
2070
2071 for (i = 0; current_char; ++i)
2072 {
2073 QUIT;
2074 current_char = extract_unsigned_integer (string + i * width,
2075 width, byte_order);
2076 }
2077 length = i;
2078 }
2079
2080 /* If the string was not truncated due to `set print elements', and
2081 the last byte of it is a null, we don't print that, in
2082 traditional C style. */
2083 if (c_style_terminator
2084 && !force_ellipses
2085 && length > 0
2086 && (extract_unsigned_integer (string + (length - 1) * width,
2087 width, byte_order) == 0))
2088 length--;
2089
2090 if (length == 0)
2091 {
2092 fputs_filtered ("\"\"", stream);
2093 return;
2094 }
2095
2096 /* Arrange to iterate over the characters, in wchar_t form. */
2097 iter = make_wchar_iterator (string, length * width, encoding, width);
2098 cleanup = make_cleanup_wchar_iterator (iter);
2099
2100 /* WCHAR_BUF is the obstack we use to represent the string in
2101 wchar_t form. */
2102 obstack_init (&wchar_buf);
2103 make_cleanup_obstack_free (&wchar_buf);
2104
2105 while (!finished && things_printed < options->print_max)
2106 {
2107 int num_chars;
2108 enum wchar_iterate_result result;
2109 gdb_wchar_t *chars;
2110 const gdb_byte *buf;
2111 size_t buflen;
2112
2113 QUIT;
2114
2115 if (need_comma)
2116 {
2117 obstack_grow_wstr (&wchar_buf, LCST (", "));
2118 need_comma = 0;
2119 }
2120
2121 num_chars = wchar_iterate (iter, &result, &chars, &buf, &buflen);
2122 /* We only look at repetitions when we were able to convert a
2123 single character in isolation. This makes the code simpler
2124 and probably does the sensible thing in the majority of
2125 cases. */
2126 while (num_chars == 1 && things_printed < options->print_max)
2127 {
2128 /* Count the number of repetitions. */
2129 unsigned int reps = 0;
2130 gdb_wchar_t current_char = chars[0];
2131 const gdb_byte *orig_buf = buf;
2132 int orig_len = buflen;
2133
2134 if (need_comma)
2135 {
2136 obstack_grow_wstr (&wchar_buf, LCST (", "));
2137 need_comma = 0;
2138 }
2139
2140 while (num_chars == 1 && current_char == chars[0])
2141 {
2142 num_chars = wchar_iterate (iter, &result, &chars,
2143 &buf, &buflen);
2144 ++reps;
2145 }
2146
2147 /* Emit CURRENT_CHAR according to the repetition count and
2148 options. */
2149 if (reps > options->repeat_count_threshold)
2150 {
2151 if (in_quotes)
2152 {
2153 if (options->inspect_it)
2154 obstack_grow_wstr (&wchar_buf, LCST ("\\"));
2155 obstack_grow (&wchar_buf, &wide_quote_char,
2156 sizeof (gdb_wchar_t));
2157 obstack_grow_wstr (&wchar_buf, LCST (", "));
2158 in_quotes = 0;
2159 }
2160 obstack_grow_wstr (&wchar_buf, LCST ("'"));
2161 need_escape = 0;
2162 print_wchar (current_char, orig_buf, orig_len, width,
2163 byte_order, &wchar_buf, '\'', &need_escape);
2164 obstack_grow_wstr (&wchar_buf, LCST ("'"));
2165 {
2166 /* Painful gyrations. */
2167 int j;
2168 char *s = xstrprintf (_(" <repeats %u times>"), reps);
2169
2170 for (j = 0; s[j]; ++j)
2171 {
2172 gdb_wchar_t w = gdb_btowc (s[j]);
2173 obstack_grow (&wchar_buf, &w, sizeof (gdb_wchar_t));
2174 }
2175 xfree (s);
2176 }
2177 things_printed += options->repeat_count_threshold;
2178 need_comma = 1;
2179 }
2180 else
2181 {
2182 /* Saw the character one or more times, but fewer than
2183 the repetition threshold. */
2184 if (!in_quotes)
2185 {
2186 if (options->inspect_it)
2187 obstack_grow_wstr (&wchar_buf, LCST ("\\"));
2188 obstack_grow (&wchar_buf, &wide_quote_char,
2189 sizeof (gdb_wchar_t));
2190 in_quotes = 1;
2191 need_escape = 0;
2192 }
2193
2194 while (reps-- > 0)
2195 {
2196 print_wchar (current_char, orig_buf,
2197 orig_len, width,
2198 byte_order, &wchar_buf,
2199 quote_char, &need_escape);
2200 ++things_printed;
2201 }
2202 }
2203 }
2204
2205 /* NUM_CHARS and the other outputs from wchar_iterate are valid
2206 here regardless of which branch was taken above. */
2207 if (num_chars < 0)
2208 {
2209 /* Hit EOF. */
2210 finished = 1;
2211 break;
2212 }
2213
2214 switch (result)
2215 {
2216 case wchar_iterate_invalid:
2217 if (!in_quotes)
2218 {
2219 if (options->inspect_it)
2220 obstack_grow_wstr (&wchar_buf, LCST ("\\"));
2221 obstack_grow (&wchar_buf, &wide_quote_char,
2222 sizeof (gdb_wchar_t));
2223 in_quotes = 1;
2224 }
2225 need_escape = 0;
2226 print_wchar (gdb_WEOF, buf, buflen, width, byte_order,
2227 &wchar_buf, quote_char, &need_escape);
2228 break;
2229
2230 case wchar_iterate_incomplete:
2231 if (in_quotes)
2232 {
2233 if (options->inspect_it)
2234 obstack_grow_wstr (&wchar_buf, LCST ("\\"));
2235 obstack_grow (&wchar_buf, &wide_quote_char,
2236 sizeof (gdb_wchar_t));
2237 obstack_grow_wstr (&wchar_buf, LCST (","));
2238 in_quotes = 0;
2239 }
2240 obstack_grow_wstr (&wchar_buf,
2241 LCST (" <incomplete sequence "));
2242 print_wchar (gdb_WEOF, buf, buflen, width,
2243 byte_order, &wchar_buf,
2244 0, &need_escape);
2245 obstack_grow_wstr (&wchar_buf, LCST (">"));
2246 finished = 1;
2247 break;
2248 }
2249 }
2250
2251 /* Terminate the quotes if necessary. */
2252 if (in_quotes)
2253 {
2254 if (options->inspect_it)
2255 obstack_grow_wstr (&wchar_buf, LCST ("\\"));
2256 obstack_grow (&wchar_buf, &wide_quote_char,
2257 sizeof (gdb_wchar_t));
2258 }
2259
2260 if (force_ellipses || !finished)
2261 obstack_grow_wstr (&wchar_buf, LCST ("..."));
2262
2263 /* OUTPUT is where we collect `char's for printing. */
2264 obstack_init (&output);
2265 make_cleanup_obstack_free (&output);
2266
2267 convert_between_encodings (INTERMEDIATE_ENCODING, host_charset (),
2268 obstack_base (&wchar_buf),
2269 obstack_object_size (&wchar_buf),
2270 1, &output, translit_char);
2271 obstack_1grow (&output, '\0');
2272
2273 fputs_filtered (obstack_base (&output), stream);
2274
2275 do_cleanups (cleanup);
2276}
2277
ae6a3a4c
TJB
2278/* Print a string from the inferior, starting at ADDR and printing up to LEN
2279 characters, of WIDTH bytes a piece, to STREAM. If LEN is -1, printing
2280 stops at the first null byte, otherwise printing proceeds (including null
2281 bytes) until either print_max or LEN characters have been printed,
09ca9e2e
TT
2282 whichever is smaller. ENCODING is the name of the string's
2283 encoding. It can be NULL, in which case the target encoding is
2284 assumed. */
ae6a3a4c
TJB
2285
2286int
09ca9e2e
TT
2287val_print_string (struct type *elttype, const char *encoding,
2288 CORE_ADDR addr, int len,
6c7a06a3 2289 struct ui_file *stream,
ae6a3a4c
TJB
2290 const struct value_print_options *options)
2291{
2292 int force_ellipsis = 0; /* Force ellipsis to be printed if nonzero. */
2293 int errcode; /* Errno returned from bad reads. */
581e13c1 2294 int found_nul; /* Non-zero if we found the nul char. */
ae6a3a4c
TJB
2295 unsigned int fetchlimit; /* Maximum number of chars to print. */
2296 int bytes_read;
2297 gdb_byte *buffer = NULL; /* Dynamically growable fetch buffer. */
2298 struct cleanup *old_chain = NULL; /* Top of the old cleanup chain. */
5af949e3 2299 struct gdbarch *gdbarch = get_type_arch (elttype);
e17a4113 2300 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
6c7a06a3 2301 int width = TYPE_LENGTH (elttype);
ae6a3a4c
TJB
2302
2303 /* First we need to figure out the limit on the number of characters we are
2304 going to attempt to fetch and print. This is actually pretty simple. If
2305 LEN >= zero, then the limit is the minimum of LEN and print_max. If
2306 LEN is -1, then the limit is print_max. This is true regardless of
2307 whether print_max is zero, UINT_MAX (unlimited), or something in between,
2308 because finding the null byte (or available memory) is what actually
2309 limits the fetch. */
2310
3e43a32a
MS
2311 fetchlimit = (len == -1 ? options->print_max : min (len,
2312 options->print_max));
ae6a3a4c 2313
e17a4113
UW
2314 errcode = read_string (addr, len, width, fetchlimit, byte_order,
2315 &buffer, &bytes_read);
ae6a3a4c
TJB
2316 old_chain = make_cleanup (xfree, buffer);
2317
2318 addr += bytes_read;
c906108c 2319
3e43a32a
MS
2320 /* We now have either successfully filled the buffer to fetchlimit,
2321 or terminated early due to an error or finding a null char when
2322 LEN is -1. */
ae6a3a4c
TJB
2323
2324 /* Determine found_nul by looking at the last character read. */
e17a4113
UW
2325 found_nul = extract_unsigned_integer (buffer + bytes_read - width, width,
2326 byte_order) == 0;
c906108c
SS
2327 if (len == -1 && !found_nul)
2328 {
777ea8f1 2329 gdb_byte *peekbuf;
c906108c 2330
ae6a3a4c 2331 /* We didn't find a NUL terminator we were looking for. Attempt
c5aa993b
JM
2332 to peek at the next character. If not successful, or it is not
2333 a null byte, then force ellipsis to be printed. */
c906108c 2334
777ea8f1 2335 peekbuf = (gdb_byte *) alloca (width);
c906108c
SS
2336
2337 if (target_read_memory (addr, peekbuf, width) == 0
e17a4113 2338 && extract_unsigned_integer (peekbuf, width, byte_order) != 0)
c906108c
SS
2339 force_ellipsis = 1;
2340 }
ae6a3a4c 2341 else if ((len >= 0 && errcode != 0) || (len > bytes_read / width))
c906108c
SS
2342 {
2343 /* Getting an error when we have a requested length, or fetching less
c5aa993b 2344 than the number of characters actually requested, always make us
ae6a3a4c 2345 print ellipsis. */
c906108c
SS
2346 force_ellipsis = 1;
2347 }
2348
c906108c
SS
2349 /* If we get an error before fetching anything, don't print a string.
2350 But if we fetch something and then get an error, print the string
2351 and then the error message. */
ae6a3a4c 2352 if (errcode == 0 || bytes_read > 0)
c906108c 2353 {
79a45b7d 2354 if (options->addressprint)
c906108c
SS
2355 {
2356 fputs_filtered (" ", stream);
2357 }
be759fcf 2358 LA_PRINT_STRING (stream, elttype, buffer, bytes_read / width,
3a772aa4 2359 encoding, force_ellipsis, options);
c906108c
SS
2360 }
2361
2362 if (errcode != 0)
2363 {
2364 if (errcode == EIO)
2365 {
2366 fprintf_filtered (stream, " <Address ");
5af949e3 2367 fputs_filtered (paddress (gdbarch, addr), stream);
c906108c
SS
2368 fprintf_filtered (stream, " out of bounds>");
2369 }
2370 else
2371 {
2372 fprintf_filtered (stream, " <Error reading address ");
5af949e3 2373 fputs_filtered (paddress (gdbarch, addr), stream);
c906108c
SS
2374 fprintf_filtered (stream, ": %s>", safe_strerror (errcode));
2375 }
2376 }
ae6a3a4c 2377
c906108c
SS
2378 gdb_flush (stream);
2379 do_cleanups (old_chain);
ae6a3a4c
TJB
2380
2381 return (bytes_read / width);
c906108c 2382}
c906108c 2383\f
c5aa993b 2384
09e6485f
PA
2385/* The 'set input-radix' command writes to this auxiliary variable.
2386 If the requested radix is valid, INPUT_RADIX is updated; otherwise,
2387 it is left unchanged. */
2388
2389static unsigned input_radix_1 = 10;
2390
c906108c
SS
2391/* Validate an input or output radix setting, and make sure the user
2392 knows what they really did here. Radix setting is confusing, e.g.
2393 setting the input radix to "10" never changes it! */
2394
c906108c 2395static void
fba45db2 2396set_input_radix (char *args, int from_tty, struct cmd_list_element *c)
c906108c 2397{
09e6485f 2398 set_input_radix_1 (from_tty, input_radix_1);
c906108c
SS
2399}
2400
c906108c 2401static void
fba45db2 2402set_input_radix_1 (int from_tty, unsigned radix)
c906108c
SS
2403{
2404 /* We don't currently disallow any input radix except 0 or 1, which don't
2405 make any mathematical sense. In theory, we can deal with any input
2406 radix greater than 1, even if we don't have unique digits for every
2407 value from 0 to radix-1, but in practice we lose on large radix values.
2408 We should either fix the lossage or restrict the radix range more.
581e13c1 2409 (FIXME). */
c906108c
SS
2410
2411 if (radix < 2)
2412 {
09e6485f 2413 input_radix_1 = input_radix;
8a3fe4f8 2414 error (_("Nonsense input radix ``decimal %u''; input radix unchanged."),
c906108c
SS
2415 radix);
2416 }
09e6485f 2417 input_radix_1 = input_radix = radix;
c906108c
SS
2418 if (from_tty)
2419 {
3e43a32a
MS
2420 printf_filtered (_("Input radix now set to "
2421 "decimal %u, hex %x, octal %o.\n"),
c906108c
SS
2422 radix, radix, radix);
2423 }
2424}
2425
09e6485f
PA
2426/* The 'set output-radix' command writes to this auxiliary variable.
2427 If the requested radix is valid, OUTPUT_RADIX is updated,
2428 otherwise, it is left unchanged. */
2429
2430static unsigned output_radix_1 = 10;
2431
c906108c 2432static void
fba45db2 2433set_output_radix (char *args, int from_tty, struct cmd_list_element *c)
c906108c 2434{
09e6485f 2435 set_output_radix_1 (from_tty, output_radix_1);
c906108c
SS
2436}
2437
2438static void
fba45db2 2439set_output_radix_1 (int from_tty, unsigned radix)
c906108c
SS
2440{
2441 /* Validate the radix and disallow ones that we aren't prepared to
581e13c1 2442 handle correctly, leaving the radix unchanged. */
c906108c
SS
2443 switch (radix)
2444 {
2445 case 16:
79a45b7d 2446 user_print_options.output_format = 'x'; /* hex */
c906108c
SS
2447 break;
2448 case 10:
79a45b7d 2449 user_print_options.output_format = 0; /* decimal */
c906108c
SS
2450 break;
2451 case 8:
79a45b7d 2452 user_print_options.output_format = 'o'; /* octal */
c906108c
SS
2453 break;
2454 default:
09e6485f 2455 output_radix_1 = output_radix;
3e43a32a
MS
2456 error (_("Unsupported output radix ``decimal %u''; "
2457 "output radix unchanged."),
c906108c
SS
2458 radix);
2459 }
09e6485f 2460 output_radix_1 = output_radix = radix;
c906108c
SS
2461 if (from_tty)
2462 {
3e43a32a
MS
2463 printf_filtered (_("Output radix now set to "
2464 "decimal %u, hex %x, octal %o.\n"),
c906108c
SS
2465 radix, radix, radix);
2466 }
2467}
2468
2469/* Set both the input and output radix at once. Try to set the output radix
2470 first, since it has the most restrictive range. An radix that is valid as
2471 an output radix is also valid as an input radix.
2472
2473 It may be useful to have an unusual input radix. If the user wishes to
2474 set an input radix that is not valid as an output radix, he needs to use
581e13c1 2475 the 'set input-radix' command. */
c906108c
SS
2476
2477static void
fba45db2 2478set_radix (char *arg, int from_tty)
c906108c
SS
2479{
2480 unsigned radix;
2481
bb518678 2482 radix = (arg == NULL) ? 10 : parse_and_eval_long (arg);
c906108c
SS
2483 set_output_radix_1 (0, radix);
2484 set_input_radix_1 (0, radix);
2485 if (from_tty)
2486 {
3e43a32a
MS
2487 printf_filtered (_("Input and output radices now set to "
2488 "decimal %u, hex %x, octal %o.\n"),
c906108c
SS
2489 radix, radix, radix);
2490 }
2491}
2492
581e13c1 2493/* Show both the input and output radices. */
c906108c 2494
c906108c 2495static void
fba45db2 2496show_radix (char *arg, int from_tty)
c906108c
SS
2497{
2498 if (from_tty)
2499 {
2500 if (input_radix == output_radix)
2501 {
3e43a32a
MS
2502 printf_filtered (_("Input and output radices set to "
2503 "decimal %u, hex %x, octal %o.\n"),
c906108c
SS
2504 input_radix, input_radix, input_radix);
2505 }
2506 else
2507 {
3e43a32a
MS
2508 printf_filtered (_("Input radix set to decimal "
2509 "%u, hex %x, octal %o.\n"),
c906108c 2510 input_radix, input_radix, input_radix);
3e43a32a
MS
2511 printf_filtered (_("Output radix set to decimal "
2512 "%u, hex %x, octal %o.\n"),
c906108c
SS
2513 output_radix, output_radix, output_radix);
2514 }
2515 }
2516}
c906108c 2517\f
c5aa993b 2518
c906108c 2519static void
fba45db2 2520set_print (char *arg, int from_tty)
c906108c
SS
2521{
2522 printf_unfiltered (
c5aa993b 2523 "\"set print\" must be followed by the name of a print subcommand.\n");
c906108c
SS
2524 help_list (setprintlist, "set print ", -1, gdb_stdout);
2525}
2526
c906108c 2527static void
fba45db2 2528show_print (char *args, int from_tty)
c906108c
SS
2529{
2530 cmd_show_list (showprintlist, from_tty, "");
2531}
2532\f
2533void
fba45db2 2534_initialize_valprint (void)
c906108c 2535{
c906108c 2536 add_prefix_cmd ("print", no_class, set_print,
1bedd215 2537 _("Generic command for setting how things print."),
c906108c 2538 &setprintlist, "set print ", 0, &setlist);
c5aa993b 2539 add_alias_cmd ("p", "print", no_class, 1, &setlist);
581e13c1 2540 /* Prefer set print to set prompt. */
c906108c
SS
2541 add_alias_cmd ("pr", "print", no_class, 1, &setlist);
2542
2543 add_prefix_cmd ("print", no_class, show_print,
1bedd215 2544 _("Generic command for showing print settings."),
c906108c 2545 &showprintlist, "show print ", 0, &showlist);
c5aa993b
JM
2546 add_alias_cmd ("p", "print", no_class, 1, &showlist);
2547 add_alias_cmd ("pr", "print", no_class, 1, &showlist);
c906108c 2548
79a45b7d
TT
2549 add_setshow_uinteger_cmd ("elements", no_class,
2550 &user_print_options.print_max, _("\
35096d9d
AC
2551Set limit on string chars or array elements to print."), _("\
2552Show limit on string chars or array elements to print."), _("\
2553\"set print elements 0\" causes there to be no limit."),
2554 NULL,
920d2a44 2555 show_print_max,
35096d9d 2556 &setprintlist, &showprintlist);
c906108c 2557
79a45b7d
TT
2558 add_setshow_boolean_cmd ("null-stop", no_class,
2559 &user_print_options.stop_print_at_null, _("\
5bf193a2
AC
2560Set printing of char arrays to stop at first null char."), _("\
2561Show printing of char arrays to stop at first null char."), NULL,
2562 NULL,
920d2a44 2563 show_stop_print_at_null,
5bf193a2 2564 &setprintlist, &showprintlist);
c906108c 2565
35096d9d 2566 add_setshow_uinteger_cmd ("repeats", no_class,
79a45b7d 2567 &user_print_options.repeat_count_threshold, _("\
35096d9d
AC
2568Set threshold for repeated print elements."), _("\
2569Show threshold for repeated print elements."), _("\
2570\"set print repeats 0\" causes all elements to be individually printed."),
2571 NULL,
920d2a44 2572 show_repeat_count_threshold,
35096d9d 2573 &setprintlist, &showprintlist);
c906108c 2574
79a45b7d
TT
2575 add_setshow_boolean_cmd ("pretty", class_support,
2576 &user_print_options.prettyprint_structs, _("\
5bf193a2
AC
2577Set prettyprinting of structures."), _("\
2578Show prettyprinting of structures."), NULL,
2579 NULL,
920d2a44 2580 show_prettyprint_structs,
5bf193a2
AC
2581 &setprintlist, &showprintlist);
2582
79a45b7d
TT
2583 add_setshow_boolean_cmd ("union", class_support,
2584 &user_print_options.unionprint, _("\
5bf193a2
AC
2585Set printing of unions interior to structures."), _("\
2586Show printing of unions interior to structures."), NULL,
2587 NULL,
920d2a44 2588 show_unionprint,
5bf193a2
AC
2589 &setprintlist, &showprintlist);
2590
79a45b7d
TT
2591 add_setshow_boolean_cmd ("array", class_support,
2592 &user_print_options.prettyprint_arrays, _("\
5bf193a2
AC
2593Set prettyprinting of arrays."), _("\
2594Show prettyprinting of arrays."), NULL,
2595 NULL,
920d2a44 2596 show_prettyprint_arrays,
5bf193a2
AC
2597 &setprintlist, &showprintlist);
2598
79a45b7d
TT
2599 add_setshow_boolean_cmd ("address", class_support,
2600 &user_print_options.addressprint, _("\
5bf193a2
AC
2601Set printing of addresses."), _("\
2602Show printing of addresses."), NULL,
2603 NULL,
920d2a44 2604 show_addressprint,
5bf193a2 2605 &setprintlist, &showprintlist);
c906108c 2606
1e8fb976
PA
2607 add_setshow_zuinteger_cmd ("input-radix", class_support, &input_radix_1,
2608 _("\
35096d9d
AC
2609Set default input radix for entering numbers."), _("\
2610Show default input radix for entering numbers."), NULL,
1e8fb976
PA
2611 set_input_radix,
2612 show_input_radix,
2613 &setlist, &showlist);
35096d9d 2614
1e8fb976
PA
2615 add_setshow_zuinteger_cmd ("output-radix", class_support, &output_radix_1,
2616 _("\
35096d9d
AC
2617Set default output radix for printing of values."), _("\
2618Show default output radix for printing of values."), NULL,
1e8fb976
PA
2619 set_output_radix,
2620 show_output_radix,
2621 &setlist, &showlist);
c906108c 2622
cb1a6d5f
AC
2623 /* The "set radix" and "show radix" commands are special in that
2624 they are like normal set and show commands but allow two normally
2625 independent variables to be either set or shown with a single
b66df561 2626 command. So the usual deprecated_add_set_cmd() and [deleted]
581e13c1 2627 add_show_from_set() commands aren't really appropriate. */
b66df561
AC
2628 /* FIXME: i18n: With the new add_setshow_integer command, that is no
2629 longer true - show can display anything. */
1a966eab
AC
2630 add_cmd ("radix", class_support, set_radix, _("\
2631Set default input and output number radices.\n\
c906108c 2632Use 'set input-radix' or 'set output-radix' to independently set each.\n\
1a966eab 2633Without an argument, sets both radices back to the default value of 10."),
c906108c 2634 &setlist);
1a966eab
AC
2635 add_cmd ("radix", class_support, show_radix, _("\
2636Show the default input and output number radices.\n\
2637Use 'show input-radix' or 'show output-radix' to independently show each."),
c906108c
SS
2638 &showlist);
2639
e79af960 2640 add_setshow_boolean_cmd ("array-indexes", class_support,
79a45b7d 2641 &user_print_options.print_array_indexes, _("\
e79af960
JB
2642Set printing of array indexes."), _("\
2643Show printing of array indexes"), NULL, NULL, show_print_array_indexes,
2644 &setprintlist, &showprintlist);
c906108c 2645}
This page took 1.458236 seconds and 4 git commands to generate.