Commit | Line | Data |
---|---|---|
197e01b6 | 1 | /* Ada language support routines for GDB, the GNU debugger. Copyright (C) |
10a2c479 | 2 | |
f7f9143b JB |
3 | 1992, 1993, 1994, 1997, 1998, 1999, 2000, 2003, 2004, 2005, 2007 |
4 | Free Software Foundation, Inc. | |
14f9c5c9 AS |
5 | |
6 | This file is part of GDB. | |
7 | ||
8 | This program is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 2 of the License, or | |
11 | (at your option) any later version. | |
12 | ||
13 | This program is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with this program; if not, write to the Free Software | |
197e01b6 EZ |
20 | Foundation, Inc., 51 Franklin Street, Fifth Floor, |
21 | Boston, MA 02110-1301, USA. */ | |
14f9c5c9 | 22 | |
96d887e8 | 23 | |
4c4b4cd2 | 24 | #include "defs.h" |
14f9c5c9 | 25 | #include <stdio.h> |
0c30c098 | 26 | #include "gdb_string.h" |
14f9c5c9 AS |
27 | #include <ctype.h> |
28 | #include <stdarg.h> | |
29 | #include "demangle.h" | |
4c4b4cd2 PH |
30 | #include "gdb_regex.h" |
31 | #include "frame.h" | |
14f9c5c9 AS |
32 | #include "symtab.h" |
33 | #include "gdbtypes.h" | |
34 | #include "gdbcmd.h" | |
35 | #include "expression.h" | |
36 | #include "parser-defs.h" | |
37 | #include "language.h" | |
38 | #include "c-lang.h" | |
39 | #include "inferior.h" | |
40 | #include "symfile.h" | |
41 | #include "objfiles.h" | |
42 | #include "breakpoint.h" | |
43 | #include "gdbcore.h" | |
4c4b4cd2 PH |
44 | #include "hashtab.h" |
45 | #include "gdb_obstack.h" | |
14f9c5c9 | 46 | #include "ada-lang.h" |
4c4b4cd2 PH |
47 | #include "completer.h" |
48 | #include "gdb_stat.h" | |
49 | #ifdef UI_OUT | |
14f9c5c9 | 50 | #include "ui-out.h" |
4c4b4cd2 | 51 | #endif |
fe898f56 | 52 | #include "block.h" |
04714b91 | 53 | #include "infcall.h" |
de4f826b | 54 | #include "dictionary.h" |
60250e8b | 55 | #include "exceptions.h" |
f7f9143b JB |
56 | #include "annotate.h" |
57 | #include "valprint.h" | |
14f9c5c9 | 58 | |
4c4b4cd2 PH |
59 | #ifndef ADA_RETAIN_DOTS |
60 | #define ADA_RETAIN_DOTS 0 | |
61 | #endif | |
62 | ||
63 | /* Define whether or not the C operator '/' truncates towards zero for | |
64 | differently signed operands (truncation direction is undefined in C). | |
65 | Copied from valarith.c. */ | |
66 | ||
67 | #ifndef TRUNCATION_TOWARDS_ZERO | |
68 | #define TRUNCATION_TOWARDS_ZERO ((-5 / 2) == -2) | |
69 | #endif | |
70 | ||
4c4b4cd2 | 71 | |
4c4b4cd2 | 72 | static void extract_string (CORE_ADDR addr, char *buf); |
14f9c5c9 | 73 | |
d2e4a39e | 74 | static struct type *ada_create_fundamental_type (struct objfile *, int); |
14f9c5c9 AS |
75 | |
76 | static void modify_general_field (char *, LONGEST, int, int); | |
77 | ||
d2e4a39e | 78 | static struct type *desc_base_type (struct type *); |
14f9c5c9 | 79 | |
d2e4a39e | 80 | static struct type *desc_bounds_type (struct type *); |
14f9c5c9 | 81 | |
d2e4a39e | 82 | static struct value *desc_bounds (struct value *); |
14f9c5c9 | 83 | |
d2e4a39e | 84 | static int fat_pntr_bounds_bitpos (struct type *); |
14f9c5c9 | 85 | |
d2e4a39e | 86 | static int fat_pntr_bounds_bitsize (struct type *); |
14f9c5c9 | 87 | |
d2e4a39e | 88 | static struct type *desc_data_type (struct type *); |
14f9c5c9 | 89 | |
d2e4a39e | 90 | static struct value *desc_data (struct value *); |
14f9c5c9 | 91 | |
d2e4a39e | 92 | static int fat_pntr_data_bitpos (struct type *); |
14f9c5c9 | 93 | |
d2e4a39e | 94 | static int fat_pntr_data_bitsize (struct type *); |
14f9c5c9 | 95 | |
d2e4a39e | 96 | static struct value *desc_one_bound (struct value *, int, int); |
14f9c5c9 | 97 | |
d2e4a39e | 98 | static int desc_bound_bitpos (struct type *, int, int); |
14f9c5c9 | 99 | |
d2e4a39e | 100 | static int desc_bound_bitsize (struct type *, int, int); |
14f9c5c9 | 101 | |
d2e4a39e | 102 | static struct type *desc_index_type (struct type *, int); |
14f9c5c9 | 103 | |
d2e4a39e | 104 | static int desc_arity (struct type *); |
14f9c5c9 | 105 | |
d2e4a39e | 106 | static int ada_type_match (struct type *, struct type *, int); |
14f9c5c9 | 107 | |
d2e4a39e | 108 | static int ada_args_match (struct symbol *, struct value **, int); |
14f9c5c9 | 109 | |
4c4b4cd2 | 110 | static struct value *ensure_lval (struct value *, CORE_ADDR *); |
14f9c5c9 | 111 | |
d2e4a39e | 112 | static struct value *convert_actual (struct value *, struct type *, |
4c4b4cd2 | 113 | CORE_ADDR *); |
14f9c5c9 | 114 | |
d2e4a39e | 115 | static struct value *make_array_descriptor (struct type *, struct value *, |
4c4b4cd2 | 116 | CORE_ADDR *); |
14f9c5c9 | 117 | |
4c4b4cd2 | 118 | static void ada_add_block_symbols (struct obstack *, |
76a01679 | 119 | struct block *, const char *, |
4c4b4cd2 | 120 | domain_enum, struct objfile *, |
76a01679 | 121 | struct symtab *, int); |
14f9c5c9 | 122 | |
4c4b4cd2 | 123 | static int is_nonfunction (struct ada_symbol_info *, int); |
14f9c5c9 | 124 | |
76a01679 JB |
125 | static void add_defn_to_vec (struct obstack *, struct symbol *, |
126 | struct block *, struct symtab *); | |
14f9c5c9 | 127 | |
4c4b4cd2 PH |
128 | static int num_defns_collected (struct obstack *); |
129 | ||
130 | static struct ada_symbol_info *defns_collected (struct obstack *, int); | |
14f9c5c9 | 131 | |
d2e4a39e | 132 | static struct partial_symbol *ada_lookup_partial_symbol (struct partial_symtab |
76a01679 JB |
133 | *, const char *, int, |
134 | domain_enum, int); | |
14f9c5c9 | 135 | |
d2e4a39e | 136 | static struct symtab *symtab_for_sym (struct symbol *); |
14f9c5c9 | 137 | |
4c4b4cd2 | 138 | static struct value *resolve_subexp (struct expression **, int *, int, |
76a01679 | 139 | struct type *); |
14f9c5c9 | 140 | |
d2e4a39e | 141 | static void replace_operator_with_call (struct expression **, int, int, int, |
4c4b4cd2 | 142 | struct symbol *, struct block *); |
14f9c5c9 | 143 | |
d2e4a39e | 144 | static int possible_user_operator_p (enum exp_opcode, struct value **); |
14f9c5c9 | 145 | |
4c4b4cd2 PH |
146 | static char *ada_op_name (enum exp_opcode); |
147 | ||
148 | static const char *ada_decoded_op_name (enum exp_opcode); | |
14f9c5c9 | 149 | |
d2e4a39e | 150 | static int numeric_type_p (struct type *); |
14f9c5c9 | 151 | |
d2e4a39e | 152 | static int integer_type_p (struct type *); |
14f9c5c9 | 153 | |
d2e4a39e | 154 | static int scalar_type_p (struct type *); |
14f9c5c9 | 155 | |
d2e4a39e | 156 | static int discrete_type_p (struct type *); |
14f9c5c9 | 157 | |
4c4b4cd2 | 158 | static struct type *ada_lookup_struct_elt_type (struct type *, char *, |
76a01679 | 159 | int, int, int *); |
4c4b4cd2 | 160 | |
d2e4a39e | 161 | static struct value *evaluate_subexp (struct type *, struct expression *, |
4c4b4cd2 | 162 | int *, enum noside); |
14f9c5c9 | 163 | |
d2e4a39e | 164 | static struct value *evaluate_subexp_type (struct expression *, int *); |
14f9c5c9 | 165 | |
d2e4a39e | 166 | static int is_dynamic_field (struct type *, int); |
14f9c5c9 | 167 | |
10a2c479 | 168 | static struct type *to_fixed_variant_branch_type (struct type *, |
fc1a4b47 | 169 | const gdb_byte *, |
4c4b4cd2 PH |
170 | CORE_ADDR, struct value *); |
171 | ||
172 | static struct type *to_fixed_array_type (struct type *, struct value *, int); | |
14f9c5c9 | 173 | |
d2e4a39e | 174 | static struct type *to_fixed_range_type (char *, struct value *, |
4c4b4cd2 | 175 | struct objfile *); |
14f9c5c9 | 176 | |
d2e4a39e | 177 | static struct type *to_static_fixed_type (struct type *); |
14f9c5c9 | 178 | |
d2e4a39e | 179 | static struct value *unwrap_value (struct value *); |
14f9c5c9 | 180 | |
d2e4a39e | 181 | static struct type *packed_array_type (struct type *, long *); |
14f9c5c9 | 182 | |
d2e4a39e | 183 | static struct type *decode_packed_array_type (struct type *); |
14f9c5c9 | 184 | |
d2e4a39e | 185 | static struct value *decode_packed_array (struct value *); |
14f9c5c9 | 186 | |
d2e4a39e | 187 | static struct value *value_subscript_packed (struct value *, int, |
4c4b4cd2 | 188 | struct value **); |
14f9c5c9 | 189 | |
52ce6436 PH |
190 | static void move_bits (gdb_byte *, int, const gdb_byte *, int, int); |
191 | ||
4c4b4cd2 PH |
192 | static struct value *coerce_unspec_val_to_type (struct value *, |
193 | struct type *); | |
14f9c5c9 | 194 | |
d2e4a39e | 195 | static struct value *get_var_value (char *, char *); |
14f9c5c9 | 196 | |
d2e4a39e | 197 | static int lesseq_defined_than (struct symbol *, struct symbol *); |
14f9c5c9 | 198 | |
d2e4a39e | 199 | static int equiv_types (struct type *, struct type *); |
14f9c5c9 | 200 | |
d2e4a39e | 201 | static int is_name_suffix (const char *); |
14f9c5c9 | 202 | |
d2e4a39e | 203 | static int wild_match (const char *, int, const char *); |
14f9c5c9 | 204 | |
d2e4a39e | 205 | static struct value *ada_coerce_ref (struct value *); |
14f9c5c9 | 206 | |
4c4b4cd2 PH |
207 | static LONGEST pos_atr (struct value *); |
208 | ||
d2e4a39e | 209 | static struct value *value_pos_atr (struct value *); |
14f9c5c9 | 210 | |
d2e4a39e | 211 | static struct value *value_val_atr (struct type *, struct value *); |
14f9c5c9 | 212 | |
4c4b4cd2 PH |
213 | static struct symbol *standard_lookup (const char *, const struct block *, |
214 | domain_enum); | |
14f9c5c9 | 215 | |
4c4b4cd2 PH |
216 | static struct value *ada_search_struct_field (char *, struct value *, int, |
217 | struct type *); | |
218 | ||
219 | static struct value *ada_value_primitive_field (struct value *, int, int, | |
220 | struct type *); | |
221 | ||
76a01679 | 222 | static int find_struct_field (char *, struct type *, int, |
52ce6436 | 223 | struct type **, int *, int *, int *, int *); |
4c4b4cd2 PH |
224 | |
225 | static struct value *ada_to_fixed_value_create (struct type *, CORE_ADDR, | |
226 | struct value *); | |
227 | ||
228 | static struct value *ada_to_fixed_value (struct value *); | |
14f9c5c9 | 229 | |
4c4b4cd2 PH |
230 | static int ada_resolve_function (struct ada_symbol_info *, int, |
231 | struct value **, int, const char *, | |
232 | struct type *); | |
233 | ||
234 | static struct value *ada_coerce_to_simple_array (struct value *); | |
235 | ||
236 | static int ada_is_direct_array_type (struct type *); | |
237 | ||
72d5681a PH |
238 | static void ada_language_arch_info (struct gdbarch *, |
239 | struct language_arch_info *); | |
714e53ab PH |
240 | |
241 | static void check_size (const struct type *); | |
52ce6436 PH |
242 | |
243 | static struct value *ada_index_struct_field (int, struct value *, int, | |
244 | struct type *); | |
245 | ||
246 | static struct value *assign_aggregate (struct value *, struct value *, | |
247 | struct expression *, int *, enum noside); | |
248 | ||
249 | static void aggregate_assign_from_choices (struct value *, struct value *, | |
250 | struct expression *, | |
251 | int *, LONGEST *, int *, | |
252 | int, LONGEST, LONGEST); | |
253 | ||
254 | static void aggregate_assign_positional (struct value *, struct value *, | |
255 | struct expression *, | |
256 | int *, LONGEST *, int *, int, | |
257 | LONGEST, LONGEST); | |
258 | ||
259 | ||
260 | static void aggregate_assign_others (struct value *, struct value *, | |
261 | struct expression *, | |
262 | int *, LONGEST *, int, LONGEST, LONGEST); | |
263 | ||
264 | ||
265 | static void add_component_interval (LONGEST, LONGEST, LONGEST *, int *, int); | |
266 | ||
267 | ||
268 | static struct value *ada_evaluate_subexp (struct type *, struct expression *, | |
269 | int *, enum noside); | |
270 | ||
271 | static void ada_forward_operator_length (struct expression *, int, int *, | |
272 | int *); | |
4c4b4cd2 PH |
273 | \f |
274 | ||
76a01679 | 275 | |
4c4b4cd2 | 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 | 288 | /* The name of the symbol to use to get the name of the main subprogram. */ |
76a01679 | 289 | static const char ADA_MAIN_PROGRAM_SYMBOL_NAME[] |
4c4b4cd2 | 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 | ||
4c4b4cd2 PH |
304 | /* A string that reflects the longest exception expression rewrite, |
305 | aside from the exception name. */ | |
306 | static const char longest_exception_template[] = | |
307 | "'__gnat_raise_nodefer_with_msg' if long_integer(e) = long_integer(&)"; | |
308 | ||
309 | /* Limit on the number of warnings to raise per expression evaluation. */ | |
310 | static int warning_limit = 2; | |
311 | ||
312 | /* Number of warning messages issued; reset to 0 by cleanups after | |
313 | expression evaluation. */ | |
314 | static int warnings_issued = 0; | |
315 | ||
316 | static const char *known_runtime_file_name_patterns[] = { | |
317 | ADA_KNOWN_RUNTIME_FILE_NAME_PATTERNS NULL | |
318 | }; | |
319 | ||
320 | static const char *known_auxiliary_function_name_patterns[] = { | |
321 | ADA_KNOWN_AUXILIARY_FUNCTION_NAME_PATTERNS NULL | |
322 | }; | |
323 | ||
324 | /* Space for allocating results of ada_lookup_symbol_list. */ | |
325 | static struct obstack symbol_list_obstack; | |
326 | ||
327 | /* Utilities */ | |
328 | ||
96d887e8 | 329 | |
4c4b4cd2 PH |
330 | static char * |
331 | ada_get_gdb_completer_word_break_characters (void) | |
332 | { | |
333 | return ada_completer_word_break_characters; | |
334 | } | |
335 | ||
e79af960 JB |
336 | /* Print an array element index using the Ada syntax. */ |
337 | ||
338 | static void | |
339 | ada_print_array_index (struct value *index_value, struct ui_file *stream, | |
340 | int format, enum val_prettyprint pretty) | |
341 | { | |
342 | LA_VALUE_PRINT (index_value, stream, format, pretty); | |
343 | fprintf_filtered (stream, " => "); | |
344 | } | |
345 | ||
4c4b4cd2 PH |
346 | /* Read the string located at ADDR from the inferior and store the |
347 | result into BUF. */ | |
348 | ||
349 | static void | |
14f9c5c9 AS |
350 | extract_string (CORE_ADDR addr, char *buf) |
351 | { | |
d2e4a39e | 352 | int char_index = 0; |
14f9c5c9 | 353 | |
4c4b4cd2 PH |
354 | /* Loop, reading one byte at a time, until we reach the '\000' |
355 | end-of-string marker. */ | |
d2e4a39e AS |
356 | do |
357 | { | |
358 | target_read_memory (addr + char_index * sizeof (char), | |
4c4b4cd2 | 359 | buf + char_index * sizeof (char), sizeof (char)); |
d2e4a39e AS |
360 | char_index++; |
361 | } | |
362 | while (buf[char_index - 1] != '\000'); | |
14f9c5c9 AS |
363 | } |
364 | ||
f27cf670 | 365 | /* Assuming VECT points to an array of *SIZE objects of size |
14f9c5c9 | 366 | ELEMENT_SIZE, grow it to contain at least MIN_SIZE objects, |
f27cf670 | 367 | updating *SIZE as necessary and returning the (new) array. */ |
14f9c5c9 | 368 | |
f27cf670 AS |
369 | void * |
370 | grow_vect (void *vect, size_t *size, size_t min_size, int element_size) | |
14f9c5c9 | 371 | { |
d2e4a39e AS |
372 | if (*size < min_size) |
373 | { | |
374 | *size *= 2; | |
375 | if (*size < min_size) | |
4c4b4cd2 | 376 | *size = min_size; |
f27cf670 | 377 | vect = xrealloc (vect, *size * element_size); |
d2e4a39e | 378 | } |
f27cf670 | 379 | return vect; |
14f9c5c9 AS |
380 | } |
381 | ||
382 | /* True (non-zero) iff TARGET matches FIELD_NAME up to any trailing | |
4c4b4cd2 | 383 | suffix of FIELD_NAME beginning "___". */ |
14f9c5c9 AS |
384 | |
385 | static int | |
ebf56fd3 | 386 | field_name_match (const char *field_name, const char *target) |
14f9c5c9 AS |
387 | { |
388 | int len = strlen (target); | |
d2e4a39e | 389 | return |
4c4b4cd2 PH |
390 | (strncmp (field_name, target, len) == 0 |
391 | && (field_name[len] == '\0' | |
392 | || (strncmp (field_name + len, "___", 3) == 0 | |
76a01679 JB |
393 | && strcmp (field_name + strlen (field_name) - 6, |
394 | "___XVN") != 0))); | |
14f9c5c9 AS |
395 | } |
396 | ||
397 | ||
4c4b4cd2 PH |
398 | /* Assuming TYPE is a TYPE_CODE_STRUCT, find the field whose name matches |
399 | FIELD_NAME, and return its index. This function also handles fields | |
400 | whose name have ___ suffixes because the compiler sometimes alters | |
401 | their name by adding such a suffix to represent fields with certain | |
402 | constraints. If the field could not be found, return a negative | |
403 | number if MAYBE_MISSING is set. Otherwise raise an error. */ | |
404 | ||
405 | int | |
406 | ada_get_field_index (const struct type *type, const char *field_name, | |
407 | int maybe_missing) | |
408 | { | |
409 | int fieldno; | |
410 | for (fieldno = 0; fieldno < TYPE_NFIELDS (type); fieldno++) | |
411 | if (field_name_match (TYPE_FIELD_NAME (type, fieldno), field_name)) | |
412 | return fieldno; | |
413 | ||
414 | if (!maybe_missing) | |
323e0a4a | 415 | error (_("Unable to find field %s in struct %s. Aborting"), |
4c4b4cd2 PH |
416 | field_name, TYPE_NAME (type)); |
417 | ||
418 | return -1; | |
419 | } | |
420 | ||
421 | /* The length of the prefix of NAME prior to any "___" suffix. */ | |
14f9c5c9 AS |
422 | |
423 | int | |
d2e4a39e | 424 | ada_name_prefix_len (const char *name) |
14f9c5c9 AS |
425 | { |
426 | if (name == NULL) | |
427 | return 0; | |
d2e4a39e | 428 | else |
14f9c5c9 | 429 | { |
d2e4a39e | 430 | const char *p = strstr (name, "___"); |
14f9c5c9 | 431 | if (p == NULL) |
4c4b4cd2 | 432 | return strlen (name); |
14f9c5c9 | 433 | else |
4c4b4cd2 | 434 | return p - name; |
14f9c5c9 AS |
435 | } |
436 | } | |
437 | ||
4c4b4cd2 PH |
438 | /* Return non-zero if SUFFIX is a suffix of STR. |
439 | Return zero if STR is null. */ | |
440 | ||
14f9c5c9 | 441 | static int |
d2e4a39e | 442 | is_suffix (const char *str, const char *suffix) |
14f9c5c9 AS |
443 | { |
444 | int len1, len2; | |
445 | if (str == NULL) | |
446 | return 0; | |
447 | len1 = strlen (str); | |
448 | len2 = strlen (suffix); | |
4c4b4cd2 | 449 | return (len1 >= len2 && strcmp (str + len1 - len2, suffix) == 0); |
14f9c5c9 AS |
450 | } |
451 | ||
452 | /* Create a value of type TYPE whose contents come from VALADDR, if it | |
4c4b4cd2 PH |
453 | is non-null, and whose memory address (in the inferior) is |
454 | ADDRESS. */ | |
455 | ||
d2e4a39e | 456 | struct value * |
10a2c479 | 457 | value_from_contents_and_address (struct type *type, |
fc1a4b47 | 458 | const gdb_byte *valaddr, |
4c4b4cd2 | 459 | CORE_ADDR address) |
14f9c5c9 | 460 | { |
d2e4a39e AS |
461 | struct value *v = allocate_value (type); |
462 | if (valaddr == NULL) | |
dfa52d88 | 463 | set_value_lazy (v, 1); |
14f9c5c9 | 464 | else |
990a07ab | 465 | memcpy (value_contents_raw (v), valaddr, TYPE_LENGTH (type)); |
14f9c5c9 AS |
466 | VALUE_ADDRESS (v) = address; |
467 | if (address != 0) | |
468 | VALUE_LVAL (v) = lval_memory; | |
469 | return v; | |
470 | } | |
471 | ||
4c4b4cd2 PH |
472 | /* The contents of value VAL, treated as a value of type TYPE. The |
473 | result is an lval in memory if VAL is. */ | |
14f9c5c9 | 474 | |
d2e4a39e | 475 | static struct value * |
4c4b4cd2 | 476 | coerce_unspec_val_to_type (struct value *val, struct type *type) |
14f9c5c9 | 477 | { |
61ee279c | 478 | type = ada_check_typedef (type); |
df407dfe | 479 | if (value_type (val) == type) |
4c4b4cd2 | 480 | return val; |
d2e4a39e | 481 | else |
14f9c5c9 | 482 | { |
4c4b4cd2 PH |
483 | struct value *result; |
484 | ||
485 | /* Make sure that the object size is not unreasonable before | |
486 | trying to allocate some memory for it. */ | |
714e53ab | 487 | check_size (type); |
4c4b4cd2 PH |
488 | |
489 | result = allocate_value (type); | |
490 | VALUE_LVAL (result) = VALUE_LVAL (val); | |
9bbda503 AC |
491 | set_value_bitsize (result, value_bitsize (val)); |
492 | set_value_bitpos (result, value_bitpos (val)); | |
df407dfe | 493 | VALUE_ADDRESS (result) = VALUE_ADDRESS (val) + value_offset (val); |
d69fe07e | 494 | if (value_lazy (val) |
df407dfe | 495 | || TYPE_LENGTH (type) > TYPE_LENGTH (value_type (val))) |
dfa52d88 | 496 | set_value_lazy (result, 1); |
d2e4a39e | 497 | else |
0fd88904 | 498 | memcpy (value_contents_raw (result), value_contents (val), |
4c4b4cd2 | 499 | TYPE_LENGTH (type)); |
14f9c5c9 AS |
500 | return result; |
501 | } | |
502 | } | |
503 | ||
fc1a4b47 AC |
504 | static const gdb_byte * |
505 | cond_offset_host (const gdb_byte *valaddr, long offset) | |
14f9c5c9 AS |
506 | { |
507 | if (valaddr == NULL) | |
508 | return NULL; | |
509 | else | |
510 | return valaddr + offset; | |
511 | } | |
512 | ||
513 | static CORE_ADDR | |
ebf56fd3 | 514 | cond_offset_target (CORE_ADDR address, long offset) |
14f9c5c9 AS |
515 | { |
516 | if (address == 0) | |
517 | return 0; | |
d2e4a39e | 518 | else |
14f9c5c9 AS |
519 | return address + offset; |
520 | } | |
521 | ||
4c4b4cd2 PH |
522 | /* Issue a warning (as for the definition of warning in utils.c, but |
523 | with exactly one argument rather than ...), unless the limit on the | |
524 | number of warnings has passed during the evaluation of the current | |
525 | expression. */ | |
a2249542 | 526 | |
77109804 AC |
527 | /* FIXME: cagney/2004-10-10: This function is mimicking the behavior |
528 | provided by "complaint". */ | |
529 | static void lim_warning (const char *format, ...) ATTR_FORMAT (printf, 1, 2); | |
530 | ||
14f9c5c9 | 531 | static void |
a2249542 | 532 | lim_warning (const char *format, ...) |
14f9c5c9 | 533 | { |
a2249542 MK |
534 | va_list args; |
535 | va_start (args, format); | |
536 | ||
4c4b4cd2 PH |
537 | warnings_issued += 1; |
538 | if (warnings_issued <= warning_limit) | |
a2249542 MK |
539 | vwarning (format, args); |
540 | ||
541 | va_end (args); | |
4c4b4cd2 PH |
542 | } |
543 | ||
714e53ab PH |
544 | /* Issue an error if the size of an object of type T is unreasonable, |
545 | i.e. if it would be a bad idea to allocate a value of this type in | |
546 | GDB. */ | |
547 | ||
548 | static void | |
549 | check_size (const struct type *type) | |
550 | { | |
551 | if (TYPE_LENGTH (type) > varsize_limit) | |
323e0a4a | 552 | error (_("object size is larger than varsize-limit")); |
714e53ab PH |
553 | } |
554 | ||
555 | ||
c3e5cd34 PH |
556 | /* Note: would have used MAX_OF_TYPE and MIN_OF_TYPE macros from |
557 | gdbtypes.h, but some of the necessary definitions in that file | |
558 | seem to have gone missing. */ | |
559 | ||
560 | /* Maximum value of a SIZE-byte signed integer type. */ | |
4c4b4cd2 | 561 | static LONGEST |
c3e5cd34 | 562 | max_of_size (int size) |
4c4b4cd2 | 563 | { |
76a01679 JB |
564 | LONGEST top_bit = (LONGEST) 1 << (size * 8 - 2); |
565 | return top_bit | (top_bit - 1); | |
4c4b4cd2 PH |
566 | } |
567 | ||
c3e5cd34 | 568 | /* Minimum value of a SIZE-byte signed integer type. */ |
4c4b4cd2 | 569 | static LONGEST |
c3e5cd34 | 570 | min_of_size (int size) |
4c4b4cd2 | 571 | { |
c3e5cd34 | 572 | return -max_of_size (size) - 1; |
4c4b4cd2 PH |
573 | } |
574 | ||
c3e5cd34 | 575 | /* Maximum value of a SIZE-byte unsigned integer type. */ |
4c4b4cd2 | 576 | static ULONGEST |
c3e5cd34 | 577 | umax_of_size (int size) |
4c4b4cd2 | 578 | { |
76a01679 JB |
579 | ULONGEST top_bit = (ULONGEST) 1 << (size * 8 - 1); |
580 | return top_bit | (top_bit - 1); | |
4c4b4cd2 PH |
581 | } |
582 | ||
c3e5cd34 PH |
583 | /* Maximum value of integral type T, as a signed quantity. */ |
584 | static LONGEST | |
585 | max_of_type (struct type *t) | |
4c4b4cd2 | 586 | { |
c3e5cd34 PH |
587 | if (TYPE_UNSIGNED (t)) |
588 | return (LONGEST) umax_of_size (TYPE_LENGTH (t)); | |
589 | else | |
590 | return max_of_size (TYPE_LENGTH (t)); | |
591 | } | |
592 | ||
593 | /* Minimum value of integral type T, as a signed quantity. */ | |
594 | static LONGEST | |
595 | min_of_type (struct type *t) | |
596 | { | |
597 | if (TYPE_UNSIGNED (t)) | |
598 | return 0; | |
599 | else | |
600 | return min_of_size (TYPE_LENGTH (t)); | |
4c4b4cd2 PH |
601 | } |
602 | ||
603 | /* The largest value in the domain of TYPE, a discrete type, as an integer. */ | |
604 | static struct value * | |
605 | discrete_type_high_bound (struct type *type) | |
606 | { | |
76a01679 | 607 | switch (TYPE_CODE (type)) |
4c4b4cd2 PH |
608 | { |
609 | case TYPE_CODE_RANGE: | |
610 | return value_from_longest (TYPE_TARGET_TYPE (type), | |
76a01679 | 611 | TYPE_HIGH_BOUND (type)); |
4c4b4cd2 | 612 | case TYPE_CODE_ENUM: |
76a01679 JB |
613 | return |
614 | value_from_longest (type, | |
615 | TYPE_FIELD_BITPOS (type, | |
616 | TYPE_NFIELDS (type) - 1)); | |
617 | case TYPE_CODE_INT: | |
c3e5cd34 | 618 | return value_from_longest (type, max_of_type (type)); |
4c4b4cd2 | 619 | default: |
323e0a4a | 620 | error (_("Unexpected type in discrete_type_high_bound.")); |
4c4b4cd2 PH |
621 | } |
622 | } | |
623 | ||
624 | /* The largest value in the domain of TYPE, a discrete type, as an integer. */ | |
625 | static struct value * | |
626 | discrete_type_low_bound (struct type *type) | |
627 | { | |
76a01679 | 628 | switch (TYPE_CODE (type)) |
4c4b4cd2 PH |
629 | { |
630 | case TYPE_CODE_RANGE: | |
631 | return value_from_longest (TYPE_TARGET_TYPE (type), | |
76a01679 | 632 | TYPE_LOW_BOUND (type)); |
4c4b4cd2 | 633 | case TYPE_CODE_ENUM: |
76a01679 JB |
634 | return value_from_longest (type, TYPE_FIELD_BITPOS (type, 0)); |
635 | case TYPE_CODE_INT: | |
c3e5cd34 | 636 | return value_from_longest (type, min_of_type (type)); |
4c4b4cd2 | 637 | default: |
323e0a4a | 638 | error (_("Unexpected type in discrete_type_low_bound.")); |
4c4b4cd2 PH |
639 | } |
640 | } | |
641 | ||
642 | /* The identity on non-range types. For range types, the underlying | |
76a01679 | 643 | non-range scalar type. */ |
4c4b4cd2 PH |
644 | |
645 | static struct type * | |
646 | base_type (struct type *type) | |
647 | { | |
648 | while (type != NULL && TYPE_CODE (type) == TYPE_CODE_RANGE) | |
649 | { | |
76a01679 JB |
650 | if (type == TYPE_TARGET_TYPE (type) || TYPE_TARGET_TYPE (type) == NULL) |
651 | return type; | |
4c4b4cd2 PH |
652 | type = TYPE_TARGET_TYPE (type); |
653 | } | |
654 | return type; | |
14f9c5c9 | 655 | } |
4c4b4cd2 | 656 | \f |
76a01679 | 657 | |
4c4b4cd2 | 658 | /* Language Selection */ |
14f9c5c9 AS |
659 | |
660 | /* If the main program is in Ada, return language_ada, otherwise return LANG | |
661 | (the main program is in Ada iif the adainit symbol is found). | |
662 | ||
4c4b4cd2 | 663 | MAIN_PST is not used. */ |
d2e4a39e | 664 | |
14f9c5c9 | 665 | enum language |
d2e4a39e | 666 | ada_update_initial_language (enum language lang, |
4c4b4cd2 | 667 | struct partial_symtab *main_pst) |
14f9c5c9 | 668 | { |
d2e4a39e | 669 | if (lookup_minimal_symbol ("adainit", (const char *) NULL, |
4c4b4cd2 PH |
670 | (struct objfile *) NULL) != NULL) |
671 | return language_ada; | |
14f9c5c9 AS |
672 | |
673 | return lang; | |
674 | } | |
96d887e8 PH |
675 | |
676 | /* If the main procedure is written in Ada, then return its name. | |
677 | The result is good until the next call. Return NULL if the main | |
678 | procedure doesn't appear to be in Ada. */ | |
679 | ||
680 | char * | |
681 | ada_main_name (void) | |
682 | { | |
683 | struct minimal_symbol *msym; | |
684 | CORE_ADDR main_program_name_addr; | |
685 | static char main_program_name[1024]; | |
6c038f32 | 686 | |
96d887e8 PH |
687 | /* For Ada, the name of the main procedure is stored in a specific |
688 | string constant, generated by the binder. Look for that symbol, | |
689 | extract its address, and then read that string. If we didn't find | |
690 | that string, then most probably the main procedure is not written | |
691 | in Ada. */ | |
692 | msym = lookup_minimal_symbol (ADA_MAIN_PROGRAM_SYMBOL_NAME, NULL, NULL); | |
693 | ||
694 | if (msym != NULL) | |
695 | { | |
696 | main_program_name_addr = SYMBOL_VALUE_ADDRESS (msym); | |
697 | if (main_program_name_addr == 0) | |
323e0a4a | 698 | error (_("Invalid address for Ada main program name.")); |
96d887e8 PH |
699 | |
700 | extract_string (main_program_name_addr, main_program_name); | |
701 | return main_program_name; | |
702 | } | |
703 | ||
704 | /* The main procedure doesn't seem to be in Ada. */ | |
705 | return NULL; | |
706 | } | |
14f9c5c9 | 707 | \f |
4c4b4cd2 | 708 | /* Symbols */ |
d2e4a39e | 709 | |
4c4b4cd2 PH |
710 | /* Table of Ada operators and their GNAT-encoded names. Last entry is pair |
711 | of NULLs. */ | |
14f9c5c9 | 712 | |
d2e4a39e AS |
713 | const struct ada_opname_map ada_opname_table[] = { |
714 | {"Oadd", "\"+\"", BINOP_ADD}, | |
715 | {"Osubtract", "\"-\"", BINOP_SUB}, | |
716 | {"Omultiply", "\"*\"", BINOP_MUL}, | |
717 | {"Odivide", "\"/\"", BINOP_DIV}, | |
718 | {"Omod", "\"mod\"", BINOP_MOD}, | |
719 | {"Orem", "\"rem\"", BINOP_REM}, | |
720 | {"Oexpon", "\"**\"", BINOP_EXP}, | |
721 | {"Olt", "\"<\"", BINOP_LESS}, | |
722 | {"Ole", "\"<=\"", BINOP_LEQ}, | |
723 | {"Ogt", "\">\"", BINOP_GTR}, | |
724 | {"Oge", "\">=\"", BINOP_GEQ}, | |
725 | {"Oeq", "\"=\"", BINOP_EQUAL}, | |
726 | {"One", "\"/=\"", BINOP_NOTEQUAL}, | |
727 | {"Oand", "\"and\"", BINOP_BITWISE_AND}, | |
728 | {"Oor", "\"or\"", BINOP_BITWISE_IOR}, | |
729 | {"Oxor", "\"xor\"", BINOP_BITWISE_XOR}, | |
730 | {"Oconcat", "\"&\"", BINOP_CONCAT}, | |
731 | {"Oabs", "\"abs\"", UNOP_ABS}, | |
732 | {"Onot", "\"not\"", UNOP_LOGICAL_NOT}, | |
733 | {"Oadd", "\"+\"", UNOP_PLUS}, | |
734 | {"Osubtract", "\"-\"", UNOP_NEG}, | |
735 | {NULL, NULL} | |
14f9c5c9 AS |
736 | }; |
737 | ||
4c4b4cd2 PH |
738 | /* Return non-zero if STR should be suppressed in info listings. */ |
739 | ||
14f9c5c9 | 740 | static int |
d2e4a39e | 741 | is_suppressed_name (const char *str) |
14f9c5c9 | 742 | { |
4c4b4cd2 | 743 | if (strncmp (str, "_ada_", 5) == 0) |
14f9c5c9 AS |
744 | str += 5; |
745 | if (str[0] == '_' || str[0] == '\000') | |
746 | return 1; | |
747 | else | |
748 | { | |
d2e4a39e AS |
749 | const char *p; |
750 | const char *suffix = strstr (str, "___"); | |
14f9c5c9 | 751 | if (suffix != NULL && suffix[3] != 'X') |
4c4b4cd2 | 752 | return 1; |
14f9c5c9 | 753 | if (suffix == NULL) |
4c4b4cd2 | 754 | suffix = str + strlen (str); |
d2e4a39e | 755 | for (p = suffix - 1; p != str; p -= 1) |
4c4b4cd2 PH |
756 | if (isupper (*p)) |
757 | { | |
758 | int i; | |
759 | if (p[0] == 'X' && p[-1] != '_') | |
760 | goto OK; | |
761 | if (*p != 'O') | |
762 | return 1; | |
763 | for (i = 0; ada_opname_table[i].encoded != NULL; i += 1) | |
764 | if (strncmp (ada_opname_table[i].encoded, p, | |
765 | strlen (ada_opname_table[i].encoded)) == 0) | |
766 | goto OK; | |
767 | return 1; | |
768 | OK:; | |
769 | } | |
14f9c5c9 AS |
770 | return 0; |
771 | } | |
772 | } | |
773 | ||
4c4b4cd2 PH |
774 | /* The "encoded" form of DECODED, according to GNAT conventions. |
775 | The result is valid until the next call to ada_encode. */ | |
776 | ||
14f9c5c9 | 777 | char * |
4c4b4cd2 | 778 | ada_encode (const char *decoded) |
14f9c5c9 | 779 | { |
4c4b4cd2 PH |
780 | static char *encoding_buffer = NULL; |
781 | static size_t encoding_buffer_size = 0; | |
d2e4a39e | 782 | const char *p; |
14f9c5c9 | 783 | int k; |
d2e4a39e | 784 | |
4c4b4cd2 | 785 | if (decoded == NULL) |
14f9c5c9 AS |
786 | return NULL; |
787 | ||
4c4b4cd2 PH |
788 | GROW_VECT (encoding_buffer, encoding_buffer_size, |
789 | 2 * strlen (decoded) + 10); | |
14f9c5c9 AS |
790 | |
791 | k = 0; | |
4c4b4cd2 | 792 | for (p = decoded; *p != '\0'; p += 1) |
14f9c5c9 | 793 | { |
4c4b4cd2 PH |
794 | if (!ADA_RETAIN_DOTS && *p == '.') |
795 | { | |
796 | encoding_buffer[k] = encoding_buffer[k + 1] = '_'; | |
797 | k += 2; | |
798 | } | |
14f9c5c9 | 799 | else if (*p == '"') |
4c4b4cd2 PH |
800 | { |
801 | const struct ada_opname_map *mapping; | |
802 | ||
803 | for (mapping = ada_opname_table; | |
1265e4aa JB |
804 | mapping->encoded != NULL |
805 | && strncmp (mapping->decoded, p, | |
806 | strlen (mapping->decoded)) != 0; mapping += 1) | |
4c4b4cd2 PH |
807 | ; |
808 | if (mapping->encoded == NULL) | |
323e0a4a | 809 | error (_("invalid Ada operator name: %s"), p); |
4c4b4cd2 PH |
810 | strcpy (encoding_buffer + k, mapping->encoded); |
811 | k += strlen (mapping->encoded); | |
812 | break; | |
813 | } | |
d2e4a39e | 814 | else |
4c4b4cd2 PH |
815 | { |
816 | encoding_buffer[k] = *p; | |
817 | k += 1; | |
818 | } | |
14f9c5c9 AS |
819 | } |
820 | ||
4c4b4cd2 PH |
821 | encoding_buffer[k] = '\0'; |
822 | return encoding_buffer; | |
14f9c5c9 AS |
823 | } |
824 | ||
825 | /* Return NAME folded to lower case, or, if surrounded by single | |
4c4b4cd2 PH |
826 | quotes, unfolded, but with the quotes stripped away. Result good |
827 | to next call. */ | |
828 | ||
d2e4a39e AS |
829 | char * |
830 | ada_fold_name (const char *name) | |
14f9c5c9 | 831 | { |
d2e4a39e | 832 | static char *fold_buffer = NULL; |
14f9c5c9 AS |
833 | static size_t fold_buffer_size = 0; |
834 | ||
835 | int len = strlen (name); | |
d2e4a39e | 836 | GROW_VECT (fold_buffer, fold_buffer_size, len + 1); |
14f9c5c9 AS |
837 | |
838 | if (name[0] == '\'') | |
839 | { | |
d2e4a39e AS |
840 | strncpy (fold_buffer, name + 1, len - 2); |
841 | fold_buffer[len - 2] = '\000'; | |
14f9c5c9 AS |
842 | } |
843 | else | |
844 | { | |
845 | int i; | |
846 | for (i = 0; i <= len; i += 1) | |
4c4b4cd2 | 847 | fold_buffer[i] = tolower (name[i]); |
14f9c5c9 AS |
848 | } |
849 | ||
850 | return fold_buffer; | |
851 | } | |
852 | ||
529cad9c PH |
853 | /* Return nonzero if C is either a digit or a lowercase alphabet character. */ |
854 | ||
855 | static int | |
856 | is_lower_alphanum (const char c) | |
857 | { | |
858 | return (isdigit (c) || (isalpha (c) && islower (c))); | |
859 | } | |
860 | ||
861 | /* Decode: | |
862 | . Discard trailing .{DIGIT}+, ${DIGIT}+ or ___{DIGIT}+ | |
4c4b4cd2 PH |
863 | These are suffixes introduced by GNAT5 to nested subprogram |
864 | names, and do not serve any purpose for the debugger. | |
529cad9c PH |
865 | . Discard final __{DIGIT}+ or $({DIGIT}+(__{DIGIT}+)*) |
866 | . Discard final N if it follows a lowercase alphanumeric character | |
867 | (protected object subprogram suffix) | |
868 | . Convert other instances of embedded "__" to `.'. | |
869 | . Discard leading _ada_. | |
870 | . Convert operator names to the appropriate quoted symbols. | |
871 | . Remove everything after first ___ if it is followed by | |
14f9c5c9 | 872 | 'X'. |
529cad9c PH |
873 | . Replace TK__ with __, and a trailing B or TKB with nothing. |
874 | . Replace _[EB]{DIGIT}+[sb] with nothing (protected object entries) | |
875 | . Put symbols that should be suppressed in <...> brackets. | |
876 | . Remove trailing X[bn]* suffix (indicating names in package bodies). | |
14f9c5c9 | 877 | |
4c4b4cd2 PH |
878 | The resulting string is valid until the next call of ada_decode. |
879 | If the string is unchanged by demangling, the original string pointer | |
880 | is returned. */ | |
881 | ||
882 | const char * | |
883 | ada_decode (const char *encoded) | |
14f9c5c9 AS |
884 | { |
885 | int i, j; | |
886 | int len0; | |
d2e4a39e | 887 | const char *p; |
4c4b4cd2 | 888 | char *decoded; |
14f9c5c9 | 889 | int at_start_name; |
4c4b4cd2 PH |
890 | static char *decoding_buffer = NULL; |
891 | static size_t decoding_buffer_size = 0; | |
d2e4a39e | 892 | |
4c4b4cd2 PH |
893 | if (strncmp (encoded, "_ada_", 5) == 0) |
894 | encoded += 5; | |
14f9c5c9 | 895 | |
4c4b4cd2 | 896 | if (encoded[0] == '_' || encoded[0] == '<') |
14f9c5c9 AS |
897 | goto Suppress; |
898 | ||
529cad9c | 899 | /* Remove trailing .{DIGIT}+ or ___{DIGIT}+ or __{DIGIT}+. */ |
4c4b4cd2 PH |
900 | len0 = strlen (encoded); |
901 | if (len0 > 1 && isdigit (encoded[len0 - 1])) | |
902 | { | |
903 | i = len0 - 2; | |
904 | while (i > 0 && isdigit (encoded[i])) | |
905 | i--; | |
906 | if (i >= 0 && encoded[i] == '.') | |
907 | len0 = i; | |
529cad9c PH |
908 | else if (i >= 0 && encoded[i] == '$') |
909 | len0 = i; | |
4c4b4cd2 PH |
910 | else if (i >= 2 && strncmp (encoded + i - 2, "___", 3) == 0) |
911 | len0 = i - 2; | |
529cad9c PH |
912 | else if (i >= 1 && strncmp (encoded + i - 1, "__", 2) == 0) |
913 | len0 = i - 1; | |
4c4b4cd2 PH |
914 | } |
915 | ||
529cad9c PH |
916 | /* Remove trailing N. */ |
917 | ||
918 | /* Protected entry subprograms are broken into two | |
919 | separate subprograms: The first one is unprotected, and has | |
920 | a 'N' suffix; the second is the protected version, and has | |
921 | the 'P' suffix. The second calls the first one after handling | |
922 | the protection. Since the P subprograms are internally generated, | |
923 | we leave these names undecoded, giving the user a clue that this | |
924 | entity is internal. */ | |
925 | ||
926 | if (len0 > 1 | |
927 | && encoded[len0 - 1] == 'N' | |
928 | && (isdigit (encoded[len0 - 2]) || islower (encoded[len0 - 2]))) | |
929 | len0--; | |
930 | ||
4c4b4cd2 PH |
931 | /* Remove the ___X.* suffix if present. Do not forget to verify that |
932 | the suffix is located before the current "end" of ENCODED. We want | |
933 | to avoid re-matching parts of ENCODED that have previously been | |
934 | marked as discarded (by decrementing LEN0). */ | |
935 | p = strstr (encoded, "___"); | |
936 | if (p != NULL && p - encoded < len0 - 3) | |
14f9c5c9 AS |
937 | { |
938 | if (p[3] == 'X') | |
4c4b4cd2 | 939 | len0 = p - encoded; |
14f9c5c9 | 940 | else |
4c4b4cd2 | 941 | goto Suppress; |
14f9c5c9 | 942 | } |
4c4b4cd2 PH |
943 | |
944 | if (len0 > 3 && strncmp (encoded + len0 - 3, "TKB", 3) == 0) | |
14f9c5c9 | 945 | len0 -= 3; |
76a01679 | 946 | |
4c4b4cd2 | 947 | if (len0 > 1 && strncmp (encoded + len0 - 1, "B", 1) == 0) |
14f9c5c9 AS |
948 | len0 -= 1; |
949 | ||
4c4b4cd2 PH |
950 | /* Make decoded big enough for possible expansion by operator name. */ |
951 | GROW_VECT (decoding_buffer, decoding_buffer_size, 2 * len0 + 1); | |
952 | decoded = decoding_buffer; | |
14f9c5c9 | 953 | |
4c4b4cd2 | 954 | if (len0 > 1 && isdigit (encoded[len0 - 1])) |
d2e4a39e | 955 | { |
4c4b4cd2 PH |
956 | i = len0 - 2; |
957 | while ((i >= 0 && isdigit (encoded[i])) | |
958 | || (i >= 1 && encoded[i] == '_' && isdigit (encoded[i - 1]))) | |
959 | i -= 1; | |
960 | if (i > 1 && encoded[i] == '_' && encoded[i - 1] == '_') | |
961 | len0 = i - 1; | |
962 | else if (encoded[i] == '$') | |
963 | len0 = i; | |
d2e4a39e | 964 | } |
14f9c5c9 | 965 | |
4c4b4cd2 PH |
966 | for (i = 0, j = 0; i < len0 && !isalpha (encoded[i]); i += 1, j += 1) |
967 | decoded[j] = encoded[i]; | |
14f9c5c9 AS |
968 | |
969 | at_start_name = 1; | |
970 | while (i < len0) | |
971 | { | |
4c4b4cd2 PH |
972 | if (at_start_name && encoded[i] == 'O') |
973 | { | |
974 | int k; | |
975 | for (k = 0; ada_opname_table[k].encoded != NULL; k += 1) | |
976 | { | |
977 | int op_len = strlen (ada_opname_table[k].encoded); | |
06d5cf63 JB |
978 | if ((strncmp (ada_opname_table[k].encoded + 1, encoded + i + 1, |
979 | op_len - 1) == 0) | |
980 | && !isalnum (encoded[i + op_len])) | |
4c4b4cd2 PH |
981 | { |
982 | strcpy (decoded + j, ada_opname_table[k].decoded); | |
983 | at_start_name = 0; | |
984 | i += op_len; | |
985 | j += strlen (ada_opname_table[k].decoded); | |
986 | break; | |
987 | } | |
988 | } | |
989 | if (ada_opname_table[k].encoded != NULL) | |
990 | continue; | |
991 | } | |
14f9c5c9 AS |
992 | at_start_name = 0; |
993 | ||
529cad9c PH |
994 | /* Replace "TK__" with "__", which will eventually be translated |
995 | into "." (just below). */ | |
996 | ||
4c4b4cd2 PH |
997 | if (i < len0 - 4 && strncmp (encoded + i, "TK__", 4) == 0) |
998 | i += 2; | |
529cad9c PH |
999 | |
1000 | /* Remove _E{DIGITS}+[sb] */ | |
1001 | ||
1002 | /* Just as for protected object subprograms, there are 2 categories | |
1003 | of subprograms created by the compiler for each entry. The first | |
1004 | one implements the actual entry code, and has a suffix following | |
1005 | the convention above; the second one implements the barrier and | |
1006 | uses the same convention as above, except that the 'E' is replaced | |
1007 | by a 'B'. | |
1008 | ||
1009 | Just as above, we do not decode the name of barrier functions | |
1010 | to give the user a clue that the code he is debugging has been | |
1011 | internally generated. */ | |
1012 | ||
1013 | if (len0 - i > 3 && encoded [i] == '_' && encoded[i+1] == 'E' | |
1014 | && isdigit (encoded[i+2])) | |
1015 | { | |
1016 | int k = i + 3; | |
1017 | ||
1018 | while (k < len0 && isdigit (encoded[k])) | |
1019 | k++; | |
1020 | ||
1021 | if (k < len0 | |
1022 | && (encoded[k] == 'b' || encoded[k] == 's')) | |
1023 | { | |
1024 | k++; | |
1025 | /* Just as an extra precaution, make sure that if this | |
1026 | suffix is followed by anything else, it is a '_'. | |
1027 | Otherwise, we matched this sequence by accident. */ | |
1028 | if (k == len0 | |
1029 | || (k < len0 && encoded[k] == '_')) | |
1030 | i = k; | |
1031 | } | |
1032 | } | |
1033 | ||
1034 | /* Remove trailing "N" in [a-z0-9]+N__. The N is added by | |
1035 | the GNAT front-end in protected object subprograms. */ | |
1036 | ||
1037 | if (i < len0 + 3 | |
1038 | && encoded[i] == 'N' && encoded[i+1] == '_' && encoded[i+2] == '_') | |
1039 | { | |
1040 | /* Backtrack a bit up until we reach either the begining of | |
1041 | the encoded name, or "__". Make sure that we only find | |
1042 | digits or lowercase characters. */ | |
1043 | const char *ptr = encoded + i - 1; | |
1044 | ||
1045 | while (ptr >= encoded && is_lower_alphanum (ptr[0])) | |
1046 | ptr--; | |
1047 | if (ptr < encoded | |
1048 | || (ptr > encoded && ptr[0] == '_' && ptr[-1] == '_')) | |
1049 | i++; | |
1050 | } | |
1051 | ||
4c4b4cd2 PH |
1052 | if (encoded[i] == 'X' && i != 0 && isalnum (encoded[i - 1])) |
1053 | { | |
1054 | do | |
1055 | i += 1; | |
1056 | while (i < len0 && (encoded[i] == 'b' || encoded[i] == 'n')); | |
1057 | if (i < len0) | |
1058 | goto Suppress; | |
1059 | } | |
1060 | else if (!ADA_RETAIN_DOTS | |
1061 | && i < len0 - 2 && encoded[i] == '_' && encoded[i + 1] == '_') | |
1062 | { | |
1063 | decoded[j] = '.'; | |
1064 | at_start_name = 1; | |
1065 | i += 2; | |
1066 | j += 1; | |
1067 | } | |
14f9c5c9 | 1068 | else |
4c4b4cd2 PH |
1069 | { |
1070 | decoded[j] = encoded[i]; | |
1071 | i += 1; | |
1072 | j += 1; | |
1073 | } | |
14f9c5c9 | 1074 | } |
4c4b4cd2 | 1075 | decoded[j] = '\000'; |
14f9c5c9 | 1076 | |
4c4b4cd2 PH |
1077 | for (i = 0; decoded[i] != '\0'; i += 1) |
1078 | if (isupper (decoded[i]) || decoded[i] == ' ') | |
14f9c5c9 AS |
1079 | goto Suppress; |
1080 | ||
4c4b4cd2 PH |
1081 | if (strcmp (decoded, encoded) == 0) |
1082 | return encoded; | |
1083 | else | |
1084 | return decoded; | |
14f9c5c9 AS |
1085 | |
1086 | Suppress: | |
4c4b4cd2 PH |
1087 | GROW_VECT (decoding_buffer, decoding_buffer_size, strlen (encoded) + 3); |
1088 | decoded = decoding_buffer; | |
1089 | if (encoded[0] == '<') | |
1090 | strcpy (decoded, encoded); | |
14f9c5c9 | 1091 | else |
4c4b4cd2 PH |
1092 | sprintf (decoded, "<%s>", encoded); |
1093 | return decoded; | |
1094 | ||
1095 | } | |
1096 | ||
1097 | /* Table for keeping permanent unique copies of decoded names. Once | |
1098 | allocated, names in this table are never released. While this is a | |
1099 | storage leak, it should not be significant unless there are massive | |
1100 | changes in the set of decoded names in successive versions of a | |
1101 | symbol table loaded during a single session. */ | |
1102 | static struct htab *decoded_names_store; | |
1103 | ||
1104 | /* Returns the decoded name of GSYMBOL, as for ada_decode, caching it | |
1105 | in the language-specific part of GSYMBOL, if it has not been | |
1106 | previously computed. Tries to save the decoded name in the same | |
1107 | obstack as GSYMBOL, if possible, and otherwise on the heap (so that, | |
1108 | in any case, the decoded symbol has a lifetime at least that of | |
1109 | GSYMBOL). | |
1110 | The GSYMBOL parameter is "mutable" in the C++ sense: logically | |
1111 | const, but nevertheless modified to a semantically equivalent form | |
1112 | when a decoded name is cached in it. | |
76a01679 | 1113 | */ |
4c4b4cd2 | 1114 | |
76a01679 JB |
1115 | char * |
1116 | ada_decode_symbol (const struct general_symbol_info *gsymbol) | |
4c4b4cd2 | 1117 | { |
76a01679 | 1118 | char **resultp = |
4c4b4cd2 PH |
1119 | (char **) &gsymbol->language_specific.cplus_specific.demangled_name; |
1120 | if (*resultp == NULL) | |
1121 | { | |
1122 | const char *decoded = ada_decode (gsymbol->name); | |
1123 | if (gsymbol->bfd_section != NULL) | |
76a01679 JB |
1124 | { |
1125 | bfd *obfd = gsymbol->bfd_section->owner; | |
1126 | if (obfd != NULL) | |
1127 | { | |
1128 | struct objfile *objf; | |
1129 | ALL_OBJFILES (objf) | |
1130 | { | |
1131 | if (obfd == objf->obfd) | |
1132 | { | |
1133 | *resultp = obsavestring (decoded, strlen (decoded), | |
1134 | &objf->objfile_obstack); | |
1135 | break; | |
1136 | } | |
1137 | } | |
1138 | } | |
1139 | } | |
4c4b4cd2 | 1140 | /* Sometimes, we can't find a corresponding objfile, in which |
76a01679 JB |
1141 | case, we put the result on the heap. Since we only decode |
1142 | when needed, we hope this usually does not cause a | |
1143 | significant memory leak (FIXME). */ | |
4c4b4cd2 | 1144 | if (*resultp == NULL) |
76a01679 JB |
1145 | { |
1146 | char **slot = (char **) htab_find_slot (decoded_names_store, | |
1147 | decoded, INSERT); | |
1148 | if (*slot == NULL) | |
1149 | *slot = xstrdup (decoded); | |
1150 | *resultp = *slot; | |
1151 | } | |
4c4b4cd2 | 1152 | } |
14f9c5c9 | 1153 | |
4c4b4cd2 PH |
1154 | return *resultp; |
1155 | } | |
76a01679 JB |
1156 | |
1157 | char * | |
1158 | ada_la_decode (const char *encoded, int options) | |
4c4b4cd2 PH |
1159 | { |
1160 | return xstrdup (ada_decode (encoded)); | |
14f9c5c9 AS |
1161 | } |
1162 | ||
1163 | /* Returns non-zero iff SYM_NAME matches NAME, ignoring any trailing | |
4c4b4cd2 PH |
1164 | suffixes that encode debugging information or leading _ada_ on |
1165 | SYM_NAME (see is_name_suffix commentary for the debugging | |
1166 | information that is ignored). If WILD, then NAME need only match a | |
1167 | suffix of SYM_NAME minus the same suffixes. Also returns 0 if | |
1168 | either argument is NULL. */ | |
14f9c5c9 AS |
1169 | |
1170 | int | |
d2e4a39e | 1171 | ada_match_name (const char *sym_name, const char *name, int wild) |
14f9c5c9 AS |
1172 | { |
1173 | if (sym_name == NULL || name == NULL) | |
1174 | return 0; | |
1175 | else if (wild) | |
1176 | return wild_match (name, strlen (name), sym_name); | |
d2e4a39e AS |
1177 | else |
1178 | { | |
1179 | int len_name = strlen (name); | |
4c4b4cd2 PH |
1180 | return (strncmp (sym_name, name, len_name) == 0 |
1181 | && is_name_suffix (sym_name + len_name)) | |
1182 | || (strncmp (sym_name, "_ada_", 5) == 0 | |
1183 | && strncmp (sym_name + 5, name, len_name) == 0 | |
1184 | && is_name_suffix (sym_name + len_name + 5)); | |
d2e4a39e | 1185 | } |
14f9c5c9 AS |
1186 | } |
1187 | ||
4c4b4cd2 PH |
1188 | /* True (non-zero) iff, in Ada mode, the symbol SYM should be |
1189 | suppressed in info listings. */ | |
14f9c5c9 AS |
1190 | |
1191 | int | |
ebf56fd3 | 1192 | ada_suppress_symbol_printing (struct symbol *sym) |
14f9c5c9 | 1193 | { |
176620f1 | 1194 | if (SYMBOL_DOMAIN (sym) == STRUCT_DOMAIN) |
14f9c5c9 | 1195 | return 1; |
d2e4a39e | 1196 | else |
4c4b4cd2 | 1197 | return is_suppressed_name (SYMBOL_LINKAGE_NAME (sym)); |
14f9c5c9 | 1198 | } |
14f9c5c9 | 1199 | \f |
d2e4a39e | 1200 | |
4c4b4cd2 | 1201 | /* Arrays */ |
14f9c5c9 | 1202 | |
4c4b4cd2 | 1203 | /* Names of MAX_ADA_DIMENS bounds in P_BOUNDS fields of array descriptors. */ |
14f9c5c9 | 1204 | |
d2e4a39e AS |
1205 | static char *bound_name[] = { |
1206 | "LB0", "UB0", "LB1", "UB1", "LB2", "UB2", "LB3", "UB3", | |
14f9c5c9 AS |
1207 | "LB4", "UB4", "LB5", "UB5", "LB6", "UB6", "LB7", "UB7" |
1208 | }; | |
1209 | ||
1210 | /* Maximum number of array dimensions we are prepared to handle. */ | |
1211 | ||
4c4b4cd2 | 1212 | #define MAX_ADA_DIMENS (sizeof(bound_name) / (2*sizeof(char *))) |
14f9c5c9 | 1213 | |
4c4b4cd2 | 1214 | /* Like modify_field, but allows bitpos > wordlength. */ |
14f9c5c9 AS |
1215 | |
1216 | static void | |
ebf56fd3 | 1217 | modify_general_field (char *addr, LONGEST fieldval, int bitpos, int bitsize) |
14f9c5c9 | 1218 | { |
4c4b4cd2 | 1219 | modify_field (addr + bitpos / 8, fieldval, bitpos % 8, bitsize); |
14f9c5c9 AS |
1220 | } |
1221 | ||
1222 | ||
4c4b4cd2 PH |
1223 | /* The desc_* routines return primitive portions of array descriptors |
1224 | (fat pointers). */ | |
14f9c5c9 AS |
1225 | |
1226 | /* The descriptor or array type, if any, indicated by TYPE; removes | |
4c4b4cd2 PH |
1227 | level of indirection, if needed. */ |
1228 | ||
d2e4a39e AS |
1229 | static struct type * |
1230 | desc_base_type (struct type *type) | |
14f9c5c9 AS |
1231 | { |
1232 | if (type == NULL) | |
1233 | return NULL; | |
61ee279c | 1234 | type = ada_check_typedef (type); |
1265e4aa JB |
1235 | if (type != NULL |
1236 | && (TYPE_CODE (type) == TYPE_CODE_PTR | |
1237 | || TYPE_CODE (type) == TYPE_CODE_REF)) | |
61ee279c | 1238 | return ada_check_typedef (TYPE_TARGET_TYPE (type)); |
14f9c5c9 AS |
1239 | else |
1240 | return type; | |
1241 | } | |
1242 | ||
4c4b4cd2 PH |
1243 | /* True iff TYPE indicates a "thin" array pointer type. */ |
1244 | ||
14f9c5c9 | 1245 | static int |
d2e4a39e | 1246 | is_thin_pntr (struct type *type) |
14f9c5c9 | 1247 | { |
d2e4a39e | 1248 | return |
14f9c5c9 AS |
1249 | is_suffix (ada_type_name (desc_base_type (type)), "___XUT") |
1250 | || is_suffix (ada_type_name (desc_base_type (type)), "___XUT___XVE"); | |
1251 | } | |
1252 | ||
4c4b4cd2 PH |
1253 | /* The descriptor type for thin pointer type TYPE. */ |
1254 | ||
d2e4a39e AS |
1255 | static struct type * |
1256 | thin_descriptor_type (struct type *type) | |
14f9c5c9 | 1257 | { |
d2e4a39e | 1258 | struct type *base_type = desc_base_type (type); |
14f9c5c9 AS |
1259 | if (base_type == NULL) |
1260 | return NULL; | |
1261 | if (is_suffix (ada_type_name (base_type), "___XVE")) | |
1262 | return base_type; | |
d2e4a39e | 1263 | else |
14f9c5c9 | 1264 | { |
d2e4a39e | 1265 | struct type *alt_type = ada_find_parallel_type (base_type, "___XVE"); |
14f9c5c9 | 1266 | if (alt_type == NULL) |
4c4b4cd2 | 1267 | return base_type; |
14f9c5c9 | 1268 | else |
4c4b4cd2 | 1269 | return alt_type; |
14f9c5c9 AS |
1270 | } |
1271 | } | |
1272 | ||
4c4b4cd2 PH |
1273 | /* A pointer to the array data for thin-pointer value VAL. */ |
1274 | ||
d2e4a39e AS |
1275 | static struct value * |
1276 | thin_data_pntr (struct value *val) | |
14f9c5c9 | 1277 | { |
df407dfe | 1278 | struct type *type = value_type (val); |
14f9c5c9 | 1279 | if (TYPE_CODE (type) == TYPE_CODE_PTR) |
d2e4a39e | 1280 | return value_cast (desc_data_type (thin_descriptor_type (type)), |
4c4b4cd2 | 1281 | value_copy (val)); |
d2e4a39e | 1282 | else |
14f9c5c9 | 1283 | return value_from_longest (desc_data_type (thin_descriptor_type (type)), |
df407dfe | 1284 | VALUE_ADDRESS (val) + value_offset (val)); |
14f9c5c9 AS |
1285 | } |
1286 | ||
4c4b4cd2 PH |
1287 | /* True iff TYPE indicates a "thick" array pointer type. */ |
1288 | ||
14f9c5c9 | 1289 | static int |
d2e4a39e | 1290 | is_thick_pntr (struct type *type) |
14f9c5c9 AS |
1291 | { |
1292 | type = desc_base_type (type); | |
1293 | return (type != NULL && TYPE_CODE (type) == TYPE_CODE_STRUCT | |
4c4b4cd2 | 1294 | && lookup_struct_elt_type (type, "P_BOUNDS", 1) != NULL); |
14f9c5c9 AS |
1295 | } |
1296 | ||
4c4b4cd2 PH |
1297 | /* If TYPE is the type of an array descriptor (fat or thin pointer) or a |
1298 | pointer to one, the type of its bounds data; otherwise, NULL. */ | |
76a01679 | 1299 | |
d2e4a39e AS |
1300 | static struct type * |
1301 | desc_bounds_type (struct type *type) | |
14f9c5c9 | 1302 | { |
d2e4a39e | 1303 | struct type *r; |
14f9c5c9 AS |
1304 | |
1305 | type = desc_base_type (type); | |
1306 | ||
1307 | if (type == NULL) | |
1308 | return NULL; | |
1309 | else if (is_thin_pntr (type)) | |
1310 | { | |
1311 | type = thin_descriptor_type (type); | |
1312 | if (type == NULL) | |
4c4b4cd2 | 1313 | return NULL; |
14f9c5c9 AS |
1314 | r = lookup_struct_elt_type (type, "BOUNDS", 1); |
1315 | if (r != NULL) | |
61ee279c | 1316 | return ada_check_typedef (r); |
14f9c5c9 AS |
1317 | } |
1318 | else if (TYPE_CODE (type) == TYPE_CODE_STRUCT) | |
1319 | { | |
1320 | r = lookup_struct_elt_type (type, "P_BOUNDS", 1); | |
1321 | if (r != NULL) | |
61ee279c | 1322 | return ada_check_typedef (TYPE_TARGET_TYPE (ada_check_typedef (r))); |
14f9c5c9 AS |
1323 | } |
1324 | return NULL; | |
1325 | } | |
1326 | ||
1327 | /* If ARR is an array descriptor (fat or thin pointer), or pointer to | |
4c4b4cd2 PH |
1328 | one, a pointer to its bounds data. Otherwise NULL. */ |
1329 | ||
d2e4a39e AS |
1330 | static struct value * |
1331 | desc_bounds (struct value *arr) | |
14f9c5c9 | 1332 | { |
df407dfe | 1333 | struct type *type = ada_check_typedef (value_type (arr)); |
d2e4a39e | 1334 | if (is_thin_pntr (type)) |
14f9c5c9 | 1335 | { |
d2e4a39e | 1336 | struct type *bounds_type = |
4c4b4cd2 | 1337 | desc_bounds_type (thin_descriptor_type (type)); |
14f9c5c9 AS |
1338 | LONGEST addr; |
1339 | ||
1340 | if (desc_bounds_type == NULL) | |
323e0a4a | 1341 | error (_("Bad GNAT array descriptor")); |
14f9c5c9 AS |
1342 | |
1343 | /* NOTE: The following calculation is not really kosher, but | |
d2e4a39e | 1344 | since desc_type is an XVE-encoded type (and shouldn't be), |
4c4b4cd2 | 1345 | the correct calculation is a real pain. FIXME (and fix GCC). */ |
14f9c5c9 | 1346 | if (TYPE_CODE (type) == TYPE_CODE_PTR) |
4c4b4cd2 | 1347 | addr = value_as_long (arr); |
d2e4a39e | 1348 | else |
df407dfe | 1349 | addr = VALUE_ADDRESS (arr) + value_offset (arr); |
14f9c5c9 | 1350 | |
d2e4a39e | 1351 | return |
4c4b4cd2 PH |
1352 | value_from_longest (lookup_pointer_type (bounds_type), |
1353 | addr - TYPE_LENGTH (bounds_type)); | |
14f9c5c9 AS |
1354 | } |
1355 | ||
1356 | else if (is_thick_pntr (type)) | |
d2e4a39e | 1357 | return value_struct_elt (&arr, NULL, "P_BOUNDS", NULL, |
323e0a4a | 1358 | _("Bad GNAT array descriptor")); |
14f9c5c9 AS |
1359 | else |
1360 | return NULL; | |
1361 | } | |
1362 | ||
4c4b4cd2 PH |
1363 | /* If TYPE is the type of an array-descriptor (fat pointer), the bit |
1364 | position of the field containing the address of the bounds data. */ | |
1365 | ||
14f9c5c9 | 1366 | static int |
d2e4a39e | 1367 | fat_pntr_bounds_bitpos (struct type *type) |
14f9c5c9 AS |
1368 | { |
1369 | return TYPE_FIELD_BITPOS (desc_base_type (type), 1); | |
1370 | } | |
1371 | ||
1372 | /* If TYPE is the type of an array-descriptor (fat pointer), the bit | |
4c4b4cd2 PH |
1373 | size of the field containing the address of the bounds data. */ |
1374 | ||
14f9c5c9 | 1375 | static int |
d2e4a39e | 1376 | fat_pntr_bounds_bitsize (struct type *type) |
14f9c5c9 AS |
1377 | { |
1378 | type = desc_base_type (type); | |
1379 | ||
d2e4a39e | 1380 | if (TYPE_FIELD_BITSIZE (type, 1) > 0) |
14f9c5c9 AS |
1381 | return TYPE_FIELD_BITSIZE (type, 1); |
1382 | else | |
61ee279c | 1383 | return 8 * TYPE_LENGTH (ada_check_typedef (TYPE_FIELD_TYPE (type, 1))); |
14f9c5c9 AS |
1384 | } |
1385 | ||
4c4b4cd2 | 1386 | /* If TYPE is the type of an array descriptor (fat or thin pointer) or a |
14f9c5c9 | 1387 | pointer to one, the type of its array data (a |
4c4b4cd2 PH |
1388 | pointer-to-array-with-no-bounds type); otherwise, NULL. Use |
1389 | ada_type_of_array to get an array type with bounds data. */ | |
1390 | ||
d2e4a39e AS |
1391 | static struct type * |
1392 | desc_data_type (struct type *type) | |
14f9c5c9 AS |
1393 | { |
1394 | type = desc_base_type (type); | |
1395 | ||
4c4b4cd2 | 1396 | /* NOTE: The following is bogus; see comment in desc_bounds. */ |
14f9c5c9 | 1397 | if (is_thin_pntr (type)) |
d2e4a39e AS |
1398 | return lookup_pointer_type |
1399 | (desc_base_type (TYPE_FIELD_TYPE (thin_descriptor_type (type), 1))); | |
14f9c5c9 AS |
1400 | else if (is_thick_pntr (type)) |
1401 | return lookup_struct_elt_type (type, "P_ARRAY", 1); | |
1402 | else | |
1403 | return NULL; | |
1404 | } | |
1405 | ||
1406 | /* If ARR is an array descriptor (fat or thin pointer), a pointer to | |
1407 | its array data. */ | |
4c4b4cd2 | 1408 | |
d2e4a39e AS |
1409 | static struct value * |
1410 | desc_data (struct value *arr) | |
14f9c5c9 | 1411 | { |
df407dfe | 1412 | struct type *type = value_type (arr); |
14f9c5c9 AS |
1413 | if (is_thin_pntr (type)) |
1414 | return thin_data_pntr (arr); | |
1415 | else if (is_thick_pntr (type)) | |
d2e4a39e | 1416 | return value_struct_elt (&arr, NULL, "P_ARRAY", NULL, |
323e0a4a | 1417 | _("Bad GNAT array descriptor")); |
14f9c5c9 AS |
1418 | else |
1419 | return NULL; | |
1420 | } | |
1421 | ||
1422 | ||
1423 | /* If TYPE is the type of an array-descriptor (fat pointer), the bit | |
4c4b4cd2 PH |
1424 | position of the field containing the address of the data. */ |
1425 | ||
14f9c5c9 | 1426 | static int |
d2e4a39e | 1427 | fat_pntr_data_bitpos (struct type *type) |
14f9c5c9 AS |
1428 | { |
1429 | return TYPE_FIELD_BITPOS (desc_base_type (type), 0); | |
1430 | } | |
1431 | ||
1432 | /* If TYPE is the type of an array-descriptor (fat pointer), the bit | |
4c4b4cd2 PH |
1433 | size of the field containing the address of the data. */ |
1434 | ||
14f9c5c9 | 1435 | static int |
d2e4a39e | 1436 | fat_pntr_data_bitsize (struct type *type) |
14f9c5c9 AS |
1437 | { |
1438 | type = desc_base_type (type); | |
1439 | ||
1440 | if (TYPE_FIELD_BITSIZE (type, 0) > 0) | |
1441 | return TYPE_FIELD_BITSIZE (type, 0); | |
d2e4a39e | 1442 | else |
14f9c5c9 AS |
1443 | return TARGET_CHAR_BIT * TYPE_LENGTH (TYPE_FIELD_TYPE (type, 0)); |
1444 | } | |
1445 | ||
4c4b4cd2 | 1446 | /* If BOUNDS is an array-bounds structure (or pointer to one), return |
14f9c5c9 | 1447 | the Ith lower bound stored in it, if WHICH is 0, and the Ith upper |
4c4b4cd2 PH |
1448 | bound, if WHICH is 1. The first bound is I=1. */ |
1449 | ||
d2e4a39e AS |
1450 | static struct value * |
1451 | desc_one_bound (struct value *bounds, int i, int which) | |
14f9c5c9 | 1452 | { |
d2e4a39e | 1453 | return value_struct_elt (&bounds, NULL, bound_name[2 * i + which - 2], NULL, |
323e0a4a | 1454 | _("Bad GNAT array descriptor bounds")); |
14f9c5c9 AS |
1455 | } |
1456 | ||
1457 | /* If BOUNDS is an array-bounds structure type, return the bit position | |
1458 | of the Ith lower bound stored in it, if WHICH is 0, and the Ith upper | |
4c4b4cd2 PH |
1459 | bound, if WHICH is 1. The first bound is I=1. */ |
1460 | ||
14f9c5c9 | 1461 | static int |
d2e4a39e | 1462 | desc_bound_bitpos (struct type *type, int i, int which) |
14f9c5c9 | 1463 | { |
d2e4a39e | 1464 | return TYPE_FIELD_BITPOS (desc_base_type (type), 2 * i + which - 2); |
14f9c5c9 AS |
1465 | } |
1466 | ||
1467 | /* If BOUNDS is an array-bounds structure type, return the bit field size | |
1468 | of the Ith lower bound stored in it, if WHICH is 0, and the Ith upper | |
4c4b4cd2 PH |
1469 | bound, if WHICH is 1. The first bound is I=1. */ |
1470 | ||
76a01679 | 1471 | static int |
d2e4a39e | 1472 | desc_bound_bitsize (struct type *type, int i, int which) |
14f9c5c9 AS |
1473 | { |
1474 | type = desc_base_type (type); | |
1475 | ||
d2e4a39e AS |
1476 | if (TYPE_FIELD_BITSIZE (type, 2 * i + which - 2) > 0) |
1477 | return TYPE_FIELD_BITSIZE (type, 2 * i + which - 2); | |
1478 | else | |
1479 | return 8 * TYPE_LENGTH (TYPE_FIELD_TYPE (type, 2 * i + which - 2)); | |
14f9c5c9 AS |
1480 | } |
1481 | ||
1482 | /* If TYPE is the type of an array-bounds structure, the type of its | |
4c4b4cd2 PH |
1483 | Ith bound (numbering from 1). Otherwise, NULL. */ |
1484 | ||
d2e4a39e AS |
1485 | static struct type * |
1486 | desc_index_type (struct type *type, int i) | |
14f9c5c9 AS |
1487 | { |
1488 | type = desc_base_type (type); | |
1489 | ||
1490 | if (TYPE_CODE (type) == TYPE_CODE_STRUCT) | |
d2e4a39e AS |
1491 | return lookup_struct_elt_type (type, bound_name[2 * i - 2], 1); |
1492 | else | |
14f9c5c9 AS |
1493 | return NULL; |
1494 | } | |
1495 | ||
4c4b4cd2 PH |
1496 | /* The number of index positions in the array-bounds type TYPE. |
1497 | Return 0 if TYPE is NULL. */ | |
1498 | ||
14f9c5c9 | 1499 | static int |
d2e4a39e | 1500 | desc_arity (struct type *type) |
14f9c5c9 AS |
1501 | { |
1502 | type = desc_base_type (type); | |
1503 | ||
1504 | if (type != NULL) | |
1505 | return TYPE_NFIELDS (type) / 2; | |
1506 | return 0; | |
1507 | } | |
1508 | ||
4c4b4cd2 PH |
1509 | /* Non-zero iff TYPE is a simple array type (not a pointer to one) or |
1510 | an array descriptor type (representing an unconstrained array | |
1511 | type). */ | |
1512 | ||
76a01679 JB |
1513 | static int |
1514 | ada_is_direct_array_type (struct type *type) | |
4c4b4cd2 PH |
1515 | { |
1516 | if (type == NULL) | |
1517 | return 0; | |
61ee279c | 1518 | type = ada_check_typedef (type); |
4c4b4cd2 | 1519 | return (TYPE_CODE (type) == TYPE_CODE_ARRAY |
76a01679 | 1520 | || ada_is_array_descriptor_type (type)); |
4c4b4cd2 PH |
1521 | } |
1522 | ||
52ce6436 PH |
1523 | /* Non-zero iff TYPE represents any kind of array in Ada, or a pointer |
1524 | * to one. */ | |
1525 | ||
1526 | int | |
1527 | ada_is_array_type (struct type *type) | |
1528 | { | |
1529 | while (type != NULL | |
1530 | && (TYPE_CODE (type) == TYPE_CODE_PTR | |
1531 | || TYPE_CODE (type) == TYPE_CODE_REF)) | |
1532 | type = TYPE_TARGET_TYPE (type); | |
1533 | return ada_is_direct_array_type (type); | |
1534 | } | |
1535 | ||
4c4b4cd2 | 1536 | /* Non-zero iff TYPE is a simple array type or pointer to one. */ |
14f9c5c9 | 1537 | |
14f9c5c9 | 1538 | int |
4c4b4cd2 | 1539 | ada_is_simple_array_type (struct type *type) |
14f9c5c9 AS |
1540 | { |
1541 | if (type == NULL) | |
1542 | return 0; | |
61ee279c | 1543 | type = ada_check_typedef (type); |
14f9c5c9 | 1544 | return (TYPE_CODE (type) == TYPE_CODE_ARRAY |
4c4b4cd2 PH |
1545 | || (TYPE_CODE (type) == TYPE_CODE_PTR |
1546 | && TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_ARRAY)); | |
14f9c5c9 AS |
1547 | } |
1548 | ||
4c4b4cd2 PH |
1549 | /* Non-zero iff TYPE belongs to a GNAT array descriptor. */ |
1550 | ||
14f9c5c9 | 1551 | int |
4c4b4cd2 | 1552 | ada_is_array_descriptor_type (struct type *type) |
14f9c5c9 | 1553 | { |
d2e4a39e | 1554 | struct type *data_type = desc_data_type (type); |
14f9c5c9 AS |
1555 | |
1556 | if (type == NULL) | |
1557 | return 0; | |
61ee279c | 1558 | type = ada_check_typedef (type); |
d2e4a39e | 1559 | return |
14f9c5c9 AS |
1560 | data_type != NULL |
1561 | && ((TYPE_CODE (data_type) == TYPE_CODE_PTR | |
4c4b4cd2 PH |
1562 | && TYPE_TARGET_TYPE (data_type) != NULL |
1563 | && TYPE_CODE (TYPE_TARGET_TYPE (data_type)) == TYPE_CODE_ARRAY) | |
1265e4aa | 1564 | || TYPE_CODE (data_type) == TYPE_CODE_ARRAY) |
14f9c5c9 AS |
1565 | && desc_arity (desc_bounds_type (type)) > 0; |
1566 | } | |
1567 | ||
1568 | /* Non-zero iff type is a partially mal-formed GNAT array | |
4c4b4cd2 | 1569 | descriptor. FIXME: This is to compensate for some problems with |
14f9c5c9 | 1570 | debugging output from GNAT. Re-examine periodically to see if it |
4c4b4cd2 PH |
1571 | is still needed. */ |
1572 | ||
14f9c5c9 | 1573 | int |
ebf56fd3 | 1574 | ada_is_bogus_array_descriptor (struct type *type) |
14f9c5c9 | 1575 | { |
d2e4a39e | 1576 | return |
14f9c5c9 AS |
1577 | type != NULL |
1578 | && TYPE_CODE (type) == TYPE_CODE_STRUCT | |
1579 | && (lookup_struct_elt_type (type, "P_BOUNDS", 1) != NULL | |
4c4b4cd2 PH |
1580 | || lookup_struct_elt_type (type, "P_ARRAY", 1) != NULL) |
1581 | && !ada_is_array_descriptor_type (type); | |
14f9c5c9 AS |
1582 | } |
1583 | ||
1584 | ||
4c4b4cd2 | 1585 | /* If ARR has a record type in the form of a standard GNAT array descriptor, |
14f9c5c9 | 1586 | (fat pointer) returns the type of the array data described---specifically, |
4c4b4cd2 | 1587 | a pointer-to-array type. If BOUNDS is non-zero, the bounds data are filled |
14f9c5c9 | 1588 | in from the descriptor; otherwise, they are left unspecified. If |
4c4b4cd2 PH |
1589 | the ARR denotes a null array descriptor and BOUNDS is non-zero, |
1590 | returns NULL. The result is simply the type of ARR if ARR is not | |
14f9c5c9 | 1591 | a descriptor. */ |
d2e4a39e AS |
1592 | struct type * |
1593 | ada_type_of_array (struct value *arr, int bounds) | |
14f9c5c9 | 1594 | { |
df407dfe AC |
1595 | if (ada_is_packed_array_type (value_type (arr))) |
1596 | return decode_packed_array_type (value_type (arr)); | |
14f9c5c9 | 1597 | |
df407dfe AC |
1598 | if (!ada_is_array_descriptor_type (value_type (arr))) |
1599 | return value_type (arr); | |
d2e4a39e AS |
1600 | |
1601 | if (!bounds) | |
1602 | return | |
df407dfe | 1603 | ada_check_typedef (TYPE_TARGET_TYPE (desc_data_type (value_type (arr)))); |
14f9c5c9 AS |
1604 | else |
1605 | { | |
d2e4a39e | 1606 | struct type *elt_type; |
14f9c5c9 | 1607 | int arity; |
d2e4a39e | 1608 | struct value *descriptor; |
df407dfe | 1609 | struct objfile *objf = TYPE_OBJFILE (value_type (arr)); |
14f9c5c9 | 1610 | |
df407dfe AC |
1611 | elt_type = ada_array_element_type (value_type (arr), -1); |
1612 | arity = ada_array_arity (value_type (arr)); | |
14f9c5c9 | 1613 | |
d2e4a39e | 1614 | if (elt_type == NULL || arity == 0) |
df407dfe | 1615 | return ada_check_typedef (value_type (arr)); |
14f9c5c9 AS |
1616 | |
1617 | descriptor = desc_bounds (arr); | |
d2e4a39e | 1618 | if (value_as_long (descriptor) == 0) |
4c4b4cd2 | 1619 | return NULL; |
d2e4a39e | 1620 | while (arity > 0) |
4c4b4cd2 PH |
1621 | { |
1622 | struct type *range_type = alloc_type (objf); | |
1623 | struct type *array_type = alloc_type (objf); | |
1624 | struct value *low = desc_one_bound (descriptor, arity, 0); | |
1625 | struct value *high = desc_one_bound (descriptor, arity, 1); | |
1626 | arity -= 1; | |
1627 | ||
df407dfe | 1628 | create_range_type (range_type, value_type (low), |
529cad9c PH |
1629 | longest_to_int (value_as_long (low)), |
1630 | longest_to_int (value_as_long (high))); | |
4c4b4cd2 PH |
1631 | elt_type = create_array_type (array_type, elt_type, range_type); |
1632 | } | |
14f9c5c9 AS |
1633 | |
1634 | return lookup_pointer_type (elt_type); | |
1635 | } | |
1636 | } | |
1637 | ||
1638 | /* If ARR does not represent an array, returns ARR unchanged. | |
4c4b4cd2 PH |
1639 | Otherwise, returns either a standard GDB array with bounds set |
1640 | appropriately or, if ARR is a non-null fat pointer, a pointer to a standard | |
1641 | GDB array. Returns NULL if ARR is a null fat pointer. */ | |
1642 | ||
d2e4a39e AS |
1643 | struct value * |
1644 | ada_coerce_to_simple_array_ptr (struct value *arr) | |
14f9c5c9 | 1645 | { |
df407dfe | 1646 | if (ada_is_array_descriptor_type (value_type (arr))) |
14f9c5c9 | 1647 | { |
d2e4a39e | 1648 | struct type *arrType = ada_type_of_array (arr, 1); |
14f9c5c9 | 1649 | if (arrType == NULL) |
4c4b4cd2 | 1650 | return NULL; |
14f9c5c9 AS |
1651 | return value_cast (arrType, value_copy (desc_data (arr))); |
1652 | } | |
df407dfe | 1653 | else if (ada_is_packed_array_type (value_type (arr))) |
14f9c5c9 AS |
1654 | return decode_packed_array (arr); |
1655 | else | |
1656 | return arr; | |
1657 | } | |
1658 | ||
1659 | /* If ARR does not represent an array, returns ARR unchanged. | |
1660 | Otherwise, returns a standard GDB array describing ARR (which may | |
4c4b4cd2 PH |
1661 | be ARR itself if it already is in the proper form). */ |
1662 | ||
1663 | static struct value * | |
d2e4a39e | 1664 | ada_coerce_to_simple_array (struct value *arr) |
14f9c5c9 | 1665 | { |
df407dfe | 1666 | if (ada_is_array_descriptor_type (value_type (arr))) |
14f9c5c9 | 1667 | { |
d2e4a39e | 1668 | struct value *arrVal = ada_coerce_to_simple_array_ptr (arr); |
14f9c5c9 | 1669 | if (arrVal == NULL) |
323e0a4a | 1670 | error (_("Bounds unavailable for null array pointer.")); |
529cad9c | 1671 | check_size (TYPE_TARGET_TYPE (value_type (arrVal))); |
14f9c5c9 AS |
1672 | return value_ind (arrVal); |
1673 | } | |
df407dfe | 1674 | else if (ada_is_packed_array_type (value_type (arr))) |
14f9c5c9 | 1675 | return decode_packed_array (arr); |
d2e4a39e | 1676 | else |
14f9c5c9 AS |
1677 | return arr; |
1678 | } | |
1679 | ||
1680 | /* If TYPE represents a GNAT array type, return it translated to an | |
1681 | ordinary GDB array type (possibly with BITSIZE fields indicating | |
4c4b4cd2 PH |
1682 | packing). For other types, is the identity. */ |
1683 | ||
d2e4a39e AS |
1684 | struct type * |
1685 | ada_coerce_to_simple_array_type (struct type *type) | |
14f9c5c9 | 1686 | { |
d2e4a39e AS |
1687 | struct value *mark = value_mark (); |
1688 | struct value *dummy = value_from_longest (builtin_type_long, 0); | |
1689 | struct type *result; | |
04624583 | 1690 | deprecated_set_value_type (dummy, type); |
14f9c5c9 | 1691 | result = ada_type_of_array (dummy, 0); |
4c4b4cd2 | 1692 | value_free_to_mark (mark); |
14f9c5c9 AS |
1693 | return result; |
1694 | } | |
1695 | ||
4c4b4cd2 PH |
1696 | /* Non-zero iff TYPE represents a standard GNAT packed-array type. */ |
1697 | ||
14f9c5c9 | 1698 | int |
d2e4a39e | 1699 | ada_is_packed_array_type (struct type *type) |
14f9c5c9 AS |
1700 | { |
1701 | if (type == NULL) | |
1702 | return 0; | |
4c4b4cd2 | 1703 | type = desc_base_type (type); |
61ee279c | 1704 | type = ada_check_typedef (type); |
d2e4a39e | 1705 | return |
14f9c5c9 AS |
1706 | ada_type_name (type) != NULL |
1707 | && strstr (ada_type_name (type), "___XP") != NULL; | |
1708 | } | |
1709 | ||
1710 | /* Given that TYPE is a standard GDB array type with all bounds filled | |
1711 | in, and that the element size of its ultimate scalar constituents | |
1712 | (that is, either its elements, or, if it is an array of arrays, its | |
1713 | elements' elements, etc.) is *ELT_BITS, return an identical type, | |
1714 | but with the bit sizes of its elements (and those of any | |
1715 | constituent arrays) recorded in the BITSIZE components of its | |
4c4b4cd2 PH |
1716 | TYPE_FIELD_BITSIZE values, and with *ELT_BITS set to its total size |
1717 | in bits. */ | |
1718 | ||
d2e4a39e AS |
1719 | static struct type * |
1720 | packed_array_type (struct type *type, long *elt_bits) | |
14f9c5c9 | 1721 | { |
d2e4a39e AS |
1722 | struct type *new_elt_type; |
1723 | struct type *new_type; | |
14f9c5c9 AS |
1724 | LONGEST low_bound, high_bound; |
1725 | ||
61ee279c | 1726 | type = ada_check_typedef (type); |
14f9c5c9 AS |
1727 | if (TYPE_CODE (type) != TYPE_CODE_ARRAY) |
1728 | return type; | |
1729 | ||
1730 | new_type = alloc_type (TYPE_OBJFILE (type)); | |
61ee279c | 1731 | new_elt_type = packed_array_type (ada_check_typedef (TYPE_TARGET_TYPE (type)), |
4c4b4cd2 | 1732 | elt_bits); |
14f9c5c9 AS |
1733 | create_array_type (new_type, new_elt_type, TYPE_FIELD_TYPE (type, 0)); |
1734 | TYPE_FIELD_BITSIZE (new_type, 0) = *elt_bits; | |
1735 | TYPE_NAME (new_type) = ada_type_name (type); | |
1736 | ||
d2e4a39e | 1737 | if (get_discrete_bounds (TYPE_FIELD_TYPE (type, 0), |
4c4b4cd2 | 1738 | &low_bound, &high_bound) < 0) |
14f9c5c9 AS |
1739 | low_bound = high_bound = 0; |
1740 | if (high_bound < low_bound) | |
1741 | *elt_bits = TYPE_LENGTH (new_type) = 0; | |
d2e4a39e | 1742 | else |
14f9c5c9 AS |
1743 | { |
1744 | *elt_bits *= (high_bound - low_bound + 1); | |
d2e4a39e | 1745 | TYPE_LENGTH (new_type) = |
4c4b4cd2 | 1746 | (*elt_bits + HOST_CHAR_BIT - 1) / HOST_CHAR_BIT; |
14f9c5c9 AS |
1747 | } |
1748 | ||
4c4b4cd2 | 1749 | TYPE_FLAGS (new_type) |= TYPE_FLAG_FIXED_INSTANCE; |
14f9c5c9 AS |
1750 | return new_type; |
1751 | } | |
1752 | ||
4c4b4cd2 PH |
1753 | /* The array type encoded by TYPE, where ada_is_packed_array_type (TYPE). */ |
1754 | ||
d2e4a39e AS |
1755 | static struct type * |
1756 | decode_packed_array_type (struct type *type) | |
1757 | { | |
4c4b4cd2 | 1758 | struct symbol *sym; |
d2e4a39e | 1759 | struct block **blocks; |
61ee279c | 1760 | const char *raw_name = ada_type_name (ada_check_typedef (type)); |
d2e4a39e AS |
1761 | char *name = (char *) alloca (strlen (raw_name) + 1); |
1762 | char *tail = strstr (raw_name, "___XP"); | |
1763 | struct type *shadow_type; | |
14f9c5c9 AS |
1764 | long bits; |
1765 | int i, n; | |
1766 | ||
4c4b4cd2 PH |
1767 | type = desc_base_type (type); |
1768 | ||
14f9c5c9 AS |
1769 | memcpy (name, raw_name, tail - raw_name); |
1770 | name[tail - raw_name] = '\000'; | |
1771 | ||
4c4b4cd2 PH |
1772 | sym = standard_lookup (name, get_selected_block (0), VAR_DOMAIN); |
1773 | if (sym == NULL || SYMBOL_TYPE (sym) == NULL) | |
14f9c5c9 | 1774 | { |
323e0a4a | 1775 | lim_warning (_("could not find bounds information on packed array")); |
14f9c5c9 AS |
1776 | return NULL; |
1777 | } | |
4c4b4cd2 | 1778 | shadow_type = SYMBOL_TYPE (sym); |
14f9c5c9 AS |
1779 | |
1780 | if (TYPE_CODE (shadow_type) != TYPE_CODE_ARRAY) | |
1781 | { | |
323e0a4a | 1782 | lim_warning (_("could not understand bounds information on packed array")); |
14f9c5c9 AS |
1783 | return NULL; |
1784 | } | |
d2e4a39e | 1785 | |
14f9c5c9 AS |
1786 | if (sscanf (tail + sizeof ("___XP") - 1, "%ld", &bits) != 1) |
1787 | { | |
4c4b4cd2 | 1788 | lim_warning |
323e0a4a | 1789 | (_("could not understand bit size information on packed array")); |
14f9c5c9 AS |
1790 | return NULL; |
1791 | } | |
d2e4a39e | 1792 | |
14f9c5c9 AS |
1793 | return packed_array_type (shadow_type, &bits); |
1794 | } | |
1795 | ||
4c4b4cd2 | 1796 | /* Given that ARR is a struct value *indicating a GNAT packed array, |
14f9c5c9 AS |
1797 | returns a simple array that denotes that array. Its type is a |
1798 | standard GDB array type except that the BITSIZEs of the array | |
1799 | target types are set to the number of bits in each element, and the | |
4c4b4cd2 | 1800 | type length is set appropriately. */ |
14f9c5c9 | 1801 | |
d2e4a39e AS |
1802 | static struct value * |
1803 | decode_packed_array (struct value *arr) | |
14f9c5c9 | 1804 | { |
4c4b4cd2 | 1805 | struct type *type; |
14f9c5c9 | 1806 | |
4c4b4cd2 | 1807 | arr = ada_coerce_ref (arr); |
df407dfe | 1808 | if (TYPE_CODE (value_type (arr)) == TYPE_CODE_PTR) |
4c4b4cd2 PH |
1809 | arr = ada_value_ind (arr); |
1810 | ||
df407dfe | 1811 | type = decode_packed_array_type (value_type (arr)); |
14f9c5c9 AS |
1812 | if (type == NULL) |
1813 | { | |
323e0a4a | 1814 | error (_("can't unpack array")); |
14f9c5c9 AS |
1815 | return NULL; |
1816 | } | |
61ee279c | 1817 | |
df407dfe | 1818 | if (BITS_BIG_ENDIAN && ada_is_modular_type (value_type (arr))) |
61ee279c PH |
1819 | { |
1820 | /* This is a (right-justified) modular type representing a packed | |
1821 | array with no wrapper. In order to interpret the value through | |
1822 | the (left-justified) packed array type we just built, we must | |
1823 | first left-justify it. */ | |
1824 | int bit_size, bit_pos; | |
1825 | ULONGEST mod; | |
1826 | ||
df407dfe | 1827 | mod = ada_modulus (value_type (arr)) - 1; |
61ee279c PH |
1828 | bit_size = 0; |
1829 | while (mod > 0) | |
1830 | { | |
1831 | bit_size += 1; | |
1832 | mod >>= 1; | |
1833 | } | |
df407dfe | 1834 | bit_pos = HOST_CHAR_BIT * TYPE_LENGTH (value_type (arr)) - bit_size; |
61ee279c PH |
1835 | arr = ada_value_primitive_packed_val (arr, NULL, |
1836 | bit_pos / HOST_CHAR_BIT, | |
1837 | bit_pos % HOST_CHAR_BIT, | |
1838 | bit_size, | |
1839 | type); | |
1840 | } | |
1841 | ||
4c4b4cd2 | 1842 | return coerce_unspec_val_to_type (arr, type); |
14f9c5c9 AS |
1843 | } |
1844 | ||
1845 | ||
1846 | /* The value of the element of packed array ARR at the ARITY indices | |
4c4b4cd2 | 1847 | given in IND. ARR must be a simple array. */ |
14f9c5c9 | 1848 | |
d2e4a39e AS |
1849 | static struct value * |
1850 | value_subscript_packed (struct value *arr, int arity, struct value **ind) | |
14f9c5c9 AS |
1851 | { |
1852 | int i; | |
1853 | int bits, elt_off, bit_off; | |
1854 | long elt_total_bit_offset; | |
d2e4a39e AS |
1855 | struct type *elt_type; |
1856 | struct value *v; | |
14f9c5c9 AS |
1857 | |
1858 | bits = 0; | |
1859 | elt_total_bit_offset = 0; | |
df407dfe | 1860 | elt_type = ada_check_typedef (value_type (arr)); |
d2e4a39e | 1861 | for (i = 0; i < arity; i += 1) |
14f9c5c9 | 1862 | { |
d2e4a39e | 1863 | if (TYPE_CODE (elt_type) != TYPE_CODE_ARRAY |
4c4b4cd2 PH |
1864 | || TYPE_FIELD_BITSIZE (elt_type, 0) == 0) |
1865 | error | |
323e0a4a | 1866 | (_("attempt to do packed indexing of something other than a packed array")); |
14f9c5c9 | 1867 | else |
4c4b4cd2 PH |
1868 | { |
1869 | struct type *range_type = TYPE_INDEX_TYPE (elt_type); | |
1870 | LONGEST lowerbound, upperbound; | |
1871 | LONGEST idx; | |
1872 | ||
1873 | if (get_discrete_bounds (range_type, &lowerbound, &upperbound) < 0) | |
1874 | { | |
323e0a4a | 1875 | lim_warning (_("don't know bounds of array")); |
4c4b4cd2 PH |
1876 | lowerbound = upperbound = 0; |
1877 | } | |
1878 | ||
1879 | idx = value_as_long (value_pos_atr (ind[i])); | |
1880 | if (idx < lowerbound || idx > upperbound) | |
323e0a4a | 1881 | lim_warning (_("packed array index %ld out of bounds"), (long) idx); |
4c4b4cd2 PH |
1882 | bits = TYPE_FIELD_BITSIZE (elt_type, 0); |
1883 | elt_total_bit_offset += (idx - lowerbound) * bits; | |
61ee279c | 1884 | elt_type = ada_check_typedef (TYPE_TARGET_TYPE (elt_type)); |
4c4b4cd2 | 1885 | } |
14f9c5c9 AS |
1886 | } |
1887 | elt_off = elt_total_bit_offset / HOST_CHAR_BIT; | |
1888 | bit_off = elt_total_bit_offset % HOST_CHAR_BIT; | |
d2e4a39e AS |
1889 | |
1890 | v = ada_value_primitive_packed_val (arr, NULL, elt_off, bit_off, | |
4c4b4cd2 | 1891 | bits, elt_type); |
14f9c5c9 AS |
1892 | return v; |
1893 | } | |
1894 | ||
4c4b4cd2 | 1895 | /* Non-zero iff TYPE includes negative integer values. */ |
14f9c5c9 AS |
1896 | |
1897 | static int | |
d2e4a39e | 1898 | has_negatives (struct type *type) |
14f9c5c9 | 1899 | { |
d2e4a39e AS |
1900 | switch (TYPE_CODE (type)) |
1901 | { | |
1902 | default: | |
1903 | return 0; | |
1904 | case TYPE_CODE_INT: | |
1905 | return !TYPE_UNSIGNED (type); | |
1906 | case TYPE_CODE_RANGE: | |
1907 | return TYPE_LOW_BOUND (type) < 0; | |
1908 | } | |
14f9c5c9 | 1909 | } |
d2e4a39e | 1910 | |
14f9c5c9 AS |
1911 | |
1912 | /* Create a new value of type TYPE from the contents of OBJ starting | |
1913 | at byte OFFSET, and bit offset BIT_OFFSET within that byte, | |
1914 | proceeding for BIT_SIZE bits. If OBJ is an lval in memory, then | |
4c4b4cd2 PH |
1915 | assigning through the result will set the field fetched from. |
1916 | VALADDR is ignored unless OBJ is NULL, in which case, | |
1917 | VALADDR+OFFSET must address the start of storage containing the | |
1918 | packed value. The value returned in this case is never an lval. | |
1919 | Assumes 0 <= BIT_OFFSET < HOST_CHAR_BIT. */ | |
14f9c5c9 | 1920 | |
d2e4a39e | 1921 | struct value * |
fc1a4b47 | 1922 | ada_value_primitive_packed_val (struct value *obj, const gdb_byte *valaddr, |
a2bd3dcd | 1923 | long offset, int bit_offset, int bit_size, |
4c4b4cd2 | 1924 | struct type *type) |
14f9c5c9 | 1925 | { |
d2e4a39e | 1926 | struct value *v; |
4c4b4cd2 PH |
1927 | int src, /* Index into the source area */ |
1928 | targ, /* Index into the target area */ | |
1929 | srcBitsLeft, /* Number of source bits left to move */ | |
1930 | nsrc, ntarg, /* Number of source and target bytes */ | |
1931 | unusedLS, /* Number of bits in next significant | |
1932 | byte of source that are unused */ | |
1933 | accumSize; /* Number of meaningful bits in accum */ | |
1934 | unsigned char *bytes; /* First byte containing data to unpack */ | |
d2e4a39e | 1935 | unsigned char *unpacked; |
4c4b4cd2 | 1936 | unsigned long accum; /* Staging area for bits being transferred */ |
14f9c5c9 AS |
1937 | unsigned char sign; |
1938 | int len = (bit_size + bit_offset + HOST_CHAR_BIT - 1) / 8; | |
4c4b4cd2 PH |
1939 | /* Transmit bytes from least to most significant; delta is the direction |
1940 | the indices move. */ | |
14f9c5c9 AS |
1941 | int delta = BITS_BIG_ENDIAN ? -1 : 1; |
1942 | ||
61ee279c | 1943 | type = ada_check_typedef (type); |
14f9c5c9 AS |
1944 | |
1945 | if (obj == NULL) | |
1946 | { | |
1947 | v = allocate_value (type); | |
d2e4a39e | 1948 | bytes = (unsigned char *) (valaddr + offset); |
14f9c5c9 | 1949 | } |
d69fe07e | 1950 | else if (value_lazy (obj)) |
14f9c5c9 AS |
1951 | { |
1952 | v = value_at (type, | |
df407dfe | 1953 | VALUE_ADDRESS (obj) + value_offset (obj) + offset); |
d2e4a39e | 1954 | bytes = (unsigned char *) alloca (len); |
14f9c5c9 AS |
1955 | read_memory (VALUE_ADDRESS (v), bytes, len); |
1956 | } | |
d2e4a39e | 1957 | else |
14f9c5c9 AS |
1958 | { |
1959 | v = allocate_value (type); | |
0fd88904 | 1960 | bytes = (unsigned char *) value_contents (obj) + offset; |
14f9c5c9 | 1961 | } |
d2e4a39e AS |
1962 | |
1963 | if (obj != NULL) | |
14f9c5c9 AS |
1964 | { |
1965 | VALUE_LVAL (v) = VALUE_LVAL (obj); | |
1966 | if (VALUE_LVAL (obj) == lval_internalvar) | |
4c4b4cd2 | 1967 | VALUE_LVAL (v) = lval_internalvar_component; |
df407dfe | 1968 | VALUE_ADDRESS (v) = VALUE_ADDRESS (obj) + value_offset (obj) + offset; |
9bbda503 AC |
1969 | set_value_bitpos (v, bit_offset + value_bitpos (obj)); |
1970 | set_value_bitsize (v, bit_size); | |
df407dfe | 1971 | if (value_bitpos (v) >= HOST_CHAR_BIT) |
4c4b4cd2 PH |
1972 | { |
1973 | VALUE_ADDRESS (v) += 1; | |
9bbda503 | 1974 | set_value_bitpos (v, value_bitpos (v) - HOST_CHAR_BIT); |
4c4b4cd2 | 1975 | } |
14f9c5c9 AS |
1976 | } |
1977 | else | |
9bbda503 | 1978 | set_value_bitsize (v, bit_size); |
0fd88904 | 1979 | unpacked = (unsigned char *) value_contents (v); |
14f9c5c9 AS |
1980 | |
1981 | srcBitsLeft = bit_size; | |
1982 | nsrc = len; | |
1983 | ntarg = TYPE_LENGTH (type); | |
1984 | sign = 0; | |
1985 | if (bit_size == 0) | |
1986 | { | |
1987 | memset (unpacked, 0, TYPE_LENGTH (type)); | |
1988 | return v; | |
1989 | } | |
1990 | else if (BITS_BIG_ENDIAN) | |
1991 | { | |
d2e4a39e | 1992 | src = len - 1; |
1265e4aa JB |
1993 | if (has_negatives (type) |
1994 | && ((bytes[0] << bit_offset) & (1 << (HOST_CHAR_BIT - 1)))) | |
4c4b4cd2 | 1995 | sign = ~0; |
d2e4a39e AS |
1996 | |
1997 | unusedLS = | |
4c4b4cd2 PH |
1998 | (HOST_CHAR_BIT - (bit_size + bit_offset) % HOST_CHAR_BIT) |
1999 | % HOST_CHAR_BIT; | |
14f9c5c9 AS |
2000 | |
2001 | switch (TYPE_CODE (type)) | |
4c4b4cd2 PH |
2002 | { |
2003 | case TYPE_CODE_ARRAY: | |
2004 | case TYPE_CODE_UNION: | |
2005 | case TYPE_CODE_STRUCT: | |
2006 | /* Non-scalar values must be aligned at a byte boundary... */ | |
2007 | accumSize = | |
2008 | (HOST_CHAR_BIT - bit_size % HOST_CHAR_BIT) % HOST_CHAR_BIT; | |
2009 | /* ... And are placed at the beginning (most-significant) bytes | |
2010 | of the target. */ | |
529cad9c | 2011 | targ = (bit_size + HOST_CHAR_BIT - 1) / HOST_CHAR_BIT - 1; |
4c4b4cd2 PH |
2012 | break; |
2013 | default: | |
2014 | accumSize = 0; | |
2015 | targ = TYPE_LENGTH (type) - 1; | |
2016 | break; | |
2017 | } | |
14f9c5c9 | 2018 | } |
d2e4a39e | 2019 | else |
14f9c5c9 AS |
2020 | { |
2021 | int sign_bit_offset = (bit_size + bit_offset - 1) % 8; | |
2022 | ||
2023 | src = targ = 0; | |
2024 | unusedLS = bit_offset; | |
2025 | accumSize = 0; | |
2026 | ||
d2e4a39e | 2027 | if (has_negatives (type) && (bytes[len - 1] & (1 << sign_bit_offset))) |
4c4b4cd2 | 2028 | sign = ~0; |
14f9c5c9 | 2029 | } |
d2e4a39e | 2030 | |
14f9c5c9 AS |
2031 | accum = 0; |
2032 | while (nsrc > 0) | |
2033 | { | |
2034 | /* Mask for removing bits of the next source byte that are not | |
4c4b4cd2 | 2035 | part of the value. */ |
d2e4a39e | 2036 | unsigned int unusedMSMask = |
4c4b4cd2 PH |
2037 | (1 << (srcBitsLeft >= HOST_CHAR_BIT ? HOST_CHAR_BIT : srcBitsLeft)) - |
2038 | 1; | |
2039 | /* Sign-extend bits for this byte. */ | |
14f9c5c9 | 2040 | unsigned int signMask = sign & ~unusedMSMask; |
d2e4a39e | 2041 | accum |= |
4c4b4cd2 | 2042 | (((bytes[src] >> unusedLS) & unusedMSMask) | signMask) << accumSize; |
14f9c5c9 | 2043 | accumSize += HOST_CHAR_BIT - unusedLS; |
d2e4a39e | 2044 | if (accumSize >= HOST_CHAR_BIT) |
4c4b4cd2 PH |
2045 | { |
2046 | unpacked[targ] = accum & ~(~0L << HOST_CHAR_BIT); | |
2047 | accumSize -= HOST_CHAR_BIT; | |
2048 | accum >>= HOST_CHAR_BIT; | |
2049 | ntarg -= 1; | |
2050 | targ += delta; | |
2051 | } | |
14f9c5c9 AS |
2052 | srcBitsLeft -= HOST_CHAR_BIT - unusedLS; |
2053 | unusedLS = 0; | |
2054 | nsrc -= 1; | |
2055 | src += delta; | |
2056 | } | |
2057 | while (ntarg > 0) | |
2058 | { | |
2059 | accum |= sign << accumSize; | |
2060 | unpacked[targ] = accum & ~(~0L << HOST_CHAR_BIT); | |
2061 | accumSize -= HOST_CHAR_BIT; | |
2062 | accum >>= HOST_CHAR_BIT; | |
2063 | ntarg -= 1; | |
2064 | targ += delta; | |
2065 | } | |
2066 | ||
2067 | return v; | |
2068 | } | |
d2e4a39e | 2069 | |
14f9c5c9 AS |
2070 | /* Move N bits from SOURCE, starting at bit offset SRC_OFFSET to |
2071 | TARGET, starting at bit offset TARG_OFFSET. SOURCE and TARGET must | |
4c4b4cd2 | 2072 | not overlap. */ |
14f9c5c9 | 2073 | static void |
fc1a4b47 | 2074 | move_bits (gdb_byte *target, int targ_offset, const gdb_byte *source, |
0fd88904 | 2075 | int src_offset, int n) |
14f9c5c9 AS |
2076 | { |
2077 | unsigned int accum, mask; | |
2078 | int accum_bits, chunk_size; | |
2079 | ||
2080 | target += targ_offset / HOST_CHAR_BIT; | |
2081 | targ_offset %= HOST_CHAR_BIT; | |
2082 | source += src_offset / HOST_CHAR_BIT; | |
2083 | src_offset %= HOST_CHAR_BIT; | |
d2e4a39e | 2084 | if (BITS_BIG_ENDIAN) |
14f9c5c9 AS |
2085 | { |
2086 | accum = (unsigned char) *source; | |
2087 | source += 1; | |
2088 | accum_bits = HOST_CHAR_BIT - src_offset; | |
2089 | ||
d2e4a39e | 2090 | while (n > 0) |
4c4b4cd2 PH |
2091 | { |
2092 | int unused_right; | |
2093 | accum = (accum << HOST_CHAR_BIT) + (unsigned char) *source; | |
2094 | accum_bits += HOST_CHAR_BIT; | |
2095 | source += 1; | |
2096 | chunk_size = HOST_CHAR_BIT - targ_offset; | |
2097 | if (chunk_size > n) | |
2098 | chunk_size = n; | |
2099 | unused_right = HOST_CHAR_BIT - (chunk_size + targ_offset); | |
2100 | mask = ((1 << chunk_size) - 1) << unused_right; | |
2101 | *target = | |
2102 | (*target & ~mask) | |
2103 | | ((accum >> (accum_bits - chunk_size - unused_right)) & mask); | |
2104 | n -= chunk_size; | |
2105 | accum_bits -= chunk_size; | |
2106 | target += 1; | |
2107 | targ_offset = 0; | |
2108 | } | |
14f9c5c9 AS |
2109 | } |
2110 | else | |
2111 | { | |
2112 | accum = (unsigned char) *source >> src_offset; | |
2113 | source += 1; | |
2114 | accum_bits = HOST_CHAR_BIT - src_offset; | |
2115 | ||
d2e4a39e | 2116 | while (n > 0) |
4c4b4cd2 PH |
2117 | { |
2118 | accum = accum + ((unsigned char) *source << accum_bits); | |
2119 | accum_bits += HOST_CHAR_BIT; | |
2120 | source += 1; | |
2121 | chunk_size = HOST_CHAR_BIT - targ_offset; | |
2122 | if (chunk_size > n) | |
2123 | chunk_size = n; | |
2124 | mask = ((1 << chunk_size) - 1) << targ_offset; | |
2125 | *target = (*target & ~mask) | ((accum << targ_offset) & mask); | |
2126 | n -= chunk_size; | |
2127 | accum_bits -= chunk_size; | |
2128 | accum >>= chunk_size; | |
2129 | target += 1; | |
2130 | targ_offset = 0; | |
2131 | } | |
14f9c5c9 AS |
2132 | } |
2133 | } | |
2134 | ||
14f9c5c9 AS |
2135 | /* Store the contents of FROMVAL into the location of TOVAL. |
2136 | Return a new value with the location of TOVAL and contents of | |
2137 | FROMVAL. Handles assignment into packed fields that have | |
4c4b4cd2 | 2138 | floating-point or non-scalar types. */ |
14f9c5c9 | 2139 | |
d2e4a39e AS |
2140 | static struct value * |
2141 | ada_value_assign (struct value *toval, struct value *fromval) | |
14f9c5c9 | 2142 | { |
df407dfe AC |
2143 | struct type *type = value_type (toval); |
2144 | int bits = value_bitsize (toval); | |
14f9c5c9 | 2145 | |
52ce6436 PH |
2146 | toval = ada_coerce_ref (toval); |
2147 | fromval = ada_coerce_ref (fromval); | |
2148 | ||
2149 | if (ada_is_direct_array_type (value_type (toval))) | |
2150 | toval = ada_coerce_to_simple_array (toval); | |
2151 | if (ada_is_direct_array_type (value_type (fromval))) | |
2152 | fromval = ada_coerce_to_simple_array (fromval); | |
2153 | ||
88e3b34b | 2154 | if (!deprecated_value_modifiable (toval)) |
323e0a4a | 2155 | error (_("Left operand of assignment is not a modifiable lvalue.")); |
14f9c5c9 | 2156 | |
d2e4a39e | 2157 | if (VALUE_LVAL (toval) == lval_memory |
14f9c5c9 | 2158 | && bits > 0 |
d2e4a39e | 2159 | && (TYPE_CODE (type) == TYPE_CODE_FLT |
4c4b4cd2 | 2160 | || TYPE_CODE (type) == TYPE_CODE_STRUCT)) |
14f9c5c9 | 2161 | { |
df407dfe AC |
2162 | int len = (value_bitpos (toval) |
2163 | + bits + HOST_CHAR_BIT - 1) / HOST_CHAR_BIT; | |
d2e4a39e AS |
2164 | char *buffer = (char *) alloca (len); |
2165 | struct value *val; | |
52ce6436 | 2166 | CORE_ADDR to_addr = VALUE_ADDRESS (toval) + value_offset (toval); |
14f9c5c9 AS |
2167 | |
2168 | if (TYPE_CODE (type) == TYPE_CODE_FLT) | |
4c4b4cd2 | 2169 | fromval = value_cast (type, fromval); |
14f9c5c9 | 2170 | |
52ce6436 | 2171 | read_memory (to_addr, buffer, len); |
14f9c5c9 | 2172 | if (BITS_BIG_ENDIAN) |
df407dfe | 2173 | move_bits (buffer, value_bitpos (toval), |
0fd88904 | 2174 | value_contents (fromval), |
df407dfe | 2175 | TYPE_LENGTH (value_type (fromval)) * TARGET_CHAR_BIT - |
4c4b4cd2 | 2176 | bits, bits); |
14f9c5c9 | 2177 | else |
0fd88904 | 2178 | move_bits (buffer, value_bitpos (toval), value_contents (fromval), |
4c4b4cd2 | 2179 | 0, bits); |
52ce6436 PH |
2180 | write_memory (to_addr, buffer, len); |
2181 | if (deprecated_memory_changed_hook) | |
2182 | deprecated_memory_changed_hook (to_addr, len); | |
2183 | ||
14f9c5c9 | 2184 | val = value_copy (toval); |
0fd88904 | 2185 | memcpy (value_contents_raw (val), value_contents (fromval), |
4c4b4cd2 | 2186 | TYPE_LENGTH (type)); |
04624583 | 2187 | deprecated_set_value_type (val, type); |
d2e4a39e | 2188 | |
14f9c5c9 AS |
2189 | return val; |
2190 | } | |
2191 | ||
2192 | return value_assign (toval, fromval); | |
2193 | } | |
2194 | ||
2195 | ||
52ce6436 PH |
2196 | /* Given that COMPONENT is a memory lvalue that is part of the lvalue |
2197 | * CONTAINER, assign the contents of VAL to COMPONENTS's place in | |
2198 | * CONTAINER. Modifies the VALUE_CONTENTS of CONTAINER only, not | |
2199 | * COMPONENT, and not the inferior's memory. The current contents | |
2200 | * of COMPONENT are ignored. */ | |
2201 | static void | |
2202 | value_assign_to_component (struct value *container, struct value *component, | |
2203 | struct value *val) | |
2204 | { | |
2205 | LONGEST offset_in_container = | |
2206 | (LONGEST) (VALUE_ADDRESS (component) + value_offset (component) | |
2207 | - VALUE_ADDRESS (container) - value_offset (container)); | |
2208 | int bit_offset_in_container = | |
2209 | value_bitpos (component) - value_bitpos (container); | |
2210 | int bits; | |
2211 | ||
2212 | val = value_cast (value_type (component), val); | |
2213 | ||
2214 | if (value_bitsize (component) == 0) | |
2215 | bits = TARGET_CHAR_BIT * TYPE_LENGTH (value_type (component)); | |
2216 | else | |
2217 | bits = value_bitsize (component); | |
2218 | ||
2219 | if (BITS_BIG_ENDIAN) | |
2220 | move_bits (value_contents_writeable (container) + offset_in_container, | |
2221 | value_bitpos (container) + bit_offset_in_container, | |
2222 | value_contents (val), | |
2223 | TYPE_LENGTH (value_type (component)) * TARGET_CHAR_BIT - bits, | |
2224 | bits); | |
2225 | else | |
2226 | move_bits (value_contents_writeable (container) + offset_in_container, | |
2227 | value_bitpos (container) + bit_offset_in_container, | |
2228 | value_contents (val), 0, bits); | |
2229 | } | |
2230 | ||
4c4b4cd2 PH |
2231 | /* The value of the element of array ARR at the ARITY indices given in IND. |
2232 | ARR may be either a simple array, GNAT array descriptor, or pointer | |
14f9c5c9 AS |
2233 | thereto. */ |
2234 | ||
d2e4a39e AS |
2235 | struct value * |
2236 | ada_value_subscript (struct value *arr, int arity, struct value **ind) | |
14f9c5c9 AS |
2237 | { |
2238 | int k; | |
d2e4a39e AS |
2239 | struct value *elt; |
2240 | struct type *elt_type; | |
14f9c5c9 AS |
2241 | |
2242 | elt = ada_coerce_to_simple_array (arr); | |
2243 | ||
df407dfe | 2244 | elt_type = ada_check_typedef (value_type (elt)); |
d2e4a39e | 2245 | if (TYPE_CODE (elt_type) == TYPE_CODE_ARRAY |
14f9c5c9 AS |
2246 | && TYPE_FIELD_BITSIZE (elt_type, 0) > 0) |
2247 | return value_subscript_packed (elt, arity, ind); | |
2248 | ||
2249 | for (k = 0; k < arity; k += 1) | |
2250 | { | |
2251 | if (TYPE_CODE (elt_type) != TYPE_CODE_ARRAY) | |
323e0a4a | 2252 | error (_("too many subscripts (%d expected)"), k); |
14f9c5c9 AS |
2253 | elt = value_subscript (elt, value_pos_atr (ind[k])); |
2254 | } | |
2255 | return elt; | |
2256 | } | |
2257 | ||
2258 | /* Assuming ARR is a pointer to a standard GDB array of type TYPE, the | |
2259 | value of the element of *ARR at the ARITY indices given in | |
4c4b4cd2 | 2260 | IND. Does not read the entire array into memory. */ |
14f9c5c9 | 2261 | |
d2e4a39e AS |
2262 | struct value * |
2263 | ada_value_ptr_subscript (struct value *arr, struct type *type, int arity, | |
4c4b4cd2 | 2264 | struct value **ind) |
14f9c5c9 AS |
2265 | { |
2266 | int k; | |
2267 | ||
2268 | for (k = 0; k < arity; k += 1) | |
2269 | { | |
2270 | LONGEST lwb, upb; | |
d2e4a39e | 2271 | struct value *idx; |
14f9c5c9 AS |
2272 | |
2273 | if (TYPE_CODE (type) != TYPE_CODE_ARRAY) | |
323e0a4a | 2274 | error (_("too many subscripts (%d expected)"), k); |
d2e4a39e | 2275 | arr = value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (type)), |
4c4b4cd2 | 2276 | value_copy (arr)); |
14f9c5c9 | 2277 | get_discrete_bounds (TYPE_INDEX_TYPE (type), &lwb, &upb); |
4c4b4cd2 PH |
2278 | idx = value_pos_atr (ind[k]); |
2279 | if (lwb != 0) | |
2280 | idx = value_sub (idx, value_from_longest (builtin_type_int, lwb)); | |
14f9c5c9 AS |
2281 | arr = value_add (arr, idx); |
2282 | type = TYPE_TARGET_TYPE (type); | |
2283 | } | |
2284 | ||
2285 | return value_ind (arr); | |
2286 | } | |
2287 | ||
0b5d8877 PH |
2288 | /* Given that ARRAY_PTR is a pointer or reference to an array of type TYPE (the |
2289 | actual type of ARRAY_PTR is ignored), returns a reference to | |
2290 | the Ada slice of HIGH-LOW+1 elements starting at index LOW. The lower | |
2291 | bound of this array is LOW, as per Ada rules. */ | |
2292 | static struct value * | |
6c038f32 | 2293 | ada_value_slice_ptr (struct value *array_ptr, struct type *type, |
0b5d8877 PH |
2294 | int low, int high) |
2295 | { | |
6c038f32 | 2296 | CORE_ADDR base = value_as_address (array_ptr) |
0b5d8877 PH |
2297 | + ((low - TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type))) |
2298 | * TYPE_LENGTH (TYPE_TARGET_TYPE (type))); | |
6c038f32 PH |
2299 | struct type *index_type = |
2300 | create_range_type (NULL, TYPE_TARGET_TYPE (TYPE_INDEX_TYPE (type)), | |
0b5d8877 | 2301 | low, high); |
6c038f32 | 2302 | struct type *slice_type = |
0b5d8877 PH |
2303 | create_array_type (NULL, TYPE_TARGET_TYPE (type), index_type); |
2304 | return value_from_pointer (lookup_reference_type (slice_type), base); | |
2305 | } | |
2306 | ||
2307 | ||
2308 | static struct value * | |
2309 | ada_value_slice (struct value *array, int low, int high) | |
2310 | { | |
df407dfe | 2311 | struct type *type = value_type (array); |
6c038f32 | 2312 | struct type *index_type = |
0b5d8877 | 2313 | create_range_type (NULL, TYPE_INDEX_TYPE (type), low, high); |
6c038f32 | 2314 | struct type *slice_type = |
0b5d8877 | 2315 | create_array_type (NULL, TYPE_TARGET_TYPE (type), index_type); |
6c038f32 | 2316 | return value_cast (slice_type, value_slice (array, low, high - low + 1)); |
0b5d8877 PH |
2317 | } |
2318 | ||
14f9c5c9 AS |
2319 | /* If type is a record type in the form of a standard GNAT array |
2320 | descriptor, returns the number of dimensions for type. If arr is a | |
2321 | simple array, returns the number of "array of"s that prefix its | |
4c4b4cd2 | 2322 | type designation. Otherwise, returns 0. */ |
14f9c5c9 AS |
2323 | |
2324 | int | |
d2e4a39e | 2325 | ada_array_arity (struct type *type) |
14f9c5c9 AS |
2326 | { |
2327 | int arity; | |
2328 | ||
2329 | if (type == NULL) | |
2330 | return 0; | |
2331 | ||
2332 | type = desc_base_type (type); | |
2333 | ||
2334 | arity = 0; | |
d2e4a39e | 2335 | if (TYPE_CODE (type) == TYPE_CODE_STRUCT) |
14f9c5c9 | 2336 | return desc_arity (desc_bounds_type (type)); |
d2e4a39e AS |
2337 | else |
2338 | while (TYPE_CODE (type) == TYPE_CODE_ARRAY) | |
14f9c5c9 | 2339 | { |
4c4b4cd2 | 2340 | arity += 1; |
61ee279c | 2341 | type = ada_check_typedef (TYPE_TARGET_TYPE (type)); |
14f9c5c9 | 2342 | } |
d2e4a39e | 2343 | |
14f9c5c9 AS |
2344 | return arity; |
2345 | } | |
2346 | ||
2347 | /* If TYPE is a record type in the form of a standard GNAT array | |
2348 | descriptor or a simple array type, returns the element type for | |
2349 | TYPE after indexing by NINDICES indices, or by all indices if | |
4c4b4cd2 | 2350 | NINDICES is -1. Otherwise, returns NULL. */ |
14f9c5c9 | 2351 | |
d2e4a39e AS |
2352 | struct type * |
2353 | ada_array_element_type (struct type *type, int nindices) | |
14f9c5c9 AS |
2354 | { |
2355 | type = desc_base_type (type); | |
2356 | ||
d2e4a39e | 2357 | if (TYPE_CODE (type) == TYPE_CODE_STRUCT) |
14f9c5c9 AS |
2358 | { |
2359 | int k; | |
d2e4a39e | 2360 | struct type *p_array_type; |
14f9c5c9 AS |
2361 | |
2362 | p_array_type = desc_data_type (type); | |
2363 | ||
2364 | k = ada_array_arity (type); | |
2365 | if (k == 0) | |
4c4b4cd2 | 2366 | return NULL; |
d2e4a39e | 2367 | |
4c4b4cd2 | 2368 | /* Initially p_array_type = elt_type(*)[]...(k times)...[]. */ |
14f9c5c9 | 2369 | if (nindices >= 0 && k > nindices) |
4c4b4cd2 | 2370 | k = nindices; |
14f9c5c9 | 2371 | p_array_type = TYPE_TARGET_TYPE (p_array_type); |
d2e4a39e | 2372 | while (k > 0 && p_array_type != NULL) |
4c4b4cd2 | 2373 | { |
61ee279c | 2374 | p_array_type = ada_check_typedef (TYPE_TARGET_TYPE (p_array_type)); |
4c4b4cd2 PH |
2375 | k -= 1; |
2376 | } | |
14f9c5c9 AS |
2377 | return p_array_type; |
2378 | } | |
2379 | else if (TYPE_CODE (type) == TYPE_CODE_ARRAY) | |
2380 | { | |
2381 | while (nindices != 0 && TYPE_CODE (type) == TYPE_CODE_ARRAY) | |
4c4b4cd2 PH |
2382 | { |
2383 | type = TYPE_TARGET_TYPE (type); | |
2384 | nindices -= 1; | |
2385 | } | |
14f9c5c9 AS |
2386 | return type; |
2387 | } | |
2388 | ||
2389 | return NULL; | |
2390 | } | |
2391 | ||
4c4b4cd2 PH |
2392 | /* The type of nth index in arrays of given type (n numbering from 1). |
2393 | Does not examine memory. */ | |
14f9c5c9 | 2394 | |
d2e4a39e AS |
2395 | struct type * |
2396 | ada_index_type (struct type *type, int n) | |
14f9c5c9 | 2397 | { |
4c4b4cd2 PH |
2398 | struct type *result_type; |
2399 | ||
14f9c5c9 AS |
2400 | type = desc_base_type (type); |
2401 | ||
2402 | if (n > ada_array_arity (type)) | |
2403 | return NULL; | |
2404 | ||
4c4b4cd2 | 2405 | if (ada_is_simple_array_type (type)) |
14f9c5c9 AS |
2406 | { |
2407 | int i; | |
2408 | ||
2409 | for (i = 1; i < n; i += 1) | |
4c4b4cd2 PH |
2410 | type = TYPE_TARGET_TYPE (type); |
2411 | result_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, 0)); | |
2412 | /* FIXME: The stabs type r(0,0);bound;bound in an array type | |
2413 | has a target type of TYPE_CODE_UNDEF. We compensate here, but | |
76a01679 JB |
2414 | perhaps stabsread.c would make more sense. */ |
2415 | if (result_type == NULL || TYPE_CODE (result_type) == TYPE_CODE_UNDEF) | |
2416 | result_type = builtin_type_int; | |
14f9c5c9 | 2417 | |
4c4b4cd2 | 2418 | return result_type; |
14f9c5c9 | 2419 | } |
d2e4a39e | 2420 | else |
14f9c5c9 AS |
2421 | return desc_index_type (desc_bounds_type (type), n); |
2422 | } | |
2423 | ||
2424 | /* Given that arr is an array type, returns the lower bound of the | |
2425 | Nth index (numbering from 1) if WHICH is 0, and the upper bound if | |
4c4b4cd2 PH |
2426 | WHICH is 1. This returns bounds 0 .. -1 if ARR_TYPE is an |
2427 | array-descriptor type. If TYPEP is non-null, *TYPEP is set to the | |
2428 | bounds type. It works for other arrays with bounds supplied by | |
2429 | run-time quantities other than discriminants. */ | |
14f9c5c9 AS |
2430 | |
2431 | LONGEST | |
d2e4a39e | 2432 | ada_array_bound_from_type (struct type * arr_type, int n, int which, |
4c4b4cd2 | 2433 | struct type ** typep) |
14f9c5c9 | 2434 | { |
d2e4a39e AS |
2435 | struct type *type; |
2436 | struct type *index_type_desc; | |
14f9c5c9 AS |
2437 | |
2438 | if (ada_is_packed_array_type (arr_type)) | |
2439 | arr_type = decode_packed_array_type (arr_type); | |
2440 | ||
4c4b4cd2 | 2441 | if (arr_type == NULL || !ada_is_simple_array_type (arr_type)) |
14f9c5c9 AS |
2442 | { |
2443 | if (typep != NULL) | |
4c4b4cd2 | 2444 | *typep = builtin_type_int; |
d2e4a39e | 2445 | return (LONGEST) - which; |
14f9c5c9 AS |
2446 | } |
2447 | ||
2448 | if (TYPE_CODE (arr_type) == TYPE_CODE_PTR) | |
2449 | type = TYPE_TARGET_TYPE (arr_type); | |
2450 | else | |
2451 | type = arr_type; | |
2452 | ||
2453 | index_type_desc = ada_find_parallel_type (type, "___XA"); | |
d2e4a39e | 2454 | if (index_type_desc == NULL) |
14f9c5c9 | 2455 | { |
d2e4a39e AS |
2456 | struct type *range_type; |
2457 | struct type *index_type; | |
14f9c5c9 | 2458 | |
d2e4a39e | 2459 | while (n > 1) |
4c4b4cd2 PH |
2460 | { |
2461 | type = TYPE_TARGET_TYPE (type); | |
2462 | n -= 1; | |
2463 | } | |
14f9c5c9 AS |
2464 | |
2465 | range_type = TYPE_INDEX_TYPE (type); | |
2466 | index_type = TYPE_TARGET_TYPE (range_type); | |
2467 | if (TYPE_CODE (index_type) == TYPE_CODE_UNDEF) | |
4c4b4cd2 | 2468 | index_type = builtin_type_long; |
14f9c5c9 | 2469 | if (typep != NULL) |
4c4b4cd2 | 2470 | *typep = index_type; |
d2e4a39e | 2471 | return |
4c4b4cd2 PH |
2472 | (LONGEST) (which == 0 |
2473 | ? TYPE_LOW_BOUND (range_type) | |
2474 | : TYPE_HIGH_BOUND (range_type)); | |
14f9c5c9 | 2475 | } |
d2e4a39e | 2476 | else |
14f9c5c9 | 2477 | { |
d2e4a39e | 2478 | struct type *index_type = |
4c4b4cd2 PH |
2479 | to_fixed_range_type (TYPE_FIELD_NAME (index_type_desc, n - 1), |
2480 | NULL, TYPE_OBJFILE (arr_type)); | |
14f9c5c9 | 2481 | if (typep != NULL) |
4c4b4cd2 | 2482 | *typep = TYPE_TARGET_TYPE (index_type); |
d2e4a39e | 2483 | return |
4c4b4cd2 PH |
2484 | (LONGEST) (which == 0 |
2485 | ? TYPE_LOW_BOUND (index_type) | |
2486 | : TYPE_HIGH_BOUND (index_type)); | |
14f9c5c9 AS |
2487 | } |
2488 | } | |
2489 | ||
2490 | /* Given that arr is an array value, returns the lower bound of the | |
2491 | nth index (numbering from 1) if which is 0, and the upper bound if | |
4c4b4cd2 PH |
2492 | which is 1. This routine will also work for arrays with bounds |
2493 | supplied by run-time quantities other than discriminants. */ | |
14f9c5c9 | 2494 | |
d2e4a39e | 2495 | struct value * |
4dc81987 | 2496 | ada_array_bound (struct value *arr, int n, int which) |
14f9c5c9 | 2497 | { |
df407dfe | 2498 | struct type *arr_type = value_type (arr); |
14f9c5c9 AS |
2499 | |
2500 | if (ada_is_packed_array_type (arr_type)) | |
2501 | return ada_array_bound (decode_packed_array (arr), n, which); | |
4c4b4cd2 | 2502 | else if (ada_is_simple_array_type (arr_type)) |
14f9c5c9 | 2503 | { |
d2e4a39e | 2504 | struct type *type; |
14f9c5c9 AS |
2505 | LONGEST v = ada_array_bound_from_type (arr_type, n, which, &type); |
2506 | return value_from_longest (type, v); | |
2507 | } | |
2508 | else | |
2509 | return desc_one_bound (desc_bounds (arr), n, which); | |
2510 | } | |
2511 | ||
2512 | /* Given that arr is an array value, returns the length of the | |
2513 | nth index. This routine will also work for arrays with bounds | |
4c4b4cd2 PH |
2514 | supplied by run-time quantities other than discriminants. |
2515 | Does not work for arrays indexed by enumeration types with representation | |
2516 | clauses at the moment. */ | |
14f9c5c9 | 2517 | |
d2e4a39e AS |
2518 | struct value * |
2519 | ada_array_length (struct value *arr, int n) | |
14f9c5c9 | 2520 | { |
df407dfe | 2521 | struct type *arr_type = ada_check_typedef (value_type (arr)); |
14f9c5c9 AS |
2522 | |
2523 | if (ada_is_packed_array_type (arr_type)) | |
2524 | return ada_array_length (decode_packed_array (arr), n); | |
2525 | ||
4c4b4cd2 | 2526 | if (ada_is_simple_array_type (arr_type)) |
14f9c5c9 | 2527 | { |
d2e4a39e | 2528 | struct type *type; |
14f9c5c9 | 2529 | LONGEST v = |
4c4b4cd2 PH |
2530 | ada_array_bound_from_type (arr_type, n, 1, &type) - |
2531 | ada_array_bound_from_type (arr_type, n, 0, NULL) + 1; | |
14f9c5c9 AS |
2532 | return value_from_longest (type, v); |
2533 | } | |
2534 | else | |
d2e4a39e | 2535 | return |
72d5681a | 2536 | value_from_longest (builtin_type_int, |
4c4b4cd2 PH |
2537 | value_as_long (desc_one_bound (desc_bounds (arr), |
2538 | n, 1)) | |
2539 | - value_as_long (desc_one_bound (desc_bounds (arr), | |
2540 | n, 0)) + 1); | |
2541 | } | |
2542 | ||
2543 | /* An empty array whose type is that of ARR_TYPE (an array type), | |
2544 | with bounds LOW to LOW-1. */ | |
2545 | ||
2546 | static struct value * | |
2547 | empty_array (struct type *arr_type, int low) | |
2548 | { | |
6c038f32 | 2549 | struct type *index_type = |
0b5d8877 PH |
2550 | create_range_type (NULL, TYPE_TARGET_TYPE (TYPE_INDEX_TYPE (arr_type)), |
2551 | low, low - 1); | |
2552 | struct type *elt_type = ada_array_element_type (arr_type, 1); | |
2553 | return allocate_value (create_array_type (NULL, elt_type, index_type)); | |
14f9c5c9 | 2554 | } |
14f9c5c9 | 2555 | \f |
d2e4a39e | 2556 | |
4c4b4cd2 | 2557 | /* Name resolution */ |
14f9c5c9 | 2558 | |
4c4b4cd2 PH |
2559 | /* The "decoded" name for the user-definable Ada operator corresponding |
2560 | to OP. */ | |
14f9c5c9 | 2561 | |
d2e4a39e | 2562 | static const char * |
4c4b4cd2 | 2563 | ada_decoded_op_name (enum exp_opcode op) |
14f9c5c9 AS |
2564 | { |
2565 | int i; | |
2566 | ||
4c4b4cd2 | 2567 | for (i = 0; ada_opname_table[i].encoded != NULL; i += 1) |
14f9c5c9 AS |
2568 | { |
2569 | if (ada_opname_table[i].op == op) | |
4c4b4cd2 | 2570 | return ada_opname_table[i].decoded; |
14f9c5c9 | 2571 | } |
323e0a4a | 2572 | error (_("Could not find operator name for opcode")); |
14f9c5c9 AS |
2573 | } |
2574 | ||
2575 | ||
4c4b4cd2 PH |
2576 | /* Same as evaluate_type (*EXP), but resolves ambiguous symbol |
2577 | references (marked by OP_VAR_VALUE nodes in which the symbol has an | |
2578 | undefined namespace) and converts operators that are | |
2579 | user-defined into appropriate function calls. If CONTEXT_TYPE is | |
14f9c5c9 AS |
2580 | non-null, it provides a preferred result type [at the moment, only |
2581 | type void has any effect---causing procedures to be preferred over | |
2582 | functions in calls]. A null CONTEXT_TYPE indicates that a non-void | |
4c4b4cd2 | 2583 | return type is preferred. May change (expand) *EXP. */ |
14f9c5c9 | 2584 | |
4c4b4cd2 PH |
2585 | static void |
2586 | resolve (struct expression **expp, int void_context_p) | |
14f9c5c9 AS |
2587 | { |
2588 | int pc; | |
2589 | pc = 0; | |
4c4b4cd2 | 2590 | resolve_subexp (expp, &pc, 1, void_context_p ? builtin_type_void : NULL); |
14f9c5c9 AS |
2591 | } |
2592 | ||
4c4b4cd2 PH |
2593 | /* Resolve the operator of the subexpression beginning at |
2594 | position *POS of *EXPP. "Resolving" consists of replacing | |
2595 | the symbols that have undefined namespaces in OP_VAR_VALUE nodes | |
2596 | with their resolutions, replacing built-in operators with | |
2597 | function calls to user-defined operators, where appropriate, and, | |
2598 | when DEPROCEDURE_P is non-zero, converting function-valued variables | |
2599 | into parameterless calls. May expand *EXPP. The CONTEXT_TYPE functions | |
2600 | are as in ada_resolve, above. */ | |
14f9c5c9 | 2601 | |
d2e4a39e | 2602 | static struct value * |
4c4b4cd2 | 2603 | resolve_subexp (struct expression **expp, int *pos, int deprocedure_p, |
76a01679 | 2604 | struct type *context_type) |
14f9c5c9 AS |
2605 | { |
2606 | int pc = *pos; | |
2607 | int i; | |
4c4b4cd2 | 2608 | struct expression *exp; /* Convenience: == *expp. */ |
14f9c5c9 | 2609 | enum exp_opcode op = (*expp)->elts[pc].opcode; |
4c4b4cd2 PH |
2610 | struct value **argvec; /* Vector of operand types (alloca'ed). */ |
2611 | int nargs; /* Number of operands. */ | |
52ce6436 | 2612 | int oplen; |
14f9c5c9 AS |
2613 | |
2614 | argvec = NULL; | |
2615 | nargs = 0; | |
2616 | exp = *expp; | |
2617 | ||
52ce6436 PH |
2618 | /* Pass one: resolve operands, saving their types and updating *pos, |
2619 | if needed. */ | |
14f9c5c9 AS |
2620 | switch (op) |
2621 | { | |
4c4b4cd2 PH |
2622 | case OP_FUNCALL: |
2623 | if (exp->elts[pc + 3].opcode == OP_VAR_VALUE | |
76a01679 JB |
2624 | && SYMBOL_DOMAIN (exp->elts[pc + 5].symbol) == UNDEF_DOMAIN) |
2625 | *pos += 7; | |
4c4b4cd2 PH |
2626 | else |
2627 | { | |
2628 | *pos += 3; | |
2629 | resolve_subexp (expp, pos, 0, NULL); | |
2630 | } | |
2631 | nargs = longest_to_int (exp->elts[pc + 1].longconst); | |
14f9c5c9 AS |
2632 | break; |
2633 | ||
14f9c5c9 | 2634 | case UNOP_ADDR: |
4c4b4cd2 PH |
2635 | *pos += 1; |
2636 | resolve_subexp (expp, pos, 0, NULL); | |
2637 | break; | |
2638 | ||
52ce6436 PH |
2639 | case UNOP_QUAL: |
2640 | *pos += 3; | |
2641 | resolve_subexp (expp, pos, 1, exp->elts[pc + 1].type); | |
4c4b4cd2 PH |
2642 | break; |
2643 | ||
52ce6436 | 2644 | case OP_ATR_MODULUS: |
4c4b4cd2 PH |
2645 | case OP_ATR_SIZE: |
2646 | case OP_ATR_TAG: | |
4c4b4cd2 PH |
2647 | case OP_ATR_FIRST: |
2648 | case OP_ATR_LAST: | |
2649 | case OP_ATR_LENGTH: | |
2650 | case OP_ATR_POS: | |
2651 | case OP_ATR_VAL: | |
4c4b4cd2 PH |
2652 | case OP_ATR_MIN: |
2653 | case OP_ATR_MAX: | |
52ce6436 PH |
2654 | case TERNOP_IN_RANGE: |
2655 | case BINOP_IN_BOUNDS: | |
2656 | case UNOP_IN_RANGE: | |
2657 | case OP_AGGREGATE: | |
2658 | case OP_OTHERS: | |
2659 | case OP_CHOICES: | |
2660 | case OP_POSITIONAL: | |
2661 | case OP_DISCRETE_RANGE: | |
2662 | case OP_NAME: | |
2663 | ada_forward_operator_length (exp, pc, &oplen, &nargs); | |
2664 | *pos += oplen; | |
14f9c5c9 AS |
2665 | break; |
2666 | ||
2667 | case BINOP_ASSIGN: | |
2668 | { | |
4c4b4cd2 PH |
2669 | struct value *arg1; |
2670 | ||
2671 | *pos += 1; | |
2672 | arg1 = resolve_subexp (expp, pos, 0, NULL); | |
2673 | if (arg1 == NULL) | |
2674 | resolve_subexp (expp, pos, 1, NULL); | |
2675 | else | |
df407dfe | 2676 | resolve_subexp (expp, pos, 1, value_type (arg1)); |
4c4b4cd2 | 2677 | break; |
14f9c5c9 AS |
2678 | } |
2679 | ||
4c4b4cd2 | 2680 | case UNOP_CAST: |
4c4b4cd2 PH |
2681 | *pos += 3; |
2682 | nargs = 1; | |
2683 | break; | |
14f9c5c9 | 2684 | |
4c4b4cd2 PH |
2685 | case BINOP_ADD: |
2686 | case BINOP_SUB: | |
2687 | case BINOP_MUL: | |
2688 | case BINOP_DIV: | |
2689 | case BINOP_REM: | |
2690 | case BINOP_MOD: | |
2691 | case BINOP_EXP: | |
2692 | case BINOP_CONCAT: | |
2693 | case BINOP_LOGICAL_AND: | |
2694 | case BINOP_LOGICAL_OR: | |
2695 | case BINOP_BITWISE_AND: | |
2696 | case BINOP_BITWISE_IOR: | |
2697 | case BINOP_BITWISE_XOR: | |
14f9c5c9 | 2698 | |
4c4b4cd2 PH |
2699 | case BINOP_EQUAL: |
2700 | case BINOP_NOTEQUAL: | |
2701 | case BINOP_LESS: | |
2702 | case BINOP_GTR: | |
2703 | case BINOP_LEQ: | |
2704 | case BINOP_GEQ: | |
14f9c5c9 | 2705 | |
4c4b4cd2 PH |
2706 | case BINOP_REPEAT: |
2707 | case BINOP_SUBSCRIPT: | |
2708 | case BINOP_COMMA: | |
14f9c5c9 | 2709 | |
4c4b4cd2 PH |
2710 | case UNOP_NEG: |
2711 | case UNOP_PLUS: | |
2712 | case UNOP_LOGICAL_NOT: | |
2713 | case UNOP_ABS: | |
2714 | case UNOP_IND: | |
2715 | *pos += 1; | |
2716 | nargs = 1; | |
2717 | break; | |
14f9c5c9 | 2718 | |
4c4b4cd2 PH |
2719 | case OP_LONG: |
2720 | case OP_DOUBLE: | |
2721 | case OP_VAR_VALUE: | |
2722 | *pos += 4; | |
2723 | break; | |
14f9c5c9 | 2724 | |
4c4b4cd2 PH |
2725 | case OP_TYPE: |
2726 | case OP_BOOL: | |
2727 | case OP_LAST: | |
2728 | case OP_REGISTER: | |
2729 | case OP_INTERNALVAR: | |
2730 | *pos += 3; | |
2731 | break; | |
14f9c5c9 | 2732 | |
4c4b4cd2 PH |
2733 | case UNOP_MEMVAL: |
2734 | *pos += 3; | |
2735 | nargs = 1; | |
2736 | break; | |
2737 | ||
2738 | case STRUCTOP_STRUCT: | |
2739 | *pos += 4 + BYTES_TO_EXP_ELEM (exp->elts[pc + 1].longconst + 1); | |
2740 | nargs = 1; | |
2741 | break; | |
2742 | ||
4c4b4cd2 | 2743 | case TERNOP_SLICE: |
4c4b4cd2 PH |
2744 | *pos += 1; |
2745 | nargs = 3; | |
2746 | break; | |
2747 | ||
52ce6436 | 2748 | case OP_STRING: |
14f9c5c9 | 2749 | break; |
4c4b4cd2 PH |
2750 | |
2751 | default: | |
323e0a4a | 2752 | error (_("Unexpected operator during name resolution")); |
14f9c5c9 AS |
2753 | } |
2754 | ||
76a01679 | 2755 | argvec = (struct value * *) alloca (sizeof (struct value *) * (nargs + 1)); |
4c4b4cd2 PH |
2756 | for (i = 0; i < nargs; i += 1) |
2757 | argvec[i] = resolve_subexp (expp, pos, 1, NULL); | |
2758 | argvec[i] = NULL; | |
2759 | exp = *expp; | |
2760 | ||
2761 | /* Pass two: perform any resolution on principal operator. */ | |
14f9c5c9 AS |
2762 | switch (op) |
2763 | { | |
2764 | default: | |
2765 | break; | |
2766 | ||
14f9c5c9 | 2767 | case OP_VAR_VALUE: |
4c4b4cd2 | 2768 | if (SYMBOL_DOMAIN (exp->elts[pc + 2].symbol) == UNDEF_DOMAIN) |
76a01679 JB |
2769 | { |
2770 | struct ada_symbol_info *candidates; | |
2771 | int n_candidates; | |
2772 | ||
2773 | n_candidates = | |
2774 | ada_lookup_symbol_list (SYMBOL_LINKAGE_NAME | |
2775 | (exp->elts[pc + 2].symbol), | |
2776 | exp->elts[pc + 1].block, VAR_DOMAIN, | |
2777 | &candidates); | |
2778 | ||
2779 | if (n_candidates > 1) | |
2780 | { | |
2781 | /* Types tend to get re-introduced locally, so if there | |
2782 | are any local symbols that are not types, first filter | |
2783 | out all types. */ | |
2784 | int j; | |
2785 | for (j = 0; j < n_candidates; j += 1) | |
2786 | switch (SYMBOL_CLASS (candidates[j].sym)) | |
2787 | { | |
2788 | case LOC_REGISTER: | |
2789 | case LOC_ARG: | |
2790 | case LOC_REF_ARG: | |
2791 | case LOC_REGPARM: | |
2792 | case LOC_REGPARM_ADDR: | |
2793 | case LOC_LOCAL: | |
2794 | case LOC_LOCAL_ARG: | |
2795 | case LOC_BASEREG: | |
2796 | case LOC_BASEREG_ARG: | |
2797 | case LOC_COMPUTED: | |
2798 | case LOC_COMPUTED_ARG: | |
2799 | goto FoundNonType; | |
2800 | default: | |
2801 | break; | |
2802 | } | |
2803 | FoundNonType: | |
2804 | if (j < n_candidates) | |
2805 | { | |
2806 | j = 0; | |
2807 | while (j < n_candidates) | |
2808 | { | |
2809 | if (SYMBOL_CLASS (candidates[j].sym) == LOC_TYPEDEF) | |
2810 | { | |
2811 | candidates[j] = candidates[n_candidates - 1]; | |
2812 | n_candidates -= 1; | |
2813 | } | |
2814 | else | |
2815 | j += 1; | |
2816 | } | |
2817 | } | |
2818 | } | |
2819 | ||
2820 | if (n_candidates == 0) | |
323e0a4a | 2821 | error (_("No definition found for %s"), |
76a01679 JB |
2822 | SYMBOL_PRINT_NAME (exp->elts[pc + 2].symbol)); |
2823 | else if (n_candidates == 1) | |
2824 | i = 0; | |
2825 | else if (deprocedure_p | |
2826 | && !is_nonfunction (candidates, n_candidates)) | |
2827 | { | |
06d5cf63 JB |
2828 | i = ada_resolve_function |
2829 | (candidates, n_candidates, NULL, 0, | |
2830 | SYMBOL_LINKAGE_NAME (exp->elts[pc + 2].symbol), | |
2831 | context_type); | |
76a01679 | 2832 | if (i < 0) |
323e0a4a | 2833 | error (_("Could not find a match for %s"), |
76a01679 JB |
2834 | SYMBOL_PRINT_NAME (exp->elts[pc + 2].symbol)); |
2835 | } | |
2836 | else | |
2837 | { | |
323e0a4a | 2838 | printf_filtered (_("Multiple matches for %s\n"), |
76a01679 JB |
2839 | SYMBOL_PRINT_NAME (exp->elts[pc + 2].symbol)); |
2840 | user_select_syms (candidates, n_candidates, 1); | |
2841 | i = 0; | |
2842 | } | |
2843 | ||
2844 | exp->elts[pc + 1].block = candidates[i].block; | |
2845 | exp->elts[pc + 2].symbol = candidates[i].sym; | |
1265e4aa JB |
2846 | if (innermost_block == NULL |
2847 | || contained_in (candidates[i].block, innermost_block)) | |
76a01679 JB |
2848 | innermost_block = candidates[i].block; |
2849 | } | |
2850 | ||
2851 | if (deprocedure_p | |
2852 | && (TYPE_CODE (SYMBOL_TYPE (exp->elts[pc + 2].symbol)) | |
2853 | == TYPE_CODE_FUNC)) | |
2854 | { | |
2855 | replace_operator_with_call (expp, pc, 0, 0, | |
2856 | exp->elts[pc + 2].symbol, | |
2857 | exp->elts[pc + 1].block); | |
2858 | exp = *expp; | |
2859 | } | |
14f9c5c9 AS |
2860 | break; |
2861 | ||
2862 | case OP_FUNCALL: | |
2863 | { | |
4c4b4cd2 | 2864 | if (exp->elts[pc + 3].opcode == OP_VAR_VALUE |
76a01679 | 2865 | && SYMBOL_DOMAIN (exp->elts[pc + 5].symbol) == UNDEF_DOMAIN) |
4c4b4cd2 PH |
2866 | { |
2867 | struct ada_symbol_info *candidates; | |
2868 | int n_candidates; | |
2869 | ||
2870 | n_candidates = | |
76a01679 JB |
2871 | ada_lookup_symbol_list (SYMBOL_LINKAGE_NAME |
2872 | (exp->elts[pc + 5].symbol), | |
2873 | exp->elts[pc + 4].block, VAR_DOMAIN, | |
2874 | &candidates); | |
4c4b4cd2 PH |
2875 | if (n_candidates == 1) |
2876 | i = 0; | |
2877 | else | |
2878 | { | |
06d5cf63 JB |
2879 | i = ada_resolve_function |
2880 | (candidates, n_candidates, | |
2881 | argvec, nargs, | |
2882 | SYMBOL_LINKAGE_NAME (exp->elts[pc + 5].symbol), | |
2883 | context_type); | |
4c4b4cd2 | 2884 | if (i < 0) |
323e0a4a | 2885 | error (_("Could not find a match for %s"), |
4c4b4cd2 PH |
2886 | SYMBOL_PRINT_NAME (exp->elts[pc + 5].symbol)); |
2887 | } | |
2888 | ||
2889 | exp->elts[pc + 4].block = candidates[i].block; | |
2890 | exp->elts[pc + 5].symbol = candidates[i].sym; | |
1265e4aa JB |
2891 | if (innermost_block == NULL |
2892 | || contained_in (candidates[i].block, innermost_block)) | |
4c4b4cd2 PH |
2893 | innermost_block = candidates[i].block; |
2894 | } | |
14f9c5c9 AS |
2895 | } |
2896 | break; | |
2897 | case BINOP_ADD: | |
2898 | case BINOP_SUB: | |
2899 | case BINOP_MUL: | |
2900 | case BINOP_DIV: | |
2901 | case BINOP_REM: | |
2902 | case BINOP_MOD: | |
2903 | case BINOP_CONCAT: | |
2904 | case BINOP_BITWISE_AND: | |
2905 | case BINOP_BITWISE_IOR: | |
2906 | case BINOP_BITWISE_XOR: | |
2907 | case BINOP_EQUAL: | |
2908 | case BINOP_NOTEQUAL: | |
2909 | case BINOP_LESS: | |
2910 | case BINOP_GTR: | |
2911 | case BINOP_LEQ: | |
2912 | case BINOP_GEQ: | |
2913 | case BINOP_EXP: | |
2914 | case UNOP_NEG: | |
2915 | case UNOP_PLUS: | |
2916 | case UNOP_LOGICAL_NOT: | |
2917 | case UNOP_ABS: | |
2918 | if (possible_user_operator_p (op, argvec)) | |
4c4b4cd2 PH |
2919 | { |
2920 | struct ada_symbol_info *candidates; | |
2921 | int n_candidates; | |
2922 | ||
2923 | n_candidates = | |
2924 | ada_lookup_symbol_list (ada_encode (ada_decoded_op_name (op)), | |
2925 | (struct block *) NULL, VAR_DOMAIN, | |
2926 | &candidates); | |
2927 | i = ada_resolve_function (candidates, n_candidates, argvec, nargs, | |
76a01679 | 2928 | ada_decoded_op_name (op), NULL); |
4c4b4cd2 PH |
2929 | if (i < 0) |
2930 | break; | |
2931 | ||
76a01679 JB |
2932 | replace_operator_with_call (expp, pc, nargs, 1, |
2933 | candidates[i].sym, candidates[i].block); | |
4c4b4cd2 PH |
2934 | exp = *expp; |
2935 | } | |
14f9c5c9 | 2936 | break; |
4c4b4cd2 PH |
2937 | |
2938 | case OP_TYPE: | |
2939 | return NULL; | |
14f9c5c9 AS |
2940 | } |
2941 | ||
2942 | *pos = pc; | |
2943 | return evaluate_subexp_type (exp, pos); | |
2944 | } | |
2945 | ||
2946 | /* Return non-zero if formal type FTYPE matches actual type ATYPE. If | |
4c4b4cd2 PH |
2947 | MAY_DEREF is non-zero, the formal may be a pointer and the actual |
2948 | a non-pointer. A type of 'void' (which is never a valid expression type) | |
2949 | by convention matches anything. */ | |
14f9c5c9 | 2950 | /* The term "match" here is rather loose. The match is heuristic and |
4c4b4cd2 | 2951 | liberal. FIXME: TOO liberal, in fact. */ |
14f9c5c9 AS |
2952 | |
2953 | static int | |
4dc81987 | 2954 | ada_type_match (struct type *ftype, struct type *atype, int may_deref) |
14f9c5c9 | 2955 | { |
61ee279c PH |
2956 | ftype = ada_check_typedef (ftype); |
2957 | atype = ada_check_typedef (atype); | |
14f9c5c9 AS |
2958 | |
2959 | if (TYPE_CODE (ftype) == TYPE_CODE_REF) | |
2960 | ftype = TYPE_TARGET_TYPE (ftype); | |
2961 | if (TYPE_CODE (atype) == TYPE_CODE_REF) | |
2962 | atype = TYPE_TARGET_TYPE (atype); | |
2963 | ||
d2e4a39e | 2964 | if (TYPE_CODE (ftype) == TYPE_CODE_VOID |
14f9c5c9 AS |
2965 | || TYPE_CODE (atype) == TYPE_CODE_VOID) |
2966 | return 1; | |
2967 | ||
d2e4a39e | 2968 | switch (TYPE_CODE (ftype)) |
14f9c5c9 AS |
2969 | { |
2970 | default: | |
2971 | return 1; | |
2972 | case TYPE_CODE_PTR: | |
2973 | if (TYPE_CODE (atype) == TYPE_CODE_PTR) | |
4c4b4cd2 PH |
2974 | return ada_type_match (TYPE_TARGET_TYPE (ftype), |
2975 | TYPE_TARGET_TYPE (atype), 0); | |
d2e4a39e | 2976 | else |
1265e4aa JB |
2977 | return (may_deref |
2978 | && ada_type_match (TYPE_TARGET_TYPE (ftype), atype, 0)); | |
14f9c5c9 AS |
2979 | case TYPE_CODE_INT: |
2980 | case TYPE_CODE_ENUM: | |
2981 | case TYPE_CODE_RANGE: | |
2982 | switch (TYPE_CODE (atype)) | |
4c4b4cd2 PH |
2983 | { |
2984 | case TYPE_CODE_INT: | |
2985 | case TYPE_CODE_ENUM: | |
2986 | case TYPE_CODE_RANGE: | |
2987 | return 1; | |
2988 | default: | |
2989 | return 0; | |
2990 | } | |
14f9c5c9 AS |
2991 | |
2992 | case TYPE_CODE_ARRAY: | |
d2e4a39e | 2993 | return (TYPE_CODE (atype) == TYPE_CODE_ARRAY |
4c4b4cd2 | 2994 | || ada_is_array_descriptor_type (atype)); |
14f9c5c9 AS |
2995 | |
2996 | case TYPE_CODE_STRUCT: | |
4c4b4cd2 PH |
2997 | if (ada_is_array_descriptor_type (ftype)) |
2998 | return (TYPE_CODE (atype) == TYPE_CODE_ARRAY | |
2999 | || ada_is_array_descriptor_type (atype)); | |
14f9c5c9 | 3000 | else |
4c4b4cd2 PH |
3001 | return (TYPE_CODE (atype) == TYPE_CODE_STRUCT |
3002 | && !ada_is_array_descriptor_type (atype)); | |
14f9c5c9 AS |
3003 | |
3004 | case TYPE_CODE_UNION: | |
3005 | case TYPE_CODE_FLT: | |
3006 | return (TYPE_CODE (atype) == TYPE_CODE (ftype)); | |
3007 | } | |
3008 | } | |
3009 | ||
3010 | /* Return non-zero if the formals of FUNC "sufficiently match" the | |
3011 | vector of actual argument types ACTUALS of size N_ACTUALS. FUNC | |
3012 | may also be an enumeral, in which case it is treated as a 0- | |
4c4b4cd2 | 3013 | argument function. */ |
14f9c5c9 AS |
3014 | |
3015 | static int | |
d2e4a39e | 3016 | ada_args_match (struct symbol *func, struct value **actuals, int n_actuals) |
14f9c5c9 AS |
3017 | { |
3018 | int i; | |
d2e4a39e | 3019 | struct type *func_type = SYMBOL_TYPE (func); |
14f9c5c9 | 3020 | |
1265e4aa JB |
3021 | if (SYMBOL_CLASS (func) == LOC_CONST |
3022 | && TYPE_CODE (func_type) == TYPE_CODE_ENUM) | |
14f9c5c9 AS |
3023 | return (n_actuals == 0); |
3024 | else if (func_type == NULL || TYPE_CODE (func_type) != TYPE_CODE_FUNC) | |
3025 | return 0; | |
3026 | ||
3027 | if (TYPE_NFIELDS (func_type) != n_actuals) | |
3028 | return 0; | |
3029 | ||
3030 | for (i = 0; i < n_actuals; i += 1) | |
3031 | { | |
4c4b4cd2 | 3032 | if (actuals[i] == NULL) |
76a01679 JB |
3033 | return 0; |
3034 | else | |
3035 | { | |
61ee279c | 3036 | struct type *ftype = ada_check_typedef (TYPE_FIELD_TYPE (func_type, i)); |
df407dfe | 3037 | struct type *atype = ada_check_typedef (value_type (actuals[i])); |
4c4b4cd2 | 3038 | |
76a01679 JB |
3039 | if (!ada_type_match (ftype, atype, 1)) |
3040 | return 0; | |
3041 | } | |
14f9c5c9 AS |
3042 | } |
3043 | return 1; | |
3044 | } | |
3045 | ||
3046 | /* False iff function type FUNC_TYPE definitely does not produce a value | |
3047 | compatible with type CONTEXT_TYPE. Conservatively returns 1 if | |
3048 | FUNC_TYPE is not a valid function type with a non-null return type | |
3049 | or an enumerated type. A null CONTEXT_TYPE indicates any non-void type. */ | |
3050 | ||
3051 | static int | |
d2e4a39e | 3052 | return_match (struct type *func_type, struct type *context_type) |
14f9c5c9 | 3053 | { |
d2e4a39e | 3054 | struct type *return_type; |
14f9c5c9 AS |
3055 | |
3056 | if (func_type == NULL) | |
3057 | return 1; | |
3058 | ||
4c4b4cd2 PH |
3059 | if (TYPE_CODE (func_type) == TYPE_CODE_FUNC) |
3060 | return_type = base_type (TYPE_TARGET_TYPE (func_type)); | |
3061 | else | |
3062 | return_type = base_type (func_type); | |
14f9c5c9 AS |
3063 | if (return_type == NULL) |
3064 | return 1; | |
3065 | ||
4c4b4cd2 | 3066 | context_type = base_type (context_type); |
14f9c5c9 AS |
3067 | |
3068 | if (TYPE_CODE (return_type) == TYPE_CODE_ENUM) | |
3069 | return context_type == NULL || return_type == context_type; | |
3070 | else if (context_type == NULL) | |
3071 | return TYPE_CODE (return_type) != TYPE_CODE_VOID; | |
3072 | else | |
3073 | return TYPE_CODE (return_type) == TYPE_CODE (context_type); | |
3074 | } | |
3075 | ||
3076 | ||
4c4b4cd2 | 3077 | /* Returns the index in SYMS[0..NSYMS-1] that contains the symbol for the |
14f9c5c9 | 3078 | function (if any) that matches the types of the NARGS arguments in |
4c4b4cd2 PH |
3079 | ARGS. If CONTEXT_TYPE is non-null and there is at least one match |
3080 | that returns that type, then eliminate matches that don't. If | |
3081 | CONTEXT_TYPE is void and there is at least one match that does not | |
3082 | return void, eliminate all matches that do. | |
3083 | ||
14f9c5c9 AS |
3084 | Asks the user if there is more than one match remaining. Returns -1 |
3085 | if there is no such symbol or none is selected. NAME is used | |
4c4b4cd2 PH |
3086 | solely for messages. May re-arrange and modify SYMS in |
3087 | the process; the index returned is for the modified vector. */ | |
14f9c5c9 | 3088 | |
4c4b4cd2 PH |
3089 | static int |
3090 | ada_resolve_function (struct ada_symbol_info syms[], | |
3091 | int nsyms, struct value **args, int nargs, | |
3092 | const char *name, struct type *context_type) | |
14f9c5c9 AS |
3093 | { |
3094 | int k; | |
4c4b4cd2 | 3095 | int m; /* Number of hits */ |
d2e4a39e AS |
3096 | struct type *fallback; |
3097 | struct type *return_type; | |
14f9c5c9 AS |
3098 | |
3099 | return_type = context_type; | |
3100 | if (context_type == NULL) | |
3101 | fallback = builtin_type_void; | |
3102 | else | |
3103 | fallback = NULL; | |
3104 | ||
d2e4a39e | 3105 | m = 0; |
14f9c5c9 AS |
3106 | while (1) |
3107 | { | |
3108 | for (k = 0; k < nsyms; k += 1) | |
4c4b4cd2 | 3109 | { |
61ee279c | 3110 | struct type *type = ada_check_typedef (SYMBOL_TYPE (syms[k].sym)); |
4c4b4cd2 PH |
3111 | |
3112 | if (ada_args_match (syms[k].sym, args, nargs) | |
3113 | && return_match (type, return_type)) | |
3114 | { | |
3115 | syms[m] = syms[k]; | |
3116 | m += 1; | |
3117 | } | |
3118 | } | |
14f9c5c9 | 3119 | if (m > 0 || return_type == fallback) |
4c4b4cd2 | 3120 | break; |
14f9c5c9 | 3121 | else |
4c4b4cd2 | 3122 | return_type = fallback; |
14f9c5c9 AS |
3123 | } |
3124 | ||
3125 | if (m == 0) | |
3126 | return -1; | |
3127 | else if (m > 1) | |
3128 | { | |
323e0a4a | 3129 | printf_filtered (_("Multiple matches for %s\n"), name); |
4c4b4cd2 | 3130 | user_select_syms (syms, m, 1); |
14f9c5c9 AS |
3131 | return 0; |
3132 | } | |
3133 | return 0; | |
3134 | } | |
3135 | ||
4c4b4cd2 PH |
3136 | /* Returns true (non-zero) iff decoded name N0 should appear before N1 |
3137 | in a listing of choices during disambiguation (see sort_choices, below). | |
3138 | The idea is that overloadings of a subprogram name from the | |
3139 | same package should sort in their source order. We settle for ordering | |
3140 | such symbols by their trailing number (__N or $N). */ | |
3141 | ||
14f9c5c9 | 3142 | static int |
4c4b4cd2 | 3143 | encoded_ordered_before (char *N0, char *N1) |
14f9c5c9 AS |
3144 | { |
3145 | if (N1 == NULL) | |
3146 | return 0; | |
3147 | else if (N0 == NULL) | |
3148 | return 1; | |
3149 | else | |
3150 | { | |
3151 | int k0, k1; | |
d2e4a39e | 3152 | for (k0 = strlen (N0) - 1; k0 > 0 && isdigit (N0[k0]); k0 -= 1) |
4c4b4cd2 | 3153 | ; |
d2e4a39e | 3154 | for (k1 = strlen (N1) - 1; k1 > 0 && isdigit (N1[k1]); k1 -= 1) |
4c4b4cd2 | 3155 | ; |
d2e4a39e | 3156 | if ((N0[k0] == '_' || N0[k0] == '$') && N0[k0 + 1] != '\000' |
4c4b4cd2 PH |
3157 | && (N1[k1] == '_' || N1[k1] == '$') && N1[k1 + 1] != '\000') |
3158 | { | |
3159 | int n0, n1; | |
3160 | n0 = k0; | |
3161 | while (N0[n0] == '_' && n0 > 0 && N0[n0 - 1] == '_') | |
3162 | n0 -= 1; | |
3163 | n1 = k1; | |
3164 | while (N1[n1] == '_' && n1 > 0 && N1[n1 - 1] == '_') | |
3165 | n1 -= 1; | |
3166 | if (n0 == n1 && strncmp (N0, N1, n0) == 0) | |
3167 | return (atoi (N0 + k0 + 1) < atoi (N1 + k1 + 1)); | |
3168 | } | |
14f9c5c9 AS |
3169 | return (strcmp (N0, N1) < 0); |
3170 | } | |
3171 | } | |
d2e4a39e | 3172 | |
4c4b4cd2 PH |
3173 | /* Sort SYMS[0..NSYMS-1] to put the choices in a canonical order by the |
3174 | encoded names. */ | |
3175 | ||
d2e4a39e | 3176 | static void |
4c4b4cd2 | 3177 | sort_choices (struct ada_symbol_info syms[], int nsyms) |
14f9c5c9 | 3178 | { |
4c4b4cd2 | 3179 | int i; |
d2e4a39e | 3180 | for (i = 1; i < nsyms; i += 1) |
14f9c5c9 | 3181 | { |
4c4b4cd2 | 3182 | struct ada_symbol_info sym = syms[i]; |
14f9c5c9 AS |
3183 | int j; |
3184 | ||
d2e4a39e | 3185 | for (j = i - 1; j >= 0; j -= 1) |
4c4b4cd2 PH |
3186 | { |
3187 | if (encoded_ordered_before (SYMBOL_LINKAGE_NAME (syms[j].sym), | |
3188 | SYMBOL_LINKAGE_NAME (sym.sym))) | |
3189 | break; | |
3190 | syms[j + 1] = syms[j]; | |
3191 | } | |
d2e4a39e | 3192 | syms[j + 1] = sym; |
14f9c5c9 AS |
3193 | } |
3194 | } | |
3195 | ||
4c4b4cd2 PH |
3196 | /* Given a list of NSYMS symbols in SYMS, select up to MAX_RESULTS>0 |
3197 | by asking the user (if necessary), returning the number selected, | |
3198 | and setting the first elements of SYMS items. Error if no symbols | |
3199 | selected. */ | |
14f9c5c9 AS |
3200 | |
3201 | /* NOTE: Adapted from decode_line_2 in symtab.c, with which it ought | |
4c4b4cd2 | 3202 | to be re-integrated one of these days. */ |
14f9c5c9 AS |
3203 | |
3204 | int | |
4c4b4cd2 | 3205 | user_select_syms (struct ada_symbol_info *syms, int nsyms, int max_results) |
14f9c5c9 AS |
3206 | { |
3207 | int i; | |
d2e4a39e | 3208 | int *chosen = (int *) alloca (sizeof (int) * nsyms); |
14f9c5c9 AS |
3209 | int n_chosen; |
3210 | int first_choice = (max_results == 1) ? 1 : 2; | |
3211 | ||
3212 | if (max_results < 1) | |
323e0a4a | 3213 | error (_("Request to select 0 symbols!")); |
14f9c5c9 AS |
3214 | if (nsyms <= 1) |
3215 | return nsyms; | |
3216 | ||
323e0a4a | 3217 | printf_unfiltered (_("[0] cancel\n")); |
14f9c5c9 | 3218 | if (max_results > 1) |
323e0a4a | 3219 | printf_unfiltered (_("[1] all\n")); |
14f9c5c9 | 3220 | |
4c4b4cd2 | 3221 | sort_choices (syms, nsyms); |
14f9c5c9 AS |
3222 | |
3223 | for (i = 0; i < nsyms; i += 1) | |
3224 | { | |
4c4b4cd2 PH |
3225 | if (syms[i].sym == NULL) |
3226 | continue; | |
3227 | ||
3228 | if (SYMBOL_CLASS (syms[i].sym) == LOC_BLOCK) | |
3229 | { | |
76a01679 JB |
3230 | struct symtab_and_line sal = |
3231 | find_function_start_sal (syms[i].sym, 1); | |
323e0a4a AC |
3232 | if (sal.symtab == NULL) |
3233 | printf_unfiltered (_("[%d] %s at <no source file available>:%d\n"), | |
3234 | i + first_choice, | |
3235 | SYMBOL_PRINT_NAME (syms[i].sym), | |
3236 | sal.line); | |
3237 | else | |
3238 | printf_unfiltered (_("[%d] %s at %s:%d\n"), i + first_choice, | |
3239 | SYMBOL_PRINT_NAME (syms[i].sym), | |
3240 | sal.symtab->filename, sal.line); | |
4c4b4cd2 PH |
3241 | continue; |
3242 | } | |
d2e4a39e | 3243 | else |
4c4b4cd2 PH |
3244 | { |
3245 | int is_enumeral = | |
3246 | (SYMBOL_CLASS (syms[i].sym) == LOC_CONST | |
3247 | && SYMBOL_TYPE (syms[i].sym) != NULL | |
3248 | && TYPE_CODE (SYMBOL_TYPE (syms[i].sym)) == TYPE_CODE_ENUM); | |
3249 | struct symtab *symtab = symtab_for_sym (syms[i].sym); | |
3250 | ||
3251 | if (SYMBOL_LINE (syms[i].sym) != 0 && symtab != NULL) | |
323e0a4a | 3252 | printf_unfiltered (_("[%d] %s at %s:%d\n"), |
4c4b4cd2 PH |
3253 | i + first_choice, |
3254 | SYMBOL_PRINT_NAME (syms[i].sym), | |
3255 | symtab->filename, SYMBOL_LINE (syms[i].sym)); | |
76a01679 JB |
3256 | else if (is_enumeral |
3257 | && TYPE_NAME (SYMBOL_TYPE (syms[i].sym)) != NULL) | |
4c4b4cd2 | 3258 | { |
a3f17187 | 3259 | printf_unfiltered (("[%d] "), i + first_choice); |
76a01679 JB |
3260 | ada_print_type (SYMBOL_TYPE (syms[i].sym), NULL, |
3261 | gdb_stdout, -1, 0); | |
323e0a4a | 3262 | printf_unfiltered (_("'(%s) (enumeral)\n"), |
4c4b4cd2 PH |
3263 | SYMBOL_PRINT_NAME (syms[i].sym)); |
3264 | } | |
3265 | else if (symtab != NULL) | |
3266 | printf_unfiltered (is_enumeral | |
323e0a4a AC |
3267 | ? _("[%d] %s in %s (enumeral)\n") |
3268 | : _("[%d] %s at %s:?\n"), | |
4c4b4cd2 PH |
3269 | i + first_choice, |
3270 | SYMBOL_PRINT_NAME (syms[i].sym), | |
3271 | symtab->filename); | |
3272 | else | |
3273 | printf_unfiltered (is_enumeral | |
323e0a4a AC |
3274 | ? _("[%d] %s (enumeral)\n") |
3275 | : _("[%d] %s at ?\n"), | |
4c4b4cd2 PH |
3276 | i + first_choice, |
3277 | SYMBOL_PRINT_NAME (syms[i].sym)); | |
3278 | } | |
14f9c5c9 | 3279 | } |
d2e4a39e | 3280 | |
14f9c5c9 | 3281 | n_chosen = get_selections (chosen, nsyms, max_results, max_results > 1, |
4c4b4cd2 | 3282 | "overload-choice"); |
14f9c5c9 AS |
3283 | |
3284 | for (i = 0; i < n_chosen; i += 1) | |
4c4b4cd2 | 3285 | syms[i] = syms[chosen[i]]; |
14f9c5c9 AS |
3286 | |
3287 | return n_chosen; | |
3288 | } | |
3289 | ||
3290 | /* Read and validate a set of numeric choices from the user in the | |
4c4b4cd2 | 3291 | range 0 .. N_CHOICES-1. Place the results in increasing |
14f9c5c9 AS |
3292 | order in CHOICES[0 .. N-1], and return N. |
3293 | ||
3294 | The user types choices as a sequence of numbers on one line | |
3295 | separated by blanks, encoding them as follows: | |
3296 | ||
4c4b4cd2 | 3297 | + A choice of 0 means to cancel the selection, throwing an error. |
14f9c5c9 AS |
3298 | + If IS_ALL_CHOICE, a choice of 1 selects the entire set 0 .. N_CHOICES-1. |
3299 | + The user chooses k by typing k+IS_ALL_CHOICE+1. | |
3300 | ||
4c4b4cd2 | 3301 | The user is not allowed to choose more than MAX_RESULTS values. |
14f9c5c9 AS |
3302 | |
3303 | ANNOTATION_SUFFIX, if present, is used to annotate the input | |
4c4b4cd2 | 3304 | prompts (for use with the -f switch). */ |
14f9c5c9 AS |
3305 | |
3306 | int | |
d2e4a39e | 3307 | get_selections (int *choices, int n_choices, int max_results, |
4c4b4cd2 | 3308 | int is_all_choice, char *annotation_suffix) |
14f9c5c9 | 3309 | { |
d2e4a39e AS |
3310 | char *args; |
3311 | const char *prompt; | |
14f9c5c9 AS |
3312 | int n_chosen; |
3313 | int first_choice = is_all_choice ? 2 : 1; | |
d2e4a39e | 3314 | |
14f9c5c9 AS |
3315 | prompt = getenv ("PS2"); |
3316 | if (prompt == NULL) | |
3317 | prompt = ">"; | |
3318 | ||
a3f17187 | 3319 | printf_unfiltered (("%s "), prompt); |
14f9c5c9 AS |
3320 | gdb_flush (gdb_stdout); |
3321 | ||
3322 | args = command_line_input ((char *) NULL, 0, annotation_suffix); | |
d2e4a39e | 3323 | |
14f9c5c9 | 3324 | if (args == NULL) |
323e0a4a | 3325 | error_no_arg (_("one or more choice numbers")); |
14f9c5c9 AS |
3326 | |
3327 | n_chosen = 0; | |
76a01679 | 3328 | |
4c4b4cd2 PH |
3329 | /* Set choices[0 .. n_chosen-1] to the users' choices in ascending |
3330 | order, as given in args. Choices are validated. */ | |
14f9c5c9 AS |
3331 | while (1) |
3332 | { | |
d2e4a39e | 3333 | char *args2; |
14f9c5c9 AS |
3334 | int choice, j; |
3335 | ||
3336 | while (isspace (*args)) | |
4c4b4cd2 | 3337 | args += 1; |
14f9c5c9 | 3338 | if (*args == '\0' && n_chosen == 0) |
323e0a4a | 3339 | error_no_arg (_("one or more choice numbers")); |
14f9c5c9 | 3340 | else if (*args == '\0') |
4c4b4cd2 | 3341 | break; |
14f9c5c9 AS |
3342 | |
3343 | choice = strtol (args, &args2, 10); | |
d2e4a39e | 3344 | if (args == args2 || choice < 0 |
4c4b4cd2 | 3345 | || choice > n_choices + first_choice - 1) |
323e0a4a | 3346 | error (_("Argument must be choice number")); |
14f9c5c9 AS |
3347 | args = args2; |
3348 | ||
d2e4a39e | 3349 | if (choice == 0) |
323e0a4a | 3350 | error (_("cancelled")); |
14f9c5c9 AS |
3351 | |
3352 | if (choice < first_choice) | |
4c4b4cd2 PH |
3353 | { |
3354 | n_chosen = n_choices; | |
3355 | for (j = 0; j < n_choices; j += 1) | |
3356 | choices[j] = j; | |
3357 | break; | |
3358 | } | |
14f9c5c9 AS |
3359 | choice -= first_choice; |
3360 | ||
d2e4a39e | 3361 | for (j = n_chosen - 1; j >= 0 && choice < choices[j]; j -= 1) |
4c4b4cd2 PH |
3362 | { |
3363 | } | |
14f9c5c9 AS |
3364 | |
3365 | if (j < 0 || choice != choices[j]) | |
4c4b4cd2 PH |
3366 | { |
3367 | int k; | |
3368 | for (k = n_chosen - 1; k > j; k -= 1) | |
3369 | choices[k + 1] = choices[k]; | |
3370 | choices[j + 1] = choice; | |
3371 | n_chosen += 1; | |
3372 | } | |
14f9c5c9 AS |
3373 | } |
3374 | ||
3375 | if (n_chosen > max_results) | |
323e0a4a | 3376 | error (_("Select no more than %d of the above"), max_results); |
d2e4a39e | 3377 | |
14f9c5c9 AS |
3378 | return n_chosen; |
3379 | } | |
3380 | ||
4c4b4cd2 PH |
3381 | /* Replace the operator of length OPLEN at position PC in *EXPP with a call |
3382 | on the function identified by SYM and BLOCK, and taking NARGS | |
3383 | arguments. Update *EXPP as needed to hold more space. */ | |
14f9c5c9 AS |
3384 | |
3385 | static void | |
d2e4a39e | 3386 | replace_operator_with_call (struct expression **expp, int pc, int nargs, |
4c4b4cd2 PH |
3387 | int oplen, struct symbol *sym, |
3388 | struct block *block) | |
14f9c5c9 AS |
3389 | { |
3390 | /* A new expression, with 6 more elements (3 for funcall, 4 for function | |
4c4b4cd2 | 3391 | symbol, -oplen for operator being replaced). */ |
d2e4a39e | 3392 | struct expression *newexp = (struct expression *) |
14f9c5c9 | 3393 | xmalloc (sizeof (struct expression) |
4c4b4cd2 | 3394 | + EXP_ELEM_TO_BYTES ((*expp)->nelts + 7 - oplen)); |
d2e4a39e | 3395 | struct expression *exp = *expp; |
14f9c5c9 AS |
3396 | |
3397 | newexp->nelts = exp->nelts + 7 - oplen; | |
3398 | newexp->language_defn = exp->language_defn; | |
3399 | memcpy (newexp->elts, exp->elts, EXP_ELEM_TO_BYTES (pc)); | |
d2e4a39e | 3400 | memcpy (newexp->elts + pc + 7, exp->elts + pc + oplen, |
4c4b4cd2 | 3401 | EXP_ELEM_TO_BYTES (exp->nelts - pc - oplen)); |
14f9c5c9 AS |
3402 | |
3403 | newexp->elts[pc].opcode = newexp->elts[pc + 2].opcode = OP_FUNCALL; | |
3404 | newexp->elts[pc + 1].longconst = (LONGEST) nargs; | |
3405 | ||
3406 | newexp->elts[pc + 3].opcode = newexp->elts[pc + 6].opcode = OP_VAR_VALUE; | |
3407 | newexp->elts[pc + 4].block = block; | |
3408 | newexp->elts[pc + 5].symbol = sym; | |
3409 | ||
3410 | *expp = newexp; | |
aacb1f0a | 3411 | xfree (exp); |
d2e4a39e | 3412 | } |
14f9c5c9 AS |
3413 | |
3414 | /* Type-class predicates */ | |
3415 | ||
4c4b4cd2 PH |
3416 | /* True iff TYPE is numeric (i.e., an INT, RANGE (of numeric type), |
3417 | or FLOAT). */ | |
14f9c5c9 AS |
3418 | |
3419 | static int | |
d2e4a39e | 3420 | numeric_type_p (struct type *type) |
14f9c5c9 AS |
3421 | { |
3422 | if (type == NULL) | |
3423 | return 0; | |
d2e4a39e AS |
3424 | else |
3425 | { | |
3426 | switch (TYPE_CODE (type)) | |
4c4b4cd2 PH |
3427 | { |
3428 | case TYPE_CODE_INT: | |
3429 | case TYPE_CODE_FLT: | |
3430 | return 1; | |
3431 | case TYPE_CODE_RANGE: | |
3432 | return (type == TYPE_TARGET_TYPE (type) | |
3433 | || numeric_type_p (TYPE_TARGET_TYPE (type))); | |
3434 | default: | |
3435 | return 0; | |
3436 | } | |
d2e4a39e | 3437 | } |
14f9c5c9 AS |
3438 | } |
3439 | ||
4c4b4cd2 | 3440 | /* True iff TYPE is integral (an INT or RANGE of INTs). */ |
14f9c5c9 AS |
3441 | |
3442 | static int | |
d2e4a39e | 3443 | integer_type_p (struct type *type) |
14f9c5c9 AS |
3444 | { |
3445 | if (type == NULL) | |
3446 | return 0; | |
d2e4a39e AS |
3447 | else |
3448 | { | |
3449 | switch (TYPE_CODE (type)) | |
4c4b4cd2 PH |
3450 | { |
3451 | case TYPE_CODE_INT: | |
3452 | return 1; | |
3453 | case TYPE_CODE_RANGE: | |
3454 | return (type == TYPE_TARGET_TYPE (type) | |
3455 | || integer_type_p (TYPE_TARGET_TYPE (type))); | |
3456 | default: | |
3457 | return 0; | |
3458 | } | |
d2e4a39e | 3459 | } |
14f9c5c9 AS |
3460 | } |
3461 | ||
4c4b4cd2 | 3462 | /* True iff TYPE is scalar (INT, RANGE, FLOAT, ENUM). */ |
14f9c5c9 AS |
3463 | |
3464 | static int | |
d2e4a39e | 3465 | scalar_type_p (struct type *type) |
14f9c5c9 AS |
3466 | { |
3467 | if (type == NULL) | |
3468 | return 0; | |
d2e4a39e AS |
3469 | else |
3470 | { | |
3471 | switch (TYPE_CODE (type)) | |
4c4b4cd2 PH |
3472 | { |
3473 | case TYPE_CODE_INT: | |
3474 | case TYPE_CODE_RANGE: | |
3475 | case TYPE_CODE_ENUM: | |
3476 | case TYPE_CODE_FLT: | |
3477 | return 1; | |
3478 | default: | |
3479 | return 0; | |
3480 | } | |
d2e4a39e | 3481 | } |
14f9c5c9 AS |
3482 | } |
3483 | ||
4c4b4cd2 | 3484 | /* True iff TYPE is discrete (INT, RANGE, ENUM). */ |
14f9c5c9 AS |
3485 | |
3486 | static int | |
d2e4a39e | 3487 | discrete_type_p (struct type *type) |
14f9c5c9 AS |
3488 | { |
3489 | if (type == NULL) | |
3490 | return 0; | |
d2e4a39e AS |
3491 | else |
3492 | { | |
3493 | switch (TYPE_CODE (type)) | |
4c4b4cd2 PH |
3494 | { |
3495 | case TYPE_CODE_INT: | |
3496 | case TYPE_CODE_RANGE: | |
3497 | case TYPE_CODE_ENUM: | |
3498 | return 1; | |
3499 | default: | |
3500 | return 0; | |
3501 | } | |
d2e4a39e | 3502 | } |
14f9c5c9 AS |
3503 | } |
3504 | ||
4c4b4cd2 PH |
3505 | /* Returns non-zero if OP with operands in the vector ARGS could be |
3506 | a user-defined function. Errs on the side of pre-defined operators | |
3507 | (i.e., result 0). */ | |
14f9c5c9 AS |
3508 | |
3509 | static int | |
d2e4a39e | 3510 | possible_user_operator_p (enum exp_opcode op, struct value *args[]) |
14f9c5c9 | 3511 | { |
76a01679 | 3512 | struct type *type0 = |
df407dfe | 3513 | (args[0] == NULL) ? NULL : ada_check_typedef (value_type (args[0])); |
d2e4a39e | 3514 | struct type *type1 = |
df407dfe | 3515 | (args[1] == NULL) ? NULL : ada_check_typedef (value_type (args[1])); |
d2e4a39e | 3516 | |
4c4b4cd2 PH |
3517 | if (type0 == NULL) |
3518 | return 0; | |
3519 | ||
14f9c5c9 AS |
3520 | switch (op) |
3521 | { | |
3522 | default: | |
3523 | return 0; | |
3524 | ||
3525 | case BINOP_ADD: | |
3526 | case BINOP_SUB: | |
3527 | case BINOP_MUL: | |
3528 | case BINOP_DIV: | |
d2e4a39e | 3529 | return (!(numeric_type_p (type0) && numeric_type_p (type1))); |
14f9c5c9 AS |
3530 | |
3531 | case BINOP_REM: | |
3532 | case BINOP_MOD: | |
3533 | case BINOP_BITWISE_AND: | |
3534 | case BINOP_BITWISE_IOR: | |
3535 | case BINOP_BITWISE_XOR: | |
d2e4a39e | 3536 | return (!(integer_type_p (type0) && integer_type_p (type1))); |
14f9c5c9 AS |
3537 | |
3538 | case BINOP_EQUAL: | |
3539 | case BINOP_NOTEQUAL: | |
3540 | case BINOP_LESS: | |
3541 | case BINOP_GTR: | |
3542 | case BINOP_LEQ: | |
3543 | case BINOP_GEQ: | |
d2e4a39e | 3544 | return (!(scalar_type_p (type0) && scalar_type_p (type1))); |
14f9c5c9 AS |
3545 | |
3546 | case BINOP_CONCAT: | |
1265e4aa JB |
3547 | return |
3548 | ((TYPE_CODE (type0) != TYPE_CODE_ARRAY | |
3549 | && (TYPE_CODE (type0) != TYPE_CODE_PTR | |
3550 | || TYPE_CODE (TYPE_TARGET_TYPE (type0)) != TYPE_CODE_ARRAY)) | |
3551 | || (TYPE_CODE (type1) != TYPE_CODE_ARRAY | |
3552 | && (TYPE_CODE (type1) != TYPE_CODE_PTR | |
c3e5cd34 PH |
3553 | || (TYPE_CODE (TYPE_TARGET_TYPE (type1)) |
3554 | != TYPE_CODE_ARRAY)))); | |
14f9c5c9 AS |
3555 | |
3556 | case BINOP_EXP: | |
d2e4a39e | 3557 | return (!(numeric_type_p (type0) && integer_type_p (type1))); |
14f9c5c9 AS |
3558 | |
3559 | case UNOP_NEG: | |
3560 | case UNOP_PLUS: | |
3561 | case UNOP_LOGICAL_NOT: | |
d2e4a39e AS |
3562 | case UNOP_ABS: |
3563 | return (!numeric_type_p (type0)); | |
14f9c5c9 AS |
3564 | |
3565 | } | |
3566 | } | |
3567 | \f | |
4c4b4cd2 | 3568 | /* Renaming */ |
14f9c5c9 | 3569 | |
4c4b4cd2 PH |
3570 | /* NOTE: In the following, we assume that a renaming type's name may |
3571 | have an ___XD suffix. It would be nice if this went away at some | |
3572 | point. */ | |
14f9c5c9 AS |
3573 | |
3574 | /* If TYPE encodes a renaming, returns the renaming suffix, which | |
4c4b4cd2 PH |
3575 | is XR for an object renaming, XRP for a procedure renaming, XRE for |
3576 | an exception renaming, and XRS for a subprogram renaming. Returns | |
3577 | NULL if NAME encodes none of these. */ | |
3578 | ||
d2e4a39e AS |
3579 | const char * |
3580 | ada_renaming_type (struct type *type) | |
14f9c5c9 AS |
3581 | { |
3582 | if (type != NULL && TYPE_CODE (type) == TYPE_CODE_ENUM) | |
3583 | { | |
d2e4a39e AS |
3584 | const char *name = type_name_no_tag (type); |
3585 | const char *suffix = (name == NULL) ? NULL : strstr (name, "___XR"); | |
3586 | if (suffix == NULL | |
4c4b4cd2 PH |
3587 | || (suffix[5] != '\000' && strchr ("PES_", suffix[5]) == NULL)) |
3588 | return NULL; | |
14f9c5c9 | 3589 | else |
4c4b4cd2 | 3590 | return suffix + 3; |
14f9c5c9 AS |
3591 | } |
3592 | else | |
3593 | return NULL; | |
3594 | } | |
3595 | ||
4c4b4cd2 PH |
3596 | /* Return non-zero iff SYM encodes an object renaming. */ |
3597 | ||
14f9c5c9 | 3598 | int |
d2e4a39e | 3599 | ada_is_object_renaming (struct symbol *sym) |
14f9c5c9 | 3600 | { |
d2e4a39e AS |
3601 | const char *renaming_type = ada_renaming_type (SYMBOL_TYPE (sym)); |
3602 | return renaming_type != NULL | |
14f9c5c9 AS |
3603 | && (renaming_type[2] == '\0' || renaming_type[2] == '_'); |
3604 | } | |
3605 | ||
3606 | /* Assuming that SYM encodes a non-object renaming, returns the original | |
4c4b4cd2 PH |
3607 | name of the renamed entity. The name is good until the end of |
3608 | parsing. */ | |
3609 | ||
3610 | char * | |
d2e4a39e | 3611 | ada_simple_renamed_entity (struct symbol *sym) |
14f9c5c9 | 3612 | { |
d2e4a39e AS |
3613 | struct type *type; |
3614 | const char *raw_name; | |
14f9c5c9 | 3615 | int len; |
d2e4a39e | 3616 | char *result; |
14f9c5c9 AS |
3617 | |
3618 | type = SYMBOL_TYPE (sym); | |
3619 | if (type == NULL || TYPE_NFIELDS (type) < 1) | |
323e0a4a | 3620 | error (_("Improperly encoded renaming.")); |
14f9c5c9 AS |
3621 | |
3622 | raw_name = TYPE_FIELD_NAME (type, 0); | |
3623 | len = (raw_name == NULL ? 0 : strlen (raw_name)) - 5; | |
3624 | if (len <= 0) | |
323e0a4a | 3625 | error (_("Improperly encoded renaming.")); |
14f9c5c9 AS |
3626 | |
3627 | result = xmalloc (len + 1); | |
14f9c5c9 AS |
3628 | strncpy (result, raw_name, len); |
3629 | result[len] = '\000'; | |
3630 | return result; | |
3631 | } | |
52ce6436 | 3632 | |
14f9c5c9 | 3633 | \f |
d2e4a39e | 3634 | |
4c4b4cd2 | 3635 | /* Evaluation: Function Calls */ |
14f9c5c9 | 3636 | |
4c4b4cd2 PH |
3637 | /* Return an lvalue containing the value VAL. This is the identity on |
3638 | lvalues, and otherwise has the side-effect of pushing a copy of VAL | |
3639 | on the stack, using and updating *SP as the stack pointer, and | |
3640 | returning an lvalue whose VALUE_ADDRESS points to the copy. */ | |
14f9c5c9 | 3641 | |
d2e4a39e | 3642 | static struct value * |
4c4b4cd2 | 3643 | ensure_lval (struct value *val, CORE_ADDR *sp) |
14f9c5c9 | 3644 | { |
c3e5cd34 PH |
3645 | if (! VALUE_LVAL (val)) |
3646 | { | |
df407dfe | 3647 | int len = TYPE_LENGTH (ada_check_typedef (value_type (val))); |
c3e5cd34 PH |
3648 | |
3649 | /* The following is taken from the structure-return code in | |
3650 | call_function_by_hand. FIXME: Therefore, some refactoring seems | |
3651 | indicated. */ | |
3652 | if (INNER_THAN (1, 2)) | |
3653 | { | |
3654 | /* Stack grows downward. Align SP and VALUE_ADDRESS (val) after | |
3655 | reserving sufficient space. */ | |
3656 | *sp -= len; | |
3657 | if (gdbarch_frame_align_p (current_gdbarch)) | |
3658 | *sp = gdbarch_frame_align (current_gdbarch, *sp); | |
3659 | VALUE_ADDRESS (val) = *sp; | |
3660 | } | |
3661 | else | |
3662 | { | |
3663 | /* Stack grows upward. Align the frame, allocate space, and | |
3664 | then again, re-align the frame. */ | |
3665 | if (gdbarch_frame_align_p (current_gdbarch)) | |
3666 | *sp = gdbarch_frame_align (current_gdbarch, *sp); | |
3667 | VALUE_ADDRESS (val) = *sp; | |
3668 | *sp += len; | |
3669 | if (gdbarch_frame_align_p (current_gdbarch)) | |
3670 | *sp = gdbarch_frame_align (current_gdbarch, *sp); | |
3671 | } | |
14f9c5c9 | 3672 | |
990a07ab | 3673 | write_memory (VALUE_ADDRESS (val), value_contents_raw (val), len); |
c3e5cd34 | 3674 | } |
14f9c5c9 AS |
3675 | |
3676 | return val; | |
3677 | } | |
3678 | ||
3679 | /* Return the value ACTUAL, converted to be an appropriate value for a | |
3680 | formal of type FORMAL_TYPE. Use *SP as a stack pointer for | |
3681 | allocating any necessary descriptors (fat pointers), or copies of | |
4c4b4cd2 | 3682 | values not residing in memory, updating it as needed. */ |
14f9c5c9 | 3683 | |
d2e4a39e AS |
3684 | static struct value * |
3685 | convert_actual (struct value *actual, struct type *formal_type0, | |
4c4b4cd2 | 3686 | CORE_ADDR *sp) |
14f9c5c9 | 3687 | { |
df407dfe | 3688 | struct type *actual_type = ada_check_typedef (value_type (actual)); |
61ee279c | 3689 | struct type *formal_type = ada_check_typedef (formal_type0); |
d2e4a39e AS |
3690 | struct type *formal_target = |
3691 | TYPE_CODE (formal_type) == TYPE_CODE_PTR | |
61ee279c | 3692 | ? ada_check_typedef (TYPE_TARGET_TYPE (formal_type)) : formal_type; |
d2e4a39e AS |
3693 | struct type *actual_target = |
3694 | TYPE_CODE (actual_type) == TYPE_CODE_PTR | |
61ee279c | 3695 | ? ada_check_typedef (TYPE_TARGET_TYPE (actual_type)) : actual_type; |
14f9c5c9 | 3696 | |
4c4b4cd2 | 3697 | if (ada_is_array_descriptor_type (formal_target) |
14f9c5c9 AS |
3698 | && TYPE_CODE (actual_target) == TYPE_CODE_ARRAY) |
3699 | return make_array_descriptor (formal_type, actual, sp); | |
3700 | else if (TYPE_CODE (formal_type) == TYPE_CODE_PTR) | |
3701 | { | |
3702 | if (TYPE_CODE (formal_target) == TYPE_CODE_ARRAY | |
4c4b4cd2 PH |
3703 | && ada_is_array_descriptor_type (actual_target)) |
3704 | return desc_data (actual); | |
14f9c5c9 | 3705 | else if (TYPE_CODE (actual_type) != TYPE_CODE_PTR) |
4c4b4cd2 PH |
3706 | { |
3707 | if (VALUE_LVAL (actual) != lval_memory) | |
3708 | { | |
3709 | struct value *val; | |
df407dfe | 3710 | actual_type = ada_check_typedef (value_type (actual)); |
4c4b4cd2 | 3711 | val = allocate_value (actual_type); |
990a07ab | 3712 | memcpy ((char *) value_contents_raw (val), |
0fd88904 | 3713 | (char *) value_contents (actual), |
4c4b4cd2 PH |
3714 | TYPE_LENGTH (actual_type)); |
3715 | actual = ensure_lval (val, sp); | |
3716 | } | |
3717 | return value_addr (actual); | |
3718 | } | |
14f9c5c9 AS |
3719 | } |
3720 | else if (TYPE_CODE (actual_type) == TYPE_CODE_PTR) | |
3721 | return ada_value_ind (actual); | |
3722 | ||
3723 | return actual; | |
3724 | } | |
3725 | ||
3726 | ||
4c4b4cd2 PH |
3727 | /* Push a descriptor of type TYPE for array value ARR on the stack at |
3728 | *SP, updating *SP to reflect the new descriptor. Return either | |
14f9c5c9 | 3729 | an lvalue representing the new descriptor, or (if TYPE is a pointer- |
4c4b4cd2 PH |
3730 | to-descriptor type rather than a descriptor type), a struct value * |
3731 | representing a pointer to this descriptor. */ | |
14f9c5c9 | 3732 | |
d2e4a39e AS |
3733 | static struct value * |
3734 | make_array_descriptor (struct type *type, struct value *arr, CORE_ADDR *sp) | |
14f9c5c9 | 3735 | { |
d2e4a39e AS |
3736 | struct type *bounds_type = desc_bounds_type (type); |
3737 | struct type *desc_type = desc_base_type (type); | |
3738 | struct value *descriptor = allocate_value (desc_type); | |
3739 | struct value *bounds = allocate_value (bounds_type); | |
14f9c5c9 | 3740 | int i; |
d2e4a39e | 3741 | |
df407dfe | 3742 | for (i = ada_array_arity (ada_check_typedef (value_type (arr))); i > 0; i -= 1) |
14f9c5c9 | 3743 | { |
0fd88904 | 3744 | modify_general_field (value_contents_writeable (bounds), |
4c4b4cd2 PH |
3745 | value_as_long (ada_array_bound (arr, i, 0)), |
3746 | desc_bound_bitpos (bounds_type, i, 0), | |
3747 | desc_bound_bitsize (bounds_type, i, 0)); | |
0fd88904 | 3748 | modify_general_field (value_contents_writeable (bounds), |
4c4b4cd2 PH |
3749 | value_as_long (ada_array_bound (arr, i, 1)), |
3750 | desc_bound_bitpos (bounds_type, i, 1), | |
3751 | desc_bound_bitsize (bounds_type, i, 1)); | |
14f9c5c9 | 3752 | } |
d2e4a39e | 3753 | |
4c4b4cd2 | 3754 | bounds = ensure_lval (bounds, sp); |
d2e4a39e | 3755 | |
0fd88904 | 3756 | modify_general_field (value_contents_writeable (descriptor), |
76a01679 JB |
3757 | VALUE_ADDRESS (ensure_lval (arr, sp)), |
3758 | fat_pntr_data_bitpos (desc_type), | |
3759 | fat_pntr_data_bitsize (desc_type)); | |
4c4b4cd2 | 3760 | |
0fd88904 | 3761 | modify_general_field (value_contents_writeable (descriptor), |
4c4b4cd2 PH |
3762 | VALUE_ADDRESS (bounds), |
3763 | fat_pntr_bounds_bitpos (desc_type), | |
3764 | fat_pntr_bounds_bitsize (desc_type)); | |
14f9c5c9 | 3765 | |
4c4b4cd2 | 3766 | descriptor = ensure_lval (descriptor, sp); |
14f9c5c9 AS |
3767 | |
3768 | if (TYPE_CODE (type) == TYPE_CODE_PTR) | |
3769 | return value_addr (descriptor); | |
3770 | else | |
3771 | return descriptor; | |
3772 | } | |
3773 | ||
3774 | ||
4c4b4cd2 | 3775 | /* Assuming a dummy frame has been established on the target, perform any |
14f9c5c9 | 3776 | conversions needed for calling function FUNC on the NARGS actual |
4c4b4cd2 | 3777 | parameters in ARGS, other than standard C conversions. Does |
14f9c5c9 | 3778 | nothing if FUNC does not have Ada-style prototype data, or if NARGS |
4c4b4cd2 | 3779 | does not match the number of arguments expected. Use *SP as a |
14f9c5c9 | 3780 | stack pointer for additional data that must be pushed, updating its |
4c4b4cd2 | 3781 | value as needed. */ |
14f9c5c9 AS |
3782 | |
3783 | void | |
d2e4a39e | 3784 | ada_convert_actuals (struct value *func, int nargs, struct value *args[], |
4c4b4cd2 | 3785 | CORE_ADDR *sp) |
14f9c5c9 AS |
3786 | { |
3787 | int i; | |
3788 | ||
df407dfe AC |
3789 | if (TYPE_NFIELDS (value_type (func)) == 0 |
3790 | || nargs != TYPE_NFIELDS (value_type (func))) | |
14f9c5c9 AS |
3791 | return; |
3792 | ||
3793 | for (i = 0; i < nargs; i += 1) | |
d2e4a39e | 3794 | args[i] = |
df407dfe | 3795 | convert_actual (args[i], TYPE_FIELD_TYPE (value_type (func), i), sp); |
14f9c5c9 | 3796 | } |
14f9c5c9 | 3797 | \f |
963a6417 PH |
3798 | /* Dummy definitions for an experimental caching module that is not |
3799 | * used in the public sources. */ | |
96d887e8 | 3800 | |
96d887e8 PH |
3801 | static int |
3802 | lookup_cached_symbol (const char *name, domain_enum namespace, | |
76a01679 JB |
3803 | struct symbol **sym, struct block **block, |
3804 | struct symtab **symtab) | |
96d887e8 PH |
3805 | { |
3806 | return 0; | |
3807 | } | |
3808 | ||
3809 | static void | |
3810 | cache_symbol (const char *name, domain_enum namespace, struct symbol *sym, | |
76a01679 | 3811 | struct block *block, struct symtab *symtab) |
96d887e8 PH |
3812 | { |
3813 | } | |
4c4b4cd2 PH |
3814 | \f |
3815 | /* Symbol Lookup */ | |
3816 | ||
3817 | /* Return the result of a standard (literal, C-like) lookup of NAME in | |
3818 | given DOMAIN, visible from lexical block BLOCK. */ | |
3819 | ||
3820 | static struct symbol * | |
3821 | standard_lookup (const char *name, const struct block *block, | |
3822 | domain_enum domain) | |
3823 | { | |
3824 | struct symbol *sym; | |
3825 | struct symtab *symtab; | |
3826 | ||
3827 | if (lookup_cached_symbol (name, domain, &sym, NULL, NULL)) | |
3828 | return sym; | |
76a01679 JB |
3829 | sym = |
3830 | lookup_symbol_in_language (name, block, domain, language_c, 0, &symtab); | |
4c4b4cd2 PH |
3831 | cache_symbol (name, domain, sym, block_found, symtab); |
3832 | return sym; | |
3833 | } | |
3834 | ||
3835 | ||
3836 | /* Non-zero iff there is at least one non-function/non-enumeral symbol | |
3837 | in the symbol fields of SYMS[0..N-1]. We treat enumerals as functions, | |
3838 | since they contend in overloading in the same way. */ | |
3839 | static int | |
3840 | is_nonfunction (struct ada_symbol_info syms[], int n) | |
3841 | { | |
3842 | int i; | |
3843 | ||
3844 | for (i = 0; i < n; i += 1) | |
3845 | if (TYPE_CODE (SYMBOL_TYPE (syms[i].sym)) != TYPE_CODE_FUNC | |
3846 | && (TYPE_CODE (SYMBOL_TYPE (syms[i].sym)) != TYPE_CODE_ENUM | |
3847 | || SYMBOL_CLASS (syms[i].sym) != LOC_CONST)) | |
14f9c5c9 AS |
3848 | return 1; |
3849 | ||
3850 | return 0; | |
3851 | } | |
3852 | ||
3853 | /* If true (non-zero), then TYPE0 and TYPE1 represent equivalent | |
4c4b4cd2 | 3854 | struct types. Otherwise, they may not. */ |
14f9c5c9 AS |
3855 | |
3856 | static int | |
d2e4a39e | 3857 | equiv_types (struct type *type0, struct type *type1) |
14f9c5c9 | 3858 | { |
d2e4a39e | 3859 | if (type0 == type1) |
14f9c5c9 | 3860 | return 1; |
d2e4a39e | 3861 | if (type0 == NULL || type1 == NULL |
14f9c5c9 AS |
3862 | || TYPE_CODE (type0) != TYPE_CODE (type1)) |
3863 | return 0; | |
d2e4a39e | 3864 | if ((TYPE_CODE (type0) == TYPE_CODE_STRUCT |
14f9c5c9 AS |
3865 | || TYPE_CODE (type0) == TYPE_CODE_ENUM) |
3866 | && ada_type_name (type0) != NULL && ada_type_name (type1) != NULL | |
4c4b4cd2 | 3867 | && strcmp (ada_type_name (type0), ada_type_name (type1)) == 0) |
14f9c5c9 | 3868 | return 1; |
d2e4a39e | 3869 | |
14f9c5c9 AS |
3870 | return 0; |
3871 | } | |
3872 | ||
3873 | /* True iff SYM0 represents the same entity as SYM1, or one that is | |
4c4b4cd2 | 3874 | no more defined than that of SYM1. */ |
14f9c5c9 AS |
3875 | |
3876 | static int | |
d2e4a39e | 3877 | lesseq_defined_than (struct symbol *sym0, struct symbol *sym1) |
14f9c5c9 AS |
3878 | { |
3879 | if (sym0 == sym1) | |
3880 | return 1; | |
176620f1 | 3881 | if (SYMBOL_DOMAIN (sym0) != SYMBOL_DOMAIN (sym1) |
14f9c5c9 AS |
3882 | || SYMBOL_CLASS (sym0) != SYMBOL_CLASS (sym1)) |
3883 | return 0; | |
3884 | ||
d2e4a39e | 3885 | switch (SYMBOL_CLASS (sym0)) |
14f9c5c9 AS |
3886 | { |
3887 | case LOC_UNDEF: | |
3888 | return 1; | |
3889 | case LOC_TYPEDEF: | |
3890 | { | |
4c4b4cd2 PH |
3891 | struct type *type0 = SYMBOL_TYPE (sym0); |
3892 | struct type *type1 = SYMBOL_TYPE (sym1); | |
3893 | char *name0 = SYMBOL_LINKAGE_NAME (sym0); | |
3894 | char *name1 = SYMBOL_LINKAGE_NAME (sym1); | |
3895 | int len0 = strlen (name0); | |
3896 | return | |
3897 | TYPE_CODE (type0) == TYPE_CODE (type1) | |
3898 | && (equiv_types (type0, type1) | |
3899 | || (len0 < strlen (name1) && strncmp (name0, name1, len0) == 0 | |
3900 | && strncmp (name1 + len0, "___XV", 5) == 0)); | |
14f9c5c9 AS |
3901 | } |
3902 | case LOC_CONST: | |
3903 | return SYMBOL_VALUE (sym0) == SYMBOL_VALUE (sym1) | |
4c4b4cd2 | 3904 | && equiv_types (SYMBOL_TYPE (sym0), SYMBOL_TYPE (sym1)); |
d2e4a39e AS |
3905 | default: |
3906 | return 0; | |
14f9c5c9 AS |
3907 | } |
3908 | } | |
3909 | ||
4c4b4cd2 PH |
3910 | /* Append (SYM,BLOCK,SYMTAB) to the end of the array of struct ada_symbol_info |
3911 | records in OBSTACKP. Do nothing if SYM is a duplicate. */ | |
14f9c5c9 AS |
3912 | |
3913 | static void | |
76a01679 JB |
3914 | add_defn_to_vec (struct obstack *obstackp, |
3915 | struct symbol *sym, | |
3916 | struct block *block, struct symtab *symtab) | |
14f9c5c9 AS |
3917 | { |
3918 | int i; | |
3919 | size_t tmp; | |
4c4b4cd2 | 3920 | struct ada_symbol_info *prevDefns = defns_collected (obstackp, 0); |
14f9c5c9 | 3921 | |
529cad9c PH |
3922 | /* Do not try to complete stub types, as the debugger is probably |
3923 | already scanning all symbols matching a certain name at the | |
3924 | time when this function is called. Trying to replace the stub | |
3925 | type by its associated full type will cause us to restart a scan | |
3926 | which may lead to an infinite recursion. Instead, the client | |
3927 | collecting the matching symbols will end up collecting several | |
3928 | matches, with at least one of them complete. It can then filter | |
3929 | out the stub ones if needed. */ | |
3930 | ||
4c4b4cd2 PH |
3931 | for (i = num_defns_collected (obstackp) - 1; i >= 0; i -= 1) |
3932 | { | |
3933 | if (lesseq_defined_than (sym, prevDefns[i].sym)) | |
3934 | return; | |
3935 | else if (lesseq_defined_than (prevDefns[i].sym, sym)) | |
3936 | { | |
3937 | prevDefns[i].sym = sym; | |
3938 | prevDefns[i].block = block; | |
76a01679 | 3939 | prevDefns[i].symtab = symtab; |
4c4b4cd2 | 3940 | return; |
76a01679 | 3941 | } |
4c4b4cd2 PH |
3942 | } |
3943 | ||
3944 | { | |
3945 | struct ada_symbol_info info; | |
3946 | ||
3947 | info.sym = sym; | |
3948 | info.block = block; | |
3949 | info.symtab = symtab; | |
3950 | obstack_grow (obstackp, &info, sizeof (struct ada_symbol_info)); | |
3951 | } | |
3952 | } | |
3953 | ||
3954 | /* Number of ada_symbol_info structures currently collected in | |
3955 | current vector in *OBSTACKP. */ | |
3956 | ||
76a01679 JB |
3957 | static int |
3958 | num_defns_collected (struct obstack *obstackp) | |
4c4b4cd2 PH |
3959 | { |
3960 | return obstack_object_size (obstackp) / sizeof (struct ada_symbol_info); | |
3961 | } | |
3962 | ||
3963 | /* Vector of ada_symbol_info structures currently collected in current | |
3964 | vector in *OBSTACKP. If FINISH, close off the vector and return | |
3965 | its final address. */ | |
3966 | ||
76a01679 | 3967 | static struct ada_symbol_info * |
4c4b4cd2 PH |
3968 | defns_collected (struct obstack *obstackp, int finish) |
3969 | { | |
3970 | if (finish) | |
3971 | return obstack_finish (obstackp); | |
3972 | else | |
3973 | return (struct ada_symbol_info *) obstack_base (obstackp); | |
3974 | } | |
3975 | ||
96d887e8 PH |
3976 | /* Look, in partial_symtab PST, for symbol NAME in given namespace. |
3977 | Check the global symbols if GLOBAL, the static symbols if not. | |
3978 | Do wild-card match if WILD. */ | |
4c4b4cd2 | 3979 | |
96d887e8 PH |
3980 | static struct partial_symbol * |
3981 | ada_lookup_partial_symbol (struct partial_symtab *pst, const char *name, | |
3982 | int global, domain_enum namespace, int wild) | |
4c4b4cd2 | 3983 | { |
96d887e8 PH |
3984 | struct partial_symbol **start; |
3985 | int name_len = strlen (name); | |
3986 | int length = (global ? pst->n_global_syms : pst->n_static_syms); | |
3987 | int i; | |
4c4b4cd2 | 3988 | |
96d887e8 | 3989 | if (length == 0) |
4c4b4cd2 | 3990 | { |
96d887e8 | 3991 | return (NULL); |
4c4b4cd2 PH |
3992 | } |
3993 | ||
96d887e8 PH |
3994 | start = (global ? |
3995 | pst->objfile->global_psymbols.list + pst->globals_offset : | |
3996 | pst->objfile->static_psymbols.list + pst->statics_offset); | |
4c4b4cd2 | 3997 | |
96d887e8 | 3998 | if (wild) |
4c4b4cd2 | 3999 | { |
96d887e8 PH |
4000 | for (i = 0; i < length; i += 1) |
4001 | { | |
4002 | struct partial_symbol *psym = start[i]; | |
4c4b4cd2 | 4003 | |
1265e4aa JB |
4004 | if (SYMBOL_DOMAIN (psym) == namespace |
4005 | && wild_match (name, name_len, SYMBOL_LINKAGE_NAME (psym))) | |
96d887e8 PH |
4006 | return psym; |
4007 | } | |
4008 | return NULL; | |
4c4b4cd2 | 4009 | } |
96d887e8 PH |
4010 | else |
4011 | { | |
4012 | if (global) | |
4013 | { | |
4014 | int U; | |
4015 | i = 0; | |
4016 | U = length - 1; | |
4017 | while (U - i > 4) | |
4018 | { | |
4019 | int M = (U + i) >> 1; | |
4020 | struct partial_symbol *psym = start[M]; | |
4021 | if (SYMBOL_LINKAGE_NAME (psym)[0] < name[0]) | |
4022 | i = M + 1; | |
4023 | else if (SYMBOL_LINKAGE_NAME (psym)[0] > name[0]) | |
4024 | U = M - 1; | |
4025 | else if (strcmp (SYMBOL_LINKAGE_NAME (psym), name) < 0) | |
4026 | i = M + 1; | |
4027 | else | |
4028 | U = M; | |
4029 | } | |
4030 | } | |
4031 | else | |
4032 | i = 0; | |
4c4b4cd2 | 4033 | |
96d887e8 PH |
4034 | while (i < length) |
4035 | { | |
4036 | struct partial_symbol *psym = start[i]; | |
4c4b4cd2 | 4037 | |
96d887e8 PH |
4038 | if (SYMBOL_DOMAIN (psym) == namespace) |
4039 | { | |
4040 | int cmp = strncmp (name, SYMBOL_LINKAGE_NAME (psym), name_len); | |
4c4b4cd2 | 4041 | |
96d887e8 PH |
4042 | if (cmp < 0) |
4043 | { | |
4044 | if (global) | |
4045 | break; | |
4046 | } | |
4047 | else if (cmp == 0 | |
4048 | && is_name_suffix (SYMBOL_LINKAGE_NAME (psym) | |
76a01679 | 4049 | + name_len)) |
96d887e8 PH |
4050 | return psym; |
4051 | } | |
4052 | i += 1; | |
4053 | } | |
4c4b4cd2 | 4054 | |
96d887e8 PH |
4055 | if (global) |
4056 | { | |
4057 | int U; | |
4058 | i = 0; | |
4059 | U = length - 1; | |
4060 | while (U - i > 4) | |
4061 | { | |
4062 | int M = (U + i) >> 1; | |
4063 | struct partial_symbol *psym = start[M]; | |
4064 | if (SYMBOL_LINKAGE_NAME (psym)[0] < '_') | |
4065 | i = M + 1; | |
4066 | else if (SYMBOL_LINKAGE_NAME (psym)[0] > '_') | |
4067 | U = M - 1; | |
4068 | else if (strcmp (SYMBOL_LINKAGE_NAME (psym), "_ada_") < 0) | |
4069 | i = M + 1; | |
4070 | else | |
4071 | U = M; | |
4072 | } | |
4073 | } | |
4074 | else | |
4075 | i = 0; | |
4c4b4cd2 | 4076 | |
96d887e8 PH |
4077 | while (i < length) |
4078 | { | |
4079 | struct partial_symbol *psym = start[i]; | |
4c4b4cd2 | 4080 | |
96d887e8 PH |
4081 | if (SYMBOL_DOMAIN (psym) == namespace) |
4082 | { | |
4083 | int cmp; | |
4c4b4cd2 | 4084 | |
96d887e8 PH |
4085 | cmp = (int) '_' - (int) SYMBOL_LINKAGE_NAME (psym)[0]; |
4086 | if (cmp == 0) | |
4087 | { | |
4088 | cmp = strncmp ("_ada_", SYMBOL_LINKAGE_NAME (psym), 5); | |
4089 | if (cmp == 0) | |
4090 | cmp = strncmp (name, SYMBOL_LINKAGE_NAME (psym) + 5, | |
76a01679 | 4091 | name_len); |
96d887e8 | 4092 | } |
4c4b4cd2 | 4093 | |
96d887e8 PH |
4094 | if (cmp < 0) |
4095 | { | |
4096 | if (global) | |
4097 | break; | |
4098 | } | |
4099 | else if (cmp == 0 | |
4100 | && is_name_suffix (SYMBOL_LINKAGE_NAME (psym) | |
76a01679 | 4101 | + name_len + 5)) |
96d887e8 PH |
4102 | return psym; |
4103 | } | |
4104 | i += 1; | |
4105 | } | |
4106 | } | |
4107 | return NULL; | |
4c4b4cd2 PH |
4108 | } |
4109 | ||
96d887e8 | 4110 | /* Find a symbol table containing symbol SYM or NULL if none. */ |
4c4b4cd2 | 4111 | |
96d887e8 PH |
4112 | static struct symtab * |
4113 | symtab_for_sym (struct symbol *sym) | |
4c4b4cd2 | 4114 | { |
96d887e8 PH |
4115 | struct symtab *s; |
4116 | struct objfile *objfile; | |
4117 | struct block *b; | |
4118 | struct symbol *tmp_sym; | |
4119 | struct dict_iterator iter; | |
4120 | int j; | |
4c4b4cd2 | 4121 | |
96d887e8 PH |
4122 | ALL_SYMTABS (objfile, s) |
4123 | { | |
4124 | switch (SYMBOL_CLASS (sym)) | |
4125 | { | |
4126 | case LOC_CONST: | |
4127 | case LOC_STATIC: | |
4128 | case LOC_TYPEDEF: | |
4129 | case LOC_REGISTER: | |
4130 | case LOC_LABEL: | |
4131 | case LOC_BLOCK: | |
4132 | case LOC_CONST_BYTES: | |
76a01679 JB |
4133 | b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK); |
4134 | ALL_BLOCK_SYMBOLS (b, iter, tmp_sym) if (sym == tmp_sym) | |
4135 | return s; | |
4136 | b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK); | |
4137 | ALL_BLOCK_SYMBOLS (b, iter, tmp_sym) if (sym == tmp_sym) | |
4138 | return s; | |
96d887e8 PH |
4139 | break; |
4140 | default: | |
4141 | break; | |
4142 | } | |
4143 | switch (SYMBOL_CLASS (sym)) | |
4144 | { | |
4145 | case LOC_REGISTER: | |
4146 | case LOC_ARG: | |
4147 | case LOC_REF_ARG: | |
4148 | case LOC_REGPARM: | |
4149 | case LOC_REGPARM_ADDR: | |
4150 | case LOC_LOCAL: | |
4151 | case LOC_TYPEDEF: | |
4152 | case LOC_LOCAL_ARG: | |
4153 | case LOC_BASEREG: | |
4154 | case LOC_BASEREG_ARG: | |
4155 | case LOC_COMPUTED: | |
4156 | case LOC_COMPUTED_ARG: | |
76a01679 JB |
4157 | for (j = FIRST_LOCAL_BLOCK; |
4158 | j < BLOCKVECTOR_NBLOCKS (BLOCKVECTOR (s)); j += 1) | |
4159 | { | |
4160 | b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), j); | |
4161 | ALL_BLOCK_SYMBOLS (b, iter, tmp_sym) if (sym == tmp_sym) | |
4162 | return s; | |
4163 | } | |
4164 | break; | |
96d887e8 PH |
4165 | default: |
4166 | break; | |
4167 | } | |
4168 | } | |
4169 | return NULL; | |
4c4b4cd2 PH |
4170 | } |
4171 | ||
96d887e8 PH |
4172 | /* Return a minimal symbol matching NAME according to Ada decoding |
4173 | rules. Returns NULL if there is no such minimal symbol. Names | |
4174 | prefixed with "standard__" are handled specially: "standard__" is | |
4175 | first stripped off, and only static and global symbols are searched. */ | |
4c4b4cd2 | 4176 | |
96d887e8 PH |
4177 | struct minimal_symbol * |
4178 | ada_lookup_simple_minsym (const char *name) | |
4c4b4cd2 | 4179 | { |
4c4b4cd2 | 4180 | struct objfile *objfile; |
96d887e8 PH |
4181 | struct minimal_symbol *msymbol; |
4182 | int wild_match; | |
4c4b4cd2 | 4183 | |
96d887e8 | 4184 | if (strncmp (name, "standard__", sizeof ("standard__") - 1) == 0) |
4c4b4cd2 | 4185 | { |
96d887e8 | 4186 | name += sizeof ("standard__") - 1; |
4c4b4cd2 | 4187 | wild_match = 0; |
4c4b4cd2 PH |
4188 | } |
4189 | else | |
96d887e8 | 4190 | wild_match = (strstr (name, "__") == NULL); |
4c4b4cd2 | 4191 | |
96d887e8 PH |
4192 | ALL_MSYMBOLS (objfile, msymbol) |
4193 | { | |
4194 | if (ada_match_name (SYMBOL_LINKAGE_NAME (msymbol), name, wild_match) | |
4195 | && MSYMBOL_TYPE (msymbol) != mst_solib_trampoline) | |
4196 | return msymbol; | |
4197 | } | |
4c4b4cd2 | 4198 | |
96d887e8 PH |
4199 | return NULL; |
4200 | } | |
4c4b4cd2 | 4201 | |
96d887e8 PH |
4202 | /* For all subprograms that statically enclose the subprogram of the |
4203 | selected frame, add symbols matching identifier NAME in DOMAIN | |
4204 | and their blocks to the list of data in OBSTACKP, as for | |
4205 | ada_add_block_symbols (q.v.). If WILD, treat as NAME with a | |
4206 | wildcard prefix. */ | |
4c4b4cd2 | 4207 | |
96d887e8 PH |
4208 | static void |
4209 | add_symbols_from_enclosing_procs (struct obstack *obstackp, | |
76a01679 | 4210 | const char *name, domain_enum namespace, |
96d887e8 PH |
4211 | int wild_match) |
4212 | { | |
96d887e8 | 4213 | } |
14f9c5c9 | 4214 | |
96d887e8 | 4215 | /* FIXME: The next two routines belong in symtab.c */ |
14f9c5c9 | 4216 | |
76a01679 JB |
4217 | static void |
4218 | restore_language (void *lang) | |
96d887e8 PH |
4219 | { |
4220 | set_language ((enum language) lang); | |
4221 | } | |
4c4b4cd2 | 4222 | |
96d887e8 PH |
4223 | /* As for lookup_symbol, but performed as if the current language |
4224 | were LANG. */ | |
4c4b4cd2 | 4225 | |
96d887e8 PH |
4226 | struct symbol * |
4227 | lookup_symbol_in_language (const char *name, const struct block *block, | |
76a01679 JB |
4228 | domain_enum domain, enum language lang, |
4229 | int *is_a_field_of_this, struct symtab **symtab) | |
96d887e8 | 4230 | { |
76a01679 JB |
4231 | struct cleanup *old_chain |
4232 | = make_cleanup (restore_language, (void *) current_language->la_language); | |
96d887e8 PH |
4233 | struct symbol *result; |
4234 | set_language (lang); | |
4235 | result = lookup_symbol (name, block, domain, is_a_field_of_this, symtab); | |
4236 | do_cleanups (old_chain); | |
4237 | return result; | |
4238 | } | |
14f9c5c9 | 4239 | |
96d887e8 PH |
4240 | /* True if TYPE is definitely an artificial type supplied to a symbol |
4241 | for which no debugging information was given in the symbol file. */ | |
14f9c5c9 | 4242 | |
96d887e8 PH |
4243 | static int |
4244 | is_nondebugging_type (struct type *type) | |
4245 | { | |
4246 | char *name = ada_type_name (type); | |
4247 | return (name != NULL && strcmp (name, "<variable, no debug info>") == 0); | |
4248 | } | |
4c4b4cd2 | 4249 | |
96d887e8 PH |
4250 | /* Remove any non-debugging symbols in SYMS[0 .. NSYMS-1] that definitely |
4251 | duplicate other symbols in the list (The only case I know of where | |
4252 | this happens is when object files containing stabs-in-ecoff are | |
4253 | linked with files containing ordinary ecoff debugging symbols (or no | |
4254 | debugging symbols)). Modifies SYMS to squeeze out deleted entries. | |
4255 | Returns the number of items in the modified list. */ | |
4c4b4cd2 | 4256 | |
96d887e8 PH |
4257 | static int |
4258 | remove_extra_symbols (struct ada_symbol_info *syms, int nsyms) | |
4259 | { | |
4260 | int i, j; | |
4c4b4cd2 | 4261 | |
96d887e8 PH |
4262 | i = 0; |
4263 | while (i < nsyms) | |
4264 | { | |
4265 | if (SYMBOL_LINKAGE_NAME (syms[i].sym) != NULL | |
4266 | && SYMBOL_CLASS (syms[i].sym) == LOC_STATIC | |
4267 | && is_nondebugging_type (SYMBOL_TYPE (syms[i].sym))) | |
4268 | { | |
4269 | for (j = 0; j < nsyms; j += 1) | |
4270 | { | |
4271 | if (i != j | |
4272 | && SYMBOL_LINKAGE_NAME (syms[j].sym) != NULL | |
4273 | && strcmp (SYMBOL_LINKAGE_NAME (syms[i].sym), | |
76a01679 | 4274 | SYMBOL_LINKAGE_NAME (syms[j].sym)) == 0 |
96d887e8 PH |
4275 | && SYMBOL_CLASS (syms[i].sym) == SYMBOL_CLASS (syms[j].sym) |
4276 | && SYMBOL_VALUE_ADDRESS (syms[i].sym) | |
4277 | == SYMBOL_VALUE_ADDRESS (syms[j].sym)) | |
4c4b4cd2 | 4278 | { |
96d887e8 PH |
4279 | int k; |
4280 | for (k = i + 1; k < nsyms; k += 1) | |
76a01679 | 4281 | syms[k - 1] = syms[k]; |
96d887e8 PH |
4282 | nsyms -= 1; |
4283 | goto NextSymbol; | |
4c4b4cd2 | 4284 | } |
4c4b4cd2 | 4285 | } |
4c4b4cd2 | 4286 | } |
96d887e8 PH |
4287 | i += 1; |
4288 | NextSymbol: | |
4289 | ; | |
14f9c5c9 | 4290 | } |
96d887e8 | 4291 | return nsyms; |
14f9c5c9 AS |
4292 | } |
4293 | ||
96d887e8 PH |
4294 | /* Given a type that corresponds to a renaming entity, use the type name |
4295 | to extract the scope (package name or function name, fully qualified, | |
4296 | and following the GNAT encoding convention) where this renaming has been | |
4297 | defined. The string returned needs to be deallocated after use. */ | |
4c4b4cd2 | 4298 | |
96d887e8 PH |
4299 | static char * |
4300 | xget_renaming_scope (struct type *renaming_type) | |
14f9c5c9 | 4301 | { |
96d887e8 PH |
4302 | /* The renaming types adhere to the following convention: |
4303 | <scope>__<rename>___<XR extension>. | |
4304 | So, to extract the scope, we search for the "___XR" extension, | |
4305 | and then backtrack until we find the first "__". */ | |
76a01679 | 4306 | |
96d887e8 PH |
4307 | const char *name = type_name_no_tag (renaming_type); |
4308 | char *suffix = strstr (name, "___XR"); | |
4309 | char *last; | |
4310 | int scope_len; | |
4311 | char *scope; | |
14f9c5c9 | 4312 | |
96d887e8 PH |
4313 | /* Now, backtrack a bit until we find the first "__". Start looking |
4314 | at suffix - 3, as the <rename> part is at least one character long. */ | |
14f9c5c9 | 4315 | |
96d887e8 PH |
4316 | for (last = suffix - 3; last > name; last--) |
4317 | if (last[0] == '_' && last[1] == '_') | |
4318 | break; | |
76a01679 | 4319 | |
96d887e8 | 4320 | /* Make a copy of scope and return it. */ |
14f9c5c9 | 4321 | |
96d887e8 PH |
4322 | scope_len = last - name; |
4323 | scope = (char *) xmalloc ((scope_len + 1) * sizeof (char)); | |
14f9c5c9 | 4324 | |
96d887e8 PH |
4325 | strncpy (scope, name, scope_len); |
4326 | scope[scope_len] = '\0'; | |
4c4b4cd2 | 4327 | |
96d887e8 | 4328 | return scope; |
4c4b4cd2 PH |
4329 | } |
4330 | ||
96d887e8 | 4331 | /* Return nonzero if NAME corresponds to a package name. */ |
4c4b4cd2 | 4332 | |
96d887e8 PH |
4333 | static int |
4334 | is_package_name (const char *name) | |
4c4b4cd2 | 4335 | { |
96d887e8 PH |
4336 | /* Here, We take advantage of the fact that no symbols are generated |
4337 | for packages, while symbols are generated for each function. | |
4338 | So the condition for NAME represent a package becomes equivalent | |
4339 | to NAME not existing in our list of symbols. There is only one | |
4340 | small complication with library-level functions (see below). */ | |
4c4b4cd2 | 4341 | |
96d887e8 | 4342 | char *fun_name; |
76a01679 | 4343 | |
96d887e8 PH |
4344 | /* If it is a function that has not been defined at library level, |
4345 | then we should be able to look it up in the symbols. */ | |
4346 | if (standard_lookup (name, NULL, VAR_DOMAIN) != NULL) | |
4347 | return 0; | |
14f9c5c9 | 4348 | |
96d887e8 PH |
4349 | /* Library-level function names start with "_ada_". See if function |
4350 | "_ada_" followed by NAME can be found. */ | |
14f9c5c9 | 4351 | |
96d887e8 | 4352 | /* Do a quick check that NAME does not contain "__", since library-level |
e1d5a0d2 | 4353 | functions names cannot contain "__" in them. */ |
96d887e8 PH |
4354 | if (strstr (name, "__") != NULL) |
4355 | return 0; | |
4c4b4cd2 | 4356 | |
b435e160 | 4357 | fun_name = xstrprintf ("_ada_%s", name); |
14f9c5c9 | 4358 | |
96d887e8 PH |
4359 | return (standard_lookup (fun_name, NULL, VAR_DOMAIN) == NULL); |
4360 | } | |
14f9c5c9 | 4361 | |
96d887e8 PH |
4362 | /* Return nonzero if SYM corresponds to a renaming entity that is |
4363 | visible from FUNCTION_NAME. */ | |
14f9c5c9 | 4364 | |
96d887e8 PH |
4365 | static int |
4366 | renaming_is_visible (const struct symbol *sym, char *function_name) | |
4367 | { | |
4368 | char *scope = xget_renaming_scope (SYMBOL_TYPE (sym)); | |
d2e4a39e | 4369 | |
96d887e8 | 4370 | make_cleanup (xfree, scope); |
14f9c5c9 | 4371 | |
96d887e8 PH |
4372 | /* If the rename has been defined in a package, then it is visible. */ |
4373 | if (is_package_name (scope)) | |
4374 | return 1; | |
14f9c5c9 | 4375 | |
96d887e8 PH |
4376 | /* Check that the rename is in the current function scope by checking |
4377 | that its name starts with SCOPE. */ | |
76a01679 | 4378 | |
96d887e8 PH |
4379 | /* If the function name starts with "_ada_", it means that it is |
4380 | a library-level function. Strip this prefix before doing the | |
4381 | comparison, as the encoding for the renaming does not contain | |
4382 | this prefix. */ | |
4383 | if (strncmp (function_name, "_ada_", 5) == 0) | |
4384 | function_name += 5; | |
f26caa11 | 4385 | |
96d887e8 | 4386 | return (strncmp (function_name, scope, strlen (scope)) == 0); |
f26caa11 PH |
4387 | } |
4388 | ||
96d887e8 PH |
4389 | /* Iterates over the SYMS list and remove any entry that corresponds to |
4390 | a renaming entity that is not visible from the function associated | |
4391 | with CURRENT_BLOCK. | |
4392 | ||
4393 | Rationale: | |
4394 | GNAT emits a type following a specified encoding for each renaming | |
4395 | entity. Unfortunately, STABS currently does not support the definition | |
4396 | of types that are local to a given lexical block, so all renamings types | |
4397 | are emitted at library level. As a consequence, if an application | |
4398 | contains two renaming entities using the same name, and a user tries to | |
4399 | print the value of one of these entities, the result of the ada symbol | |
4400 | lookup will also contain the wrong renaming type. | |
f26caa11 | 4401 | |
96d887e8 PH |
4402 | This function partially covers for this limitation by attempting to |
4403 | remove from the SYMS list renaming symbols that should be visible | |
4404 | from CURRENT_BLOCK. However, there does not seem be a 100% reliable | |
4405 | method with the current information available. The implementation | |
4406 | below has a couple of limitations (FIXME: brobecker-2003-05-12): | |
4407 | ||
4408 | - When the user tries to print a rename in a function while there | |
4409 | is another rename entity defined in a package: Normally, the | |
4410 | rename in the function has precedence over the rename in the | |
4411 | package, so the latter should be removed from the list. This is | |
4412 | currently not the case. | |
4413 | ||
4414 | - This function will incorrectly remove valid renames if | |
4415 | the CURRENT_BLOCK corresponds to a function which symbol name | |
4416 | has been changed by an "Export" pragma. As a consequence, | |
4417 | the user will be unable to print such rename entities. */ | |
4c4b4cd2 | 4418 | |
14f9c5c9 | 4419 | static int |
96d887e8 | 4420 | remove_out_of_scope_renamings (struct ada_symbol_info *syms, |
76a01679 | 4421 | int nsyms, struct block *current_block) |
4c4b4cd2 PH |
4422 | { |
4423 | struct symbol *current_function; | |
4424 | char *current_function_name; | |
4425 | int i; | |
4426 | ||
4427 | /* Extract the function name associated to CURRENT_BLOCK. | |
4428 | Abort if unable to do so. */ | |
76a01679 | 4429 | |
4c4b4cd2 PH |
4430 | if (current_block == NULL) |
4431 | return nsyms; | |
76a01679 | 4432 | |
4c4b4cd2 PH |
4433 | current_function = block_function (current_block); |
4434 | if (current_function == NULL) | |
4435 | return nsyms; | |
4436 | ||
4437 | current_function_name = SYMBOL_LINKAGE_NAME (current_function); | |
4438 | if (current_function_name == NULL) | |
4439 | return nsyms; | |
4440 | ||
4441 | /* Check each of the symbols, and remove it from the list if it is | |
4442 | a type corresponding to a renaming that is out of the scope of | |
4443 | the current block. */ | |
4444 | ||
4445 | i = 0; | |
4446 | while (i < nsyms) | |
4447 | { | |
4448 | if (ada_is_object_renaming (syms[i].sym) | |
4449 | && !renaming_is_visible (syms[i].sym, current_function_name)) | |
4450 | { | |
4451 | int j; | |
4452 | for (j = i + 1; j < nsyms; j++) | |
76a01679 | 4453 | syms[j - 1] = syms[j]; |
4c4b4cd2 PH |
4454 | nsyms -= 1; |
4455 | } | |
4456 | else | |
4457 | i += 1; | |
4458 | } | |
4459 | ||
4460 | return nsyms; | |
4461 | } | |
4462 | ||
4463 | /* Find symbols in DOMAIN matching NAME0, in BLOCK0 and enclosing | |
4464 | scope and in global scopes, returning the number of matches. Sets | |
4465 | *RESULTS to point to a vector of (SYM,BLOCK,SYMTAB) triples, | |
4466 | indicating the symbols found and the blocks and symbol tables (if | |
4467 | any) in which they were found. This vector are transient---good only to | |
4468 | the next call of ada_lookup_symbol_list. Any non-function/non-enumeral | |
4469 | symbol match within the nest of blocks whose innermost member is BLOCK0, | |
4470 | is the one match returned (no other matches in that or | |
4471 | enclosing blocks is returned). If there are any matches in or | |
4472 | surrounding BLOCK0, then these alone are returned. Otherwise, the | |
4473 | search extends to global and file-scope (static) symbol tables. | |
4474 | Names prefixed with "standard__" are handled specially: "standard__" | |
4475 | is first stripped off, and only static and global symbols are searched. */ | |
14f9c5c9 AS |
4476 | |
4477 | int | |
4c4b4cd2 | 4478 | ada_lookup_symbol_list (const char *name0, const struct block *block0, |
76a01679 JB |
4479 | domain_enum namespace, |
4480 | struct ada_symbol_info **results) | |
14f9c5c9 AS |
4481 | { |
4482 | struct symbol *sym; | |
4483 | struct symtab *s; | |
4484 | struct partial_symtab *ps; | |
4485 | struct blockvector *bv; | |
4486 | struct objfile *objfile; | |
14f9c5c9 | 4487 | struct block *block; |
4c4b4cd2 | 4488 | const char *name; |
14f9c5c9 | 4489 | struct minimal_symbol *msymbol; |
4c4b4cd2 | 4490 | int wild_match; |
14f9c5c9 | 4491 | int cacheIfUnique; |
4c4b4cd2 PH |
4492 | int block_depth; |
4493 | int ndefns; | |
14f9c5c9 | 4494 | |
4c4b4cd2 PH |
4495 | obstack_free (&symbol_list_obstack, NULL); |
4496 | obstack_init (&symbol_list_obstack); | |
14f9c5c9 | 4497 | |
14f9c5c9 AS |
4498 | cacheIfUnique = 0; |
4499 | ||
4500 | /* Search specified block and its superiors. */ | |
4501 | ||
4c4b4cd2 PH |
4502 | wild_match = (strstr (name0, "__") == NULL); |
4503 | name = name0; | |
76a01679 JB |
4504 | block = (struct block *) block0; /* FIXME: No cast ought to be |
4505 | needed, but adding const will | |
4506 | have a cascade effect. */ | |
4c4b4cd2 PH |
4507 | if (strncmp (name0, "standard__", sizeof ("standard__") - 1) == 0) |
4508 | { | |
4509 | wild_match = 0; | |
4510 | block = NULL; | |
4511 | name = name0 + sizeof ("standard__") - 1; | |
4512 | } | |
4513 | ||
4514 | block_depth = 0; | |
14f9c5c9 AS |
4515 | while (block != NULL) |
4516 | { | |
4c4b4cd2 | 4517 | block_depth += 1; |
76a01679 JB |
4518 | ada_add_block_symbols (&symbol_list_obstack, block, name, |
4519 | namespace, NULL, NULL, wild_match); | |
14f9c5c9 | 4520 | |
4c4b4cd2 PH |
4521 | /* If we found a non-function match, assume that's the one. */ |
4522 | if (is_nonfunction (defns_collected (&symbol_list_obstack, 0), | |
76a01679 | 4523 | num_defns_collected (&symbol_list_obstack))) |
4c4b4cd2 | 4524 | goto done; |
14f9c5c9 AS |
4525 | |
4526 | block = BLOCK_SUPERBLOCK (block); | |
4527 | } | |
4528 | ||
4c4b4cd2 PH |
4529 | /* If no luck so far, try to find NAME as a local symbol in some lexically |
4530 | enclosing subprogram. */ | |
4531 | if (num_defns_collected (&symbol_list_obstack) == 0 && block_depth > 2) | |
4532 | add_symbols_from_enclosing_procs (&symbol_list_obstack, | |
76a01679 | 4533 | name, namespace, wild_match); |
4c4b4cd2 PH |
4534 | |
4535 | /* If we found ANY matches among non-global symbols, we're done. */ | |
14f9c5c9 | 4536 | |
4c4b4cd2 | 4537 | if (num_defns_collected (&symbol_list_obstack) > 0) |
14f9c5c9 | 4538 | goto done; |
d2e4a39e | 4539 | |
14f9c5c9 | 4540 | cacheIfUnique = 1; |
4c4b4cd2 PH |
4541 | if (lookup_cached_symbol (name0, namespace, &sym, &block, &s)) |
4542 | { | |
4543 | if (sym != NULL) | |
4544 | add_defn_to_vec (&symbol_list_obstack, sym, block, s); | |
4545 | goto done; | |
4546 | } | |
14f9c5c9 AS |
4547 | |
4548 | /* Now add symbols from all global blocks: symbol tables, minimal symbol | |
4c4b4cd2 | 4549 | tables, and psymtab's. */ |
14f9c5c9 AS |
4550 | |
4551 | ALL_SYMTABS (objfile, s) | |
d2e4a39e AS |
4552 | { |
4553 | QUIT; | |
4554 | if (!s->primary) | |
4555 | continue; | |
4556 | bv = BLOCKVECTOR (s); | |
4557 | block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); | |
76a01679 JB |
4558 | ada_add_block_symbols (&symbol_list_obstack, block, name, namespace, |
4559 | objfile, s, wild_match); | |
d2e4a39e | 4560 | } |
14f9c5c9 | 4561 | |
4c4b4cd2 | 4562 | if (namespace == VAR_DOMAIN) |
14f9c5c9 AS |
4563 | { |
4564 | ALL_MSYMBOLS (objfile, msymbol) | |
d2e4a39e | 4565 | { |
4c4b4cd2 PH |
4566 | if (ada_match_name (SYMBOL_LINKAGE_NAME (msymbol), name, wild_match)) |
4567 | { | |
4568 | switch (MSYMBOL_TYPE (msymbol)) | |
4569 | { | |
4570 | case mst_solib_trampoline: | |
4571 | break; | |
4572 | default: | |
4573 | s = find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol)); | |
4574 | if (s != NULL) | |
4575 | { | |
4576 | int ndefns0 = num_defns_collected (&symbol_list_obstack); | |
4577 | QUIT; | |
4578 | bv = BLOCKVECTOR (s); | |
4579 | block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); | |
4580 | ada_add_block_symbols (&symbol_list_obstack, block, | |
4581 | SYMBOL_LINKAGE_NAME (msymbol), | |
4582 | namespace, objfile, s, wild_match); | |
76a01679 | 4583 | |
4c4b4cd2 PH |
4584 | if (num_defns_collected (&symbol_list_obstack) == ndefns0) |
4585 | { | |
4586 | block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK); | |
4587 | ada_add_block_symbols (&symbol_list_obstack, block, | |
4588 | SYMBOL_LINKAGE_NAME (msymbol), | |
4589 | namespace, objfile, s, | |
4590 | wild_match); | |
4591 | } | |
4592 | } | |
4593 | } | |
4594 | } | |
d2e4a39e | 4595 | } |
14f9c5c9 | 4596 | } |
d2e4a39e | 4597 | |
14f9c5c9 | 4598 | ALL_PSYMTABS (objfile, ps) |
d2e4a39e AS |
4599 | { |
4600 | QUIT; | |
4601 | if (!ps->readin | |
4c4b4cd2 | 4602 | && ada_lookup_partial_symbol (ps, name, 1, namespace, wild_match)) |
d2e4a39e | 4603 | { |
4c4b4cd2 PH |
4604 | s = PSYMTAB_TO_SYMTAB (ps); |
4605 | if (!s->primary) | |
4606 | continue; | |
4607 | bv = BLOCKVECTOR (s); | |
4608 | block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); | |
4609 | ada_add_block_symbols (&symbol_list_obstack, block, name, | |
76a01679 | 4610 | namespace, objfile, s, wild_match); |
d2e4a39e AS |
4611 | } |
4612 | } | |
4613 | ||
4c4b4cd2 | 4614 | /* Now add symbols from all per-file blocks if we've gotten no hits |
14f9c5c9 | 4615 | (Not strictly correct, but perhaps better than an error). |
4c4b4cd2 | 4616 | Do the symtabs first, then check the psymtabs. */ |
d2e4a39e | 4617 | |
4c4b4cd2 | 4618 | if (num_defns_collected (&symbol_list_obstack) == 0) |
14f9c5c9 AS |
4619 | { |
4620 | ||
4621 | ALL_SYMTABS (objfile, s) | |
d2e4a39e | 4622 | { |
4c4b4cd2 PH |
4623 | QUIT; |
4624 | if (!s->primary) | |
4625 | continue; | |
4626 | bv = BLOCKVECTOR (s); | |
4627 | block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK); | |
76a01679 JB |
4628 | ada_add_block_symbols (&symbol_list_obstack, block, name, namespace, |
4629 | objfile, s, wild_match); | |
d2e4a39e AS |
4630 | } |
4631 | ||
14f9c5c9 | 4632 | ALL_PSYMTABS (objfile, ps) |
d2e4a39e | 4633 | { |
4c4b4cd2 PH |
4634 | QUIT; |
4635 | if (!ps->readin | |
4636 | && ada_lookup_partial_symbol (ps, name, 0, namespace, wild_match)) | |
4637 | { | |
4638 | s = PSYMTAB_TO_SYMTAB (ps); | |
4639 | bv = BLOCKVECTOR (s); | |
4640 | if (!s->primary) | |
4641 | continue; | |
4642 | block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK); | |
76a01679 JB |
4643 | ada_add_block_symbols (&symbol_list_obstack, block, name, |
4644 | namespace, objfile, s, wild_match); | |
4c4b4cd2 | 4645 | } |
d2e4a39e AS |
4646 | } |
4647 | } | |
14f9c5c9 | 4648 | |
4c4b4cd2 PH |
4649 | done: |
4650 | ndefns = num_defns_collected (&symbol_list_obstack); | |
4651 | *results = defns_collected (&symbol_list_obstack, 1); | |
4652 | ||
4653 | ndefns = remove_extra_symbols (*results, ndefns); | |
4654 | ||
d2e4a39e | 4655 | if (ndefns == 0) |
4c4b4cd2 | 4656 | cache_symbol (name0, namespace, NULL, NULL, NULL); |
14f9c5c9 | 4657 | |
4c4b4cd2 | 4658 | if (ndefns == 1 && cacheIfUnique) |
76a01679 JB |
4659 | cache_symbol (name0, namespace, (*results)[0].sym, (*results)[0].block, |
4660 | (*results)[0].symtab); | |
14f9c5c9 | 4661 | |
4c4b4cd2 PH |
4662 | ndefns = remove_out_of_scope_renamings (*results, ndefns, |
4663 | (struct block *) block0); | |
14f9c5c9 | 4664 | |
14f9c5c9 AS |
4665 | return ndefns; |
4666 | } | |
4667 | ||
4c4b4cd2 PH |
4668 | /* Return a symbol in DOMAIN matching NAME, in BLOCK0 and enclosing |
4669 | scope and in global scopes, or NULL if none. NAME is folded and | |
4670 | encoded first. Otherwise, the result is as for ada_lookup_symbol_list, | |
714e53ab PH |
4671 | choosing the first symbol if there are multiple choices. |
4672 | *IS_A_FIELD_OF_THIS is set to 0 and *SYMTAB is set to the symbol | |
4673 | table in which the symbol was found (in both cases, these | |
4674 | assignments occur only if the pointers are non-null). */ | |
4675 | ||
d2e4a39e | 4676 | struct symbol * |
4c4b4cd2 PH |
4677 | ada_lookup_symbol (const char *name, const struct block *block0, |
4678 | domain_enum namespace, int *is_a_field_of_this, | |
76a01679 | 4679 | struct symtab **symtab) |
14f9c5c9 | 4680 | { |
4c4b4cd2 | 4681 | struct ada_symbol_info *candidates; |
14f9c5c9 AS |
4682 | int n_candidates; |
4683 | ||
4c4b4cd2 PH |
4684 | n_candidates = ada_lookup_symbol_list (ada_encode (ada_fold_name (name)), |
4685 | block0, namespace, &candidates); | |
14f9c5c9 AS |
4686 | |
4687 | if (n_candidates == 0) | |
4688 | return NULL; | |
4c4b4cd2 PH |
4689 | |
4690 | if (is_a_field_of_this != NULL) | |
4691 | *is_a_field_of_this = 0; | |
4692 | ||
76a01679 | 4693 | if (symtab != NULL) |
4c4b4cd2 PH |
4694 | { |
4695 | *symtab = candidates[0].symtab; | |
76a01679 JB |
4696 | if (*symtab == NULL && candidates[0].block != NULL) |
4697 | { | |
4698 | struct objfile *objfile; | |
4699 | struct symtab *s; | |
4700 | struct block *b; | |
4701 | struct blockvector *bv; | |
4702 | ||
4703 | /* Search the list of symtabs for one which contains the | |
4704 | address of the start of this block. */ | |
4705 | ALL_SYMTABS (objfile, s) | |
4706 | { | |
4707 | bv = BLOCKVECTOR (s); | |
4708 | b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); | |
4709 | if (BLOCK_START (b) <= BLOCK_START (candidates[0].block) | |
4710 | && BLOCK_END (b) > BLOCK_START (candidates[0].block)) | |
4711 | { | |
4712 | *symtab = s; | |
4713 | return fixup_symbol_section (candidates[0].sym, objfile); | |
4714 | } | |
76a01679 | 4715 | } |
529cad9c PH |
4716 | /* FIXME: brobecker/2004-11-12: I think that we should never |
4717 | reach this point. I don't see a reason why we would not | |
4718 | find a symtab for a given block, so I suggest raising an | |
4719 | internal_error exception here. Otherwise, we end up | |
4720 | returning a symbol but no symtab, which certain parts of | |
4721 | the code that rely (indirectly) on this function do not | |
4722 | expect, eventually causing a SEGV. */ | |
4723 | return fixup_symbol_section (candidates[0].sym, NULL); | |
76a01679 JB |
4724 | } |
4725 | } | |
4c4b4cd2 PH |
4726 | return candidates[0].sym; |
4727 | } | |
14f9c5c9 | 4728 | |
4c4b4cd2 PH |
4729 | static struct symbol * |
4730 | ada_lookup_symbol_nonlocal (const char *name, | |
76a01679 JB |
4731 | const char *linkage_name, |
4732 | const struct block *block, | |
4733 | const domain_enum domain, struct symtab **symtab) | |
4c4b4cd2 PH |
4734 | { |
4735 | if (linkage_name == NULL) | |
4736 | linkage_name = name; | |
76a01679 JB |
4737 | return ada_lookup_symbol (linkage_name, block_static_block (block), domain, |
4738 | NULL, symtab); | |
14f9c5c9 AS |
4739 | } |
4740 | ||
4741 | ||
4c4b4cd2 PH |
4742 | /* True iff STR is a possible encoded suffix of a normal Ada name |
4743 | that is to be ignored for matching purposes. Suffixes of parallel | |
4744 | names (e.g., XVE) are not included here. Currently, the possible suffixes | |
4745 | are given by either of the regular expression: | |
4746 | ||
529cad9c PH |
4747 | (__[0-9]+)?[.$][0-9]+ [nested subprogram suffix, on platforms such |
4748 | as GNU/Linux] | |
4c4b4cd2 | 4749 | ___[0-9]+ [nested subprogram suffix, on platforms such as HP/UX] |
529cad9c | 4750 | _E[0-9]+[bs]$ [protected object entry suffixes] |
61ee279c | 4751 | (X[nb]*)?((\$|__)[0-9](_?[0-9]+)|___(JM|LJM|X([FDBUP].*|R[^T]?)))?$ |
14f9c5c9 | 4752 | */ |
4c4b4cd2 | 4753 | |
14f9c5c9 | 4754 | static int |
d2e4a39e | 4755 | is_name_suffix (const char *str) |
14f9c5c9 AS |
4756 | { |
4757 | int k; | |
4c4b4cd2 PH |
4758 | const char *matching; |
4759 | const int len = strlen (str); | |
4760 | ||
4761 | /* (__[0-9]+)?\.[0-9]+ */ | |
4762 | matching = str; | |
4763 | if (len > 3 && str[0] == '_' && str[1] == '_' && isdigit (str[2])) | |
4764 | { | |
4765 | matching += 3; | |
4766 | while (isdigit (matching[0])) | |
4767 | matching += 1; | |
4768 | if (matching[0] == '\0') | |
4769 | return 1; | |
4770 | } | |
4771 | ||
529cad9c | 4772 | if (matching[0] == '.' || matching[0] == '$') |
4c4b4cd2 PH |
4773 | { |
4774 | matching += 1; | |
4775 | while (isdigit (matching[0])) | |
4776 | matching += 1; | |
4777 | if (matching[0] == '\0') | |
4778 | return 1; | |
4779 | } | |
4780 | ||
4781 | /* ___[0-9]+ */ | |
4782 | if (len > 3 && str[0] == '_' && str[1] == '_' && str[2] == '_') | |
4783 | { | |
4784 | matching = str + 3; | |
4785 | while (isdigit (matching[0])) | |
4786 | matching += 1; | |
4787 | if (matching[0] == '\0') | |
4788 | return 1; | |
4789 | } | |
4790 | ||
529cad9c PH |
4791 | #if 0 |
4792 | /* FIXME: brobecker/2005-09-23: Protected Object subprograms end | |
4793 | with a N at the end. Unfortunately, the compiler uses the same | |
4794 | convention for other internal types it creates. So treating | |
4795 | all entity names that end with an "N" as a name suffix causes | |
4796 | some regressions. For instance, consider the case of an enumerated | |
4797 | type. To support the 'Image attribute, it creates an array whose | |
4798 | name ends with N. | |
4799 | Having a single character like this as a suffix carrying some | |
4800 | information is a bit risky. Perhaps we should change the encoding | |
4801 | to be something like "_N" instead. In the meantime, do not do | |
4802 | the following check. */ | |
4803 | /* Protected Object Subprograms */ | |
4804 | if (len == 1 && str [0] == 'N') | |
4805 | return 1; | |
4806 | #endif | |
4807 | ||
4808 | /* _E[0-9]+[bs]$ */ | |
4809 | if (len > 3 && str[0] == '_' && str [1] == 'E' && isdigit (str[2])) | |
4810 | { | |
4811 | matching = str + 3; | |
4812 | while (isdigit (matching[0])) | |
4813 | matching += 1; | |
4814 | if ((matching[0] == 'b' || matching[0] == 's') | |
4815 | && matching [1] == '\0') | |
4816 | return 1; | |
4817 | } | |
4818 | ||
4c4b4cd2 PH |
4819 | /* ??? We should not modify STR directly, as we are doing below. This |
4820 | is fine in this case, but may become problematic later if we find | |
4821 | that this alternative did not work, and want to try matching | |
4822 | another one from the begining of STR. Since we modified it, we | |
4823 | won't be able to find the begining of the string anymore! */ | |
14f9c5c9 AS |
4824 | if (str[0] == 'X') |
4825 | { | |
4826 | str += 1; | |
d2e4a39e | 4827 | while (str[0] != '_' && str[0] != '\0') |
4c4b4cd2 PH |
4828 | { |
4829 | if (str[0] != 'n' && str[0] != 'b') | |
4830 | return 0; | |
4831 | str += 1; | |
4832 | } | |
14f9c5c9 AS |
4833 | } |
4834 | if (str[0] == '\000') | |
4835 | return 1; | |
d2e4a39e | 4836 | if (str[0] == '_') |
14f9c5c9 AS |
4837 | { |
4838 | if (str[1] != '_' || str[2] == '\000') | |
4c4b4cd2 | 4839 | return 0; |
d2e4a39e | 4840 | if (str[2] == '_') |
4c4b4cd2 | 4841 | { |
61ee279c PH |
4842 | if (strcmp (str + 3, "JM") == 0) |
4843 | return 1; | |
4844 | /* FIXME: brobecker/2004-09-30: GNAT will soon stop using | |
4845 | the LJM suffix in favor of the JM one. But we will | |
4846 | still accept LJM as a valid suffix for a reasonable | |
4847 | amount of time, just to allow ourselves to debug programs | |
4848 | compiled using an older version of GNAT. */ | |
4c4b4cd2 PH |
4849 | if (strcmp (str + 3, "LJM") == 0) |
4850 | return 1; | |
4851 | if (str[3] != 'X') | |
4852 | return 0; | |
1265e4aa JB |
4853 | if (str[4] == 'F' || str[4] == 'D' || str[4] == 'B' |
4854 | || str[4] == 'U' || str[4] == 'P') | |
4c4b4cd2 PH |
4855 | return 1; |
4856 | if (str[4] == 'R' && str[5] != 'T') | |
4857 | return 1; | |
4858 | return 0; | |
4859 | } | |
4860 | if (!isdigit (str[2])) | |
4861 | return 0; | |
4862 | for (k = 3; str[k] != '\0'; k += 1) | |
4863 | if (!isdigit (str[k]) && str[k] != '_') | |
4864 | return 0; | |
14f9c5c9 AS |
4865 | return 1; |
4866 | } | |
4c4b4cd2 | 4867 | if (str[0] == '$' && isdigit (str[1])) |
14f9c5c9 | 4868 | { |
4c4b4cd2 PH |
4869 | for (k = 2; str[k] != '\0'; k += 1) |
4870 | if (!isdigit (str[k]) && str[k] != '_') | |
4871 | return 0; | |
14f9c5c9 AS |
4872 | return 1; |
4873 | } | |
4874 | return 0; | |
4875 | } | |
d2e4a39e | 4876 | |
4c4b4cd2 PH |
4877 | /* Return nonzero if the given string starts with a dot ('.') |
4878 | followed by zero or more digits. | |
4879 | ||
4880 | Note: brobecker/2003-11-10: A forward declaration has not been | |
4881 | added at the begining of this file yet, because this function | |
4882 | is only used to work around a problem found during wild matching | |
4883 | when trying to match minimal symbol names against symbol names | |
4884 | obtained from dwarf-2 data. This function is therefore currently | |
4885 | only used in wild_match() and is likely to be deleted when the | |
4886 | problem in dwarf-2 is fixed. */ | |
4887 | ||
4888 | static int | |
4889 | is_dot_digits_suffix (const char *str) | |
4890 | { | |
4891 | if (str[0] != '.') | |
4892 | return 0; | |
4893 | ||
4894 | str++; | |
4895 | while (isdigit (str[0])) | |
4896 | str++; | |
4897 | return (str[0] == '\0'); | |
4898 | } | |
4899 | ||
529cad9c PH |
4900 | /* Return non-zero if NAME0 is a valid match when doing wild matching. |
4901 | Certain symbols appear at first to match, except that they turn out | |
4902 | not to follow the Ada encoding and hence should not be used as a wild | |
4903 | match of a given pattern. */ | |
4904 | ||
4905 | static int | |
4906 | is_valid_name_for_wild_match (const char *name0) | |
4907 | { | |
4908 | const char *decoded_name = ada_decode (name0); | |
4909 | int i; | |
4910 | ||
4911 | for (i=0; decoded_name[i] != '\0'; i++) | |
4912 | if (isalpha (decoded_name[i]) && !islower (decoded_name[i])) | |
4913 | return 0; | |
4914 | ||
4915 | return 1; | |
4916 | } | |
4917 | ||
4c4b4cd2 PH |
4918 | /* True if NAME represents a name of the form A1.A2....An, n>=1 and |
4919 | PATN[0..PATN_LEN-1] = Ak.Ak+1.....An for some k >= 1. Ignores | |
4920 | informational suffixes of NAME (i.e., for which is_name_suffix is | |
4921 | true). */ | |
4922 | ||
14f9c5c9 | 4923 | static int |
4c4b4cd2 | 4924 | wild_match (const char *patn0, int patn_len, const char *name0) |
14f9c5c9 AS |
4925 | { |
4926 | int name_len; | |
4c4b4cd2 PH |
4927 | char *name; |
4928 | char *patn; | |
4929 | ||
4930 | /* FIXME: brobecker/2003-11-10: For some reason, the symbol name | |
4931 | stored in the symbol table for nested function names is sometimes | |
4932 | different from the name of the associated entity stored in | |
4933 | the dwarf-2 data: This is the case for nested subprograms, where | |
4934 | the minimal symbol name contains a trailing ".[:digit:]+" suffix, | |
4935 | while the symbol name from the dwarf-2 data does not. | |
4936 | ||
4937 | Although the DWARF-2 standard documents that entity names stored | |
4938 | in the dwarf-2 data should be identical to the name as seen in | |
4939 | the source code, GNAT takes a different approach as we already use | |
4940 | a special encoding mechanism to convey the information so that | |
4941 | a C debugger can still use the information generated to debug | |
4942 | Ada programs. A corollary is that the symbol names in the dwarf-2 | |
4943 | data should match the names found in the symbol table. I therefore | |
4944 | consider this issue as a compiler defect. | |
76a01679 | 4945 | |
4c4b4cd2 PH |
4946 | Until the compiler is properly fixed, we work-around the problem |
4947 | by ignoring such suffixes during the match. We do so by making | |
4948 | a copy of PATN0 and NAME0, and then by stripping such a suffix | |
4949 | if present. We then perform the match on the resulting strings. */ | |
4950 | { | |
4951 | char *dot; | |
4952 | name_len = strlen (name0); | |
4953 | ||
4954 | name = (char *) alloca ((name_len + 1) * sizeof (char)); | |
4955 | strcpy (name, name0); | |
4956 | dot = strrchr (name, '.'); | |
4957 | if (dot != NULL && is_dot_digits_suffix (dot)) | |
4958 | *dot = '\0'; | |
4959 | ||
4960 | patn = (char *) alloca ((patn_len + 1) * sizeof (char)); | |
4961 | strncpy (patn, patn0, patn_len); | |
4962 | patn[patn_len] = '\0'; | |
4963 | dot = strrchr (patn, '.'); | |
4964 | if (dot != NULL && is_dot_digits_suffix (dot)) | |
4965 | { | |
4966 | *dot = '\0'; | |
4967 | patn_len = dot - patn; | |
4968 | } | |
4969 | } | |
4970 | ||
4971 | /* Now perform the wild match. */ | |
14f9c5c9 AS |
4972 | |
4973 | name_len = strlen (name); | |
4c4b4cd2 PH |
4974 | if (name_len >= patn_len + 5 && strncmp (name, "_ada_", 5) == 0 |
4975 | && strncmp (patn, name + 5, patn_len) == 0 | |
d2e4a39e | 4976 | && is_name_suffix (name + patn_len + 5)) |
14f9c5c9 AS |
4977 | return 1; |
4978 | ||
d2e4a39e | 4979 | while (name_len >= patn_len) |
14f9c5c9 | 4980 | { |
4c4b4cd2 PH |
4981 | if (strncmp (patn, name, patn_len) == 0 |
4982 | && is_name_suffix (name + patn_len)) | |
529cad9c | 4983 | return (is_valid_name_for_wild_match (name0)); |
4c4b4cd2 PH |
4984 | do |
4985 | { | |
4986 | name += 1; | |
4987 | name_len -= 1; | |
4988 | } | |
d2e4a39e | 4989 | while (name_len > 0 |
4c4b4cd2 | 4990 | && name[0] != '.' && (name[0] != '_' || name[1] != '_')); |
14f9c5c9 | 4991 | if (name_len <= 0) |
4c4b4cd2 | 4992 | return 0; |
14f9c5c9 | 4993 | if (name[0] == '_') |
4c4b4cd2 PH |
4994 | { |
4995 | if (!islower (name[2])) | |
4996 | return 0; | |
4997 | name += 2; | |
4998 | name_len -= 2; | |
4999 | } | |
14f9c5c9 | 5000 | else |
4c4b4cd2 PH |
5001 | { |
5002 | if (!islower (name[1])) | |
5003 | return 0; | |
5004 | name += 1; | |
5005 | name_len -= 1; | |
5006 | } | |
96d887e8 PH |
5007 | } |
5008 | ||
5009 | return 0; | |
5010 | } | |
5011 | ||
5012 | ||
5013 | /* Add symbols from BLOCK matching identifier NAME in DOMAIN to | |
5014 | vector *defn_symbols, updating the list of symbols in OBSTACKP | |
5015 | (if necessary). If WILD, treat as NAME with a wildcard prefix. | |
5016 | OBJFILE is the section containing BLOCK. | |
5017 | SYMTAB is recorded with each symbol added. */ | |
5018 | ||
5019 | static void | |
5020 | ada_add_block_symbols (struct obstack *obstackp, | |
76a01679 | 5021 | struct block *block, const char *name, |
96d887e8 PH |
5022 | domain_enum domain, struct objfile *objfile, |
5023 | struct symtab *symtab, int wild) | |
5024 | { | |
5025 | struct dict_iterator iter; | |
5026 | int name_len = strlen (name); | |
5027 | /* A matching argument symbol, if any. */ | |
5028 | struct symbol *arg_sym; | |
5029 | /* Set true when we find a matching non-argument symbol. */ | |
5030 | int found_sym; | |
5031 | struct symbol *sym; | |
5032 | ||
5033 | arg_sym = NULL; | |
5034 | found_sym = 0; | |
5035 | if (wild) | |
5036 | { | |
5037 | struct symbol *sym; | |
5038 | ALL_BLOCK_SYMBOLS (block, iter, sym) | |
76a01679 | 5039 | { |
1265e4aa JB |
5040 | if (SYMBOL_DOMAIN (sym) == domain |
5041 | && wild_match (name, name_len, SYMBOL_LINKAGE_NAME (sym))) | |
76a01679 JB |
5042 | { |
5043 | switch (SYMBOL_CLASS (sym)) | |
5044 | { | |
5045 | case LOC_ARG: | |
5046 | case LOC_LOCAL_ARG: | |
5047 | case LOC_REF_ARG: | |
5048 | case LOC_REGPARM: | |
5049 | case LOC_REGPARM_ADDR: | |
5050 | case LOC_BASEREG_ARG: | |
5051 | case LOC_COMPUTED_ARG: | |
5052 | arg_sym = sym; | |
5053 | break; | |
5054 | case LOC_UNRESOLVED: | |
5055 | continue; | |
5056 | default: | |
5057 | found_sym = 1; | |
5058 | add_defn_to_vec (obstackp, | |
5059 | fixup_symbol_section (sym, objfile), | |
5060 | block, symtab); | |
5061 | break; | |
5062 | } | |
5063 | } | |
5064 | } | |
96d887e8 PH |
5065 | } |
5066 | else | |
5067 | { | |
5068 | ALL_BLOCK_SYMBOLS (block, iter, sym) | |
76a01679 JB |
5069 | { |
5070 | if (SYMBOL_DOMAIN (sym) == domain) | |
5071 | { | |
5072 | int cmp = strncmp (name, SYMBOL_LINKAGE_NAME (sym), name_len); | |
5073 | if (cmp == 0 | |
5074 | && is_name_suffix (SYMBOL_LINKAGE_NAME (sym) + name_len)) | |
5075 | { | |
5076 | switch (SYMBOL_CLASS (sym)) | |
5077 | { | |
5078 | case LOC_ARG: | |
5079 | case LOC_LOCAL_ARG: | |
5080 | case LOC_REF_ARG: | |
5081 | case LOC_REGPARM: | |
5082 | case LOC_REGPARM_ADDR: | |
5083 | case LOC_BASEREG_ARG: | |
5084 | case LOC_COMPUTED_ARG: | |
5085 | arg_sym = sym; | |
5086 | break; | |
5087 | case LOC_UNRESOLVED: | |
5088 | break; | |
5089 | default: | |
5090 | found_sym = 1; | |
5091 | add_defn_to_vec (obstackp, | |
5092 | fixup_symbol_section (sym, objfile), | |
5093 | block, symtab); | |
5094 | break; | |
5095 | } | |
5096 | } | |
5097 | } | |
5098 | } | |
96d887e8 PH |
5099 | } |
5100 | ||
5101 | if (!found_sym && arg_sym != NULL) | |
5102 | { | |
76a01679 JB |
5103 | add_defn_to_vec (obstackp, |
5104 | fixup_symbol_section (arg_sym, objfile), | |
5105 | block, symtab); | |
96d887e8 PH |
5106 | } |
5107 | ||
5108 | if (!wild) | |
5109 | { | |
5110 | arg_sym = NULL; | |
5111 | found_sym = 0; | |
5112 | ||
5113 | ALL_BLOCK_SYMBOLS (block, iter, sym) | |
76a01679 JB |
5114 | { |
5115 | if (SYMBOL_DOMAIN (sym) == domain) | |
5116 | { | |
5117 | int cmp; | |
5118 | ||
5119 | cmp = (int) '_' - (int) SYMBOL_LINKAGE_NAME (sym)[0]; | |
5120 | if (cmp == 0) | |
5121 | { | |
5122 | cmp = strncmp ("_ada_", SYMBOL_LINKAGE_NAME (sym), 5); | |
5123 | if (cmp == 0) | |
5124 | cmp = strncmp (name, SYMBOL_LINKAGE_NAME (sym) + 5, | |
5125 | name_len); | |
5126 | } | |
5127 | ||
5128 | if (cmp == 0 | |
5129 | && is_name_suffix (SYMBOL_LINKAGE_NAME (sym) + name_len + 5)) | |
5130 | { | |
5131 | switch (SYMBOL_CLASS (sym)) | |
5132 | { | |
5133 | case LOC_ARG: | |
5134 | case LOC_LOCAL_ARG: | |
5135 | case LOC_REF_ARG: | |
5136 | case LOC_REGPARM: | |
5137 | case LOC_REGPARM_ADDR: | |
5138 | case LOC_BASEREG_ARG: | |
5139 | case LOC_COMPUTED_ARG: | |
5140 | arg_sym = sym; | |
5141 | break; | |
5142 | case LOC_UNRESOLVED: | |
5143 | break; | |
5144 | default: | |
5145 | found_sym = 1; | |
5146 | add_defn_to_vec (obstackp, | |
5147 | fixup_symbol_section (sym, objfile), | |
5148 | block, symtab); | |
5149 | break; | |
5150 | } | |
5151 | } | |
5152 | } | |
76a01679 | 5153 | } |
96d887e8 PH |
5154 | |
5155 | /* NOTE: This really shouldn't be needed for _ada_ symbols. | |
5156 | They aren't parameters, right? */ | |
5157 | if (!found_sym && arg_sym != NULL) | |
5158 | { | |
5159 | add_defn_to_vec (obstackp, | |
76a01679 JB |
5160 | fixup_symbol_section (arg_sym, objfile), |
5161 | block, symtab); | |
96d887e8 PH |
5162 | } |
5163 | } | |
5164 | } | |
5165 | \f | |
963a6417 | 5166 | /* Field Access */ |
96d887e8 | 5167 | |
963a6417 PH |
5168 | /* True if field number FIELD_NUM in struct or union type TYPE is supposed |
5169 | to be invisible to users. */ | |
96d887e8 | 5170 | |
963a6417 PH |
5171 | int |
5172 | ada_is_ignored_field (struct type *type, int field_num) | |
96d887e8 | 5173 | { |
963a6417 PH |
5174 | if (field_num < 0 || field_num > TYPE_NFIELDS (type)) |
5175 | return 1; | |
5176 | else | |
96d887e8 | 5177 | { |
963a6417 PH |
5178 | const char *name = TYPE_FIELD_NAME (type, field_num); |
5179 | return (name == NULL | |
5180 | || (name[0] == '_' && strncmp (name, "_parent", 7) != 0)); | |
96d887e8 | 5181 | } |
963a6417 | 5182 | } |
96d887e8 | 5183 | |
963a6417 PH |
5184 | /* True iff TYPE has a tag field. If REFOK, then TYPE may also be a |
5185 | pointer or reference type whose ultimate target has a tag field. */ | |
96d887e8 | 5186 | |
963a6417 PH |
5187 | int |
5188 | ada_is_tagged_type (struct type *type, int refok) | |
5189 | { | |
5190 | return (ada_lookup_struct_elt_type (type, "_tag", refok, 1, NULL) != NULL); | |
5191 | } | |
96d887e8 | 5192 | |
963a6417 | 5193 | /* True iff TYPE represents the type of X'Tag */ |
96d887e8 | 5194 | |
963a6417 PH |
5195 | int |
5196 | ada_is_tag_type (struct type *type) | |
5197 | { | |
5198 | if (type == NULL || TYPE_CODE (type) != TYPE_CODE_PTR) | |
5199 | return 0; | |
5200 | else | |
96d887e8 | 5201 | { |
963a6417 PH |
5202 | const char *name = ada_type_name (TYPE_TARGET_TYPE (type)); |
5203 | return (name != NULL | |
5204 | && strcmp (name, "ada__tags__dispatch_table") == 0); | |
96d887e8 | 5205 | } |
96d887e8 PH |
5206 | } |
5207 | ||
963a6417 | 5208 | /* The type of the tag on VAL. */ |
76a01679 | 5209 | |
963a6417 PH |
5210 | struct type * |
5211 | ada_tag_type (struct value *val) | |
96d887e8 | 5212 | { |
df407dfe | 5213 | return ada_lookup_struct_elt_type (value_type (val), "_tag", 1, 0, NULL); |
963a6417 | 5214 | } |
96d887e8 | 5215 | |
963a6417 | 5216 | /* The value of the tag on VAL. */ |
96d887e8 | 5217 | |
963a6417 PH |
5218 | struct value * |
5219 | ada_value_tag (struct value *val) | |
5220 | { | |
03ee6b2e | 5221 | return ada_value_struct_elt (val, "_tag", 0); |
96d887e8 PH |
5222 | } |
5223 | ||
963a6417 PH |
5224 | /* The value of the tag on the object of type TYPE whose contents are |
5225 | saved at VALADDR, if it is non-null, or is at memory address | |
5226 | ADDRESS. */ | |
96d887e8 | 5227 | |
963a6417 | 5228 | static struct value * |
10a2c479 | 5229 | value_tag_from_contents_and_address (struct type *type, |
fc1a4b47 | 5230 | const gdb_byte *valaddr, |
963a6417 | 5231 | CORE_ADDR address) |
96d887e8 | 5232 | { |
963a6417 PH |
5233 | int tag_byte_offset, dummy1, dummy2; |
5234 | struct type *tag_type; | |
5235 | if (find_struct_field ("_tag", type, 0, &tag_type, &tag_byte_offset, | |
52ce6436 | 5236 | NULL, NULL, NULL)) |
96d887e8 | 5237 | { |
fc1a4b47 | 5238 | const gdb_byte *valaddr1 = ((valaddr == NULL) |
10a2c479 AC |
5239 | ? NULL |
5240 | : valaddr + tag_byte_offset); | |
963a6417 | 5241 | CORE_ADDR address1 = (address == 0) ? 0 : address + tag_byte_offset; |
96d887e8 | 5242 | |
963a6417 | 5243 | return value_from_contents_and_address (tag_type, valaddr1, address1); |
96d887e8 | 5244 | } |
963a6417 PH |
5245 | return NULL; |
5246 | } | |
96d887e8 | 5247 | |
963a6417 PH |
5248 | static struct type * |
5249 | type_from_tag (struct value *tag) | |
5250 | { | |
5251 | const char *type_name = ada_tag_name (tag); | |
5252 | if (type_name != NULL) | |
5253 | return ada_find_any_type (ada_encode (type_name)); | |
5254 | return NULL; | |
5255 | } | |
96d887e8 | 5256 | |
963a6417 PH |
5257 | struct tag_args |
5258 | { | |
5259 | struct value *tag; | |
5260 | char *name; | |
5261 | }; | |
4c4b4cd2 | 5262 | |
529cad9c PH |
5263 | |
5264 | static int ada_tag_name_1 (void *); | |
5265 | static int ada_tag_name_2 (struct tag_args *); | |
5266 | ||
4c4b4cd2 PH |
5267 | /* Wrapper function used by ada_tag_name. Given a struct tag_args* |
5268 | value ARGS, sets ARGS->name to the tag name of ARGS->tag. | |
5269 | The value stored in ARGS->name is valid until the next call to | |
5270 | ada_tag_name_1. */ | |
5271 | ||
5272 | static int | |
5273 | ada_tag_name_1 (void *args0) | |
5274 | { | |
5275 | struct tag_args *args = (struct tag_args *) args0; | |
5276 | static char name[1024]; | |
76a01679 | 5277 | char *p; |
4c4b4cd2 PH |
5278 | struct value *val; |
5279 | args->name = NULL; | |
03ee6b2e | 5280 | val = ada_value_struct_elt (args->tag, "tsd", 1); |
529cad9c PH |
5281 | if (val == NULL) |
5282 | return ada_tag_name_2 (args); | |
03ee6b2e | 5283 | val = ada_value_struct_elt (val, "expanded_name", 1); |
529cad9c PH |
5284 | if (val == NULL) |
5285 | return 0; | |
5286 | read_memory_string (value_as_address (val), name, sizeof (name) - 1); | |
5287 | for (p = name; *p != '\0'; p += 1) | |
5288 | if (isalpha (*p)) | |
5289 | *p = tolower (*p); | |
5290 | args->name = name; | |
5291 | return 0; | |
5292 | } | |
5293 | ||
5294 | /* Utility function for ada_tag_name_1 that tries the second | |
5295 | representation for the dispatch table (in which there is no | |
5296 | explicit 'tsd' field in the referent of the tag pointer, and instead | |
5297 | the tsd pointer is stored just before the dispatch table. */ | |
5298 | ||
5299 | static int | |
5300 | ada_tag_name_2 (struct tag_args *args) | |
5301 | { | |
5302 | struct type *info_type; | |
5303 | static char name[1024]; | |
5304 | char *p; | |
5305 | struct value *val, *valp; | |
5306 | ||
5307 | args->name = NULL; | |
5308 | info_type = ada_find_any_type ("ada__tags__type_specific_data"); | |
5309 | if (info_type == NULL) | |
5310 | return 0; | |
5311 | info_type = lookup_pointer_type (lookup_pointer_type (info_type)); | |
5312 | valp = value_cast (info_type, args->tag); | |
5313 | if (valp == NULL) | |
5314 | return 0; | |
5315 | val = value_ind (value_add (valp, value_from_longest (builtin_type_int, -1))); | |
4c4b4cd2 PH |
5316 | if (val == NULL) |
5317 | return 0; | |
03ee6b2e | 5318 | val = ada_value_struct_elt (val, "expanded_name", 1); |
4c4b4cd2 PH |
5319 | if (val == NULL) |
5320 | return 0; | |
5321 | read_memory_string (value_as_address (val), name, sizeof (name) - 1); | |
5322 | for (p = name; *p != '\0'; p += 1) | |
5323 | if (isalpha (*p)) | |
5324 | *p = tolower (*p); | |
5325 | args->name = name; | |
5326 | return 0; | |
5327 | } | |
5328 | ||
5329 | /* The type name of the dynamic type denoted by the 'tag value TAG, as | |
5330 | * a C string. */ | |
5331 | ||
5332 | const char * | |
5333 | ada_tag_name (struct value *tag) | |
5334 | { | |
5335 | struct tag_args args; | |
df407dfe | 5336 | if (!ada_is_tag_type (value_type (tag))) |
4c4b4cd2 | 5337 | return NULL; |
76a01679 | 5338 | args.tag = tag; |
4c4b4cd2 PH |
5339 | args.name = NULL; |
5340 | catch_errors (ada_tag_name_1, &args, NULL, RETURN_MASK_ALL); | |
5341 | return args.name; | |
5342 | } | |
5343 | ||
5344 | /* The parent type of TYPE, or NULL if none. */ | |
14f9c5c9 | 5345 | |
d2e4a39e | 5346 | struct type * |
ebf56fd3 | 5347 | ada_parent_type (struct type *type) |
14f9c5c9 AS |
5348 | { |
5349 | int i; | |
5350 | ||
61ee279c | 5351 | type = ada_check_typedef (type); |
14f9c5c9 AS |
5352 | |
5353 | if (type == NULL || TYPE_CODE (type) != TYPE_CODE_STRUCT) | |
5354 | return NULL; | |
5355 | ||
5356 | for (i = 0; i < TYPE_NFIELDS (type); i += 1) | |
5357 | if (ada_is_parent_field (type, i)) | |
61ee279c | 5358 | return ada_check_typedef (TYPE_FIELD_TYPE (type, i)); |
14f9c5c9 AS |
5359 | |
5360 | return NULL; | |
5361 | } | |
5362 | ||
4c4b4cd2 PH |
5363 | /* True iff field number FIELD_NUM of structure type TYPE contains the |
5364 | parent-type (inherited) fields of a derived type. Assumes TYPE is | |
5365 | a structure type with at least FIELD_NUM+1 fields. */ | |
14f9c5c9 AS |
5366 | |
5367 | int | |
ebf56fd3 | 5368 | ada_is_parent_field (struct type *type, int field_num) |
14f9c5c9 | 5369 | { |
61ee279c | 5370 | const char *name = TYPE_FIELD_NAME (ada_check_typedef (type), field_num); |
4c4b4cd2 PH |
5371 | return (name != NULL |
5372 | && (strncmp (name, "PARENT", 6) == 0 | |
5373 | || strncmp (name, "_parent", 7) == 0)); | |
14f9c5c9 AS |
5374 | } |
5375 | ||
4c4b4cd2 | 5376 | /* True iff field number FIELD_NUM of structure type TYPE is a |
14f9c5c9 | 5377 | transparent wrapper field (which should be silently traversed when doing |
4c4b4cd2 | 5378 | field selection and flattened when printing). Assumes TYPE is a |
14f9c5c9 | 5379 | structure type with at least FIELD_NUM+1 fields. Such fields are always |
4c4b4cd2 | 5380 | structures. */ |
14f9c5c9 AS |
5381 | |
5382 | int | |
ebf56fd3 | 5383 | ada_is_wrapper_field (struct type *type, int field_num) |
14f9c5c9 | 5384 | { |
d2e4a39e AS |
5385 | const char *name = TYPE_FIELD_NAME (type, field_num); |
5386 | return (name != NULL | |
4c4b4cd2 PH |
5387 | && (strncmp (name, "PARENT", 6) == 0 |
5388 | || strcmp (name, "REP") == 0 | |
5389 | || strncmp (name, "_parent", 7) == 0 | |
5390 | || name[0] == 'S' || name[0] == 'R' || name[0] == 'O')); | |
14f9c5c9 AS |
5391 | } |
5392 | ||
4c4b4cd2 PH |
5393 | /* True iff field number FIELD_NUM of structure or union type TYPE |
5394 | is a variant wrapper. Assumes TYPE is a structure type with at least | |
5395 | FIELD_NUM+1 fields. */ | |
14f9c5c9 AS |
5396 | |
5397 | int | |
ebf56fd3 | 5398 | ada_is_variant_part (struct type *type, int field_num) |
14f9c5c9 | 5399 | { |
d2e4a39e | 5400 | struct type *field_type = TYPE_FIELD_TYPE (type, field_num); |
14f9c5c9 | 5401 | return (TYPE_CODE (field_type) == TYPE_CODE_UNION |
4c4b4cd2 | 5402 | || (is_dynamic_field (type, field_num) |
c3e5cd34 PH |
5403 | && (TYPE_CODE (TYPE_TARGET_TYPE (field_type)) |
5404 | == TYPE_CODE_UNION))); | |
14f9c5c9 AS |
5405 | } |
5406 | ||
5407 | /* Assuming that VAR_TYPE is a variant wrapper (type of the variant part) | |
4c4b4cd2 | 5408 | whose discriminants are contained in the record type OUTER_TYPE, |
14f9c5c9 AS |
5409 | returns the type of the controlling discriminant for the variant. */ |
5410 | ||
d2e4a39e | 5411 | struct type * |
ebf56fd3 | 5412 | ada_variant_discrim_type (struct type *var_type, struct type *outer_type) |
14f9c5c9 | 5413 | { |
d2e4a39e | 5414 | char *name = ada_variant_discrim_name (var_type); |
76a01679 | 5415 | struct type *type = |
4c4b4cd2 | 5416 | ada_lookup_struct_elt_type (outer_type, name, 1, 1, NULL); |
14f9c5c9 AS |
5417 | if (type == NULL) |
5418 | return builtin_type_int; | |
5419 | else | |
5420 | return type; | |
5421 | } | |
5422 | ||
4c4b4cd2 | 5423 | /* Assuming that TYPE is the type of a variant wrapper, and FIELD_NUM is a |
14f9c5c9 | 5424 | valid field number within it, returns 1 iff field FIELD_NUM of TYPE |
4c4b4cd2 | 5425 | represents a 'when others' clause; otherwise 0. */ |
14f9c5c9 AS |
5426 | |
5427 | int | |
ebf56fd3 | 5428 | ada_is_others_clause (struct type *type, int field_num) |
14f9c5c9 | 5429 | { |
d2e4a39e | 5430 | const char *name = TYPE_FIELD_NAME (type, field_num); |
14f9c5c9 AS |
5431 | return (name != NULL && name[0] == 'O'); |
5432 | } | |
5433 | ||
5434 | /* Assuming that TYPE0 is the type of the variant part of a record, | |
4c4b4cd2 PH |
5435 | returns the name of the discriminant controlling the variant. |
5436 | The value is valid until the next call to ada_variant_discrim_name. */ | |
14f9c5c9 | 5437 | |
d2e4a39e | 5438 | char * |
ebf56fd3 | 5439 | ada_variant_discrim_name (struct type *type0) |
14f9c5c9 | 5440 | { |
d2e4a39e | 5441 | static char *result = NULL; |
14f9c5c9 | 5442 | static size_t result_len = 0; |
d2e4a39e AS |
5443 | struct type *type; |
5444 | const char *name; | |
5445 | const char *discrim_end; | |
5446 | const char *discrim_start; | |
14f9c5c9 AS |
5447 | |
5448 | if (TYPE_CODE (type0) == TYPE_CODE_PTR) | |
5449 | type = TYPE_TARGET_TYPE (type0); | |
5450 | else | |
5451 | type = type0; | |
5452 | ||
5453 | name = ada_type_name (type); | |
5454 | ||
5455 | if (name == NULL || name[0] == '\000') | |
5456 | return ""; | |
5457 | ||
5458 | for (discrim_end = name + strlen (name) - 6; discrim_end != name; | |
5459 | discrim_end -= 1) | |
5460 | { | |
4c4b4cd2 PH |
5461 | if (strncmp (discrim_end, "___XVN", 6) == 0) |
5462 | break; | |
14f9c5c9 AS |
5463 | } |
5464 | if (discrim_end == name) | |
5465 | return ""; | |
5466 | ||
d2e4a39e | 5467 | for (discrim_start = discrim_end; discrim_start != name + 3; |
14f9c5c9 AS |
5468 | discrim_start -= 1) |
5469 | { | |
d2e4a39e | 5470 | if (discrim_start == name + 1) |
4c4b4cd2 | 5471 | return ""; |
76a01679 | 5472 | if ((discrim_start > name + 3 |
4c4b4cd2 PH |
5473 | && strncmp (discrim_start - 3, "___", 3) == 0) |
5474 | || discrim_start[-1] == '.') | |
5475 | break; | |
14f9c5c9 AS |
5476 | } |
5477 | ||
5478 | GROW_VECT (result, result_len, discrim_end - discrim_start + 1); | |
5479 | strncpy (result, discrim_start, discrim_end - discrim_start); | |
d2e4a39e | 5480 | result[discrim_end - discrim_start] = '\0'; |
14f9c5c9 AS |
5481 | return result; |
5482 | } | |
5483 | ||
4c4b4cd2 PH |
5484 | /* Scan STR for a subtype-encoded number, beginning at position K. |
5485 | Put the position of the character just past the number scanned in | |
5486 | *NEW_K, if NEW_K!=NULL. Put the scanned number in *R, if R!=NULL. | |
5487 | Return 1 if there was a valid number at the given position, and 0 | |
5488 | otherwise. A "subtype-encoded" number consists of the absolute value | |
5489 | in decimal, followed by the letter 'm' to indicate a negative number. | |
5490 | Assumes 0m does not occur. */ | |
14f9c5c9 AS |
5491 | |
5492 | int | |
d2e4a39e | 5493 | ada_scan_number (const char str[], int k, LONGEST * R, int *new_k) |
14f9c5c9 AS |
5494 | { |
5495 | ULONGEST RU; | |
5496 | ||
d2e4a39e | 5497 | if (!isdigit (str[k])) |
14f9c5c9 AS |
5498 | return 0; |
5499 | ||
4c4b4cd2 | 5500 | /* Do it the hard way so as not to make any assumption about |
14f9c5c9 | 5501 | the relationship of unsigned long (%lu scan format code) and |
4c4b4cd2 | 5502 | LONGEST. */ |
14f9c5c9 AS |
5503 | RU = 0; |
5504 | while (isdigit (str[k])) | |
5505 | { | |
d2e4a39e | 5506 | RU = RU * 10 + (str[k] - '0'); |
14f9c5c9 AS |
5507 | k += 1; |
5508 | } | |
5509 | ||
d2e4a39e | 5510 | if (str[k] == 'm') |
14f9c5c9 AS |
5511 | { |
5512 | if (R != NULL) | |
4c4b4cd2 | 5513 | *R = (-(LONGEST) (RU - 1)) - 1; |
14f9c5c9 AS |
5514 | k += 1; |
5515 | } | |
5516 | else if (R != NULL) | |
5517 | *R = (LONGEST) RU; | |
5518 | ||
4c4b4cd2 | 5519 | /* NOTE on the above: Technically, C does not say what the results of |
14f9c5c9 AS |
5520 | - (LONGEST) RU or (LONGEST) -RU are for RU == largest positive |
5521 | number representable as a LONGEST (although either would probably work | |
5522 | in most implementations). When RU>0, the locution in the then branch | |
4c4b4cd2 | 5523 | above is always equivalent to the negative of RU. */ |
14f9c5c9 AS |
5524 | |
5525 | if (new_k != NULL) | |
5526 | *new_k = k; | |
5527 | return 1; | |
5528 | } | |
5529 | ||
4c4b4cd2 PH |
5530 | /* Assuming that TYPE is a variant part wrapper type (a VARIANTS field), |
5531 | and FIELD_NUM is a valid field number within it, returns 1 iff VAL is | |
5532 | in the range encoded by field FIELD_NUM of TYPE; otherwise 0. */ | |
14f9c5c9 | 5533 | |
d2e4a39e | 5534 | int |
ebf56fd3 | 5535 | ada_in_variant (LONGEST val, struct type *type, int field_num) |
14f9c5c9 | 5536 | { |
d2e4a39e | 5537 | const char *name = TYPE_FIELD_NAME (type, field_num); |
14f9c5c9 AS |
5538 | int p; |
5539 | ||
5540 | p = 0; | |
5541 | while (1) | |
5542 | { | |
d2e4a39e | 5543 | switch (name[p]) |
4c4b4cd2 PH |
5544 | { |
5545 | case '\0': | |
5546 | return 0; | |
5547 | case 'S': | |
5548 | { | |
5549 | LONGEST W; | |
5550 | if (!ada_scan_number (name, p + 1, &W, &p)) | |
5551 | return 0; | |
5552 | if (val == W) | |
5553 | return 1; | |
5554 | break; | |
5555 | } | |
5556 | case 'R': | |
5557 | { | |
5558 | LONGEST L, U; | |
5559 | if (!ada_scan_number (name, p + 1, &L, &p) | |
5560 | || name[p] != 'T' || !ada_scan_number (name, p + 1, &U, &p)) | |
5561 | return 0; | |
5562 | if (val >= L && val <= U) | |
5563 | return 1; | |
5564 | break; | |
5565 | } | |
5566 | case 'O': | |
5567 | return 1; | |
5568 | default: | |
5569 | return 0; | |
5570 | } | |
5571 | } | |
5572 | } | |
5573 | ||
5574 | /* FIXME: Lots of redundancy below. Try to consolidate. */ | |
5575 | ||
5576 | /* Given a value ARG1 (offset by OFFSET bytes) of a struct or union type | |
5577 | ARG_TYPE, extract and return the value of one of its (non-static) | |
5578 | fields. FIELDNO says which field. Differs from value_primitive_field | |
5579 | only in that it can handle packed values of arbitrary type. */ | |
14f9c5c9 | 5580 | |
4c4b4cd2 | 5581 | static struct value * |
d2e4a39e | 5582 | ada_value_primitive_field (struct value *arg1, int offset, int fieldno, |
4c4b4cd2 | 5583 | struct type *arg_type) |
14f9c5c9 | 5584 | { |
14f9c5c9 AS |
5585 | struct type *type; |
5586 | ||
61ee279c | 5587 | arg_type = ada_check_typedef (arg_type); |
14f9c5c9 AS |
5588 | type = TYPE_FIELD_TYPE (arg_type, fieldno); |
5589 | ||
4c4b4cd2 | 5590 | /* Handle packed fields. */ |
14f9c5c9 AS |
5591 | |
5592 | if (TYPE_FIELD_BITSIZE (arg_type, fieldno) != 0) | |
5593 | { | |
5594 | int bit_pos = TYPE_FIELD_BITPOS (arg_type, fieldno); | |
5595 | int bit_size = TYPE_FIELD_BITSIZE (arg_type, fieldno); | |
d2e4a39e | 5596 | |
0fd88904 | 5597 | return ada_value_primitive_packed_val (arg1, value_contents (arg1), |
4c4b4cd2 PH |
5598 | offset + bit_pos / 8, |
5599 | bit_pos % 8, bit_size, type); | |
14f9c5c9 AS |
5600 | } |
5601 | else | |
5602 | return value_primitive_field (arg1, offset, fieldno, arg_type); | |
5603 | } | |
5604 | ||
52ce6436 PH |
5605 | /* Find field with name NAME in object of type TYPE. If found, |
5606 | set the following for each argument that is non-null: | |
5607 | - *FIELD_TYPE_P to the field's type; | |
5608 | - *BYTE_OFFSET_P to OFFSET + the byte offset of the field within | |
5609 | an object of that type; | |
5610 | - *BIT_OFFSET_P to the bit offset modulo byte size of the field; | |
5611 | - *BIT_SIZE_P to its size in bits if the field is packed, and | |
5612 | 0 otherwise; | |
5613 | If INDEX_P is non-null, increment *INDEX_P by the number of source-visible | |
5614 | fields up to but not including the desired field, or by the total | |
5615 | number of fields if not found. A NULL value of NAME never | |
5616 | matches; the function just counts visible fields in this case. | |
5617 | ||
5618 | Returns 1 if found, 0 otherwise. */ | |
5619 | ||
4c4b4cd2 | 5620 | static int |
76a01679 JB |
5621 | find_struct_field (char *name, struct type *type, int offset, |
5622 | struct type **field_type_p, | |
52ce6436 PH |
5623 | int *byte_offset_p, int *bit_offset_p, int *bit_size_p, |
5624 | int *index_p) | |
4c4b4cd2 PH |
5625 | { |
5626 | int i; | |
5627 | ||
61ee279c | 5628 | type = ada_check_typedef (type); |
76a01679 | 5629 | |
52ce6436 PH |
5630 | if (field_type_p != NULL) |
5631 | *field_type_p = NULL; | |
5632 | if (byte_offset_p != NULL) | |
d5d6fca5 | 5633 | *byte_offset_p = 0; |
52ce6436 PH |
5634 | if (bit_offset_p != NULL) |
5635 | *bit_offset_p = 0; | |
5636 | if (bit_size_p != NULL) | |
5637 | *bit_size_p = 0; | |
5638 | ||
5639 | for (i = 0; i < TYPE_NFIELDS (type); i += 1) | |
4c4b4cd2 PH |
5640 | { |
5641 | int bit_pos = TYPE_FIELD_BITPOS (type, i); | |
5642 | int fld_offset = offset + bit_pos / 8; | |
5643 | char *t_field_name = TYPE_FIELD_NAME (type, i); | |
76a01679 | 5644 | |
4c4b4cd2 PH |
5645 | if (t_field_name == NULL) |
5646 | continue; | |
5647 | ||
52ce6436 | 5648 | else if (name != NULL && field_name_match (t_field_name, name)) |
76a01679 JB |
5649 | { |
5650 | int bit_size = TYPE_FIELD_BITSIZE (type, i); | |
52ce6436 PH |
5651 | if (field_type_p != NULL) |
5652 | *field_type_p = TYPE_FIELD_TYPE (type, i); | |
5653 | if (byte_offset_p != NULL) | |
5654 | *byte_offset_p = fld_offset; | |
5655 | if (bit_offset_p != NULL) | |
5656 | *bit_offset_p = bit_pos % 8; | |
5657 | if (bit_size_p != NULL) | |
5658 | *bit_size_p = bit_size; | |
76a01679 JB |
5659 | return 1; |
5660 | } | |
4c4b4cd2 PH |
5661 | else if (ada_is_wrapper_field (type, i)) |
5662 | { | |
52ce6436 PH |
5663 | if (find_struct_field (name, TYPE_FIELD_TYPE (type, i), fld_offset, |
5664 | field_type_p, byte_offset_p, bit_offset_p, | |
5665 | bit_size_p, index_p)) | |
76a01679 JB |
5666 | return 1; |
5667 | } | |
4c4b4cd2 PH |
5668 | else if (ada_is_variant_part (type, i)) |
5669 | { | |
52ce6436 PH |
5670 | /* PNH: Wait. Do we ever execute this section, or is ARG always of |
5671 | fixed type?? */ | |
4c4b4cd2 | 5672 | int j; |
52ce6436 PH |
5673 | struct type *field_type |
5674 | = ada_check_typedef (TYPE_FIELD_TYPE (type, i)); | |
4c4b4cd2 | 5675 | |
52ce6436 | 5676 | for (j = 0; j < TYPE_NFIELDS (field_type); j += 1) |
4c4b4cd2 | 5677 | { |
76a01679 JB |
5678 | if (find_struct_field (name, TYPE_FIELD_TYPE (field_type, j), |
5679 | fld_offset | |
5680 | + TYPE_FIELD_BITPOS (field_type, j) / 8, | |
5681 | field_type_p, byte_offset_p, | |
52ce6436 | 5682 | bit_offset_p, bit_size_p, index_p)) |
76a01679 | 5683 | return 1; |
4c4b4cd2 PH |
5684 | } |
5685 | } | |
52ce6436 PH |
5686 | else if (index_p != NULL) |
5687 | *index_p += 1; | |
4c4b4cd2 PH |
5688 | } |
5689 | return 0; | |
5690 | } | |
5691 | ||
52ce6436 | 5692 | /* Number of user-visible fields in record type TYPE. */ |
4c4b4cd2 | 5693 | |
52ce6436 PH |
5694 | static int |
5695 | num_visible_fields (struct type *type) | |
5696 | { | |
5697 | int n; | |
5698 | n = 0; | |
5699 | find_struct_field (NULL, type, 0, NULL, NULL, NULL, NULL, &n); | |
5700 | return n; | |
5701 | } | |
14f9c5c9 | 5702 | |
4c4b4cd2 | 5703 | /* Look for a field NAME in ARG. Adjust the address of ARG by OFFSET bytes, |
14f9c5c9 AS |
5704 | and search in it assuming it has (class) type TYPE. |
5705 | If found, return value, else return NULL. | |
5706 | ||
4c4b4cd2 | 5707 | Searches recursively through wrapper fields (e.g., '_parent'). */ |
14f9c5c9 | 5708 | |
4c4b4cd2 | 5709 | static struct value * |
d2e4a39e | 5710 | ada_search_struct_field (char *name, struct value *arg, int offset, |
4c4b4cd2 | 5711 | struct type *type) |
14f9c5c9 AS |
5712 | { |
5713 | int i; | |
61ee279c | 5714 | type = ada_check_typedef (type); |
14f9c5c9 | 5715 | |
52ce6436 | 5716 | for (i = 0; i < TYPE_NFIELDS (type); i += 1) |
14f9c5c9 AS |
5717 | { |
5718 | char *t_field_name = TYPE_FIELD_NAME (type, i); | |
5719 | ||
5720 | if (t_field_name == NULL) | |
4c4b4cd2 | 5721 | continue; |
14f9c5c9 AS |
5722 | |
5723 | else if (field_name_match (t_field_name, name)) | |
4c4b4cd2 | 5724 | return ada_value_primitive_field (arg, offset, i, type); |
14f9c5c9 AS |
5725 | |
5726 | else if (ada_is_wrapper_field (type, i)) | |
4c4b4cd2 | 5727 | { |
06d5cf63 JB |
5728 | struct value *v = /* Do not let indent join lines here. */ |
5729 | ada_search_struct_field (name, arg, | |
5730 | offset + TYPE_FIELD_BITPOS (type, i) / 8, | |
5731 | TYPE_FIELD_TYPE (type, i)); | |
4c4b4cd2 PH |
5732 | if (v != NULL) |
5733 | return v; | |
5734 | } | |
14f9c5c9 AS |
5735 | |
5736 | else if (ada_is_variant_part (type, i)) | |
4c4b4cd2 | 5737 | { |
52ce6436 | 5738 | /* PNH: Do we ever get here? See find_struct_field. */ |
4c4b4cd2 | 5739 | int j; |
61ee279c | 5740 | struct type *field_type = ada_check_typedef (TYPE_FIELD_TYPE (type, i)); |
4c4b4cd2 PH |
5741 | int var_offset = offset + TYPE_FIELD_BITPOS (type, i) / 8; |
5742 | ||
52ce6436 | 5743 | for (j = 0; j < TYPE_NFIELDS (field_type); j += 1) |
4c4b4cd2 | 5744 | { |
06d5cf63 JB |
5745 | struct value *v = ada_search_struct_field /* Force line break. */ |
5746 | (name, arg, | |
5747 | var_offset + TYPE_FIELD_BITPOS (field_type, j) / 8, | |
5748 | TYPE_FIELD_TYPE (field_type, j)); | |
4c4b4cd2 PH |
5749 | if (v != NULL) |
5750 | return v; | |
5751 | } | |
5752 | } | |
14f9c5c9 AS |
5753 | } |
5754 | return NULL; | |
5755 | } | |
d2e4a39e | 5756 | |
52ce6436 PH |
5757 | static struct value *ada_index_struct_field_1 (int *, struct value *, |
5758 | int, struct type *); | |
5759 | ||
5760 | ||
5761 | /* Return field #INDEX in ARG, where the index is that returned by | |
5762 | * find_struct_field through its INDEX_P argument. Adjust the address | |
5763 | * of ARG by OFFSET bytes, and search in it assuming it has (class) type TYPE. | |
5764 | * If found, return value, else return NULL. */ | |
5765 | ||
5766 | static struct value * | |
5767 | ada_index_struct_field (int index, struct value *arg, int offset, | |
5768 | struct type *type) | |
5769 | { | |
5770 | return ada_index_struct_field_1 (&index, arg, offset, type); | |
5771 | } | |
5772 | ||
5773 | ||
5774 | /* Auxiliary function for ada_index_struct_field. Like | |
5775 | * ada_index_struct_field, but takes index from *INDEX_P and modifies | |
5776 | * *INDEX_P. */ | |
5777 | ||
5778 | static struct value * | |
5779 | ada_index_struct_field_1 (int *index_p, struct value *arg, int offset, | |
5780 | struct type *type) | |
5781 | { | |
5782 | int i; | |
5783 | type = ada_check_typedef (type); | |
5784 | ||
5785 | for (i = 0; i < TYPE_NFIELDS (type); i += 1) | |
5786 | { | |
5787 | if (TYPE_FIELD_NAME (type, i) == NULL) | |
5788 | continue; | |
5789 | else if (ada_is_wrapper_field (type, i)) | |
5790 | { | |
5791 | struct value *v = /* Do not let indent join lines here. */ | |
5792 | ada_index_struct_field_1 (index_p, arg, | |
5793 | offset + TYPE_FIELD_BITPOS (type, i) / 8, | |
5794 | TYPE_FIELD_TYPE (type, i)); | |
5795 | if (v != NULL) | |
5796 | return v; | |
5797 | } | |
5798 | ||
5799 | else if (ada_is_variant_part (type, i)) | |
5800 | { | |
5801 | /* PNH: Do we ever get here? See ada_search_struct_field, | |
5802 | find_struct_field. */ | |
5803 | error (_("Cannot assign this kind of variant record")); | |
5804 | } | |
5805 | else if (*index_p == 0) | |
5806 | return ada_value_primitive_field (arg, offset, i, type); | |
5807 | else | |
5808 | *index_p -= 1; | |
5809 | } | |
5810 | return NULL; | |
5811 | } | |
5812 | ||
4c4b4cd2 PH |
5813 | /* Given ARG, a value of type (pointer or reference to a)* |
5814 | structure/union, extract the component named NAME from the ultimate | |
5815 | target structure/union and return it as a value with its | |
5816 | appropriate type. If ARG is a pointer or reference and the field | |
5817 | is not packed, returns a reference to the field, otherwise the | |
5818 | value of the field (an lvalue if ARG is an lvalue). | |
14f9c5c9 | 5819 | |
4c4b4cd2 PH |
5820 | The routine searches for NAME among all members of the structure itself |
5821 | and (recursively) among all members of any wrapper members | |
14f9c5c9 AS |
5822 | (e.g., '_parent'). |
5823 | ||
03ee6b2e PH |
5824 | If NO_ERR, then simply return NULL in case of error, rather than |
5825 | calling error. */ | |
14f9c5c9 | 5826 | |
d2e4a39e | 5827 | struct value * |
03ee6b2e | 5828 | ada_value_struct_elt (struct value *arg, char *name, int no_err) |
14f9c5c9 | 5829 | { |
4c4b4cd2 | 5830 | struct type *t, *t1; |
d2e4a39e | 5831 | struct value *v; |
14f9c5c9 | 5832 | |
4c4b4cd2 | 5833 | v = NULL; |
df407dfe | 5834 | t1 = t = ada_check_typedef (value_type (arg)); |
4c4b4cd2 PH |
5835 | if (TYPE_CODE (t) == TYPE_CODE_REF) |
5836 | { | |
5837 | t1 = TYPE_TARGET_TYPE (t); | |
5838 | if (t1 == NULL) | |
03ee6b2e | 5839 | goto BadValue; |
61ee279c | 5840 | t1 = ada_check_typedef (t1); |
4c4b4cd2 | 5841 | if (TYPE_CODE (t1) == TYPE_CODE_PTR) |
76a01679 | 5842 | { |
994b9211 | 5843 | arg = coerce_ref (arg); |
76a01679 JB |
5844 | t = t1; |
5845 | } | |
4c4b4cd2 | 5846 | } |
14f9c5c9 | 5847 | |
4c4b4cd2 PH |
5848 | while (TYPE_CODE (t) == TYPE_CODE_PTR) |
5849 | { | |
5850 | t1 = TYPE_TARGET_TYPE (t); | |
5851 | if (t1 == NULL) | |
03ee6b2e | 5852 | goto BadValue; |
61ee279c | 5853 | t1 = ada_check_typedef (t1); |
4c4b4cd2 | 5854 | if (TYPE_CODE (t1) == TYPE_CODE_PTR) |
76a01679 JB |
5855 | { |
5856 | arg = value_ind (arg); | |
5857 | t = t1; | |
5858 | } | |
4c4b4cd2 | 5859 | else |
76a01679 | 5860 | break; |
4c4b4cd2 | 5861 | } |
14f9c5c9 | 5862 | |
4c4b4cd2 | 5863 | if (TYPE_CODE (t1) != TYPE_CODE_STRUCT && TYPE_CODE (t1) != TYPE_CODE_UNION) |
03ee6b2e | 5864 | goto BadValue; |
14f9c5c9 | 5865 | |
4c4b4cd2 PH |
5866 | if (t1 == t) |
5867 | v = ada_search_struct_field (name, arg, 0, t); | |
5868 | else | |
5869 | { | |
5870 | int bit_offset, bit_size, byte_offset; | |
5871 | struct type *field_type; | |
5872 | CORE_ADDR address; | |
5873 | ||
76a01679 JB |
5874 | if (TYPE_CODE (t) == TYPE_CODE_PTR) |
5875 | address = value_as_address (arg); | |
4c4b4cd2 | 5876 | else |
0fd88904 | 5877 | address = unpack_pointer (t, value_contents (arg)); |
14f9c5c9 | 5878 | |
4c4b4cd2 | 5879 | t1 = ada_to_fixed_type (ada_get_base_type (t1), NULL, address, NULL); |
76a01679 JB |
5880 | if (find_struct_field (name, t1, 0, |
5881 | &field_type, &byte_offset, &bit_offset, | |
52ce6436 | 5882 | &bit_size, NULL)) |
76a01679 JB |
5883 | { |
5884 | if (bit_size != 0) | |
5885 | { | |
714e53ab PH |
5886 | if (TYPE_CODE (t) == TYPE_CODE_REF) |
5887 | arg = ada_coerce_ref (arg); | |
5888 | else | |
5889 | arg = ada_value_ind (arg); | |
76a01679 JB |
5890 | v = ada_value_primitive_packed_val (arg, NULL, byte_offset, |
5891 | bit_offset, bit_size, | |
5892 | field_type); | |
5893 | } | |
5894 | else | |
5895 | v = value_from_pointer (lookup_reference_type (field_type), | |
5896 | address + byte_offset); | |
5897 | } | |
5898 | } | |
5899 | ||
03ee6b2e PH |
5900 | if (v != NULL || no_err) |
5901 | return v; | |
5902 | else | |
323e0a4a | 5903 | error (_("There is no member named %s."), name); |
14f9c5c9 | 5904 | |
03ee6b2e PH |
5905 | BadValue: |
5906 | if (no_err) | |
5907 | return NULL; | |
5908 | else | |
5909 | error (_("Attempt to extract a component of a value that is not a record.")); | |
14f9c5c9 AS |
5910 | } |
5911 | ||
5912 | /* Given a type TYPE, look up the type of the component of type named NAME. | |
4c4b4cd2 PH |
5913 | If DISPP is non-null, add its byte displacement from the beginning of a |
5914 | structure (pointed to by a value) of type TYPE to *DISPP (does not | |
14f9c5c9 AS |
5915 | work for packed fields). |
5916 | ||
5917 | Matches any field whose name has NAME as a prefix, possibly | |
4c4b4cd2 | 5918 | followed by "___". |
14f9c5c9 | 5919 | |
4c4b4cd2 PH |
5920 | TYPE can be either a struct or union. If REFOK, TYPE may also |
5921 | be a (pointer or reference)+ to a struct or union, and the | |
5922 | ultimate target type will be searched. | |
14f9c5c9 AS |
5923 | |
5924 | Looks recursively into variant clauses and parent types. | |
5925 | ||
4c4b4cd2 PH |
5926 | If NOERR is nonzero, return NULL if NAME is not suitably defined or |
5927 | TYPE is not a type of the right kind. */ | |
14f9c5c9 | 5928 | |
4c4b4cd2 | 5929 | static struct type * |
76a01679 JB |
5930 | ada_lookup_struct_elt_type (struct type *type, char *name, int refok, |
5931 | int noerr, int *dispp) | |
14f9c5c9 AS |
5932 | { |
5933 | int i; | |
5934 | ||
5935 | if (name == NULL) | |
5936 | goto BadName; | |
5937 | ||
76a01679 | 5938 | if (refok && type != NULL) |
4c4b4cd2 PH |
5939 | while (1) |
5940 | { | |
61ee279c | 5941 | type = ada_check_typedef (type); |
76a01679 JB |
5942 | if (TYPE_CODE (type) != TYPE_CODE_PTR |
5943 | && TYPE_CODE (type) != TYPE_CODE_REF) | |
5944 | break; | |
5945 | type = TYPE_TARGET_TYPE (type); | |
4c4b4cd2 | 5946 | } |
14f9c5c9 | 5947 | |
76a01679 | 5948 | if (type == NULL |
1265e4aa JB |
5949 | || (TYPE_CODE (type) != TYPE_CODE_STRUCT |
5950 | && TYPE_CODE (type) != TYPE_CODE_UNION)) | |
14f9c5c9 | 5951 | { |
4c4b4cd2 | 5952 | if (noerr) |
76a01679 | 5953 | return NULL; |
4c4b4cd2 | 5954 | else |
76a01679 JB |
5955 | { |
5956 | target_terminal_ours (); | |
5957 | gdb_flush (gdb_stdout); | |
323e0a4a AC |
5958 | if (type == NULL) |
5959 | error (_("Type (null) is not a structure or union type")); | |
5960 | else | |
5961 | { | |
5962 | /* XXX: type_sprint */ | |
5963 | fprintf_unfiltered (gdb_stderr, _("Type ")); | |
5964 | type_print (type, "", gdb_stderr, -1); | |
5965 | error (_(" is not a structure or union type")); | |
5966 | } | |
76a01679 | 5967 | } |
14f9c5c9 AS |
5968 | } |
5969 | ||
5970 | type = to_static_fixed_type (type); | |
5971 | ||
5972 | for (i = 0; i < TYPE_NFIELDS (type); i += 1) | |
5973 | { | |
5974 | char *t_field_name = TYPE_FIELD_NAME (type, i); | |
5975 | struct type *t; | |
5976 | int disp; | |
d2e4a39e | 5977 | |
14f9c5c9 | 5978 | if (t_field_name == NULL) |
4c4b4cd2 | 5979 | continue; |
14f9c5c9 AS |
5980 | |
5981 | else if (field_name_match (t_field_name, name)) | |
4c4b4cd2 PH |
5982 | { |
5983 | if (dispp != NULL) | |
5984 | *dispp += TYPE_FIELD_BITPOS (type, i) / 8; | |
61ee279c | 5985 | return ada_check_typedef (TYPE_FIELD_TYPE (type, i)); |
4c4b4cd2 | 5986 | } |
14f9c5c9 AS |
5987 | |
5988 | else if (ada_is_wrapper_field (type, i)) | |
4c4b4cd2 PH |
5989 | { |
5990 | disp = 0; | |
5991 | t = ada_lookup_struct_elt_type (TYPE_FIELD_TYPE (type, i), name, | |
5992 | 0, 1, &disp); | |
5993 | if (t != NULL) | |
5994 | { | |
5995 | if (dispp != NULL) | |
5996 | *dispp += disp + TYPE_FIELD_BITPOS (type, i) / 8; | |
5997 | return t; | |
5998 | } | |
5999 | } | |
14f9c5c9 AS |
6000 | |
6001 | else if (ada_is_variant_part (type, i)) | |
4c4b4cd2 PH |
6002 | { |
6003 | int j; | |
61ee279c | 6004 | struct type *field_type = ada_check_typedef (TYPE_FIELD_TYPE (type, i)); |
4c4b4cd2 PH |
6005 | |
6006 | for (j = TYPE_NFIELDS (field_type) - 1; j >= 0; j -= 1) | |
6007 | { | |
6008 | disp = 0; | |
6009 | t = ada_lookup_struct_elt_type (TYPE_FIELD_TYPE (field_type, j), | |
6010 | name, 0, 1, &disp); | |
6011 | if (t != NULL) | |
6012 | { | |
6013 | if (dispp != NULL) | |
6014 | *dispp += disp + TYPE_FIELD_BITPOS (type, i) / 8; | |
6015 | return t; | |
6016 | } | |
6017 | } | |
6018 | } | |
14f9c5c9 AS |
6019 | |
6020 | } | |
6021 | ||
6022 | BadName: | |
d2e4a39e | 6023 | if (!noerr) |
14f9c5c9 AS |
6024 | { |
6025 | target_terminal_ours (); | |
6026 | gdb_flush (gdb_stdout); | |
323e0a4a AC |
6027 | if (name == NULL) |
6028 | { | |
6029 | /* XXX: type_sprint */ | |
6030 | fprintf_unfiltered (gdb_stderr, _("Type ")); | |
6031 | type_print (type, "", gdb_stderr, -1); | |
6032 | error (_(" has no component named <null>")); | |
6033 | } | |
6034 | else | |
6035 | { | |
6036 | /* XXX: type_sprint */ | |
6037 | fprintf_unfiltered (gdb_stderr, _("Type ")); | |
6038 | type_print (type, "", gdb_stderr, -1); | |
6039 | error (_(" has no component named %s"), name); | |
6040 | } | |
14f9c5c9 AS |
6041 | } |
6042 | ||
6043 | return NULL; | |
6044 | } | |
6045 | ||
6046 | /* Assuming that VAR_TYPE is the type of a variant part of a record (a union), | |
6047 | within a value of type OUTER_TYPE that is stored in GDB at | |
4c4b4cd2 PH |
6048 | OUTER_VALADDR, determine which variant clause (field number in VAR_TYPE, |
6049 | numbering from 0) is applicable. Returns -1 if none are. */ | |
14f9c5c9 | 6050 | |
d2e4a39e | 6051 | int |
ebf56fd3 | 6052 | ada_which_variant_applies (struct type *var_type, struct type *outer_type, |
fc1a4b47 | 6053 | const gdb_byte *outer_valaddr) |
14f9c5c9 AS |
6054 | { |
6055 | int others_clause; | |
6056 | int i; | |
6057 | int disp; | |
d2e4a39e AS |
6058 | struct type *discrim_type; |
6059 | char *discrim_name = ada_variant_discrim_name (var_type); | |
14f9c5c9 AS |
6060 | LONGEST discrim_val; |
6061 | ||
6062 | disp = 0; | |
d2e4a39e | 6063 | discrim_type = |
4c4b4cd2 | 6064 | ada_lookup_struct_elt_type (outer_type, discrim_name, 1, 1, &disp); |
14f9c5c9 AS |
6065 | if (discrim_type == NULL) |
6066 | return -1; | |
6067 | discrim_val = unpack_long (discrim_type, outer_valaddr + disp); | |
6068 | ||
6069 | others_clause = -1; | |
6070 | for (i = 0; i < TYPE_NFIELDS (var_type); i += 1) | |
6071 | { | |
6072 | if (ada_is_others_clause (var_type, i)) | |
4c4b4cd2 | 6073 | others_clause = i; |
14f9c5c9 | 6074 | else if (ada_in_variant (discrim_val, var_type, i)) |
4c4b4cd2 | 6075 | return i; |
14f9c5c9 AS |
6076 | } |
6077 | ||
6078 | return others_clause; | |
6079 | } | |
d2e4a39e | 6080 | \f |
14f9c5c9 AS |
6081 | |
6082 | ||
4c4b4cd2 | 6083 | /* Dynamic-Sized Records */ |
14f9c5c9 AS |
6084 | |
6085 | /* Strategy: The type ostensibly attached to a value with dynamic size | |
6086 | (i.e., a size that is not statically recorded in the debugging | |
6087 | data) does not accurately reflect the size or layout of the value. | |
6088 | Our strategy is to convert these values to values with accurate, | |
4c4b4cd2 | 6089 | conventional types that are constructed on the fly. */ |
14f9c5c9 AS |
6090 | |
6091 | /* There is a subtle and tricky problem here. In general, we cannot | |
6092 | determine the size of dynamic records without its data. However, | |
6093 | the 'struct value' data structure, which GDB uses to represent | |
6094 | quantities in the inferior process (the target), requires the size | |
6095 | of the type at the time of its allocation in order to reserve space | |
6096 | for GDB's internal copy of the data. That's why the | |
6097 | 'to_fixed_xxx_type' routines take (target) addresses as parameters, | |
4c4b4cd2 | 6098 | rather than struct value*s. |
14f9c5c9 AS |
6099 | |
6100 | However, GDB's internal history variables ($1, $2, etc.) are | |
6101 | struct value*s containing internal copies of the data that are not, in | |
6102 | general, the same as the data at their corresponding addresses in | |
6103 | the target. Fortunately, the types we give to these values are all | |
6104 | conventional, fixed-size types (as per the strategy described | |
6105 | above), so that we don't usually have to perform the | |
6106 | 'to_fixed_xxx_type' conversions to look at their values. | |
6107 | Unfortunately, there is one exception: if one of the internal | |
6108 | history variables is an array whose elements are unconstrained | |
6109 | records, then we will need to create distinct fixed types for each | |
6110 | element selected. */ | |
6111 | ||
6112 | /* The upshot of all of this is that many routines take a (type, host | |
6113 | address, target address) triple as arguments to represent a value. | |
6114 | The host address, if non-null, is supposed to contain an internal | |
6115 | copy of the relevant data; otherwise, the program is to consult the | |
4c4b4cd2 | 6116 | target at the target address. */ |
14f9c5c9 AS |
6117 | |
6118 | /* Assuming that VAL0 represents a pointer value, the result of | |
6119 | dereferencing it. Differs from value_ind in its treatment of | |
4c4b4cd2 | 6120 | dynamic-sized types. */ |
14f9c5c9 | 6121 | |
d2e4a39e AS |
6122 | struct value * |
6123 | ada_value_ind (struct value *val0) | |
14f9c5c9 | 6124 | { |
d2e4a39e | 6125 | struct value *val = unwrap_value (value_ind (val0)); |
4c4b4cd2 | 6126 | return ada_to_fixed_value (val); |
14f9c5c9 AS |
6127 | } |
6128 | ||
6129 | /* The value resulting from dereferencing any "reference to" | |
4c4b4cd2 PH |
6130 | qualifiers on VAL0. */ |
6131 | ||
d2e4a39e AS |
6132 | static struct value * |
6133 | ada_coerce_ref (struct value *val0) | |
6134 | { | |
df407dfe | 6135 | if (TYPE_CODE (value_type (val0)) == TYPE_CODE_REF) |
d2e4a39e AS |
6136 | { |
6137 | struct value *val = val0; | |
994b9211 | 6138 | val = coerce_ref (val); |
d2e4a39e | 6139 | val = unwrap_value (val); |
4c4b4cd2 | 6140 | return ada_to_fixed_value (val); |
d2e4a39e AS |
6141 | } |
6142 | else | |
14f9c5c9 AS |
6143 | return val0; |
6144 | } | |
6145 | ||
6146 | /* Return OFF rounded upward if necessary to a multiple of | |
4c4b4cd2 | 6147 | ALIGNMENT (a power of 2). */ |
14f9c5c9 AS |
6148 | |
6149 | static unsigned int | |
ebf56fd3 | 6150 | align_value (unsigned int off, unsigned int alignment) |
14f9c5c9 AS |
6151 | { |
6152 | return (off + alignment - 1) & ~(alignment - 1); | |
6153 | } | |
6154 | ||
4c4b4cd2 | 6155 | /* Return the bit alignment required for field #F of template type TYPE. */ |
14f9c5c9 AS |
6156 | |
6157 | static unsigned int | |
ebf56fd3 | 6158 | field_alignment (struct type *type, int f) |
14f9c5c9 | 6159 | { |
d2e4a39e | 6160 | const char *name = TYPE_FIELD_NAME (type, f); |
14f9c5c9 AS |
6161 | int len = (name == NULL) ? 0 : strlen (name); |
6162 | int align_offset; | |
6163 | ||
4c4b4cd2 PH |
6164 | if (!isdigit (name[len - 1])) |
6165 | return 1; | |
14f9c5c9 | 6166 | |
d2e4a39e | 6167 | if (isdigit (name[len - 2])) |
14f9c5c9 AS |
6168 | align_offset = len - 2; |
6169 | else | |
6170 | align_offset = len - 1; | |
6171 | ||
4c4b4cd2 | 6172 | if (align_offset < 7 || strncmp ("___XV", name + align_offset - 6, 5) != 0) |
14f9c5c9 AS |
6173 | return TARGET_CHAR_BIT; |
6174 | ||
4c4b4cd2 PH |
6175 | return atoi (name + align_offset) * TARGET_CHAR_BIT; |
6176 | } | |
6177 | ||
6178 | /* Find a symbol named NAME. Ignores ambiguity. */ | |
6179 | ||
6180 | struct symbol * | |
6181 | ada_find_any_symbol (const char *name) | |
6182 | { | |
6183 | struct symbol *sym; | |
6184 | ||
6185 | sym = standard_lookup (name, get_selected_block (NULL), VAR_DOMAIN); | |
6186 | if (sym != NULL && SYMBOL_CLASS (sym) == LOC_TYPEDEF) | |
6187 | return sym; | |
6188 | ||
6189 | sym = standard_lookup (name, NULL, STRUCT_DOMAIN); | |
6190 | return sym; | |
14f9c5c9 AS |
6191 | } |
6192 | ||
6193 | /* Find a type named NAME. Ignores ambiguity. */ | |
4c4b4cd2 | 6194 | |
d2e4a39e | 6195 | struct type * |
ebf56fd3 | 6196 | ada_find_any_type (const char *name) |
14f9c5c9 | 6197 | { |
4c4b4cd2 | 6198 | struct symbol *sym = ada_find_any_symbol (name); |
14f9c5c9 | 6199 | |
14f9c5c9 AS |
6200 | if (sym != NULL) |
6201 | return SYMBOL_TYPE (sym); | |
6202 | ||
6203 | return NULL; | |
6204 | } | |
6205 | ||
4c4b4cd2 PH |
6206 | /* Given a symbol NAME and its associated BLOCK, search all symbols |
6207 | for its ___XR counterpart, which is the ``renaming'' symbol | |
6208 | associated to NAME. Return this symbol if found, return | |
6209 | NULL otherwise. */ | |
6210 | ||
6211 | struct symbol * | |
6212 | ada_find_renaming_symbol (const char *name, struct block *block) | |
6213 | { | |
6214 | const struct symbol *function_sym = block_function (block); | |
6215 | char *rename; | |
6216 | ||
6217 | if (function_sym != NULL) | |
6218 | { | |
6219 | /* If the symbol is defined inside a function, NAME is not fully | |
6220 | qualified. This means we need to prepend the function name | |
6221 | as well as adding the ``___XR'' suffix to build the name of | |
6222 | the associated renaming symbol. */ | |
6223 | char *function_name = SYMBOL_LINKAGE_NAME (function_sym); | |
529cad9c PH |
6224 | /* Function names sometimes contain suffixes used |
6225 | for instance to qualify nested subprograms. When building | |
6226 | the XR type name, we need to make sure that this suffix is | |
6227 | not included. So do not include any suffix in the function | |
6228 | name length below. */ | |
6229 | const int function_name_len = ada_name_prefix_len (function_name); | |
76a01679 JB |
6230 | const int rename_len = function_name_len + 2 /* "__" */ |
6231 | + strlen (name) + 6 /* "___XR\0" */ ; | |
4c4b4cd2 | 6232 | |
529cad9c PH |
6233 | /* Strip the suffix if necessary. */ |
6234 | function_name[function_name_len] = '\0'; | |
6235 | ||
4c4b4cd2 PH |
6236 | /* Library-level functions are a special case, as GNAT adds |
6237 | a ``_ada_'' prefix to the function name to avoid namespace | |
6238 | pollution. However, the renaming symbol themselves do not | |
6239 | have this prefix, so we need to skip this prefix if present. */ | |
6240 | if (function_name_len > 5 /* "_ada_" */ | |
6241 | && strstr (function_name, "_ada_") == function_name) | |
6242 | function_name = function_name + 5; | |
6243 | ||
6244 | rename = (char *) alloca (rename_len * sizeof (char)); | |
6245 | sprintf (rename, "%s__%s___XR", function_name, name); | |
6246 | } | |
6247 | else | |
6248 | { | |
6249 | const int rename_len = strlen (name) + 6; | |
6250 | rename = (char *) alloca (rename_len * sizeof (char)); | |
6251 | sprintf (rename, "%s___XR", name); | |
6252 | } | |
6253 | ||
6254 | return ada_find_any_symbol (rename); | |
6255 | } | |
6256 | ||
14f9c5c9 | 6257 | /* Because of GNAT encoding conventions, several GDB symbols may match a |
4c4b4cd2 | 6258 | given type name. If the type denoted by TYPE0 is to be preferred to |
14f9c5c9 | 6259 | that of TYPE1 for purposes of type printing, return non-zero; |
4c4b4cd2 PH |
6260 | otherwise return 0. */ |
6261 | ||
14f9c5c9 | 6262 | int |
d2e4a39e | 6263 | ada_prefer_type (struct type *type0, struct type *type1) |
14f9c5c9 AS |
6264 | { |
6265 | if (type1 == NULL) | |
6266 | return 1; | |
6267 | else if (type0 == NULL) | |
6268 | return 0; | |
6269 | else if (TYPE_CODE (type1) == TYPE_CODE_VOID) | |
6270 | return 1; | |
6271 | else if (TYPE_CODE (type0) == TYPE_CODE_VOID) | |
6272 | return 0; | |
4c4b4cd2 PH |
6273 | else if (TYPE_NAME (type1) == NULL && TYPE_NAME (type0) != NULL) |
6274 | return 1; | |
14f9c5c9 AS |
6275 | else if (ada_is_packed_array_type (type0)) |
6276 | return 1; | |
4c4b4cd2 PH |
6277 | else if (ada_is_array_descriptor_type (type0) |
6278 | && !ada_is_array_descriptor_type (type1)) | |
14f9c5c9 | 6279 | return 1; |
d2e4a39e | 6280 | else if (ada_renaming_type (type0) != NULL |
4c4b4cd2 | 6281 | && ada_renaming_type (type1) == NULL) |
14f9c5c9 AS |
6282 | return 1; |
6283 | return 0; | |
6284 | } | |
6285 | ||
6286 | /* The name of TYPE, which is either its TYPE_NAME, or, if that is | |
4c4b4cd2 PH |
6287 | null, its TYPE_TAG_NAME. Null if TYPE is null. */ |
6288 | ||
d2e4a39e AS |
6289 | char * |
6290 | ada_type_name (struct type *type) | |
14f9c5c9 | 6291 | { |
d2e4a39e | 6292 | if (type == NULL) |
14f9c5c9 AS |
6293 | return NULL; |
6294 | else if (TYPE_NAME (type) != NULL) | |
6295 | return TYPE_NAME (type); | |
6296 | else | |
6297 | return TYPE_TAG_NAME (type); | |
6298 | } | |
6299 | ||
6300 | /* Find a parallel type to TYPE whose name is formed by appending | |
4c4b4cd2 | 6301 | SUFFIX to the name of TYPE. */ |
14f9c5c9 | 6302 | |
d2e4a39e | 6303 | struct type * |
ebf56fd3 | 6304 | ada_find_parallel_type (struct type *type, const char *suffix) |
14f9c5c9 | 6305 | { |
d2e4a39e | 6306 | static char *name; |
14f9c5c9 | 6307 | static size_t name_len = 0; |
14f9c5c9 | 6308 | int len; |
d2e4a39e AS |
6309 | char *typename = ada_type_name (type); |
6310 | ||
14f9c5c9 AS |
6311 | if (typename == NULL) |
6312 | return NULL; | |
6313 | ||
6314 | len = strlen (typename); | |
6315 | ||
d2e4a39e | 6316 | GROW_VECT (name, name_len, len + strlen (suffix) + 1); |
14f9c5c9 AS |
6317 | |
6318 | strcpy (name, typename); | |
6319 | strcpy (name + len, suffix); | |
6320 | ||
6321 | return ada_find_any_type (name); | |
6322 | } | |
6323 | ||
6324 | ||
6325 | /* If TYPE is a variable-size record type, return the corresponding template | |
4c4b4cd2 | 6326 | type describing its fields. Otherwise, return NULL. */ |
14f9c5c9 | 6327 | |
d2e4a39e AS |
6328 | static struct type * |
6329 | dynamic_template_type (struct type *type) | |
14f9c5c9 | 6330 | { |
61ee279c | 6331 | type = ada_check_typedef (type); |
14f9c5c9 AS |
6332 | |
6333 | if (type == NULL || TYPE_CODE (type) != TYPE_CODE_STRUCT | |
d2e4a39e | 6334 | || ada_type_name (type) == NULL) |
14f9c5c9 | 6335 | return NULL; |
d2e4a39e | 6336 | else |
14f9c5c9 AS |
6337 | { |
6338 | int len = strlen (ada_type_name (type)); | |
4c4b4cd2 PH |
6339 | if (len > 6 && strcmp (ada_type_name (type) + len - 6, "___XVE") == 0) |
6340 | return type; | |
14f9c5c9 | 6341 | else |
4c4b4cd2 | 6342 | return ada_find_parallel_type (type, "___XVE"); |
14f9c5c9 AS |
6343 | } |
6344 | } | |
6345 | ||
6346 | /* Assuming that TEMPL_TYPE is a union or struct type, returns | |
4c4b4cd2 | 6347 | non-zero iff field FIELD_NUM of TEMPL_TYPE has dynamic size. */ |
14f9c5c9 | 6348 | |
d2e4a39e AS |
6349 | static int |
6350 | is_dynamic_field (struct type *templ_type, int field_num) | |
14f9c5c9 AS |
6351 | { |
6352 | const char *name = TYPE_FIELD_NAME (templ_type, field_num); | |
d2e4a39e | 6353 | return name != NULL |
14f9c5c9 AS |
6354 | && TYPE_CODE (TYPE_FIELD_TYPE (templ_type, field_num)) == TYPE_CODE_PTR |
6355 | && strstr (name, "___XVL") != NULL; | |
6356 | } | |
6357 | ||
4c4b4cd2 PH |
6358 | /* The index of the variant field of TYPE, or -1 if TYPE does not |
6359 | represent a variant record type. */ | |
14f9c5c9 | 6360 | |
d2e4a39e | 6361 | static int |
4c4b4cd2 | 6362 | variant_field_index (struct type *type) |
14f9c5c9 AS |
6363 | { |
6364 | int f; | |
6365 | ||
4c4b4cd2 PH |
6366 | if (type == NULL || TYPE_CODE (type) != TYPE_CODE_STRUCT) |
6367 | return -1; | |
6368 | ||
6369 | for (f = 0; f < TYPE_NFIELDS (type); f += 1) | |
6370 | { | |
6371 | if (ada_is_variant_part (type, f)) | |
6372 | return f; | |
6373 | } | |
6374 | return -1; | |
14f9c5c9 AS |
6375 | } |
6376 | ||
4c4b4cd2 PH |
6377 | /* A record type with no fields. */ |
6378 | ||
d2e4a39e AS |
6379 | static struct type * |
6380 | empty_record (struct objfile *objfile) | |
14f9c5c9 | 6381 | { |
d2e4a39e | 6382 | struct type *type = alloc_type (objfile); |
14f9c5c9 AS |
6383 | TYPE_CODE (type) = TYPE_CODE_STRUCT; |
6384 | TYPE_NFIELDS (type) = 0; | |
6385 | TYPE_FIELDS (type) = NULL; | |
6386 | TYPE_NAME (type) = "<empty>"; | |
6387 | TYPE_TAG_NAME (type) = NULL; | |
6388 | TYPE_FLAGS (type) = 0; | |
6389 | TYPE_LENGTH (type) = 0; | |
6390 | return type; | |
6391 | } | |
6392 | ||
6393 | /* An ordinary record type (with fixed-length fields) that describes | |
4c4b4cd2 PH |
6394 | the value of type TYPE at VALADDR or ADDRESS (see comments at |
6395 | the beginning of this section) VAL according to GNAT conventions. | |
6396 | DVAL0 should describe the (portion of a) record that contains any | |
df407dfe | 6397 | necessary discriminants. It should be NULL if value_type (VAL) is |
14f9c5c9 AS |
6398 | an outer-level type (i.e., as opposed to a branch of a variant.) A |
6399 | variant field (unless unchecked) is replaced by a particular branch | |
4c4b4cd2 | 6400 | of the variant. |
14f9c5c9 | 6401 | |
4c4b4cd2 PH |
6402 | If not KEEP_DYNAMIC_FIELDS, then all fields whose position or |
6403 | length are not statically known are discarded. As a consequence, | |
6404 | VALADDR, ADDRESS and DVAL0 are ignored. | |
6405 | ||
6406 | NOTE: Limitations: For now, we assume that dynamic fields and | |
6407 | variants occupy whole numbers of bytes. However, they need not be | |
6408 | byte-aligned. */ | |
6409 | ||
6410 | struct type * | |
10a2c479 | 6411 | ada_template_to_fixed_record_type_1 (struct type *type, |
fc1a4b47 | 6412 | const gdb_byte *valaddr, |
4c4b4cd2 PH |
6413 | CORE_ADDR address, struct value *dval0, |
6414 | int keep_dynamic_fields) | |
14f9c5c9 | 6415 | { |
d2e4a39e AS |
6416 | struct value *mark = value_mark (); |
6417 | struct value *dval; | |
6418 | struct type *rtype; | |
14f9c5c9 | 6419 | int nfields, bit_len; |
4c4b4cd2 | 6420 | int variant_field; |
14f9c5c9 | 6421 | long off; |
4c4b4cd2 | 6422 | int fld_bit_len, bit_incr; |
14f9c5c9 AS |
6423 | int f; |
6424 | ||
4c4b4cd2 PH |
6425 | /* Compute the number of fields in this record type that are going |
6426 | to be processed: unless keep_dynamic_fields, this includes only | |
6427 | fields whose position and length are static will be processed. */ | |
6428 | if (keep_dynamic_fields) | |
6429 | nfields = TYPE_NFIELDS (type); | |
6430 | else | |
6431 | { | |
6432 | nfields = 0; | |
76a01679 | 6433 | while (nfields < TYPE_NFIELDS (type) |
4c4b4cd2 PH |
6434 | && !ada_is_variant_part (type, nfields) |
6435 | && !is_dynamic_field (type, nfields)) | |
6436 | nfields++; | |
6437 | } | |
6438 | ||
14f9c5c9 AS |
6439 | rtype = alloc_type (TYPE_OBJFILE (type)); |
6440 | TYPE_CODE (rtype) = TYPE_CODE_STRUCT; | |
6441 | INIT_CPLUS_SPECIFIC (rtype); | |
6442 | TYPE_NFIELDS (rtype) = nfields; | |
d2e4a39e | 6443 | TYPE_FIELDS (rtype) = (struct field *) |
14f9c5c9 AS |
6444 | TYPE_ALLOC (rtype, nfields * sizeof (struct field)); |
6445 | memset (TYPE_FIELDS (rtype), 0, sizeof (struct field) * nfields); | |
6446 | TYPE_NAME (rtype) = ada_type_name (type); | |
6447 | TYPE_TAG_NAME (rtype) = NULL; | |
4c4b4cd2 | 6448 | TYPE_FLAGS (rtype) |= TYPE_FLAG_FIXED_INSTANCE; |
14f9c5c9 | 6449 | |
d2e4a39e AS |
6450 | off = 0; |
6451 | bit_len = 0; | |
4c4b4cd2 PH |
6452 | variant_field = -1; |
6453 | ||
14f9c5c9 AS |
6454 | for (f = 0; f < nfields; f += 1) |
6455 | { | |
6c038f32 PH |
6456 | off = align_value (off, field_alignment (type, f)) |
6457 | + TYPE_FIELD_BITPOS (type, f); | |
14f9c5c9 | 6458 | TYPE_FIELD_BITPOS (rtype, f) = off; |
d2e4a39e | 6459 | TYPE_FIELD_BITSIZE (rtype, f) = 0; |
14f9c5c9 | 6460 | |
d2e4a39e | 6461 | if (ada_is_variant_part (type, f)) |
4c4b4cd2 PH |
6462 | { |
6463 | variant_field = f; | |
6464 | fld_bit_len = bit_incr = 0; | |
6465 | } | |
14f9c5c9 | 6466 | else if (is_dynamic_field (type, f)) |
4c4b4cd2 PH |
6467 | { |
6468 | if (dval0 == NULL) | |
6469 | dval = value_from_contents_and_address (rtype, valaddr, address); | |
6470 | else | |
6471 | dval = dval0; | |
6472 | ||
6473 | TYPE_FIELD_TYPE (rtype, f) = | |
6474 | ada_to_fixed_type | |
6475 | (ada_get_base_type | |
6476 | (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, f))), | |
6477 | cond_offset_host (valaddr, off / TARGET_CHAR_BIT), | |
6478 | cond_offset_target (address, off / TARGET_CHAR_BIT), dval); | |
6479 | TYPE_FIELD_NAME (rtype, f) = TYPE_FIELD_NAME (type, f); | |
6480 | bit_incr = fld_bit_len = | |
6481 | TYPE_LENGTH (TYPE_FIELD_TYPE (rtype, f)) * TARGET_CHAR_BIT; | |
6482 | } | |
14f9c5c9 | 6483 | else |
4c4b4cd2 PH |
6484 | { |
6485 | TYPE_FIELD_TYPE (rtype, f) = TYPE_FIELD_TYPE (type, f); | |
6486 | TYPE_FIELD_NAME (rtype, f) = TYPE_FIELD_NAME (type, f); | |
6487 | if (TYPE_FIELD_BITSIZE (type, f) > 0) | |
6488 | bit_incr = fld_bit_len = | |
6489 | TYPE_FIELD_BITSIZE (rtype, f) = TYPE_FIELD_BITSIZE (type, f); | |
6490 | else | |
6491 | bit_incr = fld_bit_len = | |
6492 | TYPE_LENGTH (TYPE_FIELD_TYPE (type, f)) * TARGET_CHAR_BIT; | |
6493 | } | |
14f9c5c9 | 6494 | if (off + fld_bit_len > bit_len) |
4c4b4cd2 | 6495 | bit_len = off + fld_bit_len; |
14f9c5c9 | 6496 | off += bit_incr; |
4c4b4cd2 PH |
6497 | TYPE_LENGTH (rtype) = |
6498 | align_value (bit_len, TARGET_CHAR_BIT) / TARGET_CHAR_BIT; | |
14f9c5c9 | 6499 | } |
4c4b4cd2 PH |
6500 | |
6501 | /* We handle the variant part, if any, at the end because of certain | |
6502 | odd cases in which it is re-ordered so as NOT the last field of | |
6503 | the record. This can happen in the presence of representation | |
6504 | clauses. */ | |
6505 | if (variant_field >= 0) | |
6506 | { | |
6507 | struct type *branch_type; | |
6508 | ||
6509 | off = TYPE_FIELD_BITPOS (rtype, variant_field); | |
6510 | ||
6511 | if (dval0 == NULL) | |
6512 | dval = value_from_contents_and_address (rtype, valaddr, address); | |
6513 | else | |
6514 | dval = dval0; | |
6515 | ||
6516 | branch_type = | |
6517 | to_fixed_variant_branch_type | |
6518 | (TYPE_FIELD_TYPE (type, variant_field), | |
6519 | cond_offset_host (valaddr, off / TARGET_CHAR_BIT), | |
6520 | cond_offset_target (address, off / TARGET_CHAR_BIT), dval); | |
6521 | if (branch_type == NULL) | |
6522 | { | |
6523 | for (f = variant_field + 1; f < TYPE_NFIELDS (rtype); f += 1) | |
6524 | TYPE_FIELDS (rtype)[f - 1] = TYPE_FIELDS (rtype)[f]; | |
6525 | TYPE_NFIELDS (rtype) -= 1; | |
6526 | } | |
6527 | else | |
6528 | { | |
6529 | TYPE_FIELD_TYPE (rtype, variant_field) = branch_type; | |
6530 | TYPE_FIELD_NAME (rtype, variant_field) = "S"; | |
6531 | fld_bit_len = | |
6532 | TYPE_LENGTH (TYPE_FIELD_TYPE (rtype, variant_field)) * | |
6533 | TARGET_CHAR_BIT; | |
6534 | if (off + fld_bit_len > bit_len) | |
6535 | bit_len = off + fld_bit_len; | |
6536 | TYPE_LENGTH (rtype) = | |
6537 | align_value (bit_len, TARGET_CHAR_BIT) / TARGET_CHAR_BIT; | |
6538 | } | |
6539 | } | |
6540 | ||
714e53ab PH |
6541 | /* According to exp_dbug.ads, the size of TYPE for variable-size records |
6542 | should contain the alignment of that record, which should be a strictly | |
6543 | positive value. If null or negative, then something is wrong, most | |
6544 | probably in the debug info. In that case, we don't round up the size | |
6545 | of the resulting type. If this record is not part of another structure, | |
6546 | the current RTYPE length might be good enough for our purposes. */ | |
6547 | if (TYPE_LENGTH (type) <= 0) | |
6548 | { | |
323e0a4a AC |
6549 | if (TYPE_NAME (rtype)) |
6550 | warning (_("Invalid type size for `%s' detected: %d."), | |
6551 | TYPE_NAME (rtype), TYPE_LENGTH (type)); | |
6552 | else | |
6553 | warning (_("Invalid type size for <unnamed> detected: %d."), | |
6554 | TYPE_LENGTH (type)); | |
714e53ab PH |
6555 | } |
6556 | else | |
6557 | { | |
6558 | TYPE_LENGTH (rtype) = align_value (TYPE_LENGTH (rtype), | |
6559 | TYPE_LENGTH (type)); | |
6560 | } | |
14f9c5c9 AS |
6561 | |
6562 | value_free_to_mark (mark); | |
d2e4a39e | 6563 | if (TYPE_LENGTH (rtype) > varsize_limit) |
323e0a4a | 6564 | error (_("record type with dynamic size is larger than varsize-limit")); |
14f9c5c9 AS |
6565 | return rtype; |
6566 | } | |
6567 | ||
4c4b4cd2 PH |
6568 | /* As for ada_template_to_fixed_record_type_1 with KEEP_DYNAMIC_FIELDS |
6569 | of 1. */ | |
14f9c5c9 | 6570 | |
d2e4a39e | 6571 | static struct type * |
fc1a4b47 | 6572 | template_to_fixed_record_type (struct type *type, const gdb_byte *valaddr, |
4c4b4cd2 PH |
6573 | CORE_ADDR address, struct value *dval0) |
6574 | { | |
6575 | return ada_template_to_fixed_record_type_1 (type, valaddr, | |
6576 | address, dval0, 1); | |
6577 | } | |
6578 | ||
6579 | /* An ordinary record type in which ___XVL-convention fields and | |
6580 | ___XVU- and ___XVN-convention field types in TYPE0 are replaced with | |
6581 | static approximations, containing all possible fields. Uses | |
6582 | no runtime values. Useless for use in values, but that's OK, | |
6583 | since the results are used only for type determinations. Works on both | |
6584 | structs and unions. Representation note: to save space, we memorize | |
6585 | the result of this function in the TYPE_TARGET_TYPE of the | |
6586 | template type. */ | |
6587 | ||
6588 | static struct type * | |
6589 | template_to_static_fixed_type (struct type *type0) | |
14f9c5c9 AS |
6590 | { |
6591 | struct type *type; | |
6592 | int nfields; | |
6593 | int f; | |
6594 | ||
4c4b4cd2 PH |
6595 | if (TYPE_TARGET_TYPE (type0) != NULL) |
6596 | return TYPE_TARGET_TYPE (type0); | |
6597 | ||
6598 | nfields = TYPE_NFIELDS (type0); | |
6599 | type = type0; | |
14f9c5c9 AS |
6600 | |
6601 | for (f = 0; f < nfields; f += 1) | |
6602 | { | |
61ee279c | 6603 | struct type *field_type = ada_check_typedef (TYPE_FIELD_TYPE (type0, f)); |
4c4b4cd2 | 6604 | struct type *new_type; |
14f9c5c9 | 6605 | |
4c4b4cd2 PH |
6606 | if (is_dynamic_field (type0, f)) |
6607 | new_type = to_static_fixed_type (TYPE_TARGET_TYPE (field_type)); | |
14f9c5c9 | 6608 | else |
4c4b4cd2 PH |
6609 | new_type = to_static_fixed_type (field_type); |
6610 | if (type == type0 && new_type != field_type) | |
6611 | { | |
6612 | TYPE_TARGET_TYPE (type0) = type = alloc_type (TYPE_OBJFILE (type0)); | |
6613 | TYPE_CODE (type) = TYPE_CODE (type0); | |
6614 | INIT_CPLUS_SPECIFIC (type); | |
6615 | TYPE_NFIELDS (type) = nfields; | |
6616 | TYPE_FIELDS (type) = (struct field *) | |
6617 | TYPE_ALLOC (type, nfields * sizeof (struct field)); | |
6618 | memcpy (TYPE_FIELDS (type), TYPE_FIELDS (type0), | |
6619 | sizeof (struct field) * nfields); | |
6620 | TYPE_NAME (type) = ada_type_name (type0); | |
6621 | TYPE_TAG_NAME (type) = NULL; | |
6622 | TYPE_FLAGS (type) |= TYPE_FLAG_FIXED_INSTANCE; | |
6623 | TYPE_LENGTH (type) = 0; | |
6624 | } | |
6625 | TYPE_FIELD_TYPE (type, f) = new_type; | |
6626 | TYPE_FIELD_NAME (type, f) = TYPE_FIELD_NAME (type0, f); | |
14f9c5c9 | 6627 | } |
14f9c5c9 AS |
6628 | return type; |
6629 | } | |
6630 | ||
4c4b4cd2 PH |
6631 | /* Given an object of type TYPE whose contents are at VALADDR and |
6632 | whose address in memory is ADDRESS, returns a revision of TYPE -- | |
6633 | a non-dynamic-sized record with a variant part -- in which | |
6634 | the variant part is replaced with the appropriate branch. Looks | |
6635 | for discriminant values in DVAL0, which can be NULL if the record | |
6636 | contains the necessary discriminant values. */ | |
6637 | ||
d2e4a39e | 6638 | static struct type * |
fc1a4b47 | 6639 | to_record_with_fixed_variant_part (struct type *type, const gdb_byte *valaddr, |
4c4b4cd2 | 6640 | CORE_ADDR address, struct value *dval0) |
14f9c5c9 | 6641 | { |
d2e4a39e | 6642 | struct value *mark = value_mark (); |
4c4b4cd2 | 6643 | struct value *dval; |
d2e4a39e | 6644 | struct type *rtype; |
14f9c5c9 AS |
6645 | struct type *branch_type; |
6646 | int nfields = TYPE_NFIELDS (type); | |
4c4b4cd2 | 6647 | int variant_field = variant_field_index (type); |
14f9c5c9 | 6648 | |
4c4b4cd2 | 6649 | if (variant_field == -1) |
14f9c5c9 AS |
6650 | return type; |
6651 | ||
4c4b4cd2 PH |
6652 | if (dval0 == NULL) |
6653 | dval = value_from_contents_and_address (type, valaddr, address); | |
6654 | else | |
6655 | dval = dval0; | |
6656 | ||
14f9c5c9 AS |
6657 | rtype = alloc_type (TYPE_OBJFILE (type)); |
6658 | TYPE_CODE (rtype) = TYPE_CODE_STRUCT; | |
4c4b4cd2 PH |
6659 | INIT_CPLUS_SPECIFIC (rtype); |
6660 | TYPE_NFIELDS (rtype) = nfields; | |
d2e4a39e AS |
6661 | TYPE_FIELDS (rtype) = |
6662 | (struct field *) TYPE_ALLOC (rtype, nfields * sizeof (struct field)); | |
6663 | memcpy (TYPE_FIELDS (rtype), TYPE_FIELDS (type), | |
4c4b4cd2 | 6664 | sizeof (struct field) * nfields); |
14f9c5c9 AS |
6665 | TYPE_NAME (rtype) = ada_type_name (type); |
6666 | TYPE_TAG_NAME (rtype) = NULL; | |
4c4b4cd2 | 6667 | TYPE_FLAGS (rtype) |= TYPE_FLAG_FIXED_INSTANCE; |
14f9c5c9 AS |
6668 | TYPE_LENGTH (rtype) = TYPE_LENGTH (type); |
6669 | ||
4c4b4cd2 PH |
6670 | branch_type = to_fixed_variant_branch_type |
6671 | (TYPE_FIELD_TYPE (type, variant_field), | |
d2e4a39e | 6672 | cond_offset_host (valaddr, |
4c4b4cd2 PH |
6673 | TYPE_FIELD_BITPOS (type, variant_field) |
6674 | / TARGET_CHAR_BIT), | |
d2e4a39e | 6675 | cond_offset_target (address, |
4c4b4cd2 PH |
6676 | TYPE_FIELD_BITPOS (type, variant_field) |
6677 | / TARGET_CHAR_BIT), dval); | |
d2e4a39e | 6678 | if (branch_type == NULL) |
14f9c5c9 | 6679 | { |
4c4b4cd2 PH |
6680 | int f; |
6681 | for (f = variant_field + 1; f < nfields; f += 1) | |
6682 | TYPE_FIELDS (rtype)[f - 1] = TYPE_FIELDS (rtype)[f]; | |
14f9c5c9 | 6683 | TYPE_NFIELDS (rtype) -= 1; |
14f9c5c9 AS |
6684 | } |
6685 | else | |
6686 | { | |
4c4b4cd2 PH |
6687 | TYPE_FIELD_TYPE (rtype, variant_field) = branch_type; |
6688 | TYPE_FIELD_NAME (rtype, variant_field) = "S"; | |
6689 | TYPE_FIELD_BITSIZE (rtype, variant_field) = 0; | |
14f9c5c9 | 6690 | TYPE_LENGTH (rtype) += TYPE_LENGTH (branch_type); |
14f9c5c9 | 6691 | } |
4c4b4cd2 | 6692 | TYPE_LENGTH (rtype) -= TYPE_LENGTH (TYPE_FIELD_TYPE (type, variant_field)); |
d2e4a39e | 6693 | |
4c4b4cd2 | 6694 | value_free_to_mark (mark); |
14f9c5c9 AS |
6695 | return rtype; |
6696 | } | |
6697 | ||
6698 | /* An ordinary record type (with fixed-length fields) that describes | |
6699 | the value at (TYPE0, VALADDR, ADDRESS) [see explanation at | |
6700 | beginning of this section]. Any necessary discriminants' values | |
4c4b4cd2 PH |
6701 | should be in DVAL, a record value; it may be NULL if the object |
6702 | at ADDR itself contains any necessary discriminant values. | |
6703 | Additionally, VALADDR and ADDRESS may also be NULL if no discriminant | |
6704 | values from the record are needed. Except in the case that DVAL, | |
6705 | VALADDR, and ADDRESS are all 0 or NULL, a variant field (unless | |
6706 | unchecked) is replaced by a particular branch of the variant. | |
6707 | ||
6708 | NOTE: the case in which DVAL and VALADDR are NULL and ADDRESS is 0 | |
6709 | is questionable and may be removed. It can arise during the | |
6710 | processing of an unconstrained-array-of-record type where all the | |
6711 | variant branches have exactly the same size. This is because in | |
6712 | such cases, the compiler does not bother to use the XVS convention | |
6713 | when encoding the record. I am currently dubious of this | |
6714 | shortcut and suspect the compiler should be altered. FIXME. */ | |
14f9c5c9 | 6715 | |
d2e4a39e | 6716 | static struct type * |
fc1a4b47 | 6717 | to_fixed_record_type (struct type *type0, const gdb_byte *valaddr, |
4c4b4cd2 | 6718 | CORE_ADDR address, struct value *dval) |
14f9c5c9 | 6719 | { |
d2e4a39e | 6720 | struct type *templ_type; |
14f9c5c9 | 6721 | |
4c4b4cd2 PH |
6722 | if (TYPE_FLAGS (type0) & TYPE_FLAG_FIXED_INSTANCE) |
6723 | return type0; | |
6724 | ||
d2e4a39e | 6725 | templ_type = dynamic_template_type (type0); |
14f9c5c9 AS |
6726 | |
6727 | if (templ_type != NULL) | |
6728 | return template_to_fixed_record_type (templ_type, valaddr, address, dval); | |
4c4b4cd2 PH |
6729 | else if (variant_field_index (type0) >= 0) |
6730 | { | |
6731 | if (dval == NULL && valaddr == NULL && address == 0) | |
6732 | return type0; | |
6733 | return to_record_with_fixed_variant_part (type0, valaddr, address, | |
6734 | dval); | |
6735 | } | |
14f9c5c9 AS |
6736 | else |
6737 | { | |
4c4b4cd2 | 6738 | TYPE_FLAGS (type0) |= TYPE_FLAG_FIXED_INSTANCE; |
14f9c5c9 AS |
6739 | return type0; |
6740 | } | |
6741 | ||
6742 | } | |
6743 | ||
6744 | /* An ordinary record type (with fixed-length fields) that describes | |
6745 | the value at (VAR_TYPE0, VALADDR, ADDRESS), where VAR_TYPE0 is a | |
6746 | union type. Any necessary discriminants' values should be in DVAL, | |
6747 | a record value. That is, this routine selects the appropriate | |
6748 | branch of the union at ADDR according to the discriminant value | |
4c4b4cd2 | 6749 | indicated in the union's type name. */ |
14f9c5c9 | 6750 | |
d2e4a39e | 6751 | static struct type * |
fc1a4b47 | 6752 | to_fixed_variant_branch_type (struct type *var_type0, const gdb_byte *valaddr, |
4c4b4cd2 | 6753 | CORE_ADDR address, struct value *dval) |
14f9c5c9 AS |
6754 | { |
6755 | int which; | |
d2e4a39e AS |
6756 | struct type *templ_type; |
6757 | struct type *var_type; | |
14f9c5c9 AS |
6758 | |
6759 | if (TYPE_CODE (var_type0) == TYPE_CODE_PTR) | |
6760 | var_type = TYPE_TARGET_TYPE (var_type0); | |
d2e4a39e | 6761 | else |
14f9c5c9 AS |
6762 | var_type = var_type0; |
6763 | ||
6764 | templ_type = ada_find_parallel_type (var_type, "___XVU"); | |
6765 | ||
6766 | if (templ_type != NULL) | |
6767 | var_type = templ_type; | |
6768 | ||
d2e4a39e AS |
6769 | which = |
6770 | ada_which_variant_applies (var_type, | |
0fd88904 | 6771 | value_type (dval), value_contents (dval)); |
14f9c5c9 AS |
6772 | |
6773 | if (which < 0) | |
6774 | return empty_record (TYPE_OBJFILE (var_type)); | |
6775 | else if (is_dynamic_field (var_type, which)) | |
4c4b4cd2 | 6776 | return to_fixed_record_type |
d2e4a39e AS |
6777 | (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (var_type, which)), |
6778 | valaddr, address, dval); | |
4c4b4cd2 | 6779 | else if (variant_field_index (TYPE_FIELD_TYPE (var_type, which)) >= 0) |
d2e4a39e AS |
6780 | return |
6781 | to_fixed_record_type | |
6782 | (TYPE_FIELD_TYPE (var_type, which), valaddr, address, dval); | |
14f9c5c9 AS |
6783 | else |
6784 | return TYPE_FIELD_TYPE (var_type, which); | |
6785 | } | |
6786 | ||
6787 | /* Assuming that TYPE0 is an array type describing the type of a value | |
6788 | at ADDR, and that DVAL describes a record containing any | |
6789 | discriminants used in TYPE0, returns a type for the value that | |
6790 | contains no dynamic components (that is, no components whose sizes | |
6791 | are determined by run-time quantities). Unless IGNORE_TOO_BIG is | |
6792 | true, gives an error message if the resulting type's size is over | |
4c4b4cd2 | 6793 | varsize_limit. */ |
14f9c5c9 | 6794 | |
d2e4a39e AS |
6795 | static struct type * |
6796 | to_fixed_array_type (struct type *type0, struct value *dval, | |
4c4b4cd2 | 6797 | int ignore_too_big) |
14f9c5c9 | 6798 | { |
d2e4a39e AS |
6799 | struct type *index_type_desc; |
6800 | struct type *result; | |
14f9c5c9 | 6801 | |
4c4b4cd2 PH |
6802 | if (ada_is_packed_array_type (type0) /* revisit? */ |
6803 | || (TYPE_FLAGS (type0) & TYPE_FLAG_FIXED_INSTANCE)) | |
6804 | return type0; | |
14f9c5c9 AS |
6805 | |
6806 | index_type_desc = ada_find_parallel_type (type0, "___XA"); | |
6807 | if (index_type_desc == NULL) | |
6808 | { | |
61ee279c | 6809 | struct type *elt_type0 = ada_check_typedef (TYPE_TARGET_TYPE (type0)); |
14f9c5c9 | 6810 | /* NOTE: elt_type---the fixed version of elt_type0---should never |
4c4b4cd2 PH |
6811 | depend on the contents of the array in properly constructed |
6812 | debugging data. */ | |
529cad9c PH |
6813 | /* Create a fixed version of the array element type. |
6814 | We're not providing the address of an element here, | |
e1d5a0d2 | 6815 | and thus the actual object value cannot be inspected to do |
529cad9c PH |
6816 | the conversion. This should not be a problem, since arrays of |
6817 | unconstrained objects are not allowed. In particular, all | |
6818 | the elements of an array of a tagged type should all be of | |
6819 | the same type specified in the debugging info. No need to | |
6820 | consult the object tag. */ | |
d2e4a39e | 6821 | struct type *elt_type = ada_to_fixed_type (elt_type0, 0, 0, dval); |
14f9c5c9 AS |
6822 | |
6823 | if (elt_type0 == elt_type) | |
4c4b4cd2 | 6824 | result = type0; |
14f9c5c9 | 6825 | else |
4c4b4cd2 PH |
6826 | result = create_array_type (alloc_type (TYPE_OBJFILE (type0)), |
6827 | elt_type, TYPE_INDEX_TYPE (type0)); | |
14f9c5c9 AS |
6828 | } |
6829 | else | |
6830 | { | |
6831 | int i; | |
6832 | struct type *elt_type0; | |
6833 | ||
6834 | elt_type0 = type0; | |
6835 | for (i = TYPE_NFIELDS (index_type_desc); i > 0; i -= 1) | |
4c4b4cd2 | 6836 | elt_type0 = TYPE_TARGET_TYPE (elt_type0); |
14f9c5c9 AS |
6837 | |
6838 | /* NOTE: result---the fixed version of elt_type0---should never | |
4c4b4cd2 PH |
6839 | depend on the contents of the array in properly constructed |
6840 | debugging data. */ | |
529cad9c PH |
6841 | /* Create a fixed version of the array element type. |
6842 | We're not providing the address of an element here, | |
e1d5a0d2 | 6843 | and thus the actual object value cannot be inspected to do |
529cad9c PH |
6844 | the conversion. This should not be a problem, since arrays of |
6845 | unconstrained objects are not allowed. In particular, all | |
6846 | the elements of an array of a tagged type should all be of | |
6847 | the same type specified in the debugging info. No need to | |
6848 | consult the object tag. */ | |
61ee279c | 6849 | result = ada_to_fixed_type (ada_check_typedef (elt_type0), 0, 0, dval); |
14f9c5c9 | 6850 | for (i = TYPE_NFIELDS (index_type_desc) - 1; i >= 0; i -= 1) |
4c4b4cd2 PH |
6851 | { |
6852 | struct type *range_type = | |
6853 | to_fixed_range_type (TYPE_FIELD_NAME (index_type_desc, i), | |
6854 | dval, TYPE_OBJFILE (type0)); | |
6855 | result = create_array_type (alloc_type (TYPE_OBJFILE (type0)), | |
6856 | result, range_type); | |
6857 | } | |
d2e4a39e | 6858 | if (!ignore_too_big && TYPE_LENGTH (result) > varsize_limit) |
323e0a4a | 6859 | error (_("array type with dynamic size is larger than varsize-limit")); |
14f9c5c9 AS |
6860 | } |
6861 | ||
4c4b4cd2 | 6862 | TYPE_FLAGS (result) |= TYPE_FLAG_FIXED_INSTANCE; |
14f9c5c9 | 6863 | return result; |
d2e4a39e | 6864 | } |
14f9c5c9 AS |
6865 | |
6866 | ||
6867 | /* A standard type (containing no dynamically sized components) | |
6868 | corresponding to TYPE for the value (TYPE, VALADDR, ADDRESS) | |
6869 | DVAL describes a record containing any discriminants used in TYPE0, | |
4c4b4cd2 | 6870 | and may be NULL if there are none, or if the object of type TYPE at |
529cad9c PH |
6871 | ADDRESS or in VALADDR contains these discriminants. |
6872 | ||
6873 | In the case of tagged types, this function attempts to locate the object's | |
6874 | tag and use it to compute the actual type. However, when ADDRESS is null, | |
6875 | we cannot use it to determine the location of the tag, and therefore | |
6876 | compute the tagged type's actual type. So we return the tagged type | |
6877 | without consulting the tag. */ | |
6878 | ||
d2e4a39e | 6879 | struct type * |
fc1a4b47 | 6880 | ada_to_fixed_type (struct type *type, const gdb_byte *valaddr, |
4c4b4cd2 | 6881 | CORE_ADDR address, struct value *dval) |
14f9c5c9 | 6882 | { |
61ee279c | 6883 | type = ada_check_typedef (type); |
d2e4a39e AS |
6884 | switch (TYPE_CODE (type)) |
6885 | { | |
6886 | default: | |
14f9c5c9 | 6887 | return type; |
d2e4a39e | 6888 | case TYPE_CODE_STRUCT: |
4c4b4cd2 | 6889 | { |
76a01679 | 6890 | struct type *static_type = to_static_fixed_type (type); |
529cad9c PH |
6891 | |
6892 | /* If STATIC_TYPE is a tagged type and we know the object's address, | |
6893 | then we can determine its tag, and compute the object's actual | |
6894 | type from there. */ | |
6895 | ||
6896 | if (address != 0 && ada_is_tagged_type (static_type, 0)) | |
76a01679 JB |
6897 | { |
6898 | struct type *real_type = | |
6899 | type_from_tag (value_tag_from_contents_and_address (static_type, | |
6900 | valaddr, | |
6901 | address)); | |
6902 | if (real_type != NULL) | |
6903 | type = real_type; | |
6904 | } | |
6905 | return to_fixed_record_type (type, valaddr, address, NULL); | |
4c4b4cd2 | 6906 | } |
d2e4a39e | 6907 | case TYPE_CODE_ARRAY: |
4c4b4cd2 | 6908 | return to_fixed_array_type (type, dval, 1); |
d2e4a39e AS |
6909 | case TYPE_CODE_UNION: |
6910 | if (dval == NULL) | |
4c4b4cd2 | 6911 | return type; |
d2e4a39e | 6912 | else |
4c4b4cd2 | 6913 | return to_fixed_variant_branch_type (type, valaddr, address, dval); |
d2e4a39e | 6914 | } |
14f9c5c9 AS |
6915 | } |
6916 | ||
6917 | /* A standard (static-sized) type corresponding as well as possible to | |
4c4b4cd2 | 6918 | TYPE0, but based on no runtime data. */ |
14f9c5c9 | 6919 | |
d2e4a39e AS |
6920 | static struct type * |
6921 | to_static_fixed_type (struct type *type0) | |
14f9c5c9 | 6922 | { |
d2e4a39e | 6923 | struct type *type; |
14f9c5c9 AS |
6924 | |
6925 | if (type0 == NULL) | |
6926 | return NULL; | |
6927 | ||
4c4b4cd2 PH |
6928 | if (TYPE_FLAGS (type0) & TYPE_FLAG_FIXED_INSTANCE) |
6929 | return type0; | |
6930 | ||
61ee279c | 6931 | type0 = ada_check_typedef (type0); |
d2e4a39e | 6932 | |
14f9c5c9 AS |
6933 | switch (TYPE_CODE (type0)) |
6934 | { | |
6935 | default: | |
6936 | return type0; | |
6937 | case TYPE_CODE_STRUCT: | |
6938 | type = dynamic_template_type (type0); | |
d2e4a39e | 6939 | if (type != NULL) |
4c4b4cd2 PH |
6940 | return template_to_static_fixed_type (type); |
6941 | else | |
6942 | return template_to_static_fixed_type (type0); | |
14f9c5c9 AS |
6943 | case TYPE_CODE_UNION: |
6944 | type = ada_find_parallel_type (type0, "___XVU"); | |
6945 | if (type != NULL) | |
4c4b4cd2 PH |
6946 | return template_to_static_fixed_type (type); |
6947 | else | |
6948 | return template_to_static_fixed_type (type0); | |
14f9c5c9 AS |
6949 | } |
6950 | } | |
6951 | ||
4c4b4cd2 PH |
6952 | /* A static approximation of TYPE with all type wrappers removed. */ |
6953 | ||
d2e4a39e AS |
6954 | static struct type * |
6955 | static_unwrap_type (struct type *type) | |
14f9c5c9 AS |
6956 | { |
6957 | if (ada_is_aligner_type (type)) | |
6958 | { | |
61ee279c | 6959 | struct type *type1 = TYPE_FIELD_TYPE (ada_check_typedef (type), 0); |
14f9c5c9 | 6960 | if (ada_type_name (type1) == NULL) |
4c4b4cd2 | 6961 | TYPE_NAME (type1) = ada_type_name (type); |
14f9c5c9 AS |
6962 | |
6963 | return static_unwrap_type (type1); | |
6964 | } | |
d2e4a39e | 6965 | else |
14f9c5c9 | 6966 | { |
d2e4a39e AS |
6967 | struct type *raw_real_type = ada_get_base_type (type); |
6968 | if (raw_real_type == type) | |
4c4b4cd2 | 6969 | return type; |
14f9c5c9 | 6970 | else |
4c4b4cd2 | 6971 | return to_static_fixed_type (raw_real_type); |
14f9c5c9 AS |
6972 | } |
6973 | } | |
6974 | ||
6975 | /* In some cases, incomplete and private types require | |
4c4b4cd2 | 6976 | cross-references that are not resolved as records (for example, |
14f9c5c9 AS |
6977 | type Foo; |
6978 | type FooP is access Foo; | |
6979 | V: FooP; | |
6980 | type Foo is array ...; | |
4c4b4cd2 | 6981 | ). In these cases, since there is no mechanism for producing |
14f9c5c9 AS |
6982 | cross-references to such types, we instead substitute for FooP a |
6983 | stub enumeration type that is nowhere resolved, and whose tag is | |
4c4b4cd2 | 6984 | the name of the actual type. Call these types "non-record stubs". */ |
14f9c5c9 AS |
6985 | |
6986 | /* A type equivalent to TYPE that is not a non-record stub, if one | |
4c4b4cd2 PH |
6987 | exists, otherwise TYPE. */ |
6988 | ||
d2e4a39e | 6989 | struct type * |
61ee279c | 6990 | ada_check_typedef (struct type *type) |
14f9c5c9 AS |
6991 | { |
6992 | CHECK_TYPEDEF (type); | |
6993 | if (type == NULL || TYPE_CODE (type) != TYPE_CODE_ENUM | |
529cad9c | 6994 | || !TYPE_STUB (type) |
14f9c5c9 AS |
6995 | || TYPE_TAG_NAME (type) == NULL) |
6996 | return type; | |
d2e4a39e | 6997 | else |
14f9c5c9 | 6998 | { |
d2e4a39e AS |
6999 | char *name = TYPE_TAG_NAME (type); |
7000 | struct type *type1 = ada_find_any_type (name); | |
14f9c5c9 AS |
7001 | return (type1 == NULL) ? type : type1; |
7002 | } | |
7003 | } | |
7004 | ||
7005 | /* A value representing the data at VALADDR/ADDRESS as described by | |
7006 | type TYPE0, but with a standard (static-sized) type that correctly | |
7007 | describes it. If VAL0 is not NULL and TYPE0 already is a standard | |
7008 | type, then return VAL0 [this feature is simply to avoid redundant | |
4c4b4cd2 | 7009 | creation of struct values]. */ |
14f9c5c9 | 7010 | |
4c4b4cd2 PH |
7011 | static struct value * |
7012 | ada_to_fixed_value_create (struct type *type0, CORE_ADDR address, | |
7013 | struct value *val0) | |
14f9c5c9 | 7014 | { |
4c4b4cd2 | 7015 | struct type *type = ada_to_fixed_type (type0, 0, address, NULL); |
14f9c5c9 AS |
7016 | if (type == type0 && val0 != NULL) |
7017 | return val0; | |
d2e4a39e | 7018 | else |
4c4b4cd2 PH |
7019 | return value_from_contents_and_address (type, 0, address); |
7020 | } | |
7021 | ||
7022 | /* A value representing VAL, but with a standard (static-sized) type | |
7023 | that correctly describes it. Does not necessarily create a new | |
7024 | value. */ | |
7025 | ||
7026 | static struct value * | |
7027 | ada_to_fixed_value (struct value *val) | |
7028 | { | |
df407dfe AC |
7029 | return ada_to_fixed_value_create (value_type (val), |
7030 | VALUE_ADDRESS (val) + value_offset (val), | |
4c4b4cd2 | 7031 | val); |
14f9c5c9 AS |
7032 | } |
7033 | ||
4c4b4cd2 | 7034 | /* A value representing VAL, but with a standard (static-sized) type |
14f9c5c9 AS |
7035 | chosen to approximate the real type of VAL as well as possible, but |
7036 | without consulting any runtime values. For Ada dynamic-sized | |
4c4b4cd2 | 7037 | types, therefore, the type of the result is likely to be inaccurate. */ |
14f9c5c9 | 7038 | |
d2e4a39e AS |
7039 | struct value * |
7040 | ada_to_static_fixed_value (struct value *val) | |
14f9c5c9 | 7041 | { |
d2e4a39e | 7042 | struct type *type = |
df407dfe AC |
7043 | to_static_fixed_type (static_unwrap_type (value_type (val))); |
7044 | if (type == value_type (val)) | |
14f9c5c9 AS |
7045 | return val; |
7046 | else | |
4c4b4cd2 | 7047 | return coerce_unspec_val_to_type (val, type); |
14f9c5c9 | 7048 | } |
d2e4a39e | 7049 | \f |
14f9c5c9 | 7050 | |
14f9c5c9 AS |
7051 | /* Attributes */ |
7052 | ||
4c4b4cd2 PH |
7053 | /* Table mapping attribute numbers to names. |
7054 | NOTE: Keep up to date with enum ada_attribute definition in ada-lang.h. */ | |
14f9c5c9 | 7055 | |
d2e4a39e | 7056 | static const char *attribute_names[] = { |
14f9c5c9 AS |
7057 | "<?>", |
7058 | ||
d2e4a39e | 7059 | "first", |
14f9c5c9 AS |
7060 | "last", |
7061 | "length", | |
7062 | "image", | |
14f9c5c9 AS |
7063 | "max", |
7064 | "min", | |
4c4b4cd2 PH |
7065 | "modulus", |
7066 | "pos", | |
7067 | "size", | |
7068 | "tag", | |
14f9c5c9 | 7069 | "val", |
14f9c5c9 AS |
7070 | 0 |
7071 | }; | |
7072 | ||
d2e4a39e | 7073 | const char * |
4c4b4cd2 | 7074 | ada_attribute_name (enum exp_opcode n) |
14f9c5c9 | 7075 | { |
4c4b4cd2 PH |
7076 | if (n >= OP_ATR_FIRST && n <= (int) OP_ATR_VAL) |
7077 | return attribute_names[n - OP_ATR_FIRST + 1]; | |
14f9c5c9 AS |
7078 | else |
7079 | return attribute_names[0]; | |
7080 | } | |
7081 | ||
4c4b4cd2 | 7082 | /* Evaluate the 'POS attribute applied to ARG. */ |
14f9c5c9 | 7083 | |
4c4b4cd2 PH |
7084 | static LONGEST |
7085 | pos_atr (struct value *arg) | |
14f9c5c9 | 7086 | { |
df407dfe | 7087 | struct type *type = value_type (arg); |
14f9c5c9 | 7088 | |
d2e4a39e | 7089 | if (!discrete_type_p (type)) |
323e0a4a | 7090 | error (_("'POS only defined on discrete types")); |
14f9c5c9 AS |
7091 | |
7092 | if (TYPE_CODE (type) == TYPE_CODE_ENUM) | |
7093 | { | |
7094 | int i; | |
7095 | LONGEST v = value_as_long (arg); | |
7096 | ||
d2e4a39e | 7097 | for (i = 0; i < TYPE_NFIELDS (type); i += 1) |
4c4b4cd2 PH |
7098 | { |
7099 | if (v == TYPE_FIELD_BITPOS (type, i)) | |
7100 | return i; | |
7101 | } | |
323e0a4a | 7102 | error (_("enumeration value is invalid: can't find 'POS")); |
14f9c5c9 AS |
7103 | } |
7104 | else | |
4c4b4cd2 PH |
7105 | return value_as_long (arg); |
7106 | } | |
7107 | ||
7108 | static struct value * | |
7109 | value_pos_atr (struct value *arg) | |
7110 | { | |
72d5681a | 7111 | return value_from_longest (builtin_type_int, pos_atr (arg)); |
14f9c5c9 AS |
7112 | } |
7113 | ||
4c4b4cd2 | 7114 | /* Evaluate the TYPE'VAL attribute applied to ARG. */ |
14f9c5c9 | 7115 | |
d2e4a39e AS |
7116 | static struct value * |
7117 | value_val_atr (struct type *type, struct value *arg) | |
14f9c5c9 | 7118 | { |
d2e4a39e | 7119 | if (!discrete_type_p (type)) |
323e0a4a | 7120 | error (_("'VAL only defined on discrete types")); |
df407dfe | 7121 | if (!integer_type_p (value_type (arg))) |
323e0a4a | 7122 | error (_("'VAL requires integral argument")); |
14f9c5c9 AS |
7123 | |
7124 | if (TYPE_CODE (type) == TYPE_CODE_ENUM) | |
7125 | { | |
7126 | long pos = value_as_long (arg); | |
7127 | if (pos < 0 || pos >= TYPE_NFIELDS (type)) | |
323e0a4a | 7128 | error (_("argument to 'VAL out of range")); |
d2e4a39e | 7129 | return value_from_longest (type, TYPE_FIELD_BITPOS (type, pos)); |
14f9c5c9 AS |
7130 | } |
7131 | else | |
7132 | return value_from_longest (type, value_as_long (arg)); | |
7133 | } | |
14f9c5c9 | 7134 | \f |
d2e4a39e | 7135 | |
4c4b4cd2 | 7136 | /* Evaluation */ |
14f9c5c9 | 7137 | |
4c4b4cd2 PH |
7138 | /* True if TYPE appears to be an Ada character type. |
7139 | [At the moment, this is true only for Character and Wide_Character; | |
7140 | It is a heuristic test that could stand improvement]. */ | |
14f9c5c9 | 7141 | |
d2e4a39e AS |
7142 | int |
7143 | ada_is_character_type (struct type *type) | |
14f9c5c9 | 7144 | { |
d2e4a39e AS |
7145 | const char *name = ada_type_name (type); |
7146 | return | |
14f9c5c9 | 7147 | name != NULL |
d2e4a39e | 7148 | && (TYPE_CODE (type) == TYPE_CODE_CHAR |
4c4b4cd2 PH |
7149 | || TYPE_CODE (type) == TYPE_CODE_INT |
7150 | || TYPE_CODE (type) == TYPE_CODE_RANGE) | |
7151 | && (strcmp (name, "character") == 0 | |
7152 | || strcmp (name, "wide_character") == 0 | |
7153 | || strcmp (name, "unsigned char") == 0); | |
14f9c5c9 AS |
7154 | } |
7155 | ||
4c4b4cd2 | 7156 | /* True if TYPE appears to be an Ada string type. */ |
14f9c5c9 AS |
7157 | |
7158 | int | |
ebf56fd3 | 7159 | ada_is_string_type (struct type *type) |
14f9c5c9 | 7160 | { |
61ee279c | 7161 | type = ada_check_typedef (type); |
d2e4a39e | 7162 | if (type != NULL |
14f9c5c9 | 7163 | && TYPE_CODE (type) != TYPE_CODE_PTR |
76a01679 JB |
7164 | && (ada_is_simple_array_type (type) |
7165 | || ada_is_array_descriptor_type (type)) | |
14f9c5c9 AS |
7166 | && ada_array_arity (type) == 1) |
7167 | { | |
7168 | struct type *elttype = ada_array_element_type (type, 1); | |
7169 | ||
7170 | return ada_is_character_type (elttype); | |
7171 | } | |
d2e4a39e | 7172 | else |
14f9c5c9 AS |
7173 | return 0; |
7174 | } | |
7175 | ||
7176 | ||
7177 | /* True if TYPE is a struct type introduced by the compiler to force the | |
7178 | alignment of a value. Such types have a single field with a | |
4c4b4cd2 | 7179 | distinctive name. */ |
14f9c5c9 AS |
7180 | |
7181 | int | |
ebf56fd3 | 7182 | ada_is_aligner_type (struct type *type) |
14f9c5c9 | 7183 | { |
61ee279c | 7184 | type = ada_check_typedef (type); |
714e53ab PH |
7185 | |
7186 | /* If we can find a parallel XVS type, then the XVS type should | |
7187 | be used instead of this type. And hence, this is not an aligner | |
7188 | type. */ | |
7189 | if (ada_find_parallel_type (type, "___XVS") != NULL) | |
7190 | return 0; | |
7191 | ||
14f9c5c9 | 7192 | return (TYPE_CODE (type) == TYPE_CODE_STRUCT |
4c4b4cd2 PH |
7193 | && TYPE_NFIELDS (type) == 1 |
7194 | && strcmp (TYPE_FIELD_NAME (type, 0), "F") == 0); | |
14f9c5c9 AS |
7195 | } |
7196 | ||
7197 | /* If there is an ___XVS-convention type parallel to SUBTYPE, return | |
4c4b4cd2 | 7198 | the parallel type. */ |
14f9c5c9 | 7199 | |
d2e4a39e AS |
7200 | struct type * |
7201 | ada_get_base_type (struct type *raw_type) | |
14f9c5c9 | 7202 | { |
d2e4a39e AS |
7203 | struct type *real_type_namer; |
7204 | struct type *raw_real_type; | |
14f9c5c9 AS |
7205 | |
7206 | if (raw_type == NULL || TYPE_CODE (raw_type) != TYPE_CODE_STRUCT) | |
7207 | return raw_type; | |
7208 | ||
7209 | real_type_namer = ada_find_parallel_type (raw_type, "___XVS"); | |
d2e4a39e | 7210 | if (real_type_namer == NULL |
14f9c5c9 AS |
7211 | || TYPE_CODE (real_type_namer) != TYPE_CODE_STRUCT |
7212 | || TYPE_NFIELDS (real_type_namer) != 1) | |
7213 | return raw_type; | |
7214 | ||
7215 | raw_real_type = ada_find_any_type (TYPE_FIELD_NAME (real_type_namer, 0)); | |
d2e4a39e | 7216 | if (raw_real_type == NULL) |
14f9c5c9 AS |
7217 | return raw_type; |
7218 | else | |
7219 | return raw_real_type; | |
d2e4a39e | 7220 | } |
14f9c5c9 | 7221 | |
4c4b4cd2 | 7222 | /* The type of value designated by TYPE, with all aligners removed. */ |
14f9c5c9 | 7223 | |
d2e4a39e AS |
7224 | struct type * |
7225 | ada_aligned_type (struct type *type) | |
14f9c5c9 AS |
7226 | { |
7227 | if (ada_is_aligner_type (type)) | |
7228 | return ada_aligned_type (TYPE_FIELD_TYPE (type, 0)); | |
7229 | else | |
7230 | return ada_get_base_type (type); | |
7231 | } | |
7232 | ||
7233 | ||
7234 | /* The address of the aligned value in an object at address VALADDR | |
4c4b4cd2 | 7235 | having type TYPE. Assumes ada_is_aligner_type (TYPE). */ |
14f9c5c9 | 7236 | |
fc1a4b47 AC |
7237 | const gdb_byte * |
7238 | ada_aligned_value_addr (struct type *type, const gdb_byte *valaddr) | |
14f9c5c9 | 7239 | { |
d2e4a39e | 7240 | if (ada_is_aligner_type (type)) |
14f9c5c9 | 7241 | return ada_aligned_value_addr (TYPE_FIELD_TYPE (type, 0), |
4c4b4cd2 PH |
7242 | valaddr + |
7243 | TYPE_FIELD_BITPOS (type, | |
7244 | 0) / TARGET_CHAR_BIT); | |
14f9c5c9 AS |
7245 | else |
7246 | return valaddr; | |
7247 | } | |
7248 | ||
4c4b4cd2 PH |
7249 | |
7250 | ||
14f9c5c9 | 7251 | /* The printed representation of an enumeration literal with encoded |
4c4b4cd2 | 7252 | name NAME. The value is good to the next call of ada_enum_name. */ |
d2e4a39e AS |
7253 | const char * |
7254 | ada_enum_name (const char *name) | |
14f9c5c9 | 7255 | { |
4c4b4cd2 PH |
7256 | static char *result; |
7257 | static size_t result_len = 0; | |
d2e4a39e | 7258 | char *tmp; |
14f9c5c9 | 7259 | |
4c4b4cd2 PH |
7260 | /* First, unqualify the enumeration name: |
7261 | 1. Search for the last '.' character. If we find one, then skip | |
76a01679 JB |
7262 | all the preceeding characters, the unqualified name starts |
7263 | right after that dot. | |
4c4b4cd2 | 7264 | 2. Otherwise, we may be debugging on a target where the compiler |
76a01679 JB |
7265 | translates dots into "__". Search forward for double underscores, |
7266 | but stop searching when we hit an overloading suffix, which is | |
7267 | of the form "__" followed by digits. */ | |
4c4b4cd2 | 7268 | |
c3e5cd34 PH |
7269 | tmp = strrchr (name, '.'); |
7270 | if (tmp != NULL) | |
4c4b4cd2 PH |
7271 | name = tmp + 1; |
7272 | else | |
14f9c5c9 | 7273 | { |
4c4b4cd2 PH |
7274 | while ((tmp = strstr (name, "__")) != NULL) |
7275 | { | |
7276 | if (isdigit (tmp[2])) | |
7277 | break; | |
7278 | else | |
7279 | name = tmp + 2; | |
7280 | } | |
14f9c5c9 AS |
7281 | } |
7282 | ||
7283 | if (name[0] == 'Q') | |
7284 | { | |
14f9c5c9 AS |
7285 | int v; |
7286 | if (name[1] == 'U' || name[1] == 'W') | |
4c4b4cd2 PH |
7287 | { |
7288 | if (sscanf (name + 2, "%x", &v) != 1) | |
7289 | return name; | |
7290 | } | |
14f9c5c9 | 7291 | else |
4c4b4cd2 | 7292 | return name; |
14f9c5c9 | 7293 | |
4c4b4cd2 | 7294 | GROW_VECT (result, result_len, 16); |
14f9c5c9 | 7295 | if (isascii (v) && isprint (v)) |
4c4b4cd2 | 7296 | sprintf (result, "'%c'", v); |
14f9c5c9 | 7297 | else if (name[1] == 'U') |
4c4b4cd2 | 7298 | sprintf (result, "[\"%02x\"]", v); |
14f9c5c9 | 7299 | else |
4c4b4cd2 | 7300 | sprintf (result, "[\"%04x\"]", v); |
14f9c5c9 AS |
7301 | |
7302 | return result; | |
7303 | } | |
d2e4a39e | 7304 | else |
4c4b4cd2 | 7305 | { |
c3e5cd34 PH |
7306 | tmp = strstr (name, "__"); |
7307 | if (tmp == NULL) | |
7308 | tmp = strstr (name, "$"); | |
7309 | if (tmp != NULL) | |
4c4b4cd2 PH |
7310 | { |
7311 | GROW_VECT (result, result_len, tmp - name + 1); | |
7312 | strncpy (result, name, tmp - name); | |
7313 | result[tmp - name] = '\0'; | |
7314 | return result; | |
7315 | } | |
7316 | ||
7317 | return name; | |
7318 | } | |
14f9c5c9 AS |
7319 | } |
7320 | ||
d2e4a39e | 7321 | static struct value * |
ebf56fd3 | 7322 | evaluate_subexp (struct type *expect_type, struct expression *exp, int *pos, |
4c4b4cd2 | 7323 | enum noside noside) |
14f9c5c9 | 7324 | { |
76a01679 | 7325 | return (*exp->language_defn->la_exp_desc->evaluate_exp) |
4c4b4cd2 | 7326 | (expect_type, exp, pos, noside); |
14f9c5c9 AS |
7327 | } |
7328 | ||
7329 | /* Evaluate the subexpression of EXP starting at *POS as for | |
7330 | evaluate_type, updating *POS to point just past the evaluated | |
4c4b4cd2 | 7331 | expression. */ |
14f9c5c9 | 7332 | |
d2e4a39e AS |
7333 | static struct value * |
7334 | evaluate_subexp_type (struct expression *exp, int *pos) | |
14f9c5c9 | 7335 | { |
4c4b4cd2 | 7336 | return (*exp->language_defn->la_exp_desc->evaluate_exp) |
14f9c5c9 AS |
7337 | (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS); |
7338 | } | |
7339 | ||
7340 | /* If VAL is wrapped in an aligner or subtype wrapper, return the | |
4c4b4cd2 | 7341 | value it wraps. */ |
14f9c5c9 | 7342 | |
d2e4a39e AS |
7343 | static struct value * |
7344 | unwrap_value (struct value *val) | |
14f9c5c9 | 7345 | { |
df407dfe | 7346 | struct type *type = ada_check_typedef (value_type (val)); |
14f9c5c9 AS |
7347 | if (ada_is_aligner_type (type)) |
7348 | { | |
d2e4a39e | 7349 | struct value *v = value_struct_elt (&val, NULL, "F", |
4c4b4cd2 | 7350 | NULL, "internal structure"); |
df407dfe | 7351 | struct type *val_type = ada_check_typedef (value_type (v)); |
14f9c5c9 | 7352 | if (ada_type_name (val_type) == NULL) |
4c4b4cd2 | 7353 | TYPE_NAME (val_type) = ada_type_name (type); |
14f9c5c9 AS |
7354 | |
7355 | return unwrap_value (v); | |
7356 | } | |
d2e4a39e | 7357 | else |
14f9c5c9 | 7358 | { |
d2e4a39e | 7359 | struct type *raw_real_type = |
61ee279c | 7360 | ada_check_typedef (ada_get_base_type (type)); |
d2e4a39e | 7361 | |
14f9c5c9 | 7362 | if (type == raw_real_type) |
4c4b4cd2 | 7363 | return val; |
14f9c5c9 | 7364 | |
d2e4a39e | 7365 | return |
4c4b4cd2 PH |
7366 | coerce_unspec_val_to_type |
7367 | (val, ada_to_fixed_type (raw_real_type, 0, | |
df407dfe | 7368 | VALUE_ADDRESS (val) + value_offset (val), |
4c4b4cd2 | 7369 | NULL)); |
14f9c5c9 AS |
7370 | } |
7371 | } | |
d2e4a39e AS |
7372 | |
7373 | static struct value * | |
7374 | cast_to_fixed (struct type *type, struct value *arg) | |
14f9c5c9 AS |
7375 | { |
7376 | LONGEST val; | |
7377 | ||
df407dfe | 7378 | if (type == value_type (arg)) |
14f9c5c9 | 7379 | return arg; |
df407dfe | 7380 | else if (ada_is_fixed_point_type (value_type (arg))) |
d2e4a39e | 7381 | val = ada_float_to_fixed (type, |
df407dfe | 7382 | ada_fixed_to_float (value_type (arg), |
4c4b4cd2 | 7383 | value_as_long (arg))); |
d2e4a39e | 7384 | else |
14f9c5c9 | 7385 | { |
d2e4a39e | 7386 | DOUBLEST argd = |
4c4b4cd2 | 7387 | value_as_double (value_cast (builtin_type_double, value_copy (arg))); |
14f9c5c9 AS |
7388 | val = ada_float_to_fixed (type, argd); |
7389 | } | |
7390 | ||
7391 | return value_from_longest (type, val); | |
7392 | } | |
7393 | ||
d2e4a39e AS |
7394 | static struct value * |
7395 | cast_from_fixed_to_double (struct value *arg) | |
14f9c5c9 | 7396 | { |
df407dfe | 7397 | DOUBLEST val = ada_fixed_to_float (value_type (arg), |
4c4b4cd2 | 7398 | value_as_long (arg)); |
14f9c5c9 AS |
7399 | return value_from_double (builtin_type_double, val); |
7400 | } | |
7401 | ||
4c4b4cd2 PH |
7402 | /* Coerce VAL as necessary for assignment to an lval of type TYPE, and |
7403 | return the converted value. */ | |
7404 | ||
d2e4a39e AS |
7405 | static struct value * |
7406 | coerce_for_assign (struct type *type, struct value *val) | |
14f9c5c9 | 7407 | { |
df407dfe | 7408 | struct type *type2 = value_type (val); |
14f9c5c9 AS |
7409 | if (type == type2) |
7410 | return val; | |
7411 | ||
61ee279c PH |
7412 | type2 = ada_check_typedef (type2); |
7413 | type = ada_check_typedef (type); | |
14f9c5c9 | 7414 | |
d2e4a39e AS |
7415 | if (TYPE_CODE (type2) == TYPE_CODE_PTR |
7416 | && TYPE_CODE (type) == TYPE_CODE_ARRAY) | |
14f9c5c9 AS |
7417 | { |
7418 | val = ada_value_ind (val); | |
df407dfe | 7419 | type2 = value_type (val); |
14f9c5c9 AS |
7420 | } |
7421 | ||
d2e4a39e | 7422 | if (TYPE_CODE (type2) == TYPE_CODE_ARRAY |
14f9c5c9 AS |
7423 | && TYPE_CODE (type) == TYPE_CODE_ARRAY) |
7424 | { | |
7425 | if (TYPE_LENGTH (type2) != TYPE_LENGTH (type) | |
4c4b4cd2 PH |
7426 | || TYPE_LENGTH (TYPE_TARGET_TYPE (type2)) |
7427 | != TYPE_LENGTH (TYPE_TARGET_TYPE (type2))) | |
323e0a4a | 7428 | error (_("Incompatible types in assignment")); |
04624583 | 7429 | deprecated_set_value_type (val, type); |
14f9c5c9 | 7430 | } |
d2e4a39e | 7431 | return val; |
14f9c5c9 AS |
7432 | } |
7433 | ||
4c4b4cd2 PH |
7434 | static struct value * |
7435 | ada_value_binop (struct value *arg1, struct value *arg2, enum exp_opcode op) | |
7436 | { | |
7437 | struct value *val; | |
7438 | struct type *type1, *type2; | |
7439 | LONGEST v, v1, v2; | |
7440 | ||
994b9211 AC |
7441 | arg1 = coerce_ref (arg1); |
7442 | arg2 = coerce_ref (arg2); | |
df407dfe AC |
7443 | type1 = base_type (ada_check_typedef (value_type (arg1))); |
7444 | type2 = base_type (ada_check_typedef (value_type (arg2))); | |
4c4b4cd2 | 7445 | |
76a01679 JB |
7446 | if (TYPE_CODE (type1) != TYPE_CODE_INT |
7447 | || TYPE_CODE (type2) != TYPE_CODE_INT) | |
4c4b4cd2 PH |
7448 | return value_binop (arg1, arg2, op); |
7449 | ||
76a01679 | 7450 | switch (op) |
4c4b4cd2 PH |
7451 | { |
7452 | case BINOP_MOD: | |
7453 | case BINOP_DIV: | |
7454 | case BINOP_REM: | |
7455 | break; | |
7456 | default: | |
7457 | return value_binop (arg1, arg2, op); | |
7458 | } | |
7459 | ||
7460 | v2 = value_as_long (arg2); | |
7461 | if (v2 == 0) | |
323e0a4a | 7462 | error (_("second operand of %s must not be zero."), op_string (op)); |
4c4b4cd2 PH |
7463 | |
7464 | if (TYPE_UNSIGNED (type1) || op == BINOP_MOD) | |
7465 | return value_binop (arg1, arg2, op); | |
7466 | ||
7467 | v1 = value_as_long (arg1); | |
7468 | switch (op) | |
7469 | { | |
7470 | case BINOP_DIV: | |
7471 | v = v1 / v2; | |
76a01679 JB |
7472 | if (!TRUNCATION_TOWARDS_ZERO && v1 * (v1 % v2) < 0) |
7473 | v += v > 0 ? -1 : 1; | |
4c4b4cd2 PH |
7474 | break; |
7475 | case BINOP_REM: | |
7476 | v = v1 % v2; | |
76a01679 JB |
7477 | if (v * v1 < 0) |
7478 | v -= v2; | |
4c4b4cd2 PH |
7479 | break; |
7480 | default: | |
7481 | /* Should not reach this point. */ | |
7482 | v = 0; | |
7483 | } | |
7484 | ||
7485 | val = allocate_value (type1); | |
990a07ab | 7486 | store_unsigned_integer (value_contents_raw (val), |
df407dfe | 7487 | TYPE_LENGTH (value_type (val)), v); |
4c4b4cd2 PH |
7488 | return val; |
7489 | } | |
7490 | ||
7491 | static int | |
7492 | ada_value_equal (struct value *arg1, struct value *arg2) | |
7493 | { | |
df407dfe AC |
7494 | if (ada_is_direct_array_type (value_type (arg1)) |
7495 | || ada_is_direct_array_type (value_type (arg2))) | |
4c4b4cd2 PH |
7496 | { |
7497 | arg1 = ada_coerce_to_simple_array (arg1); | |
7498 | arg2 = ada_coerce_to_simple_array (arg2); | |
df407dfe AC |
7499 | if (TYPE_CODE (value_type (arg1)) != TYPE_CODE_ARRAY |
7500 | || TYPE_CODE (value_type (arg2)) != TYPE_CODE_ARRAY) | |
323e0a4a | 7501 | error (_("Attempt to compare array with non-array")); |
4c4b4cd2 | 7502 | /* FIXME: The following works only for types whose |
76a01679 JB |
7503 | representations use all bits (no padding or undefined bits) |
7504 | and do not have user-defined equality. */ | |
7505 | return | |
df407dfe | 7506 | TYPE_LENGTH (value_type (arg1)) == TYPE_LENGTH (value_type (arg2)) |
0fd88904 | 7507 | && memcmp (value_contents (arg1), value_contents (arg2), |
df407dfe | 7508 | TYPE_LENGTH (value_type (arg1))) == 0; |
4c4b4cd2 PH |
7509 | } |
7510 | return value_equal (arg1, arg2); | |
7511 | } | |
7512 | ||
52ce6436 PH |
7513 | /* Total number of component associations in the aggregate starting at |
7514 | index PC in EXP. Assumes that index PC is the start of an | |
7515 | OP_AGGREGATE. */ | |
7516 | ||
7517 | static int | |
7518 | num_component_specs (struct expression *exp, int pc) | |
7519 | { | |
7520 | int n, m, i; | |
7521 | m = exp->elts[pc + 1].longconst; | |
7522 | pc += 3; | |
7523 | n = 0; | |
7524 | for (i = 0; i < m; i += 1) | |
7525 | { | |
7526 | switch (exp->elts[pc].opcode) | |
7527 | { | |
7528 | default: | |
7529 | n += 1; | |
7530 | break; | |
7531 | case OP_CHOICES: | |
7532 | n += exp->elts[pc + 1].longconst; | |
7533 | break; | |
7534 | } | |
7535 | ada_evaluate_subexp (NULL, exp, &pc, EVAL_SKIP); | |
7536 | } | |
7537 | return n; | |
7538 | } | |
7539 | ||
7540 | /* Assign the result of evaluating EXP starting at *POS to the INDEXth | |
7541 | component of LHS (a simple array or a record), updating *POS past | |
7542 | the expression, assuming that LHS is contained in CONTAINER. Does | |
7543 | not modify the inferior's memory, nor does it modify LHS (unless | |
7544 | LHS == CONTAINER). */ | |
7545 | ||
7546 | static void | |
7547 | assign_component (struct value *container, struct value *lhs, LONGEST index, | |
7548 | struct expression *exp, int *pos) | |
7549 | { | |
7550 | struct value *mark = value_mark (); | |
7551 | struct value *elt; | |
7552 | if (TYPE_CODE (value_type (lhs)) == TYPE_CODE_ARRAY) | |
7553 | { | |
7554 | struct value *index_val = value_from_longest (builtin_type_int, index); | |
7555 | elt = unwrap_value (ada_value_subscript (lhs, 1, &index_val)); | |
7556 | } | |
7557 | else | |
7558 | { | |
7559 | elt = ada_index_struct_field (index, lhs, 0, value_type (lhs)); | |
7560 | elt = ada_to_fixed_value (unwrap_value (elt)); | |
7561 | } | |
7562 | ||
7563 | if (exp->elts[*pos].opcode == OP_AGGREGATE) | |
7564 | assign_aggregate (container, elt, exp, pos, EVAL_NORMAL); | |
7565 | else | |
7566 | value_assign_to_component (container, elt, | |
7567 | ada_evaluate_subexp (NULL, exp, pos, | |
7568 | EVAL_NORMAL)); | |
7569 | ||
7570 | value_free_to_mark (mark); | |
7571 | } | |
7572 | ||
7573 | /* Assuming that LHS represents an lvalue having a record or array | |
7574 | type, and EXP->ELTS[*POS] is an OP_AGGREGATE, evaluate an assignment | |
7575 | of that aggregate's value to LHS, advancing *POS past the | |
7576 | aggregate. NOSIDE is as for evaluate_subexp. CONTAINER is an | |
7577 | lvalue containing LHS (possibly LHS itself). Does not modify | |
7578 | the inferior's memory, nor does it modify the contents of | |
7579 | LHS (unless == CONTAINER). Returns the modified CONTAINER. */ | |
7580 | ||
7581 | static struct value * | |
7582 | assign_aggregate (struct value *container, | |
7583 | struct value *lhs, struct expression *exp, | |
7584 | int *pos, enum noside noside) | |
7585 | { | |
7586 | struct type *lhs_type; | |
7587 | int n = exp->elts[*pos+1].longconst; | |
7588 | LONGEST low_index, high_index; | |
7589 | int num_specs; | |
7590 | LONGEST *indices; | |
7591 | int max_indices, num_indices; | |
7592 | int is_array_aggregate; | |
7593 | int i; | |
7594 | struct value *mark = value_mark (); | |
7595 | ||
7596 | *pos += 3; | |
7597 | if (noside != EVAL_NORMAL) | |
7598 | { | |
7599 | int i; | |
7600 | for (i = 0; i < n; i += 1) | |
7601 | ada_evaluate_subexp (NULL, exp, pos, noside); | |
7602 | return container; | |
7603 | } | |
7604 | ||
7605 | container = ada_coerce_ref (container); | |
7606 | if (ada_is_direct_array_type (value_type (container))) | |
7607 | container = ada_coerce_to_simple_array (container); | |
7608 | lhs = ada_coerce_ref (lhs); | |
7609 | if (!deprecated_value_modifiable (lhs)) | |
7610 | error (_("Left operand of assignment is not a modifiable lvalue.")); | |
7611 | ||
7612 | lhs_type = value_type (lhs); | |
7613 | if (ada_is_direct_array_type (lhs_type)) | |
7614 | { | |
7615 | lhs = ada_coerce_to_simple_array (lhs); | |
7616 | lhs_type = value_type (lhs); | |
7617 | low_index = TYPE_ARRAY_LOWER_BOUND_VALUE (lhs_type); | |
7618 | high_index = TYPE_ARRAY_UPPER_BOUND_VALUE (lhs_type); | |
7619 | is_array_aggregate = 1; | |
7620 | } | |
7621 | else if (TYPE_CODE (lhs_type) == TYPE_CODE_STRUCT) | |
7622 | { | |
7623 | low_index = 0; | |
7624 | high_index = num_visible_fields (lhs_type) - 1; | |
7625 | is_array_aggregate = 0; | |
7626 | } | |
7627 | else | |
7628 | error (_("Left-hand side must be array or record.")); | |
7629 | ||
7630 | num_specs = num_component_specs (exp, *pos - 3); | |
7631 | max_indices = 4 * num_specs + 4; | |
7632 | indices = alloca (max_indices * sizeof (indices[0])); | |
7633 | indices[0] = indices[1] = low_index - 1; | |
7634 | indices[2] = indices[3] = high_index + 1; | |
7635 | num_indices = 4; | |
7636 | ||
7637 | for (i = 0; i < n; i += 1) | |
7638 | { | |
7639 | switch (exp->elts[*pos].opcode) | |
7640 | { | |
7641 | case OP_CHOICES: | |
7642 | aggregate_assign_from_choices (container, lhs, exp, pos, indices, | |
7643 | &num_indices, max_indices, | |
7644 | low_index, high_index); | |
7645 | break; | |
7646 | case OP_POSITIONAL: | |
7647 | aggregate_assign_positional (container, lhs, exp, pos, indices, | |
7648 | &num_indices, max_indices, | |
7649 | low_index, high_index); | |
7650 | break; | |
7651 | case OP_OTHERS: | |
7652 | if (i != n-1) | |
7653 | error (_("Misplaced 'others' clause")); | |
7654 | aggregate_assign_others (container, lhs, exp, pos, indices, | |
7655 | num_indices, low_index, high_index); | |
7656 | break; | |
7657 | default: | |
7658 | error (_("Internal error: bad aggregate clause")); | |
7659 | } | |
7660 | } | |
7661 | ||
7662 | return container; | |
7663 | } | |
7664 | ||
7665 | /* Assign into the component of LHS indexed by the OP_POSITIONAL | |
7666 | construct at *POS, updating *POS past the construct, given that | |
7667 | the positions are relative to lower bound LOW, where HIGH is the | |
7668 | upper bound. Record the position in INDICES[0 .. MAX_INDICES-1] | |
7669 | updating *NUM_INDICES as needed. CONTAINER is as for | |
7670 | assign_aggregate. */ | |
7671 | static void | |
7672 | aggregate_assign_positional (struct value *container, | |
7673 | struct value *lhs, struct expression *exp, | |
7674 | int *pos, LONGEST *indices, int *num_indices, | |
7675 | int max_indices, LONGEST low, LONGEST high) | |
7676 | { | |
7677 | LONGEST ind = longest_to_int (exp->elts[*pos + 1].longconst) + low; | |
7678 | ||
7679 | if (ind - 1 == high) | |
e1d5a0d2 | 7680 | warning (_("Extra components in aggregate ignored.")); |
52ce6436 PH |
7681 | if (ind <= high) |
7682 | { | |
7683 | add_component_interval (ind, ind, indices, num_indices, max_indices); | |
7684 | *pos += 3; | |
7685 | assign_component (container, lhs, ind, exp, pos); | |
7686 | } | |
7687 | else | |
7688 | ada_evaluate_subexp (NULL, exp, pos, EVAL_SKIP); | |
7689 | } | |
7690 | ||
7691 | /* Assign into the components of LHS indexed by the OP_CHOICES | |
7692 | construct at *POS, updating *POS past the construct, given that | |
7693 | the allowable indices are LOW..HIGH. Record the indices assigned | |
7694 | to in INDICES[0 .. MAX_INDICES-1], updating *NUM_INDICES as | |
7695 | needed. CONTAINER is as for assign_aggregate. */ | |
7696 | static void | |
7697 | aggregate_assign_from_choices (struct value *container, | |
7698 | struct value *lhs, struct expression *exp, | |
7699 | int *pos, LONGEST *indices, int *num_indices, | |
7700 | int max_indices, LONGEST low, LONGEST high) | |
7701 | { | |
7702 | int j; | |
7703 | int n_choices = longest_to_int (exp->elts[*pos+1].longconst); | |
7704 | int choice_pos, expr_pc; | |
7705 | int is_array = ada_is_direct_array_type (value_type (lhs)); | |
7706 | ||
7707 | choice_pos = *pos += 3; | |
7708 | ||
7709 | for (j = 0; j < n_choices; j += 1) | |
7710 | ada_evaluate_subexp (NULL, exp, pos, EVAL_SKIP); | |
7711 | expr_pc = *pos; | |
7712 | ada_evaluate_subexp (NULL, exp, pos, EVAL_SKIP); | |
7713 | ||
7714 | for (j = 0; j < n_choices; j += 1) | |
7715 | { | |
7716 | LONGEST lower, upper; | |
7717 | enum exp_opcode op = exp->elts[choice_pos].opcode; | |
7718 | if (op == OP_DISCRETE_RANGE) | |
7719 | { | |
7720 | choice_pos += 1; | |
7721 | lower = value_as_long (ada_evaluate_subexp (NULL, exp, pos, | |
7722 | EVAL_NORMAL)); | |
7723 | upper = value_as_long (ada_evaluate_subexp (NULL, exp, pos, | |
7724 | EVAL_NORMAL)); | |
7725 | } | |
7726 | else if (is_array) | |
7727 | { | |
7728 | lower = value_as_long (ada_evaluate_subexp (NULL, exp, &choice_pos, | |
7729 | EVAL_NORMAL)); | |
7730 | upper = lower; | |
7731 | } | |
7732 | else | |
7733 | { | |
7734 | int ind; | |
7735 | char *name; | |
7736 | switch (op) | |
7737 | { | |
7738 | case OP_NAME: | |
7739 | name = &exp->elts[choice_pos + 2].string; | |
7740 | break; | |
7741 | case OP_VAR_VALUE: | |
7742 | name = SYMBOL_NATURAL_NAME (exp->elts[choice_pos + 2].symbol); | |
7743 | break; | |
7744 | default: | |
7745 | error (_("Invalid record component association.")); | |
7746 | } | |
7747 | ada_evaluate_subexp (NULL, exp, &choice_pos, EVAL_SKIP); | |
7748 | ind = 0; | |
7749 | if (! find_struct_field (name, value_type (lhs), 0, | |
7750 | NULL, NULL, NULL, NULL, &ind)) | |
7751 | error (_("Unknown component name: %s."), name); | |
7752 | lower = upper = ind; | |
7753 | } | |
7754 | ||
7755 | if (lower <= upper && (lower < low || upper > high)) | |
7756 | error (_("Index in component association out of bounds.")); | |
7757 | ||
7758 | add_component_interval (lower, upper, indices, num_indices, | |
7759 | max_indices); | |
7760 | while (lower <= upper) | |
7761 | { | |
7762 | int pos1; | |
7763 | pos1 = expr_pc; | |
7764 | assign_component (container, lhs, lower, exp, &pos1); | |
7765 | lower += 1; | |
7766 | } | |
7767 | } | |
7768 | } | |
7769 | ||
7770 | /* Assign the value of the expression in the OP_OTHERS construct in | |
7771 | EXP at *POS into the components of LHS indexed from LOW .. HIGH that | |
7772 | have not been previously assigned. The index intervals already assigned | |
7773 | are in INDICES[0 .. NUM_INDICES-1]. Updates *POS to after the | |
7774 | OP_OTHERS clause. CONTAINER is as for assign_aggregate*/ | |
7775 | static void | |
7776 | aggregate_assign_others (struct value *container, | |
7777 | struct value *lhs, struct expression *exp, | |
7778 | int *pos, LONGEST *indices, int num_indices, | |
7779 | LONGEST low, LONGEST high) | |
7780 | { | |
7781 | int i; | |
7782 | int expr_pc = *pos+1; | |
7783 | ||
7784 | for (i = 0; i < num_indices - 2; i += 2) | |
7785 | { | |
7786 | LONGEST ind; | |
7787 | for (ind = indices[i + 1] + 1; ind < indices[i + 2]; ind += 1) | |
7788 | { | |
7789 | int pos; | |
7790 | pos = expr_pc; | |
7791 | assign_component (container, lhs, ind, exp, &pos); | |
7792 | } | |
7793 | } | |
7794 | ada_evaluate_subexp (NULL, exp, pos, EVAL_SKIP); | |
7795 | } | |
7796 | ||
7797 | /* Add the interval [LOW .. HIGH] to the sorted set of intervals | |
7798 | [ INDICES[0] .. INDICES[1] ],..., [ INDICES[*SIZE-2] .. INDICES[*SIZE-1] ], | |
7799 | modifying *SIZE as needed. It is an error if *SIZE exceeds | |
7800 | MAX_SIZE. The resulting intervals do not overlap. */ | |
7801 | static void | |
7802 | add_component_interval (LONGEST low, LONGEST high, | |
7803 | LONGEST* indices, int *size, int max_size) | |
7804 | { | |
7805 | int i, j; | |
7806 | for (i = 0; i < *size; i += 2) { | |
7807 | if (high >= indices[i] && low <= indices[i + 1]) | |
7808 | { | |
7809 | int kh; | |
7810 | for (kh = i + 2; kh < *size; kh += 2) | |
7811 | if (high < indices[kh]) | |
7812 | break; | |
7813 | if (low < indices[i]) | |
7814 | indices[i] = low; | |
7815 | indices[i + 1] = indices[kh - 1]; | |
7816 | if (high > indices[i + 1]) | |
7817 | indices[i + 1] = high; | |
7818 | memcpy (indices + i + 2, indices + kh, *size - kh); | |
7819 | *size -= kh - i - 2; | |
7820 | return; | |
7821 | } | |
7822 | else if (high < indices[i]) | |
7823 | break; | |
7824 | } | |
7825 | ||
7826 | if (*size == max_size) | |
7827 | error (_("Internal error: miscounted aggregate components.")); | |
7828 | *size += 2; | |
7829 | for (j = *size-1; j >= i+2; j -= 1) | |
7830 | indices[j] = indices[j - 2]; | |
7831 | indices[i] = low; | |
7832 | indices[i + 1] = high; | |
7833 | } | |
7834 | ||
7835 | static struct value * | |
ebf56fd3 | 7836 | ada_evaluate_subexp (struct type *expect_type, struct expression *exp, |
4c4b4cd2 | 7837 | int *pos, enum noside noside) |
14f9c5c9 AS |
7838 | { |
7839 | enum exp_opcode op; | |
14f9c5c9 AS |
7840 | int tem, tem2, tem3; |
7841 | int pc; | |
7842 | struct value *arg1 = NULL, *arg2 = NULL, *arg3; | |
7843 | struct type *type; | |
52ce6436 | 7844 | int nargs, oplen; |
d2e4a39e | 7845 | struct value **argvec; |
14f9c5c9 | 7846 | |
d2e4a39e AS |
7847 | pc = *pos; |
7848 | *pos += 1; | |
14f9c5c9 AS |
7849 | op = exp->elts[pc].opcode; |
7850 | ||
d2e4a39e | 7851 | switch (op) |
14f9c5c9 AS |
7852 | { |
7853 | default: | |
7854 | *pos -= 1; | |
d2e4a39e | 7855 | return |
4c4b4cd2 PH |
7856 | unwrap_value (evaluate_subexp_standard |
7857 | (expect_type, exp, pos, noside)); | |
7858 | ||
7859 | case OP_STRING: | |
7860 | { | |
76a01679 JB |
7861 | struct value *result; |
7862 | *pos -= 1; | |
7863 | result = evaluate_subexp_standard (expect_type, exp, pos, noside); | |
7864 | /* The result type will have code OP_STRING, bashed there from | |
7865 | OP_ARRAY. Bash it back. */ | |
df407dfe AC |
7866 | if (TYPE_CODE (value_type (result)) == TYPE_CODE_STRING) |
7867 | TYPE_CODE (value_type (result)) = TYPE_CODE_ARRAY; | |
76a01679 | 7868 | return result; |
4c4b4cd2 | 7869 | } |
14f9c5c9 AS |
7870 | |
7871 | case UNOP_CAST: | |
7872 | (*pos) += 2; | |
7873 | type = exp->elts[pc + 1].type; | |
7874 | arg1 = evaluate_subexp (type, exp, pos, noside); | |
7875 | if (noside == EVAL_SKIP) | |
4c4b4cd2 | 7876 | goto nosideret; |
df407dfe | 7877 | if (type != ada_check_typedef (value_type (arg1))) |
4c4b4cd2 PH |
7878 | { |
7879 | if (ada_is_fixed_point_type (type)) | |
7880 | arg1 = cast_to_fixed (type, arg1); | |
df407dfe | 7881 | else if (ada_is_fixed_point_type (value_type (arg1))) |
4c4b4cd2 PH |
7882 | arg1 = value_cast (type, cast_from_fixed_to_double (arg1)); |
7883 | else if (VALUE_LVAL (arg1) == lval_memory) | |
7884 | { | |
7885 | /* This is in case of the really obscure (and undocumented, | |
7886 | but apparently expected) case of (Foo) Bar.all, where Bar | |
7887 | is an integer constant and Foo is a dynamic-sized type. | |
7888 | If we don't do this, ARG1 will simply be relabeled with | |
7889 | TYPE. */ | |
7890 | if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
7891 | return value_zero (to_static_fixed_type (type), not_lval); | |
7892 | arg1 = | |
7893 | ada_to_fixed_value_create | |
df407dfe | 7894 | (type, VALUE_ADDRESS (arg1) + value_offset (arg1), 0); |
4c4b4cd2 PH |
7895 | } |
7896 | else | |
7897 | arg1 = value_cast (type, arg1); | |
7898 | } | |
14f9c5c9 AS |
7899 | return arg1; |
7900 | ||
4c4b4cd2 PH |
7901 | case UNOP_QUAL: |
7902 | (*pos) += 2; | |
7903 | type = exp->elts[pc + 1].type; | |
7904 | return ada_evaluate_subexp (type, exp, pos, noside); | |
7905 | ||
14f9c5c9 AS |
7906 | case BINOP_ASSIGN: |
7907 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
52ce6436 PH |
7908 | if (exp->elts[*pos].opcode == OP_AGGREGATE) |
7909 | { | |
7910 | arg1 = assign_aggregate (arg1, arg1, exp, pos, noside); | |
7911 | if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS) | |
7912 | return arg1; | |
7913 | return ada_value_assign (arg1, arg1); | |
7914 | } | |
df407dfe | 7915 | arg2 = evaluate_subexp (value_type (arg1), exp, pos, noside); |
14f9c5c9 | 7916 | if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS) |
4c4b4cd2 | 7917 | return arg1; |
df407dfe AC |
7918 | if (ada_is_fixed_point_type (value_type (arg1))) |
7919 | arg2 = cast_to_fixed (value_type (arg1), arg2); | |
7920 | else if (ada_is_fixed_point_type (value_type (arg2))) | |
76a01679 | 7921 | error |
323e0a4a | 7922 | (_("Fixed-point values must be assigned to fixed-point variables")); |
d2e4a39e | 7923 | else |
df407dfe | 7924 | arg2 = coerce_for_assign (value_type (arg1), arg2); |
4c4b4cd2 | 7925 | return ada_value_assign (arg1, arg2); |
14f9c5c9 AS |
7926 | |
7927 | case BINOP_ADD: | |
7928 | arg1 = evaluate_subexp_with_coercion (exp, pos, noside); | |
7929 | arg2 = evaluate_subexp_with_coercion (exp, pos, noside); | |
7930 | if (noside == EVAL_SKIP) | |
4c4b4cd2 | 7931 | goto nosideret; |
df407dfe AC |
7932 | if ((ada_is_fixed_point_type (value_type (arg1)) |
7933 | || ada_is_fixed_point_type (value_type (arg2))) | |
7934 | && value_type (arg1) != value_type (arg2)) | |
323e0a4a | 7935 | error (_("Operands of fixed-point addition must have the same type")); |
df407dfe | 7936 | return value_cast (value_type (arg1), value_add (arg1, arg2)); |
14f9c5c9 AS |
7937 | |
7938 | case BINOP_SUB: | |
7939 | arg1 = evaluate_subexp_with_coercion (exp, pos, noside); | |
7940 | arg2 = evaluate_subexp_with_coercion (exp, pos, noside); | |
7941 | if (noside == EVAL_SKIP) | |
4c4b4cd2 | 7942 | goto nosideret; |
df407dfe AC |
7943 | if ((ada_is_fixed_point_type (value_type (arg1)) |
7944 | || ada_is_fixed_point_type (value_type (arg2))) | |
7945 | && value_type (arg1) != value_type (arg2)) | |
323e0a4a | 7946 | error (_("Operands of fixed-point subtraction must have the same type")); |
df407dfe | 7947 | return value_cast (value_type (arg1), value_sub (arg1, arg2)); |
14f9c5c9 AS |
7948 | |
7949 | case BINOP_MUL: | |
7950 | case BINOP_DIV: | |
7951 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
7952 | arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
7953 | if (noside == EVAL_SKIP) | |
4c4b4cd2 PH |
7954 | goto nosideret; |
7955 | else if (noside == EVAL_AVOID_SIDE_EFFECTS | |
76a01679 | 7956 | && (op == BINOP_DIV || op == BINOP_REM || op == BINOP_MOD)) |
df407dfe | 7957 | return value_zero (value_type (arg1), not_lval); |
14f9c5c9 | 7958 | else |
4c4b4cd2 | 7959 | { |
df407dfe | 7960 | if (ada_is_fixed_point_type (value_type (arg1))) |
4c4b4cd2 | 7961 | arg1 = cast_from_fixed_to_double (arg1); |
df407dfe | 7962 | if (ada_is_fixed_point_type (value_type (arg2))) |
4c4b4cd2 PH |
7963 | arg2 = cast_from_fixed_to_double (arg2); |
7964 | return ada_value_binop (arg1, arg2, op); | |
7965 | } | |
7966 | ||
7967 | case BINOP_REM: | |
7968 | case BINOP_MOD: | |
7969 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
7970 | arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
7971 | if (noside == EVAL_SKIP) | |
76a01679 | 7972 | goto nosideret; |
4c4b4cd2 | 7973 | else if (noside == EVAL_AVOID_SIDE_EFFECTS |
76a01679 | 7974 | && (op == BINOP_DIV || op == BINOP_REM || op == BINOP_MOD)) |
df407dfe | 7975 | return value_zero (value_type (arg1), not_lval); |
14f9c5c9 | 7976 | else |
76a01679 | 7977 | return ada_value_binop (arg1, arg2, op); |
14f9c5c9 | 7978 | |
4c4b4cd2 PH |
7979 | case BINOP_EQUAL: |
7980 | case BINOP_NOTEQUAL: | |
14f9c5c9 | 7981 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); |
df407dfe | 7982 | arg2 = evaluate_subexp (value_type (arg1), exp, pos, noside); |
14f9c5c9 | 7983 | if (noside == EVAL_SKIP) |
76a01679 | 7984 | goto nosideret; |
4c4b4cd2 | 7985 | if (noside == EVAL_AVOID_SIDE_EFFECTS) |
76a01679 | 7986 | tem = 0; |
4c4b4cd2 | 7987 | else |
76a01679 | 7988 | tem = ada_value_equal (arg1, arg2); |
4c4b4cd2 | 7989 | if (op == BINOP_NOTEQUAL) |
76a01679 | 7990 | tem = !tem; |
4c4b4cd2 PH |
7991 | return value_from_longest (LA_BOOL_TYPE, (LONGEST) tem); |
7992 | ||
7993 | case UNOP_NEG: | |
7994 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
7995 | if (noside == EVAL_SKIP) | |
7996 | goto nosideret; | |
df407dfe AC |
7997 | else if (ada_is_fixed_point_type (value_type (arg1))) |
7998 | return value_cast (value_type (arg1), value_neg (arg1)); | |
14f9c5c9 | 7999 | else |
4c4b4cd2 PH |
8000 | return value_neg (arg1); |
8001 | ||
14f9c5c9 AS |
8002 | case OP_VAR_VALUE: |
8003 | *pos -= 1; | |
8004 | if (noside == EVAL_SKIP) | |
4c4b4cd2 PH |
8005 | { |
8006 | *pos += 4; | |
8007 | goto nosideret; | |
8008 | } | |
8009 | else if (SYMBOL_DOMAIN (exp->elts[pc + 2].symbol) == UNDEF_DOMAIN) | |
76a01679 JB |
8010 | /* Only encountered when an unresolved symbol occurs in a |
8011 | context other than a function call, in which case, it is | |
52ce6436 | 8012 | invalid. */ |
323e0a4a | 8013 | error (_("Unexpected unresolved symbol, %s, during evaluation"), |
4c4b4cd2 | 8014 | SYMBOL_PRINT_NAME (exp->elts[pc + 2].symbol)); |
14f9c5c9 | 8015 | else if (noside == EVAL_AVOID_SIDE_EFFECTS) |
4c4b4cd2 PH |
8016 | { |
8017 | *pos += 4; | |
8018 | return value_zero | |
8019 | (to_static_fixed_type | |
8020 | (static_unwrap_type (SYMBOL_TYPE (exp->elts[pc + 2].symbol))), | |
8021 | not_lval); | |
8022 | } | |
d2e4a39e | 8023 | else |
4c4b4cd2 PH |
8024 | { |
8025 | arg1 = | |
8026 | unwrap_value (evaluate_subexp_standard | |
8027 | (expect_type, exp, pos, noside)); | |
8028 | return ada_to_fixed_value (arg1); | |
8029 | } | |
8030 | ||
8031 | case OP_FUNCALL: | |
8032 | (*pos) += 2; | |
8033 | ||
8034 | /* Allocate arg vector, including space for the function to be | |
8035 | called in argvec[0] and a terminating NULL. */ | |
8036 | nargs = longest_to_int (exp->elts[pc + 1].longconst); | |
8037 | argvec = | |
8038 | (struct value **) alloca (sizeof (struct value *) * (nargs + 2)); | |
8039 | ||
8040 | if (exp->elts[*pos].opcode == OP_VAR_VALUE | |
76a01679 | 8041 | && SYMBOL_DOMAIN (exp->elts[pc + 5].symbol) == UNDEF_DOMAIN) |
323e0a4a | 8042 | error (_("Unexpected unresolved symbol, %s, during evaluation"), |
4c4b4cd2 PH |
8043 | SYMBOL_PRINT_NAME (exp->elts[pc + 5].symbol)); |
8044 | else | |
8045 | { | |
8046 | for (tem = 0; tem <= nargs; tem += 1) | |
8047 | argvec[tem] = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
8048 | argvec[tem] = 0; | |
8049 | ||
8050 | if (noside == EVAL_SKIP) | |
8051 | goto nosideret; | |
8052 | } | |
8053 | ||
df407dfe | 8054 | if (ada_is_packed_array_type (desc_base_type (value_type (argvec[0])))) |
4c4b4cd2 | 8055 | argvec[0] = ada_coerce_to_simple_array (argvec[0]); |
df407dfe AC |
8056 | else if (TYPE_CODE (value_type (argvec[0])) == TYPE_CODE_REF |
8057 | || (TYPE_CODE (value_type (argvec[0])) == TYPE_CODE_ARRAY | |
76a01679 | 8058 | && VALUE_LVAL (argvec[0]) == lval_memory)) |
4c4b4cd2 PH |
8059 | argvec[0] = value_addr (argvec[0]); |
8060 | ||
df407dfe | 8061 | type = ada_check_typedef (value_type (argvec[0])); |
4c4b4cd2 PH |
8062 | if (TYPE_CODE (type) == TYPE_CODE_PTR) |
8063 | { | |
61ee279c | 8064 | switch (TYPE_CODE (ada_check_typedef (TYPE_TARGET_TYPE (type)))) |
4c4b4cd2 PH |
8065 | { |
8066 | case TYPE_CODE_FUNC: | |
61ee279c | 8067 | type = ada_check_typedef (TYPE_TARGET_TYPE (type)); |
4c4b4cd2 PH |
8068 | break; |
8069 | case TYPE_CODE_ARRAY: | |
8070 | break; | |
8071 | case TYPE_CODE_STRUCT: | |
8072 | if (noside != EVAL_AVOID_SIDE_EFFECTS) | |
8073 | argvec[0] = ada_value_ind (argvec[0]); | |
61ee279c | 8074 | type = ada_check_typedef (TYPE_TARGET_TYPE (type)); |
4c4b4cd2 PH |
8075 | break; |
8076 | default: | |
323e0a4a | 8077 | error (_("cannot subscript or call something of type `%s'"), |
df407dfe | 8078 | ada_type_name (value_type (argvec[0]))); |
4c4b4cd2 PH |
8079 | break; |
8080 | } | |
8081 | } | |
8082 | ||
8083 | switch (TYPE_CODE (type)) | |
8084 | { | |
8085 | case TYPE_CODE_FUNC: | |
8086 | if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
8087 | return allocate_value (TYPE_TARGET_TYPE (type)); | |
8088 | return call_function_by_hand (argvec[0], nargs, argvec + 1); | |
8089 | case TYPE_CODE_STRUCT: | |
8090 | { | |
8091 | int arity; | |
8092 | ||
4c4b4cd2 PH |
8093 | arity = ada_array_arity (type); |
8094 | type = ada_array_element_type (type, nargs); | |
8095 | if (type == NULL) | |
323e0a4a | 8096 | error (_("cannot subscript or call a record")); |
4c4b4cd2 | 8097 | if (arity != nargs) |
323e0a4a | 8098 | error (_("wrong number of subscripts; expecting %d"), arity); |
4c4b4cd2 PH |
8099 | if (noside == EVAL_AVOID_SIDE_EFFECTS) |
8100 | return allocate_value (ada_aligned_type (type)); | |
8101 | return | |
8102 | unwrap_value (ada_value_subscript | |
8103 | (argvec[0], nargs, argvec + 1)); | |
8104 | } | |
8105 | case TYPE_CODE_ARRAY: | |
8106 | if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
8107 | { | |
8108 | type = ada_array_element_type (type, nargs); | |
8109 | if (type == NULL) | |
323e0a4a | 8110 | error (_("element type of array unknown")); |
4c4b4cd2 PH |
8111 | else |
8112 | return allocate_value (ada_aligned_type (type)); | |
8113 | } | |
8114 | return | |
8115 | unwrap_value (ada_value_subscript | |
8116 | (ada_coerce_to_simple_array (argvec[0]), | |
8117 | nargs, argvec + 1)); | |
8118 | case TYPE_CODE_PTR: /* Pointer to array */ | |
8119 | type = to_fixed_array_type (TYPE_TARGET_TYPE (type), NULL, 1); | |
8120 | if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
8121 | { | |
8122 | type = ada_array_element_type (type, nargs); | |
8123 | if (type == NULL) | |
323e0a4a | 8124 | error (_("element type of array unknown")); |
4c4b4cd2 PH |
8125 | else |
8126 | return allocate_value (ada_aligned_type (type)); | |
8127 | } | |
8128 | return | |
8129 | unwrap_value (ada_value_ptr_subscript (argvec[0], type, | |
8130 | nargs, argvec + 1)); | |
8131 | ||
8132 | default: | |
e1d5a0d2 PH |
8133 | error (_("Attempt to index or call something other than an " |
8134 | "array or function")); | |
4c4b4cd2 PH |
8135 | } |
8136 | ||
8137 | case TERNOP_SLICE: | |
8138 | { | |
8139 | struct value *array = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
8140 | struct value *low_bound_val = | |
8141 | evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
714e53ab PH |
8142 | struct value *high_bound_val = |
8143 | evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
8144 | LONGEST low_bound; | |
8145 | LONGEST high_bound; | |
994b9211 AC |
8146 | low_bound_val = coerce_ref (low_bound_val); |
8147 | high_bound_val = coerce_ref (high_bound_val); | |
714e53ab PH |
8148 | low_bound = pos_atr (low_bound_val); |
8149 | high_bound = pos_atr (high_bound_val); | |
963a6417 | 8150 | |
4c4b4cd2 PH |
8151 | if (noside == EVAL_SKIP) |
8152 | goto nosideret; | |
8153 | ||
4c4b4cd2 PH |
8154 | /* If this is a reference to an aligner type, then remove all |
8155 | the aligners. */ | |
df407dfe AC |
8156 | if (TYPE_CODE (value_type (array)) == TYPE_CODE_REF |
8157 | && ada_is_aligner_type (TYPE_TARGET_TYPE (value_type (array)))) | |
8158 | TYPE_TARGET_TYPE (value_type (array)) = | |
8159 | ada_aligned_type (TYPE_TARGET_TYPE (value_type (array))); | |
4c4b4cd2 | 8160 | |
df407dfe | 8161 | if (ada_is_packed_array_type (value_type (array))) |
323e0a4a | 8162 | error (_("cannot slice a packed array")); |
4c4b4cd2 PH |
8163 | |
8164 | /* If this is a reference to an array or an array lvalue, | |
8165 | convert to a pointer. */ | |
df407dfe AC |
8166 | if (TYPE_CODE (value_type (array)) == TYPE_CODE_REF |
8167 | || (TYPE_CODE (value_type (array)) == TYPE_CODE_ARRAY | |
4c4b4cd2 PH |
8168 | && VALUE_LVAL (array) == lval_memory)) |
8169 | array = value_addr (array); | |
8170 | ||
1265e4aa | 8171 | if (noside == EVAL_AVOID_SIDE_EFFECTS |
61ee279c | 8172 | && ada_is_array_descriptor_type (ada_check_typedef |
df407dfe | 8173 | (value_type (array)))) |
0b5d8877 | 8174 | return empty_array (ada_type_of_array (array, 0), low_bound); |
4c4b4cd2 PH |
8175 | |
8176 | array = ada_coerce_to_simple_array_ptr (array); | |
8177 | ||
714e53ab PH |
8178 | /* If we have more than one level of pointer indirection, |
8179 | dereference the value until we get only one level. */ | |
df407dfe AC |
8180 | while (TYPE_CODE (value_type (array)) == TYPE_CODE_PTR |
8181 | && (TYPE_CODE (TYPE_TARGET_TYPE (value_type (array))) | |
714e53ab PH |
8182 | == TYPE_CODE_PTR)) |
8183 | array = value_ind (array); | |
8184 | ||
8185 | /* Make sure we really do have an array type before going further, | |
8186 | to avoid a SEGV when trying to get the index type or the target | |
8187 | type later down the road if the debug info generated by | |
8188 | the compiler is incorrect or incomplete. */ | |
df407dfe | 8189 | if (!ada_is_simple_array_type (value_type (array))) |
323e0a4a | 8190 | error (_("cannot take slice of non-array")); |
714e53ab | 8191 | |
df407dfe | 8192 | if (TYPE_CODE (value_type (array)) == TYPE_CODE_PTR) |
4c4b4cd2 | 8193 | { |
0b5d8877 | 8194 | if (high_bound < low_bound || noside == EVAL_AVOID_SIDE_EFFECTS) |
df407dfe | 8195 | return empty_array (TYPE_TARGET_TYPE (value_type (array)), |
4c4b4cd2 PH |
8196 | low_bound); |
8197 | else | |
8198 | { | |
8199 | struct type *arr_type0 = | |
df407dfe | 8200 | to_fixed_array_type (TYPE_TARGET_TYPE (value_type (array)), |
4c4b4cd2 | 8201 | NULL, 1); |
0b5d8877 | 8202 | return ada_value_slice_ptr (array, arr_type0, |
529cad9c PH |
8203 | longest_to_int (low_bound), |
8204 | longest_to_int (high_bound)); | |
4c4b4cd2 PH |
8205 | } |
8206 | } | |
8207 | else if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
8208 | return array; | |
8209 | else if (high_bound < low_bound) | |
df407dfe | 8210 | return empty_array (value_type (array), low_bound); |
4c4b4cd2 | 8211 | else |
529cad9c PH |
8212 | return ada_value_slice (array, longest_to_int (low_bound), |
8213 | longest_to_int (high_bound)); | |
4c4b4cd2 | 8214 | } |
14f9c5c9 | 8215 | |
4c4b4cd2 PH |
8216 | case UNOP_IN_RANGE: |
8217 | (*pos) += 2; | |
8218 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
8219 | type = exp->elts[pc + 1].type; | |
14f9c5c9 | 8220 | |
14f9c5c9 | 8221 | if (noside == EVAL_SKIP) |
4c4b4cd2 | 8222 | goto nosideret; |
14f9c5c9 | 8223 | |
4c4b4cd2 PH |
8224 | switch (TYPE_CODE (type)) |
8225 | { | |
8226 | default: | |
e1d5a0d2 PH |
8227 | lim_warning (_("Membership test incompletely implemented; " |
8228 | "always returns true")); | |
4c4b4cd2 PH |
8229 | return value_from_longest (builtin_type_int, (LONGEST) 1); |
8230 | ||
8231 | case TYPE_CODE_RANGE: | |
76a01679 | 8232 | arg2 = value_from_longest (builtin_type_int, TYPE_LOW_BOUND (type)); |
4c4b4cd2 PH |
8233 | arg3 = value_from_longest (builtin_type_int, |
8234 | TYPE_HIGH_BOUND (type)); | |
8235 | return | |
8236 | value_from_longest (builtin_type_int, | |
8237 | (value_less (arg1, arg3) | |
8238 | || value_equal (arg1, arg3)) | |
8239 | && (value_less (arg2, arg1) | |
8240 | || value_equal (arg2, arg1))); | |
8241 | } | |
8242 | ||
8243 | case BINOP_IN_BOUNDS: | |
14f9c5c9 | 8244 | (*pos) += 2; |
4c4b4cd2 PH |
8245 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); |
8246 | arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
14f9c5c9 | 8247 | |
4c4b4cd2 PH |
8248 | if (noside == EVAL_SKIP) |
8249 | goto nosideret; | |
14f9c5c9 | 8250 | |
4c4b4cd2 PH |
8251 | if (noside == EVAL_AVOID_SIDE_EFFECTS) |
8252 | return value_zero (builtin_type_int, not_lval); | |
14f9c5c9 | 8253 | |
4c4b4cd2 | 8254 | tem = longest_to_int (exp->elts[pc + 1].longconst); |
14f9c5c9 | 8255 | |
df407dfe | 8256 | if (tem < 1 || tem > ada_array_arity (value_type (arg2))) |
323e0a4a | 8257 | error (_("invalid dimension number to 'range")); |
14f9c5c9 | 8258 | |
4c4b4cd2 PH |
8259 | arg3 = ada_array_bound (arg2, tem, 1); |
8260 | arg2 = ada_array_bound (arg2, tem, 0); | |
d2e4a39e | 8261 | |
4c4b4cd2 PH |
8262 | return |
8263 | value_from_longest (builtin_type_int, | |
8264 | (value_less (arg1, arg3) | |
8265 | || value_equal (arg1, arg3)) | |
8266 | && (value_less (arg2, arg1) | |
8267 | || value_equal (arg2, arg1))); | |
8268 | ||
8269 | case TERNOP_IN_RANGE: | |
8270 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
8271 | arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
8272 | arg3 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
8273 | ||
8274 | if (noside == EVAL_SKIP) | |
8275 | goto nosideret; | |
8276 | ||
8277 | return | |
8278 | value_from_longest (builtin_type_int, | |
8279 | (value_less (arg1, arg3) | |
8280 | || value_equal (arg1, arg3)) | |
8281 | && (value_less (arg2, arg1) | |
8282 | || value_equal (arg2, arg1))); | |
8283 | ||
8284 | case OP_ATR_FIRST: | |
8285 | case OP_ATR_LAST: | |
8286 | case OP_ATR_LENGTH: | |
8287 | { | |
76a01679 JB |
8288 | struct type *type_arg; |
8289 | if (exp->elts[*pos].opcode == OP_TYPE) | |
8290 | { | |
8291 | evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP); | |
8292 | arg1 = NULL; | |
8293 | type_arg = exp->elts[pc + 2].type; | |
8294 | } | |
8295 | else | |
8296 | { | |
8297 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
8298 | type_arg = NULL; | |
8299 | } | |
8300 | ||
8301 | if (exp->elts[*pos].opcode != OP_LONG) | |
323e0a4a | 8302 | error (_("Invalid operand to '%s"), ada_attribute_name (op)); |
76a01679 JB |
8303 | tem = longest_to_int (exp->elts[*pos + 2].longconst); |
8304 | *pos += 4; | |
8305 | ||
8306 | if (noside == EVAL_SKIP) | |
8307 | goto nosideret; | |
8308 | ||
8309 | if (type_arg == NULL) | |
8310 | { | |
8311 | arg1 = ada_coerce_ref (arg1); | |
8312 | ||
df407dfe | 8313 | if (ada_is_packed_array_type (value_type (arg1))) |
76a01679 JB |
8314 | arg1 = ada_coerce_to_simple_array (arg1); |
8315 | ||
df407dfe | 8316 | if (tem < 1 || tem > ada_array_arity (value_type (arg1))) |
323e0a4a | 8317 | error (_("invalid dimension number to '%s"), |
76a01679 JB |
8318 | ada_attribute_name (op)); |
8319 | ||
8320 | if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
8321 | { | |
df407dfe | 8322 | type = ada_index_type (value_type (arg1), tem); |
76a01679 JB |
8323 | if (type == NULL) |
8324 | error | |
323e0a4a | 8325 | (_("attempt to take bound of something that is not an array")); |
76a01679 JB |
8326 | return allocate_value (type); |
8327 | } | |
8328 | ||
8329 | switch (op) | |
8330 | { | |
8331 | default: /* Should never happen. */ | |
323e0a4a | 8332 | error (_("unexpected attribute encountered")); |
76a01679 JB |
8333 | case OP_ATR_FIRST: |
8334 | return ada_array_bound (arg1, tem, 0); | |
8335 | case OP_ATR_LAST: | |
8336 | return ada_array_bound (arg1, tem, 1); | |
8337 | case OP_ATR_LENGTH: | |
8338 | return ada_array_length (arg1, tem); | |
8339 | } | |
8340 | } | |
8341 | else if (discrete_type_p (type_arg)) | |
8342 | { | |
8343 | struct type *range_type; | |
8344 | char *name = ada_type_name (type_arg); | |
8345 | range_type = NULL; | |
8346 | if (name != NULL && TYPE_CODE (type_arg) != TYPE_CODE_ENUM) | |
8347 | range_type = | |
8348 | to_fixed_range_type (name, NULL, TYPE_OBJFILE (type_arg)); | |
8349 | if (range_type == NULL) | |
8350 | range_type = type_arg; | |
8351 | switch (op) | |
8352 | { | |
8353 | default: | |
323e0a4a | 8354 | error (_("unexpected attribute encountered")); |
76a01679 JB |
8355 | case OP_ATR_FIRST: |
8356 | return discrete_type_low_bound (range_type); | |
8357 | case OP_ATR_LAST: | |
8358 | return discrete_type_high_bound (range_type); | |
8359 | case OP_ATR_LENGTH: | |
323e0a4a | 8360 | error (_("the 'length attribute applies only to array types")); |
76a01679 JB |
8361 | } |
8362 | } | |
8363 | else if (TYPE_CODE (type_arg) == TYPE_CODE_FLT) | |
323e0a4a | 8364 | error (_("unimplemented type attribute")); |
76a01679 JB |
8365 | else |
8366 | { | |
8367 | LONGEST low, high; | |
8368 | ||
8369 | if (ada_is_packed_array_type (type_arg)) | |
8370 | type_arg = decode_packed_array_type (type_arg); | |
8371 | ||
8372 | if (tem < 1 || tem > ada_array_arity (type_arg)) | |
323e0a4a | 8373 | error (_("invalid dimension number to '%s"), |
76a01679 JB |
8374 | ada_attribute_name (op)); |
8375 | ||
8376 | type = ada_index_type (type_arg, tem); | |
8377 | if (type == NULL) | |
8378 | error | |
323e0a4a | 8379 | (_("attempt to take bound of something that is not an array")); |
76a01679 JB |
8380 | if (noside == EVAL_AVOID_SIDE_EFFECTS) |
8381 | return allocate_value (type); | |
8382 | ||
8383 | switch (op) | |
8384 | { | |
8385 | default: | |
323e0a4a | 8386 | error (_("unexpected attribute encountered")); |
76a01679 JB |
8387 | case OP_ATR_FIRST: |
8388 | low = ada_array_bound_from_type (type_arg, tem, 0, &type); | |
8389 | return value_from_longest (type, low); | |
8390 | case OP_ATR_LAST: | |
8391 | high = ada_array_bound_from_type (type_arg, tem, 1, &type); | |
8392 | return value_from_longest (type, high); | |
8393 | case OP_ATR_LENGTH: | |
8394 | low = ada_array_bound_from_type (type_arg, tem, 0, &type); | |
8395 | high = ada_array_bound_from_type (type_arg, tem, 1, NULL); | |
8396 | return value_from_longest (type, high - low + 1); | |
8397 | } | |
8398 | } | |
14f9c5c9 AS |
8399 | } |
8400 | ||
4c4b4cd2 PH |
8401 | case OP_ATR_TAG: |
8402 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
8403 | if (noside == EVAL_SKIP) | |
76a01679 | 8404 | goto nosideret; |
4c4b4cd2 PH |
8405 | |
8406 | if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
76a01679 | 8407 | return value_zero (ada_tag_type (arg1), not_lval); |
4c4b4cd2 PH |
8408 | |
8409 | return ada_value_tag (arg1); | |
8410 | ||
8411 | case OP_ATR_MIN: | |
8412 | case OP_ATR_MAX: | |
8413 | evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP); | |
14f9c5c9 AS |
8414 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); |
8415 | arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
8416 | if (noside == EVAL_SKIP) | |
76a01679 | 8417 | goto nosideret; |
d2e4a39e | 8418 | else if (noside == EVAL_AVOID_SIDE_EFFECTS) |
df407dfe | 8419 | return value_zero (value_type (arg1), not_lval); |
14f9c5c9 | 8420 | else |
76a01679 JB |
8421 | return value_binop (arg1, arg2, |
8422 | op == OP_ATR_MIN ? BINOP_MIN : BINOP_MAX); | |
14f9c5c9 | 8423 | |
4c4b4cd2 PH |
8424 | case OP_ATR_MODULUS: |
8425 | { | |
76a01679 JB |
8426 | struct type *type_arg = exp->elts[pc + 2].type; |
8427 | evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP); | |
4c4b4cd2 | 8428 | |
76a01679 JB |
8429 | if (noside == EVAL_SKIP) |
8430 | goto nosideret; | |
4c4b4cd2 | 8431 | |
76a01679 | 8432 | if (!ada_is_modular_type (type_arg)) |
323e0a4a | 8433 | error (_("'modulus must be applied to modular type")); |
4c4b4cd2 | 8434 | |
76a01679 JB |
8435 | return value_from_longest (TYPE_TARGET_TYPE (type_arg), |
8436 | ada_modulus (type_arg)); | |
4c4b4cd2 PH |
8437 | } |
8438 | ||
8439 | ||
8440 | case OP_ATR_POS: | |
8441 | evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP); | |
14f9c5c9 AS |
8442 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); |
8443 | if (noside == EVAL_SKIP) | |
76a01679 | 8444 | goto nosideret; |
4c4b4cd2 | 8445 | else if (noside == EVAL_AVOID_SIDE_EFFECTS) |
72d5681a | 8446 | return value_zero (builtin_type_int, not_lval); |
14f9c5c9 | 8447 | else |
76a01679 | 8448 | return value_pos_atr (arg1); |
14f9c5c9 | 8449 | |
4c4b4cd2 PH |
8450 | case OP_ATR_SIZE: |
8451 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
8452 | if (noside == EVAL_SKIP) | |
76a01679 | 8453 | goto nosideret; |
4c4b4cd2 | 8454 | else if (noside == EVAL_AVOID_SIDE_EFFECTS) |
72d5681a | 8455 | return value_zero (builtin_type_int, not_lval); |
4c4b4cd2 | 8456 | else |
72d5681a | 8457 | return value_from_longest (builtin_type_int, |
76a01679 | 8458 | TARGET_CHAR_BIT |
df407dfe | 8459 | * TYPE_LENGTH (value_type (arg1))); |
4c4b4cd2 PH |
8460 | |
8461 | case OP_ATR_VAL: | |
8462 | evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP); | |
14f9c5c9 | 8463 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); |
4c4b4cd2 | 8464 | type = exp->elts[pc + 2].type; |
14f9c5c9 | 8465 | if (noside == EVAL_SKIP) |
76a01679 | 8466 | goto nosideret; |
4c4b4cd2 | 8467 | else if (noside == EVAL_AVOID_SIDE_EFFECTS) |
76a01679 | 8468 | return value_zero (type, not_lval); |
4c4b4cd2 | 8469 | else |
76a01679 | 8470 | return value_val_atr (type, arg1); |
4c4b4cd2 PH |
8471 | |
8472 | case BINOP_EXP: | |
8473 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
8474 | arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
8475 | if (noside == EVAL_SKIP) | |
8476 | goto nosideret; | |
8477 | else if (noside == EVAL_AVOID_SIDE_EFFECTS) | |
df407dfe | 8478 | return value_zero (value_type (arg1), not_lval); |
4c4b4cd2 PH |
8479 | else |
8480 | return value_binop (arg1, arg2, op); | |
8481 | ||
8482 | case UNOP_PLUS: | |
8483 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
8484 | if (noside == EVAL_SKIP) | |
8485 | goto nosideret; | |
8486 | else | |
8487 | return arg1; | |
8488 | ||
8489 | case UNOP_ABS: | |
8490 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
8491 | if (noside == EVAL_SKIP) | |
8492 | goto nosideret; | |
df407dfe | 8493 | if (value_less (arg1, value_zero (value_type (arg1), not_lval))) |
4c4b4cd2 | 8494 | return value_neg (arg1); |
14f9c5c9 | 8495 | else |
4c4b4cd2 | 8496 | return arg1; |
14f9c5c9 AS |
8497 | |
8498 | case UNOP_IND: | |
8499 | if (expect_type && TYPE_CODE (expect_type) == TYPE_CODE_PTR) | |
61ee279c | 8500 | expect_type = TYPE_TARGET_TYPE (ada_check_typedef (expect_type)); |
14f9c5c9 AS |
8501 | arg1 = evaluate_subexp (expect_type, exp, pos, noside); |
8502 | if (noside == EVAL_SKIP) | |
4c4b4cd2 | 8503 | goto nosideret; |
df407dfe | 8504 | type = ada_check_typedef (value_type (arg1)); |
14f9c5c9 | 8505 | if (noside == EVAL_AVOID_SIDE_EFFECTS) |
4c4b4cd2 PH |
8506 | { |
8507 | if (ada_is_array_descriptor_type (type)) | |
8508 | /* GDB allows dereferencing GNAT array descriptors. */ | |
8509 | { | |
8510 | struct type *arrType = ada_type_of_array (arg1, 0); | |
8511 | if (arrType == NULL) | |
323e0a4a | 8512 | error (_("Attempt to dereference null array pointer.")); |
00a4c844 | 8513 | return value_at_lazy (arrType, 0); |
4c4b4cd2 PH |
8514 | } |
8515 | else if (TYPE_CODE (type) == TYPE_CODE_PTR | |
8516 | || TYPE_CODE (type) == TYPE_CODE_REF | |
8517 | /* In C you can dereference an array to get the 1st elt. */ | |
8518 | || TYPE_CODE (type) == TYPE_CODE_ARRAY) | |
714e53ab PH |
8519 | { |
8520 | type = to_static_fixed_type | |
8521 | (ada_aligned_type | |
8522 | (ada_check_typedef (TYPE_TARGET_TYPE (type)))); | |
8523 | check_size (type); | |
8524 | return value_zero (type, lval_memory); | |
8525 | } | |
4c4b4cd2 PH |
8526 | else if (TYPE_CODE (type) == TYPE_CODE_INT) |
8527 | /* GDB allows dereferencing an int. */ | |
8528 | return value_zero (builtin_type_int, lval_memory); | |
8529 | else | |
323e0a4a | 8530 | error (_("Attempt to take contents of a non-pointer value.")); |
4c4b4cd2 | 8531 | } |
76a01679 | 8532 | arg1 = ada_coerce_ref (arg1); /* FIXME: What is this for?? */ |
df407dfe | 8533 | type = ada_check_typedef (value_type (arg1)); |
d2e4a39e | 8534 | |
4c4b4cd2 PH |
8535 | if (ada_is_array_descriptor_type (type)) |
8536 | /* GDB allows dereferencing GNAT array descriptors. */ | |
8537 | return ada_coerce_to_simple_array (arg1); | |
14f9c5c9 | 8538 | else |
4c4b4cd2 | 8539 | return ada_value_ind (arg1); |
14f9c5c9 AS |
8540 | |
8541 | case STRUCTOP_STRUCT: | |
8542 | tem = longest_to_int (exp->elts[pc + 1].longconst); | |
8543 | (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1); | |
8544 | arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); | |
8545 | if (noside == EVAL_SKIP) | |
4c4b4cd2 | 8546 | goto nosideret; |
14f9c5c9 | 8547 | if (noside == EVAL_AVOID_SIDE_EFFECTS) |
76a01679 | 8548 | { |
df407dfe | 8549 | struct type *type1 = value_type (arg1); |
76a01679 JB |
8550 | if (ada_is_tagged_type (type1, 1)) |
8551 | { | |
8552 | type = ada_lookup_struct_elt_type (type1, | |
8553 | &exp->elts[pc + 2].string, | |
8554 | 1, 1, NULL); | |
8555 | if (type == NULL) | |
8556 | /* In this case, we assume that the field COULD exist | |
8557 | in some extension of the type. Return an object of | |
8558 | "type" void, which will match any formal | |
8559 | (see ada_type_match). */ | |
8560 | return value_zero (builtin_type_void, lval_memory); | |
8561 | } | |
8562 | else | |
8563 | type = | |
8564 | ada_lookup_struct_elt_type (type1, &exp->elts[pc + 2].string, 1, | |
8565 | 0, NULL); | |
8566 | ||
8567 | return value_zero (ada_aligned_type (type), lval_memory); | |
8568 | } | |
14f9c5c9 | 8569 | else |
76a01679 JB |
8570 | return |
8571 | ada_to_fixed_value (unwrap_value | |
8572 | (ada_value_struct_elt | |
03ee6b2e | 8573 | (arg1, &exp->elts[pc + 2].string, 0))); |
14f9c5c9 | 8574 | case OP_TYPE: |
4c4b4cd2 PH |
8575 | /* The value is not supposed to be used. This is here to make it |
8576 | easier to accommodate expressions that contain types. */ | |
14f9c5c9 AS |
8577 | (*pos) += 2; |
8578 | if (noside == EVAL_SKIP) | |
4c4b4cd2 | 8579 | goto nosideret; |
14f9c5c9 | 8580 | else if (noside == EVAL_AVOID_SIDE_EFFECTS) |
a6cfbe68 | 8581 | return allocate_value (exp->elts[pc + 1].type); |
14f9c5c9 | 8582 | else |
323e0a4a | 8583 | error (_("Attempt to use a type name as an expression")); |
52ce6436 PH |
8584 | |
8585 | case OP_AGGREGATE: | |
8586 | case OP_CHOICES: | |
8587 | case OP_OTHERS: | |
8588 | case OP_DISCRETE_RANGE: | |
8589 | case OP_POSITIONAL: | |
8590 | case OP_NAME: | |
8591 | if (noside == EVAL_NORMAL) | |
8592 | switch (op) | |
8593 | { | |
8594 | case OP_NAME: | |
8595 | error (_("Undefined name, ambiguous name, or renaming used in " | |
e1d5a0d2 | 8596 | "component association: %s."), &exp->elts[pc+2].string); |
52ce6436 PH |
8597 | case OP_AGGREGATE: |
8598 | error (_("Aggregates only allowed on the right of an assignment")); | |
8599 | default: | |
e1d5a0d2 | 8600 | internal_error (__FILE__, __LINE__, _("aggregate apparently mangled")); |
52ce6436 PH |
8601 | } |
8602 | ||
8603 | ada_forward_operator_length (exp, pc, &oplen, &nargs); | |
8604 | *pos += oplen - 1; | |
8605 | for (tem = 0; tem < nargs; tem += 1) | |
8606 | ada_evaluate_subexp (NULL, exp, pos, noside); | |
8607 | goto nosideret; | |
14f9c5c9 AS |
8608 | } |
8609 | ||
8610 | nosideret: | |
8611 | return value_from_longest (builtin_type_long, (LONGEST) 1); | |
8612 | } | |
14f9c5c9 | 8613 | \f |
d2e4a39e | 8614 | |
4c4b4cd2 | 8615 | /* Fixed point */ |
14f9c5c9 AS |
8616 | |
8617 | /* If TYPE encodes an Ada fixed-point type, return the suffix of the | |
8618 | type name that encodes the 'small and 'delta information. | |
4c4b4cd2 | 8619 | Otherwise, return NULL. */ |
14f9c5c9 | 8620 | |
d2e4a39e | 8621 | static const char * |
ebf56fd3 | 8622 | fixed_type_info (struct type *type) |
14f9c5c9 | 8623 | { |
d2e4a39e | 8624 | const char *name = ada_type_name (type); |
14f9c5c9 AS |
8625 | enum type_code code = (type == NULL) ? TYPE_CODE_UNDEF : TYPE_CODE (type); |
8626 | ||
d2e4a39e AS |
8627 | if ((code == TYPE_CODE_INT || code == TYPE_CODE_RANGE) && name != NULL) |
8628 | { | |
14f9c5c9 AS |
8629 | const char *tail = strstr (name, "___XF_"); |
8630 | if (tail == NULL) | |
4c4b4cd2 | 8631 | return NULL; |
d2e4a39e | 8632 | else |
4c4b4cd2 | 8633 | return tail + 5; |
14f9c5c9 AS |
8634 | } |
8635 | else if (code == TYPE_CODE_RANGE && TYPE_TARGET_TYPE (type) != type) | |
8636 | return fixed_type_info (TYPE_TARGET_TYPE (type)); | |
8637 | else | |
8638 | return NULL; | |
8639 | } | |
8640 | ||
4c4b4cd2 | 8641 | /* Returns non-zero iff TYPE represents an Ada fixed-point type. */ |
14f9c5c9 AS |
8642 | |
8643 | int | |
ebf56fd3 | 8644 | ada_is_fixed_point_type (struct type *type) |
14f9c5c9 AS |
8645 | { |
8646 | return fixed_type_info (type) != NULL; | |
8647 | } | |
8648 | ||
4c4b4cd2 PH |
8649 | /* Return non-zero iff TYPE represents a System.Address type. */ |
8650 | ||
8651 | int | |
8652 | ada_is_system_address_type (struct type *type) | |
8653 | { | |
8654 | return (TYPE_NAME (type) | |
8655 | && strcmp (TYPE_NAME (type), "system__address") == 0); | |
8656 | } | |
8657 | ||
14f9c5c9 AS |
8658 | /* Assuming that TYPE is the representation of an Ada fixed-point |
8659 | type, return its delta, or -1 if the type is malformed and the | |
4c4b4cd2 | 8660 | delta cannot be determined. */ |
14f9c5c9 AS |
8661 | |
8662 | DOUBLEST | |
ebf56fd3 | 8663 | ada_delta (struct type *type) |
14f9c5c9 AS |
8664 | { |
8665 | const char *encoding = fixed_type_info (type); | |
8666 | long num, den; | |
8667 | ||
8668 | if (sscanf (encoding, "_%ld_%ld", &num, &den) < 2) | |
8669 | return -1.0; | |
d2e4a39e | 8670 | else |
14f9c5c9 AS |
8671 | return (DOUBLEST) num / (DOUBLEST) den; |
8672 | } | |
8673 | ||
8674 | /* Assuming that ada_is_fixed_point_type (TYPE), return the scaling | |
4c4b4cd2 | 8675 | factor ('SMALL value) associated with the type. */ |
14f9c5c9 AS |
8676 | |
8677 | static DOUBLEST | |
ebf56fd3 | 8678 | scaling_factor (struct type *type) |
14f9c5c9 AS |
8679 | { |
8680 | const char *encoding = fixed_type_info (type); | |
8681 | unsigned long num0, den0, num1, den1; | |
8682 | int n; | |
d2e4a39e | 8683 | |
14f9c5c9 AS |
8684 | n = sscanf (encoding, "_%lu_%lu_%lu_%lu", &num0, &den0, &num1, &den1); |
8685 | ||
8686 | if (n < 2) | |
8687 | return 1.0; | |
8688 | else if (n == 4) | |
8689 | return (DOUBLEST) num1 / (DOUBLEST) den1; | |
d2e4a39e | 8690 | else |
14f9c5c9 AS |
8691 | return (DOUBLEST) num0 / (DOUBLEST) den0; |
8692 | } | |
8693 | ||
8694 | ||
8695 | /* Assuming that X is the representation of a value of fixed-point | |
4c4b4cd2 | 8696 | type TYPE, return its floating-point equivalent. */ |
14f9c5c9 AS |
8697 | |
8698 | DOUBLEST | |
ebf56fd3 | 8699 | ada_fixed_to_float (struct type *type, LONGEST x) |
14f9c5c9 | 8700 | { |
d2e4a39e | 8701 | return (DOUBLEST) x *scaling_factor (type); |
14f9c5c9 AS |
8702 | } |
8703 | ||
4c4b4cd2 PH |
8704 | /* The representation of a fixed-point value of type TYPE |
8705 | corresponding to the value X. */ | |
14f9c5c9 AS |
8706 | |
8707 | LONGEST | |
ebf56fd3 | 8708 | ada_float_to_fixed (struct type *type, DOUBLEST x) |
14f9c5c9 AS |
8709 | { |
8710 | return (LONGEST) (x / scaling_factor (type) + 0.5); | |
8711 | } | |
8712 | ||
8713 | ||
4c4b4cd2 | 8714 | /* VAX floating formats */ |
14f9c5c9 AS |
8715 | |
8716 | /* Non-zero iff TYPE represents one of the special VAX floating-point | |
4c4b4cd2 PH |
8717 | types. */ |
8718 | ||
14f9c5c9 | 8719 | int |
d2e4a39e | 8720 | ada_is_vax_floating_type (struct type *type) |
14f9c5c9 | 8721 | { |
d2e4a39e | 8722 | int name_len = |
14f9c5c9 | 8723 | (ada_type_name (type) == NULL) ? 0 : strlen (ada_type_name (type)); |
d2e4a39e | 8724 | return |
14f9c5c9 | 8725 | name_len > 6 |
d2e4a39e | 8726 | && (TYPE_CODE (type) == TYPE_CODE_INT |
4c4b4cd2 PH |
8727 | || TYPE_CODE (type) == TYPE_CODE_RANGE) |
8728 | && strncmp (ada_type_name (type) + name_len - 6, "___XF", 5) == 0; | |
14f9c5c9 AS |
8729 | } |
8730 | ||
8731 | /* The type of special VAX floating-point type this is, assuming | |
4c4b4cd2 PH |
8732 | ada_is_vax_floating_point. */ |
8733 | ||
14f9c5c9 | 8734 | int |
d2e4a39e | 8735 | ada_vax_float_type_suffix (struct type *type) |
14f9c5c9 | 8736 | { |
d2e4a39e | 8737 | return ada_type_name (type)[strlen (ada_type_name (type)) - 1]; |
14f9c5c9 AS |
8738 | } |
8739 | ||
4c4b4cd2 | 8740 | /* A value representing the special debugging function that outputs |
14f9c5c9 | 8741 | VAX floating-point values of the type represented by TYPE. Assumes |
4c4b4cd2 PH |
8742 | ada_is_vax_floating_type (TYPE). */ |
8743 | ||
d2e4a39e AS |
8744 | struct value * |
8745 | ada_vax_float_print_function (struct type *type) | |
8746 | { | |
8747 | switch (ada_vax_float_type_suffix (type)) | |
8748 | { | |
8749 | case 'F': | |
8750 | return get_var_value ("DEBUG_STRING_F", 0); | |
8751 | case 'D': | |
8752 | return get_var_value ("DEBUG_STRING_D", 0); | |
8753 | case 'G': | |
8754 | return get_var_value ("DEBUG_STRING_G", 0); | |
8755 | default: | |
323e0a4a | 8756 | error (_("invalid VAX floating-point type")); |
d2e4a39e | 8757 | } |
14f9c5c9 | 8758 | } |
14f9c5c9 | 8759 | \f |
d2e4a39e | 8760 | |
4c4b4cd2 | 8761 | /* Range types */ |
14f9c5c9 AS |
8762 | |
8763 | /* Scan STR beginning at position K for a discriminant name, and | |
8764 | return the value of that discriminant field of DVAL in *PX. If | |
8765 | PNEW_K is not null, put the position of the character beyond the | |
8766 | name scanned in *PNEW_K. Return 1 if successful; return 0 and do | |
4c4b4cd2 | 8767 | not alter *PX and *PNEW_K if unsuccessful. */ |
14f9c5c9 AS |
8768 | |
8769 | static int | |
07d8f827 | 8770 | scan_discrim_bound (char *str, int k, struct value *dval, LONGEST * px, |
76a01679 | 8771 | int *pnew_k) |
14f9c5c9 AS |
8772 | { |
8773 | static char *bound_buffer = NULL; | |
8774 | static size_t bound_buffer_len = 0; | |
8775 | char *bound; | |
8776 | char *pend; | |
d2e4a39e | 8777 | struct value *bound_val; |
14f9c5c9 AS |
8778 | |
8779 | if (dval == NULL || str == NULL || str[k] == '\0') | |
8780 | return 0; | |
8781 | ||
d2e4a39e | 8782 | pend = strstr (str + k, "__"); |
14f9c5c9 AS |
8783 | if (pend == NULL) |
8784 | { | |
d2e4a39e | 8785 | bound = str + k; |
14f9c5c9 AS |
8786 | k += strlen (bound); |
8787 | } | |
d2e4a39e | 8788 | else |
14f9c5c9 | 8789 | { |
d2e4a39e | 8790 | GROW_VECT (bound_buffer, bound_buffer_len, pend - (str + k) + 1); |
14f9c5c9 | 8791 | bound = bound_buffer; |
d2e4a39e AS |
8792 | strncpy (bound_buffer, str + k, pend - (str + k)); |
8793 | bound[pend - (str + k)] = '\0'; | |
8794 | k = pend - str; | |
14f9c5c9 | 8795 | } |
d2e4a39e | 8796 | |
df407dfe | 8797 | bound_val = ada_search_struct_field (bound, dval, 0, value_type (dval)); |
14f9c5c9 AS |
8798 | if (bound_val == NULL) |
8799 | return 0; | |
8800 | ||
8801 | *px = value_as_long (bound_val); | |
8802 | if (pnew_k != NULL) | |
8803 | *pnew_k = k; | |
8804 | return 1; | |
8805 | } | |
8806 | ||
8807 | /* Value of variable named NAME in the current environment. If | |
8808 | no such variable found, then if ERR_MSG is null, returns 0, and | |
4c4b4cd2 PH |
8809 | otherwise causes an error with message ERR_MSG. */ |
8810 | ||
d2e4a39e AS |
8811 | static struct value * |
8812 | get_var_value (char *name, char *err_msg) | |
14f9c5c9 | 8813 | { |
4c4b4cd2 | 8814 | struct ada_symbol_info *syms; |
14f9c5c9 AS |
8815 | int nsyms; |
8816 | ||
4c4b4cd2 PH |
8817 | nsyms = ada_lookup_symbol_list (name, get_selected_block (0), VAR_DOMAIN, |
8818 | &syms); | |
14f9c5c9 AS |
8819 | |
8820 | if (nsyms != 1) | |
8821 | { | |
8822 | if (err_msg == NULL) | |
4c4b4cd2 | 8823 | return 0; |
14f9c5c9 | 8824 | else |
8a3fe4f8 | 8825 | error (("%s"), err_msg); |
14f9c5c9 AS |
8826 | } |
8827 | ||
4c4b4cd2 | 8828 | return value_of_variable (syms[0].sym, syms[0].block); |
14f9c5c9 | 8829 | } |
d2e4a39e | 8830 | |
14f9c5c9 | 8831 | /* Value of integer variable named NAME in the current environment. If |
4c4b4cd2 PH |
8832 | no such variable found, returns 0, and sets *FLAG to 0. If |
8833 | successful, sets *FLAG to 1. */ | |
8834 | ||
14f9c5c9 | 8835 | LONGEST |
4c4b4cd2 | 8836 | get_int_var_value (char *name, int *flag) |
14f9c5c9 | 8837 | { |
4c4b4cd2 | 8838 | struct value *var_val = get_var_value (name, 0); |
d2e4a39e | 8839 | |
14f9c5c9 AS |
8840 | if (var_val == 0) |
8841 | { | |
8842 | if (flag != NULL) | |
4c4b4cd2 | 8843 | *flag = 0; |
14f9c5c9 AS |
8844 | return 0; |
8845 | } | |
8846 | else | |
8847 | { | |
8848 | if (flag != NULL) | |
4c4b4cd2 | 8849 | *flag = 1; |
14f9c5c9 AS |
8850 | return value_as_long (var_val); |
8851 | } | |
8852 | } | |
d2e4a39e | 8853 | |
14f9c5c9 AS |
8854 | |
8855 | /* Return a range type whose base type is that of the range type named | |
8856 | NAME in the current environment, and whose bounds are calculated | |
4c4b4cd2 | 8857 | from NAME according to the GNAT range encoding conventions. |
14f9c5c9 AS |
8858 | Extract discriminant values, if needed, from DVAL. If a new type |
8859 | must be created, allocate in OBJFILE's space. The bounds | |
8860 | information, in general, is encoded in NAME, the base type given in | |
4c4b4cd2 | 8861 | the named range type. */ |
14f9c5c9 | 8862 | |
d2e4a39e | 8863 | static struct type * |
ebf56fd3 | 8864 | to_fixed_range_type (char *name, struct value *dval, struct objfile *objfile) |
14f9c5c9 AS |
8865 | { |
8866 | struct type *raw_type = ada_find_any_type (name); | |
8867 | struct type *base_type; | |
d2e4a39e | 8868 | char *subtype_info; |
14f9c5c9 AS |
8869 | |
8870 | if (raw_type == NULL) | |
8871 | base_type = builtin_type_int; | |
8872 | else if (TYPE_CODE (raw_type) == TYPE_CODE_RANGE) | |
8873 | base_type = TYPE_TARGET_TYPE (raw_type); | |
8874 | else | |
8875 | base_type = raw_type; | |
8876 | ||
8877 | subtype_info = strstr (name, "___XD"); | |
8878 | if (subtype_info == NULL) | |
8879 | return raw_type; | |
8880 | else | |
8881 | { | |
8882 | static char *name_buf = NULL; | |
8883 | static size_t name_len = 0; | |
8884 | int prefix_len = subtype_info - name; | |
8885 | LONGEST L, U; | |
8886 | struct type *type; | |
8887 | char *bounds_str; | |
8888 | int n; | |
8889 | ||
8890 | GROW_VECT (name_buf, name_len, prefix_len + 5); | |
8891 | strncpy (name_buf, name, prefix_len); | |
8892 | name_buf[prefix_len] = '\0'; | |
8893 | ||
8894 | subtype_info += 5; | |
8895 | bounds_str = strchr (subtype_info, '_'); | |
8896 | n = 1; | |
8897 | ||
d2e4a39e | 8898 | if (*subtype_info == 'L') |
4c4b4cd2 PH |
8899 | { |
8900 | if (!ada_scan_number (bounds_str, n, &L, &n) | |
8901 | && !scan_discrim_bound (bounds_str, n, dval, &L, &n)) | |
8902 | return raw_type; | |
8903 | if (bounds_str[n] == '_') | |
8904 | n += 2; | |
8905 | else if (bounds_str[n] == '.') /* FIXME? SGI Workshop kludge. */ | |
8906 | n += 1; | |
8907 | subtype_info += 1; | |
8908 | } | |
d2e4a39e | 8909 | else |
4c4b4cd2 PH |
8910 | { |
8911 | int ok; | |
8912 | strcpy (name_buf + prefix_len, "___L"); | |
8913 | L = get_int_var_value (name_buf, &ok); | |
8914 | if (!ok) | |
8915 | { | |
323e0a4a | 8916 | lim_warning (_("Unknown lower bound, using 1.")); |
4c4b4cd2 PH |
8917 | L = 1; |
8918 | } | |
8919 | } | |
14f9c5c9 | 8920 | |
d2e4a39e | 8921 | if (*subtype_info == 'U') |
4c4b4cd2 PH |
8922 | { |
8923 | if (!ada_scan_number (bounds_str, n, &U, &n) | |
8924 | && !scan_discrim_bound (bounds_str, n, dval, &U, &n)) | |
8925 | return raw_type; | |
8926 | } | |
d2e4a39e | 8927 | else |
4c4b4cd2 PH |
8928 | { |
8929 | int ok; | |
8930 | strcpy (name_buf + prefix_len, "___U"); | |
8931 | U = get_int_var_value (name_buf, &ok); | |
8932 | if (!ok) | |
8933 | { | |
323e0a4a | 8934 | lim_warning (_("Unknown upper bound, using %ld."), (long) L); |
4c4b4cd2 PH |
8935 | U = L; |
8936 | } | |
8937 | } | |
14f9c5c9 | 8938 | |
d2e4a39e | 8939 | if (objfile == NULL) |
4c4b4cd2 | 8940 | objfile = TYPE_OBJFILE (base_type); |
14f9c5c9 | 8941 | type = create_range_type (alloc_type (objfile), base_type, L, U); |
d2e4a39e | 8942 | TYPE_NAME (type) = name; |
14f9c5c9 AS |
8943 | return type; |
8944 | } | |
8945 | } | |
8946 | ||
4c4b4cd2 PH |
8947 | /* True iff NAME is the name of a range type. */ |
8948 | ||
14f9c5c9 | 8949 | int |
d2e4a39e | 8950 | ada_is_range_type_name (const char *name) |
14f9c5c9 AS |
8951 | { |
8952 | return (name != NULL && strstr (name, "___XD")); | |
d2e4a39e | 8953 | } |
14f9c5c9 | 8954 | \f |
d2e4a39e | 8955 | |
4c4b4cd2 PH |
8956 | /* Modular types */ |
8957 | ||
8958 | /* True iff TYPE is an Ada modular type. */ | |
14f9c5c9 | 8959 | |
14f9c5c9 | 8960 | int |
d2e4a39e | 8961 | ada_is_modular_type (struct type *type) |
14f9c5c9 | 8962 | { |
4c4b4cd2 | 8963 | struct type *subranged_type = base_type (type); |
14f9c5c9 AS |
8964 | |
8965 | return (subranged_type != NULL && TYPE_CODE (type) == TYPE_CODE_RANGE | |
4c4b4cd2 PH |
8966 | && TYPE_CODE (subranged_type) != TYPE_CODE_ENUM |
8967 | && TYPE_UNSIGNED (subranged_type)); | |
14f9c5c9 AS |
8968 | } |
8969 | ||
4c4b4cd2 PH |
8970 | /* Assuming ada_is_modular_type (TYPE), the modulus of TYPE. */ |
8971 | ||
61ee279c | 8972 | ULONGEST |
d2e4a39e | 8973 | ada_modulus (struct type * type) |
14f9c5c9 | 8974 | { |
61ee279c | 8975 | return (ULONGEST) TYPE_HIGH_BOUND (type) + 1; |
14f9c5c9 | 8976 | } |
d2e4a39e | 8977 | \f |
f7f9143b JB |
8978 | |
8979 | /* Ada exception catchpoint support: | |
8980 | --------------------------------- | |
8981 | ||
8982 | We support 3 kinds of exception catchpoints: | |
8983 | . catchpoints on Ada exceptions | |
8984 | . catchpoints on unhandled Ada exceptions | |
8985 | . catchpoints on failed assertions | |
8986 | ||
8987 | Exceptions raised during failed assertions, or unhandled exceptions | |
8988 | could perfectly be caught with the general catchpoint on Ada exceptions. | |
8989 | However, we can easily differentiate these two special cases, and having | |
8990 | the option to distinguish these two cases from the rest can be useful | |
8991 | to zero-in on certain situations. | |
8992 | ||
8993 | Exception catchpoints are a specialized form of breakpoint, | |
8994 | since they rely on inserting breakpoints inside known routines | |
8995 | of the GNAT runtime. The implementation therefore uses a standard | |
8996 | breakpoint structure of the BP_BREAKPOINT type, but with its own set | |
8997 | of breakpoint_ops. | |
8998 | ||
8999 | At this time, we do not support the use of conditions on Ada exception | |
9000 | catchpoints. The COND and COND_STRING fields are therefore set | |
9001 | to NULL (most of the time, see below). | |
9002 | ||
9003 | Conditions where EXP_STRING, COND, and COND_STRING are used: | |
9004 | ||
9005 | When a user specifies the name of a specific exception in the case | |
9006 | of catchpoints on Ada exceptions, we store the name of that exception | |
9007 | in the EXP_STRING. We then translate this request into an actual | |
9008 | condition stored in COND_STRING, and then parse it into an expression | |
9009 | stored in COND. */ | |
9010 | ||
9011 | /* The different types of catchpoints that we introduced for catching | |
9012 | Ada exceptions. */ | |
9013 | ||
9014 | enum exception_catchpoint_kind | |
9015 | { | |
9016 | ex_catch_exception, | |
9017 | ex_catch_exception_unhandled, | |
9018 | ex_catch_assert | |
9019 | }; | |
9020 | ||
9021 | /* Return the name of the function at PC, NULL if could not find it. | |
9022 | This function only checks the debugging information, not the symbol | |
9023 | table. */ | |
9024 | ||
9025 | static char * | |
9026 | function_name_from_pc (CORE_ADDR pc) | |
9027 | { | |
9028 | char *func_name; | |
9029 | ||
9030 | if (!find_pc_partial_function (pc, &func_name, NULL, NULL)) | |
9031 | return NULL; | |
9032 | ||
9033 | return func_name; | |
9034 | } | |
9035 | ||
9036 | /* True iff FRAME is very likely to be that of a function that is | |
9037 | part of the runtime system. This is all very heuristic, but is | |
9038 | intended to be used as advice as to what frames are uninteresting | |
9039 | to most users. */ | |
9040 | ||
9041 | static int | |
9042 | is_known_support_routine (struct frame_info *frame) | |
9043 | { | |
9044 | struct frame_info *next_frame = get_next_frame (frame); | |
9045 | /* If frame is not innermost, that normally means that frame->pc | |
9046 | points to *after* the call instruction, and we want to get the line | |
9047 | containing the call, never the next line. But if the next frame is | |
9048 | a signal_handler_caller or a dummy frame, then the next frame was | |
9049 | not entered as the result of a call, and we want to get the line | |
9050 | containing frame->pc. */ | |
9051 | const int pc_is_after_call = | |
9052 | next_frame != NULL | |
9053 | && get_frame_type (next_frame) != SIGTRAMP_FRAME | |
9054 | && get_frame_type (next_frame) != DUMMY_FRAME; | |
9055 | struct symtab_and_line sal | |
9056 | = find_pc_line (get_frame_pc (frame), pc_is_after_call); | |
9057 | char *func_name; | |
9058 | int i; | |
9059 | struct stat st; | |
9060 | ||
9061 | /* The heuristic: | |
9062 | 1. The symtab is null (indicating no debugging symbols) | |
9063 | 2. The symtab's filename does not exist. | |
9064 | 3. The object file's name is one of the standard libraries. | |
9065 | 4. The symtab's file name has the form of an Ada library source file. | |
9066 | 5. The function at frame's PC has a GNAT-compiler-generated name. */ | |
9067 | ||
9068 | if (sal.symtab == NULL) | |
9069 | return 1; | |
9070 | ||
9071 | /* On some systems (e.g. VxWorks), the kernel contains debugging | |
9072 | symbols; in this case, the filename referenced by these symbols | |
9073 | does not exists. */ | |
9074 | ||
9075 | if (stat (sal.symtab->filename, &st)) | |
9076 | return 1; | |
9077 | ||
9078 | for (i = 0; known_runtime_file_name_patterns[i] != NULL; i += 1) | |
9079 | { | |
9080 | re_comp (known_runtime_file_name_patterns[i]); | |
9081 | if (re_exec (sal.symtab->filename)) | |
9082 | return 1; | |
9083 | } | |
9084 | if (sal.symtab->objfile != NULL) | |
9085 | { | |
9086 | for (i = 0; known_runtime_file_name_patterns[i] != NULL; i += 1) | |
9087 | { | |
9088 | re_comp (known_runtime_file_name_patterns[i]); | |
9089 | if (re_exec (sal.symtab->objfile->name)) | |
9090 | return 1; | |
9091 | } | |
9092 | } | |
9093 | ||
9094 | /* If the frame PC points after the call instruction, then we need to | |
9095 | decrement it in order to search for the function associated to this | |
9096 | PC. Otherwise, if the associated call was the last instruction of | |
9097 | the function, we might either find the wrong function or even fail | |
9098 | during the function name lookup. */ | |
9099 | if (pc_is_after_call) | |
9100 | func_name = function_name_from_pc (get_frame_pc (frame) - 1); | |
9101 | else | |
9102 | func_name = function_name_from_pc (get_frame_pc (frame)); | |
9103 | ||
9104 | if (func_name == NULL) | |
9105 | return 1; | |
9106 | ||
9107 | for (i = 0; known_auxiliary_function_name_patterns[i] != NULL; i += 1) | |
9108 | { | |
9109 | re_comp (known_auxiliary_function_name_patterns[i]); | |
9110 | if (re_exec (func_name)) | |
9111 | return 1; | |
9112 | } | |
9113 | ||
9114 | return 0; | |
9115 | } | |
9116 | ||
9117 | /* Find the first frame that contains debugging information and that is not | |
9118 | part of the Ada run-time, starting from FI and moving upward. */ | |
9119 | ||
9120 | static void | |
9121 | ada_find_printable_frame (struct frame_info *fi) | |
9122 | { | |
9123 | for (; fi != NULL; fi = get_prev_frame (fi)) | |
9124 | { | |
9125 | if (!is_known_support_routine (fi)) | |
9126 | { | |
9127 | select_frame (fi); | |
9128 | break; | |
9129 | } | |
9130 | } | |
9131 | ||
9132 | } | |
9133 | ||
9134 | /* Assuming that the inferior just triggered an unhandled exception | |
9135 | catchpoint, return the address in inferior memory where the name | |
9136 | of the exception is stored. | |
9137 | ||
9138 | Return zero if the address could not be computed. */ | |
9139 | ||
9140 | static CORE_ADDR | |
9141 | ada_unhandled_exception_name_addr (void) | |
9142 | { | |
9143 | int frame_level; | |
9144 | struct frame_info *fi; | |
9145 | ||
9146 | /* To determine the name of this exception, we need to select | |
9147 | the frame corresponding to RAISE_SYM_NAME. This frame is | |
9148 | at least 3 levels up, so we simply skip the first 3 frames | |
9149 | without checking the name of their associated function. */ | |
9150 | fi = get_current_frame (); | |
9151 | for (frame_level = 0; frame_level < 3; frame_level += 1) | |
9152 | if (fi != NULL) | |
9153 | fi = get_prev_frame (fi); | |
9154 | ||
9155 | while (fi != NULL) | |
9156 | { | |
9157 | const char *func_name = | |
9158 | function_name_from_pc (get_frame_address_in_block (fi)); | |
9159 | if (func_name != NULL | |
9160 | && strcmp (func_name, raise_sym_name) == 0) | |
9161 | break; /* We found the frame we were looking for... */ | |
9162 | fi = get_prev_frame (fi); | |
9163 | } | |
9164 | ||
9165 | if (fi == NULL) | |
9166 | return 0; | |
9167 | ||
9168 | select_frame (fi); | |
9169 | return parse_and_eval_address ("id.full_name"); | |
9170 | } | |
9171 | ||
9172 | /* Assuming the inferior just triggered an Ada exception catchpoint | |
9173 | (of any type), return the address in inferior memory where the name | |
9174 | of the exception is stored, if applicable. | |
9175 | ||
9176 | Return zero if the address could not be computed, or if not relevant. */ | |
9177 | ||
9178 | static CORE_ADDR | |
9179 | ada_exception_name_addr_1 (enum exception_catchpoint_kind ex, | |
9180 | struct breakpoint *b) | |
9181 | { | |
9182 | switch (ex) | |
9183 | { | |
9184 | case ex_catch_exception: | |
9185 | return (parse_and_eval_address ("e.full_name")); | |
9186 | break; | |
9187 | ||
9188 | case ex_catch_exception_unhandled: | |
9189 | return ada_unhandled_exception_name_addr (); | |
9190 | break; | |
9191 | ||
9192 | case ex_catch_assert: | |
9193 | return 0; /* Exception name is not relevant in this case. */ | |
9194 | break; | |
9195 | ||
9196 | default: | |
9197 | internal_error (__FILE__, __LINE__, _("unexpected catchpoint type")); | |
9198 | break; | |
9199 | } | |
9200 | ||
9201 | return 0; /* Should never be reached. */ | |
9202 | } | |
9203 | ||
9204 | /* Same as ada_exception_name_addr_1, except that it intercepts and contains | |
9205 | any error that ada_exception_name_addr_1 might cause to be thrown. | |
9206 | When an error is intercepted, a warning with the error message is printed, | |
9207 | and zero is returned. */ | |
9208 | ||
9209 | static CORE_ADDR | |
9210 | ada_exception_name_addr (enum exception_catchpoint_kind ex, | |
9211 | struct breakpoint *b) | |
9212 | { | |
9213 | struct gdb_exception e; | |
9214 | CORE_ADDR result = 0; | |
9215 | ||
9216 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
9217 | { | |
9218 | result = ada_exception_name_addr_1 (ex, b); | |
9219 | } | |
9220 | ||
9221 | if (e.reason < 0) | |
9222 | { | |
9223 | warning (_("failed to get exception name: %s"), e.message); | |
9224 | return 0; | |
9225 | } | |
9226 | ||
9227 | return result; | |
9228 | } | |
9229 | ||
9230 | /* Implement the PRINT_IT method in the breakpoint_ops structure | |
9231 | for all exception catchpoint kinds. */ | |
9232 | ||
9233 | static enum print_stop_action | |
9234 | print_it_exception (enum exception_catchpoint_kind ex, struct breakpoint *b) | |
9235 | { | |
9236 | const CORE_ADDR addr = ada_exception_name_addr (ex, b); | |
9237 | char exception_name[256]; | |
9238 | ||
9239 | if (addr != 0) | |
9240 | { | |
9241 | read_memory (addr, exception_name, sizeof (exception_name) - 1); | |
9242 | exception_name [sizeof (exception_name) - 1] = '\0'; | |
9243 | } | |
9244 | ||
9245 | ada_find_printable_frame (get_current_frame ()); | |
9246 | ||
9247 | annotate_catchpoint (b->number); | |
9248 | switch (ex) | |
9249 | { | |
9250 | case ex_catch_exception: | |
9251 | if (addr != 0) | |
9252 | printf_filtered (_("\nCatchpoint %d, %s at "), | |
9253 | b->number, exception_name); | |
9254 | else | |
9255 | printf_filtered (_("\nCatchpoint %d, exception at "), b->number); | |
9256 | break; | |
9257 | case ex_catch_exception_unhandled: | |
9258 | if (addr != 0) | |
9259 | printf_filtered (_("\nCatchpoint %d, unhandled %s at "), | |
9260 | b->number, exception_name); | |
9261 | else | |
9262 | printf_filtered (_("\nCatchpoint %d, unhandled exception at "), | |
9263 | b->number); | |
9264 | break; | |
9265 | case ex_catch_assert: | |
9266 | printf_filtered (_("\nCatchpoint %d, failed assertion at "), | |
9267 | b->number); | |
9268 | break; | |
9269 | } | |
9270 | ||
9271 | return PRINT_SRC_AND_LOC; | |
9272 | } | |
9273 | ||
9274 | /* Implement the PRINT_ONE method in the breakpoint_ops structure | |
9275 | for all exception catchpoint kinds. */ | |
9276 | ||
9277 | static void | |
9278 | print_one_exception (enum exception_catchpoint_kind ex, | |
9279 | struct breakpoint *b, CORE_ADDR *last_addr) | |
9280 | { | |
9281 | if (addressprint) | |
9282 | { | |
9283 | annotate_field (4); | |
9284 | ui_out_field_core_addr (uiout, "addr", b->loc->address); | |
9285 | } | |
9286 | ||
9287 | annotate_field (5); | |
9288 | *last_addr = b->loc->address; | |
9289 | switch (ex) | |
9290 | { | |
9291 | case ex_catch_exception: | |
9292 | if (b->exp_string != NULL) | |
9293 | { | |
9294 | char *msg = xstrprintf (_("`%s' Ada exception"), b->exp_string); | |
9295 | ||
9296 | ui_out_field_string (uiout, "what", msg); | |
9297 | xfree (msg); | |
9298 | } | |
9299 | else | |
9300 | ui_out_field_string (uiout, "what", "all Ada exceptions"); | |
9301 | ||
9302 | break; | |
9303 | ||
9304 | case ex_catch_exception_unhandled: | |
9305 | ui_out_field_string (uiout, "what", "unhandled Ada exceptions"); | |
9306 | break; | |
9307 | ||
9308 | case ex_catch_assert: | |
9309 | ui_out_field_string (uiout, "what", "failed Ada assertions"); | |
9310 | break; | |
9311 | ||
9312 | default: | |
9313 | internal_error (__FILE__, __LINE__, _("unexpected catchpoint type")); | |
9314 | break; | |
9315 | } | |
9316 | } | |
9317 | ||
9318 | /* Implement the PRINT_MENTION method in the breakpoint_ops structure | |
9319 | for all exception catchpoint kinds. */ | |
9320 | ||
9321 | static void | |
9322 | print_mention_exception (enum exception_catchpoint_kind ex, | |
9323 | struct breakpoint *b) | |
9324 | { | |
9325 | switch (ex) | |
9326 | { | |
9327 | case ex_catch_exception: | |
9328 | if (b->exp_string != NULL) | |
9329 | printf_filtered (_("Catchpoint %d: `%s' Ada exception"), | |
9330 | b->number, b->exp_string); | |
9331 | else | |
9332 | printf_filtered (_("Catchpoint %d: all Ada exceptions"), b->number); | |
9333 | ||
9334 | break; | |
9335 | ||
9336 | case ex_catch_exception_unhandled: | |
9337 | printf_filtered (_("Catchpoint %d: unhandled Ada exceptions"), | |
9338 | b->number); | |
9339 | break; | |
9340 | ||
9341 | case ex_catch_assert: | |
9342 | printf_filtered (_("Catchpoint %d: failed Ada assertions"), b->number); | |
9343 | break; | |
9344 | ||
9345 | default: | |
9346 | internal_error (__FILE__, __LINE__, _("unexpected catchpoint type")); | |
9347 | break; | |
9348 | } | |
9349 | } | |
9350 | ||
9351 | /* Virtual table for "catch exception" breakpoints. */ | |
9352 | ||
9353 | static enum print_stop_action | |
9354 | print_it_catch_exception (struct breakpoint *b) | |
9355 | { | |
9356 | return print_it_exception (ex_catch_exception, b); | |
9357 | } | |
9358 | ||
9359 | static void | |
9360 | print_one_catch_exception (struct breakpoint *b, CORE_ADDR *last_addr) | |
9361 | { | |
9362 | print_one_exception (ex_catch_exception, b, last_addr); | |
9363 | } | |
9364 | ||
9365 | static void | |
9366 | print_mention_catch_exception (struct breakpoint *b) | |
9367 | { | |
9368 | print_mention_exception (ex_catch_exception, b); | |
9369 | } | |
9370 | ||
9371 | static struct breakpoint_ops catch_exception_breakpoint_ops = | |
9372 | { | |
9373 | print_it_catch_exception, | |
9374 | print_one_catch_exception, | |
9375 | print_mention_catch_exception | |
9376 | }; | |
9377 | ||
9378 | /* Virtual table for "catch exception unhandled" breakpoints. */ | |
9379 | ||
9380 | static enum print_stop_action | |
9381 | print_it_catch_exception_unhandled (struct breakpoint *b) | |
9382 | { | |
9383 | return print_it_exception (ex_catch_exception_unhandled, b); | |
9384 | } | |
9385 | ||
9386 | static void | |
9387 | print_one_catch_exception_unhandled (struct breakpoint *b, CORE_ADDR *last_addr) | |
9388 | { | |
9389 | print_one_exception (ex_catch_exception_unhandled, b, last_addr); | |
9390 | } | |
9391 | ||
9392 | static void | |
9393 | print_mention_catch_exception_unhandled (struct breakpoint *b) | |
9394 | { | |
9395 | print_mention_exception (ex_catch_exception_unhandled, b); | |
9396 | } | |
9397 | ||
9398 | static struct breakpoint_ops catch_exception_unhandled_breakpoint_ops = { | |
9399 | print_it_catch_exception_unhandled, | |
9400 | print_one_catch_exception_unhandled, | |
9401 | print_mention_catch_exception_unhandled | |
9402 | }; | |
9403 | ||
9404 | /* Virtual table for "catch assert" breakpoints. */ | |
9405 | ||
9406 | static enum print_stop_action | |
9407 | print_it_catch_assert (struct breakpoint *b) | |
9408 | { | |
9409 | return print_it_exception (ex_catch_assert, b); | |
9410 | } | |
9411 | ||
9412 | static void | |
9413 | print_one_catch_assert (struct breakpoint *b, CORE_ADDR *last_addr) | |
9414 | { | |
9415 | print_one_exception (ex_catch_assert, b, last_addr); | |
9416 | } | |
9417 | ||
9418 | static void | |
9419 | print_mention_catch_assert (struct breakpoint *b) | |
9420 | { | |
9421 | print_mention_exception (ex_catch_assert, b); | |
9422 | } | |
9423 | ||
9424 | static struct breakpoint_ops catch_assert_breakpoint_ops = { | |
9425 | print_it_catch_assert, | |
9426 | print_one_catch_assert, | |
9427 | print_mention_catch_assert | |
9428 | }; | |
9429 | ||
9430 | /* Return non-zero if B is an Ada exception catchpoint. */ | |
9431 | ||
9432 | int | |
9433 | ada_exception_catchpoint_p (struct breakpoint *b) | |
9434 | { | |
9435 | return (b->ops == &catch_exception_breakpoint_ops | |
9436 | || b->ops == &catch_exception_unhandled_breakpoint_ops | |
9437 | || b->ops == &catch_assert_breakpoint_ops); | |
9438 | } | |
9439 | ||
9440 | /* Cause the appropriate error if no appropriate runtime symbol is | |
9441 | found to set a breakpoint, using ERR_DESC to describe the | |
9442 | breakpoint. */ | |
9443 | ||
9444 | static void | |
9445 | error_breakpoint_runtime_sym_not_found (const char *err_desc) | |
9446 | { | |
9447 | /* If we are not debugging an Ada program, we cannot put exception | |
9448 | catchpoints! */ | |
9449 | ||
9450 | if (ada_update_initial_language (language_unknown, NULL) != language_ada) | |
9451 | error (_("Unable to break on %s. Is this an Ada main program?"), | |
9452 | err_desc); | |
9453 | ||
9454 | /* If the symbol does not exist, then check that the program is | |
9455 | already started, to make sure that shared libraries have been | |
9456 | loaded. If it is not started, this may mean that the symbol is | |
9457 | in a shared library. */ | |
9458 | ||
9459 | if (ptid_get_pid (inferior_ptid) == 0) | |
9460 | error (_("Unable to break on %s. Try to start the program first."), | |
9461 | err_desc); | |
9462 | ||
9463 | /* At this point, we know that we are debugging an Ada program and | |
9464 | that the inferior has been started, but we still are not able to | |
9465 | find the run-time symbols. That can mean that we are in | |
9466 | configurable run time mode, or that a-except as been optimized | |
9467 | out by the linker... In any case, at this point it is not worth | |
9468 | supporting this feature. */ | |
9469 | ||
9470 | error (_("Cannot break on %s in this configuration."), err_desc); | |
9471 | } | |
9472 | ||
9473 | /* Return a newly allocated copy of the first space-separated token | |
9474 | in ARGSP, and then adjust ARGSP to point immediately after that | |
9475 | token. | |
9476 | ||
9477 | Return NULL if ARGPS does not contain any more tokens. */ | |
9478 | ||
9479 | static char * | |
9480 | ada_get_next_arg (char **argsp) | |
9481 | { | |
9482 | char *args = *argsp; | |
9483 | char *end; | |
9484 | char *result; | |
9485 | ||
9486 | /* Skip any leading white space. */ | |
9487 | ||
9488 | while (isspace (*args)) | |
9489 | args++; | |
9490 | ||
9491 | if (args[0] == '\0') | |
9492 | return NULL; /* No more arguments. */ | |
9493 | ||
9494 | /* Find the end of the current argument. */ | |
9495 | ||
9496 | end = args; | |
9497 | while (*end != '\0' && !isspace (*end)) | |
9498 | end++; | |
9499 | ||
9500 | /* Adjust ARGSP to point to the start of the next argument. */ | |
9501 | ||
9502 | *argsp = end; | |
9503 | ||
9504 | /* Make a copy of the current argument and return it. */ | |
9505 | ||
9506 | result = xmalloc (end - args + 1); | |
9507 | strncpy (result, args, end - args); | |
9508 | result[end - args] = '\0'; | |
9509 | ||
9510 | return result; | |
9511 | } | |
9512 | ||
9513 | /* Split the arguments specified in a "catch exception" command. | |
9514 | Set EX to the appropriate catchpoint type. | |
9515 | Set EXP_STRING to the name of the specific exception if | |
9516 | specified by the user. */ | |
9517 | ||
9518 | static void | |
9519 | catch_ada_exception_command_split (char *args, | |
9520 | enum exception_catchpoint_kind *ex, | |
9521 | char **exp_string) | |
9522 | { | |
9523 | struct cleanup *old_chain = make_cleanup (null_cleanup, NULL); | |
9524 | char *exception_name; | |
9525 | ||
9526 | exception_name = ada_get_next_arg (&args); | |
9527 | make_cleanup (xfree, exception_name); | |
9528 | ||
9529 | /* Check that we do not have any more arguments. Anything else | |
9530 | is unexpected. */ | |
9531 | ||
9532 | while (isspace (*args)) | |
9533 | args++; | |
9534 | ||
9535 | if (args[0] != '\0') | |
9536 | error (_("Junk at end of expression")); | |
9537 | ||
9538 | discard_cleanups (old_chain); | |
9539 | ||
9540 | if (exception_name == NULL) | |
9541 | { | |
9542 | /* Catch all exceptions. */ | |
9543 | *ex = ex_catch_exception; | |
9544 | *exp_string = NULL; | |
9545 | } | |
9546 | else if (strcmp (exception_name, "unhandled") == 0) | |
9547 | { | |
9548 | /* Catch unhandled exceptions. */ | |
9549 | *ex = ex_catch_exception_unhandled; | |
9550 | *exp_string = NULL; | |
9551 | } | |
9552 | else | |
9553 | { | |
9554 | /* Catch a specific exception. */ | |
9555 | *ex = ex_catch_exception; | |
9556 | *exp_string = exception_name; | |
9557 | } | |
9558 | } | |
9559 | ||
9560 | /* Return the name of the symbol on which we should break in order to | |
9561 | implement a catchpoint of the EX kind. */ | |
9562 | ||
9563 | static const char * | |
9564 | ada_exception_sym_name (enum exception_catchpoint_kind ex) | |
9565 | { | |
9566 | switch (ex) | |
9567 | { | |
9568 | case ex_catch_exception: | |
9569 | return (raise_sym_name); | |
9570 | break; | |
9571 | case ex_catch_exception_unhandled: | |
9572 | return (raise_unhandled_sym_name); | |
9573 | break; | |
9574 | case ex_catch_assert: | |
9575 | return (raise_assert_sym_name); | |
9576 | break; | |
9577 | default: | |
9578 | internal_error (__FILE__, __LINE__, | |
9579 | _("unexpected catchpoint kind (%d)"), ex); | |
9580 | } | |
9581 | } | |
9582 | ||
9583 | /* Return the breakpoint ops "virtual table" used for catchpoints | |
9584 | of the EX kind. */ | |
9585 | ||
9586 | static struct breakpoint_ops * | |
9587 | ada_exception_breakption_ops (enum exception_catchpoint_kind ex) | |
9588 | { | |
9589 | switch (ex) | |
9590 | { | |
9591 | case ex_catch_exception: | |
9592 | return (&catch_exception_breakpoint_ops); | |
9593 | break; | |
9594 | case ex_catch_exception_unhandled: | |
9595 | return (&catch_exception_unhandled_breakpoint_ops); | |
9596 | break; | |
9597 | case ex_catch_assert: | |
9598 | return (&catch_assert_breakpoint_ops); | |
9599 | break; | |
9600 | default: | |
9601 | internal_error (__FILE__, __LINE__, | |
9602 | _("unexpected catchpoint kind (%d)"), ex); | |
9603 | } | |
9604 | } | |
9605 | ||
9606 | /* Return the condition that will be used to match the current exception | |
9607 | being raised with the exception that the user wants to catch. This | |
9608 | assumes that this condition is used when the inferior just triggered | |
9609 | an exception catchpoint. | |
9610 | ||
9611 | The string returned is a newly allocated string that needs to be | |
9612 | deallocated later. */ | |
9613 | ||
9614 | static char * | |
9615 | ada_exception_catchpoint_cond_string (const char *exp_string) | |
9616 | { | |
9617 | return xstrprintf ("long_integer (e) = long_integer (&%s)", exp_string); | |
9618 | } | |
9619 | ||
9620 | /* Return the expression corresponding to COND_STRING evaluated at SAL. */ | |
9621 | ||
9622 | static struct expression * | |
9623 | ada_parse_catchpoint_condition (char *cond_string, | |
9624 | struct symtab_and_line sal) | |
9625 | { | |
9626 | return (parse_exp_1 (&cond_string, block_for_pc (sal.pc), 0)); | |
9627 | } | |
9628 | ||
9629 | /* Return the symtab_and_line that should be used to insert an exception | |
9630 | catchpoint of the TYPE kind. | |
9631 | ||
9632 | EX_STRING should contain the name of a specific exception | |
9633 | that the catchpoint should catch, or NULL otherwise. | |
9634 | ||
9635 | The idea behind all the remaining parameters is that their names match | |
9636 | the name of certain fields in the breakpoint structure that are used to | |
9637 | handle exception catchpoints. This function returns the value to which | |
9638 | these fields should be set, depending on the type of catchpoint we need | |
9639 | to create. | |
9640 | ||
9641 | If COND and COND_STRING are both non-NULL, any value they might | |
9642 | hold will be free'ed, and then replaced by newly allocated ones. | |
9643 | These parameters are left untouched otherwise. */ | |
9644 | ||
9645 | static struct symtab_and_line | |
9646 | ada_exception_sal (enum exception_catchpoint_kind ex, char *exp_string, | |
9647 | char **addr_string, char **cond_string, | |
9648 | struct expression **cond, struct breakpoint_ops **ops) | |
9649 | { | |
9650 | const char *sym_name; | |
9651 | struct symbol *sym; | |
9652 | struct symtab_and_line sal; | |
9653 | ||
9654 | /* First lookup the function on which we will break in order to catch | |
9655 | the Ada exceptions requested by the user. */ | |
9656 | ||
9657 | sym_name = ada_exception_sym_name (ex); | |
9658 | sym = standard_lookup (sym_name, NULL, VAR_DOMAIN); | |
9659 | ||
9660 | /* The symbol we're looking up is provided by a unit in the GNAT runtime | |
9661 | that should be compiled with debugging information. As a result, we | |
9662 | expect to find that symbol in the symtabs. If we don't find it, then | |
9663 | the target most likely does not support Ada exceptions, or we cannot | |
9664 | insert exception breakpoints yet, because the GNAT runtime hasn't been | |
9665 | loaded yet. */ | |
9666 | ||
9667 | /* brobecker/2006-12-26: It is conceivable that the runtime was compiled | |
9668 | in such a way that no debugging information is produced for the symbol | |
9669 | we are looking for. In this case, we could search the minimal symbols | |
9670 | as a fall-back mechanism. This would still be operating in degraded | |
9671 | mode, however, as we would still be missing the debugging information | |
9672 | that is needed in order to extract the name of the exception being | |
9673 | raised (this name is printed in the catchpoint message, and is also | |
9674 | used when trying to catch a specific exception). We do not handle | |
9675 | this case for now. */ | |
9676 | ||
9677 | if (sym == NULL) | |
9678 | error_breakpoint_runtime_sym_not_found (sym_name); | |
9679 | ||
9680 | /* Make sure that the symbol we found corresponds to a function. */ | |
9681 | if (SYMBOL_CLASS (sym) != LOC_BLOCK) | |
9682 | error (_("Symbol \"%s\" is not a function (class = %d)"), | |
9683 | sym_name, SYMBOL_CLASS (sym)); | |
9684 | ||
9685 | sal = find_function_start_sal (sym, 1); | |
9686 | ||
9687 | /* Set ADDR_STRING. */ | |
9688 | ||
9689 | *addr_string = xstrdup (sym_name); | |
9690 | ||
9691 | /* Set the COND and COND_STRING (if not NULL). */ | |
9692 | ||
9693 | if (cond_string != NULL && cond != NULL) | |
9694 | { | |
9695 | if (*cond_string != NULL) | |
9696 | { | |
9697 | xfree (*cond_string); | |
9698 | *cond_string = NULL; | |
9699 | } | |
9700 | if (*cond != NULL) | |
9701 | { | |
9702 | xfree (*cond); | |
9703 | *cond = NULL; | |
9704 | } | |
9705 | if (exp_string != NULL) | |
9706 | { | |
9707 | *cond_string = ada_exception_catchpoint_cond_string (exp_string); | |
9708 | *cond = ada_parse_catchpoint_condition (*cond_string, sal); | |
9709 | } | |
9710 | } | |
9711 | ||
9712 | /* Set OPS. */ | |
9713 | *ops = ada_exception_breakption_ops (ex); | |
9714 | ||
9715 | return sal; | |
9716 | } | |
9717 | ||
9718 | /* Parse the arguments (ARGS) of the "catch exception" command. | |
9719 | ||
9720 | Set TYPE to the appropriate exception catchpoint type. | |
9721 | If the user asked the catchpoint to catch only a specific | |
9722 | exception, then save the exception name in ADDR_STRING. | |
9723 | ||
9724 | See ada_exception_sal for a description of all the remaining | |
9725 | function arguments of this function. */ | |
9726 | ||
9727 | struct symtab_and_line | |
9728 | ada_decode_exception_location (char *args, char **addr_string, | |
9729 | char **exp_string, char **cond_string, | |
9730 | struct expression **cond, | |
9731 | struct breakpoint_ops **ops) | |
9732 | { | |
9733 | enum exception_catchpoint_kind ex; | |
9734 | ||
9735 | catch_ada_exception_command_split (args, &ex, exp_string); | |
9736 | return ada_exception_sal (ex, *exp_string, addr_string, cond_string, | |
9737 | cond, ops); | |
9738 | } | |
9739 | ||
9740 | struct symtab_and_line | |
9741 | ada_decode_assert_location (char *args, char **addr_string, | |
9742 | struct breakpoint_ops **ops) | |
9743 | { | |
9744 | /* Check that no argument where provided at the end of the command. */ | |
9745 | ||
9746 | if (args != NULL) | |
9747 | { | |
9748 | while (isspace (*args)) | |
9749 | args++; | |
9750 | if (*args != '\0') | |
9751 | error (_("Junk at end of arguments.")); | |
9752 | } | |
9753 | ||
9754 | return ada_exception_sal (ex_catch_assert, NULL, addr_string, NULL, NULL, | |
9755 | ops); | |
9756 | } | |
9757 | ||
4c4b4cd2 PH |
9758 | /* Operators */ |
9759 | /* Information about operators given special treatment in functions | |
9760 | below. */ | |
9761 | /* Format: OP_DEFN (<operator>, <operator length>, <# args>, <binop>). */ | |
9762 | ||
9763 | #define ADA_OPERATORS \ | |
9764 | OP_DEFN (OP_VAR_VALUE, 4, 0, 0) \ | |
9765 | OP_DEFN (BINOP_IN_BOUNDS, 3, 2, 0) \ | |
9766 | OP_DEFN (TERNOP_IN_RANGE, 1, 3, 0) \ | |
9767 | OP_DEFN (OP_ATR_FIRST, 1, 2, 0) \ | |
9768 | OP_DEFN (OP_ATR_LAST, 1, 2, 0) \ | |
9769 | OP_DEFN (OP_ATR_LENGTH, 1, 2, 0) \ | |
9770 | OP_DEFN (OP_ATR_IMAGE, 1, 2, 0) \ | |
9771 | OP_DEFN (OP_ATR_MAX, 1, 3, 0) \ | |
9772 | OP_DEFN (OP_ATR_MIN, 1, 3, 0) \ | |
9773 | OP_DEFN (OP_ATR_MODULUS, 1, 1, 0) \ | |
9774 | OP_DEFN (OP_ATR_POS, 1, 2, 0) \ | |
9775 | OP_DEFN (OP_ATR_SIZE, 1, 1, 0) \ | |
9776 | OP_DEFN (OP_ATR_TAG, 1, 1, 0) \ | |
9777 | OP_DEFN (OP_ATR_VAL, 1, 2, 0) \ | |
9778 | OP_DEFN (UNOP_QUAL, 3, 1, 0) \ | |
52ce6436 PH |
9779 | OP_DEFN (UNOP_IN_RANGE, 3, 1, 0) \ |
9780 | OP_DEFN (OP_OTHERS, 1, 1, 0) \ | |
9781 | OP_DEFN (OP_POSITIONAL, 3, 1, 0) \ | |
9782 | OP_DEFN (OP_DISCRETE_RANGE, 1, 2, 0) | |
4c4b4cd2 PH |
9783 | |
9784 | static void | |
9785 | ada_operator_length (struct expression *exp, int pc, int *oplenp, int *argsp) | |
9786 | { | |
9787 | switch (exp->elts[pc - 1].opcode) | |
9788 | { | |
76a01679 | 9789 | default: |
4c4b4cd2 PH |
9790 | operator_length_standard (exp, pc, oplenp, argsp); |
9791 | break; | |
9792 | ||
9793 | #define OP_DEFN(op, len, args, binop) \ | |
9794 | case op: *oplenp = len; *argsp = args; break; | |
9795 | ADA_OPERATORS; | |
9796 | #undef OP_DEFN | |
52ce6436 PH |
9797 | |
9798 | case OP_AGGREGATE: | |
9799 | *oplenp = 3; | |
9800 | *argsp = longest_to_int (exp->elts[pc - 2].longconst); | |
9801 | break; | |
9802 | ||
9803 | case OP_CHOICES: | |
9804 | *oplenp = 3; | |
9805 | *argsp = longest_to_int (exp->elts[pc - 2].longconst) + 1; | |
9806 | break; | |
4c4b4cd2 PH |
9807 | } |
9808 | } | |
9809 | ||
9810 | static char * | |
9811 | ada_op_name (enum exp_opcode opcode) | |
9812 | { | |
9813 | switch (opcode) | |
9814 | { | |
76a01679 | 9815 | default: |
4c4b4cd2 | 9816 | return op_name_standard (opcode); |
52ce6436 | 9817 | |
4c4b4cd2 PH |
9818 | #define OP_DEFN(op, len, args, binop) case op: return #op; |
9819 | ADA_OPERATORS; | |
9820 | #undef OP_DEFN | |
52ce6436 PH |
9821 | |
9822 | case OP_AGGREGATE: | |
9823 | return "OP_AGGREGATE"; | |
9824 | case OP_CHOICES: | |
9825 | return "OP_CHOICES"; | |
9826 | case OP_NAME: | |
9827 | return "OP_NAME"; | |
4c4b4cd2 PH |
9828 | } |
9829 | } | |
9830 | ||
9831 | /* As for operator_length, but assumes PC is pointing at the first | |
9832 | element of the operator, and gives meaningful results only for the | |
52ce6436 | 9833 | Ada-specific operators, returning 0 for *OPLENP and *ARGSP otherwise. */ |
4c4b4cd2 PH |
9834 | |
9835 | static void | |
76a01679 JB |
9836 | ada_forward_operator_length (struct expression *exp, int pc, |
9837 | int *oplenp, int *argsp) | |
4c4b4cd2 | 9838 | { |
76a01679 | 9839 | switch (exp->elts[pc].opcode) |
4c4b4cd2 PH |
9840 | { |
9841 | default: | |
9842 | *oplenp = *argsp = 0; | |
9843 | break; | |
52ce6436 | 9844 | |
4c4b4cd2 PH |
9845 | #define OP_DEFN(op, len, args, binop) \ |
9846 | case op: *oplenp = len; *argsp = args; break; | |
9847 | ADA_OPERATORS; | |
9848 | #undef OP_DEFN | |
52ce6436 PH |
9849 | |
9850 | case OP_AGGREGATE: | |
9851 | *oplenp = 3; | |
9852 | *argsp = longest_to_int (exp->elts[pc + 1].longconst); | |
9853 | break; | |
9854 | ||
9855 | case OP_CHOICES: | |
9856 | *oplenp = 3; | |
9857 | *argsp = longest_to_int (exp->elts[pc + 1].longconst) + 1; | |
9858 | break; | |
9859 | ||
9860 | case OP_STRING: | |
9861 | case OP_NAME: | |
9862 | { | |
9863 | int len = longest_to_int (exp->elts[pc + 1].longconst); | |
9864 | *oplenp = 4 + BYTES_TO_EXP_ELEM (len + 1); | |
9865 | *argsp = 0; | |
9866 | break; | |
9867 | } | |
4c4b4cd2 PH |
9868 | } |
9869 | } | |
9870 | ||
9871 | static int | |
9872 | ada_dump_subexp_body (struct expression *exp, struct ui_file *stream, int elt) | |
9873 | { | |
9874 | enum exp_opcode op = exp->elts[elt].opcode; | |
9875 | int oplen, nargs; | |
9876 | int pc = elt; | |
9877 | int i; | |
76a01679 | 9878 | |
4c4b4cd2 PH |
9879 | ada_forward_operator_length (exp, elt, &oplen, &nargs); |
9880 | ||
76a01679 | 9881 | switch (op) |
4c4b4cd2 | 9882 | { |
76a01679 | 9883 | /* Ada attributes ('Foo). */ |
4c4b4cd2 PH |
9884 | case OP_ATR_FIRST: |
9885 | case OP_ATR_LAST: | |
9886 | case OP_ATR_LENGTH: | |
9887 | case OP_ATR_IMAGE: | |
9888 | case OP_ATR_MAX: | |
9889 | case OP_ATR_MIN: | |
9890 | case OP_ATR_MODULUS: | |
9891 | case OP_ATR_POS: | |
9892 | case OP_ATR_SIZE: | |
9893 | case OP_ATR_TAG: | |
9894 | case OP_ATR_VAL: | |
9895 | break; | |
9896 | ||
9897 | case UNOP_IN_RANGE: | |
9898 | case UNOP_QUAL: | |
323e0a4a AC |
9899 | /* XXX: gdb_sprint_host_address, type_sprint */ |
9900 | fprintf_filtered (stream, _("Type @")); | |
4c4b4cd2 PH |
9901 | gdb_print_host_address (exp->elts[pc + 1].type, stream); |
9902 | fprintf_filtered (stream, " ("); | |
9903 | type_print (exp->elts[pc + 1].type, NULL, stream, 0); | |
9904 | fprintf_filtered (stream, ")"); | |
9905 | break; | |
9906 | case BINOP_IN_BOUNDS: | |
52ce6436 PH |
9907 | fprintf_filtered (stream, " (%d)", |
9908 | longest_to_int (exp->elts[pc + 2].longconst)); | |
4c4b4cd2 PH |
9909 | break; |
9910 | case TERNOP_IN_RANGE: | |
9911 | break; | |
9912 | ||
52ce6436 PH |
9913 | case OP_AGGREGATE: |
9914 | case OP_OTHERS: | |
9915 | case OP_DISCRETE_RANGE: | |
9916 | case OP_POSITIONAL: | |
9917 | case OP_CHOICES: | |
9918 | break; | |
9919 | ||
9920 | case OP_NAME: | |
9921 | case OP_STRING: | |
9922 | { | |
9923 | char *name = &exp->elts[elt + 2].string; | |
9924 | int len = longest_to_int (exp->elts[elt + 1].longconst); | |
9925 | fprintf_filtered (stream, "Text: `%.*s'", len, name); | |
9926 | break; | |
9927 | } | |
9928 | ||
4c4b4cd2 PH |
9929 | default: |
9930 | return dump_subexp_body_standard (exp, stream, elt); | |
9931 | } | |
9932 | ||
9933 | elt += oplen; | |
9934 | for (i = 0; i < nargs; i += 1) | |
9935 | elt = dump_subexp (exp, stream, elt); | |
9936 | ||
9937 | return elt; | |
9938 | } | |
9939 | ||
9940 | /* The Ada extension of print_subexp (q.v.). */ | |
9941 | ||
76a01679 JB |
9942 | static void |
9943 | ada_print_subexp (struct expression *exp, int *pos, | |
9944 | struct ui_file *stream, enum precedence prec) | |
4c4b4cd2 | 9945 | { |
52ce6436 | 9946 | int oplen, nargs, i; |
4c4b4cd2 PH |
9947 | int pc = *pos; |
9948 | enum exp_opcode op = exp->elts[pc].opcode; | |
9949 | ||
9950 | ada_forward_operator_length (exp, pc, &oplen, &nargs); | |
9951 | ||
52ce6436 | 9952 | *pos += oplen; |
4c4b4cd2 PH |
9953 | switch (op) |
9954 | { | |
9955 | default: | |
52ce6436 | 9956 | *pos -= oplen; |
4c4b4cd2 PH |
9957 | print_subexp_standard (exp, pos, stream, prec); |
9958 | return; | |
9959 | ||
9960 | case OP_VAR_VALUE: | |
4c4b4cd2 PH |
9961 | fputs_filtered (SYMBOL_NATURAL_NAME (exp->elts[pc + 2].symbol), stream); |
9962 | return; | |
9963 | ||
9964 | case BINOP_IN_BOUNDS: | |
323e0a4a | 9965 | /* XXX: sprint_subexp */ |
4c4b4cd2 | 9966 | print_subexp (exp, pos, stream, PREC_SUFFIX); |
0b48a291 | 9967 | fputs_filtered (" in ", stream); |
4c4b4cd2 | 9968 | print_subexp (exp, pos, stream, PREC_SUFFIX); |
0b48a291 | 9969 | fputs_filtered ("'range", stream); |
4c4b4cd2 | 9970 | if (exp->elts[pc + 1].longconst > 1) |
76a01679 JB |
9971 | fprintf_filtered (stream, "(%ld)", |
9972 | (long) exp->elts[pc + 1].longconst); | |
4c4b4cd2 PH |
9973 | return; |
9974 | ||
9975 | case TERNOP_IN_RANGE: | |
4c4b4cd2 | 9976 | if (prec >= PREC_EQUAL) |
76a01679 | 9977 | fputs_filtered ("(", stream); |
323e0a4a | 9978 | /* XXX: sprint_subexp */ |
4c4b4cd2 | 9979 | print_subexp (exp, pos, stream, PREC_SUFFIX); |
0b48a291 | 9980 | fputs_filtered (" in ", stream); |
4c4b4cd2 PH |
9981 | print_subexp (exp, pos, stream, PREC_EQUAL); |
9982 | fputs_filtered (" .. ", stream); | |
9983 | print_subexp (exp, pos, stream, PREC_EQUAL); | |
9984 | if (prec >= PREC_EQUAL) | |
76a01679 JB |
9985 | fputs_filtered (")", stream); |
9986 | return; | |
4c4b4cd2 PH |
9987 | |
9988 | case OP_ATR_FIRST: | |
9989 | case OP_ATR_LAST: | |
9990 | case OP_ATR_LENGTH: | |
9991 | case OP_ATR_IMAGE: | |
9992 | case OP_ATR_MAX: | |
9993 | case OP_ATR_MIN: | |
9994 | case OP_ATR_MODULUS: | |
9995 | case OP_ATR_POS: | |
9996 | case OP_ATR_SIZE: | |
9997 | case OP_ATR_TAG: | |
9998 | case OP_ATR_VAL: | |
4c4b4cd2 | 9999 | if (exp->elts[*pos].opcode == OP_TYPE) |
76a01679 JB |
10000 | { |
10001 | if (TYPE_CODE (exp->elts[*pos + 1].type) != TYPE_CODE_VOID) | |
10002 | LA_PRINT_TYPE (exp->elts[*pos + 1].type, "", stream, 0, 0); | |
10003 | *pos += 3; | |
10004 | } | |
4c4b4cd2 | 10005 | else |
76a01679 | 10006 | print_subexp (exp, pos, stream, PREC_SUFFIX); |
4c4b4cd2 PH |
10007 | fprintf_filtered (stream, "'%s", ada_attribute_name (op)); |
10008 | if (nargs > 1) | |
76a01679 JB |
10009 | { |
10010 | int tem; | |
10011 | for (tem = 1; tem < nargs; tem += 1) | |
10012 | { | |
10013 | fputs_filtered ((tem == 1) ? " (" : ", ", stream); | |
10014 | print_subexp (exp, pos, stream, PREC_ABOVE_COMMA); | |
10015 | } | |
10016 | fputs_filtered (")", stream); | |
10017 | } | |
4c4b4cd2 | 10018 | return; |
14f9c5c9 | 10019 | |
4c4b4cd2 | 10020 | case UNOP_QUAL: |
4c4b4cd2 PH |
10021 | type_print (exp->elts[pc + 1].type, "", stream, 0); |
10022 | fputs_filtered ("'(", stream); | |
10023 | print_subexp (exp, pos, stream, PREC_PREFIX); | |
10024 | fputs_filtered (")", stream); | |
10025 | return; | |
14f9c5c9 | 10026 | |
4c4b4cd2 | 10027 | case UNOP_IN_RANGE: |
323e0a4a | 10028 | /* XXX: sprint_subexp */ |
4c4b4cd2 | 10029 | print_subexp (exp, pos, stream, PREC_SUFFIX); |
0b48a291 | 10030 | fputs_filtered (" in ", stream); |
4c4b4cd2 PH |
10031 | LA_PRINT_TYPE (exp->elts[pc + 1].type, "", stream, 1, 0); |
10032 | return; | |
52ce6436 PH |
10033 | |
10034 | case OP_DISCRETE_RANGE: | |
10035 | print_subexp (exp, pos, stream, PREC_SUFFIX); | |
10036 | fputs_filtered ("..", stream); | |
10037 | print_subexp (exp, pos, stream, PREC_SUFFIX); | |
10038 | return; | |
10039 | ||
10040 | case OP_OTHERS: | |
10041 | fputs_filtered ("others => ", stream); | |
10042 | print_subexp (exp, pos, stream, PREC_SUFFIX); | |
10043 | return; | |
10044 | ||
10045 | case OP_CHOICES: | |
10046 | for (i = 0; i < nargs-1; i += 1) | |
10047 | { | |
10048 | if (i > 0) | |
10049 | fputs_filtered ("|", stream); | |
10050 | print_subexp (exp, pos, stream, PREC_SUFFIX); | |
10051 | } | |
10052 | fputs_filtered (" => ", stream); | |
10053 | print_subexp (exp, pos, stream, PREC_SUFFIX); | |
10054 | return; | |
10055 | ||
10056 | case OP_POSITIONAL: | |
10057 | print_subexp (exp, pos, stream, PREC_SUFFIX); | |
10058 | return; | |
10059 | ||
10060 | case OP_AGGREGATE: | |
10061 | fputs_filtered ("(", stream); | |
10062 | for (i = 0; i < nargs; i += 1) | |
10063 | { | |
10064 | if (i > 0) | |
10065 | fputs_filtered (", ", stream); | |
10066 | print_subexp (exp, pos, stream, PREC_SUFFIX); | |
10067 | } | |
10068 | fputs_filtered (")", stream); | |
10069 | return; | |
4c4b4cd2 PH |
10070 | } |
10071 | } | |
14f9c5c9 AS |
10072 | |
10073 | /* Table mapping opcodes into strings for printing operators | |
10074 | and precedences of the operators. */ | |
10075 | ||
d2e4a39e AS |
10076 | static const struct op_print ada_op_print_tab[] = { |
10077 | {":=", BINOP_ASSIGN, PREC_ASSIGN, 1}, | |
10078 | {"or else", BINOP_LOGICAL_OR, PREC_LOGICAL_OR, 0}, | |
10079 | {"and then", BINOP_LOGICAL_AND, PREC_LOGICAL_AND, 0}, | |
10080 | {"or", BINOP_BITWISE_IOR, PREC_BITWISE_IOR, 0}, | |
10081 | {"xor", BINOP_BITWISE_XOR, PREC_BITWISE_XOR, 0}, | |
10082 | {"and", BINOP_BITWISE_AND, PREC_BITWISE_AND, 0}, | |
10083 | {"=", BINOP_EQUAL, PREC_EQUAL, 0}, | |
10084 | {"/=", BINOP_NOTEQUAL, PREC_EQUAL, 0}, | |
10085 | {"<=", BINOP_LEQ, PREC_ORDER, 0}, | |
10086 | {">=", BINOP_GEQ, PREC_ORDER, 0}, | |
10087 | {">", BINOP_GTR, PREC_ORDER, 0}, | |
10088 | {"<", BINOP_LESS, PREC_ORDER, 0}, | |
10089 | {">>", BINOP_RSH, PREC_SHIFT, 0}, | |
10090 | {"<<", BINOP_LSH, PREC_SHIFT, 0}, | |
10091 | {"+", BINOP_ADD, PREC_ADD, 0}, | |
10092 | {"-", BINOP_SUB, PREC_ADD, 0}, | |
10093 | {"&", BINOP_CONCAT, PREC_ADD, 0}, | |
10094 | {"*", BINOP_MUL, PREC_MUL, 0}, | |
10095 | {"/", BINOP_DIV, PREC_MUL, 0}, | |
10096 | {"rem", BINOP_REM, PREC_MUL, 0}, | |
10097 | {"mod", BINOP_MOD, PREC_MUL, 0}, | |
10098 | {"**", BINOP_EXP, PREC_REPEAT, 0}, | |
10099 | {"@", BINOP_REPEAT, PREC_REPEAT, 0}, | |
10100 | {"-", UNOP_NEG, PREC_PREFIX, 0}, | |
10101 | {"+", UNOP_PLUS, PREC_PREFIX, 0}, | |
10102 | {"not ", UNOP_LOGICAL_NOT, PREC_PREFIX, 0}, | |
10103 | {"not ", UNOP_COMPLEMENT, PREC_PREFIX, 0}, | |
10104 | {"abs ", UNOP_ABS, PREC_PREFIX, 0}, | |
4c4b4cd2 PH |
10105 | {".all", UNOP_IND, PREC_SUFFIX, 1}, |
10106 | {"'access", UNOP_ADDR, PREC_SUFFIX, 1}, | |
10107 | {"'size", OP_ATR_SIZE, PREC_SUFFIX, 1}, | |
d2e4a39e | 10108 | {NULL, 0, 0, 0} |
14f9c5c9 AS |
10109 | }; |
10110 | \f | |
6c038f32 | 10111 | /* Fundamental Ada Types */ |
14f9c5c9 AS |
10112 | |
10113 | /* Create a fundamental Ada type using default reasonable for the current | |
10114 | target machine. | |
10115 | ||
10116 | Some object/debugging file formats (DWARF version 1, COFF, etc) do not | |
10117 | define fundamental types such as "int" or "double". Others (stabs or | |
10118 | DWARF version 2, etc) do define fundamental types. For the formats which | |
10119 | don't provide fundamental types, gdb can create such types using this | |
10120 | function. | |
10121 | ||
10122 | FIXME: Some compilers distinguish explicitly signed integral types | |
10123 | (signed short, signed int, signed long) from "regular" integral types | |
10124 | (short, int, long) in the debugging information. There is some dis- | |
10125 | agreement as to how useful this feature is. In particular, gcc does | |
10126 | not support this. Also, only some debugging formats allow the | |
10127 | distinction to be passed on to a debugger. For now, we always just | |
10128 | use "short", "int", or "long" as the type name, for both the implicit | |
10129 | and explicitly signed types. This also makes life easier for the | |
10130 | gdb test suite since we don't have to account for the differences | |
10131 | in output depending upon what the compiler and debugging format | |
10132 | support. We will probably have to re-examine the issue when gdb | |
10133 | starts taking it's fundamental type information directly from the | |
10134 | debugging information supplied by the compiler. fnf@cygnus.com */ | |
10135 | ||
10136 | static struct type * | |
ebf56fd3 | 10137 | ada_create_fundamental_type (struct objfile *objfile, int typeid) |
14f9c5c9 AS |
10138 | { |
10139 | struct type *type = NULL; | |
10140 | ||
10141 | switch (typeid) | |
10142 | { | |
d2e4a39e AS |
10143 | default: |
10144 | /* FIXME: For now, if we are asked to produce a type not in this | |
10145 | language, create the equivalent of a C integer type with the | |
10146 | name "<?type?>". When all the dust settles from the type | |
4c4b4cd2 | 10147 | reconstruction work, this should probably become an error. */ |
d2e4a39e | 10148 | type = init_type (TYPE_CODE_INT, |
4c4b4cd2 PH |
10149 | TARGET_INT_BIT / TARGET_CHAR_BIT, |
10150 | 0, "<?type?>", objfile); | |
323e0a4a | 10151 | warning (_("internal error: no Ada fundamental type %d"), typeid); |
d2e4a39e AS |
10152 | break; |
10153 | case FT_VOID: | |
10154 | type = init_type (TYPE_CODE_VOID, | |
4c4b4cd2 PH |
10155 | TARGET_CHAR_BIT / TARGET_CHAR_BIT, |
10156 | 0, "void", objfile); | |
d2e4a39e AS |
10157 | break; |
10158 | case FT_CHAR: | |
10159 | type = init_type (TYPE_CODE_INT, | |
4c4b4cd2 PH |
10160 | TARGET_CHAR_BIT / TARGET_CHAR_BIT, |
10161 | 0, "character", objfile); | |
d2e4a39e AS |
10162 | break; |
10163 | case FT_SIGNED_CHAR: | |
10164 | type = init_type (TYPE_CODE_INT, | |
4c4b4cd2 PH |
10165 | TARGET_CHAR_BIT / TARGET_CHAR_BIT, |
10166 | 0, "signed char", objfile); | |
d2e4a39e AS |
10167 | break; |
10168 | case FT_UNSIGNED_CHAR: | |
10169 | type = init_type (TYPE_CODE_INT, | |
4c4b4cd2 PH |
10170 | TARGET_CHAR_BIT / TARGET_CHAR_BIT, |
10171 | TYPE_FLAG_UNSIGNED, "unsigned char", objfile); | |
d2e4a39e AS |
10172 | break; |
10173 | case FT_SHORT: | |
10174 | type = init_type (TYPE_CODE_INT, | |
4c4b4cd2 PH |
10175 | TARGET_SHORT_BIT / TARGET_CHAR_BIT, |
10176 | 0, "short_integer", objfile); | |
d2e4a39e AS |
10177 | break; |
10178 | case FT_SIGNED_SHORT: | |
10179 | type = init_type (TYPE_CODE_INT, | |
4c4b4cd2 PH |
10180 | TARGET_SHORT_BIT / TARGET_CHAR_BIT, |
10181 | 0, "short_integer", objfile); | |
d2e4a39e AS |
10182 | break; |
10183 | case FT_UNSIGNED_SHORT: | |
10184 | type = init_type (TYPE_CODE_INT, | |
4c4b4cd2 PH |
10185 | TARGET_SHORT_BIT / TARGET_CHAR_BIT, |
10186 | TYPE_FLAG_UNSIGNED, "unsigned short", objfile); | |
d2e4a39e AS |
10187 | break; |
10188 | case FT_INTEGER: | |
10189 | type = init_type (TYPE_CODE_INT, | |
4c4b4cd2 PH |
10190 | TARGET_INT_BIT / TARGET_CHAR_BIT, |
10191 | 0, "integer", objfile); | |
d2e4a39e AS |
10192 | break; |
10193 | case FT_SIGNED_INTEGER: | |
72d5681a PH |
10194 | type = init_type (TYPE_CODE_INT, TARGET_INT_BIT / |
10195 | TARGET_CHAR_BIT, | |
10196 | 0, "integer", objfile); /* FIXME -fnf */ | |
d2e4a39e AS |
10197 | break; |
10198 | case FT_UNSIGNED_INTEGER: | |
10199 | type = init_type (TYPE_CODE_INT, | |
4c4b4cd2 PH |
10200 | TARGET_INT_BIT / TARGET_CHAR_BIT, |
10201 | TYPE_FLAG_UNSIGNED, "unsigned int", objfile); | |
d2e4a39e AS |
10202 | break; |
10203 | case FT_LONG: | |
10204 | type = init_type (TYPE_CODE_INT, | |
4c4b4cd2 PH |
10205 | TARGET_LONG_BIT / TARGET_CHAR_BIT, |
10206 | 0, "long_integer", objfile); | |
d2e4a39e AS |
10207 | break; |
10208 | case FT_SIGNED_LONG: | |
10209 | type = init_type (TYPE_CODE_INT, | |
4c4b4cd2 PH |
10210 | TARGET_LONG_BIT / TARGET_CHAR_BIT, |
10211 | 0, "long_integer", objfile); | |
d2e4a39e AS |
10212 | break; |
10213 | case FT_UNSIGNED_LONG: | |
10214 | type = init_type (TYPE_CODE_INT, | |
4c4b4cd2 PH |
10215 | TARGET_LONG_BIT / TARGET_CHAR_BIT, |
10216 | TYPE_FLAG_UNSIGNED, "unsigned long", objfile); | |
d2e4a39e AS |
10217 | break; |
10218 | case FT_LONG_LONG: | |
10219 | type = init_type (TYPE_CODE_INT, | |
4c4b4cd2 PH |
10220 | TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT, |
10221 | 0, "long_long_integer", objfile); | |
d2e4a39e AS |
10222 | break; |
10223 | case FT_SIGNED_LONG_LONG: | |
10224 | type = init_type (TYPE_CODE_INT, | |
4c4b4cd2 PH |
10225 | TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT, |
10226 | 0, "long_long_integer", objfile); | |
d2e4a39e AS |
10227 | break; |
10228 | case FT_UNSIGNED_LONG_LONG: | |
10229 | type = init_type (TYPE_CODE_INT, | |
4c4b4cd2 PH |
10230 | TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT, |
10231 | TYPE_FLAG_UNSIGNED, "unsigned long long", objfile); | |
d2e4a39e AS |
10232 | break; |
10233 | case FT_FLOAT: | |
10234 | type = init_type (TYPE_CODE_FLT, | |
4c4b4cd2 PH |
10235 | TARGET_FLOAT_BIT / TARGET_CHAR_BIT, |
10236 | 0, "float", objfile); | |
d2e4a39e AS |
10237 | break; |
10238 | case FT_DBL_PREC_FLOAT: | |
10239 | type = init_type (TYPE_CODE_FLT, | |
4c4b4cd2 PH |
10240 | TARGET_DOUBLE_BIT / TARGET_CHAR_BIT, |
10241 | 0, "long_float", objfile); | |
d2e4a39e AS |
10242 | break; |
10243 | case FT_EXT_PREC_FLOAT: | |
10244 | type = init_type (TYPE_CODE_FLT, | |
4c4b4cd2 PH |
10245 | TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT, |
10246 | 0, "long_long_float", objfile); | |
d2e4a39e AS |
10247 | break; |
10248 | } | |
14f9c5c9 AS |
10249 | return (type); |
10250 | } | |
10251 | ||
72d5681a PH |
10252 | enum ada_primitive_types { |
10253 | ada_primitive_type_int, | |
10254 | ada_primitive_type_long, | |
10255 | ada_primitive_type_short, | |
10256 | ada_primitive_type_char, | |
10257 | ada_primitive_type_float, | |
10258 | ada_primitive_type_double, | |
10259 | ada_primitive_type_void, | |
10260 | ada_primitive_type_long_long, | |
10261 | ada_primitive_type_long_double, | |
10262 | ada_primitive_type_natural, | |
10263 | ada_primitive_type_positive, | |
10264 | ada_primitive_type_system_address, | |
10265 | nr_ada_primitive_types | |
10266 | }; | |
6c038f32 PH |
10267 | |
10268 | static void | |
72d5681a PH |
10269 | ada_language_arch_info (struct gdbarch *current_gdbarch, |
10270 | struct language_arch_info *lai) | |
10271 | { | |
10272 | const struct builtin_type *builtin = builtin_type (current_gdbarch); | |
10273 | lai->primitive_type_vector | |
10274 | = GDBARCH_OBSTACK_CALLOC (current_gdbarch, nr_ada_primitive_types + 1, | |
10275 | struct type *); | |
10276 | lai->primitive_type_vector [ada_primitive_type_int] = | |
6c038f32 PH |
10277 | init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT, |
10278 | 0, "integer", (struct objfile *) NULL); | |
72d5681a | 10279 | lai->primitive_type_vector [ada_primitive_type_long] = |
6c038f32 PH |
10280 | init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT, |
10281 | 0, "long_integer", (struct objfile *) NULL); | |
72d5681a | 10282 | lai->primitive_type_vector [ada_primitive_type_short] = |
6c038f32 PH |
10283 | init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT, |
10284 | 0, "short_integer", (struct objfile *) NULL); | |
61ee279c PH |
10285 | lai->string_char_type = |
10286 | lai->primitive_type_vector [ada_primitive_type_char] = | |
6c038f32 PH |
10287 | init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT, |
10288 | 0, "character", (struct objfile *) NULL); | |
72d5681a | 10289 | lai->primitive_type_vector [ada_primitive_type_float] = |
6c038f32 PH |
10290 | init_type (TYPE_CODE_FLT, TARGET_FLOAT_BIT / TARGET_CHAR_BIT, |
10291 | 0, "float", (struct objfile *) NULL); | |
72d5681a | 10292 | lai->primitive_type_vector [ada_primitive_type_double] = |
6c038f32 PH |
10293 | init_type (TYPE_CODE_FLT, TARGET_DOUBLE_BIT / TARGET_CHAR_BIT, |
10294 | 0, "long_float", (struct objfile *) NULL); | |
72d5681a | 10295 | lai->primitive_type_vector [ada_primitive_type_long_long] = |
6c038f32 PH |
10296 | init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT, |
10297 | 0, "long_long_integer", (struct objfile *) NULL); | |
72d5681a | 10298 | lai->primitive_type_vector [ada_primitive_type_long_double] = |
6c038f32 PH |
10299 | init_type (TYPE_CODE_FLT, TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT, |
10300 | 0, "long_long_float", (struct objfile *) NULL); | |
72d5681a | 10301 | lai->primitive_type_vector [ada_primitive_type_natural] = |
6c038f32 PH |
10302 | init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT, |
10303 | 0, "natural", (struct objfile *) NULL); | |
72d5681a | 10304 | lai->primitive_type_vector [ada_primitive_type_positive] = |
6c038f32 PH |
10305 | init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT, |
10306 | 0, "positive", (struct objfile *) NULL); | |
72d5681a | 10307 | lai->primitive_type_vector [ada_primitive_type_void] = builtin->builtin_void; |
6c038f32 | 10308 | |
72d5681a | 10309 | lai->primitive_type_vector [ada_primitive_type_system_address] = |
6c038f32 PH |
10310 | lookup_pointer_type (init_type (TYPE_CODE_VOID, 1, 0, "void", |
10311 | (struct objfile *) NULL)); | |
72d5681a PH |
10312 | TYPE_NAME (lai->primitive_type_vector [ada_primitive_type_system_address]) |
10313 | = "system__address"; | |
6c038f32 | 10314 | } |
6c038f32 PH |
10315 | \f |
10316 | /* Language vector */ | |
10317 | ||
10318 | /* Not really used, but needed in the ada_language_defn. */ | |
10319 | ||
10320 | static void | |
10321 | emit_char (int c, struct ui_file *stream, int quoter) | |
10322 | { | |
10323 | ada_emit_char (c, stream, quoter, 1); | |
10324 | } | |
10325 | ||
10326 | static int | |
10327 | parse (void) | |
10328 | { | |
10329 | warnings_issued = 0; | |
10330 | return ada_parse (); | |
10331 | } | |
10332 | ||
10333 | static const struct exp_descriptor ada_exp_descriptor = { | |
10334 | ada_print_subexp, | |
10335 | ada_operator_length, | |
10336 | ada_op_name, | |
10337 | ada_dump_subexp_body, | |
10338 | ada_evaluate_subexp | |
10339 | }; | |
10340 | ||
10341 | const struct language_defn ada_language_defn = { | |
10342 | "ada", /* Language name */ | |
10343 | language_ada, | |
72d5681a | 10344 | NULL, |
6c038f32 PH |
10345 | range_check_off, |
10346 | type_check_off, | |
10347 | case_sensitive_on, /* Yes, Ada is case-insensitive, but | |
10348 | that's not quite what this means. */ | |
6c038f32 PH |
10349 | array_row_major, |
10350 | &ada_exp_descriptor, | |
10351 | parse, | |
10352 | ada_error, | |
10353 | resolve, | |
10354 | ada_printchar, /* Print a character constant */ | |
10355 | ada_printstr, /* Function to print string constant */ | |
10356 | emit_char, /* Function to print single char (not used) */ | |
10357 | ada_create_fundamental_type, /* Create fundamental type in this language */ | |
10358 | ada_print_type, /* Print a type using appropriate syntax */ | |
10359 | ada_val_print, /* Print a value using appropriate syntax */ | |
10360 | ada_value_print, /* Print a top-level value */ | |
10361 | NULL, /* Language specific skip_trampoline */ | |
10362 | NULL, /* value_of_this */ | |
10363 | ada_lookup_symbol_nonlocal, /* Looking up non-local symbols. */ | |
10364 | basic_lookup_transparent_type, /* lookup_transparent_type */ | |
10365 | ada_la_decode, /* Language specific symbol demangler */ | |
10366 | NULL, /* Language specific class_name_from_physname */ | |
10367 | ada_op_print_tab, /* expression operators for printing */ | |
10368 | 0, /* c-style arrays */ | |
10369 | 1, /* String lower bound */ | |
72d5681a | 10370 | NULL, |
6c038f32 | 10371 | ada_get_gdb_completer_word_break_characters, |
72d5681a | 10372 | ada_language_arch_info, |
e79af960 | 10373 | ada_print_array_index, |
6c038f32 PH |
10374 | LANG_MAGIC |
10375 | }; | |
10376 | ||
d2e4a39e | 10377 | void |
6c038f32 | 10378 | _initialize_ada_language (void) |
14f9c5c9 | 10379 | { |
6c038f32 PH |
10380 | add_language (&ada_language_defn); |
10381 | ||
10382 | varsize_limit = 65536; | |
6c038f32 PH |
10383 | |
10384 | obstack_init (&symbol_list_obstack); | |
10385 | ||
10386 | decoded_names_store = htab_create_alloc | |
10387 | (256, htab_hash_string, (int (*)(const void *, const void *)) streq, | |
10388 | NULL, xcalloc, xfree); | |
14f9c5c9 | 10389 | } |