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