Commit | Line | Data |
---|---|---|
14f9c5c9 | 1 | /* Ada language support routines for GDB, the GNU debugger. Copyright |
4c4b4cd2 | 2 | 1992, 1993, 1994, 1997, 1998, 1999, 2000, 2003, 2004. |
de5ad195 | 3 | Free Software Foundation, Inc. |
14f9c5c9 AS |
4 | |
5 | This file is part of GDB. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program; if not, write to the Free Software | |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
20 | ||
4c4b4cd2 | 21 | #include "defs.h" |
14f9c5c9 | 22 | #include <stdio.h> |
0c30c098 | 23 | #include "gdb_string.h" |
14f9c5c9 AS |
24 | #include <ctype.h> |
25 | #include <stdarg.h> | |
26 | #include "demangle.h" | |
4c4b4cd2 PH |
27 | #include "gdb_regex.h" |
28 | #include "frame.h" | |
14f9c5c9 AS |
29 | #include "symtab.h" |
30 | #include "gdbtypes.h" | |
31 | #include "gdbcmd.h" | |
32 | #include "expression.h" | |
33 | #include "parser-defs.h" | |
34 | #include "language.h" | |
35 | #include "c-lang.h" | |
36 | #include "inferior.h" | |
37 | #include "symfile.h" | |
38 | #include "objfiles.h" | |
39 | #include "breakpoint.h" | |
40 | #include "gdbcore.h" | |
4c4b4cd2 PH |
41 | #include "hashtab.h" |
42 | #include "gdb_obstack.h" | |
14f9c5c9 | 43 | #include "ada-lang.h" |
4c4b4cd2 PH |
44 | #include "completer.h" |
45 | #include "gdb_stat.h" | |
46 | #ifdef UI_OUT | |
14f9c5c9 | 47 | #include "ui-out.h" |
4c4b4cd2 | 48 | #endif |
fe898f56 | 49 | #include "block.h" |
04714b91 | 50 | #include "infcall.h" |
de4f826b | 51 | #include "dictionary.h" |
14f9c5c9 | 52 | |
4c4b4cd2 PH |
53 | #ifndef ADA_RETAIN_DOTS |
54 | #define ADA_RETAIN_DOTS 0 | |
55 | #endif | |
56 | ||
57 | /* Define whether or not the C operator '/' truncates towards zero for | |
58 | differently signed operands (truncation direction is undefined in C). | |
59 | Copied from valarith.c. */ | |
60 | ||
61 | #ifndef TRUNCATION_TOWARDS_ZERO | |
62 | #define TRUNCATION_TOWARDS_ZERO ((-5 / 2) == -2) | |
63 | #endif | |
64 | ||
65 | /* A structure that contains a vector of strings. | |
66 | The main purpose of this type is to group the vector and its | |
67 | associated parameters in one structure. This makes it easier | |
68 | to handle and pass around. */ | |
14f9c5c9 | 69 | |
4c4b4cd2 PH |
70 | struct string_vector |
71 | { | |
72 | char **array; /* The vector itself. */ | |
73 | int index; /* Index of the next available element in the array. */ | |
74 | size_t size; /* The number of entries allocated in the array. */ | |
75 | }; | |
76 | ||
77 | static struct string_vector xnew_string_vector (int initial_size); | |
78 | static void string_vector_append (struct string_vector *sv, char *str); | |
79 | ||
80 | static const char *ada_unqualified_name (const char *decoded_name); | |
81 | static char *add_angle_brackets (const char *str); | |
82 | static void extract_string (CORE_ADDR addr, char *buf); | |
83 | static char *function_name_from_pc (CORE_ADDR pc); | |
14f9c5c9 | 84 | |
d2e4a39e | 85 | static struct type *ada_create_fundamental_type (struct objfile *, int); |
14f9c5c9 AS |
86 | |
87 | static void modify_general_field (char *, LONGEST, int, int); | |
88 | ||
d2e4a39e | 89 | static struct type *desc_base_type (struct type *); |
14f9c5c9 | 90 | |
d2e4a39e | 91 | static struct type *desc_bounds_type (struct type *); |
14f9c5c9 | 92 | |
d2e4a39e | 93 | static struct value *desc_bounds (struct value *); |
14f9c5c9 | 94 | |
d2e4a39e | 95 | static int fat_pntr_bounds_bitpos (struct type *); |
14f9c5c9 | 96 | |
d2e4a39e | 97 | static int fat_pntr_bounds_bitsize (struct type *); |
14f9c5c9 | 98 | |
d2e4a39e | 99 | static struct type *desc_data_type (struct type *); |
14f9c5c9 | 100 | |
d2e4a39e | 101 | static struct value *desc_data (struct value *); |
14f9c5c9 | 102 | |
d2e4a39e | 103 | static int fat_pntr_data_bitpos (struct type *); |
14f9c5c9 | 104 | |
d2e4a39e | 105 | static int fat_pntr_data_bitsize (struct type *); |
14f9c5c9 | 106 | |
d2e4a39e | 107 | static struct value *desc_one_bound (struct value *, int, int); |
14f9c5c9 | 108 | |
d2e4a39e | 109 | static int desc_bound_bitpos (struct type *, int, int); |
14f9c5c9 | 110 | |
d2e4a39e | 111 | static int desc_bound_bitsize (struct type *, int, int); |
14f9c5c9 | 112 | |
d2e4a39e | 113 | static struct type *desc_index_type (struct type *, int); |
14f9c5c9 | 114 | |
d2e4a39e | 115 | static int desc_arity (struct type *); |
14f9c5c9 | 116 | |
d2e4a39e | 117 | static int ada_type_match (struct type *, struct type *, int); |
14f9c5c9 | 118 | |
d2e4a39e | 119 | static int ada_args_match (struct symbol *, struct value **, int); |
14f9c5c9 | 120 | |
4c4b4cd2 | 121 | static struct value *ensure_lval (struct value *, CORE_ADDR *); |
14f9c5c9 | 122 | |
d2e4a39e | 123 | static struct value *convert_actual (struct value *, struct type *, |
4c4b4cd2 | 124 | CORE_ADDR *); |
14f9c5c9 | 125 | |
d2e4a39e | 126 | static struct value *make_array_descriptor (struct type *, struct value *, |
4c4b4cd2 | 127 | CORE_ADDR *); |
14f9c5c9 | 128 | |
4c4b4cd2 PH |
129 | static void ada_add_block_symbols (struct obstack *, |
130 | struct block *, const char *, | |
131 | domain_enum, struct objfile *, | |
132 | struct symtab *, int); | |
14f9c5c9 | 133 | |
4c4b4cd2 | 134 | static int is_nonfunction (struct ada_symbol_info *, int); |
14f9c5c9 | 135 | |
4c4b4cd2 PH |
136 | static void add_defn_to_vec (struct obstack *, struct symbol *, struct block *, |
137 | struct symtab *); | |
14f9c5c9 | 138 | |
4c4b4cd2 PH |
139 | static int num_defns_collected (struct obstack *); |
140 | ||
141 | static struct ada_symbol_info *defns_collected (struct obstack *, int); | |
14f9c5c9 | 142 | |
d2e4a39e AS |
143 | static struct partial_symbol *ada_lookup_partial_symbol (struct partial_symtab |
144 | *, const char *, int, | |
176620f1 | 145 | domain_enum, int); |
14f9c5c9 | 146 | |
d2e4a39e | 147 | static struct symtab *symtab_for_sym (struct symbol *); |
14f9c5c9 | 148 | |
4c4b4cd2 PH |
149 | static struct value *resolve_subexp (struct expression **, int *, int, |
150 | struct type *); | |
14f9c5c9 | 151 | |
d2e4a39e | 152 | static void replace_operator_with_call (struct expression **, int, int, int, |
4c4b4cd2 | 153 | struct symbol *, struct block *); |
14f9c5c9 | 154 | |
d2e4a39e | 155 | static int possible_user_operator_p (enum exp_opcode, struct value **); |
14f9c5c9 | 156 | |
4c4b4cd2 PH |
157 | static char *ada_op_name (enum exp_opcode); |
158 | ||
159 | static const char *ada_decoded_op_name (enum exp_opcode); | |
14f9c5c9 | 160 | |
d2e4a39e | 161 | static int numeric_type_p (struct type *); |
14f9c5c9 | 162 | |
d2e4a39e | 163 | static int integer_type_p (struct type *); |
14f9c5c9 | 164 | |
d2e4a39e | 165 | static int scalar_type_p (struct type *); |
14f9c5c9 | 166 | |
d2e4a39e | 167 | static int discrete_type_p (struct type *); |
14f9c5c9 | 168 | |
4c4b4cd2 PH |
169 | static struct type *ada_lookup_struct_elt_type (struct type *, char *, |
170 | int, int, int *); | |
171 | ||
d2e4a39e | 172 | static char *extended_canonical_line_spec (struct symtab_and_line, |
4c4b4cd2 | 173 | const char *); |
14f9c5c9 | 174 | |
d2e4a39e | 175 | static struct value *evaluate_subexp (struct type *, struct expression *, |
4c4b4cd2 | 176 | int *, enum noside); |
14f9c5c9 | 177 | |
d2e4a39e | 178 | static struct value *evaluate_subexp_type (struct expression *, int *); |
14f9c5c9 | 179 | |
d2e4a39e | 180 | static struct type *ada_create_fundamental_type (struct objfile *, int); |
14f9c5c9 | 181 | |
d2e4a39e | 182 | static int is_dynamic_field (struct type *, int); |
14f9c5c9 | 183 | |
d2e4a39e | 184 | static struct type *to_fixed_variant_branch_type (struct type *, char *, |
4c4b4cd2 PH |
185 | CORE_ADDR, struct value *); |
186 | ||
187 | static struct type *to_fixed_array_type (struct type *, struct value *, int); | |
14f9c5c9 | 188 | |
d2e4a39e | 189 | static struct type *to_fixed_range_type (char *, struct value *, |
4c4b4cd2 | 190 | struct objfile *); |
14f9c5c9 | 191 | |
d2e4a39e | 192 | static struct type *to_static_fixed_type (struct type *); |
14f9c5c9 | 193 | |
d2e4a39e | 194 | static struct value *unwrap_value (struct value *); |
14f9c5c9 | 195 | |
d2e4a39e | 196 | static struct type *packed_array_type (struct type *, long *); |
14f9c5c9 | 197 | |
d2e4a39e | 198 | static struct type *decode_packed_array_type (struct type *); |
14f9c5c9 | 199 | |
d2e4a39e | 200 | static struct value *decode_packed_array (struct value *); |
14f9c5c9 | 201 | |
d2e4a39e | 202 | static struct value *value_subscript_packed (struct value *, int, |
4c4b4cd2 | 203 | struct value **); |
14f9c5c9 | 204 | |
4c4b4cd2 PH |
205 | static struct value *coerce_unspec_val_to_type (struct value *, |
206 | struct type *); | |
14f9c5c9 | 207 | |
d2e4a39e | 208 | static struct value *get_var_value (char *, char *); |
14f9c5c9 | 209 | |
d2e4a39e | 210 | static int lesseq_defined_than (struct symbol *, struct symbol *); |
14f9c5c9 | 211 | |
d2e4a39e | 212 | static int equiv_types (struct type *, struct type *); |
14f9c5c9 | 213 | |
d2e4a39e | 214 | static int is_name_suffix (const char *); |
14f9c5c9 | 215 | |
d2e4a39e | 216 | static int wild_match (const char *, int, const char *); |
14f9c5c9 | 217 | |
4c4b4cd2 PH |
218 | static struct symtabs_and_lines |
219 | find_sal_from_funcs_and_line (const char *, int, | |
220 | struct ada_symbol_info *, int); | |
14f9c5c9 | 221 | |
4c4b4cd2 PH |
222 | static int find_line_in_linetable (struct linetable *, int, |
223 | struct ada_symbol_info *, | |
d2e4a39e | 224 | int, int *); |
14f9c5c9 | 225 | |
d2e4a39e | 226 | static int find_next_line_in_linetable (struct linetable *, int, int, int); |
14f9c5c9 | 227 | |
d2e4a39e | 228 | static void read_all_symtabs (const char *); |
14f9c5c9 | 229 | |
d2e4a39e | 230 | static int is_plausible_func_for_line (struct symbol *, int); |
14f9c5c9 | 231 | |
d2e4a39e | 232 | static struct value *ada_coerce_ref (struct value *); |
14f9c5c9 | 233 | |
4c4b4cd2 PH |
234 | static LONGEST pos_atr (struct value *); |
235 | ||
d2e4a39e | 236 | static struct value *value_pos_atr (struct value *); |
14f9c5c9 | 237 | |
d2e4a39e | 238 | static struct value *value_val_atr (struct type *, struct value *); |
14f9c5c9 | 239 | |
4c4b4cd2 PH |
240 | static struct symbol *standard_lookup (const char *, const struct block *, |
241 | domain_enum); | |
14f9c5c9 | 242 | |
4c4b4cd2 PH |
243 | extern void symtab_symbol_info (char *regexp, domain_enum kind, |
244 | int from_tty); | |
245 | ||
246 | static struct value *ada_search_struct_field (char *, struct value *, int, | |
247 | struct type *); | |
248 | ||
249 | static struct value *ada_value_primitive_field (struct value *, int, int, | |
250 | struct type *); | |
251 | ||
252 | static int find_struct_field (char *, struct type *, int, | |
253 | struct type **, int *, int *, int *); | |
254 | ||
255 | static struct value *ada_to_fixed_value_create (struct type *, CORE_ADDR, | |
256 | struct value *); | |
257 | ||
258 | static struct value *ada_to_fixed_value (struct value *); | |
14f9c5c9 | 259 | |
4c4b4cd2 | 260 | static void adjust_pc_past_prologue (CORE_ADDR *); |
d2e4a39e | 261 | |
4c4b4cd2 PH |
262 | static int ada_resolve_function (struct ada_symbol_info *, int, |
263 | struct value **, int, const char *, | |
264 | struct type *); | |
265 | ||
266 | static struct value *ada_coerce_to_simple_array (struct value *); | |
267 | ||
268 | static int ada_is_direct_array_type (struct type *); | |
269 | ||
270 | static void error_breakpoint_runtime_sym_not_found (const char *err_desc); | |
271 | ||
272 | static int is_runtime_sym_defined (const char *name, int allow_tramp); | |
273 | ||
274 | \f | |
275 | ||
276 | /* Maximum-sized dynamic type. */ | |
14f9c5c9 AS |
277 | static unsigned int varsize_limit; |
278 | ||
4c4b4cd2 PH |
279 | /* FIXME: brobecker/2003-09-17: No longer a const because it is |
280 | returned by a function that does not return a const char *. */ | |
281 | static char *ada_completer_word_break_characters = | |
282 | #ifdef VMS | |
283 | " \t\n!@#%^&*()+=|~`}{[]\";:?/,-"; | |
284 | #else | |
14f9c5c9 | 285 | " \t\n!@#$%^&*()+=|~`}{[]\";:?/,-"; |
4c4b4cd2 | 286 | #endif |
14f9c5c9 | 287 | |
4c4b4cd2 PH |
288 | /* The name of the symbol to use to get the name of the main subprogram. */ |
289 | static const char ADA_MAIN_PROGRAM_SYMBOL_NAME[] | |
290 | = "__gnat_ada_main_program_name"; | |
14f9c5c9 | 291 | |
4c4b4cd2 PH |
292 | /* The name of the runtime function called when an exception is raised. */ |
293 | static const char raise_sym_name[] = "__gnat_raise_nodefer_with_msg"; | |
14f9c5c9 | 294 | |
4c4b4cd2 PH |
295 | /* The name of the runtime function called when an unhandled exception |
296 | is raised. */ | |
297 | static const char raise_unhandled_sym_name[] = "__gnat_unhandled_exception"; | |
298 | ||
299 | /* The name of the runtime function called when an assert failure is | |
300 | raised. */ | |
301 | static const char raise_assert_sym_name[] = | |
302 | "system__assertions__raise_assert_failure"; | |
303 | ||
304 | /* When GDB stops on an unhandled exception, GDB will go up the stack until | |
305 | if finds a frame corresponding to this function, in order to extract the | |
306 | name of the exception that has been raised from one of the parameters. */ | |
307 | static const char process_raise_exception_name[] = | |
308 | "ada__exceptions__process_raise_exception"; | |
309 | ||
310 | /* A string that reflects the longest exception expression rewrite, | |
311 | aside from the exception name. */ | |
312 | static const char longest_exception_template[] = | |
313 | "'__gnat_raise_nodefer_with_msg' if long_integer(e) = long_integer(&)"; | |
314 | ||
315 | /* Limit on the number of warnings to raise per expression evaluation. */ | |
316 | static int warning_limit = 2; | |
317 | ||
318 | /* Number of warning messages issued; reset to 0 by cleanups after | |
319 | expression evaluation. */ | |
320 | static int warnings_issued = 0; | |
321 | ||
322 | static const char *known_runtime_file_name_patterns[] = { | |
323 | ADA_KNOWN_RUNTIME_FILE_NAME_PATTERNS NULL | |
324 | }; | |
325 | ||
326 | static const char *known_auxiliary_function_name_patterns[] = { | |
327 | ADA_KNOWN_AUXILIARY_FUNCTION_NAME_PATTERNS NULL | |
328 | }; | |
329 | ||
330 | /* Space for allocating results of ada_lookup_symbol_list. */ | |
331 | static struct obstack symbol_list_obstack; | |
332 | ||
333 | /* Utilities */ | |
334 | ||
335 | /* Create a new empty string_vector struct with an initial size of | |
336 | INITIAL_SIZE. */ | |
337 | ||
338 | static struct string_vector | |
339 | xnew_string_vector (int initial_size) | |
340 | { | |
341 | struct string_vector result; | |
342 | ||
343 | result.array = (char **) xmalloc ((initial_size + 1) * sizeof (char *)); | |
344 | result.index = 0; | |
345 | result.size = initial_size; | |
346 | ||
347 | return result; | |
348 | } | |
349 | ||
350 | /* Add STR at the end of the given string vector SV. If SV is already | |
351 | full, its size is automatically increased (doubled). */ | |
352 | ||
353 | static void | |
354 | string_vector_append (struct string_vector *sv, char *str) | |
355 | { | |
356 | if (sv->index >= sv->size) | |
357 | GROW_VECT (sv->array, sv->size, sv->size * 2); | |
358 | ||
359 | sv->array[sv->index] = str; | |
360 | sv->index++; | |
361 | } | |
362 | ||
363 | /* Given DECODED_NAME a string holding a symbol name in its | |
364 | decoded form (ie using the Ada dotted notation), returns | |
365 | its unqualified name. */ | |
366 | ||
367 | static const char * | |
368 | ada_unqualified_name (const char *decoded_name) | |
369 | { | |
370 | const char *result = strrchr (decoded_name, '.'); | |
371 | ||
372 | if (result != NULL) | |
373 | result++; /* Skip the dot... */ | |
374 | else | |
375 | result = decoded_name; | |
376 | ||
377 | return result; | |
378 | } | |
379 | ||
380 | /* Return a string starting with '<', followed by STR, and '>'. | |
381 | The result is good until the next call. */ | |
382 | ||
383 | static char * | |
384 | add_angle_brackets (const char *str) | |
385 | { | |
386 | static char *result = NULL; | |
387 | ||
388 | xfree (result); | |
389 | result = (char *) xmalloc ((strlen (str) + 3) * sizeof (char)); | |
390 | ||
391 | sprintf (result, "<%s>", str); | |
392 | return result; | |
393 | } | |
394 | ||
395 | static char * | |
396 | ada_get_gdb_completer_word_break_characters (void) | |
397 | { | |
398 | return ada_completer_word_break_characters; | |
399 | } | |
400 | ||
401 | /* Read the string located at ADDR from the inferior and store the | |
402 | result into BUF. */ | |
403 | ||
404 | static void | |
14f9c5c9 AS |
405 | extract_string (CORE_ADDR addr, char *buf) |
406 | { | |
d2e4a39e | 407 | int char_index = 0; |
14f9c5c9 | 408 | |
4c4b4cd2 PH |
409 | /* Loop, reading one byte at a time, until we reach the '\000' |
410 | end-of-string marker. */ | |
d2e4a39e AS |
411 | do |
412 | { | |
413 | target_read_memory (addr + char_index * sizeof (char), | |
4c4b4cd2 | 414 | buf + char_index * sizeof (char), sizeof (char)); |
d2e4a39e AS |
415 | char_index++; |
416 | } | |
417 | while (buf[char_index - 1] != '\000'); | |
14f9c5c9 AS |
418 | } |
419 | ||
4c4b4cd2 PH |
420 | /* Return the name of the function owning the instruction located at PC. |
421 | Return NULL if no such function could be found. */ | |
422 | ||
423 | static char * | |
424 | function_name_from_pc (CORE_ADDR pc) | |
425 | { | |
426 | char *func_name; | |
427 | ||
428 | if (!find_pc_partial_function (pc, &func_name, NULL, NULL)) | |
429 | return NULL; | |
430 | ||
431 | return func_name; | |
432 | } | |
433 | ||
14f9c5c9 AS |
434 | /* Assuming *OLD_VECT points to an array of *SIZE objects of size |
435 | ELEMENT_SIZE, grow it to contain at least MIN_SIZE objects, | |
4c4b4cd2 | 436 | updating *OLD_VECT and *SIZE as necessary. */ |
14f9c5c9 AS |
437 | |
438 | void | |
d2e4a39e | 439 | grow_vect (void **old_vect, size_t * size, size_t min_size, int element_size) |
14f9c5c9 | 440 | { |
d2e4a39e AS |
441 | if (*size < min_size) |
442 | { | |
443 | *size *= 2; | |
444 | if (*size < min_size) | |
4c4b4cd2 | 445 | *size = min_size; |
d2e4a39e AS |
446 | *old_vect = xrealloc (*old_vect, *size * element_size); |
447 | } | |
14f9c5c9 AS |
448 | } |
449 | ||
450 | /* True (non-zero) iff TARGET matches FIELD_NAME up to any trailing | |
4c4b4cd2 | 451 | suffix of FIELD_NAME beginning "___". */ |
14f9c5c9 AS |
452 | |
453 | static int | |
ebf56fd3 | 454 | field_name_match (const char *field_name, const char *target) |
14f9c5c9 AS |
455 | { |
456 | int len = strlen (target); | |
d2e4a39e | 457 | return |
4c4b4cd2 PH |
458 | (strncmp (field_name, target, len) == 0 |
459 | && (field_name[len] == '\0' | |
460 | || (strncmp (field_name + len, "___", 3) == 0 | |
461 | && strcmp (field_name + strlen (field_name) - 6, "___XVN") != 0))); | |
14f9c5c9 AS |
462 | } |
463 | ||
464 | ||
4c4b4cd2 PH |
465 | /* Assuming TYPE is a TYPE_CODE_STRUCT, find the field whose name matches |
466 | FIELD_NAME, and return its index. This function also handles fields | |
467 | whose name have ___ suffixes because the compiler sometimes alters | |
468 | their name by adding such a suffix to represent fields with certain | |
469 | constraints. If the field could not be found, return a negative | |
470 | number if MAYBE_MISSING is set. Otherwise raise an error. */ | |
471 | ||
472 | int | |
473 | ada_get_field_index (const struct type *type, const char *field_name, | |
474 | int maybe_missing) | |
475 | { | |
476 | int fieldno; | |
477 | for (fieldno = 0; fieldno < TYPE_NFIELDS (type); fieldno++) | |
478 | if (field_name_match (TYPE_FIELD_NAME (type, fieldno), field_name)) | |
479 | return fieldno; | |
480 | ||
481 | if (!maybe_missing) | |
482 | error ("Unable to find field %s in struct %s. Aborting", | |
483 | field_name, TYPE_NAME (type)); | |
484 | ||
485 | return -1; | |
486 | } | |
487 | ||
488 | /* The length of the prefix of NAME prior to any "___" suffix. */ | |
14f9c5c9 AS |
489 | |
490 | int | |
d2e4a39e | 491 | ada_name_prefix_len (const char *name) |
14f9c5c9 AS |
492 | { |
493 | if (name == NULL) | |
494 | return 0; | |
d2e4a39e | 495 | else |
14f9c5c9 | 496 | { |
d2e4a39e | 497 | const char *p = strstr (name, "___"); |
14f9c5c9 | 498 | if (p == NULL) |
4c4b4cd2 | 499 | return strlen (name); |
14f9c5c9 | 500 | else |
4c4b4cd2 | 501 | return p - name; |
14f9c5c9 AS |
502 | } |
503 | } | |
504 | ||
4c4b4cd2 PH |
505 | /* Return non-zero if SUFFIX is a suffix of STR. |
506 | Return zero if STR is null. */ | |
507 | ||
14f9c5c9 | 508 | static int |
d2e4a39e | 509 | is_suffix (const char *str, const char *suffix) |
14f9c5c9 AS |
510 | { |
511 | int len1, len2; | |
512 | if (str == NULL) | |
513 | return 0; | |
514 | len1 = strlen (str); | |
515 | len2 = strlen (suffix); | |
4c4b4cd2 | 516 | return (len1 >= len2 && strcmp (str + len1 - len2, suffix) == 0); |
14f9c5c9 AS |
517 | } |
518 | ||
519 | /* Create a value of type TYPE whose contents come from VALADDR, if it | |
4c4b4cd2 PH |
520 | is non-null, and whose memory address (in the inferior) is |
521 | ADDRESS. */ | |
522 | ||
d2e4a39e AS |
523 | struct value * |
524 | value_from_contents_and_address (struct type *type, char *valaddr, | |
4c4b4cd2 | 525 | CORE_ADDR address) |
14f9c5c9 | 526 | { |
d2e4a39e AS |
527 | struct value *v = allocate_value (type); |
528 | if (valaddr == NULL) | |
14f9c5c9 AS |
529 | VALUE_LAZY (v) = 1; |
530 | else | |
531 | memcpy (VALUE_CONTENTS_RAW (v), valaddr, TYPE_LENGTH (type)); | |
532 | VALUE_ADDRESS (v) = address; | |
533 | if (address != 0) | |
534 | VALUE_LVAL (v) = lval_memory; | |
535 | return v; | |
536 | } | |
537 | ||
4c4b4cd2 PH |
538 | /* The contents of value VAL, treated as a value of type TYPE. The |
539 | result is an lval in memory if VAL is. */ | |
14f9c5c9 | 540 | |
d2e4a39e | 541 | static struct value * |
4c4b4cd2 | 542 | coerce_unspec_val_to_type (struct value *val, struct type *type) |
14f9c5c9 AS |
543 | { |
544 | CHECK_TYPEDEF (type); | |
4c4b4cd2 PH |
545 | if (VALUE_TYPE (val) == type) |
546 | return val; | |
d2e4a39e | 547 | else |
14f9c5c9 | 548 | { |
4c4b4cd2 PH |
549 | struct value *result; |
550 | ||
551 | /* Make sure that the object size is not unreasonable before | |
552 | trying to allocate some memory for it. */ | |
553 | if (TYPE_LENGTH (type) > varsize_limit) | |
554 | error ("object size is larger than varsize-limit"); | |
555 | ||
556 | result = allocate_value (type); | |
557 | VALUE_LVAL (result) = VALUE_LVAL (val); | |
558 | VALUE_BITSIZE (result) = VALUE_BITSIZE (val); | |
559 | VALUE_BITPOS (result) = VALUE_BITPOS (val); | |
560 | VALUE_ADDRESS (result) = VALUE_ADDRESS (val) + VALUE_OFFSET (val); | |
561 | if (VALUE_LAZY (val) || | |
562 | TYPE_LENGTH (type) > TYPE_LENGTH (VALUE_TYPE (val))) | |
563 | VALUE_LAZY (result) = 1; | |
d2e4a39e | 564 | else |
4c4b4cd2 PH |
565 | memcpy (VALUE_CONTENTS_RAW (result), VALUE_CONTENTS (val), |
566 | TYPE_LENGTH (type)); | |
14f9c5c9 AS |
567 | return result; |
568 | } | |
569 | } | |
570 | ||
d2e4a39e AS |
571 | static char * |
572 | cond_offset_host (char *valaddr, long offset) | |
14f9c5c9 AS |
573 | { |
574 | if (valaddr == NULL) | |
575 | return NULL; | |
576 | else | |
577 | return valaddr + offset; | |
578 | } | |
579 | ||
580 | static CORE_ADDR | |
ebf56fd3 | 581 | cond_offset_target (CORE_ADDR address, long offset) |
14f9c5c9 AS |
582 | { |
583 | if (address == 0) | |
584 | return 0; | |
d2e4a39e | 585 | else |
14f9c5c9 AS |
586 | return address + offset; |
587 | } | |
588 | ||
4c4b4cd2 PH |
589 | /* Issue a warning (as for the definition of warning in utils.c, but |
590 | with exactly one argument rather than ...), unless the limit on the | |
591 | number of warnings has passed during the evaluation of the current | |
592 | expression. */ | |
14f9c5c9 | 593 | static void |
4c4b4cd2 | 594 | lim_warning (const char *format, long arg) |
14f9c5c9 | 595 | { |
4c4b4cd2 PH |
596 | warnings_issued += 1; |
597 | if (warnings_issued <= warning_limit) | |
598 | warning (format, arg); | |
599 | } | |
600 | ||
601 | static const char * | |
602 | ada_translate_error_message (const char *string) | |
603 | { | |
604 | if (strcmp (string, "Invalid cast.") == 0) | |
605 | return "Invalid type conversion."; | |
606 | else | |
607 | return string; | |
608 | } | |
609 | ||
610 | static LONGEST | |
611 | MAX_OF_SIZE (int size) | |
612 | { | |
613 | LONGEST top_bit = (LONGEST) 1 << (size*8-2); | |
614 | return top_bit | (top_bit-1); | |
615 | } | |
616 | ||
617 | static LONGEST | |
618 | MIN_OF_SIZE (int size) | |
619 | { | |
620 | return - MAX_OF_SIZE (size) - 1; | |
621 | } | |
622 | ||
623 | static ULONGEST | |
624 | UMAX_OF_SIZE (int size) | |
625 | { | |
626 | ULONGEST top_bit = (ULONGEST) 1 << (size*8-1); | |
627 | return top_bit | (top_bit-1); | |
628 | } | |
629 | ||
630 | static ULONGEST | |
631 | UMIN_OF_SIZE (int size) | |
632 | { | |
633 | return 0; | |
634 | } | |
635 | ||
636 | /* The largest value in the domain of TYPE, a discrete type, as an integer. */ | |
637 | static struct value * | |
638 | discrete_type_high_bound (struct type *type) | |
639 | { | |
640 | switch (TYPE_CODE (type)) | |
641 | { | |
642 | case TYPE_CODE_RANGE: | |
643 | return value_from_longest (TYPE_TARGET_TYPE (type), | |
644 | TYPE_HIGH_BOUND (type)); | |
645 | case TYPE_CODE_ENUM: | |
646 | return | |
647 | value_from_longest (type, | |
648 | TYPE_FIELD_BITPOS (type, TYPE_NFIELDS (type)-1)); | |
649 | case TYPE_CODE_INT: | |
650 | return value_from_longest (type, MAX_OF_TYPE (type)); | |
651 | default: | |
652 | error ("Unexpected type in discrete_type_high_bound."); | |
653 | } | |
654 | } | |
655 | ||
656 | /* The largest value in the domain of TYPE, a discrete type, as an integer. */ | |
657 | static struct value * | |
658 | discrete_type_low_bound (struct type *type) | |
659 | { | |
660 | switch (TYPE_CODE (type)) | |
661 | { | |
662 | case TYPE_CODE_RANGE: | |
663 | return value_from_longest (TYPE_TARGET_TYPE (type), | |
664 | TYPE_LOW_BOUND (type)); | |
665 | case TYPE_CODE_ENUM: | |
666 | return value_from_longest (type, TYPE_FIELD_BITPOS (type, 0)); | |
667 | case TYPE_CODE_INT: | |
668 | return value_from_longest (type, MIN_OF_TYPE (type)); | |
669 | default: | |
670 | error ("Unexpected type in discrete_type_low_bound."); | |
671 | } | |
672 | } | |
673 | ||
674 | /* The identity on non-range types. For range types, the underlying | |
675 | non-range scalar type. */ | |
676 | ||
677 | static struct type * | |
678 | base_type (struct type *type) | |
679 | { | |
680 | while (type != NULL && TYPE_CODE (type) == TYPE_CODE_RANGE) | |
681 | { | |
682 | if (type == TYPE_TARGET_TYPE (type) | |
683 | || TYPE_TARGET_TYPE (type) == NULL) | |
684 | return type; | |
685 | type = TYPE_TARGET_TYPE (type); | |
686 | } | |
687 | return type; | |
14f9c5c9 | 688 | } |
d2e4a39e | 689 | |
4c4b4cd2 PH |
690 | \f |
691 | /* Language Selection */ | |
14f9c5c9 AS |
692 | |
693 | /* If the main program is in Ada, return language_ada, otherwise return LANG | |
694 | (the main program is in Ada iif the adainit symbol is found). | |
695 | ||
4c4b4cd2 | 696 | MAIN_PST is not used. */ |
d2e4a39e | 697 | |
14f9c5c9 | 698 | enum language |
d2e4a39e | 699 | ada_update_initial_language (enum language lang, |
4c4b4cd2 | 700 | struct partial_symtab *main_pst) |
14f9c5c9 | 701 | { |
d2e4a39e | 702 | if (lookup_minimal_symbol ("adainit", (const char *) NULL, |
4c4b4cd2 PH |
703 | (struct objfile *) NULL) != NULL) |
704 | return language_ada; | |
14f9c5c9 AS |
705 | |
706 | return lang; | |
707 | } | |
14f9c5c9 | 708 | \f |
4c4b4cd2 | 709 | /* Symbols */ |
d2e4a39e | 710 | |
4c4b4cd2 PH |
711 | /* Table of Ada operators and their GNAT-encoded names. Last entry is pair |
712 | of NULLs. */ | |
14f9c5c9 | 713 | |
d2e4a39e AS |
714 | const struct ada_opname_map ada_opname_table[] = { |
715 | {"Oadd", "\"+\"", BINOP_ADD}, | |
716 | {"Osubtract", "\"-\"", BINOP_SUB}, | |
717 | {"Omultiply", "\"*\"", BINOP_MUL}, | |
718 | {"Odivide", "\"/\"", BINOP_DIV}, | |
719 | {"Omod", "\"mod\"", BINOP_MOD}, | |
720 | {"Orem", "\"rem\"", BINOP_REM}, | |
721 | {"Oexpon", "\"**\"", BINOP_EXP}, | |
722 | {"Olt", "\"<\"", BINOP_LESS}, | |
723 | {"Ole", "\"<=\"", BINOP_LEQ}, | |
724 | {"Ogt", "\">\"", BINOP_GTR}, | |
725 | {"Oge", "\">=\"", BINOP_GEQ}, | |
726 | {"Oeq", "\"=\"", BINOP_EQUAL}, | |
727 | {"One", "\"/=\"", BINOP_NOTEQUAL}, | |
728 | {"Oand", "\"and\"", BINOP_BITWISE_AND}, | |
729 | {"Oor", "\"or\"", BINOP_BITWISE_IOR}, | |
730 | {"Oxor", "\"xor\"", BINOP_BITWISE_XOR}, | |
731 | {"Oconcat", "\"&\"", BINOP_CONCAT}, | |
732 | {"Oabs", "\"abs\"", UNOP_ABS}, | |
733 | {"Onot", "\"not\"", UNOP_LOGICAL_NOT}, | |
734 | {"Oadd", "\"+\"", UNOP_PLUS}, | |
735 | {"Osubtract", "\"-\"", UNOP_NEG}, | |
736 | {NULL, NULL} | |
14f9c5c9 AS |
737 | }; |
738 | ||
4c4b4cd2 PH |
739 | /* Return non-zero if STR should be suppressed in info listings. */ |
740 | ||
14f9c5c9 | 741 | static int |
d2e4a39e | 742 | is_suppressed_name (const char *str) |
14f9c5c9 | 743 | { |
4c4b4cd2 | 744 | if (strncmp (str, "_ada_", 5) == 0) |
14f9c5c9 AS |
745 | str += 5; |
746 | if (str[0] == '_' || str[0] == '\000') | |
747 | return 1; | |
748 | else | |
749 | { | |
d2e4a39e AS |
750 | const char *p; |
751 | const char *suffix = strstr (str, "___"); | |
14f9c5c9 | 752 | if (suffix != NULL && suffix[3] != 'X') |
4c4b4cd2 | 753 | return 1; |
14f9c5c9 | 754 | if (suffix == NULL) |
4c4b4cd2 | 755 | suffix = str + strlen (str); |
d2e4a39e | 756 | for (p = suffix - 1; p != str; p -= 1) |
4c4b4cd2 PH |
757 | if (isupper (*p)) |
758 | { | |
759 | int i; | |
760 | if (p[0] == 'X' && p[-1] != '_') | |
761 | goto OK; | |
762 | if (*p != 'O') | |
763 | return 1; | |
764 | for (i = 0; ada_opname_table[i].encoded != NULL; i += 1) | |
765 | if (strncmp (ada_opname_table[i].encoded, p, | |
766 | strlen (ada_opname_table[i].encoded)) == 0) | |
767 | goto OK; | |
768 | return 1; | |
769 | OK:; | |
770 | } | |
14f9c5c9 AS |
771 | return 0; |
772 | } | |
773 | } | |
774 | ||
4c4b4cd2 PH |
775 | /* The "encoded" form of DECODED, according to GNAT conventions. |
776 | The result is valid until the next call to ada_encode. */ | |
777 | ||
14f9c5c9 | 778 | char * |
4c4b4cd2 | 779 | ada_encode (const char *decoded) |
14f9c5c9 | 780 | { |
4c4b4cd2 PH |
781 | static char *encoding_buffer = NULL; |
782 | static size_t encoding_buffer_size = 0; | |
d2e4a39e | 783 | const char *p; |
14f9c5c9 | 784 | int k; |
d2e4a39e | 785 | |
4c4b4cd2 | 786 | if (decoded == NULL) |
14f9c5c9 AS |
787 | return NULL; |
788 | ||
4c4b4cd2 PH |
789 | GROW_VECT (encoding_buffer, encoding_buffer_size, |
790 | 2 * strlen (decoded) + 10); | |
14f9c5c9 AS |
791 | |
792 | k = 0; | |
4c4b4cd2 | 793 | for (p = decoded; *p != '\0'; p += 1) |
14f9c5c9 | 794 | { |
4c4b4cd2 PH |
795 | if (!ADA_RETAIN_DOTS && *p == '.') |
796 | { | |
797 | encoding_buffer[k] = encoding_buffer[k + 1] = '_'; | |
798 | k += 2; | |
799 | } | |
14f9c5c9 | 800 | else if (*p == '"') |
4c4b4cd2 PH |
801 | { |
802 | const struct ada_opname_map *mapping; | |
803 | ||
804 | for (mapping = ada_opname_table; | |
805 | mapping->encoded != NULL && | |
806 | strncmp (mapping->decoded, p, | |
807 | strlen (mapping->decoded)) != 0; | |
808 | mapping += 1) | |
809 | ; | |
810 | if (mapping->encoded == NULL) | |
811 | error ("invalid Ada operator name: %s", p); | |
812 | strcpy (encoding_buffer + k, mapping->encoded); | |
813 | k += strlen (mapping->encoded); | |
814 | break; | |
815 | } | |
d2e4a39e | 816 | else |
4c4b4cd2 PH |
817 | { |
818 | encoding_buffer[k] = *p; | |
819 | k += 1; | |
820 | } | |
14f9c5c9 AS |
821 | } |
822 | ||
4c4b4cd2 PH |
823 | encoding_buffer[k] = '\0'; |
824 | return encoding_buffer; | |
14f9c5c9 AS |
825 | } |
826 | ||
827 | /* Return NAME folded to lower case, or, if surrounded by single | |
4c4b4cd2 PH |
828 | quotes, unfolded, but with the quotes stripped away. Result good |
829 | to next call. */ | |
830 | ||
d2e4a39e AS |
831 | char * |
832 | ada_fold_name (const char *name) | |
14f9c5c9 | 833 | { |
d2e4a39e | 834 | static char *fold_buffer = NULL; |
14f9c5c9 AS |
835 | static size_t fold_buffer_size = 0; |
836 | ||
837 | int len = strlen (name); | |
d2e4a39e | 838 | GROW_VECT (fold_buffer, fold_buffer_size, len + 1); |
14f9c5c9 AS |
839 | |
840 | if (name[0] == '\'') | |
841 | { | |
d2e4a39e AS |
842 | strncpy (fold_buffer, name + 1, len - 2); |
843 | fold_buffer[len - 2] = '\000'; | |
14f9c5c9 AS |
844 | } |
845 | else | |
846 | { | |
847 | int i; | |
848 | for (i = 0; i <= len; i += 1) | |
4c4b4cd2 | 849 | fold_buffer[i] = tolower (name[i]); |
14f9c5c9 AS |
850 | } |
851 | ||
852 | return fold_buffer; | |
853 | } | |
854 | ||
4c4b4cd2 PH |
855 | /* decode: |
856 | 0. Discard trailing .{DIGIT}+ or trailing ___{DIGIT}+ | |
857 | These are suffixes introduced by GNAT5 to nested subprogram | |
858 | names, and do not serve any purpose for the debugger. | |
859 | 1. Discard final __{DIGIT}+ or $({DIGIT}+(__{DIGIT}+)*) | |
14f9c5c9 AS |
860 | 2. Convert other instances of embedded "__" to `.'. |
861 | 3. Discard leading _ada_. | |
862 | 4. Convert operator names to the appropriate quoted symbols. | |
4c4b4cd2 | 863 | 5. Remove everything after first ___ if it is followed by |
14f9c5c9 AS |
864 | 'X'. |
865 | 6. Replace TK__ with __, and a trailing B or TKB with nothing. | |
866 | 7. Put symbols that should be suppressed in <...> brackets. | |
867 | 8. Remove trailing X[bn]* suffix (indicating names in package bodies). | |
14f9c5c9 | 868 | |
4c4b4cd2 PH |
869 | The resulting string is valid until the next call of ada_decode. |
870 | If the string is unchanged by demangling, the original string pointer | |
871 | is returned. */ | |
872 | ||
873 | const char * | |
874 | ada_decode (const char *encoded) | |
14f9c5c9 AS |
875 | { |
876 | int i, j; | |
877 | int len0; | |
d2e4a39e | 878 | const char *p; |
4c4b4cd2 | 879 | char *decoded; |
14f9c5c9 | 880 | int at_start_name; |
4c4b4cd2 PH |
881 | static char *decoding_buffer = NULL; |
882 | static size_t decoding_buffer_size = 0; | |
d2e4a39e | 883 | |
4c4b4cd2 PH |
884 | if (strncmp (encoded, "_ada_", 5) == 0) |
885 | encoded += 5; | |
14f9c5c9 | 886 | |
4c4b4cd2 | 887 | if (encoded[0] == '_' || encoded[0] == '<') |
14f9c5c9 AS |
888 | goto Suppress; |
889 | ||
4c4b4cd2 PH |
890 | /* Remove trailing .{DIGIT}+ or ___{DIGIT}+. */ |
891 | len0 = strlen (encoded); | |
892 | if (len0 > 1 && isdigit (encoded[len0 - 1])) | |
893 | { | |
894 | i = len0 - 2; | |
895 | while (i > 0 && isdigit (encoded[i])) | |
896 | i--; | |
897 | if (i >= 0 && encoded[i] == '.') | |
898 | len0 = i; | |
899 | else if (i >= 2 && strncmp (encoded + i - 2, "___", 3) == 0) | |
900 | len0 = i - 2; | |
901 | } | |
902 | ||
903 | /* Remove the ___X.* suffix if present. Do not forget to verify that | |
904 | the suffix is located before the current "end" of ENCODED. We want | |
905 | to avoid re-matching parts of ENCODED that have previously been | |
906 | marked as discarded (by decrementing LEN0). */ | |
907 | p = strstr (encoded, "___"); | |
908 | if (p != NULL && p - encoded < len0 - 3) | |
14f9c5c9 AS |
909 | { |
910 | if (p[3] == 'X') | |
4c4b4cd2 | 911 | len0 = p - encoded; |
14f9c5c9 | 912 | else |
4c4b4cd2 | 913 | goto Suppress; |
14f9c5c9 | 914 | } |
4c4b4cd2 PH |
915 | |
916 | if (len0 > 3 && strncmp (encoded + len0 - 3, "TKB", 3) == 0) | |
14f9c5c9 | 917 | len0 -= 3; |
4c4b4cd2 PH |
918 | |
919 | if (len0 > 1 && strncmp (encoded + len0 - 1, "B", 1) == 0) | |
14f9c5c9 AS |
920 | len0 -= 1; |
921 | ||
4c4b4cd2 PH |
922 | /* Make decoded big enough for possible expansion by operator name. */ |
923 | GROW_VECT (decoding_buffer, decoding_buffer_size, 2 * len0 + 1); | |
924 | decoded = decoding_buffer; | |
14f9c5c9 | 925 | |
4c4b4cd2 | 926 | if (len0 > 1 && isdigit (encoded[len0 - 1])) |
d2e4a39e | 927 | { |
4c4b4cd2 PH |
928 | i = len0 - 2; |
929 | while ((i >= 0 && isdigit (encoded[i])) | |
930 | || (i >= 1 && encoded[i] == '_' && isdigit (encoded[i - 1]))) | |
931 | i -= 1; | |
932 | if (i > 1 && encoded[i] == '_' && encoded[i - 1] == '_') | |
933 | len0 = i - 1; | |
934 | else if (encoded[i] == '$') | |
935 | len0 = i; | |
d2e4a39e | 936 | } |
14f9c5c9 | 937 | |
4c4b4cd2 PH |
938 | for (i = 0, j = 0; i < len0 && !isalpha (encoded[i]); i += 1, j += 1) |
939 | decoded[j] = encoded[i]; | |
14f9c5c9 AS |
940 | |
941 | at_start_name = 1; | |
942 | while (i < len0) | |
943 | { | |
4c4b4cd2 PH |
944 | if (at_start_name && encoded[i] == 'O') |
945 | { | |
946 | int k; | |
947 | for (k = 0; ada_opname_table[k].encoded != NULL; k += 1) | |
948 | { | |
949 | int op_len = strlen (ada_opname_table[k].encoded); | |
950 | if (strncmp (ada_opname_table[k].encoded + 1, encoded + i + 1, | |
951 | op_len - 1) == 0 | |
952 | && !isalnum (encoded[i + op_len])) | |
953 | { | |
954 | strcpy (decoded + j, ada_opname_table[k].decoded); | |
955 | at_start_name = 0; | |
956 | i += op_len; | |
957 | j += strlen (ada_opname_table[k].decoded); | |
958 | break; | |
959 | } | |
960 | } | |
961 | if (ada_opname_table[k].encoded != NULL) | |
962 | continue; | |
963 | } | |
14f9c5c9 AS |
964 | at_start_name = 0; |
965 | ||
4c4b4cd2 PH |
966 | if (i < len0 - 4 && strncmp (encoded + i, "TK__", 4) == 0) |
967 | i += 2; | |
968 | if (encoded[i] == 'X' && i != 0 && isalnum (encoded[i - 1])) | |
969 | { | |
970 | do | |
971 | i += 1; | |
972 | while (i < len0 && (encoded[i] == 'b' || encoded[i] == 'n')); | |
973 | if (i < len0) | |
974 | goto Suppress; | |
975 | } | |
976 | else if (!ADA_RETAIN_DOTS | |
977 | && i < len0 - 2 && encoded[i] == '_' && encoded[i + 1] == '_') | |
978 | { | |
979 | decoded[j] = '.'; | |
980 | at_start_name = 1; | |
981 | i += 2; | |
982 | j += 1; | |
983 | } | |
14f9c5c9 | 984 | else |
4c4b4cd2 PH |
985 | { |
986 | decoded[j] = encoded[i]; | |
987 | i += 1; | |
988 | j += 1; | |
989 | } | |
14f9c5c9 | 990 | } |
4c4b4cd2 | 991 | decoded[j] = '\000'; |
14f9c5c9 | 992 | |
4c4b4cd2 PH |
993 | for (i = 0; decoded[i] != '\0'; i += 1) |
994 | if (isupper (decoded[i]) || decoded[i] == ' ') | |
14f9c5c9 AS |
995 | goto Suppress; |
996 | ||
4c4b4cd2 PH |
997 | if (strcmp (decoded, encoded) == 0) |
998 | return encoded; | |
999 | else | |
1000 | return decoded; | |
14f9c5c9 AS |
1001 | |
1002 | Suppress: | |
4c4b4cd2 PH |
1003 | GROW_VECT (decoding_buffer, decoding_buffer_size, strlen (encoded) + 3); |
1004 | decoded = decoding_buffer; | |
1005 | if (encoded[0] == '<') | |
1006 | strcpy (decoded, encoded); | |
14f9c5c9 | 1007 | else |
4c4b4cd2 PH |
1008 | sprintf (decoded, "<%s>", encoded); |
1009 | return decoded; | |
1010 | ||
1011 | } | |
1012 | ||
1013 | /* Table for keeping permanent unique copies of decoded names. Once | |
1014 | allocated, names in this table are never released. While this is a | |
1015 | storage leak, it should not be significant unless there are massive | |
1016 | changes in the set of decoded names in successive versions of a | |
1017 | symbol table loaded during a single session. */ | |
1018 | static struct htab *decoded_names_store; | |
1019 | ||
1020 | /* Returns the decoded name of GSYMBOL, as for ada_decode, caching it | |
1021 | in the language-specific part of GSYMBOL, if it has not been | |
1022 | previously computed. Tries to save the decoded name in the same | |
1023 | obstack as GSYMBOL, if possible, and otherwise on the heap (so that, | |
1024 | in any case, the decoded symbol has a lifetime at least that of | |
1025 | GSYMBOL). | |
1026 | The GSYMBOL parameter is "mutable" in the C++ sense: logically | |
1027 | const, but nevertheless modified to a semantically equivalent form | |
1028 | when a decoded name is cached in it. | |
1029 | */ | |
1030 | ||
1031 | char *ada_decode_symbol (const struct general_symbol_info *gsymbol) | |
1032 | { | |
1033 | char **resultp = | |
1034 | (char **) &gsymbol->language_specific.cplus_specific.demangled_name; | |
1035 | if (*resultp == NULL) | |
1036 | { | |
1037 | const char *decoded = ada_decode (gsymbol->name); | |
1038 | if (gsymbol->bfd_section != NULL) | |
1039 | { | |
1040 | bfd *obfd = gsymbol->bfd_section->owner; | |
1041 | if (obfd != NULL) | |
1042 | { | |
1043 | struct objfile *objf; | |
1044 | ALL_OBJFILES (objf) | |
1045 | { | |
1046 | if (obfd == objf->obfd) | |
1047 | { | |
1048 | *resultp = obsavestring (decoded, strlen (decoded), | |
1049 | &objf->objfile_obstack); | |
1050 | break; | |
1051 | } | |
1052 | } | |
1053 | } | |
1054 | } | |
1055 | /* Sometimes, we can't find a corresponding objfile, in which | |
1056 | case, we put the result on the heap. Since we only decode | |
1057 | when needed, we hope this usually does not cause a | |
1058 | significant memory leak (FIXME). */ | |
1059 | if (*resultp == NULL) | |
1060 | { | |
1061 | char **slot = | |
1062 | (char **) htab_find_slot (decoded_names_store, | |
1063 | decoded, INSERT); | |
1064 | if (*slot == NULL) | |
1065 | *slot = xstrdup (decoded); | |
1066 | *resultp = *slot; | |
1067 | } | |
1068 | } | |
14f9c5c9 | 1069 | |
4c4b4cd2 PH |
1070 | return *resultp; |
1071 | } | |
1072 | ||
1073 | char *ada_la_decode (const char *encoded, int options) | |
1074 | { | |
1075 | return xstrdup (ada_decode (encoded)); | |
14f9c5c9 AS |
1076 | } |
1077 | ||
1078 | /* Returns non-zero iff SYM_NAME matches NAME, ignoring any trailing | |
4c4b4cd2 PH |
1079 | suffixes that encode debugging information or leading _ada_ on |
1080 | SYM_NAME (see is_name_suffix commentary for the debugging | |
1081 | information that is ignored). If WILD, then NAME need only match a | |
1082 | suffix of SYM_NAME minus the same suffixes. Also returns 0 if | |
1083 | either argument is NULL. */ | |
14f9c5c9 AS |
1084 | |
1085 | int | |
d2e4a39e | 1086 | ada_match_name (const char *sym_name, const char *name, int wild) |
14f9c5c9 AS |
1087 | { |
1088 | if (sym_name == NULL || name == NULL) | |
1089 | return 0; | |
1090 | else if (wild) | |
1091 | return wild_match (name, strlen (name), sym_name); | |
d2e4a39e AS |
1092 | else |
1093 | { | |
1094 | int len_name = strlen (name); | |
4c4b4cd2 PH |
1095 | return (strncmp (sym_name, name, len_name) == 0 |
1096 | && is_name_suffix (sym_name + len_name)) | |
1097 | || (strncmp (sym_name, "_ada_", 5) == 0 | |
1098 | && strncmp (sym_name + 5, name, len_name) == 0 | |
1099 | && is_name_suffix (sym_name + len_name + 5)); | |
d2e4a39e | 1100 | } |
14f9c5c9 AS |
1101 | } |
1102 | ||
4c4b4cd2 PH |
1103 | /* True (non-zero) iff, in Ada mode, the symbol SYM should be |
1104 | suppressed in info listings. */ | |
14f9c5c9 AS |
1105 | |
1106 | int | |
ebf56fd3 | 1107 | ada_suppress_symbol_printing (struct symbol *sym) |
14f9c5c9 | 1108 | { |
176620f1 | 1109 | if (SYMBOL_DOMAIN (sym) == STRUCT_DOMAIN) |
14f9c5c9 | 1110 | return 1; |
d2e4a39e | 1111 | else |
4c4b4cd2 | 1112 | return is_suppressed_name (SYMBOL_LINKAGE_NAME (sym)); |
14f9c5c9 | 1113 | } |
14f9c5c9 | 1114 | \f |
d2e4a39e | 1115 | |
4c4b4cd2 | 1116 | /* Arrays */ |
14f9c5c9 | 1117 | |
4c4b4cd2 | 1118 | /* Names of MAX_ADA_DIMENS bounds in P_BOUNDS fields of array descriptors. */ |
14f9c5c9 | 1119 | |
d2e4a39e AS |
1120 | static char *bound_name[] = { |
1121 | "LB0", "UB0", "LB1", "UB1", "LB2", "UB2", "LB3", "UB3", | |
14f9c5c9 AS |
1122 | "LB4", "UB4", "LB5", "UB5", "LB6", "UB6", "LB7", "UB7" |
1123 | }; | |
1124 | ||
1125 | /* Maximum number of array dimensions we are prepared to handle. */ | |
1126 | ||
4c4b4cd2 | 1127 | #define MAX_ADA_DIMENS (sizeof(bound_name) / (2*sizeof(char *))) |
14f9c5c9 | 1128 | |
4c4b4cd2 | 1129 | /* Like modify_field, but allows bitpos > wordlength. */ |
14f9c5c9 AS |
1130 | |
1131 | static void | |
ebf56fd3 | 1132 | modify_general_field (char *addr, LONGEST fieldval, int bitpos, int bitsize) |
14f9c5c9 | 1133 | { |
4c4b4cd2 | 1134 | modify_field (addr + bitpos / 8, fieldval, bitpos % 8, bitsize); |
14f9c5c9 AS |
1135 | } |
1136 | ||
1137 | ||
4c4b4cd2 PH |
1138 | /* The desc_* routines return primitive portions of array descriptors |
1139 | (fat pointers). */ | |
14f9c5c9 AS |
1140 | |
1141 | /* The descriptor or array type, if any, indicated by TYPE; removes | |
4c4b4cd2 PH |
1142 | level of indirection, if needed. */ |
1143 | ||
d2e4a39e AS |
1144 | static struct type * |
1145 | desc_base_type (struct type *type) | |
14f9c5c9 AS |
1146 | { |
1147 | if (type == NULL) | |
1148 | return NULL; | |
1149 | CHECK_TYPEDEF (type); | |
4c4b4cd2 PH |
1150 | if (type != NULL && |
1151 | (TYPE_CODE (type) == TYPE_CODE_PTR | |
1152 | || TYPE_CODE (type) == TYPE_CODE_REF)) | |
14f9c5c9 AS |
1153 | return check_typedef (TYPE_TARGET_TYPE (type)); |
1154 | else | |
1155 | return type; | |
1156 | } | |
1157 | ||
4c4b4cd2 PH |
1158 | /* True iff TYPE indicates a "thin" array pointer type. */ |
1159 | ||
14f9c5c9 | 1160 | static int |
d2e4a39e | 1161 | is_thin_pntr (struct type *type) |
14f9c5c9 | 1162 | { |
d2e4a39e | 1163 | return |
14f9c5c9 AS |
1164 | is_suffix (ada_type_name (desc_base_type (type)), "___XUT") |
1165 | || is_suffix (ada_type_name (desc_base_type (type)), "___XUT___XVE"); | |
1166 | } | |
1167 | ||
4c4b4cd2 PH |
1168 | /* The descriptor type for thin pointer type TYPE. */ |
1169 | ||
d2e4a39e AS |
1170 | static struct type * |
1171 | thin_descriptor_type (struct type *type) | |
14f9c5c9 | 1172 | { |
d2e4a39e | 1173 | struct type *base_type = desc_base_type (type); |
14f9c5c9 AS |
1174 | if (base_type == NULL) |
1175 | return NULL; | |
1176 | if (is_suffix (ada_type_name (base_type), "___XVE")) | |
1177 | return base_type; | |
d2e4a39e | 1178 | else |
14f9c5c9 | 1179 | { |
d2e4a39e | 1180 | struct type *alt_type = ada_find_parallel_type (base_type, "___XVE"); |
14f9c5c9 | 1181 | if (alt_type == NULL) |
4c4b4cd2 | 1182 | return base_type; |
14f9c5c9 | 1183 | else |
4c4b4cd2 | 1184 | return alt_type; |
14f9c5c9 AS |
1185 | } |
1186 | } | |
1187 | ||
4c4b4cd2 PH |
1188 | /* A pointer to the array data for thin-pointer value VAL. */ |
1189 | ||
d2e4a39e AS |
1190 | static struct value * |
1191 | thin_data_pntr (struct value *val) | |
14f9c5c9 | 1192 | { |
d2e4a39e | 1193 | struct type *type = VALUE_TYPE (val); |
14f9c5c9 | 1194 | if (TYPE_CODE (type) == TYPE_CODE_PTR) |
d2e4a39e | 1195 | return value_cast (desc_data_type (thin_descriptor_type (type)), |
4c4b4cd2 | 1196 | value_copy (val)); |
d2e4a39e | 1197 | else |
14f9c5c9 | 1198 | return value_from_longest (desc_data_type (thin_descriptor_type (type)), |
4c4b4cd2 | 1199 | VALUE_ADDRESS (val) + VALUE_OFFSET (val)); |
14f9c5c9 AS |
1200 | } |
1201 | ||
4c4b4cd2 PH |
1202 | /* True iff TYPE indicates a "thick" array pointer type. */ |
1203 | ||
14f9c5c9 | 1204 | static int |
d2e4a39e | 1205 | is_thick_pntr (struct type *type) |
14f9c5c9 AS |
1206 | { |
1207 | type = desc_base_type (type); | |
1208 | return (type != NULL && TYPE_CODE (type) == TYPE_CODE_STRUCT | |
4c4b4cd2 | 1209 | && lookup_struct_elt_type (type, "P_BOUNDS", 1) != NULL); |
14f9c5c9 AS |
1210 | } |
1211 | ||
4c4b4cd2 PH |
1212 | /* If TYPE is the type of an array descriptor (fat or thin pointer) or a |
1213 | pointer to one, the type of its bounds data; otherwise, NULL. */ | |
1214 | ||
d2e4a39e AS |
1215 | static struct type * |
1216 | desc_bounds_type (struct type *type) | |
14f9c5c9 | 1217 | { |
d2e4a39e | 1218 | struct type *r; |
14f9c5c9 AS |
1219 | |
1220 | type = desc_base_type (type); | |
1221 | ||
1222 | if (type == NULL) | |
1223 | return NULL; | |
1224 | else if (is_thin_pntr (type)) | |
1225 | { | |
1226 | type = thin_descriptor_type (type); | |
1227 | if (type == NULL) | |
4c4b4cd2 | 1228 | return NULL; |
14f9c5c9 AS |
1229 | r = lookup_struct_elt_type (type, "BOUNDS", 1); |
1230 | if (r != NULL) | |
4c4b4cd2 | 1231 | return check_typedef (r); |
14f9c5c9 AS |
1232 | } |
1233 | else if (TYPE_CODE (type) == TYPE_CODE_STRUCT) | |
1234 | { | |
1235 | r = lookup_struct_elt_type (type, "P_BOUNDS", 1); | |
1236 | if (r != NULL) | |
4c4b4cd2 | 1237 | return check_typedef (TYPE_TARGET_TYPE (check_typedef (r))); |
14f9c5c9 AS |
1238 | } |
1239 | return NULL; | |
1240 | } | |
1241 | ||
1242 | /* If ARR is an array descriptor (fat or thin pointer), or pointer to | |
4c4b4cd2 PH |
1243 | one, a pointer to its bounds data. Otherwise NULL. */ |
1244 | ||
d2e4a39e AS |
1245 | static struct value * |
1246 | desc_bounds (struct value *arr) | |
14f9c5c9 | 1247 | { |
d2e4a39e AS |
1248 | struct type *type = check_typedef (VALUE_TYPE (arr)); |
1249 | if (is_thin_pntr (type)) | |
14f9c5c9 | 1250 | { |
d2e4a39e | 1251 | struct type *bounds_type = |
4c4b4cd2 | 1252 | desc_bounds_type (thin_descriptor_type (type)); |
14f9c5c9 AS |
1253 | LONGEST addr; |
1254 | ||
1255 | if (desc_bounds_type == NULL) | |
4c4b4cd2 | 1256 | error ("Bad GNAT array descriptor"); |
14f9c5c9 AS |
1257 | |
1258 | /* NOTE: The following calculation is not really kosher, but | |
d2e4a39e | 1259 | since desc_type is an XVE-encoded type (and shouldn't be), |
4c4b4cd2 | 1260 | the correct calculation is a real pain. FIXME (and fix GCC). */ |
14f9c5c9 | 1261 | if (TYPE_CODE (type) == TYPE_CODE_PTR) |
4c4b4cd2 | 1262 | addr = value_as_long (arr); |
d2e4a39e | 1263 | else |
4c4b4cd2 | 1264 | addr = VALUE_ADDRESS (arr) + VALUE_OFFSET (arr); |
14f9c5c9 | 1265 | |
d2e4a39e | 1266 | return |
4c4b4cd2 PH |
1267 | value_from_longest (lookup_pointer_type (bounds_type), |
1268 | addr - TYPE_LENGTH (bounds_type)); | |
14f9c5c9 AS |
1269 | } |
1270 | ||
1271 | else if (is_thick_pntr (type)) | |
d2e4a39e | 1272 | return value_struct_elt (&arr, NULL, "P_BOUNDS", NULL, |
4c4b4cd2 | 1273 | "Bad GNAT array descriptor"); |
14f9c5c9 AS |
1274 | else |
1275 | return NULL; | |
1276 | } | |
1277 | ||
4c4b4cd2 PH |
1278 | /* If TYPE is the type of an array-descriptor (fat pointer), the bit |
1279 | position of the field containing the address of the bounds data. */ | |
1280 | ||
14f9c5c9 | 1281 | static int |
d2e4a39e | 1282 | fat_pntr_bounds_bitpos (struct type *type) |
14f9c5c9 AS |
1283 | { |
1284 | return TYPE_FIELD_BITPOS (desc_base_type (type), 1); | |
1285 | } | |
1286 | ||
1287 | /* If TYPE is the type of an array-descriptor (fat pointer), the bit | |
4c4b4cd2 PH |
1288 | size of the field containing the address of the bounds data. */ |
1289 | ||
14f9c5c9 | 1290 | static int |
d2e4a39e | 1291 | fat_pntr_bounds_bitsize (struct type *type) |
14f9c5c9 AS |
1292 | { |
1293 | type = desc_base_type (type); | |
1294 | ||
d2e4a39e | 1295 | if (TYPE_FIELD_BITSIZE (type, 1) > 0) |
14f9c5c9 AS |
1296 | return TYPE_FIELD_BITSIZE (type, 1); |
1297 | else | |
1298 | return 8 * TYPE_LENGTH (check_typedef (TYPE_FIELD_TYPE (type, 1))); | |
1299 | } | |
1300 | ||
4c4b4cd2 | 1301 | /* If TYPE is the type of an array descriptor (fat or thin pointer) or a |
14f9c5c9 | 1302 | pointer to one, the type of its array data (a |
4c4b4cd2 PH |
1303 | pointer-to-array-with-no-bounds type); otherwise, NULL. Use |
1304 | ada_type_of_array to get an array type with bounds data. */ | |
1305 | ||
d2e4a39e AS |
1306 | static struct type * |
1307 | desc_data_type (struct type *type) | |
14f9c5c9 AS |
1308 | { |
1309 | type = desc_base_type (type); | |
1310 | ||
4c4b4cd2 | 1311 | /* NOTE: The following is bogus; see comment in desc_bounds. */ |
14f9c5c9 | 1312 | if (is_thin_pntr (type)) |
d2e4a39e AS |
1313 | return lookup_pointer_type |
1314 | (desc_base_type (TYPE_FIELD_TYPE (thin_descriptor_type (type), 1))); | |
14f9c5c9 AS |
1315 | else if (is_thick_pntr (type)) |
1316 | return lookup_struct_elt_type (type, "P_ARRAY", 1); | |
1317 | else | |
1318 | return NULL; | |
1319 | } | |
1320 | ||
1321 | /* If ARR is an array descriptor (fat or thin pointer), a pointer to | |
1322 | its array data. */ | |
4c4b4cd2 | 1323 | |
d2e4a39e AS |
1324 | static struct value * |
1325 | desc_data (struct value *arr) | |
14f9c5c9 | 1326 | { |
d2e4a39e | 1327 | struct type *type = VALUE_TYPE (arr); |
14f9c5c9 AS |
1328 | if (is_thin_pntr (type)) |
1329 | return thin_data_pntr (arr); | |
1330 | else if (is_thick_pntr (type)) | |
d2e4a39e | 1331 | return value_struct_elt (&arr, NULL, "P_ARRAY", NULL, |
4c4b4cd2 | 1332 | "Bad GNAT array descriptor"); |
14f9c5c9 AS |
1333 | else |
1334 | return NULL; | |
1335 | } | |
1336 | ||
1337 | ||
1338 | /* If TYPE is the type of an array-descriptor (fat pointer), the bit | |
4c4b4cd2 PH |
1339 | position of the field containing the address of the data. */ |
1340 | ||
14f9c5c9 | 1341 | static int |
d2e4a39e | 1342 | fat_pntr_data_bitpos (struct type *type) |
14f9c5c9 AS |
1343 | { |
1344 | return TYPE_FIELD_BITPOS (desc_base_type (type), 0); | |
1345 | } | |
1346 | ||
1347 | /* If TYPE is the type of an array-descriptor (fat pointer), the bit | |
4c4b4cd2 PH |
1348 | size of the field containing the address of the data. */ |
1349 | ||
14f9c5c9 | 1350 | static int |
d2e4a39e | 1351 | fat_pntr_data_bitsize (struct type *type) |
14f9c5c9 AS |
1352 | { |
1353 | type = desc_base_type (type); | |
1354 | ||
1355 | if (TYPE_FIELD_BITSIZE (type, 0) > 0) | |
1356 | return TYPE_FIELD_BITSIZE (type, 0); | |
d2e4a39e | 1357 | else |
14f9c5c9 AS |
1358 | return TARGET_CHAR_BIT * TYPE_LENGTH (TYPE_FIELD_TYPE (type, 0)); |
1359 | } | |
1360 | ||
4c4b4cd2 | 1361 | /* If BOUNDS is an array-bounds structure (or pointer to one), return |
14f9c5c9 | 1362 | the Ith lower bound stored in it, if WHICH is 0, and the Ith upper |
4c4b4cd2 PH |
1363 | bound, if WHICH is 1. The first bound is I=1. */ |
1364 | ||
d2e4a39e AS |
1365 | static struct value * |
1366 | desc_one_bound (struct value *bounds, int i, int which) | |
14f9c5c9 | 1367 | { |
d2e4a39e | 1368 | return value_struct_elt (&bounds, NULL, bound_name[2 * i + which - 2], NULL, |
4c4b4cd2 | 1369 | "Bad GNAT array descriptor bounds"); |
14f9c5c9 AS |
1370 | } |
1371 | ||
1372 | /* If BOUNDS is an array-bounds structure type, return the bit position | |
1373 | of the Ith lower bound stored in it, if WHICH is 0, and the Ith upper | |
4c4b4cd2 PH |
1374 | bound, if WHICH is 1. The first bound is I=1. */ |
1375 | ||
14f9c5c9 | 1376 | static int |
d2e4a39e | 1377 | desc_bound_bitpos (struct type *type, int i, int which) |
14f9c5c9 | 1378 | { |
d2e4a39e | 1379 | return TYPE_FIELD_BITPOS (desc_base_type (type), 2 * i + which - 2); |
14f9c5c9 AS |
1380 | } |
1381 | ||
1382 | /* If BOUNDS is an array-bounds structure type, return the bit field size | |
1383 | of the Ith lower bound stored in it, if WHICH is 0, and the Ith upper | |
4c4b4cd2 PH |
1384 | bound, if WHICH is 1. The first bound is I=1. */ |
1385 | ||
1386 | static int | |
d2e4a39e | 1387 | desc_bound_bitsize (struct type *type, int i, int which) |
14f9c5c9 AS |
1388 | { |
1389 | type = desc_base_type (type); | |
1390 | ||
d2e4a39e AS |
1391 | if (TYPE_FIELD_BITSIZE (type, 2 * i + which - 2) > 0) |
1392 | return TYPE_FIELD_BITSIZE (type, 2 * i + which - 2); | |
1393 | else | |
1394 | return 8 * TYPE_LENGTH (TYPE_FIELD_TYPE (type, 2 * i + which - 2)); | |
14f9c5c9 AS |
1395 | } |
1396 | ||
1397 | /* If TYPE is the type of an array-bounds structure, the type of its | |
4c4b4cd2 PH |
1398 | Ith bound (numbering from 1). Otherwise, NULL. */ |
1399 | ||
d2e4a39e AS |
1400 | static struct type * |
1401 | desc_index_type (struct type *type, int i) | |
14f9c5c9 AS |
1402 | { |
1403 | type = desc_base_type (type); | |
1404 | ||
1405 | if (TYPE_CODE (type) == TYPE_CODE_STRUCT) | |
d2e4a39e AS |
1406 | return lookup_struct_elt_type (type, bound_name[2 * i - 2], 1); |
1407 | else | |
14f9c5c9 AS |
1408 | return NULL; |
1409 | } | |
1410 | ||
4c4b4cd2 PH |
1411 | /* The number of index positions in the array-bounds type TYPE. |
1412 | Return 0 if TYPE is NULL. */ | |
1413 | ||
14f9c5c9 | 1414 | static int |
d2e4a39e | 1415 | desc_arity (struct type *type) |
14f9c5c9 AS |
1416 | { |
1417 | type = desc_base_type (type); | |
1418 | ||
1419 | if (type != NULL) | |
1420 | return TYPE_NFIELDS (type) / 2; | |
1421 | return 0; | |
1422 | } | |
1423 | ||
4c4b4cd2 PH |
1424 | /* Non-zero iff TYPE is a simple array type (not a pointer to one) or |
1425 | an array descriptor type (representing an unconstrained array | |
1426 | type). */ | |
1427 | ||
1428 | static int | |
1429 | ada_is_direct_array_type (struct type *type) | |
1430 | { | |
1431 | if (type == NULL) | |
1432 | return 0; | |
1433 | CHECK_TYPEDEF (type); | |
1434 | return (TYPE_CODE (type) == TYPE_CODE_ARRAY | |
1435 | || ada_is_array_descriptor_type (type)); | |
1436 | } | |
1437 | ||
1438 | /* Non-zero iff TYPE is a simple array type or pointer to one. */ | |
14f9c5c9 | 1439 | |
14f9c5c9 | 1440 | int |
4c4b4cd2 | 1441 | ada_is_simple_array_type (struct type *type) |
14f9c5c9 AS |
1442 | { |
1443 | if (type == NULL) | |
1444 | return 0; | |
1445 | CHECK_TYPEDEF (type); | |
1446 | return (TYPE_CODE (type) == TYPE_CODE_ARRAY | |
4c4b4cd2 PH |
1447 | || (TYPE_CODE (type) == TYPE_CODE_PTR |
1448 | && TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_ARRAY)); | |
14f9c5c9 AS |
1449 | } |
1450 | ||
4c4b4cd2 PH |
1451 | /* Non-zero iff TYPE belongs to a GNAT array descriptor. */ |
1452 | ||
14f9c5c9 | 1453 | int |
4c4b4cd2 | 1454 | ada_is_array_descriptor_type (struct type *type) |
14f9c5c9 | 1455 | { |
d2e4a39e | 1456 | struct type *data_type = desc_data_type (type); |
14f9c5c9 AS |
1457 | |
1458 | if (type == NULL) | |
1459 | return 0; | |
1460 | CHECK_TYPEDEF (type); | |
d2e4a39e | 1461 | return |
14f9c5c9 AS |
1462 | data_type != NULL |
1463 | && ((TYPE_CODE (data_type) == TYPE_CODE_PTR | |
4c4b4cd2 PH |
1464 | && TYPE_TARGET_TYPE (data_type) != NULL |
1465 | && TYPE_CODE (TYPE_TARGET_TYPE (data_type)) == TYPE_CODE_ARRAY) | |
1466 | || | |
1467 | TYPE_CODE (data_type) == TYPE_CODE_ARRAY) | |
14f9c5c9 AS |
1468 | && desc_arity (desc_bounds_type (type)) > 0; |
1469 | } | |
1470 | ||
1471 | /* Non-zero iff type is a partially mal-formed GNAT array | |
4c4b4cd2 | 1472 | descriptor. FIXME: This is to compensate for some problems with |
14f9c5c9 | 1473 | debugging output from GNAT. Re-examine periodically to see if it |
4c4b4cd2 PH |
1474 | is still needed. */ |
1475 | ||
14f9c5c9 | 1476 | int |
ebf56fd3 | 1477 | ada_is_bogus_array_descriptor (struct type *type) |
14f9c5c9 | 1478 | { |
d2e4a39e | 1479 | return |
14f9c5c9 AS |
1480 | type != NULL |
1481 | && TYPE_CODE (type) == TYPE_CODE_STRUCT | |
1482 | && (lookup_struct_elt_type (type, "P_BOUNDS", 1) != NULL | |
4c4b4cd2 PH |
1483 | || lookup_struct_elt_type (type, "P_ARRAY", 1) != NULL) |
1484 | && !ada_is_array_descriptor_type (type); | |
14f9c5c9 AS |
1485 | } |
1486 | ||
1487 | ||
4c4b4cd2 | 1488 | /* If ARR has a record type in the form of a standard GNAT array descriptor, |
14f9c5c9 | 1489 | (fat pointer) returns the type of the array data described---specifically, |
4c4b4cd2 | 1490 | a pointer-to-array type. If BOUNDS is non-zero, the bounds data are filled |
14f9c5c9 | 1491 | in from the descriptor; otherwise, they are left unspecified. If |
4c4b4cd2 PH |
1492 | the ARR denotes a null array descriptor and BOUNDS is non-zero, |
1493 | returns NULL. The result is simply the type of ARR if ARR is not | |
14f9c5c9 | 1494 | a descriptor. */ |
d2e4a39e AS |
1495 | struct type * |
1496 | ada_type_of_array (struct value *arr, int bounds) | |
14f9c5c9 AS |
1497 | { |
1498 | if (ada_is_packed_array_type (VALUE_TYPE (arr))) | |
1499 | return decode_packed_array_type (VALUE_TYPE (arr)); | |
1500 | ||
4c4b4cd2 | 1501 | if (!ada_is_array_descriptor_type (VALUE_TYPE (arr))) |
14f9c5c9 | 1502 | return VALUE_TYPE (arr); |
d2e4a39e AS |
1503 | |
1504 | if (!bounds) | |
1505 | return | |
1506 | check_typedef (TYPE_TARGET_TYPE (desc_data_type (VALUE_TYPE (arr)))); | |
14f9c5c9 AS |
1507 | else |
1508 | { | |
d2e4a39e | 1509 | struct type *elt_type; |
14f9c5c9 | 1510 | int arity; |
d2e4a39e | 1511 | struct value *descriptor; |
14f9c5c9 AS |
1512 | struct objfile *objf = TYPE_OBJFILE (VALUE_TYPE (arr)); |
1513 | ||
1514 | elt_type = ada_array_element_type (VALUE_TYPE (arr), -1); | |
1515 | arity = ada_array_arity (VALUE_TYPE (arr)); | |
1516 | ||
d2e4a39e | 1517 | if (elt_type == NULL || arity == 0) |
4c4b4cd2 | 1518 | return check_typedef (VALUE_TYPE (arr)); |
14f9c5c9 AS |
1519 | |
1520 | descriptor = desc_bounds (arr); | |
d2e4a39e | 1521 | if (value_as_long (descriptor) == 0) |
4c4b4cd2 | 1522 | return NULL; |
d2e4a39e | 1523 | while (arity > 0) |
4c4b4cd2 PH |
1524 | { |
1525 | struct type *range_type = alloc_type (objf); | |
1526 | struct type *array_type = alloc_type (objf); | |
1527 | struct value *low = desc_one_bound (descriptor, arity, 0); | |
1528 | struct value *high = desc_one_bound (descriptor, arity, 1); | |
1529 | arity -= 1; | |
1530 | ||
1531 | create_range_type (range_type, VALUE_TYPE (low), | |
1532 | (int) value_as_long (low), | |
1533 | (int) value_as_long (high)); | |
1534 | elt_type = create_array_type (array_type, elt_type, range_type); | |
1535 | } | |
14f9c5c9 AS |
1536 | |
1537 | return lookup_pointer_type (elt_type); | |
1538 | } | |
1539 | } | |
1540 | ||
1541 | /* If ARR does not represent an array, returns ARR unchanged. | |
4c4b4cd2 PH |
1542 | Otherwise, returns either a standard GDB array with bounds set |
1543 | appropriately or, if ARR is a non-null fat pointer, a pointer to a standard | |
1544 | GDB array. Returns NULL if ARR is a null fat pointer. */ | |
1545 | ||
d2e4a39e AS |
1546 | struct value * |
1547 | ada_coerce_to_simple_array_ptr (struct value *arr) | |
14f9c5c9 | 1548 | { |
4c4b4cd2 | 1549 | if (ada_is_array_descriptor_type (VALUE_TYPE (arr))) |
14f9c5c9 | 1550 | { |
d2e4a39e | 1551 | struct type *arrType = ada_type_of_array (arr, 1); |
14f9c5c9 | 1552 | if (arrType == NULL) |
4c4b4cd2 | 1553 | return NULL; |
14f9c5c9 AS |
1554 | return value_cast (arrType, value_copy (desc_data (arr))); |
1555 | } | |
1556 | else if (ada_is_packed_array_type (VALUE_TYPE (arr))) | |
1557 | return decode_packed_array (arr); | |
1558 | else | |
1559 | return arr; | |
1560 | } | |
1561 | ||
1562 | /* If ARR does not represent an array, returns ARR unchanged. | |
1563 | Otherwise, returns a standard GDB array describing ARR (which may | |
4c4b4cd2 PH |
1564 | be ARR itself if it already is in the proper form). */ |
1565 | ||
1566 | static struct value * | |
d2e4a39e | 1567 | ada_coerce_to_simple_array (struct value *arr) |
14f9c5c9 | 1568 | { |
4c4b4cd2 | 1569 | if (ada_is_array_descriptor_type (VALUE_TYPE (arr))) |
14f9c5c9 | 1570 | { |
d2e4a39e | 1571 | struct value *arrVal = ada_coerce_to_simple_array_ptr (arr); |
14f9c5c9 | 1572 | if (arrVal == NULL) |
4c4b4cd2 | 1573 | error ("Bounds unavailable for null array pointer."); |
14f9c5c9 AS |
1574 | return value_ind (arrVal); |
1575 | } | |
1576 | else if (ada_is_packed_array_type (VALUE_TYPE (arr))) | |
1577 | return decode_packed_array (arr); | |
d2e4a39e | 1578 | else |
14f9c5c9 AS |
1579 | return arr; |
1580 | } | |
1581 | ||
1582 | /* If TYPE represents a GNAT array type, return it translated to an | |
1583 | ordinary GDB array type (possibly with BITSIZE fields indicating | |
4c4b4cd2 PH |
1584 | packing). For other types, is the identity. */ |
1585 | ||
d2e4a39e AS |
1586 | struct type * |
1587 | ada_coerce_to_simple_array_type (struct type *type) | |
14f9c5c9 | 1588 | { |
d2e4a39e AS |
1589 | struct value *mark = value_mark (); |
1590 | struct value *dummy = value_from_longest (builtin_type_long, 0); | |
1591 | struct type *result; | |
14f9c5c9 AS |
1592 | VALUE_TYPE (dummy) = type; |
1593 | result = ada_type_of_array (dummy, 0); | |
4c4b4cd2 | 1594 | value_free_to_mark (mark); |
14f9c5c9 AS |
1595 | return result; |
1596 | } | |
1597 | ||
4c4b4cd2 PH |
1598 | /* Non-zero iff TYPE represents a standard GNAT packed-array type. */ |
1599 | ||
14f9c5c9 | 1600 | int |
d2e4a39e | 1601 | ada_is_packed_array_type (struct type *type) |
14f9c5c9 AS |
1602 | { |
1603 | if (type == NULL) | |
1604 | return 0; | |
4c4b4cd2 | 1605 | type = desc_base_type (type); |
14f9c5c9 | 1606 | CHECK_TYPEDEF (type); |
d2e4a39e | 1607 | return |
14f9c5c9 AS |
1608 | ada_type_name (type) != NULL |
1609 | && strstr (ada_type_name (type), "___XP") != NULL; | |
1610 | } | |
1611 | ||
1612 | /* Given that TYPE is a standard GDB array type with all bounds filled | |
1613 | in, and that the element size of its ultimate scalar constituents | |
1614 | (that is, either its elements, or, if it is an array of arrays, its | |
1615 | elements' elements, etc.) is *ELT_BITS, return an identical type, | |
1616 | but with the bit sizes of its elements (and those of any | |
1617 | constituent arrays) recorded in the BITSIZE components of its | |
4c4b4cd2 PH |
1618 | TYPE_FIELD_BITSIZE values, and with *ELT_BITS set to its total size |
1619 | in bits. */ | |
1620 | ||
d2e4a39e AS |
1621 | static struct type * |
1622 | packed_array_type (struct type *type, long *elt_bits) | |
14f9c5c9 | 1623 | { |
d2e4a39e AS |
1624 | struct type *new_elt_type; |
1625 | struct type *new_type; | |
14f9c5c9 AS |
1626 | LONGEST low_bound, high_bound; |
1627 | ||
1628 | CHECK_TYPEDEF (type); | |
1629 | if (TYPE_CODE (type) != TYPE_CODE_ARRAY) | |
1630 | return type; | |
1631 | ||
1632 | new_type = alloc_type (TYPE_OBJFILE (type)); | |
1633 | new_elt_type = packed_array_type (check_typedef (TYPE_TARGET_TYPE (type)), | |
4c4b4cd2 | 1634 | elt_bits); |
14f9c5c9 AS |
1635 | create_array_type (new_type, new_elt_type, TYPE_FIELD_TYPE (type, 0)); |
1636 | TYPE_FIELD_BITSIZE (new_type, 0) = *elt_bits; | |
1637 | TYPE_NAME (new_type) = ada_type_name (type); | |
1638 | ||
d2e4a39e | 1639 | if (get_discrete_bounds (TYPE_FIELD_TYPE (type, 0), |
4c4b4cd2 | 1640 | &low_bound, &high_bound) < 0) |
14f9c5c9 AS |
1641 | low_bound = high_bound = 0; |
1642 | if (high_bound < low_bound) | |
1643 | *elt_bits = TYPE_LENGTH (new_type) = 0; | |
d2e4a39e | 1644 | else |
14f9c5c9 AS |
1645 | { |
1646 | *elt_bits *= (high_bound - low_bound + 1); | |
d2e4a39e | 1647 | TYPE_LENGTH (new_type) = |
4c4b4cd2 | 1648 | (*elt_bits + HOST_CHAR_BIT - 1) / HOST_CHAR_BIT; |
14f9c5c9 AS |
1649 | } |
1650 | ||
4c4b4cd2 | 1651 | TYPE_FLAGS (new_type) |= TYPE_FLAG_FIXED_INSTANCE; |
14f9c5c9 AS |
1652 | return new_type; |
1653 | } | |
1654 | ||
4c4b4cd2 PH |
1655 | /* The array type encoded by TYPE, where ada_is_packed_array_type (TYPE). */ |
1656 | ||
d2e4a39e AS |
1657 | static struct type * |
1658 | decode_packed_array_type (struct type *type) | |
1659 | { | |
4c4b4cd2 | 1660 | struct symbol *sym; |
d2e4a39e AS |
1661 | struct block **blocks; |
1662 | const char *raw_name = ada_type_name (check_typedef (type)); | |
1663 | char *name = (char *) alloca (strlen (raw_name) + 1); | |
1664 | char *tail = strstr (raw_name, "___XP"); | |
1665 | struct type *shadow_type; | |
14f9c5c9 AS |
1666 | long bits; |
1667 | int i, n; | |
1668 | ||
4c4b4cd2 PH |
1669 | type = desc_base_type (type); |
1670 | ||
14f9c5c9 AS |
1671 | memcpy (name, raw_name, tail - raw_name); |
1672 | name[tail - raw_name] = '\000'; | |
1673 | ||
4c4b4cd2 PH |
1674 | sym = standard_lookup (name, get_selected_block (0), VAR_DOMAIN); |
1675 | if (sym == NULL || SYMBOL_TYPE (sym) == NULL) | |
14f9c5c9 | 1676 | { |
4c4b4cd2 | 1677 | lim_warning ("could not find bounds information on packed array", 0); |
14f9c5c9 AS |
1678 | return NULL; |
1679 | } | |
4c4b4cd2 | 1680 | shadow_type = SYMBOL_TYPE (sym); |
14f9c5c9 AS |
1681 | |
1682 | if (TYPE_CODE (shadow_type) != TYPE_CODE_ARRAY) | |
1683 | { | |
4c4b4cd2 PH |
1684 | lim_warning ("could not understand bounds information on packed array", |
1685 | 0); | |
14f9c5c9 AS |
1686 | return NULL; |
1687 | } | |
d2e4a39e | 1688 | |
14f9c5c9 AS |
1689 | if (sscanf (tail + sizeof ("___XP") - 1, "%ld", &bits) != 1) |
1690 | { | |
4c4b4cd2 PH |
1691 | lim_warning |
1692 | ("could not understand bit size information on packed array", 0); | |
14f9c5c9 AS |
1693 | return NULL; |
1694 | } | |
d2e4a39e | 1695 | |
14f9c5c9 AS |
1696 | return packed_array_type (shadow_type, &bits); |
1697 | } | |
1698 | ||
4c4b4cd2 | 1699 | /* Given that ARR is a struct value *indicating a GNAT packed array, |
14f9c5c9 AS |
1700 | returns a simple array that denotes that array. Its type is a |
1701 | standard GDB array type except that the BITSIZEs of the array | |
1702 | target types are set to the number of bits in each element, and the | |
4c4b4cd2 | 1703 | type length is set appropriately. */ |
14f9c5c9 | 1704 | |
d2e4a39e AS |
1705 | static struct value * |
1706 | decode_packed_array (struct value *arr) | |
14f9c5c9 | 1707 | { |
4c4b4cd2 | 1708 | struct type *type; |
14f9c5c9 | 1709 | |
4c4b4cd2 PH |
1710 | arr = ada_coerce_ref (arr); |
1711 | if (TYPE_CODE (VALUE_TYPE (arr)) == TYPE_CODE_PTR) | |
1712 | arr = ada_value_ind (arr); | |
1713 | ||
1714 | type = decode_packed_array_type (VALUE_TYPE (arr)); | |
14f9c5c9 AS |
1715 | if (type == NULL) |
1716 | { | |
1717 | error ("can't unpack array"); | |
1718 | return NULL; | |
1719 | } | |
4c4b4cd2 | 1720 | return coerce_unspec_val_to_type (arr, type); |
14f9c5c9 AS |
1721 | } |
1722 | ||
1723 | ||
1724 | /* The value of the element of packed array ARR at the ARITY indices | |
4c4b4cd2 | 1725 | given in IND. ARR must be a simple array. */ |
14f9c5c9 | 1726 | |
d2e4a39e AS |
1727 | static struct value * |
1728 | value_subscript_packed (struct value *arr, int arity, struct value **ind) | |
14f9c5c9 AS |
1729 | { |
1730 | int i; | |
1731 | int bits, elt_off, bit_off; | |
1732 | long elt_total_bit_offset; | |
d2e4a39e AS |
1733 | struct type *elt_type; |
1734 | struct value *v; | |
14f9c5c9 AS |
1735 | |
1736 | bits = 0; | |
1737 | elt_total_bit_offset = 0; | |
1738 | elt_type = check_typedef (VALUE_TYPE (arr)); | |
d2e4a39e | 1739 | for (i = 0; i < arity; i += 1) |
14f9c5c9 | 1740 | { |
d2e4a39e | 1741 | if (TYPE_CODE (elt_type) != TYPE_CODE_ARRAY |
4c4b4cd2 PH |
1742 | || TYPE_FIELD_BITSIZE (elt_type, 0) == 0) |
1743 | error | |
1744 | ("attempt to do packed indexing of something other than a packed array"); | |
14f9c5c9 | 1745 | else |
4c4b4cd2 PH |
1746 | { |
1747 | struct type *range_type = TYPE_INDEX_TYPE (elt_type); | |
1748 | LONGEST lowerbound, upperbound; | |
1749 | LONGEST idx; | |
1750 | ||
1751 | if (get_discrete_bounds (range_type, &lowerbound, &upperbound) < 0) | |
1752 | { | |
1753 | lim_warning ("don't know bounds of array", 0); | |
1754 | lowerbound = upperbound = 0; | |
1755 | } | |
1756 | ||
1757 | idx = value_as_long (value_pos_atr (ind[i])); | |
1758 | if (idx < lowerbound || idx > upperbound) | |
1759 | lim_warning ("packed array index %ld out of bounds", (long) idx); | |
1760 | bits = TYPE_FIELD_BITSIZE (elt_type, 0); | |
1761 | elt_total_bit_offset += (idx - lowerbound) * bits; | |
1762 | elt_type = check_typedef (TYPE_TARGET_TYPE (elt_type)); | |
1763 | } | |
14f9c5c9 AS |
1764 | } |
1765 | elt_off = elt_total_bit_offset / HOST_CHAR_BIT; | |
1766 | bit_off = elt_total_bit_offset % HOST_CHAR_BIT; | |
d2e4a39e AS |
1767 | |
1768 | v = ada_value_primitive_packed_val (arr, NULL, elt_off, bit_off, | |
4c4b4cd2 | 1769 | bits, elt_type); |
14f9c5c9 AS |
1770 | if (VALUE_LVAL (arr) == lval_internalvar) |
1771 | VALUE_LVAL (v) = lval_internalvar_component; | |
1772 | else | |
1773 | VALUE_LVAL (v) = VALUE_LVAL (arr); | |
1774 | return v; | |
1775 | } | |
1776 | ||
4c4b4cd2 | 1777 | /* Non-zero iff TYPE includes negative integer values. */ |
14f9c5c9 AS |
1778 | |
1779 | static int | |
d2e4a39e | 1780 | has_negatives (struct type *type) |
14f9c5c9 | 1781 | { |
d2e4a39e AS |
1782 | switch (TYPE_CODE (type)) |
1783 | { | |
1784 | default: | |
1785 | return 0; | |
1786 | case TYPE_CODE_INT: | |
1787 | return !TYPE_UNSIGNED (type); | |
1788 | case TYPE_CODE_RANGE: | |
1789 | return TYPE_LOW_BOUND (type) < 0; | |
1790 | } | |
14f9c5c9 | 1791 | } |
d2e4a39e | 1792 | |
14f9c5c9 AS |
1793 | |
1794 | /* Create a new value of type TYPE from the contents of OBJ starting | |
1795 | at byte OFFSET, and bit offset BIT_OFFSET within that byte, | |
1796 | proceeding for BIT_SIZE bits. If OBJ is an lval in memory, then | |
4c4b4cd2 PH |
1797 | assigning through the result will set the field fetched from. |
1798 | VALADDR is ignored unless OBJ is NULL, in which case, | |
1799 | VALADDR+OFFSET must address the start of storage containing the | |
1800 | packed value. The value returned in this case is never an lval. | |
1801 | Assumes 0 <= BIT_OFFSET < HOST_CHAR_BIT. */ | |
14f9c5c9 | 1802 | |
d2e4a39e AS |
1803 | struct value * |
1804 | ada_value_primitive_packed_val (struct value *obj, char *valaddr, long offset, | |
4c4b4cd2 PH |
1805 | int bit_offset, int bit_size, |
1806 | struct type *type) | |
14f9c5c9 | 1807 | { |
d2e4a39e | 1808 | struct value *v; |
4c4b4cd2 PH |
1809 | int src, /* Index into the source area */ |
1810 | targ, /* Index into the target area */ | |
1811 | srcBitsLeft, /* Number of source bits left to move */ | |
1812 | nsrc, ntarg, /* Number of source and target bytes */ | |
1813 | unusedLS, /* Number of bits in next significant | |
1814 | byte of source that are unused */ | |
1815 | accumSize; /* Number of meaningful bits in accum */ | |
1816 | unsigned char *bytes; /* First byte containing data to unpack */ | |
d2e4a39e | 1817 | unsigned char *unpacked; |
4c4b4cd2 | 1818 | unsigned long accum; /* Staging area for bits being transferred */ |
14f9c5c9 AS |
1819 | unsigned char sign; |
1820 | int len = (bit_size + bit_offset + HOST_CHAR_BIT - 1) / 8; | |
4c4b4cd2 PH |
1821 | /* Transmit bytes from least to most significant; delta is the direction |
1822 | the indices move. */ | |
14f9c5c9 AS |
1823 | int delta = BITS_BIG_ENDIAN ? -1 : 1; |
1824 | ||
1825 | CHECK_TYPEDEF (type); | |
1826 | ||
1827 | if (obj == NULL) | |
1828 | { | |
1829 | v = allocate_value (type); | |
d2e4a39e | 1830 | bytes = (unsigned char *) (valaddr + offset); |
14f9c5c9 AS |
1831 | } |
1832 | else if (VALUE_LAZY (obj)) | |
1833 | { | |
1834 | v = value_at (type, | |
4c4b4cd2 | 1835 | VALUE_ADDRESS (obj) + VALUE_OFFSET (obj) + offset, NULL); |
d2e4a39e | 1836 | bytes = (unsigned char *) alloca (len); |
14f9c5c9 AS |
1837 | read_memory (VALUE_ADDRESS (v), bytes, len); |
1838 | } | |
d2e4a39e | 1839 | else |
14f9c5c9 AS |
1840 | { |
1841 | v = allocate_value (type); | |
d2e4a39e | 1842 | bytes = (unsigned char *) VALUE_CONTENTS (obj) + offset; |
14f9c5c9 | 1843 | } |
d2e4a39e AS |
1844 | |
1845 | if (obj != NULL) | |
14f9c5c9 AS |
1846 | { |
1847 | VALUE_LVAL (v) = VALUE_LVAL (obj); | |
1848 | if (VALUE_LVAL (obj) == lval_internalvar) | |
4c4b4cd2 | 1849 | VALUE_LVAL (v) = lval_internalvar_component; |
14f9c5c9 AS |
1850 | VALUE_ADDRESS (v) = VALUE_ADDRESS (obj) + VALUE_OFFSET (obj) + offset; |
1851 | VALUE_BITPOS (v) = bit_offset + VALUE_BITPOS (obj); | |
1852 | VALUE_BITSIZE (v) = bit_size; | |
1853 | if (VALUE_BITPOS (v) >= HOST_CHAR_BIT) | |
4c4b4cd2 PH |
1854 | { |
1855 | VALUE_ADDRESS (v) += 1; | |
1856 | VALUE_BITPOS (v) -= HOST_CHAR_BIT; | |
1857 | } | |
14f9c5c9 AS |
1858 | } |
1859 | else | |
1860 | VALUE_BITSIZE (v) = bit_size; | |
d2e4a39e | 1861 | unpacked = (unsigned char *) VALUE_CONTENTS (v); |
14f9c5c9 AS |
1862 | |
1863 | srcBitsLeft = bit_size; | |
1864 | nsrc = len; | |
1865 | ntarg = TYPE_LENGTH (type); | |
1866 | sign = 0; | |
1867 | if (bit_size == 0) | |
1868 | { | |
1869 | memset (unpacked, 0, TYPE_LENGTH (type)); | |
1870 | return v; | |
1871 | } | |
1872 | else if (BITS_BIG_ENDIAN) | |
1873 | { | |
d2e4a39e AS |
1874 | src = len - 1; |
1875 | if (has_negatives (type) && | |
4c4b4cd2 PH |
1876 | ((bytes[0] << bit_offset) & (1 << (HOST_CHAR_BIT - 1)))) |
1877 | sign = ~0; | |
d2e4a39e AS |
1878 | |
1879 | unusedLS = | |
4c4b4cd2 PH |
1880 | (HOST_CHAR_BIT - (bit_size + bit_offset) % HOST_CHAR_BIT) |
1881 | % HOST_CHAR_BIT; | |
14f9c5c9 AS |
1882 | |
1883 | switch (TYPE_CODE (type)) | |
4c4b4cd2 PH |
1884 | { |
1885 | case TYPE_CODE_ARRAY: | |
1886 | case TYPE_CODE_UNION: | |
1887 | case TYPE_CODE_STRUCT: | |
1888 | /* Non-scalar values must be aligned at a byte boundary... */ | |
1889 | accumSize = | |
1890 | (HOST_CHAR_BIT - bit_size % HOST_CHAR_BIT) % HOST_CHAR_BIT; | |
1891 | /* ... And are placed at the beginning (most-significant) bytes | |
1892 | of the target. */ | |
1893 | targ = src; | |
1894 | break; | |
1895 | default: | |
1896 | accumSize = 0; | |
1897 | targ = TYPE_LENGTH (type) - 1; | |
1898 | break; | |
1899 | } | |
14f9c5c9 | 1900 | } |
d2e4a39e | 1901 | else |
14f9c5c9 AS |
1902 | { |
1903 | int sign_bit_offset = (bit_size + bit_offset - 1) % 8; | |
1904 | ||
1905 | src = targ = 0; | |
1906 | unusedLS = bit_offset; | |
1907 | accumSize = 0; | |
1908 | ||
d2e4a39e | 1909 | if (has_negatives (type) && (bytes[len - 1] & (1 << sign_bit_offset))) |
4c4b4cd2 | 1910 | sign = ~0; |
14f9c5c9 | 1911 | } |
d2e4a39e | 1912 | |
14f9c5c9 AS |
1913 | accum = 0; |
1914 | while (nsrc > 0) | |
1915 | { | |
1916 | /* Mask for removing bits of the next source byte that are not | |
4c4b4cd2 | 1917 | part of the value. */ |
d2e4a39e | 1918 | unsigned int unusedMSMask = |
4c4b4cd2 PH |
1919 | (1 << (srcBitsLeft >= HOST_CHAR_BIT ? HOST_CHAR_BIT : srcBitsLeft)) - |
1920 | 1; | |
1921 | /* Sign-extend bits for this byte. */ | |
14f9c5c9 | 1922 | unsigned int signMask = sign & ~unusedMSMask; |
d2e4a39e | 1923 | accum |= |
4c4b4cd2 | 1924 | (((bytes[src] >> unusedLS) & unusedMSMask) | signMask) << accumSize; |
14f9c5c9 | 1925 | accumSize += HOST_CHAR_BIT - unusedLS; |
d2e4a39e | 1926 | if (accumSize >= HOST_CHAR_BIT) |
4c4b4cd2 PH |
1927 | { |
1928 | unpacked[targ] = accum & ~(~0L << HOST_CHAR_BIT); | |
1929 | accumSize -= HOST_CHAR_BIT; | |
1930 | accum >>= HOST_CHAR_BIT; | |
1931 | ntarg -= 1; | |
1932 | targ += delta; | |
1933 | } | |
14f9c5c9 AS |
1934 | srcBitsLeft -= HOST_CHAR_BIT - unusedLS; |
1935 | unusedLS = 0; | |
1936 | nsrc -= 1; | |
1937 | src += delta; | |
1938 | } | |
1939 | while (ntarg > 0) | |
1940 | { | |
1941 | accum |= sign << accumSize; | |
1942 | unpacked[targ] = accum & ~(~0L << HOST_CHAR_BIT); | |
1943 | accumSize -= HOST_CHAR_BIT; | |
1944 | accum >>= HOST_CHAR_BIT; | |
1945 | ntarg -= 1; | |
1946 | targ += delta; | |
1947 | } | |
1948 | ||
1949 | return v; | |
1950 | } | |
d2e4a39e | 1951 | |
14f9c5c9 AS |
1952 | /* Move N bits from SOURCE, starting at bit offset SRC_OFFSET to |
1953 | TARGET, starting at bit offset TARG_OFFSET. SOURCE and TARGET must | |
4c4b4cd2 | 1954 | not overlap. */ |
14f9c5c9 | 1955 | static void |
d2e4a39e | 1956 | move_bits (char *target, int targ_offset, char *source, int src_offset, int n) |
14f9c5c9 AS |
1957 | { |
1958 | unsigned int accum, mask; | |
1959 | int accum_bits, chunk_size; | |
1960 | ||
1961 | target += targ_offset / HOST_CHAR_BIT; | |
1962 | targ_offset %= HOST_CHAR_BIT; | |
1963 | source += src_offset / HOST_CHAR_BIT; | |
1964 | src_offset %= HOST_CHAR_BIT; | |
d2e4a39e | 1965 | if (BITS_BIG_ENDIAN) |
14f9c5c9 AS |
1966 | { |
1967 | accum = (unsigned char) *source; | |
1968 | source += 1; | |
1969 | accum_bits = HOST_CHAR_BIT - src_offset; | |
1970 | ||
d2e4a39e | 1971 | while (n > 0) |
4c4b4cd2 PH |
1972 | { |
1973 | int unused_right; | |
1974 | accum = (accum << HOST_CHAR_BIT) + (unsigned char) *source; | |
1975 | accum_bits += HOST_CHAR_BIT; | |
1976 | source += 1; | |
1977 | chunk_size = HOST_CHAR_BIT - targ_offset; | |
1978 | if (chunk_size > n) | |
1979 | chunk_size = n; | |
1980 | unused_right = HOST_CHAR_BIT - (chunk_size + targ_offset); | |
1981 | mask = ((1 << chunk_size) - 1) << unused_right; | |
1982 | *target = | |
1983 | (*target & ~mask) | |
1984 | | ((accum >> (accum_bits - chunk_size - unused_right)) & mask); | |
1985 | n -= chunk_size; | |
1986 | accum_bits -= chunk_size; | |
1987 | target += 1; | |
1988 | targ_offset = 0; | |
1989 | } | |
14f9c5c9 AS |
1990 | } |
1991 | else | |
1992 | { | |
1993 | accum = (unsigned char) *source >> src_offset; | |
1994 | source += 1; | |
1995 | accum_bits = HOST_CHAR_BIT - src_offset; | |
1996 | ||
d2e4a39e | 1997 | while (n > 0) |
4c4b4cd2 PH |
1998 | { |
1999 | accum = accum + ((unsigned char) *source << accum_bits); | |
2000 | accum_bits += HOST_CHAR_BIT; | |
2001 | source += 1; | |
2002 | chunk_size = HOST_CHAR_BIT - targ_offset; | |
2003 | if (chunk_size > n) | |
2004 | chunk_size = n; | |
2005 | mask = ((1 << chunk_size) - 1) << targ_offset; | |
2006 | *target = (*target & ~mask) | ((accum << targ_offset) & mask); | |
2007 | n -= chunk_size; | |
2008 | accum_bits -= chunk_size; | |
2009 | accum >>= chunk_size; | |
2010 | target += 1; | |
2011 | targ_offset = 0; | |
2012 | } | |
14f9c5c9 AS |
2013 | } |
2014 | } | |
2015 | ||
2016 | ||
2017 | /* Store the contents of FROMVAL into the location of TOVAL. | |
2018 | Return a new value with the location of TOVAL and contents of | |
2019 | FROMVAL. Handles assignment into packed fields that have | |
4c4b4cd2 | 2020 | floating-point or non-scalar types. */ |
14f9c5c9 | 2021 | |
d2e4a39e AS |
2022 | static struct value * |
2023 | ada_value_assign (struct value *toval, struct value *fromval) | |
14f9c5c9 | 2024 | { |
d2e4a39e | 2025 | struct type *type = VALUE_TYPE (toval); |
14f9c5c9 AS |
2026 | int bits = VALUE_BITSIZE (toval); |
2027 | ||
2028 | if (!toval->modifiable) | |
2029 | error ("Left operand of assignment is not a modifiable lvalue."); | |
2030 | ||
2031 | COERCE_REF (toval); | |
2032 | ||
d2e4a39e | 2033 | if (VALUE_LVAL (toval) == lval_memory |
14f9c5c9 | 2034 | && bits > 0 |
d2e4a39e | 2035 | && (TYPE_CODE (type) == TYPE_CODE_FLT |
4c4b4cd2 | 2036 | || TYPE_CODE (type) == TYPE_CODE_STRUCT)) |
14f9c5c9 | 2037 | { |
d2e4a39e | 2038 | int len = |
4c4b4cd2 | 2039 | (VALUE_BITPOS (toval) + bits + HOST_CHAR_BIT - 1) / HOST_CHAR_BIT; |
d2e4a39e AS |
2040 | char *buffer = (char *) alloca (len); |
2041 | struct value *val; | |
14f9c5c9 AS |
2042 | |
2043 | if (TYPE_CODE (type) == TYPE_CODE_FLT) | |
4c4b4cd2 | 2044 | fromval = value_cast (type, fromval); |
14f9c5c9 AS |
2045 | |
2046 | read_memory (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval), buffer, len); | |
2047 | if (BITS_BIG_ENDIAN) | |
4c4b4cd2 PH |
2048 | move_bits (buffer, VALUE_BITPOS (toval), |
2049 | VALUE_CONTENTS (fromval), | |
2050 | TYPE_LENGTH (VALUE_TYPE (fromval)) * TARGET_CHAR_BIT - | |
2051 | bits, bits); | |
14f9c5c9 | 2052 | else |
4c4b4cd2 PH |
2053 | move_bits (buffer, VALUE_BITPOS (toval), VALUE_CONTENTS (fromval), |
2054 | 0, bits); | |
d2e4a39e | 2055 | write_memory (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval), buffer, |
4c4b4cd2 | 2056 | len); |
14f9c5c9 AS |
2057 | |
2058 | val = value_copy (toval); | |
2059 | memcpy (VALUE_CONTENTS_RAW (val), VALUE_CONTENTS (fromval), | |
4c4b4cd2 | 2060 | TYPE_LENGTH (type)); |
14f9c5c9 | 2061 | VALUE_TYPE (val) = type; |
d2e4a39e | 2062 | |
14f9c5c9 AS |
2063 | return val; |
2064 | } | |
2065 | ||
2066 | return value_assign (toval, fromval); | |
2067 | } | |
2068 | ||
2069 | ||
4c4b4cd2 PH |
2070 | /* The value of the element of array ARR at the ARITY indices given in IND. |
2071 | ARR may be either a simple array, GNAT array descriptor, or pointer | |
14f9c5c9 AS |
2072 | thereto. */ |
2073 | ||
d2e4a39e AS |
2074 | struct value * |
2075 | ada_value_subscript (struct value *arr, int arity, struct value **ind) | |
14f9c5c9 AS |
2076 | { |
2077 | int k; | |
d2e4a39e AS |
2078 | struct value *elt; |
2079 | struct type *elt_type; | |
14f9c5c9 AS |
2080 | |
2081 | elt = ada_coerce_to_simple_array (arr); | |
2082 | ||
2083 | elt_type = check_typedef (VALUE_TYPE (elt)); | |
d2e4a39e | 2084 | if (TYPE_CODE (elt_type) == TYPE_CODE_ARRAY |
14f9c5c9 AS |
2085 | && TYPE_FIELD_BITSIZE (elt_type, 0) > 0) |
2086 | return value_subscript_packed (elt, arity, ind); | |
2087 | ||
2088 | for (k = 0; k < arity; k += 1) | |
2089 | { | |
2090 | if (TYPE_CODE (elt_type) != TYPE_CODE_ARRAY) | |
4c4b4cd2 | 2091 | error ("too many subscripts (%d expected)", k); |
14f9c5c9 AS |
2092 | elt = value_subscript (elt, value_pos_atr (ind[k])); |
2093 | } | |
2094 | return elt; | |
2095 | } | |
2096 | ||
2097 | /* Assuming ARR is a pointer to a standard GDB array of type TYPE, the | |
2098 | value of the element of *ARR at the ARITY indices given in | |
4c4b4cd2 | 2099 | IND. Does not read the entire array into memory. */ |
14f9c5c9 | 2100 | |
d2e4a39e AS |
2101 | struct value * |
2102 | ada_value_ptr_subscript (struct value *arr, struct type *type, int arity, | |
4c4b4cd2 | 2103 | struct value **ind) |
14f9c5c9 AS |
2104 | { |
2105 | int k; | |
2106 | ||
2107 | for (k = 0; k < arity; k += 1) | |
2108 | { | |
2109 | LONGEST lwb, upb; | |
d2e4a39e | 2110 | struct value *idx; |
14f9c5c9 AS |
2111 | |
2112 | if (TYPE_CODE (type) != TYPE_CODE_ARRAY) | |
4c4b4cd2 | 2113 | error ("too many subscripts (%d expected)", k); |
d2e4a39e | 2114 | arr = value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (type)), |
4c4b4cd2 | 2115 | value_copy (arr)); |
14f9c5c9 | 2116 | get_discrete_bounds (TYPE_INDEX_TYPE (type), &lwb, &upb); |
4c4b4cd2 PH |
2117 | idx = value_pos_atr (ind[k]); |
2118 | if (lwb != 0) | |
2119 | idx = value_sub (idx, value_from_longest (builtin_type_int, lwb)); | |
14f9c5c9 AS |
2120 | arr = value_add (arr, idx); |
2121 | type = TYPE_TARGET_TYPE (type); | |
2122 | } | |
2123 | ||
2124 | return value_ind (arr); | |
2125 | } | |
2126 | ||
2127 | /* If type is a record type in the form of a standard GNAT array | |
2128 | descriptor, returns the number of dimensions for type. If arr is a | |
2129 | simple array, returns the number of "array of"s that prefix its | |
4c4b4cd2 | 2130 | type designation. Otherwise, returns 0. */ |
14f9c5c9 AS |
2131 | |
2132 | int | |
d2e4a39e | 2133 | ada_array_arity (struct type *type) |
14f9c5c9 AS |
2134 | { |
2135 | int arity; | |
2136 | ||
2137 | if (type == NULL) | |
2138 | return 0; | |
2139 | ||
2140 | type = desc_base_type (type); | |
2141 | ||
2142 | arity = 0; | |
d2e4a39e | 2143 | if (TYPE_CODE (type) == TYPE_CODE_STRUCT) |
14f9c5c9 | 2144 | return desc_arity (desc_bounds_type (type)); |
d2e4a39e AS |
2145 | else |
2146 | while (TYPE_CODE (type) == TYPE_CODE_ARRAY) | |
14f9c5c9 | 2147 | { |
4c4b4cd2 PH |
2148 | arity += 1; |
2149 | type = check_typedef (TYPE_TARGET_TYPE (type)); | |
14f9c5c9 | 2150 | } |
d2e4a39e | 2151 | |
14f9c5c9 AS |
2152 | return arity; |
2153 | } | |
2154 | ||
2155 | /* If TYPE is a record type in the form of a standard GNAT array | |
2156 | descriptor or a simple array type, returns the element type for | |
2157 | TYPE after indexing by NINDICES indices, or by all indices if | |
4c4b4cd2 | 2158 | NINDICES is -1. Otherwise, returns NULL. */ |
14f9c5c9 | 2159 | |
d2e4a39e AS |
2160 | struct type * |
2161 | ada_array_element_type (struct type *type, int nindices) | |
14f9c5c9 AS |
2162 | { |
2163 | type = desc_base_type (type); | |
2164 | ||
d2e4a39e | 2165 | if (TYPE_CODE (type) == TYPE_CODE_STRUCT) |
14f9c5c9 AS |
2166 | { |
2167 | int k; | |
d2e4a39e | 2168 | struct type *p_array_type; |
14f9c5c9 AS |
2169 | |
2170 | p_array_type = desc_data_type (type); | |
2171 | ||
2172 | k = ada_array_arity (type); | |
2173 | if (k == 0) | |
4c4b4cd2 | 2174 | return NULL; |
d2e4a39e | 2175 | |
4c4b4cd2 | 2176 | /* Initially p_array_type = elt_type(*)[]...(k times)...[]. */ |
14f9c5c9 | 2177 | if (nindices >= 0 && k > nindices) |
4c4b4cd2 | 2178 | k = nindices; |
14f9c5c9 | 2179 | p_array_type = TYPE_TARGET_TYPE (p_array_type); |
d2e4a39e | 2180 | while (k > 0 && p_array_type != NULL) |
4c4b4cd2 PH |
2181 | { |
2182 | p_array_type = check_typedef (TYPE_TARGET_TYPE (p_array_type)); | |
2183 | k -= 1; | |
2184 | } | |
14f9c5c9 AS |
2185 | return p_array_type; |
2186 | } | |
2187 | else if (TYPE_CODE (type) == TYPE_CODE_ARRAY) | |
2188 | { | |
2189 | while (nindices != 0 && TYPE_CODE (type) == TYPE_CODE_ARRAY) | |
4c4b4cd2 PH |
2190 | { |
2191 | type = TYPE_TARGET_TYPE (type); | |
2192 | nindices -= 1; | |
2193 | } | |
14f9c5c9 AS |
2194 | return type; |
2195 | } | |
2196 | ||
2197 | return NULL; | |
2198 | } | |
2199 | ||
4c4b4cd2 PH |
2200 | /* The type of nth index in arrays of given type (n numbering from 1). |
2201 | Does not examine memory. */ | |
14f9c5c9 | 2202 | |
d2e4a39e AS |
2203 | struct type * |
2204 | ada_index_type (struct type *type, int n) | |
14f9c5c9 | 2205 | { |
4c4b4cd2 PH |
2206 | struct type *result_type; |
2207 | ||
14f9c5c9 AS |
2208 | type = desc_base_type (type); |
2209 | ||
2210 | if (n > ada_array_arity (type)) | |
2211 | return NULL; | |
2212 | ||
4c4b4cd2 | 2213 | if (ada_is_simple_array_type (type)) |
14f9c5c9 AS |
2214 | { |
2215 | int i; | |
2216 | ||
2217 | for (i = 1; i < n; i += 1) | |
4c4b4cd2 PH |
2218 | type = TYPE_TARGET_TYPE (type); |
2219 | result_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, 0)); | |
2220 | /* FIXME: The stabs type r(0,0);bound;bound in an array type | |
2221 | has a target type of TYPE_CODE_UNDEF. We compensate here, but | |
2222 | perhaps stabsread.c would make more sense. */ | |
2223 | if (result_type == NULL | |
2224 | || TYPE_CODE (result_type) == TYPE_CODE_UNDEF) | |
2225 | result_type = builtin_type_int; | |
14f9c5c9 | 2226 | |
4c4b4cd2 | 2227 | return result_type; |
14f9c5c9 | 2228 | } |
d2e4a39e | 2229 | else |
14f9c5c9 AS |
2230 | return desc_index_type (desc_bounds_type (type), n); |
2231 | } | |
2232 | ||
2233 | /* Given that arr is an array type, returns the lower bound of the | |
2234 | Nth index (numbering from 1) if WHICH is 0, and the upper bound if | |
4c4b4cd2 PH |
2235 | WHICH is 1. This returns bounds 0 .. -1 if ARR_TYPE is an |
2236 | array-descriptor type. If TYPEP is non-null, *TYPEP is set to the | |
2237 | bounds type. It works for other arrays with bounds supplied by | |
2238 | run-time quantities other than discriminants. */ | |
14f9c5c9 AS |
2239 | |
2240 | LONGEST | |
d2e4a39e | 2241 | ada_array_bound_from_type (struct type * arr_type, int n, int which, |
4c4b4cd2 | 2242 | struct type ** typep) |
14f9c5c9 | 2243 | { |
d2e4a39e AS |
2244 | struct type *type; |
2245 | struct type *index_type_desc; | |
14f9c5c9 AS |
2246 | |
2247 | if (ada_is_packed_array_type (arr_type)) | |
2248 | arr_type = decode_packed_array_type (arr_type); | |
2249 | ||
4c4b4cd2 | 2250 | if (arr_type == NULL || !ada_is_simple_array_type (arr_type)) |
14f9c5c9 AS |
2251 | { |
2252 | if (typep != NULL) | |
4c4b4cd2 | 2253 | *typep = builtin_type_int; |
d2e4a39e | 2254 | return (LONGEST) - which; |
14f9c5c9 AS |
2255 | } |
2256 | ||
2257 | if (TYPE_CODE (arr_type) == TYPE_CODE_PTR) | |
2258 | type = TYPE_TARGET_TYPE (arr_type); | |
2259 | else | |
2260 | type = arr_type; | |
2261 | ||
2262 | index_type_desc = ada_find_parallel_type (type, "___XA"); | |
d2e4a39e | 2263 | if (index_type_desc == NULL) |
14f9c5c9 | 2264 | { |
d2e4a39e AS |
2265 | struct type *range_type; |
2266 | struct type *index_type; | |
14f9c5c9 | 2267 | |
d2e4a39e | 2268 | while (n > 1) |
4c4b4cd2 PH |
2269 | { |
2270 | type = TYPE_TARGET_TYPE (type); | |
2271 | n -= 1; | |
2272 | } | |
14f9c5c9 AS |
2273 | |
2274 | range_type = TYPE_INDEX_TYPE (type); | |
2275 | index_type = TYPE_TARGET_TYPE (range_type); | |
2276 | if (TYPE_CODE (index_type) == TYPE_CODE_UNDEF) | |
4c4b4cd2 | 2277 | index_type = builtin_type_long; |
14f9c5c9 | 2278 | if (typep != NULL) |
4c4b4cd2 | 2279 | *typep = index_type; |
d2e4a39e | 2280 | return |
4c4b4cd2 PH |
2281 | (LONGEST) (which == 0 |
2282 | ? TYPE_LOW_BOUND (range_type) | |
2283 | : TYPE_HIGH_BOUND (range_type)); | |
14f9c5c9 | 2284 | } |
d2e4a39e | 2285 | else |
14f9c5c9 | 2286 | { |
d2e4a39e | 2287 | struct type *index_type = |
4c4b4cd2 PH |
2288 | to_fixed_range_type (TYPE_FIELD_NAME (index_type_desc, n - 1), |
2289 | NULL, TYPE_OBJFILE (arr_type)); | |
14f9c5c9 | 2290 | if (typep != NULL) |
4c4b4cd2 | 2291 | *typep = TYPE_TARGET_TYPE (index_type); |
d2e4a39e | 2292 | return |
4c4b4cd2 PH |
2293 | (LONGEST) (which == 0 |
2294 | ? TYPE_LOW_BOUND (index_type) | |
2295 | : TYPE_HIGH_BOUND (index_type)); | |
14f9c5c9 AS |
2296 | } |
2297 | } | |
2298 | ||
2299 | /* Given that arr is an array value, returns the lower bound of the | |
2300 | nth index (numbering from 1) if which is 0, and the upper bound if | |
4c4b4cd2 PH |
2301 | which is 1. This routine will also work for arrays with bounds |
2302 | supplied by run-time quantities other than discriminants. */ | |
14f9c5c9 | 2303 | |
d2e4a39e | 2304 | struct value * |
4dc81987 | 2305 | ada_array_bound (struct value *arr, int n, int which) |
14f9c5c9 | 2306 | { |
d2e4a39e | 2307 | struct type *arr_type = VALUE_TYPE (arr); |
14f9c5c9 AS |
2308 | |
2309 | if (ada_is_packed_array_type (arr_type)) | |
2310 | return ada_array_bound (decode_packed_array (arr), n, which); | |
4c4b4cd2 | 2311 | else if (ada_is_simple_array_type (arr_type)) |
14f9c5c9 | 2312 | { |
d2e4a39e | 2313 | struct type *type; |
14f9c5c9 AS |
2314 | LONGEST v = ada_array_bound_from_type (arr_type, n, which, &type); |
2315 | return value_from_longest (type, v); | |
2316 | } | |
2317 | else | |
2318 | return desc_one_bound (desc_bounds (arr), n, which); | |
2319 | } | |
2320 | ||
2321 | /* Given that arr is an array value, returns the length of the | |
2322 | nth index. This routine will also work for arrays with bounds | |
4c4b4cd2 PH |
2323 | supplied by run-time quantities other than discriminants. |
2324 | Does not work for arrays indexed by enumeration types with representation | |
2325 | clauses at the moment. */ | |
14f9c5c9 | 2326 | |
d2e4a39e AS |
2327 | struct value * |
2328 | ada_array_length (struct value *arr, int n) | |
14f9c5c9 | 2329 | { |
d2e4a39e | 2330 | struct type *arr_type = check_typedef (VALUE_TYPE (arr)); |
14f9c5c9 AS |
2331 | |
2332 | if (ada_is_packed_array_type (arr_type)) | |
2333 | return ada_array_length (decode_packed_array (arr), n); | |
2334 | ||
4c4b4cd2 | 2335 | if (ada_is_simple_array_type (arr_type)) |
14f9c5c9 | 2336 | { |
d2e4a39e | 2337 | struct type *type; |
14f9c5c9 | 2338 | LONGEST v = |
4c4b4cd2 PH |
2339 | ada_array_bound_from_type (arr_type, n, 1, &type) - |
2340 | ada_array_bound_from_type (arr_type, n, 0, NULL) + 1; | |
14f9c5c9 AS |
2341 | return value_from_longest (type, v); |
2342 | } | |
2343 | else | |
d2e4a39e | 2344 | return |
14f9c5c9 | 2345 | value_from_longest (builtin_type_ada_int, |
4c4b4cd2 PH |
2346 | value_as_long (desc_one_bound (desc_bounds (arr), |
2347 | n, 1)) | |
2348 | - value_as_long (desc_one_bound (desc_bounds (arr), | |
2349 | n, 0)) + 1); | |
2350 | } | |
2351 | ||
2352 | /* An empty array whose type is that of ARR_TYPE (an array type), | |
2353 | with bounds LOW to LOW-1. */ | |
2354 | ||
2355 | static struct value * | |
2356 | empty_array (struct type *arr_type, int low) | |
2357 | { | |
2358 | return allocate_value (create_range_type (NULL, TYPE_INDEX_TYPE (arr_type), | |
2359 | low, low - 1)); | |
14f9c5c9 | 2360 | } |
14f9c5c9 | 2361 | \f |
d2e4a39e | 2362 | |
4c4b4cd2 | 2363 | /* Name resolution */ |
14f9c5c9 | 2364 | |
4c4b4cd2 PH |
2365 | /* The "decoded" name for the user-definable Ada operator corresponding |
2366 | to OP. */ | |
14f9c5c9 | 2367 | |
d2e4a39e | 2368 | static const char * |
4c4b4cd2 | 2369 | ada_decoded_op_name (enum exp_opcode op) |
14f9c5c9 AS |
2370 | { |
2371 | int i; | |
2372 | ||
4c4b4cd2 | 2373 | for (i = 0; ada_opname_table[i].encoded != NULL; i += 1) |
14f9c5c9 AS |
2374 | { |
2375 | if (ada_opname_table[i].op == op) | |
4c4b4cd2 | 2376 | return ada_opname_table[i].decoded; |
14f9c5c9 AS |
2377 | } |
2378 | error ("Could not find operator name for opcode"); | |
2379 | } | |
2380 | ||
2381 | ||
4c4b4cd2 PH |
2382 | /* Same as evaluate_type (*EXP), but resolves ambiguous symbol |
2383 | references (marked by OP_VAR_VALUE nodes in which the symbol has an | |
2384 | undefined namespace) and converts operators that are | |
2385 | user-defined into appropriate function calls. If CONTEXT_TYPE is | |
14f9c5c9 AS |
2386 | non-null, it provides a preferred result type [at the moment, only |
2387 | type void has any effect---causing procedures to be preferred over | |
2388 | functions in calls]. A null CONTEXT_TYPE indicates that a non-void | |
4c4b4cd2 | 2389 | return type is preferred. May change (expand) *EXP. */ |
14f9c5c9 | 2390 | |
4c4b4cd2 PH |
2391 | static void |
2392 | resolve (struct expression **expp, int void_context_p) | |
14f9c5c9 AS |
2393 | { |
2394 | int pc; | |
2395 | pc = 0; | |
4c4b4cd2 | 2396 | resolve_subexp (expp, &pc, 1, void_context_p ? builtin_type_void : NULL); |
14f9c5c9 AS |
2397 | } |
2398 | ||
4c4b4cd2 PH |
2399 | /* Resolve the operator of the subexpression beginning at |
2400 | position *POS of *EXPP. "Resolving" consists of replacing | |
2401 | the symbols that have undefined namespaces in OP_VAR_VALUE nodes | |
2402 | with their resolutions, replacing built-in operators with | |
2403 | function calls to user-defined operators, where appropriate, and, | |
2404 | when DEPROCEDURE_P is non-zero, converting function-valued variables | |
2405 | into parameterless calls. May expand *EXPP. The CONTEXT_TYPE functions | |
2406 | are as in ada_resolve, above. */ | |
14f9c5c9 | 2407 | |
d2e4a39e | 2408 | static struct value * |
4c4b4cd2 PH |
2409 | resolve_subexp (struct expression **expp, int *pos, int deprocedure_p, |
2410 | struct type *context_type) | |
14f9c5c9 AS |
2411 | { |
2412 | int pc = *pos; | |
2413 | int i; | |
4c4b4cd2 | 2414 | struct expression *exp; /* Convenience: == *expp. */ |
14f9c5c9 | 2415 | enum exp_opcode op = (*expp)->elts[pc].opcode; |
4c4b4cd2 PH |
2416 | struct value **argvec; /* Vector of operand types (alloca'ed). */ |
2417 | int nargs; /* Number of operands. */ | |
14f9c5c9 AS |
2418 | |
2419 | argvec = NULL; | |
2420 | nargs = 0; | |
2421 | exp = *expp; | |
2422 | ||
4c4b4cd2 | 2423 | /* Pass one: resolve operands, saving their types and updating *pos. */ |
14f9c5c9 AS |
2424 | switch (op) |
2425 | { | |
4c4b4cd2 PH |
2426 | case OP_FUNCALL: |
2427 | if (exp->elts[pc + 3].opcode == OP_VAR_VALUE | |
2428 | && SYMBOL_DOMAIN (exp->elts[pc + 5].symbol) == UNDEF_DOMAIN) | |
2429 | *pos += 7; | |
2430 | else | |
2431 | { | |
2432 | *pos += 3; | |
2433 | resolve_subexp (expp, pos, 0, NULL); | |
2434 | } | |
2435 | nargs = longest_to_int (exp->elts[pc + 1].longconst); | |
14f9c5c9 AS |
2436 | break; |
2437 | ||
4c4b4cd2 PH |
2438 | case UNOP_QUAL: |
2439 | *pos += 3; | |
2440 | resolve_subexp (expp, pos, 1, exp->elts[pc + 1].type); | |
14f9c5c9 AS |
2441 | break; |
2442 | ||
14f9c5c9 | 2443 | case UNOP_ADDR: |
4c4b4cd2 PH |
2444 | *pos += 1; |
2445 | resolve_subexp (expp, pos, 0, NULL); | |
2446 | break; | |
2447 | ||
2448 | case OP_ATR_MODULUS: | |
2449 | *pos += 4; | |
2450 | break; | |
2451 | ||
2452 | case OP_ATR_SIZE: | |
2453 | case OP_ATR_TAG: | |
2454 | *pos += 1; | |
14f9c5c9 | 2455 | nargs = 1; |
4c4b4cd2 PH |
2456 | break; |
2457 | ||
2458 | case OP_ATR_FIRST: | |
2459 | case OP_ATR_LAST: | |
2460 | case OP_ATR_LENGTH: | |
2461 | case OP_ATR_POS: | |
2462 | case OP_ATR_VAL: | |
14f9c5c9 | 2463 | *pos += 1; |
4c4b4cd2 PH |
2464 | nargs = 2; |
2465 | break; | |
2466 | ||
2467 | case OP_ATR_MIN: | |
2468 | case OP_ATR_MAX: | |
2469 | *pos += 1; | |
2470 | nargs = 3; | |
14f9c5c9 AS |
2471 | break; |
2472 | ||
2473 | case BINOP_ASSIGN: | |
2474 | { | |
4c4b4cd2 PH |
2475 | struct value *arg1; |
2476 | ||
2477 | *pos += 1; | |
2478 | arg1 = resolve_subexp (expp, pos, 0, NULL); | |
2479 | if (arg1 == NULL) | |
2480 | resolve_subexp (expp, pos, 1, NULL); | |
2481 | else | |
2482 | resolve_subexp (expp, pos, 1, VALUE_TYPE (arg1)); | |
2483 | break; | |
14f9c5c9 AS |
2484 | } |
2485 | ||
4c4b4cd2 PH |
2486 | case UNOP_CAST: |
2487 | case UNOP_IN_RANGE: | |
2488 | *pos += 3; | |
2489 | nargs = 1; | |
2490 | break; | |
14f9c5c9 | 2491 | |
4c4b4cd2 PH |
2492 | case BINOP_ADD: |
2493 | case BINOP_SUB: | |
2494 | case BINOP_MUL: | |
2495 | case BINOP_DIV: | |
2496 | case BINOP_REM: | |
2497 | case BINOP_MOD: | |
2498 | case BINOP_EXP: | |
2499 | case BINOP_CONCAT: | |
2500 | case BINOP_LOGICAL_AND: | |
2501 | case BINOP_LOGICAL_OR: | |
2502 | case BINOP_BITWISE_AND: | |
2503 | case BINOP_BITWISE_IOR: | |
2504 | case BINOP_BITWISE_XOR: | |
14f9c5c9 | 2505 | |
4c4b4cd2 PH |
2506 | case BINOP_EQUAL: |
2507 | case BINOP_NOTEQUAL: | |
2508 | case BINOP_LESS: | |
2509 | case BINOP_GTR: | |
2510 | case BINOP_LEQ: | |
2511 | case BINOP_GEQ: | |
14f9c5c9 | 2512 | |
4c4b4cd2 PH |
2513 | case BINOP_REPEAT: |
2514 | case BINOP_SUBSCRIPT: | |
2515 | case BINOP_COMMA: | |
2516 | *pos += 1; | |
2517 | nargs = 2; | |
2518 | break; | |
14f9c5c9 | 2519 | |
4c4b4cd2 PH |
2520 | case UNOP_NEG: |
2521 | case UNOP_PLUS: | |
2522 | case UNOP_LOGICAL_NOT: | |
2523 | case UNOP_ABS: | |
2524 | case UNOP_IND: | |
2525 | *pos += 1; | |
2526 | nargs = 1; | |
2527 | break; | |
14f9c5c9 | 2528 | |
4c4b4cd2 PH |
2529 | case OP_LONG: |
2530 | case OP_DOUBLE: | |
2531 | case OP_VAR_VALUE: | |
2532 | *pos += 4; | |
2533 | break; | |
14f9c5c9 | 2534 | |
4c4b4cd2 PH |
2535 | case OP_TYPE: |
2536 | case OP_BOOL: | |
2537 | case OP_LAST: | |
2538 | case OP_REGISTER: | |
2539 | case OP_INTERNALVAR: | |
2540 | *pos += 3; | |
2541 | break; | |
14f9c5c9 | 2542 | |
4c4b4cd2 PH |
2543 | case UNOP_MEMVAL: |
2544 | *pos += 3; | |
2545 | nargs = 1; | |
2546 | break; | |
2547 | ||
2548 | case STRUCTOP_STRUCT: | |
2549 | *pos += 4 + BYTES_TO_EXP_ELEM (exp->elts[pc + 1].longconst + 1); | |
2550 | nargs = 1; | |
2551 | break; | |
2552 | ||
2553 | case OP_STRING: | |
2554 | (*pos) += 3 | |
2555 | + BYTES_TO_EXP_ELEM (longest_to_int (exp->elts[pc + 1].longconst) + 1); | |
2556 | break; | |
2557 | ||
2558 | case TERNOP_SLICE: | |
2559 | case TERNOP_IN_RANGE: | |
2560 | *pos += 1; | |
2561 | nargs = 3; | |
2562 | break; | |
2563 | ||
2564 | case BINOP_IN_BOUNDS: | |
2565 | *pos += 3; | |
2566 | nargs = 2; | |
14f9c5c9 | 2567 | break; |
4c4b4cd2 PH |
2568 | |
2569 | default: | |
2570 | error ("Unexpected operator during name resolution"); | |
14f9c5c9 AS |
2571 | } |
2572 | ||
4c4b4cd2 PH |
2573 | argvec = |
2574 | (struct value * *) alloca (sizeof (struct value *) * (nargs + 1)); | |
2575 | for (i = 0; i < nargs; i += 1) | |
2576 | argvec[i] = resolve_subexp (expp, pos, 1, NULL); | |
2577 | argvec[i] = NULL; | |
2578 | exp = *expp; | |
2579 | ||
2580 | /* Pass two: perform any resolution on principal operator. */ | |
14f9c5c9 AS |
2581 | switch (op) |
2582 | { | |
2583 | default: | |
2584 | break; | |
2585 | ||
14f9c5c9 | 2586 | case OP_VAR_VALUE: |
4c4b4cd2 PH |
2587 | if (SYMBOL_DOMAIN (exp->elts[pc + 2].symbol) == UNDEF_DOMAIN) |
2588 | { | |
2589 | struct ada_symbol_info *candidates; | |
2590 | int n_candidates; | |
2591 | ||
2592 | n_candidates = | |
2593 | ada_lookup_symbol_list (SYMBOL_LINKAGE_NAME (exp->elts[pc + 2] | |
2594 | .symbol), | |
2595 | exp->elts[pc + 1].block, | |
2596 | VAR_DOMAIN, &candidates); | |
2597 | ||
2598 | if (n_candidates > 1) | |
2599 | { | |
2600 | /* Types tend to get re-introduced locally, so if there | |
2601 | are any local symbols that are not types, first filter | |
2602 | out all types. */ | |
2603 | int j; | |
2604 | for (j = 0; j < n_candidates; j += 1) | |
2605 | switch (SYMBOL_CLASS (candidates[j].sym)) | |
2606 | { | |
2607 | case LOC_REGISTER: | |
2608 | case LOC_ARG: | |
2609 | case LOC_REF_ARG: | |
2610 | case LOC_REGPARM: | |
2611 | case LOC_REGPARM_ADDR: | |
2612 | case LOC_LOCAL: | |
2613 | case LOC_LOCAL_ARG: | |
2614 | case LOC_BASEREG: | |
2615 | case LOC_BASEREG_ARG: | |
2616 | case LOC_COMPUTED: | |
2617 | case LOC_COMPUTED_ARG: | |
2618 | goto FoundNonType; | |
2619 | default: | |
2620 | break; | |
2621 | } | |
2622 | FoundNonType: | |
2623 | if (j < n_candidates) | |
2624 | { | |
2625 | j = 0; | |
2626 | while (j < n_candidates) | |
2627 | { | |
2628 | if (SYMBOL_CLASS (candidates[j].sym) == LOC_TYPEDEF) | |
2629 | { | |
2630 | candidates[j] = candidates[n_candidates - 1]; | |
2631 | n_candidates -= 1; | |
2632 | } | |
2633 | else | |
2634 | j += 1; | |
2635 | } | |
2636 | } | |
2637 | } | |
2638 | ||
2639 | if (n_candidates == 0) | |
2640 | error ("No definition found for %s", | |
2641 | SYMBOL_PRINT_NAME (exp->elts[pc + 2].symbol)); | |
2642 | else if (n_candidates == 1) | |
2643 | i = 0; | |
2644 | else if (deprocedure_p | |
2645 | && !is_nonfunction (candidates, n_candidates)) | |
2646 | { | |
2647 | i = ada_resolve_function (candidates, n_candidates, NULL, 0, | |
2648 | SYMBOL_LINKAGE_NAME (exp->elts[pc + 2] | |
2649 | .symbol), | |
2650 | context_type); | |
2651 | if (i < 0) | |
2652 | error ("Could not find a match for %s", | |
2653 | SYMBOL_PRINT_NAME (exp->elts[pc + 2].symbol)); | |
2654 | } | |
2655 | else | |
2656 | { | |
2657 | printf_filtered ("Multiple matches for %s\n", | |
2658 | SYMBOL_PRINT_NAME (exp->elts[pc + 2].symbol)); | |
2659 | user_select_syms (candidates, n_candidates, 1); | |
2660 | i = 0; | |
2661 | } | |
2662 | ||
2663 | exp->elts[pc + 1].block = candidates[i].block; | |
2664 | exp->elts[pc + 2].symbol = candidates[i].sym; | |
2665 | if (innermost_block == NULL || | |
2666 | contained_in (candidates[i].block, innermost_block)) | |
2667 | innermost_block = candidates[i].block; | |
2668 | } | |
2669 | ||
2670 | if (deprocedure_p | |
2671 | && (TYPE_CODE (SYMBOL_TYPE (exp->elts[pc + 2].symbol)) | |
2672 | == TYPE_CODE_FUNC)) | |
14f9c5c9 | 2673 | { |
d2e4a39e AS |
2674 | replace_operator_with_call (expp, pc, 0, 0, |
2675 | exp->elts[pc + 2].symbol, | |
2676 | exp->elts[pc + 1].block); | |
14f9c5c9 AS |
2677 | exp = *expp; |
2678 | } | |
2679 | break; | |
2680 | ||
2681 | case OP_FUNCALL: | |
2682 | { | |
4c4b4cd2 PH |
2683 | if (exp->elts[pc + 3].opcode == OP_VAR_VALUE |
2684 | && SYMBOL_DOMAIN (exp->elts[pc + 5].symbol) == UNDEF_DOMAIN) | |
2685 | { | |
2686 | struct ada_symbol_info *candidates; | |
2687 | int n_candidates; | |
2688 | ||
2689 | n_candidates = | |
2690 | ada_lookup_symbol_list (SYMBOL_LINKAGE_NAME (exp->elts[pc + 5] | |
2691 | .symbol), | |
2692 | exp->elts[pc + 4].block, | |
2693 | VAR_DOMAIN, &candidates); | |
2694 | if (n_candidates == 1) | |
2695 | i = 0; | |
2696 | else | |
2697 | { | |
2698 | i = ada_resolve_function (candidates, n_candidates, | |
2699 | argvec, nargs, | |
2700 | SYMBOL_LINKAGE_NAME (exp->elts[pc+5] | |
2701 | .symbol), | |
2702 | context_type); | |
2703 | if (i < 0) | |
2704 | error ("Could not find a match for %s", | |
2705 | SYMBOL_PRINT_NAME (exp->elts[pc + 5].symbol)); | |
2706 | } | |
2707 | ||
2708 | exp->elts[pc + 4].block = candidates[i].block; | |
2709 | exp->elts[pc + 5].symbol = candidates[i].sym; | |
2710 | if (innermost_block == NULL || | |
2711 | contained_in (candidates[i].block, innermost_block)) | |
2712 | innermost_block = candidates[i].block; | |
2713 | } | |
14f9c5c9 AS |
2714 | } |
2715 | break; | |
2716 | case BINOP_ADD: | |
2717 | case BINOP_SUB: | |
2718 | case BINOP_MUL: | |
2719 | case BINOP_DIV: | |
2720 | case BINOP_REM: | |
2721 | case BINOP_MOD: | |
2722 | case BINOP_CONCAT: | |
2723 | case BINOP_BITWISE_AND: | |
2724 | case BINOP_BITWISE_IOR: | |
2725 | case BINOP_BITWISE_XOR: | |
2726 | case BINOP_EQUAL: | |
2727 | case BINOP_NOTEQUAL: | |
2728 | case BINOP_LESS: | |
2729 | case BINOP_GTR: | |
2730 | case BINOP_LEQ: | |
2731 | case BINOP_GEQ: | |
2732 | case BINOP_EXP: | |
2733 | case UNOP_NEG: | |
2734 | case UNOP_PLUS: | |
2735 | case UNOP_LOGICAL_NOT: | |
2736 | case UNOP_ABS: | |
2737 | if (possible_user_operator_p (op, argvec)) | |
4c4b4cd2 PH |
2738 | { |
2739 | struct ada_symbol_info *candidates; | |
2740 | int n_candidates; | |
2741 | ||
2742 | n_candidates = | |
2743 | ada_lookup_symbol_list (ada_encode (ada_decoded_op_name (op)), | |
2744 | (struct block *) NULL, VAR_DOMAIN, | |
2745 | &candidates); | |
2746 | i = ada_resolve_function (candidates, n_candidates, argvec, nargs, | |
2747 | ada_decoded_op_name (op), NULL); | |
2748 | if (i < 0) | |
2749 | break; | |
2750 | ||
2751 | replace_operator_with_call (expp, pc, nargs, 1, | |
2752 | candidates[i].sym, candidates[i].block); | |
2753 | exp = *expp; | |
2754 | } | |
14f9c5c9 | 2755 | break; |
4c4b4cd2 PH |
2756 | |
2757 | case OP_TYPE: | |
2758 | return NULL; | |
14f9c5c9 AS |
2759 | } |
2760 | ||
2761 | *pos = pc; | |
2762 | return evaluate_subexp_type (exp, pos); | |
2763 | } | |
2764 | ||
2765 | /* Return non-zero if formal type FTYPE matches actual type ATYPE. If | |
4c4b4cd2 PH |
2766 | MAY_DEREF is non-zero, the formal may be a pointer and the actual |
2767 | a non-pointer. A type of 'void' (which is never a valid expression type) | |
2768 | by convention matches anything. */ | |
14f9c5c9 | 2769 | /* The term "match" here is rather loose. The match is heuristic and |
4c4b4cd2 | 2770 | liberal. FIXME: TOO liberal, in fact. */ |
14f9c5c9 AS |
2771 | |
2772 | static int | |
4dc81987 | 2773 | ada_type_match (struct type *ftype, struct type *atype, int may_deref) |
14f9c5c9 AS |
2774 | { |
2775 | CHECK_TYPEDEF (ftype); | |
2776 | CHECK_TYPEDEF (atype); | |
2777 | ||
2778 | if (TYPE_CODE (ftype) == TYPE_CODE_REF) | |
2779 | ftype = TYPE_TARGET_TYPE (ftype); | |
2780 | if (TYPE_CODE (atype) == TYPE_CODE_REF) | |
2781 | atype = TYPE_TARGET_TYPE (atype); | |
2782 | ||
d2e4a39e | 2783 | if (TYPE_CODE (ftype) == TYPE_CODE_VOID |
14f9c5c9 AS |
2784 | || TYPE_CODE (atype) == TYPE_CODE_VOID) |
2785 | return 1; | |
2786 | ||
d2e4a39e | 2787 | switch (TYPE_CODE (ftype)) |
14f9c5c9 AS |
2788 | { |
2789 | default: | |
2790 | return 1; | |
2791 | case TYPE_CODE_PTR: | |
2792 | if (TYPE_CODE (atype) == TYPE_CODE_PTR) | |
4c4b4cd2 PH |
2793 | return ada_type_match (TYPE_TARGET_TYPE (ftype), |
2794 | TYPE_TARGET_TYPE (atype), 0); | |
d2e4a39e | 2795 | else |
4c4b4cd2 PH |
2796 | return (may_deref && |
2797 | ada_type_match (TYPE_TARGET_TYPE (ftype), atype, 0)); | |
14f9c5c9 AS |
2798 | case TYPE_CODE_INT: |
2799 | case TYPE_CODE_ENUM: | |
2800 | case TYPE_CODE_RANGE: | |
2801 | switch (TYPE_CODE (atype)) | |
4c4b4cd2 PH |
2802 | { |
2803 | case TYPE_CODE_INT: | |
2804 | case TYPE_CODE_ENUM: | |
2805 | case TYPE_CODE_RANGE: | |
2806 | return 1; | |
2807 | default: | |
2808 | return 0; | |
2809 | } | |
14f9c5c9 AS |
2810 | |
2811 | case TYPE_CODE_ARRAY: | |
d2e4a39e | 2812 | return (TYPE_CODE (atype) == TYPE_CODE_ARRAY |
4c4b4cd2 | 2813 | || ada_is_array_descriptor_type (atype)); |
14f9c5c9 AS |
2814 | |
2815 | case TYPE_CODE_STRUCT: | |
4c4b4cd2 PH |
2816 | if (ada_is_array_descriptor_type (ftype)) |
2817 | return (TYPE_CODE (atype) == TYPE_CODE_ARRAY | |
2818 | || ada_is_array_descriptor_type (atype)); | |
14f9c5c9 | 2819 | else |
4c4b4cd2 PH |
2820 | return (TYPE_CODE (atype) == TYPE_CODE_STRUCT |
2821 | && !ada_is_array_descriptor_type (atype)); | |
14f9c5c9 AS |
2822 | |
2823 | case TYPE_CODE_UNION: | |
2824 | case TYPE_CODE_FLT: | |
2825 | return (TYPE_CODE (atype) == TYPE_CODE (ftype)); | |
2826 | } | |
2827 | } | |
2828 | ||
2829 | /* Return non-zero if the formals of FUNC "sufficiently match" the | |
2830 | vector of actual argument types ACTUALS of size N_ACTUALS. FUNC | |
2831 | may also be an enumeral, in which case it is treated as a 0- | |
4c4b4cd2 | 2832 | argument function. */ |
14f9c5c9 AS |
2833 | |
2834 | static int | |
d2e4a39e | 2835 | ada_args_match (struct symbol *func, struct value **actuals, int n_actuals) |
14f9c5c9 AS |
2836 | { |
2837 | int i; | |
d2e4a39e | 2838 | struct type *func_type = SYMBOL_TYPE (func); |
14f9c5c9 | 2839 | |
d2e4a39e | 2840 | if (SYMBOL_CLASS (func) == LOC_CONST && |
14f9c5c9 AS |
2841 | TYPE_CODE (func_type) == TYPE_CODE_ENUM) |
2842 | return (n_actuals == 0); | |
2843 | else if (func_type == NULL || TYPE_CODE (func_type) != TYPE_CODE_FUNC) | |
2844 | return 0; | |
2845 | ||
2846 | if (TYPE_NFIELDS (func_type) != n_actuals) | |
2847 | return 0; | |
2848 | ||
2849 | for (i = 0; i < n_actuals; i += 1) | |
2850 | { | |
4c4b4cd2 | 2851 | if (actuals[i] == NULL) |
14f9c5c9 | 2852 | return 0; |
4c4b4cd2 PH |
2853 | else |
2854 | { | |
2855 | struct type *ftype = check_typedef (TYPE_FIELD_TYPE (func_type, i)); | |
2856 | struct type *atype = check_typedef (VALUE_TYPE (actuals[i])); | |
2857 | ||
2858 | if (!ada_type_match (ftype, atype, 1)) | |
2859 | return 0; | |
2860 | } | |
14f9c5c9 AS |
2861 | } |
2862 | return 1; | |
2863 | } | |
2864 | ||
2865 | /* False iff function type FUNC_TYPE definitely does not produce a value | |
2866 | compatible with type CONTEXT_TYPE. Conservatively returns 1 if | |
2867 | FUNC_TYPE is not a valid function type with a non-null return type | |
2868 | or an enumerated type. A null CONTEXT_TYPE indicates any non-void type. */ | |
2869 | ||
2870 | static int | |
d2e4a39e | 2871 | return_match (struct type *func_type, struct type *context_type) |
14f9c5c9 | 2872 | { |
d2e4a39e | 2873 | struct type *return_type; |
14f9c5c9 AS |
2874 | |
2875 | if (func_type == NULL) | |
2876 | return 1; | |
2877 | ||
4c4b4cd2 PH |
2878 | if (TYPE_CODE (func_type) == TYPE_CODE_FUNC) |
2879 | return_type = base_type (TYPE_TARGET_TYPE (func_type)); | |
2880 | else | |
2881 | return_type = base_type (func_type); | |
14f9c5c9 AS |
2882 | if (return_type == NULL) |
2883 | return 1; | |
2884 | ||
4c4b4cd2 | 2885 | context_type = base_type (context_type); |
14f9c5c9 AS |
2886 | |
2887 | if (TYPE_CODE (return_type) == TYPE_CODE_ENUM) | |
2888 | return context_type == NULL || return_type == context_type; | |
2889 | else if (context_type == NULL) | |
2890 | return TYPE_CODE (return_type) != TYPE_CODE_VOID; | |
2891 | else | |
2892 | return TYPE_CODE (return_type) == TYPE_CODE (context_type); | |
2893 | } | |
2894 | ||
2895 | ||
4c4b4cd2 | 2896 | /* Returns the index in SYMS[0..NSYMS-1] that contains the symbol for the |
14f9c5c9 | 2897 | function (if any) that matches the types of the NARGS arguments in |
4c4b4cd2 PH |
2898 | ARGS. If CONTEXT_TYPE is non-null and there is at least one match |
2899 | that returns that type, then eliminate matches that don't. If | |
2900 | CONTEXT_TYPE is void and there is at least one match that does not | |
2901 | return void, eliminate all matches that do. | |
2902 | ||
14f9c5c9 AS |
2903 | Asks the user if there is more than one match remaining. Returns -1 |
2904 | if there is no such symbol or none is selected. NAME is used | |
4c4b4cd2 PH |
2905 | solely for messages. May re-arrange and modify SYMS in |
2906 | the process; the index returned is for the modified vector. */ | |
14f9c5c9 | 2907 | |
4c4b4cd2 PH |
2908 | static int |
2909 | ada_resolve_function (struct ada_symbol_info syms[], | |
2910 | int nsyms, struct value **args, int nargs, | |
2911 | const char *name, struct type *context_type) | |
14f9c5c9 AS |
2912 | { |
2913 | int k; | |
4c4b4cd2 | 2914 | int m; /* Number of hits */ |
d2e4a39e AS |
2915 | struct type *fallback; |
2916 | struct type *return_type; | |
14f9c5c9 AS |
2917 | |
2918 | return_type = context_type; | |
2919 | if (context_type == NULL) | |
2920 | fallback = builtin_type_void; | |
2921 | else | |
2922 | fallback = NULL; | |
2923 | ||
d2e4a39e | 2924 | m = 0; |
14f9c5c9 AS |
2925 | while (1) |
2926 | { | |
2927 | for (k = 0; k < nsyms; k += 1) | |
4c4b4cd2 PH |
2928 | { |
2929 | struct type *type = check_typedef (SYMBOL_TYPE (syms[k].sym)); | |
2930 | ||
2931 | if (ada_args_match (syms[k].sym, args, nargs) | |
2932 | && return_match (type, return_type)) | |
2933 | { | |
2934 | syms[m] = syms[k]; | |
2935 | m += 1; | |
2936 | } | |
2937 | } | |
14f9c5c9 | 2938 | if (m > 0 || return_type == fallback) |
4c4b4cd2 | 2939 | break; |
14f9c5c9 | 2940 | else |
4c4b4cd2 | 2941 | return_type = fallback; |
14f9c5c9 AS |
2942 | } |
2943 | ||
2944 | if (m == 0) | |
2945 | return -1; | |
2946 | else if (m > 1) | |
2947 | { | |
2948 | printf_filtered ("Multiple matches for %s\n", name); | |
4c4b4cd2 | 2949 | user_select_syms (syms, m, 1); |
14f9c5c9 AS |
2950 | return 0; |
2951 | } | |
2952 | return 0; | |
2953 | } | |
2954 | ||
4c4b4cd2 PH |
2955 | /* Returns true (non-zero) iff decoded name N0 should appear before N1 |
2956 | in a listing of choices during disambiguation (see sort_choices, below). | |
2957 | The idea is that overloadings of a subprogram name from the | |
2958 | same package should sort in their source order. We settle for ordering | |
2959 | such symbols by their trailing number (__N or $N). */ | |
2960 | ||
14f9c5c9 | 2961 | static int |
4c4b4cd2 | 2962 | encoded_ordered_before (char *N0, char *N1) |
14f9c5c9 AS |
2963 | { |
2964 | if (N1 == NULL) | |
2965 | return 0; | |
2966 | else if (N0 == NULL) | |
2967 | return 1; | |
2968 | else | |
2969 | { | |
2970 | int k0, k1; | |
d2e4a39e | 2971 | for (k0 = strlen (N0) - 1; k0 > 0 && isdigit (N0[k0]); k0 -= 1) |
4c4b4cd2 | 2972 | ; |
d2e4a39e | 2973 | for (k1 = strlen (N1) - 1; k1 > 0 && isdigit (N1[k1]); k1 -= 1) |
4c4b4cd2 | 2974 | ; |
d2e4a39e | 2975 | if ((N0[k0] == '_' || N0[k0] == '$') && N0[k0 + 1] != '\000' |
4c4b4cd2 PH |
2976 | && (N1[k1] == '_' || N1[k1] == '$') && N1[k1 + 1] != '\000') |
2977 | { | |
2978 | int n0, n1; | |
2979 | n0 = k0; | |
2980 | while (N0[n0] == '_' && n0 > 0 && N0[n0 - 1] == '_') | |
2981 | n0 -= 1; | |
2982 | n1 = k1; | |
2983 | while (N1[n1] == '_' && n1 > 0 && N1[n1 - 1] == '_') | |
2984 | n1 -= 1; | |
2985 | if (n0 == n1 && strncmp (N0, N1, n0) == 0) | |
2986 | return (atoi (N0 + k0 + 1) < atoi (N1 + k1 + 1)); | |
2987 | } | |
14f9c5c9 AS |
2988 | return (strcmp (N0, N1) < 0); |
2989 | } | |
2990 | } | |
d2e4a39e | 2991 | |
4c4b4cd2 PH |
2992 | /* Sort SYMS[0..NSYMS-1] to put the choices in a canonical order by the |
2993 | encoded names. */ | |
2994 | ||
d2e4a39e | 2995 | static void |
4c4b4cd2 | 2996 | sort_choices (struct ada_symbol_info syms[], int nsyms) |
14f9c5c9 | 2997 | { |
4c4b4cd2 | 2998 | int i; |
d2e4a39e | 2999 | for (i = 1; i < nsyms; i += 1) |
14f9c5c9 | 3000 | { |
4c4b4cd2 | 3001 | struct ada_symbol_info sym = syms[i]; |
14f9c5c9 AS |
3002 | int j; |
3003 | ||
d2e4a39e | 3004 | for (j = i - 1; j >= 0; j -= 1) |
4c4b4cd2 PH |
3005 | { |
3006 | if (encoded_ordered_before (SYMBOL_LINKAGE_NAME (syms[j].sym), | |
3007 | SYMBOL_LINKAGE_NAME (sym.sym))) | |
3008 | break; | |
3009 | syms[j + 1] = syms[j]; | |
3010 | } | |
d2e4a39e | 3011 | syms[j + 1] = sym; |
14f9c5c9 AS |
3012 | } |
3013 | } | |
3014 | ||
4c4b4cd2 PH |
3015 | /* Given a list of NSYMS symbols in SYMS, select up to MAX_RESULTS>0 |
3016 | by asking the user (if necessary), returning the number selected, | |
3017 | and setting the first elements of SYMS items. Error if no symbols | |
3018 | selected. */ | |
14f9c5c9 AS |
3019 | |
3020 | /* NOTE: Adapted from decode_line_2 in symtab.c, with which it ought | |
4c4b4cd2 | 3021 | to be re-integrated one of these days. */ |
14f9c5c9 AS |
3022 | |
3023 | int | |
4c4b4cd2 | 3024 | user_select_syms (struct ada_symbol_info *syms, int nsyms, int max_results) |
14f9c5c9 AS |
3025 | { |
3026 | int i; | |
d2e4a39e | 3027 | int *chosen = (int *) alloca (sizeof (int) * nsyms); |
14f9c5c9 AS |
3028 | int n_chosen; |
3029 | int first_choice = (max_results == 1) ? 1 : 2; | |
3030 | ||
3031 | if (max_results < 1) | |
3032 | error ("Request to select 0 symbols!"); | |
3033 | if (nsyms <= 1) | |
3034 | return nsyms; | |
3035 | ||
d2e4a39e | 3036 | printf_unfiltered ("[0] cancel\n"); |
14f9c5c9 | 3037 | if (max_results > 1) |
d2e4a39e | 3038 | printf_unfiltered ("[1] all\n"); |
14f9c5c9 | 3039 | |
4c4b4cd2 | 3040 | sort_choices (syms, nsyms); |
14f9c5c9 AS |
3041 | |
3042 | for (i = 0; i < nsyms; i += 1) | |
3043 | { | |
4c4b4cd2 PH |
3044 | if (syms[i].sym == NULL) |
3045 | continue; | |
3046 | ||
3047 | if (SYMBOL_CLASS (syms[i].sym) == LOC_BLOCK) | |
3048 | { | |
3049 | struct symtab_and_line sal = find_function_start_sal (syms[i].sym, 1); | |
3050 | printf_unfiltered ("[%d] %s at %s:%d\n", | |
3051 | i + first_choice, | |
3052 | SYMBOL_PRINT_NAME (syms[i].sym), | |
3053 | sal.symtab == NULL | |
3054 | ? "<no source file available>" | |
3055 | : sal.symtab->filename, sal.line); | |
3056 | continue; | |
3057 | } | |
d2e4a39e | 3058 | else |
4c4b4cd2 PH |
3059 | { |
3060 | int is_enumeral = | |
3061 | (SYMBOL_CLASS (syms[i].sym) == LOC_CONST | |
3062 | && SYMBOL_TYPE (syms[i].sym) != NULL | |
3063 | && TYPE_CODE (SYMBOL_TYPE (syms[i].sym)) == TYPE_CODE_ENUM); | |
3064 | struct symtab *symtab = symtab_for_sym (syms[i].sym); | |
3065 | ||
3066 | if (SYMBOL_LINE (syms[i].sym) != 0 && symtab != NULL) | |
3067 | printf_unfiltered ("[%d] %s at %s:%d\n", | |
3068 | i + first_choice, | |
3069 | SYMBOL_PRINT_NAME (syms[i].sym), | |
3070 | symtab->filename, SYMBOL_LINE (syms[i].sym)); | |
3071 | else if (is_enumeral && TYPE_NAME (SYMBOL_TYPE (syms[i].sym)) != NULL) | |
3072 | { | |
3073 | printf_unfiltered ("[%d] ", i + first_choice); | |
3074 | ada_print_type (SYMBOL_TYPE (syms[i].sym), NULL, | |
3075 | gdb_stdout, -1, 0); | |
3076 | printf_unfiltered ("'(%s) (enumeral)\n", | |
3077 | SYMBOL_PRINT_NAME (syms[i].sym)); | |
3078 | } | |
3079 | else if (symtab != NULL) | |
3080 | printf_unfiltered (is_enumeral | |
3081 | ? "[%d] %s in %s (enumeral)\n" | |
3082 | : "[%d] %s at %s:?\n", | |
3083 | i + first_choice, | |
3084 | SYMBOL_PRINT_NAME (syms[i].sym), | |
3085 | symtab->filename); | |
3086 | else | |
3087 | printf_unfiltered (is_enumeral | |
3088 | ? "[%d] %s (enumeral)\n" | |
3089 | : "[%d] %s at ?\n", | |
3090 | i + first_choice, | |
3091 | SYMBOL_PRINT_NAME (syms[i].sym)); | |
3092 | } | |
14f9c5c9 | 3093 | } |
d2e4a39e | 3094 | |
14f9c5c9 | 3095 | n_chosen = get_selections (chosen, nsyms, max_results, max_results > 1, |
4c4b4cd2 | 3096 | "overload-choice"); |
14f9c5c9 AS |
3097 | |
3098 | for (i = 0; i < n_chosen; i += 1) | |
4c4b4cd2 | 3099 | syms[i] = syms[chosen[i]]; |
14f9c5c9 AS |
3100 | |
3101 | return n_chosen; | |
3102 | } | |
3103 | ||
3104 | /* Read and validate a set of numeric choices from the user in the | |
4c4b4cd2 | 3105 | range 0 .. N_CHOICES-1. Place the results in increasing |
14f9c5c9 AS |
3106 | order in CHOICES[0 .. N-1], and return N. |
3107 | ||
3108 | The user types choices as a sequence of numbers on one line | |
3109 | separated by blanks, encoding them as follows: | |
3110 | ||
4c4b4cd2 | 3111 | + A choice of 0 means to cancel the selection, throwing an error. |
14f9c5c9 AS |
3112 | + If IS_ALL_CHOICE, a choice of 1 selects the entire set 0 .. N_CHOICES-1. |
3113 | + The user chooses k by typing k+IS_ALL_CHOICE+1. | |
3114 | ||
4c4b4cd2 | 3115 | The user is not allowed to choose more than MAX_RESULTS values. |
14f9c5c9 AS |
3116 | |
3117 | ANNOTATION_SUFFIX, if present, is used to annotate the input | |
4c4b4cd2 | 3118 | prompts (for use with the -f switch). */ |
14f9c5c9 AS |
3119 | |
3120 | int | |
d2e4a39e | 3121 | get_selections (int *choices, int n_choices, int max_results, |
4c4b4cd2 | 3122 | int is_all_choice, char *annotation_suffix) |
14f9c5c9 | 3123 | { |
d2e4a39e AS |
3124 | char *args; |
3125 | const char *prompt; | |
14f9c5c9 AS |
3126 | int n_chosen; |
3127 | int first_choice = is_all_choice ? 2 : 1; | |
d2e4a39e | 3128 | |
14f9c5c9 AS |
3129 | prompt = getenv ("PS2"); |
3130 | if (prompt == NULL) | |
3131 | prompt = ">"; | |
3132 | ||
3133 | printf_unfiltered ("%s ", prompt); | |
3134 | gdb_flush (gdb_stdout); | |
3135 | ||
3136 | args = command_line_input ((char *) NULL, 0, annotation_suffix); | |
d2e4a39e | 3137 | |
14f9c5c9 AS |
3138 | if (args == NULL) |
3139 | error_no_arg ("one or more choice numbers"); | |
3140 | ||
3141 | n_chosen = 0; | |
4c4b4cd2 PH |
3142 | |
3143 | /* Set choices[0 .. n_chosen-1] to the users' choices in ascending | |
3144 | order, as given in args. Choices are validated. */ | |
14f9c5c9 AS |
3145 | while (1) |
3146 | { | |
d2e4a39e | 3147 | char *args2; |
14f9c5c9 AS |
3148 | int choice, j; |
3149 | ||
3150 | while (isspace (*args)) | |
4c4b4cd2 | 3151 | args += 1; |
14f9c5c9 | 3152 | if (*args == '\0' && n_chosen == 0) |
4c4b4cd2 | 3153 | error_no_arg ("one or more choice numbers"); |
14f9c5c9 | 3154 | else if (*args == '\0') |
4c4b4cd2 | 3155 | break; |
14f9c5c9 AS |
3156 | |
3157 | choice = strtol (args, &args2, 10); | |
d2e4a39e | 3158 | if (args == args2 || choice < 0 |
4c4b4cd2 PH |
3159 | || choice > n_choices + first_choice - 1) |
3160 | error ("Argument must be choice number"); | |
14f9c5c9 AS |
3161 | args = args2; |
3162 | ||
d2e4a39e | 3163 | if (choice == 0) |
4c4b4cd2 | 3164 | error ("cancelled"); |
14f9c5c9 AS |
3165 | |
3166 | if (choice < first_choice) | |
4c4b4cd2 PH |
3167 | { |
3168 | n_chosen = n_choices; | |
3169 | for (j = 0; j < n_choices; j += 1) | |
3170 | choices[j] = j; | |
3171 | break; | |
3172 | } | |
14f9c5c9 AS |
3173 | choice -= first_choice; |
3174 | ||
d2e4a39e | 3175 | for (j = n_chosen - 1; j >= 0 && choice < choices[j]; j -= 1) |
4c4b4cd2 PH |
3176 | { |
3177 | } | |
14f9c5c9 AS |
3178 | |
3179 | if (j < 0 || choice != choices[j]) | |
4c4b4cd2 PH |
3180 | { |
3181 | int k; | |
3182 | for (k = n_chosen - 1; k > j; k -= 1) | |
3183 | choices[k + 1] = choices[k]; | |
3184 | choices[j + 1] = choice; | |
3185 | n_chosen += 1; | |
3186 | } | |
14f9c5c9 AS |
3187 | } |
3188 | ||
3189 | if (n_chosen > max_results) | |
3190 | error ("Select no more than %d of the above", max_results); | |
d2e4a39e | 3191 | |
14f9c5c9 AS |
3192 | return n_chosen; |
3193 | } | |
3194 | ||
4c4b4cd2 PH |
3195 | /* Replace the operator of length OPLEN at position PC in *EXPP with a call |
3196 | on the function identified by SYM and BLOCK, and taking NARGS | |
3197 | arguments. Update *EXPP as needed to hold more space. */ | |
14f9c5c9 AS |
3198 | |
3199 | static void | |
d2e4a39e | 3200 | replace_operator_with_call (struct expression **expp, int pc, int nargs, |
4c4b4cd2 PH |
3201 | int oplen, struct symbol *sym, |
3202 | struct block *block) | |
14f9c5c9 AS |
3203 | { |
3204 | /* A new expression, with 6 more elements (3 for funcall, 4 for function | |
4c4b4cd2 | 3205 | symbol, -oplen for operator being replaced). */ |
d2e4a39e | 3206 | struct expression *newexp = (struct expression *) |
14f9c5c9 | 3207 | xmalloc (sizeof (struct expression) |
4c4b4cd2 | 3208 | + EXP_ELEM_TO_BYTES ((*expp)->nelts + 7 - oplen)); |
d2e4a39e | 3209 | struct expression *exp = *expp; |
14f9c5c9 AS |
3210 | |
3211 | newexp->nelts = exp->nelts + 7 - oplen; | |
3212 | newexp->language_defn = exp->language_defn; | |
3213 | memcpy (newexp->elts, exp->elts, EXP_ELEM_TO_BYTES (pc)); | |
d2e4a39e | 3214 | memcpy (newexp->elts + pc + 7, exp->elts + pc + oplen, |
4c4b4cd2 | 3215 | EXP_ELEM_TO_BYTES (exp->nelts - pc - oplen)); |
14f9c5c9 AS |
3216 | |
3217 | newexp->elts[pc].opcode = newexp->elts[pc + 2].opcode = OP_FUNCALL; | |
3218 | newexp->elts[pc + 1].longconst = (LONGEST) nargs; | |
3219 | ||
3220 | newexp->elts[pc + 3].opcode = newexp->elts[pc + 6].opcode = OP_VAR_VALUE; | |
3221 | newexp->elts[pc + 4].block = block; | |
3222 | newexp->elts[pc + 5].symbol = sym; | |
3223 | ||
3224 | *expp = newexp; | |
aacb1f0a | 3225 | xfree (exp); |
d2e4a39e | 3226 | } |
14f9c5c9 AS |
3227 | |
3228 | /* Type-class predicates */ | |
3229 | ||
4c4b4cd2 PH |
3230 | /* True iff TYPE is numeric (i.e., an INT, RANGE (of numeric type), |
3231 | or FLOAT). */ | |
14f9c5c9 AS |
3232 | |
3233 | static int | |
d2e4a39e | 3234 | numeric_type_p (struct type *type) |
14f9c5c9 AS |
3235 | { |
3236 | if (type == NULL) | |
3237 | return 0; | |
d2e4a39e AS |
3238 | else |
3239 | { | |
3240 | switch (TYPE_CODE (type)) | |
4c4b4cd2 PH |
3241 | { |
3242 | case TYPE_CODE_INT: | |
3243 | case TYPE_CODE_FLT: | |
3244 | return 1; | |
3245 | case TYPE_CODE_RANGE: | |
3246 | return (type == TYPE_TARGET_TYPE (type) | |
3247 | || numeric_type_p (TYPE_TARGET_TYPE (type))); | |
3248 | default: | |
3249 | return 0; | |
3250 | } | |
d2e4a39e | 3251 | } |
14f9c5c9 AS |
3252 | } |
3253 | ||
4c4b4cd2 | 3254 | /* True iff TYPE is integral (an INT or RANGE of INTs). */ |
14f9c5c9 AS |
3255 | |
3256 | static int | |
d2e4a39e | 3257 | integer_type_p (struct type *type) |
14f9c5c9 AS |
3258 | { |
3259 | if (type == NULL) | |
3260 | return 0; | |
d2e4a39e AS |
3261 | else |
3262 | { | |
3263 | switch (TYPE_CODE (type)) | |
4c4b4cd2 PH |
3264 | { |
3265 | case TYPE_CODE_INT: | |
3266 | return 1; | |
3267 | case TYPE_CODE_RANGE: | |
3268 | return (type == TYPE_TARGET_TYPE (type) | |
3269 | || integer_type_p (TYPE_TARGET_TYPE (type))); | |
3270 | default: | |
3271 | return 0; | |
3272 | } | |
d2e4a39e | 3273 | } |
14f9c5c9 AS |
3274 | } |
3275 | ||
4c4b4cd2 | 3276 | /* True iff TYPE is scalar (INT, RANGE, FLOAT, ENUM). */ |
14f9c5c9 AS |
3277 | |
3278 | static int | |
d2e4a39e | 3279 | scalar_type_p (struct type *type) |
14f9c5c9 AS |
3280 | { |
3281 | if (type == NULL) | |
3282 | return 0; | |
d2e4a39e AS |
3283 | else |
3284 | { | |
3285 | switch (TYPE_CODE (type)) | |
4c4b4cd2 PH |
3286 | { |
3287 | case TYPE_CODE_INT: | |
3288 | case TYPE_CODE_RANGE: | |
3289 | case TYPE_CODE_ENUM: | |
3290 | case TYPE_CODE_FLT: | |
3291 | return 1; | |
3292 | default: | |
3293 | return 0; | |
3294 | } | |
d2e4a39e | 3295 | } |
14f9c5c9 AS |
3296 | } |
3297 | ||
4c4b4cd2 | 3298 | /* True iff TYPE is discrete (INT, RANGE, ENUM). */ |
14f9c5c9 AS |
3299 | |
3300 | static int | |
d2e4a39e | 3301 | discrete_type_p (struct type *type) |
14f9c5c9 AS |
3302 | { |
3303 | if (type == NULL) | |
3304 | return 0; | |
d2e4a39e AS |
3305 | else |
3306 | { | |
3307 | switch (TYPE_CODE (type)) | |
4c4b4cd2 PH |
3308 | { |
3309 | case TYPE_CODE_INT: | |
3310 | case TYPE_CODE_RANGE: | |
3311 | case TYPE_CODE_ENUM: | |
3312 | return 1; | |
3313 | default: | |
3314 | return 0; | |
3315 | } | |
d2e4a39e | 3316 | } |
14f9c5c9 AS |
3317 | } |
3318 | ||
4c4b4cd2 PH |
3319 | /* Returns non-zero if OP with operands in the vector ARGS could be |
3320 | a user-defined function. Errs on the side of pre-defined operators | |
3321 | (i.e., result 0). */ | |
14f9c5c9 AS |
3322 | |
3323 | static int | |
d2e4a39e | 3324 | possible_user_operator_p (enum exp_opcode op, struct value *args[]) |
14f9c5c9 | 3325 | { |
4c4b4cd2 PH |
3326 | struct type *type0 = |
3327 | (args[0] == NULL) ? NULL : check_typedef (VALUE_TYPE (args[0])); | |
d2e4a39e | 3328 | struct type *type1 = |
14f9c5c9 | 3329 | (args[1] == NULL) ? NULL : check_typedef (VALUE_TYPE (args[1])); |
d2e4a39e | 3330 | |
4c4b4cd2 PH |
3331 | if (type0 == NULL) |
3332 | return 0; | |
3333 | ||
14f9c5c9 AS |
3334 | switch (op) |
3335 | { | |
3336 | default: | |
3337 | return 0; | |
3338 | ||
3339 | case BINOP_ADD: | |
3340 | case BINOP_SUB: | |
3341 | case BINOP_MUL: | |
3342 | case BINOP_DIV: | |
d2e4a39e | 3343 | return (!(numeric_type_p (type0) && numeric_type_p (type1))); |
14f9c5c9 AS |
3344 | |
3345 | case BINOP_REM: | |
3346 | case BINOP_MOD: | |
3347 | case BINOP_BITWISE_AND: | |
3348 | case BINOP_BITWISE_IOR: | |
3349 | case BINOP_BITWISE_XOR: | |
d2e4a39e | 3350 | return (!(integer_type_p (type0) && integer_type_p (type1))); |
14f9c5c9 AS |
3351 | |
3352 | case BINOP_EQUAL: | |
3353 | case BINOP_NOTEQUAL: | |
3354 | case BINOP_LESS: | |
3355 | case BINOP_GTR: | |
3356 | case BINOP_LEQ: | |
3357 | case BINOP_GEQ: | |
d2e4a39e | 3358 | return (!(scalar_type_p (type0) && scalar_type_p (type1))); |
14f9c5c9 AS |
3359 | |
3360 | case BINOP_CONCAT: | |
d2e4a39e | 3361 | return ((TYPE_CODE (type0) != TYPE_CODE_ARRAY && |
4c4b4cd2 PH |
3362 | (TYPE_CODE (type0) != TYPE_CODE_PTR || |
3363 | TYPE_CODE (TYPE_TARGET_TYPE (type0)) | |
3364 | != TYPE_CODE_ARRAY)) | |
3365 | || (TYPE_CODE (type1) != TYPE_CODE_ARRAY && | |
3366 | (TYPE_CODE (type1) != TYPE_CODE_PTR || | |
3367 | TYPE_CODE (TYPE_TARGET_TYPE (type1)) != TYPE_CODE_ARRAY))); | |
14f9c5c9 AS |
3368 | |
3369 | case BINOP_EXP: | |
d2e4a39e | 3370 | return (!(numeric_type_p (type0) && integer_type_p (type1))); |
14f9c5c9 AS |
3371 | |
3372 | case UNOP_NEG: | |
3373 | case UNOP_PLUS: | |
3374 | case UNOP_LOGICAL_NOT: | |
d2e4a39e AS |
3375 | case UNOP_ABS: |
3376 | return (!numeric_type_p (type0)); | |
14f9c5c9 AS |
3377 | |
3378 | } | |
3379 | } | |
3380 | \f | |
4c4b4cd2 | 3381 | /* Renaming */ |
14f9c5c9 | 3382 | |
4c4b4cd2 PH |
3383 | /* NOTE: In the following, we assume that a renaming type's name may |
3384 | have an ___XD suffix. It would be nice if this went away at some | |
3385 | point. */ | |
14f9c5c9 AS |
3386 | |
3387 | /* If TYPE encodes a renaming, returns the renaming suffix, which | |
4c4b4cd2 PH |
3388 | is XR for an object renaming, XRP for a procedure renaming, XRE for |
3389 | an exception renaming, and XRS for a subprogram renaming. Returns | |
3390 | NULL if NAME encodes none of these. */ | |
3391 | ||
d2e4a39e AS |
3392 | const char * |
3393 | ada_renaming_type (struct type *type) | |
14f9c5c9 AS |
3394 | { |
3395 | if (type != NULL && TYPE_CODE (type) == TYPE_CODE_ENUM) | |
3396 | { | |
d2e4a39e AS |
3397 | const char *name = type_name_no_tag (type); |
3398 | const char *suffix = (name == NULL) ? NULL : strstr (name, "___XR"); | |
3399 | if (suffix == NULL | |
4c4b4cd2 PH |
3400 | || (suffix[5] != '\000' && strchr ("PES_", suffix[5]) == NULL)) |
3401 | return NULL; | |
14f9c5c9 | 3402 | else |
4c4b4cd2 | 3403 | return suffix + 3; |
14f9c5c9 AS |
3404 | } |
3405 | else | |
3406 | return NULL; | |
3407 | } | |
3408 | ||
4c4b4cd2 PH |
3409 | /* Return non-zero iff SYM encodes an object renaming. */ |
3410 | ||
14f9c5c9 | 3411 | int |
d2e4a39e | 3412 | ada_is_object_renaming (struct symbol *sym) |
14f9c5c9 | 3413 | { |
d2e4a39e AS |
3414 | const char *renaming_type = ada_renaming_type (SYMBOL_TYPE (sym)); |
3415 | return renaming_type != NULL | |
14f9c5c9 AS |
3416 | && (renaming_type[2] == '\0' || renaming_type[2] == '_'); |
3417 | } | |
3418 | ||
3419 | /* Assuming that SYM encodes a non-object renaming, returns the original | |
4c4b4cd2 PH |
3420 | name of the renamed entity. The name is good until the end of |
3421 | parsing. */ | |
3422 | ||
3423 | char * | |
d2e4a39e | 3424 | ada_simple_renamed_entity (struct symbol *sym) |
14f9c5c9 | 3425 | { |
d2e4a39e AS |
3426 | struct type *type; |
3427 | const char *raw_name; | |
14f9c5c9 | 3428 | int len; |
d2e4a39e | 3429 | char *result; |
14f9c5c9 AS |
3430 | |
3431 | type = SYMBOL_TYPE (sym); | |
3432 | if (type == NULL || TYPE_NFIELDS (type) < 1) | |
3433 | error ("Improperly encoded renaming."); | |
3434 | ||
3435 | raw_name = TYPE_FIELD_NAME (type, 0); | |
3436 | len = (raw_name == NULL ? 0 : strlen (raw_name)) - 5; | |
3437 | if (len <= 0) | |
3438 | error ("Improperly encoded renaming."); | |
3439 | ||
3440 | result = xmalloc (len + 1); | |
14f9c5c9 AS |
3441 | strncpy (result, raw_name, len); |
3442 | result[len] = '\000'; | |
3443 | return result; | |
3444 | } | |
14f9c5c9 | 3445 | \f |
d2e4a39e | 3446 | |
4c4b4cd2 | 3447 | /* Evaluation: Function Calls */ |
14f9c5c9 | 3448 | |
4c4b4cd2 PH |
3449 | /* Return an lvalue containing the value VAL. This is the identity on |
3450 | lvalues, and otherwise has the side-effect of pushing a copy of VAL | |
3451 | on the stack, using and updating *SP as the stack pointer, and | |
3452 | returning an lvalue whose VALUE_ADDRESS points to the copy. */ | |
14f9c5c9 | 3453 | |
d2e4a39e | 3454 | static struct value * |
4c4b4cd2 | 3455 | ensure_lval (struct value *val, CORE_ADDR *sp) |
14f9c5c9 AS |
3456 | { |
3457 | CORE_ADDR old_sp = *sp; | |
3458 | ||
4c4b4cd2 PH |
3459 | if (VALUE_LVAL (val)) |
3460 | return val; | |
3461 | ||
3462 | if (DEPRECATED_STACK_ALIGN_P ()) | |
3463 | *sp = push_bytes (*sp, VALUE_CONTENTS_RAW (val), | |
3464 | DEPRECATED_STACK_ALIGN | |
3465 | (TYPE_LENGTH (check_typedef (VALUE_TYPE (val))))); | |
3466 | else | |
3467 | *sp = push_bytes (*sp, VALUE_CONTENTS_RAW (val), | |
3468 | TYPE_LENGTH (check_typedef (VALUE_TYPE (val)))); | |
14f9c5c9 AS |
3469 | |
3470 | VALUE_LVAL (val) = lval_memory; | |
3471 | if (INNER_THAN (1, 2)) | |
3472 | VALUE_ADDRESS (val) = *sp; | |
3473 | else | |
3474 | VALUE_ADDRESS (val) = old_sp; | |
3475 | ||
3476 | return val; | |
3477 | } | |
3478 | ||
3479 | /* Return the value ACTUAL, converted to be an appropriate value for a | |
3480 | formal of type FORMAL_TYPE. Use *SP as a stack pointer for | |
3481 | allocating any necessary descriptors (fat pointers), or copies of | |
4c4b4cd2 | 3482 | values not residing in memory, updating it as needed. */ |
14f9c5c9 | 3483 | |
d2e4a39e AS |
3484 | static struct value * |
3485 | convert_actual (struct value *actual, struct type *formal_type0, | |
4c4b4cd2 | 3486 | CORE_ADDR *sp) |
14f9c5c9 | 3487 | { |
d2e4a39e AS |
3488 | struct type *actual_type = check_typedef (VALUE_TYPE (actual)); |
3489 | struct type *formal_type = check_typedef (formal_type0); | |
3490 | struct type *formal_target = | |
3491 | TYPE_CODE (formal_type) == TYPE_CODE_PTR | |
3492 | ? check_typedef (TYPE_TARGET_TYPE (formal_type)) : formal_type; | |
3493 | struct type *actual_target = | |
3494 | TYPE_CODE (actual_type) == TYPE_CODE_PTR | |
3495 | ? check_typedef (TYPE_TARGET_TYPE (actual_type)) : actual_type; | |
14f9c5c9 | 3496 | |
4c4b4cd2 | 3497 | if (ada_is_array_descriptor_type (formal_target) |
14f9c5c9 AS |
3498 | && TYPE_CODE (actual_target) == TYPE_CODE_ARRAY) |
3499 | return make_array_descriptor (formal_type, actual, sp); | |
3500 | else if (TYPE_CODE (formal_type) == TYPE_CODE_PTR) | |
3501 | { | |
3502 | if (TYPE_CODE (formal_target) == TYPE_CODE_ARRAY | |
4c4b4cd2 PH |
3503 | && ada_is_array_descriptor_type (actual_target)) |
3504 | return desc_data (actual); | |
14f9c5c9 | 3505 | else if (TYPE_CODE (actual_type) != TYPE_CODE_PTR) |
4c4b4cd2 PH |
3506 | { |
3507 | if (VALUE_LVAL (actual) != lval_memory) | |
3508 | { | |
3509 | struct value *val; | |
3510 | actual_type = check_typedef (VALUE_TYPE (actual)); | |
3511 | val = allocate_value (actual_type); | |
3512 | memcpy ((char *) VALUE_CONTENTS_RAW (val), | |
3513 | (char *) VALUE_CONTENTS (actual), | |
3514 | TYPE_LENGTH (actual_type)); | |
3515 | actual = ensure_lval (val, sp); | |
3516 | } | |
3517 | return value_addr (actual); | |
3518 | } | |
14f9c5c9 AS |
3519 | } |
3520 | else if (TYPE_CODE (actual_type) == TYPE_CODE_PTR) | |
3521 | return ada_value_ind (actual); | |
3522 | ||
3523 | return actual; | |
3524 | } | |
3525 | ||
3526 | ||
4c4b4cd2 PH |
3527 | /* Push a descriptor of type TYPE for array value ARR on the stack at |
3528 | *SP, updating *SP to reflect the new descriptor. Return either | |
14f9c5c9 | 3529 | an lvalue representing the new descriptor, or (if TYPE is a pointer- |
4c4b4cd2 PH |
3530 | to-descriptor type rather than a descriptor type), a struct value * |
3531 | representing a pointer to this descriptor. */ | |
14f9c5c9 | 3532 | |
d2e4a39e AS |
3533 | static struct value * |
3534 | make_array_descriptor (struct type *type, struct value *arr, CORE_ADDR *sp) | |
14f9c5c9 | 3535 | { |
d2e4a39e AS |
3536 | struct type *bounds_type = desc_bounds_type (type); |
3537 | struct type *desc_type = desc_base_type (type); | |
3538 | struct value *descriptor = allocate_value (desc_type); | |
3539 | struct value *bounds = allocate_value (bounds_type); | |
14f9c5c9 | 3540 | int i; |
d2e4a39e | 3541 | |
14f9c5c9 AS |
3542 | for (i = ada_array_arity (check_typedef (VALUE_TYPE (arr))); i > 0; i -= 1) |
3543 | { | |
3544 | modify_general_field (VALUE_CONTENTS (bounds), | |
4c4b4cd2 PH |
3545 | value_as_long (ada_array_bound (arr, i, 0)), |
3546 | desc_bound_bitpos (bounds_type, i, 0), | |
3547 | desc_bound_bitsize (bounds_type, i, 0)); | |
14f9c5c9 | 3548 | modify_general_field (VALUE_CONTENTS (bounds), |
4c4b4cd2 PH |
3549 | value_as_long (ada_array_bound (arr, i, 1)), |
3550 | desc_bound_bitpos (bounds_type, i, 1), | |
3551 | desc_bound_bitsize (bounds_type, i, 1)); | |
14f9c5c9 | 3552 | } |
d2e4a39e | 3553 | |
4c4b4cd2 | 3554 | bounds = ensure_lval (bounds, sp); |
d2e4a39e | 3555 | |
14f9c5c9 | 3556 | modify_general_field (VALUE_CONTENTS (descriptor), |
4c4b4cd2 | 3557 | VALUE_ADDRESS (ensure_lval (arr, sp)), |
14f9c5c9 AS |
3558 | fat_pntr_data_bitpos (desc_type), |
3559 | fat_pntr_data_bitsize (desc_type)); | |
4c4b4cd2 | 3560 | |
14f9c5c9 | 3561 | modify_general_field (VALUE_CONTENTS (descriptor), |
4c4b4cd2 PH |
3562 | VALUE_ADDRESS (bounds), |
3563 | fat_pntr_bounds_bitpos (desc_type), | |
3564 | fat_pntr_bounds_bitsize (desc_type)); | |
14f9c5c9 | 3565 | |
4c4b4cd2 | 3566 | descriptor = ensure_lval (descriptor, sp); |
14f9c5c9 AS |
3567 | |
3568 | if (TYPE_CODE (type) == TYPE_CODE_PTR) | |
3569 | return value_addr (descriptor); | |
3570 | else | |
3571 | return descriptor; | |
3572 | } | |
3573 | ||
3574 | ||
4c4b4cd2 | 3575 | /* Assuming a dummy frame has been established on the target, perform any |
14f9c5c9 | 3576 | conversions needed for calling function FUNC on the NARGS actual |
4c4b4cd2 | 3577 | parameters in ARGS, other than standard C conversions. Does |
14f9c5c9 | 3578 | nothing if FUNC does not have Ada-style prototype data, or if NARGS |
4c4b4cd2 | 3579 | does not match the number of arguments expected. Use *SP as a |
14f9c5c9 | 3580 | stack pointer for additional data that must be pushed, updating its |
4c4b4cd2 | 3581 | value as needed. */ |
14f9c5c9 AS |
3582 | |
3583 | void | |
d2e4a39e | 3584 | ada_convert_actuals (struct value *func, int nargs, struct value *args[], |
4c4b4cd2 | 3585 | CORE_ADDR *sp) |
14f9c5c9 AS |
3586 | { |
3587 | int i; | |
3588 | ||
d2e4a39e | 3589 | if (TYPE_NFIELDS (VALUE_TYPE (func)) == 0 |
14f9c5c9 AS |
3590 | || nargs != TYPE_NFIELDS (VALUE_TYPE (func))) |
3591 | return; | |
3592 | ||
3593 | for (i = 0; i < nargs; i += 1) | |
d2e4a39e AS |
3594 | args[i] = |
3595 | convert_actual (args[i], TYPE_FIELD_TYPE (VALUE_TYPE (func), i), sp); | |
14f9c5c9 | 3596 | } |
14f9c5c9 | 3597 | \f |
4c4b4cd2 | 3598 | /* Experimental Symbol Cache Module */ |
d2e4a39e | 3599 | |
4c4b4cd2 PH |
3600 | /* This section implements a simple, fixed-sized hash table for those |
3601 | Ada-mode symbols that get looked up in the course of executing the user's | |
3602 | commands. The size is fixed on the grounds that there are not | |
3603 | likely to be all that many symbols looked up during any given | |
3604 | session, regardless of the size of the symbol table. If we decide | |
3605 | to go to a resizable table, let's just use the stuff from libiberty | |
3606 | instead. */ | |
14f9c5c9 | 3607 | |
4c4b4cd2 | 3608 | #define HASH_SIZE 1009 |
14f9c5c9 | 3609 | |
4c4b4cd2 PH |
3610 | struct cache_entry { |
3611 | const char *name; | |
3612 | domain_enum namespace; | |
3613 | struct symbol *sym; | |
3614 | struct symtab *symtab; | |
3615 | struct block *block; | |
3616 | struct cache_entry *next; | |
3617 | }; | |
14f9c5c9 | 3618 | |
4c4b4cd2 | 3619 | static struct obstack cache_space; |
14f9c5c9 | 3620 | |
4c4b4cd2 | 3621 | static struct cache_entry *cache[HASH_SIZE]; |
14f9c5c9 | 3622 | |
4c4b4cd2 | 3623 | /* Clear all entries from the symbol cache. */ |
14f9c5c9 | 3624 | |
4c4b4cd2 PH |
3625 | void |
3626 | clear_ada_sym_cache (void) | |
3627 | { | |
3628 | obstack_free (&cache_space, NULL); | |
3629 | obstack_init (&cache_space); | |
3630 | memset (cache, '\000', sizeof (cache)); | |
3631 | } | |
14f9c5c9 | 3632 | |
4c4b4cd2 PH |
3633 | static struct cache_entry ** |
3634 | find_entry (const char *name, domain_enum namespace) | |
14f9c5c9 | 3635 | { |
4c4b4cd2 PH |
3636 | int h = msymbol_hash (name) % HASH_SIZE; |
3637 | struct cache_entry **e; | |
3638 | for (e = &cache[h]; *e != NULL; e = &(*e)->next) | |
3639 | { | |
3640 | if (namespace == (*e)->namespace && strcmp (name, (*e)->name) == 0) | |
3641 | return e; | |
3642 | } | |
3643 | return NULL; | |
14f9c5c9 | 3644 | } |
d2e4a39e | 3645 | |
4c4b4cd2 PH |
3646 | /* Return (in SYM) the last cached definition for global or static symbol NAME |
3647 | in namespace DOMAIN. Returns 1 if entry found, 0 otherwise. | |
3648 | If SYMTAB is non-NULL, store the symbol | |
3649 | table in which the symbol was found there, or NULL if not found. | |
3650 | *BLOCK is set to the block in which NAME is found. */ | |
14f9c5c9 | 3651 | |
14f9c5c9 | 3652 | static int |
4c4b4cd2 PH |
3653 | lookup_cached_symbol (const char *name, domain_enum namespace, |
3654 | struct symbol **sym, struct block **block, | |
3655 | struct symtab **symtab) | |
14f9c5c9 | 3656 | { |
4c4b4cd2 PH |
3657 | struct cache_entry **e = find_entry (name, namespace); |
3658 | if (e == NULL) | |
3659 | return 0; | |
3660 | if (sym != NULL) | |
3661 | *sym = (*e)->sym; | |
3662 | if (block != NULL) | |
3663 | *block = (*e)->block; | |
3664 | if (symtab != NULL) | |
3665 | *symtab = (*e)->symtab; | |
3666 | return 1; | |
3667 | } | |
14f9c5c9 | 3668 | |
4c4b4cd2 PH |
3669 | /* Set the cached definition of NAME in DOMAIN to SYM in block |
3670 | BLOCK and symbol table SYMTAB. */ | |
3671 | ||
3672 | static void | |
3673 | cache_symbol (const char *name, domain_enum namespace, struct symbol *sym, | |
3674 | struct block *block, struct symtab *symtab) | |
3675 | { | |
3676 | int h = msymbol_hash (name) % HASH_SIZE; | |
3677 | char *copy; | |
3678 | struct cache_entry *e = | |
3679 | (struct cache_entry *) obstack_alloc(&cache_space, sizeof (*e)); | |
3680 | e->next = cache[h]; | |
3681 | cache[h] = e; | |
3682 | e->name = copy = obstack_alloc (&cache_space, strlen (name) + 1); | |
3683 | strcpy (copy, name); | |
3684 | e->sym = sym; | |
3685 | e->namespace = namespace; | |
3686 | e->symtab = symtab; | |
3687 | e->block = block; | |
3688 | } | |
3689 | \f | |
3690 | /* Symbol Lookup */ | |
3691 | ||
3692 | /* Return the result of a standard (literal, C-like) lookup of NAME in | |
3693 | given DOMAIN, visible from lexical block BLOCK. */ | |
3694 | ||
3695 | static struct symbol * | |
3696 | standard_lookup (const char *name, const struct block *block, | |
3697 | domain_enum domain) | |
3698 | { | |
3699 | struct symbol *sym; | |
3700 | struct symtab *symtab; | |
3701 | ||
3702 | if (lookup_cached_symbol (name, domain, &sym, NULL, NULL)) | |
3703 | return sym; | |
3704 | sym = lookup_symbol_in_language (name, block, domain, language_c, 0, &symtab); | |
3705 | cache_symbol (name, domain, sym, block_found, symtab); | |
3706 | return sym; | |
3707 | } | |
3708 | ||
3709 | ||
3710 | /* Non-zero iff there is at least one non-function/non-enumeral symbol | |
3711 | in the symbol fields of SYMS[0..N-1]. We treat enumerals as functions, | |
3712 | since they contend in overloading in the same way. */ | |
3713 | static int | |
3714 | is_nonfunction (struct ada_symbol_info syms[], int n) | |
3715 | { | |
3716 | int i; | |
3717 | ||
3718 | for (i = 0; i < n; i += 1) | |
3719 | if (TYPE_CODE (SYMBOL_TYPE (syms[i].sym)) != TYPE_CODE_FUNC | |
3720 | && (TYPE_CODE (SYMBOL_TYPE (syms[i].sym)) != TYPE_CODE_ENUM | |
3721 | || SYMBOL_CLASS (syms[i].sym) != LOC_CONST)) | |
14f9c5c9 AS |
3722 | return 1; |
3723 | ||
3724 | return 0; | |
3725 | } | |
3726 | ||
3727 | /* If true (non-zero), then TYPE0 and TYPE1 represent equivalent | |
4c4b4cd2 | 3728 | struct types. Otherwise, they may not. */ |
14f9c5c9 AS |
3729 | |
3730 | static int | |
d2e4a39e | 3731 | equiv_types (struct type *type0, struct type *type1) |
14f9c5c9 | 3732 | { |
d2e4a39e | 3733 | if (type0 == type1) |
14f9c5c9 | 3734 | return 1; |
d2e4a39e | 3735 | if (type0 == NULL || type1 == NULL |
14f9c5c9 AS |
3736 | || TYPE_CODE (type0) != TYPE_CODE (type1)) |
3737 | return 0; | |
d2e4a39e | 3738 | if ((TYPE_CODE (type0) == TYPE_CODE_STRUCT |
14f9c5c9 AS |
3739 | || TYPE_CODE (type0) == TYPE_CODE_ENUM) |
3740 | && ada_type_name (type0) != NULL && ada_type_name (type1) != NULL | |
4c4b4cd2 | 3741 | && strcmp (ada_type_name (type0), ada_type_name (type1)) == 0) |
14f9c5c9 | 3742 | return 1; |
d2e4a39e | 3743 | |
14f9c5c9 AS |
3744 | return 0; |
3745 | } | |
3746 | ||
3747 | /* True iff SYM0 represents the same entity as SYM1, or one that is | |
4c4b4cd2 | 3748 | no more defined than that of SYM1. */ |
14f9c5c9 AS |
3749 | |
3750 | static int | |
d2e4a39e | 3751 | lesseq_defined_than (struct symbol *sym0, struct symbol *sym1) |
14f9c5c9 AS |
3752 | { |
3753 | if (sym0 == sym1) | |
3754 | return 1; | |
176620f1 | 3755 | if (SYMBOL_DOMAIN (sym0) != SYMBOL_DOMAIN (sym1) |
14f9c5c9 AS |
3756 | || SYMBOL_CLASS (sym0) != SYMBOL_CLASS (sym1)) |
3757 | return 0; | |
3758 | ||
d2e4a39e | 3759 | switch (SYMBOL_CLASS (sym0)) |
14f9c5c9 AS |
3760 | { |
3761 | case LOC_UNDEF: | |
3762 | return 1; | |
3763 | case LOC_TYPEDEF: | |
3764 | { | |
4c4b4cd2 PH |
3765 | struct type *type0 = SYMBOL_TYPE (sym0); |
3766 | struct type *type1 = SYMBOL_TYPE (sym1); | |
3767 | char *name0 = SYMBOL_LINKAGE_NAME (sym0); | |
3768 | char *name1 = SYMBOL_LINKAGE_NAME (sym1); | |
3769 | int len0 = strlen (name0); | |
3770 | return | |
3771 | TYPE_CODE (type0) == TYPE_CODE (type1) | |
3772 | && (equiv_types (type0, type1) | |
3773 | || (len0 < strlen (name1) && strncmp (name0, name1, len0) == 0 | |
3774 | && strncmp (name1 + len0, "___XV", 5) == 0)); | |
14f9c5c9 AS |
3775 | } |
3776 | case LOC_CONST: | |
3777 | return SYMBOL_VALUE (sym0) == SYMBOL_VALUE (sym1) | |
4c4b4cd2 | 3778 | && equiv_types (SYMBOL_TYPE (sym0), SYMBOL_TYPE (sym1)); |
d2e4a39e AS |
3779 | default: |
3780 | return 0; | |
14f9c5c9 AS |
3781 | } |
3782 | } | |
3783 | ||
4c4b4cd2 PH |
3784 | /* Append (SYM,BLOCK,SYMTAB) to the end of the array of struct ada_symbol_info |
3785 | records in OBSTACKP. Do nothing if SYM is a duplicate. */ | |
14f9c5c9 AS |
3786 | |
3787 | static void | |
4c4b4cd2 PH |
3788 | add_defn_to_vec (struct obstack *obstackp, |
3789 | struct symbol *sym, | |
3790 | struct block *block, | |
3791 | struct symtab *symtab) | |
14f9c5c9 AS |
3792 | { |
3793 | int i; | |
3794 | size_t tmp; | |
4c4b4cd2 | 3795 | struct ada_symbol_info *prevDefns = defns_collected (obstackp, 0); |
14f9c5c9 | 3796 | |
d2e4a39e | 3797 | if (SYMBOL_TYPE (sym) != NULL) |
14f9c5c9 | 3798 | CHECK_TYPEDEF (SYMBOL_TYPE (sym)); |
4c4b4cd2 PH |
3799 | for (i = num_defns_collected (obstackp) - 1; i >= 0; i -= 1) |
3800 | { | |
3801 | if (lesseq_defined_than (sym, prevDefns[i].sym)) | |
3802 | return; | |
3803 | else if (lesseq_defined_than (prevDefns[i].sym, sym)) | |
3804 | { | |
3805 | prevDefns[i].sym = sym; | |
3806 | prevDefns[i].block = block; | |
3807 | prevDefns[i].symtab = symtab; | |
3808 | return; | |
3809 | } | |
3810 | } | |
3811 | ||
3812 | { | |
3813 | struct ada_symbol_info info; | |
3814 | ||
3815 | info.sym = sym; | |
3816 | info.block = block; | |
3817 | info.symtab = symtab; | |
3818 | obstack_grow (obstackp, &info, sizeof (struct ada_symbol_info)); | |
3819 | } | |
3820 | } | |
3821 | ||
3822 | /* Number of ada_symbol_info structures currently collected in | |
3823 | current vector in *OBSTACKP. */ | |
3824 | ||
3825 | static int | |
3826 | num_defns_collected (struct obstack *obstackp) | |
3827 | { | |
3828 | return obstack_object_size (obstackp) / sizeof (struct ada_symbol_info); | |
3829 | } | |
3830 | ||
3831 | /* Vector of ada_symbol_info structures currently collected in current | |
3832 | vector in *OBSTACKP. If FINISH, close off the vector and return | |
3833 | its final address. */ | |
3834 | ||
3835 | static struct ada_symbol_info * | |
3836 | defns_collected (struct obstack *obstackp, int finish) | |
3837 | { | |
3838 | if (finish) | |
3839 | return obstack_finish (obstackp); | |
3840 | else | |
3841 | return (struct ada_symbol_info *) obstack_base (obstackp); | |
3842 | } | |
3843 | ||
3844 | /* If SYM_NAME is a completion candidate for TEXT, return this symbol | |
3845 | name in a form that's appropriate for the completion. The result | |
3846 | does not need to be deallocated, but is only good until the next call. | |
3847 | ||
3848 | TEXT_LEN is equal to the length of TEXT. | |
3849 | Perform a wild match if WILD_MATCH is set. | |
3850 | ENCODED should be set if TEXT represents the start of a symbol name | |
3851 | in its encoded form. */ | |
3852 | ||
3853 | static const char * | |
3854 | symbol_completion_match (const char *sym_name, | |
3855 | const char *text, int text_len, | |
3856 | int wild_match, int encoded) | |
3857 | { | |
3858 | char *result; | |
3859 | const int verbatim_match = (text[0] == '<'); | |
3860 | int match = 0; | |
3861 | ||
3862 | if (verbatim_match) | |
3863 | { | |
3864 | /* Strip the leading angle bracket. */ | |
3865 | text = text + 1; | |
3866 | text_len--; | |
3867 | } | |
3868 | ||
3869 | /* First, test against the fully qualified name of the symbol. */ | |
3870 | ||
3871 | if (strncmp (sym_name, text, text_len) == 0) | |
3872 | match = 1; | |
3873 | ||
3874 | if (match && !encoded) | |
14f9c5c9 | 3875 | { |
4c4b4cd2 PH |
3876 | /* One needed check before declaring a positive match is to verify |
3877 | that iff we are doing a verbatim match, the decoded version | |
3878 | of the symbol name starts with '<'. Otherwise, this symbol name | |
3879 | is not a suitable completion. */ | |
3880 | const char *sym_name_copy = sym_name; | |
3881 | int has_angle_bracket; | |
3882 | ||
3883 | sym_name = ada_decode (sym_name); | |
3884 | has_angle_bracket = (sym_name [0] == '<'); | |
3885 | match = (has_angle_bracket == verbatim_match); | |
3886 | sym_name = sym_name_copy; | |
3887 | } | |
3888 | ||
3889 | if (match && !verbatim_match) | |
3890 | { | |
3891 | /* When doing non-verbatim match, another check that needs to | |
3892 | be done is to verify that the potentially matching symbol name | |
3893 | does not include capital letters, because the ada-mode would | |
3894 | not be able to understand these symbol names without the | |
3895 | angle bracket notation. */ | |
3896 | const char *tmp; | |
3897 | ||
3898 | for (tmp = sym_name; *tmp != '\0' && !isupper (*tmp); tmp++); | |
3899 | if (*tmp != '\0') | |
3900 | match = 0; | |
3901 | } | |
3902 | ||
3903 | /* Second: Try wild matching... */ | |
3904 | ||
3905 | if (!match && wild_match) | |
3906 | { | |
3907 | /* Since we are doing wild matching, this means that TEXT | |
3908 | may represent an unqualified symbol name. We therefore must | |
3909 | also compare TEXT against the unqualified name of the symbol. */ | |
3910 | sym_name = ada_unqualified_name (ada_decode (sym_name)); | |
3911 | ||
3912 | if (strncmp (sym_name, text, text_len) == 0) | |
3913 | match = 1; | |
3914 | } | |
3915 | ||
3916 | /* Finally: If we found a mach, prepare the result to return. */ | |
3917 | ||
3918 | if (!match) | |
3919 | return NULL; | |
3920 | ||
3921 | if (verbatim_match) | |
3922 | sym_name = add_angle_brackets (sym_name); | |
3923 | ||
3924 | if (!encoded) | |
3925 | sym_name = ada_decode (sym_name); | |
3926 | ||
3927 | return sym_name; | |
3928 | } | |
3929 | ||
3930 | /* A companion function to ada_make_symbol_completion_list(). | |
3931 | Check if SYM_NAME represents a symbol which name would be suitable | |
3932 | to complete TEXT (TEXT_LEN is the length of TEXT), in which case | |
3933 | it is appended at the end of the given string vector SV. | |
3934 | ||
3935 | ORIG_TEXT is the string original string from the user command | |
3936 | that needs to be completed. WORD is the entire command on which | |
3937 | completion should be performed. These two parameters are used to | |
3938 | determine which part of the symbol name should be added to the | |
3939 | completion vector. | |
3940 | if WILD_MATCH is set, then wild matching is performed. | |
3941 | ENCODED should be set if TEXT represents a symbol name in its | |
3942 | encoded formed (in which case the completion should also be | |
3943 | encoded). */ | |
3944 | ||
3945 | static void | |
3946 | symbol_completion_add (struct string_vector *sv, | |
3947 | const char *sym_name, | |
3948 | const char *text, int text_len, | |
3949 | const char *orig_text, const char *word, | |
3950 | int wild_match, int encoded) | |
3951 | { | |
3952 | const char *match = symbol_completion_match (sym_name, text, text_len, | |
3953 | wild_match, encoded); | |
3954 | char *completion; | |
3955 | ||
3956 | if (match == NULL) | |
3957 | return; | |
3958 | ||
3959 | /* We found a match, so add the appropriate completion to the given | |
3960 | string vector. */ | |
3961 | ||
3962 | if (word == orig_text) | |
3963 | { | |
3964 | completion = xmalloc (strlen (match) + 5); | |
3965 | strcpy (completion, match); | |
3966 | } | |
3967 | else if (word > orig_text) | |
3968 | { | |
3969 | /* Return some portion of sym_name. */ | |
3970 | completion = xmalloc (strlen (match) + 5); | |
3971 | strcpy (completion, match + (word - orig_text)); | |
3972 | } | |
3973 | else | |
3974 | { | |
3975 | /* Return some of ORIG_TEXT plus sym_name. */ | |
3976 | completion = xmalloc (strlen (match) + (orig_text - word) + 5); | |
3977 | strncpy (completion, word, orig_text - word); | |
3978 | completion[orig_text - word] = '\0'; | |
3979 | strcat (completion, match); | |
3980 | } | |
3981 | ||
3982 | string_vector_append (sv, completion); | |
3983 | } | |
3984 | ||
3985 | /* Return a list of possible symbol names completing TEXT0. The list | |
3986 | is NULL terminated. WORD is the entire command on which completion | |
3987 | is made. */ | |
3988 | ||
3989 | char ** | |
3990 | ada_make_symbol_completion_list (const char *text0, const char *word) | |
3991 | { | |
3992 | /* Note: This function is almost a copy of make_symbol_completion_list(), | |
3993 | except it has been adapted for Ada. It is somewhat of a shame to | |
3994 | duplicate so much code, but we don't really have the infrastructure | |
3995 | yet to develop a language-aware version of he symbol completer... */ | |
3996 | char *text; | |
3997 | int text_len; | |
3998 | int wild_match; | |
3999 | int encoded; | |
4000 | struct string_vector result = xnew_string_vector (128); | |
4001 | struct symbol *sym; | |
4002 | struct symtab *s; | |
4003 | struct partial_symtab *ps; | |
4004 | struct minimal_symbol *msymbol; | |
4005 | struct objfile *objfile; | |
4006 | struct block *b, *surrounding_static_block = 0; | |
4007 | int i; | |
4008 | struct dict_iterator iter; | |
4009 | ||
4010 | if (text0[0] == '<') | |
4011 | { | |
4012 | text = xstrdup (text0); | |
4013 | make_cleanup (xfree, text); | |
4014 | text_len = strlen (text); | |
4015 | wild_match = 0; | |
4016 | encoded = 1; | |
4017 | } | |
4018 | else | |
4019 | { | |
4020 | text = xstrdup (ada_encode (text0)); | |
4021 | make_cleanup (xfree, text); | |
4022 | text_len = strlen (text); | |
4023 | for (i = 0; i < text_len; i++) | |
4024 | text[i] = tolower (text[i]); | |
4025 | ||
4026 | /* FIXME: brobecker/2003-09-17: When we get rid of ADA_RETAIN_DOTS, | |
4027 | we can restrict the wild_match check to searching "__" only. */ | |
4028 | wild_match = (strstr (text0, "__") == NULL | |
4029 | && strchr (text0, '.') == NULL); | |
4030 | encoded = (strstr (text0, "__") != NULL); | |
4031 | } | |
4032 | ||
4033 | /* First, look at the partial symtab symbols. */ | |
4034 | ALL_PSYMTABS (objfile, ps) | |
4035 | { | |
4036 | struct partial_symbol **psym; | |
4037 | ||
4038 | /* If the psymtab's been read in we'll get it when we search | |
4039 | through the blockvector. */ | |
4040 | if (ps->readin) | |
4041 | continue; | |
4042 | ||
4043 | for (psym = objfile->global_psymbols.list + ps->globals_offset; | |
4044 | psym < (objfile->global_psymbols.list + ps->globals_offset | |
4045 | + ps->n_global_syms); | |
4046 | psym++) | |
4047 | { | |
4048 | QUIT; | |
4049 | symbol_completion_add (&result, SYMBOL_LINKAGE_NAME (*psym), | |
4050 | text, text_len, text0, word, | |
4051 | wild_match, encoded); | |
4052 | } | |
4053 | ||
4054 | for (psym = objfile->static_psymbols.list + ps->statics_offset; | |
4055 | psym < (objfile->static_psymbols.list + ps->statics_offset | |
4056 | + ps->n_static_syms); | |
4057 | psym++) | |
4058 | { | |
4059 | QUIT; | |
4060 | symbol_completion_add (&result, SYMBOL_LINKAGE_NAME (*psym), | |
4061 | text, text_len, text0, word, | |
4062 | wild_match, encoded); | |
4063 | } | |
4064 | } | |
4065 | ||
4066 | /* At this point scan through the misc symbol vectors and add each | |
4067 | symbol you find to the list. Eventually we want to ignore | |
4068 | anything that isn't a text symbol (everything else will be | |
4069 | handled by the psymtab code above). */ | |
4070 | ||
4071 | ALL_MSYMBOLS (objfile, msymbol) | |
4072 | { | |
4073 | QUIT; | |
4074 | symbol_completion_add (&result, SYMBOL_LINKAGE_NAME (msymbol), | |
4075 | text, text_len, text0, word, | |
4076 | wild_match, encoded); | |
4077 | } | |
4078 | ||
4079 | /* Search upwards from currently selected frame (so that we can | |
4080 | complete on local vars. */ | |
4081 | ||
4082 | for (b = get_selected_block (0); b != NULL; b = BLOCK_SUPERBLOCK (b)) | |
4083 | { | |
4084 | if (!BLOCK_SUPERBLOCK (b)) | |
4085 | surrounding_static_block = b; /* For elmin of dups */ | |
4086 | ||
4087 | ALL_BLOCK_SYMBOLS (b, iter, sym) | |
14f9c5c9 | 4088 | { |
4c4b4cd2 PH |
4089 | symbol_completion_add (&result, SYMBOL_LINKAGE_NAME (sym), |
4090 | text, text_len, text0, word, | |
4091 | wild_match, encoded); | |
14f9c5c9 AS |
4092 | } |
4093 | } | |
4094 | ||
4c4b4cd2 PH |
4095 | /* Go through the symtabs and check the externs and statics for |
4096 | symbols which match. */ | |
4097 | ||
4098 | ALL_SYMTABS (objfile, s) | |
4099 | { | |
4100 | QUIT; | |
4101 | b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK); | |
4102 | ALL_BLOCK_SYMBOLS (b, iter, sym) | |
4103 | { | |
4104 | symbol_completion_add (&result, SYMBOL_LINKAGE_NAME (sym), | |
4105 | text, text_len, text0, word, | |
4106 | wild_match, encoded); | |
4107 | } | |
4108 | } | |
14f9c5c9 | 4109 | |
4c4b4cd2 PH |
4110 | ALL_SYMTABS (objfile, s) |
4111 | { | |
4112 | QUIT; | |
4113 | b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK); | |
4114 | /* Don't do this block twice. */ | |
4115 | if (b == surrounding_static_block) | |
4116 | continue; | |
4117 | ALL_BLOCK_SYMBOLS (b, iter, sym) | |
4118 | { | |
4119 | symbol_completion_add (&result, SYMBOL_LINKAGE_NAME (sym), | |
4120 | text, text_len, text0, word, | |
4121 | wild_match, encoded); | |
4122 | } | |
4123 | } | |
4124 | ||
4125 | /* Append the closing NULL entry. */ | |
4126 | string_vector_append (&result, NULL); | |
4127 | ||
4128 | return (result.array); | |
14f9c5c9 AS |
4129 | } |
4130 | ||
4c4b4cd2 PH |
4131 | /* Look, in partial_symtab PST, for symbol NAME in given namespace. |
4132 | Check the global symbols if GLOBAL, the static symbols if not. | |
4133 | Do wild-card match if WILD. */ | |
14f9c5c9 AS |
4134 | |
4135 | static struct partial_symbol * | |
d2e4a39e | 4136 | ada_lookup_partial_symbol (struct partial_symtab *pst, const char *name, |
4c4b4cd2 | 4137 | int global, domain_enum namespace, int wild) |
14f9c5c9 AS |
4138 | { |
4139 | struct partial_symbol **start; | |
4140 | int name_len = strlen (name); | |
4141 | int length = (global ? pst->n_global_syms : pst->n_static_syms); | |
4142 | int i; | |
4143 | ||
4144 | if (length == 0) | |
4145 | { | |
4146 | return (NULL); | |
4147 | } | |
d2e4a39e | 4148 | |
14f9c5c9 | 4149 | start = (global ? |
4c4b4cd2 PH |
4150 | pst->objfile->global_psymbols.list + pst->globals_offset : |
4151 | pst->objfile->static_psymbols.list + pst->statics_offset); | |
14f9c5c9 AS |
4152 | |
4153 | if (wild) | |
4154 | { | |
4155 | for (i = 0; i < length; i += 1) | |
4c4b4cd2 PH |
4156 | { |
4157 | struct partial_symbol *psym = start[i]; | |
14f9c5c9 | 4158 | |
4c4b4cd2 PH |
4159 | if (SYMBOL_DOMAIN (psym) == namespace && |
4160 | wild_match (name, name_len, SYMBOL_LINKAGE_NAME (psym))) | |
4161 | return psym; | |
4162 | } | |
14f9c5c9 AS |
4163 | return NULL; |
4164 | } | |
d2e4a39e | 4165 | else |
14f9c5c9 AS |
4166 | { |
4167 | if (global) | |
4c4b4cd2 PH |
4168 | { |
4169 | int U; | |
4170 | i = 0; | |
4171 | U = length - 1; | |
4172 | while (U - i > 4) | |
4173 | { | |
4174 | int M = (U + i) >> 1; | |
4175 | struct partial_symbol *psym = start[M]; | |
4176 | if (SYMBOL_LINKAGE_NAME (psym)[0] < name[0]) | |
4177 | i = M + 1; | |
4178 | else if (SYMBOL_LINKAGE_NAME (psym)[0] > name[0]) | |
4179 | U = M - 1; | |
4180 | else if (strcmp (SYMBOL_LINKAGE_NAME (psym), name) < 0) | |
4181 | i = M + 1; | |
4182 | else | |
4183 | U = M; | |
4184 | } | |
4185 | } | |
14f9c5c9 | 4186 | else |
4c4b4cd2 | 4187 | i = 0; |
14f9c5c9 AS |
4188 | |
4189 | while (i < length) | |
4c4b4cd2 PH |
4190 | { |
4191 | struct partial_symbol *psym = start[i]; | |
4192 | ||
4193 | if (SYMBOL_DOMAIN (psym) == namespace) | |
4194 | { | |
4195 | int cmp = strncmp (name, SYMBOL_LINKAGE_NAME (psym), name_len); | |
4196 | ||
4197 | if (cmp < 0) | |
4198 | { | |
4199 | if (global) | |
4200 | break; | |
4201 | } | |
4202 | else if (cmp == 0 | |
4203 | && is_name_suffix (SYMBOL_LINKAGE_NAME (psym) | |
4204 | + name_len)) | |
4205 | return psym; | |
4206 | } | |
4207 | i += 1; | |
4208 | } | |
14f9c5c9 AS |
4209 | |
4210 | if (global) | |
4c4b4cd2 PH |
4211 | { |
4212 | int U; | |
4213 | i = 0; | |
4214 | U = length - 1; | |
4215 | while (U - i > 4) | |
4216 | { | |
4217 | int M = (U + i) >> 1; | |
4218 | struct partial_symbol *psym = start[M]; | |
4219 | if (SYMBOL_LINKAGE_NAME (psym)[0] < '_') | |
4220 | i = M + 1; | |
4221 | else if (SYMBOL_LINKAGE_NAME (psym)[0] > '_') | |
4222 | U = M - 1; | |
4223 | else if (strcmp (SYMBOL_LINKAGE_NAME (psym), "_ada_") < 0) | |
4224 | i = M + 1; | |
4225 | else | |
4226 | U = M; | |
4227 | } | |
4228 | } | |
14f9c5c9 | 4229 | else |
4c4b4cd2 | 4230 | i = 0; |
14f9c5c9 AS |
4231 | |
4232 | while (i < length) | |
4c4b4cd2 PH |
4233 | { |
4234 | struct partial_symbol *psym = start[i]; | |
4235 | ||
4236 | if (SYMBOL_DOMAIN (psym) == namespace) | |
4237 | { | |
4238 | int cmp; | |
4239 | ||
4240 | cmp = (int) '_' - (int) SYMBOL_LINKAGE_NAME (psym)[0]; | |
4241 | if (cmp == 0) | |
4242 | { | |
4243 | cmp = strncmp ("_ada_", SYMBOL_LINKAGE_NAME (psym), 5); | |
4244 | if (cmp == 0) | |
4245 | cmp = strncmp (name, SYMBOL_LINKAGE_NAME (psym) + 5, | |
4246 | name_len); | |
4247 | } | |
4248 | ||
4249 | if (cmp < 0) | |
4250 | { | |
4251 | if (global) | |
4252 | break; | |
4253 | } | |
4254 | else if (cmp == 0 | |
4255 | && is_name_suffix (SYMBOL_LINKAGE_NAME (psym) | |
4256 | + name_len + 5)) | |
4257 | return psym; | |
4258 | } | |
4259 | i += 1; | |
4260 | } | |
14f9c5c9 AS |
4261 | } |
4262 | return NULL; | |
4263 | } | |
4264 | ||
14f9c5c9 | 4265 | /* Find a symbol table containing symbol SYM or NULL if none. */ |
4c4b4cd2 | 4266 | |
d2e4a39e AS |
4267 | static struct symtab * |
4268 | symtab_for_sym (struct symbol *sym) | |
14f9c5c9 | 4269 | { |
d2e4a39e | 4270 | struct symtab *s; |
14f9c5c9 AS |
4271 | struct objfile *objfile; |
4272 | struct block *b; | |
261397f8 | 4273 | struct symbol *tmp_sym; |
de4f826b DC |
4274 | struct dict_iterator iter; |
4275 | int j; | |
14f9c5c9 AS |
4276 | |
4277 | ALL_SYMTABS (objfile, s) | |
d2e4a39e AS |
4278 | { |
4279 | switch (SYMBOL_CLASS (sym)) | |
4280 | { | |
4281 | case LOC_CONST: | |
4282 | case LOC_STATIC: | |
4283 | case LOC_TYPEDEF: | |
4284 | case LOC_REGISTER: | |
4285 | case LOC_LABEL: | |
4286 | case LOC_BLOCK: | |
4287 | case LOC_CONST_BYTES: | |
4288 | b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK); | |
de4f826b | 4289 | ALL_BLOCK_SYMBOLS (b, iter, tmp_sym) if (sym == tmp_sym) |
d2e4a39e AS |
4290 | return s; |
4291 | b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK); | |
de4f826b | 4292 | ALL_BLOCK_SYMBOLS (b, iter, tmp_sym) if (sym == tmp_sym) |
d2e4a39e | 4293 | return s; |
4c4b4cd2 | 4294 | break; |
d2e4a39e | 4295 | default: |
4c4b4cd2 | 4296 | break; |
d2e4a39e AS |
4297 | } |
4298 | switch (SYMBOL_CLASS (sym)) | |
4299 | { | |
4300 | case LOC_REGISTER: | |
4301 | case LOC_ARG: | |
4302 | case LOC_REF_ARG: | |
4303 | case LOC_REGPARM: | |
4304 | case LOC_REGPARM_ADDR: | |
4305 | case LOC_LOCAL: | |
4306 | case LOC_TYPEDEF: | |
4307 | case LOC_LOCAL_ARG: | |
4308 | case LOC_BASEREG: | |
4309 | case LOC_BASEREG_ARG: | |
4c2df51b DJ |
4310 | case LOC_COMPUTED: |
4311 | case LOC_COMPUTED_ARG: | |
d2e4a39e AS |
4312 | for (j = FIRST_LOCAL_BLOCK; |
4313 | j < BLOCKVECTOR_NBLOCKS (BLOCKVECTOR (s)); j += 1) | |
4314 | { | |
4315 | b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), j); | |
de4f826b | 4316 | ALL_BLOCK_SYMBOLS (b, iter, tmp_sym) if (sym == tmp_sym) |
14f9c5c9 | 4317 | return s; |
d2e4a39e AS |
4318 | } |
4319 | break; | |
4320 | default: | |
4c4b4cd2 | 4321 | break; |
d2e4a39e AS |
4322 | } |
4323 | } | |
14f9c5c9 AS |
4324 | return NULL; |
4325 | } | |
4326 | ||
4c4b4cd2 PH |
4327 | /* Return a minimal symbol matching NAME according to Ada decoding |
4328 | rules. Returns NULL if there is no such minimal symbol. Names | |
4329 | prefixed with "standard__" are handled specially: "standard__" is | |
4330 | first stripped off, and only static and global symbols are searched. */ | |
14f9c5c9 | 4331 | |
d2e4a39e | 4332 | struct minimal_symbol * |
4c4b4cd2 | 4333 | ada_lookup_simple_minsym (const char *name) |
14f9c5c9 | 4334 | { |
d2e4a39e AS |
4335 | struct objfile *objfile; |
4336 | struct minimal_symbol *msymbol; | |
4c4b4cd2 PH |
4337 | int wild_match; |
4338 | ||
4339 | if (strncmp (name, "standard__", sizeof ("standard__") - 1) == 0) | |
4340 | { | |
4341 | name += sizeof ("standard__") - 1; | |
4342 | wild_match = 0; | |
4343 | } | |
4344 | else | |
4345 | wild_match = (strstr (name, "__") == NULL); | |
14f9c5c9 AS |
4346 | |
4347 | ALL_MSYMBOLS (objfile, msymbol) | |
d2e4a39e | 4348 | { |
4c4b4cd2 PH |
4349 | if (ada_match_name (SYMBOL_LINKAGE_NAME (msymbol), name, wild_match) |
4350 | && MSYMBOL_TYPE (msymbol) != mst_solib_trampoline) | |
d2e4a39e AS |
4351 | return msymbol; |
4352 | } | |
14f9c5c9 AS |
4353 | |
4354 | return NULL; | |
4355 | } | |
4356 | ||
4c4b4cd2 PH |
4357 | /* Return up minimal symbol for NAME, folded and encoded according to |
4358 | Ada conventions, or NULL if none. The last two arguments are ignored. */ | |
4359 | ||
4360 | static struct minimal_symbol * | |
4361 | ada_lookup_minimal_symbol (const char *name, const char *sfile, | |
4362 | struct objfile *objf) | |
4363 | { | |
4364 | return ada_lookup_simple_minsym (ada_encode (name)); | |
4365 | } | |
4366 | ||
14f9c5c9 | 4367 | /* For all subprograms that statically enclose the subprogram of the |
4c4b4cd2 PH |
4368 | selected frame, add symbols matching identifier NAME in DOMAIN |
4369 | and their blocks to the list of data in OBSTACKP, as for | |
4370 | ada_add_block_symbols (q.v.). If WILD, treat as NAME with a | |
4371 | wildcard prefix. */ | |
4372 | ||
14f9c5c9 | 4373 | static void |
4c4b4cd2 PH |
4374 | add_symbols_from_enclosing_procs (struct obstack *obstackp, |
4375 | const char *name, domain_enum namespace, | |
4376 | int wild_match) | |
4377 | { | |
4378 | #ifdef HAVE_ADD_SYMBOLS_FROM_ENCLOSING_PROCS | |
4379 | /* Use a heuristic to find the frames of enclosing subprograms: treat the | |
4380 | pointer-sized value at location 0 from the local-variable base of a | |
4381 | frame as a static link, and then search up the call stack for a | |
4382 | frame with that same local-variable base. */ | |
14f9c5c9 AS |
4383 | static struct symbol static_link_sym; |
4384 | static struct symbol *static_link; | |
4c4b4cd2 | 4385 | struct value *target_link_val; |
14f9c5c9 | 4386 | |
d2e4a39e AS |
4387 | struct cleanup *old_chain = make_cleanup (null_cleanup, NULL); |
4388 | struct frame_info *frame; | |
4c4b4cd2 PH |
4389 | |
4390 | if (! target_has_stack) | |
4391 | return; | |
14f9c5c9 AS |
4392 | |
4393 | if (static_link == NULL) | |
4394 | { | |
4395 | /* Initialize the local variable symbol that stands for the | |
4c4b4cd2 | 4396 | static link (when there is one). */ |
14f9c5c9 | 4397 | static_link = &static_link_sym; |
4c4b4cd2 | 4398 | SYMBOL_LINKAGE_NAME (static_link) = ""; |
14f9c5c9 AS |
4399 | SYMBOL_LANGUAGE (static_link) = language_unknown; |
4400 | SYMBOL_CLASS (static_link) = LOC_LOCAL; | |
176620f1 | 4401 | SYMBOL_DOMAIN (static_link) = VAR_DOMAIN; |
14f9c5c9 | 4402 | SYMBOL_TYPE (static_link) = lookup_pointer_type (builtin_type_void); |
d2e4a39e | 4403 | SYMBOL_VALUE (static_link) = |
4c4b4cd2 | 4404 | -(long) TYPE_LENGTH (SYMBOL_TYPE (static_link)); |
14f9c5c9 AS |
4405 | } |
4406 | ||
4c4b4cd2 PH |
4407 | frame = get_selected_frame (); |
4408 | if (frame == NULL | |
4409 | || inside_main_func (get_frame_address_in_block (frame))) | |
4410 | return; | |
4411 | ||
4412 | target_link_val = read_var_value (static_link, frame); | |
4413 | while (target_link_val != NULL | |
4414 | && num_defns_collected (obstackp) == 0 | |
4415 | && frame_relative_level (frame) <= MAX_ENCLOSING_FRAME_LEVELS) | |
14f9c5c9 | 4416 | { |
4c4b4cd2 | 4417 | CORE_ADDR target_link = value_as_address (target_link_val); |
14f9c5c9 | 4418 | |
4c4b4cd2 PH |
4419 | frame = get_prev_frame (frame); |
4420 | if (frame == NULL) | |
14f9c5c9 | 4421 | break; |
14f9c5c9 | 4422 | |
4c4b4cd2 | 4423 | if (get_frame_locals_address (frame) == target_link) |
d2e4a39e | 4424 | { |
4c4b4cd2 PH |
4425 | struct block *block; |
4426 | ||
14f9c5c9 | 4427 | QUIT; |
14f9c5c9 | 4428 | |
4c4b4cd2 PH |
4429 | block = get_frame_block (frame, 0); |
4430 | while (block != NULL && block_function (block) != NULL | |
4431 | && num_defns_collected (obstackp) == 0) | |
4432 | { | |
4433 | QUIT; | |
d2e4a39e | 4434 | |
4c4b4cd2 PH |
4435 | ada_add_block_symbols (obstackp, block, name, namespace, |
4436 | NULL, NULL, wild_match); | |
4437 | ||
4438 | block = BLOCK_SUPERBLOCK (block); | |
4439 | } | |
14f9c5c9 AS |
4440 | } |
4441 | } | |
4442 | ||
4443 | do_cleanups (old_chain); | |
4444 | #endif | |
4445 | } | |
4446 | ||
4447 | /* True if TYPE is definitely an artificial type supplied to a symbol | |
4c4b4cd2 PH |
4448 | for which no debugging information was given in the symbol file. */ |
4449 | ||
14f9c5c9 | 4450 | static int |
d2e4a39e | 4451 | is_nondebugging_type (struct type *type) |
14f9c5c9 | 4452 | { |
d2e4a39e | 4453 | char *name = ada_type_name (type); |
4c4b4cd2 | 4454 | return (name != NULL && strcmp (name, "<variable, no debug info>") == 0); |
14f9c5c9 AS |
4455 | } |
4456 | ||
4c4b4cd2 PH |
4457 | /* Remove any non-debugging symbols in SYMS[0 .. NSYMS-1] that definitely |
4458 | duplicate other symbols in the list (The only case I know of where | |
4459 | this happens is when object files containing stabs-in-ecoff are | |
4460 | linked with files containing ordinary ecoff debugging symbols (or no | |
4461 | debugging symbols)). Modifies SYMS to squeeze out deleted entries. | |
4462 | Returns the number of items in the modified list. */ | |
4463 | ||
14f9c5c9 | 4464 | static int |
4c4b4cd2 | 4465 | remove_extra_symbols (struct ada_symbol_info *syms, int nsyms) |
14f9c5c9 AS |
4466 | { |
4467 | int i, j; | |
4468 | ||
4469 | i = 0; | |
4470 | while (i < nsyms) | |
4471 | { | |
4c4b4cd2 PH |
4472 | if (SYMBOL_LINKAGE_NAME (syms[i].sym) != NULL |
4473 | && SYMBOL_CLASS (syms[i].sym) == LOC_STATIC | |
4474 | && is_nondebugging_type (SYMBOL_TYPE (syms[i].sym))) | |
4475 | { | |
4476 | for (j = 0; j < nsyms; j += 1) | |
4477 | { | |
4478 | if (i != j | |
4479 | && SYMBOL_LINKAGE_NAME (syms[j].sym) != NULL | |
4480 | && strcmp (SYMBOL_LINKAGE_NAME (syms[i].sym), | |
4481 | SYMBOL_LINKAGE_NAME (syms[j].sym)) == 0 | |
4482 | && SYMBOL_CLASS (syms[i].sym) == SYMBOL_CLASS (syms[j].sym) | |
4483 | && SYMBOL_VALUE_ADDRESS (syms[i].sym) | |
4484 | == SYMBOL_VALUE_ADDRESS (syms[j].sym)) | |
4485 | { | |
4486 | int k; | |
4487 | for (k = i + 1; k < nsyms; k += 1) | |
4488 | syms[k - 1] = syms[k]; | |
4489 | nsyms -= 1; | |
4490 | goto NextSymbol; | |
4491 | } | |
4492 | } | |
4493 | } | |
14f9c5c9 AS |
4494 | i += 1; |
4495 | NextSymbol: | |
4496 | ; | |
4497 | } | |
4498 | return nsyms; | |
4499 | } | |
4500 | ||
4c4b4cd2 PH |
4501 | /* Given a type that corresponds to a renaming entity, use the type name |
4502 | to extract the scope (package name or function name, fully qualified, | |
4503 | and following the GNAT encoding convention) where this renaming has been | |
4504 | defined. The string returned needs to be deallocated after use. */ | |
4505 | ||
4506 | static char * | |
4507 | xget_renaming_scope (struct type *renaming_type) | |
4508 | { | |
4509 | /* The renaming types adhere to the following convention: | |
4510 | <scope>__<rename>___<XR extension>. | |
4511 | So, to extract the scope, we search for the "___XR" extension, | |
4512 | and then backtrack until we find the first "__". */ | |
4513 | ||
4514 | const char *name = type_name_no_tag (renaming_type); | |
4515 | char *suffix = strstr (name, "___XR"); | |
4516 | char *last; | |
4517 | int scope_len; | |
4518 | char *scope; | |
4519 | ||
4520 | /* Now, backtrack a bit until we find the first "__". Start looking | |
4521 | at suffix - 3, as the <rename> part is at least one character long. */ | |
4522 | ||
4523 | for (last = suffix - 3; last > name; last--) | |
4524 | if (last[0] == '_' && last[1] == '_') | |
4525 | break; | |
4526 | ||
4527 | /* Make a copy of scope and return it. */ | |
4528 | ||
4529 | scope_len = last - name; | |
4530 | scope = (char *) xmalloc ((scope_len + 1) * sizeof (char)); | |
4531 | ||
4532 | strncpy (scope, name, scope_len); | |
4533 | scope[scope_len] = '\0'; | |
4534 | ||
4535 | return scope; | |
4536 | } | |
4537 | ||
4538 | /* Return nonzero if NAME corresponds to a package name. */ | |
4539 | ||
4540 | static int | |
4541 | is_package_name (const char *name) | |
4542 | { | |
4543 | /* Here, We take advantage of the fact that no symbols are generated | |
4544 | for packages, while symbols are generated for each function. | |
4545 | So the condition for NAME represent a package becomes equivalent | |
4546 | to NAME not existing in our list of symbols. There is only one | |
4547 | small complication with library-level functions (see below). */ | |
4548 | ||
4549 | char *fun_name; | |
4550 | ||
4551 | /* If it is a function that has not been defined at library level, | |
4552 | then we should be able to look it up in the symbols. */ | |
4553 | if (standard_lookup (name, NULL, VAR_DOMAIN) != NULL) | |
4554 | return 0; | |
4555 | ||
4556 | /* Library-level function names start with "_ada_". See if function | |
4557 | "_ada_" followed by NAME can be found. */ | |
4558 | ||
4559 | /* Do a quick check that NAME does not contain "__", since library-level | |
4560 | functions names can not contain "__" in them. */ | |
4561 | if (strstr (name, "__") != NULL) | |
4562 | return 0; | |
4563 | ||
4564 | fun_name = (char *) alloca (strlen (name) + 5 + 1); | |
4565 | xasprintf (&fun_name, "_ada_%s", name); | |
4566 | ||
4567 | return (standard_lookup (fun_name, NULL, VAR_DOMAIN) == NULL); | |
4568 | } | |
4569 | ||
4570 | /* Return nonzero if SYM corresponds to a renaming entity that is | |
4571 | visible from FUNCTION_NAME. */ | |
4572 | ||
4573 | static int | |
4574 | renaming_is_visible (const struct symbol *sym, char *function_name) | |
4575 | { | |
4576 | char *scope = xget_renaming_scope (SYMBOL_TYPE (sym)); | |
4577 | ||
4578 | make_cleanup (xfree, scope); | |
4579 | ||
4580 | /* If the rename has been defined in a package, then it is visible. */ | |
4581 | if (is_package_name (scope)) | |
4582 | return 1; | |
4583 | ||
4584 | /* Check that the rename is in the current function scope by checking | |
4585 | that its name starts with SCOPE. */ | |
4586 | ||
4587 | /* If the function name starts with "_ada_", it means that it is | |
4588 | a library-level function. Strip this prefix before doing the | |
4589 | comparison, as the encoding for the renaming does not contain | |
4590 | this prefix. */ | |
4591 | if (strncmp (function_name, "_ada_", 5) == 0) | |
4592 | function_name += 5; | |
4593 | ||
4594 | return (strncmp (function_name, scope, strlen (scope)) == 0); | |
4595 | } | |
4596 | ||
4597 | /* Iterates over the SYMS list and remove any entry that corresponds to | |
4598 | a renaming entity that is not visible from the function associated | |
4599 | with CURRENT_BLOCK. | |
4600 | ||
4601 | Rationale: | |
4602 | GNAT emits a type following a specified encoding for each renaming | |
4603 | entity. Unfortunately, STABS currently does not support the definition | |
4604 | of types that are local to a given lexical block, so all renamings types | |
4605 | are emitted at library level. As a consequence, if an application | |
4606 | contains two renaming entities using the same name, and a user tries to | |
4607 | print the value of one of these entities, the result of the ada symbol | |
4608 | lookup will also contain the wrong renaming type. | |
4609 | ||
4610 | This function partially covers for this limitation by attempting to | |
4611 | remove from the SYMS list renaming symbols that should be visible | |
4612 | from CURRENT_BLOCK. However, there does not seem be a 100% reliable | |
4613 | method with the current information available. The implementation | |
4614 | below has a couple of limitations (FIXME: brobecker-2003-05-12): | |
4615 | ||
4616 | - When the user tries to print a rename in a function while there | |
4617 | is another rename entity defined in a package: Normally, the | |
4618 | rename in the function has precedence over the rename in the | |
4619 | package, so the latter should be removed from the list. This is | |
4620 | currently not the case. | |
4621 | ||
4622 | - This function will incorrectly remove valid renames if | |
4623 | the CURRENT_BLOCK corresponds to a function which symbol name | |
4624 | has been changed by an "Export" pragma. As a consequence, | |
4625 | the user will be unable to print such rename entities. */ | |
4626 | ||
4627 | static int | |
4628 | remove_out_of_scope_renamings (struct ada_symbol_info *syms, | |
4629 | int nsyms, | |
4630 | struct block *current_block) | |
4631 | { | |
4632 | struct symbol *current_function; | |
4633 | char *current_function_name; | |
4634 | int i; | |
4635 | ||
4636 | /* Extract the function name associated to CURRENT_BLOCK. | |
4637 | Abort if unable to do so. */ | |
4638 | ||
4639 | if (current_block == NULL) | |
4640 | return nsyms; | |
4641 | ||
4642 | current_function = block_function (current_block); | |
4643 | if (current_function == NULL) | |
4644 | return nsyms; | |
4645 | ||
4646 | current_function_name = SYMBOL_LINKAGE_NAME (current_function); | |
4647 | if (current_function_name == NULL) | |
4648 | return nsyms; | |
4649 | ||
4650 | /* Check each of the symbols, and remove it from the list if it is | |
4651 | a type corresponding to a renaming that is out of the scope of | |
4652 | the current block. */ | |
4653 | ||
4654 | i = 0; | |
4655 | while (i < nsyms) | |
4656 | { | |
4657 | if (ada_is_object_renaming (syms[i].sym) | |
4658 | && !renaming_is_visible (syms[i].sym, current_function_name)) | |
4659 | { | |
4660 | int j; | |
4661 | for (j = i + 1; j < nsyms; j++) | |
4662 | syms[j - 1] = syms[j]; | |
4663 | nsyms -= 1; | |
4664 | } | |
4665 | else | |
4666 | i += 1; | |
4667 | } | |
4668 | ||
4669 | return nsyms; | |
4670 | } | |
4671 | ||
4672 | /* Find symbols in DOMAIN matching NAME0, in BLOCK0 and enclosing | |
4673 | scope and in global scopes, returning the number of matches. Sets | |
4674 | *RESULTS to point to a vector of (SYM,BLOCK,SYMTAB) triples, | |
4675 | indicating the symbols found and the blocks and symbol tables (if | |
4676 | any) in which they were found. This vector are transient---good only to | |
4677 | the next call of ada_lookup_symbol_list. Any non-function/non-enumeral | |
4678 | symbol match within the nest of blocks whose innermost member is BLOCK0, | |
4679 | is the one match returned (no other matches in that or | |
4680 | enclosing blocks is returned). If there are any matches in or | |
4681 | surrounding BLOCK0, then these alone are returned. Otherwise, the | |
4682 | search extends to global and file-scope (static) symbol tables. | |
4683 | Names prefixed with "standard__" are handled specially: "standard__" | |
4684 | is first stripped off, and only static and global symbols are searched. */ | |
14f9c5c9 AS |
4685 | |
4686 | int | |
4c4b4cd2 PH |
4687 | ada_lookup_symbol_list (const char *name0, const struct block *block0, |
4688 | domain_enum namespace, | |
4689 | struct ada_symbol_info **results) | |
14f9c5c9 AS |
4690 | { |
4691 | struct symbol *sym; | |
4692 | struct symtab *s; | |
4693 | struct partial_symtab *ps; | |
4694 | struct blockvector *bv; | |
4695 | struct objfile *objfile; | |
14f9c5c9 | 4696 | struct block *block; |
4c4b4cd2 | 4697 | const char *name; |
14f9c5c9 | 4698 | struct minimal_symbol *msymbol; |
4c4b4cd2 | 4699 | int wild_match; |
14f9c5c9 | 4700 | int cacheIfUnique; |
4c4b4cd2 PH |
4701 | int block_depth; |
4702 | int ndefns; | |
14f9c5c9 | 4703 | |
4c4b4cd2 PH |
4704 | obstack_free (&symbol_list_obstack, NULL); |
4705 | obstack_init (&symbol_list_obstack); | |
14f9c5c9 | 4706 | |
14f9c5c9 AS |
4707 | cacheIfUnique = 0; |
4708 | ||
4709 | /* Search specified block and its superiors. */ | |
4710 | ||
4c4b4cd2 PH |
4711 | wild_match = (strstr (name0, "__") == NULL); |
4712 | name = name0; | |
4713 | block = (struct block *) block0; /* FIXME: No cast ought to be | |
4714 | needed, but adding const will | |
4715 | have a cascade effect. */ | |
4716 | if (strncmp (name0, "standard__", sizeof ("standard__") - 1) == 0) | |
4717 | { | |
4718 | wild_match = 0; | |
4719 | block = NULL; | |
4720 | name = name0 + sizeof ("standard__") - 1; | |
4721 | } | |
4722 | ||
4723 | block_depth = 0; | |
14f9c5c9 AS |
4724 | while (block != NULL) |
4725 | { | |
4c4b4cd2 PH |
4726 | block_depth += 1; |
4727 | ada_add_block_symbols (&symbol_list_obstack, block, name, | |
4728 | namespace, NULL, NULL, wild_match); | |
14f9c5c9 | 4729 | |
4c4b4cd2 PH |
4730 | /* If we found a non-function match, assume that's the one. */ |
4731 | if (is_nonfunction (defns_collected (&symbol_list_obstack, 0), | |
4732 | num_defns_collected (&symbol_list_obstack))) | |
4733 | goto done; | |
14f9c5c9 AS |
4734 | |
4735 | block = BLOCK_SUPERBLOCK (block); | |
4736 | } | |
4737 | ||
4c4b4cd2 PH |
4738 | /* If no luck so far, try to find NAME as a local symbol in some lexically |
4739 | enclosing subprogram. */ | |
4740 | if (num_defns_collected (&symbol_list_obstack) == 0 && block_depth > 2) | |
4741 | add_symbols_from_enclosing_procs (&symbol_list_obstack, | |
4742 | name, namespace, wild_match); | |
4743 | ||
4744 | /* If we found ANY matches among non-global symbols, we're done. */ | |
14f9c5c9 | 4745 | |
4c4b4cd2 | 4746 | if (num_defns_collected (&symbol_list_obstack) > 0) |
14f9c5c9 | 4747 | goto done; |
d2e4a39e | 4748 | |
14f9c5c9 | 4749 | cacheIfUnique = 1; |
4c4b4cd2 PH |
4750 | if (lookup_cached_symbol (name0, namespace, &sym, &block, &s)) |
4751 | { | |
4752 | if (sym != NULL) | |
4753 | add_defn_to_vec (&symbol_list_obstack, sym, block, s); | |
4754 | goto done; | |
4755 | } | |
14f9c5c9 AS |
4756 | |
4757 | /* Now add symbols from all global blocks: symbol tables, minimal symbol | |
4c4b4cd2 | 4758 | tables, and psymtab's. */ |
14f9c5c9 AS |
4759 | |
4760 | ALL_SYMTABS (objfile, s) | |
d2e4a39e AS |
4761 | { |
4762 | QUIT; | |
4763 | if (!s->primary) | |
4764 | continue; | |
4765 | bv = BLOCKVECTOR (s); | |
4766 | block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); | |
4c4b4cd2 PH |
4767 | ada_add_block_symbols (&symbol_list_obstack, block, name, namespace, |
4768 | objfile, s, wild_match); | |
d2e4a39e | 4769 | } |
14f9c5c9 | 4770 | |
4c4b4cd2 | 4771 | if (namespace == VAR_DOMAIN) |
14f9c5c9 AS |
4772 | { |
4773 | ALL_MSYMBOLS (objfile, msymbol) | |
d2e4a39e | 4774 | { |
4c4b4cd2 PH |
4775 | if (ada_match_name (SYMBOL_LINKAGE_NAME (msymbol), name, wild_match)) |
4776 | { | |
4777 | switch (MSYMBOL_TYPE (msymbol)) | |
4778 | { | |
4779 | case mst_solib_trampoline: | |
4780 | break; | |
4781 | default: | |
4782 | s = find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol)); | |
4783 | if (s != NULL) | |
4784 | { | |
4785 | int ndefns0 = num_defns_collected (&symbol_list_obstack); | |
4786 | QUIT; | |
4787 | bv = BLOCKVECTOR (s); | |
4788 | block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); | |
4789 | ada_add_block_symbols (&symbol_list_obstack, block, | |
4790 | SYMBOL_LINKAGE_NAME (msymbol), | |
4791 | namespace, objfile, s, wild_match); | |
4792 | ||
4793 | if (num_defns_collected (&symbol_list_obstack) == ndefns0) | |
4794 | { | |
4795 | block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK); | |
4796 | ada_add_block_symbols (&symbol_list_obstack, block, | |
4797 | SYMBOL_LINKAGE_NAME (msymbol), | |
4798 | namespace, objfile, s, | |
4799 | wild_match); | |
4800 | } | |
4801 | } | |
4802 | } | |
4803 | } | |
d2e4a39e | 4804 | } |
14f9c5c9 | 4805 | } |
d2e4a39e | 4806 | |
14f9c5c9 | 4807 | ALL_PSYMTABS (objfile, ps) |
d2e4a39e AS |
4808 | { |
4809 | QUIT; | |
4810 | if (!ps->readin | |
4c4b4cd2 | 4811 | && ada_lookup_partial_symbol (ps, name, 1, namespace, wild_match)) |
d2e4a39e | 4812 | { |
4c4b4cd2 PH |
4813 | s = PSYMTAB_TO_SYMTAB (ps); |
4814 | if (!s->primary) | |
4815 | continue; | |
4816 | bv = BLOCKVECTOR (s); | |
4817 | block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); | |
4818 | ada_add_block_symbols (&symbol_list_obstack, block, name, | |
4819 | namespace, objfile, s, wild_match); | |
d2e4a39e AS |
4820 | } |
4821 | } | |
4822 | ||
4c4b4cd2 | 4823 | /* Now add symbols from all per-file blocks if we've gotten no hits |
14f9c5c9 | 4824 | (Not strictly correct, but perhaps better than an error). |
4c4b4cd2 | 4825 | Do the symtabs first, then check the psymtabs. */ |
d2e4a39e | 4826 | |
4c4b4cd2 | 4827 | if (num_defns_collected (&symbol_list_obstack) == 0) |
14f9c5c9 AS |
4828 | { |
4829 | ||
4830 | ALL_SYMTABS (objfile, s) | |
d2e4a39e | 4831 | { |
4c4b4cd2 PH |
4832 | QUIT; |
4833 | if (!s->primary) | |
4834 | continue; | |
4835 | bv = BLOCKVECTOR (s); | |
4836 | block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK); | |
4837 | ada_add_block_symbols (&symbol_list_obstack, block, name, namespace, | |
4838 | objfile, s, wild_match); | |
d2e4a39e AS |
4839 | } |
4840 | ||
14f9c5c9 | 4841 | ALL_PSYMTABS (objfile, ps) |
d2e4a39e | 4842 | { |
4c4b4cd2 PH |
4843 | QUIT; |
4844 | if (!ps->readin | |
4845 | && ada_lookup_partial_symbol (ps, name, 0, namespace, wild_match)) | |
4846 | { | |
4847 | s = PSYMTAB_TO_SYMTAB (ps); | |
4848 | bv = BLOCKVECTOR (s); | |
4849 | if (!s->primary) | |
4850 | continue; | |
4851 | block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK); | |
4852 | ada_add_block_symbols (&symbol_list_obstack, block, name, | |
4853 | namespace, objfile, s, wild_match); | |
4854 | } | |
d2e4a39e AS |
4855 | } |
4856 | } | |
14f9c5c9 | 4857 | |
4c4b4cd2 PH |
4858 | done: |
4859 | ndefns = num_defns_collected (&symbol_list_obstack); | |
4860 | *results = defns_collected (&symbol_list_obstack, 1); | |
4861 | ||
4862 | ndefns = remove_extra_symbols (*results, ndefns); | |
4863 | ||
d2e4a39e | 4864 | if (ndefns == 0) |
4c4b4cd2 | 4865 | cache_symbol (name0, namespace, NULL, NULL, NULL); |
14f9c5c9 | 4866 | |
4c4b4cd2 PH |
4867 | if (ndefns == 1 && cacheIfUnique) |
4868 | cache_symbol (name0, namespace, (*results)[0].sym, (*results)[0].block, | |
4869 | (*results)[0].symtab); | |
14f9c5c9 | 4870 | |
4c4b4cd2 PH |
4871 | ndefns = remove_out_of_scope_renamings (*results, ndefns, |
4872 | (struct block *) block0); | |
14f9c5c9 | 4873 | |
14f9c5c9 AS |
4874 | return ndefns; |
4875 | } | |
4876 | ||
4c4b4cd2 PH |
4877 | /* Return a symbol in DOMAIN matching NAME, in BLOCK0 and enclosing |
4878 | scope and in global scopes, or NULL if none. NAME is folded and | |
4879 | encoded first. Otherwise, the result is as for ada_lookup_symbol_list, | |
4880 | but is disambiguated by user query if needed. *IS_A_FIELD_OF_THIS is | |
4881 | set to 0 and *SYMTAB is set to the symbol table in which the symbol | |
4882 | was found (in both cases, these assignments occur only if the | |
4883 | pointers are non-null). */ | |
4884 | ||
14f9c5c9 | 4885 | |
d2e4a39e | 4886 | struct symbol * |
4c4b4cd2 PH |
4887 | ada_lookup_symbol (const char *name, const struct block *block0, |
4888 | domain_enum namespace, int *is_a_field_of_this, | |
4889 | struct symtab **symtab) | |
14f9c5c9 | 4890 | { |
4c4b4cd2 | 4891 | struct ada_symbol_info *candidates; |
14f9c5c9 AS |
4892 | int n_candidates; |
4893 | ||
4c4b4cd2 PH |
4894 | n_candidates = ada_lookup_symbol_list (ada_encode (ada_fold_name (name)), |
4895 | block0, namespace, &candidates); | |
14f9c5c9 AS |
4896 | |
4897 | if (n_candidates == 0) | |
4898 | return NULL; | |
4899 | else if (n_candidates != 1) | |
4c4b4cd2 PH |
4900 | user_select_syms (candidates, n_candidates, 1); |
4901 | ||
4902 | if (is_a_field_of_this != NULL) | |
4903 | *is_a_field_of_this = 0; | |
4904 | ||
4905 | if (symtab != NULL) | |
4906 | { | |
4907 | *symtab = candidates[0].symtab; | |
4908 | if (*symtab == NULL && candidates[0].block != NULL) | |
4909 | { | |
4910 | struct objfile *objfile; | |
4911 | struct symtab *s; | |
4912 | struct block *b; | |
4913 | struct blockvector *bv; | |
4914 | ||
4915 | /* Search the list of symtabs for one which contains the | |
4916 | address of the start of this block. */ | |
4917 | ALL_SYMTABS (objfile, s) | |
4918 | { | |
4919 | bv = BLOCKVECTOR (s); | |
4920 | b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); | |
4921 | if (BLOCK_START (b) <= BLOCK_START (candidates[0].block) | |
4922 | && BLOCK_END (b) > BLOCK_START (candidates[0].block)) | |
4923 | { | |
4924 | *symtab = s; | |
4925 | return fixup_symbol_section (candidates[0].sym, objfile); | |
4926 | } | |
4927 | return fixup_symbol_section (candidates[0].sym, NULL); | |
4928 | } | |
4929 | } | |
4930 | } | |
4931 | return candidates[0].sym; | |
4932 | } | |
14f9c5c9 | 4933 | |
4c4b4cd2 PH |
4934 | static struct symbol * |
4935 | ada_lookup_symbol_nonlocal (const char *name, | |
4936 | const char *linkage_name, | |
4937 | const struct block *block, | |
4938 | const domain_enum domain, | |
4939 | struct symtab **symtab) | |
4940 | { | |
4941 | if (linkage_name == NULL) | |
4942 | linkage_name = name; | |
4943 | return ada_lookup_symbol (linkage_name, block_static_block (block), domain, | |
4944 | NULL, symtab); | |
14f9c5c9 AS |
4945 | } |
4946 | ||
4947 | ||
4c4b4cd2 PH |
4948 | /* True iff STR is a possible encoded suffix of a normal Ada name |
4949 | that is to be ignored for matching purposes. Suffixes of parallel | |
4950 | names (e.g., XVE) are not included here. Currently, the possible suffixes | |
4951 | are given by either of the regular expression: | |
4952 | ||
4953 | (__[0-9]+)?\.[0-9]+ [nested subprogram suffix, on platforms such as Linux] | |
4954 | ___[0-9]+ [nested subprogram suffix, on platforms such as HP/UX] | |
4955 | (X[nb]*)?((\$|__)[0-9](_?[0-9]+)|___(LJM|X([FDBUP].*|R[^T]?)))?$ | |
14f9c5c9 | 4956 | */ |
4c4b4cd2 | 4957 | |
14f9c5c9 | 4958 | static int |
d2e4a39e | 4959 | is_name_suffix (const char *str) |
14f9c5c9 AS |
4960 | { |
4961 | int k; | |
4c4b4cd2 PH |
4962 | const char *matching; |
4963 | const int len = strlen (str); | |
4964 | ||
4965 | /* (__[0-9]+)?\.[0-9]+ */ | |
4966 | matching = str; | |
4967 | if (len > 3 && str[0] == '_' && str[1] == '_' && isdigit (str[2])) | |
4968 | { | |
4969 | matching += 3; | |
4970 | while (isdigit (matching[0])) | |
4971 | matching += 1; | |
4972 | if (matching[0] == '\0') | |
4973 | return 1; | |
4974 | } | |
4975 | ||
4976 | if (matching[0] == '.') | |
4977 | { | |
4978 | matching += 1; | |
4979 | while (isdigit (matching[0])) | |
4980 | matching += 1; | |
4981 | if (matching[0] == '\0') | |
4982 | return 1; | |
4983 | } | |
4984 | ||
4985 | /* ___[0-9]+ */ | |
4986 | if (len > 3 && str[0] == '_' && str[1] == '_' && str[2] == '_') | |
4987 | { | |
4988 | matching = str + 3; | |
4989 | while (isdigit (matching[0])) | |
4990 | matching += 1; | |
4991 | if (matching[0] == '\0') | |
4992 | return 1; | |
4993 | } | |
4994 | ||
4995 | /* ??? We should not modify STR directly, as we are doing below. This | |
4996 | is fine in this case, but may become problematic later if we find | |
4997 | that this alternative did not work, and want to try matching | |
4998 | another one from the begining of STR. Since we modified it, we | |
4999 | won't be able to find the begining of the string anymore! */ | |
14f9c5c9 AS |
5000 | if (str[0] == 'X') |
5001 | { | |
5002 | str += 1; | |
d2e4a39e | 5003 | while (str[0] != '_' && str[0] != '\0') |
4c4b4cd2 PH |
5004 | { |
5005 | if (str[0] != 'n' && str[0] != 'b') | |
5006 | return 0; | |
5007 | str += 1; | |
5008 | } | |
14f9c5c9 AS |
5009 | } |
5010 | if (str[0] == '\000') | |
5011 | return 1; | |
d2e4a39e | 5012 | if (str[0] == '_') |
14f9c5c9 AS |
5013 | { |
5014 | if (str[1] != '_' || str[2] == '\000') | |
4c4b4cd2 | 5015 | return 0; |
d2e4a39e | 5016 | if (str[2] == '_') |
4c4b4cd2 PH |
5017 | { |
5018 | if (strcmp (str + 3, "LJM") == 0) | |
5019 | return 1; | |
5020 | if (str[3] != 'X') | |
5021 | return 0; | |
5022 | if (str[4] == 'F' || str[4] == 'D' || str[4] == 'B' || | |
5023 | str[4] == 'U' || str[4] == 'P') | |
5024 | return 1; | |
5025 | if (str[4] == 'R' && str[5] != 'T') | |
5026 | return 1; | |
5027 | return 0; | |
5028 | } | |
5029 | if (!isdigit (str[2])) | |
5030 | return 0; | |
5031 | for (k = 3; str[k] != '\0'; k += 1) | |
5032 | if (!isdigit (str[k]) && str[k] != '_') | |
5033 | return 0; | |
14f9c5c9 AS |
5034 | return 1; |
5035 | } | |
4c4b4cd2 | 5036 | if (str[0] == '$' && isdigit (str[1])) |
14f9c5c9 | 5037 | { |
4c4b4cd2 PH |
5038 | for (k = 2; str[k] != '\0'; k += 1) |
5039 | if (!isdigit (str[k]) && str[k] != '_') | |
5040 | return 0; | |
14f9c5c9 AS |
5041 | return 1; |
5042 | } | |
5043 | return 0; | |
5044 | } | |
d2e4a39e | 5045 | |
4c4b4cd2 PH |
5046 | /* Return nonzero if the given string starts with a dot ('.') |
5047 | followed by zero or more digits. | |
5048 | ||
5049 | Note: brobecker/2003-11-10: A forward declaration has not been | |
5050 | added at the begining of this file yet, because this function | |
5051 | is only used to work around a problem found during wild matching | |
5052 | when trying to match minimal symbol names against symbol names | |
5053 | obtained from dwarf-2 data. This function is therefore currently | |
5054 | only used in wild_match() and is likely to be deleted when the | |
5055 | problem in dwarf-2 is fixed. */ | |
5056 | ||
5057 | static int | |
5058 | is_dot_digits_suffix (const char *str) | |
5059 | { | |
5060 | if (str[0] != '.') | |
5061 | return 0; | |
5062 | ||
5063 | str++; | |
5064 | while (isdigit (str[0])) | |
5065 | str++; | |
5066 | return (str[0] == '\0'); | |
5067 | } | |
5068 | ||
5069 | /* True if NAME represents a name of the form A1.A2....An, n>=1 and | |
5070 | PATN[0..PATN_LEN-1] = Ak.Ak+1.....An for some k >= 1. Ignores | |
5071 | informational suffixes of NAME (i.e., for which is_name_suffix is | |
5072 | true). */ | |
5073 | ||
14f9c5c9 | 5074 | static int |
4c4b4cd2 | 5075 | wild_match (const char *patn0, int patn_len, const char *name0) |
14f9c5c9 AS |
5076 | { |
5077 | int name_len; | |
4c4b4cd2 PH |
5078 | char *name; |
5079 | char *patn; | |
5080 | ||
5081 | /* FIXME: brobecker/2003-11-10: For some reason, the symbol name | |
5082 | stored in the symbol table for nested function names is sometimes | |
5083 | different from the name of the associated entity stored in | |
5084 | the dwarf-2 data: This is the case for nested subprograms, where | |
5085 | the minimal symbol name contains a trailing ".[:digit:]+" suffix, | |
5086 | while the symbol name from the dwarf-2 data does not. | |
5087 | ||
5088 | Although the DWARF-2 standard documents that entity names stored | |
5089 | in the dwarf-2 data should be identical to the name as seen in | |
5090 | the source code, GNAT takes a different approach as we already use | |
5091 | a special encoding mechanism to convey the information so that | |
5092 | a C debugger can still use the information generated to debug | |
5093 | Ada programs. A corollary is that the symbol names in the dwarf-2 | |
5094 | data should match the names found in the symbol table. I therefore | |
5095 | consider this issue as a compiler defect. | |
5096 | ||
5097 | Until the compiler is properly fixed, we work-around the problem | |
5098 | by ignoring such suffixes during the match. We do so by making | |
5099 | a copy of PATN0 and NAME0, and then by stripping such a suffix | |
5100 | if present. We then perform the match on the resulting strings. */ | |
5101 | { | |
5102 | char *dot; | |
5103 | name_len = strlen (name0); | |
5104 | ||
5105 | name = (char *) alloca ((name_len + 1) * sizeof (char)); | |
5106 | strcpy (name, name0); | |
5107 | dot = strrchr (name, '.'); | |
5108 | if (dot != NULL && is_dot_digits_suffix (dot)) | |
5109 | *dot = '\0'; | |
5110 | ||
5111 | patn = (char *) alloca ((patn_len + 1) * sizeof (char)); | |
5112 | strncpy (patn, patn0, patn_len); | |
5113 | patn[patn_len] = '\0'; | |
5114 | dot = strrchr (patn, '.'); | |
5115 | if (dot != NULL && is_dot_digits_suffix (dot)) | |
5116 | { | |
5117 | *dot = '\0'; | |
5118 | patn_len = dot - patn; | |
5119 | } | |
5120 | } | |
5121 | ||
5122 | /* Now perform the wild match. */ | |
14f9c5c9 AS |
5123 | |
5124 | name_len = strlen (name); | |
4c4b4cd2 PH |
5125 | if (name_len >= patn_len + 5 && strncmp (name, "_ada_", 5) == 0 |
5126 | && strncmp (patn, name + 5, patn_len) == 0 | |
d2e4a39e | 5127 | && is_name_suffix (name + patn_len + 5)) |
14f9c5c9 AS |
5128 | return 1; |
5129 | ||
d2e4a39e | 5130 | while (name_len >= patn_len) |
14f9c5c9 | 5131 | { |
4c4b4cd2 PH |
5132 | if (strncmp (patn, name, patn_len) == 0 |
5133 | && is_name_suffix (name + patn_len)) | |
5134 | return 1; | |
5135 | do | |
5136 | { | |
5137 | name += 1; | |
5138 | name_len -= 1; | |
5139 | } | |
d2e4a39e | 5140 | while (name_len > 0 |
4c4b4cd2 | 5141 | && name[0] != '.' && (name[0] != '_' || name[1] != '_')); |
14f9c5c9 | 5142 | if (name_len <= 0) |
4c4b4cd2 | 5143 | return 0; |
14f9c5c9 | 5144 | if (name[0] == '_') |
4c4b4cd2 PH |
5145 | { |
5146 | if (!islower (name[2])) | |
5147 | return 0; | |
5148 | name += 2; | |
5149 | name_len -= 2; | |
5150 | } | |
14f9c5c9 | 5151 | else |
4c4b4cd2 PH |
5152 | { |
5153 | if (!islower (name[1])) | |
5154 | return 0; | |
5155 | name += 1; | |
5156 | name_len -= 1; | |
5157 | } | |
14f9c5c9 AS |
5158 | } |
5159 | ||
5160 | return 0; | |
5161 | } | |
5162 | ||
5163 | ||
4c4b4cd2 PH |
5164 | /* Add symbols from BLOCK matching identifier NAME in DOMAIN to |
5165 | vector *defn_symbols, updating the list of symbols in OBSTACKP | |
5166 | (if necessary). If WILD, treat as NAME with a wildcard prefix. | |
5167 | OBJFILE is the section containing BLOCK. | |
5168 | SYMTAB is recorded with each symbol added. */ | |
14f9c5c9 | 5169 | |
d2e4a39e | 5170 | static void |
4c4b4cd2 PH |
5171 | ada_add_block_symbols (struct obstack *obstackp, |
5172 | struct block *block, const char *name, | |
5173 | domain_enum domain, struct objfile *objfile, | |
5174 | struct symtab *symtab, int wild) | |
14f9c5c9 | 5175 | { |
de4f826b | 5176 | struct dict_iterator iter; |
14f9c5c9 | 5177 | int name_len = strlen (name); |
4c4b4cd2 | 5178 | /* A matching argument symbol, if any. */ |
14f9c5c9 | 5179 | struct symbol *arg_sym; |
4c4b4cd2 | 5180 | /* Set true when we find a matching non-argument symbol. */ |
14f9c5c9 | 5181 | int found_sym; |
261397f8 | 5182 | struct symbol *sym; |
14f9c5c9 | 5183 | |
d2e4a39e AS |
5184 | arg_sym = NULL; |
5185 | found_sym = 0; | |
14f9c5c9 AS |
5186 | if (wild) |
5187 | { | |
261397f8 | 5188 | struct symbol *sym; |
de4f826b | 5189 | ALL_BLOCK_SYMBOLS (block, iter, sym) |
4c4b4cd2 PH |
5190 | { |
5191 | if (SYMBOL_DOMAIN (sym) == domain && | |
5192 | wild_match (name, name_len, SYMBOL_LINKAGE_NAME (sym))) | |
5193 | { | |
5194 | switch (SYMBOL_CLASS (sym)) | |
5195 | { | |
5196 | case LOC_ARG: | |
5197 | case LOC_LOCAL_ARG: | |
5198 | case LOC_REF_ARG: | |
5199 | case LOC_REGPARM: | |
5200 | case LOC_REGPARM_ADDR: | |
5201 | case LOC_BASEREG_ARG: | |
5202 | case LOC_COMPUTED_ARG: | |
5203 | arg_sym = sym; | |
5204 | break; | |
5205 | case LOC_UNRESOLVED: | |
5206 | continue; | |
5207 | default: | |
5208 | found_sym = 1; | |
5209 | add_defn_to_vec (obstackp, | |
5210 | fixup_symbol_section (sym, objfile), | |
5211 | block, symtab); | |
5212 | break; | |
5213 | } | |
5214 | } | |
5215 | } | |
14f9c5c9 | 5216 | } |
d2e4a39e | 5217 | else |
14f9c5c9 | 5218 | { |
de4f826b | 5219 | ALL_BLOCK_SYMBOLS (block, iter, sym) |
4c4b4cd2 PH |
5220 | { |
5221 | if (SYMBOL_DOMAIN (sym) == domain) | |
5222 | { | |
5223 | int cmp = strncmp (name, SYMBOL_LINKAGE_NAME (sym), name_len); | |
5224 | if (cmp == 0 | |
5225 | && is_name_suffix (SYMBOL_LINKAGE_NAME (sym) + name_len)) | |
5226 | { | |
5227 | switch (SYMBOL_CLASS (sym)) | |
5228 | { | |
5229 | case LOC_ARG: | |
5230 | case LOC_LOCAL_ARG: | |
5231 | case LOC_REF_ARG: | |
5232 | case LOC_REGPARM: | |
5233 | case LOC_REGPARM_ADDR: | |
5234 | case LOC_BASEREG_ARG: | |
5235 | case LOC_COMPUTED_ARG: | |
5236 | arg_sym = sym; | |
5237 | break; | |
5238 | case LOC_UNRESOLVED: | |
5239 | break; | |
5240 | default: | |
5241 | found_sym = 1; | |
5242 | add_defn_to_vec (obstackp, | |
5243 | fixup_symbol_section (sym, objfile), | |
5244 | block, symtab); | |
5245 | break; | |
5246 | } | |
5247 | } | |
5248 | } | |
5249 | } | |
14f9c5c9 AS |
5250 | } |
5251 | ||
d2e4a39e | 5252 | if (!found_sym && arg_sym != NULL) |
14f9c5c9 | 5253 | { |
4c4b4cd2 PH |
5254 | add_defn_to_vec (obstackp, |
5255 | fixup_symbol_section (arg_sym, objfile), | |
5256 | block, symtab); | |
14f9c5c9 AS |
5257 | } |
5258 | ||
d2e4a39e | 5259 | if (!wild) |
14f9c5c9 | 5260 | { |
d2e4a39e AS |
5261 | arg_sym = NULL; |
5262 | found_sym = 0; | |
14f9c5c9 | 5263 | |
de4f826b | 5264 | ALL_BLOCK_SYMBOLS (block, iter, sym) |
261397f8 | 5265 | { |
176620f1 | 5266 | if (SYMBOL_DOMAIN (sym) == domain) |
261397f8 DJ |
5267 | { |
5268 | int cmp; | |
14f9c5c9 | 5269 | |
4c4b4cd2 | 5270 | cmp = (int) '_' - (int) SYMBOL_LINKAGE_NAME (sym)[0]; |
d2e4a39e | 5271 | if (cmp == 0) |
261397f8 | 5272 | { |
4c4b4cd2 | 5273 | cmp = strncmp ("_ada_", SYMBOL_LINKAGE_NAME (sym), 5); |
261397f8 | 5274 | if (cmp == 0) |
4c4b4cd2 PH |
5275 | cmp = strncmp (name, SYMBOL_LINKAGE_NAME (sym) + 5, |
5276 | name_len); | |
261397f8 DJ |
5277 | } |
5278 | ||
526e70c0 | 5279 | if (cmp == 0 |
4c4b4cd2 | 5280 | && is_name_suffix (SYMBOL_LINKAGE_NAME (sym) + name_len + 5)) |
261397f8 DJ |
5281 | { |
5282 | switch (SYMBOL_CLASS (sym)) | |
5283 | { | |
5284 | case LOC_ARG: | |
5285 | case LOC_LOCAL_ARG: | |
5286 | case LOC_REF_ARG: | |
5287 | case LOC_REGPARM: | |
5288 | case LOC_REGPARM_ADDR: | |
5289 | case LOC_BASEREG_ARG: | |
4c2df51b | 5290 | case LOC_COMPUTED_ARG: |
261397f8 DJ |
5291 | arg_sym = sym; |
5292 | break; | |
5293 | case LOC_UNRESOLVED: | |
5294 | break; | |
5295 | default: | |
5296 | found_sym = 1; | |
4c4b4cd2 PH |
5297 | add_defn_to_vec (obstackp, |
5298 | fixup_symbol_section (sym, objfile), | |
5299 | block, symtab); | |
261397f8 DJ |
5300 | break; |
5301 | } | |
5302 | } | |
5303 | } | |
4c4b4cd2 | 5304 | end_loop2: ; |
261397f8 | 5305 | } |
d2e4a39e | 5306 | |
14f9c5c9 | 5307 | /* NOTE: This really shouldn't be needed for _ada_ symbols. |
4c4b4cd2 | 5308 | They aren't parameters, right? */ |
d2e4a39e | 5309 | if (!found_sym && arg_sym != NULL) |
4c4b4cd2 PH |
5310 | { |
5311 | add_defn_to_vec (obstackp, | |
5312 | fixup_symbol_section (arg_sym, objfile), | |
5313 | block, symtab); | |
5314 | } | |
14f9c5c9 AS |
5315 | } |
5316 | } | |
14f9c5c9 | 5317 | \f |
4c4b4cd2 | 5318 | /* Breakpoint-related */ |
d2e4a39e | 5319 | |
4c4b4cd2 PH |
5320 | /* Import message from symtab.c. */ |
5321 | extern char no_symtab_msg[]; | |
14f9c5c9 AS |
5322 | |
5323 | /* Assuming that LINE is pointing at the beginning of an argument to | |
5324 | 'break', return a pointer to the delimiter for the initial segment | |
4c4b4cd2 PH |
5325 | of that name. This is the first ':', ' ', or end of LINE. */ |
5326 | ||
d2e4a39e AS |
5327 | char * |
5328 | ada_start_decode_line_1 (char *line) | |
14f9c5c9 | 5329 | { |
4c4b4cd2 PH |
5330 | /* NOTE: strpbrk would be more elegant, but I am reluctant to be |
5331 | the first to use such a library function in GDB code. */ | |
d2e4a39e | 5332 | char *p; |
14f9c5c9 AS |
5333 | for (p = line; *p != '\000' && *p != ' ' && *p != ':'; p += 1) |
5334 | ; | |
5335 | return p; | |
5336 | } | |
5337 | ||
5338 | /* *SPEC points to a function and line number spec (as in a break | |
5339 | command), following any initial file name specification. | |
5340 | ||
5341 | Return all symbol table/line specfications (sals) consistent with the | |
4c4b4cd2 | 5342 | information in *SPEC and FILE_TABLE in the following sense: |
14f9c5c9 AS |
5343 | + FILE_TABLE is null, or the sal refers to a line in the file |
5344 | named by FILE_TABLE. | |
5345 | + If *SPEC points to an argument with a trailing ':LINENUM', | |
4c4b4cd2 | 5346 | then the sal refers to that line (or one following it as closely as |
14f9c5c9 | 5347 | possible). |
4c4b4cd2 | 5348 | + If *SPEC does not start with '*', the sal is in a function with |
14f9c5c9 AS |
5349 | that name. |
5350 | ||
5351 | Returns with 0 elements if no matching non-minimal symbols found. | |
5352 | ||
5353 | If *SPEC begins with a function name of the form <NAME>, then NAME | |
5354 | is taken as a literal name; otherwise the function name is subject | |
4c4b4cd2 | 5355 | to the usual encoding. |
14f9c5c9 AS |
5356 | |
5357 | *SPEC is updated to point after the function/line number specification. | |
5358 | ||
5359 | FUNFIRSTLINE is non-zero if we desire the first line of real code | |
4c4b4cd2 | 5360 | in each function. |
14f9c5c9 AS |
5361 | |
5362 | If CANONICAL is non-NULL, and if any of the sals require a | |
5363 | 'canonical line spec', then *CANONICAL is set to point to an array | |
5364 | of strings, corresponding to and equal in length to the returned | |
4c4b4cd2 PH |
5365 | list of sals, such that (*CANONICAL)[i] is non-null and contains a |
5366 | canonical line spec for the ith returned sal, if needed. If no | |
5367 | canonical line specs are required and CANONICAL is non-null, | |
14f9c5c9 AS |
5368 | *CANONICAL is set to NULL. |
5369 | ||
5370 | A 'canonical line spec' is simply a name (in the format of the | |
5371 | breakpoint command) that uniquely identifies a breakpoint position, | |
5372 | with no further contextual information or user selection. It is | |
5373 | needed whenever the file name, function name, and line number | |
5374 | information supplied is insufficient for this unique | |
4c4b4cd2 | 5375 | identification. Currently overloaded functions, the name '*', |
14f9c5c9 AS |
5376 | or static functions without a filename yield a canonical line spec. |
5377 | The array and the line spec strings are allocated on the heap; it | |
4c4b4cd2 | 5378 | is the caller's responsibility to free them. */ |
14f9c5c9 AS |
5379 | |
5380 | struct symtabs_and_lines | |
d2e4a39e | 5381 | ada_finish_decode_line_1 (char **spec, struct symtab *file_table, |
4c4b4cd2 | 5382 | int funfirstline, char ***canonical) |
14f9c5c9 | 5383 | { |
4c4b4cd2 PH |
5384 | struct ada_symbol_info *symbols; |
5385 | const struct block *block; | |
14f9c5c9 AS |
5386 | int n_matches, i, line_num; |
5387 | struct symtabs_and_lines selected; | |
d2e4a39e AS |
5388 | struct cleanup *old_chain = make_cleanup (null_cleanup, NULL); |
5389 | char *name; | |
4c4b4cd2 | 5390 | int is_quoted; |
14f9c5c9 AS |
5391 | |
5392 | int len; | |
d2e4a39e AS |
5393 | char *lower_name; |
5394 | char *unquoted_name; | |
14f9c5c9 | 5395 | |
4c4b4cd2 PH |
5396 | if (file_table == NULL) |
5397 | block = block_static_block (get_selected_block (0)); | |
14f9c5c9 AS |
5398 | else |
5399 | block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (file_table), STATIC_BLOCK); | |
5400 | ||
5401 | if (canonical != NULL) | |
d2e4a39e | 5402 | *canonical = (char **) NULL; |
14f9c5c9 | 5403 | |
4c4b4cd2 PH |
5404 | is_quoted = (**spec && strchr (get_gdb_completer_quote_characters (), |
5405 | **spec) != NULL); | |
5406 | ||
14f9c5c9 | 5407 | name = *spec; |
d2e4a39e | 5408 | if (**spec == '*') |
14f9c5c9 AS |
5409 | *spec += 1; |
5410 | else | |
5411 | { | |
4c4b4cd2 PH |
5412 | if (is_quoted) |
5413 | *spec = skip_quoted (*spec); | |
d2e4a39e | 5414 | while (**spec != '\000' && |
4c4b4cd2 PH |
5415 | !strchr (ada_completer_word_break_characters, **spec)) |
5416 | *spec += 1; | |
14f9c5c9 AS |
5417 | } |
5418 | len = *spec - name; | |
5419 | ||
5420 | line_num = -1; | |
5421 | if (file_table != NULL && (*spec)[0] == ':' && isdigit ((*spec)[1])) | |
5422 | { | |
5423 | line_num = strtol (*spec + 1, spec, 10); | |
d2e4a39e | 5424 | while (**spec == ' ' || **spec == '\t') |
4c4b4cd2 | 5425 | *spec += 1; |
14f9c5c9 AS |
5426 | } |
5427 | ||
d2e4a39e | 5428 | if (name[0] == '*') |
14f9c5c9 AS |
5429 | { |
5430 | if (line_num == -1) | |
4c4b4cd2 | 5431 | error ("Wild-card function with no line number or file name."); |
14f9c5c9 | 5432 | |
4c4b4cd2 PH |
5433 | return ada_sals_for_line (file_table->filename, line_num, |
5434 | funfirstline, canonical, 0); | |
14f9c5c9 AS |
5435 | } |
5436 | ||
5437 | if (name[0] == '\'') | |
5438 | { | |
5439 | name += 1; | |
5440 | len -= 2; | |
5441 | } | |
5442 | ||
5443 | if (name[0] == '<') | |
5444 | { | |
d2e4a39e AS |
5445 | unquoted_name = (char *) alloca (len - 1); |
5446 | memcpy (unquoted_name, name + 1, len - 2); | |
5447 | unquoted_name[len - 2] = '\000'; | |
14f9c5c9 AS |
5448 | lower_name = NULL; |
5449 | } | |
5450 | else | |
5451 | { | |
d2e4a39e | 5452 | unquoted_name = (char *) alloca (len + 1); |
14f9c5c9 AS |
5453 | memcpy (unquoted_name, name, len); |
5454 | unquoted_name[len] = '\000'; | |
d2e4a39e | 5455 | lower_name = (char *) alloca (len + 1); |
14f9c5c9 | 5456 | for (i = 0; i < len; i += 1) |
4c4b4cd2 | 5457 | lower_name[i] = tolower (name[i]); |
14f9c5c9 AS |
5458 | lower_name[len] = '\000'; |
5459 | } | |
5460 | ||
5461 | n_matches = 0; | |
d2e4a39e | 5462 | if (lower_name != NULL) |
4c4b4cd2 PH |
5463 | n_matches = ada_lookup_symbol_list (ada_encode (lower_name), block, |
5464 | VAR_DOMAIN, &symbols); | |
14f9c5c9 | 5465 | if (n_matches == 0) |
d2e4a39e | 5466 | n_matches = ada_lookup_symbol_list (unquoted_name, block, |
4c4b4cd2 | 5467 | VAR_DOMAIN, &symbols); |
14f9c5c9 AS |
5468 | if (n_matches == 0 && line_num >= 0) |
5469 | error ("No line number information found for %s.", unquoted_name); | |
5470 | else if (n_matches == 0) | |
5471 | { | |
5472 | #ifdef HPPA_COMPILER_BUG | |
5473 | /* FIXME: See comment in symtab.c::decode_line_1 */ | |
5474 | #undef volatile | |
5475 | volatile struct symtab_and_line val; | |
4c4b4cd2 | 5476 | #define volatile /*nothing */ |
14f9c5c9 AS |
5477 | #else |
5478 | struct symtab_and_line val; | |
5479 | #endif | |
d2e4a39e | 5480 | struct minimal_symbol *msymbol; |
14f9c5c9 | 5481 | |
fe39c653 | 5482 | init_sal (&val); |
14f9c5c9 AS |
5483 | |
5484 | msymbol = NULL; | |
d2e4a39e | 5485 | if (lower_name != NULL) |
4c4b4cd2 | 5486 | msymbol = ada_lookup_simple_minsym (ada_encode (lower_name)); |
14f9c5c9 | 5487 | if (msymbol == NULL) |
4c4b4cd2 | 5488 | msymbol = ada_lookup_simple_minsym (unquoted_name); |
14f9c5c9 | 5489 | if (msymbol != NULL) |
4c4b4cd2 PH |
5490 | { |
5491 | val.pc = SYMBOL_VALUE_ADDRESS (msymbol); | |
5492 | val.section = SYMBOL_BFD_SECTION (msymbol); | |
5493 | if (funfirstline) | |
5494 | { | |
5495 | val.pc += FUNCTION_START_OFFSET; | |
5496 | SKIP_PROLOGUE (val.pc); | |
5497 | } | |
5498 | selected.sals = (struct symtab_and_line *) | |
5499 | xmalloc (sizeof (struct symtab_and_line)); | |
5500 | selected.sals[0] = val; | |
5501 | selected.nelts = 1; | |
5502 | return selected; | |
5503 | } | |
d2e4a39e | 5504 | |
14f9c5c9 | 5505 | if (!have_full_symbols () && |
4c4b4cd2 PH |
5506 | !have_partial_symbols () && !have_minimal_symbols ()) |
5507 | error ("No symbol table is loaded. Use the \"file\" command."); | |
14f9c5c9 AS |
5508 | |
5509 | error ("Function \"%s\" not defined.", unquoted_name); | |
4c4b4cd2 | 5510 | return selected; /* for lint */ |
14f9c5c9 AS |
5511 | } |
5512 | ||
5513 | if (line_num >= 0) | |
5514 | { | |
4c4b4cd2 PH |
5515 | struct symtabs_and_lines best_sal = |
5516 | find_sal_from_funcs_and_line (file_table->filename, line_num, | |
5517 | symbols, n_matches); | |
5518 | if (funfirstline) | |
5519 | adjust_pc_past_prologue (&best_sal.sals[0].pc); | |
5520 | return best_sal; | |
14f9c5c9 AS |
5521 | } |
5522 | else | |
5523 | { | |
d2e4a39e | 5524 | selected.nelts = |
4c4b4cd2 | 5525 | user_select_syms (symbols, n_matches, n_matches); |
14f9c5c9 AS |
5526 | } |
5527 | ||
d2e4a39e | 5528 | selected.sals = (struct symtab_and_line *) |
14f9c5c9 AS |
5529 | xmalloc (sizeof (struct symtab_and_line) * selected.nelts); |
5530 | memset (selected.sals, 0, selected.nelts * sizeof (selected.sals[i])); | |
aacb1f0a | 5531 | make_cleanup (xfree, selected.sals); |
14f9c5c9 AS |
5532 | |
5533 | i = 0; | |
5534 | while (i < selected.nelts) | |
5535 | { | |
4c4b4cd2 PH |
5536 | if (SYMBOL_CLASS (symbols[i].sym) == LOC_BLOCK) |
5537 | selected.sals[i] | |
5538 | = find_function_start_sal (symbols[i].sym, funfirstline); | |
5539 | else if (SYMBOL_LINE (symbols[i].sym) != 0) | |
5540 | { | |
5541 | selected.sals[i].symtab = | |
5542 | symbols[i].symtab | |
5543 | ? symbols[i].symtab : symtab_for_sym (symbols[i].sym); | |
5544 | selected.sals[i].line = SYMBOL_LINE (symbols[i].sym); | |
5545 | } | |
14f9c5c9 | 5546 | else if (line_num >= 0) |
4c4b4cd2 PH |
5547 | { |
5548 | /* Ignore this choice */ | |
5549 | symbols[i] = symbols[selected.nelts - 1]; | |
5550 | selected.nelts -= 1; | |
5551 | continue; | |
5552 | } | |
d2e4a39e | 5553 | else |
4c4b4cd2 | 5554 | error ("Line number not known for symbol \"%s\"", unquoted_name); |
14f9c5c9 AS |
5555 | i += 1; |
5556 | } | |
5557 | ||
5558 | if (canonical != NULL && (line_num >= 0 || n_matches > 1)) | |
5559 | { | |
d2e4a39e | 5560 | *canonical = (char **) xmalloc (sizeof (char *) * selected.nelts); |
14f9c5c9 | 5561 | for (i = 0; i < selected.nelts; i += 1) |
4c4b4cd2 PH |
5562 | (*canonical)[i] = |
5563 | extended_canonical_line_spec (selected.sals[i], | |
5564 | SYMBOL_PRINT_NAME (symbols[i].sym)); | |
14f9c5c9 | 5565 | } |
d2e4a39e | 5566 | |
14f9c5c9 AS |
5567 | discard_cleanups (old_chain); |
5568 | return selected; | |
d2e4a39e AS |
5569 | } |
5570 | ||
14f9c5c9 | 5571 | /* The (single) sal corresponding to line LINE_NUM in a symbol table |
4c4b4cd2 PH |
5572 | with file name FILENAME that occurs in one of the functions listed |
5573 | in the symbol fields of SYMBOLS[0 .. NSYMS-1]. */ | |
5574 | ||
14f9c5c9 | 5575 | static struct symtabs_and_lines |
d2e4a39e | 5576 | find_sal_from_funcs_and_line (const char *filename, int line_num, |
4c4b4cd2 | 5577 | struct ada_symbol_info *symbols, int nsyms) |
14f9c5c9 AS |
5578 | { |
5579 | struct symtabs_and_lines sals; | |
5580 | int best_index, best; | |
d2e4a39e AS |
5581 | struct linetable *best_linetable; |
5582 | struct objfile *objfile; | |
5583 | struct symtab *s; | |
5584 | struct symtab *best_symtab; | |
14f9c5c9 AS |
5585 | |
5586 | read_all_symtabs (filename); | |
5587 | ||
d2e4a39e AS |
5588 | best_index = 0; |
5589 | best_linetable = NULL; | |
5590 | best_symtab = NULL; | |
14f9c5c9 AS |
5591 | best = 0; |
5592 | ALL_SYMTABS (objfile, s) | |
d2e4a39e AS |
5593 | { |
5594 | struct linetable *l; | |
5595 | int ind, exact; | |
14f9c5c9 | 5596 | |
d2e4a39e | 5597 | QUIT; |
14f9c5c9 | 5598 | |
4c4b4cd2 | 5599 | if (strcmp (filename, s->filename) != 0) |
d2e4a39e AS |
5600 | continue; |
5601 | l = LINETABLE (s); | |
5602 | ind = find_line_in_linetable (l, line_num, symbols, nsyms, &exact); | |
5603 | if (ind >= 0) | |
5604 | { | |
4c4b4cd2 PH |
5605 | if (exact) |
5606 | { | |
5607 | best_index = ind; | |
5608 | best_linetable = l; | |
5609 | best_symtab = s; | |
5610 | goto done; | |
5611 | } | |
5612 | if (best == 0 || l->item[ind].line < best) | |
5613 | { | |
5614 | best = l->item[ind].line; | |
5615 | best_index = ind; | |
5616 | best_linetable = l; | |
5617 | best_symtab = s; | |
5618 | } | |
d2e4a39e AS |
5619 | } |
5620 | } | |
14f9c5c9 AS |
5621 | |
5622 | if (best == 0) | |
5623 | error ("Line number not found in designated function."); | |
5624 | ||
d2e4a39e AS |
5625 | done: |
5626 | ||
14f9c5c9 | 5627 | sals.nelts = 1; |
d2e4a39e | 5628 | sals.sals = (struct symtab_and_line *) xmalloc (sizeof (sals.sals[0])); |
14f9c5c9 | 5629 | |
fe39c653 | 5630 | init_sal (&sals.sals[0]); |
d2e4a39e | 5631 | |
14f9c5c9 AS |
5632 | sals.sals[0].line = best_linetable->item[best_index].line; |
5633 | sals.sals[0].pc = best_linetable->item[best_index].pc; | |
5634 | sals.sals[0].symtab = best_symtab; | |
5635 | ||
5636 | return sals; | |
5637 | } | |
5638 | ||
5639 | /* Return the index in LINETABLE of the best match for LINE_NUM whose | |
4c4b4cd2 PH |
5640 | pc falls within one of the functions denoted by the symbol fields |
5641 | of SYMBOLS[0..NSYMS-1]. Set *EXACTP to 1 if the match is exact, | |
5642 | and 0 otherwise. */ | |
5643 | ||
14f9c5c9 | 5644 | static int |
d2e4a39e | 5645 | find_line_in_linetable (struct linetable *linetable, int line_num, |
4c4b4cd2 | 5646 | struct ada_symbol_info *symbols, int nsyms, int *exactp) |
14f9c5c9 AS |
5647 | { |
5648 | int i, len, best_index, best; | |
5649 | ||
5650 | if (line_num <= 0 || linetable == NULL) | |
5651 | return -1; | |
5652 | ||
5653 | len = linetable->nitems; | |
5654 | for (i = 0, best_index = -1, best = 0; i < len; i += 1) | |
5655 | { | |
5656 | int k; | |
d2e4a39e | 5657 | struct linetable_entry *item = &(linetable->item[i]); |
14f9c5c9 AS |
5658 | |
5659 | for (k = 0; k < nsyms; k += 1) | |
4c4b4cd2 PH |
5660 | { |
5661 | if (symbols[k].sym != NULL | |
5662 | && SYMBOL_CLASS (symbols[k].sym) == LOC_BLOCK | |
5663 | && item->pc >= BLOCK_START (SYMBOL_BLOCK_VALUE (symbols[k].sym)) | |
5664 | && item->pc < BLOCK_END (SYMBOL_BLOCK_VALUE (symbols[k].sym))) | |
5665 | goto candidate; | |
5666 | } | |
14f9c5c9 AS |
5667 | continue; |
5668 | ||
5669 | candidate: | |
5670 | ||
5671 | if (item->line == line_num) | |
4c4b4cd2 PH |
5672 | { |
5673 | *exactp = 1; | |
5674 | return i; | |
5675 | } | |
14f9c5c9 AS |
5676 | |
5677 | if (item->line > line_num && (best == 0 || item->line < best)) | |
4c4b4cd2 PH |
5678 | { |
5679 | best = item->line; | |
5680 | best_index = i; | |
5681 | } | |
14f9c5c9 AS |
5682 | } |
5683 | ||
5684 | *exactp = 0; | |
5685 | return best_index; | |
5686 | } | |
5687 | ||
5688 | /* Find the smallest k >= LINE_NUM such that k is a line number in | |
5689 | LINETABLE, and k falls strictly within a named function that begins at | |
4c4b4cd2 PH |
5690 | or before LINE_NUM. Return -1 if there is no such k. */ |
5691 | ||
14f9c5c9 | 5692 | static int |
d2e4a39e | 5693 | nearest_line_number_in_linetable (struct linetable *linetable, int line_num) |
14f9c5c9 AS |
5694 | { |
5695 | int i, len, best; | |
5696 | ||
5697 | if (line_num <= 0 || linetable == NULL || linetable->nitems == 0) | |
5698 | return -1; | |
5699 | len = linetable->nitems; | |
5700 | ||
d2e4a39e AS |
5701 | i = 0; |
5702 | best = INT_MAX; | |
14f9c5c9 AS |
5703 | while (i < len) |
5704 | { | |
d2e4a39e | 5705 | struct linetable_entry *item = &(linetable->item[i]); |
14f9c5c9 AS |
5706 | |
5707 | if (item->line >= line_num && item->line < best) | |
4c4b4cd2 PH |
5708 | { |
5709 | char *func_name; | |
5710 | CORE_ADDR start, end; | |
5711 | ||
5712 | func_name = NULL; | |
5713 | find_pc_partial_function (item->pc, &func_name, &start, &end); | |
5714 | ||
5715 | if (func_name != NULL && item->pc < end) | |
5716 | { | |
5717 | if (item->line == line_num) | |
5718 | return line_num; | |
5719 | else | |
5720 | { | |
5721 | struct symbol *sym = | |
5722 | standard_lookup (func_name, NULL, VAR_DOMAIN); | |
5723 | if (is_plausible_func_for_line (sym, line_num)) | |
5724 | best = item->line; | |
5725 | else | |
5726 | { | |
5727 | do | |
5728 | i += 1; | |
5729 | while (i < len && linetable->item[i].pc < end); | |
5730 | continue; | |
5731 | } | |
5732 | } | |
5733 | } | |
5734 | } | |
14f9c5c9 AS |
5735 | |
5736 | i += 1; | |
5737 | } | |
5738 | ||
5739 | return (best == INT_MAX) ? -1 : best; | |
5740 | } | |
5741 | ||
5742 | ||
4c4b4cd2 | 5743 | /* Return the next higher index, k, into LINETABLE such that k > IND, |
14f9c5c9 | 5744 | entry k in LINETABLE has a line number equal to LINE_NUM, k |
4c4b4cd2 | 5745 | corresponds to a PC that is in a function different from that |
14f9c5c9 | 5746 | corresponding to IND, and falls strictly within a named function |
4c4b4cd2 PH |
5747 | that begins at a line at or preceding STARTING_LINE. |
5748 | Return -1 if there is no such k. | |
5749 | IND == -1 corresponds to no function. */ | |
14f9c5c9 AS |
5750 | |
5751 | static int | |
d2e4a39e | 5752 | find_next_line_in_linetable (struct linetable *linetable, int line_num, |
4c4b4cd2 | 5753 | int starting_line, int ind) |
14f9c5c9 AS |
5754 | { |
5755 | int i, len; | |
5756 | ||
5757 | if (line_num <= 0 || linetable == NULL || ind >= linetable->nitems) | |
5758 | return -1; | |
5759 | len = linetable->nitems; | |
5760 | ||
d2e4a39e | 5761 | if (ind >= 0) |
14f9c5c9 AS |
5762 | { |
5763 | CORE_ADDR start, end; | |
5764 | ||
5765 | if (find_pc_partial_function (linetable->item[ind].pc, | |
4c4b4cd2 PH |
5766 | (char **) NULL, &start, &end)) |
5767 | { | |
5768 | while (ind < len && linetable->item[ind].pc < end) | |
5769 | ind += 1; | |
5770 | } | |
14f9c5c9 | 5771 | else |
4c4b4cd2 | 5772 | ind += 1; |
14f9c5c9 AS |
5773 | } |
5774 | else | |
5775 | ind = 0; | |
5776 | ||
5777 | i = ind; | |
5778 | while (i < len) | |
5779 | { | |
d2e4a39e | 5780 | struct linetable_entry *item = &(linetable->item[i]); |
14f9c5c9 AS |
5781 | |
5782 | if (item->line >= line_num) | |
4c4b4cd2 PH |
5783 | { |
5784 | char *func_name; | |
5785 | CORE_ADDR start, end; | |
5786 | ||
5787 | func_name = NULL; | |
5788 | find_pc_partial_function (item->pc, &func_name, &start, &end); | |
5789 | ||
5790 | if (func_name != NULL && item->pc < end) | |
5791 | { | |
5792 | if (item->line == line_num) | |
5793 | { | |
5794 | struct symbol *sym = | |
5795 | standard_lookup (func_name, NULL, VAR_DOMAIN); | |
5796 | if (is_plausible_func_for_line (sym, starting_line)) | |
5797 | return i; | |
5798 | else | |
5799 | { | |
5800 | while ((i + 1) < len && linetable->item[i + 1].pc < end) | |
5801 | i += 1; | |
5802 | } | |
5803 | } | |
5804 | } | |
5805 | } | |
14f9c5c9 AS |
5806 | i += 1; |
5807 | } | |
5808 | ||
5809 | return -1; | |
5810 | } | |
5811 | ||
5812 | /* True iff function symbol SYM starts somewhere at or before line # | |
4c4b4cd2 PH |
5813 | LINE_NUM. */ |
5814 | ||
14f9c5c9 | 5815 | static int |
d2e4a39e | 5816 | is_plausible_func_for_line (struct symbol *sym, int line_num) |
14f9c5c9 AS |
5817 | { |
5818 | struct symtab_and_line start_sal; | |
5819 | ||
5820 | if (sym == NULL) | |
5821 | return 0; | |
5822 | ||
5823 | start_sal = find_function_start_sal (sym, 0); | |
5824 | ||
5825 | return (start_sal.line != 0 && line_num >= start_sal.line); | |
5826 | } | |
5827 | ||
14f9c5c9 | 5828 | /* Read in all symbol tables corresponding to partial symbol tables |
4c4b4cd2 PH |
5829 | with file name FILENAME. */ |
5830 | ||
14f9c5c9 | 5831 | static void |
d2e4a39e | 5832 | read_all_symtabs (const char *filename) |
14f9c5c9 | 5833 | { |
d2e4a39e AS |
5834 | struct partial_symtab *ps; |
5835 | struct objfile *objfile; | |
14f9c5c9 AS |
5836 | |
5837 | ALL_PSYMTABS (objfile, ps) | |
d2e4a39e AS |
5838 | { |
5839 | QUIT; | |
14f9c5c9 | 5840 | |
4c4b4cd2 | 5841 | if (strcmp (filename, ps->filename) == 0) |
d2e4a39e AS |
5842 | PSYMTAB_TO_SYMTAB (ps); |
5843 | } | |
14f9c5c9 AS |
5844 | } |
5845 | ||
5846 | /* All sals corresponding to line LINE_NUM in a symbol table from file | |
4c4b4cd2 PH |
5847 | FILENAME, as filtered by the user. Filter out any lines that |
5848 | reside in functions with "suppressed" names (not corresponding to | |
5849 | explicit Ada functions), if there is at least one in a function | |
5850 | with a non-suppressed name. If CANONICAL is not null, set | |
5851 | it to a corresponding array of canonical line specs. | |
5852 | If ONE_LOCATION_ONLY is set and several matches are found for | |
5853 | the given location, then automatically select the first match found | |
5854 | instead of asking the user which instance should be returned. */ | |
5855 | ||
5856 | struct symtabs_and_lines | |
5857 | ada_sals_for_line (const char *filename, int line_num, | |
5858 | int funfirstline, char ***canonical, | |
5859 | int one_location_only) | |
14f9c5c9 AS |
5860 | { |
5861 | struct symtabs_and_lines result; | |
d2e4a39e AS |
5862 | struct objfile *objfile; |
5863 | struct symtab *s; | |
5864 | struct cleanup *old_chain = make_cleanup (null_cleanup, NULL); | |
14f9c5c9 AS |
5865 | size_t len; |
5866 | ||
5867 | read_all_symtabs (filename); | |
5868 | ||
d2e4a39e AS |
5869 | result.sals = |
5870 | (struct symtab_and_line *) xmalloc (4 * sizeof (result.sals[0])); | |
14f9c5c9 AS |
5871 | result.nelts = 0; |
5872 | len = 4; | |
5873 | make_cleanup (free_current_contents, &result.sals); | |
5874 | ||
d2e4a39e AS |
5875 | ALL_SYMTABS (objfile, s) |
5876 | { | |
5877 | int ind, target_line_num; | |
14f9c5c9 | 5878 | |
d2e4a39e | 5879 | QUIT; |
14f9c5c9 | 5880 | |
4c4b4cd2 | 5881 | if (strcmp (s->filename, filename) != 0) |
d2e4a39e | 5882 | continue; |
14f9c5c9 | 5883 | |
d2e4a39e AS |
5884 | target_line_num = |
5885 | nearest_line_number_in_linetable (LINETABLE (s), line_num); | |
5886 | if (target_line_num == -1) | |
5887 | continue; | |
14f9c5c9 | 5888 | |
d2e4a39e AS |
5889 | ind = -1; |
5890 | while (1) | |
5891 | { | |
4c4b4cd2 PH |
5892 | ind = |
5893 | find_next_line_in_linetable (LINETABLE (s), | |
5894 | target_line_num, line_num, ind); | |
14f9c5c9 | 5895 | |
4c4b4cd2 PH |
5896 | if (ind < 0) |
5897 | break; | |
5898 | ||
5899 | GROW_VECT (result.sals, len, result.nelts + 1); | |
5900 | init_sal (&result.sals[result.nelts]); | |
5901 | result.sals[result.nelts].line = line_num; | |
5902 | result.sals[result.nelts].pc = LINETABLE (s)->item[ind].pc; | |
5903 | result.sals[result.nelts].symtab = s; | |
d2e4a39e | 5904 | |
4c4b4cd2 PH |
5905 | if (funfirstline) |
5906 | adjust_pc_past_prologue (&result.sals[result.nelts].pc); | |
5907 | ||
5908 | result.nelts += 1; | |
d2e4a39e AS |
5909 | } |
5910 | } | |
14f9c5c9 AS |
5911 | |
5912 | if (canonical != NULL || result.nelts > 1) | |
5913 | { | |
4c4b4cd2 | 5914 | int k, j, n; |
d2e4a39e | 5915 | char **func_names = (char **) alloca (result.nelts * sizeof (char *)); |
14f9c5c9 | 5916 | int first_choice = (result.nelts > 1) ? 2 : 1; |
d2e4a39e AS |
5917 | int *choices = (int *) alloca (result.nelts * sizeof (int)); |
5918 | ||
5919 | for (k = 0; k < result.nelts; k += 1) | |
4c4b4cd2 PH |
5920 | { |
5921 | find_pc_partial_function (result.sals[k].pc, &func_names[k], | |
5922 | (CORE_ADDR *) NULL, (CORE_ADDR *) NULL); | |
5923 | if (func_names[k] == NULL) | |
5924 | error ("Could not find function for one or more breakpoints."); | |
5925 | } | |
5926 | ||
5927 | /* Remove suppressed names, unless all are suppressed. */ | |
5928 | for (j = 0; j < result.nelts; j += 1) | |
5929 | if (!is_suppressed_name (func_names[j])) | |
5930 | { | |
5931 | /* At least one name is unsuppressed, so remove all | |
5932 | suppressed names. */ | |
5933 | for (k = n = 0; k < result.nelts; k += 1) | |
5934 | if (!is_suppressed_name (func_names[k])) | |
5935 | { | |
5936 | func_names[n] = func_names[k]; | |
5937 | result.sals[n] = result.sals[k]; | |
5938 | n += 1; | |
5939 | } | |
5940 | result.nelts = n; | |
5941 | break; | |
5942 | } | |
d2e4a39e AS |
5943 | |
5944 | if (result.nelts > 1) | |
4c4b4cd2 PH |
5945 | { |
5946 | if (one_location_only) | |
5947 | { | |
5948 | /* Automatically select the first of all possible choices. */ | |
5949 | n = 1; | |
5950 | choices[0] = 0; | |
5951 | } | |
5952 | else | |
5953 | { | |
5954 | printf_unfiltered ("[0] cancel\n"); | |
5955 | if (result.nelts > 1) | |
5956 | printf_unfiltered ("[1] all\n"); | |
5957 | for (k = 0; k < result.nelts; k += 1) | |
5958 | printf_unfiltered ("[%d] %s\n", k + first_choice, | |
5959 | ada_decode (func_names[k])); | |
5960 | ||
5961 | n = get_selections (choices, result.nelts, result.nelts, | |
5962 | result.nelts > 1, "instance-choice"); | |
5963 | } | |
5964 | ||
5965 | for (k = 0; k < n; k += 1) | |
5966 | { | |
5967 | result.sals[k] = result.sals[choices[k]]; | |
5968 | func_names[k] = func_names[choices[k]]; | |
5969 | } | |
5970 | result.nelts = n; | |
5971 | } | |
5972 | ||
5973 | if (canonical != NULL && result.nelts == 0) | |
5974 | *canonical = NULL; | |
5975 | else if (canonical != NULL) | |
5976 | { | |
5977 | *canonical = (char **) xmalloc (result.nelts * sizeof (char **)); | |
5978 | make_cleanup (xfree, *canonical); | |
5979 | for (k = 0; k < result.nelts; k += 1) | |
5980 | { | |
5981 | (*canonical)[k] = | |
5982 | extended_canonical_line_spec (result.sals[k], func_names[k]); | |
5983 | if ((*canonical)[k] == NULL) | |
5984 | error ("Could not locate one or more breakpoints."); | |
5985 | make_cleanup (xfree, (*canonical)[k]); | |
5986 | } | |
5987 | } | |
5988 | } | |
5989 | ||
5990 | if (result.nelts == 0) | |
5991 | { | |
5992 | do_cleanups (old_chain); | |
5993 | result.sals = NULL; | |
14f9c5c9 | 5994 | } |
4c4b4cd2 PH |
5995 | else |
5996 | discard_cleanups (old_chain); | |
14f9c5c9 AS |
5997 | return result; |
5998 | } | |
5999 | ||
6000 | ||
6001 | /* A canonical line specification of the form FILE:NAME:LINENUM for | |
6002 | symbol table and line data SAL. NULL if insufficient | |
4c4b4cd2 PH |
6003 | information. The caller is responsible for releasing any space |
6004 | allocated. */ | |
14f9c5c9 | 6005 | |
d2e4a39e AS |
6006 | static char * |
6007 | extended_canonical_line_spec (struct symtab_and_line sal, const char *name) | |
14f9c5c9 | 6008 | { |
d2e4a39e | 6009 | char *r; |
14f9c5c9 | 6010 | |
d2e4a39e | 6011 | if (sal.symtab == NULL || sal.symtab->filename == NULL || sal.line <= 0) |
14f9c5c9 AS |
6012 | return NULL; |
6013 | ||
d2e4a39e | 6014 | r = (char *) xmalloc (strlen (name) + strlen (sal.symtab->filename) |
4c4b4cd2 | 6015 | + sizeof (sal.line) * 3 + 3); |
14f9c5c9 AS |
6016 | sprintf (r, "%s:'%s':%d", sal.symtab->filename, name, sal.line); |
6017 | return r; | |
6018 | } | |
6019 | ||
4c4b4cd2 PH |
6020 | /* If the main procedure is written in Ada, then return its name. |
6021 | The result is good until the next call. Return NULL if the main | |
6022 | procedure doesn't appear to be in Ada. */ | |
14f9c5c9 | 6023 | |
4c4b4cd2 PH |
6024 | char * |
6025 | ada_main_name (void) | |
14f9c5c9 | 6026 | { |
4c4b4cd2 PH |
6027 | struct minimal_symbol *msym; |
6028 | CORE_ADDR main_program_name_addr; | |
6029 | static char main_program_name[1024]; | |
6030 | /* For Ada, the name of the main procedure is stored in a specific | |
6031 | string constant, generated by the binder. Look for that symbol, | |
6032 | extract its address, and then read that string. If we didn't find | |
6033 | that string, then most probably the main procedure is not written | |
6034 | in Ada. */ | |
6035 | msym = lookup_minimal_symbol (ADA_MAIN_PROGRAM_SYMBOL_NAME, NULL, NULL); | |
6036 | ||
6037 | if (msym != NULL) | |
6038 | { | |
6039 | main_program_name_addr = SYMBOL_VALUE_ADDRESS (msym); | |
6040 | if (main_program_name_addr == 0) | |
6041 | error ("Invalid address for Ada main program name."); | |
6042 | ||
6043 | extract_string (main_program_name_addr, main_program_name); | |
6044 | return main_program_name; | |
6045 | } | |
6046 | ||
6047 | /* The main procedure doesn't seem to be in Ada. */ | |
6048 | return NULL; | |
14f9c5c9 AS |
6049 | } |
6050 | ||
4c4b4cd2 PH |
6051 | /* Return type of Ada breakpoint associated with bp_stat: |
6052 | 0 if not an Ada-specific breakpoint, 1 for break on specific exception, | |
6053 | 2 for break on unhandled exception, 3 for assert. */ | |
6054 | ||
6055 | static int | |
6056 | ada_exception_breakpoint_type (bpstat bs) | |
6057 | { | |
6058 | #ifdef GNAT_GDB | |
6059 | return ((! bs || ! bs->breakpoint_at) ? 0 | |
6060 | : bs->breakpoint_at->break_on_exception); | |
6061 | #else | |
6062 | return 0; | |
6063 | #endif | |
6064 | } | |
6065 | ||
6066 | /* True iff FRAME is very likely to be that of a function that is | |
6067 | part of the runtime system. This is all very heuristic, but is | |
6068 | intended to be used as advice as to what frames are uninteresting | |
6069 | to most users. */ | |
6070 | ||
6071 | static int | |
6072 | is_known_support_routine (struct frame_info *frame) | |
6073 | { | |
6074 | struct frame_info *next_frame = get_next_frame (frame); | |
6075 | /* If frame is not innermost, that normally means that frame->pc | |
6076 | points to *after* the call instruction, and we want to get the line | |
6077 | containing the call, never the next line. But if the next frame is | |
6078 | a signal_handler_caller or a dummy frame, then the next frame was | |
6079 | not entered as the result of a call, and we want to get the line | |
6080 | containing frame->pc. */ | |
6081 | const int pc_is_after_call = | |
6082 | next_frame != NULL | |
6083 | && get_frame_type (next_frame) != SIGTRAMP_FRAME | |
6084 | && get_frame_type (next_frame) != DUMMY_FRAME; | |
6085 | struct symtab_and_line sal | |
6086 | = find_pc_line (get_frame_pc (frame), pc_is_after_call); | |
6087 | char *func_name; | |
6088 | int i; | |
6089 | struct stat st; | |
6090 | ||
6091 | /* The heuristic: | |
6092 | 1. The symtab is null (indicating no debugging symbols) | |
6093 | 2. The symtab's filename does not exist. | |
6094 | 3. The object file's name is one of the standard libraries. | |
6095 | 4. The symtab's file name has the form of an Ada library source file. | |
6096 | 5. The function at frame's PC has a GNAT-compiler-generated name. */ | |
6097 | ||
6098 | if (sal.symtab == NULL) | |
6099 | return 1; | |
6100 | ||
6101 | /* On some systems (e.g. VxWorks), the kernel contains debugging | |
6102 | symbols; in this case, the filename referenced by these symbols | |
6103 | does not exists. */ | |
6104 | ||
6105 | if (stat (sal.symtab->filename, &st)) | |
6106 | return 1; | |
6107 | ||
6108 | for (i = 0; known_runtime_file_name_patterns[i] != NULL; i += 1) | |
6109 | { | |
6110 | re_comp (known_runtime_file_name_patterns[i]); | |
6111 | if (re_exec (sal.symtab->filename)) | |
6112 | return 1; | |
6113 | } | |
6114 | if (sal.symtab->objfile != NULL) | |
6115 | { | |
6116 | for (i = 0; known_runtime_file_name_patterns[i] != NULL; i += 1) | |
6117 | { | |
6118 | re_comp (known_runtime_file_name_patterns[i]); | |
6119 | if (re_exec (sal.symtab->objfile->name)) | |
6120 | return 1; | |
6121 | } | |
6122 | } | |
6123 | ||
6124 | /* If the frame PC points after the call instruction, then we need to | |
6125 | decrement it in order to search for the function associated to this | |
6126 | PC. Otherwise, if the associated call was the last instruction of | |
6127 | the function, we might either find the wrong function or even fail | |
6128 | during the function name lookup. */ | |
6129 | if (pc_is_after_call) | |
6130 | func_name = function_name_from_pc (get_frame_pc (frame) - 1); | |
6131 | else | |
6132 | func_name = function_name_from_pc (get_frame_pc (frame)); | |
6133 | ||
6134 | if (func_name == NULL) | |
6135 | return 1; | |
6136 | ||
6137 | for (i = 0; known_auxiliary_function_name_patterns[i] != NULL; i += 1) | |
6138 | { | |
6139 | re_comp (known_auxiliary_function_name_patterns[i]); | |
6140 | if (re_exec (func_name)) | |
6141 | return 1; | |
6142 | } | |
6143 | ||
6144 | return 0; | |
6145 | } | |
6146 | ||
6147 | /* Find the first frame that contains debugging information and that is not | |
6148 | part of the Ada run-time, starting from FI and moving upward. */ | |
6149 | ||
6150 | void | |
6151 | ada_find_printable_frame (struct frame_info *fi) | |
14f9c5c9 | 6152 | { |
4c4b4cd2 PH |
6153 | for (; fi != NULL; fi = get_prev_frame (fi)) |
6154 | { | |
6155 | if (!is_known_support_routine (fi)) | |
6156 | { | |
6157 | select_frame (fi); | |
6158 | break; | |
6159 | } | |
6160 | } | |
14f9c5c9 | 6161 | |
4c4b4cd2 | 6162 | } |
d2e4a39e | 6163 | |
4c4b4cd2 PH |
6164 | /* Name found for exception associated with last bpstat sent to |
6165 | ada_adjust_exception_stop. Set to the null string if that bpstat | |
6166 | did not correspond to an Ada exception or no name could be found. */ | |
14f9c5c9 | 6167 | |
4c4b4cd2 | 6168 | static char last_exception_name[256]; |
14f9c5c9 | 6169 | |
4c4b4cd2 PH |
6170 | /* If BS indicates a stop in an Ada exception, try to go up to a frame |
6171 | that will be meaningful to the user, and save the name of the last | |
6172 | exception (truncated, if necessary) in last_exception_name. */ | |
14f9c5c9 | 6173 | |
4c4b4cd2 PH |
6174 | void |
6175 | ada_adjust_exception_stop (bpstat bs) | |
6176 | { | |
6177 | CORE_ADDR addr; | |
6178 | struct frame_info *fi; | |
6179 | int frame_level; | |
6180 | char *selected_frame_func; | |
14f9c5c9 | 6181 | |
4c4b4cd2 PH |
6182 | addr = 0; |
6183 | last_exception_name[0] = '\0'; | |
6184 | fi = get_selected_frame (); | |
6185 | selected_frame_func = function_name_from_pc (get_frame_pc (fi)); | |
6186 | ||
6187 | switch (ada_exception_breakpoint_type (bs)) | |
d2e4a39e | 6188 | { |
4c4b4cd2 PH |
6189 | default: |
6190 | return; | |
6191 | case 1: | |
6192 | break; | |
6193 | case 2: | |
6194 | /* Unhandled exceptions. Select the frame corresponding to | |
6195 | ada.exceptions.process_raise_exception. This frame is at | |
6196 | least 2 levels up, so we simply skip the first 2 frames | |
6197 | without checking the name of their associated function. */ | |
6198 | for (frame_level = 0; frame_level < 2; frame_level += 1) | |
6199 | if (fi != NULL) | |
6200 | fi = get_prev_frame (fi); | |
6201 | while (fi != NULL) | |
6202 | { | |
6203 | const char *func_name = function_name_from_pc (get_frame_pc (fi)); | |
6204 | if (func_name != NULL | |
6205 | && strcmp (func_name, process_raise_exception_name) == 0) | |
6206 | break; /* We found the frame we were looking for... */ | |
6207 | fi = get_prev_frame (fi); | |
6208 | } | |
6209 | if (fi == NULL) | |
6210 | break; | |
6211 | select_frame (fi); | |
6212 | break; | |
d2e4a39e | 6213 | } |
14f9c5c9 | 6214 | |
4c4b4cd2 PH |
6215 | addr = parse_and_eval_address ("e.full_name"); |
6216 | ||
6217 | if (addr != 0) | |
6218 | read_memory (addr, last_exception_name, | |
6219 | sizeof (last_exception_name) - 1); | |
6220 | last_exception_name[sizeof (last_exception_name) - 1] = '\0'; | |
6221 | ada_find_printable_frame (get_selected_frame ()); | |
14f9c5c9 AS |
6222 | } |
6223 | ||
4c4b4cd2 PH |
6224 | /* Output Ada exception name (if any) associated with last call to |
6225 | ada_adjust_exception_stop. */ | |
6226 | ||
6227 | void | |
6228 | ada_print_exception_stop (bpstat bs) | |
14f9c5c9 | 6229 | { |
4c4b4cd2 PH |
6230 | if (last_exception_name[0] != '\000') |
6231 | { | |
6232 | ui_out_text (uiout, last_exception_name); | |
6233 | ui_out_text (uiout, " at "); | |
6234 | } | |
14f9c5c9 AS |
6235 | } |
6236 | ||
4c4b4cd2 PH |
6237 | /* Parses the CONDITION string associated with a breakpoint exception |
6238 | to get the name of the exception on which the breakpoint has been | |
6239 | set. The returned string needs to be deallocated after use. */ | |
14f9c5c9 | 6240 | |
4c4b4cd2 PH |
6241 | static char * |
6242 | exception_name_from_cond (const char *condition) | |
14f9c5c9 | 6243 | { |
4c4b4cd2 PH |
6244 | char *start, *end, *exception_name; |
6245 | int exception_name_len; | |
d2e4a39e | 6246 | |
4c4b4cd2 PH |
6247 | start = strrchr (condition, '&') + 1; |
6248 | end = strchr (start, ')') - 1; | |
6249 | exception_name_len = end - start + 1; | |
14f9c5c9 | 6250 | |
4c4b4cd2 PH |
6251 | exception_name = |
6252 | (char *) xmalloc ((exception_name_len + 1) * sizeof (char)); | |
6253 | sprintf (exception_name, "%.*s", exception_name_len, start); | |
6254 | ||
6255 | return exception_name; | |
6256 | } | |
6257 | ||
6258 | /* Print Ada-specific exception information about B, other than task | |
6259 | clause. Return non-zero iff B was an Ada exception breakpoint. */ | |
14f9c5c9 | 6260 | |
4c4b4cd2 PH |
6261 | int |
6262 | ada_print_exception_breakpoint_nontask (struct breakpoint *b) | |
6263 | { | |
6264 | #ifdef GNAT_GDB | |
6265 | if (b->break_on_exception == 1) | |
6266 | { | |
6267 | if (b->cond_string) /* the breakpoint is on a specific exception. */ | |
6268 | { | |
6269 | char *exception_name = exception_name_from_cond (b->cond_string); | |
6270 | ||
6271 | make_cleanup (xfree, exception_name); | |
6272 | ||
6273 | ui_out_text (uiout, "on "); | |
6274 | if (ui_out_is_mi_like_p (uiout)) | |
6275 | ui_out_field_string (uiout, "exception", exception_name); | |
6276 | else | |
6277 | { | |
6278 | ui_out_text (uiout, "exception "); | |
6279 | ui_out_text (uiout, exception_name); | |
6280 | ui_out_text (uiout, " "); | |
6281 | } | |
6282 | } | |
6283 | else | |
6284 | ui_out_text (uiout, "on all exceptions"); | |
6285 | } | |
6286 | else if (b->break_on_exception == 2) | |
6287 | ui_out_text (uiout, "on unhandled exception"); | |
6288 | else if (b->break_on_exception == 3) | |
6289 | ui_out_text (uiout, "on assert failure"); | |
6290 | else | |
6291 | return 0; | |
6292 | return 1; | |
6293 | #else | |
6294 | return 0; | |
6295 | #endif | |
14f9c5c9 AS |
6296 | } |
6297 | ||
4c4b4cd2 PH |
6298 | /* Print task identifier for breakpoint B, if it is an Ada-specific |
6299 | breakpoint with non-zero tasking information. */ | |
6300 | ||
14f9c5c9 | 6301 | void |
4c4b4cd2 PH |
6302 | ada_print_exception_breakpoint_task (struct breakpoint *b) |
6303 | { | |
6304 | #ifdef GNAT_GDB | |
6305 | if (b->task != 0) | |
6306 | { | |
6307 | ui_out_text (uiout, " task "); | |
6308 | ui_out_field_int (uiout, "task", b->task); | |
6309 | } | |
6310 | #endif | |
14f9c5c9 AS |
6311 | } |
6312 | ||
6313 | int | |
d2e4a39e | 6314 | ada_is_exception_sym (struct symbol *sym) |
14f9c5c9 AS |
6315 | { |
6316 | char *type_name = type_name_no_tag (SYMBOL_TYPE (sym)); | |
d2e4a39e | 6317 | |
14f9c5c9 | 6318 | return (SYMBOL_CLASS (sym) != LOC_TYPEDEF |
4c4b4cd2 PH |
6319 | && SYMBOL_CLASS (sym) != LOC_BLOCK |
6320 | && SYMBOL_CLASS (sym) != LOC_CONST | |
6321 | && type_name != NULL && strcmp (type_name, "exception") == 0); | |
14f9c5c9 AS |
6322 | } |
6323 | ||
6324 | int | |
d2e4a39e | 6325 | ada_maybe_exception_partial_symbol (struct partial_symbol *sym) |
14f9c5c9 AS |
6326 | { |
6327 | return (SYMBOL_CLASS (sym) != LOC_TYPEDEF | |
4c4b4cd2 PH |
6328 | && SYMBOL_CLASS (sym) != LOC_BLOCK |
6329 | && SYMBOL_CLASS (sym) != LOC_CONST); | |
6330 | } | |
6331 | ||
6332 | /* Cause the appropriate error if no appropriate runtime symbol is | |
6333 | found to set a breakpoint, using ERR_DESC to describe the | |
6334 | breakpoint. */ | |
6335 | ||
6336 | static void | |
6337 | error_breakpoint_runtime_sym_not_found (const char *err_desc) | |
6338 | { | |
6339 | /* If we are not debugging an Ada program, we can not put exception | |
6340 | breakpoints! */ | |
6341 | ||
6342 | if (ada_update_initial_language (language_unknown, NULL) != language_ada) | |
6343 | error ("Unable to break on %s. Is this an Ada main program?", err_desc); | |
6344 | ||
6345 | /* If the symbol does not exist, then check that the program is | |
6346 | already started, to make sure that shared libraries have been | |
6347 | loaded. If it is not started, this may mean that the symbol is | |
6348 | in a shared library. */ | |
6349 | ||
6350 | if (ptid_get_pid (inferior_ptid) == 0) | |
6351 | error ("Unable to break on %s. Try to start the program first.", err_desc); | |
6352 | ||
6353 | /* At this point, we know that we are debugging an Ada program and | |
6354 | that the inferior has been started, but we still are not able to | |
6355 | find the run-time symbols. That can mean that we are in | |
6356 | configurable run time mode, or that a-except as been optimized | |
6357 | out by the linker... In any case, at this point it is not worth | |
6358 | supporting this feature. */ | |
6359 | ||
6360 | error ("Cannot break on %s in this configuration.", err_desc); | |
6361 | } | |
6362 | ||
6363 | /* Test if NAME is currently defined, and that either ALLOW_TRAMP or | |
6364 | the symbol is not a shared-library trampoline. Return the result of | |
6365 | the test. */ | |
6366 | ||
6367 | static int | |
6368 | is_runtime_sym_defined (const char *name, int allow_tramp) | |
6369 | { | |
6370 | struct minimal_symbol *msym; | |
6371 | ||
6372 | msym = lookup_minimal_symbol (name, NULL, NULL); | |
6373 | return (msym != NULL && msym->type != mst_unknown | |
6374 | && (allow_tramp || msym->type != mst_solib_trampoline)); | |
14f9c5c9 AS |
6375 | } |
6376 | ||
6377 | /* If ARG points to an Ada exception or assert breakpoint, rewrite | |
4c4b4cd2 | 6378 | into equivalent form. Return resulting argument string. Set |
14f9c5c9 | 6379 | *BREAK_ON_EXCEPTIONP to 1 for ordinary break on exception, 2 for |
4c4b4cd2 PH |
6380 | break on unhandled, 3 for assert, 0 otherwise. */ |
6381 | ||
d2e4a39e AS |
6382 | char * |
6383 | ada_breakpoint_rewrite (char *arg, int *break_on_exceptionp) | |
14f9c5c9 AS |
6384 | { |
6385 | if (arg == NULL) | |
6386 | return arg; | |
6387 | *break_on_exceptionp = 0; | |
4c4b4cd2 PH |
6388 | if (current_language->la_language == language_ada |
6389 | && strncmp (arg, "exception", 9) == 0 | |
6390 | && (arg[9] == ' ' || arg[9] == '\t' || arg[9] == '\0')) | |
6391 | { | |
6392 | char *tok, *end_tok; | |
6393 | int toklen; | |
6394 | int has_exception_propagation = | |
6395 | is_runtime_sym_defined (raise_sym_name, 1); | |
6396 | ||
6397 | *break_on_exceptionp = 1; | |
6398 | ||
6399 | tok = arg + 9; | |
6400 | while (*tok == ' ' || *tok == '\t') | |
6401 | tok += 1; | |
6402 | ||
6403 | end_tok = tok; | |
6404 | ||
6405 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
6406 | end_tok += 1; | |
6407 | ||
6408 | toklen = end_tok - tok; | |
6409 | ||
6410 | arg = (char *) xmalloc (sizeof (longest_exception_template) + toklen); | |
6411 | make_cleanup (xfree, arg); | |
6412 | if (toklen == 0) | |
6413 | { | |
6414 | if (has_exception_propagation) | |
6415 | sprintf (arg, "'%s'", raise_sym_name); | |
6416 | else | |
6417 | error_breakpoint_runtime_sym_not_found ("exception"); | |
6418 | } | |
6419 | else if (strncmp (tok, "unhandled", toklen) == 0) | |
6420 | { | |
6421 | if (is_runtime_sym_defined (raise_unhandled_sym_name, 1)) | |
6422 | sprintf (arg, "'%s'", raise_unhandled_sym_name); | |
6423 | else | |
6424 | error_breakpoint_runtime_sym_not_found ("exception"); | |
6425 | ||
6426 | *break_on_exceptionp = 2; | |
6427 | } | |
6428 | else | |
6429 | { | |
6430 | if (is_runtime_sym_defined (raise_sym_name, 0)) | |
6431 | sprintf (arg, "'%s' if long_integer(e) = long_integer(&%.*s)", | |
6432 | raise_sym_name, toklen, tok); | |
6433 | else | |
6434 | error_breakpoint_runtime_sym_not_found ("specific exception"); | |
6435 | } | |
6436 | } | |
6437 | else if (current_language->la_language == language_ada | |
6438 | && strncmp (arg, "assert", 6) == 0 | |
6439 | && (arg[6] == ' ' || arg[6] == '\t' || arg[6] == '\0')) | |
6440 | { | |
6441 | char *tok = arg + 6; | |
6442 | ||
6443 | if (!is_runtime_sym_defined (raise_assert_sym_name, 1)) | |
6444 | error_breakpoint_runtime_sym_not_found ("failed assertion"); | |
6445 | ||
6446 | *break_on_exceptionp = 3; | |
6447 | ||
6448 | arg = | |
6449 | (char *) xmalloc (sizeof (raise_assert_sym_name) + strlen (tok) + 2); | |
6450 | make_cleanup (xfree, arg); | |
6451 | sprintf (arg, "'%s'%s", raise_assert_sym_name, tok); | |
6452 | } | |
14f9c5c9 AS |
6453 | return arg; |
6454 | } | |
14f9c5c9 | 6455 | \f |
d2e4a39e | 6456 | |
4c4b4cd2 | 6457 | /* Field Access */ |
14f9c5c9 AS |
6458 | |
6459 | /* True if field number FIELD_NUM in struct or union type TYPE is supposed | |
4c4b4cd2 | 6460 | to be invisible to users. */ |
14f9c5c9 AS |
6461 | |
6462 | int | |
ebf56fd3 | 6463 | ada_is_ignored_field (struct type *type, int field_num) |
14f9c5c9 AS |
6464 | { |
6465 | if (field_num < 0 || field_num > TYPE_NFIELDS (type)) | |
6466 | return 1; | |
d2e4a39e | 6467 | else |
14f9c5c9 | 6468 | { |
d2e4a39e | 6469 | const char *name = TYPE_FIELD_NAME (type, field_num); |
14f9c5c9 | 6470 | return (name == NULL |
4c4b4cd2 | 6471 | || (name[0] == '_' && strncmp (name, "_parent", 7) != 0)); |
14f9c5c9 AS |
6472 | } |
6473 | } | |
6474 | ||
4c4b4cd2 PH |
6475 | /* True iff TYPE has a tag field. If REFOK, then TYPE may also be a |
6476 | pointer or reference type whose ultimate target has a tag field. */ | |
14f9c5c9 AS |
6477 | |
6478 | int | |
4c4b4cd2 | 6479 | ada_is_tagged_type (struct type *type, int refok) |
14f9c5c9 | 6480 | { |
4c4b4cd2 PH |
6481 | return (ada_lookup_struct_elt_type (type, "_tag", refok, 1, NULL) != NULL); |
6482 | } | |
14f9c5c9 | 6483 | |
4c4b4cd2 PH |
6484 | /* True iff TYPE represents the type of X'Tag */ |
6485 | ||
6486 | int | |
6487 | ada_is_tag_type (struct type *type) | |
6488 | { | |
6489 | if (type == NULL || TYPE_CODE (type) != TYPE_CODE_PTR) | |
6490 | return 0; | |
6491 | else { | |
6492 | const char *name = ada_type_name (TYPE_TARGET_TYPE (type)); | |
6493 | return (name != NULL | |
6494 | && strcmp (name, "ada__tags__dispatch_table") == 0); | |
6495 | } | |
14f9c5c9 AS |
6496 | } |
6497 | ||
4c4b4cd2 | 6498 | /* The type of the tag on VAL. */ |
14f9c5c9 | 6499 | |
d2e4a39e AS |
6500 | struct type * |
6501 | ada_tag_type (struct value *val) | |
14f9c5c9 | 6502 | { |
4c4b4cd2 | 6503 | return ada_lookup_struct_elt_type (VALUE_TYPE (val), "_tag", 1, 0, NULL); |
14f9c5c9 AS |
6504 | } |
6505 | ||
4c4b4cd2 | 6506 | /* The value of the tag on VAL. */ |
14f9c5c9 | 6507 | |
d2e4a39e AS |
6508 | struct value * |
6509 | ada_value_tag (struct value *val) | |
14f9c5c9 AS |
6510 | { |
6511 | return ada_value_struct_elt (val, "_tag", "record"); | |
6512 | } | |
6513 | ||
4c4b4cd2 PH |
6514 | /* The value of the tag on the object of type TYPE whose contents are |
6515 | saved at VALADDR, if it is non-null, or is at memory address | |
6516 | ADDRESS. */ | |
6517 | ||
6518 | static struct value * | |
6519 | value_tag_from_contents_and_address (struct type *type, char *valaddr, | |
6520 | CORE_ADDR address) | |
6521 | { | |
6522 | int tag_byte_offset, dummy1, dummy2; | |
6523 | struct type *tag_type; | |
6524 | if (find_struct_field ("_tag", type, 0, &tag_type, &tag_byte_offset, | |
6525 | &dummy1, &dummy2)) | |
6526 | { | |
6527 | char *valaddr1 = (valaddr == NULL) ? NULL : valaddr + tag_byte_offset; | |
6528 | CORE_ADDR address1 = (address == 0) ? 0 : address + tag_byte_offset; | |
6529 | ||
6530 | return value_from_contents_and_address (tag_type, valaddr1, address1); | |
6531 | } | |
6532 | return NULL; | |
6533 | } | |
6534 | ||
6535 | static struct type * | |
6536 | type_from_tag (struct value *tag) | |
6537 | { | |
6538 | const char *type_name = ada_tag_name (tag); | |
6539 | if (type_name != NULL) | |
6540 | return ada_find_any_type (ada_encode (type_name)); | |
6541 | return NULL; | |
6542 | } | |
6543 | ||
6544 | struct tag_args { | |
6545 | struct value *tag; | |
6546 | char *name; | |
6547 | }; | |
6548 | ||
6549 | /* Wrapper function used by ada_tag_name. Given a struct tag_args* | |
6550 | value ARGS, sets ARGS->name to the tag name of ARGS->tag. | |
6551 | The value stored in ARGS->name is valid until the next call to | |
6552 | ada_tag_name_1. */ | |
6553 | ||
6554 | static int | |
6555 | ada_tag_name_1 (void *args0) | |
6556 | { | |
6557 | struct tag_args *args = (struct tag_args *) args0; | |
6558 | static char name[1024]; | |
6559 | char* p; | |
6560 | struct value *val; | |
6561 | args->name = NULL; | |
6562 | val = ada_value_struct_elt (args->tag, "tsd", NULL); | |
6563 | if (val == NULL) | |
6564 | return 0; | |
6565 | val = ada_value_struct_elt (val, "expanded_name", NULL); | |
6566 | if (val == NULL) | |
6567 | return 0; | |
6568 | read_memory_string (value_as_address (val), name, sizeof (name) - 1); | |
6569 | for (p = name; *p != '\0'; p += 1) | |
6570 | if (isalpha (*p)) | |
6571 | *p = tolower (*p); | |
6572 | args->name = name; | |
6573 | return 0; | |
6574 | } | |
6575 | ||
6576 | /* The type name of the dynamic type denoted by the 'tag value TAG, as | |
6577 | * a C string. */ | |
6578 | ||
6579 | const char * | |
6580 | ada_tag_name (struct value *tag) | |
6581 | { | |
6582 | struct tag_args args; | |
6583 | if (! ada_is_tag_type (VALUE_TYPE (tag))) | |
6584 | return NULL; | |
6585 | args.tag = tag; | |
6586 | args.name = NULL; | |
6587 | catch_errors (ada_tag_name_1, &args, NULL, RETURN_MASK_ALL); | |
6588 | return args.name; | |
6589 | } | |
6590 | ||
6591 | /* The parent type of TYPE, or NULL if none. */ | |
14f9c5c9 | 6592 | |
d2e4a39e | 6593 | struct type * |
ebf56fd3 | 6594 | ada_parent_type (struct type *type) |
14f9c5c9 AS |
6595 | { |
6596 | int i; | |
6597 | ||
6598 | CHECK_TYPEDEF (type); | |
6599 | ||
6600 | if (type == NULL || TYPE_CODE (type) != TYPE_CODE_STRUCT) | |
6601 | return NULL; | |
6602 | ||
6603 | for (i = 0; i < TYPE_NFIELDS (type); i += 1) | |
6604 | if (ada_is_parent_field (type, i)) | |
6605 | return check_typedef (TYPE_FIELD_TYPE (type, i)); | |
6606 | ||
6607 | return NULL; | |
6608 | } | |
6609 | ||
4c4b4cd2 PH |
6610 | /* True iff field number FIELD_NUM of structure type TYPE contains the |
6611 | parent-type (inherited) fields of a derived type. Assumes TYPE is | |
6612 | a structure type with at least FIELD_NUM+1 fields. */ | |
14f9c5c9 AS |
6613 | |
6614 | int | |
ebf56fd3 | 6615 | ada_is_parent_field (struct type *type, int field_num) |
14f9c5c9 | 6616 | { |
d2e4a39e | 6617 | const char *name = TYPE_FIELD_NAME (check_typedef (type), field_num); |
4c4b4cd2 PH |
6618 | return (name != NULL |
6619 | && (strncmp (name, "PARENT", 6) == 0 | |
6620 | || strncmp (name, "_parent", 7) == 0)); | |
14f9c5c9 AS |
6621 | } |
6622 | ||
4c4b4cd2 | 6623 | /* True iff field number FIELD_NUM of structure type TYPE is a |
14f9c5c9 | 6624 | transparent wrapper field (which should be silently traversed when doing |
4c4b4cd2 | 6625 | field selection and flattened when printing). Assumes TYPE is a |
14f9c5c9 | 6626 | structure type with at least FIELD_NUM+1 fields. Such fields are always |
4c4b4cd2 | 6627 | structures. */ |
14f9c5c9 AS |
6628 | |
6629 | int | |
ebf56fd3 | 6630 | ada_is_wrapper_field (struct type *type, int field_num) |
14f9c5c9 | 6631 | { |
d2e4a39e AS |
6632 | const char *name = TYPE_FIELD_NAME (type, field_num); |
6633 | return (name != NULL | |
4c4b4cd2 PH |
6634 | && (strncmp (name, "PARENT", 6) == 0 |
6635 | || strcmp (name, "REP") == 0 | |
6636 | || strncmp (name, "_parent", 7) == 0 | |
6637 | || name[0] == 'S' || name[0] == 'R' || name[0] == 'O')); | |
14f9c5c9 AS |
6638 | } |
6639 | ||
4c4b4cd2 PH |
6640 | /* True iff field number FIELD_NUM of structure or union type TYPE |
6641 | is a variant wrapper. Assumes TYPE is a structure type with at least | |
6642 | FIELD_NUM+1 fields. */ | |
14f9c5c9 AS |
6643 | |
6644 | int | |
ebf56fd3 | 6645 | ada_is_variant_part (struct type *type, int field_num) |
14f9c5c9 | 6646 | { |
d2e4a39e | 6647 | struct type *field_type = TYPE_FIELD_TYPE (type, field_num); |
14f9c5c9 | 6648 | return (TYPE_CODE (field_type) == TYPE_CODE_UNION |
4c4b4cd2 PH |
6649 | || (is_dynamic_field (type, field_num) |
6650 | && TYPE_CODE (TYPE_TARGET_TYPE (field_type)) == | |
6651 | TYPE_CODE_UNION)); | |
14f9c5c9 AS |
6652 | } |
6653 | ||
6654 | /* Assuming that VAR_TYPE is a variant wrapper (type of the variant part) | |
4c4b4cd2 | 6655 | whose discriminants are contained in the record type OUTER_TYPE, |
14f9c5c9 AS |
6656 | returns the type of the controlling discriminant for the variant. */ |
6657 | ||
d2e4a39e | 6658 | struct type * |
ebf56fd3 | 6659 | ada_variant_discrim_type (struct type *var_type, struct type *outer_type) |
14f9c5c9 | 6660 | { |
d2e4a39e | 6661 | char *name = ada_variant_discrim_name (var_type); |
4c4b4cd2 PH |
6662 | struct type *type = |
6663 | ada_lookup_struct_elt_type (outer_type, name, 1, 1, NULL); | |
14f9c5c9 AS |
6664 | if (type == NULL) |
6665 | return builtin_type_int; | |
6666 | else | |
6667 | return type; | |
6668 | } | |
6669 | ||
4c4b4cd2 | 6670 | /* Assuming that TYPE is the type of a variant wrapper, and FIELD_NUM is a |
14f9c5c9 | 6671 | valid field number within it, returns 1 iff field FIELD_NUM of TYPE |
4c4b4cd2 | 6672 | represents a 'when others' clause; otherwise 0. */ |
14f9c5c9 AS |
6673 | |
6674 | int | |
ebf56fd3 | 6675 | ada_is_others_clause (struct type *type, int field_num) |
14f9c5c9 | 6676 | { |
d2e4a39e | 6677 | const char *name = TYPE_FIELD_NAME (type, field_num); |
14f9c5c9 AS |
6678 | return (name != NULL && name[0] == 'O'); |
6679 | } | |
6680 | ||
6681 | /* Assuming that TYPE0 is the type of the variant part of a record, | |
4c4b4cd2 PH |
6682 | returns the name of the discriminant controlling the variant. |
6683 | The value is valid until the next call to ada_variant_discrim_name. */ | |
14f9c5c9 | 6684 | |
d2e4a39e | 6685 | char * |
ebf56fd3 | 6686 | ada_variant_discrim_name (struct type *type0) |
14f9c5c9 | 6687 | { |
d2e4a39e | 6688 | static char *result = NULL; |
14f9c5c9 | 6689 | static size_t result_len = 0; |
d2e4a39e AS |
6690 | struct type *type; |
6691 | const char *name; | |
6692 | const char *discrim_end; | |
6693 | const char *discrim_start; | |
14f9c5c9 AS |
6694 | |
6695 | if (TYPE_CODE (type0) == TYPE_CODE_PTR) | |
6696 | type = TYPE_TARGET_TYPE (type0); | |
6697 | else | |
6698 | type = type0; | |
6699 | ||
6700 | name = ada_type_name (type); | |
6701 | ||
6702 | if (name == NULL || name[0] == '\000') | |
6703 | return ""; | |
6704 | ||
6705 | for (discrim_end = name + strlen (name) - 6; discrim_end != name; | |
6706 | discrim_end -= 1) | |
6707 | { | |
4c4b4cd2 PH |
6708 | if (strncmp (discrim_end, "___XVN", 6) == 0) |
6709 | break; | |
14f9c5c9 AS |
6710 | } |
6711 | if (discrim_end == name) | |
6712 | return ""; | |
6713 | ||
d2e4a39e | 6714 | for (discrim_start = discrim_end; discrim_start != name + 3; |
14f9c5c9 AS |
6715 | discrim_start -= 1) |
6716 | { | |
d2e4a39e | 6717 | if (discrim_start == name + 1) |
4c4b4cd2 PH |
6718 | return ""; |
6719 | if ((discrim_start > name + 3 | |
6720 | && strncmp (discrim_start - 3, "___", 3) == 0) | |
6721 | || discrim_start[-1] == '.') | |
6722 | break; | |
14f9c5c9 AS |
6723 | } |
6724 | ||
6725 | GROW_VECT (result, result_len, discrim_end - discrim_start + 1); | |
6726 | strncpy (result, discrim_start, discrim_end - discrim_start); | |
d2e4a39e | 6727 | result[discrim_end - discrim_start] = '\0'; |
14f9c5c9 AS |
6728 | return result; |
6729 | } | |
6730 | ||
4c4b4cd2 PH |
6731 | /* Scan STR for a subtype-encoded number, beginning at position K. |
6732 | Put the position of the character just past the number scanned in | |
6733 | *NEW_K, if NEW_K!=NULL. Put the scanned number in *R, if R!=NULL. | |
6734 | Return 1 if there was a valid number at the given position, and 0 | |
6735 | otherwise. A "subtype-encoded" number consists of the absolute value | |
6736 | in decimal, followed by the letter 'm' to indicate a negative number. | |
6737 | Assumes 0m does not occur. */ | |
14f9c5c9 AS |
6738 | |
6739 | int | |
d2e4a39e | 6740 | ada_scan_number (const char str[], int k, LONGEST * R, int *new_k) |
14f9c5c9 AS |
6741 | { |
6742 | ULONGEST RU; | |
6743 | ||
d2e4a39e | 6744 | if (!isdigit (str[k])) |
14f9c5c9 AS |
6745 | return 0; |
6746 | ||
4c4b4cd2 | 6747 | /* Do it the hard way so as not to make any assumption about |
14f9c5c9 | 6748 | the relationship of unsigned long (%lu scan format code) and |
4c4b4cd2 | 6749 | LONGEST. */ |
14f9c5c9 AS |
6750 | RU = 0; |
6751 | while (isdigit (str[k])) | |
6752 | { | |
d2e4a39e | 6753 | RU = RU * 10 + (str[k] - '0'); |
14f9c5c9 AS |
6754 | k += 1; |
6755 | } | |
6756 | ||
d2e4a39e | 6757 | if (str[k] == 'm') |
14f9c5c9 AS |
6758 | { |
6759 | if (R != NULL) | |
4c4b4cd2 | 6760 | *R = (-(LONGEST) (RU - 1)) - 1; |
14f9c5c9 AS |
6761 | k += 1; |
6762 | } | |
6763 | else if (R != NULL) | |
6764 | *R = (LONGEST) RU; | |
6765 | ||
4c4b4cd2 | 6766 | /* NOTE on the above: Technically, C does not say what the results of |
14f9c5c9 AS |
6767 | - (LONGEST) RU or (LONGEST) -RU are for RU == largest positive |
6768 | number representable as a LONGEST (although either would probably work | |
6769 | in most implementations). When RU>0, the locution in the then branch | |
4c4b4cd2 | 6770 | above is always equivalent to the negative of RU. */ |
14f9c5c9 AS |
6771 | |
6772 | if (new_k != NULL) | |
6773 | *new_k = k; | |
6774 | return 1; | |
6775 | } | |
6776 | ||
4c4b4cd2 PH |
6777 | /* Assuming that TYPE is a variant part wrapper type (a VARIANTS field), |
6778 | and FIELD_NUM is a valid field number within it, returns 1 iff VAL is | |
6779 | in the range encoded by field FIELD_NUM of TYPE; otherwise 0. */ | |
14f9c5c9 | 6780 | |
d2e4a39e | 6781 | int |
ebf56fd3 | 6782 | ada_in_variant (LONGEST val, struct type *type, int field_num) |
14f9c5c9 | 6783 | { |
d2e4a39e | 6784 | const char *name = TYPE_FIELD_NAME (type, field_num); |
14f9c5c9 AS |
6785 | int p; |
6786 | ||
6787 | p = 0; | |
6788 | while (1) | |
6789 | { | |
d2e4a39e | 6790 | switch (name[p]) |
4c4b4cd2 PH |
6791 | { |
6792 | case '\0': | |
6793 | return 0; | |
6794 | case 'S': | |
6795 | { | |
6796 | LONGEST W; | |
6797 | if (!ada_scan_number (name, p + 1, &W, &p)) | |
6798 | return 0; | |
6799 | if (val == W) | |
6800 | return 1; | |
6801 | break; | |
6802 | } | |
6803 | case 'R': | |
6804 | { | |
6805 | LONGEST L, U; | |
6806 | if (!ada_scan_number (name, p + 1, &L, &p) | |
6807 | || name[p] != 'T' || !ada_scan_number (name, p + 1, &U, &p)) | |
6808 | return 0; | |
6809 | if (val >= L && val <= U) | |
6810 | return 1; | |
6811 | break; | |
6812 | } | |
6813 | case 'O': | |
6814 | return 1; | |
6815 | default: | |
6816 | return 0; | |
6817 | } | |
6818 | } | |
6819 | } | |
6820 | ||
6821 | /* FIXME: Lots of redundancy below. Try to consolidate. */ | |
6822 | ||
6823 | /* Given a value ARG1 (offset by OFFSET bytes) of a struct or union type | |
6824 | ARG_TYPE, extract and return the value of one of its (non-static) | |
6825 | fields. FIELDNO says which field. Differs from value_primitive_field | |
6826 | only in that it can handle packed values of arbitrary type. */ | |
14f9c5c9 | 6827 | |
4c4b4cd2 | 6828 | static struct value * |
d2e4a39e | 6829 | ada_value_primitive_field (struct value *arg1, int offset, int fieldno, |
4c4b4cd2 | 6830 | struct type *arg_type) |
14f9c5c9 | 6831 | { |
14f9c5c9 AS |
6832 | struct type *type; |
6833 | ||
6834 | CHECK_TYPEDEF (arg_type); | |
6835 | type = TYPE_FIELD_TYPE (arg_type, fieldno); | |
6836 | ||
4c4b4cd2 | 6837 | /* Handle packed fields. */ |
14f9c5c9 AS |
6838 | |
6839 | if (TYPE_FIELD_BITSIZE (arg_type, fieldno) != 0) | |
6840 | { | |
6841 | int bit_pos = TYPE_FIELD_BITPOS (arg_type, fieldno); | |
6842 | int bit_size = TYPE_FIELD_BITSIZE (arg_type, fieldno); | |
d2e4a39e | 6843 | |
14f9c5c9 | 6844 | return ada_value_primitive_packed_val (arg1, VALUE_CONTENTS (arg1), |
4c4b4cd2 PH |
6845 | offset + bit_pos / 8, |
6846 | bit_pos % 8, bit_size, type); | |
14f9c5c9 AS |
6847 | } |
6848 | else | |
6849 | return value_primitive_field (arg1, offset, fieldno, arg_type); | |
6850 | } | |
6851 | ||
4c4b4cd2 PH |
6852 | /* Find field with name NAME in object of type TYPE. If found, return 1 |
6853 | after setting *FIELD_TYPE_P to the field's type, *BYTE_OFFSET_P to | |
6854 | OFFSET + the byte offset of the field within an object of that type, | |
6855 | *BIT_OFFSET_P to the bit offset modulo byte size of the field, and | |
6856 | *BIT_SIZE_P to its size in bits if the field is packed, and 0 otherwise. | |
6857 | Looks inside wrappers for the field. Returns 0 if field not | |
6858 | found. */ | |
6859 | static int | |
6860 | find_struct_field (char *name, struct type *type, int offset, | |
6861 | struct type **field_type_p, | |
6862 | int *byte_offset_p, int *bit_offset_p, int *bit_size_p) | |
6863 | { | |
6864 | int i; | |
6865 | ||
6866 | CHECK_TYPEDEF (type); | |
6867 | *field_type_p = NULL; | |
6868 | *byte_offset_p = *bit_offset_p = *bit_size_p = 0; | |
6869 | ||
6870 | for (i = TYPE_NFIELDS (type) - 1; i >= 0; i -= 1) | |
6871 | { | |
6872 | int bit_pos = TYPE_FIELD_BITPOS (type, i); | |
6873 | int fld_offset = offset + bit_pos / 8; | |
6874 | char *t_field_name = TYPE_FIELD_NAME (type, i); | |
6875 | ||
6876 | if (t_field_name == NULL) | |
6877 | continue; | |
6878 | ||
6879 | else if (field_name_match (t_field_name, name)) | |
6880 | { | |
6881 | int bit_size = TYPE_FIELD_BITSIZE (type, i); | |
6882 | *field_type_p = TYPE_FIELD_TYPE (type, i); | |
6883 | *byte_offset_p = fld_offset; | |
6884 | *bit_offset_p = bit_pos % 8; | |
6885 | *bit_size_p = bit_size; | |
6886 | return 1; | |
6887 | } | |
6888 | else if (ada_is_wrapper_field (type, i)) | |
6889 | { | |
6890 | if (find_struct_field (name, TYPE_FIELD_TYPE (type, i), fld_offset, | |
6891 | field_type_p, byte_offset_p, bit_offset_p, | |
6892 | bit_size_p)) | |
6893 | return 1; | |
6894 | } | |
6895 | else if (ada_is_variant_part (type, i)) | |
6896 | { | |
6897 | int j; | |
6898 | struct type *field_type = check_typedef (TYPE_FIELD_TYPE (type, i)); | |
6899 | ||
6900 | for (j = TYPE_NFIELDS (field_type) - 1; j >= 0; j -= 1) | |
6901 | { | |
6902 | if (find_struct_field (name, TYPE_FIELD_TYPE (field_type, j), | |
6903 | fld_offset | |
6904 | + TYPE_FIELD_BITPOS (field_type, j)/8, | |
6905 | field_type_p, byte_offset_p, bit_offset_p, | |
6906 | bit_size_p)) | |
6907 | return 1; | |
6908 | } | |
6909 | } | |
6910 | } | |
6911 | return 0; | |
6912 | } | |
6913 | ||
6914 | ||
14f9c5c9 | 6915 | |
4c4b4cd2 | 6916 | /* Look for a field NAME in ARG. Adjust the address of ARG by OFFSET bytes, |
14f9c5c9 AS |
6917 | and search in it assuming it has (class) type TYPE. |
6918 | If found, return value, else return NULL. | |
6919 | ||
4c4b4cd2 | 6920 | Searches recursively through wrapper fields (e.g., '_parent'). */ |
14f9c5c9 | 6921 | |
4c4b4cd2 | 6922 | static struct value * |
d2e4a39e | 6923 | ada_search_struct_field (char *name, struct value *arg, int offset, |
4c4b4cd2 | 6924 | struct type *type) |
14f9c5c9 AS |
6925 | { |
6926 | int i; | |
6927 | CHECK_TYPEDEF (type); | |
6928 | ||
d2e4a39e | 6929 | for (i = TYPE_NFIELDS (type) - 1; i >= 0; i -= 1) |
14f9c5c9 AS |
6930 | { |
6931 | char *t_field_name = TYPE_FIELD_NAME (type, i); | |
6932 | ||
6933 | if (t_field_name == NULL) | |
4c4b4cd2 | 6934 | continue; |
14f9c5c9 AS |
6935 | |
6936 | else if (field_name_match (t_field_name, name)) | |
4c4b4cd2 | 6937 | return ada_value_primitive_field (arg, offset, i, type); |
14f9c5c9 AS |
6938 | |
6939 | else if (ada_is_wrapper_field (type, i)) | |
4c4b4cd2 PH |
6940 | { |
6941 | struct value *v = | |
6942 | ada_search_struct_field (name, arg, | |
6943 | offset + TYPE_FIELD_BITPOS (type, i) / 8, | |
6944 | TYPE_FIELD_TYPE (type, i)); | |
6945 | if (v != NULL) | |
6946 | return v; | |
6947 | } | |
14f9c5c9 AS |
6948 | |
6949 | else if (ada_is_variant_part (type, i)) | |
4c4b4cd2 PH |
6950 | { |
6951 | int j; | |
6952 | struct type *field_type = check_typedef (TYPE_FIELD_TYPE (type, i)); | |
6953 | int var_offset = offset + TYPE_FIELD_BITPOS (type, i) / 8; | |
6954 | ||
6955 | for (j = TYPE_NFIELDS (field_type) - 1; j >= 0; j -= 1) | |
6956 | { | |
6957 | struct value *v = | |
6958 | ada_search_struct_field (name, arg, | |
6959 | var_offset | |
6960 | + TYPE_FIELD_BITPOS (field_type, j)/8, | |
6961 | TYPE_FIELD_TYPE (field_type, j)); | |
6962 | if (v != NULL) | |
6963 | return v; | |
6964 | } | |
6965 | } | |
14f9c5c9 AS |
6966 | } |
6967 | return NULL; | |
6968 | } | |
d2e4a39e | 6969 | |
4c4b4cd2 PH |
6970 | /* Given ARG, a value of type (pointer or reference to a)* |
6971 | structure/union, extract the component named NAME from the ultimate | |
6972 | target structure/union and return it as a value with its | |
6973 | appropriate type. If ARG is a pointer or reference and the field | |
6974 | is not packed, returns a reference to the field, otherwise the | |
6975 | value of the field (an lvalue if ARG is an lvalue). | |
14f9c5c9 | 6976 | |
4c4b4cd2 PH |
6977 | The routine searches for NAME among all members of the structure itself |
6978 | and (recursively) among all members of any wrapper members | |
14f9c5c9 AS |
6979 | (e.g., '_parent'). |
6980 | ||
4c4b4cd2 PH |
6981 | ERR is a name (for use in error messages) that identifies the class |
6982 | of entity that ARG is supposed to be. ERR may be null, indicating | |
6983 | that on error, the function simply returns NULL, and does not | |
6984 | throw an error. (FIXME: True only if ARG is a pointer or reference | |
6985 | at the moment). */ | |
14f9c5c9 | 6986 | |
d2e4a39e | 6987 | struct value * |
ebf56fd3 | 6988 | ada_value_struct_elt (struct value *arg, char *name, char *err) |
14f9c5c9 | 6989 | { |
4c4b4cd2 | 6990 | struct type *t, *t1; |
d2e4a39e | 6991 | struct value *v; |
14f9c5c9 | 6992 | |
4c4b4cd2 PH |
6993 | v = NULL; |
6994 | t1 = t = check_typedef (VALUE_TYPE (arg)); | |
6995 | if (TYPE_CODE (t) == TYPE_CODE_REF) | |
6996 | { | |
6997 | t1 = TYPE_TARGET_TYPE (t); | |
6998 | if (t1 == NULL) | |
6999 | { | |
7000 | if (err == NULL) | |
7001 | return NULL; | |
7002 | else | |
7003 | error ("Bad value type in a %s.", err); | |
7004 | } | |
7005 | CHECK_TYPEDEF (t1); | |
7006 | if (TYPE_CODE (t1) == TYPE_CODE_PTR) | |
7007 | { | |
7008 | COERCE_REF (arg); | |
7009 | t = t1; | |
7010 | } | |
7011 | } | |
14f9c5c9 | 7012 | |
4c4b4cd2 PH |
7013 | while (TYPE_CODE (t) == TYPE_CODE_PTR) |
7014 | { | |
7015 | t1 = TYPE_TARGET_TYPE (t); | |
7016 | if (t1 == NULL) | |
7017 | { | |
7018 | if (err == NULL) | |
7019 | return NULL; | |
7020 | else | |
7021 | error ("Bad value type in a %s.", err); | |
7022 | } | |
7023 | CHECK_TYPEDEF (t1); | |
7024 | if (TYPE_CODE (t1) == TYPE_CODE_PTR) | |
7025 | { | |
7026 | arg = value_ind (arg); | |
7027 | t = t1; | |
7028 | } | |
7029 | else | |
7030 | break; | |
7031 | } | |
14f9c5c9 | 7032 | |
4c4b4cd2 | 7033 | if (TYPE_CODE (t1) != TYPE_CODE_STRUCT && TYPE_CODE (t1) != TYPE_CODE_UNION) |
14f9c5c9 | 7034 | { |
4c4b4cd2 PH |
7035 | if (err == NULL) |
7036 | return NULL; | |
7037 | else | |
7038 | error ("Attempt to extract a component of a value that is not a %s.", | |
7039 | err); | |
14f9c5c9 AS |
7040 | } |
7041 | ||
4c4b4cd2 PH |
7042 | if (t1 == t) |
7043 | v = ada_search_struct_field (name, arg, 0, t); | |
7044 | else | |
7045 | { | |
7046 | int bit_offset, bit_size, byte_offset; | |
7047 | struct type *field_type; | |
7048 | CORE_ADDR address; | |
7049 | ||
7050 | if (TYPE_CODE (t) == TYPE_CODE_PTR) | |
7051 | address = value_as_address (arg); | |
7052 | else | |
7053 | address = unpack_pointer (t, VALUE_CONTENTS (arg)); | |
14f9c5c9 | 7054 | |
4c4b4cd2 PH |
7055 | t1 = ada_to_fixed_type (ada_get_base_type (t1), NULL, address, NULL); |
7056 | if (find_struct_field (name, t1, 0, | |
7057 | &field_type, &byte_offset, &bit_offset, &bit_size)) | |
7058 | { | |
7059 | if (bit_size != 0) | |
7060 | { | |
7061 | arg = ada_value_ind (arg); | |
7062 | v = ada_value_primitive_packed_val (arg, NULL, byte_offset, | |
7063 | bit_offset, bit_size, | |
7064 | field_type); | |
7065 | } | |
7066 | else | |
7067 | v = value_from_pointer (lookup_reference_type (field_type), | |
7068 | address + byte_offset); | |
7069 | } | |
7070 | } | |
7071 | ||
7072 | if (v == NULL && err != NULL) | |
14f9c5c9 AS |
7073 | error ("There is no member named %s.", name); |
7074 | ||
7075 | return v; | |
7076 | } | |
7077 | ||
7078 | /* Given a type TYPE, look up the type of the component of type named NAME. | |
4c4b4cd2 PH |
7079 | If DISPP is non-null, add its byte displacement from the beginning of a |
7080 | structure (pointed to by a value) of type TYPE to *DISPP (does not | |
14f9c5c9 AS |
7081 | work for packed fields). |
7082 | ||
7083 | Matches any field whose name has NAME as a prefix, possibly | |
4c4b4cd2 | 7084 | followed by "___". |
14f9c5c9 | 7085 | |
4c4b4cd2 PH |
7086 | TYPE can be either a struct or union. If REFOK, TYPE may also |
7087 | be a (pointer or reference)+ to a struct or union, and the | |
7088 | ultimate target type will be searched. | |
14f9c5c9 AS |
7089 | |
7090 | Looks recursively into variant clauses and parent types. | |
7091 | ||
4c4b4cd2 PH |
7092 | If NOERR is nonzero, return NULL if NAME is not suitably defined or |
7093 | TYPE is not a type of the right kind. */ | |
14f9c5c9 | 7094 | |
4c4b4cd2 PH |
7095 | static struct type * |
7096 | ada_lookup_struct_elt_type (struct type *type, char *name, int refok, | |
7097 | int noerr, int *dispp) | |
14f9c5c9 AS |
7098 | { |
7099 | int i; | |
7100 | ||
7101 | if (name == NULL) | |
7102 | goto BadName; | |
7103 | ||
4c4b4cd2 PH |
7104 | if (refok && type != NULL) |
7105 | while (1) | |
7106 | { | |
7107 | CHECK_TYPEDEF (type); | |
7108 | if (TYPE_CODE (type) != TYPE_CODE_PTR | |
7109 | && TYPE_CODE (type) != TYPE_CODE_REF) | |
7110 | break; | |
7111 | type = TYPE_TARGET_TYPE (type); | |
7112 | } | |
14f9c5c9 | 7113 | |
4c4b4cd2 PH |
7114 | if (type == NULL |
7115 | || (TYPE_CODE (type) != TYPE_CODE_STRUCT && | |
7116 | TYPE_CODE (type) != TYPE_CODE_UNION)) | |
14f9c5c9 | 7117 | { |
4c4b4cd2 PH |
7118 | if (noerr) |
7119 | return NULL; | |
7120 | else | |
7121 | { | |
7122 | target_terminal_ours (); | |
7123 | gdb_flush (gdb_stdout); | |
7124 | fprintf_unfiltered (gdb_stderr, "Type "); | |
7125 | if (type == NULL) | |
7126 | fprintf_unfiltered (gdb_stderr, "(null)"); | |
7127 | else | |
7128 | type_print (type, "", gdb_stderr, -1); | |
7129 | error (" is not a structure or union type"); | |
7130 | } | |
14f9c5c9 AS |
7131 | } |
7132 | ||
7133 | type = to_static_fixed_type (type); | |
7134 | ||
7135 | for (i = 0; i < TYPE_NFIELDS (type); i += 1) | |
7136 | { | |
7137 | char *t_field_name = TYPE_FIELD_NAME (type, i); | |
7138 | struct type *t; | |
7139 | int disp; | |
d2e4a39e | 7140 | |
14f9c5c9 | 7141 | if (t_field_name == NULL) |
4c4b4cd2 | 7142 | continue; |
14f9c5c9 AS |
7143 | |
7144 | else if (field_name_match (t_field_name, name)) | |
4c4b4cd2 PH |
7145 | { |
7146 | if (dispp != NULL) | |
7147 | *dispp += TYPE_FIELD_BITPOS (type, i) / 8; | |
7148 | return check_typedef (TYPE_FIELD_TYPE (type, i)); | |
7149 | } | |
14f9c5c9 AS |
7150 | |
7151 | else if (ada_is_wrapper_field (type, i)) | |
4c4b4cd2 PH |
7152 | { |
7153 | disp = 0; | |
7154 | t = ada_lookup_struct_elt_type (TYPE_FIELD_TYPE (type, i), name, | |
7155 | 0, 1, &disp); | |
7156 | if (t != NULL) | |
7157 | { | |
7158 | if (dispp != NULL) | |
7159 | *dispp += disp + TYPE_FIELD_BITPOS (type, i) / 8; | |
7160 | return t; | |
7161 | } | |
7162 | } | |
14f9c5c9 AS |
7163 | |
7164 | else if (ada_is_variant_part (type, i)) | |
4c4b4cd2 PH |
7165 | { |
7166 | int j; | |
7167 | struct type *field_type = check_typedef (TYPE_FIELD_TYPE (type, i)); | |
7168 | ||
7169 | for (j = TYPE_NFIELDS (field_type) - 1; j >= 0; j -= 1) | |
7170 | { | |
7171 | disp = 0; | |
7172 | t = ada_lookup_struct_elt_type (TYPE_FIELD_TYPE (field_type, j), | |
7173 | name, 0, 1, &disp); | |
7174 | if (t != NULL) | |
7175 | { | |
7176 | if (dispp != NULL) | |
7177 | *dispp += disp + TYPE_FIELD_BITPOS (type, i) / 8; | |
7178 | return t; | |
7179 | } | |
7180 | } | |
7181 | } | |
14f9c5c9 AS |
7182 | |
7183 | } | |
7184 | ||
7185 | BadName: | |
d2e4a39e | 7186 | if (!noerr) |
14f9c5c9 AS |
7187 | { |
7188 | target_terminal_ours (); | |
7189 | gdb_flush (gdb_stdout); | |
7190 | fprintf_unfiltered (gdb_stderr, "Type "); | |
7191 | type_print (type, "", gdb_stderr, -1); | |
7192 | fprintf_unfiltered (gdb_stderr, " has no component named "); | |
7193 | error ("%s", name == NULL ? "<null>" : name); | |
7194 | } | |
7195 | ||
7196 | return NULL; | |
7197 | } | |
7198 | ||
7199 | /* Assuming that VAR_TYPE is the type of a variant part of a record (a union), | |
7200 | within a value of type OUTER_TYPE that is stored in GDB at | |
4c4b4cd2 PH |
7201 | OUTER_VALADDR, determine which variant clause (field number in VAR_TYPE, |
7202 | numbering from 0) is applicable. Returns -1 if none are. */ | |
14f9c5c9 | 7203 | |
d2e4a39e | 7204 | int |
ebf56fd3 | 7205 | ada_which_variant_applies (struct type *var_type, struct type *outer_type, |
4c4b4cd2 | 7206 | char *outer_valaddr) |
14f9c5c9 AS |
7207 | { |
7208 | int others_clause; | |
7209 | int i; | |
7210 | int disp; | |
d2e4a39e AS |
7211 | struct type *discrim_type; |
7212 | char *discrim_name = ada_variant_discrim_name (var_type); | |
14f9c5c9 AS |
7213 | LONGEST discrim_val; |
7214 | ||
7215 | disp = 0; | |
d2e4a39e | 7216 | discrim_type = |
4c4b4cd2 | 7217 | ada_lookup_struct_elt_type (outer_type, discrim_name, 1, 1, &disp); |
14f9c5c9 AS |
7218 | if (discrim_type == NULL) |
7219 | return -1; | |
7220 | discrim_val = unpack_long (discrim_type, outer_valaddr + disp); | |
7221 | ||
7222 | others_clause = -1; | |
7223 | for (i = 0; i < TYPE_NFIELDS (var_type); i += 1) | |
7224 | { | |
7225 | if (ada_is_others_clause (var_type, i)) | |
4c4b4cd2 | 7226 | others_clause = i; |
14f9c5c9 | 7227 | else if (ada_in_variant (discrim_val, var_type, i)) |
4c4b4cd2 | 7228 | return i; |
14f9c5c9 AS |
7229 | } |
7230 | ||
7231 | return others_clause; | |
7232 | } | |
d2e4a39e | 7233 | \f |
14f9c5c9 AS |
7234 | |
7235 | ||
4c4b4cd2 | 7236 | /* Dynamic-Sized Records */ |
14f9c5c9 AS |
7237 | |
7238 | /* Strategy: The type ostensibly attached to a value with dynamic size | |
7239 | (i.e., a size that is not statically recorded in the debugging | |
7240 | data) does not accurately reflect the size or layout of the value. | |
7241 | Our strategy is to convert these values to values with accurate, | |
4c4b4cd2 | 7242 | conventional types that are constructed on the fly. */ |
14f9c5c9 AS |
7243 | |
7244 | /* There is a subtle and tricky problem here. In general, we cannot | |
7245 | determine the size of dynamic records without its data. However, | |
7246 | the 'struct value' data structure, which GDB uses to represent | |
7247 | quantities in the inferior process (the target), requires the size | |
7248 | of the type at the time of its allocation in order to reserve space | |
7249 | for GDB's internal copy of the data. That's why the | |
7250 | 'to_fixed_xxx_type' routines take (target) addresses as parameters, | |
4c4b4cd2 | 7251 | rather than struct value*s. |
14f9c5c9 AS |
7252 | |
7253 | However, GDB's internal history variables ($1, $2, etc.) are | |
7254 | struct value*s containing internal copies of the data that are not, in | |
7255 | general, the same as the data at their corresponding addresses in | |
7256 | the target. Fortunately, the types we give to these values are all | |
7257 | conventional, fixed-size types (as per the strategy described | |
7258 | above), so that we don't usually have to perform the | |
7259 | 'to_fixed_xxx_type' conversions to look at their values. | |
7260 | Unfortunately, there is one exception: if one of the internal | |
7261 | history variables is an array whose elements are unconstrained | |
7262 | records, then we will need to create distinct fixed types for each | |
7263 | element selected. */ | |
7264 | ||
7265 | /* The upshot of all of this is that many routines take a (type, host | |
7266 | address, target address) triple as arguments to represent a value. | |
7267 | The host address, if non-null, is supposed to contain an internal | |
7268 | copy of the relevant data; otherwise, the program is to consult the | |
4c4b4cd2 | 7269 | target at the target address. */ |
14f9c5c9 AS |
7270 | |
7271 | /* Assuming that VAL0 represents a pointer value, the result of | |
7272 | dereferencing it. Differs from value_ind in its treatment of | |
4c4b4cd2 | 7273 | dynamic-sized types. */ |
14f9c5c9 | 7274 | |
d2e4a39e AS |
7275 | struct value * |
7276 | ada_value_ind (struct value *val0) | |
14f9c5c9 | 7277 | { |
d2e4a39e | 7278 | struct value *val = unwrap_value (value_ind (val0)); |
4c4b4cd2 | 7279 | return ada_to_fixed_value (val); |
14f9c5c9 AS |
7280 | } |
7281 | ||
7282 | /* The value resulting from dereferencing any "reference to" | |
4c4b4cd2 PH |
7283 | qualifiers on VAL0. */ |
7284 | ||
d2e4a39e AS |
7285 | static struct value * |
7286 | ada_coerce_ref (struct value *val0) | |
7287 | { | |
7288 | if (TYPE_CODE (VALUE_TYPE (val0)) == TYPE_CODE_REF) | |
7289 | { | |
7290 | struct value *val = val0; | |
7291 | COERCE_REF (val); | |
7292 | val = unwrap_value (val); | |
4c4b4cd2 | 7293 | return ada_to_fixed_value (val); |
d2e4a39e AS |
7294 | } |
7295 | else | |
14f9c5c9 AS |
7296 | return val0; |
7297 | } | |
7298 | ||
7299 | /* Return OFF rounded upward if necessary to a multiple of | |
4c4b4cd2 | 7300 | ALIGNMENT (a power of 2). */ |
14f9c5c9 AS |
7301 | |
7302 | static unsigned int | |
ebf56fd3 | 7303 | align_value (unsigned int off, unsigned int alignment) |
14f9c5c9 AS |
7304 | { |
7305 | return (off + alignment - 1) & ~(alignment - 1); | |
7306 | } | |
7307 | ||
4c4b4cd2 | 7308 | /* Return the bit alignment required for field #F of template type TYPE. */ |
14f9c5c9 AS |
7309 | |
7310 | static unsigned int | |
ebf56fd3 | 7311 | field_alignment (struct type *type, int f) |
14f9c5c9 | 7312 | { |
d2e4a39e | 7313 | const char *name = TYPE_FIELD_NAME (type, f); |
14f9c5c9 AS |
7314 | int len = (name == NULL) ? 0 : strlen (name); |
7315 | int align_offset; | |
7316 | ||
4c4b4cd2 PH |
7317 | if (!isdigit (name[len - 1])) |
7318 | return 1; | |
14f9c5c9 | 7319 | |
d2e4a39e | 7320 | if (isdigit (name[len - 2])) |
14f9c5c9 AS |
7321 | align_offset = len - 2; |
7322 | else | |
7323 | align_offset = len - 1; | |
7324 | ||
4c4b4cd2 | 7325 | if (align_offset < 7 || strncmp ("___XV", name + align_offset - 6, 5) != 0) |
14f9c5c9 AS |
7326 | return TARGET_CHAR_BIT; |
7327 | ||
4c4b4cd2 PH |
7328 | return atoi (name + align_offset) * TARGET_CHAR_BIT; |
7329 | } | |
7330 | ||
7331 | /* Find a symbol named NAME. Ignores ambiguity. */ | |
7332 | ||
7333 | struct symbol * | |
7334 | ada_find_any_symbol (const char *name) | |
7335 | { | |
7336 | struct symbol *sym; | |
7337 | ||
7338 | sym = standard_lookup (name, get_selected_block (NULL), VAR_DOMAIN); | |
7339 | if (sym != NULL && SYMBOL_CLASS (sym) == LOC_TYPEDEF) | |
7340 | return sym; | |
7341 | ||
7342 | sym = standard_lookup (name, NULL, STRUCT_DOMAIN); | |
7343 | return sym; | |
14f9c5c9 AS |
7344 | } |
7345 | ||
7346 | /* Find a type named NAME. Ignores ambiguity. */ | |
4c4b4cd2 | 7347 | |
d2e4a39e | 7348 | struct type * |
ebf56fd3 | 7349 | ada_find_any_type (const char *name) |
14f9c5c9 | 7350 | { |
4c4b4cd2 | 7351 | struct symbol *sym = ada_find_any_symbol (name); |
14f9c5c9 | 7352 | |
14f9c5c9 AS |
7353 | if (sym != NULL) |
7354 | return SYMBOL_TYPE (sym); | |
7355 | ||
7356 | return NULL; | |
7357 | } | |
7358 | ||
4c4b4cd2 PH |
7359 | /* Given a symbol NAME and its associated BLOCK, search all symbols |
7360 | for its ___XR counterpart, which is the ``renaming'' symbol | |
7361 | associated to NAME. Return this symbol if found, return | |
7362 | NULL otherwise. */ | |
7363 | ||
7364 | struct symbol * | |
7365 | ada_find_renaming_symbol (const char *name, struct block *block) | |
7366 | { | |
7367 | const struct symbol *function_sym = block_function (block); | |
7368 | char *rename; | |
7369 | ||
7370 | if (function_sym != NULL) | |
7371 | { | |
7372 | /* If the symbol is defined inside a function, NAME is not fully | |
7373 | qualified. This means we need to prepend the function name | |
7374 | as well as adding the ``___XR'' suffix to build the name of | |
7375 | the associated renaming symbol. */ | |
7376 | char *function_name = SYMBOL_LINKAGE_NAME (function_sym); | |
7377 | const int function_name_len = strlen (function_name); | |
7378 | const int rename_len = function_name_len | |
7379 | + 2 /* "__" */ | |
7380 | + strlen (name) | |
7381 | + 6 /* "___XR\0" */; | |
7382 | ||
7383 | /* Library-level functions are a special case, as GNAT adds | |
7384 | a ``_ada_'' prefix to the function name to avoid namespace | |
7385 | pollution. However, the renaming symbol themselves do not | |
7386 | have this prefix, so we need to skip this prefix if present. */ | |
7387 | if (function_name_len > 5 /* "_ada_" */ | |
7388 | && strstr (function_name, "_ada_") == function_name) | |
7389 | function_name = function_name + 5; | |
7390 | ||
7391 | rename = (char *) alloca (rename_len * sizeof (char)); | |
7392 | sprintf (rename, "%s__%s___XR", function_name, name); | |
7393 | } | |
7394 | else | |
7395 | { | |
7396 | const int rename_len = strlen (name) + 6; | |
7397 | rename = (char *) alloca (rename_len * sizeof (char)); | |
7398 | sprintf (rename, "%s___XR", name); | |
7399 | } | |
7400 | ||
7401 | return ada_find_any_symbol (rename); | |
7402 | } | |
7403 | ||
14f9c5c9 | 7404 | /* Because of GNAT encoding conventions, several GDB symbols may match a |
4c4b4cd2 | 7405 | given type name. If the type denoted by TYPE0 is to be preferred to |
14f9c5c9 | 7406 | that of TYPE1 for purposes of type printing, return non-zero; |
4c4b4cd2 PH |
7407 | otherwise return 0. */ |
7408 | ||
14f9c5c9 | 7409 | int |
d2e4a39e | 7410 | ada_prefer_type (struct type *type0, struct type *type1) |
14f9c5c9 AS |
7411 | { |
7412 | if (type1 == NULL) | |
7413 | return 1; | |
7414 | else if (type0 == NULL) | |
7415 | return 0; | |
7416 | else if (TYPE_CODE (type1) == TYPE_CODE_VOID) | |
7417 | return 1; | |
7418 | else if (TYPE_CODE (type0) == TYPE_CODE_VOID) | |
7419 | return 0; | |
4c4b4cd2 PH |
7420 | else if (TYPE_NAME (type1) == NULL && TYPE_NAME (type0) != NULL) |
7421 | return 1; | |
14f9c5c9 AS |
7422 | else if (ada_is_packed_array_type (type0)) |
7423 | return 1; | |
4c4b4cd2 PH |
7424 | else if (ada_is_array_descriptor_type (type0) |
7425 | && !ada_is_array_descriptor_type (type1)) | |
14f9c5c9 | 7426 | return 1; |
d2e4a39e | 7427 | else if (ada_renaming_type (type0) != NULL |
4c4b4cd2 | 7428 | && ada_renaming_type (type1) == NULL) |
14f9c5c9 AS |
7429 | return 1; |
7430 | return 0; | |
7431 | } | |
7432 | ||
7433 | /* The name of TYPE, which is either its TYPE_NAME, or, if that is | |
4c4b4cd2 PH |
7434 | null, its TYPE_TAG_NAME. Null if TYPE is null. */ |
7435 | ||
d2e4a39e AS |
7436 | char * |
7437 | ada_type_name (struct type *type) | |
14f9c5c9 | 7438 | { |
d2e4a39e | 7439 | if (type == NULL) |
14f9c5c9 AS |
7440 | return NULL; |
7441 | else if (TYPE_NAME (type) != NULL) | |
7442 | return TYPE_NAME (type); | |
7443 | else | |
7444 | return TYPE_TAG_NAME (type); | |
7445 | } | |
7446 | ||
7447 | /* Find a parallel type to TYPE whose name is formed by appending | |
4c4b4cd2 | 7448 | SUFFIX to the name of TYPE. */ |
14f9c5c9 | 7449 | |
d2e4a39e | 7450 | struct type * |
ebf56fd3 | 7451 | ada_find_parallel_type (struct type *type, const char *suffix) |
14f9c5c9 | 7452 | { |
d2e4a39e | 7453 | static char *name; |
14f9c5c9 | 7454 | static size_t name_len = 0; |
14f9c5c9 | 7455 | int len; |
d2e4a39e AS |
7456 | char *typename = ada_type_name (type); |
7457 | ||
14f9c5c9 AS |
7458 | if (typename == NULL) |
7459 | return NULL; | |
7460 | ||
7461 | len = strlen (typename); | |
7462 | ||
d2e4a39e | 7463 | GROW_VECT (name, name_len, len + strlen (suffix) + 1); |
14f9c5c9 AS |
7464 | |
7465 | strcpy (name, typename); | |
7466 | strcpy (name + len, suffix); | |
7467 | ||
7468 | return ada_find_any_type (name); | |
7469 | } | |
7470 | ||
7471 | ||
7472 | /* If TYPE is a variable-size record type, return the corresponding template | |
4c4b4cd2 | 7473 | type describing its fields. Otherwise, return NULL. */ |
14f9c5c9 | 7474 | |
d2e4a39e AS |
7475 | static struct type * |
7476 | dynamic_template_type (struct type *type) | |
14f9c5c9 AS |
7477 | { |
7478 | CHECK_TYPEDEF (type); | |
7479 | ||
7480 | if (type == NULL || TYPE_CODE (type) != TYPE_CODE_STRUCT | |
d2e4a39e | 7481 | || ada_type_name (type) == NULL) |
14f9c5c9 | 7482 | return NULL; |
d2e4a39e | 7483 | else |
14f9c5c9 AS |
7484 | { |
7485 | int len = strlen (ada_type_name (type)); | |
4c4b4cd2 PH |
7486 | if (len > 6 && strcmp (ada_type_name (type) + len - 6, "___XVE") == 0) |
7487 | return type; | |
14f9c5c9 | 7488 | else |
4c4b4cd2 | 7489 | return ada_find_parallel_type (type, "___XVE"); |
14f9c5c9 AS |
7490 | } |
7491 | } | |
7492 | ||
7493 | /* Assuming that TEMPL_TYPE is a union or struct type, returns | |
4c4b4cd2 | 7494 | non-zero iff field FIELD_NUM of TEMPL_TYPE has dynamic size. */ |
14f9c5c9 | 7495 | |
d2e4a39e AS |
7496 | static int |
7497 | is_dynamic_field (struct type *templ_type, int field_num) | |
14f9c5c9 AS |
7498 | { |
7499 | const char *name = TYPE_FIELD_NAME (templ_type, field_num); | |
d2e4a39e | 7500 | return name != NULL |
14f9c5c9 AS |
7501 | && TYPE_CODE (TYPE_FIELD_TYPE (templ_type, field_num)) == TYPE_CODE_PTR |
7502 | && strstr (name, "___XVL") != NULL; | |
7503 | } | |
7504 | ||
4c4b4cd2 PH |
7505 | /* The index of the variant field of TYPE, or -1 if TYPE does not |
7506 | represent a variant record type. */ | |
14f9c5c9 | 7507 | |
d2e4a39e | 7508 | static int |
4c4b4cd2 | 7509 | variant_field_index (struct type *type) |
14f9c5c9 AS |
7510 | { |
7511 | int f; | |
7512 | ||
4c4b4cd2 PH |
7513 | if (type == NULL || TYPE_CODE (type) != TYPE_CODE_STRUCT) |
7514 | return -1; | |
7515 | ||
7516 | for (f = 0; f < TYPE_NFIELDS (type); f += 1) | |
7517 | { | |
7518 | if (ada_is_variant_part (type, f)) | |
7519 | return f; | |
7520 | } | |
7521 | return -1; | |
14f9c5c9 AS |
7522 | } |
7523 | ||
4c4b4cd2 PH |
7524 | /* A record type with no fields. */ |
7525 | ||
d2e4a39e AS |
7526 | static struct type * |
7527 | empty_record (struct objfile *objfile) | |
14f9c5c9 | 7528 | { |
d2e4a39e | 7529 | struct type *type = alloc_type (objfile); |
14f9c5c9 AS |
7530 | TYPE_CODE (type) = TYPE_CODE_STRUCT; |
7531 | TYPE_NFIELDS (type) = 0; | |
7532 | TYPE_FIELDS (type) = NULL; | |
7533 | TYPE_NAME (type) = "<empty>"; | |
7534 | TYPE_TAG_NAME (type) = NULL; | |
7535 | TYPE_FLAGS (type) = 0; | |
7536 | TYPE_LENGTH (type) = 0; | |
7537 | return type; | |
7538 | } | |
7539 | ||
7540 | /* An ordinary record type (with fixed-length fields) that describes | |
4c4b4cd2 PH |
7541 | the value of type TYPE at VALADDR or ADDRESS (see comments at |
7542 | the beginning of this section) VAL according to GNAT conventions. | |
7543 | DVAL0 should describe the (portion of a) record that contains any | |
14f9c5c9 AS |
7544 | necessary discriminants. It should be NULL if VALUE_TYPE (VAL) is |
7545 | an outer-level type (i.e., as opposed to a branch of a variant.) A | |
7546 | variant field (unless unchecked) is replaced by a particular branch | |
4c4b4cd2 | 7547 | of the variant. |
14f9c5c9 | 7548 | |
4c4b4cd2 PH |
7549 | If not KEEP_DYNAMIC_FIELDS, then all fields whose position or |
7550 | length are not statically known are discarded. As a consequence, | |
7551 | VALADDR, ADDRESS and DVAL0 are ignored. | |
7552 | ||
7553 | NOTE: Limitations: For now, we assume that dynamic fields and | |
7554 | variants occupy whole numbers of bytes. However, they need not be | |
7555 | byte-aligned. */ | |
7556 | ||
7557 | struct type * | |
7558 | ada_template_to_fixed_record_type_1 (struct type *type, char *valaddr, | |
7559 | CORE_ADDR address, struct value *dval0, | |
7560 | int keep_dynamic_fields) | |
14f9c5c9 | 7561 | { |
d2e4a39e AS |
7562 | struct value *mark = value_mark (); |
7563 | struct value *dval; | |
7564 | struct type *rtype; | |
14f9c5c9 | 7565 | int nfields, bit_len; |
4c4b4cd2 | 7566 | int variant_field; |
14f9c5c9 | 7567 | long off; |
4c4b4cd2 | 7568 | int fld_bit_len, bit_incr; |
14f9c5c9 AS |
7569 | int f; |
7570 | ||
4c4b4cd2 PH |
7571 | /* Compute the number of fields in this record type that are going |
7572 | to be processed: unless keep_dynamic_fields, this includes only | |
7573 | fields whose position and length are static will be processed. */ | |
7574 | if (keep_dynamic_fields) | |
7575 | nfields = TYPE_NFIELDS (type); | |
7576 | else | |
7577 | { | |
7578 | nfields = 0; | |
7579 | while (nfields < TYPE_NFIELDS (type) | |
7580 | && !ada_is_variant_part (type, nfields) | |
7581 | && !is_dynamic_field (type, nfields)) | |
7582 | nfields++; | |
7583 | } | |
7584 | ||
14f9c5c9 AS |
7585 | rtype = alloc_type (TYPE_OBJFILE (type)); |
7586 | TYPE_CODE (rtype) = TYPE_CODE_STRUCT; | |
7587 | INIT_CPLUS_SPECIFIC (rtype); | |
7588 | TYPE_NFIELDS (rtype) = nfields; | |
d2e4a39e | 7589 | TYPE_FIELDS (rtype) = (struct field *) |
14f9c5c9 AS |
7590 | TYPE_ALLOC (rtype, nfields * sizeof (struct field)); |
7591 | memset (TYPE_FIELDS (rtype), 0, sizeof (struct field) * nfields); | |
7592 | TYPE_NAME (rtype) = ada_type_name (type); | |
7593 | TYPE_TAG_NAME (rtype) = NULL; | |
4c4b4cd2 | 7594 | TYPE_FLAGS (rtype) |= TYPE_FLAG_FIXED_INSTANCE; |
14f9c5c9 | 7595 | |
d2e4a39e AS |
7596 | off = 0; |
7597 | bit_len = 0; | |
4c4b4cd2 PH |
7598 | variant_field = -1; |
7599 | ||
14f9c5c9 AS |
7600 | for (f = 0; f < nfields; f += 1) |
7601 | { | |
d2e4a39e | 7602 | off = |
4c4b4cd2 PH |
7603 | align_value (off, |
7604 | field_alignment (type, f)) + TYPE_FIELD_BITPOS (type, f); | |
14f9c5c9 | 7605 | TYPE_FIELD_BITPOS (rtype, f) = off; |
d2e4a39e | 7606 | TYPE_FIELD_BITSIZE (rtype, f) = 0; |
14f9c5c9 | 7607 | |
d2e4a39e | 7608 | if (ada_is_variant_part (type, f)) |
4c4b4cd2 PH |
7609 | { |
7610 | variant_field = f; | |
7611 | fld_bit_len = bit_incr = 0; | |
7612 | } | |
14f9c5c9 | 7613 | else if (is_dynamic_field (type, f)) |
4c4b4cd2 PH |
7614 | { |
7615 | if (dval0 == NULL) | |
7616 | dval = value_from_contents_and_address (rtype, valaddr, address); | |
7617 | else | |
7618 | dval = dval0; | |
7619 | ||
7620 | TYPE_FIELD_TYPE (rtype, f) = | |
7621 | ada_to_fixed_type | |
7622 | (ada_get_base_type | |
7623 | (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, f))), | |
7624 | cond_offset_host (valaddr, off / TARGET_CHAR_BIT), | |
7625 | cond_offset_target (address, off / TARGET_CHAR_BIT), dval); | |
7626 | TYPE_FIELD_NAME (rtype, f) = TYPE_FIELD_NAME (type, f); | |
7627 | bit_incr = fld_bit_len = | |
7628 | TYPE_LENGTH (TYPE_FIELD_TYPE (rtype, f)) * TARGET_CHAR_BIT; | |
7629 | } | |
14f9c5c9 | 7630 | else |
4c4b4cd2 PH |
7631 | { |
7632 | TYPE_FIELD_TYPE (rtype, f) = TYPE_FIELD_TYPE (type, f); | |
7633 | TYPE_FIELD_NAME (rtype, f) = TYPE_FIELD_NAME (type, f); | |
7634 | if (TYPE_FIELD_BITSIZE (type, f) > 0) | |
7635 | bit_incr = fld_bit_len = | |
7636 | TYPE_FIELD_BITSIZE (rtype, f) = TYPE_FIELD_BITSIZE (type, f); | |
7637 | else | |
7638 | bit_incr = fld_bit_len = | |
7639 | TYPE_LENGTH (TYPE_FIELD_TYPE (type, f)) * TARGET_CHAR_BIT; | |
7640 | } | |
14f9c5c9 | 7641 | if (off + fld_bit_len > bit_len) |
4c4b4cd2 | 7642 | bit_len = off + fld_bit_len; |
14f9c5c9 | 7643 | off += bit_incr; |
4c4b4cd2 PH |
7644 | TYPE_LENGTH (rtype) = |
7645 | align_value (bit_len, TARGET_CHAR_BIT) / TARGET_CHAR_BIT; | |
14f9c5c9 | 7646 | } |
4c4b4cd2 PH |
7647 | |
7648 | /* We handle the variant part, if any, at the end because of certain | |
7649 | odd cases in which it is re-ordered so as NOT the last field of | |
7650 | the record. This can happen in the presence of representation | |
7651 | clauses. */ | |
7652 | if (variant_field >= 0) | |
7653 | { | |
7654 | struct type *branch_type; | |
7655 | ||
7656 | off = TYPE_FIELD_BITPOS (rtype, variant_field); | |
7657 | ||
7658 | if (dval0 == NULL) | |
7659 | dval = value_from_contents_and_address (rtype, valaddr, address); | |
7660 | else | |
7661 | dval = dval0; | |
7662 | ||
7663 | branch_type = | |
7664 | to_fixed_variant_branch_type | |
7665 | (TYPE_FIELD_TYPE (type, variant_field), | |
7666 | cond_offset_host (valaddr, off / TARGET_CHAR_BIT), | |
7667 | cond_offset_target (address, off / TARGET_CHAR_BIT), dval); | |
7668 | if (branch_type == NULL) | |
7669 | { | |
7670 | for (f = variant_field + 1; f < TYPE_NFIELDS (rtype); f += 1) | |
7671 | TYPE_FIELDS (rtype)[f - 1] = TYPE_FIELDS (rtype)[f]; | |
7672 | TYPE_NFIELDS (rtype) -= 1; | |
7673 | } | |
7674 | else | |
7675 | { | |
7676 | TYPE_FIELD_TYPE (rtype, variant_field) = branch_type; | |
7677 | TYPE_FIELD_NAME (rtype, variant_field) = "S"; | |
7678 | fld_bit_len = | |
7679 | TYPE_LENGTH (TYPE_FIELD_TYPE (rtype, variant_field)) * | |
7680 | TARGET_CHAR_BIT; | |
7681 | if (off + fld_bit_len > bit_len) | |
7682 | bit_len = off + fld_bit_len; | |
7683 | TYPE_LENGTH (rtype) = | |
7684 | align_value (bit_len, TARGET_CHAR_BIT) / TARGET_CHAR_BIT; | |
7685 | } | |
7686 | } | |
7687 | ||
14f9c5c9 AS |
7688 | TYPE_LENGTH (rtype) = align_value (TYPE_LENGTH (rtype), TYPE_LENGTH (type)); |
7689 | ||
7690 | value_free_to_mark (mark); | |
d2e4a39e | 7691 | if (TYPE_LENGTH (rtype) > varsize_limit) |
14f9c5c9 AS |
7692 | error ("record type with dynamic size is larger than varsize-limit"); |
7693 | return rtype; | |
7694 | } | |
7695 | ||
4c4b4cd2 PH |
7696 | /* As for ada_template_to_fixed_record_type_1 with KEEP_DYNAMIC_FIELDS |
7697 | of 1. */ | |
14f9c5c9 | 7698 | |
d2e4a39e | 7699 | static struct type * |
4c4b4cd2 PH |
7700 | template_to_fixed_record_type (struct type *type, char *valaddr, |
7701 | CORE_ADDR address, struct value *dval0) | |
7702 | { | |
7703 | return ada_template_to_fixed_record_type_1 (type, valaddr, | |
7704 | address, dval0, 1); | |
7705 | } | |
7706 | ||
7707 | /* An ordinary record type in which ___XVL-convention fields and | |
7708 | ___XVU- and ___XVN-convention field types in TYPE0 are replaced with | |
7709 | static approximations, containing all possible fields. Uses | |
7710 | no runtime values. Useless for use in values, but that's OK, | |
7711 | since the results are used only for type determinations. Works on both | |
7712 | structs and unions. Representation note: to save space, we memorize | |
7713 | the result of this function in the TYPE_TARGET_TYPE of the | |
7714 | template type. */ | |
7715 | ||
7716 | static struct type * | |
7717 | template_to_static_fixed_type (struct type *type0) | |
14f9c5c9 AS |
7718 | { |
7719 | struct type *type; | |
7720 | int nfields; | |
7721 | int f; | |
7722 | ||
4c4b4cd2 PH |
7723 | if (TYPE_TARGET_TYPE (type0) != NULL) |
7724 | return TYPE_TARGET_TYPE (type0); | |
7725 | ||
7726 | nfields = TYPE_NFIELDS (type0); | |
7727 | type = type0; | |
14f9c5c9 AS |
7728 | |
7729 | for (f = 0; f < nfields; f += 1) | |
7730 | { | |
4c4b4cd2 PH |
7731 | struct type *field_type = CHECK_TYPEDEF (TYPE_FIELD_TYPE (type0, f)); |
7732 | struct type *new_type; | |
14f9c5c9 | 7733 | |
4c4b4cd2 PH |
7734 | if (is_dynamic_field (type0, f)) |
7735 | new_type = to_static_fixed_type (TYPE_TARGET_TYPE (field_type)); | |
14f9c5c9 | 7736 | else |
4c4b4cd2 PH |
7737 | new_type = to_static_fixed_type (field_type); |
7738 | if (type == type0 && new_type != field_type) | |
7739 | { | |
7740 | TYPE_TARGET_TYPE (type0) = type = alloc_type (TYPE_OBJFILE (type0)); | |
7741 | TYPE_CODE (type) = TYPE_CODE (type0); | |
7742 | INIT_CPLUS_SPECIFIC (type); | |
7743 | TYPE_NFIELDS (type) = nfields; | |
7744 | TYPE_FIELDS (type) = (struct field *) | |
7745 | TYPE_ALLOC (type, nfields * sizeof (struct field)); | |
7746 | memcpy (TYPE_FIELDS (type), TYPE_FIELDS (type0), | |
7747 | sizeof (struct field) * nfields); | |
7748 | TYPE_NAME (type) = ada_type_name (type0); | |
7749 | TYPE_TAG_NAME (type) = NULL; | |
7750 | TYPE_FLAGS (type) |= TYPE_FLAG_FIXED_INSTANCE; | |
7751 | TYPE_LENGTH (type) = 0; | |
7752 | } | |
7753 | TYPE_FIELD_TYPE (type, f) = new_type; | |
7754 | TYPE_FIELD_NAME (type, f) = TYPE_FIELD_NAME (type0, f); | |
14f9c5c9 | 7755 | } |
14f9c5c9 AS |
7756 | return type; |
7757 | } | |
7758 | ||
4c4b4cd2 PH |
7759 | /* Given an object of type TYPE whose contents are at VALADDR and |
7760 | whose address in memory is ADDRESS, returns a revision of TYPE -- | |
7761 | a non-dynamic-sized record with a variant part -- in which | |
7762 | the variant part is replaced with the appropriate branch. Looks | |
7763 | for discriminant values in DVAL0, which can be NULL if the record | |
7764 | contains the necessary discriminant values. */ | |
7765 | ||
d2e4a39e AS |
7766 | static struct type * |
7767 | to_record_with_fixed_variant_part (struct type *type, char *valaddr, | |
4c4b4cd2 | 7768 | CORE_ADDR address, struct value *dval0) |
14f9c5c9 | 7769 | { |
d2e4a39e | 7770 | struct value *mark = value_mark (); |
4c4b4cd2 | 7771 | struct value *dval; |
d2e4a39e | 7772 | struct type *rtype; |
14f9c5c9 AS |
7773 | struct type *branch_type; |
7774 | int nfields = TYPE_NFIELDS (type); | |
4c4b4cd2 | 7775 | int variant_field = variant_field_index (type); |
14f9c5c9 | 7776 | |
4c4b4cd2 | 7777 | if (variant_field == -1) |
14f9c5c9 AS |
7778 | return type; |
7779 | ||
4c4b4cd2 PH |
7780 | if (dval0 == NULL) |
7781 | dval = value_from_contents_and_address (type, valaddr, address); | |
7782 | else | |
7783 | dval = dval0; | |
7784 | ||
14f9c5c9 AS |
7785 | rtype = alloc_type (TYPE_OBJFILE (type)); |
7786 | TYPE_CODE (rtype) = TYPE_CODE_STRUCT; | |
4c4b4cd2 PH |
7787 | INIT_CPLUS_SPECIFIC (rtype); |
7788 | TYPE_NFIELDS (rtype) = nfields; | |
d2e4a39e AS |
7789 | TYPE_FIELDS (rtype) = |
7790 | (struct field *) TYPE_ALLOC (rtype, nfields * sizeof (struct field)); | |
7791 | memcpy (TYPE_FIELDS (rtype), TYPE_FIELDS (type), | |
4c4b4cd2 | 7792 | sizeof (struct field) * nfields); |
14f9c5c9 AS |
7793 | TYPE_NAME (rtype) = ada_type_name (type); |
7794 | TYPE_TAG_NAME (rtype) = NULL; | |
4c4b4cd2 | 7795 | TYPE_FLAGS (rtype) |= TYPE_FLAG_FIXED_INSTANCE; |
14f9c5c9 AS |
7796 | TYPE_LENGTH (rtype) = TYPE_LENGTH (type); |
7797 | ||
4c4b4cd2 PH |
7798 | branch_type = to_fixed_variant_branch_type |
7799 | (TYPE_FIELD_TYPE (type, variant_field), | |
d2e4a39e | 7800 | cond_offset_host (valaddr, |
4c4b4cd2 PH |
7801 | TYPE_FIELD_BITPOS (type, variant_field) |
7802 | / TARGET_CHAR_BIT), | |
d2e4a39e | 7803 | cond_offset_target (address, |
4c4b4cd2 PH |
7804 | TYPE_FIELD_BITPOS (type, variant_field) |
7805 | / TARGET_CHAR_BIT), dval); | |
d2e4a39e | 7806 | if (branch_type == NULL) |
14f9c5c9 | 7807 | { |
4c4b4cd2 PH |
7808 | int f; |
7809 | for (f = variant_field + 1; f < nfields; f += 1) | |
7810 | TYPE_FIELDS (rtype)[f - 1] = TYPE_FIELDS (rtype)[f]; | |
14f9c5c9 | 7811 | TYPE_NFIELDS (rtype) -= 1; |
14f9c5c9 AS |
7812 | } |
7813 | else | |
7814 | { | |
4c4b4cd2 PH |
7815 | TYPE_FIELD_TYPE (rtype, variant_field) = branch_type; |
7816 | TYPE_FIELD_NAME (rtype, variant_field) = "S"; | |
7817 | TYPE_FIELD_BITSIZE (rtype, variant_field) = 0; | |
14f9c5c9 | 7818 | TYPE_LENGTH (rtype) += TYPE_LENGTH (branch_type); |
14f9c5c9 | 7819 | } |
4c4b4cd2 | 7820 | TYPE_LENGTH (rtype) -= TYPE_LENGTH (TYPE_FIELD_TYPE (type, variant_field)); |
d2e4a39e | 7821 | |
4c4b4cd2 | 7822 | value_free_to_mark (mark); |
14f9c5c9 AS |
7823 | return rtype; |
7824 | } | |
7825 | ||
7826 | /* An ordinary record type (with fixed-length fields) that describes | |
7827 | the value at (TYPE0, VALADDR, ADDRESS) [see explanation at | |
7828 | beginning of this section]. Any necessary discriminants' values | |
4c4b4cd2 PH |
7829 | should be in DVAL, a record value; it may be NULL if the object |
7830 | at ADDR itself contains any necessary discriminant values. | |
7831 | Additionally, VALADDR and ADDRESS may also be NULL if no discriminant | |
7832 | values from the record are needed. Except in the case that DVAL, | |
7833 | VALADDR, and ADDRESS are all 0 or NULL, a variant field (unless | |
7834 | unchecked) is replaced by a particular branch of the variant. | |
7835 | ||
7836 | NOTE: the case in which DVAL and VALADDR are NULL and ADDRESS is 0 | |
7837 | is questionable and may be removed. It can arise during the | |
7838 | processing of an unconstrained-array-of-record type where all the | |
7839 | variant branches have exactly the same size. This is because in | |
7840 | such cases, the compiler does not bother to use the XVS convention | |
7841 | when encoding the record. I am currently dubious of this | |
7842 | shortcut and suspect the compiler should be altered. FIXME. */ | |
14f9c5c9 | 7843 | |
d2e4a39e | 7844 | static struct type * |
4c4b4cd2 PH |
7845 | to_fixed_record_type (struct type *type0, char *valaddr, |
7846 | CORE_ADDR address, struct value *dval) | |
14f9c5c9 | 7847 | { |
d2e4a39e | 7848 | struct type *templ_type; |
14f9c5c9 | 7849 | |
4c4b4cd2 PH |
7850 | if (TYPE_FLAGS (type0) & TYPE_FLAG_FIXED_INSTANCE) |
7851 | return type0; | |
7852 | ||
d2e4a39e | 7853 | templ_type = dynamic_template_type (type0); |
14f9c5c9 AS |
7854 | |
7855 | if (templ_type != NULL) | |
7856 | return template_to_fixed_record_type (templ_type, valaddr, address, dval); | |
4c4b4cd2 PH |
7857 | else if (variant_field_index (type0) >= 0) |
7858 | { | |
7859 | if (dval == NULL && valaddr == NULL && address == 0) | |
7860 | return type0; | |
7861 | return to_record_with_fixed_variant_part (type0, valaddr, address, | |
7862 | dval); | |
7863 | } | |
14f9c5c9 AS |
7864 | else |
7865 | { | |
4c4b4cd2 | 7866 | TYPE_FLAGS (type0) |= TYPE_FLAG_FIXED_INSTANCE; |
14f9c5c9 AS |
7867 | return type0; |
7868 | } | |
7869 | ||
7870 | } | |
7871 | ||
7872 | /* An ordinary record type (with fixed-length fields) that describes | |
7873 | the value at (VAR_TYPE0, VALADDR, ADDRESS), where VAR_TYPE0 is a | |
7874 | union type. Any necessary discriminants' values should be in DVAL, | |
7875 | a record value. That is, this routine selects the appropriate | |
7876 | branch of the union at ADDR according to the discriminant value | |
4c4b4cd2 | 7877 | indicated in the union's type name. */ |
14f9c5c9 | 7878 | |
d2e4a39e AS |
7879 | static struct type * |
7880 | to_fixed_variant_branch_type (struct type *var_type0, char *valaddr, | |
4c4b4cd2 | 7881 | CORE_ADDR address, struct value *dval) |
14f9c5c9 AS |
7882 | { |
7883 | int which; | |
d2e4a39e AS |
7884 | struct type *templ_type; |
7885 | struct type *var_type; | |
14f9c5c9 AS |
7886 | |
7887 | if (TYPE_CODE (var_type0) == TYPE_CODE_PTR) | |
7888 | var_type = TYPE_TARGET_TYPE (var_type0); | |
d2e4a39e | 7889 | else |
14f9c5c9 AS |
7890 | var_type = var_type0; |
7891 | ||
7892 | templ_type = ada_find_parallel_type (var_type, "___XVU"); | |
7893 | ||
7894 | if (templ_type != NULL) | |
7895 | var_type = templ_type; | |
7896 | ||
d2e4a39e AS |
7897 | which = |
7898 | ada_which_variant_applies (var_type, | |
4c4b4cd2 | 7899 | VALUE_TYPE (dval), VALUE_CONTENTS (dval)); |
14f9c5c9 AS |
7900 | |
7901 | if (which < 0) | |
7902 | return empty_record (TYPE_OBJFILE (var_type)); | |
7903 | else if (is_dynamic_field (var_type, which)) | |
4c4b4cd2 | 7904 | return to_fixed_record_type |
d2e4a39e AS |
7905 | (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (var_type, which)), |
7906 | valaddr, address, dval); | |
4c4b4cd2 | 7907 | else if (variant_field_index (TYPE_FIELD_TYPE (var_type, which)) >= 0) |
d2e4a39e AS |
7908 | return |
7909 | to_fixed_record_type | |
7910 | (TYPE_FIELD_TYPE (var_type, which), valaddr, address, dval); | |
14f9c5c9 AS |
7911 | else |
7912 | return TYPE_FIELD_TYPE (var_type, which); | |
7913 | } | |
7914 | ||
7915 | /* Assuming that TYPE0 is an array type describing the type of a value | |
7916 | at ADDR, and that DVAL describes a record containing any | |
7917 | discriminants used in TYPE0, returns a type for the value that | |
7918 | contains no dynamic components (that is, no components whose sizes | |
7919 | are determined by run-time quantities). Unless IGNORE_TOO_BIG is | |
7920 | true, gives an error message if the resulting type's size is over | |
4c4b4cd2 | 7921 | varsize_limit. */ |
14f9c5c9 | 7922 | |
d2e4a39e AS |
7923 | static struct type * |
7924 | to_fixed_array_type (struct type *type0, struct value *dval, | |
4c4b4cd2 | 7925 | int ignore_too_big) |
14f9c5c9 | 7926 | { |
d2e4a39e AS |
7927 | struct type *index_type_desc; |
7928 | struct type *result; | |
14f9c5c9 | 7929 | |
4c4b4cd2 PH |
7930 | if (ada_is_packed_array_type (type0) /* revisit? */ |
7931 | || (TYPE_FLAGS (type0) & TYPE_FLAG_FIXED_INSTANCE)) | |
7932 | return type0; | |
14f9c5c9 AS |
7933 | |
7934 | index_type_desc = ada_find_parallel_type (type0, "___XA"); | |
7935 | if (index_type_desc == NULL) | |
7936 | { | |
7937 | struct type *elt_type0 = check_typedef (TYPE_TARGET_TYPE (type0)); | |
7938 | /* NOTE: elt_type---the fixed version of elt_type0---should never | |
4c4b4cd2 PH |
7939 | depend on the contents of the array in properly constructed |
7940 | debugging data. */ | |
d2e4a39e | 7941 | struct type *elt_type = ada_to_fixed_type (elt_type0, 0, 0, dval); |
14f9c5c9 AS |
7942 | |
7943 | if (elt_type0 == elt_type) | |
4c4b4cd2 | 7944 | result = type0; |
14f9c5c9 | 7945 | else |
4c4b4cd2 PH |
7946 | result = create_array_type (alloc_type (TYPE_OBJFILE (type0)), |
7947 | elt_type, TYPE_INDEX_TYPE (type0)); | |
14f9c5c9 AS |
7948 | } |
7949 | else | |
7950 | { | |
7951 | int i; | |
7952 | struct type *elt_type0; | |
7953 | ||
7954 | elt_type0 = type0; | |
7955 | for (i = TYPE_NFIELDS (index_type_desc); i > 0; i -= 1) | |
4c4b4cd2 | 7956 | elt_type0 = TYPE_TARGET_TYPE (elt_type0); |
14f9c5c9 AS |
7957 | |
7958 | /* NOTE: result---the fixed version of elt_type0---should never | |
4c4b4cd2 PH |
7959 | depend on the contents of the array in properly constructed |
7960 | debugging data. */ | |
d2e4a39e | 7961 | result = ada_to_fixed_type (check_typedef (elt_type0), 0, 0, dval); |
14f9c5c9 | 7962 | for (i = TYPE_NFIELDS (index_type_desc) - 1; i >= 0; i -= 1) |
4c4b4cd2 PH |
7963 | { |
7964 | struct type *range_type = | |
7965 | to_fixed_range_type (TYPE_FIELD_NAME (index_type_desc, i), | |
7966 | dval, TYPE_OBJFILE (type0)); | |
7967 | result = create_array_type (alloc_type (TYPE_OBJFILE (type0)), | |
7968 | result, range_type); | |
7969 | } | |
d2e4a39e | 7970 | if (!ignore_too_big && TYPE_LENGTH (result) > varsize_limit) |
4c4b4cd2 | 7971 | error ("array type with dynamic size is larger than varsize-limit"); |
14f9c5c9 AS |
7972 | } |
7973 | ||
4c4b4cd2 | 7974 | TYPE_FLAGS (result) |= TYPE_FLAG_FIXED_INSTANCE; |
14f9c5c9 | 7975 | return result; |
d2e4a39e | 7976 | } |
14f9c5c9 AS |
7977 | |
7978 | ||
7979 | /* A standard type (containing no dynamically sized components) | |
7980 | corresponding to TYPE for the value (TYPE, VALADDR, ADDRESS) | |
7981 | DVAL describes a record containing any discriminants used in TYPE0, | |
4c4b4cd2 PH |
7982 | and may be NULL if there are none, or if the object of type TYPE at |
7983 | ADDRESS or in VALADDR contains these discriminants. */ | |
14f9c5c9 | 7984 | |
d2e4a39e | 7985 | struct type * |
4c4b4cd2 PH |
7986 | ada_to_fixed_type (struct type *type, char *valaddr, |
7987 | CORE_ADDR address, struct value *dval) | |
14f9c5c9 AS |
7988 | { |
7989 | CHECK_TYPEDEF (type); | |
d2e4a39e AS |
7990 | switch (TYPE_CODE (type)) |
7991 | { | |
7992 | default: | |
14f9c5c9 | 7993 | return type; |
d2e4a39e | 7994 | case TYPE_CODE_STRUCT: |
4c4b4cd2 PH |
7995 | { |
7996 | struct type *static_type = to_static_fixed_type (type); | |
7997 | if (ada_is_tagged_type (static_type, 0)) | |
7998 | { | |
7999 | struct type *real_type = | |
8000 | type_from_tag (value_tag_from_contents_and_address (static_type, | |
8001 | valaddr, | |
8002 | address)); | |
8003 | if (real_type != NULL) | |
8004 | type = real_type; | |
8005 | } | |
8006 | return to_fixed_record_type (type, valaddr, address, NULL); | |
8007 | } | |
d2e4a39e | 8008 | case TYPE_CODE_ARRAY: |
4c4b4cd2 | 8009 | return to_fixed_array_type (type, dval, 1); |
d2e4a39e AS |
8010 | case TYPE_CODE_UNION: |
8011 | if (dval == NULL) | |
4c4b4cd2 | 8012 | return type; |
d2e4a39e | 8013 | else |
4c4b4cd2 | 8014 | return to_fixed_variant_branch_type (type, valaddr, address, dval); |
d2e4a39e | 8015 | } |
14f9c5c9 AS |
8016 | } |
8017 | ||
8018 | /* A standard (static-sized) type corresponding as well as possible to | |
4c4b4cd2 | 8019 | TYPE0, but based on no runtime data. */ |
14f9c5c9 | 8020 | |
d2e4a39e AS |
8021 | static struct type * |
8022 | to_static_fixed_type (struct type *type0) | |
14f9c5c9 | 8023 | { |
d2e4a39e | 8024 | struct type *type; |
14f9c5c9 AS |
8025 | |
8026 | if (type0 == NULL) | |
8027 | return NULL; | |
8028 | ||
4c4b4cd2 PH |
8029 | if (TYPE_FLAGS (type0) & TYPE_FLAG_FIXED_INSTANCE) |
8030 | return type0; | |
8031 | ||
14f9c5c9 | 8032 | CHECK_TYPEDEF (type0); |
d2e4a39e | 8033 | |
14f9c5c9 AS |
8034 | switch (TYPE_CODE (type0)) |
8035 | { | |
8036 | default: | |
8037 | return type0; | |
8038 | case TYPE_CODE_STRUCT: | |
8039 | type = dynamic_template_type (type0); | |
d2e4a39e | 8040 | if (type != NULL) |
4c4b4cd2 PH |
8041 | return template_to_static_fixed_type (type); |
8042 | else | |
8043 | return template_to_static_fixed_type (type0); | |
14f9c5c9 AS |
8044 | case TYPE_CODE_UNION: |
8045 | type = ada_find_parallel_type (type0, "___XVU"); | |
8046 | if (type != NULL) | |
4c4b4cd2 PH |
8047 | return template_to_static_fixed_type (type); |
8048 | else | |
8049 | return template_to_static_fixed_type (type0); | |
14f9c5c9 AS |
8050 | } |
8051 | } | |
8052 | ||
4c4b4cd2 PH |
8053 | /* A static approximation of TYPE with all type wrappers removed. */ |
8054 | ||
d2e4a39e AS |
8055 | static struct type * |
8056 | static_unwrap_type (struct type *type) | |
14f9c5c9 AS |
8057 | { |
8058 | if (ada_is_aligner_type (type)) | |
8059 | { | |
d2e4a39e | 8060 | struct type *type1 = TYPE_FIELD_TYPE (check_typedef (type), 0); |
14f9c5c9 | 8061 | if (ada_type_name (type1) == NULL) |
4c4b4cd2 | 8062 | TYPE_NAME (type1) = ada_type_name (type); |
14f9c5c9 AS |
8063 | |
8064 | return static_unwrap_type (type1); | |
8065 | } | |
d2e4a39e | 8066 | else |
14f9c5c9 | 8067 | { |
d2e4a39e AS |
8068 | struct type *raw_real_type = ada_get_base_type (type); |
8069 | if (raw_real_type == type) | |
4c4b4cd2 | 8070 | return type; |
14f9c5c9 | 8071 | else |
4c4b4cd2 | 8072 | return to_static_fixed_type (raw_real_type); |
14f9c5c9 AS |
8073 | } |
8074 | } | |
8075 | ||
8076 | /* In some cases, incomplete and private types require | |
4c4b4cd2 | 8077 | cross-references that are not resolved as records (for example, |
14f9c5c9 AS |
8078 | type Foo; |
8079 | type FooP is access Foo; | |
8080 | V: FooP; | |
8081 | type Foo is array ...; | |
4c4b4cd2 | 8082 | ). In these cases, since there is no mechanism for producing |
14f9c5c9 AS |
8083 | cross-references to such types, we instead substitute for FooP a |
8084 | stub enumeration type that is nowhere resolved, and whose tag is | |
4c4b4cd2 | 8085 | the name of the actual type. Call these types "non-record stubs". */ |
14f9c5c9 AS |
8086 | |
8087 | /* A type equivalent to TYPE that is not a non-record stub, if one | |
4c4b4cd2 PH |
8088 | exists, otherwise TYPE. */ |
8089 | ||
d2e4a39e AS |
8090 | struct type * |
8091 | ada_completed_type (struct type *type) | |
14f9c5c9 AS |
8092 | { |
8093 | CHECK_TYPEDEF (type); | |
8094 | if (type == NULL || TYPE_CODE (type) != TYPE_CODE_ENUM | |
8095 | || (TYPE_FLAGS (type) & TYPE_FLAG_STUB) == 0 | |
8096 | || TYPE_TAG_NAME (type) == NULL) | |
8097 | return type; | |
d2e4a39e | 8098 | else |
14f9c5c9 | 8099 | { |
d2e4a39e AS |
8100 | char *name = TYPE_TAG_NAME (type); |
8101 | struct type *type1 = ada_find_any_type (name); | |
14f9c5c9 AS |
8102 | return (type1 == NULL) ? type : type1; |
8103 | } | |
8104 | } | |
8105 | ||
8106 | /* A value representing the data at VALADDR/ADDRESS as described by | |
8107 | type TYPE0, but with a standard (static-sized) type that correctly | |
8108 | describes it. If VAL0 is not NULL and TYPE0 already is a standard | |
8109 | type, then return VAL0 [this feature is simply to avoid redundant | |
4c4b4cd2 | 8110 | creation of struct values]. */ |
14f9c5c9 | 8111 | |
4c4b4cd2 PH |
8112 | static struct value * |
8113 | ada_to_fixed_value_create (struct type *type0, CORE_ADDR address, | |
8114 | struct value *val0) | |
14f9c5c9 | 8115 | { |
4c4b4cd2 | 8116 | struct type *type = ada_to_fixed_type (type0, 0, address, NULL); |
14f9c5c9 AS |
8117 | if (type == type0 && val0 != NULL) |
8118 | return val0; | |
d2e4a39e | 8119 | else |
4c4b4cd2 PH |
8120 | return value_from_contents_and_address (type, 0, address); |
8121 | } | |
8122 | ||
8123 | /* A value representing VAL, but with a standard (static-sized) type | |
8124 | that correctly describes it. Does not necessarily create a new | |
8125 | value. */ | |
8126 | ||
8127 | static struct value * | |
8128 | ada_to_fixed_value (struct value *val) | |
8129 | { | |
8130 | return ada_to_fixed_value_create (VALUE_TYPE (val), | |
8131 | VALUE_ADDRESS (val) + VALUE_OFFSET (val), | |
8132 | val); | |
14f9c5c9 AS |
8133 | } |
8134 | ||
4c4b4cd2 PH |
8135 | /* If the PC is pointing inside a function prologue, then re-adjust it |
8136 | past this prologue. */ | |
8137 | ||
8138 | static void | |
8139 | adjust_pc_past_prologue (CORE_ADDR *pc) | |
8140 | { | |
8141 | struct symbol *func_sym = find_pc_function (*pc); | |
8142 | ||
8143 | if (func_sym) | |
8144 | { | |
8145 | const struct symtab_and_line sal = find_function_start_sal (func_sym, 1); | |
8146 | ||
8147 | if (*pc <= sal.pc) | |
8148 | *pc = sal.pc; | |
8149 | } | |
8150 | } | |
8151 | ||
8152 | /* A value representing VAL, but with a standard (static-sized) type | |
14f9c5c9 AS |
8153 | chosen to approximate the real type of VAL as well as possible, but |
8154 | without consulting any runtime values. For Ada dynamic-sized | |
4c4b4cd2 | 8155 | types, therefore, the type of the result is likely to be inaccurate. */ |
14f9c5c9 | 8156 | |
d2e4a39e AS |
8157 | struct value * |
8158 | ada_to_static_fixed_value (struct value *val) | |
14f9c5c9 | 8159 | { |
d2e4a39e | 8160 | struct type *type = |
14f9c5c9 AS |
8161 | to_static_fixed_type (static_unwrap_type (VALUE_TYPE (val))); |
8162 | if (type == VALUE_TYPE (val)) | |
8163 | return val; | |
8164 | else | |
4c4b4cd2 | 8165 | return coerce_unspec_val_to_type (val, type); |
14f9c5c9 | 8166 | } |
d2e4a39e | 8167 | \f |
14f9c5c9 | 8168 | |
14f9c5c9 AS |
8169 | /* Attributes */ |
8170 | ||
4c4b4cd2 PH |
8171 | /* Table mapping attribute numbers to names. |
8172 | NOTE: Keep up to date with enum ada_attribute definition in ada-lang.h. */ | |
14f9c5c9 | 8173 | |
d2e4a39e | 8174 | static const char *attribute_names[] = { |
14f9c5c9 AS |
8175 | "<?>", |
8176 | ||
d2e4a39e | 8177 | "first", |
14f9c5c9 AS |
8178 | "last", |
8179 | "length", | |
8180 | "image", | |
14f9c5c9 AS |
8181 | "max", |
8182 | "min", | |
4c4b4cd2 PH |
8183 | "modulus", |
8184 | "pos", | |
8185 | "size", | |
8186 | "tag", | |
14f9c5c9 | 8187 | "val", |
14f9c5c9 AS |
8188 | 0 |
8189 | }; | |
8190 | ||
d2e4a39e | 8191 | const char * |
4c4b4cd2 | 8192 | ada_attribute_name (enum exp_opcode n) |
14f9c5c9 | 8193 | { |
4c4b4cd2 PH |
8194 | if (n >= OP_ATR_FIRST && n <= (int) OP_ATR_VAL) |
8195 | return attribute_names[n - OP_ATR_FIRST + 1]; | |
14f9c5c9 AS |
8196 | else |
8197 | return attribute_names[0]; | |
8198 | } | |
8199 | ||
4c4b4cd2 | 8200 | /* Evaluate the 'POS attribute applied to ARG. */ |
14f9c5c9 | 8201 | |
4c4b4cd2 PH |
8202 | static LONGEST |
8203 | pos_atr (struct value *arg) | |
14f9c5c9 AS |
8204 | { |
8205 | struct type *type = VALUE_TYPE (arg); | |
8206 | ||
d2e4a39e | 8207 | if (!discrete_type_p (type)) |
14f9c5c9 AS |
8208 | error ("'POS only defined on discrete types"); |
8209 | ||
8210 | if (TYPE_CODE (type) == TYPE_CODE_ENUM) | |
8211 | { | |
8212 | int i; | |
8213 | LONGEST v = value_as_long (arg); | |
8214 | ||
d2e4a39e | 8215 | for (i = 0; i < TYPE_NFIELDS (type); i += 1) |
4c4b4cd2 PH |
8216 | { |
8217 | if (v == TYPE_FIELD_BITPOS (type, i)) | |
8218 | return i; | |
8219 | } | |
14f9c5c9 AS |
8220 | error ("enumeration value is invalid: can't find 'POS"); |
8221 | } | |
8222 | else | |
4c4b4cd2 PH |
8223 | return value_as_long (arg); |
8224 | } | |
8225 | ||
8226 | static struct value * | |
8227 | value_pos_atr (struct value *arg) | |
8228 | { | |
8229 | return value_from_longest (builtin_type_ada_int, pos_atr (arg)); | |
14f9c5c9 AS |
8230 | } |
8231 | ||
4c4b4cd2 | 8232 | /* Evaluate the TYPE'VAL attribute applied to ARG. */ |
14f9c5c9 | 8233 | |
d2e4a39e AS |
8234 | static struct value * |
8235 | value_val_atr (struct type *type, struct value *arg) | |
14f9c5c9 | 8236 | { |
d2e4a39e | 8237 | if (!discrete_type_p (type)) |
14f9c5c9 | 8238 | error ("'VAL only defined on discrete types"); |
d2e4a39e | 8239 | if (!integer_type_p (VALUE_TYPE (arg))) |
14f9c5c9 AS |
8240 | error ("'VAL requires integral argument"); |
8241 | ||
8242 | if (TYPE_CODE (type) == TYPE_CODE_ENUM) | |
8243 | { | |
8244 | long pos = value_as_long (arg); | |
8245 | if (pos < 0 || pos >= TYPE_NFIELDS (type)) | |
4c4b4cd2 | 8246 | error ("argument to 'VAL out of range"); |
d2e4a39e | 8247 | return value_from_longest (type, TYPE_FIELD_BITPOS (type, pos)); |
14f9c5c9 AS |
8248 | } |
8249 | else | |
8250 | return value_from_longest (type, value_as_long (arg)); | |
8251 | } | |
14f9c5c9 | 8252 | \f |
d2e4a39e | 8253 | |
4c4b4cd2 | 8254 | /* Evaluation */ |
14f9c5c9 | 8255 | |
4c4b4cd2 PH |
8256 | /* True if TYPE appears to be an Ada character type. |
8257 | [At the moment, this is true only for Character and Wide_Character; | |
8258 | It is a heuristic test that could stand improvement]. */ | |
14f9c5c9 | 8259 | |
d2e4a39e AS |
8260 | int |
8261 | ada_is_character_type (struct type *type) | |
14f9c5c9 | 8262 | { |
d2e4a39e AS |
8263 | const char *name = ada_type_name (type); |
8264 | return | |
14f9c5c9 | 8265 | name != NULL |
d2e4a39e | 8266 | && (TYPE_CODE (type) == TYPE_CODE_CHAR |
4c4b4cd2 PH |
8267 | || TYPE_CODE (type) == TYPE_CODE_INT |
8268 | || TYPE_CODE (type) == TYPE_CODE_RANGE) | |
8269 | && (strcmp (name, "character") == 0 | |
8270 | || strcmp (name, "wide_character") == 0 | |
8271 | || strcmp (name, "unsigned char") == 0); | |
14f9c5c9 AS |
8272 | } |
8273 | ||
4c4b4cd2 | 8274 | /* True if TYPE appears to be an Ada string type. */ |
14f9c5c9 AS |
8275 | |
8276 | int | |
ebf56fd3 | 8277 | ada_is_string_type (struct type *type) |
14f9c5c9 AS |
8278 | { |
8279 | CHECK_TYPEDEF (type); | |
d2e4a39e | 8280 | if (type != NULL |
14f9c5c9 | 8281 | && TYPE_CODE (type) != TYPE_CODE_PTR |
4c4b4cd2 | 8282 | && (ada_is_simple_array_type (type) || ada_is_array_descriptor_type (type)) |
14f9c5c9 AS |
8283 | && ada_array_arity (type) == 1) |
8284 | { | |
8285 | struct type *elttype = ada_array_element_type (type, 1); | |
8286 | ||
8287 | return ada_is_character_type (elttype); | |
8288 | } | |
d2e4a39e | 8289 | else |
14f9c5c9 AS |
8290 | return 0; |
8291 | } | |
8292 | ||
8293 | ||
8294 | /* True if TYPE is a struct type introduced by the compiler to force the | |
8295 | alignment of a value. Such types have a single field with a | |
4c4b4cd2 | 8296 | distinctive name. */ |
14f9c5c9 AS |
8297 | |
8298 | int | |
ebf56fd3 | 8299 | ada_is_aligner_type (struct type *type) |
14f9c5c9 AS |
8300 | { |
8301 | CHECK_TYPEDEF (type); | |
8302 | return (TYPE_CODE (type) == TYPE_CODE_STRUCT | |
4c4b4cd2 PH |
8303 | && TYPE_NFIELDS (type) == 1 |
8304 | && strcmp (TYPE_FIELD_NAME (type, 0), "F") == 0); | |
14f9c5c9 AS |
8305 | } |
8306 | ||
8307 | /* If there is an ___XVS-convention type parallel to SUBTYPE, return | |
4c4b4cd2 | 8308 | the parallel type. */ |
14f9c5c9 | 8309 | |
d2e4a39e AS |
8310 | struct type * |
8311 | ada_get_base_type (struct type *raw_type) | |
14f9c5c9 | 8312 | { |
d2e4a39e AS |
8313 | struct type *real_type_namer; |
8314 | struct type *raw_real_type; | |
14f9c5c9 AS |
8315 | |
8316 | if (raw_type == NULL || TYPE_CODE (raw_type) != TYPE_CODE_STRUCT) | |
8317 | return raw_type; | |
8318 | ||
8319 | real_type_namer = ada_find_parallel_type (raw_type, "___XVS"); | |
d2e4a39e | 8320 | if (real_type_namer == NULL |
14f9c5c9 AS |
8321 | || TYPE_CODE (real_type_namer) != TYPE_CODE_STRUCT |
8322 | || TYPE_NFIELDS (real_type_namer) != 1) | |
8323 | return raw_type; | |
8324 | ||
8325 | raw_real_type = ada_find_any_type (TYPE_FIELD_NAME (real_type_namer, 0)); | |
d2e4a39e | 8326 | if (raw_real_type == NULL) |
14f9c5c9 AS |
8327 | return raw_type; |
8328 | else | |
8329 | return raw_real_type; | |
d2e4a39e | 8330 | } |
14f9c5c9 | 8331 | |
4c4b4cd2 | 8332 | /* The type of value designated by TYPE, with all aligners removed. */ |
14f9c5c9 | 8333 | |
d2e4a39e AS |
8334 | struct type * |
8335 | ada_aligned_type (struct type *type) | |
14f9c5c9 AS |
8336 | { |
8337 | if (ada_is_aligner_type (type)) | |
8338 | return ada_aligned_type (TYPE_FIELD_TYPE (type, 0)); | |
8339 | else | |
8340 | return ada_get_base_type (type); | |
8341 | } | |
8342 | ||
8343 | ||
8344 | /* The address of the aligned value in an object at address VALADDR | |
4c4b4cd2 | 8345 | having type TYPE. Assumes ada_is_aligner_type (TYPE). */ |
14f9c5c9 | 8346 | |
d2e4a39e | 8347 | char * |
ebf56fd3 | 8348 | ada_aligned_value_addr (struct type *type, char *valaddr) |
14f9c5c9 | 8349 | { |
d2e4a39e | 8350 | if (ada_is_aligner_type (type)) |
14f9c5c9 | 8351 | return ada_aligned_value_addr (TYPE_FIELD_TYPE (type, 0), |
4c4b4cd2 PH |
8352 | valaddr + |
8353 | TYPE_FIELD_BITPOS (type, | |
8354 | 0) / TARGET_CHAR_BIT); | |
14f9c5c9 AS |
8355 | else |
8356 | return valaddr; | |
8357 | } | |
8358 | ||
4c4b4cd2 PH |
8359 | |
8360 | ||
14f9c5c9 | 8361 | /* The printed representation of an enumeration literal with encoded |
4c4b4cd2 | 8362 | name NAME. The value is good to the next call of ada_enum_name. */ |
d2e4a39e AS |
8363 | const char * |
8364 | ada_enum_name (const char *name) | |
14f9c5c9 | 8365 | { |
4c4b4cd2 PH |
8366 | static char *result; |
8367 | static size_t result_len = 0; | |
d2e4a39e | 8368 | char *tmp; |
14f9c5c9 | 8369 | |
4c4b4cd2 PH |
8370 | /* First, unqualify the enumeration name: |
8371 | 1. Search for the last '.' character. If we find one, then skip | |
8372 | all the preceeding characters, the unqualified name starts | |
8373 | right after that dot. | |
8374 | 2. Otherwise, we may be debugging on a target where the compiler | |
8375 | translates dots into "__". Search forward for double underscores, | |
8376 | but stop searching when we hit an overloading suffix, which is | |
8377 | of the form "__" followed by digits. */ | |
8378 | ||
8379 | if ((tmp = strrchr (name, '.')) != NULL) | |
8380 | name = tmp + 1; | |
8381 | else | |
14f9c5c9 | 8382 | { |
4c4b4cd2 PH |
8383 | while ((tmp = strstr (name, "__")) != NULL) |
8384 | { | |
8385 | if (isdigit (tmp[2])) | |
8386 | break; | |
8387 | else | |
8388 | name = tmp + 2; | |
8389 | } | |
14f9c5c9 AS |
8390 | } |
8391 | ||
8392 | if (name[0] == 'Q') | |
8393 | { | |
14f9c5c9 AS |
8394 | int v; |
8395 | if (name[1] == 'U' || name[1] == 'W') | |
4c4b4cd2 PH |
8396 | { |
8397 | if (sscanf (name + 2, "%x", &v) != 1) | |
8398 | return name; | |
8399 | } | |
14f9c5c9 | 8400 | else |
4c4b4cd2 | 8401 | return name; |
14f9c5c9 | 8402 | |
4c4b4cd2 | 8403 | GROW_VECT (result, result_len, 16); |
14f9c5c9 | 8404 | if (isascii (v) && isprint (v)) |
4c4b4cd2 | 8405 | sprintf (result, "'%c'", v); |
14f9c5c9 | 8406 | else if (name[1] == 'U') |
4c4b4cd2 | 8407 | sprintf (result, "[\"%02x\"]", v); |
14f9c5c9 | 8408 | else |
4c4b4cd2 | 8409 | sprintf (result, "[\"%04x\"]", v); |
14f9c5c9 AS |
8410 | |
8411 | return result; | |
8412 | } | |
d2e4a39e | 8413 | else |
4c4b4cd2 PH |
8414 | { |
8415 | if ((tmp = strstr (name, "__")) != NULL | |
8416 | || (tmp = strstr (name, "$")) != NULL) | |
8417 | { | |
8418 | GROW_VECT (result, result_len, tmp - name + 1); | |
8419 | strncpy (result, name, tmp - name); | |
8420 | result[tmp - name] = '\0'; | |
8421 | return result; | |
8422 | } | |
8423 | ||
8424 | return name; | |
8425 | } | |
14f9c5c9 AS |
8426 | } |
8427 | ||
d2e4a39e | 8428 | static struct value * |
ebf56fd3 | 8429 | evaluate_subexp (struct type *expect_type, struct expression *exp, int *pos, |
4c4b4cd2 | 8430 | enum noside noside) |
14f9c5c9 | 8431 | { |
4c4b4cd2 PH |
8432 | return (*exp->language_defn->la_exp_desc->evaluate_exp) |
8433 | (expect_type, exp, pos, noside); | |
14f9c5c9 AS |
8434 | } |
8435 | ||
8436 | /* Evaluate the subexpression of EXP starting at *POS as for | |
8437 | evaluate_type, updating *POS to point just past the evaluated | |
4c4b4cd2 | 8438 | expression. */ |
14f9c5c9 | 8439 | |
d2e4a39e AS |
8440 | static struct value * |
8441 | evaluate_subexp_type (struct expression *exp, int *pos) | |
14f9c5c9 | 8442 | { |
4c4b4cd2 | 8443 | return (*exp->language_defn->la_exp_desc->evaluate_exp) |
14f9c5c9 AS |
8444 | (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS); |
8445 | } | |
8446 | ||
8447 | /* If VAL is wrapped in an aligner or subtype wrapper, return the | |
4c4b4cd2 | 8448 | value it wraps. */ |
14f9c5c9 | 8449 | |
d2e4a39e AS |
8450 | static struct value * |
8451 | unwrap_value (struct value *val) | |
14f9c5c9 | 8452 | { |
d2e4a39e | 8453 | struct type *type = check_typedef (VALUE_TYPE (val)); |
14f9c5c9 AS |
8454 | if (ada_is_aligner_type (type)) |
8455 | { | |
d2e4a39e | 8456 | struct value *v = value_struct_elt (&val, NULL, "F", |
4c4b4cd2 | 8457 | NULL, "internal structure"); |
d2e4a39e | 8458 | struct type *val_type = check_typedef (VALUE_TYPE (v)); |
14f9c5c9 | 8459 | if (ada_type_name (val_type) == NULL) |
4c4b4cd2 | 8460 | TYPE_NAME (val_type) = ada_type_name (type); |
14f9c5c9 AS |
8461 | |
8462 | return unwrap_value (v); | |
8463 | } | |
d2e4a39e | 8464 | else |
14f9c5c9 | 8465 | { |
d2e4a39e | 8466 | struct type *raw_real_type = |
4c4b4cd2 | 8467 | ada_completed_type (ada_get_base_type (type)); |
d2e4a39e | 8468 | |
14f9c5c9 | 8469 | if (type == raw_real_type) |
4c4b4cd2 | 8470 | return val; |
14f9c5c9 | 8471 | |
d2e4a39e | 8472 | return |
4c4b4cd2 PH |
8473 | coerce_unspec_val_to_type |
8474 | (val, ada_to_fixed_type (raw_real_type, 0, | |
8475 | VALUE_ADDRESS (val) + VALUE_OFFSET (val), | |
8476 | NULL)); | |
14f9c5c9 AS |
8477 | } |
8478 | } | |
d2e4a39e AS |
8479 | |
8480 | static struct value * | |
8481 | cast_to_fixed (struct type *type, struct value *arg) | |
14f9c5c9 AS |
8482 | { |
8483 | LONGEST val; | |
8484 | ||
8485 | if (type == VALUE_TYPE (arg)) | |
8486 | return arg; | |
8487 | else if (ada_is_fixed_point_type (VALUE_TYPE (arg))) | |
d2e4a39e | 8488 | val = ada_float_to_fixed (type, |
4c4b4cd2 PH |
8489 | ada_fixed_to_float (VALUE_TYPE (arg), |
8490 | value_as_long (arg))); | |
d2e4a39e | 8491 | else |
14f9c5c9 | 8492 | { |
d2e4a39e | 8493 | DOUBLEST argd = |
4c4b4cd2 | 8494 | value_as_double (value_cast (builtin_type_double, value_copy (arg))); |
14f9c5c9 AS |
8495 | val = ada_float_to_fixed (type, argd); |
8496 | } | |
8497 | ||
8498 | return value_from_longest (type, val); | |
8499 | } | |
8500 | ||
d2e4a39e AS |
8501 | static struct value * |
8502 | cast_from_fixed_to_double (struct value *arg) | |
14f9c5c9 AS |
8503 | { |
8504 | DOUBLEST val = ada_fixed_to_float (VALUE_TYPE (arg), | |
4c4b4cd2 | 8505 | value_as_long (arg)); |
14f9c5c9 AS |
8506 | return value_from_double (builtin_type_double, val); |
8507 | } | |
8508 | ||
4c4b4cd2 PH |
8509 | /* Coerce VAL as necessary for assignment to an lval of type TYPE, and |
8510 | return the converted value. */ | |
8511 | ||
d2e4a39e AS |
8512 | static struct value * |
8513 | coerce_for_assign (struct type *type, struct value *val) | |
14f9c5c9 | 8514 | { |
d2e4a39e | 8515 | struct type *type2 = VALUE_TYPE (val); |
14f9c5c9 AS |
8516 | if (type == type2) |
8517 | return val; | |
8518 | ||
8519 | CHECK_TYPEDEF (type2); | |
8520 | CHECK_TYPEDEF (type); | |
8521 | ||
d2e4a39e AS |
8522 | if (TYPE_CODE (type2) == TYPE_CODE_PTR |
8523 | && TYPE_CODE (type) == TYPE_CODE_ARRAY) | |
14f9c5c9 AS |
8524 | { |
8525 | val = ada_value_ind (val); | |
8526 | type2 = VALUE_TYPE (val); | |
8527 | } | |
8528 | ||
d2e4a39e | 8529 | if (TYPE_CODE (type2) == TYPE_CODE_ARRAY |
14f9c5c9 AS |
8530 | && TYPE_CODE (type) == TYPE_CODE_ARRAY) |
8531 | { | |
8532 | if (TYPE_LENGTH (type2) != TYPE_LENGTH (type) | |
4c4b4cd2 PH |
8533 | || TYPE_LENGTH (TYPE_TARGET_TYPE (type2)) |
8534 | != TYPE_LENGTH (TYPE_TARGET_TYPE (type2))) | |
8535 | error ("Incompatible types in assignment"); | |
14f9c5c9 AS |
8536 | VALUE_TYPE (val) = type; |
8537 | } | |
d2e4a39e | 8538 | return val; |
14f9c5c9 AS |
8539 | } |
8540 | ||
4c4b4cd2 PH |
8541 | static struct value * |
8542 | ada_value_binop (struct value *arg1, struct value *arg2, enum exp_opcode op) | |
8543 | { | |
8544 | struct value *val; | |
8545 | struct type *type1, *type2; | |
8546 | LONGEST v, v1, v2; | |
8547 | ||
8548 | COERCE_REF (arg1); | |
8549 | COERCE_REF (arg2); | |
8550 | type1 = base_type (check_typedef (VALUE_TYPE (arg1))); | |
8551 | type2 = base_type (check_typedef (VALUE_TYPE (arg2))); | |
8552 | ||
8553 | if (TYPE_CODE (type1) != TYPE_CODE_INT || TYPE_CODE (type2) != TYPE_CODE_INT) | |
8554 | return value_binop (arg1, arg2, op); | |
8555 | ||
8556 | switch (op) | |
8557 | { | |
8558 | case BINOP_MOD: | |
8559 | case BINOP_DIV: | |
8560 | case BINOP_REM: | |
8561 | break; | |
8562 | default: | |
8563 | return value_binop (arg1, arg2, op); | |
8564 | } | |
8565 | ||
8566 | v2 = value_as_long (arg2); | |
8567 | if (v2 == 0) | |
8568 | error ("second operand of %s must not be zero.", op_string (op)); | |
8569 | ||
8570 | if (TYPE_UNSIGNED (type1) || op == BINOP_MOD) | |
8571 | return value_binop (arg1, arg2, op); | |
8572 | ||
8573 | v1 = value_as_long (arg1); | |
8574 | switch (op) | |
8575 | { | |
8576 | case BINOP_DIV: | |
8577 | v = v1 / v2; | |
8578 | if (! TRUNCATION_TOWARDS_ZERO && v1 * (v1%v2) < 0) | |
8579 | v += v > 0 ? -1 : 1; | |
8580 | break; | |
8581 | case BINOP_REM: | |
8582 | v = v1 % v2; | |
8583 | if (v*v1 < 0) | |
8584 | v -= v2; | |
8585 | break; | |
8586 | default: | |
8587 | /* Should not reach this point. */ | |
8588 | v = 0; | |
8589 | } | |
8590 | ||
8591 | val = allocate_value (type1); | |
8592 | store_unsigned_integer (VALUE_CONTENTS_RAW (val), | |
8593 | TYPE_LENGTH (VALUE_TYPE (val)), | |
8594 | v); | |
8595 | return val; | |
8596 | } | |
8597 | ||
8598 | static int | |
8599 | ada_value_equal (struct value *arg1, struct value *arg2) | |
8600 | { | |
8601 | if (ada_is_direct_array_type (VALUE_TYPE (arg1)) | |
8602 | || ada_is_direct_array_type (VALUE_TYPE (arg2))) | |
8603 | { | |
8604 | arg1 = ada_coerce_to_simple_array (arg1); | |
8605 | arg2 = ada_coerce_to_simple_array (arg2); | |
8606 | if (TYPE_CODE (VALUE_TYPE (arg1)) != TYPE_CODE_ARRAY | |
8607 | || TYPE_CODE (VALUE_TYPE (arg2)) != TYPE_CODE_ARRAY) | |
8608 | error ("Attempt to compare array with non-array"); | |
8609 | /* FIXME: The following works only for types whose | |
8610 | representations use all bits (no padding or undefined bits) | |
8611 | and do not have user-defined equality. */ | |
8612 | return | |
8613 | TYPE_LENGTH (VALUE_TYPE (arg1)) == TYPE_LENGTH (VALUE_TYPE (arg2)) | |
8614 | && memcmp (VALUE_CONTENTS (arg1), VALUE_CONTENTS (arg2), | |
8615 | TYPE_LENGTH (VALUE_TYPE (arg1))) == 0; | |
8616 | } | |
8617 | return value_equal (arg1, arg2); | |
8618 | } | |
8619 | ||
d2e4a39e | 8620 | struct value * |
ebf56fd3 | 8621 | ada_evaluate_subexp (struct type *expect_type, struct expression *exp, |
4c4b4cd2 | 8622 | int *pos, enum noside noside) |
14f9c5c9 AS |
8623 | { |
8624 | enum exp_opcode op; | |
14f9c5c9 AS |
8625 | int tem, tem2, tem3; |
8626 | int pc; | |
8627 | struct value *arg1 = NULL, *arg2 = NULL, *arg3; | |
8628 | struct type *type; | |
8629 | int nargs; | |
d2e4a39e | 8630 | struct value **argvec; |
14f9c5c9 | 8631 | |
d2e4a39e AS |
8632 | pc = *pos; |
8633 | *pos += 1; | |
14f9c5c9 AS |
8634 | op = exp->elts[pc].opcode; |
8635 | ||
d2e4a39e | 8636 | switch (op) |
14f9c5c9 AS |
8637 | { |
8638 | default: | |
8639 | *pos -= 1; | |
d2e4a39e | 8640 | return |
4c4b4cd2 PH |
8641 | unwrap_value (evaluate_subexp_standard |
8642 | (expect_type, exp, pos, noside)); | |
8643 | ||
8644 | case OP_STRING: | |
8645 | { | |
8646 | struct value *result; | |
8647 | *pos -= 1; | |
8648 | result = evaluate_subexp_standard (expect_type, exp, pos, noside); | |
8649 | /* The result type will have code OP_STRING, bashed there from | |
8650 | OP_ARRAY. Bash it back. */ | |
8651 | if (TYPE_CODE (VALUE_TYPE (result)) == TYPE_CODE_STRING) | |
8652 | TYPE_CODE (VALUE_TYPE (result)) = TYPE_CODE_ARRAY; | |
8653 | return result; | |
8654 | } | |
14f9c5c9 AS |
8655 | |
8656 | case UNOP_CAST: | |
8657 | (*pos) += 2; | |
8658 | type = exp->elts[pc + 1].type; | |
8659 | arg1 = evaluate_subexp (type, exp, pos, noside); | |
8660 | if (noside == EVAL_SKIP) | |
4c4b4cd2 | 8661 | goto nosideret; |
14f9c5c9 | 8662 | if (type != check_typedef (VALUE_TYPE (arg1))) |
4c4b4cd2 PH |
8663 | { |
8664 | if (ada_is_fixed_point_type (type)) | |
8665 | arg1 = cast_to_fixed (type, arg1); | |
8666 | else if (ada_is_fixed_point_type (VALUE_TYPE (arg1))) | |
8667 | arg1 = value_cast (type, cast_from_fixed_to_double (arg1)); | |
8668 | else if (VALUE_LVAL (arg1) == lval_memory) | |
8669 | { | |
8670 | /* This is in case of the really obscure (and undocumented, | |
8671 | but apparently expected) case of (Foo) Bar.all, where Bar | |
8672 | is an integer constant and Foo is a dynamic-sized type. | |
8673 | If we don't do this, ARG1 will simply be relabeled with | |
8674 | TYPE. */ | |
8675 | if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
8676 | return value_zero (to_static_fixed_type (type), not_lval); | |
8677 | arg1 = | |
8678 | ada_to_fixed_value_create | |
8679 | (type, VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1), 0); | |
8680 | } | |
8681 | else | |
8682 | arg1 = value_cast (type, arg1); | |
8683 | } | |
14f9c5c9 AS |
8684 | return arg1; |
8685 | ||
4c4b4cd2 PH |
8686 | case UNOP_QUAL: |
8687 | (*pos) += 2; | |
8688 | type = exp->elts[pc + 1].type; | |
8689 | return ada_evaluate_subexp (type, exp, pos, noside); | |
8690 | ||
14f9c5c9 AS |
8691 | case BINOP_ASSIGN: |
8692 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
8693 | arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside); | |
8694 | if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS) | |
4c4b4cd2 PH |
8695 | return arg1; |
8696 | if (ada_is_fixed_point_type (VALUE_TYPE (arg1))) | |
8697 | arg2 = cast_to_fixed (VALUE_TYPE (arg1), arg2); | |
8698 | else if (ada_is_fixed_point_type (VALUE_TYPE (arg2))) | |
8699 | error | |
8700 | ("Fixed-point values must be assigned to fixed-point variables"); | |
d2e4a39e | 8701 | else |
4c4b4cd2 PH |
8702 | arg2 = coerce_for_assign (VALUE_TYPE (arg1), arg2); |
8703 | return ada_value_assign (arg1, arg2); | |
14f9c5c9 AS |
8704 | |
8705 | case BINOP_ADD: | |
8706 | arg1 = evaluate_subexp_with_coercion (exp, pos, noside); | |
8707 | arg2 = evaluate_subexp_with_coercion (exp, pos, noside); | |
8708 | if (noside == EVAL_SKIP) | |
4c4b4cd2 PH |
8709 | goto nosideret; |
8710 | if ((ada_is_fixed_point_type (VALUE_TYPE (arg1)) | |
8711 | || ada_is_fixed_point_type (VALUE_TYPE (arg2))) | |
8712 | && VALUE_TYPE (arg1) != VALUE_TYPE (arg2)) | |
8713 | error | |
8714 | ("Operands of fixed-point addition must have the same type"); | |
8715 | return value_cast (VALUE_TYPE (arg1), value_add (arg1, arg2)); | |
14f9c5c9 AS |
8716 | |
8717 | case BINOP_SUB: | |
8718 | arg1 = evaluate_subexp_with_coercion (exp, pos, noside); | |
8719 | arg2 = evaluate_subexp_with_coercion (exp, pos, noside); | |
8720 | if (noside == EVAL_SKIP) | |
4c4b4cd2 PH |
8721 | goto nosideret; |
8722 | if ((ada_is_fixed_point_type (VALUE_TYPE (arg1)) | |
8723 | || ada_is_fixed_point_type (VALUE_TYPE (arg2))) | |
8724 | && VALUE_TYPE (arg1) != VALUE_TYPE (arg2)) | |
8725 | error | |
8726 | ("Operands of fixed-point subtraction must have the same type"); | |
8727 | return value_cast (VALUE_TYPE (arg1), value_sub (arg1, arg2)); | |
14f9c5c9 AS |
8728 | |
8729 | case BINOP_MUL: | |
8730 | case BINOP_DIV: | |
8731 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
8732 | arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
8733 | if (noside == EVAL_SKIP) | |
4c4b4cd2 PH |
8734 | goto nosideret; |
8735 | else if (noside == EVAL_AVOID_SIDE_EFFECTS | |
8736 | && (op == BINOP_DIV || op == BINOP_REM || op == BINOP_MOD)) | |
8737 | return value_zero (VALUE_TYPE (arg1), not_lval); | |
14f9c5c9 | 8738 | else |
4c4b4cd2 PH |
8739 | { |
8740 | if (ada_is_fixed_point_type (VALUE_TYPE (arg1))) | |
8741 | arg1 = cast_from_fixed_to_double (arg1); | |
8742 | if (ada_is_fixed_point_type (VALUE_TYPE (arg2))) | |
8743 | arg2 = cast_from_fixed_to_double (arg2); | |
8744 | return ada_value_binop (arg1, arg2, op); | |
8745 | } | |
8746 | ||
8747 | case BINOP_REM: | |
8748 | case BINOP_MOD: | |
8749 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
8750 | arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
8751 | if (noside == EVAL_SKIP) | |
8752 | goto nosideret; | |
8753 | else if (noside == EVAL_AVOID_SIDE_EFFECTS | |
8754 | && (op == BINOP_DIV || op == BINOP_REM || op == BINOP_MOD)) | |
d2e4a39e | 8755 | return value_zero (VALUE_TYPE (arg1), not_lval); |
14f9c5c9 | 8756 | else |
4c4b4cd2 | 8757 | return ada_value_binop (arg1, arg2, op); |
14f9c5c9 | 8758 | |
4c4b4cd2 PH |
8759 | case BINOP_EQUAL: |
8760 | case BINOP_NOTEQUAL: | |
14f9c5c9 | 8761 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); |
4c4b4cd2 | 8762 | arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside); |
14f9c5c9 AS |
8763 | if (noside == EVAL_SKIP) |
8764 | goto nosideret; | |
4c4b4cd2 PH |
8765 | if (noside == EVAL_AVOID_SIDE_EFFECTS) |
8766 | tem = 0; | |
8767 | else | |
8768 | tem = ada_value_equal (arg1, arg2); | |
8769 | if (op == BINOP_NOTEQUAL) | |
8770 | tem = ! tem; | |
8771 | return value_from_longest (LA_BOOL_TYPE, (LONGEST) tem); | |
8772 | ||
8773 | case UNOP_NEG: | |
8774 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
8775 | if (noside == EVAL_SKIP) | |
8776 | goto nosideret; | |
14f9c5c9 | 8777 | else if (ada_is_fixed_point_type (VALUE_TYPE (arg1))) |
4c4b4cd2 | 8778 | return value_cast (VALUE_TYPE (arg1), value_neg (arg1)); |
14f9c5c9 | 8779 | else |
4c4b4cd2 PH |
8780 | return value_neg (arg1); |
8781 | ||
14f9c5c9 AS |
8782 | case OP_VAR_VALUE: |
8783 | *pos -= 1; | |
8784 | if (noside == EVAL_SKIP) | |
4c4b4cd2 PH |
8785 | { |
8786 | *pos += 4; | |
8787 | goto nosideret; | |
8788 | } | |
8789 | else if (SYMBOL_DOMAIN (exp->elts[pc + 2].symbol) == UNDEF_DOMAIN) | |
8790 | /* Only encountered when an unresolved symbol occurs in a | |
8791 | context other than a function call, in which case, it is | |
8792 | illegal. */ | |
8793 | error ("Unexpected unresolved symbol, %s, during evaluation", | |
8794 | SYMBOL_PRINT_NAME (exp->elts[pc + 2].symbol)); | |
14f9c5c9 | 8795 | else if (noside == EVAL_AVOID_SIDE_EFFECTS) |
4c4b4cd2 PH |
8796 | { |
8797 | *pos += 4; | |
8798 | return value_zero | |
8799 | (to_static_fixed_type | |
8800 | (static_unwrap_type (SYMBOL_TYPE (exp->elts[pc + 2].symbol))), | |
8801 | not_lval); | |
8802 | } | |
d2e4a39e | 8803 | else |
4c4b4cd2 PH |
8804 | { |
8805 | arg1 = | |
8806 | unwrap_value (evaluate_subexp_standard | |
8807 | (expect_type, exp, pos, noside)); | |
8808 | return ada_to_fixed_value (arg1); | |
8809 | } | |
8810 | ||
8811 | case OP_FUNCALL: | |
8812 | (*pos) += 2; | |
8813 | ||
8814 | /* Allocate arg vector, including space for the function to be | |
8815 | called in argvec[0] and a terminating NULL. */ | |
8816 | nargs = longest_to_int (exp->elts[pc + 1].longconst); | |
8817 | argvec = | |
8818 | (struct value **) alloca (sizeof (struct value *) * (nargs + 2)); | |
8819 | ||
8820 | if (exp->elts[*pos].opcode == OP_VAR_VALUE | |
8821 | && SYMBOL_DOMAIN (exp->elts[pc + 5].symbol) == UNDEF_DOMAIN) | |
8822 | error ("Unexpected unresolved symbol, %s, during evaluation", | |
8823 | SYMBOL_PRINT_NAME (exp->elts[pc + 5].symbol)); | |
8824 | else | |
8825 | { | |
8826 | for (tem = 0; tem <= nargs; tem += 1) | |
8827 | argvec[tem] = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
8828 | argvec[tem] = 0; | |
8829 | ||
8830 | if (noside == EVAL_SKIP) | |
8831 | goto nosideret; | |
8832 | } | |
8833 | ||
8834 | if (ada_is_packed_array_type (desc_base_type (VALUE_TYPE (argvec[0])))) | |
8835 | argvec[0] = ada_coerce_to_simple_array (argvec[0]); | |
8836 | else if (TYPE_CODE (VALUE_TYPE (argvec[0])) == TYPE_CODE_REF | |
8837 | || (TYPE_CODE (VALUE_TYPE (argvec[0])) == TYPE_CODE_ARRAY | |
8838 | && VALUE_LVAL (argvec[0]) == lval_memory)) | |
8839 | argvec[0] = value_addr (argvec[0]); | |
8840 | ||
8841 | type = check_typedef (VALUE_TYPE (argvec[0])); | |
8842 | if (TYPE_CODE (type) == TYPE_CODE_PTR) | |
8843 | { | |
8844 | switch (TYPE_CODE (check_typedef (TYPE_TARGET_TYPE (type)))) | |
8845 | { | |
8846 | case TYPE_CODE_FUNC: | |
8847 | type = check_typedef (TYPE_TARGET_TYPE (type)); | |
8848 | break; | |
8849 | case TYPE_CODE_ARRAY: | |
8850 | break; | |
8851 | case TYPE_CODE_STRUCT: | |
8852 | if (noside != EVAL_AVOID_SIDE_EFFECTS) | |
8853 | argvec[0] = ada_value_ind (argvec[0]); | |
8854 | type = check_typedef (TYPE_TARGET_TYPE (type)); | |
8855 | break; | |
8856 | default: | |
8857 | error ("cannot subscript or call something of type `%s'", | |
8858 | ada_type_name (VALUE_TYPE (argvec[0]))); | |
8859 | break; | |
8860 | } | |
8861 | } | |
8862 | ||
8863 | switch (TYPE_CODE (type)) | |
8864 | { | |
8865 | case TYPE_CODE_FUNC: | |
8866 | if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
8867 | return allocate_value (TYPE_TARGET_TYPE (type)); | |
8868 | return call_function_by_hand (argvec[0], nargs, argvec + 1); | |
8869 | case TYPE_CODE_STRUCT: | |
8870 | { | |
8871 | int arity; | |
8872 | ||
8873 | /* Make sure to use the parallel ___XVS type if any. | |
8874 | Otherwise, we won't be able to find the array arity | |
8875 | and element type. */ | |
8876 | type = ada_get_base_type (type); | |
8877 | ||
8878 | arity = ada_array_arity (type); | |
8879 | type = ada_array_element_type (type, nargs); | |
8880 | if (type == NULL) | |
8881 | error ("cannot subscript or call a record"); | |
8882 | if (arity != nargs) | |
8883 | error ("wrong number of subscripts; expecting %d", arity); | |
8884 | if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
8885 | return allocate_value (ada_aligned_type (type)); | |
8886 | return | |
8887 | unwrap_value (ada_value_subscript | |
8888 | (argvec[0], nargs, argvec + 1)); | |
8889 | } | |
8890 | case TYPE_CODE_ARRAY: | |
8891 | if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
8892 | { | |
8893 | type = ada_array_element_type (type, nargs); | |
8894 | if (type == NULL) | |
8895 | error ("element type of array unknown"); | |
8896 | else | |
8897 | return allocate_value (ada_aligned_type (type)); | |
8898 | } | |
8899 | return | |
8900 | unwrap_value (ada_value_subscript | |
8901 | (ada_coerce_to_simple_array (argvec[0]), | |
8902 | nargs, argvec + 1)); | |
8903 | case TYPE_CODE_PTR: /* Pointer to array */ | |
8904 | type = to_fixed_array_type (TYPE_TARGET_TYPE (type), NULL, 1); | |
8905 | if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
8906 | { | |
8907 | type = ada_array_element_type (type, nargs); | |
8908 | if (type == NULL) | |
8909 | error ("element type of array unknown"); | |
8910 | else | |
8911 | return allocate_value (ada_aligned_type (type)); | |
8912 | } | |
8913 | return | |
8914 | unwrap_value (ada_value_ptr_subscript (argvec[0], type, | |
8915 | nargs, argvec + 1)); | |
8916 | ||
8917 | default: | |
8918 | error ("Internal error in evaluate_subexp"); | |
8919 | } | |
8920 | ||
8921 | case TERNOP_SLICE: | |
8922 | { | |
8923 | struct value *array = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
8924 | struct value *low_bound_val = | |
8925 | evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
8926 | LONGEST low_bound = pos_atr (low_bound_val); | |
8927 | LONGEST high_bound | |
8928 | = pos_atr (evaluate_subexp (NULL_TYPE, exp, pos, noside)); | |
8929 | if (noside == EVAL_SKIP) | |
8930 | goto nosideret; | |
8931 | ||
8932 | /* If this is a reference type or a pointer type, and | |
8933 | the target type has an XVS parallel type, then get | |
8934 | the real target type. */ | |
8935 | if (TYPE_CODE (VALUE_TYPE (array)) == TYPE_CODE_REF | |
8936 | || TYPE_CODE (VALUE_TYPE (array)) == TYPE_CODE_PTR) | |
8937 | TYPE_TARGET_TYPE (VALUE_TYPE (array)) = | |
8938 | ada_get_base_type (TYPE_TARGET_TYPE (VALUE_TYPE (array))); | |
8939 | ||
8940 | /* If this is a reference to an aligner type, then remove all | |
8941 | the aligners. */ | |
8942 | if (TYPE_CODE (VALUE_TYPE (array)) == TYPE_CODE_REF | |
8943 | && ada_is_aligner_type (TYPE_TARGET_TYPE (VALUE_TYPE (array)))) | |
8944 | TYPE_TARGET_TYPE (VALUE_TYPE (array)) = | |
8945 | ada_aligned_type (TYPE_TARGET_TYPE (VALUE_TYPE (array))); | |
8946 | ||
8947 | if (ada_is_packed_array_type (VALUE_TYPE (array))) | |
8948 | error ("cannot slice a packed array"); | |
8949 | ||
8950 | /* If this is a reference to an array or an array lvalue, | |
8951 | convert to a pointer. */ | |
8952 | if (TYPE_CODE (VALUE_TYPE (array)) == TYPE_CODE_REF | |
8953 | || (TYPE_CODE (VALUE_TYPE (array)) == TYPE_CODE_ARRAY | |
8954 | && VALUE_LVAL (array) == lval_memory)) | |
8955 | array = value_addr (array); | |
8956 | ||
8957 | if (noside == EVAL_AVOID_SIDE_EFFECTS && | |
8958 | ada_is_array_descriptor_type (check_typedef (VALUE_TYPE (array)))) | |
8959 | { | |
8960 | /* Try dereferencing the array, in case it is an access | |
8961 | to array. */ | |
8962 | struct type *arrType = ada_type_of_array (array, 0); | |
8963 | if (arrType != NULL) | |
8964 | array = value_at_lazy (arrType, 0, NULL); | |
8965 | } | |
8966 | ||
8967 | array = ada_coerce_to_simple_array_ptr (array); | |
8968 | ||
8969 | /* When EVAL_AVOID_SIDE_EFFECTS, we may get the bounds wrong, | |
8970 | but only in contexts where the value is not being requested | |
8971 | (FIXME?). */ | |
8972 | if (TYPE_CODE (VALUE_TYPE (array)) == TYPE_CODE_PTR) | |
8973 | { | |
8974 | if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
8975 | return ada_value_ind (array); | |
8976 | else if (high_bound < low_bound) | |
8977 | return empty_array (TYPE_TARGET_TYPE (VALUE_TYPE (array)), | |
8978 | low_bound); | |
8979 | else | |
8980 | { | |
8981 | struct type *arr_type0 = | |
8982 | to_fixed_array_type (TYPE_TARGET_TYPE (VALUE_TYPE (array)), | |
8983 | NULL, 1); | |
8984 | struct value *item0 = | |
8985 | ada_value_ptr_subscript (array, arr_type0, 1, | |
8986 | &low_bound_val); | |
8987 | struct value *slice = | |
8988 | value_repeat (item0, high_bound - low_bound + 1); | |
8989 | struct type *arr_type1 = VALUE_TYPE (slice); | |
8990 | TYPE_LOW_BOUND (TYPE_INDEX_TYPE (arr_type1)) = low_bound; | |
8991 | TYPE_HIGH_BOUND (TYPE_INDEX_TYPE (arr_type1)) += low_bound; | |
8992 | return slice; | |
8993 | } | |
8994 | } | |
8995 | else if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
8996 | return array; | |
8997 | else if (high_bound < low_bound) | |
8998 | return empty_array (VALUE_TYPE (array), low_bound); | |
8999 | else | |
9000 | return value_slice (array, low_bound, high_bound - low_bound + 1); | |
9001 | } | |
14f9c5c9 | 9002 | |
4c4b4cd2 PH |
9003 | case UNOP_IN_RANGE: |
9004 | (*pos) += 2; | |
9005 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
9006 | type = exp->elts[pc + 1].type; | |
14f9c5c9 | 9007 | |
14f9c5c9 | 9008 | if (noside == EVAL_SKIP) |
4c4b4cd2 | 9009 | goto nosideret; |
14f9c5c9 | 9010 | |
4c4b4cd2 PH |
9011 | switch (TYPE_CODE (type)) |
9012 | { | |
9013 | default: | |
9014 | lim_warning ("Membership test incompletely implemented; " | |
9015 | "always returns true", 0); | |
9016 | return value_from_longest (builtin_type_int, (LONGEST) 1); | |
9017 | ||
9018 | case TYPE_CODE_RANGE: | |
9019 | arg2 = value_from_longest (builtin_type_int, | |
9020 | TYPE_LOW_BOUND (type)); | |
9021 | arg3 = value_from_longest (builtin_type_int, | |
9022 | TYPE_HIGH_BOUND (type)); | |
9023 | return | |
9024 | value_from_longest (builtin_type_int, | |
9025 | (value_less (arg1, arg3) | |
9026 | || value_equal (arg1, arg3)) | |
9027 | && (value_less (arg2, arg1) | |
9028 | || value_equal (arg2, arg1))); | |
9029 | } | |
9030 | ||
9031 | case BINOP_IN_BOUNDS: | |
14f9c5c9 | 9032 | (*pos) += 2; |
4c4b4cd2 PH |
9033 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); |
9034 | arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
14f9c5c9 | 9035 | |
4c4b4cd2 PH |
9036 | if (noside == EVAL_SKIP) |
9037 | goto nosideret; | |
14f9c5c9 | 9038 | |
4c4b4cd2 PH |
9039 | if (noside == EVAL_AVOID_SIDE_EFFECTS) |
9040 | return value_zero (builtin_type_int, not_lval); | |
14f9c5c9 | 9041 | |
4c4b4cd2 | 9042 | tem = longest_to_int (exp->elts[pc + 1].longconst); |
14f9c5c9 | 9043 | |
4c4b4cd2 PH |
9044 | if (tem < 1 || tem > ada_array_arity (VALUE_TYPE (arg2))) |
9045 | error ("invalid dimension number to '%s", "range"); | |
14f9c5c9 | 9046 | |
4c4b4cd2 PH |
9047 | arg3 = ada_array_bound (arg2, tem, 1); |
9048 | arg2 = ada_array_bound (arg2, tem, 0); | |
d2e4a39e | 9049 | |
4c4b4cd2 PH |
9050 | return |
9051 | value_from_longest (builtin_type_int, | |
9052 | (value_less (arg1, arg3) | |
9053 | || value_equal (arg1, arg3)) | |
9054 | && (value_less (arg2, arg1) | |
9055 | || value_equal (arg2, arg1))); | |
9056 | ||
9057 | case TERNOP_IN_RANGE: | |
9058 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
9059 | arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
9060 | arg3 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
9061 | ||
9062 | if (noside == EVAL_SKIP) | |
9063 | goto nosideret; | |
9064 | ||
9065 | return | |
9066 | value_from_longest (builtin_type_int, | |
9067 | (value_less (arg1, arg3) | |
9068 | || value_equal (arg1, arg3)) | |
9069 | && (value_less (arg2, arg1) | |
9070 | || value_equal (arg2, arg1))); | |
9071 | ||
9072 | case OP_ATR_FIRST: | |
9073 | case OP_ATR_LAST: | |
9074 | case OP_ATR_LENGTH: | |
9075 | { | |
9076 | struct type *type_arg; | |
9077 | if (exp->elts[*pos].opcode == OP_TYPE) | |
14f9c5c9 | 9078 | { |
4c4b4cd2 PH |
9079 | evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP); |
9080 | arg1 = NULL; | |
9081 | type_arg = exp->elts[pc + 2].type; | |
9082 | } | |
9083 | else | |
9084 | { | |
9085 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
9086 | type_arg = NULL; | |
14f9c5c9 | 9087 | } |
14f9c5c9 | 9088 | |
4c4b4cd2 PH |
9089 | if (exp->elts[*pos].opcode != OP_LONG) |
9090 | error ("illegal operand to '%s", ada_attribute_name (op)); | |
9091 | tem = longest_to_int (exp->elts[*pos + 2].longconst); | |
9092 | *pos += 4; | |
14f9c5c9 | 9093 | |
14f9c5c9 AS |
9094 | if (noside == EVAL_SKIP) |
9095 | goto nosideret; | |
d2e4a39e | 9096 | |
4c4b4cd2 | 9097 | if (type_arg == NULL) |
d2e4a39e | 9098 | { |
4c4b4cd2 | 9099 | arg1 = ada_coerce_ref (arg1); |
14f9c5c9 | 9100 | |
4c4b4cd2 PH |
9101 | if (ada_is_packed_array_type (VALUE_TYPE (arg1))) |
9102 | arg1 = ada_coerce_to_simple_array (arg1); | |
9103 | ||
9104 | if (tem < 1 || tem > ada_array_arity (VALUE_TYPE (arg1))) | |
9105 | error ("invalid dimension number to '%s", | |
9106 | ada_attribute_name (op)); | |
9107 | ||
9108 | if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
9109 | { | |
9110 | type = ada_index_type (VALUE_TYPE (arg1), tem); | |
9111 | if (type == NULL) | |
9112 | error | |
9113 | ("attempt to take bound of something that is not an array"); | |
9114 | return allocate_value (type); | |
9115 | } | |
9116 | ||
9117 | switch (op) | |
9118 | { | |
9119 | default: /* Should never happen. */ | |
9120 | error ("unexpected attribute encountered"); | |
9121 | case OP_ATR_FIRST: | |
9122 | return ada_array_bound (arg1, tem, 0); | |
9123 | case OP_ATR_LAST: | |
9124 | return ada_array_bound (arg1, tem, 1); | |
9125 | case OP_ATR_LENGTH: | |
9126 | return ada_array_length (arg1, tem); | |
9127 | } | |
14f9c5c9 | 9128 | } |
4c4b4cd2 | 9129 | else if (discrete_type_p (type_arg)) |
d2e4a39e | 9130 | { |
4c4b4cd2 PH |
9131 | struct type *range_type; |
9132 | char *name = ada_type_name (type_arg); | |
9133 | range_type = NULL; | |
9134 | if (name != NULL && TYPE_CODE (type_arg) != TYPE_CODE_ENUM) | |
9135 | range_type = | |
9136 | to_fixed_range_type (name, NULL, TYPE_OBJFILE (type_arg)); | |
9137 | if (range_type == NULL) | |
9138 | range_type = type_arg; | |
9139 | switch (op) | |
9140 | { | |
9141 | default: | |
9142 | error ("unexpected attribute encountered"); | |
9143 | case OP_ATR_FIRST: | |
9144 | return discrete_type_low_bound (range_type); | |
9145 | case OP_ATR_LAST: | |
9146 | return discrete_type_high_bound (range_type); | |
9147 | case OP_ATR_LENGTH: | |
9148 | error ("the 'length attribute applies only to array types"); | |
9149 | } | |
d2e4a39e | 9150 | } |
4c4b4cd2 PH |
9151 | else if (TYPE_CODE (type_arg) == TYPE_CODE_FLT) |
9152 | error ("unimplemented type attribute"); | |
14f9c5c9 | 9153 | else |
4c4b4cd2 PH |
9154 | { |
9155 | LONGEST low, high; | |
9156 | ||
9157 | if (ada_is_packed_array_type (type_arg)) | |
9158 | type_arg = decode_packed_array_type (type_arg); | |
9159 | ||
9160 | if (tem < 1 || tem > ada_array_arity (type_arg)) | |
9161 | error ("invalid dimension number to '%s", | |
9162 | ada_attribute_name (op)); | |
9163 | ||
9164 | type = ada_index_type (type_arg, tem); | |
9165 | if (type == NULL) | |
9166 | error ("attempt to take bound of something that is not an array"); | |
9167 | if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
9168 | return allocate_value (type); | |
9169 | ||
9170 | switch (op) | |
9171 | { | |
9172 | default: | |
9173 | error ("unexpected attribute encountered"); | |
9174 | case OP_ATR_FIRST: | |
9175 | low = ada_array_bound_from_type (type_arg, tem, 0, &type); | |
9176 | return value_from_longest (type, low); | |
9177 | case OP_ATR_LAST: | |
9178 | high = | |
9179 | ada_array_bound_from_type (type_arg, tem, 1, &type); | |
9180 | return value_from_longest (type, high); | |
9181 | case OP_ATR_LENGTH: | |
9182 | low = ada_array_bound_from_type (type_arg, tem, 0, &type); | |
9183 | high = ada_array_bound_from_type (type_arg, tem, 1, NULL); | |
9184 | return value_from_longest (type, high - low + 1); | |
9185 | } | |
9186 | } | |
14f9c5c9 AS |
9187 | } |
9188 | ||
4c4b4cd2 PH |
9189 | case OP_ATR_TAG: |
9190 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
9191 | if (noside == EVAL_SKIP) | |
9192 | goto nosideret; | |
9193 | ||
9194 | if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
9195 | return value_zero (ada_tag_type (arg1), not_lval); | |
9196 | ||
9197 | return ada_value_tag (arg1); | |
9198 | ||
9199 | case OP_ATR_MIN: | |
9200 | case OP_ATR_MAX: | |
9201 | evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP); | |
14f9c5c9 AS |
9202 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); |
9203 | arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
9204 | if (noside == EVAL_SKIP) | |
9205 | goto nosideret; | |
d2e4a39e AS |
9206 | else if (noside == EVAL_AVOID_SIDE_EFFECTS) |
9207 | return value_zero (VALUE_TYPE (arg1), not_lval); | |
14f9c5c9 | 9208 | else |
4c4b4cd2 PH |
9209 | return value_binop (arg1, arg2, |
9210 | op == OP_ATR_MIN ? BINOP_MIN : BINOP_MAX); | |
14f9c5c9 | 9211 | |
4c4b4cd2 PH |
9212 | case OP_ATR_MODULUS: |
9213 | { | |
9214 | struct type *type_arg = exp->elts[pc + 2].type; | |
9215 | evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP); | |
9216 | ||
9217 | if (noside == EVAL_SKIP) | |
9218 | goto nosideret; | |
9219 | ||
9220 | if (!ada_is_modular_type (type_arg)) | |
9221 | error ("'modulus must be applied to modular type"); | |
9222 | ||
9223 | return value_from_longest (TYPE_TARGET_TYPE (type_arg), | |
9224 | ada_modulus (type_arg)); | |
9225 | } | |
9226 | ||
9227 | ||
9228 | case OP_ATR_POS: | |
9229 | evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP); | |
14f9c5c9 AS |
9230 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); |
9231 | if (noside == EVAL_SKIP) | |
9232 | goto nosideret; | |
4c4b4cd2 PH |
9233 | else if (noside == EVAL_AVOID_SIDE_EFFECTS) |
9234 | return value_zero (builtin_type_ada_int, not_lval); | |
14f9c5c9 | 9235 | else |
4c4b4cd2 | 9236 | return value_pos_atr (arg1); |
14f9c5c9 | 9237 | |
4c4b4cd2 PH |
9238 | case OP_ATR_SIZE: |
9239 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
9240 | if (noside == EVAL_SKIP) | |
9241 | goto nosideret; | |
9242 | else if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
9243 | return value_zero (builtin_type_ada_int, not_lval); | |
9244 | else | |
9245 | return value_from_longest (builtin_type_ada_int, | |
9246 | TARGET_CHAR_BIT | |
9247 | * TYPE_LENGTH (VALUE_TYPE (arg1))); | |
9248 | ||
9249 | case OP_ATR_VAL: | |
9250 | evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP); | |
14f9c5c9 | 9251 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); |
4c4b4cd2 | 9252 | type = exp->elts[pc + 2].type; |
14f9c5c9 AS |
9253 | if (noside == EVAL_SKIP) |
9254 | goto nosideret; | |
4c4b4cd2 PH |
9255 | else if (noside == EVAL_AVOID_SIDE_EFFECTS) |
9256 | return value_zero (type, not_lval); | |
9257 | else | |
9258 | return value_val_atr (type, arg1); | |
9259 | ||
9260 | case BINOP_EXP: | |
9261 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
9262 | arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
9263 | if (noside == EVAL_SKIP) | |
9264 | goto nosideret; | |
9265 | else if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
9266 | return value_zero (VALUE_TYPE (arg1), not_lval); | |
9267 | else | |
9268 | return value_binop (arg1, arg2, op); | |
9269 | ||
9270 | case UNOP_PLUS: | |
9271 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
9272 | if (noside == EVAL_SKIP) | |
9273 | goto nosideret; | |
9274 | else | |
9275 | return arg1; | |
9276 | ||
9277 | case UNOP_ABS: | |
9278 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
9279 | if (noside == EVAL_SKIP) | |
9280 | goto nosideret; | |
14f9c5c9 | 9281 | if (value_less (arg1, value_zero (VALUE_TYPE (arg1), not_lval))) |
4c4b4cd2 | 9282 | return value_neg (arg1); |
14f9c5c9 | 9283 | else |
4c4b4cd2 | 9284 | return arg1; |
14f9c5c9 AS |
9285 | |
9286 | case UNOP_IND: | |
9287 | if (expect_type && TYPE_CODE (expect_type) == TYPE_CODE_PTR) | |
4c4b4cd2 | 9288 | expect_type = TYPE_TARGET_TYPE (check_typedef (expect_type)); |
14f9c5c9 AS |
9289 | arg1 = evaluate_subexp (expect_type, exp, pos, noside); |
9290 | if (noside == EVAL_SKIP) | |
4c4b4cd2 | 9291 | goto nosideret; |
14f9c5c9 AS |
9292 | type = check_typedef (VALUE_TYPE (arg1)); |
9293 | if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
4c4b4cd2 PH |
9294 | { |
9295 | if (ada_is_array_descriptor_type (type)) | |
9296 | /* GDB allows dereferencing GNAT array descriptors. */ | |
9297 | { | |
9298 | struct type *arrType = ada_type_of_array (arg1, 0); | |
9299 | if (arrType == NULL) | |
9300 | error ("Attempt to dereference null array pointer."); | |
9301 | return value_at_lazy (arrType, 0, NULL); | |
9302 | } | |
9303 | else if (TYPE_CODE (type) == TYPE_CODE_PTR | |
9304 | || TYPE_CODE (type) == TYPE_CODE_REF | |
9305 | /* In C you can dereference an array to get the 1st elt. */ | |
9306 | || TYPE_CODE (type) == TYPE_CODE_ARRAY) | |
9307 | return | |
9308 | value_zero | |
9309 | (to_static_fixed_type | |
9310 | (ada_aligned_type (check_typedef (TYPE_TARGET_TYPE (type)))), | |
9311 | lval_memory); | |
9312 | else if (TYPE_CODE (type) == TYPE_CODE_INT) | |
9313 | /* GDB allows dereferencing an int. */ | |
9314 | return value_zero (builtin_type_int, lval_memory); | |
9315 | else | |
9316 | error ("Attempt to take contents of a non-pointer value."); | |
9317 | } | |
9318 | arg1 = ada_coerce_ref (arg1); /* FIXME: What is this for?? */ | |
14f9c5c9 | 9319 | type = check_typedef (VALUE_TYPE (arg1)); |
d2e4a39e | 9320 | |
4c4b4cd2 PH |
9321 | if (ada_is_array_descriptor_type (type)) |
9322 | /* GDB allows dereferencing GNAT array descriptors. */ | |
9323 | return ada_coerce_to_simple_array (arg1); | |
14f9c5c9 | 9324 | else |
4c4b4cd2 | 9325 | return ada_value_ind (arg1); |
14f9c5c9 AS |
9326 | |
9327 | case STRUCTOP_STRUCT: | |
9328 | tem = longest_to_int (exp->elts[pc + 1].longconst); | |
9329 | (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1); | |
9330 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
9331 | if (noside == EVAL_SKIP) | |
4c4b4cd2 | 9332 | goto nosideret; |
14f9c5c9 | 9333 | if (noside == EVAL_AVOID_SIDE_EFFECTS) |
4c4b4cd2 PH |
9334 | { |
9335 | struct type *type1 = VALUE_TYPE (arg1); | |
9336 | if (ada_is_tagged_type (type1, 1)) | |
9337 | { | |
9338 | type = ada_lookup_struct_elt_type (type1, | |
9339 | &exp->elts[pc + 2].string, | |
9340 | 1, 1, NULL); | |
9341 | if (type == NULL) | |
9342 | /* In this case, we assume that the field COULD exist | |
9343 | in some extension of the type. Return an object of | |
9344 | "type" void, which will match any formal | |
9345 | (see ada_type_match). */ | |
9346 | return value_zero (builtin_type_void, lval_memory); | |
9347 | } | |
9348 | else | |
9349 | type = ada_lookup_struct_elt_type (type1, &exp->elts[pc + 2].string, | |
9350 | 1, 0, NULL); | |
9351 | ||
9352 | return value_zero (ada_aligned_type (type), lval_memory); | |
9353 | } | |
14f9c5c9 | 9354 | else |
4c4b4cd2 PH |
9355 | return |
9356 | ada_to_fixed_value (unwrap_value | |
9357 | (ada_value_struct_elt | |
9358 | (arg1, &exp->elts[pc + 2].string, "record"))); | |
14f9c5c9 | 9359 | case OP_TYPE: |
4c4b4cd2 PH |
9360 | /* The value is not supposed to be used. This is here to make it |
9361 | easier to accommodate expressions that contain types. */ | |
14f9c5c9 AS |
9362 | (*pos) += 2; |
9363 | if (noside == EVAL_SKIP) | |
4c4b4cd2 | 9364 | goto nosideret; |
14f9c5c9 | 9365 | else if (noside == EVAL_AVOID_SIDE_EFFECTS) |
4c4b4cd2 | 9366 | return allocate_value (builtin_type_void); |
14f9c5c9 | 9367 | else |
4c4b4cd2 | 9368 | error ("Attempt to use a type name as an expression"); |
14f9c5c9 AS |
9369 | } |
9370 | ||
9371 | nosideret: | |
9372 | return value_from_longest (builtin_type_long, (LONGEST) 1); | |
9373 | } | |
14f9c5c9 | 9374 | \f |
d2e4a39e | 9375 | |
4c4b4cd2 | 9376 | /* Fixed point */ |
14f9c5c9 AS |
9377 | |
9378 | /* If TYPE encodes an Ada fixed-point type, return the suffix of the | |
9379 | type name that encodes the 'small and 'delta information. | |
4c4b4cd2 | 9380 | Otherwise, return NULL. */ |
14f9c5c9 | 9381 | |
d2e4a39e | 9382 | static const char * |
ebf56fd3 | 9383 | fixed_type_info (struct type *type) |
14f9c5c9 | 9384 | { |
d2e4a39e | 9385 | const char *name = ada_type_name (type); |
14f9c5c9 AS |
9386 | enum type_code code = (type == NULL) ? TYPE_CODE_UNDEF : TYPE_CODE (type); |
9387 | ||
d2e4a39e AS |
9388 | if ((code == TYPE_CODE_INT || code == TYPE_CODE_RANGE) && name != NULL) |
9389 | { | |
14f9c5c9 AS |
9390 | const char *tail = strstr (name, "___XF_"); |
9391 | if (tail == NULL) | |
4c4b4cd2 | 9392 | return NULL; |
d2e4a39e | 9393 | else |
4c4b4cd2 | 9394 | return tail + 5; |
14f9c5c9 AS |
9395 | } |
9396 | else if (code == TYPE_CODE_RANGE && TYPE_TARGET_TYPE (type) != type) | |
9397 | return fixed_type_info (TYPE_TARGET_TYPE (type)); | |
9398 | else | |
9399 | return NULL; | |
9400 | } | |
9401 | ||
4c4b4cd2 | 9402 | /* Returns non-zero iff TYPE represents an Ada fixed-point type. */ |
14f9c5c9 AS |
9403 | |
9404 | int | |
ebf56fd3 | 9405 | ada_is_fixed_point_type (struct type *type) |
14f9c5c9 AS |
9406 | { |
9407 | return fixed_type_info (type) != NULL; | |
9408 | } | |
9409 | ||
4c4b4cd2 PH |
9410 | /* Return non-zero iff TYPE represents a System.Address type. */ |
9411 | ||
9412 | int | |
9413 | ada_is_system_address_type (struct type *type) | |
9414 | { | |
9415 | return (TYPE_NAME (type) | |
9416 | && strcmp (TYPE_NAME (type), "system__address") == 0); | |
9417 | } | |
9418 | ||
14f9c5c9 AS |
9419 | /* Assuming that TYPE is the representation of an Ada fixed-point |
9420 | type, return its delta, or -1 if the type is malformed and the | |
4c4b4cd2 | 9421 | delta cannot be determined. */ |
14f9c5c9 AS |
9422 | |
9423 | DOUBLEST | |
ebf56fd3 | 9424 | ada_delta (struct type *type) |
14f9c5c9 AS |
9425 | { |
9426 | const char *encoding = fixed_type_info (type); | |
9427 | long num, den; | |
9428 | ||
9429 | if (sscanf (encoding, "_%ld_%ld", &num, &den) < 2) | |
9430 | return -1.0; | |
d2e4a39e | 9431 | else |
14f9c5c9 AS |
9432 | return (DOUBLEST) num / (DOUBLEST) den; |
9433 | } | |
9434 | ||
9435 | /* Assuming that ada_is_fixed_point_type (TYPE), return the scaling | |
4c4b4cd2 | 9436 | factor ('SMALL value) associated with the type. */ |
14f9c5c9 AS |
9437 | |
9438 | static DOUBLEST | |
ebf56fd3 | 9439 | scaling_factor (struct type *type) |
14f9c5c9 AS |
9440 | { |
9441 | const char *encoding = fixed_type_info (type); | |
9442 | unsigned long num0, den0, num1, den1; | |
9443 | int n; | |
d2e4a39e | 9444 | |
14f9c5c9 AS |
9445 | n = sscanf (encoding, "_%lu_%lu_%lu_%lu", &num0, &den0, &num1, &den1); |
9446 | ||
9447 | if (n < 2) | |
9448 | return 1.0; | |
9449 | else if (n == 4) | |
9450 | return (DOUBLEST) num1 / (DOUBLEST) den1; | |
d2e4a39e | 9451 | else |
14f9c5c9 AS |
9452 | return (DOUBLEST) num0 / (DOUBLEST) den0; |
9453 | } | |
9454 | ||
9455 | ||
9456 | /* Assuming that X is the representation of a value of fixed-point | |
4c4b4cd2 | 9457 | type TYPE, return its floating-point equivalent. */ |
14f9c5c9 AS |
9458 | |
9459 | DOUBLEST | |
ebf56fd3 | 9460 | ada_fixed_to_float (struct type *type, LONGEST x) |
14f9c5c9 | 9461 | { |
d2e4a39e | 9462 | return (DOUBLEST) x *scaling_factor (type); |
14f9c5c9 AS |
9463 | } |
9464 | ||
4c4b4cd2 PH |
9465 | /* The representation of a fixed-point value of type TYPE |
9466 | corresponding to the value X. */ | |
14f9c5c9 AS |
9467 | |
9468 | LONGEST | |
ebf56fd3 | 9469 | ada_float_to_fixed (struct type *type, DOUBLEST x) |
14f9c5c9 AS |
9470 | { |
9471 | return (LONGEST) (x / scaling_factor (type) + 0.5); | |
9472 | } | |
9473 | ||
9474 | ||
4c4b4cd2 | 9475 | /* VAX floating formats */ |
14f9c5c9 AS |
9476 | |
9477 | /* Non-zero iff TYPE represents one of the special VAX floating-point | |
4c4b4cd2 PH |
9478 | types. */ |
9479 | ||
14f9c5c9 | 9480 | int |
d2e4a39e | 9481 | ada_is_vax_floating_type (struct type *type) |
14f9c5c9 | 9482 | { |
d2e4a39e | 9483 | int name_len = |
14f9c5c9 | 9484 | (ada_type_name (type) == NULL) ? 0 : strlen (ada_type_name (type)); |
d2e4a39e | 9485 | return |
14f9c5c9 | 9486 | name_len > 6 |
d2e4a39e | 9487 | && (TYPE_CODE (type) == TYPE_CODE_INT |
4c4b4cd2 PH |
9488 | || TYPE_CODE (type) == TYPE_CODE_RANGE) |
9489 | && strncmp (ada_type_name (type) + name_len - 6, "___XF", 5) == 0; | |
14f9c5c9 AS |
9490 | } |
9491 | ||
9492 | /* The type of special VAX floating-point type this is, assuming | |
4c4b4cd2 PH |
9493 | ada_is_vax_floating_point. */ |
9494 | ||
14f9c5c9 | 9495 | int |
d2e4a39e | 9496 | ada_vax_float_type_suffix (struct type *type) |
14f9c5c9 | 9497 | { |
d2e4a39e | 9498 | return ada_type_name (type)[strlen (ada_type_name (type)) - 1]; |
14f9c5c9 AS |
9499 | } |
9500 | ||
4c4b4cd2 | 9501 | /* A value representing the special debugging function that outputs |
14f9c5c9 | 9502 | VAX floating-point values of the type represented by TYPE. Assumes |
4c4b4cd2 PH |
9503 | ada_is_vax_floating_type (TYPE). */ |
9504 | ||
d2e4a39e AS |
9505 | struct value * |
9506 | ada_vax_float_print_function (struct type *type) | |
9507 | { | |
9508 | switch (ada_vax_float_type_suffix (type)) | |
9509 | { | |
9510 | case 'F': | |
9511 | return get_var_value ("DEBUG_STRING_F", 0); | |
9512 | case 'D': | |
9513 | return get_var_value ("DEBUG_STRING_D", 0); | |
9514 | case 'G': | |
9515 | return get_var_value ("DEBUG_STRING_G", 0); | |
9516 | default: | |
9517 | error ("invalid VAX floating-point type"); | |
9518 | } | |
14f9c5c9 | 9519 | } |
14f9c5c9 | 9520 | \f |
d2e4a39e | 9521 | |
4c4b4cd2 | 9522 | /* Range types */ |
14f9c5c9 AS |
9523 | |
9524 | /* Scan STR beginning at position K for a discriminant name, and | |
9525 | return the value of that discriminant field of DVAL in *PX. If | |
9526 | PNEW_K is not null, put the position of the character beyond the | |
9527 | name scanned in *PNEW_K. Return 1 if successful; return 0 and do | |
4c4b4cd2 | 9528 | not alter *PX and *PNEW_K if unsuccessful. */ |
14f9c5c9 AS |
9529 | |
9530 | static int | |
07d8f827 | 9531 | scan_discrim_bound (char *str, int k, struct value *dval, LONGEST * px, |
d2e4a39e | 9532 | int *pnew_k) |
14f9c5c9 AS |
9533 | { |
9534 | static char *bound_buffer = NULL; | |
9535 | static size_t bound_buffer_len = 0; | |
9536 | char *bound; | |
9537 | char *pend; | |
d2e4a39e | 9538 | struct value *bound_val; |
14f9c5c9 AS |
9539 | |
9540 | if (dval == NULL || str == NULL || str[k] == '\0') | |
9541 | return 0; | |
9542 | ||
d2e4a39e | 9543 | pend = strstr (str + k, "__"); |
14f9c5c9 AS |
9544 | if (pend == NULL) |
9545 | { | |
d2e4a39e | 9546 | bound = str + k; |
14f9c5c9 AS |
9547 | k += strlen (bound); |
9548 | } | |
d2e4a39e | 9549 | else |
14f9c5c9 | 9550 | { |
d2e4a39e | 9551 | GROW_VECT (bound_buffer, bound_buffer_len, pend - (str + k) + 1); |
14f9c5c9 | 9552 | bound = bound_buffer; |
d2e4a39e AS |
9553 | strncpy (bound_buffer, str + k, pend - (str + k)); |
9554 | bound[pend - (str + k)] = '\0'; | |
9555 | k = pend - str; | |
14f9c5c9 | 9556 | } |
d2e4a39e AS |
9557 | |
9558 | bound_val = ada_search_struct_field (bound, dval, 0, VALUE_TYPE (dval)); | |
14f9c5c9 AS |
9559 | if (bound_val == NULL) |
9560 | return 0; | |
9561 | ||
9562 | *px = value_as_long (bound_val); | |
9563 | if (pnew_k != NULL) | |
9564 | *pnew_k = k; | |
9565 | return 1; | |
9566 | } | |
9567 | ||
9568 | /* Value of variable named NAME in the current environment. If | |
9569 | no such variable found, then if ERR_MSG is null, returns 0, and | |
4c4b4cd2 PH |
9570 | otherwise causes an error with message ERR_MSG. */ |
9571 | ||
d2e4a39e AS |
9572 | static struct value * |
9573 | get_var_value (char *name, char *err_msg) | |
14f9c5c9 | 9574 | { |
4c4b4cd2 | 9575 | struct ada_symbol_info *syms; |
14f9c5c9 AS |
9576 | int nsyms; |
9577 | ||
4c4b4cd2 PH |
9578 | nsyms = ada_lookup_symbol_list (name, get_selected_block (0), VAR_DOMAIN, |
9579 | &syms); | |
14f9c5c9 AS |
9580 | |
9581 | if (nsyms != 1) | |
9582 | { | |
9583 | if (err_msg == NULL) | |
4c4b4cd2 | 9584 | return 0; |
14f9c5c9 | 9585 | else |
4c4b4cd2 | 9586 | error ("%s", err_msg); |
14f9c5c9 AS |
9587 | } |
9588 | ||
4c4b4cd2 | 9589 | return value_of_variable (syms[0].sym, syms[0].block); |
14f9c5c9 | 9590 | } |
d2e4a39e | 9591 | |
14f9c5c9 | 9592 | /* Value of integer variable named NAME in the current environment. If |
4c4b4cd2 PH |
9593 | no such variable found, returns 0, and sets *FLAG to 0. If |
9594 | successful, sets *FLAG to 1. */ | |
9595 | ||
14f9c5c9 | 9596 | LONGEST |
4c4b4cd2 | 9597 | get_int_var_value (char *name, int *flag) |
14f9c5c9 | 9598 | { |
4c4b4cd2 | 9599 | struct value *var_val = get_var_value (name, 0); |
d2e4a39e | 9600 | |
14f9c5c9 AS |
9601 | if (var_val == 0) |
9602 | { | |
9603 | if (flag != NULL) | |
4c4b4cd2 | 9604 | *flag = 0; |
14f9c5c9 AS |
9605 | return 0; |
9606 | } | |
9607 | else | |
9608 | { | |
9609 | if (flag != NULL) | |
4c4b4cd2 | 9610 | *flag = 1; |
14f9c5c9 AS |
9611 | return value_as_long (var_val); |
9612 | } | |
9613 | } | |
d2e4a39e | 9614 | |
14f9c5c9 AS |
9615 | |
9616 | /* Return a range type whose base type is that of the range type named | |
9617 | NAME in the current environment, and whose bounds are calculated | |
4c4b4cd2 | 9618 | from NAME according to the GNAT range encoding conventions. |
14f9c5c9 AS |
9619 | Extract discriminant values, if needed, from DVAL. If a new type |
9620 | must be created, allocate in OBJFILE's space. The bounds | |
9621 | information, in general, is encoded in NAME, the base type given in | |
4c4b4cd2 | 9622 | the named range type. */ |
14f9c5c9 | 9623 | |
d2e4a39e | 9624 | static struct type * |
ebf56fd3 | 9625 | to_fixed_range_type (char *name, struct value *dval, struct objfile *objfile) |
14f9c5c9 AS |
9626 | { |
9627 | struct type *raw_type = ada_find_any_type (name); | |
9628 | struct type *base_type; | |
d2e4a39e | 9629 | char *subtype_info; |
14f9c5c9 AS |
9630 | |
9631 | if (raw_type == NULL) | |
9632 | base_type = builtin_type_int; | |
9633 | else if (TYPE_CODE (raw_type) == TYPE_CODE_RANGE) | |
9634 | base_type = TYPE_TARGET_TYPE (raw_type); | |
9635 | else | |
9636 | base_type = raw_type; | |
9637 | ||
9638 | subtype_info = strstr (name, "___XD"); | |
9639 | if (subtype_info == NULL) | |
9640 | return raw_type; | |
9641 | else | |
9642 | { | |
9643 | static char *name_buf = NULL; | |
9644 | static size_t name_len = 0; | |
9645 | int prefix_len = subtype_info - name; | |
9646 | LONGEST L, U; | |
9647 | struct type *type; | |
9648 | char *bounds_str; | |
9649 | int n; | |
9650 | ||
9651 | GROW_VECT (name_buf, name_len, prefix_len + 5); | |
9652 | strncpy (name_buf, name, prefix_len); | |
9653 | name_buf[prefix_len] = '\0'; | |
9654 | ||
9655 | subtype_info += 5; | |
9656 | bounds_str = strchr (subtype_info, '_'); | |
9657 | n = 1; | |
9658 | ||
d2e4a39e | 9659 | if (*subtype_info == 'L') |
4c4b4cd2 PH |
9660 | { |
9661 | if (!ada_scan_number (bounds_str, n, &L, &n) | |
9662 | && !scan_discrim_bound (bounds_str, n, dval, &L, &n)) | |
9663 | return raw_type; | |
9664 | if (bounds_str[n] == '_') | |
9665 | n += 2; | |
9666 | else if (bounds_str[n] == '.') /* FIXME? SGI Workshop kludge. */ | |
9667 | n += 1; | |
9668 | subtype_info += 1; | |
9669 | } | |
d2e4a39e | 9670 | else |
4c4b4cd2 PH |
9671 | { |
9672 | int ok; | |
9673 | strcpy (name_buf + prefix_len, "___L"); | |
9674 | L = get_int_var_value (name_buf, &ok); | |
9675 | if (!ok) | |
9676 | { | |
9677 | lim_warning ("Unknown lower bound, using 1.", 1); | |
9678 | L = 1; | |
9679 | } | |
9680 | } | |
14f9c5c9 | 9681 | |
d2e4a39e | 9682 | if (*subtype_info == 'U') |
4c4b4cd2 PH |
9683 | { |
9684 | if (!ada_scan_number (bounds_str, n, &U, &n) | |
9685 | && !scan_discrim_bound (bounds_str, n, dval, &U, &n)) | |
9686 | return raw_type; | |
9687 | } | |
d2e4a39e | 9688 | else |
4c4b4cd2 PH |
9689 | { |
9690 | int ok; | |
9691 | strcpy (name_buf + prefix_len, "___U"); | |
9692 | U = get_int_var_value (name_buf, &ok); | |
9693 | if (!ok) | |
9694 | { | |
9695 | lim_warning ("Unknown upper bound, using %ld.", (long) L); | |
9696 | U = L; | |
9697 | } | |
9698 | } | |
14f9c5c9 | 9699 | |
d2e4a39e | 9700 | if (objfile == NULL) |
4c4b4cd2 | 9701 | objfile = TYPE_OBJFILE (base_type); |
14f9c5c9 | 9702 | type = create_range_type (alloc_type (objfile), base_type, L, U); |
d2e4a39e | 9703 | TYPE_NAME (type) = name; |
14f9c5c9 AS |
9704 | return type; |
9705 | } | |
9706 | } | |
9707 | ||
4c4b4cd2 PH |
9708 | /* True iff NAME is the name of a range type. */ |
9709 | ||
14f9c5c9 | 9710 | int |
d2e4a39e | 9711 | ada_is_range_type_name (const char *name) |
14f9c5c9 AS |
9712 | { |
9713 | return (name != NULL && strstr (name, "___XD")); | |
d2e4a39e | 9714 | } |
14f9c5c9 | 9715 | \f |
d2e4a39e | 9716 | |
4c4b4cd2 PH |
9717 | /* Modular types */ |
9718 | ||
9719 | /* True iff TYPE is an Ada modular type. */ | |
14f9c5c9 | 9720 | |
14f9c5c9 | 9721 | int |
d2e4a39e | 9722 | ada_is_modular_type (struct type *type) |
14f9c5c9 | 9723 | { |
4c4b4cd2 | 9724 | struct type *subranged_type = base_type (type); |
14f9c5c9 AS |
9725 | |
9726 | return (subranged_type != NULL && TYPE_CODE (type) == TYPE_CODE_RANGE | |
4c4b4cd2 PH |
9727 | && TYPE_CODE (subranged_type) != TYPE_CODE_ENUM |
9728 | && TYPE_UNSIGNED (subranged_type)); | |
14f9c5c9 AS |
9729 | } |
9730 | ||
4c4b4cd2 PH |
9731 | /* Assuming ada_is_modular_type (TYPE), the modulus of TYPE. */ |
9732 | ||
14f9c5c9 | 9733 | LONGEST |
d2e4a39e | 9734 | ada_modulus (struct type * type) |
14f9c5c9 | 9735 | { |
d2e4a39e | 9736 | return TYPE_HIGH_BOUND (type) + 1; |
14f9c5c9 | 9737 | } |
d2e4a39e | 9738 | \f |
4c4b4cd2 PH |
9739 | /* Operators */ |
9740 | /* Information about operators given special treatment in functions | |
9741 | below. */ | |
9742 | /* Format: OP_DEFN (<operator>, <operator length>, <# args>, <binop>). */ | |
9743 | ||
9744 | #define ADA_OPERATORS \ | |
9745 | OP_DEFN (OP_VAR_VALUE, 4, 0, 0) \ | |
9746 | OP_DEFN (BINOP_IN_BOUNDS, 3, 2, 0) \ | |
9747 | OP_DEFN (TERNOP_IN_RANGE, 1, 3, 0) \ | |
9748 | OP_DEFN (OP_ATR_FIRST, 1, 2, 0) \ | |
9749 | OP_DEFN (OP_ATR_LAST, 1, 2, 0) \ | |
9750 | OP_DEFN (OP_ATR_LENGTH, 1, 2, 0) \ | |
9751 | OP_DEFN (OP_ATR_IMAGE, 1, 2, 0) \ | |
9752 | OP_DEFN (OP_ATR_MAX, 1, 3, 0) \ | |
9753 | OP_DEFN (OP_ATR_MIN, 1, 3, 0) \ | |
9754 | OP_DEFN (OP_ATR_MODULUS, 1, 1, 0) \ | |
9755 | OP_DEFN (OP_ATR_POS, 1, 2, 0) \ | |
9756 | OP_DEFN (OP_ATR_SIZE, 1, 1, 0) \ | |
9757 | OP_DEFN (OP_ATR_TAG, 1, 1, 0) \ | |
9758 | OP_DEFN (OP_ATR_VAL, 1, 2, 0) \ | |
9759 | OP_DEFN (UNOP_QUAL, 3, 1, 0) \ | |
9760 | OP_DEFN (UNOP_IN_RANGE, 3, 1, 0) | |
9761 | ||
9762 | static void | |
9763 | ada_operator_length (struct expression *exp, int pc, int *oplenp, int *argsp) | |
9764 | { | |
9765 | switch (exp->elts[pc - 1].opcode) | |
9766 | { | |
9767 | default: | |
9768 | operator_length_standard (exp, pc, oplenp, argsp); | |
9769 | break; | |
9770 | ||
9771 | #define OP_DEFN(op, len, args, binop) \ | |
9772 | case op: *oplenp = len; *argsp = args; break; | |
9773 | ADA_OPERATORS; | |
9774 | #undef OP_DEFN | |
9775 | } | |
9776 | } | |
9777 | ||
9778 | static char * | |
9779 | ada_op_name (enum exp_opcode opcode) | |
9780 | { | |
9781 | switch (opcode) | |
9782 | { | |
9783 | default: | |
9784 | return op_name_standard (opcode); | |
9785 | #define OP_DEFN(op, len, args, binop) case op: return #op; | |
9786 | ADA_OPERATORS; | |
9787 | #undef OP_DEFN | |
9788 | } | |
9789 | } | |
9790 | ||
9791 | /* As for operator_length, but assumes PC is pointing at the first | |
9792 | element of the operator, and gives meaningful results only for the | |
9793 | Ada-specific operators. */ | |
9794 | ||
9795 | static void | |
9796 | ada_forward_operator_length (struct expression *exp, int pc, | |
9797 | int *oplenp, int *argsp) | |
9798 | { | |
9799 | switch (exp->elts[pc].opcode) | |
9800 | { | |
9801 | default: | |
9802 | *oplenp = *argsp = 0; | |
9803 | break; | |
9804 | #define OP_DEFN(op, len, args, binop) \ | |
9805 | case op: *oplenp = len; *argsp = args; break; | |
9806 | ADA_OPERATORS; | |
9807 | #undef OP_DEFN | |
9808 | } | |
9809 | } | |
9810 | ||
9811 | static int | |
9812 | ada_dump_subexp_body (struct expression *exp, struct ui_file *stream, int elt) | |
9813 | { | |
9814 | enum exp_opcode op = exp->elts[elt].opcode; | |
9815 | int oplen, nargs; | |
9816 | int pc = elt; | |
9817 | int i; | |
9818 | ||
9819 | ada_forward_operator_length (exp, elt, &oplen, &nargs); | |
9820 | ||
9821 | switch (op) | |
9822 | { | |
9823 | /* Ada attributes ('Foo). */ | |
9824 | case OP_ATR_FIRST: | |
9825 | case OP_ATR_LAST: | |
9826 | case OP_ATR_LENGTH: | |
9827 | case OP_ATR_IMAGE: | |
9828 | case OP_ATR_MAX: | |
9829 | case OP_ATR_MIN: | |
9830 | case OP_ATR_MODULUS: | |
9831 | case OP_ATR_POS: | |
9832 | case OP_ATR_SIZE: | |
9833 | case OP_ATR_TAG: | |
9834 | case OP_ATR_VAL: | |
9835 | break; | |
9836 | ||
9837 | case UNOP_IN_RANGE: | |
9838 | case UNOP_QUAL: | |
9839 | fprintf_filtered (stream, "Type @"); | |
9840 | gdb_print_host_address (exp->elts[pc + 1].type, stream); | |
9841 | fprintf_filtered (stream, " ("); | |
9842 | type_print (exp->elts[pc + 1].type, NULL, stream, 0); | |
9843 | fprintf_filtered (stream, ")"); | |
9844 | break; | |
9845 | case BINOP_IN_BOUNDS: | |
9846 | fprintf_filtered (stream, " (%d)", (int) exp->elts[pc + 2].longconst); | |
9847 | break; | |
9848 | case TERNOP_IN_RANGE: | |
9849 | break; | |
9850 | ||
9851 | default: | |
9852 | return dump_subexp_body_standard (exp, stream, elt); | |
9853 | } | |
9854 | ||
9855 | elt += oplen; | |
9856 | for (i = 0; i < nargs; i += 1) | |
9857 | elt = dump_subexp (exp, stream, elt); | |
9858 | ||
9859 | return elt; | |
9860 | } | |
9861 | ||
9862 | /* The Ada extension of print_subexp (q.v.). */ | |
9863 | ||
9864 | static void | |
9865 | ada_print_subexp (struct expression *exp, int *pos, | |
9866 | struct ui_file *stream, enum precedence prec) | |
9867 | { | |
9868 | int oplen, nargs; | |
9869 | int pc = *pos; | |
9870 | enum exp_opcode op = exp->elts[pc].opcode; | |
9871 | ||
9872 | ada_forward_operator_length (exp, pc, &oplen, &nargs); | |
9873 | ||
9874 | switch (op) | |
9875 | { | |
9876 | default: | |
9877 | print_subexp_standard (exp, pos, stream, prec); | |
9878 | return; | |
9879 | ||
9880 | case OP_VAR_VALUE: | |
9881 | *pos += oplen; | |
9882 | fputs_filtered (SYMBOL_NATURAL_NAME (exp->elts[pc + 2].symbol), stream); | |
9883 | return; | |
9884 | ||
9885 | case BINOP_IN_BOUNDS: | |
9886 | *pos += oplen; | |
9887 | print_subexp (exp, pos, stream, PREC_SUFFIX); | |
9888 | fputs_filtered (" in ", stream); | |
9889 | print_subexp (exp, pos, stream, PREC_SUFFIX); | |
9890 | fputs_filtered ("'range", stream); | |
9891 | if (exp->elts[pc + 1].longconst > 1) | |
9892 | fprintf_filtered (stream, "(%ld)", (long) exp->elts[pc + 1].longconst); | |
9893 | return; | |
9894 | ||
9895 | case TERNOP_IN_RANGE: | |
9896 | *pos += oplen; | |
9897 | if (prec >= PREC_EQUAL) | |
9898 | fputs_filtered ("(", stream); | |
9899 | print_subexp (exp, pos, stream, PREC_SUFFIX); | |
9900 | fputs_filtered (" in ", stream); | |
9901 | print_subexp (exp, pos, stream, PREC_EQUAL); | |
9902 | fputs_filtered (" .. ", stream); | |
9903 | print_subexp (exp, pos, stream, PREC_EQUAL); | |
9904 | if (prec >= PREC_EQUAL) | |
9905 | fputs_filtered (")", stream); | |
9906 | return; | |
9907 | ||
9908 | case OP_ATR_FIRST: | |
9909 | case OP_ATR_LAST: | |
9910 | case OP_ATR_LENGTH: | |
9911 | case OP_ATR_IMAGE: | |
9912 | case OP_ATR_MAX: | |
9913 | case OP_ATR_MIN: | |
9914 | case OP_ATR_MODULUS: | |
9915 | case OP_ATR_POS: | |
9916 | case OP_ATR_SIZE: | |
9917 | case OP_ATR_TAG: | |
9918 | case OP_ATR_VAL: | |
9919 | *pos += oplen; | |
9920 | if (exp->elts[*pos].opcode == OP_TYPE) | |
9921 | { | |
9922 | if (TYPE_CODE (exp->elts[*pos + 1].type) != TYPE_CODE_VOID) | |
9923 | LA_PRINT_TYPE (exp->elts[*pos + 1].type, "", stream, 0, 0); | |
9924 | *pos += 3; | |
9925 | } | |
9926 | else | |
9927 | print_subexp (exp, pos, stream, PREC_SUFFIX); | |
9928 | fprintf_filtered (stream, "'%s", ada_attribute_name (op)); | |
9929 | if (nargs > 1) | |
9930 | { | |
9931 | int tem; | |
9932 | for (tem = 1; tem < nargs; tem += 1) | |
9933 | { | |
9934 | fputs_filtered ( (tem == 1) ? " (" : ", ", stream); | |
9935 | print_subexp (exp, pos, stream, PREC_ABOVE_COMMA); | |
9936 | } | |
9937 | fputs_filtered (")", stream); | |
9938 | } | |
9939 | return; | |
14f9c5c9 | 9940 | |
4c4b4cd2 PH |
9941 | case UNOP_QUAL: |
9942 | *pos += oplen; | |
9943 | type_print (exp->elts[pc + 1].type, "", stream, 0); | |
9944 | fputs_filtered ("'(", stream); | |
9945 | print_subexp (exp, pos, stream, PREC_PREFIX); | |
9946 | fputs_filtered (")", stream); | |
9947 | return; | |
14f9c5c9 | 9948 | |
4c4b4cd2 PH |
9949 | case UNOP_IN_RANGE: |
9950 | *pos += oplen; | |
9951 | print_subexp (exp, pos, stream, PREC_SUFFIX); | |
9952 | fputs_filtered (" in ", stream); | |
9953 | LA_PRINT_TYPE (exp->elts[pc + 1].type, "", stream, 1, 0); | |
9954 | return; | |
9955 | } | |
9956 | } | |
14f9c5c9 AS |
9957 | |
9958 | /* Table mapping opcodes into strings for printing operators | |
9959 | and precedences of the operators. */ | |
9960 | ||
d2e4a39e AS |
9961 | static const struct op_print ada_op_print_tab[] = { |
9962 | {":=", BINOP_ASSIGN, PREC_ASSIGN, 1}, | |
9963 | {"or else", BINOP_LOGICAL_OR, PREC_LOGICAL_OR, 0}, | |
9964 | {"and then", BINOP_LOGICAL_AND, PREC_LOGICAL_AND, 0}, | |
9965 | {"or", BINOP_BITWISE_IOR, PREC_BITWISE_IOR, 0}, | |
9966 | {"xor", BINOP_BITWISE_XOR, PREC_BITWISE_XOR, 0}, | |
9967 | {"and", BINOP_BITWISE_AND, PREC_BITWISE_AND, 0}, | |
9968 | {"=", BINOP_EQUAL, PREC_EQUAL, 0}, | |
9969 | {"/=", BINOP_NOTEQUAL, PREC_EQUAL, 0}, | |
9970 | {"<=", BINOP_LEQ, PREC_ORDER, 0}, | |
9971 | {">=", BINOP_GEQ, PREC_ORDER, 0}, | |
9972 | {">", BINOP_GTR, PREC_ORDER, 0}, | |
9973 | {"<", BINOP_LESS, PREC_ORDER, 0}, | |
9974 | {">>", BINOP_RSH, PREC_SHIFT, 0}, | |
9975 | {"<<", BINOP_LSH, PREC_SHIFT, 0}, | |
9976 | {"+", BINOP_ADD, PREC_ADD, 0}, | |
9977 | {"-", BINOP_SUB, PREC_ADD, 0}, | |
9978 | {"&", BINOP_CONCAT, PREC_ADD, 0}, | |
9979 | {"*", BINOP_MUL, PREC_MUL, 0}, | |
9980 | {"/", BINOP_DIV, PREC_MUL, 0}, | |
9981 | {"rem", BINOP_REM, PREC_MUL, 0}, | |
9982 | {"mod", BINOP_MOD, PREC_MUL, 0}, | |
9983 | {"**", BINOP_EXP, PREC_REPEAT, 0}, | |
9984 | {"@", BINOP_REPEAT, PREC_REPEAT, 0}, | |
9985 | {"-", UNOP_NEG, PREC_PREFIX, 0}, | |
9986 | {"+", UNOP_PLUS, PREC_PREFIX, 0}, | |
9987 | {"not ", UNOP_LOGICAL_NOT, PREC_PREFIX, 0}, | |
9988 | {"not ", UNOP_COMPLEMENT, PREC_PREFIX, 0}, | |
9989 | {"abs ", UNOP_ABS, PREC_PREFIX, 0}, | |
4c4b4cd2 PH |
9990 | {".all", UNOP_IND, PREC_SUFFIX, 1}, |
9991 | {"'access", UNOP_ADDR, PREC_SUFFIX, 1}, | |
9992 | {"'size", OP_ATR_SIZE, PREC_SUFFIX, 1}, | |
d2e4a39e | 9993 | {NULL, 0, 0, 0} |
14f9c5c9 AS |
9994 | }; |
9995 | \f | |
4c4b4cd2 | 9996 | /* Assorted Types and Interfaces */ |
14f9c5c9 | 9997 | |
d2e4a39e AS |
9998 | struct type *builtin_type_ada_int; |
9999 | struct type *builtin_type_ada_short; | |
10000 | struct type *builtin_type_ada_long; | |
10001 | struct type *builtin_type_ada_long_long; | |
10002 | struct type *builtin_type_ada_char; | |
10003 | struct type *builtin_type_ada_float; | |
10004 | struct type *builtin_type_ada_double; | |
10005 | struct type *builtin_type_ada_long_double; | |
10006 | struct type *builtin_type_ada_natural; | |
10007 | struct type *builtin_type_ada_positive; | |
10008 | struct type *builtin_type_ada_system_address; | |
10009 | ||
10010 | struct type **const (ada_builtin_types[]) = | |
10011 | { | |
14f9c5c9 | 10012 | &builtin_type_ada_int, |
4c4b4cd2 PH |
10013 | &builtin_type_ada_long, |
10014 | &builtin_type_ada_short, | |
10015 | &builtin_type_ada_char, | |
10016 | &builtin_type_ada_float, | |
10017 | &builtin_type_ada_double, | |
10018 | &builtin_type_ada_long_long, | |
10019 | &builtin_type_ada_long_double, | |
10020 | &builtin_type_ada_natural, &builtin_type_ada_positive, | |
10021 | /* The following types are carried over from C for convenience. */ | |
10022 | &builtin_type_int, | |
10023 | &builtin_type_long, | |
10024 | &builtin_type_short, | |
10025 | &builtin_type_char, | |
10026 | &builtin_type_float, | |
10027 | &builtin_type_double, | |
10028 | &builtin_type_long_long, | |
10029 | &builtin_type_void, | |
10030 | &builtin_type_signed_char, | |
10031 | &builtin_type_unsigned_char, | |
10032 | &builtin_type_unsigned_short, | |
10033 | &builtin_type_unsigned_int, | |
10034 | &builtin_type_unsigned_long, | |
10035 | &builtin_type_unsigned_long_long, | |
10036 | &builtin_type_long_double, | |
10037 | &builtin_type_complex, | |
10038 | &builtin_type_double_complex, | |
10039 | 0 | |
10040 | }; | |
10041 | ||
10042 | /* Not really used, but needed in the ada_language_defn. */ | |
10043 | ||
d2e4a39e AS |
10044 | static void |
10045 | emit_char (int c, struct ui_file *stream, int quoter) | |
14f9c5c9 AS |
10046 | { |
10047 | ada_emit_char (c, stream, quoter, 1); | |
10048 | } | |
10049 | ||
4c4b4cd2 PH |
10050 | static int |
10051 | parse () | |
10052 | { | |
10053 | warnings_issued = 0; | |
10054 | return ada_parse (); | |
10055 | } | |
10056 | ||
10057 | static const struct exp_descriptor ada_exp_descriptor = | |
10058 | { | |
10059 | ada_print_subexp, | |
10060 | ada_operator_length, | |
10061 | ada_op_name, | |
10062 | ada_dump_subexp_body, | |
10063 | ada_evaluate_subexp | |
10064 | }; | |
10065 | ||
14f9c5c9 | 10066 | const struct language_defn ada_language_defn = { |
4c4b4cd2 PH |
10067 | "ada", /* Language name */ |
10068 | language_ada, | |
14f9c5c9 AS |
10069 | ada_builtin_types, |
10070 | range_check_off, | |
10071 | type_check_off, | |
4c4b4cd2 PH |
10072 | case_sensitive_on, /* Yes, Ada is case-insensitive, but |
10073 | that's not quite what this means. */ | |
10074 | #ifdef GNAT_GDB | |
10075 | ada_lookup_symbol, | |
10076 | ada_lookup_minimal_symbol, | |
10077 | #endif | |
10078 | &ada_exp_descriptor, | |
10079 | parse, | |
14f9c5c9 | 10080 | ada_error, |
4c4b4cd2 | 10081 | resolve, |
14f9c5c9 AS |
10082 | ada_printchar, /* Print a character constant */ |
10083 | ada_printstr, /* Function to print string constant */ | |
10084 | emit_char, /* Function to print single char (not used) */ | |
10085 | ada_create_fundamental_type, /* Create fundamental type in this language */ | |
10086 | ada_print_type, /* Print a type using appropriate syntax */ | |
10087 | ada_val_print, /* Print a value using appropriate syntax */ | |
10088 | ada_value_print, /* Print a top-level value */ | |
f636b87d | 10089 | NULL, /* Language specific skip_trampoline */ |
4c4b4cd2 PH |
10090 | NULL, /* value_of_this */ |
10091 | ada_lookup_symbol_nonlocal, /* Looking up non-local symbols. */ | |
b368761e | 10092 | basic_lookup_transparent_type,/* lookup_transparent_type */ |
4c4b4cd2 | 10093 | ada_la_decode, /* Language specific symbol demangler */ |
d2e4a39e | 10094 | {"", "", "", ""}, /* Binary format info */ |
14f9c5c9 | 10095 | #if 0 |
4c4b4cd2 PH |
10096 | {"8#%lo#", "8#", "o", "#"}, /* Octal format info */ |
10097 | {"%ld", "", "d", ""}, /* Decimal format info */ | |
10098 | {"16#%lx#", "16#", "x", "#"}, /* Hex format info */ | |
14f9c5c9 | 10099 | #else |
4c4b4cd2 PH |
10100 | /* Copied from c-lang.c. */ |
10101 | {"0%lo", "0", "o", ""}, /* Octal format info */ | |
10102 | {"%ld", "", "d", ""}, /* Decimal format info */ | |
10103 | {"0x%lx", "0x", "x", ""}, /* Hex format info */ | |
14f9c5c9 | 10104 | #endif |
4c4b4cd2 PH |
10105 | ada_op_print_tab, /* expression operators for printing */ |
10106 | 0, /* c-style arrays */ | |
10107 | 1, /* String lower bound */ | |
14f9c5c9 | 10108 | &builtin_type_ada_char, |
4c4b4cd2 PH |
10109 | ada_get_gdb_completer_word_break_characters, |
10110 | #ifdef GNAT_GDB | |
10111 | ada_translate_error_message, /* Substitute Ada-specific terminology | |
10112 | in errors and warnings. */ | |
10113 | #endif | |
14f9c5c9 AS |
10114 | LANG_MAGIC |
10115 | }; | |
10116 | ||
4c4b4cd2 PH |
10117 | static void |
10118 | build_ada_types (void) { | |
14f9c5c9 AS |
10119 | builtin_type_ada_int = |
10120 | init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT, | |
4c4b4cd2 | 10121 | 0, "integer", (struct objfile *) NULL); |
14f9c5c9 AS |
10122 | builtin_type_ada_long = |
10123 | init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT, | |
4c4b4cd2 | 10124 | 0, "long_integer", (struct objfile *) NULL); |
14f9c5c9 AS |
10125 | builtin_type_ada_short = |
10126 | init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT, | |
4c4b4cd2 | 10127 | 0, "short_integer", (struct objfile *) NULL); |
14f9c5c9 AS |
10128 | builtin_type_ada_char = |
10129 | init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
4c4b4cd2 | 10130 | 0, "character", (struct objfile *) NULL); |
14f9c5c9 AS |
10131 | builtin_type_ada_float = |
10132 | init_type (TYPE_CODE_FLT, TARGET_FLOAT_BIT / TARGET_CHAR_BIT, | |
4c4b4cd2 | 10133 | 0, "float", (struct objfile *) NULL); |
14f9c5c9 AS |
10134 | builtin_type_ada_double = |
10135 | init_type (TYPE_CODE_FLT, TARGET_DOUBLE_BIT / TARGET_CHAR_BIT, | |
4c4b4cd2 | 10136 | 0, "long_float", (struct objfile *) NULL); |
14f9c5c9 AS |
10137 | builtin_type_ada_long_long = |
10138 | init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT, | |
4c4b4cd2 | 10139 | 0, "long_long_integer", (struct objfile *) NULL); |
14f9c5c9 AS |
10140 | builtin_type_ada_long_double = |
10141 | init_type (TYPE_CODE_FLT, TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT, | |
4c4b4cd2 | 10142 | 0, "long_long_float", (struct objfile *) NULL); |
14f9c5c9 AS |
10143 | builtin_type_ada_natural = |
10144 | init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT, | |
4c4b4cd2 | 10145 | 0, "natural", (struct objfile *) NULL); |
14f9c5c9 AS |
10146 | builtin_type_ada_positive = |
10147 | init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT, | |
4c4b4cd2 | 10148 | 0, "positive", (struct objfile *) NULL); |
14f9c5c9 AS |
10149 | |
10150 | ||
d2e4a39e AS |
10151 | builtin_type_ada_system_address = |
10152 | lookup_pointer_type (init_type (TYPE_CODE_VOID, 1, 0, "void", | |
4c4b4cd2 | 10153 | (struct objfile *) NULL)); |
14f9c5c9 | 10154 | TYPE_NAME (builtin_type_ada_system_address) = "system__address"; |
4c4b4cd2 PH |
10155 | } |
10156 | ||
10157 | void | |
10158 | _initialize_ada_language (void) | |
10159 | { | |
14f9c5c9 | 10160 | |
4c4b4cd2 PH |
10161 | build_ada_types (); |
10162 | deprecated_register_gdbarch_swap (NULL, 0, build_ada_types); | |
14f9c5c9 AS |
10163 | add_language (&ada_language_defn); |
10164 | ||
4c4b4cd2 | 10165 | #ifdef GNAT_GDB |
d2e4a39e | 10166 | add_show_from_set |
14f9c5c9 | 10167 | (add_set_cmd ("varsize-limit", class_support, var_uinteger, |
4c4b4cd2 PH |
10168 | (char *) &varsize_limit, |
10169 | "Set maximum bytes in dynamic-sized object.", | |
10170 | &setlist), &showlist); | |
10171 | #endif | |
14f9c5c9 AS |
10172 | varsize_limit = 65536; |
10173 | ||
4c4b4cd2 PH |
10174 | obstack_init (&symbol_list_obstack); |
10175 | obstack_init (&cache_space); | |
14f9c5c9 | 10176 | |
4c4b4cd2 PH |
10177 | decoded_names_store = htab_create_alloc_ex |
10178 | (256, htab_hash_string, (int (*) (const void *, const void *)) streq, | |
10179 | NULL, NULL, xmcalloc, xmfree); | |
10180 | } | |
14f9c5c9 AS |
10181 | |
10182 | /* Create a fundamental Ada type using default reasonable for the current | |
10183 | target machine. | |
10184 | ||
10185 | Some object/debugging file formats (DWARF version 1, COFF, etc) do not | |
10186 | define fundamental types such as "int" or "double". Others (stabs or | |
10187 | DWARF version 2, etc) do define fundamental types. For the formats which | |
10188 | don't provide fundamental types, gdb can create such types using this | |
10189 | function. | |
10190 | ||
10191 | FIXME: Some compilers distinguish explicitly signed integral types | |
10192 | (signed short, signed int, signed long) from "regular" integral types | |
10193 | (short, int, long) in the debugging information. There is some dis- | |
10194 | agreement as to how useful this feature is. In particular, gcc does | |
10195 | not support this. Also, only some debugging formats allow the | |
10196 | distinction to be passed on to a debugger. For now, we always just | |
10197 | use "short", "int", or "long" as the type name, for both the implicit | |
10198 | and explicitly signed types. This also makes life easier for the | |
10199 | gdb test suite since we don't have to account for the differences | |
10200 | in output depending upon what the compiler and debugging format | |
10201 | support. We will probably have to re-examine the issue when gdb | |
10202 | starts taking it's fundamental type information directly from the | |
10203 | debugging information supplied by the compiler. fnf@cygnus.com */ | |
10204 | ||
10205 | static struct type * | |
ebf56fd3 | 10206 | ada_create_fundamental_type (struct objfile *objfile, int typeid) |
14f9c5c9 AS |
10207 | { |
10208 | struct type *type = NULL; | |
10209 | ||
10210 | switch (typeid) | |
10211 | { | |
d2e4a39e AS |
10212 | default: |
10213 | /* FIXME: For now, if we are asked to produce a type not in this | |
10214 | language, create the equivalent of a C integer type with the | |
10215 | name "<?type?>". When all the dust settles from the type | |
4c4b4cd2 | 10216 | reconstruction work, this should probably become an error. */ |
d2e4a39e | 10217 | type = init_type (TYPE_CODE_INT, |
4c4b4cd2 PH |
10218 | TARGET_INT_BIT / TARGET_CHAR_BIT, |
10219 | 0, "<?type?>", objfile); | |
d2e4a39e AS |
10220 | warning ("internal error: no Ada fundamental type %d", typeid); |
10221 | break; | |
10222 | case FT_VOID: | |
10223 | type = init_type (TYPE_CODE_VOID, | |
4c4b4cd2 PH |
10224 | TARGET_CHAR_BIT / TARGET_CHAR_BIT, |
10225 | 0, "void", objfile); | |
d2e4a39e AS |
10226 | break; |
10227 | case FT_CHAR: | |
10228 | type = init_type (TYPE_CODE_INT, | |
4c4b4cd2 PH |
10229 | TARGET_CHAR_BIT / TARGET_CHAR_BIT, |
10230 | 0, "character", objfile); | |
d2e4a39e AS |
10231 | break; |
10232 | case FT_SIGNED_CHAR: | |
10233 | type = init_type (TYPE_CODE_INT, | |
4c4b4cd2 PH |
10234 | TARGET_CHAR_BIT / TARGET_CHAR_BIT, |
10235 | 0, "signed char", objfile); | |
d2e4a39e AS |
10236 | break; |
10237 | case FT_UNSIGNED_CHAR: | |
10238 | type = init_type (TYPE_CODE_INT, | |
4c4b4cd2 PH |
10239 | TARGET_CHAR_BIT / TARGET_CHAR_BIT, |
10240 | TYPE_FLAG_UNSIGNED, "unsigned char", objfile); | |
d2e4a39e AS |
10241 | break; |
10242 | case FT_SHORT: | |
10243 | type = init_type (TYPE_CODE_INT, | |
4c4b4cd2 PH |
10244 | TARGET_SHORT_BIT / TARGET_CHAR_BIT, |
10245 | 0, "short_integer", objfile); | |
d2e4a39e AS |
10246 | break; |
10247 | case FT_SIGNED_SHORT: | |
10248 | type = init_type (TYPE_CODE_INT, | |
4c4b4cd2 PH |
10249 | TARGET_SHORT_BIT / TARGET_CHAR_BIT, |
10250 | 0, "short_integer", objfile); | |
d2e4a39e AS |
10251 | break; |
10252 | case FT_UNSIGNED_SHORT: | |
10253 | type = init_type (TYPE_CODE_INT, | |
4c4b4cd2 PH |
10254 | TARGET_SHORT_BIT / TARGET_CHAR_BIT, |
10255 | TYPE_FLAG_UNSIGNED, "unsigned short", objfile); | |
d2e4a39e AS |
10256 | break; |
10257 | case FT_INTEGER: | |
10258 | type = init_type (TYPE_CODE_INT, | |
4c4b4cd2 PH |
10259 | TARGET_INT_BIT / TARGET_CHAR_BIT, |
10260 | 0, "integer", objfile); | |
d2e4a39e AS |
10261 | break; |
10262 | case FT_SIGNED_INTEGER: | |
4c4b4cd2 | 10263 | type = init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT, 0, "integer", objfile); /* FIXME -fnf */ |
d2e4a39e AS |
10264 | break; |
10265 | case FT_UNSIGNED_INTEGER: | |
10266 | type = init_type (TYPE_CODE_INT, | |
4c4b4cd2 PH |
10267 | TARGET_INT_BIT / TARGET_CHAR_BIT, |
10268 | TYPE_FLAG_UNSIGNED, "unsigned int", objfile); | |
d2e4a39e AS |
10269 | break; |
10270 | case FT_LONG: | |
10271 | type = init_type (TYPE_CODE_INT, | |
4c4b4cd2 PH |
10272 | TARGET_LONG_BIT / TARGET_CHAR_BIT, |
10273 | 0, "long_integer", objfile); | |
d2e4a39e AS |
10274 | break; |
10275 | case FT_SIGNED_LONG: | |
10276 | type = init_type (TYPE_CODE_INT, | |
4c4b4cd2 PH |
10277 | TARGET_LONG_BIT / TARGET_CHAR_BIT, |
10278 | 0, "long_integer", objfile); | |
d2e4a39e AS |
10279 | break; |
10280 | case FT_UNSIGNED_LONG: | |
10281 | type = init_type (TYPE_CODE_INT, | |
4c4b4cd2 PH |
10282 | TARGET_LONG_BIT / TARGET_CHAR_BIT, |
10283 | TYPE_FLAG_UNSIGNED, "unsigned long", objfile); | |
d2e4a39e AS |
10284 | break; |
10285 | case FT_LONG_LONG: | |
10286 | type = init_type (TYPE_CODE_INT, | |
4c4b4cd2 PH |
10287 | TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT, |
10288 | 0, "long_long_integer", objfile); | |
d2e4a39e AS |
10289 | break; |
10290 | case FT_SIGNED_LONG_LONG: | |
10291 | type = init_type (TYPE_CODE_INT, | |
4c4b4cd2 PH |
10292 | TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT, |
10293 | 0, "long_long_integer", objfile); | |
d2e4a39e AS |
10294 | break; |
10295 | case FT_UNSIGNED_LONG_LONG: | |
10296 | type = init_type (TYPE_CODE_INT, | |
4c4b4cd2 PH |
10297 | TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT, |
10298 | TYPE_FLAG_UNSIGNED, "unsigned long long", objfile); | |
d2e4a39e AS |
10299 | break; |
10300 | case FT_FLOAT: | |
10301 | type = init_type (TYPE_CODE_FLT, | |
4c4b4cd2 PH |
10302 | TARGET_FLOAT_BIT / TARGET_CHAR_BIT, |
10303 | 0, "float", objfile); | |
d2e4a39e AS |
10304 | break; |
10305 | case FT_DBL_PREC_FLOAT: | |
10306 | type = init_type (TYPE_CODE_FLT, | |
4c4b4cd2 PH |
10307 | TARGET_DOUBLE_BIT / TARGET_CHAR_BIT, |
10308 | 0, "long_float", objfile); | |
d2e4a39e AS |
10309 | break; |
10310 | case FT_EXT_PREC_FLOAT: | |
10311 | type = init_type (TYPE_CODE_FLT, | |
4c4b4cd2 PH |
10312 | TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT, |
10313 | 0, "long_long_float", objfile); | |
d2e4a39e AS |
10314 | break; |
10315 | } | |
14f9c5c9 AS |
10316 | return (type); |
10317 | } | |
10318 | ||
d2e4a39e AS |
10319 | void |
10320 | ada_dump_symtab (struct symtab *s) | |
14f9c5c9 AS |
10321 | { |
10322 | int i; | |
10323 | fprintf (stderr, "New symtab: [\n"); | |
d2e4a39e | 10324 | fprintf (stderr, " Name: %s/%s;\n", |
4c4b4cd2 | 10325 | s->dirname ? s->dirname : "?", s->filename ? s->filename : "?"); |
14f9c5c9 AS |
10326 | fprintf (stderr, " Format: %s;\n", s->debugformat); |
10327 | if (s->linetable != NULL) | |
10328 | { | |
10329 | fprintf (stderr, " Line table (section %d):\n", s->block_line_section); | |
10330 | for (i = 0; i < s->linetable->nitems; i += 1) | |
4c4b4cd2 PH |
10331 | { |
10332 | struct linetable_entry *e = s->linetable->item + i; | |
10333 | fprintf (stderr, " %4ld: %8lx\n", (long) e->line, (long) e->pc); | |
10334 | } | |
14f9c5c9 AS |
10335 | } |
10336 | fprintf (stderr, "]\n"); | |
10337 | } |