Add hyphens in usage messages.
[deliverable/binutils-gdb.git] / gdb / valprint.c
CommitLineData
7d9884b9
JG
1/* Print values for GDB, the GNU debugger.
2 Copyright 1986, 1988, 1989, 1991 Free Software Foundation, Inc.
bd5635a1
RP
3
4This file is part of GDB.
5
36b9d39c 6This program is free software; you can redistribute it and/or modify
bd5635a1 7it under the terms of the GNU General Public License as published by
36b9d39c
JG
8the Free Software Foundation; either version 2 of the License, or
9(at your option) any later version.
bd5635a1 10
36b9d39c 11This program is distributed in the hope that it will be useful,
bd5635a1
RP
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
36b9d39c
JG
17along with this program; if not, write to the Free Software
18Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
bd5635a1 19
bd5635a1 20#include "defs.h"
2cd99985 21#include <string.h>
bd5635a1 22#include "symtab.h"
2cd99985 23#include "gdbtypes.h"
bd5635a1
RP
24#include "value.h"
25#include "gdbcore.h"
26#include "gdbcmd.h"
27#include "target.h"
28#include "obstack.h"
be3bc7ad 29#include "language.h"
8f793aa5 30#include "demangle.h"
bd5635a1
RP
31
32#include <errno.h>
2cd99985
PB
33
34/* Prototypes for local functions */
35
a8a69e63
FF
36static void
37print_hex_chars PARAMS ((FILE *, unsigned char *, unsigned int));
38
2cd99985
PB
39static void
40show_print PARAMS ((char *, int));
41
42static void
43set_print PARAMS ((char *, int));
44
45static void
46set_radix PARAMS ((char *, int, struct cmd_list_element *));
47
48static void
49set_output_radix PARAMS ((char *, int, struct cmd_list_element *));
50
51static void
a8a69e63 52value_print_array_elements PARAMS ((value, FILE *, int, enum val_prettyprint));
bd5635a1
RP
53
54/* Maximum number of chars to print for a string pointer value
55 or vector contents, or UINT_MAX for no limit. */
56
85f0a848 57unsigned int print_max;
bd5635a1 58
bd5635a1
RP
59/* Default input and output radixes, and output format letter. */
60
61unsigned input_radix = 10;
62unsigned output_radix = 10;
63int output_format = 0;
64
85f0a848
FF
65/* Print repeat counts if there are more than this many repetitions of an
66 element in an array. Referenced by the low level language dependent
67 print routines. */
68
69unsigned int repeat_count_threshold = 10;
0dce3774 70
a8a69e63
FF
71int prettyprint_structs; /* Controls pretty printing of structures */
72int prettyprint_arrays; /* Controls pretty printing of arrays. */
0dce3774 73
a8a69e63
FF
74/* If nonzero, causes unions inside structures or other unions to be
75 printed. */
bd5635a1 76
a8a69e63 77int unionprint; /* Controls printing of nested unions. */
bd5635a1 78
a8a69e63 79/* If nonzero, causes machine addresses to be printed in certain contexts. */
bd5635a1 80
a8a69e63 81int addressprint; /* Controls printing of machine addresses */
bd5635a1 82
a8a69e63 83\f
c7da3ed3
FF
84/* Print data of type TYPE located at VALADDR (within GDB), which came from
85 the inferior at address ADDRESS, onto stdio stream STREAM according to
86 FORMAT (a letter, or 0 for natural format using TYPE).
bd5635a1 87
c7da3ed3
FF
88 If DEREF_REF is nonzero, then dereference references, otherwise just print
89 them like pointers.
bd5635a1 90
c7da3ed3
FF
91 The PRETTY parameter controls prettyprinting.
92
93 If the data are a string pointer, returns the number of string characters
94 printed.
95
96 FIXME: The data at VALADDR is in target byte order. If gdb is ever
97 enhanced to be able to debug more than the single target it was compiled
98 for (specific CPU type and thus specific target byte ordering), then
99 either the print routines are going to have to take this into account,
100 or the data is going to have to be passed into here already converted
101 to the host byte ordering, whichever is more convenient. */
bd5635a1 102
bd5635a1 103
a8a69e63 104int
c7da3ed3 105val_print (type, valaddr, address, stream, format, deref_ref, recurse, pretty)
a8a69e63
FF
106 struct type *type;
107 char *valaddr;
108 CORE_ADDR address;
bd5635a1 109 FILE *stream;
a8a69e63
FF
110 int format;
111 int deref_ref;
112 int recurse;
113 enum val_prettyprint pretty;
bd5635a1 114{
a8a69e63
FF
115 if (pretty == Val_pretty_default)
116 {
117 pretty = prettyprint_structs ? Val_prettyprint : Val_no_prettyprint;
118 }
bd5635a1 119
a8a69e63
FF
120 QUIT;
121
122 /* Ensure that the type is complete and not just a stub. If the type is
123 only a stub and we can't find and substitute its complete type, then
124 print appropriate string and return. Typical types that my be stubs
125 are structs, unions, and C++ methods. */
126
127 check_stub_type (type);
128 if (TYPE_FLAGS (type) & TYPE_FLAG_STUB)
bd5635a1 129 {
a8a69e63
FF
130 fprintf_filtered (stream, "<incomplete type>");
131 fflush (stream);
132 return (0);
bd5635a1 133 }
a8a69e63
FF
134
135 return (LA_VAL_PRINT (type, valaddr, address, stream, format, deref_ref,
136 recurse, pretty));
bd5635a1 137}
a8a69e63 138
bd5635a1
RP
139/* Print the value VAL in C-ish syntax on stream STREAM.
140 FORMAT is a format-letter, or 0 for print in natural format of data type.
141 If the object printed is a string pointer, returns
142 the number of string bytes printed. */
143
144int
145value_print (val, stream, format, pretty)
146 value val;
147 FILE *stream;
2cd99985 148 int format;
bd5635a1
RP
149 enum val_prettyprint pretty;
150{
a8a69e63 151 register unsigned int n, typelen;
bd5635a1
RP
152
153 if (val == 0)
154 {
155 printf_filtered ("<address of value unknown>");
156 return 0;
157 }
158 if (VALUE_OPTIMIZED_OUT (val))
159 {
160 printf_filtered ("<value optimized out>");
161 return 0;
162 }
aec4cb91 163
bd5635a1
RP
164 /* A "repeated" value really contains several values in a row.
165 They are made by the @ operator.
166 Print such values as if they were arrays. */
167
a8a69e63 168 if (VALUE_REPEATED (val))
bd5635a1
RP
169 {
170 n = VALUE_REPETITIONS (val);
171 typelen = TYPE_LENGTH (VALUE_TYPE (val));
172 fprintf_filtered (stream, "{");
173 /* Print arrays of characters using string syntax. */
174 if (typelen == 1 && TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_INT
175 && format == 0)
a8a69e63 176 LA_PRINT_STRING (stream, VALUE_CONTENTS (val), n, 0);
bd5635a1
RP
177 else
178 {
a8a69e63 179 value_print_array_elements (val, stream, format, pretty);
bd5635a1
RP
180 }
181 fprintf_filtered (stream, "}");
a8a69e63 182 return (n * typelen);
bd5635a1
RP
183 }
184 else
185 {
0dce3774
JK
186 struct type *type = VALUE_TYPE (val);
187
bd5635a1
RP
188 /* If it is a pointer, indicate what it points to.
189
190 Print type also if it is a reference.
191
192 C++: if it is a member pointer, we will take care
193 of that when we print it. */
a8a69e63
FF
194 if (TYPE_CODE (type) == TYPE_CODE_PTR ||
195 TYPE_CODE (type) == TYPE_CODE_REF)
bd5635a1
RP
196 {
197 /* Hack: remove (char *) for char strings. Their
198 type is indicated by the quoted string anyway. */
a8a69e63
FF
199 if (TYPE_CODE (type) == TYPE_CODE_PTR &&
200 TYPE_LENGTH (TYPE_TARGET_TYPE (type)) == sizeof(char) &&
201 TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_INT &&
202 !TYPE_UNSIGNED (TYPE_TARGET_TYPE (type)))
bd5635a1
RP
203 {
204 /* Print nothing */
205 }
a8a69e63
FF
206 else
207 {
208 fprintf_filtered (stream, "(");
209 type_print (type, "", stream, -1);
210 fprintf_filtered (stream, ") ");
211 }
212 }
213 return (val_print (type, VALUE_CONTENTS (val),
214 VALUE_ADDRESS (val), stream, format, 1, 0, pretty));
bd5635a1
RP
215 }
216}
217
a8a69e63
FF
218/* Called by various <lang>_val_print routines to print TYPE_CODE_INT's */
219
220void
221val_print_type_code_int (type, valaddr, stream)
9e4667f6 222 struct type *type;
a8a69e63 223 char *valaddr;
9e4667f6
FF
224 FILE *stream;
225{
a8a69e63
FF
226 char *p;
227 /* Pointer to first (i.e. lowest address) nonzero character. */
228 char *first_addr;
229 unsigned int len;
9e4667f6 230
a8a69e63 231 if (TYPE_LENGTH (type) > sizeof (LONGEST))
9e4667f6 232 {
a8a69e63 233 if (TYPE_UNSIGNED (type))
9e4667f6 234 {
a8a69e63
FF
235 /* First figure out whether the number in fact has zeros
236 in all its bytes more significant than least significant
237 sizeof (LONGEST) ones. */
238 len = TYPE_LENGTH (type);
239
240#if TARGET_BYTE_ORDER == BIG_ENDIAN
241 for (p = valaddr;
242 len > sizeof (LONGEST) && p < valaddr + TYPE_LENGTH (type);
243 p++)
244#else /* Little endian. */
245 first_addr = valaddr;
246 for (p = valaddr + TYPE_LENGTH (type);
247 len > sizeof (LONGEST) && p >= valaddr;
248 p--)
249#endif /* Little endian. */
9e4667f6 250 {
a8a69e63 251 if (*p == 0)
9e4667f6 252 {
a8a69e63 253 len--;
9e4667f6 254 }
a8a69e63 255 else
9e4667f6 256 {
a8a69e63 257 break;
9e4667f6
FF
258 }
259 }
a8a69e63
FF
260#if TARGET_BYTE_ORDER == BIG_ENDIAN
261 first_addr = p;
262#endif
263 if (len <= sizeof (LONGEST))
264 {
265 /* We can print it in decimal. */
266 fprintf_filtered
267 (stream,
268#if defined (LONG_LONG)
269 "%llu",
270#else
271 "%lu",
272#endif
273 unpack_long (BUILTIN_TYPE_LONGEST, first_addr));
274 }
275 else
276 {
277 /* It is big, so print it in hex. */
278 print_hex_chars (stream, (unsigned char *) first_addr, len);
279 }
280 }
281 else
282 {
283 /* Signed. One could assume two's complement (a reasonable
284 assumption, I think) and do better than this. */
285 print_hex_chars (stream, (unsigned char *) valaddr,
286 TYPE_LENGTH (type));
9e4667f6
FF
287 }
288 }
a8a69e63
FF
289 else
290 {
291#ifdef PRINT_TYPELESS_INTEGER
292 PRINT_TYPELESS_INTEGER (stream, type, unpack_long (type, valaddr));
293#else
294 fprintf_filtered (stream, TYPE_UNSIGNED (type) ?
295#if defined (LONG_LONG)
296 "%llu" : "%lld",
297#else
298 "%u" : "%d",
299#endif
300 unpack_long (type, valaddr));
301#endif
302 }
303}
9e4667f6 304
a8a69e63
FF
305/* Print a floating point value of type TYPE, pointed to in GDB by VALADDR,
306 on STREAM. */
bd5635a1 307
a8a69e63
FF
308void
309print_floating (valaddr, type, stream)
310 char *valaddr;
bd5635a1
RP
311 struct type *type;
312 FILE *stream;
bd5635a1 313{
a8a69e63
FF
314 double doub;
315 int inv;
316 unsigned len = TYPE_LENGTH (type);
317
318#if defined (IEEE_FLOAT)
bd5635a1 319
a8a69e63
FF
320 /* Check for NaN's. Note that this code does not depend on us being
321 on an IEEE conforming system. It only depends on the target
322 machine using IEEE representation. This means (a)
323 cross-debugging works right, and (2) IEEE_FLOAT can (and should)
324 be defined for systems like the 68881, which uses IEEE
325 representation, but is not IEEE conforming. */
bd5635a1 326
a8a69e63
FF
327 {
328 long low, high;
329 /* Is the sign bit 0? */
330 int nonnegative;
331 /* Is it is a NaN (i.e. the exponent is all ones and
332 the fraction is nonzero)? */
333 int is_nan;
bd5635a1 334
a8a69e63
FF
335 if (len == sizeof (float))
336 {
337 /* It's single precision. */
338 memcpy ((char *) &low, valaddr, sizeof (low));
339 /* target -> host. */
340 SWAP_TARGET_AND_HOST (&low, sizeof (float));
341 nonnegative = low >= 0;
342 is_nan = ((((low >> 23) & 0xFF) == 0xFF)
343 && 0 != (low & 0x7FFFFF));
344 low &= 0x7fffff;
345 high = 0;
346 }
347 else
348 {
349 /* It's double precision. Get the high and low words. */
bd5635a1 350
a8a69e63
FF
351#if TARGET_BYTE_ORDER == BIG_ENDIAN
352 memcpy (&low, valaddr+4, sizeof (low));
353 memcpy (&high, valaddr+0, sizeof (high));
354#else
355 memcpy (&low, valaddr+0, sizeof (low));
356 memcpy (&high, valaddr+4, sizeof (high));
357#endif
358 SWAP_TARGET_AND_HOST (&low, sizeof (low));
359 SWAP_TARGET_AND_HOST (&high, sizeof (high));
360 nonnegative = high >= 0;
361 is_nan = (((high >> 20) & 0x7ff) == 0x7ff
362 && ! ((((high & 0xfffff) == 0)) && (low == 0)));
363 high &= 0xfffff;
364 }
bd5635a1 365
a8a69e63
FF
366 if (is_nan)
367 {
368 /* The meaning of the sign and fraction is not defined by IEEE.
369 But the user might know what they mean. For example, they
370 (in an implementation-defined manner) distinguish between
371 signaling and quiet NaN's. */
372 if (high)
373 fprintf_filtered (stream, "-NaN(0x%lx%.8lx)" + nonnegative,
374 high, low);
375 else
376 fprintf_filtered (stream, "-NaN(0x%lx)" + nonnegative, low);
377 return;
378 }
379 }
380#endif /* IEEE_FLOAT. */
bd5635a1 381
a8a69e63
FF
382 doub = unpack_double (type, valaddr, &inv);
383 if (inv)
384 fprintf_filtered (stream, "<invalid float value>");
385 else
386 fprintf_filtered (stream, len <= sizeof(float) ? "%.9g" : "%.17g", doub);
bd5635a1
RP
387}
388
a8a69e63 389/* VALADDR points to an integer of LEN bytes. Print it in hex on stream. */
bd5635a1
RP
390
391static void
a8a69e63 392print_hex_chars (stream, valaddr, len)
bd5635a1 393 FILE *stream;
a8a69e63
FF
394 unsigned char *valaddr;
395 unsigned len;
bd5635a1 396{
a8a69e63
FF
397 unsigned char *p;
398
399 fprintf_filtered (stream, "0x");
400#if TARGET_BYTE_ORDER == BIG_ENDIAN
401 for (p = valaddr;
402 p < valaddr + len;
403 p++)
404#else /* Little endian. */
405 for (p = valaddr + len - 1;
406 p >= valaddr;
407 p--)
408#endif
bd5635a1 409 {
a8a69e63 410 fprintf_filtered (stream, "%02x", *p);
bd5635a1 411 }
a8a69e63 412}
bd5635a1 413
a8a69e63
FF
414/* Called by various <lang>_val_print routines to print elements of an
415 array in the form "<elem1>, <elem2>, <elem3>, ...".
4a11eef2 416
a8a69e63
FF
417 (FIXME?) Assumes array element separator is a comma, which is correct
418 for all languages currently handled.
419 (FIXME?) Some languages have a notation for repeated array elements,
420 perhaps we should try to use that notation when appropriate.
421 */
bd5635a1 422
a8a69e63
FF
423void
424val_print_array_elements (type, valaddr, address, stream, format, deref_ref,
425 recurse, pretty, i)
426 struct type *type;
427 char *valaddr;
428 CORE_ADDR address;
429 FILE *stream;
430 int format;
431 int deref_ref;
432 int recurse;
433 enum val_prettyprint pretty;
434 unsigned int i;
435{
436 unsigned int things_printed = 0;
437 unsigned len;
438 struct type *elttype;
439 unsigned eltlen;
440 /* Position of the array element we are examining to see
441 whether it is repeated. */
442 unsigned int rep1;
443 /* Number of repetitions we have detected so far. */
444 unsigned int reps;
445
446 elttype = TYPE_TARGET_TYPE (type);
447 eltlen = TYPE_LENGTH (elttype);
448 len = TYPE_LENGTH (type) / eltlen;
449
450 for (; i < len && things_printed < print_max; i++)
bd5635a1 451 {
a8a69e63 452 if (i != 0)
bd5635a1 453 {
a8a69e63 454 if (prettyprint_arrays)
bd5635a1 455 {
a8a69e63
FF
456 fprintf_filtered (stream, ",\n");
457 print_spaces_filtered (2 + 2 * recurse, stream);
bd5635a1 458 }
a8a69e63 459 else
bd5635a1 460 {
a8a69e63 461 fprintf_filtered (stream, ", ");
bd5635a1 462 }
bd5635a1 463 }
a8a69e63
FF
464 wrap_here (n_spaces (2 + 2 * recurse));
465
466 rep1 = i + 1;
467 reps = 1;
468 while ((rep1 < len) &&
469 !memcmp (valaddr + i * eltlen, valaddr + rep1 * eltlen, eltlen))
470 {
471 ++reps;
472 ++rep1;
473 }
474
475 if (reps > repeat_count_threshold)
bd5635a1 476 {
a8a69e63
FF
477 val_print (elttype, valaddr + i * eltlen, 0, stream, format,
478 deref_ref, recurse + 1, pretty);
479 fprintf_filtered (stream, " <repeats %u times>", reps);
480 i = rep1 - 1;
481 things_printed += repeat_count_threshold;
bd5635a1 482 }
bd5635a1
RP
483 else
484 {
a8a69e63
FF
485 val_print (elttype, valaddr + i * eltlen, 0, stream, format,
486 deref_ref, recurse + 1, pretty);
487 things_printed++;
bd5635a1 488 }
a8a69e63
FF
489 }
490 if (i < len)
491 {
492 fprintf_filtered (stream, "...");
493 }
494}
e2aab031 495
a8a69e63
FF
496static void
497value_print_array_elements (val, stream, format, pretty)
498 value val;
499 FILE *stream;
500 int format;
501 enum val_prettyprint pretty;
502{
503 unsigned int things_printed = 0;
504 register unsigned int i, n, typelen;
505 /* Position of the array elem we are examining to see if it is repeated. */
506 unsigned int rep1;
507 /* Number of repetitions we have detected so far. */
508 unsigned int reps;
509
510 n = VALUE_REPETITIONS (val);
511 typelen = TYPE_LENGTH (VALUE_TYPE (val));
512 for (i = 0; i < n && things_printed < print_max; i++)
513 {
514 if (i != 0)
515 {
516 fprintf_filtered (stream, ", ");
517 }
518 wrap_here ("");
519
520 rep1 = i + 1;
521 reps = 1;
522 while (rep1 < n && !memcmp (VALUE_CONTENTS (val) + typelen * i,
523 VALUE_CONTENTS (val) + typelen * rep1,
524 typelen))
525 {
526 ++reps;
527 ++rep1;
528 }
529
530 if (reps > repeat_count_threshold)
4ace50a5 531 {
a8a69e63
FF
532 val_print (VALUE_TYPE (val), VALUE_CONTENTS (val) + typelen * i,
533 VALUE_ADDRESS (val) + typelen * i, stream, format, 1,
534 0, pretty);
535 fprintf (stream, " <repeats %u times>", reps);
536 i = rep1 - 1;
537 things_printed += repeat_count_threshold;
4ace50a5
FF
538 }
539 else
540 {
a8a69e63
FF
541 val_print (VALUE_TYPE (val), VALUE_CONTENTS (val) + typelen * i,
542 VALUE_ADDRESS (val) + typelen * i, stream, format, 1,
543 0, pretty);
544 things_printed++;
4ace50a5 545 }
a8a69e63
FF
546 }
547 if (i < n)
548 {
549 fprintf_filtered (stream, "...");
bd5635a1
RP
550 }
551}
a8a69e63 552
c7da3ed3
FF
553int
554val_print_string (addr, stream)
555 CORE_ADDR addr;
556 FILE *stream;
557{
558 int first_addr_err;
559 int errcode;
560 unsigned char c;
561 char *string;
562 int force_ellipses;
563 unsigned int i = 0; /* Number of characters printed. */
564
565 /* Get first character. */
566 errcode = target_read_memory (addr, (char *)&c, 1);
567 if (errcode != 0)
568 {
569 /* First address out of bounds. */
570 first_addr_err = 1;
571 }
572 else
573 {
574 first_addr_err = 0;
575 /* A real string. */
576 string = (char *) alloca (print_max);
577
578 /* If the loop ends by us hitting print_max characters,
579 we need to have elipses at the end. */
580 force_ellipses = 1;
581
582 /* This loop always fetches print_max characters, even
583 though LA_PRINT_STRING might want to print more or fewer
584 (with repeated characters). This is so that
585 we don't spend forever fetching if we print
586 a long string consisting of the same character
587 repeated. Also so we can do it all in one memory
588 operation, which is faster. However, this will be
589 slower if print_max is set high, e.g. if you set
590 print_max to 1000, not only will it take a long
591 time to fetch short strings, but if you are near
592 the end of the address space, it might not work. */
593 QUIT;
594 errcode = target_read_memory (addr, string, print_max);
595 if (errcode != 0)
596 {
597 /* Try reading just one character. If that succeeds,
598 assume we hit the end of the address space, but
599 the initial part of the string is probably safe. */
600 char x[1];
601 errcode = target_read_memory (addr, x, 1);
602 }
603 if (errcode != 0)
604 force_ellipses = 0;
605 else
606 for (i = 0; i < print_max; i++)
607 if (string[i] == '\0')
608 {
609 force_ellipses = 0;
610 break;
611 }
612 QUIT;
613
614 if (addressprint)
615 {
616 fputs_filtered (" ", stream);
617 }
618 LA_PRINT_STRING (stream, string, i, force_ellipses);
619 }
620
621 if (errcode != 0)
622 {
623 if (errcode == EIO)
624 {
625 fprintf_filtered (stream,
626 (" <Address 0x%x out of bounds>" + first_addr_err),
627 addr + i);
628 }
629 else
630 {
631 error ("Error reading memory address 0x%x: %s.", addr + i,
632 safe_strerror (errcode));
633 }
634 }
635 fflush (stream);
636 return (i);
637}
bd5635a1 638\f
e1ce8aa5 639#if 0
bd5635a1
RP
640/* Validate an input or output radix setting, and make sure the user
641 knows what they really did here. Radix setting is confusing, e.g.
642 setting the input radix to "10" never changes it! */
643
e1ce8aa5 644/* ARGSUSED */
bd5635a1
RP
645static void
646set_input_radix (args, from_tty, c)
647 char *args;
648 int from_tty;
649 struct cmd_list_element *c;
650{
651 unsigned radix = *(unsigned *)c->var;
652
653 if (from_tty)
654 printf_filtered ("Input radix set to decimal %d, hex %x, octal %o\n",
655 radix, radix, radix);
656}
e1ce8aa5 657#endif
bd5635a1 658
e1ce8aa5 659/* ARGSUSED */
bd5635a1
RP
660static void
661set_output_radix (args, from_tty, c)
662 char *args;
663 int from_tty;
664 struct cmd_list_element *c;
665{
666 unsigned radix = *(unsigned *)c->var;
667
668 if (from_tty)
669 printf_filtered ("Output radix set to decimal %d, hex %x, octal %o\n",
670 radix, radix, radix);
671
672 /* FIXME, we really should be able to validate the setting BEFORE
673 it takes effect. */
674 switch (radix)
675 {
676 case 16:
677 output_format = 'x';
678 break;
679 case 10:
680 output_format = 0;
681 break;
682 case 8:
683 output_format = 'o'; /* octal */
684 break;
685 default:
686 output_format = 0;
687 error ("Unsupported radix ``decimal %d''; using decimal output",
688 radix);
689 }
690}
691
692/* Both at once */
693static void
694set_radix (arg, from_tty, c)
695 char *arg;
696 int from_tty;
697 struct cmd_list_element *c;
698{
699 unsigned radix = *(unsigned *)c->var;
700
701 if (from_tty)
702 printf_filtered ("Radix set to decimal %d, hex %x, octal %o\n",
703 radix, radix, radix);
704
705 input_radix = radix;
706 output_radix = radix;
707
708 set_output_radix (arg, 0, c);
709}
710\f
f266e564
JK
711/*ARGSUSED*/
712static void
713set_print (arg, from_tty)
714 char *arg;
715 int from_tty;
716{
717 printf (
718"\"set print\" must be followed by the name of a print subcommand.\n");
719 help_list (setprintlist, "set print ", -1, stdout);
720}
721
722/*ARGSUSED*/
723static void
724show_print (args, from_tty)
725 char *args;
726 int from_tty;
727{
728 cmd_show_list (showprintlist, from_tty, "");
729}
730\f
bd5635a1
RP
731void
732_initialize_valprint ()
733{
734 struct cmd_list_element *c;
735
f266e564
JK
736 add_prefix_cmd ("print", no_class, set_print,
737 "Generic command for setting how things print.",
738 &setprintlist, "set print ", 0, &setlist);
36b9d39c
JG
739 add_alias_cmd ("p", "print", no_class, 1, &setlist);
740 add_alias_cmd ("pr", "print", no_class, 1, &setlist); /* prefer set print
741 to set prompt */
f266e564
JK
742 add_prefix_cmd ("print", no_class, show_print,
743 "Generic command for showing print settings.",
744 &showprintlist, "show print ", 0, &showlist);
36b9d39c
JG
745 add_alias_cmd ("p", "print", no_class, 1, &showlist);
746 add_alias_cmd ("pr", "print", no_class, 1, &showlist);
f266e564 747
bd5635a1 748 add_show_from_set
f266e564 749 (add_set_cmd ("elements", no_class, var_uinteger, (char *)&print_max,
bd5635a1 750 "Set limit on string chars or array elements to print.\n\
f266e564
JK
751\"set print elements 0\" causes there to be no limit.",
752 &setprintlist),
753 &showprintlist);
bd5635a1 754
85f0a848
FF
755 add_show_from_set
756 (add_set_cmd ("repeats", no_class, var_uinteger,
757 (char *)&repeat_count_threshold,
758 "Set threshold for repeated print elements.\n\
759\"set print repeats 0\" causes all elements to be individually printed.",
760 &setprintlist),
761 &showprintlist);
762
bd5635a1 763 add_show_from_set
a8a69e63
FF
764 (add_set_cmd ("pretty", class_support, var_boolean,
765 (char *)&prettyprint_structs,
bd5635a1 766 "Set prettyprinting of structures.",
f266e564
JK
767 &setprintlist),
768 &showprintlist);
bd5635a1
RP
769
770 add_show_from_set
f266e564 771 (add_set_cmd ("union", class_support, var_boolean, (char *)&unionprint,
bd5635a1 772 "Set printing of unions interior to structures.",
f266e564
JK
773 &setprintlist),
774 &showprintlist);
bd5635a1
RP
775
776 add_show_from_set
a8a69e63
FF
777 (add_set_cmd ("array", class_support, var_boolean,
778 (char *)&prettyprint_arrays,
bd5635a1 779 "Set prettyprinting of arrays.",
f266e564
JK
780 &setprintlist),
781 &showprintlist);
bd5635a1
RP
782
783 add_show_from_set
f266e564 784 (add_set_cmd ("address", class_support, var_boolean, (char *)&addressprint,
bd5635a1 785 "Set printing of addresses.",
f266e564
JK
786 &setprintlist),
787 &showprintlist);
bd5635a1
RP
788
789#if 0
790 /* The "show radix" cmd isn't good enough to show two separate values.
791 The rest of the code works, but the show part is confusing, so don't
792 let them be set separately 'til we work out "show". */
793 c = add_set_cmd ("input-radix", class_support, var_uinteger,
794 (char *)&input_radix,
795 "Set default input radix for entering numbers.",
796 &setlist);
797 add_show_from_set (c, &showlist);
798 c->function = set_input_radix;
799
800 c = add_set_cmd ("output-radix", class_support, var_uinteger,
801 (char *)&output_radix,
802 "Set default output radix for printing of values.",
803 &setlist);
804 add_show_from_set (c, &showlist);
805 c->function = set_output_radix;
806#endif
807
808 c = add_set_cmd ("radix", class_support, var_uinteger,
809 (char *)&output_radix,
810 "Set default input and output number radix.",
811 &setlist);
812 add_show_from_set (c, &showlist);
2cd99985 813 c->function.sfunc = set_radix;
bd5635a1
RP
814
815 /* Give people the defaults which they are used to. */
a8a69e63
FF
816 prettyprint_structs = 0;
817 prettyprint_arrays = 0;
bd5635a1 818 unionprint = 1;
bd5635a1 819 addressprint = 1;
bd5635a1 820 print_max = 200;
bd5635a1 821}
This page took 0.151354 seconds and 4 git commands to generate.