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).
6 This file is part of GDB.
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.
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.
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. */
23 #include "gdb_string.h"
26 #include "expression.h"
27 #include "parser-defs.h"
31 /* The built-in types of F77. FIXME: integer*4 is missing, plain
32 logical is missing (builtin_type_logical is logical*4). */
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
;
48 /* Following is dubious stuff that had been in the xcoff reader. */
52 long line_offset
; /* Line offset for function */
53 struct saved_fcn
*next
;
57 struct saved_bf_symnum
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
;
64 typedef struct saved_fcn SAVED_FUNCTION
, *SAVED_FUNCTION_PTR
;
65 typedef struct saved_bf_symnum SAVED_BF
, *SAVED_BF_PTR
;
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));
84 static struct type
*f_create_fundamental_type
PARAMS ((struct objfile
*, int));
85 static void f_printstr
PARAMS ((FILE *, char *, unsigned int, int));
86 static void f_printchar
PARAMS ((int, FILE *));
87 static void emit_char
PARAMS ((int, FILE *, int));
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. */
96 emit_char (c
, stream
, quoter
)
101 c
&= 0xFF; /* Avoid sign bit follies */
103 if (PRINT_LITERAL_FORM (c
))
105 if (c
== '\\' || c
== quoter
)
106 fputs_filtered ("\\", stream
);
107 fprintf_filtered (stream
, "%c", c
);
114 fputs_filtered ("\\n", stream
);
117 fputs_filtered ("\\b", stream
);
120 fputs_filtered ("\\t", stream
);
123 fputs_filtered ("\\f", stream
);
126 fputs_filtered ("\\r", stream
);
129 fputs_filtered ("\\e", stream
);
132 fputs_filtered ("\\a", stream
);
135 fprintf_filtered (stream
, "\\%.3o", (unsigned int) c
);
141 /* FIXME: This is a copy of the same function from c-exp.y. It should
142 be replaced with a true F77version. */
145 f_printchar (c
, stream
)
149 fputs_filtered ("'", stream
);
150 emit_char (c
, stream
, '\'');
151 fputs_filtered ("'", stream
);
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. */
162 f_printstr (stream
, string
, length
, force_ellipses
)
168 register unsigned int i
;
169 unsigned int things_printed
= 0;
172 extern int inspect_it
;
173 extern int repeat_count_threshold
;
174 extern int print_max
;
178 fputs_filtered ("''", stdout
);
182 for (i
= 0; i
< length
&& things_printed
< print_max
; ++i
)
184 /* Position of the character we are examining
185 to see whether it is repeated. */
187 /* Number of repetitions we have detected so far. */
194 fputs_filtered (", ", stream
);
200 while (rep1
< length
&& string
[rep1
] == string
[i
])
206 if (reps
> repeat_count_threshold
)
211 fputs_filtered ("\\', ", stream
);
213 fputs_filtered ("', ", stream
);
216 f_printchar (string
[i
], stream
);
217 fprintf_filtered (stream
, " <repeats %u times>", reps
);
219 things_printed
+= repeat_count_threshold
;
227 fputs_filtered ("\\'", stream
);
229 fputs_filtered ("'", stream
);
232 emit_char (string
[i
], stream
, '"');
237 /* Terminate the quotes if necessary. */
241 fputs_filtered ("\\'", stream
);
243 fputs_filtered ("'", stream
);
246 if (force_ellipses
|| i
< length
)
247 fputs_filtered ("...", stream
);
250 /* FIXME: This is a copy of c_create_fundamental_type(), before
251 all the non-C types were stripped from it. Needs to be fixed
252 by an experienced F77 programmer. */
255 f_create_fundamental_type (objfile
, typeid)
256 struct objfile
*objfile
;
259 register struct type
*type
= NULL
;
264 type
= init_type (TYPE_CODE_VOID
,
265 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
269 type
= init_type (TYPE_CODE_BOOL
,
270 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
271 TYPE_FLAG_UNSIGNED
, "boolean", objfile
);
274 type
= init_type (TYPE_CODE_STRING
,
275 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
276 0, "string", objfile
);
279 type
= init_type (TYPE_CODE_INT
,
280 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
281 0, "character", objfile
);
284 type
= init_type (TYPE_CODE_INT
,
285 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
286 0, "integer*1", objfile
);
288 case FT_UNSIGNED_CHAR
:
289 type
= init_type (TYPE_CODE_BOOL
,
290 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
291 TYPE_FLAG_UNSIGNED
, "logical*1", objfile
);
294 type
= init_type (TYPE_CODE_INT
,
295 TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
296 0, "integer*2", objfile
);
298 case FT_SIGNED_SHORT
:
299 type
= init_type (TYPE_CODE_INT
,
300 TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
301 0, "short", objfile
); /* FIXME-fnf */
303 case FT_UNSIGNED_SHORT
:
304 type
= init_type (TYPE_CODE_BOOL
,
305 TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
306 TYPE_FLAG_UNSIGNED
, "logical*2", objfile
);
309 type
= init_type (TYPE_CODE_INT
,
310 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
311 0, "integer*4", objfile
);
313 case FT_SIGNED_INTEGER
:
314 type
= init_type (TYPE_CODE_INT
,
315 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
316 0, "integer", objfile
); /* FIXME -fnf */
318 case FT_UNSIGNED_INTEGER
:
319 type
= init_type (TYPE_CODE_BOOL
,
320 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
321 TYPE_FLAG_UNSIGNED
, "logical*4", objfile
);
323 case FT_FIXED_DECIMAL
:
324 type
= init_type (TYPE_CODE_INT
,
325 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
326 0, "fixed decimal", objfile
);
329 type
= init_type (TYPE_CODE_INT
,
330 TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
334 type
= init_type (TYPE_CODE_INT
,
335 TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
336 0, "long", objfile
); /* FIXME -fnf */
338 case FT_UNSIGNED_LONG
:
339 type
= init_type (TYPE_CODE_INT
,
340 TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
341 TYPE_FLAG_UNSIGNED
, "unsigned long", objfile
);
344 type
= init_type (TYPE_CODE_INT
,
345 TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
346 0, "long long", objfile
);
348 case FT_SIGNED_LONG_LONG
:
349 type
= init_type (TYPE_CODE_INT
,
350 TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
351 0, "signed long long", objfile
);
353 case FT_UNSIGNED_LONG_LONG
:
354 type
= init_type (TYPE_CODE_INT
,
355 TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
356 TYPE_FLAG_UNSIGNED
, "unsigned long long", objfile
);
359 type
= init_type (TYPE_CODE_FLT
,
360 TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
,
363 case FT_DBL_PREC_FLOAT
:
364 type
= init_type (TYPE_CODE_FLT
,
365 TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
366 0, "real*8", objfile
);
368 case FT_FLOAT_DECIMAL
:
369 type
= init_type (TYPE_CODE_FLT
,
370 TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
371 0, "floating decimal", objfile
);
373 case FT_EXT_PREC_FLOAT
:
374 type
= init_type (TYPE_CODE_FLT
,
375 TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
376 0, "real*16", objfile
);
379 type
= init_type (TYPE_CODE_COMPLEX
,
380 2 * TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
,
381 0, "complex*8", objfile
);
382 TYPE_TARGET_TYPE (type
) = builtin_type_f_real
;
384 case FT_DBL_PREC_COMPLEX
:
385 type
= init_type (TYPE_CODE_COMPLEX
,
386 2 * TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
387 0, "complex*16", objfile
);
388 TYPE_TARGET_TYPE (type
) = builtin_type_f_real_s8
;
390 case FT_EXT_PREC_COMPLEX
:
391 type
= init_type (TYPE_CODE_COMPLEX
,
392 2 * TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
393 0, "complex*32", objfile
);
394 TYPE_TARGET_TYPE (type
) = builtin_type_f_real_s16
;
397 /* FIXME: For now, if we are asked to produce a type not in this
398 language, create the equivalent of a C integer type with the
399 name "<?type?>". When all the dust settles from the type
400 reconstruction work, this should probably become an error. */
401 type
= init_type (TYPE_CODE_INT
,
402 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
403 0, "<?type?>", objfile
);
404 warning ("internal error: no F77 fundamental type %d", typeid);
411 /* Table of operators and their precedences for printing expressions. */
413 static const struct op_print f_op_print_tab
[] = {
414 { "+", BINOP_ADD
, PREC_ADD
, 0 },
415 { "+", UNOP_PLUS
, PREC_PREFIX
, 0 },
416 { "-", BINOP_SUB
, PREC_ADD
, 0 },
417 { "-", UNOP_NEG
, PREC_PREFIX
, 0 },
418 { "*", BINOP_MUL
, PREC_MUL
, 0 },
419 { "/", BINOP_DIV
, PREC_MUL
, 0 },
420 { "DIV", BINOP_INTDIV
, PREC_MUL
, 0 },
421 { "MOD", BINOP_REM
, PREC_MUL
, 0 },
422 { "=", BINOP_ASSIGN
, PREC_ASSIGN
, 1 },
423 { ".OR.", BINOP_LOGICAL_OR
, PREC_LOGICAL_OR
, 0 },
424 { ".AND.", BINOP_LOGICAL_AND
, PREC_LOGICAL_AND
, 0 },
425 { ".NOT.", UNOP_LOGICAL_NOT
, PREC_PREFIX
, 0 },
426 { ".EQ.", BINOP_EQUAL
, PREC_EQUAL
, 0 },
427 { ".NE.", BINOP_NOTEQUAL
, PREC_EQUAL
, 0 },
428 { ".LE.", BINOP_LEQ
, PREC_ORDER
, 0 },
429 { ".GE.", BINOP_GEQ
, PREC_ORDER
, 0 },
430 { ".GT.", BINOP_GTR
, PREC_ORDER
, 0 },
431 { ".LT.", BINOP_LESS
, PREC_ORDER
, 0 },
432 { "**", UNOP_IND
, PREC_PREFIX
, 0 },
433 { "@", BINOP_REPEAT
, PREC_REPEAT
, 0 },
437 struct type
** CONST_PTR (f_builtin_types
[]) =
439 &builtin_type_f_character
,
440 &builtin_type_f_logical
,
441 &builtin_type_f_logical_s1
,
442 &builtin_type_f_logical_s2
,
443 &builtin_type_f_integer
,
444 &builtin_type_f_integer_s2
,
445 &builtin_type_f_real
,
446 &builtin_type_f_real_s8
,
447 &builtin_type_f_real_s16
,
448 &builtin_type_f_complex_s8
,
449 &builtin_type_f_complex_s16
,
451 &builtin_type_f_complex_s32
,
453 &builtin_type_f_void
,
457 /* This is declared in c-lang.h but it is silly to import that file for what
458 is already just a hack. */
460 c_value_print
PARAMS ((struct value
*, GDB_FILE
*, int, enum val_prettyprint
));
462 const struct language_defn f_language_defn
= {
468 f_parse
, /* parser */
469 f_error
, /* parser error function */
470 evaluate_subexp_standard
,
471 f_printchar
, /* Print character constant */
472 f_printstr
, /* function to print string constant */
473 f_create_fundamental_type
, /* Create fundamental type in this language */
474 f_print_type
, /* Print a type using appropriate syntax */
475 f_val_print
, /* Print a value using appropriate syntax */
476 c_value_print
, /* FIXME */
477 {"", "", "", ""}, /* Binary format info */
478 {"0%o", "0", "o", ""}, /* Octal format info */
479 {"%d", "", "d", ""}, /* Decimal format info */
480 {"0x%x", "0x", "x", ""}, /* Hex format info */
481 f_op_print_tab
, /* expression operators for printing */
482 0, /* arrays are first-class (not c-style) */
483 1, /* String lower bound */
484 &builtin_type_f_character
, /* Type of string elements */
489 _initialize_f_language ()
491 builtin_type_f_void
=
492 init_type (TYPE_CODE_VOID
, 1,
494 "VOID", (struct objfile
*) NULL
);
496 builtin_type_f_character
=
497 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
499 "character", (struct objfile
*) NULL
);
501 builtin_type_f_logical_s1
=
502 init_type (TYPE_CODE_BOOL
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
504 "logical*1", (struct objfile
*) NULL
);
506 builtin_type_f_integer_s2
=
507 init_type (TYPE_CODE_INT
, TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
509 "integer*2", (struct objfile
*) NULL
);
511 builtin_type_f_logical_s2
=
512 init_type (TYPE_CODE_BOOL
, TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
514 "logical*2", (struct objfile
*) NULL
);
516 builtin_type_f_integer
=
517 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
519 "integer", (struct objfile
*) NULL
);
521 builtin_type_f_logical
=
522 init_type (TYPE_CODE_BOOL
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
524 "logical*4", (struct objfile
*) NULL
);
526 builtin_type_f_real
=
527 init_type (TYPE_CODE_FLT
, TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
,
529 "real", (struct objfile
*) NULL
);
531 builtin_type_f_real_s8
=
532 init_type (TYPE_CODE_FLT
, TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
534 "real*8", (struct objfile
*) NULL
);
536 builtin_type_f_real_s16
=
537 init_type (TYPE_CODE_FLT
, TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
539 "real*16", (struct objfile
*) NULL
);
541 builtin_type_f_complex_s8
=
542 init_type (TYPE_CODE_COMPLEX
, 2 * TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
,
544 "complex*8", (struct objfile
*) NULL
);
545 TYPE_TARGET_TYPE (builtin_type_f_complex_s8
) = builtin_type_f_real
;
547 builtin_type_f_complex_s16
=
548 init_type (TYPE_CODE_COMPLEX
, 2 * TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
550 "complex*16", (struct objfile
*) NULL
);
551 TYPE_TARGET_TYPE (builtin_type_f_complex_s16
) = builtin_type_f_real_s8
;
553 /* We have a new size == 4 double floats for the
554 complex*32 data type */
556 builtin_type_f_complex_s32
=
557 init_type (TYPE_CODE_COMPLEX
, 2 * TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
559 "complex*32", (struct objfile
*) NULL
);
560 TYPE_TARGET_TYPE (builtin_type_f_complex_s32
) = builtin_type_f_real_s16
;
562 builtin_type_string
=
563 init_type (TYPE_CODE_STRING
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
565 "character string", (struct objfile
*) NULL
);
567 add_language (&f_language_defn
);
572 allocate_saved_bf_node()
576 new = (SAVED_BF_PTR
) xmalloc (sizeof (SAVED_BF
));
580 static SAVED_FUNCTION
*
581 allocate_saved_function_node()
585 new = (SAVED_FUNCTION
*) xmalloc (sizeof (SAVED_FUNCTION
));
589 static SAVED_F77_COMMON_PTR
allocate_saved_f77_common_node()
591 SAVED_F77_COMMON_PTR
new;
593 new = (SAVED_F77_COMMON_PTR
) xmalloc (sizeof (SAVED_F77_COMMON
));
597 static COMMON_ENTRY_PTR
allocate_common_entry_node()
599 COMMON_ENTRY_PTR
new;
601 new = (COMMON_ENTRY_PTR
) xmalloc (sizeof (COMMON_ENTRY
));
606 SAVED_F77_COMMON_PTR head_common_list
=NULL
; /* Ptr to 1st saved COMMON */
607 SAVED_F77_COMMON_PTR tail_common_list
=NULL
; /* Ptr to last saved COMMON */
608 SAVED_F77_COMMON_PTR current_common
=NULL
; /* Ptr to current COMMON */
611 static SAVED_BF_PTR saved_bf_list
=NULL
; /* Ptr to (.bf,function)
613 static SAVED_BF_PTR saved_bf_list_end
=NULL
; /* Ptr to above list's end */
614 static SAVED_BF_PTR current_head_bf_list
=NULL
; /* Current head of above list
617 static SAVED_BF_PTR tmp_bf_ptr
; /* Generic temporary for use
620 /* The following function simply enters a given common block onto
621 the global common block chain */
624 add_common_block(name
,offset
,secnum
,func_stab
)
630 SAVED_F77_COMMON_PTR tmp
;
631 char *c
,*local_copy_func_stab
;
633 /* If the COMMON block we are trying to add has a blank
634 name (i.e. "#BLNK_COM") then we set it to __BLANK
635 because the darn "#" character makes GDB's input
639 if (STREQ(name
,BLANK_COMMON_NAME_ORIGINAL
) ||
640 STREQ(name
,BLANK_COMMON_NAME_MF77
))
644 name
= alloca(strlen(BLANK_COMMON_NAME_LOCAL
) + 1);
645 strcpy(name
,BLANK_COMMON_NAME_LOCAL
);
648 tmp
= allocate_saved_f77_common_node();
650 local_copy_func_stab
= xmalloc (strlen(func_stab
) + 1);
651 strcpy(local_copy_func_stab
,func_stab
);
653 tmp
->name
= xmalloc(strlen(name
) + 1);
655 /* local_copy_func_stab is a stabstring, let us first extract the
656 function name from the stab by NULLing out the ':' character. */
660 c
= strchr(local_copy_func_stab
,':');
665 error("Malformed function STAB found in add_common_block()");
668 tmp
->owning_function
= xmalloc (strlen(local_copy_func_stab
) + 1);
670 strcpy(tmp
->owning_function
,local_copy_func_stab
);
672 strcpy(tmp
->name
,name
);
673 tmp
->offset
= offset
;
676 tmp
->secnum
= secnum
;
678 current_common
= tmp
;
680 if (head_common_list
== NULL
)
682 head_common_list
= tail_common_list
= tmp
;
686 tail_common_list
->next
= tmp
;
687 tail_common_list
= tmp
;
692 /* The following function simply enters a given common entry onto
693 the "current_common" block that has been saved away. */
697 add_common_entry(entry_sym_ptr
)
698 struct symbol
*entry_sym_ptr
;
700 COMMON_ENTRY_PTR tmp
;
704 /* The order of this list is important, since
705 we expect the entries to appear in decl.
706 order when we later issue "info common" calls */
708 tmp
= allocate_common_entry_node();
711 tmp
->symbol
= entry_sym_ptr
;
713 if (current_common
== NULL
)
714 error("Attempt to add COMMON entry with no block open!");
717 if (current_common
->entries
== NULL
)
719 current_common
->entries
= tmp
;
720 current_common
->end_of_entries
= tmp
;
724 current_common
->end_of_entries
->next
= tmp
;
725 current_common
->end_of_entries
= tmp
;
731 /* This routine finds the first encountred COMMON block named "name" */
734 static SAVED_F77_COMMON_PTR
735 find_first_common_named(name
)
739 SAVED_F77_COMMON_PTR tmp
;
741 tmp
= head_common_list
;
745 if (STREQ(tmp
->name
,name
))
754 /* This routine finds the first encountred COMMON block named "name"
755 that belongs to function funcname */
757 SAVED_F77_COMMON_PTR
find_common_for_function(name
, funcname
)
762 SAVED_F77_COMMON_PTR tmp
;
764 tmp
= head_common_list
;
768 if (STREQ(tmp
->name
,name
) && STREQ(tmp
->owning_function
,funcname
))
779 /* The following function is called to patch up the offsets
780 for the statics contained in the COMMON block named
784 patch_common_entries (blk
, offset
, secnum
)
785 SAVED_F77_COMMON_PTR blk
;
789 COMMON_ENTRY_PTR entry
;
791 blk
->offset
= offset
; /* Keep this around for future use. */
793 entry
= blk
->entries
;
795 while (entry
!= NULL
)
797 SYMBOL_VALUE (entry
->symbol
) += offset
;
798 SYMBOL_SECTION (entry
->symbol
) = secnum
;
802 blk
->secnum
= secnum
;
805 /* Patch all commons named "name" that need patching.Since COMMON
806 blocks occur with relative infrequency, we simply do a linear scan on
807 the name. Eventually, the best way to do this will be a
808 hashed-lookup. Secnum is the section number for the .bss section
809 (which is where common data lives). */
812 patch_all_commons_by_name (name
, offset
, secnum
)
818 SAVED_F77_COMMON_PTR tmp
;
820 /* For blank common blocks, change the canonical reprsentation
823 if ((STREQ(name
,BLANK_COMMON_NAME_ORIGINAL
)) ||
824 (STREQ(name
,BLANK_COMMON_NAME_MF77
)))
827 name
= alloca(strlen(BLANK_COMMON_NAME_LOCAL
) + 1);
828 strcpy(name
,BLANK_COMMON_NAME_LOCAL
);
831 tmp
= head_common_list
;
835 if (COMMON_NEEDS_PATCHING(tmp
))
836 if (STREQ(tmp
->name
,name
))
837 patch_common_entries(tmp
,offset
,secnum
);
844 /* This macro adds the symbol-number for the start of the function
845 (the symbol number of the .bf) referenced by symnum_fcn to a
846 list. This list, in reality should be a FIFO queue but since
847 #line pragmas sometimes cause line ranges to get messed up
848 we simply create a linear list. This list can then be searched
849 first by a queueing algorithm and upon failure fall back to
853 #define ADD_BF_SYMNUM(bf_sym,fcn_sym) \
855 if (saved_bf_list == NULL) \
857 tmp_bf_ptr = allocate_saved_bf_node(); \
859 tmp_bf_ptr->symnum_bf = (bf_sym); \
860 tmp_bf_ptr->symnum_fcn = (fcn_sym); \
861 tmp_bf_ptr->next = NULL; \
863 current_head_bf_list = saved_bf_list = tmp_bf_ptr; \
864 saved_bf_list_end = tmp_bf_ptr; \
868 tmp_bf_ptr = allocate_saved_bf_node(); \
870 tmp_bf_ptr->symnum_bf = (bf_sym); \
871 tmp_bf_ptr->symnum_fcn = (fcn_sym); \
872 tmp_bf_ptr->next = NULL; \
874 saved_bf_list_end->next = tmp_bf_ptr; \
875 saved_bf_list_end = tmp_bf_ptr; \
879 /* This function frees the entire (.bf,function) list */
886 SAVED_BF_PTR tmp
= saved_bf_list
;
887 SAVED_BF_PTR next
= NULL
;
895 saved_bf_list
= NULL
;
899 int global_remote_debug
;
904 get_bf_for_fcn (the_function
)
910 /* First use a simple queuing algorithm (i.e. look and see if the
911 item at the head of the queue is the one you want) */
913 if (saved_bf_list
== NULL
)
914 fatal ("cannot get .bf node off empty list");
916 if (current_head_bf_list
!= NULL
)
917 if (current_head_bf_list
->symnum_fcn
== the_function
)
919 if (global_remote_debug
)
922 tmp
= current_head_bf_list
;
923 current_head_bf_list
= current_head_bf_list
->next
;
924 return(tmp
->symnum_bf
);
927 /* If the above did not work (probably because #line directives were
928 used in the sourcefile and they messed up our internal tables) we now do
929 the ugly linear scan */
931 if (global_remote_debug
)
932 fprintf(stderr
,"\ndefaulting to linear scan\n");
939 if (tmp
->symnum_fcn
== the_function
)
941 if (global_remote_debug
)
942 fprintf(stderr
,"Found in %d probes\n",nprobes
);
943 current_head_bf_list
= tmp
->next
;
944 return(tmp
->symnum_bf
);
952 static SAVED_FUNCTION_PTR saved_function_list
=NULL
;
953 static SAVED_FUNCTION_PTR saved_function_list_end
=NULL
;
956 clear_function_list()
958 SAVED_FUNCTION_PTR tmp
= saved_function_list
;
959 SAVED_FUNCTION_PTR next
= NULL
;
968 saved_function_list
= NULL
;