*** empty log message ***
[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,
9b254dd1 4 2007, 2008 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
fba45db2 64f77_get_dynamic_lowerbound (struct type *type, int *lower_bound)
c906108c 65{
206415a3 66 struct frame_info *frame;
c5aa993b
JM
67 CORE_ADDR current_frame_addr;
68 CORE_ADDR ptr_to_lower_bound;
69
c906108c
SS
70 switch (TYPE_ARRAY_LOWER_BOUND_TYPE (type))
71 {
72 case BOUND_BY_VALUE_ON_STACK:
206415a3
DJ
73 frame = deprecated_safe_get_selected_frame ();
74 current_frame_addr = get_frame_base (frame);
c5aa993b 75 if (current_frame_addr > 0)
c906108c 76 {
c5aa993b
JM
77 *lower_bound =
78 read_memory_integer (current_frame_addr +
c906108c
SS
79 TYPE_ARRAY_LOWER_BOUND_VALUE (type),
80 4);
81 }
82 else
83 {
c5aa993b
JM
84 *lower_bound = DEFAULT_LOWER_BOUND;
85 return BOUND_FETCH_ERROR;
c906108c 86 }
c5aa993b
JM
87 break;
88
c906108c
SS
89 case BOUND_SIMPLE:
90 *lower_bound = TYPE_ARRAY_LOWER_BOUND_VALUE (type);
c5aa993b
JM
91 break;
92
93 case BOUND_CANNOT_BE_DETERMINED:
8a3fe4f8 94 error (_("Lower bound may not be '*' in F77"));
c5aa993b
JM
95 break;
96
c906108c 97 case BOUND_BY_REF_ON_STACK:
206415a3
DJ
98 frame = deprecated_safe_get_selected_frame ();
99 current_frame_addr = get_frame_base (frame);
c5aa993b 100 if (current_frame_addr > 0)
c906108c 101 {
5ed92fa8 102 struct gdbarch *arch = get_frame_arch (frame);
c5aa993b 103 ptr_to_lower_bound =
0d540cdf
KD
104 read_memory_typed_address (current_frame_addr +
105 TYPE_ARRAY_LOWER_BOUND_VALUE (type),
5ed92fa8 106 builtin_type (arch)->builtin_data_ptr);
c5aa993b 107 *lower_bound = read_memory_integer (ptr_to_lower_bound, 4);
c906108c
SS
108 }
109 else
110 {
c5aa993b
JM
111 *lower_bound = DEFAULT_LOWER_BOUND;
112 return BOUND_FETCH_ERROR;
c906108c 113 }
c5aa993b
JM
114 break;
115
116 case BOUND_BY_REF_IN_REG:
117 case BOUND_BY_VALUE_IN_REG:
118 default:
8a3fe4f8 119 error (_("??? unhandled dynamic array bound type ???"));
c5aa993b 120 break;
c906108c
SS
121 }
122 return BOUND_FETCH_OK;
123}
124
c5aa993b 125int
fba45db2 126f77_get_dynamic_upperbound (struct type *type, int *upper_bound)
c906108c 127{
206415a3 128 struct frame_info *frame;
c906108c 129 CORE_ADDR current_frame_addr = 0;
c5aa993b
JM
130 CORE_ADDR ptr_to_upper_bound;
131
c906108c
SS
132 switch (TYPE_ARRAY_UPPER_BOUND_TYPE (type))
133 {
134 case BOUND_BY_VALUE_ON_STACK:
206415a3
DJ
135 frame = deprecated_safe_get_selected_frame ();
136 current_frame_addr = get_frame_base (frame);
c5aa993b 137 if (current_frame_addr > 0)
c906108c 138 {
c5aa993b
JM
139 *upper_bound =
140 read_memory_integer (current_frame_addr +
c906108c
SS
141 TYPE_ARRAY_UPPER_BOUND_VALUE (type),
142 4);
143 }
144 else
145 {
c5aa993b
JM
146 *upper_bound = DEFAULT_UPPER_BOUND;
147 return BOUND_FETCH_ERROR;
c906108c 148 }
c5aa993b
JM
149 break;
150
c906108c
SS
151 case BOUND_SIMPLE:
152 *upper_bound = TYPE_ARRAY_UPPER_BOUND_VALUE (type);
c5aa993b
JM
153 break;
154
155 case BOUND_CANNOT_BE_DETERMINED:
c906108c 156 /* we have an assumed size array on our hands. Assume that
c5aa993b
JM
157 upper_bound == lower_bound so that we show at least
158 1 element.If the user wants to see more elements, let
159 him manually ask for 'em and we'll subscript the
160 array and show him */
c906108c 161 f77_get_dynamic_lowerbound (type, upper_bound);
c5aa993b
JM
162 break;
163
c906108c 164 case BOUND_BY_REF_ON_STACK:
206415a3
DJ
165 frame = deprecated_safe_get_selected_frame ();
166 current_frame_addr = get_frame_base (frame);
c5aa993b 167 if (current_frame_addr > 0)
c906108c 168 {
5ed92fa8 169 struct gdbarch *arch = get_frame_arch (frame);
c5aa993b 170 ptr_to_upper_bound =
0d540cdf
KD
171 read_memory_typed_address (current_frame_addr +
172 TYPE_ARRAY_UPPER_BOUND_VALUE (type),
5ed92fa8 173 builtin_type (arch)->builtin_data_ptr);
c5aa993b 174 *upper_bound = read_memory_integer (ptr_to_upper_bound, 4);
c906108c
SS
175 }
176 else
177 {
c5aa993b 178 *upper_bound = DEFAULT_UPPER_BOUND;
c906108c
SS
179 return BOUND_FETCH_ERROR;
180 }
c5aa993b
JM
181 break;
182
183 case BOUND_BY_REF_IN_REG:
184 case BOUND_BY_VALUE_IN_REG:
185 default:
8a3fe4f8 186 error (_("??? unhandled dynamic array bound type ???"));
c5aa993b 187 break;
c906108c
SS
188 }
189 return BOUND_FETCH_OK;
190}
191
c5aa993b 192/* Obtain F77 adjustable array dimensions */
c906108c
SS
193
194static void
fba45db2 195f77_get_dynamic_length_of_aggregate (struct type *type)
c906108c
SS
196{
197 int upper_bound = -1;
c5aa993b
JM
198 int lower_bound = 1;
199 int retcode;
200
c906108c
SS
201 /* Recursively go all the way down into a possibly multi-dimensional
202 F77 array and get the bounds. For simple arrays, this is pretty
203 easy but when the bounds are dynamic, we must be very careful
204 to add up all the lengths correctly. Not doing this right
205 will lead to horrendous-looking arrays in parameter lists.
c5aa993b 206
c906108c 207 This function also works for strings which behave very
c5aa993b
JM
208 similarly to arrays. */
209
210 if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_ARRAY
211 || TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_STRING)
c906108c 212 f77_get_dynamic_length_of_aggregate (TYPE_TARGET_TYPE (type));
c5aa993b
JM
213
214 /* Recursion ends here, start setting up lengths. */
215 retcode = f77_get_dynamic_lowerbound (type, &lower_bound);
c906108c 216 if (retcode == BOUND_FETCH_ERROR)
8a3fe4f8 217 error (_("Cannot obtain valid array lower bound"));
c5aa993b
JM
218
219 retcode = f77_get_dynamic_upperbound (type, &upper_bound);
c906108c 220 if (retcode == BOUND_FETCH_ERROR)
8a3fe4f8 221 error (_("Cannot obtain valid array upper bound"));
c5aa993b
JM
222
223 /* Patch in a valid length value. */
224
c906108c
SS
225 TYPE_LENGTH (type) =
226 (upper_bound - lower_bound + 1) * TYPE_LENGTH (check_typedef (TYPE_TARGET_TYPE (type)));
c5aa993b 227}
c906108c
SS
228
229/* Function that sets up the array offset,size table for the array
c5aa993b 230 type "type". */
c906108c 231
c5aa993b 232static void
fba45db2 233f77_create_arrayprint_offset_tbl (struct type *type, struct ui_file *stream)
c906108c
SS
234{
235 struct type *tmp_type;
236 int eltlen;
237 int ndimen = 1;
c5aa993b
JM
238 int upper, lower, retcode;
239
240 tmp_type = type;
241
242 while ((TYPE_CODE (tmp_type) == TYPE_CODE_ARRAY))
c906108c
SS
243 {
244 if (TYPE_ARRAY_UPPER_BOUND_TYPE (tmp_type) == BOUND_CANNOT_BE_DETERMINED)
c5aa993b
JM
245 fprintf_filtered (stream, "<assumed size array> ");
246
c906108c
SS
247 retcode = f77_get_dynamic_upperbound (tmp_type, &upper);
248 if (retcode == BOUND_FETCH_ERROR)
8a3fe4f8 249 error (_("Cannot obtain dynamic upper bound"));
c5aa993b
JM
250
251 retcode = f77_get_dynamic_lowerbound (tmp_type, &lower);
c906108c 252 if (retcode == BOUND_FETCH_ERROR)
8a3fe4f8 253 error (_("Cannot obtain dynamic lower bound"));
c5aa993b 254
c906108c 255 F77_DIM_SIZE (ndimen) = upper - lower + 1;
c5aa993b 256
c906108c 257 tmp_type = TYPE_TARGET_TYPE (tmp_type);
c5aa993b 258 ndimen++;
c906108c 259 }
c5aa993b 260
c906108c
SS
261 /* Now we multiply eltlen by all the offsets, so that later we
262 can print out array elements correctly. Up till now we
263 know an offset to apply to get the item but we also
264 have to know how much to add to get to the next item */
c5aa993b 265
c906108c 266 ndimen--;
c5aa993b 267 eltlen = TYPE_LENGTH (tmp_type);
c906108c
SS
268 F77_DIM_OFFSET (ndimen) = eltlen;
269 while (--ndimen > 0)
270 {
271 eltlen *= F77_DIM_SIZE (ndimen + 1);
272 F77_DIM_OFFSET (ndimen) = eltlen;
273 }
274}
275
b3cacbee
DL
276
277
c906108c
SS
278/* Actual function which prints out F77 arrays, Valaddr == address in
279 the superior. Address == the address in the inferior. */
7b0090c3 280
c5aa993b 281static void
a2bd3dcd 282f77_print_array_1 (int nss, int ndimensions, struct type *type,
fc1a4b47 283 const gdb_byte *valaddr, CORE_ADDR address,
a2bd3dcd 284 struct ui_file *stream, int format,
b3cacbee
DL
285 int deref_ref, int recurse, enum val_prettyprint pretty,
286 int *elts)
c906108c
SS
287{
288 int i;
c5aa993b 289
c906108c
SS
290 if (nss != ndimensions)
291 {
b3cacbee 292 for (i = 0; (i < F77_DIM_SIZE (nss) && (*elts) < print_max); i++)
c906108c
SS
293 {
294 fprintf_filtered (stream, "( ");
295 f77_print_array_1 (nss + 1, ndimensions, TYPE_TARGET_TYPE (type),
c5aa993b
JM
296 valaddr + i * F77_DIM_OFFSET (nss),
297 address + i * F77_DIM_OFFSET (nss),
b3cacbee 298 stream, format, deref_ref, recurse, pretty, elts);
c906108c
SS
299 fprintf_filtered (stream, ") ");
300 }
7b0090c3 301 if (*elts >= print_max && i < F77_DIM_SIZE (nss))
b3cacbee 302 fprintf_filtered (stream, "...");
c906108c
SS
303 }
304 else
305 {
7b0090c3
DL
306 for (i = 0; i < F77_DIM_SIZE (nss) && (*elts) < print_max;
307 i++, (*elts)++)
c906108c
SS
308 {
309 val_print (TYPE_TARGET_TYPE (type),
310 valaddr + i * F77_DIM_OFFSET (ndimensions),
c5aa993b 311 0,
c906108c 312 address + i * F77_DIM_OFFSET (ndimensions),
d8ca156b
JB
313 stream, format, deref_ref, recurse, pretty,
314 current_language);
c906108c
SS
315
316 if (i != (F77_DIM_SIZE (nss) - 1))
c5aa993b
JM
317 fprintf_filtered (stream, ", ");
318
7b0090c3 319 if ((*elts == print_max - 1) && (i != (F77_DIM_SIZE (nss) - 1)))
c906108c
SS
320 fprintf_filtered (stream, "...");
321 }
322 }
323}
324
325/* This function gets called to print an F77 array, we set up some
326 stuff and then immediately call f77_print_array_1() */
327
c5aa993b 328static void
fc1a4b47 329f77_print_array (struct type *type, const gdb_byte *valaddr,
a2bd3dcd
AC
330 CORE_ADDR address, struct ui_file *stream,
331 int format, int deref_ref, int recurse,
fba45db2 332 enum val_prettyprint pretty)
c906108c 333{
c5aa993b 334 int ndimensions;
b3cacbee 335 int elts = 0;
c5aa993b
JM
336
337 ndimensions = calc_f77_array_dims (type);
338
c906108c 339 if (ndimensions > MAX_FORTRAN_DIMS || ndimensions < 0)
8a3fe4f8 340 error (_("Type node corrupt! F77 arrays cannot have %d subscripts (%d Max)"),
c906108c 341 ndimensions, MAX_FORTRAN_DIMS);
c5aa993b 342
c906108c
SS
343 /* Since F77 arrays are stored column-major, we set up an
344 offset table to get at the various row's elements. The
c5aa993b 345 offset table contains entries for both offset and subarray size. */
c906108c 346
c5aa993b
JM
347 f77_create_arrayprint_offset_tbl (type, stream);
348
349 f77_print_array_1 (1, ndimensions, type, valaddr, address, stream, format,
b3cacbee 350 deref_ref, recurse, pretty, &elts);
c5aa993b 351}
c906108c 352\f
c5aa993b 353
c906108c
SS
354/* Print data of type TYPE located at VALADDR (within GDB), which came from
355 the inferior at address ADDRESS, onto stdio stream STREAM according to
356 FORMAT (a letter or 0 for natural format). The data at VALADDR is in
357 target byte order.
c5aa993b 358
c906108c
SS
359 If the data are a string pointer, returns the number of string characters
360 printed.
c5aa993b 361
c906108c
SS
362 If DEREF_REF is nonzero, then dereference references, otherwise just print
363 them like pointers.
c5aa993b 364
c906108c
SS
365 The PRETTY parameter controls prettyprinting. */
366
367int
fc1a4b47 368f_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
fba45db2
KB
369 CORE_ADDR address, struct ui_file *stream, int format,
370 int deref_ref, int recurse, enum val_prettyprint pretty)
c906108c 371{
52f0bd74 372 unsigned int i = 0; /* Number of characters printed */
c906108c
SS
373 struct type *elttype;
374 LONGEST val;
375 CORE_ADDR addr;
2a5e440c 376 int index;
c5aa993b 377
c906108c
SS
378 CHECK_TYPEDEF (type);
379 switch (TYPE_CODE (type))
380 {
c5aa993b 381 case TYPE_CODE_STRING:
c906108c
SS
382 f77_get_dynamic_length_of_aggregate (type);
383 LA_PRINT_STRING (stream, valaddr, TYPE_LENGTH (type), 1, 0);
384 break;
c5aa993b 385
c906108c 386 case TYPE_CODE_ARRAY:
c5aa993b
JM
387 fprintf_filtered (stream, "(");
388 f77_print_array (type, valaddr, address, stream, format,
389 deref_ref, recurse, pretty);
c906108c
SS
390 fprintf_filtered (stream, ")");
391 break;
7e86466e 392
c906108c
SS
393 case TYPE_CODE_PTR:
394 if (format && format != 's')
395 {
396 print_scalar_formatted (valaddr, type, format, 0, stream);
397 break;
398 }
399 else
400 {
401 addr = unpack_pointer (type, valaddr);
402 elttype = check_typedef (TYPE_TARGET_TYPE (type));
c5aa993b 403
c906108c
SS
404 if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
405 {
406 /* Try to print what function it points to. */
407 print_address_demangle (addr, stream, demangle);
408 /* Return value is irrelevant except for string pointers. */
409 return 0;
410 }
c5aa993b 411
c906108c 412 if (addressprint && format != 's')
ed49a04f 413 fputs_filtered (paddress (addr), stream);
c5aa993b 414
c906108c
SS
415 /* For a pointer to char or unsigned char, also print the string
416 pointed to, unless pointer is null. */
417 if (TYPE_LENGTH (elttype) == 1
418 && TYPE_CODE (elttype) == TYPE_CODE_INT
419 && (format == 0 || format == 's')
420 && addr != 0)
421 i = val_print_string (addr, -1, TYPE_LENGTH (elttype), stream);
c5aa993b 422
7e86466e
RH
423 /* Return number of characters printed, including the terminating
424 '\0' if we reached the end. val_print_string takes care including
425 the terminating '\0' if necessary. */
426 return i;
427 }
428 break;
429
430 case TYPE_CODE_REF:
431 elttype = check_typedef (TYPE_TARGET_TYPE (type));
432 if (addressprint)
433 {
434 CORE_ADDR addr
435 = extract_typed_address (valaddr + embedded_offset, type);
436 fprintf_filtered (stream, "@");
ed49a04f 437 fputs_filtered (paddress (addr), stream);
7e86466e
RH
438 if (deref_ref)
439 fputs_filtered (": ", stream);
440 }
441 /* De-reference the reference. */
442 if (deref_ref)
443 {
444 if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF)
445 {
446 struct value *deref_val =
447 value_at
448 (TYPE_TARGET_TYPE (type),
d8631d21 449 unpack_pointer (type, valaddr + embedded_offset));
806048c6 450 common_val_print (deref_val, stream, format, deref_ref, recurse,
d8ca156b 451 pretty, current_language);
7e86466e
RH
452 }
453 else
454 fputs_filtered ("???", stream);
c906108c
SS
455 }
456 break;
c5aa993b 457
c906108c
SS
458 case TYPE_CODE_FUNC:
459 if (format)
460 {
461 print_scalar_formatted (valaddr, type, format, 0, stream);
462 break;
463 }
464 /* FIXME, we should consider, at least for ANSI C language, eliminating
c5aa993b 465 the distinction made between FUNCs and POINTERs to FUNCs. */
c906108c
SS
466 fprintf_filtered (stream, "{");
467 type_print (type, "", stream, -1);
468 fprintf_filtered (stream, "} ");
469 /* Try to print what function it points to, and its address. */
470 print_address_demangle (address, stream, demangle);
471 break;
c5aa993b 472
c906108c
SS
473 case TYPE_CODE_INT:
474 format = format ? format : output_format;
475 if (format)
476 print_scalar_formatted (valaddr, type, format, 0, stream);
477 else
478 {
479 val_print_type_code_int (type, valaddr, stream);
480 /* C and C++ has no single byte int type, char is used instead.
481 Since we don't know whether the value is really intended to
482 be used as an integer or a character, print the character
483 equivalent as well. */
484 if (TYPE_LENGTH (type) == 1)
485 {
486 fputs_filtered (" ", stream);
487 LA_PRINT_CHAR ((unsigned char) unpack_long (type, valaddr),
488 stream);
489 }
490 }
491 break;
c5aa993b 492
4f2aea11
MK
493 case TYPE_CODE_FLAGS:
494 if (format)
495 print_scalar_formatted (valaddr, type, format, 0, stream);
496 else
497 val_print_type_code_flags (type, valaddr, stream);
498 break;
499
c906108c
SS
500 case TYPE_CODE_FLT:
501 if (format)
502 print_scalar_formatted (valaddr, type, format, 0, stream);
503 else
504 print_floating (valaddr, type, stream);
505 break;
c5aa993b 506
c906108c
SS
507 case TYPE_CODE_VOID:
508 fprintf_filtered (stream, "VOID");
509 break;
c5aa993b 510
c906108c
SS
511 case TYPE_CODE_ERROR:
512 fprintf_filtered (stream, "<error type>");
513 break;
c5aa993b 514
c906108c
SS
515 case TYPE_CODE_RANGE:
516 /* FIXME, we should not ever have to print one of these yet. */
517 fprintf_filtered (stream, "<range type>");
518 break;
c5aa993b 519
c906108c
SS
520 case TYPE_CODE_BOOL:
521 format = format ? format : output_format;
522 if (format)
523 print_scalar_formatted (valaddr, type, format, 0, stream);
524 else
525 {
b806fb9a 526 val = extract_unsigned_integer (valaddr, TYPE_LENGTH (type));
c5aa993b
JM
527
528 if (val == 0)
c906108c 529 fprintf_filtered (stream, ".FALSE.");
c5aa993b
JM
530 else if (val == 1)
531 fprintf_filtered (stream, ".TRUE.");
532 else
533 /* Not a legitimate logical type, print as an integer. */
534 {
535 /* Bash the type code temporarily. */
536 TYPE_CODE (type) = TYPE_CODE_INT;
537 f_val_print (type, valaddr, 0, address, stream, format,
538 deref_ref, recurse, pretty);
539 /* Restore the type code so later uses work as intended. */
540 TYPE_CODE (type) = TYPE_CODE_BOOL;
541 }
c906108c
SS
542 }
543 break;
c5aa993b 544
c906108c 545 case TYPE_CODE_COMPLEX:
b806fb9a 546 type = TYPE_TARGET_TYPE (type);
c906108c
SS
547 fputs_filtered ("(", stream);
548 print_floating (valaddr, type, stream);
549 fputs_filtered (",", stream);
9af97293 550 print_floating (valaddr + TYPE_LENGTH (type), type, stream);
c906108c
SS
551 fputs_filtered (")", stream);
552 break;
c5aa993b 553
c906108c
SS
554 case TYPE_CODE_UNDEF:
555 /* This happens (without TYPE_FLAG_STUB set) on systems which don't use
c5aa993b
JM
556 dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar"
557 and no complete type for struct foo in that file. */
c906108c
SS
558 fprintf_filtered (stream, "<incomplete type>");
559 break;
c5aa993b 560
2a5e440c 561 case TYPE_CODE_STRUCT:
9eec4d1e 562 case TYPE_CODE_UNION:
2a5e440c
WZ
563 /* Starting from the Fortran 90 standard, Fortran supports derived
564 types. */
9eec4d1e 565 fprintf_filtered (stream, "( ");
2a5e440c
WZ
566 for (index = 0; index < TYPE_NFIELDS (type); index++)
567 {
568 int offset = TYPE_FIELD_BITPOS (type, index) / 8;
569 f_val_print (TYPE_FIELD_TYPE (type, index), valaddr + offset,
570 embedded_offset, address, stream,
571 format, deref_ref, recurse, pretty);
572 if (index != TYPE_NFIELDS (type) - 1)
573 fputs_filtered (", ", stream);
574 }
9eec4d1e 575 fprintf_filtered (stream, " )");
2a5e440c
WZ
576 break;
577
c906108c 578 default:
8a3fe4f8 579 error (_("Invalid F77 type code %d in symbol table."), TYPE_CODE (type));
c906108c
SS
580 }
581 gdb_flush (stream);
582 return 0;
583}
584
585static void
fba45db2 586list_all_visible_commons (char *funname)
c906108c 587{
c5aa993b
JM
588 SAVED_F77_COMMON_PTR tmp;
589
c906108c 590 tmp = head_common_list;
c5aa993b 591
a3f17187 592 printf_filtered (_("All COMMON blocks visible at this level:\n\n"));
c5aa993b 593
c906108c
SS
594 while (tmp != NULL)
595 {
762f08a3 596 if (strcmp (tmp->owning_function, funname) == 0)
c5aa993b
JM
597 printf_filtered ("%s\n", tmp->name);
598
c906108c
SS
599 tmp = tmp->next;
600 }
601}
602
603/* This function is used to print out the values in a given COMMON
604 block. It will always use the most local common block of the
c5aa993b 605 given name */
c906108c 606
c5aa993b 607static void
fba45db2 608info_common_command (char *comname, int from_tty)
c906108c 609{
c5aa993b
JM
610 SAVED_F77_COMMON_PTR the_common;
611 COMMON_ENTRY_PTR entry;
c906108c 612 struct frame_info *fi;
52f0bd74 613 char *funname = 0;
c906108c 614 struct symbol *func;
c5aa993b 615
c906108c
SS
616 /* We have been told to display the contents of F77 COMMON
617 block supposedly visible in this function. Let us
618 first make sure that it is visible and if so, let
c5aa993b
JM
619 us display its contents */
620
206415a3 621 fi = get_selected_frame (_("No frame selected"));
c5aa993b 622
c906108c 623 /* The following is generally ripped off from stack.c's routine
c5aa993b
JM
624 print_frame_info() */
625
bdd78e62 626 func = find_pc_function (get_frame_pc (fi));
c906108c
SS
627 if (func)
628 {
629 /* In certain pathological cases, the symtabs give the wrong
c5aa993b
JM
630 function (when we are in the first function in a file which
631 is compiled without debugging symbols, the previous function
632 is compiled with debugging symbols, and the "foo.o" symbol
633 that is supposed to tell us where the file with debugging symbols
634 ends has been truncated by ar because it is longer than 15
635 characters).
636
637 So look in the minimal symbol tables as well, and if it comes
638 up with a larger address for the function use that instead.
639 I don't think this can ever cause any problems; there shouldn't
640 be any minimal symbols in the middle of a function.
641 FIXME: (Not necessarily true. What about text labels) */
642
7c6e0d48
MS
643 struct minimal_symbol *msymbol =
644 lookup_minimal_symbol_by_pc (get_frame_pc (fi));
c5aa993b 645
c906108c 646 if (msymbol != NULL
c5aa993b 647 && (SYMBOL_VALUE_ADDRESS (msymbol)
c906108c 648 > BLOCK_START (SYMBOL_BLOCK_VALUE (func))))
3567439c 649 funname = SYMBOL_LINKAGE_NAME (msymbol);
c906108c 650 else
3567439c 651 funname = SYMBOL_LINKAGE_NAME (func);
c906108c
SS
652 }
653 else
654 {
aa1ee363 655 struct minimal_symbol *msymbol =
bdd78e62 656 lookup_minimal_symbol_by_pc (get_frame_pc (fi));
c5aa993b 657
c906108c 658 if (msymbol != NULL)
3567439c 659 funname = SYMBOL_LINKAGE_NAME (msymbol);
7c6e0d48
MS
660 else /* Got no 'funname', code below will fail. */
661 error (_("No function found for frame."));
c906108c 662 }
c5aa993b 663
c906108c 664 /* If comname is NULL, we assume the user wishes to see the
c5aa993b
JM
665 which COMMON blocks are visible here and then return */
666
c906108c
SS
667 if (comname == 0)
668 {
669 list_all_visible_commons (funname);
c5aa993b 670 return;
c906108c 671 }
c5aa993b
JM
672
673 the_common = find_common_for_function (comname, funname);
674
c906108c
SS
675 if (the_common)
676 {
762f08a3 677 if (strcmp (comname, BLANK_COMMON_NAME_LOCAL) == 0)
a3f17187 678 printf_filtered (_("Contents of blank COMMON block:\n"));
c5aa993b 679 else
a3f17187 680 printf_filtered (_("Contents of F77 COMMON block '%s':\n"), comname);
c5aa993b
JM
681
682 printf_filtered ("\n");
683 entry = the_common->entries;
684
c906108c
SS
685 while (entry != NULL)
686 {
3567439c 687 printf_filtered ("%s = ", SYMBOL_PRINT_NAME (entry->symbol));
c5aa993b
JM
688 print_variable_value (entry->symbol, fi, gdb_stdout);
689 printf_filtered ("\n");
690 entry = entry->next;
c906108c
SS
691 }
692 }
c5aa993b 693 else
a3f17187 694 printf_filtered (_("Cannot locate the common block %s in function '%s'\n"),
c5aa993b 695 comname, funname);
c906108c
SS
696}
697
698/* This function is used to determine whether there is a
c5aa993b 699 F77 common block visible at the current scope called 'comname'. */
c906108c
SS
700
701#if 0
702static int
fba45db2 703there_is_a_visible_common_named (char *comname)
c906108c 704{
c5aa993b 705 SAVED_F77_COMMON_PTR the_common;
c906108c 706 struct frame_info *fi;
52f0bd74 707 char *funname = 0;
c906108c 708 struct symbol *func;
c5aa993b 709
c906108c 710 if (comname == NULL)
8a3fe4f8 711 error (_("Cannot deal with NULL common name!"));
c5aa993b 712
206415a3 713 fi = get_selected_frame (_("No frame selected"));
c5aa993b 714
c906108c 715 /* The following is generally ripped off from stack.c's routine
c5aa993b
JM
716 print_frame_info() */
717
c906108c
SS
718 func = find_pc_function (fi->pc);
719 if (func)
720 {
721 /* In certain pathological cases, the symtabs give the wrong
c5aa993b
JM
722 function (when we are in the first function in a file which
723 is compiled without debugging symbols, the previous function
724 is compiled with debugging symbols, and the "foo.o" symbol
725 that is supposed to tell us where the file with debugging symbols
726 ends has been truncated by ar because it is longer than 15
727 characters).
728
729 So look in the minimal symbol tables as well, and if it comes
730 up with a larger address for the function use that instead.
731 I don't think this can ever cause any problems; there shouldn't
732 be any minimal symbols in the middle of a function.
733 FIXME: (Not necessarily true. What about text labels) */
734
c906108c 735 struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (fi->pc);
c5aa993b 736
c906108c 737 if (msymbol != NULL
c5aa993b 738 && (SYMBOL_VALUE_ADDRESS (msymbol)
c906108c 739 > BLOCK_START (SYMBOL_BLOCK_VALUE (func))))
3567439c 740 funname = SYMBOL_LINKAGE_NAME (msymbol);
c906108c 741 else
3567439c 742 funname = SYMBOL_LINKAGE_NAME (func);
c906108c
SS
743 }
744 else
745 {
aa1ee363 746 struct minimal_symbol *msymbol =
c5aa993b
JM
747 lookup_minimal_symbol_by_pc (fi->pc);
748
c906108c 749 if (msymbol != NULL)
3567439c 750 funname = SYMBOL_LINKAGE_NAME (msymbol);
c906108c 751 }
c5aa993b
JM
752
753 the_common = find_common_for_function (comname, funname);
754
c906108c
SS
755 return (the_common ? 1 : 0);
756}
757#endif
758
759void
fba45db2 760_initialize_f_valprint (void)
c906108c
SS
761{
762 add_info ("common", info_common_command,
1bedd215 763 _("Print out the values contained in a Fortran COMMON block."));
c906108c 764 if (xdb_commands)
c5aa993b 765 add_com ("lc", class_info, info_common_command,
1bedd215 766 _("Print out the values contained in a Fortran COMMON block."));
c906108c 767}
This page took 0.641452 seconds and 4 git commands to generate.