* infrun.c (adjust_pc_after_break): Do not assume software single-step
[deliverable/binutils-gdb.git] / gdb / f-lang.c
1 /* Fortran language support routines for GDB, the GNU debugger.
2
3 Copyright (C) 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003,
4 2004, 2005, 2007 Free Software Foundation, Inc.
5
6 Contributed by Motorola. Adapted from the C parser by Farooq Butt
7 (fmbutt@engage.sps.mot.com).
8
9 This file is part of GDB.
10
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.
15
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.
20
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. */
25
26 #include "defs.h"
27 #include "gdb_string.h"
28 #include "symtab.h"
29 #include "gdbtypes.h"
30 #include "expression.h"
31 #include "parser-defs.h"
32 #include "language.h"
33 #include "f-lang.h"
34 #include "valprint.h"
35 #include "value.h"
36
37
38 /* Following is dubious stuff that had been in the xcoff reader. */
39
40 struct saved_fcn
41 {
42 long line_offset; /* Line offset for function */
43 struct saved_fcn *next;
44 };
45
46
47 struct saved_bf_symnum
48 {
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;
52 };
53
54 typedef struct saved_fcn SAVED_FUNCTION, *SAVED_FUNCTION_PTR;
55 typedef struct saved_bf_symnum SAVED_BF, *SAVED_BF_PTR;
56
57 /* Local functions */
58
59 extern void _initialize_f_language (void);
60 #if 0
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);
73 #endif
74
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);
78
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. */
84
85 static void
86 f_emit_char (int c, struct ui_file *stream, int quoter)
87 {
88 c &= 0xFF; /* Avoid sign bit follies */
89
90 if (PRINT_LITERAL_FORM (c))
91 {
92 if (c == '\\' || c == quoter)
93 fputs_filtered ("\\", stream);
94 fprintf_filtered (stream, "%c", c);
95 }
96 else
97 {
98 switch (c)
99 {
100 case '\n':
101 fputs_filtered ("\\n", stream);
102 break;
103 case '\b':
104 fputs_filtered ("\\b", stream);
105 break;
106 case '\t':
107 fputs_filtered ("\\t", stream);
108 break;
109 case '\f':
110 fputs_filtered ("\\f", stream);
111 break;
112 case '\r':
113 fputs_filtered ("\\r", stream);
114 break;
115 case '\033':
116 fputs_filtered ("\\e", stream);
117 break;
118 case '\007':
119 fputs_filtered ("\\a", stream);
120 break;
121 default:
122 fprintf_filtered (stream, "\\%.3o", (unsigned int) c);
123 break;
124 }
125 }
126 }
127
128 /* FIXME: This is a copy of the same function from c-exp.y. It should
129 be replaced with a true F77version. */
130
131 static void
132 f_printchar (int c, struct ui_file *stream)
133 {
134 fputs_filtered ("'", stream);
135 LA_EMIT_CHAR (c, stream, '\'');
136 fputs_filtered ("'", stream);
137 }
138
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. */
145
146 static void
147 f_printstr (struct ui_file *stream, const gdb_byte *string,
148 unsigned int length, int width, int force_ellipses)
149 {
150 unsigned int i;
151 unsigned int things_printed = 0;
152 int in_quotes = 0;
153 int need_comma = 0;
154
155 if (length == 0)
156 {
157 fputs_filtered ("''", gdb_stdout);
158 return;
159 }
160
161 for (i = 0; i < length && things_printed < print_max; ++i)
162 {
163 /* Position of the character we are examining
164 to see whether it is repeated. */
165 unsigned int rep1;
166 /* Number of repetitions we have detected so far. */
167 unsigned int reps;
168
169 QUIT;
170
171 if (need_comma)
172 {
173 fputs_filtered (", ", stream);
174 need_comma = 0;
175 }
176
177 rep1 = i + 1;
178 reps = 1;
179 while (rep1 < length && string[rep1] == string[i])
180 {
181 ++rep1;
182 ++reps;
183 }
184
185 if (reps > repeat_count_threshold)
186 {
187 if (in_quotes)
188 {
189 if (inspect_it)
190 fputs_filtered ("\\', ", stream);
191 else
192 fputs_filtered ("', ", stream);
193 in_quotes = 0;
194 }
195 f_printchar (string[i], stream);
196 fprintf_filtered (stream, " <repeats %u times>", reps);
197 i = rep1 - 1;
198 things_printed += repeat_count_threshold;
199 need_comma = 1;
200 }
201 else
202 {
203 if (!in_quotes)
204 {
205 if (inspect_it)
206 fputs_filtered ("\\'", stream);
207 else
208 fputs_filtered ("'", stream);
209 in_quotes = 1;
210 }
211 LA_EMIT_CHAR (string[i], stream, '"');
212 ++things_printed;
213 }
214 }
215
216 /* Terminate the quotes if necessary. */
217 if (in_quotes)
218 {
219 if (inspect_it)
220 fputs_filtered ("\\'", stream);
221 else
222 fputs_filtered ("'", stream);
223 }
224
225 if (force_ellipses || i < length)
226 fputs_filtered ("...", stream);
227 }
228
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. */
232
233 static struct type *
234 f_create_fundamental_type (struct objfile *objfile, int typeid)
235 {
236 struct type *type = NULL;
237
238 switch (typeid)
239 {
240 case FT_VOID:
241 type = init_type (TYPE_CODE_VOID,
242 TARGET_CHAR_BIT / TARGET_CHAR_BIT,
243 0, "VOID", objfile);
244 break;
245 case FT_BOOLEAN:
246 type = init_type (TYPE_CODE_BOOL,
247 TARGET_CHAR_BIT / TARGET_CHAR_BIT,
248 TYPE_FLAG_UNSIGNED, "boolean", objfile);
249 break;
250 case FT_STRING:
251 type = init_type (TYPE_CODE_STRING,
252 TARGET_CHAR_BIT / TARGET_CHAR_BIT,
253 0, "string", objfile);
254 break;
255 case FT_CHAR:
256 type = init_type (TYPE_CODE_INT,
257 TARGET_CHAR_BIT / TARGET_CHAR_BIT,
258 0, "character", objfile);
259 break;
260 case FT_SIGNED_CHAR:
261 type = init_type (TYPE_CODE_INT,
262 TARGET_CHAR_BIT / TARGET_CHAR_BIT,
263 0, "integer*1", objfile);
264 break;
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);
269 break;
270 case FT_SHORT:
271 type = init_type (TYPE_CODE_INT,
272 gdbarch_short_bit (current_gdbarch) / TARGET_CHAR_BIT,
273 0, "integer*2", objfile);
274 break;
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 */
279 break;
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);
284 break;
285 case FT_INTEGER:
286 type = init_type (TYPE_CODE_INT,
287 gdbarch_int_bit (current_gdbarch) / TARGET_CHAR_BIT,
288 0, "integer*4", objfile);
289 break;
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 */
294 break;
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);
299 break;
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);
304 break;
305 case FT_LONG:
306 type = init_type (TYPE_CODE_INT,
307 gdbarch_long_bit (current_gdbarch) / TARGET_CHAR_BIT,
308 0, "long", objfile);
309 break;
310 case FT_SIGNED_LONG:
311 type = init_type (TYPE_CODE_INT,
312 gdbarch_long_bit (current_gdbarch) / TARGET_CHAR_BIT,
313 0, "long", objfile); /* FIXME -fnf */
314 break;
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);
319 break;
320 case FT_LONG_LONG:
321 type = init_type (TYPE_CODE_INT,
322 gdbarch_long_long_bit (current_gdbarch)
323 / TARGET_CHAR_BIT,
324 0, "long long", objfile);
325 break;
326 case FT_SIGNED_LONG_LONG:
327 type = init_type (TYPE_CODE_INT,
328 gdbarch_long_long_bit (current_gdbarch)
329 / TARGET_CHAR_BIT,
330 0, "signed long long", objfile);
331 break;
332 case FT_UNSIGNED_LONG_LONG:
333 type = init_type (TYPE_CODE_INT,
334 gdbarch_long_long_bit (current_gdbarch)
335 / TARGET_CHAR_BIT,
336 TYPE_FLAG_UNSIGNED, "unsigned long long", objfile);
337 break;
338 case FT_FLOAT:
339 type = init_type (TYPE_CODE_FLT,
340 gdbarch_float_bit (current_gdbarch) / TARGET_CHAR_BIT,
341 0, "real", objfile);
342 break;
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);
347 break;
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);
352 break;
353 case FT_EXT_PREC_FLOAT:
354 type = init_type (TYPE_CODE_FLT,
355 gdbarch_long_double_bit (current_gdbarch)
356 / TARGET_CHAR_BIT,
357 0, "real*16", objfile);
358 break;
359 case FT_COMPLEX:
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;
364 break;
365 case FT_DBL_PREC_COMPLEX:
366 type = init_type (TYPE_CODE_COMPLEX,
367 2 * gdbarch_double_bit (current_gdbarch)
368 / TARGET_CHAR_BIT,
369 0, "complex*16", objfile);
370 TYPE_TARGET_TYPE (type) = builtin_type_f_real_s8;
371 break;
372 case FT_EXT_PREC_COMPLEX:
373 type = init_type (TYPE_CODE_COMPLEX,
374 2 * gdbarch_long_double_bit (current_gdbarch)
375 / TARGET_CHAR_BIT,
376 0, "complex*32", objfile);
377 TYPE_TARGET_TYPE (type) = builtin_type_f_real_s16;
378 break;
379 default:
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);
388 break;
389 }
390 return (type);
391 }
392 \f
393
394 /* Table of operators and their precedences for printing expressions. */
395
396 static const struct op_print f_op_print_tab[] =
397 {
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},
418 {NULL, 0, 0, 0}
419 };
420 \f
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,
434 nr_f_primitive_types
435 };
436
437 static void
438 f_language_arch_info (struct gdbarch *gdbarch,
439 struct language_arch_info *lai)
440 {
441 const struct builtin_f_type *builtin = builtin_f_type (gdbarch);
442
443 lai->string_char_type = builtin->builtin_character;
444 lai->primitive_type_vector
445 = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_f_primitive_types + 1,
446 struct type *);
447
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;
468 }
469
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);
474
475 const struct language_defn f_language_defn =
476 {
477 "fortran",
478 language_fortran,
479 NULL,
480 range_check_on,
481 type_check_on,
482 case_sensitive_off,
483 array_column_major,
484 &exp_descriptor_standard,
485 f_parse, /* parser */
486 f_error, /* parser error function */
487 null_post_parser,
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 */
504 NULL,
505 default_word_break_characters,
506 f_language_arch_info,
507 default_print_array_index,
508 LANG_MAGIC
509 };
510
511 static void *
512 build_fortran_types (struct gdbarch *gdbarch)
513 {
514 struct builtin_f_type *builtin_f_type
515 = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct builtin_f_type);
516
517 builtin_f_type->builtin_void =
518 init_type (TYPE_CODE_VOID, 1,
519 0,
520 "VOID", (struct objfile *) NULL);
521
522 builtin_f_type->builtin_character =
523 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
524 0,
525 "character", (struct objfile *) NULL);
526
527 builtin_f_type->builtin_logical_s1 =
528 init_type (TYPE_CODE_BOOL, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
529 TYPE_FLAG_UNSIGNED,
530 "logical*1", (struct objfile *) NULL);
531
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);
536
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);
541
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);
546
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);
551
552 builtin_f_type->builtin_real =
553 init_type (TYPE_CODE_FLT,
554 gdbarch_float_bit (current_gdbarch) / TARGET_CHAR_BIT,
555 0,
556 "real", (struct objfile *) NULL);
557
558 builtin_f_type->builtin_real_s8 =
559 init_type (TYPE_CODE_FLT,
560 gdbarch_double_bit (current_gdbarch) / TARGET_CHAR_BIT,
561 0,
562 "real*8", (struct objfile *) NULL);
563
564 builtin_f_type->builtin_real_s16 =
565 init_type (TYPE_CODE_FLT,
566 gdbarch_long_double_bit (current_gdbarch) / TARGET_CHAR_BIT,
567 0,
568 "real*16", (struct objfile *) NULL);
569
570 builtin_f_type->builtin_complex_s8 =
571 init_type (TYPE_CODE_COMPLEX,
572 2 * gdbarch_float_bit (current_gdbarch) / TARGET_CHAR_BIT,
573 0,
574 "complex*8", (struct objfile *) NULL);
575 TYPE_TARGET_TYPE (builtin_f_type->builtin_complex_s8)
576 = builtin_f_type->builtin_real;
577
578 builtin_f_type->builtin_complex_s16 =
579 init_type (TYPE_CODE_COMPLEX,
580 2 * gdbarch_double_bit (current_gdbarch) / TARGET_CHAR_BIT,
581 0,
582 "complex*16", (struct objfile *) NULL);
583 TYPE_TARGET_TYPE (builtin_f_type->builtin_complex_s16)
584 = builtin_f_type->builtin_real_s8;
585
586 /* We have a new size == 4 double floats for the
587 complex*32 data type */
588
589 builtin_f_type->builtin_complex_s32 =
590 init_type (TYPE_CODE_COMPLEX,
591 2 * gdbarch_long_double_bit (current_gdbarch) / TARGET_CHAR_BIT,
592 0,
593 "complex*32", (struct objfile *) NULL);
594 TYPE_TARGET_TYPE (builtin_f_type->builtin_complex_s32)
595 = builtin_f_type->builtin_real_s16;
596
597 return builtin_f_type;
598 }
599
600 static struct gdbarch_data *f_type_data;
601
602 const struct builtin_f_type *
603 builtin_f_type (struct gdbarch *gdbarch)
604 {
605 return gdbarch_data (gdbarch, f_type_data);
606 }
607
608 void
609 _initialize_f_language (void)
610 {
611 f_type_data = gdbarch_data_register_post_init (build_fortran_types);
612
613 add_language (&f_language_defn);
614 }
615
616 #if 0
617 static SAVED_BF_PTR
618 allocate_saved_bf_node (void)
619 {
620 SAVED_BF_PTR new;
621
622 new = (SAVED_BF_PTR) xmalloc (sizeof (SAVED_BF));
623 return (new);
624 }
625
626 static SAVED_FUNCTION *
627 allocate_saved_function_node (void)
628 {
629 SAVED_FUNCTION *new;
630
631 new = (SAVED_FUNCTION *) xmalloc (sizeof (SAVED_FUNCTION));
632 return (new);
633 }
634
635 static SAVED_F77_COMMON_PTR
636 allocate_saved_f77_common_node (void)
637 {
638 SAVED_F77_COMMON_PTR new;
639
640 new = (SAVED_F77_COMMON_PTR) xmalloc (sizeof (SAVED_F77_COMMON));
641 return (new);
642 }
643
644 static COMMON_ENTRY_PTR
645 allocate_common_entry_node (void)
646 {
647 COMMON_ENTRY_PTR new;
648
649 new = (COMMON_ENTRY_PTR) xmalloc (sizeof (COMMON_ENTRY));
650 return (new);
651 }
652 #endif
653
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 */
657
658 #if 0
659 static SAVED_BF_PTR saved_bf_list = NULL; /* Ptr to (.bf,function)
660 list */
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
663 */
664
665 static SAVED_BF_PTR tmp_bf_ptr; /* Generic temporary for use
666 in macros */
667
668 /* The following function simply enters a given common block onto
669 the global common block chain */
670
671 static void
672 add_common_block (char *name, CORE_ADDR offset, int secnum, char *func_stab)
673 {
674 SAVED_F77_COMMON_PTR tmp;
675 char *c, *local_copy_func_stab;
676
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
680 parser have fits. */
681
682
683 if (strcmp (name, BLANK_COMMON_NAME_ORIGINAL) == 0
684 || strcmp (name, BLANK_COMMON_NAME_MF77) == 0)
685 {
686
687 xfree (name);
688 name = alloca (strlen (BLANK_COMMON_NAME_LOCAL) + 1);
689 strcpy (name, BLANK_COMMON_NAME_LOCAL);
690 }
691
692 tmp = allocate_saved_f77_common_node ();
693
694 local_copy_func_stab = xmalloc (strlen (func_stab) + 1);
695 strcpy (local_copy_func_stab, func_stab);
696
697 tmp->name = xmalloc (strlen (name) + 1);
698
699 /* local_copy_func_stab is a stabstring, let us first extract the
700 function name from the stab by NULLing out the ':' character. */
701
702
703 c = NULL;
704 c = strchr (local_copy_func_stab, ':');
705
706 if (c)
707 *c = '\0';
708 else
709 error (_("Malformed function STAB found in add_common_block()"));
710
711
712 tmp->owning_function = xmalloc (strlen (local_copy_func_stab) + 1);
713
714 strcpy (tmp->owning_function, local_copy_func_stab);
715
716 strcpy (tmp->name, name);
717 tmp->offset = offset;
718 tmp->next = NULL;
719 tmp->entries = NULL;
720 tmp->secnum = secnum;
721
722 current_common = tmp;
723
724 if (head_common_list == NULL)
725 {
726 head_common_list = tail_common_list = tmp;
727 }
728 else
729 {
730 tail_common_list->next = tmp;
731 tail_common_list = tmp;
732 }
733 }
734 #endif
735
736 /* The following function simply enters a given common entry onto
737 the "current_common" block that has been saved away. */
738
739 #if 0
740 static void
741 add_common_entry (struct symbol *entry_sym_ptr)
742 {
743 COMMON_ENTRY_PTR tmp;
744
745
746
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 */
750
751 tmp = allocate_common_entry_node ();
752
753 tmp->next = NULL;
754 tmp->symbol = entry_sym_ptr;
755
756 if (current_common == NULL)
757 error (_("Attempt to add COMMON entry with no block open!"));
758 else
759 {
760 if (current_common->entries == NULL)
761 {
762 current_common->entries = tmp;
763 current_common->end_of_entries = tmp;
764 }
765 else
766 {
767 current_common->end_of_entries->next = tmp;
768 current_common->end_of_entries = tmp;
769 }
770 }
771 }
772 #endif
773
774 /* This routine finds the first encountred COMMON block named "name" */
775
776 #if 0
777 static SAVED_F77_COMMON_PTR
778 find_first_common_named (char *name)
779 {
780
781 SAVED_F77_COMMON_PTR tmp;
782
783 tmp = head_common_list;
784
785 while (tmp != NULL)
786 {
787 if (strcmp (tmp->name, name) == 0)
788 return (tmp);
789 else
790 tmp = tmp->next;
791 }
792 return (NULL);
793 }
794 #endif
795
796 /* This routine finds the first encountred COMMON block named "name"
797 that belongs to function funcname */
798
799 SAVED_F77_COMMON_PTR
800 find_common_for_function (char *name, char *funcname)
801 {
802
803 SAVED_F77_COMMON_PTR tmp;
804
805 tmp = head_common_list;
806
807 while (tmp != NULL)
808 {
809 if (DEPRECATED_STREQ (tmp->name, name)
810 && DEPRECATED_STREQ (tmp->owning_function, funcname))
811 return (tmp);
812 else
813 tmp = tmp->next;
814 }
815 return (NULL);
816 }
817
818
819 #if 0
820
821 /* The following function is called to patch up the offsets
822 for the statics contained in the COMMON block named
823 "name." */
824
825 static void
826 patch_common_entries (SAVED_F77_COMMON_PTR blk, CORE_ADDR offset, int secnum)
827 {
828 COMMON_ENTRY_PTR entry;
829
830 blk->offset = offset; /* Keep this around for future use. */
831
832 entry = blk->entries;
833
834 while (entry != NULL)
835 {
836 SYMBOL_VALUE (entry->symbol) += offset;
837 SYMBOL_SECTION (entry->symbol) = secnum;
838
839 entry = entry->next;
840 }
841 blk->secnum = secnum;
842 }
843
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). */
849
850 static void
851 patch_all_commons_by_name (char *name, CORE_ADDR offset, int secnum)
852 {
853
854 SAVED_F77_COMMON_PTR tmp;
855
856 /* For blank common blocks, change the canonical reprsentation
857 of a blank name */
858
859 if (strcmp (name, BLANK_COMMON_NAME_ORIGINAL) == 0
860 || strcmp (name, BLANK_COMMON_NAME_MF77) == 0)
861 {
862 xfree (name);
863 name = alloca (strlen (BLANK_COMMON_NAME_LOCAL) + 1);
864 strcpy (name, BLANK_COMMON_NAME_LOCAL);
865 }
866
867 tmp = head_common_list;
868
869 while (tmp != NULL)
870 {
871 if (COMMON_NEEDS_PATCHING (tmp))
872 if (strcmp (tmp->name, name) == 0)
873 patch_common_entries (tmp, offset, secnum);
874
875 tmp = tmp->next;
876 }
877 }
878 #endif
879
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
886 a linear scan. */
887
888 #if 0
889 #define ADD_BF_SYMNUM(bf_sym,fcn_sym) \
890 \
891 if (saved_bf_list == NULL) \
892 { \
893 tmp_bf_ptr = allocate_saved_bf_node(); \
894 \
895 tmp_bf_ptr->symnum_bf = (bf_sym); \
896 tmp_bf_ptr->symnum_fcn = (fcn_sym); \
897 tmp_bf_ptr->next = NULL; \
898 \
899 current_head_bf_list = saved_bf_list = tmp_bf_ptr; \
900 saved_bf_list_end = tmp_bf_ptr; \
901 } \
902 else \
903 { \
904 tmp_bf_ptr = allocate_saved_bf_node(); \
905 \
906 tmp_bf_ptr->symnum_bf = (bf_sym); \
907 tmp_bf_ptr->symnum_fcn = (fcn_sym); \
908 tmp_bf_ptr->next = NULL; \
909 \
910 saved_bf_list_end->next = tmp_bf_ptr; \
911 saved_bf_list_end = tmp_bf_ptr; \
912 }
913 #endif
914
915 /* This function frees the entire (.bf,function) list */
916
917 #if 0
918 static void
919 clear_bf_list (void)
920 {
921
922 SAVED_BF_PTR tmp = saved_bf_list;
923 SAVED_BF_PTR next = NULL;
924
925 while (tmp != NULL)
926 {
927 next = tmp->next;
928 xfree (tmp);
929 tmp = next;
930 }
931 saved_bf_list = NULL;
932 }
933 #endif
934
935 int global_remote_debug;
936
937 #if 0
938
939 static long
940 get_bf_for_fcn (long the_function)
941 {
942 SAVED_BF_PTR tmp;
943 int nprobes = 0;
944
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) */
947
948 if (saved_bf_list == NULL)
949 internal_error (__FILE__, __LINE__,
950 _("cannot get .bf node off empty list"));
951
952 if (current_head_bf_list != NULL)
953 if (current_head_bf_list->symnum_fcn == the_function)
954 {
955 if (global_remote_debug)
956 fprintf_unfiltered (gdb_stderr, "*");
957
958 tmp = current_head_bf_list;
959 current_head_bf_list = current_head_bf_list->next;
960 return (tmp->symnum_bf);
961 }
962
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 */
966
967 if (global_remote_debug)
968 fprintf_unfiltered (gdb_stderr, "\ndefaulting to linear scan\n");
969
970 nprobes = 0;
971 tmp = saved_bf_list;
972 while (tmp != NULL)
973 {
974 nprobes++;
975 if (tmp->symnum_fcn == the_function)
976 {
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);
981 }
982 tmp = tmp->next;
983 }
984
985 return (-1);
986 }
987
988 static SAVED_FUNCTION_PTR saved_function_list = NULL;
989 static SAVED_FUNCTION_PTR saved_function_list_end = NULL;
990
991 static void
992 clear_function_list (void)
993 {
994 SAVED_FUNCTION_PTR tmp = saved_function_list;
995 SAVED_FUNCTION_PTR next = NULL;
996
997 while (tmp != NULL)
998 {
999 next = tmp->next;
1000 xfree (tmp);
1001 tmp = next;
1002 }
1003
1004 saved_function_list = NULL;
1005 }
1006 #endif
This page took 0.050878 seconds and 4 git commands to generate.