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