2010-11-19 Jan Kratochvil <jan.kratochvil@redhat.com>
[deliverable/binutils-gdb.git] / gdb / f-valprint.c
CommitLineData
c906108c 1/* Support for printing Fortran values for GDB, the GNU debugger.
a2bd3dcd 2
6aba47ca 3 Copyright (C) 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2003, 2005, 2006,
4c38e0a4 4 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
a2bd3dcd 5
c906108c
SS
6 Contributed by Motorola. Adapted from the C definitions by Farooq Butt
7 (fmbutt@engage.sps.mot.com), additionally worked over by Stan Shebs.
8
c5aa993b 9 This file is part of GDB.
c906108c 10
c5aa993b
JM
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
a9762ec7 13 the Free Software Foundation; either version 3 of the License, or
c5aa993b 14 (at your option) any later version.
c906108c 15
c5aa993b
JM
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
c906108c 20
c5aa993b 21 You should have received a copy of the GNU General Public License
a9762ec7 22 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c
SS
23
24#include "defs.h"
25#include "gdb_string.h"
26#include "symtab.h"
27#include "gdbtypes.h"
28#include "expression.h"
29#include "value.h"
c906108c
SS
30#include "valprint.h"
31#include "language.h"
c5aa993b 32#include "f-lang.h"
c906108c
SS
33#include "frame.h"
34#include "gdbcore.h"
35#include "command.h"
fe898f56 36#include "block.h"
c906108c
SS
37
38#if 0
a14ed312 39static int there_is_a_visible_common_named (char *);
c906108c
SS
40#endif
41
a14ed312
KB
42extern void _initialize_f_valprint (void);
43static void info_common_command (char *, int);
44static void list_all_visible_commons (char *);
d9fcf2fb
JM
45static void f77_create_arrayprint_offset_tbl (struct type *,
46 struct ui_file *);
a14ed312 47static void f77_get_dynamic_length_of_aggregate (struct type *);
c906108c 48
c5aa993b 49int f77_array_offset_tbl[MAX_FORTRAN_DIMS + 1][2];
c906108c
SS
50
51/* Array which holds offsets to be applied to get a row's elements
52 for a given array. Array also holds the size of each subarray. */
53
54/* The following macro gives us the size of the nth dimension, Where
c5aa993b 55 n is 1 based. */
c906108c
SS
56
57#define F77_DIM_SIZE(n) (f77_array_offset_tbl[n][1])
58
c5aa993b 59/* The following gives us the offset for row n where n is 1-based. */
c906108c
SS
60
61#define F77_DIM_OFFSET(n) (f77_array_offset_tbl[n][0])
62
c5aa993b 63int
d78df370 64f77_get_lowerbound (struct type *type)
c906108c 65{
d78df370
JK
66 if (TYPE_ARRAY_LOWER_BOUND_IS_UNDEFINED (type))
67 error (_("Lower bound may not be '*' in F77"));
c5aa993b 68
d78df370 69 return TYPE_ARRAY_LOWER_BOUND_VALUE (type);
c906108c
SS
70}
71
c5aa993b 72int
d78df370 73f77_get_upperbound (struct type *type)
c906108c 74{
d78df370 75 if (TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))
c906108c 76 {
d78df370
JK
77 /* We have an assumed size array on our hands. Assume that
78 upper_bound == lower_bound so that we show at least 1 element.
79 If the user wants to see more elements, let him manually ask for 'em
80 and we'll subscript the array and show him. */
81
82 return f77_get_lowerbound (type);
c906108c 83 }
d78df370
JK
84
85 return TYPE_ARRAY_UPPER_BOUND_VALUE (type);
c906108c
SS
86}
87
c5aa993b 88/* Obtain F77 adjustable array dimensions */
c906108c
SS
89
90static void
fba45db2 91f77_get_dynamic_length_of_aggregate (struct type *type)
c906108c
SS
92{
93 int upper_bound = -1;
c5aa993b 94 int lower_bound = 1;
c5aa993b 95
c906108c
SS
96 /* Recursively go all the way down into a possibly multi-dimensional
97 F77 array and get the bounds. For simple arrays, this is pretty
98 easy but when the bounds are dynamic, we must be very careful
99 to add up all the lengths correctly. Not doing this right
100 will lead to horrendous-looking arrays in parameter lists.
c5aa993b 101
c906108c 102 This function also works for strings which behave very
c5aa993b
JM
103 similarly to arrays. */
104
105 if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_ARRAY
106 || TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_STRING)
c906108c 107 f77_get_dynamic_length_of_aggregate (TYPE_TARGET_TYPE (type));
c5aa993b
JM
108
109 /* Recursion ends here, start setting up lengths. */
d78df370
JK
110 lower_bound = f77_get_lowerbound (type);
111 upper_bound = f77_get_upperbound (type);
c5aa993b
JM
112
113 /* Patch in a valid length value. */
114
c906108c
SS
115 TYPE_LENGTH (type) =
116 (upper_bound - lower_bound + 1) * TYPE_LENGTH (check_typedef (TYPE_TARGET_TYPE (type)));
c5aa993b 117}
c906108c
SS
118
119/* Function that sets up the array offset,size table for the array
c5aa993b 120 type "type". */
c906108c 121
c5aa993b 122static void
fba45db2 123f77_create_arrayprint_offset_tbl (struct type *type, struct ui_file *stream)
c906108c
SS
124{
125 struct type *tmp_type;
126 int eltlen;
127 int ndimen = 1;
9216103f 128 int upper, lower;
c5aa993b
JM
129
130 tmp_type = type;
131
132 while ((TYPE_CODE (tmp_type) == TYPE_CODE_ARRAY))
c906108c 133 {
d78df370
JK
134 upper = f77_get_upperbound (tmp_type);
135 lower = f77_get_lowerbound (tmp_type);
c5aa993b 136
c906108c 137 F77_DIM_SIZE (ndimen) = upper - lower + 1;
c5aa993b 138
c906108c 139 tmp_type = TYPE_TARGET_TYPE (tmp_type);
c5aa993b 140 ndimen++;
c906108c 141 }
c5aa993b 142
c906108c
SS
143 /* Now we multiply eltlen by all the offsets, so that later we
144 can print out array elements correctly. Up till now we
145 know an offset to apply to get the item but we also
146 have to know how much to add to get to the next item */
c5aa993b 147
c906108c 148 ndimen--;
c5aa993b 149 eltlen = TYPE_LENGTH (tmp_type);
c906108c
SS
150 F77_DIM_OFFSET (ndimen) = eltlen;
151 while (--ndimen > 0)
152 {
153 eltlen *= F77_DIM_SIZE (ndimen + 1);
154 F77_DIM_OFFSET (ndimen) = eltlen;
155 }
156}
157
b3cacbee
DL
158
159
c906108c
SS
160/* Actual function which prints out F77 arrays, Valaddr == address in
161 the superior. Address == the address in the inferior. */
7b0090c3 162
c5aa993b 163static void
a2bd3dcd 164f77_print_array_1 (int nss, int ndimensions, struct type *type,
fc1a4b47 165 const gdb_byte *valaddr, CORE_ADDR address,
79a45b7d 166 struct ui_file *stream, int recurse,
0e03807e 167 const struct value *val,
79a45b7d 168 const struct value_print_options *options,
b3cacbee 169 int *elts)
c906108c
SS
170{
171 int i;
c5aa993b 172
c906108c
SS
173 if (nss != ndimensions)
174 {
79a45b7d 175 for (i = 0; (i < F77_DIM_SIZE (nss) && (*elts) < options->print_max); i++)
c906108c
SS
176 {
177 fprintf_filtered (stream, "( ");
178 f77_print_array_1 (nss + 1, ndimensions, TYPE_TARGET_TYPE (type),
c5aa993b
JM
179 valaddr + i * F77_DIM_OFFSET (nss),
180 address + i * F77_DIM_OFFSET (nss),
0e03807e 181 stream, recurse, val, options, elts);
c906108c
SS
182 fprintf_filtered (stream, ") ");
183 }
79a45b7d 184 if (*elts >= options->print_max && i < F77_DIM_SIZE (nss))
b3cacbee 185 fprintf_filtered (stream, "...");
c906108c
SS
186 }
187 else
188 {
79a45b7d 189 for (i = 0; i < F77_DIM_SIZE (nss) && (*elts) < options->print_max;
7b0090c3 190 i++, (*elts)++)
c906108c
SS
191 {
192 val_print (TYPE_TARGET_TYPE (type),
193 valaddr + i * F77_DIM_OFFSET (ndimensions),
c5aa993b 194 0,
c906108c 195 address + i * F77_DIM_OFFSET (ndimensions),
0e03807e 196 stream, recurse, val, options, current_language);
c906108c
SS
197
198 if (i != (F77_DIM_SIZE (nss) - 1))
c5aa993b
JM
199 fprintf_filtered (stream, ", ");
200
79a45b7d
TT
201 if ((*elts == options->print_max - 1)
202 && (i != (F77_DIM_SIZE (nss) - 1)))
c906108c
SS
203 fprintf_filtered (stream, "...");
204 }
205 }
206}
207
208/* This function gets called to print an F77 array, we set up some
209 stuff and then immediately call f77_print_array_1() */
210
c5aa993b 211static void
fc1a4b47 212f77_print_array (struct type *type, const gdb_byte *valaddr,
a2bd3dcd 213 CORE_ADDR address, struct ui_file *stream,
0e03807e
TT
214 int recurse,
215 const struct value *val,
216 const struct value_print_options *options)
c906108c 217{
c5aa993b 218 int ndimensions;
b3cacbee 219 int elts = 0;
c5aa993b
JM
220
221 ndimensions = calc_f77_array_dims (type);
222
c906108c 223 if (ndimensions > MAX_FORTRAN_DIMS || ndimensions < 0)
8a3fe4f8 224 error (_("Type node corrupt! F77 arrays cannot have %d subscripts (%d Max)"),
c906108c 225 ndimensions, MAX_FORTRAN_DIMS);
c5aa993b 226
c906108c
SS
227 /* Since F77 arrays are stored column-major, we set up an
228 offset table to get at the various row's elements. The
c5aa993b 229 offset table contains entries for both offset and subarray size. */
c906108c 230
c5aa993b
JM
231 f77_create_arrayprint_offset_tbl (type, stream);
232
79a45b7d 233 f77_print_array_1 (1, ndimensions, type, valaddr, address, stream,
0e03807e 234 recurse, val, options, &elts);
c5aa993b 235}
c906108c 236\f
c5aa993b 237
c906108c
SS
238/* Print data of type TYPE located at VALADDR (within GDB), which came from
239 the inferior at address ADDRESS, onto stdio stream STREAM according to
79a45b7d 240 OPTIONS. The data at VALADDR is in target byte order.
c5aa993b 241
c906108c 242 If the data are a string pointer, returns the number of string characters
79a45b7d 243 printed. */
c906108c
SS
244
245int
fc1a4b47 246f_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
79a45b7d 247 CORE_ADDR address, struct ui_file *stream, int recurse,
0e03807e 248 const struct value *original_value,
79a45b7d 249 const struct value_print_options *options)
c906108c 250{
50810684 251 struct gdbarch *gdbarch = get_type_arch (type);
e17a4113 252 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
52f0bd74 253 unsigned int i = 0; /* Number of characters printed */
c906108c
SS
254 struct type *elttype;
255 LONGEST val;
256 CORE_ADDR addr;
2a5e440c 257 int index;
c5aa993b 258
c906108c
SS
259 CHECK_TYPEDEF (type);
260 switch (TYPE_CODE (type))
261 {
c5aa993b 262 case TYPE_CODE_STRING:
c906108c 263 f77_get_dynamic_length_of_aggregate (type);
50810684 264 LA_PRINT_STRING (stream, builtin_type (gdbarch)->builtin_char,
be759fcf 265 valaddr, TYPE_LENGTH (type), NULL, 0, options);
c906108c 266 break;
c5aa993b 267
c906108c 268 case TYPE_CODE_ARRAY:
c5aa993b 269 fprintf_filtered (stream, "(");
0e03807e 270 f77_print_array (type, valaddr, address, stream, recurse, original_value, options);
c906108c
SS
271 fprintf_filtered (stream, ")");
272 break;
7e86466e 273
c906108c 274 case TYPE_CODE_PTR:
79a45b7d 275 if (options->format && options->format != 's')
c906108c 276 {
79a45b7d 277 print_scalar_formatted (valaddr, type, options, 0, stream);
c906108c
SS
278 break;
279 }
280 else
281 {
282 addr = unpack_pointer (type, valaddr);
283 elttype = check_typedef (TYPE_TARGET_TYPE (type));
c5aa993b 284
c906108c
SS
285 if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
286 {
287 /* Try to print what function it points to. */
5af949e3 288 print_address_demangle (gdbarch, addr, stream, demangle);
c906108c
SS
289 /* Return value is irrelevant except for string pointers. */
290 return 0;
291 }
c5aa993b 292
79a45b7d 293 if (options->addressprint && options->format != 's')
5af949e3 294 fputs_filtered (paddress (gdbarch, addr), stream);
c5aa993b 295
c906108c
SS
296 /* For a pointer to char or unsigned char, also print the string
297 pointed to, unless pointer is null. */
298 if (TYPE_LENGTH (elttype) == 1
299 && TYPE_CODE (elttype) == TYPE_CODE_INT
79a45b7d 300 && (options->format == 0 || options->format == 's')
c906108c 301 && addr != 0)
09ca9e2e
TT
302 i = val_print_string (TYPE_TARGET_TYPE (type), NULL, addr, -1,
303 stream, options);
c5aa993b 304
7e86466e
RH
305 /* Return number of characters printed, including the terminating
306 '\0' if we reached the end. val_print_string takes care including
307 the terminating '\0' if necessary. */
308 return i;
309 }
310 break;
311
312 case TYPE_CODE_REF:
313 elttype = check_typedef (TYPE_TARGET_TYPE (type));
79a45b7d 314 if (options->addressprint)
7e86466e
RH
315 {
316 CORE_ADDR addr
317 = extract_typed_address (valaddr + embedded_offset, type);
bb9bcb69 318
7e86466e 319 fprintf_filtered (stream, "@");
5af949e3 320 fputs_filtered (paddress (gdbarch, addr), stream);
79a45b7d 321 if (options->deref_ref)
7e86466e
RH
322 fputs_filtered (": ", stream);
323 }
324 /* De-reference the reference. */
79a45b7d 325 if (options->deref_ref)
7e86466e
RH
326 {
327 if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF)
328 {
329 struct value *deref_val =
bb9bcb69
MS
330 value_at
331 (TYPE_TARGET_TYPE (type),
332 unpack_pointer (type, valaddr + embedded_offset));
333
79a45b7d
TT
334 common_val_print (deref_val, stream, recurse,
335 options, current_language);
7e86466e
RH
336 }
337 else
338 fputs_filtered ("???", stream);
c906108c
SS
339 }
340 break;
c5aa993b 341
c906108c 342 case TYPE_CODE_FUNC:
79a45b7d 343 if (options->format)
c906108c 344 {
79a45b7d 345 print_scalar_formatted (valaddr, type, options, 0, stream);
c906108c
SS
346 break;
347 }
348 /* FIXME, we should consider, at least for ANSI C language, eliminating
c5aa993b 349 the distinction made between FUNCs and POINTERs to FUNCs. */
c906108c
SS
350 fprintf_filtered (stream, "{");
351 type_print (type, "", stream, -1);
352 fprintf_filtered (stream, "} ");
353 /* Try to print what function it points to, and its address. */
5af949e3 354 print_address_demangle (gdbarch, address, stream, demangle);
c906108c 355 break;
c5aa993b 356
c906108c 357 case TYPE_CODE_INT:
79a45b7d
TT
358 if (options->format || options->output_format)
359 {
360 struct value_print_options opts = *options;
bb9bcb69 361
79a45b7d
TT
362 opts.format = (options->format ? options->format
363 : options->output_format);
364 print_scalar_formatted (valaddr, type, &opts, 0, stream);
365 }
c906108c
SS
366 else
367 {
368 val_print_type_code_int (type, valaddr, stream);
369 /* C and C++ has no single byte int type, char is used instead.
370 Since we don't know whether the value is really intended to
371 be used as an integer or a character, print the character
372 equivalent as well. */
373 if (TYPE_LENGTH (type) == 1)
374 {
375 fputs_filtered (" ", stream);
376 LA_PRINT_CHAR ((unsigned char) unpack_long (type, valaddr),
6c7a06a3 377 type, stream);
c906108c
SS
378 }
379 }
380 break;
c5aa993b 381
4f2aea11 382 case TYPE_CODE_FLAGS:
79a45b7d
TT
383 if (options->format)
384 print_scalar_formatted (valaddr, type, options, 0, stream);
4f2aea11
MK
385 else
386 val_print_type_code_flags (type, valaddr, stream);
387 break;
388
c906108c 389 case TYPE_CODE_FLT:
79a45b7d
TT
390 if (options->format)
391 print_scalar_formatted (valaddr, type, options, 0, stream);
c906108c
SS
392 else
393 print_floating (valaddr, type, stream);
394 break;
c5aa993b 395
c906108c
SS
396 case TYPE_CODE_VOID:
397 fprintf_filtered (stream, "VOID");
398 break;
c5aa993b 399
c906108c 400 case TYPE_CODE_ERROR:
b00fdb78 401 fprintf_filtered (stream, "%s", TYPE_ERROR_NAME (type));
c906108c 402 break;
c5aa993b 403
c906108c
SS
404 case TYPE_CODE_RANGE:
405 /* FIXME, we should not ever have to print one of these yet. */
406 fprintf_filtered (stream, "<range type>");
407 break;
c5aa993b 408
c906108c 409 case TYPE_CODE_BOOL:
79a45b7d
TT
410 if (options->format || options->output_format)
411 {
412 struct value_print_options opts = *options;
bb9bcb69 413
79a45b7d
TT
414 opts.format = (options->format ? options->format
415 : options->output_format);
416 print_scalar_formatted (valaddr, type, &opts, 0, stream);
417 }
c906108c
SS
418 else
419 {
e17a4113
UW
420 val = extract_unsigned_integer (valaddr,
421 TYPE_LENGTH (type), byte_order);
c5aa993b 422 if (val == 0)
c906108c 423 fprintf_filtered (stream, ".FALSE.");
c5aa993b
JM
424 else if (val == 1)
425 fprintf_filtered (stream, ".TRUE.");
426 else
427 /* Not a legitimate logical type, print as an integer. */
428 {
429 /* Bash the type code temporarily. */
430 TYPE_CODE (type) = TYPE_CODE_INT;
0e03807e
TT
431 val_print (type, valaddr, 0, address, stream, recurse,
432 original_value, options, current_language);
c5aa993b
JM
433 /* Restore the type code so later uses work as intended. */
434 TYPE_CODE (type) = TYPE_CODE_BOOL;
435 }
c906108c
SS
436 }
437 break;
c5aa993b 438
c906108c 439 case TYPE_CODE_COMPLEX:
b806fb9a 440 type = TYPE_TARGET_TYPE (type);
c906108c
SS
441 fputs_filtered ("(", stream);
442 print_floating (valaddr, type, stream);
443 fputs_filtered (",", stream);
9af97293 444 print_floating (valaddr + TYPE_LENGTH (type), type, stream);
c906108c
SS
445 fputs_filtered (")", stream);
446 break;
c5aa993b 447
c906108c
SS
448 case TYPE_CODE_UNDEF:
449 /* This happens (without TYPE_FLAG_STUB set) on systems which don't use
c5aa993b
JM
450 dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar"
451 and no complete type for struct foo in that file. */
c906108c
SS
452 fprintf_filtered (stream, "<incomplete type>");
453 break;
c5aa993b 454
2a5e440c 455 case TYPE_CODE_STRUCT:
9eec4d1e 456 case TYPE_CODE_UNION:
2a5e440c
WZ
457 /* Starting from the Fortran 90 standard, Fortran supports derived
458 types. */
9eec4d1e 459 fprintf_filtered (stream, "( ");
2a5e440c
WZ
460 for (index = 0; index < TYPE_NFIELDS (type); index++)
461 {
462 int offset = TYPE_FIELD_BITPOS (type, index) / 8;
bb9bcb69 463
0e03807e
TT
464 val_print (TYPE_FIELD_TYPE (type, index), valaddr + offset,
465 embedded_offset, address, stream, recurse + 1,
466 original_value, options, current_language);
2a5e440c
WZ
467 if (index != TYPE_NFIELDS (type) - 1)
468 fputs_filtered (", ", stream);
469 }
9eec4d1e 470 fprintf_filtered (stream, " )");
2a5e440c
WZ
471 break;
472
c906108c 473 default:
8a3fe4f8 474 error (_("Invalid F77 type code %d in symbol table."), TYPE_CODE (type));
c906108c
SS
475 }
476 gdb_flush (stream);
477 return 0;
478}
479
480static void
fba45db2 481list_all_visible_commons (char *funname)
c906108c 482{
c5aa993b
JM
483 SAVED_F77_COMMON_PTR tmp;
484
c906108c 485 tmp = head_common_list;
c5aa993b 486
a3f17187 487 printf_filtered (_("All COMMON blocks visible at this level:\n\n"));
c5aa993b 488
c906108c
SS
489 while (tmp != NULL)
490 {
762f08a3 491 if (strcmp (tmp->owning_function, funname) == 0)
c5aa993b
JM
492 printf_filtered ("%s\n", tmp->name);
493
c906108c
SS
494 tmp = tmp->next;
495 }
496}
497
498/* This function is used to print out the values in a given COMMON
499 block. It will always use the most local common block of the
c5aa993b 500 given name */
c906108c 501
c5aa993b 502static void
fba45db2 503info_common_command (char *comname, int from_tty)
c906108c 504{
c5aa993b
JM
505 SAVED_F77_COMMON_PTR the_common;
506 COMMON_ENTRY_PTR entry;
c906108c 507 struct frame_info *fi;
52f0bd74 508 char *funname = 0;
c906108c 509 struct symbol *func;
c5aa993b 510
c906108c
SS
511 /* We have been told to display the contents of F77 COMMON
512 block supposedly visible in this function. Let us
513 first make sure that it is visible and if so, let
c5aa993b
JM
514 us display its contents */
515
206415a3 516 fi = get_selected_frame (_("No frame selected"));
c5aa993b 517
c906108c 518 /* The following is generally ripped off from stack.c's routine
c5aa993b
JM
519 print_frame_info() */
520
bdd78e62 521 func = find_pc_function (get_frame_pc (fi));
c906108c
SS
522 if (func)
523 {
524 /* In certain pathological cases, the symtabs give the wrong
c5aa993b
JM
525 function (when we are in the first function in a file which
526 is compiled without debugging symbols, the previous function
527 is compiled with debugging symbols, and the "foo.o" symbol
528 that is supposed to tell us where the file with debugging symbols
529 ends has been truncated by ar because it is longer than 15
530 characters).
531
532 So look in the minimal symbol tables as well, and if it comes
533 up with a larger address for the function use that instead.
534 I don't think this can ever cause any problems; there shouldn't
535 be any minimal symbols in the middle of a function.
536 FIXME: (Not necessarily true. What about text labels) */
537
7c6e0d48
MS
538 struct minimal_symbol *msymbol =
539 lookup_minimal_symbol_by_pc (get_frame_pc (fi));
c5aa993b 540
c906108c 541 if (msymbol != NULL
c5aa993b 542 && (SYMBOL_VALUE_ADDRESS (msymbol)
c906108c 543 > BLOCK_START (SYMBOL_BLOCK_VALUE (func))))
3567439c 544 funname = SYMBOL_LINKAGE_NAME (msymbol);
c906108c 545 else
3567439c 546 funname = SYMBOL_LINKAGE_NAME (func);
c906108c
SS
547 }
548 else
549 {
aa1ee363 550 struct minimal_symbol *msymbol =
bb9bcb69 551 lookup_minimal_symbol_by_pc (get_frame_pc (fi));
c5aa993b 552
c906108c 553 if (msymbol != NULL)
3567439c 554 funname = SYMBOL_LINKAGE_NAME (msymbol);
7c6e0d48
MS
555 else /* Got no 'funname', code below will fail. */
556 error (_("No function found for frame."));
c906108c 557 }
c5aa993b 558
c906108c 559 /* If comname is NULL, we assume the user wishes to see the
c5aa993b
JM
560 which COMMON blocks are visible here and then return */
561
c906108c
SS
562 if (comname == 0)
563 {
564 list_all_visible_commons (funname);
c5aa993b 565 return;
c906108c 566 }
c5aa993b
JM
567
568 the_common = find_common_for_function (comname, funname);
569
c906108c
SS
570 if (the_common)
571 {
762f08a3 572 if (strcmp (comname, BLANK_COMMON_NAME_LOCAL) == 0)
a3f17187 573 printf_filtered (_("Contents of blank COMMON block:\n"));
c5aa993b 574 else
a3f17187 575 printf_filtered (_("Contents of F77 COMMON block '%s':\n"), comname);
c5aa993b
JM
576
577 printf_filtered ("\n");
578 entry = the_common->entries;
579
c906108c
SS
580 while (entry != NULL)
581 {
aad95b57 582 print_variable_and_value (NULL, entry->symbol, fi, gdb_stdout, 0);
c5aa993b 583 entry = entry->next;
c906108c
SS
584 }
585 }
c5aa993b 586 else
a3f17187 587 printf_filtered (_("Cannot locate the common block %s in function '%s'\n"),
c5aa993b 588 comname, funname);
c906108c
SS
589}
590
591/* This function is used to determine whether there is a
c5aa993b 592 F77 common block visible at the current scope called 'comname'. */
c906108c
SS
593
594#if 0
595static int
fba45db2 596there_is_a_visible_common_named (char *comname)
c906108c 597{
c5aa993b 598 SAVED_F77_COMMON_PTR the_common;
c906108c 599 struct frame_info *fi;
52f0bd74 600 char *funname = 0;
c906108c 601 struct symbol *func;
c5aa993b 602
c906108c 603 if (comname == NULL)
8a3fe4f8 604 error (_("Cannot deal with NULL common name!"));
c5aa993b 605
206415a3 606 fi = get_selected_frame (_("No frame selected"));
c5aa993b 607
c906108c 608 /* The following is generally ripped off from stack.c's routine
c5aa993b
JM
609 print_frame_info() */
610
c906108c
SS
611 func = find_pc_function (fi->pc);
612 if (func)
613 {
614 /* In certain pathological cases, the symtabs give the wrong
c5aa993b
JM
615 function (when we are in the first function in a file which
616 is compiled without debugging symbols, the previous function
617 is compiled with debugging symbols, and the "foo.o" symbol
618 that is supposed to tell us where the file with debugging symbols
619 ends has been truncated by ar because it is longer than 15
620 characters).
621
622 So look in the minimal symbol tables as well, and if it comes
623 up with a larger address for the function use that instead.
624 I don't think this can ever cause any problems; there shouldn't
625 be any minimal symbols in the middle of a function.
626 FIXME: (Not necessarily true. What about text labels) */
627
c906108c 628 struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (fi->pc);
c5aa993b 629
c906108c 630 if (msymbol != NULL
c5aa993b 631 && (SYMBOL_VALUE_ADDRESS (msymbol)
c906108c 632 > BLOCK_START (SYMBOL_BLOCK_VALUE (func))))
3567439c 633 funname = SYMBOL_LINKAGE_NAME (msymbol);
c906108c 634 else
3567439c 635 funname = SYMBOL_LINKAGE_NAME (func);
c906108c
SS
636 }
637 else
638 {
aa1ee363 639 struct minimal_symbol *msymbol =
bb9bcb69 640 lookup_minimal_symbol_by_pc (fi->pc);
c5aa993b 641
c906108c 642 if (msymbol != NULL)
3567439c 643 funname = SYMBOL_LINKAGE_NAME (msymbol);
c906108c 644 }
c5aa993b
JM
645
646 the_common = find_common_for_function (comname, funname);
647
c906108c
SS
648 return (the_common ? 1 : 0);
649}
650#endif
651
652void
fba45db2 653_initialize_f_valprint (void)
c906108c
SS
654{
655 add_info ("common", info_common_command,
1bedd215 656 _("Print out the values contained in a Fortran COMMON block."));
c906108c 657 if (xdb_commands)
c5aa993b 658 add_com ("lc", class_info, info_common_command,
1bedd215 659 _("Print out the values contained in a Fortran COMMON block."));
c906108c 660}
This page took 0.868628 seconds and 4 git commands to generate.