* gdbtypes.c (check_typedef): Document that this function can
[platform/upstream/binutils.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, 2008, 2009, 2010, 2011 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 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   LANG_MAGIC
313 };
314
315 static void *
316 build_fortran_types (struct gdbarch *gdbarch)
317 {
318   struct builtin_f_type *builtin_f_type
319     = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct builtin_f_type);
320
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
338   builtin_f_type->builtin_logical_s8
339     = arch_boolean_type (gdbarch, gdbarch_long_long_bit (gdbarch), 1,
340                          "logical*8");
341
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);
369
370   return builtin_f_type;
371 }
372
373 static struct gdbarch_data *f_type_data;
374
375 const struct builtin_f_type *
376 builtin_f_type (struct gdbarch *gdbarch)
377 {
378   return gdbarch_data (gdbarch, f_type_data);
379 }
380
381 void
382 _initialize_f_language (void)
383 {
384   f_type_data = gdbarch_data_register_post_init (build_fortran_types);
385
386   add_language (&f_language_defn);
387 }
388
389 #if 0
390 static SAVED_BF_PTR
391 allocate_saved_bf_node (void)
392 {
393   SAVED_BF_PTR new;
394
395   new = (SAVED_BF_PTR) xmalloc (sizeof (SAVED_BF));
396   return (new);
397 }
398
399 static SAVED_FUNCTION *
400 allocate_saved_function_node (void)
401 {
402   SAVED_FUNCTION *new;
403
404   new = (SAVED_FUNCTION *) xmalloc (sizeof (SAVED_FUNCTION));
405   return (new);
406 }
407
408 static SAVED_F77_COMMON_PTR
409 allocate_saved_f77_common_node (void)
410 {
411   SAVED_F77_COMMON_PTR new;
412
413   new = (SAVED_F77_COMMON_PTR) xmalloc (sizeof (SAVED_F77_COMMON));
414   return (new);
415 }
416
417 static COMMON_ENTRY_PTR
418 allocate_common_entry_node (void)
419 {
420   COMMON_ENTRY_PTR new;
421
422   new = (COMMON_ENTRY_PTR) xmalloc (sizeof (COMMON_ENTRY));
423   return (new);
424 }
425 #endif
426
427 SAVED_F77_COMMON_PTR head_common_list = NULL;   /* Ptr to 1st saved COMMON  */
428 SAVED_F77_COMMON_PTR tail_common_list = NULL;   /* Ptr to last saved COMMON  */
429 SAVED_F77_COMMON_PTR current_common = NULL;     /* Ptr to current COMMON */
430
431 #if 0
432 static SAVED_BF_PTR saved_bf_list = NULL;       /* Ptr to (.bf,function) 
433                                                    list */
434 static SAVED_BF_PTR saved_bf_list_end = NULL;   /* Ptr to above list's end */
435 static SAVED_BF_PTR current_head_bf_list = NULL;    /* Current head of
436                                                        above list.  */
437
438 static SAVED_BF_PTR tmp_bf_ptr; /* Generic temporary for use 
439                                    in macros.  */
440
441 /* The following function simply enters a given common block onto 
442    the global common block chain.  */
443
444 static void
445 add_common_block (char *name, CORE_ADDR offset, int secnum, char *func_stab)
446 {
447   SAVED_F77_COMMON_PTR tmp;
448   char *c, *local_copy_func_stab;
449
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 
453      parser have fits.  */
454
455
456   if (strcmp (name, BLANK_COMMON_NAME_ORIGINAL) == 0
457       || strcmp (name, BLANK_COMMON_NAME_MF77) == 0)
458     {
459
460       xfree (name);
461       name = alloca (strlen (BLANK_COMMON_NAME_LOCAL) + 1);
462       strcpy (name, BLANK_COMMON_NAME_LOCAL);
463     }
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
472   /* local_copy_func_stab is a stabstring, let us first extract the 
473      function name from the stab by NULLing out the ':' character.  */
474
475
476   c = NULL;
477   c = strchr (local_copy_func_stab, ':');
478
479   if (c)
480     *c = '\0';
481   else
482     error (_("Malformed function STAB found in add_common_block()"));
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;
491   tmp->next = NULL;
492   tmp->entries = NULL;
493   tmp->secnum = secnum;
494
495   current_common = tmp;
496
497   if (head_common_list == NULL)
498     {
499       head_common_list = tail_common_list = tmp;
500     }
501   else
502     {
503       tail_common_list->next = tmp;
504       tail_common_list = tmp;
505     }
506 }
507 #endif
508
509 /* The following function simply enters a given common entry onto 
510    the "current_common" block that has been saved away.  */
511
512 #if 0
513 static void
514 add_common_entry (struct symbol *entry_sym_ptr)
515 {
516   COMMON_ENTRY_PTR tmp;
517
518
519
520   /* The order of this list is important, since 
521      we expect the entries to appear in decl.
522      order when we later issue "info common" calls.  */
523
524   tmp = allocate_common_entry_node ();
525
526   tmp->next = NULL;
527   tmp->symbol = entry_sym_ptr;
528
529   if (current_common == NULL)
530     error (_("Attempt to add COMMON entry with no block open!"));
531   else
532     {
533       if (current_common->entries == NULL)
534         {
535           current_common->entries = tmp;
536           current_common->end_of_entries = tmp;
537         }
538       else
539         {
540           current_common->end_of_entries->next = tmp;
541           current_common->end_of_entries = tmp;
542         }
543     }
544 }
545 #endif
546
547 /* This routine finds the first encountred COMMON block named "name".  */
548
549 #if 0
550 static SAVED_F77_COMMON_PTR
551 find_first_common_named (char *name)
552 {
553
554   SAVED_F77_COMMON_PTR tmp;
555
556   tmp = head_common_list;
557
558   while (tmp != NULL)
559     {
560       if (strcmp (tmp->name, name) == 0)
561         return (tmp);
562       else
563         tmp = tmp->next;
564     }
565   return (NULL);
566 }
567 #endif
568
569 /* This routine finds the first encountred COMMON block named "name" 
570    that belongs to function funcname.  */
571
572 SAVED_F77_COMMON_PTR
573 find_common_for_function (char *name, char *funcname)
574 {
575
576   SAVED_F77_COMMON_PTR tmp;
577
578   tmp = head_common_list;
579
580   while (tmp != NULL)
581     {
582       if (strcmp (tmp->name, name) == 0
583           && strcmp (tmp->owning_function, funcname) == 0)
584         return (tmp);
585       else
586         tmp = tmp->next;
587     }
588   return (NULL);
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
596    "name."  */
597
598 static void
599 patch_common_entries (SAVED_F77_COMMON_PTR blk, CORE_ADDR offset, int secnum)
600 {
601   COMMON_ENTRY_PTR entry;
602
603   blk->offset = offset;         /* Keep this around for future use.  */
604
605   entry = blk->entries;
606
607   while (entry != NULL)
608     {
609       SYMBOL_VALUE (entry->symbol) += offset;
610       SYMBOL_SECTION (entry->symbol) = secnum;
611
612       entry = entry->next;
613     }
614   blk->secnum = secnum;
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
621    (which is where common data lives).  */
622
623 static void
624 patch_all_commons_by_name (char *name, CORE_ADDR offset, int secnum)
625 {
626
627   SAVED_F77_COMMON_PTR tmp;
628
629   /* For blank common blocks, change the canonical reprsentation 
630      of a blank name */
631
632   if (strcmp (name, BLANK_COMMON_NAME_ORIGINAL) == 0
633       || strcmp (name, BLANK_COMMON_NAME_MF77) == 0)
634     {
635       xfree (name);
636       name = alloca (strlen (BLANK_COMMON_NAME_LOCAL) + 1);
637       strcpy (name, BLANK_COMMON_NAME_LOCAL);
638     }
639
640   tmp = head_common_list;
641
642   while (tmp != NULL)
643     {
644       if (COMMON_NEEDS_PATCHING (tmp))
645         if (strcmp (tmp->name, name) == 0)
646           patch_common_entries (tmp, offset, secnum);
647
648       tmp = tmp->next;
649     }
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 
659    a linear scan.  */
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                   } \
675 else \
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; \
685                    }
686 #endif
687
688 /* This function frees the entire (.bf,function) list.  */
689
690 #if 0
691 static void
692 clear_bf_list (void)
693 {
694
695   SAVED_BF_PTR tmp = saved_bf_list;
696   SAVED_BF_PTR next = NULL;
697
698   while (tmp != NULL)
699     {
700       next = tmp->next;
701       xfree (tmp);
702       tmp = next;
703     }
704   saved_bf_list = NULL;
705 }
706 #endif
707
708 int global_remote_debug;
709
710 #if 0
711
712 static long
713 get_bf_for_fcn (long the_function)
714 {
715   SAVED_BF_PTR tmp;
716   int nprobes = 0;
717
718   /* First use a simple queuing algorithm (i.e. look and see if the 
719      item at the head of the queue is the one you want).  */
720
721   if (saved_bf_list == NULL)
722     internal_error (__FILE__, __LINE__,
723                     _("cannot get .bf node off empty list"));
724
725   if (current_head_bf_list != NULL)
726     if (current_head_bf_list->symnum_fcn == the_function)
727       {
728         if (global_remote_debug)
729           fprintf_unfiltered (gdb_stderr, "*");
730
731         tmp = current_head_bf_list;
732         current_head_bf_list = current_head_bf_list->next;
733         return (tmp->symnum_bf);
734       }
735
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
738      the ugly linear scan.  */
739
740   if (global_remote_debug)
741     fprintf_unfiltered (gdb_stderr, "\ndefaulting to linear scan\n");
742
743   nprobes = 0;
744   tmp = saved_bf_list;
745   while (tmp != NULL)
746     {
747       nprobes++;
748       if (tmp->symnum_fcn == the_function)
749         {
750           if (global_remote_debug)
751             fprintf_unfiltered (gdb_stderr, "Found in %d probes\n", nprobes);
752           current_head_bf_list = tmp->next;
753           return (tmp->symnum_bf);
754         }
755       tmp = tmp->next;
756     }
757
758   return (-1);
759 }
760
761 static SAVED_FUNCTION_PTR saved_function_list = NULL;
762 static SAVED_FUNCTION_PTR saved_function_list_end = NULL;
763
764 static void
765 clear_function_list (void)
766 {
767   SAVED_FUNCTION_PTR tmp = saved_function_list;
768   SAVED_FUNCTION_PTR next = NULL;
769
770   while (tmp != NULL)
771     {
772       next = tmp->next;
773       xfree (tmp);
774       tmp = next;
775     }
776
777   saved_function_list = NULL;
778 }
779 #endif