Allow really large fortran array bounds: TYPE_LENGTH to ULONGEST
[binutils-gdb.git] / gdb / typeprint.c
1 /* Language independent support for printing types for GDB, the GNU debugger.
2
3 Copyright (C) 1986-2019 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 #include "defs.h"
21 #include "gdb_obstack.h"
22 #include "bfd.h" /* Binary File Description */
23 #include "symtab.h"
24 #include "gdbtypes.h"
25 #include "expression.h"
26 #include "value.h"
27 #include "gdbcore.h"
28 #include "command.h"
29 #include "gdbcmd.h"
30 #include "target.h"
31 #include "language.h"
32 #include "cp-abi.h"
33 #include "typeprint.h"
34 #include "valprint.h"
35 #include <ctype.h>
36 #include "cli/cli-utils.h"
37 #include "extension.h"
38 #include "completer.h"
39
40 const struct type_print_options type_print_raw_options =
41 {
42 1, /* raw */
43 1, /* print_methods */
44 1, /* print_typedefs */
45 0, /* print_offsets */
46 0, /* print_nested_type_limit */
47 NULL, /* local_typedefs */
48 NULL, /* global_table */
49 NULL /* global_printers */
50 };
51
52 /* The default flags for 'ptype' and 'whatis'. */
53
54 static struct type_print_options default_ptype_flags =
55 {
56 0, /* raw */
57 1, /* print_methods */
58 1, /* print_typedefs */
59 0, /* print_offsets */
60 0, /* print_nested_type_limit */
61 NULL, /* local_typedefs */
62 NULL, /* global_table */
63 NULL /* global_printers */
64 };
65
66 \f
67
68 /* See typeprint.h. */
69
70 const int print_offset_data::indentation = 23;
71
72
73 /* See typeprint.h. */
74
75 void
76 print_offset_data::maybe_print_hole (struct ui_file *stream,
77 unsigned int bitpos,
78 const char *for_what)
79 {
80 /* We check for END_BITPOS > 0 because there is a specific
81 scenario when END_BITPOS can be zero and BITPOS can be >
82 0: when we are dealing with a struct/class with a virtual method.
83 Because of the vtable, the first field of the struct/class will
84 have an offset of sizeof (void *) (the size of the vtable). If
85 we do not check for END_BITPOS > 0 here, GDB will report
86 a hole before the first field, which is not accurate. */
87 if (end_bitpos > 0 && end_bitpos < bitpos)
88 {
89 /* If END_BITPOS is smaller than the current type's
90 bitpos, it means there's a hole in the struct, so we report
91 it here. */
92 unsigned int hole = bitpos - end_bitpos;
93 unsigned int hole_byte = hole / TARGET_CHAR_BIT;
94 unsigned int hole_bit = hole % TARGET_CHAR_BIT;
95
96 if (hole_bit > 0)
97 fprintf_filtered (stream, "/* XXX %2u-bit %s */\n", hole_bit,
98 for_what);
99
100 if (hole_byte > 0)
101 fprintf_filtered (stream, "/* XXX %2u-byte %s */\n", hole_byte,
102 for_what);
103 }
104 }
105
106 /* See typeprint.h. */
107
108 void
109 print_offset_data::update (struct type *type, unsigned int field_idx,
110 struct ui_file *stream)
111 {
112 if (field_is_static (&TYPE_FIELD (type, field_idx)))
113 {
114 print_spaces_filtered (indentation, stream);
115 return;
116 }
117
118 struct type *ftype = check_typedef (TYPE_FIELD_TYPE (type, field_idx));
119 if (TYPE_CODE (type) == TYPE_CODE_UNION)
120 {
121 /* Since union fields don't have the concept of offsets, we just
122 print their sizes. */
123 fprintf_filtered (stream, "/* %4s */",
124 pulongest (TYPE_LENGTH (ftype)));
125 return;
126 }
127
128 unsigned int bitpos = TYPE_FIELD_BITPOS (type, field_idx);
129 unsigned int fieldsize_byte = TYPE_LENGTH (ftype);
130 unsigned int fieldsize_bit = fieldsize_byte * TARGET_CHAR_BIT;
131
132 maybe_print_hole (stream, bitpos, "hole");
133
134 if (TYPE_FIELD_PACKED (type, field_idx))
135 {
136 /* We're dealing with a bitfield. Print how many bits are left
137 to be used. */
138 unsigned int bitsize = TYPE_FIELD_BITSIZE (type, field_idx);
139 /* The bitpos relative to the beginning of our container
140 field. */
141 unsigned int relative_bitpos;
142
143 /* The following was copied from
144 value.c:value_primitive_field. */
145 if ((bitpos % fieldsize_bit) + bitsize <= fieldsize_bit)
146 relative_bitpos = bitpos % fieldsize_bit;
147 else
148 relative_bitpos = bitpos % TARGET_CHAR_BIT;
149
150 /* This is the exact offset (in bits) of this bitfield. */
151 unsigned int bit_offset
152 = (bitpos - relative_bitpos) + offset_bitpos;
153
154 /* The position of the field, relative to the beginning of the
155 struct, and how many bits are left to be used in this
156 container. */
157 fprintf_filtered (stream, "/* %4u:%2u", bit_offset / TARGET_CHAR_BIT,
158 fieldsize_bit - (relative_bitpos + bitsize));
159 fieldsize_bit = bitsize;
160 }
161 else
162 {
163 /* The position of the field, relative to the beginning of the
164 struct. */
165 fprintf_filtered (stream, "/* %4u",
166 (bitpos + offset_bitpos) / TARGET_CHAR_BIT);
167
168 fprintf_filtered (stream, " ");
169 }
170
171 fprintf_filtered (stream, " | %4u */", fieldsize_byte);
172
173 end_bitpos = bitpos + fieldsize_bit;
174 }
175
176 /* See typeprint.h. */
177
178 void
179 print_offset_data::finish (struct type *type, int level,
180 struct ui_file *stream)
181 {
182 unsigned int bitpos = TYPE_LENGTH (type) * TARGET_CHAR_BIT;
183 maybe_print_hole (stream, bitpos, "padding");
184
185 fputs_filtered ("\n", stream);
186 print_spaces_filtered (level + 4 + print_offset_data::indentation, stream);
187 fprintf_filtered (stream, "/* total size (bytes): %4s */\n",
188 pulongest (TYPE_LENGTH (type)));
189 }
190
191 \f
192
193 /* A hash function for a typedef_field. */
194
195 static hashval_t
196 hash_typedef_field (const void *p)
197 {
198 const struct decl_field *tf = (const struct decl_field *) p;
199 struct type *t = check_typedef (tf->type);
200
201 return htab_hash_string (TYPE_SAFE_NAME (t));
202 }
203
204 /* An equality function for a typedef field. */
205
206 static int
207 eq_typedef_field (const void *a, const void *b)
208 {
209 const struct decl_field *tfa = (const struct decl_field *) a;
210 const struct decl_field *tfb = (const struct decl_field *) b;
211
212 return types_equal (tfa->type, tfb->type);
213 }
214
215 /* See typeprint.h. */
216
217 void
218 typedef_hash_table::recursively_update (struct type *t)
219 {
220 int i;
221
222 for (i = 0; i < TYPE_TYPEDEF_FIELD_COUNT (t); ++i)
223 {
224 struct decl_field *tdef = &TYPE_TYPEDEF_FIELD (t, i);
225 void **slot;
226
227 slot = htab_find_slot (m_table, tdef, INSERT);
228 /* Only add a given typedef name once. Really this shouldn't
229 happen; but it is safe enough to do the updates breadth-first
230 and thus use the most specific typedef. */
231 if (*slot == NULL)
232 *slot = tdef;
233 }
234
235 /* Recurse into superclasses. */
236 for (i = 0; i < TYPE_N_BASECLASSES (t); ++i)
237 recursively_update (TYPE_BASECLASS (t, i));
238 }
239
240 /* See typeprint.h. */
241
242 void
243 typedef_hash_table::add_template_parameters (struct type *t)
244 {
245 int i;
246
247 for (i = 0; i < TYPE_N_TEMPLATE_ARGUMENTS (t); ++i)
248 {
249 struct decl_field *tf;
250 void **slot;
251
252 /* We only want type-valued template parameters in the hash. */
253 if (SYMBOL_CLASS (TYPE_TEMPLATE_ARGUMENT (t, i)) != LOC_TYPEDEF)
254 continue;
255
256 tf = XOBNEW (&m_storage, struct decl_field);
257 tf->name = SYMBOL_LINKAGE_NAME (TYPE_TEMPLATE_ARGUMENT (t, i));
258 tf->type = SYMBOL_TYPE (TYPE_TEMPLATE_ARGUMENT (t, i));
259
260 slot = htab_find_slot (m_table, tf, INSERT);
261 if (*slot == NULL)
262 *slot = tf;
263 }
264 }
265
266 /* See typeprint.h. */
267
268 typedef_hash_table::typedef_hash_table ()
269 {
270 m_table = htab_create_alloc (10, hash_typedef_field, eq_typedef_field,
271 NULL, xcalloc, xfree);
272 }
273
274 /* Free a typedef field table. */
275
276 typedef_hash_table::~typedef_hash_table ()
277 {
278 htab_delete (m_table);
279 }
280
281 /* Helper function for typedef_hash_table::copy. */
282
283 static int
284 copy_typedef_hash_element (void **slot, void *nt)
285 {
286 htab_t new_table = (htab_t) nt;
287 void **new_slot;
288
289 new_slot = htab_find_slot (new_table, *slot, INSERT);
290 if (*new_slot == NULL)
291 *new_slot = *slot;
292
293 return 1;
294 }
295
296 /* See typeprint.h. */
297
298 typedef_hash_table::typedef_hash_table (const typedef_hash_table &table)
299 {
300 m_table = htab_create_alloc (10, hash_typedef_field, eq_typedef_field,
301 NULL, xcalloc, xfree);
302 htab_traverse_noresize (table.m_table, copy_typedef_hash_element,
303 m_table);
304 }
305
306 /* Look up the type T in the global typedef hash. If it is found,
307 return the typedef name. If it is not found, apply the
308 type-printers, if any, given by start_script_type_printers and return the
309 result. A NULL return means that the name was not found. */
310
311 const char *
312 typedef_hash_table::find_global_typedef (const struct type_print_options *flags,
313 struct type *t)
314 {
315 char *applied;
316 void **slot;
317 struct decl_field tf, *new_tf;
318
319 if (flags->global_typedefs == NULL)
320 return NULL;
321
322 tf.name = NULL;
323 tf.type = t;
324
325 slot = htab_find_slot (flags->global_typedefs->m_table, &tf, INSERT);
326 if (*slot != NULL)
327 {
328 new_tf = (struct decl_field *) *slot;
329 return new_tf->name;
330 }
331
332 /* Put an entry into the hash table now, in case
333 apply_ext_lang_type_printers recurses. */
334 new_tf = XOBNEW (&flags->global_typedefs->m_storage, struct decl_field);
335 new_tf->name = NULL;
336 new_tf->type = t;
337
338 *slot = new_tf;
339
340 applied = apply_ext_lang_type_printers (flags->global_printers, t);
341
342 if (applied != NULL)
343 {
344 new_tf->name
345 = (const char *) obstack_copy0 (&flags->global_typedefs->m_storage,
346 applied, strlen (applied));
347 xfree (applied);
348 }
349
350 return new_tf->name;
351 }
352
353 /* See typeprint.h. */
354
355 const char *
356 typedef_hash_table::find_typedef (const struct type_print_options *flags,
357 struct type *t)
358 {
359 if (flags->local_typedefs != NULL)
360 {
361 struct decl_field tf, *found;
362
363 tf.name = NULL;
364 tf.type = t;
365 found = (struct decl_field *) htab_find (flags->local_typedefs->m_table,
366 &tf);
367
368 if (found != NULL)
369 return found->name;
370 }
371
372 return find_global_typedef (flags, t);
373 }
374
375 \f
376
377 /* Print a description of a type in the format of a
378 typedef for the current language.
379 NEW is the new name for a type TYPE. */
380
381 void
382 typedef_print (struct type *type, struct symbol *newobj, struct ui_file *stream)
383 {
384 LA_PRINT_TYPEDEF (type, newobj, stream);
385 }
386
387 /* The default way to print a typedef. */
388
389 void
390 default_print_typedef (struct type *type, struct symbol *new_symbol,
391 struct ui_file *stream)
392 {
393 error (_("Language not supported."));
394 }
395
396 /* Print a description of a type TYPE in the form of a declaration of a
397 variable named VARSTRING. (VARSTRING is demangled if necessary.)
398 Output goes to STREAM (via stdio).
399 If SHOW is positive, we show the contents of the outermost level
400 of structure even if there is a type name that could be used instead.
401 If SHOW is negative, we never show the details of elements' types. */
402
403 void
404 type_print (struct type *type, const char *varstring, struct ui_file *stream,
405 int show)
406 {
407 LA_PRINT_TYPE (type, varstring, stream, show, 0, &default_ptype_flags);
408 }
409
410 /* Print TYPE to a string, returning it. The caller is responsible for
411 freeing the string. */
412
413 std::string
414 type_to_string (struct type *type)
415 {
416 TRY
417 {
418 string_file stb;
419
420 type_print (type, "", &stb, -1);
421 return std::move (stb.string ());
422 }
423 CATCH (except, RETURN_MASK_ALL)
424 {
425 }
426 END_CATCH
427
428 return {};
429 }
430
431 /* See typeprint.h. */
432
433 void
434 type_print_unknown_return_type (struct ui_file *stream)
435 {
436 fprintf_filtered (stream, _("<unknown return type>"));
437 }
438
439 /* See typeprint.h. */
440
441 void
442 error_unknown_type (const char *sym_print_name)
443 {
444 error (_("'%s' has unknown type; cast it to its declared type"),
445 sym_print_name);
446 }
447
448 /* Print type of EXP, or last thing in value history if EXP == NULL.
449 show is passed to type_print. */
450
451 static void
452 whatis_exp (const char *exp, int show)
453 {
454 struct value *val;
455 struct type *real_type = NULL;
456 struct type *type;
457 int full = 0;
458 LONGEST top = -1;
459 int using_enc = 0;
460 struct value_print_options opts;
461 struct type_print_options flags = default_ptype_flags;
462
463 if (exp)
464 {
465 if (*exp == '/')
466 {
467 int seen_one = 0;
468
469 for (++exp; *exp && !isspace (*exp); ++exp)
470 {
471 switch (*exp)
472 {
473 case 'r':
474 flags.raw = 1;
475 break;
476 case 'm':
477 flags.print_methods = 0;
478 break;
479 case 'M':
480 flags.print_methods = 1;
481 break;
482 case 't':
483 flags.print_typedefs = 0;
484 break;
485 case 'T':
486 flags.print_typedefs = 1;
487 break;
488 case 'o':
489 {
490 /* Filter out languages which don't implement the
491 feature. */
492 if (show > 0
493 && (current_language->la_language == language_c
494 || current_language->la_language == language_cplus
495 || current_language->la_language == language_rust))
496 {
497 flags.print_offsets = 1;
498 flags.print_typedefs = 0;
499 flags.print_methods = 0;
500 }
501 break;
502 }
503 default:
504 error (_("unrecognized flag '%c'"), *exp);
505 }
506 seen_one = 1;
507 }
508
509 if (!*exp && !seen_one)
510 error (_("flag expected"));
511 if (!isspace (*exp))
512 error (_("expected space after format"));
513 exp = skip_spaces (exp);
514 }
515
516 expression_up expr = parse_expression (exp);
517
518 /* The behavior of "whatis" depends on whether the user
519 expression names a type directly, or a language expression
520 (including variable names). If the former, then "whatis"
521 strips one level of typedefs, only. If an expression,
522 "whatis" prints the type of the expression without stripping
523 any typedef level. "ptype" always strips all levels of
524 typedefs. */
525 if (show == -1 && expr->elts[0].opcode == OP_TYPE)
526 {
527 /* The user expression names a type directly. */
528 type = expr->elts[1].type;
529
530 /* If this is a typedef, then find its immediate target.
531 Use check_typedef to resolve stubs, but ignore its result
532 because we do not want to dig past all typedefs. */
533 check_typedef (type);
534 if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
535 type = TYPE_TARGET_TYPE (type);
536
537 /* If the expression is actually a type, then there's no
538 value to fetch the dynamic type from. */
539 val = NULL;
540 }
541 else
542 {
543 /* The user expression names a type indirectly by naming an
544 object or expression of that type. Find that
545 indirectly-named type. */
546 val = evaluate_type (expr.get ());
547 type = value_type (val);
548 }
549 }
550 else
551 {
552 val = access_value_history (0);
553 type = value_type (val);
554 }
555
556 get_user_print_options (&opts);
557 if (val != NULL && opts.objectprint)
558 {
559 if (((TYPE_CODE (type) == TYPE_CODE_PTR) || TYPE_IS_REFERENCE (type))
560 && (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_STRUCT))
561 real_type = value_rtti_indirect_type (val, &full, &top, &using_enc);
562 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
563 real_type = value_rtti_type (val, &full, &top, &using_enc);
564 }
565
566 if (flags.print_offsets
567 && (TYPE_CODE (type) == TYPE_CODE_STRUCT
568 || TYPE_CODE (type) == TYPE_CODE_UNION))
569 fprintf_filtered (gdb_stdout, "/* offset | size */ ");
570
571 printf_filtered ("type = ");
572
573 std::unique_ptr<typedef_hash_table> table_holder;
574 std::unique_ptr<ext_lang_type_printers> printer_holder;
575 if (!flags.raw)
576 {
577 table_holder.reset (new typedef_hash_table);
578 flags.global_typedefs = table_holder.get ();
579
580 printer_holder.reset (new ext_lang_type_printers);
581 flags.global_printers = printer_holder.get ();
582 }
583
584 if (real_type)
585 {
586 printf_filtered ("/* real type = ");
587 type_print (real_type, "", gdb_stdout, -1);
588 if (! full)
589 printf_filtered (" (incomplete object)");
590 printf_filtered (" */\n");
591 }
592
593 LA_PRINT_TYPE (type, "", gdb_stdout, show, 0, &flags);
594 printf_filtered ("\n");
595 }
596
597 static void
598 whatis_command (const char *exp, int from_tty)
599 {
600 /* Most of the time users do not want to see all the fields
601 in a structure. If they do they can use the "ptype" command.
602 Hence the "-1" below. */
603 whatis_exp (exp, -1);
604 }
605
606 /* TYPENAME is either the name of a type, or an expression. */
607
608 static void
609 ptype_command (const char *type_name, int from_tty)
610 {
611 whatis_exp (type_name, 1);
612 }
613
614 /* Print integral scalar data VAL, of type TYPE, onto stdio stream STREAM.
615 Used to print data from type structures in a specified type. For example,
616 array bounds may be characters or booleans in some languages, and this
617 allows the ranges to be printed in their "natural" form rather than as
618 decimal integer values.
619
620 FIXME: This is here simply because only the type printing routines
621 currently use it, and it wasn't clear if it really belonged somewhere
622 else (like printcmd.c). There are a lot of other gdb routines that do
623 something similar, but they are generally concerned with printing values
624 that come from the inferior in target byte order and target size. */
625
626 void
627 print_type_scalar (struct type *type, LONGEST val, struct ui_file *stream)
628 {
629 unsigned int i;
630 unsigned len;
631
632 type = check_typedef (type);
633
634 switch (TYPE_CODE (type))
635 {
636
637 case TYPE_CODE_ENUM:
638 len = TYPE_NFIELDS (type);
639 for (i = 0; i < len; i++)
640 {
641 if (TYPE_FIELD_ENUMVAL (type, i) == val)
642 {
643 break;
644 }
645 }
646 if (i < len)
647 {
648 fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
649 }
650 else
651 {
652 print_longest (stream, 'd', 0, val);
653 }
654 break;
655
656 case TYPE_CODE_INT:
657 print_longest (stream, TYPE_UNSIGNED (type) ? 'u' : 'd', 0, val);
658 break;
659
660 case TYPE_CODE_CHAR:
661 LA_PRINT_CHAR ((unsigned char) val, type, stream);
662 break;
663
664 case TYPE_CODE_BOOL:
665 fprintf_filtered (stream, val ? "TRUE" : "FALSE");
666 break;
667
668 case TYPE_CODE_RANGE:
669 print_type_scalar (TYPE_TARGET_TYPE (type), val, stream);
670 return;
671
672 case TYPE_CODE_UNDEF:
673 case TYPE_CODE_PTR:
674 case TYPE_CODE_ARRAY:
675 case TYPE_CODE_STRUCT:
676 case TYPE_CODE_UNION:
677 case TYPE_CODE_FUNC:
678 case TYPE_CODE_FLT:
679 case TYPE_CODE_VOID:
680 case TYPE_CODE_SET:
681 case TYPE_CODE_STRING:
682 case TYPE_CODE_ERROR:
683 case TYPE_CODE_MEMBERPTR:
684 case TYPE_CODE_METHODPTR:
685 case TYPE_CODE_METHOD:
686 case TYPE_CODE_REF:
687 case TYPE_CODE_RVALUE_REF:
688 case TYPE_CODE_NAMESPACE:
689 error (_("internal error: unhandled type in print_type_scalar"));
690 break;
691
692 default:
693 error (_("Invalid type code in symbol table."));
694 }
695 }
696
697 /* Dump details of a type specified either directly or indirectly.
698 Uses the same sort of type lookup mechanism as ptype_command()
699 and whatis_command(). */
700
701 void
702 maintenance_print_type (const char *type_name, int from_tty)
703 {
704 struct value *val;
705 struct type *type;
706
707 if (type_name != NULL)
708 {
709 expression_up expr = parse_expression (type_name);
710 if (expr->elts[0].opcode == OP_TYPE)
711 {
712 /* The user expression names a type directly, just use that type. */
713 type = expr->elts[1].type;
714 }
715 else
716 {
717 /* The user expression may name a type indirectly by naming an
718 object of that type. Find that indirectly named type. */
719 val = evaluate_type (expr.get ());
720 type = value_type (val);
721 }
722 if (type != NULL)
723 {
724 recursive_dump_type (type, 0);
725 }
726 }
727 }
728 \f
729
730 struct cmd_list_element *setprinttypelist;
731
732 struct cmd_list_element *showprinttypelist;
733
734 static void
735 set_print_type (const char *arg, int from_tty)
736 {
737 printf_unfiltered (
738 "\"set print type\" must be followed by the name of a subcommand.\n");
739 help_list (setprintlist, "set print type ", all_commands, gdb_stdout);
740 }
741
742 static void
743 show_print_type (const char *args, int from_tty)
744 {
745 cmd_show_list (showprinttypelist, from_tty, "");
746 }
747
748 static int print_methods = 1;
749
750 static void
751 set_print_type_methods (const char *args,
752 int from_tty, struct cmd_list_element *c)
753 {
754 default_ptype_flags.print_methods = print_methods;
755 }
756
757 static void
758 show_print_type_methods (struct ui_file *file, int from_tty,
759 struct cmd_list_element *c, const char *value)
760 {
761 fprintf_filtered (file, _("Printing of methods defined in a class in %s\n"),
762 value);
763 }
764
765 static int print_typedefs = 1;
766
767 static void
768 set_print_type_typedefs (const char *args,
769 int from_tty, struct cmd_list_element *c)
770 {
771 default_ptype_flags.print_typedefs = print_typedefs;
772 }
773
774 static void
775 show_print_type_typedefs (struct ui_file *file, int from_tty,
776 struct cmd_list_element *c, const char *value)
777 {
778 fprintf_filtered (file, _("Printing of typedefs defined in a class in %s\n"),
779 value);
780 }
781
782 /* Limit on the number of nested type definitions to print or -1 to print
783 all nested type definitions in a class. By default, we do not print
784 nested definitions. */
785
786 static int print_nested_type_limit = 0;
787
788 /* Set how many nested type definitions should be printed by the type
789 printer. */
790
791 static void
792 set_print_type_nested_types (const char *args, int from_tty,
793 struct cmd_list_element *c)
794 {
795 default_ptype_flags.print_nested_type_limit = print_nested_type_limit;
796 }
797
798 /* Show how many nested type definitions the type printer will print. */
799
800 static void
801 show_print_type_nested_types (struct ui_file *file, int from_tty,
802 struct cmd_list_element *c, const char *value)
803 {
804 if (*value == '0')
805 {
806 fprintf_filtered (file,
807 _("Will not print nested types defined in a class\n"));
808 }
809 else
810 {
811 fprintf_filtered (file,
812 _("Will print %s nested types defined in a class\n"),
813 value);
814 }
815 }
816
817 void
818 _initialize_typeprint (void)
819 {
820 struct cmd_list_element *c;
821
822 c = add_com ("ptype", class_vars, ptype_command, _("\
823 Print definition of type TYPE.\n\
824 Usage: ptype[/FLAGS] TYPE | EXPRESSION\n\
825 Argument may be any type (for example a type name defined by typedef,\n\
826 or \"struct STRUCT-TAG\" or \"class CLASS-NAME\" or \"union UNION-TAG\"\n\
827 or \"enum ENUM-TAG\") or an expression.\n\
828 The selected stack frame's lexical context is used to look up the name.\n\
829 Contrary to \"whatis\", \"ptype\" always unrolls any typedefs.\n\
830 \n\
831 Available FLAGS are:\n\
832 /r print in \"raw\" form; do not substitute typedefs\n\
833 /m do not print methods defined in a class\n\
834 /M print methods defined in a class\n\
835 /t do not print typedefs defined in a class\n\
836 /T print typedefs defined in a class\n\
837 /o print offsets and sizes of fields in a struct (like pahole)\n"));
838 set_cmd_completer (c, expression_completer);
839
840 c = add_com ("whatis", class_vars, whatis_command,
841 _("Print data type of expression EXP.\n\
842 Only one level of typedefs is unrolled. See also \"ptype\"."));
843 set_cmd_completer (c, expression_completer);
844
845 add_prefix_cmd ("type", no_class, show_print_type,
846 _("Generic command for showing type-printing settings."),
847 &showprinttypelist, "show print type ", 0, &showprintlist);
848 add_prefix_cmd ("type", no_class, set_print_type,
849 _("Generic command for setting how types print."),
850 &setprinttypelist, "set print type ", 0, &setprintlist);
851
852 add_setshow_boolean_cmd ("methods", no_class, &print_methods,
853 _("\
854 Set printing of methods defined in classes."), _("\
855 Show printing of methods defined in classes."), NULL,
856 set_print_type_methods,
857 show_print_type_methods,
858 &setprinttypelist, &showprinttypelist);
859 add_setshow_boolean_cmd ("typedefs", no_class, &print_typedefs,
860 _("\
861 Set printing of typedefs defined in classes."), _("\
862 Show printing of typedefs defined in classes."), NULL,
863 set_print_type_typedefs,
864 show_print_type_typedefs,
865 &setprinttypelist, &showprinttypelist);
866
867 add_setshow_zuinteger_unlimited_cmd ("nested-type-limit", no_class,
868 &print_nested_type_limit,
869 _("\
870 Set the number of recursive nested type definitions to print \
871 (\"unlimited\" or -1 to show all)."), _("\
872 Show the number of recursive nested type definitions to print."), NULL,
873 set_print_type_nested_types,
874 show_print_type_nested_types,
875 &setprinttypelist, &showprinttypelist);
876 }
877
878 /* Print <not allocated> status to stream STREAM. */
879
880 void
881 val_print_not_allocated (struct ui_file *stream)
882 {
883 fprintf_filtered (stream, _("<not allocated>"));
884 }
885
886 /* Print <not associated> status to stream STREAM. */
887
888 void
889 val_print_not_associated (struct ui_file *stream)
890 {
891 fprintf_filtered (stream, _("<not associated>"));
892 }