Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Print values for GDB, the GNU debugger. |
5c1c87f0 | 2 | |
c5a57081 | 3 | Copyright (C) 1986, 1988-2012 Free Software Foundation, Inc. |
c906108c | 4 | |
c5aa993b | 5 | This file is part of GDB. |
c906108c | 6 | |
c5aa993b JM |
7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 9 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 10 | (at your option) any later version. |
c906108c | 11 | |
c5aa993b JM |
12 | This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
c906108c | 16 | |
c5aa993b | 17 | You should have received a copy of the GNU General Public License |
a9762ec7 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
19 | |
20 | #include "defs.h" | |
21 | #include "gdb_string.h" | |
22 | #include "symtab.h" | |
23 | #include "gdbtypes.h" | |
24 | #include "value.h" | |
25 | #include "gdbcore.h" | |
26 | #include "gdbcmd.h" | |
27 | #include "target.h" | |
c906108c | 28 | #include "language.h" |
c906108c SS |
29 | #include "annotate.h" |
30 | #include "valprint.h" | |
39424bef | 31 | #include "floatformat.h" |
d16aafd8 | 32 | #include "doublest.h" |
19ca80ba | 33 | #include "exceptions.h" |
7678ef8f | 34 | #include "dfp.h" |
a6bac58e | 35 | #include "python/python.h" |
0c3acc09 | 36 | #include "ada-lang.h" |
3b2b8fea TT |
37 | #include "gdb_obstack.h" |
38 | #include "charset.h" | |
39 | #include <ctype.h> | |
c906108c SS |
40 | |
41 | #include <errno.h> | |
42 | ||
43 | /* Prototypes for local functions */ | |
44 | ||
777ea8f1 | 45 | static int partial_memory_read (CORE_ADDR memaddr, gdb_byte *myaddr, |
917317f4 JM |
46 | int len, int *errnoptr); |
47 | ||
a14ed312 | 48 | static void show_print (char *, int); |
c906108c | 49 | |
a14ed312 | 50 | static void set_print (char *, int); |
c906108c | 51 | |
a14ed312 | 52 | static void set_radix (char *, int); |
c906108c | 53 | |
a14ed312 | 54 | static void show_radix (char *, int); |
c906108c | 55 | |
a14ed312 | 56 | static void set_input_radix (char *, int, struct cmd_list_element *); |
c906108c | 57 | |
a14ed312 | 58 | static void set_input_radix_1 (int, unsigned); |
c906108c | 59 | |
a14ed312 | 60 | static void set_output_radix (char *, int, struct cmd_list_element *); |
c906108c | 61 | |
a14ed312 | 62 | static void set_output_radix_1 (int, unsigned); |
c906108c | 63 | |
a14ed312 | 64 | void _initialize_valprint (void); |
c906108c | 65 | |
581e13c1 | 66 | #define PRINT_MAX_DEFAULT 200 /* Start print_max off at this value. */ |
79a45b7d TT |
67 | |
68 | struct value_print_options user_print_options = | |
69 | { | |
70 | Val_pretty_default, /* pretty */ | |
71 | 0, /* prettyprint_arrays */ | |
72 | 0, /* prettyprint_structs */ | |
73 | 0, /* vtblprint */ | |
74 | 1, /* unionprint */ | |
75 | 1, /* addressprint */ | |
76 | 0, /* objectprint */ | |
77 | PRINT_MAX_DEFAULT, /* print_max */ | |
78 | 10, /* repeat_count_threshold */ | |
79 | 0, /* output_format */ | |
80 | 0, /* format */ | |
81 | 0, /* stop_print_at_null */ | |
82 | 0, /* inspect_it */ | |
83 | 0, /* print_array_indexes */ | |
84 | 0, /* deref_ref */ | |
85 | 1, /* static_field_print */ | |
a6bac58e TT |
86 | 1, /* pascal_static_field_print */ |
87 | 0, /* raw */ | |
88 | 0 /* summary */ | |
79a45b7d TT |
89 | }; |
90 | ||
91 | /* Initialize *OPTS to be a copy of the user print options. */ | |
92 | void | |
93 | get_user_print_options (struct value_print_options *opts) | |
94 | { | |
95 | *opts = user_print_options; | |
96 | } | |
97 | ||
98 | /* Initialize *OPTS to be a copy of the user print options, but with | |
99 | pretty-printing disabled. */ | |
100 | void | |
101 | get_raw_print_options (struct value_print_options *opts) | |
102 | { | |
103 | *opts = user_print_options; | |
104 | opts->pretty = Val_no_prettyprint; | |
105 | } | |
106 | ||
107 | /* Initialize *OPTS to be a copy of the user print options, but using | |
108 | FORMAT as the formatting option. */ | |
109 | void | |
110 | get_formatted_print_options (struct value_print_options *opts, | |
111 | char format) | |
112 | { | |
113 | *opts = user_print_options; | |
114 | opts->format = format; | |
115 | } | |
116 | ||
920d2a44 AC |
117 | static void |
118 | show_print_max (struct ui_file *file, int from_tty, | |
119 | struct cmd_list_element *c, const char *value) | |
120 | { | |
3e43a32a MS |
121 | fprintf_filtered (file, |
122 | _("Limit on string chars or array " | |
123 | "elements to print is %s.\n"), | |
920d2a44 AC |
124 | value); |
125 | } | |
126 | ||
c906108c SS |
127 | |
128 | /* Default input and output radixes, and output format letter. */ | |
129 | ||
130 | unsigned input_radix = 10; | |
920d2a44 AC |
131 | static void |
132 | show_input_radix (struct ui_file *file, int from_tty, | |
133 | struct cmd_list_element *c, const char *value) | |
134 | { | |
3e43a32a MS |
135 | fprintf_filtered (file, |
136 | _("Default input radix for entering numbers is %s.\n"), | |
920d2a44 AC |
137 | value); |
138 | } | |
139 | ||
c906108c | 140 | unsigned output_radix = 10; |
920d2a44 AC |
141 | static void |
142 | show_output_radix (struct ui_file *file, int from_tty, | |
143 | struct cmd_list_element *c, const char *value) | |
144 | { | |
3e43a32a MS |
145 | fprintf_filtered (file, |
146 | _("Default output radix for printing of values is %s.\n"), | |
920d2a44 AC |
147 | value); |
148 | } | |
c906108c | 149 | |
e79af960 JB |
150 | /* By default we print arrays without printing the index of each element in |
151 | the array. This behavior can be changed by setting PRINT_ARRAY_INDEXES. */ | |
152 | ||
e79af960 JB |
153 | static void |
154 | show_print_array_indexes (struct ui_file *file, int from_tty, | |
155 | struct cmd_list_element *c, const char *value) | |
156 | { | |
157 | fprintf_filtered (file, _("Printing of array indexes is %s.\n"), value); | |
158 | } | |
159 | ||
c906108c SS |
160 | /* Print repeat counts if there are more than this many repetitions of an |
161 | element in an array. Referenced by the low level language dependent | |
581e13c1 | 162 | print routines. */ |
c906108c | 163 | |
920d2a44 AC |
164 | static void |
165 | show_repeat_count_threshold (struct ui_file *file, int from_tty, | |
166 | struct cmd_list_element *c, const char *value) | |
167 | { | |
168 | fprintf_filtered (file, _("Threshold for repeated print elements is %s.\n"), | |
169 | value); | |
170 | } | |
c906108c | 171 | |
581e13c1 | 172 | /* If nonzero, stops printing of char arrays at first null. */ |
c906108c | 173 | |
920d2a44 AC |
174 | static void |
175 | show_stop_print_at_null (struct ui_file *file, int from_tty, | |
176 | struct cmd_list_element *c, const char *value) | |
177 | { | |
3e43a32a MS |
178 | fprintf_filtered (file, |
179 | _("Printing of char arrays to stop " | |
180 | "at first null char is %s.\n"), | |
920d2a44 AC |
181 | value); |
182 | } | |
c906108c | 183 | |
581e13c1 | 184 | /* Controls pretty printing of structures. */ |
c906108c | 185 | |
920d2a44 AC |
186 | static void |
187 | show_prettyprint_structs (struct ui_file *file, int from_tty, | |
188 | struct cmd_list_element *c, const char *value) | |
189 | { | |
190 | fprintf_filtered (file, _("Prettyprinting of structures is %s.\n"), value); | |
191 | } | |
c906108c SS |
192 | |
193 | /* Controls pretty printing of arrays. */ | |
194 | ||
920d2a44 AC |
195 | static void |
196 | show_prettyprint_arrays (struct ui_file *file, int from_tty, | |
197 | struct cmd_list_element *c, const char *value) | |
198 | { | |
199 | fprintf_filtered (file, _("Prettyprinting of arrays is %s.\n"), value); | |
200 | } | |
c906108c SS |
201 | |
202 | /* If nonzero, causes unions inside structures or other unions to be | |
581e13c1 | 203 | printed. */ |
c906108c | 204 | |
920d2a44 AC |
205 | static void |
206 | show_unionprint (struct ui_file *file, int from_tty, | |
207 | struct cmd_list_element *c, const char *value) | |
208 | { | |
3e43a32a MS |
209 | fprintf_filtered (file, |
210 | _("Printing of unions interior to structures is %s.\n"), | |
920d2a44 AC |
211 | value); |
212 | } | |
c906108c | 213 | |
581e13c1 | 214 | /* If nonzero, causes machine addresses to be printed in certain contexts. */ |
c906108c | 215 | |
920d2a44 AC |
216 | static void |
217 | show_addressprint (struct ui_file *file, int from_tty, | |
218 | struct cmd_list_element *c, const char *value) | |
219 | { | |
220 | fprintf_filtered (file, _("Printing of addresses is %s.\n"), value); | |
221 | } | |
c906108c | 222 | \f |
c5aa993b | 223 | |
a6bac58e TT |
224 | /* A helper function for val_print. When printing in "summary" mode, |
225 | we want to print scalar arguments, but not aggregate arguments. | |
226 | This function distinguishes between the two. */ | |
227 | ||
228 | static int | |
229 | scalar_type_p (struct type *type) | |
230 | { | |
231 | CHECK_TYPEDEF (type); | |
232 | while (TYPE_CODE (type) == TYPE_CODE_REF) | |
233 | { | |
234 | type = TYPE_TARGET_TYPE (type); | |
235 | CHECK_TYPEDEF (type); | |
236 | } | |
237 | switch (TYPE_CODE (type)) | |
238 | { | |
239 | case TYPE_CODE_ARRAY: | |
240 | case TYPE_CODE_STRUCT: | |
241 | case TYPE_CODE_UNION: | |
242 | case TYPE_CODE_SET: | |
243 | case TYPE_CODE_STRING: | |
244 | case TYPE_CODE_BITSTRING: | |
245 | return 0; | |
246 | default: | |
247 | return 1; | |
248 | } | |
249 | } | |
250 | ||
a72c8f6a | 251 | /* See its definition in value.h. */ |
0e03807e | 252 | |
a72c8f6a | 253 | int |
0e03807e TT |
254 | valprint_check_validity (struct ui_file *stream, |
255 | struct type *type, | |
4e07d55f | 256 | int embedded_offset, |
0e03807e TT |
257 | const struct value *val) |
258 | { | |
259 | CHECK_TYPEDEF (type); | |
260 | ||
261 | if (TYPE_CODE (type) != TYPE_CODE_UNION | |
262 | && TYPE_CODE (type) != TYPE_CODE_STRUCT | |
263 | && TYPE_CODE (type) != TYPE_CODE_ARRAY) | |
264 | { | |
4e07d55f PA |
265 | if (!value_bits_valid (val, TARGET_CHAR_BIT * embedded_offset, |
266 | TARGET_CHAR_BIT * TYPE_LENGTH (type))) | |
0e03807e | 267 | { |
585fdaa1 | 268 | val_print_optimized_out (stream); |
0e03807e TT |
269 | return 0; |
270 | } | |
8cf6f0b1 | 271 | |
4e07d55f | 272 | if (value_bits_synthetic_pointer (val, TARGET_CHAR_BIT * embedded_offset, |
8cf6f0b1 TT |
273 | TARGET_CHAR_BIT * TYPE_LENGTH (type))) |
274 | { | |
275 | fputs_filtered (_("<synthetic pointer>"), stream); | |
276 | return 0; | |
277 | } | |
4e07d55f PA |
278 | |
279 | if (!value_bytes_available (val, embedded_offset, TYPE_LENGTH (type))) | |
280 | { | |
281 | val_print_unavailable (stream); | |
282 | return 0; | |
283 | } | |
0e03807e TT |
284 | } |
285 | ||
286 | return 1; | |
287 | } | |
288 | ||
585fdaa1 PA |
289 | void |
290 | val_print_optimized_out (struct ui_file *stream) | |
291 | { | |
292 | fprintf_filtered (stream, _("<optimized out>")); | |
293 | } | |
294 | ||
4e07d55f PA |
295 | void |
296 | val_print_unavailable (struct ui_file *stream) | |
297 | { | |
298 | fprintf_filtered (stream, _("<unavailable>")); | |
299 | } | |
300 | ||
8af8e3bc PA |
301 | void |
302 | val_print_invalid_address (struct ui_file *stream) | |
303 | { | |
304 | fprintf_filtered (stream, _("<invalid address>")); | |
305 | } | |
306 | ||
e88acd96 TT |
307 | /* A generic val_print that is suitable for use by language |
308 | implementations of the la_val_print method. This function can | |
309 | handle most type codes, though not all, notably exception | |
310 | TYPE_CODE_UNION and TYPE_CODE_STRUCT, which must be implemented by | |
311 | the caller. | |
312 | ||
313 | Most arguments are as to val_print. | |
314 | ||
315 | The additional DECORATIONS argument can be used to customize the | |
316 | output in some small, language-specific ways. */ | |
317 | ||
318 | void | |
319 | generic_val_print (struct type *type, const gdb_byte *valaddr, | |
320 | int embedded_offset, CORE_ADDR address, | |
321 | struct ui_file *stream, int recurse, | |
322 | const struct value *original_value, | |
323 | const struct value_print_options *options, | |
324 | const struct generic_val_print_decorations *decorations) | |
325 | { | |
326 | struct gdbarch *gdbarch = get_type_arch (type); | |
327 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); | |
328 | unsigned int i = 0; /* Number of characters printed. */ | |
329 | unsigned len; | |
330 | struct type *elttype, *unresolved_elttype; | |
331 | struct type *unresolved_type = type; | |
332 | unsigned eltlen; | |
333 | LONGEST val; | |
334 | CORE_ADDR addr; | |
335 | ||
336 | CHECK_TYPEDEF (type); | |
337 | switch (TYPE_CODE (type)) | |
338 | { | |
339 | case TYPE_CODE_ARRAY: | |
340 | unresolved_elttype = TYPE_TARGET_TYPE (type); | |
341 | elttype = check_typedef (unresolved_elttype); | |
342 | if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (unresolved_elttype) > 0) | |
343 | { | |
344 | LONGEST low_bound, high_bound; | |
345 | ||
346 | if (!get_array_bounds (type, &low_bound, &high_bound)) | |
347 | error (_("Could not determine the array high bound")); | |
348 | ||
349 | if (options->prettyprint_arrays) | |
350 | { | |
351 | print_spaces_filtered (2 + 2 * recurse, stream); | |
352 | } | |
353 | ||
354 | fprintf_filtered (stream, "{"); | |
355 | val_print_array_elements (type, valaddr, embedded_offset, | |
356 | address, stream, | |
357 | recurse, original_value, options, 0); | |
358 | fprintf_filtered (stream, "}"); | |
359 | break; | |
360 | } | |
361 | /* Array of unspecified length: treat like pointer to first | |
362 | elt. */ | |
363 | addr = address + embedded_offset; | |
364 | goto print_unpacked_pointer; | |
365 | ||
366 | case TYPE_CODE_MEMBERPTR: | |
367 | val_print_scalar_formatted (type, valaddr, embedded_offset, | |
368 | original_value, options, 0, stream); | |
369 | break; | |
370 | ||
371 | case TYPE_CODE_PTR: | |
372 | if (options->format && options->format != 's') | |
373 | { | |
374 | val_print_scalar_formatted (type, valaddr, embedded_offset, | |
375 | original_value, options, 0, stream); | |
376 | break; | |
377 | } | |
378 | unresolved_elttype = TYPE_TARGET_TYPE (type); | |
379 | elttype = check_typedef (unresolved_elttype); | |
380 | { | |
381 | addr = unpack_pointer (type, valaddr + embedded_offset); | |
382 | print_unpacked_pointer: | |
383 | ||
384 | if (TYPE_CODE (elttype) == TYPE_CODE_FUNC) | |
385 | { | |
386 | /* Try to print what function it points to. */ | |
387 | print_function_pointer_address (gdbarch, addr, stream, | |
388 | options->addressprint); | |
389 | return; | |
390 | } | |
391 | ||
392 | if (options->addressprint) | |
393 | fputs_filtered (paddress (gdbarch, addr), stream); | |
394 | } | |
395 | break; | |
396 | ||
397 | case TYPE_CODE_REF: | |
398 | elttype = check_typedef (TYPE_TARGET_TYPE (type)); | |
399 | if (options->addressprint) | |
400 | { | |
401 | CORE_ADDR addr | |
402 | = extract_typed_address (valaddr + embedded_offset, type); | |
403 | ||
404 | fprintf_filtered (stream, "@"); | |
405 | fputs_filtered (paddress (gdbarch, addr), stream); | |
406 | if (options->deref_ref) | |
407 | fputs_filtered (": ", stream); | |
408 | } | |
409 | /* De-reference the reference. */ | |
410 | if (options->deref_ref) | |
411 | { | |
412 | if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF) | |
413 | { | |
414 | struct value *deref_val; | |
415 | ||
416 | deref_val = coerce_ref_if_computed (original_value); | |
417 | if (deref_val != NULL) | |
418 | { | |
419 | /* More complicated computed references are not supported. */ | |
420 | gdb_assert (embedded_offset == 0); | |
421 | } | |
422 | else | |
423 | deref_val = value_at (TYPE_TARGET_TYPE (type), | |
424 | unpack_pointer (type, | |
425 | (valaddr | |
426 | + embedded_offset))); | |
427 | ||
428 | common_val_print (deref_val, stream, recurse, options, | |
429 | current_language); | |
430 | } | |
431 | else | |
432 | fputs_filtered ("???", stream); | |
433 | } | |
434 | break; | |
435 | ||
436 | case TYPE_CODE_ENUM: | |
437 | if (options->format) | |
438 | { | |
439 | val_print_scalar_formatted (type, valaddr, embedded_offset, | |
440 | original_value, options, 0, stream); | |
441 | break; | |
442 | } | |
443 | len = TYPE_NFIELDS (type); | |
444 | val = unpack_long (type, valaddr + embedded_offset); | |
445 | for (i = 0; i < len; i++) | |
446 | { | |
447 | QUIT; | |
14e75d8e | 448 | if (val == TYPE_FIELD_ENUMVAL (type, i)) |
e88acd96 TT |
449 | { |
450 | break; | |
451 | } | |
452 | } | |
453 | if (i < len) | |
454 | { | |
455 | fputs_filtered (TYPE_FIELD_NAME (type, i), stream); | |
456 | } | |
457 | else if (TYPE_FLAG_ENUM (type)) | |
458 | { | |
459 | int first = 1; | |
460 | ||
461 | /* We have a "flag" enum, so we try to decompose it into | |
462 | pieces as appropriate. A flag enum has disjoint | |
463 | constants by definition. */ | |
464 | fputs_filtered ("(", stream); | |
465 | for (i = 0; i < len; ++i) | |
466 | { | |
467 | QUIT; | |
468 | ||
14e75d8e | 469 | if ((val & TYPE_FIELD_ENUMVAL (type, i)) != 0) |
e88acd96 TT |
470 | { |
471 | if (!first) | |
472 | fputs_filtered (" | ", stream); | |
473 | first = 0; | |
474 | ||
14e75d8e | 475 | val &= ~TYPE_FIELD_ENUMVAL (type, i); |
e88acd96 TT |
476 | fputs_filtered (TYPE_FIELD_NAME (type, i), stream); |
477 | } | |
478 | } | |
479 | ||
480 | if (first || val != 0) | |
481 | { | |
482 | if (!first) | |
483 | fputs_filtered (" | ", stream); | |
484 | fputs_filtered ("unknown: ", stream); | |
485 | print_longest (stream, 'd', 0, val); | |
486 | } | |
487 | ||
488 | fputs_filtered (")", stream); | |
489 | } | |
490 | else | |
491 | print_longest (stream, 'd', 0, val); | |
492 | break; | |
493 | ||
494 | case TYPE_CODE_FLAGS: | |
495 | if (options->format) | |
496 | val_print_scalar_formatted (type, valaddr, embedded_offset, | |
497 | original_value, options, 0, stream); | |
498 | else | |
499 | val_print_type_code_flags (type, valaddr + embedded_offset, | |
500 | stream); | |
501 | break; | |
502 | ||
503 | case TYPE_CODE_FUNC: | |
504 | case TYPE_CODE_METHOD: | |
505 | if (options->format) | |
506 | { | |
507 | val_print_scalar_formatted (type, valaddr, embedded_offset, | |
508 | original_value, options, 0, stream); | |
509 | break; | |
510 | } | |
511 | /* FIXME, we should consider, at least for ANSI C language, | |
512 | eliminating the distinction made between FUNCs and POINTERs | |
513 | to FUNCs. */ | |
514 | fprintf_filtered (stream, "{"); | |
515 | type_print (type, "", stream, -1); | |
516 | fprintf_filtered (stream, "} "); | |
517 | /* Try to print what function it points to, and its address. */ | |
518 | print_address_demangle (gdbarch, address, stream, demangle); | |
519 | break; | |
520 | ||
521 | case TYPE_CODE_BOOL: | |
522 | if (options->format || options->output_format) | |
523 | { | |
524 | struct value_print_options opts = *options; | |
525 | opts.format = (options->format ? options->format | |
526 | : options->output_format); | |
527 | val_print_scalar_formatted (type, valaddr, embedded_offset, | |
528 | original_value, &opts, 0, stream); | |
529 | } | |
530 | else | |
531 | { | |
532 | val = unpack_long (type, valaddr + embedded_offset); | |
533 | if (val == 0) | |
534 | fputs_filtered (decorations->false_name, stream); | |
535 | else if (val == 1) | |
536 | fputs_filtered (decorations->true_name, stream); | |
537 | else | |
538 | print_longest (stream, 'd', 0, val); | |
539 | } | |
540 | break; | |
541 | ||
542 | case TYPE_CODE_RANGE: | |
543 | /* FIXME: create_range_type does not set the unsigned bit in a | |
544 | range type (I think it probably should copy it from the | |
545 | target type), so we won't print values which are too large to | |
546 | fit in a signed integer correctly. */ | |
547 | /* FIXME: Doesn't handle ranges of enums correctly. (Can't just | |
548 | print with the target type, though, because the size of our | |
549 | type and the target type might differ). */ | |
550 | ||
551 | /* FALLTHROUGH */ | |
552 | ||
553 | case TYPE_CODE_INT: | |
554 | if (options->format || options->output_format) | |
555 | { | |
556 | struct value_print_options opts = *options; | |
557 | ||
558 | opts.format = (options->format ? options->format | |
559 | : options->output_format); | |
560 | val_print_scalar_formatted (type, valaddr, embedded_offset, | |
561 | original_value, &opts, 0, stream); | |
562 | } | |
563 | else | |
564 | val_print_type_code_int (type, valaddr + embedded_offset, stream); | |
565 | break; | |
566 | ||
567 | case TYPE_CODE_CHAR: | |
568 | if (options->format || options->output_format) | |
569 | { | |
570 | struct value_print_options opts = *options; | |
571 | ||
572 | opts.format = (options->format ? options->format | |
573 | : options->output_format); | |
574 | val_print_scalar_formatted (type, valaddr, embedded_offset, | |
575 | original_value, &opts, 0, stream); | |
576 | } | |
577 | else | |
578 | { | |
579 | val = unpack_long (type, valaddr + embedded_offset); | |
580 | if (TYPE_UNSIGNED (type)) | |
581 | fprintf_filtered (stream, "%u", (unsigned int) val); | |
582 | else | |
583 | fprintf_filtered (stream, "%d", (int) val); | |
584 | fputs_filtered (" ", stream); | |
585 | LA_PRINT_CHAR (val, unresolved_type, stream); | |
586 | } | |
587 | break; | |
588 | ||
589 | case TYPE_CODE_FLT: | |
590 | if (options->format) | |
591 | { | |
592 | val_print_scalar_formatted (type, valaddr, embedded_offset, | |
593 | original_value, options, 0, stream); | |
594 | } | |
595 | else | |
596 | { | |
597 | print_floating (valaddr + embedded_offset, type, stream); | |
598 | } | |
599 | break; | |
600 | ||
601 | case TYPE_CODE_DECFLOAT: | |
602 | if (options->format) | |
603 | val_print_scalar_formatted (type, valaddr, embedded_offset, | |
604 | original_value, options, 0, stream); | |
605 | else | |
606 | print_decimal_floating (valaddr + embedded_offset, | |
607 | type, stream); | |
608 | break; | |
609 | ||
610 | case TYPE_CODE_VOID: | |
611 | fputs_filtered (decorations->void_name, stream); | |
612 | break; | |
613 | ||
614 | case TYPE_CODE_ERROR: | |
615 | fprintf_filtered (stream, "%s", TYPE_ERROR_NAME (type)); | |
616 | break; | |
617 | ||
618 | case TYPE_CODE_UNDEF: | |
619 | /* This happens (without TYPE_FLAG_STUB set) on systems which | |
620 | don't use dbx xrefs (NO_DBX_XREFS in gcc) if a file has a | |
621 | "struct foo *bar" and no complete type for struct foo in that | |
622 | file. */ | |
623 | fprintf_filtered (stream, _("<incomplete type>")); | |
624 | break; | |
625 | ||
626 | case TYPE_CODE_COMPLEX: | |
627 | fprintf_filtered (stream, "%s", decorations->complex_prefix); | |
628 | if (options->format) | |
629 | val_print_scalar_formatted (TYPE_TARGET_TYPE (type), | |
630 | valaddr, embedded_offset, | |
631 | original_value, options, 0, stream); | |
632 | else | |
633 | print_floating (valaddr + embedded_offset, | |
634 | TYPE_TARGET_TYPE (type), | |
635 | stream); | |
636 | fprintf_filtered (stream, "%s", decorations->complex_infix); | |
637 | if (options->format) | |
638 | val_print_scalar_formatted (TYPE_TARGET_TYPE (type), | |
639 | valaddr, | |
640 | embedded_offset | |
641 | + TYPE_LENGTH (TYPE_TARGET_TYPE (type)), | |
642 | original_value, | |
643 | options, 0, stream); | |
644 | else | |
645 | print_floating (valaddr + embedded_offset | |
646 | + TYPE_LENGTH (TYPE_TARGET_TYPE (type)), | |
647 | TYPE_TARGET_TYPE (type), | |
648 | stream); | |
649 | fprintf_filtered (stream, "%s", decorations->complex_suffix); | |
650 | break; | |
651 | ||
652 | case TYPE_CODE_UNION: | |
653 | case TYPE_CODE_STRUCT: | |
654 | case TYPE_CODE_METHODPTR: | |
655 | default: | |
656 | error (_("Unhandled type code %d in symbol table."), | |
657 | TYPE_CODE (type)); | |
658 | } | |
659 | gdb_flush (stream); | |
660 | } | |
661 | ||
32b72a42 PA |
662 | /* Print using the given LANGUAGE the data of type TYPE located at |
663 | VALADDR + EMBEDDED_OFFSET (within GDB), which came from the | |
664 | inferior at address ADDRESS + EMBEDDED_OFFSET, onto stdio stream | |
665 | STREAM according to OPTIONS. VAL is the whole object that came | |
666 | from ADDRESS. VALADDR must point to the head of VAL's contents | |
667 | buffer. | |
668 | ||
669 | The language printers will pass down an adjusted EMBEDDED_OFFSET to | |
670 | further helper subroutines as subfields of TYPE are printed. In | |
671 | such cases, VALADDR is passed down unadjusted, as well as VAL, so | |
672 | that VAL can be queried for metadata about the contents data being | |
673 | printed, using EMBEDDED_OFFSET as an offset into VAL's contents | |
674 | buffer. For example: "has this field been optimized out", or "I'm | |
675 | printing an object while inspecting a traceframe; has this | |
676 | particular piece of data been collected?". | |
677 | ||
678 | RECURSE indicates the amount of indentation to supply before | |
679 | continuation lines; this amount is roughly twice the value of | |
35c0084b | 680 | RECURSE. */ |
32b72a42 | 681 | |
35c0084b | 682 | void |
fc1a4b47 | 683 | val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, |
79a45b7d | 684 | CORE_ADDR address, struct ui_file *stream, int recurse, |
0e03807e | 685 | const struct value *val, |
79a45b7d | 686 | const struct value_print_options *options, |
d8ca156b | 687 | const struct language_defn *language) |
c906108c | 688 | { |
19ca80ba DJ |
689 | volatile struct gdb_exception except; |
690 | int ret = 0; | |
79a45b7d | 691 | struct value_print_options local_opts = *options; |
c906108c | 692 | struct type *real_type = check_typedef (type); |
79a45b7d TT |
693 | |
694 | if (local_opts.pretty == Val_pretty_default) | |
695 | local_opts.pretty = (local_opts.prettyprint_structs | |
696 | ? Val_prettyprint : Val_no_prettyprint); | |
c5aa993b | 697 | |
c906108c SS |
698 | QUIT; |
699 | ||
700 | /* Ensure that the type is complete and not just a stub. If the type is | |
701 | only a stub and we can't find and substitute its complete type, then | |
702 | print appropriate string and return. */ | |
703 | ||
74a9bb82 | 704 | if (TYPE_STUB (real_type)) |
c906108c | 705 | { |
0e03807e | 706 | fprintf_filtered (stream, _("<incomplete type>")); |
c906108c | 707 | gdb_flush (stream); |
35c0084b | 708 | return; |
c906108c | 709 | } |
c5aa993b | 710 | |
0e03807e | 711 | if (!valprint_check_validity (stream, real_type, embedded_offset, val)) |
35c0084b | 712 | return; |
0e03807e | 713 | |
a6bac58e TT |
714 | if (!options->raw) |
715 | { | |
716 | ret = apply_val_pretty_printer (type, valaddr, embedded_offset, | |
0e03807e TT |
717 | address, stream, recurse, |
718 | val, options, language); | |
a6bac58e | 719 | if (ret) |
35c0084b | 720 | return; |
a6bac58e TT |
721 | } |
722 | ||
723 | /* Handle summary mode. If the value is a scalar, print it; | |
724 | otherwise, print an ellipsis. */ | |
725 | if (options->summary && !scalar_type_p (type)) | |
726 | { | |
727 | fprintf_filtered (stream, "..."); | |
35c0084b | 728 | return; |
a6bac58e TT |
729 | } |
730 | ||
19ca80ba DJ |
731 | TRY_CATCH (except, RETURN_MASK_ERROR) |
732 | { | |
d3eab38a TT |
733 | language->la_val_print (type, valaddr, embedded_offset, address, |
734 | stream, recurse, val, | |
735 | &local_opts); | |
19ca80ba DJ |
736 | } |
737 | if (except.reason < 0) | |
738 | fprintf_filtered (stream, _("<error reading variable>")); | |
c906108c SS |
739 | } |
740 | ||
806048c6 | 741 | /* Check whether the value VAL is printable. Return 1 if it is; |
6501578c YQ |
742 | return 0 and print an appropriate error message to STREAM according to |
743 | OPTIONS if it is not. */ | |
c906108c | 744 | |
806048c6 | 745 | static int |
6501578c YQ |
746 | value_check_printable (struct value *val, struct ui_file *stream, |
747 | const struct value_print_options *options) | |
c906108c SS |
748 | { |
749 | if (val == 0) | |
750 | { | |
806048c6 | 751 | fprintf_filtered (stream, _("<address of value unknown>")); |
c906108c SS |
752 | return 0; |
753 | } | |
806048c6 | 754 | |
0e03807e | 755 | if (value_entirely_optimized_out (val)) |
c906108c | 756 | { |
6501578c YQ |
757 | if (options->summary && !scalar_type_p (value_type (val))) |
758 | fprintf_filtered (stream, "..."); | |
759 | else | |
760 | val_print_optimized_out (stream); | |
c906108c SS |
761 | return 0; |
762 | } | |
806048c6 | 763 | |
bc3b79fd TJB |
764 | if (TYPE_CODE (value_type (val)) == TYPE_CODE_INTERNAL_FUNCTION) |
765 | { | |
766 | fprintf_filtered (stream, _("<internal function %s>"), | |
767 | value_internal_function_name (val)); | |
768 | return 0; | |
769 | } | |
770 | ||
806048c6 DJ |
771 | return 1; |
772 | } | |
773 | ||
d8ca156b | 774 | /* Print using the given LANGUAGE the value VAL onto stream STREAM according |
79a45b7d | 775 | to OPTIONS. |
806048c6 | 776 | |
806048c6 DJ |
777 | This is a preferable interface to val_print, above, because it uses |
778 | GDB's value mechanism. */ | |
779 | ||
a1f5dd1b | 780 | void |
79a45b7d TT |
781 | common_val_print (struct value *val, struct ui_file *stream, int recurse, |
782 | const struct value_print_options *options, | |
d8ca156b | 783 | const struct language_defn *language) |
806048c6 | 784 | { |
6501578c | 785 | if (!value_check_printable (val, stream, options)) |
a1f5dd1b | 786 | return; |
806048c6 | 787 | |
0c3acc09 JB |
788 | if (language->la_language == language_ada) |
789 | /* The value might have a dynamic type, which would cause trouble | |
790 | below when trying to extract the value contents (since the value | |
791 | size is determined from the type size which is unknown). So | |
792 | get a fixed representation of our value. */ | |
793 | val = ada_to_fixed_value (val); | |
794 | ||
a1f5dd1b TT |
795 | val_print (value_type (val), value_contents_for_printing (val), |
796 | value_embedded_offset (val), value_address (val), | |
797 | stream, recurse, | |
798 | val, options, language); | |
806048c6 DJ |
799 | } |
800 | ||
7348c5e1 | 801 | /* Print on stream STREAM the value VAL according to OPTIONS. The value |
8e069a98 | 802 | is printed using the current_language syntax. */ |
7348c5e1 | 803 | |
8e069a98 | 804 | void |
79a45b7d TT |
805 | value_print (struct value *val, struct ui_file *stream, |
806 | const struct value_print_options *options) | |
806048c6 | 807 | { |
6501578c | 808 | if (!value_check_printable (val, stream, options)) |
8e069a98 | 809 | return; |
806048c6 | 810 | |
a6bac58e TT |
811 | if (!options->raw) |
812 | { | |
813 | int r = apply_val_pretty_printer (value_type (val), | |
0e03807e | 814 | value_contents_for_printing (val), |
a6bac58e TT |
815 | value_embedded_offset (val), |
816 | value_address (val), | |
0e03807e TT |
817 | stream, 0, |
818 | val, options, current_language); | |
a109c7c1 | 819 | |
a6bac58e | 820 | if (r) |
8e069a98 | 821 | return; |
a6bac58e TT |
822 | } |
823 | ||
8e069a98 | 824 | LA_VALUE_PRINT (val, stream, options); |
c906108c SS |
825 | } |
826 | ||
827 | /* Called by various <lang>_val_print routines to print | |
828 | TYPE_CODE_INT's. TYPE is the type. VALADDR is the address of the | |
829 | value. STREAM is where to print the value. */ | |
830 | ||
831 | void | |
fc1a4b47 | 832 | val_print_type_code_int (struct type *type, const gdb_byte *valaddr, |
fba45db2 | 833 | struct ui_file *stream) |
c906108c | 834 | { |
50810684 | 835 | enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type)); |
d44e8473 | 836 | |
c906108c SS |
837 | if (TYPE_LENGTH (type) > sizeof (LONGEST)) |
838 | { | |
839 | LONGEST val; | |
840 | ||
841 | if (TYPE_UNSIGNED (type) | |
842 | && extract_long_unsigned_integer (valaddr, TYPE_LENGTH (type), | |
e17a4113 | 843 | byte_order, &val)) |
c906108c SS |
844 | { |
845 | print_longest (stream, 'u', 0, val); | |
846 | } | |
847 | else | |
848 | { | |
849 | /* Signed, or we couldn't turn an unsigned value into a | |
850 | LONGEST. For signed values, one could assume two's | |
851 | complement (a reasonable assumption, I think) and do | |
852 | better than this. */ | |
853 | print_hex_chars (stream, (unsigned char *) valaddr, | |
d44e8473 | 854 | TYPE_LENGTH (type), byte_order); |
c906108c SS |
855 | } |
856 | } | |
857 | else | |
858 | { | |
c906108c SS |
859 | print_longest (stream, TYPE_UNSIGNED (type) ? 'u' : 'd', 0, |
860 | unpack_long (type, valaddr)); | |
c906108c SS |
861 | } |
862 | } | |
863 | ||
4f2aea11 MK |
864 | void |
865 | val_print_type_code_flags (struct type *type, const gdb_byte *valaddr, | |
866 | struct ui_file *stream) | |
867 | { | |
befae759 | 868 | ULONGEST val = unpack_long (type, valaddr); |
4f2aea11 MK |
869 | int bitpos, nfields = TYPE_NFIELDS (type); |
870 | ||
871 | fputs_filtered ("[ ", stream); | |
872 | for (bitpos = 0; bitpos < nfields; bitpos++) | |
873 | { | |
316703b9 MK |
874 | if (TYPE_FIELD_BITPOS (type, bitpos) != -1 |
875 | && (val & ((ULONGEST)1 << bitpos))) | |
4f2aea11 MK |
876 | { |
877 | if (TYPE_FIELD_NAME (type, bitpos)) | |
878 | fprintf_filtered (stream, "%s ", TYPE_FIELD_NAME (type, bitpos)); | |
879 | else | |
880 | fprintf_filtered (stream, "#%d ", bitpos); | |
881 | } | |
882 | } | |
883 | fputs_filtered ("]", stream); | |
19c37f24 | 884 | } |
ab2188aa PA |
885 | |
886 | /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR, | |
887 | according to OPTIONS and SIZE on STREAM. Format i is not supported | |
888 | at this level. | |
889 | ||
890 | This is how the elements of an array or structure are printed | |
891 | with a format. */ | |
ab2188aa PA |
892 | |
893 | void | |
894 | val_print_scalar_formatted (struct type *type, | |
895 | const gdb_byte *valaddr, int embedded_offset, | |
896 | const struct value *val, | |
897 | const struct value_print_options *options, | |
898 | int size, | |
899 | struct ui_file *stream) | |
900 | { | |
901 | gdb_assert (val != NULL); | |
902 | gdb_assert (valaddr == value_contents_for_printing_const (val)); | |
903 | ||
904 | /* If we get here with a string format, try again without it. Go | |
905 | all the way back to the language printers, which may call us | |
906 | again. */ | |
907 | if (options->format == 's') | |
908 | { | |
909 | struct value_print_options opts = *options; | |
910 | opts.format = 0; | |
911 | opts.deref_ref = 0; | |
912 | val_print (type, valaddr, embedded_offset, 0, stream, 0, val, &opts, | |
913 | current_language); | |
914 | return; | |
915 | } | |
916 | ||
917 | /* A scalar object that does not have all bits available can't be | |
918 | printed, because all bits contribute to its representation. */ | |
919 | if (!value_bits_valid (val, TARGET_CHAR_BIT * embedded_offset, | |
920 | TARGET_CHAR_BIT * TYPE_LENGTH (type))) | |
921 | val_print_optimized_out (stream); | |
4e07d55f PA |
922 | else if (!value_bytes_available (val, embedded_offset, TYPE_LENGTH (type))) |
923 | val_print_unavailable (stream); | |
ab2188aa PA |
924 | else |
925 | print_scalar_formatted (valaddr + embedded_offset, type, | |
926 | options, size, stream); | |
4f2aea11 MK |
927 | } |
928 | ||
c906108c SS |
929 | /* Print a number according to FORMAT which is one of d,u,x,o,b,h,w,g. |
930 | The raison d'etre of this function is to consolidate printing of | |
581e13c1 | 931 | LONG_LONG's into this one function. The format chars b,h,w,g are |
bb599908 | 932 | from print_scalar_formatted(). Numbers are printed using C |
581e13c1 | 933 | format. |
bb599908 PH |
934 | |
935 | USE_C_FORMAT means to use C format in all cases. Without it, | |
936 | 'o' and 'x' format do not include the standard C radix prefix | |
937 | (leading 0 or 0x). | |
938 | ||
939 | Hilfinger/2004-09-09: USE_C_FORMAT was originally called USE_LOCAL | |
940 | and was intended to request formating according to the current | |
941 | language and would be used for most integers that GDB prints. The | |
942 | exceptional cases were things like protocols where the format of | |
943 | the integer is a protocol thing, not a user-visible thing). The | |
944 | parameter remains to preserve the information of what things might | |
945 | be printed with language-specific format, should we ever resurrect | |
581e13c1 | 946 | that capability. */ |
c906108c SS |
947 | |
948 | void | |
bb599908 | 949 | print_longest (struct ui_file *stream, int format, int use_c_format, |
fba45db2 | 950 | LONGEST val_long) |
c906108c | 951 | { |
2bfb72ee AC |
952 | const char *val; |
953 | ||
c906108c SS |
954 | switch (format) |
955 | { | |
956 | case 'd': | |
bb599908 | 957 | val = int_string (val_long, 10, 1, 0, 1); break; |
c906108c | 958 | case 'u': |
bb599908 | 959 | val = int_string (val_long, 10, 0, 0, 1); break; |
c906108c | 960 | case 'x': |
bb599908 | 961 | val = int_string (val_long, 16, 0, 0, use_c_format); break; |
c906108c | 962 | case 'b': |
bb599908 | 963 | val = int_string (val_long, 16, 0, 2, 1); break; |
c906108c | 964 | case 'h': |
bb599908 | 965 | val = int_string (val_long, 16, 0, 4, 1); break; |
c906108c | 966 | case 'w': |
bb599908 | 967 | val = int_string (val_long, 16, 0, 8, 1); break; |
c906108c | 968 | case 'g': |
bb599908 | 969 | val = int_string (val_long, 16, 0, 16, 1); break; |
c906108c SS |
970 | break; |
971 | case 'o': | |
bb599908 | 972 | val = int_string (val_long, 8, 0, 0, use_c_format); break; |
c906108c | 973 | default: |
3e43a32a MS |
974 | internal_error (__FILE__, __LINE__, |
975 | _("failed internal consistency check")); | |
bb599908 | 976 | } |
2bfb72ee | 977 | fputs_filtered (val, stream); |
c906108c SS |
978 | } |
979 | ||
c906108c SS |
980 | /* This used to be a macro, but I don't think it is called often enough |
981 | to merit such treatment. */ | |
982 | /* Convert a LONGEST to an int. This is used in contexts (e.g. number of | |
983 | arguments to a function, number in a value history, register number, etc.) | |
984 | where the value must not be larger than can fit in an int. */ | |
985 | ||
986 | int | |
fba45db2 | 987 | longest_to_int (LONGEST arg) |
c906108c | 988 | { |
581e13c1 | 989 | /* Let the compiler do the work. */ |
c906108c SS |
990 | int rtnval = (int) arg; |
991 | ||
581e13c1 | 992 | /* Check for overflows or underflows. */ |
c906108c SS |
993 | if (sizeof (LONGEST) > sizeof (int)) |
994 | { | |
995 | if (rtnval != arg) | |
996 | { | |
8a3fe4f8 | 997 | error (_("Value out of range.")); |
c906108c SS |
998 | } |
999 | } | |
1000 | return (rtnval); | |
1001 | } | |
1002 | ||
a73c86fb AC |
1003 | /* Print a floating point value of type TYPE (not always a |
1004 | TYPE_CODE_FLT), pointed to in GDB by VALADDR, on STREAM. */ | |
c906108c SS |
1005 | |
1006 | void | |
fc1a4b47 | 1007 | print_floating (const gdb_byte *valaddr, struct type *type, |
c84141d6 | 1008 | struct ui_file *stream) |
c906108c SS |
1009 | { |
1010 | DOUBLEST doub; | |
1011 | int inv; | |
a73c86fb | 1012 | const struct floatformat *fmt = NULL; |
c906108c | 1013 | unsigned len = TYPE_LENGTH (type); |
20389057 | 1014 | enum float_kind kind; |
c5aa993b | 1015 | |
a73c86fb AC |
1016 | /* If it is a floating-point, check for obvious problems. */ |
1017 | if (TYPE_CODE (type) == TYPE_CODE_FLT) | |
1018 | fmt = floatformat_from_type (type); | |
20389057 | 1019 | if (fmt != NULL) |
39424bef | 1020 | { |
20389057 DJ |
1021 | kind = floatformat_classify (fmt, valaddr); |
1022 | if (kind == float_nan) | |
1023 | { | |
1024 | if (floatformat_is_negative (fmt, valaddr)) | |
1025 | fprintf_filtered (stream, "-"); | |
1026 | fprintf_filtered (stream, "nan("); | |
1027 | fputs_filtered ("0x", stream); | |
1028 | fputs_filtered (floatformat_mantissa (fmt, valaddr), stream); | |
1029 | fprintf_filtered (stream, ")"); | |
1030 | return; | |
1031 | } | |
1032 | else if (kind == float_infinite) | |
1033 | { | |
1034 | if (floatformat_is_negative (fmt, valaddr)) | |
1035 | fputs_filtered ("-", stream); | |
1036 | fputs_filtered ("inf", stream); | |
1037 | return; | |
1038 | } | |
7355ddba | 1039 | } |
c906108c | 1040 | |
a73c86fb AC |
1041 | /* NOTE: cagney/2002-01-15: The TYPE passed into print_floating() |
1042 | isn't necessarily a TYPE_CODE_FLT. Consequently, unpack_double | |
1043 | needs to be used as that takes care of any necessary type | |
1044 | conversions. Such conversions are of course direct to DOUBLEST | |
1045 | and disregard any possible target floating point limitations. | |
1046 | For instance, a u64 would be converted and displayed exactly on a | |
1047 | host with 80 bit DOUBLEST but with loss of information on a host | |
1048 | with 64 bit DOUBLEST. */ | |
c2f05ac9 | 1049 | |
c906108c SS |
1050 | doub = unpack_double (type, valaddr, &inv); |
1051 | if (inv) | |
1052 | { | |
1053 | fprintf_filtered (stream, "<invalid float value>"); | |
1054 | return; | |
1055 | } | |
1056 | ||
39424bef MK |
1057 | /* FIXME: kettenis/2001-01-20: The following code makes too much |
1058 | assumptions about the host and target floating point format. */ | |
1059 | ||
a73c86fb | 1060 | /* NOTE: cagney/2002-02-03: Since the TYPE of what was passed in may |
c41b8590 | 1061 | not necessarily be a TYPE_CODE_FLT, the below ignores that and |
a73c86fb AC |
1062 | instead uses the type's length to determine the precision of the |
1063 | floating-point value being printed. */ | |
c2f05ac9 | 1064 | |
c906108c | 1065 | if (len < sizeof (double)) |
c5aa993b | 1066 | fprintf_filtered (stream, "%.9g", (double) doub); |
c906108c | 1067 | else if (len == sizeof (double)) |
c5aa993b | 1068 | fprintf_filtered (stream, "%.17g", (double) doub); |
c906108c SS |
1069 | else |
1070 | #ifdef PRINTF_HAS_LONG_DOUBLE | |
1071 | fprintf_filtered (stream, "%.35Lg", doub); | |
1072 | #else | |
39424bef MK |
1073 | /* This at least wins with values that are representable as |
1074 | doubles. */ | |
c906108c SS |
1075 | fprintf_filtered (stream, "%.17g", (double) doub); |
1076 | #endif | |
1077 | } | |
1078 | ||
7678ef8f TJB |
1079 | void |
1080 | print_decimal_floating (const gdb_byte *valaddr, struct type *type, | |
1081 | struct ui_file *stream) | |
1082 | { | |
e17a4113 | 1083 | enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type)); |
7678ef8f TJB |
1084 | char decstr[MAX_DECIMAL_STRING]; |
1085 | unsigned len = TYPE_LENGTH (type); | |
1086 | ||
e17a4113 | 1087 | decimal_to_string (valaddr, len, byte_order, decstr); |
7678ef8f TJB |
1088 | fputs_filtered (decstr, stream); |
1089 | return; | |
1090 | } | |
1091 | ||
c5aa993b | 1092 | void |
fc1a4b47 | 1093 | print_binary_chars (struct ui_file *stream, const gdb_byte *valaddr, |
d44e8473 | 1094 | unsigned len, enum bfd_endian byte_order) |
c906108c SS |
1095 | { |
1096 | ||
1097 | #define BITS_IN_BYTES 8 | |
1098 | ||
fc1a4b47 | 1099 | const gdb_byte *p; |
745b8ca0 | 1100 | unsigned int i; |
c5aa993b | 1101 | int b; |
c906108c SS |
1102 | |
1103 | /* Declared "int" so it will be signed. | |
581e13c1 MS |
1104 | This ensures that right shift will shift in zeros. */ |
1105 | ||
c5aa993b | 1106 | const int mask = 0x080; |
c906108c SS |
1107 | |
1108 | /* FIXME: We should be not printing leading zeroes in most cases. */ | |
1109 | ||
d44e8473 | 1110 | if (byte_order == BFD_ENDIAN_BIG) |
c906108c SS |
1111 | { |
1112 | for (p = valaddr; | |
1113 | p < valaddr + len; | |
1114 | p++) | |
1115 | { | |
c5aa993b | 1116 | /* Every byte has 8 binary characters; peel off |
581e13c1 MS |
1117 | and print from the MSB end. */ |
1118 | ||
c5aa993b JM |
1119 | for (i = 0; i < (BITS_IN_BYTES * sizeof (*p)); i++) |
1120 | { | |
1121 | if (*p & (mask >> i)) | |
1122 | b = 1; | |
1123 | else | |
1124 | b = 0; | |
1125 | ||
1126 | fprintf_filtered (stream, "%1d", b); | |
1127 | } | |
c906108c SS |
1128 | } |
1129 | } | |
1130 | else | |
1131 | { | |
1132 | for (p = valaddr + len - 1; | |
1133 | p >= valaddr; | |
1134 | p--) | |
1135 | { | |
c5aa993b JM |
1136 | for (i = 0; i < (BITS_IN_BYTES * sizeof (*p)); i++) |
1137 | { | |
1138 | if (*p & (mask >> i)) | |
1139 | b = 1; | |
1140 | else | |
1141 | b = 0; | |
1142 | ||
1143 | fprintf_filtered (stream, "%1d", b); | |
1144 | } | |
c906108c SS |
1145 | } |
1146 | } | |
c906108c SS |
1147 | } |
1148 | ||
1149 | /* VALADDR points to an integer of LEN bytes. | |
581e13c1 MS |
1150 | Print it in octal on stream or format it in buf. */ |
1151 | ||
c906108c | 1152 | void |
fc1a4b47 | 1153 | print_octal_chars (struct ui_file *stream, const gdb_byte *valaddr, |
d44e8473 | 1154 | unsigned len, enum bfd_endian byte_order) |
c906108c | 1155 | { |
fc1a4b47 | 1156 | const gdb_byte *p; |
c906108c | 1157 | unsigned char octa1, octa2, octa3, carry; |
c5aa993b JM |
1158 | int cycle; |
1159 | ||
c906108c SS |
1160 | /* FIXME: We should be not printing leading zeroes in most cases. */ |
1161 | ||
1162 | ||
1163 | /* Octal is 3 bits, which doesn't fit. Yuk. So we have to track | |
1164 | * the extra bits, which cycle every three bytes: | |
1165 | * | |
1166 | * Byte side: 0 1 2 3 | |
1167 | * | | | | | |
1168 | * bit number 123 456 78 | 9 012 345 6 | 78 901 234 | 567 890 12 | | |
1169 | * | |
1170 | * Octal side: 0 1 carry 3 4 carry ... | |
1171 | * | |
1172 | * Cycle number: 0 1 2 | |
1173 | * | |
1174 | * But of course we are printing from the high side, so we have to | |
1175 | * figure out where in the cycle we are so that we end up with no | |
1176 | * left over bits at the end. | |
1177 | */ | |
1178 | #define BITS_IN_OCTAL 3 | |
1179 | #define HIGH_ZERO 0340 | |
1180 | #define LOW_ZERO 0016 | |
1181 | #define CARRY_ZERO 0003 | |
1182 | #define HIGH_ONE 0200 | |
1183 | #define MID_ONE 0160 | |
1184 | #define LOW_ONE 0016 | |
1185 | #define CARRY_ONE 0001 | |
1186 | #define HIGH_TWO 0300 | |
1187 | #define MID_TWO 0070 | |
1188 | #define LOW_TWO 0007 | |
1189 | ||
1190 | /* For 32 we start in cycle 2, with two bits and one bit carry; | |
581e13c1 MS |
1191 | for 64 in cycle in cycle 1, with one bit and a two bit carry. */ |
1192 | ||
c906108c SS |
1193 | cycle = (len * BITS_IN_BYTES) % BITS_IN_OCTAL; |
1194 | carry = 0; | |
c5aa993b | 1195 | |
bb599908 | 1196 | fputs_filtered ("0", stream); |
d44e8473 | 1197 | if (byte_order == BFD_ENDIAN_BIG) |
c906108c SS |
1198 | { |
1199 | for (p = valaddr; | |
1200 | p < valaddr + len; | |
1201 | p++) | |
1202 | { | |
c5aa993b JM |
1203 | switch (cycle) |
1204 | { | |
1205 | case 0: | |
581e13c1 MS |
1206 | /* No carry in, carry out two bits. */ |
1207 | ||
c5aa993b JM |
1208 | octa1 = (HIGH_ZERO & *p) >> 5; |
1209 | octa2 = (LOW_ZERO & *p) >> 2; | |
1210 | carry = (CARRY_ZERO & *p); | |
1211 | fprintf_filtered (stream, "%o", octa1); | |
1212 | fprintf_filtered (stream, "%o", octa2); | |
1213 | break; | |
1214 | ||
1215 | case 1: | |
581e13c1 MS |
1216 | /* Carry in two bits, carry out one bit. */ |
1217 | ||
c5aa993b JM |
1218 | octa1 = (carry << 1) | ((HIGH_ONE & *p) >> 7); |
1219 | octa2 = (MID_ONE & *p) >> 4; | |
1220 | octa3 = (LOW_ONE & *p) >> 1; | |
1221 | carry = (CARRY_ONE & *p); | |
1222 | fprintf_filtered (stream, "%o", octa1); | |
1223 | fprintf_filtered (stream, "%o", octa2); | |
1224 | fprintf_filtered (stream, "%o", octa3); | |
1225 | break; | |
1226 | ||
1227 | case 2: | |
581e13c1 MS |
1228 | /* Carry in one bit, no carry out. */ |
1229 | ||
c5aa993b JM |
1230 | octa1 = (carry << 2) | ((HIGH_TWO & *p) >> 6); |
1231 | octa2 = (MID_TWO & *p) >> 3; | |
1232 | octa3 = (LOW_TWO & *p); | |
1233 | carry = 0; | |
1234 | fprintf_filtered (stream, "%o", octa1); | |
1235 | fprintf_filtered (stream, "%o", octa2); | |
1236 | fprintf_filtered (stream, "%o", octa3); | |
1237 | break; | |
1238 | ||
1239 | default: | |
8a3fe4f8 | 1240 | error (_("Internal error in octal conversion;")); |
c5aa993b JM |
1241 | } |
1242 | ||
1243 | cycle++; | |
1244 | cycle = cycle % BITS_IN_OCTAL; | |
c906108c SS |
1245 | } |
1246 | } | |
1247 | else | |
1248 | { | |
1249 | for (p = valaddr + len - 1; | |
1250 | p >= valaddr; | |
1251 | p--) | |
1252 | { | |
c5aa993b JM |
1253 | switch (cycle) |
1254 | { | |
1255 | case 0: | |
1256 | /* Carry out, no carry in */ | |
581e13c1 | 1257 | |
c5aa993b JM |
1258 | octa1 = (HIGH_ZERO & *p) >> 5; |
1259 | octa2 = (LOW_ZERO & *p) >> 2; | |
1260 | carry = (CARRY_ZERO & *p); | |
1261 | fprintf_filtered (stream, "%o", octa1); | |
1262 | fprintf_filtered (stream, "%o", octa2); | |
1263 | break; | |
1264 | ||
1265 | case 1: | |
1266 | /* Carry in, carry out */ | |
581e13c1 | 1267 | |
c5aa993b JM |
1268 | octa1 = (carry << 1) | ((HIGH_ONE & *p) >> 7); |
1269 | octa2 = (MID_ONE & *p) >> 4; | |
1270 | octa3 = (LOW_ONE & *p) >> 1; | |
1271 | carry = (CARRY_ONE & *p); | |
1272 | fprintf_filtered (stream, "%o", octa1); | |
1273 | fprintf_filtered (stream, "%o", octa2); | |
1274 | fprintf_filtered (stream, "%o", octa3); | |
1275 | break; | |
1276 | ||
1277 | case 2: | |
1278 | /* Carry in, no carry out */ | |
581e13c1 | 1279 | |
c5aa993b JM |
1280 | octa1 = (carry << 2) | ((HIGH_TWO & *p) >> 6); |
1281 | octa2 = (MID_TWO & *p) >> 3; | |
1282 | octa3 = (LOW_TWO & *p); | |
1283 | carry = 0; | |
1284 | fprintf_filtered (stream, "%o", octa1); | |
1285 | fprintf_filtered (stream, "%o", octa2); | |
1286 | fprintf_filtered (stream, "%o", octa3); | |
1287 | break; | |
1288 | ||
1289 | default: | |
8a3fe4f8 | 1290 | error (_("Internal error in octal conversion;")); |
c5aa993b JM |
1291 | } |
1292 | ||
1293 | cycle++; | |
1294 | cycle = cycle % BITS_IN_OCTAL; | |
c906108c SS |
1295 | } |
1296 | } | |
1297 | ||
c906108c SS |
1298 | } |
1299 | ||
1300 | /* VALADDR points to an integer of LEN bytes. | |
581e13c1 MS |
1301 | Print it in decimal on stream or format it in buf. */ |
1302 | ||
c906108c | 1303 | void |
fc1a4b47 | 1304 | print_decimal_chars (struct ui_file *stream, const gdb_byte *valaddr, |
d44e8473 | 1305 | unsigned len, enum bfd_endian byte_order) |
c906108c SS |
1306 | { |
1307 | #define TEN 10 | |
c5aa993b | 1308 | #define CARRY_OUT( x ) ((x) / TEN) /* extend char to int */ |
c906108c SS |
1309 | #define CARRY_LEFT( x ) ((x) % TEN) |
1310 | #define SHIFT( x ) ((x) << 4) | |
c906108c SS |
1311 | #define LOW_NIBBLE( x ) ( (x) & 0x00F) |
1312 | #define HIGH_NIBBLE( x ) (((x) & 0x0F0) >> 4) | |
1313 | ||
fc1a4b47 | 1314 | const gdb_byte *p; |
c906108c | 1315 | unsigned char *digits; |
c5aa993b JM |
1316 | int carry; |
1317 | int decimal_len; | |
1318 | int i, j, decimal_digits; | |
1319 | int dummy; | |
1320 | int flip; | |
1321 | ||
c906108c | 1322 | /* Base-ten number is less than twice as many digits |
581e13c1 MS |
1323 | as the base 16 number, which is 2 digits per byte. */ |
1324 | ||
c906108c | 1325 | decimal_len = len * 2 * 2; |
3c37485b | 1326 | digits = xmalloc (decimal_len); |
c906108c | 1327 | |
c5aa993b JM |
1328 | for (i = 0; i < decimal_len; i++) |
1329 | { | |
c906108c | 1330 | digits[i] = 0; |
c5aa993b | 1331 | } |
c906108c | 1332 | |
c906108c SS |
1333 | /* Ok, we have an unknown number of bytes of data to be printed in |
1334 | * decimal. | |
1335 | * | |
1336 | * Given a hex number (in nibbles) as XYZ, we start by taking X and | |
1337 | * decemalizing it as "x1 x2" in two decimal nibbles. Then we multiply | |
1338 | * the nibbles by 16, add Y and re-decimalize. Repeat with Z. | |
1339 | * | |
1340 | * The trick is that "digits" holds a base-10 number, but sometimes | |
581e13c1 | 1341 | * the individual digits are > 10. |
c906108c SS |
1342 | * |
1343 | * Outer loop is per nibble (hex digit) of input, from MSD end to | |
1344 | * LSD end. | |
1345 | */ | |
c5aa993b | 1346 | decimal_digits = 0; /* Number of decimal digits so far */ |
d44e8473 | 1347 | p = (byte_order == BFD_ENDIAN_BIG) ? valaddr : valaddr + len - 1; |
c906108c | 1348 | flip = 0; |
d44e8473 | 1349 | while ((byte_order == BFD_ENDIAN_BIG) ? (p < valaddr + len) : (p >= valaddr)) |
c5aa993b | 1350 | { |
c906108c SS |
1351 | /* |
1352 | * Multiply current base-ten number by 16 in place. | |
1353 | * Each digit was between 0 and 9, now is between | |
1354 | * 0 and 144. | |
1355 | */ | |
c5aa993b JM |
1356 | for (j = 0; j < decimal_digits; j++) |
1357 | { | |
1358 | digits[j] = SHIFT (digits[j]); | |
1359 | } | |
1360 | ||
c906108c SS |
1361 | /* Take the next nibble off the input and add it to what |
1362 | * we've got in the LSB position. Bottom 'digit' is now | |
1363 | * between 0 and 159. | |
1364 | * | |
1365 | * "flip" is used to run this loop twice for each byte. | |
1366 | */ | |
c5aa993b JM |
1367 | if (flip == 0) |
1368 | { | |
581e13c1 MS |
1369 | /* Take top nibble. */ |
1370 | ||
c5aa993b JM |
1371 | digits[0] += HIGH_NIBBLE (*p); |
1372 | flip = 1; | |
1373 | } | |
1374 | else | |
1375 | { | |
581e13c1 MS |
1376 | /* Take low nibble and bump our pointer "p". */ |
1377 | ||
c5aa993b | 1378 | digits[0] += LOW_NIBBLE (*p); |
d44e8473 MD |
1379 | if (byte_order == BFD_ENDIAN_BIG) |
1380 | p++; | |
1381 | else | |
1382 | p--; | |
c5aa993b JM |
1383 | flip = 0; |
1384 | } | |
c906108c SS |
1385 | |
1386 | /* Re-decimalize. We have to do this often enough | |
1387 | * that we don't overflow, but once per nibble is | |
1388 | * overkill. Easier this way, though. Note that the | |
1389 | * carry is often larger than 10 (e.g. max initial | |
1390 | * carry out of lowest nibble is 15, could bubble all | |
1391 | * the way up greater than 10). So we have to do | |
1392 | * the carrying beyond the last current digit. | |
1393 | */ | |
1394 | carry = 0; | |
c5aa993b JM |
1395 | for (j = 0; j < decimal_len - 1; j++) |
1396 | { | |
1397 | digits[j] += carry; | |
1398 | ||
1399 | /* "/" won't handle an unsigned char with | |
1400 | * a value that if signed would be negative. | |
1401 | * So extend to longword int via "dummy". | |
1402 | */ | |
1403 | dummy = digits[j]; | |
1404 | carry = CARRY_OUT (dummy); | |
1405 | digits[j] = CARRY_LEFT (dummy); | |
1406 | ||
1407 | if (j >= decimal_digits && carry == 0) | |
1408 | { | |
1409 | /* | |
1410 | * All higher digits are 0 and we | |
1411 | * no longer have a carry. | |
1412 | * | |
1413 | * Note: "j" is 0-based, "decimal_digits" is | |
1414 | * 1-based. | |
1415 | */ | |
1416 | decimal_digits = j + 1; | |
1417 | break; | |
1418 | } | |
1419 | } | |
1420 | } | |
c906108c SS |
1421 | |
1422 | /* Ok, now "digits" is the decimal representation, with | |
581e13c1 MS |
1423 | the "decimal_digits" actual digits. Print! */ |
1424 | ||
c5aa993b JM |
1425 | for (i = decimal_digits - 1; i >= 0; i--) |
1426 | { | |
1427 | fprintf_filtered (stream, "%1d", digits[i]); | |
1428 | } | |
b8c9b27d | 1429 | xfree (digits); |
c906108c SS |
1430 | } |
1431 | ||
1432 | /* VALADDR points to an integer of LEN bytes. Print it in hex on stream. */ | |
1433 | ||
6b9acc27 | 1434 | void |
fc1a4b47 | 1435 | print_hex_chars (struct ui_file *stream, const gdb_byte *valaddr, |
d44e8473 | 1436 | unsigned len, enum bfd_endian byte_order) |
c906108c | 1437 | { |
fc1a4b47 | 1438 | const gdb_byte *p; |
c906108c SS |
1439 | |
1440 | /* FIXME: We should be not printing leading zeroes in most cases. */ | |
1441 | ||
bb599908 | 1442 | fputs_filtered ("0x", stream); |
d44e8473 | 1443 | if (byte_order == BFD_ENDIAN_BIG) |
c906108c SS |
1444 | { |
1445 | for (p = valaddr; | |
1446 | p < valaddr + len; | |
1447 | p++) | |
1448 | { | |
1449 | fprintf_filtered (stream, "%02x", *p); | |
1450 | } | |
1451 | } | |
1452 | else | |
1453 | { | |
1454 | for (p = valaddr + len - 1; | |
1455 | p >= valaddr; | |
1456 | p--) | |
1457 | { | |
1458 | fprintf_filtered (stream, "%02x", *p); | |
1459 | } | |
1460 | } | |
c906108c SS |
1461 | } |
1462 | ||
3e43a32a | 1463 | /* VALADDR points to a char integer of LEN bytes. |
581e13c1 | 1464 | Print it out in appropriate language form on stream. |
6b9acc27 JJ |
1465 | Omit any leading zero chars. */ |
1466 | ||
1467 | void | |
6c7a06a3 TT |
1468 | print_char_chars (struct ui_file *stream, struct type *type, |
1469 | const gdb_byte *valaddr, | |
d44e8473 | 1470 | unsigned len, enum bfd_endian byte_order) |
6b9acc27 | 1471 | { |
fc1a4b47 | 1472 | const gdb_byte *p; |
6b9acc27 | 1473 | |
d44e8473 | 1474 | if (byte_order == BFD_ENDIAN_BIG) |
6b9acc27 JJ |
1475 | { |
1476 | p = valaddr; | |
1477 | while (p < valaddr + len - 1 && *p == 0) | |
1478 | ++p; | |
1479 | ||
1480 | while (p < valaddr + len) | |
1481 | { | |
6c7a06a3 | 1482 | LA_EMIT_CHAR (*p, type, stream, '\''); |
6b9acc27 JJ |
1483 | ++p; |
1484 | } | |
1485 | } | |
1486 | else | |
1487 | { | |
1488 | p = valaddr + len - 1; | |
1489 | while (p > valaddr && *p == 0) | |
1490 | --p; | |
1491 | ||
1492 | while (p >= valaddr) | |
1493 | { | |
6c7a06a3 | 1494 | LA_EMIT_CHAR (*p, type, stream, '\''); |
6b9acc27 JJ |
1495 | --p; |
1496 | } | |
1497 | } | |
1498 | } | |
1499 | ||
132c57b4 TT |
1500 | /* Print function pointer with inferior address ADDRESS onto stdio |
1501 | stream STREAM. */ | |
1502 | ||
1503 | void | |
1504 | print_function_pointer_address (struct gdbarch *gdbarch, | |
1505 | CORE_ADDR address, | |
1506 | struct ui_file *stream, | |
1507 | int addressprint) | |
1508 | { | |
1509 | CORE_ADDR func_addr | |
1510 | = gdbarch_convert_from_func_ptr_addr (gdbarch, address, | |
1511 | ¤t_target); | |
1512 | ||
1513 | /* If the function pointer is represented by a description, print | |
1514 | the address of the description. */ | |
1515 | if (addressprint && func_addr != address) | |
1516 | { | |
1517 | fputs_filtered ("@", stream); | |
1518 | fputs_filtered (paddress (gdbarch, address), stream); | |
1519 | fputs_filtered (": ", stream); | |
1520 | } | |
1521 | print_address_demangle (gdbarch, func_addr, stream, demangle); | |
1522 | } | |
1523 | ||
1524 | ||
79a45b7d | 1525 | /* Print on STREAM using the given OPTIONS the index for the element |
e79af960 JB |
1526 | at INDEX of an array whose index type is INDEX_TYPE. */ |
1527 | ||
1528 | void | |
1529 | maybe_print_array_index (struct type *index_type, LONGEST index, | |
79a45b7d TT |
1530 | struct ui_file *stream, |
1531 | const struct value_print_options *options) | |
e79af960 JB |
1532 | { |
1533 | struct value *index_value; | |
1534 | ||
79a45b7d | 1535 | if (!options->print_array_indexes) |
e79af960 JB |
1536 | return; |
1537 | ||
1538 | index_value = value_from_longest (index_type, index); | |
1539 | ||
79a45b7d TT |
1540 | LA_PRINT_ARRAY_INDEX (index_value, stream, options); |
1541 | } | |
e79af960 | 1542 | |
c906108c | 1543 | /* Called by various <lang>_val_print routines to print elements of an |
c5aa993b | 1544 | array in the form "<elem1>, <elem2>, <elem3>, ...". |
c906108c | 1545 | |
c5aa993b JM |
1546 | (FIXME?) Assumes array element separator is a comma, which is correct |
1547 | for all languages currently handled. | |
1548 | (FIXME?) Some languages have a notation for repeated array elements, | |
581e13c1 | 1549 | perhaps we should try to use that notation when appropriate. */ |
c906108c SS |
1550 | |
1551 | void | |
490f124f PA |
1552 | val_print_array_elements (struct type *type, |
1553 | const gdb_byte *valaddr, int embedded_offset, | |
a2bd3dcd | 1554 | CORE_ADDR address, struct ui_file *stream, |
79a45b7d | 1555 | int recurse, |
0e03807e | 1556 | const struct value *val, |
79a45b7d | 1557 | const struct value_print_options *options, |
fba45db2 | 1558 | unsigned int i) |
c906108c SS |
1559 | { |
1560 | unsigned int things_printed = 0; | |
1561 | unsigned len; | |
e79af960 | 1562 | struct type *elttype, *index_type; |
c906108c SS |
1563 | unsigned eltlen; |
1564 | /* Position of the array element we are examining to see | |
1565 | whether it is repeated. */ | |
1566 | unsigned int rep1; | |
1567 | /* Number of repetitions we have detected so far. */ | |
1568 | unsigned int reps; | |
dbc98a8b | 1569 | LONGEST low_bound, high_bound; |
c5aa993b | 1570 | |
c906108c SS |
1571 | elttype = TYPE_TARGET_TYPE (type); |
1572 | eltlen = TYPE_LENGTH (check_typedef (elttype)); | |
e79af960 | 1573 | index_type = TYPE_INDEX_TYPE (type); |
c906108c | 1574 | |
dbc98a8b | 1575 | if (get_array_bounds (type, &low_bound, &high_bound)) |
75be741b JB |
1576 | { |
1577 | /* The array length should normally be HIGH_BOUND - LOW_BOUND + 1. | |
1578 | But we have to be a little extra careful, because some languages | |
1579 | such as Ada allow LOW_BOUND to be greater than HIGH_BOUND for | |
1580 | empty arrays. In that situation, the array length is just zero, | |
1581 | not negative! */ | |
1582 | if (low_bound > high_bound) | |
1583 | len = 0; | |
1584 | else | |
1585 | len = high_bound - low_bound + 1; | |
1586 | } | |
e936309c JB |
1587 | else |
1588 | { | |
dbc98a8b KW |
1589 | warning (_("unable to get bounds of array, assuming null array")); |
1590 | low_bound = 0; | |
1591 | len = 0; | |
168de233 JB |
1592 | } |
1593 | ||
c906108c SS |
1594 | annotate_array_section_begin (i, elttype); |
1595 | ||
79a45b7d | 1596 | for (; i < len && things_printed < options->print_max; i++) |
c906108c SS |
1597 | { |
1598 | if (i != 0) | |
1599 | { | |
79a45b7d | 1600 | if (options->prettyprint_arrays) |
c906108c SS |
1601 | { |
1602 | fprintf_filtered (stream, ",\n"); | |
1603 | print_spaces_filtered (2 + 2 * recurse, stream); | |
1604 | } | |
1605 | else | |
1606 | { | |
1607 | fprintf_filtered (stream, ", "); | |
1608 | } | |
1609 | } | |
1610 | wrap_here (n_spaces (2 + 2 * recurse)); | |
dbc98a8b | 1611 | maybe_print_array_index (index_type, i + low_bound, |
79a45b7d | 1612 | stream, options); |
c906108c SS |
1613 | |
1614 | rep1 = i + 1; | |
1615 | reps = 1; | |
35bef4fd TT |
1616 | /* Only check for reps if repeat_count_threshold is not set to |
1617 | UINT_MAX (unlimited). */ | |
1618 | if (options->repeat_count_threshold < UINT_MAX) | |
c906108c | 1619 | { |
35bef4fd TT |
1620 | while (rep1 < len |
1621 | && value_available_contents_eq (val, | |
1622 | embedded_offset + i * eltlen, | |
1623 | val, | |
1624 | (embedded_offset | |
1625 | + rep1 * eltlen), | |
1626 | eltlen)) | |
1627 | { | |
1628 | ++reps; | |
1629 | ++rep1; | |
1630 | } | |
c906108c SS |
1631 | } |
1632 | ||
79a45b7d | 1633 | if (reps > options->repeat_count_threshold) |
c906108c | 1634 | { |
490f124f PA |
1635 | val_print (elttype, valaddr, embedded_offset + i * eltlen, |
1636 | address, stream, recurse + 1, val, options, | |
1637 | current_language); | |
c906108c SS |
1638 | annotate_elt_rep (reps); |
1639 | fprintf_filtered (stream, " <repeats %u times>", reps); | |
1640 | annotate_elt_rep_end (); | |
1641 | ||
1642 | i = rep1 - 1; | |
79a45b7d | 1643 | things_printed += options->repeat_count_threshold; |
c906108c SS |
1644 | } |
1645 | else | |
1646 | { | |
490f124f PA |
1647 | val_print (elttype, valaddr, embedded_offset + i * eltlen, |
1648 | address, | |
0e03807e | 1649 | stream, recurse + 1, val, options, current_language); |
c906108c SS |
1650 | annotate_elt (); |
1651 | things_printed++; | |
1652 | } | |
1653 | } | |
1654 | annotate_array_section_end (); | |
1655 | if (i < len) | |
1656 | { | |
1657 | fprintf_filtered (stream, "..."); | |
1658 | } | |
1659 | } | |
1660 | ||
917317f4 JM |
1661 | /* Read LEN bytes of target memory at address MEMADDR, placing the |
1662 | results in GDB's memory at MYADDR. Returns a count of the bytes | |
1663 | actually read, and optionally an errno value in the location | |
581e13c1 | 1664 | pointed to by ERRNOPTR if ERRNOPTR is non-null. */ |
917317f4 JM |
1665 | |
1666 | /* FIXME: cagney/1999-10-14: Only used by val_print_string. Can this | |
1667 | function be eliminated. */ | |
1668 | ||
1669 | static int | |
3e43a32a MS |
1670 | partial_memory_read (CORE_ADDR memaddr, gdb_byte *myaddr, |
1671 | int len, int *errnoptr) | |
917317f4 | 1672 | { |
581e13c1 MS |
1673 | int nread; /* Number of bytes actually read. */ |
1674 | int errcode; /* Error from last read. */ | |
917317f4 | 1675 | |
581e13c1 | 1676 | /* First try a complete read. */ |
917317f4 JM |
1677 | errcode = target_read_memory (memaddr, myaddr, len); |
1678 | if (errcode == 0) | |
1679 | { | |
581e13c1 | 1680 | /* Got it all. */ |
917317f4 JM |
1681 | nread = len; |
1682 | } | |
1683 | else | |
1684 | { | |
581e13c1 | 1685 | /* Loop, reading one byte at a time until we get as much as we can. */ |
917317f4 JM |
1686 | for (errcode = 0, nread = 0; len > 0 && errcode == 0; nread++, len--) |
1687 | { | |
1688 | errcode = target_read_memory (memaddr++, myaddr++, 1); | |
1689 | } | |
581e13c1 | 1690 | /* If an error, the last read was unsuccessful, so adjust count. */ |
917317f4 JM |
1691 | if (errcode != 0) |
1692 | { | |
1693 | nread--; | |
1694 | } | |
1695 | } | |
1696 | if (errnoptr != NULL) | |
1697 | { | |
1698 | *errnoptr = errcode; | |
1699 | } | |
1700 | return (nread); | |
1701 | } | |
1702 | ||
ae6a3a4c TJB |
1703 | /* Read a string from the inferior, at ADDR, with LEN characters of WIDTH bytes |
1704 | each. Fetch at most FETCHLIMIT characters. BUFFER will be set to a newly | |
1705 | allocated buffer containing the string, which the caller is responsible to | |
1706 | free, and BYTES_READ will be set to the number of bytes read. Returns 0 on | |
1707 | success, or errno on failure. | |
1708 | ||
1709 | If LEN > 0, reads exactly LEN characters (including eventual NULs in | |
1710 | the middle or end of the string). If LEN is -1, stops at the first | |
1711 | null character (not necessarily the first null byte) up to a maximum | |
1712 | of FETCHLIMIT characters. Set FETCHLIMIT to UINT_MAX to read as many | |
1713 | characters as possible from the string. | |
1714 | ||
1715 | Unless an exception is thrown, BUFFER will always be allocated, even on | |
1716 | failure. In this case, some characters might have been read before the | |
1717 | failure happened. Check BYTES_READ to recognize this situation. | |
1718 | ||
1719 | Note: There was a FIXME asking to make this code use target_read_string, | |
1720 | but this function is more general (can read past null characters, up to | |
581e13c1 | 1721 | given LEN). Besides, it is used much more often than target_read_string |
ae6a3a4c TJB |
1722 | so it is more tested. Perhaps callers of target_read_string should use |
1723 | this function instead? */ | |
c906108c SS |
1724 | |
1725 | int | |
ae6a3a4c | 1726 | read_string (CORE_ADDR addr, int len, int width, unsigned int fetchlimit, |
e17a4113 | 1727 | enum bfd_endian byte_order, gdb_byte **buffer, int *bytes_read) |
c906108c | 1728 | { |
ae6a3a4c TJB |
1729 | int found_nul; /* Non-zero if we found the nul char. */ |
1730 | int errcode; /* Errno returned from bad reads. */ | |
1731 | unsigned int nfetch; /* Chars to fetch / chars fetched. */ | |
1732 | unsigned int chunksize; /* Size of each fetch, in chars. */ | |
3e43a32a MS |
1733 | gdb_byte *bufptr; /* Pointer to next available byte in |
1734 | buffer. */ | |
ae6a3a4c TJB |
1735 | gdb_byte *limit; /* First location past end of fetch buffer. */ |
1736 | struct cleanup *old_chain = NULL; /* Top of the old cleanup chain. */ | |
1737 | ||
1738 | /* Decide how large of chunks to try to read in one operation. This | |
c906108c SS |
1739 | is also pretty simple. If LEN >= zero, then we want fetchlimit chars, |
1740 | so we might as well read them all in one operation. If LEN is -1, we | |
ae6a3a4c | 1741 | are looking for a NUL terminator to end the fetching, so we might as |
c906108c SS |
1742 | well read in blocks that are large enough to be efficient, but not so |
1743 | large as to be slow if fetchlimit happens to be large. So we choose the | |
1744 | minimum of 8 and fetchlimit. We used to use 200 instead of 8 but | |
1745 | 200 is way too big for remote debugging over a serial line. */ | |
1746 | ||
1747 | chunksize = (len == -1 ? min (8, fetchlimit) : fetchlimit); | |
1748 | ||
ae6a3a4c TJB |
1749 | /* Loop until we either have all the characters, or we encounter |
1750 | some error, such as bumping into the end of the address space. */ | |
c906108c SS |
1751 | |
1752 | found_nul = 0; | |
b5096abe PM |
1753 | *buffer = NULL; |
1754 | ||
1755 | old_chain = make_cleanup (free_current_contents, buffer); | |
c906108c SS |
1756 | |
1757 | if (len > 0) | |
1758 | { | |
ae6a3a4c TJB |
1759 | *buffer = (gdb_byte *) xmalloc (len * width); |
1760 | bufptr = *buffer; | |
c906108c | 1761 | |
917317f4 | 1762 | nfetch = partial_memory_read (addr, bufptr, len * width, &errcode) |
c906108c SS |
1763 | / width; |
1764 | addr += nfetch * width; | |
1765 | bufptr += nfetch * width; | |
1766 | } | |
1767 | else if (len == -1) | |
1768 | { | |
1769 | unsigned long bufsize = 0; | |
ae6a3a4c | 1770 | |
c906108c SS |
1771 | do |
1772 | { | |
1773 | QUIT; | |
1774 | nfetch = min (chunksize, fetchlimit - bufsize); | |
1775 | ||
ae6a3a4c TJB |
1776 | if (*buffer == NULL) |
1777 | *buffer = (gdb_byte *) xmalloc (nfetch * width); | |
c906108c | 1778 | else |
b5096abe PM |
1779 | *buffer = (gdb_byte *) xrealloc (*buffer, |
1780 | (nfetch + bufsize) * width); | |
c906108c | 1781 | |
ae6a3a4c | 1782 | bufptr = *buffer + bufsize * width; |
c906108c SS |
1783 | bufsize += nfetch; |
1784 | ||
ae6a3a4c | 1785 | /* Read as much as we can. */ |
917317f4 | 1786 | nfetch = partial_memory_read (addr, bufptr, nfetch * width, &errcode) |
ae6a3a4c | 1787 | / width; |
c906108c | 1788 | |
ae6a3a4c | 1789 | /* Scan this chunk for the null character that terminates the string |
c906108c SS |
1790 | to print. If found, we don't need to fetch any more. Note |
1791 | that bufptr is explicitly left pointing at the next character | |
ae6a3a4c TJB |
1792 | after the null character, or at the next character after the end |
1793 | of the buffer. */ | |
c906108c SS |
1794 | |
1795 | limit = bufptr + nfetch * width; | |
1796 | while (bufptr < limit) | |
1797 | { | |
1798 | unsigned long c; | |
1799 | ||
e17a4113 | 1800 | c = extract_unsigned_integer (bufptr, width, byte_order); |
c906108c SS |
1801 | addr += width; |
1802 | bufptr += width; | |
1803 | if (c == 0) | |
1804 | { | |
1805 | /* We don't care about any error which happened after | |
ae6a3a4c | 1806 | the NUL terminator. */ |
c906108c SS |
1807 | errcode = 0; |
1808 | found_nul = 1; | |
1809 | break; | |
1810 | } | |
1811 | } | |
1812 | } | |
c5aa993b | 1813 | while (errcode == 0 /* no error */ |
ae6a3a4c TJB |
1814 | && bufptr - *buffer < fetchlimit * width /* no overrun */ |
1815 | && !found_nul); /* haven't found NUL yet */ | |
c906108c SS |
1816 | } |
1817 | else | |
ae6a3a4c TJB |
1818 | { /* Length of string is really 0! */ |
1819 | /* We always allocate *buffer. */ | |
1820 | *buffer = bufptr = xmalloc (1); | |
c906108c SS |
1821 | errcode = 0; |
1822 | } | |
1823 | ||
1824 | /* bufptr and addr now point immediately beyond the last byte which we | |
1825 | consider part of the string (including a '\0' which ends the string). */ | |
ae6a3a4c TJB |
1826 | *bytes_read = bufptr - *buffer; |
1827 | ||
1828 | QUIT; | |
1829 | ||
1830 | discard_cleanups (old_chain); | |
1831 | ||
1832 | return errcode; | |
1833 | } | |
1834 | ||
3b2b8fea TT |
1835 | /* Return true if print_wchar can display W without resorting to a |
1836 | numeric escape, false otherwise. */ | |
1837 | ||
1838 | static int | |
1839 | wchar_printable (gdb_wchar_t w) | |
1840 | { | |
1841 | return (gdb_iswprint (w) | |
1842 | || w == LCST ('\a') || w == LCST ('\b') | |
1843 | || w == LCST ('\f') || w == LCST ('\n') | |
1844 | || w == LCST ('\r') || w == LCST ('\t') | |
1845 | || w == LCST ('\v')); | |
1846 | } | |
1847 | ||
1848 | /* A helper function that converts the contents of STRING to wide | |
1849 | characters and then appends them to OUTPUT. */ | |
1850 | ||
1851 | static void | |
1852 | append_string_as_wide (const char *string, | |
1853 | struct obstack *output) | |
1854 | { | |
1855 | for (; *string; ++string) | |
1856 | { | |
1857 | gdb_wchar_t w = gdb_btowc (*string); | |
1858 | obstack_grow (output, &w, sizeof (gdb_wchar_t)); | |
1859 | } | |
1860 | } | |
1861 | ||
1862 | /* Print a wide character W to OUTPUT. ORIG is a pointer to the | |
1863 | original (target) bytes representing the character, ORIG_LEN is the | |
1864 | number of valid bytes. WIDTH is the number of bytes in a base | |
1865 | characters of the type. OUTPUT is an obstack to which wide | |
1866 | characters are emitted. QUOTER is a (narrow) character indicating | |
1867 | the style of quotes surrounding the character to be printed. | |
1868 | NEED_ESCAPE is an in/out flag which is used to track numeric | |
1869 | escapes across calls. */ | |
1870 | ||
1871 | static void | |
1872 | print_wchar (gdb_wint_t w, const gdb_byte *orig, | |
1873 | int orig_len, int width, | |
1874 | enum bfd_endian byte_order, | |
1875 | struct obstack *output, | |
1876 | int quoter, int *need_escapep) | |
1877 | { | |
1878 | int need_escape = *need_escapep; | |
1879 | ||
1880 | *need_escapep = 0; | |
1881 | if (gdb_iswprint (w) && (!need_escape || (!gdb_iswdigit (w) | |
1882 | && w != LCST ('8') | |
1883 | && w != LCST ('9')))) | |
1884 | { | |
1885 | gdb_wchar_t wchar = w; | |
1886 | ||
1887 | if (w == gdb_btowc (quoter) || w == LCST ('\\')) | |
1888 | obstack_grow_wstr (output, LCST ("\\")); | |
1889 | obstack_grow (output, &wchar, sizeof (gdb_wchar_t)); | |
1890 | } | |
1891 | else | |
1892 | { | |
1893 | switch (w) | |
1894 | { | |
1895 | case LCST ('\a'): | |
1896 | obstack_grow_wstr (output, LCST ("\\a")); | |
1897 | break; | |
1898 | case LCST ('\b'): | |
1899 | obstack_grow_wstr (output, LCST ("\\b")); | |
1900 | break; | |
1901 | case LCST ('\f'): | |
1902 | obstack_grow_wstr (output, LCST ("\\f")); | |
1903 | break; | |
1904 | case LCST ('\n'): | |
1905 | obstack_grow_wstr (output, LCST ("\\n")); | |
1906 | break; | |
1907 | case LCST ('\r'): | |
1908 | obstack_grow_wstr (output, LCST ("\\r")); | |
1909 | break; | |
1910 | case LCST ('\t'): | |
1911 | obstack_grow_wstr (output, LCST ("\\t")); | |
1912 | break; | |
1913 | case LCST ('\v'): | |
1914 | obstack_grow_wstr (output, LCST ("\\v")); | |
1915 | break; | |
1916 | default: | |
1917 | { | |
1918 | int i; | |
1919 | ||
1920 | for (i = 0; i + width <= orig_len; i += width) | |
1921 | { | |
1922 | char octal[30]; | |
1923 | ULONGEST value; | |
1924 | ||
1925 | value = extract_unsigned_integer (&orig[i], width, | |
1926 | byte_order); | |
1927 | /* If the value fits in 3 octal digits, print it that | |
1928 | way. Otherwise, print it as a hex escape. */ | |
1929 | if (value <= 0777) | |
1930 | sprintf (octal, "\\%.3o", (int) (value & 0777)); | |
1931 | else | |
1932 | sprintf (octal, "\\x%lx", (long) value); | |
1933 | append_string_as_wide (octal, output); | |
1934 | } | |
1935 | /* If we somehow have extra bytes, print them now. */ | |
1936 | while (i < orig_len) | |
1937 | { | |
1938 | char octal[5]; | |
1939 | ||
1940 | sprintf (octal, "\\%.3o", orig[i] & 0xff); | |
1941 | append_string_as_wide (octal, output); | |
1942 | ++i; | |
1943 | } | |
1944 | ||
1945 | *need_escapep = 1; | |
1946 | } | |
1947 | break; | |
1948 | } | |
1949 | } | |
1950 | } | |
1951 | ||
1952 | /* Print the character C on STREAM as part of the contents of a | |
1953 | literal string whose delimiter is QUOTER. ENCODING names the | |
1954 | encoding of C. */ | |
1955 | ||
1956 | void | |
1957 | generic_emit_char (int c, struct type *type, struct ui_file *stream, | |
1958 | int quoter, const char *encoding) | |
1959 | { | |
1960 | enum bfd_endian byte_order | |
1961 | = gdbarch_byte_order (get_type_arch (type)); | |
1962 | struct obstack wchar_buf, output; | |
1963 | struct cleanup *cleanups; | |
1964 | gdb_byte *buf; | |
1965 | struct wchar_iterator *iter; | |
1966 | int need_escape = 0; | |
1967 | ||
1968 | buf = alloca (TYPE_LENGTH (type)); | |
1969 | pack_long (buf, type, c); | |
1970 | ||
1971 | iter = make_wchar_iterator (buf, TYPE_LENGTH (type), | |
1972 | encoding, TYPE_LENGTH (type)); | |
1973 | cleanups = make_cleanup_wchar_iterator (iter); | |
1974 | ||
1975 | /* This holds the printable form of the wchar_t data. */ | |
1976 | obstack_init (&wchar_buf); | |
1977 | make_cleanup_obstack_free (&wchar_buf); | |
1978 | ||
1979 | while (1) | |
1980 | { | |
1981 | int num_chars; | |
1982 | gdb_wchar_t *chars; | |
1983 | const gdb_byte *buf; | |
1984 | size_t buflen; | |
1985 | int print_escape = 1; | |
1986 | enum wchar_iterate_result result; | |
1987 | ||
1988 | num_chars = wchar_iterate (iter, &result, &chars, &buf, &buflen); | |
1989 | if (num_chars < 0) | |
1990 | break; | |
1991 | if (num_chars > 0) | |
1992 | { | |
1993 | /* If all characters are printable, print them. Otherwise, | |
1994 | we're going to have to print an escape sequence. We | |
1995 | check all characters because we want to print the target | |
1996 | bytes in the escape sequence, and we don't know character | |
1997 | boundaries there. */ | |
1998 | int i; | |
1999 | ||
2000 | print_escape = 0; | |
2001 | for (i = 0; i < num_chars; ++i) | |
2002 | if (!wchar_printable (chars[i])) | |
2003 | { | |
2004 | print_escape = 1; | |
2005 | break; | |
2006 | } | |
2007 | ||
2008 | if (!print_escape) | |
2009 | { | |
2010 | for (i = 0; i < num_chars; ++i) | |
2011 | print_wchar (chars[i], buf, buflen, | |
2012 | TYPE_LENGTH (type), byte_order, | |
2013 | &wchar_buf, quoter, &need_escape); | |
2014 | } | |
2015 | } | |
2016 | ||
2017 | /* This handles the NUM_CHARS == 0 case as well. */ | |
2018 | if (print_escape) | |
2019 | print_wchar (gdb_WEOF, buf, buflen, TYPE_LENGTH (type), | |
2020 | byte_order, &wchar_buf, quoter, &need_escape); | |
2021 | } | |
2022 | ||
2023 | /* The output in the host encoding. */ | |
2024 | obstack_init (&output); | |
2025 | make_cleanup_obstack_free (&output); | |
2026 | ||
2027 | convert_between_encodings (INTERMEDIATE_ENCODING, host_charset (), | |
2028 | obstack_base (&wchar_buf), | |
2029 | obstack_object_size (&wchar_buf), | |
2030 | 1, &output, translit_char); | |
2031 | obstack_1grow (&output, '\0'); | |
2032 | ||
2033 | fputs_filtered (obstack_base (&output), stream); | |
2034 | ||
2035 | do_cleanups (cleanups); | |
2036 | } | |
2037 | ||
2038 | /* Print the character string STRING, printing at most LENGTH | |
2039 | characters. LENGTH is -1 if the string is nul terminated. TYPE is | |
2040 | the type of each character. OPTIONS holds the printing options; | |
2041 | printing stops early if the number hits print_max; repeat counts | |
2042 | are printed as appropriate. Print ellipses at the end if we had to | |
2043 | stop before printing LENGTH characters, or if FORCE_ELLIPSES. | |
2044 | QUOTE_CHAR is the character to print at each end of the string. If | |
2045 | C_STYLE_TERMINATOR is true, and the last character is 0, then it is | |
2046 | omitted. */ | |
2047 | ||
2048 | void | |
2049 | generic_printstr (struct ui_file *stream, struct type *type, | |
2050 | const gdb_byte *string, unsigned int length, | |
2051 | const char *encoding, int force_ellipses, | |
2052 | int quote_char, int c_style_terminator, | |
2053 | const struct value_print_options *options) | |
2054 | { | |
2055 | enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type)); | |
2056 | unsigned int i; | |
2057 | unsigned int things_printed = 0; | |
2058 | int in_quotes = 0; | |
2059 | int need_comma = 0; | |
2060 | int width = TYPE_LENGTH (type); | |
2061 | struct obstack wchar_buf, output; | |
2062 | struct cleanup *cleanup; | |
2063 | struct wchar_iterator *iter; | |
2064 | int finished = 0; | |
2065 | int need_escape = 0; | |
2066 | gdb_wchar_t wide_quote_char = gdb_btowc (quote_char); | |
2067 | ||
2068 | if (length == -1) | |
2069 | { | |
2070 | unsigned long current_char = 1; | |
2071 | ||
2072 | for (i = 0; current_char; ++i) | |
2073 | { | |
2074 | QUIT; | |
2075 | current_char = extract_unsigned_integer (string + i * width, | |
2076 | width, byte_order); | |
2077 | } | |
2078 | length = i; | |
2079 | } | |
2080 | ||
2081 | /* If the string was not truncated due to `set print elements', and | |
2082 | the last byte of it is a null, we don't print that, in | |
2083 | traditional C style. */ | |
2084 | if (c_style_terminator | |
2085 | && !force_ellipses | |
2086 | && length > 0 | |
2087 | && (extract_unsigned_integer (string + (length - 1) * width, | |
2088 | width, byte_order) == 0)) | |
2089 | length--; | |
2090 | ||
2091 | if (length == 0) | |
2092 | { | |
2093 | fputs_filtered ("\"\"", stream); | |
2094 | return; | |
2095 | } | |
2096 | ||
2097 | /* Arrange to iterate over the characters, in wchar_t form. */ | |
2098 | iter = make_wchar_iterator (string, length * width, encoding, width); | |
2099 | cleanup = make_cleanup_wchar_iterator (iter); | |
2100 | ||
2101 | /* WCHAR_BUF is the obstack we use to represent the string in | |
2102 | wchar_t form. */ | |
2103 | obstack_init (&wchar_buf); | |
2104 | make_cleanup_obstack_free (&wchar_buf); | |
2105 | ||
2106 | while (!finished && things_printed < options->print_max) | |
2107 | { | |
2108 | int num_chars; | |
2109 | enum wchar_iterate_result result; | |
2110 | gdb_wchar_t *chars; | |
2111 | const gdb_byte *buf; | |
2112 | size_t buflen; | |
2113 | ||
2114 | QUIT; | |
2115 | ||
2116 | if (need_comma) | |
2117 | { | |
2118 | obstack_grow_wstr (&wchar_buf, LCST (", ")); | |
2119 | need_comma = 0; | |
2120 | } | |
2121 | ||
2122 | num_chars = wchar_iterate (iter, &result, &chars, &buf, &buflen); | |
2123 | /* We only look at repetitions when we were able to convert a | |
2124 | single character in isolation. This makes the code simpler | |
2125 | and probably does the sensible thing in the majority of | |
2126 | cases. */ | |
2127 | while (num_chars == 1 && things_printed < options->print_max) | |
2128 | { | |
2129 | /* Count the number of repetitions. */ | |
2130 | unsigned int reps = 0; | |
2131 | gdb_wchar_t current_char = chars[0]; | |
2132 | const gdb_byte *orig_buf = buf; | |
2133 | int orig_len = buflen; | |
2134 | ||
2135 | if (need_comma) | |
2136 | { | |
2137 | obstack_grow_wstr (&wchar_buf, LCST (", ")); | |
2138 | need_comma = 0; | |
2139 | } | |
2140 | ||
2141 | while (num_chars == 1 && current_char == chars[0]) | |
2142 | { | |
2143 | num_chars = wchar_iterate (iter, &result, &chars, | |
2144 | &buf, &buflen); | |
2145 | ++reps; | |
2146 | } | |
2147 | ||
2148 | /* Emit CURRENT_CHAR according to the repetition count and | |
2149 | options. */ | |
2150 | if (reps > options->repeat_count_threshold) | |
2151 | { | |
2152 | if (in_quotes) | |
2153 | { | |
2154 | if (options->inspect_it) | |
2155 | obstack_grow_wstr (&wchar_buf, LCST ("\\")); | |
2156 | obstack_grow (&wchar_buf, &wide_quote_char, | |
2157 | sizeof (gdb_wchar_t)); | |
2158 | obstack_grow_wstr (&wchar_buf, LCST (", ")); | |
2159 | in_quotes = 0; | |
2160 | } | |
2161 | obstack_grow_wstr (&wchar_buf, LCST ("'")); | |
2162 | need_escape = 0; | |
2163 | print_wchar (current_char, orig_buf, orig_len, width, | |
2164 | byte_order, &wchar_buf, '\'', &need_escape); | |
2165 | obstack_grow_wstr (&wchar_buf, LCST ("'")); | |
2166 | { | |
2167 | /* Painful gyrations. */ | |
2168 | int j; | |
2169 | char *s = xstrprintf (_(" <repeats %u times>"), reps); | |
2170 | ||
2171 | for (j = 0; s[j]; ++j) | |
2172 | { | |
2173 | gdb_wchar_t w = gdb_btowc (s[j]); | |
2174 | obstack_grow (&wchar_buf, &w, sizeof (gdb_wchar_t)); | |
2175 | } | |
2176 | xfree (s); | |
2177 | } | |
2178 | things_printed += options->repeat_count_threshold; | |
2179 | need_comma = 1; | |
2180 | } | |
2181 | else | |
2182 | { | |
2183 | /* Saw the character one or more times, but fewer than | |
2184 | the repetition threshold. */ | |
2185 | if (!in_quotes) | |
2186 | { | |
2187 | if (options->inspect_it) | |
2188 | obstack_grow_wstr (&wchar_buf, LCST ("\\")); | |
2189 | obstack_grow (&wchar_buf, &wide_quote_char, | |
2190 | sizeof (gdb_wchar_t)); | |
2191 | in_quotes = 1; | |
2192 | need_escape = 0; | |
2193 | } | |
2194 | ||
2195 | while (reps-- > 0) | |
2196 | { | |
2197 | print_wchar (current_char, orig_buf, | |
2198 | orig_len, width, | |
2199 | byte_order, &wchar_buf, | |
2200 | quote_char, &need_escape); | |
2201 | ++things_printed; | |
2202 | } | |
2203 | } | |
2204 | } | |
2205 | ||
2206 | /* NUM_CHARS and the other outputs from wchar_iterate are valid | |
2207 | here regardless of which branch was taken above. */ | |
2208 | if (num_chars < 0) | |
2209 | { | |
2210 | /* Hit EOF. */ | |
2211 | finished = 1; | |
2212 | break; | |
2213 | } | |
2214 | ||
2215 | switch (result) | |
2216 | { | |
2217 | case wchar_iterate_invalid: | |
2218 | if (!in_quotes) | |
2219 | { | |
2220 | if (options->inspect_it) | |
2221 | obstack_grow_wstr (&wchar_buf, LCST ("\\")); | |
2222 | obstack_grow (&wchar_buf, &wide_quote_char, | |
2223 | sizeof (gdb_wchar_t)); | |
2224 | in_quotes = 1; | |
2225 | } | |
2226 | need_escape = 0; | |
2227 | print_wchar (gdb_WEOF, buf, buflen, width, byte_order, | |
2228 | &wchar_buf, quote_char, &need_escape); | |
2229 | break; | |
2230 | ||
2231 | case wchar_iterate_incomplete: | |
2232 | if (in_quotes) | |
2233 | { | |
2234 | if (options->inspect_it) | |
2235 | obstack_grow_wstr (&wchar_buf, LCST ("\\")); | |
2236 | obstack_grow (&wchar_buf, &wide_quote_char, | |
2237 | sizeof (gdb_wchar_t)); | |
2238 | obstack_grow_wstr (&wchar_buf, LCST (",")); | |
2239 | in_quotes = 0; | |
2240 | } | |
2241 | obstack_grow_wstr (&wchar_buf, | |
2242 | LCST (" <incomplete sequence ")); | |
2243 | print_wchar (gdb_WEOF, buf, buflen, width, | |
2244 | byte_order, &wchar_buf, | |
2245 | 0, &need_escape); | |
2246 | obstack_grow_wstr (&wchar_buf, LCST (">")); | |
2247 | finished = 1; | |
2248 | break; | |
2249 | } | |
2250 | } | |
2251 | ||
2252 | /* Terminate the quotes if necessary. */ | |
2253 | if (in_quotes) | |
2254 | { | |
2255 | if (options->inspect_it) | |
2256 | obstack_grow_wstr (&wchar_buf, LCST ("\\")); | |
2257 | obstack_grow (&wchar_buf, &wide_quote_char, | |
2258 | sizeof (gdb_wchar_t)); | |
2259 | } | |
2260 | ||
2261 | if (force_ellipses || !finished) | |
2262 | obstack_grow_wstr (&wchar_buf, LCST ("...")); | |
2263 | ||
2264 | /* OUTPUT is where we collect `char's for printing. */ | |
2265 | obstack_init (&output); | |
2266 | make_cleanup_obstack_free (&output); | |
2267 | ||
2268 | convert_between_encodings (INTERMEDIATE_ENCODING, host_charset (), | |
2269 | obstack_base (&wchar_buf), | |
2270 | obstack_object_size (&wchar_buf), | |
2271 | 1, &output, translit_char); | |
2272 | obstack_1grow (&output, '\0'); | |
2273 | ||
2274 | fputs_filtered (obstack_base (&output), stream); | |
2275 | ||
2276 | do_cleanups (cleanup); | |
2277 | } | |
2278 | ||
ae6a3a4c TJB |
2279 | /* Print a string from the inferior, starting at ADDR and printing up to LEN |
2280 | characters, of WIDTH bytes a piece, to STREAM. If LEN is -1, printing | |
2281 | stops at the first null byte, otherwise printing proceeds (including null | |
2282 | bytes) until either print_max or LEN characters have been printed, | |
09ca9e2e TT |
2283 | whichever is smaller. ENCODING is the name of the string's |
2284 | encoding. It can be NULL, in which case the target encoding is | |
2285 | assumed. */ | |
ae6a3a4c TJB |
2286 | |
2287 | int | |
09ca9e2e TT |
2288 | val_print_string (struct type *elttype, const char *encoding, |
2289 | CORE_ADDR addr, int len, | |
6c7a06a3 | 2290 | struct ui_file *stream, |
ae6a3a4c TJB |
2291 | const struct value_print_options *options) |
2292 | { | |
2293 | int force_ellipsis = 0; /* Force ellipsis to be printed if nonzero. */ | |
2294 | int errcode; /* Errno returned from bad reads. */ | |
581e13c1 | 2295 | int found_nul; /* Non-zero if we found the nul char. */ |
ae6a3a4c TJB |
2296 | unsigned int fetchlimit; /* Maximum number of chars to print. */ |
2297 | int bytes_read; | |
2298 | gdb_byte *buffer = NULL; /* Dynamically growable fetch buffer. */ | |
2299 | struct cleanup *old_chain = NULL; /* Top of the old cleanup chain. */ | |
5af949e3 | 2300 | struct gdbarch *gdbarch = get_type_arch (elttype); |
e17a4113 | 2301 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
6c7a06a3 | 2302 | int width = TYPE_LENGTH (elttype); |
ae6a3a4c TJB |
2303 | |
2304 | /* First we need to figure out the limit on the number of characters we are | |
2305 | going to attempt to fetch and print. This is actually pretty simple. If | |
2306 | LEN >= zero, then the limit is the minimum of LEN and print_max. If | |
2307 | LEN is -1, then the limit is print_max. This is true regardless of | |
2308 | whether print_max is zero, UINT_MAX (unlimited), or something in between, | |
2309 | because finding the null byte (or available memory) is what actually | |
2310 | limits the fetch. */ | |
2311 | ||
3e43a32a MS |
2312 | fetchlimit = (len == -1 ? options->print_max : min (len, |
2313 | options->print_max)); | |
ae6a3a4c | 2314 | |
e17a4113 UW |
2315 | errcode = read_string (addr, len, width, fetchlimit, byte_order, |
2316 | &buffer, &bytes_read); | |
ae6a3a4c TJB |
2317 | old_chain = make_cleanup (xfree, buffer); |
2318 | ||
2319 | addr += bytes_read; | |
c906108c | 2320 | |
3e43a32a MS |
2321 | /* We now have either successfully filled the buffer to fetchlimit, |
2322 | or terminated early due to an error or finding a null char when | |
2323 | LEN is -1. */ | |
ae6a3a4c TJB |
2324 | |
2325 | /* Determine found_nul by looking at the last character read. */ | |
e17a4113 UW |
2326 | found_nul = extract_unsigned_integer (buffer + bytes_read - width, width, |
2327 | byte_order) == 0; | |
c906108c SS |
2328 | if (len == -1 && !found_nul) |
2329 | { | |
777ea8f1 | 2330 | gdb_byte *peekbuf; |
c906108c | 2331 | |
ae6a3a4c | 2332 | /* We didn't find a NUL terminator we were looking for. Attempt |
c5aa993b JM |
2333 | to peek at the next character. If not successful, or it is not |
2334 | a null byte, then force ellipsis to be printed. */ | |
c906108c | 2335 | |
777ea8f1 | 2336 | peekbuf = (gdb_byte *) alloca (width); |
c906108c SS |
2337 | |
2338 | if (target_read_memory (addr, peekbuf, width) == 0 | |
e17a4113 | 2339 | && extract_unsigned_integer (peekbuf, width, byte_order) != 0) |
c906108c SS |
2340 | force_ellipsis = 1; |
2341 | } | |
ae6a3a4c | 2342 | else if ((len >= 0 && errcode != 0) || (len > bytes_read / width)) |
c906108c SS |
2343 | { |
2344 | /* Getting an error when we have a requested length, or fetching less | |
c5aa993b | 2345 | than the number of characters actually requested, always make us |
ae6a3a4c | 2346 | print ellipsis. */ |
c906108c SS |
2347 | force_ellipsis = 1; |
2348 | } | |
2349 | ||
c906108c SS |
2350 | /* If we get an error before fetching anything, don't print a string. |
2351 | But if we fetch something and then get an error, print the string | |
2352 | and then the error message. */ | |
ae6a3a4c | 2353 | if (errcode == 0 || bytes_read > 0) |
c906108c | 2354 | { |
79a45b7d | 2355 | if (options->addressprint) |
c906108c SS |
2356 | { |
2357 | fputs_filtered (" ", stream); | |
2358 | } | |
be759fcf | 2359 | LA_PRINT_STRING (stream, elttype, buffer, bytes_read / width, |
3a772aa4 | 2360 | encoding, force_ellipsis, options); |
c906108c SS |
2361 | } |
2362 | ||
2363 | if (errcode != 0) | |
2364 | { | |
2365 | if (errcode == EIO) | |
2366 | { | |
2367 | fprintf_filtered (stream, " <Address "); | |
5af949e3 | 2368 | fputs_filtered (paddress (gdbarch, addr), stream); |
c906108c SS |
2369 | fprintf_filtered (stream, " out of bounds>"); |
2370 | } | |
2371 | else | |
2372 | { | |
2373 | fprintf_filtered (stream, " <Error reading address "); | |
5af949e3 | 2374 | fputs_filtered (paddress (gdbarch, addr), stream); |
c906108c SS |
2375 | fprintf_filtered (stream, ": %s>", safe_strerror (errcode)); |
2376 | } | |
2377 | } | |
ae6a3a4c | 2378 | |
c906108c SS |
2379 | gdb_flush (stream); |
2380 | do_cleanups (old_chain); | |
ae6a3a4c TJB |
2381 | |
2382 | return (bytes_read / width); | |
c906108c | 2383 | } |
c906108c | 2384 | \f |
c5aa993b | 2385 | |
09e6485f PA |
2386 | /* The 'set input-radix' command writes to this auxiliary variable. |
2387 | If the requested radix is valid, INPUT_RADIX is updated; otherwise, | |
2388 | it is left unchanged. */ | |
2389 | ||
2390 | static unsigned input_radix_1 = 10; | |
2391 | ||
c906108c SS |
2392 | /* Validate an input or output radix setting, and make sure the user |
2393 | knows what they really did here. Radix setting is confusing, e.g. | |
2394 | setting the input radix to "10" never changes it! */ | |
2395 | ||
c906108c | 2396 | static void |
fba45db2 | 2397 | set_input_radix (char *args, int from_tty, struct cmd_list_element *c) |
c906108c | 2398 | { |
09e6485f | 2399 | set_input_radix_1 (from_tty, input_radix_1); |
c906108c SS |
2400 | } |
2401 | ||
c906108c | 2402 | static void |
fba45db2 | 2403 | set_input_radix_1 (int from_tty, unsigned radix) |
c906108c SS |
2404 | { |
2405 | /* We don't currently disallow any input radix except 0 or 1, which don't | |
2406 | make any mathematical sense. In theory, we can deal with any input | |
2407 | radix greater than 1, even if we don't have unique digits for every | |
2408 | value from 0 to radix-1, but in practice we lose on large radix values. | |
2409 | We should either fix the lossage or restrict the radix range more. | |
581e13c1 | 2410 | (FIXME). */ |
c906108c SS |
2411 | |
2412 | if (radix < 2) | |
2413 | { | |
09e6485f | 2414 | input_radix_1 = input_radix; |
8a3fe4f8 | 2415 | error (_("Nonsense input radix ``decimal %u''; input radix unchanged."), |
c906108c SS |
2416 | radix); |
2417 | } | |
09e6485f | 2418 | input_radix_1 = input_radix = radix; |
c906108c SS |
2419 | if (from_tty) |
2420 | { | |
3e43a32a MS |
2421 | printf_filtered (_("Input radix now set to " |
2422 | "decimal %u, hex %x, octal %o.\n"), | |
c906108c SS |
2423 | radix, radix, radix); |
2424 | } | |
2425 | } | |
2426 | ||
09e6485f PA |
2427 | /* The 'set output-radix' command writes to this auxiliary variable. |
2428 | If the requested radix is valid, OUTPUT_RADIX is updated, | |
2429 | otherwise, it is left unchanged. */ | |
2430 | ||
2431 | static unsigned output_radix_1 = 10; | |
2432 | ||
c906108c | 2433 | static void |
fba45db2 | 2434 | set_output_radix (char *args, int from_tty, struct cmd_list_element *c) |
c906108c | 2435 | { |
09e6485f | 2436 | set_output_radix_1 (from_tty, output_radix_1); |
c906108c SS |
2437 | } |
2438 | ||
2439 | static void | |
fba45db2 | 2440 | set_output_radix_1 (int from_tty, unsigned radix) |
c906108c SS |
2441 | { |
2442 | /* Validate the radix and disallow ones that we aren't prepared to | |
581e13c1 | 2443 | handle correctly, leaving the radix unchanged. */ |
c906108c SS |
2444 | switch (radix) |
2445 | { | |
2446 | case 16: | |
79a45b7d | 2447 | user_print_options.output_format = 'x'; /* hex */ |
c906108c SS |
2448 | break; |
2449 | case 10: | |
79a45b7d | 2450 | user_print_options.output_format = 0; /* decimal */ |
c906108c SS |
2451 | break; |
2452 | case 8: | |
79a45b7d | 2453 | user_print_options.output_format = 'o'; /* octal */ |
c906108c SS |
2454 | break; |
2455 | default: | |
09e6485f | 2456 | output_radix_1 = output_radix; |
3e43a32a MS |
2457 | error (_("Unsupported output radix ``decimal %u''; " |
2458 | "output radix unchanged."), | |
c906108c SS |
2459 | radix); |
2460 | } | |
09e6485f | 2461 | output_radix_1 = output_radix = radix; |
c906108c SS |
2462 | if (from_tty) |
2463 | { | |
3e43a32a MS |
2464 | printf_filtered (_("Output radix now set to " |
2465 | "decimal %u, hex %x, octal %o.\n"), | |
c906108c SS |
2466 | radix, radix, radix); |
2467 | } | |
2468 | } | |
2469 | ||
2470 | /* Set both the input and output radix at once. Try to set the output radix | |
2471 | first, since it has the most restrictive range. An radix that is valid as | |
2472 | an output radix is also valid as an input radix. | |
2473 | ||
2474 | It may be useful to have an unusual input radix. If the user wishes to | |
2475 | set an input radix that is not valid as an output radix, he needs to use | |
581e13c1 | 2476 | the 'set input-radix' command. */ |
c906108c SS |
2477 | |
2478 | static void | |
fba45db2 | 2479 | set_radix (char *arg, int from_tty) |
c906108c SS |
2480 | { |
2481 | unsigned radix; | |
2482 | ||
bb518678 | 2483 | radix = (arg == NULL) ? 10 : parse_and_eval_long (arg); |
c906108c SS |
2484 | set_output_radix_1 (0, radix); |
2485 | set_input_radix_1 (0, radix); | |
2486 | if (from_tty) | |
2487 | { | |
3e43a32a MS |
2488 | printf_filtered (_("Input and output radices now set to " |
2489 | "decimal %u, hex %x, octal %o.\n"), | |
c906108c SS |
2490 | radix, radix, radix); |
2491 | } | |
2492 | } | |
2493 | ||
581e13c1 | 2494 | /* Show both the input and output radices. */ |
c906108c | 2495 | |
c906108c | 2496 | static void |
fba45db2 | 2497 | show_radix (char *arg, int from_tty) |
c906108c SS |
2498 | { |
2499 | if (from_tty) | |
2500 | { | |
2501 | if (input_radix == output_radix) | |
2502 | { | |
3e43a32a MS |
2503 | printf_filtered (_("Input and output radices set to " |
2504 | "decimal %u, hex %x, octal %o.\n"), | |
c906108c SS |
2505 | input_radix, input_radix, input_radix); |
2506 | } | |
2507 | else | |
2508 | { | |
3e43a32a MS |
2509 | printf_filtered (_("Input radix set to decimal " |
2510 | "%u, hex %x, octal %o.\n"), | |
c906108c | 2511 | input_radix, input_radix, input_radix); |
3e43a32a MS |
2512 | printf_filtered (_("Output radix set to decimal " |
2513 | "%u, hex %x, octal %o.\n"), | |
c906108c SS |
2514 | output_radix, output_radix, output_radix); |
2515 | } | |
2516 | } | |
2517 | } | |
c906108c | 2518 | \f |
c5aa993b | 2519 | |
c906108c | 2520 | static void |
fba45db2 | 2521 | set_print (char *arg, int from_tty) |
c906108c SS |
2522 | { |
2523 | printf_unfiltered ( | |
c5aa993b | 2524 | "\"set print\" must be followed by the name of a print subcommand.\n"); |
c906108c SS |
2525 | help_list (setprintlist, "set print ", -1, gdb_stdout); |
2526 | } | |
2527 | ||
c906108c | 2528 | static void |
fba45db2 | 2529 | show_print (char *args, int from_tty) |
c906108c SS |
2530 | { |
2531 | cmd_show_list (showprintlist, from_tty, ""); | |
2532 | } | |
2533 | \f | |
2534 | void | |
fba45db2 | 2535 | _initialize_valprint (void) |
c906108c | 2536 | { |
c906108c | 2537 | add_prefix_cmd ("print", no_class, set_print, |
1bedd215 | 2538 | _("Generic command for setting how things print."), |
c906108c | 2539 | &setprintlist, "set print ", 0, &setlist); |
c5aa993b | 2540 | add_alias_cmd ("p", "print", no_class, 1, &setlist); |
581e13c1 | 2541 | /* Prefer set print to set prompt. */ |
c906108c SS |
2542 | add_alias_cmd ("pr", "print", no_class, 1, &setlist); |
2543 | ||
2544 | add_prefix_cmd ("print", no_class, show_print, | |
1bedd215 | 2545 | _("Generic command for showing print settings."), |
c906108c | 2546 | &showprintlist, "show print ", 0, &showlist); |
c5aa993b JM |
2547 | add_alias_cmd ("p", "print", no_class, 1, &showlist); |
2548 | add_alias_cmd ("pr", "print", no_class, 1, &showlist); | |
c906108c | 2549 | |
79a45b7d TT |
2550 | add_setshow_uinteger_cmd ("elements", no_class, |
2551 | &user_print_options.print_max, _("\ | |
35096d9d AC |
2552 | Set limit on string chars or array elements to print."), _("\ |
2553 | Show limit on string chars or array elements to print."), _("\ | |
2554 | \"set print elements 0\" causes there to be no limit."), | |
2555 | NULL, | |
920d2a44 | 2556 | show_print_max, |
35096d9d | 2557 | &setprintlist, &showprintlist); |
c906108c | 2558 | |
79a45b7d TT |
2559 | add_setshow_boolean_cmd ("null-stop", no_class, |
2560 | &user_print_options.stop_print_at_null, _("\ | |
5bf193a2 AC |
2561 | Set printing of char arrays to stop at first null char."), _("\ |
2562 | Show printing of char arrays to stop at first null char."), NULL, | |
2563 | NULL, | |
920d2a44 | 2564 | show_stop_print_at_null, |
5bf193a2 | 2565 | &setprintlist, &showprintlist); |
c906108c | 2566 | |
35096d9d | 2567 | add_setshow_uinteger_cmd ("repeats", no_class, |
79a45b7d | 2568 | &user_print_options.repeat_count_threshold, _("\ |
35096d9d AC |
2569 | Set threshold for repeated print elements."), _("\ |
2570 | Show threshold for repeated print elements."), _("\ | |
2571 | \"set print repeats 0\" causes all elements to be individually printed."), | |
2572 | NULL, | |
920d2a44 | 2573 | show_repeat_count_threshold, |
35096d9d | 2574 | &setprintlist, &showprintlist); |
c906108c | 2575 | |
79a45b7d TT |
2576 | add_setshow_boolean_cmd ("pretty", class_support, |
2577 | &user_print_options.prettyprint_structs, _("\ | |
5bf193a2 AC |
2578 | Set prettyprinting of structures."), _("\ |
2579 | Show prettyprinting of structures."), NULL, | |
2580 | NULL, | |
920d2a44 | 2581 | show_prettyprint_structs, |
5bf193a2 AC |
2582 | &setprintlist, &showprintlist); |
2583 | ||
79a45b7d TT |
2584 | add_setshow_boolean_cmd ("union", class_support, |
2585 | &user_print_options.unionprint, _("\ | |
5bf193a2 AC |
2586 | Set printing of unions interior to structures."), _("\ |
2587 | Show printing of unions interior to structures."), NULL, | |
2588 | NULL, | |
920d2a44 | 2589 | show_unionprint, |
5bf193a2 AC |
2590 | &setprintlist, &showprintlist); |
2591 | ||
79a45b7d TT |
2592 | add_setshow_boolean_cmd ("array", class_support, |
2593 | &user_print_options.prettyprint_arrays, _("\ | |
5bf193a2 AC |
2594 | Set prettyprinting of arrays."), _("\ |
2595 | Show prettyprinting of arrays."), NULL, | |
2596 | NULL, | |
920d2a44 | 2597 | show_prettyprint_arrays, |
5bf193a2 AC |
2598 | &setprintlist, &showprintlist); |
2599 | ||
79a45b7d TT |
2600 | add_setshow_boolean_cmd ("address", class_support, |
2601 | &user_print_options.addressprint, _("\ | |
5bf193a2 AC |
2602 | Set printing of addresses."), _("\ |
2603 | Show printing of addresses."), NULL, | |
2604 | NULL, | |
920d2a44 | 2605 | show_addressprint, |
5bf193a2 | 2606 | &setprintlist, &showprintlist); |
c906108c | 2607 | |
1e8fb976 PA |
2608 | add_setshow_zuinteger_cmd ("input-radix", class_support, &input_radix_1, |
2609 | _("\ | |
35096d9d AC |
2610 | Set default input radix for entering numbers."), _("\ |
2611 | Show default input radix for entering numbers."), NULL, | |
1e8fb976 PA |
2612 | set_input_radix, |
2613 | show_input_radix, | |
2614 | &setlist, &showlist); | |
35096d9d | 2615 | |
1e8fb976 PA |
2616 | add_setshow_zuinteger_cmd ("output-radix", class_support, &output_radix_1, |
2617 | _("\ | |
35096d9d AC |
2618 | Set default output radix for printing of values."), _("\ |
2619 | Show default output radix for printing of values."), NULL, | |
1e8fb976 PA |
2620 | set_output_radix, |
2621 | show_output_radix, | |
2622 | &setlist, &showlist); | |
c906108c | 2623 | |
cb1a6d5f AC |
2624 | /* The "set radix" and "show radix" commands are special in that |
2625 | they are like normal set and show commands but allow two normally | |
2626 | independent variables to be either set or shown with a single | |
b66df561 | 2627 | command. So the usual deprecated_add_set_cmd() and [deleted] |
581e13c1 | 2628 | add_show_from_set() commands aren't really appropriate. */ |
b66df561 AC |
2629 | /* FIXME: i18n: With the new add_setshow_integer command, that is no |
2630 | longer true - show can display anything. */ | |
1a966eab AC |
2631 | add_cmd ("radix", class_support, set_radix, _("\ |
2632 | Set default input and output number radices.\n\ | |
c906108c | 2633 | Use 'set input-radix' or 'set output-radix' to independently set each.\n\ |
1a966eab | 2634 | Without an argument, sets both radices back to the default value of 10."), |
c906108c | 2635 | &setlist); |
1a966eab AC |
2636 | add_cmd ("radix", class_support, show_radix, _("\ |
2637 | Show the default input and output number radices.\n\ | |
2638 | Use 'show input-radix' or 'show output-radix' to independently show each."), | |
c906108c SS |
2639 | &showlist); |
2640 | ||
e79af960 | 2641 | add_setshow_boolean_cmd ("array-indexes", class_support, |
79a45b7d | 2642 | &user_print_options.print_array_indexes, _("\ |
e79af960 JB |
2643 | Set printing of array indexes."), _("\ |
2644 | Show printing of array indexes"), NULL, NULL, show_print_array_indexes, | |
2645 | &setprintlist, &showprintlist); | |
c906108c | 2646 | } |