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