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