gdb/p-valprint.c - gdb

Global variables defined

Functions defined

Source code

  1. /* Support for printing Pascal values for GDB, the GNU debugger.

  2.    Copyright (C) 2000-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. /* This file is derived from c-valprint.c */

  15. #include "defs.h"
  16. #include "gdb_obstack.h"
  17. #include "symtab.h"
  18. #include "gdbtypes.h"
  19. #include "expression.h"
  20. #include "value.h"
  21. #include "command.h"
  22. #include "gdbcmd.h"
  23. #include "gdbcore.h"
  24. #include "demangle.h"
  25. #include "valprint.h"
  26. #include "typeprint.h"
  27. #include "language.h"
  28. #include "target.h"
  29. #include "annotate.h"
  30. #include "p-lang.h"
  31. #include "cp-abi.h"
  32. #include "cp-support.h"
  33. #include "objfiles.h"


  34. /* Decorations for Pascal.  */

  35. static const struct generic_val_print_decorations p_decorations =
  36. {
  37.   "",
  38.   " + ",
  39.   " * I",
  40.   "true",
  41.   "false",
  42.   "void"
  43. };

  44. /* See val_print for a description of the various parameters of this
  45.    function; they are identical.  */

  46. void
  47. pascal_val_print (struct type *type, const gdb_byte *valaddr,
  48.                   int embedded_offset, CORE_ADDR address,
  49.                   struct ui_file *stream, int recurse,
  50.                   const struct value *original_value,
  51.                   const struct value_print_options *options)
  52. {
  53.   struct gdbarch *gdbarch = get_type_arch (type);
  54.   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  55.   unsigned int i = 0;        /* Number of characters printed */
  56.   unsigned len;
  57.   LONGEST low_bound, high_bound;
  58.   struct type *elttype;
  59.   unsigned eltlen;
  60.   int length_pos, length_size, string_pos;
  61.   struct type *char_type;
  62.   CORE_ADDR addr;
  63.   int want_space = 0;

  64.   CHECK_TYPEDEF (type);
  65.   switch (TYPE_CODE (type))
  66.     {
  67.     case TYPE_CODE_ARRAY:
  68.       if (get_array_bounds (type, &low_bound, &high_bound))
  69.         {
  70.           len = high_bound - low_bound + 1;
  71.           elttype = check_typedef (TYPE_TARGET_TYPE (type));
  72.           eltlen = TYPE_LENGTH (elttype);
  73.           if (options->prettyformat_arrays)
  74.             {
  75.               print_spaces_filtered (2 + 2 * recurse, stream);
  76.             }
  77.           /* If 's' format is used, try to print out as string.
  78.              If no format is given, print as string if element type
  79.              is of TYPE_CODE_CHAR and element size is 1,2 or 4.  */
  80.           if (options->format == 's'
  81.               || ((eltlen == 1 || eltlen == 2 || eltlen == 4)
  82.                   && TYPE_CODE (elttype) == TYPE_CODE_CHAR
  83.                   && options->format == 0))
  84.             {
  85.               /* If requested, look for the first null char and only print
  86.                  elements up to it.  */
  87.               if (options->stop_print_at_null)
  88.                 {
  89.                   unsigned int temp_len;

  90.                   /* Look for a NULL char.  */
  91.                   for (temp_len = 0;
  92.                        extract_unsigned_integer (valaddr + embedded_offset +
  93.                                                  temp_len * eltlen, eltlen,
  94.                                                  byte_order)
  95.                        && temp_len < len && temp_len < options->print_max;
  96.                        temp_len++);
  97.                   len = temp_len;
  98.                 }

  99.               LA_PRINT_STRING (stream, TYPE_TARGET_TYPE (type),
  100.                                valaddr + embedded_offset, len, NULL, 0,
  101.                                options);
  102.               i = len;
  103.             }
  104.           else
  105.             {
  106.               fprintf_filtered (stream, "{");
  107.               /* If this is a virtual function table, print the 0th
  108.                  entry specially, and the rest of the members normally.  */
  109.               if (pascal_object_is_vtbl_ptr_type (elttype))
  110.                 {
  111.                   i = 1;
  112.                   fprintf_filtered (stream, "%d vtable entries", len - 1);
  113.                 }
  114.               else
  115.                 {
  116.                   i = 0;
  117.                 }
  118.               val_print_array_elements (type, valaddr, embedded_offset,
  119.                                         address, stream, recurse,
  120.                                         original_value, options, i);
  121.               fprintf_filtered (stream, "}");
  122.             }
  123.           break;
  124.         }
  125.       /* Array of unspecified length: treat like pointer to first elt.  */
  126.       addr = address + embedded_offset;
  127.       goto print_unpacked_pointer;

  128.     case TYPE_CODE_PTR:
  129.       if (options->format && options->format != 's')
  130.         {
  131.           val_print_scalar_formatted (type, valaddr, embedded_offset,
  132.                                       original_value, options, 0, stream);
  133.           break;
  134.         }
  135.       if (options->vtblprint && pascal_object_is_vtbl_ptr_type (type))
  136.         {
  137.           /* Print the unmangled name if desired.  */
  138.           /* Print vtable entry - we only get here if we ARE using
  139.              -fvtable_thunks.  (Otherwise, look under TYPE_CODE_STRUCT.)  */
  140.           /* Extract the address, assume that it is unsigned.  */
  141.           addr = extract_unsigned_integer (valaddr + embedded_offset,
  142.                                            TYPE_LENGTH (type), byte_order);
  143.           print_address_demangle (options, gdbarch, addr, stream, demangle);
  144.           break;
  145.         }
  146.       check_typedef (TYPE_TARGET_TYPE (type));

  147.       addr = unpack_pointer (type, valaddr + embedded_offset);
  148.     print_unpacked_pointer:
  149.       elttype = check_typedef (TYPE_TARGET_TYPE (type));

  150.       if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
  151.         {
  152.           /* Try to print what function it points to.  */
  153.           print_address_demangle (options, gdbarch, addr, stream, demangle);
  154.           return;
  155.         }

  156.       if (options->addressprint && options->format != 's')
  157.         {
  158.           fputs_filtered (paddress (gdbarch, addr), stream);
  159.           want_space = 1;
  160.         }

  161.       /* For a pointer to char or unsigned char, also print the string
  162.          pointed to, unless pointer is null.  */
  163.       if (((TYPE_LENGTH (elttype) == 1
  164.            && (TYPE_CODE (elttype) == TYPE_CODE_INT
  165.               || TYPE_CODE (elttype) == TYPE_CODE_CHAR))
  166.           || ((TYPE_LENGTH (elttype) == 2 || TYPE_LENGTH (elttype) == 4)
  167.               && TYPE_CODE (elttype) == TYPE_CODE_CHAR))
  168.           && (options->format == 0 || options->format == 's')
  169.           && addr != 0)
  170.         {
  171.           if (want_space)
  172.             fputs_filtered (" ", stream);
  173.           /* No wide string yet.  */
  174.           i = val_print_string (elttype, NULL, addr, -1, stream, options);
  175.         }
  176.       /* Also for pointers to pascal strings.  */
  177.       /* Note: this is Free Pascal specific:
  178.          as GDB does not recognize stabs pascal strings
  179.          Pascal strings are mapped to records
  180.          with lowercase names PM.  */
  181.       if (is_pascal_string_type (elttype, &length_pos, &length_size,
  182.                                  &string_pos, &char_type, NULL)
  183.           && addr != 0)
  184.         {
  185.           ULONGEST string_length;
  186.           void *buffer;

  187.           if (want_space)
  188.             fputs_filtered (" ", stream);
  189.           buffer = xmalloc (length_size);
  190.           read_memory (addr + length_pos, buffer, length_size);
  191.           string_length = extract_unsigned_integer (buffer, length_size,
  192.                                                     byte_order);
  193.           xfree (buffer);
  194.           i = val_print_string (char_type, NULL,
  195.                                 addr + string_pos, string_length,
  196.                                 stream, options);
  197.         }
  198.       else if (pascal_object_is_vtbl_member (type))
  199.         {
  200.           /* Print vtbl's nicely.  */
  201.           CORE_ADDR vt_address = unpack_pointer (type,
  202.                                                  valaddr + embedded_offset);
  203.           struct bound_minimal_symbol msymbol =
  204.             lookup_minimal_symbol_by_pc (vt_address);

  205.           /* If 'symbol_print' is set, we did the work above.  */
  206.           if (!options->symbol_print
  207.               && (msymbol.minsym != NULL)
  208.               && (vt_address == BMSYMBOL_VALUE_ADDRESS (msymbol)))
  209.             {
  210.               if (want_space)
  211.                 fputs_filtered (" ", stream);
  212.               fputs_filtered ("<", stream);
  213.               fputs_filtered (MSYMBOL_PRINT_NAME (msymbol.minsym), stream);
  214.               fputs_filtered (">", stream);
  215.               want_space = 1;
  216.             }
  217.           if (vt_address && options->vtblprint)
  218.             {
  219.               struct value *vt_val;
  220.               struct symbol *wsym = (struct symbol *) NULL;
  221.               struct type *wtype;
  222.               struct block *block = (struct block *) NULL;
  223.               struct field_of_this_result is_this_fld;

  224.               if (want_space)
  225.                 fputs_filtered (" ", stream);

  226.               if (msymbol.minsym != NULL)
  227.                 wsym = lookup_symbol (MSYMBOL_LINKAGE_NAME (msymbol.minsym),
  228.                                       block,
  229.                                       VAR_DOMAIN, &is_this_fld);

  230.               if (wsym)
  231.                 {
  232.                   wtype = SYMBOL_TYPE (wsym);
  233.                 }
  234.               else
  235.                 {
  236.                   wtype = TYPE_TARGET_TYPE (type);
  237.                 }
  238.               vt_val = value_at (wtype, vt_address);
  239.               common_val_print (vt_val, stream, recurse + 1, options,
  240.                                 current_language);
  241.               if (options->prettyformat)
  242.                 {
  243.                   fprintf_filtered (stream, "\n");
  244.                   print_spaces_filtered (2 + 2 * recurse, stream);
  245.                 }
  246.             }
  247.         }

  248.       return;

  249.     case TYPE_CODE_REF:
  250.     case TYPE_CODE_ENUM:
  251.     case TYPE_CODE_FLAGS:
  252.     case TYPE_CODE_FUNC:
  253.     case TYPE_CODE_RANGE:
  254.     case TYPE_CODE_INT:
  255.     case TYPE_CODE_FLT:
  256.     case TYPE_CODE_VOID:
  257.     case TYPE_CODE_ERROR:
  258.     case TYPE_CODE_UNDEF:
  259.     case TYPE_CODE_BOOL:
  260.     case TYPE_CODE_CHAR:
  261.       generic_val_print (type, valaddr, embedded_offset, address,
  262.                          stream, recurse, original_value, options,
  263.                          &p_decorations);
  264.       break;

  265.     case TYPE_CODE_UNION:
  266.       if (recurse && !options->unionprint)
  267.         {
  268.           fprintf_filtered (stream, "{...}");
  269.           break;
  270.         }
  271.       /* Fall through.  */
  272.     case TYPE_CODE_STRUCT:
  273.       if (options->vtblprint && pascal_object_is_vtbl_ptr_type (type))
  274.         {
  275.           /* Print the unmangled name if desired.  */
  276.           /* Print vtable entry - we only get here if NOT using
  277.              -fvtable_thunks.  (Otherwise, look under TYPE_CODE_PTR.)  */
  278.           /* Extract the address, assume that it is unsigned.  */
  279.           print_address_demangle
  280.             (options, gdbarch,
  281.              extract_unsigned_integer (valaddr + embedded_offset
  282.                                        + TYPE_FIELD_BITPOS (type,
  283.                                                             VTBL_FNADDR_OFFSET) / 8,
  284.                                        TYPE_LENGTH (TYPE_FIELD_TYPE (type,
  285.                                                                      VTBL_FNADDR_OFFSET)),
  286.                                        byte_order),
  287.              stream, demangle);
  288.         }
  289.       else
  290.         {
  291.           if (is_pascal_string_type (type, &length_pos, &length_size,
  292.                                      &string_pos, &char_type, NULL))
  293.             {
  294.               len = extract_unsigned_integer (valaddr + embedded_offset
  295.                                               + length_pos, length_size,
  296.                                               byte_order);
  297.               LA_PRINT_STRING (stream, char_type,
  298.                                valaddr + embedded_offset + string_pos,
  299.                                len, NULL, 0, options);
  300.             }
  301.           else
  302.             pascal_object_print_value_fields (type, valaddr, embedded_offset,
  303.                                               address, stream, recurse,
  304.                                               original_value, options,
  305.                                               NULL, 0);
  306.         }
  307.       break;

  308.     case TYPE_CODE_SET:
  309.       elttype = TYPE_INDEX_TYPE (type);
  310.       CHECK_TYPEDEF (elttype);
  311.       if (TYPE_STUB (elttype))
  312.         {
  313.           fprintf_filtered (stream, "<incomplete type>");
  314.           gdb_flush (stream);
  315.           break;
  316.         }
  317.       else
  318.         {
  319.           struct type *range = elttype;
  320.           LONGEST low_bound, high_bound;
  321.           int i;
  322.           int need_comma = 0;

  323.           fputs_filtered ("[", stream);

  324.           i = get_discrete_bounds (range, &low_bound, &high_bound);
  325.           if (low_bound == 0 && high_bound == -1 && TYPE_LENGTH (type) > 0)
  326.             {
  327.               /* If we know the size of the set type, we can figure out the
  328.               maximum value.  */
  329.               i = 0;
  330.               high_bound = TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1;
  331.               TYPE_HIGH_BOUND (range) = high_bound;
  332.             }
  333.         maybe_bad_bstring:
  334.           if (i < 0)
  335.             {
  336.               fputs_filtered ("<error value>", stream);
  337.               goto done;
  338.             }

  339.           for (i = low_bound; i <= high_bound; i++)
  340.             {
  341.               int element = value_bit_index (type,
  342.                                              valaddr + embedded_offset, i);

  343.               if (element < 0)
  344.                 {
  345.                   i = element;
  346.                   goto maybe_bad_bstring;
  347.                 }
  348.               if (element)
  349.                 {
  350.                   if (need_comma)
  351.                     fputs_filtered (", ", stream);
  352.                   print_type_scalar (range, i, stream);
  353.                   need_comma = 1;

  354.                   if (i + 1 <= high_bound
  355.                       && value_bit_index (type,
  356.                                           valaddr + embedded_offset, ++i))
  357.                     {
  358.                       int j = i;

  359.                       fputs_filtered ("..", stream);
  360.                       while (i + 1 <= high_bound
  361.                              && value_bit_index (type,
  362.                                                  valaddr + embedded_offset,
  363.                                                  ++i))
  364.                         j = i;
  365.                       print_type_scalar (range, j, stream);
  366.                     }
  367.                 }
  368.             }
  369.         done:
  370.           fputs_filtered ("]", stream);
  371.         }
  372.       break;

  373.     default:
  374.       error (_("Invalid pascal type code %d in symbol table."),
  375.              TYPE_CODE (type));
  376.     }
  377.   gdb_flush (stream);
  378. }

  379. void
  380. pascal_value_print (struct value *val, struct ui_file *stream,
  381.                     const struct value_print_options *options)
  382. {
  383.   struct type *type = value_type (val);
  384.   struct value_print_options opts = *options;

  385.   opts.deref_ref = 1;

  386.   /* If it is a pointer, indicate what it points to.

  387.      Print type also if it is a reference.

  388.      Object pascal: if it is a member pointer, we will take care
  389.      of that when we print it.  */
  390.   if (TYPE_CODE (type) == TYPE_CODE_PTR
  391.       || TYPE_CODE (type) == TYPE_CODE_REF)
  392.     {
  393.       /* Hack:  remove (char *) for char strings.  Their
  394.          type is indicated by the quoted string anyway.  */
  395.       if (TYPE_CODE (type) == TYPE_CODE_PTR
  396.           && TYPE_NAME (type) == NULL
  397.           && TYPE_NAME (TYPE_TARGET_TYPE (type)) != NULL
  398.           && strcmp (TYPE_NAME (TYPE_TARGET_TYPE (type)), "char") == 0)
  399.         {
  400.           /* Print nothing.  */
  401.         }
  402.       else
  403.         {
  404.           fprintf_filtered (stream, "(");
  405.           type_print (type, "", stream, -1);
  406.           fprintf_filtered (stream, ") ");
  407.         }
  408.     }
  409.   common_val_print (val, stream, 0, &opts, current_language);
  410. }


  411. static void
  412. show_pascal_static_field_print (struct ui_file *file, int from_tty,
  413.                                 struct cmd_list_element *c, const char *value)
  414. {
  415.   fprintf_filtered (file, _("Printing of pascal static members is %s.\n"),
  416.                     value);
  417. }

  418. static struct obstack dont_print_vb_obstack;
  419. static struct obstack dont_print_statmem_obstack;

  420. static void pascal_object_print_static_field (struct value *,
  421.                                               struct ui_file *, int,
  422.                                               const struct value_print_options *);

  423. static void pascal_object_print_value (struct type *, const gdb_byte *,
  424.                                        int,
  425.                                        CORE_ADDR, struct ui_file *, int,
  426.                                        const struct value *,
  427.                                        const struct value_print_options *,
  428.                                        struct type **);

  429. /* It was changed to this after 2.4.5.  */
  430. const char pascal_vtbl_ptr_name[] =
  431. {'_', '_', 'v', 't', 'b', 'l', '_', 'p', 't', 'r', '_', 't', 'y', 'p', 'e', 0};

  432. /* Return truth value for assertion that TYPE is of the type
  433.    "pointer to virtual function".  */

  434. int
  435. pascal_object_is_vtbl_ptr_type (struct type *type)
  436. {
  437.   const char *typename = type_name_no_tag (type);

  438.   return (typename != NULL
  439.           && strcmp (typename, pascal_vtbl_ptr_name) == 0);
  440. }

  441. /* Return truth value for the assertion that TYPE is of the type
  442.    "pointer to virtual function table".  */

  443. int
  444. pascal_object_is_vtbl_member (struct type *type)
  445. {
  446.   if (TYPE_CODE (type) == TYPE_CODE_PTR)
  447.     {
  448.       type = TYPE_TARGET_TYPE (type);
  449.       if (TYPE_CODE (type) == TYPE_CODE_ARRAY)
  450.         {
  451.           type = TYPE_TARGET_TYPE (type);
  452.           if (TYPE_CODE (type) == TYPE_CODE_STRUCT        /* If not using
  453.                                                            thunks.  */
  454.               || TYPE_CODE (type) == TYPE_CODE_PTR)        /* If using thunks.  */
  455.             {
  456.               /* Virtual functions tables are full of pointers
  457.                  to virtual functions.  */
  458.               return pascal_object_is_vtbl_ptr_type (type);
  459.             }
  460.         }
  461.     }
  462.   return 0;
  463. }

  464. /* Mutually recursive subroutines of pascal_object_print_value and
  465.    c_val_print to print out a structure's fields:
  466.    pascal_object_print_value_fields and pascal_object_print_value.

  467.    TYPE, VALADDR, ADDRESS, STREAM, RECURSE, and OPTIONS have the
  468.    same meanings as in pascal_object_print_value and c_val_print.

  469.    DONT_PRINT is an array of baseclass types that we
  470.    should not print, or zero if called from top level.  */

  471. void
  472. pascal_object_print_value_fields (struct type *type, const gdb_byte *valaddr,
  473.                                   int offset,
  474.                                   CORE_ADDR address, struct ui_file *stream,
  475.                                   int recurse,
  476.                                   const struct value *val,
  477.                                   const struct value_print_options *options,
  478.                                   struct type **dont_print_vb,
  479.                                   int dont_print_statmem)
  480. {
  481.   int i, len, n_baseclasses;
  482.   char *last_dont_print = obstack_next_free (&dont_print_statmem_obstack);

  483.   CHECK_TYPEDEF (type);

  484.   fprintf_filtered (stream, "{");
  485.   len = TYPE_NFIELDS (type);
  486.   n_baseclasses = TYPE_N_BASECLASSES (type);

  487.   /* Print out baseclasses such that we don't print
  488.      duplicates of virtual baseclasses.  */
  489.   if (n_baseclasses > 0)
  490.     pascal_object_print_value (type, valaddr, offset, address,
  491.                                stream, recurse + 1, val,
  492.                                options, dont_print_vb);

  493.   if (!len && n_baseclasses == 1)
  494.     fprintf_filtered (stream, "<No data fields>");
  495.   else
  496.     {
  497.       struct obstack tmp_obstack = dont_print_statmem_obstack;
  498.       int fields_seen = 0;

  499.       if (dont_print_statmem == 0)
  500.         {
  501.           /* If we're at top level, carve out a completely fresh
  502.              chunk of the obstack and use that until this particular
  503.              invocation returns.  */
  504.           obstack_finish (&dont_print_statmem_obstack);
  505.         }

  506.       for (i = n_baseclasses; i < len; i++)
  507.         {
  508.           /* If requested, skip printing of static fields.  */
  509.           if (!options->pascal_static_field_print
  510.               && field_is_static (&TYPE_FIELD (type, i)))
  511.             continue;
  512.           if (fields_seen)
  513.             fprintf_filtered (stream, ", ");
  514.           else if (n_baseclasses > 0)
  515.             {
  516.               if (options->prettyformat)
  517.                 {
  518.                   fprintf_filtered (stream, "\n");
  519.                   print_spaces_filtered (2 + 2 * recurse, stream);
  520.                   fputs_filtered ("members of ", stream);
  521.                   fputs_filtered (type_name_no_tag (type), stream);
  522.                   fputs_filtered (": ", stream);
  523.                 }
  524.             }
  525.           fields_seen = 1;

  526.           if (options->prettyformat)
  527.             {
  528.               fprintf_filtered (stream, "\n");
  529.               print_spaces_filtered (2 + 2 * recurse, stream);
  530.             }
  531.           else
  532.             {
  533.               wrap_here (n_spaces (2 + 2 * recurse));
  534.             }

  535.           annotate_field_begin (TYPE_FIELD_TYPE (type, i));

  536.           if (field_is_static (&TYPE_FIELD (type, i)))
  537.             fputs_filtered ("static ", stream);
  538.           fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i),
  539.                                    language_cplus,
  540.                                    DMGL_PARAMS | DMGL_ANSI);
  541.           annotate_field_name_end ();
  542.           fputs_filtered (" = ", stream);
  543.           annotate_field_value ();

  544.           if (!field_is_static (&TYPE_FIELD (type, i))
  545.               && TYPE_FIELD_PACKED (type, i))
  546.             {
  547.               struct value *v;

  548.               /* Bitfields require special handling, especially due to byte
  549.                  order problems.  */
  550.               if (TYPE_FIELD_IGNORE (type, i))
  551.                 {
  552.                   fputs_filtered ("<optimized out or zero length>", stream);
  553.                 }
  554.               else if (value_bits_synthetic_pointer (val,
  555.                                                      TYPE_FIELD_BITPOS (type,
  556.                                                                         i),
  557.                                                      TYPE_FIELD_BITSIZE (type,
  558.                                                                          i)))
  559.                 {
  560.                   fputs_filtered (_("<synthetic pointer>"), stream);
  561.                 }
  562.               else
  563.                 {
  564.                   struct value_print_options opts = *options;

  565.                   v = value_field_bitfield (type, i, valaddr, offset, val);

  566.                   opts.deref_ref = 0;
  567.                   common_val_print (v, stream, recurse + 1, &opts,
  568.                                     current_language);
  569.                 }
  570.             }
  571.           else
  572.             {
  573.               if (TYPE_FIELD_IGNORE (type, i))
  574.                 {
  575.                   fputs_filtered ("<optimized out or zero length>", stream);
  576.                 }
  577.               else if (field_is_static (&TYPE_FIELD (type, i)))
  578.                 {
  579.                   /* struct value *v = value_static_field (type, i);
  580.                      v4.17 specific.  */
  581.                   struct value *v;

  582.                   v = value_field_bitfield (type, i, valaddr, offset, val);

  583.                   if (v == NULL)
  584.                     val_print_optimized_out (NULL, stream);
  585.                   else
  586.                     pascal_object_print_static_field (v, stream, recurse + 1,
  587.                                                       options);
  588.                 }
  589.               else
  590.                 {
  591.                   struct value_print_options opts = *options;

  592.                   opts.deref_ref = 0;
  593.                   /* val_print (TYPE_FIELD_TYPE (type, i),
  594.                      valaddr + TYPE_FIELD_BITPOS (type, i) / 8,
  595.                      address + TYPE_FIELD_BITPOS (type, i) / 8, 0,
  596.                      stream, format, 0, recurse + 1, pretty); */
  597.                   val_print (TYPE_FIELD_TYPE (type, i),
  598.                              valaddr, offset + TYPE_FIELD_BITPOS (type, i) / 8,
  599.                              address, stream, recurse + 1, val, &opts,
  600.                              current_language);
  601.                 }
  602.             }
  603.           annotate_field_end ();
  604.         }

  605.       if (dont_print_statmem == 0)
  606.         {
  607.           /* Free the space used to deal with the printing
  608.              of the members from top level.  */
  609.           obstack_free (&dont_print_statmem_obstack, last_dont_print);
  610.           dont_print_statmem_obstack = tmp_obstack;
  611.         }

  612.       if (options->prettyformat)
  613.         {
  614.           fprintf_filtered (stream, "\n");
  615.           print_spaces_filtered (2 * recurse, stream);
  616.         }
  617.     }
  618.   fprintf_filtered (stream, "}");
  619. }

  620. /* Special val_print routine to avoid printing multiple copies of virtual
  621.    baseclasses.  */

  622. static void
  623. pascal_object_print_value (struct type *type, const gdb_byte *valaddr,
  624.                            int offset,
  625.                            CORE_ADDR address, struct ui_file *stream,
  626.                            int recurse,
  627.                            const struct value *val,
  628.                            const struct value_print_options *options,
  629.                            struct type **dont_print_vb)
  630. {
  631.   struct type **last_dont_print
  632.     = (struct type **) obstack_next_free (&dont_print_vb_obstack);
  633.   struct obstack tmp_obstack = dont_print_vb_obstack;
  634.   int i, n_baseclasses = TYPE_N_BASECLASSES (type);

  635.   if (dont_print_vb == 0)
  636.     {
  637.       /* If we're at top level, carve out a completely fresh
  638.          chunk of the obstack and use that until this particular
  639.          invocation returns.  */
  640.       /* Bump up the high-water mark.  Now alpha is omega.  */
  641.       obstack_finish (&dont_print_vb_obstack);
  642.     }

  643.   for (i = 0; i < n_baseclasses; i++)
  644.     {
  645.       int boffset = 0;
  646.       struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i));
  647.       const char *basename = type_name_no_tag (baseclass);
  648.       const gdb_byte *base_valaddr = NULL;
  649.       int thisoffset;
  650.       volatile struct gdb_exception ex;
  651.       int skip = 0;

  652.       if (BASETYPE_VIA_VIRTUAL (type, i))
  653.         {
  654.           struct type **first_dont_print
  655.             = (struct type **) obstack_base (&dont_print_vb_obstack);

  656.           int j = (struct type **) obstack_next_free (&dont_print_vb_obstack)
  657.             - first_dont_print;

  658.           while (--j >= 0)
  659.             if (baseclass == first_dont_print[j])
  660.               goto flush_it;

  661.           obstack_ptr_grow (&dont_print_vb_obstack, baseclass);
  662.         }

  663.       thisoffset = offset;

  664.       TRY_CATCH (ex, RETURN_MASK_ERROR)
  665.         {
  666.           boffset = baseclass_offset (type, i, valaddr, offset, address, val);
  667.         }
  668.       if (ex.reason < 0 && ex.error == NOT_AVAILABLE_ERROR)
  669.         skip = -1;
  670.       else if (ex.reason < 0)
  671.         skip = 1;
  672.       else
  673.         {
  674.           skip = 0;

  675.           /* The virtual base class pointer might have been clobbered by the
  676.              user program. Make sure that it still points to a valid memory
  677.              location.  */

  678.           if (boffset < 0 || boffset >= TYPE_LENGTH (type))
  679.             {
  680.               gdb_byte *buf;
  681.               struct cleanup *back_to;

  682.               buf = xmalloc (TYPE_LENGTH (baseclass));
  683.               back_to = make_cleanup (xfree, buf);

  684.               base_valaddr = buf;
  685.               if (target_read_memory (address + boffset, buf,
  686.                                       TYPE_LENGTH (baseclass)) != 0)
  687.                 skip = 1;
  688.               address = address + boffset;
  689.               thisoffset = 0;
  690.               boffset = 0;
  691.               do_cleanups (back_to);
  692.             }
  693.           else
  694.             base_valaddr = valaddr;
  695.         }

  696.       if (options->prettyformat)
  697.         {
  698.           fprintf_filtered (stream, "\n");
  699.           print_spaces_filtered (2 * recurse, stream);
  700.         }
  701.       fputs_filtered ("<", stream);
  702.       /* Not sure what the best notation is in the case where there is no
  703.          baseclass name.  */

  704.       fputs_filtered (basename ? basename : "", stream);
  705.       fputs_filtered ("> = ", stream);

  706.       if (skip < 0)
  707.         val_print_unavailable (stream);
  708.       else if (skip > 0)
  709.         val_print_invalid_address (stream);
  710.       else
  711.         pascal_object_print_value_fields (baseclass, base_valaddr,
  712.                                           thisoffset + boffset, address,
  713.                                           stream, recurse, val, options,
  714.                      (struct type **) obstack_base (&dont_print_vb_obstack),
  715.                                           0);
  716.       fputs_filtered (", ", stream);

  717.     flush_it:
  718.       ;
  719.     }

  720.   if (dont_print_vb == 0)
  721.     {
  722.       /* Free the space used to deal with the printing
  723.          of this type from top level.  */
  724.       obstack_free (&dont_print_vb_obstack, last_dont_print);
  725.       /* Reset watermark so that we can continue protecting
  726.          ourselves from whatever we were protecting ourselves.  */
  727.       dont_print_vb_obstack = tmp_obstack;
  728.     }
  729. }

  730. /* Print value of a static member.
  731.    To avoid infinite recursion when printing a class that contains
  732.    a static instance of the class, we keep the addresses of all printed
  733.    static member classes in an obstack and refuse to print them more
  734.    than once.

  735.    VAL contains the value to print, STREAM, RECURSE, and OPTIONS
  736.    have the same meanings as in c_val_print.  */

  737. static void
  738. pascal_object_print_static_field (struct value *val,
  739.                                   struct ui_file *stream,
  740.                                   int recurse,
  741.                                   const struct value_print_options *options)
  742. {
  743.   struct type *type = value_type (val);
  744.   struct value_print_options opts;

  745.   if (value_entirely_optimized_out (val))
  746.     {
  747.       val_print_optimized_out (val, stream);
  748.       return;
  749.     }

  750.   if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
  751.     {
  752.       CORE_ADDR *first_dont_print, addr;
  753.       int i;

  754.       first_dont_print
  755.         = (CORE_ADDR *) obstack_base (&dont_print_statmem_obstack);
  756.       i = (CORE_ADDR *) obstack_next_free (&dont_print_statmem_obstack)
  757.         - first_dont_print;

  758.       while (--i >= 0)
  759.         {
  760.           if (value_address (val) == first_dont_print[i])
  761.             {
  762.               fputs_filtered ("\
  763. <same as static member of an already seen type>",
  764.                               stream);
  765.               return;
  766.             }
  767.         }

  768.       addr = value_address (val);
  769.       obstack_grow (&dont_print_statmem_obstack, (char *) &addr,
  770.                     sizeof (CORE_ADDR));

  771.       CHECK_TYPEDEF (type);
  772.       pascal_object_print_value_fields (type,
  773.                                         value_contents_for_printing (val),
  774.                                         value_embedded_offset (val),
  775.                                         addr,
  776.                                         stream, recurse,
  777.                                         val, options, NULL, 1);
  778.       return;
  779.     }

  780.   opts = *options;
  781.   opts.deref_ref = 0;
  782.   common_val_print (val, stream, recurse, &opts, current_language);
  783. }

  784. /* -Wmissing-prototypes */
  785. extern initialize_file_ftype _initialize_pascal_valprint;

  786. void
  787. _initialize_pascal_valprint (void)
  788. {
  789.   add_setshow_boolean_cmd ("pascal_static-members", class_support,
  790.                            &user_print_options.pascal_static_field_print, _("\
  791. Set printing of pascal static members."), _("\
  792. Show printing of pascal static members."), NULL,
  793.                            NULL,
  794.                            show_pascal_static_field_print,
  795.                            &setprintlist, &showprintlist);
  796. }