home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Atari / Gnu / gdb36p4s.zoo / valprint.c < prev    next >
C/C++ Source or Header  |  1993-08-13  |  41KB  |  1,498 lines

  1. /* Print values for GNU debugger gdb.
  2.    Copyright (C) 1986, 1988, 1989 Free Software Foundation, Inc.
  3.  
  4. This file is part of GDB.
  5.  
  6. GDB is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. GDB is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GDB; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #include <stdio.h>
  21. #include "defs.h"
  22. #include "param.h"
  23. #include "symtab.h"
  24. #include "value.h"
  25.  
  26. /* GNU software is only expected to run on systems with 32-bit integers.  */
  27. #define UINT_MAX 0xffffffff
  28.  
  29. /* Maximum number of chars to print for a string pointer value
  30.    or vector contents, or UINT_MAX for no limit.  */
  31.  
  32. static unsigned int print_max;
  33.  
  34. static void type_print_varspec_suffix ();
  35. static void type_print_varspec_prefix ();
  36. static void type_print_base ();
  37. static void type_print_method_args ();
  38.  
  39.  
  40. char **unsigned_type_table;
  41. char **signed_type_table;
  42. char **float_type_table;
  43.  
  44.  
  45. /* Print repeat counts if there are more than this
  46.    many repetitions of an element in an array.  */
  47. #define    REPEAT_COUNT_THRESHOLD    10
  48.  
  49. /* Print the character string STRING, printing at most LENGTH characters.
  50.    Printing stops early if the number hits print_max; repeat counts
  51.    are printed as appropriate.  Print ellipses at the end if we
  52.    had to stop before printing LENGTH characters, or if FORCE_ELLIPSES.  */
  53.  
  54. void
  55. print_string (stream, string, length, force_ellipses)
  56.      FILE *stream;
  57.      char *string;
  58.      unsigned int length;
  59.      int force_ellipses;
  60. {
  61.   register unsigned int i;
  62.   unsigned int things_printed = 0;
  63.   int in_quotes = 0;
  64.   int need_comma = 0;
  65.  
  66.   if (length == 0)
  67.     {
  68.       fputs_filtered ("\"\"", stdout);
  69.       return;
  70.     }
  71.  
  72.   for (i = 0; i < length && things_printed < print_max; ++i)
  73.     {
  74.       /* Position of the character we are examining
  75.      to see whether it is repeated.  */
  76.       unsigned int rep1;
  77.       /* Number of repititions we have detected so far.  */
  78.       unsigned int reps;
  79.  
  80.       QUIT;
  81.  
  82.       if (need_comma)
  83.     {
  84.       fputs_filtered (", ", stream);
  85.       need_comma = 0;
  86.     }
  87.  
  88.       rep1 = i + 1;
  89.       reps = 1;
  90.       while (rep1 < length && string[rep1] == string[i])
  91.     {
  92.       ++rep1;
  93.       ++reps;
  94.     }
  95.  
  96.       if (reps > REPEAT_COUNT_THRESHOLD)
  97.     {
  98.       if (in_quotes)
  99.         {
  100.           fputs_filtered ("\", ", stream);
  101.           in_quotes = 0;
  102.         }
  103.       fputs_filtered ("'", stream);
  104.       printchar (string[i], stream, '\'');
  105.       fprintf_filtered (stream, "' <repeats %u times>", reps);
  106.       i = rep1 - 1;
  107.       things_printed += REPEAT_COUNT_THRESHOLD;
  108.       need_comma = 1;
  109.     }
  110.       else
  111.     {
  112.       if (!in_quotes)
  113.         {
  114.           fputs_filtered ("\"", stream);
  115.           in_quotes = 1;
  116.         }
  117.       printchar (string[i], stream, '"');
  118.       ++things_printed;
  119.     }
  120.     }
  121.  
  122.   /* Terminate the quotes if necessary.  */
  123.   if (in_quotes)
  124.     fputs_filtered ("\"", stream);
  125.  
  126.   if (force_ellipses || i < length)
  127.     fputs_filtered ("...", stream);
  128. }
  129.  
  130. /* Print the value VAL in C-ish syntax on stream STREAM.
  131.    FORMAT is a format-letter, or 0 for print in natural format of data type.
  132.    If the object printed is a string pointer, returns
  133.    the number of string bytes printed.  */
  134.  
  135. int
  136. value_print (val, stream, format, pretty)
  137.      value val;
  138.      FILE *stream;
  139.      char format;
  140.      enum val_prettyprint pretty;
  141. {
  142.   register unsigned int i, n, typelen;
  143.  
  144.   /* A "repeated" value really contains several values in a row.
  145.      They are made by the @ operator.
  146.      Print such values as if they were arrays.  */
  147.  
  148.   if (VALUE_REPEATED (val))
  149.     {
  150.       n = VALUE_REPETITIONS (val);
  151.       typelen = TYPE_LENGTH (VALUE_TYPE (val));
  152.       fprintf_filtered (stream, "{");
  153.       /* Print arrays of characters using string syntax.  */
  154.       if (typelen == 1 && TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_INT
  155.       && format == 0)
  156.     print_string (stream, VALUE_CONTENTS (val), n, 0);
  157.       else
  158.     {
  159.       unsigned int things_printed = 0;
  160.       
  161.       for (i = 0; i < n && things_printed < print_max; i++)
  162.         {
  163.           /* Position of the array element we are examining to see
  164.          whether it is repeated.  */
  165.           unsigned int rep1;
  166.           /* Number of repititions we have detected so far.  */
  167.           unsigned int reps;
  168.  
  169.           if (i != 0)
  170.         fprintf_filtered (stream, ", ");
  171.  
  172.           rep1 = i + 1;
  173.           reps = 1;
  174.           while (rep1 < n
  175.              && !bcmp (VALUE_CONTENTS (val) + typelen * i,
  176.                    VALUE_CONTENTS (val) + typelen * rep1, typelen))
  177.         {
  178.           ++reps;
  179.           ++rep1;
  180.         }
  181.  
  182.           if (reps > REPEAT_COUNT_THRESHOLD)
  183.         {
  184.           val_print (VALUE_TYPE (val),
  185.                  VALUE_CONTENTS (val) + typelen * i,
  186.                  VALUE_ADDRESS (val) + typelen * i,
  187.                  stream, format, 1, 0, pretty);
  188.           fprintf (stream, " <repeats %u times>", reps);
  189.           i = rep1 - 1;
  190.           things_printed += REPEAT_COUNT_THRESHOLD;
  191.         }
  192.           else
  193.         {
  194.           val_print (VALUE_TYPE (val),
  195.                  VALUE_CONTENTS (val) + typelen * i,
  196.                  VALUE_ADDRESS (val) + typelen * i,
  197.                  stream, format, 1, 0, pretty);
  198.           things_printed++;
  199.         }
  200.         }
  201.       if (i < n)
  202.         fprintf_filtered (stream, "...");
  203.     }
  204.       fprintf_filtered (stream, "}");
  205.       return n * typelen;
  206.     }
  207.   else
  208.     {
  209.       /* If it is a pointer, indicate what it points to.
  210.  
  211.      Print type also if it is a reference.
  212.  
  213.          C++: if it is a member pointer, we will take care
  214.      of that when we print it.  */
  215.       if (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_PTR
  216.       || TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_REF)
  217.     {
  218.       fprintf_filtered (stream, "(");
  219.       type_print (VALUE_TYPE (val), "", stream, -1);
  220.       fprintf_filtered (stream, ") ");
  221.  
  222.       /* If this is a function pointer, try to print what
  223.          function it is pointing to by name.  */
  224.       if (TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (val)))
  225.           == TYPE_CODE_FUNC)
  226.         {
  227.           print_address (((int *) VALUE_CONTENTS (val))[0], stream);
  228.           /* Return value is irrelevant except for string pointers.  */
  229.           return 0;
  230.         }
  231.     }
  232.       return val_print (VALUE_TYPE (val), VALUE_CONTENTS (val),
  233.             VALUE_ADDRESS (val), stream, format, 1, 0, pretty);
  234.     }
  235. }
  236.  
  237. /* Return truth value for assertion that TYPE is of the type
  238.    "pointer to virtual function".  */
  239. static int
  240. is_vtbl_ptr_type(type)
  241.      struct type *type;
  242. {
  243.   return (!strcmp(TYPE_NAME(type), "$vtbl_ptr_type"));
  244. }
  245.  
  246. /* Return truth value for the assertion that TYPE is of the type
  247.    "pointer to virtual function table".  */
  248. static int
  249. is_vtbl_member(type)
  250.      struct type *type;
  251. {
  252.   if (TYPE_CODE (type) == TYPE_CODE_PTR
  253.       && TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_ARRAY
  254.       && TYPE_CODE (TYPE_TARGET_TYPE (TYPE_TARGET_TYPE (type))) == TYPE_CODE_STRUCT)
  255.     /* Virtual functions tables are full of pointers to virtual functions.  */
  256.     return is_vtbl_ptr_type (TYPE_TARGET_TYPE (TYPE_TARGET_TYPE (type)));
  257.   return 0;
  258. }
  259.  
  260. static int prettyprint;    /* Controls prettyprinting of structures.  */
  261. int unionprint;        /* Controls printing of nested unions.  */
  262. int vtblprint;        /* Controls printing of vtbl's */
  263.  
  264. /* Print data of type TYPE located at VALADDR (within GDB),
  265.    which came from the inferior at address ADDRESS,
  266.    onto stdio stream STREAM according to FORMAT
  267.    (a letter or 0 for natural format).
  268.  
  269.    If the data are a string pointer, returns the number of
  270.    sting characters printed.
  271.  
  272.    if DEREF_REF is nonzero, then dereference references,
  273.    otherwise just print them like pointers.
  274.  
  275.    The PRETTY parameter controls prettyprinting.  */
  276.  
  277. int
  278. val_print (type, valaddr, address, stream, format,
  279.        deref_ref, recurse, pretty)
  280.      struct type *type;
  281.      char *valaddr;
  282.      CORE_ADDR address;
  283.      FILE *stream;
  284.      char format;
  285.      int deref_ref;
  286.      int recurse;
  287.      enum val_prettyprint pretty;
  288. {
  289.   register unsigned int i;
  290.   int len, n_baseclasses;
  291.   struct type *elttype;
  292.   int eltlen;
  293.   LONGEST val;
  294.   unsigned char c;
  295.  
  296.   if (pretty == Val_pretty_default)
  297.     {
  298.       pretty = prettyprint ? Val_prettyprint : Val_no_prettyprint;
  299.     }
  300.   
  301.   QUIT;
  302.  
  303.   check_stub_type(type);
  304.  
  305.   if (TYPE_FLAGS (type) & TYPE_FLAG_STUB)
  306.     {
  307.       fprintf_filtered (stream, "<Type not defined in this context>");
  308.       fflush (stream);
  309.       return 0;
  310.     }
  311.   
  312.   switch (TYPE_CODE (type))
  313.     {
  314.     case TYPE_CODE_ARRAY:
  315.       if (TYPE_LENGTH (type) >= 0
  316.       && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0)
  317.     {
  318.       elttype = TYPE_TARGET_TYPE (type);
  319.       eltlen = TYPE_LENGTH (elttype);
  320.       len = TYPE_LENGTH (type) / eltlen;
  321.       fprintf_filtered (stream, "{");
  322.       /* For an array of chars, print with string syntax.  */
  323.       if (eltlen == 1 && TYPE_CODE (elttype) == TYPE_CODE_INT
  324.           && format == 0)
  325.         print_string (stream, valaddr, len, 0);
  326.       else
  327.         {
  328.           unsigned int things_printed = 0;
  329.           
  330.           for (i = 0; i < len && things_printed < print_max; i++)
  331.         {
  332.           /* Position of the array element we are examining to see
  333.              whether it is repeated.  */
  334.           unsigned int rep1;
  335.           /* Number of repititions we have detected so far.  */
  336.           unsigned int reps;
  337.           
  338.           if (i > 0)
  339.             fprintf_filtered (stream, ", ");
  340.  
  341.           rep1 = i + 1;
  342.           reps = 1;
  343.           while (rep1 < len
  344.              && !bcmp (valaddr + i * eltlen,
  345.                    valaddr + rep1 * eltlen, eltlen))
  346.             {
  347.               ++reps;
  348.               ++rep1;
  349.             }
  350.  
  351.           if (reps > REPEAT_COUNT_THRESHOLD)
  352.             {
  353.               val_print (elttype, valaddr + i * eltlen,
  354.                  0, stream, format, deref_ref,
  355.                  recurse + 1, pretty);
  356.               fprintf_filtered (stream, " <repeats %u times>", reps);
  357.               i = rep1 - 1;
  358.               things_printed += REPEAT_COUNT_THRESHOLD;
  359.             }
  360.           else
  361.             {
  362.               val_print (elttype, valaddr + i * eltlen,
  363.                  0, stream, format, deref_ref,
  364.                  recurse + 1, pretty);
  365.               things_printed++;
  366.             }
  367.         }
  368.           if (i < len)
  369.         fprintf_filtered (stream, "...");
  370.         }
  371.       fprintf_filtered (stream, "}");
  372.       break;
  373.     }
  374.       /* Array of unspecified length: treat like pointer to first elt.  */
  375.       valaddr = (char *) &address;
  376.  
  377.     case TYPE_CODE_PTR:
  378.       if (format)
  379.     {
  380.       print_scalar_formatted (valaddr, type, format, 0, stream);
  381.       break;
  382.     }
  383.       if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_METHOD)
  384.     {
  385.       struct type *domain = TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type));
  386.       struct type *target = TYPE_TARGET_TYPE (TYPE_TARGET_TYPE (type));
  387.       struct fn_field *f;
  388.       int j, len2;
  389.       char *kind = "";
  390.  
  391.       val = unpack_long (builtin_type_int, valaddr);
  392.       if (val < 128)
  393.         {
  394.           len = TYPE_NFN_FIELDS (domain);
  395.           for (i = 0; i < len; i++)
  396.         {
  397.           f = TYPE_FN_FIELDLIST1 (domain, i);
  398.           len2 = TYPE_FN_FIELDLIST_LENGTH (domain, i);
  399.  
  400.           for (j = 0; j < len2; j++)
  401.             {
  402.               QUIT;
  403.               if (TYPE_FN_FIELD_VOFFSET (f, j) == val)
  404.             {
  405.               kind = "virtual";
  406.               goto common;
  407.             }
  408.             }
  409.         }
  410.         }
  411.       else
  412.         {
  413.           struct symbol *sym = find_pc_function ((CORE_ADDR) val);
  414.           if (sym == 0)
  415.         error ("invalid pointer to member function");
  416.           len = TYPE_NFN_FIELDS (domain);
  417.           for (i = 0; i < len; i++)
  418.         {
  419.           f = TYPE_FN_FIELDLIST1 (domain, i);
  420.           len2 = TYPE_FN_FIELDLIST_LENGTH (domain, i);
  421.  
  422.           for (j = 0; j < len2; j++)
  423.             {
  424.               QUIT;
  425.               if (!strcmp (SYMBOL_NAME (sym), TYPE_FN_FIELD_PHYSNAME (f, j)))
  426.             goto common;
  427.             }
  428.         }
  429.         }
  430.     common:
  431.       if (i < len)
  432.         {
  433.           fprintf_filtered (stream, "&");
  434.           type_print_varspec_prefix (TYPE_FN_FIELD_TYPE (f, j), stream, 0, 0);
  435.           fprintf (stream, kind);
  436.           if (TYPE_FN_FIELD_PHYSNAME (f, j)[0] == '_'
  437.           && TYPE_FN_FIELD_PHYSNAME (f, j)[1] == '$')
  438.         type_print_method_args
  439.           (TYPE_FN_FIELD_ARGS (f, j) + 1, "~",
  440.            TYPE_FN_FIELDLIST_NAME (domain, i), 0, stream);
  441.           else
  442.         type_print_method_args
  443.           (TYPE_FN_FIELD_ARGS (f, j), "",
  444.            TYPE_FN_FIELDLIST_NAME (domain, i), 0, stream);
  445.           break;
  446.         }
  447.       fprintf_filtered (stream, "(");
  448.         type_print (type, "", stream, -1);
  449.       fprintf_filtered (stream, ") %d", (int) val >> 3);
  450.     }
  451.       else if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_MEMBER)
  452.     {
  453.       struct type *domain = TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type));
  454.       struct type *target = TYPE_TARGET_TYPE (TYPE_TARGET_TYPE (type));
  455.       char *kind = "";
  456.  
  457.       /* VAL is a byte offset into the structure type DOMAIN.
  458.          Find the name of the field for that offset and
  459.          print it.  */
  460.       int extra = 0;
  461.       int bits = 0;
  462.       len = TYPE_NFIELDS (domain);
  463.       /* @@ Make VAL into bit offset */
  464.       val = unpack_long (builtin_type_int, valaddr) << 3;
  465.       for (i = 0; i < len; i++)
  466.         {
  467.           int bitpos = TYPE_FIELD_BITPOS (domain, i);
  468.           QUIT;
  469.           if (val == bitpos)
  470.         break;
  471.           if (val < bitpos && i > 0)
  472.         {
  473.           int ptrsize = (TYPE_LENGTH (builtin_type_char) * TYPE_LENGTH (target));
  474.           /* Somehow pointing into a field.  */
  475.           i -= 1;
  476.           extra = (val - TYPE_FIELD_BITPOS (domain, i));
  477.           if (extra & 0x3)
  478.             bits = 1;
  479.           else
  480.             extra >>= 3;
  481.           break;
  482.         }
  483.         }
  484.       if (i < len)
  485.         {
  486.           fprintf_filtered (stream, "&");
  487.           type_print_base (domain, stream, 0, 0);
  488.           fprintf_filtered (stream, "::");
  489.           fputs_filtered (TYPE_FIELD_NAME (domain, i), stream);
  490.           if (extra)
  491.         fprintf_filtered (stream, " + %d bytes", extra);
  492.           if (bits)
  493.         fprintf_filtered (stream, " (offset in bits)");
  494.           break;
  495.         }
  496.       fprintf_filtered (stream, "%d", val >> 3);
  497.     }
  498.       else
  499.     {
  500.       fprintf_filtered (stream, "0x%x", * (int *) valaddr);
  501.       /* For a pointer to char or unsigned char,
  502.          also print the string pointed to, unless pointer is null.  */
  503.       
  504.       /* For an array of chars, print with string syntax.  */
  505.       elttype = TYPE_TARGET_TYPE (type);
  506.       i = 0;        /* Number of characters printed.  */
  507.       if (TYPE_LENGTH (elttype) == 1 
  508.           && TYPE_CODE (elttype) == TYPE_CODE_INT
  509.           && format == 0
  510.           && unpack_long (type, valaddr) != 0
  511.           /* If print_max is UINT_MAX, the alloca below will fail.
  512.              In that case don't try to print the string.  */
  513.           && print_max < UINT_MAX)
  514.         {
  515.           fprintf_filtered (stream, " ");
  516.  
  517.           /* Get first character.  */
  518.           if (read_memory ( (CORE_ADDR) unpack_long (type, valaddr),
  519.                    &c, 1))
  520.         {
  521.           /* First address out of bounds.  */
  522.           fprintf_filtered (stream, "<Address 0x%x out of bounds>",
  523.                (* (int *) valaddr));
  524.           break;
  525.         }
  526.           else
  527.         {
  528.           /* A real string.  */
  529.           int out_of_bounds = 0;
  530.           char *string = (char *) alloca (print_max);
  531.  
  532.           /* If the loop ends by us hitting print_max characters,
  533.              we need to have elipses at the end.  */
  534.           int force_ellipses = 1;
  535.  
  536.           /* This loop only fetches print_max characters, even
  537.              though print_string might want to print more
  538.              (with repeated characters).  This is so that
  539.              we don't spend forever fetching if we print
  540.              a long string consisting of the same character
  541.              repeated.  */
  542.           while (i < print_max)
  543.             {
  544.               QUIT;
  545.               if (read_memory ((CORE_ADDR) unpack_long (type, valaddr)
  546.                        + i, &c, 1))
  547.             {
  548.               out_of_bounds = 1;
  549.               force_ellipses = 0;
  550.               break;
  551.             }
  552.               else if (c == '\0')
  553.             {
  554.               force_ellipses = 0;
  555.               break;
  556.             }
  557.               else
  558.             string[i++] = c;
  559.             }
  560.  
  561.           if (i != 0)
  562.             print_string (stream, string, i, force_ellipses);
  563.           if (out_of_bounds)
  564.             fprintf_filtered (stream,
  565.                       " <Address 0x%x out of bounds>",
  566.                       (*(int *) valaddr) + i);
  567.         }
  568.  
  569.           fflush (stream);
  570.         }
  571.         else /* print vtbl's nicely */
  572.       if (vtblprint && is_vtbl_member(type))
  573.         {
  574.           value val = value_at (TYPE_TARGET_TYPE (type), *((int *)valaddr));
  575.               val_print (VALUE_TYPE (val), VALUE_CONTENTS (val),
  576.              VALUE_ADDRESS (val), stream, format,
  577.              deref_ref, recurse + 1, pretty);
  578.         }
  579.  
  580.       /* Return number of characters printed, plus one for the
  581.          terminating null if we have "reached the end".  */
  582.       return i + (print_max && i != print_max);
  583.     }
  584.       break;
  585.  
  586.     case TYPE_CODE_MEMBER:
  587.       error ("not implemented: member type in val_print");
  588.       break;
  589.  
  590.     case TYPE_CODE_REF:
  591.       fprintf_filtered (stream, "(0x%x &) = ", * (int *) valaddr);
  592.       /* De-reference the reference.  */
  593.       if (deref_ref)
  594.     {
  595.       if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_UNDEF)
  596.         {
  597.           value val = value_at (TYPE_TARGET_TYPE (type), * (int *) valaddr);
  598.           val_print (VALUE_TYPE (val), VALUE_CONTENTS (val),
  599.              VALUE_ADDRESS (val), stream, format,
  600.              deref_ref, recurse + 1, pretty);
  601.         }
  602.       else
  603.         fprintf_filtered (stream, "???");
  604.     }
  605.       break;
  606.  
  607.     case TYPE_CODE_UNION:
  608.       if (recurse && !unionprint)
  609.     {
  610.       fprintf_filtered (stream, "{...}");
  611.       break;
  612.     }
  613.       /* Fall through.  */
  614.     case TYPE_CODE_STRUCT:
  615.       if (vtblprint && is_vtbl_ptr_type(type))
  616.     /* Print the unmangled name if desired.  */
  617.     print_address(unpack_long (type, valaddr + TYPE_FIELD_BITPOS (type, VTBL_FNADDR_OFFSET) / 8),
  618.               stream);
  619.  
  620.       fprintf_filtered (stream, "{");
  621.       len = TYPE_NFIELDS (type);
  622.       n_baseclasses = TYPE_N_BASECLASSES (type);
  623.       for (i = 1; i <= n_baseclasses; i++)
  624.     {
  625.       char *baddr = baseclass_addr (type, i, valaddr);
  626.       if (baddr == 0)
  627.         error ("could not find virtual baseclass `%s'\n",
  628.            type_name_no_tag (TYPE_BASECLASS (type, i)));
  629.       fprintf_filtered (stream, "\n");
  630.       if (pretty)
  631.         print_spaces_filtered (2 + 2 * recurse, stream);
  632.       fputs_filtered ("<", stream);
  633.       fputs_filtered (type_name_no_tag (TYPE_BASECLASS (type, i)), stream);
  634.       fputs_filtered ("> = ", stream);
  635.       val_print (TYPE_FIELD_TYPE (type, i-1), baddr,
  636.              0, stream, 0, 0, recurse + 1, pretty);
  637.     }
  638.       if (i > 1) {
  639.     fprintf_filtered (stream, "\n");
  640.     print_spaces_filtered (2 + 2 * recurse, stream);
  641.     fputs_filtered ("members of ", stream);
  642.         fputs_filtered (type_name_no_tag (type), stream);
  643.         fputs_filtered (": ", stream);
  644.       }
  645.       if (!len && i == 1)
  646.     fprintf_filtered (stream, "<No data fields>");
  647.       else
  648.     {
  649.       for (i -= 1; i < len; i++)
  650.         {
  651.           if (i > n_baseclasses) fprintf_filtered (stream, ", ");
  652.           if (pretty)
  653.         {
  654.           fprintf_filtered (stream, "\n");
  655.           print_spaces_filtered (2 + 2 * recurse, stream);
  656.         }
  657.           fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
  658.           fputs_filtered (" = ", stream);
  659.           /* check if static field */
  660.           if (TYPE_FIELD_STATIC (type, i))
  661.         {
  662.           value v;
  663.           
  664.           v = value_static_field (type, TYPE_FIELD_NAME (type, i), i);
  665.           val_print (TYPE_FIELD_TYPE (type, i),
  666.                  VALUE_CONTENTS (v), 0, stream, format,
  667.                  deref_ref, recurse + 1, pretty);
  668.         }
  669.           else if (TYPE_FIELD_PACKED (type, i))
  670.         {
  671.           char *valp = (char *) & val;
  672.           union {int i; char c;} test;
  673.           test.i = 1;
  674.           if (test.c != 1)
  675.             valp += sizeof val - TYPE_LENGTH (TYPE_FIELD_TYPE (type, i));
  676.           val = unpack_field_as_long (type, valaddr, i);
  677.           val_print (TYPE_FIELD_TYPE (type, i), valp, 0,
  678.                  stream, format, deref_ref, recurse + 1, pretty);
  679.         }
  680.           else
  681.         {
  682.           val_print (TYPE_FIELD_TYPE (type, i), 
  683.                  valaddr + TYPE_FIELD_BITPOS (type, i) / 8,
  684.                  0, stream, format, deref_ref,
  685.                  recurse + 1, pretty);
  686.         }
  687.         }
  688.       if (pretty)
  689.         {
  690.           fprintf_filtered (stream, "\n");
  691.           print_spaces_filtered (2 * recurse, stream);
  692.         }
  693.     }
  694.       fprintf_filtered (stream, "}");
  695.       break;
  696.  
  697.     case TYPE_CODE_ENUM:
  698.       if (format)
  699.     {
  700.       print_scalar_formatted (valaddr, type, format, 0, stream);
  701.       break;
  702.     }
  703.       len = TYPE_NFIELDS (type);
  704. #ifdef atarist
  705.       val = unpack_long (gcc_mshort ? builtin_type_short : builtin_type_int,
  706.              valaddr);
  707. #else
  708.       val = unpack_long (builtin_type_int, valaddr);
  709. #endif
  710.       for (i = 0; i < len; i++)
  711.     {
  712.       QUIT;
  713.       if (val == TYPE_FIELD_BITPOS (type, i))
  714.         break;
  715.     }
  716.       if (i < len)
  717.     fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
  718.       else
  719.     fprintf_filtered (stream, "%d", (int) val);
  720.       break;
  721.  
  722.     case TYPE_CODE_FUNC:
  723.       if (format)
  724.     {
  725.       print_scalar_formatted (valaddr, type, format, 0, stream);
  726.       break;
  727.     }
  728.       fprintf_filtered (stream, "{");
  729.       type_print (type, "", stream, -1);
  730.       fprintf_filtered (stream, "} ");
  731.       fprintf_filtered (stream, "0x%x", address);
  732.       break;
  733.  
  734.     case TYPE_CODE_INT:
  735.       if (format)
  736.     {
  737.       print_scalar_formatted (valaddr, type, format, 0, stream);
  738.       break;
  739.     }
  740. #ifdef PRINT_TYPELESS_INTEGER
  741.       PRINT_TYPELESS_INTEGER (stream, type, unpack_long (type, valaddr));
  742. #else
  743. #ifndef LONG_LONG
  744.       fprintf_filtered (stream,
  745.             TYPE_UNSIGNED (type) ? "%u" : "%d",
  746.             unpack_long (type, valaddr));
  747. #else
  748. #ifdef HAVE_LONG_LONG_PRINTF
  749.       fprintf_filtered (stream,
  750.             TYPE_UNSIGNED (type) ? "%llu" : "%lld",
  751.             unpack_long (type, valaddr));
  752. #else
  753.       fprintf_long_long (stream, TYPE_UNSIGNED (type),
  754.              unpack_long (type, valaddr));
  755. #endif
  756. #endif
  757. #endif
  758.             
  759.       if (TYPE_LENGTH (type) == 1)
  760.     {
  761.       fprintf_filtered (stream, " '");
  762.       printchar ((unsigned char) unpack_long (type, valaddr), 
  763.              stream, '\'');
  764.       fprintf_filtered (stream, "'");
  765.     }
  766.       break;
  767.  
  768.     case TYPE_CODE_FLT:
  769.       if (format)
  770.     {
  771.       print_scalar_formatted (valaddr, type, format, 0, stream);
  772.       break;
  773.     }
  774. #ifdef IEEE_FLOAT
  775.       if (is_nan ((char *) valaddr, TYPE_LENGTH (type)))
  776.     {
  777.       fprintf_filtered (stream, "NaN");
  778.       break;
  779.     }
  780. #endif
  781.       {
  782.     double doub;
  783.     int inv;
  784.  
  785.     doub = unpack_double (type, valaddr, &inv);
  786.     if (inv)
  787.       fprintf_filtered (stream, "Invalid float value");
  788.     else
  789.       fprintf_filtered (stream,
  790.                 TYPE_LENGTH (type) <= 4? "%.6g": "%.16g", doub);
  791.       }
  792.       break;
  793.  
  794.     case TYPE_CODE_VOID:
  795.       fprintf_filtered (stream, "void");
  796.       break;
  797.  
  798.     default:
  799.       error ("Invalid type code in symbol table.");
  800.     }
  801.   fflush (stream);
  802.   return 0;
  803. }
  804.  
  805. #ifdef IEEE_FLOAT
  806.  
  807. /* Nonzero if ARG (a double) is a NAN.  */
  808.  
  809. int
  810. is_nan (fp, len)
  811.      char *fp;
  812.      int len;
  813. {
  814.   int lowhalf, highhalf;
  815.   union ieee
  816.     {
  817.       long i[2];        /* ASSUMED 32 BITS */
  818.       float f;        /* ASSUMED 32 BITS */
  819.       double d;        /* ASSUMED 64 BITS */
  820.     } *arg;
  821.  
  822.   arg = (union ieee *)fp;
  823.  
  824.   /*
  825.    * Single precision float.
  826.    */
  827.   if (len == sizeof(long))
  828.     {
  829.       highhalf = arg->i[0];
  830.       return ((((highhalf >> 23) & 0xFF) == 0xFF) 
  831.           && 0 != (highhalf & 0x7FFFFF));
  832.     }
  833.   
  834.   /* Separate the high and low words of the double.
  835.      Distinguish big and little-endian machines.  */
  836. #ifdef WORDS_BIG_ENDIAN
  837.     lowhalf = arg->i[1], highhalf = arg->i[0];
  838. #else
  839.     lowhalf = arg->i[0], highhalf = arg->i[1];
  840. #endif
  841.   
  842.   /* Nan: exponent is the maximum possible, and fraction is nonzero.  */
  843.   return (((highhalf>>20) & 0x7ff) == 0x7ff
  844.       && ! ((highhalf & 0xfffff == 0) && (lowhalf == 0)));
  845. }
  846. #endif
  847.  
  848. /* Print a description of a type TYPE
  849.    in the form of a declaration of a variable named VARSTRING.
  850.    Output goes to STREAM (via stdio).
  851.    If SHOW is positive, we show the contents of the outermost level
  852.    of structure even if there is a type name that could be used instead.
  853.    If SHOW is negative, we never show the details of elements' types.  */
  854.  
  855. void
  856. type_print (type, varstring, stream, show)
  857.      struct type *type;
  858.      char *varstring;
  859.      FILE *stream;
  860.      int show;
  861. {
  862.   type_print_1 (type, varstring, stream, show, 0);
  863. }
  864.  
  865. /* LEVEL is the depth to indent lines by.  */
  866.  
  867. void
  868. type_print_1 (type, varstring, stream, show, level)
  869.      struct type *type;
  870.      char *varstring;
  871.      FILE *stream;
  872.      int show;
  873.      int level;
  874. {
  875.   register enum type_code code;
  876.   type_print_base (type, stream, show, level);
  877.   code = TYPE_CODE (type);
  878.   if ((varstring && *varstring)
  879.       ||
  880.       /* Need a space if going to print stars or brackets;
  881.      but not if we will print just a type name.  */
  882.       ((show > 0 || TYPE_NAME (type) == 0)
  883.        &&
  884.        (code == TYPE_CODE_PTR || code == TYPE_CODE_FUNC
  885.     || code == TYPE_CODE_METHOD
  886.     || code == TYPE_CODE_ARRAY
  887.     || code == TYPE_CODE_MEMBER
  888.     || code == TYPE_CODE_REF)))
  889.     fprintf_filtered (stream, " ");
  890.   type_print_varspec_prefix (type, stream, show, 0);
  891.   print_demangled (varstring, stream);
  892.   type_print_varspec_suffix (type, stream, show, 0);
  893. }
  894.  
  895. /* Print the method arguments ARGS to the file STREAM.  */
  896. static void
  897. type_print_method_args (args, prefix, varstring, staticp, stream)
  898.      struct type **args;
  899.      char *prefix, *varstring;
  900.      int staticp;
  901.      FILE *stream;
  902. {
  903.   int i;
  904.  
  905.   fputs_filtered (" ", stream);
  906.   fputs_filtered (prefix, stream);
  907.   fputs_filtered (varstring, stream);
  908.   fputs_filtered (" (", stream);
  909.   if (args && args[!staticp] && args[!staticp]->code != TYPE_CODE_VOID)
  910.     {
  911.       i = !staticp;        /* skip the class variable */
  912.       while (1)
  913.     {
  914.       type_print (args[i++], "", stream, 0);
  915.       if (!args[i]) 
  916.         {
  917.           fprintf_filtered (stream, " ...");
  918.           break;
  919.         }
  920.       else if (args[i]->code != TYPE_CODE_VOID)
  921.         {
  922.           fprintf_filtered (stream, ", ");
  923.         }
  924.       else break;
  925.     }
  926.     }
  927.   fprintf_filtered (stream, ")");
  928. }
  929.   
  930. /* If TYPE is a derived type, then print out derivation
  931.    information.  Print out all layers of the type heirarchy
  932.    until we encounter one with multiple inheritance.
  933.    At that point, print out that ply, and return.  */
  934. static void
  935. type_print_derivation_info (stream, type)
  936.      FILE *stream;
  937.      struct type *type;
  938. {
  939.   char *name;
  940.   int i, n_baseclasses = TYPE_N_BASECLASSES (type);
  941.   struct type *basetype = 0;
  942.  
  943.   while (type && n_baseclasses == 1)
  944.     {
  945.  
  946.       check_stub_type(type);    /* Not actually sure about this one -- Bryan. */
  947.  
  948.       basetype = TYPE_BASECLASS (type, 1);
  949.       if (name = type_name_no_tag (basetype))
  950.     {
  951.       fprintf_filtered (stream, ": %s%s ",
  952.            TYPE_VIA_PUBLIC (basetype) ? "public" : "private",
  953.            TYPE_VIA_VIRTUAL (basetype) ? " virtual" : "");
  954.       fputs_filtered (name, stream);
  955.       fputs_filtered (" ", stream);
  956.     }
  957.       n_baseclasses = TYPE_N_BASECLASSES (basetype);
  958.       type = basetype;
  959.     }
  960.  
  961.   if (type)
  962.     {
  963.       if (n_baseclasses != 0)
  964.     fprintf_filtered (stream, ": ");
  965.       for (i = 1; i <= n_baseclasses; i++)
  966.     {
  967.       basetype = TYPE_BASECLASS (type, i);
  968.       if (name = type_name_no_tag (basetype))
  969.         {
  970.           fprintf_filtered (stream, "%s%s ",
  971.                TYPE_VIA_PUBLIC (basetype) ? "public" : "private",
  972.                TYPE_VIA_VIRTUAL (basetype) ? " virtual" : "");
  973.           fputs_filtered (name, stream);
  974.         }
  975.       if (i < n_baseclasses)
  976.         fprintf_filtered (stream, ", ");
  977.     }
  978.       fprintf_filtered (stream, " ");
  979.     }
  980. }
  981.  
  982. /* Print any asterisks or open-parentheses needed before the
  983.    variable name (to describe its type).
  984.  
  985.    On outermost call, pass 0 for PASSED_A_PTR.
  986.    On outermost call, SHOW > 0 means should ignore
  987.    any typename for TYPE and show its details.
  988.    SHOW is always zero on recursive calls.  */
  989.  
  990. static void
  991. type_print_varspec_prefix (type, stream, show, passed_a_ptr)
  992.      struct type *type;
  993.      FILE *stream;
  994.      int show;
  995.      int passed_a_ptr;
  996. {
  997.   if (type == 0)
  998.     return;
  999.  
  1000.   if (TYPE_NAME (type) && show <= 0)
  1001.     return;
  1002.  
  1003.   QUIT;
  1004.  
  1005.   switch (TYPE_CODE (type))
  1006.     {
  1007.     case TYPE_CODE_PTR:
  1008.       type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 1);
  1009.       fprintf_filtered (stream, "*");
  1010.       break;
  1011.  
  1012.     case TYPE_CODE_MEMBER:
  1013.       if (passed_a_ptr)
  1014.     fprintf_filtered (stream, "(");
  1015.       type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0,
  1016.                  0);
  1017.       fprintf_filtered (stream, " ");
  1018.       type_print_base (TYPE_DOMAIN_TYPE (type), stream, 0,
  1019.                passed_a_ptr);
  1020.       fprintf_filtered (stream, "::");
  1021.       break;
  1022.  
  1023.     case TYPE_CODE_METHOD:
  1024.       if (passed_a_ptr)
  1025.     fprintf (stream, "(");
  1026.       type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0,
  1027.                  0);
  1028.       fprintf_filtered (stream, " ");
  1029. #if 0
  1030.       type_print_base (TYPE_DOMAIN_TYPE (type), stream, 0,
  1031.                passed_a_ptr);
  1032.       fprintf_filtered (stream, "::");
  1033. #endif
  1034.       break;
  1035.  
  1036.     case TYPE_CODE_REF:
  1037.       type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 1);
  1038.       fprintf_filtered (stream, "&");
  1039.       break;
  1040.  
  1041.     case TYPE_CODE_FUNC:
  1042.       type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0,
  1043.                  0);
  1044.       if (passed_a_ptr)
  1045.     fprintf_filtered (stream, "(");
  1046.       break;
  1047.  
  1048.     case TYPE_CODE_ARRAY:
  1049.       type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0,
  1050.                  0);
  1051.       if (passed_a_ptr)
  1052.     fprintf_filtered (stream, "(");
  1053.     }
  1054. }
  1055.  
  1056. /* Print any array sizes, function arguments or close parentheses
  1057.    needed after the variable name (to describe its type).
  1058.    Args work like type_print_varspec_prefix.  */
  1059.  
  1060. static void
  1061. type_print_varspec_suffix (type, stream, show, passed_a_ptr)
  1062.      struct type *type;
  1063.      FILE *stream;
  1064.      int show;
  1065.      int passed_a_ptr;
  1066. {
  1067.   if (type == 0)
  1068.     return;
  1069.  
  1070.   if (TYPE_NAME (type) && show <= 0)
  1071.     return;
  1072.  
  1073.   QUIT;
  1074.  
  1075.   switch (TYPE_CODE (type))
  1076.     {
  1077.     case TYPE_CODE_ARRAY:
  1078.       if (passed_a_ptr)
  1079.     fprintf_filtered (stream, ")");
  1080.       
  1081.       fprintf_filtered (stream, "[");
  1082.       if (TYPE_LENGTH (type) >= 0
  1083.       && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0)
  1084.     fprintf_filtered (stream, "%d",
  1085.               (TYPE_LENGTH (type)
  1086.                / TYPE_LENGTH (TYPE_TARGET_TYPE (type))));
  1087.       fprintf_filtered (stream, "]");
  1088.       
  1089.       type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0,
  1090.                  0);
  1091.       break;
  1092.  
  1093.     case TYPE_CODE_MEMBER:
  1094.       if (passed_a_ptr)
  1095.     fprintf_filtered (stream, ")");
  1096.       type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0);
  1097.       break;
  1098.  
  1099.     case TYPE_CODE_METHOD:
  1100.       if (passed_a_ptr)
  1101.     fprintf_filtered (stream, ")");
  1102.       type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0);
  1103.       if (passed_a_ptr)
  1104.     {
  1105.       int i;
  1106.       struct type **args = TYPE_ARG_TYPES (type);
  1107.  
  1108.       fprintf_filtered (stream, "(");
  1109.       if (args[1] == 0)
  1110.         fprintf_filtered (stream, "...");
  1111.       else for (i = 1; args[i] != 0 && args[i]->code != TYPE_CODE_VOID; i++)
  1112.         {
  1113.           type_print_1 (args[i], "", stream, -1, 0);
  1114.           if (args[i+1] == 0)
  1115.         fprintf_filtered (stream, "...");
  1116.           else if (args[i+1]->code != TYPE_CODE_VOID)
  1117.         fprintf_filtered (stream, ",");
  1118.         }
  1119.       fprintf_filtered (stream, ")");
  1120.     }
  1121.       break;
  1122.  
  1123.     case TYPE_CODE_PTR:
  1124.     case TYPE_CODE_REF:
  1125.       type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 1);
  1126.       break;
  1127.  
  1128.     case TYPE_CODE_FUNC:
  1129.       type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0,
  1130.                  passed_a_ptr);
  1131.       if (passed_a_ptr)
  1132.     fprintf_filtered (stream, ")");
  1133.       fprintf_filtered (stream, "()");
  1134.       break;
  1135.     }
  1136. }
  1137.  
  1138. /* Print the name of the type (or the ultimate pointer target,
  1139.    function value or array element), or the description of a
  1140.    structure or union.
  1141.  
  1142.    SHOW nonzero means don't print this type as just its name;
  1143.    show its real definition even if it has a name.
  1144.    SHOW zero means print just typename or struct tag if there is one
  1145.    SHOW negative means abbreviate structure elements.
  1146.    SHOW is decremented for printing of structure elements.
  1147.  
  1148.    LEVEL is the depth to indent by.
  1149.    We increase it for some recursive calls.  */
  1150.  
  1151. static void
  1152. type_print_base (type, stream, show, level)
  1153.      struct type *type;
  1154.      FILE *stream;
  1155.      int show;
  1156.      int level;
  1157. {
  1158.   char *name;
  1159.   register int i;
  1160.   register int len;
  1161.   register int lastval;
  1162.  
  1163.   QUIT;
  1164.  
  1165.   if (type == 0)
  1166.     {
  1167.       fprintf_filtered (stream, "type unknown");
  1168.       return;
  1169.     }
  1170.  
  1171.   if (TYPE_NAME (type) && show <= 0)
  1172.     {
  1173.       fputs_filtered (TYPE_NAME (type), stream);
  1174.       return;
  1175.     }
  1176.  
  1177.   switch (TYPE_CODE (type))
  1178.     {
  1179.     case TYPE_CODE_ARRAY:
  1180.     case TYPE_CODE_PTR:
  1181.     case TYPE_CODE_MEMBER:
  1182.     case TYPE_CODE_REF:
  1183.     case TYPE_CODE_FUNC:
  1184.     case TYPE_CODE_METHOD:
  1185.       type_print_base (TYPE_TARGET_TYPE (type), stream, show, level);
  1186.       break;
  1187.  
  1188.     case TYPE_CODE_STRUCT:
  1189.       fprintf_filtered (stream, "struct ");
  1190.       goto struct_union;
  1191.  
  1192.     case TYPE_CODE_UNION:
  1193.       fprintf_filtered (stream, "union ");
  1194.     struct_union:
  1195.       if (name = type_name_no_tag (type))
  1196.     {
  1197.       fputs_filtered (name, stream);
  1198.       fputs_filtered (" ", stream);
  1199.     }
  1200.       if (show < 0)
  1201.     fprintf_filtered (stream, "{...}");
  1202.       else
  1203.     {
  1204.       int i;
  1205.  
  1206.       check_stub_type (type);
  1207.  
  1208.       type_print_derivation_info (stream, type);
  1209.       
  1210.       fprintf_filtered (stream, "{");
  1211.       len = TYPE_NFIELDS (type);
  1212.       if (len)
  1213.         fprintf_filtered (stream, "\n");
  1214.       else
  1215.         {
  1216.           if (TYPE_FLAGS (type) & TYPE_FLAG_STUB)
  1217.         fprintf_filtered (stream, "<incomplete type>\n");
  1218.           else
  1219.         fprintf_filtered (stream, "<no data fields>\n");
  1220.         }
  1221.  
  1222.       /* If there is a base class for this type,
  1223.          do not print the field that it occupies.  */
  1224.       for (i = TYPE_N_BASECLASSES (type); i < len; i++)
  1225.         {
  1226.           QUIT;
  1227.           /* Don't print out virtual function table.  */
  1228.           if (! strncmp (TYPE_FIELD_NAME (type, i),
  1229.                "_vptr$", 6))
  1230.         continue;
  1231.  
  1232.           print_spaces_filtered (level + 4, stream);
  1233.           if (TYPE_FIELD_STATIC (type, i))
  1234.         {
  1235.           fprintf_filtered (stream, "static ");
  1236.         }
  1237.           type_print_1 (TYPE_FIELD_TYPE (type, i),
  1238.                 TYPE_FIELD_NAME (type, i),
  1239.                 stream, show - 1, level + 4);
  1240.           if (!TYPE_FIELD_STATIC (type, i)
  1241.           && TYPE_FIELD_PACKED (type, i))
  1242.         {
  1243.           /* It is a bitfield.  This code does not attempt
  1244.              to look at the bitpos and reconstruct filler,
  1245.              unnamed fields.  This would lead to misleading
  1246.              results if the compiler does not put out fields
  1247.              for such things (I don't know what it does).  */
  1248.           fprintf_filtered (stream, " : %d",
  1249.                     TYPE_FIELD_BITSIZE (type, i));
  1250.         }
  1251.           fprintf_filtered (stream, ";\n");
  1252.         }
  1253.  
  1254.       /* C++: print out the methods */
  1255.       len = TYPE_NFN_FIELDS (type);
  1256.       for (i = 0; i < len; i++)
  1257.         {
  1258.           struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i);
  1259.           int j, len2 = TYPE_FN_FIELDLIST_LENGTH (type, i);
  1260.  
  1261.           for (j = 0; j < len2; j++)
  1262.         {
  1263.           QUIT;
  1264.           print_spaces_filtered (level + 4, stream);
  1265.           if (TYPE_FN_FIELD_VIRTUAL_P (f, j))
  1266.             fprintf_filtered (stream, "virtual ");
  1267.           else if (TYPE_FN_FIELD_STATIC_P (f, j))
  1268.             fprintf_filtered (stream, "static ");
  1269.           type_print_1 (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)),
  1270.                 "", stream, show - 1, level + 4);
  1271.           if (TYPE_FN_FIELD_PHYSNAME (f, j)[0] == '_'
  1272.               && TYPE_FN_FIELD_PHYSNAME (f, j)[1] == '$')
  1273.             type_print_method_args
  1274.               (TYPE_FN_FIELD_ARGS (f, j) + 1, "~",
  1275.                TYPE_FN_FIELDLIST_NAME (type, i), 0, stream);
  1276.           else if (TYPE_FLAGS (TYPE_FN_FIELD_TYPE (f, j)) & TYPE_FLAG_STUB)
  1277.             {
  1278.               /* Build something we can demangle.  */
  1279.               char *strchr (), *gdb_mangle_typename ();
  1280.               char *inner_name = gdb_mangle_typename (type);
  1281.               char *mangled_name
  1282.             = (char *)malloc (strlen (TYPE_FN_FIELDLIST_NAME (type, i))
  1283.                       + strlen (inner_name)
  1284.                       + strlen (TYPE_FN_FIELD_PHYSNAME (f, j))
  1285.                       + 1);
  1286.               char *demangled_name, *cplus_demangle ();
  1287.               if (!strcmp (type_name_no_tag (type),
  1288.                    TYPE_FN_FIELDLIST_NAME (type, i)))
  1289.             /* Constructor */
  1290.             strcpy (mangled_name, inner_name);
  1291.               else
  1292.             {
  1293.               strcpy (mangled_name,
  1294.                   TYPE_FN_FIELDLIST_NAME (type, i));
  1295.               strcat (mangled_name, inner_name);
  1296.             }
  1297.               strcat (mangled_name, TYPE_FN_FIELD_PHYSNAME (f, j));
  1298.               demangled_name = cplus_demangle (mangled_name, 1);
  1299.               fprintf_filtered (stream, " %s", strchr (demangled_name, ':') + 2);
  1300.               free (demangled_name);
  1301.               free (mangled_name);
  1302.             }
  1303.           else
  1304.             type_print_method_args
  1305.               (TYPE_FN_FIELD_ARGS (f, j), "",
  1306.                TYPE_FN_FIELDLIST_NAME (type, i),
  1307.                TYPE_FN_FIELD_STATIC_P (f, j), stream);
  1308.  
  1309.           fprintf_filtered (stream, ";\n");
  1310.         }
  1311.         }
  1312.  
  1313.       print_spaces_filtered (level, stream);
  1314.       fprintf_filtered (stream, "}");
  1315.     }
  1316.       break;
  1317.  
  1318.     case TYPE_CODE_ENUM:
  1319.       fprintf_filtered (stream, "enum ");
  1320.       if (name = type_name_no_tag (type))
  1321.     {
  1322.       fputs_filtered (name, stream);
  1323.       fputs_filtered (" ", stream);
  1324.     }
  1325.       if (show < 0)
  1326.     fprintf_filtered (stream, "{...}");
  1327.       else
  1328.     {
  1329.       fprintf_filtered (stream, "{");
  1330.       len = TYPE_NFIELDS (type);
  1331.       lastval = 0;
  1332.       for (i = 0; i < len; i++)
  1333.         {
  1334.           QUIT;
  1335.           if (i) fprintf_filtered (stream, ", ");
  1336.           fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
  1337.           if (lastval != TYPE_FIELD_BITPOS (type, i))
  1338.         {
  1339.           fprintf_filtered (stream, " : %d", TYPE_FIELD_BITPOS (type, i));
  1340.           lastval = TYPE_FIELD_BITPOS (type, i);
  1341.         }
  1342.           lastval++;
  1343.         }
  1344.       fprintf_filtered (stream, "}");
  1345.     }
  1346.       break;
  1347.  
  1348.     case TYPE_CODE_INT:
  1349.       if (TYPE_UNSIGNED (type))
  1350.     name = unsigned_type_table[TYPE_LENGTH (type)];
  1351.       else
  1352.     name = signed_type_table[TYPE_LENGTH (type)];
  1353.       fputs_filtered (name, stream);
  1354.       break;
  1355.  
  1356.     case TYPE_CODE_FLT:
  1357.       name = float_type_table[TYPE_LENGTH (type)];
  1358.       fputs_filtered (name, stream);
  1359.       break;
  1360.  
  1361.     case TYPE_CODE_VOID:
  1362.       fprintf_filtered (stream, "void");
  1363.       break;
  1364.  
  1365.     case 0:
  1366.       fprintf_filtered (stream, "struct unknown");
  1367.       break;
  1368.  
  1369.     default:
  1370.       error ("Invalid type code in symbol table.");
  1371.     }
  1372. }
  1373.  
  1374. static void
  1375. set_maximum_command (arg)
  1376.      char *arg;
  1377. {
  1378.   if (!arg) error_no_arg ("value for maximum elements to print");
  1379.   print_max = parse_and_eval_address (arg);
  1380.   if (print_max == 0)
  1381.     print_max = UINT_MAX;
  1382. }
  1383.  
  1384. static void
  1385. set_prettyprint_command (arg, from_tty)
  1386.      char *arg;
  1387.      int from_tty;
  1388. {
  1389.   prettyprint = parse_binary_operation ("set prettyprint", arg);
  1390. }
  1391.  
  1392. static void
  1393. set_unionprint_command (arg, from_tty)
  1394.      char *arg;
  1395.      int from_tty;
  1396. {
  1397.   unionprint = parse_binary_operation ("set unionprint", arg);
  1398. }
  1399.  
  1400. static void
  1401. set_vtblprint_command (arg, from_tty)
  1402.      char *arg;
  1403.      int from_tty;
  1404. {
  1405.   vtblprint = parse_binary_operation ("set vtblprint", arg);
  1406. }
  1407.  
  1408. format_info (arg, from_tty)
  1409.      char *arg;
  1410.      int from_tty;
  1411. {
  1412.   if (arg)
  1413.     error ("\"info format\" does not take any arguments.");
  1414.   printf ("Prettyprinting of structures is %s.\n",
  1415.       prettyprint ? "on" : "off");
  1416.   printf ("Printing of unions interior to structures is %s.\n",
  1417.       unionprint ? "on" : "off");
  1418.   printf ("Printing of vtbl interior to structures is %s.\n",
  1419.       vtblprint ? "on" : "off");
  1420.   if (print_max == UINT_MAX)
  1421.     printf_filtered
  1422.       ("There is no maximum number of array elements printed.\n");
  1423.   else
  1424.     printf_filtered
  1425.       ("The maximum number of array elements printed is %d.\n", print_max);
  1426. }
  1427.  
  1428. extern struct cmd_list_element *setlist;
  1429.  
  1430. void
  1431. _initialize_valprint ()
  1432. {
  1433.   add_cmd ("array-max", class_vars, set_maximum_command,
  1434.        "Set NUMBER as limit on string chars or array elements to print.\n\
  1435. \"set array-max 0\" causes there to be no limit.",
  1436.        &setlist);
  1437.  
  1438.   add_cmd ("prettyprint", class_support, set_prettyprint_command,
  1439.        "Turn prettyprinting of structures on and off.",
  1440.        &setlist);
  1441.   add_alias_cmd ("pp", "prettyprint", class_support, 1, &setlist);
  1442.  
  1443.   add_cmd ("unionprint", class_support, set_unionprint_command,
  1444.        "Turn printing of unions interior to structures on and off.",
  1445.        &setlist);
  1446.  
  1447.   add_cmd ("vtblprint", class_support, set_vtblprint_command,
  1448.        "Turn printing of vtbl interior to structures on and off.",
  1449.        &setlist);
  1450.  
  1451.   add_info ("format", format_info,
  1452.         "Show current settings of data formatting options.");
  1453.  
  1454.   /* Give people the defaults which they are used to.  */
  1455.   prettyprint = 0;
  1456.   unionprint = 1;
  1457.   vtblprint = 0;
  1458.  
  1459.   print_max = 200;
  1460.  
  1461.   unsigned_type_table
  1462.     = (char **) xmalloc ((1 + sizeof (unsigned LONGEST)) * sizeof (char *));
  1463.   bzero (unsigned_type_table, (1 + sizeof (unsigned LONGEST)));
  1464.   unsigned_type_table[sizeof (unsigned char)] = "unsigned char";
  1465.   unsigned_type_table[sizeof (unsigned short)] = "unsigned short";
  1466.   unsigned_type_table[sizeof (unsigned long)] = "unsigned long";
  1467.   unsigned_type_table[sizeof (unsigned int)] = "unsigned int";
  1468. #ifdef LONG_LONG
  1469.   unsigned_type_table[sizeof (unsigned long long)] = "unsigned long long";
  1470. #endif
  1471.  
  1472.   signed_type_table
  1473.     = (char **) xmalloc ((1 + sizeof (LONGEST)) * sizeof (char *));
  1474.   bzero (signed_type_table, (1 + sizeof (LONGEST)));
  1475.   signed_type_table[sizeof (char)] = "char";
  1476.   signed_type_table[sizeof (short)] = "short";
  1477.   signed_type_table[sizeof (long)] = "long";
  1478.   signed_type_table[sizeof (int)] = "int";
  1479. #ifdef LONG_LONG
  1480.   signed_type_table[sizeof (long long)] = "long long";
  1481. #endif
  1482.  
  1483.   float_type_table
  1484. #ifdef LONG_DOUBLE
  1485.     = (char **) xmalloc ((1 + sizeof (long double)) * sizeof (char *));
  1486.   bzero (float_type_table, (1 + sizeof (long double)));
  1487. #else
  1488.     = (char **) xmalloc ((1 + sizeof (double)) * sizeof (char *));
  1489.   bzero (float_type_table, (1 + sizeof (double)));
  1490. #endif
  1491.   float_type_table[sizeof (float)] = "float";
  1492.   float_type_table[sizeof (double)] = "double";
  1493. #ifdef LONG_DOUBLE
  1494.   float_type_table[sizeof (long double)] = "long double";
  1495. #endif
  1496. }
  1497.  
  1498.