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