Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Support for printing Modula 2 values for GDB, the GNU debugger. |
a8d6eb4a | 2 | |
0b302171 JB |
3 | Copyright (C) 1986, 1988-1989, 1991-1992, 1996, 1998, 2000, 2005-2012 |
4 | Free Software Foundation, Inc. | |
c906108c | 5 | |
c5aa993b | 6 | This file is part of GDB. |
c906108c | 7 | |
c5aa993b JM |
8 | This program is free software; you can redistribute it and/or modify |
9 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 10 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 11 | (at your option) any later version. |
c906108c | 12 | |
c5aa993b JM |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
c906108c | 17 | |
c5aa993b | 18 | You should have received a copy of the GNU General Public License |
a9762ec7 | 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
20 | |
21 | #include "defs.h" | |
c906108c SS |
22 | #include "symtab.h" |
23 | #include "gdbtypes.h" | |
72019c9c GM |
24 | #include "expression.h" |
25 | #include "value.h" | |
26 | #include "valprint.h" | |
27 | #include "language.h" | |
28 | #include "typeprint.h" | |
a8d6eb4a | 29 | #include "c-lang.h" |
72019c9c GM |
30 | #include "m2-lang.h" |
31 | #include "target.h" | |
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 GM |
37 | static void |
38 | m2_print_array_contents (struct type *type, const gdb_byte *valaddr, | |
39 | int embedded_offset, CORE_ADDR address, | |
79a45b7d | 40 | struct ui_file *stream, int recurse, |
0e03807e | 41 | const struct value *val, |
79a45b7d TT |
42 | const struct value_print_options *options, |
43 | int len); | |
72019c9c GM |
44 | |
45 | ||
844781a1 GM |
46 | /* get_long_set_bounds - assigns the bounds of the long set to low and |
47 | high. */ | |
72019c9c GM |
48 | |
49 | int | |
50 | get_long_set_bounds (struct type *type, LONGEST *low, LONGEST *high) | |
51 | { | |
52 | int len, i; | |
53 | ||
54 | if (TYPE_CODE (type) == TYPE_CODE_STRUCT) | |
55 | { | |
56 | len = TYPE_NFIELDS (type); | |
57 | i = TYPE_N_BASECLASSES (type); | |
58 | if (len == 0) | |
59 | return 0; | |
60 | *low = TYPE_LOW_BOUND (TYPE_INDEX_TYPE (TYPE_FIELD_TYPE (type, i))); | |
61 | *high = TYPE_HIGH_BOUND (TYPE_INDEX_TYPE (TYPE_FIELD_TYPE (type, | |
62 | len-1))); | |
63 | return 1; | |
64 | } | |
65 | error (_("expecting long_set")); | |
66 | return 0; | |
67 | } | |
68 | ||
69 | static void | |
70 | m2_print_long_set (struct type *type, const gdb_byte *valaddr, | |
71 | int embedded_offset, CORE_ADDR address, | |
79a45b7d | 72 | struct ui_file *stream) |
72019c9c GM |
73 | { |
74 | int empty_set = 1; | |
75 | int element_seen = 0; | |
76 | LONGEST previous_low = 0; | |
77 | LONGEST previous_high= 0; | |
78 | LONGEST i, low_bound, high_bound; | |
79 | LONGEST field_low, field_high; | |
80 | struct type *range; | |
81 | int len, field; | |
82 | struct type *target; | |
83 | int bitval; | |
84 | ||
85 | CHECK_TYPEDEF (type); | |
86 | ||
87 | fprintf_filtered (stream, "{"); | |
88 | len = TYPE_NFIELDS (type); | |
89 | if (get_long_set_bounds (type, &low_bound, &high_bound)) | |
90 | { | |
91 | field = TYPE_N_BASECLASSES (type); | |
92 | range = TYPE_INDEX_TYPE (TYPE_FIELD_TYPE (type, field)); | |
93 | } | |
94 | else | |
95 | { | |
96 | fprintf_filtered (stream, " %s }", _("<unknown bounds of set>")); | |
97 | return; | |
98 | } | |
99 | ||
100 | target = TYPE_TARGET_TYPE (range); | |
72019c9c GM |
101 | |
102 | if (get_discrete_bounds (range, &field_low, &field_high) >= 0) | |
103 | { | |
104 | for (i = low_bound; i <= high_bound; i++) | |
105 | { | |
106 | bitval = value_bit_index (TYPE_FIELD_TYPE (type, field), | |
107 | (TYPE_FIELD_BITPOS (type, field) / 8) + | |
108 | valaddr + embedded_offset, i); | |
109 | if (bitval < 0) | |
110 | error (_("bit test is out of range")); | |
111 | else if (bitval > 0) | |
112 | { | |
113 | previous_high = i; | |
114 | if (! element_seen) | |
115 | { | |
116 | if (! empty_set) | |
117 | fprintf_filtered (stream, ", "); | |
118 | print_type_scalar (target, i, stream); | |
119 | empty_set = 0; | |
120 | element_seen = 1; | |
121 | previous_low = i; | |
122 | } | |
123 | } | |
124 | else | |
125 | { | |
126 | /* bit is not set */ | |
127 | if (element_seen) | |
128 | { | |
129 | if (previous_low+1 < previous_high) | |
130 | fprintf_filtered (stream, ".."); | |
131 | if (previous_low+1 < previous_high) | |
132 | print_type_scalar (target, previous_high, stream); | |
133 | element_seen = 0; | |
134 | } | |
135 | } | |
136 | if (i == field_high) | |
137 | { | |
138 | field++; | |
139 | if (field == len) | |
140 | break; | |
141 | range = TYPE_INDEX_TYPE (TYPE_FIELD_TYPE (type, field)); | |
142 | if (get_discrete_bounds (range, &field_low, &field_high) < 0) | |
143 | break; | |
144 | target = TYPE_TARGET_TYPE (range); | |
72019c9c GM |
145 | } |
146 | } | |
147 | if (element_seen) | |
148 | { | |
149 | if (previous_low+1 < previous_high) | |
150 | { | |
151 | fprintf_filtered (stream, ".."); | |
152 | print_type_scalar (target, previous_high, stream); | |
153 | } | |
154 | element_seen = 0; | |
155 | } | |
156 | fprintf_filtered (stream, "}"); | |
157 | } | |
158 | } | |
159 | ||
844781a1 GM |
160 | static void |
161 | m2_print_unbounded_array (struct type *type, const gdb_byte *valaddr, | |
162 | int embedded_offset, CORE_ADDR address, | |
79a45b7d TT |
163 | struct ui_file *stream, int recurse, |
164 | const struct value_print_options *options) | |
844781a1 GM |
165 | { |
166 | struct type *content_type; | |
167 | CORE_ADDR addr; | |
168 | LONGEST len; | |
169 | struct value *val; | |
170 | ||
171 | CHECK_TYPEDEF (type); | |
172 | content_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, 0)); | |
173 | ||
174 | addr = unpack_pointer (TYPE_FIELD_TYPE (type, 0), | |
175 | (TYPE_FIELD_BITPOS (type, 0) / 8) + | |
176 | valaddr + embedded_offset); | |
177 | ||
178 | val = value_at_lazy (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, 0)), | |
179 | addr); | |
180 | len = unpack_field_as_long (type, valaddr + embedded_offset, 1); | |
181 | ||
182 | fprintf_filtered (stream, "{"); | |
66d61a4c PA |
183 | m2_print_array_contents (value_type (val), |
184 | value_contents_for_printing (val), | |
844781a1 | 185 | value_embedded_offset (val), addr, stream, |
66d61a4c | 186 | recurse, val, options, len); |
844781a1 GM |
187 | fprintf_filtered (stream, ", HIGH = %d}", (int) len); |
188 | } | |
189 | ||
79a45b7d | 190 | static int |
72019c9c GM |
191 | print_unpacked_pointer (struct type *type, |
192 | CORE_ADDR address, CORE_ADDR addr, | |
79a45b7d TT |
193 | const struct value_print_options *options, |
194 | struct ui_file *stream) | |
72019c9c | 195 | { |
50810684 | 196 | struct gdbarch *gdbarch = get_type_arch (type); |
72019c9c GM |
197 | struct type *elttype = check_typedef (TYPE_TARGET_TYPE (type)); |
198 | ||
199 | if (TYPE_CODE (elttype) == TYPE_CODE_FUNC) | |
200 | { | |
201 | /* Try to print what function it points to. */ | |
50810684 UW |
202 | print_function_pointer_address (gdbarch, addr, stream, |
203 | options->addressprint); | |
72019c9c GM |
204 | /* Return value is irrelevant except for string pointers. */ |
205 | return 0; | |
206 | } | |
207 | ||
79a45b7d | 208 | if (options->addressprint && options->format != 's') |
5af949e3 | 209 | fputs_filtered (paddress (gdbarch, address), stream); |
72019c9c GM |
210 | |
211 | /* For a pointer to char or unsigned char, also print the string | |
212 | pointed to, unless pointer is null. */ | |
213 | ||
214 | if (TYPE_LENGTH (elttype) == 1 | |
215 | && TYPE_CODE (elttype) == TYPE_CODE_INT | |
79a45b7d | 216 | && (options->format == 0 || options->format == 's') |
72019c9c | 217 | && addr != 0) |
09ca9e2e | 218 | return val_print_string (TYPE_TARGET_TYPE (type), NULL, addr, -1, |
6c7a06a3 | 219 | stream, options); |
72019c9c GM |
220 | |
221 | return 0; | |
222 | } | |
223 | ||
224 | static void | |
844781a1 GM |
225 | print_variable_at_address (struct type *type, |
226 | const gdb_byte *valaddr, | |
79a45b7d TT |
227 | struct ui_file *stream, |
228 | int recurse, | |
229 | const struct value_print_options *options) | |
72019c9c | 230 | { |
5af949e3 | 231 | struct gdbarch *gdbarch = get_type_arch (type); |
72019c9c GM |
232 | CORE_ADDR addr = unpack_pointer (type, valaddr); |
233 | struct type *elttype = check_typedef (TYPE_TARGET_TYPE (type)); | |
234 | ||
235 | fprintf_filtered (stream, "["); | |
5af949e3 | 236 | fputs_filtered (paddress (gdbarch, addr), stream); |
72019c9c GM |
237 | fprintf_filtered (stream, "] : "); |
238 | ||
239 | if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF) | |
240 | { | |
241 | struct value *deref_val = | |
d8631d21 | 242 | value_at (TYPE_TARGET_TYPE (type), unpack_pointer (type, valaddr)); |
b8d56208 | 243 | |
79a45b7d | 244 | common_val_print (deref_val, stream, recurse, options, current_language); |
72019c9c GM |
245 | } |
246 | else | |
247 | fputs_filtered ("???", stream); | |
248 | } | |
249 | ||
844781a1 GM |
250 | |
251 | /* m2_print_array_contents - prints out the contents of an | |
252 | array up to a max_print values. | |
253 | It prints arrays of char as a string | |
254 | and all other data types as comma | |
255 | separated values. */ | |
256 | ||
257 | static void | |
258 | m2_print_array_contents (struct type *type, const gdb_byte *valaddr, | |
259 | int embedded_offset, CORE_ADDR address, | |
79a45b7d | 260 | struct ui_file *stream, int recurse, |
0e03807e | 261 | const struct value *val, |
79a45b7d TT |
262 | const struct value_print_options *options, |
263 | int len) | |
844781a1 GM |
264 | { |
265 | int eltlen; | |
266 | CHECK_TYPEDEF (type); | |
267 | ||
268 | if (TYPE_LENGTH (type) > 0) | |
269 | { | |
270 | eltlen = TYPE_LENGTH (type); | |
79a45b7d | 271 | if (options->prettyprint_arrays) |
844781a1 GM |
272 | print_spaces_filtered (2 + 2 * recurse, stream); |
273 | /* For an array of chars, print with string syntax. */ | |
274 | if (eltlen == 1 && | |
275 | ((TYPE_CODE (type) == TYPE_CODE_INT) | |
276 | || ((current_language->la_language == language_m2) | |
277 | && (TYPE_CODE (type) == TYPE_CODE_CHAR))) | |
79a45b7d | 278 | && (options->format == 0 || options->format == 's')) |
09ca9e2e | 279 | val_print_string (type, NULL, address, len+1, stream, options); |
844781a1 GM |
280 | else |
281 | { | |
282 | fprintf_filtered (stream, "{"); | |
490f124f | 283 | val_print_array_elements (type, valaddr, embedded_offset, |
0e03807e TT |
284 | address, stream, recurse, val, |
285 | options, 0); | |
844781a1 GM |
286 | fprintf_filtered (stream, "}"); |
287 | } | |
288 | } | |
289 | } | |
290 | ||
291 | ||
32b72a42 PA |
292 | /* See val_print for a description of the various parameters of this |
293 | function; they are identical. The semantics of the return value is | |
294 | also identical to val_print. */ | |
c906108c SS |
295 | |
296 | int | |
fc1a4b47 | 297 | m2_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset, |
79a45b7d | 298 | CORE_ADDR address, struct ui_file *stream, int recurse, |
0e03807e | 299 | const struct value *original_value, |
79a45b7d | 300 | const struct value_print_options *options) |
c906108c | 301 | { |
5af949e3 | 302 | struct gdbarch *gdbarch = get_type_arch (type); |
025bb325 | 303 | unsigned int i = 0; /* Number of characters printed. */ |
72019c9c GM |
304 | unsigned len; |
305 | struct type *elttype; | |
306 | unsigned eltlen; | |
72019c9c GM |
307 | LONGEST val; |
308 | CORE_ADDR addr; | |
309 | ||
310 | CHECK_TYPEDEF (type); | |
311 | switch (TYPE_CODE (type)) | |
312 | { | |
313 | case TYPE_CODE_ARRAY: | |
314 | if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0) | |
315 | { | |
316 | elttype = check_typedef (TYPE_TARGET_TYPE (type)); | |
317 | eltlen = TYPE_LENGTH (elttype); | |
318 | len = TYPE_LENGTH (type) / eltlen; | |
79a45b7d | 319 | if (options->prettyprint_arrays) |
72019c9c GM |
320 | print_spaces_filtered (2 + 2 * recurse, stream); |
321 | /* For an array of chars, print with string syntax. */ | |
322 | if (eltlen == 1 && | |
323 | ((TYPE_CODE (elttype) == TYPE_CODE_INT) | |
324 | || ((current_language->la_language == language_m2) | |
325 | && (TYPE_CODE (elttype) == TYPE_CODE_CHAR))) | |
79a45b7d | 326 | && (options->format == 0 || options->format == 's')) |
72019c9c GM |
327 | { |
328 | /* If requested, look for the first null char and only print | |
329 | elements up to it. */ | |
79a45b7d | 330 | if (options->stop_print_at_null) |
72019c9c GM |
331 | { |
332 | unsigned int temp_len; | |
333 | ||
025bb325 | 334 | /* Look for a NULL char. */ |
72019c9c GM |
335 | for (temp_len = 0; |
336 | (valaddr + embedded_offset)[temp_len] | |
79a45b7d | 337 | && temp_len < len && temp_len < options->print_max; |
72019c9c GM |
338 | temp_len++); |
339 | len = temp_len; | |
340 | } | |
341 | ||
6c7a06a3 | 342 | LA_PRINT_STRING (stream, TYPE_TARGET_TYPE (type), |
be759fcf PM |
343 | valaddr + embedded_offset, len, NULL, |
344 | 0, options); | |
72019c9c GM |
345 | i = len; |
346 | } | |
347 | else | |
348 | { | |
349 | fprintf_filtered (stream, "{"); | |
490f124f | 350 | val_print_array_elements (type, valaddr, embedded_offset, |
025bb325 MS |
351 | address, stream, |
352 | recurse, original_value, | |
0e03807e | 353 | options, 0); |
72019c9c GM |
354 | fprintf_filtered (stream, "}"); |
355 | } | |
356 | break; | |
357 | } | |
358 | /* Array of unspecified length: treat like pointer to first elt. */ | |
79a45b7d | 359 | print_unpacked_pointer (type, address, address, options, stream); |
72019c9c GM |
360 | break; |
361 | ||
362 | case TYPE_CODE_PTR: | |
363 | if (TYPE_CONST (type)) | |
364 | print_variable_at_address (type, valaddr + embedded_offset, | |
79a45b7d TT |
365 | stream, recurse, options); |
366 | else if (options->format && options->format != 's') | |
ab2188aa PA |
367 | val_print_scalar_formatted (type, valaddr, embedded_offset, |
368 | original_value, options, 0, stream); | |
72019c9c GM |
369 | else |
370 | { | |
371 | addr = unpack_pointer (type, valaddr + embedded_offset); | |
79a45b7d | 372 | print_unpacked_pointer (type, addr, address, options, stream); |
72019c9c GM |
373 | } |
374 | break; | |
375 | ||
72019c9c GM |
376 | case TYPE_CODE_REF: |
377 | elttype = check_typedef (TYPE_TARGET_TYPE (type)); | |
79a45b7d | 378 | if (options->addressprint) |
72019c9c GM |
379 | { |
380 | CORE_ADDR addr | |
381 | = extract_typed_address (valaddr + embedded_offset, type); | |
b8d56208 | 382 | |
72019c9c | 383 | fprintf_filtered (stream, "@"); |
5af949e3 | 384 | fputs_filtered (paddress (gdbarch, addr), stream); |
79a45b7d | 385 | if (options->deref_ref) |
72019c9c GM |
386 | fputs_filtered (": ", stream); |
387 | } | |
388 | /* De-reference the reference. */ | |
79a45b7d | 389 | if (options->deref_ref) |
72019c9c GM |
390 | { |
391 | if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF) | |
392 | { | |
393 | struct value *deref_val = | |
394 | value_at | |
395 | (TYPE_TARGET_TYPE (type), | |
d8631d21 | 396 | unpack_pointer (type, valaddr + embedded_offset)); |
b8d56208 | 397 | |
79a45b7d TT |
398 | common_val_print (deref_val, stream, recurse, options, |
399 | current_language); | |
72019c9c GM |
400 | } |
401 | else | |
402 | fputs_filtered ("???", stream); | |
403 | } | |
404 | break; | |
405 | ||
406 | case TYPE_CODE_UNION: | |
79a45b7d | 407 | if (recurse && !options->unionprint) |
72019c9c GM |
408 | { |
409 | fprintf_filtered (stream, "{...}"); | |
410 | break; | |
411 | } | |
412 | /* Fall through. */ | |
413 | case TYPE_CODE_STRUCT: | |
414 | if (m2_is_long_set (type)) | |
415 | m2_print_long_set (type, valaddr, embedded_offset, address, | |
79a45b7d | 416 | stream); |
844781a1 GM |
417 | else if (m2_is_unbounded_array (type)) |
418 | m2_print_unbounded_array (type, valaddr, embedded_offset, | |
79a45b7d | 419 | address, stream, recurse, options); |
72019c9c GM |
420 | else |
421 | cp_print_value_fields (type, type, valaddr, embedded_offset, | |
0e03807e TT |
422 | address, stream, recurse, original_value, |
423 | options, NULL, 0); | |
72019c9c GM |
424 | break; |
425 | ||
426 | case TYPE_CODE_ENUM: | |
79a45b7d | 427 | if (options->format) |
72019c9c | 428 | { |
ab2188aa PA |
429 | val_print_scalar_formatted (type, valaddr, embedded_offset, |
430 | original_value, options, 0, stream); | |
72019c9c GM |
431 | break; |
432 | } | |
433 | len = TYPE_NFIELDS (type); | |
434 | val = unpack_long (type, valaddr + embedded_offset); | |
435 | for (i = 0; i < len; i++) | |
436 | { | |
437 | QUIT; | |
438 | if (val == TYPE_FIELD_BITPOS (type, i)) | |
439 | { | |
440 | break; | |
441 | } | |
442 | } | |
443 | if (i < len) | |
444 | { | |
445 | fputs_filtered (TYPE_FIELD_NAME (type, i), stream); | |
446 | } | |
447 | else | |
448 | { | |
449 | print_longest (stream, 'd', 0, val); | |
450 | } | |
451 | break; | |
452 | ||
453 | case TYPE_CODE_FUNC: | |
79a45b7d | 454 | if (options->format) |
72019c9c | 455 | { |
ab2188aa PA |
456 | val_print_scalar_formatted (type, valaddr, embedded_offset, |
457 | original_value, options, 0, stream); | |
72019c9c GM |
458 | break; |
459 | } | |
460 | /* FIXME, we should consider, at least for ANSI C language, eliminating | |
461 | the distinction made between FUNCs and POINTERs to FUNCs. */ | |
462 | fprintf_filtered (stream, "{"); | |
463 | type_print (type, "", stream, -1); | |
464 | fprintf_filtered (stream, "} "); | |
465 | /* Try to print what function it points to, and its address. */ | |
5af949e3 | 466 | print_address_demangle (gdbarch, address, stream, demangle); |
72019c9c GM |
467 | break; |
468 | ||
469 | case TYPE_CODE_BOOL: | |
79a45b7d TT |
470 | if (options->format || options->output_format) |
471 | { | |
472 | struct value_print_options opts = *options; | |
b8d56208 | 473 | |
79a45b7d TT |
474 | opts.format = (options->format ? options->format |
475 | : options->output_format); | |
ab2188aa PA |
476 | val_print_scalar_formatted (type, valaddr, embedded_offset, |
477 | original_value, &opts, 0, stream); | |
79a45b7d | 478 | } |
72019c9c GM |
479 | else |
480 | { | |
481 | val = unpack_long (type, valaddr + embedded_offset); | |
482 | if (val == 0) | |
483 | fputs_filtered ("FALSE", stream); | |
484 | else if (val == 1) | |
485 | fputs_filtered ("TRUE", stream); | |
486 | else | |
487 | fprintf_filtered (stream, "%ld)", (long int) val); | |
488 | } | |
489 | break; | |
490 | ||
491 | case TYPE_CODE_RANGE: | |
492 | if (TYPE_LENGTH (type) == TYPE_LENGTH (TYPE_TARGET_TYPE (type))) | |
493 | { | |
494 | m2_val_print (TYPE_TARGET_TYPE (type), valaddr, embedded_offset, | |
0e03807e | 495 | address, stream, recurse, original_value, options); |
72019c9c GM |
496 | break; |
497 | } | |
498 | /* FIXME: create_range_type does not set the unsigned bit in a | |
499 | range type (I think it probably should copy it from the target | |
500 | type), so we won't print values which are too large to | |
501 | fit in a signed integer correctly. */ | |
502 | /* FIXME: Doesn't handle ranges of enums correctly. (Can't just | |
503 | print with the target type, though, because the size of our type | |
504 | and the target type might differ). */ | |
505 | /* FALLTHROUGH */ | |
506 | ||
507 | case TYPE_CODE_INT: | |
79a45b7d TT |
508 | if (options->format || options->output_format) |
509 | { | |
510 | struct value_print_options opts = *options; | |
b8d56208 | 511 | |
79a45b7d TT |
512 | opts.format = (options->format ? options->format |
513 | : options->output_format); | |
ab2188aa PA |
514 | val_print_scalar_formatted (type, valaddr, embedded_offset, |
515 | original_value, &opts, 0, stream); | |
79a45b7d | 516 | } |
72019c9c GM |
517 | else |
518 | val_print_type_code_int (type, valaddr + embedded_offset, stream); | |
519 | break; | |
520 | ||
521 | case TYPE_CODE_CHAR: | |
79a45b7d TT |
522 | if (options->format || options->output_format) |
523 | { | |
524 | struct value_print_options opts = *options; | |
b8d56208 | 525 | |
79a45b7d TT |
526 | opts.format = (options->format ? options->format |
527 | : options->output_format); | |
ab2188aa PA |
528 | val_print_scalar_formatted (type, valaddr, embedded_offset, |
529 | original_value, &opts, 0, stream); | |
79a45b7d | 530 | } |
72019c9c GM |
531 | else |
532 | { | |
533 | val = unpack_long (type, valaddr + embedded_offset); | |
534 | if (TYPE_UNSIGNED (type)) | |
535 | fprintf_filtered (stream, "%u", (unsigned int) val); | |
536 | else | |
537 | fprintf_filtered (stream, "%d", (int) val); | |
538 | fputs_filtered (" ", stream); | |
6c7a06a3 | 539 | LA_PRINT_CHAR ((unsigned char) val, type, stream); |
72019c9c GM |
540 | } |
541 | break; | |
542 | ||
543 | case TYPE_CODE_FLT: | |
79a45b7d | 544 | if (options->format) |
ab2188aa PA |
545 | val_print_scalar_formatted (type, valaddr, embedded_offset, |
546 | original_value, options, 0, stream); | |
72019c9c GM |
547 | else |
548 | print_floating (valaddr + embedded_offset, type, stream); | |
549 | break; | |
550 | ||
551 | case TYPE_CODE_METHOD: | |
552 | break; | |
553 | ||
554 | case TYPE_CODE_BITSTRING: | |
555 | case TYPE_CODE_SET: | |
556 | elttype = TYPE_INDEX_TYPE (type); | |
557 | CHECK_TYPEDEF (elttype); | |
558 | if (TYPE_STUB (elttype)) | |
559 | { | |
560 | fprintf_filtered (stream, _("<incomplete type>")); | |
561 | gdb_flush (stream); | |
562 | break; | |
563 | } | |
564 | else | |
565 | { | |
566 | struct type *range = elttype; | |
567 | LONGEST low_bound, high_bound; | |
568 | int i; | |
569 | int is_bitstring = TYPE_CODE (type) == TYPE_CODE_BITSTRING; | |
570 | int need_comma = 0; | |
571 | ||
572 | if (is_bitstring) | |
573 | fputs_filtered ("B'", stream); | |
574 | else | |
575 | fputs_filtered ("{", stream); | |
576 | ||
577 | i = get_discrete_bounds (range, &low_bound, &high_bound); | |
578 | maybe_bad_bstring: | |
579 | if (i < 0) | |
580 | { | |
581 | fputs_filtered (_("<error value>"), stream); | |
582 | goto done; | |
583 | } | |
584 | ||
585 | for (i = low_bound; i <= high_bound; i++) | |
586 | { | |
587 | int element = value_bit_index (type, valaddr + embedded_offset, | |
588 | i); | |
b8d56208 | 589 | |
72019c9c GM |
590 | if (element < 0) |
591 | { | |
592 | i = element; | |
593 | goto maybe_bad_bstring; | |
594 | } | |
595 | if (is_bitstring) | |
596 | fprintf_filtered (stream, "%d", element); | |
597 | else if (element) | |
598 | { | |
599 | if (need_comma) | |
600 | fputs_filtered (", ", stream); | |
601 | print_type_scalar (range, i, stream); | |
602 | need_comma = 1; | |
603 | ||
604 | if (i + 1 <= high_bound | |
605 | && value_bit_index (type, valaddr + embedded_offset, | |
606 | ++i)) | |
607 | { | |
608 | int j = i; | |
b8d56208 | 609 | |
72019c9c GM |
610 | fputs_filtered ("..", stream); |
611 | while (i + 1 <= high_bound | |
612 | && value_bit_index (type, | |
613 | valaddr + embedded_offset, | |
614 | ++i)) | |
615 | j = i; | |
616 | print_type_scalar (range, j, stream); | |
617 | } | |
618 | } | |
619 | } | |
620 | done: | |
621 | if (is_bitstring) | |
622 | fputs_filtered ("'", stream); | |
623 | else | |
624 | fputs_filtered ("}", stream); | |
625 | } | |
626 | break; | |
627 | ||
628 | case TYPE_CODE_VOID: | |
629 | fprintf_filtered (stream, "void"); | |
630 | break; | |
631 | ||
632 | case TYPE_CODE_ERROR: | |
b00fdb78 | 633 | fprintf_filtered (stream, "%s", TYPE_ERROR_NAME (type)); |
72019c9c GM |
634 | break; |
635 | ||
636 | case TYPE_CODE_UNDEF: | |
637 | /* This happens (without TYPE_FLAG_STUB set) on systems which don't use | |
638 | dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar" | |
639 | and no complete type for struct foo in that file. */ | |
640 | fprintf_filtered (stream, _("<incomplete type>")); | |
641 | break; | |
642 | ||
643 | default: | |
644 | error (_("Invalid m2 type code %d in symbol table."), TYPE_CODE (type)); | |
645 | } | |
646 | gdb_flush (stream); | |
647 | return (0); | |
c906108c | 648 | } |