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