| 1 | /* Support for printing Fortran values for GDB, the GNU debugger. |
| 2 | Copyright 1993, 1994, 1995 Free Software Foundation, Inc. |
| 3 | Contributed by Motorola. Adapted from the C definitions by Farooq Butt |
| 4 | (fmbutt@engage.sps.mot.com), additionally worked over by Stan Shebs. |
| 5 | |
| 6 | This file is part of GDB. |
| 7 | |
| 8 | This program is free software; you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation; either version 2 of the License, or |
| 11 | (at your option) any later version. |
| 12 | |
| 13 | This program is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with this program; if not, write to the Free Software |
| 20 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ |
| 21 | |
| 22 | #include "defs.h" |
| 23 | #include <string.h> |
| 24 | #include "symtab.h" |
| 25 | #include "gdbtypes.h" |
| 26 | #include "expression.h" |
| 27 | #include "value.h" |
| 28 | #include "demangle.h" |
| 29 | #include "valprint.h" |
| 30 | #include "language.h" |
| 31 | #include "f-lang.h" |
| 32 | #include "frame.h" |
| 33 | #include "gdbcore.h" |
| 34 | #include "command.h" |
| 35 | |
| 36 | extern unsigned int print_max; /* No of array elements to print */ |
| 37 | |
| 38 | extern int calc_f77_array_dims PARAMS ((struct type *)); |
| 39 | |
| 40 | int f77_array_offset_tbl[MAX_FORTRAN_DIMS+1][2]; |
| 41 | |
| 42 | /* Array which holds offsets to be applied to get a row's elements |
| 43 | for a given array. Array also holds the size of each subarray. */ |
| 44 | |
| 45 | /* The following macro gives us the size of the nth dimension, Where |
| 46 | n is 1 based. */ |
| 47 | |
| 48 | #define F77_DIM_SIZE(n) (f77_array_offset_tbl[n][1]) |
| 49 | |
| 50 | /* The following gives us the offset for row n where n is 1-based. */ |
| 51 | |
| 52 | #define F77_DIM_OFFSET(n) (f77_array_offset_tbl[n][0]) |
| 53 | |
| 54 | int |
| 55 | f77_get_dynamic_lowerbound (type, lower_bound) |
| 56 | struct type *type; |
| 57 | int *lower_bound; |
| 58 | { |
| 59 | CORE_ADDR current_frame_addr; |
| 60 | CORE_ADDR ptr_to_lower_bound; |
| 61 | |
| 62 | switch (TYPE_ARRAY_LOWER_BOUND_TYPE (type)) |
| 63 | { |
| 64 | case BOUND_BY_VALUE_ON_STACK: |
| 65 | current_frame_addr = selected_frame->frame; |
| 66 | if (current_frame_addr > 0) |
| 67 | { |
| 68 | *lower_bound = |
| 69 | read_memory_integer (current_frame_addr + |
| 70 | TYPE_ARRAY_LOWER_BOUND_VALUE (type), |
| 71 | 4); |
| 72 | } |
| 73 | else |
| 74 | { |
| 75 | *lower_bound = DEFAULT_LOWER_BOUND; |
| 76 | return BOUND_FETCH_ERROR; |
| 77 | } |
| 78 | break; |
| 79 | |
| 80 | case BOUND_SIMPLE: |
| 81 | *lower_bound = TYPE_ARRAY_LOWER_BOUND_VALUE (type); |
| 82 | break; |
| 83 | |
| 84 | case BOUND_CANNOT_BE_DETERMINED: |
| 85 | error ("Lower bound may not be '*' in F77"); |
| 86 | break; |
| 87 | |
| 88 | case BOUND_BY_REF_ON_STACK: |
| 89 | current_frame_addr = selected_frame->frame; |
| 90 | if (current_frame_addr > 0) |
| 91 | { |
| 92 | ptr_to_lower_bound = |
| 93 | read_memory_integer (current_frame_addr + |
| 94 | TYPE_ARRAY_LOWER_BOUND_VALUE (type), |
| 95 | 4); |
| 96 | *lower_bound = read_memory_integer (ptr_to_lower_bound, 4); |
| 97 | } |
| 98 | else |
| 99 | { |
| 100 | *lower_bound = DEFAULT_LOWER_BOUND; |
| 101 | return BOUND_FETCH_ERROR; |
| 102 | } |
| 103 | break; |
| 104 | |
| 105 | case BOUND_BY_REF_IN_REG: |
| 106 | case BOUND_BY_VALUE_IN_REG: |
| 107 | default: |
| 108 | error ("??? unhandled dynamic array bound type ???"); |
| 109 | break; |
| 110 | } |
| 111 | return BOUND_FETCH_OK; |
| 112 | } |
| 113 | |
| 114 | int |
| 115 | f77_get_dynamic_upperbound (type, upper_bound) |
| 116 | struct type *type; |
| 117 | int *upper_bound; |
| 118 | { |
| 119 | CORE_ADDR current_frame_addr = 0; |
| 120 | CORE_ADDR ptr_to_upper_bound; |
| 121 | |
| 122 | switch (TYPE_ARRAY_UPPER_BOUND_TYPE (type)) |
| 123 | { |
| 124 | case BOUND_BY_VALUE_ON_STACK: |
| 125 | current_frame_addr = selected_frame->frame; |
| 126 | if (current_frame_addr > 0) |
| 127 | { |
| 128 | *upper_bound = |
| 129 | read_memory_integer (current_frame_addr + |
| 130 | TYPE_ARRAY_UPPER_BOUND_VALUE (type), |
| 131 | 4); |
| 132 | } |
| 133 | else |
| 134 | { |
| 135 | *upper_bound = DEFAULT_UPPER_BOUND; |
| 136 | return BOUND_FETCH_ERROR; |
| 137 | } |
| 138 | break; |
| 139 | |
| 140 | case BOUND_SIMPLE: |
| 141 | *upper_bound = TYPE_ARRAY_UPPER_BOUND_VALUE (type); |
| 142 | break; |
| 143 | |
| 144 | case BOUND_CANNOT_BE_DETERMINED: |
| 145 | /* we have an assumed size array on our hands. Assume that |
| 146 | upper_bound == lower_bound so that we show at least |
| 147 | 1 element.If the user wants to see more elements, let |
| 148 | him manually ask for 'em and we'll subscript the |
| 149 | array and show him */ |
| 150 | f77_get_dynamic_lowerbound (type, upper_bound); |
| 151 | break; |
| 152 | |
| 153 | case BOUND_BY_REF_ON_STACK: |
| 154 | current_frame_addr = selected_frame->frame; |
| 155 | if (current_frame_addr > 0) |
| 156 | { |
| 157 | ptr_to_upper_bound = |
| 158 | read_memory_integer (current_frame_addr + |
| 159 | TYPE_ARRAY_UPPER_BOUND_VALUE (type), |
| 160 | 4); |
| 161 | *upper_bound = read_memory_integer(ptr_to_upper_bound, 4); |
| 162 | } |
| 163 | else |
| 164 | { |
| 165 | *upper_bound = DEFAULT_UPPER_BOUND; |
| 166 | return BOUND_FETCH_ERROR; |
| 167 | } |
| 168 | break; |
| 169 | |
| 170 | case BOUND_BY_REF_IN_REG: |
| 171 | case BOUND_BY_VALUE_IN_REG: |
| 172 | default: |
| 173 | error ("??? unhandled dynamic array bound type ???"); |
| 174 | break; |
| 175 | } |
| 176 | return BOUND_FETCH_OK; |
| 177 | } |
| 178 | |
| 179 | /* Obtain F77 adjustable array dimensions */ |
| 180 | |
| 181 | void |
| 182 | f77_get_dynamic_length_of_aggregate (type) |
| 183 | struct type *type; |
| 184 | { |
| 185 | int upper_bound = -1; |
| 186 | int lower_bound = 1; |
| 187 | int retcode; |
| 188 | |
| 189 | /* Recursively go all the way down into a possibly multi-dimensional |
| 190 | F77 array and get the bounds. For simple arrays, this is pretty |
| 191 | easy but when the bounds are dynamic, we must be very careful |
| 192 | to add up all the lengths correctly. Not doing this right |
| 193 | will lead to horrendous-looking arrays in parameter lists. |
| 194 | |
| 195 | This function also works for strings which behave very |
| 196 | similarly to arrays. */ |
| 197 | |
| 198 | if (TYPE_CODE(TYPE_TARGET_TYPE (type)) == TYPE_CODE_ARRAY |
| 199 | || TYPE_CODE(TYPE_TARGET_TYPE (type)) == TYPE_CODE_STRING) |
| 200 | f77_get_dynamic_length_of_aggregate (TYPE_TARGET_TYPE (type)); |
| 201 | |
| 202 | /* Recursion ends here, start setting up lengths. */ |
| 203 | retcode = f77_get_dynamic_lowerbound (type, &lower_bound); |
| 204 | if (retcode == BOUND_FETCH_ERROR) |
| 205 | error ("Cannot obtain valid array lower bound"); |
| 206 | |
| 207 | retcode = f77_get_dynamic_upperbound (type, &upper_bound); |
| 208 | if (retcode == BOUND_FETCH_ERROR) |
| 209 | error ("Cannot obtain valid array upper bound"); |
| 210 | |
| 211 | /* Patch in a valid length value. */ |
| 212 | |
| 213 | TYPE_LENGTH (type) = |
| 214 | (upper_bound - lower_bound + 1) * TYPE_LENGTH (TYPE_TARGET_TYPE (type)); |
| 215 | } |
| 216 | |
| 217 | /* Function that sets up the array offset,size table for the array |
| 218 | type "type". */ |
| 219 | |
| 220 | void |
| 221 | f77_create_arrayprint_offset_tbl (type, stream) |
| 222 | struct type *type; |
| 223 | FILE *stream; |
| 224 | { |
| 225 | struct type *tmp_type; |
| 226 | int eltlen; |
| 227 | int ndimen = 1; |
| 228 | int upper, lower, retcode; |
| 229 | |
| 230 | tmp_type = type; |
| 231 | |
| 232 | while ((TYPE_CODE (tmp_type) == TYPE_CODE_ARRAY)) |
| 233 | { |
| 234 | if (TYPE_ARRAY_UPPER_BOUND_TYPE (tmp_type) == BOUND_CANNOT_BE_DETERMINED) |
| 235 | fprintf_filtered (stream, "<assumed size array> "); |
| 236 | |
| 237 | retcode = f77_get_dynamic_upperbound (tmp_type, &upper); |
| 238 | if (retcode == BOUND_FETCH_ERROR) |
| 239 | error ("Cannot obtain dynamic upper bound"); |
| 240 | |
| 241 | retcode = f77_get_dynamic_lowerbound(tmp_type,&lower); |
| 242 | if (retcode == BOUND_FETCH_ERROR) |
| 243 | error("Cannot obtain dynamic lower bound"); |
| 244 | |
| 245 | F77_DIM_SIZE (ndimen) = upper - lower + 1; |
| 246 | |
| 247 | tmp_type = TYPE_TARGET_TYPE (tmp_type); |
| 248 | ndimen++; |
| 249 | } |
| 250 | |
| 251 | /* Now we multiply eltlen by all the offsets, so that later we |
| 252 | can print out array elements correctly. Up till now we |
| 253 | know an offset to apply to get the item but we also |
| 254 | have to know how much to add to get to the next item */ |
| 255 | |
| 256 | ndimen--; |
| 257 | eltlen = TYPE_LENGTH (tmp_type); |
| 258 | F77_DIM_OFFSET (ndimen) = eltlen; |
| 259 | while (--ndimen > 0) |
| 260 | { |
| 261 | eltlen *= F77_DIM_SIZE (ndimen + 1); |
| 262 | F77_DIM_OFFSET (ndimen) = eltlen; |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | /* Actual function which prints out F77 arrays, Valaddr == address in |
| 267 | the superior. Address == the address in the inferior. */ |
| 268 | |
| 269 | void |
| 270 | f77_print_array_1 (nss, ndimensions, type, valaddr, address, |
| 271 | stream, format, deref_ref, recurse, pretty) |
| 272 | int nss; |
| 273 | int ndimensions; |
| 274 | char *valaddr; |
| 275 | struct type *type; |
| 276 | CORE_ADDR address; |
| 277 | FILE *stream; |
| 278 | int format; |
| 279 | int deref_ref; |
| 280 | int recurse; |
| 281 | enum val_prettyprint pretty; |
| 282 | { |
| 283 | int i; |
| 284 | |
| 285 | if (nss != ndimensions) |
| 286 | { |
| 287 | for (i = 0; i< F77_DIM_SIZE(nss); i++) |
| 288 | { |
| 289 | fprintf_filtered (stream, "( "); |
| 290 | f77_print_array_1 (nss + 1, ndimensions, TYPE_TARGET_TYPE (type), |
| 291 | valaddr + i * F77_DIM_OFFSET (nss), |
| 292 | address + i * F77_DIM_OFFSET (nss), |
| 293 | stream, format, deref_ref, recurse, pretty, i); |
| 294 | fprintf_filtered (stream, ") "); |
| 295 | } |
| 296 | } |
| 297 | else |
| 298 | { |
| 299 | for (i = 0; (i < F77_DIM_SIZE (nss) && i < print_max); i++) |
| 300 | { |
| 301 | val_print (TYPE_TARGET_TYPE (type), |
| 302 | valaddr + i * F77_DIM_OFFSET (ndimensions), |
| 303 | address + i * F77_DIM_OFFSET (ndimensions), |
| 304 | stream, format, deref_ref, recurse, pretty); |
| 305 | |
| 306 | if (i != (F77_DIM_SIZE (nss) - 1)) |
| 307 | fprintf_filtered (stream, ", "); |
| 308 | |
| 309 | if (i == print_max - 1) |
| 310 | fprintf_filtered (stream, "..."); |
| 311 | } |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | /* This function gets called to print an F77 array, we set up some |
| 316 | stuff and then immediately call f77_print_array_1() */ |
| 317 | |
| 318 | void |
| 319 | f77_print_array (type, valaddr, address, stream, format, deref_ref, recurse, |
| 320 | pretty) |
| 321 | struct type *type; |
| 322 | char *valaddr; |
| 323 | CORE_ADDR address; |
| 324 | FILE *stream; |
| 325 | int format; |
| 326 | int deref_ref; |
| 327 | int recurse; |
| 328 | enum val_prettyprint pretty; |
| 329 | { |
| 330 | int ndimensions; |
| 331 | |
| 332 | ndimensions = calc_f77_array_dims (type); |
| 333 | |
| 334 | if (ndimensions > MAX_FORTRAN_DIMS || ndimensions < 0) |
| 335 | error ("Type node corrupt! F77 arrays cannot have %d subscripts (%d Max)", |
| 336 | ndimensions, MAX_FORTRAN_DIMS); |
| 337 | |
| 338 | /* Since F77 arrays are stored column-major, we set up an |
| 339 | offset table to get at the various row's elements. The |
| 340 | offset table contains entries for both offset and subarray size. */ |
| 341 | |
| 342 | f77_create_arrayprint_offset_tbl (type, stream); |
| 343 | |
| 344 | f77_print_array_1 (1, ndimensions, type, valaddr, address, stream, format, |
| 345 | deref_ref, recurse, pretty); |
| 346 | } |
| 347 | |
| 348 | \f |
| 349 | /* Print data of type TYPE located at VALADDR (within GDB), which came from |
| 350 | the inferior at address ADDRESS, onto stdio stream STREAM according to |
| 351 | FORMAT (a letter or 0 for natural format). The data at VALADDR is in |
| 352 | target byte order. |
| 353 | |
| 354 | If the data are a string pointer, returns the number of string characters |
| 355 | printed. |
| 356 | |
| 357 | If DEREF_REF is nonzero, then dereference references, otherwise just print |
| 358 | them like pointers. |
| 359 | |
| 360 | The PRETTY parameter controls prettyprinting. */ |
| 361 | |
| 362 | int |
| 363 | f_val_print (type, valaddr, address, stream, format, deref_ref, recurse, |
| 364 | pretty) |
| 365 | struct type *type; |
| 366 | char *valaddr; |
| 367 | CORE_ADDR address; |
| 368 | FILE *stream; |
| 369 | int format; |
| 370 | int deref_ref; |
| 371 | int recurse; |
| 372 | enum val_prettyprint pretty; |
| 373 | { |
| 374 | register unsigned int i = 0; /* Number of characters printed */ |
| 375 | struct type *elttype; |
| 376 | LONGEST val; |
| 377 | char *straddr; |
| 378 | CORE_ADDR addr; |
| 379 | |
| 380 | switch (TYPE_CODE (type)) |
| 381 | { |
| 382 | case TYPE_CODE_STRING: |
| 383 | f77_get_dynamic_length_of_aggregate (type); |
| 384 | LA_PRINT_STRING (stream, valaddr, TYPE_LENGTH (type), 0); |
| 385 | break; |
| 386 | |
| 387 | case TYPE_CODE_ARRAY: |
| 388 | fprintf_filtered (stream, "("); |
| 389 | f77_print_array (type, valaddr, address, stream, format, |
| 390 | deref_ref, recurse, pretty); |
| 391 | fprintf_filtered (stream, ")"); |
| 392 | break; |
| 393 | #if 0 |
| 394 | /* Array of unspecified length: treat like pointer to first elt. */ |
| 395 | valaddr = (char *) &address; |
| 396 | /* FALL THROUGH */ |
| 397 | #endif |
| 398 | case TYPE_CODE_PTR: |
| 399 | if (format && format != 's') |
| 400 | { |
| 401 | print_scalar_formatted (valaddr, type, format, 0, stream); |
| 402 | break; |
| 403 | } |
| 404 | else |
| 405 | { |
| 406 | addr = unpack_pointer (type, valaddr); |
| 407 | elttype = TYPE_TARGET_TYPE (type); |
| 408 | |
| 409 | if (TYPE_CODE (elttype) == TYPE_CODE_FUNC) |
| 410 | { |
| 411 | /* Try to print what function it points to. */ |
| 412 | print_address_demangle (addr, stream, demangle); |
| 413 | /* Return value is irrelevant except for string pointers. */ |
| 414 | return 0; |
| 415 | } |
| 416 | |
| 417 | if (addressprint && format != 's') |
| 418 | fprintf_filtered (stream, "0x%x", addr); |
| 419 | |
| 420 | /* For a pointer to char or unsigned char, also print the string |
| 421 | pointed to, unless pointer is null. */ |
| 422 | if (TYPE_LENGTH (elttype) == 1 |
| 423 | && TYPE_CODE (elttype) == TYPE_CODE_INT |
| 424 | && (format == 0 || format == 's') |
| 425 | && addr != 0) |
| 426 | i = val_print_string (addr, 0, stream); |
| 427 | |
| 428 | /* Return number of characters printed, plus one for the |
| 429 | terminating null if we have "reached the end". */ |
| 430 | return (i + (print_max && i != print_max)); |
| 431 | } |
| 432 | break; |
| 433 | |
| 434 | case TYPE_CODE_FUNC: |
| 435 | if (format) |
| 436 | { |
| 437 | print_scalar_formatted (valaddr, type, format, 0, stream); |
| 438 | break; |
| 439 | } |
| 440 | /* FIXME, we should consider, at least for ANSI C language, eliminating |
| 441 | the distinction made between FUNCs and POINTERs to FUNCs. */ |
| 442 | fprintf_filtered (stream, "{"); |
| 443 | type_print (type, "", stream, -1); |
| 444 | fprintf_filtered (stream, "} "); |
| 445 | /* Try to print what function it points to, and its address. */ |
| 446 | print_address_demangle (address, stream, demangle); |
| 447 | break; |
| 448 | |
| 449 | case TYPE_CODE_INT: |
| 450 | format = format ? format : output_format; |
| 451 | if (format) |
| 452 | print_scalar_formatted (valaddr, type, format, 0, stream); |
| 453 | else |
| 454 | { |
| 455 | val_print_type_code_int (type, valaddr, stream); |
| 456 | /* C and C++ has no single byte int type, char is used instead. |
| 457 | Since we don't know whether the value is really intended to |
| 458 | be used as an integer or a character, print the character |
| 459 | equivalent as well. */ |
| 460 | if (TYPE_LENGTH (type) == 1) |
| 461 | { |
| 462 | fputs_filtered (" ", stream); |
| 463 | LA_PRINT_CHAR ((unsigned char) unpack_long (type, valaddr), |
| 464 | stream); |
| 465 | } |
| 466 | } |
| 467 | break; |
| 468 | |
| 469 | case TYPE_CODE_FLT: |
| 470 | if (format) |
| 471 | print_scalar_formatted (valaddr, type, format, 0, stream); |
| 472 | else |
| 473 | print_floating (valaddr, type, stream); |
| 474 | break; |
| 475 | |
| 476 | case TYPE_CODE_VOID: |
| 477 | fprintf_filtered (stream, "VOID"); |
| 478 | break; |
| 479 | |
| 480 | case TYPE_CODE_ERROR: |
| 481 | fprintf_filtered (stream, "<error type>"); |
| 482 | break; |
| 483 | |
| 484 | case TYPE_CODE_RANGE: |
| 485 | /* FIXME, we should not ever have to print one of these yet. */ |
| 486 | fprintf_filtered (stream, "<range type>"); |
| 487 | break; |
| 488 | |
| 489 | case TYPE_CODE_BOOL: |
| 490 | format = format ? format : output_format; |
| 491 | if (format) |
| 492 | print_scalar_formatted (valaddr, type, format, 0, stream); |
| 493 | else |
| 494 | { |
| 495 | val = 0; |
| 496 | switch (TYPE_LENGTH(type)) |
| 497 | { |
| 498 | case 1: |
| 499 | val = unpack_long (builtin_type_f_logical_s1, valaddr); |
| 500 | break ; |
| 501 | |
| 502 | case 2: |
| 503 | val = unpack_long (builtin_type_f_logical_s2, valaddr); |
| 504 | break ; |
| 505 | |
| 506 | case 4: |
| 507 | val = unpack_long (builtin_type_f_logical, valaddr); |
| 508 | break ; |
| 509 | |
| 510 | default: |
| 511 | error ("Logicals of length %d bytes not supported", |
| 512 | TYPE_LENGTH (type)); |
| 513 | |
| 514 | } |
| 515 | |
| 516 | if (val == 0) |
| 517 | fprintf_filtered (stream, ".FALSE."); |
| 518 | else |
| 519 | if (val == 1) |
| 520 | fprintf_filtered (stream, ".TRUE."); |
| 521 | else |
| 522 | /* Not a legitimate logical type, print as an integer. */ |
| 523 | { |
| 524 | /* Bash the type code temporarily. */ |
| 525 | TYPE_CODE (type) = TYPE_CODE_INT; |
| 526 | f_val_print (type, valaddr, address, stream, format, |
| 527 | deref_ref, recurse, pretty); |
| 528 | /* Restore the type code so later uses work as intended. */ |
| 529 | TYPE_CODE (type) = TYPE_CODE_BOOL; |
| 530 | } |
| 531 | } |
| 532 | break; |
| 533 | |
| 534 | case TYPE_CODE_COMPLEX: |
| 535 | switch (TYPE_LENGTH (type)) |
| 536 | { |
| 537 | case 8: type = builtin_type_f_real; break; |
| 538 | case 16: type = builtin_type_f_real_s8; break; |
| 539 | case 32: type = builtin_type_f_real_s16; break; |
| 540 | default: |
| 541 | error ("Cannot print out complex*%d variables", TYPE_LENGTH(type)); |
| 542 | } |
| 543 | fputs_filtered ("(", stream); |
| 544 | print_floating (valaddr, type, stream); |
| 545 | fputs_filtered (",", stream); |
| 546 | print_floating (valaddr, type, stream); |
| 547 | fputs_filtered (")", stream); |
| 548 | break; |
| 549 | |
| 550 | case TYPE_CODE_UNDEF: |
| 551 | /* This happens (without TYPE_FLAG_STUB set) on systems which don't use |
| 552 | dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar" |
| 553 | and no complete type for struct foo in that file. */ |
| 554 | fprintf_filtered (stream, "<incomplete type>"); |
| 555 | break; |
| 556 | |
| 557 | default: |
| 558 | error ("Invalid F77 type code %d in symbol table.", TYPE_CODE (type)); |
| 559 | } |
| 560 | fflush (stream); |
| 561 | return 0; |
| 562 | } |
| 563 | |
| 564 | void |
| 565 | list_all_visible_commons (funname) |
| 566 | char *funname; |
| 567 | { |
| 568 | SAVED_F77_COMMON_PTR tmp; |
| 569 | |
| 570 | tmp = head_common_list; |
| 571 | |
| 572 | printf_filtered ("All COMMON blocks visible at this level:\n\n"); |
| 573 | |
| 574 | while (tmp != NULL) |
| 575 | { |
| 576 | if (STREQ(tmp->owning_function,funname)) |
| 577 | printf_filtered ("%s\n", tmp->name); |
| 578 | |
| 579 | tmp = tmp->next; |
| 580 | } |
| 581 | } |
| 582 | |
| 583 | /* This function is used to print out the values in a given COMMON |
| 584 | block. It will always use the most local common block of the |
| 585 | given name */ |
| 586 | |
| 587 | static void |
| 588 | info_common_command (comname, from_tty) |
| 589 | char *comname; |
| 590 | int from_tty; |
| 591 | { |
| 592 | SAVED_F77_COMMON_PTR the_common; |
| 593 | COMMON_ENTRY_PTR entry; |
| 594 | struct frame_info *fi; |
| 595 | register char *funname = 0; |
| 596 | struct symbol *func; |
| 597 | |
| 598 | /* We have been told to display the contents of F77 COMMON |
| 599 | block supposedly visible in this function. Let us |
| 600 | first make sure that it is visible and if so, let |
| 601 | us display its contents */ |
| 602 | |
| 603 | fi = selected_frame; |
| 604 | |
| 605 | if (fi == NULL) |
| 606 | error ("No frame selected"); |
| 607 | |
| 608 | /* The following is generally ripped off from stack.c's routine |
| 609 | print_frame_info() */ |
| 610 | |
| 611 | func = find_pc_function (fi->pc); |
| 612 | if (func) |
| 613 | { |
| 614 | /* In certain pathological cases, the symtabs give the wrong |
| 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 | |
| 628 | struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (fi->pc); |
| 629 | |
| 630 | if (msymbol != NULL |
| 631 | && (SYMBOL_VALUE_ADDRESS (msymbol) |
| 632 | > BLOCK_START (SYMBOL_BLOCK_VALUE (func)))) |
| 633 | funname = SYMBOL_NAME (msymbol); |
| 634 | else |
| 635 | funname = SYMBOL_NAME (func); |
| 636 | } |
| 637 | else |
| 638 | { |
| 639 | register struct minimal_symbol *msymbol = |
| 640 | lookup_minimal_symbol_by_pc (fi->pc); |
| 641 | |
| 642 | if (msymbol != NULL) |
| 643 | funname = SYMBOL_NAME (msymbol); |
| 644 | } |
| 645 | |
| 646 | /* If comname is NULL, we assume the user wishes to see the |
| 647 | which COMMON blocks are visible here and then return */ |
| 648 | |
| 649 | if (comname == 0) |
| 650 | { |
| 651 | list_all_visible_commons (funname); |
| 652 | return; |
| 653 | } |
| 654 | |
| 655 | the_common = find_common_for_function (comname,funname); |
| 656 | |
| 657 | if (the_common) |
| 658 | { |
| 659 | if (STREQ(comname,BLANK_COMMON_NAME_LOCAL)) |
| 660 | printf_filtered ("Contents of blank COMMON block:\n"); |
| 661 | else |
| 662 | printf_filtered ("Contents of F77 COMMON block '%s':\n",comname); |
| 663 | |
| 664 | printf_filtered ("\n"); |
| 665 | entry = the_common->entries; |
| 666 | |
| 667 | while (entry != NULL) |
| 668 | { |
| 669 | printf_filtered ("%s = ",SYMBOL_NAME(entry->symbol)); |
| 670 | print_variable_value (entry->symbol,fi,stdout); |
| 671 | printf_filtered ("\n"); |
| 672 | entry = entry->next; |
| 673 | } |
| 674 | } |
| 675 | else |
| 676 | printf_filtered ("Cannot locate the common block %s in function '%s'\n", |
| 677 | comname, funname); |
| 678 | } |
| 679 | |
| 680 | /* This function is used to determine whether there is a |
| 681 | F77 common block visible at the current scope called 'comname'. */ |
| 682 | |
| 683 | int |
| 684 | there_is_a_visible_common_named (comname) |
| 685 | char *comname; |
| 686 | { |
| 687 | SAVED_F77_COMMON_PTR the_common; |
| 688 | struct frame_info *fi; |
| 689 | register char *funname = 0; |
| 690 | struct symbol *func; |
| 691 | |
| 692 | if (comname == NULL) |
| 693 | error ("Cannot deal with NULL common name!"); |
| 694 | |
| 695 | fi = selected_frame; |
| 696 | |
| 697 | if (fi == NULL) |
| 698 | error ("No frame selected"); |
| 699 | |
| 700 | /* The following is generally ripped off from stack.c's routine |
| 701 | print_frame_info() */ |
| 702 | |
| 703 | func = find_pc_function (fi->pc); |
| 704 | if (func) |
| 705 | { |
| 706 | /* In certain pathological cases, the symtabs give the wrong |
| 707 | function (when we are in the first function in a file which |
| 708 | is compiled without debugging symbols, the previous function |
| 709 | is compiled with debugging symbols, and the "foo.o" symbol |
| 710 | that is supposed to tell us where the file with debugging symbols |
| 711 | ends has been truncated by ar because it is longer than 15 |
| 712 | characters). |
| 713 | |
| 714 | So look in the minimal symbol tables as well, and if it comes |
| 715 | up with a larger address for the function use that instead. |
| 716 | I don't think this can ever cause any problems; there shouldn't |
| 717 | be any minimal symbols in the middle of a function. |
| 718 | FIXME: (Not necessarily true. What about text labels) */ |
| 719 | |
| 720 | struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (fi->pc); |
| 721 | |
| 722 | if (msymbol != NULL |
| 723 | && (SYMBOL_VALUE_ADDRESS (msymbol) |
| 724 | > BLOCK_START (SYMBOL_BLOCK_VALUE (func)))) |
| 725 | funname = SYMBOL_NAME (msymbol); |
| 726 | else |
| 727 | funname = SYMBOL_NAME (func); |
| 728 | } |
| 729 | else |
| 730 | { |
| 731 | register struct minimal_symbol *msymbol = |
| 732 | lookup_minimal_symbol_by_pc (fi->pc); |
| 733 | |
| 734 | if (msymbol != NULL) |
| 735 | funname = SYMBOL_NAME (msymbol); |
| 736 | } |
| 737 | |
| 738 | the_common = find_common_for_function (comname, funname); |
| 739 | |
| 740 | return (the_common ? 1 : 0); |
| 741 | } |
| 742 | |
| 743 | void |
| 744 | _initialize_f_valprint () |
| 745 | { |
| 746 | add_info ("common", info_common_command, |
| 747 | "Print out the values contained in a Fortran COMMON block."); |
| 748 | } |