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