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