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