1 /* Fortran language support routines for GDB, the GNU debugger.
2 Copyright 1993, 1994, 1996, 2000 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,
21 Boston, MA 02111-1307, USA. */
24 #include "gdb_string.h"
27 #include "expression.h"
28 #include "parser-defs.h"
33 /* The built-in types of F77. FIXME: integer*4 is missing, plain
34 logical is missing (builtin_type_logical is logical*4). */
36 struct type
*builtin_type_f_character
;
37 struct type
*builtin_type_f_logical
;
38 struct type
*builtin_type_f_logical_s1
;
39 struct type
*builtin_type_f_logical_s2
;
40 struct type
*builtin_type_f_integer
;
41 struct type
*builtin_type_f_integer_s2
;
42 struct type
*builtin_type_f_real
;
43 struct type
*builtin_type_f_real_s8
;
44 struct type
*builtin_type_f_real_s16
;
45 struct type
*builtin_type_f_complex_s8
;
46 struct type
*builtin_type_f_complex_s16
;
47 struct type
*builtin_type_f_complex_s32
;
48 struct type
*builtin_type_f_void
;
50 /* Following is dubious stuff that had been in the xcoff reader. */
54 long line_offset
; /* Line offset for function */
55 struct saved_fcn
*next
;
59 struct saved_bf_symnum
61 long symnum_fcn
; /* Symnum of function (i.e. .function directive) */
62 long symnum_bf
; /* Symnum of .bf for this function */
63 struct saved_bf_symnum
*next
;
66 typedef struct saved_fcn SAVED_FUNCTION
, *SAVED_FUNCTION_PTR
;
67 typedef struct saved_bf_symnum SAVED_BF
, *SAVED_BF_PTR
;
71 extern void _initialize_f_language (void);
73 static void clear_function_list (void);
74 static long get_bf_for_fcn (long);
75 static void clear_bf_list (void);
76 static void patch_all_commons_by_name (char *, CORE_ADDR
, int);
77 static SAVED_F77_COMMON_PTR
find_first_common_named (char *);
78 static void add_common_entry (struct symbol
*);
79 static void add_common_block (char *, CORE_ADDR
, int, char *);
80 static SAVED_FUNCTION
*allocate_saved_function_node (void);
81 static SAVED_BF_PTR
allocate_saved_bf_node (void);
82 static COMMON_ENTRY_PTR
allocate_common_entry_node (void);
83 static SAVED_F77_COMMON_PTR
allocate_saved_f77_common_node (void);
84 static void patch_common_entries (SAVED_F77_COMMON_PTR
, CORE_ADDR
, int);
87 static struct type
*f_create_fundamental_type (struct objfile
*, int);
88 static void f_printstr (struct ui_file
* stream
, char *string
,
89 unsigned int length
, int width
,
91 static void f_printchar (int c
, struct ui_file
* stream
);
92 static void f_emit_char (int c
, struct ui_file
* stream
, int quoter
);
94 /* Print the character C on STREAM as part of the contents of a literal
95 string whose delimiter is QUOTER. Note that that format for printing
96 characters and strings is language specific.
97 FIXME: This is a copy of the same function from c-exp.y. It should
98 be replaced with a true F77 version. */
101 f_emit_char (c
, stream
, quoter
)
103 struct ui_file
*stream
;
106 c
&= 0xFF; /* Avoid sign bit follies */
108 if (PRINT_LITERAL_FORM (c
))
110 if (c
== '\\' || c
== quoter
)
111 fputs_filtered ("\\", stream
);
112 fprintf_filtered (stream
, "%c", c
);
119 fputs_filtered ("\\n", stream
);
122 fputs_filtered ("\\b", stream
);
125 fputs_filtered ("\\t", stream
);
128 fputs_filtered ("\\f", stream
);
131 fputs_filtered ("\\r", stream
);
134 fputs_filtered ("\\e", stream
);
137 fputs_filtered ("\\a", stream
);
140 fprintf_filtered (stream
, "\\%.3o", (unsigned int) c
);
146 /* FIXME: This is a copy of the same function from c-exp.y. It should
147 be replaced with a true F77version. */
150 f_printchar (c
, stream
)
152 struct ui_file
*stream
;
154 fputs_filtered ("'", stream
);
155 LA_EMIT_CHAR (c
, stream
, '\'');
156 fputs_filtered ("'", stream
);
159 /* Print the character string STRING, printing at most LENGTH characters.
160 Printing stops early if the number hits print_max; repeat counts
161 are printed as appropriate. Print ellipses at the end if we
162 had to stop before printing LENGTH characters, or if FORCE_ELLIPSES.
163 FIXME: This is a copy of the same function from c-exp.y. It should
164 be replaced with a true F77 version. */
167 f_printstr (stream
, string
, length
, width
, force_ellipses
)
168 struct ui_file
*stream
;
174 register unsigned int i
;
175 unsigned int things_printed
= 0;
178 extern int inspect_it
;
182 fputs_filtered ("''", gdb_stdout
);
186 for (i
= 0; i
< length
&& things_printed
< print_max
; ++i
)
188 /* Position of the character we are examining
189 to see whether it is repeated. */
191 /* Number of repetitions we have detected so far. */
198 fputs_filtered (", ", stream
);
204 while (rep1
< length
&& string
[rep1
] == string
[i
])
210 if (reps
> repeat_count_threshold
)
215 fputs_filtered ("\\', ", stream
);
217 fputs_filtered ("', ", stream
);
220 f_printchar (string
[i
], stream
);
221 fprintf_filtered (stream
, " <repeats %u times>", reps
);
223 things_printed
+= repeat_count_threshold
;
231 fputs_filtered ("\\'", stream
);
233 fputs_filtered ("'", stream
);
236 LA_EMIT_CHAR (string
[i
], stream
, '"');
241 /* Terminate the quotes if necessary. */
245 fputs_filtered ("\\'", stream
);
247 fputs_filtered ("'", stream
);
250 if (force_ellipses
|| i
< length
)
251 fputs_filtered ("...", stream
);
254 /* FIXME: This is a copy of c_create_fundamental_type(), before
255 all the non-C types were stripped from it. Needs to be fixed
256 by an experienced F77 programmer. */
259 f_create_fundamental_type (objfile
, typeid)
260 struct objfile
*objfile
;
263 register struct type
*type
= NULL
;
268 type
= init_type (TYPE_CODE_VOID
,
269 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
273 type
= init_type (TYPE_CODE_BOOL
,
274 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
275 TYPE_FLAG_UNSIGNED
, "boolean", objfile
);
278 type
= init_type (TYPE_CODE_STRING
,
279 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
280 0, "string", objfile
);
283 type
= init_type (TYPE_CODE_INT
,
284 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
285 0, "character", objfile
);
288 type
= init_type (TYPE_CODE_INT
,
289 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
290 0, "integer*1", objfile
);
292 case FT_UNSIGNED_CHAR
:
293 type
= init_type (TYPE_CODE_BOOL
,
294 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
295 TYPE_FLAG_UNSIGNED
, "logical*1", objfile
);
298 type
= init_type (TYPE_CODE_INT
,
299 TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
300 0, "integer*2", objfile
);
302 case FT_SIGNED_SHORT
:
303 type
= init_type (TYPE_CODE_INT
,
304 TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
305 0, "short", objfile
); /* FIXME-fnf */
307 case FT_UNSIGNED_SHORT
:
308 type
= init_type (TYPE_CODE_BOOL
,
309 TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
310 TYPE_FLAG_UNSIGNED
, "logical*2", objfile
);
313 type
= init_type (TYPE_CODE_INT
,
314 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
315 0, "integer*4", objfile
);
317 case FT_SIGNED_INTEGER
:
318 type
= init_type (TYPE_CODE_INT
,
319 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
320 0, "integer", objfile
); /* FIXME -fnf */
322 case FT_UNSIGNED_INTEGER
:
323 type
= init_type (TYPE_CODE_BOOL
,
324 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
325 TYPE_FLAG_UNSIGNED
, "logical*4", objfile
);
327 case FT_FIXED_DECIMAL
:
328 type
= init_type (TYPE_CODE_INT
,
329 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
330 0, "fixed decimal", objfile
);
333 type
= init_type (TYPE_CODE_INT
,
334 TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
338 type
= init_type (TYPE_CODE_INT
,
339 TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
340 0, "long", objfile
); /* FIXME -fnf */
342 case FT_UNSIGNED_LONG
:
343 type
= init_type (TYPE_CODE_INT
,
344 TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
345 TYPE_FLAG_UNSIGNED
, "unsigned long", objfile
);
348 type
= init_type (TYPE_CODE_INT
,
349 TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
350 0, "long long", objfile
);
352 case FT_SIGNED_LONG_LONG
:
353 type
= init_type (TYPE_CODE_INT
,
354 TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
355 0, "signed long long", objfile
);
357 case FT_UNSIGNED_LONG_LONG
:
358 type
= init_type (TYPE_CODE_INT
,
359 TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
360 TYPE_FLAG_UNSIGNED
, "unsigned long long", objfile
);
363 type
= init_type (TYPE_CODE_FLT
,
364 TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
,
367 case FT_DBL_PREC_FLOAT
:
368 type
= init_type (TYPE_CODE_FLT
,
369 TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
370 0, "real*8", objfile
);
372 case FT_FLOAT_DECIMAL
:
373 type
= init_type (TYPE_CODE_FLT
,
374 TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
375 0, "floating decimal", objfile
);
377 case FT_EXT_PREC_FLOAT
:
378 type
= init_type (TYPE_CODE_FLT
,
379 TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
380 0, "real*16", objfile
);
383 type
= init_type (TYPE_CODE_COMPLEX
,
384 2 * TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
,
385 0, "complex*8", objfile
);
386 TYPE_TARGET_TYPE (type
) = builtin_type_f_real
;
388 case FT_DBL_PREC_COMPLEX
:
389 type
= init_type (TYPE_CODE_COMPLEX
,
390 2 * TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
391 0, "complex*16", objfile
);
392 TYPE_TARGET_TYPE (type
) = builtin_type_f_real_s8
;
394 case FT_EXT_PREC_COMPLEX
:
395 type
= init_type (TYPE_CODE_COMPLEX
,
396 2 * TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
397 0, "complex*32", objfile
);
398 TYPE_TARGET_TYPE (type
) = builtin_type_f_real_s16
;
401 /* FIXME: For now, if we are asked to produce a type not in this
402 language, create the equivalent of a C integer type with the
403 name "<?type?>". When all the dust settles from the type
404 reconstruction work, this should probably become an error. */
405 type
= init_type (TYPE_CODE_INT
,
406 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
407 0, "<?type?>", objfile
);
408 warning ("internal error: no F77 fundamental type %d", typeid);
415 /* Table of operators and their precedences for printing expressions. */
417 static const struct op_print f_op_print_tab
[] =
419 {"+", BINOP_ADD
, PREC_ADD
, 0},
420 {"+", UNOP_PLUS
, PREC_PREFIX
, 0},
421 {"-", BINOP_SUB
, PREC_ADD
, 0},
422 {"-", UNOP_NEG
, PREC_PREFIX
, 0},
423 {"*", BINOP_MUL
, PREC_MUL
, 0},
424 {"/", BINOP_DIV
, PREC_MUL
, 0},
425 {"DIV", BINOP_INTDIV
, PREC_MUL
, 0},
426 {"MOD", BINOP_REM
, PREC_MUL
, 0},
427 {"=", BINOP_ASSIGN
, PREC_ASSIGN
, 1},
428 {".OR.", BINOP_LOGICAL_OR
, PREC_LOGICAL_OR
, 0},
429 {".AND.", BINOP_LOGICAL_AND
, PREC_LOGICAL_AND
, 0},
430 {".NOT.", UNOP_LOGICAL_NOT
, PREC_PREFIX
, 0},
431 {".EQ.", BINOP_EQUAL
, PREC_EQUAL
, 0},
432 {".NE.", BINOP_NOTEQUAL
, PREC_EQUAL
, 0},
433 {".LE.", BINOP_LEQ
, PREC_ORDER
, 0},
434 {".GE.", BINOP_GEQ
, PREC_ORDER
, 0},
435 {".GT.", BINOP_GTR
, PREC_ORDER
, 0},
436 {".LT.", BINOP_LESS
, PREC_ORDER
, 0},
437 {"**", UNOP_IND
, PREC_PREFIX
, 0},
438 {"@", BINOP_REPEAT
, PREC_REPEAT
, 0},
442 struct type
**CONST_PTR (f_builtin_types
[]) =
444 &builtin_type_f_character
,
445 &builtin_type_f_logical
,
446 &builtin_type_f_logical_s1
,
447 &builtin_type_f_logical_s2
,
448 &builtin_type_f_integer
,
449 &builtin_type_f_integer_s2
,
450 &builtin_type_f_real
,
451 &builtin_type_f_real_s8
,
452 &builtin_type_f_real_s16
,
453 &builtin_type_f_complex_s8
,
454 &builtin_type_f_complex_s16
,
456 &builtin_type_f_complex_s32
,
458 &builtin_type_f_void
,
462 /* This is declared in c-lang.h but it is silly to import that file for what
463 is already just a hack. */
464 extern int c_value_print (struct value
*, struct ui_file
*, int,
465 enum val_prettyprint
);
467 const struct language_defn f_language_defn
=
474 f_parse
, /* parser */
475 f_error
, /* parser error function */
476 evaluate_subexp_standard
,
477 f_printchar
, /* Print character constant */
478 f_printstr
, /* function to print string constant */
479 f_emit_char
, /* Function to print a single character */
480 f_create_fundamental_type
, /* Create fundamental type in this language */
481 f_print_type
, /* Print a type using appropriate syntax */
482 f_val_print
, /* Print a value using appropriate syntax */
483 c_value_print
, /* FIXME */
484 {"", "", "", ""}, /* Binary format info */
485 {"0%o", "0", "o", ""}, /* Octal format info */
486 {"%d", "", "d", ""}, /* Decimal format info */
487 {"0x%x", "0x", "x", ""}, /* Hex format info */
488 f_op_print_tab
, /* expression operators for printing */
489 0, /* arrays are first-class (not c-style) */
490 1, /* String lower bound */
491 &builtin_type_f_character
, /* Type of string elements */
496 _initialize_f_language ()
498 builtin_type_f_void
=
499 init_type (TYPE_CODE_VOID
, 1,
501 "VOID", (struct objfile
*) NULL
);
503 builtin_type_f_character
=
504 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
506 "character", (struct objfile
*) NULL
);
508 builtin_type_f_logical_s1
=
509 init_type (TYPE_CODE_BOOL
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
511 "logical*1", (struct objfile
*) NULL
);
513 builtin_type_f_integer_s2
=
514 init_type (TYPE_CODE_INT
, TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
516 "integer*2", (struct objfile
*) NULL
);
518 builtin_type_f_logical_s2
=
519 init_type (TYPE_CODE_BOOL
, TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
521 "logical*2", (struct objfile
*) NULL
);
523 builtin_type_f_integer
=
524 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
526 "integer", (struct objfile
*) NULL
);
528 builtin_type_f_logical
=
529 init_type (TYPE_CODE_BOOL
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
531 "logical*4", (struct objfile
*) NULL
);
533 builtin_type_f_real
=
534 init_type (TYPE_CODE_FLT
, TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
,
536 "real", (struct objfile
*) NULL
);
538 builtin_type_f_real_s8
=
539 init_type (TYPE_CODE_FLT
, TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
541 "real*8", (struct objfile
*) NULL
);
543 builtin_type_f_real_s16
=
544 init_type (TYPE_CODE_FLT
, TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
546 "real*16", (struct objfile
*) NULL
);
548 builtin_type_f_complex_s8
=
549 init_type (TYPE_CODE_COMPLEX
, 2 * TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
,
551 "complex*8", (struct objfile
*) NULL
);
552 TYPE_TARGET_TYPE (builtin_type_f_complex_s8
) = builtin_type_f_real
;
554 builtin_type_f_complex_s16
=
555 init_type (TYPE_CODE_COMPLEX
, 2 * TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
557 "complex*16", (struct objfile
*) NULL
);
558 TYPE_TARGET_TYPE (builtin_type_f_complex_s16
) = builtin_type_f_real_s8
;
560 /* We have a new size == 4 double floats for the
561 complex*32 data type */
563 builtin_type_f_complex_s32
=
564 init_type (TYPE_CODE_COMPLEX
, 2 * TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
566 "complex*32", (struct objfile
*) NULL
);
567 TYPE_TARGET_TYPE (builtin_type_f_complex_s32
) = builtin_type_f_real_s16
;
569 builtin_type_string
=
570 init_type (TYPE_CODE_STRING
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
572 "character string", (struct objfile
*) NULL
);
574 add_language (&f_language_defn
);
579 allocate_saved_bf_node ()
583 new = (SAVED_BF_PTR
) xmalloc (sizeof (SAVED_BF
));
587 static SAVED_FUNCTION
*
588 allocate_saved_function_node ()
592 new = (SAVED_FUNCTION
*) xmalloc (sizeof (SAVED_FUNCTION
));
596 static SAVED_F77_COMMON_PTR
597 allocate_saved_f77_common_node ()
599 SAVED_F77_COMMON_PTR
new;
601 new = (SAVED_F77_COMMON_PTR
) xmalloc (sizeof (SAVED_F77_COMMON
));
605 static COMMON_ENTRY_PTR
606 allocate_common_entry_node ()
608 COMMON_ENTRY_PTR
new;
610 new = (COMMON_ENTRY_PTR
) xmalloc (sizeof (COMMON_ENTRY
));
615 SAVED_F77_COMMON_PTR head_common_list
= NULL
; /* Ptr to 1st saved COMMON */
616 SAVED_F77_COMMON_PTR tail_common_list
= NULL
; /* Ptr to last saved COMMON */
617 SAVED_F77_COMMON_PTR current_common
= NULL
; /* Ptr to current COMMON */
620 static SAVED_BF_PTR saved_bf_list
= NULL
; /* Ptr to (.bf,function)
622 static SAVED_BF_PTR saved_bf_list_end
= NULL
; /* Ptr to above list's end */
623 static SAVED_BF_PTR current_head_bf_list
= NULL
; /* Current head of above list
626 static SAVED_BF_PTR tmp_bf_ptr
; /* Generic temporary for use
629 /* The following function simply enters a given common block onto
630 the global common block chain */
633 add_common_block (name
, offset
, secnum
, func_stab
)
639 SAVED_F77_COMMON_PTR tmp
;
640 char *c
, *local_copy_func_stab
;
642 /* If the COMMON block we are trying to add has a blank
643 name (i.e. "#BLNK_COM") then we set it to __BLANK
644 because the darn "#" character makes GDB's input
648 if (STREQ (name
, BLANK_COMMON_NAME_ORIGINAL
) ||
649 STREQ (name
, BLANK_COMMON_NAME_MF77
))
653 name
= alloca (strlen (BLANK_COMMON_NAME_LOCAL
) + 1);
654 strcpy (name
, BLANK_COMMON_NAME_LOCAL
);
657 tmp
= allocate_saved_f77_common_node ();
659 local_copy_func_stab
= xmalloc (strlen (func_stab
) + 1);
660 strcpy (local_copy_func_stab
, func_stab
);
662 tmp
->name
= xmalloc (strlen (name
) + 1);
664 /* local_copy_func_stab is a stabstring, let us first extract the
665 function name from the stab by NULLing out the ':' character. */
669 c
= strchr (local_copy_func_stab
, ':');
674 error ("Malformed function STAB found in add_common_block()");
677 tmp
->owning_function
= xmalloc (strlen (local_copy_func_stab
) + 1);
679 strcpy (tmp
->owning_function
, local_copy_func_stab
);
681 strcpy (tmp
->name
, name
);
682 tmp
->offset
= offset
;
685 tmp
->secnum
= secnum
;
687 current_common
= tmp
;
689 if (head_common_list
== NULL
)
691 head_common_list
= tail_common_list
= tmp
;
695 tail_common_list
->next
= tmp
;
696 tail_common_list
= tmp
;
701 /* The following function simply enters a given common entry onto
702 the "current_common" block that has been saved away. */
706 add_common_entry (entry_sym_ptr
)
707 struct symbol
*entry_sym_ptr
;
709 COMMON_ENTRY_PTR tmp
;
713 /* The order of this list is important, since
714 we expect the entries to appear in decl.
715 order when we later issue "info common" calls */
717 tmp
= allocate_common_entry_node ();
720 tmp
->symbol
= entry_sym_ptr
;
722 if (current_common
== NULL
)
723 error ("Attempt to add COMMON entry with no block open!");
726 if (current_common
->entries
== NULL
)
728 current_common
->entries
= tmp
;
729 current_common
->end_of_entries
= tmp
;
733 current_common
->end_of_entries
->next
= tmp
;
734 current_common
->end_of_entries
= tmp
;
740 /* This routine finds the first encountred COMMON block named "name" */
743 static SAVED_F77_COMMON_PTR
744 find_first_common_named (name
)
748 SAVED_F77_COMMON_PTR tmp
;
750 tmp
= head_common_list
;
754 if (STREQ (tmp
->name
, name
))
763 /* This routine finds the first encountred COMMON block named "name"
764 that belongs to function funcname */
767 find_common_for_function (name
, funcname
)
772 SAVED_F77_COMMON_PTR tmp
;
774 tmp
= head_common_list
;
778 if (STREQ (tmp
->name
, name
) && STREQ (tmp
->owning_function
, funcname
))
789 /* The following function is called to patch up the offsets
790 for the statics contained in the COMMON block named
794 patch_common_entries (blk
, offset
, secnum
)
795 SAVED_F77_COMMON_PTR blk
;
799 COMMON_ENTRY_PTR entry
;
801 blk
->offset
= offset
; /* Keep this around for future use. */
803 entry
= blk
->entries
;
805 while (entry
!= NULL
)
807 SYMBOL_VALUE (entry
->symbol
) += offset
;
808 SYMBOL_SECTION (entry
->symbol
) = secnum
;
812 blk
->secnum
= secnum
;
815 /* Patch all commons named "name" that need patching.Since COMMON
816 blocks occur with relative infrequency, we simply do a linear scan on
817 the name. Eventually, the best way to do this will be a
818 hashed-lookup. Secnum is the section number for the .bss section
819 (which is where common data lives). */
822 patch_all_commons_by_name (name
, offset
, secnum
)
828 SAVED_F77_COMMON_PTR tmp
;
830 /* For blank common blocks, change the canonical reprsentation
833 if ((STREQ (name
, BLANK_COMMON_NAME_ORIGINAL
)) ||
834 (STREQ (name
, BLANK_COMMON_NAME_MF77
)))
837 name
= alloca (strlen (BLANK_COMMON_NAME_LOCAL
) + 1);
838 strcpy (name
, BLANK_COMMON_NAME_LOCAL
);
841 tmp
= head_common_list
;
845 if (COMMON_NEEDS_PATCHING (tmp
))
846 if (STREQ (tmp
->name
, name
))
847 patch_common_entries (tmp
, offset
, secnum
);
854 /* This macro adds the symbol-number for the start of the function
855 (the symbol number of the .bf) referenced by symnum_fcn to a
856 list. This list, in reality should be a FIFO queue but since
857 #line pragmas sometimes cause line ranges to get messed up
858 we simply create a linear list. This list can then be searched
859 first by a queueing algorithm and upon failure fall back to
863 #define ADD_BF_SYMNUM(bf_sym,fcn_sym) \
865 if (saved_bf_list == NULL) \
867 tmp_bf_ptr = allocate_saved_bf_node(); \
869 tmp_bf_ptr->symnum_bf = (bf_sym); \
870 tmp_bf_ptr->symnum_fcn = (fcn_sym); \
871 tmp_bf_ptr->next = NULL; \
873 current_head_bf_list = saved_bf_list = tmp_bf_ptr; \
874 saved_bf_list_end = tmp_bf_ptr; \
878 tmp_bf_ptr = allocate_saved_bf_node(); \
880 tmp_bf_ptr->symnum_bf = (bf_sym); \
881 tmp_bf_ptr->symnum_fcn = (fcn_sym); \
882 tmp_bf_ptr->next = NULL; \
884 saved_bf_list_end->next = tmp_bf_ptr; \
885 saved_bf_list_end = tmp_bf_ptr; \
889 /* This function frees the entire (.bf,function) list */
896 SAVED_BF_PTR tmp
= saved_bf_list
;
897 SAVED_BF_PTR next
= NULL
;
905 saved_bf_list
= NULL
;
909 int global_remote_debug
;
914 get_bf_for_fcn (the_function
)
920 /* First use a simple queuing algorithm (i.e. look and see if the
921 item at the head of the queue is the one you want) */
923 if (saved_bf_list
== NULL
)
924 internal_error ("cannot get .bf node off empty list");
926 if (current_head_bf_list
!= NULL
)
927 if (current_head_bf_list
->symnum_fcn
== the_function
)
929 if (global_remote_debug
)
930 fprintf (stderr
, "*");
932 tmp
= current_head_bf_list
;
933 current_head_bf_list
= current_head_bf_list
->next
;
934 return (tmp
->symnum_bf
);
937 /* If the above did not work (probably because #line directives were
938 used in the sourcefile and they messed up our internal tables) we now do
939 the ugly linear scan */
941 if (global_remote_debug
)
942 fprintf (stderr
, "\ndefaulting to linear scan\n");
949 if (tmp
->symnum_fcn
== the_function
)
951 if (global_remote_debug
)
952 fprintf (stderr
, "Found in %d probes\n", nprobes
);
953 current_head_bf_list
= tmp
->next
;
954 return (tmp
->symnum_bf
);
962 static SAVED_FUNCTION_PTR saved_function_list
= NULL
;
963 static SAVED_FUNCTION_PTR saved_function_list_end
= NULL
;
966 clear_function_list ()
968 SAVED_FUNCTION_PTR tmp
= saved_function_list
;
969 SAVED_FUNCTION_PTR next
= NULL
;
978 saved_function_list
= NULL
;