* hppa-tdep.c (read_unwind_info): Fix typo in comment.
[deliverable/binutils-gdb.git] / gdb / valprint.c
CommitLineData
c906108c 1/* Print values for GDB, the GNU debugger.
5c1c87f0
AC
2
3 Copyright 1986, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
acf0f27f
AC
4 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2005 Free Software
5 Foundation, Inc.
c906108c 6
c5aa993b 7 This file is part of GDB.
c906108c 8
c5aa993b
JM
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
c906108c 13
c5aa993b
JM
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
c906108c 18
c5aa993b
JM
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
c906108c
SS
23
24#include "defs.h"
25#include "gdb_string.h"
26#include "symtab.h"
27#include "gdbtypes.h"
28#include "value.h"
29#include "gdbcore.h"
30#include "gdbcmd.h"
31#include "target.h"
c906108c 32#include "language.h"
c906108c
SS
33#include "annotate.h"
34#include "valprint.h"
39424bef 35#include "floatformat.h"
d16aafd8 36#include "doublest.h"
c906108c
SS
37
38#include <errno.h>
39
40/* Prototypes for local functions */
41
917317f4
JM
42static int partial_memory_read (CORE_ADDR memaddr, char *myaddr,
43 int len, int *errnoptr);
44
a14ed312 45static void show_print (char *, int);
c906108c 46
a14ed312 47static void set_print (char *, int);
c906108c 48
a14ed312 49static void set_radix (char *, int);
c906108c 50
a14ed312 51static void show_radix (char *, int);
c906108c 52
a14ed312 53static void set_input_radix (char *, int, struct cmd_list_element *);
c906108c 54
a14ed312 55static void set_input_radix_1 (int, unsigned);
c906108c 56
a14ed312 57static void set_output_radix (char *, int, struct cmd_list_element *);
c906108c 58
a14ed312 59static void set_output_radix_1 (int, unsigned);
c906108c 60
a14ed312 61void _initialize_valprint (void);
c906108c
SS
62
63/* Maximum number of chars to print for a string pointer value or vector
64 contents, or UINT_MAX for no limit. Note that "set print elements 0"
65 stores UINT_MAX in print_max, which displays in a show command as
66 "unlimited". */
67
68unsigned int print_max;
69#define PRINT_MAX_DEFAULT 200 /* Start print_max off at this value. */
920d2a44
AC
70static void
71show_print_max (struct ui_file *file, int from_tty,
72 struct cmd_list_element *c, const char *value)
73{
74 fprintf_filtered (file, _("\
75Limit on string chars or array elements to print is %s.\n"),
76 value);
77}
78
c906108c
SS
79
80/* Default input and output radixes, and output format letter. */
81
82unsigned input_radix = 10;
920d2a44
AC
83static void
84show_input_radix (struct ui_file *file, int from_tty,
85 struct cmd_list_element *c, const char *value)
86{
87 fprintf_filtered (file, _("\
88Default input radix for entering numbers is %s.\n"),
89 value);
90}
91
c906108c 92unsigned output_radix = 10;
920d2a44
AC
93static void
94show_output_radix (struct ui_file *file, int from_tty,
95 struct cmd_list_element *c, const char *value)
96{
97 fprintf_filtered (file, _("\
98Default output radix for printing of values is %s.\n"),
99 value);
100}
c906108c
SS
101int output_format = 0;
102
103/* Print repeat counts if there are more than this many repetitions of an
104 element in an array. Referenced by the low level language dependent
105 print routines. */
106
107unsigned int repeat_count_threshold = 10;
920d2a44
AC
108static void
109show_repeat_count_threshold (struct ui_file *file, int from_tty,
110 struct cmd_list_element *c, const char *value)
111{
112 fprintf_filtered (file, _("Threshold for repeated print elements is %s.\n"),
113 value);
114}
c906108c
SS
115
116/* If nonzero, stops printing of char arrays at first null. */
117
118int stop_print_at_null;
920d2a44
AC
119static void
120show_stop_print_at_null (struct ui_file *file, int from_tty,
121 struct cmd_list_element *c, const char *value)
122{
123 fprintf_filtered (file, _("\
124Printing of char arrays to stop at first null char is %s.\n"),
125 value);
126}
c906108c
SS
127
128/* Controls pretty printing of structures. */
129
130int prettyprint_structs;
920d2a44
AC
131static void
132show_prettyprint_structs (struct ui_file *file, int from_tty,
133 struct cmd_list_element *c, const char *value)
134{
135 fprintf_filtered (file, _("Prettyprinting of structures is %s.\n"), value);
136}
c906108c
SS
137
138/* Controls pretty printing of arrays. */
139
140int prettyprint_arrays;
920d2a44
AC
141static void
142show_prettyprint_arrays (struct ui_file *file, int from_tty,
143 struct cmd_list_element *c, const char *value)
144{
145 fprintf_filtered (file, _("Prettyprinting of arrays is %s.\n"), value);
146}
c906108c
SS
147
148/* If nonzero, causes unions inside structures or other unions to be
149 printed. */
150
151int unionprint; /* Controls printing of nested unions. */
920d2a44
AC
152static void
153show_unionprint (struct ui_file *file, int from_tty,
154 struct cmd_list_element *c, const char *value)
155{
156 fprintf_filtered (file, _("\
157Printing of unions interior to structures is %s.\n"),
158 value);
159}
c906108c
SS
160
161/* If nonzero, causes machine addresses to be printed in certain contexts. */
162
163int addressprint; /* Controls printing of machine addresses */
920d2a44
AC
164static void
165show_addressprint (struct ui_file *file, int from_tty,
166 struct cmd_list_element *c, const char *value)
167{
168 fprintf_filtered (file, _("Printing of addresses is %s.\n"), value);
169}
c906108c 170\f
c5aa993b 171
c906108c
SS
172/* Print data of type TYPE located at VALADDR (within GDB), which came from
173 the inferior at address ADDRESS, onto stdio stream STREAM according to
174 FORMAT (a letter, or 0 for natural format using TYPE).
175
176 If DEREF_REF is nonzero, then dereference references, otherwise just print
177 them like pointers.
178
179 The PRETTY parameter controls prettyprinting.
180
181 If the data are a string pointer, returns the number of string characters
182 printed.
183
184 FIXME: The data at VALADDR is in target byte order. If gdb is ever
185 enhanced to be able to debug more than the single target it was compiled
186 for (specific CPU type and thus specific target byte ordering), then
187 either the print routines are going to have to take this into account,
188 or the data is going to have to be passed into here already converted
189 to the host byte ordering, whichever is more convenient. */
190
191
192int
fc1a4b47 193val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
a2bd3dcd
AC
194 CORE_ADDR address, struct ui_file *stream, int format,
195 int deref_ref, int recurse, enum val_prettyprint pretty)
c906108c
SS
196{
197 struct type *real_type = check_typedef (type);
198 if (pretty == Val_pretty_default)
199 {
200 pretty = prettyprint_structs ? Val_prettyprint : Val_no_prettyprint;
201 }
c5aa993b 202
c906108c
SS
203 QUIT;
204
205 /* Ensure that the type is complete and not just a stub. If the type is
206 only a stub and we can't find and substitute its complete type, then
207 print appropriate string and return. */
208
74a9bb82 209 if (TYPE_STUB (real_type))
c906108c
SS
210 {
211 fprintf_filtered (stream, "<incomplete type>");
212 gdb_flush (stream);
213 return (0);
214 }
c5aa993b 215
c906108c 216 return (LA_VAL_PRINT (type, valaddr, embedded_offset, address,
c5aa993b 217 stream, format, deref_ref, recurse, pretty));
c906108c
SS
218}
219
806048c6
DJ
220/* Check whether the value VAL is printable. Return 1 if it is;
221 return 0 and print an appropriate error message to STREAM if it
222 is not. */
c906108c 223
806048c6
DJ
224static int
225value_check_printable (struct value *val, struct ui_file *stream)
c906108c
SS
226{
227 if (val == 0)
228 {
806048c6 229 fprintf_filtered (stream, _("<address of value unknown>"));
c906108c
SS
230 return 0;
231 }
806048c6 232
feb13ab0 233 if (value_optimized_out (val))
c906108c 234 {
806048c6 235 fprintf_filtered (stream, _("<value optimized out>"));
c906108c
SS
236 return 0;
237 }
806048c6
DJ
238
239 return 1;
240}
241
242/* Print the value VAL onto stream STREAM according to FORMAT (a
243 letter, or 0 for natural format using TYPE).
244
245 If DEREF_REF is nonzero, then dereference references, otherwise just print
246 them like pointers.
247
248 The PRETTY parameter controls prettyprinting.
249
250 If the data are a string pointer, returns the number of string characters
251 printed.
252
253 This is a preferable interface to val_print, above, because it uses
254 GDB's value mechanism. */
255
256int
257common_val_print (struct value *val, struct ui_file *stream, int format,
258 int deref_ref, int recurse, enum val_prettyprint pretty)
259{
260 if (!value_check_printable (val, stream))
261 return 0;
262
263 return val_print (value_type (val), value_contents_all (val),
264 value_embedded_offset (val), VALUE_ADDRESS (val),
265 stream, format, deref_ref, recurse, pretty);
266}
267
268/* Print the value VAL in C-ish syntax on stream STREAM.
269 FORMAT is a format-letter, or 0 for print in natural format of data type.
270 If the object printed is a string pointer, returns
271 the number of string bytes printed. */
272
273int
274value_print (struct value *val, struct ui_file *stream, int format,
275 enum val_prettyprint pretty)
276{
277 if (!value_check_printable (val, stream))
278 return 0;
279
c906108c
SS
280 return LA_VALUE_PRINT (val, stream, format, pretty);
281}
282
283/* Called by various <lang>_val_print routines to print
284 TYPE_CODE_INT's. TYPE is the type. VALADDR is the address of the
285 value. STREAM is where to print the value. */
286
287void
fc1a4b47 288val_print_type_code_int (struct type *type, const gdb_byte *valaddr,
fba45db2 289 struct ui_file *stream)
c906108c
SS
290{
291 if (TYPE_LENGTH (type) > sizeof (LONGEST))
292 {
293 LONGEST val;
294
295 if (TYPE_UNSIGNED (type)
296 && extract_long_unsigned_integer (valaddr, TYPE_LENGTH (type),
297 &val))
298 {
299 print_longest (stream, 'u', 0, val);
300 }
301 else
302 {
303 /* Signed, or we couldn't turn an unsigned value into a
304 LONGEST. For signed values, one could assume two's
305 complement (a reasonable assumption, I think) and do
306 better than this. */
307 print_hex_chars (stream, (unsigned char *) valaddr,
308 TYPE_LENGTH (type));
309 }
310 }
311 else
312 {
c906108c
SS
313 print_longest (stream, TYPE_UNSIGNED (type) ? 'u' : 'd', 0,
314 unpack_long (type, valaddr));
c906108c
SS
315 }
316}
317
318/* Print a number according to FORMAT which is one of d,u,x,o,b,h,w,g.
319 The raison d'etre of this function is to consolidate printing of
bb599908
PH
320 LONG_LONG's into this one function. The format chars b,h,w,g are
321 from print_scalar_formatted(). Numbers are printed using C
322 format.
323
324 USE_C_FORMAT means to use C format in all cases. Without it,
325 'o' and 'x' format do not include the standard C radix prefix
326 (leading 0 or 0x).
327
328 Hilfinger/2004-09-09: USE_C_FORMAT was originally called USE_LOCAL
329 and was intended to request formating according to the current
330 language and would be used for most integers that GDB prints. The
331 exceptional cases were things like protocols where the format of
332 the integer is a protocol thing, not a user-visible thing). The
333 parameter remains to preserve the information of what things might
334 be printed with language-specific format, should we ever resurrect
335 that capability. */
c906108c
SS
336
337void
bb599908 338print_longest (struct ui_file *stream, int format, int use_c_format,
fba45db2 339 LONGEST val_long)
c906108c 340{
2bfb72ee
AC
341 const char *val;
342
c906108c
SS
343 switch (format)
344 {
345 case 'd':
bb599908 346 val = int_string (val_long, 10, 1, 0, 1); break;
c906108c 347 case 'u':
bb599908 348 val = int_string (val_long, 10, 0, 0, 1); break;
c906108c 349 case 'x':
bb599908 350 val = int_string (val_long, 16, 0, 0, use_c_format); break;
c906108c 351 case 'b':
bb599908 352 val = int_string (val_long, 16, 0, 2, 1); break;
c906108c 353 case 'h':
bb599908 354 val = int_string (val_long, 16, 0, 4, 1); break;
c906108c 355 case 'w':
bb599908 356 val = int_string (val_long, 16, 0, 8, 1); break;
c906108c 357 case 'g':
bb599908 358 val = int_string (val_long, 16, 0, 16, 1); break;
c906108c
SS
359 break;
360 case 'o':
bb599908 361 val = int_string (val_long, 8, 0, 0, use_c_format); break;
c906108c 362 default:
e2e0b3e5 363 internal_error (__FILE__, __LINE__, _("failed internal consistency check"));
bb599908 364 }
2bfb72ee 365 fputs_filtered (val, stream);
c906108c
SS
366}
367
c906108c
SS
368/* This used to be a macro, but I don't think it is called often enough
369 to merit such treatment. */
370/* Convert a LONGEST to an int. This is used in contexts (e.g. number of
371 arguments to a function, number in a value history, register number, etc.)
372 where the value must not be larger than can fit in an int. */
373
374int
fba45db2 375longest_to_int (LONGEST arg)
c906108c
SS
376{
377 /* Let the compiler do the work */
378 int rtnval = (int) arg;
379
380 /* Check for overflows or underflows */
381 if (sizeof (LONGEST) > sizeof (int))
382 {
383 if (rtnval != arg)
384 {
8a3fe4f8 385 error (_("Value out of range."));
c906108c
SS
386 }
387 }
388 return (rtnval);
389}
390
a73c86fb
AC
391/* Print a floating point value of type TYPE (not always a
392 TYPE_CODE_FLT), pointed to in GDB by VALADDR, on STREAM. */
c906108c
SS
393
394void
fc1a4b47 395print_floating (const gdb_byte *valaddr, struct type *type,
c84141d6 396 struct ui_file *stream)
c906108c
SS
397{
398 DOUBLEST doub;
399 int inv;
a73c86fb 400 const struct floatformat *fmt = NULL;
c906108c 401 unsigned len = TYPE_LENGTH (type);
c5aa993b 402
a73c86fb
AC
403 /* If it is a floating-point, check for obvious problems. */
404 if (TYPE_CODE (type) == TYPE_CODE_FLT)
405 fmt = floatformat_from_type (type);
406 if (fmt != NULL && floatformat_is_nan (fmt, valaddr))
39424bef
MK
407 {
408 if (floatformat_is_negative (fmt, valaddr))
409 fprintf_filtered (stream, "-");
410 fprintf_filtered (stream, "nan(");
bb599908 411 fputs_filtered ("0x", stream);
306d9ac5 412 fputs_filtered (floatformat_mantissa (fmt, valaddr), stream);
39424bef
MK
413 fprintf_filtered (stream, ")");
414 return;
7355ddba 415 }
c906108c 416
a73c86fb
AC
417 /* NOTE: cagney/2002-01-15: The TYPE passed into print_floating()
418 isn't necessarily a TYPE_CODE_FLT. Consequently, unpack_double
419 needs to be used as that takes care of any necessary type
420 conversions. Such conversions are of course direct to DOUBLEST
421 and disregard any possible target floating point limitations.
422 For instance, a u64 would be converted and displayed exactly on a
423 host with 80 bit DOUBLEST but with loss of information on a host
424 with 64 bit DOUBLEST. */
c2f05ac9 425
c906108c
SS
426 doub = unpack_double (type, valaddr, &inv);
427 if (inv)
428 {
429 fprintf_filtered (stream, "<invalid float value>");
430 return;
431 }
432
39424bef
MK
433 /* FIXME: kettenis/2001-01-20: The following code makes too much
434 assumptions about the host and target floating point format. */
435
a73c86fb 436 /* NOTE: cagney/2002-02-03: Since the TYPE of what was passed in may
c41b8590 437 not necessarily be a TYPE_CODE_FLT, the below ignores that and
a73c86fb
AC
438 instead uses the type's length to determine the precision of the
439 floating-point value being printed. */
c2f05ac9 440
c906108c 441 if (len < sizeof (double))
c5aa993b 442 fprintf_filtered (stream, "%.9g", (double) doub);
c906108c 443 else if (len == sizeof (double))
c5aa993b 444 fprintf_filtered (stream, "%.17g", (double) doub);
c906108c
SS
445 else
446#ifdef PRINTF_HAS_LONG_DOUBLE
447 fprintf_filtered (stream, "%.35Lg", doub);
448#else
39424bef
MK
449 /* This at least wins with values that are representable as
450 doubles. */
c906108c
SS
451 fprintf_filtered (stream, "%.17g", (double) doub);
452#endif
453}
454
c5aa993b 455void
fc1a4b47 456print_binary_chars (struct ui_file *stream, const gdb_byte *valaddr,
fba45db2 457 unsigned len)
c906108c
SS
458{
459
460#define BITS_IN_BYTES 8
461
fc1a4b47 462 const gdb_byte *p;
745b8ca0 463 unsigned int i;
c5aa993b 464 int b;
c906108c
SS
465
466 /* Declared "int" so it will be signed.
467 * This ensures that right shift will shift in zeros.
468 */
c5aa993b 469 const int mask = 0x080;
c906108c
SS
470
471 /* FIXME: We should be not printing leading zeroes in most cases. */
472
d7449b42 473 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
c906108c
SS
474 {
475 for (p = valaddr;
476 p < valaddr + len;
477 p++)
478 {
c5aa993b
JM
479 /* Every byte has 8 binary characters; peel off
480 * and print from the MSB end.
481 */
482 for (i = 0; i < (BITS_IN_BYTES * sizeof (*p)); i++)
483 {
484 if (*p & (mask >> i))
485 b = 1;
486 else
487 b = 0;
488
489 fprintf_filtered (stream, "%1d", b);
490 }
c906108c
SS
491 }
492 }
493 else
494 {
495 for (p = valaddr + len - 1;
496 p >= valaddr;
497 p--)
498 {
c5aa993b
JM
499 for (i = 0; i < (BITS_IN_BYTES * sizeof (*p)); i++)
500 {
501 if (*p & (mask >> i))
502 b = 1;
503 else
504 b = 0;
505
506 fprintf_filtered (stream, "%1d", b);
507 }
c906108c
SS
508 }
509 }
c906108c
SS
510}
511
512/* VALADDR points to an integer of LEN bytes.
513 * Print it in octal on stream or format it in buf.
514 */
515void
fc1a4b47 516print_octal_chars (struct ui_file *stream, const gdb_byte *valaddr,
6c403953 517 unsigned len)
c906108c 518{
fc1a4b47 519 const gdb_byte *p;
c906108c 520 unsigned char octa1, octa2, octa3, carry;
c5aa993b
JM
521 int cycle;
522
c906108c
SS
523 /* FIXME: We should be not printing leading zeroes in most cases. */
524
525
526 /* Octal is 3 bits, which doesn't fit. Yuk. So we have to track
527 * the extra bits, which cycle every three bytes:
528 *
529 * Byte side: 0 1 2 3
530 * | | | |
531 * bit number 123 456 78 | 9 012 345 6 | 78 901 234 | 567 890 12 |
532 *
533 * Octal side: 0 1 carry 3 4 carry ...
534 *
535 * Cycle number: 0 1 2
536 *
537 * But of course we are printing from the high side, so we have to
538 * figure out where in the cycle we are so that we end up with no
539 * left over bits at the end.
540 */
541#define BITS_IN_OCTAL 3
542#define HIGH_ZERO 0340
543#define LOW_ZERO 0016
544#define CARRY_ZERO 0003
545#define HIGH_ONE 0200
546#define MID_ONE 0160
547#define LOW_ONE 0016
548#define CARRY_ONE 0001
549#define HIGH_TWO 0300
550#define MID_TWO 0070
551#define LOW_TWO 0007
552
553 /* For 32 we start in cycle 2, with two bits and one bit carry;
554 * for 64 in cycle in cycle 1, with one bit and a two bit carry.
555 */
556 cycle = (len * BITS_IN_BYTES) % BITS_IN_OCTAL;
557 carry = 0;
c5aa993b 558
bb599908 559 fputs_filtered ("0", stream);
d7449b42 560 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
c906108c
SS
561 {
562 for (p = valaddr;
563 p < valaddr + len;
564 p++)
565 {
c5aa993b
JM
566 switch (cycle)
567 {
568 case 0:
569 /* No carry in, carry out two bits.
570 */
571 octa1 = (HIGH_ZERO & *p) >> 5;
572 octa2 = (LOW_ZERO & *p) >> 2;
573 carry = (CARRY_ZERO & *p);
574 fprintf_filtered (stream, "%o", octa1);
575 fprintf_filtered (stream, "%o", octa2);
576 break;
577
578 case 1:
579 /* Carry in two bits, carry out one bit.
580 */
581 octa1 = (carry << 1) | ((HIGH_ONE & *p) >> 7);
582 octa2 = (MID_ONE & *p) >> 4;
583 octa3 = (LOW_ONE & *p) >> 1;
584 carry = (CARRY_ONE & *p);
585 fprintf_filtered (stream, "%o", octa1);
586 fprintf_filtered (stream, "%o", octa2);
587 fprintf_filtered (stream, "%o", octa3);
588 break;
589
590 case 2:
591 /* Carry in one bit, no carry out.
592 */
593 octa1 = (carry << 2) | ((HIGH_TWO & *p) >> 6);
594 octa2 = (MID_TWO & *p) >> 3;
595 octa3 = (LOW_TWO & *p);
596 carry = 0;
597 fprintf_filtered (stream, "%o", octa1);
598 fprintf_filtered (stream, "%o", octa2);
599 fprintf_filtered (stream, "%o", octa3);
600 break;
601
602 default:
8a3fe4f8 603 error (_("Internal error in octal conversion;"));
c5aa993b
JM
604 }
605
606 cycle++;
607 cycle = cycle % BITS_IN_OCTAL;
c906108c
SS
608 }
609 }
610 else
611 {
612 for (p = valaddr + len - 1;
613 p >= valaddr;
614 p--)
615 {
c5aa993b
JM
616 switch (cycle)
617 {
618 case 0:
619 /* Carry out, no carry in */
620 octa1 = (HIGH_ZERO & *p) >> 5;
621 octa2 = (LOW_ZERO & *p) >> 2;
622 carry = (CARRY_ZERO & *p);
623 fprintf_filtered (stream, "%o", octa1);
624 fprintf_filtered (stream, "%o", octa2);
625 break;
626
627 case 1:
628 /* Carry in, carry out */
629 octa1 = (carry << 1) | ((HIGH_ONE & *p) >> 7);
630 octa2 = (MID_ONE & *p) >> 4;
631 octa3 = (LOW_ONE & *p) >> 1;
632 carry = (CARRY_ONE & *p);
633 fprintf_filtered (stream, "%o", octa1);
634 fprintf_filtered (stream, "%o", octa2);
635 fprintf_filtered (stream, "%o", octa3);
636 break;
637
638 case 2:
639 /* Carry in, no carry out */
640 octa1 = (carry << 2) | ((HIGH_TWO & *p) >> 6);
641 octa2 = (MID_TWO & *p) >> 3;
642 octa3 = (LOW_TWO & *p);
643 carry = 0;
644 fprintf_filtered (stream, "%o", octa1);
645 fprintf_filtered (stream, "%o", octa2);
646 fprintf_filtered (stream, "%o", octa3);
647 break;
648
649 default:
8a3fe4f8 650 error (_("Internal error in octal conversion;"));
c5aa993b
JM
651 }
652
653 cycle++;
654 cycle = cycle % BITS_IN_OCTAL;
c906108c
SS
655 }
656 }
657
c906108c
SS
658}
659
660/* VALADDR points to an integer of LEN bytes.
661 * Print it in decimal on stream or format it in buf.
662 */
663void
fc1a4b47 664print_decimal_chars (struct ui_file *stream, const gdb_byte *valaddr,
fba45db2 665 unsigned len)
c906108c
SS
666{
667#define TEN 10
668#define TWO_TO_FOURTH 16
c5aa993b 669#define CARRY_OUT( x ) ((x) / TEN) /* extend char to int */
c906108c
SS
670#define CARRY_LEFT( x ) ((x) % TEN)
671#define SHIFT( x ) ((x) << 4)
672#define START_P \
d7449b42 673 ((TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) ? valaddr : valaddr + len - 1)
c906108c 674#define NOT_END_P \
d7449b42 675 ((TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) ? (p < valaddr + len) : (p >= valaddr))
c906108c 676#define NEXT_P \
d7449b42 677 ((TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) ? p++ : p-- )
c906108c
SS
678#define LOW_NIBBLE( x ) ( (x) & 0x00F)
679#define HIGH_NIBBLE( x ) (((x) & 0x0F0) >> 4)
680
fc1a4b47 681 const gdb_byte *p;
c906108c 682 unsigned char *digits;
c5aa993b
JM
683 int carry;
684 int decimal_len;
685 int i, j, decimal_digits;
686 int dummy;
687 int flip;
688
c906108c
SS
689 /* Base-ten number is less than twice as many digits
690 * as the base 16 number, which is 2 digits per byte.
691 */
692 decimal_len = len * 2 * 2;
3c37485b 693 digits = xmalloc (decimal_len);
c906108c 694
c5aa993b
JM
695 for (i = 0; i < decimal_len; i++)
696 {
c906108c 697 digits[i] = 0;
c5aa993b 698 }
c906108c 699
c906108c
SS
700 /* Ok, we have an unknown number of bytes of data to be printed in
701 * decimal.
702 *
703 * Given a hex number (in nibbles) as XYZ, we start by taking X and
704 * decemalizing it as "x1 x2" in two decimal nibbles. Then we multiply
705 * the nibbles by 16, add Y and re-decimalize. Repeat with Z.
706 *
707 * The trick is that "digits" holds a base-10 number, but sometimes
708 * the individual digits are > 10.
709 *
710 * Outer loop is per nibble (hex digit) of input, from MSD end to
711 * LSD end.
712 */
c5aa993b 713 decimal_digits = 0; /* Number of decimal digits so far */
c906108c
SS
714 p = START_P;
715 flip = 0;
c5aa993b
JM
716 while (NOT_END_P)
717 {
c906108c
SS
718 /*
719 * Multiply current base-ten number by 16 in place.
720 * Each digit was between 0 and 9, now is between
721 * 0 and 144.
722 */
c5aa993b
JM
723 for (j = 0; j < decimal_digits; j++)
724 {
725 digits[j] = SHIFT (digits[j]);
726 }
727
c906108c
SS
728 /* Take the next nibble off the input and add it to what
729 * we've got in the LSB position. Bottom 'digit' is now
730 * between 0 and 159.
731 *
732 * "flip" is used to run this loop twice for each byte.
733 */
c5aa993b
JM
734 if (flip == 0)
735 {
736 /* Take top nibble.
737 */
738 digits[0] += HIGH_NIBBLE (*p);
739 flip = 1;
740 }
741 else
742 {
743 /* Take low nibble and bump our pointer "p".
744 */
745 digits[0] += LOW_NIBBLE (*p);
746 NEXT_P;
747 flip = 0;
748 }
c906108c
SS
749
750 /* Re-decimalize. We have to do this often enough
751 * that we don't overflow, but once per nibble is
752 * overkill. Easier this way, though. Note that the
753 * carry is often larger than 10 (e.g. max initial
754 * carry out of lowest nibble is 15, could bubble all
755 * the way up greater than 10). So we have to do
756 * the carrying beyond the last current digit.
757 */
758 carry = 0;
c5aa993b
JM
759 for (j = 0; j < decimal_len - 1; j++)
760 {
761 digits[j] += carry;
762
763 /* "/" won't handle an unsigned char with
764 * a value that if signed would be negative.
765 * So extend to longword int via "dummy".
766 */
767 dummy = digits[j];
768 carry = CARRY_OUT (dummy);
769 digits[j] = CARRY_LEFT (dummy);
770
771 if (j >= decimal_digits && carry == 0)
772 {
773 /*
774 * All higher digits are 0 and we
775 * no longer have a carry.
776 *
777 * Note: "j" is 0-based, "decimal_digits" is
778 * 1-based.
779 */
780 decimal_digits = j + 1;
781 break;
782 }
783 }
784 }
c906108c
SS
785
786 /* Ok, now "digits" is the decimal representation, with
787 * the "decimal_digits" actual digits. Print!
788 */
c5aa993b
JM
789 for (i = decimal_digits - 1; i >= 0; i--)
790 {
791 fprintf_filtered (stream, "%1d", digits[i]);
792 }
b8c9b27d 793 xfree (digits);
c906108c
SS
794}
795
796/* VALADDR points to an integer of LEN bytes. Print it in hex on stream. */
797
6b9acc27 798void
fc1a4b47 799print_hex_chars (struct ui_file *stream, const gdb_byte *valaddr,
6c403953 800 unsigned len)
c906108c 801{
fc1a4b47 802 const gdb_byte *p;
c906108c
SS
803
804 /* FIXME: We should be not printing leading zeroes in most cases. */
805
bb599908 806 fputs_filtered ("0x", stream);
d7449b42 807 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
c906108c
SS
808 {
809 for (p = valaddr;
810 p < valaddr + len;
811 p++)
812 {
813 fprintf_filtered (stream, "%02x", *p);
814 }
815 }
816 else
817 {
818 for (p = valaddr + len - 1;
819 p >= valaddr;
820 p--)
821 {
822 fprintf_filtered (stream, "%02x", *p);
823 }
824 }
c906108c
SS
825}
826
6b9acc27
JJ
827/* VALADDR points to a char integer of LEN bytes. Print it out in appropriate language form on stream.
828 Omit any leading zero chars. */
829
830void
fc1a4b47 831print_char_chars (struct ui_file *stream, const gdb_byte *valaddr,
6c403953 832 unsigned len)
6b9acc27 833{
fc1a4b47 834 const gdb_byte *p;
6b9acc27
JJ
835
836 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
837 {
838 p = valaddr;
839 while (p < valaddr + len - 1 && *p == 0)
840 ++p;
841
842 while (p < valaddr + len)
843 {
844 LA_EMIT_CHAR (*p, stream, '\'');
845 ++p;
846 }
847 }
848 else
849 {
850 p = valaddr + len - 1;
851 while (p > valaddr && *p == 0)
852 --p;
853
854 while (p >= valaddr)
855 {
856 LA_EMIT_CHAR (*p, stream, '\'');
857 --p;
858 }
859 }
860}
861
c906108c 862/* Called by various <lang>_val_print routines to print elements of an
c5aa993b 863 array in the form "<elem1>, <elem2>, <elem3>, ...".
c906108c 864
c5aa993b
JM
865 (FIXME?) Assumes array element separator is a comma, which is correct
866 for all languages currently handled.
867 (FIXME?) Some languages have a notation for repeated array elements,
868 perhaps we should try to use that notation when appropriate.
869 */
c906108c
SS
870
871void
fc1a4b47 872val_print_array_elements (struct type *type, const gdb_byte *valaddr,
a2bd3dcd
AC
873 CORE_ADDR address, struct ui_file *stream,
874 int format, int deref_ref,
fba45db2
KB
875 int recurse, enum val_prettyprint pretty,
876 unsigned int i)
c906108c
SS
877{
878 unsigned int things_printed = 0;
879 unsigned len;
880 struct type *elttype;
881 unsigned eltlen;
882 /* Position of the array element we are examining to see
883 whether it is repeated. */
884 unsigned int rep1;
885 /* Number of repetitions we have detected so far. */
886 unsigned int reps;
c5aa993b 887
c906108c
SS
888 elttype = TYPE_TARGET_TYPE (type);
889 eltlen = TYPE_LENGTH (check_typedef (elttype));
890 len = TYPE_LENGTH (type) / eltlen;
891
892 annotate_array_section_begin (i, elttype);
893
894 for (; i < len && things_printed < print_max; i++)
895 {
896 if (i != 0)
897 {
898 if (prettyprint_arrays)
899 {
900 fprintf_filtered (stream, ",\n");
901 print_spaces_filtered (2 + 2 * recurse, stream);
902 }
903 else
904 {
905 fprintf_filtered (stream, ", ");
906 }
907 }
908 wrap_here (n_spaces (2 + 2 * recurse));
909
910 rep1 = i + 1;
911 reps = 1;
c5aa993b 912 while ((rep1 < len) &&
c906108c
SS
913 !memcmp (valaddr + i * eltlen, valaddr + rep1 * eltlen, eltlen))
914 {
915 ++reps;
916 ++rep1;
917 }
918
919 if (reps > repeat_count_threshold)
920 {
921 val_print (elttype, valaddr + i * eltlen, 0, 0, stream, format,
922 deref_ref, recurse + 1, pretty);
923 annotate_elt_rep (reps);
924 fprintf_filtered (stream, " <repeats %u times>", reps);
925 annotate_elt_rep_end ();
926
927 i = rep1 - 1;
928 things_printed += repeat_count_threshold;
929 }
930 else
931 {
932 val_print (elttype, valaddr + i * eltlen, 0, 0, stream, format,
933 deref_ref, recurse + 1, pretty);
934 annotate_elt ();
935 things_printed++;
936 }
937 }
938 annotate_array_section_end ();
939 if (i < len)
940 {
941 fprintf_filtered (stream, "...");
942 }
943}
944
917317f4
JM
945/* Read LEN bytes of target memory at address MEMADDR, placing the
946 results in GDB's memory at MYADDR. Returns a count of the bytes
947 actually read, and optionally an errno value in the location
948 pointed to by ERRNOPTR if ERRNOPTR is non-null. */
949
950/* FIXME: cagney/1999-10-14: Only used by val_print_string. Can this
951 function be eliminated. */
952
953static int
954partial_memory_read (CORE_ADDR memaddr, char *myaddr, int len, int *errnoptr)
955{
956 int nread; /* Number of bytes actually read. */
957 int errcode; /* Error from last read. */
958
959 /* First try a complete read. */
960 errcode = target_read_memory (memaddr, myaddr, len);
961 if (errcode == 0)
962 {
963 /* Got it all. */
964 nread = len;
965 }
966 else
967 {
968 /* Loop, reading one byte at a time until we get as much as we can. */
969 for (errcode = 0, nread = 0; len > 0 && errcode == 0; nread++, len--)
970 {
971 errcode = target_read_memory (memaddr++, myaddr++, 1);
972 }
973 /* If an error, the last read was unsuccessful, so adjust count. */
974 if (errcode != 0)
975 {
976 nread--;
977 }
978 }
979 if (errnoptr != NULL)
980 {
981 *errnoptr = errcode;
982 }
983 return (nread);
984}
985
c906108c 986/* Print a string from the inferior, starting at ADDR and printing up to LEN
c5aa993b
JM
987 characters, of WIDTH bytes a piece, to STREAM. If LEN is -1, printing
988 stops at the first null byte, otherwise printing proceeds (including null
989 bytes) until either print_max or LEN characters have been printed,
990 whichever is smaller. */
c906108c
SS
991
992/* FIXME: Use target_read_string. */
993
994int
fba45db2 995val_print_string (CORE_ADDR addr, int len, int width, struct ui_file *stream)
c906108c
SS
996{
997 int force_ellipsis = 0; /* Force ellipsis to be printed if nonzero. */
998 int errcode; /* Errno returned from bad reads. */
999 unsigned int fetchlimit; /* Maximum number of chars to print. */
1000 unsigned int nfetch; /* Chars to fetch / chars fetched. */
1001 unsigned int chunksize; /* Size of each fetch, in chars. */
1002 char *buffer = NULL; /* Dynamically growable fetch buffer. */
1003 char *bufptr; /* Pointer to next available byte in buffer. */
1004 char *limit; /* First location past end of fetch buffer. */
c5aa993b 1005 struct cleanup *old_chain = NULL; /* Top of the old cleanup chain. */
c906108c
SS
1006 int found_nul; /* Non-zero if we found the nul char */
1007
1008 /* First we need to figure out the limit on the number of characters we are
1009 going to attempt to fetch and print. This is actually pretty simple. If
1010 LEN >= zero, then the limit is the minimum of LEN and print_max. If
1011 LEN is -1, then the limit is print_max. This is true regardless of
1012 whether print_max is zero, UINT_MAX (unlimited), or something in between,
1013 because finding the null byte (or available memory) is what actually
1014 limits the fetch. */
1015
1016 fetchlimit = (len == -1 ? print_max : min (len, print_max));
1017
1018 /* Now decide how large of chunks to try to read in one operation. This
1019 is also pretty simple. If LEN >= zero, then we want fetchlimit chars,
1020 so we might as well read them all in one operation. If LEN is -1, we
1021 are looking for a null terminator to end the fetching, so we might as
1022 well read in blocks that are large enough to be efficient, but not so
1023 large as to be slow if fetchlimit happens to be large. So we choose the
1024 minimum of 8 and fetchlimit. We used to use 200 instead of 8 but
1025 200 is way too big for remote debugging over a serial line. */
1026
1027 chunksize = (len == -1 ? min (8, fetchlimit) : fetchlimit);
1028
1029 /* Loop until we either have all the characters to print, or we encounter
1030 some error, such as bumping into the end of the address space. */
1031
1032 found_nul = 0;
1033 old_chain = make_cleanup (null_cleanup, 0);
1034
1035 if (len > 0)
1036 {
1037 buffer = (char *) xmalloc (len * width);
1038 bufptr = buffer;
b8c9b27d 1039 old_chain = make_cleanup (xfree, buffer);
c906108c 1040
917317f4 1041 nfetch = partial_memory_read (addr, bufptr, len * width, &errcode)
c906108c
SS
1042 / width;
1043 addr += nfetch * width;
1044 bufptr += nfetch * width;
1045 }
1046 else if (len == -1)
1047 {
1048 unsigned long bufsize = 0;
1049 do
1050 {
1051 QUIT;
1052 nfetch = min (chunksize, fetchlimit - bufsize);
1053
1054 if (buffer == NULL)
1055 buffer = (char *) xmalloc (nfetch * width);
1056 else
1057 {
1058 discard_cleanups (old_chain);
1059 buffer = (char *) xrealloc (buffer, (nfetch + bufsize) * width);
1060 }
1061
b8c9b27d 1062 old_chain = make_cleanup (xfree, buffer);
c906108c
SS
1063 bufptr = buffer + bufsize * width;
1064 bufsize += nfetch;
1065
1066 /* Read as much as we can. */
917317f4 1067 nfetch = partial_memory_read (addr, bufptr, nfetch * width, &errcode)
c5aa993b 1068 / width;
c906108c
SS
1069
1070 /* Scan this chunk for the null byte that terminates the string
1071 to print. If found, we don't need to fetch any more. Note
1072 that bufptr is explicitly left pointing at the next character
1073 after the null byte, or at the next character after the end of
1074 the buffer. */
1075
1076 limit = bufptr + nfetch * width;
1077 while (bufptr < limit)
1078 {
1079 unsigned long c;
1080
1081 c = extract_unsigned_integer (bufptr, width);
1082 addr += width;
1083 bufptr += width;
1084 if (c == 0)
1085 {
1086 /* We don't care about any error which happened after
1087 the NULL terminator. */
1088 errcode = 0;
1089 found_nul = 1;
1090 break;
1091 }
1092 }
1093 }
c5aa993b
JM
1094 while (errcode == 0 /* no error */
1095 && bufptr - buffer < fetchlimit * width /* no overrun */
1096 && !found_nul); /* haven't found nul yet */
c906108c
SS
1097 }
1098 else
1099 { /* length of string is really 0! */
1100 buffer = bufptr = NULL;
1101 errcode = 0;
1102 }
1103
1104 /* bufptr and addr now point immediately beyond the last byte which we
1105 consider part of the string (including a '\0' which ends the string). */
1106
1107 /* We now have either successfully filled the buffer to fetchlimit, or
1108 terminated early due to an error or finding a null char when LEN is -1. */
1109
1110 if (len == -1 && !found_nul)
1111 {
1112 char *peekbuf;
1113
1114 /* We didn't find a null terminator we were looking for. Attempt
c5aa993b
JM
1115 to peek at the next character. If not successful, or it is not
1116 a null byte, then force ellipsis to be printed. */
c906108c
SS
1117
1118 peekbuf = (char *) alloca (width);
1119
1120 if (target_read_memory (addr, peekbuf, width) == 0
1121 && extract_unsigned_integer (peekbuf, width) != 0)
1122 force_ellipsis = 1;
1123 }
c5aa993b 1124 else if ((len >= 0 && errcode != 0) || (len > (bufptr - buffer) / width))
c906108c
SS
1125 {
1126 /* Getting an error when we have a requested length, or fetching less
c5aa993b
JM
1127 than the number of characters actually requested, always make us
1128 print ellipsis. */
c906108c
SS
1129 force_ellipsis = 1;
1130 }
1131
1132 QUIT;
1133
1134 /* If we get an error before fetching anything, don't print a string.
1135 But if we fetch something and then get an error, print the string
1136 and then the error message. */
1137 if (errcode == 0 || bufptr > buffer)
1138 {
1139 if (addressprint)
1140 {
1141 fputs_filtered (" ", stream);
1142 }
c5aa993b 1143 LA_PRINT_STRING (stream, buffer, (bufptr - buffer) / width, width, force_ellipsis);
c906108c
SS
1144 }
1145
1146 if (errcode != 0)
1147 {
1148 if (errcode == EIO)
1149 {
1150 fprintf_filtered (stream, " <Address ");
66bf4b3a 1151 deprecated_print_address_numeric (addr, 1, stream);
c906108c
SS
1152 fprintf_filtered (stream, " out of bounds>");
1153 }
1154 else
1155 {
1156 fprintf_filtered (stream, " <Error reading address ");
66bf4b3a 1157 deprecated_print_address_numeric (addr, 1, stream);
c906108c
SS
1158 fprintf_filtered (stream, ": %s>", safe_strerror (errcode));
1159 }
1160 }
1161 gdb_flush (stream);
1162 do_cleanups (old_chain);
c5aa993b 1163 return ((bufptr - buffer) / width);
c906108c 1164}
c906108c 1165\f
c5aa993b 1166
c906108c
SS
1167/* Validate an input or output radix setting, and make sure the user
1168 knows what they really did here. Radix setting is confusing, e.g.
1169 setting the input radix to "10" never changes it! */
1170
c906108c 1171static void
fba45db2 1172set_input_radix (char *args, int from_tty, struct cmd_list_element *c)
c906108c 1173{
f66c9f11 1174 set_input_radix_1 (from_tty, input_radix);
c906108c
SS
1175}
1176
c906108c 1177static void
fba45db2 1178set_input_radix_1 (int from_tty, unsigned radix)
c906108c
SS
1179{
1180 /* We don't currently disallow any input radix except 0 or 1, which don't
1181 make any mathematical sense. In theory, we can deal with any input
1182 radix greater than 1, even if we don't have unique digits for every
1183 value from 0 to radix-1, but in practice we lose on large radix values.
1184 We should either fix the lossage or restrict the radix range more.
1185 (FIXME). */
1186
1187 if (radix < 2)
1188 {
f66c9f11
AC
1189 /* FIXME: cagney/2002-03-17: This needs to revert the bad radix
1190 value. */
8a3fe4f8 1191 error (_("Nonsense input radix ``decimal %u''; input radix unchanged."),
c906108c
SS
1192 radix);
1193 }
1194 input_radix = radix;
1195 if (from_tty)
1196 {
a3f17187 1197 printf_filtered (_("Input radix now set to decimal %u, hex %x, octal %o.\n"),
c906108c
SS
1198 radix, radix, radix);
1199 }
1200}
1201
c906108c 1202static void
fba45db2 1203set_output_radix (char *args, int from_tty, struct cmd_list_element *c)
c906108c 1204{
f66c9f11 1205 set_output_radix_1 (from_tty, output_radix);
c906108c
SS
1206}
1207
1208static void
fba45db2 1209set_output_radix_1 (int from_tty, unsigned radix)
c906108c
SS
1210{
1211 /* Validate the radix and disallow ones that we aren't prepared to
1212 handle correctly, leaving the radix unchanged. */
1213 switch (radix)
1214 {
1215 case 16:
c5aa993b 1216 output_format = 'x'; /* hex */
c906108c
SS
1217 break;
1218 case 10:
c5aa993b 1219 output_format = 0; /* decimal */
c906108c
SS
1220 break;
1221 case 8:
c5aa993b 1222 output_format = 'o'; /* octal */
c906108c
SS
1223 break;
1224 default:
f66c9f11
AC
1225 /* FIXME: cagney/2002-03-17: This needs to revert the bad radix
1226 value. */
8a3fe4f8 1227 error (_("Unsupported output radix ``decimal %u''; output radix unchanged."),
c906108c
SS
1228 radix);
1229 }
1230 output_radix = radix;
1231 if (from_tty)
1232 {
a3f17187 1233 printf_filtered (_("Output radix now set to decimal %u, hex %x, octal %o.\n"),
c906108c
SS
1234 radix, radix, radix);
1235 }
1236}
1237
1238/* Set both the input and output radix at once. Try to set the output radix
1239 first, since it has the most restrictive range. An radix that is valid as
1240 an output radix is also valid as an input radix.
1241
1242 It may be useful to have an unusual input radix. If the user wishes to
1243 set an input radix that is not valid as an output radix, he needs to use
1244 the 'set input-radix' command. */
1245
1246static void
fba45db2 1247set_radix (char *arg, int from_tty)
c906108c
SS
1248{
1249 unsigned radix;
1250
bb518678 1251 radix = (arg == NULL) ? 10 : parse_and_eval_long (arg);
c906108c
SS
1252 set_output_radix_1 (0, radix);
1253 set_input_radix_1 (0, radix);
1254 if (from_tty)
1255 {
a3f17187 1256 printf_filtered (_("Input and output radices now set to decimal %u, hex %x, octal %o.\n"),
c906108c
SS
1257 radix, radix, radix);
1258 }
1259}
1260
1261/* Show both the input and output radices. */
1262
c906108c 1263static void
fba45db2 1264show_radix (char *arg, int from_tty)
c906108c
SS
1265{
1266 if (from_tty)
1267 {
1268 if (input_radix == output_radix)
1269 {
a3f17187 1270 printf_filtered (_("Input and output radices set to decimal %u, hex %x, octal %o.\n"),
c906108c
SS
1271 input_radix, input_radix, input_radix);
1272 }
1273 else
1274 {
a3f17187 1275 printf_filtered (_("Input radix set to decimal %u, hex %x, octal %o.\n"),
c906108c 1276 input_radix, input_radix, input_radix);
a3f17187 1277 printf_filtered (_("Output radix set to decimal %u, hex %x, octal %o.\n"),
c906108c
SS
1278 output_radix, output_radix, output_radix);
1279 }
1280 }
1281}
c906108c 1282\f
c5aa993b 1283
c906108c 1284static void
fba45db2 1285set_print (char *arg, int from_tty)
c906108c
SS
1286{
1287 printf_unfiltered (
c5aa993b 1288 "\"set print\" must be followed by the name of a print subcommand.\n");
c906108c
SS
1289 help_list (setprintlist, "set print ", -1, gdb_stdout);
1290}
1291
c906108c 1292static void
fba45db2 1293show_print (char *args, int from_tty)
c906108c
SS
1294{
1295 cmd_show_list (showprintlist, from_tty, "");
1296}
1297\f
1298void
fba45db2 1299_initialize_valprint (void)
c906108c
SS
1300{
1301 struct cmd_list_element *c;
1302
1303 add_prefix_cmd ("print", no_class, set_print,
1bedd215 1304 _("Generic command for setting how things print."),
c906108c 1305 &setprintlist, "set print ", 0, &setlist);
c5aa993b
JM
1306 add_alias_cmd ("p", "print", no_class, 1, &setlist);
1307 /* prefer set print to set prompt */
c906108c
SS
1308 add_alias_cmd ("pr", "print", no_class, 1, &setlist);
1309
1310 add_prefix_cmd ("print", no_class, show_print,
1bedd215 1311 _("Generic command for showing print settings."),
c906108c 1312 &showprintlist, "show print ", 0, &showlist);
c5aa993b
JM
1313 add_alias_cmd ("p", "print", no_class, 1, &showlist);
1314 add_alias_cmd ("pr", "print", no_class, 1, &showlist);
c906108c 1315
35096d9d
AC
1316 add_setshow_uinteger_cmd ("elements", no_class, &print_max, _("\
1317Set limit on string chars or array elements to print."), _("\
1318Show limit on string chars or array elements to print."), _("\
1319\"set print elements 0\" causes there to be no limit."),
1320 NULL,
920d2a44 1321 show_print_max,
35096d9d 1322 &setprintlist, &showprintlist);
c906108c 1323
5bf193a2
AC
1324 add_setshow_boolean_cmd ("null-stop", no_class, &stop_print_at_null, _("\
1325Set printing of char arrays to stop at first null char."), _("\
1326Show printing of char arrays to stop at first null char."), NULL,
1327 NULL,
920d2a44 1328 show_stop_print_at_null,
5bf193a2 1329 &setprintlist, &showprintlist);
c906108c 1330
35096d9d
AC
1331 add_setshow_uinteger_cmd ("repeats", no_class,
1332 &repeat_count_threshold, _("\
1333Set threshold for repeated print elements."), _("\
1334Show threshold for repeated print elements."), _("\
1335\"set print repeats 0\" causes all elements to be individually printed."),
1336 NULL,
920d2a44 1337 show_repeat_count_threshold,
35096d9d 1338 &setprintlist, &showprintlist);
c906108c 1339
5bf193a2
AC
1340 add_setshow_boolean_cmd ("pretty", class_support, &prettyprint_structs, _("\
1341Set prettyprinting of structures."), _("\
1342Show prettyprinting of structures."), NULL,
1343 NULL,
920d2a44 1344 show_prettyprint_structs,
5bf193a2
AC
1345 &setprintlist, &showprintlist);
1346
1347 add_setshow_boolean_cmd ("union", class_support, &unionprint, _("\
1348Set printing of unions interior to structures."), _("\
1349Show printing of unions interior to structures."), NULL,
1350 NULL,
920d2a44 1351 show_unionprint,
5bf193a2
AC
1352 &setprintlist, &showprintlist);
1353
1354 add_setshow_boolean_cmd ("array", class_support, &prettyprint_arrays, _("\
1355Set prettyprinting of arrays."), _("\
1356Show prettyprinting of arrays."), NULL,
1357 NULL,
920d2a44 1358 show_prettyprint_arrays,
5bf193a2
AC
1359 &setprintlist, &showprintlist);
1360
1361 add_setshow_boolean_cmd ("address", class_support, &addressprint, _("\
1362Set printing of addresses."), _("\
1363Show printing of addresses."), NULL,
1364 NULL,
920d2a44 1365 show_addressprint,
5bf193a2 1366 &setprintlist, &showprintlist);
c906108c 1367
35096d9d
AC
1368 add_setshow_uinteger_cmd ("input-radix", class_support, &input_radix, _("\
1369Set default input radix for entering numbers."), _("\
1370Show default input radix for entering numbers."), NULL,
1371 set_input_radix,
920d2a44 1372 show_input_radix,
35096d9d
AC
1373 &setlist, &showlist);
1374
1375 add_setshow_uinteger_cmd ("output-radix", class_support, &output_radix, _("\
1376Set default output radix for printing of values."), _("\
1377Show default output radix for printing of values."), NULL,
1378 set_output_radix,
920d2a44 1379 show_output_radix,
35096d9d 1380 &setlist, &showlist);
c906108c 1381
cb1a6d5f
AC
1382 /* The "set radix" and "show radix" commands are special in that
1383 they are like normal set and show commands but allow two normally
1384 independent variables to be either set or shown with a single
b66df561 1385 command. So the usual deprecated_add_set_cmd() and [deleted]
cb1a6d5f 1386 add_show_from_set() commands aren't really appropriate. */
b66df561
AC
1387 /* FIXME: i18n: With the new add_setshow_integer command, that is no
1388 longer true - show can display anything. */
1a966eab
AC
1389 add_cmd ("radix", class_support, set_radix, _("\
1390Set default input and output number radices.\n\
c906108c 1391Use 'set input-radix' or 'set output-radix' to independently set each.\n\
1a966eab 1392Without an argument, sets both radices back to the default value of 10."),
c906108c 1393 &setlist);
1a966eab
AC
1394 add_cmd ("radix", class_support, show_radix, _("\
1395Show the default input and output number radices.\n\
1396Use 'show input-radix' or 'show output-radix' to independently show each."),
c906108c
SS
1397 &showlist);
1398
1399 /* Give people the defaults which they are used to. */
1400 prettyprint_structs = 0;
1401 prettyprint_arrays = 0;
1402 unionprint = 1;
1403 addressprint = 1;
1404 print_max = PRINT_MAX_DEFAULT;
1405}
This page took 0.679179 seconds and 4 git commands to generate.