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