1 /* Ada language support routines for GDB, the GNU debugger. Copyright (C)
3 1992, 1993, 1994, 1997, 1998, 1999, 2000, 2003, 2004, 2005, 2007, 2008,
4 2009 Free Software Foundation, Inc.
6 This file is part of GDB.
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 3 of the License, or
11 (at your option) any later version.
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.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "gdb_string.h"
28 #include "gdb_regex.h"
33 #include "expression.h"
34 #include "parser-defs.h"
40 #include "breakpoint.h"
43 #include "gdb_obstack.h"
45 #include "completer.h"
52 #include "dictionary.h"
53 #include "exceptions.h"
63 #include "mi/mi-common.h"
65 /* Define whether or not the C operator '/' truncates towards zero for
66 differently signed operands (truncation direction is undefined in C).
67 Copied from valarith.c. */
69 #ifndef TRUNCATION_TOWARDS_ZERO
70 #define TRUNCATION_TOWARDS_ZERO ((-5 / 2) == -2)
73 static struct type *desc_base_type (struct type *);
75 static struct type *desc_bounds_type (struct type *);
77 static struct value *desc_bounds (struct value *);
79 static int fat_pntr_bounds_bitpos (struct type *);
81 static int fat_pntr_bounds_bitsize (struct type *);
83 static struct type *desc_data_target_type (struct type *);
85 static struct value *desc_data (struct value *);
87 static int fat_pntr_data_bitpos (struct type *);
89 static int fat_pntr_data_bitsize (struct type *);
91 static struct value *desc_one_bound (struct value *, int, int);
93 static int desc_bound_bitpos (struct type *, int, int);
95 static int desc_bound_bitsize (struct type *, int, int);
97 static struct type *desc_index_type (struct type *, int);
99 static int desc_arity (struct type *);
101 static int ada_type_match (struct type *, struct type *, int);
103 static int ada_args_match (struct symbol *, struct value **, int);
105 static int full_match (const char *, const char *);
107 static struct value *make_array_descriptor (struct type *, struct value *);
109 static void ada_add_block_symbols (struct obstack *,
110 struct block *, const char *,
111 domain_enum, struct objfile *, int);
113 static int is_nonfunction (struct ada_symbol_info *, int);
115 static void add_defn_to_vec (struct obstack *, struct symbol *,
118 static int num_defns_collected (struct obstack *);
120 static struct ada_symbol_info *defns_collected (struct obstack *, int);
122 static struct value *resolve_subexp (struct expression **, int *, int,
125 static void replace_operator_with_call (struct expression **, int, int, int,
126 struct symbol *, struct block *);
128 static int possible_user_operator_p (enum exp_opcode, struct value **);
130 static char *ada_op_name (enum exp_opcode);
132 static const char *ada_decoded_op_name (enum exp_opcode);
134 static int numeric_type_p (struct type *);
136 static int integer_type_p (struct type *);
138 static int scalar_type_p (struct type *);
140 static int discrete_type_p (struct type *);
142 static enum ada_renaming_category parse_old_style_renaming (struct type *,
147 static struct symbol *find_old_style_renaming_symbol (const char *,
150 static struct type *ada_lookup_struct_elt_type (struct type *, char *,
153 static struct value *evaluate_subexp_type (struct expression *, int *);
155 static struct type *ada_find_parallel_type_with_name (struct type *,
158 static int is_dynamic_field (struct type *, int);
160 static struct type *to_fixed_variant_branch_type (struct type *,
162 CORE_ADDR, struct value *);
164 static struct type *to_fixed_array_type (struct type *, struct value *, int);
166 static struct type *to_fixed_range_type (struct type *, struct value *);
168 static struct type *to_static_fixed_type (struct type *);
169 static struct type *static_unwrap_type (struct type *type);
171 static struct value *unwrap_value (struct value *);
173 static struct type *constrained_packed_array_type (struct type *, long *);
175 static struct type *decode_constrained_packed_array_type (struct type *);
177 static long decode_packed_array_bitsize (struct type *);
179 static struct value *decode_constrained_packed_array (struct value *);
181 static int ada_is_packed_array_type (struct type *);
183 static int ada_is_unconstrained_packed_array_type (struct type *);
185 static struct value *value_subscript_packed (struct value *, int,
188 static void move_bits (gdb_byte *, int, const gdb_byte *, int, int, int);
190 static struct value *coerce_unspec_val_to_type (struct value *,
193 static struct value *get_var_value (char *, char *);
195 static int lesseq_defined_than (struct symbol *, struct symbol *);
197 static int equiv_types (struct type *, struct type *);
199 static int is_name_suffix (const char *);
201 static int advance_wild_match (const char **, const char *, int);
203 static int wild_match (const char *, const char *);
205 static struct value *ada_coerce_ref (struct value *);
207 static LONGEST pos_atr (struct value *);
209 static struct value *value_pos_atr (struct type *, struct value *);
211 static struct value *value_val_atr (struct type *, struct value *);
213 static struct symbol *standard_lookup (const char *, const struct block *,
216 static struct value *ada_search_struct_field (char *, struct value *, int,
219 static struct value *ada_value_primitive_field (struct value *, int, int,
222 static int find_struct_field (char *, struct type *, int,
223 struct type **, int *, int *, int *, int *);
225 static struct value *ada_to_fixed_value_create (struct type *, CORE_ADDR,
228 static int ada_resolve_function (struct ada_symbol_info *, int,
229 struct value **, int, const char *,
232 static int ada_is_direct_array_type (struct type *);
234 static void ada_language_arch_info (struct gdbarch *,
235 struct language_arch_info *);
237 static void check_size (const struct type *);
239 static struct value *ada_index_struct_field (int, struct value *, int,
242 static struct value *assign_aggregate (struct value *, struct value *,
246 static void aggregate_assign_from_choices (struct value *, struct value *,
248 int *, LONGEST *, int *,
249 int, LONGEST, LONGEST);
251 static void aggregate_assign_positional (struct value *, struct value *,
253 int *, LONGEST *, int *, int,
257 static void aggregate_assign_others (struct value *, struct value *,
259 int *, LONGEST *, int, LONGEST, LONGEST);
262 static void add_component_interval (LONGEST, LONGEST, LONGEST *, int *, int);
265 static struct value *ada_evaluate_subexp (struct type *, struct expression *,
268 static void ada_forward_operator_length (struct expression *, int, int *,
273 /* Maximum-sized dynamic type. */
274 static unsigned int varsize_limit;
276 /* FIXME: brobecker/2003-09-17: No longer a const because it is
277 returned by a function that does not return a const char *. */
278 static char *ada_completer_word_break_characters =
280 " \t\n!@#%^&*()+=|~`}{[]\";:?/,-";
282 " \t\n!@#$%^&*()+=|~`}{[]\";:?/,-";
285 /* The name of the symbol to use to get the name of the main subprogram. */
286 static const char ADA_MAIN_PROGRAM_SYMBOL_NAME[]
287 = "__gnat_ada_main_program_name";
289 /* Limit on the number of warnings to raise per expression evaluation. */
290 static int warning_limit = 2;
292 /* Number of warning messages issued; reset to 0 by cleanups after
293 expression evaluation. */
294 static int warnings_issued = 0;
296 static const char *known_runtime_file_name_patterns[] = {
297 ADA_KNOWN_RUNTIME_FILE_NAME_PATTERNS NULL
300 static const char *known_auxiliary_function_name_patterns[] = {
301 ADA_KNOWN_AUXILIARY_FUNCTION_NAME_PATTERNS NULL
304 /* Space for allocating results of ada_lookup_symbol_list. */
305 static struct obstack symbol_list_obstack;
307 /* Inferior-specific data. */
309 /* Per-inferior data for this module. */
311 struct ada_inferior_data
313 /* The ada__tags__type_specific_data type, which is used when decoding
314 tagged types. With older versions of GNAT, this type was directly
315 accessible through a component ("tsd") in the object tag. But this
316 is no longer the case, so we cache it for each inferior. */
317 struct type *tsd_type;
320 /* Our key to this module's inferior data. */
321 static const struct inferior_data *ada_inferior_data;
323 /* A cleanup routine for our inferior data. */
325 ada_inferior_data_cleanup (struct inferior *inf, void *arg)
327 struct ada_inferior_data *data;
329 data = inferior_data (inf, ada_inferior_data);
334 /* Return our inferior data for the given inferior (INF).
336 This function always returns a valid pointer to an allocated
337 ada_inferior_data structure. If INF's inferior data has not
338 been previously set, this functions creates a new one with all
339 fields set to zero, sets INF's inferior to it, and then returns
340 a pointer to that newly allocated ada_inferior_data. */
342 static struct ada_inferior_data *
343 get_ada_inferior_data (struct inferior *inf)
345 struct ada_inferior_data *data;
347 data = inferior_data (inf, ada_inferior_data);
350 data = XZALLOC (struct ada_inferior_data);
351 set_inferior_data (inf, ada_inferior_data, data);
357 /* Perform all necessary cleanups regarding our module's inferior data
358 that is required after the inferior INF just exited. */
361 ada_inferior_exit (struct inferior *inf)
363 ada_inferior_data_cleanup (inf, NULL);
364 set_inferior_data (inf, ada_inferior_data, NULL);
369 /* If TYPE is a TYPE_CODE_TYPEDEF type, return the target type after
370 all typedef layers have been peeled. Otherwise, return TYPE.
372 Normally, we really expect a typedef type to only have 1 typedef layer.
373 In other words, we really expect the target type of a typedef type to be
374 a non-typedef type. This is particularly true for Ada units, because
375 the language does not have a typedef vs not-typedef distinction.
376 In that respect, the Ada compiler has been trying to eliminate as many
377 typedef definitions in the debugging information, since they generally
378 do not bring any extra information (we still use typedef under certain
379 circumstances related mostly to the GNAT encoding).
381 Unfortunately, we have seen situations where the debugging information
382 generated by the compiler leads to such multiple typedef layers. For
383 instance, consider the following example with stabs:
385 .stabs "pck__float_array___XUP:Tt(0,46)=s16P_ARRAY:(0,47)=[...]"[...]
386 .stabs "pck__float_array___XUP:t(0,36)=(0,46)",128,0,6,0
388 This is an error in the debugging information which causes type
389 pck__float_array___XUP to be defined twice, and the second time,
390 it is defined as a typedef of a typedef.
392 This is on the fringe of legality as far as debugging information is
393 concerned, and certainly unexpected. But it is easy to handle these
394 situations correctly, so we can afford to be lenient in this case. */
397 ada_typedef_target_type (struct type *type)
399 while (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
400 type = TYPE_TARGET_TYPE (type);
404 /* Given DECODED_NAME a string holding a symbol name in its
405 decoded form (ie using the Ada dotted notation), returns
406 its unqualified name. */
409 ada_unqualified_name (const char *decoded_name)
411 const char *result = strrchr (decoded_name, '.');
414 result++; /* Skip the dot... */
416 result = decoded_name;
421 /* Return a string starting with '<', followed by STR, and '>'.
422 The result is good until the next call. */
425 add_angle_brackets (const char *str)
427 static char *result = NULL;
430 result = xstrprintf ("<%s>", str);
435 ada_get_gdb_completer_word_break_characters (void)
437 return ada_completer_word_break_characters;
440 /* Print an array element index using the Ada syntax. */
443 ada_print_array_index (struct value *index_value, struct ui_file *stream,
444 const struct value_print_options *options)
446 LA_VALUE_PRINT (index_value, stream, options);
447 fprintf_filtered (stream, " => ");
450 /* Assuming VECT points to an array of *SIZE objects of size
451 ELEMENT_SIZE, grow it to contain at least MIN_SIZE objects,
452 updating *SIZE as necessary and returning the (new) array. */
455 grow_vect (void *vect, size_t *size, size_t min_size, int element_size)
457 if (*size < min_size)
460 if (*size < min_size)
462 vect = xrealloc (vect, *size * element_size);
467 /* True (non-zero) iff TARGET matches FIELD_NAME up to any trailing
468 suffix of FIELD_NAME beginning "___". */
471 field_name_match (const char *field_name, const char *target)
473 int len = strlen (target);
476 (strncmp (field_name, target, len) == 0
477 && (field_name[len] == '\0'
478 || (strncmp (field_name + len, "___", 3) == 0
479 && strcmp (field_name + strlen (field_name) - 6,
484 /* Assuming TYPE is a TYPE_CODE_STRUCT or a TYPE_CODE_TYPDEF to
485 a TYPE_CODE_STRUCT, find the field whose name matches FIELD_NAME,
486 and return its index. This function also handles fields whose name
487 have ___ suffixes because the compiler sometimes alters their name
488 by adding such a suffix to represent fields with certain constraints.
489 If the field could not be found, return a negative number if
490 MAYBE_MISSING is set. Otherwise raise an error. */
493 ada_get_field_index (const struct type *type, const char *field_name,
497 struct type *struct_type = check_typedef ((struct type *) type);
499 for (fieldno = 0; fieldno < TYPE_NFIELDS (struct_type); fieldno++)
500 if (field_name_match (TYPE_FIELD_NAME (struct_type, fieldno), field_name))
504 error (_("Unable to find field %s in struct %s. Aborting"),
505 field_name, TYPE_NAME (struct_type));
510 /* The length of the prefix of NAME prior to any "___" suffix. */
513 ada_name_prefix_len (const char *name)
519 const char *p = strstr (name, "___");
522 return strlen (name);
528 /* Return non-zero if SUFFIX is a suffix of STR.
529 Return zero if STR is null. */
532 is_suffix (const char *str, const char *suffix)
539 len2 = strlen (suffix);
540 return (len1 >= len2 && strcmp (str + len1 - len2, suffix) == 0);
543 /* The contents of value VAL, treated as a value of type TYPE. The
544 result is an lval in memory if VAL is. */
546 static struct value *
547 coerce_unspec_val_to_type (struct value *val, struct type *type)
549 type = ada_check_typedef (type);
550 if (value_type (val) == type)
554 struct value *result;
556 /* Make sure that the object size is not unreasonable before
557 trying to allocate some memory for it. */
561 || TYPE_LENGTH (type) > TYPE_LENGTH (value_type (val)))
562 result = allocate_value_lazy (type);
565 result = allocate_value (type);
566 memcpy (value_contents_raw (result), value_contents (val),
569 set_value_component_location (result, val);
570 set_value_bitsize (result, value_bitsize (val));
571 set_value_bitpos (result, value_bitpos (val));
572 set_value_address (result, value_address (val));
577 static const gdb_byte *
578 cond_offset_host (const gdb_byte *valaddr, long offset)
583 return valaddr + offset;
587 cond_offset_target (CORE_ADDR address, long offset)
592 return address + offset;
595 /* Issue a warning (as for the definition of warning in utils.c, but
596 with exactly one argument rather than ...), unless the limit on the
597 number of warnings has passed during the evaluation of the current
600 /* FIXME: cagney/2004-10-10: This function is mimicking the behavior
601 provided by "complaint". */
602 static void lim_warning (const char *format, ...) ATTRIBUTE_PRINTF (1, 2);
605 lim_warning (const char *format, ...)
609 va_start (args, format);
610 warnings_issued += 1;
611 if (warnings_issued <= warning_limit)
612 vwarning (format, args);
617 /* Issue an error if the size of an object of type T is unreasonable,
618 i.e. if it would be a bad idea to allocate a value of this type in
622 check_size (const struct type *type)
624 if (TYPE_LENGTH (type) > varsize_limit)
625 error (_("object size is larger than varsize-limit"));
628 /* Maximum value of a SIZE-byte signed integer type. */
630 max_of_size (int size)
632 LONGEST top_bit = (LONGEST) 1 << (size * 8 - 2);
634 return top_bit | (top_bit - 1);
637 /* Minimum value of a SIZE-byte signed integer type. */
639 min_of_size (int size)
641 return -max_of_size (size) - 1;
644 /* Maximum value of a SIZE-byte unsigned integer type. */
646 umax_of_size (int size)
648 ULONGEST top_bit = (ULONGEST) 1 << (size * 8 - 1);
650 return top_bit | (top_bit - 1);
653 /* Maximum value of integral type T, as a signed quantity. */
655 max_of_type (struct type *t)
657 if (TYPE_UNSIGNED (t))
658 return (LONGEST) umax_of_size (TYPE_LENGTH (t));
660 return max_of_size (TYPE_LENGTH (t));
663 /* Minimum value of integral type T, as a signed quantity. */
665 min_of_type (struct type *t)
667 if (TYPE_UNSIGNED (t))
670 return min_of_size (TYPE_LENGTH (t));
673 /* The largest value in the domain of TYPE, a discrete type, as an integer. */
675 ada_discrete_type_high_bound (struct type *type)
677 switch (TYPE_CODE (type))
679 case TYPE_CODE_RANGE:
680 return TYPE_HIGH_BOUND (type);
682 return TYPE_FIELD_BITPOS (type, TYPE_NFIELDS (type) - 1);
687 return max_of_type (type);
689 error (_("Unexpected type in ada_discrete_type_high_bound."));
693 /* The largest value in the domain of TYPE, a discrete type, as an integer. */
695 ada_discrete_type_low_bound (struct type *type)
697 switch (TYPE_CODE (type))
699 case TYPE_CODE_RANGE:
700 return TYPE_LOW_BOUND (type);
702 return TYPE_FIELD_BITPOS (type, 0);
707 return min_of_type (type);
709 error (_("Unexpected type in ada_discrete_type_low_bound."));
713 /* The identity on non-range types. For range types, the underlying
714 non-range scalar type. */
717 base_type (struct type *type)
719 while (type != NULL && TYPE_CODE (type) == TYPE_CODE_RANGE)
721 if (type == TYPE_TARGET_TYPE (type) || TYPE_TARGET_TYPE (type) == NULL)
723 type = TYPE_TARGET_TYPE (type);
729 /* Language Selection */
731 /* If the main program is in Ada, return language_ada, otherwise return LANG
732 (the main program is in Ada iif the adainit symbol is found). */
735 ada_update_initial_language (enum language lang)
737 if (lookup_minimal_symbol ("adainit", (const char *) NULL,
738 (struct objfile *) NULL) != NULL)
744 /* If the main procedure is written in Ada, then return its name.
745 The result is good until the next call. Return NULL if the main
746 procedure doesn't appear to be in Ada. */
751 struct minimal_symbol *msym;
752 static char *main_program_name = NULL;
754 /* For Ada, the name of the main procedure is stored in a specific
755 string constant, generated by the binder. Look for that symbol,
756 extract its address, and then read that string. If we didn't find
757 that string, then most probably the main procedure is not written
759 msym = lookup_minimal_symbol (ADA_MAIN_PROGRAM_SYMBOL_NAME, NULL, NULL);
763 CORE_ADDR main_program_name_addr;
766 main_program_name_addr = SYMBOL_VALUE_ADDRESS (msym);
767 if (main_program_name_addr == 0)
768 error (_("Invalid address for Ada main program name."));
770 xfree (main_program_name);
771 target_read_string (main_program_name_addr, &main_program_name,
776 return main_program_name;
779 /* The main procedure doesn't seem to be in Ada. */
785 /* Table of Ada operators and their GNAT-encoded names. Last entry is pair
788 const struct ada_opname_map ada_opname_table[] = {
789 {"Oadd", "\"+\"", BINOP_ADD},
790 {"Osubtract", "\"-\"", BINOP_SUB},
791 {"Omultiply", "\"*\"", BINOP_MUL},
792 {"Odivide", "\"/\"", BINOP_DIV},
793 {"Omod", "\"mod\"", BINOP_MOD},
794 {"Orem", "\"rem\"", BINOP_REM},
795 {"Oexpon", "\"**\"", BINOP_EXP},
796 {"Olt", "\"<\"", BINOP_LESS},
797 {"Ole", "\"<=\"", BINOP_LEQ},
798 {"Ogt", "\">\"", BINOP_GTR},
799 {"Oge", "\">=\"", BINOP_GEQ},
800 {"Oeq", "\"=\"", BINOP_EQUAL},
801 {"One", "\"/=\"", BINOP_NOTEQUAL},
802 {"Oand", "\"and\"", BINOP_BITWISE_AND},
803 {"Oor", "\"or\"", BINOP_BITWISE_IOR},
804 {"Oxor", "\"xor\"", BINOP_BITWISE_XOR},
805 {"Oconcat", "\"&\"", BINOP_CONCAT},
806 {"Oabs", "\"abs\"", UNOP_ABS},
807 {"Onot", "\"not\"", UNOP_LOGICAL_NOT},
808 {"Oadd", "\"+\"", UNOP_PLUS},
809 {"Osubtract", "\"-\"", UNOP_NEG},
813 /* The "encoded" form of DECODED, according to GNAT conventions.
814 The result is valid until the next call to ada_encode. */
817 ada_encode (const char *decoded)
819 static char *encoding_buffer = NULL;
820 static size_t encoding_buffer_size = 0;
827 GROW_VECT (encoding_buffer, encoding_buffer_size,
828 2 * strlen (decoded) + 10);
831 for (p = decoded; *p != '\0'; p += 1)
835 encoding_buffer[k] = encoding_buffer[k + 1] = '_';
840 const struct ada_opname_map *mapping;
842 for (mapping = ada_opname_table;
843 mapping->encoded != NULL
844 && strncmp (mapping->decoded, p,
845 strlen (mapping->decoded)) != 0; mapping += 1)
847 if (mapping->encoded == NULL)
848 error (_("invalid Ada operator name: %s"), p);
849 strcpy (encoding_buffer + k, mapping->encoded);
850 k += strlen (mapping->encoded);
855 encoding_buffer[k] = *p;
860 encoding_buffer[k] = '\0';
861 return encoding_buffer;
864 /* Return NAME folded to lower case, or, if surrounded by single
865 quotes, unfolded, but with the quotes stripped away. Result good
869 ada_fold_name (const char *name)
871 static char *fold_buffer = NULL;
872 static size_t fold_buffer_size = 0;
874 int len = strlen (name);
875 GROW_VECT (fold_buffer, fold_buffer_size, len + 1);
879 strncpy (fold_buffer, name + 1, len - 2);
880 fold_buffer[len - 2] = '\000';
886 for (i = 0; i <= len; i += 1)
887 fold_buffer[i] = tolower (name[i]);
893 /* Return nonzero if C is either a digit or a lowercase alphabet character. */
896 is_lower_alphanum (const char c)
898 return (isdigit (c) || (isalpha (c) && islower (c)));
901 /* Remove either of these suffixes:
906 These are suffixes introduced by the compiler for entities such as
907 nested subprogram for instance, in order to avoid name clashes.
908 They do not serve any purpose for the debugger. */
911 ada_remove_trailing_digits (const char *encoded, int *len)
913 if (*len > 1 && isdigit (encoded[*len - 1]))
917 while (i > 0 && isdigit (encoded[i]))
919 if (i >= 0 && encoded[i] == '.')
921 else if (i >= 0 && encoded[i] == '$')
923 else if (i >= 2 && strncmp (encoded + i - 2, "___", 3) == 0)
925 else if (i >= 1 && strncmp (encoded + i - 1, "__", 2) == 0)
930 /* Remove the suffix introduced by the compiler for protected object
934 ada_remove_po_subprogram_suffix (const char *encoded, int *len)
936 /* Remove trailing N. */
938 /* Protected entry subprograms are broken into two
939 separate subprograms: The first one is unprotected, and has
940 a 'N' suffix; the second is the protected version, and has
941 the 'P' suffix. The second calls the first one after handling
942 the protection. Since the P subprograms are internally generated,
943 we leave these names undecoded, giving the user a clue that this
944 entity is internal. */
947 && encoded[*len - 1] == 'N'
948 && (isdigit (encoded[*len - 2]) || islower (encoded[*len - 2])))
952 /* Remove trailing X[bn]* suffixes (indicating names in package bodies). */
955 ada_remove_Xbn_suffix (const char *encoded, int *len)
959 while (i > 0 && (encoded[i] == 'b' || encoded[i] == 'n'))
962 if (encoded[i] != 'X')
968 if (isalnum (encoded[i-1]))
972 /* If ENCODED follows the GNAT entity encoding conventions, then return
973 the decoded form of ENCODED. Otherwise, return "<%s>" where "%s" is
976 The resulting string is valid until the next call of ada_decode.
977 If the string is unchanged by decoding, the original string pointer
981 ada_decode (const char *encoded)
988 static char *decoding_buffer = NULL;
989 static size_t decoding_buffer_size = 0;
991 /* The name of the Ada main procedure starts with "_ada_".
992 This prefix is not part of the decoded name, so skip this part
993 if we see this prefix. */
994 if (strncmp (encoded, "_ada_", 5) == 0)
997 /* If the name starts with '_', then it is not a properly encoded
998 name, so do not attempt to decode it. Similarly, if the name
999 starts with '<', the name should not be decoded. */
1000 if (encoded[0] == '_' || encoded[0] == '<')
1003 len0 = strlen (encoded);
1005 ada_remove_trailing_digits (encoded, &len0);
1006 ada_remove_po_subprogram_suffix (encoded, &len0);
1008 /* Remove the ___X.* suffix if present. Do not forget to verify that
1009 the suffix is located before the current "end" of ENCODED. We want
1010 to avoid re-matching parts of ENCODED that have previously been
1011 marked as discarded (by decrementing LEN0). */
1012 p = strstr (encoded, "___");
1013 if (p != NULL && p - encoded < len0 - 3)
1021 /* Remove any trailing TKB suffix. It tells us that this symbol
1022 is for the body of a task, but that information does not actually
1023 appear in the decoded name. */
1025 if (len0 > 3 && strncmp (encoded + len0 - 3, "TKB", 3) == 0)
1028 /* Remove any trailing TB suffix. The TB suffix is slightly different
1029 from the TKB suffix because it is used for non-anonymous task
1032 if (len0 > 2 && strncmp (encoded + len0 - 2, "TB", 2) == 0)
1035 /* Remove trailing "B" suffixes. */
1036 /* FIXME: brobecker/2006-04-19: Not sure what this are used for... */
1038 if (len0 > 1 && strncmp (encoded + len0 - 1, "B", 1) == 0)
1041 /* Make decoded big enough for possible expansion by operator name. */
1043 GROW_VECT (decoding_buffer, decoding_buffer_size, 2 * len0 + 1);
1044 decoded = decoding_buffer;
1046 /* Remove trailing __{digit}+ or trailing ${digit}+. */
1048 if (len0 > 1 && isdigit (encoded[len0 - 1]))
1051 while ((i >= 0 && isdigit (encoded[i]))
1052 || (i >= 1 && encoded[i] == '_' && isdigit (encoded[i - 1])))
1054 if (i > 1 && encoded[i] == '_' && encoded[i - 1] == '_')
1056 else if (encoded[i] == '$')
1060 /* The first few characters that are not alphabetic are not part
1061 of any encoding we use, so we can copy them over verbatim. */
1063 for (i = 0, j = 0; i < len0 && !isalpha (encoded[i]); i += 1, j += 1)
1064 decoded[j] = encoded[i];
1069 /* Is this a symbol function? */
1070 if (at_start_name && encoded[i] == 'O')
1074 for (k = 0; ada_opname_table[k].encoded != NULL; k += 1)
1076 int op_len = strlen (ada_opname_table[k].encoded);
1077 if ((strncmp (ada_opname_table[k].encoded + 1, encoded + i + 1,
1079 && !isalnum (encoded[i + op_len]))
1081 strcpy (decoded + j, ada_opname_table[k].decoded);
1084 j += strlen (ada_opname_table[k].decoded);
1088 if (ada_opname_table[k].encoded != NULL)
1093 /* Replace "TK__" with "__", which will eventually be translated
1094 into "." (just below). */
1096 if (i < len0 - 4 && strncmp (encoded + i, "TK__", 4) == 0)
1099 /* Replace "__B_{DIGITS}+__" sequences by "__", which will eventually
1100 be translated into "." (just below). These are internal names
1101 generated for anonymous blocks inside which our symbol is nested. */
1103 if (len0 - i > 5 && encoded [i] == '_' && encoded [i+1] == '_'
1104 && encoded [i+2] == 'B' && encoded [i+3] == '_'
1105 && isdigit (encoded [i+4]))
1109 while (k < len0 && isdigit (encoded[k]))
1110 k++; /* Skip any extra digit. */
1112 /* Double-check that the "__B_{DIGITS}+" sequence we found
1113 is indeed followed by "__". */
1114 if (len0 - k > 2 && encoded [k] == '_' && encoded [k+1] == '_')
1118 /* Remove _E{DIGITS}+[sb] */
1120 /* Just as for protected object subprograms, there are 2 categories
1121 of subprograms created by the compiler for each entry. The first
1122 one implements the actual entry code, and has a suffix following
1123 the convention above; the second one implements the barrier and
1124 uses the same convention as above, except that the 'E' is replaced
1127 Just as above, we do not decode the name of barrier functions
1128 to give the user a clue that the code he is debugging has been
1129 internally generated. */
1131 if (len0 - i > 3 && encoded [i] == '_' && encoded[i+1] == 'E'
1132 && isdigit (encoded[i+2]))
1136 while (k < len0 && isdigit (encoded[k]))
1140 && (encoded[k] == 'b' || encoded[k] == 's'))
1143 /* Just as an extra precaution, make sure that if this
1144 suffix is followed by anything else, it is a '_'.
1145 Otherwise, we matched this sequence by accident. */
1147 || (k < len0 && encoded[k] == '_'))
1152 /* Remove trailing "N" in [a-z0-9]+N__. The N is added by
1153 the GNAT front-end in protected object subprograms. */
1156 && encoded[i] == 'N' && encoded[i+1] == '_' && encoded[i+2] == '_')
1158 /* Backtrack a bit up until we reach either the begining of
1159 the encoded name, or "__". Make sure that we only find
1160 digits or lowercase characters. */
1161 const char *ptr = encoded + i - 1;
1163 while (ptr >= encoded && is_lower_alphanum (ptr[0]))
1166 || (ptr > encoded && ptr[0] == '_' && ptr[-1] == '_'))
1170 if (encoded[i] == 'X' && i != 0 && isalnum (encoded[i - 1]))
1172 /* This is a X[bn]* sequence not separated from the previous
1173 part of the name with a non-alpha-numeric character (in other
1174 words, immediately following an alpha-numeric character), then
1175 verify that it is placed at the end of the encoded name. If
1176 not, then the encoding is not valid and we should abort the
1177 decoding. Otherwise, just skip it, it is used in body-nested
1181 while (i < len0 && (encoded[i] == 'b' || encoded[i] == 'n'));
1185 else if (i < len0 - 2 && encoded[i] == '_' && encoded[i + 1] == '_')
1187 /* Replace '__' by '.'. */
1195 /* It's a character part of the decoded name, so just copy it
1197 decoded[j] = encoded[i];
1202 decoded[j] = '\000';
1204 /* Decoded names should never contain any uppercase character.
1205 Double-check this, and abort the decoding if we find one. */
1207 for (i = 0; decoded[i] != '\0'; i += 1)
1208 if (isupper (decoded[i]) || decoded[i] == ' ')
1211 if (strcmp (decoded, encoded) == 0)
1217 GROW_VECT (decoding_buffer, decoding_buffer_size, strlen (encoded) + 3);
1218 decoded = decoding_buffer;
1219 if (encoded[0] == '<')
1220 strcpy (decoded, encoded);
1222 xsnprintf (decoded, decoding_buffer_size, "<%s>", encoded);
1227 /* Table for keeping permanent unique copies of decoded names. Once
1228 allocated, names in this table are never released. While this is a
1229 storage leak, it should not be significant unless there are massive
1230 changes in the set of decoded names in successive versions of a
1231 symbol table loaded during a single session. */
1232 static struct htab *decoded_names_store;
1234 /* Returns the decoded name of GSYMBOL, as for ada_decode, caching it
1235 in the language-specific part of GSYMBOL, if it has not been
1236 previously computed. Tries to save the decoded name in the same
1237 obstack as GSYMBOL, if possible, and otherwise on the heap (so that,
1238 in any case, the decoded symbol has a lifetime at least that of
1240 The GSYMBOL parameter is "mutable" in the C++ sense: logically
1241 const, but nevertheless modified to a semantically equivalent form
1242 when a decoded name is cached in it. */
1245 ada_decode_symbol (const struct general_symbol_info *gsymbol)
1248 (char **) &gsymbol->language_specific.mangled_lang.demangled_name;
1250 if (*resultp == NULL)
1252 const char *decoded = ada_decode (gsymbol->name);
1254 if (gsymbol->obj_section != NULL)
1256 struct objfile *objf = gsymbol->obj_section->objfile;
1258 *resultp = obsavestring (decoded, strlen (decoded),
1259 &objf->objfile_obstack);
1261 /* Sometimes, we can't find a corresponding objfile, in which
1262 case, we put the result on the heap. Since we only decode
1263 when needed, we hope this usually does not cause a
1264 significant memory leak (FIXME). */
1265 if (*resultp == NULL)
1267 char **slot = (char **) htab_find_slot (decoded_names_store,
1271 *slot = xstrdup (decoded);
1280 ada_la_decode (const char *encoded, int options)
1282 return xstrdup (ada_decode (encoded));
1285 /* Returns non-zero iff SYM_NAME matches NAME, ignoring any trailing
1286 suffixes that encode debugging information or leading _ada_ on
1287 SYM_NAME (see is_name_suffix commentary for the debugging
1288 information that is ignored). If WILD, then NAME need only match a
1289 suffix of SYM_NAME minus the same suffixes. Also returns 0 if
1290 either argument is NULL. */
1293 match_name (const char *sym_name, const char *name, int wild)
1295 if (sym_name == NULL || name == NULL)
1298 return wild_match (sym_name, name) == 0;
1301 int len_name = strlen (name);
1303 return (strncmp (sym_name, name, len_name) == 0
1304 && is_name_suffix (sym_name + len_name))
1305 || (strncmp (sym_name, "_ada_", 5) == 0
1306 && strncmp (sym_name + 5, name, len_name) == 0
1307 && is_name_suffix (sym_name + len_name + 5));
1314 /* Assuming that INDEX_DESC_TYPE is an ___XA structure, a structure
1315 generated by the GNAT compiler to describe the index type used
1316 for each dimension of an array, check whether it follows the latest
1317 known encoding. If not, fix it up to conform to the latest encoding.
1318 Otherwise, do nothing. This function also does nothing if
1319 INDEX_DESC_TYPE is NULL.
1321 The GNAT encoding used to describle the array index type evolved a bit.
1322 Initially, the information would be provided through the name of each
1323 field of the structure type only, while the type of these fields was
1324 described as unspecified and irrelevant. The debugger was then expected
1325 to perform a global type lookup using the name of that field in order
1326 to get access to the full index type description. Because these global
1327 lookups can be very expensive, the encoding was later enhanced to make
1328 the global lookup unnecessary by defining the field type as being
1329 the full index type description.
1331 The purpose of this routine is to allow us to support older versions
1332 of the compiler by detecting the use of the older encoding, and by
1333 fixing up the INDEX_DESC_TYPE to follow the new one (at this point,
1334 we essentially replace each field's meaningless type by the associated
1338 ada_fixup_array_indexes_type (struct type *index_desc_type)
1342 if (index_desc_type == NULL)
1344 gdb_assert (TYPE_NFIELDS (index_desc_type) > 0);
1346 /* Check if INDEX_DESC_TYPE follows the older encoding (it is sufficient
1347 to check one field only, no need to check them all). If not, return
1350 If our INDEX_DESC_TYPE was generated using the older encoding,
1351 the field type should be a meaningless integer type whose name
1352 is not equal to the field name. */
1353 if (TYPE_NAME (TYPE_FIELD_TYPE (index_desc_type, 0)) != NULL
1354 && strcmp (TYPE_NAME (TYPE_FIELD_TYPE (index_desc_type, 0)),
1355 TYPE_FIELD_NAME (index_desc_type, 0)) == 0)
1358 /* Fixup each field of INDEX_DESC_TYPE. */
1359 for (i = 0; i < TYPE_NFIELDS (index_desc_type); i++)
1361 char *name = TYPE_FIELD_NAME (index_desc_type, i);
1362 struct type *raw_type = ada_check_typedef (ada_find_any_type (name));
1365 TYPE_FIELD_TYPE (index_desc_type, i) = raw_type;
1369 /* Names of MAX_ADA_DIMENS bounds in P_BOUNDS fields of array descriptors. */
1371 static char *bound_name[] = {
1372 "LB0", "UB0", "LB1", "UB1", "LB2", "UB2", "LB3", "UB3",
1373 "LB4", "UB4", "LB5", "UB5", "LB6", "UB6", "LB7", "UB7"
1376 /* Maximum number of array dimensions we are prepared to handle. */
1378 #define MAX_ADA_DIMENS (sizeof(bound_name) / (2*sizeof(char *)))
1381 /* The desc_* routines return primitive portions of array descriptors
1384 /* The descriptor or array type, if any, indicated by TYPE; removes
1385 level of indirection, if needed. */
1387 static struct type *
1388 desc_base_type (struct type *type)
1392 type = ada_check_typedef (type);
1393 if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
1394 type = ada_typedef_target_type (type);
1397 && (TYPE_CODE (type) == TYPE_CODE_PTR
1398 || TYPE_CODE (type) == TYPE_CODE_REF))
1399 return ada_check_typedef (TYPE_TARGET_TYPE (type));
1404 /* True iff TYPE indicates a "thin" array pointer type. */
1407 is_thin_pntr (struct type *type)
1410 is_suffix (ada_type_name (desc_base_type (type)), "___XUT")
1411 || is_suffix (ada_type_name (desc_base_type (type)), "___XUT___XVE");
1414 /* The descriptor type for thin pointer type TYPE. */
1416 static struct type *
1417 thin_descriptor_type (struct type *type)
1419 struct type *base_type = desc_base_type (type);
1421 if (base_type == NULL)
1423 if (is_suffix (ada_type_name (base_type), "___XVE"))
1427 struct type *alt_type = ada_find_parallel_type (base_type, "___XVE");
1429 if (alt_type == NULL)
1436 /* A pointer to the array data for thin-pointer value VAL. */
1438 static struct value *
1439 thin_data_pntr (struct value *val)
1441 struct type *type = value_type (val);
1442 struct type *data_type = desc_data_target_type (thin_descriptor_type (type));
1444 data_type = lookup_pointer_type (data_type);
1446 if (TYPE_CODE (type) == TYPE_CODE_PTR)
1447 return value_cast (data_type, value_copy (val));
1449 return value_from_longest (data_type, value_address (val));
1452 /* True iff TYPE indicates a "thick" array pointer type. */
1455 is_thick_pntr (struct type *type)
1457 type = desc_base_type (type);
1458 return (type != NULL && TYPE_CODE (type) == TYPE_CODE_STRUCT
1459 && lookup_struct_elt_type (type, "P_BOUNDS", 1) != NULL);
1462 /* If TYPE is the type of an array descriptor (fat or thin pointer) or a
1463 pointer to one, the type of its bounds data; otherwise, NULL. */
1465 static struct type *
1466 desc_bounds_type (struct type *type)
1470 type = desc_base_type (type);
1474 else if (is_thin_pntr (type))
1476 type = thin_descriptor_type (type);
1479 r = lookup_struct_elt_type (type, "BOUNDS", 1);
1481 return ada_check_typedef (r);
1483 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
1485 r = lookup_struct_elt_type (type, "P_BOUNDS", 1);
1487 return ada_check_typedef (TYPE_TARGET_TYPE (ada_check_typedef (r)));
1492 /* If ARR is an array descriptor (fat or thin pointer), or pointer to
1493 one, a pointer to its bounds data. Otherwise NULL. */
1495 static struct value *
1496 desc_bounds (struct value *arr)
1498 struct type *type = ada_check_typedef (value_type (arr));
1500 if (is_thin_pntr (type))
1502 struct type *bounds_type =
1503 desc_bounds_type (thin_descriptor_type (type));
1506 if (bounds_type == NULL)
1507 error (_("Bad GNAT array descriptor"));
1509 /* NOTE: The following calculation is not really kosher, but
1510 since desc_type is an XVE-encoded type (and shouldn't be),
1511 the correct calculation is a real pain. FIXME (and fix GCC). */
1512 if (TYPE_CODE (type) == TYPE_CODE_PTR)
1513 addr = value_as_long (arr);
1515 addr = value_address (arr);
1518 value_from_longest (lookup_pointer_type (bounds_type),
1519 addr - TYPE_LENGTH (bounds_type));
1522 else if (is_thick_pntr (type))
1524 struct value *p_bounds = value_struct_elt (&arr, NULL, "P_BOUNDS", NULL,
1525 _("Bad GNAT array descriptor"));
1526 struct type *p_bounds_type = value_type (p_bounds);
1529 && TYPE_CODE (p_bounds_type) == TYPE_CODE_PTR)
1531 struct type *target_type = TYPE_TARGET_TYPE (p_bounds_type);
1533 if (TYPE_STUB (target_type))
1534 p_bounds = value_cast (lookup_pointer_type
1535 (ada_check_typedef (target_type)),
1539 error (_("Bad GNAT array descriptor"));
1547 /* If TYPE is the type of an array-descriptor (fat pointer), the bit
1548 position of the field containing the address of the bounds data. */
1551 fat_pntr_bounds_bitpos (struct type *type)
1553 return TYPE_FIELD_BITPOS (desc_base_type (type), 1);
1556 /* If TYPE is the type of an array-descriptor (fat pointer), the bit
1557 size of the field containing the address of the bounds data. */
1560 fat_pntr_bounds_bitsize (struct type *type)
1562 type = desc_base_type (type);
1564 if (TYPE_FIELD_BITSIZE (type, 1) > 0)
1565 return TYPE_FIELD_BITSIZE (type, 1);
1567 return 8 * TYPE_LENGTH (ada_check_typedef (TYPE_FIELD_TYPE (type, 1)));
1570 /* If TYPE is the type of an array descriptor (fat or thin pointer) or a
1571 pointer to one, the type of its array data (a array-with-no-bounds type);
1572 otherwise, NULL. Use ada_type_of_array to get an array type with bounds
1575 static struct type *
1576 desc_data_target_type (struct type *type)
1578 type = desc_base_type (type);
1580 /* NOTE: The following is bogus; see comment in desc_bounds. */
1581 if (is_thin_pntr (type))
1582 return desc_base_type (TYPE_FIELD_TYPE (thin_descriptor_type (type), 1));
1583 else if (is_thick_pntr (type))
1585 struct type *data_type = lookup_struct_elt_type (type, "P_ARRAY", 1);
1588 && TYPE_CODE (ada_check_typedef (data_type)) == TYPE_CODE_PTR)
1589 return ada_check_typedef (TYPE_TARGET_TYPE (data_type));
1595 /* If ARR is an array descriptor (fat or thin pointer), a pointer to
1598 static struct value *
1599 desc_data (struct value *arr)
1601 struct type *type = value_type (arr);
1603 if (is_thin_pntr (type))
1604 return thin_data_pntr (arr);
1605 else if (is_thick_pntr (type))
1606 return value_struct_elt (&arr, NULL, "P_ARRAY", NULL,
1607 _("Bad GNAT array descriptor"));
1613 /* If TYPE is the type of an array-descriptor (fat pointer), the bit
1614 position of the field containing the address of the data. */
1617 fat_pntr_data_bitpos (struct type *type)
1619 return TYPE_FIELD_BITPOS (desc_base_type (type), 0);
1622 /* If TYPE is the type of an array-descriptor (fat pointer), the bit
1623 size of the field containing the address of the data. */
1626 fat_pntr_data_bitsize (struct type *type)
1628 type = desc_base_type (type);
1630 if (TYPE_FIELD_BITSIZE (type, 0) > 0)
1631 return TYPE_FIELD_BITSIZE (type, 0);
1633 return TARGET_CHAR_BIT * TYPE_LENGTH (TYPE_FIELD_TYPE (type, 0));
1636 /* If BOUNDS is an array-bounds structure (or pointer to one), return
1637 the Ith lower bound stored in it, if WHICH is 0, and the Ith upper
1638 bound, if WHICH is 1. The first bound is I=1. */
1640 static struct value *
1641 desc_one_bound (struct value *bounds, int i, int which)
1643 return value_struct_elt (&bounds, NULL, bound_name[2 * i + which - 2], NULL,
1644 _("Bad GNAT array descriptor bounds"));
1647 /* If BOUNDS is an array-bounds structure type, return the bit position
1648 of the Ith lower bound stored in it, if WHICH is 0, and the Ith upper
1649 bound, if WHICH is 1. The first bound is I=1. */
1652 desc_bound_bitpos (struct type *type, int i, int which)
1654 return TYPE_FIELD_BITPOS (desc_base_type (type), 2 * i + which - 2);
1657 /* If BOUNDS is an array-bounds structure type, return the bit field size
1658 of the Ith lower bound stored in it, if WHICH is 0, and the Ith upper
1659 bound, if WHICH is 1. The first bound is I=1. */
1662 desc_bound_bitsize (struct type *type, int i, int which)
1664 type = desc_base_type (type);
1666 if (TYPE_FIELD_BITSIZE (type, 2 * i + which - 2) > 0)
1667 return TYPE_FIELD_BITSIZE (type, 2 * i + which - 2);
1669 return 8 * TYPE_LENGTH (TYPE_FIELD_TYPE (type, 2 * i + which - 2));
1672 /* If TYPE is the type of an array-bounds structure, the type of its
1673 Ith bound (numbering from 1). Otherwise, NULL. */
1675 static struct type *
1676 desc_index_type (struct type *type, int i)
1678 type = desc_base_type (type);
1680 if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
1681 return lookup_struct_elt_type (type, bound_name[2 * i - 2], 1);
1686 /* The number of index positions in the array-bounds type TYPE.
1687 Return 0 if TYPE is NULL. */
1690 desc_arity (struct type *type)
1692 type = desc_base_type (type);
1695 return TYPE_NFIELDS (type) / 2;
1699 /* Non-zero iff TYPE is a simple array type (not a pointer to one) or
1700 an array descriptor type (representing an unconstrained array
1704 ada_is_direct_array_type (struct type *type)
1708 type = ada_check_typedef (type);
1709 return (TYPE_CODE (type) == TYPE_CODE_ARRAY
1710 || ada_is_array_descriptor_type (type));
1713 /* Non-zero iff TYPE represents any kind of array in Ada, or a pointer
1717 ada_is_array_type (struct type *type)
1720 && (TYPE_CODE (type) == TYPE_CODE_PTR
1721 || TYPE_CODE (type) == TYPE_CODE_REF))
1722 type = TYPE_TARGET_TYPE (type);
1723 return ada_is_direct_array_type (type);
1726 /* Non-zero iff TYPE is a simple array type or pointer to one. */
1729 ada_is_simple_array_type (struct type *type)
1733 type = ada_check_typedef (type);
1734 return (TYPE_CODE (type) == TYPE_CODE_ARRAY
1735 || (TYPE_CODE (type) == TYPE_CODE_PTR
1736 && TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_ARRAY));
1739 /* Non-zero iff TYPE belongs to a GNAT array descriptor. */
1742 ada_is_array_descriptor_type (struct type *type)
1744 struct type *data_type = desc_data_target_type (type);
1748 type = ada_check_typedef (type);
1749 return (data_type != NULL
1750 && TYPE_CODE (data_type) == TYPE_CODE_ARRAY
1751 && desc_arity (desc_bounds_type (type)) > 0);
1754 /* Non-zero iff type is a partially mal-formed GNAT array
1755 descriptor. FIXME: This is to compensate for some problems with
1756 debugging output from GNAT. Re-examine periodically to see if it
1760 ada_is_bogus_array_descriptor (struct type *type)
1764 && TYPE_CODE (type) == TYPE_CODE_STRUCT
1765 && (lookup_struct_elt_type (type, "P_BOUNDS", 1) != NULL
1766 || lookup_struct_elt_type (type, "P_ARRAY", 1) != NULL)
1767 && !ada_is_array_descriptor_type (type);
1771 /* If ARR has a record type in the form of a standard GNAT array descriptor,
1772 (fat pointer) returns the type of the array data described---specifically,
1773 a pointer-to-array type. If BOUNDS is non-zero, the bounds data are filled
1774 in from the descriptor; otherwise, they are left unspecified. If
1775 the ARR denotes a null array descriptor and BOUNDS is non-zero,
1776 returns NULL. The result is simply the type of ARR if ARR is not
1779 ada_type_of_array (struct value *arr, int bounds)
1781 if (ada_is_constrained_packed_array_type (value_type (arr)))
1782 return decode_constrained_packed_array_type (value_type (arr));
1784 if (!ada_is_array_descriptor_type (value_type (arr)))
1785 return value_type (arr);
1789 struct type *array_type =
1790 ada_check_typedef (desc_data_target_type (value_type (arr)));
1792 if (ada_is_unconstrained_packed_array_type (value_type (arr)))
1793 TYPE_FIELD_BITSIZE (array_type, 0) =
1794 decode_packed_array_bitsize (value_type (arr));
1800 struct type *elt_type;
1802 struct value *descriptor;
1804 elt_type = ada_array_element_type (value_type (arr), -1);
1805 arity = ada_array_arity (value_type (arr));
1807 if (elt_type == NULL || arity == 0)
1808 return ada_check_typedef (value_type (arr));
1810 descriptor = desc_bounds (arr);
1811 if (value_as_long (descriptor) == 0)
1815 struct type *range_type = alloc_type_copy (value_type (arr));
1816 struct type *array_type = alloc_type_copy (value_type (arr));
1817 struct value *low = desc_one_bound (descriptor, arity, 0);
1818 struct value *high = desc_one_bound (descriptor, arity, 1);
1821 create_range_type (range_type, value_type (low),
1822 longest_to_int (value_as_long (low)),
1823 longest_to_int (value_as_long (high)));
1824 elt_type = create_array_type (array_type, elt_type, range_type);
1826 if (ada_is_unconstrained_packed_array_type (value_type (arr)))
1828 /* We need to store the element packed bitsize, as well as
1829 recompute the array size, because it was previously
1830 computed based on the unpacked element size. */
1831 LONGEST lo = value_as_long (low);
1832 LONGEST hi = value_as_long (high);
1834 TYPE_FIELD_BITSIZE (elt_type, 0) =
1835 decode_packed_array_bitsize (value_type (arr));
1836 /* If the array has no element, then the size is already
1837 zero, and does not need to be recomputed. */
1841 (hi - lo + 1) * TYPE_FIELD_BITSIZE (elt_type, 0);
1843 TYPE_LENGTH (array_type) = (array_bitsize + 7) / 8;
1848 return lookup_pointer_type (elt_type);
1852 /* If ARR does not represent an array, returns ARR unchanged.
1853 Otherwise, returns either a standard GDB array with bounds set
1854 appropriately or, if ARR is a non-null fat pointer, a pointer to a standard
1855 GDB array. Returns NULL if ARR is a null fat pointer. */
1858 ada_coerce_to_simple_array_ptr (struct value *arr)
1860 if (ada_is_array_descriptor_type (value_type (arr)))
1862 struct type *arrType = ada_type_of_array (arr, 1);
1864 if (arrType == NULL)
1866 return value_cast (arrType, value_copy (desc_data (arr)));
1868 else if (ada_is_constrained_packed_array_type (value_type (arr)))
1869 return decode_constrained_packed_array (arr);
1874 /* If ARR does not represent an array, returns ARR unchanged.
1875 Otherwise, returns a standard GDB array describing ARR (which may
1876 be ARR itself if it already is in the proper form). */
1879 ada_coerce_to_simple_array (struct value *arr)
1881 if (ada_is_array_descriptor_type (value_type (arr)))
1883 struct value *arrVal = ada_coerce_to_simple_array_ptr (arr);
1886 error (_("Bounds unavailable for null array pointer."));
1887 check_size (TYPE_TARGET_TYPE (value_type (arrVal)));
1888 return value_ind (arrVal);
1890 else if (ada_is_constrained_packed_array_type (value_type (arr)))
1891 return decode_constrained_packed_array (arr);
1896 /* If TYPE represents a GNAT array type, return it translated to an
1897 ordinary GDB array type (possibly with BITSIZE fields indicating
1898 packing). For other types, is the identity. */
1901 ada_coerce_to_simple_array_type (struct type *type)
1903 if (ada_is_constrained_packed_array_type (type))
1904 return decode_constrained_packed_array_type (type);
1906 if (ada_is_array_descriptor_type (type))
1907 return ada_check_typedef (desc_data_target_type (type));
1912 /* Non-zero iff TYPE represents a standard GNAT packed-array type. */
1915 ada_is_packed_array_type (struct type *type)
1919 type = desc_base_type (type);
1920 type = ada_check_typedef (type);
1922 ada_type_name (type) != NULL
1923 && strstr (ada_type_name (type), "___XP") != NULL;
1926 /* Non-zero iff TYPE represents a standard GNAT constrained
1927 packed-array type. */
1930 ada_is_constrained_packed_array_type (struct type *type)
1932 return ada_is_packed_array_type (type)
1933 && !ada_is_array_descriptor_type (type);
1936 /* Non-zero iff TYPE represents an array descriptor for a
1937 unconstrained packed-array type. */
1940 ada_is_unconstrained_packed_array_type (struct type *type)
1942 return ada_is_packed_array_type (type)
1943 && ada_is_array_descriptor_type (type);
1946 /* Given that TYPE encodes a packed array type (constrained or unconstrained),
1947 return the size of its elements in bits. */
1950 decode_packed_array_bitsize (struct type *type)
1956 /* Access to arrays implemented as fat pointers are encoded as a typedef
1957 of the fat pointer type. We need the name of the fat pointer type
1958 to do the decoding, so strip the typedef layer. */
1959 if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
1960 type = ada_typedef_target_type (type);
1962 raw_name = ada_type_name (ada_check_typedef (type));
1964 raw_name = ada_type_name (desc_base_type (type));
1969 tail = strstr (raw_name, "___XP");
1970 gdb_assert (tail != NULL);
1972 if (sscanf (tail + sizeof ("___XP") - 1, "%ld", &bits) != 1)
1975 (_("could not understand bit size information on packed array"));
1982 /* Given that TYPE is a standard GDB array type with all bounds filled
1983 in, and that the element size of its ultimate scalar constituents
1984 (that is, either its elements, or, if it is an array of arrays, its
1985 elements' elements, etc.) is *ELT_BITS, return an identical type,
1986 but with the bit sizes of its elements (and those of any
1987 constituent arrays) recorded in the BITSIZE components of its
1988 TYPE_FIELD_BITSIZE values, and with *ELT_BITS set to its total size
1991 static struct type *
1992 constrained_packed_array_type (struct type *type, long *elt_bits)
1994 struct type *new_elt_type;
1995 struct type *new_type;
1996 LONGEST low_bound, high_bound;
1998 type = ada_check_typedef (type);
1999 if (TYPE_CODE (type) != TYPE_CODE_ARRAY)
2002 new_type = alloc_type_copy (type);
2004 constrained_packed_array_type (ada_check_typedef (TYPE_TARGET_TYPE (type)),
2006 create_array_type (new_type, new_elt_type, TYPE_INDEX_TYPE (type));
2007 TYPE_FIELD_BITSIZE (new_type, 0) = *elt_bits;
2008 TYPE_NAME (new_type) = ada_type_name (type);
2010 if (get_discrete_bounds (TYPE_INDEX_TYPE (type),
2011 &low_bound, &high_bound) < 0)
2012 low_bound = high_bound = 0;
2013 if (high_bound < low_bound)
2014 *elt_bits = TYPE_LENGTH (new_type) = 0;
2017 *elt_bits *= (high_bound - low_bound + 1);
2018 TYPE_LENGTH (new_type) =
2019 (*elt_bits + HOST_CHAR_BIT - 1) / HOST_CHAR_BIT;
2022 TYPE_FIXED_INSTANCE (new_type) = 1;
2026 /* The array type encoded by TYPE, where
2027 ada_is_constrained_packed_array_type (TYPE). */
2029 static struct type *
2030 decode_constrained_packed_array_type (struct type *type)
2032 char *raw_name = ada_type_name (ada_check_typedef (type));
2035 struct type *shadow_type;
2039 raw_name = ada_type_name (desc_base_type (type));
2044 name = (char *) alloca (strlen (raw_name) + 1);
2045 tail = strstr (raw_name, "___XP");
2046 type = desc_base_type (type);
2048 memcpy (name, raw_name, tail - raw_name);
2049 name[tail - raw_name] = '\000';
2051 shadow_type = ada_find_parallel_type_with_name (type, name);
2053 if (shadow_type == NULL)
2055 lim_warning (_("could not find bounds information on packed array"));
2058 CHECK_TYPEDEF (shadow_type);
2060 if (TYPE_CODE (shadow_type) != TYPE_CODE_ARRAY)
2062 lim_warning (_("could not understand bounds "
2063 "information on packed array"));
2067 bits = decode_packed_array_bitsize (type);
2068 return constrained_packed_array_type (shadow_type, &bits);
2071 /* Given that ARR is a struct value *indicating a GNAT constrained packed
2072 array, returns a simple array that denotes that array. Its type is a
2073 standard GDB array type except that the BITSIZEs of the array
2074 target types are set to the number of bits in each element, and the
2075 type length is set appropriately. */
2077 static struct value *
2078 decode_constrained_packed_array (struct value *arr)
2082 arr = ada_coerce_ref (arr);
2084 /* If our value is a pointer, then dererence it. Make sure that
2085 this operation does not cause the target type to be fixed, as
2086 this would indirectly cause this array to be decoded. The rest
2087 of the routine assumes that the array hasn't been decoded yet,
2088 so we use the basic "value_ind" routine to perform the dereferencing,
2089 as opposed to using "ada_value_ind". */
2090 if (TYPE_CODE (value_type (arr)) == TYPE_CODE_PTR)
2091 arr = value_ind (arr);
2093 type = decode_constrained_packed_array_type (value_type (arr));
2096 error (_("can't unpack array"));
2100 if (gdbarch_bits_big_endian (get_type_arch (value_type (arr)))
2101 && ada_is_modular_type (value_type (arr)))
2103 /* This is a (right-justified) modular type representing a packed
2104 array with no wrapper. In order to interpret the value through
2105 the (left-justified) packed array type we just built, we must
2106 first left-justify it. */
2107 int bit_size, bit_pos;
2110 mod = ada_modulus (value_type (arr)) - 1;
2117 bit_pos = HOST_CHAR_BIT * TYPE_LENGTH (value_type (arr)) - bit_size;
2118 arr = ada_value_primitive_packed_val (arr, NULL,
2119 bit_pos / HOST_CHAR_BIT,
2120 bit_pos % HOST_CHAR_BIT,
2125 return coerce_unspec_val_to_type (arr, type);
2129 /* The value of the element of packed array ARR at the ARITY indices
2130 given in IND. ARR must be a simple array. */
2132 static struct value *
2133 value_subscript_packed (struct value *arr, int arity, struct value **ind)
2136 int bits, elt_off, bit_off;
2137 long elt_total_bit_offset;
2138 struct type *elt_type;
2142 elt_total_bit_offset = 0;
2143 elt_type = ada_check_typedef (value_type (arr));
2144 for (i = 0; i < arity; i += 1)
2146 if (TYPE_CODE (elt_type) != TYPE_CODE_ARRAY
2147 || TYPE_FIELD_BITSIZE (elt_type, 0) == 0)
2149 (_("attempt to do packed indexing of "
2150 "something other than a packed array"));
2153 struct type *range_type = TYPE_INDEX_TYPE (elt_type);
2154 LONGEST lowerbound, upperbound;
2157 if (get_discrete_bounds (range_type, &lowerbound, &upperbound) < 0)
2159 lim_warning (_("don't know bounds of array"));
2160 lowerbound = upperbound = 0;
2163 idx = pos_atr (ind[i]);
2164 if (idx < lowerbound || idx > upperbound)
2165 lim_warning (_("packed array index %ld out of bounds"),
2167 bits = TYPE_FIELD_BITSIZE (elt_type, 0);
2168 elt_total_bit_offset += (idx - lowerbound) * bits;
2169 elt_type = ada_check_typedef (TYPE_TARGET_TYPE (elt_type));
2172 elt_off = elt_total_bit_offset / HOST_CHAR_BIT;
2173 bit_off = elt_total_bit_offset % HOST_CHAR_BIT;
2175 v = ada_value_primitive_packed_val (arr, NULL, elt_off, bit_off,
2180 /* Non-zero iff TYPE includes negative integer values. */
2183 has_negatives (struct type *type)
2185 switch (TYPE_CODE (type))
2190 return !TYPE_UNSIGNED (type);
2191 case TYPE_CODE_RANGE:
2192 return TYPE_LOW_BOUND (type) < 0;
2197 /* Create a new value of type TYPE from the contents of OBJ starting
2198 at byte OFFSET, and bit offset BIT_OFFSET within that byte,
2199 proceeding for BIT_SIZE bits. If OBJ is an lval in memory, then
2200 assigning through the result will set the field fetched from.
2201 VALADDR is ignored unless OBJ is NULL, in which case,
2202 VALADDR+OFFSET must address the start of storage containing the
2203 packed value. The value returned in this case is never an lval.
2204 Assumes 0 <= BIT_OFFSET < HOST_CHAR_BIT. */
2207 ada_value_primitive_packed_val (struct value *obj, const gdb_byte *valaddr,
2208 long offset, int bit_offset, int bit_size,
2212 int src, /* Index into the source area */
2213 targ, /* Index into the target area */
2214 srcBitsLeft, /* Number of source bits left to move */
2215 nsrc, ntarg, /* Number of source and target bytes */
2216 unusedLS, /* Number of bits in next significant
2217 byte of source that are unused */
2218 accumSize; /* Number of meaningful bits in accum */
2219 unsigned char *bytes; /* First byte containing data to unpack */
2220 unsigned char *unpacked;
2221 unsigned long accum; /* Staging area for bits being transferred */
2223 int len = (bit_size + bit_offset + HOST_CHAR_BIT - 1) / 8;
2224 /* Transmit bytes from least to most significant; delta is the direction
2225 the indices move. */
2226 int delta = gdbarch_bits_big_endian (get_type_arch (type)) ? -1 : 1;
2228 type = ada_check_typedef (type);
2232 v = allocate_value (type);
2233 bytes = (unsigned char *) (valaddr + offset);
2235 else if (VALUE_LVAL (obj) == lval_memory && value_lazy (obj))
2238 value_address (obj) + offset);
2239 bytes = (unsigned char *) alloca (len);
2240 read_memory (value_address (v), bytes, len);
2244 v = allocate_value (type);
2245 bytes = (unsigned char *) value_contents (obj) + offset;
2252 set_value_component_location (v, obj);
2253 new_addr = value_address (obj) + offset;
2254 set_value_bitpos (v, bit_offset + value_bitpos (obj));
2255 set_value_bitsize (v, bit_size);
2256 if (value_bitpos (v) >= HOST_CHAR_BIT)
2259 set_value_bitpos (v, value_bitpos (v) - HOST_CHAR_BIT);
2261 set_value_address (v, new_addr);
2264 set_value_bitsize (v, bit_size);
2265 unpacked = (unsigned char *) value_contents (v);
2267 srcBitsLeft = bit_size;
2269 ntarg = TYPE_LENGTH (type);
2273 memset (unpacked, 0, TYPE_LENGTH (type));
2276 else if (gdbarch_bits_big_endian (get_type_arch (type)))
2279 if (has_negatives (type)
2280 && ((bytes[0] << bit_offset) & (1 << (HOST_CHAR_BIT - 1))))
2284 (HOST_CHAR_BIT - (bit_size + bit_offset) % HOST_CHAR_BIT)
2287 switch (TYPE_CODE (type))
2289 case TYPE_CODE_ARRAY:
2290 case TYPE_CODE_UNION:
2291 case TYPE_CODE_STRUCT:
2292 /* Non-scalar values must be aligned at a byte boundary... */
2294 (HOST_CHAR_BIT - bit_size % HOST_CHAR_BIT) % HOST_CHAR_BIT;
2295 /* ... And are placed at the beginning (most-significant) bytes
2297 targ = (bit_size + HOST_CHAR_BIT - 1) / HOST_CHAR_BIT - 1;
2302 targ = TYPE_LENGTH (type) - 1;
2308 int sign_bit_offset = (bit_size + bit_offset - 1) % 8;
2311 unusedLS = bit_offset;
2314 if (has_negatives (type) && (bytes[len - 1] & (1 << sign_bit_offset)))
2321 /* Mask for removing bits of the next source byte that are not
2322 part of the value. */
2323 unsigned int unusedMSMask =
2324 (1 << (srcBitsLeft >= HOST_CHAR_BIT ? HOST_CHAR_BIT : srcBitsLeft)) -
2326 /* Sign-extend bits for this byte. */
2327 unsigned int signMask = sign & ~unusedMSMask;
2330 (((bytes[src] >> unusedLS) & unusedMSMask) | signMask) << accumSize;
2331 accumSize += HOST_CHAR_BIT - unusedLS;
2332 if (accumSize >= HOST_CHAR_BIT)
2334 unpacked[targ] = accum & ~(~0L << HOST_CHAR_BIT);
2335 accumSize -= HOST_CHAR_BIT;
2336 accum >>= HOST_CHAR_BIT;
2340 srcBitsLeft -= HOST_CHAR_BIT - unusedLS;
2347 accum |= sign << accumSize;
2348 unpacked[targ] = accum & ~(~0L << HOST_CHAR_BIT);
2349 accumSize -= HOST_CHAR_BIT;
2350 accum >>= HOST_CHAR_BIT;
2358 /* Move N bits from SOURCE, starting at bit offset SRC_OFFSET to
2359 TARGET, starting at bit offset TARG_OFFSET. SOURCE and TARGET must
2362 move_bits (gdb_byte *target, int targ_offset, const gdb_byte *source,
2363 int src_offset, int n, int bits_big_endian_p)
2365 unsigned int accum, mask;
2366 int accum_bits, chunk_size;
2368 target += targ_offset / HOST_CHAR_BIT;
2369 targ_offset %= HOST_CHAR_BIT;
2370 source += src_offset / HOST_CHAR_BIT;
2371 src_offset %= HOST_CHAR_BIT;
2372 if (bits_big_endian_p)
2374 accum = (unsigned char) *source;
2376 accum_bits = HOST_CHAR_BIT - src_offset;
2382 accum = (accum << HOST_CHAR_BIT) + (unsigned char) *source;
2383 accum_bits += HOST_CHAR_BIT;
2385 chunk_size = HOST_CHAR_BIT - targ_offset;
2388 unused_right = HOST_CHAR_BIT - (chunk_size + targ_offset);
2389 mask = ((1 << chunk_size) - 1) << unused_right;
2392 | ((accum >> (accum_bits - chunk_size - unused_right)) & mask);
2394 accum_bits -= chunk_size;
2401 accum = (unsigned char) *source >> src_offset;
2403 accum_bits = HOST_CHAR_BIT - src_offset;
2407 accum = accum + ((unsigned char) *source << accum_bits);
2408 accum_bits += HOST_CHAR_BIT;
2410 chunk_size = HOST_CHAR_BIT - targ_offset;
2413 mask = ((1 << chunk_size) - 1) << targ_offset;
2414 *target = (*target & ~mask) | ((accum << targ_offset) & mask);
2416 accum_bits -= chunk_size;
2417 accum >>= chunk_size;
2424 /* Store the contents of FROMVAL into the location of TOVAL.
2425 Return a new value with the location of TOVAL and contents of
2426 FROMVAL. Handles assignment into packed fields that have
2427 floating-point or non-scalar types. */
2429 static struct value *
2430 ada_value_assign (struct value *toval, struct value *fromval)
2432 struct type *type = value_type (toval);
2433 int bits = value_bitsize (toval);
2435 toval = ada_coerce_ref (toval);
2436 fromval = ada_coerce_ref (fromval);
2438 if (ada_is_direct_array_type (value_type (toval)))
2439 toval = ada_coerce_to_simple_array (toval);
2440 if (ada_is_direct_array_type (value_type (fromval)))
2441 fromval = ada_coerce_to_simple_array (fromval);
2443 if (!deprecated_value_modifiable (toval))
2444 error (_("Left operand of assignment is not a modifiable lvalue."));
2446 if (VALUE_LVAL (toval) == lval_memory
2448 && (TYPE_CODE (type) == TYPE_CODE_FLT
2449 || TYPE_CODE (type) == TYPE_CODE_STRUCT))
2451 int len = (value_bitpos (toval)
2452 + bits + HOST_CHAR_BIT - 1) / HOST_CHAR_BIT;
2454 char *buffer = (char *) alloca (len);
2456 CORE_ADDR to_addr = value_address (toval);
2458 if (TYPE_CODE (type) == TYPE_CODE_FLT)
2459 fromval = value_cast (type, fromval);
2461 read_memory (to_addr, buffer, len);
2462 from_size = value_bitsize (fromval);
2464 from_size = TYPE_LENGTH (value_type (fromval)) * TARGET_CHAR_BIT;
2465 if (gdbarch_bits_big_endian (get_type_arch (type)))
2466 move_bits (buffer, value_bitpos (toval),
2467 value_contents (fromval), from_size - bits, bits, 1);
2469 move_bits (buffer, value_bitpos (toval),
2470 value_contents (fromval), 0, bits, 0);
2471 write_memory (to_addr, buffer, len);
2472 observer_notify_memory_changed (to_addr, len, buffer);
2474 val = value_copy (toval);
2475 memcpy (value_contents_raw (val), value_contents (fromval),
2476 TYPE_LENGTH (type));
2477 deprecated_set_value_type (val, type);
2482 return value_assign (toval, fromval);
2486 /* Given that COMPONENT is a memory lvalue that is part of the lvalue
2487 * CONTAINER, assign the contents of VAL to COMPONENTS's place in
2488 * CONTAINER. Modifies the VALUE_CONTENTS of CONTAINER only, not
2489 * COMPONENT, and not the inferior's memory. The current contents
2490 * of COMPONENT are ignored. */
2492 value_assign_to_component (struct value *container, struct value *component,
2495 LONGEST offset_in_container =
2496 (LONGEST) (value_address (component) - value_address (container));
2497 int bit_offset_in_container =
2498 value_bitpos (component) - value_bitpos (container);
2501 val = value_cast (value_type (component), val);
2503 if (value_bitsize (component) == 0)
2504 bits = TARGET_CHAR_BIT * TYPE_LENGTH (value_type (component));
2506 bits = value_bitsize (component);
2508 if (gdbarch_bits_big_endian (get_type_arch (value_type (container))))
2509 move_bits (value_contents_writeable (container) + offset_in_container,
2510 value_bitpos (container) + bit_offset_in_container,
2511 value_contents (val),
2512 TYPE_LENGTH (value_type (component)) * TARGET_CHAR_BIT - bits,
2515 move_bits (value_contents_writeable (container) + offset_in_container,
2516 value_bitpos (container) + bit_offset_in_container,
2517 value_contents (val), 0, bits, 0);
2520 /* The value of the element of array ARR at the ARITY indices given in IND.
2521 ARR may be either a simple array, GNAT array descriptor, or pointer
2525 ada_value_subscript (struct value *arr, int arity, struct value **ind)
2529 struct type *elt_type;
2531 elt = ada_coerce_to_simple_array (arr);
2533 elt_type = ada_check_typedef (value_type (elt));
2534 if (TYPE_CODE (elt_type) == TYPE_CODE_ARRAY
2535 && TYPE_FIELD_BITSIZE (elt_type, 0) > 0)
2536 return value_subscript_packed (elt, arity, ind);
2538 for (k = 0; k < arity; k += 1)
2540 if (TYPE_CODE (elt_type) != TYPE_CODE_ARRAY)
2541 error (_("too many subscripts (%d expected)"), k);
2542 elt = value_subscript (elt, pos_atr (ind[k]));
2547 /* Assuming ARR is a pointer to a standard GDB array of type TYPE, the
2548 value of the element of *ARR at the ARITY indices given in
2549 IND. Does not read the entire array into memory. */
2551 static struct value *
2552 ada_value_ptr_subscript (struct value *arr, struct type *type, int arity,
2557 for (k = 0; k < arity; k += 1)
2561 if (TYPE_CODE (type) != TYPE_CODE_ARRAY)
2562 error (_("too many subscripts (%d expected)"), k);
2563 arr = value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
2565 get_discrete_bounds (TYPE_INDEX_TYPE (type), &lwb, &upb);
2566 arr = value_ptradd (arr, pos_atr (ind[k]) - lwb);
2567 type = TYPE_TARGET_TYPE (type);
2570 return value_ind (arr);
2573 /* Given that ARRAY_PTR is a pointer or reference to an array of type TYPE (the
2574 actual type of ARRAY_PTR is ignored), returns the Ada slice of HIGH-LOW+1
2575 elements starting at index LOW. The lower bound of this array is LOW, as
2577 static struct value *
2578 ada_value_slice_from_ptr (struct value *array_ptr, struct type *type,
2581 CORE_ADDR base = value_as_address (array_ptr)
2582 + ((low - ada_discrete_type_low_bound (TYPE_INDEX_TYPE (type)))
2583 * TYPE_LENGTH (TYPE_TARGET_TYPE (type)));
2584 struct type *index_type =
2585 create_range_type (NULL, TYPE_TARGET_TYPE (TYPE_INDEX_TYPE (type)),
2587 struct type *slice_type =
2588 create_array_type (NULL, TYPE_TARGET_TYPE (type), index_type);
2590 return value_at_lazy (slice_type, base);
2594 static struct value *
2595 ada_value_slice (struct value *array, int low, int high)
2597 struct type *type = value_type (array);
2598 struct type *index_type =
2599 create_range_type (NULL, TYPE_INDEX_TYPE (type), low, high);
2600 struct type *slice_type =
2601 create_array_type (NULL, TYPE_TARGET_TYPE (type), index_type);
2603 return value_cast (slice_type, value_slice (array, low, high - low + 1));
2606 /* If type is a record type in the form of a standard GNAT array
2607 descriptor, returns the number of dimensions for type. If arr is a
2608 simple array, returns the number of "array of"s that prefix its
2609 type designation. Otherwise, returns 0. */
2612 ada_array_arity (struct type *type)
2619 type = desc_base_type (type);
2622 if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
2623 return desc_arity (desc_bounds_type (type));
2625 while (TYPE_CODE (type) == TYPE_CODE_ARRAY)
2628 type = ada_check_typedef (TYPE_TARGET_TYPE (type));
2634 /* If TYPE is a record type in the form of a standard GNAT array
2635 descriptor or a simple array type, returns the element type for
2636 TYPE after indexing by NINDICES indices, or by all indices if
2637 NINDICES is -1. Otherwise, returns NULL. */
2640 ada_array_element_type (struct type *type, int nindices)
2642 type = desc_base_type (type);
2644 if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
2647 struct type *p_array_type;
2649 p_array_type = desc_data_target_type (type);
2651 k = ada_array_arity (type);
2655 /* Initially p_array_type = elt_type(*)[]...(k times)...[]. */
2656 if (nindices >= 0 && k > nindices)
2658 while (k > 0 && p_array_type != NULL)
2660 p_array_type = ada_check_typedef (TYPE_TARGET_TYPE (p_array_type));
2663 return p_array_type;
2665 else if (TYPE_CODE (type) == TYPE_CODE_ARRAY)
2667 while (nindices != 0 && TYPE_CODE (type) == TYPE_CODE_ARRAY)
2669 type = TYPE_TARGET_TYPE (type);
2678 /* The type of nth index in arrays of given type (n numbering from 1).
2679 Does not examine memory. Throws an error if N is invalid or TYPE
2680 is not an array type. NAME is the name of the Ada attribute being
2681 evaluated ('range, 'first, 'last, or 'length); it is used in building
2682 the error message. */
2684 static struct type *
2685 ada_index_type (struct type *type, int n, const char *name)
2687 struct type *result_type;
2689 type = desc_base_type (type);
2691 if (n < 0 || n > ada_array_arity (type))
2692 error (_("invalid dimension number to '%s"), name);
2694 if (ada_is_simple_array_type (type))
2698 for (i = 1; i < n; i += 1)
2699 type = TYPE_TARGET_TYPE (type);
2700 result_type = TYPE_TARGET_TYPE (TYPE_INDEX_TYPE (type));
2701 /* FIXME: The stabs type r(0,0);bound;bound in an array type
2702 has a target type of TYPE_CODE_UNDEF. We compensate here, but
2703 perhaps stabsread.c would make more sense. */
2704 if (result_type && TYPE_CODE (result_type) == TYPE_CODE_UNDEF)
2709 result_type = desc_index_type (desc_bounds_type (type), n);
2710 if (result_type == NULL)
2711 error (_("attempt to take bound of something that is not an array"));
2717 /* Given that arr is an array type, returns the lower bound of the
2718 Nth index (numbering from 1) if WHICH is 0, and the upper bound if
2719 WHICH is 1. This returns bounds 0 .. -1 if ARR_TYPE is an
2720 array-descriptor type. It works for other arrays with bounds supplied
2721 by run-time quantities other than discriminants. */
2724 ada_array_bound_from_type (struct type * arr_type, int n, int which)
2726 struct type *type, *elt_type, *index_type_desc, *index_type;
2729 gdb_assert (which == 0 || which == 1);
2731 if (ada_is_constrained_packed_array_type (arr_type))
2732 arr_type = decode_constrained_packed_array_type (arr_type);
2734 if (arr_type == NULL || !ada_is_simple_array_type (arr_type))
2735 return (LONGEST) - which;
2737 if (TYPE_CODE (arr_type) == TYPE_CODE_PTR)
2738 type = TYPE_TARGET_TYPE (arr_type);
2743 for (i = n; i > 1; i--)
2744 elt_type = TYPE_TARGET_TYPE (type);
2746 index_type_desc = ada_find_parallel_type (type, "___XA");
2747 ada_fixup_array_indexes_type (index_type_desc);
2748 if (index_type_desc != NULL)
2749 index_type = to_fixed_range_type (TYPE_FIELD_TYPE (index_type_desc, n - 1),
2752 index_type = TYPE_INDEX_TYPE (elt_type);
2755 (LONGEST) (which == 0
2756 ? ada_discrete_type_low_bound (index_type)
2757 : ada_discrete_type_high_bound (index_type));
2760 /* Given that arr is an array value, returns the lower bound of the
2761 nth index (numbering from 1) if WHICH is 0, and the upper bound if
2762 WHICH is 1. This routine will also work for arrays with bounds
2763 supplied by run-time quantities other than discriminants. */
2766 ada_array_bound (struct value *arr, int n, int which)
2768 struct type *arr_type = value_type (arr);
2770 if (ada_is_constrained_packed_array_type (arr_type))
2771 return ada_array_bound (decode_constrained_packed_array (arr), n, which);
2772 else if (ada_is_simple_array_type (arr_type))
2773 return ada_array_bound_from_type (arr_type, n, which);
2775 return value_as_long (desc_one_bound (desc_bounds (arr), n, which));
2778 /* Given that arr is an array value, returns the length of the
2779 nth index. This routine will also work for arrays with bounds
2780 supplied by run-time quantities other than discriminants.
2781 Does not work for arrays indexed by enumeration types with representation
2782 clauses at the moment. */
2785 ada_array_length (struct value *arr, int n)
2787 struct type *arr_type = ada_check_typedef (value_type (arr));
2789 if (ada_is_constrained_packed_array_type (arr_type))
2790 return ada_array_length (decode_constrained_packed_array (arr), n);
2792 if (ada_is_simple_array_type (arr_type))
2793 return (ada_array_bound_from_type (arr_type, n, 1)
2794 - ada_array_bound_from_type (arr_type, n, 0) + 1);
2796 return (value_as_long (desc_one_bound (desc_bounds (arr), n, 1))
2797 - value_as_long (desc_one_bound (desc_bounds (arr), n, 0)) + 1);
2800 /* An empty array whose type is that of ARR_TYPE (an array type),
2801 with bounds LOW to LOW-1. */
2803 static struct value *
2804 empty_array (struct type *arr_type, int low)
2806 struct type *index_type =
2807 create_range_type (NULL, TYPE_TARGET_TYPE (TYPE_INDEX_TYPE (arr_type)),
2809 struct type *elt_type = ada_array_element_type (arr_type, 1);
2811 return allocate_value (create_array_type (NULL, elt_type, index_type));
2815 /* Name resolution */
2817 /* The "decoded" name for the user-definable Ada operator corresponding
2821 ada_decoded_op_name (enum exp_opcode op)
2825 for (i = 0; ada_opname_table[i].encoded != NULL; i += 1)
2827 if (ada_opname_table[i].op == op)
2828 return ada_opname_table[i].decoded;
2830 error (_("Could not find operator name for opcode"));
2834 /* Same as evaluate_type (*EXP), but resolves ambiguous symbol
2835 references (marked by OP_VAR_VALUE nodes in which the symbol has an
2836 undefined namespace) and converts operators that are
2837 user-defined into appropriate function calls. If CONTEXT_TYPE is
2838 non-null, it provides a preferred result type [at the moment, only
2839 type void has any effect---causing procedures to be preferred over
2840 functions in calls]. A null CONTEXT_TYPE indicates that a non-void
2841 return type is preferred. May change (expand) *EXP. */
2844 resolve (struct expression **expp, int void_context_p)
2846 struct type *context_type = NULL;
2850 context_type = builtin_type ((*expp)->gdbarch)->builtin_void;
2852 resolve_subexp (expp, &pc, 1, context_type);
2855 /* Resolve the operator of the subexpression beginning at
2856 position *POS of *EXPP. "Resolving" consists of replacing
2857 the symbols that have undefined namespaces in OP_VAR_VALUE nodes
2858 with their resolutions, replacing built-in operators with
2859 function calls to user-defined operators, where appropriate, and,
2860 when DEPROCEDURE_P is non-zero, converting function-valued variables
2861 into parameterless calls. May expand *EXPP. The CONTEXT_TYPE functions
2862 are as in ada_resolve, above. */
2864 static struct value *
2865 resolve_subexp (struct expression **expp, int *pos, int deprocedure_p,
2866 struct type *context_type)
2870 struct expression *exp; /* Convenience: == *expp. */
2871 enum exp_opcode op = (*expp)->elts[pc].opcode;
2872 struct value **argvec; /* Vector of operand types (alloca'ed). */
2873 int nargs; /* Number of operands. */
2880 /* Pass one: resolve operands, saving their types and updating *pos,
2885 if (exp->elts[pc + 3].opcode == OP_VAR_VALUE
2886 && SYMBOL_DOMAIN (exp->elts[pc + 5].symbol) == UNDEF_DOMAIN)
2891 resolve_subexp (expp, pos, 0, NULL);
2893 nargs = longest_to_int (exp->elts[pc + 1].longconst);
2898 resolve_subexp (expp, pos, 0, NULL);
2903 resolve_subexp (expp, pos, 1, check_typedef (exp->elts[pc + 1].type));
2906 case OP_ATR_MODULUS:
2916 case TERNOP_IN_RANGE:
2917 case BINOP_IN_BOUNDS:
2923 case OP_DISCRETE_RANGE:
2925 ada_forward_operator_length (exp, pc, &oplen, &nargs);
2934 arg1 = resolve_subexp (expp, pos, 0, NULL);
2936 resolve_subexp (expp, pos, 1, NULL);
2938 resolve_subexp (expp, pos, 1, value_type (arg1));
2955 case BINOP_LOGICAL_AND:
2956 case BINOP_LOGICAL_OR:
2957 case BINOP_BITWISE_AND:
2958 case BINOP_BITWISE_IOR:
2959 case BINOP_BITWISE_XOR:
2962 case BINOP_NOTEQUAL:
2969 case BINOP_SUBSCRIPT:
2977 case UNOP_LOGICAL_NOT:
2993 case OP_INTERNALVAR:
3003 *pos += 4 + BYTES_TO_EXP_ELEM (exp->elts[pc + 1].longconst + 1);
3006 case STRUCTOP_STRUCT:
3007 *pos += 4 + BYTES_TO_EXP_ELEM (exp->elts[pc + 1].longconst + 1);
3020 error (_("Unexpected operator during name resolution"));
3023 argvec = (struct value * *) alloca (sizeof (struct value *) * (nargs + 1));
3024 for (i = 0; i < nargs; i += 1)
3025 argvec[i] = resolve_subexp (expp, pos, 1, NULL);
3029 /* Pass two: perform any resolution on principal operator. */
3036 if (SYMBOL_DOMAIN (exp->elts[pc + 2].symbol) == UNDEF_DOMAIN)
3038 struct ada_symbol_info *candidates;
3042 ada_lookup_symbol_list (SYMBOL_LINKAGE_NAME
3043 (exp->elts[pc + 2].symbol),
3044 exp->elts[pc + 1].block, VAR_DOMAIN,
3047 if (n_candidates > 1)
3049 /* Types tend to get re-introduced locally, so if there
3050 are any local symbols that are not types, first filter
3053 for (j = 0; j < n_candidates; j += 1)
3054 switch (SYMBOL_CLASS (candidates[j].sym))
3059 case LOC_REGPARM_ADDR:
3067 if (j < n_candidates)
3070 while (j < n_candidates)
3072 if (SYMBOL_CLASS (candidates[j].sym) == LOC_TYPEDEF)
3074 candidates[j] = candidates[n_candidates - 1];
3083 if (n_candidates == 0)
3084 error (_("No definition found for %s"),
3085 SYMBOL_PRINT_NAME (exp->elts[pc + 2].symbol));
3086 else if (n_candidates == 1)
3088 else if (deprocedure_p
3089 && !is_nonfunction (candidates, n_candidates))
3091 i = ada_resolve_function
3092 (candidates, n_candidates, NULL, 0,
3093 SYMBOL_LINKAGE_NAME (exp->elts[pc + 2].symbol),
3096 error (_("Could not find a match for %s"),
3097 SYMBOL_PRINT_NAME (exp->elts[pc + 2].symbol));
3101 printf_filtered (_("Multiple matches for %s\n"),
3102 SYMBOL_PRINT_NAME (exp->elts[pc + 2].symbol));
3103 user_select_syms (candidates, n_candidates, 1);
3107 exp->elts[pc + 1].block = candidates[i].block;
3108 exp->elts[pc + 2].symbol = candidates[i].sym;
3109 if (innermost_block == NULL
3110 || contained_in (candidates[i].block, innermost_block))
3111 innermost_block = candidates[i].block;
3115 && (TYPE_CODE (SYMBOL_TYPE (exp->elts[pc + 2].symbol))
3118 replace_operator_with_call (expp, pc, 0, 0,
3119 exp->elts[pc + 2].symbol,
3120 exp->elts[pc + 1].block);
3127 if (exp->elts[pc + 3].opcode == OP_VAR_VALUE
3128 && SYMBOL_DOMAIN (exp->elts[pc + 5].symbol) == UNDEF_DOMAIN)
3130 struct ada_symbol_info *candidates;
3134 ada_lookup_symbol_list (SYMBOL_LINKAGE_NAME
3135 (exp->elts[pc + 5].symbol),
3136 exp->elts[pc + 4].block, VAR_DOMAIN,
3138 if (n_candidates == 1)
3142 i = ada_resolve_function
3143 (candidates, n_candidates,
3145 SYMBOL_LINKAGE_NAME (exp->elts[pc + 5].symbol),
3148 error (_("Could not find a match for %s"),
3149 SYMBOL_PRINT_NAME (exp->elts[pc + 5].symbol));
3152 exp->elts[pc + 4].block = candidates[i].block;
3153 exp->elts[pc + 5].symbol = candidates[i].sym;
3154 if (innermost_block == NULL
3155 || contained_in (candidates[i].block, innermost_block))
3156 innermost_block = candidates[i].block;
3167 case BINOP_BITWISE_AND:
3168 case BINOP_BITWISE_IOR:
3169 case BINOP_BITWISE_XOR:
3171 case BINOP_NOTEQUAL:
3179 case UNOP_LOGICAL_NOT:
3181 if (possible_user_operator_p (op, argvec))
3183 struct ada_symbol_info *candidates;
3187 ada_lookup_symbol_list (ada_encode (ada_decoded_op_name (op)),
3188 (struct block *) NULL, VAR_DOMAIN,
3190 i = ada_resolve_function (candidates, n_candidates, argvec, nargs,
3191 ada_decoded_op_name (op), NULL);
3195 replace_operator_with_call (expp, pc, nargs, 1,
3196 candidates[i].sym, candidates[i].block);
3207 return evaluate_subexp_type (exp, pos);
3210 /* Return non-zero if formal type FTYPE matches actual type ATYPE. If
3211 MAY_DEREF is non-zero, the formal may be a pointer and the actual
3213 /* The term "match" here is rather loose. The match is heuristic and
3217 ada_type_match (struct type *ftype, struct type *atype, int may_deref)
3219 ftype = ada_check_typedef (ftype);
3220 atype = ada_check_typedef (atype);
3222 if (TYPE_CODE (ftype) == TYPE_CODE_REF)
3223 ftype = TYPE_TARGET_TYPE (ftype);
3224 if (TYPE_CODE (atype) == TYPE_CODE_REF)
3225 atype = TYPE_TARGET_TYPE (atype);
3227 switch (TYPE_CODE (ftype))
3230 return TYPE_CODE (ftype) == TYPE_CODE (atype);
3232 if (TYPE_CODE (atype) == TYPE_CODE_PTR)
3233 return ada_type_match (TYPE_TARGET_TYPE (ftype),
3234 TYPE_TARGET_TYPE (atype), 0);
3237 && ada_type_match (TYPE_TARGET_TYPE (ftype), atype, 0));
3239 case TYPE_CODE_ENUM:
3240 case TYPE_CODE_RANGE:
3241 switch (TYPE_CODE (atype))
3244 case TYPE_CODE_ENUM:
3245 case TYPE_CODE_RANGE:
3251 case TYPE_CODE_ARRAY:
3252 return (TYPE_CODE (atype) == TYPE_CODE_ARRAY
3253 || ada_is_array_descriptor_type (atype));
3255 case TYPE_CODE_STRUCT:
3256 if (ada_is_array_descriptor_type (ftype))
3257 return (TYPE_CODE (atype) == TYPE_CODE_ARRAY
3258 || ada_is_array_descriptor_type (atype));
3260 return (TYPE_CODE (atype) == TYPE_CODE_STRUCT
3261 && !ada_is_array_descriptor_type (atype));
3263 case TYPE_CODE_UNION:
3265 return (TYPE_CODE (atype) == TYPE_CODE (ftype));
3269 /* Return non-zero if the formals of FUNC "sufficiently match" the
3270 vector of actual argument types ACTUALS of size N_ACTUALS. FUNC
3271 may also be an enumeral, in which case it is treated as a 0-
3272 argument function. */
3275 ada_args_match (struct symbol *func, struct value **actuals, int n_actuals)
3278 struct type *func_type = SYMBOL_TYPE (func);
3280 if (SYMBOL_CLASS (func) == LOC_CONST
3281 && TYPE_CODE (func_type) == TYPE_CODE_ENUM)
3282 return (n_actuals == 0);
3283 else if (func_type == NULL || TYPE_CODE (func_type) != TYPE_CODE_FUNC)
3286 if (TYPE_NFIELDS (func_type) != n_actuals)
3289 for (i = 0; i < n_actuals; i += 1)
3291 if (actuals[i] == NULL)
3295 struct type *ftype = ada_check_typedef (TYPE_FIELD_TYPE (func_type,
3297 struct type *atype = ada_check_typedef (value_type (actuals[i]));
3299 if (!ada_type_match (ftype, atype, 1))
3306 /* False iff function type FUNC_TYPE definitely does not produce a value
3307 compatible with type CONTEXT_TYPE. Conservatively returns 1 if
3308 FUNC_TYPE is not a valid function type with a non-null return type
3309 or an enumerated type. A null CONTEXT_TYPE indicates any non-void type. */
3312 return_match (struct type *func_type, struct type *context_type)
3314 struct type *return_type;
3316 if (func_type == NULL)
3319 if (TYPE_CODE (func_type) == TYPE_CODE_FUNC)
3320 return_type = base_type (TYPE_TARGET_TYPE (func_type));
3322 return_type = base_type (func_type);
3323 if (return_type == NULL)
3326 context_type = base_type (context_type);
3328 if (TYPE_CODE (return_type) == TYPE_CODE_ENUM)
3329 return context_type == NULL || return_type == context_type;
3330 else if (context_type == NULL)
3331 return TYPE_CODE (return_type) != TYPE_CODE_VOID;
3333 return TYPE_CODE (return_type) == TYPE_CODE (context_type);
3337 /* Returns the index in SYMS[0..NSYMS-1] that contains the symbol for the
3338 function (if any) that matches the types of the NARGS arguments in
3339 ARGS. If CONTEXT_TYPE is non-null and there is at least one match
3340 that returns that type, then eliminate matches that don't. If
3341 CONTEXT_TYPE is void and there is at least one match that does not
3342 return void, eliminate all matches that do.
3344 Asks the user if there is more than one match remaining. Returns -1
3345 if there is no such symbol or none is selected. NAME is used
3346 solely for messages. May re-arrange and modify SYMS in
3347 the process; the index returned is for the modified vector. */
3350 ada_resolve_function (struct ada_symbol_info syms[],
3351 int nsyms, struct value **args, int nargs,
3352 const char *name, struct type *context_type)
3356 int m; /* Number of hits */
3359 /* In the first pass of the loop, we only accept functions matching
3360 context_type. If none are found, we add a second pass of the loop
3361 where every function is accepted. */
3362 for (fallback = 0; m == 0 && fallback < 2; fallback++)
3364 for (k = 0; k < nsyms; k += 1)
3366 struct type *type = ada_check_typedef (SYMBOL_TYPE (syms[k].sym));
3368 if (ada_args_match (syms[k].sym, args, nargs)
3369 && (fallback || return_match (type, context_type)))
3381 printf_filtered (_("Multiple matches for %s\n"), name);
3382 user_select_syms (syms, m, 1);
3388 /* Returns true (non-zero) iff decoded name N0 should appear before N1
3389 in a listing of choices during disambiguation (see sort_choices, below).
3390 The idea is that overloadings of a subprogram name from the
3391 same package should sort in their source order. We settle for ordering
3392 such symbols by their trailing number (__N or $N). */
3395 encoded_ordered_before (char *N0, char *N1)
3399 else if (N0 == NULL)
3405 for (k0 = strlen (N0) - 1; k0 > 0 && isdigit (N0[k0]); k0 -= 1)
3407 for (k1 = strlen (N1) - 1; k1 > 0 && isdigit (N1[k1]); k1 -= 1)
3409 if ((N0[k0] == '_' || N0[k0] == '$') && N0[k0 + 1] != '\000'
3410 && (N1[k1] == '_' || N1[k1] == '$') && N1[k1 + 1] != '\000')
3415 while (N0[n0] == '_' && n0 > 0 && N0[n0 - 1] == '_')
3418 while (N1[n1] == '_' && n1 > 0 && N1[n1 - 1] == '_')
3420 if (n0 == n1 && strncmp (N0, N1, n0) == 0)
3421 return (atoi (N0 + k0 + 1) < atoi (N1 + k1 + 1));
3423 return (strcmp (N0, N1) < 0);
3427 /* Sort SYMS[0..NSYMS-1] to put the choices in a canonical order by the
3431 sort_choices (struct ada_symbol_info syms[], int nsyms)
3435 for (i = 1; i < nsyms; i += 1)
3437 struct ada_symbol_info sym = syms[i];
3440 for (j = i - 1; j >= 0; j -= 1)
3442 if (encoded_ordered_before (SYMBOL_LINKAGE_NAME (syms[j].sym),
3443 SYMBOL_LINKAGE_NAME (sym.sym)))
3445 syms[j + 1] = syms[j];
3451 /* Given a list of NSYMS symbols in SYMS, select up to MAX_RESULTS>0
3452 by asking the user (if necessary), returning the number selected,
3453 and setting the first elements of SYMS items. Error if no symbols
3456 /* NOTE: Adapted from decode_line_2 in symtab.c, with which it ought
3457 to be re-integrated one of these days. */
3460 user_select_syms (struct ada_symbol_info *syms, int nsyms, int max_results)
3463 int *chosen = (int *) alloca (sizeof (int) * nsyms);
3465 int first_choice = (max_results == 1) ? 1 : 2;
3466 const char *select_mode = multiple_symbols_select_mode ();
3468 if (max_results < 1)
3469 error (_("Request to select 0 symbols!"));
3473 if (select_mode == multiple_symbols_cancel)
3475 canceled because the command is ambiguous\n\
3476 See set/show multiple-symbol."));
3478 /* If select_mode is "all", then return all possible symbols.
3479 Only do that if more than one symbol can be selected, of course.
3480 Otherwise, display the menu as usual. */
3481 if (select_mode == multiple_symbols_all && max_results > 1)
3484 printf_unfiltered (_("[0] cancel\n"));
3485 if (max_results > 1)
3486 printf_unfiltered (_("[1] all\n"));
3488 sort_choices (syms, nsyms);
3490 for (i = 0; i < nsyms; i += 1)
3492 if (syms[i].sym == NULL)
3495 if (SYMBOL_CLASS (syms[i].sym) == LOC_BLOCK)
3497 struct symtab_and_line sal =
3498 find_function_start_sal (syms[i].sym, 1);
3500 if (sal.symtab == NULL)
3501 printf_unfiltered (_("[%d] %s at <no source file available>:%d\n"),
3503 SYMBOL_PRINT_NAME (syms[i].sym),
3506 printf_unfiltered (_("[%d] %s at %s:%d\n"), i + first_choice,
3507 SYMBOL_PRINT_NAME (syms[i].sym),
3508 sal.symtab->filename, sal.line);
3514 (SYMBOL_CLASS (syms[i].sym) == LOC_CONST
3515 && SYMBOL_TYPE (syms[i].sym) != NULL
3516 && TYPE_CODE (SYMBOL_TYPE (syms[i].sym)) == TYPE_CODE_ENUM);
3517 struct symtab *symtab = syms[i].sym->symtab;
3519 if (SYMBOL_LINE (syms[i].sym) != 0 && symtab != NULL)
3520 printf_unfiltered (_("[%d] %s at %s:%d\n"),
3522 SYMBOL_PRINT_NAME (syms[i].sym),
3523 symtab->filename, SYMBOL_LINE (syms[i].sym));
3524 else if (is_enumeral
3525 && TYPE_NAME (SYMBOL_TYPE (syms[i].sym)) != NULL)
3527 printf_unfiltered (("[%d] "), i + first_choice);
3528 ada_print_type (SYMBOL_TYPE (syms[i].sym), NULL,
3530 printf_unfiltered (_("'(%s) (enumeral)\n"),
3531 SYMBOL_PRINT_NAME (syms[i].sym));
3533 else if (symtab != NULL)
3534 printf_unfiltered (is_enumeral
3535 ? _("[%d] %s in %s (enumeral)\n")
3536 : _("[%d] %s at %s:?\n"),
3538 SYMBOL_PRINT_NAME (syms[i].sym),
3541 printf_unfiltered (is_enumeral
3542 ? _("[%d] %s (enumeral)\n")
3543 : _("[%d] %s at ?\n"),
3545 SYMBOL_PRINT_NAME (syms[i].sym));
3549 n_chosen = get_selections (chosen, nsyms, max_results, max_results > 1,
3552 for (i = 0; i < n_chosen; i += 1)
3553 syms[i] = syms[chosen[i]];
3558 /* Read and validate a set of numeric choices from the user in the
3559 range 0 .. N_CHOICES-1. Place the results in increasing
3560 order in CHOICES[0 .. N-1], and return N.
3562 The user types choices as a sequence of numbers on one line
3563 separated by blanks, encoding them as follows:
3565 + A choice of 0 means to cancel the selection, throwing an error.
3566 + If IS_ALL_CHOICE, a choice of 1 selects the entire set 0 .. N_CHOICES-1.
3567 + The user chooses k by typing k+IS_ALL_CHOICE+1.
3569 The user is not allowed to choose more than MAX_RESULTS values.
3571 ANNOTATION_SUFFIX, if present, is used to annotate the input
3572 prompts (for use with the -f switch). */
3575 get_selections (int *choices, int n_choices, int max_results,
3576 int is_all_choice, char *annotation_suffix)
3581 int first_choice = is_all_choice ? 2 : 1;
3583 prompt = getenv ("PS2");
3587 args = command_line_input (prompt, 0, annotation_suffix);
3590 error_no_arg (_("one or more choice numbers"));
3594 /* Set choices[0 .. n_chosen-1] to the users' choices in ascending
3595 order, as given in args. Choices are validated. */
3601 while (isspace (*args))
3603 if (*args == '\0' && n_chosen == 0)
3604 error_no_arg (_("one or more choice numbers"));
3605 else if (*args == '\0')
3608 choice = strtol (args, &args2, 10);
3609 if (args == args2 || choice < 0
3610 || choice > n_choices + first_choice - 1)
3611 error (_("Argument must be choice number"));
3615 error (_("cancelled"));
3617 if (choice < first_choice)
3619 n_chosen = n_choices;
3620 for (j = 0; j < n_choices; j += 1)
3624 choice -= first_choice;
3626 for (j = n_chosen - 1; j >= 0 && choice < choices[j]; j -= 1)
3630 if (j < 0 || choice != choices[j])
3634 for (k = n_chosen - 1; k > j; k -= 1)
3635 choices[k + 1] = choices[k];
3636 choices[j + 1] = choice;
3641 if (n_chosen > max_results)
3642 error (_("Select no more than %d of the above"), max_results);
3647 /* Replace the operator of length OPLEN at position PC in *EXPP with a call
3648 on the function identified by SYM and BLOCK, and taking NARGS
3649 arguments. Update *EXPP as needed to hold more space. */
3652 replace_operator_with_call (struct expression **expp, int pc, int nargs,
3653 int oplen, struct symbol *sym,
3654 struct block *block)
3656 /* A new expression, with 6 more elements (3 for funcall, 4 for function
3657 symbol, -oplen for operator being replaced). */
3658 struct expression *newexp = (struct expression *)
3659 xzalloc (sizeof (struct expression)
3660 + EXP_ELEM_TO_BYTES ((*expp)->nelts + 7 - oplen));
3661 struct expression *exp = *expp;
3663 newexp->nelts = exp->nelts + 7 - oplen;
3664 newexp->language_defn = exp->language_defn;
3665 newexp->gdbarch = exp->gdbarch;
3666 memcpy (newexp->elts, exp->elts, EXP_ELEM_TO_BYTES (pc));
3667 memcpy (newexp->elts + pc + 7, exp->elts + pc + oplen,
3668 EXP_ELEM_TO_BYTES (exp->nelts - pc - oplen));
3670 newexp->elts[pc].opcode = newexp->elts[pc + 2].opcode = OP_FUNCALL;
3671 newexp->elts[pc + 1].longconst = (LONGEST) nargs;
3673 newexp->elts[pc + 3].opcode = newexp->elts[pc + 6].opcode = OP_VAR_VALUE;
3674 newexp->elts[pc + 4].block = block;
3675 newexp->elts[pc + 5].symbol = sym;
3681 /* Type-class predicates */
3683 /* True iff TYPE is numeric (i.e., an INT, RANGE (of numeric type),
3687 numeric_type_p (struct type *type)
3693 switch (TYPE_CODE (type))
3698 case TYPE_CODE_RANGE:
3699 return (type == TYPE_TARGET_TYPE (type)
3700 || numeric_type_p (TYPE_TARGET_TYPE (type)));
3707 /* True iff TYPE is integral (an INT or RANGE of INTs). */
3710 integer_type_p (struct type *type)
3716 switch (TYPE_CODE (type))
3720 case TYPE_CODE_RANGE:
3721 return (type == TYPE_TARGET_TYPE (type)
3722 || integer_type_p (TYPE_TARGET_TYPE (type)));
3729 /* True iff TYPE is scalar (INT, RANGE, FLOAT, ENUM). */
3732 scalar_type_p (struct type *type)
3738 switch (TYPE_CODE (type))
3741 case TYPE_CODE_RANGE:
3742 case TYPE_CODE_ENUM:
3751 /* True iff TYPE is discrete (INT, RANGE, ENUM). */
3754 discrete_type_p (struct type *type)
3760 switch (TYPE_CODE (type))
3763 case TYPE_CODE_RANGE:
3764 case TYPE_CODE_ENUM:
3765 case TYPE_CODE_BOOL:
3773 /* Returns non-zero if OP with operands in the vector ARGS could be
3774 a user-defined function. Errs on the side of pre-defined operators
3775 (i.e., result 0). */
3778 possible_user_operator_p (enum exp_opcode op, struct value *args[])
3780 struct type *type0 =
3781 (args[0] == NULL) ? NULL : ada_check_typedef (value_type (args[0]));
3782 struct type *type1 =
3783 (args[1] == NULL) ? NULL : ada_check_typedef (value_type (args[1]));
3797 return (!(numeric_type_p (type0) && numeric_type_p (type1)));
3801 case BINOP_BITWISE_AND:
3802 case BINOP_BITWISE_IOR:
3803 case BINOP_BITWISE_XOR:
3804 return (!(integer_type_p (type0) && integer_type_p (type1)));
3807 case BINOP_NOTEQUAL:
3812 return (!(scalar_type_p (type0) && scalar_type_p (type1)));
3815 return !ada_is_array_type (type0) || !ada_is_array_type (type1);
3818 return (!(numeric_type_p (type0) && integer_type_p (type1)));
3822 case UNOP_LOGICAL_NOT:
3824 return (!numeric_type_p (type0));
3833 1. In the following, we assume that a renaming type's name may
3834 have an ___XD suffix. It would be nice if this went away at some
3836 2. We handle both the (old) purely type-based representation of
3837 renamings and the (new) variable-based encoding. At some point,
3838 it is devoutly to be hoped that the former goes away
3839 (FIXME: hilfinger-2007-07-09).
3840 3. Subprogram renamings are not implemented, although the XRS
3841 suffix is recognized (FIXME: hilfinger-2007-07-09). */
3843 /* If SYM encodes a renaming,
3845 <renaming> renames <renamed entity>,
3847 sets *LEN to the length of the renamed entity's name,
3848 *RENAMED_ENTITY to that name (not null-terminated), and *RENAMING_EXPR to
3849 the string describing the subcomponent selected from the renamed
3850 entity. Returns ADA_NOT_RENAMING if SYM does not encode a renaming
3851 (in which case, the values of *RENAMED_ENTITY, *LEN, and *RENAMING_EXPR
3852 are undefined). Otherwise, returns a value indicating the category
3853 of entity renamed: an object (ADA_OBJECT_RENAMING), exception
3854 (ADA_EXCEPTION_RENAMING), package (ADA_PACKAGE_RENAMING), or
3855 subprogram (ADA_SUBPROGRAM_RENAMING). Does no allocation; the
3856 strings returned in *RENAMED_ENTITY and *RENAMING_EXPR should not be
3857 deallocated. The values of RENAMED_ENTITY, LEN, or RENAMING_EXPR
3858 may be NULL, in which case they are not assigned.
3860 [Currently, however, GCC does not generate subprogram renamings.] */
3862 enum ada_renaming_category
3863 ada_parse_renaming (struct symbol *sym,
3864 const char **renamed_entity, int *len,
3865 const char **renaming_expr)
3867 enum ada_renaming_category kind;
3872 return ADA_NOT_RENAMING;
3873 switch (SYMBOL_CLASS (sym))
3876 return ADA_NOT_RENAMING;
3878 return parse_old_style_renaming (SYMBOL_TYPE (sym),
3879 renamed_entity, len, renaming_expr);
3883 case LOC_OPTIMIZED_OUT:
3884 info = strstr (SYMBOL_LINKAGE_NAME (sym), "___XR");
3886 return ADA_NOT_RENAMING;
3890 kind = ADA_OBJECT_RENAMING;
3894 kind = ADA_EXCEPTION_RENAMING;
3898 kind = ADA_PACKAGE_RENAMING;
3902 kind = ADA_SUBPROGRAM_RENAMING;
3906 return ADA_NOT_RENAMING;
3910 if (renamed_entity != NULL)
3911 *renamed_entity = info;
3912 suffix = strstr (info, "___XE");
3913 if (suffix == NULL || suffix == info)
3914 return ADA_NOT_RENAMING;
3916 *len = strlen (info) - strlen (suffix);
3918 if (renaming_expr != NULL)
3919 *renaming_expr = suffix;
3923 /* Assuming TYPE encodes a renaming according to the old encoding in
3924 exp_dbug.ads, returns details of that renaming in *RENAMED_ENTITY,
3925 *LEN, and *RENAMING_EXPR, as for ada_parse_renaming, above. Returns
3926 ADA_NOT_RENAMING otherwise. */
3927 static enum ada_renaming_category
3928 parse_old_style_renaming (struct type *type,
3929 const char **renamed_entity, int *len,
3930 const char **renaming_expr)
3932 enum ada_renaming_category kind;
3937 if (type == NULL || TYPE_CODE (type) != TYPE_CODE_ENUM
3938 || TYPE_NFIELDS (type) != 1)
3939 return ADA_NOT_RENAMING;
3941 name = type_name_no_tag (type);
3943 return ADA_NOT_RENAMING;
3945 name = strstr (name, "___XR");
3947 return ADA_NOT_RENAMING;
3952 kind = ADA_OBJECT_RENAMING;
3955 kind = ADA_EXCEPTION_RENAMING;
3958 kind = ADA_PACKAGE_RENAMING;
3961 kind = ADA_SUBPROGRAM_RENAMING;
3964 return ADA_NOT_RENAMING;
3967 info = TYPE_FIELD_NAME (type, 0);
3969 return ADA_NOT_RENAMING;
3970 if (renamed_entity != NULL)
3971 *renamed_entity = info;
3972 suffix = strstr (info, "___XE");
3973 if (renaming_expr != NULL)
3974 *renaming_expr = suffix + 5;
3975 if (suffix == NULL || suffix == info)
3976 return ADA_NOT_RENAMING;
3978 *len = suffix - info;
3984 /* Evaluation: Function Calls */
3986 /* Return an lvalue containing the value VAL. This is the identity on
3987 lvalues, and otherwise has the side-effect of allocating memory
3988 in the inferior where a copy of the value contents is copied. */
3990 static struct value *
3991 ensure_lval (struct value *val)
3993 if (VALUE_LVAL (val) == not_lval
3994 || VALUE_LVAL (val) == lval_internalvar)
3996 int len = TYPE_LENGTH (ada_check_typedef (value_type (val)));
3997 const CORE_ADDR addr =
3998 value_as_long (value_allocate_space_in_inferior (len));
4000 set_value_address (val, addr);
4001 VALUE_LVAL (val) = lval_memory;
4002 write_memory (addr, value_contents (val), len);
4008 /* Return the value ACTUAL, converted to be an appropriate value for a
4009 formal of type FORMAL_TYPE. Use *SP as a stack pointer for
4010 allocating any necessary descriptors (fat pointers), or copies of
4011 values not residing in memory, updating it as needed. */
4014 ada_convert_actual (struct value *actual, struct type *formal_type0)
4016 struct type *actual_type = ada_check_typedef (value_type (actual));
4017 struct type *formal_type = ada_check_typedef (formal_type0);
4018 struct type *formal_target =
4019 TYPE_CODE (formal_type) == TYPE_CODE_PTR
4020 ? ada_check_typedef (TYPE_TARGET_TYPE (formal_type)) : formal_type;
4021 struct type *actual_target =
4022 TYPE_CODE (actual_type) == TYPE_CODE_PTR
4023 ? ada_check_typedef (TYPE_TARGET_TYPE (actual_type)) : actual_type;
4025 if (ada_is_array_descriptor_type (formal_target)
4026 && TYPE_CODE (actual_target) == TYPE_CODE_ARRAY)
4027 return make_array_descriptor (formal_type, actual);
4028 else if (TYPE_CODE (formal_type) == TYPE_CODE_PTR
4029 || TYPE_CODE (formal_type) == TYPE_CODE_REF)
4031 struct value *result;
4033 if (TYPE_CODE (formal_target) == TYPE_CODE_ARRAY
4034 && ada_is_array_descriptor_type (actual_target))
4035 result = desc_data (actual);
4036 else if (TYPE_CODE (actual_type) != TYPE_CODE_PTR)
4038 if (VALUE_LVAL (actual) != lval_memory)
4042 actual_type = ada_check_typedef (value_type (actual));
4043 val = allocate_value (actual_type);
4044 memcpy ((char *) value_contents_raw (val),
4045 (char *) value_contents (actual),
4046 TYPE_LENGTH (actual_type));
4047 actual = ensure_lval (val);
4049 result = value_addr (actual);
4053 return value_cast_pointers (formal_type, result);
4055 else if (TYPE_CODE (actual_type) == TYPE_CODE_PTR)
4056 return ada_value_ind (actual);
4061 /* Convert VALUE (which must be an address) to a CORE_ADDR that is a pointer of
4062 type TYPE. This is usually an inefficient no-op except on some targets
4063 (such as AVR) where the representation of a pointer and an address
4067 value_pointer (struct value *value, struct type *type)
4069 struct gdbarch *gdbarch = get_type_arch (type);
4070 unsigned len = TYPE_LENGTH (type);
4071 gdb_byte *buf = alloca (len);
4074 addr = value_address (value);
4075 gdbarch_address_to_pointer (gdbarch, type, buf, addr);
4076 addr = extract_unsigned_integer (buf, len, gdbarch_byte_order (gdbarch));
4081 /* Push a descriptor of type TYPE for array value ARR on the stack at
4082 *SP, updating *SP to reflect the new descriptor. Return either
4083 an lvalue representing the new descriptor, or (if TYPE is a pointer-
4084 to-descriptor type rather than a descriptor type), a struct value *
4085 representing a pointer to this descriptor. */
4087 static struct value *
4088 make_array_descriptor (struct type *type, struct value *arr)
4090 struct type *bounds_type = desc_bounds_type (type);
4091 struct type *desc_type = desc_base_type (type);
4092 struct value *descriptor = allocate_value (desc_type);
4093 struct value *bounds = allocate_value (bounds_type);
4096 for (i = ada_array_arity (ada_check_typedef (value_type (arr)));
4099 modify_field (value_type (bounds), value_contents_writeable (bounds),
4100 ada_array_bound (arr, i, 0),
4101 desc_bound_bitpos (bounds_type, i, 0),
4102 desc_bound_bitsize (bounds_type, i, 0));
4103 modify_field (value_type (bounds), value_contents_writeable (bounds),
4104 ada_array_bound (arr, i, 1),
4105 desc_bound_bitpos (bounds_type, i, 1),
4106 desc_bound_bitsize (bounds_type, i, 1));
4109 bounds = ensure_lval (bounds);
4111 modify_field (value_type (descriptor),
4112 value_contents_writeable (descriptor),
4113 value_pointer (ensure_lval (arr),
4114 TYPE_FIELD_TYPE (desc_type, 0)),
4115 fat_pntr_data_bitpos (desc_type),
4116 fat_pntr_data_bitsize (desc_type));
4118 modify_field (value_type (descriptor),
4119 value_contents_writeable (descriptor),
4120 value_pointer (bounds,
4121 TYPE_FIELD_TYPE (desc_type, 1)),
4122 fat_pntr_bounds_bitpos (desc_type),
4123 fat_pntr_bounds_bitsize (desc_type));
4125 descriptor = ensure_lval (descriptor);
4127 if (TYPE_CODE (type) == TYPE_CODE_PTR)
4128 return value_addr (descriptor);
4133 /* Dummy definitions for an experimental caching module that is not
4134 * used in the public sources. */
4137 lookup_cached_symbol (const char *name, domain_enum namespace,
4138 struct symbol **sym, struct block **block)
4144 cache_symbol (const char *name, domain_enum namespace, struct symbol *sym,
4145 struct block *block)
4151 /* Return the result of a standard (literal, C-like) lookup of NAME in
4152 given DOMAIN, visible from lexical block BLOCK. */
4154 static struct symbol *
4155 standard_lookup (const char *name, const struct block *block,
4160 if (lookup_cached_symbol (name, domain, &sym, NULL))
4162 sym = lookup_symbol_in_language (name, block, domain, language_c, 0);
4163 cache_symbol (name, domain, sym, block_found);
4168 /* Non-zero iff there is at least one non-function/non-enumeral symbol
4169 in the symbol fields of SYMS[0..N-1]. We treat enumerals as functions,
4170 since they contend in overloading in the same way. */
4172 is_nonfunction (struct ada_symbol_info syms[], int n)
4176 for (i = 0; i < n; i += 1)
4177 if (TYPE_CODE (SYMBOL_TYPE (syms[i].sym)) != TYPE_CODE_FUNC
4178 && (TYPE_CODE (SYMBOL_TYPE (syms[i].sym)) != TYPE_CODE_ENUM
4179 || SYMBOL_CLASS (syms[i].sym) != LOC_CONST))
4185 /* If true (non-zero), then TYPE0 and TYPE1 represent equivalent
4186 struct types. Otherwise, they may not. */
4189 equiv_types (struct type *type0, struct type *type1)
4193 if (type0 == NULL || type1 == NULL
4194 || TYPE_CODE (type0) != TYPE_CODE (type1))
4196 if ((TYPE_CODE (type0) == TYPE_CODE_STRUCT
4197 || TYPE_CODE (type0) == TYPE_CODE_ENUM)
4198 && ada_type_name (type0) != NULL && ada_type_name (type1) != NULL
4199 && strcmp (ada_type_name (type0), ada_type_name (type1)) == 0)
4205 /* True iff SYM0 represents the same entity as SYM1, or one that is
4206 no more defined than that of SYM1. */
4209 lesseq_defined_than (struct symbol *sym0, struct symbol *sym1)
4213 if (SYMBOL_DOMAIN (sym0) != SYMBOL_DOMAIN (sym1)
4214 || SYMBOL_CLASS (sym0) != SYMBOL_CLASS (sym1))
4217 switch (SYMBOL_CLASS (sym0))
4223 struct type *type0 = SYMBOL_TYPE (sym0);
4224 struct type *type1 = SYMBOL_TYPE (sym1);
4225 char *name0 = SYMBOL_LINKAGE_NAME (sym0);
4226 char *name1 = SYMBOL_LINKAGE_NAME (sym1);
4227 int len0 = strlen (name0);
4230 TYPE_CODE (type0) == TYPE_CODE (type1)
4231 && (equiv_types (type0, type1)
4232 || (len0 < strlen (name1) && strncmp (name0, name1, len0) == 0
4233 && strncmp (name1 + len0, "___XV", 5) == 0));
4236 return SYMBOL_VALUE (sym0) == SYMBOL_VALUE (sym1)
4237 && equiv_types (SYMBOL_TYPE (sym0), SYMBOL_TYPE (sym1));
4243 /* Append (SYM,BLOCK,SYMTAB) to the end of the array of struct ada_symbol_info
4244 records in OBSTACKP. Do nothing if SYM is a duplicate. */
4247 add_defn_to_vec (struct obstack *obstackp,
4249 struct block *block)
4252 struct ada_symbol_info *prevDefns = defns_collected (obstackp, 0);
4254 /* Do not try to complete stub types, as the debugger is probably
4255 already scanning all symbols matching a certain name at the
4256 time when this function is called. Trying to replace the stub
4257 type by its associated full type will cause us to restart a scan
4258 which may lead to an infinite recursion. Instead, the client
4259 collecting the matching symbols will end up collecting several
4260 matches, with at least one of them complete. It can then filter
4261 out the stub ones if needed. */
4263 for (i = num_defns_collected (obstackp) - 1; i >= 0; i -= 1)
4265 if (lesseq_defined_than (sym, prevDefns[i].sym))
4267 else if (lesseq_defined_than (prevDefns[i].sym, sym))
4269 prevDefns[i].sym = sym;
4270 prevDefns[i].block = block;
4276 struct ada_symbol_info info;
4280 obstack_grow (obstackp, &info, sizeof (struct ada_symbol_info));
4284 /* Number of ada_symbol_info structures currently collected in
4285 current vector in *OBSTACKP. */
4288 num_defns_collected (struct obstack *obstackp)
4290 return obstack_object_size (obstackp) / sizeof (struct ada_symbol_info);
4293 /* Vector of ada_symbol_info structures currently collected in current
4294 vector in *OBSTACKP. If FINISH, close off the vector and return
4295 its final address. */
4297 static struct ada_symbol_info *
4298 defns_collected (struct obstack *obstackp, int finish)
4301 return obstack_finish (obstackp);
4303 return (struct ada_symbol_info *) obstack_base (obstackp);
4306 /* Return a minimal symbol matching NAME according to Ada decoding
4307 rules. Returns NULL if there is no such minimal symbol. Names
4308 prefixed with "standard__" are handled specially: "standard__" is
4309 first stripped off, and only static and global symbols are searched. */
4311 struct minimal_symbol *
4312 ada_lookup_simple_minsym (const char *name)
4314 struct objfile *objfile;
4315 struct minimal_symbol *msymbol;
4318 if (strncmp (name, "standard__", sizeof ("standard__") - 1) == 0)
4320 name += sizeof ("standard__") - 1;
4324 wild_match = (strstr (name, "__") == NULL);
4326 ALL_MSYMBOLS (objfile, msymbol)
4328 if (match_name (SYMBOL_LINKAGE_NAME (msymbol), name, wild_match)
4329 && MSYMBOL_TYPE (msymbol) != mst_solib_trampoline)
4336 /* For all subprograms that statically enclose the subprogram of the
4337 selected frame, add symbols matching identifier NAME in DOMAIN
4338 and their blocks to the list of data in OBSTACKP, as for
4339 ada_add_block_symbols (q.v.). If WILD, treat as NAME with a
4343 add_symbols_from_enclosing_procs (struct obstack *obstackp,
4344 const char *name, domain_enum namespace,
4349 /* True if TYPE is definitely an artificial type supplied to a symbol
4350 for which no debugging information was given in the symbol file. */
4353 is_nondebugging_type (struct type *type)
4355 char *name = ada_type_name (type);
4357 return (name != NULL && strcmp (name, "<variable, no debug info>") == 0);
4360 /* Remove any non-debugging symbols in SYMS[0 .. NSYMS-1] that definitely
4361 duplicate other symbols in the list (The only case I know of where
4362 this happens is when object files containing stabs-in-ecoff are
4363 linked with files containing ordinary ecoff debugging symbols (or no
4364 debugging symbols)). Modifies SYMS to squeeze out deleted entries.
4365 Returns the number of items in the modified list. */
4368 remove_extra_symbols (struct ada_symbol_info *syms, int nsyms)
4377 /* If two symbols have the same name and one of them is a stub type,
4378 the get rid of the stub. */
4380 if (TYPE_STUB (SYMBOL_TYPE (syms[i].sym))
4381 && SYMBOL_LINKAGE_NAME (syms[i].sym) != NULL)
4383 for (j = 0; j < nsyms; j++)
4386 && !TYPE_STUB (SYMBOL_TYPE (syms[j].sym))
4387 && SYMBOL_LINKAGE_NAME (syms[j].sym) != NULL
4388 && strcmp (SYMBOL_LINKAGE_NAME (syms[i].sym),
4389 SYMBOL_LINKAGE_NAME (syms[j].sym)) == 0)
4394 /* Two symbols with the same name, same class and same address
4395 should be identical. */
4397 else if (SYMBOL_LINKAGE_NAME (syms[i].sym) != NULL
4398 && SYMBOL_CLASS (syms[i].sym) == LOC_STATIC
4399 && is_nondebugging_type (SYMBOL_TYPE (syms[i].sym)))
4401 for (j = 0; j < nsyms; j += 1)
4404 && SYMBOL_LINKAGE_NAME (syms[j].sym) != NULL
4405 && strcmp (SYMBOL_LINKAGE_NAME (syms[i].sym),
4406 SYMBOL_LINKAGE_NAME (syms[j].sym)) == 0
4407 && SYMBOL_CLASS (syms[i].sym) == SYMBOL_CLASS (syms[j].sym)
4408 && SYMBOL_VALUE_ADDRESS (syms[i].sym)
4409 == SYMBOL_VALUE_ADDRESS (syms[j].sym))
4416 for (j = i + 1; j < nsyms; j += 1)
4417 syms[j - 1] = syms[j];
4426 /* Given a type that corresponds to a renaming entity, use the type name
4427 to extract the scope (package name or function name, fully qualified,
4428 and following the GNAT encoding convention) where this renaming has been
4429 defined. The string returned needs to be deallocated after use. */
4432 xget_renaming_scope (struct type *renaming_type)
4434 /* The renaming types adhere to the following convention:
4435 <scope>__<rename>___<XR extension>.
4436 So, to extract the scope, we search for the "___XR" extension,
4437 and then backtrack until we find the first "__". */
4439 const char *name = type_name_no_tag (renaming_type);
4440 char *suffix = strstr (name, "___XR");
4445 /* Now, backtrack a bit until we find the first "__". Start looking
4446 at suffix - 3, as the <rename> part is at least one character long. */
4448 for (last = suffix - 3; last > name; last--)
4449 if (last[0] == '_' && last[1] == '_')
4452 /* Make a copy of scope and return it. */
4454 scope_len = last - name;
4455 scope = (char *) xmalloc ((scope_len + 1) * sizeof (char));
4457 strncpy (scope, name, scope_len);
4458 scope[scope_len] = '\0';
4463 /* Return nonzero if NAME corresponds to a package name. */
4466 is_package_name (const char *name)
4468 /* Here, We take advantage of the fact that no symbols are generated
4469 for packages, while symbols are generated for each function.
4470 So the condition for NAME represent a package becomes equivalent
4471 to NAME not existing in our list of symbols. There is only one
4472 small complication with library-level functions (see below). */
4476 /* If it is a function that has not been defined at library level,
4477 then we should be able to look it up in the symbols. */
4478 if (standard_lookup (name, NULL, VAR_DOMAIN) != NULL)
4481 /* Library-level function names start with "_ada_". See if function
4482 "_ada_" followed by NAME can be found. */
4484 /* Do a quick check that NAME does not contain "__", since library-level
4485 functions names cannot contain "__" in them. */
4486 if (strstr (name, "__") != NULL)
4489 fun_name = xstrprintf ("_ada_%s", name);
4491 return (standard_lookup (fun_name, NULL, VAR_DOMAIN) == NULL);
4494 /* Return nonzero if SYM corresponds to a renaming entity that is
4495 not visible from FUNCTION_NAME. */
4498 old_renaming_is_invisible (const struct symbol *sym, char *function_name)
4502 if (SYMBOL_CLASS (sym) != LOC_TYPEDEF)
4505 scope = xget_renaming_scope (SYMBOL_TYPE (sym));
4507 make_cleanup (xfree, scope);
4509 /* If the rename has been defined in a package, then it is visible. */
4510 if (is_package_name (scope))
4513 /* Check that the rename is in the current function scope by checking
4514 that its name starts with SCOPE. */
4516 /* If the function name starts with "_ada_", it means that it is
4517 a library-level function. Strip this prefix before doing the
4518 comparison, as the encoding for the renaming does not contain
4520 if (strncmp (function_name, "_ada_", 5) == 0)
4523 return (strncmp (function_name, scope, strlen (scope)) != 0);
4526 /* Remove entries from SYMS that corresponds to a renaming entity that
4527 is not visible from the function associated with CURRENT_BLOCK or
4528 that is superfluous due to the presence of more specific renaming
4529 information. Places surviving symbols in the initial entries of
4530 SYMS and returns the number of surviving symbols.
4533 First, in cases where an object renaming is implemented as a
4534 reference variable, GNAT may produce both the actual reference
4535 variable and the renaming encoding. In this case, we discard the
4538 Second, GNAT emits a type following a specified encoding for each renaming
4539 entity. Unfortunately, STABS currently does not support the definition
4540 of types that are local to a given lexical block, so all renamings types
4541 are emitted at library level. As a consequence, if an application
4542 contains two renaming entities using the same name, and a user tries to
4543 print the value of one of these entities, the result of the ada symbol
4544 lookup will also contain the wrong renaming type.
4546 This function partially covers for this limitation by attempting to
4547 remove from the SYMS list renaming symbols that should be visible
4548 from CURRENT_BLOCK. However, there does not seem be a 100% reliable
4549 method with the current information available. The implementation
4550 below has a couple of limitations (FIXME: brobecker-2003-05-12):
4552 - When the user tries to print a rename in a function while there
4553 is another rename entity defined in a package: Normally, the
4554 rename in the function has precedence over the rename in the
4555 package, so the latter should be removed from the list. This is
4556 currently not the case.
4558 - This function will incorrectly remove valid renames if
4559 the CURRENT_BLOCK corresponds to a function which symbol name
4560 has been changed by an "Export" pragma. As a consequence,
4561 the user will be unable to print such rename entities. */
4564 remove_irrelevant_renamings (struct ada_symbol_info *syms,
4565 int nsyms, const struct block *current_block)
4567 struct symbol *current_function;
4568 char *current_function_name;
4570 int is_new_style_renaming;
4572 /* If there is both a renaming foo___XR... encoded as a variable and
4573 a simple variable foo in the same block, discard the latter.
4574 First, zero out such symbols, then compress. */
4575 is_new_style_renaming = 0;
4576 for (i = 0; i < nsyms; i += 1)
4578 struct symbol *sym = syms[i].sym;
4579 struct block *block = syms[i].block;
4583 if (sym == NULL || SYMBOL_CLASS (sym) == LOC_TYPEDEF)
4585 name = SYMBOL_LINKAGE_NAME (sym);
4586 suffix = strstr (name, "___XR");
4590 int name_len = suffix - name;
4593 is_new_style_renaming = 1;
4594 for (j = 0; j < nsyms; j += 1)
4595 if (i != j && syms[j].sym != NULL
4596 && strncmp (name, SYMBOL_LINKAGE_NAME (syms[j].sym),
4598 && block == syms[j].block)
4602 if (is_new_style_renaming)
4606 for (j = k = 0; j < nsyms; j += 1)
4607 if (syms[j].sym != NULL)
4615 /* Extract the function name associated to CURRENT_BLOCK.
4616 Abort if unable to do so. */
4618 if (current_block == NULL)
4621 current_function = block_linkage_function (current_block);
4622 if (current_function == NULL)
4625 current_function_name = SYMBOL_LINKAGE_NAME (current_function);
4626 if (current_function_name == NULL)
4629 /* Check each of the symbols, and remove it from the list if it is
4630 a type corresponding to a renaming that is out of the scope of
4631 the current block. */
4636 if (ada_parse_renaming (syms[i].sym, NULL, NULL, NULL)
4637 == ADA_OBJECT_RENAMING
4638 && old_renaming_is_invisible (syms[i].sym, current_function_name))
4642 for (j = i + 1; j < nsyms; j += 1)
4643 syms[j - 1] = syms[j];
4653 /* Add to OBSTACKP all symbols from BLOCK (and its super-blocks)
4654 whose name and domain match NAME and DOMAIN respectively.
4655 If no match was found, then extend the search to "enclosing"
4656 routines (in other words, if we're inside a nested function,
4657 search the symbols defined inside the enclosing functions).
4659 Note: This function assumes that OBSTACKP has 0 (zero) element in it. */
4662 ada_add_local_symbols (struct obstack *obstackp, const char *name,
4663 struct block *block, domain_enum domain,
4666 int block_depth = 0;
4668 while (block != NULL)
4671 ada_add_block_symbols (obstackp, block, name, domain, NULL, wild_match);
4673 /* If we found a non-function match, assume that's the one. */
4674 if (is_nonfunction (defns_collected (obstackp, 0),
4675 num_defns_collected (obstackp)))
4678 block = BLOCK_SUPERBLOCK (block);
4681 /* If no luck so far, try to find NAME as a local symbol in some lexically
4682 enclosing subprogram. */
4683 if (num_defns_collected (obstackp) == 0 && block_depth > 2)
4684 add_symbols_from_enclosing_procs (obstackp, name, domain, wild_match);
4687 /* An object of this type is used as the user_data argument when
4688 calling the map_matching_symbols method. */
4692 struct objfile *objfile;
4693 struct obstack *obstackp;
4694 struct symbol *arg_sym;
4698 /* A callback for add_matching_symbols that adds SYM, found in BLOCK,
4699 to a list of symbols. DATA0 is a pointer to a struct match_data *
4700 containing the obstack that collects the symbol list, the file that SYM
4701 must come from, a flag indicating whether a non-argument symbol has
4702 been found in the current block, and the last argument symbol
4703 passed in SYM within the current block (if any). When SYM is null,
4704 marking the end of a block, the argument symbol is added if no
4705 other has been found. */
4708 aux_add_nonlocal_symbols (struct block *block, struct symbol *sym, void *data0)
4710 struct match_data *data = (struct match_data *) data0;
4714 if (!data->found_sym && data->arg_sym != NULL)
4715 add_defn_to_vec (data->obstackp,
4716 fixup_symbol_section (data->arg_sym, data->objfile),
4718 data->found_sym = 0;
4719 data->arg_sym = NULL;
4723 if (SYMBOL_CLASS (sym) == LOC_UNRESOLVED)
4725 else if (SYMBOL_IS_ARGUMENT (sym))
4726 data->arg_sym = sym;
4729 data->found_sym = 1;
4730 add_defn_to_vec (data->obstackp,
4731 fixup_symbol_section (sym, data->objfile),
4738 /* Compare STRING1 to STRING2, with results as for strcmp.
4739 Compatible with strcmp_iw in that strcmp_iw (STRING1, STRING2) <= 0
4740 implies compare_names (STRING1, STRING2) (they may differ as to
4741 what symbols compare equal). */
4744 compare_names (const char *string1, const char *string2)
4746 while (*string1 != '\0' && *string2 != '\0')
4748 if (isspace (*string1) || isspace (*string2))
4749 return strcmp_iw_ordered (string1, string2);
4750 if (*string1 != *string2)
4758 return strcmp_iw_ordered (string1, string2);
4760 if (*string2 == '\0')
4762 if (is_name_suffix (string1))
4769 if (*string2 == '(')
4770 return strcmp_iw_ordered (string1, string2);
4772 return *string1 - *string2;
4776 /* Add to OBSTACKP all non-local symbols whose name and domain match
4777 NAME and DOMAIN respectively. The search is performed on GLOBAL_BLOCK
4778 symbols if GLOBAL is non-zero, or on STATIC_BLOCK symbols otherwise. */
4781 add_nonlocal_symbols (struct obstack *obstackp, const char *name,
4782 domain_enum domain, int global,
4785 struct objfile *objfile;
4786 struct match_data data;
4788 data.obstackp = obstackp;
4789 data.arg_sym = NULL;
4791 ALL_OBJFILES (objfile)
4793 data.objfile = objfile;
4796 objfile->sf->qf->map_matching_symbols (name, domain, objfile, global,
4797 aux_add_nonlocal_symbols, &data,
4800 objfile->sf->qf->map_matching_symbols (name, domain, objfile, global,
4801 aux_add_nonlocal_symbols, &data,
4802 full_match, compare_names);
4805 if (num_defns_collected (obstackp) == 0 && global && !is_wild_match)
4807 ALL_OBJFILES (objfile)
4809 char *name1 = alloca (strlen (name) + sizeof ("_ada_"));
4810 strcpy (name1, "_ada_");
4811 strcpy (name1 + sizeof ("_ada_") - 1, name);
4812 data.objfile = objfile;
4813 objfile->sf->qf->map_matching_symbols (name1, domain,
4815 aux_add_nonlocal_symbols,
4817 full_match, compare_names);
4822 /* Find symbols in DOMAIN matching NAME0, in BLOCK0 and enclosing
4823 scope and in global scopes, returning the number of matches. Sets
4824 *RESULTS to point to a vector of (SYM,BLOCK) tuples,
4825 indicating the symbols found and the blocks and symbol tables (if
4826 any) in which they were found. This vector are transient---good only to
4827 the next call of ada_lookup_symbol_list. Any non-function/non-enumeral
4828 symbol match within the nest of blocks whose innermost member is BLOCK0,
4829 is the one match returned (no other matches in that or
4830 enclosing blocks is returned). If there are any matches in or
4831 surrounding BLOCK0, then these alone are returned. Otherwise, the
4832 search extends to global and file-scope (static) symbol tables.
4833 Names prefixed with "standard__" are handled specially: "standard__"
4834 is first stripped off, and only static and global symbols are searched. */
4837 ada_lookup_symbol_list (const char *name0, const struct block *block0,
4838 domain_enum namespace,
4839 struct ada_symbol_info **results)
4842 struct block *block;
4848 obstack_free (&symbol_list_obstack, NULL);
4849 obstack_init (&symbol_list_obstack);
4853 /* Search specified block and its superiors. */
4855 wild_match = (strstr (name0, "__") == NULL);
4857 block = (struct block *) block0; /* FIXME: No cast ought to be
4858 needed, but adding const will
4859 have a cascade effect. */
4861 /* Special case: If the user specifies a symbol name inside package
4862 Standard, do a non-wild matching of the symbol name without
4863 the "standard__" prefix. This was primarily introduced in order
4864 to allow the user to specifically access the standard exceptions
4865 using, for instance, Standard.Constraint_Error when Constraint_Error
4866 is ambiguous (due to the user defining its own Constraint_Error
4867 entity inside its program). */
4868 if (strncmp (name0, "standard__", sizeof ("standard__") - 1) == 0)
4872 name = name0 + sizeof ("standard__") - 1;
4875 /* Check the non-global symbols. If we have ANY match, then we're done. */
4877 ada_add_local_symbols (&symbol_list_obstack, name, block, namespace,
4879 if (num_defns_collected (&symbol_list_obstack) > 0)
4882 /* No non-global symbols found. Check our cache to see if we have
4883 already performed this search before. If we have, then return
4887 if (lookup_cached_symbol (name0, namespace, &sym, &block))
4890 add_defn_to_vec (&symbol_list_obstack, sym, block);
4894 /* Search symbols from all global blocks. */
4896 add_nonlocal_symbols (&symbol_list_obstack, name, namespace, 1,
4899 /* Now add symbols from all per-file blocks if we've gotten no hits
4900 (not strictly correct, but perhaps better than an error). */
4902 if (num_defns_collected (&symbol_list_obstack) == 0)
4903 add_nonlocal_symbols (&symbol_list_obstack, name, namespace, 0,
4907 ndefns = num_defns_collected (&symbol_list_obstack);
4908 *results = defns_collected (&symbol_list_obstack, 1);
4910 ndefns = remove_extra_symbols (*results, ndefns);
4913 cache_symbol (name0, namespace, NULL, NULL);
4915 if (ndefns == 1 && cacheIfUnique)
4916 cache_symbol (name0, namespace, (*results)[0].sym, (*results)[0].block);
4918 ndefns = remove_irrelevant_renamings (*results, ndefns, block0);
4924 ada_lookup_encoded_symbol (const char *name, const struct block *block0,
4925 domain_enum namespace, struct block **block_found)
4927 struct ada_symbol_info *candidates;
4930 n_candidates = ada_lookup_symbol_list (name, block0, namespace, &candidates);
4932 if (n_candidates == 0)
4935 if (block_found != NULL)
4936 *block_found = candidates[0].block;
4938 return fixup_symbol_section (candidates[0].sym, NULL);
4941 /* Return a symbol in DOMAIN matching NAME, in BLOCK0 and enclosing
4942 scope and in global scopes, or NULL if none. NAME is folded and
4943 encoded first. Otherwise, the result is as for ada_lookup_symbol_list,
4944 choosing the first symbol if there are multiple choices.
4945 *IS_A_FIELD_OF_THIS is set to 0 and *SYMTAB is set to the symbol
4946 table in which the symbol was found (in both cases, these
4947 assignments occur only if the pointers are non-null). */
4949 ada_lookup_symbol (const char *name, const struct block *block0,
4950 domain_enum namespace, int *is_a_field_of_this)
4952 if (is_a_field_of_this != NULL)
4953 *is_a_field_of_this = 0;
4956 ada_lookup_encoded_symbol (ada_encode (ada_fold_name (name)),
4957 block0, namespace, NULL);
4960 static struct symbol *
4961 ada_lookup_symbol_nonlocal (const char *name,
4962 const struct block *block,
4963 const domain_enum domain)
4965 return ada_lookup_symbol (name, block_static_block (block), domain, NULL);
4969 /* True iff STR is a possible encoded suffix of a normal Ada name
4970 that is to be ignored for matching purposes. Suffixes of parallel
4971 names (e.g., XVE) are not included here. Currently, the possible suffixes
4972 are given by any of the regular expressions:
4974 [.$][0-9]+ [nested subprogram suffix, on platforms such as GNU/Linux]
4975 ___[0-9]+ [nested subprogram suffix, on platforms such as HP/UX]
4976 _E[0-9]+[bs]$ [protected object entry suffixes]
4977 (X[nb]*)?((\$|__)[0-9](_?[0-9]+)|___(JM|LJM|X([FDBUP].*|R[^T]?)))?$
4979 Also, any leading "__[0-9]+" sequence is skipped before the suffix
4980 match is performed. This sequence is used to differentiate homonyms,
4981 is an optional part of a valid name suffix. */
4984 is_name_suffix (const char *str)
4987 const char *matching;
4988 const int len = strlen (str);
4990 /* Skip optional leading __[0-9]+. */
4992 if (len > 3 && str[0] == '_' && str[1] == '_' && isdigit (str[2]))
4995 while (isdigit (str[0]))
5001 if (str[0] == '.' || str[0] == '$')
5004 while (isdigit (matching[0]))
5006 if (matching[0] == '\0')
5012 if (len > 3 && str[0] == '_' && str[1] == '_' && str[2] == '_')
5015 while (isdigit (matching[0]))
5017 if (matching[0] == '\0')
5022 /* FIXME: brobecker/2005-09-23: Protected Object subprograms end
5023 with a N at the end. Unfortunately, the compiler uses the same
5024 convention for other internal types it creates. So treating
5025 all entity names that end with an "N" as a name suffix causes
5026 some regressions. For instance, consider the case of an enumerated
5027 type. To support the 'Image attribute, it creates an array whose
5029 Having a single character like this as a suffix carrying some
5030 information is a bit risky. Perhaps we should change the encoding
5031 to be something like "_N" instead. In the meantime, do not do
5032 the following check. */
5033 /* Protected Object Subprograms */
5034 if (len == 1 && str [0] == 'N')
5039 if (len > 3 && str[0] == '_' && str [1] == 'E' && isdigit (str[2]))
5042 while (isdigit (matching[0]))
5044 if ((matching[0] == 'b' || matching[0] == 's')
5045 && matching [1] == '\0')
5049 /* ??? We should not modify STR directly, as we are doing below. This
5050 is fine in this case, but may become problematic later if we find
5051 that this alternative did not work, and want to try matching
5052 another one from the begining of STR. Since we modified it, we
5053 won't be able to find the begining of the string anymore! */
5057 while (str[0] != '_' && str[0] != '\0')
5059 if (str[0] != 'n' && str[0] != 'b')
5065 if (str[0] == '\000')
5070 if (str[1] != '_' || str[2] == '\000')
5074 if (strcmp (str + 3, "JM") == 0)
5076 /* FIXME: brobecker/2004-09-30: GNAT will soon stop using
5077 the LJM suffix in favor of the JM one. But we will
5078 still accept LJM as a valid suffix for a reasonable
5079 amount of time, just to allow ourselves to debug programs
5080 compiled using an older version of GNAT. */
5081 if (strcmp (str + 3, "LJM") == 0)
5085 if (str[4] == 'F' || str[4] == 'D' || str[4] == 'B'
5086 || str[4] == 'U' || str[4] == 'P')
5088 if (str[4] == 'R' && str[5] != 'T')
5092 if (!isdigit (str[2]))
5094 for (k = 3; str[k] != '\0'; k += 1)
5095 if (!isdigit (str[k]) && str[k] != '_')
5099 if (str[0] == '$' && isdigit (str[1]))
5101 for (k = 2; str[k] != '\0'; k += 1)
5102 if (!isdigit (str[k]) && str[k] != '_')
5109 /* Return non-zero if the string starting at NAME and ending before
5110 NAME_END contains no capital letters. */
5113 is_valid_name_for_wild_match (const char *name0)
5115 const char *decoded_name = ada_decode (name0);
5118 /* If the decoded name starts with an angle bracket, it means that
5119 NAME0 does not follow the GNAT encoding format. It should then
5120 not be allowed as a possible wild match. */
5121 if (decoded_name[0] == '<')
5124 for (i=0; decoded_name[i] != '\0'; i++)
5125 if (isalpha (decoded_name[i]) && !islower (decoded_name[i]))
5131 /* Advance *NAMEP to next occurrence of TARGET0 in the string NAME0
5132 that could start a simple name. Assumes that *NAMEP points into
5133 the string beginning at NAME0. */
5136 advance_wild_match (const char **namep, const char *name0, int target0)
5138 const char *name = *namep;
5148 if ((t1 >= 'a' && t1 <= 'z') || (t1 >= '0' && t1 <= '9'))
5151 if (name == name0 + 5 && strncmp (name0, "_ada", 4) == 0)
5156 else if (t1 == '_' && ((name[2] >= 'a' && name[2] <= 'z')
5157 || name[2] == target0))
5165 else if ((t0 >= 'a' && t0 <= 'z') || (t0 >= '0' && t0 <= '9'))
5175 /* Return 0 iff NAME encodes a name of the form prefix.PATN. Ignores any
5176 informational suffixes of NAME (i.e., for which is_name_suffix is
5177 true). Assumes that PATN is a lower-cased Ada simple name. */
5180 wild_match (const char *name, const char *patn)
5183 const char *name0 = name;
5187 const char *match = name;
5191 for (name += 1, p = patn + 1; *p != '\0'; name += 1, p += 1)
5194 if (*p == '\0' && is_name_suffix (name))
5195 return match != name0 && !is_valid_name_for_wild_match (name0);
5197 if (name[-1] == '_')
5200 if (!advance_wild_match (&name, name0, *patn))
5205 /* Returns 0 iff symbol name SYM_NAME matches SEARCH_NAME, apart from
5206 informational suffix. */
5209 full_match (const char *sym_name, const char *search_name)
5211 return !match_name (sym_name, search_name, 0);
5215 /* Add symbols from BLOCK matching identifier NAME in DOMAIN to
5216 vector *defn_symbols, updating the list of symbols in OBSTACKP
5217 (if necessary). If WILD, treat as NAME with a wildcard prefix.
5218 OBJFILE is the section containing BLOCK.
5219 SYMTAB is recorded with each symbol added. */
5222 ada_add_block_symbols (struct obstack *obstackp,
5223 struct block *block, const char *name,
5224 domain_enum domain, struct objfile *objfile,
5227 struct dict_iterator iter;
5228 int name_len = strlen (name);
5229 /* A matching argument symbol, if any. */
5230 struct symbol *arg_sym;
5231 /* Set true when we find a matching non-argument symbol. */
5239 for (sym = dict_iter_match_first (BLOCK_DICT (block), name,
5241 sym != NULL; sym = dict_iter_match_next (name, wild_match, &iter))
5243 if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
5244 SYMBOL_DOMAIN (sym), domain)
5245 && wild_match (SYMBOL_LINKAGE_NAME (sym), name) == 0)
5247 if (SYMBOL_CLASS (sym) == LOC_UNRESOLVED)
5249 else if (SYMBOL_IS_ARGUMENT (sym))
5254 add_defn_to_vec (obstackp,
5255 fixup_symbol_section (sym, objfile),
5263 for (sym = dict_iter_match_first (BLOCK_DICT (block), name,
5265 sym != NULL; sym = dict_iter_match_next (name, full_match, &iter))
5267 if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
5268 SYMBOL_DOMAIN (sym), domain))
5270 if (SYMBOL_CLASS (sym) != LOC_UNRESOLVED)
5272 if (SYMBOL_IS_ARGUMENT (sym))
5277 add_defn_to_vec (obstackp,
5278 fixup_symbol_section (sym, objfile),
5286 if (!found_sym && arg_sym != NULL)
5288 add_defn_to_vec (obstackp,
5289 fixup_symbol_section (arg_sym, objfile),
5298 ALL_BLOCK_SYMBOLS (block, iter, sym)
5300 if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
5301 SYMBOL_DOMAIN (sym), domain))
5305 cmp = (int) '_' - (int) SYMBOL_LINKAGE_NAME (sym)[0];
5308 cmp = strncmp ("_ada_", SYMBOL_LINKAGE_NAME (sym), 5);
5310 cmp = strncmp (name, SYMBOL_LINKAGE_NAME (sym) + 5,
5315 && is_name_suffix (SYMBOL_LINKAGE_NAME (sym) + name_len + 5))
5317 if (SYMBOL_CLASS (sym) != LOC_UNRESOLVED)
5319 if (SYMBOL_IS_ARGUMENT (sym))
5324 add_defn_to_vec (obstackp,
5325 fixup_symbol_section (sym, objfile),
5333 /* NOTE: This really shouldn't be needed for _ada_ symbols.
5334 They aren't parameters, right? */
5335 if (!found_sym && arg_sym != NULL)
5337 add_defn_to_vec (obstackp,
5338 fixup_symbol_section (arg_sym, objfile),
5345 /* Symbol Completion */
5347 /* If SYM_NAME is a completion candidate for TEXT, return this symbol
5348 name in a form that's appropriate for the completion. The result
5349 does not need to be deallocated, but is only good until the next call.
5351 TEXT_LEN is equal to the length of TEXT.
5352 Perform a wild match if WILD_MATCH is set.
5353 ENCODED should be set if TEXT represents the start of a symbol name
5354 in its encoded form. */
5357 symbol_completion_match (const char *sym_name,
5358 const char *text, int text_len,
5359 int wild_match, int encoded)
5361 const int verbatim_match = (text[0] == '<');
5366 /* Strip the leading angle bracket. */
5371 /* First, test against the fully qualified name of the symbol. */
5373 if (strncmp (sym_name, text, text_len) == 0)
5376 if (match && !encoded)
5378 /* One needed check before declaring a positive match is to verify
5379 that iff we are doing a verbatim match, the decoded version
5380 of the symbol name starts with '<'. Otherwise, this symbol name
5381 is not a suitable completion. */
5382 const char *sym_name_copy = sym_name;
5383 int has_angle_bracket;
5385 sym_name = ada_decode (sym_name);
5386 has_angle_bracket = (sym_name[0] == '<');
5387 match = (has_angle_bracket == verbatim_match);
5388 sym_name = sym_name_copy;
5391 if (match && !verbatim_match)
5393 /* When doing non-verbatim match, another check that needs to
5394 be done is to verify that the potentially matching symbol name
5395 does not include capital letters, because the ada-mode would
5396 not be able to understand these symbol names without the
5397 angle bracket notation. */
5400 for (tmp = sym_name; *tmp != '\0' && !isupper (*tmp); tmp++);
5405 /* Second: Try wild matching... */
5407 if (!match && wild_match)
5409 /* Since we are doing wild matching, this means that TEXT
5410 may represent an unqualified symbol name. We therefore must
5411 also compare TEXT against the unqualified name of the symbol. */
5412 sym_name = ada_unqualified_name (ada_decode (sym_name));
5414 if (strncmp (sym_name, text, text_len) == 0)
5418 /* Finally: If we found a mach, prepare the result to return. */
5424 sym_name = add_angle_brackets (sym_name);
5427 sym_name = ada_decode (sym_name);
5432 DEF_VEC_P (char_ptr);
5434 /* A companion function to ada_make_symbol_completion_list().
5435 Check if SYM_NAME represents a symbol which name would be suitable
5436 to complete TEXT (TEXT_LEN is the length of TEXT), in which case
5437 it is appended at the end of the given string vector SV.
5439 ORIG_TEXT is the string original string from the user command
5440 that needs to be completed. WORD is the entire command on which
5441 completion should be performed. These two parameters are used to
5442 determine which part of the symbol name should be added to the
5444 if WILD_MATCH is set, then wild matching is performed.
5445 ENCODED should be set if TEXT represents a symbol name in its
5446 encoded formed (in which case the completion should also be
5450 symbol_completion_add (VEC(char_ptr) **sv,
5451 const char *sym_name,
5452 const char *text, int text_len,
5453 const char *orig_text, const char *word,
5454 int wild_match, int encoded)
5456 const char *match = symbol_completion_match (sym_name, text, text_len,
5457 wild_match, encoded);
5463 /* We found a match, so add the appropriate completion to the given
5466 if (word == orig_text)
5468 completion = xmalloc (strlen (match) + 5);
5469 strcpy (completion, match);
5471 else if (word > orig_text)
5473 /* Return some portion of sym_name. */
5474 completion = xmalloc (strlen (match) + 5);
5475 strcpy (completion, match + (word - orig_text));
5479 /* Return some of ORIG_TEXT plus sym_name. */
5480 completion = xmalloc (strlen (match) + (orig_text - word) + 5);
5481 strncpy (completion, word, orig_text - word);
5482 completion[orig_text - word] = '\0';
5483 strcat (completion, match);
5486 VEC_safe_push (char_ptr, *sv, completion);
5489 /* An object of this type is passed as the user_data argument to the
5490 map_partial_symbol_names method. */
5491 struct add_partial_datum
5493 VEC(char_ptr) **completions;
5502 /* A callback for map_partial_symbol_names. */
5504 ada_add_partial_symbol_completions (const char *name, void *user_data)
5506 struct add_partial_datum *data = user_data;
5508 symbol_completion_add (data->completions, name,
5509 data->text, data->text_len, data->text0, data->word,
5510 data->wild_match, data->encoded);
5513 /* Return a list of possible symbol names completing TEXT0. The list
5514 is NULL terminated. WORD is the entire command on which completion
5518 ada_make_symbol_completion_list (char *text0, char *word)
5524 VEC(char_ptr) *completions = VEC_alloc (char_ptr, 128);
5527 struct minimal_symbol *msymbol;
5528 struct objfile *objfile;
5529 struct block *b, *surrounding_static_block = 0;
5531 struct dict_iterator iter;
5533 if (text0[0] == '<')
5535 text = xstrdup (text0);
5536 make_cleanup (xfree, text);
5537 text_len = strlen (text);
5543 text = xstrdup (ada_encode (text0));
5544 make_cleanup (xfree, text);
5545 text_len = strlen (text);
5546 for (i = 0; i < text_len; i++)
5547 text[i] = tolower (text[i]);
5549 encoded = (strstr (text0, "__") != NULL);
5550 /* If the name contains a ".", then the user is entering a fully
5551 qualified entity name, and the match must not be done in wild
5552 mode. Similarly, if the user wants to complete what looks like
5553 an encoded name, the match must not be done in wild mode. */
5554 wild_match = (strchr (text0, '.') == NULL && !encoded);
5557 /* First, look at the partial symtab symbols. */
5559 struct add_partial_datum data;
5561 data.completions = &completions;
5563 data.text_len = text_len;
5566 data.wild_match = wild_match;
5567 data.encoded = encoded;
5568 map_partial_symbol_names (ada_add_partial_symbol_completions, &data);
5571 /* At this point scan through the misc symbol vectors and add each
5572 symbol you find to the list. Eventually we want to ignore
5573 anything that isn't a text symbol (everything else will be
5574 handled by the psymtab code above). */
5576 ALL_MSYMBOLS (objfile, msymbol)
5579 symbol_completion_add (&completions, SYMBOL_LINKAGE_NAME (msymbol),
5580 text, text_len, text0, word, wild_match, encoded);
5583 /* Search upwards from currently selected frame (so that we can
5584 complete on local vars. */
5586 for (b = get_selected_block (0); b != NULL; b = BLOCK_SUPERBLOCK (b))
5588 if (!BLOCK_SUPERBLOCK (b))
5589 surrounding_static_block = b; /* For elmin of dups */
5591 ALL_BLOCK_SYMBOLS (b, iter, sym)
5593 symbol_completion_add (&completions, SYMBOL_LINKAGE_NAME (sym),
5594 text, text_len, text0, word,
5595 wild_match, encoded);
5599 /* Go through the symtabs and check the externs and statics for
5600 symbols which match. */
5602 ALL_SYMTABS (objfile, s)
5605 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK);
5606 ALL_BLOCK_SYMBOLS (b, iter, sym)
5608 symbol_completion_add (&completions, SYMBOL_LINKAGE_NAME (sym),
5609 text, text_len, text0, word,
5610 wild_match, encoded);
5614 ALL_SYMTABS (objfile, s)
5617 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK);
5618 /* Don't do this block twice. */
5619 if (b == surrounding_static_block)
5621 ALL_BLOCK_SYMBOLS (b, iter, sym)
5623 symbol_completion_add (&completions, SYMBOL_LINKAGE_NAME (sym),
5624 text, text_len, text0, word,
5625 wild_match, encoded);
5629 /* Append the closing NULL entry. */
5630 VEC_safe_push (char_ptr, completions, NULL);
5632 /* Make a copy of the COMPLETIONS VEC before we free it, and then
5633 return the copy. It's unfortunate that we have to make a copy
5634 of an array that we're about to destroy, but there is nothing much
5635 we can do about it. Fortunately, it's typically not a very large
5638 const size_t completions_size =
5639 VEC_length (char_ptr, completions) * sizeof (char *);
5640 char **result = xmalloc (completions_size);
5642 memcpy (result, VEC_address (char_ptr, completions), completions_size);
5644 VEC_free (char_ptr, completions);
5651 /* Return non-zero if TYPE is a pointer to the GNAT dispatch table used
5652 for tagged types. */
5655 ada_is_dispatch_table_ptr_type (struct type *type)
5659 if (TYPE_CODE (type) != TYPE_CODE_PTR)
5662 name = TYPE_NAME (TYPE_TARGET_TYPE (type));
5666 return (strcmp (name, "ada__tags__dispatch_table") == 0);
5669 /* True if field number FIELD_NUM in struct or union type TYPE is supposed
5670 to be invisible to users. */
5673 ada_is_ignored_field (struct type *type, int field_num)
5675 if (field_num < 0 || field_num > TYPE_NFIELDS (type))
5678 /* Check the name of that field. */
5680 const char *name = TYPE_FIELD_NAME (type, field_num);
5682 /* Anonymous field names should not be printed.
5683 brobecker/2007-02-20: I don't think this can actually happen
5684 but we don't want to print the value of annonymous fields anyway. */
5688 /* A field named "_parent" is internally generated by GNAT for
5689 tagged types, and should not be printed either. */
5690 if (name[0] == '_' && strncmp (name, "_parent", 7) != 0)
5694 /* If this is the dispatch table of a tagged type, then ignore. */
5695 if (ada_is_tagged_type (type, 1)
5696 && ada_is_dispatch_table_ptr_type (TYPE_FIELD_TYPE (type, field_num)))
5699 /* Not a special field, so it should not be ignored. */
5703 /* True iff TYPE has a tag field. If REFOK, then TYPE may also be a
5704 pointer or reference type whose ultimate target has a tag field. */
5707 ada_is_tagged_type (struct type *type, int refok)
5709 return (ada_lookup_struct_elt_type (type, "_tag", refok, 1, NULL) != NULL);
5712 /* True iff TYPE represents the type of X'Tag */
5715 ada_is_tag_type (struct type *type)
5717 if (type == NULL || TYPE_CODE (type) != TYPE_CODE_PTR)
5721 const char *name = ada_type_name (TYPE_TARGET_TYPE (type));
5723 return (name != NULL
5724 && strcmp (name, "ada__tags__dispatch_table") == 0);
5728 /* The type of the tag on VAL. */
5731 ada_tag_type (struct value *val)
5733 return ada_lookup_struct_elt_type (value_type (val), "_tag", 1, 0, NULL);
5736 /* The value of the tag on VAL. */
5739 ada_value_tag (struct value *val)
5741 return ada_value_struct_elt (val, "_tag", 0);
5744 /* The value of the tag on the object of type TYPE whose contents are
5745 saved at VALADDR, if it is non-null, or is at memory address
5748 static struct value *
5749 value_tag_from_contents_and_address (struct type *type,
5750 const gdb_byte *valaddr,
5753 int tag_byte_offset;
5754 struct type *tag_type;
5756 if (find_struct_field ("_tag", type, 0, &tag_type, &tag_byte_offset,
5759 const gdb_byte *valaddr1 = ((valaddr == NULL)
5761 : valaddr + tag_byte_offset);
5762 CORE_ADDR address1 = (address == 0) ? 0 : address + tag_byte_offset;
5764 return value_from_contents_and_address (tag_type, valaddr1, address1);
5769 static struct type *
5770 type_from_tag (struct value *tag)
5772 const char *type_name = ada_tag_name (tag);
5774 if (type_name != NULL)
5775 return ada_find_any_type (ada_encode (type_name));
5786 static int ada_tag_name_1 (void *);
5787 static int ada_tag_name_2 (struct tag_args *);
5789 /* Wrapper function used by ada_tag_name. Given a struct tag_args*
5790 value ARGS, sets ARGS->name to the tag name of ARGS->tag.
5791 The value stored in ARGS->name is valid until the next call to
5795 ada_tag_name_1 (void *args0)
5797 struct tag_args *args = (struct tag_args *) args0;
5798 static char name[1024];
5803 val = ada_value_struct_elt (args->tag, "tsd", 1);
5805 return ada_tag_name_2 (args);
5806 val = ada_value_struct_elt (val, "expanded_name", 1);
5809 read_memory_string (value_as_address (val), name, sizeof (name) - 1);
5810 for (p = name; *p != '\0'; p += 1)
5817 /* Return the "ada__tags__type_specific_data" type. */
5819 static struct type *
5820 ada_get_tsd_type (struct inferior *inf)
5822 struct ada_inferior_data *data = get_ada_inferior_data (inf);
5824 if (data->tsd_type == 0)
5825 data->tsd_type = ada_find_any_type ("ada__tags__type_specific_data");
5826 return data->tsd_type;
5829 /* Utility function for ada_tag_name_1 that tries the second
5830 representation for the dispatch table (in which there is no
5831 explicit 'tsd' field in the referent of the tag pointer, and instead
5832 the tsd pointer is stored just before the dispatch table. */
5835 ada_tag_name_2 (struct tag_args *args)
5837 struct type *info_type;
5838 static char name[1024];
5840 struct value *val, *valp;
5843 info_type = ada_get_tsd_type (current_inferior());
5844 if (info_type == NULL)
5846 info_type = lookup_pointer_type (lookup_pointer_type (info_type));
5847 valp = value_cast (info_type, args->tag);
5850 val = value_ind (value_ptradd (valp, -1));
5853 val = ada_value_struct_elt (val, "expanded_name", 1);
5856 read_memory_string (value_as_address (val), name, sizeof (name) - 1);
5857 for (p = name; *p != '\0'; p += 1)
5864 /* The type name of the dynamic type denoted by the 'tag value TAG, as
5868 ada_tag_name (struct value *tag)
5870 struct tag_args args;
5872 if (!ada_is_tag_type (value_type (tag)))
5876 catch_errors (ada_tag_name_1, &args, NULL, RETURN_MASK_ALL);
5880 /* The parent type of TYPE, or NULL if none. */
5883 ada_parent_type (struct type *type)
5887 type = ada_check_typedef (type);
5889 if (type == NULL || TYPE_CODE (type) != TYPE_CODE_STRUCT)
5892 for (i = 0; i < TYPE_NFIELDS (type); i += 1)
5893 if (ada_is_parent_field (type, i))
5895 struct type *parent_type = TYPE_FIELD_TYPE (type, i);
5897 /* If the _parent field is a pointer, then dereference it. */
5898 if (TYPE_CODE (parent_type) == TYPE_CODE_PTR)
5899 parent_type = TYPE_TARGET_TYPE (parent_type);
5900 /* If there is a parallel XVS type, get the actual base type. */
5901 parent_type = ada_get_base_type (parent_type);
5903 return ada_check_typedef (parent_type);
5909 /* True iff field number FIELD_NUM of structure type TYPE contains the
5910 parent-type (inherited) fields of a derived type. Assumes TYPE is
5911 a structure type with at least FIELD_NUM+1 fields. */
5914 ada_is_parent_field (struct type *type, int field_num)
5916 const char *name = TYPE_FIELD_NAME (ada_check_typedef (type), field_num);
5918 return (name != NULL
5919 && (strncmp (name, "PARENT", 6) == 0
5920 || strncmp (name, "_parent", 7) == 0));
5923 /* True iff field number FIELD_NUM of structure type TYPE is a
5924 transparent wrapper field (which should be silently traversed when doing
5925 field selection and flattened when printing). Assumes TYPE is a
5926 structure type with at least FIELD_NUM+1 fields. Such fields are always
5930 ada_is_wrapper_field (struct type *type, int field_num)
5932 const char *name = TYPE_FIELD_NAME (type, field_num);
5934 return (name != NULL
5935 && (strncmp (name, "PARENT", 6) == 0
5936 || strcmp (name, "REP") == 0
5937 || strncmp (name, "_parent", 7) == 0
5938 || name[0] == 'S' || name[0] == 'R' || name[0] == 'O'));
5941 /* True iff field number FIELD_NUM of structure or union type TYPE
5942 is a variant wrapper. Assumes TYPE is a structure type with at least
5943 FIELD_NUM+1 fields. */
5946 ada_is_variant_part (struct type *type, int field_num)
5948 struct type *field_type = TYPE_FIELD_TYPE (type, field_num);
5950 return (TYPE_CODE (field_type) == TYPE_CODE_UNION
5951 || (is_dynamic_field (type, field_num)
5952 && (TYPE_CODE (TYPE_TARGET_TYPE (field_type))
5953 == TYPE_CODE_UNION)));
5956 /* Assuming that VAR_TYPE is a variant wrapper (type of the variant part)
5957 whose discriminants are contained in the record type OUTER_TYPE,
5958 returns the type of the controlling discriminant for the variant.
5959 May return NULL if the type could not be found. */
5962 ada_variant_discrim_type (struct type *var_type, struct type *outer_type)
5964 char *name = ada_variant_discrim_name (var_type);
5966 return ada_lookup_struct_elt_type (outer_type, name, 1, 1, NULL);
5969 /* Assuming that TYPE is the type of a variant wrapper, and FIELD_NUM is a
5970 valid field number within it, returns 1 iff field FIELD_NUM of TYPE
5971 represents a 'when others' clause; otherwise 0. */
5974 ada_is_others_clause (struct type *type, int field_num)
5976 const char *name = TYPE_FIELD_NAME (type, field_num);
5978 return (name != NULL && name[0] == 'O');
5981 /* Assuming that TYPE0 is the type of the variant part of a record,
5982 returns the name of the discriminant controlling the variant.
5983 The value is valid until the next call to ada_variant_discrim_name. */
5986 ada_variant_discrim_name (struct type *type0)
5988 static char *result = NULL;
5989 static size_t result_len = 0;
5992 const char *discrim_end;
5993 const char *discrim_start;
5995 if (TYPE_CODE (type0) == TYPE_CODE_PTR)
5996 type = TYPE_TARGET_TYPE (type0);
6000 name = ada_type_name (type);
6002 if (name == NULL || name[0] == '\000')
6005 for (discrim_end = name + strlen (name) - 6; discrim_end != name;
6008 if (strncmp (discrim_end, "___XVN", 6) == 0)
6011 if (discrim_end == name)
6014 for (discrim_start = discrim_end; discrim_start != name + 3;
6017 if (discrim_start == name + 1)
6019 if ((discrim_start > name + 3
6020 && strncmp (discrim_start - 3, "___", 3) == 0)
6021 || discrim_start[-1] == '.')
6025 GROW_VECT (result, result_len, discrim_end - discrim_start + 1);
6026 strncpy (result, discrim_start, discrim_end - discrim_start);
6027 result[discrim_end - discrim_start] = '\0';
6031 /* Scan STR for a subtype-encoded number, beginning at position K.
6032 Put the position of the character just past the number scanned in
6033 *NEW_K, if NEW_K!=NULL. Put the scanned number in *R, if R!=NULL.
6034 Return 1 if there was a valid number at the given position, and 0
6035 otherwise. A "subtype-encoded" number consists of the absolute value
6036 in decimal, followed by the letter 'm' to indicate a negative number.
6037 Assumes 0m does not occur. */
6040 ada_scan_number (const char str[], int k, LONGEST * R, int *new_k)
6044 if (!isdigit (str[k]))
6047 /* Do it the hard way so as not to make any assumption about
6048 the relationship of unsigned long (%lu scan format code) and
6051 while (isdigit (str[k]))
6053 RU = RU * 10 + (str[k] - '0');
6060 *R = (-(LONGEST) (RU - 1)) - 1;
6066 /* NOTE on the above: Technically, C does not say what the results of
6067 - (LONGEST) RU or (LONGEST) -RU are for RU == largest positive
6068 number representable as a LONGEST (although either would probably work
6069 in most implementations). When RU>0, the locution in the then branch
6070 above is always equivalent to the negative of RU. */
6077 /* Assuming that TYPE is a variant part wrapper type (a VARIANTS field),
6078 and FIELD_NUM is a valid field number within it, returns 1 iff VAL is
6079 in the range encoded by field FIELD_NUM of TYPE; otherwise 0. */
6082 ada_in_variant (LONGEST val, struct type *type, int field_num)
6084 const char *name = TYPE_FIELD_NAME (type, field_num);
6098 if (!ada_scan_number (name, p + 1, &W, &p))
6108 if (!ada_scan_number (name, p + 1, &L, &p)
6109 || name[p] != 'T' || !ada_scan_number (name, p + 1, &U, &p))
6111 if (val >= L && val <= U)
6123 /* FIXME: Lots of redundancy below. Try to consolidate. */
6125 /* Given a value ARG1 (offset by OFFSET bytes) of a struct or union type
6126 ARG_TYPE, extract and return the value of one of its (non-static)
6127 fields. FIELDNO says which field. Differs from value_primitive_field
6128 only in that it can handle packed values of arbitrary type. */
6130 static struct value *
6131 ada_value_primitive_field (struct value *arg1, int offset, int fieldno,
6132 struct type *arg_type)
6136 arg_type = ada_check_typedef (arg_type);
6137 type = TYPE_FIELD_TYPE (arg_type, fieldno);
6139 /* Handle packed fields. */
6141 if (TYPE_FIELD_BITSIZE (arg_type, fieldno) != 0)
6143 int bit_pos = TYPE_FIELD_BITPOS (arg_type, fieldno);
6144 int bit_size = TYPE_FIELD_BITSIZE (arg_type, fieldno);
6146 return ada_value_primitive_packed_val (arg1, value_contents (arg1),
6147 offset + bit_pos / 8,
6148 bit_pos % 8, bit_size, type);
6151 return value_primitive_field (arg1, offset, fieldno, arg_type);
6154 /* Find field with name NAME in object of type TYPE. If found,
6155 set the following for each argument that is non-null:
6156 - *FIELD_TYPE_P to the field's type;
6157 - *BYTE_OFFSET_P to OFFSET + the byte offset of the field within
6158 an object of that type;
6159 - *BIT_OFFSET_P to the bit offset modulo byte size of the field;
6160 - *BIT_SIZE_P to its size in bits if the field is packed, and
6162 If INDEX_P is non-null, increment *INDEX_P by the number of source-visible
6163 fields up to but not including the desired field, or by the total
6164 number of fields if not found. A NULL value of NAME never
6165 matches; the function just counts visible fields in this case.
6167 Returns 1 if found, 0 otherwise. */
6170 find_struct_field (char *name, struct type *type, int offset,
6171 struct type **field_type_p,
6172 int *byte_offset_p, int *bit_offset_p, int *bit_size_p,
6177 type = ada_check_typedef (type);
6179 if (field_type_p != NULL)
6180 *field_type_p = NULL;
6181 if (byte_offset_p != NULL)
6183 if (bit_offset_p != NULL)
6185 if (bit_size_p != NULL)
6188 for (i = 0; i < TYPE_NFIELDS (type); i += 1)
6190 int bit_pos = TYPE_FIELD_BITPOS (type, i);
6191 int fld_offset = offset + bit_pos / 8;
6192 char *t_field_name = TYPE_FIELD_NAME (type, i);
6194 if (t_field_name == NULL)
6197 else if (name != NULL && field_name_match (t_field_name, name))
6199 int bit_size = TYPE_FIELD_BITSIZE (type, i);
6201 if (field_type_p != NULL)
6202 *field_type_p = TYPE_FIELD_TYPE (type, i);
6203 if (byte_offset_p != NULL)
6204 *byte_offset_p = fld_offset;
6205 if (bit_offset_p != NULL)
6206 *bit_offset_p = bit_pos % 8;
6207 if (bit_size_p != NULL)
6208 *bit_size_p = bit_size;
6211 else if (ada_is_wrapper_field (type, i))
6213 if (find_struct_field (name, TYPE_FIELD_TYPE (type, i), fld_offset,
6214 field_type_p, byte_offset_p, bit_offset_p,
6215 bit_size_p, index_p))
6218 else if (ada_is_variant_part (type, i))
6220 /* PNH: Wait. Do we ever execute this section, or is ARG always of
6223 struct type *field_type
6224 = ada_check_typedef (TYPE_FIELD_TYPE (type, i));
6226 for (j = 0; j < TYPE_NFIELDS (field_type); j += 1)
6228 if (find_struct_field (name, TYPE_FIELD_TYPE (field_type, j),
6230 + TYPE_FIELD_BITPOS (field_type, j) / 8,
6231 field_type_p, byte_offset_p,
6232 bit_offset_p, bit_size_p, index_p))
6236 else if (index_p != NULL)
6242 /* Number of user-visible fields in record type TYPE. */
6245 num_visible_fields (struct type *type)
6250 find_struct_field (NULL, type, 0, NULL, NULL, NULL, NULL, &n);
6254 /* Look for a field NAME in ARG. Adjust the address of ARG by OFFSET bytes,
6255 and search in it assuming it has (class) type TYPE.
6256 If found, return value, else return NULL.
6258 Searches recursively through wrapper fields (e.g., '_parent'). */
6260 static struct value *
6261 ada_search_struct_field (char *name, struct value *arg, int offset,
6266 type = ada_check_typedef (type);
6267 for (i = 0; i < TYPE_NFIELDS (type); i += 1)
6269 char *t_field_name = TYPE_FIELD_NAME (type, i);
6271 if (t_field_name == NULL)
6274 else if (field_name_match (t_field_name, name))
6275 return ada_value_primitive_field (arg, offset, i, type);
6277 else if (ada_is_wrapper_field (type, i))
6279 struct value *v = /* Do not let indent join lines here. */
6280 ada_search_struct_field (name, arg,
6281 offset + TYPE_FIELD_BITPOS (type, i) / 8,
6282 TYPE_FIELD_TYPE (type, i));
6288 else if (ada_is_variant_part (type, i))
6290 /* PNH: Do we ever get here? See find_struct_field. */
6292 struct type *field_type = ada_check_typedef (TYPE_FIELD_TYPE (type,
6294 int var_offset = offset + TYPE_FIELD_BITPOS (type, i) / 8;
6296 for (j = 0; j < TYPE_NFIELDS (field_type); j += 1)
6298 struct value *v = ada_search_struct_field /* Force line
6301 var_offset + TYPE_FIELD_BITPOS (field_type, j) / 8,
6302 TYPE_FIELD_TYPE (field_type, j));
6312 static struct value *ada_index_struct_field_1 (int *, struct value *,
6313 int, struct type *);
6316 /* Return field #INDEX in ARG, where the index is that returned by
6317 * find_struct_field through its INDEX_P argument. Adjust the address
6318 * of ARG by OFFSET bytes, and search in it assuming it has (class) type TYPE.
6319 * If found, return value, else return NULL. */
6321 static struct value *
6322 ada_index_struct_field (int index, struct value *arg, int offset,
6325 return ada_index_struct_field_1 (&index, arg, offset, type);
6329 /* Auxiliary function for ada_index_struct_field. Like
6330 * ada_index_struct_field, but takes index from *INDEX_P and modifies
6333 static struct value *
6334 ada_index_struct_field_1 (int *index_p, struct value *arg, int offset,
6338 type = ada_check_typedef (type);
6340 for (i = 0; i < TYPE_NFIELDS (type); i += 1)
6342 if (TYPE_FIELD_NAME (type, i) == NULL)
6344 else if (ada_is_wrapper_field (type, i))
6346 struct value *v = /* Do not let indent join lines here. */
6347 ada_index_struct_field_1 (index_p, arg,
6348 offset + TYPE_FIELD_BITPOS (type, i) / 8,
6349 TYPE_FIELD_TYPE (type, i));
6355 else if (ada_is_variant_part (type, i))
6357 /* PNH: Do we ever get here? See ada_search_struct_field,
6358 find_struct_field. */
6359 error (_("Cannot assign this kind of variant record"));
6361 else if (*index_p == 0)
6362 return ada_value_primitive_field (arg, offset, i, type);
6369 /* Given ARG, a value of type (pointer or reference to a)*
6370 structure/union, extract the component named NAME from the ultimate
6371 target structure/union and return it as a value with its
6374 The routine searches for NAME among all members of the structure itself
6375 and (recursively) among all members of any wrapper members
6378 If NO_ERR, then simply return NULL in case of error, rather than
6382 ada_value_struct_elt (struct value *arg, char *name, int no_err)
6384 struct type *t, *t1;
6388 t1 = t = ada_check_typedef (value_type (arg));
6389 if (TYPE_CODE (t) == TYPE_CODE_REF)
6391 t1 = TYPE_TARGET_TYPE (t);
6394 t1 = ada_check_typedef (t1);
6395 if (TYPE_CODE (t1) == TYPE_CODE_PTR)
6397 arg = coerce_ref (arg);
6402 while (TYPE_CODE (t) == TYPE_CODE_PTR)
6404 t1 = TYPE_TARGET_TYPE (t);
6407 t1 = ada_check_typedef (t1);
6408 if (TYPE_CODE (t1) == TYPE_CODE_PTR)
6410 arg = value_ind (arg);
6417 if (TYPE_CODE (t1) != TYPE_CODE_STRUCT && TYPE_CODE (t1) != TYPE_CODE_UNION)
6421 v = ada_search_struct_field (name, arg, 0, t);
6424 int bit_offset, bit_size, byte_offset;
6425 struct type *field_type;
6428 if (TYPE_CODE (t) == TYPE_CODE_PTR)
6429 address = value_as_address (arg);
6431 address = unpack_pointer (t, value_contents (arg));
6433 t1 = ada_to_fixed_type (ada_get_base_type (t1), NULL, address, NULL, 1);
6434 if (find_struct_field (name, t1, 0,
6435 &field_type, &byte_offset, &bit_offset,
6440 if (TYPE_CODE (t) == TYPE_CODE_REF)
6441 arg = ada_coerce_ref (arg);
6443 arg = ada_value_ind (arg);
6444 v = ada_value_primitive_packed_val (arg, NULL, byte_offset,
6445 bit_offset, bit_size,
6449 v = value_at_lazy (field_type, address + byte_offset);
6453 if (v != NULL || no_err)
6456 error (_("There is no member named %s."), name);
6462 error (_("Attempt to extract a component of "
6463 "a value that is not a record."));
6466 /* Given a type TYPE, look up the type of the component of type named NAME.
6467 If DISPP is non-null, add its byte displacement from the beginning of a
6468 structure (pointed to by a value) of type TYPE to *DISPP (does not
6469 work for packed fields).
6471 Matches any field whose name has NAME as a prefix, possibly
6474 TYPE can be either a struct or union. If REFOK, TYPE may also
6475 be a (pointer or reference)+ to a struct or union, and the
6476 ultimate target type will be searched.
6478 Looks recursively into variant clauses and parent types.
6480 If NOERR is nonzero, return NULL if NAME is not suitably defined or
6481 TYPE is not a type of the right kind. */
6483 static struct type *
6484 ada_lookup_struct_elt_type (struct type *type, char *name, int refok,
6485 int noerr, int *dispp)
6492 if (refok && type != NULL)
6495 type = ada_check_typedef (type);
6496 if (TYPE_CODE (type) != TYPE_CODE_PTR
6497 && TYPE_CODE (type) != TYPE_CODE_REF)
6499 type = TYPE_TARGET_TYPE (type);
6503 || (TYPE_CODE (type) != TYPE_CODE_STRUCT
6504 && TYPE_CODE (type) != TYPE_CODE_UNION))
6510 target_terminal_ours ();
6511 gdb_flush (gdb_stdout);
6513 error (_("Type (null) is not a structure or union type"));
6516 /* XXX: type_sprint */
6517 fprintf_unfiltered (gdb_stderr, _("Type "));
6518 type_print (type, "", gdb_stderr, -1);
6519 error (_(" is not a structure or union type"));
6524 type = to_static_fixed_type (type);
6526 for (i = 0; i < TYPE_NFIELDS (type); i += 1)
6528 char *t_field_name = TYPE_FIELD_NAME (type, i);
6532 if (t_field_name == NULL)
6535 else if (field_name_match (t_field_name, name))
6538 *dispp += TYPE_FIELD_BITPOS (type, i) / 8;
6539 return ada_check_typedef (TYPE_FIELD_TYPE (type, i));
6542 else if (ada_is_wrapper_field (type, i))
6545 t = ada_lookup_struct_elt_type (TYPE_FIELD_TYPE (type, i), name,
6550 *dispp += disp + TYPE_FIELD_BITPOS (type, i) / 8;
6555 else if (ada_is_variant_part (type, i))
6558 struct type *field_type = ada_check_typedef (TYPE_FIELD_TYPE (type,
6561 for (j = TYPE_NFIELDS (field_type) - 1; j >= 0; j -= 1)
6563 /* FIXME pnh 2008/01/26: We check for a field that is
6564 NOT wrapped in a struct, since the compiler sometimes
6565 generates these for unchecked variant types. Revisit
6566 if the compiler changes this practice. */
6567 char *v_field_name = TYPE_FIELD_NAME (field_type, j);
6569 if (v_field_name != NULL
6570 && field_name_match (v_field_name, name))
6571 t = ada_check_typedef (TYPE_FIELD_TYPE (field_type, j));
6573 t = ada_lookup_struct_elt_type (TYPE_FIELD_TYPE (field_type,
6580 *dispp += disp + TYPE_FIELD_BITPOS (type, i) / 8;
6591 target_terminal_ours ();
6592 gdb_flush (gdb_stdout);
6595 /* XXX: type_sprint */
6596 fprintf_unfiltered (gdb_stderr, _("Type "));
6597 type_print (type, "", gdb_stderr, -1);
6598 error (_(" has no component named <null>"));
6602 /* XXX: type_sprint */
6603 fprintf_unfiltered (gdb_stderr, _("Type "));
6604 type_print (type, "", gdb_stderr, -1);
6605 error (_(" has no component named %s"), name);
6612 /* Assuming that VAR_TYPE is the type of a variant part of a record (a union),
6613 within a value of type OUTER_TYPE, return true iff VAR_TYPE
6614 represents an unchecked union (that is, the variant part of a
6615 record that is named in an Unchecked_Union pragma). */
6618 is_unchecked_variant (struct type *var_type, struct type *outer_type)
6620 char *discrim_name = ada_variant_discrim_name (var_type);
6622 return (ada_lookup_struct_elt_type (outer_type, discrim_name, 0, 1, NULL)
6627 /* Assuming that VAR_TYPE is the type of a variant part of a record (a union),
6628 within a value of type OUTER_TYPE that is stored in GDB at
6629 OUTER_VALADDR, determine which variant clause (field number in VAR_TYPE,
6630 numbering from 0) is applicable. Returns -1 if none are. */
6633 ada_which_variant_applies (struct type *var_type, struct type *outer_type,
6634 const gdb_byte *outer_valaddr)
6638 char *discrim_name = ada_variant_discrim_name (var_type);
6639 struct value *outer;
6640 struct value *discrim;
6641 LONGEST discrim_val;
6643 outer = value_from_contents_and_address (outer_type, outer_valaddr, 0);
6644 discrim = ada_value_struct_elt (outer, discrim_name, 1);
6645 if (discrim == NULL)
6647 discrim_val = value_as_long (discrim);
6650 for (i = 0; i < TYPE_NFIELDS (var_type); i += 1)
6652 if (ada_is_others_clause (var_type, i))
6654 else if (ada_in_variant (discrim_val, var_type, i))
6658 return others_clause;
6663 /* Dynamic-Sized Records */
6665 /* Strategy: The type ostensibly attached to a value with dynamic size
6666 (i.e., a size that is not statically recorded in the debugging
6667 data) does not accurately reflect the size or layout of the value.
6668 Our strategy is to convert these values to values with accurate,
6669 conventional types that are constructed on the fly. */
6671 /* There is a subtle and tricky problem here. In general, we cannot
6672 determine the size of dynamic records without its data. However,
6673 the 'struct value' data structure, which GDB uses to represent
6674 quantities in the inferior process (the target), requires the size
6675 of the type at the time of its allocation in order to reserve space
6676 for GDB's internal copy of the data. That's why the
6677 'to_fixed_xxx_type' routines take (target) addresses as parameters,
6678 rather than struct value*s.
6680 However, GDB's internal history variables ($1, $2, etc.) are
6681 struct value*s containing internal copies of the data that are not, in
6682 general, the same as the data at their corresponding addresses in
6683 the target. Fortunately, the types we give to these values are all
6684 conventional, fixed-size types (as per the strategy described
6685 above), so that we don't usually have to perform the
6686 'to_fixed_xxx_type' conversions to look at their values.
6687 Unfortunately, there is one exception: if one of the internal
6688 history variables is an array whose elements are unconstrained
6689 records, then we will need to create distinct fixed types for each
6690 element selected. */
6692 /* The upshot of all of this is that many routines take a (type, host
6693 address, target address) triple as arguments to represent a value.
6694 The host address, if non-null, is supposed to contain an internal
6695 copy of the relevant data; otherwise, the program is to consult the
6696 target at the target address. */
6698 /* Assuming that VAL0 represents a pointer value, the result of
6699 dereferencing it. Differs from value_ind in its treatment of
6700 dynamic-sized types. */
6703 ada_value_ind (struct value *val0)
6705 struct value *val = unwrap_value (value_ind (val0));
6707 return ada_to_fixed_value (val);
6710 /* The value resulting from dereferencing any "reference to"
6711 qualifiers on VAL0. */
6713 static struct value *
6714 ada_coerce_ref (struct value *val0)
6716 if (TYPE_CODE (value_type (val0)) == TYPE_CODE_REF)
6718 struct value *val = val0;
6720 val = coerce_ref (val);
6721 val = unwrap_value (val);
6722 return ada_to_fixed_value (val);
6728 /* Return OFF rounded upward if necessary to a multiple of
6729 ALIGNMENT (a power of 2). */
6732 align_value (unsigned int off, unsigned int alignment)
6734 return (off + alignment - 1) & ~(alignment - 1);
6737 /* Return the bit alignment required for field #F of template type TYPE. */
6740 field_alignment (struct type *type, int f)
6742 const char *name = TYPE_FIELD_NAME (type, f);
6746 /* The field name should never be null, unless the debugging information
6747 is somehow malformed. In this case, we assume the field does not
6748 require any alignment. */
6752 len = strlen (name);
6754 if (!isdigit (name[len - 1]))
6757 if (isdigit (name[len - 2]))
6758 align_offset = len - 2;
6760 align_offset = len - 1;
6762 if (align_offset < 7 || strncmp ("___XV", name + align_offset - 6, 5) != 0)
6763 return TARGET_CHAR_BIT;
6765 return atoi (name + align_offset) * TARGET_CHAR_BIT;
6768 /* Find a symbol named NAME. Ignores ambiguity. */
6771 ada_find_any_symbol (const char *name)
6775 sym = standard_lookup (name, get_selected_block (NULL), VAR_DOMAIN);
6776 if (sym != NULL && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
6779 sym = standard_lookup (name, NULL, STRUCT_DOMAIN);
6783 /* Find a type named NAME. Ignores ambiguity. This routine will look
6784 solely for types defined by debug info, it will not search the GDB
6788 ada_find_any_type (const char *name)
6790 struct symbol *sym = ada_find_any_symbol (name);
6793 return SYMBOL_TYPE (sym);
6798 /* Given NAME and an associated BLOCK, search all symbols for
6799 NAME suffixed with "___XR", which is the ``renaming'' symbol
6800 associated to NAME. Return this symbol if found, return
6804 ada_find_renaming_symbol (const char *name, struct block *block)
6808 sym = find_old_style_renaming_symbol (name, block);
6813 /* Not right yet. FIXME pnh 7/20/2007. */
6814 sym = ada_find_any_symbol (name);
6815 if (sym != NULL && strstr (SYMBOL_LINKAGE_NAME (sym), "___XR") != NULL)
6821 static struct symbol *
6822 find_old_style_renaming_symbol (const char *name, struct block *block)
6824 const struct symbol *function_sym = block_linkage_function (block);
6827 if (function_sym != NULL)
6829 /* If the symbol is defined inside a function, NAME is not fully
6830 qualified. This means we need to prepend the function name
6831 as well as adding the ``___XR'' suffix to build the name of
6832 the associated renaming symbol. */
6833 char *function_name = SYMBOL_LINKAGE_NAME (function_sym);
6834 /* Function names sometimes contain suffixes used
6835 for instance to qualify nested subprograms. When building
6836 the XR type name, we need to make sure that this suffix is
6837 not included. So do not include any suffix in the function
6838 name length below. */
6839 int function_name_len = ada_name_prefix_len (function_name);
6840 const int rename_len = function_name_len + 2 /* "__" */
6841 + strlen (name) + 6 /* "___XR\0" */ ;
6843 /* Strip the suffix if necessary. */
6844 ada_remove_trailing_digits (function_name, &function_name_len);
6845 ada_remove_po_subprogram_suffix (function_name, &function_name_len);
6846 ada_remove_Xbn_suffix (function_name, &function_name_len);
6848 /* Library-level functions are a special case, as GNAT adds
6849 a ``_ada_'' prefix to the function name to avoid namespace
6850 pollution. However, the renaming symbols themselves do not
6851 have this prefix, so we need to skip this prefix if present. */
6852 if (function_name_len > 5 /* "_ada_" */
6853 && strstr (function_name, "_ada_") == function_name)
6856 function_name_len -= 5;
6859 rename = (char *) alloca (rename_len * sizeof (char));
6860 strncpy (rename, function_name, function_name_len);
6861 xsnprintf (rename + function_name_len, rename_len - function_name_len,
6866 const int rename_len = strlen (name) + 6;
6868 rename = (char *) alloca (rename_len * sizeof (char));
6869 xsnprintf (rename, rename_len * sizeof (char), "%s___XR", name);
6872 return ada_find_any_symbol (rename);
6875 /* Because of GNAT encoding conventions, several GDB symbols may match a
6876 given type name. If the type denoted by TYPE0 is to be preferred to
6877 that of TYPE1 for purposes of type printing, return non-zero;
6878 otherwise return 0. */
6881 ada_prefer_type (struct type *type0, struct type *type1)
6885 else if (type0 == NULL)
6887 else if (TYPE_CODE (type1) == TYPE_CODE_VOID)
6889 else if (TYPE_CODE (type0) == TYPE_CODE_VOID)
6891 else if (TYPE_NAME (type1) == NULL && TYPE_NAME (type0) != NULL)
6893 else if (ada_is_constrained_packed_array_type (type0))
6895 else if (ada_is_array_descriptor_type (type0)
6896 && !ada_is_array_descriptor_type (type1))
6900 const char *type0_name = type_name_no_tag (type0);
6901 const char *type1_name = type_name_no_tag (type1);
6903 if (type0_name != NULL && strstr (type0_name, "___XR") != NULL
6904 && (type1_name == NULL || strstr (type1_name, "___XR") == NULL))
6910 /* The name of TYPE, which is either its TYPE_NAME, or, if that is
6911 null, its TYPE_TAG_NAME. Null if TYPE is null. */
6914 ada_type_name (struct type *type)
6918 else if (TYPE_NAME (type) != NULL)
6919 return TYPE_NAME (type);
6921 return TYPE_TAG_NAME (type);
6924 /* Search the list of "descriptive" types associated to TYPE for a type
6925 whose name is NAME. */
6927 static struct type *
6928 find_parallel_type_by_descriptive_type (struct type *type, const char *name)
6930 struct type *result;
6932 /* If there no descriptive-type info, then there is no parallel type
6934 if (!HAVE_GNAT_AUX_INFO (type))
6937 result = TYPE_DESCRIPTIVE_TYPE (type);
6938 while (result != NULL)
6940 char *result_name = ada_type_name (result);
6942 if (result_name == NULL)
6944 warning (_("unexpected null name on descriptive type"));
6948 /* If the names match, stop. */
6949 if (strcmp (result_name, name) == 0)
6952 /* Otherwise, look at the next item on the list, if any. */
6953 if (HAVE_GNAT_AUX_INFO (result))
6954 result = TYPE_DESCRIPTIVE_TYPE (result);
6959 /* If we didn't find a match, see whether this is a packed array. With
6960 older compilers, the descriptive type information is either absent or
6961 irrelevant when it comes to packed arrays so the above lookup fails.
6962 Fall back to using a parallel lookup by name in this case. */
6963 if (result == NULL && ada_is_constrained_packed_array_type (type))
6964 return ada_find_any_type (name);
6969 /* Find a parallel type to TYPE with the specified NAME, using the
6970 descriptive type taken from the debugging information, if available,
6971 and otherwise using the (slower) name-based method. */
6973 static struct type *
6974 ada_find_parallel_type_with_name (struct type *type, const char *name)
6976 struct type *result = NULL;
6978 if (HAVE_GNAT_AUX_INFO (type))
6979 result = find_parallel_type_by_descriptive_type (type, name);
6981 result = ada_find_any_type (name);
6986 /* Same as above, but specify the name of the parallel type by appending
6987 SUFFIX to the name of TYPE. */
6990 ada_find_parallel_type (struct type *type, const char *suffix)
6992 char *name, *typename = ada_type_name (type);
6995 if (typename == NULL)
6998 len = strlen (typename);
7000 name = (char *) alloca (len + strlen (suffix) + 1);
7002 strcpy (name, typename);
7003 strcpy (name + len, suffix);
7005 return ada_find_parallel_type_with_name (type, name);
7008 /* If TYPE is a variable-size record type, return the corresponding template
7009 type describing its fields. Otherwise, return NULL. */
7011 static struct type *
7012 dynamic_template_type (struct type *type)
7014 type = ada_check_typedef (type);
7016 if (type == NULL || TYPE_CODE (type) != TYPE_CODE_STRUCT
7017 || ada_type_name (type) == NULL)
7021 int len = strlen (ada_type_name (type));
7023 if (len > 6 && strcmp (ada_type_name (type) + len - 6, "___XVE") == 0)
7026 return ada_find_parallel_type (type, "___XVE");
7030 /* Assuming that TEMPL_TYPE is a union or struct type, returns
7031 non-zero iff field FIELD_NUM of TEMPL_TYPE has dynamic size. */
7034 is_dynamic_field (struct type *templ_type, int field_num)
7036 const char *name = TYPE_FIELD_NAME (templ_type, field_num);
7039 && TYPE_CODE (TYPE_FIELD_TYPE (templ_type, field_num)) == TYPE_CODE_PTR
7040 && strstr (name, "___XVL") != NULL;
7043 /* The index of the variant field of TYPE, or -1 if TYPE does not
7044 represent a variant record type. */
7047 variant_field_index (struct type *type)
7051 if (type == NULL || TYPE_CODE (type) != TYPE_CODE_STRUCT)
7054 for (f = 0; f < TYPE_NFIELDS (type); f += 1)
7056 if (ada_is_variant_part (type, f))
7062 /* A record type with no fields. */
7064 static struct type *
7065 empty_record (struct type *template)
7067 struct type *type = alloc_type_copy (template);
7069 TYPE_CODE (type) = TYPE_CODE_STRUCT;
7070 TYPE_NFIELDS (type) = 0;
7071 TYPE_FIELDS (type) = NULL;
7072 INIT_CPLUS_SPECIFIC (type);
7073 TYPE_NAME (type) = "<empty>";
7074 TYPE_TAG_NAME (type) = NULL;
7075 TYPE_LENGTH (type) = 0;
7079 /* An ordinary record type (with fixed-length fields) that describes
7080 the value of type TYPE at VALADDR or ADDRESS (see comments at
7081 the beginning of this section) VAL according to GNAT conventions.
7082 DVAL0 should describe the (portion of a) record that contains any
7083 necessary discriminants. It should be NULL if value_type (VAL) is
7084 an outer-level type (i.e., as opposed to a branch of a variant.) A
7085 variant field (unless unchecked) is replaced by a particular branch
7088 If not KEEP_DYNAMIC_FIELDS, then all fields whose position or
7089 length are not statically known are discarded. As a consequence,
7090 VALADDR, ADDRESS and DVAL0 are ignored.
7092 NOTE: Limitations: For now, we assume that dynamic fields and
7093 variants occupy whole numbers of bytes. However, they need not be
7097 ada_template_to_fixed_record_type_1 (struct type *type,
7098 const gdb_byte *valaddr,
7099 CORE_ADDR address, struct value *dval0,
7100 int keep_dynamic_fields)
7102 struct value *mark = value_mark ();
7105 int nfields, bit_len;
7111 /* Compute the number of fields in this record type that are going
7112 to be processed: unless keep_dynamic_fields, this includes only
7113 fields whose position and length are static will be processed. */
7114 if (keep_dynamic_fields)
7115 nfields = TYPE_NFIELDS (type);
7119 while (nfields < TYPE_NFIELDS (type)
7120 && !ada_is_variant_part (type, nfields)
7121 && !is_dynamic_field (type, nfields))
7125 rtype = alloc_type_copy (type);
7126 TYPE_CODE (rtype) = TYPE_CODE_STRUCT;
7127 INIT_CPLUS_SPECIFIC (rtype);
7128 TYPE_NFIELDS (rtype) = nfields;
7129 TYPE_FIELDS (rtype) = (struct field *)
7130 TYPE_ALLOC (rtype, nfields * sizeof (struct field));
7131 memset (TYPE_FIELDS (rtype), 0, sizeof (struct field) * nfields);
7132 TYPE_NAME (rtype) = ada_type_name (type);
7133 TYPE_TAG_NAME (rtype) = NULL;
7134 TYPE_FIXED_INSTANCE (rtype) = 1;
7140 for (f = 0; f < nfields; f += 1)
7142 off = align_value (off, field_alignment (type, f))
7143 + TYPE_FIELD_BITPOS (type, f);
7144 TYPE_FIELD_BITPOS (rtype, f) = off;
7145 TYPE_FIELD_BITSIZE (rtype, f) = 0;
7147 if (ada_is_variant_part (type, f))
7152 else if (is_dynamic_field (type, f))
7154 const gdb_byte *field_valaddr = valaddr;
7155 CORE_ADDR field_address = address;
7156 struct type *field_type =
7157 TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, f));
7161 /* rtype's length is computed based on the run-time
7162 value of discriminants. If the discriminants are not
7163 initialized, the type size may be completely bogus and
7164 GDB may fail to allocate a value for it. So check the
7165 size first before creating the value. */
7167 dval = value_from_contents_and_address (rtype, valaddr, address);
7172 /* If the type referenced by this field is an aligner type, we need
7173 to unwrap that aligner type, because its size might not be set.
7174 Keeping the aligner type would cause us to compute the wrong
7175 size for this field, impacting the offset of the all the fields
7176 that follow this one. */
7177 if (ada_is_aligner_type (field_type))
7179 long field_offset = TYPE_FIELD_BITPOS (field_type, f);
7181 field_valaddr = cond_offset_host (field_valaddr, field_offset);
7182 field_address = cond_offset_target (field_address, field_offset);
7183 field_type = ada_aligned_type (field_type);
7186 field_valaddr = cond_offset_host (field_valaddr,
7187 off / TARGET_CHAR_BIT);
7188 field_address = cond_offset_target (field_address,
7189 off / TARGET_CHAR_BIT);
7191 /* Get the fixed type of the field. Note that, in this case,
7192 we do not want to get the real type out of the tag: if
7193 the current field is the parent part of a tagged record,
7194 we will get the tag of the object. Clearly wrong: the real
7195 type of the parent is not the real type of the child. We
7196 would end up in an infinite loop. */
7197 field_type = ada_get_base_type (field_type);
7198 field_type = ada_to_fixed_type (field_type, field_valaddr,
7199 field_address, dval, 0);
7200 /* If the field size is already larger than the maximum
7201 object size, then the record itself will necessarily
7202 be larger than the maximum object size. We need to make
7203 this check now, because the size might be so ridiculously
7204 large (due to an uninitialized variable in the inferior)
7205 that it would cause an overflow when adding it to the
7207 check_size (field_type);
7209 TYPE_FIELD_TYPE (rtype, f) = field_type;
7210 TYPE_FIELD_NAME (rtype, f) = TYPE_FIELD_NAME (type, f);
7211 /* The multiplication can potentially overflow. But because
7212 the field length has been size-checked just above, and
7213 assuming that the maximum size is a reasonable value,
7214 an overflow should not happen in practice. So rather than
7215 adding overflow recovery code to this already complex code,
7216 we just assume that it's not going to happen. */
7218 TYPE_LENGTH (TYPE_FIELD_TYPE (rtype, f)) * TARGET_CHAR_BIT;
7222 struct type *field_type = TYPE_FIELD_TYPE (type, f);
7224 /* If our field is a typedef type (most likely a typedef of
7225 a fat pointer, encoding an array access), then we need to
7226 look at its target type to determine its characteristics.
7227 In particular, we would miscompute the field size if we took
7228 the size of the typedef (zero), instead of the size of
7230 if (TYPE_CODE (field_type) == TYPE_CODE_TYPEDEF)
7231 field_type = ada_typedef_target_type (field_type);
7233 TYPE_FIELD_TYPE (rtype, f) = field_type;
7234 TYPE_FIELD_NAME (rtype, f) = TYPE_FIELD_NAME (type, f);
7235 if (TYPE_FIELD_BITSIZE (type, f) > 0)
7237 TYPE_FIELD_BITSIZE (rtype, f) = TYPE_FIELD_BITSIZE (type, f);
7240 TYPE_LENGTH (ada_check_typedef (field_type)) * TARGET_CHAR_BIT;
7242 if (off + fld_bit_len > bit_len)
7243 bit_len = off + fld_bit_len;
7245 TYPE_LENGTH (rtype) =
7246 align_value (bit_len, TARGET_CHAR_BIT) / TARGET_CHAR_BIT;
7249 /* We handle the variant part, if any, at the end because of certain
7250 odd cases in which it is re-ordered so as NOT to be the last field of
7251 the record. This can happen in the presence of representation
7253 if (variant_field >= 0)
7255 struct type *branch_type;
7257 off = TYPE_FIELD_BITPOS (rtype, variant_field);
7260 dval = value_from_contents_and_address (rtype, valaddr, address);
7265 to_fixed_variant_branch_type
7266 (TYPE_FIELD_TYPE (type, variant_field),
7267 cond_offset_host (valaddr, off / TARGET_CHAR_BIT),
7268 cond_offset_target (address, off / TARGET_CHAR_BIT), dval);
7269 if (branch_type == NULL)
7271 for (f = variant_field + 1; f < TYPE_NFIELDS (rtype); f += 1)
7272 TYPE_FIELDS (rtype)[f - 1] = TYPE_FIELDS (rtype)[f];
7273 TYPE_NFIELDS (rtype) -= 1;
7277 TYPE_FIELD_TYPE (rtype, variant_field) = branch_type;
7278 TYPE_FIELD_NAME (rtype, variant_field) = "S";
7280 TYPE_LENGTH (TYPE_FIELD_TYPE (rtype, variant_field)) *
7282 if (off + fld_bit_len > bit_len)
7283 bit_len = off + fld_bit_len;
7284 TYPE_LENGTH (rtype) =
7285 align_value (bit_len, TARGET_CHAR_BIT) / TARGET_CHAR_BIT;
7289 /* According to exp_dbug.ads, the size of TYPE for variable-size records
7290 should contain the alignment of that record, which should be a strictly
7291 positive value. If null or negative, then something is wrong, most
7292 probably in the debug info. In that case, we don't round up the size
7293 of the resulting type. If this record is not part of another structure,
7294 the current RTYPE length might be good enough for our purposes. */
7295 if (TYPE_LENGTH (type) <= 0)
7297 if (TYPE_NAME (rtype))
7298 warning (_("Invalid type size for `%s' detected: %d."),
7299 TYPE_NAME (rtype), TYPE_LENGTH (type));
7301 warning (_("Invalid type size for <unnamed> detected: %d."),
7302 TYPE_LENGTH (type));
7306 TYPE_LENGTH (rtype) = align_value (TYPE_LENGTH (rtype),
7307 TYPE_LENGTH (type));
7310 value_free_to_mark (mark);
7311 if (TYPE_LENGTH (rtype) > varsize_limit)
7312 error (_("record type with dynamic size is larger than varsize-limit"));
7316 /* As for ada_template_to_fixed_record_type_1 with KEEP_DYNAMIC_FIELDS
7319 static struct type *
7320 template_to_fixed_record_type (struct type *type, const gdb_byte *valaddr,
7321 CORE_ADDR address, struct value *dval0)
7323 return ada_template_to_fixed_record_type_1 (type, valaddr,
7327 /* An ordinary record type in which ___XVL-convention fields and
7328 ___XVU- and ___XVN-convention field types in TYPE0 are replaced with
7329 static approximations, containing all possible fields. Uses
7330 no runtime values. Useless for use in values, but that's OK,
7331 since the results are used only for type determinations. Works on both
7332 structs and unions. Representation note: to save space, we memorize
7333 the result of this function in the TYPE_TARGET_TYPE of the
7336 static struct type *
7337 template_to_static_fixed_type (struct type *type0)
7343 if (TYPE_TARGET_TYPE (type0) != NULL)
7344 return TYPE_TARGET_TYPE (type0);
7346 nfields = TYPE_NFIELDS (type0);
7349 for (f = 0; f < nfields; f += 1)
7351 struct type *field_type = ada_check_typedef (TYPE_FIELD_TYPE (type0, f));
7352 struct type *new_type;
7354 if (is_dynamic_field (type0, f))
7355 new_type = to_static_fixed_type (TYPE_TARGET_TYPE (field_type));
7357 new_type = static_unwrap_type (field_type);
7358 if (type == type0 && new_type != field_type)
7360 TYPE_TARGET_TYPE (type0) = type = alloc_type_copy (type0);
7361 TYPE_CODE (type) = TYPE_CODE (type0);
7362 INIT_CPLUS_SPECIFIC (type);
7363 TYPE_NFIELDS (type) = nfields;
7364 TYPE_FIELDS (type) = (struct field *)
7365 TYPE_ALLOC (type, nfields * sizeof (struct field));
7366 memcpy (TYPE_FIELDS (type), TYPE_FIELDS (type0),
7367 sizeof (struct field) * nfields);
7368 TYPE_NAME (type) = ada_type_name (type0);
7369 TYPE_TAG_NAME (type) = NULL;
7370 TYPE_FIXED_INSTANCE (type) = 1;
7371 TYPE_LENGTH (type) = 0;
7373 TYPE_FIELD_TYPE (type, f) = new_type;
7374 TYPE_FIELD_NAME (type, f) = TYPE_FIELD_NAME (type0, f);
7379 /* Given an object of type TYPE whose contents are at VALADDR and
7380 whose address in memory is ADDRESS, returns a revision of TYPE,
7381 which should be a non-dynamic-sized record, in which the variant
7382 part, if any, is replaced with the appropriate branch. Looks
7383 for discriminant values in DVAL0, which can be NULL if the record
7384 contains the necessary discriminant values. */
7386 static struct type *
7387 to_record_with_fixed_variant_part (struct type *type, const gdb_byte *valaddr,
7388 CORE_ADDR address, struct value *dval0)
7390 struct value *mark = value_mark ();
7393 struct type *branch_type;
7394 int nfields = TYPE_NFIELDS (type);
7395 int variant_field = variant_field_index (type);
7397 if (variant_field == -1)
7401 dval = value_from_contents_and_address (type, valaddr, address);
7405 rtype = alloc_type_copy (type);
7406 TYPE_CODE (rtype) = TYPE_CODE_STRUCT;
7407 INIT_CPLUS_SPECIFIC (rtype);
7408 TYPE_NFIELDS (rtype) = nfields;
7409 TYPE_FIELDS (rtype) =
7410 (struct field *) TYPE_ALLOC (rtype, nfields * sizeof (struct field));
7411 memcpy (TYPE_FIELDS (rtype), TYPE_FIELDS (type),
7412 sizeof (struct field) * nfields);
7413 TYPE_NAME (rtype) = ada_type_name (type);
7414 TYPE_TAG_NAME (rtype) = NULL;
7415 TYPE_FIXED_INSTANCE (rtype) = 1;
7416 TYPE_LENGTH (rtype) = TYPE_LENGTH (type);
7418 branch_type = to_fixed_variant_branch_type
7419 (TYPE_FIELD_TYPE (type, variant_field),
7420 cond_offset_host (valaddr,
7421 TYPE_FIELD_BITPOS (type, variant_field)
7423 cond_offset_target (address,
7424 TYPE_FIELD_BITPOS (type, variant_field)
7425 / TARGET_CHAR_BIT), dval);
7426 if (branch_type == NULL)
7430 for (f = variant_field + 1; f < nfields; f += 1)
7431 TYPE_FIELDS (rtype)[f - 1] = TYPE_FIELDS (rtype)[f];
7432 TYPE_NFIELDS (rtype) -= 1;
7436 TYPE_FIELD_TYPE (rtype, variant_field) = branch_type;
7437 TYPE_FIELD_NAME (rtype, variant_field) = "S";
7438 TYPE_FIELD_BITSIZE (rtype, variant_field) = 0;
7439 TYPE_LENGTH (rtype) += TYPE_LENGTH (branch_type);
7441 TYPE_LENGTH (rtype) -= TYPE_LENGTH (TYPE_FIELD_TYPE (type, variant_field));
7443 value_free_to_mark (mark);
7447 /* An ordinary record type (with fixed-length fields) that describes
7448 the value at (TYPE0, VALADDR, ADDRESS) [see explanation at
7449 beginning of this section]. Any necessary discriminants' values
7450 should be in DVAL, a record value; it may be NULL if the object
7451 at ADDR itself contains any necessary discriminant values.
7452 Additionally, VALADDR and ADDRESS may also be NULL if no discriminant
7453 values from the record are needed. Except in the case that DVAL,
7454 VALADDR, and ADDRESS are all 0 or NULL, a variant field (unless
7455 unchecked) is replaced by a particular branch of the variant.
7457 NOTE: the case in which DVAL and VALADDR are NULL and ADDRESS is 0
7458 is questionable and may be removed. It can arise during the
7459 processing of an unconstrained-array-of-record type where all the
7460 variant branches have exactly the same size. This is because in
7461 such cases, the compiler does not bother to use the XVS convention
7462 when encoding the record. I am currently dubious of this
7463 shortcut and suspect the compiler should be altered. FIXME. */
7465 static struct type *
7466 to_fixed_record_type (struct type *type0, const gdb_byte *valaddr,
7467 CORE_ADDR address, struct value *dval)
7469 struct type *templ_type;
7471 if (TYPE_FIXED_INSTANCE (type0))
7474 templ_type = dynamic_template_type (type0);
7476 if (templ_type != NULL)
7477 return template_to_fixed_record_type (templ_type, valaddr, address, dval);
7478 else if (variant_field_index (type0) >= 0)
7480 if (dval == NULL && valaddr == NULL && address == 0)
7482 return to_record_with_fixed_variant_part (type0, valaddr, address,
7487 TYPE_FIXED_INSTANCE (type0) = 1;
7493 /* An ordinary record type (with fixed-length fields) that describes
7494 the value at (VAR_TYPE0, VALADDR, ADDRESS), where VAR_TYPE0 is a
7495 union type. Any necessary discriminants' values should be in DVAL,
7496 a record value. That is, this routine selects the appropriate
7497 branch of the union at ADDR according to the discriminant value
7498 indicated in the union's type name. Returns VAR_TYPE0 itself if
7499 it represents a variant subject to a pragma Unchecked_Union. */
7501 static struct type *
7502 to_fixed_variant_branch_type (struct type *var_type0, const gdb_byte *valaddr,
7503 CORE_ADDR address, struct value *dval)
7506 struct type *templ_type;
7507 struct type *var_type;
7509 if (TYPE_CODE (var_type0) == TYPE_CODE_PTR)
7510 var_type = TYPE_TARGET_TYPE (var_type0);
7512 var_type = var_type0;
7514 templ_type = ada_find_parallel_type (var_type, "___XVU");
7516 if (templ_type != NULL)
7517 var_type = templ_type;
7519 if (is_unchecked_variant (var_type, value_type (dval)))
7522 ada_which_variant_applies (var_type,
7523 value_type (dval), value_contents (dval));
7526 return empty_record (var_type);
7527 else if (is_dynamic_field (var_type, which))
7528 return to_fixed_record_type
7529 (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (var_type, which)),
7530 valaddr, address, dval);
7531 else if (variant_field_index (TYPE_FIELD_TYPE (var_type, which)) >= 0)
7533 to_fixed_record_type
7534 (TYPE_FIELD_TYPE (var_type, which), valaddr, address, dval);
7536 return TYPE_FIELD_TYPE (var_type, which);
7539 /* Assuming that TYPE0 is an array type describing the type of a value
7540 at ADDR, and that DVAL describes a record containing any
7541 discriminants used in TYPE0, returns a type for the value that
7542 contains no dynamic components (that is, no components whose sizes
7543 are determined by run-time quantities). Unless IGNORE_TOO_BIG is
7544 true, gives an error message if the resulting type's size is over
7547 static struct type *
7548 to_fixed_array_type (struct type *type0, struct value *dval,
7551 struct type *index_type_desc;
7552 struct type *result;
7553 int constrained_packed_array_p;
7555 if (TYPE_FIXED_INSTANCE (type0))
7558 constrained_packed_array_p = ada_is_constrained_packed_array_type (type0);
7559 if (constrained_packed_array_p)
7560 type0 = decode_constrained_packed_array_type (type0);
7562 index_type_desc = ada_find_parallel_type (type0, "___XA");
7563 ada_fixup_array_indexes_type (index_type_desc);
7564 if (index_type_desc == NULL)
7566 struct type *elt_type0 = ada_check_typedef (TYPE_TARGET_TYPE (type0));
7568 /* NOTE: elt_type---the fixed version of elt_type0---should never
7569 depend on the contents of the array in properly constructed
7571 /* Create a fixed version of the array element type.
7572 We're not providing the address of an element here,
7573 and thus the actual object value cannot be inspected to do
7574 the conversion. This should not be a problem, since arrays of
7575 unconstrained objects are not allowed. In particular, all
7576 the elements of an array of a tagged type should all be of
7577 the same type specified in the debugging info. No need to
7578 consult the object tag. */
7579 struct type *elt_type = ada_to_fixed_type (elt_type0, 0, 0, dval, 1);
7581 /* Make sure we always create a new array type when dealing with
7582 packed array types, since we're going to fix-up the array
7583 type length and element bitsize a little further down. */
7584 if (elt_type0 == elt_type && !constrained_packed_array_p)
7587 result = create_array_type (alloc_type_copy (type0),
7588 elt_type, TYPE_INDEX_TYPE (type0));
7593 struct type *elt_type0;
7596 for (i = TYPE_NFIELDS (index_type_desc); i > 0; i -= 1)
7597 elt_type0 = TYPE_TARGET_TYPE (elt_type0);
7599 /* NOTE: result---the fixed version of elt_type0---should never
7600 depend on the contents of the array in properly constructed
7602 /* Create a fixed version of the array element type.
7603 We're not providing the address of an element here,
7604 and thus the actual object value cannot be inspected to do
7605 the conversion. This should not be a problem, since arrays of
7606 unconstrained objects are not allowed. In particular, all
7607 the elements of an array of a tagged type should all be of
7608 the same type specified in the debugging info. No need to
7609 consult the object tag. */
7611 ada_to_fixed_type (ada_check_typedef (elt_type0), 0, 0, dval, 1);
7614 for (i = TYPE_NFIELDS (index_type_desc) - 1; i >= 0; i -= 1)
7616 struct type *range_type =
7617 to_fixed_range_type (TYPE_FIELD_TYPE (index_type_desc, i), dval);
7619 result = create_array_type (alloc_type_copy (elt_type0),
7620 result, range_type);
7621 elt_type0 = TYPE_TARGET_TYPE (elt_type0);
7623 if (!ignore_too_big && TYPE_LENGTH (result) > varsize_limit)
7624 error (_("array type with dynamic size is larger than varsize-limit"));
7627 if (constrained_packed_array_p)
7629 /* So far, the resulting type has been created as if the original
7630 type was a regular (non-packed) array type. As a result, the
7631 bitsize of the array elements needs to be set again, and the array
7632 length needs to be recomputed based on that bitsize. */
7633 int len = TYPE_LENGTH (result) / TYPE_LENGTH (TYPE_TARGET_TYPE (result));
7634 int elt_bitsize = TYPE_FIELD_BITSIZE (type0, 0);
7636 TYPE_FIELD_BITSIZE (result, 0) = TYPE_FIELD_BITSIZE (type0, 0);
7637 TYPE_LENGTH (result) = len * elt_bitsize / HOST_CHAR_BIT;
7638 if (TYPE_LENGTH (result) * HOST_CHAR_BIT < len * elt_bitsize)
7639 TYPE_LENGTH (result)++;
7642 TYPE_FIXED_INSTANCE (result) = 1;
7647 /* A standard type (containing no dynamically sized components)
7648 corresponding to TYPE for the value (TYPE, VALADDR, ADDRESS)
7649 DVAL describes a record containing any discriminants used in TYPE0,
7650 and may be NULL if there are none, or if the object of type TYPE at
7651 ADDRESS or in VALADDR contains these discriminants.
7653 If CHECK_TAG is not null, in the case of tagged types, this function
7654 attempts to locate the object's tag and use it to compute the actual
7655 type. However, when ADDRESS is null, we cannot use it to determine the
7656 location of the tag, and therefore compute the tagged type's actual type.
7657 So we return the tagged type without consulting the tag. */
7659 static struct type *
7660 ada_to_fixed_type_1 (struct type *type, const gdb_byte *valaddr,
7661 CORE_ADDR address, struct value *dval, int check_tag)
7663 type = ada_check_typedef (type);
7664 switch (TYPE_CODE (type))
7668 case TYPE_CODE_STRUCT:
7670 struct type *static_type = to_static_fixed_type (type);
7671 struct type *fixed_record_type =
7672 to_fixed_record_type (type, valaddr, address, NULL);
7674 /* If STATIC_TYPE is a tagged type and we know the object's address,
7675 then we can determine its tag, and compute the object's actual
7676 type from there. Note that we have to use the fixed record
7677 type (the parent part of the record may have dynamic fields
7678 and the way the location of _tag is expressed may depend on
7681 if (check_tag && address != 0 && ada_is_tagged_type (static_type, 0))
7683 struct type *real_type =
7684 type_from_tag (value_tag_from_contents_and_address
7689 if (real_type != NULL)
7690 return to_fixed_record_type (real_type, valaddr, address, NULL);
7693 /* Check to see if there is a parallel ___XVZ variable.
7694 If there is, then it provides the actual size of our type. */
7695 else if (ada_type_name (fixed_record_type) != NULL)
7697 char *name = ada_type_name (fixed_record_type);
7698 char *xvz_name = alloca (strlen (name) + 7 /* "___XVZ\0" */);
7702 xsnprintf (xvz_name, strlen (name) + 7, "%s___XVZ", name);
7703 size = get_int_var_value (xvz_name, &xvz_found);
7704 if (xvz_found && TYPE_LENGTH (fixed_record_type) != size)
7706 fixed_record_type = copy_type (fixed_record_type);
7707 TYPE_LENGTH (fixed_record_type) = size;
7709 /* The FIXED_RECORD_TYPE may have be a stub. We have
7710 observed this when the debugging info is STABS, and
7711 apparently it is something that is hard to fix.
7713 In practice, we don't need the actual type definition
7714 at all, because the presence of the XVZ variable allows us
7715 to assume that there must be a XVS type as well, which we
7716 should be able to use later, when we need the actual type
7719 In the meantime, pretend that the "fixed" type we are
7720 returning is NOT a stub, because this can cause trouble
7721 when using this type to create new types targeting it.
7722 Indeed, the associated creation routines often check
7723 whether the target type is a stub and will try to replace
7724 it, thus using a type with the wrong size. This, in turn,
7725 might cause the new type to have the wrong size too.
7726 Consider the case of an array, for instance, where the size
7727 of the array is computed from the number of elements in
7728 our array multiplied by the size of its element. */
7729 TYPE_STUB (fixed_record_type) = 0;
7732 return fixed_record_type;
7734 case TYPE_CODE_ARRAY:
7735 return to_fixed_array_type (type, dval, 1);
7736 case TYPE_CODE_UNION:
7740 return to_fixed_variant_branch_type (type, valaddr, address, dval);
7744 /* The same as ada_to_fixed_type_1, except that it preserves the type
7745 if it is a TYPE_CODE_TYPEDEF of a type that is already fixed.
7747 The typedef layer needs be preserved in order to differentiate between
7748 arrays and array pointers when both types are implemented using the same
7749 fat pointer. In the array pointer case, the pointer is encoded as
7750 a typedef of the pointer type. For instance, considering:
7752 type String_Access is access String;
7753 S1 : String_Access := null;
7755 To the debugger, S1 is defined as a typedef of type String. But
7756 to the user, it is a pointer. So if the user tries to print S1,
7757 we should not dereference the array, but print the array address
7760 If we didn't preserve the typedef layer, we would lose the fact that
7761 the type is to be presented as a pointer (needs de-reference before
7762 being printed). And we would also use the source-level type name. */
7765 ada_to_fixed_type (struct type *type, const gdb_byte *valaddr,
7766 CORE_ADDR address, struct value *dval, int check_tag)
7769 struct type *fixed_type =
7770 ada_to_fixed_type_1 (type, valaddr, address, dval, check_tag);
7772 /* If TYPE is a typedef and its target type is the same as the FIXED_TYPE,
7773 then preserve the typedef layer.
7775 Implementation note: We can only check the main-type portion of
7776 the TYPE and FIXED_TYPE, because eliminating the typedef layer
7777 from TYPE now returns a type that has the same instance flags
7778 as TYPE. For instance, if TYPE is a "typedef const", and its
7779 target type is a "struct", then the typedef elimination will return
7780 a "const" version of the target type. See check_typedef for more
7781 details about how the typedef layer elimination is done.
7783 brobecker/2010-11-19: It seems to me that the only case where it is
7784 useful to preserve the typedef layer is when dealing with fat pointers.
7785 Perhaps, we could add a check for that and preserve the typedef layer
7786 only in that situation. But this seems unecessary so far, probably
7787 because we call check_typedef/ada_check_typedef pretty much everywhere.
7789 if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF
7790 && (TYPE_MAIN_TYPE (ada_typedef_target_type (type))
7791 == TYPE_MAIN_TYPE (fixed_type)))
7797 /* A standard (static-sized) type corresponding as well as possible to
7798 TYPE0, but based on no runtime data. */
7800 static struct type *
7801 to_static_fixed_type (struct type *type0)
7808 if (TYPE_FIXED_INSTANCE (type0))
7811 type0 = ada_check_typedef (type0);
7813 switch (TYPE_CODE (type0))
7817 case TYPE_CODE_STRUCT:
7818 type = dynamic_template_type (type0);
7820 return template_to_static_fixed_type (type);
7822 return template_to_static_fixed_type (type0);
7823 case TYPE_CODE_UNION:
7824 type = ada_find_parallel_type (type0, "___XVU");
7826 return template_to_static_fixed_type (type);
7828 return template_to_static_fixed_type (type0);
7832 /* A static approximation of TYPE with all type wrappers removed. */
7834 static struct type *
7835 static_unwrap_type (struct type *type)
7837 if (ada_is_aligner_type (type))
7839 struct type *type1 = TYPE_FIELD_TYPE (ada_check_typedef (type), 0);
7840 if (ada_type_name (type1) == NULL)
7841 TYPE_NAME (type1) = ada_type_name (type);
7843 return static_unwrap_type (type1);
7847 struct type *raw_real_type = ada_get_base_type (type);
7849 if (raw_real_type == type)
7852 return to_static_fixed_type (raw_real_type);
7856 /* In some cases, incomplete and private types require
7857 cross-references that are not resolved as records (for example,
7859 type FooP is access Foo;
7861 type Foo is array ...;
7862 ). In these cases, since there is no mechanism for producing
7863 cross-references to such types, we instead substitute for FooP a
7864 stub enumeration type that is nowhere resolved, and whose tag is
7865 the name of the actual type. Call these types "non-record stubs". */
7867 /* A type equivalent to TYPE that is not a non-record stub, if one
7868 exists, otherwise TYPE. */
7871 ada_check_typedef (struct type *type)
7876 /* If our type is a typedef type of a fat pointer, then we're done.
7877 We don't want to strip the TYPE_CODE_TYPDEF layer, because this is
7878 what allows us to distinguish between fat pointers that represent
7879 array types, and fat pointers that represent array access types
7880 (in both cases, the compiler implements them as fat pointers). */
7881 if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF
7882 && is_thick_pntr (ada_typedef_target_type (type)))
7885 CHECK_TYPEDEF (type);
7886 if (type == NULL || TYPE_CODE (type) != TYPE_CODE_ENUM
7887 || !TYPE_STUB (type)
7888 || TYPE_TAG_NAME (type) == NULL)
7892 char *name = TYPE_TAG_NAME (type);
7893 struct type *type1 = ada_find_any_type (name);
7898 /* TYPE1 might itself be a TYPE_CODE_TYPEDEF (this can happen with
7899 stubs pointing to arrays, as we don't create symbols for array
7900 types, only for the typedef-to-array types). If that's the case,
7901 strip the typedef layer. */
7902 if (TYPE_CODE (type1) == TYPE_CODE_TYPEDEF)
7903 type1 = ada_check_typedef (type1);
7909 /* A value representing the data at VALADDR/ADDRESS as described by
7910 type TYPE0, but with a standard (static-sized) type that correctly
7911 describes it. If VAL0 is not NULL and TYPE0 already is a standard
7912 type, then return VAL0 [this feature is simply to avoid redundant
7913 creation of struct values]. */
7915 static struct value *
7916 ada_to_fixed_value_create (struct type *type0, CORE_ADDR address,
7919 struct type *type = ada_to_fixed_type (type0, 0, address, NULL, 1);
7921 if (type == type0 && val0 != NULL)
7924 return value_from_contents_and_address (type, 0, address);
7927 /* A value representing VAL, but with a standard (static-sized) type
7928 that correctly describes it. Does not necessarily create a new
7932 ada_to_fixed_value (struct value *val)
7934 return ada_to_fixed_value_create (value_type (val),
7935 value_address (val),
7942 /* Table mapping attribute numbers to names.
7943 NOTE: Keep up to date with enum ada_attribute definition in ada-lang.h. */
7945 static const char *attribute_names[] = {
7963 ada_attribute_name (enum exp_opcode n)
7965 if (n >= OP_ATR_FIRST && n <= (int) OP_ATR_VAL)
7966 return attribute_names[n - OP_ATR_FIRST + 1];
7968 return attribute_names[0];
7971 /* Evaluate the 'POS attribute applied to ARG. */
7974 pos_atr (struct value *arg)
7976 struct value *val = coerce_ref (arg);
7977 struct type *type = value_type (val);
7979 if (!discrete_type_p (type))
7980 error (_("'POS only defined on discrete types"));
7982 if (TYPE_CODE (type) == TYPE_CODE_ENUM)
7985 LONGEST v = value_as_long (val);
7987 for (i = 0; i < TYPE_NFIELDS (type); i += 1)
7989 if (v == TYPE_FIELD_BITPOS (type, i))
7992 error (_("enumeration value is invalid: can't find 'POS"));
7995 return value_as_long (val);
7998 static struct value *
7999 value_pos_atr (struct type *type, struct value *arg)
8001 return value_from_longest (type, pos_atr (arg));
8004 /* Evaluate the TYPE'VAL attribute applied to ARG. */
8006 static struct value *
8007 value_val_atr (struct type *type, struct value *arg)
8009 if (!discrete_type_p (type))
8010 error (_("'VAL only defined on discrete types"));
8011 if (!integer_type_p (value_type (arg)))
8012 error (_("'VAL requires integral argument"));
8014 if (TYPE_CODE (type) == TYPE_CODE_ENUM)
8016 long pos = value_as_long (arg);
8018 if (pos < 0 || pos >= TYPE_NFIELDS (type))
8019 error (_("argument to 'VAL out of range"));
8020 return value_from_longest (type, TYPE_FIELD_BITPOS (type, pos));
8023 return value_from_longest (type, value_as_long (arg));
8029 /* True if TYPE appears to be an Ada character type.
8030 [At the moment, this is true only for Character and Wide_Character;
8031 It is a heuristic test that could stand improvement]. */
8034 ada_is_character_type (struct type *type)
8038 /* If the type code says it's a character, then assume it really is,
8039 and don't check any further. */
8040 if (TYPE_CODE (type) == TYPE_CODE_CHAR)
8043 /* Otherwise, assume it's a character type iff it is a discrete type
8044 with a known character type name. */
8045 name = ada_type_name (type);
8046 return (name != NULL
8047 && (TYPE_CODE (type) == TYPE_CODE_INT
8048 || TYPE_CODE (type) == TYPE_CODE_RANGE)
8049 && (strcmp (name, "character") == 0
8050 || strcmp (name, "wide_character") == 0
8051 || strcmp (name, "wide_wide_character") == 0
8052 || strcmp (name, "unsigned char") == 0));
8055 /* True if TYPE appears to be an Ada string type. */
8058 ada_is_string_type (struct type *type)
8060 type = ada_check_typedef (type);
8062 && TYPE_CODE (type) != TYPE_CODE_PTR
8063 && (ada_is_simple_array_type (type)
8064 || ada_is_array_descriptor_type (type))
8065 && ada_array_arity (type) == 1)
8067 struct type *elttype = ada_array_element_type (type, 1);
8069 return ada_is_character_type (elttype);
8075 /* The compiler sometimes provides a parallel XVS type for a given
8076 PAD type. Normally, it is safe to follow the PAD type directly,
8077 but older versions of the compiler have a bug that causes the offset
8078 of its "F" field to be wrong. Following that field in that case
8079 would lead to incorrect results, but this can be worked around
8080 by ignoring the PAD type and using the associated XVS type instead.
8082 Set to True if the debugger should trust the contents of PAD types.
8083 Otherwise, ignore the PAD type if there is a parallel XVS type. */
8084 static int trust_pad_over_xvs = 1;
8086 /* True if TYPE is a struct type introduced by the compiler to force the
8087 alignment of a value. Such types have a single field with a
8088 distinctive name. */
8091 ada_is_aligner_type (struct type *type)
8093 type = ada_check_typedef (type);
8095 if (!trust_pad_over_xvs && ada_find_parallel_type (type, "___XVS") != NULL)
8098 return (TYPE_CODE (type) == TYPE_CODE_STRUCT
8099 && TYPE_NFIELDS (type) == 1
8100 && strcmp (TYPE_FIELD_NAME (type, 0), "F") == 0);
8103 /* If there is an ___XVS-convention type parallel to SUBTYPE, return
8104 the parallel type. */
8107 ada_get_base_type (struct type *raw_type)
8109 struct type *real_type_namer;
8110 struct type *raw_real_type;
8112 if (raw_type == NULL || TYPE_CODE (raw_type) != TYPE_CODE_STRUCT)
8115 if (ada_is_aligner_type (raw_type))
8116 /* The encoding specifies that we should always use the aligner type.
8117 So, even if this aligner type has an associated XVS type, we should
8120 According to the compiler gurus, an XVS type parallel to an aligner
8121 type may exist because of a stabs limitation. In stabs, aligner
8122 types are empty because the field has a variable-sized type, and
8123 thus cannot actually be used as an aligner type. As a result,
8124 we need the associated parallel XVS type to decode the type.
8125 Since the policy in the compiler is to not change the internal
8126 representation based on the debugging info format, we sometimes
8127 end up having a redundant XVS type parallel to the aligner type. */
8130 real_type_namer = ada_find_parallel_type (raw_type, "___XVS");
8131 if (real_type_namer == NULL
8132 || TYPE_CODE (real_type_namer) != TYPE_CODE_STRUCT
8133 || TYPE_NFIELDS (real_type_namer) != 1)
8136 if (TYPE_CODE (TYPE_FIELD_TYPE (real_type_namer, 0)) != TYPE_CODE_REF)
8138 /* This is an older encoding form where the base type needs to be
8139 looked up by name. We prefer the newer enconding because it is
8141 raw_real_type = ada_find_any_type (TYPE_FIELD_NAME (real_type_namer, 0));
8142 if (raw_real_type == NULL)
8145 return raw_real_type;
8148 /* The field in our XVS type is a reference to the base type. */
8149 return TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (real_type_namer, 0));
8152 /* The type of value designated by TYPE, with all aligners removed. */
8155 ada_aligned_type (struct type *type)
8157 if (ada_is_aligner_type (type))
8158 return ada_aligned_type (TYPE_FIELD_TYPE (type, 0));
8160 return ada_get_base_type (type);
8164 /* The address of the aligned value in an object at address VALADDR
8165 having type TYPE. Assumes ada_is_aligner_type (TYPE). */
8168 ada_aligned_value_addr (struct type *type, const gdb_byte *valaddr)
8170 if (ada_is_aligner_type (type))
8171 return ada_aligned_value_addr (TYPE_FIELD_TYPE (type, 0),
8173 TYPE_FIELD_BITPOS (type,
8174 0) / TARGET_CHAR_BIT);
8181 /* The printed representation of an enumeration literal with encoded
8182 name NAME. The value is good to the next call of ada_enum_name. */
8184 ada_enum_name (const char *name)
8186 static char *result;
8187 static size_t result_len = 0;
8190 /* First, unqualify the enumeration name:
8191 1. Search for the last '.' character. If we find one, then skip
8192 all the preceeding characters, the unqualified name starts
8193 right after that dot.
8194 2. Otherwise, we may be debugging on a target where the compiler
8195 translates dots into "__". Search forward for double underscores,
8196 but stop searching when we hit an overloading suffix, which is
8197 of the form "__" followed by digits. */
8199 tmp = strrchr (name, '.');
8204 while ((tmp = strstr (name, "__")) != NULL)
8206 if (isdigit (tmp[2]))
8217 if (name[1] == 'U' || name[1] == 'W')
8219 if (sscanf (name + 2, "%x", &v) != 1)
8225 GROW_VECT (result, result_len, 16);
8226 if (isascii (v) && isprint (v))
8227 xsnprintf (result, result_len, "'%c'", v);
8228 else if (name[1] == 'U')
8229 xsnprintf (result, result_len, "[\"%02x\"]", v);
8231 xsnprintf (result, result_len, "[\"%04x\"]", v);
8237 tmp = strstr (name, "__");
8239 tmp = strstr (name, "$");
8242 GROW_VECT (result, result_len, tmp - name + 1);
8243 strncpy (result, name, tmp - name);
8244 result[tmp - name] = '\0';
8252 /* Evaluate the subexpression of EXP starting at *POS as for
8253 evaluate_type, updating *POS to point just past the evaluated
8256 static struct value *
8257 evaluate_subexp_type (struct expression *exp, int *pos)
8259 return evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
8262 /* If VAL is wrapped in an aligner or subtype wrapper, return the
8265 static struct value *
8266 unwrap_value (struct value *val)
8268 struct type *type = ada_check_typedef (value_type (val));
8270 if (ada_is_aligner_type (type))
8272 struct value *v = ada_value_struct_elt (val, "F", 0);
8273 struct type *val_type = ada_check_typedef (value_type (v));
8275 if (ada_type_name (val_type) == NULL)
8276 TYPE_NAME (val_type) = ada_type_name (type);
8278 return unwrap_value (v);
8282 struct type *raw_real_type =
8283 ada_check_typedef (ada_get_base_type (type));
8285 /* If there is no parallel XVS or XVE type, then the value is
8286 already unwrapped. Return it without further modification. */
8287 if ((type == raw_real_type)
8288 && ada_find_parallel_type (type, "___XVE") == NULL)
8292 coerce_unspec_val_to_type
8293 (val, ada_to_fixed_type (raw_real_type, 0,
8294 value_address (val),
8299 static struct value *
8300 cast_to_fixed (struct type *type, struct value *arg)
8304 if (type == value_type (arg))
8306 else if (ada_is_fixed_point_type (value_type (arg)))
8307 val = ada_float_to_fixed (type,
8308 ada_fixed_to_float (value_type (arg),
8309 value_as_long (arg)));
8312 DOUBLEST argd = value_as_double (arg);
8314 val = ada_float_to_fixed (type, argd);
8317 return value_from_longest (type, val);
8320 static struct value *
8321 cast_from_fixed (struct type *type, struct value *arg)
8323 DOUBLEST val = ada_fixed_to_float (value_type (arg),
8324 value_as_long (arg));
8326 return value_from_double (type, val);
8329 /* Coerce VAL as necessary for assignment to an lval of type TYPE, and
8330 return the converted value. */
8332 static struct value *
8333 coerce_for_assign (struct type *type, struct value *val)
8335 struct type *type2 = value_type (val);
8340 type2 = ada_check_typedef (type2);
8341 type = ada_check_typedef (type);
8343 if (TYPE_CODE (type2) == TYPE_CODE_PTR
8344 && TYPE_CODE (type) == TYPE_CODE_ARRAY)
8346 val = ada_value_ind (val);
8347 type2 = value_type (val);
8350 if (TYPE_CODE (type2) == TYPE_CODE_ARRAY
8351 && TYPE_CODE (type) == TYPE_CODE_ARRAY)
8353 if (TYPE_LENGTH (type2) != TYPE_LENGTH (type)
8354 || TYPE_LENGTH (TYPE_TARGET_TYPE (type2))
8355 != TYPE_LENGTH (TYPE_TARGET_TYPE (type2)))
8356 error (_("Incompatible types in assignment"));
8357 deprecated_set_value_type (val, type);
8362 static struct value *
8363 ada_value_binop (struct value *arg1, struct value *arg2, enum exp_opcode op)
8366 struct type *type1, *type2;
8369 arg1 = coerce_ref (arg1);
8370 arg2 = coerce_ref (arg2);
8371 type1 = base_type (ada_check_typedef (value_type (arg1)));
8372 type2 = base_type (ada_check_typedef (value_type (arg2)));
8374 if (TYPE_CODE (type1) != TYPE_CODE_INT
8375 || TYPE_CODE (type2) != TYPE_CODE_INT)
8376 return value_binop (arg1, arg2, op);
8385 return value_binop (arg1, arg2, op);
8388 v2 = value_as_long (arg2);
8390 error (_("second operand of %s must not be zero."), op_string (op));
8392 if (TYPE_UNSIGNED (type1) || op == BINOP_MOD)
8393 return value_binop (arg1, arg2, op);
8395 v1 = value_as_long (arg1);
8400 if (!TRUNCATION_TOWARDS_ZERO && v1 * (v1 % v2) < 0)
8401 v += v > 0 ? -1 : 1;
8409 /* Should not reach this point. */
8413 val = allocate_value (type1);
8414 store_unsigned_integer (value_contents_raw (val),
8415 TYPE_LENGTH (value_type (val)),
8416 gdbarch_byte_order (get_type_arch (type1)), v);
8421 ada_value_equal (struct value *arg1, struct value *arg2)
8423 if (ada_is_direct_array_type (value_type (arg1))
8424 || ada_is_direct_array_type (value_type (arg2)))
8426 /* Automatically dereference any array reference before
8427 we attempt to perform the comparison. */
8428 arg1 = ada_coerce_ref (arg1);
8429 arg2 = ada_coerce_ref (arg2);
8431 arg1 = ada_coerce_to_simple_array (arg1);
8432 arg2 = ada_coerce_to_simple_array (arg2);
8433 if (TYPE_CODE (value_type (arg1)) != TYPE_CODE_ARRAY
8434 || TYPE_CODE (value_type (arg2)) != TYPE_CODE_ARRAY)
8435 error (_("Attempt to compare array with non-array"));
8436 /* FIXME: The following works only for types whose
8437 representations use all bits (no padding or undefined bits)
8438 and do not have user-defined equality. */
8440 TYPE_LENGTH (value_type (arg1)) == TYPE_LENGTH (value_type (arg2))
8441 && memcmp (value_contents (arg1), value_contents (arg2),
8442 TYPE_LENGTH (value_type (arg1))) == 0;
8444 return value_equal (arg1, arg2);
8447 /* Total number of component associations in the aggregate starting at
8448 index PC in EXP. Assumes that index PC is the start of an
8452 num_component_specs (struct expression *exp, int pc)
8456 m = exp->elts[pc + 1].longconst;
8459 for (i = 0; i < m; i += 1)
8461 switch (exp->elts[pc].opcode)
8467 n += exp->elts[pc + 1].longconst;
8470 ada_evaluate_subexp (NULL, exp, &pc, EVAL_SKIP);
8475 /* Assign the result of evaluating EXP starting at *POS to the INDEXth
8476 component of LHS (a simple array or a record), updating *POS past
8477 the expression, assuming that LHS is contained in CONTAINER. Does
8478 not modify the inferior's memory, nor does it modify LHS (unless
8479 LHS == CONTAINER). */
8482 assign_component (struct value *container, struct value *lhs, LONGEST index,
8483 struct expression *exp, int *pos)
8485 struct value *mark = value_mark ();
8488 if (TYPE_CODE (value_type (lhs)) == TYPE_CODE_ARRAY)
8490 struct type *index_type = builtin_type (exp->gdbarch)->builtin_int;
8491 struct value *index_val = value_from_longest (index_type, index);
8493 elt = unwrap_value (ada_value_subscript (lhs, 1, &index_val));
8497 elt = ada_index_struct_field (index, lhs, 0, value_type (lhs));
8498 elt = ada_to_fixed_value (unwrap_value (elt));
8501 if (exp->elts[*pos].opcode == OP_AGGREGATE)
8502 assign_aggregate (container, elt, exp, pos, EVAL_NORMAL);
8504 value_assign_to_component (container, elt,
8505 ada_evaluate_subexp (NULL, exp, pos,
8508 value_free_to_mark (mark);
8511 /* Assuming that LHS represents an lvalue having a record or array
8512 type, and EXP->ELTS[*POS] is an OP_AGGREGATE, evaluate an assignment
8513 of that aggregate's value to LHS, advancing *POS past the
8514 aggregate. NOSIDE is as for evaluate_subexp. CONTAINER is an
8515 lvalue containing LHS (possibly LHS itself). Does not modify
8516 the inferior's memory, nor does it modify the contents of
8517 LHS (unless == CONTAINER). Returns the modified CONTAINER. */
8519 static struct value *
8520 assign_aggregate (struct value *container,
8521 struct value *lhs, struct expression *exp,
8522 int *pos, enum noside noside)
8524 struct type *lhs_type;
8525 int n = exp->elts[*pos+1].longconst;
8526 LONGEST low_index, high_index;
8529 int max_indices, num_indices;
8530 int is_array_aggregate;
8534 if (noside != EVAL_NORMAL)
8538 for (i = 0; i < n; i += 1)
8539 ada_evaluate_subexp (NULL, exp, pos, noside);
8543 container = ada_coerce_ref (container);
8544 if (ada_is_direct_array_type (value_type (container)))
8545 container = ada_coerce_to_simple_array (container);
8546 lhs = ada_coerce_ref (lhs);
8547 if (!deprecated_value_modifiable (lhs))
8548 error (_("Left operand of assignment is not a modifiable lvalue."));
8550 lhs_type = value_type (lhs);
8551 if (ada_is_direct_array_type (lhs_type))
8553 lhs = ada_coerce_to_simple_array (lhs);
8554 lhs_type = value_type (lhs);
8555 low_index = TYPE_ARRAY_LOWER_BOUND_VALUE (lhs_type);
8556 high_index = TYPE_ARRAY_UPPER_BOUND_VALUE (lhs_type);
8557 is_array_aggregate = 1;
8559 else if (TYPE_CODE (lhs_type) == TYPE_CODE_STRUCT)
8562 high_index = num_visible_fields (lhs_type) - 1;
8563 is_array_aggregate = 0;
8566 error (_("Left-hand side must be array or record."));
8568 num_specs = num_component_specs (exp, *pos - 3);
8569 max_indices = 4 * num_specs + 4;
8570 indices = alloca (max_indices * sizeof (indices[0]));
8571 indices[0] = indices[1] = low_index - 1;
8572 indices[2] = indices[3] = high_index + 1;
8575 for (i = 0; i < n; i += 1)
8577 switch (exp->elts[*pos].opcode)
8580 aggregate_assign_from_choices (container, lhs, exp, pos, indices,
8581 &num_indices, max_indices,
8582 low_index, high_index);
8585 aggregate_assign_positional (container, lhs, exp, pos, indices,
8586 &num_indices, max_indices,
8587 low_index, high_index);
8591 error (_("Misplaced 'others' clause"));
8592 aggregate_assign_others (container, lhs, exp, pos, indices,
8593 num_indices, low_index, high_index);
8596 error (_("Internal error: bad aggregate clause"));
8603 /* Assign into the component of LHS indexed by the OP_POSITIONAL
8604 construct at *POS, updating *POS past the construct, given that
8605 the positions are relative to lower bound LOW, where HIGH is the
8606 upper bound. Record the position in INDICES[0 .. MAX_INDICES-1]
8607 updating *NUM_INDICES as needed. CONTAINER is as for
8608 assign_aggregate. */
8610 aggregate_assign_positional (struct value *container,
8611 struct value *lhs, struct expression *exp,
8612 int *pos, LONGEST *indices, int *num_indices,
8613 int max_indices, LONGEST low, LONGEST high)
8615 LONGEST ind = longest_to_int (exp->elts[*pos + 1].longconst) + low;
8617 if (ind - 1 == high)
8618 warning (_("Extra components in aggregate ignored."));
8621 add_component_interval (ind, ind, indices, num_indices, max_indices);
8623 assign_component (container, lhs, ind, exp, pos);
8626 ada_evaluate_subexp (NULL, exp, pos, EVAL_SKIP);
8629 /* Assign into the components of LHS indexed by the OP_CHOICES
8630 construct at *POS, updating *POS past the construct, given that
8631 the allowable indices are LOW..HIGH. Record the indices assigned
8632 to in INDICES[0 .. MAX_INDICES-1], updating *NUM_INDICES as
8633 needed. CONTAINER is as for assign_aggregate. */
8635 aggregate_assign_from_choices (struct value *container,
8636 struct value *lhs, struct expression *exp,
8637 int *pos, LONGEST *indices, int *num_indices,
8638 int max_indices, LONGEST low, LONGEST high)
8641 int n_choices = longest_to_int (exp->elts[*pos+1].longconst);
8642 int choice_pos, expr_pc;
8643 int is_array = ada_is_direct_array_type (value_type (lhs));
8645 choice_pos = *pos += 3;
8647 for (j = 0; j < n_choices; j += 1)
8648 ada_evaluate_subexp (NULL, exp, pos, EVAL_SKIP);
8650 ada_evaluate_subexp (NULL, exp, pos, EVAL_SKIP);
8652 for (j = 0; j < n_choices; j += 1)
8654 LONGEST lower, upper;
8655 enum exp_opcode op = exp->elts[choice_pos].opcode;
8657 if (op == OP_DISCRETE_RANGE)
8660 lower = value_as_long (ada_evaluate_subexp (NULL, exp, pos,
8662 upper = value_as_long (ada_evaluate_subexp (NULL, exp, pos,
8667 lower = value_as_long (ada_evaluate_subexp (NULL, exp, &choice_pos,
8679 name = &exp->elts[choice_pos + 2].string;
8682 name = SYMBOL_NATURAL_NAME (exp->elts[choice_pos + 2].symbol);
8685 error (_("Invalid record component association."));
8687 ada_evaluate_subexp (NULL, exp, &choice_pos, EVAL_SKIP);
8689 if (! find_struct_field (name, value_type (lhs), 0,
8690 NULL, NULL, NULL, NULL, &ind))
8691 error (_("Unknown component name: %s."), name);
8692 lower = upper = ind;
8695 if (lower <= upper && (lower < low || upper > high))
8696 error (_("Index in component association out of bounds."));
8698 add_component_interval (lower, upper, indices, num_indices,
8700 while (lower <= upper)
8705 assign_component (container, lhs, lower, exp, &pos1);
8711 /* Assign the value of the expression in the OP_OTHERS construct in
8712 EXP at *POS into the components of LHS indexed from LOW .. HIGH that
8713 have not been previously assigned. The index intervals already assigned
8714 are in INDICES[0 .. NUM_INDICES-1]. Updates *POS to after the
8715 OP_OTHERS clause. CONTAINER is as for assign_aggregate. */
8717 aggregate_assign_others (struct value *container,
8718 struct value *lhs, struct expression *exp,
8719 int *pos, LONGEST *indices, int num_indices,
8720 LONGEST low, LONGEST high)
8723 int expr_pc = *pos + 1;
8725 for (i = 0; i < num_indices - 2; i += 2)
8729 for (ind = indices[i + 1] + 1; ind < indices[i + 2]; ind += 1)
8734 assign_component (container, lhs, ind, exp, &localpos);
8737 ada_evaluate_subexp (NULL, exp, pos, EVAL_SKIP);
8740 /* Add the interval [LOW .. HIGH] to the sorted set of intervals
8741 [ INDICES[0] .. INDICES[1] ],..., [ INDICES[*SIZE-2] .. INDICES[*SIZE-1] ],
8742 modifying *SIZE as needed. It is an error if *SIZE exceeds
8743 MAX_SIZE. The resulting intervals do not overlap. */
8745 add_component_interval (LONGEST low, LONGEST high,
8746 LONGEST* indices, int *size, int max_size)
8750 for (i = 0; i < *size; i += 2) {
8751 if (high >= indices[i] && low <= indices[i + 1])
8755 for (kh = i + 2; kh < *size; kh += 2)
8756 if (high < indices[kh])
8758 if (low < indices[i])
8760 indices[i + 1] = indices[kh - 1];
8761 if (high > indices[i + 1])
8762 indices[i + 1] = high;
8763 memcpy (indices + i + 2, indices + kh, *size - kh);
8764 *size -= kh - i - 2;
8767 else if (high < indices[i])
8771 if (*size == max_size)
8772 error (_("Internal error: miscounted aggregate components."));
8774 for (j = *size-1; j >= i+2; j -= 1)
8775 indices[j] = indices[j - 2];
8777 indices[i + 1] = high;
8780 /* Perform and Ada cast of ARG2 to type TYPE if the type of ARG2
8783 static struct value *
8784 ada_value_cast (struct type *type, struct value *arg2, enum noside noside)
8786 if (type == ada_check_typedef (value_type (arg2)))
8789 if (ada_is_fixed_point_type (type))
8790 return (cast_to_fixed (type, arg2));
8792 if (ada_is_fixed_point_type (value_type (arg2)))
8793 return cast_from_fixed (type, arg2);
8795 return value_cast (type, arg2);
8798 /* Evaluating Ada expressions, and printing their result.
8799 ------------------------------------------------------
8804 We usually evaluate an Ada expression in order to print its value.
8805 We also evaluate an expression in order to print its type, which
8806 happens during the EVAL_AVOID_SIDE_EFFECTS phase of the evaluation,
8807 but we'll focus mostly on the EVAL_NORMAL phase. In practice, the
8808 EVAL_AVOID_SIDE_EFFECTS phase allows us to simplify certain aspects of
8809 the evaluation compared to the EVAL_NORMAL, but is otherwise very
8812 Evaluating expressions is a little more complicated for Ada entities
8813 than it is for entities in languages such as C. The main reason for
8814 this is that Ada provides types whose definition might be dynamic.
8815 One example of such types is variant records. Or another example
8816 would be an array whose bounds can only be known at run time.
8818 The following description is a general guide as to what should be
8819 done (and what should NOT be done) in order to evaluate an expression
8820 involving such types, and when. This does not cover how the semantic
8821 information is encoded by GNAT as this is covered separatly. For the
8822 document used as the reference for the GNAT encoding, see exp_dbug.ads
8823 in the GNAT sources.
8825 Ideally, we should embed each part of this description next to its
8826 associated code. Unfortunately, the amount of code is so vast right
8827 now that it's hard to see whether the code handling a particular
8828 situation might be duplicated or not. One day, when the code is
8829 cleaned up, this guide might become redundant with the comments
8830 inserted in the code, and we might want to remove it.
8832 2. ``Fixing'' an Entity, the Simple Case:
8833 -----------------------------------------
8835 When evaluating Ada expressions, the tricky issue is that they may
8836 reference entities whose type contents and size are not statically
8837 known. Consider for instance a variant record:
8839 type Rec (Empty : Boolean := True) is record
8842 when False => Value : Integer;
8845 Yes : Rec := (Empty => False, Value => 1);
8846 No : Rec := (empty => True);
8848 The size and contents of that record depends on the value of the
8849 descriminant (Rec.Empty). At this point, neither the debugging
8850 information nor the associated type structure in GDB are able to
8851 express such dynamic types. So what the debugger does is to create
8852 "fixed" versions of the type that applies to the specific object.
8853 We also informally refer to this opperation as "fixing" an object,
8854 which means creating its associated fixed type.
8856 Example: when printing the value of variable "Yes" above, its fixed
8857 type would look like this:
8864 On the other hand, if we printed the value of "No", its fixed type
8871 Things become a little more complicated when trying to fix an entity
8872 with a dynamic type that directly contains another dynamic type,
8873 such as an array of variant records, for instance. There are
8874 two possible cases: Arrays, and records.
8876 3. ``Fixing'' Arrays:
8877 ---------------------
8879 The type structure in GDB describes an array in terms of its bounds,
8880 and the type of its elements. By design, all elements in the array
8881 have the same type and we cannot represent an array of variant elements
8882 using the current type structure in GDB. When fixing an array,
8883 we cannot fix the array element, as we would potentially need one
8884 fixed type per element of the array. As a result, the best we can do
8885 when fixing an array is to produce an array whose bounds and size
8886 are correct (allowing us to read it from memory), but without having
8887 touched its element type. Fixing each element will be done later,
8888 when (if) necessary.
8890 Arrays are a little simpler to handle than records, because the same
8891 amount of memory is allocated for each element of the array, even if
8892 the amount of space actually used by each element differs from element
8893 to element. Consider for instance the following array of type Rec:
8895 type Rec_Array is array (1 .. 2) of Rec;
8897 The actual amount of memory occupied by each element might be different
8898 from element to element, depending on the value of their discriminant.
8899 But the amount of space reserved for each element in the array remains
8900 fixed regardless. So we simply need to compute that size using
8901 the debugging information available, from which we can then determine
8902 the array size (we multiply the number of elements of the array by
8903 the size of each element).
8905 The simplest case is when we have an array of a constrained element
8906 type. For instance, consider the following type declarations:
8908 type Bounded_String (Max_Size : Integer) is
8910 Buffer : String (1 .. Max_Size);
8912 type Bounded_String_Array is array (1 ..2) of Bounded_String (80);
8914 In this case, the compiler describes the array as an array of
8915 variable-size elements (identified by its XVS suffix) for which
8916 the size can be read in the parallel XVZ variable.
8918 In the case of an array of an unconstrained element type, the compiler
8919 wraps the array element inside a private PAD type. This type should not
8920 be shown to the user, and must be "unwrap"'ed before printing. Note
8921 that we also use the adjective "aligner" in our code to designate
8922 these wrapper types.
8924 In some cases, the size allocated for each element is statically
8925 known. In that case, the PAD type already has the correct size,
8926 and the array element should remain unfixed.
8928 But there are cases when this size is not statically known.
8929 For instance, assuming that "Five" is an integer variable:
8931 type Dynamic is array (1 .. Five) of Integer;
8932 type Wrapper (Has_Length : Boolean := False) is record
8935 when True => Length : Integer;
8939 type Wrapper_Array is array (1 .. 2) of Wrapper;
8941 Hello : Wrapper_Array := (others => (Has_Length => True,
8942 Data => (others => 17),
8946 The debugging info would describe variable Hello as being an
8947 array of a PAD type. The size of that PAD type is not statically
8948 known, but can be determined using a parallel XVZ variable.
8949 In that case, a copy of the PAD type with the correct size should
8950 be used for the fixed array.
8952 3. ``Fixing'' record type objects:
8953 ----------------------------------
8955 Things are slightly different from arrays in the case of dynamic
8956 record types. In this case, in order to compute the associated
8957 fixed type, we need to determine the size and offset of each of
8958 its components. This, in turn, requires us to compute the fixed
8959 type of each of these components.
8961 Consider for instance the example:
8963 type Bounded_String (Max_Size : Natural) is record
8964 Str : String (1 .. Max_Size);
8967 My_String : Bounded_String (Max_Size => 10);
8969 In that case, the position of field "Length" depends on the size
8970 of field Str, which itself depends on the value of the Max_Size
8971 discriminant. In order to fix the type of variable My_String,
8972 we need to fix the type of field Str. Therefore, fixing a variant
8973 record requires us to fix each of its components.
8975 However, if a component does not have a dynamic size, the component
8976 should not be fixed. In particular, fields that use a PAD type
8977 should not fixed. Here is an example where this might happen
8978 (assuming type Rec above):
8980 type Container (Big : Boolean) is record
8984 when True => Another : Integer;
8988 My_Container : Container := (Big => False,
8989 First => (Empty => True),
8992 In that example, the compiler creates a PAD type for component First,
8993 whose size is constant, and then positions the component After just
8994 right after it. The offset of component After is therefore constant
8997 The debugger computes the position of each field based on an algorithm
8998 that uses, among other things, the actual position and size of the field
8999 preceding it. Let's now imagine that the user is trying to print
9000 the value of My_Container. If the type fixing was recursive, we would
9001 end up computing the offset of field After based on the size of the
9002 fixed version of field First. And since in our example First has
9003 only one actual field, the size of the fixed type is actually smaller
9004 than the amount of space allocated to that field, and thus we would
9005 compute the wrong offset of field After.
9007 To make things more complicated, we need to watch out for dynamic
9008 components of variant records (identified by the ___XVL suffix in
9009 the component name). Even if the target type is a PAD type, the size
9010 of that type might not be statically known. So the PAD type needs
9011 to be unwrapped and the resulting type needs to be fixed. Otherwise,
9012 we might end up with the wrong size for our component. This can be
9013 observed with the following type declarations:
9015 type Octal is new Integer range 0 .. 7;
9016 type Octal_Array is array (Positive range <>) of Octal;
9017 pragma Pack (Octal_Array);
9019 type Octal_Buffer (Size : Positive) is record
9020 Buffer : Octal_Array (1 .. Size);
9024 In that case, Buffer is a PAD type whose size is unset and needs
9025 to be computed by fixing the unwrapped type.
9027 4. When to ``Fix'' un-``Fixed'' sub-elements of an entity:
9028 ----------------------------------------------------------
9030 Lastly, when should the sub-elements of an entity that remained unfixed
9031 thus far, be actually fixed?
9033 The answer is: Only when referencing that element. For instance
9034 when selecting one component of a record, this specific component
9035 should be fixed at that point in time. Or when printing the value
9036 of a record, each component should be fixed before its value gets
9037 printed. Similarly for arrays, the element of the array should be
9038 fixed when printing each element of the array, or when extracting
9039 one element out of that array. On the other hand, fixing should
9040 not be performed on the elements when taking a slice of an array!
9042 Note that one of the side-effects of miscomputing the offset and
9043 size of each field is that we end up also miscomputing the size
9044 of the containing type. This can have adverse results when computing
9045 the value of an entity. GDB fetches the value of an entity based
9046 on the size of its type, and thus a wrong size causes GDB to fetch
9047 the wrong amount of memory. In the case where the computed size is
9048 too small, GDB fetches too little data to print the value of our
9049 entiry. Results in this case as unpredicatble, as we usually read
9050 past the buffer containing the data =:-o. */
9052 /* Implement the evaluate_exp routine in the exp_descriptor structure
9053 for the Ada language. */
9055 static struct value *
9056 ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
9057 int *pos, enum noside noside)
9062 struct value *arg1 = NULL, *arg2 = NULL, *arg3;
9065 struct value **argvec;
9069 op = exp->elts[pc].opcode;
9075 arg1 = evaluate_subexp_standard (expect_type, exp, pos, noside);
9076 arg1 = unwrap_value (arg1);
9078 /* If evaluating an OP_DOUBLE and an EXPECT_TYPE was provided,
9079 then we need to perform the conversion manually, because
9080 evaluate_subexp_standard doesn't do it. This conversion is
9081 necessary in Ada because the different kinds of float/fixed
9082 types in Ada have different representations.
9084 Similarly, we need to perform the conversion from OP_LONG
9086 if ((op == OP_DOUBLE || op == OP_LONG) && expect_type != NULL)
9087 arg1 = ada_value_cast (expect_type, arg1, noside);
9093 struct value *result;
9096 result = evaluate_subexp_standard (expect_type, exp, pos, noside);
9097 /* The result type will have code OP_STRING, bashed there from
9098 OP_ARRAY. Bash it back. */
9099 if (TYPE_CODE (value_type (result)) == TYPE_CODE_STRING)
9100 TYPE_CODE (value_type (result)) = TYPE_CODE_ARRAY;
9106 type = exp->elts[pc + 1].type;
9107 arg1 = evaluate_subexp (type, exp, pos, noside);
9108 if (noside == EVAL_SKIP)
9110 arg1 = ada_value_cast (type, arg1, noside);
9115 type = exp->elts[pc + 1].type;
9116 return ada_evaluate_subexp (type, exp, pos, noside);
9119 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
9120 if (exp->elts[*pos].opcode == OP_AGGREGATE)
9122 arg1 = assign_aggregate (arg1, arg1, exp, pos, noside);
9123 if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
9125 return ada_value_assign (arg1, arg1);
9127 /* Force the evaluation of the rhs ARG2 to the type of the lhs ARG1,
9128 except if the lhs of our assignment is a convenience variable.
9129 In the case of assigning to a convenience variable, the lhs
9130 should be exactly the result of the evaluation of the rhs. */
9131 type = value_type (arg1);
9132 if (VALUE_LVAL (arg1) == lval_internalvar)
9134 arg2 = evaluate_subexp (type, exp, pos, noside);
9135 if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
9137 if (ada_is_fixed_point_type (value_type (arg1)))
9138 arg2 = cast_to_fixed (value_type (arg1), arg2);
9139 else if (ada_is_fixed_point_type (value_type (arg2)))
9141 (_("Fixed-point values must be assigned to fixed-point variables"));
9143 arg2 = coerce_for_assign (value_type (arg1), arg2);
9144 return ada_value_assign (arg1, arg2);
9147 arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
9148 arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
9149 if (noside == EVAL_SKIP)
9151 if (TYPE_CODE (value_type (arg1)) == TYPE_CODE_PTR)
9152 return (value_from_longest
9154 value_as_long (arg1) + value_as_long (arg2)));
9155 if ((ada_is_fixed_point_type (value_type (arg1))
9156 || ada_is_fixed_point_type (value_type (arg2)))
9157 && value_type (arg1) != value_type (arg2))
9158 error (_("Operands of fixed-point addition must have the same type"));
9159 /* Do the addition, and cast the result to the type of the first
9160 argument. We cannot cast the result to a reference type, so if
9161 ARG1 is a reference type, find its underlying type. */
9162 type = value_type (arg1);
9163 while (TYPE_CODE (type) == TYPE_CODE_REF)
9164 type = TYPE_TARGET_TYPE (type);
9165 binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
9166 return value_cast (type, value_binop (arg1, arg2, BINOP_ADD));
9169 arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
9170 arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
9171 if (noside == EVAL_SKIP)
9173 if (TYPE_CODE (value_type (arg1)) == TYPE_CODE_PTR)
9174 return (value_from_longest
9176 value_as_long (arg1) - value_as_long (arg2)));
9177 if ((ada_is_fixed_point_type (value_type (arg1))
9178 || ada_is_fixed_point_type (value_type (arg2)))
9179 && value_type (arg1) != value_type (arg2))
9180 error (_("Operands of fixed-point subtraction "
9181 "must have the same type"));
9182 /* Do the substraction, and cast the result to the type of the first
9183 argument. We cannot cast the result to a reference type, so if
9184 ARG1 is a reference type, find its underlying type. */
9185 type = value_type (arg1);
9186 while (TYPE_CODE (type) == TYPE_CODE_REF)
9187 type = TYPE_TARGET_TYPE (type);
9188 binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
9189 return value_cast (type, value_binop (arg1, arg2, BINOP_SUB));
9195 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
9196 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
9197 if (noside == EVAL_SKIP)
9199 else if (noside == EVAL_AVOID_SIDE_EFFECTS)
9201 binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
9202 return value_zero (value_type (arg1), not_lval);
9206 type = builtin_type (exp->gdbarch)->builtin_double;
9207 if (ada_is_fixed_point_type (value_type (arg1)))
9208 arg1 = cast_from_fixed (type, arg1);
9209 if (ada_is_fixed_point_type (value_type (arg2)))
9210 arg2 = cast_from_fixed (type, arg2);
9211 binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
9212 return ada_value_binop (arg1, arg2, op);
9216 case BINOP_NOTEQUAL:
9217 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
9218 arg2 = evaluate_subexp (value_type (arg1), exp, pos, noside);
9219 if (noside == EVAL_SKIP)
9221 if (noside == EVAL_AVOID_SIDE_EFFECTS)
9225 binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
9226 tem = ada_value_equal (arg1, arg2);
9228 if (op == BINOP_NOTEQUAL)
9230 type = language_bool_type (exp->language_defn, exp->gdbarch);
9231 return value_from_longest (type, (LONGEST) tem);
9234 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
9235 if (noside == EVAL_SKIP)
9237 else if (ada_is_fixed_point_type (value_type (arg1)))
9238 return value_cast (value_type (arg1), value_neg (arg1));
9241 unop_promote (exp->language_defn, exp->gdbarch, &arg1);
9242 return value_neg (arg1);
9245 case BINOP_LOGICAL_AND:
9246 case BINOP_LOGICAL_OR:
9247 case UNOP_LOGICAL_NOT:
9252 val = evaluate_subexp_standard (expect_type, exp, pos, noside);
9253 type = language_bool_type (exp->language_defn, exp->gdbarch);
9254 return value_cast (type, val);
9257 case BINOP_BITWISE_AND:
9258 case BINOP_BITWISE_IOR:
9259 case BINOP_BITWISE_XOR:
9263 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
9265 val = evaluate_subexp_standard (expect_type, exp, pos, noside);
9267 return value_cast (value_type (arg1), val);
9273 if (noside == EVAL_SKIP)
9278 else if (SYMBOL_DOMAIN (exp->elts[pc + 2].symbol) == UNDEF_DOMAIN)
9279 /* Only encountered when an unresolved symbol occurs in a
9280 context other than a function call, in which case, it is
9282 error (_("Unexpected unresolved symbol, %s, during evaluation"),
9283 SYMBOL_PRINT_NAME (exp->elts[pc + 2].symbol));
9284 else if (noside == EVAL_AVOID_SIDE_EFFECTS)
9286 type = static_unwrap_type (SYMBOL_TYPE (exp->elts[pc + 2].symbol));
9287 /* Check to see if this is a tagged type. We also need to handle
9288 the case where the type is a reference to a tagged type, but
9289 we have to be careful to exclude pointers to tagged types.
9290 The latter should be shown as usual (as a pointer), whereas
9291 a reference should mostly be transparent to the user. */
9292 if (ada_is_tagged_type (type, 0)
9293 || (TYPE_CODE(type) == TYPE_CODE_REF
9294 && ada_is_tagged_type (TYPE_TARGET_TYPE (type), 0)))
9296 /* Tagged types are a little special in the fact that the real
9297 type is dynamic and can only be determined by inspecting the
9298 object's tag. This means that we need to get the object's
9299 value first (EVAL_NORMAL) and then extract the actual object
9302 Note that we cannot skip the final step where we extract
9303 the object type from its tag, because the EVAL_NORMAL phase
9304 results in dynamic components being resolved into fixed ones.
9305 This can cause problems when trying to print the type
9306 description of tagged types whose parent has a dynamic size:
9307 We use the type name of the "_parent" component in order
9308 to print the name of the ancestor type in the type description.
9309 If that component had a dynamic size, the resolution into
9310 a fixed type would result in the loss of that type name,
9311 thus preventing us from printing the name of the ancestor
9312 type in the type description. */
9313 struct type *actual_type;
9315 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_NORMAL);
9316 actual_type = type_from_tag (ada_value_tag (arg1));
9317 if (actual_type == NULL)
9318 /* If, for some reason, we were unable to determine
9319 the actual type from the tag, then use the static
9320 approximation that we just computed as a fallback.
9321 This can happen if the debugging information is
9322 incomplete, for instance. */
9325 return value_zero (actual_type, not_lval);
9330 (to_static_fixed_type
9331 (static_unwrap_type (SYMBOL_TYPE (exp->elts[pc + 2].symbol))),
9336 arg1 = evaluate_subexp_standard (expect_type, exp, pos, noside);
9337 arg1 = unwrap_value (arg1);
9338 return ada_to_fixed_value (arg1);
9344 /* Allocate arg vector, including space for the function to be
9345 called in argvec[0] and a terminating NULL. */
9346 nargs = longest_to_int (exp->elts[pc + 1].longconst);
9348 (struct value **) alloca (sizeof (struct value *) * (nargs + 2));
9350 if (exp->elts[*pos].opcode == OP_VAR_VALUE
9351 && SYMBOL_DOMAIN (exp->elts[pc + 5].symbol) == UNDEF_DOMAIN)
9352 error (_("Unexpected unresolved symbol, %s, during evaluation"),
9353 SYMBOL_PRINT_NAME (exp->elts[pc + 5].symbol));
9356 for (tem = 0; tem <= nargs; tem += 1)
9357 argvec[tem] = evaluate_subexp (NULL_TYPE, exp, pos, noside);
9360 if (noside == EVAL_SKIP)
9364 if (ada_is_constrained_packed_array_type
9365 (desc_base_type (value_type (argvec[0]))))
9366 argvec[0] = ada_coerce_to_simple_array (argvec[0]);
9367 else if (TYPE_CODE (value_type (argvec[0])) == TYPE_CODE_ARRAY
9368 && TYPE_FIELD_BITSIZE (value_type (argvec[0]), 0) != 0)
9369 /* This is a packed array that has already been fixed, and
9370 therefore already coerced to a simple array. Nothing further
9373 else if (TYPE_CODE (value_type (argvec[0])) == TYPE_CODE_REF
9374 || (TYPE_CODE (value_type (argvec[0])) == TYPE_CODE_ARRAY
9375 && VALUE_LVAL (argvec[0]) == lval_memory))
9376 argvec[0] = value_addr (argvec[0]);
9378 type = ada_check_typedef (value_type (argvec[0]));
9380 /* Ada allows us to implicitly dereference arrays when subscripting
9381 them. So, if this is an typedef (encoding use for array access
9382 types encoded as fat pointers), strip it now. */
9383 if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
9384 type = ada_typedef_target_type (type);
9386 if (TYPE_CODE (type) == TYPE_CODE_PTR)
9388 switch (TYPE_CODE (ada_check_typedef (TYPE_TARGET_TYPE (type))))
9390 case TYPE_CODE_FUNC:
9391 type = ada_check_typedef (TYPE_TARGET_TYPE (type));
9393 case TYPE_CODE_ARRAY:
9395 case TYPE_CODE_STRUCT:
9396 if (noside != EVAL_AVOID_SIDE_EFFECTS)
9397 argvec[0] = ada_value_ind (argvec[0]);
9398 type = ada_check_typedef (TYPE_TARGET_TYPE (type));
9401 error (_("cannot subscript or call something of type `%s'"),
9402 ada_type_name (value_type (argvec[0])));
9407 switch (TYPE_CODE (type))
9409 case TYPE_CODE_FUNC:
9410 if (noside == EVAL_AVOID_SIDE_EFFECTS)
9411 return allocate_value (TYPE_TARGET_TYPE (type));
9412 return call_function_by_hand (argvec[0], nargs, argvec + 1);
9413 case TYPE_CODE_STRUCT:
9417 arity = ada_array_arity (type);
9418 type = ada_array_element_type (type, nargs);
9420 error (_("cannot subscript or call a record"));
9422 error (_("wrong number of subscripts; expecting %d"), arity);
9423 if (noside == EVAL_AVOID_SIDE_EFFECTS)
9424 return value_zero (ada_aligned_type (type), lval_memory);
9426 unwrap_value (ada_value_subscript
9427 (argvec[0], nargs, argvec + 1));
9429 case TYPE_CODE_ARRAY:
9430 if (noside == EVAL_AVOID_SIDE_EFFECTS)
9432 type = ada_array_element_type (type, nargs);
9434 error (_("element type of array unknown"));
9436 return value_zero (ada_aligned_type (type), lval_memory);
9439 unwrap_value (ada_value_subscript
9440 (ada_coerce_to_simple_array (argvec[0]),
9441 nargs, argvec + 1));
9442 case TYPE_CODE_PTR: /* Pointer to array */
9443 type = to_fixed_array_type (TYPE_TARGET_TYPE (type), NULL, 1);
9444 if (noside == EVAL_AVOID_SIDE_EFFECTS)
9446 type = ada_array_element_type (type, nargs);
9448 error (_("element type of array unknown"));
9450 return value_zero (ada_aligned_type (type), lval_memory);
9453 unwrap_value (ada_value_ptr_subscript (argvec[0], type,
9454 nargs, argvec + 1));
9457 error (_("Attempt to index or call something other than an "
9458 "array or function"));
9463 struct value *array = evaluate_subexp (NULL_TYPE, exp, pos, noside);
9464 struct value *low_bound_val =
9465 evaluate_subexp (NULL_TYPE, exp, pos, noside);
9466 struct value *high_bound_val =
9467 evaluate_subexp (NULL_TYPE, exp, pos, noside);
9471 low_bound_val = coerce_ref (low_bound_val);
9472 high_bound_val = coerce_ref (high_bound_val);
9473 low_bound = pos_atr (low_bound_val);
9474 high_bound = pos_atr (high_bound_val);
9476 if (noside == EVAL_SKIP)
9479 /* If this is a reference to an aligner type, then remove all
9481 if (TYPE_CODE (value_type (array)) == TYPE_CODE_REF
9482 && ada_is_aligner_type (TYPE_TARGET_TYPE (value_type (array))))
9483 TYPE_TARGET_TYPE (value_type (array)) =
9484 ada_aligned_type (TYPE_TARGET_TYPE (value_type (array)));
9486 if (ada_is_constrained_packed_array_type (value_type (array)))
9487 error (_("cannot slice a packed array"));
9489 /* If this is a reference to an array or an array lvalue,
9490 convert to a pointer. */
9491 if (TYPE_CODE (value_type (array)) == TYPE_CODE_REF
9492 || (TYPE_CODE (value_type (array)) == TYPE_CODE_ARRAY
9493 && VALUE_LVAL (array) == lval_memory))
9494 array = value_addr (array);
9496 if (noside == EVAL_AVOID_SIDE_EFFECTS
9497 && ada_is_array_descriptor_type (ada_check_typedef
9498 (value_type (array))))
9499 return empty_array (ada_type_of_array (array, 0), low_bound);
9501 array = ada_coerce_to_simple_array_ptr (array);
9503 /* If we have more than one level of pointer indirection,
9504 dereference the value until we get only one level. */
9505 while (TYPE_CODE (value_type (array)) == TYPE_CODE_PTR
9506 && (TYPE_CODE (TYPE_TARGET_TYPE (value_type (array)))
9508 array = value_ind (array);
9510 /* Make sure we really do have an array type before going further,
9511 to avoid a SEGV when trying to get the index type or the target
9512 type later down the road if the debug info generated by
9513 the compiler is incorrect or incomplete. */
9514 if (!ada_is_simple_array_type (value_type (array)))
9515 error (_("cannot take slice of non-array"));
9517 if (TYPE_CODE (value_type (array)) == TYPE_CODE_PTR)
9519 if (high_bound < low_bound || noside == EVAL_AVOID_SIDE_EFFECTS)
9520 return empty_array (TYPE_TARGET_TYPE (value_type (array)),
9524 struct type *arr_type0 =
9525 to_fixed_array_type (TYPE_TARGET_TYPE (value_type (array)),
9528 return ada_value_slice_from_ptr (array, arr_type0,
9529 longest_to_int (low_bound),
9530 longest_to_int (high_bound));
9533 else if (noside == EVAL_AVOID_SIDE_EFFECTS)
9535 else if (high_bound < low_bound)
9536 return empty_array (value_type (array), low_bound);
9538 return ada_value_slice (array, longest_to_int (low_bound),
9539 longest_to_int (high_bound));
9544 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
9545 type = check_typedef (exp->elts[pc + 1].type);
9547 if (noside == EVAL_SKIP)
9550 switch (TYPE_CODE (type))
9553 lim_warning (_("Membership test incompletely implemented; "
9554 "always returns true"));
9555 type = language_bool_type (exp->language_defn, exp->gdbarch);
9556 return value_from_longest (type, (LONGEST) 1);
9558 case TYPE_CODE_RANGE:
9559 arg2 = value_from_longest (type, TYPE_LOW_BOUND (type));
9560 arg3 = value_from_longest (type, TYPE_HIGH_BOUND (type));
9561 binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
9562 binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg3);
9563 type = language_bool_type (exp->language_defn, exp->gdbarch);
9565 value_from_longest (type,
9566 (value_less (arg1, arg3)
9567 || value_equal (arg1, arg3))
9568 && (value_less (arg2, arg1)
9569 || value_equal (arg2, arg1)));
9572 case BINOP_IN_BOUNDS:
9574 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
9575 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
9577 if (noside == EVAL_SKIP)
9580 if (noside == EVAL_AVOID_SIDE_EFFECTS)
9582 type = language_bool_type (exp->language_defn, exp->gdbarch);
9583 return value_zero (type, not_lval);
9586 tem = longest_to_int (exp->elts[pc + 1].longconst);
9588 type = ada_index_type (value_type (arg2), tem, "range");
9590 type = value_type (arg1);
9592 arg3 = value_from_longest (type, ada_array_bound (arg2, tem, 1));
9593 arg2 = value_from_longest (type, ada_array_bound (arg2, tem, 0));
9595 binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
9596 binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg3);
9597 type = language_bool_type (exp->language_defn, exp->gdbarch);
9599 value_from_longest (type,
9600 (value_less (arg1, arg3)
9601 || value_equal (arg1, arg3))
9602 && (value_less (arg2, arg1)
9603 || value_equal (arg2, arg1)));
9605 case TERNOP_IN_RANGE:
9606 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
9607 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
9608 arg3 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
9610 if (noside == EVAL_SKIP)
9613 binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
9614 binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg3);
9615 type = language_bool_type (exp->language_defn, exp->gdbarch);
9617 value_from_longest (type,
9618 (value_less (arg1, arg3)
9619 || value_equal (arg1, arg3))
9620 && (value_less (arg2, arg1)
9621 || value_equal (arg2, arg1)));
9627 struct type *type_arg;
9629 if (exp->elts[*pos].opcode == OP_TYPE)
9631 evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
9633 type_arg = check_typedef (exp->elts[pc + 2].type);
9637 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
9641 if (exp->elts[*pos].opcode != OP_LONG)
9642 error (_("Invalid operand to '%s"), ada_attribute_name (op));
9643 tem = longest_to_int (exp->elts[*pos + 2].longconst);
9646 if (noside == EVAL_SKIP)
9649 if (type_arg == NULL)
9651 arg1 = ada_coerce_ref (arg1);
9653 if (ada_is_constrained_packed_array_type (value_type (arg1)))
9654 arg1 = ada_coerce_to_simple_array (arg1);
9656 type = ada_index_type (value_type (arg1), tem,
9657 ada_attribute_name (op));
9659 type = builtin_type (exp->gdbarch)->builtin_int;
9661 if (noside == EVAL_AVOID_SIDE_EFFECTS)
9662 return allocate_value (type);
9666 default: /* Should never happen. */
9667 error (_("unexpected attribute encountered"));
9669 return value_from_longest
9670 (type, ada_array_bound (arg1, tem, 0));
9672 return value_from_longest
9673 (type, ada_array_bound (arg1, tem, 1));
9675 return value_from_longest
9676 (type, ada_array_length (arg1, tem));
9679 else if (discrete_type_p (type_arg))
9681 struct type *range_type;
9682 char *name = ada_type_name (type_arg);
9685 if (name != NULL && TYPE_CODE (type_arg) != TYPE_CODE_ENUM)
9686 range_type = to_fixed_range_type (type_arg, NULL);
9687 if (range_type == NULL)
9688 range_type = type_arg;
9692 error (_("unexpected attribute encountered"));
9694 return value_from_longest
9695 (range_type, ada_discrete_type_low_bound (range_type));
9697 return value_from_longest
9698 (range_type, ada_discrete_type_high_bound (range_type));
9700 error (_("the 'length attribute applies only to array types"));
9703 else if (TYPE_CODE (type_arg) == TYPE_CODE_FLT)
9704 error (_("unimplemented type attribute"));
9709 if (ada_is_constrained_packed_array_type (type_arg))
9710 type_arg = decode_constrained_packed_array_type (type_arg);
9712 type = ada_index_type (type_arg, tem, ada_attribute_name (op));
9714 type = builtin_type (exp->gdbarch)->builtin_int;
9716 if (noside == EVAL_AVOID_SIDE_EFFECTS)
9717 return allocate_value (type);
9722 error (_("unexpected attribute encountered"));
9724 low = ada_array_bound_from_type (type_arg, tem, 0);
9725 return value_from_longest (type, low);
9727 high = ada_array_bound_from_type (type_arg, tem, 1);
9728 return value_from_longest (type, high);
9730 low = ada_array_bound_from_type (type_arg, tem, 0);
9731 high = ada_array_bound_from_type (type_arg, tem, 1);
9732 return value_from_longest (type, high - low + 1);
9738 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
9739 if (noside == EVAL_SKIP)
9742 if (noside == EVAL_AVOID_SIDE_EFFECTS)
9743 return value_zero (ada_tag_type (arg1), not_lval);
9745 return ada_value_tag (arg1);
9749 evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
9750 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
9751 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
9752 if (noside == EVAL_SKIP)
9754 else if (noside == EVAL_AVOID_SIDE_EFFECTS)
9755 return value_zero (value_type (arg1), not_lval);
9758 binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
9759 return value_binop (arg1, arg2,
9760 op == OP_ATR_MIN ? BINOP_MIN : BINOP_MAX);
9763 case OP_ATR_MODULUS:
9765 struct type *type_arg = check_typedef (exp->elts[pc + 2].type);
9767 evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
9768 if (noside == EVAL_SKIP)
9771 if (!ada_is_modular_type (type_arg))
9772 error (_("'modulus must be applied to modular type"));
9774 return value_from_longest (TYPE_TARGET_TYPE (type_arg),
9775 ada_modulus (type_arg));
9780 evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
9781 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
9782 if (noside == EVAL_SKIP)
9784 type = builtin_type (exp->gdbarch)->builtin_int;
9785 if (noside == EVAL_AVOID_SIDE_EFFECTS)
9786 return value_zero (type, not_lval);
9788 return value_pos_atr (type, arg1);
9791 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
9792 type = value_type (arg1);
9794 /* If the argument is a reference, then dereference its type, since
9795 the user is really asking for the size of the actual object,
9796 not the size of the pointer. */
9797 if (TYPE_CODE (type) == TYPE_CODE_REF)
9798 type = TYPE_TARGET_TYPE (type);
9800 if (noside == EVAL_SKIP)
9802 else if (noside == EVAL_AVOID_SIDE_EFFECTS)
9803 return value_zero (builtin_type (exp->gdbarch)->builtin_int, not_lval);
9805 return value_from_longest (builtin_type (exp->gdbarch)->builtin_int,
9806 TARGET_CHAR_BIT * TYPE_LENGTH (type));
9809 evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
9810 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
9811 type = exp->elts[pc + 2].type;
9812 if (noside == EVAL_SKIP)
9814 else if (noside == EVAL_AVOID_SIDE_EFFECTS)
9815 return value_zero (type, not_lval);
9817 return value_val_atr (type, arg1);
9820 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
9821 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
9822 if (noside == EVAL_SKIP)
9824 else if (noside == EVAL_AVOID_SIDE_EFFECTS)
9825 return value_zero (value_type (arg1), not_lval);
9828 /* For integer exponentiation operations,
9829 only promote the first argument. */
9830 if (is_integral_type (value_type (arg2)))
9831 unop_promote (exp->language_defn, exp->gdbarch, &arg1);
9833 binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
9835 return value_binop (arg1, arg2, op);
9839 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
9840 if (noside == EVAL_SKIP)
9846 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
9847 if (noside == EVAL_SKIP)
9849 unop_promote (exp->language_defn, exp->gdbarch, &arg1);
9850 if (value_less (arg1, value_zero (value_type (arg1), not_lval)))
9851 return value_neg (arg1);
9856 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
9857 if (noside == EVAL_SKIP)
9859 type = ada_check_typedef (value_type (arg1));
9860 if (noside == EVAL_AVOID_SIDE_EFFECTS)
9862 if (ada_is_array_descriptor_type (type))
9863 /* GDB allows dereferencing GNAT array descriptors. */
9865 struct type *arrType = ada_type_of_array (arg1, 0);
9867 if (arrType == NULL)
9868 error (_("Attempt to dereference null array pointer."));
9869 return value_at_lazy (arrType, 0);
9871 else if (TYPE_CODE (type) == TYPE_CODE_PTR
9872 || TYPE_CODE (type) == TYPE_CODE_REF
9873 /* In C you can dereference an array to get the 1st elt. */
9874 || TYPE_CODE (type) == TYPE_CODE_ARRAY)
9876 type = to_static_fixed_type
9878 (ada_check_typedef (TYPE_TARGET_TYPE (type))));
9880 return value_zero (type, lval_memory);
9882 else if (TYPE_CODE (type) == TYPE_CODE_INT)
9884 /* GDB allows dereferencing an int. */
9885 if (expect_type == NULL)
9886 return value_zero (builtin_type (exp->gdbarch)->builtin_int,
9891 to_static_fixed_type (ada_aligned_type (expect_type));
9892 return value_zero (expect_type, lval_memory);
9896 error (_("Attempt to take contents of a non-pointer value."));
9898 arg1 = ada_coerce_ref (arg1); /* FIXME: What is this for?? */
9899 type = ada_check_typedef (value_type (arg1));
9901 if (TYPE_CODE (type) == TYPE_CODE_INT)
9902 /* GDB allows dereferencing an int. If we were given
9903 the expect_type, then use that as the target type.
9904 Otherwise, assume that the target type is an int. */
9906 if (expect_type != NULL)
9907 return ada_value_ind (value_cast (lookup_pointer_type (expect_type),
9910 return value_at_lazy (builtin_type (exp->gdbarch)->builtin_int,
9911 (CORE_ADDR) value_as_address (arg1));
9914 if (ada_is_array_descriptor_type (type))
9915 /* GDB allows dereferencing GNAT array descriptors. */
9916 return ada_coerce_to_simple_array (arg1);
9918 return ada_value_ind (arg1);
9920 case STRUCTOP_STRUCT:
9921 tem = longest_to_int (exp->elts[pc + 1].longconst);
9922 (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
9923 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
9924 if (noside == EVAL_SKIP)
9926 if (noside == EVAL_AVOID_SIDE_EFFECTS)
9928 struct type *type1 = value_type (arg1);
9930 if (ada_is_tagged_type (type1, 1))
9932 type = ada_lookup_struct_elt_type (type1,
9933 &exp->elts[pc + 2].string,
9936 /* In this case, we assume that the field COULD exist
9937 in some extension of the type. Return an object of
9938 "type" void, which will match any formal
9939 (see ada_type_match). */
9940 return value_zero (builtin_type (exp->gdbarch)->builtin_void,
9945 ada_lookup_struct_elt_type (type1, &exp->elts[pc + 2].string, 1,
9948 return value_zero (ada_aligned_type (type), lval_memory);
9951 arg1 = ada_value_struct_elt (arg1, &exp->elts[pc + 2].string, 0);
9952 arg1 = unwrap_value (arg1);
9953 return ada_to_fixed_value (arg1);
9956 /* The value is not supposed to be used. This is here to make it
9957 easier to accommodate expressions that contain types. */
9959 if (noside == EVAL_SKIP)
9961 else if (noside == EVAL_AVOID_SIDE_EFFECTS)
9962 return allocate_value (exp->elts[pc + 1].type);
9964 error (_("Attempt to use a type name as an expression"));
9969 case OP_DISCRETE_RANGE:
9972 if (noside == EVAL_NORMAL)
9976 error (_("Undefined name, ambiguous name, or renaming used in "
9977 "component association: %s."), &exp->elts[pc+2].string);
9979 error (_("Aggregates only allowed on the right of an assignment"));
9981 internal_error (__FILE__, __LINE__,
9982 _("aggregate apparently mangled"));
9985 ada_forward_operator_length (exp, pc, &oplen, &nargs);
9987 for (tem = 0; tem < nargs; tem += 1)
9988 ada_evaluate_subexp (NULL, exp, pos, noside);
9993 return value_from_longest (builtin_type (exp->gdbarch)->builtin_int, 1);
9999 /* If TYPE encodes an Ada fixed-point type, return the suffix of the
10000 type name that encodes the 'small and 'delta information.
10001 Otherwise, return NULL. */
10003 static const char *
10004 fixed_type_info (struct type *type)
10006 const char *name = ada_type_name (type);
10007 enum type_code code = (type == NULL) ? TYPE_CODE_UNDEF : TYPE_CODE (type);
10009 if ((code == TYPE_CODE_INT || code == TYPE_CODE_RANGE) && name != NULL)
10011 const char *tail = strstr (name, "___XF_");
10018 else if (code == TYPE_CODE_RANGE && TYPE_TARGET_TYPE (type) != type)
10019 return fixed_type_info (TYPE_TARGET_TYPE (type));
10024 /* Returns non-zero iff TYPE represents an Ada fixed-point type. */
10027 ada_is_fixed_point_type (struct type *type)
10029 return fixed_type_info (type) != NULL;
10032 /* Return non-zero iff TYPE represents a System.Address type. */
10035 ada_is_system_address_type (struct type *type)
10037 return (TYPE_NAME (type)
10038 && strcmp (TYPE_NAME (type), "system__address") == 0);
10041 /* Assuming that TYPE is the representation of an Ada fixed-point
10042 type, return its delta, or -1 if the type is malformed and the
10043 delta cannot be determined. */
10046 ada_delta (struct type *type)
10048 const char *encoding = fixed_type_info (type);
10051 /* Strictly speaking, num and den are encoded as integer. However,
10052 they may not fit into a long, and they will have to be converted
10053 to DOUBLEST anyway. So scan them as DOUBLEST. */
10054 if (sscanf (encoding, "_%" DOUBLEST_SCAN_FORMAT "_%" DOUBLEST_SCAN_FORMAT,
10061 /* Assuming that ada_is_fixed_point_type (TYPE), return the scaling
10062 factor ('SMALL value) associated with the type. */
10065 scaling_factor (struct type *type)
10067 const char *encoding = fixed_type_info (type);
10068 DOUBLEST num0, den0, num1, den1;
10071 /* Strictly speaking, num's and den's are encoded as integer. However,
10072 they may not fit into a long, and they will have to be converted
10073 to DOUBLEST anyway. So scan them as DOUBLEST. */
10074 n = sscanf (encoding,
10075 "_%" DOUBLEST_SCAN_FORMAT "_%" DOUBLEST_SCAN_FORMAT
10076 "_%" DOUBLEST_SCAN_FORMAT "_%" DOUBLEST_SCAN_FORMAT,
10077 &num0, &den0, &num1, &den1);
10082 return num1 / den1;
10084 return num0 / den0;
10088 /* Assuming that X is the representation of a value of fixed-point
10089 type TYPE, return its floating-point equivalent. */
10092 ada_fixed_to_float (struct type *type, LONGEST x)
10094 return (DOUBLEST) x *scaling_factor (type);
10097 /* The representation of a fixed-point value of type TYPE
10098 corresponding to the value X. */
10101 ada_float_to_fixed (struct type *type, DOUBLEST x)
10103 return (LONGEST) (x / scaling_factor (type) + 0.5);
10110 /* Scan STR beginning at position K for a discriminant name, and
10111 return the value of that discriminant field of DVAL in *PX. If
10112 PNEW_K is not null, put the position of the character beyond the
10113 name scanned in *PNEW_K. Return 1 if successful; return 0 and do
10114 not alter *PX and *PNEW_K if unsuccessful. */
10117 scan_discrim_bound (char *str, int k, struct value *dval, LONGEST * px,
10120 static char *bound_buffer = NULL;
10121 static size_t bound_buffer_len = 0;
10124 struct value *bound_val;
10126 if (dval == NULL || str == NULL || str[k] == '\0')
10129 pend = strstr (str + k, "__");
10133 k += strlen (bound);
10137 GROW_VECT (bound_buffer, bound_buffer_len, pend - (str + k) + 1);
10138 bound = bound_buffer;
10139 strncpy (bound_buffer, str + k, pend - (str + k));
10140 bound[pend - (str + k)] = '\0';
10144 bound_val = ada_search_struct_field (bound, dval, 0, value_type (dval));
10145 if (bound_val == NULL)
10148 *px = value_as_long (bound_val);
10149 if (pnew_k != NULL)
10154 /* Value of variable named NAME in the current environment. If
10155 no such variable found, then if ERR_MSG is null, returns 0, and
10156 otherwise causes an error with message ERR_MSG. */
10158 static struct value *
10159 get_var_value (char *name, char *err_msg)
10161 struct ada_symbol_info *syms;
10164 nsyms = ada_lookup_symbol_list (name, get_selected_block (0), VAR_DOMAIN,
10169 if (err_msg == NULL)
10172 error (("%s"), err_msg);
10175 return value_of_variable (syms[0].sym, syms[0].block);
10178 /* Value of integer variable named NAME in the current environment. If
10179 no such variable found, returns 0, and sets *FLAG to 0. If
10180 successful, sets *FLAG to 1. */
10183 get_int_var_value (char *name, int *flag)
10185 struct value *var_val = get_var_value (name, 0);
10197 return value_as_long (var_val);
10202 /* Return a range type whose base type is that of the range type named
10203 NAME in the current environment, and whose bounds are calculated
10204 from NAME according to the GNAT range encoding conventions.
10205 Extract discriminant values, if needed, from DVAL. ORIG_TYPE is the
10206 corresponding range type from debug information; fall back to using it
10207 if symbol lookup fails. If a new type must be created, allocate it
10208 like ORIG_TYPE was. The bounds information, in general, is encoded
10209 in NAME, the base type given in the named range type. */
10211 static struct type *
10212 to_fixed_range_type (struct type *raw_type, struct value *dval)
10215 struct type *base_type;
10216 char *subtype_info;
10218 gdb_assert (raw_type != NULL);
10219 gdb_assert (TYPE_NAME (raw_type) != NULL);
10221 if (TYPE_CODE (raw_type) == TYPE_CODE_RANGE)
10222 base_type = TYPE_TARGET_TYPE (raw_type);
10224 base_type = raw_type;
10226 name = TYPE_NAME (raw_type);
10227 subtype_info = strstr (name, "___XD");
10228 if (subtype_info == NULL)
10230 LONGEST L = ada_discrete_type_low_bound (raw_type);
10231 LONGEST U = ada_discrete_type_high_bound (raw_type);
10233 if (L < INT_MIN || U > INT_MAX)
10236 return create_range_type (alloc_type_copy (raw_type), raw_type,
10237 ada_discrete_type_low_bound (raw_type),
10238 ada_discrete_type_high_bound (raw_type));
10242 static char *name_buf = NULL;
10243 static size_t name_len = 0;
10244 int prefix_len = subtype_info - name;
10250 GROW_VECT (name_buf, name_len, prefix_len + 5);
10251 strncpy (name_buf, name, prefix_len);
10252 name_buf[prefix_len] = '\0';
10255 bounds_str = strchr (subtype_info, '_');
10258 if (*subtype_info == 'L')
10260 if (!ada_scan_number (bounds_str, n, &L, &n)
10261 && !scan_discrim_bound (bounds_str, n, dval, &L, &n))
10263 if (bounds_str[n] == '_')
10265 else if (bounds_str[n] == '.') /* FIXME? SGI Workshop kludge. */
10273 strcpy (name_buf + prefix_len, "___L");
10274 L = get_int_var_value (name_buf, &ok);
10277 lim_warning (_("Unknown lower bound, using 1."));
10282 if (*subtype_info == 'U')
10284 if (!ada_scan_number (bounds_str, n, &U, &n)
10285 && !scan_discrim_bound (bounds_str, n, dval, &U, &n))
10292 strcpy (name_buf + prefix_len, "___U");
10293 U = get_int_var_value (name_buf, &ok);
10296 lim_warning (_("Unknown upper bound, using %ld."), (long) L);
10301 type = create_range_type (alloc_type_copy (raw_type), base_type, L, U);
10302 TYPE_NAME (type) = name;
10307 /* True iff NAME is the name of a range type. */
10310 ada_is_range_type_name (const char *name)
10312 return (name != NULL && strstr (name, "___XD"));
10316 /* Modular types */
10318 /* True iff TYPE is an Ada modular type. */
10321 ada_is_modular_type (struct type *type)
10323 struct type *subranged_type = base_type (type);
10325 return (subranged_type != NULL && TYPE_CODE (type) == TYPE_CODE_RANGE
10326 && TYPE_CODE (subranged_type) == TYPE_CODE_INT
10327 && TYPE_UNSIGNED (subranged_type));
10330 /* Try to determine the lower and upper bounds of the given modular type
10331 using the type name only. Return non-zero and set L and U as the lower
10332 and upper bounds (respectively) if successful. */
10335 ada_modulus_from_name (struct type *type, ULONGEST *modulus)
10337 char *name = ada_type_name (type);
10345 /* Discrete type bounds are encoded using an __XD suffix. In our case,
10346 we are looking for static bounds, which means an __XDLU suffix.
10347 Moreover, we know that the lower bound of modular types is always
10348 zero, so the actual suffix should start with "__XDLU_0__", and
10349 then be followed by the upper bound value. */
10350 suffix = strstr (name, "__XDLU_0__");
10351 if (suffix == NULL)
10354 if (!ada_scan_number (suffix, k, &U, NULL))
10357 *modulus = (ULONGEST) U + 1;
10361 /* Assuming ada_is_modular_type (TYPE), the modulus of TYPE. */
10364 ada_modulus (struct type *type)
10366 return (ULONGEST) TYPE_HIGH_BOUND (type) + 1;
10370 /* Ada exception catchpoint support:
10371 ---------------------------------
10373 We support 3 kinds of exception catchpoints:
10374 . catchpoints on Ada exceptions
10375 . catchpoints on unhandled Ada exceptions
10376 . catchpoints on failed assertions
10378 Exceptions raised during failed assertions, or unhandled exceptions
10379 could perfectly be caught with the general catchpoint on Ada exceptions.
10380 However, we can easily differentiate these two special cases, and having
10381 the option to distinguish these two cases from the rest can be useful
10382 to zero-in on certain situations.
10384 Exception catchpoints are a specialized form of breakpoint,
10385 since they rely on inserting breakpoints inside known routines
10386 of the GNAT runtime. The implementation therefore uses a standard
10387 breakpoint structure of the BP_BREAKPOINT type, but with its own set
10390 Support in the runtime for exception catchpoints have been changed
10391 a few times already, and these changes affect the implementation
10392 of these catchpoints. In order to be able to support several
10393 variants of the runtime, we use a sniffer that will determine
10394 the runtime variant used by the program being debugged.
10396 At this time, we do not support the use of conditions on Ada exception
10397 catchpoints. The COND and COND_STRING fields are therefore set
10398 to NULL (most of the time, see below).
10400 Conditions where EXP_STRING, COND, and COND_STRING are used:
10402 When a user specifies the name of a specific exception in the case
10403 of catchpoints on Ada exceptions, we store the name of that exception
10404 in the EXP_STRING. We then translate this request into an actual
10405 condition stored in COND_STRING, and then parse it into an expression
10408 /* The different types of catchpoints that we introduced for catching
10411 enum exception_catchpoint_kind
10413 ex_catch_exception,
10414 ex_catch_exception_unhandled,
10418 /* Ada's standard exceptions. */
10420 static char *standard_exc[] = {
10421 "constraint_error",
10427 typedef CORE_ADDR (ada_unhandled_exception_name_addr_ftype) (void);
10429 /* A structure that describes how to support exception catchpoints
10430 for a given executable. */
10432 struct exception_support_info
10434 /* The name of the symbol to break on in order to insert
10435 a catchpoint on exceptions. */
10436 const char *catch_exception_sym;
10438 /* The name of the symbol to break on in order to insert
10439 a catchpoint on unhandled exceptions. */
10440 const char *catch_exception_unhandled_sym;
10442 /* The name of the symbol to break on in order to insert
10443 a catchpoint on failed assertions. */
10444 const char *catch_assert_sym;
10446 /* Assuming that the inferior just triggered an unhandled exception
10447 catchpoint, this function is responsible for returning the address
10448 in inferior memory where the name of that exception is stored.
10449 Return zero if the address could not be computed. */
10450 ada_unhandled_exception_name_addr_ftype *unhandled_exception_name_addr;
10453 static CORE_ADDR ada_unhandled_exception_name_addr (void);
10454 static CORE_ADDR ada_unhandled_exception_name_addr_from_raise (void);
10456 /* The following exception support info structure describes how to
10457 implement exception catchpoints with the latest version of the
10458 Ada runtime (as of 2007-03-06). */
10460 static const struct exception_support_info default_exception_support_info =
10462 "__gnat_debug_raise_exception", /* catch_exception_sym */
10463 "__gnat_unhandled_exception", /* catch_exception_unhandled_sym */
10464 "__gnat_debug_raise_assert_failure", /* catch_assert_sym */
10465 ada_unhandled_exception_name_addr
10468 /* The following exception support info structure describes how to
10469 implement exception catchpoints with a slightly older version
10470 of the Ada runtime. */
10472 static const struct exception_support_info exception_support_info_fallback =
10474 "__gnat_raise_nodefer_with_msg", /* catch_exception_sym */
10475 "__gnat_unhandled_exception", /* catch_exception_unhandled_sym */
10476 "system__assertions__raise_assert_failure", /* catch_assert_sym */
10477 ada_unhandled_exception_name_addr_from_raise
10480 /* For each executable, we sniff which exception info structure to use
10481 and cache it in the following global variable. */
10483 static const struct exception_support_info *exception_info = NULL;
10485 /* Inspect the Ada runtime and determine which exception info structure
10486 should be used to provide support for exception catchpoints.
10488 This function will always set exception_info, or raise an error. */
10491 ada_exception_support_info_sniffer (void)
10493 struct symbol *sym;
10495 /* If the exception info is already known, then no need to recompute it. */
10496 if (exception_info != NULL)
10499 /* Check the latest (default) exception support info. */
10500 sym = standard_lookup (default_exception_support_info.catch_exception_sym,
10504 exception_info = &default_exception_support_info;
10508 /* Try our fallback exception suport info. */
10509 sym = standard_lookup (exception_support_info_fallback.catch_exception_sym,
10513 exception_info = &exception_support_info_fallback;
10517 /* Sometimes, it is normal for us to not be able to find the routine
10518 we are looking for. This happens when the program is linked with
10519 the shared version of the GNAT runtime, and the program has not been
10520 started yet. Inform the user of these two possible causes if
10523 if (ada_update_initial_language (language_unknown) != language_ada)
10524 error (_("Unable to insert catchpoint. Is this an Ada main program?"));
10526 /* If the symbol does not exist, then check that the program is
10527 already started, to make sure that shared libraries have been
10528 loaded. If it is not started, this may mean that the symbol is
10529 in a shared library. */
10531 if (ptid_get_pid (inferior_ptid) == 0)
10532 error (_("Unable to insert catchpoint. Try to start the program first."));
10534 /* At this point, we know that we are debugging an Ada program and
10535 that the inferior has been started, but we still are not able to
10536 find the run-time symbols. That can mean that we are in
10537 configurable run time mode, or that a-except as been optimized
10538 out by the linker... In any case, at this point it is not worth
10539 supporting this feature. */
10541 error (_("Cannot insert catchpoints in this configuration."));
10544 /* An observer of "executable_changed" events.
10545 Its role is to clear certain cached values that need to be recomputed
10546 each time a new executable is loaded by GDB. */
10549 ada_executable_changed_observer (void)
10551 /* If the executable changed, then it is possible that the Ada runtime
10552 is different. So we need to invalidate the exception support info
10554 exception_info = NULL;
10557 /* True iff FRAME is very likely to be that of a function that is
10558 part of the runtime system. This is all very heuristic, but is
10559 intended to be used as advice as to what frames are uninteresting
10563 is_known_support_routine (struct frame_info *frame)
10565 struct symtab_and_line sal;
10567 enum language func_lang;
10570 /* If this code does not have any debugging information (no symtab),
10571 This cannot be any user code. */
10573 find_frame_sal (frame, &sal);
10574 if (sal.symtab == NULL)
10577 /* If there is a symtab, but the associated source file cannot be
10578 located, then assume this is not user code: Selecting a frame
10579 for which we cannot display the code would not be very helpful
10580 for the user. This should also take care of case such as VxWorks
10581 where the kernel has some debugging info provided for a few units. */
10583 if (symtab_to_fullname (sal.symtab) == NULL)
10586 /* Check the unit filename againt the Ada runtime file naming.
10587 We also check the name of the objfile against the name of some
10588 known system libraries that sometimes come with debugging info
10591 for (i = 0; known_runtime_file_name_patterns[i] != NULL; i += 1)
10593 re_comp (known_runtime_file_name_patterns[i]);
10594 if (re_exec (sal.symtab->filename))
10596 if (sal.symtab->objfile != NULL
10597 && re_exec (sal.symtab->objfile->name))
10601 /* Check whether the function is a GNAT-generated entity. */
10603 find_frame_funname (frame, &func_name, &func_lang, NULL);
10604 if (func_name == NULL)
10607 for (i = 0; known_auxiliary_function_name_patterns[i] != NULL; i += 1)
10609 re_comp (known_auxiliary_function_name_patterns[i]);
10610 if (re_exec (func_name))
10617 /* Find the first frame that contains debugging information and that is not
10618 part of the Ada run-time, starting from FI and moving upward. */
10621 ada_find_printable_frame (struct frame_info *fi)
10623 for (; fi != NULL; fi = get_prev_frame (fi))
10625 if (!is_known_support_routine (fi))
10634 /* Assuming that the inferior just triggered an unhandled exception
10635 catchpoint, return the address in inferior memory where the name
10636 of the exception is stored.
10638 Return zero if the address could not be computed. */
10641 ada_unhandled_exception_name_addr (void)
10643 return parse_and_eval_address ("e.full_name");
10646 /* Same as ada_unhandled_exception_name_addr, except that this function
10647 should be used when the inferior uses an older version of the runtime,
10648 where the exception name needs to be extracted from a specific frame
10649 several frames up in the callstack. */
10652 ada_unhandled_exception_name_addr_from_raise (void)
10655 struct frame_info *fi;
10657 /* To determine the name of this exception, we need to select
10658 the frame corresponding to RAISE_SYM_NAME. This frame is
10659 at least 3 levels up, so we simply skip the first 3 frames
10660 without checking the name of their associated function. */
10661 fi = get_current_frame ();
10662 for (frame_level = 0; frame_level < 3; frame_level += 1)
10664 fi = get_prev_frame (fi);
10669 enum language func_lang;
10671 find_frame_funname (fi, &func_name, &func_lang, NULL);
10672 if (func_name != NULL
10673 && strcmp (func_name, exception_info->catch_exception_sym) == 0)
10674 break; /* We found the frame we were looking for... */
10675 fi = get_prev_frame (fi);
10682 return parse_and_eval_address ("id.full_name");
10685 /* Assuming the inferior just triggered an Ada exception catchpoint
10686 (of any type), return the address in inferior memory where the name
10687 of the exception is stored, if applicable.
10689 Return zero if the address could not be computed, or if not relevant. */
10692 ada_exception_name_addr_1 (enum exception_catchpoint_kind ex,
10693 struct breakpoint *b)
10697 case ex_catch_exception:
10698 return (parse_and_eval_address ("e.full_name"));
10701 case ex_catch_exception_unhandled:
10702 return exception_info->unhandled_exception_name_addr ();
10705 case ex_catch_assert:
10706 return 0; /* Exception name is not relevant in this case. */
10710 internal_error (__FILE__, __LINE__, _("unexpected catchpoint type"));
10714 return 0; /* Should never be reached. */
10717 /* Same as ada_exception_name_addr_1, except that it intercepts and contains
10718 any error that ada_exception_name_addr_1 might cause to be thrown.
10719 When an error is intercepted, a warning with the error message is printed,
10720 and zero is returned. */
10723 ada_exception_name_addr (enum exception_catchpoint_kind ex,
10724 struct breakpoint *b)
10726 struct gdb_exception e;
10727 CORE_ADDR result = 0;
10729 TRY_CATCH (e, RETURN_MASK_ERROR)
10731 result = ada_exception_name_addr_1 (ex, b);
10736 warning (_("failed to get exception name: %s"), e.message);
10743 /* Implement the PRINT_IT method in the breakpoint_ops structure
10744 for all exception catchpoint kinds. */
10746 static enum print_stop_action
10747 print_it_exception (enum exception_catchpoint_kind ex, struct breakpoint *b)
10749 annotate_catchpoint (b->number);
10751 if (ui_out_is_mi_like_p (uiout))
10753 ui_out_field_string (uiout, "reason",
10754 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
10755 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
10758 ui_out_text (uiout, "\nCatchpoint ");
10759 ui_out_field_int (uiout, "bkptno", b->number);
10760 ui_out_text (uiout, ", ");
10764 case ex_catch_exception:
10765 case ex_catch_exception_unhandled:
10767 const CORE_ADDR addr = ada_exception_name_addr (ex, b);
10768 char exception_name[256];
10772 read_memory (addr, exception_name, sizeof (exception_name) - 1);
10773 exception_name [sizeof (exception_name) - 1] = '\0';
10777 /* For some reason, we were unable to read the exception
10778 name. This could happen if the Runtime was compiled
10779 without debugging info, for instance. In that case,
10780 just replace the exception name by the generic string
10781 "exception" - it will read as "an exception" in the
10782 notification we are about to print. */
10783 sprintf (exception_name, "exception");
10785 /* In the case of unhandled exception breakpoints, we print
10786 the exception name as "unhandled EXCEPTION_NAME", to make
10787 it clearer to the user which kind of catchpoint just got
10788 hit. We used ui_out_text to make sure that this extra
10789 info does not pollute the exception name in the MI case. */
10790 if (ex == ex_catch_exception_unhandled)
10791 ui_out_text (uiout, "unhandled ");
10792 ui_out_field_string (uiout, "exception-name", exception_name);
10795 case ex_catch_assert:
10796 /* In this case, the name of the exception is not really
10797 important. Just print "failed assertion" to make it clearer
10798 that his program just hit an assertion-failure catchpoint.
10799 We used ui_out_text because this info does not belong in
10801 ui_out_text (uiout, "failed assertion");
10804 ui_out_text (uiout, " at ");
10805 ada_find_printable_frame (get_current_frame ());
10807 return PRINT_SRC_AND_LOC;
10810 /* Implement the PRINT_ONE method in the breakpoint_ops structure
10811 for all exception catchpoint kinds. */
10814 print_one_exception (enum exception_catchpoint_kind ex,
10815 struct breakpoint *b, struct bp_location **last_loc)
10817 struct value_print_options opts;
10819 get_user_print_options (&opts);
10820 if (opts.addressprint)
10822 annotate_field (4);
10823 ui_out_field_core_addr (uiout, "addr", b->loc->gdbarch, b->loc->address);
10826 annotate_field (5);
10827 *last_loc = b->loc;
10830 case ex_catch_exception:
10831 if (b->exp_string != NULL)
10833 char *msg = xstrprintf (_("`%s' Ada exception"), b->exp_string);
10835 ui_out_field_string (uiout, "what", msg);
10839 ui_out_field_string (uiout, "what", "all Ada exceptions");
10843 case ex_catch_exception_unhandled:
10844 ui_out_field_string (uiout, "what", "unhandled Ada exceptions");
10847 case ex_catch_assert:
10848 ui_out_field_string (uiout, "what", "failed Ada assertions");
10852 internal_error (__FILE__, __LINE__, _("unexpected catchpoint type"));
10857 /* Implement the PRINT_MENTION method in the breakpoint_ops structure
10858 for all exception catchpoint kinds. */
10861 print_mention_exception (enum exception_catchpoint_kind ex,
10862 struct breakpoint *b)
10866 case ex_catch_exception:
10867 if (b->exp_string != NULL)
10868 printf_filtered (_("Catchpoint %d: `%s' Ada exception"),
10869 b->number, b->exp_string);
10871 printf_filtered (_("Catchpoint %d: all Ada exceptions"), b->number);
10875 case ex_catch_exception_unhandled:
10876 printf_filtered (_("Catchpoint %d: unhandled Ada exceptions"),
10880 case ex_catch_assert:
10881 printf_filtered (_("Catchpoint %d: failed Ada assertions"), b->number);
10885 internal_error (__FILE__, __LINE__, _("unexpected catchpoint type"));
10890 /* Implement the PRINT_RECREATE method in the breakpoint_ops structure
10891 for all exception catchpoint kinds. */
10894 print_recreate_exception (enum exception_catchpoint_kind ex,
10895 struct breakpoint *b, struct ui_file *fp)
10899 case ex_catch_exception:
10900 fprintf_filtered (fp, "catch exception");
10901 if (b->exp_string != NULL)
10902 fprintf_filtered (fp, " %s", b->exp_string);
10905 case ex_catch_exception_unhandled:
10906 fprintf_filtered (fp, "catch exception unhandled");
10909 case ex_catch_assert:
10910 fprintf_filtered (fp, "catch assert");
10914 internal_error (__FILE__, __LINE__, _("unexpected catchpoint type"));
10918 /* Virtual table for "catch exception" breakpoints. */
10920 static enum print_stop_action
10921 print_it_catch_exception (struct breakpoint *b)
10923 return print_it_exception (ex_catch_exception, b);
10927 print_one_catch_exception (struct breakpoint *b, struct bp_location **last_loc)
10929 print_one_exception (ex_catch_exception, b, last_loc);
10933 print_mention_catch_exception (struct breakpoint *b)
10935 print_mention_exception (ex_catch_exception, b);
10939 print_recreate_catch_exception (struct breakpoint *b, struct ui_file *fp)
10941 print_recreate_exception (ex_catch_exception, b, fp);
10944 static struct breakpoint_ops catch_exception_breakpoint_ops =
10948 NULL, /* breakpoint_hit */
10949 NULL, /* resources_needed */
10950 print_it_catch_exception,
10951 print_one_catch_exception,
10952 NULL, /* print_one_detail */
10953 print_mention_catch_exception,
10954 print_recreate_catch_exception
10957 /* Virtual table for "catch exception unhandled" breakpoints. */
10959 static enum print_stop_action
10960 print_it_catch_exception_unhandled (struct breakpoint *b)
10962 return print_it_exception (ex_catch_exception_unhandled, b);
10966 print_one_catch_exception_unhandled (struct breakpoint *b,
10967 struct bp_location **last_loc)
10969 print_one_exception (ex_catch_exception_unhandled, b, last_loc);
10973 print_mention_catch_exception_unhandled (struct breakpoint *b)
10975 print_mention_exception (ex_catch_exception_unhandled, b);
10979 print_recreate_catch_exception_unhandled (struct breakpoint *b,
10980 struct ui_file *fp)
10982 print_recreate_exception (ex_catch_exception_unhandled, b, fp);
10985 static struct breakpoint_ops catch_exception_unhandled_breakpoint_ops = {
10988 NULL, /* breakpoint_hit */
10989 NULL, /* resources_needed */
10990 print_it_catch_exception_unhandled,
10991 print_one_catch_exception_unhandled,
10992 NULL, /* print_one_detail */
10993 print_mention_catch_exception_unhandled,
10994 print_recreate_catch_exception_unhandled
10997 /* Virtual table for "catch assert" breakpoints. */
10999 static enum print_stop_action
11000 print_it_catch_assert (struct breakpoint *b)
11002 return print_it_exception (ex_catch_assert, b);
11006 print_one_catch_assert (struct breakpoint *b, struct bp_location **last_loc)
11008 print_one_exception (ex_catch_assert, b, last_loc);
11012 print_mention_catch_assert (struct breakpoint *b)
11014 print_mention_exception (ex_catch_assert, b);
11018 print_recreate_catch_assert (struct breakpoint *b, struct ui_file *fp)
11020 print_recreate_exception (ex_catch_assert, b, fp);
11023 static struct breakpoint_ops catch_assert_breakpoint_ops = {
11026 NULL, /* breakpoint_hit */
11027 NULL, /* resources_needed */
11028 print_it_catch_assert,
11029 print_one_catch_assert,
11030 NULL, /* print_one_detail */
11031 print_mention_catch_assert,
11032 print_recreate_catch_assert
11035 /* Return non-zero if B is an Ada exception catchpoint. */
11038 ada_exception_catchpoint_p (struct breakpoint *b)
11040 return (b->ops == &catch_exception_breakpoint_ops
11041 || b->ops == &catch_exception_unhandled_breakpoint_ops
11042 || b->ops == &catch_assert_breakpoint_ops);
11045 /* Return a newly allocated copy of the first space-separated token
11046 in ARGSP, and then adjust ARGSP to point immediately after that
11049 Return NULL if ARGPS does not contain any more tokens. */
11052 ada_get_next_arg (char **argsp)
11054 char *args = *argsp;
11058 /* Skip any leading white space. */
11060 while (isspace (*args))
11063 if (args[0] == '\0')
11064 return NULL; /* No more arguments. */
11066 /* Find the end of the current argument. */
11069 while (*end != '\0' && !isspace (*end))
11072 /* Adjust ARGSP to point to the start of the next argument. */
11076 /* Make a copy of the current argument and return it. */
11078 result = xmalloc (end - args + 1);
11079 strncpy (result, args, end - args);
11080 result[end - args] = '\0';
11085 /* Split the arguments specified in a "catch exception" command.
11086 Set EX to the appropriate catchpoint type.
11087 Set EXP_STRING to the name of the specific exception if
11088 specified by the user. */
11091 catch_ada_exception_command_split (char *args,
11092 enum exception_catchpoint_kind *ex,
11095 struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
11096 char *exception_name;
11098 exception_name = ada_get_next_arg (&args);
11099 make_cleanup (xfree, exception_name);
11101 /* Check that we do not have any more arguments. Anything else
11104 while (isspace (*args))
11107 if (args[0] != '\0')
11108 error (_("Junk at end of expression"));
11110 discard_cleanups (old_chain);
11112 if (exception_name == NULL)
11114 /* Catch all exceptions. */
11115 *ex = ex_catch_exception;
11116 *exp_string = NULL;
11118 else if (strcmp (exception_name, "unhandled") == 0)
11120 /* Catch unhandled exceptions. */
11121 *ex = ex_catch_exception_unhandled;
11122 *exp_string = NULL;
11126 /* Catch a specific exception. */
11127 *ex = ex_catch_exception;
11128 *exp_string = exception_name;
11132 /* Return the name of the symbol on which we should break in order to
11133 implement a catchpoint of the EX kind. */
11135 static const char *
11136 ada_exception_sym_name (enum exception_catchpoint_kind ex)
11138 gdb_assert (exception_info != NULL);
11142 case ex_catch_exception:
11143 return (exception_info->catch_exception_sym);
11145 case ex_catch_exception_unhandled:
11146 return (exception_info->catch_exception_unhandled_sym);
11148 case ex_catch_assert:
11149 return (exception_info->catch_assert_sym);
11152 internal_error (__FILE__, __LINE__,
11153 _("unexpected catchpoint kind (%d)"), ex);
11157 /* Return the breakpoint ops "virtual table" used for catchpoints
11160 static struct breakpoint_ops *
11161 ada_exception_breakpoint_ops (enum exception_catchpoint_kind ex)
11165 case ex_catch_exception:
11166 return (&catch_exception_breakpoint_ops);
11168 case ex_catch_exception_unhandled:
11169 return (&catch_exception_unhandled_breakpoint_ops);
11171 case ex_catch_assert:
11172 return (&catch_assert_breakpoint_ops);
11175 internal_error (__FILE__, __LINE__,
11176 _("unexpected catchpoint kind (%d)"), ex);
11180 /* Return the condition that will be used to match the current exception
11181 being raised with the exception that the user wants to catch. This
11182 assumes that this condition is used when the inferior just triggered
11183 an exception catchpoint.
11185 The string returned is a newly allocated string that needs to be
11186 deallocated later. */
11189 ada_exception_catchpoint_cond_string (const char *exp_string)
11193 /* The standard exceptions are a special case. They are defined in
11194 runtime units that have been compiled without debugging info; if
11195 EXP_STRING is the not-fully-qualified name of a standard
11196 exception (e.g. "constraint_error") then, during the evaluation
11197 of the condition expression, the symbol lookup on this name would
11198 *not* return this standard exception. The catchpoint condition
11199 may then be set only on user-defined exceptions which have the
11200 same not-fully-qualified name (e.g. my_package.constraint_error).
11202 To avoid this unexcepted behavior, these standard exceptions are
11203 systematically prefixed by "standard". This means that "catch
11204 exception constraint_error" is rewritten into "catch exception
11205 standard.constraint_error".
11207 If an exception named contraint_error is defined in another package of
11208 the inferior program, then the only way to specify this exception as a
11209 breakpoint condition is to use its fully-qualified named:
11210 e.g. my_package.constraint_error. */
11212 for (i = 0; i < sizeof (standard_exc) / sizeof (char *); i++)
11214 if (strcmp (standard_exc [i], exp_string) == 0)
11216 return xstrprintf ("long_integer (e) = long_integer (&standard.%s)",
11220 return xstrprintf ("long_integer (e) = long_integer (&%s)", exp_string);
11223 /* Return the expression corresponding to COND_STRING evaluated at SAL. */
11225 static struct expression *
11226 ada_parse_catchpoint_condition (char *cond_string,
11227 struct symtab_and_line sal)
11229 return (parse_exp_1 (&cond_string, block_for_pc (sal.pc), 0));
11232 /* Return the symtab_and_line that should be used to insert an exception
11233 catchpoint of the TYPE kind.
11235 EX_STRING should contain the name of a specific exception
11236 that the catchpoint should catch, or NULL otherwise.
11238 The idea behind all the remaining parameters is that their names match
11239 the name of certain fields in the breakpoint structure that are used to
11240 handle exception catchpoints. This function returns the value to which
11241 these fields should be set, depending on the type of catchpoint we need
11244 If COND and COND_STRING are both non-NULL, any value they might
11245 hold will be free'ed, and then replaced by newly allocated ones.
11246 These parameters are left untouched otherwise. */
11248 static struct symtab_and_line
11249 ada_exception_sal (enum exception_catchpoint_kind ex, char *exp_string,
11250 char **addr_string, char **cond_string,
11251 struct expression **cond, struct breakpoint_ops **ops)
11253 const char *sym_name;
11254 struct symbol *sym;
11255 struct symtab_and_line sal;
11257 /* First, find out which exception support info to use. */
11258 ada_exception_support_info_sniffer ();
11260 /* Then lookup the function on which we will break in order to catch
11261 the Ada exceptions requested by the user. */
11263 sym_name = ada_exception_sym_name (ex);
11264 sym = standard_lookup (sym_name, NULL, VAR_DOMAIN);
11266 /* The symbol we're looking up is provided by a unit in the GNAT runtime
11267 that should be compiled with debugging information. As a result, we
11268 expect to find that symbol in the symtabs. If we don't find it, then
11269 the target most likely does not support Ada exceptions, or we cannot
11270 insert exception breakpoints yet, because the GNAT runtime hasn't been
11273 /* brobecker/2006-12-26: It is conceivable that the runtime was compiled
11274 in such a way that no debugging information is produced for the symbol
11275 we are looking for. In this case, we could search the minimal symbols
11276 as a fall-back mechanism. This would still be operating in degraded
11277 mode, however, as we would still be missing the debugging information
11278 that is needed in order to extract the name of the exception being
11279 raised (this name is printed in the catchpoint message, and is also
11280 used when trying to catch a specific exception). We do not handle
11281 this case for now. */
11284 error (_("Unable to break on '%s' in this configuration."), sym_name);
11286 /* Make sure that the symbol we found corresponds to a function. */
11287 if (SYMBOL_CLASS (sym) != LOC_BLOCK)
11288 error (_("Symbol \"%s\" is not a function (class = %d)"),
11289 sym_name, SYMBOL_CLASS (sym));
11291 sal = find_function_start_sal (sym, 1);
11293 /* Set ADDR_STRING. */
11295 *addr_string = xstrdup (sym_name);
11297 /* Set the COND and COND_STRING (if not NULL). */
11299 if (cond_string != NULL && cond != NULL)
11301 if (*cond_string != NULL)
11303 xfree (*cond_string);
11304 *cond_string = NULL;
11311 if (exp_string != NULL)
11313 *cond_string = ada_exception_catchpoint_cond_string (exp_string);
11314 *cond = ada_parse_catchpoint_condition (*cond_string, sal);
11319 *ops = ada_exception_breakpoint_ops (ex);
11324 /* Parse the arguments (ARGS) of the "catch exception" command.
11326 Set TYPE to the appropriate exception catchpoint type.
11327 If the user asked the catchpoint to catch only a specific
11328 exception, then save the exception name in ADDR_STRING.
11330 See ada_exception_sal for a description of all the remaining
11331 function arguments of this function. */
11333 struct symtab_and_line
11334 ada_decode_exception_location (char *args, char **addr_string,
11335 char **exp_string, char **cond_string,
11336 struct expression **cond,
11337 struct breakpoint_ops **ops)
11339 enum exception_catchpoint_kind ex;
11341 catch_ada_exception_command_split (args, &ex, exp_string);
11342 return ada_exception_sal (ex, *exp_string, addr_string, cond_string,
11346 struct symtab_and_line
11347 ada_decode_assert_location (char *args, char **addr_string,
11348 struct breakpoint_ops **ops)
11350 /* Check that no argument where provided at the end of the command. */
11354 while (isspace (*args))
11357 error (_("Junk at end of arguments."));
11360 return ada_exception_sal (ex_catch_assert, NULL, addr_string, NULL, NULL,
11365 /* Information about operators given special treatment in functions
11367 /* Format: OP_DEFN (<operator>, <operator length>, <# args>, <binop>). */
11369 #define ADA_OPERATORS \
11370 OP_DEFN (OP_VAR_VALUE, 4, 0, 0) \
11371 OP_DEFN (BINOP_IN_BOUNDS, 3, 2, 0) \
11372 OP_DEFN (TERNOP_IN_RANGE, 1, 3, 0) \
11373 OP_DEFN (OP_ATR_FIRST, 1, 2, 0) \
11374 OP_DEFN (OP_ATR_LAST, 1, 2, 0) \
11375 OP_DEFN (OP_ATR_LENGTH, 1, 2, 0) \
11376 OP_DEFN (OP_ATR_IMAGE, 1, 2, 0) \
11377 OP_DEFN (OP_ATR_MAX, 1, 3, 0) \
11378 OP_DEFN (OP_ATR_MIN, 1, 3, 0) \
11379 OP_DEFN (OP_ATR_MODULUS, 1, 1, 0) \
11380 OP_DEFN (OP_ATR_POS, 1, 2, 0) \
11381 OP_DEFN (OP_ATR_SIZE, 1, 1, 0) \
11382 OP_DEFN (OP_ATR_TAG, 1, 1, 0) \
11383 OP_DEFN (OP_ATR_VAL, 1, 2, 0) \
11384 OP_DEFN (UNOP_QUAL, 3, 1, 0) \
11385 OP_DEFN (UNOP_IN_RANGE, 3, 1, 0) \
11386 OP_DEFN (OP_OTHERS, 1, 1, 0) \
11387 OP_DEFN (OP_POSITIONAL, 3, 1, 0) \
11388 OP_DEFN (OP_DISCRETE_RANGE, 1, 2, 0)
11391 ada_operator_length (const struct expression *exp, int pc, int *oplenp,
11394 switch (exp->elts[pc - 1].opcode)
11397 operator_length_standard (exp, pc, oplenp, argsp);
11400 #define OP_DEFN(op, len, args, binop) \
11401 case op: *oplenp = len; *argsp = args; break;
11407 *argsp = longest_to_int (exp->elts[pc - 2].longconst);
11412 *argsp = longest_to_int (exp->elts[pc - 2].longconst) + 1;
11417 /* Implementation of the exp_descriptor method operator_check. */
11420 ada_operator_check (struct expression *exp, int pos,
11421 int (*objfile_func) (struct objfile *objfile, void *data),
11424 const union exp_element *const elts = exp->elts;
11425 struct type *type = NULL;
11427 switch (elts[pos].opcode)
11429 case UNOP_IN_RANGE:
11431 type = elts[pos + 1].type;
11435 return operator_check_standard (exp, pos, objfile_func, data);
11438 /* Invoke callbacks for TYPE and OBJFILE if they were set as non-NULL. */
11440 if (type && TYPE_OBJFILE (type)
11441 && (*objfile_func) (TYPE_OBJFILE (type), data))
11448 ada_op_name (enum exp_opcode opcode)
11453 return op_name_standard (opcode);
11455 #define OP_DEFN(op, len, args, binop) case op: return #op;
11460 return "OP_AGGREGATE";
11462 return "OP_CHOICES";
11468 /* As for operator_length, but assumes PC is pointing at the first
11469 element of the operator, and gives meaningful results only for the
11470 Ada-specific operators, returning 0 for *OPLENP and *ARGSP otherwise. */
11473 ada_forward_operator_length (struct expression *exp, int pc,
11474 int *oplenp, int *argsp)
11476 switch (exp->elts[pc].opcode)
11479 *oplenp = *argsp = 0;
11482 #define OP_DEFN(op, len, args, binop) \
11483 case op: *oplenp = len; *argsp = args; break;
11489 *argsp = longest_to_int (exp->elts[pc + 1].longconst);
11494 *argsp = longest_to_int (exp->elts[pc + 1].longconst) + 1;
11500 int len = longest_to_int (exp->elts[pc + 1].longconst);
11502 *oplenp = 4 + BYTES_TO_EXP_ELEM (len + 1);
11510 ada_dump_subexp_body (struct expression *exp, struct ui_file *stream, int elt)
11512 enum exp_opcode op = exp->elts[elt].opcode;
11517 ada_forward_operator_length (exp, elt, &oplen, &nargs);
11521 /* Ada attributes ('Foo). */
11524 case OP_ATR_LENGTH:
11528 case OP_ATR_MODULUS:
11535 case UNOP_IN_RANGE:
11537 /* XXX: gdb_sprint_host_address, type_sprint */
11538 fprintf_filtered (stream, _("Type @"));
11539 gdb_print_host_address (exp->elts[pc + 1].type, stream);
11540 fprintf_filtered (stream, " (");
11541 type_print (exp->elts[pc + 1].type, NULL, stream, 0);
11542 fprintf_filtered (stream, ")");
11544 case BINOP_IN_BOUNDS:
11545 fprintf_filtered (stream, " (%d)",
11546 longest_to_int (exp->elts[pc + 2].longconst));
11548 case TERNOP_IN_RANGE:
11553 case OP_DISCRETE_RANGE:
11554 case OP_POSITIONAL:
11561 char *name = &exp->elts[elt + 2].string;
11562 int len = longest_to_int (exp->elts[elt + 1].longconst);
11564 fprintf_filtered (stream, "Text: `%.*s'", len, name);
11569 return dump_subexp_body_standard (exp, stream, elt);
11573 for (i = 0; i < nargs; i += 1)
11574 elt = dump_subexp (exp, stream, elt);
11579 /* The Ada extension of print_subexp (q.v.). */
11582 ada_print_subexp (struct expression *exp, int *pos,
11583 struct ui_file *stream, enum precedence prec)
11585 int oplen, nargs, i;
11587 enum exp_opcode op = exp->elts[pc].opcode;
11589 ada_forward_operator_length (exp, pc, &oplen, &nargs);
11596 print_subexp_standard (exp, pos, stream, prec);
11600 fputs_filtered (SYMBOL_NATURAL_NAME (exp->elts[pc + 2].symbol), stream);
11603 case BINOP_IN_BOUNDS:
11604 /* XXX: sprint_subexp */
11605 print_subexp (exp, pos, stream, PREC_SUFFIX);
11606 fputs_filtered (" in ", stream);
11607 print_subexp (exp, pos, stream, PREC_SUFFIX);
11608 fputs_filtered ("'range", stream);
11609 if (exp->elts[pc + 1].longconst > 1)
11610 fprintf_filtered (stream, "(%ld)",
11611 (long) exp->elts[pc + 1].longconst);
11614 case TERNOP_IN_RANGE:
11615 if (prec >= PREC_EQUAL)
11616 fputs_filtered ("(", stream);
11617 /* XXX: sprint_subexp */
11618 print_subexp (exp, pos, stream, PREC_SUFFIX);
11619 fputs_filtered (" in ", stream);
11620 print_subexp (exp, pos, stream, PREC_EQUAL);
11621 fputs_filtered (" .. ", stream);
11622 print_subexp (exp, pos, stream, PREC_EQUAL);
11623 if (prec >= PREC_EQUAL)
11624 fputs_filtered (")", stream);
11629 case OP_ATR_LENGTH:
11633 case OP_ATR_MODULUS:
11638 if (exp->elts[*pos].opcode == OP_TYPE)
11640 if (TYPE_CODE (exp->elts[*pos + 1].type) != TYPE_CODE_VOID)
11641 LA_PRINT_TYPE (exp->elts[*pos + 1].type, "", stream, 0, 0);
11645 print_subexp (exp, pos, stream, PREC_SUFFIX);
11646 fprintf_filtered (stream, "'%s", ada_attribute_name (op));
11651 for (tem = 1; tem < nargs; tem += 1)
11653 fputs_filtered ((tem == 1) ? " (" : ", ", stream);
11654 print_subexp (exp, pos, stream, PREC_ABOVE_COMMA);
11656 fputs_filtered (")", stream);
11661 type_print (exp->elts[pc + 1].type, "", stream, 0);
11662 fputs_filtered ("'(", stream);
11663 print_subexp (exp, pos, stream, PREC_PREFIX);
11664 fputs_filtered (")", stream);
11667 case UNOP_IN_RANGE:
11668 /* XXX: sprint_subexp */
11669 print_subexp (exp, pos, stream, PREC_SUFFIX);
11670 fputs_filtered (" in ", stream);
11671 LA_PRINT_TYPE (exp->elts[pc + 1].type, "", stream, 1, 0);
11674 case OP_DISCRETE_RANGE:
11675 print_subexp (exp, pos, stream, PREC_SUFFIX);
11676 fputs_filtered ("..", stream);
11677 print_subexp (exp, pos, stream, PREC_SUFFIX);
11681 fputs_filtered ("others => ", stream);
11682 print_subexp (exp, pos, stream, PREC_SUFFIX);
11686 for (i = 0; i < nargs-1; i += 1)
11689 fputs_filtered ("|", stream);
11690 print_subexp (exp, pos, stream, PREC_SUFFIX);
11692 fputs_filtered (" => ", stream);
11693 print_subexp (exp, pos, stream, PREC_SUFFIX);
11696 case OP_POSITIONAL:
11697 print_subexp (exp, pos, stream, PREC_SUFFIX);
11701 fputs_filtered ("(", stream);
11702 for (i = 0; i < nargs; i += 1)
11705 fputs_filtered (", ", stream);
11706 print_subexp (exp, pos, stream, PREC_SUFFIX);
11708 fputs_filtered (")", stream);
11713 /* Table mapping opcodes into strings for printing operators
11714 and precedences of the operators. */
11716 static const struct op_print ada_op_print_tab[] = {
11717 {":=", BINOP_ASSIGN, PREC_ASSIGN, 1},
11718 {"or else", BINOP_LOGICAL_OR, PREC_LOGICAL_OR, 0},
11719 {"and then", BINOP_LOGICAL_AND, PREC_LOGICAL_AND, 0},
11720 {"or", BINOP_BITWISE_IOR, PREC_BITWISE_IOR, 0},
11721 {"xor", BINOP_BITWISE_XOR, PREC_BITWISE_XOR, 0},
11722 {"and", BINOP_BITWISE_AND, PREC_BITWISE_AND, 0},
11723 {"=", BINOP_EQUAL, PREC_EQUAL, 0},
11724 {"/=", BINOP_NOTEQUAL, PREC_EQUAL, 0},
11725 {"<=", BINOP_LEQ, PREC_ORDER, 0},
11726 {">=", BINOP_GEQ, PREC_ORDER, 0},
11727 {">", BINOP_GTR, PREC_ORDER, 0},
11728 {"<", BINOP_LESS, PREC_ORDER, 0},
11729 {">>", BINOP_RSH, PREC_SHIFT, 0},
11730 {"<<", BINOP_LSH, PREC_SHIFT, 0},
11731 {"+", BINOP_ADD, PREC_ADD, 0},
11732 {"-", BINOP_SUB, PREC_ADD, 0},
11733 {"&", BINOP_CONCAT, PREC_ADD, 0},
11734 {"*", BINOP_MUL, PREC_MUL, 0},
11735 {"/", BINOP_DIV, PREC_MUL, 0},
11736 {"rem", BINOP_REM, PREC_MUL, 0},
11737 {"mod", BINOP_MOD, PREC_MUL, 0},
11738 {"**", BINOP_EXP, PREC_REPEAT, 0},
11739 {"@", BINOP_REPEAT, PREC_REPEAT, 0},
11740 {"-", UNOP_NEG, PREC_PREFIX, 0},
11741 {"+", UNOP_PLUS, PREC_PREFIX, 0},
11742 {"not ", UNOP_LOGICAL_NOT, PREC_PREFIX, 0},
11743 {"not ", UNOP_COMPLEMENT, PREC_PREFIX, 0},
11744 {"abs ", UNOP_ABS, PREC_PREFIX, 0},
11745 {".all", UNOP_IND, PREC_SUFFIX, 1},
11746 {"'access", UNOP_ADDR, PREC_SUFFIX, 1},
11747 {"'size", OP_ATR_SIZE, PREC_SUFFIX, 1},
11751 enum ada_primitive_types {
11752 ada_primitive_type_int,
11753 ada_primitive_type_long,
11754 ada_primitive_type_short,
11755 ada_primitive_type_char,
11756 ada_primitive_type_float,
11757 ada_primitive_type_double,
11758 ada_primitive_type_void,
11759 ada_primitive_type_long_long,
11760 ada_primitive_type_long_double,
11761 ada_primitive_type_natural,
11762 ada_primitive_type_positive,
11763 ada_primitive_type_system_address,
11764 nr_ada_primitive_types
11768 ada_language_arch_info (struct gdbarch *gdbarch,
11769 struct language_arch_info *lai)
11771 const struct builtin_type *builtin = builtin_type (gdbarch);
11773 lai->primitive_type_vector
11774 = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_ada_primitive_types + 1,
11777 lai->primitive_type_vector [ada_primitive_type_int]
11778 = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
11780 lai->primitive_type_vector [ada_primitive_type_long]
11781 = arch_integer_type (gdbarch, gdbarch_long_bit (gdbarch),
11782 0, "long_integer");
11783 lai->primitive_type_vector [ada_primitive_type_short]
11784 = arch_integer_type (gdbarch, gdbarch_short_bit (gdbarch),
11785 0, "short_integer");
11786 lai->string_char_type
11787 = lai->primitive_type_vector [ada_primitive_type_char]
11788 = arch_integer_type (gdbarch, TARGET_CHAR_BIT, 0, "character");
11789 lai->primitive_type_vector [ada_primitive_type_float]
11790 = arch_float_type (gdbarch, gdbarch_float_bit (gdbarch),
11792 lai->primitive_type_vector [ada_primitive_type_double]
11793 = arch_float_type (gdbarch, gdbarch_double_bit (gdbarch),
11794 "long_float", NULL);
11795 lai->primitive_type_vector [ada_primitive_type_long_long]
11796 = arch_integer_type (gdbarch, gdbarch_long_long_bit (gdbarch),
11797 0, "long_long_integer");
11798 lai->primitive_type_vector [ada_primitive_type_long_double]
11799 = arch_float_type (gdbarch, gdbarch_double_bit (gdbarch),
11800 "long_long_float", NULL);
11801 lai->primitive_type_vector [ada_primitive_type_natural]
11802 = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
11804 lai->primitive_type_vector [ada_primitive_type_positive]
11805 = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
11807 lai->primitive_type_vector [ada_primitive_type_void]
11808 = builtin->builtin_void;
11810 lai->primitive_type_vector [ada_primitive_type_system_address]
11811 = lookup_pointer_type (arch_type (gdbarch, TYPE_CODE_VOID, 1, "void"));
11812 TYPE_NAME (lai->primitive_type_vector [ada_primitive_type_system_address])
11813 = "system__address";
11815 lai->bool_type_symbol = NULL;
11816 lai->bool_type_default = builtin->builtin_bool;
11819 /* Language vector */
11821 /* Not really used, but needed in the ada_language_defn. */
11824 emit_char (int c, struct type *type, struct ui_file *stream, int quoter)
11826 ada_emit_char (c, type, stream, quoter, 1);
11832 warnings_issued = 0;
11833 return ada_parse ();
11836 static const struct exp_descriptor ada_exp_descriptor = {
11838 ada_operator_length,
11839 ada_operator_check,
11841 ada_dump_subexp_body,
11842 ada_evaluate_subexp
11845 const struct language_defn ada_language_defn = {
11846 "ada", /* Language name */
11850 case_sensitive_on, /* Yes, Ada is case-insensitive, but
11851 that's not quite what this means. */
11853 macro_expansion_no,
11854 &ada_exp_descriptor,
11858 ada_printchar, /* Print a character constant */
11859 ada_printstr, /* Function to print string constant */
11860 emit_char, /* Function to print single char (not used) */
11861 ada_print_type, /* Print a type using appropriate syntax */
11862 ada_print_typedef, /* Print a typedef using appropriate syntax */
11863 ada_val_print, /* Print a value using appropriate syntax */
11864 ada_value_print, /* Print a top-level value */
11865 NULL, /* Language specific skip_trampoline */
11866 NULL, /* name_of_this */
11867 ada_lookup_symbol_nonlocal, /* Looking up non-local symbols. */
11868 basic_lookup_transparent_type, /* lookup_transparent_type */
11869 ada_la_decode, /* Language specific symbol demangler */
11870 NULL, /* Language specific
11871 class_name_from_physname */
11872 ada_op_print_tab, /* expression operators for printing */
11873 0, /* c-style arrays */
11874 1, /* String lower bound */
11875 ada_get_gdb_completer_word_break_characters,
11876 ada_make_symbol_completion_list,
11877 ada_language_arch_info,
11878 ada_print_array_index,
11879 default_pass_by_reference,
11884 /* Provide a prototype to silence -Wmissing-prototypes. */
11885 extern initialize_file_ftype _initialize_ada_language;
11887 /* Command-list for the "set/show ada" prefix command. */
11888 static struct cmd_list_element *set_ada_list;
11889 static struct cmd_list_element *show_ada_list;
11891 /* Implement the "set ada" prefix command. */
11894 set_ada_command (char *arg, int from_tty)
11896 printf_unfiltered (_(\
11897 "\"set ada\" must be followed by the name of a setting.\n"));
11898 help_list (set_ada_list, "set ada ", -1, gdb_stdout);
11901 /* Implement the "show ada" prefix command. */
11904 show_ada_command (char *args, int from_tty)
11906 cmd_show_list (show_ada_list, from_tty, "");
11910 _initialize_ada_language (void)
11912 add_language (&ada_language_defn);
11914 add_prefix_cmd ("ada", no_class, set_ada_command,
11915 _("Prefix command for changing Ada-specfic settings"),
11916 &set_ada_list, "set ada ", 0, &setlist);
11918 add_prefix_cmd ("ada", no_class, show_ada_command,
11919 _("Generic command for showing Ada-specific settings."),
11920 &show_ada_list, "show ada ", 0, &showlist);
11922 add_setshow_boolean_cmd ("trust-PAD-over-XVS", class_obscure,
11923 &trust_pad_over_xvs, _("\
11924 Enable or disable an optimization trusting PAD types over XVS types"), _("\
11925 Show whether an optimization trusting PAD types over XVS types is activated"),
11927 This is related to the encoding used by the GNAT compiler. The debugger\n\
11928 should normally trust the contents of PAD types, but certain older versions\n\
11929 of GNAT have a bug that sometimes causes the information in the PAD type\n\
11930 to be incorrect. Turning this setting \"off\" allows the debugger to\n\
11931 work around this bug. It is always safe to turn this option \"off\", but\n\
11932 this incurs a slight performance penalty, so it is recommended to NOT change\n\
11933 this option to \"off\" unless necessary."),
11934 NULL, NULL, &set_ada_list, &show_ada_list);
11936 varsize_limit = 65536;
11938 obstack_init (&symbol_list_obstack);
11940 decoded_names_store = htab_create_alloc
11941 (256, htab_hash_string, (int (*)(const void *, const void *)) streq,
11942 NULL, xcalloc, xfree);
11944 observer_attach_executable_changed (ada_executable_changed_observer);
11946 /* Setup per-inferior data. */
11947 observer_attach_inferior_exit (ada_inferior_exit);
11949 = register_inferior_data_with_cleanup (ada_inferior_data_cleanup);