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