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