Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Support for printing Modula 2 values for GDB, the GNU debugger. |
a8d6eb4a | 2 | |
b811d2c2 | 3 | Copyright (C) 1986-2020 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" | |
72019c9c GM |
23 | #include "expression.h" |
24 | #include "value.h" | |
25 | #include "valprint.h" | |
26 | #include "language.h" | |
27 | #include "typeprint.h" | |
a8d6eb4a | 28 | #include "c-lang.h" |
72019c9c GM |
29 | #include "m2-lang.h" |
30 | #include "target.h" | |
7f6aba03 | 31 | #include "cli/cli-style.h" |
72019c9c | 32 | |
79a45b7d TT |
33 | static int print_unpacked_pointer (struct type *type, |
34 | CORE_ADDR address, CORE_ADDR addr, | |
35 | const struct value_print_options *options, | |
36 | struct ui_file *stream); | |
844781a1 | 37 | static void |
59fcdac6 | 38 | m2_print_array_contents (struct value *val, |
79a45b7d TT |
39 | struct ui_file *stream, int recurse, |
40 | const struct value_print_options *options, | |
41 | int len); | |
72019c9c GM |
42 | |
43 | ||
844781a1 GM |
44 | /* get_long_set_bounds - assigns the bounds of the long set to low and |
45 | high. */ | |
72019c9c GM |
46 | |
47 | int | |
48 | get_long_set_bounds (struct type *type, LONGEST *low, LONGEST *high) | |
49 | { | |
50 | int len, i; | |
51 | ||
52 | if (TYPE_CODE (type) == TYPE_CODE_STRUCT) | |
53 | { | |
54 | len = TYPE_NFIELDS (type); | |
55 | i = TYPE_N_BASECLASSES (type); | |
56 | if (len == 0) | |
57 | return 0; | |
58 | *low = TYPE_LOW_BOUND (TYPE_INDEX_TYPE (TYPE_FIELD_TYPE (type, i))); | |
59 | *high = TYPE_HIGH_BOUND (TYPE_INDEX_TYPE (TYPE_FIELD_TYPE (type, | |
60 | len-1))); | |
61 | return 1; | |
62 | } | |
63 | error (_("expecting long_set")); | |
64 | return 0; | |
65 | } | |
66 | ||
67 | static void | |
68 | m2_print_long_set (struct type *type, const gdb_byte *valaddr, | |
69 | int embedded_offset, CORE_ADDR address, | |
79a45b7d | 70 | struct ui_file *stream) |
72019c9c GM |
71 | { |
72 | int empty_set = 1; | |
73 | int element_seen = 0; | |
74 | LONGEST previous_low = 0; | |
75 | LONGEST previous_high= 0; | |
76 | LONGEST i, low_bound, high_bound; | |
77 | LONGEST field_low, field_high; | |
78 | struct type *range; | |
79 | int len, field; | |
80 | struct type *target; | |
81 | int bitval; | |
82 | ||
f168693b | 83 | type = check_typedef (type); |
72019c9c GM |
84 | |
85 | fprintf_filtered (stream, "{"); | |
86 | len = TYPE_NFIELDS (type); | |
87 | if (get_long_set_bounds (type, &low_bound, &high_bound)) | |
88 | { | |
89 | field = TYPE_N_BASECLASSES (type); | |
90 | range = TYPE_INDEX_TYPE (TYPE_FIELD_TYPE (type, field)); | |
91 | } | |
92 | else | |
93 | { | |
7f6aba03 TT |
94 | fprintf_styled (stream, metadata_style.style (), |
95 | " %s }", _("<unknown bounds of set>")); | |
72019c9c GM |
96 | return; |
97 | } | |
98 | ||
99 | target = TYPE_TARGET_TYPE (range); | |
72019c9c GM |
100 | |
101 | if (get_discrete_bounds (range, &field_low, &field_high) >= 0) | |
102 | { | |
103 | for (i = low_bound; i <= high_bound; i++) | |
104 | { | |
105 | bitval = value_bit_index (TYPE_FIELD_TYPE (type, field), | |
106 | (TYPE_FIELD_BITPOS (type, field) / 8) + | |
107 | valaddr + embedded_offset, i); | |
108 | if (bitval < 0) | |
109 | error (_("bit test is out of range")); | |
110 | else if (bitval > 0) | |
111 | { | |
112 | previous_high = i; | |
113 | if (! element_seen) | |
114 | { | |
115 | if (! empty_set) | |
116 | fprintf_filtered (stream, ", "); | |
117 | print_type_scalar (target, i, stream); | |
118 | empty_set = 0; | |
119 | element_seen = 1; | |
120 | previous_low = i; | |
121 | } | |
122 | } | |
123 | else | |
124 | { | |
125 | /* bit is not set */ | |
126 | if (element_seen) | |
127 | { | |
128 | if (previous_low+1 < previous_high) | |
129 | fprintf_filtered (stream, ".."); | |
130 | if (previous_low+1 < previous_high) | |
131 | print_type_scalar (target, previous_high, stream); | |
132 | element_seen = 0; | |
133 | } | |
134 | } | |
135 | if (i == field_high) | |
136 | { | |
137 | field++; | |
138 | if (field == len) | |
139 | break; | |
140 | range = TYPE_INDEX_TYPE (TYPE_FIELD_TYPE (type, field)); | |
141 | if (get_discrete_bounds (range, &field_low, &field_high) < 0) | |
142 | break; | |
143 | target = TYPE_TARGET_TYPE (range); | |
72019c9c GM |
144 | } |
145 | } | |
146 | if (element_seen) | |
147 | { | |
148 | if (previous_low+1 < previous_high) | |
149 | { | |
150 | fprintf_filtered (stream, ".."); | |
151 | print_type_scalar (target, previous_high, stream); | |
152 | } | |
153 | element_seen = 0; | |
154 | } | |
155 | fprintf_filtered (stream, "}"); | |
156 | } | |
157 | } | |
158 | ||
59fcdac6 TT |
159 | static void |
160 | m2_print_unbounded_array (struct value *value, | |
161 | struct ui_file *stream, int recurse, | |
162 | const struct value_print_options *options) | |
163 | { | |
164 | CORE_ADDR addr; | |
165 | LONGEST len; | |
166 | struct value *val; | |
167 | ||
168 | struct type *type = check_typedef (value_type (value)); | |
169 | const gdb_byte *valaddr = value_contents_for_printing (value); | |
170 | ||
171 | addr = unpack_pointer (TYPE_FIELD_TYPE (type, 0), | |
172 | (TYPE_FIELD_BITPOS (type, 0) / 8) + | |
173 | valaddr); | |
174 | ||
175 | val = value_at_lazy (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, 0)), | |
176 | addr); | |
177 | len = unpack_field_as_long (type, valaddr, 1); | |
178 | ||
179 | fprintf_filtered (stream, "{"); | |
180 | m2_print_array_contents (val, stream, recurse, options, len); | |
181 | fprintf_filtered (stream, ", HIGH = %d}", (int) len); | |
182 | } | |
183 | ||
844781a1 GM |
184 | static void |
185 | m2_print_unbounded_array (struct type *type, const gdb_byte *valaddr, | |
186 | int embedded_offset, CORE_ADDR address, | |
79a45b7d TT |
187 | struct ui_file *stream, int recurse, |
188 | const struct value_print_options *options) | |
844781a1 | 189 | { |
844781a1 GM |
190 | CORE_ADDR addr; |
191 | LONGEST len; | |
192 | struct value *val; | |
193 | ||
f168693b | 194 | type = check_typedef (type); |
844781a1 GM |
195 | |
196 | addr = unpack_pointer (TYPE_FIELD_TYPE (type, 0), | |
197 | (TYPE_FIELD_BITPOS (type, 0) / 8) + | |
198 | valaddr + embedded_offset); | |
199 | ||
200 | val = value_at_lazy (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, 0)), | |
201 | addr); | |
202 | len = unpack_field_as_long (type, valaddr + embedded_offset, 1); | |
203 | ||
204 | fprintf_filtered (stream, "{"); | |
59fcdac6 | 205 | m2_print_array_contents (val, stream, recurse, options, len); |
844781a1 GM |
206 | fprintf_filtered (stream, ", HIGH = %d}", (int) len); |
207 | } | |
208 | ||
79a45b7d | 209 | static int |
72019c9c GM |
210 | print_unpacked_pointer (struct type *type, |
211 | CORE_ADDR address, CORE_ADDR addr, | |
79a45b7d TT |
212 | const struct value_print_options *options, |
213 | struct ui_file *stream) | |
72019c9c | 214 | { |
50810684 | 215 | struct gdbarch *gdbarch = get_type_arch (type); |
72019c9c | 216 | struct type *elttype = check_typedef (TYPE_TARGET_TYPE (type)); |
b012acdd | 217 | int want_space = 0; |
72019c9c GM |
218 | |
219 | if (TYPE_CODE (elttype) == TYPE_CODE_FUNC) | |
220 | { | |
221 | /* Try to print what function it points to. */ | |
edf0c1b7 | 222 | print_function_pointer_address (options, gdbarch, addr, stream); |
72019c9c GM |
223 | /* Return value is irrelevant except for string pointers. */ |
224 | return 0; | |
225 | } | |
226 | ||
79a45b7d | 227 | if (options->addressprint && options->format != 's') |
b012acdd TT |
228 | { |
229 | fputs_filtered (paddress (gdbarch, address), stream); | |
230 | want_space = 1; | |
231 | } | |
72019c9c GM |
232 | |
233 | /* For a pointer to char or unsigned char, also print the string | |
234 | pointed to, unless pointer is null. */ | |
235 | ||
236 | if (TYPE_LENGTH (elttype) == 1 | |
237 | && TYPE_CODE (elttype) == TYPE_CODE_INT | |
79a45b7d | 238 | && (options->format == 0 || options->format == 's') |
72019c9c | 239 | && addr != 0) |
b012acdd TT |
240 | { |
241 | if (want_space) | |
242 | fputs_filtered (" ", stream); | |
243 | return val_print_string (TYPE_TARGET_TYPE (type), NULL, addr, -1, | |
244 | stream, options); | |
245 | } | |
72019c9c GM |
246 | |
247 | return 0; | |
248 | } | |
249 | ||
250 | static void | |
844781a1 GM |
251 | print_variable_at_address (struct type *type, |
252 | const gdb_byte *valaddr, | |
79a45b7d TT |
253 | struct ui_file *stream, |
254 | int recurse, | |
255 | const struct value_print_options *options) | |
72019c9c | 256 | { |
5af949e3 | 257 | struct gdbarch *gdbarch = get_type_arch (type); |
72019c9c GM |
258 | CORE_ADDR addr = unpack_pointer (type, valaddr); |
259 | struct type *elttype = check_typedef (TYPE_TARGET_TYPE (type)); | |
260 | ||
261 | fprintf_filtered (stream, "["); | |
5af949e3 | 262 | fputs_filtered (paddress (gdbarch, addr), stream); |
72019c9c GM |
263 | fprintf_filtered (stream, "] : "); |
264 | ||
265 | if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF) | |
266 | { | |
267 | struct value *deref_val = | |
d8631d21 | 268 | value_at (TYPE_TARGET_TYPE (type), unpack_pointer (type, valaddr)); |
b8d56208 | 269 | |
79a45b7d | 270 | common_val_print (deref_val, stream, recurse, options, current_language); |
72019c9c GM |
271 | } |
272 | else | |
273 | fputs_filtered ("???", stream); | |
274 | } | |
275 | ||
844781a1 GM |
276 | |
277 | /* m2_print_array_contents - prints out the contents of an | |
278 | array up to a max_print values. | |
279 | It prints arrays of char as a string | |
280 | and all other data types as comma | |
281 | separated values. */ | |
282 | ||
283 | static void | |
59fcdac6 | 284 | m2_print_array_contents (struct value *val, |
79a45b7d TT |
285 | struct ui_file *stream, int recurse, |
286 | const struct value_print_options *options, | |
287 | int len) | |
844781a1 | 288 | { |
59fcdac6 | 289 | struct type *type = check_typedef (value_type (val)); |
844781a1 GM |
290 | |
291 | if (TYPE_LENGTH (type) > 0) | |
292 | { | |
2a998fc0 | 293 | if (options->prettyformat_arrays) |
844781a1 GM |
294 | print_spaces_filtered (2 + 2 * recurse, stream); |
295 | /* For an array of chars, print with string syntax. */ | |
354ecfd5 | 296 | if (TYPE_LENGTH (type) == 1 && |
844781a1 GM |
297 | ((TYPE_CODE (type) == TYPE_CODE_INT) |
298 | || ((current_language->la_language == language_m2) | |
299 | && (TYPE_CODE (type) == TYPE_CODE_CHAR))) | |
79a45b7d | 300 | && (options->format == 0 || options->format == 's')) |
59fcdac6 TT |
301 | val_print_string (type, NULL, value_address (val), len+1, stream, |
302 | options); | |
844781a1 GM |
303 | else |
304 | { | |
305 | fprintf_filtered (stream, "{"); | |
59fcdac6 | 306 | value_print_array_elements (val, stream, recurse, options, 0); |
844781a1 GM |
307 | fprintf_filtered (stream, "}"); |
308 | } | |
309 | } | |
310 | } | |
311 | ||
e88acd96 TT |
312 | /* Decorations for Modula 2. */ |
313 | ||
314 | static const struct generic_val_print_decorations m2_decorations = | |
315 | { | |
316 | "", | |
317 | " + ", | |
318 | " * I", | |
319 | "TRUE", | |
320 | "FALSE", | |
00272ec4 TT |
321 | "void", |
322 | "{", | |
323 | "}" | |
e88acd96 | 324 | }; |
844781a1 | 325 | |
32b72a42 | 326 | /* See val_print for a description of the various parameters of this |
d3eab38a | 327 | function; they are identical. */ |
c906108c | 328 | |
d3eab38a | 329 | void |
e8b24d9f | 330 | m2_val_print (struct type *type, int embedded_offset, |
79a45b7d | 331 | CORE_ADDR address, struct ui_file *stream, int recurse, |
e8b24d9f | 332 | struct value *original_value, |
79a45b7d | 333 | const struct value_print_options *options) |
c906108c | 334 | { |
72019c9c GM |
335 | unsigned len; |
336 | struct type *elttype; | |
72019c9c | 337 | CORE_ADDR addr; |
e8b24d9f | 338 | const gdb_byte *valaddr = value_contents_for_printing (original_value); |
72019c9c | 339 | |
f168693b | 340 | type = check_typedef (type); |
72019c9c GM |
341 | switch (TYPE_CODE (type)) |
342 | { | |
343 | case TYPE_CODE_ARRAY: | |
344 | if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0) | |
345 | { | |
346 | elttype = check_typedef (TYPE_TARGET_TYPE (type)); | |
354ecfd5 | 347 | len = TYPE_LENGTH (type) / TYPE_LENGTH (elttype); |
2a998fc0 | 348 | if (options->prettyformat_arrays) |
72019c9c GM |
349 | print_spaces_filtered (2 + 2 * recurse, stream); |
350 | /* For an array of chars, print with string syntax. */ | |
354ecfd5 | 351 | if (TYPE_LENGTH (elttype) == 1 && |
72019c9c GM |
352 | ((TYPE_CODE (elttype) == TYPE_CODE_INT) |
353 | || ((current_language->la_language == language_m2) | |
354 | && (TYPE_CODE (elttype) == TYPE_CODE_CHAR))) | |
79a45b7d | 355 | && (options->format == 0 || options->format == 's')) |
72019c9c GM |
356 | { |
357 | /* If requested, look for the first null char and only print | |
358 | elements up to it. */ | |
79a45b7d | 359 | if (options->stop_print_at_null) |
72019c9c GM |
360 | { |
361 | unsigned int temp_len; | |
362 | ||
025bb325 | 363 | /* Look for a NULL char. */ |
72019c9c GM |
364 | for (temp_len = 0; |
365 | (valaddr + embedded_offset)[temp_len] | |
79a45b7d | 366 | && temp_len < len && temp_len < options->print_max; |
72019c9c GM |
367 | temp_len++); |
368 | len = temp_len; | |
369 | } | |
370 | ||
6c7a06a3 | 371 | LA_PRINT_STRING (stream, TYPE_TARGET_TYPE (type), |
be759fcf PM |
372 | valaddr + embedded_offset, len, NULL, |
373 | 0, options); | |
72019c9c GM |
374 | } |
375 | else | |
376 | { | |
377 | fprintf_filtered (stream, "{"); | |
e8b24d9f | 378 | val_print_array_elements (type, embedded_offset, |
025bb325 MS |
379 | address, stream, |
380 | recurse, original_value, | |
0e03807e | 381 | options, 0); |
72019c9c GM |
382 | fprintf_filtered (stream, "}"); |
383 | } | |
384 | break; | |
385 | } | |
386 | /* Array of unspecified length: treat like pointer to first elt. */ | |
79a45b7d | 387 | print_unpacked_pointer (type, address, address, options, stream); |
72019c9c GM |
388 | break; |
389 | ||
390 | case TYPE_CODE_PTR: | |
391 | if (TYPE_CONST (type)) | |
392 | print_variable_at_address (type, valaddr + embedded_offset, | |
79a45b7d TT |
393 | stream, recurse, options); |
394 | else if (options->format && options->format != 's') | |
e8b24d9f | 395 | val_print_scalar_formatted (type, embedded_offset, |
ab2188aa | 396 | original_value, options, 0, stream); |
72019c9c GM |
397 | else |
398 | { | |
399 | addr = unpack_pointer (type, valaddr + embedded_offset); | |
79a45b7d | 400 | print_unpacked_pointer (type, addr, address, options, stream); |
72019c9c GM |
401 | } |
402 | break; | |
403 | ||
72019c9c | 404 | case TYPE_CODE_UNION: |
79a45b7d | 405 | if (recurse && !options->unionprint) |
72019c9c GM |
406 | { |
407 | fprintf_filtered (stream, "{...}"); | |
408 | break; | |
409 | } | |
410 | /* Fall through. */ | |
411 | case TYPE_CODE_STRUCT: | |
412 | if (m2_is_long_set (type)) | |
413 | m2_print_long_set (type, valaddr, embedded_offset, address, | |
79a45b7d | 414 | stream); |
844781a1 GM |
415 | else if (m2_is_unbounded_array (type)) |
416 | m2_print_unbounded_array (type, valaddr, embedded_offset, | |
79a45b7d | 417 | address, stream, recurse, options); |
72019c9c | 418 | else |
65408fa6 | 419 | cp_print_value_fields (type, type, embedded_offset, |
0e03807e TT |
420 | address, stream, recurse, original_value, |
421 | options, NULL, 0); | |
72019c9c GM |
422 | break; |
423 | ||
72019c9c GM |
424 | case TYPE_CODE_SET: |
425 | elttype = TYPE_INDEX_TYPE (type); | |
f168693b | 426 | elttype = check_typedef (elttype); |
72019c9c GM |
427 | if (TYPE_STUB (elttype)) |
428 | { | |
7f6aba03 TT |
429 | fprintf_styled (stream, metadata_style.style (), |
430 | _("<incomplete type>")); | |
72019c9c GM |
431 | break; |
432 | } | |
433 | else | |
434 | { | |
435 | struct type *range = elttype; | |
436 | LONGEST low_bound, high_bound; | |
437 | int i; | |
72019c9c GM |
438 | int need_comma = 0; |
439 | ||
6b1755ce | 440 | fputs_filtered ("{", stream); |
72019c9c GM |
441 | |
442 | i = get_discrete_bounds (range, &low_bound, &high_bound); | |
443 | maybe_bad_bstring: | |
444 | if (i < 0) | |
445 | { | |
7f6aba03 TT |
446 | fputs_styled (_("<error value>"), metadata_style.style (), |
447 | stream); | |
72019c9c GM |
448 | goto done; |
449 | } | |
450 | ||
451 | for (i = low_bound; i <= high_bound; i++) | |
452 | { | |
453 | int element = value_bit_index (type, valaddr + embedded_offset, | |
454 | i); | |
b8d56208 | 455 | |
72019c9c GM |
456 | if (element < 0) |
457 | { | |
458 | i = element; | |
459 | goto maybe_bad_bstring; | |
460 | } | |
6b1755ce | 461 | if (element) |
72019c9c GM |
462 | { |
463 | if (need_comma) | |
464 | fputs_filtered (", ", stream); | |
465 | print_type_scalar (range, i, stream); | |
466 | need_comma = 1; | |
467 | ||
468 | if (i + 1 <= high_bound | |
469 | && value_bit_index (type, valaddr + embedded_offset, | |
470 | ++i)) | |
471 | { | |
472 | int j = i; | |
b8d56208 | 473 | |
72019c9c GM |
474 | fputs_filtered ("..", stream); |
475 | while (i + 1 <= high_bound | |
476 | && value_bit_index (type, | |
477 | valaddr + embedded_offset, | |
478 | ++i)) | |
479 | j = i; | |
480 | print_type_scalar (range, j, stream); | |
481 | } | |
482 | } | |
483 | } | |
484 | done: | |
6b1755ce | 485 | fputs_filtered ("}", stream); |
72019c9c GM |
486 | } |
487 | break; | |
488 | ||
e88acd96 TT |
489 | case TYPE_CODE_RANGE: |
490 | if (TYPE_LENGTH (type) == TYPE_LENGTH (TYPE_TARGET_TYPE (type))) | |
491 | { | |
e8b24d9f | 492 | m2_val_print (TYPE_TARGET_TYPE (type), embedded_offset, |
e88acd96 TT |
493 | address, stream, recurse, original_value, options); |
494 | break; | |
495 | } | |
0c9c3474 | 496 | /* FIXME: create_static_range_type does not set the unsigned bit in a |
e88acd96 TT |
497 | range type (I think it probably should copy it from the target |
498 | type), so we won't print values which are too large to | |
499 | fit in a signed integer correctly. */ | |
500 | /* FIXME: Doesn't handle ranges of enums correctly. (Can't just | |
501 | print with the target type, though, because the size of our type | |
502 | and the target type might differ). */ | |
503 | /* FALLTHROUGH */ | |
72019c9c | 504 | |
e88acd96 TT |
505 | case TYPE_CODE_REF: |
506 | case TYPE_CODE_ENUM: | |
507 | case TYPE_CODE_FUNC: | |
508 | case TYPE_CODE_INT: | |
509 | case TYPE_CODE_FLT: | |
510 | case TYPE_CODE_METHOD: | |
511 | case TYPE_CODE_VOID: | |
72019c9c | 512 | case TYPE_CODE_ERROR: |
72019c9c | 513 | case TYPE_CODE_UNDEF: |
e88acd96 TT |
514 | case TYPE_CODE_BOOL: |
515 | case TYPE_CODE_CHAR: | |
72019c9c | 516 | default: |
e8b24d9f | 517 | generic_val_print (type, embedded_offset, address, |
e88acd96 TT |
518 | stream, recurse, original_value, options, |
519 | &m2_decorations); | |
520 | break; | |
72019c9c | 521 | } |
c906108c | 522 | } |
62c4663d TT |
523 | |
524 | /* See m2-lang.h. */ | |
525 | ||
526 | void | |
527 | m2_value_print_inner (struct value *val, struct ui_file *stream, int recurse, | |
528 | const struct value_print_options *options) | |
529 | { | |
59fcdac6 TT |
530 | unsigned len; |
531 | struct type *elttype; | |
532 | CORE_ADDR addr; | |
533 | const gdb_byte *valaddr = value_contents_for_printing (val); | |
534 | const CORE_ADDR address = value_address (val); | |
535 | ||
536 | struct type *type = check_typedef (value_type (val)); | |
537 | switch (TYPE_CODE (type)) | |
538 | { | |
539 | case TYPE_CODE_ARRAY: | |
540 | if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0) | |
541 | { | |
542 | elttype = check_typedef (TYPE_TARGET_TYPE (type)); | |
543 | len = TYPE_LENGTH (type) / TYPE_LENGTH (elttype); | |
544 | if (options->prettyformat_arrays) | |
545 | print_spaces_filtered (2 + 2 * recurse, stream); | |
546 | /* For an array of chars, print with string syntax. */ | |
547 | if (TYPE_LENGTH (elttype) == 1 && | |
548 | ((TYPE_CODE (elttype) == TYPE_CODE_INT) | |
549 | || ((current_language->la_language == language_m2) | |
550 | && (TYPE_CODE (elttype) == TYPE_CODE_CHAR))) | |
551 | && (options->format == 0 || options->format == 's')) | |
552 | { | |
553 | /* If requested, look for the first null char and only print | |
554 | elements up to it. */ | |
555 | if (options->stop_print_at_null) | |
556 | { | |
557 | unsigned int temp_len; | |
558 | ||
559 | /* Look for a NULL char. */ | |
560 | for (temp_len = 0; | |
561 | (valaddr[temp_len] | |
562 | && temp_len < len && temp_len < options->print_max); | |
563 | temp_len++); | |
564 | len = temp_len; | |
565 | } | |
566 | ||
567 | LA_PRINT_STRING (stream, TYPE_TARGET_TYPE (type), | |
568 | valaddr, len, NULL, 0, options); | |
569 | } | |
570 | else | |
571 | { | |
572 | fprintf_filtered (stream, "{"); | |
573 | value_print_array_elements (val, stream, recurse, | |
574 | options, 0); | |
575 | fprintf_filtered (stream, "}"); | |
576 | } | |
577 | break; | |
578 | } | |
579 | /* Array of unspecified length: treat like pointer to first elt. */ | |
580 | print_unpacked_pointer (type, address, address, options, stream); | |
581 | break; | |
582 | ||
583 | case TYPE_CODE_PTR: | |
584 | if (TYPE_CONST (type)) | |
585 | print_variable_at_address (type, valaddr, stream, recurse, options); | |
586 | else if (options->format && options->format != 's') | |
587 | value_print_scalar_formatted (val, options, 0, stream); | |
588 | else | |
589 | { | |
590 | addr = unpack_pointer (type, valaddr); | |
591 | print_unpacked_pointer (type, addr, address, options, stream); | |
592 | } | |
593 | break; | |
594 | ||
595 | case TYPE_CODE_UNION: | |
596 | if (recurse && !options->unionprint) | |
597 | { | |
598 | fprintf_filtered (stream, "{...}"); | |
599 | break; | |
600 | } | |
601 | /* Fall through. */ | |
602 | case TYPE_CODE_STRUCT: | |
603 | if (m2_is_long_set (type)) | |
604 | m2_print_long_set (type, valaddr, 0, address, stream); | |
605 | else if (m2_is_unbounded_array (type)) | |
606 | m2_print_unbounded_array (val, stream, recurse, options); | |
607 | else | |
64b653ca | 608 | cp_print_value_fields (val, stream, recurse, options, NULL, 0); |
59fcdac6 TT |
609 | break; |
610 | ||
611 | case TYPE_CODE_SET: | |
612 | elttype = TYPE_INDEX_TYPE (type); | |
613 | elttype = check_typedef (elttype); | |
614 | if (TYPE_STUB (elttype)) | |
615 | { | |
616 | fprintf_styled (stream, metadata_style.style (), | |
617 | _("<incomplete type>")); | |
618 | break; | |
619 | } | |
620 | else | |
621 | { | |
622 | struct type *range = elttype; | |
623 | LONGEST low_bound, high_bound; | |
624 | int i; | |
625 | int need_comma = 0; | |
626 | ||
627 | fputs_filtered ("{", stream); | |
628 | ||
629 | i = get_discrete_bounds (range, &low_bound, &high_bound); | |
630 | maybe_bad_bstring: | |
631 | if (i < 0) | |
632 | { | |
633 | fputs_styled (_("<error value>"), metadata_style.style (), | |
634 | stream); | |
635 | goto done; | |
636 | } | |
637 | ||
638 | for (i = low_bound; i <= high_bound; i++) | |
639 | { | |
640 | int element = value_bit_index (type, valaddr, i); | |
641 | ||
642 | if (element < 0) | |
643 | { | |
644 | i = element; | |
645 | goto maybe_bad_bstring; | |
646 | } | |
647 | if (element) | |
648 | { | |
649 | if (need_comma) | |
650 | fputs_filtered (", ", stream); | |
651 | print_type_scalar (range, i, stream); | |
652 | need_comma = 1; | |
653 | ||
654 | if (i + 1 <= high_bound | |
655 | && value_bit_index (type, valaddr, ++i)) | |
656 | { | |
657 | int j = i; | |
658 | ||
659 | fputs_filtered ("..", stream); | |
660 | while (i + 1 <= high_bound | |
661 | && value_bit_index (type, valaddr, ++i)) | |
662 | j = i; | |
663 | print_type_scalar (range, j, stream); | |
664 | } | |
665 | } | |
666 | } | |
667 | done: | |
668 | fputs_filtered ("}", stream); | |
669 | } | |
670 | break; | |
671 | ||
672 | case TYPE_CODE_RANGE: | |
673 | if (TYPE_LENGTH (type) == TYPE_LENGTH (TYPE_TARGET_TYPE (type))) | |
674 | { | |
675 | struct value *v = value_cast (TYPE_TARGET_TYPE (type), val); | |
676 | m2_value_print_inner (v, stream, recurse, options); | |
677 | break; | |
678 | } | |
679 | /* FIXME: create_static_range_type does not set the unsigned bit in a | |
680 | range type (I think it probably should copy it from the target | |
681 | type), so we won't print values which are too large to | |
682 | fit in a signed integer correctly. */ | |
683 | /* FIXME: Doesn't handle ranges of enums correctly. (Can't just | |
684 | print with the target type, though, because the size of our type | |
685 | and the target type might differ). */ | |
686 | /* FALLTHROUGH */ | |
687 | ||
688 | case TYPE_CODE_REF: | |
689 | case TYPE_CODE_ENUM: | |
690 | case TYPE_CODE_FUNC: | |
691 | case TYPE_CODE_INT: | |
692 | case TYPE_CODE_FLT: | |
693 | case TYPE_CODE_METHOD: | |
694 | case TYPE_CODE_VOID: | |
695 | case TYPE_CODE_ERROR: | |
696 | case TYPE_CODE_UNDEF: | |
697 | case TYPE_CODE_BOOL: | |
698 | case TYPE_CODE_CHAR: | |
699 | default: | |
700 | generic_value_print (val, stream, recurse, options, &m2_decorations); | |
701 | break; | |
702 | } | |
62c4663d | 703 | } |