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