Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Fortran language support routines for GDB, the GNU debugger. |
ce27fb25 | 2 | |
0b302171 JB |
3 | Copyright (C) 1993-1996, 1998-2005, 2007-2012 Free Software |
4 | 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 | |
40 | struct 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 |
47 | struct 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 |
55 | typedef struct saved_fcn SAVED_FUNCTION, *SAVED_FUNCTION_PTR; |
56 | typedef struct saved_bf_symnum SAVED_BF, *SAVED_BF_PTR; | |
c906108c SS |
57 | |
58 | /* Local functions */ | |
59 | ||
a14ed312 | 60 | extern void _initialize_f_language (void); |
c906108c | 61 | #if 0 |
a14ed312 KB |
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); | |
c906108c SS |
74 | #endif |
75 | ||
6c7a06a3 TT |
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); | |
c906108c | 79 | |
3b2b8fea TT |
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 | ||
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 | ||
113 | static void | |
6c7a06a3 | 114 | f_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 | |
123 | static void | |
6c7a06a3 | 124 | f_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 | |
138 | static void | |
6c7a06a3 | 139 | f_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 |
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} | |
c906108c SS |
181 | }; |
182 | \f | |
cad351d1 UW |
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, | |
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 |
200 | static void |
201 | f_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 | ||
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 | ||
3e43a32a MS |
262 | /* Consider the modules separator :: as a valid symbol name character |
263 | class. */ | |
f55ee35c JK |
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 | ||
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 |
273 | extern int c_value_print (struct value *, struct ui_file *, |
274 | const struct value_print_options *); | |
c906108c | 275 | |
c5aa993b JM |
276 | const 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, |
f8eba3c6 TT |
312 | strcmp_iw_ordered, |
313 | iterate_over_symbols, | |
c906108c | 314 | LANG_MAGIC |
c5aa993b | 315 | }; |
c906108c | 316 | |
54ef06c7 UW |
317 | static void * |
318 | build_fortran_types (struct gdbarch *gdbarch) | |
c906108c | 319 | { |
54ef06c7 UW |
320 | struct builtin_f_type *builtin_f_type |
321 | = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct builtin_f_type); | |
322 | ||
e9bb382b UW |
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 | ||
ce4b0682 SDJ |
340 | builtin_f_type->builtin_logical_s8 |
341 | = arch_boolean_type (gdbarch, gdbarch_long_long_bit (gdbarch), 1, | |
342 | "logical*8"); | |
343 | ||
e9bb382b UW |
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); | |
54ef06c7 UW |
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); | |
4e845cd3 MS |
381 | } |
382 | ||
383 | void | |
384 | _initialize_f_language (void) | |
385 | { | |
54ef06c7 | 386 | f_type_data = gdbarch_data_register_post_init (build_fortran_types); |
c906108c | 387 | |
c906108c SS |
388 | add_language (&f_language_defn); |
389 | } | |
390 | ||
391 | #if 0 | |
392 | static SAVED_BF_PTR | |
fba45db2 | 393 | allocate_saved_bf_node (void) |
c906108c SS |
394 | { |
395 | SAVED_BF_PTR new; | |
c5aa993b | 396 | |
c906108c | 397 | new = (SAVED_BF_PTR) xmalloc (sizeof (SAVED_BF)); |
c5aa993b | 398 | return (new); |
c906108c SS |
399 | } |
400 | ||
401 | static SAVED_FUNCTION * | |
fba45db2 | 402 | allocate_saved_function_node (void) |
c906108c SS |
403 | { |
404 | SAVED_FUNCTION *new; | |
c5aa993b | 405 | |
c906108c | 406 | new = (SAVED_FUNCTION *) xmalloc (sizeof (SAVED_FUNCTION)); |
c5aa993b | 407 | return (new); |
c906108c SS |
408 | } |
409 | ||
c5aa993b | 410 | static SAVED_F77_COMMON_PTR |
fba45db2 | 411 | allocate_saved_f77_common_node (void) |
c906108c SS |
412 | { |
413 | SAVED_F77_COMMON_PTR new; | |
c5aa993b | 414 | |
c906108c | 415 | new = (SAVED_F77_COMMON_PTR) xmalloc (sizeof (SAVED_F77_COMMON)); |
c5aa993b | 416 | return (new); |
c906108c SS |
417 | } |
418 | ||
c5aa993b | 419 | static COMMON_ENTRY_PTR |
fba45db2 | 420 | allocate_common_entry_node (void) |
c906108c SS |
421 | { |
422 | COMMON_ENTRY_PTR new; | |
c5aa993b | 423 | |
c906108c | 424 | new = (COMMON_ENTRY_PTR) xmalloc (sizeof (COMMON_ENTRY)); |
c5aa993b | 425 | return (new); |
c906108c SS |
426 | } |
427 | #endif | |
428 | ||
c5aa993b JM |
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 */ | |
c906108c SS |
432 | |
433 | #if 0 | |
c5aa993b JM |
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 */ | |
3e43a32a MS |
437 | static SAVED_BF_PTR current_head_bf_list = NULL; /* Current head of |
438 | above list. */ | |
c906108c | 439 | |
c5aa993b | 440 | static SAVED_BF_PTR tmp_bf_ptr; /* Generic temporary for use |
0963b4bd | 441 | in macros. */ |
c906108c SS |
442 | |
443 | /* The following function simply enters a given common block onto | |
0963b4bd | 444 | the global common block chain. */ |
c906108c SS |
445 | |
446 | static void | |
fba45db2 | 447 | add_common_block (char *name, CORE_ADDR offset, int secnum, char *func_stab) |
c906108c SS |
448 | { |
449 | SAVED_F77_COMMON_PTR tmp; | |
c5aa993b JM |
450 | char *c, *local_copy_func_stab; |
451 | ||
c906108c SS |
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 | |
0963b4bd | 455 | parser have fits. */ |
c5aa993b JM |
456 | |
457 | ||
6314a349 AC |
458 | if (strcmp (name, BLANK_COMMON_NAME_ORIGINAL) == 0 |
459 | || strcmp (name, BLANK_COMMON_NAME_MF77) == 0) | |
c906108c | 460 | { |
c5aa993b | 461 | |
b8c9b27d | 462 | xfree (name); |
c5aa993b JM |
463 | name = alloca (strlen (BLANK_COMMON_NAME_LOCAL) + 1); |
464 | strcpy (name, BLANK_COMMON_NAME_LOCAL); | |
c906108c | 465 | } |
c5aa993b JM |
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 | ||
c906108c | 474 | /* local_copy_func_stab is a stabstring, let us first extract the |
0963b4bd | 475 | function name from the stab by NULLing out the ':' character. */ |
c5aa993b JM |
476 | |
477 | ||
478 | c = NULL; | |
479 | c = strchr (local_copy_func_stab, ':'); | |
480 | ||
c906108c SS |
481 | if (c) |
482 | *c = '\0'; | |
483 | else | |
8a3fe4f8 | 484 | error (_("Malformed function STAB found in add_common_block()")); |
c5aa993b JM |
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; | |
c906108c SS |
493 | tmp->next = NULL; |
494 | tmp->entries = NULL; | |
c5aa993b JM |
495 | tmp->secnum = secnum; |
496 | ||
c906108c | 497 | current_common = tmp; |
c5aa993b | 498 | |
c906108c SS |
499 | if (head_common_list == NULL) |
500 | { | |
501 | head_common_list = tail_common_list = tmp; | |
502 | } | |
503 | else | |
504 | { | |
c5aa993b | 505 | tail_common_list->next = tmp; |
c906108c SS |
506 | tail_common_list = tmp; |
507 | } | |
508 | } | |
509 | #endif | |
510 | ||
511 | /* The following function simply enters a given common entry onto | |
0963b4bd | 512 | the "current_common" block that has been saved away. */ |
c906108c SS |
513 | |
514 | #if 0 | |
515 | static void | |
fba45db2 | 516 | add_common_entry (struct symbol *entry_sym_ptr) |
c906108c SS |
517 | { |
518 | COMMON_ENTRY_PTR tmp; | |
c5aa993b JM |
519 | |
520 | ||
521 | ||
c906108c SS |
522 | /* The order of this list is important, since |
523 | we expect the entries to appear in decl. | |
0963b4bd | 524 | order when we later issue "info common" calls. */ |
c5aa993b JM |
525 | |
526 | tmp = allocate_common_entry_node (); | |
527 | ||
c906108c SS |
528 | tmp->next = NULL; |
529 | tmp->symbol = entry_sym_ptr; | |
c5aa993b | 530 | |
c906108c | 531 | if (current_common == NULL) |
8a3fe4f8 | 532 | error (_("Attempt to add COMMON entry with no block open!")); |
c5aa993b | 533 | else |
c906108c SS |
534 | { |
535 | if (current_common->entries == NULL) | |
536 | { | |
537 | current_common->entries = tmp; | |
c5aa993b | 538 | current_common->end_of_entries = tmp; |
c906108c SS |
539 | } |
540 | else | |
541 | { | |
c5aa993b JM |
542 | current_common->end_of_entries->next = tmp; |
543 | current_common->end_of_entries = tmp; | |
c906108c SS |
544 | } |
545 | } | |
546 | } | |
547 | #endif | |
548 | ||
0963b4bd | 549 | /* This routine finds the first encountred COMMON block named "name". */ |
c906108c SS |
550 | |
551 | #if 0 | |
552 | static SAVED_F77_COMMON_PTR | |
fba45db2 | 553 | find_first_common_named (char *name) |
c906108c | 554 | { |
c5aa993b | 555 | |
c906108c | 556 | SAVED_F77_COMMON_PTR tmp; |
c5aa993b | 557 | |
c906108c | 558 | tmp = head_common_list; |
c5aa993b | 559 | |
c906108c SS |
560 | while (tmp != NULL) |
561 | { | |
6314a349 | 562 | if (strcmp (tmp->name, name) == 0) |
c5aa993b | 563 | return (tmp); |
c906108c SS |
564 | else |
565 | tmp = tmp->next; | |
566 | } | |
c5aa993b | 567 | return (NULL); |
c906108c SS |
568 | } |
569 | #endif | |
570 | ||
571 | /* This routine finds the first encountred COMMON block named "name" | |
0963b4bd | 572 | that belongs to function funcname. */ |
c906108c | 573 | |
c5aa993b | 574 | SAVED_F77_COMMON_PTR |
fba45db2 | 575 | find_common_for_function (char *name, char *funcname) |
c906108c | 576 | { |
c5aa993b | 577 | |
c906108c | 578 | SAVED_F77_COMMON_PTR tmp; |
c5aa993b | 579 | |
c906108c | 580 | tmp = head_common_list; |
c5aa993b | 581 | |
c906108c SS |
582 | while (tmp != NULL) |
583 | { | |
7ecb6532 MD |
584 | if (strcmp (tmp->name, name) == 0 |
585 | && strcmp (tmp->owning_function, funcname) == 0) | |
c5aa993b | 586 | return (tmp); |
c906108c SS |
587 | else |
588 | tmp = tmp->next; | |
589 | } | |
c5aa993b | 590 | return (NULL); |
c906108c SS |
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 | |
c5aa993b | 598 | "name." */ |
c906108c SS |
599 | |
600 | static void | |
fba45db2 | 601 | patch_common_entries (SAVED_F77_COMMON_PTR blk, CORE_ADDR offset, int secnum) |
c906108c SS |
602 | { |
603 | COMMON_ENTRY_PTR entry; | |
c5aa993b | 604 | |
0963b4bd | 605 | blk->offset = offset; /* Keep this around for future use. */ |
c5aa993b | 606 | |
c906108c | 607 | entry = blk->entries; |
c5aa993b | 608 | |
c906108c SS |
609 | while (entry != NULL) |
610 | { | |
c5aa993b | 611 | SYMBOL_VALUE (entry->symbol) += offset; |
c906108c | 612 | SYMBOL_SECTION (entry->symbol) = secnum; |
c5aa993b | 613 | |
c906108c SS |
614 | entry = entry->next; |
615 | } | |
c5aa993b | 616 | blk->secnum = secnum; |
c906108c SS |
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 | |
0963b4bd | 623 | (which is where common data lives). */ |
c906108c SS |
624 | |
625 | static void | |
fba45db2 | 626 | patch_all_commons_by_name (char *name, CORE_ADDR offset, int secnum) |
c906108c | 627 | { |
c5aa993b | 628 | |
c906108c | 629 | SAVED_F77_COMMON_PTR tmp; |
c5aa993b | 630 | |
c906108c SS |
631 | /* For blank common blocks, change the canonical reprsentation |
632 | of a blank name */ | |
c5aa993b | 633 | |
6314a349 AC |
634 | if (strcmp (name, BLANK_COMMON_NAME_ORIGINAL) == 0 |
635 | || strcmp (name, BLANK_COMMON_NAME_MF77) == 0) | |
c906108c | 636 | { |
b8c9b27d | 637 | xfree (name); |
c5aa993b JM |
638 | name = alloca (strlen (BLANK_COMMON_NAME_LOCAL) + 1); |
639 | strcpy (name, BLANK_COMMON_NAME_LOCAL); | |
c906108c | 640 | } |
c5aa993b | 641 | |
c906108c | 642 | tmp = head_common_list; |
c5aa993b | 643 | |
c906108c SS |
644 | while (tmp != NULL) |
645 | { | |
c5aa993b | 646 | if (COMMON_NEEDS_PATCHING (tmp)) |
6314a349 | 647 | if (strcmp (tmp->name, name) == 0) |
c5aa993b JM |
648 | patch_common_entries (tmp, offset, secnum); |
649 | ||
c906108c | 650 | tmp = tmp->next; |
c5aa993b | 651 | } |
c906108c SS |
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 | |
0963b4bd | 661 | a linear scan. */ |
c906108c SS |
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; \ | |
c5aa993b | 687 | } |
c906108c SS |
688 | #endif |
689 | ||
0963b4bd | 690 | /* This function frees the entire (.bf,function) list. */ |
c906108c SS |
691 | |
692 | #if 0 | |
c5aa993b | 693 | static void |
fba45db2 | 694 | clear_bf_list (void) |
c906108c | 695 | { |
c5aa993b | 696 | |
c906108c | 697 | SAVED_BF_PTR tmp = saved_bf_list; |
c5aa993b JM |
698 | SAVED_BF_PTR next = NULL; |
699 | ||
c906108c SS |
700 | while (tmp != NULL) |
701 | { | |
702 | next = tmp->next; | |
b8c9b27d | 703 | xfree (tmp); |
c5aa993b | 704 | tmp = next; |
c906108c SS |
705 | } |
706 | saved_bf_list = NULL; | |
707 | } | |
708 | #endif | |
709 | ||
710 | int global_remote_debug; | |
711 | ||
712 | #if 0 | |
713 | ||
714 | static long | |
fba45db2 | 715 | get_bf_for_fcn (long the_function) |
c906108c SS |
716 | { |
717 | SAVED_BF_PTR tmp; | |
718 | int nprobes = 0; | |
c5aa993b | 719 | |
c906108c | 720 | /* First use a simple queuing algorithm (i.e. look and see if the |
0963b4bd | 721 | item at the head of the queue is the one you want). */ |
c5aa993b | 722 | |
c906108c | 723 | if (saved_bf_list == NULL) |
8e65ff28 | 724 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 725 | _("cannot get .bf node off empty list")); |
c5aa993b JM |
726 | |
727 | if (current_head_bf_list != NULL) | |
c906108c SS |
728 | if (current_head_bf_list->symnum_fcn == the_function) |
729 | { | |
c5aa993b | 730 | if (global_remote_debug) |
dac8068e | 731 | fprintf_unfiltered (gdb_stderr, "*"); |
c906108c | 732 | |
c5aa993b | 733 | tmp = current_head_bf_list; |
c906108c | 734 | current_head_bf_list = current_head_bf_list->next; |
c5aa993b | 735 | return (tmp->symnum_bf); |
c906108c | 736 | } |
c5aa993b | 737 | |
c906108c SS |
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 | |
0963b4bd | 740 | the ugly linear scan. */ |
c5aa993b JM |
741 | |
742 | if (global_remote_debug) | |
dac8068e | 743 | fprintf_unfiltered (gdb_stderr, "\ndefaulting to linear scan\n"); |
c5aa993b JM |
744 | |
745 | nprobes = 0; | |
c906108c SS |
746 | tmp = saved_bf_list; |
747 | while (tmp != NULL) | |
748 | { | |
c5aa993b | 749 | nprobes++; |
c906108c | 750 | if (tmp->symnum_fcn == the_function) |
c5aa993b | 751 | { |
c906108c | 752 | if (global_remote_debug) |
dac8068e | 753 | fprintf_unfiltered (gdb_stderr, "Found in %d probes\n", nprobes); |
c906108c | 754 | current_head_bf_list = tmp->next; |
c5aa993b JM |
755 | return (tmp->symnum_bf); |
756 | } | |
757 | tmp = tmp->next; | |
c906108c | 758 | } |
c5aa993b JM |
759 | |
760 | return (-1); | |
c906108c SS |
761 | } |
762 | ||
c5aa993b JM |
763 | static SAVED_FUNCTION_PTR saved_function_list = NULL; |
764 | static SAVED_FUNCTION_PTR saved_function_list_end = NULL; | |
c906108c SS |
765 | |
766 | static void | |
fba45db2 | 767 | clear_function_list (void) |
c906108c SS |
768 | { |
769 | SAVED_FUNCTION_PTR tmp = saved_function_list; | |
c5aa993b JM |
770 | SAVED_FUNCTION_PTR next = NULL; |
771 | ||
c906108c SS |
772 | while (tmp != NULL) |
773 | { | |
774 | next = tmp->next; | |
b8c9b27d | 775 | xfree (tmp); |
c906108c SS |
776 | tmp = next; |
777 | } | |
c5aa993b | 778 | |
c906108c SS |
779 | saved_function_list = NULL; |
780 | } | |
781 | #endif |