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