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