gdb/c-typeprint.c - gdb

Functions defined

Source code

  1. /* Support for printing C and C++ types for GDB, the GNU debugger.
  2.    Copyright (C) 1986-2015 Free Software Foundation, Inc.

  3.    This file is part of GDB.

  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 3 of the License, or
  7.    (at your option) any later version.

  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.

  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  14. #include "defs.h"
  15. #include "gdb_obstack.h"
  16. #include "bfd.h"                /* Binary File Description.  */
  17. #include "symtab.h"
  18. #include "gdbtypes.h"
  19. #include "expression.h"
  20. #include "value.h"
  21. #include "gdbcore.h"
  22. #include "target.h"
  23. #include "language.h"
  24. #include "demangle.h"
  25. #include "c-lang.h"
  26. #include "typeprint.h"
  27. #include "cp-abi.h"
  28. #include "jv-lang.h"
  29. #include "cp-support.h"

  30. static void c_type_print_varspec_prefix (struct type *,
  31.                                          struct ui_file *,
  32.                                          int, int, int,
  33.                                          const struct type_print_options *);

  34. /* Print "const", "volatile", or address space modifiers.  */
  35. static void c_type_print_modifier (struct type *,
  36.                                    struct ui_file *,
  37.                                    int, int);


  38. /* A callback function for cp_canonicalize_string_full that uses
  39.    find_typedef_in_hash.  */

  40. static const char *
  41. find_typedef_for_canonicalize (struct type *t, void *data)
  42. {
  43.   return find_typedef_in_hash (data, t);
  44. }

  45. /* Print NAME on STREAM.  If the 'raw' field of FLAGS is not set,
  46.    canonicalize NAME using the local typedefs first.  */

  47. static void
  48. print_name_maybe_canonical (const char *name,
  49.                             const struct type_print_options *flags,
  50.                             struct ui_file *stream)
  51. {
  52.   char *s = NULL;

  53.   if (!flags->raw)
  54.     s = cp_canonicalize_string_full (name,
  55.                                      find_typedef_for_canonicalize,
  56.                                      (void *) flags);

  57.   fputs_filtered (s ? s : name, stream);
  58.   xfree (s);
  59. }



  60. /* LEVEL is the depth to indent lines by.  */

  61. void
  62. c_print_type (struct type *type,
  63.               const char *varstring,
  64.               struct ui_file *stream,
  65.               int show, int level,
  66.               const struct type_print_options *flags)
  67. {
  68.   enum type_code code;
  69.   int demangled_args;
  70.   int need_post_space;
  71.   const char *local_name;

  72.   if (show > 0)
  73.     CHECK_TYPEDEF (type);

  74.   local_name = find_typedef_in_hash (flags, type);
  75.   if (local_name != NULL)
  76.     {
  77.       fputs_filtered (local_name, stream);
  78.       if (varstring != NULL && *varstring != '\0')
  79.         fputs_filtered (" ", stream);
  80.     }
  81.   else
  82.     {
  83.       c_type_print_base (type, stream, show, level, flags);
  84.       code = TYPE_CODE (type);
  85.       if ((varstring != NULL && *varstring != '\0')
  86.           /* Need a space if going to print stars or brackets;
  87.              but not if we will print just a type name.  */
  88.           || ((show > 0 || TYPE_NAME (type) == 0)
  89.               && (code == TYPE_CODE_PTR || code == TYPE_CODE_FUNC
  90.                   || code == TYPE_CODE_METHOD
  91.                   || (code == TYPE_CODE_ARRAY
  92.                       && !TYPE_VECTOR (type))
  93.                   || code == TYPE_CODE_MEMBERPTR
  94.                   || code == TYPE_CODE_METHODPTR
  95.                   || code == TYPE_CODE_REF)))
  96.         fputs_filtered (" ", stream);
  97.       need_post_space = (varstring != NULL && strcmp (varstring, "") != 0);
  98.       c_type_print_varspec_prefix (type, stream, show, 0, need_post_space,
  99.                                    flags);
  100.     }

  101.   if (varstring != NULL)
  102.     {
  103.       fputs_filtered (varstring, stream);

  104.       /* For demangled function names, we have the arglist as part of
  105.          the name, so don't print an additional pair of ()'s.  */
  106.       if (local_name == NULL)
  107.         {
  108.           demangled_args = strchr (varstring, '(') != NULL;
  109.           c_type_print_varspec_suffix (type, stream, show,
  110.                                        0, demangled_args,
  111.                                        flags);
  112.         }
  113.     }
  114. }

  115. /* Print a typedef using C syntax.  TYPE is the underlying type.
  116.    NEW_SYMBOL is the symbol naming the type.  STREAM is the stream on
  117.    which to print.  */

  118. void
  119. c_print_typedef (struct type *type,
  120.                  struct symbol *new_symbol,
  121.                  struct ui_file *stream)
  122. {
  123.   CHECK_TYPEDEF (type);
  124.   fprintf_filtered (stream, "typedef ");
  125.   type_print (type, "", stream, 0);
  126.   if (TYPE_NAME ((SYMBOL_TYPE (new_symbol))) == 0
  127.       || strcmp (TYPE_NAME ((SYMBOL_TYPE (new_symbol))),
  128.                  SYMBOL_LINKAGE_NAME (new_symbol)) != 0
  129.       || TYPE_CODE (SYMBOL_TYPE (new_symbol)) == TYPE_CODE_TYPEDEF)
  130.     fprintf_filtered (stream, " %s", SYMBOL_PRINT_NAME (new_symbol));
  131.   fprintf_filtered (stream, ";\n");
  132. }

  133. /* If TYPE is a derived type, then print out derivation information.
  134.    Print only the actual base classes of this type, not the base
  135.    classes of the base classes.  I.e. for the derivation hierarchy:

  136.    class A { int a; };
  137.    class B : public A {int b; };
  138.    class C : public B {int c; };

  139.    Print the type of class C as:

  140.    class C : public B {
  141.    int c;
  142.    }

  143.    Not as the following (like gdb used to), which is not legal C++
  144.    syntax for derived types and may be confused with the multiple
  145.    inheritance form:

  146.    class C : public B : public A {
  147.    int c;
  148.    }

  149.    In general, gdb should try to print the types as closely as
  150.    possible to the form that they appear in the source code.  */

  151. static void
  152. cp_type_print_derivation_info (struct ui_file *stream,
  153.                                struct type *type,
  154.                                const struct type_print_options *flags)
  155. {
  156.   const char *name;
  157.   int i;

  158.   for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
  159.     {
  160.       wrap_here ("        ");
  161.       fputs_filtered (i == 0 ? ": " : ", ", stream);
  162.       fprintf_filtered (stream, "%s%s ",
  163.                         BASETYPE_VIA_PUBLIC (type, i)
  164.                         ? "public" : (TYPE_FIELD_PROTECTED (type, i)
  165.                                       ? "protected" : "private"),
  166.                         BASETYPE_VIA_VIRTUAL (type, i) ? " virtual" : "");
  167.       name = type_name_no_tag (TYPE_BASECLASS (type, i));
  168.       if (name)
  169.         print_name_maybe_canonical (name, flags, stream);
  170.       else
  171.         fprintf_filtered (stream, "(null)");
  172.     }
  173.   if (i > 0)
  174.     {
  175.       fputs_filtered (" ", stream);
  176.     }
  177. }

  178. /* Print the C++ method arguments ARGS to the file STREAM.  */

  179. static void
  180. cp_type_print_method_args (struct type *mtype, const char *prefix,
  181.                            const char *varstring, int staticp,
  182.                            struct ui_file *stream,
  183.                            const struct type_print_options *flags)
  184. {
  185.   struct field *args = TYPE_FIELDS (mtype);
  186.   int nargs = TYPE_NFIELDS (mtype);
  187.   int varargs = TYPE_VARARGS (mtype);
  188.   int i;

  189.   fprintf_symbol_filtered (stream, prefix,
  190.                            language_cplus, DMGL_ANSI);
  191.   fprintf_symbol_filtered (stream, varstring,
  192.                            language_cplus, DMGL_ANSI);
  193.   fputs_filtered ("(", stream);

  194.   /* Skip the class variable.  */
  195.   i = staticp ? 0 : 1;
  196.   if (nargs > i)
  197.     {
  198.       while (i < nargs)
  199.         {
  200.           c_print_type (args[i++].type, "", stream, 0, 0, flags);

  201.           if (i == nargs && varargs)
  202.             fprintf_filtered (stream, ", ...");
  203.           else if (i < nargs)
  204.             {
  205.               fprintf_filtered (stream, ", ");
  206.               wrap_here ("        ");
  207.             }
  208.         }
  209.     }
  210.   else if (varargs)
  211.     fprintf_filtered (stream, "...");
  212.   else if (current_language->la_language == language_cplus)
  213.     fprintf_filtered (stream, "void");

  214.   fprintf_filtered (stream, ")");

  215.   /* For non-static methods, read qualifiers from the type of
  216.      THIS.  */
  217.   if (!staticp)
  218.     {
  219.       struct type *domain;

  220.       gdb_assert (nargs > 0);
  221.       gdb_assert (TYPE_CODE (args[0].type) == TYPE_CODE_PTR);
  222.       domain = TYPE_TARGET_TYPE (args[0].type);

  223.       if (TYPE_CONST (domain))
  224.         fprintf_filtered (stream, " const");

  225.       if (TYPE_VOLATILE (domain))
  226.         fprintf_filtered (stream, " volatile");

  227.       if (TYPE_RESTRICT (domain))
  228.         fprintf_filtered (stream, " restrict");
  229.     }
  230. }


  231. /* Print any asterisks or open-parentheses needed before the
  232.    variable name (to describe its type).

  233.    On outermost call, pass 0 for PASSED_A_PTR.
  234.    On outermost call, SHOW > 0 means should ignore
  235.    any typename for TYPE and show its details.
  236.    SHOW is always zero on recursive calls.

  237.    NEED_POST_SPACE is non-zero when a space will be be needed
  238.    between a trailing qualifier and a field, variable, or function
  239.    name.  */

  240. static void
  241. c_type_print_varspec_prefix (struct type *type,
  242.                              struct ui_file *stream,
  243.                              int show, int passed_a_ptr,
  244.                              int need_post_space,
  245.                              const struct type_print_options *flags)
  246. {
  247.   const char *name;

  248.   if (type == 0)
  249.     return;

  250.   if (TYPE_NAME (type) && show <= 0)
  251.     return;

  252.   QUIT;

  253.   switch (TYPE_CODE (type))
  254.     {
  255.     case TYPE_CODE_PTR:
  256.       c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type),
  257.                                    stream, show, 1, 1, flags);
  258.       fprintf_filtered (stream, "*");
  259.       c_type_print_modifier (type, stream, 1, need_post_space);
  260.       break;

  261.     case TYPE_CODE_MEMBERPTR:
  262.       c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type),
  263.                                    stream, show, 0, 0, flags);
  264.       name = type_name_no_tag (TYPE_DOMAIN_TYPE (type));
  265.       if (name)
  266.         print_name_maybe_canonical (name, flags, stream);
  267.       else
  268.         c_type_print_base (TYPE_DOMAIN_TYPE (type),
  269.                            stream, -1, passed_a_ptr, flags);
  270.       fprintf_filtered (stream, "::*");
  271.       break;

  272.     case TYPE_CODE_METHODPTR:
  273.       c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type),
  274.                                    stream, show, 0, 0, flags);
  275.       fprintf_filtered (stream, "(");
  276.       name = type_name_no_tag (TYPE_DOMAIN_TYPE (type));
  277.       if (name)
  278.         print_name_maybe_canonical (name, flags, stream);
  279.       else
  280.         c_type_print_base (TYPE_DOMAIN_TYPE (type),
  281.                            stream, -1, passed_a_ptr, flags);
  282.       fprintf_filtered (stream, "::*");
  283.       break;

  284.     case TYPE_CODE_REF:
  285.       c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type),
  286.                                    stream, show, 1, 0, flags);
  287.       fprintf_filtered (stream, "&");
  288.       c_type_print_modifier (type, stream, 1, need_post_space);
  289.       break;

  290.     case TYPE_CODE_METHOD:
  291.     case TYPE_CODE_FUNC:
  292.       c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type),
  293.                                    stream, show, 0, 0, flags);
  294.       if (passed_a_ptr)
  295.         fprintf_filtered (stream, "(");
  296.       break;

  297.     case TYPE_CODE_ARRAY:
  298.       c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type),
  299.                                    stream, show, 0, 0, flags);
  300.       if (passed_a_ptr)
  301.         fprintf_filtered (stream, "(");
  302.       break;

  303.     case TYPE_CODE_TYPEDEF:
  304.       c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type),
  305.                                    stream, show, passed_a_ptr, 0, flags);
  306.       break;

  307.     case TYPE_CODE_UNDEF:
  308.     case TYPE_CODE_STRUCT:
  309.     case TYPE_CODE_UNION:
  310.     case TYPE_CODE_ENUM:
  311.     case TYPE_CODE_INT:
  312.     case TYPE_CODE_FLT:
  313.     case TYPE_CODE_VOID:
  314.     case TYPE_CODE_ERROR:
  315.     case TYPE_CODE_CHAR:
  316.     case TYPE_CODE_BOOL:
  317.     case TYPE_CODE_SET:
  318.     case TYPE_CODE_RANGE:
  319.     case TYPE_CODE_STRING:
  320.     case TYPE_CODE_COMPLEX:
  321.     case TYPE_CODE_NAMESPACE:
  322.     case TYPE_CODE_DECFLOAT:
  323.       /* These types need no prefix.  They are listed here so that
  324.          gcc -Wall will reveal any types that haven't been handled.  */
  325.       break;
  326.     default:
  327.       error (_("type not handled in c_type_print_varspec_prefix()"));
  328.       break;
  329.     }
  330. }

  331. /* Print out "const" and "volatile" attributes,
  332.    and address space id if present.
  333.    TYPE is a pointer to the type being printed out.
  334.    STREAM is the output destination.
  335.    NEED_PRE_SPACE = 1 indicates an initial white space is needed.
  336.    NEED_POST_SPACE = 1 indicates a final white space is needed.  */

  337. static void
  338. c_type_print_modifier (struct type *type, struct ui_file *stream,
  339.                        int need_pre_space, int need_post_space)
  340. {
  341.   int did_print_modifier = 0;
  342.   const char *address_space_id;

  343.   /* We don't print `const' qualifiers for references --- since all
  344.      operators affect the thing referenced, not the reference itself,
  345.      every reference is `const'.  */
  346.   if (TYPE_CONST (type)
  347.       && TYPE_CODE (type) != TYPE_CODE_REF)
  348.     {
  349.       if (need_pre_space)
  350.         fprintf_filtered (stream, " ");
  351.       fprintf_filtered (stream, "const");
  352.       did_print_modifier = 1;
  353.     }

  354.   if (TYPE_VOLATILE (type))
  355.     {
  356.       if (did_print_modifier || need_pre_space)
  357.         fprintf_filtered (stream, " ");
  358.       fprintf_filtered (stream, "volatile");
  359.       did_print_modifier = 1;
  360.     }

  361.   if (TYPE_RESTRICT (type))
  362.     {
  363.       if (did_print_modifier || need_pre_space)
  364.         fprintf_filtered (stream, " ");
  365.       fprintf_filtered (stream, "restrict");
  366.       did_print_modifier = 1;
  367.     }

  368.   address_space_id = address_space_int_to_name (get_type_arch (type),
  369.                                                 TYPE_INSTANCE_FLAGS (type));
  370.   if (address_space_id)
  371.     {
  372.       if (did_print_modifier || need_pre_space)
  373.         fprintf_filtered (stream, " ");
  374.       fprintf_filtered (stream, "@%s", address_space_id);
  375.       did_print_modifier = 1;
  376.     }

  377.   if (did_print_modifier && need_post_space)
  378.     fprintf_filtered (stream, " ");
  379. }


  380. /* Print out the arguments of TYPE, which should have TYPE_CODE_METHOD
  381.    or TYPE_CODE_FUNC, to STREAM.  Artificial arguments, such as "this"
  382.    in non-static methods, are displayed if LINKAGE_NAME is zero.  If
  383.    LINKAGE_NAME is non-zero and LANGUAGE is language_cplus the topmost
  384.    parameter types get removed their possible const and volatile qualifiers to
  385.    match demangled linkage name parameters part of such function type.
  386.    LANGUAGE is the language in which TYPE was defined.  This is a necessary
  387.    evil since this code is used by the C, C++, and Java backends.  */

  388. void
  389. c_type_print_args (struct type *type, struct ui_file *stream,
  390.                    int linkage_name, enum language language,
  391.                    const struct type_print_options *flags)
  392. {
  393.   int i;
  394.   int printed_any = 0;

  395.   fprintf_filtered (stream, "(");

  396.   for (i = 0; i < TYPE_NFIELDS (type); i++)
  397.     {
  398.       struct type *param_type;

  399.       if (TYPE_FIELD_ARTIFICIAL (type, i) && linkage_name)
  400.         continue;

  401.       if (printed_any)
  402.         {
  403.           fprintf_filtered (stream, ", ");
  404.           wrap_here ("    ");
  405.         }

  406.       param_type = TYPE_FIELD_TYPE (type, i);

  407.       if (language == language_cplus && linkage_name)
  408.         {
  409.           /* C++ standard, 13.1 Overloadable declarations, point 3, item:
  410.              - Parameter declarations that differ only in the presence or
  411.                absence of const and/or volatile are equivalent.

  412.              And the const/volatile qualifiers are not present in the mangled
  413.              names as produced by GCC.  */

  414.           param_type = make_cv_type (0, 0, param_type, NULL);
  415.         }

  416.       if (language == language_java)
  417.         java_print_type (param_type, "", stream, -1, 0, flags);
  418.       else
  419.         c_print_type (param_type, "", stream, -1, 0, flags);
  420.       printed_any = 1;
  421.     }

  422.   if (printed_any && TYPE_VARARGS (type))
  423.     {
  424.       /* Print out a trailing ellipsis for varargs functions.  Ignore
  425.          TYPE_VARARGS if the function has no named arguments; that
  426.          represents unprototyped (K&R style) C functions.  */
  427.       if (printed_any && TYPE_VARARGS (type))
  428.         {
  429.           fprintf_filtered (stream, ", ");
  430.           wrap_here ("    ");
  431.           fprintf_filtered (stream, "...");
  432.         }
  433.     }
  434.   else if (!printed_any
  435.            && ((TYPE_PROTOTYPED (type) && language != language_java)
  436.                || language == language_cplus))
  437.     fprintf_filtered (stream, "void");

  438.   fprintf_filtered (stream, ")");
  439. }

  440. /* Return true iff the j'th overloading of the i'th method of TYPE
  441.    is a type conversion operator, like `operator int () { ... }'.
  442.    When listing a class's methods, we don't print the return type of
  443.    such operators.  */

  444. static int
  445. is_type_conversion_operator (struct type *type, int i, int j)
  446. {
  447.   /* I think the whole idea of recognizing type conversion operators
  448.      by their name is pretty terrible.  But I don't think our present
  449.      data structure gives us any other way to tell.  If you know of
  450.      some other way, feel free to rewrite this function.  */
  451.   const char *name = TYPE_FN_FIELDLIST_NAME (type, i);

  452.   if (strncmp (name, "operator", 8) != 0)
  453.     return 0;

  454.   name += 8;
  455.   if (! strchr (" \t\f\n\r", *name))
  456.     return 0;

  457.   while (strchr (" \t\f\n\r", *name))
  458.     name++;

  459.   if (!('a' <= *name && *name <= 'z')
  460.       && !('A' <= *name && *name <= 'Z')
  461.       && *name != '_')
  462.     /* If this doesn't look like the start of an identifier, then it
  463.        isn't a type conversion operator.  */
  464.     return 0;
  465.   else if (strncmp (name, "new", 3) == 0)
  466.     name += 3;
  467.   else if (strncmp (name, "delete", 6) == 0)
  468.     name += 6;
  469.   else
  470.     /* If it doesn't look like new or delete, it's a type conversion
  471.        operator.  */
  472.     return 1;

  473.   /* Is that really the end of the name?  */
  474.   if (('a' <= *name && *name <= 'z')
  475.       || ('A' <= *name && *name <= 'Z')
  476.       || ('0' <= *name && *name <= '9')
  477.       || *name == '_')
  478.     /* No, so the identifier following "operator" must be a type name,
  479.        and this is a type conversion operator.  */
  480.     return 1;

  481.   /* That was indeed the end of the name, so it was `operator new' or
  482.      `operator delete', neither of which are type conversion
  483.      operators.  */
  484.   return 0;
  485. }

  486. /* Given a C++ qualified identifier QID, strip off the qualifiers,
  487.    yielding the unqualified name.  The return value is a pointer into
  488.    the original string.

  489.    It's a pity we don't have this information in some more structured
  490.    form.  Even the author of this function feels that writing little
  491.    parsers like this everywhere is stupid.  */

  492. static char *
  493. remove_qualifiers (char *qid)
  494. {
  495.   int quoted = 0;        /* Zero if we're not in quotes;
  496.                            '"' if we're in a double-quoted string;
  497.                            '\'' if we're in a single-quoted string.  */
  498.   int depth = 0;        /* Number of unclosed parens we've seen.  */
  499.   char *parenstack = (char *) alloca (strlen (qid));
  500.   char *scan;
  501.   char *last = 0;        /* The character after the rightmost
  502.                            `::' token we've seen so far.  */

  503.   for (scan = qid; *scan; scan++)
  504.     {
  505.       if (quoted)
  506.         {
  507.           if (*scan == quoted)
  508.             quoted = 0;
  509.           else if (*scan == '\\' && *(scan + 1))
  510.             scan++;
  511.         }
  512.       else if (scan[0] == ':' && scan[1] == ':')
  513.         {
  514.           /* If we're inside parenthesis (i.e., an argument list) or
  515.              angle brackets (i.e., a list of template arguments), then
  516.              we don't record the position of this :: token, since it's
  517.              not relevant to the top-level structure we're trying to
  518.              operate on.  */
  519.           if (depth == 0)
  520.             {
  521.               last = scan + 2;
  522.               scan++;
  523.             }
  524.         }
  525.       else if (*scan == '"' || *scan == '\'')
  526.         quoted = *scan;
  527.       else if (*scan == '(')
  528.         parenstack[depth++] = ')';
  529.       else if (*scan == '[')
  530.         parenstack[depth++] = ']';
  531.       /* We're going to treat <> as a pair of matching characters,
  532.          since we're more likely to see those in template id's than
  533.          real less-than characters.  What a crock.  */
  534.       else if (*scan == '<')
  535.         parenstack[depth++] = '>';
  536.       else if (*scan == ')' || *scan == ']' || *scan == '>')
  537.         {
  538.           if (depth > 0 && parenstack[depth - 1] == *scan)
  539.             depth--;
  540.           else
  541.             {
  542.               /* We're going to do a little error recovery here.  If
  543.                  we don't find a match for *scan on the paren stack,
  544.                  but there is something lower on the stack that does
  545.                  match, we pop the stack to that point.  */
  546.               int i;

  547.               for (i = depth - 1; i >= 0; i--)
  548.                 if (parenstack[i] == *scan)
  549.                   {
  550.                     depth = i;
  551.                     break;
  552.                   }
  553.             }
  554.         }
  555.     }

  556.   if (last)
  557.     return last;
  558.   else
  559.     /* We didn't find any :: tokens at the top level, so declare the
  560.        whole thing an unqualified identifier.  */
  561.     return qid;
  562. }

  563. /* Print any array sizes, function arguments or close parentheses
  564.    needed after the variable name (to describe its type).
  565.    Args work like c_type_print_varspec_prefix.  */

  566. void
  567. c_type_print_varspec_suffix (struct type *type,
  568.                              struct ui_file *stream,
  569.                              int show, int passed_a_ptr,
  570.                              int demangled_args,
  571.                              const struct type_print_options *flags)
  572. {
  573.   if (type == 0)
  574.     return;

  575.   if (TYPE_NAME (type) && show <= 0)
  576.     return;

  577.   QUIT;

  578.   switch (TYPE_CODE (type))
  579.     {
  580.     case TYPE_CODE_ARRAY:
  581.       {
  582.         LONGEST low_bound, high_bound;
  583.         int is_vector = TYPE_VECTOR (type);

  584.         if (passed_a_ptr)
  585.           fprintf_filtered (stream, ")");

  586.         fprintf_filtered (stream, (is_vector ?
  587.                                    " __attribute__ ((vector_size(" : "["));
  588.         /* Bounds are not yet resolved, print a bounds placeholder instead.  */
  589.         if (TYPE_HIGH_BOUND_KIND (TYPE_INDEX_TYPE (type)) == PROP_LOCEXPR
  590.             || TYPE_HIGH_BOUND_KIND (TYPE_INDEX_TYPE (type)) == PROP_LOCLIST)
  591.           fprintf_filtered (stream, "variable length");
  592.         else if (get_array_bounds (type, &low_bound, &high_bound))
  593.           fprintf_filtered (stream, "%s",
  594.                             plongest (high_bound - low_bound + 1));
  595.         fprintf_filtered (stream, (is_vector ? ")))" : "]"));

  596.         c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream,
  597.                                      show, 0, 0, flags);
  598.       }
  599.       break;

  600.     case TYPE_CODE_MEMBERPTR:
  601.       c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream,
  602.                                    show, 0, 0, flags);
  603.       break;

  604.     case TYPE_CODE_METHODPTR:
  605.       fprintf_filtered (stream, ")");
  606.       c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream,
  607.                                    show, 0, 0, flags);
  608.       break;

  609.     case TYPE_CODE_PTR:
  610.     case TYPE_CODE_REF:
  611.       c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream,
  612.                                    show, 1, 0, flags);
  613.       break;

  614.     case TYPE_CODE_METHOD:
  615.     case TYPE_CODE_FUNC:
  616.       if (passed_a_ptr)
  617.         fprintf_filtered (stream, ")");
  618.       if (!demangled_args)
  619.         c_type_print_args (type, stream, 0, current_language->la_language,
  620.                            flags);
  621.       c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream,
  622.                                    show, passed_a_ptr, 0, flags);
  623.       break;

  624.     case TYPE_CODE_TYPEDEF:
  625.       c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream,
  626.                                    show, passed_a_ptr, 0, flags);
  627.       break;

  628.     case TYPE_CODE_UNDEF:
  629.     case TYPE_CODE_STRUCT:
  630.     case TYPE_CODE_UNION:
  631.     case TYPE_CODE_ENUM:
  632.     case TYPE_CODE_INT:
  633.     case TYPE_CODE_FLT:
  634.     case TYPE_CODE_VOID:
  635.     case TYPE_CODE_ERROR:
  636.     case TYPE_CODE_CHAR:
  637.     case TYPE_CODE_BOOL:
  638.     case TYPE_CODE_SET:
  639.     case TYPE_CODE_RANGE:
  640.     case TYPE_CODE_STRING:
  641.     case TYPE_CODE_COMPLEX:
  642.     case TYPE_CODE_NAMESPACE:
  643.     case TYPE_CODE_DECFLOAT:
  644.       /* These types do not need a suffix.  They are listed so that
  645.          gcc -Wall will report types that may not have been
  646.          considered.  */
  647.       break;
  648.     default:
  649.       error (_("type not handled in c_type_print_varspec_suffix()"));
  650.       break;
  651.     }
  652. }

  653. /* A helper for c_type_print_base that displays template
  654.    parameters and their bindings, if needed.

  655.    TABLE is the local bindings table to use.  If NULL, no printing is
  656.    done.  Note that, at this point, TABLE won't have any useful
  657.    information in it -- but it is also used as a flag to
  658.    print_name_maybe_canonical to activate searching the global typedef
  659.    table.

  660.    TYPE is the type whose template arguments are being displayed.

  661.    STREAM is the stream on which to print.  */

  662. static void
  663. c_type_print_template_args (const struct type_print_options *flags,
  664.                             struct type *type, struct ui_file *stream)
  665. {
  666.   int first = 1, i;

  667.   if (flags->raw)
  668.     return;

  669.   for (i = 0; i < TYPE_N_TEMPLATE_ARGUMENTS (type); ++i)
  670.     {
  671.       struct symbol *sym = TYPE_TEMPLATE_ARGUMENT (type, i);

  672.       if (SYMBOL_CLASS (sym) != LOC_TYPEDEF)
  673.         continue;

  674.       if (first)
  675.         {
  676.           wrap_here ("    ");
  677.           fprintf_filtered (stream, _("[with %s = "),
  678.                             SYMBOL_LINKAGE_NAME (sym));
  679.           first = 0;
  680.         }
  681.       else
  682.         {
  683.           fputs_filtered (", ", stream);
  684.           wrap_here ("         ");
  685.           fprintf_filtered (stream, "%s = ", SYMBOL_LINKAGE_NAME (sym));
  686.         }

  687.       c_print_type (SYMBOL_TYPE (sym), "", stream, -1, 0, flags);
  688.     }

  689.   if (!first)
  690.     fputs_filtered (_("] "), stream);
  691. }

  692. /* Print the name of the type (or the ultimate pointer target,
  693.    function value or array element), or the description of a structure
  694.    or union.

  695.    SHOW positive means print details about the type (e.g. enum
  696.    values), and print structure elements passing SHOW - 1 for show.

  697.    SHOW negative means just print the type name or struct tag if there
  698.    is one.  If there is no name, print something sensible but concise
  699.    like "struct {...}".

  700.    SHOW zero means just print the type name or struct tag if there is
  701.    one.  If there is no name, print something sensible but not as
  702.    concise like "struct {int x; int y;}".

  703.    LEVEL is the number of spaces to indent by.
  704.    We increase it for some recursive calls.  */

  705. void
  706. c_type_print_base (struct type *type, struct ui_file *stream,
  707.                    int show, int level, const struct type_print_options *flags)
  708. {
  709.   int i;
  710.   int len, real_len;
  711.   enum
  712.     {
  713.       s_none, s_public, s_private, s_protected
  714.     }
  715.   section_type;
  716.   int need_access_label = 0;
  717.   int j, len2;

  718.   QUIT;

  719.   if (type == NULL)
  720.     {
  721.       fputs_filtered (_("<type unknown>"), stream);
  722.       return;
  723.     }

  724.   /* When SHOW is zero or less, and there is a valid type name, then
  725.      always just print the type name directly from the type.  */
  726.   /* If we have "typedef struct foo {. . .} bar;" do we want to print
  727.      it as "struct foo" or as "bar"?  Pick the latter, because C++
  728.      folk tend to expect things like "class5 *foo" rather than "struct
  729.      class5 *foo".  */

  730.   if (show <= 0
  731.       && TYPE_NAME (type) != NULL)
  732.     {
  733.       c_type_print_modifier (type, stream, 0, 1);
  734.       print_name_maybe_canonical (TYPE_NAME (type), flags, stream);
  735.       return;
  736.     }

  737.   CHECK_TYPEDEF (type);

  738.   switch (TYPE_CODE (type))
  739.     {
  740.     case TYPE_CODE_TYPEDEF:
  741.       /* If we get here, the typedef doesn't have a name, and we
  742.          couldn't resolve TYPE_TARGET_TYPE.  Not much we can do.  */
  743.       gdb_assert (TYPE_NAME (type) == NULL);
  744.       gdb_assert (TYPE_TARGET_TYPE (type) == NULL);
  745.       fprintf_filtered (stream, _("<unnamed typedef>"));
  746.       break;

  747.     case TYPE_CODE_ARRAY:
  748.     case TYPE_CODE_PTR:
  749.     case TYPE_CODE_MEMBERPTR:
  750.     case TYPE_CODE_REF:
  751.     case TYPE_CODE_FUNC:
  752.     case TYPE_CODE_METHOD:
  753.     case TYPE_CODE_METHODPTR:
  754.       c_type_print_base (TYPE_TARGET_TYPE (type),
  755.                          stream, show, level, flags);
  756.       break;

  757.     case TYPE_CODE_STRUCT:
  758.     case TYPE_CODE_UNION:
  759.       {
  760.         struct type_print_options local_flags = *flags;
  761.         struct type_print_options semi_local_flags = *flags;
  762.         struct cleanup *local_cleanups = make_cleanup (null_cleanup, NULL);

  763.         local_flags.local_typedefs = NULL;
  764.         semi_local_flags.local_typedefs = NULL;

  765.         if (!flags->raw)
  766.           {
  767.             if (flags->local_typedefs)
  768.               local_flags.local_typedefs
  769.                 = copy_typedef_hash (flags->local_typedefs);
  770.             else
  771.               local_flags.local_typedefs = create_typedef_hash ();

  772.             make_cleanup_free_typedef_hash (local_flags.local_typedefs);
  773.           }

  774.         c_type_print_modifier (type, stream, 0, 1);
  775.         if (TYPE_CODE (type) == TYPE_CODE_UNION)
  776.           fprintf_filtered (stream, "union ");
  777.         else if (TYPE_DECLARED_CLASS (type))
  778.           fprintf_filtered (stream, "class ");
  779.         else
  780.           fprintf_filtered (stream, "struct ");

  781.         /* Print the tag if it exists.  The HP aCC compiler emits a
  782.            spurious "{unnamed struct}"/"{unnamed union}"/"{unnamed
  783.            enum}" tag for unnamed struct/union/enum's, which we don't
  784.            want to print.  */
  785.         if (TYPE_TAG_NAME (type) != NULL
  786.             && strncmp (TYPE_TAG_NAME (type), "{unnamed", 8))
  787.           {
  788.             /* When printing the tag name, we are still effectively
  789.                printing in the outer context, hence the use of FLAGS
  790.                here.  */
  791.             print_name_maybe_canonical (TYPE_TAG_NAME (type), flags, stream);
  792.             if (show > 0)
  793.               fputs_filtered (" ", stream);
  794.           }

  795.         if (show < 0)
  796.           {
  797.             /* If we just printed a tag name, no need to print anything
  798.                else.  */
  799.             if (TYPE_TAG_NAME (type) == NULL)
  800.               fprintf_filtered (stream, "{...}");
  801.           }
  802.         else if (show > 0 || TYPE_TAG_NAME (type) == NULL)
  803.           {
  804.             struct type *basetype;
  805.             int vptr_fieldno;

  806.             c_type_print_template_args (&local_flags, type, stream);

  807.             /* Add in template parameters when printing derivation info.  */
  808.             add_template_parameters (local_flags.local_typedefs, type);
  809.             cp_type_print_derivation_info (stream, type, &local_flags);

  810.             /* This holds just the global typedefs and the template
  811.                parameters.  */
  812.             semi_local_flags.local_typedefs
  813.               = copy_typedef_hash (local_flags.local_typedefs);
  814.             if (semi_local_flags.local_typedefs)
  815.               make_cleanup_free_typedef_hash (semi_local_flags.local_typedefs);

  816.             /* Now add in the local typedefs.  */
  817.             recursively_update_typedef_hash (local_flags.local_typedefs, type);

  818.             fprintf_filtered (stream, "{\n");
  819.             if (TYPE_NFIELDS (type) == 0 && TYPE_NFN_FIELDS (type) == 0
  820.                 && TYPE_TYPEDEF_FIELD_COUNT (type) == 0)
  821.               {
  822.                 if (TYPE_STUB (type))
  823.                   fprintfi_filtered (level + 4, stream,
  824.                                      _("<incomplete type>\n"));
  825.                 else
  826.                   fprintfi_filtered (level + 4, stream,
  827.                                      _("<no data fields>\n"));
  828.               }

  829.             /* Start off with no specific section type, so we can print
  830.                one for the first field we find, and use that section type
  831.                thereafter until we find another type.  */

  832.             section_type = s_none;

  833.             /* For a class, if all members are private, there's no need
  834.                for a "private:" label; similarly, for a struct or union
  835.                masquerading as a class, if all members are public, there's
  836.                no need for a "public:" label.  */

  837.             if (TYPE_DECLARED_CLASS (type))
  838.               {
  839.                 QUIT;
  840.                 len = TYPE_NFIELDS (type);
  841.                 for (i = TYPE_N_BASECLASSES (type); i < len; i++)
  842.                   if (!TYPE_FIELD_PRIVATE (type, i))
  843.                     {
  844.                       need_access_label = 1;
  845.                       break;
  846.                     }
  847.                 QUIT;
  848.                 if (!need_access_label)
  849.                   {
  850.                     len2 = TYPE_NFN_FIELDS (type);
  851.                     for (j = 0; j < len2; j++)
  852.                       {
  853.                         len = TYPE_FN_FIELDLIST_LENGTH (type, j);
  854.                         for (i = 0; i < len; i++)
  855.                           if (!TYPE_FN_FIELD_PRIVATE (TYPE_FN_FIELDLIST1 (type,
  856.                                                                           j), i))
  857.                             {
  858.                               need_access_label = 1;
  859.                               break;
  860.                             }
  861.                         if (need_access_label)
  862.                           break;
  863.                       }
  864.                   }
  865.               }
  866.             else
  867.               {
  868.                 QUIT;
  869.                 len = TYPE_NFIELDS (type);
  870.                 for (i = TYPE_N_BASECLASSES (type); i < len; i++)
  871.                   if (TYPE_FIELD_PRIVATE (type, i)
  872.                       || TYPE_FIELD_PROTECTED (type, i))
  873.                     {
  874.                       need_access_label = 1;
  875.                       break;
  876.                     }
  877.                 QUIT;
  878.                 if (!need_access_label)
  879.                   {
  880.                     len2 = TYPE_NFN_FIELDS (type);
  881.                     for (j = 0; j < len2; j++)
  882.                       {
  883.                         QUIT;
  884.                         len = TYPE_FN_FIELDLIST_LENGTH (type, j);
  885.                         for (i = 0; i < len; i++)
  886.                           if (TYPE_FN_FIELD_PROTECTED (TYPE_FN_FIELDLIST1 (type,
  887.                                                                            j), i)
  888.                               || TYPE_FN_FIELD_PRIVATE (TYPE_FN_FIELDLIST1 (type,
  889.                                                                             j),
  890.                                                         i))
  891.                             {
  892.                               need_access_label = 1;
  893.                               break;
  894.                             }
  895.                         if (need_access_label)
  896.                           break;
  897.                       }
  898.                   }
  899.               }

  900.             /* If there is a base class for this type,
  901.                do not print the field that it occupies.  */

  902.             len = TYPE_NFIELDS (type);
  903.             vptr_fieldno = get_vptr_fieldno (type, &basetype);
  904.             for (i = TYPE_N_BASECLASSES (type); i < len; i++)
  905.               {
  906.                 QUIT;

  907.                 /* If we have a virtual table pointer, omit it.  Even if
  908.                    virtual table pointers are not specifically marked in
  909.                    the debug info, they should be artificial.  */
  910.                 if ((i == vptr_fieldno && type == basetype)
  911.                     || TYPE_FIELD_ARTIFICIAL (type, i))
  912.                   continue;

  913.                 if (need_access_label)
  914.                   {
  915.                     if (TYPE_FIELD_PROTECTED (type, i))
  916.                       {
  917.                         if (section_type != s_protected)
  918.                           {
  919.                             section_type = s_protected;
  920.                             fprintfi_filtered (level + 2, stream,
  921.                                                "protected:\n");
  922.                           }
  923.                       }
  924.                     else if (TYPE_FIELD_PRIVATE (type, i))
  925.                       {
  926.                         if (section_type != s_private)
  927.                           {
  928.                             section_type = s_private;
  929.                             fprintfi_filtered (level + 2, stream,
  930.                                                "private:\n");
  931.                           }
  932.                       }
  933.                     else
  934.                       {
  935.                         if (section_type != s_public)
  936.                           {
  937.                             section_type = s_public;
  938.                             fprintfi_filtered (level + 2, stream,
  939.                                                "public:\n");
  940.                           }
  941.                       }
  942.                   }

  943.                 print_spaces_filtered (level + 4, stream);
  944.                 if (field_is_static (&TYPE_FIELD (type, i)))
  945.                   fprintf_filtered (stream, "static ");
  946.                 c_print_type (TYPE_FIELD_TYPE (type, i),
  947.                               TYPE_FIELD_NAME (type, i),
  948.                               stream, show - 1, level + 4,
  949.                               &local_flags);
  950.                 if (!field_is_static (&TYPE_FIELD (type, i))
  951.                     && TYPE_FIELD_PACKED (type, i))
  952.                   {
  953.                     /* It is a bitfield.  This code does not attempt
  954.                        to look at the bitpos and reconstruct filler,
  955.                        unnamed fields.  This would lead to misleading
  956.                        results if the compiler does not put out fields
  957.                        for such things (I don't know what it does).  */
  958.                     fprintf_filtered (stream, " : %d",
  959.                                       TYPE_FIELD_BITSIZE (type, i));
  960.                   }
  961.                 fprintf_filtered (stream, ";\n");
  962.               }

  963.           /* If there are both fields and methods, put a blank line
  964.              between them.  Make sure to count only method that we
  965.              will display; artificial methods will be hidden.  */
  966.           len = TYPE_NFN_FIELDS (type);
  967.           if (!flags->print_methods)
  968.             len = 0;
  969.           real_len = 0;
  970.           for (i = 0; i < len; i++)
  971.             {
  972.               struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i);
  973.               int len2 = TYPE_FN_FIELDLIST_LENGTH (type, i);
  974.               int j;

  975.               for (j = 0; j < len2; j++)
  976.                 if (!TYPE_FN_FIELD_ARTIFICIAL (f, j))
  977.                   real_len++;
  978.             }
  979.           if (real_len > 0 && section_type != s_none)
  980.             fprintf_filtered (stream, "\n");

  981.           /* C++: print out the methods.  */
  982.           for (i = 0; i < len; i++)
  983.             {
  984.               struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i);
  985.               int j, len2 = TYPE_FN_FIELDLIST_LENGTH (type, i);
  986.               const char *method_name = TYPE_FN_FIELDLIST_NAME (type, i);
  987.               const char *name = type_name_no_tag (type);
  988.               int is_constructor = name && strcmp (method_name,
  989.                                                    name) == 0;

  990.               for (j = 0; j < len2; j++)
  991.                 {
  992.                   const char *mangled_name;
  993.                   char *demangled_name;
  994.                   struct cleanup *inner_cleanup;
  995.                   const char *physname = TYPE_FN_FIELD_PHYSNAME (f, j);
  996.                   int is_full_physname_constructor =
  997.                     TYPE_FN_FIELD_CONSTRUCTOR (f, j)
  998.                     || is_constructor_name (physname)
  999.                     || is_destructor_name (physname)
  1000.                     || method_name[0] == '~';

  1001.                   /* Do not print out artificial methods.  */
  1002.                   if (TYPE_FN_FIELD_ARTIFICIAL (f, j))
  1003.                     continue;

  1004.                   inner_cleanup = make_cleanup (null_cleanup, NULL);

  1005.                   QUIT;
  1006.                   if (TYPE_FN_FIELD_PROTECTED (f, j))
  1007.                     {
  1008.                       if (section_type != s_protected)
  1009.                         {
  1010.                           section_type = s_protected;
  1011.                           fprintfi_filtered (level + 2, stream,
  1012.                                              "protected:\n");
  1013.                         }
  1014.                     }
  1015.                   else if (TYPE_FN_FIELD_PRIVATE (f, j))
  1016.                     {
  1017.                       if (section_type != s_private)
  1018.                         {
  1019.                           section_type = s_private;
  1020.                           fprintfi_filtered (level + 2, stream,
  1021.                                              "private:\n");
  1022.                         }
  1023.                     }
  1024.                   else
  1025.                     {
  1026.                       if (section_type != s_public)
  1027.                         {
  1028.                           section_type = s_public;
  1029.                           fprintfi_filtered (level + 2, stream,
  1030.                                              "public:\n");
  1031.                         }
  1032.                     }

  1033.                   print_spaces_filtered (level + 4, stream);
  1034.                   if (TYPE_FN_FIELD_VIRTUAL_P (f, j))
  1035.                     fprintf_filtered (stream, "virtual ");
  1036.                   else if (TYPE_FN_FIELD_STATIC_P (f, j))
  1037.                     fprintf_filtered (stream, "static ");
  1038.                   if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)) == 0)
  1039.                     {
  1040.                       /* Keep GDB from crashing here.  */
  1041.                       fprintf_filtered (stream,
  1042.                                         _("<undefined type> %s;\n"),
  1043.                                         TYPE_FN_FIELD_PHYSNAME (f, j));
  1044.                       break;
  1045.                     }
  1046.                   else if (!is_constructor        /* Constructors don't
  1047.                                                    have declared
  1048.                                                    types.  */
  1049.                            && !is_full_physname_constructor  /* " " */
  1050.                            && !is_type_conversion_operator (type, i, j))
  1051.                     {
  1052.                       c_print_type (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)),
  1053.                                     "", stream, -1, 0,
  1054.                                     &local_flags);
  1055.                       fputs_filtered (" ", stream);
  1056.                     }
  1057.                   if (TYPE_FN_FIELD_STUB (f, j))
  1058.                     {
  1059.                       char *tem;

  1060.                       /* Build something we can demangle.  */
  1061.                       tem = gdb_mangle_name (type, i, j);
  1062.                       make_cleanup (xfree, tem);
  1063.                       mangled_name = tem;
  1064.                     }
  1065.                   else
  1066.                     mangled_name = TYPE_FN_FIELD_PHYSNAME (f, j);

  1067.                   demangled_name =
  1068.                     gdb_demangle (mangled_name,
  1069.                                   DMGL_ANSI | DMGL_PARAMS);
  1070.                   if (demangled_name == NULL)
  1071.                     {
  1072.                       /* In some cases (for instance with the HP
  1073.                          demangling), if a function has more than 10
  1074.                          arguments, the demangling will fail.
  1075.                          Let's try to reconstruct the function
  1076.                          signature from the symbol information.  */
  1077.                       if (!TYPE_FN_FIELD_STUB (f, j))
  1078.                         {
  1079.                           int staticp = TYPE_FN_FIELD_STATIC_P (f, j);
  1080.                           struct type *mtype = TYPE_FN_FIELD_TYPE (f, j);

  1081.                           cp_type_print_method_args (mtype,
  1082.                                                      "",
  1083.                                                      method_name,
  1084.                                                      staticp,
  1085.                                                      stream, &local_flags);
  1086.                         }
  1087.                       else
  1088.                         fprintf_filtered (stream,
  1089.                                           _("<badly mangled name '%s'>"),
  1090.                                           mangled_name);
  1091.                     }
  1092.                   else
  1093.                     {
  1094.                       char *p;
  1095.                       char *demangled_no_class
  1096.                         = remove_qualifiers (demangled_name);

  1097.                       /* Get rid of the `static' appended by the
  1098.                          demangler.  */
  1099.                       p = strstr (demangled_no_class, " static");
  1100.                       if (p != NULL)
  1101.                         {
  1102.                           int length = p - demangled_no_class;
  1103.                           char *demangled_no_static;

  1104.                           demangled_no_static
  1105.                             = (char *) xmalloc (length + 1);
  1106.                           strncpy (demangled_no_static,
  1107.                                    demangled_no_class, length);
  1108.                           *(demangled_no_static + length) = '\0';
  1109.                           fputs_filtered (demangled_no_static, stream);
  1110.                           xfree (demangled_no_static);
  1111.                         }
  1112.                       else
  1113.                         fputs_filtered (demangled_no_class, stream);
  1114.                       xfree (demangled_name);
  1115.                     }

  1116.                   do_cleanups (inner_cleanup);

  1117.                   fprintf_filtered (stream, ";\n");
  1118.                 }
  1119.             }

  1120.           /* Print typedefs defined in this class.  */

  1121.           if (TYPE_TYPEDEF_FIELD_COUNT (type) != 0 && flags->print_typedefs)
  1122.             {
  1123.               if (TYPE_NFIELDS (type) != 0 || TYPE_NFN_FIELDS (type) != 0)
  1124.                 fprintf_filtered (stream, "\n");

  1125.                 for (i = 0; i < TYPE_TYPEDEF_FIELD_COUNT (type); i++)
  1126.                   {
  1127.                     struct type *target = TYPE_TYPEDEF_FIELD_TYPE (type, i);

  1128.                     /* Dereference the typedef declaration itself.  */
  1129.                     gdb_assert (TYPE_CODE (target) == TYPE_CODE_TYPEDEF);
  1130.                     target = TYPE_TARGET_TYPE (target);

  1131.                     print_spaces_filtered (level + 4, stream);
  1132.                     fprintf_filtered (stream, "typedef ");

  1133.                     /* We want to print typedefs with substitutions
  1134.                        from the template parameters or globally-known
  1135.                        typedefs but not local typedefs.  */
  1136.                     c_print_type (target,
  1137.                                   TYPE_TYPEDEF_FIELD_NAME (type, i),
  1138.                                   stream, show - 1, level + 4,
  1139.                                   &semi_local_flags);
  1140.                     fprintf_filtered (stream, ";\n");
  1141.                   }
  1142.               }

  1143.             fprintfi_filtered (level, stream, "}");
  1144.           }

  1145.         do_cleanups (local_cleanups);
  1146.       }
  1147.       break;

  1148.     case TYPE_CODE_ENUM:
  1149.       c_type_print_modifier (type, stream, 0, 1);
  1150.       fprintf_filtered (stream, "enum ");
  1151.       if (TYPE_DECLARED_CLASS (type))
  1152.         fprintf_filtered (stream, "class ");
  1153.       /* Print the tag name if it exists.
  1154.          The aCC compiler emits a spurious
  1155.          "{unnamed struct}"/"{unnamed union}"/"{unnamed enum}"
  1156.          tag for unnamed struct/union/enum's, which we don't
  1157.          want to print.  */
  1158.       if (TYPE_TAG_NAME (type) != NULL
  1159.           && strncmp (TYPE_TAG_NAME (type), "{unnamed", 8))
  1160.         {
  1161.           print_name_maybe_canonical (TYPE_TAG_NAME (type), flags, stream);
  1162.           if (show > 0)
  1163.             fputs_filtered (" ", stream);
  1164.         }

  1165.       wrap_here ("    ");
  1166.       if (show < 0)
  1167.         {
  1168.           /* If we just printed a tag name, no need to print anything
  1169.              else.  */
  1170.           if (TYPE_TAG_NAME (type) == NULL)
  1171.             fprintf_filtered (stream, "{...}");
  1172.         }
  1173.       else if (show > 0 || TYPE_TAG_NAME (type) == NULL)
  1174.         {
  1175.           LONGEST lastval = 0;

  1176.           /* We can't handle this case perfectly, as DWARF does not
  1177.              tell us whether or not the underlying type was specified
  1178.              in the source (and other debug formats don't provide this
  1179.              at all).  We choose to print the underlying type, if it
  1180.              has a name, when in C++ on the theory that it's better to
  1181.              print too much than too little; but conversely not to
  1182.              print something egregiously outside the current
  1183.              language's syntax.  */
  1184.           if (current_language->la_language == language_cplus
  1185.               && TYPE_TARGET_TYPE (type) != NULL)
  1186.             {
  1187.               struct type *underlying = check_typedef (TYPE_TARGET_TYPE (type));

  1188.               if (TYPE_NAME (underlying) != NULL)
  1189.                 fprintf_filtered (stream, ": %s ", TYPE_NAME (underlying));
  1190.             }

  1191.           fprintf_filtered (stream, "{");
  1192.           len = TYPE_NFIELDS (type);
  1193.           for (i = 0; i < len; i++)
  1194.             {
  1195.               QUIT;
  1196.               if (i)
  1197.                 fprintf_filtered (stream, ", ");
  1198.               wrap_here ("    ");
  1199.               fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
  1200.               if (lastval != TYPE_FIELD_ENUMVAL (type, i))
  1201.                 {
  1202.                   fprintf_filtered (stream, " = %s",
  1203.                                     plongest (TYPE_FIELD_ENUMVAL (type, i)));
  1204.                   lastval = TYPE_FIELD_ENUMVAL (type, i);
  1205.                 }
  1206.               lastval++;
  1207.             }
  1208.           fprintf_filtered (stream, "}");
  1209.         }
  1210.       break;

  1211.     case TYPE_CODE_VOID:
  1212.       fprintf_filtered (stream, "void");
  1213.       break;

  1214.     case TYPE_CODE_UNDEF:
  1215.       fprintf_filtered (stream, _("struct <unknown>"));
  1216.       break;

  1217.     case TYPE_CODE_ERROR:
  1218.       fprintf_filtered (stream, "%s", TYPE_ERROR_NAME (type));
  1219.       break;

  1220.     case TYPE_CODE_RANGE:
  1221.       /* This should not occur.  */
  1222.       fprintf_filtered (stream, _("<range type>"));
  1223.       break;

  1224.     case TYPE_CODE_NAMESPACE:
  1225.       fputs_filtered ("namespace ", stream);
  1226.       fputs_filtered (TYPE_TAG_NAME (type), stream);
  1227.       break;

  1228.     default:
  1229.       /* Handle types not explicitly handled by the other cases, such
  1230.          as fundamental types.  For these, just print whatever the
  1231.          type name is, as recorded in the type itself.  If there is no
  1232.          type name, then complain.  */
  1233.       if (TYPE_NAME (type) != NULL)
  1234.         {
  1235.           c_type_print_modifier (type, stream, 0, 1);
  1236.           print_name_maybe_canonical (TYPE_NAME (type), flags, stream);
  1237.         }
  1238.       else
  1239.         {
  1240.           /* At least for dump_symtab, it is important that this not
  1241.              be an error ().  */
  1242.           fprintf_filtered (stream, _("<invalid type code %d>"),
  1243.                             TYPE_CODE (type));
  1244.         }
  1245.       break;
  1246.     }
  1247. }