| 1 | /* Fortran language support routines for GDB, the GNU debugger. |
| 2 | Copyright 1993, 1994, 1996 Free Software Foundation, Inc. |
| 3 | Contributed by Motorola. Adapted from the C parser by Farooq Butt |
| 4 | (fmbutt@engage.sps.mot.com). |
| 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
| 21 | |
| 22 | #include "defs.h" |
| 23 | #include "gdb_string.h" |
| 24 | #include "symtab.h" |
| 25 | #include "gdbtypes.h" |
| 26 | #include "expression.h" |
| 27 | #include "parser-defs.h" |
| 28 | #include "language.h" |
| 29 | #include "f-lang.h" |
| 30 | |
| 31 | /* The built-in types of F77. FIXME: integer*4 is missing, plain |
| 32 | logical is missing (builtin_type_logical is logical*4). */ |
| 33 | |
| 34 | struct type *builtin_type_f_character; |
| 35 | struct type *builtin_type_f_logical; |
| 36 | struct type *builtin_type_f_logical_s1; |
| 37 | struct type *builtin_type_f_logical_s2; |
| 38 | struct type *builtin_type_f_integer; |
| 39 | struct type *builtin_type_f_integer_s2; |
| 40 | struct type *builtin_type_f_real; |
| 41 | struct type *builtin_type_f_real_s8; |
| 42 | struct type *builtin_type_f_real_s16; |
| 43 | struct type *builtin_type_f_complex_s8; |
| 44 | struct type *builtin_type_f_complex_s16; |
| 45 | struct type *builtin_type_f_complex_s32; |
| 46 | struct type *builtin_type_f_void; |
| 47 | |
| 48 | /* Following is dubious stuff that had been in the xcoff reader. */ |
| 49 | |
| 50 | struct saved_fcn |
| 51 | { |
| 52 | long line_offset; /* Line offset for function */ |
| 53 | struct saved_fcn *next; |
| 54 | }; |
| 55 | |
| 56 | |
| 57 | struct saved_bf_symnum |
| 58 | { |
| 59 | long symnum_fcn; /* Symnum of function (i.e. .function directive) */ |
| 60 | long symnum_bf; /* Symnum of .bf for this function */ |
| 61 | struct saved_bf_symnum *next; |
| 62 | }; |
| 63 | |
| 64 | typedef struct saved_fcn SAVED_FUNCTION, *SAVED_FUNCTION_PTR; |
| 65 | typedef struct saved_bf_symnum SAVED_BF, *SAVED_BF_PTR; |
| 66 | |
| 67 | /* Local functions */ |
| 68 | |
| 69 | #if 0 |
| 70 | static void clear_function_list PARAMS ((void)); |
| 71 | static long get_bf_for_fcn PARAMS ((long)); |
| 72 | static void clear_bf_list PARAMS ((void)); |
| 73 | static void patch_all_commons_by_name PARAMS ((char *, CORE_ADDR, int)); |
| 74 | static SAVED_F77_COMMON_PTR find_first_common_named PARAMS ((char *)); |
| 75 | static void add_common_entry PARAMS ((struct symbol *)); |
| 76 | static void add_common_block PARAMS ((char *, CORE_ADDR, int, char *)); |
| 77 | static SAVED_FUNCTION *allocate_saved_function_node PARAMS ((void)); |
| 78 | static SAVED_BF_PTR allocate_saved_bf_node PARAMS ((void)); |
| 79 | static COMMON_ENTRY_PTR allocate_common_entry_node PARAMS ((void)); |
| 80 | static SAVED_F77_COMMON_PTR allocate_saved_f77_common_node PARAMS ((void)); |
| 81 | static void patch_common_entries PARAMS ((SAVED_F77_COMMON_PTR, CORE_ADDR, int)); |
| 82 | #endif |
| 83 | |
| 84 | static struct type *f_create_fundamental_type PARAMS ((struct objfile *, int)); |
| 85 | static void f_printstr PARAMS ((GDB_FILE *stream, char *string, unsigned int length, int width, int force_ellipses)); |
| 86 | static void f_printchar PARAMS ((int c, GDB_FILE *stream)); |
| 87 | static void f_emit_char PARAMS ((int c, GDB_FILE *stream, int quoter)); |
| 88 | |
| 89 | /* Print the character C on STREAM as part of the contents of a literal |
| 90 | string whose delimiter is QUOTER. Note that that format for printing |
| 91 | characters and strings is language specific. |
| 92 | FIXME: This is a copy of the same function from c-exp.y. It should |
| 93 | be replaced with a true F77 version. */ |
| 94 | |
| 95 | static void |
| 96 | f_emit_char (c, stream, quoter) |
| 97 | register int c; |
| 98 | GDB_FILE *stream; |
| 99 | int quoter; |
| 100 | { |
| 101 | c &= 0xFF; /* Avoid sign bit follies */ |
| 102 | |
| 103 | if (PRINT_LITERAL_FORM (c)) |
| 104 | { |
| 105 | if (c == '\\' || c == quoter) |
| 106 | fputs_filtered ("\\", stream); |
| 107 | fprintf_filtered (stream, "%c", c); |
| 108 | } |
| 109 | else |
| 110 | { |
| 111 | switch (c) |
| 112 | { |
| 113 | case '\n': |
| 114 | fputs_filtered ("\\n", stream); |
| 115 | break; |
| 116 | case '\b': |
| 117 | fputs_filtered ("\\b", stream); |
| 118 | break; |
| 119 | case '\t': |
| 120 | fputs_filtered ("\\t", stream); |
| 121 | break; |
| 122 | case '\f': |
| 123 | fputs_filtered ("\\f", stream); |
| 124 | break; |
| 125 | case '\r': |
| 126 | fputs_filtered ("\\r", stream); |
| 127 | break; |
| 128 | case '\033': |
| 129 | fputs_filtered ("\\e", stream); |
| 130 | break; |
| 131 | case '\007': |
| 132 | fputs_filtered ("\\a", stream); |
| 133 | break; |
| 134 | default: |
| 135 | fprintf_filtered (stream, "\\%.3o", (unsigned int) c); |
| 136 | break; |
| 137 | } |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | /* FIXME: This is a copy of the same function from c-exp.y. It should |
| 142 | be replaced with a true F77version. */ |
| 143 | |
| 144 | static void |
| 145 | f_printchar (c, stream) |
| 146 | int c; |
| 147 | GDB_FILE *stream; |
| 148 | { |
| 149 | fputs_filtered ("'", stream); |
| 150 | LA_EMIT_CHAR (c, stream, '\''); |
| 151 | fputs_filtered ("'", stream); |
| 152 | } |
| 153 | |
| 154 | /* Print the character string STRING, printing at most LENGTH characters. |
| 155 | Printing stops early if the number hits print_max; repeat counts |
| 156 | are printed as appropriate. Print ellipses at the end if we |
| 157 | had to stop before printing LENGTH characters, or if FORCE_ELLIPSES. |
| 158 | FIXME: This is a copy of the same function from c-exp.y. It should |
| 159 | be replaced with a true F77 version. */ |
| 160 | |
| 161 | static void |
| 162 | f_printstr (stream, string, length, width, force_ellipses) |
| 163 | GDB_FILE *stream; |
| 164 | char *string; |
| 165 | unsigned int length; |
| 166 | int width; |
| 167 | int force_ellipses; |
| 168 | { |
| 169 | register unsigned int i; |
| 170 | unsigned int things_printed = 0; |
| 171 | int in_quotes = 0; |
| 172 | int need_comma = 0; |
| 173 | extern int inspect_it; |
| 174 | extern int repeat_count_threshold; |
| 175 | extern int print_max; |
| 176 | |
| 177 | if (length == 0) |
| 178 | { |
| 179 | fputs_filtered ("''", gdb_stdout); |
| 180 | return; |
| 181 | } |
| 182 | |
| 183 | for (i = 0; i < length && things_printed < print_max; ++i) |
| 184 | { |
| 185 | /* Position of the character we are examining |
| 186 | to see whether it is repeated. */ |
| 187 | unsigned int rep1; |
| 188 | /* Number of repetitions we have detected so far. */ |
| 189 | unsigned int reps; |
| 190 | |
| 191 | QUIT; |
| 192 | |
| 193 | if (need_comma) |
| 194 | { |
| 195 | fputs_filtered (", ", stream); |
| 196 | need_comma = 0; |
| 197 | } |
| 198 | |
| 199 | rep1 = i + 1; |
| 200 | reps = 1; |
| 201 | while (rep1 < length && string[rep1] == string[i]) |
| 202 | { |
| 203 | ++rep1; |
| 204 | ++reps; |
| 205 | } |
| 206 | |
| 207 | if (reps > repeat_count_threshold) |
| 208 | { |
| 209 | if (in_quotes) |
| 210 | { |
| 211 | if (inspect_it) |
| 212 | fputs_filtered ("\\', ", stream); |
| 213 | else |
| 214 | fputs_filtered ("', ", stream); |
| 215 | in_quotes = 0; |
| 216 | } |
| 217 | f_printchar (string[i], stream); |
| 218 | fprintf_filtered (stream, " <repeats %u times>", reps); |
| 219 | i = rep1 - 1; |
| 220 | things_printed += repeat_count_threshold; |
| 221 | need_comma = 1; |
| 222 | } |
| 223 | else |
| 224 | { |
| 225 | if (!in_quotes) |
| 226 | { |
| 227 | if (inspect_it) |
| 228 | fputs_filtered ("\\'", stream); |
| 229 | else |
| 230 | fputs_filtered ("'", stream); |
| 231 | in_quotes = 1; |
| 232 | } |
| 233 | LA_EMIT_CHAR (string[i], stream, '"'); |
| 234 | ++things_printed; |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | /* Terminate the quotes if necessary. */ |
| 239 | if (in_quotes) |
| 240 | { |
| 241 | if (inspect_it) |
| 242 | fputs_filtered ("\\'", stream); |
| 243 | else |
| 244 | fputs_filtered ("'", stream); |
| 245 | } |
| 246 | |
| 247 | if (force_ellipses || i < length) |
| 248 | fputs_filtered ("...", stream); |
| 249 | } |
| 250 | |
| 251 | /* FIXME: This is a copy of c_create_fundamental_type(), before |
| 252 | all the non-C types were stripped from it. Needs to be fixed |
| 253 | by an experienced F77 programmer. */ |
| 254 | |
| 255 | static struct type * |
| 256 | f_create_fundamental_type (objfile, typeid) |
| 257 | struct objfile *objfile; |
| 258 | int typeid; |
| 259 | { |
| 260 | register struct type *type = NULL; |
| 261 | |
| 262 | switch (typeid) |
| 263 | { |
| 264 | case FT_VOID: |
| 265 | type = init_type (TYPE_CODE_VOID, |
| 266 | TARGET_CHAR_BIT / TARGET_CHAR_BIT, |
| 267 | 0, "VOID", objfile); |
| 268 | break; |
| 269 | case FT_BOOLEAN: |
| 270 | type = init_type (TYPE_CODE_BOOL, |
| 271 | TARGET_CHAR_BIT / TARGET_CHAR_BIT, |
| 272 | TYPE_FLAG_UNSIGNED, "boolean", objfile); |
| 273 | break; |
| 274 | case FT_STRING: |
| 275 | type = init_type (TYPE_CODE_STRING, |
| 276 | TARGET_CHAR_BIT / TARGET_CHAR_BIT, |
| 277 | 0, "string", objfile); |
| 278 | break; |
| 279 | case FT_CHAR: |
| 280 | type = init_type (TYPE_CODE_INT, |
| 281 | TARGET_CHAR_BIT / TARGET_CHAR_BIT, |
| 282 | 0, "character", objfile); |
| 283 | break; |
| 284 | case FT_SIGNED_CHAR: |
| 285 | type = init_type (TYPE_CODE_INT, |
| 286 | TARGET_CHAR_BIT / TARGET_CHAR_BIT, |
| 287 | 0, "integer*1", objfile); |
| 288 | break; |
| 289 | case FT_UNSIGNED_CHAR: |
| 290 | type = init_type (TYPE_CODE_BOOL, |
| 291 | TARGET_CHAR_BIT / TARGET_CHAR_BIT, |
| 292 | TYPE_FLAG_UNSIGNED, "logical*1", objfile); |
| 293 | break; |
| 294 | case FT_SHORT: |
| 295 | type = init_type (TYPE_CODE_INT, |
| 296 | TARGET_SHORT_BIT / TARGET_CHAR_BIT, |
| 297 | 0, "integer*2", objfile); |
| 298 | break; |
| 299 | case FT_SIGNED_SHORT: |
| 300 | type = init_type (TYPE_CODE_INT, |
| 301 | TARGET_SHORT_BIT / TARGET_CHAR_BIT, |
| 302 | 0, "short", objfile); /* FIXME-fnf */ |
| 303 | break; |
| 304 | case FT_UNSIGNED_SHORT: |
| 305 | type = init_type (TYPE_CODE_BOOL, |
| 306 | TARGET_SHORT_BIT / TARGET_CHAR_BIT, |
| 307 | TYPE_FLAG_UNSIGNED, "logical*2", objfile); |
| 308 | break; |
| 309 | case FT_INTEGER: |
| 310 | type = init_type (TYPE_CODE_INT, |
| 311 | TARGET_INT_BIT / TARGET_CHAR_BIT, |
| 312 | 0, "integer*4", objfile); |
| 313 | break; |
| 314 | case FT_SIGNED_INTEGER: |
| 315 | type = init_type (TYPE_CODE_INT, |
| 316 | TARGET_INT_BIT / TARGET_CHAR_BIT, |
| 317 | 0, "integer", objfile); /* FIXME -fnf */ |
| 318 | break; |
| 319 | case FT_UNSIGNED_INTEGER: |
| 320 | type = init_type (TYPE_CODE_BOOL, |
| 321 | TARGET_INT_BIT / TARGET_CHAR_BIT, |
| 322 | TYPE_FLAG_UNSIGNED, "logical*4", objfile); |
| 323 | break; |
| 324 | case FT_FIXED_DECIMAL: |
| 325 | type = init_type (TYPE_CODE_INT, |
| 326 | TARGET_INT_BIT / TARGET_CHAR_BIT, |
| 327 | 0, "fixed decimal", objfile); |
| 328 | break; |
| 329 | case FT_LONG: |
| 330 | type = init_type (TYPE_CODE_INT, |
| 331 | TARGET_LONG_BIT / TARGET_CHAR_BIT, |
| 332 | 0, "long", objfile); |
| 333 | break; |
| 334 | case FT_SIGNED_LONG: |
| 335 | type = init_type (TYPE_CODE_INT, |
| 336 | TARGET_LONG_BIT / TARGET_CHAR_BIT, |
| 337 | 0, "long", objfile); /* FIXME -fnf */ |
| 338 | break; |
| 339 | case FT_UNSIGNED_LONG: |
| 340 | type = init_type (TYPE_CODE_INT, |
| 341 | TARGET_LONG_BIT / TARGET_CHAR_BIT, |
| 342 | TYPE_FLAG_UNSIGNED, "unsigned long", objfile); |
| 343 | break; |
| 344 | case FT_LONG_LONG: |
| 345 | type = init_type (TYPE_CODE_INT, |
| 346 | TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT, |
| 347 | 0, "long long", objfile); |
| 348 | break; |
| 349 | case FT_SIGNED_LONG_LONG: |
| 350 | type = init_type (TYPE_CODE_INT, |
| 351 | TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT, |
| 352 | 0, "signed long long", objfile); |
| 353 | break; |
| 354 | case FT_UNSIGNED_LONG_LONG: |
| 355 | type = init_type (TYPE_CODE_INT, |
| 356 | TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT, |
| 357 | TYPE_FLAG_UNSIGNED, "unsigned long long", objfile); |
| 358 | break; |
| 359 | case FT_FLOAT: |
| 360 | type = init_type (TYPE_CODE_FLT, |
| 361 | TARGET_FLOAT_BIT / TARGET_CHAR_BIT, |
| 362 | 0, "real", objfile); |
| 363 | break; |
| 364 | case FT_DBL_PREC_FLOAT: |
| 365 | type = init_type (TYPE_CODE_FLT, |
| 366 | TARGET_DOUBLE_BIT / TARGET_CHAR_BIT, |
| 367 | 0, "real*8", objfile); |
| 368 | break; |
| 369 | case FT_FLOAT_DECIMAL: |
| 370 | type = init_type (TYPE_CODE_FLT, |
| 371 | TARGET_DOUBLE_BIT / TARGET_CHAR_BIT, |
| 372 | 0, "floating decimal", objfile); |
| 373 | break; |
| 374 | case FT_EXT_PREC_FLOAT: |
| 375 | type = init_type (TYPE_CODE_FLT, |
| 376 | TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT, |
| 377 | 0, "real*16", objfile); |
| 378 | break; |
| 379 | case FT_COMPLEX: |
| 380 | type = init_type (TYPE_CODE_COMPLEX, |
| 381 | 2 * TARGET_FLOAT_BIT / TARGET_CHAR_BIT, |
| 382 | 0, "complex*8", objfile); |
| 383 | TYPE_TARGET_TYPE (type) = builtin_type_f_real; |
| 384 | break; |
| 385 | case FT_DBL_PREC_COMPLEX: |
| 386 | type = init_type (TYPE_CODE_COMPLEX, |
| 387 | 2 * TARGET_DOUBLE_BIT / TARGET_CHAR_BIT, |
| 388 | 0, "complex*16", objfile); |
| 389 | TYPE_TARGET_TYPE (type) = builtin_type_f_real_s8; |
| 390 | break; |
| 391 | case FT_EXT_PREC_COMPLEX: |
| 392 | type = init_type (TYPE_CODE_COMPLEX, |
| 393 | 2 * TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT, |
| 394 | 0, "complex*32", objfile); |
| 395 | TYPE_TARGET_TYPE (type) = builtin_type_f_real_s16; |
| 396 | break; |
| 397 | default: |
| 398 | /* FIXME: For now, if we are asked to produce a type not in this |
| 399 | language, create the equivalent of a C integer type with the |
| 400 | name "<?type?>". When all the dust settles from the type |
| 401 | reconstruction work, this should probably become an error. */ |
| 402 | type = init_type (TYPE_CODE_INT, |
| 403 | TARGET_INT_BIT / TARGET_CHAR_BIT, |
| 404 | 0, "<?type?>", objfile); |
| 405 | warning ("internal error: no F77 fundamental type %d", typeid); |
| 406 | break; |
| 407 | } |
| 408 | return (type); |
| 409 | } |
| 410 | |
| 411 | \f |
| 412 | /* Table of operators and their precedences for printing expressions. */ |
| 413 | |
| 414 | static const struct op_print f_op_print_tab[] = { |
| 415 | { "+", BINOP_ADD, PREC_ADD, 0 }, |
| 416 | { "+", UNOP_PLUS, PREC_PREFIX, 0 }, |
| 417 | { "-", BINOP_SUB, PREC_ADD, 0 }, |
| 418 | { "-", UNOP_NEG, PREC_PREFIX, 0 }, |
| 419 | { "*", BINOP_MUL, PREC_MUL, 0 }, |
| 420 | { "/", BINOP_DIV, PREC_MUL, 0 }, |
| 421 | { "DIV", BINOP_INTDIV, PREC_MUL, 0 }, |
| 422 | { "MOD", BINOP_REM, PREC_MUL, 0 }, |
| 423 | { "=", BINOP_ASSIGN, PREC_ASSIGN, 1 }, |
| 424 | { ".OR.", BINOP_LOGICAL_OR, PREC_LOGICAL_OR, 0 }, |
| 425 | { ".AND.", BINOP_LOGICAL_AND, PREC_LOGICAL_AND, 0 }, |
| 426 | { ".NOT.", UNOP_LOGICAL_NOT, PREC_PREFIX, 0 }, |
| 427 | { ".EQ.", BINOP_EQUAL, PREC_EQUAL, 0 }, |
| 428 | { ".NE.", BINOP_NOTEQUAL, PREC_EQUAL, 0 }, |
| 429 | { ".LE.", BINOP_LEQ, PREC_ORDER, 0 }, |
| 430 | { ".GE.", BINOP_GEQ, PREC_ORDER, 0 }, |
| 431 | { ".GT.", BINOP_GTR, PREC_ORDER, 0 }, |
| 432 | { ".LT.", BINOP_LESS, PREC_ORDER, 0 }, |
| 433 | { "**", UNOP_IND, PREC_PREFIX, 0 }, |
| 434 | { "@", BINOP_REPEAT, PREC_REPEAT, 0 }, |
| 435 | { NULL, 0, 0, 0 } |
| 436 | }; |
| 437 | \f |
| 438 | struct type ** CONST_PTR (f_builtin_types[]) = |
| 439 | { |
| 440 | &builtin_type_f_character, |
| 441 | &builtin_type_f_logical, |
| 442 | &builtin_type_f_logical_s1, |
| 443 | &builtin_type_f_logical_s2, |
| 444 | &builtin_type_f_integer, |
| 445 | &builtin_type_f_integer_s2, |
| 446 | &builtin_type_f_real, |
| 447 | &builtin_type_f_real_s8, |
| 448 | &builtin_type_f_real_s16, |
| 449 | &builtin_type_f_complex_s8, |
| 450 | &builtin_type_f_complex_s16, |
| 451 | #if 0 |
| 452 | &builtin_type_f_complex_s32, |
| 453 | #endif |
| 454 | &builtin_type_f_void, |
| 455 | 0 |
| 456 | }; |
| 457 | |
| 458 | /* This is declared in c-lang.h but it is silly to import that file for what |
| 459 | is already just a hack. */ |
| 460 | extern int |
| 461 | c_value_print PARAMS ((struct value *, GDB_FILE *, int, enum val_prettyprint)); |
| 462 | |
| 463 | const struct language_defn f_language_defn = { |
| 464 | "fortran", |
| 465 | language_fortran, |
| 466 | f_builtin_types, |
| 467 | range_check_on, |
| 468 | type_check_on, |
| 469 | f_parse, /* parser */ |
| 470 | f_error, /* parser error function */ |
| 471 | evaluate_subexp_standard, |
| 472 | f_printchar, /* Print character constant */ |
| 473 | f_printstr, /* function to print string constant */ |
| 474 | f_emit_char, /* Function to print a single character */ |
| 475 | f_create_fundamental_type, /* Create fundamental type in this language */ |
| 476 | f_print_type, /* Print a type using appropriate syntax */ |
| 477 | f_val_print, /* Print a value using appropriate syntax */ |
| 478 | c_value_print, /* FIXME */ |
| 479 | {"", "", "", ""}, /* Binary format info */ |
| 480 | {"0%o", "0", "o", ""}, /* Octal format info */ |
| 481 | {"%d", "", "d", ""}, /* Decimal format info */ |
| 482 | {"0x%x", "0x", "x", ""}, /* Hex format info */ |
| 483 | f_op_print_tab, /* expression operators for printing */ |
| 484 | 0, /* arrays are first-class (not c-style) */ |
| 485 | 1, /* String lower bound */ |
| 486 | &builtin_type_f_character, /* Type of string elements */ |
| 487 | LANG_MAGIC |
| 488 | }; |
| 489 | |
| 490 | void |
| 491 | _initialize_f_language () |
| 492 | { |
| 493 | builtin_type_f_void = |
| 494 | init_type (TYPE_CODE_VOID, 1, |
| 495 | 0, |
| 496 | "VOID", (struct objfile *) NULL); |
| 497 | |
| 498 | builtin_type_f_character = |
| 499 | init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT, |
| 500 | 0, |
| 501 | "character", (struct objfile *) NULL); |
| 502 | |
| 503 | builtin_type_f_logical_s1 = |
| 504 | init_type (TYPE_CODE_BOOL, TARGET_CHAR_BIT / TARGET_CHAR_BIT, |
| 505 | TYPE_FLAG_UNSIGNED, |
| 506 | "logical*1", (struct objfile *) NULL); |
| 507 | |
| 508 | builtin_type_f_integer_s2 = |
| 509 | init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT, |
| 510 | 0, |
| 511 | "integer*2", (struct objfile *) NULL); |
| 512 | |
| 513 | builtin_type_f_logical_s2 = |
| 514 | init_type (TYPE_CODE_BOOL, TARGET_SHORT_BIT / TARGET_CHAR_BIT, |
| 515 | TYPE_FLAG_UNSIGNED, |
| 516 | "logical*2", (struct objfile *) NULL); |
| 517 | |
| 518 | builtin_type_f_integer = |
| 519 | init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT, |
| 520 | 0, |
| 521 | "integer", (struct objfile *) NULL); |
| 522 | |
| 523 | builtin_type_f_logical = |
| 524 | init_type (TYPE_CODE_BOOL, TARGET_INT_BIT / TARGET_CHAR_BIT, |
| 525 | TYPE_FLAG_UNSIGNED, |
| 526 | "logical*4", (struct objfile *) NULL); |
| 527 | |
| 528 | builtin_type_f_real = |
| 529 | init_type (TYPE_CODE_FLT, TARGET_FLOAT_BIT / TARGET_CHAR_BIT, |
| 530 | 0, |
| 531 | "real", (struct objfile *) NULL); |
| 532 | |
| 533 | builtin_type_f_real_s8 = |
| 534 | init_type (TYPE_CODE_FLT, TARGET_DOUBLE_BIT / TARGET_CHAR_BIT, |
| 535 | 0, |
| 536 | "real*8", (struct objfile *) NULL); |
| 537 | |
| 538 | builtin_type_f_real_s16 = |
| 539 | init_type (TYPE_CODE_FLT, TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT, |
| 540 | 0, |
| 541 | "real*16", (struct objfile *) NULL); |
| 542 | |
| 543 | builtin_type_f_complex_s8 = |
| 544 | init_type (TYPE_CODE_COMPLEX, 2 * TARGET_FLOAT_BIT / TARGET_CHAR_BIT, |
| 545 | 0, |
| 546 | "complex*8", (struct objfile *) NULL); |
| 547 | TYPE_TARGET_TYPE (builtin_type_f_complex_s8) = builtin_type_f_real; |
| 548 | |
| 549 | builtin_type_f_complex_s16 = |
| 550 | init_type (TYPE_CODE_COMPLEX, 2 * TARGET_DOUBLE_BIT / TARGET_CHAR_BIT, |
| 551 | 0, |
| 552 | "complex*16", (struct objfile *) NULL); |
| 553 | TYPE_TARGET_TYPE (builtin_type_f_complex_s16) = builtin_type_f_real_s8; |
| 554 | |
| 555 | /* We have a new size == 4 double floats for the |
| 556 | complex*32 data type */ |
| 557 | |
| 558 | builtin_type_f_complex_s32 = |
| 559 | init_type (TYPE_CODE_COMPLEX, 2 * TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT, |
| 560 | 0, |
| 561 | "complex*32", (struct objfile *) NULL); |
| 562 | TYPE_TARGET_TYPE (builtin_type_f_complex_s32) = builtin_type_f_real_s16; |
| 563 | |
| 564 | builtin_type_string = |
| 565 | init_type (TYPE_CODE_STRING, TARGET_CHAR_BIT / TARGET_CHAR_BIT, |
| 566 | 0, |
| 567 | "character string", (struct objfile *) NULL); |
| 568 | |
| 569 | add_language (&f_language_defn); |
| 570 | } |
| 571 | |
| 572 | #if 0 |
| 573 | static SAVED_BF_PTR |
| 574 | allocate_saved_bf_node() |
| 575 | { |
| 576 | SAVED_BF_PTR new; |
| 577 | |
| 578 | new = (SAVED_BF_PTR) xmalloc (sizeof (SAVED_BF)); |
| 579 | return(new); |
| 580 | } |
| 581 | |
| 582 | static SAVED_FUNCTION * |
| 583 | allocate_saved_function_node() |
| 584 | { |
| 585 | SAVED_FUNCTION *new; |
| 586 | |
| 587 | new = (SAVED_FUNCTION *) xmalloc (sizeof (SAVED_FUNCTION)); |
| 588 | return(new); |
| 589 | } |
| 590 | |
| 591 | static SAVED_F77_COMMON_PTR allocate_saved_f77_common_node() |
| 592 | { |
| 593 | SAVED_F77_COMMON_PTR new; |
| 594 | |
| 595 | new = (SAVED_F77_COMMON_PTR) xmalloc (sizeof (SAVED_F77_COMMON)); |
| 596 | return(new); |
| 597 | } |
| 598 | |
| 599 | static COMMON_ENTRY_PTR allocate_common_entry_node() |
| 600 | { |
| 601 | COMMON_ENTRY_PTR new; |
| 602 | |
| 603 | new = (COMMON_ENTRY_PTR) xmalloc (sizeof (COMMON_ENTRY)); |
| 604 | return(new); |
| 605 | } |
| 606 | #endif |
| 607 | |
| 608 | SAVED_F77_COMMON_PTR head_common_list=NULL; /* Ptr to 1st saved COMMON */ |
| 609 | SAVED_F77_COMMON_PTR tail_common_list=NULL; /* Ptr to last saved COMMON */ |
| 610 | SAVED_F77_COMMON_PTR current_common=NULL; /* Ptr to current COMMON */ |
| 611 | |
| 612 | #if 0 |
| 613 | static SAVED_BF_PTR saved_bf_list=NULL; /* Ptr to (.bf,function) |
| 614 | list*/ |
| 615 | static SAVED_BF_PTR saved_bf_list_end=NULL; /* Ptr to above list's end */ |
| 616 | static SAVED_BF_PTR current_head_bf_list=NULL; /* Current head of above list |
| 617 | */ |
| 618 | |
| 619 | static SAVED_BF_PTR tmp_bf_ptr; /* Generic temporary for use |
| 620 | in macros */ |
| 621 | |
| 622 | /* The following function simply enters a given common block onto |
| 623 | the global common block chain */ |
| 624 | |
| 625 | static void |
| 626 | add_common_block(name,offset,secnum,func_stab) |
| 627 | char *name; |
| 628 | CORE_ADDR offset; |
| 629 | int secnum; |
| 630 | char *func_stab; |
| 631 | { |
| 632 | SAVED_F77_COMMON_PTR tmp; |
| 633 | char *c,*local_copy_func_stab; |
| 634 | |
| 635 | /* If the COMMON block we are trying to add has a blank |
| 636 | name (i.e. "#BLNK_COM") then we set it to __BLANK |
| 637 | because the darn "#" character makes GDB's input |
| 638 | parser have fits. */ |
| 639 | |
| 640 | |
| 641 | if (STREQ(name,BLANK_COMMON_NAME_ORIGINAL) || |
| 642 | STREQ(name,BLANK_COMMON_NAME_MF77)) |
| 643 | { |
| 644 | |
| 645 | free(name); |
| 646 | name = alloca(strlen(BLANK_COMMON_NAME_LOCAL) + 1); |
| 647 | strcpy(name,BLANK_COMMON_NAME_LOCAL); |
| 648 | } |
| 649 | |
| 650 | tmp = allocate_saved_f77_common_node(); |
| 651 | |
| 652 | local_copy_func_stab = xmalloc (strlen(func_stab) + 1); |
| 653 | strcpy(local_copy_func_stab,func_stab); |
| 654 | |
| 655 | tmp->name = xmalloc(strlen(name) + 1); |
| 656 | |
| 657 | /* local_copy_func_stab is a stabstring, let us first extract the |
| 658 | function name from the stab by NULLing out the ':' character. */ |
| 659 | |
| 660 | |
| 661 | c = NULL; |
| 662 | c = strchr(local_copy_func_stab,':'); |
| 663 | |
| 664 | if (c) |
| 665 | *c = '\0'; |
| 666 | else |
| 667 | error("Malformed function STAB found in add_common_block()"); |
| 668 | |
| 669 | |
| 670 | tmp->owning_function = xmalloc (strlen(local_copy_func_stab) + 1); |
| 671 | |
| 672 | strcpy(tmp->owning_function,local_copy_func_stab); |
| 673 | |
| 674 | strcpy(tmp->name,name); |
| 675 | tmp->offset = offset; |
| 676 | tmp->next = NULL; |
| 677 | tmp->entries = NULL; |
| 678 | tmp->secnum = secnum; |
| 679 | |
| 680 | current_common = tmp; |
| 681 | |
| 682 | if (head_common_list == NULL) |
| 683 | { |
| 684 | head_common_list = tail_common_list = tmp; |
| 685 | } |
| 686 | else |
| 687 | { |
| 688 | tail_common_list->next = tmp; |
| 689 | tail_common_list = tmp; |
| 690 | } |
| 691 | } |
| 692 | #endif |
| 693 | |
| 694 | /* The following function simply enters a given common entry onto |
| 695 | the "current_common" block that has been saved away. */ |
| 696 | |
| 697 | #if 0 |
| 698 | static void |
| 699 | add_common_entry(entry_sym_ptr) |
| 700 | struct symbol *entry_sym_ptr; |
| 701 | { |
| 702 | COMMON_ENTRY_PTR tmp; |
| 703 | |
| 704 | |
| 705 | |
| 706 | /* The order of this list is important, since |
| 707 | we expect the entries to appear in decl. |
| 708 | order when we later issue "info common" calls */ |
| 709 | |
| 710 | tmp = allocate_common_entry_node(); |
| 711 | |
| 712 | tmp->next = NULL; |
| 713 | tmp->symbol = entry_sym_ptr; |
| 714 | |
| 715 | if (current_common == NULL) |
| 716 | error("Attempt to add COMMON entry with no block open!"); |
| 717 | else |
| 718 | { |
| 719 | if (current_common->entries == NULL) |
| 720 | { |
| 721 | current_common->entries = tmp; |
| 722 | current_common->end_of_entries = tmp; |
| 723 | } |
| 724 | else |
| 725 | { |
| 726 | current_common->end_of_entries->next = tmp; |
| 727 | current_common->end_of_entries = tmp; |
| 728 | } |
| 729 | } |
| 730 | } |
| 731 | #endif |
| 732 | |
| 733 | /* This routine finds the first encountred COMMON block named "name" */ |
| 734 | |
| 735 | #if 0 |
| 736 | static SAVED_F77_COMMON_PTR |
| 737 | find_first_common_named(name) |
| 738 | char *name; |
| 739 | { |
| 740 | |
| 741 | SAVED_F77_COMMON_PTR tmp; |
| 742 | |
| 743 | tmp = head_common_list; |
| 744 | |
| 745 | while (tmp != NULL) |
| 746 | { |
| 747 | if (STREQ(tmp->name,name)) |
| 748 | return(tmp); |
| 749 | else |
| 750 | tmp = tmp->next; |
| 751 | } |
| 752 | return(NULL); |
| 753 | } |
| 754 | #endif |
| 755 | |
| 756 | /* This routine finds the first encountred COMMON block named "name" |
| 757 | that belongs to function funcname */ |
| 758 | |
| 759 | SAVED_F77_COMMON_PTR find_common_for_function(name, funcname) |
| 760 | char *name; |
| 761 | char *funcname; |
| 762 | { |
| 763 | |
| 764 | SAVED_F77_COMMON_PTR tmp; |
| 765 | |
| 766 | tmp = head_common_list; |
| 767 | |
| 768 | while (tmp != NULL) |
| 769 | { |
| 770 | if (STREQ(tmp->name,name) && STREQ(tmp->owning_function,funcname)) |
| 771 | return(tmp); |
| 772 | else |
| 773 | tmp = tmp->next; |
| 774 | } |
| 775 | return(NULL); |
| 776 | } |
| 777 | |
| 778 | |
| 779 | #if 0 |
| 780 | |
| 781 | /* The following function is called to patch up the offsets |
| 782 | for the statics contained in the COMMON block named |
| 783 | "name." */ |
| 784 | |
| 785 | static void |
| 786 | patch_common_entries (blk, offset, secnum) |
| 787 | SAVED_F77_COMMON_PTR blk; |
| 788 | CORE_ADDR offset; |
| 789 | int secnum; |
| 790 | { |
| 791 | COMMON_ENTRY_PTR entry; |
| 792 | |
| 793 | blk->offset = offset; /* Keep this around for future use. */ |
| 794 | |
| 795 | entry = blk->entries; |
| 796 | |
| 797 | while (entry != NULL) |
| 798 | { |
| 799 | SYMBOL_VALUE (entry->symbol) += offset; |
| 800 | SYMBOL_SECTION (entry->symbol) = secnum; |
| 801 | |
| 802 | entry = entry->next; |
| 803 | } |
| 804 | blk->secnum = secnum; |
| 805 | } |
| 806 | |
| 807 | /* Patch all commons named "name" that need patching.Since COMMON |
| 808 | blocks occur with relative infrequency, we simply do a linear scan on |
| 809 | the name. Eventually, the best way to do this will be a |
| 810 | hashed-lookup. Secnum is the section number for the .bss section |
| 811 | (which is where common data lives). */ |
| 812 | |
| 813 | static void |
| 814 | patch_all_commons_by_name (name, offset, secnum) |
| 815 | char *name; |
| 816 | CORE_ADDR offset; |
| 817 | int secnum; |
| 818 | { |
| 819 | |
| 820 | SAVED_F77_COMMON_PTR tmp; |
| 821 | |
| 822 | /* For blank common blocks, change the canonical reprsentation |
| 823 | of a blank name */ |
| 824 | |
| 825 | if ((STREQ(name,BLANK_COMMON_NAME_ORIGINAL)) || |
| 826 | (STREQ(name,BLANK_COMMON_NAME_MF77))) |
| 827 | { |
| 828 | free(name); |
| 829 | name = alloca(strlen(BLANK_COMMON_NAME_LOCAL) + 1); |
| 830 | strcpy(name,BLANK_COMMON_NAME_LOCAL); |
| 831 | } |
| 832 | |
| 833 | tmp = head_common_list; |
| 834 | |
| 835 | while (tmp != NULL) |
| 836 | { |
| 837 | if (COMMON_NEEDS_PATCHING(tmp)) |
| 838 | if (STREQ(tmp->name,name)) |
| 839 | patch_common_entries(tmp,offset,secnum); |
| 840 | |
| 841 | tmp = tmp->next; |
| 842 | } |
| 843 | } |
| 844 | #endif |
| 845 | |
| 846 | /* This macro adds the symbol-number for the start of the function |
| 847 | (the symbol number of the .bf) referenced by symnum_fcn to a |
| 848 | list. This list, in reality should be a FIFO queue but since |
| 849 | #line pragmas sometimes cause line ranges to get messed up |
| 850 | we simply create a linear list. This list can then be searched |
| 851 | first by a queueing algorithm and upon failure fall back to |
| 852 | a linear scan. */ |
| 853 | |
| 854 | #if 0 |
| 855 | #define ADD_BF_SYMNUM(bf_sym,fcn_sym) \ |
| 856 | \ |
| 857 | if (saved_bf_list == NULL) \ |
| 858 | { \ |
| 859 | tmp_bf_ptr = allocate_saved_bf_node(); \ |
| 860 | \ |
| 861 | tmp_bf_ptr->symnum_bf = (bf_sym); \ |
| 862 | tmp_bf_ptr->symnum_fcn = (fcn_sym); \ |
| 863 | tmp_bf_ptr->next = NULL; \ |
| 864 | \ |
| 865 | current_head_bf_list = saved_bf_list = tmp_bf_ptr; \ |
| 866 | saved_bf_list_end = tmp_bf_ptr; \ |
| 867 | } \ |
| 868 | else \ |
| 869 | { \ |
| 870 | tmp_bf_ptr = allocate_saved_bf_node(); \ |
| 871 | \ |
| 872 | tmp_bf_ptr->symnum_bf = (bf_sym); \ |
| 873 | tmp_bf_ptr->symnum_fcn = (fcn_sym); \ |
| 874 | tmp_bf_ptr->next = NULL; \ |
| 875 | \ |
| 876 | saved_bf_list_end->next = tmp_bf_ptr; \ |
| 877 | saved_bf_list_end = tmp_bf_ptr; \ |
| 878 | } |
| 879 | #endif |
| 880 | |
| 881 | /* This function frees the entire (.bf,function) list */ |
| 882 | |
| 883 | #if 0 |
| 884 | static void |
| 885 | clear_bf_list() |
| 886 | { |
| 887 | |
| 888 | SAVED_BF_PTR tmp = saved_bf_list; |
| 889 | SAVED_BF_PTR next = NULL; |
| 890 | |
| 891 | while (tmp != NULL) |
| 892 | { |
| 893 | next = tmp->next; |
| 894 | free(tmp); |
| 895 | tmp=next; |
| 896 | } |
| 897 | saved_bf_list = NULL; |
| 898 | } |
| 899 | #endif |
| 900 | |
| 901 | int global_remote_debug; |
| 902 | |
| 903 | #if 0 |
| 904 | |
| 905 | static long |
| 906 | get_bf_for_fcn (the_function) |
| 907 | long the_function; |
| 908 | { |
| 909 | SAVED_BF_PTR tmp; |
| 910 | int nprobes = 0; |
| 911 | |
| 912 | /* First use a simple queuing algorithm (i.e. look and see if the |
| 913 | item at the head of the queue is the one you want) */ |
| 914 | |
| 915 | if (saved_bf_list == NULL) |
| 916 | fatal ("cannot get .bf node off empty list"); |
| 917 | |
| 918 | if (current_head_bf_list != NULL) |
| 919 | if (current_head_bf_list->symnum_fcn == the_function) |
| 920 | { |
| 921 | if (global_remote_debug) |
| 922 | fprintf(stderr,"*"); |
| 923 | |
| 924 | tmp = current_head_bf_list; |
| 925 | current_head_bf_list = current_head_bf_list->next; |
| 926 | return(tmp->symnum_bf); |
| 927 | } |
| 928 | |
| 929 | /* If the above did not work (probably because #line directives were |
| 930 | used in the sourcefile and they messed up our internal tables) we now do |
| 931 | the ugly linear scan */ |
| 932 | |
| 933 | if (global_remote_debug) |
| 934 | fprintf(stderr,"\ndefaulting to linear scan\n"); |
| 935 | |
| 936 | nprobes = 0; |
| 937 | tmp = saved_bf_list; |
| 938 | while (tmp != NULL) |
| 939 | { |
| 940 | nprobes++; |
| 941 | if (tmp->symnum_fcn == the_function) |
| 942 | { |
| 943 | if (global_remote_debug) |
| 944 | fprintf(stderr,"Found in %d probes\n",nprobes); |
| 945 | current_head_bf_list = tmp->next; |
| 946 | return(tmp->symnum_bf); |
| 947 | } |
| 948 | tmp= tmp->next; |
| 949 | } |
| 950 | |
| 951 | return(-1); |
| 952 | } |
| 953 | |
| 954 | static SAVED_FUNCTION_PTR saved_function_list=NULL; |
| 955 | static SAVED_FUNCTION_PTR saved_function_list_end=NULL; |
| 956 | |
| 957 | static void |
| 958 | clear_function_list() |
| 959 | { |
| 960 | SAVED_FUNCTION_PTR tmp = saved_function_list; |
| 961 | SAVED_FUNCTION_PTR next = NULL; |
| 962 | |
| 963 | while (tmp != NULL) |
| 964 | { |
| 965 | next = tmp->next; |
| 966 | free(tmp); |
| 967 | tmp = next; |
| 968 | } |
| 969 | |
| 970 | saved_function_list = NULL; |
| 971 | } |
| 972 | #endif |
| 973 | |