xref: /dflybsd-src/contrib/gdb-7/gdb/p-valprint.c (revision de8e141f24382815c10a4012d209bbbf7abf1112)
15796c8dcSSimon Schubert /* Support for printing Pascal values for GDB, the GNU debugger.
25796c8dcSSimon Schubert 
3*ef5ccd6cSJohn Marino    Copyright (C) 2000-2013 Free Software Foundation, Inc.
45796c8dcSSimon Schubert 
55796c8dcSSimon Schubert    This file is part of GDB.
65796c8dcSSimon Schubert 
75796c8dcSSimon Schubert    This program is free software; you can redistribute it and/or modify
85796c8dcSSimon Schubert    it under the terms of the GNU General Public License as published by
95796c8dcSSimon Schubert    the Free Software Foundation; either version 3 of the License, or
105796c8dcSSimon Schubert    (at your option) any later version.
115796c8dcSSimon Schubert 
125796c8dcSSimon Schubert    This program is distributed in the hope that it will be useful,
135796c8dcSSimon Schubert    but WITHOUT ANY WARRANTY; without even the implied warranty of
145796c8dcSSimon Schubert    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
155796c8dcSSimon Schubert    GNU General Public License for more details.
165796c8dcSSimon Schubert 
175796c8dcSSimon Schubert    You should have received a copy of the GNU General Public License
185796c8dcSSimon Schubert    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
195796c8dcSSimon Schubert 
205796c8dcSSimon Schubert /* This file is derived from c-valprint.c */
215796c8dcSSimon Schubert 
225796c8dcSSimon Schubert #include "defs.h"
235796c8dcSSimon Schubert #include "gdb_obstack.h"
245796c8dcSSimon Schubert #include "symtab.h"
255796c8dcSSimon Schubert #include "gdbtypes.h"
265796c8dcSSimon Schubert #include "expression.h"
275796c8dcSSimon Schubert #include "value.h"
285796c8dcSSimon Schubert #include "command.h"
295796c8dcSSimon Schubert #include "gdbcmd.h"
305796c8dcSSimon Schubert #include "gdbcore.h"
315796c8dcSSimon Schubert #include "demangle.h"
325796c8dcSSimon Schubert #include "valprint.h"
335796c8dcSSimon Schubert #include "typeprint.h"
345796c8dcSSimon Schubert #include "language.h"
355796c8dcSSimon Schubert #include "target.h"
365796c8dcSSimon Schubert #include "annotate.h"
375796c8dcSSimon Schubert #include "p-lang.h"
385796c8dcSSimon Schubert #include "cp-abi.h"
395796c8dcSSimon Schubert #include "cp-support.h"
40c50c785cSJohn Marino #include "exceptions.h"
415796c8dcSSimon Schubert 
425796c8dcSSimon Schubert 
43*ef5ccd6cSJohn Marino /* Decorations for Pascal.  */
445796c8dcSSimon Schubert 
45*ef5ccd6cSJohn Marino static const struct generic_val_print_decorations p_decorations =
46*ef5ccd6cSJohn Marino {
47*ef5ccd6cSJohn Marino   "",
48*ef5ccd6cSJohn Marino   " + ",
49*ef5ccd6cSJohn Marino   " * I",
50*ef5ccd6cSJohn Marino   "true",
51*ef5ccd6cSJohn Marino   "false",
52*ef5ccd6cSJohn Marino   "void"
53*ef5ccd6cSJohn Marino };
54*ef5ccd6cSJohn Marino 
55*ef5ccd6cSJohn Marino /* See val_print for a description of the various parameters of this
56*ef5ccd6cSJohn Marino    function; they are identical.  */
57*ef5ccd6cSJohn Marino 
58*ef5ccd6cSJohn Marino void
pascal_val_print(struct type * type,const gdb_byte * valaddr,int embedded_offset,CORE_ADDR address,struct ui_file * stream,int recurse,const struct value * original_value,const struct value_print_options * options)595796c8dcSSimon Schubert pascal_val_print (struct type *type, const gdb_byte *valaddr,
605796c8dcSSimon Schubert 		  int embedded_offset, CORE_ADDR address,
615796c8dcSSimon Schubert 		  struct ui_file *stream, int recurse,
62cf7f2e2dSJohn Marino 		  const struct value *original_value,
635796c8dcSSimon Schubert 		  const struct value_print_options *options)
645796c8dcSSimon Schubert {
655796c8dcSSimon Schubert   struct gdbarch *gdbarch = get_type_arch (type);
665796c8dcSSimon Schubert   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
675796c8dcSSimon Schubert   unsigned int i = 0;	/* Number of characters printed */
685796c8dcSSimon Schubert   unsigned len;
69cf7f2e2dSJohn Marino   LONGEST low_bound, high_bound;
705796c8dcSSimon Schubert   struct type *elttype;
715796c8dcSSimon Schubert   unsigned eltlen;
725796c8dcSSimon Schubert   int length_pos, length_size, string_pos;
735796c8dcSSimon Schubert   struct type *char_type;
745796c8dcSSimon Schubert   CORE_ADDR addr;
75*ef5ccd6cSJohn Marino   int want_space = 0;
765796c8dcSSimon Schubert 
775796c8dcSSimon Schubert   CHECK_TYPEDEF (type);
785796c8dcSSimon Schubert   switch (TYPE_CODE (type))
795796c8dcSSimon Schubert     {
805796c8dcSSimon Schubert     case TYPE_CODE_ARRAY:
81cf7f2e2dSJohn Marino       if (get_array_bounds (type, &low_bound, &high_bound))
825796c8dcSSimon Schubert 	{
83cf7f2e2dSJohn Marino 	  len = high_bound - low_bound + 1;
845796c8dcSSimon Schubert 	  elttype = check_typedef (TYPE_TARGET_TYPE (type));
855796c8dcSSimon Schubert 	  eltlen = TYPE_LENGTH (elttype);
865796c8dcSSimon Schubert 	  if (options->prettyprint_arrays)
875796c8dcSSimon Schubert 	    {
885796c8dcSSimon Schubert 	      print_spaces_filtered (2 + 2 * recurse, stream);
895796c8dcSSimon Schubert 	    }
90cf7f2e2dSJohn Marino 	  /* If 's' format is used, try to print out as string.
91cf7f2e2dSJohn Marino 	     If no format is given, print as string if element type
92cf7f2e2dSJohn Marino 	     is of TYPE_CODE_CHAR and element size is 1,2 or 4.  */
93cf7f2e2dSJohn Marino 	  if (options->format == 's'
94cf7f2e2dSJohn Marino 	      || ((eltlen == 1 || eltlen == 2 || eltlen == 4)
95cf7f2e2dSJohn Marino 		  && TYPE_CODE (elttype) == TYPE_CODE_CHAR
96cf7f2e2dSJohn Marino 		  && options->format == 0))
975796c8dcSSimon Schubert 	    {
985796c8dcSSimon Schubert 	      /* If requested, look for the first null char and only print
995796c8dcSSimon Schubert 	         elements up to it.  */
1005796c8dcSSimon Schubert 	      if (options->stop_print_at_null)
1015796c8dcSSimon Schubert 		{
1025796c8dcSSimon Schubert 		  unsigned int temp_len;
1035796c8dcSSimon Schubert 
1045796c8dcSSimon Schubert 		  /* Look for a NULL char.  */
1055796c8dcSSimon Schubert 		  for (temp_len = 0;
1065796c8dcSSimon Schubert 		       extract_unsigned_integer (valaddr + embedded_offset +
1075796c8dcSSimon Schubert 						 temp_len * eltlen, eltlen,
1085796c8dcSSimon Schubert 						 byte_order)
1095796c8dcSSimon Schubert 		       && temp_len < len && temp_len < options->print_max;
1105796c8dcSSimon Schubert 		       temp_len++);
1115796c8dcSSimon Schubert 		  len = temp_len;
1125796c8dcSSimon Schubert 		}
1135796c8dcSSimon Schubert 
1145796c8dcSSimon Schubert 	      LA_PRINT_STRING (stream, TYPE_TARGET_TYPE (type),
115cf7f2e2dSJohn Marino 			       valaddr + embedded_offset, len, NULL, 0,
1165796c8dcSSimon Schubert 			       options);
1175796c8dcSSimon Schubert 	      i = len;
1185796c8dcSSimon Schubert 	    }
1195796c8dcSSimon Schubert 	  else
1205796c8dcSSimon Schubert 	    {
1215796c8dcSSimon Schubert 	      fprintf_filtered (stream, "{");
1225796c8dcSSimon Schubert 	      /* If this is a virtual function table, print the 0th
1235796c8dcSSimon Schubert 	         entry specially, and the rest of the members normally.  */
1245796c8dcSSimon Schubert 	      if (pascal_object_is_vtbl_ptr_type (elttype))
1255796c8dcSSimon Schubert 		{
1265796c8dcSSimon Schubert 		  i = 1;
1275796c8dcSSimon Schubert 		  fprintf_filtered (stream, "%d vtable entries", len - 1);
1285796c8dcSSimon Schubert 		}
1295796c8dcSSimon Schubert 	      else
1305796c8dcSSimon Schubert 		{
1315796c8dcSSimon Schubert 		  i = 0;
1325796c8dcSSimon Schubert 		}
133c50c785cSJohn Marino 	      val_print_array_elements (type, valaddr, embedded_offset,
134c50c785cSJohn Marino 					address, stream, recurse,
135c50c785cSJohn Marino 					original_value, options, i);
1365796c8dcSSimon Schubert 	      fprintf_filtered (stream, "}");
1375796c8dcSSimon Schubert 	    }
1385796c8dcSSimon Schubert 	  break;
1395796c8dcSSimon Schubert 	}
1405796c8dcSSimon Schubert       /* Array of unspecified length: treat like pointer to first elt.  */
141c50c785cSJohn Marino       addr = address + embedded_offset;
1425796c8dcSSimon Schubert       goto print_unpacked_pointer;
1435796c8dcSSimon Schubert 
1445796c8dcSSimon Schubert     case TYPE_CODE_PTR:
1455796c8dcSSimon Schubert       if (options->format && options->format != 's')
1465796c8dcSSimon Schubert 	{
147c50c785cSJohn Marino 	  val_print_scalar_formatted (type, valaddr, embedded_offset,
148c50c785cSJohn Marino 				      original_value, options, 0, stream);
1495796c8dcSSimon Schubert 	  break;
1505796c8dcSSimon Schubert 	}
1515796c8dcSSimon Schubert       if (options->vtblprint && pascal_object_is_vtbl_ptr_type (type))
1525796c8dcSSimon Schubert 	{
1535796c8dcSSimon Schubert 	  /* Print the unmangled name if desired.  */
1545796c8dcSSimon Schubert 	  /* Print vtable entry - we only get here if we ARE using
1555796c8dcSSimon Schubert 	     -fvtable_thunks.  (Otherwise, look under TYPE_CODE_STRUCT.)  */
1565796c8dcSSimon Schubert 	  /* Extract the address, assume that it is unsigned.  */
1575796c8dcSSimon Schubert 	  addr = extract_unsigned_integer (valaddr + embedded_offset,
1585796c8dcSSimon Schubert 					   TYPE_LENGTH (type), byte_order);
159*ef5ccd6cSJohn Marino 	  print_address_demangle (options, gdbarch, addr, stream, demangle);
1605796c8dcSSimon Schubert 	  break;
1615796c8dcSSimon Schubert 	}
162c50c785cSJohn Marino       check_typedef (TYPE_TARGET_TYPE (type));
163cf7f2e2dSJohn Marino 
1645796c8dcSSimon Schubert       addr = unpack_pointer (type, valaddr + embedded_offset);
1655796c8dcSSimon Schubert     print_unpacked_pointer:
1665796c8dcSSimon Schubert       elttype = check_typedef (TYPE_TARGET_TYPE (type));
1675796c8dcSSimon Schubert 
1685796c8dcSSimon Schubert       if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
1695796c8dcSSimon Schubert 	{
1705796c8dcSSimon Schubert 	  /* Try to print what function it points to.  */
171*ef5ccd6cSJohn Marino 	  print_address_demangle (options, gdbarch, addr, stream, demangle);
172*ef5ccd6cSJohn Marino 	  return;
1735796c8dcSSimon Schubert 	}
1745796c8dcSSimon Schubert 
1755796c8dcSSimon Schubert       if (options->addressprint && options->format != 's')
1765796c8dcSSimon Schubert 	{
1775796c8dcSSimon Schubert 	  fputs_filtered (paddress (gdbarch, addr), stream);
178*ef5ccd6cSJohn Marino 	  want_space = 1;
1795796c8dcSSimon Schubert 	}
1805796c8dcSSimon Schubert 
1815796c8dcSSimon Schubert       /* For a pointer to char or unsigned char, also print the string
1825796c8dcSSimon Schubert 	 pointed to, unless pointer is null.  */
1835796c8dcSSimon Schubert       if (((TYPE_LENGTH (elttype) == 1
1845796c8dcSSimon Schubert 	   && (TYPE_CODE (elttype) == TYPE_CODE_INT
1855796c8dcSSimon Schubert 	      || TYPE_CODE (elttype) == TYPE_CODE_CHAR))
1865796c8dcSSimon Schubert 	  || ((TYPE_LENGTH (elttype) == 2 || TYPE_LENGTH (elttype) == 4)
1875796c8dcSSimon Schubert 	      && TYPE_CODE (elttype) == TYPE_CODE_CHAR))
1885796c8dcSSimon Schubert 	  && (options->format == 0 || options->format == 's')
1895796c8dcSSimon Schubert 	  && addr != 0)
1905796c8dcSSimon Schubert 	{
191*ef5ccd6cSJohn Marino 	  if (want_space)
192*ef5ccd6cSJohn Marino 	    fputs_filtered (" ", stream);
193c50c785cSJohn Marino 	  /* No wide string yet.  */
194c50c785cSJohn Marino 	  i = val_print_string (elttype, NULL, addr, -1, stream, options);
1955796c8dcSSimon Schubert 	}
196c50c785cSJohn Marino       /* Also for pointers to pascal strings.  */
1975796c8dcSSimon Schubert       /* Note: this is Free Pascal specific:
1985796c8dcSSimon Schubert 	 as GDB does not recognize stabs pascal strings
1995796c8dcSSimon Schubert 	 Pascal strings are mapped to records
200c50c785cSJohn Marino 	 with lowercase names PM.  */
2015796c8dcSSimon Schubert       if (is_pascal_string_type (elttype, &length_pos, &length_size,
2025796c8dcSSimon Schubert 				 &string_pos, &char_type, NULL)
2035796c8dcSSimon Schubert 	  && addr != 0)
2045796c8dcSSimon Schubert 	{
2055796c8dcSSimon Schubert 	  ULONGEST string_length;
2065796c8dcSSimon Schubert 	  void *buffer;
207cf7f2e2dSJohn Marino 
208*ef5ccd6cSJohn Marino 	  if (want_space)
209*ef5ccd6cSJohn Marino 	    fputs_filtered (" ", stream);
2105796c8dcSSimon Schubert 	  buffer = xmalloc (length_size);
2115796c8dcSSimon Schubert 	  read_memory (addr + length_pos, buffer, length_size);
2125796c8dcSSimon Schubert 	  string_length = extract_unsigned_integer (buffer, length_size,
2135796c8dcSSimon Schubert 						    byte_order);
2145796c8dcSSimon Schubert 	  xfree (buffer);
215c50c785cSJohn Marino 	  i = val_print_string (char_type, NULL,
216c50c785cSJohn Marino 				addr + string_pos, string_length,
217c50c785cSJohn Marino 				stream, options);
2185796c8dcSSimon Schubert 	}
2195796c8dcSSimon Schubert       else if (pascal_object_is_vtbl_member (type))
2205796c8dcSSimon Schubert 	{
221c50c785cSJohn Marino 	  /* Print vtbl's nicely.  */
222c50c785cSJohn Marino 	  CORE_ADDR vt_address = unpack_pointer (type,
223c50c785cSJohn Marino 						 valaddr + embedded_offset);
2245796c8dcSSimon Schubert 	  struct minimal_symbol *msymbol =
2255796c8dcSSimon Schubert 	    lookup_minimal_symbol_by_pc (vt_address);
226cf7f2e2dSJohn Marino 
227*ef5ccd6cSJohn Marino 	  /* If 'symbol_print' is set, we did the work above.  */
228*ef5ccd6cSJohn Marino 	  if (!options->symbol_print
229*ef5ccd6cSJohn Marino 	      && (msymbol != NULL)
2305796c8dcSSimon Schubert 	      && (vt_address == SYMBOL_VALUE_ADDRESS (msymbol)))
2315796c8dcSSimon Schubert 	    {
232*ef5ccd6cSJohn Marino 	      if (want_space)
233*ef5ccd6cSJohn Marino 		fputs_filtered (" ", stream);
2345796c8dcSSimon Schubert 	      fputs_filtered ("<", stream);
2355796c8dcSSimon Schubert 	      fputs_filtered (SYMBOL_PRINT_NAME (msymbol), stream);
2365796c8dcSSimon Schubert 	      fputs_filtered (">", stream);
237*ef5ccd6cSJohn Marino 	      want_space = 1;
2385796c8dcSSimon Schubert 	    }
2395796c8dcSSimon Schubert 	  if (vt_address && options->vtblprint)
2405796c8dcSSimon Schubert 	    {
2415796c8dcSSimon Schubert 	      struct value *vt_val;
2425796c8dcSSimon Schubert 	      struct symbol *wsym = (struct symbol *) NULL;
2435796c8dcSSimon Schubert 	      struct type *wtype;
2445796c8dcSSimon Schubert 	      struct block *block = (struct block *) NULL;
245*ef5ccd6cSJohn Marino 	      struct field_of_this_result is_this_fld;
246*ef5ccd6cSJohn Marino 
247*ef5ccd6cSJohn Marino 	      if (want_space)
248*ef5ccd6cSJohn Marino 		fputs_filtered (" ", stream);
2495796c8dcSSimon Schubert 
2505796c8dcSSimon Schubert 	      if (msymbol != NULL)
2515796c8dcSSimon Schubert 		wsym = lookup_symbol (SYMBOL_LINKAGE_NAME (msymbol), block,
2525796c8dcSSimon Schubert 				      VAR_DOMAIN, &is_this_fld);
2535796c8dcSSimon Schubert 
2545796c8dcSSimon Schubert 	      if (wsym)
2555796c8dcSSimon Schubert 		{
2565796c8dcSSimon Schubert 		  wtype = SYMBOL_TYPE (wsym);
2575796c8dcSSimon Schubert 		}
2585796c8dcSSimon Schubert 	      else
2595796c8dcSSimon Schubert 		{
2605796c8dcSSimon Schubert 		  wtype = TYPE_TARGET_TYPE (type);
2615796c8dcSSimon Schubert 		}
2625796c8dcSSimon Schubert 	      vt_val = value_at (wtype, vt_address);
2635796c8dcSSimon Schubert 	      common_val_print (vt_val, stream, recurse + 1, options,
2645796c8dcSSimon Schubert 				current_language);
2655796c8dcSSimon Schubert 	      if (options->pretty)
2665796c8dcSSimon Schubert 		{
2675796c8dcSSimon Schubert 		  fprintf_filtered (stream, "\n");
2685796c8dcSSimon Schubert 		  print_spaces_filtered (2 + 2 * recurse, stream);
2695796c8dcSSimon Schubert 		}
2705796c8dcSSimon Schubert 	    }
2715796c8dcSSimon Schubert 	}
2725796c8dcSSimon Schubert 
273*ef5ccd6cSJohn Marino       return;
2745796c8dcSSimon Schubert 
2755796c8dcSSimon Schubert     case TYPE_CODE_REF:
276*ef5ccd6cSJohn Marino     case TYPE_CODE_ENUM:
277*ef5ccd6cSJohn Marino     case TYPE_CODE_FLAGS:
278*ef5ccd6cSJohn Marino     case TYPE_CODE_FUNC:
279*ef5ccd6cSJohn Marino     case TYPE_CODE_RANGE:
280*ef5ccd6cSJohn Marino     case TYPE_CODE_INT:
281*ef5ccd6cSJohn Marino     case TYPE_CODE_FLT:
282*ef5ccd6cSJohn Marino     case TYPE_CODE_VOID:
283*ef5ccd6cSJohn Marino     case TYPE_CODE_ERROR:
284*ef5ccd6cSJohn Marino     case TYPE_CODE_UNDEF:
285*ef5ccd6cSJohn Marino     case TYPE_CODE_BOOL:
286*ef5ccd6cSJohn Marino     case TYPE_CODE_CHAR:
287*ef5ccd6cSJohn Marino       generic_val_print (type, valaddr, embedded_offset, address,
288*ef5ccd6cSJohn Marino 			 stream, recurse, original_value, options,
289*ef5ccd6cSJohn Marino 			 &p_decorations);
2905796c8dcSSimon Schubert       break;
2915796c8dcSSimon Schubert 
2925796c8dcSSimon Schubert     case TYPE_CODE_UNION:
2935796c8dcSSimon Schubert       if (recurse && !options->unionprint)
2945796c8dcSSimon Schubert 	{
2955796c8dcSSimon Schubert 	  fprintf_filtered (stream, "{...}");
2965796c8dcSSimon Schubert 	  break;
2975796c8dcSSimon Schubert 	}
2985796c8dcSSimon Schubert       /* Fall through.  */
2995796c8dcSSimon Schubert     case TYPE_CODE_STRUCT:
3005796c8dcSSimon Schubert       if (options->vtblprint && pascal_object_is_vtbl_ptr_type (type))
3015796c8dcSSimon Schubert 	{
3025796c8dcSSimon Schubert 	  /* Print the unmangled name if desired.  */
3035796c8dcSSimon Schubert 	  /* Print vtable entry - we only get here if NOT using
3045796c8dcSSimon Schubert 	     -fvtable_thunks.  (Otherwise, look under TYPE_CODE_PTR.)  */
3055796c8dcSSimon Schubert 	  /* Extract the address, assume that it is unsigned.  */
3065796c8dcSSimon Schubert 	  print_address_demangle
307*ef5ccd6cSJohn Marino 	    (options, gdbarch,
308c50c785cSJohn Marino 	     extract_unsigned_integer (valaddr + embedded_offset
309c50c785cSJohn Marino 				       + TYPE_FIELD_BITPOS (type,
310c50c785cSJohn Marino 							    VTBL_FNADDR_OFFSET) / 8,
311c50c785cSJohn Marino 				       TYPE_LENGTH (TYPE_FIELD_TYPE (type,
312c50c785cSJohn Marino 								     VTBL_FNADDR_OFFSET)),
313c50c785cSJohn Marino 				       byte_order),
3145796c8dcSSimon Schubert 	     stream, demangle);
3155796c8dcSSimon Schubert 	}
3165796c8dcSSimon Schubert       else
3175796c8dcSSimon Schubert 	{
3185796c8dcSSimon Schubert           if (is_pascal_string_type (type, &length_pos, &length_size,
3195796c8dcSSimon Schubert                                      &string_pos, &char_type, NULL))
3205796c8dcSSimon Schubert 	    {
321c50c785cSJohn Marino 	      len = extract_unsigned_integer (valaddr + embedded_offset
322c50c785cSJohn Marino 					      + length_pos, length_size,
323c50c785cSJohn Marino 					      byte_order);
324cf7f2e2dSJohn Marino 	      LA_PRINT_STRING (stream, char_type,
325cf7f2e2dSJohn Marino 			       valaddr + embedded_offset + string_pos,
326cf7f2e2dSJohn Marino 			       len, NULL, 0, options);
3275796c8dcSSimon Schubert 	    }
3285796c8dcSSimon Schubert 	  else
329c50c785cSJohn Marino 	    pascal_object_print_value_fields (type, valaddr, embedded_offset,
330c50c785cSJohn Marino 					      address, stream, recurse,
331c50c785cSJohn Marino 					      original_value, options,
332c50c785cSJohn Marino 					      NULL, 0);
3335796c8dcSSimon Schubert 	}
3345796c8dcSSimon Schubert       break;
3355796c8dcSSimon Schubert 
3365796c8dcSSimon Schubert     case TYPE_CODE_SET:
3375796c8dcSSimon Schubert       elttype = TYPE_INDEX_TYPE (type);
3385796c8dcSSimon Schubert       CHECK_TYPEDEF (elttype);
3395796c8dcSSimon Schubert       if (TYPE_STUB (elttype))
3405796c8dcSSimon Schubert 	{
3415796c8dcSSimon Schubert 	  fprintf_filtered (stream, "<incomplete type>");
3425796c8dcSSimon Schubert 	  gdb_flush (stream);
3435796c8dcSSimon Schubert 	  break;
3445796c8dcSSimon Schubert 	}
3455796c8dcSSimon Schubert       else
3465796c8dcSSimon Schubert 	{
3475796c8dcSSimon Schubert 	  struct type *range = elttype;
3485796c8dcSSimon Schubert 	  LONGEST low_bound, high_bound;
3495796c8dcSSimon Schubert 	  int i;
3505796c8dcSSimon Schubert 	  int need_comma = 0;
3515796c8dcSSimon Schubert 
3525796c8dcSSimon Schubert 	  fputs_filtered ("[", stream);
3535796c8dcSSimon Schubert 
3545796c8dcSSimon Schubert 	  i = get_discrete_bounds (range, &low_bound, &high_bound);
355cf7f2e2dSJohn Marino 	  if (low_bound == 0 && high_bound == -1 && TYPE_LENGTH (type) > 0)
356cf7f2e2dSJohn Marino 	    {
357cf7f2e2dSJohn Marino 	      /* If we know the size of the set type, we can figure out the
358cf7f2e2dSJohn Marino 	      maximum value.  */
359cf7f2e2dSJohn Marino 	      i = 0;
360cf7f2e2dSJohn Marino 	      high_bound = TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1;
361cf7f2e2dSJohn Marino 	      TYPE_HIGH_BOUND (range) = high_bound;
362cf7f2e2dSJohn Marino 	    }
3635796c8dcSSimon Schubert 	maybe_bad_bstring:
3645796c8dcSSimon Schubert 	  if (i < 0)
3655796c8dcSSimon Schubert 	    {
3665796c8dcSSimon Schubert 	      fputs_filtered ("<error value>", stream);
3675796c8dcSSimon Schubert 	      goto done;
3685796c8dcSSimon Schubert 	    }
3695796c8dcSSimon Schubert 
3705796c8dcSSimon Schubert 	  for (i = low_bound; i <= high_bound; i++)
3715796c8dcSSimon Schubert 	    {
372c50c785cSJohn Marino 	      int element = value_bit_index (type,
373c50c785cSJohn Marino 					     valaddr + embedded_offset, i);
374cf7f2e2dSJohn Marino 
3755796c8dcSSimon Schubert 	      if (element < 0)
3765796c8dcSSimon Schubert 		{
3775796c8dcSSimon Schubert 		  i = element;
3785796c8dcSSimon Schubert 		  goto maybe_bad_bstring;
3795796c8dcSSimon Schubert 		}
380*ef5ccd6cSJohn Marino 	      if (element)
3815796c8dcSSimon Schubert 		{
3825796c8dcSSimon Schubert 		  if (need_comma)
3835796c8dcSSimon Schubert 		    fputs_filtered (", ", stream);
3845796c8dcSSimon Schubert 		  print_type_scalar (range, i, stream);
3855796c8dcSSimon Schubert 		  need_comma = 1;
3865796c8dcSSimon Schubert 
387c50c785cSJohn Marino 		  if (i + 1 <= high_bound
388c50c785cSJohn Marino 		      && value_bit_index (type,
389c50c785cSJohn Marino 					  valaddr + embedded_offset, ++i))
3905796c8dcSSimon Schubert 		    {
3915796c8dcSSimon Schubert 		      int j = i;
392cf7f2e2dSJohn Marino 
3935796c8dcSSimon Schubert 		      fputs_filtered ("..", stream);
3945796c8dcSSimon Schubert 		      while (i + 1 <= high_bound
395c50c785cSJohn Marino 			     && value_bit_index (type,
396c50c785cSJohn Marino 						 valaddr + embedded_offset,
397c50c785cSJohn Marino 						 ++i))
3985796c8dcSSimon Schubert 			j = i;
3995796c8dcSSimon Schubert 		      print_type_scalar (range, j, stream);
4005796c8dcSSimon Schubert 		    }
4015796c8dcSSimon Schubert 		}
4025796c8dcSSimon Schubert 	    }
4035796c8dcSSimon Schubert 	done:
4045796c8dcSSimon Schubert 	  fputs_filtered ("]", stream);
4055796c8dcSSimon Schubert 	}
4065796c8dcSSimon Schubert       break;
4075796c8dcSSimon Schubert 
4085796c8dcSSimon Schubert     default:
409c50c785cSJohn Marino       error (_("Invalid pascal type code %d in symbol table."),
410c50c785cSJohn Marino 	     TYPE_CODE (type));
4115796c8dcSSimon Schubert     }
4125796c8dcSSimon Schubert   gdb_flush (stream);
4135796c8dcSSimon Schubert }
4145796c8dcSSimon Schubert 
415*ef5ccd6cSJohn Marino void
pascal_value_print(struct value * val,struct ui_file * stream,const struct value_print_options * options)4165796c8dcSSimon Schubert pascal_value_print (struct value *val, struct ui_file *stream,
4175796c8dcSSimon Schubert 		    const struct value_print_options *options)
4185796c8dcSSimon Schubert {
4195796c8dcSSimon Schubert   struct type *type = value_type (val);
420cf7f2e2dSJohn Marino   struct value_print_options opts = *options;
421cf7f2e2dSJohn Marino 
422cf7f2e2dSJohn Marino   opts.deref_ref = 1;
4235796c8dcSSimon Schubert 
4245796c8dcSSimon Schubert   /* If it is a pointer, indicate what it points to.
4255796c8dcSSimon Schubert 
4265796c8dcSSimon Schubert      Print type also if it is a reference.
4275796c8dcSSimon Schubert 
4285796c8dcSSimon Schubert      Object pascal: if it is a member pointer, we will take care
4295796c8dcSSimon Schubert      of that when we print it.  */
4305796c8dcSSimon Schubert   if (TYPE_CODE (type) == TYPE_CODE_PTR
4315796c8dcSSimon Schubert       || TYPE_CODE (type) == TYPE_CODE_REF)
4325796c8dcSSimon Schubert     {
4335796c8dcSSimon Schubert       /* Hack:  remove (char *) for char strings.  Their
4345796c8dcSSimon Schubert          type is indicated by the quoted string anyway.  */
4355796c8dcSSimon Schubert       if (TYPE_CODE (type) == TYPE_CODE_PTR
4365796c8dcSSimon Schubert 	  && TYPE_NAME (type) == NULL
4375796c8dcSSimon Schubert 	  && TYPE_NAME (TYPE_TARGET_TYPE (type)) != NULL
4385796c8dcSSimon Schubert 	  && strcmp (TYPE_NAME (TYPE_TARGET_TYPE (type)), "char") == 0)
4395796c8dcSSimon Schubert 	{
440c50c785cSJohn Marino 	  /* Print nothing.  */
4415796c8dcSSimon Schubert 	}
4425796c8dcSSimon Schubert       else
4435796c8dcSSimon Schubert 	{
4445796c8dcSSimon Schubert 	  fprintf_filtered (stream, "(");
4455796c8dcSSimon Schubert 	  type_print (type, "", stream, -1);
4465796c8dcSSimon Schubert 	  fprintf_filtered (stream, ") ");
4475796c8dcSSimon Schubert 	}
4485796c8dcSSimon Schubert     }
449*ef5ccd6cSJohn Marino   common_val_print (val, stream, 0, &opts, current_language);
4505796c8dcSSimon Schubert }
4515796c8dcSSimon Schubert 
4525796c8dcSSimon Schubert 
4535796c8dcSSimon Schubert static void
show_pascal_static_field_print(struct ui_file * file,int from_tty,struct cmd_list_element * c,const char * value)4545796c8dcSSimon Schubert show_pascal_static_field_print (struct ui_file *file, int from_tty,
4555796c8dcSSimon Schubert 				struct cmd_list_element *c, const char *value)
4565796c8dcSSimon Schubert {
4575796c8dcSSimon Schubert   fprintf_filtered (file, _("Printing of pascal static members is %s.\n"),
4585796c8dcSSimon Schubert 		    value);
4595796c8dcSSimon Schubert }
4605796c8dcSSimon Schubert 
4615796c8dcSSimon Schubert static struct obstack dont_print_vb_obstack;
4625796c8dcSSimon Schubert static struct obstack dont_print_statmem_obstack;
4635796c8dcSSimon Schubert 
4645796c8dcSSimon Schubert static void pascal_object_print_static_field (struct value *,
4655796c8dcSSimon Schubert 					      struct ui_file *, int,
4665796c8dcSSimon Schubert 					      const struct value_print_options *);
4675796c8dcSSimon Schubert 
4685796c8dcSSimon Schubert static void pascal_object_print_value (struct type *, const gdb_byte *,
469c50c785cSJohn Marino 				       int,
4705796c8dcSSimon Schubert 				       CORE_ADDR, struct ui_file *, int,
471cf7f2e2dSJohn Marino 				       const struct value *,
4725796c8dcSSimon Schubert 				       const struct value_print_options *,
4735796c8dcSSimon Schubert 				       struct type **);
4745796c8dcSSimon Schubert 
4755796c8dcSSimon Schubert /* It was changed to this after 2.4.5.  */
4765796c8dcSSimon Schubert const char pascal_vtbl_ptr_name[] =
4775796c8dcSSimon Schubert {'_', '_', 'v', 't', 'b', 'l', '_', 'p', 't', 'r', '_', 't', 'y', 'p', 'e', 0};
4785796c8dcSSimon Schubert 
4795796c8dcSSimon Schubert /* Return truth value for assertion that TYPE is of the type
4805796c8dcSSimon Schubert    "pointer to virtual function".  */
4815796c8dcSSimon Schubert 
4825796c8dcSSimon Schubert int
pascal_object_is_vtbl_ptr_type(struct type * type)4835796c8dcSSimon Schubert pascal_object_is_vtbl_ptr_type (struct type *type)
4845796c8dcSSimon Schubert {
485*ef5ccd6cSJohn Marino   const char *typename = type_name_no_tag (type);
4865796c8dcSSimon Schubert 
4875796c8dcSSimon Schubert   return (typename != NULL
4885796c8dcSSimon Schubert 	  && strcmp (typename, pascal_vtbl_ptr_name) == 0);
4895796c8dcSSimon Schubert }
4905796c8dcSSimon Schubert 
4915796c8dcSSimon Schubert /* Return truth value for the assertion that TYPE is of the type
4925796c8dcSSimon Schubert    "pointer to virtual function table".  */
4935796c8dcSSimon Schubert 
4945796c8dcSSimon Schubert int
pascal_object_is_vtbl_member(struct type * type)4955796c8dcSSimon Schubert pascal_object_is_vtbl_member (struct type *type)
4965796c8dcSSimon Schubert {
4975796c8dcSSimon Schubert   if (TYPE_CODE (type) == TYPE_CODE_PTR)
4985796c8dcSSimon Schubert     {
4995796c8dcSSimon Schubert       type = TYPE_TARGET_TYPE (type);
5005796c8dcSSimon Schubert       if (TYPE_CODE (type) == TYPE_CODE_ARRAY)
5015796c8dcSSimon Schubert 	{
5025796c8dcSSimon Schubert 	  type = TYPE_TARGET_TYPE (type);
503c50c785cSJohn Marino 	  if (TYPE_CODE (type) == TYPE_CODE_STRUCT	/* If not using
504c50c785cSJohn Marino 							   thunks.  */
505c50c785cSJohn Marino 	      || TYPE_CODE (type) == TYPE_CODE_PTR)	/* If using thunks.  */
5065796c8dcSSimon Schubert 	    {
5075796c8dcSSimon Schubert 	      /* Virtual functions tables are full of pointers
5085796c8dcSSimon Schubert 	         to virtual functions.  */
5095796c8dcSSimon Schubert 	      return pascal_object_is_vtbl_ptr_type (type);
5105796c8dcSSimon Schubert 	    }
5115796c8dcSSimon Schubert 	}
5125796c8dcSSimon Schubert     }
5135796c8dcSSimon Schubert   return 0;
5145796c8dcSSimon Schubert }
5155796c8dcSSimon Schubert 
5165796c8dcSSimon Schubert /* Mutually recursive subroutines of pascal_object_print_value and
5175796c8dcSSimon Schubert    c_val_print to print out a structure's fields:
5185796c8dcSSimon Schubert    pascal_object_print_value_fields and pascal_object_print_value.
5195796c8dcSSimon Schubert 
5205796c8dcSSimon Schubert    TYPE, VALADDR, ADDRESS, STREAM, RECURSE, and OPTIONS have the
5215796c8dcSSimon Schubert    same meanings as in pascal_object_print_value and c_val_print.
5225796c8dcSSimon Schubert 
5235796c8dcSSimon Schubert    DONT_PRINT is an array of baseclass types that we
5245796c8dcSSimon Schubert    should not print, or zero if called from top level.  */
5255796c8dcSSimon Schubert 
5265796c8dcSSimon Schubert void
pascal_object_print_value_fields(struct type * type,const gdb_byte * valaddr,int offset,CORE_ADDR address,struct ui_file * stream,int recurse,const struct value * val,const struct value_print_options * options,struct type ** dont_print_vb,int dont_print_statmem)5275796c8dcSSimon Schubert pascal_object_print_value_fields (struct type *type, const gdb_byte *valaddr,
528c50c785cSJohn Marino 				  int offset,
5295796c8dcSSimon Schubert 				  CORE_ADDR address, struct ui_file *stream,
5305796c8dcSSimon Schubert 				  int recurse,
531cf7f2e2dSJohn Marino 				  const struct value *val,
5325796c8dcSSimon Schubert 				  const struct value_print_options *options,
5335796c8dcSSimon Schubert 				  struct type **dont_print_vb,
5345796c8dcSSimon Schubert 				  int dont_print_statmem)
5355796c8dcSSimon Schubert {
5365796c8dcSSimon Schubert   int i, len, n_baseclasses;
5375796c8dcSSimon Schubert   char *last_dont_print = obstack_next_free (&dont_print_statmem_obstack);
5385796c8dcSSimon Schubert 
5395796c8dcSSimon Schubert   CHECK_TYPEDEF (type);
5405796c8dcSSimon Schubert 
5415796c8dcSSimon Schubert   fprintf_filtered (stream, "{");
5425796c8dcSSimon Schubert   len = TYPE_NFIELDS (type);
5435796c8dcSSimon Schubert   n_baseclasses = TYPE_N_BASECLASSES (type);
5445796c8dcSSimon Schubert 
5455796c8dcSSimon Schubert   /* Print out baseclasses such that we don't print
5465796c8dcSSimon Schubert      duplicates of virtual baseclasses.  */
5475796c8dcSSimon Schubert   if (n_baseclasses > 0)
548c50c785cSJohn Marino     pascal_object_print_value (type, valaddr, offset, address,
549c50c785cSJohn Marino 			       stream, recurse + 1, val,
550c50c785cSJohn Marino 			       options, dont_print_vb);
5515796c8dcSSimon Schubert 
5525796c8dcSSimon Schubert   if (!len && n_baseclasses == 1)
5535796c8dcSSimon Schubert     fprintf_filtered (stream, "<No data fields>");
5545796c8dcSSimon Schubert   else
5555796c8dcSSimon Schubert     {
5565796c8dcSSimon Schubert       struct obstack tmp_obstack = dont_print_statmem_obstack;
5575796c8dcSSimon Schubert       int fields_seen = 0;
5585796c8dcSSimon Schubert 
5595796c8dcSSimon Schubert       if (dont_print_statmem == 0)
5605796c8dcSSimon Schubert 	{
5615796c8dcSSimon Schubert 	  /* If we're at top level, carve out a completely fresh
5625796c8dcSSimon Schubert 	     chunk of the obstack and use that until this particular
5635796c8dcSSimon Schubert 	     invocation returns.  */
5645796c8dcSSimon Schubert 	  obstack_finish (&dont_print_statmem_obstack);
5655796c8dcSSimon Schubert 	}
5665796c8dcSSimon Schubert 
5675796c8dcSSimon Schubert       for (i = n_baseclasses; i < len; i++)
5685796c8dcSSimon Schubert 	{
5695796c8dcSSimon Schubert 	  /* If requested, skip printing of static fields.  */
5705796c8dcSSimon Schubert 	  if (!options->pascal_static_field_print
5715796c8dcSSimon Schubert 	      && field_is_static (&TYPE_FIELD (type, i)))
5725796c8dcSSimon Schubert 	    continue;
5735796c8dcSSimon Schubert 	  if (fields_seen)
5745796c8dcSSimon Schubert 	    fprintf_filtered (stream, ", ");
5755796c8dcSSimon Schubert 	  else if (n_baseclasses > 0)
5765796c8dcSSimon Schubert 	    {
5775796c8dcSSimon Schubert 	      if (options->pretty)
5785796c8dcSSimon Schubert 		{
5795796c8dcSSimon Schubert 		  fprintf_filtered (stream, "\n");
5805796c8dcSSimon Schubert 		  print_spaces_filtered (2 + 2 * recurse, stream);
5815796c8dcSSimon Schubert 		  fputs_filtered ("members of ", stream);
5825796c8dcSSimon Schubert 		  fputs_filtered (type_name_no_tag (type), stream);
5835796c8dcSSimon Schubert 		  fputs_filtered (": ", stream);
5845796c8dcSSimon Schubert 		}
5855796c8dcSSimon Schubert 	    }
5865796c8dcSSimon Schubert 	  fields_seen = 1;
5875796c8dcSSimon Schubert 
5885796c8dcSSimon Schubert 	  if (options->pretty)
5895796c8dcSSimon Schubert 	    {
5905796c8dcSSimon Schubert 	      fprintf_filtered (stream, "\n");
5915796c8dcSSimon Schubert 	      print_spaces_filtered (2 + 2 * recurse, stream);
5925796c8dcSSimon Schubert 	    }
5935796c8dcSSimon Schubert 	  else
5945796c8dcSSimon Schubert 	    {
5955796c8dcSSimon Schubert 	      wrap_here (n_spaces (2 + 2 * recurse));
5965796c8dcSSimon Schubert 	    }
597*ef5ccd6cSJohn Marino 
5985796c8dcSSimon Schubert 	  annotate_field_begin (TYPE_FIELD_TYPE (type, i));
5995796c8dcSSimon Schubert 
6005796c8dcSSimon Schubert 	  if (field_is_static (&TYPE_FIELD (type, i)))
6015796c8dcSSimon Schubert 	    fputs_filtered ("static ", stream);
6025796c8dcSSimon Schubert 	  fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i),
6035796c8dcSSimon Schubert 				   language_cplus,
6045796c8dcSSimon Schubert 				   DMGL_PARAMS | DMGL_ANSI);
6055796c8dcSSimon Schubert 	  annotate_field_name_end ();
6065796c8dcSSimon Schubert 	  fputs_filtered (" = ", stream);
6075796c8dcSSimon Schubert 	  annotate_field_value ();
6085796c8dcSSimon Schubert 
6095796c8dcSSimon Schubert 	  if (!field_is_static (&TYPE_FIELD (type, i))
6105796c8dcSSimon Schubert 	      && TYPE_FIELD_PACKED (type, i))
6115796c8dcSSimon Schubert 	    {
6125796c8dcSSimon Schubert 	      struct value *v;
6135796c8dcSSimon Schubert 
6145796c8dcSSimon Schubert 	      /* Bitfields require special handling, especially due to byte
6155796c8dcSSimon Schubert 	         order problems.  */
6165796c8dcSSimon Schubert 	      if (TYPE_FIELD_IGNORE (type, i))
6175796c8dcSSimon Schubert 		{
6185796c8dcSSimon Schubert 		  fputs_filtered ("<optimized out or zero length>", stream);
6195796c8dcSSimon Schubert 		}
620c50c785cSJohn Marino 	      else if (value_bits_synthetic_pointer (val,
621c50c785cSJohn Marino 						     TYPE_FIELD_BITPOS (type,
622c50c785cSJohn Marino 									i),
623c50c785cSJohn Marino 						     TYPE_FIELD_BITSIZE (type,
624c50c785cSJohn Marino 									 i)))
625c50c785cSJohn Marino 		{
626c50c785cSJohn Marino 		  fputs_filtered (_("<synthetic pointer>"), stream);
627c50c785cSJohn Marino 		}
628cf7f2e2dSJohn Marino 	      else if (!value_bits_valid (val, TYPE_FIELD_BITPOS (type, i),
629cf7f2e2dSJohn Marino 					  TYPE_FIELD_BITSIZE (type, i)))
630cf7f2e2dSJohn Marino 		{
631c50c785cSJohn Marino 		  val_print_optimized_out (stream);
632cf7f2e2dSJohn Marino 		}
6335796c8dcSSimon Schubert 	      else
6345796c8dcSSimon Schubert 		{
6355796c8dcSSimon Schubert 		  struct value_print_options opts = *options;
636cf7f2e2dSJohn Marino 
637c50c785cSJohn Marino 		  v = value_field_bitfield (type, i, valaddr, offset, val);
6385796c8dcSSimon Schubert 
6395796c8dcSSimon Schubert 		  opts.deref_ref = 0;
6405796c8dcSSimon Schubert 		  common_val_print (v, stream, recurse + 1, &opts,
6415796c8dcSSimon Schubert 				    current_language);
6425796c8dcSSimon Schubert 		}
6435796c8dcSSimon Schubert 	    }
6445796c8dcSSimon Schubert 	  else
6455796c8dcSSimon Schubert 	    {
6465796c8dcSSimon Schubert 	      if (TYPE_FIELD_IGNORE (type, i))
6475796c8dcSSimon Schubert 		{
6485796c8dcSSimon Schubert 		  fputs_filtered ("<optimized out or zero length>", stream);
6495796c8dcSSimon Schubert 		}
6505796c8dcSSimon Schubert 	      else if (field_is_static (&TYPE_FIELD (type, i)))
6515796c8dcSSimon Schubert 		{
652c50c785cSJohn Marino 		  /* struct value *v = value_static_field (type, i);
653c50c785cSJohn Marino 		     v4.17 specific.  */
6545796c8dcSSimon Schubert 		  struct value *v;
655cf7f2e2dSJohn Marino 
656c50c785cSJohn Marino 		  v = value_field_bitfield (type, i, valaddr, offset, val);
6575796c8dcSSimon Schubert 
6585796c8dcSSimon Schubert 		  if (v == NULL)
659c50c785cSJohn Marino 		    val_print_optimized_out (stream);
6605796c8dcSSimon Schubert 		  else
6615796c8dcSSimon Schubert 		    pascal_object_print_static_field (v, stream, recurse + 1,
6625796c8dcSSimon Schubert 						      options);
6635796c8dcSSimon Schubert 		}
6645796c8dcSSimon Schubert 	      else
6655796c8dcSSimon Schubert 		{
6665796c8dcSSimon Schubert 		  struct value_print_options opts = *options;
667cf7f2e2dSJohn Marino 
6685796c8dcSSimon Schubert 		  opts.deref_ref = 0;
6695796c8dcSSimon Schubert 		  /* val_print (TYPE_FIELD_TYPE (type, i),
6705796c8dcSSimon Schubert 		     valaddr + TYPE_FIELD_BITPOS (type, i) / 8,
6715796c8dcSSimon Schubert 		     address + TYPE_FIELD_BITPOS (type, i) / 8, 0,
6725796c8dcSSimon Schubert 		     stream, format, 0, recurse + 1, pretty); */
6735796c8dcSSimon Schubert 		  val_print (TYPE_FIELD_TYPE (type, i),
674c50c785cSJohn Marino 			     valaddr, offset + TYPE_FIELD_BITPOS (type, i) / 8,
675c50c785cSJohn Marino 			     address, stream, recurse + 1, val, &opts,
6765796c8dcSSimon Schubert 			     current_language);
6775796c8dcSSimon Schubert 		}
6785796c8dcSSimon Schubert 	    }
6795796c8dcSSimon Schubert 	  annotate_field_end ();
6805796c8dcSSimon Schubert 	}
6815796c8dcSSimon Schubert 
6825796c8dcSSimon Schubert       if (dont_print_statmem == 0)
6835796c8dcSSimon Schubert 	{
6845796c8dcSSimon Schubert 	  /* Free the space used to deal with the printing
6855796c8dcSSimon Schubert 	     of the members from top level.  */
6865796c8dcSSimon Schubert 	  obstack_free (&dont_print_statmem_obstack, last_dont_print);
6875796c8dcSSimon Schubert 	  dont_print_statmem_obstack = tmp_obstack;
6885796c8dcSSimon Schubert 	}
6895796c8dcSSimon Schubert 
6905796c8dcSSimon Schubert       if (options->pretty)
6915796c8dcSSimon Schubert 	{
6925796c8dcSSimon Schubert 	  fprintf_filtered (stream, "\n");
6935796c8dcSSimon Schubert 	  print_spaces_filtered (2 * recurse, stream);
6945796c8dcSSimon Schubert 	}
6955796c8dcSSimon Schubert     }
6965796c8dcSSimon Schubert   fprintf_filtered (stream, "}");
6975796c8dcSSimon Schubert }
6985796c8dcSSimon Schubert 
6995796c8dcSSimon Schubert /* Special val_print routine to avoid printing multiple copies of virtual
7005796c8dcSSimon Schubert    baseclasses.  */
7015796c8dcSSimon Schubert 
7025796c8dcSSimon Schubert static void
pascal_object_print_value(struct type * type,const gdb_byte * valaddr,int offset,CORE_ADDR address,struct ui_file * stream,int recurse,const struct value * val,const struct value_print_options * options,struct type ** dont_print_vb)7035796c8dcSSimon Schubert pascal_object_print_value (struct type *type, const gdb_byte *valaddr,
704c50c785cSJohn Marino 			   int offset,
7055796c8dcSSimon Schubert 			   CORE_ADDR address, struct ui_file *stream,
7065796c8dcSSimon Schubert 			   int recurse,
707cf7f2e2dSJohn Marino 			   const struct value *val,
7085796c8dcSSimon Schubert 			   const struct value_print_options *options,
7095796c8dcSSimon Schubert 			   struct type **dont_print_vb)
7105796c8dcSSimon Schubert {
7115796c8dcSSimon Schubert   struct type **last_dont_print
7125796c8dcSSimon Schubert     = (struct type **) obstack_next_free (&dont_print_vb_obstack);
7135796c8dcSSimon Schubert   struct obstack tmp_obstack = dont_print_vb_obstack;
7145796c8dcSSimon Schubert   int i, n_baseclasses = TYPE_N_BASECLASSES (type);
7155796c8dcSSimon Schubert 
7165796c8dcSSimon Schubert   if (dont_print_vb == 0)
7175796c8dcSSimon Schubert     {
7185796c8dcSSimon Schubert       /* If we're at top level, carve out a completely fresh
7195796c8dcSSimon Schubert          chunk of the obstack and use that until this particular
7205796c8dcSSimon Schubert          invocation returns.  */
7215796c8dcSSimon Schubert       /* Bump up the high-water mark.  Now alpha is omega.  */
7225796c8dcSSimon Schubert       obstack_finish (&dont_print_vb_obstack);
7235796c8dcSSimon Schubert     }
7245796c8dcSSimon Schubert 
7255796c8dcSSimon Schubert   for (i = 0; i < n_baseclasses; i++)
7265796c8dcSSimon Schubert     {
727c50c785cSJohn Marino       int boffset = 0;
7285796c8dcSSimon Schubert       struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i));
729*ef5ccd6cSJohn Marino       const char *basename = type_name_no_tag (baseclass);
730c50c785cSJohn Marino       const gdb_byte *base_valaddr = NULL;
731c50c785cSJohn Marino       int thisoffset;
732c50c785cSJohn Marino       volatile struct gdb_exception ex;
733c50c785cSJohn Marino       int skip = 0;
7345796c8dcSSimon Schubert 
7355796c8dcSSimon Schubert       if (BASETYPE_VIA_VIRTUAL (type, i))
7365796c8dcSSimon Schubert 	{
7375796c8dcSSimon Schubert 	  struct type **first_dont_print
7385796c8dcSSimon Schubert 	    = (struct type **) obstack_base (&dont_print_vb_obstack);
7395796c8dcSSimon Schubert 
7405796c8dcSSimon Schubert 	  int j = (struct type **) obstack_next_free (&dont_print_vb_obstack)
7415796c8dcSSimon Schubert 	    - first_dont_print;
7425796c8dcSSimon Schubert 
7435796c8dcSSimon Schubert 	  while (--j >= 0)
7445796c8dcSSimon Schubert 	    if (baseclass == first_dont_print[j])
7455796c8dcSSimon Schubert 	      goto flush_it;
7465796c8dcSSimon Schubert 
7475796c8dcSSimon Schubert 	  obstack_ptr_grow (&dont_print_vb_obstack, baseclass);
7485796c8dcSSimon Schubert 	}
7495796c8dcSSimon Schubert 
750c50c785cSJohn Marino       thisoffset = offset;
751c50c785cSJohn Marino 
752c50c785cSJohn Marino       TRY_CATCH (ex, RETURN_MASK_ERROR)
753c50c785cSJohn Marino 	{
754c50c785cSJohn Marino 	  boffset = baseclass_offset (type, i, valaddr, offset, address, val);
755c50c785cSJohn Marino 	}
756c50c785cSJohn Marino       if (ex.reason < 0 && ex.error == NOT_AVAILABLE_ERROR)
757c50c785cSJohn Marino 	skip = -1;
758c50c785cSJohn Marino       else if (ex.reason < 0)
759c50c785cSJohn Marino 	skip = 1;
760c50c785cSJohn Marino       else
761c50c785cSJohn Marino 	{
762c50c785cSJohn Marino 	  skip = 0;
763c50c785cSJohn Marino 
764c50c785cSJohn Marino 	  /* The virtual base class pointer might have been clobbered by the
765c50c785cSJohn Marino 	     user program. Make sure that it still points to a valid memory
766c50c785cSJohn Marino 	     location.  */
767c50c785cSJohn Marino 
768c50c785cSJohn Marino 	  if (boffset < 0 || boffset >= TYPE_LENGTH (type))
769c50c785cSJohn Marino 	    {
770*ef5ccd6cSJohn Marino 	      gdb_byte *buf;
771*ef5ccd6cSJohn Marino 	      struct cleanup *back_to;
772*ef5ccd6cSJohn Marino 
773*ef5ccd6cSJohn Marino 	      buf = xmalloc (TYPE_LENGTH (baseclass));
774*ef5ccd6cSJohn Marino 	      back_to = make_cleanup (xfree, buf);
775c50c785cSJohn Marino 
776c50c785cSJohn Marino 	      base_valaddr = buf;
777c50c785cSJohn Marino 	      if (target_read_memory (address + boffset, buf,
778c50c785cSJohn Marino 				      TYPE_LENGTH (baseclass)) != 0)
779c50c785cSJohn Marino 		skip = 1;
780c50c785cSJohn Marino 	      address = address + boffset;
781c50c785cSJohn Marino 	      thisoffset = 0;
782c50c785cSJohn Marino 	      boffset = 0;
783*ef5ccd6cSJohn Marino 	      do_cleanups (back_to);
784c50c785cSJohn Marino 	    }
785c50c785cSJohn Marino 	  else
786c50c785cSJohn Marino 	    base_valaddr = valaddr;
787c50c785cSJohn Marino 	}
7885796c8dcSSimon Schubert 
7895796c8dcSSimon Schubert       if (options->pretty)
7905796c8dcSSimon Schubert 	{
7915796c8dcSSimon Schubert 	  fprintf_filtered (stream, "\n");
7925796c8dcSSimon Schubert 	  print_spaces_filtered (2 * recurse, stream);
7935796c8dcSSimon Schubert 	}
7945796c8dcSSimon Schubert       fputs_filtered ("<", stream);
7955796c8dcSSimon Schubert       /* Not sure what the best notation is in the case where there is no
7965796c8dcSSimon Schubert          baseclass name.  */
7975796c8dcSSimon Schubert 
7985796c8dcSSimon Schubert       fputs_filtered (basename ? basename : "", stream);
7995796c8dcSSimon Schubert       fputs_filtered ("> = ", stream);
8005796c8dcSSimon Schubert 
801c50c785cSJohn Marino       if (skip < 0)
802c50c785cSJohn Marino 	val_print_unavailable (stream);
803c50c785cSJohn Marino       else if (skip > 0)
804c50c785cSJohn Marino 	val_print_invalid_address (stream);
8055796c8dcSSimon Schubert       else
806c50c785cSJohn Marino 	pascal_object_print_value_fields (baseclass, base_valaddr,
807c50c785cSJohn Marino 					  thisoffset + boffset, address,
808cf7f2e2dSJohn Marino 					  stream, recurse, val, options,
8095796c8dcSSimon Schubert 		     (struct type **) obstack_base (&dont_print_vb_obstack),
8105796c8dcSSimon Schubert 					  0);
8115796c8dcSSimon Schubert       fputs_filtered (", ", stream);
8125796c8dcSSimon Schubert 
8135796c8dcSSimon Schubert     flush_it:
8145796c8dcSSimon Schubert       ;
8155796c8dcSSimon Schubert     }
8165796c8dcSSimon Schubert 
8175796c8dcSSimon Schubert   if (dont_print_vb == 0)
8185796c8dcSSimon Schubert     {
8195796c8dcSSimon Schubert       /* Free the space used to deal with the printing
8205796c8dcSSimon Schubert          of this type from top level.  */
8215796c8dcSSimon Schubert       obstack_free (&dont_print_vb_obstack, last_dont_print);
8225796c8dcSSimon Schubert       /* Reset watermark so that we can continue protecting
8235796c8dcSSimon Schubert          ourselves from whatever we were protecting ourselves.  */
8245796c8dcSSimon Schubert       dont_print_vb_obstack = tmp_obstack;
8255796c8dcSSimon Schubert     }
8265796c8dcSSimon Schubert }
8275796c8dcSSimon Schubert 
8285796c8dcSSimon Schubert /* Print value of a static member.
8295796c8dcSSimon Schubert    To avoid infinite recursion when printing a class that contains
8305796c8dcSSimon Schubert    a static instance of the class, we keep the addresses of all printed
8315796c8dcSSimon Schubert    static member classes in an obstack and refuse to print them more
8325796c8dcSSimon Schubert    than once.
8335796c8dcSSimon Schubert 
8345796c8dcSSimon Schubert    VAL contains the value to print, STREAM, RECURSE, and OPTIONS
8355796c8dcSSimon Schubert    have the same meanings as in c_val_print.  */
8365796c8dcSSimon Schubert 
8375796c8dcSSimon Schubert static void
pascal_object_print_static_field(struct value * val,struct ui_file * stream,int recurse,const struct value_print_options * options)8385796c8dcSSimon Schubert pascal_object_print_static_field (struct value *val,
8395796c8dcSSimon Schubert 				  struct ui_file *stream,
8405796c8dcSSimon Schubert 				  int recurse,
8415796c8dcSSimon Schubert 				  const struct value_print_options *options)
8425796c8dcSSimon Schubert {
8435796c8dcSSimon Schubert   struct type *type = value_type (val);
8445796c8dcSSimon Schubert   struct value_print_options opts;
8455796c8dcSSimon Schubert 
8465796c8dcSSimon Schubert   if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
8475796c8dcSSimon Schubert     {
8485796c8dcSSimon Schubert       CORE_ADDR *first_dont_print, addr;
8495796c8dcSSimon Schubert       int i;
8505796c8dcSSimon Schubert 
8515796c8dcSSimon Schubert       first_dont_print
8525796c8dcSSimon Schubert 	= (CORE_ADDR *) obstack_base (&dont_print_statmem_obstack);
8535796c8dcSSimon Schubert       i = (CORE_ADDR *) obstack_next_free (&dont_print_statmem_obstack)
8545796c8dcSSimon Schubert 	- first_dont_print;
8555796c8dcSSimon Schubert 
8565796c8dcSSimon Schubert       while (--i >= 0)
8575796c8dcSSimon Schubert 	{
8585796c8dcSSimon Schubert 	  if (value_address (val) == first_dont_print[i])
8595796c8dcSSimon Schubert 	    {
860c50c785cSJohn Marino 	      fputs_filtered ("\
861c50c785cSJohn Marino <same as static member of an already seen type>",
8625796c8dcSSimon Schubert 			      stream);
8635796c8dcSSimon Schubert 	      return;
8645796c8dcSSimon Schubert 	    }
8655796c8dcSSimon Schubert 	}
8665796c8dcSSimon Schubert 
8675796c8dcSSimon Schubert       addr = value_address (val);
8685796c8dcSSimon Schubert       obstack_grow (&dont_print_statmem_obstack, (char *) &addr,
8695796c8dcSSimon Schubert 		    sizeof (CORE_ADDR));
8705796c8dcSSimon Schubert 
8715796c8dcSSimon Schubert       CHECK_TYPEDEF (type);
872c50c785cSJohn Marino       pascal_object_print_value_fields (type,
873c50c785cSJohn Marino 					value_contents_for_printing (val),
874c50c785cSJohn Marino 					value_embedded_offset (val),
875c50c785cSJohn Marino 					addr,
876c50c785cSJohn Marino 					stream, recurse,
877c50c785cSJohn Marino 					val, options, NULL, 1);
8785796c8dcSSimon Schubert       return;
8795796c8dcSSimon Schubert     }
8805796c8dcSSimon Schubert 
8815796c8dcSSimon Schubert   opts = *options;
8825796c8dcSSimon Schubert   opts.deref_ref = 0;
8835796c8dcSSimon Schubert   common_val_print (val, stream, recurse, &opts, current_language);
8845796c8dcSSimon Schubert }
8855796c8dcSSimon Schubert 
886c50c785cSJohn Marino /* -Wmissing-prototypes */
887c50c785cSJohn Marino extern initialize_file_ftype _initialize_pascal_valprint;
8885796c8dcSSimon Schubert 
8895796c8dcSSimon Schubert void
_initialize_pascal_valprint(void)8905796c8dcSSimon Schubert _initialize_pascal_valprint (void)
8915796c8dcSSimon Schubert {
8925796c8dcSSimon Schubert   add_setshow_boolean_cmd ("pascal_static-members", class_support,
8935796c8dcSSimon Schubert 			   &user_print_options.pascal_static_field_print, _("\
8945796c8dcSSimon Schubert Set printing of pascal static members."), _("\
8955796c8dcSSimon Schubert Show printing of pascal static members."), NULL,
8965796c8dcSSimon Schubert 			   NULL,
8975796c8dcSSimon Schubert 			   show_pascal_static_field_print,
8985796c8dcSSimon Schubert 			   &setprintlist, &showprintlist);
8995796c8dcSSimon Schubert }
900