1 /* Fortran language support routines for GDB, the GNU debugger.
3 Copyright (C) 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003,
4 2004, 2005, 2007 Free Software Foundation, Inc.
6 Contributed by Motorola. Adapted from the C parser by Farooq Butt
7 (fmbutt@engage.sps.mot.com).
9 This file is part of GDB.
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 Boston, MA 02110-1301, USA. */
27 #include "gdb_string.h"
30 #include "expression.h"
31 #include "parser-defs.h"
38 /* Following is dubious stuff that had been in the xcoff reader. */
42 long line_offset
; /* Line offset for function */
43 struct saved_fcn
*next
;
47 struct saved_bf_symnum
49 long symnum_fcn
; /* Symnum of function (i.e. .function directive) */
50 long symnum_bf
; /* Symnum of .bf for this function */
51 struct saved_bf_symnum
*next
;
54 typedef struct saved_fcn SAVED_FUNCTION
, *SAVED_FUNCTION_PTR
;
55 typedef struct saved_bf_symnum SAVED_BF
, *SAVED_BF_PTR
;
59 extern void _initialize_f_language (void);
61 static void clear_function_list (void);
62 static long get_bf_for_fcn (long);
63 static void clear_bf_list (void);
64 static void patch_all_commons_by_name (char *, CORE_ADDR
, int);
65 static SAVED_F77_COMMON_PTR
find_first_common_named (char *);
66 static void add_common_entry (struct symbol
*);
67 static void add_common_block (char *, CORE_ADDR
, int, char *);
68 static SAVED_FUNCTION
*allocate_saved_function_node (void);
69 static SAVED_BF_PTR
allocate_saved_bf_node (void);
70 static COMMON_ENTRY_PTR
allocate_common_entry_node (void);
71 static SAVED_F77_COMMON_PTR
allocate_saved_f77_common_node (void);
72 static void patch_common_entries (SAVED_F77_COMMON_PTR
, CORE_ADDR
, int);
75 static struct type
*f_create_fundamental_type (struct objfile
*, int);
76 static void f_printchar (int c
, struct ui_file
* stream
);
77 static void f_emit_char (int c
, struct ui_file
* stream
, int quoter
);
79 /* Print the character C on STREAM as part of the contents of a literal
80 string whose delimiter is QUOTER. Note that that format for printing
81 characters and strings is language specific.
82 FIXME: This is a copy of the same function from c-exp.y. It should
83 be replaced with a true F77 version. */
86 f_emit_char (int c
, struct ui_file
*stream
, int quoter
)
88 c
&= 0xFF; /* Avoid sign bit follies */
90 if (PRINT_LITERAL_FORM (c
))
92 if (c
== '\\' || c
== quoter
)
93 fputs_filtered ("\\", stream
);
94 fprintf_filtered (stream
, "%c", c
);
101 fputs_filtered ("\\n", stream
);
104 fputs_filtered ("\\b", stream
);
107 fputs_filtered ("\\t", stream
);
110 fputs_filtered ("\\f", stream
);
113 fputs_filtered ("\\r", stream
);
116 fputs_filtered ("\\e", stream
);
119 fputs_filtered ("\\a", stream
);
122 fprintf_filtered (stream
, "\\%.3o", (unsigned int) c
);
128 /* FIXME: This is a copy of the same function from c-exp.y. It should
129 be replaced with a true F77version. */
132 f_printchar (int c
, struct ui_file
*stream
)
134 fputs_filtered ("'", stream
);
135 LA_EMIT_CHAR (c
, stream
, '\'');
136 fputs_filtered ("'", stream
);
139 /* Print the character string STRING, printing at most LENGTH characters.
140 Printing stops early if the number hits print_max; repeat counts
141 are printed as appropriate. Print ellipses at the end if we
142 had to stop before printing LENGTH characters, or if FORCE_ELLIPSES.
143 FIXME: This is a copy of the same function from c-exp.y. It should
144 be replaced with a true F77 version. */
147 f_printstr (struct ui_file
*stream
, const gdb_byte
*string
,
148 unsigned int length
, int width
, int force_ellipses
)
151 unsigned int things_printed
= 0;
157 fputs_filtered ("''", gdb_stdout
);
161 for (i
= 0; i
< length
&& things_printed
< print_max
; ++i
)
163 /* Position of the character we are examining
164 to see whether it is repeated. */
166 /* Number of repetitions we have detected so far. */
173 fputs_filtered (", ", stream
);
179 while (rep1
< length
&& string
[rep1
] == string
[i
])
185 if (reps
> repeat_count_threshold
)
190 fputs_filtered ("\\', ", stream
);
192 fputs_filtered ("', ", stream
);
195 f_printchar (string
[i
], stream
);
196 fprintf_filtered (stream
, " <repeats %u times>", reps
);
198 things_printed
+= repeat_count_threshold
;
206 fputs_filtered ("\\'", stream
);
208 fputs_filtered ("'", stream
);
211 LA_EMIT_CHAR (string
[i
], stream
, '"');
216 /* Terminate the quotes if necessary. */
220 fputs_filtered ("\\'", stream
);
222 fputs_filtered ("'", stream
);
225 if (force_ellipses
|| i
< length
)
226 fputs_filtered ("...", stream
);
229 /* FIXME: This is a copy of c_create_fundamental_type(), before
230 all the non-C types were stripped from it. Needs to be fixed
231 by an experienced F77 programmer. */
234 f_create_fundamental_type (struct objfile
*objfile
, int typeid)
236 struct type
*type
= NULL
;
241 type
= init_type (TYPE_CODE_VOID
,
242 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
246 type
= init_type (TYPE_CODE_BOOL
,
247 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
248 TYPE_FLAG_UNSIGNED
, "boolean", objfile
);
251 type
= init_type (TYPE_CODE_STRING
,
252 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
253 0, "string", objfile
);
256 type
= init_type (TYPE_CODE_INT
,
257 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
258 0, "character", objfile
);
261 type
= init_type (TYPE_CODE_INT
,
262 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
263 0, "integer*1", objfile
);
265 case FT_UNSIGNED_CHAR
:
266 type
= init_type (TYPE_CODE_BOOL
,
267 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
268 TYPE_FLAG_UNSIGNED
, "logical*1", objfile
);
271 type
= init_type (TYPE_CODE_INT
,
272 gdbarch_short_bit (current_gdbarch
) / TARGET_CHAR_BIT
,
273 0, "integer*2", objfile
);
275 case FT_SIGNED_SHORT
:
276 type
= init_type (TYPE_CODE_INT
,
277 gdbarch_short_bit (current_gdbarch
) / TARGET_CHAR_BIT
,
278 0, "short", objfile
); /* FIXME-fnf */
280 case FT_UNSIGNED_SHORT
:
281 type
= init_type (TYPE_CODE_BOOL
,
282 gdbarch_short_bit (current_gdbarch
) / TARGET_CHAR_BIT
,
283 TYPE_FLAG_UNSIGNED
, "logical*2", objfile
);
286 type
= init_type (TYPE_CODE_INT
,
287 gdbarch_int_bit (current_gdbarch
) / TARGET_CHAR_BIT
,
288 0, "integer*4", objfile
);
290 case FT_SIGNED_INTEGER
:
291 type
= init_type (TYPE_CODE_INT
,
292 gdbarch_int_bit (current_gdbarch
) / TARGET_CHAR_BIT
,
293 0, "integer", objfile
); /* FIXME -fnf */
295 case FT_UNSIGNED_INTEGER
:
296 type
= init_type (TYPE_CODE_BOOL
,
297 gdbarch_int_bit (current_gdbarch
) / TARGET_CHAR_BIT
,
298 TYPE_FLAG_UNSIGNED
, "logical*4", objfile
);
300 case FT_FIXED_DECIMAL
:
301 type
= init_type (TYPE_CODE_INT
,
302 gdbarch_int_bit (current_gdbarch
) / TARGET_CHAR_BIT
,
303 0, "fixed decimal", objfile
);
306 type
= init_type (TYPE_CODE_INT
,
307 gdbarch_long_bit (current_gdbarch
) / TARGET_CHAR_BIT
,
311 type
= init_type (TYPE_CODE_INT
,
312 gdbarch_long_bit (current_gdbarch
) / TARGET_CHAR_BIT
,
313 0, "long", objfile
); /* FIXME -fnf */
315 case FT_UNSIGNED_LONG
:
316 type
= init_type (TYPE_CODE_INT
,
317 gdbarch_long_bit (current_gdbarch
) / TARGET_CHAR_BIT
,
318 TYPE_FLAG_UNSIGNED
, "unsigned long", objfile
);
321 type
= init_type (TYPE_CODE_INT
,
322 gdbarch_long_long_bit (current_gdbarch
)
324 0, "long long", objfile
);
326 case FT_SIGNED_LONG_LONG
:
327 type
= init_type (TYPE_CODE_INT
,
328 gdbarch_long_long_bit (current_gdbarch
)
330 0, "signed long long", objfile
);
332 case FT_UNSIGNED_LONG_LONG
:
333 type
= init_type (TYPE_CODE_INT
,
334 gdbarch_long_long_bit (current_gdbarch
)
336 TYPE_FLAG_UNSIGNED
, "unsigned long long", objfile
);
339 type
= init_type (TYPE_CODE_FLT
,
340 gdbarch_float_bit (current_gdbarch
) / TARGET_CHAR_BIT
,
343 case FT_DBL_PREC_FLOAT
:
344 type
= init_type (TYPE_CODE_FLT
,
345 gdbarch_double_bit (current_gdbarch
) / TARGET_CHAR_BIT
,
346 0, "real*8", objfile
);
348 case FT_FLOAT_DECIMAL
:
349 type
= init_type (TYPE_CODE_FLT
,
350 gdbarch_double_bit (current_gdbarch
) / TARGET_CHAR_BIT
,
351 0, "floating decimal", objfile
);
353 case FT_EXT_PREC_FLOAT
:
354 type
= init_type (TYPE_CODE_FLT
,
355 gdbarch_long_double_bit (current_gdbarch
)
357 0, "real*16", objfile
);
360 type
= init_type (TYPE_CODE_COMPLEX
,
361 2 * gdbarch_float_bit (current_gdbarch
) / TARGET_CHAR_BIT
,
362 0, "complex*8", objfile
);
363 TYPE_TARGET_TYPE (type
) = builtin_type_f_real
;
365 case FT_DBL_PREC_COMPLEX
:
366 type
= init_type (TYPE_CODE_COMPLEX
,
367 2 * gdbarch_double_bit (current_gdbarch
)
369 0, "complex*16", objfile
);
370 TYPE_TARGET_TYPE (type
) = builtin_type_f_real_s8
;
372 case FT_EXT_PREC_COMPLEX
:
373 type
= init_type (TYPE_CODE_COMPLEX
,
374 2 * gdbarch_long_double_bit (current_gdbarch
)
376 0, "complex*32", objfile
);
377 TYPE_TARGET_TYPE (type
) = builtin_type_f_real_s16
;
380 /* FIXME: For now, if we are asked to produce a type not in this
381 language, create the equivalent of a C integer type with the
382 name "<?type?>". When all the dust settles from the type
383 reconstruction work, this should probably become an error. */
384 type
= init_type (TYPE_CODE_INT
,
385 gdbarch_int_bit (current_gdbarch
) / TARGET_CHAR_BIT
,
386 0, "<?type?>", objfile
);
387 warning (_("internal error: no F77 fundamental type %d"), typeid);
394 /* Table of operators and their precedences for printing expressions. */
396 static const struct op_print f_op_print_tab
[] =
398 {"+", BINOP_ADD
, PREC_ADD
, 0},
399 {"+", UNOP_PLUS
, PREC_PREFIX
, 0},
400 {"-", BINOP_SUB
, PREC_ADD
, 0},
401 {"-", UNOP_NEG
, PREC_PREFIX
, 0},
402 {"*", BINOP_MUL
, PREC_MUL
, 0},
403 {"/", BINOP_DIV
, PREC_MUL
, 0},
404 {"DIV", BINOP_INTDIV
, PREC_MUL
, 0},
405 {"MOD", BINOP_REM
, PREC_MUL
, 0},
406 {"=", BINOP_ASSIGN
, PREC_ASSIGN
, 1},
407 {".OR.", BINOP_LOGICAL_OR
, PREC_LOGICAL_OR
, 0},
408 {".AND.", BINOP_LOGICAL_AND
, PREC_LOGICAL_AND
, 0},
409 {".NOT.", UNOP_LOGICAL_NOT
, PREC_PREFIX
, 0},
410 {".EQ.", BINOP_EQUAL
, PREC_EQUAL
, 0},
411 {".NE.", BINOP_NOTEQUAL
, PREC_EQUAL
, 0},
412 {".LE.", BINOP_LEQ
, PREC_ORDER
, 0},
413 {".GE.", BINOP_GEQ
, PREC_ORDER
, 0},
414 {".GT.", BINOP_GTR
, PREC_ORDER
, 0},
415 {".LT.", BINOP_LESS
, PREC_ORDER
, 0},
416 {"**", UNOP_IND
, PREC_PREFIX
, 0},
417 {"@", BINOP_REPEAT
, PREC_REPEAT
, 0},
421 enum f_primitive_types
{
422 f_primitive_type_character
,
423 f_primitive_type_logical
,
424 f_primitive_type_logical_s1
,
425 f_primitive_type_logical_s2
,
426 f_primitive_type_integer
,
427 f_primitive_type_integer_s2
,
428 f_primitive_type_real
,
429 f_primitive_type_real_s8
,
430 f_primitive_type_real_s16
,
431 f_primitive_type_complex_s8
,
432 f_primitive_type_complex_s16
,
433 f_primitive_type_void
,
438 f_language_arch_info (struct gdbarch
*gdbarch
,
439 struct language_arch_info
*lai
)
441 const struct builtin_f_type
*builtin
= builtin_f_type (gdbarch
);
443 lai
->string_char_type
= builtin
->builtin_character
;
444 lai
->primitive_type_vector
445 = GDBARCH_OBSTACK_CALLOC (gdbarch
, nr_f_primitive_types
+ 1,
448 lai
->primitive_type_vector
[f_primitive_type_character
]
449 = builtin
->builtin_character
;
450 lai
->primitive_type_vector
[f_primitive_type_logical
]
451 = builtin
->builtin_logical
;
452 lai
->primitive_type_vector
[f_primitive_type_logical_s1
]
453 = builtin
->builtin_logical_s1
;
454 lai
->primitive_type_vector
[f_primitive_type_logical_s2
]
455 = builtin
->builtin_logical_s2
;
456 lai
->primitive_type_vector
[f_primitive_type_real
]
457 = builtin
->builtin_real
;
458 lai
->primitive_type_vector
[f_primitive_type_real_s8
]
459 = builtin
->builtin_real_s8
;
460 lai
->primitive_type_vector
[f_primitive_type_real_s16
]
461 = builtin
->builtin_real_s16
;
462 lai
->primitive_type_vector
[f_primitive_type_complex_s8
]
463 = builtin
->builtin_complex_s8
;
464 lai
->primitive_type_vector
[f_primitive_type_complex_s16
]
465 = builtin
->builtin_complex_s16
;
466 lai
->primitive_type_vector
[f_primitive_type_void
]
467 = builtin
->builtin_void
;
470 /* This is declared in c-lang.h but it is silly to import that file for what
471 is already just a hack. */
472 extern int c_value_print (struct value
*, struct ui_file
*, int,
473 enum val_prettyprint
);
475 const struct language_defn f_language_defn
=
484 &exp_descriptor_standard
,
485 f_parse
, /* parser */
486 f_error
, /* parser error function */
488 f_printchar
, /* Print character constant */
489 f_printstr
, /* function to print string constant */
490 f_emit_char
, /* Function to print a single character */
491 f_create_fundamental_type
, /* Create fundamental type in this language */
492 f_print_type
, /* Print a type using appropriate syntax */
493 f_val_print
, /* Print a value using appropriate syntax */
494 c_value_print
, /* FIXME */
495 NULL
, /* Language specific skip_trampoline */
496 value_of_this
, /* value_of_this */
497 basic_lookup_symbol_nonlocal
, /* lookup_symbol_nonlocal */
498 basic_lookup_transparent_type
,/* lookup_transparent_type */
499 NULL
, /* Language specific symbol demangler */
500 NULL
, /* Language specific class_name_from_physname */
501 f_op_print_tab
, /* expression operators for printing */
502 0, /* arrays are first-class (not c-style) */
503 1, /* String lower bound */
505 default_word_break_characters
,
506 f_language_arch_info
,
507 default_print_array_index
,
512 build_fortran_types (struct gdbarch
*gdbarch
)
514 struct builtin_f_type
*builtin_f_type
515 = GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct builtin_f_type
);
517 builtin_f_type
->builtin_void
=
518 init_type (TYPE_CODE_VOID
, 1,
520 "VOID", (struct objfile
*) NULL
);
522 builtin_f_type
->builtin_character
=
523 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
525 "character", (struct objfile
*) NULL
);
527 builtin_f_type
->builtin_logical_s1
=
528 init_type (TYPE_CODE_BOOL
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
530 "logical*1", (struct objfile
*) NULL
);
532 builtin_f_type
->builtin_integer_s2
=
533 init_type (TYPE_CODE_INT
,
534 gdbarch_short_bit (current_gdbarch
) / TARGET_CHAR_BIT
,
535 0, "integer*2", (struct objfile
*) NULL
);
537 builtin_f_type
->builtin_logical_s2
=
538 init_type (TYPE_CODE_BOOL
,
539 gdbarch_short_bit (current_gdbarch
) / TARGET_CHAR_BIT
,
540 TYPE_FLAG_UNSIGNED
, "logical*2", (struct objfile
*) NULL
);
542 builtin_f_type
->builtin_integer
=
543 init_type (TYPE_CODE_INT
,
544 gdbarch_int_bit (current_gdbarch
) / TARGET_CHAR_BIT
,
545 0, "integer", (struct objfile
*) NULL
);
547 builtin_f_type
->builtin_logical
=
548 init_type (TYPE_CODE_BOOL
,
549 gdbarch_int_bit (current_gdbarch
) / TARGET_CHAR_BIT
,
550 TYPE_FLAG_UNSIGNED
, "logical*4", (struct objfile
*) NULL
);
552 builtin_f_type
->builtin_real
=
553 init_type (TYPE_CODE_FLT
,
554 gdbarch_float_bit (current_gdbarch
) / TARGET_CHAR_BIT
,
556 "real", (struct objfile
*) NULL
);
558 builtin_f_type
->builtin_real_s8
=
559 init_type (TYPE_CODE_FLT
,
560 gdbarch_double_bit (current_gdbarch
) / TARGET_CHAR_BIT
,
562 "real*8", (struct objfile
*) NULL
);
564 builtin_f_type
->builtin_real_s16
=
565 init_type (TYPE_CODE_FLT
,
566 gdbarch_long_double_bit (current_gdbarch
) / TARGET_CHAR_BIT
,
568 "real*16", (struct objfile
*) NULL
);
570 builtin_f_type
->builtin_complex_s8
=
571 init_type (TYPE_CODE_COMPLEX
,
572 2 * gdbarch_float_bit (current_gdbarch
) / TARGET_CHAR_BIT
,
574 "complex*8", (struct objfile
*) NULL
);
575 TYPE_TARGET_TYPE (builtin_f_type
->builtin_complex_s8
)
576 = builtin_f_type
->builtin_real
;
578 builtin_f_type
->builtin_complex_s16
=
579 init_type (TYPE_CODE_COMPLEX
,
580 2 * gdbarch_double_bit (current_gdbarch
) / TARGET_CHAR_BIT
,
582 "complex*16", (struct objfile
*) NULL
);
583 TYPE_TARGET_TYPE (builtin_f_type
->builtin_complex_s16
)
584 = builtin_f_type
->builtin_real_s8
;
586 /* We have a new size == 4 double floats for the
587 complex*32 data type */
589 builtin_f_type
->builtin_complex_s32
=
590 init_type (TYPE_CODE_COMPLEX
,
591 2 * gdbarch_long_double_bit (current_gdbarch
) / TARGET_CHAR_BIT
,
593 "complex*32", (struct objfile
*) NULL
);
594 TYPE_TARGET_TYPE (builtin_f_type
->builtin_complex_s32
)
595 = builtin_f_type
->builtin_real_s16
;
597 return builtin_f_type
;
600 static struct gdbarch_data
*f_type_data
;
602 const struct builtin_f_type
*
603 builtin_f_type (struct gdbarch
*gdbarch
)
605 return gdbarch_data (gdbarch
, f_type_data
);
609 _initialize_f_language (void)
611 f_type_data
= gdbarch_data_register_post_init (build_fortran_types
);
613 add_language (&f_language_defn
);
618 allocate_saved_bf_node (void)
622 new = (SAVED_BF_PTR
) xmalloc (sizeof (SAVED_BF
));
626 static SAVED_FUNCTION
*
627 allocate_saved_function_node (void)
631 new = (SAVED_FUNCTION
*) xmalloc (sizeof (SAVED_FUNCTION
));
635 static SAVED_F77_COMMON_PTR
636 allocate_saved_f77_common_node (void)
638 SAVED_F77_COMMON_PTR
new;
640 new = (SAVED_F77_COMMON_PTR
) xmalloc (sizeof (SAVED_F77_COMMON
));
644 static COMMON_ENTRY_PTR
645 allocate_common_entry_node (void)
647 COMMON_ENTRY_PTR
new;
649 new = (COMMON_ENTRY_PTR
) xmalloc (sizeof (COMMON_ENTRY
));
654 SAVED_F77_COMMON_PTR head_common_list
= NULL
; /* Ptr to 1st saved COMMON */
655 SAVED_F77_COMMON_PTR tail_common_list
= NULL
; /* Ptr to last saved COMMON */
656 SAVED_F77_COMMON_PTR current_common
= NULL
; /* Ptr to current COMMON */
659 static SAVED_BF_PTR saved_bf_list
= NULL
; /* Ptr to (.bf,function)
661 static SAVED_BF_PTR saved_bf_list_end
= NULL
; /* Ptr to above list's end */
662 static SAVED_BF_PTR current_head_bf_list
= NULL
; /* Current head of above list
665 static SAVED_BF_PTR tmp_bf_ptr
; /* Generic temporary for use
668 /* The following function simply enters a given common block onto
669 the global common block chain */
672 add_common_block (char *name
, CORE_ADDR offset
, int secnum
, char *func_stab
)
674 SAVED_F77_COMMON_PTR tmp
;
675 char *c
, *local_copy_func_stab
;
677 /* If the COMMON block we are trying to add has a blank
678 name (i.e. "#BLNK_COM") then we set it to __BLANK
679 because the darn "#" character makes GDB's input
683 if (strcmp (name
, BLANK_COMMON_NAME_ORIGINAL
) == 0
684 || strcmp (name
, BLANK_COMMON_NAME_MF77
) == 0)
688 name
= alloca (strlen (BLANK_COMMON_NAME_LOCAL
) + 1);
689 strcpy (name
, BLANK_COMMON_NAME_LOCAL
);
692 tmp
= allocate_saved_f77_common_node ();
694 local_copy_func_stab
= xmalloc (strlen (func_stab
) + 1);
695 strcpy (local_copy_func_stab
, func_stab
);
697 tmp
->name
= xmalloc (strlen (name
) + 1);
699 /* local_copy_func_stab is a stabstring, let us first extract the
700 function name from the stab by NULLing out the ':' character. */
704 c
= strchr (local_copy_func_stab
, ':');
709 error (_("Malformed function STAB found in add_common_block()"));
712 tmp
->owning_function
= xmalloc (strlen (local_copy_func_stab
) + 1);
714 strcpy (tmp
->owning_function
, local_copy_func_stab
);
716 strcpy (tmp
->name
, name
);
717 tmp
->offset
= offset
;
720 tmp
->secnum
= secnum
;
722 current_common
= tmp
;
724 if (head_common_list
== NULL
)
726 head_common_list
= tail_common_list
= tmp
;
730 tail_common_list
->next
= tmp
;
731 tail_common_list
= tmp
;
736 /* The following function simply enters a given common entry onto
737 the "current_common" block that has been saved away. */
741 add_common_entry (struct symbol
*entry_sym_ptr
)
743 COMMON_ENTRY_PTR tmp
;
747 /* The order of this list is important, since
748 we expect the entries to appear in decl.
749 order when we later issue "info common" calls */
751 tmp
= allocate_common_entry_node ();
754 tmp
->symbol
= entry_sym_ptr
;
756 if (current_common
== NULL
)
757 error (_("Attempt to add COMMON entry with no block open!"));
760 if (current_common
->entries
== NULL
)
762 current_common
->entries
= tmp
;
763 current_common
->end_of_entries
= tmp
;
767 current_common
->end_of_entries
->next
= tmp
;
768 current_common
->end_of_entries
= tmp
;
774 /* This routine finds the first encountred COMMON block named "name" */
777 static SAVED_F77_COMMON_PTR
778 find_first_common_named (char *name
)
781 SAVED_F77_COMMON_PTR tmp
;
783 tmp
= head_common_list
;
787 if (strcmp (tmp
->name
, name
) == 0)
796 /* This routine finds the first encountred COMMON block named "name"
797 that belongs to function funcname */
800 find_common_for_function (char *name
, char *funcname
)
803 SAVED_F77_COMMON_PTR tmp
;
805 tmp
= head_common_list
;
809 if (DEPRECATED_STREQ (tmp
->name
, name
)
810 && DEPRECATED_STREQ (tmp
->owning_function
, funcname
))
821 /* The following function is called to patch up the offsets
822 for the statics contained in the COMMON block named
826 patch_common_entries (SAVED_F77_COMMON_PTR blk
, CORE_ADDR offset
, int secnum
)
828 COMMON_ENTRY_PTR entry
;
830 blk
->offset
= offset
; /* Keep this around for future use. */
832 entry
= blk
->entries
;
834 while (entry
!= NULL
)
836 SYMBOL_VALUE (entry
->symbol
) += offset
;
837 SYMBOL_SECTION (entry
->symbol
) = secnum
;
841 blk
->secnum
= secnum
;
844 /* Patch all commons named "name" that need patching.Since COMMON
845 blocks occur with relative infrequency, we simply do a linear scan on
846 the name. Eventually, the best way to do this will be a
847 hashed-lookup. Secnum is the section number for the .bss section
848 (which is where common data lives). */
851 patch_all_commons_by_name (char *name
, CORE_ADDR offset
, int secnum
)
854 SAVED_F77_COMMON_PTR tmp
;
856 /* For blank common blocks, change the canonical reprsentation
859 if (strcmp (name
, BLANK_COMMON_NAME_ORIGINAL
) == 0
860 || strcmp (name
, BLANK_COMMON_NAME_MF77
) == 0)
863 name
= alloca (strlen (BLANK_COMMON_NAME_LOCAL
) + 1);
864 strcpy (name
, BLANK_COMMON_NAME_LOCAL
);
867 tmp
= head_common_list
;
871 if (COMMON_NEEDS_PATCHING (tmp
))
872 if (strcmp (tmp
->name
, name
) == 0)
873 patch_common_entries (tmp
, offset
, secnum
);
880 /* This macro adds the symbol-number for the start of the function
881 (the symbol number of the .bf) referenced by symnum_fcn to a
882 list. This list, in reality should be a FIFO queue but since
883 #line pragmas sometimes cause line ranges to get messed up
884 we simply create a linear list. This list can then be searched
885 first by a queueing algorithm and upon failure fall back to
889 #define ADD_BF_SYMNUM(bf_sym,fcn_sym) \
891 if (saved_bf_list == NULL) \
893 tmp_bf_ptr = allocate_saved_bf_node(); \
895 tmp_bf_ptr->symnum_bf = (bf_sym); \
896 tmp_bf_ptr->symnum_fcn = (fcn_sym); \
897 tmp_bf_ptr->next = NULL; \
899 current_head_bf_list = saved_bf_list = tmp_bf_ptr; \
900 saved_bf_list_end = tmp_bf_ptr; \
904 tmp_bf_ptr = allocate_saved_bf_node(); \
906 tmp_bf_ptr->symnum_bf = (bf_sym); \
907 tmp_bf_ptr->symnum_fcn = (fcn_sym); \
908 tmp_bf_ptr->next = NULL; \
910 saved_bf_list_end->next = tmp_bf_ptr; \
911 saved_bf_list_end = tmp_bf_ptr; \
915 /* This function frees the entire (.bf,function) list */
922 SAVED_BF_PTR tmp
= saved_bf_list
;
923 SAVED_BF_PTR next
= NULL
;
931 saved_bf_list
= NULL
;
935 int global_remote_debug
;
940 get_bf_for_fcn (long the_function
)
945 /* First use a simple queuing algorithm (i.e. look and see if the
946 item at the head of the queue is the one you want) */
948 if (saved_bf_list
== NULL
)
949 internal_error (__FILE__
, __LINE__
,
950 _("cannot get .bf node off empty list"));
952 if (current_head_bf_list
!= NULL
)
953 if (current_head_bf_list
->symnum_fcn
== the_function
)
955 if (global_remote_debug
)
956 fprintf_unfiltered (gdb_stderr
, "*");
958 tmp
= current_head_bf_list
;
959 current_head_bf_list
= current_head_bf_list
->next
;
960 return (tmp
->symnum_bf
);
963 /* If the above did not work (probably because #line directives were
964 used in the sourcefile and they messed up our internal tables) we now do
965 the ugly linear scan */
967 if (global_remote_debug
)
968 fprintf_unfiltered (gdb_stderr
, "\ndefaulting to linear scan\n");
975 if (tmp
->symnum_fcn
== the_function
)
977 if (global_remote_debug
)
978 fprintf_unfiltered (gdb_stderr
, "Found in %d probes\n", nprobes
);
979 current_head_bf_list
= tmp
->next
;
980 return (tmp
->symnum_bf
);
988 static SAVED_FUNCTION_PTR saved_function_list
= NULL
;
989 static SAVED_FUNCTION_PTR saved_function_list_end
= NULL
;
992 clear_function_list (void)
994 SAVED_FUNCTION_PTR tmp
= saved_function_list
;
995 SAVED_FUNCTION_PTR next
= NULL
;
1004 saved_function_list
= NULL
;