PageRenderTime 62ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/src/freebsd/contrib/gdb/gdb/valprint.c

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