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