Home | History | Annotate | Line # | Download | only in gdb
f-valprint.c revision 1.1
      1  1.1  christos /* Support for printing Fortran values for GDB, the GNU debugger.
      2  1.1  christos 
      3  1.1  christos    Copyright (C) 1993-2014 Free Software Foundation, Inc.
      4  1.1  christos 
      5  1.1  christos    Contributed by Motorola.  Adapted from the C definitions by Farooq Butt
      6  1.1  christos    (fmbutt (at) engage.sps.mot.com), additionally worked over by Stan Shebs.
      7  1.1  christos 
      8  1.1  christos    This file is part of GDB.
      9  1.1  christos 
     10  1.1  christos    This program is free software; you can redistribute it and/or modify
     11  1.1  christos    it under the terms of the GNU General Public License as published by
     12  1.1  christos    the Free Software Foundation; either version 3 of the License, or
     13  1.1  christos    (at your option) any later version.
     14  1.1  christos 
     15  1.1  christos    This program is distributed in the hope that it will be useful,
     16  1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     17  1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     18  1.1  christos    GNU General Public License for more details.
     19  1.1  christos 
     20  1.1  christos    You should have received a copy of the GNU General Public License
     21  1.1  christos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
     22  1.1  christos 
     23  1.1  christos #include "defs.h"
     24  1.1  christos #include <string.h>
     25  1.1  christos #include "symtab.h"
     26  1.1  christos #include "gdbtypes.h"
     27  1.1  christos #include "expression.h"
     28  1.1  christos #include "value.h"
     29  1.1  christos #include "valprint.h"
     30  1.1  christos #include "language.h"
     31  1.1  christos #include "f-lang.h"
     32  1.1  christos #include "frame.h"
     33  1.1  christos #include "gdbcore.h"
     34  1.1  christos #include "command.h"
     35  1.1  christos #include "block.h"
     36  1.1  christos #include "dictionary.h"
     37  1.1  christos #include "gdb_assert.h"
     38  1.1  christos #include "exceptions.h"
     39  1.1  christos 
     40  1.1  christos extern void _initialize_f_valprint (void);
     41  1.1  christos static void info_common_command (char *, int);
     42  1.1  christos static void f77_create_arrayprint_offset_tbl (struct type *,
     43  1.1  christos 					      struct ui_file *);
     44  1.1  christos static void f77_get_dynamic_length_of_aggregate (struct type *);
     45  1.1  christos 
     46  1.1  christos int f77_array_offset_tbl[MAX_FORTRAN_DIMS + 1][2];
     47  1.1  christos 
     48  1.1  christos /* Array which holds offsets to be applied to get a row's elements
     49  1.1  christos    for a given array.  Array also holds the size of each subarray.  */
     50  1.1  christos 
     51  1.1  christos /* The following macro gives us the size of the nth dimension, Where
     52  1.1  christos    n is 1 based.  */
     53  1.1  christos 
     54  1.1  christos #define F77_DIM_SIZE(n) (f77_array_offset_tbl[n][1])
     55  1.1  christos 
     56  1.1  christos /* The following gives us the offset for row n where n is 1-based.  */
     57  1.1  christos 
     58  1.1  christos #define F77_DIM_OFFSET(n) (f77_array_offset_tbl[n][0])
     59  1.1  christos 
     60  1.1  christos int
     61  1.1  christos f77_get_lowerbound (struct type *type)
     62  1.1  christos {
     63  1.1  christos   if (TYPE_ARRAY_LOWER_BOUND_IS_UNDEFINED (type))
     64  1.1  christos     error (_("Lower bound may not be '*' in F77"));
     65  1.1  christos 
     66  1.1  christos   return TYPE_ARRAY_LOWER_BOUND_VALUE (type);
     67  1.1  christos }
     68  1.1  christos 
     69  1.1  christos int
     70  1.1  christos f77_get_upperbound (struct type *type)
     71  1.1  christos {
     72  1.1  christos   if (TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))
     73  1.1  christos     {
     74  1.1  christos       /* We have an assumed size array on our hands.  Assume that
     75  1.1  christos 	 upper_bound == lower_bound so that we show at least 1 element.
     76  1.1  christos 	 If the user wants to see more elements, let him manually ask for 'em
     77  1.1  christos 	 and we'll subscript the array and show him.  */
     78  1.1  christos 
     79  1.1  christos       return f77_get_lowerbound (type);
     80  1.1  christos     }
     81  1.1  christos 
     82  1.1  christos   return TYPE_ARRAY_UPPER_BOUND_VALUE (type);
     83  1.1  christos }
     84  1.1  christos 
     85  1.1  christos /* Obtain F77 adjustable array dimensions.  */
     86  1.1  christos 
     87  1.1  christos static void
     88  1.1  christos f77_get_dynamic_length_of_aggregate (struct type *type)
     89  1.1  christos {
     90  1.1  christos   int upper_bound = -1;
     91  1.1  christos   int lower_bound = 1;
     92  1.1  christos 
     93  1.1  christos   /* Recursively go all the way down into a possibly multi-dimensional
     94  1.1  christos      F77 array and get the bounds.  For simple arrays, this is pretty
     95  1.1  christos      easy but when the bounds are dynamic, we must be very careful
     96  1.1  christos      to add up all the lengths correctly.  Not doing this right
     97  1.1  christos      will lead to horrendous-looking arrays in parameter lists.
     98  1.1  christos 
     99  1.1  christos      This function also works for strings which behave very
    100  1.1  christos      similarly to arrays.  */
    101  1.1  christos 
    102  1.1  christos   if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_ARRAY
    103  1.1  christos       || TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_STRING)
    104  1.1  christos     f77_get_dynamic_length_of_aggregate (TYPE_TARGET_TYPE (type));
    105  1.1  christos 
    106  1.1  christos   /* Recursion ends here, start setting up lengths.  */
    107  1.1  christos   lower_bound = f77_get_lowerbound (type);
    108  1.1  christos   upper_bound = f77_get_upperbound (type);
    109  1.1  christos 
    110  1.1  christos   /* Patch in a valid length value.  */
    111  1.1  christos 
    112  1.1  christos   TYPE_LENGTH (type) =
    113  1.1  christos     (upper_bound - lower_bound + 1)
    114  1.1  christos     * TYPE_LENGTH (check_typedef (TYPE_TARGET_TYPE (type)));
    115  1.1  christos }
    116  1.1  christos 
    117  1.1  christos /* Function that sets up the array offset,size table for the array
    118  1.1  christos    type "type".  */
    119  1.1  christos 
    120  1.1  christos static void
    121  1.1  christos f77_create_arrayprint_offset_tbl (struct type *type, struct ui_file *stream)
    122  1.1  christos {
    123  1.1  christos   struct type *tmp_type;
    124  1.1  christos   int eltlen;
    125  1.1  christos   int ndimen = 1;
    126  1.1  christos   int upper, lower;
    127  1.1  christos 
    128  1.1  christos   tmp_type = type;
    129  1.1  christos 
    130  1.1  christos   while (TYPE_CODE (tmp_type) == TYPE_CODE_ARRAY)
    131  1.1  christos     {
    132  1.1  christos       upper = f77_get_upperbound (tmp_type);
    133  1.1  christos       lower = f77_get_lowerbound (tmp_type);
    134  1.1  christos 
    135  1.1  christos       F77_DIM_SIZE (ndimen) = upper - lower + 1;
    136  1.1  christos 
    137  1.1  christos       tmp_type = TYPE_TARGET_TYPE (tmp_type);
    138  1.1  christos       ndimen++;
    139  1.1  christos     }
    140  1.1  christos 
    141  1.1  christos   /* Now we multiply eltlen by all the offsets, so that later we
    142  1.1  christos      can print out array elements correctly.  Up till now we
    143  1.1  christos      know an offset to apply to get the item but we also
    144  1.1  christos      have to know how much to add to get to the next item.  */
    145  1.1  christos 
    146  1.1  christos   ndimen--;
    147  1.1  christos   eltlen = TYPE_LENGTH (tmp_type);
    148  1.1  christos   F77_DIM_OFFSET (ndimen) = eltlen;
    149  1.1  christos   while (--ndimen > 0)
    150  1.1  christos     {
    151  1.1  christos       eltlen *= F77_DIM_SIZE (ndimen + 1);
    152  1.1  christos       F77_DIM_OFFSET (ndimen) = eltlen;
    153  1.1  christos     }
    154  1.1  christos }
    155  1.1  christos 
    156  1.1  christos 
    157  1.1  christos 
    158  1.1  christos /* Actual function which prints out F77 arrays, Valaddr == address in
    159  1.1  christos    the superior.  Address == the address in the inferior.  */
    160  1.1  christos 
    161  1.1  christos static void
    162  1.1  christos f77_print_array_1 (int nss, int ndimensions, struct type *type,
    163  1.1  christos 		   const gdb_byte *valaddr,
    164  1.1  christos 		   int embedded_offset, CORE_ADDR address,
    165  1.1  christos 		   struct ui_file *stream, int recurse,
    166  1.1  christos 		   const struct value *val,
    167  1.1  christos 		   const struct value_print_options *options,
    168  1.1  christos 		   int *elts)
    169  1.1  christos {
    170  1.1  christos   int i;
    171  1.1  christos 
    172  1.1  christos   if (nss != ndimensions)
    173  1.1  christos     {
    174  1.1  christos       for (i = 0;
    175  1.1  christos 	   (i < F77_DIM_SIZE (nss) && (*elts) < options->print_max);
    176  1.1  christos 	   i++)
    177  1.1  christos 	{
    178  1.1  christos 	  fprintf_filtered (stream, "( ");
    179  1.1  christos 	  f77_print_array_1 (nss + 1, ndimensions, TYPE_TARGET_TYPE (type),
    180  1.1  christos 			     valaddr,
    181  1.1  christos 			     embedded_offset + i * F77_DIM_OFFSET (nss),
    182  1.1  christos 			     address,
    183  1.1  christos 			     stream, recurse, val, options, elts);
    184  1.1  christos 	  fprintf_filtered (stream, ") ");
    185  1.1  christos 	}
    186  1.1  christos       if (*elts >= options->print_max && i < F77_DIM_SIZE (nss))
    187  1.1  christos 	fprintf_filtered (stream, "...");
    188  1.1  christos     }
    189  1.1  christos   else
    190  1.1  christos     {
    191  1.1  christos       for (i = 0; i < F77_DIM_SIZE (nss) && (*elts) < options->print_max;
    192  1.1  christos 	   i++, (*elts)++)
    193  1.1  christos 	{
    194  1.1  christos 	  val_print (TYPE_TARGET_TYPE (type),
    195  1.1  christos 		     valaddr,
    196  1.1  christos 		     embedded_offset + i * F77_DIM_OFFSET (ndimensions),
    197  1.1  christos 		     address, stream, recurse,
    198  1.1  christos 		     val, options, current_language);
    199  1.1  christos 
    200  1.1  christos 	  if (i != (F77_DIM_SIZE (nss) - 1))
    201  1.1  christos 	    fprintf_filtered (stream, ", ");
    202  1.1  christos 
    203  1.1  christos 	  if ((*elts == options->print_max - 1)
    204  1.1  christos 	      && (i != (F77_DIM_SIZE (nss) - 1)))
    205  1.1  christos 	    fprintf_filtered (stream, "...");
    206  1.1  christos 	}
    207  1.1  christos     }
    208  1.1  christos }
    209  1.1  christos 
    210  1.1  christos /* This function gets called to print an F77 array, we set up some
    211  1.1  christos    stuff and then immediately call f77_print_array_1().  */
    212  1.1  christos 
    213  1.1  christos static void
    214  1.1  christos f77_print_array (struct type *type, const gdb_byte *valaddr,
    215  1.1  christos 		 int embedded_offset,
    216  1.1  christos 		 CORE_ADDR address, struct ui_file *stream,
    217  1.1  christos 		 int recurse,
    218  1.1  christos 		 const struct value *val,
    219  1.1  christos 		 const struct value_print_options *options)
    220  1.1  christos {
    221  1.1  christos   int ndimensions;
    222  1.1  christos   int elts = 0;
    223  1.1  christos 
    224  1.1  christos   ndimensions = calc_f77_array_dims (type);
    225  1.1  christos 
    226  1.1  christos   if (ndimensions > MAX_FORTRAN_DIMS || ndimensions < 0)
    227  1.1  christos     error (_("\
    228  1.1  christos Type node corrupt! F77 arrays cannot have %d subscripts (%d Max)"),
    229  1.1  christos 	   ndimensions, MAX_FORTRAN_DIMS);
    230  1.1  christos 
    231  1.1  christos   /* Since F77 arrays are stored column-major, we set up an
    232  1.1  christos      offset table to get at the various row's elements.  The
    233  1.1  christos      offset table contains entries for both offset and subarray size.  */
    234  1.1  christos 
    235  1.1  christos   f77_create_arrayprint_offset_tbl (type, stream);
    236  1.1  christos 
    237  1.1  christos   f77_print_array_1 (1, ndimensions, type, valaddr, embedded_offset,
    238  1.1  christos 		     address, stream, recurse, val, options, &elts);
    239  1.1  christos }
    240  1.1  christos 
    241  1.1  christos 
    243  1.1  christos /* Decorations for Fortran.  */
    244  1.1  christos 
    245  1.1  christos static const struct generic_val_print_decorations f_decorations =
    246  1.1  christos {
    247  1.1  christos   "(",
    248  1.1  christos   ",",
    249  1.1  christos   ")",
    250  1.1  christos   ".TRUE.",
    251  1.1  christos   ".FALSE.",
    252  1.1  christos   "VOID",
    253  1.1  christos };
    254  1.1  christos 
    255  1.1  christos /* See val_print for a description of the various parameters of this
    256  1.1  christos    function; they are identical.  */
    257  1.1  christos 
    258  1.1  christos void
    259  1.1  christos f_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
    260  1.1  christos 	     CORE_ADDR address, struct ui_file *stream, int recurse,
    261  1.1  christos 	     const struct value *original_value,
    262  1.1  christos 	     const struct value_print_options *options)
    263  1.1  christos {
    264  1.1  christos   struct gdbarch *gdbarch = get_type_arch (type);
    265  1.1  christos   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
    266  1.1  christos   unsigned int i = 0;	/* Number of characters printed.  */
    267  1.1  christos   struct type *elttype;
    268  1.1  christos   CORE_ADDR addr;
    269  1.1  christos   int index;
    270  1.1  christos 
    271  1.1  christos   CHECK_TYPEDEF (type);
    272  1.1  christos   switch (TYPE_CODE (type))
    273  1.1  christos     {
    274  1.1  christos     case TYPE_CODE_STRING:
    275  1.1  christos       f77_get_dynamic_length_of_aggregate (type);
    276  1.1  christos       LA_PRINT_STRING (stream, builtin_type (gdbarch)->builtin_char,
    277  1.1  christos 		       valaddr + embedded_offset,
    278  1.1  christos 		       TYPE_LENGTH (type), NULL, 0, options);
    279  1.1  christos       break;
    280  1.1  christos 
    281  1.1  christos     case TYPE_CODE_ARRAY:
    282  1.1  christos       if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_CHAR)
    283  1.1  christos 	{
    284  1.1  christos 	  fprintf_filtered (stream, "(");
    285  1.1  christos 	  f77_print_array (type, valaddr, embedded_offset,
    286  1.1  christos 			   address, stream, recurse, original_value, options);
    287  1.1  christos 	  fprintf_filtered (stream, ")");
    288  1.1  christos 	}
    289  1.1  christos       else
    290  1.1  christos 	{
    291  1.1  christos 	  struct type *ch_type = TYPE_TARGET_TYPE (type);
    292  1.1  christos 
    293  1.1  christos 	  f77_get_dynamic_length_of_aggregate (type);
    294  1.1  christos 	  LA_PRINT_STRING (stream, ch_type,
    295  1.1  christos 			   valaddr + embedded_offset,
    296  1.1  christos 			   TYPE_LENGTH (type) / TYPE_LENGTH (ch_type),
    297  1.1  christos 			   NULL, 0, options);
    298  1.1  christos 	}
    299  1.1  christos       break;
    300  1.1  christos 
    301  1.1  christos     case TYPE_CODE_PTR:
    302  1.1  christos       if (options->format && options->format != 's')
    303  1.1  christos 	{
    304  1.1  christos 	  val_print_scalar_formatted (type, valaddr, embedded_offset,
    305  1.1  christos 				      original_value, options, 0, stream);
    306  1.1  christos 	  break;
    307  1.1  christos 	}
    308  1.1  christos       else
    309  1.1  christos 	{
    310  1.1  christos 	  int want_space = 0;
    311  1.1  christos 
    312  1.1  christos 	  addr = unpack_pointer (type, valaddr + embedded_offset);
    313  1.1  christos 	  elttype = check_typedef (TYPE_TARGET_TYPE (type));
    314  1.1  christos 
    315  1.1  christos 	  if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
    316  1.1  christos 	    {
    317  1.1  christos 	      /* Try to print what function it points to.  */
    318  1.1  christos 	      print_function_pointer_address (options, gdbarch, addr, stream);
    319  1.1  christos 	      return;
    320  1.1  christos 	    }
    321  1.1  christos 
    322  1.1  christos 	  if (options->symbol_print)
    323  1.1  christos 	    want_space = print_address_demangle (options, gdbarch, addr,
    324  1.1  christos 						 stream, demangle);
    325  1.1  christos 	  else if (options->addressprint && options->format != 's')
    326  1.1  christos 	    {
    327  1.1  christos 	      fputs_filtered (paddress (gdbarch, addr), stream);
    328  1.1  christos 	      want_space = 1;
    329  1.1  christos 	    }
    330  1.1  christos 
    331  1.1  christos 	  /* For a pointer to char or unsigned char, also print the string
    332  1.1  christos 	     pointed to, unless pointer is null.  */
    333  1.1  christos 	  if (TYPE_LENGTH (elttype) == 1
    334  1.1  christos 	      && TYPE_CODE (elttype) == TYPE_CODE_INT
    335  1.1  christos 	      && (options->format == 0 || options->format == 's')
    336  1.1  christos 	      && addr != 0)
    337  1.1  christos 	    {
    338  1.1  christos 	      if (want_space)
    339  1.1  christos 		fputs_filtered (" ", stream);
    340  1.1  christos 	      i = val_print_string (TYPE_TARGET_TYPE (type), NULL, addr, -1,
    341  1.1  christos 				    stream, options);
    342  1.1  christos 	    }
    343  1.1  christos 	  return;
    344  1.1  christos 	}
    345  1.1  christos       break;
    346  1.1  christos 
    347  1.1  christos     case TYPE_CODE_INT:
    348  1.1  christos       if (options->format || options->output_format)
    349  1.1  christos 	{
    350  1.1  christos 	  struct value_print_options opts = *options;
    351  1.1  christos 
    352  1.1  christos 	  opts.format = (options->format ? options->format
    353  1.1  christos 			 : options->output_format);
    354  1.1  christos 	  val_print_scalar_formatted (type, valaddr, embedded_offset,
    355  1.1  christos 				      original_value, options, 0, stream);
    356  1.1  christos 	}
    357  1.1  christos       else
    358  1.1  christos 	{
    359  1.1  christos 	  val_print_type_code_int (type, valaddr + embedded_offset, stream);
    360  1.1  christos 	  /* C and C++ has no single byte int type, char is used instead.
    361  1.1  christos 	     Since we don't know whether the value is really intended to
    362  1.1  christos 	     be used as an integer or a character, print the character
    363  1.1  christos 	     equivalent as well.  */
    364  1.1  christos 	  if (TYPE_LENGTH (type) == 1)
    365  1.1  christos 	    {
    366  1.1  christos 	      LONGEST c;
    367  1.1  christos 
    368  1.1  christos 	      fputs_filtered (" ", stream);
    369  1.1  christos 	      c = unpack_long (type, valaddr + embedded_offset);
    370  1.1  christos 	      LA_PRINT_CHAR ((unsigned char) c, type, stream);
    371  1.1  christos 	    }
    372  1.1  christos 	}
    373  1.1  christos       break;
    374  1.1  christos 
    375  1.1  christos     case TYPE_CODE_STRUCT:
    376  1.1  christos     case TYPE_CODE_UNION:
    377  1.1  christos       /* Starting from the Fortran 90 standard, Fortran supports derived
    378  1.1  christos          types.  */
    379  1.1  christos       fprintf_filtered (stream, "( ");
    380  1.1  christos       for (index = 0; index < TYPE_NFIELDS (type); index++)
    381  1.1  christos         {
    382  1.1  christos           int offset = TYPE_FIELD_BITPOS (type, index) / 8;
    383  1.1  christos 
    384  1.1  christos           val_print (TYPE_FIELD_TYPE (type, index), valaddr,
    385  1.1  christos 		     embedded_offset + offset,
    386  1.1  christos 		     address, stream, recurse + 1,
    387  1.1  christos 		     original_value, options, current_language);
    388  1.1  christos           if (index != TYPE_NFIELDS (type) - 1)
    389  1.1  christos             fputs_filtered (", ", stream);
    390  1.1  christos         }
    391  1.1  christos       fprintf_filtered (stream, " )");
    392  1.1  christos       break;
    393  1.1  christos 
    394  1.1  christos     case TYPE_CODE_REF:
    395  1.1  christos     case TYPE_CODE_FUNC:
    396  1.1  christos     case TYPE_CODE_FLAGS:
    397  1.1  christos     case TYPE_CODE_FLT:
    398  1.1  christos     case TYPE_CODE_VOID:
    399  1.1  christos     case TYPE_CODE_ERROR:
    400  1.1  christos     case TYPE_CODE_RANGE:
    401  1.1  christos     case TYPE_CODE_UNDEF:
    402  1.1  christos     case TYPE_CODE_COMPLEX:
    403  1.1  christos     case TYPE_CODE_BOOL:
    404  1.1  christos     case TYPE_CODE_CHAR:
    405  1.1  christos     default:
    406  1.1  christos       generic_val_print (type, valaddr, embedded_offset, address,
    407  1.1  christos 			 stream, recurse, original_value, options,
    408  1.1  christos 			 &f_decorations);
    409  1.1  christos       break;
    410  1.1  christos     }
    411  1.1  christos   gdb_flush (stream);
    412  1.1  christos }
    413  1.1  christos 
    414  1.1  christos static void
    415  1.1  christos info_common_command_for_block (struct block *block, const char *comname,
    416  1.1  christos 			       int *any_printed)
    417  1.1  christos {
    418  1.1  christos   struct block_iterator iter;
    419  1.1  christos   struct symbol *sym;
    420  1.1  christos   const char *name;
    421  1.1  christos   struct value_print_options opts;
    422  1.1  christos 
    423  1.1  christos   get_user_print_options (&opts);
    424  1.1  christos 
    425  1.1  christos   ALL_BLOCK_SYMBOLS (block, iter, sym)
    426  1.1  christos     if (SYMBOL_DOMAIN (sym) == COMMON_BLOCK_DOMAIN)
    427  1.1  christos       {
    428  1.1  christos 	struct common_block *common = SYMBOL_VALUE_COMMON_BLOCK (sym);
    429  1.1  christos 	size_t index;
    430  1.1  christos 
    431  1.1  christos 	gdb_assert (SYMBOL_CLASS (sym) == LOC_COMMON_BLOCK);
    432  1.1  christos 
    433  1.1  christos 	if (comname && (!SYMBOL_LINKAGE_NAME (sym)
    434  1.1  christos 	                || strcmp (comname, SYMBOL_LINKAGE_NAME (sym)) != 0))
    435  1.1  christos 	  continue;
    436  1.1  christos 
    437  1.1  christos 	if (*any_printed)
    438  1.1  christos 	  putchar_filtered ('\n');
    439  1.1  christos 	else
    440  1.1  christos 	  *any_printed = 1;
    441  1.1  christos 	if (SYMBOL_PRINT_NAME (sym))
    442  1.1  christos 	  printf_filtered (_("Contents of F77 COMMON block '%s':\n"),
    443  1.1  christos 			   SYMBOL_PRINT_NAME (sym));
    444  1.1  christos 	else
    445  1.1  christos 	  printf_filtered (_("Contents of blank COMMON block:\n"));
    446  1.1  christos 
    447  1.1  christos 	for (index = 0; index < common->n_entries; index++)
    448  1.1  christos 	  {
    449  1.1  christos 	    struct value *val = NULL;
    450  1.1  christos 	    volatile struct gdb_exception except;
    451  1.1  christos 
    452  1.1  christos 	    printf_filtered ("%s = ",
    453  1.1  christos 			     SYMBOL_PRINT_NAME (common->contents[index]));
    454  1.1  christos 
    455  1.1  christos 	    TRY_CATCH (except, RETURN_MASK_ERROR)
    456  1.1  christos 	      {
    457  1.1  christos 		val = value_of_variable (common->contents[index], block);
    458  1.1  christos 		value_print (val, gdb_stdout, &opts);
    459  1.1  christos 	      }
    460  1.1  christos 
    461  1.1  christos 	    if (except.reason < 0)
    462  1.1  christos 	      printf_filtered ("<error reading variable: %s>", except.message);
    463  1.1  christos 	    putchar_filtered ('\n');
    464  1.1  christos 	  }
    465  1.1  christos       }
    466  1.1  christos }
    467  1.1  christos 
    468  1.1  christos /* This function is used to print out the values in a given COMMON
    469  1.1  christos    block.  It will always use the most local common block of the
    470  1.1  christos    given name.  */
    471  1.1  christos 
    472  1.1  christos static void
    473  1.1  christos info_common_command (char *comname, int from_tty)
    474  1.1  christos {
    475  1.1  christos   struct frame_info *fi;
    476  1.1  christos   struct block *block;
    477  1.1  christos   int values_printed = 0;
    478  1.1  christos 
    479  1.1  christos   /* We have been told to display the contents of F77 COMMON
    480  1.1  christos      block supposedly visible in this function.  Let us
    481  1.1  christos      first make sure that it is visible and if so, let
    482  1.1  christos      us display its contents.  */
    483  1.1  christos 
    484  1.1  christos   fi = get_selected_frame (_("No frame selected"));
    485  1.1  christos 
    486  1.1  christos   /* The following is generally ripped off from stack.c's routine
    487  1.1  christos      print_frame_info().  */
    488  1.1  christos 
    489  1.1  christos   block = get_frame_block (fi, 0);
    490  1.1  christos   if (block == NULL)
    491  1.1  christos     {
    492  1.1  christos       printf_filtered (_("No symbol table info available.\n"));
    493  1.1  christos       return;
    494  1.1  christos     }
    495  1.1  christos 
    496  1.1  christos   while (block)
    497  1.1  christos     {
    498  1.1  christos       info_common_command_for_block (block, comname, &values_printed);
    499  1.1  christos       /* After handling the function's top-level block, stop.  Don't
    500  1.1  christos          continue to its superblock, the block of per-file symbols.  */
    501  1.1  christos       if (BLOCK_FUNCTION (block))
    502  1.1  christos 	break;
    503  1.1  christos       block = BLOCK_SUPERBLOCK (block);
    504  1.1  christos     }
    505  1.1  christos 
    506  1.1  christos   if (!values_printed)
    507  1.1  christos     {
    508  1.1  christos       if (comname)
    509  1.1  christos 	printf_filtered (_("No common block '%s'.\n"), comname);
    510  1.1  christos       else
    511  1.1  christos 	printf_filtered (_("No common blocks.\n"));
    512  1.1  christos     }
    513  1.1  christos }
    514  1.1  christos 
    515  1.1  christos void
    516  1.1  christos _initialize_f_valprint (void)
    517  1.1  christos {
    518  1.1  christos   add_info ("common", info_common_command,
    519  1.1  christos 	    _("Print out the values contained in a Fortran COMMON block."));
    520  1.1  christos   if (xdb_commands)
    521  1.1  christos     add_com ("lc", class_info, info_common_command,
    522  1.1  christos 	     _("Print out the values contained in a Fortran COMMON block."));
    523                }
    524