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