]>
Commit | Line | Data |
---|---|---|
7d9884b9 JG |
1 | /* Print values for GDB, the GNU debugger. |
2 | Copyright 1986, 1988, 1989, 1991 Free Software Foundation, Inc. | |
bd5635a1 RP |
3 | |
4 | This file is part of GDB. | |
5 | ||
36b9d39c | 6 | This program is free software; you can redistribute it and/or modify |
bd5635a1 | 7 | it under the terms of the GNU General Public License as published by |
36b9d39c JG |
8 | the Free Software Foundation; either version 2 of the License, or |
9 | (at your option) any later version. | |
bd5635a1 | 10 | |
36b9d39c | 11 | This program is distributed in the hope that it will be useful, |
bd5635a1 RP |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
36b9d39c JG |
17 | along with this program; if not, write to the Free Software |
18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
bd5635a1 RP |
19 | |
20 | #include <stdio.h> | |
21 | #include <string.h> | |
22 | #include "defs.h" | |
bd5635a1 RP |
23 | #include "symtab.h" |
24 | #include "value.h" | |
25 | #include "gdbcore.h" | |
26 | #include "gdbcmd.h" | |
27 | #include "target.h" | |
28 | #include "obstack.h" | |
be3bc7ad | 29 | #include "language.h" |
bd5635a1 RP |
30 | |
31 | #include <errno.h> | |
32 | extern int sys_nerr; | |
33 | extern char *sys_errlist[]; | |
34 | ||
35 | extern void print_scalar_formatted(); /* printcmd.c */ | |
36 | extern void print_address_demangle(); /* printcmd.c */ | |
37 | extern int demangle; /* whether to print C++ syms raw or source-form */ | |
38 | ||
39 | /* Maximum number of chars to print for a string pointer value | |
40 | or vector contents, or UINT_MAX for no limit. */ | |
41 | ||
42 | static unsigned int print_max; | |
43 | ||
44 | static void type_print_varspec_suffix (); | |
45 | static void type_print_varspec_prefix (); | |
46 | static void type_print_base (); | |
47 | static void type_print_method_args (); | |
48 | ||
49 | /* Default input and output radixes, and output format letter. */ | |
50 | ||
51 | unsigned input_radix = 10; | |
52 | unsigned output_radix = 10; | |
53 | int output_format = 0; | |
54 | ||
55 | ||
56 | char **unsigned_type_table; | |
57 | char **signed_type_table; | |
58 | char **float_type_table; | |
59 | ||
60 | ||
61 | /* Print repeat counts if there are more than this | |
62 | many repetitions of an element in an array. */ | |
63 | #define REPEAT_COUNT_THRESHOLD 10 | |
0dce3774 JK |
64 | |
65 | /* Define a mess of print controls. */ | |
66 | ||
67 | int prettyprint; /* Controls pretty printing of structures */ | |
68 | int vtblprint; /* Controls printing of vtbl's */ | |
69 | int unionprint; /* Controls printing of nested unions. */ | |
70 | int arrayprint; /* Controls pretty printing of arrays. */ | |
71 | int addressprint; /* Controls pretty printing of addresses. */ | |
72 | int objectprint; /* Controls looking up an object's derived type | |
73 | using what we find in its vtables. */ | |
74 | ||
75 | struct obstack dont_print_obstack; | |
76 | ||
77 | static void cplus_val_print (); | |
bd5635a1 RP |
78 | \f |
79 | /* Print the character string STRING, printing at most LENGTH characters. | |
80 | Printing stops early if the number hits print_max; repeat counts | |
81 | are printed as appropriate. Print ellipses at the end if we | |
82 | had to stop before printing LENGTH characters, or if FORCE_ELLIPSES. */ | |
83 | ||
84 | void | |
85 | print_string (stream, string, length, force_ellipses) | |
86 | FILE *stream; | |
87 | char *string; | |
88 | unsigned int length; | |
89 | int force_ellipses; | |
90 | { | |
91 | register unsigned int i; | |
92 | unsigned int things_printed = 0; | |
93 | int in_quotes = 0; | |
94 | int need_comma = 0; | |
95 | extern int inspect_it; | |
96 | ||
97 | if (length == 0) | |
98 | { | |
99 | fputs_filtered ("\"\"", stdout); | |
100 | return; | |
101 | } | |
102 | ||
103 | for (i = 0; i < length && things_printed < print_max; ++i) | |
104 | { | |
105 | /* Position of the character we are examining | |
106 | to see whether it is repeated. */ | |
107 | unsigned int rep1; | |
108 | /* Number of repetitions we have detected so far. */ | |
109 | unsigned int reps; | |
110 | ||
111 | QUIT; | |
112 | ||
113 | if (need_comma) | |
114 | { | |
115 | fputs_filtered (", ", stream); | |
116 | need_comma = 0; | |
117 | } | |
118 | ||
119 | rep1 = i + 1; | |
120 | reps = 1; | |
121 | while (rep1 < length && string[rep1] == string[i]) | |
122 | { | |
123 | ++rep1; | |
124 | ++reps; | |
125 | } | |
126 | ||
127 | if (reps > REPEAT_COUNT_THRESHOLD) | |
128 | { | |
129 | if (in_quotes) | |
130 | { | |
131 | if (inspect_it) | |
132 | fputs_filtered ("\\\", ", stream); | |
133 | else | |
134 | fputs_filtered ("\", ", stream); | |
135 | in_quotes = 0; | |
136 | } | |
137 | fputs_filtered ("'", stream); | |
138 | printchar (string[i], stream, '\''); | |
139 | fprintf_filtered (stream, "' <repeats %u times>", reps); | |
140 | i = rep1 - 1; | |
141 | things_printed += REPEAT_COUNT_THRESHOLD; | |
142 | need_comma = 1; | |
143 | } | |
144 | else | |
145 | { | |
146 | if (!in_quotes) | |
147 | { | |
148 | if (inspect_it) | |
149 | fputs_filtered ("\\\"", stream); | |
150 | else | |
151 | fputs_filtered ("\"", stream); | |
152 | in_quotes = 1; | |
153 | } | |
154 | printchar (string[i], stream, '"'); | |
155 | ++things_printed; | |
156 | } | |
157 | } | |
158 | ||
159 | /* Terminate the quotes if necessary. */ | |
160 | if (in_quotes) | |
161 | { | |
162 | if (inspect_it) | |
163 | fputs_filtered ("\\\"", stream); | |
164 | else | |
165 | fputs_filtered ("\"", stream); | |
166 | } | |
167 | ||
168 | if (force_ellipses || i < length) | |
169 | fputs_filtered ("...", stream); | |
170 | } | |
171 | ||
172 | /* Print a floating point value of type TYPE, pointed to in GDB by VALADDR, | |
173 | on STREAM. */ | |
174 | ||
175 | void | |
176 | print_floating (valaddr, type, stream) | |
177 | char *valaddr; | |
178 | struct type *type; | |
179 | FILE *stream; | |
180 | { | |
181 | double doub; | |
182 | int inv; | |
183 | unsigned len = TYPE_LENGTH (type); | |
184 | ||
185 | #if defined (IEEE_FLOAT) | |
186 | ||
187 | /* Check for NaN's. Note that this code does not depend on us being | |
188 | on an IEEE conforming system. It only depends on the target | |
189 | machine using IEEE representation. This means (a) | |
190 | cross-debugging works right, and (2) IEEE_FLOAT can (and should) | |
191 | be defined for systems like the 68881, which uses IEEE | |
192 | representation, but is not IEEE conforming. */ | |
193 | ||
194 | { | |
195 | long low, high; | |
196 | /* Is the sign bit 0? */ | |
197 | int nonnegative; | |
198 | /* Is it is a NaN (i.e. the exponent is all ones and | |
199 | the fraction is nonzero)? */ | |
200 | int is_nan; | |
201 | ||
202 | if (len == sizeof (float)) | |
203 | { | |
204 | /* It's single precision. */ | |
205 | bcopy (valaddr, &low, sizeof (low)); | |
206 | /* target -> host. */ | |
207 | SWAP_TARGET_AND_HOST (&low, sizeof (float)); | |
208 | nonnegative = low >= 0; | |
209 | is_nan = ((((low >> 23) & 0xFF) == 0xFF) | |
210 | && 0 != (low & 0x7FFFFF)); | |
211 | low &= 0x7fffff; | |
212 | high = 0; | |
213 | } | |
214 | else | |
215 | { | |
216 | /* It's double precision. Get the high and low words. */ | |
217 | ||
218 | #if TARGET_BYTE_ORDER == BIG_ENDIAN | |
219 | bcopy (valaddr+4, &low, sizeof (low)); | |
220 | bcopy (valaddr+0, &high, sizeof (high)); | |
221 | #else | |
222 | bcopy (valaddr+0, &low, sizeof (low)); | |
223 | bcopy (valaddr+4, &high, sizeof (high)); | |
224 | #endif | |
225 | SWAP_TARGET_AND_HOST (&low, sizeof (low)); | |
226 | SWAP_TARGET_AND_HOST (&high, sizeof (high)); | |
227 | nonnegative = high >= 0; | |
228 | is_nan = (((high >> 20) & 0x7ff) == 0x7ff | |
229 | && ! ((((high & 0xfffff) == 0)) && (low == 0))); | |
230 | high &= 0xfffff; | |
231 | } | |
232 | ||
233 | if (is_nan) | |
234 | { | |
235 | /* The meaning of the sign and fraction is not defined by IEEE. | |
236 | But the user might know what they mean. For example, they | |
237 | (in an implementation-defined manner) distinguish between | |
238 | signaling and quiet NaN's. */ | |
239 | if (high) | |
240 | fprintf_filtered (stream, "-NaN(0x%lx%.8lx)" + nonnegative, | |
241 | high, low); | |
242 | else | |
243 | fprintf_filtered (stream, "-NaN(0x%lx)" + nonnegative, low); | |
244 | return; | |
245 | } | |
246 | } | |
247 | #endif /* IEEE_FLOAT. */ | |
248 | ||
249 | doub = unpack_double (type, valaddr, &inv); | |
250 | if (inv) | |
251 | fprintf_filtered (stream, "<invalid float value>"); | |
252 | else | |
be3bc7ad | 253 | fprintf_filtered (stream, len <= sizeof(float) ? "%.9g" : "%.17g", doub); |
bd5635a1 RP |
254 | } |
255 | ||
256 | /* VALADDR points to an integer of LEN bytes. Print it in hex on stream. */ | |
257 | static void | |
258 | print_hex_chars (stream, valaddr, len) | |
259 | FILE *stream; | |
260 | unsigned char *valaddr; | |
261 | unsigned len; | |
262 | { | |
263 | unsigned char *p; | |
264 | ||
265 | fprintf_filtered (stream, "0x"); | |
266 | #if TARGET_BYTE_ORDER == BIG_ENDIAN | |
267 | for (p = valaddr; | |
268 | p < valaddr + len; | |
269 | p++) | |
270 | #else /* Little endian. */ | |
271 | for (p = valaddr + len - 1; | |
272 | p >= valaddr; | |
273 | p--) | |
274 | #endif | |
275 | { | |
276 | fprintf_filtered (stream, "%02x", *p); | |
277 | } | |
278 | } | |
279 | \f | |
280 | /* Print the value VAL in C-ish syntax on stream STREAM. | |
281 | FORMAT is a format-letter, or 0 for print in natural format of data type. | |
282 | If the object printed is a string pointer, returns | |
283 | the number of string bytes printed. */ | |
284 | ||
285 | int | |
286 | value_print (val, stream, format, pretty) | |
287 | value val; | |
288 | FILE *stream; | |
289 | char format; | |
290 | enum val_prettyprint pretty; | |
291 | { | |
292 | register unsigned int i, n, typelen; | |
293 | ||
294 | if (val == 0) | |
295 | { | |
296 | printf_filtered ("<address of value unknown>"); | |
297 | return 0; | |
298 | } | |
299 | if (VALUE_OPTIMIZED_OUT (val)) | |
300 | { | |
301 | printf_filtered ("<value optimized out>"); | |
302 | return 0; | |
303 | } | |
aec4cb91 | 304 | |
bd5635a1 RP |
305 | /* A "repeated" value really contains several values in a row. |
306 | They are made by the @ operator. | |
307 | Print such values as if they were arrays. */ | |
308 | ||
309 | else if (VALUE_REPEATED (val)) | |
310 | { | |
311 | n = VALUE_REPETITIONS (val); | |
312 | typelen = TYPE_LENGTH (VALUE_TYPE (val)); | |
313 | fprintf_filtered (stream, "{"); | |
314 | /* Print arrays of characters using string syntax. */ | |
315 | if (typelen == 1 && TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_INT | |
316 | && format == 0) | |
317 | print_string (stream, VALUE_CONTENTS (val), n, 0); | |
318 | else | |
319 | { | |
320 | unsigned int things_printed = 0; | |
321 | ||
322 | for (i = 0; i < n && things_printed < print_max; i++) | |
323 | { | |
324 | /* Position of the array element we are examining to see | |
325 | whether it is repeated. */ | |
326 | unsigned int rep1; | |
327 | /* Number of repetitions we have detected so far. */ | |
328 | unsigned int reps; | |
329 | ||
330 | if (i != 0) | |
331 | fprintf_filtered (stream, ", "); | |
332 | wrap_here (""); | |
333 | ||
334 | rep1 = i + 1; | |
335 | reps = 1; | |
336 | while (rep1 < n | |
337 | && !bcmp (VALUE_CONTENTS (val) + typelen * i, | |
338 | VALUE_CONTENTS (val) + typelen * rep1, typelen)) | |
339 | { | |
340 | ++reps; | |
341 | ++rep1; | |
342 | } | |
343 | ||
344 | if (reps > REPEAT_COUNT_THRESHOLD) | |
345 | { | |
346 | val_print (VALUE_TYPE (val), | |
347 | VALUE_CONTENTS (val) + typelen * i, | |
348 | VALUE_ADDRESS (val) + typelen * i, | |
349 | stream, format, 1, 0, pretty); | |
350 | fprintf (stream, " <repeats %u times>", reps); | |
351 | i = rep1 - 1; | |
352 | things_printed += REPEAT_COUNT_THRESHOLD; | |
353 | } | |
354 | else | |
355 | { | |
356 | val_print (VALUE_TYPE (val), | |
357 | VALUE_CONTENTS (val) + typelen * i, | |
358 | VALUE_ADDRESS (val) + typelen * i, | |
359 | stream, format, 1, 0, pretty); | |
360 | things_printed++; | |
361 | } | |
362 | } | |
363 | if (i < n) | |
364 | fprintf_filtered (stream, "..."); | |
365 | } | |
366 | fprintf_filtered (stream, "}"); | |
367 | return n * typelen; | |
368 | } | |
369 | else | |
370 | { | |
0dce3774 JK |
371 | struct type *type = VALUE_TYPE (val); |
372 | ||
bd5635a1 RP |
373 | /* If it is a pointer, indicate what it points to. |
374 | ||
375 | Print type also if it is a reference. | |
376 | ||
377 | C++: if it is a member pointer, we will take care | |
378 | of that when we print it. */ | |
0dce3774 JK |
379 | if (TYPE_CODE (type) == TYPE_CODE_PTR |
380 | || TYPE_CODE (type) == TYPE_CODE_REF) | |
bd5635a1 RP |
381 | { |
382 | /* Hack: remove (char *) for char strings. Their | |
383 | type is indicated by the quoted string anyway. */ | |
0dce3774 JK |
384 | if (TYPE_CODE (type) == TYPE_CODE_PTR |
385 | && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) == sizeof(char) | |
386 | && TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_INT | |
387 | && !TYPE_UNSIGNED (TYPE_TARGET_TYPE (type))) | |
bd5635a1 RP |
388 | { |
389 | /* Print nothing */ | |
390 | } | |
391 | else | |
392 | { | |
393 | fprintf_filtered (stream, "("); | |
0dce3774 | 394 | type_print (type, "", stream, -1); |
bd5635a1 RP |
395 | fprintf_filtered (stream, ") "); |
396 | } | |
397 | } | |
0dce3774 | 398 | return val_print (type, VALUE_CONTENTS (val), |
bd5635a1 RP |
399 | VALUE_ADDRESS (val), stream, format, 1, 0, pretty); |
400 | } | |
401 | } | |
402 | ||
403 | /* Return truth value for assertion that TYPE is of the type | |
404 | "pointer to virtual function". */ | |
405 | static int | |
406 | is_vtbl_ptr_type(type) | |
407 | struct type *type; | |
408 | { | |
abefb1f1 | 409 | char *typename = type_name_no_tag (type); |
bd5635a1 | 410 | static const char vtbl_ptr_name[] = |
bcccec8c | 411 | { CPLUS_MARKER,'v','t','b','l','_','p','t','r','_','t','y','p','e', 0 }; |
bd5635a1 RP |
412 | |
413 | return (typename != NULL && !strcmp(typename, vtbl_ptr_name)); | |
414 | } | |
415 | ||
416 | /* Return truth value for the assertion that TYPE is of the type | |
417 | "pointer to virtual function table". */ | |
418 | static int | |
419 | is_vtbl_member(type) | |
420 | struct type *type; | |
421 | { | |
0dce3774 JK |
422 | if (TYPE_CODE (type) == TYPE_CODE_PTR) |
423 | type = TYPE_TARGET_TYPE (type); | |
424 | else | |
425 | return 0; | |
426 | ||
427 | if (TYPE_CODE (type) == TYPE_CODE_ARRAY | |
428 | && TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_STRUCT) | |
bd5635a1 | 429 | /* Virtual functions tables are full of pointers to virtual functions. */ |
0dce3774 | 430 | return is_vtbl_ptr_type (TYPE_TARGET_TYPE (type)); |
bd5635a1 RP |
431 | return 0; |
432 | } | |
433 | \f | |
bd5635a1 RP |
434 | /* Mutually recursive subroutines of cplus_val_print and val_print to print out |
435 | a structure's fields: val_print_fields and cplus_val_print. | |
436 | ||
437 | TYPE, VALADDR, STREAM, RECURSE, and PRETTY have the | |
438 | same meanings as in cplus_val_print and val_print. | |
439 | ||
440 | DONT_PRINT is an array of baseclass types that we | |
441 | should not print, or zero if called from top level. */ | |
442 | static void | |
443 | val_print_fields (type, valaddr, stream, format, recurse, pretty, dont_print) | |
444 | struct type *type; | |
445 | char *valaddr; | |
446 | FILE *stream; | |
447 | char format; | |
448 | int recurse; | |
449 | enum val_prettyprint pretty; | |
450 | struct type **dont_print; | |
451 | { | |
452 | int i, len, n_baseclasses; | |
453 | ||
be3bc7ad JG |
454 | check_stub_type (type); |
455 | ||
bd5635a1 RP |
456 | fprintf_filtered (stream, "{"); |
457 | len = TYPE_NFIELDS (type); | |
458 | n_baseclasses = TYPE_N_BASECLASSES (type); | |
459 | ||
460 | /* Print out baseclasses such that we don't print | |
461 | duplicates of virtual baseclasses. */ | |
462 | if (n_baseclasses > 0) | |
463 | cplus_val_print (type, valaddr, stream, format, recurse+1, pretty, dont_print); | |
464 | ||
465 | if (!len && n_baseclasses == 1) | |
466 | fprintf_filtered (stream, "<No data fields>"); | |
467 | else | |
468 | { | |
469 | extern int inspect_it; | |
470 | int fields_seen = 0; | |
471 | ||
472 | for (i = n_baseclasses; i < len; i++) | |
473 | { | |
474 | /* Check if static field */ | |
475 | if (TYPE_FIELD_STATIC (type, i)) | |
476 | continue; | |
477 | if (fields_seen) | |
478 | fprintf_filtered (stream, ", "); | |
479 | else if (n_baseclasses > 0) | |
480 | { | |
481 | fprintf_filtered (stream, "\n"); | |
482 | print_spaces_filtered (2 + 2 * recurse, stream); | |
483 | fputs_filtered ("members of ", stream); | |
484 | fputs_filtered (type_name_no_tag (type), stream); | |
485 | fputs_filtered (": ", stream); | |
486 | } | |
487 | fields_seen = 1; | |
488 | ||
489 | if (pretty) | |
490 | { | |
491 | fprintf_filtered (stream, "\n"); | |
492 | print_spaces_filtered (2 + 2 * recurse, stream); | |
493 | } | |
494 | else | |
495 | { | |
496 | wrap_here (n_spaces (2 + 2 * recurse)); | |
497 | } | |
498 | if (inspect_it) | |
499 | { | |
500 | if (TYPE_CODE (TYPE_FIELD_TYPE (type, i)) == TYPE_CODE_PTR) | |
501 | fputs_filtered ("\"( ptr \"", stream); | |
502 | else | |
503 | fputs_filtered ("\"( nodef \"", stream); | |
504 | fputs_filtered (TYPE_FIELD_NAME (type, i), stream); | |
505 | fputs_filtered ("\" \"", stream); | |
506 | fputs_filtered (TYPE_FIELD_NAME (type, i), stream); | |
507 | fputs_filtered ("\") \"", stream); | |
508 | } | |
509 | else | |
510 | { | |
511 | fputs_filtered (TYPE_FIELD_NAME (type, i), stream); | |
512 | fputs_filtered (" = ", stream); | |
513 | } | |
514 | if (TYPE_FIELD_PACKED (type, i)) | |
515 | { | |
f266e564 | 516 | value v; |
bd5635a1 | 517 | |
f266e564 JK |
518 | /* Bitfields require special handling, especially due to byte |
519 | order problems. */ | |
bee3c1a1 | 520 | v = value_from_longest (TYPE_FIELD_TYPE (type, i), |
f266e564 | 521 | unpack_field_as_long (type, valaddr, i)); |
bd5635a1 | 522 | |
f266e564 | 523 | val_print (TYPE_FIELD_TYPE (type, i), VALUE_CONTENTS (v), 0, |
bd5635a1 RP |
524 | stream, format, 0, recurse + 1, pretty); |
525 | } | |
526 | else | |
527 | { | |
528 | val_print (TYPE_FIELD_TYPE (type, i), | |
529 | valaddr + TYPE_FIELD_BITPOS (type, i) / 8, | |
530 | 0, stream, format, 0, recurse + 1, pretty); | |
531 | } | |
532 | } | |
533 | if (pretty) | |
534 | { | |
535 | fprintf_filtered (stream, "\n"); | |
536 | print_spaces_filtered (2 * recurse, stream); | |
537 | } | |
538 | } | |
539 | fprintf_filtered (stream, "}"); | |
540 | } | |
541 | ||
542 | /* Special val_print routine to avoid printing multiple copies of virtual | |
543 | baseclasses. */ | |
544 | ||
545 | static void | |
546 | cplus_val_print (type, valaddr, stream, format, recurse, pretty, dont_print) | |
547 | struct type *type; | |
548 | char *valaddr; | |
549 | FILE *stream; | |
550 | char format; | |
551 | int recurse; | |
552 | enum val_prettyprint pretty; | |
553 | struct type **dont_print; | |
554 | { | |
555 | struct obstack tmp_obstack; | |
556 | struct type **last_dont_print | |
557 | = (struct type **)obstack_next_free (&dont_print_obstack); | |
558 | int i, n_baseclasses = TYPE_N_BASECLASSES (type); | |
559 | ||
560 | if (dont_print == 0) | |
561 | { | |
562 | /* If we're at top level, carve out a completely fresh | |
563 | chunk of the obstack and use that until this particular | |
564 | invocation returns. */ | |
565 | tmp_obstack = dont_print_obstack; | |
566 | /* Bump up the high-water mark. Now alpha is omega. */ | |
567 | obstack_finish (&dont_print_obstack); | |
568 | } | |
569 | ||
570 | for (i = 0; i < n_baseclasses; i++) | |
571 | { | |
572 | char *baddr; | |
0dce3774 | 573 | int err; |
bd5635a1 RP |
574 | |
575 | if (BASETYPE_VIA_VIRTUAL (type, i)) | |
576 | { | |
577 | struct type **first_dont_print | |
578 | = (struct type **)obstack_base (&dont_print_obstack); | |
579 | ||
580 | int j = (struct type **)obstack_next_free (&dont_print_obstack) | |
581 | - first_dont_print; | |
582 | ||
583 | while (--j >= 0) | |
584 | if (TYPE_BASECLASS (type, i) == first_dont_print[j]) | |
585 | goto flush_it; | |
586 | ||
587 | obstack_ptr_grow (&dont_print_obstack, TYPE_BASECLASS (type, i)); | |
588 | } | |
589 | ||
0dce3774 JK |
590 | baddr = baseclass_addr (type, i, valaddr, 0, &err); |
591 | if (err == 0 && baddr == 0) | |
bd5635a1 RP |
592 | error ("could not find virtual baseclass `%s'\n", |
593 | type_name_no_tag (TYPE_BASECLASS (type, i))); | |
594 | ||
595 | fprintf_filtered (stream, "\n"); | |
596 | if (pretty) | |
597 | print_spaces_filtered (2 + 2 * recurse, stream); | |
598 | fputs_filtered ("<", stream); | |
599 | fputs_filtered (type_name_no_tag (TYPE_BASECLASS (type, i)), stream); | |
600 | fputs_filtered ("> = ", stream); | |
0dce3774 JK |
601 | if (err != 0) |
602 | fprintf_filtered (stream, "<invalid address 0x%x>", baddr); | |
603 | else | |
604 | val_print_fields (TYPE_BASECLASS (type, i), baddr, stream, format, | |
605 | recurse, pretty, | |
606 | (struct type **)obstack_base (&dont_print_obstack)); | |
bd5635a1 RP |
607 | flush_it: |
608 | ; | |
609 | } | |
610 | ||
611 | if (dont_print == 0) | |
612 | { | |
613 | /* Free the space used to deal with the printing | |
614 | of this type from top level. */ | |
615 | obstack_free (&dont_print_obstack, last_dont_print); | |
616 | /* Reset watermark so that we can continue protecting | |
617 | ourselves from whatever we were protecting ourselves. */ | |
618 | dont_print_obstack = tmp_obstack; | |
619 | } | |
620 | } | |
621 | ||
622 | /* Print data of type TYPE located at VALADDR (within GDB), | |
623 | which came from the inferior at address ADDRESS, | |
624 | onto stdio stream STREAM according to FORMAT | |
625 | (a letter or 0 for natural format). The data at VALADDR | |
626 | is in target byte order. | |
627 | ||
628 | If the data are a string pointer, returns the number of | |
629 | sting characters printed. | |
630 | ||
631 | if DEREF_REF is nonzero, then dereference references, | |
632 | otherwise just print them like pointers. | |
633 | ||
634 | The PRETTY parameter controls prettyprinting. */ | |
635 | ||
636 | int | |
637 | val_print (type, valaddr, address, stream, format, | |
638 | deref_ref, recurse, pretty) | |
639 | struct type *type; | |
640 | char *valaddr; | |
641 | CORE_ADDR address; | |
642 | FILE *stream; | |
643 | char format; | |
644 | int deref_ref; | |
645 | int recurse; | |
646 | enum val_prettyprint pretty; | |
647 | { | |
648 | register unsigned int i; | |
649 | unsigned len; | |
650 | struct type *elttype; | |
651 | unsigned eltlen; | |
652 | LONGEST val; | |
653 | unsigned char c; | |
654 | ||
655 | if (pretty == Val_pretty_default) | |
656 | { | |
657 | pretty = prettyprint ? Val_prettyprint : Val_no_prettyprint; | |
658 | } | |
659 | ||
660 | QUIT; | |
661 | ||
662 | check_stub_type (type); | |
663 | ||
664 | if (TYPE_FLAGS (type) & TYPE_FLAG_STUB) | |
665 | { | |
666 | fprintf_filtered (stream, "<unknown struct>"); | |
667 | fflush (stream); | |
668 | return 0; | |
669 | } | |
670 | ||
671 | switch (TYPE_CODE (type)) | |
672 | { | |
673 | case TYPE_CODE_ARRAY: | |
2a5ec41d | 674 | if (TYPE_LENGTH (type) > 0 |
bd5635a1 RP |
675 | && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0) |
676 | { | |
677 | elttype = TYPE_TARGET_TYPE (type); | |
678 | eltlen = TYPE_LENGTH (elttype); | |
679 | len = TYPE_LENGTH (type) / eltlen; | |
680 | if (arrayprint) | |
681 | print_spaces_filtered (2 + 2 * recurse, stream); | |
682 | fprintf_filtered (stream, "{"); | |
683 | /* For an array of chars, print with string syntax. */ | |
684 | if (eltlen == 1 && TYPE_CODE (elttype) == TYPE_CODE_INT | |
685 | && (format == 0 || format == 's') ) | |
686 | print_string (stream, valaddr, len, 0); | |
687 | else | |
688 | { | |
689 | unsigned int things_printed = 0; | |
690 | ||
0dce3774 JK |
691 | /* If this is a virtual function table, print the 0th |
692 | entry specially, and the rest of the members normally. */ | |
693 | if (is_vtbl_ptr_type (elttype)) | |
694 | { | |
695 | fprintf_filtered (stream, "%d vtable entries", len-1); | |
696 | i = 1; | |
697 | } | |
698 | else | |
699 | i = 0; | |
700 | ||
701 | for (; i < len && things_printed < print_max; i++) | |
bd5635a1 RP |
702 | { |
703 | /* Position of the array element we are examining to see | |
704 | whether it is repeated. */ | |
705 | unsigned int rep1; | |
706 | /* Number of repetitions we have detected so far. */ | |
707 | unsigned int reps; | |
708 | ||
709 | if (i != 0) | |
710 | if (arrayprint) | |
711 | { | |
712 | fprintf_filtered (stream, ",\n"); | |
713 | print_spaces_filtered (2 + 2 * recurse, stream); | |
714 | } | |
715 | else | |
716 | fprintf_filtered (stream, ", "); | |
717 | wrap_here (n_spaces (2 + 2 * recurse)); | |
718 | ||
719 | rep1 = i + 1; | |
720 | reps = 1; | |
721 | while (rep1 < len | |
722 | && !bcmp (valaddr + i * eltlen, | |
723 | valaddr + rep1 * eltlen, eltlen)) | |
724 | { | |
725 | ++reps; | |
726 | ++rep1; | |
727 | } | |
728 | ||
729 | if (reps > REPEAT_COUNT_THRESHOLD) | |
730 | { | |
731 | val_print (elttype, valaddr + i * eltlen, | |
732 | 0, stream, format, deref_ref, | |
733 | recurse + 1, pretty); | |
734 | fprintf_filtered (stream, " <repeats %u times>", reps); | |
735 | i = rep1 - 1; | |
736 | things_printed += REPEAT_COUNT_THRESHOLD; | |
737 | } | |
738 | else | |
739 | { | |
740 | val_print (elttype, valaddr + i * eltlen, | |
741 | 0, stream, format, deref_ref, | |
742 | recurse + 1, pretty); | |
743 | things_printed++; | |
744 | } | |
745 | } | |
746 | if (i < len) | |
747 | fprintf_filtered (stream, "..."); | |
748 | } | |
749 | fprintf_filtered (stream, "}"); | |
750 | break; | |
751 | } | |
752 | /* Array of unspecified length: treat like pointer to first elt. */ | |
753 | valaddr = (char *) &address; | |
754 | ||
755 | case TYPE_CODE_PTR: | |
756 | if (format && format != 's') | |
757 | { | |
758 | print_scalar_formatted (valaddr, type, format, 0, stream); | |
759 | break; | |
760 | } | |
761 | if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_METHOD) | |
762 | { | |
763 | struct type *domain = TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type)); | |
764 | struct fn_field *f; | |
765 | int j, len2; | |
766 | char *kind = ""; | |
e1ce8aa5 | 767 | CORE_ADDR addr; |
bd5635a1 | 768 | |
e1ce8aa5 JK |
769 | addr = unpack_pointer (lookup_pointer_type (builtin_type_void), |
770 | valaddr); | |
2a5ec41d | 771 | if (addr < 128) /* FIXME! What is this 128? */ |
bd5635a1 RP |
772 | { |
773 | len = TYPE_NFN_FIELDS (domain); | |
774 | for (i = 0; i < len; i++) | |
775 | { | |
776 | f = TYPE_FN_FIELDLIST1 (domain, i); | |
777 | len2 = TYPE_FN_FIELDLIST_LENGTH (domain, i); | |
778 | ||
779 | for (j = 0; j < len2; j++) | |
780 | { | |
781 | QUIT; | |
e1ce8aa5 | 782 | if (TYPE_FN_FIELD_VOFFSET (f, j) == addr) |
bd5635a1 RP |
783 | { |
784 | kind = "virtual"; | |
785 | goto common; | |
786 | } | |
787 | } | |
788 | } | |
789 | } | |
790 | else | |
791 | { | |
e1ce8aa5 | 792 | struct symbol *sym = find_pc_function (addr); |
bd5635a1 RP |
793 | if (sym == 0) |
794 | error ("invalid pointer to member function"); | |
795 | len = TYPE_NFN_FIELDS (domain); | |
796 | for (i = 0; i < len; i++) | |
797 | { | |
798 | f = TYPE_FN_FIELDLIST1 (domain, i); | |
799 | len2 = TYPE_FN_FIELDLIST_LENGTH (domain, i); | |
800 | ||
801 | for (j = 0; j < len2; j++) | |
802 | { | |
803 | QUIT; | |
804 | if (!strcmp (SYMBOL_NAME (sym), TYPE_FN_FIELD_PHYSNAME (f, j))) | |
805 | goto common; | |
806 | } | |
807 | } | |
808 | } | |
809 | common: | |
810 | if (i < len) | |
811 | { | |
812 | fprintf_filtered (stream, "&"); | |
813 | type_print_varspec_prefix (TYPE_FN_FIELD_TYPE (f, j), stream, 0, 0); | |
814 | fprintf (stream, kind); | |
815 | if (TYPE_FN_FIELD_PHYSNAME (f, j)[0] == '_' | |
816 | && TYPE_FN_FIELD_PHYSNAME (f, j)[1] == CPLUS_MARKER) | |
817 | type_print_method_args | |
818 | (TYPE_FN_FIELD_ARGS (f, j) + 1, "~", | |
819 | TYPE_FN_FIELDLIST_NAME (domain, i), 0, stream); | |
820 | else | |
821 | type_print_method_args | |
822 | (TYPE_FN_FIELD_ARGS (f, j), "", | |
823 | TYPE_FN_FIELDLIST_NAME (domain, i), 0, stream); | |
824 | break; | |
825 | } | |
826 | fprintf_filtered (stream, "("); | |
827 | type_print (type, "", stream, -1); | |
e1ce8aa5 | 828 | fprintf_filtered (stream, ") %d", (int) addr >> 3); |
bd5635a1 RP |
829 | } |
830 | else if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_MEMBER) | |
831 | { | |
832 | struct type *domain = TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type)); | |
833 | ||
834 | /* VAL is a byte offset into the structure type DOMAIN. | |
835 | Find the name of the field for that offset and | |
836 | print it. */ | |
837 | int extra = 0; | |
838 | int bits = 0; | |
839 | len = TYPE_NFIELDS (domain); | |
840 | /* @@ Make VAL into bit offset */ | |
841 | val = unpack_long (builtin_type_int, valaddr) << 3; | |
842 | for (i = TYPE_N_BASECLASSES (domain); i < len; i++) | |
843 | { | |
844 | int bitpos = TYPE_FIELD_BITPOS (domain, i); | |
845 | QUIT; | |
846 | if (val == bitpos) | |
847 | break; | |
848 | if (val < bitpos && i != 0) | |
849 | { | |
850 | /* Somehow pointing into a field. */ | |
851 | i -= 1; | |
852 | extra = (val - TYPE_FIELD_BITPOS (domain, i)); | |
2a5ec41d | 853 | if (extra & 0x7) |
bd5635a1 RP |
854 | bits = 1; |
855 | else | |
856 | extra >>= 3; | |
857 | break; | |
858 | } | |
859 | } | |
860 | if (i < len) | |
861 | { | |
862 | fprintf_filtered (stream, "&"); | |
863 | type_print_base (domain, stream, 0, 0); | |
864 | fprintf_filtered (stream, "::"); | |
865 | fputs_filtered (TYPE_FIELD_NAME (domain, i), stream); | |
866 | if (extra) | |
867 | fprintf_filtered (stream, " + %d bytes", extra); | |
868 | if (bits) | |
869 | fprintf_filtered (stream, " (offset in bits)"); | |
870 | break; | |
871 | } | |
872 | fprintf_filtered (stream, "%d", val >> 3); | |
873 | } | |
874 | else | |
875 | { | |
e1ce8aa5 | 876 | CORE_ADDR addr = unpack_pointer (type, valaddr); |
bd5635a1 RP |
877 | elttype = TYPE_TARGET_TYPE (type); |
878 | ||
879 | if (TYPE_CODE (elttype) == TYPE_CODE_FUNC) | |
880 | { | |
881 | /* Try to print what function it points to. */ | |
882 | print_address_demangle (addr, stream, demangle); | |
883 | /* Return value is irrelevant except for string pointers. */ | |
884 | return 0; | |
885 | } | |
886 | ||
887 | if (addressprint && format != 's') | |
888 | fprintf_filtered (stream, "0x%x", addr); | |
889 | ||
890 | /* For a pointer to char or unsigned char, | |
891 | also print the string pointed to, unless pointer is null. */ | |
892 | i = 0; /* Number of characters printed. */ | |
893 | if (TYPE_LENGTH (elttype) == 1 | |
894 | && TYPE_CODE (elttype) == TYPE_CODE_INT | |
895 | && (format == 0 || format == 's') | |
896 | && addr != 0 | |
897 | /* If print_max is UINT_MAX, the alloca below will fail. | |
898 | In that case don't try to print the string. */ | |
899 | && print_max < UINT_MAX) | |
900 | { | |
901 | int first_addr_err = 0; | |
902 | int errcode = 0; | |
903 | ||
904 | /* Get first character. */ | |
905 | errcode = target_read_memory (addr, (char *)&c, 1); | |
906 | if (errcode != 0) | |
907 | { | |
908 | /* First address out of bounds. */ | |
909 | first_addr_err = 1; | |
910 | } | |
911 | else | |
912 | { | |
913 | /* A real string. */ | |
914 | char *string = (char *) alloca (print_max); | |
915 | ||
916 | /* If the loop ends by us hitting print_max characters, | |
917 | we need to have elipses at the end. */ | |
918 | int force_ellipses = 1; | |
919 | ||
920 | /* This loop always fetches print_max characters, even | |
921 | though print_string might want to print more or fewer | |
922 | (with repeated characters). This is so that | |
923 | we don't spend forever fetching if we print | |
924 | a long string consisting of the same character | |
925 | repeated. Also so we can do it all in one memory | |
926 | operation, which is faster. However, this will be | |
927 | slower if print_max is set high, e.g. if you set | |
928 | print_max to 1000, not only will it take a long | |
929 | time to fetch short strings, but if you are near | |
930 | the end of the address space, it might not work. | |
931 | FIXME. */ | |
932 | QUIT; | |
933 | errcode = target_read_memory (addr, string, print_max); | |
934 | if (errcode != 0) | |
935 | force_ellipses = 0; | |
936 | else | |
937 | for (i = 0; i < print_max; i++) | |
938 | if (string[i] == '\0') | |
939 | { | |
940 | force_ellipses = 0; | |
941 | break; | |
942 | } | |
943 | QUIT; | |
944 | ||
945 | if (addressprint) | |
946 | fputs_filtered (" ", stream); | |
947 | print_string (stream, string, i, force_ellipses); | |
948 | } | |
949 | ||
950 | if (errcode != 0) | |
951 | { | |
952 | if (errcode == EIO) | |
953 | { | |
954 | fprintf_filtered (stream, | |
955 | (" <Address 0x%x out of bounds>" | |
956 | + first_addr_err), | |
957 | addr + i); | |
958 | } | |
959 | else | |
960 | { | |
961 | if (errcode >= sys_nerr || errcode < 0) | |
962 | error ("Error reading memory address 0x%x: unknown error (%d).", | |
963 | addr + i, errcode); | |
964 | else | |
965 | error ("Error reading memory address 0x%x: %s.", | |
966 | addr + i, sys_errlist[errcode]); | |
967 | } | |
968 | } | |
969 | ||
970 | fflush (stream); | |
971 | } | |
972 | else /* print vtbl's nicely */ | |
973 | if (is_vtbl_member(type)) | |
974 | { | |
e1ce8aa5 | 975 | CORE_ADDR vt_address = unpack_pointer (type, valaddr); |
bd5635a1 RP |
976 | |
977 | int vt_index = find_pc_misc_function (vt_address); | |
978 | if (vt_index >= 0 | |
979 | && vt_address == misc_function_vector[vt_index].address) | |
980 | { | |
981 | fputs_filtered (" <", stream); | |
982 | fputs_demangled (misc_function_vector[vt_index].name, | |
983 | stream, 1); | |
984 | fputs_filtered (">", stream); | |
985 | } | |
986 | if (vtblprint) | |
987 | { | |
e1ce8aa5 | 988 | value vt_val; |
bd5635a1 | 989 | |
e1ce8aa5 JK |
990 | vt_val = value_at (TYPE_TARGET_TYPE (type), vt_address); |
991 | val_print (VALUE_TYPE (vt_val), VALUE_CONTENTS (vt_val), | |
992 | VALUE_ADDRESS (vt_val), stream, format, | |
bd5635a1 RP |
993 | deref_ref, recurse + 1, pretty); |
994 | if (pretty) | |
995 | { | |
996 | fprintf_filtered (stream, "\n"); | |
997 | print_spaces_filtered (2 + 2 * recurse, stream); | |
998 | } | |
999 | } | |
1000 | } | |
1001 | ||
1002 | /* Return number of characters printed, plus one for the | |
1003 | terminating null if we have "reached the end". */ | |
1004 | return i + (print_max && i != print_max); | |
1005 | } | |
1006 | break; | |
1007 | ||
1008 | case TYPE_CODE_MEMBER: | |
1009 | error ("not implemented: member type in val_print"); | |
1010 | break; | |
1011 | ||
1012 | case TYPE_CODE_REF: | |
1013 | if (addressprint) | |
1014 | { | |
1015 | fprintf_filtered (stream, "@0x%lx", | |
1016 | unpack_long (builtin_type_int, valaddr)); | |
1017 | if (deref_ref) | |
1018 | fputs_filtered (": ", stream); | |
1019 | } | |
1020 | /* De-reference the reference. */ | |
1021 | if (deref_ref) | |
1022 | { | |
1023 | if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_UNDEF) | |
1024 | { | |
e1ce8aa5 JK |
1025 | value deref_val = |
1026 | value_at | |
1027 | (TYPE_TARGET_TYPE (type), | |
1028 | unpack_pointer (lookup_pointer_type (builtin_type_void), | |
1029 | valaddr)); | |
1030 | val_print (VALUE_TYPE (deref_val), VALUE_CONTENTS (deref_val), | |
1031 | VALUE_ADDRESS (deref_val), stream, format, | |
bd5635a1 RP |
1032 | deref_ref, recurse + 1, pretty); |
1033 | } | |
1034 | else | |
1035 | fputs_filtered ("???", stream); | |
1036 | } | |
1037 | break; | |
1038 | ||
1039 | case TYPE_CODE_UNION: | |
1040 | if (recurse && !unionprint) | |
1041 | { | |
1042 | fprintf_filtered (stream, "{...}"); | |
1043 | break; | |
1044 | } | |
1045 | /* Fall through. */ | |
1046 | case TYPE_CODE_STRUCT: | |
1047 | if (vtblprint && is_vtbl_ptr_type(type)) | |
1048 | { | |
1049 | /* Print the unmangled name if desired. */ | |
1050 | print_address_demangle(*((int *) (valaddr + /* FIXME bytesex */ | |
1051 | TYPE_FIELD_BITPOS (type, VTBL_FNADDR_OFFSET) / 8)), | |
1052 | stream, demangle); | |
1053 | break; | |
1054 | } | |
1055 | val_print_fields (type, valaddr, stream, format, recurse, pretty, 0); | |
1056 | break; | |
1057 | ||
1058 | case TYPE_CODE_ENUM: | |
1059 | if (format) | |
1060 | { | |
1061 | print_scalar_formatted (valaddr, type, format, 0, stream); | |
1062 | break; | |
1063 | } | |
1064 | len = TYPE_NFIELDS (type); | |
1065 | val = unpack_long (builtin_type_int, valaddr); | |
1066 | for (i = 0; i < len; i++) | |
1067 | { | |
1068 | QUIT; | |
1069 | if (val == TYPE_FIELD_BITPOS (type, i)) | |
1070 | break; | |
1071 | } | |
1072 | if (i < len) | |
1073 | fputs_filtered (TYPE_FIELD_NAME (type, i), stream); | |
1074 | else | |
e1ce8aa5 JK |
1075 | #ifdef LONG_LONG |
1076 | fprintf_filtered (stream, "%lld", val); | |
1077 | #else | |
1078 | fprintf_filtered (stream, "%ld", val); | |
1079 | #endif | |
bd5635a1 RP |
1080 | break; |
1081 | ||
1082 | case TYPE_CODE_FUNC: | |
1083 | if (format) | |
1084 | { | |
1085 | print_scalar_formatted (valaddr, type, format, 0, stream); | |
1086 | break; | |
1087 | } | |
36b9d39c JG |
1088 | /* FIXME, we should consider, at least for ANSI C language, eliminating |
1089 | the distinction made between FUNCs and POINTERs to FUNCs. */ | |
bd5635a1 RP |
1090 | fprintf_filtered (stream, "{"); |
1091 | type_print (type, "", stream, -1); | |
1092 | fprintf_filtered (stream, "} "); | |
36b9d39c JG |
1093 | /* Try to print what function it points to, and its address. */ |
1094 | print_address_demangle (address, stream, demangle); | |
bd5635a1 RP |
1095 | break; |
1096 | ||
1097 | case TYPE_CODE_INT: | |
1098 | if (format || output_format) | |
1099 | { | |
1100 | print_scalar_formatted (valaddr, type, | |
1101 | format? format: output_format, | |
1102 | 0, stream); | |
1103 | break; | |
1104 | } | |
1105 | if (TYPE_LENGTH (type) > sizeof (LONGEST)) | |
1106 | { | |
1107 | if (TYPE_UNSIGNED (type)) | |
1108 | { | |
1109 | /* First figure out whether the number in fact has zeros | |
1110 | in all its bytes more significant than least significant | |
1111 | sizeof (LONGEST) ones. */ | |
1112 | char *p; | |
1113 | /* Pointer to first (i.e. lowest address) nonzero character. */ | |
1114 | char *first_addr; | |
e1ce8aa5 | 1115 | len = TYPE_LENGTH (type); |
bd5635a1 RP |
1116 | |
1117 | #if TARGET_BYTE_ORDER == BIG_ENDIAN | |
1118 | for (p = valaddr; | |
1119 | len > sizeof (LONGEST) | |
1120 | && p < valaddr + TYPE_LENGTH (type); | |
1121 | p++) | |
1122 | #else /* Little endian. */ | |
1123 | first_addr = valaddr; | |
1124 | for (p = valaddr + TYPE_LENGTH (type); | |
1125 | len > sizeof (LONGEST) && p >= valaddr; | |
1126 | p--) | |
1127 | #endif /* Little endian. */ | |
1128 | { | |
1129 | if (*p == 0) | |
1130 | len--; | |
1131 | else | |
1132 | break; | |
1133 | } | |
1134 | #if TARGET_BYTE_ORDER == BIG_ENDIAN | |
1135 | first_addr = p; | |
1136 | #endif | |
1137 | ||
1138 | if (len <= sizeof (LONGEST)) | |
1139 | { | |
1140 | /* We can print it in decimal. */ | |
1141 | fprintf_filtered | |
1142 | (stream, | |
1143 | #if defined (LONG_LONG) | |
1144 | "%llu", | |
1145 | #else | |
1146 | "%lu", | |
1147 | #endif | |
1148 | unpack_long (BUILTIN_TYPE_LONGEST, first_addr)); | |
1149 | } | |
1150 | else | |
1151 | { | |
1152 | /* It is big, so print it in hex. */ | |
1153 | print_hex_chars (stream, (unsigned char *)first_addr, len); | |
1154 | } | |
1155 | } | |
1156 | else | |
1157 | { | |
1158 | /* Signed. One could assume two's complement (a reasonable | |
1159 | assumption, I think) and do better than this. */ | |
1160 | print_hex_chars (stream, (unsigned char *)valaddr, | |
1161 | TYPE_LENGTH (type)); | |
1162 | } | |
1163 | break; | |
1164 | } | |
1165 | #ifdef PRINT_TYPELESS_INTEGER | |
1166 | PRINT_TYPELESS_INTEGER (stream, type, unpack_long (type, valaddr)); | |
1167 | #else | |
1168 | #ifndef LONG_LONG | |
1169 | fprintf_filtered (stream, | |
1170 | TYPE_UNSIGNED (type) ? "%u" : "%d", | |
1171 | unpack_long (type, valaddr)); | |
1172 | #else | |
1173 | fprintf_filtered (stream, | |
1174 | TYPE_UNSIGNED (type) ? "%llu" : "%lld", | |
1175 | unpack_long (type, valaddr)); | |
1176 | #endif | |
1177 | #endif | |
1178 | ||
1179 | if (TYPE_LENGTH (type) == 1) | |
1180 | { | |
1181 | fprintf_filtered (stream, " '"); | |
1182 | printchar ((unsigned char) unpack_long (type, valaddr), | |
1183 | stream, '\''); | |
1184 | fprintf_filtered (stream, "'"); | |
1185 | } | |
1186 | break; | |
1187 | ||
1188 | case TYPE_CODE_FLT: | |
1189 | if (format) | |
1190 | print_scalar_formatted (valaddr, type, format, 0, stream); | |
1191 | else | |
1192 | print_floating (valaddr, type, stream); | |
1193 | break; | |
1194 | ||
1195 | case TYPE_CODE_VOID: | |
1196 | fprintf_filtered (stream, "void"); | |
1197 | break; | |
1198 | ||
1199 | case TYPE_CODE_UNDEF: | |
1200 | /* This happens (without TYPE_FLAG_STUB set) on systems which don't use | |
1201 | dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar" | |
1202 | and no complete type for struct foo in that file. */ | |
1203 | fprintf_filtered (stream, "<unknown struct>"); | |
1204 | break; | |
1205 | ||
1206 | case TYPE_CODE_ERROR: | |
1207 | fprintf_filtered (stream, "?"); | |
1208 | break; | |
1209 | ||
e2aab031 FF |
1210 | case TYPE_CODE_RANGE: |
1211 | /* FIXME, we should not ever have to print one of these yet. */ | |
1212 | fprintf_filtered (stream, "<range type>"); | |
1213 | break; | |
1214 | ||
bd5635a1 RP |
1215 | default: |
1216 | error ("Invalid type code in symbol table."); | |
1217 | } | |
1218 | fflush (stream); | |
1219 | return 0; | |
1220 | } | |
1221 | \f | |
be3bc7ad JG |
1222 | /* Print a description of a type in the format of a |
1223 | typedef for the current language. | |
1224 | NEW is the new name for a type TYPE. */ | |
1225 | void | |
1226 | typedef_print (type, new, stream) | |
1227 | struct type *type; | |
1228 | struct symbol *new; | |
1229 | FILE *stream; | |
1230 | { | |
1231 | switch (current_language->la_language) | |
1232 | { | |
1233 | #ifdef _LANG_c | |
1234 | case language_c: | |
7d9884b9 | 1235 | case language_cplus: |
be3bc7ad JG |
1236 | fprintf_filtered(stream, "typedef "); |
1237 | type_print(type,"",stream,0); | |
1238 | if(TYPE_NAME ((SYMBOL_TYPE (new))) == 0 | |
1239 | || 0 != strcmp (TYPE_NAME ((SYMBOL_TYPE (new))), | |
1240 | SYMBOL_NAME (new))) | |
1241 | fprintf_filtered(stream, " %s", SYMBOL_NAME(new)); | |
1242 | break; | |
1243 | #endif | |
1244 | #ifdef _LANG_m2 | |
1245 | case language_m2: | |
1246 | fprintf_filtered(stream, "TYPE "); | |
1247 | if(!TYPE_NAME(SYMBOL_TYPE(new)) || | |
1248 | strcmp (TYPE_NAME(SYMBOL_TYPE(new)), | |
1249 | SYMBOL_NAME(new))) | |
1250 | fprintf_filtered(stream, "%s = ", SYMBOL_NAME(new)); | |
1251 | else | |
1252 | fprintf_filtered(stream, "<builtin> = "); | |
1253 | type_print(type,"",stream,0); | |
1254 | break; | |
1255 | #endif | |
1256 | default: | |
1257 | error("Language not supported."); | |
1258 | } | |
1259 | fprintf_filtered(stream, ";\n"); | |
1260 | } | |
1261 | ||
1262 | ||
bd5635a1 RP |
1263 | /* Print a description of a type TYPE |
1264 | in the form of a declaration of a variable named VARSTRING. | |
1265 | (VARSTRING is demangled if necessary.) | |
1266 | Output goes to STREAM (via stdio). | |
1267 | If SHOW is positive, we show the contents of the outermost level | |
1268 | of structure even if there is a type name that could be used instead. | |
1269 | If SHOW is negative, we never show the details of elements' types. */ | |
1270 | ||
1271 | void | |
1272 | type_print (type, varstring, stream, show) | |
1273 | struct type *type; | |
1274 | char *varstring; | |
1275 | FILE *stream; | |
1276 | int show; | |
1277 | { | |
1278 | type_print_1 (type, varstring, stream, show, 0); | |
1279 | } | |
1280 | ||
1281 | /* LEVEL is the depth to indent lines by. */ | |
1282 | ||
1283 | void | |
1284 | type_print_1 (type, varstring, stream, show, level) | |
1285 | struct type *type; | |
1286 | char *varstring; | |
1287 | FILE *stream; | |
1288 | int show; | |
1289 | int level; | |
1290 | { | |
1291 | register enum type_code code; | |
1292 | type_print_base (type, stream, show, level); | |
1293 | code = TYPE_CODE (type); | |
1294 | if ((varstring && *varstring) | |
1295 | || | |
1296 | /* Need a space if going to print stars or brackets; | |
1297 | but not if we will print just a type name. */ | |
1298 | ((show > 0 || TYPE_NAME (type) == 0) | |
1299 | && | |
1300 | (code == TYPE_CODE_PTR || code == TYPE_CODE_FUNC | |
1301 | || code == TYPE_CODE_METHOD | |
1302 | || code == TYPE_CODE_ARRAY | |
1303 | || code == TYPE_CODE_MEMBER | |
1304 | || code == TYPE_CODE_REF))) | |
1305 | fprintf_filtered (stream, " "); | |
1306 | type_print_varspec_prefix (type, stream, show, 0); | |
1307 | fputs_demangled (varstring, stream, -1); /* Print demangled name | |
1308 | without arguments */ | |
1309 | type_print_varspec_suffix (type, stream, show, 0); | |
1310 | } | |
1311 | ||
1312 | /* Print the method arguments ARGS to the file STREAM. */ | |
1313 | static void | |
1314 | type_print_method_args (args, prefix, varstring, staticp, stream) | |
1315 | struct type **args; | |
1316 | char *prefix, *varstring; | |
1317 | int staticp; | |
1318 | FILE *stream; | |
1319 | { | |
1320 | int i; | |
1321 | ||
1322 | fputs_filtered (" ", stream); | |
1323 | fputs_demangled (prefix, stream, 1); | |
1324 | fputs_demangled (varstring, stream, 1); | |
1325 | fputs_filtered (" (", stream); | |
1326 | if (args && args[!staticp] && args[!staticp]->code != TYPE_CODE_VOID) | |
1327 | { | |
1328 | i = !staticp; /* skip the class variable */ | |
1329 | while (1) | |
1330 | { | |
1331 | type_print (args[i++], "", stream, 0); | |
1332 | if (!args[i]) | |
1333 | { | |
1334 | fprintf_filtered (stream, " ..."); | |
1335 | break; | |
1336 | } | |
1337 | else if (args[i]->code != TYPE_CODE_VOID) | |
1338 | { | |
1339 | fprintf_filtered (stream, ", "); | |
1340 | } | |
1341 | else break; | |
1342 | } | |
1343 | } | |
1344 | fprintf_filtered (stream, ")"); | |
1345 | } | |
1346 | ||
1347 | /* If TYPE is a derived type, then print out derivation | |
1348 | information. Print out all layers of the type heirarchy | |
1349 | until we encounter one with multiple inheritance. | |
1350 | At that point, print out that ply, and return. */ | |
1351 | static void | |
1352 | type_print_derivation_info (stream, type) | |
1353 | FILE *stream; | |
1354 | struct type *type; | |
1355 | { | |
1356 | char *name; | |
1357 | int i, n_baseclasses = TYPE_N_BASECLASSES (type); | |
1358 | struct type *basetype = 0; | |
1359 | ||
1360 | while (type && n_baseclasses > 0) | |
1361 | { | |
1362 | /* Not actually sure about this one -- Bryan. */ | |
1363 | check_stub_type (type); | |
1364 | ||
1365 | fprintf_filtered (stream, ": "); | |
1366 | for (i = 0; ;) | |
1367 | { | |
1368 | basetype = TYPE_BASECLASS (type, i); | |
1369 | if (name = type_name_no_tag (basetype)) | |
1370 | { | |
1371 | fprintf_filtered (stream, "%s%s ", | |
1372 | BASETYPE_VIA_PUBLIC(type, i) ? "public" : "private", | |
1373 | BASETYPE_VIA_VIRTUAL(type, i) ? " virtual" : ""); | |
1374 | fputs_filtered (name, stream); | |
1375 | } | |
1376 | i++; | |
1377 | if (i >= n_baseclasses) | |
1378 | break; | |
1379 | fprintf_filtered (stream, ", "); | |
1380 | } | |
1381 | ||
1382 | fprintf_filtered (stream, " "); | |
1383 | if (n_baseclasses != 1) | |
1384 | break; | |
1385 | n_baseclasses = TYPE_N_BASECLASSES (basetype); | |
1386 | type = basetype; | |
1387 | } | |
1388 | } | |
1389 | ||
1390 | /* Print any asterisks or open-parentheses needed before the | |
1391 | variable name (to describe its type). | |
1392 | ||
1393 | On outermost call, pass 0 for PASSED_A_PTR. | |
1394 | On outermost call, SHOW > 0 means should ignore | |
1395 | any typename for TYPE and show its details. | |
1396 | SHOW is always zero on recursive calls. */ | |
1397 | ||
1398 | static void | |
1399 | type_print_varspec_prefix (type, stream, show, passed_a_ptr) | |
1400 | struct type *type; | |
1401 | FILE *stream; | |
1402 | int show; | |
1403 | int passed_a_ptr; | |
1404 | { | |
1405 | if (type == 0) | |
1406 | return; | |
1407 | ||
1408 | if (TYPE_NAME (type) && show <= 0) | |
1409 | return; | |
1410 | ||
1411 | QUIT; | |
1412 | ||
1413 | switch (TYPE_CODE (type)) | |
1414 | { | |
1415 | case TYPE_CODE_PTR: | |
1416 | type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 1); | |
1417 | fprintf_filtered (stream, "*"); | |
1418 | break; | |
1419 | ||
1420 | case TYPE_CODE_MEMBER: | |
1421 | if (passed_a_ptr) | |
1422 | fprintf_filtered (stream, "("); | |
1423 | type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, | |
1424 | 0); | |
1425 | fprintf_filtered (stream, " "); | |
1426 | type_print_base (TYPE_DOMAIN_TYPE (type), stream, 0, | |
1427 | passed_a_ptr); | |
1428 | fprintf_filtered (stream, "::"); | |
1429 | break; | |
1430 | ||
1431 | case TYPE_CODE_METHOD: | |
1432 | if (passed_a_ptr) | |
1433 | fprintf (stream, "("); | |
1434 | type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, | |
1435 | 0); | |
0dce3774 JK |
1436 | if (passed_a_ptr) |
1437 | { | |
1438 | fprintf_filtered (stream, " "); | |
1439 | type_print_base (TYPE_DOMAIN_TYPE (type), stream, 0, | |
1440 | passed_a_ptr); | |
1441 | fprintf_filtered (stream, "::"); | |
1442 | } | |
bd5635a1 RP |
1443 | break; |
1444 | ||
1445 | case TYPE_CODE_REF: | |
1446 | type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 1); | |
1447 | fprintf_filtered (stream, "&"); | |
1448 | break; | |
1449 | ||
1450 | case TYPE_CODE_FUNC: | |
1451 | type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, | |
1452 | 0); | |
1453 | if (passed_a_ptr) | |
1454 | fprintf_filtered (stream, "("); | |
1455 | break; | |
1456 | ||
1457 | case TYPE_CODE_ARRAY: | |
1458 | type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, | |
1459 | 0); | |
1460 | if (passed_a_ptr) | |
1461 | fprintf_filtered (stream, "("); | |
2a5ec41d | 1462 | break; |
bd5635a1 RP |
1463 | |
1464 | case TYPE_CODE_UNDEF: | |
1465 | case TYPE_CODE_STRUCT: | |
1466 | case TYPE_CODE_UNION: | |
1467 | case TYPE_CODE_ENUM: | |
1468 | case TYPE_CODE_INT: | |
1469 | case TYPE_CODE_FLT: | |
1470 | case TYPE_CODE_VOID: | |
1471 | case TYPE_CODE_ERROR: | |
7d9884b9 JG |
1472 | case TYPE_CODE_CHAR: |
1473 | case TYPE_CODE_BOOL: | |
bd5635a1 RP |
1474 | /* These types need no prefix. They are listed here so that |
1475 | gcc -Wall will reveal any types that haven't been handled. */ | |
1476 | break; | |
1477 | } | |
1478 | } | |
1479 | ||
1480 | /* Print any array sizes, function arguments or close parentheses | |
1481 | needed after the variable name (to describe its type). | |
1482 | Args work like type_print_varspec_prefix. */ | |
1483 | ||
1484 | static void | |
1485 | type_print_varspec_suffix (type, stream, show, passed_a_ptr) | |
1486 | struct type *type; | |
1487 | FILE *stream; | |
1488 | int show; | |
1489 | int passed_a_ptr; | |
1490 | { | |
1491 | if (type == 0) | |
1492 | return; | |
1493 | ||
1494 | if (TYPE_NAME (type) && show <= 0) | |
1495 | return; | |
1496 | ||
1497 | QUIT; | |
1498 | ||
1499 | switch (TYPE_CODE (type)) | |
1500 | { | |
1501 | case TYPE_CODE_ARRAY: | |
1502 | if (passed_a_ptr) | |
1503 | fprintf_filtered (stream, ")"); | |
1504 | ||
1505 | fprintf_filtered (stream, "["); | |
bee3c1a1 JG |
1506 | if (TYPE_LENGTH (type) > 0 |
1507 | && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0) | |
bd5635a1 RP |
1508 | fprintf_filtered (stream, "%d", |
1509 | (TYPE_LENGTH (type) | |
1510 | / TYPE_LENGTH (TYPE_TARGET_TYPE (type)))); | |
1511 | fprintf_filtered (stream, "]"); | |
1512 | ||
1513 | type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, | |
1514 | 0); | |
1515 | break; | |
1516 | ||
1517 | case TYPE_CODE_MEMBER: | |
1518 | if (passed_a_ptr) | |
1519 | fprintf_filtered (stream, ")"); | |
1520 | type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0); | |
1521 | break; | |
1522 | ||
1523 | case TYPE_CODE_METHOD: | |
1524 | if (passed_a_ptr) | |
1525 | fprintf_filtered (stream, ")"); | |
1526 | type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0); | |
1527 | if (passed_a_ptr) | |
1528 | { | |
1529 | int i; | |
1530 | struct type **args = TYPE_ARG_TYPES (type); | |
1531 | ||
1532 | fprintf_filtered (stream, "("); | |
1533 | if (args[1] == 0) | |
1534 | fprintf_filtered (stream, "..."); | |
1535 | else for (i = 1; args[i] != 0 && args[i]->code != TYPE_CODE_VOID; i++) | |
1536 | { | |
1537 | type_print_1 (args[i], "", stream, -1, 0); | |
1538 | if (args[i+1] == 0) | |
1539 | fprintf_filtered (stream, "..."); | |
8ffd75c8 | 1540 | else if (args[i+1]->code != TYPE_CODE_VOID) { |
bd5635a1 | 1541 | fprintf_filtered (stream, ","); |
8ffd75c8 JG |
1542 | wrap_here (" "); |
1543 | } | |
bd5635a1 RP |
1544 | } |
1545 | fprintf_filtered (stream, ")"); | |
1546 | } | |
1547 | break; | |
1548 | ||
1549 | case TYPE_CODE_PTR: | |
1550 | case TYPE_CODE_REF: | |
1551 | type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 1); | |
1552 | break; | |
1553 | ||
1554 | case TYPE_CODE_FUNC: | |
1555 | type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, | |
1556 | passed_a_ptr); | |
1557 | if (passed_a_ptr) | |
1558 | fprintf_filtered (stream, ")"); | |
1559 | fprintf_filtered (stream, "()"); | |
1560 | break; | |
1561 | ||
1562 | case TYPE_CODE_UNDEF: | |
1563 | case TYPE_CODE_STRUCT: | |
1564 | case TYPE_CODE_UNION: | |
1565 | case TYPE_CODE_ENUM: | |
1566 | case TYPE_CODE_INT: | |
1567 | case TYPE_CODE_FLT: | |
1568 | case TYPE_CODE_VOID: | |
1569 | case TYPE_CODE_ERROR: | |
7d9884b9 JG |
1570 | case TYPE_CODE_CHAR: |
1571 | case TYPE_CODE_BOOL: | |
bd5635a1 RP |
1572 | /* These types do not need a suffix. They are listed so that |
1573 | gcc -Wall will report types that may not have been considered. */ | |
1574 | break; | |
1575 | } | |
1576 | } | |
1577 | ||
1578 | /* Print the name of the type (or the ultimate pointer target, | |
1579 | function value or array element), or the description of a | |
1580 | structure or union. | |
1581 | ||
1582 | SHOW nonzero means don't print this type as just its name; | |
1583 | show its real definition even if it has a name. | |
1584 | SHOW zero means print just typename or struct tag if there is one | |
1585 | SHOW negative means abbreviate structure elements. | |
1586 | SHOW is decremented for printing of structure elements. | |
1587 | ||
1588 | LEVEL is the depth to indent by. | |
1589 | We increase it for some recursive calls. */ | |
1590 | ||
1591 | static void | |
1592 | type_print_base (type, stream, show, level) | |
1593 | struct type *type; | |
1594 | FILE *stream; | |
1595 | int show; | |
1596 | int level; | |
1597 | { | |
1598 | char *name; | |
1599 | register int i; | |
1600 | register int len; | |
1601 | register int lastval; | |
1602 | ||
1603 | QUIT; | |
1604 | ||
8ffd75c8 | 1605 | wrap_here (" "); |
bd5635a1 RP |
1606 | if (type == 0) |
1607 | { | |
e2aab031 | 1608 | fprintf_filtered (stream, "<type unknown>"); |
bd5635a1 RP |
1609 | return; |
1610 | } | |
1611 | ||
1612 | if (TYPE_NAME (type) && show <= 0) | |
1613 | { | |
1614 | fputs_filtered (TYPE_NAME (type), stream); | |
1615 | return; | |
1616 | } | |
1617 | ||
1618 | switch (TYPE_CODE (type)) | |
1619 | { | |
1620 | case TYPE_CODE_ARRAY: | |
1621 | case TYPE_CODE_PTR: | |
1622 | case TYPE_CODE_MEMBER: | |
1623 | case TYPE_CODE_REF: | |
1624 | case TYPE_CODE_FUNC: | |
1625 | case TYPE_CODE_METHOD: | |
1626 | type_print_base (TYPE_TARGET_TYPE (type), stream, show, level); | |
1627 | break; | |
1628 | ||
1629 | case TYPE_CODE_STRUCT: | |
1630 | fprintf_filtered (stream, "struct "); | |
1631 | goto struct_union; | |
1632 | ||
1633 | case TYPE_CODE_UNION: | |
1634 | fprintf_filtered (stream, "union "); | |
1635 | struct_union: | |
1636 | if (name = type_name_no_tag (type)) | |
1637 | { | |
1638 | fputs_filtered (name, stream); | |
1639 | fputs_filtered (" ", stream); | |
8ffd75c8 | 1640 | wrap_here (" "); |
bd5635a1 RP |
1641 | } |
1642 | if (show < 0) | |
1643 | fprintf_filtered (stream, "{...}"); | |
1644 | else | |
1645 | { | |
1646 | check_stub_type (type); | |
1647 | ||
1648 | type_print_derivation_info (stream, type); | |
1649 | ||
1650 | fprintf_filtered (stream, "{"); | |
1651 | len = TYPE_NFIELDS (type); | |
1652 | if (len) | |
1653 | fprintf_filtered (stream, "\n"); | |
1654 | else | |
1655 | { | |
1656 | if (TYPE_FLAGS (type) & TYPE_FLAG_STUB) | |
1657 | fprintf_filtered (stream, "<incomplete type>\n"); | |
1658 | else | |
1659 | fprintf_filtered (stream, "<no data fields>\n"); | |
1660 | } | |
1661 | ||
1662 | /* If there is a base class for this type, | |
1663 | do not print the field that it occupies. */ | |
1664 | for (i = TYPE_N_BASECLASSES (type); i < len; i++) | |
1665 | { | |
1666 | QUIT; | |
1667 | /* Don't print out virtual function table. */ | |
1668 | if ((TYPE_FIELD_NAME (type, i))[5] == CPLUS_MARKER && | |
1669 | !strncmp (TYPE_FIELD_NAME (type, i), "_vptr", 5)) | |
1670 | continue; | |
1671 | ||
1672 | print_spaces_filtered (level + 4, stream); | |
1673 | if (TYPE_FIELD_STATIC (type, i)) | |
1674 | { | |
1675 | fprintf_filtered (stream, "static "); | |
1676 | } | |
1677 | type_print_1 (TYPE_FIELD_TYPE (type, i), | |
1678 | TYPE_FIELD_NAME (type, i), | |
1679 | stream, show - 1, level + 4); | |
1680 | if (!TYPE_FIELD_STATIC (type, i) | |
1681 | && TYPE_FIELD_PACKED (type, i)) | |
1682 | { | |
1683 | /* It is a bitfield. This code does not attempt | |
1684 | to look at the bitpos and reconstruct filler, | |
1685 | unnamed fields. This would lead to misleading | |
1686 | results if the compiler does not put out fields | |
1687 | for such things (I don't know what it does). */ | |
1688 | fprintf_filtered (stream, " : %d", | |
1689 | TYPE_FIELD_BITSIZE (type, i)); | |
1690 | } | |
1691 | fprintf_filtered (stream, ";\n"); | |
1692 | } | |
1693 | ||
1694 | /* C++: print out the methods */ | |
1695 | len = TYPE_NFN_FIELDS (type); | |
1696 | if (len) fprintf_filtered (stream, "\n"); | |
1697 | for (i = 0; i < len; i++) | |
1698 | { | |
1699 | struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i); | |
1700 | int j, len2 = TYPE_FN_FIELDLIST_LENGTH (type, i); | |
1701 | ||
1702 | for (j = 0; j < len2; j++) | |
1703 | { | |
1704 | QUIT; | |
1705 | print_spaces_filtered (level + 4, stream); | |
1706 | if (TYPE_FN_FIELD_VIRTUAL_P (f, j)) | |
1707 | fprintf_filtered (stream, "virtual "); | |
1708 | else if (TYPE_FN_FIELD_STATIC_P (f, j)) | |
1709 | fprintf_filtered (stream, "static "); | |
aec4cb91 MT |
1710 | if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)) == 0) |
1711 | { | |
1712 | /* Keep GDB from crashing here. */ | |
1713 | fprintf (stream, "<undefined type> %s;\n", | |
1714 | TYPE_FN_FIELD_PHYSNAME (f, j)); | |
1715 | break; | |
1716 | } | |
1717 | else | |
1718 | type_print (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)), "", stream, 0); | |
bd5635a1 RP |
1719 | if (TYPE_FLAGS (TYPE_FN_FIELD_TYPE (f, j)) & TYPE_FLAG_STUB) |
1720 | { | |
1721 | /* Build something we can demangle. */ | |
bcccec8c PB |
1722 | char *strchr (), *gdb_mangle_name (), *cplus_demangle (); |
1723 | char *mangled_name = gdb_mangle_name (type, i, j); | |
1724 | char *demangled_name = cplus_demangle (mangled_name, 1); | |
bd5635a1 RP |
1725 | if (demangled_name == 0) |
1726 | fprintf_filtered (stream, " <badly mangled name %s>", | |
1727 | mangled_name); | |
1728 | else | |
1729 | { | |
1730 | fprintf_filtered (stream, " %s", | |
1731 | strchr (demangled_name, ':') + 2); | |
1732 | free (demangled_name); | |
1733 | } | |
1734 | free (mangled_name); | |
1735 | } | |
1736 | else if (TYPE_FN_FIELD_PHYSNAME (f, j)[0] == '_' | |
1737 | && TYPE_FN_FIELD_PHYSNAME (f, j)[1] == CPLUS_MARKER) | |
1738 | type_print_method_args | |
1739 | (TYPE_FN_FIELD_ARGS (f, j) + 1, "~", | |
1740 | TYPE_FN_FIELDLIST_NAME (type, i), 0, stream); | |
1741 | else | |
1742 | type_print_method_args | |
1743 | (TYPE_FN_FIELD_ARGS (f, j), "", | |
1744 | TYPE_FN_FIELDLIST_NAME (type, i), | |
1745 | TYPE_FN_FIELD_STATIC_P (f, j), stream); | |
1746 | ||
1747 | fprintf_filtered (stream, ";\n"); | |
1748 | } | |
1749 | } | |
1750 | ||
1751 | print_spaces_filtered (level, stream); | |
1752 | fprintf_filtered (stream, "}"); | |
1753 | } | |
1754 | break; | |
1755 | ||
1756 | case TYPE_CODE_ENUM: | |
1757 | fprintf_filtered (stream, "enum "); | |
1758 | if (name = type_name_no_tag (type)) | |
1759 | { | |
1760 | fputs_filtered (name, stream); | |
1761 | fputs_filtered (" ", stream); | |
1762 | } | |
8ffd75c8 | 1763 | wrap_here (" "); |
bd5635a1 RP |
1764 | if (show < 0) |
1765 | fprintf_filtered (stream, "{...}"); | |
1766 | else | |
1767 | { | |
1768 | fprintf_filtered (stream, "{"); | |
1769 | len = TYPE_NFIELDS (type); | |
1770 | lastval = 0; | |
1771 | for (i = 0; i < len; i++) | |
1772 | { | |
1773 | QUIT; | |
1774 | if (i) fprintf_filtered (stream, ", "); | |
8ffd75c8 | 1775 | wrap_here (" "); |
bd5635a1 RP |
1776 | fputs_filtered (TYPE_FIELD_NAME (type, i), stream); |
1777 | if (lastval != TYPE_FIELD_BITPOS (type, i)) | |
1778 | { | |
1779 | fprintf_filtered (stream, " = %d", TYPE_FIELD_BITPOS (type, i)); | |
1780 | lastval = TYPE_FIELD_BITPOS (type, i); | |
1781 | } | |
1782 | lastval++; | |
1783 | } | |
1784 | fprintf_filtered (stream, "}"); | |
1785 | } | |
1786 | break; | |
1787 | ||
1788 | case TYPE_CODE_INT: | |
bee3c1a1 JG |
1789 | name = 0; |
1790 | if (TYPE_LENGTH (type) <= sizeof (LONGEST)) | |
bd5635a1 RP |
1791 | { |
1792 | if (TYPE_UNSIGNED (type)) | |
1793 | name = unsigned_type_table[TYPE_LENGTH (type)]; | |
1794 | else | |
1795 | name = signed_type_table[TYPE_LENGTH (type)]; | |
1796 | } | |
bee3c1a1 JG |
1797 | if (name) |
1798 | fputs_filtered (name, stream); | |
1799 | else | |
1800 | fprintf_filtered (stream, "<%d bit integer>", | |
1801 | TYPE_LENGTH (type) * TARGET_CHAR_BIT); | |
bd5635a1 RP |
1802 | break; |
1803 | ||
1804 | case TYPE_CODE_FLT: | |
1805 | name = float_type_table[TYPE_LENGTH (type)]; | |
1806 | fputs_filtered (name, stream); | |
1807 | break; | |
1808 | ||
1809 | case TYPE_CODE_VOID: | |
1810 | fprintf_filtered (stream, "void"); | |
1811 | break; | |
1812 | ||
e2aab031 FF |
1813 | case TYPE_CODE_UNDEF: |
1814 | fprintf_filtered (stream, "struct <unknown>"); | |
bd5635a1 RP |
1815 | break; |
1816 | ||
1817 | case TYPE_CODE_ERROR: | |
1818 | fprintf_filtered (stream, "<unknown type>"); | |
1819 | break; | |
1820 | ||
e2aab031 FF |
1821 | case TYPE_CODE_RANGE: |
1822 | /* This should not occur */ | |
1823 | fprintf_filtered (stream, "<range type>"); | |
1824 | break; | |
1825 | ||
bd5635a1 RP |
1826 | default: |
1827 | error ("Invalid type code in symbol table."); | |
1828 | } | |
1829 | } | |
1830 | \f | |
e1ce8aa5 | 1831 | #if 0 |
bd5635a1 RP |
1832 | /* Validate an input or output radix setting, and make sure the user |
1833 | knows what they really did here. Radix setting is confusing, e.g. | |
1834 | setting the input radix to "10" never changes it! */ | |
1835 | ||
e1ce8aa5 | 1836 | /* ARGSUSED */ |
bd5635a1 RP |
1837 | static void |
1838 | set_input_radix (args, from_tty, c) | |
1839 | char *args; | |
1840 | int from_tty; | |
1841 | struct cmd_list_element *c; | |
1842 | { | |
1843 | unsigned radix = *(unsigned *)c->var; | |
1844 | ||
1845 | if (from_tty) | |
1846 | printf_filtered ("Input radix set to decimal %d, hex %x, octal %o\n", | |
1847 | radix, radix, radix); | |
1848 | } | |
e1ce8aa5 | 1849 | #endif |
bd5635a1 | 1850 | |
e1ce8aa5 | 1851 | /* ARGSUSED */ |
bd5635a1 RP |
1852 | static void |
1853 | set_output_radix (args, from_tty, c) | |
1854 | char *args; | |
1855 | int from_tty; | |
1856 | struct cmd_list_element *c; | |
1857 | { | |
1858 | unsigned radix = *(unsigned *)c->var; | |
1859 | ||
1860 | if (from_tty) | |
1861 | printf_filtered ("Output radix set to decimal %d, hex %x, octal %o\n", | |
1862 | radix, radix, radix); | |
1863 | ||
1864 | /* FIXME, we really should be able to validate the setting BEFORE | |
1865 | it takes effect. */ | |
1866 | switch (radix) | |
1867 | { | |
1868 | case 16: | |
1869 | output_format = 'x'; | |
1870 | break; | |
1871 | case 10: | |
1872 | output_format = 0; | |
1873 | break; | |
1874 | case 8: | |
1875 | output_format = 'o'; /* octal */ | |
1876 | break; | |
1877 | default: | |
1878 | output_format = 0; | |
1879 | error ("Unsupported radix ``decimal %d''; using decimal output", | |
1880 | radix); | |
1881 | } | |
1882 | } | |
1883 | ||
1884 | /* Both at once */ | |
1885 | static void | |
1886 | set_radix (arg, from_tty, c) | |
1887 | char *arg; | |
1888 | int from_tty; | |
1889 | struct cmd_list_element *c; | |
1890 | { | |
1891 | unsigned radix = *(unsigned *)c->var; | |
1892 | ||
1893 | if (from_tty) | |
1894 | printf_filtered ("Radix set to decimal %d, hex %x, octal %o\n", | |
1895 | radix, radix, radix); | |
1896 | ||
1897 | input_radix = radix; | |
1898 | output_radix = radix; | |
1899 | ||
1900 | set_output_radix (arg, 0, c); | |
1901 | } | |
1902 | \f | |
f266e564 JK |
1903 | struct cmd_list_element *setprintlist = NULL; |
1904 | struct cmd_list_element *showprintlist = NULL; | |
1905 | ||
1906 | /*ARGSUSED*/ | |
1907 | static void | |
1908 | set_print (arg, from_tty) | |
1909 | char *arg; | |
1910 | int from_tty; | |
1911 | { | |
1912 | printf ( | |
1913 | "\"set print\" must be followed by the name of a print subcommand.\n"); | |
1914 | help_list (setprintlist, "set print ", -1, stdout); | |
1915 | } | |
1916 | ||
1917 | /*ARGSUSED*/ | |
1918 | static void | |
1919 | show_print (args, from_tty) | |
1920 | char *args; | |
1921 | int from_tty; | |
1922 | { | |
1923 | cmd_show_list (showprintlist, from_tty, ""); | |
1924 | } | |
1925 | \f | |
bd5635a1 RP |
1926 | void |
1927 | _initialize_valprint () | |
1928 | { | |
1929 | struct cmd_list_element *c; | |
1930 | ||
f266e564 JK |
1931 | add_prefix_cmd ("print", no_class, set_print, |
1932 | "Generic command for setting how things print.", | |
1933 | &setprintlist, "set print ", 0, &setlist); | |
36b9d39c JG |
1934 | add_alias_cmd ("p", "print", no_class, 1, &setlist); |
1935 | add_alias_cmd ("pr", "print", no_class, 1, &setlist); /* prefer set print | |
1936 | to set prompt */ | |
f266e564 JK |
1937 | add_prefix_cmd ("print", no_class, show_print, |
1938 | "Generic command for showing print settings.", | |
1939 | &showprintlist, "show print ", 0, &showlist); | |
36b9d39c JG |
1940 | add_alias_cmd ("p", "print", no_class, 1, &showlist); |
1941 | add_alias_cmd ("pr", "print", no_class, 1, &showlist); | |
f266e564 | 1942 | |
bd5635a1 | 1943 | add_show_from_set |
f266e564 | 1944 | (add_set_cmd ("elements", no_class, var_uinteger, (char *)&print_max, |
bd5635a1 | 1945 | "Set limit on string chars or array elements to print.\n\ |
f266e564 JK |
1946 | \"set print elements 0\" causes there to be no limit.", |
1947 | &setprintlist), | |
1948 | &showprintlist); | |
bd5635a1 RP |
1949 | |
1950 | add_show_from_set | |
f266e564 | 1951 | (add_set_cmd ("pretty", class_support, var_boolean, (char *)&prettyprint, |
bd5635a1 | 1952 | "Set prettyprinting of structures.", |
f266e564 JK |
1953 | &setprintlist), |
1954 | &showprintlist); | |
bd5635a1 RP |
1955 | |
1956 | add_show_from_set | |
f266e564 | 1957 | (add_set_cmd ("union", class_support, var_boolean, (char *)&unionprint, |
bd5635a1 | 1958 | "Set printing of unions interior to structures.", |
f266e564 JK |
1959 | &setprintlist), |
1960 | &showprintlist); | |
bd5635a1 RP |
1961 | |
1962 | add_show_from_set | |
f266e564 | 1963 | (add_set_cmd ("vtbl", class_support, var_boolean, (char *)&vtblprint, |
bd5635a1 | 1964 | "Set printing of C++ virtual function tables.", |
f266e564 JK |
1965 | &setprintlist), |
1966 | &showprintlist); | |
bd5635a1 RP |
1967 | |
1968 | add_show_from_set | |
f266e564 | 1969 | (add_set_cmd ("array", class_support, var_boolean, (char *)&arrayprint, |
bd5635a1 | 1970 | "Set prettyprinting of arrays.", |
f266e564 JK |
1971 | &setprintlist), |
1972 | &showprintlist); | |
bd5635a1 | 1973 | |
0dce3774 JK |
1974 | add_show_from_set |
1975 | (add_set_cmd ("object", class_support, var_boolean, (char *)&objectprint, | |
1976 | "Set printing of object's derived type based on vtable info.", | |
1977 | &setprintlist), | |
1978 | &showprintlist); | |
1979 | ||
bd5635a1 | 1980 | add_show_from_set |
f266e564 | 1981 | (add_set_cmd ("address", class_support, var_boolean, (char *)&addressprint, |
bd5635a1 | 1982 | "Set printing of addresses.", |
f266e564 JK |
1983 | &setprintlist), |
1984 | &showprintlist); | |
bd5635a1 RP |
1985 | |
1986 | #if 0 | |
1987 | /* The "show radix" cmd isn't good enough to show two separate values. | |
1988 | The rest of the code works, but the show part is confusing, so don't | |
1989 | let them be set separately 'til we work out "show". */ | |
1990 | c = add_set_cmd ("input-radix", class_support, var_uinteger, | |
1991 | (char *)&input_radix, | |
1992 | "Set default input radix for entering numbers.", | |
1993 | &setlist); | |
1994 | add_show_from_set (c, &showlist); | |
1995 | c->function = set_input_radix; | |
1996 | ||
1997 | c = add_set_cmd ("output-radix", class_support, var_uinteger, | |
1998 | (char *)&output_radix, | |
1999 | "Set default output radix for printing of values.", | |
2000 | &setlist); | |
2001 | add_show_from_set (c, &showlist); | |
2002 | c->function = set_output_radix; | |
2003 | #endif | |
2004 | ||
2005 | c = add_set_cmd ("radix", class_support, var_uinteger, | |
2006 | (char *)&output_radix, | |
2007 | "Set default input and output number radix.", | |
2008 | &setlist); | |
2009 | add_show_from_set (c, &showlist); | |
2010 | c->function = set_radix; | |
2011 | ||
2012 | /* Give people the defaults which they are used to. */ | |
2013 | prettyprint = 0; | |
2014 | unionprint = 1; | |
2015 | vtblprint = 0; | |
2016 | arrayprint = 0; | |
2017 | addressprint = 1; | |
0dce3774 | 2018 | objectprint = 0; |
bd5635a1 RP |
2019 | |
2020 | print_max = 200; | |
2021 | ||
e2aab031 FF |
2022 | /* Initialize the names of the various types based on their lengths on |
2023 | the target, in bits. Note that ordering is important, so that for example, | |
2024 | if ints and longs are the same size, that size will default to "int". */ | |
2025 | ||
2026 | unsigned_type_table = (char **) | |
2027 | xmalloc ((1 + (TARGET_LONG_LONG_BIT/TARGET_CHAR_BIT)) * sizeof (char *)); | |
2028 | bzero (unsigned_type_table, (1 + (TARGET_LONG_LONG_BIT/TARGET_CHAR_BIT))); | |
2029 | unsigned_type_table[TARGET_CHAR_BIT/TARGET_CHAR_BIT] = "unsigned char"; | |
2030 | unsigned_type_table[TARGET_SHORT_BIT/TARGET_CHAR_BIT] = "unsigned short"; | |
2031 | unsigned_type_table[TARGET_LONG_LONG_BIT/TARGET_CHAR_BIT] = "unsigned long long"; | |
2032 | unsigned_type_table[TARGET_LONG_BIT/TARGET_CHAR_BIT] = "unsigned long"; | |
2033 | unsigned_type_table[TARGET_INT_BIT/TARGET_CHAR_BIT] = "unsigned int"; | |
2034 | ||
2035 | signed_type_table = (char **) | |
2036 | xmalloc ((1 + (TARGET_LONG_LONG_BIT/TARGET_CHAR_BIT)) * sizeof (char *)); | |
2037 | bzero (signed_type_table, (1 + (TARGET_LONG_LONG_BIT/TARGET_CHAR_BIT))); | |
2038 | signed_type_table[TARGET_CHAR_BIT/TARGET_CHAR_BIT] = "char"; | |
2039 | signed_type_table[TARGET_SHORT_BIT/TARGET_CHAR_BIT] = "short"; | |
bee3c1a1 | 2040 | signed_type_table[TARGET_LONG_LONG_BIT/TARGET_CHAR_BIT] = "long long"; |
e2aab031 FF |
2041 | signed_type_table[TARGET_LONG_BIT/TARGET_CHAR_BIT] = "long"; |
2042 | signed_type_table[TARGET_INT_BIT/TARGET_CHAR_BIT] = "int"; | |
2043 | ||
2044 | float_type_table = (char **) | |
2045 | xmalloc ((1 + (TARGET_LONG_DOUBLE_BIT/TARGET_CHAR_BIT)) * sizeof (char *)); | |
2046 | bzero (float_type_table, (1 + (TARGET_LONG_DOUBLE_BIT/TARGET_CHAR_BIT))); | |
2047 | float_type_table[TARGET_FLOAT_BIT/TARGET_CHAR_BIT] = "float"; | |
2048 | float_type_table[TARGET_DOUBLE_COMPLEX_BIT/TARGET_CHAR_BIT] = "double complex"; | |
2049 | float_type_table[TARGET_COMPLEX_BIT/TARGET_CHAR_BIT] = "complex"; | |
2050 | float_type_table[TARGET_LONG_DOUBLE_BIT/TARGET_CHAR_BIT] = "long double"; | |
2051 | float_type_table[TARGET_DOUBLE_BIT/TARGET_CHAR_BIT] = "double"; | |
bd5635a1 | 2052 | |
bd5635a1 RP |
2053 | obstack_begin (&dont_print_obstack, 32 * sizeof (struct type *)); |
2054 | } |