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