gdb/
[deliverable/binutils-gdb.git] / gdb / f-lang.c
CommitLineData
c906108c 1/* Fortran language support routines for GDB, the GNU debugger.
ce27fb25 2
6aba47ca 3 Copyright (C) 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003,
7b6bb8da 4 2004, 2005, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
ce27fb25 5
c906108c
SS
6 Contributed by Motorola. Adapted from the C parser by Farooq Butt
7 (fmbutt@engage.sps.mot.com).
8
c5aa993b 9 This file is part of GDB.
c906108c 10
c5aa993b
JM
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
a9762ec7 13 the Free Software Foundation; either version 3 of the License, or
c5aa993b 14 (at your option) any later version.
c906108c 15
c5aa993b
JM
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.
c906108c 20
c5aa993b 21 You should have received a copy of the GNU General Public License
a9762ec7 22 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c
SS
23
24#include "defs.h"
25#include "gdb_string.h"
26#include "symtab.h"
27#include "gdbtypes.h"
28#include "expression.h"
29#include "parser-defs.h"
30#include "language.h"
31#include "f-lang.h"
745b8ca0 32#include "valprint.h"
5f9a71c3 33#include "value.h"
f55ee35c 34#include "cp-support.h"
3b2b8fea 35#include "charset.h"
c906108c 36
c906108c 37
0963b4bd 38/* Following is dubious stuff that had been in the xcoff reader. */
c906108c
SS
39
40struct saved_fcn
c5aa993b 41 {
0963b4bd 42 long line_offset; /* Line offset for function. */
c5aa993b
JM
43 struct saved_fcn *next;
44 };
c906108c
SS
45
46
c5aa993b
JM
47struct saved_bf_symnum
48 {
3e43a32a
MS
49 long symnum_fcn; /* Symnum of function (i.e. .function
50 directive). */
51 long symnum_bf; /* Symnum of .bf for this function. */
c5aa993b
JM
52 struct saved_bf_symnum *next;
53 };
c906108c 54
c5aa993b
JM
55typedef struct saved_fcn SAVED_FUNCTION, *SAVED_FUNCTION_PTR;
56typedef struct saved_bf_symnum SAVED_BF, *SAVED_BF_PTR;
c906108c
SS
57
58/* Local functions */
59
a14ed312 60extern void _initialize_f_language (void);
c906108c 61#if 0
a14ed312
KB
62static void clear_function_list (void);
63static long get_bf_for_fcn (long);
64static void clear_bf_list (void);
65static void patch_all_commons_by_name (char *, CORE_ADDR, int);
66static SAVED_F77_COMMON_PTR find_first_common_named (char *);
67static void add_common_entry (struct symbol *);
68static void add_common_block (char *, CORE_ADDR, int, char *);
69static SAVED_FUNCTION *allocate_saved_function_node (void);
70static SAVED_BF_PTR allocate_saved_bf_node (void);
71static COMMON_ENTRY_PTR allocate_common_entry_node (void);
72static SAVED_F77_COMMON_PTR allocate_saved_f77_common_node (void);
73static void patch_common_entries (SAVED_F77_COMMON_PTR, CORE_ADDR, int);
c906108c
SS
74#endif
75
6c7a06a3
TT
76static void f_printchar (int c, struct type *type, struct ui_file * stream);
77static void f_emit_char (int c, struct type *type,
78 struct ui_file * stream, int quoter);
c906108c 79
3b2b8fea
TT
80/* Return the encoding that should be used for the character type
81 TYPE. */
82
83static const char *
84f_get_encoding (struct type *type)
85{
86 const char *encoding;
87
88 switch (TYPE_LENGTH (type))
89 {
90 case 1:
91 encoding = target_charset (get_type_arch (type));
92 break;
93 case 4:
94 if (gdbarch_byte_order (get_type_arch (type)) == BFD_ENDIAN_BIG)
95 encoding = "UTF-32BE";
96 else
97 encoding = "UTF-32LE";
98 break;
99
100 default:
101 error (_("unrecognized character type"));
102 }
103
104 return encoding;
105}
106
c906108c
SS
107/* Print the character C on STREAM as part of the contents of a literal
108 string whose delimiter is QUOTER. Note that that format for printing
109 characters and strings is language specific.
110 FIXME: This is a copy of the same function from c-exp.y. It should
111 be replaced with a true F77 version. */
112
113static void
6c7a06a3 114f_emit_char (int c, struct type *type, struct ui_file *stream, int quoter)
c906108c 115{
3b2b8fea 116 const char *encoding = f_get_encoding (type);
c5aa993b 117
3b2b8fea 118 generic_emit_char (c, type, stream, quoter, encoding);
c906108c
SS
119}
120
3b2b8fea 121/* Implementation of la_printchar. */
c906108c
SS
122
123static void
6c7a06a3 124f_printchar (int c, struct type *type, struct ui_file *stream)
c906108c
SS
125{
126 fputs_filtered ("'", stream);
6c7a06a3 127 LA_EMIT_CHAR (c, type, stream, '\'');
c906108c
SS
128 fputs_filtered ("'", stream);
129}
130
131/* Print the character string STRING, printing at most LENGTH characters.
132 Printing stops early if the number hits print_max; repeat counts
133 are printed as appropriate. Print ellipses at the end if we
134 had to stop before printing LENGTH characters, or if FORCE_ELLIPSES.
135 FIXME: This is a copy of the same function from c-exp.y. It should
0963b4bd 136 be replaced with a true F77 version. */
c906108c
SS
137
138static void
6c7a06a3 139f_printstr (struct ui_file *stream, struct type *type, const gdb_byte *string,
be759fcf 140 unsigned int length, const char *encoding, int force_ellipses,
79a45b7d 141 const struct value_print_options *options)
c906108c 142{
3b2b8fea 143 const char *type_encoding = f_get_encoding (type);
c5aa993b 144
3b2b8fea
TT
145 if (TYPE_LENGTH (type) == 4)
146 fputs_filtered ("4_", stream);
c5aa993b 147
3b2b8fea
TT
148 if (!encoding || !*encoding)
149 encoding = type_encoding;
c5aa993b 150
3b2b8fea
TT
151 generic_printstr (stream, type, string, length, encoding,
152 force_ellipses, '\'', 0, options);
c906108c 153}
c906108c 154\f
c5aa993b 155
c906108c
SS
156/* Table of operators and their precedences for printing expressions. */
157
c5aa993b
JM
158static const struct op_print f_op_print_tab[] =
159{
160 {"+", BINOP_ADD, PREC_ADD, 0},
161 {"+", UNOP_PLUS, PREC_PREFIX, 0},
162 {"-", BINOP_SUB, PREC_ADD, 0},
163 {"-", UNOP_NEG, PREC_PREFIX, 0},
164 {"*", BINOP_MUL, PREC_MUL, 0},
165 {"/", BINOP_DIV, PREC_MUL, 0},
166 {"DIV", BINOP_INTDIV, PREC_MUL, 0},
167 {"MOD", BINOP_REM, PREC_MUL, 0},
168 {"=", BINOP_ASSIGN, PREC_ASSIGN, 1},
169 {".OR.", BINOP_LOGICAL_OR, PREC_LOGICAL_OR, 0},
170 {".AND.", BINOP_LOGICAL_AND, PREC_LOGICAL_AND, 0},
171 {".NOT.", UNOP_LOGICAL_NOT, PREC_PREFIX, 0},
172 {".EQ.", BINOP_EQUAL, PREC_EQUAL, 0},
173 {".NE.", BINOP_NOTEQUAL, PREC_EQUAL, 0},
174 {".LE.", BINOP_LEQ, PREC_ORDER, 0},
175 {".GE.", BINOP_GEQ, PREC_ORDER, 0},
176 {".GT.", BINOP_GTR, PREC_ORDER, 0},
177 {".LT.", BINOP_LESS, PREC_ORDER, 0},
178 {"**", UNOP_IND, PREC_PREFIX, 0},
179 {"@", BINOP_REPEAT, PREC_REPEAT, 0},
180 {NULL, 0, 0, 0}
c906108c
SS
181};
182\f
cad351d1
UW
183enum f_primitive_types {
184 f_primitive_type_character,
185 f_primitive_type_logical,
186 f_primitive_type_logical_s1,
187 f_primitive_type_logical_s2,
ce4b0682 188 f_primitive_type_logical_s8,
cad351d1
UW
189 f_primitive_type_integer,
190 f_primitive_type_integer_s2,
191 f_primitive_type_real,
192 f_primitive_type_real_s8,
193 f_primitive_type_real_s16,
194 f_primitive_type_complex_s8,
195 f_primitive_type_complex_s16,
196 f_primitive_type_void,
197 nr_f_primitive_types
c906108c
SS
198};
199
cad351d1
UW
200static void
201f_language_arch_info (struct gdbarch *gdbarch,
202 struct language_arch_info *lai)
203{
54ef06c7
UW
204 const struct builtin_f_type *builtin = builtin_f_type (gdbarch);
205
206 lai->string_char_type = builtin->builtin_character;
cad351d1
UW
207 lai->primitive_type_vector
208 = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_f_primitive_types + 1,
209 struct type *);
210
211 lai->primitive_type_vector [f_primitive_type_character]
54ef06c7 212 = builtin->builtin_character;
cad351d1 213 lai->primitive_type_vector [f_primitive_type_logical]
54ef06c7 214 = builtin->builtin_logical;
cad351d1 215 lai->primitive_type_vector [f_primitive_type_logical_s1]
54ef06c7 216 = builtin->builtin_logical_s1;
cad351d1 217 lai->primitive_type_vector [f_primitive_type_logical_s2]
54ef06c7 218 = builtin->builtin_logical_s2;
ce4b0682
SDJ
219 lai->primitive_type_vector [f_primitive_type_logical_s8]
220 = builtin->builtin_logical_s8;
cad351d1 221 lai->primitive_type_vector [f_primitive_type_real]
54ef06c7 222 = builtin->builtin_real;
cad351d1 223 lai->primitive_type_vector [f_primitive_type_real_s8]
54ef06c7 224 = builtin->builtin_real_s8;
cad351d1 225 lai->primitive_type_vector [f_primitive_type_real_s16]
54ef06c7 226 = builtin->builtin_real_s16;
cad351d1 227 lai->primitive_type_vector [f_primitive_type_complex_s8]
54ef06c7 228 = builtin->builtin_complex_s8;
cad351d1 229 lai->primitive_type_vector [f_primitive_type_complex_s16]
54ef06c7 230 = builtin->builtin_complex_s16;
cad351d1 231 lai->primitive_type_vector [f_primitive_type_void]
54ef06c7 232 = builtin->builtin_void;
fbb06eb1
UW
233
234 lai->bool_type_symbol = "logical";
235 lai->bool_type_default = builtin->builtin_logical_s2;
cad351d1
UW
236}
237
f55ee35c
JK
238/* Remove the modules separator :: from the default break list. */
239
240static char *
241f_word_break_characters (void)
242{
243 static char *retval;
244
245 if (!retval)
246 {
247 char *s;
248
249 retval = xstrdup (default_word_break_characters ());
250 s = strchr (retval, ':');
251 if (s)
252 {
253 char *last_char = &s[strlen (s) - 1];
254
255 *s = *last_char;
256 *last_char = 0;
257 }
258 }
259 return retval;
260}
261
3e43a32a
MS
262/* Consider the modules separator :: as a valid symbol name character
263 class. */
f55ee35c
JK
264
265static char **
266f_make_symbol_completion_list (char *text, char *word)
267{
268 return default_make_symbol_completion_list_break_on (text, word, ":");
269}
270
c906108c 271/* This is declared in c-lang.h but it is silly to import that file for what
0963b4bd 272 is already just a hack. */
79a45b7d
TT
273extern int c_value_print (struct value *, struct ui_file *,
274 const struct value_print_options *);
c906108c 275
c5aa993b
JM
276const struct language_defn f_language_defn =
277{
c906108c
SS
278 "fortran",
279 language_fortran,
c906108c
SS
280 range_check_on,
281 type_check_on,
63872f9d 282 case_sensitive_off,
7ca2d3a3 283 array_column_major,
9a044a89 284 macro_expansion_no,
5f9769d1 285 &exp_descriptor_standard,
c906108c
SS
286 f_parse, /* parser */
287 f_error, /* parser error function */
e85c3284 288 null_post_parser,
c906108c
SS
289 f_printchar, /* Print character constant */
290 f_printstr, /* function to print string constant */
291 f_emit_char, /* Function to print a single character */
c5aa993b 292 f_print_type, /* Print a type using appropriate syntax */
5c6ce71d 293 default_print_typedef, /* Print a typedef using appropriate syntax */
c906108c 294 f_val_print, /* Print a value using appropriate syntax */
c5aa993b 295 c_value_print, /* FIXME */
f636b87d 296 NULL, /* Language specific skip_trampoline */
2b2d9e11 297 NULL, /* name_of_this */
f55ee35c 298 cp_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
b368761e 299 basic_lookup_transparent_type,/* lookup_transparent_type */
9a3d7dfd 300 NULL, /* Language specific symbol demangler */
3e43a32a
MS
301 NULL, /* Language specific
302 class_name_from_physname */
c906108c
SS
303 f_op_print_tab, /* expression operators for printing */
304 0, /* arrays are first-class (not c-style) */
305 1, /* String lower bound */
f55ee35c
JK
306 f_word_break_characters,
307 f_make_symbol_completion_list,
cad351d1 308 f_language_arch_info,
e79af960 309 default_print_array_index,
41f1b697 310 default_pass_by_reference,
ae6a3a4c 311 default_get_string,
c906108c 312 LANG_MAGIC
c5aa993b 313};
c906108c 314
54ef06c7
UW
315static void *
316build_fortran_types (struct gdbarch *gdbarch)
c906108c 317{
54ef06c7
UW
318 struct builtin_f_type *builtin_f_type
319 = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct builtin_f_type);
320
e9bb382b
UW
321 builtin_f_type->builtin_void
322 = arch_type (gdbarch, TYPE_CODE_VOID, 1, "VOID");
323
324 builtin_f_type->builtin_character
325 = arch_integer_type (gdbarch, TARGET_CHAR_BIT, 0, "character");
326
327 builtin_f_type->builtin_logical_s1
328 = arch_boolean_type (gdbarch, TARGET_CHAR_BIT, 1, "logical*1");
329
330 builtin_f_type->builtin_integer_s2
331 = arch_integer_type (gdbarch, gdbarch_short_bit (gdbarch), 0,
332 "integer*2");
333
334 builtin_f_type->builtin_logical_s2
335 = arch_boolean_type (gdbarch, gdbarch_short_bit (gdbarch), 1,
336 "logical*2");
337
ce4b0682
SDJ
338 builtin_f_type->builtin_logical_s8
339 = arch_boolean_type (gdbarch, gdbarch_long_long_bit (gdbarch), 1,
340 "logical*8");
341
e9bb382b
UW
342 builtin_f_type->builtin_integer
343 = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch), 0,
344 "integer");
345
346 builtin_f_type->builtin_logical
347 = arch_boolean_type (gdbarch, gdbarch_int_bit (gdbarch), 1,
348 "logical*4");
349
350 builtin_f_type->builtin_real
351 = arch_float_type (gdbarch, gdbarch_float_bit (gdbarch),
352 "real", NULL);
353 builtin_f_type->builtin_real_s8
354 = arch_float_type (gdbarch, gdbarch_double_bit (gdbarch),
355 "real*8", NULL);
356 builtin_f_type->builtin_real_s16
357 = arch_float_type (gdbarch, gdbarch_long_double_bit (gdbarch),
358 "real*16", NULL);
359
360 builtin_f_type->builtin_complex_s8
361 = arch_complex_type (gdbarch, "complex*8",
362 builtin_f_type->builtin_real);
363 builtin_f_type->builtin_complex_s16
364 = arch_complex_type (gdbarch, "complex*16",
365 builtin_f_type->builtin_real_s8);
366 builtin_f_type->builtin_complex_s32
367 = arch_complex_type (gdbarch, "complex*32",
368 builtin_f_type->builtin_real_s16);
54ef06c7
UW
369
370 return builtin_f_type;
371}
372
373static struct gdbarch_data *f_type_data;
374
375const struct builtin_f_type *
376builtin_f_type (struct gdbarch *gdbarch)
377{
378 return gdbarch_data (gdbarch, f_type_data);
4e845cd3
MS
379}
380
381void
382_initialize_f_language (void)
383{
54ef06c7 384 f_type_data = gdbarch_data_register_post_init (build_fortran_types);
c906108c 385
c906108c
SS
386 add_language (&f_language_defn);
387}
388
389#if 0
390static SAVED_BF_PTR
fba45db2 391allocate_saved_bf_node (void)
c906108c
SS
392{
393 SAVED_BF_PTR new;
c5aa993b 394
c906108c 395 new = (SAVED_BF_PTR) xmalloc (sizeof (SAVED_BF));
c5aa993b 396 return (new);
c906108c
SS
397}
398
399static SAVED_FUNCTION *
fba45db2 400allocate_saved_function_node (void)
c906108c
SS
401{
402 SAVED_FUNCTION *new;
c5aa993b 403
c906108c 404 new = (SAVED_FUNCTION *) xmalloc (sizeof (SAVED_FUNCTION));
c5aa993b 405 return (new);
c906108c
SS
406}
407
c5aa993b 408static SAVED_F77_COMMON_PTR
fba45db2 409allocate_saved_f77_common_node (void)
c906108c
SS
410{
411 SAVED_F77_COMMON_PTR new;
c5aa993b 412
c906108c 413 new = (SAVED_F77_COMMON_PTR) xmalloc (sizeof (SAVED_F77_COMMON));
c5aa993b 414 return (new);
c906108c
SS
415}
416
c5aa993b 417static COMMON_ENTRY_PTR
fba45db2 418allocate_common_entry_node (void)
c906108c
SS
419{
420 COMMON_ENTRY_PTR new;
c5aa993b 421
c906108c 422 new = (COMMON_ENTRY_PTR) xmalloc (sizeof (COMMON_ENTRY));
c5aa993b 423 return (new);
c906108c
SS
424}
425#endif
426
c5aa993b
JM
427SAVED_F77_COMMON_PTR head_common_list = NULL; /* Ptr to 1st saved COMMON */
428SAVED_F77_COMMON_PTR tail_common_list = NULL; /* Ptr to last saved COMMON */
429SAVED_F77_COMMON_PTR current_common = NULL; /* Ptr to current COMMON */
c906108c
SS
430
431#if 0
c5aa993b
JM
432static SAVED_BF_PTR saved_bf_list = NULL; /* Ptr to (.bf,function)
433 list */
434static SAVED_BF_PTR saved_bf_list_end = NULL; /* Ptr to above list's end */
3e43a32a
MS
435static SAVED_BF_PTR current_head_bf_list = NULL; /* Current head of
436 above list. */
c906108c 437
c5aa993b 438static SAVED_BF_PTR tmp_bf_ptr; /* Generic temporary for use
0963b4bd 439 in macros. */
c906108c
SS
440
441/* The following function simply enters a given common block onto
0963b4bd 442 the global common block chain. */
c906108c
SS
443
444static void
fba45db2 445add_common_block (char *name, CORE_ADDR offset, int secnum, char *func_stab)
c906108c
SS
446{
447 SAVED_F77_COMMON_PTR tmp;
c5aa993b
JM
448 char *c, *local_copy_func_stab;
449
c906108c
SS
450 /* If the COMMON block we are trying to add has a blank
451 name (i.e. "#BLNK_COM") then we set it to __BLANK
452 because the darn "#" character makes GDB's input
0963b4bd 453 parser have fits. */
c5aa993b
JM
454
455
6314a349
AC
456 if (strcmp (name, BLANK_COMMON_NAME_ORIGINAL) == 0
457 || strcmp (name, BLANK_COMMON_NAME_MF77) == 0)
c906108c 458 {
c5aa993b 459
b8c9b27d 460 xfree (name);
c5aa993b
JM
461 name = alloca (strlen (BLANK_COMMON_NAME_LOCAL) + 1);
462 strcpy (name, BLANK_COMMON_NAME_LOCAL);
c906108c 463 }
c5aa993b
JM
464
465 tmp = allocate_saved_f77_common_node ();
466
467 local_copy_func_stab = xmalloc (strlen (func_stab) + 1);
468 strcpy (local_copy_func_stab, func_stab);
469
470 tmp->name = xmalloc (strlen (name) + 1);
471
c906108c 472 /* local_copy_func_stab is a stabstring, let us first extract the
0963b4bd 473 function name from the stab by NULLing out the ':' character. */
c5aa993b
JM
474
475
476 c = NULL;
477 c = strchr (local_copy_func_stab, ':');
478
c906108c
SS
479 if (c)
480 *c = '\0';
481 else
8a3fe4f8 482 error (_("Malformed function STAB found in add_common_block()"));
c5aa993b
JM
483
484
485 tmp->owning_function = xmalloc (strlen (local_copy_func_stab) + 1);
486
487 strcpy (tmp->owning_function, local_copy_func_stab);
488
489 strcpy (tmp->name, name);
490 tmp->offset = offset;
c906108c
SS
491 tmp->next = NULL;
492 tmp->entries = NULL;
c5aa993b
JM
493 tmp->secnum = secnum;
494
c906108c 495 current_common = tmp;
c5aa993b 496
c906108c
SS
497 if (head_common_list == NULL)
498 {
499 head_common_list = tail_common_list = tmp;
500 }
501 else
502 {
c5aa993b 503 tail_common_list->next = tmp;
c906108c
SS
504 tail_common_list = tmp;
505 }
506}
507#endif
508
509/* The following function simply enters a given common entry onto
0963b4bd 510 the "current_common" block that has been saved away. */
c906108c
SS
511
512#if 0
513static void
fba45db2 514add_common_entry (struct symbol *entry_sym_ptr)
c906108c
SS
515{
516 COMMON_ENTRY_PTR tmp;
c5aa993b
JM
517
518
519
c906108c
SS
520 /* The order of this list is important, since
521 we expect the entries to appear in decl.
0963b4bd 522 order when we later issue "info common" calls. */
c5aa993b
JM
523
524 tmp = allocate_common_entry_node ();
525
c906108c
SS
526 tmp->next = NULL;
527 tmp->symbol = entry_sym_ptr;
c5aa993b 528
c906108c 529 if (current_common == NULL)
8a3fe4f8 530 error (_("Attempt to add COMMON entry with no block open!"));
c5aa993b 531 else
c906108c
SS
532 {
533 if (current_common->entries == NULL)
534 {
535 current_common->entries = tmp;
c5aa993b 536 current_common->end_of_entries = tmp;
c906108c
SS
537 }
538 else
539 {
c5aa993b
JM
540 current_common->end_of_entries->next = tmp;
541 current_common->end_of_entries = tmp;
c906108c
SS
542 }
543 }
544}
545#endif
546
0963b4bd 547/* This routine finds the first encountred COMMON block named "name". */
c906108c
SS
548
549#if 0
550static SAVED_F77_COMMON_PTR
fba45db2 551find_first_common_named (char *name)
c906108c 552{
c5aa993b 553
c906108c 554 SAVED_F77_COMMON_PTR tmp;
c5aa993b 555
c906108c 556 tmp = head_common_list;
c5aa993b 557
c906108c
SS
558 while (tmp != NULL)
559 {
6314a349 560 if (strcmp (tmp->name, name) == 0)
c5aa993b 561 return (tmp);
c906108c
SS
562 else
563 tmp = tmp->next;
564 }
c5aa993b 565 return (NULL);
c906108c
SS
566}
567#endif
568
569/* This routine finds the first encountred COMMON block named "name"
0963b4bd 570 that belongs to function funcname. */
c906108c 571
c5aa993b 572SAVED_F77_COMMON_PTR
fba45db2 573find_common_for_function (char *name, char *funcname)
c906108c 574{
c5aa993b 575
c906108c 576 SAVED_F77_COMMON_PTR tmp;
c5aa993b 577
c906108c 578 tmp = head_common_list;
c5aa993b 579
c906108c
SS
580 while (tmp != NULL)
581 {
7ecb6532
MD
582 if (strcmp (tmp->name, name) == 0
583 && strcmp (tmp->owning_function, funcname) == 0)
c5aa993b 584 return (tmp);
c906108c
SS
585 else
586 tmp = tmp->next;
587 }
c5aa993b 588 return (NULL);
c906108c
SS
589}
590
591
592#if 0
593
594/* The following function is called to patch up the offsets
595 for the statics contained in the COMMON block named
c5aa993b 596 "name." */
c906108c
SS
597
598static void
fba45db2 599patch_common_entries (SAVED_F77_COMMON_PTR blk, CORE_ADDR offset, int secnum)
c906108c
SS
600{
601 COMMON_ENTRY_PTR entry;
c5aa993b 602
0963b4bd 603 blk->offset = offset; /* Keep this around for future use. */
c5aa993b 604
c906108c 605 entry = blk->entries;
c5aa993b 606
c906108c
SS
607 while (entry != NULL)
608 {
c5aa993b 609 SYMBOL_VALUE (entry->symbol) += offset;
c906108c 610 SYMBOL_SECTION (entry->symbol) = secnum;
c5aa993b 611
c906108c
SS
612 entry = entry->next;
613 }
c5aa993b 614 blk->secnum = secnum;
c906108c
SS
615}
616
617/* Patch all commons named "name" that need patching.Since COMMON
618 blocks occur with relative infrequency, we simply do a linear scan on
619 the name. Eventually, the best way to do this will be a
620 hashed-lookup. Secnum is the section number for the .bss section
0963b4bd 621 (which is where common data lives). */
c906108c
SS
622
623static void
fba45db2 624patch_all_commons_by_name (char *name, CORE_ADDR offset, int secnum)
c906108c 625{
c5aa993b 626
c906108c 627 SAVED_F77_COMMON_PTR tmp;
c5aa993b 628
c906108c
SS
629 /* For blank common blocks, change the canonical reprsentation
630 of a blank name */
c5aa993b 631
6314a349
AC
632 if (strcmp (name, BLANK_COMMON_NAME_ORIGINAL) == 0
633 || strcmp (name, BLANK_COMMON_NAME_MF77) == 0)
c906108c 634 {
b8c9b27d 635 xfree (name);
c5aa993b
JM
636 name = alloca (strlen (BLANK_COMMON_NAME_LOCAL) + 1);
637 strcpy (name, BLANK_COMMON_NAME_LOCAL);
c906108c 638 }
c5aa993b 639
c906108c 640 tmp = head_common_list;
c5aa993b 641
c906108c
SS
642 while (tmp != NULL)
643 {
c5aa993b 644 if (COMMON_NEEDS_PATCHING (tmp))
6314a349 645 if (strcmp (tmp->name, name) == 0)
c5aa993b
JM
646 patch_common_entries (tmp, offset, secnum);
647
c906108c 648 tmp = tmp->next;
c5aa993b 649 }
c906108c
SS
650}
651#endif
652
653/* This macro adds the symbol-number for the start of the function
654 (the symbol number of the .bf) referenced by symnum_fcn to a
655 list. This list, in reality should be a FIFO queue but since
656 #line pragmas sometimes cause line ranges to get messed up
657 we simply create a linear list. This list can then be searched
658 first by a queueing algorithm and upon failure fall back to
0963b4bd 659 a linear scan. */
c906108c
SS
660
661#if 0
662#define ADD_BF_SYMNUM(bf_sym,fcn_sym) \
663 \
664 if (saved_bf_list == NULL) \
665{ \
666 tmp_bf_ptr = allocate_saved_bf_node(); \
667 \
668 tmp_bf_ptr->symnum_bf = (bf_sym); \
669 tmp_bf_ptr->symnum_fcn = (fcn_sym); \
670 tmp_bf_ptr->next = NULL; \
671 \
672 current_head_bf_list = saved_bf_list = tmp_bf_ptr; \
673 saved_bf_list_end = tmp_bf_ptr; \
674 } \
675else \
676{ \
677 tmp_bf_ptr = allocate_saved_bf_node(); \
678 \
679 tmp_bf_ptr->symnum_bf = (bf_sym); \
680 tmp_bf_ptr->symnum_fcn = (fcn_sym); \
681 tmp_bf_ptr->next = NULL; \
682 \
683 saved_bf_list_end->next = tmp_bf_ptr; \
684 saved_bf_list_end = tmp_bf_ptr; \
c5aa993b 685 }
c906108c
SS
686#endif
687
0963b4bd 688/* This function frees the entire (.bf,function) list. */
c906108c
SS
689
690#if 0
c5aa993b 691static void
fba45db2 692clear_bf_list (void)
c906108c 693{
c5aa993b 694
c906108c 695 SAVED_BF_PTR tmp = saved_bf_list;
c5aa993b
JM
696 SAVED_BF_PTR next = NULL;
697
c906108c
SS
698 while (tmp != NULL)
699 {
700 next = tmp->next;
b8c9b27d 701 xfree (tmp);
c5aa993b 702 tmp = next;
c906108c
SS
703 }
704 saved_bf_list = NULL;
705}
706#endif
707
708int global_remote_debug;
709
710#if 0
711
712static long
fba45db2 713get_bf_for_fcn (long the_function)
c906108c
SS
714{
715 SAVED_BF_PTR tmp;
716 int nprobes = 0;
c5aa993b 717
c906108c 718 /* First use a simple queuing algorithm (i.e. look and see if the
0963b4bd 719 item at the head of the queue is the one you want). */
c5aa993b 720
c906108c 721 if (saved_bf_list == NULL)
8e65ff28 722 internal_error (__FILE__, __LINE__,
e2e0b3e5 723 _("cannot get .bf node off empty list"));
c5aa993b
JM
724
725 if (current_head_bf_list != NULL)
c906108c
SS
726 if (current_head_bf_list->symnum_fcn == the_function)
727 {
c5aa993b 728 if (global_remote_debug)
dac8068e 729 fprintf_unfiltered (gdb_stderr, "*");
c906108c 730
c5aa993b 731 tmp = current_head_bf_list;
c906108c 732 current_head_bf_list = current_head_bf_list->next;
c5aa993b 733 return (tmp->symnum_bf);
c906108c 734 }
c5aa993b 735
c906108c
SS
736 /* If the above did not work (probably because #line directives were
737 used in the sourcefile and they messed up our internal tables) we now do
0963b4bd 738 the ugly linear scan. */
c5aa993b
JM
739
740 if (global_remote_debug)
dac8068e 741 fprintf_unfiltered (gdb_stderr, "\ndefaulting to linear scan\n");
c5aa993b
JM
742
743 nprobes = 0;
c906108c
SS
744 tmp = saved_bf_list;
745 while (tmp != NULL)
746 {
c5aa993b 747 nprobes++;
c906108c 748 if (tmp->symnum_fcn == the_function)
c5aa993b 749 {
c906108c 750 if (global_remote_debug)
dac8068e 751 fprintf_unfiltered (gdb_stderr, "Found in %d probes\n", nprobes);
c906108c 752 current_head_bf_list = tmp->next;
c5aa993b
JM
753 return (tmp->symnum_bf);
754 }
755 tmp = tmp->next;
c906108c 756 }
c5aa993b
JM
757
758 return (-1);
c906108c
SS
759}
760
c5aa993b
JM
761static SAVED_FUNCTION_PTR saved_function_list = NULL;
762static SAVED_FUNCTION_PTR saved_function_list_end = NULL;
c906108c
SS
763
764static void
fba45db2 765clear_function_list (void)
c906108c
SS
766{
767 SAVED_FUNCTION_PTR tmp = saved_function_list;
c5aa993b
JM
768 SAVED_FUNCTION_PTR next = NULL;
769
c906108c
SS
770 while (tmp != NULL)
771 {
772 next = tmp->next;
b8c9b27d 773 xfree (tmp);
c906108c
SS
774 tmp = next;
775 }
c5aa993b 776
c906108c
SS
777 saved_function_list = NULL;
778}
779#endif
This page took 0.807608 seconds and 4 git commands to generate.