]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/f-lang.c
Copyright year update in most files of the GDB Project.
[thirdparty/binutils-gdb.git] / gdb / f-lang.c
1 /* Fortran language support routines for GDB, the GNU debugger.
2
3 Copyright (C) 1993-1996, 1998-2005, 2007-2012 Free Software
4 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 3 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, see <http://www.gnu.org/licenses/>. */
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"
32 #include "valprint.h"
33 #include "value.h"
34 #include "cp-support.h"
35 #include "charset.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
50 directive). */
51 long symnum_bf; /* Symnum of .bf for this function. */
52 struct saved_bf_symnum *next;
53 };
54
55 typedef struct saved_fcn SAVED_FUNCTION, *SAVED_FUNCTION_PTR;
56 typedef struct saved_bf_symnum SAVED_BF, *SAVED_BF_PTR;
57
58 /* Local functions */
59
60 extern void _initialize_f_language (void);
61 #if 0
62 static void clear_function_list (void);
63 static long get_bf_for_fcn (long);
64 static void clear_bf_list (void);
65 static void patch_all_commons_by_name (char *, CORE_ADDR, int);
66 static SAVED_F77_COMMON_PTR find_first_common_named (char *);
67 static void add_common_entry (struct symbol *);
68 static void add_common_block (char *, CORE_ADDR, int, char *);
69 static SAVED_FUNCTION *allocate_saved_function_node (void);
70 static SAVED_BF_PTR allocate_saved_bf_node (void);
71 static COMMON_ENTRY_PTR allocate_common_entry_node (void);
72 static SAVED_F77_COMMON_PTR allocate_saved_f77_common_node (void);
73 static void patch_common_entries (SAVED_F77_COMMON_PTR, CORE_ADDR, int);
74 #endif
75
76 static void f_printchar (int c, struct type *type, struct ui_file * stream);
77 static void f_emit_char (int c, struct type *type,
78 struct ui_file * stream, int quoter);
79
80 /* Return the encoding that should be used for the character type
81 TYPE. */
82
83 static const char *
84 f_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
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
113 static void
114 f_emit_char (int c, struct type *type, struct ui_file *stream, int quoter)
115 {
116 const char *encoding = f_get_encoding (type);
117
118 generic_emit_char (c, type, stream, quoter, encoding);
119 }
120
121 /* Implementation of la_printchar. */
122
123 static void
124 f_printchar (int c, struct type *type, struct ui_file *stream)
125 {
126 fputs_filtered ("'", stream);
127 LA_EMIT_CHAR (c, type, stream, '\'');
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
136 be replaced with a true F77 version. */
137
138 static void
139 f_printstr (struct ui_file *stream, struct type *type, const gdb_byte *string,
140 unsigned int length, const char *encoding, int force_ellipses,
141 const struct value_print_options *options)
142 {
143 const char *type_encoding = f_get_encoding (type);
144
145 if (TYPE_LENGTH (type) == 4)
146 fputs_filtered ("4_", stream);
147
148 if (!encoding || !*encoding)
149 encoding = type_encoding;
150
151 generic_printstr (stream, type, string, length, encoding,
152 force_ellipses, '\'', 0, options);
153 }
154 \f
155
156 /* Table of operators and their precedences for printing expressions. */
157
158 static 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}
181 };
182 \f
183 enum 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,
188 f_primitive_type_logical_s8,
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
198 };
199
200 static void
201 f_language_arch_info (struct gdbarch *gdbarch,
202 struct language_arch_info *lai)
203 {
204 const struct builtin_f_type *builtin = builtin_f_type (gdbarch);
205
206 lai->string_char_type = builtin->builtin_character;
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]
212 = builtin->builtin_character;
213 lai->primitive_type_vector [f_primitive_type_logical]
214 = builtin->builtin_logical;
215 lai->primitive_type_vector [f_primitive_type_logical_s1]
216 = builtin->builtin_logical_s1;
217 lai->primitive_type_vector [f_primitive_type_logical_s2]
218 = builtin->builtin_logical_s2;
219 lai->primitive_type_vector [f_primitive_type_logical_s8]
220 = builtin->builtin_logical_s8;
221 lai->primitive_type_vector [f_primitive_type_real]
222 = builtin->builtin_real;
223 lai->primitive_type_vector [f_primitive_type_real_s8]
224 = builtin->builtin_real_s8;
225 lai->primitive_type_vector [f_primitive_type_real_s16]
226 = builtin->builtin_real_s16;
227 lai->primitive_type_vector [f_primitive_type_complex_s8]
228 = builtin->builtin_complex_s8;
229 lai->primitive_type_vector [f_primitive_type_complex_s16]
230 = builtin->builtin_complex_s16;
231 lai->primitive_type_vector [f_primitive_type_void]
232 = builtin->builtin_void;
233
234 lai->bool_type_symbol = "logical";
235 lai->bool_type_default = builtin->builtin_logical_s2;
236 }
237
238 /* Remove the modules separator :: from the default break list. */
239
240 static char *
241 f_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
262 /* Consider the modules separator :: as a valid symbol name character
263 class. */
264
265 static char **
266 f_make_symbol_completion_list (char *text, char *word)
267 {
268 return default_make_symbol_completion_list_break_on (text, word, ":");
269 }
270
271 /* This is declared in c-lang.h but it is silly to import that file for what
272 is already just a hack. */
273 extern int c_value_print (struct value *, struct ui_file *,
274 const struct value_print_options *);
275
276 const struct language_defn f_language_defn =
277 {
278 "fortran",
279 language_fortran,
280 range_check_on,
281 type_check_on,
282 case_sensitive_off,
283 array_column_major,
284 macro_expansion_no,
285 &exp_descriptor_standard,
286 f_parse, /* parser */
287 f_error, /* parser error function */
288 null_post_parser,
289 f_printchar, /* Print character constant */
290 f_printstr, /* function to print string constant */
291 f_emit_char, /* Function to print a single character */
292 f_print_type, /* Print a type using appropriate syntax */
293 default_print_typedef, /* Print a typedef using appropriate syntax */
294 f_val_print, /* Print a value using appropriate syntax */
295 c_value_print, /* FIXME */
296 NULL, /* Language specific skip_trampoline */
297 NULL, /* name_of_this */
298 cp_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
299 basic_lookup_transparent_type,/* lookup_transparent_type */
300 NULL, /* Language specific symbol demangler */
301 NULL, /* Language specific
302 class_name_from_physname */
303 f_op_print_tab, /* expression operators for printing */
304 0, /* arrays are first-class (not c-style) */
305 1, /* String lower bound */
306 f_word_break_characters,
307 f_make_symbol_completion_list,
308 f_language_arch_info,
309 default_print_array_index,
310 default_pass_by_reference,
311 default_get_string,
312 strcmp_iw_ordered,
313 iterate_over_symbols,
314 LANG_MAGIC
315 };
316
317 static void *
318 build_fortran_types (struct gdbarch *gdbarch)
319 {
320 struct builtin_f_type *builtin_f_type
321 = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct builtin_f_type);
322
323 builtin_f_type->builtin_void
324 = arch_type (gdbarch, TYPE_CODE_VOID, 1, "VOID");
325
326 builtin_f_type->builtin_character
327 = arch_integer_type (gdbarch, TARGET_CHAR_BIT, 0, "character");
328
329 builtin_f_type->builtin_logical_s1
330 = arch_boolean_type (gdbarch, TARGET_CHAR_BIT, 1, "logical*1");
331
332 builtin_f_type->builtin_integer_s2
333 = arch_integer_type (gdbarch, gdbarch_short_bit (gdbarch), 0,
334 "integer*2");
335
336 builtin_f_type->builtin_logical_s2
337 = arch_boolean_type (gdbarch, gdbarch_short_bit (gdbarch), 1,
338 "logical*2");
339
340 builtin_f_type->builtin_logical_s8
341 = arch_boolean_type (gdbarch, gdbarch_long_long_bit (gdbarch), 1,
342 "logical*8");
343
344 builtin_f_type->builtin_integer
345 = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch), 0,
346 "integer");
347
348 builtin_f_type->builtin_logical
349 = arch_boolean_type (gdbarch, gdbarch_int_bit (gdbarch), 1,
350 "logical*4");
351
352 builtin_f_type->builtin_real
353 = arch_float_type (gdbarch, gdbarch_float_bit (gdbarch),
354 "real", NULL);
355 builtin_f_type->builtin_real_s8
356 = arch_float_type (gdbarch, gdbarch_double_bit (gdbarch),
357 "real*8", NULL);
358 builtin_f_type->builtin_real_s16
359 = arch_float_type (gdbarch, gdbarch_long_double_bit (gdbarch),
360 "real*16", NULL);
361
362 builtin_f_type->builtin_complex_s8
363 = arch_complex_type (gdbarch, "complex*8",
364 builtin_f_type->builtin_real);
365 builtin_f_type->builtin_complex_s16
366 = arch_complex_type (gdbarch, "complex*16",
367 builtin_f_type->builtin_real_s8);
368 builtin_f_type->builtin_complex_s32
369 = arch_complex_type (gdbarch, "complex*32",
370 builtin_f_type->builtin_real_s16);
371
372 return builtin_f_type;
373 }
374
375 static struct gdbarch_data *f_type_data;
376
377 const struct builtin_f_type *
378 builtin_f_type (struct gdbarch *gdbarch)
379 {
380 return gdbarch_data (gdbarch, f_type_data);
381 }
382
383 void
384 _initialize_f_language (void)
385 {
386 f_type_data = gdbarch_data_register_post_init (build_fortran_types);
387
388 add_language (&f_language_defn);
389 }
390
391 #if 0
392 static SAVED_BF_PTR
393 allocate_saved_bf_node (void)
394 {
395 SAVED_BF_PTR new;
396
397 new = (SAVED_BF_PTR) xmalloc (sizeof (SAVED_BF));
398 return (new);
399 }
400
401 static SAVED_FUNCTION *
402 allocate_saved_function_node (void)
403 {
404 SAVED_FUNCTION *new;
405
406 new = (SAVED_FUNCTION *) xmalloc (sizeof (SAVED_FUNCTION));
407 return (new);
408 }
409
410 static SAVED_F77_COMMON_PTR
411 allocate_saved_f77_common_node (void)
412 {
413 SAVED_F77_COMMON_PTR new;
414
415 new = (SAVED_F77_COMMON_PTR) xmalloc (sizeof (SAVED_F77_COMMON));
416 return (new);
417 }
418
419 static COMMON_ENTRY_PTR
420 allocate_common_entry_node (void)
421 {
422 COMMON_ENTRY_PTR new;
423
424 new = (COMMON_ENTRY_PTR) xmalloc (sizeof (COMMON_ENTRY));
425 return (new);
426 }
427 #endif
428
429 SAVED_F77_COMMON_PTR head_common_list = NULL; /* Ptr to 1st saved COMMON */
430 SAVED_F77_COMMON_PTR tail_common_list = NULL; /* Ptr to last saved COMMON */
431 SAVED_F77_COMMON_PTR current_common = NULL; /* Ptr to current COMMON */
432
433 #if 0
434 static SAVED_BF_PTR saved_bf_list = NULL; /* Ptr to (.bf,function)
435 list */
436 static SAVED_BF_PTR saved_bf_list_end = NULL; /* Ptr to above list's end */
437 static SAVED_BF_PTR current_head_bf_list = NULL; /* Current head of
438 above list. */
439
440 static SAVED_BF_PTR tmp_bf_ptr; /* Generic temporary for use
441 in macros. */
442
443 /* The following function simply enters a given common block onto
444 the global common block chain. */
445
446 static void
447 add_common_block (char *name, CORE_ADDR offset, int secnum, char *func_stab)
448 {
449 SAVED_F77_COMMON_PTR tmp;
450 char *c, *local_copy_func_stab;
451
452 /* If the COMMON block we are trying to add has a blank
453 name (i.e. "#BLNK_COM") then we set it to __BLANK
454 because the darn "#" character makes GDB's input
455 parser have fits. */
456
457
458 if (strcmp (name, BLANK_COMMON_NAME_ORIGINAL) == 0
459 || strcmp (name, BLANK_COMMON_NAME_MF77) == 0)
460 {
461
462 xfree (name);
463 name = alloca (strlen (BLANK_COMMON_NAME_LOCAL) + 1);
464 strcpy (name, BLANK_COMMON_NAME_LOCAL);
465 }
466
467 tmp = allocate_saved_f77_common_node ();
468
469 local_copy_func_stab = xmalloc (strlen (func_stab) + 1);
470 strcpy (local_copy_func_stab, func_stab);
471
472 tmp->name = xmalloc (strlen (name) + 1);
473
474 /* local_copy_func_stab is a stabstring, let us first extract the
475 function name from the stab by NULLing out the ':' character. */
476
477
478 c = NULL;
479 c = strchr (local_copy_func_stab, ':');
480
481 if (c)
482 *c = '\0';
483 else
484 error (_("Malformed function STAB found in add_common_block()"));
485
486
487 tmp->owning_function = xmalloc (strlen (local_copy_func_stab) + 1);
488
489 strcpy (tmp->owning_function, local_copy_func_stab);
490
491 strcpy (tmp->name, name);
492 tmp->offset = offset;
493 tmp->next = NULL;
494 tmp->entries = NULL;
495 tmp->secnum = secnum;
496
497 current_common = tmp;
498
499 if (head_common_list == NULL)
500 {
501 head_common_list = tail_common_list = tmp;
502 }
503 else
504 {
505 tail_common_list->next = tmp;
506 tail_common_list = tmp;
507 }
508 }
509 #endif
510
511 /* The following function simply enters a given common entry onto
512 the "current_common" block that has been saved away. */
513
514 #if 0
515 static void
516 add_common_entry (struct symbol *entry_sym_ptr)
517 {
518 COMMON_ENTRY_PTR tmp;
519
520
521
522 /* The order of this list is important, since
523 we expect the entries to appear in decl.
524 order when we later issue "info common" calls. */
525
526 tmp = allocate_common_entry_node ();
527
528 tmp->next = NULL;
529 tmp->symbol = entry_sym_ptr;
530
531 if (current_common == NULL)
532 error (_("Attempt to add COMMON entry with no block open!"));
533 else
534 {
535 if (current_common->entries == NULL)
536 {
537 current_common->entries = tmp;
538 current_common->end_of_entries = tmp;
539 }
540 else
541 {
542 current_common->end_of_entries->next = tmp;
543 current_common->end_of_entries = tmp;
544 }
545 }
546 }
547 #endif
548
549 /* This routine finds the first encountred COMMON block named "name". */
550
551 #if 0
552 static SAVED_F77_COMMON_PTR
553 find_first_common_named (char *name)
554 {
555
556 SAVED_F77_COMMON_PTR tmp;
557
558 tmp = head_common_list;
559
560 while (tmp != NULL)
561 {
562 if (strcmp (tmp->name, name) == 0)
563 return (tmp);
564 else
565 tmp = tmp->next;
566 }
567 return (NULL);
568 }
569 #endif
570
571 /* This routine finds the first encountred COMMON block named "name"
572 that belongs to function funcname. */
573
574 SAVED_F77_COMMON_PTR
575 find_common_for_function (char *name, char *funcname)
576 {
577
578 SAVED_F77_COMMON_PTR tmp;
579
580 tmp = head_common_list;
581
582 while (tmp != NULL)
583 {
584 if (strcmp (tmp->name, name) == 0
585 && strcmp (tmp->owning_function, funcname) == 0)
586 return (tmp);
587 else
588 tmp = tmp->next;
589 }
590 return (NULL);
591 }
592
593
594 #if 0
595
596 /* The following function is called to patch up the offsets
597 for the statics contained in the COMMON block named
598 "name." */
599
600 static void
601 patch_common_entries (SAVED_F77_COMMON_PTR blk, CORE_ADDR offset, int secnum)
602 {
603 COMMON_ENTRY_PTR entry;
604
605 blk->offset = offset; /* Keep this around for future use. */
606
607 entry = blk->entries;
608
609 while (entry != NULL)
610 {
611 SYMBOL_VALUE (entry->symbol) += offset;
612 SYMBOL_SECTION (entry->symbol) = secnum;
613
614 entry = entry->next;
615 }
616 blk->secnum = secnum;
617 }
618
619 /* Patch all commons named "name" that need patching.Since COMMON
620 blocks occur with relative infrequency, we simply do a linear scan on
621 the name. Eventually, the best way to do this will be a
622 hashed-lookup. Secnum is the section number for the .bss section
623 (which is where common data lives). */
624
625 static void
626 patch_all_commons_by_name (char *name, CORE_ADDR offset, int secnum)
627 {
628
629 SAVED_F77_COMMON_PTR tmp;
630
631 /* For blank common blocks, change the canonical reprsentation
632 of a blank name */
633
634 if (strcmp (name, BLANK_COMMON_NAME_ORIGINAL) == 0
635 || strcmp (name, BLANK_COMMON_NAME_MF77) == 0)
636 {
637 xfree (name);
638 name = alloca (strlen (BLANK_COMMON_NAME_LOCAL) + 1);
639 strcpy (name, BLANK_COMMON_NAME_LOCAL);
640 }
641
642 tmp = head_common_list;
643
644 while (tmp != NULL)
645 {
646 if (COMMON_NEEDS_PATCHING (tmp))
647 if (strcmp (tmp->name, name) == 0)
648 patch_common_entries (tmp, offset, secnum);
649
650 tmp = tmp->next;
651 }
652 }
653 #endif
654
655 /* This macro adds the symbol-number for the start of the function
656 (the symbol number of the .bf) referenced by symnum_fcn to a
657 list. This list, in reality should be a FIFO queue but since
658 #line pragmas sometimes cause line ranges to get messed up
659 we simply create a linear list. This list can then be searched
660 first by a queueing algorithm and upon failure fall back to
661 a linear scan. */
662
663 #if 0
664 #define ADD_BF_SYMNUM(bf_sym,fcn_sym) \
665 \
666 if (saved_bf_list == NULL) \
667 { \
668 tmp_bf_ptr = allocate_saved_bf_node(); \
669 \
670 tmp_bf_ptr->symnum_bf = (bf_sym); \
671 tmp_bf_ptr->symnum_fcn = (fcn_sym); \
672 tmp_bf_ptr->next = NULL; \
673 \
674 current_head_bf_list = saved_bf_list = tmp_bf_ptr; \
675 saved_bf_list_end = tmp_bf_ptr; \
676 } \
677 else \
678 { \
679 tmp_bf_ptr = allocate_saved_bf_node(); \
680 \
681 tmp_bf_ptr->symnum_bf = (bf_sym); \
682 tmp_bf_ptr->symnum_fcn = (fcn_sym); \
683 tmp_bf_ptr->next = NULL; \
684 \
685 saved_bf_list_end->next = tmp_bf_ptr; \
686 saved_bf_list_end = tmp_bf_ptr; \
687 }
688 #endif
689
690 /* This function frees the entire (.bf,function) list. */
691
692 #if 0
693 static void
694 clear_bf_list (void)
695 {
696
697 SAVED_BF_PTR tmp = saved_bf_list;
698 SAVED_BF_PTR next = NULL;
699
700 while (tmp != NULL)
701 {
702 next = tmp->next;
703 xfree (tmp);
704 tmp = next;
705 }
706 saved_bf_list = NULL;
707 }
708 #endif
709
710 int global_remote_debug;
711
712 #if 0
713
714 static long
715 get_bf_for_fcn (long the_function)
716 {
717 SAVED_BF_PTR tmp;
718 int nprobes = 0;
719
720 /* First use a simple queuing algorithm (i.e. look and see if the
721 item at the head of the queue is the one you want). */
722
723 if (saved_bf_list == NULL)
724 internal_error (__FILE__, __LINE__,
725 _("cannot get .bf node off empty list"));
726
727 if (current_head_bf_list != NULL)
728 if (current_head_bf_list->symnum_fcn == the_function)
729 {
730 if (global_remote_debug)
731 fprintf_unfiltered (gdb_stderr, "*");
732
733 tmp = current_head_bf_list;
734 current_head_bf_list = current_head_bf_list->next;
735 return (tmp->symnum_bf);
736 }
737
738 /* If the above did not work (probably because #line directives were
739 used in the sourcefile and they messed up our internal tables) we now do
740 the ugly linear scan. */
741
742 if (global_remote_debug)
743 fprintf_unfiltered (gdb_stderr, "\ndefaulting to linear scan\n");
744
745 nprobes = 0;
746 tmp = saved_bf_list;
747 while (tmp != NULL)
748 {
749 nprobes++;
750 if (tmp->symnum_fcn == the_function)
751 {
752 if (global_remote_debug)
753 fprintf_unfiltered (gdb_stderr, "Found in %d probes\n", nprobes);
754 current_head_bf_list = tmp->next;
755 return (tmp->symnum_bf);
756 }
757 tmp = tmp->next;
758 }
759
760 return (-1);
761 }
762
763 static SAVED_FUNCTION_PTR saved_function_list = NULL;
764 static SAVED_FUNCTION_PTR saved_function_list_end = NULL;
765
766 static void
767 clear_function_list (void)
768 {
769 SAVED_FUNCTION_PTR tmp = saved_function_list;
770 SAVED_FUNCTION_PTR next = NULL;
771
772 while (tmp != NULL)
773 {
774 next = tmp->next;
775 xfree (tmp);
776 tmp = next;
777 }
778
779 saved_function_list = NULL;
780 }
781 #endif