Commit | Line | Data |
---|---|---|
14f9c5c9 AS |
1 | /* Ada language support routines for GDB, the GNU debugger. Copyright |
2 | 1992, 1993, 1994, 1997, 1998, 1999, 2000 Free Software Foundation, Inc. | |
3 | ||
4 | This file is part of GDB. | |
5 | ||
6 | This program is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 2 of the License, or | |
9 | (at your option) any later version. | |
10 | ||
11 | This program is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with this program; if not, write to the Free Software | |
18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
19 | ||
20 | #include <stdio.h> | |
0c30c098 | 21 | #include "gdb_string.h" |
14f9c5c9 AS |
22 | #include <ctype.h> |
23 | #include <stdarg.h> | |
24 | #include "demangle.h" | |
25 | #include "defs.h" | |
26 | #include "symtab.h" | |
27 | #include "gdbtypes.h" | |
28 | #include "gdbcmd.h" | |
29 | #include "expression.h" | |
30 | #include "parser-defs.h" | |
31 | #include "language.h" | |
32 | #include "c-lang.h" | |
33 | #include "inferior.h" | |
34 | #include "symfile.h" | |
35 | #include "objfiles.h" | |
36 | #include "breakpoint.h" | |
37 | #include "gdbcore.h" | |
38 | #include "ada-lang.h" | |
39 | #ifdef UI_OUT | |
40 | #include "ui-out.h" | |
41 | #endif | |
42 | ||
d2e4a39e | 43 | struct cleanup *unresolved_names; |
14f9c5c9 AS |
44 | |
45 | void extract_string (CORE_ADDR addr, char *buf); | |
46 | ||
d2e4a39e | 47 | static struct type *ada_create_fundamental_type (struct objfile *, int); |
14f9c5c9 AS |
48 | |
49 | static void modify_general_field (char *, LONGEST, int, int); | |
50 | ||
d2e4a39e | 51 | static struct type *desc_base_type (struct type *); |
14f9c5c9 | 52 | |
d2e4a39e | 53 | static struct type *desc_bounds_type (struct type *); |
14f9c5c9 | 54 | |
d2e4a39e | 55 | static struct value *desc_bounds (struct value *); |
14f9c5c9 | 56 | |
d2e4a39e | 57 | static int fat_pntr_bounds_bitpos (struct type *); |
14f9c5c9 | 58 | |
d2e4a39e | 59 | static int fat_pntr_bounds_bitsize (struct type *); |
14f9c5c9 | 60 | |
d2e4a39e | 61 | static struct type *desc_data_type (struct type *); |
14f9c5c9 | 62 | |
d2e4a39e | 63 | static struct value *desc_data (struct value *); |
14f9c5c9 | 64 | |
d2e4a39e | 65 | static int fat_pntr_data_bitpos (struct type *); |
14f9c5c9 | 66 | |
d2e4a39e | 67 | static int fat_pntr_data_bitsize (struct type *); |
14f9c5c9 | 68 | |
d2e4a39e | 69 | static struct value *desc_one_bound (struct value *, int, int); |
14f9c5c9 | 70 | |
d2e4a39e | 71 | static int desc_bound_bitpos (struct type *, int, int); |
14f9c5c9 | 72 | |
d2e4a39e | 73 | static int desc_bound_bitsize (struct type *, int, int); |
14f9c5c9 | 74 | |
d2e4a39e | 75 | static struct type *desc_index_type (struct type *, int); |
14f9c5c9 | 76 | |
d2e4a39e | 77 | static int desc_arity (struct type *); |
14f9c5c9 | 78 | |
d2e4a39e | 79 | static int ada_type_match (struct type *, struct type *, int); |
14f9c5c9 | 80 | |
d2e4a39e | 81 | static int ada_args_match (struct symbol *, struct value **, int); |
14f9c5c9 | 82 | |
d2e4a39e | 83 | static struct value *place_on_stack (struct value *, CORE_ADDR *); |
14f9c5c9 | 84 | |
d2e4a39e AS |
85 | static struct value *convert_actual (struct value *, struct type *, |
86 | CORE_ADDR *); | |
14f9c5c9 | 87 | |
d2e4a39e AS |
88 | static struct value *make_array_descriptor (struct type *, struct value *, |
89 | CORE_ADDR *); | |
14f9c5c9 | 90 | |
d2e4a39e AS |
91 | static void ada_add_block_symbols (struct block *, const char *, |
92 | namespace_enum, struct objfile *, int); | |
14f9c5c9 | 93 | |
d2e4a39e | 94 | static void fill_in_ada_prototype (struct symbol *); |
14f9c5c9 | 95 | |
d2e4a39e | 96 | static int is_nonfunction (struct symbol **, int); |
14f9c5c9 | 97 | |
d2e4a39e | 98 | static void add_defn_to_vec (struct symbol *, struct block *); |
14f9c5c9 | 99 | |
d2e4a39e AS |
100 | static struct partial_symbol *ada_lookup_partial_symbol (struct partial_symtab |
101 | *, const char *, int, | |
102 | namespace_enum, int); | |
14f9c5c9 | 103 | |
d2e4a39e | 104 | static struct symtab *symtab_for_sym (struct symbol *); |
14f9c5c9 | 105 | |
d2e4a39e AS |
106 | static struct value *ada_resolve_subexp (struct expression **, int *, int, |
107 | struct type *); | |
14f9c5c9 | 108 | |
d2e4a39e AS |
109 | static void replace_operator_with_call (struct expression **, int, int, int, |
110 | struct symbol *, struct block *); | |
14f9c5c9 | 111 | |
d2e4a39e | 112 | static int possible_user_operator_p (enum exp_opcode, struct value **); |
14f9c5c9 | 113 | |
d2e4a39e | 114 | static const char *ada_op_name (enum exp_opcode); |
14f9c5c9 | 115 | |
d2e4a39e | 116 | static int numeric_type_p (struct type *); |
14f9c5c9 | 117 | |
d2e4a39e | 118 | static int integer_type_p (struct type *); |
14f9c5c9 | 119 | |
d2e4a39e | 120 | static int scalar_type_p (struct type *); |
14f9c5c9 | 121 | |
d2e4a39e | 122 | static int discrete_type_p (struct type *); |
14f9c5c9 | 123 | |
d2e4a39e AS |
124 | static char *extended_canonical_line_spec (struct symtab_and_line, |
125 | const char *); | |
14f9c5c9 | 126 | |
d2e4a39e AS |
127 | static struct value *evaluate_subexp (struct type *, struct expression *, |
128 | int *, enum noside); | |
14f9c5c9 | 129 | |
d2e4a39e | 130 | static struct value *evaluate_subexp_type (struct expression *, int *); |
14f9c5c9 | 131 | |
d2e4a39e | 132 | static struct type *ada_create_fundamental_type (struct objfile *, int); |
14f9c5c9 | 133 | |
d2e4a39e | 134 | static int is_dynamic_field (struct type *, int); |
14f9c5c9 | 135 | |
d2e4a39e AS |
136 | static struct type *to_fixed_variant_branch_type (struct type *, char *, |
137 | CORE_ADDR, struct value *); | |
14f9c5c9 | 138 | |
d2e4a39e AS |
139 | static struct type *to_fixed_range_type (char *, struct value *, |
140 | struct objfile *); | |
14f9c5c9 | 141 | |
d2e4a39e | 142 | static struct type *to_static_fixed_type (struct type *); |
14f9c5c9 | 143 | |
d2e4a39e | 144 | static struct value *unwrap_value (struct value *); |
14f9c5c9 | 145 | |
d2e4a39e | 146 | static struct type *packed_array_type (struct type *, long *); |
14f9c5c9 | 147 | |
d2e4a39e | 148 | static struct type *decode_packed_array_type (struct type *); |
14f9c5c9 | 149 | |
d2e4a39e | 150 | static struct value *decode_packed_array (struct value *); |
14f9c5c9 | 151 | |
d2e4a39e AS |
152 | static struct value *value_subscript_packed (struct value *, int, |
153 | struct value **); | |
14f9c5c9 | 154 | |
d2e4a39e AS |
155 | static struct value *coerce_unspec_val_to_type (struct value *, long, |
156 | struct type *); | |
14f9c5c9 | 157 | |
d2e4a39e | 158 | static struct value *get_var_value (char *, char *); |
14f9c5c9 | 159 | |
d2e4a39e | 160 | static int lesseq_defined_than (struct symbol *, struct symbol *); |
14f9c5c9 | 161 | |
d2e4a39e | 162 | static int equiv_types (struct type *, struct type *); |
14f9c5c9 | 163 | |
d2e4a39e | 164 | static int is_name_suffix (const char *); |
14f9c5c9 | 165 | |
d2e4a39e | 166 | static int wild_match (const char *, int, const char *); |
14f9c5c9 | 167 | |
d2e4a39e AS |
168 | static struct symtabs_and_lines find_sal_from_funcs_and_line (const char *, |
169 | int, | |
170 | struct symbol | |
171 | **, int); | |
14f9c5c9 | 172 | |
d2e4a39e AS |
173 | static int find_line_in_linetable (struct linetable *, int, struct symbol **, |
174 | int, int *); | |
14f9c5c9 | 175 | |
d2e4a39e | 176 | static int find_next_line_in_linetable (struct linetable *, int, int, int); |
14f9c5c9 | 177 | |
d2e4a39e AS |
178 | static struct symtabs_and_lines all_sals_for_line (const char *, int, |
179 | char ***); | |
14f9c5c9 | 180 | |
d2e4a39e | 181 | static void read_all_symtabs (const char *); |
14f9c5c9 | 182 | |
d2e4a39e | 183 | static int is_plausible_func_for_line (struct symbol *, int); |
14f9c5c9 | 184 | |
d2e4a39e | 185 | static struct value *ada_coerce_ref (struct value *); |
14f9c5c9 | 186 | |
d2e4a39e | 187 | static struct value *value_pos_atr (struct value *); |
14f9c5c9 | 188 | |
d2e4a39e | 189 | static struct value *value_val_atr (struct type *, struct value *); |
14f9c5c9 | 190 | |
d2e4a39e | 191 | static struct symbol *standard_lookup (const char *, namespace_enum); |
14f9c5c9 AS |
192 | |
193 | extern void markTimeStart (int index); | |
194 | extern void markTimeStop (int index); | |
14f9c5c9 AS |
195 | \f |
196 | ||
d2e4a39e | 197 | |
14f9c5c9 AS |
198 | /* Maximum-sized dynamic type. */ |
199 | static unsigned int varsize_limit; | |
200 | ||
d2e4a39e | 201 | static const char *ada_completer_word_break_characters = |
14f9c5c9 AS |
202 | " \t\n!@#$%^&*()+=|~`}{[]\";:?/,-"; |
203 | ||
204 | /* The name of the symbol to use to get the name of the main subprogram */ | |
205 | #define ADA_MAIN_PROGRAM_SYMBOL_NAME "__gnat_ada_main_program_name" | |
206 | ||
207 | /* Utilities */ | |
208 | ||
209 | /* extract_string | |
210 | * | |
211 | * read the string located at ADDR from the inferior and store the | |
212 | * result into BUF | |
213 | */ | |
214 | void | |
215 | extract_string (CORE_ADDR addr, char *buf) | |
216 | { | |
d2e4a39e | 217 | int char_index = 0; |
14f9c5c9 | 218 | |
d2e4a39e AS |
219 | /* Loop, reading one byte at a time, until we reach the '\000' |
220 | end-of-string marker */ | |
221 | do | |
222 | { | |
223 | target_read_memory (addr + char_index * sizeof (char), | |
224 | buf + char_index * sizeof (char), sizeof (char)); | |
225 | char_index++; | |
226 | } | |
227 | while (buf[char_index - 1] != '\000'); | |
14f9c5c9 AS |
228 | } |
229 | ||
230 | /* Assuming *OLD_VECT points to an array of *SIZE objects of size | |
231 | ELEMENT_SIZE, grow it to contain at least MIN_SIZE objects, | |
232 | updating *OLD_VECT and *SIZE as necessary. */ | |
233 | ||
234 | void | |
d2e4a39e | 235 | grow_vect (void **old_vect, size_t * size, size_t min_size, int element_size) |
14f9c5c9 | 236 | { |
d2e4a39e AS |
237 | if (*size < min_size) |
238 | { | |
239 | *size *= 2; | |
240 | if (*size < min_size) | |
241 | *size = min_size; | |
242 | *old_vect = xrealloc (*old_vect, *size * element_size); | |
243 | } | |
14f9c5c9 AS |
244 | } |
245 | ||
246 | /* True (non-zero) iff TARGET matches FIELD_NAME up to any trailing | |
247 | suffix of FIELD_NAME beginning "___" */ | |
248 | ||
249 | static int | |
ebf56fd3 | 250 | field_name_match (const char *field_name, const char *target) |
14f9c5c9 AS |
251 | { |
252 | int len = strlen (target); | |
d2e4a39e AS |
253 | return |
254 | STREQN (field_name, target, len) | |
255 | && (field_name[len] == '\0' | |
14f9c5c9 | 256 | || (STREQN (field_name + len, "___", 3) |
d2e4a39e | 257 | && !STREQ (field_name + strlen (field_name) - 6, "___XVN"))); |
14f9c5c9 AS |
258 | } |
259 | ||
260 | ||
261 | /* The length of the prefix of NAME prior to any "___" suffix. */ | |
262 | ||
263 | int | |
d2e4a39e | 264 | ada_name_prefix_len (const char *name) |
14f9c5c9 AS |
265 | { |
266 | if (name == NULL) | |
267 | return 0; | |
d2e4a39e | 268 | else |
14f9c5c9 | 269 | { |
d2e4a39e | 270 | const char *p = strstr (name, "___"); |
14f9c5c9 AS |
271 | if (p == NULL) |
272 | return strlen (name); | |
273 | else | |
274 | return p - name; | |
275 | } | |
276 | } | |
277 | ||
278 | /* SUFFIX is a suffix of STR. False if STR is null. */ | |
279 | static int | |
d2e4a39e | 280 | is_suffix (const char *str, const char *suffix) |
14f9c5c9 AS |
281 | { |
282 | int len1, len2; | |
283 | if (str == NULL) | |
284 | return 0; | |
285 | len1 = strlen (str); | |
286 | len2 = strlen (suffix); | |
287 | return (len1 >= len2 && STREQ (str + len1 - len2, suffix)); | |
288 | } | |
289 | ||
290 | /* Create a value of type TYPE whose contents come from VALADDR, if it | |
291 | * is non-null, and whose memory address (in the inferior) is | |
292 | * ADDRESS. */ | |
d2e4a39e AS |
293 | struct value * |
294 | value_from_contents_and_address (struct type *type, char *valaddr, | |
295 | CORE_ADDR address) | |
14f9c5c9 | 296 | { |
d2e4a39e AS |
297 | struct value *v = allocate_value (type); |
298 | if (valaddr == NULL) | |
14f9c5c9 AS |
299 | VALUE_LAZY (v) = 1; |
300 | else | |
301 | memcpy (VALUE_CONTENTS_RAW (v), valaddr, TYPE_LENGTH (type)); | |
302 | VALUE_ADDRESS (v) = address; | |
303 | if (address != 0) | |
304 | VALUE_LVAL (v) = lval_memory; | |
305 | return v; | |
306 | } | |
307 | ||
308 | /* The contents of value VAL, beginning at offset OFFSET, treated as a | |
309 | value of type TYPE. The result is an lval in memory if VAL is. */ | |
310 | ||
d2e4a39e AS |
311 | static struct value * |
312 | coerce_unspec_val_to_type (struct value *val, long offset, struct type *type) | |
14f9c5c9 AS |
313 | { |
314 | CHECK_TYPEDEF (type); | |
315 | if (VALUE_LVAL (val) == lval_memory) | |
316 | return value_at_lazy (type, | |
d2e4a39e AS |
317 | VALUE_ADDRESS (val) + VALUE_OFFSET (val) + offset, |
318 | NULL); | |
319 | else | |
14f9c5c9 | 320 | { |
d2e4a39e | 321 | struct value *result = allocate_value (type); |
14f9c5c9 | 322 | VALUE_LVAL (result) = not_lval; |
d2e4a39e | 323 | if (VALUE_ADDRESS (val) == 0) |
14f9c5c9 | 324 | memcpy (VALUE_CONTENTS_RAW (result), VALUE_CONTENTS (val) + offset, |
d2e4a39e | 325 | TYPE_LENGTH (type) > TYPE_LENGTH (VALUE_TYPE (val)) |
14f9c5c9 | 326 | ? TYPE_LENGTH (VALUE_TYPE (val)) : TYPE_LENGTH (type)); |
d2e4a39e | 327 | else |
14f9c5c9 | 328 | { |
d2e4a39e | 329 | VALUE_ADDRESS (result) = |
14f9c5c9 AS |
330 | VALUE_ADDRESS (val) + VALUE_OFFSET (val) + offset; |
331 | VALUE_LAZY (result) = 1; | |
332 | } | |
333 | return result; | |
334 | } | |
335 | } | |
336 | ||
d2e4a39e AS |
337 | static char * |
338 | cond_offset_host (char *valaddr, long offset) | |
14f9c5c9 AS |
339 | { |
340 | if (valaddr == NULL) | |
341 | return NULL; | |
342 | else | |
343 | return valaddr + offset; | |
344 | } | |
345 | ||
346 | static CORE_ADDR | |
ebf56fd3 | 347 | cond_offset_target (CORE_ADDR address, long offset) |
14f9c5c9 AS |
348 | { |
349 | if (address == 0) | |
350 | return 0; | |
d2e4a39e | 351 | else |
14f9c5c9 AS |
352 | return address + offset; |
353 | } | |
354 | ||
355 | /* Perform execute_command on the result of concatenating all | |
356 | arguments up to NULL. */ | |
357 | static void | |
d2e4a39e | 358 | do_command (const char *arg, ...) |
14f9c5c9 AS |
359 | { |
360 | int len; | |
d2e4a39e AS |
361 | char *cmd; |
362 | const char *s; | |
14f9c5c9 AS |
363 | va_list ap; |
364 | ||
365 | va_start (ap, arg); | |
366 | len = 0; | |
367 | s = arg; | |
368 | cmd = ""; | |
d2e4a39e | 369 | for (; s != NULL; s = va_arg (ap, const char *)) |
14f9c5c9 | 370 | { |
d2e4a39e | 371 | char *cmd1; |
14f9c5c9 | 372 | len += strlen (s); |
d2e4a39e | 373 | cmd1 = alloca (len + 1); |
14f9c5c9 AS |
374 | strcpy (cmd1, cmd); |
375 | strcat (cmd1, s); | |
376 | cmd = cmd1; | |
377 | } | |
378 | va_end (ap); | |
379 | execute_command (cmd, 0); | |
380 | } | |
14f9c5c9 | 381 | \f |
d2e4a39e | 382 | |
14f9c5c9 AS |
383 | /* Language Selection */ |
384 | ||
385 | /* If the main program is in Ada, return language_ada, otherwise return LANG | |
386 | (the main program is in Ada iif the adainit symbol is found). | |
387 | ||
388 | MAIN_PST is not used. */ | |
d2e4a39e | 389 | |
14f9c5c9 | 390 | enum language |
d2e4a39e AS |
391 | ada_update_initial_language (enum language lang, |
392 | struct partial_symtab *main_pst) | |
14f9c5c9 | 393 | { |
d2e4a39e AS |
394 | if (lookup_minimal_symbol ("adainit", (const char *) NULL, |
395 | (struct objfile *) NULL) != NULL) | |
14f9c5c9 AS |
396 | /* return language_ada; */ |
397 | /* FIXME: language_ada should be defined in defs.h */ | |
398 | return language_unknown; | |
399 | ||
400 | return lang; | |
401 | } | |
14f9c5c9 | 402 | \f |
d2e4a39e | 403 | |
14f9c5c9 AS |
404 | /* Symbols */ |
405 | ||
406 | /* Table of Ada operators and their GNAT-mangled names. Last entry is pair | |
407 | of NULLs. */ | |
408 | ||
d2e4a39e AS |
409 | const struct ada_opname_map ada_opname_table[] = { |
410 | {"Oadd", "\"+\"", BINOP_ADD}, | |
411 | {"Osubtract", "\"-\"", BINOP_SUB}, | |
412 | {"Omultiply", "\"*\"", BINOP_MUL}, | |
413 | {"Odivide", "\"/\"", BINOP_DIV}, | |
414 | {"Omod", "\"mod\"", BINOP_MOD}, | |
415 | {"Orem", "\"rem\"", BINOP_REM}, | |
416 | {"Oexpon", "\"**\"", BINOP_EXP}, | |
417 | {"Olt", "\"<\"", BINOP_LESS}, | |
418 | {"Ole", "\"<=\"", BINOP_LEQ}, | |
419 | {"Ogt", "\">\"", BINOP_GTR}, | |
420 | {"Oge", "\">=\"", BINOP_GEQ}, | |
421 | {"Oeq", "\"=\"", BINOP_EQUAL}, | |
422 | {"One", "\"/=\"", BINOP_NOTEQUAL}, | |
423 | {"Oand", "\"and\"", BINOP_BITWISE_AND}, | |
424 | {"Oor", "\"or\"", BINOP_BITWISE_IOR}, | |
425 | {"Oxor", "\"xor\"", BINOP_BITWISE_XOR}, | |
426 | {"Oconcat", "\"&\"", BINOP_CONCAT}, | |
427 | {"Oabs", "\"abs\"", UNOP_ABS}, | |
428 | {"Onot", "\"not\"", UNOP_LOGICAL_NOT}, | |
429 | {"Oadd", "\"+\"", UNOP_PLUS}, | |
430 | {"Osubtract", "\"-\"", UNOP_NEG}, | |
431 | {NULL, NULL} | |
14f9c5c9 AS |
432 | }; |
433 | ||
434 | /* True if STR should be suppressed in info listings. */ | |
435 | static int | |
d2e4a39e | 436 | is_suppressed_name (const char *str) |
14f9c5c9 AS |
437 | { |
438 | if (STREQN (str, "_ada_", 5)) | |
439 | str += 5; | |
440 | if (str[0] == '_' || str[0] == '\000') | |
441 | return 1; | |
442 | else | |
443 | { | |
d2e4a39e AS |
444 | const char *p; |
445 | const char *suffix = strstr (str, "___"); | |
14f9c5c9 AS |
446 | if (suffix != NULL && suffix[3] != 'X') |
447 | return 1; | |
448 | if (suffix == NULL) | |
449 | suffix = str + strlen (str); | |
d2e4a39e | 450 | for (p = suffix - 1; p != str; p -= 1) |
14f9c5c9 AS |
451 | if (isupper (*p)) |
452 | { | |
453 | int i; | |
454 | if (p[0] == 'X' && p[-1] != '_') | |
455 | goto OK; | |
456 | if (*p != 'O') | |
457 | return 1; | |
458 | for (i = 0; ada_opname_table[i].mangled != NULL; i += 1) | |
d2e4a39e | 459 | if (STREQN (ada_opname_table[i].mangled, p, |
14f9c5c9 AS |
460 | strlen (ada_opname_table[i].mangled))) |
461 | goto OK; | |
462 | return 1; | |
d2e4a39e | 463 | OK:; |
14f9c5c9 AS |
464 | } |
465 | return 0; | |
466 | } | |
467 | } | |
468 | ||
469 | /* The "mangled" form of DEMANGLED, according to GNAT conventions. | |
470 | * The result is valid until the next call to ada_mangle. */ | |
471 | char * | |
d2e4a39e | 472 | ada_mangle (const char *demangled) |
14f9c5c9 | 473 | { |
d2e4a39e | 474 | static char *mangling_buffer = NULL; |
14f9c5c9 | 475 | static size_t mangling_buffer_size = 0; |
d2e4a39e | 476 | const char *p; |
14f9c5c9 | 477 | int k; |
d2e4a39e | 478 | |
14f9c5c9 AS |
479 | if (demangled == NULL) |
480 | return NULL; | |
481 | ||
d2e4a39e AS |
482 | GROW_VECT (mangling_buffer, mangling_buffer_size, |
483 | 2 * strlen (demangled) + 10); | |
14f9c5c9 AS |
484 | |
485 | k = 0; | |
486 | for (p = demangled; *p != '\0'; p += 1) | |
487 | { | |
d2e4a39e | 488 | if (*p == '.') |
14f9c5c9 | 489 | { |
d2e4a39e | 490 | mangling_buffer[k] = mangling_buffer[k + 1] = '_'; |
14f9c5c9 AS |
491 | k += 2; |
492 | } | |
493 | else if (*p == '"') | |
494 | { | |
d2e4a39e | 495 | const struct ada_opname_map *mapping; |
14f9c5c9 AS |
496 | |
497 | for (mapping = ada_opname_table; | |
d2e4a39e AS |
498 | mapping->mangled != NULL && |
499 | !STREQN (mapping->demangled, p, strlen (mapping->demangled)); | |
14f9c5c9 AS |
500 | p += 1) |
501 | ; | |
502 | if (mapping->mangled == NULL) | |
503 | error ("invalid Ada operator name: %s", p); | |
d2e4a39e | 504 | strcpy (mangling_buffer + k, mapping->mangled); |
14f9c5c9 AS |
505 | k += strlen (mapping->mangled); |
506 | break; | |
507 | } | |
d2e4a39e | 508 | else |
14f9c5c9 AS |
509 | { |
510 | mangling_buffer[k] = *p; | |
511 | k += 1; | |
512 | } | |
513 | } | |
514 | ||
515 | mangling_buffer[k] = '\0'; | |
516 | return mangling_buffer; | |
517 | } | |
518 | ||
519 | /* Return NAME folded to lower case, or, if surrounded by single | |
520 | * quotes, unfolded, but with the quotes stripped away. Result good | |
521 | * to next call. */ | |
d2e4a39e AS |
522 | char * |
523 | ada_fold_name (const char *name) | |
14f9c5c9 | 524 | { |
d2e4a39e | 525 | static char *fold_buffer = NULL; |
14f9c5c9 AS |
526 | static size_t fold_buffer_size = 0; |
527 | ||
528 | int len = strlen (name); | |
d2e4a39e | 529 | GROW_VECT (fold_buffer, fold_buffer_size, len + 1); |
14f9c5c9 AS |
530 | |
531 | if (name[0] == '\'') | |
532 | { | |
d2e4a39e AS |
533 | strncpy (fold_buffer, name + 1, len - 2); |
534 | fold_buffer[len - 2] = '\000'; | |
14f9c5c9 AS |
535 | } |
536 | else | |
537 | { | |
538 | int i; | |
539 | for (i = 0; i <= len; i += 1) | |
540 | fold_buffer[i] = tolower (name[i]); | |
541 | } | |
542 | ||
543 | return fold_buffer; | |
544 | } | |
545 | ||
546 | /* Demangle: | |
547 | 1. Discard final __{DIGIT}+ or ${DIGIT}+ | |
548 | 2. Convert other instances of embedded "__" to `.'. | |
549 | 3. Discard leading _ada_. | |
550 | 4. Convert operator names to the appropriate quoted symbols. | |
551 | 5. Remove everything after first ___ if it is followed by | |
552 | 'X'. | |
553 | 6. Replace TK__ with __, and a trailing B or TKB with nothing. | |
554 | 7. Put symbols that should be suppressed in <...> brackets. | |
555 | 8. Remove trailing X[bn]* suffix (indicating names in package bodies). | |
556 | The resulting string is valid until the next call of ada_demangle. | |
557 | */ | |
558 | ||
559 | char * | |
d2e4a39e | 560 | ada_demangle (const char *mangled) |
14f9c5c9 AS |
561 | { |
562 | int i, j; | |
563 | int len0; | |
d2e4a39e AS |
564 | const char *p; |
565 | char *demangled; | |
14f9c5c9 | 566 | int at_start_name; |
d2e4a39e | 567 | static char *demangling_buffer = NULL; |
14f9c5c9 | 568 | static size_t demangling_buffer_size = 0; |
d2e4a39e | 569 | |
14f9c5c9 AS |
570 | if (STREQN (mangled, "_ada_", 5)) |
571 | mangled += 5; | |
572 | ||
573 | if (mangled[0] == '_' || mangled[0] == '<') | |
574 | goto Suppress; | |
575 | ||
576 | p = strstr (mangled, "___"); | |
577 | if (p == NULL) | |
578 | len0 = strlen (mangled); | |
d2e4a39e | 579 | else |
14f9c5c9 AS |
580 | { |
581 | if (p[3] == 'X') | |
582 | len0 = p - mangled; | |
583 | else | |
584 | goto Suppress; | |
585 | } | |
586 | if (len0 > 3 && STREQ (mangled + len0 - 3, "TKB")) | |
587 | len0 -= 3; | |
588 | if (len0 > 1 && STREQ (mangled + len0 - 1, "B")) | |
589 | len0 -= 1; | |
590 | ||
591 | /* Make demangled big enough for possible expansion by operator name. */ | |
d2e4a39e | 592 | GROW_VECT (demangling_buffer, demangling_buffer_size, 2 * len0 + 1); |
14f9c5c9 AS |
593 | demangled = demangling_buffer; |
594 | ||
d2e4a39e AS |
595 | if (isdigit (mangled[len0 - 1])) |
596 | { | |
597 | for (i = len0 - 2; i >= 0 && isdigit (mangled[i]); i -= 1) | |
598 | ; | |
599 | if (i > 1 && mangled[i] == '_' && mangled[i - 1] == '_') | |
600 | len0 = i - 1; | |
601 | else if (mangled[i] == '$') | |
602 | len0 = i; | |
603 | } | |
14f9c5c9 | 604 | |
d2e4a39e | 605 | for (i = 0, j = 0; i < len0 && !isalpha (mangled[i]); i += 1, j += 1) |
14f9c5c9 AS |
606 | demangled[j] = mangled[i]; |
607 | ||
608 | at_start_name = 1; | |
609 | while (i < len0) | |
610 | { | |
611 | if (at_start_name && mangled[i] == 'O') | |
612 | { | |
613 | int k; | |
614 | for (k = 0; ada_opname_table[k].mangled != NULL; k += 1) | |
615 | { | |
d2e4a39e AS |
616 | int op_len = strlen (ada_opname_table[k].mangled); |
617 | if (STREQN | |
618 | (ada_opname_table[k].mangled + 1, mangled + i + 1, | |
619 | op_len - 1) && !isalnum (mangled[i + op_len])) | |
14f9c5c9 AS |
620 | { |
621 | strcpy (demangled + j, ada_opname_table[k].demangled); | |
622 | at_start_name = 0; | |
623 | i += op_len; | |
624 | j += strlen (ada_opname_table[k].demangled); | |
625 | break; | |
626 | } | |
627 | } | |
628 | if (ada_opname_table[k].mangled != NULL) | |
629 | continue; | |
630 | } | |
631 | at_start_name = 0; | |
632 | ||
d2e4a39e | 633 | if (i < len0 - 4 && STREQN (mangled + i, "TK__", 4)) |
14f9c5c9 | 634 | i += 2; |
d2e4a39e | 635 | if (mangled[i] == 'X' && i != 0 && isalnum (mangled[i - 1])) |
14f9c5c9 AS |
636 | { |
637 | do | |
638 | i += 1; | |
639 | while (i < len0 && (mangled[i] == 'b' || mangled[i] == 'n')); | |
640 | if (i < len0) | |
641 | goto Suppress; | |
642 | } | |
d2e4a39e | 643 | else if (i < len0 - 2 && mangled[i] == '_' && mangled[i + 1] == '_') |
14f9c5c9 AS |
644 | { |
645 | demangled[j] = '.'; | |
646 | at_start_name = 1; | |
d2e4a39e AS |
647 | i += 2; |
648 | j += 1; | |
14f9c5c9 AS |
649 | } |
650 | else | |
651 | { | |
652 | demangled[j] = mangled[i]; | |
d2e4a39e AS |
653 | i += 1; |
654 | j += 1; | |
14f9c5c9 AS |
655 | } |
656 | } | |
657 | demangled[j] = '\000'; | |
658 | ||
659 | for (i = 0; demangled[i] != '\0'; i += 1) | |
660 | if (isupper (demangled[i]) || demangled[i] == ' ') | |
661 | goto Suppress; | |
662 | ||
663 | return demangled; | |
664 | ||
665 | Suppress: | |
d2e4a39e | 666 | GROW_VECT (demangling_buffer, demangling_buffer_size, strlen (mangled) + 3); |
14f9c5c9 AS |
667 | demangled = demangling_buffer; |
668 | if (mangled[0] == '<') | |
669 | strcpy (demangled, mangled); | |
670 | else | |
671 | sprintf (demangled, "<%s>", mangled); | |
672 | return demangled; | |
673 | ||
674 | } | |
675 | ||
676 | /* Returns non-zero iff SYM_NAME matches NAME, ignoring any trailing | |
677 | * suffixes that encode debugging information or leading _ada_ on | |
678 | * SYM_NAME (see is_name_suffix commentary for the debugging | |
679 | * information that is ignored). If WILD, then NAME need only match a | |
680 | * suffix of SYM_NAME minus the same suffixes. Also returns 0 if | |
681 | * either argument is NULL. */ | |
682 | ||
683 | int | |
d2e4a39e | 684 | ada_match_name (const char *sym_name, const char *name, int wild) |
14f9c5c9 AS |
685 | { |
686 | if (sym_name == NULL || name == NULL) | |
687 | return 0; | |
688 | else if (wild) | |
689 | return wild_match (name, strlen (name), sym_name); | |
d2e4a39e AS |
690 | else |
691 | { | |
692 | int len_name = strlen (name); | |
693 | return (STREQN (sym_name, name, len_name) | |
694 | && is_name_suffix (sym_name + len_name)) | |
695 | || (STREQN (sym_name, "_ada_", 5) | |
696 | && STREQN (sym_name + 5, name, len_name) | |
697 | && is_name_suffix (sym_name + len_name + 5)); | |
698 | } | |
14f9c5c9 AS |
699 | } |
700 | ||
701 | /* True (non-zero) iff in Ada mode, the symbol SYM should be | |
702 | suppressed in info listings. */ | |
703 | ||
704 | int | |
ebf56fd3 | 705 | ada_suppress_symbol_printing (struct symbol *sym) |
14f9c5c9 AS |
706 | { |
707 | if (SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE) | |
708 | return 1; | |
d2e4a39e | 709 | else |
14f9c5c9 AS |
710 | return is_suppressed_name (SYMBOL_NAME (sym)); |
711 | } | |
14f9c5c9 | 712 | \f |
d2e4a39e | 713 | |
14f9c5c9 AS |
714 | /* Arrays */ |
715 | ||
716 | /* Names of MAX_ADA_DIMENS bounds in P_BOUNDS fields of | |
717 | array descriptors. */ | |
718 | ||
d2e4a39e AS |
719 | static char *bound_name[] = { |
720 | "LB0", "UB0", "LB1", "UB1", "LB2", "UB2", "LB3", "UB3", | |
14f9c5c9 AS |
721 | "LB4", "UB4", "LB5", "UB5", "LB6", "UB6", "LB7", "UB7" |
722 | }; | |
723 | ||
724 | /* Maximum number of array dimensions we are prepared to handle. */ | |
725 | ||
726 | #define MAX_ADA_DIMENS (sizeof(bound_name) / (2*sizeof(char*))) | |
727 | ||
728 | /* Like modify_field, but allows bitpos > wordlength. */ | |
729 | ||
730 | static void | |
ebf56fd3 | 731 | modify_general_field (char *addr, LONGEST fieldval, int bitpos, int bitsize) |
14f9c5c9 | 732 | { |
d2e4a39e AS |
733 | modify_field (addr + sizeof (LONGEST) * bitpos / (8 * sizeof (LONGEST)), |
734 | fieldval, bitpos % (8 * sizeof (LONGEST)), bitsize); | |
14f9c5c9 AS |
735 | } |
736 | ||
737 | ||
738 | /* The desc_* routines return primitive portions of array descriptors | |
739 | (fat pointers). */ | |
740 | ||
741 | /* The descriptor or array type, if any, indicated by TYPE; removes | |
742 | level of indirection, if needed. */ | |
d2e4a39e AS |
743 | static struct type * |
744 | desc_base_type (struct type *type) | |
14f9c5c9 AS |
745 | { |
746 | if (type == NULL) | |
747 | return NULL; | |
748 | CHECK_TYPEDEF (type); | |
749 | if (type != NULL && TYPE_CODE (type) == TYPE_CODE_PTR) | |
750 | return check_typedef (TYPE_TARGET_TYPE (type)); | |
751 | else | |
752 | return type; | |
753 | } | |
754 | ||
755 | /* True iff TYPE indicates a "thin" array pointer type. */ | |
756 | static int | |
d2e4a39e | 757 | is_thin_pntr (struct type *type) |
14f9c5c9 | 758 | { |
d2e4a39e | 759 | return |
14f9c5c9 AS |
760 | is_suffix (ada_type_name (desc_base_type (type)), "___XUT") |
761 | || is_suffix (ada_type_name (desc_base_type (type)), "___XUT___XVE"); | |
762 | } | |
763 | ||
764 | /* The descriptor type for thin pointer type TYPE. */ | |
d2e4a39e AS |
765 | static struct type * |
766 | thin_descriptor_type (struct type *type) | |
14f9c5c9 | 767 | { |
d2e4a39e | 768 | struct type *base_type = desc_base_type (type); |
14f9c5c9 AS |
769 | if (base_type == NULL) |
770 | return NULL; | |
771 | if (is_suffix (ada_type_name (base_type), "___XVE")) | |
772 | return base_type; | |
d2e4a39e | 773 | else |
14f9c5c9 | 774 | { |
d2e4a39e | 775 | struct type *alt_type = ada_find_parallel_type (base_type, "___XVE"); |
14f9c5c9 AS |
776 | if (alt_type == NULL) |
777 | return base_type; | |
778 | else | |
779 | return alt_type; | |
780 | } | |
781 | } | |
782 | ||
783 | /* A pointer to the array data for thin-pointer value VAL. */ | |
d2e4a39e AS |
784 | static struct value * |
785 | thin_data_pntr (struct value *val) | |
14f9c5c9 | 786 | { |
d2e4a39e | 787 | struct type *type = VALUE_TYPE (val); |
14f9c5c9 | 788 | if (TYPE_CODE (type) == TYPE_CODE_PTR) |
d2e4a39e | 789 | return value_cast (desc_data_type (thin_descriptor_type (type)), |
14f9c5c9 | 790 | value_copy (val)); |
d2e4a39e | 791 | else |
14f9c5c9 AS |
792 | return value_from_longest (desc_data_type (thin_descriptor_type (type)), |
793 | VALUE_ADDRESS (val) + VALUE_OFFSET (val)); | |
794 | } | |
795 | ||
796 | /* True iff TYPE indicates a "thick" array pointer type. */ | |
797 | static int | |
d2e4a39e | 798 | is_thick_pntr (struct type *type) |
14f9c5c9 AS |
799 | { |
800 | type = desc_base_type (type); | |
801 | return (type != NULL && TYPE_CODE (type) == TYPE_CODE_STRUCT | |
802 | && lookup_struct_elt_type (type, "P_BOUNDS", 1) != NULL); | |
803 | } | |
804 | ||
805 | /* If TYPE is the type of an array descriptor (fat or thin pointer) or a | |
806 | pointer to one, the type of its bounds data; otherwise, NULL. */ | |
d2e4a39e AS |
807 | static struct type * |
808 | desc_bounds_type (struct type *type) | |
14f9c5c9 | 809 | { |
d2e4a39e | 810 | struct type *r; |
14f9c5c9 AS |
811 | |
812 | type = desc_base_type (type); | |
813 | ||
814 | if (type == NULL) | |
815 | return NULL; | |
816 | else if (is_thin_pntr (type)) | |
817 | { | |
818 | type = thin_descriptor_type (type); | |
819 | if (type == NULL) | |
820 | return NULL; | |
821 | r = lookup_struct_elt_type (type, "BOUNDS", 1); | |
822 | if (r != NULL) | |
823 | return check_typedef (r); | |
824 | } | |
825 | else if (TYPE_CODE (type) == TYPE_CODE_STRUCT) | |
826 | { | |
827 | r = lookup_struct_elt_type (type, "P_BOUNDS", 1); | |
828 | if (r != NULL) | |
829 | return check_typedef (TYPE_TARGET_TYPE (check_typedef (r))); | |
830 | } | |
831 | return NULL; | |
832 | } | |
833 | ||
834 | /* If ARR is an array descriptor (fat or thin pointer), or pointer to | |
835 | one, a pointer to its bounds data. Otherwise NULL. */ | |
d2e4a39e AS |
836 | static struct value * |
837 | desc_bounds (struct value *arr) | |
14f9c5c9 | 838 | { |
d2e4a39e AS |
839 | struct type *type = check_typedef (VALUE_TYPE (arr)); |
840 | if (is_thin_pntr (type)) | |
14f9c5c9 | 841 | { |
d2e4a39e AS |
842 | struct type *bounds_type = |
843 | desc_bounds_type (thin_descriptor_type (type)); | |
14f9c5c9 AS |
844 | LONGEST addr; |
845 | ||
846 | if (desc_bounds_type == NULL) | |
847 | error ("Bad GNAT array descriptor"); | |
848 | ||
849 | /* NOTE: The following calculation is not really kosher, but | |
d2e4a39e AS |
850 | since desc_type is an XVE-encoded type (and shouldn't be), |
851 | the correct calculation is a real pain. FIXME (and fix GCC). */ | |
14f9c5c9 AS |
852 | if (TYPE_CODE (type) == TYPE_CODE_PTR) |
853 | addr = value_as_long (arr); | |
d2e4a39e | 854 | else |
14f9c5c9 AS |
855 | addr = VALUE_ADDRESS (arr) + VALUE_OFFSET (arr); |
856 | ||
d2e4a39e AS |
857 | return |
858 | value_from_longest (lookup_pointer_type (bounds_type), | |
859 | addr - TYPE_LENGTH (bounds_type)); | |
14f9c5c9 AS |
860 | } |
861 | ||
862 | else if (is_thick_pntr (type)) | |
d2e4a39e | 863 | return value_struct_elt (&arr, NULL, "P_BOUNDS", NULL, |
14f9c5c9 AS |
864 | "Bad GNAT array descriptor"); |
865 | else | |
866 | return NULL; | |
867 | } | |
868 | ||
869 | /* If TYPE is the type of an array-descriptor (fat pointer), the bit | |
870 | position of the field containing the address of the bounds data. */ | |
871 | static int | |
d2e4a39e | 872 | fat_pntr_bounds_bitpos (struct type *type) |
14f9c5c9 AS |
873 | { |
874 | return TYPE_FIELD_BITPOS (desc_base_type (type), 1); | |
875 | } | |
876 | ||
877 | /* If TYPE is the type of an array-descriptor (fat pointer), the bit | |
878 | size of the field containing the address of the bounds data. */ | |
879 | static int | |
d2e4a39e | 880 | fat_pntr_bounds_bitsize (struct type *type) |
14f9c5c9 AS |
881 | { |
882 | type = desc_base_type (type); | |
883 | ||
d2e4a39e | 884 | if (TYPE_FIELD_BITSIZE (type, 1) > 0) |
14f9c5c9 AS |
885 | return TYPE_FIELD_BITSIZE (type, 1); |
886 | else | |
887 | return 8 * TYPE_LENGTH (check_typedef (TYPE_FIELD_TYPE (type, 1))); | |
888 | } | |
889 | ||
890 | /* If TYPE is the type of an array descriptor (fat or thin pointer) or a | |
891 | pointer to one, the type of its array data (a | |
892 | pointer-to-array-with-no-bounds type); otherwise, NULL. Use | |
893 | ada_type_of_array to get an array type with bounds data. */ | |
d2e4a39e AS |
894 | static struct type * |
895 | desc_data_type (struct type *type) | |
14f9c5c9 AS |
896 | { |
897 | type = desc_base_type (type); | |
898 | ||
899 | /* NOTE: The following is bogus; see comment in desc_bounds. */ | |
900 | if (is_thin_pntr (type)) | |
d2e4a39e AS |
901 | return lookup_pointer_type |
902 | (desc_base_type (TYPE_FIELD_TYPE (thin_descriptor_type (type), 1))); | |
14f9c5c9 AS |
903 | else if (is_thick_pntr (type)) |
904 | return lookup_struct_elt_type (type, "P_ARRAY", 1); | |
905 | else | |
906 | return NULL; | |
907 | } | |
908 | ||
909 | /* If ARR is an array descriptor (fat or thin pointer), a pointer to | |
910 | its array data. */ | |
d2e4a39e AS |
911 | static struct value * |
912 | desc_data (struct value *arr) | |
14f9c5c9 | 913 | { |
d2e4a39e | 914 | struct type *type = VALUE_TYPE (arr); |
14f9c5c9 AS |
915 | if (is_thin_pntr (type)) |
916 | return thin_data_pntr (arr); | |
917 | else if (is_thick_pntr (type)) | |
d2e4a39e | 918 | return value_struct_elt (&arr, NULL, "P_ARRAY", NULL, |
14f9c5c9 AS |
919 | "Bad GNAT array descriptor"); |
920 | else | |
921 | return NULL; | |
922 | } | |
923 | ||
924 | ||
925 | /* If TYPE is the type of an array-descriptor (fat pointer), the bit | |
926 | position of the field containing the address of the data. */ | |
927 | static int | |
d2e4a39e | 928 | fat_pntr_data_bitpos (struct type *type) |
14f9c5c9 AS |
929 | { |
930 | return TYPE_FIELD_BITPOS (desc_base_type (type), 0); | |
931 | } | |
932 | ||
933 | /* If TYPE is the type of an array-descriptor (fat pointer), the bit | |
934 | size of the field containing the address of the data. */ | |
935 | static int | |
d2e4a39e | 936 | fat_pntr_data_bitsize (struct type *type) |
14f9c5c9 AS |
937 | { |
938 | type = desc_base_type (type); | |
939 | ||
940 | if (TYPE_FIELD_BITSIZE (type, 0) > 0) | |
941 | return TYPE_FIELD_BITSIZE (type, 0); | |
d2e4a39e | 942 | else |
14f9c5c9 AS |
943 | return TARGET_CHAR_BIT * TYPE_LENGTH (TYPE_FIELD_TYPE (type, 0)); |
944 | } | |
945 | ||
946 | /* If BOUNDS is an array-bounds structure (or pointer to one), return | |
947 | the Ith lower bound stored in it, if WHICH is 0, and the Ith upper | |
948 | bound, if WHICH is 1. The first bound is I=1. */ | |
d2e4a39e AS |
949 | static struct value * |
950 | desc_one_bound (struct value *bounds, int i, int which) | |
14f9c5c9 | 951 | { |
d2e4a39e | 952 | return value_struct_elt (&bounds, NULL, bound_name[2 * i + which - 2], NULL, |
14f9c5c9 AS |
953 | "Bad GNAT array descriptor bounds"); |
954 | } | |
955 | ||
956 | /* If BOUNDS is an array-bounds structure type, return the bit position | |
957 | of the Ith lower bound stored in it, if WHICH is 0, and the Ith upper | |
958 | bound, if WHICH is 1. The first bound is I=1. */ | |
959 | static int | |
d2e4a39e | 960 | desc_bound_bitpos (struct type *type, int i, int which) |
14f9c5c9 | 961 | { |
d2e4a39e | 962 | return TYPE_FIELD_BITPOS (desc_base_type (type), 2 * i + which - 2); |
14f9c5c9 AS |
963 | } |
964 | ||
965 | /* If BOUNDS is an array-bounds structure type, return the bit field size | |
966 | of the Ith lower bound stored in it, if WHICH is 0, and the Ith upper | |
967 | bound, if WHICH is 1. The first bound is I=1. */ | |
968 | static int | |
d2e4a39e | 969 | desc_bound_bitsize (struct type *type, int i, int which) |
14f9c5c9 AS |
970 | { |
971 | type = desc_base_type (type); | |
972 | ||
d2e4a39e AS |
973 | if (TYPE_FIELD_BITSIZE (type, 2 * i + which - 2) > 0) |
974 | return TYPE_FIELD_BITSIZE (type, 2 * i + which - 2); | |
975 | else | |
976 | return 8 * TYPE_LENGTH (TYPE_FIELD_TYPE (type, 2 * i + which - 2)); | |
14f9c5c9 AS |
977 | } |
978 | ||
979 | /* If TYPE is the type of an array-bounds structure, the type of its | |
d2e4a39e AS |
980 | Ith bound (numbering from 1). Otherwise, NULL. */ |
981 | static struct type * | |
982 | desc_index_type (struct type *type, int i) | |
14f9c5c9 AS |
983 | { |
984 | type = desc_base_type (type); | |
985 | ||
986 | if (TYPE_CODE (type) == TYPE_CODE_STRUCT) | |
d2e4a39e AS |
987 | return lookup_struct_elt_type (type, bound_name[2 * i - 2], 1); |
988 | else | |
14f9c5c9 AS |
989 | return NULL; |
990 | } | |
991 | ||
992 | /* The number of index positions in the array-bounds type TYPE. 0 | |
993 | if TYPE is NULL. */ | |
994 | static int | |
d2e4a39e | 995 | desc_arity (struct type *type) |
14f9c5c9 AS |
996 | { |
997 | type = desc_base_type (type); | |
998 | ||
999 | if (type != NULL) | |
1000 | return TYPE_NFIELDS (type) / 2; | |
1001 | return 0; | |
1002 | } | |
1003 | ||
1004 | ||
1005 | /* Non-zero iff type is a simple array type (or pointer to one). */ | |
1006 | int | |
d2e4a39e | 1007 | ada_is_simple_array (struct type *type) |
14f9c5c9 AS |
1008 | { |
1009 | if (type == NULL) | |
1010 | return 0; | |
1011 | CHECK_TYPEDEF (type); | |
1012 | return (TYPE_CODE (type) == TYPE_CODE_ARRAY | |
1013 | || (TYPE_CODE (type) == TYPE_CODE_PTR | |
1014 | && TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_ARRAY)); | |
1015 | } | |
1016 | ||
1017 | /* Non-zero iff type belongs to a GNAT array descriptor. */ | |
1018 | int | |
d2e4a39e | 1019 | ada_is_array_descriptor (struct type *type) |
14f9c5c9 | 1020 | { |
d2e4a39e | 1021 | struct type *data_type = desc_data_type (type); |
14f9c5c9 AS |
1022 | |
1023 | if (type == NULL) | |
1024 | return 0; | |
1025 | CHECK_TYPEDEF (type); | |
d2e4a39e | 1026 | return |
14f9c5c9 AS |
1027 | data_type != NULL |
1028 | && ((TYPE_CODE (data_type) == TYPE_CODE_PTR | |
1029 | && TYPE_TARGET_TYPE (data_type) != NULL | |
1030 | && TYPE_CODE (TYPE_TARGET_TYPE (data_type)) == TYPE_CODE_ARRAY) | |
d2e4a39e | 1031 | || |
14f9c5c9 AS |
1032 | TYPE_CODE (data_type) == TYPE_CODE_ARRAY) |
1033 | && desc_arity (desc_bounds_type (type)) > 0; | |
1034 | } | |
1035 | ||
1036 | /* Non-zero iff type is a partially mal-formed GNAT array | |
1037 | descriptor. (FIXME: This is to compensate for some problems with | |
1038 | debugging output from GNAT. Re-examine periodically to see if it | |
1039 | is still needed. */ | |
1040 | int | |
ebf56fd3 | 1041 | ada_is_bogus_array_descriptor (struct type *type) |
14f9c5c9 | 1042 | { |
d2e4a39e | 1043 | return |
14f9c5c9 AS |
1044 | type != NULL |
1045 | && TYPE_CODE (type) == TYPE_CODE_STRUCT | |
1046 | && (lookup_struct_elt_type (type, "P_BOUNDS", 1) != NULL | |
1047 | || lookup_struct_elt_type (type, "P_ARRAY", 1) != NULL) | |
d2e4a39e | 1048 | && !ada_is_array_descriptor (type); |
14f9c5c9 AS |
1049 | } |
1050 | ||
1051 | ||
1052 | /* If ARR has a record type in the form of a standard GNAT array descriptor, | |
1053 | (fat pointer) returns the type of the array data described---specifically, | |
1054 | a pointer-to-array type. If BOUNDS is non-zero, the bounds data are filled | |
1055 | in from the descriptor; otherwise, they are left unspecified. If | |
1056 | the ARR denotes a null array descriptor and BOUNDS is non-zero, | |
1057 | returns NULL. The result is simply the type of ARR if ARR is not | |
1058 | a descriptor. */ | |
d2e4a39e AS |
1059 | struct type * |
1060 | ada_type_of_array (struct value *arr, int bounds) | |
14f9c5c9 AS |
1061 | { |
1062 | if (ada_is_packed_array_type (VALUE_TYPE (arr))) | |
1063 | return decode_packed_array_type (VALUE_TYPE (arr)); | |
1064 | ||
d2e4a39e | 1065 | if (!ada_is_array_descriptor (VALUE_TYPE (arr))) |
14f9c5c9 | 1066 | return VALUE_TYPE (arr); |
d2e4a39e AS |
1067 | |
1068 | if (!bounds) | |
1069 | return | |
1070 | check_typedef (TYPE_TARGET_TYPE (desc_data_type (VALUE_TYPE (arr)))); | |
14f9c5c9 AS |
1071 | else |
1072 | { | |
d2e4a39e | 1073 | struct type *elt_type; |
14f9c5c9 | 1074 | int arity; |
d2e4a39e | 1075 | struct value *descriptor; |
14f9c5c9 AS |
1076 | struct objfile *objf = TYPE_OBJFILE (VALUE_TYPE (arr)); |
1077 | ||
1078 | elt_type = ada_array_element_type (VALUE_TYPE (arr), -1); | |
1079 | arity = ada_array_arity (VALUE_TYPE (arr)); | |
1080 | ||
d2e4a39e | 1081 | if (elt_type == NULL || arity == 0) |
14f9c5c9 AS |
1082 | return check_typedef (VALUE_TYPE (arr)); |
1083 | ||
1084 | descriptor = desc_bounds (arr); | |
d2e4a39e | 1085 | if (value_as_long (descriptor) == 0) |
14f9c5c9 | 1086 | return NULL; |
d2e4a39e AS |
1087 | while (arity > 0) |
1088 | { | |
1089 | struct type *range_type = alloc_type (objf); | |
1090 | struct type *array_type = alloc_type (objf); | |
1091 | struct value *low = desc_one_bound (descriptor, arity, 0); | |
1092 | struct value *high = desc_one_bound (descriptor, arity, 1); | |
1093 | arity -= 1; | |
1094 | ||
1095 | create_range_type (range_type, VALUE_TYPE (low), | |
1096 | (int) value_as_long (low), | |
1097 | (int) value_as_long (high)); | |
1098 | elt_type = create_array_type (array_type, elt_type, range_type); | |
1099 | } | |
14f9c5c9 AS |
1100 | |
1101 | return lookup_pointer_type (elt_type); | |
1102 | } | |
1103 | } | |
1104 | ||
1105 | /* If ARR does not represent an array, returns ARR unchanged. | |
1106 | Otherwise, returns either a standard GDB array with bounds set | |
1107 | appropriately or, if ARR is a non-null fat pointer, a pointer to a standard | |
1108 | GDB array. Returns NULL if ARR is a null fat pointer. */ | |
d2e4a39e AS |
1109 | struct value * |
1110 | ada_coerce_to_simple_array_ptr (struct value *arr) | |
14f9c5c9 AS |
1111 | { |
1112 | if (ada_is_array_descriptor (VALUE_TYPE (arr))) | |
1113 | { | |
d2e4a39e | 1114 | struct type *arrType = ada_type_of_array (arr, 1); |
14f9c5c9 AS |
1115 | if (arrType == NULL) |
1116 | return NULL; | |
1117 | return value_cast (arrType, value_copy (desc_data (arr))); | |
1118 | } | |
1119 | else if (ada_is_packed_array_type (VALUE_TYPE (arr))) | |
1120 | return decode_packed_array (arr); | |
1121 | else | |
1122 | return arr; | |
1123 | } | |
1124 | ||
1125 | /* If ARR does not represent an array, returns ARR unchanged. | |
1126 | Otherwise, returns a standard GDB array describing ARR (which may | |
1127 | be ARR itself if it already is in the proper form). */ | |
d2e4a39e AS |
1128 | struct value * |
1129 | ada_coerce_to_simple_array (struct value *arr) | |
14f9c5c9 AS |
1130 | { |
1131 | if (ada_is_array_descriptor (VALUE_TYPE (arr))) | |
1132 | { | |
d2e4a39e | 1133 | struct value *arrVal = ada_coerce_to_simple_array_ptr (arr); |
14f9c5c9 AS |
1134 | if (arrVal == NULL) |
1135 | error ("Bounds unavailable for null array pointer."); | |
1136 | return value_ind (arrVal); | |
1137 | } | |
1138 | else if (ada_is_packed_array_type (VALUE_TYPE (arr))) | |
1139 | return decode_packed_array (arr); | |
d2e4a39e | 1140 | else |
14f9c5c9 AS |
1141 | return arr; |
1142 | } | |
1143 | ||
1144 | /* If TYPE represents a GNAT array type, return it translated to an | |
1145 | ordinary GDB array type (possibly with BITSIZE fields indicating | |
1146 | packing). For other types, is the identity. */ | |
d2e4a39e AS |
1147 | struct type * |
1148 | ada_coerce_to_simple_array_type (struct type *type) | |
14f9c5c9 | 1149 | { |
d2e4a39e AS |
1150 | struct value *mark = value_mark (); |
1151 | struct value *dummy = value_from_longest (builtin_type_long, 0); | |
1152 | struct type *result; | |
14f9c5c9 AS |
1153 | VALUE_TYPE (dummy) = type; |
1154 | result = ada_type_of_array (dummy, 0); | |
1155 | value_free_to_mark (dummy); | |
1156 | return result; | |
1157 | } | |
1158 | ||
1159 | /* Non-zero iff TYPE represents a standard GNAT packed-array type. */ | |
1160 | int | |
d2e4a39e | 1161 | ada_is_packed_array_type (struct type *type) |
14f9c5c9 AS |
1162 | { |
1163 | if (type == NULL) | |
1164 | return 0; | |
1165 | CHECK_TYPEDEF (type); | |
d2e4a39e | 1166 | return |
14f9c5c9 AS |
1167 | ada_type_name (type) != NULL |
1168 | && strstr (ada_type_name (type), "___XP") != NULL; | |
1169 | } | |
1170 | ||
1171 | /* Given that TYPE is a standard GDB array type with all bounds filled | |
1172 | in, and that the element size of its ultimate scalar constituents | |
1173 | (that is, either its elements, or, if it is an array of arrays, its | |
1174 | elements' elements, etc.) is *ELT_BITS, return an identical type, | |
1175 | but with the bit sizes of its elements (and those of any | |
1176 | constituent arrays) recorded in the BITSIZE components of its | |
1177 | TYPE_FIELD_BITSIZE values, and with *ELT_BITS set to its total size | |
1178 | in bits. */ | |
d2e4a39e AS |
1179 | static struct type * |
1180 | packed_array_type (struct type *type, long *elt_bits) | |
14f9c5c9 | 1181 | { |
d2e4a39e AS |
1182 | struct type *new_elt_type; |
1183 | struct type *new_type; | |
14f9c5c9 AS |
1184 | LONGEST low_bound, high_bound; |
1185 | ||
1186 | CHECK_TYPEDEF (type); | |
1187 | if (TYPE_CODE (type) != TYPE_CODE_ARRAY) | |
1188 | return type; | |
1189 | ||
1190 | new_type = alloc_type (TYPE_OBJFILE (type)); | |
1191 | new_elt_type = packed_array_type (check_typedef (TYPE_TARGET_TYPE (type)), | |
1192 | elt_bits); | |
1193 | create_array_type (new_type, new_elt_type, TYPE_FIELD_TYPE (type, 0)); | |
1194 | TYPE_FIELD_BITSIZE (new_type, 0) = *elt_bits; | |
1195 | TYPE_NAME (new_type) = ada_type_name (type); | |
1196 | ||
d2e4a39e | 1197 | if (get_discrete_bounds (TYPE_FIELD_TYPE (type, 0), |
14f9c5c9 AS |
1198 | &low_bound, &high_bound) < 0) |
1199 | low_bound = high_bound = 0; | |
1200 | if (high_bound < low_bound) | |
1201 | *elt_bits = TYPE_LENGTH (new_type) = 0; | |
d2e4a39e | 1202 | else |
14f9c5c9 AS |
1203 | { |
1204 | *elt_bits *= (high_bound - low_bound + 1); | |
d2e4a39e | 1205 | TYPE_LENGTH (new_type) = |
14f9c5c9 AS |
1206 | (*elt_bits + HOST_CHAR_BIT - 1) / HOST_CHAR_BIT; |
1207 | } | |
1208 | ||
1209 | /* TYPE_FLAGS (new_type) |= TYPE_FLAG_FIXED_INSTANCE; */ | |
1210 | /* FIXME: TYPE_FLAG_FIXED_INSTANCE should be defined in gdbtypes.h */ | |
1211 | return new_type; | |
1212 | } | |
1213 | ||
1214 | /* The array type encoded by TYPE, where ada_is_packed_array_type (TYPE). | |
1215 | */ | |
d2e4a39e AS |
1216 | static struct type * |
1217 | decode_packed_array_type (struct type *type) | |
1218 | { | |
1219 | struct symbol **syms; | |
1220 | struct block **blocks; | |
1221 | const char *raw_name = ada_type_name (check_typedef (type)); | |
1222 | char *name = (char *) alloca (strlen (raw_name) + 1); | |
1223 | char *tail = strstr (raw_name, "___XP"); | |
1224 | struct type *shadow_type; | |
14f9c5c9 AS |
1225 | long bits; |
1226 | int i, n; | |
1227 | ||
1228 | memcpy (name, raw_name, tail - raw_name); | |
1229 | name[tail - raw_name] = '\000'; | |
1230 | ||
1231 | /* NOTE: Use ada_lookup_symbol_list because of bug in some versions | |
1232 | * of gcc (Solaris, e.g.). FIXME when compiler is fixed. */ | |
d2e4a39e | 1233 | n = ada_lookup_symbol_list (name, get_selected_block (NULL), |
14f9c5c9 AS |
1234 | VAR_NAMESPACE, &syms, &blocks); |
1235 | for (i = 0; i < n; i += 1) | |
1236 | if (syms[i] != NULL && SYMBOL_CLASS (syms[i]) == LOC_TYPEDEF | |
1237 | && STREQ (name, ada_type_name (SYMBOL_TYPE (syms[i])))) | |
1238 | break; | |
1239 | if (i >= n) | |
1240 | { | |
1241 | warning ("could not find bounds information on packed array"); | |
1242 | return NULL; | |
1243 | } | |
1244 | shadow_type = SYMBOL_TYPE (syms[i]); | |
1245 | ||
1246 | if (TYPE_CODE (shadow_type) != TYPE_CODE_ARRAY) | |
1247 | { | |
1248 | warning ("could not understand bounds information on packed array"); | |
1249 | return NULL; | |
1250 | } | |
d2e4a39e | 1251 | |
14f9c5c9 AS |
1252 | if (sscanf (tail + sizeof ("___XP") - 1, "%ld", &bits) != 1) |
1253 | { | |
1254 | warning ("could not understand bit size information on packed array"); | |
1255 | return NULL; | |
1256 | } | |
d2e4a39e | 1257 | |
14f9c5c9 AS |
1258 | return packed_array_type (shadow_type, &bits); |
1259 | } | |
1260 | ||
1261 | /* Given that ARR is a struct value* indicating a GNAT packed array, | |
1262 | returns a simple array that denotes that array. Its type is a | |
1263 | standard GDB array type except that the BITSIZEs of the array | |
1264 | target types are set to the number of bits in each element, and the | |
1265 | type length is set appropriately. */ | |
1266 | ||
d2e4a39e AS |
1267 | static struct value * |
1268 | decode_packed_array (struct value *arr) | |
14f9c5c9 | 1269 | { |
d2e4a39e | 1270 | struct type *type = decode_packed_array_type (VALUE_TYPE (arr)); |
14f9c5c9 AS |
1271 | |
1272 | if (type == NULL) | |
1273 | { | |
1274 | error ("can't unpack array"); | |
1275 | return NULL; | |
1276 | } | |
1277 | else | |
1278 | return coerce_unspec_val_to_type (arr, 0, type); | |
1279 | } | |
1280 | ||
1281 | ||
1282 | /* The value of the element of packed array ARR at the ARITY indices | |
1283 | given in IND. ARR must be a simple array. */ | |
1284 | ||
d2e4a39e AS |
1285 | static struct value * |
1286 | value_subscript_packed (struct value *arr, int arity, struct value **ind) | |
14f9c5c9 AS |
1287 | { |
1288 | int i; | |
1289 | int bits, elt_off, bit_off; | |
1290 | long elt_total_bit_offset; | |
d2e4a39e AS |
1291 | struct type *elt_type; |
1292 | struct value *v; | |
14f9c5c9 AS |
1293 | |
1294 | bits = 0; | |
1295 | elt_total_bit_offset = 0; | |
1296 | elt_type = check_typedef (VALUE_TYPE (arr)); | |
d2e4a39e | 1297 | for (i = 0; i < arity; i += 1) |
14f9c5c9 | 1298 | { |
d2e4a39e | 1299 | if (TYPE_CODE (elt_type) != TYPE_CODE_ARRAY |
14f9c5c9 | 1300 | || TYPE_FIELD_BITSIZE (elt_type, 0) == 0) |
d2e4a39e AS |
1301 | error |
1302 | ("attempt to do packed indexing of something other than a packed array"); | |
14f9c5c9 AS |
1303 | else |
1304 | { | |
1305 | struct type *range_type = TYPE_INDEX_TYPE (elt_type); | |
1306 | LONGEST lowerbound, upperbound; | |
1307 | LONGEST idx; | |
1308 | ||
d2e4a39e | 1309 | if (get_discrete_bounds (range_type, &lowerbound, &upperbound) < 0) |
14f9c5c9 AS |
1310 | { |
1311 | warning ("don't know bounds of array"); | |
1312 | lowerbound = upperbound = 0; | |
1313 | } | |
d2e4a39e | 1314 | |
14f9c5c9 AS |
1315 | idx = value_as_long (value_pos_atr (ind[i])); |
1316 | if (idx < lowerbound || idx > upperbound) | |
1317 | warning ("packed array index %ld out of bounds", (long) idx); | |
1318 | bits = TYPE_FIELD_BITSIZE (elt_type, 0); | |
1319 | elt_total_bit_offset += (idx - lowerbound) * bits; | |
1320 | elt_type = check_typedef (TYPE_TARGET_TYPE (elt_type)); | |
1321 | } | |
1322 | } | |
1323 | elt_off = elt_total_bit_offset / HOST_CHAR_BIT; | |
1324 | bit_off = elt_total_bit_offset % HOST_CHAR_BIT; | |
d2e4a39e AS |
1325 | |
1326 | v = ada_value_primitive_packed_val (arr, NULL, elt_off, bit_off, | |
14f9c5c9 AS |
1327 | bits, elt_type); |
1328 | if (VALUE_LVAL (arr) == lval_internalvar) | |
1329 | VALUE_LVAL (v) = lval_internalvar_component; | |
1330 | else | |
1331 | VALUE_LVAL (v) = VALUE_LVAL (arr); | |
1332 | return v; | |
1333 | } | |
1334 | ||
1335 | /* Non-zero iff TYPE includes negative integer values. */ | |
1336 | ||
1337 | static int | |
d2e4a39e | 1338 | has_negatives (struct type *type) |
14f9c5c9 | 1339 | { |
d2e4a39e AS |
1340 | switch (TYPE_CODE (type)) |
1341 | { | |
1342 | default: | |
1343 | return 0; | |
1344 | case TYPE_CODE_INT: | |
1345 | return !TYPE_UNSIGNED (type); | |
1346 | case TYPE_CODE_RANGE: | |
1347 | return TYPE_LOW_BOUND (type) < 0; | |
1348 | } | |
14f9c5c9 | 1349 | } |
d2e4a39e | 1350 | |
14f9c5c9 AS |
1351 | |
1352 | /* Create a new value of type TYPE from the contents of OBJ starting | |
1353 | at byte OFFSET, and bit offset BIT_OFFSET within that byte, | |
1354 | proceeding for BIT_SIZE bits. If OBJ is an lval in memory, then | |
1355 | assigning through the result will set the field fetched from. OBJ | |
1356 | may also be NULL, in which case, VALADDR+OFFSET must address the | |
1357 | start of storage containing the packed value. The value returned | |
1358 | in this case is never an lval. | |
1359 | Assumes 0 <= BIT_OFFSET < HOST_CHAR_BIT. */ | |
1360 | ||
d2e4a39e AS |
1361 | struct value * |
1362 | ada_value_primitive_packed_val (struct value *obj, char *valaddr, long offset, | |
1363 | int bit_offset, int bit_size, | |
1364 | struct type *type) | |
14f9c5c9 | 1365 | { |
d2e4a39e | 1366 | struct value *v; |
14f9c5c9 AS |
1367 | int src, /* Index into the source area. */ |
1368 | targ, /* Index into the target area. */ | |
d2e4a39e | 1369 | i, srcBitsLeft, /* Number of source bits left to move. */ |
14f9c5c9 AS |
1370 | nsrc, ntarg, /* Number of source and target bytes. */ |
1371 | unusedLS, /* Number of bits in next significant | |
1372 | * byte of source that are unused. */ | |
1373 | accumSize; /* Number of meaningful bits in accum */ | |
d2e4a39e AS |
1374 | unsigned char *bytes; /* First byte containing data to unpack. */ |
1375 | unsigned char *unpacked; | |
14f9c5c9 AS |
1376 | unsigned long accum; /* Staging area for bits being transferred */ |
1377 | unsigned char sign; | |
1378 | int len = (bit_size + bit_offset + HOST_CHAR_BIT - 1) / 8; | |
1379 | /* Transmit bytes from least to most significant; delta is the | |
d2e4a39e | 1380 | * direction the indices move. */ |
14f9c5c9 AS |
1381 | int delta = BITS_BIG_ENDIAN ? -1 : 1; |
1382 | ||
1383 | CHECK_TYPEDEF (type); | |
1384 | ||
1385 | if (obj == NULL) | |
1386 | { | |
1387 | v = allocate_value (type); | |
d2e4a39e | 1388 | bytes = (unsigned char *) (valaddr + offset); |
14f9c5c9 AS |
1389 | } |
1390 | else if (VALUE_LAZY (obj)) | |
1391 | { | |
1392 | v = value_at (type, | |
1393 | VALUE_ADDRESS (obj) + VALUE_OFFSET (obj) + offset, NULL); | |
d2e4a39e | 1394 | bytes = (unsigned char *) alloca (len); |
14f9c5c9 AS |
1395 | read_memory (VALUE_ADDRESS (v), bytes, len); |
1396 | } | |
d2e4a39e | 1397 | else |
14f9c5c9 AS |
1398 | { |
1399 | v = allocate_value (type); | |
d2e4a39e | 1400 | bytes = (unsigned char *) VALUE_CONTENTS (obj) + offset; |
14f9c5c9 | 1401 | } |
d2e4a39e AS |
1402 | |
1403 | if (obj != NULL) | |
14f9c5c9 AS |
1404 | { |
1405 | VALUE_LVAL (v) = VALUE_LVAL (obj); | |
1406 | if (VALUE_LVAL (obj) == lval_internalvar) | |
1407 | VALUE_LVAL (v) = lval_internalvar_component; | |
1408 | VALUE_ADDRESS (v) = VALUE_ADDRESS (obj) + VALUE_OFFSET (obj) + offset; | |
1409 | VALUE_BITPOS (v) = bit_offset + VALUE_BITPOS (obj); | |
1410 | VALUE_BITSIZE (v) = bit_size; | |
1411 | if (VALUE_BITPOS (v) >= HOST_CHAR_BIT) | |
d2e4a39e AS |
1412 | { |
1413 | VALUE_ADDRESS (v) += 1; | |
1414 | VALUE_BITPOS (v) -= HOST_CHAR_BIT; | |
1415 | } | |
14f9c5c9 AS |
1416 | } |
1417 | else | |
1418 | VALUE_BITSIZE (v) = bit_size; | |
d2e4a39e | 1419 | unpacked = (unsigned char *) VALUE_CONTENTS (v); |
14f9c5c9 AS |
1420 | |
1421 | srcBitsLeft = bit_size; | |
1422 | nsrc = len; | |
1423 | ntarg = TYPE_LENGTH (type); | |
1424 | sign = 0; | |
1425 | if (bit_size == 0) | |
1426 | { | |
1427 | memset (unpacked, 0, TYPE_LENGTH (type)); | |
1428 | return v; | |
1429 | } | |
1430 | else if (BITS_BIG_ENDIAN) | |
1431 | { | |
d2e4a39e AS |
1432 | src = len - 1; |
1433 | if (has_negatives (type) && | |
1434 | ((bytes[0] << bit_offset) & (1 << (HOST_CHAR_BIT - 1)))) | |
14f9c5c9 | 1435 | sign = ~0; |
d2e4a39e AS |
1436 | |
1437 | unusedLS = | |
14f9c5c9 AS |
1438 | (HOST_CHAR_BIT - (bit_size + bit_offset) % HOST_CHAR_BIT) |
1439 | % HOST_CHAR_BIT; | |
1440 | ||
1441 | switch (TYPE_CODE (type)) | |
d2e4a39e AS |
1442 | { |
1443 | case TYPE_CODE_ARRAY: | |
1444 | case TYPE_CODE_UNION: | |
1445 | case TYPE_CODE_STRUCT: | |
1446 | /* Non-scalar values must be aligned at a byte boundary. */ | |
1447 | accumSize = | |
1448 | (HOST_CHAR_BIT - bit_size % HOST_CHAR_BIT) % HOST_CHAR_BIT; | |
14f9c5c9 AS |
1449 | /* And are placed at the beginning (most-significant) bytes |
1450 | * of the target. */ | |
1451 | targ = src; | |
d2e4a39e AS |
1452 | break; |
1453 | default: | |
14f9c5c9 AS |
1454 | accumSize = 0; |
1455 | targ = TYPE_LENGTH (type) - 1; | |
d2e4a39e AS |
1456 | break; |
1457 | } | |
14f9c5c9 | 1458 | } |
d2e4a39e | 1459 | else |
14f9c5c9 AS |
1460 | { |
1461 | int sign_bit_offset = (bit_size + bit_offset - 1) % 8; | |
1462 | ||
1463 | src = targ = 0; | |
1464 | unusedLS = bit_offset; | |
1465 | accumSize = 0; | |
1466 | ||
d2e4a39e | 1467 | if (has_negatives (type) && (bytes[len - 1] & (1 << sign_bit_offset))) |
14f9c5c9 AS |
1468 | sign = ~0; |
1469 | } | |
d2e4a39e | 1470 | |
14f9c5c9 AS |
1471 | accum = 0; |
1472 | while (nsrc > 0) | |
1473 | { | |
1474 | /* Mask for removing bits of the next source byte that are not | |
1475 | * part of the value. */ | |
d2e4a39e AS |
1476 | unsigned int unusedMSMask = |
1477 | (1 << (srcBitsLeft >= HOST_CHAR_BIT ? HOST_CHAR_BIT : srcBitsLeft)) - | |
1478 | 1; | |
14f9c5c9 AS |
1479 | /* Sign-extend bits for this byte. */ |
1480 | unsigned int signMask = sign & ~unusedMSMask; | |
d2e4a39e | 1481 | accum |= |
14f9c5c9 AS |
1482 | (((bytes[src] >> unusedLS) & unusedMSMask) | signMask) << accumSize; |
1483 | accumSize += HOST_CHAR_BIT - unusedLS; | |
d2e4a39e | 1484 | if (accumSize >= HOST_CHAR_BIT) |
14f9c5c9 AS |
1485 | { |
1486 | unpacked[targ] = accum & ~(~0L << HOST_CHAR_BIT); | |
1487 | accumSize -= HOST_CHAR_BIT; | |
1488 | accum >>= HOST_CHAR_BIT; | |
1489 | ntarg -= 1; | |
1490 | targ += delta; | |
1491 | } | |
1492 | srcBitsLeft -= HOST_CHAR_BIT - unusedLS; | |
1493 | unusedLS = 0; | |
1494 | nsrc -= 1; | |
1495 | src += delta; | |
1496 | } | |
1497 | while (ntarg > 0) | |
1498 | { | |
1499 | accum |= sign << accumSize; | |
1500 | unpacked[targ] = accum & ~(~0L << HOST_CHAR_BIT); | |
1501 | accumSize -= HOST_CHAR_BIT; | |
1502 | accum >>= HOST_CHAR_BIT; | |
1503 | ntarg -= 1; | |
1504 | targ += delta; | |
1505 | } | |
1506 | ||
1507 | return v; | |
1508 | } | |
d2e4a39e | 1509 | |
14f9c5c9 AS |
1510 | /* Move N bits from SOURCE, starting at bit offset SRC_OFFSET to |
1511 | TARGET, starting at bit offset TARG_OFFSET. SOURCE and TARGET must | |
1512 | not overlap. */ | |
1513 | static void | |
d2e4a39e | 1514 | move_bits (char *target, int targ_offset, char *source, int src_offset, int n) |
14f9c5c9 AS |
1515 | { |
1516 | unsigned int accum, mask; | |
1517 | int accum_bits, chunk_size; | |
1518 | ||
1519 | target += targ_offset / HOST_CHAR_BIT; | |
1520 | targ_offset %= HOST_CHAR_BIT; | |
1521 | source += src_offset / HOST_CHAR_BIT; | |
1522 | src_offset %= HOST_CHAR_BIT; | |
d2e4a39e | 1523 | if (BITS_BIG_ENDIAN) |
14f9c5c9 AS |
1524 | { |
1525 | accum = (unsigned char) *source; | |
1526 | source += 1; | |
1527 | accum_bits = HOST_CHAR_BIT - src_offset; | |
1528 | ||
d2e4a39e | 1529 | while (n > 0) |
14f9c5c9 AS |
1530 | { |
1531 | int unused_right; | |
1532 | accum = (accum << HOST_CHAR_BIT) + (unsigned char) *source; | |
1533 | accum_bits += HOST_CHAR_BIT; | |
1534 | source += 1; | |
1535 | chunk_size = HOST_CHAR_BIT - targ_offset; | |
1536 | if (chunk_size > n) | |
1537 | chunk_size = n; | |
1538 | unused_right = HOST_CHAR_BIT - (chunk_size + targ_offset); | |
1539 | mask = ((1 << chunk_size) - 1) << unused_right; | |
d2e4a39e AS |
1540 | *target = |
1541 | (*target & ~mask) | |
14f9c5c9 AS |
1542 | | ((accum >> (accum_bits - chunk_size - unused_right)) & mask); |
1543 | n -= chunk_size; | |
1544 | accum_bits -= chunk_size; | |
1545 | target += 1; | |
1546 | targ_offset = 0; | |
1547 | } | |
1548 | } | |
1549 | else | |
1550 | { | |
1551 | accum = (unsigned char) *source >> src_offset; | |
1552 | source += 1; | |
1553 | accum_bits = HOST_CHAR_BIT - src_offset; | |
1554 | ||
d2e4a39e | 1555 | while (n > 0) |
14f9c5c9 AS |
1556 | { |
1557 | accum = accum + ((unsigned char) *source << accum_bits); | |
1558 | accum_bits += HOST_CHAR_BIT; | |
1559 | source += 1; | |
1560 | chunk_size = HOST_CHAR_BIT - targ_offset; | |
1561 | if (chunk_size > n) | |
1562 | chunk_size = n; | |
1563 | mask = ((1 << chunk_size) - 1) << targ_offset; | |
d2e4a39e | 1564 | *target = (*target & ~mask) | ((accum << targ_offset) & mask); |
14f9c5c9 AS |
1565 | n -= chunk_size; |
1566 | accum_bits -= chunk_size; | |
1567 | accum >>= chunk_size; | |
1568 | target += 1; | |
1569 | targ_offset = 0; | |
1570 | } | |
1571 | } | |
1572 | } | |
1573 | ||
1574 | ||
1575 | /* Store the contents of FROMVAL into the location of TOVAL. | |
1576 | Return a new value with the location of TOVAL and contents of | |
1577 | FROMVAL. Handles assignment into packed fields that have | |
1578 | floating-point or non-scalar types. */ | |
1579 | ||
d2e4a39e AS |
1580 | static struct value * |
1581 | ada_value_assign (struct value *toval, struct value *fromval) | |
14f9c5c9 | 1582 | { |
d2e4a39e | 1583 | struct type *type = VALUE_TYPE (toval); |
14f9c5c9 AS |
1584 | int bits = VALUE_BITSIZE (toval); |
1585 | ||
1586 | if (!toval->modifiable) | |
1587 | error ("Left operand of assignment is not a modifiable lvalue."); | |
1588 | ||
1589 | COERCE_REF (toval); | |
1590 | ||
d2e4a39e | 1591 | if (VALUE_LVAL (toval) == lval_memory |
14f9c5c9 | 1592 | && bits > 0 |
d2e4a39e | 1593 | && (TYPE_CODE (type) == TYPE_CODE_FLT |
14f9c5c9 AS |
1594 | || TYPE_CODE (type) == TYPE_CODE_STRUCT)) |
1595 | { | |
d2e4a39e AS |
1596 | int len = |
1597 | (VALUE_BITPOS (toval) + bits + HOST_CHAR_BIT - 1) / HOST_CHAR_BIT; | |
1598 | char *buffer = (char *) alloca (len); | |
1599 | struct value *val; | |
14f9c5c9 AS |
1600 | |
1601 | if (TYPE_CODE (type) == TYPE_CODE_FLT) | |
1602 | fromval = value_cast (type, fromval); | |
1603 | ||
1604 | read_memory (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval), buffer, len); | |
1605 | if (BITS_BIG_ENDIAN) | |
d2e4a39e AS |
1606 | move_bits (buffer, VALUE_BITPOS (toval), |
1607 | VALUE_CONTENTS (fromval), | |
1608 | TYPE_LENGTH (VALUE_TYPE (fromval)) * TARGET_CHAR_BIT - | |
1609 | bits, bits); | |
14f9c5c9 | 1610 | else |
d2e4a39e | 1611 | move_bits (buffer, VALUE_BITPOS (toval), VALUE_CONTENTS (fromval), |
14f9c5c9 | 1612 | 0, bits); |
d2e4a39e AS |
1613 | write_memory (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval), buffer, |
1614 | len); | |
14f9c5c9 AS |
1615 | |
1616 | val = value_copy (toval); | |
1617 | memcpy (VALUE_CONTENTS_RAW (val), VALUE_CONTENTS (fromval), | |
1618 | TYPE_LENGTH (type)); | |
1619 | VALUE_TYPE (val) = type; | |
d2e4a39e | 1620 | |
14f9c5c9 AS |
1621 | return val; |
1622 | } | |
1623 | ||
1624 | return value_assign (toval, fromval); | |
1625 | } | |
1626 | ||
1627 | ||
1628 | /* The value of the element of array ARR at the ARITY indices given in IND. | |
1629 | ARR may be either a simple array, GNAT array descriptor, or pointer | |
1630 | thereto. */ | |
1631 | ||
d2e4a39e AS |
1632 | struct value * |
1633 | ada_value_subscript (struct value *arr, int arity, struct value **ind) | |
14f9c5c9 AS |
1634 | { |
1635 | int k; | |
d2e4a39e AS |
1636 | struct value *elt; |
1637 | struct type *elt_type; | |
14f9c5c9 AS |
1638 | |
1639 | elt = ada_coerce_to_simple_array (arr); | |
1640 | ||
1641 | elt_type = check_typedef (VALUE_TYPE (elt)); | |
d2e4a39e | 1642 | if (TYPE_CODE (elt_type) == TYPE_CODE_ARRAY |
14f9c5c9 AS |
1643 | && TYPE_FIELD_BITSIZE (elt_type, 0) > 0) |
1644 | return value_subscript_packed (elt, arity, ind); | |
1645 | ||
1646 | for (k = 0; k < arity; k += 1) | |
1647 | { | |
1648 | if (TYPE_CODE (elt_type) != TYPE_CODE_ARRAY) | |
d2e4a39e | 1649 | error ("too many subscripts (%d expected)", k); |
14f9c5c9 AS |
1650 | elt = value_subscript (elt, value_pos_atr (ind[k])); |
1651 | } | |
1652 | return elt; | |
1653 | } | |
1654 | ||
1655 | /* Assuming ARR is a pointer to a standard GDB array of type TYPE, the | |
1656 | value of the element of *ARR at the ARITY indices given in | |
1657 | IND. Does not read the entire array into memory. */ | |
1658 | ||
d2e4a39e AS |
1659 | struct value * |
1660 | ada_value_ptr_subscript (struct value *arr, struct type *type, int arity, | |
1661 | struct value **ind) | |
14f9c5c9 AS |
1662 | { |
1663 | int k; | |
1664 | ||
1665 | for (k = 0; k < arity; k += 1) | |
1666 | { | |
1667 | LONGEST lwb, upb; | |
d2e4a39e | 1668 | struct value *idx; |
14f9c5c9 AS |
1669 | |
1670 | if (TYPE_CODE (type) != TYPE_CODE_ARRAY) | |
d2e4a39e AS |
1671 | error ("too many subscripts (%d expected)", k); |
1672 | arr = value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (type)), | |
14f9c5c9 AS |
1673 | value_copy (arr)); |
1674 | get_discrete_bounds (TYPE_INDEX_TYPE (type), &lwb, &upb); | |
d2e4a39e | 1675 | if (lwb == 0) |
14f9c5c9 AS |
1676 | idx = ind[k]; |
1677 | else | |
1678 | idx = value_sub (ind[k], value_from_longest (builtin_type_int, lwb)); | |
1679 | arr = value_add (arr, idx); | |
1680 | type = TYPE_TARGET_TYPE (type); | |
1681 | } | |
1682 | ||
1683 | return value_ind (arr); | |
1684 | } | |
1685 | ||
1686 | /* If type is a record type in the form of a standard GNAT array | |
1687 | descriptor, returns the number of dimensions for type. If arr is a | |
1688 | simple array, returns the number of "array of"s that prefix its | |
1689 | type designation. Otherwise, returns 0. */ | |
1690 | ||
1691 | int | |
d2e4a39e | 1692 | ada_array_arity (struct type *type) |
14f9c5c9 AS |
1693 | { |
1694 | int arity; | |
1695 | ||
1696 | if (type == NULL) | |
1697 | return 0; | |
1698 | ||
1699 | type = desc_base_type (type); | |
1700 | ||
1701 | arity = 0; | |
d2e4a39e | 1702 | if (TYPE_CODE (type) == TYPE_CODE_STRUCT) |
14f9c5c9 | 1703 | return desc_arity (desc_bounds_type (type)); |
d2e4a39e AS |
1704 | else |
1705 | while (TYPE_CODE (type) == TYPE_CODE_ARRAY) | |
14f9c5c9 AS |
1706 | { |
1707 | arity += 1; | |
1708 | type = check_typedef (TYPE_TARGET_TYPE (type)); | |
1709 | } | |
d2e4a39e | 1710 | |
14f9c5c9 AS |
1711 | return arity; |
1712 | } | |
1713 | ||
1714 | /* If TYPE is a record type in the form of a standard GNAT array | |
1715 | descriptor or a simple array type, returns the element type for | |
1716 | TYPE after indexing by NINDICES indices, or by all indices if | |
1717 | NINDICES is -1. Otherwise, returns NULL. */ | |
1718 | ||
d2e4a39e AS |
1719 | struct type * |
1720 | ada_array_element_type (struct type *type, int nindices) | |
14f9c5c9 AS |
1721 | { |
1722 | type = desc_base_type (type); | |
1723 | ||
d2e4a39e | 1724 | if (TYPE_CODE (type) == TYPE_CODE_STRUCT) |
14f9c5c9 AS |
1725 | { |
1726 | int k; | |
d2e4a39e | 1727 | struct type *p_array_type; |
14f9c5c9 AS |
1728 | |
1729 | p_array_type = desc_data_type (type); | |
1730 | ||
1731 | k = ada_array_arity (type); | |
1732 | if (k == 0) | |
1733 | return NULL; | |
d2e4a39e | 1734 | |
14f9c5c9 AS |
1735 | /* Initially p_array_type = elt_type(*)[]...(k times)...[] */ |
1736 | if (nindices >= 0 && k > nindices) | |
1737 | k = nindices; | |
1738 | p_array_type = TYPE_TARGET_TYPE (p_array_type); | |
d2e4a39e | 1739 | while (k > 0 && p_array_type != NULL) |
14f9c5c9 AS |
1740 | { |
1741 | p_array_type = check_typedef (TYPE_TARGET_TYPE (p_array_type)); | |
1742 | k -= 1; | |
1743 | } | |
1744 | return p_array_type; | |
1745 | } | |
1746 | else if (TYPE_CODE (type) == TYPE_CODE_ARRAY) | |
1747 | { | |
1748 | while (nindices != 0 && TYPE_CODE (type) == TYPE_CODE_ARRAY) | |
1749 | { | |
1750 | type = TYPE_TARGET_TYPE (type); | |
1751 | nindices -= 1; | |
1752 | } | |
1753 | return type; | |
1754 | } | |
1755 | ||
1756 | return NULL; | |
1757 | } | |
1758 | ||
1759 | /* The type of nth index in arrays of given type (n numbering from 1). Does | |
1760 | not examine memory. */ | |
1761 | ||
d2e4a39e AS |
1762 | struct type * |
1763 | ada_index_type (struct type *type, int n) | |
14f9c5c9 AS |
1764 | { |
1765 | type = desc_base_type (type); | |
1766 | ||
1767 | if (n > ada_array_arity (type)) | |
1768 | return NULL; | |
1769 | ||
1770 | if (ada_is_simple_array (type)) | |
1771 | { | |
1772 | int i; | |
1773 | ||
1774 | for (i = 1; i < n; i += 1) | |
1775 | type = TYPE_TARGET_TYPE (type); | |
1776 | ||
1777 | return TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, 0)); | |
1778 | } | |
d2e4a39e | 1779 | else |
14f9c5c9 AS |
1780 | return desc_index_type (desc_bounds_type (type), n); |
1781 | } | |
1782 | ||
1783 | /* Given that arr is an array type, returns the lower bound of the | |
1784 | Nth index (numbering from 1) if WHICH is 0, and the upper bound if | |
1785 | WHICH is 1. This returns bounds 0 .. -1 if ARR_TYPE is an | |
1786 | array-descriptor type. If TYPEP is non-null, *TYPEP is set to the | |
1787 | bounds type. It works for other arrays with bounds supplied by | |
1788 | run-time quantities other than discriminants. */ | |
1789 | ||
1790 | LONGEST | |
d2e4a39e AS |
1791 | ada_array_bound_from_type (struct type * arr_type, int n, int which, |
1792 | struct type ** typep) | |
14f9c5c9 | 1793 | { |
d2e4a39e AS |
1794 | struct type *type; |
1795 | struct type *index_type_desc; | |
14f9c5c9 AS |
1796 | |
1797 | if (ada_is_packed_array_type (arr_type)) | |
1798 | arr_type = decode_packed_array_type (arr_type); | |
1799 | ||
d2e4a39e | 1800 | if (arr_type == NULL || !ada_is_simple_array (arr_type)) |
14f9c5c9 AS |
1801 | { |
1802 | if (typep != NULL) | |
1803 | *typep = builtin_type_int; | |
d2e4a39e | 1804 | return (LONGEST) - which; |
14f9c5c9 AS |
1805 | } |
1806 | ||
1807 | if (TYPE_CODE (arr_type) == TYPE_CODE_PTR) | |
1808 | type = TYPE_TARGET_TYPE (arr_type); | |
1809 | else | |
1810 | type = arr_type; | |
1811 | ||
1812 | index_type_desc = ada_find_parallel_type (type, "___XA"); | |
d2e4a39e | 1813 | if (index_type_desc == NULL) |
14f9c5c9 | 1814 | { |
d2e4a39e AS |
1815 | struct type *range_type; |
1816 | struct type *index_type; | |
14f9c5c9 | 1817 | |
d2e4a39e | 1818 | while (n > 1) |
14f9c5c9 AS |
1819 | { |
1820 | type = TYPE_TARGET_TYPE (type); | |
1821 | n -= 1; | |
1822 | } | |
1823 | ||
1824 | range_type = TYPE_INDEX_TYPE (type); | |
1825 | index_type = TYPE_TARGET_TYPE (range_type); | |
1826 | if (TYPE_CODE (index_type) == TYPE_CODE_UNDEF) | |
d2e4a39e | 1827 | index_type = builtin_type_long; |
14f9c5c9 AS |
1828 | if (typep != NULL) |
1829 | *typep = index_type; | |
d2e4a39e AS |
1830 | return |
1831 | (LONGEST) (which == 0 | |
14f9c5c9 AS |
1832 | ? TYPE_LOW_BOUND (range_type) |
1833 | : TYPE_HIGH_BOUND (range_type)); | |
1834 | } | |
d2e4a39e | 1835 | else |
14f9c5c9 | 1836 | { |
d2e4a39e AS |
1837 | struct type *index_type = |
1838 | to_fixed_range_type (TYPE_FIELD_NAME (index_type_desc, n - 1), | |
14f9c5c9 AS |
1839 | NULL, TYPE_OBJFILE (arr_type)); |
1840 | if (typep != NULL) | |
1841 | *typep = TYPE_TARGET_TYPE (index_type); | |
d2e4a39e AS |
1842 | return |
1843 | (LONGEST) (which == 0 | |
14f9c5c9 AS |
1844 | ? TYPE_LOW_BOUND (index_type) |
1845 | : TYPE_HIGH_BOUND (index_type)); | |
1846 | } | |
1847 | } | |
1848 | ||
1849 | /* Given that arr is an array value, returns the lower bound of the | |
1850 | nth index (numbering from 1) if which is 0, and the upper bound if | |
1851 | which is 1. This routine will also work for arrays with bounds | |
1852 | supplied by run-time quantities other than discriminants. */ | |
1853 | ||
d2e4a39e | 1854 | struct value * |
14f9c5c9 | 1855 | ada_array_bound (arr, n, which) |
d2e4a39e AS |
1856 | struct value *arr; |
1857 | int n; | |
14f9c5c9 AS |
1858 | int which; |
1859 | { | |
d2e4a39e | 1860 | struct type *arr_type = VALUE_TYPE (arr); |
14f9c5c9 AS |
1861 | |
1862 | if (ada_is_packed_array_type (arr_type)) | |
1863 | return ada_array_bound (decode_packed_array (arr), n, which); | |
d2e4a39e | 1864 | else if (ada_is_simple_array (arr_type)) |
14f9c5c9 | 1865 | { |
d2e4a39e | 1866 | struct type *type; |
14f9c5c9 AS |
1867 | LONGEST v = ada_array_bound_from_type (arr_type, n, which, &type); |
1868 | return value_from_longest (type, v); | |
1869 | } | |
1870 | else | |
1871 | return desc_one_bound (desc_bounds (arr), n, which); | |
1872 | } | |
1873 | ||
1874 | /* Given that arr is an array value, returns the length of the | |
1875 | nth index. This routine will also work for arrays with bounds | |
1876 | supplied by run-time quantities other than discriminants. Does not | |
1877 | work for arrays indexed by enumeration types with representation | |
d2e4a39e | 1878 | clauses at the moment. */ |
14f9c5c9 | 1879 | |
d2e4a39e AS |
1880 | struct value * |
1881 | ada_array_length (struct value *arr, int n) | |
14f9c5c9 | 1882 | { |
d2e4a39e AS |
1883 | struct type *arr_type = check_typedef (VALUE_TYPE (arr)); |
1884 | struct type *index_type_desc; | |
14f9c5c9 AS |
1885 | |
1886 | if (ada_is_packed_array_type (arr_type)) | |
1887 | return ada_array_length (decode_packed_array (arr), n); | |
1888 | ||
1889 | if (ada_is_simple_array (arr_type)) | |
1890 | { | |
d2e4a39e | 1891 | struct type *type; |
14f9c5c9 AS |
1892 | LONGEST v = |
1893 | ada_array_bound_from_type (arr_type, n, 1, &type) - | |
1894 | ada_array_bound_from_type (arr_type, n, 0, NULL) + 1; | |
1895 | return value_from_longest (type, v); | |
1896 | } | |
1897 | else | |
d2e4a39e | 1898 | return |
14f9c5c9 AS |
1899 | value_from_longest (builtin_type_ada_int, |
1900 | value_as_long (desc_one_bound (desc_bounds (arr), | |
1901 | n, 1)) | |
1902 | - value_as_long (desc_one_bound (desc_bounds (arr), | |
d2e4a39e | 1903 | n, 0)) + 1); |
14f9c5c9 | 1904 | } |
14f9c5c9 | 1905 | \f |
d2e4a39e | 1906 | |
14f9c5c9 AS |
1907 | /* Name resolution */ |
1908 | ||
1909 | /* The "demangled" name for the user-definable Ada operator corresponding | |
1910 | to op. */ | |
1911 | ||
d2e4a39e | 1912 | static const char * |
ebf56fd3 | 1913 | ada_op_name (enum exp_opcode op) |
14f9c5c9 AS |
1914 | { |
1915 | int i; | |
1916 | ||
1917 | for (i = 0; ada_opname_table[i].mangled != NULL; i += 1) | |
1918 | { | |
1919 | if (ada_opname_table[i].op == op) | |
1920 | return ada_opname_table[i].demangled; | |
1921 | } | |
1922 | error ("Could not find operator name for opcode"); | |
1923 | } | |
1924 | ||
1925 | ||
1926 | /* Same as evaluate_type (*EXP), but resolves ambiguous symbol | |
1927 | references (OP_UNRESOLVED_VALUES) and converts operators that are | |
1928 | user-defined into appropriate function calls. If CONTEXT_TYPE is | |
1929 | non-null, it provides a preferred result type [at the moment, only | |
1930 | type void has any effect---causing procedures to be preferred over | |
1931 | functions in calls]. A null CONTEXT_TYPE indicates that a non-void | |
1932 | return type is preferred. The variable unresolved_names contains a list | |
1933 | of character strings referenced by expout that should be freed. | |
1934 | May change (expand) *EXP. */ | |
1935 | ||
1936 | void | |
d2e4a39e | 1937 | ada_resolve (struct expression **expp, struct type *context_type) |
14f9c5c9 AS |
1938 | { |
1939 | int pc; | |
1940 | pc = 0; | |
1941 | ada_resolve_subexp (expp, &pc, 1, context_type); | |
1942 | } | |
1943 | ||
1944 | /* Resolve the operator of the subexpression beginning at | |
1945 | position *POS of *EXPP. "Resolving" consists of replacing | |
1946 | OP_UNRESOLVED_VALUE with an appropriate OP_VAR_VALUE, replacing | |
1947 | built-in operators with function calls to user-defined operators, | |
1948 | where appropriate, and (when DEPROCEDURE_P is non-zero), converting | |
1949 | function-valued variables into parameterless calls. May expand | |
1950 | EXP. The CONTEXT_TYPE functions as in ada_resolve, above. */ | |
1951 | ||
d2e4a39e AS |
1952 | static struct value * |
1953 | ada_resolve_subexp (struct expression **expp, int *pos, int deprocedure_p, | |
1954 | struct type *context_type) | |
14f9c5c9 AS |
1955 | { |
1956 | int pc = *pos; | |
1957 | int i; | |
d2e4a39e | 1958 | struct expression *exp; /* Convenience: == *expp */ |
14f9c5c9 | 1959 | enum exp_opcode op = (*expp)->elts[pc].opcode; |
d2e4a39e | 1960 | struct value **argvec; /* Vector of operand types (alloca'ed). */ |
14f9c5c9 AS |
1961 | int nargs; /* Number of operands */ |
1962 | ||
1963 | argvec = NULL; | |
1964 | nargs = 0; | |
1965 | exp = *expp; | |
1966 | ||
1967 | /* Pass one: resolve operands, saving their types and updating *pos. */ | |
1968 | switch (op) | |
1969 | { | |
1970 | case OP_VAR_VALUE: | |
d2e4a39e | 1971 | /* case OP_UNRESOLVED_VALUE: */ |
14f9c5c9 AS |
1972 | /* FIXME: OP_UNRESOLVED_VALUE should be defined in expression.h */ |
1973 | *pos += 4; | |
1974 | break; | |
1975 | ||
1976 | case OP_FUNCALL: | |
1977 | nargs = longest_to_int (exp->elts[pc + 1].longconst) + 1; | |
1978 | /* FIXME: OP_UNRESOLVED_VALUE should be defined in expression.h */ | |
d2e4a39e AS |
1979 | /* if (exp->elts[pc+3].opcode == OP_UNRESOLVED_VALUE) |
1980 | { | |
1981 | *pos += 7; | |
1982 | ||
1983 | argvec = (struct value* *) alloca (sizeof (struct value*) * (nargs + 1)); | |
1984 | for (i = 0; i < nargs-1; i += 1) | |
1985 | argvec[i] = ada_resolve_subexp (expp, pos, 1, NULL); | |
1986 | argvec[i] = NULL; | |
1987 | } | |
1988 | else | |
1989 | { | |
1990 | *pos += 3; | |
1991 | ada_resolve_subexp (expp, pos, 0, NULL); | |
1992 | for (i = 1; i < nargs; i += 1) | |
1993 | ada_resolve_subexp (expp, pos, 1, NULL); | |
1994 | } | |
1995 | */ | |
14f9c5c9 AS |
1996 | exp = *expp; |
1997 | break; | |
1998 | ||
1999 | /* FIXME: UNOP_QUAL should be defined in expression.h */ | |
2000 | /* case UNOP_QUAL: | |
d2e4a39e AS |
2001 | nargs = 1; |
2002 | *pos += 3; | |
2003 | ada_resolve_subexp (expp, pos, 1, exp->elts[pc + 1].type); | |
2004 | exp = *expp; | |
2005 | break; | |
2006 | */ | |
2007 | /* FIXME: OP_ATTRIBUTE should be defined in expression.h */ | |
14f9c5c9 | 2008 | /* case OP_ATTRIBUTE: |
d2e4a39e AS |
2009 | nargs = longest_to_int (exp->elts[pc + 1].longconst) + 1; |
2010 | *pos += 4; | |
2011 | for (i = 0; i < nargs; i += 1) | |
2012 | ada_resolve_subexp (expp, pos, 1, NULL); | |
2013 | exp = *expp; | |
2014 | break; | |
2015 | */ | |
14f9c5c9 AS |
2016 | case UNOP_ADDR: |
2017 | nargs = 1; | |
2018 | *pos += 1; | |
2019 | ada_resolve_subexp (expp, pos, 0, NULL); | |
2020 | exp = *expp; | |
2021 | break; | |
2022 | ||
2023 | case BINOP_ASSIGN: | |
2024 | { | |
d2e4a39e | 2025 | struct value *arg1; |
14f9c5c9 AS |
2026 | nargs = 2; |
2027 | *pos += 1; | |
2028 | arg1 = ada_resolve_subexp (expp, pos, 0, NULL); | |
2029 | if (arg1 == NULL) | |
2030 | ada_resolve_subexp (expp, pos, 1, NULL); | |
2031 | else | |
2032 | ada_resolve_subexp (expp, pos, 1, VALUE_TYPE (arg1)); | |
2033 | break; | |
2034 | } | |
2035 | ||
2036 | default: | |
d2e4a39e | 2037 | switch (op) |
14f9c5c9 AS |
2038 | { |
2039 | default: | |
2040 | error ("Unexpected operator during name resolution"); | |
2041 | case UNOP_CAST: | |
d2e4a39e AS |
2042 | /* case UNOP_MBR: |
2043 | nargs = 1; | |
2044 | *pos += 3; | |
2045 | break; | |
2046 | */ | |
14f9c5c9 AS |
2047 | case BINOP_ADD: |
2048 | case BINOP_SUB: | |
2049 | case BINOP_MUL: | |
2050 | case BINOP_DIV: | |
2051 | case BINOP_REM: | |
2052 | case BINOP_MOD: | |
2053 | case BINOP_EXP: | |
2054 | case BINOP_CONCAT: | |
2055 | case BINOP_LOGICAL_AND: | |
2056 | case BINOP_LOGICAL_OR: | |
2057 | case BINOP_BITWISE_AND: | |
2058 | case BINOP_BITWISE_IOR: | |
2059 | case BINOP_BITWISE_XOR: | |
2060 | ||
2061 | case BINOP_EQUAL: | |
2062 | case BINOP_NOTEQUAL: | |
2063 | case BINOP_LESS: | |
2064 | case BINOP_GTR: | |
2065 | case BINOP_LEQ: | |
2066 | case BINOP_GEQ: | |
2067 | ||
2068 | case BINOP_REPEAT: | |
2069 | case BINOP_SUBSCRIPT: | |
2070 | case BINOP_COMMA: | |
2071 | nargs = 2; | |
2072 | *pos += 1; | |
2073 | break; | |
2074 | ||
2075 | case UNOP_NEG: | |
2076 | case UNOP_PLUS: | |
2077 | case UNOP_LOGICAL_NOT: | |
2078 | case UNOP_ABS: | |
2079 | case UNOP_IND: | |
2080 | nargs = 1; | |
2081 | *pos += 1; | |
2082 | break; | |
2083 | ||
2084 | case OP_LONG: | |
2085 | case OP_DOUBLE: | |
2086 | case OP_VAR_VALUE: | |
2087 | *pos += 4; | |
2088 | break; | |
2089 | ||
2090 | case OP_TYPE: | |
2091 | case OP_BOOL: | |
2092 | case OP_LAST: | |
2093 | case OP_REGISTER: | |
2094 | case OP_INTERNALVAR: | |
2095 | *pos += 3; | |
2096 | break; | |
2097 | ||
2098 | case UNOP_MEMVAL: | |
2099 | *pos += 3; | |
2100 | nargs = 1; | |
2101 | break; | |
2102 | ||
2103 | case STRUCTOP_STRUCT: | |
2104 | case STRUCTOP_PTR: | |
2105 | nargs = 1; | |
2106 | *pos += 4 + BYTES_TO_EXP_ELEM (exp->elts[pc + 1].longconst + 1); | |
2107 | break; | |
2108 | ||
2109 | case OP_ARRAY: | |
d2e4a39e | 2110 | *pos += 4; |
14f9c5c9 AS |
2111 | nargs = longest_to_int (exp->elts[pc + 2].longconst) + 1; |
2112 | nargs -= longest_to_int (exp->elts[pc + 1].longconst); | |
2113 | /* A null array contains one dummy element to give the type. */ | |
d2e4a39e AS |
2114 | /* if (nargs == 0) |
2115 | nargs = 1; | |
2116 | break; */ | |
14f9c5c9 AS |
2117 | |
2118 | case TERNOP_SLICE: | |
2119 | /* FIXME: TERNOP_MBR should be defined in expression.h */ | |
d2e4a39e AS |
2120 | /* case TERNOP_MBR: |
2121 | *pos += 1; | |
2122 | nargs = 3; | |
2123 | break; | |
2124 | */ | |
14f9c5c9 | 2125 | /* FIXME: BINOP_MBR should be defined in expression.h */ |
d2e4a39e AS |
2126 | /* case BINOP_MBR: |
2127 | *pos += 3; | |
2128 | nargs = 2; | |
2129 | break; */ | |
14f9c5c9 AS |
2130 | } |
2131 | ||
d2e4a39e AS |
2132 | argvec = |
2133 | (struct value * *) alloca (sizeof (struct value *) * (nargs + 1)); | |
14f9c5c9 AS |
2134 | for (i = 0; i < nargs; i += 1) |
2135 | argvec[i] = ada_resolve_subexp (expp, pos, 1, NULL); | |
2136 | argvec[i] = NULL; | |
2137 | exp = *expp; | |
2138 | break; | |
2139 | } | |
2140 | ||
2141 | /* Pass two: perform any resolution on principal operator. */ | |
2142 | switch (op) | |
2143 | { | |
2144 | default: | |
2145 | break; | |
2146 | ||
2147 | /* FIXME: OP_UNRESOLVED_VALUE should be defined in expression.h */ | |
2148 | /* case OP_UNRESOLVED_VALUE: | |
d2e4a39e AS |
2149 | { |
2150 | struct symbol** candidate_syms; | |
2151 | struct block** candidate_blocks; | |
2152 | int n_candidates; | |
2153 | ||
2154 | n_candidates = ada_lookup_symbol_list (exp->elts[pc + 2].name, | |
2155 | exp->elts[pc + 1].block, | |
2156 | VAR_NAMESPACE, | |
2157 | &candidate_syms, | |
2158 | &candidate_blocks); | |
2159 | ||
2160 | if (n_candidates > 1) | |
2161 | { */ | |
2162 | /* Types tend to get re-introduced locally, so if there | |
2163 | are any local symbols that are not types, first filter | |
2164 | out all types. *//* | |
2165 | int j; | |
2166 | for (j = 0; j < n_candidates; j += 1) | |
2167 | switch (SYMBOL_CLASS (candidate_syms[j])) | |
2168 | { | |
2169 | case LOC_REGISTER: | |
2170 | case LOC_ARG: | |
2171 | case LOC_REF_ARG: | |
2172 | case LOC_REGPARM: | |
2173 | case LOC_REGPARM_ADDR: | |
2174 | case LOC_LOCAL: | |
2175 | case LOC_LOCAL_ARG: | |
2176 | case LOC_BASEREG: | |
2177 | case LOC_BASEREG_ARG: | |
2178 | goto FoundNonType; | |
2179 | default: | |
2180 | break; | |
2181 | } | |
2182 | FoundNonType: | |
2183 | if (j < n_candidates) | |
2184 | { | |
2185 | j = 0; | |
2186 | while (j < n_candidates) | |
2187 | { | |
2188 | if (SYMBOL_CLASS (candidate_syms[j]) == LOC_TYPEDEF) | |
2189 | { | |
2190 | candidate_syms[j] = candidate_syms[n_candidates-1]; | |
2191 | candidate_blocks[j] = candidate_blocks[n_candidates-1]; | |
2192 | n_candidates -= 1; | |
2193 | } | |
2194 | else | |
2195 | j += 1; | |
2196 | } | |
2197 | } | |
2198 | } | |
14f9c5c9 | 2199 | |
d2e4a39e AS |
2200 | if (n_candidates == 0) |
2201 | error ("No definition found for %s", | |
2202 | ada_demangle (exp->elts[pc + 2].name)); | |
2203 | else if (n_candidates == 1) | |
2204 | i = 0; | |
2205 | else if (deprocedure_p | |
2206 | && ! is_nonfunction (candidate_syms, n_candidates)) | |
2207 | { | |
2208 | i = ada_resolve_function (candidate_syms, candidate_blocks, | |
2209 | n_candidates, NULL, 0, | |
2210 | exp->elts[pc + 2].name, context_type); | |
2211 | if (i < 0) | |
2212 | error ("Could not find a match for %s", | |
2213 | ada_demangle (exp->elts[pc + 2].name)); | |
2214 | } | |
2215 | else | |
2216 | { | |
2217 | printf_filtered ("Multiple matches for %s\n", | |
2218 | ada_demangle (exp->elts[pc+2].name)); | |
2219 | user_select_syms (candidate_syms, candidate_blocks, | |
2220 | n_candidates, 1); | |
2221 | i = 0; | |
2222 | } | |
14f9c5c9 | 2223 | |
d2e4a39e AS |
2224 | exp->elts[pc].opcode = exp->elts[pc + 3].opcode = OP_VAR_VALUE; |
2225 | exp->elts[pc + 1].block = candidate_blocks[i]; | |
2226 | exp->elts[pc + 2].symbol = candidate_syms[i]; | |
2227 | if (innermost_block == NULL || | |
2228 | contained_in (candidate_blocks[i], innermost_block)) | |
2229 | innermost_block = candidate_blocks[i]; | |
2230 | } */ | |
14f9c5c9 AS |
2231 | /* FALL THROUGH */ |
2232 | ||
2233 | case OP_VAR_VALUE: | |
d2e4a39e AS |
2234 | if (deprocedure_p && |
2235 | TYPE_CODE (SYMBOL_TYPE (exp->elts[pc + 2].symbol)) == | |
2236 | TYPE_CODE_FUNC) | |
14f9c5c9 | 2237 | { |
d2e4a39e AS |
2238 | replace_operator_with_call (expp, pc, 0, 0, |
2239 | exp->elts[pc + 2].symbol, | |
2240 | exp->elts[pc + 1].block); | |
14f9c5c9 AS |
2241 | exp = *expp; |
2242 | } | |
2243 | break; | |
2244 | ||
2245 | case OP_FUNCALL: | |
2246 | { | |
2247 | /* FIXME: OP_UNRESOLVED_VALUE should be defined in expression.h */ | |
d2e4a39e AS |
2248 | /* if (exp->elts[pc+3].opcode == OP_UNRESOLVED_VALUE) |
2249 | { | |
2250 | struct symbol** candidate_syms; | |
2251 | struct block** candidate_blocks; | |
2252 | int n_candidates; | |
2253 | ||
2254 | n_candidates = ada_lookup_symbol_list (exp->elts[pc + 5].name, | |
2255 | exp->elts[pc + 4].block, | |
2256 | VAR_NAMESPACE, | |
2257 | &candidate_syms, | |
2258 | &candidate_blocks); | |
2259 | if (n_candidates == 1) | |
2260 | i = 0; | |
2261 | else | |
2262 | { | |
2263 | i = ada_resolve_function (candidate_syms, candidate_blocks, | |
2264 | n_candidates, argvec, nargs-1, | |
2265 | exp->elts[pc + 5].name, context_type); | |
2266 | if (i < 0) | |
2267 | error ("Could not find a match for %s", | |
2268 | ada_demangle (exp->elts[pc + 5].name)); | |
2269 | } | |
2270 | ||
2271 | exp->elts[pc + 3].opcode = exp->elts[pc + 6].opcode = OP_VAR_VALUE; | |
2272 | exp->elts[pc + 4].block = candidate_blocks[i]; | |
2273 | exp->elts[pc + 5].symbol = candidate_syms[i]; | |
2274 | if (innermost_block == NULL || | |
2275 | contained_in (candidate_blocks[i], innermost_block)) | |
2276 | innermost_block = candidate_blocks[i]; | |
2277 | } */ | |
14f9c5c9 | 2278 | |
14f9c5c9 AS |
2279 | } |
2280 | break; | |
2281 | case BINOP_ADD: | |
2282 | case BINOP_SUB: | |
2283 | case BINOP_MUL: | |
2284 | case BINOP_DIV: | |
2285 | case BINOP_REM: | |
2286 | case BINOP_MOD: | |
2287 | case BINOP_CONCAT: | |
2288 | case BINOP_BITWISE_AND: | |
2289 | case BINOP_BITWISE_IOR: | |
2290 | case BINOP_BITWISE_XOR: | |
2291 | case BINOP_EQUAL: | |
2292 | case BINOP_NOTEQUAL: | |
2293 | case BINOP_LESS: | |
2294 | case BINOP_GTR: | |
2295 | case BINOP_LEQ: | |
2296 | case BINOP_GEQ: | |
2297 | case BINOP_EXP: | |
2298 | case UNOP_NEG: | |
2299 | case UNOP_PLUS: | |
2300 | case UNOP_LOGICAL_NOT: | |
2301 | case UNOP_ABS: | |
2302 | if (possible_user_operator_p (op, argvec)) | |
2303 | { | |
d2e4a39e AS |
2304 | struct symbol **candidate_syms; |
2305 | struct block **candidate_blocks; | |
14f9c5c9 AS |
2306 | int n_candidates; |
2307 | ||
d2e4a39e AS |
2308 | n_candidates = |
2309 | ada_lookup_symbol_list (ada_mangle (ada_op_name (op)), | |
2310 | (struct block *) NULL, VAR_NAMESPACE, | |
2311 | &candidate_syms, &candidate_blocks); | |
2312 | i = | |
2313 | ada_resolve_function (candidate_syms, candidate_blocks, | |
2314 | n_candidates, argvec, nargs, | |
2315 | ada_op_name (op), NULL); | |
14f9c5c9 AS |
2316 | if (i < 0) |
2317 | break; | |
2318 | ||
2319 | replace_operator_with_call (expp, pc, nargs, 1, | |
2320 | candidate_syms[i], candidate_blocks[i]); | |
2321 | exp = *expp; | |
2322 | } | |
2323 | break; | |
2324 | } | |
2325 | ||
2326 | *pos = pc; | |
2327 | return evaluate_subexp_type (exp, pos); | |
2328 | } | |
2329 | ||
2330 | /* Return non-zero if formal type FTYPE matches actual type ATYPE. If | |
2331 | MAY_DEREF is non-zero, the formal may be a pointer and the actual | |
d2e4a39e | 2332 | a non-pointer. */ |
14f9c5c9 AS |
2333 | /* The term "match" here is rather loose. The match is heuristic and |
2334 | liberal. FIXME: TOO liberal, in fact. */ | |
2335 | ||
2336 | static int | |
2337 | ada_type_match (ftype, atype, may_deref) | |
d2e4a39e AS |
2338 | struct type *ftype; |
2339 | struct type *atype; | |
14f9c5c9 AS |
2340 | int may_deref; |
2341 | { | |
2342 | CHECK_TYPEDEF (ftype); | |
2343 | CHECK_TYPEDEF (atype); | |
2344 | ||
2345 | if (TYPE_CODE (ftype) == TYPE_CODE_REF) | |
2346 | ftype = TYPE_TARGET_TYPE (ftype); | |
2347 | if (TYPE_CODE (atype) == TYPE_CODE_REF) | |
2348 | atype = TYPE_TARGET_TYPE (atype); | |
2349 | ||
d2e4a39e | 2350 | if (TYPE_CODE (ftype) == TYPE_CODE_VOID |
14f9c5c9 AS |
2351 | || TYPE_CODE (atype) == TYPE_CODE_VOID) |
2352 | return 1; | |
2353 | ||
d2e4a39e | 2354 | switch (TYPE_CODE (ftype)) |
14f9c5c9 AS |
2355 | { |
2356 | default: | |
2357 | return 1; | |
2358 | case TYPE_CODE_PTR: | |
2359 | if (TYPE_CODE (atype) == TYPE_CODE_PTR) | |
2360 | return ada_type_match (TYPE_TARGET_TYPE (ftype), | |
2361 | TYPE_TARGET_TYPE (atype), 0); | |
d2e4a39e AS |
2362 | else |
2363 | return (may_deref && | |
2364 | ada_type_match (TYPE_TARGET_TYPE (ftype), atype, 0)); | |
14f9c5c9 AS |
2365 | case TYPE_CODE_INT: |
2366 | case TYPE_CODE_ENUM: | |
2367 | case TYPE_CODE_RANGE: | |
2368 | switch (TYPE_CODE (atype)) | |
2369 | { | |
2370 | case TYPE_CODE_INT: | |
2371 | case TYPE_CODE_ENUM: | |
2372 | case TYPE_CODE_RANGE: | |
2373 | return 1; | |
2374 | default: | |
2375 | return 0; | |
2376 | } | |
2377 | ||
2378 | case TYPE_CODE_ARRAY: | |
d2e4a39e | 2379 | return (TYPE_CODE (atype) == TYPE_CODE_ARRAY |
14f9c5c9 AS |
2380 | || ada_is_array_descriptor (atype)); |
2381 | ||
2382 | case TYPE_CODE_STRUCT: | |
2383 | if (ada_is_array_descriptor (ftype)) | |
d2e4a39e | 2384 | return (TYPE_CODE (atype) == TYPE_CODE_ARRAY |
14f9c5c9 AS |
2385 | || ada_is_array_descriptor (atype)); |
2386 | else | |
2387 | return (TYPE_CODE (atype) == TYPE_CODE_STRUCT | |
d2e4a39e | 2388 | && !ada_is_array_descriptor (atype)); |
14f9c5c9 AS |
2389 | |
2390 | case TYPE_CODE_UNION: | |
2391 | case TYPE_CODE_FLT: | |
2392 | return (TYPE_CODE (atype) == TYPE_CODE (ftype)); | |
2393 | } | |
2394 | } | |
2395 | ||
2396 | /* Return non-zero if the formals of FUNC "sufficiently match" the | |
2397 | vector of actual argument types ACTUALS of size N_ACTUALS. FUNC | |
2398 | may also be an enumeral, in which case it is treated as a 0- | |
2399 | argument function. */ | |
2400 | ||
2401 | static int | |
d2e4a39e | 2402 | ada_args_match (struct symbol *func, struct value **actuals, int n_actuals) |
14f9c5c9 AS |
2403 | { |
2404 | int i; | |
d2e4a39e | 2405 | struct type *func_type = SYMBOL_TYPE (func); |
14f9c5c9 | 2406 | |
d2e4a39e | 2407 | if (SYMBOL_CLASS (func) == LOC_CONST && |
14f9c5c9 AS |
2408 | TYPE_CODE (func_type) == TYPE_CODE_ENUM) |
2409 | return (n_actuals == 0); | |
2410 | else if (func_type == NULL || TYPE_CODE (func_type) != TYPE_CODE_FUNC) | |
2411 | return 0; | |
2412 | ||
2413 | if (TYPE_NFIELDS (func_type) != n_actuals) | |
2414 | return 0; | |
2415 | ||
2416 | for (i = 0; i < n_actuals; i += 1) | |
2417 | { | |
d2e4a39e AS |
2418 | struct type *ftype = check_typedef (TYPE_FIELD_TYPE (func_type, i)); |
2419 | struct type *atype = check_typedef (VALUE_TYPE (actuals[i])); | |
14f9c5c9 | 2420 | |
d2e4a39e AS |
2421 | if (!ada_type_match (TYPE_FIELD_TYPE (func_type, i), |
2422 | VALUE_TYPE (actuals[i]), 1)) | |
14f9c5c9 AS |
2423 | return 0; |
2424 | } | |
2425 | return 1; | |
2426 | } | |
2427 | ||
2428 | /* False iff function type FUNC_TYPE definitely does not produce a value | |
2429 | compatible with type CONTEXT_TYPE. Conservatively returns 1 if | |
2430 | FUNC_TYPE is not a valid function type with a non-null return type | |
2431 | or an enumerated type. A null CONTEXT_TYPE indicates any non-void type. */ | |
2432 | ||
2433 | static int | |
d2e4a39e | 2434 | return_match (struct type *func_type, struct type *context_type) |
14f9c5c9 | 2435 | { |
d2e4a39e | 2436 | struct type *return_type; |
14f9c5c9 AS |
2437 | |
2438 | if (func_type == NULL) | |
2439 | return 1; | |
2440 | ||
2441 | /* FIXME: base_type should be declared in gdbtypes.h, implemented in valarith.c */ | |
2442 | /* if (TYPE_CODE (func_type) == TYPE_CODE_FUNC) | |
d2e4a39e AS |
2443 | return_type = base_type (TYPE_TARGET_TYPE (func_type)); |
2444 | else | |
2445 | return_type = base_type (func_type); */ | |
14f9c5c9 AS |
2446 | if (return_type == NULL) |
2447 | return 1; | |
2448 | ||
2449 | /* FIXME: base_type should be declared in gdbtypes.h, implemented in valarith.c */ | |
d2e4a39e | 2450 | /* context_type = base_type (context_type); */ |
14f9c5c9 AS |
2451 | |
2452 | if (TYPE_CODE (return_type) == TYPE_CODE_ENUM) | |
2453 | return context_type == NULL || return_type == context_type; | |
2454 | else if (context_type == NULL) | |
2455 | return TYPE_CODE (return_type) != TYPE_CODE_VOID; | |
2456 | else | |
2457 | return TYPE_CODE (return_type) == TYPE_CODE (context_type); | |
2458 | } | |
2459 | ||
2460 | ||
2461 | /* Return the index in SYMS[0..NSYMS-1] of symbol for the | |
2462 | function (if any) that matches the types of the NARGS arguments in | |
2463 | ARGS. If CONTEXT_TYPE is non-null, and there is at least one match | |
2464 | that returns type CONTEXT_TYPE, then eliminate other matches. If | |
2465 | CONTEXT_TYPE is null, prefer a non-void-returning function. | |
2466 | Asks the user if there is more than one match remaining. Returns -1 | |
2467 | if there is no such symbol or none is selected. NAME is used | |
2468 | solely for messages. May re-arrange and modify SYMS in | |
2469 | the process; the index returned is for the modified vector. BLOCKS | |
2470 | is modified in parallel to SYMS. */ | |
2471 | ||
2472 | int | |
d2e4a39e AS |
2473 | ada_resolve_function (struct symbol *syms[], struct block *blocks[], |
2474 | int nsyms, struct value **args, int nargs, | |
2475 | const char *name, struct type *context_type) | |
14f9c5c9 AS |
2476 | { |
2477 | int k; | |
2478 | int m; /* Number of hits */ | |
d2e4a39e AS |
2479 | struct type *fallback; |
2480 | struct type *return_type; | |
14f9c5c9 AS |
2481 | |
2482 | return_type = context_type; | |
2483 | if (context_type == NULL) | |
2484 | fallback = builtin_type_void; | |
2485 | else | |
2486 | fallback = NULL; | |
2487 | ||
d2e4a39e | 2488 | m = 0; |
14f9c5c9 AS |
2489 | while (1) |
2490 | { | |
2491 | for (k = 0; k < nsyms; k += 1) | |
2492 | { | |
d2e4a39e | 2493 | struct type *type = check_typedef (SYMBOL_TYPE (syms[k])); |
14f9c5c9 AS |
2494 | |
2495 | if (ada_args_match (syms[k], args, nargs) | |
2496 | && return_match (SYMBOL_TYPE (syms[k]), return_type)) | |
2497 | { | |
2498 | syms[m] = syms[k]; | |
2499 | if (blocks != NULL) | |
2500 | blocks[m] = blocks[k]; | |
2501 | m += 1; | |
2502 | } | |
2503 | } | |
2504 | if (m > 0 || return_type == fallback) | |
2505 | break; | |
2506 | else | |
2507 | return_type = fallback; | |
2508 | } | |
2509 | ||
2510 | if (m == 0) | |
2511 | return -1; | |
2512 | else if (m > 1) | |
2513 | { | |
2514 | printf_filtered ("Multiple matches for %s\n", name); | |
2515 | user_select_syms (syms, blocks, m, 1); | |
2516 | return 0; | |
2517 | } | |
2518 | return 0; | |
2519 | } | |
2520 | ||
2521 | /* Returns true (non-zero) iff demangled name N0 should appear before N1 */ | |
2522 | /* in a listing of choices during disambiguation (see sort_choices, below). */ | |
2523 | /* The idea is that overloadings of a subprogram name from the */ | |
2524 | /* same package should sort in their source order. We settle for ordering */ | |
2525 | /* such symbols by their trailing number (__N or $N). */ | |
2526 | static int | |
d2e4a39e | 2527 | mangled_ordered_before (char *N0, char *N1) |
14f9c5c9 AS |
2528 | { |
2529 | if (N1 == NULL) | |
2530 | return 0; | |
2531 | else if (N0 == NULL) | |
2532 | return 1; | |
2533 | else | |
2534 | { | |
2535 | int k0, k1; | |
d2e4a39e | 2536 | for (k0 = strlen (N0) - 1; k0 > 0 && isdigit (N0[k0]); k0 -= 1) |
14f9c5c9 | 2537 | ; |
d2e4a39e | 2538 | for (k1 = strlen (N1) - 1; k1 > 0 && isdigit (N1[k1]); k1 -= 1) |
14f9c5c9 | 2539 | ; |
d2e4a39e AS |
2540 | if ((N0[k0] == '_' || N0[k0] == '$') && N0[k0 + 1] != '\000' |
2541 | && (N1[k1] == '_' || N1[k1] == '$') && N1[k1 + 1] != '\000') | |
14f9c5c9 AS |
2542 | { |
2543 | int n0, n1; | |
2544 | n0 = k0; | |
d2e4a39e | 2545 | while (N0[n0] == '_' && n0 > 0 && N0[n0 - 1] == '_') |
14f9c5c9 AS |
2546 | n0 -= 1; |
2547 | n1 = k1; | |
d2e4a39e | 2548 | while (N1[n1] == '_' && n1 > 0 && N1[n1 - 1] == '_') |
14f9c5c9 AS |
2549 | n1 -= 1; |
2550 | if (n0 == n1 && STREQN (N0, N1, n0)) | |
d2e4a39e | 2551 | return (atoi (N0 + k0 + 1) < atoi (N1 + k1 + 1)); |
14f9c5c9 AS |
2552 | } |
2553 | return (strcmp (N0, N1) < 0); | |
2554 | } | |
2555 | } | |
d2e4a39e | 2556 | |
14f9c5c9 AS |
2557 | /* Sort SYMS[0..NSYMS-1] to put the choices in a canonical order by their */ |
2558 | /* mangled names, rearranging BLOCKS[0..NSYMS-1] according to the same */ | |
2559 | /* permutation. */ | |
d2e4a39e AS |
2560 | static void |
2561 | sort_choices (struct symbol *syms[], struct block *blocks[], int nsyms) | |
14f9c5c9 AS |
2562 | { |
2563 | int i, j; | |
d2e4a39e | 2564 | for (i = 1; i < nsyms; i += 1) |
14f9c5c9 | 2565 | { |
d2e4a39e AS |
2566 | struct symbol *sym = syms[i]; |
2567 | struct block *block = blocks[i]; | |
14f9c5c9 AS |
2568 | int j; |
2569 | ||
d2e4a39e | 2570 | for (j = i - 1; j >= 0; j -= 1) |
14f9c5c9 AS |
2571 | { |
2572 | if (mangled_ordered_before (SYMBOL_NAME (syms[j]), | |
2573 | SYMBOL_NAME (sym))) | |
2574 | break; | |
d2e4a39e AS |
2575 | syms[j + 1] = syms[j]; |
2576 | blocks[j + 1] = blocks[j]; | |
14f9c5c9 | 2577 | } |
d2e4a39e AS |
2578 | syms[j + 1] = sym; |
2579 | blocks[j + 1] = block; | |
14f9c5c9 AS |
2580 | } |
2581 | } | |
2582 | ||
2583 | /* Given a list of NSYMS symbols in SYMS and corresponding blocks in */ | |
2584 | /* BLOCKS, select up to MAX_RESULTS>0 by asking the user (if */ | |
2585 | /* necessary), returning the number selected, and setting the first */ | |
2586 | /* elements of SYMS and BLOCKS to the selected symbols and */ | |
2587 | /* corresponding blocks. Error if no symbols selected. BLOCKS may */ | |
2588 | /* be NULL, in which case it is ignored. */ | |
2589 | ||
2590 | /* NOTE: Adapted from decode_line_2 in symtab.c, with which it ought | |
2591 | to be re-integrated one of these days. */ | |
2592 | ||
2593 | int | |
d2e4a39e | 2594 | user_select_syms (struct symbol *syms[], struct block *blocks[], int nsyms, |
ebf56fd3 | 2595 | int max_results) |
14f9c5c9 AS |
2596 | { |
2597 | int i; | |
d2e4a39e | 2598 | int *chosen = (int *) alloca (sizeof (int) * nsyms); |
14f9c5c9 AS |
2599 | int n_chosen; |
2600 | int first_choice = (max_results == 1) ? 1 : 2; | |
2601 | ||
2602 | if (max_results < 1) | |
2603 | error ("Request to select 0 symbols!"); | |
2604 | if (nsyms <= 1) | |
2605 | return nsyms; | |
2606 | ||
d2e4a39e | 2607 | printf_unfiltered ("[0] cancel\n"); |
14f9c5c9 | 2608 | if (max_results > 1) |
d2e4a39e | 2609 | printf_unfiltered ("[1] all\n"); |
14f9c5c9 AS |
2610 | |
2611 | sort_choices (syms, blocks, nsyms); | |
2612 | ||
2613 | for (i = 0; i < nsyms; i += 1) | |
2614 | { | |
2615 | if (syms[i] == NULL) | |
2616 | continue; | |
2617 | ||
2618 | if (SYMBOL_CLASS (syms[i]) == LOC_BLOCK) | |
2619 | { | |
2620 | struct symtab_and_line sal = find_function_start_sal (syms[i], 1); | |
2621 | printf_unfiltered ("[%d] %s at %s:%d\n", | |
d2e4a39e | 2622 | i + first_choice, |
14f9c5c9 | 2623 | SYMBOL_SOURCE_NAME (syms[i]), |
d2e4a39e AS |
2624 | sal.symtab == NULL |
2625 | ? "<no source file available>" | |
2626 | : sal.symtab->filename, sal.line); | |
14f9c5c9 AS |
2627 | continue; |
2628 | } | |
d2e4a39e | 2629 | else |
14f9c5c9 | 2630 | { |
d2e4a39e | 2631 | int is_enumeral = |
14f9c5c9 AS |
2632 | (SYMBOL_CLASS (syms[i]) == LOC_CONST |
2633 | && SYMBOL_TYPE (syms[i]) != NULL | |
d2e4a39e AS |
2634 | && TYPE_CODE (SYMBOL_TYPE (syms[i])) == TYPE_CODE_ENUM); |
2635 | struct symtab *symtab = symtab_for_sym (syms[i]); | |
14f9c5c9 AS |
2636 | |
2637 | if (SYMBOL_LINE (syms[i]) != 0 && symtab != NULL) | |
2638 | printf_unfiltered ("[%d] %s at %s:%d\n", | |
2639 | i + first_choice, | |
2640 | SYMBOL_SOURCE_NAME (syms[i]), | |
2641 | symtab->filename, SYMBOL_LINE (syms[i])); | |
d2e4a39e | 2642 | else if (is_enumeral && TYPE_NAME (SYMBOL_TYPE (syms[i])) != NULL) |
14f9c5c9 AS |
2643 | { |
2644 | printf_unfiltered ("[%d] ", i + first_choice); | |
2645 | ada_print_type (SYMBOL_TYPE (syms[i]), NULL, gdb_stdout, -1, 0); | |
2646 | printf_unfiltered ("'(%s) (enumeral)\n", | |
2647 | SYMBOL_SOURCE_NAME (syms[i])); | |
2648 | } | |
2649 | else if (symtab != NULL) | |
d2e4a39e | 2650 | printf_unfiltered (is_enumeral |
14f9c5c9 AS |
2651 | ? "[%d] %s in %s (enumeral)\n" |
2652 | : "[%d] %s at %s:?\n", | |
2653 | i + first_choice, | |
2654 | SYMBOL_SOURCE_NAME (syms[i]), | |
2655 | symtab->filename); | |
2656 | else | |
2657 | printf_unfiltered (is_enumeral | |
2658 | ? "[%d] %s (enumeral)\n" | |
2659 | : "[%d] %s at ?\n", | |
d2e4a39e AS |
2660 | i + first_choice, |
2661 | SYMBOL_SOURCE_NAME (syms[i])); | |
14f9c5c9 AS |
2662 | } |
2663 | } | |
d2e4a39e | 2664 | |
14f9c5c9 AS |
2665 | n_chosen = get_selections (chosen, nsyms, max_results, max_results > 1, |
2666 | "overload-choice"); | |
2667 | ||
2668 | for (i = 0; i < n_chosen; i += 1) | |
2669 | { | |
2670 | syms[i] = syms[chosen[i]]; | |
d2e4a39e | 2671 | if (blocks != NULL) |
14f9c5c9 AS |
2672 | blocks[i] = blocks[chosen[i]]; |
2673 | } | |
2674 | ||
2675 | return n_chosen; | |
2676 | } | |
2677 | ||
2678 | /* Read and validate a set of numeric choices from the user in the | |
2679 | range 0 .. N_CHOICES-1. Place the results in increasing | |
2680 | order in CHOICES[0 .. N-1], and return N. | |
2681 | ||
2682 | The user types choices as a sequence of numbers on one line | |
2683 | separated by blanks, encoding them as follows: | |
2684 | ||
2685 | + A choice of 0 means to cancel the selection, throwing an error. | |
2686 | + If IS_ALL_CHOICE, a choice of 1 selects the entire set 0 .. N_CHOICES-1. | |
2687 | + The user chooses k by typing k+IS_ALL_CHOICE+1. | |
2688 | ||
2689 | The user is not allowed to choose more than MAX_RESULTS values. | |
2690 | ||
2691 | ANNOTATION_SUFFIX, if present, is used to annotate the input | |
2692 | prompts (for use with the -f switch). */ | |
2693 | ||
2694 | int | |
d2e4a39e AS |
2695 | get_selections (int *choices, int n_choices, int max_results, |
2696 | int is_all_choice, char *annotation_suffix) | |
14f9c5c9 AS |
2697 | { |
2698 | int i; | |
d2e4a39e AS |
2699 | char *args; |
2700 | const char *prompt; | |
14f9c5c9 AS |
2701 | int n_chosen; |
2702 | int first_choice = is_all_choice ? 2 : 1; | |
d2e4a39e | 2703 | |
14f9c5c9 AS |
2704 | prompt = getenv ("PS2"); |
2705 | if (prompt == NULL) | |
2706 | prompt = ">"; | |
2707 | ||
2708 | printf_unfiltered ("%s ", prompt); | |
2709 | gdb_flush (gdb_stdout); | |
2710 | ||
2711 | args = command_line_input ((char *) NULL, 0, annotation_suffix); | |
d2e4a39e | 2712 | |
14f9c5c9 AS |
2713 | if (args == NULL) |
2714 | error_no_arg ("one or more choice numbers"); | |
2715 | ||
2716 | n_chosen = 0; | |
2717 | ||
2718 | /* Set choices[0 .. n_chosen-1] to the users' choices in ascending | |
2719 | order, as given in args. Choices are validated. */ | |
2720 | while (1) | |
2721 | { | |
d2e4a39e | 2722 | char *args2; |
14f9c5c9 AS |
2723 | int choice, j; |
2724 | ||
2725 | while (isspace (*args)) | |
2726 | args += 1; | |
2727 | if (*args == '\0' && n_chosen == 0) | |
2728 | error_no_arg ("one or more choice numbers"); | |
2729 | else if (*args == '\0') | |
2730 | break; | |
2731 | ||
2732 | choice = strtol (args, &args2, 10); | |
d2e4a39e AS |
2733 | if (args == args2 || choice < 0 |
2734 | || choice > n_choices + first_choice - 1) | |
14f9c5c9 AS |
2735 | error ("Argument must be choice number"); |
2736 | args = args2; | |
2737 | ||
d2e4a39e | 2738 | if (choice == 0) |
14f9c5c9 AS |
2739 | error ("cancelled"); |
2740 | ||
2741 | if (choice < first_choice) | |
2742 | { | |
2743 | n_chosen = n_choices; | |
2744 | for (j = 0; j < n_choices; j += 1) | |
2745 | choices[j] = j; | |
2746 | break; | |
2747 | } | |
2748 | choice -= first_choice; | |
2749 | ||
d2e4a39e AS |
2750 | for (j = n_chosen - 1; j >= 0 && choice < choices[j]; j -= 1) |
2751 | { | |
2752 | } | |
14f9c5c9 AS |
2753 | |
2754 | if (j < 0 || choice != choices[j]) | |
2755 | { | |
2756 | int k; | |
d2e4a39e AS |
2757 | for (k = n_chosen - 1; k > j; k -= 1) |
2758 | choices[k + 1] = choices[k]; | |
2759 | choices[j + 1] = choice; | |
14f9c5c9 AS |
2760 | n_chosen += 1; |
2761 | } | |
2762 | } | |
2763 | ||
2764 | if (n_chosen > max_results) | |
2765 | error ("Select no more than %d of the above", max_results); | |
d2e4a39e | 2766 | |
14f9c5c9 AS |
2767 | return n_chosen; |
2768 | } | |
2769 | ||
2770 | /* Replace the operator of length OPLEN at position PC in *EXPP with a call */ | |
2771 | /* on the function identified by SYM and BLOCK, and taking NARGS */ | |
2772 | /* arguments. Update *EXPP as needed to hold more space. */ | |
2773 | ||
2774 | static void | |
d2e4a39e AS |
2775 | replace_operator_with_call (struct expression **expp, int pc, int nargs, |
2776 | int oplen, struct symbol *sym, | |
2777 | struct block *block) | |
14f9c5c9 AS |
2778 | { |
2779 | /* A new expression, with 6 more elements (3 for funcall, 4 for function | |
2780 | symbol, -oplen for operator being replaced). */ | |
d2e4a39e | 2781 | struct expression *newexp = (struct expression *) |
14f9c5c9 AS |
2782 | xmalloc (sizeof (struct expression) |
2783 | + EXP_ELEM_TO_BYTES ((*expp)->nelts + 7 - oplen)); | |
d2e4a39e | 2784 | struct expression *exp = *expp; |
14f9c5c9 AS |
2785 | |
2786 | newexp->nelts = exp->nelts + 7 - oplen; | |
2787 | newexp->language_defn = exp->language_defn; | |
2788 | memcpy (newexp->elts, exp->elts, EXP_ELEM_TO_BYTES (pc)); | |
d2e4a39e | 2789 | memcpy (newexp->elts + pc + 7, exp->elts + pc + oplen, |
14f9c5c9 AS |
2790 | EXP_ELEM_TO_BYTES (exp->nelts - pc - oplen)); |
2791 | ||
2792 | newexp->elts[pc].opcode = newexp->elts[pc + 2].opcode = OP_FUNCALL; | |
2793 | newexp->elts[pc + 1].longconst = (LONGEST) nargs; | |
2794 | ||
2795 | newexp->elts[pc + 3].opcode = newexp->elts[pc + 6].opcode = OP_VAR_VALUE; | |
2796 | newexp->elts[pc + 4].block = block; | |
2797 | newexp->elts[pc + 5].symbol = sym; | |
2798 | ||
2799 | *expp = newexp; | |
aacb1f0a | 2800 | xfree (exp); |
d2e4a39e | 2801 | } |
14f9c5c9 AS |
2802 | |
2803 | /* Type-class predicates */ | |
2804 | ||
2805 | /* True iff TYPE is numeric (i.e., an INT, RANGE (of numeric type), or */ | |
2806 | /* FLOAT.) */ | |
2807 | ||
2808 | static int | |
d2e4a39e | 2809 | numeric_type_p (struct type *type) |
14f9c5c9 AS |
2810 | { |
2811 | if (type == NULL) | |
2812 | return 0; | |
d2e4a39e AS |
2813 | else |
2814 | { | |
2815 | switch (TYPE_CODE (type)) | |
2816 | { | |
2817 | case TYPE_CODE_INT: | |
2818 | case TYPE_CODE_FLT: | |
2819 | return 1; | |
2820 | case TYPE_CODE_RANGE: | |
2821 | return (type == TYPE_TARGET_TYPE (type) | |
2822 | || numeric_type_p (TYPE_TARGET_TYPE (type))); | |
2823 | default: | |
2824 | return 0; | |
2825 | } | |
2826 | } | |
14f9c5c9 AS |
2827 | } |
2828 | ||
2829 | /* True iff TYPE is integral (an INT or RANGE of INTs). */ | |
2830 | ||
2831 | static int | |
d2e4a39e | 2832 | integer_type_p (struct type *type) |
14f9c5c9 AS |
2833 | { |
2834 | if (type == NULL) | |
2835 | return 0; | |
d2e4a39e AS |
2836 | else |
2837 | { | |
2838 | switch (TYPE_CODE (type)) | |
2839 | { | |
2840 | case TYPE_CODE_INT: | |
2841 | return 1; | |
2842 | case TYPE_CODE_RANGE: | |
2843 | return (type == TYPE_TARGET_TYPE (type) | |
2844 | || integer_type_p (TYPE_TARGET_TYPE (type))); | |
2845 | default: | |
2846 | return 0; | |
2847 | } | |
2848 | } | |
14f9c5c9 AS |
2849 | } |
2850 | ||
2851 | /* True iff TYPE is scalar (INT, RANGE, FLOAT, ENUM). */ | |
2852 | ||
2853 | static int | |
d2e4a39e | 2854 | scalar_type_p (struct type *type) |
14f9c5c9 AS |
2855 | { |
2856 | if (type == NULL) | |
2857 | return 0; | |
d2e4a39e AS |
2858 | else |
2859 | { | |
2860 | switch (TYPE_CODE (type)) | |
2861 | { | |
2862 | case TYPE_CODE_INT: | |
2863 | case TYPE_CODE_RANGE: | |
2864 | case TYPE_CODE_ENUM: | |
2865 | case TYPE_CODE_FLT: | |
2866 | return 1; | |
2867 | default: | |
2868 | return 0; | |
2869 | } | |
2870 | } | |
14f9c5c9 AS |
2871 | } |
2872 | ||
2873 | /* True iff TYPE is discrete (INT, RANGE, ENUM). */ | |
2874 | ||
2875 | static int | |
d2e4a39e | 2876 | discrete_type_p (struct type *type) |
14f9c5c9 AS |
2877 | { |
2878 | if (type == NULL) | |
2879 | return 0; | |
d2e4a39e AS |
2880 | else |
2881 | { | |
2882 | switch (TYPE_CODE (type)) | |
2883 | { | |
2884 | case TYPE_CODE_INT: | |
2885 | case TYPE_CODE_RANGE: | |
2886 | case TYPE_CODE_ENUM: | |
2887 | return 1; | |
2888 | default: | |
2889 | return 0; | |
2890 | } | |
2891 | } | |
14f9c5c9 AS |
2892 | } |
2893 | ||
2894 | /* Returns non-zero if OP with operatands in the vector ARGS could be | |
2895 | a user-defined function. Errs on the side of pre-defined operators | |
2896 | (i.e., result 0). */ | |
2897 | ||
2898 | static int | |
d2e4a39e | 2899 | possible_user_operator_p (enum exp_opcode op, struct value *args[]) |
14f9c5c9 | 2900 | { |
d2e4a39e AS |
2901 | struct type *type0 = check_typedef (VALUE_TYPE (args[0])); |
2902 | struct type *type1 = | |
14f9c5c9 | 2903 | (args[1] == NULL) ? NULL : check_typedef (VALUE_TYPE (args[1])); |
d2e4a39e | 2904 | |
14f9c5c9 AS |
2905 | switch (op) |
2906 | { | |
2907 | default: | |
2908 | return 0; | |
2909 | ||
2910 | case BINOP_ADD: | |
2911 | case BINOP_SUB: | |
2912 | case BINOP_MUL: | |
2913 | case BINOP_DIV: | |
d2e4a39e | 2914 | return (!(numeric_type_p (type0) && numeric_type_p (type1))); |
14f9c5c9 AS |
2915 | |
2916 | case BINOP_REM: | |
2917 | case BINOP_MOD: | |
2918 | case BINOP_BITWISE_AND: | |
2919 | case BINOP_BITWISE_IOR: | |
2920 | case BINOP_BITWISE_XOR: | |
d2e4a39e | 2921 | return (!(integer_type_p (type0) && integer_type_p (type1))); |
14f9c5c9 AS |
2922 | |
2923 | case BINOP_EQUAL: | |
2924 | case BINOP_NOTEQUAL: | |
2925 | case BINOP_LESS: | |
2926 | case BINOP_GTR: | |
2927 | case BINOP_LEQ: | |
2928 | case BINOP_GEQ: | |
d2e4a39e | 2929 | return (!(scalar_type_p (type0) && scalar_type_p (type1))); |
14f9c5c9 AS |
2930 | |
2931 | case BINOP_CONCAT: | |
d2e4a39e AS |
2932 | return ((TYPE_CODE (type0) != TYPE_CODE_ARRAY && |
2933 | (TYPE_CODE (type0) != TYPE_CODE_PTR || | |
2934 | TYPE_CODE (TYPE_TARGET_TYPE (type0)) | |
2935 | != TYPE_CODE_ARRAY)) | |
2936 | || (TYPE_CODE (type1) != TYPE_CODE_ARRAY && | |
2937 | (TYPE_CODE (type1) != TYPE_CODE_PTR || | |
2938 | TYPE_CODE (TYPE_TARGET_TYPE (type1)) != TYPE_CODE_ARRAY))); | |
14f9c5c9 AS |
2939 | |
2940 | case BINOP_EXP: | |
d2e4a39e | 2941 | return (!(numeric_type_p (type0) && integer_type_p (type1))); |
14f9c5c9 AS |
2942 | |
2943 | case UNOP_NEG: | |
2944 | case UNOP_PLUS: | |
2945 | case UNOP_LOGICAL_NOT: | |
d2e4a39e AS |
2946 | case UNOP_ABS: |
2947 | return (!numeric_type_p (type0)); | |
14f9c5c9 AS |
2948 | |
2949 | } | |
2950 | } | |
2951 | \f | |
2952 | /* Renaming */ | |
2953 | ||
2954 | /** NOTE: In the following, we assume that a renaming type's name may | |
2955 | * have an ___XD suffix. It would be nice if this went away at some | |
2956 | * point. */ | |
2957 | ||
2958 | /* If TYPE encodes a renaming, returns the renaming suffix, which | |
2959 | * is XR for an object renaming, XRP for a procedure renaming, XRE for | |
2960 | * an exception renaming, and XRS for a subprogram renaming. Returns | |
2961 | * NULL if NAME encodes none of these. */ | |
d2e4a39e AS |
2962 | const char * |
2963 | ada_renaming_type (struct type *type) | |
14f9c5c9 AS |
2964 | { |
2965 | if (type != NULL && TYPE_CODE (type) == TYPE_CODE_ENUM) | |
2966 | { | |
d2e4a39e AS |
2967 | const char *name = type_name_no_tag (type); |
2968 | const char *suffix = (name == NULL) ? NULL : strstr (name, "___XR"); | |
2969 | if (suffix == NULL | |
2970 | || (suffix[5] != '\000' && strchr ("PES_", suffix[5]) == NULL)) | |
14f9c5c9 AS |
2971 | return NULL; |
2972 | else | |
2973 | return suffix + 3; | |
2974 | } | |
2975 | else | |
2976 | return NULL; | |
2977 | } | |
2978 | ||
2979 | /* Return non-zero iff SYM encodes an object renaming. */ | |
2980 | int | |
d2e4a39e | 2981 | ada_is_object_renaming (struct symbol *sym) |
14f9c5c9 | 2982 | { |
d2e4a39e AS |
2983 | const char *renaming_type = ada_renaming_type (SYMBOL_TYPE (sym)); |
2984 | return renaming_type != NULL | |
14f9c5c9 AS |
2985 | && (renaming_type[2] == '\0' || renaming_type[2] == '_'); |
2986 | } | |
2987 | ||
2988 | /* Assuming that SYM encodes a non-object renaming, returns the original | |
2989 | * name of the renamed entity. The name is good until the end of | |
2990 | * parsing. */ | |
d2e4a39e AS |
2991 | const char * |
2992 | ada_simple_renamed_entity (struct symbol *sym) | |
14f9c5c9 | 2993 | { |
d2e4a39e AS |
2994 | struct type *type; |
2995 | const char *raw_name; | |
14f9c5c9 | 2996 | int len; |
d2e4a39e | 2997 | char *result; |
14f9c5c9 AS |
2998 | |
2999 | type = SYMBOL_TYPE (sym); | |
3000 | if (type == NULL || TYPE_NFIELDS (type) < 1) | |
3001 | error ("Improperly encoded renaming."); | |
3002 | ||
3003 | raw_name = TYPE_FIELD_NAME (type, 0); | |
3004 | len = (raw_name == NULL ? 0 : strlen (raw_name)) - 5; | |
3005 | if (len <= 0) | |
3006 | error ("Improperly encoded renaming."); | |
3007 | ||
3008 | result = xmalloc (len + 1); | |
d2e4a39e AS |
3009 | /* FIXME: add_name_string_cleanup should be defined in parse.c */ |
3010 | /* add_name_string_cleanup (result); */ | |
14f9c5c9 AS |
3011 | strncpy (result, raw_name, len); |
3012 | result[len] = '\000'; | |
3013 | return result; | |
3014 | } | |
14f9c5c9 | 3015 | \f |
d2e4a39e | 3016 | |
14f9c5c9 AS |
3017 | /* Evaluation: Function Calls */ |
3018 | ||
3019 | /* Copy VAL onto the stack, using and updating *SP as the stack | |
3020 | pointer. Return VAL as an lvalue. */ | |
3021 | ||
d2e4a39e AS |
3022 | static struct value * |
3023 | place_on_stack (struct value *val, CORE_ADDR *sp) | |
14f9c5c9 AS |
3024 | { |
3025 | CORE_ADDR old_sp = *sp; | |
3026 | ||
3027 | #ifdef STACK_ALIGN | |
d2e4a39e AS |
3028 | *sp = push_bytes (*sp, VALUE_CONTENTS_RAW (val), |
3029 | STACK_ALIGN (TYPE_LENGTH | |
3030 | (check_typedef (VALUE_TYPE (val))))); | |
14f9c5c9 | 3031 | #else |
d2e4a39e | 3032 | *sp = push_bytes (*sp, VALUE_CONTENTS_RAW (val), |
14f9c5c9 AS |
3033 | TYPE_LENGTH (check_typedef (VALUE_TYPE (val)))); |
3034 | #endif | |
3035 | ||
3036 | VALUE_LVAL (val) = lval_memory; | |
3037 | if (INNER_THAN (1, 2)) | |
3038 | VALUE_ADDRESS (val) = *sp; | |
3039 | else | |
3040 | VALUE_ADDRESS (val) = old_sp; | |
3041 | ||
3042 | return val; | |
3043 | } | |
3044 | ||
3045 | /* Return the value ACTUAL, converted to be an appropriate value for a | |
3046 | formal of type FORMAL_TYPE. Use *SP as a stack pointer for | |
3047 | allocating any necessary descriptors (fat pointers), or copies of | |
d2e4a39e | 3048 | values not residing in memory, updating it as needed. */ |
14f9c5c9 | 3049 | |
d2e4a39e AS |
3050 | static struct value * |
3051 | convert_actual (struct value *actual, struct type *formal_type0, | |
3052 | CORE_ADDR *sp) | |
14f9c5c9 | 3053 | { |
d2e4a39e AS |
3054 | struct type *actual_type = check_typedef (VALUE_TYPE (actual)); |
3055 | struct type *formal_type = check_typedef (formal_type0); | |
3056 | struct type *formal_target = | |
3057 | TYPE_CODE (formal_type) == TYPE_CODE_PTR | |
3058 | ? check_typedef (TYPE_TARGET_TYPE (formal_type)) : formal_type; | |
3059 | struct type *actual_target = | |
3060 | TYPE_CODE (actual_type) == TYPE_CODE_PTR | |
3061 | ? check_typedef (TYPE_TARGET_TYPE (actual_type)) : actual_type; | |
14f9c5c9 AS |
3062 | |
3063 | if (ada_is_array_descriptor (formal_target) | |
3064 | && TYPE_CODE (actual_target) == TYPE_CODE_ARRAY) | |
3065 | return make_array_descriptor (formal_type, actual, sp); | |
3066 | else if (TYPE_CODE (formal_type) == TYPE_CODE_PTR) | |
3067 | { | |
3068 | if (TYPE_CODE (formal_target) == TYPE_CODE_ARRAY | |
d2e4a39e | 3069 | && ada_is_array_descriptor (actual_target)) |
14f9c5c9 AS |
3070 | return desc_data (actual); |
3071 | else if (TYPE_CODE (actual_type) != TYPE_CODE_PTR) | |
3072 | { | |
3073 | if (VALUE_LVAL (actual) != lval_memory) | |
3074 | { | |
d2e4a39e | 3075 | struct value *val; |
14f9c5c9 AS |
3076 | actual_type = check_typedef (VALUE_TYPE (actual)); |
3077 | val = allocate_value (actual_type); | |
d2e4a39e AS |
3078 | memcpy ((char *) VALUE_CONTENTS_RAW (val), |
3079 | (char *) VALUE_CONTENTS (actual), | |
14f9c5c9 AS |
3080 | TYPE_LENGTH (actual_type)); |
3081 | actual = place_on_stack (val, sp); | |
3082 | } | |
3083 | return value_addr (actual); | |
3084 | } | |
3085 | } | |
3086 | else if (TYPE_CODE (actual_type) == TYPE_CODE_PTR) | |
3087 | return ada_value_ind (actual); | |
3088 | ||
3089 | return actual; | |
3090 | } | |
3091 | ||
3092 | ||
3093 | /* Push a descriptor of type TYPE for array value ARR on the stack at | |
3094 | *SP, updating *SP to reflect the new descriptor. Return either | |
3095 | an lvalue representing the new descriptor, or (if TYPE is a pointer- | |
3096 | to-descriptor type rather than a descriptor type), a struct value* | |
3097 | representing a pointer to this descriptor. */ | |
3098 | ||
d2e4a39e AS |
3099 | static struct value * |
3100 | make_array_descriptor (struct type *type, struct value *arr, CORE_ADDR *sp) | |
14f9c5c9 | 3101 | { |
d2e4a39e AS |
3102 | struct type *bounds_type = desc_bounds_type (type); |
3103 | struct type *desc_type = desc_base_type (type); | |
3104 | struct value *descriptor = allocate_value (desc_type); | |
3105 | struct value *bounds = allocate_value (bounds_type); | |
14f9c5c9 AS |
3106 | CORE_ADDR bounds_addr; |
3107 | int i; | |
d2e4a39e | 3108 | |
14f9c5c9 AS |
3109 | for (i = ada_array_arity (check_typedef (VALUE_TYPE (arr))); i > 0; i -= 1) |
3110 | { | |
3111 | modify_general_field (VALUE_CONTENTS (bounds), | |
d2e4a39e | 3112 | value_as_long (ada_array_bound (arr, i, 0)), |
14f9c5c9 AS |
3113 | desc_bound_bitpos (bounds_type, i, 0), |
3114 | desc_bound_bitsize (bounds_type, i, 0)); | |
3115 | modify_general_field (VALUE_CONTENTS (bounds), | |
d2e4a39e | 3116 | value_as_long (ada_array_bound (arr, i, 1)), |
14f9c5c9 AS |
3117 | desc_bound_bitpos (bounds_type, i, 1), |
3118 | desc_bound_bitsize (bounds_type, i, 1)); | |
3119 | } | |
d2e4a39e | 3120 | |
14f9c5c9 | 3121 | bounds = place_on_stack (bounds, sp); |
d2e4a39e | 3122 | |
14f9c5c9 AS |
3123 | modify_general_field (VALUE_CONTENTS (descriptor), |
3124 | arr, | |
3125 | fat_pntr_data_bitpos (desc_type), | |
3126 | fat_pntr_data_bitsize (desc_type)); | |
3127 | modify_general_field (VALUE_CONTENTS (descriptor), | |
3128 | VALUE_ADDRESS (bounds), | |
3129 | fat_pntr_bounds_bitpos (desc_type), | |
3130 | fat_pntr_bounds_bitsize (desc_type)); | |
3131 | ||
3132 | descriptor = place_on_stack (descriptor, sp); | |
3133 | ||
3134 | if (TYPE_CODE (type) == TYPE_CODE_PTR) | |
3135 | return value_addr (descriptor); | |
3136 | else | |
3137 | return descriptor; | |
3138 | } | |
3139 | ||
3140 | ||
3141 | /* Assuming a dummy frame has been established on the target, perform any | |
3142 | conversions needed for calling function FUNC on the NARGS actual | |
3143 | parameters in ARGS, other than standard C conversions. Does | |
3144 | nothing if FUNC does not have Ada-style prototype data, or if NARGS | |
3145 | does not match the number of arguments expected. Use *SP as a | |
3146 | stack pointer for additional data that must be pushed, updating its | |
3147 | value as needed. */ | |
3148 | ||
3149 | void | |
d2e4a39e AS |
3150 | ada_convert_actuals (struct value *func, int nargs, struct value *args[], |
3151 | CORE_ADDR *sp) | |
14f9c5c9 AS |
3152 | { |
3153 | int i; | |
3154 | ||
d2e4a39e | 3155 | if (TYPE_NFIELDS (VALUE_TYPE (func)) == 0 |
14f9c5c9 AS |
3156 | || nargs != TYPE_NFIELDS (VALUE_TYPE (func))) |
3157 | return; | |
3158 | ||
3159 | for (i = 0; i < nargs; i += 1) | |
d2e4a39e AS |
3160 | args[i] = |
3161 | convert_actual (args[i], TYPE_FIELD_TYPE (VALUE_TYPE (func), i), sp); | |
14f9c5c9 | 3162 | } |
14f9c5c9 | 3163 | \f |
d2e4a39e | 3164 | |
14f9c5c9 AS |
3165 | /* Symbol Lookup */ |
3166 | ||
3167 | ||
3168 | /* The vectors of symbols and blocks ultimately returned from */ | |
3169 | /* ada_lookup_symbol_list. */ | |
3170 | ||
3171 | /* Current size of defn_symbols and defn_blocks */ | |
d2e4a39e | 3172 | static size_t defn_vector_size = 0; |
14f9c5c9 AS |
3173 | |
3174 | /* Current number of symbols found. */ | |
3175 | static int ndefns = 0; | |
3176 | ||
d2e4a39e AS |
3177 | static struct symbol **defn_symbols = NULL; |
3178 | static struct block **defn_blocks = NULL; | |
14f9c5c9 AS |
3179 | |
3180 | /* Return the result of a standard (literal, C-like) lookup of NAME in | |
3181 | * given NAMESPACE. */ | |
3182 | ||
d2e4a39e AS |
3183 | static struct symbol * |
3184 | standard_lookup (const char *name, namespace_enum namespace) | |
14f9c5c9 | 3185 | { |
d2e4a39e AS |
3186 | struct symbol *sym; |
3187 | struct symtab *symtab; | |
3188 | sym = lookup_symbol (name, (struct block *) NULL, namespace, 0, &symtab); | |
14f9c5c9 AS |
3189 | return sym; |
3190 | } | |
d2e4a39e | 3191 | |
14f9c5c9 AS |
3192 | |
3193 | /* Non-zero iff there is at least one non-function/non-enumeral symbol */ | |
3194 | /* in SYMS[0..N-1]. We treat enumerals as functions, since they */ | |
d2e4a39e | 3195 | /* contend in overloading in the same way. */ |
14f9c5c9 | 3196 | static int |
d2e4a39e | 3197 | is_nonfunction (struct symbol *syms[], int n) |
14f9c5c9 AS |
3198 | { |
3199 | int i; | |
3200 | ||
3201 | for (i = 0; i < n; i += 1) | |
3202 | if (TYPE_CODE (SYMBOL_TYPE (syms[i])) != TYPE_CODE_FUNC | |
3203 | && TYPE_CODE (SYMBOL_TYPE (syms[i])) != TYPE_CODE_ENUM) | |
3204 | return 1; | |
3205 | ||
3206 | return 0; | |
3207 | } | |
3208 | ||
3209 | /* If true (non-zero), then TYPE0 and TYPE1 represent equivalent | |
3210 | struct types. Otherwise, they may not. */ | |
3211 | ||
3212 | static int | |
d2e4a39e | 3213 | equiv_types (struct type *type0, struct type *type1) |
14f9c5c9 | 3214 | { |
d2e4a39e | 3215 | if (type0 == type1) |
14f9c5c9 | 3216 | return 1; |
d2e4a39e | 3217 | if (type0 == NULL || type1 == NULL |
14f9c5c9 AS |
3218 | || TYPE_CODE (type0) != TYPE_CODE (type1)) |
3219 | return 0; | |
d2e4a39e | 3220 | if ((TYPE_CODE (type0) == TYPE_CODE_STRUCT |
14f9c5c9 AS |
3221 | || TYPE_CODE (type0) == TYPE_CODE_ENUM) |
3222 | && ada_type_name (type0) != NULL && ada_type_name (type1) != NULL | |
3223 | && STREQ (ada_type_name (type0), ada_type_name (type1))) | |
3224 | return 1; | |
d2e4a39e | 3225 | |
14f9c5c9 AS |
3226 | return 0; |
3227 | } | |
3228 | ||
3229 | /* True iff SYM0 represents the same entity as SYM1, or one that is | |
3230 | no more defined than that of SYM1. */ | |
3231 | ||
3232 | static int | |
d2e4a39e | 3233 | lesseq_defined_than (struct symbol *sym0, struct symbol *sym1) |
14f9c5c9 AS |
3234 | { |
3235 | if (sym0 == sym1) | |
3236 | return 1; | |
3237 | if (SYMBOL_NAMESPACE (sym0) != SYMBOL_NAMESPACE (sym1) | |
3238 | || SYMBOL_CLASS (sym0) != SYMBOL_CLASS (sym1)) | |
3239 | return 0; | |
3240 | ||
d2e4a39e | 3241 | switch (SYMBOL_CLASS (sym0)) |
14f9c5c9 AS |
3242 | { |
3243 | case LOC_UNDEF: | |
3244 | return 1; | |
3245 | case LOC_TYPEDEF: | |
3246 | { | |
d2e4a39e AS |
3247 | struct type *type0 = SYMBOL_TYPE (sym0); |
3248 | struct type *type1 = SYMBOL_TYPE (sym1); | |
3249 | char *name0 = SYMBOL_NAME (sym0); | |
3250 | char *name1 = SYMBOL_NAME (sym1); | |
14f9c5c9 | 3251 | int len0 = strlen (name0); |
d2e4a39e | 3252 | return |
14f9c5c9 AS |
3253 | TYPE_CODE (type0) == TYPE_CODE (type1) |
3254 | && (equiv_types (type0, type1) | |
3255 | || (len0 < strlen (name1) && STREQN (name0, name1, len0) | |
3256 | && STREQN (name1 + len0, "___XV", 5))); | |
3257 | } | |
3258 | case LOC_CONST: | |
3259 | return SYMBOL_VALUE (sym0) == SYMBOL_VALUE (sym1) | |
3260 | && equiv_types (SYMBOL_TYPE (sym0), SYMBOL_TYPE (sym1)); | |
d2e4a39e AS |
3261 | default: |
3262 | return 0; | |
14f9c5c9 AS |
3263 | } |
3264 | } | |
3265 | ||
3266 | /* Append SYM to the end of defn_symbols, and BLOCK to the end of | |
3267 | defn_blocks, updating ndefns, and expanding defn_symbols and | |
3268 | defn_blocks as needed. Do not include SYM if it is a duplicate. */ | |
3269 | ||
3270 | static void | |
d2e4a39e | 3271 | add_defn_to_vec (struct symbol *sym, struct block *block) |
14f9c5c9 AS |
3272 | { |
3273 | int i; | |
3274 | size_t tmp; | |
3275 | ||
d2e4a39e | 3276 | if (SYMBOL_TYPE (sym) != NULL) |
14f9c5c9 AS |
3277 | CHECK_TYPEDEF (SYMBOL_TYPE (sym)); |
3278 | for (i = 0; i < ndefns; i += 1) | |
3279 | { | |
3280 | if (lesseq_defined_than (sym, defn_symbols[i])) | |
3281 | return; | |
3282 | else if (lesseq_defined_than (defn_symbols[i], sym)) | |
3283 | { | |
3284 | defn_symbols[i] = sym; | |
3285 | defn_blocks[i] = block; | |
3286 | return; | |
3287 | } | |
3288 | } | |
3289 | ||
3290 | tmp = defn_vector_size; | |
d2e4a39e AS |
3291 | GROW_VECT (defn_symbols, tmp, ndefns + 2); |
3292 | GROW_VECT (defn_blocks, defn_vector_size, ndefns + 2); | |
14f9c5c9 AS |
3293 | |
3294 | defn_symbols[ndefns] = sym; | |
3295 | defn_blocks[ndefns] = block; | |
3296 | ndefns += 1; | |
3297 | } | |
3298 | ||
3299 | /* Look, in partial_symtab PST, for symbol NAME in given namespace. | |
3300 | Check the global symbols if GLOBAL, the static symbols if not. Do | |
3301 | wild-card match if WILD. */ | |
3302 | ||
3303 | static struct partial_symbol * | |
d2e4a39e AS |
3304 | ada_lookup_partial_symbol (struct partial_symtab *pst, const char *name, |
3305 | int global, namespace_enum namespace, int wild) | |
14f9c5c9 AS |
3306 | { |
3307 | struct partial_symbol **start; | |
3308 | int name_len = strlen (name); | |
3309 | int length = (global ? pst->n_global_syms : pst->n_static_syms); | |
3310 | int i; | |
3311 | ||
3312 | if (length == 0) | |
3313 | { | |
3314 | return (NULL); | |
3315 | } | |
d2e4a39e | 3316 | |
14f9c5c9 AS |
3317 | start = (global ? |
3318 | pst->objfile->global_psymbols.list + pst->globals_offset : | |
d2e4a39e | 3319 | pst->objfile->static_psymbols.list + pst->statics_offset); |
14f9c5c9 AS |
3320 | |
3321 | if (wild) | |
3322 | { | |
3323 | for (i = 0; i < length; i += 1) | |
3324 | { | |
d2e4a39e | 3325 | struct partial_symbol *psym = start[i]; |
14f9c5c9 AS |
3326 | |
3327 | if (SYMBOL_NAMESPACE (psym) == namespace && | |
3328 | wild_match (name, name_len, SYMBOL_NAME (psym))) | |
3329 | return psym; | |
3330 | } | |
3331 | return NULL; | |
3332 | } | |
d2e4a39e | 3333 | else |
14f9c5c9 AS |
3334 | { |
3335 | if (global) | |
3336 | { | |
3337 | int U; | |
d2e4a39e AS |
3338 | i = 0; |
3339 | U = length - 1; | |
3340 | while (U - i > 4) | |
14f9c5c9 | 3341 | { |
d2e4a39e AS |
3342 | int M = (U + i) >> 1; |
3343 | struct partial_symbol *psym = start[M]; | |
14f9c5c9 | 3344 | if (SYMBOL_NAME (psym)[0] < name[0]) |
d2e4a39e | 3345 | i = M + 1; |
14f9c5c9 | 3346 | else if (SYMBOL_NAME (psym)[0] > name[0]) |
d2e4a39e | 3347 | U = M - 1; |
14f9c5c9 | 3348 | else if (strcmp (SYMBOL_NAME (psym), name) < 0) |
d2e4a39e | 3349 | i = M + 1; |
14f9c5c9 AS |
3350 | else |
3351 | U = M; | |
3352 | } | |
3353 | } | |
3354 | else | |
3355 | i = 0; | |
3356 | ||
3357 | while (i < length) | |
3358 | { | |
3359 | struct partial_symbol *psym = start[i]; | |
3360 | ||
3361 | if (SYMBOL_NAMESPACE (psym) == namespace) | |
3362 | { | |
3363 | int cmp = strncmp (name, SYMBOL_NAME (psym), name_len); | |
d2e4a39e AS |
3364 | |
3365 | if (cmp < 0) | |
14f9c5c9 AS |
3366 | { |
3367 | if (global) | |
3368 | break; | |
3369 | } | |
d2e4a39e AS |
3370 | else if (cmp == 0 |
3371 | && is_name_suffix (SYMBOL_NAME (psym) + name_len)) | |
14f9c5c9 AS |
3372 | return psym; |
3373 | } | |
3374 | i += 1; | |
3375 | } | |
3376 | ||
3377 | if (global) | |
3378 | { | |
3379 | int U; | |
d2e4a39e AS |
3380 | i = 0; |
3381 | U = length - 1; | |
3382 | while (U - i > 4) | |
14f9c5c9 | 3383 | { |
d2e4a39e | 3384 | int M = (U + i) >> 1; |
14f9c5c9 AS |
3385 | struct partial_symbol *psym = start[M]; |
3386 | if (SYMBOL_NAME (psym)[0] < '_') | |
d2e4a39e | 3387 | i = M + 1; |
14f9c5c9 | 3388 | else if (SYMBOL_NAME (psym)[0] > '_') |
d2e4a39e | 3389 | U = M - 1; |
14f9c5c9 | 3390 | else if (strcmp (SYMBOL_NAME (psym), "_ada_") < 0) |
d2e4a39e | 3391 | i = M + 1; |
14f9c5c9 AS |
3392 | else |
3393 | U = M; | |
3394 | } | |
3395 | } | |
3396 | else | |
3397 | i = 0; | |
3398 | ||
3399 | while (i < length) | |
3400 | { | |
d2e4a39e | 3401 | struct partial_symbol *psym = start[i]; |
14f9c5c9 AS |
3402 | |
3403 | if (SYMBOL_NAMESPACE (psym) == namespace) | |
3404 | { | |
3405 | int cmp; | |
3406 | ||
3407 | cmp = (int) '_' - (int) SYMBOL_NAME (psym)[0]; | |
d2e4a39e | 3408 | if (cmp == 0) |
14f9c5c9 AS |
3409 | { |
3410 | cmp = strncmp ("_ada_", SYMBOL_NAME (psym), 5); | |
3411 | if (cmp == 0) | |
3412 | cmp = strncmp (name, SYMBOL_NAME (psym) + 5, name_len); | |
3413 | } | |
d2e4a39e AS |
3414 | |
3415 | if (cmp < 0) | |
14f9c5c9 AS |
3416 | { |
3417 | if (global) | |
3418 | break; | |
3419 | } | |
d2e4a39e AS |
3420 | else if (cmp == 0 |
3421 | && is_name_suffix (SYMBOL_NAME (psym) + name_len + 5)) | |
14f9c5c9 AS |
3422 | return psym; |
3423 | } | |
3424 | i += 1; | |
3425 | } | |
d2e4a39e | 3426 | |
14f9c5c9 AS |
3427 | } |
3428 | return NULL; | |
3429 | } | |
3430 | ||
3431 | ||
3432 | /* Find a symbol table containing symbol SYM or NULL if none. */ | |
d2e4a39e AS |
3433 | static struct symtab * |
3434 | symtab_for_sym (struct symbol *sym) | |
14f9c5c9 | 3435 | { |
d2e4a39e | 3436 | struct symtab *s; |
14f9c5c9 AS |
3437 | struct objfile *objfile; |
3438 | struct block *b; | |
261397f8 | 3439 | struct symbol *tmp_sym; |
14f9c5c9 AS |
3440 | int i, j; |
3441 | ||
3442 | ALL_SYMTABS (objfile, s) | |
d2e4a39e AS |
3443 | { |
3444 | switch (SYMBOL_CLASS (sym)) | |
3445 | { | |
3446 | case LOC_CONST: | |
3447 | case LOC_STATIC: | |
3448 | case LOC_TYPEDEF: | |
3449 | case LOC_REGISTER: | |
3450 | case LOC_LABEL: | |
3451 | case LOC_BLOCK: | |
3452 | case LOC_CONST_BYTES: | |
3453 | b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK); | |
3454 | ALL_BLOCK_SYMBOLS (b, i, tmp_sym) if (sym == tmp_sym) | |
3455 | return s; | |
3456 | b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK); | |
3457 | ALL_BLOCK_SYMBOLS (b, i, tmp_sym) if (sym == tmp_sym) | |
3458 | return s; | |
3459 | break; | |
3460 | default: | |
3461 | break; | |
3462 | } | |
3463 | switch (SYMBOL_CLASS (sym)) | |
3464 | { | |
3465 | case LOC_REGISTER: | |
3466 | case LOC_ARG: | |
3467 | case LOC_REF_ARG: | |
3468 | case LOC_REGPARM: | |
3469 | case LOC_REGPARM_ADDR: | |
3470 | case LOC_LOCAL: | |
3471 | case LOC_TYPEDEF: | |
3472 | case LOC_LOCAL_ARG: | |
3473 | case LOC_BASEREG: | |
3474 | case LOC_BASEREG_ARG: | |
3475 | for (j = FIRST_LOCAL_BLOCK; | |
3476 | j < BLOCKVECTOR_NBLOCKS (BLOCKVECTOR (s)); j += 1) | |
3477 | { | |
3478 | b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), j); | |
3479 | ALL_BLOCK_SYMBOLS (b, i, tmp_sym) if (sym == tmp_sym) | |
14f9c5c9 | 3480 | return s; |
d2e4a39e AS |
3481 | } |
3482 | break; | |
3483 | default: | |
3484 | break; | |
3485 | } | |
3486 | } | |
14f9c5c9 AS |
3487 | return NULL; |
3488 | } | |
3489 | ||
3490 | /* Return a minimal symbol matching NAME according to Ada demangling | |
3491 | rules. Returns NULL if there is no such minimal symbol. */ | |
3492 | ||
d2e4a39e AS |
3493 | struct minimal_symbol * |
3494 | ada_lookup_minimal_symbol (const char *name) | |
14f9c5c9 | 3495 | { |
d2e4a39e AS |
3496 | struct objfile *objfile; |
3497 | struct minimal_symbol *msymbol; | |
14f9c5c9 AS |
3498 | int wild_match = (strstr (name, "__") == NULL); |
3499 | ||
3500 | ALL_MSYMBOLS (objfile, msymbol) | |
d2e4a39e AS |
3501 | { |
3502 | if (ada_match_name (SYMBOL_NAME (msymbol), name, wild_match) | |
3503 | && MSYMBOL_TYPE (msymbol) != mst_solib_trampoline) | |
3504 | return msymbol; | |
3505 | } | |
14f9c5c9 AS |
3506 | |
3507 | return NULL; | |
3508 | } | |
3509 | ||
3510 | /* For all subprograms that statically enclose the subprogram of the | |
3511 | * selected frame, add symbols matching identifier NAME in NAMESPACE | |
3512 | * and their blocks to vectors *defn_symbols and *defn_blocks, as for | |
3513 | * ada_add_block_symbols (q.v.). If WILD, treat as NAME with a | |
3514 | * wildcard prefix. At the moment, this function uses a heuristic to | |
3515 | * find the frames of enclosing subprograms: it treats the | |
3516 | * pointer-sized value at location 0 from the local-variable base of a | |
3517 | * frame as a static link, and then searches up the call stack for a | |
3518 | * frame with that same local-variable base. */ | |
3519 | static void | |
d2e4a39e AS |
3520 | add_symbols_from_enclosing_procs (const char *name, namespace_enum namespace, |
3521 | int wild_match) | |
14f9c5c9 AS |
3522 | { |
3523 | #ifdef i386 | |
3524 | static struct symbol static_link_sym; | |
3525 | static struct symbol *static_link; | |
3526 | ||
d2e4a39e AS |
3527 | struct cleanup *old_chain = make_cleanup (null_cleanup, NULL); |
3528 | struct frame_info *frame; | |
3529 | struct frame_info *target_frame; | |
14f9c5c9 AS |
3530 | |
3531 | if (static_link == NULL) | |
3532 | { | |
3533 | /* Initialize the local variable symbol that stands for the | |
3534 | * static link (when it exists). */ | |
3535 | static_link = &static_link_sym; | |
3536 | SYMBOL_NAME (static_link) = ""; | |
3537 | SYMBOL_LANGUAGE (static_link) = language_unknown; | |
3538 | SYMBOL_CLASS (static_link) = LOC_LOCAL; | |
3539 | SYMBOL_NAMESPACE (static_link) = VAR_NAMESPACE; | |
3540 | SYMBOL_TYPE (static_link) = lookup_pointer_type (builtin_type_void); | |
d2e4a39e AS |
3541 | SYMBOL_VALUE (static_link) = |
3542 | -(long) TYPE_LENGTH (SYMBOL_TYPE (static_link)); | |
14f9c5c9 AS |
3543 | } |
3544 | ||
3545 | frame = selected_frame; | |
3546 | while (frame != NULL && ndefns == 0) | |
3547 | { | |
d2e4a39e AS |
3548 | struct block *block; |
3549 | struct value *target_link_val = read_var_value (static_link, frame); | |
14f9c5c9 AS |
3550 | CORE_ADDR target_link; |
3551 | ||
3552 | if (target_link_val == NULL) | |
3553 | break; | |
3554 | QUIT; | |
3555 | ||
3556 | target_link = target_link_val; | |
d2e4a39e AS |
3557 | do |
3558 | { | |
14f9c5c9 AS |
3559 | QUIT; |
3560 | frame = get_prev_frame (frame); | |
d2e4a39e AS |
3561 | } |
3562 | while (frame != NULL && FRAME_LOCALS_ADDRESS (frame) != target_link); | |
14f9c5c9 AS |
3563 | |
3564 | if (frame == NULL) | |
3565 | break; | |
3566 | ||
3567 | block = get_frame_block (frame, 0); | |
3568 | while (block != NULL && block_function (block) != NULL && ndefns == 0) | |
3569 | { | |
3570 | ada_add_block_symbols (block, name, namespace, NULL, wild_match); | |
d2e4a39e | 3571 | |
14f9c5c9 AS |
3572 | block = BLOCK_SUPERBLOCK (block); |
3573 | } | |
3574 | } | |
3575 | ||
3576 | do_cleanups (old_chain); | |
3577 | #endif | |
3578 | } | |
3579 | ||
3580 | /* True if TYPE is definitely an artificial type supplied to a symbol | |
3581 | * for which no debugging information was given in the symbol file. */ | |
3582 | static int | |
d2e4a39e | 3583 | is_nondebugging_type (struct type *type) |
14f9c5c9 | 3584 | { |
d2e4a39e | 3585 | char *name = ada_type_name (type); |
14f9c5c9 AS |
3586 | return (name != NULL && STREQ (name, "<variable, no debug info>")); |
3587 | } | |
3588 | ||
3589 | /* Remove any non-debugging symbols in SYMS[0 .. NSYMS-1] that definitely | |
3590 | * duplicate other symbols in the list. (The only case I know of where | |
3591 | * this happens is when object files containing stabs-in-ecoff are | |
3592 | * linked with files containing ordinary ecoff debugging symbols (or no | |
3593 | * debugging symbols)). Modifies SYMS to squeeze out deleted symbols, | |
3594 | * and applies the same modification to BLOCKS to maintain the | |
3595 | * correspondence between SYMS[i] and BLOCKS[i]. Returns the number | |
3596 | * of symbols in the modified list. */ | |
3597 | static int | |
d2e4a39e | 3598 | remove_extra_symbols (struct symbol **syms, struct block **blocks, int nsyms) |
14f9c5c9 AS |
3599 | { |
3600 | int i, j; | |
3601 | ||
3602 | i = 0; | |
3603 | while (i < nsyms) | |
3604 | { | |
d2e4a39e AS |
3605 | if (SYMBOL_NAME (syms[i]) != NULL |
3606 | && SYMBOL_CLASS (syms[i]) == LOC_STATIC | |
14f9c5c9 AS |
3607 | && is_nondebugging_type (SYMBOL_TYPE (syms[i]))) |
3608 | { | |
3609 | for (j = 0; j < nsyms; j += 1) | |
3610 | { | |
d2e4a39e | 3611 | if (i != j |
14f9c5c9 AS |
3612 | && SYMBOL_NAME (syms[j]) != NULL |
3613 | && STREQ (SYMBOL_NAME (syms[i]), SYMBOL_NAME (syms[j])) | |
3614 | && SYMBOL_CLASS (syms[i]) == SYMBOL_CLASS (syms[j]) | |
d2e4a39e | 3615 | && SYMBOL_VALUE_ADDRESS (syms[i]) |
14f9c5c9 AS |
3616 | == SYMBOL_VALUE_ADDRESS (syms[j])) |
3617 | { | |
3618 | int k; | |
d2e4a39e | 3619 | for (k = i + 1; k < nsyms; k += 1) |
14f9c5c9 | 3620 | { |
d2e4a39e AS |
3621 | syms[k - 1] = syms[k]; |
3622 | blocks[k - 1] = blocks[k]; | |
14f9c5c9 AS |
3623 | } |
3624 | nsyms -= 1; | |
3625 | goto NextSymbol; | |
3626 | } | |
3627 | } | |
3628 | } | |
3629 | i += 1; | |
3630 | NextSymbol: | |
3631 | ; | |
3632 | } | |
3633 | return nsyms; | |
3634 | } | |
3635 | ||
3636 | /* Find symbols in NAMESPACE matching NAME, in BLOCK0 and enclosing | |
3637 | scope and in global scopes, returning the number of matches. Sets | |
3638 | *SYMS to point to a vector of matching symbols, with *BLOCKS | |
3639 | pointing to the vector of corresponding blocks in which those | |
3640 | symbols reside. These two vectors are transient---good only to the | |
3641 | next call of ada_lookup_symbol_list. Any non-function/non-enumeral symbol | |
3642 | match within the nest of blocks whose innermost member is BLOCK0, | |
3643 | is the outermost match returned (no other matches in that or | |
3644 | enclosing blocks is returned). If there are any matches in or | |
3645 | surrounding BLOCK0, then these alone are returned. */ | |
3646 | ||
3647 | int | |
ebf56fd3 | 3648 | ada_lookup_symbol_list (const char *name, struct block *block0, |
d2e4a39e AS |
3649 | namespace_enum namespace, struct symbol ***syms, |
3650 | struct block ***blocks) | |
14f9c5c9 AS |
3651 | { |
3652 | struct symbol *sym; | |
3653 | struct symtab *s; | |
3654 | struct partial_symtab *ps; | |
3655 | struct blockvector *bv; | |
3656 | struct objfile *objfile; | |
3657 | struct block *b; | |
3658 | struct block *block; | |
3659 | struct minimal_symbol *msymbol; | |
3660 | int wild_match = (strstr (name, "__") == NULL); | |
3661 | int cacheIfUnique; | |
3662 | ||
3663 | #ifdef TIMING | |
3664 | markTimeStart (0); | |
3665 | #endif | |
3666 | ||
3667 | ndefns = 0; | |
3668 | cacheIfUnique = 0; | |
3669 | ||
3670 | /* Search specified block and its superiors. */ | |
3671 | ||
3672 | block = block0; | |
3673 | while (block != NULL) | |
3674 | { | |
3675 | ada_add_block_symbols (block, name, namespace, NULL, wild_match); | |
3676 | ||
3677 | /* If we found a non-function match, assume that's the one. */ | |
3678 | if (is_nonfunction (defn_symbols, ndefns)) | |
3679 | goto done; | |
3680 | ||
3681 | block = BLOCK_SUPERBLOCK (block); | |
3682 | } | |
3683 | ||
3684 | /* If we found ANY matches in the specified BLOCK, we're done. */ | |
3685 | ||
3686 | if (ndefns > 0) | |
3687 | goto done; | |
d2e4a39e | 3688 | |
14f9c5c9 AS |
3689 | cacheIfUnique = 1; |
3690 | ||
3691 | /* Now add symbols from all global blocks: symbol tables, minimal symbol | |
3692 | tables, and psymtab's */ | |
3693 | ||
3694 | ALL_SYMTABS (objfile, s) | |
d2e4a39e AS |
3695 | { |
3696 | QUIT; | |
3697 | if (!s->primary) | |
3698 | continue; | |
3699 | bv = BLOCKVECTOR (s); | |
3700 | block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); | |
3701 | ada_add_block_symbols (block, name, namespace, objfile, wild_match); | |
3702 | } | |
14f9c5c9 AS |
3703 | |
3704 | if (namespace == VAR_NAMESPACE) | |
3705 | { | |
3706 | ALL_MSYMBOLS (objfile, msymbol) | |
d2e4a39e AS |
3707 | { |
3708 | if (ada_match_name (SYMBOL_NAME (msymbol), name, wild_match)) | |
3709 | { | |
3710 | switch (MSYMBOL_TYPE (msymbol)) | |
3711 | { | |
3712 | case mst_solib_trampoline: | |
3713 | break; | |
3714 | default: | |
3715 | s = find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol)); | |
3716 | if (s != NULL) | |
3717 | { | |
3718 | int old_ndefns = ndefns; | |
3719 | QUIT; | |
3720 | bv = BLOCKVECTOR (s); | |
3721 | block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); | |
3722 | ada_add_block_symbols (block, | |
3723 | SYMBOL_NAME (msymbol), | |
3724 | namespace, objfile, wild_match); | |
3725 | if (ndefns == old_ndefns) | |
3726 | { | |
3727 | block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK); | |
3728 | ada_add_block_symbols (block, | |
3729 | SYMBOL_NAME (msymbol), | |
3730 | namespace, objfile, | |
3731 | wild_match); | |
3732 | } | |
3733 | } | |
3734 | } | |
3735 | } | |
3736 | } | |
14f9c5c9 | 3737 | } |
d2e4a39e | 3738 | |
14f9c5c9 | 3739 | ALL_PSYMTABS (objfile, ps) |
d2e4a39e AS |
3740 | { |
3741 | QUIT; | |
3742 | if (!ps->readin | |
3743 | && ada_lookup_partial_symbol (ps, name, 1, namespace, wild_match)) | |
3744 | { | |
3745 | s = PSYMTAB_TO_SYMTAB (ps); | |
3746 | if (!s->primary) | |
3747 | continue; | |
3748 | bv = BLOCKVECTOR (s); | |
3749 | block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); | |
3750 | ada_add_block_symbols (block, name, namespace, objfile, wild_match); | |
3751 | } | |
3752 | } | |
3753 | ||
14f9c5c9 AS |
3754 | /* Now add symbols from all per-file blocks if we've gotten no hits. |
3755 | (Not strictly correct, but perhaps better than an error). | |
3756 | Do the symtabs first, then check the psymtabs */ | |
d2e4a39e | 3757 | |
14f9c5c9 AS |
3758 | if (ndefns == 0) |
3759 | { | |
3760 | ||
3761 | ALL_SYMTABS (objfile, s) | |
d2e4a39e AS |
3762 | { |
3763 | QUIT; | |
3764 | if (!s->primary) | |
3765 | continue; | |
3766 | bv = BLOCKVECTOR (s); | |
3767 | block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK); | |
3768 | ada_add_block_symbols (block, name, namespace, objfile, wild_match); | |
3769 | } | |
3770 | ||
14f9c5c9 | 3771 | ALL_PSYMTABS (objfile, ps) |
d2e4a39e AS |
3772 | { |
3773 | QUIT; | |
3774 | if (!ps->readin | |
3775 | && ada_lookup_partial_symbol (ps, name, 0, namespace, wild_match)) | |
3776 | { | |
3777 | s = PSYMTAB_TO_SYMTAB (ps); | |
3778 | bv = BLOCKVECTOR (s); | |
3779 | if (!s->primary) | |
3780 | continue; | |
3781 | block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK); | |
3782 | ada_add_block_symbols (block, name, namespace, | |
3783 | objfile, wild_match); | |
3784 | } | |
3785 | } | |
3786 | } | |
14f9c5c9 AS |
3787 | |
3788 | /* Finally, we try to find NAME as a local symbol in some lexically | |
3789 | enclosing block. We do this last, expecting this case to be | |
3790 | rare. */ | |
d2e4a39e | 3791 | if (ndefns == 0) |
14f9c5c9 AS |
3792 | { |
3793 | add_symbols_from_enclosing_procs (name, namespace, wild_match); | |
3794 | if (ndefns > 0) | |
3795 | goto done; | |
3796 | } | |
3797 | ||
d2e4a39e | 3798 | done: |
14f9c5c9 AS |
3799 | ndefns = remove_extra_symbols (defn_symbols, defn_blocks, ndefns); |
3800 | ||
3801 | ||
3802 | *syms = defn_symbols; | |
3803 | *blocks = defn_blocks; | |
3804 | #ifdef TIMING | |
3805 | markTimeStop (0); | |
3806 | #endif | |
3807 | return ndefns; | |
3808 | } | |
3809 | ||
3810 | /* Return a symbol in NAMESPACE matching NAME, in BLOCK0 and enclosing | |
3811 | * scope and in global scopes, or NULL if none. NAME is folded to | |
3812 | * lower case first, unless it is surrounded in single quotes. | |
3813 | * Otherwise, the result is as for ada_lookup_symbol_list, but is | |
3814 | * disambiguated by user query if needed. */ | |
3815 | ||
d2e4a39e AS |
3816 | struct symbol * |
3817 | ada_lookup_symbol (const char *name, struct block *block0, | |
3818 | namespace_enum namespace) | |
14f9c5c9 | 3819 | { |
d2e4a39e AS |
3820 | struct symbol **candidate_syms; |
3821 | struct block **candidate_blocks; | |
14f9c5c9 AS |
3822 | int n_candidates; |
3823 | ||
3824 | n_candidates = ada_lookup_symbol_list (name, | |
3825 | block0, namespace, | |
3826 | &candidate_syms, &candidate_blocks); | |
3827 | ||
3828 | if (n_candidates == 0) | |
3829 | return NULL; | |
3830 | else if (n_candidates != 1) | |
3831 | user_select_syms (candidate_syms, candidate_blocks, n_candidates, 1); | |
3832 | ||
3833 | return candidate_syms[0]; | |
3834 | } | |
3835 | ||
3836 | ||
3837 | /* True iff STR is a possible encoded suffix of a normal Ada name | |
3838 | * that is to be ignored for matching purposes. Suffixes of parallel | |
3839 | * names (e.g., XVE) are not included here. Currently, the possible suffixes | |
3840 | * are given by the regular expression: | |
3841 | * (X[nb]*)?(__[0-9]+|\$[0-9]+|___(LJM|X([FDBUP].*|R[^T]?)))?$ | |
3842 | * | |
3843 | */ | |
3844 | static int | |
d2e4a39e | 3845 | is_name_suffix (const char *str) |
14f9c5c9 AS |
3846 | { |
3847 | int k; | |
3848 | if (str[0] == 'X') | |
3849 | { | |
3850 | str += 1; | |
d2e4a39e | 3851 | while (str[0] != '_' && str[0] != '\0') |
14f9c5c9 AS |
3852 | { |
3853 | if (str[0] != 'n' && str[0] != 'b') | |
3854 | return 0; | |
3855 | str += 1; | |
d2e4a39e | 3856 | } |
14f9c5c9 AS |
3857 | } |
3858 | if (str[0] == '\000') | |
3859 | return 1; | |
d2e4a39e | 3860 | if (str[0] == '_') |
14f9c5c9 AS |
3861 | { |
3862 | if (str[1] != '_' || str[2] == '\000') | |
3863 | return 0; | |
d2e4a39e | 3864 | if (str[2] == '_') |
14f9c5c9 | 3865 | { |
d2e4a39e | 3866 | if (STREQ (str + 3, "LJM")) |
14f9c5c9 AS |
3867 | return 1; |
3868 | if (str[3] != 'X') | |
3869 | return 0; | |
3870 | if (str[4] == 'F' || str[4] == 'D' || str[4] == 'B' || | |
3871 | str[4] == 'U' || str[4] == 'P') | |
3872 | return 1; | |
3873 | if (str[4] == 'R' && str[5] != 'T') | |
3874 | return 1; | |
3875 | return 0; | |
3876 | } | |
3877 | for (k = 2; str[k] != '\0'; k += 1) | |
3878 | if (!isdigit (str[k])) | |
3879 | return 0; | |
3880 | return 1; | |
3881 | } | |
3882 | if (str[0] == '$' && str[1] != '\000') | |
3883 | { | |
3884 | for (k = 1; str[k] != '\0'; k += 1) | |
3885 | if (!isdigit (str[k])) | |
3886 | return 0; | |
3887 | return 1; | |
3888 | } | |
3889 | return 0; | |
3890 | } | |
d2e4a39e | 3891 | |
14f9c5c9 AS |
3892 | /* True if NAME represents a name of the form A1.A2....An, n>=1 and |
3893 | * PATN[0..PATN_LEN-1] = Ak.Ak+1.....An for some k >= 1. Ignores | |
3894 | * informational suffixes of NAME (i.e., for which is_name_suffix is | |
d2e4a39e | 3895 | * true). */ |
14f9c5c9 | 3896 | static int |
d2e4a39e | 3897 | wild_match (const char *patn, int patn_len, const char *name) |
14f9c5c9 AS |
3898 | { |
3899 | int name_len; | |
3900 | int s, e; | |
3901 | ||
3902 | name_len = strlen (name); | |
d2e4a39e AS |
3903 | if (name_len >= patn_len + 5 && STREQN (name, "_ada_", 5) |
3904 | && STREQN (patn, name + 5, patn_len) | |
3905 | && is_name_suffix (name + patn_len + 5)) | |
14f9c5c9 AS |
3906 | return 1; |
3907 | ||
d2e4a39e | 3908 | while (name_len >= patn_len) |
14f9c5c9 | 3909 | { |
d2e4a39e | 3910 | if (STREQN (patn, name, patn_len) && is_name_suffix (name + patn_len)) |
14f9c5c9 | 3911 | return 1; |
d2e4a39e AS |
3912 | do |
3913 | { | |
3914 | name += 1; | |
3915 | name_len -= 1; | |
3916 | } | |
3917 | while (name_len > 0 | |
3918 | && name[0] != '.' && (name[0] != '_' || name[1] != '_')); | |
14f9c5c9 AS |
3919 | if (name_len <= 0) |
3920 | return 0; | |
3921 | if (name[0] == '_') | |
3922 | { | |
d2e4a39e | 3923 | if (!islower (name[2])) |
14f9c5c9 | 3924 | return 0; |
d2e4a39e AS |
3925 | name += 2; |
3926 | name_len -= 2; | |
14f9c5c9 AS |
3927 | } |
3928 | else | |
3929 | { | |
d2e4a39e | 3930 | if (!islower (name[1])) |
14f9c5c9 | 3931 | return 0; |
d2e4a39e AS |
3932 | name += 1; |
3933 | name_len -= 1; | |
14f9c5c9 AS |
3934 | } |
3935 | } | |
3936 | ||
3937 | return 0; | |
3938 | } | |
3939 | ||
3940 | ||
3941 | /* Add symbols from BLOCK matching identifier NAME in NAMESPACE to | |
3942 | vector *defn_symbols, updating *defn_symbols (if necessary), *SZ (the size of | |
3943 | the vector *defn_symbols), and *ndefns (the number of symbols | |
3944 | currently stored in *defn_symbols). If WILD, treat as NAME with a | |
3945 | wildcard prefix. OBJFILE is the section containing BLOCK. */ | |
3946 | ||
d2e4a39e AS |
3947 | static void |
3948 | ada_add_block_symbols (struct block *block, const char *name, | |
3949 | namespace_enum namespace, struct objfile *objfile, | |
ebf56fd3 | 3950 | int wild) |
14f9c5c9 AS |
3951 | { |
3952 | int i; | |
3953 | int name_len = strlen (name); | |
3954 | /* A matching argument symbol, if any. */ | |
3955 | struct symbol *arg_sym; | |
3956 | /* Set true when we find a matching non-argument symbol */ | |
3957 | int found_sym; | |
3958 | int is_sorted = BLOCK_SHOULD_SORT (block); | |
261397f8 | 3959 | struct symbol *sym; |
14f9c5c9 | 3960 | |
d2e4a39e AS |
3961 | arg_sym = NULL; |
3962 | found_sym = 0; | |
14f9c5c9 AS |
3963 | if (wild) |
3964 | { | |
261397f8 DJ |
3965 | struct symbol *sym; |
3966 | ALL_BLOCK_SYMBOLS (block, i, sym) | |
d2e4a39e AS |
3967 | { |
3968 | if (SYMBOL_NAMESPACE (sym) == namespace && | |
3969 | wild_match (name, name_len, SYMBOL_NAME (sym))) | |
3970 | { | |
3971 | switch (SYMBOL_CLASS (sym)) | |
3972 | { | |
3973 | case LOC_ARG: | |
3974 | case LOC_LOCAL_ARG: | |
3975 | case LOC_REF_ARG: | |
3976 | case LOC_REGPARM: | |
3977 | case LOC_REGPARM_ADDR: | |
3978 | case LOC_BASEREG_ARG: | |
3979 | arg_sym = sym; | |
3980 | break; | |
3981 | case LOC_UNRESOLVED: | |
3982 | continue; | |
3983 | default: | |
3984 | found_sym = 1; | |
3985 | fill_in_ada_prototype (sym); | |
3986 | add_defn_to_vec (fixup_symbol_section (sym, objfile), block); | |
3987 | break; | |
3988 | } | |
3989 | } | |
3990 | } | |
14f9c5c9 | 3991 | } |
d2e4a39e | 3992 | else |
14f9c5c9 AS |
3993 | { |
3994 | if (is_sorted) | |
3995 | { | |
3996 | int U; | |
d2e4a39e AS |
3997 | i = 0; |
3998 | U = BLOCK_NSYMS (block) - 1; | |
3999 | while (U - i > 4) | |
14f9c5c9 | 4000 | { |
d2e4a39e | 4001 | int M = (U + i) >> 1; |
14f9c5c9 AS |
4002 | struct symbol *sym = BLOCK_SYM (block, M); |
4003 | if (SYMBOL_NAME (sym)[0] < name[0]) | |
d2e4a39e | 4004 | i = M + 1; |
14f9c5c9 | 4005 | else if (SYMBOL_NAME (sym)[0] > name[0]) |
d2e4a39e | 4006 | U = M - 1; |
14f9c5c9 | 4007 | else if (strcmp (SYMBOL_NAME (sym), name) < 0) |
d2e4a39e | 4008 | i = M + 1; |
14f9c5c9 AS |
4009 | else |
4010 | U = M; | |
4011 | } | |
4012 | } | |
4013 | else | |
4014 | i = 0; | |
4015 | ||
261397f8 DJ |
4016 | for (; i < BLOCK_BUCKETS (block); i += 1) |
4017 | for (sym = BLOCK_BUCKET (block, i); sym != NULL; sym = sym->hash_next) | |
4018 | { | |
4019 | if (SYMBOL_NAMESPACE (sym) == namespace) | |
4020 | { | |
4021 | int cmp = strncmp (name, SYMBOL_NAME (sym), name_len); | |
14f9c5c9 | 4022 | |
d2e4a39e | 4023 | if (cmp < 0) |
261397f8 DJ |
4024 | { |
4025 | if (is_sorted) | |
4026 | { | |
4027 | i = BLOCK_BUCKETS (block); | |
4028 | break; | |
4029 | } | |
4030 | } | |
d2e4a39e AS |
4031 | else if (cmp == 0 |
4032 | && is_name_suffix (SYMBOL_NAME (sym) + name_len)) | |
261397f8 DJ |
4033 | { |
4034 | switch (SYMBOL_CLASS (sym)) | |
4035 | { | |
4036 | case LOC_ARG: | |
4037 | case LOC_LOCAL_ARG: | |
4038 | case LOC_REF_ARG: | |
4039 | case LOC_REGPARM: | |
4040 | case LOC_REGPARM_ADDR: | |
4041 | case LOC_BASEREG_ARG: | |
4042 | arg_sym = sym; | |
4043 | break; | |
4044 | case LOC_UNRESOLVED: | |
4045 | break; | |
4046 | default: | |
4047 | found_sym = 1; | |
4048 | fill_in_ada_prototype (sym); | |
4049 | add_defn_to_vec (fixup_symbol_section (sym, objfile), | |
4050 | block); | |
4051 | break; | |
4052 | } | |
4053 | } | |
4054 | } | |
4055 | } | |
14f9c5c9 AS |
4056 | } |
4057 | ||
d2e4a39e | 4058 | if (!found_sym && arg_sym != NULL) |
14f9c5c9 AS |
4059 | { |
4060 | fill_in_ada_prototype (arg_sym); | |
4061 | add_defn_to_vec (fixup_symbol_section (arg_sym, objfile), block); | |
4062 | } | |
4063 | ||
d2e4a39e | 4064 | if (!wild) |
14f9c5c9 | 4065 | { |
d2e4a39e AS |
4066 | arg_sym = NULL; |
4067 | found_sym = 0; | |
14f9c5c9 AS |
4068 | if (is_sorted) |
4069 | { | |
4070 | int U; | |
d2e4a39e AS |
4071 | i = 0; |
4072 | U = BLOCK_NSYMS (block) - 1; | |
4073 | while (U - i > 4) | |
14f9c5c9 | 4074 | { |
d2e4a39e | 4075 | int M = (U + i) >> 1; |
14f9c5c9 AS |
4076 | struct symbol *sym = BLOCK_SYM (block, M); |
4077 | if (SYMBOL_NAME (sym)[0] < '_') | |
d2e4a39e | 4078 | i = M + 1; |
14f9c5c9 | 4079 | else if (SYMBOL_NAME (sym)[0] > '_') |
d2e4a39e | 4080 | U = M - 1; |
14f9c5c9 | 4081 | else if (strcmp (SYMBOL_NAME (sym), "_ada_") < 0) |
d2e4a39e | 4082 | i = M + 1; |
14f9c5c9 AS |
4083 | else |
4084 | U = M; | |
4085 | } | |
4086 | } | |
4087 | else | |
4088 | i = 0; | |
4089 | ||
261397f8 DJ |
4090 | for (; i < BLOCK_BUCKETS (block); i += 1) |
4091 | for (sym = BLOCK_BUCKET (block, i); sym != NULL; sym = sym->hash_next) | |
4092 | { | |
4093 | struct symbol *sym = BLOCK_SYM (block, i); | |
14f9c5c9 | 4094 | |
261397f8 DJ |
4095 | if (SYMBOL_NAMESPACE (sym) == namespace) |
4096 | { | |
4097 | int cmp; | |
14f9c5c9 | 4098 | |
261397f8 | 4099 | cmp = (int) '_' - (int) SYMBOL_NAME (sym)[0]; |
d2e4a39e | 4100 | if (cmp == 0) |
261397f8 DJ |
4101 | { |
4102 | cmp = strncmp ("_ada_", SYMBOL_NAME (sym), 5); | |
4103 | if (cmp == 0) | |
4104 | cmp = strncmp (name, SYMBOL_NAME (sym) + 5, name_len); | |
4105 | } | |
4106 | ||
d2e4a39e | 4107 | if (cmp < 0) |
261397f8 DJ |
4108 | { |
4109 | if (is_sorted) | |
4110 | { | |
4111 | i = BLOCK_BUCKETS (block); | |
4112 | break; | |
4113 | } | |
4114 | } | |
d2e4a39e AS |
4115 | else if (cmp == 0 |
4116 | && is_name_suffix (SYMBOL_NAME (sym) + name_len + 5)) | |
261397f8 DJ |
4117 | { |
4118 | switch (SYMBOL_CLASS (sym)) | |
4119 | { | |
4120 | case LOC_ARG: | |
4121 | case LOC_LOCAL_ARG: | |
4122 | case LOC_REF_ARG: | |
4123 | case LOC_REGPARM: | |
4124 | case LOC_REGPARM_ADDR: | |
4125 | case LOC_BASEREG_ARG: | |
4126 | arg_sym = sym; | |
4127 | break; | |
4128 | case LOC_UNRESOLVED: | |
4129 | break; | |
4130 | default: | |
4131 | found_sym = 1; | |
4132 | fill_in_ada_prototype (sym); | |
4133 | add_defn_to_vec (fixup_symbol_section (sym, objfile), | |
4134 | block); | |
4135 | break; | |
4136 | } | |
4137 | } | |
4138 | } | |
4139 | } | |
d2e4a39e | 4140 | |
14f9c5c9 | 4141 | /* NOTE: This really shouldn't be needed for _ada_ symbols. |
d2e4a39e AS |
4142 | They aren't parameters, right? */ |
4143 | if (!found_sym && arg_sym != NULL) | |
14f9c5c9 AS |
4144 | { |
4145 | fill_in_ada_prototype (arg_sym); | |
4146 | add_defn_to_vec (fixup_symbol_section (arg_sym, objfile), block); | |
4147 | } | |
4148 | } | |
4149 | } | |
14f9c5c9 | 4150 | \f |
d2e4a39e | 4151 | |
14f9c5c9 AS |
4152 | /* Function Types */ |
4153 | ||
4154 | /* Assuming that SYM is the symbol for a function, fill in its type | |
170911c7 | 4155 | with prototype information, if it is not already there. */ |
14f9c5c9 AS |
4156 | |
4157 | static void | |
d2e4a39e | 4158 | fill_in_ada_prototype (struct symbol *func) |
14f9c5c9 | 4159 | { |
d2e4a39e | 4160 | struct block *b; |
14f9c5c9 AS |
4161 | int nargs, nsyms; |
4162 | int i; | |
d2e4a39e AS |
4163 | struct type *ftype; |
4164 | struct type *rtype; | |
14f9c5c9 | 4165 | size_t max_fields; |
261397f8 | 4166 | struct symbol *sym; |
14f9c5c9 AS |
4167 | |
4168 | if (func == NULL | |
4169 | || TYPE_CODE (SYMBOL_TYPE (func)) != TYPE_CODE_FUNC | |
4170 | || TYPE_FIELDS (SYMBOL_TYPE (func)) != NULL) | |
4171 | return; | |
4172 | ||
4173 | /* We make each function type unique, so that each may have its own */ | |
4174 | /* parameter types. This particular way of doing so wastes space: */ | |
4175 | /* it would be nicer to build the argument types while the original */ | |
4176 | /* function type is being built (FIXME). */ | |
4177 | rtype = check_typedef (TYPE_TARGET_TYPE (SYMBOL_TYPE (func))); | |
4178 | ftype = alloc_type (TYPE_OBJFILE (SYMBOL_TYPE (func))); | |
4179 | make_function_type (rtype, &ftype); | |
4180 | SYMBOL_TYPE (func) = ftype; | |
4181 | ||
4182 | b = SYMBOL_BLOCK_VALUE (func); | |
14f9c5c9 AS |
4183 | |
4184 | nargs = 0; | |
d2e4a39e AS |
4185 | max_fields = 8; |
4186 | TYPE_FIELDS (ftype) = | |
4187 | (struct field *) xmalloc (sizeof (struct field) * max_fields); | |
261397f8 | 4188 | ALL_BLOCK_SYMBOLS (b, i, sym) |
d2e4a39e AS |
4189 | { |
4190 | GROW_VECT (TYPE_FIELDS (ftype), max_fields, nargs + 1); | |
14f9c5c9 | 4191 | |
d2e4a39e AS |
4192 | switch (SYMBOL_CLASS (sym)) |
4193 | { | |
4194 | case LOC_REF_ARG: | |
4195 | case LOC_REGPARM_ADDR: | |
4196 | TYPE_FIELD_BITPOS (ftype, nargs) = nargs; | |
4197 | TYPE_FIELD_BITSIZE (ftype, nargs) = 0; | |
4198 | TYPE_FIELD_TYPE (ftype, nargs) = | |
4199 | lookup_pointer_type (check_typedef (SYMBOL_TYPE (sym))); | |
4200 | TYPE_FIELD_NAME (ftype, nargs) = SYMBOL_NAME (sym); | |
4201 | nargs += 1; | |
14f9c5c9 | 4202 | |
d2e4a39e AS |
4203 | break; |
4204 | ||
4205 | case LOC_ARG: | |
4206 | case LOC_REGPARM: | |
4207 | case LOC_LOCAL_ARG: | |
4208 | case LOC_BASEREG_ARG: | |
4209 | TYPE_FIELD_BITPOS (ftype, nargs) = nargs; | |
4210 | TYPE_FIELD_BITSIZE (ftype, nargs) = 0; | |
4211 | TYPE_FIELD_TYPE (ftype, nargs) = check_typedef (SYMBOL_TYPE (sym)); | |
4212 | TYPE_FIELD_NAME (ftype, nargs) = SYMBOL_NAME (sym); | |
4213 | nargs += 1; | |
4214 | ||
4215 | break; | |
4216 | ||
4217 | default: | |
4218 | break; | |
4219 | } | |
4220 | } | |
14f9c5c9 AS |
4221 | |
4222 | /* Re-allocate fields vector; if there are no fields, make the */ | |
4223 | /* fields pointer non-null anyway, to mark that this function type */ | |
4224 | /* has been filled in. */ | |
4225 | ||
4226 | TYPE_NFIELDS (ftype) = nargs; | |
4227 | if (nargs == 0) | |
4228 | { | |
d2e4a39e | 4229 | static struct field dummy_field = { 0, 0, 0, 0 }; |
aacb1f0a | 4230 | xfree (TYPE_FIELDS (ftype)); |
14f9c5c9 AS |
4231 | TYPE_FIELDS (ftype) = &dummy_field; |
4232 | } | |
4233 | else | |
4234 | { | |
d2e4a39e AS |
4235 | struct field *fields = |
4236 | (struct field *) TYPE_ALLOC (ftype, nargs * sizeof (struct field)); | |
4237 | memcpy ((char *) fields, | |
4238 | (char *) TYPE_FIELDS (ftype), nargs * sizeof (struct field)); | |
aacb1f0a | 4239 | xfree (TYPE_FIELDS (ftype)); |
14f9c5c9 AS |
4240 | TYPE_FIELDS (ftype) = fields; |
4241 | } | |
4242 | } | |
14f9c5c9 | 4243 | \f |
d2e4a39e | 4244 | |
14f9c5c9 AS |
4245 | /* Breakpoint-related */ |
4246 | ||
d2e4a39e AS |
4247 | char no_symtab_msg[] = |
4248 | "No symbol table is loaded. Use the \"file\" command."; | |
14f9c5c9 AS |
4249 | |
4250 | /* Assuming that LINE is pointing at the beginning of an argument to | |
4251 | 'break', return a pointer to the delimiter for the initial segment | |
4252 | of that name. This is the first ':', ' ', or end of LINE. | |
4253 | */ | |
d2e4a39e AS |
4254 | char * |
4255 | ada_start_decode_line_1 (char *line) | |
14f9c5c9 AS |
4256 | { |
4257 | /* [NOTE: strpbrk would be more elegant, but I am reluctant to be | |
4258 | the first to use such a library function in GDB code.] */ | |
d2e4a39e | 4259 | char *p; |
14f9c5c9 AS |
4260 | for (p = line; *p != '\000' && *p != ' ' && *p != ':'; p += 1) |
4261 | ; | |
4262 | return p; | |
4263 | } | |
4264 | ||
4265 | /* *SPEC points to a function and line number spec (as in a break | |
4266 | command), following any initial file name specification. | |
4267 | ||
4268 | Return all symbol table/line specfications (sals) consistent with the | |
4269 | information in *SPEC and FILE_TABLE in the | |
4270 | following sense: | |
4271 | + FILE_TABLE is null, or the sal refers to a line in the file | |
4272 | named by FILE_TABLE. | |
4273 | + If *SPEC points to an argument with a trailing ':LINENUM', | |
4274 | then the sal refers to that line (or one following it as closely as | |
4275 | possible). | |
4276 | + If *SPEC does not start with '*', the sal is in a function with | |
4277 | that name. | |
4278 | ||
4279 | Returns with 0 elements if no matching non-minimal symbols found. | |
4280 | ||
4281 | If *SPEC begins with a function name of the form <NAME>, then NAME | |
4282 | is taken as a literal name; otherwise the function name is subject | |
4283 | to the usual mangling. | |
4284 | ||
4285 | *SPEC is updated to point after the function/line number specification. | |
4286 | ||
4287 | FUNFIRSTLINE is non-zero if we desire the first line of real code | |
4288 | in each function (this is ignored in the presence of a LINENUM spec.). | |
4289 | ||
4290 | If CANONICAL is non-NULL, and if any of the sals require a | |
4291 | 'canonical line spec', then *CANONICAL is set to point to an array | |
4292 | of strings, corresponding to and equal in length to the returned | |
4293 | list of sals, such that (*CANONICAL)[i] is non-null and contains a | |
4294 | canonical line spec for the ith returned sal, if needed. If no | |
4295 | canonical line specs are required and CANONICAL is non-null, | |
4296 | *CANONICAL is set to NULL. | |
4297 | ||
4298 | A 'canonical line spec' is simply a name (in the format of the | |
4299 | breakpoint command) that uniquely identifies a breakpoint position, | |
4300 | with no further contextual information or user selection. It is | |
4301 | needed whenever the file name, function name, and line number | |
4302 | information supplied is insufficient for this unique | |
4303 | identification. Currently overloaded functions, the name '*', | |
4304 | or static functions without a filename yield a canonical line spec. | |
4305 | The array and the line spec strings are allocated on the heap; it | |
4306 | is the caller's responsibility to free them. */ | |
4307 | ||
4308 | struct symtabs_and_lines | |
d2e4a39e AS |
4309 | ada_finish_decode_line_1 (char **spec, struct symtab *file_table, |
4310 | int funfirstline, char ***canonical) | |
14f9c5c9 | 4311 | { |
d2e4a39e AS |
4312 | struct symbol **symbols; |
4313 | struct block **blocks; | |
4314 | struct block *block; | |
14f9c5c9 AS |
4315 | int n_matches, i, line_num; |
4316 | struct symtabs_and_lines selected; | |
d2e4a39e AS |
4317 | struct cleanup *old_chain = make_cleanup (null_cleanup, NULL); |
4318 | char *name; | |
14f9c5c9 AS |
4319 | |
4320 | int len; | |
d2e4a39e AS |
4321 | char *lower_name; |
4322 | char *unquoted_name; | |
14f9c5c9 AS |
4323 | |
4324 | if (file_table == NULL) | |
4325 | block = get_selected_block (NULL); | |
4326 | else | |
4327 | block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (file_table), STATIC_BLOCK); | |
4328 | ||
4329 | if (canonical != NULL) | |
d2e4a39e | 4330 | *canonical = (char **) NULL; |
14f9c5c9 AS |
4331 | |
4332 | name = *spec; | |
d2e4a39e | 4333 | if (**spec == '*') |
14f9c5c9 AS |
4334 | *spec += 1; |
4335 | else | |
4336 | { | |
d2e4a39e AS |
4337 | while (**spec != '\000' && |
4338 | !strchr (ada_completer_word_break_characters, **spec)) | |
14f9c5c9 AS |
4339 | *spec += 1; |
4340 | } | |
4341 | len = *spec - name; | |
4342 | ||
4343 | line_num = -1; | |
4344 | if (file_table != NULL && (*spec)[0] == ':' && isdigit ((*spec)[1])) | |
4345 | { | |
4346 | line_num = strtol (*spec + 1, spec, 10); | |
d2e4a39e | 4347 | while (**spec == ' ' || **spec == '\t') |
14f9c5c9 AS |
4348 | *spec += 1; |
4349 | } | |
4350 | ||
d2e4a39e | 4351 | if (name[0] == '*') |
14f9c5c9 AS |
4352 | { |
4353 | if (line_num == -1) | |
4354 | error ("Wild-card function with no line number or file name."); | |
4355 | ||
4356 | return all_sals_for_line (file_table->filename, line_num, canonical); | |
4357 | } | |
4358 | ||
4359 | if (name[0] == '\'') | |
4360 | { | |
4361 | name += 1; | |
4362 | len -= 2; | |
4363 | } | |
4364 | ||
4365 | if (name[0] == '<') | |
4366 | { | |
d2e4a39e AS |
4367 | unquoted_name = (char *) alloca (len - 1); |
4368 | memcpy (unquoted_name, name + 1, len - 2); | |
4369 | unquoted_name[len - 2] = '\000'; | |
14f9c5c9 AS |
4370 | lower_name = NULL; |
4371 | } | |
4372 | else | |
4373 | { | |
d2e4a39e | 4374 | unquoted_name = (char *) alloca (len + 1); |
14f9c5c9 AS |
4375 | memcpy (unquoted_name, name, len); |
4376 | unquoted_name[len] = '\000'; | |
d2e4a39e | 4377 | lower_name = (char *) alloca (len + 1); |
14f9c5c9 AS |
4378 | for (i = 0; i < len; i += 1) |
4379 | lower_name[i] = tolower (name[i]); | |
4380 | lower_name[len] = '\000'; | |
4381 | } | |
4382 | ||
4383 | n_matches = 0; | |
d2e4a39e AS |
4384 | if (lower_name != NULL) |
4385 | n_matches = ada_lookup_symbol_list (ada_mangle (lower_name), block, | |
14f9c5c9 AS |
4386 | VAR_NAMESPACE, &symbols, &blocks); |
4387 | if (n_matches == 0) | |
d2e4a39e | 4388 | n_matches = ada_lookup_symbol_list (unquoted_name, block, |
14f9c5c9 AS |
4389 | VAR_NAMESPACE, &symbols, &blocks); |
4390 | if (n_matches == 0 && line_num >= 0) | |
4391 | error ("No line number information found for %s.", unquoted_name); | |
4392 | else if (n_matches == 0) | |
4393 | { | |
4394 | #ifdef HPPA_COMPILER_BUG | |
4395 | /* FIXME: See comment in symtab.c::decode_line_1 */ | |
4396 | #undef volatile | |
4397 | volatile struct symtab_and_line val; | |
d2e4a39e | 4398 | #define volatile /*nothing */ |
14f9c5c9 AS |
4399 | #else |
4400 | struct symtab_and_line val; | |
4401 | #endif | |
d2e4a39e | 4402 | struct minimal_symbol *msymbol; |
14f9c5c9 AS |
4403 | |
4404 | INIT_SAL (&val); | |
4405 | ||
4406 | msymbol = NULL; | |
d2e4a39e | 4407 | if (lower_name != NULL) |
14f9c5c9 AS |
4408 | msymbol = ada_lookup_minimal_symbol (ada_mangle (lower_name)); |
4409 | if (msymbol == NULL) | |
4410 | msymbol = ada_lookup_minimal_symbol (unquoted_name); | |
4411 | if (msymbol != NULL) | |
4412 | { | |
d2e4a39e | 4413 | val.pc = SYMBOL_VALUE_ADDRESS (msymbol); |
14f9c5c9 AS |
4414 | val.section = SYMBOL_BFD_SECTION (msymbol); |
4415 | if (funfirstline) | |
4416 | { | |
4417 | val.pc += FUNCTION_START_OFFSET; | |
4418 | SKIP_PROLOGUE (val.pc); | |
4419 | } | |
4420 | selected.sals = (struct symtab_and_line *) | |
4421 | xmalloc (sizeof (struct symtab_and_line)); | |
4422 | selected.sals[0] = val; | |
4423 | selected.nelts = 1; | |
4424 | return selected; | |
d2e4a39e AS |
4425 | } |
4426 | ||
14f9c5c9 AS |
4427 | if (!have_full_symbols () && |
4428 | !have_partial_symbols () && !have_minimal_symbols ()) | |
4429 | error (no_symtab_msg); | |
4430 | ||
4431 | error ("Function \"%s\" not defined.", unquoted_name); | |
d2e4a39e | 4432 | return selected; /* for lint */ |
14f9c5c9 AS |
4433 | } |
4434 | ||
4435 | if (line_num >= 0) | |
4436 | { | |
d2e4a39e AS |
4437 | return |
4438 | find_sal_from_funcs_and_line (file_table->filename, line_num, | |
14f9c5c9 AS |
4439 | symbols, n_matches); |
4440 | } | |
4441 | else | |
4442 | { | |
d2e4a39e AS |
4443 | selected.nelts = |
4444 | user_select_syms (symbols, blocks, n_matches, n_matches); | |
14f9c5c9 AS |
4445 | } |
4446 | ||
d2e4a39e | 4447 | selected.sals = (struct symtab_and_line *) |
14f9c5c9 AS |
4448 | xmalloc (sizeof (struct symtab_and_line) * selected.nelts); |
4449 | memset (selected.sals, 0, selected.nelts * sizeof (selected.sals[i])); | |
aacb1f0a | 4450 | make_cleanup (xfree, selected.sals); |
14f9c5c9 AS |
4451 | |
4452 | i = 0; | |
4453 | while (i < selected.nelts) | |
4454 | { | |
d2e4a39e | 4455 | if (SYMBOL_CLASS (symbols[i]) == LOC_BLOCK) |
14f9c5c9 | 4456 | selected.sals[i] = find_function_start_sal (symbols[i], funfirstline); |
d2e4a39e | 4457 | else if (SYMBOL_LINE (symbols[i]) != 0) |
14f9c5c9 AS |
4458 | { |
4459 | selected.sals[i].symtab = symtab_for_sym (symbols[i]); | |
4460 | selected.sals[i].line = SYMBOL_LINE (symbols[i]); | |
4461 | } | |
4462 | else if (line_num >= 0) | |
4463 | { | |
4464 | /* Ignore this choice */ | |
d2e4a39e AS |
4465 | symbols[i] = symbols[selected.nelts - 1]; |
4466 | blocks[i] = blocks[selected.nelts - 1]; | |
14f9c5c9 AS |
4467 | selected.nelts -= 1; |
4468 | continue; | |
4469 | } | |
d2e4a39e | 4470 | else |
14f9c5c9 AS |
4471 | error ("Line number not known for symbol \"%s\"", unquoted_name); |
4472 | i += 1; | |
4473 | } | |
4474 | ||
4475 | if (canonical != NULL && (line_num >= 0 || n_matches > 1)) | |
4476 | { | |
d2e4a39e | 4477 | *canonical = (char **) xmalloc (sizeof (char *) * selected.nelts); |
14f9c5c9 | 4478 | for (i = 0; i < selected.nelts; i += 1) |
d2e4a39e AS |
4479 | (*canonical)[i] = |
4480 | extended_canonical_line_spec (selected.sals[i], | |
14f9c5c9 AS |
4481 | SYMBOL_SOURCE_NAME (symbols[i])); |
4482 | } | |
d2e4a39e | 4483 | |
14f9c5c9 AS |
4484 | discard_cleanups (old_chain); |
4485 | return selected; | |
d2e4a39e AS |
4486 | } |
4487 | ||
14f9c5c9 AS |
4488 | /* The (single) sal corresponding to line LINE_NUM in a symbol table |
4489 | with file name FILENAME that occurs in one of the functions listed | |
d2e4a39e | 4490 | in SYMBOLS[0 .. NSYMS-1]. */ |
14f9c5c9 | 4491 | static struct symtabs_and_lines |
d2e4a39e AS |
4492 | find_sal_from_funcs_and_line (const char *filename, int line_num, |
4493 | struct symbol **symbols, int nsyms) | |
14f9c5c9 AS |
4494 | { |
4495 | struct symtabs_and_lines sals; | |
4496 | int best_index, best; | |
d2e4a39e AS |
4497 | struct linetable *best_linetable; |
4498 | struct objfile *objfile; | |
4499 | struct symtab *s; | |
4500 | struct symtab *best_symtab; | |
14f9c5c9 AS |
4501 | |
4502 | read_all_symtabs (filename); | |
4503 | ||
d2e4a39e AS |
4504 | best_index = 0; |
4505 | best_linetable = NULL; | |
4506 | best_symtab = NULL; | |
14f9c5c9 AS |
4507 | best = 0; |
4508 | ALL_SYMTABS (objfile, s) | |
d2e4a39e AS |
4509 | { |
4510 | struct linetable *l; | |
4511 | int ind, exact; | |
14f9c5c9 | 4512 | |
d2e4a39e | 4513 | QUIT; |
14f9c5c9 | 4514 | |
d2e4a39e AS |
4515 | if (!STREQ (filename, s->filename)) |
4516 | continue; | |
4517 | l = LINETABLE (s); | |
4518 | ind = find_line_in_linetable (l, line_num, symbols, nsyms, &exact); | |
4519 | if (ind >= 0) | |
4520 | { | |
4521 | if (exact) | |
4522 | { | |
4523 | best_index = ind; | |
4524 | best_linetable = l; | |
4525 | best_symtab = s; | |
4526 | goto done; | |
4527 | } | |
4528 | if (best == 0 || l->item[ind].line < best) | |
4529 | { | |
4530 | best = l->item[ind].line; | |
4531 | best_index = ind; | |
4532 | best_linetable = l; | |
4533 | best_symtab = s; | |
4534 | } | |
4535 | } | |
4536 | } | |
14f9c5c9 AS |
4537 | |
4538 | if (best == 0) | |
4539 | error ("Line number not found in designated function."); | |
4540 | ||
d2e4a39e AS |
4541 | done: |
4542 | ||
14f9c5c9 | 4543 | sals.nelts = 1; |
d2e4a39e | 4544 | sals.sals = (struct symtab_and_line *) xmalloc (sizeof (sals.sals[0])); |
14f9c5c9 AS |
4545 | |
4546 | INIT_SAL (&sals.sals[0]); | |
d2e4a39e | 4547 | |
14f9c5c9 AS |
4548 | sals.sals[0].line = best_linetable->item[best_index].line; |
4549 | sals.sals[0].pc = best_linetable->item[best_index].pc; | |
4550 | sals.sals[0].symtab = best_symtab; | |
4551 | ||
4552 | return sals; | |
4553 | } | |
4554 | ||
4555 | /* Return the index in LINETABLE of the best match for LINE_NUM whose | |
4556 | pc falls within one of the functions denoted by SYMBOLS[0..NSYMS-1]. | |
4557 | Set *EXACTP to the 1 if the match is exact, and 0 otherwise. */ | |
4558 | static int | |
d2e4a39e AS |
4559 | find_line_in_linetable (struct linetable *linetable, int line_num, |
4560 | struct symbol **symbols, int nsyms, int *exactp) | |
14f9c5c9 AS |
4561 | { |
4562 | int i, len, best_index, best; | |
4563 | ||
4564 | if (line_num <= 0 || linetable == NULL) | |
4565 | return -1; | |
4566 | ||
4567 | len = linetable->nitems; | |
4568 | for (i = 0, best_index = -1, best = 0; i < len; i += 1) | |
4569 | { | |
4570 | int k; | |
d2e4a39e | 4571 | struct linetable_entry *item = &(linetable->item[i]); |
14f9c5c9 AS |
4572 | |
4573 | for (k = 0; k < nsyms; k += 1) | |
4574 | { | |
4575 | if (symbols[k] != NULL && SYMBOL_CLASS (symbols[k]) == LOC_BLOCK | |
4576 | && item->pc >= BLOCK_START (SYMBOL_BLOCK_VALUE (symbols[k])) | |
4577 | && item->pc < BLOCK_END (SYMBOL_BLOCK_VALUE (symbols[k]))) | |
4578 | goto candidate; | |
4579 | } | |
4580 | continue; | |
4581 | ||
4582 | candidate: | |
4583 | ||
4584 | if (item->line == line_num) | |
4585 | { | |
4586 | *exactp = 1; | |
4587 | return i; | |
4588 | } | |
4589 | ||
4590 | if (item->line > line_num && (best == 0 || item->line < best)) | |
4591 | { | |
4592 | best = item->line; | |
4593 | best_index = i; | |
4594 | } | |
4595 | } | |
4596 | ||
4597 | *exactp = 0; | |
4598 | return best_index; | |
4599 | } | |
4600 | ||
4601 | /* Find the smallest k >= LINE_NUM such that k is a line number in | |
4602 | LINETABLE, and k falls strictly within a named function that begins at | |
4603 | or before LINE_NUM. Return -1 if there is no such k. */ | |
4604 | static int | |
d2e4a39e | 4605 | nearest_line_number_in_linetable (struct linetable *linetable, int line_num) |
14f9c5c9 AS |
4606 | { |
4607 | int i, len, best; | |
4608 | ||
4609 | if (line_num <= 0 || linetable == NULL || linetable->nitems == 0) | |
4610 | return -1; | |
4611 | len = linetable->nitems; | |
4612 | ||
d2e4a39e AS |
4613 | i = 0; |
4614 | best = INT_MAX; | |
14f9c5c9 AS |
4615 | while (i < len) |
4616 | { | |
4617 | int k; | |
d2e4a39e | 4618 | struct linetable_entry *item = &(linetable->item[i]); |
14f9c5c9 AS |
4619 | |
4620 | if (item->line >= line_num && item->line < best) | |
4621 | { | |
d2e4a39e | 4622 | char *func_name; |
14f9c5c9 AS |
4623 | CORE_ADDR start, end; |
4624 | ||
4625 | func_name = NULL; | |
4626 | find_pc_partial_function (item->pc, &func_name, &start, &end); | |
4627 | ||
4628 | if (func_name != NULL && item->pc < end) | |
4629 | { | |
4630 | if (item->line == line_num) | |
4631 | return line_num; | |
d2e4a39e | 4632 | else |
14f9c5c9 | 4633 | { |
d2e4a39e | 4634 | struct symbol *sym = |
14f9c5c9 AS |
4635 | standard_lookup (func_name, VAR_NAMESPACE); |
4636 | if (is_plausible_func_for_line (sym, line_num)) | |
4637 | best = item->line; | |
4638 | else | |
4639 | { | |
4640 | do | |
4641 | i += 1; | |
4642 | while (i < len && linetable->item[i].pc < end); | |
4643 | continue; | |
4644 | } | |
4645 | } | |
4646 | } | |
4647 | } | |
4648 | ||
4649 | i += 1; | |
4650 | } | |
4651 | ||
4652 | return (best == INT_MAX) ? -1 : best; | |
4653 | } | |
4654 | ||
4655 | ||
4656 | /* Return the next higher index, k, into LINETABLE such that k > IND, | |
4657 | entry k in LINETABLE has a line number equal to LINE_NUM, k | |
4658 | corresponds to a PC that is in a function different from that | |
4659 | corresponding to IND, and falls strictly within a named function | |
4660 | that begins at a line at or preceding STARTING_LINE. | |
4661 | Return -1 if there is no such k. | |
4662 | IND == -1 corresponds to no function. */ | |
4663 | ||
4664 | static int | |
d2e4a39e | 4665 | find_next_line_in_linetable (struct linetable *linetable, int line_num, |
ebf56fd3 | 4666 | int starting_line, int ind) |
14f9c5c9 AS |
4667 | { |
4668 | int i, len; | |
4669 | ||
4670 | if (line_num <= 0 || linetable == NULL || ind >= linetable->nitems) | |
4671 | return -1; | |
4672 | len = linetable->nitems; | |
4673 | ||
d2e4a39e | 4674 | if (ind >= 0) |
14f9c5c9 AS |
4675 | { |
4676 | CORE_ADDR start, end; | |
4677 | ||
4678 | if (find_pc_partial_function (linetable->item[ind].pc, | |
d2e4a39e | 4679 | (char **) NULL, &start, &end)) |
14f9c5c9 AS |
4680 | { |
4681 | while (ind < len && linetable->item[ind].pc < end) | |
4682 | ind += 1; | |
4683 | } | |
4684 | else | |
4685 | ind += 1; | |
4686 | } | |
4687 | else | |
4688 | ind = 0; | |
4689 | ||
4690 | i = ind; | |
4691 | while (i < len) | |
4692 | { | |
4693 | int k; | |
d2e4a39e | 4694 | struct linetable_entry *item = &(linetable->item[i]); |
14f9c5c9 AS |
4695 | |
4696 | if (item->line >= line_num) | |
4697 | { | |
d2e4a39e | 4698 | char *func_name; |
14f9c5c9 AS |
4699 | CORE_ADDR start, end; |
4700 | ||
4701 | func_name = NULL; | |
4702 | find_pc_partial_function (item->pc, &func_name, &start, &end); | |
4703 | ||
4704 | if (func_name != NULL && item->pc < end) | |
4705 | { | |
4706 | if (item->line == line_num) | |
4707 | { | |
d2e4a39e | 4708 | struct symbol *sym = |
14f9c5c9 AS |
4709 | standard_lookup (func_name, VAR_NAMESPACE); |
4710 | if (is_plausible_func_for_line (sym, starting_line)) | |
4711 | return i; | |
4712 | else | |
4713 | { | |
d2e4a39e | 4714 | while ((i + 1) < len && linetable->item[i + 1].pc < end) |
14f9c5c9 AS |
4715 | i += 1; |
4716 | } | |
4717 | } | |
4718 | } | |
4719 | } | |
4720 | i += 1; | |
4721 | } | |
4722 | ||
4723 | return -1; | |
4724 | } | |
4725 | ||
4726 | /* True iff function symbol SYM starts somewhere at or before line # | |
4727 | LINE_NUM. */ | |
4728 | static int | |
d2e4a39e | 4729 | is_plausible_func_for_line (struct symbol *sym, int line_num) |
14f9c5c9 AS |
4730 | { |
4731 | struct symtab_and_line start_sal; | |
4732 | ||
4733 | if (sym == NULL) | |
4734 | return 0; | |
4735 | ||
4736 | start_sal = find_function_start_sal (sym, 0); | |
4737 | ||
4738 | return (start_sal.line != 0 && line_num >= start_sal.line); | |
4739 | } | |
4740 | ||
4741 | static void | |
d2e4a39e | 4742 | debug_print_lines (struct linetable *lt) |
14f9c5c9 AS |
4743 | { |
4744 | int i; | |
4745 | ||
d2e4a39e | 4746 | if (lt == NULL) |
14f9c5c9 AS |
4747 | return; |
4748 | ||
4749 | fprintf (stderr, "\t"); | |
4750 | for (i = 0; i < lt->nitems; i += 1) | |
4751 | fprintf (stderr, "(%d->%p) ", lt->item[i].line, (void *) lt->item[i].pc); | |
4752 | fprintf (stderr, "\n"); | |
4753 | } | |
4754 | ||
4755 | static void | |
d2e4a39e | 4756 | debug_print_block (struct block *b) |
14f9c5c9 AS |
4757 | { |
4758 | int i; | |
261397f8 DJ |
4759 | struct symbol *i; |
4760 | ||
d2e4a39e AS |
4761 | fprintf (stderr, "Block: %p; [0x%lx, 0x%lx]", |
4762 | b, BLOCK_START (b), BLOCK_END (b)); | |
4763 | if (BLOCK_FUNCTION (b) != NULL) | |
4764 | fprintf (stderr, " Function: %s", SYMBOL_NAME (BLOCK_FUNCTION (b))); | |
14f9c5c9 | 4765 | fprintf (stderr, "\n"); |
d2e4a39e | 4766 | fprintf (stderr, "\t Superblock: %p\n", BLOCK_SUPERBLOCK (b)); |
14f9c5c9 | 4767 | fprintf (stderr, "\t Symbols:"); |
261397f8 | 4768 | ALL_BLOCK_SYMBOLS (b, i, sym) |
d2e4a39e AS |
4769 | { |
4770 | if (i > 0 && i % 4 == 0) | |
4771 | fprintf (stderr, "\n\t\t "); | |
4772 | fprintf (stderr, " %s", SYMBOL_NAME (sym)); | |
4773 | } | |
14f9c5c9 AS |
4774 | fprintf (stderr, "\n"); |
4775 | } | |
4776 | ||
4777 | static void | |
d2e4a39e | 4778 | debug_print_blocks (struct blockvector *bv) |
14f9c5c9 AS |
4779 | { |
4780 | int i; | |
4781 | ||
4782 | if (bv == NULL) | |
4783 | return; | |
d2e4a39e AS |
4784 | for (i = 0; i < BLOCKVECTOR_NBLOCKS (bv); i += 1) |
4785 | { | |
4786 | fprintf (stderr, "%6d. ", i); | |
4787 | debug_print_block (BLOCKVECTOR_BLOCK (bv, i)); | |
4788 | } | |
14f9c5c9 AS |
4789 | } |
4790 | ||
4791 | static void | |
d2e4a39e | 4792 | debug_print_symtab (struct symtab *s) |
14f9c5c9 AS |
4793 | { |
4794 | fprintf (stderr, "Symtab %p\n File: %s; Dir: %s\n", s, | |
4795 | s->filename, s->dirname); | |
4796 | fprintf (stderr, " Blockvector: %p, Primary: %d\n", | |
d2e4a39e AS |
4797 | BLOCKVECTOR (s), s->primary); |
4798 | debug_print_blocks (BLOCKVECTOR (s)); | |
14f9c5c9 | 4799 | fprintf (stderr, " Line table: %p\n", LINETABLE (s)); |
d2e4a39e | 4800 | debug_print_lines (LINETABLE (s)); |
14f9c5c9 AS |
4801 | } |
4802 | ||
4803 | /* Read in all symbol tables corresponding to partial symbol tables | |
4804 | with file name FILENAME. */ | |
4805 | static void | |
d2e4a39e | 4806 | read_all_symtabs (const char *filename) |
14f9c5c9 | 4807 | { |
d2e4a39e AS |
4808 | struct partial_symtab *ps; |
4809 | struct objfile *objfile; | |
14f9c5c9 AS |
4810 | |
4811 | ALL_PSYMTABS (objfile, ps) | |
d2e4a39e AS |
4812 | { |
4813 | QUIT; | |
14f9c5c9 | 4814 | |
d2e4a39e AS |
4815 | if (STREQ (filename, ps->filename)) |
4816 | PSYMTAB_TO_SYMTAB (ps); | |
4817 | } | |
14f9c5c9 AS |
4818 | } |
4819 | ||
4820 | /* All sals corresponding to line LINE_NUM in a symbol table from file | |
4821 | FILENAME, as filtered by the user. If CANONICAL is not null, set | |
4822 | it to a corresponding array of canonical line specs. */ | |
4823 | static struct symtabs_and_lines | |
d2e4a39e | 4824 | all_sals_for_line (const char *filename, int line_num, char ***canonical) |
14f9c5c9 AS |
4825 | { |
4826 | struct symtabs_and_lines result; | |
d2e4a39e AS |
4827 | struct objfile *objfile; |
4828 | struct symtab *s; | |
4829 | struct cleanup *old_chain = make_cleanup (null_cleanup, NULL); | |
14f9c5c9 AS |
4830 | size_t len; |
4831 | ||
4832 | read_all_symtabs (filename); | |
4833 | ||
d2e4a39e AS |
4834 | result.sals = |
4835 | (struct symtab_and_line *) xmalloc (4 * sizeof (result.sals[0])); | |
14f9c5c9 AS |
4836 | result.nelts = 0; |
4837 | len = 4; | |
4838 | make_cleanup (free_current_contents, &result.sals); | |
4839 | ||
d2e4a39e AS |
4840 | ALL_SYMTABS (objfile, s) |
4841 | { | |
4842 | int ind, target_line_num; | |
14f9c5c9 | 4843 | |
d2e4a39e | 4844 | QUIT; |
14f9c5c9 | 4845 | |
d2e4a39e AS |
4846 | if (!STREQ (s->filename, filename)) |
4847 | continue; | |
14f9c5c9 | 4848 | |
d2e4a39e AS |
4849 | target_line_num = |
4850 | nearest_line_number_in_linetable (LINETABLE (s), line_num); | |
4851 | if (target_line_num == -1) | |
4852 | continue; | |
14f9c5c9 | 4853 | |
d2e4a39e AS |
4854 | ind = -1; |
4855 | while (1) | |
4856 | { | |
4857 | ind = | |
4858 | find_next_line_in_linetable (LINETABLE (s), | |
4859 | target_line_num, line_num, ind); | |
14f9c5c9 | 4860 | |
d2e4a39e AS |
4861 | if (ind < 0) |
4862 | break; | |
4863 | ||
4864 | GROW_VECT (result.sals, len, result.nelts + 1); | |
4865 | INIT_SAL (&result.sals[result.nelts]); | |
4866 | result.sals[result.nelts].line = LINETABLE (s)->item[ind].line; | |
4867 | result.sals[result.nelts].pc = LINETABLE (s)->item[ind].pc; | |
4868 | result.sals[result.nelts].symtab = s; | |
4869 | result.nelts += 1; | |
4870 | } | |
4871 | } | |
14f9c5c9 AS |
4872 | |
4873 | if (canonical != NULL || result.nelts > 1) | |
4874 | { | |
4875 | int k; | |
d2e4a39e | 4876 | char **func_names = (char **) alloca (result.nelts * sizeof (char *)); |
14f9c5c9 AS |
4877 | int first_choice = (result.nelts > 1) ? 2 : 1; |
4878 | int n; | |
d2e4a39e AS |
4879 | int *choices = (int *) alloca (result.nelts * sizeof (int)); |
4880 | ||
4881 | for (k = 0; k < result.nelts; k += 1) | |
14f9c5c9 | 4882 | { |
d2e4a39e AS |
4883 | find_pc_partial_function (result.sals[k].pc, &func_names[k], |
4884 | (CORE_ADDR *) NULL, (CORE_ADDR *) NULL); | |
14f9c5c9 AS |
4885 | if (func_names[k] == NULL) |
4886 | error ("Could not find function for one or more breakpoints."); | |
4887 | } | |
d2e4a39e AS |
4888 | |
4889 | if (result.nelts > 1) | |
14f9c5c9 | 4890 | { |
d2e4a39e AS |
4891 | printf_unfiltered ("[0] cancel\n"); |
4892 | if (result.nelts > 1) | |
4893 | printf_unfiltered ("[1] all\n"); | |
14f9c5c9 | 4894 | for (k = 0; k < result.nelts; k += 1) |
d2e4a39e | 4895 | printf_unfiltered ("[%d] %s\n", k + first_choice, |
14f9c5c9 | 4896 | ada_demangle (func_names[k])); |
d2e4a39e | 4897 | |
14f9c5c9 AS |
4898 | n = get_selections (choices, result.nelts, result.nelts, |
4899 | result.nelts > 1, "instance-choice"); | |
d2e4a39e AS |
4900 | |
4901 | for (k = 0; k < n; k += 1) | |
14f9c5c9 AS |
4902 | { |
4903 | result.sals[k] = result.sals[choices[k]]; | |
4904 | func_names[k] = func_names[choices[k]]; | |
4905 | } | |
4906 | result.nelts = n; | |
4907 | } | |
4908 | ||
d2e4a39e | 4909 | if (canonical != NULL) |
14f9c5c9 | 4910 | { |
d2e4a39e | 4911 | *canonical = (char **) xmalloc (result.nelts * sizeof (char **)); |
aacb1f0a | 4912 | make_cleanup (xfree, *canonical); |
d2e4a39e | 4913 | for (k = 0; k < result.nelts; k += 1) |
14f9c5c9 | 4914 | { |
d2e4a39e | 4915 | (*canonical)[k] = |
14f9c5c9 AS |
4916 | extended_canonical_line_spec (result.sals[k], func_names[k]); |
4917 | if ((*canonical)[k] == NULL) | |
4918 | error ("Could not locate one or more breakpoints."); | |
aacb1f0a | 4919 | make_cleanup (xfree, (*canonical)[k]); |
14f9c5c9 AS |
4920 | } |
4921 | } | |
4922 | } | |
4923 | ||
4924 | discard_cleanups (old_chain); | |
4925 | return result; | |
4926 | } | |
4927 | ||
4928 | ||
4929 | /* A canonical line specification of the form FILE:NAME:LINENUM for | |
4930 | symbol table and line data SAL. NULL if insufficient | |
4931 | information. The caller is responsible for releasing any space | |
4932 | allocated. */ | |
4933 | ||
d2e4a39e AS |
4934 | static char * |
4935 | extended_canonical_line_spec (struct symtab_and_line sal, const char *name) | |
14f9c5c9 | 4936 | { |
d2e4a39e | 4937 | char *r; |
14f9c5c9 | 4938 | |
d2e4a39e | 4939 | if (sal.symtab == NULL || sal.symtab->filename == NULL || sal.line <= 0) |
14f9c5c9 AS |
4940 | return NULL; |
4941 | ||
d2e4a39e AS |
4942 | r = (char *) xmalloc (strlen (name) + strlen (sal.symtab->filename) |
4943 | + sizeof (sal.line) * 3 + 3); | |
14f9c5c9 AS |
4944 | sprintf (r, "%s:'%s':%d", sal.symtab->filename, name, sal.line); |
4945 | return r; | |
4946 | } | |
4947 | ||
4948 | #if 0 | |
4949 | int begin_bnum = -1; | |
4950 | #endif | |
4951 | int begin_annotate_level = 0; | |
4952 | ||
d2e4a39e AS |
4953 | static void |
4954 | begin_cleanup (void *dummy) | |
14f9c5c9 AS |
4955 | { |
4956 | begin_annotate_level = 0; | |
4957 | } | |
4958 | ||
4959 | static void | |
ebf56fd3 | 4960 | begin_command (char *args, int from_tty) |
14f9c5c9 AS |
4961 | { |
4962 | struct minimal_symbol *msym; | |
4963 | CORE_ADDR main_program_name_addr; | |
4964 | char main_program_name[1024]; | |
d2e4a39e | 4965 | struct cleanup *old_chain = make_cleanup (begin_cleanup, NULL); |
14f9c5c9 AS |
4966 | begin_annotate_level = 2; |
4967 | ||
4968 | /* Check that there is a program to debug */ | |
4969 | if (!have_full_symbols () && !have_partial_symbols ()) | |
4970 | error ("No symbol table is loaded. Use the \"file\" command."); | |
d2e4a39e | 4971 | |
14f9c5c9 AS |
4972 | /* Check that we are debugging an Ada program */ |
4973 | /* if (ada_update_initial_language (language_unknown, NULL) != language_ada) | |
d2e4a39e AS |
4974 | error ("Cannot find the Ada initialization procedure. Is this an Ada main program?"); |
4975 | */ | |
14f9c5c9 AS |
4976 | /* FIXME: language_ada should be defined in defs.h */ |
4977 | ||
4978 | /* Get the address of the name of the main procedure */ | |
4979 | msym = lookup_minimal_symbol (ADA_MAIN_PROGRAM_SYMBOL_NAME, NULL, NULL); | |
4980 | ||
4981 | if (msym != NULL) | |
d2e4a39e AS |
4982 | { |
4983 | main_program_name_addr = SYMBOL_VALUE_ADDRESS (msym); | |
4984 | if (main_program_name_addr == 0) | |
4985 | error ("Invalid address for Ada main program name."); | |
14f9c5c9 | 4986 | |
d2e4a39e AS |
4987 | /* Read the name of the main procedure */ |
4988 | extract_string (main_program_name_addr, main_program_name); | |
14f9c5c9 | 4989 | |
d2e4a39e AS |
4990 | /* Put a temporary breakpoint in the Ada main program and run */ |
4991 | do_command ("tbreak ", main_program_name, 0); | |
4992 | do_command ("run ", args, 0); | |
4993 | } | |
14f9c5c9 | 4994 | else |
d2e4a39e AS |
4995 | { |
4996 | /* If we could not find the symbol containing the name of the | |
4997 | main program, that means that the compiler that was used to build | |
4998 | was not recent enough. In that case, we fallback to the previous | |
4999 | mechanism, which is a little bit less reliable, but has proved to work | |
5000 | in most cases. The only cases where it will fail is when the user | |
5001 | has set some breakpoints which will be hit before the end of the | |
5002 | begin command processing (eg in the initialization code). | |
5003 | ||
5004 | The begining of the main Ada subprogram is located by breaking | |
5005 | on the adainit procedure. Since we know that the binder generates | |
5006 | the call to this procedure exactly 2 calls before the call to the | |
5007 | Ada main subprogram, it is then easy to put a breakpoint on this | |
5008 | Ada main subprogram once we hit adainit. | |
5009 | */ | |
5010 | do_command ("tbreak adainit", 0); | |
5011 | do_command ("run ", args, 0); | |
5012 | do_command ("up", 0); | |
5013 | do_command ("tbreak +2", 0); | |
5014 | do_command ("continue", 0); | |
5015 | do_command ("step", 0); | |
5016 | } | |
14f9c5c9 AS |
5017 | |
5018 | do_cleanups (old_chain); | |
5019 | } | |
5020 | ||
5021 | int | |
ebf56fd3 | 5022 | is_ada_runtime_file (char *filename) |
14f9c5c9 AS |
5023 | { |
5024 | return (STREQN (filename, "s-", 2) || | |
5025 | STREQN (filename, "a-", 2) || | |
d2e4a39e | 5026 | STREQN (filename, "g-", 2) || STREQN (filename, "i-", 2)); |
14f9c5c9 AS |
5027 | } |
5028 | ||
5029 | /* find the first frame that contains debugging information and that is not | |
5030 | part of the Ada run-time, starting from fi and moving upward. */ | |
5031 | ||
5032 | int | |
ebf56fd3 | 5033 | find_printable_frame (struct frame_info *fi, int level) |
14f9c5c9 AS |
5034 | { |
5035 | struct symtab_and_line sal; | |
d2e4a39e | 5036 | |
14f9c5c9 AS |
5037 | for (; fi != NULL; level += 1, fi = get_prev_frame (fi)) |
5038 | { | |
5039 | /* If fi is not the innermost frame, that normally means that fi->pc | |
d2e4a39e AS |
5040 | points to *after* the call instruction, and we want to get the line |
5041 | containing the call, never the next line. But if the next frame is | |
5042 | a signal_handler_caller or a dummy frame, then the next frame was | |
5043 | not entered as the result of a call, and we want to get the line | |
5044 | containing fi->pc. */ | |
14f9c5c9 | 5045 | sal = |
d2e4a39e | 5046 | find_pc_line (fi->pc, |
14f9c5c9 AS |
5047 | fi->next != NULL |
5048 | && !fi->next->signal_handler_caller | |
5049 | && !frame_in_dummy (fi->next)); | |
5050 | if (sal.symtab && !is_ada_runtime_file (sal.symtab->filename)) | |
5051 | { | |
5052 | #if defined(__alpha__) && defined(__osf__) && !defined(VXWORKS_TARGET) | |
d2e4a39e AS |
5053 | /* libpthread.so contains some debugging information that prevents us |
5054 | from finding the right frame */ | |
14f9c5c9 AS |
5055 | |
5056 | if (sal.symtab->objfile && | |
5057 | STREQ (sal.symtab->objfile->name, "/usr/shlib/libpthread.so")) | |
d2e4a39e | 5058 | continue; |
14f9c5c9 AS |
5059 | #endif |
5060 | selected_frame = fi; | |
5061 | break; | |
5062 | } | |
5063 | } | |
5064 | ||
5065 | return level; | |
5066 | } | |
5067 | ||
5068 | void | |
ebf56fd3 | 5069 | ada_report_exception_break (struct breakpoint *b) |
14f9c5c9 AS |
5070 | { |
5071 | #ifdef UI_OUT | |
5072 | /* FIXME: break_on_exception should be defined in breakpoint.h */ | |
5073 | /* if (b->break_on_exception == 1) | |
d2e4a39e AS |
5074 | { |
5075 | /* Assume that cond has 16 elements, the 15th | |
5076 | being the exception *//* | |
5077 | if (b->cond && b->cond->nelts == 16) | |
5078 | { | |
5079 | ui_out_text (uiout, "on "); | |
5080 | ui_out_field_string (uiout, "exception", | |
5081 | SYMBOL_NAME (b->cond->elts[14].symbol)); | |
5082 | } | |
5083 | else | |
5084 | ui_out_text (uiout, "on all exceptions"); | |
5085 | } | |
5086 | else if (b->break_on_exception == 2) | |
5087 | ui_out_text (uiout, "on unhandled exception"); | |
5088 | else if (b->break_on_exception == 3) | |
5089 | ui_out_text (uiout, "on assert failure"); | |
5090 | #else | |
5091 | if (b->break_on_exception == 1) | |
5092 | { */ | |
5093 | /* Assume that cond has 16 elements, the 15th | |
5094 | being the exception *//* | |
5095 | if (b->cond && b->cond->nelts == 16) | |
5096 | { | |
5097 | fputs_filtered ("on ", gdb_stdout); | |
5098 | fputs_filtered (SYMBOL_NAME | |
5099 | (b->cond->elts[14].symbol), gdb_stdout); | |
5100 | } | |
5101 | else | |
5102 | fputs_filtered ("on all exceptions", gdb_stdout); | |
5103 | } | |
5104 | else if (b->break_on_exception == 2) | |
5105 | fputs_filtered ("on unhandled exception", gdb_stdout); | |
5106 | else if (b->break_on_exception == 3) | |
5107 | fputs_filtered ("on assert failure", gdb_stdout); | |
5108 | */ | |
14f9c5c9 AS |
5109 | #endif |
5110 | } | |
5111 | ||
5112 | int | |
d2e4a39e | 5113 | ada_is_exception_sym (struct symbol *sym) |
14f9c5c9 AS |
5114 | { |
5115 | char *type_name = type_name_no_tag (SYMBOL_TYPE (sym)); | |
d2e4a39e | 5116 | |
14f9c5c9 AS |
5117 | return (SYMBOL_CLASS (sym) != LOC_TYPEDEF |
5118 | && SYMBOL_CLASS (sym) != LOC_BLOCK | |
5119 | && SYMBOL_CLASS (sym) != LOC_CONST | |
d2e4a39e | 5120 | && type_name != NULL && STREQ (type_name, "exception")); |
14f9c5c9 AS |
5121 | } |
5122 | ||
5123 | int | |
d2e4a39e | 5124 | ada_maybe_exception_partial_symbol (struct partial_symbol *sym) |
14f9c5c9 AS |
5125 | { |
5126 | return (SYMBOL_CLASS (sym) != LOC_TYPEDEF | |
5127 | && SYMBOL_CLASS (sym) != LOC_BLOCK | |
5128 | && SYMBOL_CLASS (sym) != LOC_CONST); | |
5129 | } | |
5130 | ||
5131 | /* If ARG points to an Ada exception or assert breakpoint, rewrite | |
5132 | into equivalent form. Return resulting argument string. Set | |
5133 | *BREAK_ON_EXCEPTIONP to 1 for ordinary break on exception, 2 for | |
5134 | break on unhandled, 3 for assert, 0 otherwise. */ | |
d2e4a39e AS |
5135 | char * |
5136 | ada_breakpoint_rewrite (char *arg, int *break_on_exceptionp) | |
14f9c5c9 AS |
5137 | { |
5138 | if (arg == NULL) | |
5139 | return arg; | |
5140 | *break_on_exceptionp = 0; | |
d2e4a39e | 5141 | /* FIXME: language_ada should be defined in defs.h */ |
14f9c5c9 | 5142 | /* if (current_language->la_language == language_ada |
d2e4a39e AS |
5143 | && STREQN (arg, "exception", 9) && |
5144 | (arg[9] == ' ' || arg[9] == '\t' || arg[9] == '\0')) | |
5145 | { | |
5146 | char *tok, *end_tok; | |
5147 | int toklen; | |
5148 | ||
5149 | *break_on_exceptionp = 1; | |
5150 | ||
5151 | tok = arg+9; | |
5152 | while (*tok == ' ' || *tok == '\t') | |
5153 | tok += 1; | |
5154 | ||
5155 | end_tok = tok; | |
5156 | ||
5157 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
5158 | end_tok += 1; | |
5159 | ||
5160 | toklen = end_tok - tok; | |
5161 | ||
5162 | arg = (char*) xmalloc (sizeof ("__gnat_raise_nodefer_with_msg if " | |
5163 | "long_integer(e) = long_integer(&)") | |
5164 | + toklen + 1); | |
5165 | make_cleanup (xfree, arg); | |
5166 | if (toklen == 0) | |
5167 | strcpy (arg, "__gnat_raise_nodefer_with_msg"); | |
5168 | else if (STREQN (tok, "unhandled", toklen)) | |
5169 | { | |
5170 | *break_on_exceptionp = 2; | |
5171 | strcpy (arg, "__gnat_unhandled_exception"); | |
5172 | } | |
5173 | else | |
5174 | { | |
5175 | sprintf (arg, "__gnat_raise_nodefer_with_msg if " | |
5176 | "long_integer(e) = long_integer(&%.*s)", | |
5177 | toklen, tok); | |
5178 | } | |
5179 | } | |
5180 | else if (current_language->la_language == language_ada | |
5181 | && STREQN (arg, "assert", 6) && | |
5182 | (arg[6] == ' ' || arg[6] == '\t' || arg[6] == '\0')) | |
5183 | { | |
5184 | char *tok = arg + 6; | |
5185 | ||
5186 | *break_on_exceptionp = 3; | |
5187 | ||
5188 | arg = (char*) | |
5189 | xmalloc (sizeof ("system__assertions__raise_assert_failure") | |
5190 | + strlen (tok) + 1); | |
5191 | make_cleanup (xfree, arg); | |
5192 | sprintf (arg, "system__assertions__raise_assert_failure%s", tok); | |
5193 | } | |
5194 | */ | |
14f9c5c9 AS |
5195 | return arg; |
5196 | } | |
14f9c5c9 | 5197 | \f |
d2e4a39e | 5198 | |
14f9c5c9 AS |
5199 | /* Field Access */ |
5200 | ||
5201 | /* True if field number FIELD_NUM in struct or union type TYPE is supposed | |
5202 | to be invisible to users. */ | |
5203 | ||
5204 | int | |
ebf56fd3 | 5205 | ada_is_ignored_field (struct type *type, int field_num) |
14f9c5c9 AS |
5206 | { |
5207 | if (field_num < 0 || field_num > TYPE_NFIELDS (type)) | |
5208 | return 1; | |
d2e4a39e | 5209 | else |
14f9c5c9 | 5210 | { |
d2e4a39e | 5211 | const char *name = TYPE_FIELD_NAME (type, field_num); |
14f9c5c9 | 5212 | return (name == NULL |
d2e4a39e | 5213 | || (name[0] == '_' && !STREQN (name, "_parent", 7))); |
14f9c5c9 AS |
5214 | } |
5215 | } | |
5216 | ||
5217 | /* True iff structure type TYPE has a tag field. */ | |
5218 | ||
5219 | int | |
ebf56fd3 | 5220 | ada_is_tagged_type (struct type *type) |
14f9c5c9 AS |
5221 | { |
5222 | if (type == NULL || TYPE_CODE (type) != TYPE_CODE_STRUCT) | |
5223 | return 0; | |
5224 | ||
5225 | return (ada_lookup_struct_elt_type (type, "_tag", 1, NULL) != NULL); | |
5226 | } | |
5227 | ||
5228 | /* The type of the tag on VAL. */ | |
5229 | ||
d2e4a39e AS |
5230 | struct type * |
5231 | ada_tag_type (struct value *val) | |
14f9c5c9 AS |
5232 | { |
5233 | return ada_lookup_struct_elt_type (VALUE_TYPE (val), "_tag", 0, NULL); | |
5234 | } | |
5235 | ||
5236 | /* The value of the tag on VAL. */ | |
5237 | ||
d2e4a39e AS |
5238 | struct value * |
5239 | ada_value_tag (struct value *val) | |
14f9c5c9 AS |
5240 | { |
5241 | return ada_value_struct_elt (val, "_tag", "record"); | |
5242 | } | |
5243 | ||
5244 | /* The parent type of TYPE, or NULL if none. */ | |
5245 | ||
d2e4a39e | 5246 | struct type * |
ebf56fd3 | 5247 | ada_parent_type (struct type *type) |
14f9c5c9 AS |
5248 | { |
5249 | int i; | |
5250 | ||
5251 | CHECK_TYPEDEF (type); | |
5252 | ||
5253 | if (type == NULL || TYPE_CODE (type) != TYPE_CODE_STRUCT) | |
5254 | return NULL; | |
5255 | ||
5256 | for (i = 0; i < TYPE_NFIELDS (type); i += 1) | |
5257 | if (ada_is_parent_field (type, i)) | |
5258 | return check_typedef (TYPE_FIELD_TYPE (type, i)); | |
5259 | ||
5260 | return NULL; | |
5261 | } | |
5262 | ||
5263 | /* True iff field number FIELD_NUM of structure type TYPE contains the | |
5264 | parent-type (inherited) fields of a derived type. Assumes TYPE is | |
5265 | a structure type with at least FIELD_NUM+1 fields. */ | |
5266 | ||
5267 | int | |
ebf56fd3 | 5268 | ada_is_parent_field (struct type *type, int field_num) |
14f9c5c9 | 5269 | { |
d2e4a39e AS |
5270 | const char *name = TYPE_FIELD_NAME (check_typedef (type), field_num); |
5271 | return (name != NULL && | |
14f9c5c9 AS |
5272 | (STREQN (name, "PARENT", 6) || STREQN (name, "_parent", 7))); |
5273 | } | |
5274 | ||
5275 | /* True iff field number FIELD_NUM of structure type TYPE is a | |
5276 | transparent wrapper field (which should be silently traversed when doing | |
5277 | field selection and flattened when printing). Assumes TYPE is a | |
5278 | structure type with at least FIELD_NUM+1 fields. Such fields are always | |
5279 | structures. */ | |
5280 | ||
5281 | int | |
ebf56fd3 | 5282 | ada_is_wrapper_field (struct type *type, int field_num) |
14f9c5c9 | 5283 | { |
d2e4a39e AS |
5284 | const char *name = TYPE_FIELD_NAME (type, field_num); |
5285 | return (name != NULL | |
5286 | && (STREQN (name, "PARENT", 6) || STREQ (name, "REP") | |
14f9c5c9 AS |
5287 | || STREQN (name, "_parent", 7) |
5288 | || name[0] == 'S' || name[0] == 'R' || name[0] == 'O')); | |
5289 | } | |
5290 | ||
5291 | /* True iff field number FIELD_NUM of structure or union type TYPE | |
5292 | is a variant wrapper. Assumes TYPE is a structure type with at least | |
d2e4a39e | 5293 | FIELD_NUM+1 fields. */ |
14f9c5c9 AS |
5294 | |
5295 | int | |
ebf56fd3 | 5296 | ada_is_variant_part (struct type *type, int field_num) |
14f9c5c9 | 5297 | { |
d2e4a39e | 5298 | struct type *field_type = TYPE_FIELD_TYPE (type, field_num); |
14f9c5c9 AS |
5299 | return (TYPE_CODE (field_type) == TYPE_CODE_UNION |
5300 | || (is_dynamic_field (type, field_num) | |
d2e4a39e AS |
5301 | && TYPE_CODE (TYPE_TARGET_TYPE (field_type)) == |
5302 | TYPE_CODE_UNION)); | |
14f9c5c9 AS |
5303 | } |
5304 | ||
5305 | /* Assuming that VAR_TYPE is a variant wrapper (type of the variant part) | |
5306 | whose discriminants are contained in the record type OUTER_TYPE, | |
5307 | returns the type of the controlling discriminant for the variant. */ | |
5308 | ||
d2e4a39e | 5309 | struct type * |
ebf56fd3 | 5310 | ada_variant_discrim_type (struct type *var_type, struct type *outer_type) |
14f9c5c9 | 5311 | { |
d2e4a39e AS |
5312 | char *name = ada_variant_discrim_name (var_type); |
5313 | struct type *type = ada_lookup_struct_elt_type (outer_type, name, 1, NULL); | |
14f9c5c9 AS |
5314 | if (type == NULL) |
5315 | return builtin_type_int; | |
5316 | else | |
5317 | return type; | |
5318 | } | |
5319 | ||
5320 | /* Assuming that TYPE is the type of a variant wrapper, and FIELD_NUM is a | |
5321 | valid field number within it, returns 1 iff field FIELD_NUM of TYPE | |
5322 | represents a 'when others' clause; otherwise 0. */ | |
5323 | ||
5324 | int | |
ebf56fd3 | 5325 | ada_is_others_clause (struct type *type, int field_num) |
14f9c5c9 | 5326 | { |
d2e4a39e | 5327 | const char *name = TYPE_FIELD_NAME (type, field_num); |
14f9c5c9 AS |
5328 | return (name != NULL && name[0] == 'O'); |
5329 | } | |
5330 | ||
5331 | /* Assuming that TYPE0 is the type of the variant part of a record, | |
5332 | returns the name of the discriminant controlling the variant. The | |
5333 | value is valid until the next call to ada_variant_discrim_name. */ | |
5334 | ||
d2e4a39e | 5335 | char * |
ebf56fd3 | 5336 | ada_variant_discrim_name (struct type *type0) |
14f9c5c9 | 5337 | { |
d2e4a39e | 5338 | static char *result = NULL; |
14f9c5c9 | 5339 | static size_t result_len = 0; |
d2e4a39e AS |
5340 | struct type *type; |
5341 | const char *name; | |
5342 | const char *discrim_end; | |
5343 | const char *discrim_start; | |
14f9c5c9 AS |
5344 | |
5345 | if (TYPE_CODE (type0) == TYPE_CODE_PTR) | |
5346 | type = TYPE_TARGET_TYPE (type0); | |
5347 | else | |
5348 | type = type0; | |
5349 | ||
5350 | name = ada_type_name (type); | |
5351 | ||
5352 | if (name == NULL || name[0] == '\000') | |
5353 | return ""; | |
5354 | ||
5355 | for (discrim_end = name + strlen (name) - 6; discrim_end != name; | |
5356 | discrim_end -= 1) | |
5357 | { | |
5358 | if (STREQN (discrim_end, "___XVN", 6)) | |
5359 | break; | |
5360 | } | |
5361 | if (discrim_end == name) | |
5362 | return ""; | |
5363 | ||
d2e4a39e | 5364 | for (discrim_start = discrim_end; discrim_start != name + 3; |
14f9c5c9 AS |
5365 | discrim_start -= 1) |
5366 | { | |
d2e4a39e | 5367 | if (discrim_start == name + 1) |
14f9c5c9 | 5368 | return ""; |
d2e4a39e | 5369 | if ((discrim_start > name + 3 && STREQN (discrim_start - 3, "___", 3)) |
14f9c5c9 AS |
5370 | || discrim_start[-1] == '.') |
5371 | break; | |
5372 | } | |
5373 | ||
5374 | GROW_VECT (result, result_len, discrim_end - discrim_start + 1); | |
5375 | strncpy (result, discrim_start, discrim_end - discrim_start); | |
d2e4a39e | 5376 | result[discrim_end - discrim_start] = '\0'; |
14f9c5c9 AS |
5377 | return result; |
5378 | } | |
5379 | ||
5380 | /* Scan STR for a subtype-encoded number, beginning at position K. Put the | |
5381 | position of the character just past the number scanned in *NEW_K, | |
5382 | if NEW_K!=NULL. Put the scanned number in *R, if R!=NULL. Return 1 | |
5383 | if there was a valid number at the given position, and 0 otherwise. A | |
5384 | "subtype-encoded" number consists of the absolute value in decimal, | |
5385 | followed by the letter 'm' to indicate a negative number. Assumes 0m | |
5386 | does not occur. */ | |
5387 | ||
5388 | int | |
d2e4a39e | 5389 | ada_scan_number (const char str[], int k, LONGEST * R, int *new_k) |
14f9c5c9 AS |
5390 | { |
5391 | ULONGEST RU; | |
5392 | ||
d2e4a39e | 5393 | if (!isdigit (str[k])) |
14f9c5c9 AS |
5394 | return 0; |
5395 | ||
5396 | /* Do it the hard way so as not to make any assumption about | |
5397 | the relationship of unsigned long (%lu scan format code) and | |
5398 | LONGEST. */ | |
5399 | RU = 0; | |
5400 | while (isdigit (str[k])) | |
5401 | { | |
d2e4a39e | 5402 | RU = RU * 10 + (str[k] - '0'); |
14f9c5c9 AS |
5403 | k += 1; |
5404 | } | |
5405 | ||
d2e4a39e | 5406 | if (str[k] == 'm') |
14f9c5c9 AS |
5407 | { |
5408 | if (R != NULL) | |
d2e4a39e | 5409 | *R = (-(LONGEST) (RU - 1)) - 1; |
14f9c5c9 AS |
5410 | k += 1; |
5411 | } | |
5412 | else if (R != NULL) | |
5413 | *R = (LONGEST) RU; | |
5414 | ||
5415 | /* NOTE on the above: Technically, C does not say what the results of | |
5416 | - (LONGEST) RU or (LONGEST) -RU are for RU == largest positive | |
5417 | number representable as a LONGEST (although either would probably work | |
5418 | in most implementations). When RU>0, the locution in the then branch | |
5419 | above is always equivalent to the negative of RU. */ | |
5420 | ||
5421 | if (new_k != NULL) | |
5422 | *new_k = k; | |
5423 | return 1; | |
5424 | } | |
5425 | ||
5426 | /* Assuming that TYPE is a variant part wrapper type (a VARIANTS field), | |
5427 | and FIELD_NUM is a valid field number within it, returns 1 iff VAL is | |
5428 | in the range encoded by field FIELD_NUM of TYPE; otherwise 0. */ | |
5429 | ||
d2e4a39e | 5430 | int |
ebf56fd3 | 5431 | ada_in_variant (LONGEST val, struct type *type, int field_num) |
14f9c5c9 | 5432 | { |
d2e4a39e | 5433 | const char *name = TYPE_FIELD_NAME (type, field_num); |
14f9c5c9 AS |
5434 | int p; |
5435 | ||
5436 | p = 0; | |
5437 | while (1) | |
5438 | { | |
d2e4a39e | 5439 | switch (name[p]) |
14f9c5c9 AS |
5440 | { |
5441 | case '\0': | |
5442 | return 0; | |
5443 | case 'S': | |
5444 | { | |
5445 | LONGEST W; | |
d2e4a39e | 5446 | if (!ada_scan_number (name, p + 1, &W, &p)) |
14f9c5c9 AS |
5447 | return 0; |
5448 | if (val == W) | |
5449 | return 1; | |
5450 | break; | |
5451 | } | |
5452 | case 'R': | |
5453 | { | |
5454 | LONGEST L, U; | |
d2e4a39e AS |
5455 | if (!ada_scan_number (name, p + 1, &L, &p) |
5456 | || name[p] != 'T' || !ada_scan_number (name, p + 1, &U, &p)) | |
14f9c5c9 AS |
5457 | return 0; |
5458 | if (val >= L && val <= U) | |
5459 | return 1; | |
5460 | break; | |
5461 | } | |
5462 | case 'O': | |
5463 | return 1; | |
5464 | default: | |
5465 | return 0; | |
5466 | } | |
5467 | } | |
5468 | } | |
5469 | ||
5470 | /* Given a value ARG1 (offset by OFFSET bytes) | |
5471 | of a struct or union type ARG_TYPE, | |
5472 | extract and return the value of one of its (non-static) fields. | |
5473 | FIELDNO says which field. Differs from value_primitive_field only | |
5474 | in that it can handle packed values of arbitrary type. */ | |
5475 | ||
d2e4a39e AS |
5476 | struct value * |
5477 | ada_value_primitive_field (struct value *arg1, int offset, int fieldno, | |
ebf56fd3 | 5478 | struct type *arg_type) |
14f9c5c9 | 5479 | { |
d2e4a39e | 5480 | struct value *v; |
14f9c5c9 AS |
5481 | struct type *type; |
5482 | ||
5483 | CHECK_TYPEDEF (arg_type); | |
5484 | type = TYPE_FIELD_TYPE (arg_type, fieldno); | |
5485 | ||
5486 | /* Handle packed fields */ | |
5487 | ||
5488 | if (TYPE_FIELD_BITSIZE (arg_type, fieldno) != 0) | |
5489 | { | |
5490 | int bit_pos = TYPE_FIELD_BITPOS (arg_type, fieldno); | |
5491 | int bit_size = TYPE_FIELD_BITSIZE (arg_type, fieldno); | |
d2e4a39e | 5492 | |
14f9c5c9 | 5493 | return ada_value_primitive_packed_val (arg1, VALUE_CONTENTS (arg1), |
d2e4a39e AS |
5494 | offset + bit_pos / 8, |
5495 | bit_pos % 8, bit_size, type); | |
14f9c5c9 AS |
5496 | } |
5497 | else | |
5498 | return value_primitive_field (arg1, offset, fieldno, arg_type); | |
5499 | } | |
5500 | ||
5501 | ||
5502 | /* Look for a field NAME in ARG. Adjust the address of ARG by OFFSET bytes, | |
5503 | and search in it assuming it has (class) type TYPE. | |
5504 | If found, return value, else return NULL. | |
5505 | ||
5506 | Searches recursively through wrapper fields (e.g., '_parent'). */ | |
5507 | ||
d2e4a39e AS |
5508 | struct value * |
5509 | ada_search_struct_field (char *name, struct value *arg, int offset, | |
ebf56fd3 | 5510 | struct type *type) |
14f9c5c9 AS |
5511 | { |
5512 | int i; | |
5513 | CHECK_TYPEDEF (type); | |
5514 | ||
d2e4a39e | 5515 | for (i = TYPE_NFIELDS (type) - 1; i >= 0; i -= 1) |
14f9c5c9 AS |
5516 | { |
5517 | char *t_field_name = TYPE_FIELD_NAME (type, i); | |
5518 | ||
5519 | if (t_field_name == NULL) | |
5520 | continue; | |
5521 | ||
5522 | else if (field_name_match (t_field_name, name)) | |
d2e4a39e | 5523 | return ada_value_primitive_field (arg, offset, i, type); |
14f9c5c9 AS |
5524 | |
5525 | else if (ada_is_wrapper_field (type, i)) | |
5526 | { | |
d2e4a39e AS |
5527 | struct value *v = ada_search_struct_field (name, arg, |
5528 | offset + | |
5529 | TYPE_FIELD_BITPOS (type, | |
5530 | i) / | |
5531 | 8, | |
5532 | TYPE_FIELD_TYPE (type, | |
5533 | i)); | |
14f9c5c9 AS |
5534 | if (v != NULL) |
5535 | return v; | |
5536 | } | |
5537 | ||
5538 | else if (ada_is_variant_part (type, i)) | |
5539 | { | |
5540 | int j; | |
5541 | struct type *field_type = check_typedef (TYPE_FIELD_TYPE (type, i)); | |
5542 | int var_offset = offset + TYPE_FIELD_BITPOS (type, i) / 8; | |
5543 | ||
5544 | for (j = TYPE_NFIELDS (field_type) - 1; j >= 0; j -= 1) | |
5545 | { | |
d2e4a39e AS |
5546 | struct value *v = ada_search_struct_field (name, arg, |
5547 | var_offset | |
5548 | + | |
5549 | TYPE_FIELD_BITPOS | |
5550 | (field_type, j) / 8, | |
5551 | TYPE_FIELD_TYPE | |
5552 | (field_type, j)); | |
14f9c5c9 AS |
5553 | if (v != NULL) |
5554 | return v; | |
5555 | } | |
5556 | } | |
5557 | } | |
5558 | return NULL; | |
5559 | } | |
d2e4a39e | 5560 | |
14f9c5c9 AS |
5561 | /* Given ARG, a value of type (pointer to a)* structure/union, |
5562 | extract the component named NAME from the ultimate target structure/union | |
5563 | and return it as a value with its appropriate type. | |
5564 | ||
5565 | The routine searches for NAME among all members of the structure itself | |
5566 | and (recursively) among all members of any wrapper members | |
5567 | (e.g., '_parent'). | |
5568 | ||
5569 | ERR is a name (for use in error messages) that identifies the class | |
5570 | of entity that ARG is supposed to be. */ | |
5571 | ||
d2e4a39e | 5572 | struct value * |
ebf56fd3 | 5573 | ada_value_struct_elt (struct value *arg, char *name, char *err) |
14f9c5c9 AS |
5574 | { |
5575 | struct type *t; | |
d2e4a39e | 5576 | struct value *v; |
14f9c5c9 AS |
5577 | |
5578 | arg = ada_coerce_ref (arg); | |
5579 | t = check_typedef (VALUE_TYPE (arg)); | |
5580 | ||
5581 | /* Follow pointers until we get to a non-pointer. */ | |
5582 | ||
5583 | while (TYPE_CODE (t) == TYPE_CODE_PTR || TYPE_CODE (t) == TYPE_CODE_REF) | |
5584 | { | |
5585 | arg = ada_value_ind (arg); | |
5586 | t = check_typedef (VALUE_TYPE (arg)); | |
5587 | } | |
5588 | ||
d2e4a39e AS |
5589 | if (TYPE_CODE (t) != TYPE_CODE_STRUCT && TYPE_CODE (t) != TYPE_CODE_UNION) |
5590 | error ("Attempt to extract a component of a value that is not a %s.", | |
5591 | err); | |
14f9c5c9 AS |
5592 | |
5593 | v = ada_search_struct_field (name, arg, 0, t); | |
5594 | if (v == NULL) | |
5595 | error ("There is no member named %s.", name); | |
5596 | ||
5597 | return v; | |
5598 | } | |
5599 | ||
5600 | /* Given a type TYPE, look up the type of the component of type named NAME. | |
5601 | If DISPP is non-null, add its byte displacement from the beginning of a | |
5602 | structure (pointed to by a value) of type TYPE to *DISPP (does not | |
5603 | work for packed fields). | |
5604 | ||
5605 | Matches any field whose name has NAME as a prefix, possibly | |
5606 | followed by "___". | |
5607 | ||
5608 | TYPE can be either a struct or union, or a pointer or reference to | |
5609 | a struct or union. If it is a pointer or reference, its target | |
5610 | type is automatically used. | |
5611 | ||
5612 | Looks recursively into variant clauses and parent types. | |
5613 | ||
5614 | If NOERR is nonzero, return NULL if NAME is not suitably defined. */ | |
5615 | ||
5616 | struct type * | |
d2e4a39e AS |
5617 | ada_lookup_struct_elt_type (struct type *type, char *name, int noerr, |
5618 | int *dispp) | |
14f9c5c9 AS |
5619 | { |
5620 | int i; | |
5621 | ||
5622 | if (name == NULL) | |
5623 | goto BadName; | |
5624 | ||
5625 | while (1) | |
5626 | { | |
5627 | CHECK_TYPEDEF (type); | |
5628 | if (TYPE_CODE (type) != TYPE_CODE_PTR | |
5629 | && TYPE_CODE (type) != TYPE_CODE_REF) | |
5630 | break; | |
5631 | type = TYPE_TARGET_TYPE (type); | |
5632 | } | |
5633 | ||
5634 | if (TYPE_CODE (type) != TYPE_CODE_STRUCT && | |
5635 | TYPE_CODE (type) != TYPE_CODE_UNION) | |
5636 | { | |
5637 | target_terminal_ours (); | |
5638 | gdb_flush (gdb_stdout); | |
5639 | fprintf_unfiltered (gdb_stderr, "Type "); | |
5640 | type_print (type, "", gdb_stderr, -1); | |
5641 | error (" is not a structure or union type"); | |
5642 | } | |
5643 | ||
5644 | type = to_static_fixed_type (type); | |
5645 | ||
5646 | for (i = 0; i < TYPE_NFIELDS (type); i += 1) | |
5647 | { | |
5648 | char *t_field_name = TYPE_FIELD_NAME (type, i); | |
5649 | struct type *t; | |
5650 | int disp; | |
d2e4a39e | 5651 | |
14f9c5c9 AS |
5652 | if (t_field_name == NULL) |
5653 | continue; | |
5654 | ||
5655 | else if (field_name_match (t_field_name, name)) | |
5656 | { | |
d2e4a39e | 5657 | if (dispp != NULL) |
14f9c5c9 AS |
5658 | *dispp += TYPE_FIELD_BITPOS (type, i) / 8; |
5659 | return check_typedef (TYPE_FIELD_TYPE (type, i)); | |
5660 | } | |
5661 | ||
5662 | else if (ada_is_wrapper_field (type, i)) | |
5663 | { | |
5664 | disp = 0; | |
d2e4a39e | 5665 | t = ada_lookup_struct_elt_type (TYPE_FIELD_TYPE (type, i), name, |
14f9c5c9 AS |
5666 | 1, &disp); |
5667 | if (t != NULL) | |
5668 | { | |
5669 | if (dispp != NULL) | |
5670 | *dispp += disp + TYPE_FIELD_BITPOS (type, i) / 8; | |
5671 | return t; | |
5672 | } | |
5673 | } | |
5674 | ||
5675 | else if (ada_is_variant_part (type, i)) | |
5676 | { | |
5677 | int j; | |
5678 | struct type *field_type = check_typedef (TYPE_FIELD_TYPE (type, i)); | |
5679 | ||
5680 | for (j = TYPE_NFIELDS (field_type) - 1; j >= 0; j -= 1) | |
5681 | { | |
5682 | disp = 0; | |
5683 | t = ada_lookup_struct_elt_type (TYPE_FIELD_TYPE (field_type, j), | |
5684 | name, 1, &disp); | |
5685 | if (t != NULL) | |
5686 | { | |
d2e4a39e | 5687 | if (dispp != NULL) |
14f9c5c9 AS |
5688 | *dispp += disp + TYPE_FIELD_BITPOS (type, i) / 8; |
5689 | return t; | |
5690 | } | |
5691 | } | |
5692 | } | |
5693 | ||
5694 | } | |
5695 | ||
5696 | BadName: | |
d2e4a39e | 5697 | if (!noerr) |
14f9c5c9 AS |
5698 | { |
5699 | target_terminal_ours (); | |
5700 | gdb_flush (gdb_stdout); | |
5701 | fprintf_unfiltered (gdb_stderr, "Type "); | |
5702 | type_print (type, "", gdb_stderr, -1); | |
5703 | fprintf_unfiltered (gdb_stderr, " has no component named "); | |
5704 | error ("%s", name == NULL ? "<null>" : name); | |
5705 | } | |
5706 | ||
5707 | return NULL; | |
5708 | } | |
5709 | ||
5710 | /* Assuming that VAR_TYPE is the type of a variant part of a record (a union), | |
5711 | within a value of type OUTER_TYPE that is stored in GDB at | |
5712 | OUTER_VALADDR, determine which variant clause (field number in VAR_TYPE, | |
5713 | numbering from 0) is applicable. Returns -1 if none are. */ | |
5714 | ||
d2e4a39e | 5715 | int |
ebf56fd3 | 5716 | ada_which_variant_applies (struct type *var_type, struct type *outer_type, |
d2e4a39e | 5717 | char *outer_valaddr) |
14f9c5c9 AS |
5718 | { |
5719 | int others_clause; | |
5720 | int i; | |
5721 | int disp; | |
d2e4a39e AS |
5722 | struct type *discrim_type; |
5723 | char *discrim_name = ada_variant_discrim_name (var_type); | |
14f9c5c9 AS |
5724 | LONGEST discrim_val; |
5725 | ||
5726 | disp = 0; | |
d2e4a39e | 5727 | discrim_type = |
14f9c5c9 AS |
5728 | ada_lookup_struct_elt_type (outer_type, discrim_name, 1, &disp); |
5729 | if (discrim_type == NULL) | |
5730 | return -1; | |
5731 | discrim_val = unpack_long (discrim_type, outer_valaddr + disp); | |
5732 | ||
5733 | others_clause = -1; | |
5734 | for (i = 0; i < TYPE_NFIELDS (var_type); i += 1) | |
5735 | { | |
5736 | if (ada_is_others_clause (var_type, i)) | |
5737 | others_clause = i; | |
5738 | else if (ada_in_variant (discrim_val, var_type, i)) | |
5739 | return i; | |
5740 | } | |
5741 | ||
5742 | return others_clause; | |
5743 | } | |
d2e4a39e | 5744 | \f |
14f9c5c9 AS |
5745 | |
5746 | ||
14f9c5c9 AS |
5747 | /* Dynamic-Sized Records */ |
5748 | ||
5749 | /* Strategy: The type ostensibly attached to a value with dynamic size | |
5750 | (i.e., a size that is not statically recorded in the debugging | |
5751 | data) does not accurately reflect the size or layout of the value. | |
5752 | Our strategy is to convert these values to values with accurate, | |
5753 | conventional types that are constructed on the fly. */ | |
5754 | ||
5755 | /* There is a subtle and tricky problem here. In general, we cannot | |
5756 | determine the size of dynamic records without its data. However, | |
5757 | the 'struct value' data structure, which GDB uses to represent | |
5758 | quantities in the inferior process (the target), requires the size | |
5759 | of the type at the time of its allocation in order to reserve space | |
5760 | for GDB's internal copy of the data. That's why the | |
5761 | 'to_fixed_xxx_type' routines take (target) addresses as parameters, | |
5762 | rather than struct value*s. | |
5763 | ||
5764 | However, GDB's internal history variables ($1, $2, etc.) are | |
5765 | struct value*s containing internal copies of the data that are not, in | |
5766 | general, the same as the data at their corresponding addresses in | |
5767 | the target. Fortunately, the types we give to these values are all | |
5768 | conventional, fixed-size types (as per the strategy described | |
5769 | above), so that we don't usually have to perform the | |
5770 | 'to_fixed_xxx_type' conversions to look at their values. | |
5771 | Unfortunately, there is one exception: if one of the internal | |
5772 | history variables is an array whose elements are unconstrained | |
5773 | records, then we will need to create distinct fixed types for each | |
5774 | element selected. */ | |
5775 | ||
5776 | /* The upshot of all of this is that many routines take a (type, host | |
5777 | address, target address) triple as arguments to represent a value. | |
5778 | The host address, if non-null, is supposed to contain an internal | |
5779 | copy of the relevant data; otherwise, the program is to consult the | |
5780 | target at the target address. */ | |
5781 | ||
5782 | /* Assuming that VAL0 represents a pointer value, the result of | |
5783 | dereferencing it. Differs from value_ind in its treatment of | |
5784 | dynamic-sized types. */ | |
5785 | ||
d2e4a39e AS |
5786 | struct value * |
5787 | ada_value_ind (struct value *val0) | |
14f9c5c9 | 5788 | { |
d2e4a39e | 5789 | struct value *val = unwrap_value (value_ind (val0)); |
14f9c5c9 | 5790 | return ada_to_fixed_value (VALUE_TYPE (val), 0, |
d2e4a39e | 5791 | VALUE_ADDRESS (val) + VALUE_OFFSET (val), val); |
14f9c5c9 AS |
5792 | } |
5793 | ||
5794 | /* The value resulting from dereferencing any "reference to" | |
5795 | * qualifiers on VAL0. */ | |
d2e4a39e AS |
5796 | static struct value * |
5797 | ada_coerce_ref (struct value *val0) | |
5798 | { | |
5799 | if (TYPE_CODE (VALUE_TYPE (val0)) == TYPE_CODE_REF) | |
5800 | { | |
5801 | struct value *val = val0; | |
5802 | COERCE_REF (val); | |
5803 | val = unwrap_value (val); | |
5804 | return ada_to_fixed_value (VALUE_TYPE (val), 0, | |
5805 | VALUE_ADDRESS (val) + VALUE_OFFSET (val), | |
5806 | val); | |
5807 | } | |
5808 | else | |
14f9c5c9 AS |
5809 | return val0; |
5810 | } | |
5811 | ||
5812 | /* Return OFF rounded upward if necessary to a multiple of | |
5813 | ALIGNMENT (a power of 2). */ | |
5814 | ||
5815 | static unsigned int | |
ebf56fd3 | 5816 | align_value (unsigned int off, unsigned int alignment) |
14f9c5c9 AS |
5817 | { |
5818 | return (off + alignment - 1) & ~(alignment - 1); | |
5819 | } | |
5820 | ||
5821 | /* Return the additional bit offset required by field F of template | |
5822 | type TYPE. */ | |
5823 | ||
5824 | static unsigned int | |
ebf56fd3 | 5825 | field_offset (struct type *type, int f) |
14f9c5c9 AS |
5826 | { |
5827 | int n = TYPE_FIELD_BITPOS (type, f); | |
5828 | /* Kludge (temporary?) to fix problem with dwarf output. */ | |
5829 | if (n < 0) | |
5830 | return (unsigned int) n & 0xffff; | |
5831 | else | |
5832 | return n; | |
5833 | } | |
5834 | ||
5835 | ||
5836 | /* Return the bit alignment required for field #F of template type TYPE. */ | |
5837 | ||
5838 | static unsigned int | |
ebf56fd3 | 5839 | field_alignment (struct type *type, int f) |
14f9c5c9 | 5840 | { |
d2e4a39e | 5841 | const char *name = TYPE_FIELD_NAME (type, f); |
14f9c5c9 AS |
5842 | int len = (name == NULL) ? 0 : strlen (name); |
5843 | int align_offset; | |
5844 | ||
d2e4a39e | 5845 | if (len < 8 || !isdigit (name[len - 1])) |
14f9c5c9 AS |
5846 | return TARGET_CHAR_BIT; |
5847 | ||
d2e4a39e | 5848 | if (isdigit (name[len - 2])) |
14f9c5c9 AS |
5849 | align_offset = len - 2; |
5850 | else | |
5851 | align_offset = len - 1; | |
5852 | ||
d2e4a39e | 5853 | if (align_offset < 7 || !STREQN ("___XV", name + align_offset - 6, 5)) |
14f9c5c9 AS |
5854 | return TARGET_CHAR_BIT; |
5855 | ||
d2e4a39e | 5856 | return atoi (name + align_offset) * TARGET_CHAR_BIT; |
14f9c5c9 AS |
5857 | } |
5858 | ||
5859 | /* Find a type named NAME. Ignores ambiguity. */ | |
d2e4a39e | 5860 | struct type * |
ebf56fd3 | 5861 | ada_find_any_type (const char *name) |
14f9c5c9 | 5862 | { |
d2e4a39e | 5863 | struct symbol *sym; |
14f9c5c9 AS |
5864 | |
5865 | sym = standard_lookup (name, VAR_NAMESPACE); | |
5866 | if (sym != NULL && SYMBOL_CLASS (sym) == LOC_TYPEDEF) | |
5867 | return SYMBOL_TYPE (sym); | |
5868 | ||
5869 | sym = standard_lookup (name, STRUCT_NAMESPACE); | |
5870 | if (sym != NULL) | |
5871 | return SYMBOL_TYPE (sym); | |
5872 | ||
5873 | return NULL; | |
5874 | } | |
5875 | ||
5876 | /* Because of GNAT encoding conventions, several GDB symbols may match a | |
5877 | given type name. If the type denoted by TYPE0 is to be preferred to | |
5878 | that of TYPE1 for purposes of type printing, return non-zero; | |
5879 | otherwise return 0. */ | |
5880 | int | |
d2e4a39e | 5881 | ada_prefer_type (struct type *type0, struct type *type1) |
14f9c5c9 AS |
5882 | { |
5883 | if (type1 == NULL) | |
5884 | return 1; | |
5885 | else if (type0 == NULL) | |
5886 | return 0; | |
5887 | else if (TYPE_CODE (type1) == TYPE_CODE_VOID) | |
5888 | return 1; | |
5889 | else if (TYPE_CODE (type0) == TYPE_CODE_VOID) | |
5890 | return 0; | |
5891 | else if (ada_is_packed_array_type (type0)) | |
5892 | return 1; | |
d2e4a39e AS |
5893 | else if (ada_is_array_descriptor (type0) |
5894 | && !ada_is_array_descriptor (type1)) | |
14f9c5c9 | 5895 | return 1; |
d2e4a39e | 5896 | else if (ada_renaming_type (type0) != NULL |
14f9c5c9 AS |
5897 | && ada_renaming_type (type1) == NULL) |
5898 | return 1; | |
5899 | return 0; | |
5900 | } | |
5901 | ||
5902 | /* The name of TYPE, which is either its TYPE_NAME, or, if that is | |
5903 | null, its TYPE_TAG_NAME. Null if TYPE is null. */ | |
d2e4a39e AS |
5904 | char * |
5905 | ada_type_name (struct type *type) | |
14f9c5c9 | 5906 | { |
d2e4a39e | 5907 | if (type == NULL) |
14f9c5c9 AS |
5908 | return NULL; |
5909 | else if (TYPE_NAME (type) != NULL) | |
5910 | return TYPE_NAME (type); | |
5911 | else | |
5912 | return TYPE_TAG_NAME (type); | |
5913 | } | |
5914 | ||
5915 | /* Find a parallel type to TYPE whose name is formed by appending | |
5916 | SUFFIX to the name of TYPE. */ | |
5917 | ||
d2e4a39e | 5918 | struct type * |
ebf56fd3 | 5919 | ada_find_parallel_type (struct type *type, const char *suffix) |
14f9c5c9 | 5920 | { |
d2e4a39e | 5921 | static char *name; |
14f9c5c9 | 5922 | static size_t name_len = 0; |
d2e4a39e AS |
5923 | struct symbol **syms; |
5924 | struct block **blocks; | |
14f9c5c9 AS |
5925 | int nsyms; |
5926 | int len; | |
d2e4a39e AS |
5927 | char *typename = ada_type_name (type); |
5928 | ||
14f9c5c9 AS |
5929 | if (typename == NULL) |
5930 | return NULL; | |
5931 | ||
5932 | len = strlen (typename); | |
5933 | ||
d2e4a39e | 5934 | GROW_VECT (name, name_len, len + strlen (suffix) + 1); |
14f9c5c9 AS |
5935 | |
5936 | strcpy (name, typename); | |
5937 | strcpy (name + len, suffix); | |
5938 | ||
5939 | return ada_find_any_type (name); | |
5940 | } | |
5941 | ||
5942 | ||
5943 | /* If TYPE is a variable-size record type, return the corresponding template | |
5944 | type describing its fields. Otherwise, return NULL. */ | |
5945 | ||
d2e4a39e AS |
5946 | static struct type * |
5947 | dynamic_template_type (struct type *type) | |
14f9c5c9 AS |
5948 | { |
5949 | CHECK_TYPEDEF (type); | |
5950 | ||
5951 | if (type == NULL || TYPE_CODE (type) != TYPE_CODE_STRUCT | |
d2e4a39e | 5952 | || ada_type_name (type) == NULL) |
14f9c5c9 | 5953 | return NULL; |
d2e4a39e | 5954 | else |
14f9c5c9 AS |
5955 | { |
5956 | int len = strlen (ada_type_name (type)); | |
5957 | if (len > 6 && STREQ (ada_type_name (type) + len - 6, "___XVE")) | |
5958 | return type; | |
5959 | else | |
5960 | return ada_find_parallel_type (type, "___XVE"); | |
5961 | } | |
5962 | } | |
5963 | ||
5964 | /* Assuming that TEMPL_TYPE is a union or struct type, returns | |
5965 | non-zero iff field FIELD_NUM of TEMPL_TYPE has dynamic size. */ | |
5966 | ||
d2e4a39e AS |
5967 | static int |
5968 | is_dynamic_field (struct type *templ_type, int field_num) | |
14f9c5c9 AS |
5969 | { |
5970 | const char *name = TYPE_FIELD_NAME (templ_type, field_num); | |
d2e4a39e | 5971 | return name != NULL |
14f9c5c9 AS |
5972 | && TYPE_CODE (TYPE_FIELD_TYPE (templ_type, field_num)) == TYPE_CODE_PTR |
5973 | && strstr (name, "___XVL") != NULL; | |
5974 | } | |
5975 | ||
5976 | /* Assuming that TYPE is a struct type, returns non-zero iff TYPE | |
5977 | contains a variant part. */ | |
5978 | ||
d2e4a39e AS |
5979 | static int |
5980 | contains_variant_part (struct type *type) | |
14f9c5c9 AS |
5981 | { |
5982 | int f; | |
5983 | ||
5984 | if (type == NULL || TYPE_CODE (type) != TYPE_CODE_STRUCT | |
5985 | || TYPE_NFIELDS (type) <= 0) | |
5986 | return 0; | |
5987 | return ada_is_variant_part (type, TYPE_NFIELDS (type) - 1); | |
5988 | } | |
5989 | ||
5990 | /* A record type with no fields, . */ | |
d2e4a39e AS |
5991 | static struct type * |
5992 | empty_record (struct objfile *objfile) | |
14f9c5c9 | 5993 | { |
d2e4a39e | 5994 | struct type *type = alloc_type (objfile); |
14f9c5c9 AS |
5995 | TYPE_CODE (type) = TYPE_CODE_STRUCT; |
5996 | TYPE_NFIELDS (type) = 0; | |
5997 | TYPE_FIELDS (type) = NULL; | |
5998 | TYPE_NAME (type) = "<empty>"; | |
5999 | TYPE_TAG_NAME (type) = NULL; | |
6000 | TYPE_FLAGS (type) = 0; | |
6001 | TYPE_LENGTH (type) = 0; | |
6002 | return type; | |
6003 | } | |
6004 | ||
6005 | /* An ordinary record type (with fixed-length fields) that describes | |
6006 | the value of type TYPE at VALADDR or ADDRESS (see comments at | |
6007 | the beginning of this section) VAL according to GNAT conventions. | |
6008 | DVAL0 should describe the (portion of a) record that contains any | |
6009 | necessary discriminants. It should be NULL if VALUE_TYPE (VAL) is | |
6010 | an outer-level type (i.e., as opposed to a branch of a variant.) A | |
6011 | variant field (unless unchecked) is replaced by a particular branch | |
6012 | of the variant. */ | |
6013 | /* NOTE: Limitations: For now, we assume that dynamic fields and | |
6014 | * variants occupy whole numbers of bytes. However, they need not be | |
6015 | * byte-aligned. */ | |
6016 | ||
d2e4a39e AS |
6017 | static struct type * |
6018 | template_to_fixed_record_type (struct type *type, char *valaddr, | |
6019 | CORE_ADDR address, struct value *dval0) | |
14f9c5c9 | 6020 | { |
d2e4a39e AS |
6021 | struct value *mark = value_mark (); |
6022 | struct value *dval; | |
6023 | struct type *rtype; | |
14f9c5c9 AS |
6024 | int nfields, bit_len; |
6025 | long off; | |
6026 | int f; | |
6027 | ||
6028 | nfields = TYPE_NFIELDS (type); | |
6029 | rtype = alloc_type (TYPE_OBJFILE (type)); | |
6030 | TYPE_CODE (rtype) = TYPE_CODE_STRUCT; | |
6031 | INIT_CPLUS_SPECIFIC (rtype); | |
6032 | TYPE_NFIELDS (rtype) = nfields; | |
d2e4a39e | 6033 | TYPE_FIELDS (rtype) = (struct field *) |
14f9c5c9 AS |
6034 | TYPE_ALLOC (rtype, nfields * sizeof (struct field)); |
6035 | memset (TYPE_FIELDS (rtype), 0, sizeof (struct field) * nfields); | |
6036 | TYPE_NAME (rtype) = ada_type_name (type); | |
6037 | TYPE_TAG_NAME (rtype) = NULL; | |
6038 | /* FIXME: TYPE_FLAG_FIXED_INSTANCE should be defined in | |
d2e4a39e AS |
6039 | gdbtypes.h */ |
6040 | /* TYPE_FLAGS (rtype) |= TYPE_FLAG_FIXED_INSTANCE; */ | |
14f9c5c9 | 6041 | |
d2e4a39e AS |
6042 | off = 0; |
6043 | bit_len = 0; | |
14f9c5c9 AS |
6044 | for (f = 0; f < nfields; f += 1) |
6045 | { | |
6046 | int fld_bit_len, bit_incr; | |
d2e4a39e AS |
6047 | off = |
6048 | align_value (off, | |
6049 | field_alignment (type, f)) + TYPE_FIELD_BITPOS (type, f); | |
14f9c5c9 AS |
6050 | /* NOTE: used to use field_offset above, but that causes |
6051 | * problems with really negative bit positions. So, let's | |
6052 | * rediscover why we needed field_offset and fix it properly. */ | |
6053 | TYPE_FIELD_BITPOS (rtype, f) = off; | |
d2e4a39e | 6054 | TYPE_FIELD_BITSIZE (rtype, f) = 0; |
14f9c5c9 | 6055 | |
d2e4a39e | 6056 | if (ada_is_variant_part (type, f)) |
14f9c5c9 AS |
6057 | { |
6058 | struct type *branch_type; | |
6059 | ||
6060 | if (dval0 == NULL) | |
d2e4a39e | 6061 | dval = value_from_contents_and_address (rtype, valaddr, address); |
14f9c5c9 AS |
6062 | else |
6063 | dval = dval0; | |
6064 | ||
d2e4a39e AS |
6065 | branch_type = |
6066 | to_fixed_variant_branch_type | |
6067 | (TYPE_FIELD_TYPE (type, f), | |
6068 | cond_offset_host (valaddr, off / TARGET_CHAR_BIT), | |
6069 | cond_offset_target (address, off / TARGET_CHAR_BIT), dval); | |
6070 | if (branch_type == NULL) | |
14f9c5c9 AS |
6071 | TYPE_NFIELDS (rtype) -= 1; |
6072 | else | |
6073 | { | |
6074 | TYPE_FIELD_TYPE (rtype, f) = branch_type; | |
6075 | TYPE_FIELD_NAME (rtype, f) = "S"; | |
6076 | } | |
6077 | bit_incr = 0; | |
6078 | fld_bit_len = | |
6079 | TYPE_LENGTH (TYPE_FIELD_TYPE (rtype, f)) * TARGET_CHAR_BIT; | |
6080 | } | |
6081 | else if (is_dynamic_field (type, f)) | |
6082 | { | |
6083 | if (dval0 == NULL) | |
d2e4a39e | 6084 | dval = value_from_contents_and_address (rtype, valaddr, address); |
14f9c5c9 AS |
6085 | else |
6086 | dval = dval0; | |
6087 | ||
d2e4a39e AS |
6088 | TYPE_FIELD_TYPE (rtype, f) = |
6089 | ada_to_fixed_type | |
6090 | (ada_get_base_type | |
6091 | (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, f))), | |
6092 | cond_offset_host (valaddr, off / TARGET_CHAR_BIT), | |
6093 | cond_offset_target (address, off / TARGET_CHAR_BIT), dval); | |
14f9c5c9 AS |
6094 | TYPE_FIELD_NAME (rtype, f) = TYPE_FIELD_NAME (type, f); |
6095 | bit_incr = fld_bit_len = | |
6096 | TYPE_LENGTH (TYPE_FIELD_TYPE (rtype, f)) * TARGET_CHAR_BIT; | |
6097 | } | |
6098 | else | |
6099 | { | |
6100 | TYPE_FIELD_TYPE (rtype, f) = TYPE_FIELD_TYPE (type, f); | |
6101 | TYPE_FIELD_NAME (rtype, f) = TYPE_FIELD_NAME (type, f); | |
6102 | if (TYPE_FIELD_BITSIZE (type, f) > 0) | |
d2e4a39e | 6103 | bit_incr = fld_bit_len = |
14f9c5c9 AS |
6104 | TYPE_FIELD_BITSIZE (rtype, f) = TYPE_FIELD_BITSIZE (type, f); |
6105 | else | |
6106 | bit_incr = fld_bit_len = | |
6107 | TYPE_LENGTH (TYPE_FIELD_TYPE (type, f)) * TARGET_CHAR_BIT; | |
6108 | } | |
6109 | if (off + fld_bit_len > bit_len) | |
6110 | bit_len = off + fld_bit_len; | |
6111 | off += bit_incr; | |
6112 | TYPE_LENGTH (rtype) = bit_len / TARGET_CHAR_BIT; | |
6113 | } | |
6114 | TYPE_LENGTH (rtype) = align_value (TYPE_LENGTH (rtype), TYPE_LENGTH (type)); | |
6115 | ||
6116 | value_free_to_mark (mark); | |
d2e4a39e | 6117 | if (TYPE_LENGTH (rtype) > varsize_limit) |
14f9c5c9 AS |
6118 | error ("record type with dynamic size is larger than varsize-limit"); |
6119 | return rtype; | |
6120 | } | |
6121 | ||
6122 | /* As for template_to_fixed_record_type, but uses no run-time values. | |
6123 | As a result, this type can only be approximate, but that's OK, | |
6124 | since it is used only for type determinations. Works on both | |
6125 | structs and unions. | |
6126 | Representation note: to save space, we memoize the result of this | |
6127 | function in the TYPE_TARGET_TYPE of the template type. */ | |
6128 | ||
d2e4a39e AS |
6129 | static struct type * |
6130 | template_to_static_fixed_type (struct type *templ_type) | |
14f9c5c9 AS |
6131 | { |
6132 | struct type *type; | |
6133 | int nfields; | |
6134 | int f; | |
6135 | ||
6136 | if (TYPE_TARGET_TYPE (templ_type) != NULL) | |
6137 | return TYPE_TARGET_TYPE (templ_type); | |
6138 | ||
6139 | nfields = TYPE_NFIELDS (templ_type); | |
d2e4a39e AS |
6140 | TYPE_TARGET_TYPE (templ_type) = type = |
6141 | alloc_type (TYPE_OBJFILE (templ_type)); | |
14f9c5c9 AS |
6142 | TYPE_CODE (type) = TYPE_CODE (templ_type); |
6143 | INIT_CPLUS_SPECIFIC (type); | |
6144 | TYPE_NFIELDS (type) = nfields; | |
d2e4a39e | 6145 | TYPE_FIELDS (type) = (struct field *) |
14f9c5c9 AS |
6146 | TYPE_ALLOC (type, nfields * sizeof (struct field)); |
6147 | memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields); | |
6148 | TYPE_NAME (type) = ada_type_name (templ_type); | |
6149 | TYPE_TAG_NAME (type) = NULL; | |
d2e4a39e | 6150 | /* FIXME: TYPE_FLAG_FIXED_INSTANCE should be defined in gdbtypes.h */ |
14f9c5c9 AS |
6151 | /* TYPE_FLAGS (type) |= TYPE_FLAG_FIXED_INSTANCE; */ |
6152 | TYPE_LENGTH (type) = 0; | |
6153 | ||
6154 | for (f = 0; f < nfields; f += 1) | |
6155 | { | |
6156 | TYPE_FIELD_BITPOS (type, f) = 0; | |
d2e4a39e | 6157 | TYPE_FIELD_BITSIZE (type, f) = 0; |
14f9c5c9 AS |
6158 | |
6159 | if (is_dynamic_field (templ_type, f)) | |
6160 | { | |
d2e4a39e AS |
6161 | TYPE_FIELD_TYPE (type, f) = |
6162 | to_static_fixed_type (TYPE_TARGET_TYPE | |
14f9c5c9 AS |
6163 | (TYPE_FIELD_TYPE (templ_type, f))); |
6164 | TYPE_FIELD_NAME (type, f) = TYPE_FIELD_NAME (templ_type, f); | |
6165 | } | |
6166 | else | |
6167 | { | |
d2e4a39e | 6168 | TYPE_FIELD_TYPE (type, f) = |
14f9c5c9 AS |
6169 | check_typedef (TYPE_FIELD_TYPE (templ_type, f)); |
6170 | TYPE_FIELD_NAME (type, f) = TYPE_FIELD_NAME (templ_type, f); | |
6171 | } | |
6172 | } | |
6173 | ||
6174 | return type; | |
6175 | } | |
6176 | ||
6177 | /* A revision of TYPE0 -- a non-dynamic-sized record with a variant | |
6178 | part -- in which the variant part is replaced with the appropriate | |
6179 | branch. */ | |
d2e4a39e AS |
6180 | static struct type * |
6181 | to_record_with_fixed_variant_part (struct type *type, char *valaddr, | |
6182 | CORE_ADDR address, struct value *dval) | |
14f9c5c9 | 6183 | { |
d2e4a39e AS |
6184 | struct value *mark = value_mark (); |
6185 | struct type *rtype; | |
14f9c5c9 AS |
6186 | struct type *branch_type; |
6187 | int nfields = TYPE_NFIELDS (type); | |
6188 | ||
6189 | if (dval == NULL) | |
6190 | return type; | |
6191 | ||
6192 | rtype = alloc_type (TYPE_OBJFILE (type)); | |
6193 | TYPE_CODE (rtype) = TYPE_CODE_STRUCT; | |
6194 | INIT_CPLUS_SPECIFIC (type); | |
6195 | TYPE_NFIELDS (rtype) = TYPE_NFIELDS (type); | |
d2e4a39e AS |
6196 | TYPE_FIELDS (rtype) = |
6197 | (struct field *) TYPE_ALLOC (rtype, nfields * sizeof (struct field)); | |
6198 | memcpy (TYPE_FIELDS (rtype), TYPE_FIELDS (type), | |
14f9c5c9 AS |
6199 | sizeof (struct field) * nfields); |
6200 | TYPE_NAME (rtype) = ada_type_name (type); | |
6201 | TYPE_TAG_NAME (rtype) = NULL; | |
d2e4a39e | 6202 | /* FIXME: TYPE_FLAG_FIXED_INSTANCE should be defined in gdbtypes.h */ |
14f9c5c9 AS |
6203 | /* TYPE_FLAGS (rtype) |= TYPE_FLAG_FIXED_INSTANCE; */ |
6204 | TYPE_LENGTH (rtype) = TYPE_LENGTH (type); | |
6205 | ||
d2e4a39e AS |
6206 | branch_type = |
6207 | to_fixed_variant_branch_type | |
6208 | (TYPE_FIELD_TYPE (type, nfields - 1), | |
6209 | cond_offset_host (valaddr, | |
6210 | TYPE_FIELD_BITPOS (type, | |
6211 | nfields - 1) / TARGET_CHAR_BIT), | |
6212 | cond_offset_target (address, | |
6213 | TYPE_FIELD_BITPOS (type, | |
6214 | nfields - 1) / TARGET_CHAR_BIT), | |
6215 | dval); | |
6216 | if (branch_type == NULL) | |
14f9c5c9 AS |
6217 | { |
6218 | TYPE_NFIELDS (rtype) -= 1; | |
d2e4a39e AS |
6219 | TYPE_LENGTH (rtype) -= |
6220 | TYPE_LENGTH (TYPE_FIELD_TYPE (type, nfields - 1)); | |
14f9c5c9 AS |
6221 | } |
6222 | else | |
6223 | { | |
d2e4a39e AS |
6224 | TYPE_FIELD_TYPE (rtype, nfields - 1) = branch_type; |
6225 | TYPE_FIELD_NAME (rtype, nfields - 1) = "S"; | |
6226 | TYPE_FIELD_BITSIZE (rtype, nfields - 1) = 0; | |
14f9c5c9 | 6227 | TYPE_LENGTH (rtype) += TYPE_LENGTH (branch_type); |
d2e4a39e | 6228 | -TYPE_LENGTH (TYPE_FIELD_TYPE (type, nfields - 1)); |
14f9c5c9 | 6229 | } |
d2e4a39e | 6230 | |
14f9c5c9 AS |
6231 | return rtype; |
6232 | } | |
6233 | ||
6234 | /* An ordinary record type (with fixed-length fields) that describes | |
6235 | the value at (TYPE0, VALADDR, ADDRESS) [see explanation at | |
6236 | beginning of this section]. Any necessary discriminants' values | |
6237 | should be in DVAL, a record value; it should be NULL if the object | |
6238 | at ADDR itself contains any necessary discriminant values. A | |
6239 | variant field (unless unchecked) is replaced by a particular branch | |
d2e4a39e | 6240 | of the variant. */ |
14f9c5c9 | 6241 | |
d2e4a39e AS |
6242 | static struct type * |
6243 | to_fixed_record_type (struct type *type0, char *valaddr, CORE_ADDR address, | |
6244 | struct value *dval) | |
14f9c5c9 | 6245 | { |
d2e4a39e | 6246 | struct type *templ_type; |
14f9c5c9 AS |
6247 | |
6248 | /* FIXME: TYPE_FLAG_FIXED_INSTANCE should be defined in gdbtypes.h */ | |
6249 | /* if (TYPE_FLAGS (type0) & TYPE_FLAG_FIXED_INSTANCE) | |
d2e4a39e AS |
6250 | return type0; |
6251 | */ | |
6252 | templ_type = dynamic_template_type (type0); | |
14f9c5c9 AS |
6253 | |
6254 | if (templ_type != NULL) | |
6255 | return template_to_fixed_record_type (templ_type, valaddr, address, dval); | |
6256 | else if (contains_variant_part (type0)) | |
6257 | return to_record_with_fixed_variant_part (type0, valaddr, address, dval); | |
6258 | else | |
6259 | { | |
d2e4a39e | 6260 | /* FIXME: TYPE_FLAG_FIXED_INSTANCE should be defined in gdbtypes.h */ |
14f9c5c9 AS |
6261 | /* TYPE_FLAGS (type0) |= TYPE_FLAG_FIXED_INSTANCE; */ |
6262 | return type0; | |
6263 | } | |
6264 | ||
6265 | } | |
6266 | ||
6267 | /* An ordinary record type (with fixed-length fields) that describes | |
6268 | the value at (VAR_TYPE0, VALADDR, ADDRESS), where VAR_TYPE0 is a | |
6269 | union type. Any necessary discriminants' values should be in DVAL, | |
6270 | a record value. That is, this routine selects the appropriate | |
6271 | branch of the union at ADDR according to the discriminant value | |
6272 | indicated in the union's type name. */ | |
6273 | ||
d2e4a39e AS |
6274 | static struct type * |
6275 | to_fixed_variant_branch_type (struct type *var_type0, char *valaddr, | |
6276 | CORE_ADDR address, struct value *dval) | |
14f9c5c9 AS |
6277 | { |
6278 | int which; | |
d2e4a39e AS |
6279 | struct type *templ_type; |
6280 | struct type *var_type; | |
14f9c5c9 AS |
6281 | |
6282 | if (TYPE_CODE (var_type0) == TYPE_CODE_PTR) | |
6283 | var_type = TYPE_TARGET_TYPE (var_type0); | |
d2e4a39e | 6284 | else |
14f9c5c9 AS |
6285 | var_type = var_type0; |
6286 | ||
6287 | templ_type = ada_find_parallel_type (var_type, "___XVU"); | |
6288 | ||
6289 | if (templ_type != NULL) | |
6290 | var_type = templ_type; | |
6291 | ||
d2e4a39e AS |
6292 | which = |
6293 | ada_which_variant_applies (var_type, | |
14f9c5c9 AS |
6294 | VALUE_TYPE (dval), VALUE_CONTENTS (dval)); |
6295 | ||
6296 | if (which < 0) | |
6297 | return empty_record (TYPE_OBJFILE (var_type)); | |
6298 | else if (is_dynamic_field (var_type, which)) | |
d2e4a39e AS |
6299 | return |
6300 | to_fixed_record_type | |
6301 | (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (var_type, which)), | |
6302 | valaddr, address, dval); | |
14f9c5c9 | 6303 | else if (contains_variant_part (TYPE_FIELD_TYPE (var_type, which))) |
d2e4a39e AS |
6304 | return |
6305 | to_fixed_record_type | |
6306 | (TYPE_FIELD_TYPE (var_type, which), valaddr, address, dval); | |
14f9c5c9 AS |
6307 | else |
6308 | return TYPE_FIELD_TYPE (var_type, which); | |
6309 | } | |
6310 | ||
6311 | /* Assuming that TYPE0 is an array type describing the type of a value | |
6312 | at ADDR, and that DVAL describes a record containing any | |
6313 | discriminants used in TYPE0, returns a type for the value that | |
6314 | contains no dynamic components (that is, no components whose sizes | |
6315 | are determined by run-time quantities). Unless IGNORE_TOO_BIG is | |
6316 | true, gives an error message if the resulting type's size is over | |
6317 | varsize_limit. | |
6318 | */ | |
6319 | ||
d2e4a39e AS |
6320 | static struct type * |
6321 | to_fixed_array_type (struct type *type0, struct value *dval, | |
ebf56fd3 | 6322 | int ignore_too_big) |
14f9c5c9 | 6323 | { |
d2e4a39e AS |
6324 | struct type *index_type_desc; |
6325 | struct type *result; | |
14f9c5c9 AS |
6326 | |
6327 | /* FIXME: TYPE_FLAG_FIXED_INSTANCE should be defined in gdbtypes.h */ | |
d2e4a39e AS |
6328 | /* if (ada_is_packed_array_type (type0) /* revisit? *//* |
6329 | || (TYPE_FLAGS (type0) & TYPE_FLAG_FIXED_INSTANCE)) | |
6330 | return type0; */ | |
14f9c5c9 AS |
6331 | |
6332 | index_type_desc = ada_find_parallel_type (type0, "___XA"); | |
6333 | if (index_type_desc == NULL) | |
6334 | { | |
6335 | struct type *elt_type0 = check_typedef (TYPE_TARGET_TYPE (type0)); | |
6336 | /* NOTE: elt_type---the fixed version of elt_type0---should never | |
6337 | * depend on the contents of the array in properly constructed | |
d2e4a39e AS |
6338 | * debugging data. */ |
6339 | struct type *elt_type = ada_to_fixed_type (elt_type0, 0, 0, dval); | |
14f9c5c9 AS |
6340 | |
6341 | if (elt_type0 == elt_type) | |
6342 | result = type0; | |
6343 | else | |
d2e4a39e | 6344 | result = create_array_type (alloc_type (TYPE_OBJFILE (type0)), |
14f9c5c9 AS |
6345 | elt_type, TYPE_INDEX_TYPE (type0)); |
6346 | } | |
6347 | else | |
6348 | { | |
6349 | int i; | |
6350 | struct type *elt_type0; | |
6351 | ||
6352 | elt_type0 = type0; | |
6353 | for (i = TYPE_NFIELDS (index_type_desc); i > 0; i -= 1) | |
6354 | elt_type0 = TYPE_TARGET_TYPE (elt_type0); | |
6355 | ||
6356 | /* NOTE: result---the fixed version of elt_type0---should never | |
6357 | * depend on the contents of the array in properly constructed | |
d2e4a39e AS |
6358 | * debugging data. */ |
6359 | result = ada_to_fixed_type (check_typedef (elt_type0), 0, 0, dval); | |
14f9c5c9 AS |
6360 | for (i = TYPE_NFIELDS (index_type_desc) - 1; i >= 0; i -= 1) |
6361 | { | |
d2e4a39e | 6362 | struct type *range_type = |
14f9c5c9 AS |
6363 | to_fixed_range_type (TYPE_FIELD_NAME (index_type_desc, i), |
6364 | dval, TYPE_OBJFILE (type0)); | |
6365 | result = create_array_type (alloc_type (TYPE_OBJFILE (type0)), | |
6366 | result, range_type); | |
6367 | } | |
d2e4a39e | 6368 | if (!ignore_too_big && TYPE_LENGTH (result) > varsize_limit) |
14f9c5c9 AS |
6369 | error ("array type with dynamic size is larger than varsize-limit"); |
6370 | } | |
6371 | ||
6372 | /* FIXME: TYPE_FLAG_FIXED_INSTANCE should be defined in gdbtypes.h */ | |
6373 | /* TYPE_FLAGS (result) |= TYPE_FLAG_FIXED_INSTANCE; */ | |
6374 | return result; | |
d2e4a39e | 6375 | } |
14f9c5c9 AS |
6376 | |
6377 | ||
6378 | /* A standard type (containing no dynamically sized components) | |
6379 | corresponding to TYPE for the value (TYPE, VALADDR, ADDRESS) | |
6380 | DVAL describes a record containing any discriminants used in TYPE0, | |
6381 | and may be NULL if there are none. */ | |
6382 | ||
d2e4a39e AS |
6383 | struct type * |
6384 | ada_to_fixed_type (struct type *type, char *valaddr, CORE_ADDR address, | |
6385 | struct value *dval) | |
14f9c5c9 AS |
6386 | { |
6387 | CHECK_TYPEDEF (type); | |
d2e4a39e AS |
6388 | switch (TYPE_CODE (type)) |
6389 | { | |
6390 | default: | |
14f9c5c9 | 6391 | return type; |
d2e4a39e AS |
6392 | case TYPE_CODE_STRUCT: |
6393 | return to_fixed_record_type (type, valaddr, address, NULL); | |
6394 | case TYPE_CODE_ARRAY: | |
6395 | return to_fixed_array_type (type, dval, 0); | |
6396 | case TYPE_CODE_UNION: | |
6397 | if (dval == NULL) | |
6398 | return type; | |
6399 | else | |
6400 | return to_fixed_variant_branch_type (type, valaddr, address, dval); | |
6401 | } | |
14f9c5c9 AS |
6402 | } |
6403 | ||
6404 | /* A standard (static-sized) type corresponding as well as possible to | |
6405 | TYPE0, but based on no runtime data. */ | |
6406 | ||
d2e4a39e AS |
6407 | static struct type * |
6408 | to_static_fixed_type (struct type *type0) | |
14f9c5c9 | 6409 | { |
d2e4a39e | 6410 | struct type *type; |
14f9c5c9 AS |
6411 | |
6412 | if (type0 == NULL) | |
6413 | return NULL; | |
6414 | ||
6415 | /* FIXME: TYPE_FLAG_FIXED_INSTANCE should be defined in gdbtypes.h */ | |
6416 | /* if (TYPE_FLAGS (type0) & TYPE_FLAG_FIXED_INSTANCE) | |
d2e4a39e AS |
6417 | return type0; |
6418 | */ | |
14f9c5c9 | 6419 | CHECK_TYPEDEF (type0); |
d2e4a39e | 6420 | |
14f9c5c9 AS |
6421 | switch (TYPE_CODE (type0)) |
6422 | { | |
6423 | default: | |
6424 | return type0; | |
6425 | case TYPE_CODE_STRUCT: | |
6426 | type = dynamic_template_type (type0); | |
d2e4a39e | 6427 | if (type != NULL) |
14f9c5c9 AS |
6428 | return template_to_static_fixed_type (type); |
6429 | return type0; | |
6430 | case TYPE_CODE_UNION: | |
6431 | type = ada_find_parallel_type (type0, "___XVU"); | |
6432 | if (type != NULL) | |
6433 | return template_to_static_fixed_type (type); | |
6434 | return type0; | |
6435 | } | |
6436 | } | |
6437 | ||
6438 | /* A static approximation of TYPE with all type wrappers removed. */ | |
d2e4a39e AS |
6439 | static struct type * |
6440 | static_unwrap_type (struct type *type) | |
14f9c5c9 AS |
6441 | { |
6442 | if (ada_is_aligner_type (type)) | |
6443 | { | |
d2e4a39e | 6444 | struct type *type1 = TYPE_FIELD_TYPE (check_typedef (type), 0); |
14f9c5c9 AS |
6445 | if (ada_type_name (type1) == NULL) |
6446 | TYPE_NAME (type1) = ada_type_name (type); | |
6447 | ||
6448 | return static_unwrap_type (type1); | |
6449 | } | |
d2e4a39e | 6450 | else |
14f9c5c9 | 6451 | { |
d2e4a39e AS |
6452 | struct type *raw_real_type = ada_get_base_type (type); |
6453 | if (raw_real_type == type) | |
14f9c5c9 AS |
6454 | return type; |
6455 | else | |
6456 | return to_static_fixed_type (raw_real_type); | |
6457 | } | |
6458 | } | |
6459 | ||
6460 | /* In some cases, incomplete and private types require | |
6461 | cross-references that are not resolved as records (for example, | |
6462 | type Foo; | |
6463 | type FooP is access Foo; | |
6464 | V: FooP; | |
6465 | type Foo is array ...; | |
6466 | ). In these cases, since there is no mechanism for producing | |
6467 | cross-references to such types, we instead substitute for FooP a | |
6468 | stub enumeration type that is nowhere resolved, and whose tag is | |
6469 | the name of the actual type. Call these types "non-record stubs". */ | |
6470 | ||
6471 | /* A type equivalent to TYPE that is not a non-record stub, if one | |
6472 | exists, otherwise TYPE. */ | |
d2e4a39e AS |
6473 | struct type * |
6474 | ada_completed_type (struct type *type) | |
14f9c5c9 AS |
6475 | { |
6476 | CHECK_TYPEDEF (type); | |
6477 | if (type == NULL || TYPE_CODE (type) != TYPE_CODE_ENUM | |
6478 | || (TYPE_FLAGS (type) & TYPE_FLAG_STUB) == 0 | |
6479 | || TYPE_TAG_NAME (type) == NULL) | |
6480 | return type; | |
d2e4a39e | 6481 | else |
14f9c5c9 | 6482 | { |
d2e4a39e AS |
6483 | char *name = TYPE_TAG_NAME (type); |
6484 | struct type *type1 = ada_find_any_type (name); | |
14f9c5c9 AS |
6485 | return (type1 == NULL) ? type : type1; |
6486 | } | |
6487 | } | |
6488 | ||
6489 | /* A value representing the data at VALADDR/ADDRESS as described by | |
6490 | type TYPE0, but with a standard (static-sized) type that correctly | |
6491 | describes it. If VAL0 is not NULL and TYPE0 already is a standard | |
6492 | type, then return VAL0 [this feature is simply to avoid redundant | |
d2e4a39e | 6493 | creation of struct values]. */ |
14f9c5c9 | 6494 | |
d2e4a39e AS |
6495 | struct value * |
6496 | ada_to_fixed_value (struct type *type0, char *valaddr, CORE_ADDR address, | |
6497 | struct value *val0) | |
14f9c5c9 | 6498 | { |
d2e4a39e | 6499 | struct type *type = ada_to_fixed_type (type0, valaddr, address, NULL); |
14f9c5c9 AS |
6500 | if (type == type0 && val0 != NULL) |
6501 | return val0; | |
d2e4a39e AS |
6502 | else |
6503 | return value_from_contents_and_address (type, valaddr, address); | |
14f9c5c9 AS |
6504 | } |
6505 | ||
6506 | /* A value representing VAL, but with a standard (static-sized) type | |
6507 | chosen to approximate the real type of VAL as well as possible, but | |
6508 | without consulting any runtime values. For Ada dynamic-sized | |
6509 | types, therefore, the type of the result is likely to be inaccurate. */ | |
6510 | ||
d2e4a39e AS |
6511 | struct value * |
6512 | ada_to_static_fixed_value (struct value *val) | |
14f9c5c9 | 6513 | { |
d2e4a39e | 6514 | struct type *type = |
14f9c5c9 AS |
6515 | to_static_fixed_type (static_unwrap_type (VALUE_TYPE (val))); |
6516 | if (type == VALUE_TYPE (val)) | |
6517 | return val; | |
6518 | else | |
6519 | return coerce_unspec_val_to_type (val, 0, type); | |
6520 | } | |
d2e4a39e | 6521 | \f |
14f9c5c9 AS |
6522 | |
6523 | ||
14f9c5c9 AS |
6524 | |
6525 | ||
6526 | /* Attributes */ | |
6527 | ||
6528 | /* Table mapping attribute numbers to names */ | |
6529 | /* NOTE: Keep up to date with enum ada_attribute definition in ada-lang.h */ | |
6530 | ||
d2e4a39e | 6531 | static const char *attribute_names[] = { |
14f9c5c9 AS |
6532 | "<?>", |
6533 | ||
d2e4a39e | 6534 | "first", |
14f9c5c9 AS |
6535 | "last", |
6536 | "length", | |
6537 | "image", | |
6538 | "img", | |
6539 | "max", | |
6540 | "min", | |
d2e4a39e | 6541 | "pos" "tag", |
14f9c5c9 AS |
6542 | "val", |
6543 | ||
6544 | 0 | |
6545 | }; | |
6546 | ||
d2e4a39e | 6547 | const char * |
ebf56fd3 | 6548 | ada_attribute_name (int n) |
14f9c5c9 AS |
6549 | { |
6550 | if (n > 0 && n < (int) ATR_END) | |
6551 | return attribute_names[n]; | |
6552 | else | |
6553 | return attribute_names[0]; | |
6554 | } | |
6555 | ||
6556 | /* Evaluate the 'POS attribute applied to ARG. */ | |
6557 | ||
d2e4a39e AS |
6558 | static struct value * |
6559 | value_pos_atr (struct value *arg) | |
14f9c5c9 AS |
6560 | { |
6561 | struct type *type = VALUE_TYPE (arg); | |
6562 | ||
d2e4a39e | 6563 | if (!discrete_type_p (type)) |
14f9c5c9 AS |
6564 | error ("'POS only defined on discrete types"); |
6565 | ||
6566 | if (TYPE_CODE (type) == TYPE_CODE_ENUM) | |
6567 | { | |
6568 | int i; | |
6569 | LONGEST v = value_as_long (arg); | |
6570 | ||
d2e4a39e | 6571 | for (i = 0; i < TYPE_NFIELDS (type); i += 1) |
14f9c5c9 AS |
6572 | { |
6573 | if (v == TYPE_FIELD_BITPOS (type, i)) | |
6574 | return value_from_longest (builtin_type_ada_int, i); | |
6575 | } | |
6576 | error ("enumeration value is invalid: can't find 'POS"); | |
6577 | } | |
6578 | else | |
6579 | return value_from_longest (builtin_type_ada_int, value_as_long (arg)); | |
6580 | } | |
6581 | ||
6582 | /* Evaluate the TYPE'VAL attribute applied to ARG. */ | |
6583 | ||
d2e4a39e AS |
6584 | static struct value * |
6585 | value_val_atr (struct type *type, struct value *arg) | |
14f9c5c9 | 6586 | { |
d2e4a39e | 6587 | if (!discrete_type_p (type)) |
14f9c5c9 | 6588 | error ("'VAL only defined on discrete types"); |
d2e4a39e | 6589 | if (!integer_type_p (VALUE_TYPE (arg))) |
14f9c5c9 AS |
6590 | error ("'VAL requires integral argument"); |
6591 | ||
6592 | if (TYPE_CODE (type) == TYPE_CODE_ENUM) | |
6593 | { | |
6594 | long pos = value_as_long (arg); | |
6595 | if (pos < 0 || pos >= TYPE_NFIELDS (type)) | |
6596 | error ("argument to 'VAL out of range"); | |
d2e4a39e | 6597 | return value_from_longest (type, TYPE_FIELD_BITPOS (type, pos)); |
14f9c5c9 AS |
6598 | } |
6599 | else | |
6600 | return value_from_longest (type, value_as_long (arg)); | |
6601 | } | |
14f9c5c9 | 6602 | \f |
d2e4a39e | 6603 | |
14f9c5c9 AS |
6604 | /* Evaluation */ |
6605 | ||
6606 | /* True if TYPE appears to be an Ada character type. | |
6607 | * [At the moment, this is true only for Character and Wide_Character; | |
6608 | * It is a heuristic test that could stand improvement]. */ | |
6609 | ||
d2e4a39e AS |
6610 | int |
6611 | ada_is_character_type (struct type *type) | |
14f9c5c9 | 6612 | { |
d2e4a39e AS |
6613 | const char *name = ada_type_name (type); |
6614 | return | |
14f9c5c9 | 6615 | name != NULL |
d2e4a39e | 6616 | && (TYPE_CODE (type) == TYPE_CODE_CHAR |
14f9c5c9 AS |
6617 | || TYPE_CODE (type) == TYPE_CODE_INT |
6618 | || TYPE_CODE (type) == TYPE_CODE_RANGE) | |
6619 | && (STREQ (name, "character") || STREQ (name, "wide_character") | |
6620 | || STREQ (name, "unsigned char")); | |
6621 | } | |
6622 | ||
6623 | /* True if TYPE appears to be an Ada string type. */ | |
6624 | ||
6625 | int | |
ebf56fd3 | 6626 | ada_is_string_type (struct type *type) |
14f9c5c9 AS |
6627 | { |
6628 | CHECK_TYPEDEF (type); | |
d2e4a39e | 6629 | if (type != NULL |
14f9c5c9 AS |
6630 | && TYPE_CODE (type) != TYPE_CODE_PTR |
6631 | && (ada_is_simple_array (type) || ada_is_array_descriptor (type)) | |
6632 | && ada_array_arity (type) == 1) | |
6633 | { | |
6634 | struct type *elttype = ada_array_element_type (type, 1); | |
6635 | ||
6636 | return ada_is_character_type (elttype); | |
6637 | } | |
d2e4a39e | 6638 | else |
14f9c5c9 AS |
6639 | return 0; |
6640 | } | |
6641 | ||
6642 | ||
6643 | /* True if TYPE is a struct type introduced by the compiler to force the | |
6644 | alignment of a value. Such types have a single field with a | |
6645 | distinctive name. */ | |
6646 | ||
6647 | int | |
ebf56fd3 | 6648 | ada_is_aligner_type (struct type *type) |
14f9c5c9 AS |
6649 | { |
6650 | CHECK_TYPEDEF (type); | |
6651 | return (TYPE_CODE (type) == TYPE_CODE_STRUCT | |
6652 | && TYPE_NFIELDS (type) == 1 | |
6653 | && STREQ (TYPE_FIELD_NAME (type, 0), "F")); | |
6654 | } | |
6655 | ||
6656 | /* If there is an ___XVS-convention type parallel to SUBTYPE, return | |
6657 | the parallel type. */ | |
6658 | ||
d2e4a39e AS |
6659 | struct type * |
6660 | ada_get_base_type (struct type *raw_type) | |
14f9c5c9 | 6661 | { |
d2e4a39e AS |
6662 | struct type *real_type_namer; |
6663 | struct type *raw_real_type; | |
6664 | struct type *real_type; | |
14f9c5c9 AS |
6665 | |
6666 | if (raw_type == NULL || TYPE_CODE (raw_type) != TYPE_CODE_STRUCT) | |
6667 | return raw_type; | |
6668 | ||
6669 | real_type_namer = ada_find_parallel_type (raw_type, "___XVS"); | |
d2e4a39e | 6670 | if (real_type_namer == NULL |
14f9c5c9 AS |
6671 | || TYPE_CODE (real_type_namer) != TYPE_CODE_STRUCT |
6672 | || TYPE_NFIELDS (real_type_namer) != 1) | |
6673 | return raw_type; | |
6674 | ||
6675 | raw_real_type = ada_find_any_type (TYPE_FIELD_NAME (real_type_namer, 0)); | |
d2e4a39e | 6676 | if (raw_real_type == NULL) |
14f9c5c9 AS |
6677 | return raw_type; |
6678 | else | |
6679 | return raw_real_type; | |
d2e4a39e | 6680 | } |
14f9c5c9 AS |
6681 | |
6682 | /* The type of value designated by TYPE, with all aligners removed. */ | |
6683 | ||
d2e4a39e AS |
6684 | struct type * |
6685 | ada_aligned_type (struct type *type) | |
14f9c5c9 AS |
6686 | { |
6687 | if (ada_is_aligner_type (type)) | |
6688 | return ada_aligned_type (TYPE_FIELD_TYPE (type, 0)); | |
6689 | else | |
6690 | return ada_get_base_type (type); | |
6691 | } | |
6692 | ||
6693 | ||
6694 | /* The address of the aligned value in an object at address VALADDR | |
6695 | having type TYPE. Assumes ada_is_aligner_type (TYPE). */ | |
6696 | ||
d2e4a39e | 6697 | char * |
ebf56fd3 | 6698 | ada_aligned_value_addr (struct type *type, char *valaddr) |
14f9c5c9 | 6699 | { |
d2e4a39e | 6700 | if (ada_is_aligner_type (type)) |
14f9c5c9 | 6701 | return ada_aligned_value_addr (TYPE_FIELD_TYPE (type, 0), |
d2e4a39e AS |
6702 | valaddr + |
6703 | TYPE_FIELD_BITPOS (type, | |
6704 | 0) / TARGET_CHAR_BIT); | |
14f9c5c9 AS |
6705 | else |
6706 | return valaddr; | |
6707 | } | |
6708 | ||
6709 | /* The printed representation of an enumeration literal with encoded | |
6710 | name NAME. The value is good to the next call of ada_enum_name. */ | |
d2e4a39e AS |
6711 | const char * |
6712 | ada_enum_name (const char *name) | |
14f9c5c9 | 6713 | { |
d2e4a39e | 6714 | char *tmp; |
14f9c5c9 | 6715 | |
d2e4a39e | 6716 | while (1) |
14f9c5c9 AS |
6717 | { |
6718 | if ((tmp = strstr (name, "__")) != NULL) | |
d2e4a39e | 6719 | name = tmp + 2; |
14f9c5c9 | 6720 | else if ((tmp = strchr (name, '.')) != NULL) |
d2e4a39e | 6721 | name = tmp + 1; |
14f9c5c9 AS |
6722 | else |
6723 | break; | |
6724 | } | |
6725 | ||
6726 | if (name[0] == 'Q') | |
6727 | { | |
6728 | static char result[16]; | |
6729 | int v; | |
6730 | if (name[1] == 'U' || name[1] == 'W') | |
6731 | { | |
d2e4a39e | 6732 | if (sscanf (name + 2, "%x", &v) != 1) |
14f9c5c9 AS |
6733 | return name; |
6734 | } | |
6735 | else | |
6736 | return name; | |
6737 | ||
6738 | if (isascii (v) && isprint (v)) | |
6739 | sprintf (result, "'%c'", v); | |
6740 | else if (name[1] == 'U') | |
6741 | sprintf (result, "[\"%02x\"]", v); | |
6742 | else | |
6743 | sprintf (result, "[\"%04x\"]", v); | |
6744 | ||
6745 | return result; | |
6746 | } | |
d2e4a39e | 6747 | else |
14f9c5c9 AS |
6748 | return name; |
6749 | } | |
6750 | ||
d2e4a39e | 6751 | static struct value * |
ebf56fd3 AS |
6752 | evaluate_subexp (struct type *expect_type, struct expression *exp, int *pos, |
6753 | enum noside noside) | |
14f9c5c9 AS |
6754 | { |
6755 | return (*exp->language_defn->evaluate_exp) (expect_type, exp, pos, noside); | |
6756 | } | |
6757 | ||
6758 | /* Evaluate the subexpression of EXP starting at *POS as for | |
6759 | evaluate_type, updating *POS to point just past the evaluated | |
6760 | expression. */ | |
6761 | ||
d2e4a39e AS |
6762 | static struct value * |
6763 | evaluate_subexp_type (struct expression *exp, int *pos) | |
14f9c5c9 | 6764 | { |
d2e4a39e | 6765 | return (*exp->language_defn->evaluate_exp) |
14f9c5c9 AS |
6766 | (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS); |
6767 | } | |
6768 | ||
6769 | /* If VAL is wrapped in an aligner or subtype wrapper, return the | |
d2e4a39e | 6770 | value it wraps. */ |
14f9c5c9 | 6771 | |
d2e4a39e AS |
6772 | static struct value * |
6773 | unwrap_value (struct value *val) | |
14f9c5c9 | 6774 | { |
d2e4a39e | 6775 | struct type *type = check_typedef (VALUE_TYPE (val)); |
14f9c5c9 AS |
6776 | if (ada_is_aligner_type (type)) |
6777 | { | |
d2e4a39e AS |
6778 | struct value *v = value_struct_elt (&val, NULL, "F", |
6779 | NULL, "internal structure"); | |
6780 | struct type *val_type = check_typedef (VALUE_TYPE (v)); | |
14f9c5c9 AS |
6781 | if (ada_type_name (val_type) == NULL) |
6782 | TYPE_NAME (val_type) = ada_type_name (type); | |
6783 | ||
6784 | return unwrap_value (v); | |
6785 | } | |
d2e4a39e | 6786 | else |
14f9c5c9 | 6787 | { |
d2e4a39e | 6788 | struct type *raw_real_type = |
14f9c5c9 | 6789 | ada_completed_type (ada_get_base_type (type)); |
d2e4a39e | 6790 | |
14f9c5c9 AS |
6791 | if (type == raw_real_type) |
6792 | return val; | |
6793 | ||
d2e4a39e AS |
6794 | return |
6795 | coerce_unspec_val_to_type | |
14f9c5c9 AS |
6796 | (val, 0, ada_to_fixed_type (raw_real_type, 0, |
6797 | VALUE_ADDRESS (val) + VALUE_OFFSET (val), | |
6798 | NULL)); | |
6799 | } | |
6800 | } | |
d2e4a39e AS |
6801 | |
6802 | static struct value * | |
6803 | cast_to_fixed (struct type *type, struct value *arg) | |
14f9c5c9 AS |
6804 | { |
6805 | LONGEST val; | |
6806 | ||
6807 | if (type == VALUE_TYPE (arg)) | |
6808 | return arg; | |
6809 | else if (ada_is_fixed_point_type (VALUE_TYPE (arg))) | |
d2e4a39e | 6810 | val = ada_float_to_fixed (type, |
14f9c5c9 AS |
6811 | ada_fixed_to_float (VALUE_TYPE (arg), |
6812 | value_as_long (arg))); | |
d2e4a39e | 6813 | else |
14f9c5c9 | 6814 | { |
d2e4a39e | 6815 | DOUBLEST argd = |
14f9c5c9 AS |
6816 | value_as_double (value_cast (builtin_type_double, value_copy (arg))); |
6817 | val = ada_float_to_fixed (type, argd); | |
6818 | } | |
6819 | ||
6820 | return value_from_longest (type, val); | |
6821 | } | |
6822 | ||
d2e4a39e AS |
6823 | static struct value * |
6824 | cast_from_fixed_to_double (struct value *arg) | |
14f9c5c9 AS |
6825 | { |
6826 | DOUBLEST val = ada_fixed_to_float (VALUE_TYPE (arg), | |
6827 | value_as_long (arg)); | |
6828 | return value_from_double (builtin_type_double, val); | |
6829 | } | |
6830 | ||
6831 | /* Coerce VAL as necessary for assignment to an lval of type TYPE, and | |
6832 | * return the converted value. */ | |
d2e4a39e AS |
6833 | static struct value * |
6834 | coerce_for_assign (struct type *type, struct value *val) | |
14f9c5c9 | 6835 | { |
d2e4a39e | 6836 | struct type *type2 = VALUE_TYPE (val); |
14f9c5c9 AS |
6837 | if (type == type2) |
6838 | return val; | |
6839 | ||
6840 | CHECK_TYPEDEF (type2); | |
6841 | CHECK_TYPEDEF (type); | |
6842 | ||
d2e4a39e AS |
6843 | if (TYPE_CODE (type2) == TYPE_CODE_PTR |
6844 | && TYPE_CODE (type) == TYPE_CODE_ARRAY) | |
14f9c5c9 AS |
6845 | { |
6846 | val = ada_value_ind (val); | |
6847 | type2 = VALUE_TYPE (val); | |
6848 | } | |
6849 | ||
d2e4a39e | 6850 | if (TYPE_CODE (type2) == TYPE_CODE_ARRAY |
14f9c5c9 AS |
6851 | && TYPE_CODE (type) == TYPE_CODE_ARRAY) |
6852 | { | |
6853 | if (TYPE_LENGTH (type2) != TYPE_LENGTH (type) | |
6854 | || TYPE_LENGTH (TYPE_TARGET_TYPE (type2)) | |
d2e4a39e | 6855 | != TYPE_LENGTH (TYPE_TARGET_TYPE (type2))) |
14f9c5c9 AS |
6856 | error ("Incompatible types in assignment"); |
6857 | VALUE_TYPE (val) = type; | |
6858 | } | |
d2e4a39e | 6859 | return val; |
14f9c5c9 AS |
6860 | } |
6861 | ||
d2e4a39e | 6862 | struct value * |
ebf56fd3 AS |
6863 | ada_evaluate_subexp (struct type *expect_type, struct expression *exp, |
6864 | int *pos, enum noside noside) | |
14f9c5c9 AS |
6865 | { |
6866 | enum exp_opcode op; | |
6867 | enum ada_attribute atr; | |
6868 | int tem, tem2, tem3; | |
6869 | int pc; | |
6870 | struct value *arg1 = NULL, *arg2 = NULL, *arg3; | |
6871 | struct type *type; | |
6872 | int nargs; | |
d2e4a39e | 6873 | struct value **argvec; |
14f9c5c9 | 6874 | |
d2e4a39e AS |
6875 | pc = *pos; |
6876 | *pos += 1; | |
14f9c5c9 AS |
6877 | op = exp->elts[pc].opcode; |
6878 | ||
d2e4a39e | 6879 | switch (op) |
14f9c5c9 AS |
6880 | { |
6881 | default: | |
6882 | *pos -= 1; | |
d2e4a39e AS |
6883 | return |
6884 | unwrap_value (evaluate_subexp_standard | |
6885 | (expect_type, exp, pos, noside)); | |
14f9c5c9 AS |
6886 | |
6887 | case UNOP_CAST: | |
6888 | (*pos) += 2; | |
6889 | type = exp->elts[pc + 1].type; | |
6890 | arg1 = evaluate_subexp (type, exp, pos, noside); | |
6891 | if (noside == EVAL_SKIP) | |
6892 | goto nosideret; | |
6893 | if (type != check_typedef (VALUE_TYPE (arg1))) | |
6894 | { | |
6895 | if (ada_is_fixed_point_type (type)) | |
6896 | arg1 = cast_to_fixed (type, arg1); | |
6897 | else if (ada_is_fixed_point_type (VALUE_TYPE (arg1))) | |
6898 | arg1 = value_cast (type, cast_from_fixed_to_double (arg1)); | |
d2e4a39e | 6899 | else if (VALUE_LVAL (arg1) == lval_memory) |
14f9c5c9 AS |
6900 | { |
6901 | /* This is in case of the really obscure (and undocumented, | |
d2e4a39e AS |
6902 | but apparently expected) case of (Foo) Bar.all, where Bar |
6903 | is an integer constant and Foo is a dynamic-sized type. | |
6904 | If we don't do this, ARG1 will simply be relabeled with | |
6905 | TYPE. */ | |
6906 | if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
14f9c5c9 | 6907 | return value_zero (to_static_fixed_type (type), not_lval); |
d2e4a39e AS |
6908 | arg1 = |
6909 | ada_to_fixed_value | |
6910 | (type, 0, VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1), 0); | |
14f9c5c9 | 6911 | } |
d2e4a39e AS |
6912 | else |
6913 | arg1 = value_cast (type, arg1); | |
14f9c5c9 AS |
6914 | } |
6915 | return arg1; | |
6916 | ||
6917 | /* FIXME: UNOP_QUAL should be defined in expression.h */ | |
6918 | /* case UNOP_QUAL: | |
d2e4a39e AS |
6919 | (*pos) += 2; |
6920 | type = exp->elts[pc + 1].type; | |
6921 | return ada_evaluate_subexp (type, exp, pos, noside); | |
6922 | */ | |
14f9c5c9 AS |
6923 | case BINOP_ASSIGN: |
6924 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
6925 | arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside); | |
6926 | if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS) | |
6927 | return arg1; | |
6928 | if (binop_user_defined_p (op, arg1, arg2)) | |
6929 | return value_x_binop (arg1, arg2, op, OP_NULL, EVAL_NORMAL); | |
d2e4a39e | 6930 | else |
14f9c5c9 AS |
6931 | { |
6932 | if (ada_is_fixed_point_type (VALUE_TYPE (arg1))) | |
6933 | arg2 = cast_to_fixed (VALUE_TYPE (arg1), arg2); | |
6934 | else if (ada_is_fixed_point_type (VALUE_TYPE (arg2))) | |
d2e4a39e AS |
6935 | error |
6936 | ("Fixed-point values must be assigned to fixed-point variables"); | |
6937 | else | |
14f9c5c9 AS |
6938 | arg2 = coerce_for_assign (VALUE_TYPE (arg1), arg2); |
6939 | return ada_value_assign (arg1, arg2); | |
6940 | } | |
6941 | ||
6942 | case BINOP_ADD: | |
6943 | arg1 = evaluate_subexp_with_coercion (exp, pos, noside); | |
6944 | arg2 = evaluate_subexp_with_coercion (exp, pos, noside); | |
6945 | if (noside == EVAL_SKIP) | |
6946 | goto nosideret; | |
6947 | if (binop_user_defined_p (op, arg1, arg2)) | |
6948 | return value_x_binop (arg1, arg2, op, OP_NULL, EVAL_NORMAL); | |
6949 | else | |
6950 | { | |
6951 | if ((ada_is_fixed_point_type (VALUE_TYPE (arg1)) | |
6952 | || ada_is_fixed_point_type (VALUE_TYPE (arg2))) | |
6953 | && VALUE_TYPE (arg1) != VALUE_TYPE (arg2)) | |
d2e4a39e AS |
6954 | error |
6955 | ("Operands of fixed-point addition must have the same type"); | |
14f9c5c9 AS |
6956 | return value_cast (VALUE_TYPE (arg1), value_add (arg1, arg2)); |
6957 | } | |
6958 | ||
6959 | case BINOP_SUB: | |
6960 | arg1 = evaluate_subexp_with_coercion (exp, pos, noside); | |
6961 | arg2 = evaluate_subexp_with_coercion (exp, pos, noside); | |
6962 | if (noside == EVAL_SKIP) | |
6963 | goto nosideret; | |
6964 | if (binop_user_defined_p (op, arg1, arg2)) | |
6965 | return value_x_binop (arg1, arg2, op, OP_NULL, EVAL_NORMAL); | |
6966 | else | |
6967 | { | |
6968 | if ((ada_is_fixed_point_type (VALUE_TYPE (arg1)) | |
6969 | || ada_is_fixed_point_type (VALUE_TYPE (arg2))) | |
6970 | && VALUE_TYPE (arg1) != VALUE_TYPE (arg2)) | |
d2e4a39e AS |
6971 | error |
6972 | ("Operands of fixed-point subtraction must have the same type"); | |
14f9c5c9 AS |
6973 | return value_cast (VALUE_TYPE (arg1), value_sub (arg1, arg2)); |
6974 | } | |
6975 | ||
6976 | case BINOP_MUL: | |
6977 | case BINOP_DIV: | |
6978 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
6979 | arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
6980 | if (noside == EVAL_SKIP) | |
6981 | goto nosideret; | |
6982 | if (binop_user_defined_p (op, arg1, arg2)) | |
6983 | return value_x_binop (arg1, arg2, op, OP_NULL, EVAL_NORMAL); | |
6984 | else | |
6985 | if (noside == EVAL_AVOID_SIDE_EFFECTS | |
6986 | && (op == BINOP_DIV || op == BINOP_REM || op == BINOP_MOD)) | |
d2e4a39e | 6987 | return value_zero (VALUE_TYPE (arg1), not_lval); |
14f9c5c9 AS |
6988 | else |
6989 | { | |
6990 | if (ada_is_fixed_point_type (VALUE_TYPE (arg1))) | |
6991 | arg1 = cast_from_fixed_to_double (arg1); | |
6992 | if (ada_is_fixed_point_type (VALUE_TYPE (arg2))) | |
6993 | arg2 = cast_from_fixed_to_double (arg2); | |
6994 | return value_binop (arg1, arg2, op); | |
6995 | } | |
6996 | ||
6997 | case UNOP_NEG: | |
6998 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
6999 | if (noside == EVAL_SKIP) | |
7000 | goto nosideret; | |
7001 | if (unop_user_defined_p (op, arg1)) | |
7002 | return value_x_unop (arg1, op, EVAL_NORMAL); | |
7003 | else if (ada_is_fixed_point_type (VALUE_TYPE (arg1))) | |
7004 | return value_cast (VALUE_TYPE (arg1), value_neg (arg1)); | |
7005 | else | |
7006 | return value_neg (arg1); | |
7007 | ||
7008 | /* FIXME: OP_UNRESOLVED_VALUE should be defined in expression.h */ | |
7009 | /* case OP_UNRESOLVED_VALUE: | |
d2e4a39e | 7010 | /* Only encountered when an unresolved symbol occurs in a |
14f9c5c9 | 7011 | context other than a function call, in which case, it is |
d2e4a39e AS |
7012 | illegal. *//* |
7013 | (*pos) += 3; | |
7014 | if (noside == EVAL_SKIP) | |
7015 | goto nosideret; | |
7016 | else | |
7017 | error ("Unexpected unresolved symbol, %s, during evaluation", | |
7018 | ada_demangle (exp->elts[pc + 2].name)); | |
7019 | */ | |
14f9c5c9 AS |
7020 | case OP_VAR_VALUE: |
7021 | *pos -= 1; | |
7022 | if (noside == EVAL_SKIP) | |
7023 | { | |
7024 | *pos += 4; | |
7025 | goto nosideret; | |
d2e4a39e | 7026 | } |
14f9c5c9 AS |
7027 | else if (noside == EVAL_AVOID_SIDE_EFFECTS) |
7028 | { | |
7029 | *pos += 4; | |
d2e4a39e AS |
7030 | return value_zero |
7031 | (to_static_fixed_type | |
7032 | (static_unwrap_type (SYMBOL_TYPE (exp->elts[pc + 2].symbol))), | |
14f9c5c9 AS |
7033 | not_lval); |
7034 | } | |
d2e4a39e | 7035 | else |
14f9c5c9 | 7036 | { |
d2e4a39e AS |
7037 | arg1 = |
7038 | unwrap_value (evaluate_subexp_standard | |
7039 | (expect_type, exp, pos, noside)); | |
14f9c5c9 | 7040 | return ada_to_fixed_value (VALUE_TYPE (arg1), 0, |
d2e4a39e AS |
7041 | VALUE_ADDRESS (arg1) + |
7042 | VALUE_OFFSET (arg1), arg1); | |
14f9c5c9 AS |
7043 | } |
7044 | ||
7045 | case OP_ARRAY: | |
7046 | (*pos) += 3; | |
7047 | tem2 = longest_to_int (exp->elts[pc + 1].longconst); | |
7048 | tem3 = longest_to_int (exp->elts[pc + 2].longconst); | |
7049 | nargs = tem3 - tem2 + 1; | |
7050 | type = expect_type ? check_typedef (expect_type) : NULL_TYPE; | |
7051 | ||
d2e4a39e AS |
7052 | argvec = |
7053 | (struct value * *) alloca (sizeof (struct value *) * (nargs + 1)); | |
14f9c5c9 AS |
7054 | for (tem = 0; tem == 0 || tem < nargs; tem += 1) |
7055 | /* At least one element gets inserted for the type */ | |
7056 | { | |
7057 | /* Ensure that array expressions are coerced into pointer objects. */ | |
7058 | argvec[tem] = evaluate_subexp_with_coercion (exp, pos, noside); | |
7059 | } | |
7060 | if (noside == EVAL_SKIP) | |
7061 | goto nosideret; | |
7062 | return value_array (tem2, tem3, argvec); | |
7063 | ||
7064 | case OP_FUNCALL: | |
7065 | (*pos) += 2; | |
7066 | ||
7067 | /* Allocate arg vector, including space for the function to be | |
d2e4a39e | 7068 | called in argvec[0] and a terminating NULL */ |
14f9c5c9 | 7069 | nargs = longest_to_int (exp->elts[pc + 1].longconst); |
d2e4a39e AS |
7070 | argvec = |
7071 | (struct value * *) alloca (sizeof (struct value *) * (nargs + 2)); | |
14f9c5c9 AS |
7072 | |
7073 | /* FIXME: OP_UNRESOLVED_VALUE should be defined in expression.h */ | |
7074 | /* FIXME: name should be defined in expresion.h */ | |
7075 | /* if (exp->elts[*pos].opcode == OP_UNRESOLVED_VALUE) | |
d2e4a39e AS |
7076 | error ("Unexpected unresolved symbol, %s, during evaluation", |
7077 | ada_demangle (exp->elts[pc + 5].name)); | |
7078 | */ | |
7079 | if (0) | |
14f9c5c9 AS |
7080 | { |
7081 | error ("unexpected code path, FIXME"); | |
7082 | } | |
7083 | else | |
7084 | { | |
7085 | for (tem = 0; tem <= nargs; tem += 1) | |
7086 | argvec[tem] = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
7087 | argvec[tem] = 0; | |
7088 | ||
7089 | if (noside == EVAL_SKIP) | |
7090 | goto nosideret; | |
7091 | } | |
7092 | ||
7093 | if (TYPE_CODE (VALUE_TYPE (argvec[0])) == TYPE_CODE_REF) | |
7094 | argvec[0] = value_addr (argvec[0]); | |
7095 | ||
7096 | if (ada_is_packed_array_type (VALUE_TYPE (argvec[0]))) | |
7097 | argvec[0] = ada_coerce_to_simple_array (argvec[0]); | |
7098 | ||
7099 | type = check_typedef (VALUE_TYPE (argvec[0])); | |
7100 | if (TYPE_CODE (type) == TYPE_CODE_PTR) | |
d2e4a39e | 7101 | { |
14f9c5c9 AS |
7102 | switch (TYPE_CODE (check_typedef (TYPE_TARGET_TYPE (type)))) |
7103 | { | |
7104 | case TYPE_CODE_FUNC: | |
7105 | type = check_typedef (TYPE_TARGET_TYPE (type)); | |
7106 | break; | |
7107 | case TYPE_CODE_ARRAY: | |
7108 | break; | |
7109 | case TYPE_CODE_STRUCT: | |
7110 | if (noside != EVAL_AVOID_SIDE_EFFECTS) | |
7111 | argvec[0] = ada_value_ind (argvec[0]); | |
7112 | type = check_typedef (TYPE_TARGET_TYPE (type)); | |
7113 | break; | |
7114 | default: | |
7115 | error ("cannot subscript or call something of type `%s'", | |
7116 | ada_type_name (VALUE_TYPE (argvec[0]))); | |
7117 | break; | |
d2e4a39e | 7118 | } |
14f9c5c9 | 7119 | } |
d2e4a39e | 7120 | |
14f9c5c9 AS |
7121 | switch (TYPE_CODE (type)) |
7122 | { | |
7123 | case TYPE_CODE_FUNC: | |
7124 | if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
7125 | return allocate_value (TYPE_TARGET_TYPE (type)); | |
7126 | return call_function_by_hand (argvec[0], nargs, argvec + 1); | |
d2e4a39e | 7127 | case TYPE_CODE_STRUCT: |
14f9c5c9 AS |
7128 | { |
7129 | int arity = ada_array_arity (type); | |
7130 | type = ada_array_element_type (type, nargs); | |
d2e4a39e | 7131 | if (type == NULL) |
14f9c5c9 | 7132 | error ("cannot subscript or call a record"); |
d2e4a39e | 7133 | if (arity != nargs) |
14f9c5c9 | 7134 | error ("wrong number of subscripts; expecting %d", arity); |
d2e4a39e | 7135 | if (noside == EVAL_AVOID_SIDE_EFFECTS) |
14f9c5c9 | 7136 | return allocate_value (ada_aligned_type (type)); |
d2e4a39e AS |
7137 | return |
7138 | unwrap_value (ada_value_subscript | |
7139 | (argvec[0], nargs, argvec + 1)); | |
14f9c5c9 AS |
7140 | } |
7141 | case TYPE_CODE_ARRAY: | |
7142 | if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
d2e4a39e | 7143 | { |
14f9c5c9 AS |
7144 | type = ada_array_element_type (type, nargs); |
7145 | if (type == NULL) | |
7146 | error ("element type of array unknown"); | |
7147 | else | |
7148 | return allocate_value (ada_aligned_type (type)); | |
7149 | } | |
d2e4a39e | 7150 | return |
14f9c5c9 AS |
7151 | unwrap_value (ada_value_subscript |
7152 | (ada_coerce_to_simple_array (argvec[0]), | |
d2e4a39e AS |
7153 | nargs, argvec + 1)); |
7154 | case TYPE_CODE_PTR: /* Pointer to array */ | |
14f9c5c9 AS |
7155 | type = to_fixed_array_type (TYPE_TARGET_TYPE (type), NULL, 1); |
7156 | if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
d2e4a39e | 7157 | { |
14f9c5c9 AS |
7158 | type = ada_array_element_type (type, nargs); |
7159 | if (type == NULL) | |
7160 | error ("element type of array unknown"); | |
7161 | else | |
7162 | return allocate_value (ada_aligned_type (type)); | |
7163 | } | |
d2e4a39e AS |
7164 | return |
7165 | unwrap_value (ada_value_ptr_subscript (argvec[0], type, | |
7166 | nargs, argvec + 1)); | |
14f9c5c9 AS |
7167 | |
7168 | default: | |
7169 | error ("Internal error in evaluate_subexp"); | |
7170 | } | |
7171 | ||
7172 | case TERNOP_SLICE: | |
7173 | { | |
d2e4a39e | 7174 | struct value *array = evaluate_subexp (NULL_TYPE, exp, pos, noside); |
14f9c5c9 AS |
7175 | int lowbound |
7176 | = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside)); | |
7177 | int upper | |
7178 | = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside)); | |
7179 | if (noside == EVAL_SKIP) | |
7180 | goto nosideret; | |
d2e4a39e AS |
7181 | |
7182 | /* If this is a reference to an array, then dereference it */ | |
7183 | if (TYPE_CODE (VALUE_TYPE (array)) == TYPE_CODE_REF | |
7184 | && TYPE_TARGET_TYPE (VALUE_TYPE (array)) != NULL | |
7185 | && TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (array))) == | |
7186 | TYPE_CODE_ARRAY | |
7187 | && !ada_is_array_descriptor (check_typedef (VALUE_TYPE (array)))) | |
7188 | { | |
7189 | array = ada_coerce_ref (array); | |
7190 | } | |
14f9c5c9 AS |
7191 | |
7192 | if (noside == EVAL_AVOID_SIDE_EFFECTS && | |
7193 | ada_is_array_descriptor (check_typedef (VALUE_TYPE (array)))) | |
7194 | { | |
7195 | /* Try to dereference the array, in case it is an access to array */ | |
d2e4a39e | 7196 | struct type *arrType = ada_type_of_array (array, 0); |
14f9c5c9 | 7197 | if (arrType != NULL) |
d2e4a39e | 7198 | array = value_at_lazy (arrType, 0, NULL); |
14f9c5c9 AS |
7199 | } |
7200 | if (ada_is_array_descriptor (VALUE_TYPE (array))) | |
7201 | array = ada_coerce_to_simple_array (array); | |
7202 | ||
d2e4a39e AS |
7203 | /* If at this point we have a pointer to an array, it means that |
7204 | it is a pointer to a simple (non-ada) array. We just then | |
7205 | dereference it */ | |
7206 | if (TYPE_CODE (VALUE_TYPE (array)) == TYPE_CODE_PTR | |
7207 | && TYPE_TARGET_TYPE (VALUE_TYPE (array)) != NULL | |
7208 | && TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (array))) == | |
7209 | TYPE_CODE_ARRAY) | |
7210 | { | |
7211 | array = ada_value_ind (array); | |
7212 | } | |
7213 | ||
14f9c5c9 AS |
7214 | if (noside == EVAL_AVOID_SIDE_EFFECTS) |
7215 | /* The following will get the bounds wrong, but only in contexts | |
7216 | where the value is not being requested (FIXME?). */ | |
7217 | return array; | |
7218 | else | |
7219 | return value_slice (array, lowbound, upper - lowbound + 1); | |
7220 | } | |
7221 | ||
7222 | /* FIXME: UNOP_MBR should be defined in expression.h */ | |
7223 | /* case UNOP_MBR: | |
d2e4a39e AS |
7224 | (*pos) += 2; |
7225 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
7226 | type = exp->elts[pc + 1].type; | |
7227 | ||
7228 | if (noside == EVAL_SKIP) | |
7229 | goto nosideret; | |
7230 | ||
7231 | switch (TYPE_CODE (type)) | |
7232 | { | |
7233 | default: | |
7234 | warning ("Membership test incompletely implemented; always returns true"); | |
7235 | return value_from_longest (builtin_type_int, (LONGEST) 1); | |
7236 | ||
7237 | case TYPE_CODE_RANGE: | |
7238 | arg2 = value_from_longest (builtin_type_int, | |
7239 | (LONGEST) TYPE_LOW_BOUND (type)); | |
7240 | arg3 = value_from_longest (builtin_type_int, | |
7241 | (LONGEST) TYPE_HIGH_BOUND (type)); | |
7242 | return | |
7243 | value_from_longest (builtin_type_int, | |
7244 | (value_less (arg1,arg3) | |
7245 | || value_equal (arg1,arg3)) | |
7246 | && (value_less (arg2,arg1) | |
7247 | || value_equal (arg2,arg1))); | |
7248 | } | |
7249 | */ | |
7250 | /* FIXME: BINOP_MBR should be defined in expression.h */ | |
14f9c5c9 | 7251 | /* case BINOP_MBR: |
d2e4a39e AS |
7252 | (*pos) += 2; |
7253 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
7254 | arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
14f9c5c9 | 7255 | |
d2e4a39e AS |
7256 | if (noside == EVAL_SKIP) |
7257 | goto nosideret; | |
14f9c5c9 | 7258 | |
d2e4a39e AS |
7259 | if (noside == EVAL_AVOID_SIDE_EFFECTS) |
7260 | return value_zero (builtin_type_int, not_lval); | |
14f9c5c9 | 7261 | |
d2e4a39e | 7262 | tem = longest_to_int (exp->elts[pc + 1].longconst); |
14f9c5c9 | 7263 | |
d2e4a39e AS |
7264 | if (tem < 1 || tem > ada_array_arity (VALUE_TYPE (arg2))) |
7265 | error ("invalid dimension number to '%s", "range"); | |
14f9c5c9 | 7266 | |
d2e4a39e AS |
7267 | arg3 = ada_array_bound (arg2, tem, 1); |
7268 | arg2 = ada_array_bound (arg2, tem, 0); | |
14f9c5c9 | 7269 | |
d2e4a39e AS |
7270 | return |
7271 | value_from_longest (builtin_type_int, | |
7272 | (value_less (arg1,arg3) | |
7273 | || value_equal (arg1,arg3)) | |
7274 | && (value_less (arg2,arg1) | |
7275 | || value_equal (arg2,arg1))); | |
7276 | */ | |
14f9c5c9 AS |
7277 | /* FIXME: TERNOP_MBR should be defined in expression.h */ |
7278 | /* case TERNOP_MBR: | |
d2e4a39e AS |
7279 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); |
7280 | arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
7281 | arg3 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
7282 | ||
7283 | if (noside == EVAL_SKIP) | |
7284 | goto nosideret; | |
7285 | ||
7286 | return | |
7287 | value_from_longest (builtin_type_int, | |
7288 | (value_less (arg1,arg3) | |
7289 | || value_equal (arg1,arg3)) | |
7290 | && (value_less (arg2,arg1) | |
7291 | || value_equal (arg2,arg1))); | |
7292 | */ | |
14f9c5c9 AS |
7293 | /* FIXME: OP_ATTRIBUTE should be defined in expression.h */ |
7294 | /* case OP_ATTRIBUTE: | |
d2e4a39e AS |
7295 | *pos += 3; |
7296 | atr = (enum ada_attribute) longest_to_int (exp->elts[pc + 2].longconst); | |
7297 | switch (atr) | |
7298 | { | |
7299 | default: | |
7300 | error ("unexpected attribute encountered"); | |
7301 | ||
7302 | case ATR_FIRST: | |
7303 | case ATR_LAST: | |
7304 | case ATR_LENGTH: | |
7305 | { | |
7306 | struct type* type_arg; | |
7307 | if (exp->elts[*pos].opcode == OP_TYPE) | |
7308 | { | |
7309 | evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP); | |
7310 | arg1 = NULL; | |
7311 | type_arg = exp->elts[pc + 5].type; | |
7312 | } | |
7313 | else | |
7314 | { | |
7315 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
7316 | type_arg = NULL; | |
7317 | } | |
7318 | ||
7319 | if (exp->elts[*pos].opcode != OP_LONG) | |
7320 | error ("illegal operand to '%s", ada_attribute_name (atr)); | |
7321 | tem = longest_to_int (exp->elts[*pos+2].longconst); | |
7322 | *pos += 4; | |
7323 | ||
7324 | if (noside == EVAL_SKIP) | |
7325 | goto nosideret; | |
7326 | ||
7327 | if (type_arg == NULL) | |
7328 | { | |
7329 | arg1 = ada_coerce_ref (arg1); | |
7330 | ||
7331 | if (ada_is_packed_array_type (VALUE_TYPE (arg1))) | |
7332 | arg1 = ada_coerce_to_simple_array (arg1); | |
7333 | ||
7334 | if (tem < 1 || tem > ada_array_arity (VALUE_TYPE (arg1))) | |
7335 | error ("invalid dimension number to '%s", | |
7336 | ada_attribute_name (atr)); | |
7337 | ||
7338 | if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
7339 | { | |
7340 | type = ada_index_type (VALUE_TYPE (arg1), tem); | |
7341 | if (type == NULL) | |
7342 | error ("attempt to take bound of something that is not an array"); | |
7343 | return allocate_value (type); | |
7344 | } | |
7345 | ||
7346 | switch (atr) | |
7347 | { | |
7348 | default: | |
7349 | error ("unexpected attribute encountered"); | |
7350 | case ATR_FIRST: | |
7351 | return ada_array_bound (arg1, tem, 0); | |
7352 | case ATR_LAST: | |
7353 | return ada_array_bound (arg1, tem, 1); | |
7354 | case ATR_LENGTH: | |
7355 | return ada_array_length (arg1, tem); | |
7356 | } | |
7357 | } | |
7358 | else if (TYPE_CODE (type_arg) == TYPE_CODE_RANGE | |
7359 | || TYPE_CODE (type_arg) == TYPE_CODE_INT) | |
7360 | { | |
7361 | struct type* range_type; | |
7362 | char* name = ada_type_name (type_arg); | |
7363 | if (name == NULL) | |
7364 | { | |
7365 | if (TYPE_CODE (type_arg) == TYPE_CODE_RANGE) | |
7366 | range_type = type_arg; | |
7367 | else | |
7368 | error ("unimplemented type attribute"); | |
7369 | } | |
7370 | else | |
7371 | range_type = | |
7372 | to_fixed_range_type (name, NULL, TYPE_OBJFILE (type_arg)); | |
7373 | switch (atr) | |
7374 | { | |
7375 | default: | |
7376 | error ("unexpected attribute encountered"); | |
7377 | case ATR_FIRST: | |
7378 | return value_from_longest (TYPE_TARGET_TYPE (range_type), | |
7379 | TYPE_LOW_BOUND (range_type)); | |
7380 | case ATR_LAST: | |
7381 | return value_from_longest (TYPE_TARGET_TYPE (range_type), | |
7382 | TYPE_HIGH_BOUND (range_type)); | |
7383 | } | |
7384 | } | |
7385 | else if (TYPE_CODE (type_arg) == TYPE_CODE_ENUM) | |
7386 | { | |
7387 | switch (atr) | |
7388 | { | |
7389 | default: | |
7390 | error ("unexpected attribute encountered"); | |
7391 | case ATR_FIRST: | |
7392 | return value_from_longest | |
7393 | (type_arg, TYPE_FIELD_BITPOS (type_arg, 0)); | |
7394 | case ATR_LAST: | |
7395 | return value_from_longest | |
7396 | (type_arg, | |
7397 | TYPE_FIELD_BITPOS (type_arg, | |
7398 | TYPE_NFIELDS (type_arg) - 1)); | |
7399 | } | |
7400 | } | |
7401 | else if (TYPE_CODE (type_arg) == TYPE_CODE_FLT) | |
7402 | error ("unimplemented type attribute"); | |
7403 | else | |
7404 | { | |
7405 | LONGEST low, high; | |
7406 | ||
7407 | if (ada_is_packed_array_type (type_arg)) | |
7408 | type_arg = decode_packed_array_type (type_arg); | |
7409 | ||
7410 | if (tem < 1 || tem > ada_array_arity (type_arg)) | |
7411 | error ("invalid dimension number to '%s", | |
7412 | ada_attribute_name (atr)); | |
7413 | ||
7414 | if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
7415 | { | |
7416 | type = ada_index_type (type_arg, tem); | |
7417 | if (type == NULL) | |
7418 | error ("attempt to take bound of something that is not an array"); | |
7419 | return allocate_value (type); | |
7420 | } | |
7421 | ||
7422 | switch (atr) | |
7423 | { | |
7424 | default: | |
7425 | error ("unexpected attribute encountered"); | |
7426 | case ATR_FIRST: | |
7427 | low = ada_array_bound_from_type (type_arg, tem, 0, &type); | |
7428 | return value_from_longest (type, low); | |
7429 | case ATR_LAST: | |
7430 | high = ada_array_bound_from_type (type_arg, tem, 1, &type); | |
7431 | return value_from_longest (type, high); | |
7432 | case ATR_LENGTH: | |
7433 | low = ada_array_bound_from_type (type_arg, tem, 0, &type); | |
7434 | high = ada_array_bound_from_type (type_arg, tem, 1, NULL); | |
7435 | return value_from_longest (type, high-low+1); | |
7436 | } | |
7437 | } | |
7438 | } | |
7439 | ||
7440 | case ATR_TAG: | |
7441 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
7442 | if (noside == EVAL_SKIP) | |
7443 | goto nosideret; | |
7444 | ||
7445 | if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
7446 | return | |
7447 | value_zero (ada_tag_type (arg1), not_lval); | |
7448 | ||
7449 | return ada_value_tag (arg1); | |
7450 | ||
7451 | case ATR_MIN: | |
7452 | case ATR_MAX: | |
7453 | evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP); | |
7454 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
7455 | arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
7456 | if (noside == EVAL_SKIP) | |
7457 | goto nosideret; | |
7458 | else if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
7459 | return value_zero (VALUE_TYPE (arg1), not_lval); | |
7460 | else | |
7461 | return value_binop (arg1, arg2, | |
7462 | atr == ATR_MIN ? BINOP_MIN : BINOP_MAX); | |
7463 | ||
7464 | case ATR_MODULUS: | |
7465 | { | |
7466 | struct type* type_arg = exp->elts[pc + 5].type; | |
7467 | evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP); | |
7468 | *pos += 4; | |
7469 | ||
7470 | if (noside == EVAL_SKIP) | |
7471 | goto nosideret; | |
7472 | ||
7473 | if (! ada_is_modular_type (type_arg)) | |
7474 | error ("'modulus must be applied to modular type"); | |
7475 | ||
7476 | return value_from_longest (TYPE_TARGET_TYPE (type_arg), | |
7477 | ada_modulus (type_arg)); | |
7478 | } | |
7479 | ||
7480 | ||
7481 | case ATR_POS: | |
7482 | evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP); | |
7483 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
7484 | if (noside == EVAL_SKIP) | |
7485 | goto nosideret; | |
7486 | else if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
7487 | return value_zero (builtin_type_ada_int, not_lval); | |
7488 | else | |
7489 | return value_pos_atr (arg1); | |
7490 | ||
7491 | case ATR_SIZE: | |
7492 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
7493 | if (noside == EVAL_SKIP) | |
7494 | goto nosideret; | |
7495 | else if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
7496 | return value_zero (builtin_type_ada_int, not_lval); | |
7497 | else | |
7498 | return value_from_longest (builtin_type_ada_int, | |
7499 | TARGET_CHAR_BIT | |
7500 | * TYPE_LENGTH (VALUE_TYPE (arg1))); | |
7501 | ||
7502 | case ATR_VAL: | |
7503 | evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP); | |
7504 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
7505 | type = exp->elts[pc + 5].type; | |
7506 | if (noside == EVAL_SKIP) | |
7507 | goto nosideret; | |
7508 | else if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
7509 | return value_zero (type, not_lval); | |
7510 | else | |
7511 | return value_val_atr (type, arg1); | |
7512 | } */ | |
14f9c5c9 AS |
7513 | case BINOP_EXP: |
7514 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
7515 | arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
7516 | if (noside == EVAL_SKIP) | |
7517 | goto nosideret; | |
7518 | if (binop_user_defined_p (op, arg1, arg2)) | |
7519 | return unwrap_value (value_x_binop (arg1, arg2, op, OP_NULL, | |
d2e4a39e AS |
7520 | EVAL_NORMAL)); |
7521 | else if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
7522 | return value_zero (VALUE_TYPE (arg1), not_lval); | |
14f9c5c9 AS |
7523 | else |
7524 | return value_binop (arg1, arg2, op); | |
7525 | ||
7526 | case UNOP_PLUS: | |
7527 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
7528 | if (noside == EVAL_SKIP) | |
7529 | goto nosideret; | |
7530 | if (unop_user_defined_p (op, arg1)) | |
7531 | return unwrap_value (value_x_unop (arg1, op, EVAL_NORMAL)); | |
7532 | else | |
7533 | return arg1; | |
7534 | ||
7535 | case UNOP_ABS: | |
7536 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
7537 | if (noside == EVAL_SKIP) | |
7538 | goto nosideret; | |
7539 | if (value_less (arg1, value_zero (VALUE_TYPE (arg1), not_lval))) | |
7540 | return value_neg (arg1); | |
7541 | else | |
7542 | return arg1; | |
7543 | ||
7544 | case UNOP_IND: | |
7545 | if (expect_type && TYPE_CODE (expect_type) == TYPE_CODE_PTR) | |
d2e4a39e | 7546 | expect_type = TYPE_TARGET_TYPE (check_typedef (expect_type)); |
14f9c5c9 AS |
7547 | arg1 = evaluate_subexp (expect_type, exp, pos, noside); |
7548 | if (noside == EVAL_SKIP) | |
7549 | goto nosideret; | |
7550 | type = check_typedef (VALUE_TYPE (arg1)); | |
7551 | if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
7552 | { | |
7553 | if (ada_is_array_descriptor (type)) | |
7554 | /* GDB allows dereferencing GNAT array descriptors. */ | |
7555 | { | |
d2e4a39e | 7556 | struct type *arrType = ada_type_of_array (arg1, 0); |
14f9c5c9 AS |
7557 | if (arrType == NULL) |
7558 | error ("Attempt to dereference null array pointer."); | |
7559 | return value_at_lazy (arrType, 0, NULL); | |
7560 | } | |
7561 | else if (TYPE_CODE (type) == TYPE_CODE_PTR | |
d2e4a39e AS |
7562 | || TYPE_CODE (type) == TYPE_CODE_REF |
7563 | /* In C you can dereference an array to get the 1st elt. */ | |
7564 | || TYPE_CODE (type) == TYPE_CODE_ARRAY) | |
7565 | return | |
7566 | value_zero | |
7567 | (to_static_fixed_type | |
7568 | (ada_aligned_type (check_typedef (TYPE_TARGET_TYPE (type)))), | |
7569 | lval_memory); | |
14f9c5c9 AS |
7570 | else if (TYPE_CODE (type) == TYPE_CODE_INT) |
7571 | /* GDB allows dereferencing an int. */ | |
7572 | return value_zero (builtin_type_int, lval_memory); | |
7573 | else | |
7574 | error ("Attempt to take contents of a non-pointer value."); | |
7575 | } | |
7576 | arg1 = ada_coerce_ref (arg1); | |
7577 | type = check_typedef (VALUE_TYPE (arg1)); | |
d2e4a39e | 7578 | |
14f9c5c9 AS |
7579 | if (ada_is_array_descriptor (type)) |
7580 | /* GDB allows dereferencing GNAT array descriptors. */ | |
7581 | return ada_coerce_to_simple_array (arg1); | |
7582 | else | |
7583 | return ada_value_ind (arg1); | |
7584 | ||
7585 | case STRUCTOP_STRUCT: | |
7586 | tem = longest_to_int (exp->elts[pc + 1].longconst); | |
7587 | (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1); | |
7588 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
7589 | if (noside == EVAL_SKIP) | |
7590 | goto nosideret; | |
7591 | if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
d2e4a39e | 7592 | return value_zero (ada_aligned_type |
14f9c5c9 | 7593 | (ada_lookup_struct_elt_type (VALUE_TYPE (arg1), |
d2e4a39e AS |
7594 | &exp->elts[pc + |
7595 | 2].string, | |
14f9c5c9 AS |
7596 | 0, NULL)), |
7597 | lval_memory); | |
7598 | else | |
7599 | return unwrap_value (ada_value_struct_elt (arg1, | |
7600 | &exp->elts[pc + 2].string, | |
7601 | "record")); | |
7602 | case OP_TYPE: | |
7603 | /* The value is not supposed to be used. This is here to make it | |
7604 | easier to accommodate expressions that contain types. */ | |
7605 | (*pos) += 2; | |
7606 | if (noside == EVAL_SKIP) | |
7607 | goto nosideret; | |
7608 | else if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
7609 | return allocate_value (builtin_type_void); | |
d2e4a39e | 7610 | else |
14f9c5c9 | 7611 | error ("Attempt to use a type name as an expression"); |
d2e4a39e | 7612 | |
14f9c5c9 AS |
7613 | case STRUCTOP_PTR: |
7614 | tem = longest_to_int (exp->elts[pc + 1].longconst); | |
7615 | (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1); | |
7616 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
7617 | if (noside == EVAL_SKIP) | |
7618 | goto nosideret; | |
7619 | if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
d2e4a39e | 7620 | return value_zero (ada_aligned_type |
14f9c5c9 | 7621 | (ada_lookup_struct_elt_type (VALUE_TYPE (arg1), |
d2e4a39e AS |
7622 | &exp->elts[pc + |
7623 | 2].string, | |
14f9c5c9 AS |
7624 | 0, NULL)), |
7625 | lval_memory); | |
7626 | else | |
7627 | return unwrap_value (ada_value_struct_elt (arg1, | |
7628 | &exp->elts[pc + 2].string, | |
7629 | "record access")); | |
7630 | } | |
7631 | ||
7632 | nosideret: | |
7633 | return value_from_longest (builtin_type_long, (LONGEST) 1); | |
7634 | } | |
14f9c5c9 | 7635 | \f |
d2e4a39e | 7636 | |
14f9c5c9 AS |
7637 | /* Fixed point */ |
7638 | ||
7639 | /* If TYPE encodes an Ada fixed-point type, return the suffix of the | |
7640 | type name that encodes the 'small and 'delta information. | |
7641 | Otherwise, return NULL. */ | |
7642 | ||
d2e4a39e | 7643 | static const char * |
ebf56fd3 | 7644 | fixed_type_info (struct type *type) |
14f9c5c9 | 7645 | { |
d2e4a39e | 7646 | const char *name = ada_type_name (type); |
14f9c5c9 AS |
7647 | enum type_code code = (type == NULL) ? TYPE_CODE_UNDEF : TYPE_CODE (type); |
7648 | ||
d2e4a39e AS |
7649 | if ((code == TYPE_CODE_INT || code == TYPE_CODE_RANGE) && name != NULL) |
7650 | { | |
14f9c5c9 AS |
7651 | const char *tail = strstr (name, "___XF_"); |
7652 | if (tail == NULL) | |
7653 | return NULL; | |
d2e4a39e | 7654 | else |
14f9c5c9 AS |
7655 | return tail + 5; |
7656 | } | |
7657 | else if (code == TYPE_CODE_RANGE && TYPE_TARGET_TYPE (type) != type) | |
7658 | return fixed_type_info (TYPE_TARGET_TYPE (type)); | |
7659 | else | |
7660 | return NULL; | |
7661 | } | |
7662 | ||
7663 | /* Returns non-zero iff TYPE represents an Ada fixed-point type. */ | |
7664 | ||
7665 | int | |
ebf56fd3 | 7666 | ada_is_fixed_point_type (struct type *type) |
14f9c5c9 AS |
7667 | { |
7668 | return fixed_type_info (type) != NULL; | |
7669 | } | |
7670 | ||
7671 | /* Assuming that TYPE is the representation of an Ada fixed-point | |
7672 | type, return its delta, or -1 if the type is malformed and the | |
7673 | delta cannot be determined. */ | |
7674 | ||
7675 | DOUBLEST | |
ebf56fd3 | 7676 | ada_delta (struct type *type) |
14f9c5c9 AS |
7677 | { |
7678 | const char *encoding = fixed_type_info (type); | |
7679 | long num, den; | |
7680 | ||
7681 | if (sscanf (encoding, "_%ld_%ld", &num, &den) < 2) | |
7682 | return -1.0; | |
d2e4a39e | 7683 | else |
14f9c5c9 AS |
7684 | return (DOUBLEST) num / (DOUBLEST) den; |
7685 | } | |
7686 | ||
7687 | /* Assuming that ada_is_fixed_point_type (TYPE), return the scaling | |
7688 | factor ('SMALL value) associated with the type. */ | |
7689 | ||
7690 | static DOUBLEST | |
ebf56fd3 | 7691 | scaling_factor (struct type *type) |
14f9c5c9 AS |
7692 | { |
7693 | const char *encoding = fixed_type_info (type); | |
7694 | unsigned long num0, den0, num1, den1; | |
7695 | int n; | |
d2e4a39e | 7696 | |
14f9c5c9 AS |
7697 | n = sscanf (encoding, "_%lu_%lu_%lu_%lu", &num0, &den0, &num1, &den1); |
7698 | ||
7699 | if (n < 2) | |
7700 | return 1.0; | |
7701 | else if (n == 4) | |
7702 | return (DOUBLEST) num1 / (DOUBLEST) den1; | |
d2e4a39e | 7703 | else |
14f9c5c9 AS |
7704 | return (DOUBLEST) num0 / (DOUBLEST) den0; |
7705 | } | |
7706 | ||
7707 | ||
7708 | /* Assuming that X is the representation of a value of fixed-point | |
7709 | type TYPE, return its floating-point equivalent. */ | |
7710 | ||
7711 | DOUBLEST | |
ebf56fd3 | 7712 | ada_fixed_to_float (struct type *type, LONGEST x) |
14f9c5c9 | 7713 | { |
d2e4a39e | 7714 | return (DOUBLEST) x *scaling_factor (type); |
14f9c5c9 AS |
7715 | } |
7716 | ||
7717 | /* The representation of a fixed-point value of type TYPE | |
7718 | corresponding to the value X. */ | |
7719 | ||
7720 | LONGEST | |
ebf56fd3 | 7721 | ada_float_to_fixed (struct type *type, DOUBLEST x) |
14f9c5c9 AS |
7722 | { |
7723 | return (LONGEST) (x / scaling_factor (type) + 0.5); | |
7724 | } | |
7725 | ||
7726 | ||
7727 | /* VAX floating formats */ | |
7728 | ||
7729 | /* Non-zero iff TYPE represents one of the special VAX floating-point | |
7730 | types. */ | |
7731 | int | |
d2e4a39e | 7732 | ada_is_vax_floating_type (struct type *type) |
14f9c5c9 | 7733 | { |
d2e4a39e | 7734 | int name_len = |
14f9c5c9 | 7735 | (ada_type_name (type) == NULL) ? 0 : strlen (ada_type_name (type)); |
d2e4a39e | 7736 | return |
14f9c5c9 | 7737 | name_len > 6 |
d2e4a39e | 7738 | && (TYPE_CODE (type) == TYPE_CODE_INT |
14f9c5c9 AS |
7739 | || TYPE_CODE (type) == TYPE_CODE_RANGE) |
7740 | && STREQN (ada_type_name (type) + name_len - 6, "___XF", 5); | |
7741 | } | |
7742 | ||
7743 | /* The type of special VAX floating-point type this is, assuming | |
7744 | ada_is_vax_floating_point */ | |
7745 | int | |
d2e4a39e | 7746 | ada_vax_float_type_suffix (struct type *type) |
14f9c5c9 | 7747 | { |
d2e4a39e | 7748 | return ada_type_name (type)[strlen (ada_type_name (type)) - 1]; |
14f9c5c9 AS |
7749 | } |
7750 | ||
7751 | /* A value representing the special debugging function that outputs | |
7752 | VAX floating-point values of the type represented by TYPE. Assumes | |
7753 | ada_is_vax_floating_type (TYPE). */ | |
d2e4a39e AS |
7754 | struct value * |
7755 | ada_vax_float_print_function (struct type *type) | |
7756 | { | |
7757 | switch (ada_vax_float_type_suffix (type)) | |
7758 | { | |
7759 | case 'F': | |
7760 | return get_var_value ("DEBUG_STRING_F", 0); | |
7761 | case 'D': | |
7762 | return get_var_value ("DEBUG_STRING_D", 0); | |
7763 | case 'G': | |
7764 | return get_var_value ("DEBUG_STRING_G", 0); | |
7765 | default: | |
7766 | error ("invalid VAX floating-point type"); | |
7767 | } | |
14f9c5c9 | 7768 | } |
14f9c5c9 | 7769 | \f |
d2e4a39e | 7770 | |
14f9c5c9 AS |
7771 | /* Range types */ |
7772 | ||
7773 | /* Scan STR beginning at position K for a discriminant name, and | |
7774 | return the value of that discriminant field of DVAL in *PX. If | |
7775 | PNEW_K is not null, put the position of the character beyond the | |
7776 | name scanned in *PNEW_K. Return 1 if successful; return 0 and do | |
7777 | not alter *PX and *PNEW_K if unsuccessful. */ | |
7778 | ||
7779 | static int | |
d2e4a39e AS |
7780 | scan_discrim_bound (char *, int k, struct value *dval, LONGEST * px, |
7781 | int *pnew_k) | |
14f9c5c9 AS |
7782 | { |
7783 | static char *bound_buffer = NULL; | |
7784 | static size_t bound_buffer_len = 0; | |
7785 | char *bound; | |
7786 | char *pend; | |
d2e4a39e | 7787 | struct value *bound_val; |
14f9c5c9 AS |
7788 | |
7789 | if (dval == NULL || str == NULL || str[k] == '\0') | |
7790 | return 0; | |
7791 | ||
d2e4a39e | 7792 | pend = strstr (str + k, "__"); |
14f9c5c9 AS |
7793 | if (pend == NULL) |
7794 | { | |
d2e4a39e | 7795 | bound = str + k; |
14f9c5c9 AS |
7796 | k += strlen (bound); |
7797 | } | |
d2e4a39e | 7798 | else |
14f9c5c9 | 7799 | { |
d2e4a39e | 7800 | GROW_VECT (bound_buffer, bound_buffer_len, pend - (str + k) + 1); |
14f9c5c9 | 7801 | bound = bound_buffer; |
d2e4a39e AS |
7802 | strncpy (bound_buffer, str + k, pend - (str + k)); |
7803 | bound[pend - (str + k)] = '\0'; | |
7804 | k = pend - str; | |
14f9c5c9 | 7805 | } |
d2e4a39e AS |
7806 | |
7807 | bound_val = ada_search_struct_field (bound, dval, 0, VALUE_TYPE (dval)); | |
14f9c5c9 AS |
7808 | if (bound_val == NULL) |
7809 | return 0; | |
7810 | ||
7811 | *px = value_as_long (bound_val); | |
7812 | if (pnew_k != NULL) | |
7813 | *pnew_k = k; | |
7814 | return 1; | |
7815 | } | |
7816 | ||
7817 | /* Value of variable named NAME in the current environment. If | |
7818 | no such variable found, then if ERR_MSG is null, returns 0, and | |
7819 | otherwise causes an error with message ERR_MSG. */ | |
d2e4a39e AS |
7820 | static struct value * |
7821 | get_var_value (char *name, char *err_msg) | |
14f9c5c9 | 7822 | { |
d2e4a39e AS |
7823 | struct symbol **syms; |
7824 | struct block **blocks; | |
14f9c5c9 AS |
7825 | int nsyms; |
7826 | ||
d2e4a39e AS |
7827 | nsyms = |
7828 | ada_lookup_symbol_list (name, get_selected_block (NULL), VAR_NAMESPACE, | |
7829 | &syms, &blocks); | |
14f9c5c9 AS |
7830 | |
7831 | if (nsyms != 1) | |
7832 | { | |
7833 | if (err_msg == NULL) | |
7834 | return 0; | |
7835 | else | |
7836 | error ("%s", err_msg); | |
7837 | } | |
7838 | ||
7839 | return value_of_variable (syms[0], blocks[0]); | |
7840 | } | |
d2e4a39e | 7841 | |
14f9c5c9 AS |
7842 | /* Value of integer variable named NAME in the current environment. If |
7843 | no such variable found, then if ERR_MSG is null, returns 0, and sets | |
7844 | *FLAG to 0. If successful, sets *FLAG to 1. */ | |
7845 | LONGEST | |
d2e4a39e | 7846 | get_int_var_value (char *name, char *err_msg, int *flag) |
14f9c5c9 | 7847 | { |
d2e4a39e AS |
7848 | struct value *var_val = get_var_value (name, err_msg); |
7849 | ||
14f9c5c9 AS |
7850 | if (var_val == 0) |
7851 | { | |
7852 | if (flag != NULL) | |
7853 | *flag = 0; | |
7854 | return 0; | |
7855 | } | |
7856 | else | |
7857 | { | |
7858 | if (flag != NULL) | |
7859 | *flag = 1; | |
7860 | return value_as_long (var_val); | |
7861 | } | |
7862 | } | |
d2e4a39e | 7863 | |
14f9c5c9 AS |
7864 | |
7865 | /* Return a range type whose base type is that of the range type named | |
7866 | NAME in the current environment, and whose bounds are calculated | |
7867 | from NAME according to the GNAT range encoding conventions. | |
7868 | Extract discriminant values, if needed, from DVAL. If a new type | |
7869 | must be created, allocate in OBJFILE's space. The bounds | |
7870 | information, in general, is encoded in NAME, the base type given in | |
7871 | the named range type. */ | |
7872 | ||
d2e4a39e | 7873 | static struct type * |
ebf56fd3 | 7874 | to_fixed_range_type (char *name, struct value *dval, struct objfile *objfile) |
14f9c5c9 AS |
7875 | { |
7876 | struct type *raw_type = ada_find_any_type (name); | |
7877 | struct type *base_type; | |
7878 | LONGEST low, high; | |
d2e4a39e | 7879 | char *subtype_info; |
14f9c5c9 AS |
7880 | |
7881 | if (raw_type == NULL) | |
7882 | base_type = builtin_type_int; | |
7883 | else if (TYPE_CODE (raw_type) == TYPE_CODE_RANGE) | |
7884 | base_type = TYPE_TARGET_TYPE (raw_type); | |
7885 | else | |
7886 | base_type = raw_type; | |
7887 | ||
7888 | subtype_info = strstr (name, "___XD"); | |
7889 | if (subtype_info == NULL) | |
7890 | return raw_type; | |
7891 | else | |
7892 | { | |
7893 | static char *name_buf = NULL; | |
7894 | static size_t name_len = 0; | |
7895 | int prefix_len = subtype_info - name; | |
7896 | LONGEST L, U; | |
7897 | struct type *type; | |
7898 | char *bounds_str; | |
7899 | int n; | |
7900 | ||
7901 | GROW_VECT (name_buf, name_len, prefix_len + 5); | |
7902 | strncpy (name_buf, name, prefix_len); | |
7903 | name_buf[prefix_len] = '\0'; | |
7904 | ||
7905 | subtype_info += 5; | |
7906 | bounds_str = strchr (subtype_info, '_'); | |
7907 | n = 1; | |
7908 | ||
d2e4a39e | 7909 | if (*subtype_info == 'L') |
14f9c5c9 | 7910 | { |
d2e4a39e AS |
7911 | if (!ada_scan_number (bounds_str, n, &L, &n) |
7912 | && !scan_discrim_bound (bounds_str, n, dval, &L, &n)) | |
14f9c5c9 AS |
7913 | return raw_type; |
7914 | if (bounds_str[n] == '_') | |
7915 | n += 2; | |
d2e4a39e | 7916 | else if (bounds_str[n] == '.') /* FIXME? SGI Workshop kludge. */ |
14f9c5c9 AS |
7917 | n += 1; |
7918 | subtype_info += 1; | |
7919 | } | |
d2e4a39e | 7920 | else |
14f9c5c9 | 7921 | { |
d2e4a39e | 7922 | strcpy (name_buf + prefix_len, "___L"); |
14f9c5c9 AS |
7923 | L = get_int_var_value (name_buf, "Index bound unknown.", NULL); |
7924 | } | |
7925 | ||
d2e4a39e | 7926 | if (*subtype_info == 'U') |
14f9c5c9 | 7927 | { |
d2e4a39e | 7928 | if (!ada_scan_number (bounds_str, n, &U, &n) |
14f9c5c9 AS |
7929 | && !scan_discrim_bound (bounds_str, n, dval, &U, &n)) |
7930 | return raw_type; | |
7931 | } | |
d2e4a39e | 7932 | else |
14f9c5c9 | 7933 | { |
d2e4a39e | 7934 | strcpy (name_buf + prefix_len, "___U"); |
14f9c5c9 AS |
7935 | U = get_int_var_value (name_buf, "Index bound unknown.", NULL); |
7936 | } | |
7937 | ||
d2e4a39e | 7938 | if (objfile == NULL) |
14f9c5c9 AS |
7939 | objfile = TYPE_OBJFILE (base_type); |
7940 | type = create_range_type (alloc_type (objfile), base_type, L, U); | |
d2e4a39e | 7941 | TYPE_NAME (type) = name; |
14f9c5c9 AS |
7942 | return type; |
7943 | } | |
7944 | } | |
7945 | ||
7946 | /* True iff NAME is the name of a range type. */ | |
7947 | int | |
d2e4a39e | 7948 | ada_is_range_type_name (const char *name) |
14f9c5c9 AS |
7949 | { |
7950 | return (name != NULL && strstr (name, "___XD")); | |
d2e4a39e | 7951 | } |
14f9c5c9 | 7952 | \f |
d2e4a39e | 7953 | |
14f9c5c9 AS |
7954 | /* Modular types */ |
7955 | ||
7956 | /* True iff TYPE is an Ada modular type. */ | |
7957 | int | |
d2e4a39e | 7958 | ada_is_modular_type (struct type *type) |
14f9c5c9 AS |
7959 | { |
7960 | /* FIXME: base_type should be declared in gdbtypes.h, implemented in | |
d2e4a39e AS |
7961 | valarith.c */ |
7962 | struct type *subranged_type; /* = base_type (type); */ | |
14f9c5c9 AS |
7963 | |
7964 | return (subranged_type != NULL && TYPE_CODE (type) == TYPE_CODE_RANGE | |
7965 | && TYPE_CODE (subranged_type) != TYPE_CODE_ENUM | |
7966 | && TYPE_UNSIGNED (subranged_type)); | |
7967 | } | |
7968 | ||
7969 | /* Assuming ada_is_modular_type (TYPE), the modulus of TYPE. */ | |
7970 | LONGEST | |
d2e4a39e | 7971 | ada_modulus (struct type * type) |
14f9c5c9 | 7972 | { |
d2e4a39e | 7973 | return TYPE_HIGH_BOUND (type) + 1; |
14f9c5c9 | 7974 | } |
d2e4a39e | 7975 | \f |
14f9c5c9 AS |
7976 | |
7977 | ||
14f9c5c9 AS |
7978 | /* Operators */ |
7979 | ||
7980 | /* Table mapping opcodes into strings for printing operators | |
7981 | and precedences of the operators. */ | |
7982 | ||
d2e4a39e AS |
7983 | static const struct op_print ada_op_print_tab[] = { |
7984 | {":=", BINOP_ASSIGN, PREC_ASSIGN, 1}, | |
7985 | {"or else", BINOP_LOGICAL_OR, PREC_LOGICAL_OR, 0}, | |
7986 | {"and then", BINOP_LOGICAL_AND, PREC_LOGICAL_AND, 0}, | |
7987 | {"or", BINOP_BITWISE_IOR, PREC_BITWISE_IOR, 0}, | |
7988 | {"xor", BINOP_BITWISE_XOR, PREC_BITWISE_XOR, 0}, | |
7989 | {"and", BINOP_BITWISE_AND, PREC_BITWISE_AND, 0}, | |
7990 | {"=", BINOP_EQUAL, PREC_EQUAL, 0}, | |
7991 | {"/=", BINOP_NOTEQUAL, PREC_EQUAL, 0}, | |
7992 | {"<=", BINOP_LEQ, PREC_ORDER, 0}, | |
7993 | {">=", BINOP_GEQ, PREC_ORDER, 0}, | |
7994 | {">", BINOP_GTR, PREC_ORDER, 0}, | |
7995 | {"<", BINOP_LESS, PREC_ORDER, 0}, | |
7996 | {">>", BINOP_RSH, PREC_SHIFT, 0}, | |
7997 | {"<<", BINOP_LSH, PREC_SHIFT, 0}, | |
7998 | {"+", BINOP_ADD, PREC_ADD, 0}, | |
7999 | {"-", BINOP_SUB, PREC_ADD, 0}, | |
8000 | {"&", BINOP_CONCAT, PREC_ADD, 0}, | |
8001 | {"*", BINOP_MUL, PREC_MUL, 0}, | |
8002 | {"/", BINOP_DIV, PREC_MUL, 0}, | |
8003 | {"rem", BINOP_REM, PREC_MUL, 0}, | |
8004 | {"mod", BINOP_MOD, PREC_MUL, 0}, | |
8005 | {"**", BINOP_EXP, PREC_REPEAT, 0}, | |
8006 | {"@", BINOP_REPEAT, PREC_REPEAT, 0}, | |
8007 | {"-", UNOP_NEG, PREC_PREFIX, 0}, | |
8008 | {"+", UNOP_PLUS, PREC_PREFIX, 0}, | |
8009 | {"not ", UNOP_LOGICAL_NOT, PREC_PREFIX, 0}, | |
8010 | {"not ", UNOP_COMPLEMENT, PREC_PREFIX, 0}, | |
8011 | {"abs ", UNOP_ABS, PREC_PREFIX, 0}, | |
8012 | {".all", UNOP_IND, PREC_SUFFIX, 1}, /* FIXME: postfix .ALL */ | |
8013 | {"'access", UNOP_ADDR, PREC_SUFFIX, 1}, /* FIXME: postfix 'ACCESS */ | |
8014 | {NULL, 0, 0, 0} | |
14f9c5c9 AS |
8015 | }; |
8016 | \f | |
8017 | /* Assorted Types and Interfaces */ | |
8018 | ||
d2e4a39e AS |
8019 | struct type *builtin_type_ada_int; |
8020 | struct type *builtin_type_ada_short; | |
8021 | struct type *builtin_type_ada_long; | |
8022 | struct type *builtin_type_ada_long_long; | |
8023 | struct type *builtin_type_ada_char; | |
8024 | struct type *builtin_type_ada_float; | |
8025 | struct type *builtin_type_ada_double; | |
8026 | struct type *builtin_type_ada_long_double; | |
8027 | struct type *builtin_type_ada_natural; | |
8028 | struct type *builtin_type_ada_positive; | |
8029 | struct type *builtin_type_ada_system_address; | |
8030 | ||
8031 | struct type **const (ada_builtin_types[]) = | |
8032 | { | |
8033 | ||
14f9c5c9 | 8034 | &builtin_type_ada_int, |
d2e4a39e AS |
8035 | &builtin_type_ada_long, |
8036 | &builtin_type_ada_short, | |
8037 | &builtin_type_ada_char, | |
8038 | &builtin_type_ada_float, | |
8039 | &builtin_type_ada_double, | |
8040 | &builtin_type_ada_long_long, | |
8041 | &builtin_type_ada_long_double, | |
8042 | &builtin_type_ada_natural, &builtin_type_ada_positive, | |
8043 | /* The following types are carried over from C for convenience. */ | |
8044 | &builtin_type_int, | |
8045 | &builtin_type_long, | |
8046 | &builtin_type_short, | |
8047 | &builtin_type_char, | |
8048 | &builtin_type_float, | |
8049 | &builtin_type_double, | |
8050 | &builtin_type_long_long, | |
8051 | &builtin_type_void, | |
8052 | &builtin_type_signed_char, | |
8053 | &builtin_type_unsigned_char, | |
8054 | &builtin_type_unsigned_short, | |
8055 | &builtin_type_unsigned_int, | |
8056 | &builtin_type_unsigned_long, | |
8057 | &builtin_type_unsigned_long_long, | |
8058 | &builtin_type_long_double, | |
8059 | &builtin_type_complex, &builtin_type_double_complex, 0}; | |
14f9c5c9 AS |
8060 | |
8061 | /* Not really used, but needed in the ada_language_defn. */ | |
d2e4a39e AS |
8062 | static void |
8063 | emit_char (int c, struct ui_file *stream, int quoter) | |
14f9c5c9 AS |
8064 | { |
8065 | ada_emit_char (c, stream, quoter, 1); | |
8066 | } | |
8067 | ||
8068 | const struct language_defn ada_language_defn = { | |
8069 | "ada", /* Language name */ | |
8070 | /* language_ada, */ | |
8071 | language_unknown, | |
8072 | /* FIXME: language_ada should be defined in defs.h */ | |
8073 | ada_builtin_types, | |
8074 | range_check_off, | |
8075 | type_check_off, | |
8076 | case_sensitive_on, /* Yes, Ada is case-insensitive, but | |
8077 | * that's not quite what this means. */ | |
8078 | ada_parse, | |
8079 | ada_error, | |
8080 | ada_evaluate_subexp, | |
8081 | ada_printchar, /* Print a character constant */ | |
8082 | ada_printstr, /* Function to print string constant */ | |
8083 | emit_char, /* Function to print single char (not used) */ | |
8084 | ada_create_fundamental_type, /* Create fundamental type in this language */ | |
8085 | ada_print_type, /* Print a type using appropriate syntax */ | |
8086 | ada_val_print, /* Print a value using appropriate syntax */ | |
8087 | ada_value_print, /* Print a top-level value */ | |
d2e4a39e | 8088 | {"", "", "", ""}, /* Binary format info */ |
14f9c5c9 | 8089 | #if 0 |
d2e4a39e AS |
8090 | {"8#%lo#", "8#", "o", "#"}, /* Octal format info */ |
8091 | {"%ld", "", "d", ""}, /* Decimal format info */ | |
8092 | {"16#%lx#", "16#", "x", "#"}, /* Hex format info */ | |
14f9c5c9 AS |
8093 | #else |
8094 | /* Copied from c-lang.c. */ | |
d2e4a39e AS |
8095 | {"0%lo", "0", "o", ""}, /* Octal format info */ |
8096 | {"%ld", "", "d", ""}, /* Decimal format info */ | |
8097 | {"0x%lx", "0x", "x", ""}, /* Hex format info */ | |
14f9c5c9 AS |
8098 | #endif |
8099 | ada_op_print_tab, /* expression operators for printing */ | |
8100 | 1, /* c-style arrays (FIXME?) */ | |
8101 | 0, /* String lower bound (FIXME?) */ | |
8102 | &builtin_type_ada_char, | |
8103 | LANG_MAGIC | |
8104 | }; | |
8105 | ||
8106 | void | |
8107 | _initialize_ada_language () | |
8108 | { | |
8109 | builtin_type_ada_int = | |
8110 | init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT, | |
d2e4a39e | 8111 | 0, "integer", (struct objfile *) NULL); |
14f9c5c9 AS |
8112 | builtin_type_ada_long = |
8113 | init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT, | |
d2e4a39e | 8114 | 0, "long_integer", (struct objfile *) NULL); |
14f9c5c9 AS |
8115 | builtin_type_ada_short = |
8116 | init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT, | |
d2e4a39e | 8117 | 0, "short_integer", (struct objfile *) NULL); |
14f9c5c9 AS |
8118 | builtin_type_ada_char = |
8119 | init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
d2e4a39e | 8120 | 0, "character", (struct objfile *) NULL); |
14f9c5c9 AS |
8121 | builtin_type_ada_float = |
8122 | init_type (TYPE_CODE_FLT, TARGET_FLOAT_BIT / TARGET_CHAR_BIT, | |
d2e4a39e | 8123 | 0, "float", (struct objfile *) NULL); |
14f9c5c9 AS |
8124 | builtin_type_ada_double = |
8125 | init_type (TYPE_CODE_FLT, TARGET_DOUBLE_BIT / TARGET_CHAR_BIT, | |
d2e4a39e | 8126 | 0, "long_float", (struct objfile *) NULL); |
14f9c5c9 AS |
8127 | builtin_type_ada_long_long = |
8128 | init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT, | |
d2e4a39e | 8129 | 0, "long_long_integer", (struct objfile *) NULL); |
14f9c5c9 AS |
8130 | builtin_type_ada_long_double = |
8131 | init_type (TYPE_CODE_FLT, TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT, | |
d2e4a39e | 8132 | 0, "long_long_float", (struct objfile *) NULL); |
14f9c5c9 AS |
8133 | builtin_type_ada_natural = |
8134 | init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT, | |
d2e4a39e | 8135 | 0, "natural", (struct objfile *) NULL); |
14f9c5c9 AS |
8136 | builtin_type_ada_positive = |
8137 | init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT, | |
d2e4a39e | 8138 | 0, "positive", (struct objfile *) NULL); |
14f9c5c9 AS |
8139 | |
8140 | ||
d2e4a39e AS |
8141 | builtin_type_ada_system_address = |
8142 | lookup_pointer_type (init_type (TYPE_CODE_VOID, 1, 0, "void", | |
14f9c5c9 AS |
8143 | (struct objfile *) NULL)); |
8144 | TYPE_NAME (builtin_type_ada_system_address) = "system__address"; | |
8145 | ||
8146 | add_language (&ada_language_defn); | |
8147 | ||
d2e4a39e | 8148 | add_show_from_set |
14f9c5c9 | 8149 | (add_set_cmd ("varsize-limit", class_support, var_uinteger, |
d2e4a39e | 8150 | (char *) &varsize_limit, |
14f9c5c9 | 8151 | "Set maximum bytes in dynamic-sized object.", |
d2e4a39e | 8152 | &setlist), &showlist); |
14f9c5c9 AS |
8153 | varsize_limit = 65536; |
8154 | ||
8155 | add_com ("begin", class_breakpoint, begin_command, | |
8156 | "Start the debugged program, stopping at the beginning of the\n\ | |
8157 | main program. You may specify command-line arguments to give it, as for\n\ | |
8158 | the \"run\" command (q.v.)."); | |
8159 | } | |
8160 | ||
8161 | ||
8162 | /* Create a fundamental Ada type using default reasonable for the current | |
8163 | target machine. | |
8164 | ||
8165 | Some object/debugging file formats (DWARF version 1, COFF, etc) do not | |
8166 | define fundamental types such as "int" or "double". Others (stabs or | |
8167 | DWARF version 2, etc) do define fundamental types. For the formats which | |
8168 | don't provide fundamental types, gdb can create such types using this | |
8169 | function. | |
8170 | ||
8171 | FIXME: Some compilers distinguish explicitly signed integral types | |
8172 | (signed short, signed int, signed long) from "regular" integral types | |
8173 | (short, int, long) in the debugging information. There is some dis- | |
8174 | agreement as to how useful this feature is. In particular, gcc does | |
8175 | not support this. Also, only some debugging formats allow the | |
8176 | distinction to be passed on to a debugger. For now, we always just | |
8177 | use "short", "int", or "long" as the type name, for both the implicit | |
8178 | and explicitly signed types. This also makes life easier for the | |
8179 | gdb test suite since we don't have to account for the differences | |
8180 | in output depending upon what the compiler and debugging format | |
8181 | support. We will probably have to re-examine the issue when gdb | |
8182 | starts taking it's fundamental type information directly from the | |
8183 | debugging information supplied by the compiler. fnf@cygnus.com */ | |
8184 | ||
8185 | static struct type * | |
ebf56fd3 | 8186 | ada_create_fundamental_type (struct objfile *objfile, int typeid) |
14f9c5c9 AS |
8187 | { |
8188 | struct type *type = NULL; | |
8189 | ||
8190 | switch (typeid) | |
8191 | { | |
d2e4a39e AS |
8192 | default: |
8193 | /* FIXME: For now, if we are asked to produce a type not in this | |
8194 | language, create the equivalent of a C integer type with the | |
8195 | name "<?type?>". When all the dust settles from the type | |
8196 | reconstruction work, this should probably become an error. */ | |
8197 | type = init_type (TYPE_CODE_INT, | |
8198 | TARGET_INT_BIT / TARGET_CHAR_BIT, | |
8199 | 0, "<?type?>", objfile); | |
8200 | warning ("internal error: no Ada fundamental type %d", typeid); | |
8201 | break; | |
8202 | case FT_VOID: | |
8203 | type = init_type (TYPE_CODE_VOID, | |
8204 | TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
8205 | 0, "void", objfile); | |
8206 | break; | |
8207 | case FT_CHAR: | |
8208 | type = init_type (TYPE_CODE_INT, | |
8209 | TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
8210 | 0, "character", objfile); | |
8211 | break; | |
8212 | case FT_SIGNED_CHAR: | |
8213 | type = init_type (TYPE_CODE_INT, | |
8214 | TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
8215 | 0, "signed char", objfile); | |
8216 | break; | |
8217 | case FT_UNSIGNED_CHAR: | |
8218 | type = init_type (TYPE_CODE_INT, | |
8219 | TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
8220 | TYPE_FLAG_UNSIGNED, "unsigned char", objfile); | |
8221 | break; | |
8222 | case FT_SHORT: | |
8223 | type = init_type (TYPE_CODE_INT, | |
8224 | TARGET_SHORT_BIT / TARGET_CHAR_BIT, | |
8225 | 0, "short_integer", objfile); | |
8226 | break; | |
8227 | case FT_SIGNED_SHORT: | |
8228 | type = init_type (TYPE_CODE_INT, | |
8229 | TARGET_SHORT_BIT / TARGET_CHAR_BIT, | |
8230 | 0, "short_integer", objfile); | |
8231 | break; | |
8232 | case FT_UNSIGNED_SHORT: | |
8233 | type = init_type (TYPE_CODE_INT, | |
8234 | TARGET_SHORT_BIT / TARGET_CHAR_BIT, | |
8235 | TYPE_FLAG_UNSIGNED, "unsigned short", objfile); | |
8236 | break; | |
8237 | case FT_INTEGER: | |
8238 | type = init_type (TYPE_CODE_INT, | |
8239 | TARGET_INT_BIT / TARGET_CHAR_BIT, | |
8240 | 0, "integer", objfile); | |
8241 | break; | |
8242 | case FT_SIGNED_INTEGER: | |
8243 | type = init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT, 0, "integer", objfile); /* FIXME -fnf */ | |
8244 | break; | |
8245 | case FT_UNSIGNED_INTEGER: | |
8246 | type = init_type (TYPE_CODE_INT, | |
8247 | TARGET_INT_BIT / TARGET_CHAR_BIT, | |
8248 | TYPE_FLAG_UNSIGNED, "unsigned int", objfile); | |
8249 | break; | |
8250 | case FT_LONG: | |
8251 | type = init_type (TYPE_CODE_INT, | |
8252 | TARGET_LONG_BIT / TARGET_CHAR_BIT, | |
8253 | 0, "long_integer", objfile); | |
8254 | break; | |
8255 | case FT_SIGNED_LONG: | |
8256 | type = init_type (TYPE_CODE_INT, | |
8257 | TARGET_LONG_BIT / TARGET_CHAR_BIT, | |
8258 | 0, "long_integer", objfile); | |
8259 | break; | |
8260 | case FT_UNSIGNED_LONG: | |
8261 | type = init_type (TYPE_CODE_INT, | |
8262 | TARGET_LONG_BIT / TARGET_CHAR_BIT, | |
8263 | TYPE_FLAG_UNSIGNED, "unsigned long", objfile); | |
8264 | break; | |
8265 | case FT_LONG_LONG: | |
8266 | type = init_type (TYPE_CODE_INT, | |
8267 | TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT, | |
8268 | 0, "long_long_integer", objfile); | |
8269 | break; | |
8270 | case FT_SIGNED_LONG_LONG: | |
8271 | type = init_type (TYPE_CODE_INT, | |
8272 | TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT, | |
8273 | 0, "long_long_integer", objfile); | |
8274 | break; | |
8275 | case FT_UNSIGNED_LONG_LONG: | |
8276 | type = init_type (TYPE_CODE_INT, | |
8277 | TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT, | |
8278 | TYPE_FLAG_UNSIGNED, "unsigned long long", objfile); | |
8279 | break; | |
8280 | case FT_FLOAT: | |
8281 | type = init_type (TYPE_CODE_FLT, | |
8282 | TARGET_FLOAT_BIT / TARGET_CHAR_BIT, | |
8283 | 0, "float", objfile); | |
8284 | break; | |
8285 | case FT_DBL_PREC_FLOAT: | |
8286 | type = init_type (TYPE_CODE_FLT, | |
8287 | TARGET_DOUBLE_BIT / TARGET_CHAR_BIT, | |
8288 | 0, "long_float", objfile); | |
8289 | break; | |
8290 | case FT_EXT_PREC_FLOAT: | |
8291 | type = init_type (TYPE_CODE_FLT, | |
8292 | TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT, | |
8293 | 0, "long_long_float", objfile); | |
8294 | break; | |
8295 | } | |
14f9c5c9 AS |
8296 | return (type); |
8297 | } | |
8298 | ||
d2e4a39e AS |
8299 | void |
8300 | ada_dump_symtab (struct symtab *s) | |
14f9c5c9 AS |
8301 | { |
8302 | int i; | |
8303 | fprintf (stderr, "New symtab: [\n"); | |
d2e4a39e AS |
8304 | fprintf (stderr, " Name: %s/%s;\n", |
8305 | s->dirname ? s->dirname : "?", s->filename ? s->filename : "?"); | |
14f9c5c9 AS |
8306 | fprintf (stderr, " Format: %s;\n", s->debugformat); |
8307 | if (s->linetable != NULL) | |
8308 | { | |
8309 | fprintf (stderr, " Line table (section %d):\n", s->block_line_section); | |
8310 | for (i = 0; i < s->linetable->nitems; i += 1) | |
8311 | { | |
d2e4a39e | 8312 | struct linetable_entry *e = s->linetable->item + i; |
14f9c5c9 AS |
8313 | fprintf (stderr, " %4ld: %8lx\n", (long) e->line, (long) e->pc); |
8314 | } | |
8315 | } | |
8316 | fprintf (stderr, "]\n"); | |
8317 | } |