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