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