Commit | Line | Data |
---|---|---|
7d9884b9 JG |
1 | /* Print values for GDB, the GNU debugger. |
2 | Copyright 1986, 1988, 1989, 1991 Free Software Foundation, Inc. | |
bd5635a1 RP |
3 | |
4 | This file is part of GDB. | |
5 | ||
36b9d39c | 6 | This program is free software; you can redistribute it and/or modify |
bd5635a1 | 7 | it under the terms of the GNU General Public License as published by |
36b9d39c JG |
8 | the Free Software Foundation; either version 2 of the License, or |
9 | (at your option) any later version. | |
bd5635a1 | 10 | |
36b9d39c | 11 | This program is distributed in the hope that it will be useful, |
bd5635a1 RP |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
36b9d39c JG |
17 | along with this program; if not, write to the Free Software |
18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
bd5635a1 | 19 | |
bd5635a1 | 20 | #include "defs.h" |
2cd99985 | 21 | #include <string.h> |
bd5635a1 | 22 | #include "symtab.h" |
2cd99985 | 23 | #include "gdbtypes.h" |
bd5635a1 RP |
24 | #include "value.h" |
25 | #include "gdbcore.h" | |
26 | #include "gdbcmd.h" | |
27 | #include "target.h" | |
28 | #include "obstack.h" | |
be3bc7ad | 29 | #include "language.h" |
8f793aa5 | 30 | #include "demangle.h" |
bd5635a1 RP |
31 | |
32 | #include <errno.h> | |
2cd99985 PB |
33 | |
34 | /* Prototypes for local functions */ | |
35 | ||
a8a69e63 | 36 | static void |
199b2450 | 37 | print_hex_chars PARAMS ((GDB_FILE *, unsigned char *, unsigned int)); |
a8a69e63 | 38 | |
2cd99985 PB |
39 | static void |
40 | show_print PARAMS ((char *, int)); | |
41 | ||
42 | static void | |
43 | set_print PARAMS ((char *, int)); | |
44 | ||
45 | static void | |
ce13daa7 FF |
46 | set_radix PARAMS ((char *, int)); |
47 | ||
48 | static void | |
49 | show_radix PARAMS ((char *, int)); | |
50 | ||
51 | static void | |
52 | set_input_radix PARAMS ((char *, int, struct cmd_list_element *)); | |
53 | ||
54 | static void | |
55 | set_input_radix_1 PARAMS ((int, unsigned)); | |
2cd99985 PB |
56 | |
57 | static void | |
58 | set_output_radix PARAMS ((char *, int, struct cmd_list_element *)); | |
59 | ||
ce13daa7 FF |
60 | static void |
61 | set_output_radix_1 PARAMS ((int, unsigned)); | |
62 | ||
2cd99985 | 63 | static void |
199b2450 | 64 | value_print_array_elements PARAMS ((value, GDB_FILE *, int, enum val_prettyprint)); |
bd5635a1 | 65 | |
ce13daa7 FF |
66 | /* Maximum number of chars to print for a string pointer value or vector |
67 | contents, or UINT_MAX for no limit. Note that "set print elements 0" | |
68 | stores UINT_MAX in print_max, which displays in a show command as | |
69 | "unlimited". */ | |
bd5635a1 | 70 | |
85f0a848 | 71 | unsigned int print_max; |
ce13daa7 | 72 | #define PRINT_MAX_DEFAULT 200 /* Start print_max off at this value. */ |
bd5635a1 | 73 | |
bd5635a1 RP |
74 | /* Default input and output radixes, and output format letter. */ |
75 | ||
76 | unsigned input_radix = 10; | |
77 | unsigned output_radix = 10; | |
78 | int output_format = 0; | |
79 | ||
85f0a848 FF |
80 | /* Print repeat counts if there are more than this many repetitions of an |
81 | element in an array. Referenced by the low level language dependent | |
82 | print routines. */ | |
83 | ||
84 | unsigned int repeat_count_threshold = 10; | |
0dce3774 | 85 | |
a8a69e63 FF |
86 | int prettyprint_structs; /* Controls pretty printing of structures */ |
87 | int prettyprint_arrays; /* Controls pretty printing of arrays. */ | |
0dce3774 | 88 | |
a8a69e63 FF |
89 | /* If nonzero, causes unions inside structures or other unions to be |
90 | printed. */ | |
bd5635a1 | 91 | |
a8a69e63 | 92 | int unionprint; /* Controls printing of nested unions. */ |
bd5635a1 | 93 | |
a8a69e63 | 94 | /* If nonzero, causes machine addresses to be printed in certain contexts. */ |
bd5635a1 | 95 | |
a8a69e63 | 96 | int addressprint; /* Controls printing of machine addresses */ |
bd5635a1 | 97 | |
a8a69e63 | 98 | \f |
c7da3ed3 FF |
99 | /* Print data of type TYPE located at VALADDR (within GDB), which came from |
100 | the inferior at address ADDRESS, onto stdio stream STREAM according to | |
101 | FORMAT (a letter, or 0 for natural format using TYPE). | |
bd5635a1 | 102 | |
c7da3ed3 FF |
103 | If DEREF_REF is nonzero, then dereference references, otherwise just print |
104 | them like pointers. | |
bd5635a1 | 105 | |
c7da3ed3 FF |
106 | The PRETTY parameter controls prettyprinting. |
107 | ||
108 | If the data are a string pointer, returns the number of string characters | |
109 | printed. | |
110 | ||
111 | FIXME: The data at VALADDR is in target byte order. If gdb is ever | |
112 | enhanced to be able to debug more than the single target it was compiled | |
113 | for (specific CPU type and thus specific target byte ordering), then | |
114 | either the print routines are going to have to take this into account, | |
115 | or the data is going to have to be passed into here already converted | |
116 | to the host byte ordering, whichever is more convenient. */ | |
bd5635a1 | 117 | |
bd5635a1 | 118 | |
a8a69e63 | 119 | int |
c7da3ed3 | 120 | val_print (type, valaddr, address, stream, format, deref_ref, recurse, pretty) |
a8a69e63 FF |
121 | struct type *type; |
122 | char *valaddr; | |
123 | CORE_ADDR address; | |
199b2450 | 124 | GDB_FILE *stream; |
a8a69e63 FF |
125 | int format; |
126 | int deref_ref; | |
127 | int recurse; | |
128 | enum val_prettyprint pretty; | |
bd5635a1 | 129 | { |
a8a69e63 FF |
130 | if (pretty == Val_pretty_default) |
131 | { | |
132 | pretty = prettyprint_structs ? Val_prettyprint : Val_no_prettyprint; | |
133 | } | |
bd5635a1 | 134 | |
a8a69e63 FF |
135 | QUIT; |
136 | ||
137 | /* Ensure that the type is complete and not just a stub. If the type is | |
138 | only a stub and we can't find and substitute its complete type, then | |
139 | print appropriate string and return. Typical types that my be stubs | |
140 | are structs, unions, and C++ methods. */ | |
141 | ||
142 | check_stub_type (type); | |
143 | if (TYPE_FLAGS (type) & TYPE_FLAG_STUB) | |
bd5635a1 | 144 | { |
a8a69e63 | 145 | fprintf_filtered (stream, "<incomplete type>"); |
199b2450 | 146 | gdb_flush (stream); |
a8a69e63 | 147 | return (0); |
bd5635a1 | 148 | } |
a8a69e63 FF |
149 | |
150 | return (LA_VAL_PRINT (type, valaddr, address, stream, format, deref_ref, | |
151 | recurse, pretty)); | |
bd5635a1 | 152 | } |
a8a69e63 | 153 | |
bd5635a1 RP |
154 | /* Print the value VAL in C-ish syntax on stream STREAM. |
155 | FORMAT is a format-letter, or 0 for print in natural format of data type. | |
156 | If the object printed is a string pointer, returns | |
157 | the number of string bytes printed. */ | |
158 | ||
159 | int | |
160 | value_print (val, stream, format, pretty) | |
161 | value val; | |
199b2450 | 162 | GDB_FILE *stream; |
2cd99985 | 163 | int format; |
bd5635a1 RP |
164 | enum val_prettyprint pretty; |
165 | { | |
a8a69e63 | 166 | register unsigned int n, typelen; |
bd5635a1 RP |
167 | |
168 | if (val == 0) | |
169 | { | |
170 | printf_filtered ("<address of value unknown>"); | |
171 | return 0; | |
172 | } | |
173 | if (VALUE_OPTIMIZED_OUT (val)) | |
174 | { | |
175 | printf_filtered ("<value optimized out>"); | |
176 | return 0; | |
177 | } | |
aec4cb91 | 178 | |
bd5635a1 RP |
179 | /* A "repeated" value really contains several values in a row. |
180 | They are made by the @ operator. | |
181 | Print such values as if they were arrays. */ | |
182 | ||
a8a69e63 | 183 | if (VALUE_REPEATED (val)) |
bd5635a1 RP |
184 | { |
185 | n = VALUE_REPETITIONS (val); | |
186 | typelen = TYPE_LENGTH (VALUE_TYPE (val)); | |
187 | fprintf_filtered (stream, "{"); | |
188 | /* Print arrays of characters using string syntax. */ | |
189 | if (typelen == 1 && TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_INT | |
190 | && format == 0) | |
a8a69e63 | 191 | LA_PRINT_STRING (stream, VALUE_CONTENTS (val), n, 0); |
bd5635a1 RP |
192 | else |
193 | { | |
a8a69e63 | 194 | value_print_array_elements (val, stream, format, pretty); |
bd5635a1 RP |
195 | } |
196 | fprintf_filtered (stream, "}"); | |
a8a69e63 | 197 | return (n * typelen); |
bd5635a1 RP |
198 | } |
199 | else | |
200 | { | |
0dce3774 JK |
201 | struct type *type = VALUE_TYPE (val); |
202 | ||
bd5635a1 RP |
203 | /* If it is a pointer, indicate what it points to. |
204 | ||
205 | Print type also if it is a reference. | |
206 | ||
207 | C++: if it is a member pointer, we will take care | |
208 | of that when we print it. */ | |
a8a69e63 FF |
209 | if (TYPE_CODE (type) == TYPE_CODE_PTR || |
210 | TYPE_CODE (type) == TYPE_CODE_REF) | |
bd5635a1 RP |
211 | { |
212 | /* Hack: remove (char *) for char strings. Their | |
213 | type is indicated by the quoted string anyway. */ | |
a8a69e63 FF |
214 | if (TYPE_CODE (type) == TYPE_CODE_PTR && |
215 | TYPE_LENGTH (TYPE_TARGET_TYPE (type)) == sizeof(char) && | |
216 | TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_INT && | |
217 | !TYPE_UNSIGNED (TYPE_TARGET_TYPE (type))) | |
bd5635a1 RP |
218 | { |
219 | /* Print nothing */ | |
220 | } | |
a8a69e63 FF |
221 | else |
222 | { | |
223 | fprintf_filtered (stream, "("); | |
224 | type_print (type, "", stream, -1); | |
225 | fprintf_filtered (stream, ") "); | |
226 | } | |
227 | } | |
228 | return (val_print (type, VALUE_CONTENTS (val), | |
229 | VALUE_ADDRESS (val), stream, format, 1, 0, pretty)); | |
bd5635a1 RP |
230 | } |
231 | } | |
232 | ||
a8a69e63 FF |
233 | /* Called by various <lang>_val_print routines to print TYPE_CODE_INT's */ |
234 | ||
235 | void | |
236 | val_print_type_code_int (type, valaddr, stream) | |
9e4667f6 | 237 | struct type *type; |
a8a69e63 | 238 | char *valaddr; |
199b2450 | 239 | GDB_FILE *stream; |
9e4667f6 | 240 | { |
a8a69e63 FF |
241 | char *p; |
242 | /* Pointer to first (i.e. lowest address) nonzero character. */ | |
243 | char *first_addr; | |
244 | unsigned int len; | |
9e4667f6 | 245 | |
a8a69e63 | 246 | if (TYPE_LENGTH (type) > sizeof (LONGEST)) |
9e4667f6 | 247 | { |
a8a69e63 | 248 | if (TYPE_UNSIGNED (type)) |
9e4667f6 | 249 | { |
a8a69e63 FF |
250 | /* First figure out whether the number in fact has zeros |
251 | in all its bytes more significant than least significant | |
252 | sizeof (LONGEST) ones. */ | |
253 | len = TYPE_LENGTH (type); | |
254 | ||
255 | #if TARGET_BYTE_ORDER == BIG_ENDIAN | |
256 | for (p = valaddr; | |
257 | len > sizeof (LONGEST) && p < valaddr + TYPE_LENGTH (type); | |
258 | p++) | |
259 | #else /* Little endian. */ | |
260 | first_addr = valaddr; | |
199b2450 | 261 | for (p = valaddr + TYPE_LENGTH (type) - 1; |
a8a69e63 FF |
262 | len > sizeof (LONGEST) && p >= valaddr; |
263 | p--) | |
264 | #endif /* Little endian. */ | |
9e4667f6 | 265 | { |
a8a69e63 | 266 | if (*p == 0) |
9e4667f6 | 267 | { |
a8a69e63 | 268 | len--; |
9e4667f6 | 269 | } |
a8a69e63 | 270 | else |
9e4667f6 | 271 | { |
a8a69e63 | 272 | break; |
9e4667f6 FF |
273 | } |
274 | } | |
a8a69e63 FF |
275 | #if TARGET_BYTE_ORDER == BIG_ENDIAN |
276 | first_addr = p; | |
277 | #endif | |
278 | if (len <= sizeof (LONGEST)) | |
279 | { | |
280 | /* We can print it in decimal. */ | |
7efb57c3 FF |
281 | print_longest (stream, 'u', 0, |
282 | unpack_long (BUILTIN_TYPE_LONGEST, first_addr)); | |
a8a69e63 FF |
283 | } |
284 | else | |
285 | { | |
286 | /* It is big, so print it in hex. */ | |
287 | print_hex_chars (stream, (unsigned char *) first_addr, len); | |
288 | } | |
289 | } | |
290 | else | |
291 | { | |
292 | /* Signed. One could assume two's complement (a reasonable | |
293 | assumption, I think) and do better than this. */ | |
294 | print_hex_chars (stream, (unsigned char *) valaddr, | |
295 | TYPE_LENGTH (type)); | |
9e4667f6 FF |
296 | } |
297 | } | |
a8a69e63 FF |
298 | else |
299 | { | |
300 | #ifdef PRINT_TYPELESS_INTEGER | |
301 | PRINT_TYPELESS_INTEGER (stream, type, unpack_long (type, valaddr)); | |
302 | #else | |
7efb57c3 FF |
303 | print_longest (stream, TYPE_UNSIGNED (type) ? 'u' : 'd', 0, |
304 | unpack_long (type, valaddr)); | |
a8a69e63 FF |
305 | #endif |
306 | } | |
b0f61d04 | 307 | } |
9e4667f6 | 308 | |
7efb57c3 FF |
309 | /* Print a number according to FORMAT which is one of d,u,x,o,b,h,w,g. |
310 | The raison d'etre of this function is to consolidate printing of LONG_LONG's | |
311 | into this one function. Some platforms have long longs but don't have a | |
312 | printf() that supports "ll" in the format string. We handle these by seeing | |
313 | if the number is actually a long, and if not we just bail out and print the | |
314 | number in hex. The format chars b,h,w,g are from | |
315 | print_scalar_formatted(). USE_LOCAL says whether or not to call the | |
316 | local formatting routine to get the format. */ | |
317 | ||
318 | void | |
319 | print_longest (stream, format, use_local, val_long) | |
199b2450 | 320 | GDB_FILE *stream; |
ce13daa7 | 321 | int format; |
7efb57c3 FF |
322 | int use_local; |
323 | LONGEST val_long; | |
324 | { | |
325 | #if defined (CC_HAS_LONG_LONG) && !defined (PRINTF_HAS_LONG_LONG) | |
326 | long vtop, vbot; | |
327 | ||
328 | vtop = val_long >> (sizeof (long) * HOST_CHAR_BIT); | |
329 | vbot = (long) val_long; | |
330 | ||
331 | if ((format == 'd' && (val_long < INT_MIN || val_long > INT_MAX)) | |
332 | || ((format == 'u' || format == 'x') && val_long > UINT_MAX)) | |
333 | { | |
199b2450 | 334 | fprintf_filtered (stream, "0x%lx%08lx", vtop, vbot); |
7efb57c3 FF |
335 | return; |
336 | } | |
337 | #endif | |
338 | ||
339 | #ifdef PRINTF_HAS_LONG_LONG | |
340 | switch (format) | |
341 | { | |
342 | case 'd': | |
343 | fprintf_filtered (stream, | |
344 | use_local ? local_decimal_format_custom ("ll") | |
345 | : "%lld", | |
346 | val_long); | |
347 | break; | |
348 | case 'u': | |
349 | fprintf_filtered (stream, "%llu", val_long); | |
350 | break; | |
351 | case 'x': | |
352 | fprintf_filtered (stream, | |
353 | use_local ? local_hex_format_custom ("ll") | |
354 | : "%llx", | |
355 | val_long); | |
356 | break; | |
357 | case 'o': | |
358 | fprintf_filtered (stream, | |
359 | use_local ? local_octal_format_custom ("ll") | |
360 | : "%llo", | |
361 | break; | |
362 | case 'b': | |
363 | fprintf_filtered (stream, local_hex_format_custom ("02ll"), val_long); | |
364 | break; | |
365 | case 'h': | |
366 | fprintf_filtered (stream, local_hex_format_custom ("04ll"), val_long); | |
367 | break; | |
368 | case 'w': | |
369 | fprintf_filtered (stream, local_hex_format_custom ("08ll"), val_long); | |
370 | break; | |
371 | case 'g': | |
372 | fprintf_filtered (stream, local_hex_format_custom ("016ll"), val_long); | |
373 | break; | |
374 | default: | |
375 | abort (); | |
376 | } | |
377 | #else /* !PRINTF_HAS_LONG_LONG */ | |
378 | /* In the following it is important to coerce (val_long) to a long. It does | |
379 | nothing if !LONG_LONG, but it will chop off the top half (which we know | |
380 | we can ignore) if the host supports long longs. */ | |
381 | ||
382 | switch (format) | |
383 | { | |
384 | case 'd': | |
385 | fprintf_filtered (stream, | |
386 | use_local ? local_decimal_format_custom ("l") | |
387 | : "%ld", | |
388 | (long) val_long); | |
389 | break; | |
390 | case 'u': | |
391 | fprintf_filtered (stream, "%lu", (unsigned long) val_long); | |
392 | break; | |
393 | case 'x': | |
394 | fprintf_filtered (stream, | |
395 | use_local ? local_hex_format_custom ("l") | |
396 | : "%lx", | |
397 | (long) val_long); | |
398 | break; | |
399 | case 'o': | |
400 | fprintf_filtered (stream, | |
401 | use_local ? local_octal_format_custom ("l") | |
402 | : "%lo", | |
403 | (long) val_long); | |
404 | break; | |
405 | case 'b': | |
406 | fprintf_filtered (stream, local_hex_format_custom ("02l"), | |
407 | (long) val_long); | |
408 | break; | |
409 | case 'h': | |
410 | fprintf_filtered (stream, local_hex_format_custom ("04l"), | |
411 | (long) val_long); | |
412 | break; | |
413 | case 'w': | |
414 | fprintf_filtered (stream, local_hex_format_custom ("08l"), | |
415 | (long) val_long); | |
416 | break; | |
417 | case 'g': | |
418 | fprintf_filtered (stream, local_hex_format_custom ("016l"), | |
419 | (long) val_long); | |
420 | break; | |
421 | default: | |
422 | abort (); | |
423 | } | |
424 | #endif /* !PRINTF_HAS_LONG_LONG */ | |
425 | } | |
426 | ||
a8a69e63 FF |
427 | /* Print a floating point value of type TYPE, pointed to in GDB by VALADDR, |
428 | on STREAM. */ | |
bd5635a1 | 429 | |
a8a69e63 FF |
430 | void |
431 | print_floating (valaddr, type, stream) | |
432 | char *valaddr; | |
bd5635a1 | 433 | struct type *type; |
199b2450 | 434 | GDB_FILE *stream; |
bd5635a1 | 435 | { |
a8a69e63 FF |
436 | double doub; |
437 | int inv; | |
438 | unsigned len = TYPE_LENGTH (type); | |
439 | ||
440 | #if defined (IEEE_FLOAT) | |
bd5635a1 | 441 | |
a8a69e63 FF |
442 | /* Check for NaN's. Note that this code does not depend on us being |
443 | on an IEEE conforming system. It only depends on the target | |
444 | machine using IEEE representation. This means (a) | |
445 | cross-debugging works right, and (2) IEEE_FLOAT can (and should) | |
446 | be defined for systems like the 68881, which uses IEEE | |
447 | representation, but is not IEEE conforming. */ | |
bd5635a1 | 448 | |
a8a69e63 | 449 | { |
199b2450 | 450 | unsigned long low, high; |
a8a69e63 FF |
451 | /* Is the sign bit 0? */ |
452 | int nonnegative; | |
453 | /* Is it is a NaN (i.e. the exponent is all ones and | |
454 | the fraction is nonzero)? */ | |
455 | int is_nan; | |
bd5635a1 | 456 | |
199b2450 | 457 | if (len == 4) |
a8a69e63 | 458 | { |
199b2450 TL |
459 | /* It's single precision. */ |
460 | /* Assume that floating point byte order is the same as | |
461 | integer byte order. */ | |
462 | low = extract_unsigned_integer (valaddr, 4); | |
833e0d94 | 463 | nonnegative = ((low & 0x80000000) == 0); |
a8a69e63 FF |
464 | is_nan = ((((low >> 23) & 0xFF) == 0xFF) |
465 | && 0 != (low & 0x7FFFFF)); | |
466 | low &= 0x7fffff; | |
467 | high = 0; | |
468 | } | |
199b2450 | 469 | else if (len == 8) |
a8a69e63 FF |
470 | { |
471 | /* It's double precision. Get the high and low words. */ | |
bd5635a1 | 472 | |
199b2450 TL |
473 | /* Assume that floating point byte order is the same as |
474 | integer byte order. */ | |
a8a69e63 | 475 | #if TARGET_BYTE_ORDER == BIG_ENDIAN |
199b2450 TL |
476 | low = extract_unsigned_integer (valaddr + 4, 4); |
477 | high = extract_unsigned_integer (valaddr, 4); | |
a8a69e63 | 478 | #else |
199b2450 TL |
479 | low = extract_unsigned_integer (valaddr, 4); |
480 | high = extract_unsigned_integer (valaddr + 4, 4); | |
a8a69e63 | 481 | #endif |
833e0d94 | 482 | nonnegative = ((high & 0x80000000) == 0); |
a8a69e63 FF |
483 | is_nan = (((high >> 20) & 0x7ff) == 0x7ff |
484 | && ! ((((high & 0xfffff) == 0)) && (low == 0))); | |
485 | high &= 0xfffff; | |
486 | } | |
199b2450 TL |
487 | else |
488 | /* Extended. We can't detect NaNs for extendeds yet. Also note | |
489 | that currently extendeds get nuked to double in | |
490 | REGISTER_CONVERTIBLE. */ | |
491 | is_nan = 0; | |
bd5635a1 | 492 | |
a8a69e63 FF |
493 | if (is_nan) |
494 | { | |
495 | /* The meaning of the sign and fraction is not defined by IEEE. | |
496 | But the user might know what they mean. For example, they | |
497 | (in an implementation-defined manner) distinguish between | |
498 | signaling and quiet NaN's. */ | |
499 | if (high) | |
500 | fprintf_filtered (stream, "-NaN(0x%lx%.8lx)" + nonnegative, | |
501 | high, low); | |
502 | else | |
503 | fprintf_filtered (stream, "-NaN(0x%lx)" + nonnegative, low); | |
504 | return; | |
505 | } | |
506 | } | |
507 | #endif /* IEEE_FLOAT. */ | |
bd5635a1 | 508 | |
a8a69e63 FF |
509 | doub = unpack_double (type, valaddr, &inv); |
510 | if (inv) | |
511 | fprintf_filtered (stream, "<invalid float value>"); | |
512 | else | |
513 | fprintf_filtered (stream, len <= sizeof(float) ? "%.9g" : "%.17g", doub); | |
bd5635a1 RP |
514 | } |
515 | ||
a8a69e63 | 516 | /* VALADDR points to an integer of LEN bytes. Print it in hex on stream. */ |
bd5635a1 RP |
517 | |
518 | static void | |
a8a69e63 | 519 | print_hex_chars (stream, valaddr, len) |
199b2450 | 520 | GDB_FILE *stream; |
a8a69e63 FF |
521 | unsigned char *valaddr; |
522 | unsigned len; | |
bd5635a1 | 523 | { |
a8a69e63 | 524 | unsigned char *p; |
b0f61d04 JK |
525 | |
526 | /* FIXME: We should be not printing leading zeroes in most cases. */ | |
527 | ||
528 | fprintf_filtered (stream, local_hex_format_prefix ()); | |
a8a69e63 FF |
529 | #if TARGET_BYTE_ORDER == BIG_ENDIAN |
530 | for (p = valaddr; | |
531 | p < valaddr + len; | |
532 | p++) | |
533 | #else /* Little endian. */ | |
534 | for (p = valaddr + len - 1; | |
535 | p >= valaddr; | |
536 | p--) | |
537 | #endif | |
bd5635a1 | 538 | { |
a8a69e63 | 539 | fprintf_filtered (stream, "%02x", *p); |
bd5635a1 | 540 | } |
b0f61d04 | 541 | fprintf_filtered (stream, local_hex_format_suffix ()); |
a8a69e63 | 542 | } |
bd5635a1 | 543 | |
a8a69e63 FF |
544 | /* Called by various <lang>_val_print routines to print elements of an |
545 | array in the form "<elem1>, <elem2>, <elem3>, ...". | |
4a11eef2 | 546 | |
a8a69e63 FF |
547 | (FIXME?) Assumes array element separator is a comma, which is correct |
548 | for all languages currently handled. | |
549 | (FIXME?) Some languages have a notation for repeated array elements, | |
550 | perhaps we should try to use that notation when appropriate. | |
551 | */ | |
bd5635a1 | 552 | |
a8a69e63 FF |
553 | void |
554 | val_print_array_elements (type, valaddr, address, stream, format, deref_ref, | |
555 | recurse, pretty, i) | |
556 | struct type *type; | |
557 | char *valaddr; | |
558 | CORE_ADDR address; | |
199b2450 | 559 | GDB_FILE *stream; |
a8a69e63 FF |
560 | int format; |
561 | int deref_ref; | |
562 | int recurse; | |
563 | enum val_prettyprint pretty; | |
564 | unsigned int i; | |
565 | { | |
566 | unsigned int things_printed = 0; | |
567 | unsigned len; | |
568 | struct type *elttype; | |
569 | unsigned eltlen; | |
570 | /* Position of the array element we are examining to see | |
571 | whether it is repeated. */ | |
572 | unsigned int rep1; | |
573 | /* Number of repetitions we have detected so far. */ | |
574 | unsigned int reps; | |
575 | ||
576 | elttype = TYPE_TARGET_TYPE (type); | |
577 | eltlen = TYPE_LENGTH (elttype); | |
578 | len = TYPE_LENGTH (type) / eltlen; | |
579 | ||
580 | for (; i < len && things_printed < print_max; i++) | |
bd5635a1 | 581 | { |
a8a69e63 | 582 | if (i != 0) |
bd5635a1 | 583 | { |
a8a69e63 | 584 | if (prettyprint_arrays) |
bd5635a1 | 585 | { |
a8a69e63 FF |
586 | fprintf_filtered (stream, ",\n"); |
587 | print_spaces_filtered (2 + 2 * recurse, stream); | |
bd5635a1 | 588 | } |
a8a69e63 | 589 | else |
bd5635a1 | 590 | { |
a8a69e63 | 591 | fprintf_filtered (stream, ", "); |
bd5635a1 | 592 | } |
bd5635a1 | 593 | } |
a8a69e63 FF |
594 | wrap_here (n_spaces (2 + 2 * recurse)); |
595 | ||
596 | rep1 = i + 1; | |
597 | reps = 1; | |
598 | while ((rep1 < len) && | |
599 | !memcmp (valaddr + i * eltlen, valaddr + rep1 * eltlen, eltlen)) | |
600 | { | |
601 | ++reps; | |
602 | ++rep1; | |
603 | } | |
604 | ||
605 | if (reps > repeat_count_threshold) | |
bd5635a1 | 606 | { |
a8a69e63 FF |
607 | val_print (elttype, valaddr + i * eltlen, 0, stream, format, |
608 | deref_ref, recurse + 1, pretty); | |
609 | fprintf_filtered (stream, " <repeats %u times>", reps); | |
610 | i = rep1 - 1; | |
611 | things_printed += repeat_count_threshold; | |
bd5635a1 | 612 | } |
bd5635a1 RP |
613 | else |
614 | { | |
a8a69e63 FF |
615 | val_print (elttype, valaddr + i * eltlen, 0, stream, format, |
616 | deref_ref, recurse + 1, pretty); | |
617 | things_printed++; | |
bd5635a1 | 618 | } |
a8a69e63 FF |
619 | } |
620 | if (i < len) | |
621 | { | |
622 | fprintf_filtered (stream, "..."); | |
623 | } | |
624 | } | |
e2aab031 | 625 | |
a8a69e63 FF |
626 | static void |
627 | value_print_array_elements (val, stream, format, pretty) | |
628 | value val; | |
199b2450 | 629 | GDB_FILE *stream; |
a8a69e63 FF |
630 | int format; |
631 | enum val_prettyprint pretty; | |
632 | { | |
633 | unsigned int things_printed = 0; | |
634 | register unsigned int i, n, typelen; | |
635 | /* Position of the array elem we are examining to see if it is repeated. */ | |
636 | unsigned int rep1; | |
637 | /* Number of repetitions we have detected so far. */ | |
638 | unsigned int reps; | |
639 | ||
640 | n = VALUE_REPETITIONS (val); | |
641 | typelen = TYPE_LENGTH (VALUE_TYPE (val)); | |
642 | for (i = 0; i < n && things_printed < print_max; i++) | |
643 | { | |
644 | if (i != 0) | |
645 | { | |
646 | fprintf_filtered (stream, ", "); | |
647 | } | |
648 | wrap_here (""); | |
649 | ||
650 | rep1 = i + 1; | |
651 | reps = 1; | |
652 | while (rep1 < n && !memcmp (VALUE_CONTENTS (val) + typelen * i, | |
653 | VALUE_CONTENTS (val) + typelen * rep1, | |
654 | typelen)) | |
655 | { | |
656 | ++reps; | |
657 | ++rep1; | |
658 | } | |
659 | ||
660 | if (reps > repeat_count_threshold) | |
4ace50a5 | 661 | { |
a8a69e63 FF |
662 | val_print (VALUE_TYPE (val), VALUE_CONTENTS (val) + typelen * i, |
663 | VALUE_ADDRESS (val) + typelen * i, stream, format, 1, | |
664 | 0, pretty); | |
199b2450 | 665 | fprintf_unfiltered (stream, " <repeats %u times>", reps); |
a8a69e63 FF |
666 | i = rep1 - 1; |
667 | things_printed += repeat_count_threshold; | |
4ace50a5 FF |
668 | } |
669 | else | |
670 | { | |
a8a69e63 FF |
671 | val_print (VALUE_TYPE (val), VALUE_CONTENTS (val) + typelen * i, |
672 | VALUE_ADDRESS (val) + typelen * i, stream, format, 1, | |
673 | 0, pretty); | |
674 | things_printed++; | |
4ace50a5 | 675 | } |
a8a69e63 FF |
676 | } |
677 | if (i < n) | |
678 | { | |
679 | fprintf_filtered (stream, "..."); | |
bd5635a1 RP |
680 | } |
681 | } | |
a8a69e63 | 682 | |
7efb57c3 FF |
683 | /* Print a string from the inferior, starting at ADDR and printing up to LEN |
684 | characters, to STREAM. If LEN is zero, printing stops at the first null | |
685 | byte, otherwise printing proceeds (including null bytes) until either | |
ce13daa7 | 686 | print_max or LEN characters have been printed, whichever is smaller. */ |
7efb57c3 | 687 | |
c7da3ed3 | 688 | int |
7efb57c3 | 689 | val_print_string (addr, len, stream) |
c7da3ed3 | 690 | CORE_ADDR addr; |
7efb57c3 | 691 | unsigned int len; |
199b2450 | 692 | GDB_FILE *stream; |
c7da3ed3 | 693 | { |
ce13daa7 FF |
694 | int force_ellipsis = 0; /* Force ellipsis to be printed if nonzero. */ |
695 | int errcode; /* Errno returned from bad reads. */ | |
696 | unsigned int fetchlimit; /* Maximum number of bytes to fetch. */ | |
697 | unsigned int nfetch; /* Bytes to fetch / bytes fetched. */ | |
698 | unsigned int chunksize; /* Size of each fetch, in bytes. */ | |
699 | int bufsize; /* Size of current fetch buffer. */ | |
700 | char *buffer = NULL; /* Dynamically growable fetch buffer. */ | |
701 | char *bufptr; /* Pointer to next available byte in buffer. */ | |
702 | char *limit; /* First location past end of fetch buffer. */ | |
199b2450 | 703 | struct cleanup *old_chain = NULL; /* Top of the old cleanup chain. */ |
ce13daa7 FF |
704 | char peekchar; /* Place into which we can read one char. */ |
705 | ||
706 | /* First we need to figure out the limit on the number of characters we are | |
707 | going to attempt to fetch and print. This is actually pretty simple. If | |
708 | LEN is nonzero, then the limit is the minimum of LEN and print_max. If | |
709 | LEN is zero, then the limit is print_max. This is true regardless of | |
710 | whether print_max is zero, UINT_MAX (unlimited), or something in between, | |
711 | because finding the null byte (or available memory) is what actually | |
712 | limits the fetch. */ | |
713 | ||
714 | fetchlimit = (len == 0 ? print_max : min (len, print_max)); | |
715 | ||
716 | /* Now decide how large of chunks to try to read in one operation. This | |
717 | is also pretty simple. If LEN is nonzero, then we want fetchlimit bytes, | |
718 | so we might as well read them all in one operation. If LEN is zero, we | |
719 | are looking for a null terminator to end the fetching, so we might as | |
720 | well read in blocks that are large enough to be efficient, but not so | |
721 | large as to be slow if fetchlimit happens to be large. So we choose the | |
833e0d94 JK |
722 | minimum of 8 and fetchlimit. We used to use 200 instead of 8 but |
723 | 200 is way too big for remote debugging over a serial line. */ | |
ce13daa7 | 724 | |
833e0d94 | 725 | chunksize = (len == 0 ? min (8, fetchlimit) : fetchlimit); |
ce13daa7 FF |
726 | |
727 | /* Loop until we either have all the characters to print, or we encounter | |
728 | some error, such as bumping into the end of the address space. */ | |
729 | ||
730 | bufsize = 0; | |
731 | do { | |
732 | QUIT; | |
733 | /* Figure out how much to fetch this time, and grow the buffer to fit. */ | |
734 | nfetch = min (chunksize, fetchlimit - bufsize); | |
735 | bufsize += nfetch; | |
736 | if (buffer == NULL) | |
737 | { | |
738 | buffer = (char *) xmalloc (bufsize); | |
739 | bufptr = buffer; | |
740 | } | |
741 | else | |
742 | { | |
743 | discard_cleanups (old_chain); | |
744 | buffer = (char *) xrealloc (buffer, bufsize); | |
745 | bufptr = buffer + bufsize - nfetch; | |
746 | } | |
747 | old_chain = make_cleanup (free, buffer); | |
748 | ||
749 | /* Read as much as we can. */ | |
750 | nfetch = target_read_memory_partial (addr, bufptr, nfetch, &errcode); | |
751 | if (len != 0) | |
752 | { | |
753 | addr += nfetch; | |
754 | bufptr += nfetch; | |
755 | } | |
756 | else | |
757 | { | |
758 | /* Scan this chunk for the null byte that terminates the string | |
759 | to print. If found, we don't need to fetch any more. Note | |
760 | that bufptr is explicitly left pointing at the next character | |
761 | after the null byte, or at the next character after the end of | |
762 | the buffer. */ | |
763 | limit = bufptr + nfetch; | |
764 | do { | |
765 | addr++; | |
766 | bufptr++; | |
767 | } while (bufptr < limit && *(bufptr - 1) != '\0'); | |
768 | } | |
769 | } while (errcode == 0 /* no error */ | |
833e0d94 | 770 | && bufsize < fetchlimit /* no overrun */ |
ce13daa7 FF |
771 | && !(len == 0 && *(bufptr - 1) == '\0')); /* no null term */ |
772 | ||
773 | /* We now have either successfully filled the buffer to fetchlimit, or | |
774 | terminated early due to an error or finding a null byte when LEN is | |
775 | zero. */ | |
776 | ||
777 | if (len == 0 && *(bufptr - 1) != '\0') | |
c7da3ed3 | 778 | { |
ce13daa7 FF |
779 | /* We didn't find a null terminator we were looking for. Attempt |
780 | to peek at the next character. If not successful, or it is not | |
781 | a null byte, then force ellipsis to be printed. */ | |
782 | if (target_read_memory (addr, &peekchar, 1) != 0 || peekchar != '\0') | |
7efb57c3 | 783 | { |
7efb57c3 FF |
784 | force_ellipsis = 1; |
785 | } | |
c7da3ed3 | 786 | } |
ce13daa7 FF |
787 | else if ((len != 0 && errcode != 0) || (len > bufptr - buffer)) |
788 | { | |
789 | /* Getting an error when we have a requested length, or fetching less | |
790 | than the number of characters actually requested, always make us | |
791 | print ellipsis. */ | |
792 | force_ellipsis = 1; | |
793 | } | |
794 | ||
795 | QUIT; | |
c7da3ed3 | 796 | |
ce13daa7 FF |
797 | if (addressprint) |
798 | { | |
799 | fputs_filtered (" ", stream); | |
800 | } | |
801 | LA_PRINT_STRING (stream, buffer, bufptr - buffer, force_ellipsis); | |
802 | ||
803 | if (errcode != 0 && force_ellipsis) | |
c7da3ed3 FF |
804 | { |
805 | if (errcode == EIO) | |
806 | { | |
833e0d94 JK |
807 | fprintf_filtered (stream, " <Address "); |
808 | print_address_numeric (addr, stream); | |
809 | fprintf_filtered (stream, " out of bounds>"); | |
c7da3ed3 FF |
810 | } |
811 | else | |
812 | { | |
833e0d94 | 813 | /* FIXME-32x64: assumes addr fits in a long. */ |
199b2450 TL |
814 | error ("Error reading memory address 0x%lx: %s.", |
815 | (unsigned long) addr, | |
c7da3ed3 FF |
816 | safe_strerror (errcode)); |
817 | } | |
818 | } | |
199b2450 | 819 | gdb_flush (stream); |
ce13daa7 FF |
820 | do_cleanups (old_chain); |
821 | return (bufptr - buffer); | |
c7da3ed3 | 822 | } |
ce13daa7 | 823 | |
bd5635a1 RP |
824 | \f |
825 | /* Validate an input or output radix setting, and make sure the user | |
826 | knows what they really did here. Radix setting is confusing, e.g. | |
827 | setting the input radix to "10" never changes it! */ | |
828 | ||
e1ce8aa5 | 829 | /* ARGSUSED */ |
bd5635a1 RP |
830 | static void |
831 | set_input_radix (args, from_tty, c) | |
832 | char *args; | |
833 | int from_tty; | |
834 | struct cmd_list_element *c; | |
835 | { | |
ce13daa7 FF |
836 | set_input_radix_1 (from_tty, *(unsigned *)c->var); |
837 | } | |
bd5635a1 | 838 | |
ce13daa7 FF |
839 | /* ARGSUSED */ |
840 | static void | |
841 | set_input_radix_1 (from_tty, radix) | |
842 | int from_tty; | |
843 | unsigned radix; | |
844 | { | |
845 | /* We don't currently disallow any input radix except 0 or 1, which don't | |
846 | make any mathematical sense. In theory, we can deal with any input | |
847 | radix greater than 1, even if we don't have unique digits for every | |
848 | value from 0 to radix-1, but in practice we lose on large radix values. | |
849 | We should either fix the lossage or restrict the radix range more. | |
850 | (FIXME). */ | |
851 | ||
852 | if (radix < 2) | |
853 | { | |
854 | error ("Nonsense input radix ``decimal %u''; input radix unchanged.", | |
855 | radix); | |
856 | } | |
857 | input_radix = radix; | |
bd5635a1 | 858 | if (from_tty) |
ce13daa7 FF |
859 | { |
860 | printf_filtered ("Input radix now set to decimal %u, hex %x, octal %o.\n", | |
861 | radix, radix, radix); | |
862 | } | |
bd5635a1 RP |
863 | } |
864 | ||
e1ce8aa5 | 865 | /* ARGSUSED */ |
bd5635a1 RP |
866 | static void |
867 | set_output_radix (args, from_tty, c) | |
868 | char *args; | |
869 | int from_tty; | |
870 | struct cmd_list_element *c; | |
871 | { | |
ce13daa7 FF |
872 | set_output_radix_1 (from_tty, *(unsigned *)c->var); |
873 | } | |
bd5635a1 | 874 | |
ce13daa7 FF |
875 | static void |
876 | set_output_radix_1 (from_tty, radix) | |
877 | int from_tty; | |
878 | unsigned radix; | |
879 | { | |
880 | /* Validate the radix and disallow ones that we aren't prepared to | |
881 | handle correctly, leaving the radix unchanged. */ | |
bd5635a1 RP |
882 | switch (radix) |
883 | { | |
884 | case 16: | |
ce13daa7 | 885 | output_format = 'x'; /* hex */ |
bd5635a1 RP |
886 | break; |
887 | case 10: | |
ce13daa7 | 888 | output_format = 0; /* decimal */ |
bd5635a1 RP |
889 | break; |
890 | case 8: | |
891 | output_format = 'o'; /* octal */ | |
892 | break; | |
893 | default: | |
ce13daa7 FF |
894 | error ("Unsupported output radix ``decimal %u''; output radix unchanged.", |
895 | radix); | |
896 | } | |
897 | output_radix = radix; | |
898 | if (from_tty) | |
899 | { | |
900 | printf_filtered ("Output radix now set to decimal %u, hex %x, octal %o.\n", | |
901 | radix, radix, radix); | |
bd5635a1 RP |
902 | } |
903 | } | |
904 | ||
ce13daa7 FF |
905 | /* Set both the input and output radix at once. Try to set the output radix |
906 | first, since it has the most restrictive range. An radix that is valid as | |
907 | an output radix is also valid as an input radix. | |
908 | ||
909 | It may be useful to have an unusual input radix. If the user wishes to | |
910 | set an input radix that is not valid as an output radix, he needs to use | |
911 | the 'set input-radix' command. */ | |
912 | ||
bd5635a1 | 913 | static void |
ce13daa7 | 914 | set_radix (arg, from_tty) |
bd5635a1 RP |
915 | char *arg; |
916 | int from_tty; | |
bd5635a1 | 917 | { |
ce13daa7 | 918 | unsigned radix; |
bd5635a1 | 919 | |
ce13daa7 FF |
920 | radix = (arg == NULL) ? 10 : parse_and_eval_address (arg); |
921 | set_output_radix_1 (0, radix); | |
922 | set_input_radix_1 (0, radix); | |
bd5635a1 | 923 | if (from_tty) |
ce13daa7 FF |
924 | { |
925 | printf_filtered ("Input and output radices now set to decimal %u, hex %x, octal %o.\n", | |
926 | radix, radix, radix); | |
927 | } | |
928 | } | |
bd5635a1 | 929 | |
ce13daa7 | 930 | /* Show both the input and output radices. */ |
bd5635a1 | 931 | |
ce13daa7 FF |
932 | /*ARGSUSED*/ |
933 | static void | |
934 | show_radix (arg, from_tty) | |
935 | char *arg; | |
936 | int from_tty; | |
937 | { | |
938 | if (from_tty) | |
939 | { | |
940 | if (input_radix == output_radix) | |
941 | { | |
942 | printf_filtered ("Input and output radices set to decimal %u, hex %x, octal %o.\n", | |
943 | input_radix, input_radix, input_radix); | |
944 | } | |
945 | else | |
946 | { | |
947 | printf_filtered ("Input radix set to decimal %u, hex %x, octal %o.\n", | |
948 | input_radix, input_radix, input_radix); | |
949 | printf_filtered ("Output radix set to decimal %u, hex %x, octal %o.\n", | |
950 | output_radix, output_radix, output_radix); | |
951 | } | |
952 | } | |
bd5635a1 | 953 | } |
ce13daa7 | 954 | |
bd5635a1 | 955 | \f |
f266e564 JK |
956 | /*ARGSUSED*/ |
957 | static void | |
958 | set_print (arg, from_tty) | |
959 | char *arg; | |
960 | int from_tty; | |
961 | { | |
199b2450 | 962 | printf_unfiltered ( |
f266e564 | 963 | "\"set print\" must be followed by the name of a print subcommand.\n"); |
199b2450 | 964 | help_list (setprintlist, "set print ", -1, gdb_stdout); |
f266e564 JK |
965 | } |
966 | ||
967 | /*ARGSUSED*/ | |
968 | static void | |
969 | show_print (args, from_tty) | |
970 | char *args; | |
971 | int from_tty; | |
972 | { | |
973 | cmd_show_list (showprintlist, from_tty, ""); | |
974 | } | |
975 | \f | |
bd5635a1 RP |
976 | void |
977 | _initialize_valprint () | |
978 | { | |
979 | struct cmd_list_element *c; | |
980 | ||
f266e564 JK |
981 | add_prefix_cmd ("print", no_class, set_print, |
982 | "Generic command for setting how things print.", | |
983 | &setprintlist, "set print ", 0, &setlist); | |
36b9d39c | 984 | add_alias_cmd ("p", "print", no_class, 1, &setlist); |
199b2450 TL |
985 | /* prefer set print to set prompt */ |
986 | add_alias_cmd ("pr", "print", no_class, 1, &setlist); | |
987 | ||
f266e564 JK |
988 | add_prefix_cmd ("print", no_class, show_print, |
989 | "Generic command for showing print settings.", | |
990 | &showprintlist, "show print ", 0, &showlist); | |
36b9d39c JG |
991 | add_alias_cmd ("p", "print", no_class, 1, &showlist); |
992 | add_alias_cmd ("pr", "print", no_class, 1, &showlist); | |
f266e564 | 993 | |
bd5635a1 | 994 | add_show_from_set |
f266e564 | 995 | (add_set_cmd ("elements", no_class, var_uinteger, (char *)&print_max, |
bd5635a1 | 996 | "Set limit on string chars or array elements to print.\n\ |
f266e564 JK |
997 | \"set print elements 0\" causes there to be no limit.", |
998 | &setprintlist), | |
999 | &showprintlist); | |
bd5635a1 | 1000 | |
85f0a848 FF |
1001 | add_show_from_set |
1002 | (add_set_cmd ("repeats", no_class, var_uinteger, | |
1003 | (char *)&repeat_count_threshold, | |
1004 | "Set threshold for repeated print elements.\n\ | |
1005 | \"set print repeats 0\" causes all elements to be individually printed.", | |
1006 | &setprintlist), | |
1007 | &showprintlist); | |
1008 | ||
bd5635a1 | 1009 | add_show_from_set |
a8a69e63 FF |
1010 | (add_set_cmd ("pretty", class_support, var_boolean, |
1011 | (char *)&prettyprint_structs, | |
bd5635a1 | 1012 | "Set prettyprinting of structures.", |
f266e564 JK |
1013 | &setprintlist), |
1014 | &showprintlist); | |
bd5635a1 RP |
1015 | |
1016 | add_show_from_set | |
f266e564 | 1017 | (add_set_cmd ("union", class_support, var_boolean, (char *)&unionprint, |
bd5635a1 | 1018 | "Set printing of unions interior to structures.", |
f266e564 JK |
1019 | &setprintlist), |
1020 | &showprintlist); | |
bd5635a1 RP |
1021 | |
1022 | add_show_from_set | |
a8a69e63 FF |
1023 | (add_set_cmd ("array", class_support, var_boolean, |
1024 | (char *)&prettyprint_arrays, | |
bd5635a1 | 1025 | "Set prettyprinting of arrays.", |
f266e564 JK |
1026 | &setprintlist), |
1027 | &showprintlist); | |
bd5635a1 RP |
1028 | |
1029 | add_show_from_set | |
f266e564 | 1030 | (add_set_cmd ("address", class_support, var_boolean, (char *)&addressprint, |
bd5635a1 | 1031 | "Set printing of addresses.", |
f266e564 JK |
1032 | &setprintlist), |
1033 | &showprintlist); | |
bd5635a1 | 1034 | |
bd5635a1 RP |
1035 | c = add_set_cmd ("input-radix", class_support, var_uinteger, |
1036 | (char *)&input_radix, | |
1037 | "Set default input radix for entering numbers.", | |
1038 | &setlist); | |
1039 | add_show_from_set (c, &showlist); | |
199b2450 | 1040 | c->function.sfunc = set_input_radix; |
bd5635a1 RP |
1041 | |
1042 | c = add_set_cmd ("output-radix", class_support, var_uinteger, | |
1043 | (char *)&output_radix, | |
1044 | "Set default output radix for printing of values.", | |
1045 | &setlist); | |
1046 | add_show_from_set (c, &showlist); | |
199b2450 | 1047 | c->function.sfunc = set_output_radix; |
bd5635a1 | 1048 | |
ce13daa7 FF |
1049 | /* The "set radix" and "show radix" commands are special in that they are |
1050 | like normal set and show commands but allow two normally independent | |
1051 | variables to be either set or shown with a single command. So the | |
1052 | usual add_set_cmd() and add_show_from_set() commands aren't really | |
1053 | appropriate. */ | |
1054 | add_cmd ("radix", class_support, set_radix, | |
1055 | "Set default input and output number radices.\n\ | |
1056 | Use 'set input-radix' or 'set output-radix' to independently set each.\n\ | |
1057 | Without an argument, sets both radices back to the default value of 10.", | |
1058 | &setlist); | |
1059 | add_cmd ("radix", class_support, show_radix, | |
1060 | "Show the default input and output number radices.\n\ | |
1061 | Use 'show input-radix' or 'show output-radix' to independently show each.", | |
1062 | &showlist); | |
bd5635a1 RP |
1063 | |
1064 | /* Give people the defaults which they are used to. */ | |
a8a69e63 FF |
1065 | prettyprint_structs = 0; |
1066 | prettyprint_arrays = 0; | |
bd5635a1 | 1067 | unionprint = 1; |
bd5635a1 | 1068 | addressprint = 1; |
ce13daa7 | 1069 | print_max = PRINT_MAX_DEFAULT; |
bd5635a1 | 1070 | } |