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"
64 /* Define whether or not the C operator '/' truncates towards zero for
65 differently signed operands (truncation direction is undefined in C).
66 Copied from valarith.c. */
68 #ifndef TRUNCATION_TOWARDS_ZERO
69 #define TRUNCATION_TOWARDS_ZERO ((-5 / 2) == -2)
72 static struct type *desc_base_type (struct type *);
74 static struct type *desc_bounds_type (struct type *);
76 static struct value *desc_bounds (struct value *);
78 static int fat_pntr_bounds_bitpos (struct type *);
80 static int fat_pntr_bounds_bitsize (struct type *);
82 static struct type *desc_data_target_type (struct type *);
84 static struct value *desc_data (struct value *);
86 static int fat_pntr_data_bitpos (struct type *);
88 static int fat_pntr_data_bitsize (struct type *);
90 static struct value *desc_one_bound (struct value *, int, int);
92 static int desc_bound_bitpos (struct type *, int, int);
94 static int desc_bound_bitsize (struct type *, int, int);
96 static struct type *desc_index_type (struct type *, int);
98 static int desc_arity (struct type *);
100 static int ada_type_match (struct type *, struct type *, int);
102 static int ada_args_match (struct symbol *, struct value **, int);
104 static int full_match (const char *, const char *);
106 static struct value *make_array_descriptor (struct type *, struct value *);
108 static void ada_add_block_symbols (struct obstack *,
109 struct block *, const char *,
110 domain_enum, struct objfile *, int);
112 static int is_nonfunction (struct ada_symbol_info *, int);
114 static void add_defn_to_vec (struct obstack *, struct symbol *,
117 static int num_defns_collected (struct obstack *);
119 static struct ada_symbol_info *defns_collected (struct obstack *, int);
121 static struct value *resolve_subexp (struct expression **, int *, int,
124 static void replace_operator_with_call (struct expression **, int, int, int,
125 struct symbol *, struct block *);
127 static int possible_user_operator_p (enum exp_opcode, struct value **);
129 static char *ada_op_name (enum exp_opcode);
131 static const char *ada_decoded_op_name (enum exp_opcode);
133 static int numeric_type_p (struct type *);
135 static int integer_type_p (struct type *);
137 static int scalar_type_p (struct type *);
139 static int discrete_type_p (struct type *);
141 static enum ada_renaming_category parse_old_style_renaming (struct type *,
146 static struct symbol *find_old_style_renaming_symbol (const char *,
149 static struct type *ada_lookup_struct_elt_type (struct type *, char *,
152 static struct value *evaluate_subexp_type (struct expression *, int *);
154 static struct type *ada_find_parallel_type_with_name (struct type *,
157 static int is_dynamic_field (struct type *, int);
159 static struct type *to_fixed_variant_branch_type (struct type *,
161 CORE_ADDR, struct value *);
163 static struct type *to_fixed_array_type (struct type *, struct value *, int);
165 static struct type *to_fixed_range_type (struct type *, struct value *);
167 static struct type *to_static_fixed_type (struct type *);
168 static struct type *static_unwrap_type (struct type *type);
170 static struct value *unwrap_value (struct value *);
172 static struct type *constrained_packed_array_type (struct type *, long *);
174 static struct type *decode_constrained_packed_array_type (struct type *);
176 static long decode_packed_array_bitsize (struct type *);
178 static struct value *decode_constrained_packed_array (struct value *);
180 static int ada_is_packed_array_type (struct type *);
182 static int ada_is_unconstrained_packed_array_type (struct type *);
184 static struct value *value_subscript_packed (struct value *, int,
187 static void move_bits (gdb_byte *, int, const gdb_byte *, int, int, int);
189 static struct value *coerce_unspec_val_to_type (struct value *,
192 static struct value *get_var_value (char *, char *);
194 static int lesseq_defined_than (struct symbol *, struct symbol *);
196 static int equiv_types (struct type *, struct type *);
198 static int is_name_suffix (const char *);
200 static int advance_wild_match (const char **, const char *, int);
202 static int wild_match (const char *, const char *);
204 static struct value *ada_coerce_ref (struct value *);
206 static LONGEST pos_atr (struct value *);
208 static struct value *value_pos_atr (struct type *, struct value *);
210 static struct value *value_val_atr (struct type *, struct value *);
212 static struct symbol *standard_lookup (const char *, const struct block *,
215 static struct value *ada_search_struct_field (char *, struct value *, int,
218 static struct value *ada_value_primitive_field (struct value *, int, int,
221 static int find_struct_field (char *, struct type *, int,
222 struct type **, int *, int *, int *, int *);
224 static struct value *ada_to_fixed_value_create (struct type *, CORE_ADDR,
227 static int ada_resolve_function (struct ada_symbol_info *, int,
228 struct value **, int, const char *,
231 static int ada_is_direct_array_type (struct type *);
233 static void ada_language_arch_info (struct gdbarch *,
234 struct language_arch_info *);
236 static void check_size (const struct type *);
238 static struct value *ada_index_struct_field (int, struct value *, int,
241 static struct value *assign_aggregate (struct value *, struct value *,
245 static void aggregate_assign_from_choices (struct value *, struct value *,
247 int *, LONGEST *, int *,
248 int, LONGEST, LONGEST);
250 static void aggregate_assign_positional (struct value *, struct value *,
252 int *, LONGEST *, int *, int,
256 static void aggregate_assign_others (struct value *, struct value *,
258 int *, LONGEST *, int, LONGEST, LONGEST);
261 static void add_component_interval (LONGEST, LONGEST, LONGEST *, int *, int);
264 static struct value *ada_evaluate_subexp (struct type *, struct expression *,
267 static void ada_forward_operator_length (struct expression *, int, int *,
272 /* Maximum-sized dynamic type. */
273 static unsigned int varsize_limit;
275 /* FIXME: brobecker/2003-09-17: No longer a const because it is
276 returned by a function that does not return a const char *. */
277 static char *ada_completer_word_break_characters =
279 " \t\n!@#%^&*()+=|~`}{[]\";:?/,-";
281 " \t\n!@#$%^&*()+=|~`}{[]\";:?/,-";
284 /* The name of the symbol to use to get the name of the main subprogram. */
285 static const char ADA_MAIN_PROGRAM_SYMBOL_NAME[]
286 = "__gnat_ada_main_program_name";
288 /* Limit on the number of warnings to raise per expression evaluation. */
289 static int warning_limit = 2;
291 /* Number of warning messages issued; reset to 0 by cleanups after
292 expression evaluation. */
293 static int warnings_issued = 0;
295 static const char *known_runtime_file_name_patterns[] = {
296 ADA_KNOWN_RUNTIME_FILE_NAME_PATTERNS NULL
299 static const char *known_auxiliary_function_name_patterns[] = {
300 ADA_KNOWN_AUXILIARY_FUNCTION_NAME_PATTERNS NULL
303 /* Space for allocating results of ada_lookup_symbol_list. */
304 static struct obstack symbol_list_obstack;
306 /* Inferior-specific data. */
308 /* Per-inferior data for this module. */
310 struct ada_inferior_data
312 /* The ada__tags__type_specific_data type, which is used when decoding
313 tagged types. With older versions of GNAT, this type was directly
314 accessible through a component ("tsd") in the object tag. But this
315 is no longer the case, so we cache it for each inferior. */
316 struct type *tsd_type;
319 /* Our key to this module's inferior data. */
320 static const struct inferior_data *ada_inferior_data;
322 /* A cleanup routine for our inferior data. */
324 ada_inferior_data_cleanup (struct inferior *inf, void *arg)
326 struct ada_inferior_data *data;
328 data = inferior_data (inf, ada_inferior_data);
333 /* Return our inferior data for the given inferior (INF).
335 This function always returns a valid pointer to an allocated
336 ada_inferior_data structure. If INF's inferior data has not
337 been previously set, this functions creates a new one with all
338 fields set to zero, sets INF's inferior to it, and then returns
339 a pointer to that newly allocated ada_inferior_data. */
341 static struct ada_inferior_data *
342 get_ada_inferior_data (struct inferior *inf)
344 struct ada_inferior_data *data;
346 data = inferior_data (inf, ada_inferior_data);
349 data = XZALLOC (struct ada_inferior_data);
350 set_inferior_data (inf, ada_inferior_data, data);
356 /* Perform all necessary cleanups regarding our module's inferior data
357 that is required after the inferior INF just exited. */
360 ada_inferior_exit (struct inferior *inf)
362 ada_inferior_data_cleanup (inf, NULL);
363 set_inferior_data (inf, ada_inferior_data, NULL);
368 /* If TYPE is a TYPE_CODE_TYPEDEF type, return the target type after
369 all typedef layers have been peeled. Otherwise, return TYPE.
371 Normally, we really expect a typedef type to only have 1 typedef layer.
372 In other words, we really expect the target type of a typedef type to be
373 a non-typedef type. This is particularly true for Ada units, because
374 the language does not have a typedef vs not-typedef distinction.
375 In that respect, the Ada compiler has been trying to eliminate as many
376 typedef definitions in the debugging information, since they generally
377 do not bring any extra information (we still use typedef under certain
378 circumstances related mostly to the GNAT encoding).
380 Unfortunately, we have seen situations where the debugging information
381 generated by the compiler leads to such multiple typedef layers. For
382 instance, consider the following example with stabs:
384 .stabs "pck__float_array___XUP:Tt(0,46)=s16P_ARRAY:(0,47)=[...]"[...]
385 .stabs "pck__float_array___XUP:t(0,36)=(0,46)",128,0,6,0
387 This is an error in the debugging information which causes type
388 pck__float_array___XUP to be defined twice, and the second time,
389 it is defined as a typedef of a typedef.
391 This is on the fringe of legality as far as debugging information is
392 concerned, and certainly unexpected. But it is easy to handle these
393 situations correctly, so we can afford to be lenient in this case. */
396 ada_typedef_target_type (struct type *type)
398 while (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
399 type = TYPE_TARGET_TYPE (type);
403 /* Given DECODED_NAME a string holding a symbol name in its
404 decoded form (ie using the Ada dotted notation), returns
405 its unqualified name. */
408 ada_unqualified_name (const char *decoded_name)
410 const char *result = strrchr (decoded_name, '.');
413 result++; /* Skip the dot... */
415 result = decoded_name;
420 /* Return a string starting with '<', followed by STR, and '>'.
421 The result is good until the next call. */
424 add_angle_brackets (const char *str)
426 static char *result = NULL;
429 result = xstrprintf ("<%s>", str);
434 ada_get_gdb_completer_word_break_characters (void)
436 return ada_completer_word_break_characters;
439 /* Print an array element index using the Ada syntax. */
442 ada_print_array_index (struct value *index_value, struct ui_file *stream,
443 const struct value_print_options *options)
445 LA_VALUE_PRINT (index_value, stream, options);
446 fprintf_filtered (stream, " => ");
449 /* Assuming VECT points to an array of *SIZE objects of size
450 ELEMENT_SIZE, grow it to contain at least MIN_SIZE objects,
451 updating *SIZE as necessary and returning the (new) array. */
454 grow_vect (void *vect, size_t *size, size_t min_size, int element_size)
456 if (*size < min_size)
459 if (*size < min_size)
461 vect = xrealloc (vect, *size * element_size);
466 /* True (non-zero) iff TARGET matches FIELD_NAME up to any trailing
467 suffix of FIELD_NAME beginning "___". */
470 field_name_match (const char *field_name, const char *target)
472 int len = strlen (target);
475 (strncmp (field_name, target, len) == 0
476 && (field_name[len] == '\0'
477 || (strncmp (field_name + len, "___", 3) == 0
478 && strcmp (field_name + strlen (field_name) - 6,
483 /* Assuming TYPE is a TYPE_CODE_STRUCT or a TYPE_CODE_TYPDEF to
484 a TYPE_CODE_STRUCT, find the field whose name matches FIELD_NAME,
485 and return its index. This function also handles fields whose name
486 have ___ suffixes because the compiler sometimes alters their name
487 by adding such a suffix to represent fields with certain constraints.
488 If the field could not be found, return a negative number if
489 MAYBE_MISSING is set. Otherwise raise an error. */
492 ada_get_field_index (const struct type *type, const char *field_name,
496 struct type *struct_type = check_typedef ((struct type *) type);
498 for (fieldno = 0; fieldno < TYPE_NFIELDS (struct_type); fieldno++)
499 if (field_name_match (TYPE_FIELD_NAME (struct_type, fieldno), field_name))
503 error (_("Unable to find field %s in struct %s. Aborting"),
504 field_name, TYPE_NAME (struct_type));
509 /* The length of the prefix of NAME prior to any "___" suffix. */
512 ada_name_prefix_len (const char *name)
518 const char *p = strstr (name, "___");
521 return strlen (name);
527 /* Return non-zero if SUFFIX is a suffix of STR.
528 Return zero if STR is null. */
531 is_suffix (const char *str, const char *suffix)
538 len2 = strlen (suffix);
539 return (len1 >= len2 && strcmp (str + len1 - len2, suffix) == 0);
542 /* The contents of value VAL, treated as a value of type TYPE. The
543 result is an lval in memory if VAL is. */
545 static struct value *
546 coerce_unspec_val_to_type (struct value *val, struct type *type)
548 type = ada_check_typedef (type);
549 if (value_type (val) == type)
553 struct value *result;
555 /* Make sure that the object size is not unreasonable before
556 trying to allocate some memory for it. */
560 || TYPE_LENGTH (type) > TYPE_LENGTH (value_type (val)))
561 result = allocate_value_lazy (type);
564 result = allocate_value (type);
565 memcpy (value_contents_raw (result), value_contents (val),
568 set_value_component_location (result, val);
569 set_value_bitsize (result, value_bitsize (val));
570 set_value_bitpos (result, value_bitpos (val));
571 set_value_address (result, value_address (val));
576 static const gdb_byte *
577 cond_offset_host (const gdb_byte *valaddr, long offset)
582 return valaddr + offset;
586 cond_offset_target (CORE_ADDR address, long offset)
591 return address + offset;
594 /* Issue a warning (as for the definition of warning in utils.c, but
595 with exactly one argument rather than ...), unless the limit on the
596 number of warnings has passed during the evaluation of the current
599 /* FIXME: cagney/2004-10-10: This function is mimicking the behavior
600 provided by "complaint". */
601 static void lim_warning (const char *format, ...) ATTRIBUTE_PRINTF (1, 2);
604 lim_warning (const char *format, ...)
608 va_start (args, format);
609 warnings_issued += 1;
610 if (warnings_issued <= warning_limit)
611 vwarning (format, args);
616 /* Issue an error if the size of an object of type T is unreasonable,
617 i.e. if it would be a bad idea to allocate a value of this type in
621 check_size (const struct type *type)
623 if (TYPE_LENGTH (type) > varsize_limit)
624 error (_("object size is larger than varsize-limit"));
627 /* Maximum value of a SIZE-byte signed integer type. */
629 max_of_size (int size)
631 LONGEST top_bit = (LONGEST) 1 << (size * 8 - 2);
633 return top_bit | (top_bit - 1);
636 /* Minimum value of a SIZE-byte signed integer type. */
638 min_of_size (int size)
640 return -max_of_size (size) - 1;
643 /* Maximum value of a SIZE-byte unsigned integer type. */
645 umax_of_size (int size)
647 ULONGEST top_bit = (ULONGEST) 1 << (size * 8 - 1);
649 return top_bit | (top_bit - 1);
652 /* Maximum value of integral type T, as a signed quantity. */
654 max_of_type (struct type *t)
656 if (TYPE_UNSIGNED (t))
657 return (LONGEST) umax_of_size (TYPE_LENGTH (t));
659 return max_of_size (TYPE_LENGTH (t));
662 /* Minimum value of integral type T, as a signed quantity. */
664 min_of_type (struct type *t)
666 if (TYPE_UNSIGNED (t))
669 return min_of_size (TYPE_LENGTH (t));
672 /* The largest value in the domain of TYPE, a discrete type, as an integer. */
674 ada_discrete_type_high_bound (struct type *type)
676 switch (TYPE_CODE (type))
678 case TYPE_CODE_RANGE:
679 return TYPE_HIGH_BOUND (type);
681 return TYPE_FIELD_BITPOS (type, TYPE_NFIELDS (type) - 1);
686 return max_of_type (type);
688 error (_("Unexpected type in ada_discrete_type_high_bound."));
692 /* The largest value in the domain of TYPE, a discrete type, as an integer. */
694 ada_discrete_type_low_bound (struct type *type)
696 switch (TYPE_CODE (type))
698 case TYPE_CODE_RANGE:
699 return TYPE_LOW_BOUND (type);
701 return TYPE_FIELD_BITPOS (type, 0);
706 return min_of_type (type);
708 error (_("Unexpected type in ada_discrete_type_low_bound."));
712 /* The identity on non-range types. For range types, the underlying
713 non-range scalar type. */
716 base_type (struct type *type)
718 while (type != NULL && TYPE_CODE (type) == TYPE_CODE_RANGE)
720 if (type == TYPE_TARGET_TYPE (type) || TYPE_TARGET_TYPE (type) == NULL)
722 type = TYPE_TARGET_TYPE (type);
728 /* Language Selection */
730 /* If the main program is in Ada, return language_ada, otherwise return LANG
731 (the main program is in Ada iif the adainit symbol is found). */
734 ada_update_initial_language (enum language lang)
736 if (lookup_minimal_symbol ("adainit", (const char *) NULL,
737 (struct objfile *) NULL) != NULL)
743 /* If the main procedure is written in Ada, then return its name.
744 The result is good until the next call. Return NULL if the main
745 procedure doesn't appear to be in Ada. */
750 struct minimal_symbol *msym;
751 static char *main_program_name = NULL;
753 /* For Ada, the name of the main procedure is stored in a specific
754 string constant, generated by the binder. Look for that symbol,
755 extract its address, and then read that string. If we didn't find
756 that string, then most probably the main procedure is not written
758 msym = lookup_minimal_symbol (ADA_MAIN_PROGRAM_SYMBOL_NAME, NULL, NULL);
762 CORE_ADDR main_program_name_addr;
765 main_program_name_addr = SYMBOL_VALUE_ADDRESS (msym);
766 if (main_program_name_addr == 0)
767 error (_("Invalid address for Ada main program name."));
769 xfree (main_program_name);
770 target_read_string (main_program_name_addr, &main_program_name,
775 return main_program_name;
778 /* The main procedure doesn't seem to be in Ada. */
784 /* Table of Ada operators and their GNAT-encoded names. Last entry is pair
787 const struct ada_opname_map ada_opname_table[] = {
788 {"Oadd", "\"+\"", BINOP_ADD},
789 {"Osubtract", "\"-\"", BINOP_SUB},
790 {"Omultiply", "\"*\"", BINOP_MUL},
791 {"Odivide", "\"/\"", BINOP_DIV},
792 {"Omod", "\"mod\"", BINOP_MOD},
793 {"Orem", "\"rem\"", BINOP_REM},
794 {"Oexpon", "\"**\"", BINOP_EXP},
795 {"Olt", "\"<\"", BINOP_LESS},
796 {"Ole", "\"<=\"", BINOP_LEQ},
797 {"Ogt", "\">\"", BINOP_GTR},
798 {"Oge", "\">=\"", BINOP_GEQ},
799 {"Oeq", "\"=\"", BINOP_EQUAL},
800 {"One", "\"/=\"", BINOP_NOTEQUAL},
801 {"Oand", "\"and\"", BINOP_BITWISE_AND},
802 {"Oor", "\"or\"", BINOP_BITWISE_IOR},
803 {"Oxor", "\"xor\"", BINOP_BITWISE_XOR},
804 {"Oconcat", "\"&\"", BINOP_CONCAT},
805 {"Oabs", "\"abs\"", UNOP_ABS},
806 {"Onot", "\"not\"", UNOP_LOGICAL_NOT},
807 {"Oadd", "\"+\"", UNOP_PLUS},
808 {"Osubtract", "\"-\"", UNOP_NEG},
812 /* The "encoded" form of DECODED, according to GNAT conventions.
813 The result is valid until the next call to ada_encode. */
816 ada_encode (const char *decoded)
818 static char *encoding_buffer = NULL;
819 static size_t encoding_buffer_size = 0;
826 GROW_VECT (encoding_buffer, encoding_buffer_size,
827 2 * strlen (decoded) + 10);
830 for (p = decoded; *p != '\0'; p += 1)
834 encoding_buffer[k] = encoding_buffer[k + 1] = '_';
839 const struct ada_opname_map *mapping;
841 for (mapping = ada_opname_table;
842 mapping->encoded != NULL
843 && strncmp (mapping->decoded, p,
844 strlen (mapping->decoded)) != 0; mapping += 1)
846 if (mapping->encoded == NULL)
847 error (_("invalid Ada operator name: %s"), p);
848 strcpy (encoding_buffer + k, mapping->encoded);
849 k += strlen (mapping->encoded);
854 encoding_buffer[k] = *p;
859 encoding_buffer[k] = '\0';
860 return encoding_buffer;
863 /* Return NAME folded to lower case, or, if surrounded by single
864 quotes, unfolded, but with the quotes stripped away. Result good
868 ada_fold_name (const char *name)
870 static char *fold_buffer = NULL;
871 static size_t fold_buffer_size = 0;
873 int len = strlen (name);
874 GROW_VECT (fold_buffer, fold_buffer_size, len + 1);
878 strncpy (fold_buffer, name + 1, len - 2);
879 fold_buffer[len - 2] = '\000';
885 for (i = 0; i <= len; i += 1)
886 fold_buffer[i] = tolower (name[i]);
892 /* Return nonzero if C is either a digit or a lowercase alphabet character. */
895 is_lower_alphanum (const char c)
897 return (isdigit (c) || (isalpha (c) && islower (c)));
900 /* Remove either of these suffixes:
905 These are suffixes introduced by the compiler for entities such as
906 nested subprogram for instance, in order to avoid name clashes.
907 They do not serve any purpose for the debugger. */
910 ada_remove_trailing_digits (const char *encoded, int *len)
912 if (*len > 1 && isdigit (encoded[*len - 1]))
916 while (i > 0 && isdigit (encoded[i]))
918 if (i >= 0 && encoded[i] == '.')
920 else if (i >= 0 && encoded[i] == '$')
922 else if (i >= 2 && strncmp (encoded + i - 2, "___", 3) == 0)
924 else if (i >= 1 && strncmp (encoded + i - 1, "__", 2) == 0)
929 /* Remove the suffix introduced by the compiler for protected object
933 ada_remove_po_subprogram_suffix (const char *encoded, int *len)
935 /* Remove trailing N. */
937 /* Protected entry subprograms are broken into two
938 separate subprograms: The first one is unprotected, and has
939 a 'N' suffix; the second is the protected version, and has
940 the 'P' suffix. The second calls the first one after handling
941 the protection. Since the P subprograms are internally generated,
942 we leave these names undecoded, giving the user a clue that this
943 entity is internal. */
946 && encoded[*len - 1] == 'N'
947 && (isdigit (encoded[*len - 2]) || islower (encoded[*len - 2])))
951 /* Remove trailing X[bn]* suffixes (indicating names in package bodies). */
954 ada_remove_Xbn_suffix (const char *encoded, int *len)
958 while (i > 0 && (encoded[i] == 'b' || encoded[i] == 'n'))
961 if (encoded[i] != 'X')
967 if (isalnum (encoded[i-1]))
971 /* If ENCODED follows the GNAT entity encoding conventions, then return
972 the decoded form of ENCODED. Otherwise, return "<%s>" where "%s" is
975 The resulting string is valid until the next call of ada_decode.
976 If the string is unchanged by decoding, the original string pointer
980 ada_decode (const char *encoded)
987 static char *decoding_buffer = NULL;
988 static size_t decoding_buffer_size = 0;
990 /* The name of the Ada main procedure starts with "_ada_".
991 This prefix is not part of the decoded name, so skip this part
992 if we see this prefix. */
993 if (strncmp (encoded, "_ada_", 5) == 0)
996 /* If the name starts with '_', then it is not a properly encoded
997 name, so do not attempt to decode it. Similarly, if the name
998 starts with '<', the name should not be decoded. */
999 if (encoded[0] == '_' || encoded[0] == '<')
1002 len0 = strlen (encoded);
1004 ada_remove_trailing_digits (encoded, &len0);
1005 ada_remove_po_subprogram_suffix (encoded, &len0);
1007 /* Remove the ___X.* suffix if present. Do not forget to verify that
1008 the suffix is located before the current "end" of ENCODED. We want
1009 to avoid re-matching parts of ENCODED that have previously been
1010 marked as discarded (by decrementing LEN0). */
1011 p = strstr (encoded, "___");
1012 if (p != NULL && p - encoded < len0 - 3)
1020 /* Remove any trailing TKB suffix. It tells us that this symbol
1021 is for the body of a task, but that information does not actually
1022 appear in the decoded name. */
1024 if (len0 > 3 && strncmp (encoded + len0 - 3, "TKB", 3) == 0)
1027 /* Remove any trailing TB suffix. The TB suffix is slightly different
1028 from the TKB suffix because it is used for non-anonymous task
1031 if (len0 > 2 && strncmp (encoded + len0 - 2, "TB", 2) == 0)
1034 /* Remove trailing "B" suffixes. */
1035 /* FIXME: brobecker/2006-04-19: Not sure what this are used for... */
1037 if (len0 > 1 && strncmp (encoded + len0 - 1, "B", 1) == 0)
1040 /* Make decoded big enough for possible expansion by operator name. */
1042 GROW_VECT (decoding_buffer, decoding_buffer_size, 2 * len0 + 1);
1043 decoded = decoding_buffer;
1045 /* Remove trailing __{digit}+ or trailing ${digit}+. */
1047 if (len0 > 1 && isdigit (encoded[len0 - 1]))
1050 while ((i >= 0 && isdigit (encoded[i]))
1051 || (i >= 1 && encoded[i] == '_' && isdigit (encoded[i - 1])))
1053 if (i > 1 && encoded[i] == '_' && encoded[i - 1] == '_')
1055 else if (encoded[i] == '$')
1059 /* The first few characters that are not alphabetic are not part
1060 of any encoding we use, so we can copy them over verbatim. */
1062 for (i = 0, j = 0; i < len0 && !isalpha (encoded[i]); i += 1, j += 1)
1063 decoded[j] = encoded[i];
1068 /* Is this a symbol function? */
1069 if (at_start_name && encoded[i] == 'O')
1073 for (k = 0; ada_opname_table[k].encoded != NULL; k += 1)
1075 int op_len = strlen (ada_opname_table[k].encoded);
1076 if ((strncmp (ada_opname_table[k].encoded + 1, encoded + i + 1,
1078 && !isalnum (encoded[i + op_len]))
1080 strcpy (decoded + j, ada_opname_table[k].decoded);
1083 j += strlen (ada_opname_table[k].decoded);
1087 if (ada_opname_table[k].encoded != NULL)
1092 /* Replace "TK__" with "__", which will eventually be translated
1093 into "." (just below). */
1095 if (i < len0 - 4 && strncmp (encoded + i, "TK__", 4) == 0)
1098 /* Replace "__B_{DIGITS}+__" sequences by "__", which will eventually
1099 be translated into "." (just below). These are internal names
1100 generated for anonymous blocks inside which our symbol is nested. */
1102 if (len0 - i > 5 && encoded [i] == '_' && encoded [i+1] == '_'
1103 && encoded [i+2] == 'B' && encoded [i+3] == '_'
1104 && isdigit (encoded [i+4]))
1108 while (k < len0 && isdigit (encoded[k]))
1109 k++; /* Skip any extra digit. */
1111 /* Double-check that the "__B_{DIGITS}+" sequence we found
1112 is indeed followed by "__". */
1113 if (len0 - k > 2 && encoded [k] == '_' && encoded [k+1] == '_')
1117 /* Remove _E{DIGITS}+[sb] */
1119 /* Just as for protected object subprograms, there are 2 categories
1120 of subprograms created by the compiler for each entry. The first
1121 one implements the actual entry code, and has a suffix following
1122 the convention above; the second one implements the barrier and
1123 uses the same convention as above, except that the 'E' is replaced
1126 Just as above, we do not decode the name of barrier functions
1127 to give the user a clue that the code he is debugging has been
1128 internally generated. */
1130 if (len0 - i > 3 && encoded [i] == '_' && encoded[i+1] == 'E'
1131 && isdigit (encoded[i+2]))
1135 while (k < len0 && isdigit (encoded[k]))
1139 && (encoded[k] == 'b' || encoded[k] == 's'))
1142 /* Just as an extra precaution, make sure that if this
1143 suffix is followed by anything else, it is a '_'.
1144 Otherwise, we matched this sequence by accident. */
1146 || (k < len0 && encoded[k] == '_'))
1151 /* Remove trailing "N" in [a-z0-9]+N__. The N is added by
1152 the GNAT front-end in protected object subprograms. */
1155 && encoded[i] == 'N' && encoded[i+1] == '_' && encoded[i+2] == '_')
1157 /* Backtrack a bit up until we reach either the begining of
1158 the encoded name, or "__". Make sure that we only find
1159 digits or lowercase characters. */
1160 const char *ptr = encoded + i - 1;
1162 while (ptr >= encoded && is_lower_alphanum (ptr[0]))
1165 || (ptr > encoded && ptr[0] == '_' && ptr[-1] == '_'))
1169 if (encoded[i] == 'X' && i != 0 && isalnum (encoded[i - 1]))
1171 /* This is a X[bn]* sequence not separated from the previous
1172 part of the name with a non-alpha-numeric character (in other
1173 words, immediately following an alpha-numeric character), then
1174 verify that it is placed at the end of the encoded name. If
1175 not, then the encoding is not valid and we should abort the
1176 decoding. Otherwise, just skip it, it is used in body-nested
1180 while (i < len0 && (encoded[i] == 'b' || encoded[i] == 'n'));
1184 else if (i < len0 - 2 && encoded[i] == '_' && encoded[i + 1] == '_')
1186 /* Replace '__' by '.'. */
1194 /* It's a character part of the decoded name, so just copy it
1196 decoded[j] = encoded[i];
1201 decoded[j] = '\000';
1203 /* Decoded names should never contain any uppercase character.
1204 Double-check this, and abort the decoding if we find one. */
1206 for (i = 0; decoded[i] != '\0'; i += 1)
1207 if (isupper (decoded[i]) || decoded[i] == ' ')
1210 if (strcmp (decoded, encoded) == 0)
1216 GROW_VECT (decoding_buffer, decoding_buffer_size, strlen (encoded) + 3);
1217 decoded = decoding_buffer;
1218 if (encoded[0] == '<')
1219 strcpy (decoded, encoded);
1221 xsnprintf (decoded, decoding_buffer_size, "<%s>", encoded);
1226 /* Table for keeping permanent unique copies of decoded names. Once
1227 allocated, names in this table are never released. While this is a
1228 storage leak, it should not be significant unless there are massive
1229 changes in the set of decoded names in successive versions of a
1230 symbol table loaded during a single session. */
1231 static struct htab *decoded_names_store;
1233 /* Returns the decoded name of GSYMBOL, as for ada_decode, caching it
1234 in the language-specific part of GSYMBOL, if it has not been
1235 previously computed. Tries to save the decoded name in the same
1236 obstack as GSYMBOL, if possible, and otherwise on the heap (so that,
1237 in any case, the decoded symbol has a lifetime at least that of
1239 The GSYMBOL parameter is "mutable" in the C++ sense: logically
1240 const, but nevertheless modified to a semantically equivalent form
1241 when a decoded name is cached in it. */
1244 ada_decode_symbol (const struct general_symbol_info *gsymbol)
1247 (char **) &gsymbol->language_specific.mangled_lang.demangled_name;
1249 if (*resultp == NULL)
1251 const char *decoded = ada_decode (gsymbol->name);
1253 if (gsymbol->obj_section != NULL)
1255 struct objfile *objf = gsymbol->obj_section->objfile;
1257 *resultp = obsavestring (decoded, strlen (decoded),
1258 &objf->objfile_obstack);
1260 /* Sometimes, we can't find a corresponding objfile, in which
1261 case, we put the result on the heap. Since we only decode
1262 when needed, we hope this usually does not cause a
1263 significant memory leak (FIXME). */
1264 if (*resultp == NULL)
1266 char **slot = (char **) htab_find_slot (decoded_names_store,
1270 *slot = xstrdup (decoded);
1279 ada_la_decode (const char *encoded, int options)
1281 return xstrdup (ada_decode (encoded));
1284 /* Returns non-zero iff SYM_NAME matches NAME, ignoring any trailing
1285 suffixes that encode debugging information or leading _ada_ on
1286 SYM_NAME (see is_name_suffix commentary for the debugging
1287 information that is ignored). If WILD, then NAME need only match a
1288 suffix of SYM_NAME minus the same suffixes. Also returns 0 if
1289 either argument is NULL. */
1292 match_name (const char *sym_name, const char *name, int wild)
1294 if (sym_name == NULL || name == NULL)
1297 return wild_match (sym_name, name) == 0;
1300 int len_name = strlen (name);
1302 return (strncmp (sym_name, name, len_name) == 0
1303 && is_name_suffix (sym_name + len_name))
1304 || (strncmp (sym_name, "_ada_", 5) == 0
1305 && strncmp (sym_name + 5, name, len_name) == 0
1306 && is_name_suffix (sym_name + len_name + 5));
1313 /* Assuming that INDEX_DESC_TYPE is an ___XA structure, a structure
1314 generated by the GNAT compiler to describe the index type used
1315 for each dimension of an array, check whether it follows the latest
1316 known encoding. If not, fix it up to conform to the latest encoding.
1317 Otherwise, do nothing. This function also does nothing if
1318 INDEX_DESC_TYPE is NULL.
1320 The GNAT encoding used to describle the array index type evolved a bit.
1321 Initially, the information would be provided through the name of each
1322 field of the structure type only, while the type of these fields was
1323 described as unspecified and irrelevant. The debugger was then expected
1324 to perform a global type lookup using the name of that field in order
1325 to get access to the full index type description. Because these global
1326 lookups can be very expensive, the encoding was later enhanced to make
1327 the global lookup unnecessary by defining the field type as being
1328 the full index type description.
1330 The purpose of this routine is to allow us to support older versions
1331 of the compiler by detecting the use of the older encoding, and by
1332 fixing up the INDEX_DESC_TYPE to follow the new one (at this point,
1333 we essentially replace each field's meaningless type by the associated
1337 ada_fixup_array_indexes_type (struct type *index_desc_type)
1341 if (index_desc_type == NULL)
1343 gdb_assert (TYPE_NFIELDS (index_desc_type) > 0);
1345 /* Check if INDEX_DESC_TYPE follows the older encoding (it is sufficient
1346 to check one field only, no need to check them all). If not, return
1349 If our INDEX_DESC_TYPE was generated using the older encoding,
1350 the field type should be a meaningless integer type whose name
1351 is not equal to the field name. */
1352 if (TYPE_NAME (TYPE_FIELD_TYPE (index_desc_type, 0)) != NULL
1353 && strcmp (TYPE_NAME (TYPE_FIELD_TYPE (index_desc_type, 0)),
1354 TYPE_FIELD_NAME (index_desc_type, 0)) == 0)
1357 /* Fixup each field of INDEX_DESC_TYPE. */
1358 for (i = 0; i < TYPE_NFIELDS (index_desc_type); i++)
1360 char *name = TYPE_FIELD_NAME (index_desc_type, i);
1361 struct type *raw_type = ada_check_typedef (ada_find_any_type (name));
1364 TYPE_FIELD_TYPE (index_desc_type, i) = raw_type;
1368 /* Names of MAX_ADA_DIMENS bounds in P_BOUNDS fields of array descriptors. */
1370 static char *bound_name[] = {
1371 "LB0", "UB0", "LB1", "UB1", "LB2", "UB2", "LB3", "UB3",
1372 "LB4", "UB4", "LB5", "UB5", "LB6", "UB6", "LB7", "UB7"
1375 /* Maximum number of array dimensions we are prepared to handle. */
1377 #define MAX_ADA_DIMENS (sizeof(bound_name) / (2*sizeof(char *)))
1380 /* The desc_* routines return primitive portions of array descriptors
1383 /* The descriptor or array type, if any, indicated by TYPE; removes
1384 level of indirection, if needed. */
1386 static struct type *
1387 desc_base_type (struct type *type)
1391 type = ada_check_typedef (type);
1392 if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
1393 type = ada_typedef_target_type (type);
1396 && (TYPE_CODE (type) == TYPE_CODE_PTR
1397 || TYPE_CODE (type) == TYPE_CODE_REF))
1398 return ada_check_typedef (TYPE_TARGET_TYPE (type));
1403 /* True iff TYPE indicates a "thin" array pointer type. */
1406 is_thin_pntr (struct type *type)
1409 is_suffix (ada_type_name (desc_base_type (type)), "___XUT")
1410 || is_suffix (ada_type_name (desc_base_type (type)), "___XUT___XVE");
1413 /* The descriptor type for thin pointer type TYPE. */
1415 static struct type *
1416 thin_descriptor_type (struct type *type)
1418 struct type *base_type = desc_base_type (type);
1420 if (base_type == NULL)
1422 if (is_suffix (ada_type_name (base_type), "___XVE"))
1426 struct type *alt_type = ada_find_parallel_type (base_type, "___XVE");
1428 if (alt_type == NULL)
1435 /* A pointer to the array data for thin-pointer value VAL. */
1437 static struct value *
1438 thin_data_pntr (struct value *val)
1440 struct type *type = value_type (val);
1441 struct type *data_type = desc_data_target_type (thin_descriptor_type (type));
1443 data_type = lookup_pointer_type (data_type);
1445 if (TYPE_CODE (type) == TYPE_CODE_PTR)
1446 return value_cast (data_type, value_copy (val));
1448 return value_from_longest (data_type, value_address (val));
1451 /* True iff TYPE indicates a "thick" array pointer type. */
1454 is_thick_pntr (struct type *type)
1456 type = desc_base_type (type);
1457 return (type != NULL && TYPE_CODE (type) == TYPE_CODE_STRUCT
1458 && lookup_struct_elt_type (type, "P_BOUNDS", 1) != NULL);
1461 /* If TYPE is the type of an array descriptor (fat or thin pointer) or a
1462 pointer to one, the type of its bounds data; otherwise, NULL. */
1464 static struct type *
1465 desc_bounds_type (struct type *type)
1469 type = desc_base_type (type);
1473 else if (is_thin_pntr (type))
1475 type = thin_descriptor_type (type);
1478 r = lookup_struct_elt_type (type, "BOUNDS", 1);
1480 return ada_check_typedef (r);
1482 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
1484 r = lookup_struct_elt_type (type, "P_BOUNDS", 1);
1486 return ada_check_typedef (TYPE_TARGET_TYPE (ada_check_typedef (r)));
1491 /* If ARR is an array descriptor (fat or thin pointer), or pointer to
1492 one, a pointer to its bounds data. Otherwise NULL. */
1494 static struct value *
1495 desc_bounds (struct value *arr)
1497 struct type *type = ada_check_typedef (value_type (arr));
1499 if (is_thin_pntr (type))
1501 struct type *bounds_type =
1502 desc_bounds_type (thin_descriptor_type (type));
1505 if (bounds_type == NULL)
1506 error (_("Bad GNAT array descriptor"));
1508 /* NOTE: The following calculation is not really kosher, but
1509 since desc_type is an XVE-encoded type (and shouldn't be),
1510 the correct calculation is a real pain. FIXME (and fix GCC). */
1511 if (TYPE_CODE (type) == TYPE_CODE_PTR)
1512 addr = value_as_long (arr);
1514 addr = value_address (arr);
1517 value_from_longest (lookup_pointer_type (bounds_type),
1518 addr - TYPE_LENGTH (bounds_type));
1521 else if (is_thick_pntr (type))
1523 struct value *p_bounds = value_struct_elt (&arr, NULL, "P_BOUNDS", NULL,
1524 _("Bad GNAT array descriptor"));
1525 struct type *p_bounds_type = value_type (p_bounds);
1528 && TYPE_CODE (p_bounds_type) == TYPE_CODE_PTR)
1530 struct type *target_type = TYPE_TARGET_TYPE (p_bounds_type);
1532 if (TYPE_STUB (target_type))
1533 p_bounds = value_cast (lookup_pointer_type
1534 (ada_check_typedef (target_type)),
1538 error (_("Bad GNAT array descriptor"));
1546 /* If TYPE is the type of an array-descriptor (fat pointer), the bit
1547 position of the field containing the address of the bounds data. */
1550 fat_pntr_bounds_bitpos (struct type *type)
1552 return TYPE_FIELD_BITPOS (desc_base_type (type), 1);
1555 /* If TYPE is the type of an array-descriptor (fat pointer), the bit
1556 size of the field containing the address of the bounds data. */
1559 fat_pntr_bounds_bitsize (struct type *type)
1561 type = desc_base_type (type);
1563 if (TYPE_FIELD_BITSIZE (type, 1) > 0)
1564 return TYPE_FIELD_BITSIZE (type, 1);
1566 return 8 * TYPE_LENGTH (ada_check_typedef (TYPE_FIELD_TYPE (type, 1)));
1569 /* If TYPE is the type of an array descriptor (fat or thin pointer) or a
1570 pointer to one, the type of its array data (a array-with-no-bounds type);
1571 otherwise, NULL. Use ada_type_of_array to get an array type with bounds
1574 static struct type *
1575 desc_data_target_type (struct type *type)
1577 type = desc_base_type (type);
1579 /* NOTE: The following is bogus; see comment in desc_bounds. */
1580 if (is_thin_pntr (type))
1581 return desc_base_type (TYPE_FIELD_TYPE (thin_descriptor_type (type), 1));
1582 else if (is_thick_pntr (type))
1584 struct type *data_type = lookup_struct_elt_type (type, "P_ARRAY", 1);
1587 && TYPE_CODE (ada_check_typedef (data_type)) == TYPE_CODE_PTR)
1588 return ada_check_typedef (TYPE_TARGET_TYPE (data_type));
1594 /* If ARR is an array descriptor (fat or thin pointer), a pointer to
1597 static struct value *
1598 desc_data (struct value *arr)
1600 struct type *type = value_type (arr);
1602 if (is_thin_pntr (type))
1603 return thin_data_pntr (arr);
1604 else if (is_thick_pntr (type))
1605 return value_struct_elt (&arr, NULL, "P_ARRAY", NULL,
1606 _("Bad GNAT array descriptor"));
1612 /* If TYPE is the type of an array-descriptor (fat pointer), the bit
1613 position of the field containing the address of the data. */
1616 fat_pntr_data_bitpos (struct type *type)
1618 return TYPE_FIELD_BITPOS (desc_base_type (type), 0);
1621 /* If TYPE is the type of an array-descriptor (fat pointer), the bit
1622 size of the field containing the address of the data. */
1625 fat_pntr_data_bitsize (struct type *type)
1627 type = desc_base_type (type);
1629 if (TYPE_FIELD_BITSIZE (type, 0) > 0)
1630 return TYPE_FIELD_BITSIZE (type, 0);
1632 return TARGET_CHAR_BIT * TYPE_LENGTH (TYPE_FIELD_TYPE (type, 0));
1635 /* If BOUNDS is an array-bounds structure (or pointer to one), return
1636 the Ith lower bound stored in it, if WHICH is 0, and the Ith upper
1637 bound, if WHICH is 1. The first bound is I=1. */
1639 static struct value *
1640 desc_one_bound (struct value *bounds, int i, int which)
1642 return value_struct_elt (&bounds, NULL, bound_name[2 * i + which - 2], NULL,
1643 _("Bad GNAT array descriptor bounds"));
1646 /* If BOUNDS is an array-bounds structure type, return the bit position
1647 of the Ith lower bound stored in it, if WHICH is 0, and the Ith upper
1648 bound, if WHICH is 1. The first bound is I=1. */
1651 desc_bound_bitpos (struct type *type, int i, int which)
1653 return TYPE_FIELD_BITPOS (desc_base_type (type), 2 * i + which - 2);
1656 /* If BOUNDS is an array-bounds structure type, return the bit field size
1657 of the Ith lower bound stored in it, if WHICH is 0, and the Ith upper
1658 bound, if WHICH is 1. The first bound is I=1. */
1661 desc_bound_bitsize (struct type *type, int i, int which)
1663 type = desc_base_type (type);
1665 if (TYPE_FIELD_BITSIZE (type, 2 * i + which - 2) > 0)
1666 return TYPE_FIELD_BITSIZE (type, 2 * i + which - 2);
1668 return 8 * TYPE_LENGTH (TYPE_FIELD_TYPE (type, 2 * i + which - 2));
1671 /* If TYPE is the type of an array-bounds structure, the type of its
1672 Ith bound (numbering from 1). Otherwise, NULL. */
1674 static struct type *
1675 desc_index_type (struct type *type, int i)
1677 type = desc_base_type (type);
1679 if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
1680 return lookup_struct_elt_type (type, bound_name[2 * i - 2], 1);
1685 /* The number of index positions in the array-bounds type TYPE.
1686 Return 0 if TYPE is NULL. */
1689 desc_arity (struct type *type)
1691 type = desc_base_type (type);
1694 return TYPE_NFIELDS (type) / 2;
1698 /* Non-zero iff TYPE is a simple array type (not a pointer to one) or
1699 an array descriptor type (representing an unconstrained array
1703 ada_is_direct_array_type (struct type *type)
1707 type = ada_check_typedef (type);
1708 return (TYPE_CODE (type) == TYPE_CODE_ARRAY
1709 || ada_is_array_descriptor_type (type));
1712 /* Non-zero iff TYPE represents any kind of array in Ada, or a pointer
1716 ada_is_array_type (struct type *type)
1719 && (TYPE_CODE (type) == TYPE_CODE_PTR
1720 || TYPE_CODE (type) == TYPE_CODE_REF))
1721 type = TYPE_TARGET_TYPE (type);
1722 return ada_is_direct_array_type (type);
1725 /* Non-zero iff TYPE is a simple array type or pointer to one. */
1728 ada_is_simple_array_type (struct type *type)
1732 type = ada_check_typedef (type);
1733 return (TYPE_CODE (type) == TYPE_CODE_ARRAY
1734 || (TYPE_CODE (type) == TYPE_CODE_PTR
1735 && TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_ARRAY));
1738 /* Non-zero iff TYPE belongs to a GNAT array descriptor. */
1741 ada_is_array_descriptor_type (struct type *type)
1743 struct type *data_type = desc_data_target_type (type);
1747 type = ada_check_typedef (type);
1748 return (data_type != NULL
1749 && TYPE_CODE (data_type) == TYPE_CODE_ARRAY
1750 && desc_arity (desc_bounds_type (type)) > 0);
1753 /* Non-zero iff type is a partially mal-formed GNAT array
1754 descriptor. FIXME: This is to compensate for some problems with
1755 debugging output from GNAT. Re-examine periodically to see if it
1759 ada_is_bogus_array_descriptor (struct type *type)
1763 && TYPE_CODE (type) == TYPE_CODE_STRUCT
1764 && (lookup_struct_elt_type (type, "P_BOUNDS", 1) != NULL
1765 || lookup_struct_elt_type (type, "P_ARRAY", 1) != NULL)
1766 && !ada_is_array_descriptor_type (type);
1770 /* If ARR has a record type in the form of a standard GNAT array descriptor,
1771 (fat pointer) returns the type of the array data described---specifically,
1772 a pointer-to-array type. If BOUNDS is non-zero, the bounds data are filled
1773 in from the descriptor; otherwise, they are left unspecified. If
1774 the ARR denotes a null array descriptor and BOUNDS is non-zero,
1775 returns NULL. The result is simply the type of ARR if ARR is not
1778 ada_type_of_array (struct value *arr, int bounds)
1780 if (ada_is_constrained_packed_array_type (value_type (arr)))
1781 return decode_constrained_packed_array_type (value_type (arr));
1783 if (!ada_is_array_descriptor_type (value_type (arr)))
1784 return value_type (arr);
1788 struct type *array_type =
1789 ada_check_typedef (desc_data_target_type (value_type (arr)));
1791 if (ada_is_unconstrained_packed_array_type (value_type (arr)))
1792 TYPE_FIELD_BITSIZE (array_type, 0) =
1793 decode_packed_array_bitsize (value_type (arr));
1799 struct type *elt_type;
1801 struct value *descriptor;
1803 elt_type = ada_array_element_type (value_type (arr), -1);
1804 arity = ada_array_arity (value_type (arr));
1806 if (elt_type == NULL || arity == 0)
1807 return ada_check_typedef (value_type (arr));
1809 descriptor = desc_bounds (arr);
1810 if (value_as_long (descriptor) == 0)
1814 struct type *range_type = alloc_type_copy (value_type (arr));
1815 struct type *array_type = alloc_type_copy (value_type (arr));
1816 struct value *low = desc_one_bound (descriptor, arity, 0);
1817 struct value *high = desc_one_bound (descriptor, arity, 1);
1820 create_range_type (range_type, value_type (low),
1821 longest_to_int (value_as_long (low)),
1822 longest_to_int (value_as_long (high)));
1823 elt_type = create_array_type (array_type, elt_type, range_type);
1825 if (ada_is_unconstrained_packed_array_type (value_type (arr)))
1826 TYPE_FIELD_BITSIZE (elt_type, 0) =
1827 decode_packed_array_bitsize (value_type (arr));
1830 return lookup_pointer_type (elt_type);
1834 /* If ARR does not represent an array, returns ARR unchanged.
1835 Otherwise, returns either a standard GDB array with bounds set
1836 appropriately or, if ARR is a non-null fat pointer, a pointer to a standard
1837 GDB array. Returns NULL if ARR is a null fat pointer. */
1840 ada_coerce_to_simple_array_ptr (struct value *arr)
1842 if (ada_is_array_descriptor_type (value_type (arr)))
1844 struct type *arrType = ada_type_of_array (arr, 1);
1846 if (arrType == NULL)
1848 return value_cast (arrType, value_copy (desc_data (arr)));
1850 else if (ada_is_constrained_packed_array_type (value_type (arr)))
1851 return decode_constrained_packed_array (arr);
1856 /* If ARR does not represent an array, returns ARR unchanged.
1857 Otherwise, returns a standard GDB array describing ARR (which may
1858 be ARR itself if it already is in the proper form). */
1861 ada_coerce_to_simple_array (struct value *arr)
1863 if (ada_is_array_descriptor_type (value_type (arr)))
1865 struct value *arrVal = ada_coerce_to_simple_array_ptr (arr);
1868 error (_("Bounds unavailable for null array pointer."));
1869 check_size (TYPE_TARGET_TYPE (value_type (arrVal)));
1870 return value_ind (arrVal);
1872 else if (ada_is_constrained_packed_array_type (value_type (arr)))
1873 return decode_constrained_packed_array (arr);
1878 /* If TYPE represents a GNAT array type, return it translated to an
1879 ordinary GDB array type (possibly with BITSIZE fields indicating
1880 packing). For other types, is the identity. */
1883 ada_coerce_to_simple_array_type (struct type *type)
1885 if (ada_is_constrained_packed_array_type (type))
1886 return decode_constrained_packed_array_type (type);
1888 if (ada_is_array_descriptor_type (type))
1889 return ada_check_typedef (desc_data_target_type (type));
1894 /* Non-zero iff TYPE represents a standard GNAT packed-array type. */
1897 ada_is_packed_array_type (struct type *type)
1901 type = desc_base_type (type);
1902 type = ada_check_typedef (type);
1904 ada_type_name (type) != NULL
1905 && strstr (ada_type_name (type), "___XP") != NULL;
1908 /* Non-zero iff TYPE represents a standard GNAT constrained
1909 packed-array type. */
1912 ada_is_constrained_packed_array_type (struct type *type)
1914 return ada_is_packed_array_type (type)
1915 && !ada_is_array_descriptor_type (type);
1918 /* Non-zero iff TYPE represents an array descriptor for a
1919 unconstrained packed-array type. */
1922 ada_is_unconstrained_packed_array_type (struct type *type)
1924 return ada_is_packed_array_type (type)
1925 && ada_is_array_descriptor_type (type);
1928 /* Given that TYPE encodes a packed array type (constrained or unconstrained),
1929 return the size of its elements in bits. */
1932 decode_packed_array_bitsize (struct type *type)
1938 /* Access to arrays implemented as fat pointers are encoded as a typedef
1939 of the fat pointer type. We need the name of the fat pointer type
1940 to do the decoding, so strip the typedef layer. */
1941 if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
1942 type = ada_typedef_target_type (type);
1944 raw_name = ada_type_name (ada_check_typedef (type));
1946 raw_name = ada_type_name (desc_base_type (type));
1951 tail = strstr (raw_name, "___XP");
1952 gdb_assert (tail != NULL);
1954 if (sscanf (tail + sizeof ("___XP") - 1, "%ld", &bits) != 1)
1957 (_("could not understand bit size information on packed array"));
1964 /* Given that TYPE is a standard GDB array type with all bounds filled
1965 in, and that the element size of its ultimate scalar constituents
1966 (that is, either its elements, or, if it is an array of arrays, its
1967 elements' elements, etc.) is *ELT_BITS, return an identical type,
1968 but with the bit sizes of its elements (and those of any
1969 constituent arrays) recorded in the BITSIZE components of its
1970 TYPE_FIELD_BITSIZE values, and with *ELT_BITS set to its total size
1973 static struct type *
1974 constrained_packed_array_type (struct type *type, long *elt_bits)
1976 struct type *new_elt_type;
1977 struct type *new_type;
1978 LONGEST low_bound, high_bound;
1980 type = ada_check_typedef (type);
1981 if (TYPE_CODE (type) != TYPE_CODE_ARRAY)
1984 new_type = alloc_type_copy (type);
1986 constrained_packed_array_type (ada_check_typedef (TYPE_TARGET_TYPE (type)),
1988 create_array_type (new_type, new_elt_type, TYPE_INDEX_TYPE (type));
1989 TYPE_FIELD_BITSIZE (new_type, 0) = *elt_bits;
1990 TYPE_NAME (new_type) = ada_type_name (type);
1992 if (get_discrete_bounds (TYPE_INDEX_TYPE (type),
1993 &low_bound, &high_bound) < 0)
1994 low_bound = high_bound = 0;
1995 if (high_bound < low_bound)
1996 *elt_bits = TYPE_LENGTH (new_type) = 0;
1999 *elt_bits *= (high_bound - low_bound + 1);
2000 TYPE_LENGTH (new_type) =
2001 (*elt_bits + HOST_CHAR_BIT - 1) / HOST_CHAR_BIT;
2004 TYPE_FIXED_INSTANCE (new_type) = 1;
2008 /* The array type encoded by TYPE, where
2009 ada_is_constrained_packed_array_type (TYPE). */
2011 static struct type *
2012 decode_constrained_packed_array_type (struct type *type)
2014 char *raw_name = ada_type_name (ada_check_typedef (type));
2017 struct type *shadow_type;
2021 raw_name = ada_type_name (desc_base_type (type));
2026 name = (char *) alloca (strlen (raw_name) + 1);
2027 tail = strstr (raw_name, "___XP");
2028 type = desc_base_type (type);
2030 memcpy (name, raw_name, tail - raw_name);
2031 name[tail - raw_name] = '\000';
2033 shadow_type = ada_find_parallel_type_with_name (type, name);
2035 if (shadow_type == NULL)
2037 lim_warning (_("could not find bounds information on packed array"));
2040 CHECK_TYPEDEF (shadow_type);
2042 if (TYPE_CODE (shadow_type) != TYPE_CODE_ARRAY)
2044 lim_warning (_("could not understand bounds "
2045 "information on packed array"));
2049 bits = decode_packed_array_bitsize (type);
2050 return constrained_packed_array_type (shadow_type, &bits);
2053 /* Given that ARR is a struct value *indicating a GNAT constrained packed
2054 array, returns a simple array that denotes that array. Its type is a
2055 standard GDB array type except that the BITSIZEs of the array
2056 target types are set to the number of bits in each element, and the
2057 type length is set appropriately. */
2059 static struct value *
2060 decode_constrained_packed_array (struct value *arr)
2064 arr = ada_coerce_ref (arr);
2066 /* If our value is a pointer, then dererence it. Make sure that
2067 this operation does not cause the target type to be fixed, as
2068 this would indirectly cause this array to be decoded. The rest
2069 of the routine assumes that the array hasn't been decoded yet,
2070 so we use the basic "value_ind" routine to perform the dereferencing,
2071 as opposed to using "ada_value_ind". */
2072 if (TYPE_CODE (value_type (arr)) == TYPE_CODE_PTR)
2073 arr = value_ind (arr);
2075 type = decode_constrained_packed_array_type (value_type (arr));
2078 error (_("can't unpack array"));
2082 if (gdbarch_bits_big_endian (get_type_arch (value_type (arr)))
2083 && ada_is_modular_type (value_type (arr)))
2085 /* This is a (right-justified) modular type representing a packed
2086 array with no wrapper. In order to interpret the value through
2087 the (left-justified) packed array type we just built, we must
2088 first left-justify it. */
2089 int bit_size, bit_pos;
2092 mod = ada_modulus (value_type (arr)) - 1;
2099 bit_pos = HOST_CHAR_BIT * TYPE_LENGTH (value_type (arr)) - bit_size;
2100 arr = ada_value_primitive_packed_val (arr, NULL,
2101 bit_pos / HOST_CHAR_BIT,
2102 bit_pos % HOST_CHAR_BIT,
2107 return coerce_unspec_val_to_type (arr, type);
2111 /* The value of the element of packed array ARR at the ARITY indices
2112 given in IND. ARR must be a simple array. */
2114 static struct value *
2115 value_subscript_packed (struct value *arr, int arity, struct value **ind)
2118 int bits, elt_off, bit_off;
2119 long elt_total_bit_offset;
2120 struct type *elt_type;
2124 elt_total_bit_offset = 0;
2125 elt_type = ada_check_typedef (value_type (arr));
2126 for (i = 0; i < arity; i += 1)
2128 if (TYPE_CODE (elt_type) != TYPE_CODE_ARRAY
2129 || TYPE_FIELD_BITSIZE (elt_type, 0) == 0)
2131 (_("attempt to do packed indexing of "
2132 "something other than a packed array"));
2135 struct type *range_type = TYPE_INDEX_TYPE (elt_type);
2136 LONGEST lowerbound, upperbound;
2139 if (get_discrete_bounds (range_type, &lowerbound, &upperbound) < 0)
2141 lim_warning (_("don't know bounds of array"));
2142 lowerbound = upperbound = 0;
2145 idx = pos_atr (ind[i]);
2146 if (idx < lowerbound || idx > upperbound)
2147 lim_warning (_("packed array index %ld out of bounds"),
2149 bits = TYPE_FIELD_BITSIZE (elt_type, 0);
2150 elt_total_bit_offset += (idx - lowerbound) * bits;
2151 elt_type = ada_check_typedef (TYPE_TARGET_TYPE (elt_type));
2154 elt_off = elt_total_bit_offset / HOST_CHAR_BIT;
2155 bit_off = elt_total_bit_offset % HOST_CHAR_BIT;
2157 v = ada_value_primitive_packed_val (arr, NULL, elt_off, bit_off,
2162 /* Non-zero iff TYPE includes negative integer values. */
2165 has_negatives (struct type *type)
2167 switch (TYPE_CODE (type))
2172 return !TYPE_UNSIGNED (type);
2173 case TYPE_CODE_RANGE:
2174 return TYPE_LOW_BOUND (type) < 0;
2179 /* Create a new value of type TYPE from the contents of OBJ starting
2180 at byte OFFSET, and bit offset BIT_OFFSET within that byte,
2181 proceeding for BIT_SIZE bits. If OBJ is an lval in memory, then
2182 assigning through the result will set the field fetched from.
2183 VALADDR is ignored unless OBJ is NULL, in which case,
2184 VALADDR+OFFSET must address the start of storage containing the
2185 packed value. The value returned in this case is never an lval.
2186 Assumes 0 <= BIT_OFFSET < HOST_CHAR_BIT. */
2189 ada_value_primitive_packed_val (struct value *obj, const gdb_byte *valaddr,
2190 long offset, int bit_offset, int bit_size,
2194 int src, /* Index into the source area */
2195 targ, /* Index into the target area */
2196 srcBitsLeft, /* Number of source bits left to move */
2197 nsrc, ntarg, /* Number of source and target bytes */
2198 unusedLS, /* Number of bits in next significant
2199 byte of source that are unused */
2200 accumSize; /* Number of meaningful bits in accum */
2201 unsigned char *bytes; /* First byte containing data to unpack */
2202 unsigned char *unpacked;
2203 unsigned long accum; /* Staging area for bits being transferred */
2205 int len = (bit_size + bit_offset + HOST_CHAR_BIT - 1) / 8;
2206 /* Transmit bytes from least to most significant; delta is the direction
2207 the indices move. */
2208 int delta = gdbarch_bits_big_endian (get_type_arch (type)) ? -1 : 1;
2210 type = ada_check_typedef (type);
2214 v = allocate_value (type);
2215 bytes = (unsigned char *) (valaddr + offset);
2217 else if (VALUE_LVAL (obj) == lval_memory && value_lazy (obj))
2220 value_address (obj) + offset);
2221 bytes = (unsigned char *) alloca (len);
2222 read_memory (value_address (v), bytes, len);
2226 v = allocate_value (type);
2227 bytes = (unsigned char *) value_contents (obj) + offset;
2234 set_value_component_location (v, obj);
2235 new_addr = value_address (obj) + offset;
2236 set_value_bitpos (v, bit_offset + value_bitpos (obj));
2237 set_value_bitsize (v, bit_size);
2238 if (value_bitpos (v) >= HOST_CHAR_BIT)
2241 set_value_bitpos (v, value_bitpos (v) - HOST_CHAR_BIT);
2243 set_value_address (v, new_addr);
2246 set_value_bitsize (v, bit_size);
2247 unpacked = (unsigned char *) value_contents (v);
2249 srcBitsLeft = bit_size;
2251 ntarg = TYPE_LENGTH (type);
2255 memset (unpacked, 0, TYPE_LENGTH (type));
2258 else if (gdbarch_bits_big_endian (get_type_arch (type)))
2261 if (has_negatives (type)
2262 && ((bytes[0] << bit_offset) & (1 << (HOST_CHAR_BIT - 1))))
2266 (HOST_CHAR_BIT - (bit_size + bit_offset) % HOST_CHAR_BIT)
2269 switch (TYPE_CODE (type))
2271 case TYPE_CODE_ARRAY:
2272 case TYPE_CODE_UNION:
2273 case TYPE_CODE_STRUCT:
2274 /* Non-scalar values must be aligned at a byte boundary... */
2276 (HOST_CHAR_BIT - bit_size % HOST_CHAR_BIT) % HOST_CHAR_BIT;
2277 /* ... And are placed at the beginning (most-significant) bytes
2279 targ = (bit_size + HOST_CHAR_BIT - 1) / HOST_CHAR_BIT - 1;
2284 targ = TYPE_LENGTH (type) - 1;
2290 int sign_bit_offset = (bit_size + bit_offset - 1) % 8;
2293 unusedLS = bit_offset;
2296 if (has_negatives (type) && (bytes[len - 1] & (1 << sign_bit_offset)))
2303 /* Mask for removing bits of the next source byte that are not
2304 part of the value. */
2305 unsigned int unusedMSMask =
2306 (1 << (srcBitsLeft >= HOST_CHAR_BIT ? HOST_CHAR_BIT : srcBitsLeft)) -
2308 /* Sign-extend bits for this byte. */
2309 unsigned int signMask = sign & ~unusedMSMask;
2312 (((bytes[src] >> unusedLS) & unusedMSMask) | signMask) << accumSize;
2313 accumSize += HOST_CHAR_BIT - unusedLS;
2314 if (accumSize >= HOST_CHAR_BIT)
2316 unpacked[targ] = accum & ~(~0L << HOST_CHAR_BIT);
2317 accumSize -= HOST_CHAR_BIT;
2318 accum >>= HOST_CHAR_BIT;
2322 srcBitsLeft -= HOST_CHAR_BIT - unusedLS;
2329 accum |= sign << accumSize;
2330 unpacked[targ] = accum & ~(~0L << HOST_CHAR_BIT);
2331 accumSize -= HOST_CHAR_BIT;
2332 accum >>= HOST_CHAR_BIT;
2340 /* Move N bits from SOURCE, starting at bit offset SRC_OFFSET to
2341 TARGET, starting at bit offset TARG_OFFSET. SOURCE and TARGET must
2344 move_bits (gdb_byte *target, int targ_offset, const gdb_byte *source,
2345 int src_offset, int n, int bits_big_endian_p)
2347 unsigned int accum, mask;
2348 int accum_bits, chunk_size;
2350 target += targ_offset / HOST_CHAR_BIT;
2351 targ_offset %= HOST_CHAR_BIT;
2352 source += src_offset / HOST_CHAR_BIT;
2353 src_offset %= HOST_CHAR_BIT;
2354 if (bits_big_endian_p)
2356 accum = (unsigned char) *source;
2358 accum_bits = HOST_CHAR_BIT - src_offset;
2364 accum = (accum << HOST_CHAR_BIT) + (unsigned char) *source;
2365 accum_bits += HOST_CHAR_BIT;
2367 chunk_size = HOST_CHAR_BIT - targ_offset;
2370 unused_right = HOST_CHAR_BIT - (chunk_size + targ_offset);
2371 mask = ((1 << chunk_size) - 1) << unused_right;
2374 | ((accum >> (accum_bits - chunk_size - unused_right)) & mask);
2376 accum_bits -= chunk_size;
2383 accum = (unsigned char) *source >> src_offset;
2385 accum_bits = HOST_CHAR_BIT - src_offset;
2389 accum = accum + ((unsigned char) *source << accum_bits);
2390 accum_bits += HOST_CHAR_BIT;
2392 chunk_size = HOST_CHAR_BIT - targ_offset;
2395 mask = ((1 << chunk_size) - 1) << targ_offset;
2396 *target = (*target & ~mask) | ((accum << targ_offset) & mask);
2398 accum_bits -= chunk_size;
2399 accum >>= chunk_size;
2406 /* Store the contents of FROMVAL into the location of TOVAL.
2407 Return a new value with the location of TOVAL and contents of
2408 FROMVAL. Handles assignment into packed fields that have
2409 floating-point or non-scalar types. */
2411 static struct value *
2412 ada_value_assign (struct value *toval, struct value *fromval)
2414 struct type *type = value_type (toval);
2415 int bits = value_bitsize (toval);
2417 toval = ada_coerce_ref (toval);
2418 fromval = ada_coerce_ref (fromval);
2420 if (ada_is_direct_array_type (value_type (toval)))
2421 toval = ada_coerce_to_simple_array (toval);
2422 if (ada_is_direct_array_type (value_type (fromval)))
2423 fromval = ada_coerce_to_simple_array (fromval);
2425 if (!deprecated_value_modifiable (toval))
2426 error (_("Left operand of assignment is not a modifiable lvalue."));
2428 if (VALUE_LVAL (toval) == lval_memory
2430 && (TYPE_CODE (type) == TYPE_CODE_FLT
2431 || TYPE_CODE (type) == TYPE_CODE_STRUCT))
2433 int len = (value_bitpos (toval)
2434 + bits + HOST_CHAR_BIT - 1) / HOST_CHAR_BIT;
2436 char *buffer = (char *) alloca (len);
2438 CORE_ADDR to_addr = value_address (toval);
2440 if (TYPE_CODE (type) == TYPE_CODE_FLT)
2441 fromval = value_cast (type, fromval);
2443 read_memory (to_addr, buffer, len);
2444 from_size = value_bitsize (fromval);
2446 from_size = TYPE_LENGTH (value_type (fromval)) * TARGET_CHAR_BIT;
2447 if (gdbarch_bits_big_endian (get_type_arch (type)))
2448 move_bits (buffer, value_bitpos (toval),
2449 value_contents (fromval), from_size - bits, bits, 1);
2451 move_bits (buffer, value_bitpos (toval),
2452 value_contents (fromval), 0, bits, 0);
2453 write_memory (to_addr, buffer, len);
2454 observer_notify_memory_changed (to_addr, len, buffer);
2456 val = value_copy (toval);
2457 memcpy (value_contents_raw (val), value_contents (fromval),
2458 TYPE_LENGTH (type));
2459 deprecated_set_value_type (val, type);
2464 return value_assign (toval, fromval);
2468 /* Given that COMPONENT is a memory lvalue that is part of the lvalue
2469 * CONTAINER, assign the contents of VAL to COMPONENTS's place in
2470 * CONTAINER. Modifies the VALUE_CONTENTS of CONTAINER only, not
2471 * COMPONENT, and not the inferior's memory. The current contents
2472 * of COMPONENT are ignored. */
2474 value_assign_to_component (struct value *container, struct value *component,
2477 LONGEST offset_in_container =
2478 (LONGEST) (value_address (component) - value_address (container));
2479 int bit_offset_in_container =
2480 value_bitpos (component) - value_bitpos (container);
2483 val = value_cast (value_type (component), val);
2485 if (value_bitsize (component) == 0)
2486 bits = TARGET_CHAR_BIT * TYPE_LENGTH (value_type (component));
2488 bits = value_bitsize (component);
2490 if (gdbarch_bits_big_endian (get_type_arch (value_type (container))))
2491 move_bits (value_contents_writeable (container) + offset_in_container,
2492 value_bitpos (container) + bit_offset_in_container,
2493 value_contents (val),
2494 TYPE_LENGTH (value_type (component)) * TARGET_CHAR_BIT - bits,
2497 move_bits (value_contents_writeable (container) + offset_in_container,
2498 value_bitpos (container) + bit_offset_in_container,
2499 value_contents (val), 0, bits, 0);
2502 /* The value of the element of array ARR at the ARITY indices given in IND.
2503 ARR may be either a simple array, GNAT array descriptor, or pointer
2507 ada_value_subscript (struct value *arr, int arity, struct value **ind)
2511 struct type *elt_type;
2513 elt = ada_coerce_to_simple_array (arr);
2515 elt_type = ada_check_typedef (value_type (elt));
2516 if (TYPE_CODE (elt_type) == TYPE_CODE_ARRAY
2517 && TYPE_FIELD_BITSIZE (elt_type, 0) > 0)
2518 return value_subscript_packed (elt, arity, ind);
2520 for (k = 0; k < arity; k += 1)
2522 if (TYPE_CODE (elt_type) != TYPE_CODE_ARRAY)
2523 error (_("too many subscripts (%d expected)"), k);
2524 elt = value_subscript (elt, pos_atr (ind[k]));
2529 /* Assuming ARR is a pointer to a standard GDB array of type TYPE, the
2530 value of the element of *ARR at the ARITY indices given in
2531 IND. Does not read the entire array into memory. */
2533 static struct value *
2534 ada_value_ptr_subscript (struct value *arr, struct type *type, int arity,
2539 for (k = 0; k < arity; k += 1)
2543 if (TYPE_CODE (type) != TYPE_CODE_ARRAY)
2544 error (_("too many subscripts (%d expected)"), k);
2545 arr = value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
2547 get_discrete_bounds (TYPE_INDEX_TYPE (type), &lwb, &upb);
2548 arr = value_ptradd (arr, pos_atr (ind[k]) - lwb);
2549 type = TYPE_TARGET_TYPE (type);
2552 return value_ind (arr);
2555 /* Given that ARRAY_PTR is a pointer or reference to an array of type TYPE (the
2556 actual type of ARRAY_PTR is ignored), returns the Ada slice of HIGH-LOW+1
2557 elements starting at index LOW. The lower bound of this array is LOW, as
2559 static struct value *
2560 ada_value_slice_from_ptr (struct value *array_ptr, struct type *type,
2563 CORE_ADDR base = value_as_address (array_ptr)
2564 + ((low - ada_discrete_type_low_bound (TYPE_INDEX_TYPE (type)))
2565 * TYPE_LENGTH (TYPE_TARGET_TYPE (type)));
2566 struct type *index_type =
2567 create_range_type (NULL, TYPE_TARGET_TYPE (TYPE_INDEX_TYPE (type)),
2569 struct type *slice_type =
2570 create_array_type (NULL, TYPE_TARGET_TYPE (type), index_type);
2572 return value_at_lazy (slice_type, base);
2576 static struct value *
2577 ada_value_slice (struct value *array, int low, int high)
2579 struct type *type = value_type (array);
2580 struct type *index_type =
2581 create_range_type (NULL, TYPE_INDEX_TYPE (type), low, high);
2582 struct type *slice_type =
2583 create_array_type (NULL, TYPE_TARGET_TYPE (type), index_type);
2585 return value_cast (slice_type, value_slice (array, low, high - low + 1));
2588 /* If type is a record type in the form of a standard GNAT array
2589 descriptor, returns the number of dimensions for type. If arr is a
2590 simple array, returns the number of "array of"s that prefix its
2591 type designation. Otherwise, returns 0. */
2594 ada_array_arity (struct type *type)
2601 type = desc_base_type (type);
2604 if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
2605 return desc_arity (desc_bounds_type (type));
2607 while (TYPE_CODE (type) == TYPE_CODE_ARRAY)
2610 type = ada_check_typedef (TYPE_TARGET_TYPE (type));
2616 /* If TYPE is a record type in the form of a standard GNAT array
2617 descriptor or a simple array type, returns the element type for
2618 TYPE after indexing by NINDICES indices, or by all indices if
2619 NINDICES is -1. Otherwise, returns NULL. */
2622 ada_array_element_type (struct type *type, int nindices)
2624 type = desc_base_type (type);
2626 if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
2629 struct type *p_array_type;
2631 p_array_type = desc_data_target_type (type);
2633 k = ada_array_arity (type);
2637 /* Initially p_array_type = elt_type(*)[]...(k times)...[]. */
2638 if (nindices >= 0 && k > nindices)
2640 while (k > 0 && p_array_type != NULL)
2642 p_array_type = ada_check_typedef (TYPE_TARGET_TYPE (p_array_type));
2645 return p_array_type;
2647 else if (TYPE_CODE (type) == TYPE_CODE_ARRAY)
2649 while (nindices != 0 && TYPE_CODE (type) == TYPE_CODE_ARRAY)
2651 type = TYPE_TARGET_TYPE (type);
2660 /* The type of nth index in arrays of given type (n numbering from 1).
2661 Does not examine memory. Throws an error if N is invalid or TYPE
2662 is not an array type. NAME is the name of the Ada attribute being
2663 evaluated ('range, 'first, 'last, or 'length); it is used in building
2664 the error message. */
2666 static struct type *
2667 ada_index_type (struct type *type, int n, const char *name)
2669 struct type *result_type;
2671 type = desc_base_type (type);
2673 if (n < 0 || n > ada_array_arity (type))
2674 error (_("invalid dimension number to '%s"), name);
2676 if (ada_is_simple_array_type (type))
2680 for (i = 1; i < n; i += 1)
2681 type = TYPE_TARGET_TYPE (type);
2682 result_type = TYPE_TARGET_TYPE (TYPE_INDEX_TYPE (type));
2683 /* FIXME: The stabs type r(0,0);bound;bound in an array type
2684 has a target type of TYPE_CODE_UNDEF. We compensate here, but
2685 perhaps stabsread.c would make more sense. */
2686 if (result_type && TYPE_CODE (result_type) == TYPE_CODE_UNDEF)
2691 result_type = desc_index_type (desc_bounds_type (type), n);
2692 if (result_type == NULL)
2693 error (_("attempt to take bound of something that is not an array"));
2699 /* Given that arr is an array type, returns the lower bound of the
2700 Nth index (numbering from 1) if WHICH is 0, and the upper bound if
2701 WHICH is 1. This returns bounds 0 .. -1 if ARR_TYPE is an
2702 array-descriptor type. It works for other arrays with bounds supplied
2703 by run-time quantities other than discriminants. */
2706 ada_array_bound_from_type (struct type * arr_type, int n, int which)
2708 struct type *type, *elt_type, *index_type_desc, *index_type;
2711 gdb_assert (which == 0 || which == 1);
2713 if (ada_is_constrained_packed_array_type (arr_type))
2714 arr_type = decode_constrained_packed_array_type (arr_type);
2716 if (arr_type == NULL || !ada_is_simple_array_type (arr_type))
2717 return (LONGEST) - which;
2719 if (TYPE_CODE (arr_type) == TYPE_CODE_PTR)
2720 type = TYPE_TARGET_TYPE (arr_type);
2725 for (i = n; i > 1; i--)
2726 elt_type = TYPE_TARGET_TYPE (type);
2728 index_type_desc = ada_find_parallel_type (type, "___XA");
2729 ada_fixup_array_indexes_type (index_type_desc);
2730 if (index_type_desc != NULL)
2731 index_type = to_fixed_range_type (TYPE_FIELD_TYPE (index_type_desc, n - 1),
2734 index_type = TYPE_INDEX_TYPE (elt_type);
2737 (LONGEST) (which == 0
2738 ? ada_discrete_type_low_bound (index_type)
2739 : ada_discrete_type_high_bound (index_type));
2742 /* Given that arr is an array value, returns the lower bound of the
2743 nth index (numbering from 1) if WHICH is 0, and the upper bound if
2744 WHICH is 1. This routine will also work for arrays with bounds
2745 supplied by run-time quantities other than discriminants. */
2748 ada_array_bound (struct value *arr, int n, int which)
2750 struct type *arr_type = value_type (arr);
2752 if (ada_is_constrained_packed_array_type (arr_type))
2753 return ada_array_bound (decode_constrained_packed_array (arr), n, which);
2754 else if (ada_is_simple_array_type (arr_type))
2755 return ada_array_bound_from_type (arr_type, n, which);
2757 return value_as_long (desc_one_bound (desc_bounds (arr), n, which));
2760 /* Given that arr is an array value, returns the length of the
2761 nth index. This routine will also work for arrays with bounds
2762 supplied by run-time quantities other than discriminants.
2763 Does not work for arrays indexed by enumeration types with representation
2764 clauses at the moment. */
2767 ada_array_length (struct value *arr, int n)
2769 struct type *arr_type = ada_check_typedef (value_type (arr));
2771 if (ada_is_constrained_packed_array_type (arr_type))
2772 return ada_array_length (decode_constrained_packed_array (arr), n);
2774 if (ada_is_simple_array_type (arr_type))
2775 return (ada_array_bound_from_type (arr_type, n, 1)
2776 - ada_array_bound_from_type (arr_type, n, 0) + 1);
2778 return (value_as_long (desc_one_bound (desc_bounds (arr), n, 1))
2779 - value_as_long (desc_one_bound (desc_bounds (arr), n, 0)) + 1);
2782 /* An empty array whose type is that of ARR_TYPE (an array type),
2783 with bounds LOW to LOW-1. */
2785 static struct value *
2786 empty_array (struct type *arr_type, int low)
2788 struct type *index_type =
2789 create_range_type (NULL, TYPE_TARGET_TYPE (TYPE_INDEX_TYPE (arr_type)),
2791 struct type *elt_type = ada_array_element_type (arr_type, 1);
2793 return allocate_value (create_array_type (NULL, elt_type, index_type));
2797 /* Name resolution */
2799 /* The "decoded" name for the user-definable Ada operator corresponding
2803 ada_decoded_op_name (enum exp_opcode op)
2807 for (i = 0; ada_opname_table[i].encoded != NULL; i += 1)
2809 if (ada_opname_table[i].op == op)
2810 return ada_opname_table[i].decoded;
2812 error (_("Could not find operator name for opcode"));
2816 /* Same as evaluate_type (*EXP), but resolves ambiguous symbol
2817 references (marked by OP_VAR_VALUE nodes in which the symbol has an
2818 undefined namespace) and converts operators that are
2819 user-defined into appropriate function calls. If CONTEXT_TYPE is
2820 non-null, it provides a preferred result type [at the moment, only
2821 type void has any effect---causing procedures to be preferred over
2822 functions in calls]. A null CONTEXT_TYPE indicates that a non-void
2823 return type is preferred. May change (expand) *EXP. */
2826 resolve (struct expression **expp, int void_context_p)
2828 struct type *context_type = NULL;
2832 context_type = builtin_type ((*expp)->gdbarch)->builtin_void;
2834 resolve_subexp (expp, &pc, 1, context_type);
2837 /* Resolve the operator of the subexpression beginning at
2838 position *POS of *EXPP. "Resolving" consists of replacing
2839 the symbols that have undefined namespaces in OP_VAR_VALUE nodes
2840 with their resolutions, replacing built-in operators with
2841 function calls to user-defined operators, where appropriate, and,
2842 when DEPROCEDURE_P is non-zero, converting function-valued variables
2843 into parameterless calls. May expand *EXPP. The CONTEXT_TYPE functions
2844 are as in ada_resolve, above. */
2846 static struct value *
2847 resolve_subexp (struct expression **expp, int *pos, int deprocedure_p,
2848 struct type *context_type)
2852 struct expression *exp; /* Convenience: == *expp. */
2853 enum exp_opcode op = (*expp)->elts[pc].opcode;
2854 struct value **argvec; /* Vector of operand types (alloca'ed). */
2855 int nargs; /* Number of operands. */
2862 /* Pass one: resolve operands, saving their types and updating *pos,
2867 if (exp->elts[pc + 3].opcode == OP_VAR_VALUE
2868 && SYMBOL_DOMAIN (exp->elts[pc + 5].symbol) == UNDEF_DOMAIN)
2873 resolve_subexp (expp, pos, 0, NULL);
2875 nargs = longest_to_int (exp->elts[pc + 1].longconst);
2880 resolve_subexp (expp, pos, 0, NULL);
2885 resolve_subexp (expp, pos, 1, check_typedef (exp->elts[pc + 1].type));
2888 case OP_ATR_MODULUS:
2898 case TERNOP_IN_RANGE:
2899 case BINOP_IN_BOUNDS:
2905 case OP_DISCRETE_RANGE:
2907 ada_forward_operator_length (exp, pc, &oplen, &nargs);
2916 arg1 = resolve_subexp (expp, pos, 0, NULL);
2918 resolve_subexp (expp, pos, 1, NULL);
2920 resolve_subexp (expp, pos, 1, value_type (arg1));
2937 case BINOP_LOGICAL_AND:
2938 case BINOP_LOGICAL_OR:
2939 case BINOP_BITWISE_AND:
2940 case BINOP_BITWISE_IOR:
2941 case BINOP_BITWISE_XOR:
2944 case BINOP_NOTEQUAL:
2951 case BINOP_SUBSCRIPT:
2959 case UNOP_LOGICAL_NOT:
2975 case OP_INTERNALVAR:
2985 *pos += 4 + BYTES_TO_EXP_ELEM (exp->elts[pc + 1].longconst + 1);
2988 case STRUCTOP_STRUCT:
2989 *pos += 4 + BYTES_TO_EXP_ELEM (exp->elts[pc + 1].longconst + 1);
3002 error (_("Unexpected operator during name resolution"));
3005 argvec = (struct value * *) alloca (sizeof (struct value *) * (nargs + 1));
3006 for (i = 0; i < nargs; i += 1)
3007 argvec[i] = resolve_subexp (expp, pos, 1, NULL);
3011 /* Pass two: perform any resolution on principal operator. */
3018 if (SYMBOL_DOMAIN (exp->elts[pc + 2].symbol) == UNDEF_DOMAIN)
3020 struct ada_symbol_info *candidates;
3024 ada_lookup_symbol_list (SYMBOL_LINKAGE_NAME
3025 (exp->elts[pc + 2].symbol),
3026 exp->elts[pc + 1].block, VAR_DOMAIN,
3029 if (n_candidates > 1)
3031 /* Types tend to get re-introduced locally, so if there
3032 are any local symbols that are not types, first filter
3035 for (j = 0; j < n_candidates; j += 1)
3036 switch (SYMBOL_CLASS (candidates[j].sym))
3041 case LOC_REGPARM_ADDR:
3049 if (j < n_candidates)
3052 while (j < n_candidates)
3054 if (SYMBOL_CLASS (candidates[j].sym) == LOC_TYPEDEF)
3056 candidates[j] = candidates[n_candidates - 1];
3065 if (n_candidates == 0)
3066 error (_("No definition found for %s"),
3067 SYMBOL_PRINT_NAME (exp->elts[pc + 2].symbol));
3068 else if (n_candidates == 1)
3070 else if (deprocedure_p
3071 && !is_nonfunction (candidates, n_candidates))
3073 i = ada_resolve_function
3074 (candidates, n_candidates, NULL, 0,
3075 SYMBOL_LINKAGE_NAME (exp->elts[pc + 2].symbol),
3078 error (_("Could not find a match for %s"),
3079 SYMBOL_PRINT_NAME (exp->elts[pc + 2].symbol));
3083 printf_filtered (_("Multiple matches for %s\n"),
3084 SYMBOL_PRINT_NAME (exp->elts[pc + 2].symbol));
3085 user_select_syms (candidates, n_candidates, 1);
3089 exp->elts[pc + 1].block = candidates[i].block;
3090 exp->elts[pc + 2].symbol = candidates[i].sym;
3091 if (innermost_block == NULL
3092 || contained_in (candidates[i].block, innermost_block))
3093 innermost_block = candidates[i].block;
3097 && (TYPE_CODE (SYMBOL_TYPE (exp->elts[pc + 2].symbol))
3100 replace_operator_with_call (expp, pc, 0, 0,
3101 exp->elts[pc + 2].symbol,
3102 exp->elts[pc + 1].block);
3109 if (exp->elts[pc + 3].opcode == OP_VAR_VALUE
3110 && SYMBOL_DOMAIN (exp->elts[pc + 5].symbol) == UNDEF_DOMAIN)
3112 struct ada_symbol_info *candidates;
3116 ada_lookup_symbol_list (SYMBOL_LINKAGE_NAME
3117 (exp->elts[pc + 5].symbol),
3118 exp->elts[pc + 4].block, VAR_DOMAIN,
3120 if (n_candidates == 1)
3124 i = ada_resolve_function
3125 (candidates, n_candidates,
3127 SYMBOL_LINKAGE_NAME (exp->elts[pc + 5].symbol),
3130 error (_("Could not find a match for %s"),
3131 SYMBOL_PRINT_NAME (exp->elts[pc + 5].symbol));
3134 exp->elts[pc + 4].block = candidates[i].block;
3135 exp->elts[pc + 5].symbol = candidates[i].sym;
3136 if (innermost_block == NULL
3137 || contained_in (candidates[i].block, innermost_block))
3138 innermost_block = candidates[i].block;
3149 case BINOP_BITWISE_AND:
3150 case BINOP_BITWISE_IOR:
3151 case BINOP_BITWISE_XOR:
3153 case BINOP_NOTEQUAL:
3161 case UNOP_LOGICAL_NOT:
3163 if (possible_user_operator_p (op, argvec))
3165 struct ada_symbol_info *candidates;
3169 ada_lookup_symbol_list (ada_encode (ada_decoded_op_name (op)),
3170 (struct block *) NULL, VAR_DOMAIN,
3172 i = ada_resolve_function (candidates, n_candidates, argvec, nargs,
3173 ada_decoded_op_name (op), NULL);
3177 replace_operator_with_call (expp, pc, nargs, 1,
3178 candidates[i].sym, candidates[i].block);
3189 return evaluate_subexp_type (exp, pos);
3192 /* Return non-zero if formal type FTYPE matches actual type ATYPE. If
3193 MAY_DEREF is non-zero, the formal may be a pointer and the actual
3195 /* The term "match" here is rather loose. The match is heuristic and
3199 ada_type_match (struct type *ftype, struct type *atype, int may_deref)
3201 ftype = ada_check_typedef (ftype);
3202 atype = ada_check_typedef (atype);
3204 if (TYPE_CODE (ftype) == TYPE_CODE_REF)
3205 ftype = TYPE_TARGET_TYPE (ftype);
3206 if (TYPE_CODE (atype) == TYPE_CODE_REF)
3207 atype = TYPE_TARGET_TYPE (atype);
3209 switch (TYPE_CODE (ftype))
3212 return TYPE_CODE (ftype) == TYPE_CODE (atype);
3214 if (TYPE_CODE (atype) == TYPE_CODE_PTR)
3215 return ada_type_match (TYPE_TARGET_TYPE (ftype),
3216 TYPE_TARGET_TYPE (atype), 0);
3219 && ada_type_match (TYPE_TARGET_TYPE (ftype), atype, 0));
3221 case TYPE_CODE_ENUM:
3222 case TYPE_CODE_RANGE:
3223 switch (TYPE_CODE (atype))
3226 case TYPE_CODE_ENUM:
3227 case TYPE_CODE_RANGE:
3233 case TYPE_CODE_ARRAY:
3234 return (TYPE_CODE (atype) == TYPE_CODE_ARRAY
3235 || ada_is_array_descriptor_type (atype));
3237 case TYPE_CODE_STRUCT:
3238 if (ada_is_array_descriptor_type (ftype))
3239 return (TYPE_CODE (atype) == TYPE_CODE_ARRAY
3240 || ada_is_array_descriptor_type (atype));
3242 return (TYPE_CODE (atype) == TYPE_CODE_STRUCT
3243 && !ada_is_array_descriptor_type (atype));
3245 case TYPE_CODE_UNION:
3247 return (TYPE_CODE (atype) == TYPE_CODE (ftype));
3251 /* Return non-zero if the formals of FUNC "sufficiently match" the
3252 vector of actual argument types ACTUALS of size N_ACTUALS. FUNC
3253 may also be an enumeral, in which case it is treated as a 0-
3254 argument function. */
3257 ada_args_match (struct symbol *func, struct value **actuals, int n_actuals)
3260 struct type *func_type = SYMBOL_TYPE (func);
3262 if (SYMBOL_CLASS (func) == LOC_CONST
3263 && TYPE_CODE (func_type) == TYPE_CODE_ENUM)
3264 return (n_actuals == 0);
3265 else if (func_type == NULL || TYPE_CODE (func_type) != TYPE_CODE_FUNC)
3268 if (TYPE_NFIELDS (func_type) != n_actuals)
3271 for (i = 0; i < n_actuals; i += 1)
3273 if (actuals[i] == NULL)
3277 struct type *ftype = ada_check_typedef (TYPE_FIELD_TYPE (func_type,
3279 struct type *atype = ada_check_typedef (value_type (actuals[i]));
3281 if (!ada_type_match (ftype, atype, 1))
3288 /* False iff function type FUNC_TYPE definitely does not produce a value
3289 compatible with type CONTEXT_TYPE. Conservatively returns 1 if
3290 FUNC_TYPE is not a valid function type with a non-null return type
3291 or an enumerated type. A null CONTEXT_TYPE indicates any non-void type. */
3294 return_match (struct type *func_type, struct type *context_type)
3296 struct type *return_type;
3298 if (func_type == NULL)
3301 if (TYPE_CODE (func_type) == TYPE_CODE_FUNC)
3302 return_type = base_type (TYPE_TARGET_TYPE (func_type));
3304 return_type = base_type (func_type);
3305 if (return_type == NULL)
3308 context_type = base_type (context_type);
3310 if (TYPE_CODE (return_type) == TYPE_CODE_ENUM)
3311 return context_type == NULL || return_type == context_type;
3312 else if (context_type == NULL)
3313 return TYPE_CODE (return_type) != TYPE_CODE_VOID;
3315 return TYPE_CODE (return_type) == TYPE_CODE (context_type);
3319 /* Returns the index in SYMS[0..NSYMS-1] that contains the symbol for the
3320 function (if any) that matches the types of the NARGS arguments in
3321 ARGS. If CONTEXT_TYPE is non-null and there is at least one match
3322 that returns that type, then eliminate matches that don't. If
3323 CONTEXT_TYPE is void and there is at least one match that does not
3324 return void, eliminate all matches that do.
3326 Asks the user if there is more than one match remaining. Returns -1
3327 if there is no such symbol or none is selected. NAME is used
3328 solely for messages. May re-arrange and modify SYMS in
3329 the process; the index returned is for the modified vector. */
3332 ada_resolve_function (struct ada_symbol_info syms[],
3333 int nsyms, struct value **args, int nargs,
3334 const char *name, struct type *context_type)
3338 int m; /* Number of hits */
3341 /* In the first pass of the loop, we only accept functions matching
3342 context_type. If none are found, we add a second pass of the loop
3343 where every function is accepted. */
3344 for (fallback = 0; m == 0 && fallback < 2; fallback++)
3346 for (k = 0; k < nsyms; k += 1)
3348 struct type *type = ada_check_typedef (SYMBOL_TYPE (syms[k].sym));
3350 if (ada_args_match (syms[k].sym, args, nargs)
3351 && (fallback || return_match (type, context_type)))
3363 printf_filtered (_("Multiple matches for %s\n"), name);
3364 user_select_syms (syms, m, 1);
3370 /* Returns true (non-zero) iff decoded name N0 should appear before N1
3371 in a listing of choices during disambiguation (see sort_choices, below).
3372 The idea is that overloadings of a subprogram name from the
3373 same package should sort in their source order. We settle for ordering
3374 such symbols by their trailing number (__N or $N). */
3377 encoded_ordered_before (char *N0, char *N1)
3381 else if (N0 == NULL)
3387 for (k0 = strlen (N0) - 1; k0 > 0 && isdigit (N0[k0]); k0 -= 1)
3389 for (k1 = strlen (N1) - 1; k1 > 0 && isdigit (N1[k1]); k1 -= 1)
3391 if ((N0[k0] == '_' || N0[k0] == '$') && N0[k0 + 1] != '\000'
3392 && (N1[k1] == '_' || N1[k1] == '$') && N1[k1 + 1] != '\000')
3397 while (N0[n0] == '_' && n0 > 0 && N0[n0 - 1] == '_')
3400 while (N1[n1] == '_' && n1 > 0 && N1[n1 - 1] == '_')
3402 if (n0 == n1 && strncmp (N0, N1, n0) == 0)
3403 return (atoi (N0 + k0 + 1) < atoi (N1 + k1 + 1));
3405 return (strcmp (N0, N1) < 0);
3409 /* Sort SYMS[0..NSYMS-1] to put the choices in a canonical order by the
3413 sort_choices (struct ada_symbol_info syms[], int nsyms)
3417 for (i = 1; i < nsyms; i += 1)
3419 struct ada_symbol_info sym = syms[i];
3422 for (j = i - 1; j >= 0; j -= 1)
3424 if (encoded_ordered_before (SYMBOL_LINKAGE_NAME (syms[j].sym),
3425 SYMBOL_LINKAGE_NAME (sym.sym)))
3427 syms[j + 1] = syms[j];
3433 /* Given a list of NSYMS symbols in SYMS, select up to MAX_RESULTS>0
3434 by asking the user (if necessary), returning the number selected,
3435 and setting the first elements of SYMS items. Error if no symbols
3438 /* NOTE: Adapted from decode_line_2 in symtab.c, with which it ought
3439 to be re-integrated one of these days. */
3442 user_select_syms (struct ada_symbol_info *syms, int nsyms, int max_results)
3445 int *chosen = (int *) alloca (sizeof (int) * nsyms);
3447 int first_choice = (max_results == 1) ? 1 : 2;
3448 const char *select_mode = multiple_symbols_select_mode ();
3450 if (max_results < 1)
3451 error (_("Request to select 0 symbols!"));
3455 if (select_mode == multiple_symbols_cancel)
3457 canceled because the command is ambiguous\n\
3458 See set/show multiple-symbol."));
3460 /* If select_mode is "all", then return all possible symbols.
3461 Only do that if more than one symbol can be selected, of course.
3462 Otherwise, display the menu as usual. */
3463 if (select_mode == multiple_symbols_all && max_results > 1)
3466 printf_unfiltered (_("[0] cancel\n"));
3467 if (max_results > 1)
3468 printf_unfiltered (_("[1] all\n"));
3470 sort_choices (syms, nsyms);
3472 for (i = 0; i < nsyms; i += 1)
3474 if (syms[i].sym == NULL)
3477 if (SYMBOL_CLASS (syms[i].sym) == LOC_BLOCK)
3479 struct symtab_and_line sal =
3480 find_function_start_sal (syms[i].sym, 1);
3482 if (sal.symtab == NULL)
3483 printf_unfiltered (_("[%d] %s at <no source file available>:%d\n"),
3485 SYMBOL_PRINT_NAME (syms[i].sym),
3488 printf_unfiltered (_("[%d] %s at %s:%d\n"), i + first_choice,
3489 SYMBOL_PRINT_NAME (syms[i].sym),
3490 sal.symtab->filename, sal.line);
3496 (SYMBOL_CLASS (syms[i].sym) == LOC_CONST
3497 && SYMBOL_TYPE (syms[i].sym) != NULL
3498 && TYPE_CODE (SYMBOL_TYPE (syms[i].sym)) == TYPE_CODE_ENUM);
3499 struct symtab *symtab = syms[i].sym->symtab;
3501 if (SYMBOL_LINE (syms[i].sym) != 0 && symtab != NULL)
3502 printf_unfiltered (_("[%d] %s at %s:%d\n"),
3504 SYMBOL_PRINT_NAME (syms[i].sym),
3505 symtab->filename, SYMBOL_LINE (syms[i].sym));
3506 else if (is_enumeral
3507 && TYPE_NAME (SYMBOL_TYPE (syms[i].sym)) != NULL)
3509 printf_unfiltered (("[%d] "), i + first_choice);
3510 ada_print_type (SYMBOL_TYPE (syms[i].sym), NULL,
3512 printf_unfiltered (_("'(%s) (enumeral)\n"),
3513 SYMBOL_PRINT_NAME (syms[i].sym));
3515 else if (symtab != NULL)
3516 printf_unfiltered (is_enumeral
3517 ? _("[%d] %s in %s (enumeral)\n")
3518 : _("[%d] %s at %s:?\n"),
3520 SYMBOL_PRINT_NAME (syms[i].sym),
3523 printf_unfiltered (is_enumeral
3524 ? _("[%d] %s (enumeral)\n")
3525 : _("[%d] %s at ?\n"),
3527 SYMBOL_PRINT_NAME (syms[i].sym));
3531 n_chosen = get_selections (chosen, nsyms, max_results, max_results > 1,
3534 for (i = 0; i < n_chosen; i += 1)
3535 syms[i] = syms[chosen[i]];
3540 /* Read and validate a set of numeric choices from the user in the
3541 range 0 .. N_CHOICES-1. Place the results in increasing
3542 order in CHOICES[0 .. N-1], and return N.
3544 The user types choices as a sequence of numbers on one line
3545 separated by blanks, encoding them as follows:
3547 + A choice of 0 means to cancel the selection, throwing an error.
3548 + If IS_ALL_CHOICE, a choice of 1 selects the entire set 0 .. N_CHOICES-1.
3549 + The user chooses k by typing k+IS_ALL_CHOICE+1.
3551 The user is not allowed to choose more than MAX_RESULTS values.
3553 ANNOTATION_SUFFIX, if present, is used to annotate the input
3554 prompts (for use with the -f switch). */
3557 get_selections (int *choices, int n_choices, int max_results,
3558 int is_all_choice, char *annotation_suffix)
3563 int first_choice = is_all_choice ? 2 : 1;
3565 prompt = getenv ("PS2");
3569 args = command_line_input (prompt, 0, annotation_suffix);
3572 error_no_arg (_("one or more choice numbers"));
3576 /* Set choices[0 .. n_chosen-1] to the users' choices in ascending
3577 order, as given in args. Choices are validated. */
3583 while (isspace (*args))
3585 if (*args == '\0' && n_chosen == 0)
3586 error_no_arg (_("one or more choice numbers"));
3587 else if (*args == '\0')
3590 choice = strtol (args, &args2, 10);
3591 if (args == args2 || choice < 0
3592 || choice > n_choices + first_choice - 1)
3593 error (_("Argument must be choice number"));
3597 error (_("cancelled"));
3599 if (choice < first_choice)
3601 n_chosen = n_choices;
3602 for (j = 0; j < n_choices; j += 1)
3606 choice -= first_choice;
3608 for (j = n_chosen - 1; j >= 0 && choice < choices[j]; j -= 1)
3612 if (j < 0 || choice != choices[j])
3616 for (k = n_chosen - 1; k > j; k -= 1)
3617 choices[k + 1] = choices[k];
3618 choices[j + 1] = choice;
3623 if (n_chosen > max_results)
3624 error (_("Select no more than %d of the above"), max_results);
3629 /* Replace the operator of length OPLEN at position PC in *EXPP with a call
3630 on the function identified by SYM and BLOCK, and taking NARGS
3631 arguments. Update *EXPP as needed to hold more space. */
3634 replace_operator_with_call (struct expression **expp, int pc, int nargs,
3635 int oplen, struct symbol *sym,
3636 struct block *block)
3638 /* A new expression, with 6 more elements (3 for funcall, 4 for function
3639 symbol, -oplen for operator being replaced). */
3640 struct expression *newexp = (struct expression *)
3641 xmalloc (sizeof (struct expression)
3642 + EXP_ELEM_TO_BYTES ((*expp)->nelts + 7 - oplen));
3643 struct expression *exp = *expp;
3645 newexp->nelts = exp->nelts + 7 - oplen;
3646 newexp->language_defn = exp->language_defn;
3647 memcpy (newexp->elts, exp->elts, EXP_ELEM_TO_BYTES (pc));
3648 memcpy (newexp->elts + pc + 7, exp->elts + pc + oplen,
3649 EXP_ELEM_TO_BYTES (exp->nelts - pc - oplen));
3651 newexp->elts[pc].opcode = newexp->elts[pc + 2].opcode = OP_FUNCALL;
3652 newexp->elts[pc + 1].longconst = (LONGEST) nargs;
3654 newexp->elts[pc + 3].opcode = newexp->elts[pc + 6].opcode = OP_VAR_VALUE;
3655 newexp->elts[pc + 4].block = block;
3656 newexp->elts[pc + 5].symbol = sym;
3662 /* Type-class predicates */
3664 /* True iff TYPE is numeric (i.e., an INT, RANGE (of numeric type),
3668 numeric_type_p (struct type *type)
3674 switch (TYPE_CODE (type))
3679 case TYPE_CODE_RANGE:
3680 return (type == TYPE_TARGET_TYPE (type)
3681 || numeric_type_p (TYPE_TARGET_TYPE (type)));
3688 /* True iff TYPE is integral (an INT or RANGE of INTs). */
3691 integer_type_p (struct type *type)
3697 switch (TYPE_CODE (type))
3701 case TYPE_CODE_RANGE:
3702 return (type == TYPE_TARGET_TYPE (type)
3703 || integer_type_p (TYPE_TARGET_TYPE (type)));
3710 /* True iff TYPE is scalar (INT, RANGE, FLOAT, ENUM). */
3713 scalar_type_p (struct type *type)
3719 switch (TYPE_CODE (type))
3722 case TYPE_CODE_RANGE:
3723 case TYPE_CODE_ENUM:
3732 /* True iff TYPE is discrete (INT, RANGE, ENUM). */
3735 discrete_type_p (struct type *type)
3741 switch (TYPE_CODE (type))
3744 case TYPE_CODE_RANGE:
3745 case TYPE_CODE_ENUM:
3746 case TYPE_CODE_BOOL:
3754 /* Returns non-zero if OP with operands in the vector ARGS could be
3755 a user-defined function. Errs on the side of pre-defined operators
3756 (i.e., result 0). */
3759 possible_user_operator_p (enum exp_opcode op, struct value *args[])
3761 struct type *type0 =
3762 (args[0] == NULL) ? NULL : ada_check_typedef (value_type (args[0]));
3763 struct type *type1 =
3764 (args[1] == NULL) ? NULL : ada_check_typedef (value_type (args[1]));
3778 return (!(numeric_type_p (type0) && numeric_type_p (type1)));
3782 case BINOP_BITWISE_AND:
3783 case BINOP_BITWISE_IOR:
3784 case BINOP_BITWISE_XOR:
3785 return (!(integer_type_p (type0) && integer_type_p (type1)));
3788 case BINOP_NOTEQUAL:
3793 return (!(scalar_type_p (type0) && scalar_type_p (type1)));
3796 return !ada_is_array_type (type0) || !ada_is_array_type (type1);
3799 return (!(numeric_type_p (type0) && integer_type_p (type1)));
3803 case UNOP_LOGICAL_NOT:
3805 return (!numeric_type_p (type0));
3814 1. In the following, we assume that a renaming type's name may
3815 have an ___XD suffix. It would be nice if this went away at some
3817 2. We handle both the (old) purely type-based representation of
3818 renamings and the (new) variable-based encoding. At some point,
3819 it is devoutly to be hoped that the former goes away
3820 (FIXME: hilfinger-2007-07-09).
3821 3. Subprogram renamings are not implemented, although the XRS
3822 suffix is recognized (FIXME: hilfinger-2007-07-09). */
3824 /* If SYM encodes a renaming,
3826 <renaming> renames <renamed entity>,
3828 sets *LEN to the length of the renamed entity's name,
3829 *RENAMED_ENTITY to that name (not null-terminated), and *RENAMING_EXPR to
3830 the string describing the subcomponent selected from the renamed
3831 entity. Returns ADA_NOT_RENAMING if SYM does not encode a renaming
3832 (in which case, the values of *RENAMED_ENTITY, *LEN, and *RENAMING_EXPR
3833 are undefined). Otherwise, returns a value indicating the category
3834 of entity renamed: an object (ADA_OBJECT_RENAMING), exception
3835 (ADA_EXCEPTION_RENAMING), package (ADA_PACKAGE_RENAMING), or
3836 subprogram (ADA_SUBPROGRAM_RENAMING). Does no allocation; the
3837 strings returned in *RENAMED_ENTITY and *RENAMING_EXPR should not be
3838 deallocated. The values of RENAMED_ENTITY, LEN, or RENAMING_EXPR
3839 may be NULL, in which case they are not assigned.
3841 [Currently, however, GCC does not generate subprogram renamings.] */
3843 enum ada_renaming_category
3844 ada_parse_renaming (struct symbol *sym,
3845 const char **renamed_entity, int *len,
3846 const char **renaming_expr)
3848 enum ada_renaming_category kind;
3853 return ADA_NOT_RENAMING;
3854 switch (SYMBOL_CLASS (sym))
3857 return ADA_NOT_RENAMING;
3859 return parse_old_style_renaming (SYMBOL_TYPE (sym),
3860 renamed_entity, len, renaming_expr);
3864 case LOC_OPTIMIZED_OUT:
3865 info = strstr (SYMBOL_LINKAGE_NAME (sym), "___XR");
3867 return ADA_NOT_RENAMING;
3871 kind = ADA_OBJECT_RENAMING;
3875 kind = ADA_EXCEPTION_RENAMING;
3879 kind = ADA_PACKAGE_RENAMING;
3883 kind = ADA_SUBPROGRAM_RENAMING;
3887 return ADA_NOT_RENAMING;
3891 if (renamed_entity != NULL)
3892 *renamed_entity = info;
3893 suffix = strstr (info, "___XE");
3894 if (suffix == NULL || suffix == info)
3895 return ADA_NOT_RENAMING;
3897 *len = strlen (info) - strlen (suffix);
3899 if (renaming_expr != NULL)
3900 *renaming_expr = suffix;
3904 /* Assuming TYPE encodes a renaming according to the old encoding in
3905 exp_dbug.ads, returns details of that renaming in *RENAMED_ENTITY,
3906 *LEN, and *RENAMING_EXPR, as for ada_parse_renaming, above. Returns
3907 ADA_NOT_RENAMING otherwise. */
3908 static enum ada_renaming_category
3909 parse_old_style_renaming (struct type *type,
3910 const char **renamed_entity, int *len,
3911 const char **renaming_expr)
3913 enum ada_renaming_category kind;
3918 if (type == NULL || TYPE_CODE (type) != TYPE_CODE_ENUM
3919 || TYPE_NFIELDS (type) != 1)
3920 return ADA_NOT_RENAMING;
3922 name = type_name_no_tag (type);
3924 return ADA_NOT_RENAMING;
3926 name = strstr (name, "___XR");
3928 return ADA_NOT_RENAMING;
3933 kind = ADA_OBJECT_RENAMING;
3936 kind = ADA_EXCEPTION_RENAMING;
3939 kind = ADA_PACKAGE_RENAMING;
3942 kind = ADA_SUBPROGRAM_RENAMING;
3945 return ADA_NOT_RENAMING;
3948 info = TYPE_FIELD_NAME (type, 0);
3950 return ADA_NOT_RENAMING;
3951 if (renamed_entity != NULL)
3952 *renamed_entity = info;
3953 suffix = strstr (info, "___XE");
3954 if (renaming_expr != NULL)
3955 *renaming_expr = suffix + 5;
3956 if (suffix == NULL || suffix == info)
3957 return ADA_NOT_RENAMING;
3959 *len = suffix - info;
3965 /* Evaluation: Function Calls */
3967 /* Return an lvalue containing the value VAL. This is the identity on
3968 lvalues, and otherwise has the side-effect of allocating memory
3969 in the inferior where a copy of the value contents is copied. */
3971 static struct value *
3972 ensure_lval (struct value *val)
3974 if (VALUE_LVAL (val) == not_lval
3975 || VALUE_LVAL (val) == lval_internalvar)
3977 int len = TYPE_LENGTH (ada_check_typedef (value_type (val)));
3978 const CORE_ADDR addr =
3979 value_as_long (value_allocate_space_in_inferior (len));
3981 set_value_address (val, addr);
3982 VALUE_LVAL (val) = lval_memory;
3983 write_memory (addr, value_contents (val), len);
3989 /* Return the value ACTUAL, converted to be an appropriate value for a
3990 formal of type FORMAL_TYPE. Use *SP as a stack pointer for
3991 allocating any necessary descriptors (fat pointers), or copies of
3992 values not residing in memory, updating it as needed. */
3995 ada_convert_actual (struct value *actual, struct type *formal_type0)
3997 struct type *actual_type = ada_check_typedef (value_type (actual));
3998 struct type *formal_type = ada_check_typedef (formal_type0);
3999 struct type *formal_target =
4000 TYPE_CODE (formal_type) == TYPE_CODE_PTR
4001 ? ada_check_typedef (TYPE_TARGET_TYPE (formal_type)) : formal_type;
4002 struct type *actual_target =
4003 TYPE_CODE (actual_type) == TYPE_CODE_PTR
4004 ? ada_check_typedef (TYPE_TARGET_TYPE (actual_type)) : actual_type;
4006 if (ada_is_array_descriptor_type (formal_target)
4007 && TYPE_CODE (actual_target) == TYPE_CODE_ARRAY)
4008 return make_array_descriptor (formal_type, actual);
4009 else if (TYPE_CODE (formal_type) == TYPE_CODE_PTR
4010 || TYPE_CODE (formal_type) == TYPE_CODE_REF)
4012 struct value *result;
4014 if (TYPE_CODE (formal_target) == TYPE_CODE_ARRAY
4015 && ada_is_array_descriptor_type (actual_target))
4016 result = desc_data (actual);
4017 else if (TYPE_CODE (actual_type) != TYPE_CODE_PTR)
4019 if (VALUE_LVAL (actual) != lval_memory)
4023 actual_type = ada_check_typedef (value_type (actual));
4024 val = allocate_value (actual_type);
4025 memcpy ((char *) value_contents_raw (val),
4026 (char *) value_contents (actual),
4027 TYPE_LENGTH (actual_type));
4028 actual = ensure_lval (val);
4030 result = value_addr (actual);
4034 return value_cast_pointers (formal_type, result);
4036 else if (TYPE_CODE (actual_type) == TYPE_CODE_PTR)
4037 return ada_value_ind (actual);
4042 /* Convert VALUE (which must be an address) to a CORE_ADDR that is a pointer of
4043 type TYPE. This is usually an inefficient no-op except on some targets
4044 (such as AVR) where the representation of a pointer and an address
4048 value_pointer (struct value *value, struct type *type)
4050 struct gdbarch *gdbarch = get_type_arch (type);
4051 unsigned len = TYPE_LENGTH (type);
4052 gdb_byte *buf = alloca (len);
4055 addr = value_address (value);
4056 gdbarch_address_to_pointer (gdbarch, type, buf, addr);
4057 addr = extract_unsigned_integer (buf, len, gdbarch_byte_order (gdbarch));
4062 /* Push a descriptor of type TYPE for array value ARR on the stack at
4063 *SP, updating *SP to reflect the new descriptor. Return either
4064 an lvalue representing the new descriptor, or (if TYPE is a pointer-
4065 to-descriptor type rather than a descriptor type), a struct value *
4066 representing a pointer to this descriptor. */
4068 static struct value *
4069 make_array_descriptor (struct type *type, struct value *arr)
4071 struct type *bounds_type = desc_bounds_type (type);
4072 struct type *desc_type = desc_base_type (type);
4073 struct value *descriptor = allocate_value (desc_type);
4074 struct value *bounds = allocate_value (bounds_type);
4077 for (i = ada_array_arity (ada_check_typedef (value_type (arr)));
4080 modify_field (value_type (bounds), value_contents_writeable (bounds),
4081 ada_array_bound (arr, i, 0),
4082 desc_bound_bitpos (bounds_type, i, 0),
4083 desc_bound_bitsize (bounds_type, i, 0));
4084 modify_field (value_type (bounds), value_contents_writeable (bounds),
4085 ada_array_bound (arr, i, 1),
4086 desc_bound_bitpos (bounds_type, i, 1),
4087 desc_bound_bitsize (bounds_type, i, 1));
4090 bounds = ensure_lval (bounds);
4092 modify_field (value_type (descriptor),
4093 value_contents_writeable (descriptor),
4094 value_pointer (ensure_lval (arr),
4095 TYPE_FIELD_TYPE (desc_type, 0)),
4096 fat_pntr_data_bitpos (desc_type),
4097 fat_pntr_data_bitsize (desc_type));
4099 modify_field (value_type (descriptor),
4100 value_contents_writeable (descriptor),
4101 value_pointer (bounds,
4102 TYPE_FIELD_TYPE (desc_type, 1)),
4103 fat_pntr_bounds_bitpos (desc_type),
4104 fat_pntr_bounds_bitsize (desc_type));
4106 descriptor = ensure_lval (descriptor);
4108 if (TYPE_CODE (type) == TYPE_CODE_PTR)
4109 return value_addr (descriptor);
4114 /* Dummy definitions for an experimental caching module that is not
4115 * used in the public sources. */
4118 lookup_cached_symbol (const char *name, domain_enum namespace,
4119 struct symbol **sym, struct block **block)
4125 cache_symbol (const char *name, domain_enum namespace, struct symbol *sym,
4126 struct block *block)
4132 /* Return the result of a standard (literal, C-like) lookup of NAME in
4133 given DOMAIN, visible from lexical block BLOCK. */
4135 static struct symbol *
4136 standard_lookup (const char *name, const struct block *block,
4141 if (lookup_cached_symbol (name, domain, &sym, NULL))
4143 sym = lookup_symbol_in_language (name, block, domain, language_c, 0);
4144 cache_symbol (name, domain, sym, block_found);
4149 /* Non-zero iff there is at least one non-function/non-enumeral symbol
4150 in the symbol fields of SYMS[0..N-1]. We treat enumerals as functions,
4151 since they contend in overloading in the same way. */
4153 is_nonfunction (struct ada_symbol_info syms[], int n)
4157 for (i = 0; i < n; i += 1)
4158 if (TYPE_CODE (SYMBOL_TYPE (syms[i].sym)) != TYPE_CODE_FUNC
4159 && (TYPE_CODE (SYMBOL_TYPE (syms[i].sym)) != TYPE_CODE_ENUM
4160 || SYMBOL_CLASS (syms[i].sym) != LOC_CONST))
4166 /* If true (non-zero), then TYPE0 and TYPE1 represent equivalent
4167 struct types. Otherwise, they may not. */
4170 equiv_types (struct type *type0, struct type *type1)
4174 if (type0 == NULL || type1 == NULL
4175 || TYPE_CODE (type0) != TYPE_CODE (type1))
4177 if ((TYPE_CODE (type0) == TYPE_CODE_STRUCT
4178 || TYPE_CODE (type0) == TYPE_CODE_ENUM)
4179 && ada_type_name (type0) != NULL && ada_type_name (type1) != NULL
4180 && strcmp (ada_type_name (type0), ada_type_name (type1)) == 0)
4186 /* True iff SYM0 represents the same entity as SYM1, or one that is
4187 no more defined than that of SYM1. */
4190 lesseq_defined_than (struct symbol *sym0, struct symbol *sym1)
4194 if (SYMBOL_DOMAIN (sym0) != SYMBOL_DOMAIN (sym1)
4195 || SYMBOL_CLASS (sym0) != SYMBOL_CLASS (sym1))
4198 switch (SYMBOL_CLASS (sym0))
4204 struct type *type0 = SYMBOL_TYPE (sym0);
4205 struct type *type1 = SYMBOL_TYPE (sym1);
4206 char *name0 = SYMBOL_LINKAGE_NAME (sym0);
4207 char *name1 = SYMBOL_LINKAGE_NAME (sym1);
4208 int len0 = strlen (name0);
4211 TYPE_CODE (type0) == TYPE_CODE (type1)
4212 && (equiv_types (type0, type1)
4213 || (len0 < strlen (name1) && strncmp (name0, name1, len0) == 0
4214 && strncmp (name1 + len0, "___XV", 5) == 0));
4217 return SYMBOL_VALUE (sym0) == SYMBOL_VALUE (sym1)
4218 && equiv_types (SYMBOL_TYPE (sym0), SYMBOL_TYPE (sym1));
4224 /* Append (SYM,BLOCK,SYMTAB) to the end of the array of struct ada_symbol_info
4225 records in OBSTACKP. Do nothing if SYM is a duplicate. */
4228 add_defn_to_vec (struct obstack *obstackp,
4230 struct block *block)
4233 struct ada_symbol_info *prevDefns = defns_collected (obstackp, 0);
4235 /* Do not try to complete stub types, as the debugger is probably
4236 already scanning all symbols matching a certain name at the
4237 time when this function is called. Trying to replace the stub
4238 type by its associated full type will cause us to restart a scan
4239 which may lead to an infinite recursion. Instead, the client
4240 collecting the matching symbols will end up collecting several
4241 matches, with at least one of them complete. It can then filter
4242 out the stub ones if needed. */
4244 for (i = num_defns_collected (obstackp) - 1; i >= 0; i -= 1)
4246 if (lesseq_defined_than (sym, prevDefns[i].sym))
4248 else if (lesseq_defined_than (prevDefns[i].sym, sym))
4250 prevDefns[i].sym = sym;
4251 prevDefns[i].block = block;
4257 struct ada_symbol_info info;
4261 obstack_grow (obstackp, &info, sizeof (struct ada_symbol_info));
4265 /* Number of ada_symbol_info structures currently collected in
4266 current vector in *OBSTACKP. */
4269 num_defns_collected (struct obstack *obstackp)
4271 return obstack_object_size (obstackp) / sizeof (struct ada_symbol_info);
4274 /* Vector of ada_symbol_info structures currently collected in current
4275 vector in *OBSTACKP. If FINISH, close off the vector and return
4276 its final address. */
4278 static struct ada_symbol_info *
4279 defns_collected (struct obstack *obstackp, int finish)
4282 return obstack_finish (obstackp);
4284 return (struct ada_symbol_info *) obstack_base (obstackp);
4287 /* Return a minimal symbol matching NAME according to Ada decoding
4288 rules. Returns NULL if there is no such minimal symbol. Names
4289 prefixed with "standard__" are handled specially: "standard__" is
4290 first stripped off, and only static and global symbols are searched. */
4292 struct minimal_symbol *
4293 ada_lookup_simple_minsym (const char *name)
4295 struct objfile *objfile;
4296 struct minimal_symbol *msymbol;
4299 if (strncmp (name, "standard__", sizeof ("standard__") - 1) == 0)
4301 name += sizeof ("standard__") - 1;
4305 wild_match = (strstr (name, "__") == NULL);
4307 ALL_MSYMBOLS (objfile, msymbol)
4309 if (match_name (SYMBOL_LINKAGE_NAME (msymbol), name, wild_match)
4310 && MSYMBOL_TYPE (msymbol) != mst_solib_trampoline)
4317 /* For all subprograms that statically enclose the subprogram of the
4318 selected frame, add symbols matching identifier NAME in DOMAIN
4319 and their blocks to the list of data in OBSTACKP, as for
4320 ada_add_block_symbols (q.v.). If WILD, treat as NAME with a
4324 add_symbols_from_enclosing_procs (struct obstack *obstackp,
4325 const char *name, domain_enum namespace,
4330 /* True if TYPE is definitely an artificial type supplied to a symbol
4331 for which no debugging information was given in the symbol file. */
4334 is_nondebugging_type (struct type *type)
4336 char *name = ada_type_name (type);
4338 return (name != NULL && strcmp (name, "<variable, no debug info>") == 0);
4341 /* Remove any non-debugging symbols in SYMS[0 .. NSYMS-1] that definitely
4342 duplicate other symbols in the list (The only case I know of where
4343 this happens is when object files containing stabs-in-ecoff are
4344 linked with files containing ordinary ecoff debugging symbols (or no
4345 debugging symbols)). Modifies SYMS to squeeze out deleted entries.
4346 Returns the number of items in the modified list. */
4349 remove_extra_symbols (struct ada_symbol_info *syms, int nsyms)
4358 /* If two symbols have the same name and one of them is a stub type,
4359 the get rid of the stub. */
4361 if (TYPE_STUB (SYMBOL_TYPE (syms[i].sym))
4362 && SYMBOL_LINKAGE_NAME (syms[i].sym) != NULL)
4364 for (j = 0; j < nsyms; j++)
4367 && !TYPE_STUB (SYMBOL_TYPE (syms[j].sym))
4368 && SYMBOL_LINKAGE_NAME (syms[j].sym) != NULL
4369 && strcmp (SYMBOL_LINKAGE_NAME (syms[i].sym),
4370 SYMBOL_LINKAGE_NAME (syms[j].sym)) == 0)
4375 /* Two symbols with the same name, same class and same address
4376 should be identical. */
4378 else if (SYMBOL_LINKAGE_NAME (syms[i].sym) != NULL
4379 && SYMBOL_CLASS (syms[i].sym) == LOC_STATIC
4380 && is_nondebugging_type (SYMBOL_TYPE (syms[i].sym)))
4382 for (j = 0; j < nsyms; j += 1)
4385 && SYMBOL_LINKAGE_NAME (syms[j].sym) != NULL
4386 && strcmp (SYMBOL_LINKAGE_NAME (syms[i].sym),
4387 SYMBOL_LINKAGE_NAME (syms[j].sym)) == 0
4388 && SYMBOL_CLASS (syms[i].sym) == SYMBOL_CLASS (syms[j].sym)
4389 && SYMBOL_VALUE_ADDRESS (syms[i].sym)
4390 == SYMBOL_VALUE_ADDRESS (syms[j].sym))
4397 for (j = i + 1; j < nsyms; j += 1)
4398 syms[j - 1] = syms[j];
4407 /* Given a type that corresponds to a renaming entity, use the type name
4408 to extract the scope (package name or function name, fully qualified,
4409 and following the GNAT encoding convention) where this renaming has been
4410 defined. The string returned needs to be deallocated after use. */
4413 xget_renaming_scope (struct type *renaming_type)
4415 /* The renaming types adhere to the following convention:
4416 <scope>__<rename>___<XR extension>.
4417 So, to extract the scope, we search for the "___XR" extension,
4418 and then backtrack until we find the first "__". */
4420 const char *name = type_name_no_tag (renaming_type);
4421 char *suffix = strstr (name, "___XR");
4426 /* Now, backtrack a bit until we find the first "__". Start looking
4427 at suffix - 3, as the <rename> part is at least one character long. */
4429 for (last = suffix - 3; last > name; last--)
4430 if (last[0] == '_' && last[1] == '_')
4433 /* Make a copy of scope and return it. */
4435 scope_len = last - name;
4436 scope = (char *) xmalloc ((scope_len + 1) * sizeof (char));
4438 strncpy (scope, name, scope_len);
4439 scope[scope_len] = '\0';
4444 /* Return nonzero if NAME corresponds to a package name. */
4447 is_package_name (const char *name)
4449 /* Here, We take advantage of the fact that no symbols are generated
4450 for packages, while symbols are generated for each function.
4451 So the condition for NAME represent a package becomes equivalent
4452 to NAME not existing in our list of symbols. There is only one
4453 small complication with library-level functions (see below). */
4457 /* If it is a function that has not been defined at library level,
4458 then we should be able to look it up in the symbols. */
4459 if (standard_lookup (name, NULL, VAR_DOMAIN) != NULL)
4462 /* Library-level function names start with "_ada_". See if function
4463 "_ada_" followed by NAME can be found. */
4465 /* Do a quick check that NAME does not contain "__", since library-level
4466 functions names cannot contain "__" in them. */
4467 if (strstr (name, "__") != NULL)
4470 fun_name = xstrprintf ("_ada_%s", name);
4472 return (standard_lookup (fun_name, NULL, VAR_DOMAIN) == NULL);
4475 /* Return nonzero if SYM corresponds to a renaming entity that is
4476 not visible from FUNCTION_NAME. */
4479 old_renaming_is_invisible (const struct symbol *sym, char *function_name)
4483 if (SYMBOL_CLASS (sym) != LOC_TYPEDEF)
4486 scope = xget_renaming_scope (SYMBOL_TYPE (sym));
4488 make_cleanup (xfree, scope);
4490 /* If the rename has been defined in a package, then it is visible. */
4491 if (is_package_name (scope))
4494 /* Check that the rename is in the current function scope by checking
4495 that its name starts with SCOPE. */
4497 /* If the function name starts with "_ada_", it means that it is
4498 a library-level function. Strip this prefix before doing the
4499 comparison, as the encoding for the renaming does not contain
4501 if (strncmp (function_name, "_ada_", 5) == 0)
4504 return (strncmp (function_name, scope, strlen (scope)) != 0);
4507 /* Remove entries from SYMS that corresponds to a renaming entity that
4508 is not visible from the function associated with CURRENT_BLOCK or
4509 that is superfluous due to the presence of more specific renaming
4510 information. Places surviving symbols in the initial entries of
4511 SYMS and returns the number of surviving symbols.
4514 First, in cases where an object renaming is implemented as a
4515 reference variable, GNAT may produce both the actual reference
4516 variable and the renaming encoding. In this case, we discard the
4519 Second, GNAT emits a type following a specified encoding for each renaming
4520 entity. Unfortunately, STABS currently does not support the definition
4521 of types that are local to a given lexical block, so all renamings types
4522 are emitted at library level. As a consequence, if an application
4523 contains two renaming entities using the same name, and a user tries to
4524 print the value of one of these entities, the result of the ada symbol
4525 lookup will also contain the wrong renaming type.
4527 This function partially covers for this limitation by attempting to
4528 remove from the SYMS list renaming symbols that should be visible
4529 from CURRENT_BLOCK. However, there does not seem be a 100% reliable
4530 method with the current information available. The implementation
4531 below has a couple of limitations (FIXME: brobecker-2003-05-12):
4533 - When the user tries to print a rename in a function while there
4534 is another rename entity defined in a package: Normally, the
4535 rename in the function has precedence over the rename in the
4536 package, so the latter should be removed from the list. This is
4537 currently not the case.
4539 - This function will incorrectly remove valid renames if
4540 the CURRENT_BLOCK corresponds to a function which symbol name
4541 has been changed by an "Export" pragma. As a consequence,
4542 the user will be unable to print such rename entities. */
4545 remove_irrelevant_renamings (struct ada_symbol_info *syms,
4546 int nsyms, const struct block *current_block)
4548 struct symbol *current_function;
4549 char *current_function_name;
4551 int is_new_style_renaming;
4553 /* If there is both a renaming foo___XR... encoded as a variable and
4554 a simple variable foo in the same block, discard the latter.
4555 First, zero out such symbols, then compress. */
4556 is_new_style_renaming = 0;
4557 for (i = 0; i < nsyms; i += 1)
4559 struct symbol *sym = syms[i].sym;
4560 struct block *block = syms[i].block;
4564 if (sym == NULL || SYMBOL_CLASS (sym) == LOC_TYPEDEF)
4566 name = SYMBOL_LINKAGE_NAME (sym);
4567 suffix = strstr (name, "___XR");
4571 int name_len = suffix - name;
4574 is_new_style_renaming = 1;
4575 for (j = 0; j < nsyms; j += 1)
4576 if (i != j && syms[j].sym != NULL
4577 && strncmp (name, SYMBOL_LINKAGE_NAME (syms[j].sym),
4579 && block == syms[j].block)
4583 if (is_new_style_renaming)
4587 for (j = k = 0; j < nsyms; j += 1)
4588 if (syms[j].sym != NULL)
4596 /* Extract the function name associated to CURRENT_BLOCK.
4597 Abort if unable to do so. */
4599 if (current_block == NULL)
4602 current_function = block_linkage_function (current_block);
4603 if (current_function == NULL)
4606 current_function_name = SYMBOL_LINKAGE_NAME (current_function);
4607 if (current_function_name == NULL)
4610 /* Check each of the symbols, and remove it from the list if it is
4611 a type corresponding to a renaming that is out of the scope of
4612 the current block. */
4617 if (ada_parse_renaming (syms[i].sym, NULL, NULL, NULL)
4618 == ADA_OBJECT_RENAMING
4619 && old_renaming_is_invisible (syms[i].sym, current_function_name))
4623 for (j = i + 1; j < nsyms; j += 1)
4624 syms[j - 1] = syms[j];
4634 /* Add to OBSTACKP all symbols from BLOCK (and its super-blocks)
4635 whose name and domain match NAME and DOMAIN respectively.
4636 If no match was found, then extend the search to "enclosing"
4637 routines (in other words, if we're inside a nested function,
4638 search the symbols defined inside the enclosing functions).
4640 Note: This function assumes that OBSTACKP has 0 (zero) element in it. */
4643 ada_add_local_symbols (struct obstack *obstackp, const char *name,
4644 struct block *block, domain_enum domain,
4647 int block_depth = 0;
4649 while (block != NULL)
4652 ada_add_block_symbols (obstackp, block, name, domain, NULL, wild_match);
4654 /* If we found a non-function match, assume that's the one. */
4655 if (is_nonfunction (defns_collected (obstackp, 0),
4656 num_defns_collected (obstackp)))
4659 block = BLOCK_SUPERBLOCK (block);
4662 /* If no luck so far, try to find NAME as a local symbol in some lexically
4663 enclosing subprogram. */
4664 if (num_defns_collected (obstackp) == 0 && block_depth > 2)
4665 add_symbols_from_enclosing_procs (obstackp, name, domain, wild_match);
4668 /* An object of this type is used as the user_data argument when
4669 calling the map_matching_symbols method. */
4673 struct objfile *objfile;
4674 struct obstack *obstackp;
4675 struct symbol *arg_sym;
4679 /* A callback for add_matching_symbols that adds SYM, found in BLOCK,
4680 to a list of symbols. DATA0 is a pointer to a struct match_data *
4681 containing the obstack that collects the symbol list, the file that SYM
4682 must come from, a flag indicating whether a non-argument symbol has
4683 been found in the current block, and the last argument symbol
4684 passed in SYM within the current block (if any). When SYM is null,
4685 marking the end of a block, the argument symbol is added if no
4686 other has been found. */
4689 aux_add_nonlocal_symbols (struct block *block, struct symbol *sym, void *data0)
4691 struct match_data *data = (struct match_data *) data0;
4695 if (!data->found_sym && data->arg_sym != NULL)
4696 add_defn_to_vec (data->obstackp,
4697 fixup_symbol_section (data->arg_sym, data->objfile),
4699 data->found_sym = 0;
4700 data->arg_sym = NULL;
4704 if (SYMBOL_CLASS (sym) == LOC_UNRESOLVED)
4706 else if (SYMBOL_IS_ARGUMENT (sym))
4707 data->arg_sym = sym;
4710 data->found_sym = 1;
4711 add_defn_to_vec (data->obstackp,
4712 fixup_symbol_section (sym, data->objfile),
4719 /* Compare STRING1 to STRING2, with results as for strcmp.
4720 Compatible with strcmp_iw in that strcmp_iw (STRING1, STRING2) <= 0
4721 implies compare_names (STRING1, STRING2) (they may differ as to
4722 what symbols compare equal). */
4725 compare_names (const char *string1, const char *string2)
4727 while (*string1 != '\0' && *string2 != '\0')
4729 if (isspace (*string1) || isspace (*string2))
4730 return strcmp_iw_ordered (string1, string2);
4731 if (*string1 != *string2)
4739 return strcmp_iw_ordered (string1, string2);
4741 if (*string2 == '\0')
4743 if (is_name_suffix (string2))
4749 if (*string2 == '(')
4750 return strcmp_iw_ordered (string1, string2);
4752 return *string1 - *string2;
4756 /* Add to OBSTACKP all non-local symbols whose name and domain match
4757 NAME and DOMAIN respectively. The search is performed on GLOBAL_BLOCK
4758 symbols if GLOBAL is non-zero, or on STATIC_BLOCK symbols otherwise. */
4761 add_nonlocal_symbols (struct obstack *obstackp, const char *name,
4762 domain_enum domain, int global,
4765 struct objfile *objfile;
4766 struct match_data data;
4768 data.obstackp = obstackp;
4769 data.arg_sym = NULL;
4771 ALL_OBJFILES (objfile)
4773 data.objfile = objfile;
4776 objfile->sf->qf->map_matching_symbols (name, domain, objfile, global,
4777 aux_add_nonlocal_symbols, &data,
4780 objfile->sf->qf->map_matching_symbols (name, domain, objfile, global,
4781 aux_add_nonlocal_symbols, &data,
4782 full_match, compare_names);
4785 if (num_defns_collected (obstackp) == 0 && global && !is_wild_match)
4787 ALL_OBJFILES (objfile)
4789 char *name1 = alloca (strlen (name) + sizeof ("_ada_"));
4790 strcpy (name1, "_ada_");
4791 strcpy (name1 + sizeof ("_ada_") - 1, name);
4792 data.objfile = objfile;
4793 objfile->sf->qf->map_matching_symbols (name1, domain,
4795 aux_add_nonlocal_symbols,
4797 full_match, compare_names);
4802 /* Find symbols in DOMAIN matching NAME0, in BLOCK0 and enclosing
4803 scope and in global scopes, returning the number of matches. Sets
4804 *RESULTS to point to a vector of (SYM,BLOCK) tuples,
4805 indicating the symbols found and the blocks and symbol tables (if
4806 any) in which they were found. This vector are transient---good only to
4807 the next call of ada_lookup_symbol_list. Any non-function/non-enumeral
4808 symbol match within the nest of blocks whose innermost member is BLOCK0,
4809 is the one match returned (no other matches in that or
4810 enclosing blocks is returned). If there are any matches in or
4811 surrounding BLOCK0, then these alone are returned. Otherwise, the
4812 search extends to global and file-scope (static) symbol tables.
4813 Names prefixed with "standard__" are handled specially: "standard__"
4814 is first stripped off, and only static and global symbols are searched. */
4817 ada_lookup_symbol_list (const char *name0, const struct block *block0,
4818 domain_enum namespace,
4819 struct ada_symbol_info **results)
4822 struct block *block;
4828 obstack_free (&symbol_list_obstack, NULL);
4829 obstack_init (&symbol_list_obstack);
4833 /* Search specified block and its superiors. */
4835 wild_match = (strstr (name0, "__") == NULL);
4837 block = (struct block *) block0; /* FIXME: No cast ought to be
4838 needed, but adding const will
4839 have a cascade effect. */
4841 /* Special case: If the user specifies a symbol name inside package
4842 Standard, do a non-wild matching of the symbol name without
4843 the "standard__" prefix. This was primarily introduced in order
4844 to allow the user to specifically access the standard exceptions
4845 using, for instance, Standard.Constraint_Error when Constraint_Error
4846 is ambiguous (due to the user defining its own Constraint_Error
4847 entity inside its program). */
4848 if (strncmp (name0, "standard__", sizeof ("standard__") - 1) == 0)
4852 name = name0 + sizeof ("standard__") - 1;
4855 /* Check the non-global symbols. If we have ANY match, then we're done. */
4857 ada_add_local_symbols (&symbol_list_obstack, name, block, namespace,
4859 if (num_defns_collected (&symbol_list_obstack) > 0)
4862 /* No non-global symbols found. Check our cache to see if we have
4863 already performed this search before. If we have, then return
4867 if (lookup_cached_symbol (name0, namespace, &sym, &block))
4870 add_defn_to_vec (&symbol_list_obstack, sym, block);
4874 /* Search symbols from all global blocks. */
4876 add_nonlocal_symbols (&symbol_list_obstack, name, namespace, 1,
4879 /* Now add symbols from all per-file blocks if we've gotten no hits
4880 (not strictly correct, but perhaps better than an error). */
4882 if (num_defns_collected (&symbol_list_obstack) == 0)
4883 add_nonlocal_symbols (&symbol_list_obstack, name, namespace, 0,
4887 ndefns = num_defns_collected (&symbol_list_obstack);
4888 *results = defns_collected (&symbol_list_obstack, 1);
4890 ndefns = remove_extra_symbols (*results, ndefns);
4893 cache_symbol (name0, namespace, NULL, NULL);
4895 if (ndefns == 1 && cacheIfUnique)
4896 cache_symbol (name0, namespace, (*results)[0].sym, (*results)[0].block);
4898 ndefns = remove_irrelevant_renamings (*results, ndefns, block0);
4904 ada_lookup_encoded_symbol (const char *name, const struct block *block0,
4905 domain_enum namespace, struct block **block_found)
4907 struct ada_symbol_info *candidates;
4910 n_candidates = ada_lookup_symbol_list (name, block0, namespace, &candidates);
4912 if (n_candidates == 0)
4915 if (block_found != NULL)
4916 *block_found = candidates[0].block;
4918 return fixup_symbol_section (candidates[0].sym, NULL);
4921 /* Return a symbol in DOMAIN matching NAME, in BLOCK0 and enclosing
4922 scope and in global scopes, or NULL if none. NAME is folded and
4923 encoded first. Otherwise, the result is as for ada_lookup_symbol_list,
4924 choosing the first symbol if there are multiple choices.
4925 *IS_A_FIELD_OF_THIS is set to 0 and *SYMTAB is set to the symbol
4926 table in which the symbol was found (in both cases, these
4927 assignments occur only if the pointers are non-null). */
4929 ada_lookup_symbol (const char *name, const struct block *block0,
4930 domain_enum namespace, int *is_a_field_of_this)
4932 if (is_a_field_of_this != NULL)
4933 *is_a_field_of_this = 0;
4936 ada_lookup_encoded_symbol (ada_encode (ada_fold_name (name)),
4937 block0, namespace, NULL);
4940 static struct symbol *
4941 ada_lookup_symbol_nonlocal (const char *name,
4942 const struct block *block,
4943 const domain_enum domain)
4945 return ada_lookup_symbol (name, block_static_block (block), domain, NULL);
4949 /* True iff STR is a possible encoded suffix of a normal Ada name
4950 that is to be ignored for matching purposes. Suffixes of parallel
4951 names (e.g., XVE) are not included here. Currently, the possible suffixes
4952 are given by any of the regular expressions:
4954 [.$][0-9]+ [nested subprogram suffix, on platforms such as GNU/Linux]
4955 ___[0-9]+ [nested subprogram suffix, on platforms such as HP/UX]
4956 _E[0-9]+[bs]$ [protected object entry suffixes]
4957 (X[nb]*)?((\$|__)[0-9](_?[0-9]+)|___(JM|LJM|X([FDBUP].*|R[^T]?)))?$
4959 Also, any leading "__[0-9]+" sequence is skipped before the suffix
4960 match is performed. This sequence is used to differentiate homonyms,
4961 is an optional part of a valid name suffix. */
4964 is_name_suffix (const char *str)
4967 const char *matching;
4968 const int len = strlen (str);
4970 /* Skip optional leading __[0-9]+. */
4972 if (len > 3 && str[0] == '_' && str[1] == '_' && isdigit (str[2]))
4975 while (isdigit (str[0]))
4981 if (str[0] == '.' || str[0] == '$')
4984 while (isdigit (matching[0]))
4986 if (matching[0] == '\0')
4992 if (len > 3 && str[0] == '_' && str[1] == '_' && str[2] == '_')
4995 while (isdigit (matching[0]))
4997 if (matching[0] == '\0')
5002 /* FIXME: brobecker/2005-09-23: Protected Object subprograms end
5003 with a N at the end. Unfortunately, the compiler uses the same
5004 convention for other internal types it creates. So treating
5005 all entity names that end with an "N" as a name suffix causes
5006 some regressions. For instance, consider the case of an enumerated
5007 type. To support the 'Image attribute, it creates an array whose
5009 Having a single character like this as a suffix carrying some
5010 information is a bit risky. Perhaps we should change the encoding
5011 to be something like "_N" instead. In the meantime, do not do
5012 the following check. */
5013 /* Protected Object Subprograms */
5014 if (len == 1 && str [0] == 'N')
5019 if (len > 3 && str[0] == '_' && str [1] == 'E' && isdigit (str[2]))
5022 while (isdigit (matching[0]))
5024 if ((matching[0] == 'b' || matching[0] == 's')
5025 && matching [1] == '\0')
5029 /* ??? We should not modify STR directly, as we are doing below. This
5030 is fine in this case, but may become problematic later if we find
5031 that this alternative did not work, and want to try matching
5032 another one from the begining of STR. Since we modified it, we
5033 won't be able to find the begining of the string anymore! */
5037 while (str[0] != '_' && str[0] != '\0')
5039 if (str[0] != 'n' && str[0] != 'b')
5045 if (str[0] == '\000')
5050 if (str[1] != '_' || str[2] == '\000')
5054 if (strcmp (str + 3, "JM") == 0)
5056 /* FIXME: brobecker/2004-09-30: GNAT will soon stop using
5057 the LJM suffix in favor of the JM one. But we will
5058 still accept LJM as a valid suffix for a reasonable
5059 amount of time, just to allow ourselves to debug programs
5060 compiled using an older version of GNAT. */
5061 if (strcmp (str + 3, "LJM") == 0)
5065 if (str[4] == 'F' || str[4] == 'D' || str[4] == 'B'
5066 || str[4] == 'U' || str[4] == 'P')
5068 if (str[4] == 'R' && str[5] != 'T')
5072 if (!isdigit (str[2]))
5074 for (k = 3; str[k] != '\0'; k += 1)
5075 if (!isdigit (str[k]) && str[k] != '_')
5079 if (str[0] == '$' && isdigit (str[1]))
5081 for (k = 2; str[k] != '\0'; k += 1)
5082 if (!isdigit (str[k]) && str[k] != '_')
5089 /* Return non-zero if the string starting at NAME and ending before
5090 NAME_END contains no capital letters. */
5093 is_valid_name_for_wild_match (const char *name0)
5095 const char *decoded_name = ada_decode (name0);
5098 /* If the decoded name starts with an angle bracket, it means that
5099 NAME0 does not follow the GNAT encoding format. It should then
5100 not be allowed as a possible wild match. */
5101 if (decoded_name[0] == '<')
5104 for (i=0; decoded_name[i] != '\0'; i++)
5105 if (isalpha (decoded_name[i]) && !islower (decoded_name[i]))
5111 /* Advance *NAMEP to next occurrence of TARGET0 in the string NAME0
5112 that could start a simple name. Assumes that *NAMEP points into
5113 the string beginning at NAME0. */
5116 advance_wild_match (const char **namep, const char *name0, int target0)
5118 const char *name = *namep;
5128 if ((t1 >= 'a' && t1 <= 'z') || (t1 >= '0' && t1 <= '9'))
5131 if (name == name0 + 5 && strncmp (name0, "_ada", 4) == 0)
5136 else if (t1 == '_' && ((name[2] >= 'a' && name[2] <= 'z')
5137 || name[2] == target0))
5145 else if ((t0 >= 'a' && t0 <= 'z') || (t0 >= '0' && t0 <= '9'))
5155 /* Return 0 iff NAME encodes a name of the form prefix.PATN. Ignores any
5156 informational suffixes of NAME (i.e., for which is_name_suffix is
5157 true). Assumes that PATN is a lower-cased Ada simple name. */
5160 wild_match (const char *name, const char *patn)
5163 const char *name0 = name;
5167 const char *match = name;
5171 for (name += 1, p = patn + 1; *p != '\0'; name += 1, p += 1)
5174 if (*p == '\0' && is_name_suffix (name))
5175 return match != name0 && !is_valid_name_for_wild_match (name0);
5177 if (name[-1] == '_')
5180 if (!advance_wild_match (&name, name0, *patn))
5185 /* Returns 0 iff symbol name SYM_NAME matches SEARCH_NAME, apart from
5186 informational suffix. */
5189 full_match (const char *sym_name, const char *search_name)
5191 return !match_name (sym_name, search_name, 0);
5195 /* Add symbols from BLOCK matching identifier NAME in DOMAIN to
5196 vector *defn_symbols, updating the list of symbols in OBSTACKP
5197 (if necessary). If WILD, treat as NAME with a wildcard prefix.
5198 OBJFILE is the section containing BLOCK.
5199 SYMTAB is recorded with each symbol added. */
5202 ada_add_block_symbols (struct obstack *obstackp,
5203 struct block *block, const char *name,
5204 domain_enum domain, struct objfile *objfile,
5207 struct dict_iterator iter;
5208 int name_len = strlen (name);
5209 /* A matching argument symbol, if any. */
5210 struct symbol *arg_sym;
5211 /* Set true when we find a matching non-argument symbol. */
5219 for (sym = dict_iter_match_first (BLOCK_DICT (block), name,
5221 sym != NULL; sym = dict_iter_match_next (name, wild_match, &iter))
5223 if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
5224 SYMBOL_DOMAIN (sym), domain)
5225 && wild_match (SYMBOL_LINKAGE_NAME (sym), name) == 0)
5227 if (SYMBOL_CLASS (sym) == LOC_UNRESOLVED)
5229 else if (SYMBOL_IS_ARGUMENT (sym))
5234 add_defn_to_vec (obstackp,
5235 fixup_symbol_section (sym, objfile),
5243 for (sym = dict_iter_match_first (BLOCK_DICT (block), name,
5245 sym != NULL; sym = dict_iter_match_next (name, full_match, &iter))
5247 if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
5248 SYMBOL_DOMAIN (sym), domain))
5250 if (SYMBOL_CLASS (sym) != LOC_UNRESOLVED)
5252 if (SYMBOL_IS_ARGUMENT (sym))
5257 add_defn_to_vec (obstackp,
5258 fixup_symbol_section (sym, objfile),
5266 if (!found_sym && arg_sym != NULL)
5268 add_defn_to_vec (obstackp,
5269 fixup_symbol_section (arg_sym, objfile),
5278 ALL_BLOCK_SYMBOLS (block, iter, sym)
5280 if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
5281 SYMBOL_DOMAIN (sym), domain))
5285 cmp = (int) '_' - (int) SYMBOL_LINKAGE_NAME (sym)[0];
5288 cmp = strncmp ("_ada_", SYMBOL_LINKAGE_NAME (sym), 5);
5290 cmp = strncmp (name, SYMBOL_LINKAGE_NAME (sym) + 5,
5295 && is_name_suffix (SYMBOL_LINKAGE_NAME (sym) + name_len + 5))
5297 if (SYMBOL_CLASS (sym) != LOC_UNRESOLVED)
5299 if (SYMBOL_IS_ARGUMENT (sym))
5304 add_defn_to_vec (obstackp,
5305 fixup_symbol_section (sym, objfile),
5313 /* NOTE: This really shouldn't be needed for _ada_ symbols.
5314 They aren't parameters, right? */
5315 if (!found_sym && arg_sym != NULL)
5317 add_defn_to_vec (obstackp,
5318 fixup_symbol_section (arg_sym, objfile),
5325 /* Symbol Completion */
5327 /* If SYM_NAME is a completion candidate for TEXT, return this symbol
5328 name in a form that's appropriate for the completion. The result
5329 does not need to be deallocated, but is only good until the next call.
5331 TEXT_LEN is equal to the length of TEXT.
5332 Perform a wild match if WILD_MATCH is set.
5333 ENCODED should be set if TEXT represents the start of a symbol name
5334 in its encoded form. */
5337 symbol_completion_match (const char *sym_name,
5338 const char *text, int text_len,
5339 int wild_match, int encoded)
5341 const int verbatim_match = (text[0] == '<');
5346 /* Strip the leading angle bracket. */
5351 /* First, test against the fully qualified name of the symbol. */
5353 if (strncmp (sym_name, text, text_len) == 0)
5356 if (match && !encoded)
5358 /* One needed check before declaring a positive match is to verify
5359 that iff we are doing a verbatim match, the decoded version
5360 of the symbol name starts with '<'. Otherwise, this symbol name
5361 is not a suitable completion. */
5362 const char *sym_name_copy = sym_name;
5363 int has_angle_bracket;
5365 sym_name = ada_decode (sym_name);
5366 has_angle_bracket = (sym_name[0] == '<');
5367 match = (has_angle_bracket == verbatim_match);
5368 sym_name = sym_name_copy;
5371 if (match && !verbatim_match)
5373 /* When doing non-verbatim match, another check that needs to
5374 be done is to verify that the potentially matching symbol name
5375 does not include capital letters, because the ada-mode would
5376 not be able to understand these symbol names without the
5377 angle bracket notation. */
5380 for (tmp = sym_name; *tmp != '\0' && !isupper (*tmp); tmp++);
5385 /* Second: Try wild matching... */
5387 if (!match && wild_match)
5389 /* Since we are doing wild matching, this means that TEXT
5390 may represent an unqualified symbol name. We therefore must
5391 also compare TEXT against the unqualified name of the symbol. */
5392 sym_name = ada_unqualified_name (ada_decode (sym_name));
5394 if (strncmp (sym_name, text, text_len) == 0)
5398 /* Finally: If we found a mach, prepare the result to return. */
5404 sym_name = add_angle_brackets (sym_name);
5407 sym_name = ada_decode (sym_name);
5412 DEF_VEC_P (char_ptr);
5414 /* A companion function to ada_make_symbol_completion_list().
5415 Check if SYM_NAME represents a symbol which name would be suitable
5416 to complete TEXT (TEXT_LEN is the length of TEXT), in which case
5417 it is appended at the end of the given string vector SV.
5419 ORIG_TEXT is the string original string from the user command
5420 that needs to be completed. WORD is the entire command on which
5421 completion should be performed. These two parameters are used to
5422 determine which part of the symbol name should be added to the
5424 if WILD_MATCH is set, then wild matching is performed.
5425 ENCODED should be set if TEXT represents a symbol name in its
5426 encoded formed (in which case the completion should also be
5430 symbol_completion_add (VEC(char_ptr) **sv,
5431 const char *sym_name,
5432 const char *text, int text_len,
5433 const char *orig_text, const char *word,
5434 int wild_match, int encoded)
5436 const char *match = symbol_completion_match (sym_name, text, text_len,
5437 wild_match, encoded);
5443 /* We found a match, so add the appropriate completion to the given
5446 if (word == orig_text)
5448 completion = xmalloc (strlen (match) + 5);
5449 strcpy (completion, match);
5451 else if (word > orig_text)
5453 /* Return some portion of sym_name. */
5454 completion = xmalloc (strlen (match) + 5);
5455 strcpy (completion, match + (word - orig_text));
5459 /* Return some of ORIG_TEXT plus sym_name. */
5460 completion = xmalloc (strlen (match) + (orig_text - word) + 5);
5461 strncpy (completion, word, orig_text - word);
5462 completion[orig_text - word] = '\0';
5463 strcat (completion, match);
5466 VEC_safe_push (char_ptr, *sv, completion);
5469 /* An object of this type is passed as the user_data argument to the
5470 map_partial_symbol_names method. */
5471 struct add_partial_datum
5473 VEC(char_ptr) **completions;
5482 /* A callback for map_partial_symbol_names. */
5484 ada_add_partial_symbol_completions (const char *name, void *user_data)
5486 struct add_partial_datum *data = user_data;
5488 symbol_completion_add (data->completions, name,
5489 data->text, data->text_len, data->text0, data->word,
5490 data->wild_match, data->encoded);
5493 /* Return a list of possible symbol names completing TEXT0. The list
5494 is NULL terminated. WORD is the entire command on which completion
5498 ada_make_symbol_completion_list (char *text0, char *word)
5504 VEC(char_ptr) *completions = VEC_alloc (char_ptr, 128);
5507 struct minimal_symbol *msymbol;
5508 struct objfile *objfile;
5509 struct block *b, *surrounding_static_block = 0;
5511 struct dict_iterator iter;
5513 if (text0[0] == '<')
5515 text = xstrdup (text0);
5516 make_cleanup (xfree, text);
5517 text_len = strlen (text);
5523 text = xstrdup (ada_encode (text0));
5524 make_cleanup (xfree, text);
5525 text_len = strlen (text);
5526 for (i = 0; i < text_len; i++)
5527 text[i] = tolower (text[i]);
5529 encoded = (strstr (text0, "__") != NULL);
5530 /* If the name contains a ".", then the user is entering a fully
5531 qualified entity name, and the match must not be done in wild
5532 mode. Similarly, if the user wants to complete what looks like
5533 an encoded name, the match must not be done in wild mode. */
5534 wild_match = (strchr (text0, '.') == NULL && !encoded);
5537 /* First, look at the partial symtab symbols. */
5539 struct add_partial_datum data;
5541 data.completions = &completions;
5543 data.text_len = text_len;
5546 data.wild_match = wild_match;
5547 data.encoded = encoded;
5548 map_partial_symbol_names (ada_add_partial_symbol_completions, &data);
5551 /* At this point scan through the misc symbol vectors and add each
5552 symbol you find to the list. Eventually we want to ignore
5553 anything that isn't a text symbol (everything else will be
5554 handled by the psymtab code above). */
5556 ALL_MSYMBOLS (objfile, msymbol)
5559 symbol_completion_add (&completions, SYMBOL_LINKAGE_NAME (msymbol),
5560 text, text_len, text0, word, wild_match, encoded);
5563 /* Search upwards from currently selected frame (so that we can
5564 complete on local vars. */
5566 for (b = get_selected_block (0); b != NULL; b = BLOCK_SUPERBLOCK (b))
5568 if (!BLOCK_SUPERBLOCK (b))
5569 surrounding_static_block = b; /* For elmin of dups */
5571 ALL_BLOCK_SYMBOLS (b, iter, sym)
5573 symbol_completion_add (&completions, SYMBOL_LINKAGE_NAME (sym),
5574 text, text_len, text0, word,
5575 wild_match, encoded);
5579 /* Go through the symtabs and check the externs and statics for
5580 symbols which match. */
5582 ALL_SYMTABS (objfile, s)
5585 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK);
5586 ALL_BLOCK_SYMBOLS (b, iter, sym)
5588 symbol_completion_add (&completions, SYMBOL_LINKAGE_NAME (sym),
5589 text, text_len, text0, word,
5590 wild_match, encoded);
5594 ALL_SYMTABS (objfile, s)
5597 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK);
5598 /* Don't do this block twice. */
5599 if (b == surrounding_static_block)
5601 ALL_BLOCK_SYMBOLS (b, iter, sym)
5603 symbol_completion_add (&completions, SYMBOL_LINKAGE_NAME (sym),
5604 text, text_len, text0, word,
5605 wild_match, encoded);
5609 /* Append the closing NULL entry. */
5610 VEC_safe_push (char_ptr, completions, NULL);
5612 /* Make a copy of the COMPLETIONS VEC before we free it, and then
5613 return the copy. It's unfortunate that we have to make a copy
5614 of an array that we're about to destroy, but there is nothing much
5615 we can do about it. Fortunately, it's typically not a very large
5618 const size_t completions_size =
5619 VEC_length (char_ptr, completions) * sizeof (char *);
5620 char **result = malloc (completions_size);
5622 memcpy (result, VEC_address (char_ptr, completions), completions_size);
5624 VEC_free (char_ptr, completions);
5631 /* Return non-zero if TYPE is a pointer to the GNAT dispatch table used
5632 for tagged types. */
5635 ada_is_dispatch_table_ptr_type (struct type *type)
5639 if (TYPE_CODE (type) != TYPE_CODE_PTR)
5642 name = TYPE_NAME (TYPE_TARGET_TYPE (type));
5646 return (strcmp (name, "ada__tags__dispatch_table") == 0);
5649 /* True if field number FIELD_NUM in struct or union type TYPE is supposed
5650 to be invisible to users. */
5653 ada_is_ignored_field (struct type *type, int field_num)
5655 if (field_num < 0 || field_num > TYPE_NFIELDS (type))
5658 /* Check the name of that field. */
5660 const char *name = TYPE_FIELD_NAME (type, field_num);
5662 /* Anonymous field names should not be printed.
5663 brobecker/2007-02-20: I don't think this can actually happen
5664 but we don't want to print the value of annonymous fields anyway. */
5668 /* A field named "_parent" is internally generated by GNAT for
5669 tagged types, and should not be printed either. */
5670 if (name[0] == '_' && strncmp (name, "_parent", 7) != 0)
5674 /* If this is the dispatch table of a tagged type, then ignore. */
5675 if (ada_is_tagged_type (type, 1)
5676 && ada_is_dispatch_table_ptr_type (TYPE_FIELD_TYPE (type, field_num)))
5679 /* Not a special field, so it should not be ignored. */
5683 /* True iff TYPE has a tag field. If REFOK, then TYPE may also be a
5684 pointer or reference type whose ultimate target has a tag field. */
5687 ada_is_tagged_type (struct type *type, int refok)
5689 return (ada_lookup_struct_elt_type (type, "_tag", refok, 1, NULL) != NULL);
5692 /* True iff TYPE represents the type of X'Tag */
5695 ada_is_tag_type (struct type *type)
5697 if (type == NULL || TYPE_CODE (type) != TYPE_CODE_PTR)
5701 const char *name = ada_type_name (TYPE_TARGET_TYPE (type));
5703 return (name != NULL
5704 && strcmp (name, "ada__tags__dispatch_table") == 0);
5708 /* The type of the tag on VAL. */
5711 ada_tag_type (struct value *val)
5713 return ada_lookup_struct_elt_type (value_type (val), "_tag", 1, 0, NULL);
5716 /* The value of the tag on VAL. */
5719 ada_value_tag (struct value *val)
5721 return ada_value_struct_elt (val, "_tag", 0);
5724 /* The value of the tag on the object of type TYPE whose contents are
5725 saved at VALADDR, if it is non-null, or is at memory address
5728 static struct value *
5729 value_tag_from_contents_and_address (struct type *type,
5730 const gdb_byte *valaddr,
5733 int tag_byte_offset;
5734 struct type *tag_type;
5736 if (find_struct_field ("_tag", type, 0, &tag_type, &tag_byte_offset,
5739 const gdb_byte *valaddr1 = ((valaddr == NULL)
5741 : valaddr + tag_byte_offset);
5742 CORE_ADDR address1 = (address == 0) ? 0 : address + tag_byte_offset;
5744 return value_from_contents_and_address (tag_type, valaddr1, address1);
5749 static struct type *
5750 type_from_tag (struct value *tag)
5752 const char *type_name = ada_tag_name (tag);
5754 if (type_name != NULL)
5755 return ada_find_any_type (ada_encode (type_name));
5766 static int ada_tag_name_1 (void *);
5767 static int ada_tag_name_2 (struct tag_args *);
5769 /* Wrapper function used by ada_tag_name. Given a struct tag_args*
5770 value ARGS, sets ARGS->name to the tag name of ARGS->tag.
5771 The value stored in ARGS->name is valid until the next call to
5775 ada_tag_name_1 (void *args0)
5777 struct tag_args *args = (struct tag_args *) args0;
5778 static char name[1024];
5783 val = ada_value_struct_elt (args->tag, "tsd", 1);
5785 return ada_tag_name_2 (args);
5786 val = ada_value_struct_elt (val, "expanded_name", 1);
5789 read_memory_string (value_as_address (val), name, sizeof (name) - 1);
5790 for (p = name; *p != '\0'; p += 1)
5797 /* Return the "ada__tags__type_specific_data" type. */
5799 static struct type *
5800 ada_get_tsd_type (struct inferior *inf)
5802 struct ada_inferior_data *data = get_ada_inferior_data (inf);
5804 if (data->tsd_type == 0)
5805 data->tsd_type = ada_find_any_type ("ada__tags__type_specific_data");
5806 return data->tsd_type;
5809 /* Utility function for ada_tag_name_1 that tries the second
5810 representation for the dispatch table (in which there is no
5811 explicit 'tsd' field in the referent of the tag pointer, and instead
5812 the tsd pointer is stored just before the dispatch table. */
5815 ada_tag_name_2 (struct tag_args *args)
5817 struct type *info_type;
5818 static char name[1024];
5820 struct value *val, *valp;
5823 info_type = ada_get_tsd_type (current_inferior());
5824 if (info_type == NULL)
5826 info_type = lookup_pointer_type (lookup_pointer_type (info_type));
5827 valp = value_cast (info_type, args->tag);
5830 val = value_ind (value_ptradd (valp, -1));
5833 val = ada_value_struct_elt (val, "expanded_name", 1);
5836 read_memory_string (value_as_address (val), name, sizeof (name) - 1);
5837 for (p = name; *p != '\0'; p += 1)
5844 /* The type name of the dynamic type denoted by the 'tag value TAG, as
5848 ada_tag_name (struct value *tag)
5850 struct tag_args args;
5852 if (!ada_is_tag_type (value_type (tag)))
5856 catch_errors (ada_tag_name_1, &args, NULL, RETURN_MASK_ALL);
5860 /* The parent type of TYPE, or NULL if none. */
5863 ada_parent_type (struct type *type)
5867 type = ada_check_typedef (type);
5869 if (type == NULL || TYPE_CODE (type) != TYPE_CODE_STRUCT)
5872 for (i = 0; i < TYPE_NFIELDS (type); i += 1)
5873 if (ada_is_parent_field (type, i))
5875 struct type *parent_type = TYPE_FIELD_TYPE (type, i);
5877 /* If the _parent field is a pointer, then dereference it. */
5878 if (TYPE_CODE (parent_type) == TYPE_CODE_PTR)
5879 parent_type = TYPE_TARGET_TYPE (parent_type);
5880 /* If there is a parallel XVS type, get the actual base type. */
5881 parent_type = ada_get_base_type (parent_type);
5883 return ada_check_typedef (parent_type);
5889 /* True iff field number FIELD_NUM of structure type TYPE contains the
5890 parent-type (inherited) fields of a derived type. Assumes TYPE is
5891 a structure type with at least FIELD_NUM+1 fields. */
5894 ada_is_parent_field (struct type *type, int field_num)
5896 const char *name = TYPE_FIELD_NAME (ada_check_typedef (type), field_num);
5898 return (name != NULL
5899 && (strncmp (name, "PARENT", 6) == 0
5900 || strncmp (name, "_parent", 7) == 0));
5903 /* True iff field number FIELD_NUM of structure type TYPE is a
5904 transparent wrapper field (which should be silently traversed when doing
5905 field selection and flattened when printing). Assumes TYPE is a
5906 structure type with at least FIELD_NUM+1 fields. Such fields are always
5910 ada_is_wrapper_field (struct type *type, int field_num)
5912 const char *name = TYPE_FIELD_NAME (type, field_num);
5914 return (name != NULL
5915 && (strncmp (name, "PARENT", 6) == 0
5916 || strcmp (name, "REP") == 0
5917 || strncmp (name, "_parent", 7) == 0
5918 || name[0] == 'S' || name[0] == 'R' || name[0] == 'O'));
5921 /* True iff field number FIELD_NUM of structure or union type TYPE
5922 is a variant wrapper. Assumes TYPE is a structure type with at least
5923 FIELD_NUM+1 fields. */
5926 ada_is_variant_part (struct type *type, int field_num)
5928 struct type *field_type = TYPE_FIELD_TYPE (type, field_num);
5930 return (TYPE_CODE (field_type) == TYPE_CODE_UNION
5931 || (is_dynamic_field (type, field_num)
5932 && (TYPE_CODE (TYPE_TARGET_TYPE (field_type))
5933 == TYPE_CODE_UNION)));
5936 /* Assuming that VAR_TYPE is a variant wrapper (type of the variant part)
5937 whose discriminants are contained in the record type OUTER_TYPE,
5938 returns the type of the controlling discriminant for the variant.
5939 May return NULL if the type could not be found. */
5942 ada_variant_discrim_type (struct type *var_type, struct type *outer_type)
5944 char *name = ada_variant_discrim_name (var_type);
5946 return ada_lookup_struct_elt_type (outer_type, name, 1, 1, NULL);
5949 /* Assuming that TYPE is the type of a variant wrapper, and FIELD_NUM is a
5950 valid field number within it, returns 1 iff field FIELD_NUM of TYPE
5951 represents a 'when others' clause; otherwise 0. */
5954 ada_is_others_clause (struct type *type, int field_num)
5956 const char *name = TYPE_FIELD_NAME (type, field_num);
5958 return (name != NULL && name[0] == 'O');
5961 /* Assuming that TYPE0 is the type of the variant part of a record,
5962 returns the name of the discriminant controlling the variant.
5963 The value is valid until the next call to ada_variant_discrim_name. */
5966 ada_variant_discrim_name (struct type *type0)
5968 static char *result = NULL;
5969 static size_t result_len = 0;
5972 const char *discrim_end;
5973 const char *discrim_start;
5975 if (TYPE_CODE (type0) == TYPE_CODE_PTR)
5976 type = TYPE_TARGET_TYPE (type0);
5980 name = ada_type_name (type);
5982 if (name == NULL || name[0] == '\000')
5985 for (discrim_end = name + strlen (name) - 6; discrim_end != name;
5988 if (strncmp (discrim_end, "___XVN", 6) == 0)
5991 if (discrim_end == name)
5994 for (discrim_start = discrim_end; discrim_start != name + 3;
5997 if (discrim_start == name + 1)
5999 if ((discrim_start > name + 3
6000 && strncmp (discrim_start - 3, "___", 3) == 0)
6001 || discrim_start[-1] == '.')
6005 GROW_VECT (result, result_len, discrim_end - discrim_start + 1);
6006 strncpy (result, discrim_start, discrim_end - discrim_start);
6007 result[discrim_end - discrim_start] = '\0';
6011 /* Scan STR for a subtype-encoded number, beginning at position K.
6012 Put the position of the character just past the number scanned in
6013 *NEW_K, if NEW_K!=NULL. Put the scanned number in *R, if R!=NULL.
6014 Return 1 if there was a valid number at the given position, and 0
6015 otherwise. A "subtype-encoded" number consists of the absolute value
6016 in decimal, followed by the letter 'm' to indicate a negative number.
6017 Assumes 0m does not occur. */
6020 ada_scan_number (const char str[], int k, LONGEST * R, int *new_k)
6024 if (!isdigit (str[k]))
6027 /* Do it the hard way so as not to make any assumption about
6028 the relationship of unsigned long (%lu scan format code) and
6031 while (isdigit (str[k]))
6033 RU = RU * 10 + (str[k] - '0');
6040 *R = (-(LONGEST) (RU - 1)) - 1;
6046 /* NOTE on the above: Technically, C does not say what the results of
6047 - (LONGEST) RU or (LONGEST) -RU are for RU == largest positive
6048 number representable as a LONGEST (although either would probably work
6049 in most implementations). When RU>0, the locution in the then branch
6050 above is always equivalent to the negative of RU. */
6057 /* Assuming that TYPE is a variant part wrapper type (a VARIANTS field),
6058 and FIELD_NUM is a valid field number within it, returns 1 iff VAL is
6059 in the range encoded by field FIELD_NUM of TYPE; otherwise 0. */
6062 ada_in_variant (LONGEST val, struct type *type, int field_num)
6064 const char *name = TYPE_FIELD_NAME (type, field_num);
6078 if (!ada_scan_number (name, p + 1, &W, &p))
6088 if (!ada_scan_number (name, p + 1, &L, &p)
6089 || name[p] != 'T' || !ada_scan_number (name, p + 1, &U, &p))
6091 if (val >= L && val <= U)
6103 /* FIXME: Lots of redundancy below. Try to consolidate. */
6105 /* Given a value ARG1 (offset by OFFSET bytes) of a struct or union type
6106 ARG_TYPE, extract and return the value of one of its (non-static)
6107 fields. FIELDNO says which field. Differs from value_primitive_field
6108 only in that it can handle packed values of arbitrary type. */
6110 static struct value *
6111 ada_value_primitive_field (struct value *arg1, int offset, int fieldno,
6112 struct type *arg_type)
6116 arg_type = ada_check_typedef (arg_type);
6117 type = TYPE_FIELD_TYPE (arg_type, fieldno);
6119 /* Handle packed fields. */
6121 if (TYPE_FIELD_BITSIZE (arg_type, fieldno) != 0)
6123 int bit_pos = TYPE_FIELD_BITPOS (arg_type, fieldno);
6124 int bit_size = TYPE_FIELD_BITSIZE (arg_type, fieldno);
6126 return ada_value_primitive_packed_val (arg1, value_contents (arg1),
6127 offset + bit_pos / 8,
6128 bit_pos % 8, bit_size, type);
6131 return value_primitive_field (arg1, offset, fieldno, arg_type);
6134 /* Find field with name NAME in object of type TYPE. If found,
6135 set the following for each argument that is non-null:
6136 - *FIELD_TYPE_P to the field's type;
6137 - *BYTE_OFFSET_P to OFFSET + the byte offset of the field within
6138 an object of that type;
6139 - *BIT_OFFSET_P to the bit offset modulo byte size of the field;
6140 - *BIT_SIZE_P to its size in bits if the field is packed, and
6142 If INDEX_P is non-null, increment *INDEX_P by the number of source-visible
6143 fields up to but not including the desired field, or by the total
6144 number of fields if not found. A NULL value of NAME never
6145 matches; the function just counts visible fields in this case.
6147 Returns 1 if found, 0 otherwise. */
6150 find_struct_field (char *name, struct type *type, int offset,
6151 struct type **field_type_p,
6152 int *byte_offset_p, int *bit_offset_p, int *bit_size_p,
6157 type = ada_check_typedef (type);
6159 if (field_type_p != NULL)
6160 *field_type_p = NULL;
6161 if (byte_offset_p != NULL)
6163 if (bit_offset_p != NULL)
6165 if (bit_size_p != NULL)
6168 for (i = 0; i < TYPE_NFIELDS (type); i += 1)
6170 int bit_pos = TYPE_FIELD_BITPOS (type, i);
6171 int fld_offset = offset + bit_pos / 8;
6172 char *t_field_name = TYPE_FIELD_NAME (type, i);
6174 if (t_field_name == NULL)
6177 else if (name != NULL && field_name_match (t_field_name, name))
6179 int bit_size = TYPE_FIELD_BITSIZE (type, i);
6181 if (field_type_p != NULL)
6182 *field_type_p = TYPE_FIELD_TYPE (type, i);
6183 if (byte_offset_p != NULL)
6184 *byte_offset_p = fld_offset;
6185 if (bit_offset_p != NULL)
6186 *bit_offset_p = bit_pos % 8;
6187 if (bit_size_p != NULL)
6188 *bit_size_p = bit_size;
6191 else if (ada_is_wrapper_field (type, i))
6193 if (find_struct_field (name, TYPE_FIELD_TYPE (type, i), fld_offset,
6194 field_type_p, byte_offset_p, bit_offset_p,
6195 bit_size_p, index_p))
6198 else if (ada_is_variant_part (type, i))
6200 /* PNH: Wait. Do we ever execute this section, or is ARG always of
6203 struct type *field_type
6204 = ada_check_typedef (TYPE_FIELD_TYPE (type, i));
6206 for (j = 0; j < TYPE_NFIELDS (field_type); j += 1)
6208 if (find_struct_field (name, TYPE_FIELD_TYPE (field_type, j),
6210 + TYPE_FIELD_BITPOS (field_type, j) / 8,
6211 field_type_p, byte_offset_p,
6212 bit_offset_p, bit_size_p, index_p))
6216 else if (index_p != NULL)
6222 /* Number of user-visible fields in record type TYPE. */
6225 num_visible_fields (struct type *type)
6230 find_struct_field (NULL, type, 0, NULL, NULL, NULL, NULL, &n);
6234 /* Look for a field NAME in ARG. Adjust the address of ARG by OFFSET bytes,
6235 and search in it assuming it has (class) type TYPE.
6236 If found, return value, else return NULL.
6238 Searches recursively through wrapper fields (e.g., '_parent'). */
6240 static struct value *
6241 ada_search_struct_field (char *name, struct value *arg, int offset,
6246 type = ada_check_typedef (type);
6247 for (i = 0; i < TYPE_NFIELDS (type); i += 1)
6249 char *t_field_name = TYPE_FIELD_NAME (type, i);
6251 if (t_field_name == NULL)
6254 else if (field_name_match (t_field_name, name))
6255 return ada_value_primitive_field (arg, offset, i, type);
6257 else if (ada_is_wrapper_field (type, i))
6259 struct value *v = /* Do not let indent join lines here. */
6260 ada_search_struct_field (name, arg,
6261 offset + TYPE_FIELD_BITPOS (type, i) / 8,
6262 TYPE_FIELD_TYPE (type, i));
6268 else if (ada_is_variant_part (type, i))
6270 /* PNH: Do we ever get here? See find_struct_field. */
6272 struct type *field_type = ada_check_typedef (TYPE_FIELD_TYPE (type,
6274 int var_offset = offset + TYPE_FIELD_BITPOS (type, i) / 8;
6276 for (j = 0; j < TYPE_NFIELDS (field_type); j += 1)
6278 struct value *v = ada_search_struct_field /* Force line
6281 var_offset + TYPE_FIELD_BITPOS (field_type, j) / 8,
6282 TYPE_FIELD_TYPE (field_type, j));
6292 static struct value *ada_index_struct_field_1 (int *, struct value *,
6293 int, struct type *);
6296 /* Return field #INDEX in ARG, where the index is that returned by
6297 * find_struct_field through its INDEX_P argument. Adjust the address
6298 * of ARG by OFFSET bytes, and search in it assuming it has (class) type TYPE.
6299 * If found, return value, else return NULL. */
6301 static struct value *
6302 ada_index_struct_field (int index, struct value *arg, int offset,
6305 return ada_index_struct_field_1 (&index, arg, offset, type);
6309 /* Auxiliary function for ada_index_struct_field. Like
6310 * ada_index_struct_field, but takes index from *INDEX_P and modifies
6313 static struct value *
6314 ada_index_struct_field_1 (int *index_p, struct value *arg, int offset,
6318 type = ada_check_typedef (type);
6320 for (i = 0; i < TYPE_NFIELDS (type); i += 1)
6322 if (TYPE_FIELD_NAME (type, i) == NULL)
6324 else if (ada_is_wrapper_field (type, i))
6326 struct value *v = /* Do not let indent join lines here. */
6327 ada_index_struct_field_1 (index_p, arg,
6328 offset + TYPE_FIELD_BITPOS (type, i) / 8,
6329 TYPE_FIELD_TYPE (type, i));
6335 else if (ada_is_variant_part (type, i))
6337 /* PNH: Do we ever get here? See ada_search_struct_field,
6338 find_struct_field. */
6339 error (_("Cannot assign this kind of variant record"));
6341 else if (*index_p == 0)
6342 return ada_value_primitive_field (arg, offset, i, type);
6349 /* Given ARG, a value of type (pointer or reference to a)*
6350 structure/union, extract the component named NAME from the ultimate
6351 target structure/union and return it as a value with its
6354 The routine searches for NAME among all members of the structure itself
6355 and (recursively) among all members of any wrapper members
6358 If NO_ERR, then simply return NULL in case of error, rather than
6362 ada_value_struct_elt (struct value *arg, char *name, int no_err)
6364 struct type *t, *t1;
6368 t1 = t = ada_check_typedef (value_type (arg));
6369 if (TYPE_CODE (t) == TYPE_CODE_REF)
6371 t1 = TYPE_TARGET_TYPE (t);
6374 t1 = ada_check_typedef (t1);
6375 if (TYPE_CODE (t1) == TYPE_CODE_PTR)
6377 arg = coerce_ref (arg);
6382 while (TYPE_CODE (t) == TYPE_CODE_PTR)
6384 t1 = TYPE_TARGET_TYPE (t);
6387 t1 = ada_check_typedef (t1);
6388 if (TYPE_CODE (t1) == TYPE_CODE_PTR)
6390 arg = value_ind (arg);
6397 if (TYPE_CODE (t1) != TYPE_CODE_STRUCT && TYPE_CODE (t1) != TYPE_CODE_UNION)
6401 v = ada_search_struct_field (name, arg, 0, t);
6404 int bit_offset, bit_size, byte_offset;
6405 struct type *field_type;
6408 if (TYPE_CODE (t) == TYPE_CODE_PTR)
6409 address = value_as_address (arg);
6411 address = unpack_pointer (t, value_contents (arg));
6413 t1 = ada_to_fixed_type (ada_get_base_type (t1), NULL, address, NULL, 1);
6414 if (find_struct_field (name, t1, 0,
6415 &field_type, &byte_offset, &bit_offset,
6420 if (TYPE_CODE (t) == TYPE_CODE_REF)
6421 arg = ada_coerce_ref (arg);
6423 arg = ada_value_ind (arg);
6424 v = ada_value_primitive_packed_val (arg, NULL, byte_offset,
6425 bit_offset, bit_size,
6429 v = value_at_lazy (field_type, address + byte_offset);
6433 if (v != NULL || no_err)
6436 error (_("There is no member named %s."), name);
6442 error (_("Attempt to extract a component of "
6443 "a value that is not a record."));
6446 /* Given a type TYPE, look up the type of the component of type named NAME.
6447 If DISPP is non-null, add its byte displacement from the beginning of a
6448 structure (pointed to by a value) of type TYPE to *DISPP (does not
6449 work for packed fields).
6451 Matches any field whose name has NAME as a prefix, possibly
6454 TYPE can be either a struct or union. If REFOK, TYPE may also
6455 be a (pointer or reference)+ to a struct or union, and the
6456 ultimate target type will be searched.
6458 Looks recursively into variant clauses and parent types.
6460 If NOERR is nonzero, return NULL if NAME is not suitably defined or
6461 TYPE is not a type of the right kind. */
6463 static struct type *
6464 ada_lookup_struct_elt_type (struct type *type, char *name, int refok,
6465 int noerr, int *dispp)
6472 if (refok && type != NULL)
6475 type = ada_check_typedef (type);
6476 if (TYPE_CODE (type) != TYPE_CODE_PTR
6477 && TYPE_CODE (type) != TYPE_CODE_REF)
6479 type = TYPE_TARGET_TYPE (type);
6483 || (TYPE_CODE (type) != TYPE_CODE_STRUCT
6484 && TYPE_CODE (type) != TYPE_CODE_UNION))
6490 target_terminal_ours ();
6491 gdb_flush (gdb_stdout);
6493 error (_("Type (null) is not a structure or union type"));
6496 /* XXX: type_sprint */
6497 fprintf_unfiltered (gdb_stderr, _("Type "));
6498 type_print (type, "", gdb_stderr, -1);
6499 error (_(" is not a structure or union type"));
6504 type = to_static_fixed_type (type);
6506 for (i = 0; i < TYPE_NFIELDS (type); i += 1)
6508 char *t_field_name = TYPE_FIELD_NAME (type, i);
6512 if (t_field_name == NULL)
6515 else if (field_name_match (t_field_name, name))
6518 *dispp += TYPE_FIELD_BITPOS (type, i) / 8;
6519 return ada_check_typedef (TYPE_FIELD_TYPE (type, i));
6522 else if (ada_is_wrapper_field (type, i))
6525 t = ada_lookup_struct_elt_type (TYPE_FIELD_TYPE (type, i), name,
6530 *dispp += disp + TYPE_FIELD_BITPOS (type, i) / 8;
6535 else if (ada_is_variant_part (type, i))
6538 struct type *field_type = ada_check_typedef (TYPE_FIELD_TYPE (type,
6541 for (j = TYPE_NFIELDS (field_type) - 1; j >= 0; j -= 1)
6543 /* FIXME pnh 2008/01/26: We check for a field that is
6544 NOT wrapped in a struct, since the compiler sometimes
6545 generates these for unchecked variant types. Revisit
6546 if the compiler changes this practice. */
6547 char *v_field_name = TYPE_FIELD_NAME (field_type, j);
6549 if (v_field_name != NULL
6550 && field_name_match (v_field_name, name))
6551 t = ada_check_typedef (TYPE_FIELD_TYPE (field_type, j));
6553 t = ada_lookup_struct_elt_type (TYPE_FIELD_TYPE (field_type,
6560 *dispp += disp + TYPE_FIELD_BITPOS (type, i) / 8;
6571 target_terminal_ours ();
6572 gdb_flush (gdb_stdout);
6575 /* XXX: type_sprint */
6576 fprintf_unfiltered (gdb_stderr, _("Type "));
6577 type_print (type, "", gdb_stderr, -1);
6578 error (_(" has no component named <null>"));
6582 /* XXX: type_sprint */
6583 fprintf_unfiltered (gdb_stderr, _("Type "));
6584 type_print (type, "", gdb_stderr, -1);
6585 error (_(" has no component named %s"), name);
6592 /* Assuming that VAR_TYPE is the type of a variant part of a record (a union),
6593 within a value of type OUTER_TYPE, return true iff VAR_TYPE
6594 represents an unchecked union (that is, the variant part of a
6595 record that is named in an Unchecked_Union pragma). */
6598 is_unchecked_variant (struct type *var_type, struct type *outer_type)
6600 char *discrim_name = ada_variant_discrim_name (var_type);
6602 return (ada_lookup_struct_elt_type (outer_type, discrim_name, 0, 1, NULL)
6607 /* Assuming that VAR_TYPE is the type of a variant part of a record (a union),
6608 within a value of type OUTER_TYPE that is stored in GDB at
6609 OUTER_VALADDR, determine which variant clause (field number in VAR_TYPE,
6610 numbering from 0) is applicable. Returns -1 if none are. */
6613 ada_which_variant_applies (struct type *var_type, struct type *outer_type,
6614 const gdb_byte *outer_valaddr)
6618 char *discrim_name = ada_variant_discrim_name (var_type);
6619 struct value *outer;
6620 struct value *discrim;
6621 LONGEST discrim_val;
6623 outer = value_from_contents_and_address (outer_type, outer_valaddr, 0);
6624 discrim = ada_value_struct_elt (outer, discrim_name, 1);
6625 if (discrim == NULL)
6627 discrim_val = value_as_long (discrim);
6630 for (i = 0; i < TYPE_NFIELDS (var_type); i += 1)
6632 if (ada_is_others_clause (var_type, i))
6634 else if (ada_in_variant (discrim_val, var_type, i))
6638 return others_clause;
6643 /* Dynamic-Sized Records */
6645 /* Strategy: The type ostensibly attached to a value with dynamic size
6646 (i.e., a size that is not statically recorded in the debugging
6647 data) does not accurately reflect the size or layout of the value.
6648 Our strategy is to convert these values to values with accurate,
6649 conventional types that are constructed on the fly. */
6651 /* There is a subtle and tricky problem here. In general, we cannot
6652 determine the size of dynamic records without its data. However,
6653 the 'struct value' data structure, which GDB uses to represent
6654 quantities in the inferior process (the target), requires the size
6655 of the type at the time of its allocation in order to reserve space
6656 for GDB's internal copy of the data. That's why the
6657 'to_fixed_xxx_type' routines take (target) addresses as parameters,
6658 rather than struct value*s.
6660 However, GDB's internal history variables ($1, $2, etc.) are
6661 struct value*s containing internal copies of the data that are not, in
6662 general, the same as the data at their corresponding addresses in
6663 the target. Fortunately, the types we give to these values are all
6664 conventional, fixed-size types (as per the strategy described
6665 above), so that we don't usually have to perform the
6666 'to_fixed_xxx_type' conversions to look at their values.
6667 Unfortunately, there is one exception: if one of the internal
6668 history variables is an array whose elements are unconstrained
6669 records, then we will need to create distinct fixed types for each
6670 element selected. */
6672 /* The upshot of all of this is that many routines take a (type, host
6673 address, target address) triple as arguments to represent a value.
6674 The host address, if non-null, is supposed to contain an internal
6675 copy of the relevant data; otherwise, the program is to consult the
6676 target at the target address. */
6678 /* Assuming that VAL0 represents a pointer value, the result of
6679 dereferencing it. Differs from value_ind in its treatment of
6680 dynamic-sized types. */
6683 ada_value_ind (struct value *val0)
6685 struct value *val = unwrap_value (value_ind (val0));
6687 return ada_to_fixed_value (val);
6690 /* The value resulting from dereferencing any "reference to"
6691 qualifiers on VAL0. */
6693 static struct value *
6694 ada_coerce_ref (struct value *val0)
6696 if (TYPE_CODE (value_type (val0)) == TYPE_CODE_REF)
6698 struct value *val = val0;
6700 val = coerce_ref (val);
6701 val = unwrap_value (val);
6702 return ada_to_fixed_value (val);
6708 /* Return OFF rounded upward if necessary to a multiple of
6709 ALIGNMENT (a power of 2). */
6712 align_value (unsigned int off, unsigned int alignment)
6714 return (off + alignment - 1) & ~(alignment - 1);
6717 /* Return the bit alignment required for field #F of template type TYPE. */
6720 field_alignment (struct type *type, int f)
6722 const char *name = TYPE_FIELD_NAME (type, f);
6726 /* The field name should never be null, unless the debugging information
6727 is somehow malformed. In this case, we assume the field does not
6728 require any alignment. */
6732 len = strlen (name);
6734 if (!isdigit (name[len - 1]))
6737 if (isdigit (name[len - 2]))
6738 align_offset = len - 2;
6740 align_offset = len - 1;
6742 if (align_offset < 7 || strncmp ("___XV", name + align_offset - 6, 5) != 0)
6743 return TARGET_CHAR_BIT;
6745 return atoi (name + align_offset) * TARGET_CHAR_BIT;
6748 /* Find a symbol named NAME. Ignores ambiguity. */
6751 ada_find_any_symbol (const char *name)
6755 sym = standard_lookup (name, get_selected_block (NULL), VAR_DOMAIN);
6756 if (sym != NULL && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
6759 sym = standard_lookup (name, NULL, STRUCT_DOMAIN);
6763 /* Find a type named NAME. Ignores ambiguity. This routine will look
6764 solely for types defined by debug info, it will not search the GDB
6768 ada_find_any_type (const char *name)
6770 struct symbol *sym = ada_find_any_symbol (name);
6773 return SYMBOL_TYPE (sym);
6778 /* Given NAME and an associated BLOCK, search all symbols for
6779 NAME suffixed with "___XR", which is the ``renaming'' symbol
6780 associated to NAME. Return this symbol if found, return
6784 ada_find_renaming_symbol (const char *name, struct block *block)
6788 sym = find_old_style_renaming_symbol (name, block);
6793 /* Not right yet. FIXME pnh 7/20/2007. */
6794 sym = ada_find_any_symbol (name);
6795 if (sym != NULL && strstr (SYMBOL_LINKAGE_NAME (sym), "___XR") != NULL)
6801 static struct symbol *
6802 find_old_style_renaming_symbol (const char *name, struct block *block)
6804 const struct symbol *function_sym = block_linkage_function (block);
6807 if (function_sym != NULL)
6809 /* If the symbol is defined inside a function, NAME is not fully
6810 qualified. This means we need to prepend the function name
6811 as well as adding the ``___XR'' suffix to build the name of
6812 the associated renaming symbol. */
6813 char *function_name = SYMBOL_LINKAGE_NAME (function_sym);
6814 /* Function names sometimes contain suffixes used
6815 for instance to qualify nested subprograms. When building
6816 the XR type name, we need to make sure that this suffix is
6817 not included. So do not include any suffix in the function
6818 name length below. */
6819 int function_name_len = ada_name_prefix_len (function_name);
6820 const int rename_len = function_name_len + 2 /* "__" */
6821 + strlen (name) + 6 /* "___XR\0" */ ;
6823 /* Strip the suffix if necessary. */
6824 ada_remove_trailing_digits (function_name, &function_name_len);
6825 ada_remove_po_subprogram_suffix (function_name, &function_name_len);
6826 ada_remove_Xbn_suffix (function_name, &function_name_len);
6828 /* Library-level functions are a special case, as GNAT adds
6829 a ``_ada_'' prefix to the function name to avoid namespace
6830 pollution. However, the renaming symbols themselves do not
6831 have this prefix, so we need to skip this prefix if present. */
6832 if (function_name_len > 5 /* "_ada_" */
6833 && strstr (function_name, "_ada_") == function_name)
6836 function_name_len -= 5;
6839 rename = (char *) alloca (rename_len * sizeof (char));
6840 strncpy (rename, function_name, function_name_len);
6841 xsnprintf (rename + function_name_len, rename_len - function_name_len,
6846 const int rename_len = strlen (name) + 6;
6848 rename = (char *) alloca (rename_len * sizeof (char));
6849 xsnprintf (rename, rename_len * sizeof (char), "%s___XR", name);
6852 return ada_find_any_symbol (rename);
6855 /* Because of GNAT encoding conventions, several GDB symbols may match a
6856 given type name. If the type denoted by TYPE0 is to be preferred to
6857 that of TYPE1 for purposes of type printing, return non-zero;
6858 otherwise return 0. */
6861 ada_prefer_type (struct type *type0, struct type *type1)
6865 else if (type0 == NULL)
6867 else if (TYPE_CODE (type1) == TYPE_CODE_VOID)
6869 else if (TYPE_CODE (type0) == TYPE_CODE_VOID)
6871 else if (TYPE_NAME (type1) == NULL && TYPE_NAME (type0) != NULL)
6873 else if (ada_is_constrained_packed_array_type (type0))
6875 else if (ada_is_array_descriptor_type (type0)
6876 && !ada_is_array_descriptor_type (type1))
6880 const char *type0_name = type_name_no_tag (type0);
6881 const char *type1_name = type_name_no_tag (type1);
6883 if (type0_name != NULL && strstr (type0_name, "___XR") != NULL
6884 && (type1_name == NULL || strstr (type1_name, "___XR") == NULL))
6890 /* The name of TYPE, which is either its TYPE_NAME, or, if that is
6891 null, its TYPE_TAG_NAME. Null if TYPE is null. */
6894 ada_type_name (struct type *type)
6898 else if (TYPE_NAME (type) != NULL)
6899 return TYPE_NAME (type);
6901 return TYPE_TAG_NAME (type);
6904 /* Search the list of "descriptive" types associated to TYPE for a type
6905 whose name is NAME. */
6907 static struct type *
6908 find_parallel_type_by_descriptive_type (struct type *type, const char *name)
6910 struct type *result;
6912 /* If there no descriptive-type info, then there is no parallel type
6914 if (!HAVE_GNAT_AUX_INFO (type))
6917 result = TYPE_DESCRIPTIVE_TYPE (type);
6918 while (result != NULL)
6920 char *result_name = ada_type_name (result);
6922 if (result_name == NULL)
6924 warning (_("unexpected null name on descriptive type"));
6928 /* If the names match, stop. */
6929 if (strcmp (result_name, name) == 0)
6932 /* Otherwise, look at the next item on the list, if any. */
6933 if (HAVE_GNAT_AUX_INFO (result))
6934 result = TYPE_DESCRIPTIVE_TYPE (result);
6939 /* If we didn't find a match, see whether this is a packed array. With
6940 older compilers, the descriptive type information is either absent or
6941 irrelevant when it comes to packed arrays so the above lookup fails.
6942 Fall back to using a parallel lookup by name in this case. */
6943 if (result == NULL && ada_is_constrained_packed_array_type (type))
6944 return ada_find_any_type (name);
6949 /* Find a parallel type to TYPE with the specified NAME, using the
6950 descriptive type taken from the debugging information, if available,
6951 and otherwise using the (slower) name-based method. */
6953 static struct type *
6954 ada_find_parallel_type_with_name (struct type *type, const char *name)
6956 struct type *result = NULL;
6958 if (HAVE_GNAT_AUX_INFO (type))
6959 result = find_parallel_type_by_descriptive_type (type, name);
6961 result = ada_find_any_type (name);
6966 /* Same as above, but specify the name of the parallel type by appending
6967 SUFFIX to the name of TYPE. */
6970 ada_find_parallel_type (struct type *type, const char *suffix)
6972 char *name, *typename = ada_type_name (type);
6975 if (typename == NULL)
6978 len = strlen (typename);
6980 name = (char *) alloca (len + strlen (suffix) + 1);
6982 strcpy (name, typename);
6983 strcpy (name + len, suffix);
6985 return ada_find_parallel_type_with_name (type, name);
6988 /* If TYPE is a variable-size record type, return the corresponding template
6989 type describing its fields. Otherwise, return NULL. */
6991 static struct type *
6992 dynamic_template_type (struct type *type)
6994 type = ada_check_typedef (type);
6996 if (type == NULL || TYPE_CODE (type) != TYPE_CODE_STRUCT
6997 || ada_type_name (type) == NULL)
7001 int len = strlen (ada_type_name (type));
7003 if (len > 6 && strcmp (ada_type_name (type) + len - 6, "___XVE") == 0)
7006 return ada_find_parallel_type (type, "___XVE");
7010 /* Assuming that TEMPL_TYPE is a union or struct type, returns
7011 non-zero iff field FIELD_NUM of TEMPL_TYPE has dynamic size. */
7014 is_dynamic_field (struct type *templ_type, int field_num)
7016 const char *name = TYPE_FIELD_NAME (templ_type, field_num);
7019 && TYPE_CODE (TYPE_FIELD_TYPE (templ_type, field_num)) == TYPE_CODE_PTR
7020 && strstr (name, "___XVL") != NULL;
7023 /* The index of the variant field of TYPE, or -1 if TYPE does not
7024 represent a variant record type. */
7027 variant_field_index (struct type *type)
7031 if (type == NULL || TYPE_CODE (type) != TYPE_CODE_STRUCT)
7034 for (f = 0; f < TYPE_NFIELDS (type); f += 1)
7036 if (ada_is_variant_part (type, f))
7042 /* A record type with no fields. */
7044 static struct type *
7045 empty_record (struct type *template)
7047 struct type *type = alloc_type_copy (template);
7049 TYPE_CODE (type) = TYPE_CODE_STRUCT;
7050 TYPE_NFIELDS (type) = 0;
7051 TYPE_FIELDS (type) = NULL;
7052 INIT_CPLUS_SPECIFIC (type);
7053 TYPE_NAME (type) = "<empty>";
7054 TYPE_TAG_NAME (type) = NULL;
7055 TYPE_LENGTH (type) = 0;
7059 /* An ordinary record type (with fixed-length fields) that describes
7060 the value of type TYPE at VALADDR or ADDRESS (see comments at
7061 the beginning of this section) VAL according to GNAT conventions.
7062 DVAL0 should describe the (portion of a) record that contains any
7063 necessary discriminants. It should be NULL if value_type (VAL) is
7064 an outer-level type (i.e., as opposed to a branch of a variant.) A
7065 variant field (unless unchecked) is replaced by a particular branch
7068 If not KEEP_DYNAMIC_FIELDS, then all fields whose position or
7069 length are not statically known are discarded. As a consequence,
7070 VALADDR, ADDRESS and DVAL0 are ignored.
7072 NOTE: Limitations: For now, we assume that dynamic fields and
7073 variants occupy whole numbers of bytes. However, they need not be
7077 ada_template_to_fixed_record_type_1 (struct type *type,
7078 const gdb_byte *valaddr,
7079 CORE_ADDR address, struct value *dval0,
7080 int keep_dynamic_fields)
7082 struct value *mark = value_mark ();
7085 int nfields, bit_len;
7091 /* Compute the number of fields in this record type that are going
7092 to be processed: unless keep_dynamic_fields, this includes only
7093 fields whose position and length are static will be processed. */
7094 if (keep_dynamic_fields)
7095 nfields = TYPE_NFIELDS (type);
7099 while (nfields < TYPE_NFIELDS (type)
7100 && !ada_is_variant_part (type, nfields)
7101 && !is_dynamic_field (type, nfields))
7105 rtype = alloc_type_copy (type);
7106 TYPE_CODE (rtype) = TYPE_CODE_STRUCT;
7107 INIT_CPLUS_SPECIFIC (rtype);
7108 TYPE_NFIELDS (rtype) = nfields;
7109 TYPE_FIELDS (rtype) = (struct field *)
7110 TYPE_ALLOC (rtype, nfields * sizeof (struct field));
7111 memset (TYPE_FIELDS (rtype), 0, sizeof (struct field) * nfields);
7112 TYPE_NAME (rtype) = ada_type_name (type);
7113 TYPE_TAG_NAME (rtype) = NULL;
7114 TYPE_FIXED_INSTANCE (rtype) = 1;
7120 for (f = 0; f < nfields; f += 1)
7122 off = align_value (off, field_alignment (type, f))
7123 + TYPE_FIELD_BITPOS (type, f);
7124 TYPE_FIELD_BITPOS (rtype, f) = off;
7125 TYPE_FIELD_BITSIZE (rtype, f) = 0;
7127 if (ada_is_variant_part (type, f))
7132 else if (is_dynamic_field (type, f))
7134 const gdb_byte *field_valaddr = valaddr;
7135 CORE_ADDR field_address = address;
7136 struct type *field_type =
7137 TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, f));
7141 /* rtype's length is computed based on the run-time
7142 value of discriminants. If the discriminants are not
7143 initialized, the type size may be completely bogus and
7144 GDB may fail to allocate a value for it. So check the
7145 size first before creating the value. */
7147 dval = value_from_contents_and_address (rtype, valaddr, address);
7152 /* If the type referenced by this field is an aligner type, we need
7153 to unwrap that aligner type, because its size might not be set.
7154 Keeping the aligner type would cause us to compute the wrong
7155 size for this field, impacting the offset of the all the fields
7156 that follow this one. */
7157 if (ada_is_aligner_type (field_type))
7159 long field_offset = TYPE_FIELD_BITPOS (field_type, f);
7161 field_valaddr = cond_offset_host (field_valaddr, field_offset);
7162 field_address = cond_offset_target (field_address, field_offset);
7163 field_type = ada_aligned_type (field_type);
7166 field_valaddr = cond_offset_host (field_valaddr,
7167 off / TARGET_CHAR_BIT);
7168 field_address = cond_offset_target (field_address,
7169 off / TARGET_CHAR_BIT);
7171 /* Get the fixed type of the field. Note that, in this case,
7172 we do not want to get the real type out of the tag: if
7173 the current field is the parent part of a tagged record,
7174 we will get the tag of the object. Clearly wrong: the real
7175 type of the parent is not the real type of the child. We
7176 would end up in an infinite loop. */
7177 field_type = ada_get_base_type (field_type);
7178 field_type = ada_to_fixed_type (field_type, field_valaddr,
7179 field_address, dval, 0);
7180 /* If the field size is already larger than the maximum
7181 object size, then the record itself will necessarily
7182 be larger than the maximum object size. We need to make
7183 this check now, because the size might be so ridiculously
7184 large (due to an uninitialized variable in the inferior)
7185 that it would cause an overflow when adding it to the
7187 check_size (field_type);
7189 TYPE_FIELD_TYPE (rtype, f) = field_type;
7190 TYPE_FIELD_NAME (rtype, f) = TYPE_FIELD_NAME (type, f);
7191 /* The multiplication can potentially overflow. But because
7192 the field length has been size-checked just above, and
7193 assuming that the maximum size is a reasonable value,
7194 an overflow should not happen in practice. So rather than
7195 adding overflow recovery code to this already complex code,
7196 we just assume that it's not going to happen. */
7198 TYPE_LENGTH (TYPE_FIELD_TYPE (rtype, f)) * TARGET_CHAR_BIT;
7202 struct type *field_type = TYPE_FIELD_TYPE (type, f);
7204 /* If our field is a typedef type (most likely a typedef of
7205 a fat pointer, encoding an array access), then we need to
7206 look at its target type to determine its characteristics.
7207 In particular, we would miscompute the field size if we took
7208 the size of the typedef (zero), instead of the size of
7210 if (TYPE_CODE (field_type) == TYPE_CODE_TYPEDEF)
7211 field_type = ada_typedef_target_type (field_type);
7213 TYPE_FIELD_TYPE (rtype, f) = field_type;
7214 TYPE_FIELD_NAME (rtype, f) = TYPE_FIELD_NAME (type, f);
7215 if (TYPE_FIELD_BITSIZE (type, f) > 0)
7217 TYPE_FIELD_BITSIZE (rtype, f) = TYPE_FIELD_BITSIZE (type, f);
7220 TYPE_LENGTH (ada_check_typedef (field_type)) * TARGET_CHAR_BIT;
7222 if (off + fld_bit_len > bit_len)
7223 bit_len = off + fld_bit_len;
7225 TYPE_LENGTH (rtype) =
7226 align_value (bit_len, TARGET_CHAR_BIT) / TARGET_CHAR_BIT;
7229 /* We handle the variant part, if any, at the end because of certain
7230 odd cases in which it is re-ordered so as NOT to be the last field of
7231 the record. This can happen in the presence of representation
7233 if (variant_field >= 0)
7235 struct type *branch_type;
7237 off = TYPE_FIELD_BITPOS (rtype, variant_field);
7240 dval = value_from_contents_and_address (rtype, valaddr, address);
7245 to_fixed_variant_branch_type
7246 (TYPE_FIELD_TYPE (type, variant_field),
7247 cond_offset_host (valaddr, off / TARGET_CHAR_BIT),
7248 cond_offset_target (address, off / TARGET_CHAR_BIT), dval);
7249 if (branch_type == NULL)
7251 for (f = variant_field + 1; f < TYPE_NFIELDS (rtype); f += 1)
7252 TYPE_FIELDS (rtype)[f - 1] = TYPE_FIELDS (rtype)[f];
7253 TYPE_NFIELDS (rtype) -= 1;
7257 TYPE_FIELD_TYPE (rtype, variant_field) = branch_type;
7258 TYPE_FIELD_NAME (rtype, variant_field) = "S";
7260 TYPE_LENGTH (TYPE_FIELD_TYPE (rtype, variant_field)) *
7262 if (off + fld_bit_len > bit_len)
7263 bit_len = off + fld_bit_len;
7264 TYPE_LENGTH (rtype) =
7265 align_value (bit_len, TARGET_CHAR_BIT) / TARGET_CHAR_BIT;
7269 /* According to exp_dbug.ads, the size of TYPE for variable-size records
7270 should contain the alignment of that record, which should be a strictly
7271 positive value. If null or negative, then something is wrong, most
7272 probably in the debug info. In that case, we don't round up the size
7273 of the resulting type. If this record is not part of another structure,
7274 the current RTYPE length might be good enough for our purposes. */
7275 if (TYPE_LENGTH (type) <= 0)
7277 if (TYPE_NAME (rtype))
7278 warning (_("Invalid type size for `%s' detected: %d."),
7279 TYPE_NAME (rtype), TYPE_LENGTH (type));
7281 warning (_("Invalid type size for <unnamed> detected: %d."),
7282 TYPE_LENGTH (type));
7286 TYPE_LENGTH (rtype) = align_value (TYPE_LENGTH (rtype),
7287 TYPE_LENGTH (type));
7290 value_free_to_mark (mark);
7291 if (TYPE_LENGTH (rtype) > varsize_limit)
7292 error (_("record type with dynamic size is larger than varsize-limit"));
7296 /* As for ada_template_to_fixed_record_type_1 with KEEP_DYNAMIC_FIELDS
7299 static struct type *
7300 template_to_fixed_record_type (struct type *type, const gdb_byte *valaddr,
7301 CORE_ADDR address, struct value *dval0)
7303 return ada_template_to_fixed_record_type_1 (type, valaddr,
7307 /* An ordinary record type in which ___XVL-convention fields and
7308 ___XVU- and ___XVN-convention field types in TYPE0 are replaced with
7309 static approximations, containing all possible fields. Uses
7310 no runtime values. Useless for use in values, but that's OK,
7311 since the results are used only for type determinations. Works on both
7312 structs and unions. Representation note: to save space, we memorize
7313 the result of this function in the TYPE_TARGET_TYPE of the
7316 static struct type *
7317 template_to_static_fixed_type (struct type *type0)
7323 if (TYPE_TARGET_TYPE (type0) != NULL)
7324 return TYPE_TARGET_TYPE (type0);
7326 nfields = TYPE_NFIELDS (type0);
7329 for (f = 0; f < nfields; f += 1)
7331 struct type *field_type = ada_check_typedef (TYPE_FIELD_TYPE (type0, f));
7332 struct type *new_type;
7334 if (is_dynamic_field (type0, f))
7335 new_type = to_static_fixed_type (TYPE_TARGET_TYPE (field_type));
7337 new_type = static_unwrap_type (field_type);
7338 if (type == type0 && new_type != field_type)
7340 TYPE_TARGET_TYPE (type0) = type = alloc_type_copy (type0);
7341 TYPE_CODE (type) = TYPE_CODE (type0);
7342 INIT_CPLUS_SPECIFIC (type);
7343 TYPE_NFIELDS (type) = nfields;
7344 TYPE_FIELDS (type) = (struct field *)
7345 TYPE_ALLOC (type, nfields * sizeof (struct field));
7346 memcpy (TYPE_FIELDS (type), TYPE_FIELDS (type0),
7347 sizeof (struct field) * nfields);
7348 TYPE_NAME (type) = ada_type_name (type0);
7349 TYPE_TAG_NAME (type) = NULL;
7350 TYPE_FIXED_INSTANCE (type) = 1;
7351 TYPE_LENGTH (type) = 0;
7353 TYPE_FIELD_TYPE (type, f) = new_type;
7354 TYPE_FIELD_NAME (type, f) = TYPE_FIELD_NAME (type0, f);
7359 /* Given an object of type TYPE whose contents are at VALADDR and
7360 whose address in memory is ADDRESS, returns a revision of TYPE,
7361 which should be a non-dynamic-sized record, in which the variant
7362 part, if any, is replaced with the appropriate branch. Looks
7363 for discriminant values in DVAL0, which can be NULL if the record
7364 contains the necessary discriminant values. */
7366 static struct type *
7367 to_record_with_fixed_variant_part (struct type *type, const gdb_byte *valaddr,
7368 CORE_ADDR address, struct value *dval0)
7370 struct value *mark = value_mark ();
7373 struct type *branch_type;
7374 int nfields = TYPE_NFIELDS (type);
7375 int variant_field = variant_field_index (type);
7377 if (variant_field == -1)
7381 dval = value_from_contents_and_address (type, valaddr, address);
7385 rtype = alloc_type_copy (type);
7386 TYPE_CODE (rtype) = TYPE_CODE_STRUCT;
7387 INIT_CPLUS_SPECIFIC (rtype);
7388 TYPE_NFIELDS (rtype) = nfields;
7389 TYPE_FIELDS (rtype) =
7390 (struct field *) TYPE_ALLOC (rtype, nfields * sizeof (struct field));
7391 memcpy (TYPE_FIELDS (rtype), TYPE_FIELDS (type),
7392 sizeof (struct field) * nfields);
7393 TYPE_NAME (rtype) = ada_type_name (type);
7394 TYPE_TAG_NAME (rtype) = NULL;
7395 TYPE_FIXED_INSTANCE (rtype) = 1;
7396 TYPE_LENGTH (rtype) = TYPE_LENGTH (type);
7398 branch_type = to_fixed_variant_branch_type
7399 (TYPE_FIELD_TYPE (type, variant_field),
7400 cond_offset_host (valaddr,
7401 TYPE_FIELD_BITPOS (type, variant_field)
7403 cond_offset_target (address,
7404 TYPE_FIELD_BITPOS (type, variant_field)
7405 / TARGET_CHAR_BIT), dval);
7406 if (branch_type == NULL)
7410 for (f = variant_field + 1; f < nfields; f += 1)
7411 TYPE_FIELDS (rtype)[f - 1] = TYPE_FIELDS (rtype)[f];
7412 TYPE_NFIELDS (rtype) -= 1;
7416 TYPE_FIELD_TYPE (rtype, variant_field) = branch_type;
7417 TYPE_FIELD_NAME (rtype, variant_field) = "S";
7418 TYPE_FIELD_BITSIZE (rtype, variant_field) = 0;
7419 TYPE_LENGTH (rtype) += TYPE_LENGTH (branch_type);
7421 TYPE_LENGTH (rtype) -= TYPE_LENGTH (TYPE_FIELD_TYPE (type, variant_field));
7423 value_free_to_mark (mark);
7427 /* An ordinary record type (with fixed-length fields) that describes
7428 the value at (TYPE0, VALADDR, ADDRESS) [see explanation at
7429 beginning of this section]. Any necessary discriminants' values
7430 should be in DVAL, a record value; it may be NULL if the object
7431 at ADDR itself contains any necessary discriminant values.
7432 Additionally, VALADDR and ADDRESS may also be NULL if no discriminant
7433 values from the record are needed. Except in the case that DVAL,
7434 VALADDR, and ADDRESS are all 0 or NULL, a variant field (unless
7435 unchecked) is replaced by a particular branch of the variant.
7437 NOTE: the case in which DVAL and VALADDR are NULL and ADDRESS is 0
7438 is questionable and may be removed. It can arise during the
7439 processing of an unconstrained-array-of-record type where all the
7440 variant branches have exactly the same size. This is because in
7441 such cases, the compiler does not bother to use the XVS convention
7442 when encoding the record. I am currently dubious of this
7443 shortcut and suspect the compiler should be altered. FIXME. */
7445 static struct type *
7446 to_fixed_record_type (struct type *type0, const gdb_byte *valaddr,
7447 CORE_ADDR address, struct value *dval)
7449 struct type *templ_type;
7451 if (TYPE_FIXED_INSTANCE (type0))
7454 templ_type = dynamic_template_type (type0);
7456 if (templ_type != NULL)
7457 return template_to_fixed_record_type (templ_type, valaddr, address, dval);
7458 else if (variant_field_index (type0) >= 0)
7460 if (dval == NULL && valaddr == NULL && address == 0)
7462 return to_record_with_fixed_variant_part (type0, valaddr, address,
7467 TYPE_FIXED_INSTANCE (type0) = 1;
7473 /* An ordinary record type (with fixed-length fields) that describes
7474 the value at (VAR_TYPE0, VALADDR, ADDRESS), where VAR_TYPE0 is a
7475 union type. Any necessary discriminants' values should be in DVAL,
7476 a record value. That is, this routine selects the appropriate
7477 branch of the union at ADDR according to the discriminant value
7478 indicated in the union's type name. Returns VAR_TYPE0 itself if
7479 it represents a variant subject to a pragma Unchecked_Union. */
7481 static struct type *
7482 to_fixed_variant_branch_type (struct type *var_type0, const gdb_byte *valaddr,
7483 CORE_ADDR address, struct value *dval)
7486 struct type *templ_type;
7487 struct type *var_type;
7489 if (TYPE_CODE (var_type0) == TYPE_CODE_PTR)
7490 var_type = TYPE_TARGET_TYPE (var_type0);
7492 var_type = var_type0;
7494 templ_type = ada_find_parallel_type (var_type, "___XVU");
7496 if (templ_type != NULL)
7497 var_type = templ_type;
7499 if (is_unchecked_variant (var_type, value_type (dval)))
7502 ada_which_variant_applies (var_type,
7503 value_type (dval), value_contents (dval));
7506 return empty_record (var_type);
7507 else if (is_dynamic_field (var_type, which))
7508 return to_fixed_record_type
7509 (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (var_type, which)),
7510 valaddr, address, dval);
7511 else if (variant_field_index (TYPE_FIELD_TYPE (var_type, which)) >= 0)
7513 to_fixed_record_type
7514 (TYPE_FIELD_TYPE (var_type, which), valaddr, address, dval);
7516 return TYPE_FIELD_TYPE (var_type, which);
7519 /* Assuming that TYPE0 is an array type describing the type of a value
7520 at ADDR, and that DVAL describes a record containing any
7521 discriminants used in TYPE0, returns a type for the value that
7522 contains no dynamic components (that is, no components whose sizes
7523 are determined by run-time quantities). Unless IGNORE_TOO_BIG is
7524 true, gives an error message if the resulting type's size is over
7527 static struct type *
7528 to_fixed_array_type (struct type *type0, struct value *dval,
7531 struct type *index_type_desc;
7532 struct type *result;
7533 int constrained_packed_array_p;
7535 if (TYPE_FIXED_INSTANCE (type0))
7538 constrained_packed_array_p = ada_is_constrained_packed_array_type (type0);
7539 if (constrained_packed_array_p)
7540 type0 = decode_constrained_packed_array_type (type0);
7542 index_type_desc = ada_find_parallel_type (type0, "___XA");
7543 ada_fixup_array_indexes_type (index_type_desc);
7544 if (index_type_desc == NULL)
7546 struct type *elt_type0 = ada_check_typedef (TYPE_TARGET_TYPE (type0));
7548 /* NOTE: elt_type---the fixed version of elt_type0---should never
7549 depend on the contents of the array in properly constructed
7551 /* Create a fixed version of the array element type.
7552 We're not providing the address of an element here,
7553 and thus the actual object value cannot be inspected to do
7554 the conversion. This should not be a problem, since arrays of
7555 unconstrained objects are not allowed. In particular, all
7556 the elements of an array of a tagged type should all be of
7557 the same type specified in the debugging info. No need to
7558 consult the object tag. */
7559 struct type *elt_type = ada_to_fixed_type (elt_type0, 0, 0, dval, 1);
7561 /* Make sure we always create a new array type when dealing with
7562 packed array types, since we're going to fix-up the array
7563 type length and element bitsize a little further down. */
7564 if (elt_type0 == elt_type && !constrained_packed_array_p)
7567 result = create_array_type (alloc_type_copy (type0),
7568 elt_type, TYPE_INDEX_TYPE (type0));
7573 struct type *elt_type0;
7576 for (i = TYPE_NFIELDS (index_type_desc); i > 0; i -= 1)
7577 elt_type0 = TYPE_TARGET_TYPE (elt_type0);
7579 /* NOTE: result---the fixed version of elt_type0---should never
7580 depend on the contents of the array in properly constructed
7582 /* Create a fixed version of the array element type.
7583 We're not providing the address of an element here,
7584 and thus the actual object value cannot be inspected to do
7585 the conversion. This should not be a problem, since arrays of
7586 unconstrained objects are not allowed. In particular, all
7587 the elements of an array of a tagged type should all be of
7588 the same type specified in the debugging info. No need to
7589 consult the object tag. */
7591 ada_to_fixed_type (ada_check_typedef (elt_type0), 0, 0, dval, 1);
7594 for (i = TYPE_NFIELDS (index_type_desc) - 1; i >= 0; i -= 1)
7596 struct type *range_type =
7597 to_fixed_range_type (TYPE_FIELD_TYPE (index_type_desc, i), dval);
7599 result = create_array_type (alloc_type_copy (elt_type0),
7600 result, range_type);
7601 elt_type0 = TYPE_TARGET_TYPE (elt_type0);
7603 if (!ignore_too_big && TYPE_LENGTH (result) > varsize_limit)
7604 error (_("array type with dynamic size is larger than varsize-limit"));
7607 if (constrained_packed_array_p)
7609 /* So far, the resulting type has been created as if the original
7610 type was a regular (non-packed) array type. As a result, the
7611 bitsize of the array elements needs to be set again, and the array
7612 length needs to be recomputed based on that bitsize. */
7613 int len = TYPE_LENGTH (result) / TYPE_LENGTH (TYPE_TARGET_TYPE (result));
7614 int elt_bitsize = TYPE_FIELD_BITSIZE (type0, 0);
7616 TYPE_FIELD_BITSIZE (result, 0) = TYPE_FIELD_BITSIZE (type0, 0);
7617 TYPE_LENGTH (result) = len * elt_bitsize / HOST_CHAR_BIT;
7618 if (TYPE_LENGTH (result) * HOST_CHAR_BIT < len * elt_bitsize)
7619 TYPE_LENGTH (result)++;
7622 TYPE_FIXED_INSTANCE (result) = 1;
7627 /* A standard type (containing no dynamically sized components)
7628 corresponding to TYPE for the value (TYPE, VALADDR, ADDRESS)
7629 DVAL describes a record containing any discriminants used in TYPE0,
7630 and may be NULL if there are none, or if the object of type TYPE at
7631 ADDRESS or in VALADDR contains these discriminants.
7633 If CHECK_TAG is not null, in the case of tagged types, this function
7634 attempts to locate the object's tag and use it to compute the actual
7635 type. However, when ADDRESS is null, we cannot use it to determine the
7636 location of the tag, and therefore compute the tagged type's actual type.
7637 So we return the tagged type without consulting the tag. */
7639 static struct type *
7640 ada_to_fixed_type_1 (struct type *type, const gdb_byte *valaddr,
7641 CORE_ADDR address, struct value *dval, int check_tag)
7643 type = ada_check_typedef (type);
7644 switch (TYPE_CODE (type))
7648 case TYPE_CODE_STRUCT:
7650 struct type *static_type = to_static_fixed_type (type);
7651 struct type *fixed_record_type =
7652 to_fixed_record_type (type, valaddr, address, NULL);
7654 /* If STATIC_TYPE is a tagged type and we know the object's address,
7655 then we can determine its tag, and compute the object's actual
7656 type from there. Note that we have to use the fixed record
7657 type (the parent part of the record may have dynamic fields
7658 and the way the location of _tag is expressed may depend on
7661 if (check_tag && address != 0 && ada_is_tagged_type (static_type, 0))
7663 struct type *real_type =
7664 type_from_tag (value_tag_from_contents_and_address
7669 if (real_type != NULL)
7670 return to_fixed_record_type (real_type, valaddr, address, NULL);
7673 /* Check to see if there is a parallel ___XVZ variable.
7674 If there is, then it provides the actual size of our type. */
7675 else if (ada_type_name (fixed_record_type) != NULL)
7677 char *name = ada_type_name (fixed_record_type);
7678 char *xvz_name = alloca (strlen (name) + 7 /* "___XVZ\0" */);
7682 xsnprintf (xvz_name, strlen (name) + 7, "%s___XVZ", name);
7683 size = get_int_var_value (xvz_name, &xvz_found);
7684 if (xvz_found && TYPE_LENGTH (fixed_record_type) != size)
7686 fixed_record_type = copy_type (fixed_record_type);
7687 TYPE_LENGTH (fixed_record_type) = size;
7689 /* The FIXED_RECORD_TYPE may have be a stub. We have
7690 observed this when the debugging info is STABS, and
7691 apparently it is something that is hard to fix.
7693 In practice, we don't need the actual type definition
7694 at all, because the presence of the XVZ variable allows us
7695 to assume that there must be a XVS type as well, which we
7696 should be able to use later, when we need the actual type
7699 In the meantime, pretend that the "fixed" type we are
7700 returning is NOT a stub, because this can cause trouble
7701 when using this type to create new types targeting it.
7702 Indeed, the associated creation routines often check
7703 whether the target type is a stub and will try to replace
7704 it, thus using a type with the wrong size. This, in turn,
7705 might cause the new type to have the wrong size too.
7706 Consider the case of an array, for instance, where the size
7707 of the array is computed from the number of elements in
7708 our array multiplied by the size of its element. */
7709 TYPE_STUB (fixed_record_type) = 0;
7712 return fixed_record_type;
7714 case TYPE_CODE_ARRAY:
7715 return to_fixed_array_type (type, dval, 1);
7716 case TYPE_CODE_UNION:
7720 return to_fixed_variant_branch_type (type, valaddr, address, dval);
7724 /* The same as ada_to_fixed_type_1, except that it preserves the type
7725 if it is a TYPE_CODE_TYPEDEF of a type that is already fixed.
7727 The typedef layer needs be preserved in order to differentiate between
7728 arrays and array pointers when both types are implemented using the same
7729 fat pointer. In the array pointer case, the pointer is encoded as
7730 a typedef of the pointer type. For instance, considering:
7732 type String_Access is access String;
7733 S1 : String_Access := null;
7735 To the debugger, S1 is defined as a typedef of type String. But
7736 to the user, it is a pointer. So if the user tries to print S1,
7737 we should not dereference the array, but print the array address
7740 If we didn't preserve the typedef layer, we would lose the fact that
7741 the type is to be presented as a pointer (needs de-reference before
7742 being printed). And we would also use the source-level type name. */
7745 ada_to_fixed_type (struct type *type, const gdb_byte *valaddr,
7746 CORE_ADDR address, struct value *dval, int check_tag)
7749 struct type *fixed_type =
7750 ada_to_fixed_type_1 (type, valaddr, address, dval, check_tag);
7752 /* If TYPE is a typedef and its target type is the same as the FIXED_TYPE,
7753 then preserve the typedef layer.
7755 Implementation note: We can only check the main-type portion of
7756 the TYPE and FIXED_TYPE, because eliminating the typedef layer
7757 from TYPE now returns a type that has the same instance flags
7758 as TYPE. For instance, if TYPE is a "typedef const", and its
7759 target type is a "struct", then the typedef elimination will return
7760 a "const" version of the target type. See check_typedef for more
7761 details about how the typedef layer elimination is done.
7763 brobecker/2010-11-19: It seems to me that the only case where it is
7764 useful to preserve the typedef layer is when dealing with fat pointers.
7765 Perhaps, we could add a check for that and preserve the typedef layer
7766 only in that situation. But this seems unecessary so far, probably
7767 because we call check_typedef/ada_check_typedef pretty much everywhere.
7769 if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF
7770 && (TYPE_MAIN_TYPE (ada_typedef_target_type (type))
7771 == TYPE_MAIN_TYPE (fixed_type)))
7777 /* A standard (static-sized) type corresponding as well as possible to
7778 TYPE0, but based on no runtime data. */
7780 static struct type *
7781 to_static_fixed_type (struct type *type0)
7788 if (TYPE_FIXED_INSTANCE (type0))
7791 type0 = ada_check_typedef (type0);
7793 switch (TYPE_CODE (type0))
7797 case TYPE_CODE_STRUCT:
7798 type = dynamic_template_type (type0);
7800 return template_to_static_fixed_type (type);
7802 return template_to_static_fixed_type (type0);
7803 case TYPE_CODE_UNION:
7804 type = ada_find_parallel_type (type0, "___XVU");
7806 return template_to_static_fixed_type (type);
7808 return template_to_static_fixed_type (type0);
7812 /* A static approximation of TYPE with all type wrappers removed. */
7814 static struct type *
7815 static_unwrap_type (struct type *type)
7817 if (ada_is_aligner_type (type))
7819 struct type *type1 = TYPE_FIELD_TYPE (ada_check_typedef (type), 0);
7820 if (ada_type_name (type1) == NULL)
7821 TYPE_NAME (type1) = ada_type_name (type);
7823 return static_unwrap_type (type1);
7827 struct type *raw_real_type = ada_get_base_type (type);
7829 if (raw_real_type == type)
7832 return to_static_fixed_type (raw_real_type);
7836 /* In some cases, incomplete and private types require
7837 cross-references that are not resolved as records (for example,
7839 type FooP is access Foo;
7841 type Foo is array ...;
7842 ). In these cases, since there is no mechanism for producing
7843 cross-references to such types, we instead substitute for FooP a
7844 stub enumeration type that is nowhere resolved, and whose tag is
7845 the name of the actual type. Call these types "non-record stubs". */
7847 /* A type equivalent to TYPE that is not a non-record stub, if one
7848 exists, otherwise TYPE. */
7851 ada_check_typedef (struct type *type)
7856 /* If our type is a typedef type of a fat pointer, then we're done.
7857 We don't want to strip the TYPE_CODE_TYPDEF layer, because this is
7858 what allows us to distinguish between fat pointers that represent
7859 array types, and fat pointers that represent array access types
7860 (in both cases, the compiler implements them as fat pointers). */
7861 if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF
7862 && is_thick_pntr (ada_typedef_target_type (type)))
7865 CHECK_TYPEDEF (type);
7866 if (type == NULL || TYPE_CODE (type) != TYPE_CODE_ENUM
7867 || !TYPE_STUB (type)
7868 || TYPE_TAG_NAME (type) == NULL)
7872 char *name = TYPE_TAG_NAME (type);
7873 struct type *type1 = ada_find_any_type (name);
7878 /* TYPE1 might itself be a TYPE_CODE_TYPEDEF (this can happen with
7879 stubs pointing to arrays, as we don't create symbols for array
7880 types, only for the typedef-to-array types). If that's the case,
7881 strip the typedef layer. */
7882 if (TYPE_CODE (type1) == TYPE_CODE_TYPEDEF)
7883 type1 = ada_check_typedef (type1);
7889 /* A value representing the data at VALADDR/ADDRESS as described by
7890 type TYPE0, but with a standard (static-sized) type that correctly
7891 describes it. If VAL0 is not NULL and TYPE0 already is a standard
7892 type, then return VAL0 [this feature is simply to avoid redundant
7893 creation of struct values]. */
7895 static struct value *
7896 ada_to_fixed_value_create (struct type *type0, CORE_ADDR address,
7899 struct type *type = ada_to_fixed_type (type0, 0, address, NULL, 1);
7901 if (type == type0 && val0 != NULL)
7904 return value_from_contents_and_address (type, 0, address);
7907 /* A value representing VAL, but with a standard (static-sized) type
7908 that correctly describes it. Does not necessarily create a new
7912 ada_to_fixed_value (struct value *val)
7914 return ada_to_fixed_value_create (value_type (val),
7915 value_address (val),
7922 /* Table mapping attribute numbers to names.
7923 NOTE: Keep up to date with enum ada_attribute definition in ada-lang.h. */
7925 static const char *attribute_names[] = {
7943 ada_attribute_name (enum exp_opcode n)
7945 if (n >= OP_ATR_FIRST && n <= (int) OP_ATR_VAL)
7946 return attribute_names[n - OP_ATR_FIRST + 1];
7948 return attribute_names[0];
7951 /* Evaluate the 'POS attribute applied to ARG. */
7954 pos_atr (struct value *arg)
7956 struct value *val = coerce_ref (arg);
7957 struct type *type = value_type (val);
7959 if (!discrete_type_p (type))
7960 error (_("'POS only defined on discrete types"));
7962 if (TYPE_CODE (type) == TYPE_CODE_ENUM)
7965 LONGEST v = value_as_long (val);
7967 for (i = 0; i < TYPE_NFIELDS (type); i += 1)
7969 if (v == TYPE_FIELD_BITPOS (type, i))
7972 error (_("enumeration value is invalid: can't find 'POS"));
7975 return value_as_long (val);
7978 static struct value *
7979 value_pos_atr (struct type *type, struct value *arg)
7981 return value_from_longest (type, pos_atr (arg));
7984 /* Evaluate the TYPE'VAL attribute applied to ARG. */
7986 static struct value *
7987 value_val_atr (struct type *type, struct value *arg)
7989 if (!discrete_type_p (type))
7990 error (_("'VAL only defined on discrete types"));
7991 if (!integer_type_p (value_type (arg)))
7992 error (_("'VAL requires integral argument"));
7994 if (TYPE_CODE (type) == TYPE_CODE_ENUM)
7996 long pos = value_as_long (arg);
7998 if (pos < 0 || pos >= TYPE_NFIELDS (type))
7999 error (_("argument to 'VAL out of range"));
8000 return value_from_longest (type, TYPE_FIELD_BITPOS (type, pos));
8003 return value_from_longest (type, value_as_long (arg));
8009 /* True if TYPE appears to be an Ada character type.
8010 [At the moment, this is true only for Character and Wide_Character;
8011 It is a heuristic test that could stand improvement]. */
8014 ada_is_character_type (struct type *type)
8018 /* If the type code says it's a character, then assume it really is,
8019 and don't check any further. */
8020 if (TYPE_CODE (type) == TYPE_CODE_CHAR)
8023 /* Otherwise, assume it's a character type iff it is a discrete type
8024 with a known character type name. */
8025 name = ada_type_name (type);
8026 return (name != NULL
8027 && (TYPE_CODE (type) == TYPE_CODE_INT
8028 || TYPE_CODE (type) == TYPE_CODE_RANGE)
8029 && (strcmp (name, "character") == 0
8030 || strcmp (name, "wide_character") == 0
8031 || strcmp (name, "wide_wide_character") == 0
8032 || strcmp (name, "unsigned char") == 0));
8035 /* True if TYPE appears to be an Ada string type. */
8038 ada_is_string_type (struct type *type)
8040 type = ada_check_typedef (type);
8042 && TYPE_CODE (type) != TYPE_CODE_PTR
8043 && (ada_is_simple_array_type (type)
8044 || ada_is_array_descriptor_type (type))
8045 && ada_array_arity (type) == 1)
8047 struct type *elttype = ada_array_element_type (type, 1);
8049 return ada_is_character_type (elttype);
8055 /* The compiler sometimes provides a parallel XVS type for a given
8056 PAD type. Normally, it is safe to follow the PAD type directly,
8057 but older versions of the compiler have a bug that causes the offset
8058 of its "F" field to be wrong. Following that field in that case
8059 would lead to incorrect results, but this can be worked around
8060 by ignoring the PAD type and using the associated XVS type instead.
8062 Set to True if the debugger should trust the contents of PAD types.
8063 Otherwise, ignore the PAD type if there is a parallel XVS type. */
8064 static int trust_pad_over_xvs = 1;
8066 /* True if TYPE is a struct type introduced by the compiler to force the
8067 alignment of a value. Such types have a single field with a
8068 distinctive name. */
8071 ada_is_aligner_type (struct type *type)
8073 type = ada_check_typedef (type);
8075 if (!trust_pad_over_xvs && ada_find_parallel_type (type, "___XVS") != NULL)
8078 return (TYPE_CODE (type) == TYPE_CODE_STRUCT
8079 && TYPE_NFIELDS (type) == 1
8080 && strcmp (TYPE_FIELD_NAME (type, 0), "F") == 0);
8083 /* If there is an ___XVS-convention type parallel to SUBTYPE, return
8084 the parallel type. */
8087 ada_get_base_type (struct type *raw_type)
8089 struct type *real_type_namer;
8090 struct type *raw_real_type;
8092 if (raw_type == NULL || TYPE_CODE (raw_type) != TYPE_CODE_STRUCT)
8095 if (ada_is_aligner_type (raw_type))
8096 /* The encoding specifies that we should always use the aligner type.
8097 So, even if this aligner type has an associated XVS type, we should
8100 According to the compiler gurus, an XVS type parallel to an aligner
8101 type may exist because of a stabs limitation. In stabs, aligner
8102 types are empty because the field has a variable-sized type, and
8103 thus cannot actually be used as an aligner type. As a result,
8104 we need the associated parallel XVS type to decode the type.
8105 Since the policy in the compiler is to not change the internal
8106 representation based on the debugging info format, we sometimes
8107 end up having a redundant XVS type parallel to the aligner type. */
8110 real_type_namer = ada_find_parallel_type (raw_type, "___XVS");
8111 if (real_type_namer == NULL
8112 || TYPE_CODE (real_type_namer) != TYPE_CODE_STRUCT
8113 || TYPE_NFIELDS (real_type_namer) != 1)
8116 if (TYPE_CODE (TYPE_FIELD_TYPE (real_type_namer, 0)) != TYPE_CODE_REF)
8118 /* This is an older encoding form where the base type needs to be
8119 looked up by name. We prefer the newer enconding because it is
8121 raw_real_type = ada_find_any_type (TYPE_FIELD_NAME (real_type_namer, 0));
8122 if (raw_real_type == NULL)
8125 return raw_real_type;
8128 /* The field in our XVS type is a reference to the base type. */
8129 return TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (real_type_namer, 0));
8132 /* The type of value designated by TYPE, with all aligners removed. */
8135 ada_aligned_type (struct type *type)
8137 if (ada_is_aligner_type (type))
8138 return ada_aligned_type (TYPE_FIELD_TYPE (type, 0));
8140 return ada_get_base_type (type);
8144 /* The address of the aligned value in an object at address VALADDR
8145 having type TYPE. Assumes ada_is_aligner_type (TYPE). */
8148 ada_aligned_value_addr (struct type *type, const gdb_byte *valaddr)
8150 if (ada_is_aligner_type (type))
8151 return ada_aligned_value_addr (TYPE_FIELD_TYPE (type, 0),
8153 TYPE_FIELD_BITPOS (type,
8154 0) / TARGET_CHAR_BIT);
8161 /* The printed representation of an enumeration literal with encoded
8162 name NAME. The value is good to the next call of ada_enum_name. */
8164 ada_enum_name (const char *name)
8166 static char *result;
8167 static size_t result_len = 0;
8170 /* First, unqualify the enumeration name:
8171 1. Search for the last '.' character. If we find one, then skip
8172 all the preceeding characters, the unqualified name starts
8173 right after that dot.
8174 2. Otherwise, we may be debugging on a target where the compiler
8175 translates dots into "__". Search forward for double underscores,
8176 but stop searching when we hit an overloading suffix, which is
8177 of the form "__" followed by digits. */
8179 tmp = strrchr (name, '.');
8184 while ((tmp = strstr (name, "__")) != NULL)
8186 if (isdigit (tmp[2]))
8197 if (name[1] == 'U' || name[1] == 'W')
8199 if (sscanf (name + 2, "%x", &v) != 1)
8205 GROW_VECT (result, result_len, 16);
8206 if (isascii (v) && isprint (v))
8207 xsnprintf (result, result_len, "'%c'", v);
8208 else if (name[1] == 'U')
8209 xsnprintf (result, result_len, "[\"%02x\"]", v);
8211 xsnprintf (result, result_len, "[\"%04x\"]", v);
8217 tmp = strstr (name, "__");
8219 tmp = strstr (name, "$");
8222 GROW_VECT (result, result_len, tmp - name + 1);
8223 strncpy (result, name, tmp - name);
8224 result[tmp - name] = '\0';
8232 /* Evaluate the subexpression of EXP starting at *POS as for
8233 evaluate_type, updating *POS to point just past the evaluated
8236 static struct value *
8237 evaluate_subexp_type (struct expression *exp, int *pos)
8239 return evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
8242 /* If VAL is wrapped in an aligner or subtype wrapper, return the
8245 static struct value *
8246 unwrap_value (struct value *val)
8248 struct type *type = ada_check_typedef (value_type (val));
8250 if (ada_is_aligner_type (type))
8252 struct value *v = ada_value_struct_elt (val, "F", 0);
8253 struct type *val_type = ada_check_typedef (value_type (v));
8255 if (ada_type_name (val_type) == NULL)
8256 TYPE_NAME (val_type) = ada_type_name (type);
8258 return unwrap_value (v);
8262 struct type *raw_real_type =
8263 ada_check_typedef (ada_get_base_type (type));
8265 /* If there is no parallel XVS or XVE type, then the value is
8266 already unwrapped. Return it without further modification. */
8267 if ((type == raw_real_type)
8268 && ada_find_parallel_type (type, "___XVE") == NULL)
8272 coerce_unspec_val_to_type
8273 (val, ada_to_fixed_type (raw_real_type, 0,
8274 value_address (val),
8279 static struct value *
8280 cast_to_fixed (struct type *type, struct value *arg)
8284 if (type == value_type (arg))
8286 else if (ada_is_fixed_point_type (value_type (arg)))
8287 val = ada_float_to_fixed (type,
8288 ada_fixed_to_float (value_type (arg),
8289 value_as_long (arg)));
8292 DOUBLEST argd = value_as_double (arg);
8294 val = ada_float_to_fixed (type, argd);
8297 return value_from_longest (type, val);
8300 static struct value *
8301 cast_from_fixed (struct type *type, struct value *arg)
8303 DOUBLEST val = ada_fixed_to_float (value_type (arg),
8304 value_as_long (arg));
8306 return value_from_double (type, val);
8309 /* Coerce VAL as necessary for assignment to an lval of type TYPE, and
8310 return the converted value. */
8312 static struct value *
8313 coerce_for_assign (struct type *type, struct value *val)
8315 struct type *type2 = value_type (val);
8320 type2 = ada_check_typedef (type2);
8321 type = ada_check_typedef (type);
8323 if (TYPE_CODE (type2) == TYPE_CODE_PTR
8324 && TYPE_CODE (type) == TYPE_CODE_ARRAY)
8326 val = ada_value_ind (val);
8327 type2 = value_type (val);
8330 if (TYPE_CODE (type2) == TYPE_CODE_ARRAY
8331 && TYPE_CODE (type) == TYPE_CODE_ARRAY)
8333 if (TYPE_LENGTH (type2) != TYPE_LENGTH (type)
8334 || TYPE_LENGTH (TYPE_TARGET_TYPE (type2))
8335 != TYPE_LENGTH (TYPE_TARGET_TYPE (type2)))
8336 error (_("Incompatible types in assignment"));
8337 deprecated_set_value_type (val, type);
8342 static struct value *
8343 ada_value_binop (struct value *arg1, struct value *arg2, enum exp_opcode op)
8346 struct type *type1, *type2;
8349 arg1 = coerce_ref (arg1);
8350 arg2 = coerce_ref (arg2);
8351 type1 = base_type (ada_check_typedef (value_type (arg1)));
8352 type2 = base_type (ada_check_typedef (value_type (arg2)));
8354 if (TYPE_CODE (type1) != TYPE_CODE_INT
8355 || TYPE_CODE (type2) != TYPE_CODE_INT)
8356 return value_binop (arg1, arg2, op);
8365 return value_binop (arg1, arg2, op);
8368 v2 = value_as_long (arg2);
8370 error (_("second operand of %s must not be zero."), op_string (op));
8372 if (TYPE_UNSIGNED (type1) || op == BINOP_MOD)
8373 return value_binop (arg1, arg2, op);
8375 v1 = value_as_long (arg1);
8380 if (!TRUNCATION_TOWARDS_ZERO && v1 * (v1 % v2) < 0)
8381 v += v > 0 ? -1 : 1;
8389 /* Should not reach this point. */
8393 val = allocate_value (type1);
8394 store_unsigned_integer (value_contents_raw (val),
8395 TYPE_LENGTH (value_type (val)),
8396 gdbarch_byte_order (get_type_arch (type1)), v);
8401 ada_value_equal (struct value *arg1, struct value *arg2)
8403 if (ada_is_direct_array_type (value_type (arg1))
8404 || ada_is_direct_array_type (value_type (arg2)))
8406 /* Automatically dereference any array reference before
8407 we attempt to perform the comparison. */
8408 arg1 = ada_coerce_ref (arg1);
8409 arg2 = ada_coerce_ref (arg2);
8411 arg1 = ada_coerce_to_simple_array (arg1);
8412 arg2 = ada_coerce_to_simple_array (arg2);
8413 if (TYPE_CODE (value_type (arg1)) != TYPE_CODE_ARRAY
8414 || TYPE_CODE (value_type (arg2)) != TYPE_CODE_ARRAY)
8415 error (_("Attempt to compare array with non-array"));
8416 /* FIXME: The following works only for types whose
8417 representations use all bits (no padding or undefined bits)
8418 and do not have user-defined equality. */
8420 TYPE_LENGTH (value_type (arg1)) == TYPE_LENGTH (value_type (arg2))
8421 && memcmp (value_contents (arg1), value_contents (arg2),
8422 TYPE_LENGTH (value_type (arg1))) == 0;
8424 return value_equal (arg1, arg2);
8427 /* Total number of component associations in the aggregate starting at
8428 index PC in EXP. Assumes that index PC is the start of an
8432 num_component_specs (struct expression *exp, int pc)
8436 m = exp->elts[pc + 1].longconst;
8439 for (i = 0; i < m; i += 1)
8441 switch (exp->elts[pc].opcode)
8447 n += exp->elts[pc + 1].longconst;
8450 ada_evaluate_subexp (NULL, exp, &pc, EVAL_SKIP);
8455 /* Assign the result of evaluating EXP starting at *POS to the INDEXth
8456 component of LHS (a simple array or a record), updating *POS past
8457 the expression, assuming that LHS is contained in CONTAINER. Does
8458 not modify the inferior's memory, nor does it modify LHS (unless
8459 LHS == CONTAINER). */
8462 assign_component (struct value *container, struct value *lhs, LONGEST index,
8463 struct expression *exp, int *pos)
8465 struct value *mark = value_mark ();
8468 if (TYPE_CODE (value_type (lhs)) == TYPE_CODE_ARRAY)
8470 struct type *index_type = builtin_type (exp->gdbarch)->builtin_int;
8471 struct value *index_val = value_from_longest (index_type, index);
8473 elt = unwrap_value (ada_value_subscript (lhs, 1, &index_val));
8477 elt = ada_index_struct_field (index, lhs, 0, value_type (lhs));
8478 elt = ada_to_fixed_value (unwrap_value (elt));
8481 if (exp->elts[*pos].opcode == OP_AGGREGATE)
8482 assign_aggregate (container, elt, exp, pos, EVAL_NORMAL);
8484 value_assign_to_component (container, elt,
8485 ada_evaluate_subexp (NULL, exp, pos,
8488 value_free_to_mark (mark);
8491 /* Assuming that LHS represents an lvalue having a record or array
8492 type, and EXP->ELTS[*POS] is an OP_AGGREGATE, evaluate an assignment
8493 of that aggregate's value to LHS, advancing *POS past the
8494 aggregate. NOSIDE is as for evaluate_subexp. CONTAINER is an
8495 lvalue containing LHS (possibly LHS itself). Does not modify
8496 the inferior's memory, nor does it modify the contents of
8497 LHS (unless == CONTAINER). Returns the modified CONTAINER. */
8499 static struct value *
8500 assign_aggregate (struct value *container,
8501 struct value *lhs, struct expression *exp,
8502 int *pos, enum noside noside)
8504 struct type *lhs_type;
8505 int n = exp->elts[*pos+1].longconst;
8506 LONGEST low_index, high_index;
8509 int max_indices, num_indices;
8510 int is_array_aggregate;
8514 if (noside != EVAL_NORMAL)
8518 for (i = 0; i < n; i += 1)
8519 ada_evaluate_subexp (NULL, exp, pos, noside);
8523 container = ada_coerce_ref (container);
8524 if (ada_is_direct_array_type (value_type (container)))
8525 container = ada_coerce_to_simple_array (container);
8526 lhs = ada_coerce_ref (lhs);
8527 if (!deprecated_value_modifiable (lhs))
8528 error (_("Left operand of assignment is not a modifiable lvalue."));
8530 lhs_type = value_type (lhs);
8531 if (ada_is_direct_array_type (lhs_type))
8533 lhs = ada_coerce_to_simple_array (lhs);
8534 lhs_type = value_type (lhs);
8535 low_index = TYPE_ARRAY_LOWER_BOUND_VALUE (lhs_type);
8536 high_index = TYPE_ARRAY_UPPER_BOUND_VALUE (lhs_type);
8537 is_array_aggregate = 1;
8539 else if (TYPE_CODE (lhs_type) == TYPE_CODE_STRUCT)
8542 high_index = num_visible_fields (lhs_type) - 1;
8543 is_array_aggregate = 0;
8546 error (_("Left-hand side must be array or record."));
8548 num_specs = num_component_specs (exp, *pos - 3);
8549 max_indices = 4 * num_specs + 4;
8550 indices = alloca (max_indices * sizeof (indices[0]));
8551 indices[0] = indices[1] = low_index - 1;
8552 indices[2] = indices[3] = high_index + 1;
8555 for (i = 0; i < n; i += 1)
8557 switch (exp->elts[*pos].opcode)
8560 aggregate_assign_from_choices (container, lhs, exp, pos, indices,
8561 &num_indices, max_indices,
8562 low_index, high_index);
8565 aggregate_assign_positional (container, lhs, exp, pos, indices,
8566 &num_indices, max_indices,
8567 low_index, high_index);
8571 error (_("Misplaced 'others' clause"));
8572 aggregate_assign_others (container, lhs, exp, pos, indices,
8573 num_indices, low_index, high_index);
8576 error (_("Internal error: bad aggregate clause"));
8583 /* Assign into the component of LHS indexed by the OP_POSITIONAL
8584 construct at *POS, updating *POS past the construct, given that
8585 the positions are relative to lower bound LOW, where HIGH is the
8586 upper bound. Record the position in INDICES[0 .. MAX_INDICES-1]
8587 updating *NUM_INDICES as needed. CONTAINER is as for
8588 assign_aggregate. */
8590 aggregate_assign_positional (struct value *container,
8591 struct value *lhs, struct expression *exp,
8592 int *pos, LONGEST *indices, int *num_indices,
8593 int max_indices, LONGEST low, LONGEST high)
8595 LONGEST ind = longest_to_int (exp->elts[*pos + 1].longconst) + low;
8597 if (ind - 1 == high)
8598 warning (_("Extra components in aggregate ignored."));
8601 add_component_interval (ind, ind, indices, num_indices, max_indices);
8603 assign_component (container, lhs, ind, exp, pos);
8606 ada_evaluate_subexp (NULL, exp, pos, EVAL_SKIP);
8609 /* Assign into the components of LHS indexed by the OP_CHOICES
8610 construct at *POS, updating *POS past the construct, given that
8611 the allowable indices are LOW..HIGH. Record the indices assigned
8612 to in INDICES[0 .. MAX_INDICES-1], updating *NUM_INDICES as
8613 needed. CONTAINER is as for assign_aggregate. */
8615 aggregate_assign_from_choices (struct value *container,
8616 struct value *lhs, struct expression *exp,
8617 int *pos, LONGEST *indices, int *num_indices,
8618 int max_indices, LONGEST low, LONGEST high)
8621 int n_choices = longest_to_int (exp->elts[*pos+1].longconst);
8622 int choice_pos, expr_pc;
8623 int is_array = ada_is_direct_array_type (value_type (lhs));
8625 choice_pos = *pos += 3;
8627 for (j = 0; j < n_choices; j += 1)
8628 ada_evaluate_subexp (NULL, exp, pos, EVAL_SKIP);
8630 ada_evaluate_subexp (NULL, exp, pos, EVAL_SKIP);
8632 for (j = 0; j < n_choices; j += 1)
8634 LONGEST lower, upper;
8635 enum exp_opcode op = exp->elts[choice_pos].opcode;
8637 if (op == OP_DISCRETE_RANGE)
8640 lower = value_as_long (ada_evaluate_subexp (NULL, exp, pos,
8642 upper = value_as_long (ada_evaluate_subexp (NULL, exp, pos,
8647 lower = value_as_long (ada_evaluate_subexp (NULL, exp, &choice_pos,
8659 name = &exp->elts[choice_pos + 2].string;
8662 name = SYMBOL_NATURAL_NAME (exp->elts[choice_pos + 2].symbol);
8665 error (_("Invalid record component association."));
8667 ada_evaluate_subexp (NULL, exp, &choice_pos, EVAL_SKIP);
8669 if (! find_struct_field (name, value_type (lhs), 0,
8670 NULL, NULL, NULL, NULL, &ind))
8671 error (_("Unknown component name: %s."), name);
8672 lower = upper = ind;
8675 if (lower <= upper && (lower < low || upper > high))
8676 error (_("Index in component association out of bounds."));
8678 add_component_interval (lower, upper, indices, num_indices,
8680 while (lower <= upper)
8685 assign_component (container, lhs, lower, exp, &pos1);
8691 /* Assign the value of the expression in the OP_OTHERS construct in
8692 EXP at *POS into the components of LHS indexed from LOW .. HIGH that
8693 have not been previously assigned. The index intervals already assigned
8694 are in INDICES[0 .. NUM_INDICES-1]. Updates *POS to after the
8695 OP_OTHERS clause. CONTAINER is as for assign_aggregate. */
8697 aggregate_assign_others (struct value *container,
8698 struct value *lhs, struct expression *exp,
8699 int *pos, LONGEST *indices, int num_indices,
8700 LONGEST low, LONGEST high)
8703 int expr_pc = *pos+1;
8705 for (i = 0; i < num_indices - 2; i += 2)
8709 for (ind = indices[i + 1] + 1; ind < indices[i + 2]; ind += 1)
8714 assign_component (container, lhs, ind, exp, &pos);
8717 ada_evaluate_subexp (NULL, exp, pos, EVAL_SKIP);
8720 /* Add the interval [LOW .. HIGH] to the sorted set of intervals
8721 [ INDICES[0] .. INDICES[1] ],..., [ INDICES[*SIZE-2] .. INDICES[*SIZE-1] ],
8722 modifying *SIZE as needed. It is an error if *SIZE exceeds
8723 MAX_SIZE. The resulting intervals do not overlap. */
8725 add_component_interval (LONGEST low, LONGEST high,
8726 LONGEST* indices, int *size, int max_size)
8730 for (i = 0; i < *size; i += 2) {
8731 if (high >= indices[i] && low <= indices[i + 1])
8735 for (kh = i + 2; kh < *size; kh += 2)
8736 if (high < indices[kh])
8738 if (low < indices[i])
8740 indices[i + 1] = indices[kh - 1];
8741 if (high > indices[i + 1])
8742 indices[i + 1] = high;
8743 memcpy (indices + i + 2, indices + kh, *size - kh);
8744 *size -= kh - i - 2;
8747 else if (high < indices[i])
8751 if (*size == max_size)
8752 error (_("Internal error: miscounted aggregate components."));
8754 for (j = *size-1; j >= i+2; j -= 1)
8755 indices[j] = indices[j - 2];
8757 indices[i + 1] = high;
8760 /* Perform and Ada cast of ARG2 to type TYPE if the type of ARG2
8763 static struct value *
8764 ada_value_cast (struct type *type, struct value *arg2, enum noside noside)
8766 if (type == ada_check_typedef (value_type (arg2)))
8769 if (ada_is_fixed_point_type (type))
8770 return (cast_to_fixed (type, arg2));
8772 if (ada_is_fixed_point_type (value_type (arg2)))
8773 return cast_from_fixed (type, arg2);
8775 return value_cast (type, arg2);
8778 /* Evaluating Ada expressions, and printing their result.
8779 ------------------------------------------------------
8784 We usually evaluate an Ada expression in order to print its value.
8785 We also evaluate an expression in order to print its type, which
8786 happens during the EVAL_AVOID_SIDE_EFFECTS phase of the evaluation,
8787 but we'll focus mostly on the EVAL_NORMAL phase. In practice, the
8788 EVAL_AVOID_SIDE_EFFECTS phase allows us to simplify certain aspects of
8789 the evaluation compared to the EVAL_NORMAL, but is otherwise very
8792 Evaluating expressions is a little more complicated for Ada entities
8793 than it is for entities in languages such as C. The main reason for
8794 this is that Ada provides types whose definition might be dynamic.
8795 One example of such types is variant records. Or another example
8796 would be an array whose bounds can only be known at run time.
8798 The following description is a general guide as to what should be
8799 done (and what should NOT be done) in order to evaluate an expression
8800 involving such types, and when. This does not cover how the semantic
8801 information is encoded by GNAT as this is covered separatly. For the
8802 document used as the reference for the GNAT encoding, see exp_dbug.ads
8803 in the GNAT sources.
8805 Ideally, we should embed each part of this description next to its
8806 associated code. Unfortunately, the amount of code is so vast right
8807 now that it's hard to see whether the code handling a particular
8808 situation might be duplicated or not. One day, when the code is
8809 cleaned up, this guide might become redundant with the comments
8810 inserted in the code, and we might want to remove it.
8812 2. ``Fixing'' an Entity, the Simple Case:
8813 -----------------------------------------
8815 When evaluating Ada expressions, the tricky issue is that they may
8816 reference entities whose type contents and size are not statically
8817 known. Consider for instance a variant record:
8819 type Rec (Empty : Boolean := True) is record
8822 when False => Value : Integer;
8825 Yes : Rec := (Empty => False, Value => 1);
8826 No : Rec := (empty => True);
8828 The size and contents of that record depends on the value of the
8829 descriminant (Rec.Empty). At this point, neither the debugging
8830 information nor the associated type structure in GDB are able to
8831 express such dynamic types. So what the debugger does is to create
8832 "fixed" versions of the type that applies to the specific object.
8833 We also informally refer to this opperation as "fixing" an object,
8834 which means creating its associated fixed type.
8836 Example: when printing the value of variable "Yes" above, its fixed
8837 type would look like this:
8844 On the other hand, if we printed the value of "No", its fixed type
8851 Things become a little more complicated when trying to fix an entity
8852 with a dynamic type that directly contains another dynamic type,
8853 such as an array of variant records, for instance. There are
8854 two possible cases: Arrays, and records.
8856 3. ``Fixing'' Arrays:
8857 ---------------------
8859 The type structure in GDB describes an array in terms of its bounds,
8860 and the type of its elements. By design, all elements in the array
8861 have the same type and we cannot represent an array of variant elements
8862 using the current type structure in GDB. When fixing an array,
8863 we cannot fix the array element, as we would potentially need one
8864 fixed type per element of the array. As a result, the best we can do
8865 when fixing an array is to produce an array whose bounds and size
8866 are correct (allowing us to read it from memory), but without having
8867 touched its element type. Fixing each element will be done later,
8868 when (if) necessary.
8870 Arrays are a little simpler to handle than records, because the same
8871 amount of memory is allocated for each element of the array, even if
8872 the amount of space actually used by each element differs from element
8873 to element. Consider for instance the following array of type Rec:
8875 type Rec_Array is array (1 .. 2) of Rec;
8877 The actual amount of memory occupied by each element might be different
8878 from element to element, depending on the value of their discriminant.
8879 But the amount of space reserved for each element in the array remains
8880 fixed regardless. So we simply need to compute that size using
8881 the debugging information available, from which we can then determine
8882 the array size (we multiply the number of elements of the array by
8883 the size of each element).
8885 The simplest case is when we have an array of a constrained element
8886 type. For instance, consider the following type declarations:
8888 type Bounded_String (Max_Size : Integer) is
8890 Buffer : String (1 .. Max_Size);
8892 type Bounded_String_Array is array (1 ..2) of Bounded_String (80);
8894 In this case, the compiler describes the array as an array of
8895 variable-size elements (identified by its XVS suffix) for which
8896 the size can be read in the parallel XVZ variable.
8898 In the case of an array of an unconstrained element type, the compiler
8899 wraps the array element inside a private PAD type. This type should not
8900 be shown to the user, and must be "unwrap"'ed before printing. Note
8901 that we also use the adjective "aligner" in our code to designate
8902 these wrapper types.
8904 In some cases, the size allocated for each element is statically
8905 known. In that case, the PAD type already has the correct size,
8906 and the array element should remain unfixed.
8908 But there are cases when this size is not statically known.
8909 For instance, assuming that "Five" is an integer variable:
8911 type Dynamic is array (1 .. Five) of Integer;
8912 type Wrapper (Has_Length : Boolean := False) is record
8915 when True => Length : Integer;
8919 type Wrapper_Array is array (1 .. 2) of Wrapper;
8921 Hello : Wrapper_Array := (others => (Has_Length => True,
8922 Data => (others => 17),
8926 The debugging info would describe variable Hello as being an
8927 array of a PAD type. The size of that PAD type is not statically
8928 known, but can be determined using a parallel XVZ variable.
8929 In that case, a copy of the PAD type with the correct size should
8930 be used for the fixed array.
8932 3. ``Fixing'' record type objects:
8933 ----------------------------------
8935 Things are slightly different from arrays in the case of dynamic
8936 record types. In this case, in order to compute the associated
8937 fixed type, we need to determine the size and offset of each of
8938 its components. This, in turn, requires us to compute the fixed
8939 type of each of these components.
8941 Consider for instance the example:
8943 type Bounded_String (Max_Size : Natural) is record
8944 Str : String (1 .. Max_Size);
8947 My_String : Bounded_String (Max_Size => 10);
8949 In that case, the position of field "Length" depends on the size
8950 of field Str, which itself depends on the value of the Max_Size
8951 discriminant. In order to fix the type of variable My_String,
8952 we need to fix the type of field Str. Therefore, fixing a variant
8953 record requires us to fix each of its components.
8955 However, if a component does not have a dynamic size, the component
8956 should not be fixed. In particular, fields that use a PAD type
8957 should not fixed. Here is an example where this might happen
8958 (assuming type Rec above):
8960 type Container (Big : Boolean) is record
8964 when True => Another : Integer;
8968 My_Container : Container := (Big => False,
8969 First => (Empty => True),
8972 In that example, the compiler creates a PAD type for component First,
8973 whose size is constant, and then positions the component After just
8974 right after it. The offset of component After is therefore constant
8977 The debugger computes the position of each field based on an algorithm
8978 that uses, among other things, the actual position and size of the field
8979 preceding it. Let's now imagine that the user is trying to print
8980 the value of My_Container. If the type fixing was recursive, we would
8981 end up computing the offset of field After based on the size of the
8982 fixed version of field First. And since in our example First has
8983 only one actual field, the size of the fixed type is actually smaller
8984 than the amount of space allocated to that field, and thus we would
8985 compute the wrong offset of field After.
8987 To make things more complicated, we need to watch out for dynamic
8988 components of variant records (identified by the ___XVL suffix in
8989 the component name). Even if the target type is a PAD type, the size
8990 of that type might not be statically known. So the PAD type needs
8991 to be unwrapped and the resulting type needs to be fixed. Otherwise,
8992 we might end up with the wrong size for our component. This can be
8993 observed with the following type declarations:
8995 type Octal is new Integer range 0 .. 7;
8996 type Octal_Array is array (Positive range <>) of Octal;
8997 pragma Pack (Octal_Array);
8999 type Octal_Buffer (Size : Positive) is record
9000 Buffer : Octal_Array (1 .. Size);
9004 In that case, Buffer is a PAD type whose size is unset and needs
9005 to be computed by fixing the unwrapped type.
9007 4. When to ``Fix'' un-``Fixed'' sub-elements of an entity:
9008 ----------------------------------------------------------
9010 Lastly, when should the sub-elements of an entity that remained unfixed
9011 thus far, be actually fixed?
9013 The answer is: Only when referencing that element. For instance
9014 when selecting one component of a record, this specific component
9015 should be fixed at that point in time. Or when printing the value
9016 of a record, each component should be fixed before its value gets
9017 printed. Similarly for arrays, the element of the array should be
9018 fixed when printing each element of the array, or when extracting
9019 one element out of that array. On the other hand, fixing should
9020 not be performed on the elements when taking a slice of an array!
9022 Note that one of the side-effects of miscomputing the offset and
9023 size of each field is that we end up also miscomputing the size
9024 of the containing type. This can have adverse results when computing
9025 the value of an entity. GDB fetches the value of an entity based
9026 on the size of its type, and thus a wrong size causes GDB to fetch
9027 the wrong amount of memory. In the case where the computed size is
9028 too small, GDB fetches too little data to print the value of our
9029 entiry. Results in this case as unpredicatble, as we usually read
9030 past the buffer containing the data =:-o. */
9032 /* Implement the evaluate_exp routine in the exp_descriptor structure
9033 for the Ada language. */
9035 static struct value *
9036 ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
9037 int *pos, enum noside noside)
9042 struct value *arg1 = NULL, *arg2 = NULL, *arg3;
9045 struct value **argvec;
9049 op = exp->elts[pc].opcode;
9055 arg1 = evaluate_subexp_standard (expect_type, exp, pos, noside);
9056 arg1 = unwrap_value (arg1);
9058 /* If evaluating an OP_DOUBLE and an EXPECT_TYPE was provided,
9059 then we need to perform the conversion manually, because
9060 evaluate_subexp_standard doesn't do it. This conversion is
9061 necessary in Ada because the different kinds of float/fixed
9062 types in Ada have different representations.
9064 Similarly, we need to perform the conversion from OP_LONG
9066 if ((op == OP_DOUBLE || op == OP_LONG) && expect_type != NULL)
9067 arg1 = ada_value_cast (expect_type, arg1, noside);
9073 struct value *result;
9076 result = evaluate_subexp_standard (expect_type, exp, pos, noside);
9077 /* The result type will have code OP_STRING, bashed there from
9078 OP_ARRAY. Bash it back. */
9079 if (TYPE_CODE (value_type (result)) == TYPE_CODE_STRING)
9080 TYPE_CODE (value_type (result)) = TYPE_CODE_ARRAY;
9086 type = exp->elts[pc + 1].type;
9087 arg1 = evaluate_subexp (type, exp, pos, noside);
9088 if (noside == EVAL_SKIP)
9090 arg1 = ada_value_cast (type, arg1, noside);
9095 type = exp->elts[pc + 1].type;
9096 return ada_evaluate_subexp (type, exp, pos, noside);
9099 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
9100 if (exp->elts[*pos].opcode == OP_AGGREGATE)
9102 arg1 = assign_aggregate (arg1, arg1, exp, pos, noside);
9103 if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
9105 return ada_value_assign (arg1, arg1);
9107 /* Force the evaluation of the rhs ARG2 to the type of the lhs ARG1,
9108 except if the lhs of our assignment is a convenience variable.
9109 In the case of assigning to a convenience variable, the lhs
9110 should be exactly the result of the evaluation of the rhs. */
9111 type = value_type (arg1);
9112 if (VALUE_LVAL (arg1) == lval_internalvar)
9114 arg2 = evaluate_subexp (type, exp, pos, noside);
9115 if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
9117 if (ada_is_fixed_point_type (value_type (arg1)))
9118 arg2 = cast_to_fixed (value_type (arg1), arg2);
9119 else if (ada_is_fixed_point_type (value_type (arg2)))
9121 (_("Fixed-point values must be assigned to fixed-point variables"));
9123 arg2 = coerce_for_assign (value_type (arg1), arg2);
9124 return ada_value_assign (arg1, arg2);
9127 arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
9128 arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
9129 if (noside == EVAL_SKIP)
9131 if (TYPE_CODE (value_type (arg1)) == TYPE_CODE_PTR)
9132 return (value_from_longest
9134 value_as_long (arg1) + value_as_long (arg2)));
9135 if ((ada_is_fixed_point_type (value_type (arg1))
9136 || ada_is_fixed_point_type (value_type (arg2)))
9137 && value_type (arg1) != value_type (arg2))
9138 error (_("Operands of fixed-point addition must have the same type"));
9139 /* Do the addition, and cast the result to the type of the first
9140 argument. We cannot cast the result to a reference type, so if
9141 ARG1 is a reference type, find its underlying type. */
9142 type = value_type (arg1);
9143 while (TYPE_CODE (type) == TYPE_CODE_REF)
9144 type = TYPE_TARGET_TYPE (type);
9145 binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
9146 return value_cast (type, value_binop (arg1, arg2, BINOP_ADD));
9149 arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
9150 arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
9151 if (noside == EVAL_SKIP)
9153 if (TYPE_CODE (value_type (arg1)) == TYPE_CODE_PTR)
9154 return (value_from_longest
9156 value_as_long (arg1) - value_as_long (arg2)));
9157 if ((ada_is_fixed_point_type (value_type (arg1))
9158 || ada_is_fixed_point_type (value_type (arg2)))
9159 && value_type (arg1) != value_type (arg2))
9160 error (_("Operands of fixed-point subtraction "
9161 "must have the same type"));
9162 /* Do the substraction, and cast the result to the type of the first
9163 argument. We cannot cast the result to a reference type, so if
9164 ARG1 is a reference type, find its underlying type. */
9165 type = value_type (arg1);
9166 while (TYPE_CODE (type) == TYPE_CODE_REF)
9167 type = TYPE_TARGET_TYPE (type);
9168 binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
9169 return value_cast (type, value_binop (arg1, arg2, BINOP_SUB));
9175 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
9176 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
9177 if (noside == EVAL_SKIP)
9179 else if (noside == EVAL_AVOID_SIDE_EFFECTS)
9181 binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
9182 return value_zero (value_type (arg1), not_lval);
9186 type = builtin_type (exp->gdbarch)->builtin_double;
9187 if (ada_is_fixed_point_type (value_type (arg1)))
9188 arg1 = cast_from_fixed (type, arg1);
9189 if (ada_is_fixed_point_type (value_type (arg2)))
9190 arg2 = cast_from_fixed (type, arg2);
9191 binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
9192 return ada_value_binop (arg1, arg2, op);
9196 case BINOP_NOTEQUAL:
9197 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
9198 arg2 = evaluate_subexp (value_type (arg1), exp, pos, noside);
9199 if (noside == EVAL_SKIP)
9201 if (noside == EVAL_AVOID_SIDE_EFFECTS)
9205 binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
9206 tem = ada_value_equal (arg1, arg2);
9208 if (op == BINOP_NOTEQUAL)
9210 type = language_bool_type (exp->language_defn, exp->gdbarch);
9211 return value_from_longest (type, (LONGEST) tem);
9214 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
9215 if (noside == EVAL_SKIP)
9217 else if (ada_is_fixed_point_type (value_type (arg1)))
9218 return value_cast (value_type (arg1), value_neg (arg1));
9221 unop_promote (exp->language_defn, exp->gdbarch, &arg1);
9222 return value_neg (arg1);
9225 case BINOP_LOGICAL_AND:
9226 case BINOP_LOGICAL_OR:
9227 case UNOP_LOGICAL_NOT:
9232 val = evaluate_subexp_standard (expect_type, exp, pos, noside);
9233 type = language_bool_type (exp->language_defn, exp->gdbarch);
9234 return value_cast (type, val);
9237 case BINOP_BITWISE_AND:
9238 case BINOP_BITWISE_IOR:
9239 case BINOP_BITWISE_XOR:
9243 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
9245 val = evaluate_subexp_standard (expect_type, exp, pos, noside);
9247 return value_cast (value_type (arg1), val);
9253 if (noside == EVAL_SKIP)
9258 else if (SYMBOL_DOMAIN (exp->elts[pc + 2].symbol) == UNDEF_DOMAIN)
9259 /* Only encountered when an unresolved symbol occurs in a
9260 context other than a function call, in which case, it is
9262 error (_("Unexpected unresolved symbol, %s, during evaluation"),
9263 SYMBOL_PRINT_NAME (exp->elts[pc + 2].symbol));
9264 else if (noside == EVAL_AVOID_SIDE_EFFECTS)
9266 type = static_unwrap_type (SYMBOL_TYPE (exp->elts[pc + 2].symbol));
9267 /* Check to see if this is a tagged type. We also need to handle
9268 the case where the type is a reference to a tagged type, but
9269 we have to be careful to exclude pointers to tagged types.
9270 The latter should be shown as usual (as a pointer), whereas
9271 a reference should mostly be transparent to the user. */
9272 if (ada_is_tagged_type (type, 0)
9273 || (TYPE_CODE(type) == TYPE_CODE_REF
9274 && ada_is_tagged_type (TYPE_TARGET_TYPE (type), 0)))
9276 /* Tagged types are a little special in the fact that the real
9277 type is dynamic and can only be determined by inspecting the
9278 object's tag. This means that we need to get the object's
9279 value first (EVAL_NORMAL) and then extract the actual object
9282 Note that we cannot skip the final step where we extract
9283 the object type from its tag, because the EVAL_NORMAL phase
9284 results in dynamic components being resolved into fixed ones.
9285 This can cause problems when trying to print the type
9286 description of tagged types whose parent has a dynamic size:
9287 We use the type name of the "_parent" component in order
9288 to print the name of the ancestor type in the type description.
9289 If that component had a dynamic size, the resolution into
9290 a fixed type would result in the loss of that type name,
9291 thus preventing us from printing the name of the ancestor
9292 type in the type description. */
9293 struct type *actual_type;
9295 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_NORMAL);
9296 actual_type = type_from_tag (ada_value_tag (arg1));
9297 if (actual_type == NULL)
9298 /* If, for some reason, we were unable to determine
9299 the actual type from the tag, then use the static
9300 approximation that we just computed as a fallback.
9301 This can happen if the debugging information is
9302 incomplete, for instance. */
9305 return value_zero (actual_type, not_lval);
9310 (to_static_fixed_type
9311 (static_unwrap_type (SYMBOL_TYPE (exp->elts[pc + 2].symbol))),
9316 arg1 = evaluate_subexp_standard (expect_type, exp, pos, noside);
9317 arg1 = unwrap_value (arg1);
9318 return ada_to_fixed_value (arg1);
9324 /* Allocate arg vector, including space for the function to be
9325 called in argvec[0] and a terminating NULL. */
9326 nargs = longest_to_int (exp->elts[pc + 1].longconst);
9328 (struct value **) alloca (sizeof (struct value *) * (nargs + 2));
9330 if (exp->elts[*pos].opcode == OP_VAR_VALUE
9331 && SYMBOL_DOMAIN (exp->elts[pc + 5].symbol) == UNDEF_DOMAIN)
9332 error (_("Unexpected unresolved symbol, %s, during evaluation"),
9333 SYMBOL_PRINT_NAME (exp->elts[pc + 5].symbol));
9336 for (tem = 0; tem <= nargs; tem += 1)
9337 argvec[tem] = evaluate_subexp (NULL_TYPE, exp, pos, noside);
9340 if (noside == EVAL_SKIP)
9344 if (ada_is_constrained_packed_array_type
9345 (desc_base_type (value_type (argvec[0]))))
9346 argvec[0] = ada_coerce_to_simple_array (argvec[0]);
9347 else if (TYPE_CODE (value_type (argvec[0])) == TYPE_CODE_ARRAY
9348 && TYPE_FIELD_BITSIZE (value_type (argvec[0]), 0) != 0)
9349 /* This is a packed array that has already been fixed, and
9350 therefore already coerced to a simple array. Nothing further
9353 else if (TYPE_CODE (value_type (argvec[0])) == TYPE_CODE_REF
9354 || (TYPE_CODE (value_type (argvec[0])) == TYPE_CODE_ARRAY
9355 && VALUE_LVAL (argvec[0]) == lval_memory))
9356 argvec[0] = value_addr (argvec[0]);
9358 type = ada_check_typedef (value_type (argvec[0]));
9360 /* Ada allows us to implicitly dereference arrays when subscripting
9361 them. So, if this is an typedef (encoding use for array access
9362 types encoded as fat pointers), strip it now. */
9363 if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
9364 type = ada_typedef_target_type (type);
9366 if (TYPE_CODE (type) == TYPE_CODE_PTR)
9368 switch (TYPE_CODE (ada_check_typedef (TYPE_TARGET_TYPE (type))))
9370 case TYPE_CODE_FUNC:
9371 type = ada_check_typedef (TYPE_TARGET_TYPE (type));
9373 case TYPE_CODE_ARRAY:
9375 case TYPE_CODE_STRUCT:
9376 if (noside != EVAL_AVOID_SIDE_EFFECTS)
9377 argvec[0] = ada_value_ind (argvec[0]);
9378 type = ada_check_typedef (TYPE_TARGET_TYPE (type));
9381 error (_("cannot subscript or call something of type `%s'"),
9382 ada_type_name (value_type (argvec[0])));
9387 switch (TYPE_CODE (type))
9389 case TYPE_CODE_FUNC:
9390 if (noside == EVAL_AVOID_SIDE_EFFECTS)
9391 return allocate_value (TYPE_TARGET_TYPE (type));
9392 return call_function_by_hand (argvec[0], nargs, argvec + 1);
9393 case TYPE_CODE_STRUCT:
9397 arity = ada_array_arity (type);
9398 type = ada_array_element_type (type, nargs);
9400 error (_("cannot subscript or call a record"));
9402 error (_("wrong number of subscripts; expecting %d"), arity);
9403 if (noside == EVAL_AVOID_SIDE_EFFECTS)
9404 return value_zero (ada_aligned_type (type), lval_memory);
9406 unwrap_value (ada_value_subscript
9407 (argvec[0], nargs, argvec + 1));
9409 case TYPE_CODE_ARRAY:
9410 if (noside == EVAL_AVOID_SIDE_EFFECTS)
9412 type = ada_array_element_type (type, nargs);
9414 error (_("element type of array unknown"));
9416 return value_zero (ada_aligned_type (type), lval_memory);
9419 unwrap_value (ada_value_subscript
9420 (ada_coerce_to_simple_array (argvec[0]),
9421 nargs, argvec + 1));
9422 case TYPE_CODE_PTR: /* Pointer to array */
9423 type = to_fixed_array_type (TYPE_TARGET_TYPE (type), NULL, 1);
9424 if (noside == EVAL_AVOID_SIDE_EFFECTS)
9426 type = ada_array_element_type (type, nargs);
9428 error (_("element type of array unknown"));
9430 return value_zero (ada_aligned_type (type), lval_memory);
9433 unwrap_value (ada_value_ptr_subscript (argvec[0], type,
9434 nargs, argvec + 1));
9437 error (_("Attempt to index or call something other than an "
9438 "array or function"));
9443 struct value *array = evaluate_subexp (NULL_TYPE, exp, pos, noside);
9444 struct value *low_bound_val =
9445 evaluate_subexp (NULL_TYPE, exp, pos, noside);
9446 struct value *high_bound_val =
9447 evaluate_subexp (NULL_TYPE, exp, pos, noside);
9451 low_bound_val = coerce_ref (low_bound_val);
9452 high_bound_val = coerce_ref (high_bound_val);
9453 low_bound = pos_atr (low_bound_val);
9454 high_bound = pos_atr (high_bound_val);
9456 if (noside == EVAL_SKIP)
9459 /* If this is a reference to an aligner type, then remove all
9461 if (TYPE_CODE (value_type (array)) == TYPE_CODE_REF
9462 && ada_is_aligner_type (TYPE_TARGET_TYPE (value_type (array))))
9463 TYPE_TARGET_TYPE (value_type (array)) =
9464 ada_aligned_type (TYPE_TARGET_TYPE (value_type (array)));
9466 if (ada_is_constrained_packed_array_type (value_type (array)))
9467 error (_("cannot slice a packed array"));
9469 /* If this is a reference to an array or an array lvalue,
9470 convert to a pointer. */
9471 if (TYPE_CODE (value_type (array)) == TYPE_CODE_REF
9472 || (TYPE_CODE (value_type (array)) == TYPE_CODE_ARRAY
9473 && VALUE_LVAL (array) == lval_memory))
9474 array = value_addr (array);
9476 if (noside == EVAL_AVOID_SIDE_EFFECTS
9477 && ada_is_array_descriptor_type (ada_check_typedef
9478 (value_type (array))))
9479 return empty_array (ada_type_of_array (array, 0), low_bound);
9481 array = ada_coerce_to_simple_array_ptr (array);
9483 /* If we have more than one level of pointer indirection,
9484 dereference the value until we get only one level. */
9485 while (TYPE_CODE (value_type (array)) == TYPE_CODE_PTR
9486 && (TYPE_CODE (TYPE_TARGET_TYPE (value_type (array)))
9488 array = value_ind (array);
9490 /* Make sure we really do have an array type before going further,
9491 to avoid a SEGV when trying to get the index type or the target
9492 type later down the road if the debug info generated by
9493 the compiler is incorrect or incomplete. */
9494 if (!ada_is_simple_array_type (value_type (array)))
9495 error (_("cannot take slice of non-array"));
9497 if (TYPE_CODE (value_type (array)) == TYPE_CODE_PTR)
9499 if (high_bound < low_bound || noside == EVAL_AVOID_SIDE_EFFECTS)
9500 return empty_array (TYPE_TARGET_TYPE (value_type (array)),
9504 struct type *arr_type0 =
9505 to_fixed_array_type (TYPE_TARGET_TYPE (value_type (array)),
9508 return ada_value_slice_from_ptr (array, arr_type0,
9509 longest_to_int (low_bound),
9510 longest_to_int (high_bound));
9513 else if (noside == EVAL_AVOID_SIDE_EFFECTS)
9515 else if (high_bound < low_bound)
9516 return empty_array (value_type (array), low_bound);
9518 return ada_value_slice (array, longest_to_int (low_bound),
9519 longest_to_int (high_bound));
9524 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
9525 type = check_typedef (exp->elts[pc + 1].type);
9527 if (noside == EVAL_SKIP)
9530 switch (TYPE_CODE (type))
9533 lim_warning (_("Membership test incompletely implemented; "
9534 "always returns true"));
9535 type = language_bool_type (exp->language_defn, exp->gdbarch);
9536 return value_from_longest (type, (LONGEST) 1);
9538 case TYPE_CODE_RANGE:
9539 arg2 = value_from_longest (type, TYPE_LOW_BOUND (type));
9540 arg3 = value_from_longest (type, TYPE_HIGH_BOUND (type));
9541 binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
9542 binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg3);
9543 type = language_bool_type (exp->language_defn, exp->gdbarch);
9545 value_from_longest (type,
9546 (value_less (arg1, arg3)
9547 || value_equal (arg1, arg3))
9548 && (value_less (arg2, arg1)
9549 || value_equal (arg2, arg1)));
9552 case BINOP_IN_BOUNDS:
9554 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
9555 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
9557 if (noside == EVAL_SKIP)
9560 if (noside == EVAL_AVOID_SIDE_EFFECTS)
9562 type = language_bool_type (exp->language_defn, exp->gdbarch);
9563 return value_zero (type, not_lval);
9566 tem = longest_to_int (exp->elts[pc + 1].longconst);
9568 type = ada_index_type (value_type (arg2), tem, "range");
9570 type = value_type (arg1);
9572 arg3 = value_from_longest (type, ada_array_bound (arg2, tem, 1));
9573 arg2 = value_from_longest (type, ada_array_bound (arg2, tem, 0));
9575 binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
9576 binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg3);
9577 type = language_bool_type (exp->language_defn, exp->gdbarch);
9579 value_from_longest (type,
9580 (value_less (arg1, arg3)
9581 || value_equal (arg1, arg3))
9582 && (value_less (arg2, arg1)
9583 || value_equal (arg2, arg1)));
9585 case TERNOP_IN_RANGE:
9586 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
9587 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
9588 arg3 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
9590 if (noside == EVAL_SKIP)
9593 binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
9594 binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg3);
9595 type = language_bool_type (exp->language_defn, exp->gdbarch);
9597 value_from_longest (type,
9598 (value_less (arg1, arg3)
9599 || value_equal (arg1, arg3))
9600 && (value_less (arg2, arg1)
9601 || value_equal (arg2, arg1)));
9607 struct type *type_arg;
9609 if (exp->elts[*pos].opcode == OP_TYPE)
9611 evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
9613 type_arg = check_typedef (exp->elts[pc + 2].type);
9617 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
9621 if (exp->elts[*pos].opcode != OP_LONG)
9622 error (_("Invalid operand to '%s"), ada_attribute_name (op));
9623 tem = longest_to_int (exp->elts[*pos + 2].longconst);
9626 if (noside == EVAL_SKIP)
9629 if (type_arg == NULL)
9631 arg1 = ada_coerce_ref (arg1);
9633 if (ada_is_constrained_packed_array_type (value_type (arg1)))
9634 arg1 = ada_coerce_to_simple_array (arg1);
9636 type = ada_index_type (value_type (arg1), tem,
9637 ada_attribute_name (op));
9639 type = builtin_type (exp->gdbarch)->builtin_int;
9641 if (noside == EVAL_AVOID_SIDE_EFFECTS)
9642 return allocate_value (type);
9646 default: /* Should never happen. */
9647 error (_("unexpected attribute encountered"));
9649 return value_from_longest
9650 (type, ada_array_bound (arg1, tem, 0));
9652 return value_from_longest
9653 (type, ada_array_bound (arg1, tem, 1));
9655 return value_from_longest
9656 (type, ada_array_length (arg1, tem));
9659 else if (discrete_type_p (type_arg))
9661 struct type *range_type;
9662 char *name = ada_type_name (type_arg);
9665 if (name != NULL && TYPE_CODE (type_arg) != TYPE_CODE_ENUM)
9666 range_type = to_fixed_range_type (type_arg, NULL);
9667 if (range_type == NULL)
9668 range_type = type_arg;
9672 error (_("unexpected attribute encountered"));
9674 return value_from_longest
9675 (range_type, ada_discrete_type_low_bound (range_type));
9677 return value_from_longest
9678 (range_type, ada_discrete_type_high_bound (range_type));
9680 error (_("the 'length attribute applies only to array types"));
9683 else if (TYPE_CODE (type_arg) == TYPE_CODE_FLT)
9684 error (_("unimplemented type attribute"));
9689 if (ada_is_constrained_packed_array_type (type_arg))
9690 type_arg = decode_constrained_packed_array_type (type_arg);
9692 type = ada_index_type (type_arg, tem, ada_attribute_name (op));
9694 type = builtin_type (exp->gdbarch)->builtin_int;
9696 if (noside == EVAL_AVOID_SIDE_EFFECTS)
9697 return allocate_value (type);
9702 error (_("unexpected attribute encountered"));
9704 low = ada_array_bound_from_type (type_arg, tem, 0);
9705 return value_from_longest (type, low);
9707 high = ada_array_bound_from_type (type_arg, tem, 1);
9708 return value_from_longest (type, high);
9710 low = ada_array_bound_from_type (type_arg, tem, 0);
9711 high = ada_array_bound_from_type (type_arg, tem, 1);
9712 return value_from_longest (type, high - low + 1);
9718 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
9719 if (noside == EVAL_SKIP)
9722 if (noside == EVAL_AVOID_SIDE_EFFECTS)
9723 return value_zero (ada_tag_type (arg1), not_lval);
9725 return ada_value_tag (arg1);
9729 evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
9730 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
9731 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
9732 if (noside == EVAL_SKIP)
9734 else if (noside == EVAL_AVOID_SIDE_EFFECTS)
9735 return value_zero (value_type (arg1), not_lval);
9738 binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
9739 return value_binop (arg1, arg2,
9740 op == OP_ATR_MIN ? BINOP_MIN : BINOP_MAX);
9743 case OP_ATR_MODULUS:
9745 struct type *type_arg = check_typedef (exp->elts[pc + 2].type);
9747 evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
9748 if (noside == EVAL_SKIP)
9751 if (!ada_is_modular_type (type_arg))
9752 error (_("'modulus must be applied to modular type"));
9754 return value_from_longest (TYPE_TARGET_TYPE (type_arg),
9755 ada_modulus (type_arg));
9760 evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
9761 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
9762 if (noside == EVAL_SKIP)
9764 type = builtin_type (exp->gdbarch)->builtin_int;
9765 if (noside == EVAL_AVOID_SIDE_EFFECTS)
9766 return value_zero (type, not_lval);
9768 return value_pos_atr (type, arg1);
9771 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
9772 type = value_type (arg1);
9774 /* If the argument is a reference, then dereference its type, since
9775 the user is really asking for the size of the actual object,
9776 not the size of the pointer. */
9777 if (TYPE_CODE (type) == TYPE_CODE_REF)
9778 type = TYPE_TARGET_TYPE (type);
9780 if (noside == EVAL_SKIP)
9782 else if (noside == EVAL_AVOID_SIDE_EFFECTS)
9783 return value_zero (builtin_type (exp->gdbarch)->builtin_int, not_lval);
9785 return value_from_longest (builtin_type (exp->gdbarch)->builtin_int,
9786 TARGET_CHAR_BIT * TYPE_LENGTH (type));
9789 evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
9790 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
9791 type = exp->elts[pc + 2].type;
9792 if (noside == EVAL_SKIP)
9794 else if (noside == EVAL_AVOID_SIDE_EFFECTS)
9795 return value_zero (type, not_lval);
9797 return value_val_atr (type, arg1);
9800 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
9801 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
9802 if (noside == EVAL_SKIP)
9804 else if (noside == EVAL_AVOID_SIDE_EFFECTS)
9805 return value_zero (value_type (arg1), not_lval);
9808 /* For integer exponentiation operations,
9809 only promote the first argument. */
9810 if (is_integral_type (value_type (arg2)))
9811 unop_promote (exp->language_defn, exp->gdbarch, &arg1);
9813 binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
9815 return value_binop (arg1, arg2, op);
9819 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
9820 if (noside == EVAL_SKIP)
9826 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
9827 if (noside == EVAL_SKIP)
9829 unop_promote (exp->language_defn, exp->gdbarch, &arg1);
9830 if (value_less (arg1, value_zero (value_type (arg1), not_lval)))
9831 return value_neg (arg1);
9836 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
9837 if (noside == EVAL_SKIP)
9839 type = ada_check_typedef (value_type (arg1));
9840 if (noside == EVAL_AVOID_SIDE_EFFECTS)
9842 if (ada_is_array_descriptor_type (type))
9843 /* GDB allows dereferencing GNAT array descriptors. */
9845 struct type *arrType = ada_type_of_array (arg1, 0);
9847 if (arrType == NULL)
9848 error (_("Attempt to dereference null array pointer."));
9849 return value_at_lazy (arrType, 0);
9851 else if (TYPE_CODE (type) == TYPE_CODE_PTR
9852 || TYPE_CODE (type) == TYPE_CODE_REF
9853 /* In C you can dereference an array to get the 1st elt. */
9854 || TYPE_CODE (type) == TYPE_CODE_ARRAY)
9856 type = to_static_fixed_type
9858 (ada_check_typedef (TYPE_TARGET_TYPE (type))));
9860 return value_zero (type, lval_memory);
9862 else if (TYPE_CODE (type) == TYPE_CODE_INT)
9864 /* GDB allows dereferencing an int. */
9865 if (expect_type == NULL)
9866 return value_zero (builtin_type (exp->gdbarch)->builtin_int,
9871 to_static_fixed_type (ada_aligned_type (expect_type));
9872 return value_zero (expect_type, lval_memory);
9876 error (_("Attempt to take contents of a non-pointer value."));
9878 arg1 = ada_coerce_ref (arg1); /* FIXME: What is this for?? */
9879 type = ada_check_typedef (value_type (arg1));
9881 if (TYPE_CODE (type) == TYPE_CODE_INT)
9882 /* GDB allows dereferencing an int. If we were given
9883 the expect_type, then use that as the target type.
9884 Otherwise, assume that the target type is an int. */
9886 if (expect_type != NULL)
9887 return ada_value_ind (value_cast (lookup_pointer_type (expect_type),
9890 return value_at_lazy (builtin_type (exp->gdbarch)->builtin_int,
9891 (CORE_ADDR) value_as_address (arg1));
9894 if (ada_is_array_descriptor_type (type))
9895 /* GDB allows dereferencing GNAT array descriptors. */
9896 return ada_coerce_to_simple_array (arg1);
9898 return ada_value_ind (arg1);
9900 case STRUCTOP_STRUCT:
9901 tem = longest_to_int (exp->elts[pc + 1].longconst);
9902 (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
9903 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
9904 if (noside == EVAL_SKIP)
9906 if (noside == EVAL_AVOID_SIDE_EFFECTS)
9908 struct type *type1 = value_type (arg1);
9910 if (ada_is_tagged_type (type1, 1))
9912 type = ada_lookup_struct_elt_type (type1,
9913 &exp->elts[pc + 2].string,
9916 /* In this case, we assume that the field COULD exist
9917 in some extension of the type. Return an object of
9918 "type" void, which will match any formal
9919 (see ada_type_match). */
9920 return value_zero (builtin_type (exp->gdbarch)->builtin_void,
9925 ada_lookup_struct_elt_type (type1, &exp->elts[pc + 2].string, 1,
9928 return value_zero (ada_aligned_type (type), lval_memory);
9931 arg1 = ada_value_struct_elt (arg1, &exp->elts[pc + 2].string, 0);
9932 arg1 = unwrap_value (arg1);
9933 return ada_to_fixed_value (arg1);
9936 /* The value is not supposed to be used. This is here to make it
9937 easier to accommodate expressions that contain types. */
9939 if (noside == EVAL_SKIP)
9941 else if (noside == EVAL_AVOID_SIDE_EFFECTS)
9942 return allocate_value (exp->elts[pc + 1].type);
9944 error (_("Attempt to use a type name as an expression"));
9949 case OP_DISCRETE_RANGE:
9952 if (noside == EVAL_NORMAL)
9956 error (_("Undefined name, ambiguous name, or renaming used in "
9957 "component association: %s."), &exp->elts[pc+2].string);
9959 error (_("Aggregates only allowed on the right of an assignment"));
9961 internal_error (__FILE__, __LINE__,
9962 _("aggregate apparently mangled"));
9965 ada_forward_operator_length (exp, pc, &oplen, &nargs);
9967 for (tem = 0; tem < nargs; tem += 1)
9968 ada_evaluate_subexp (NULL, exp, pos, noside);
9973 return value_from_longest (builtin_type (exp->gdbarch)->builtin_int, 1);
9979 /* If TYPE encodes an Ada fixed-point type, return the suffix of the
9980 type name that encodes the 'small and 'delta information.
9981 Otherwise, return NULL. */
9984 fixed_type_info (struct type *type)
9986 const char *name = ada_type_name (type);
9987 enum type_code code = (type == NULL) ? TYPE_CODE_UNDEF : TYPE_CODE (type);
9989 if ((code == TYPE_CODE_INT || code == TYPE_CODE_RANGE) && name != NULL)
9991 const char *tail = strstr (name, "___XF_");
9998 else if (code == TYPE_CODE_RANGE && TYPE_TARGET_TYPE (type) != type)
9999 return fixed_type_info (TYPE_TARGET_TYPE (type));
10004 /* Returns non-zero iff TYPE represents an Ada fixed-point type. */
10007 ada_is_fixed_point_type (struct type *type)
10009 return fixed_type_info (type) != NULL;
10012 /* Return non-zero iff TYPE represents a System.Address type. */
10015 ada_is_system_address_type (struct type *type)
10017 return (TYPE_NAME (type)
10018 && strcmp (TYPE_NAME (type), "system__address") == 0);
10021 /* Assuming that TYPE is the representation of an Ada fixed-point
10022 type, return its delta, or -1 if the type is malformed and the
10023 delta cannot be determined. */
10026 ada_delta (struct type *type)
10028 const char *encoding = fixed_type_info (type);
10031 /* Strictly speaking, num and den are encoded as integer. However,
10032 they may not fit into a long, and they will have to be converted
10033 to DOUBLEST anyway. So scan them as DOUBLEST. */
10034 if (sscanf (encoding, "_%" DOUBLEST_SCAN_FORMAT "_%" DOUBLEST_SCAN_FORMAT,
10041 /* Assuming that ada_is_fixed_point_type (TYPE), return the scaling
10042 factor ('SMALL value) associated with the type. */
10045 scaling_factor (struct type *type)
10047 const char *encoding = fixed_type_info (type);
10048 DOUBLEST num0, den0, num1, den1;
10051 /* Strictly speaking, num's and den's 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 n = sscanf (encoding,
10055 "_%" DOUBLEST_SCAN_FORMAT "_%" DOUBLEST_SCAN_FORMAT
10056 "_%" DOUBLEST_SCAN_FORMAT "_%" DOUBLEST_SCAN_FORMAT,
10057 &num0, &den0, &num1, &den1);
10062 return num1 / den1;
10064 return num0 / den0;
10068 /* Assuming that X is the representation of a value of fixed-point
10069 type TYPE, return its floating-point equivalent. */
10072 ada_fixed_to_float (struct type *type, LONGEST x)
10074 return (DOUBLEST) x *scaling_factor (type);
10077 /* The representation of a fixed-point value of type TYPE
10078 corresponding to the value X. */
10081 ada_float_to_fixed (struct type *type, DOUBLEST x)
10083 return (LONGEST) (x / scaling_factor (type) + 0.5);
10090 /* Scan STR beginning at position K for a discriminant name, and
10091 return the value of that discriminant field of DVAL in *PX. If
10092 PNEW_K is not null, put the position of the character beyond the
10093 name scanned in *PNEW_K. Return 1 if successful; return 0 and do
10094 not alter *PX and *PNEW_K if unsuccessful. */
10097 scan_discrim_bound (char *str, int k, struct value *dval, LONGEST * px,
10100 static char *bound_buffer = NULL;
10101 static size_t bound_buffer_len = 0;
10104 struct value *bound_val;
10106 if (dval == NULL || str == NULL || str[k] == '\0')
10109 pend = strstr (str + k, "__");
10113 k += strlen (bound);
10117 GROW_VECT (bound_buffer, bound_buffer_len, pend - (str + k) + 1);
10118 bound = bound_buffer;
10119 strncpy (bound_buffer, str + k, pend - (str + k));
10120 bound[pend - (str + k)] = '\0';
10124 bound_val = ada_search_struct_field (bound, dval, 0, value_type (dval));
10125 if (bound_val == NULL)
10128 *px = value_as_long (bound_val);
10129 if (pnew_k != NULL)
10134 /* Value of variable named NAME in the current environment. If
10135 no such variable found, then if ERR_MSG is null, returns 0, and
10136 otherwise causes an error with message ERR_MSG. */
10138 static struct value *
10139 get_var_value (char *name, char *err_msg)
10141 struct ada_symbol_info *syms;
10144 nsyms = ada_lookup_symbol_list (name, get_selected_block (0), VAR_DOMAIN,
10149 if (err_msg == NULL)
10152 error (("%s"), err_msg);
10155 return value_of_variable (syms[0].sym, syms[0].block);
10158 /* Value of integer variable named NAME in the current environment. If
10159 no such variable found, returns 0, and sets *FLAG to 0. If
10160 successful, sets *FLAG to 1. */
10163 get_int_var_value (char *name, int *flag)
10165 struct value *var_val = get_var_value (name, 0);
10177 return value_as_long (var_val);
10182 /* Return a range type whose base type is that of the range type named
10183 NAME in the current environment, and whose bounds are calculated
10184 from NAME according to the GNAT range encoding conventions.
10185 Extract discriminant values, if needed, from DVAL. ORIG_TYPE is the
10186 corresponding range type from debug information; fall back to using it
10187 if symbol lookup fails. If a new type must be created, allocate it
10188 like ORIG_TYPE was. The bounds information, in general, is encoded
10189 in NAME, the base type given in the named range type. */
10191 static struct type *
10192 to_fixed_range_type (struct type *raw_type, struct value *dval)
10195 struct type *base_type;
10196 char *subtype_info;
10198 gdb_assert (raw_type != NULL);
10199 gdb_assert (TYPE_NAME (raw_type) != NULL);
10201 if (TYPE_CODE (raw_type) == TYPE_CODE_RANGE)
10202 base_type = TYPE_TARGET_TYPE (raw_type);
10204 base_type = raw_type;
10206 name = TYPE_NAME (raw_type);
10207 subtype_info = strstr (name, "___XD");
10208 if (subtype_info == NULL)
10210 LONGEST L = ada_discrete_type_low_bound (raw_type);
10211 LONGEST U = ada_discrete_type_high_bound (raw_type);
10213 if (L < INT_MIN || U > INT_MAX)
10216 return create_range_type (alloc_type_copy (raw_type), raw_type,
10217 ada_discrete_type_low_bound (raw_type),
10218 ada_discrete_type_high_bound (raw_type));
10222 static char *name_buf = NULL;
10223 static size_t name_len = 0;
10224 int prefix_len = subtype_info - name;
10230 GROW_VECT (name_buf, name_len, prefix_len + 5);
10231 strncpy (name_buf, name, prefix_len);
10232 name_buf[prefix_len] = '\0';
10235 bounds_str = strchr (subtype_info, '_');
10238 if (*subtype_info == 'L')
10240 if (!ada_scan_number (bounds_str, n, &L, &n)
10241 && !scan_discrim_bound (bounds_str, n, dval, &L, &n))
10243 if (bounds_str[n] == '_')
10245 else if (bounds_str[n] == '.') /* FIXME? SGI Workshop kludge. */
10253 strcpy (name_buf + prefix_len, "___L");
10254 L = get_int_var_value (name_buf, &ok);
10257 lim_warning (_("Unknown lower bound, using 1."));
10262 if (*subtype_info == 'U')
10264 if (!ada_scan_number (bounds_str, n, &U, &n)
10265 && !scan_discrim_bound (bounds_str, n, dval, &U, &n))
10272 strcpy (name_buf + prefix_len, "___U");
10273 U = get_int_var_value (name_buf, &ok);
10276 lim_warning (_("Unknown upper bound, using %ld."), (long) L);
10281 type = create_range_type (alloc_type_copy (raw_type), base_type, L, U);
10282 TYPE_NAME (type) = name;
10287 /* True iff NAME is the name of a range type. */
10290 ada_is_range_type_name (const char *name)
10292 return (name != NULL && strstr (name, "___XD"));
10296 /* Modular types */
10298 /* True iff TYPE is an Ada modular type. */
10301 ada_is_modular_type (struct type *type)
10303 struct type *subranged_type = base_type (type);
10305 return (subranged_type != NULL && TYPE_CODE (type) == TYPE_CODE_RANGE
10306 && TYPE_CODE (subranged_type) == TYPE_CODE_INT
10307 && TYPE_UNSIGNED (subranged_type));
10310 /* Try to determine the lower and upper bounds of the given modular type
10311 using the type name only. Return non-zero and set L and U as the lower
10312 and upper bounds (respectively) if successful. */
10315 ada_modulus_from_name (struct type *type, ULONGEST *modulus)
10317 char *name = ada_type_name (type);
10325 /* Discrete type bounds are encoded using an __XD suffix. In our case,
10326 we are looking for static bounds, which means an __XDLU suffix.
10327 Moreover, we know that the lower bound of modular types is always
10328 zero, so the actual suffix should start with "__XDLU_0__", and
10329 then be followed by the upper bound value. */
10330 suffix = strstr (name, "__XDLU_0__");
10331 if (suffix == NULL)
10334 if (!ada_scan_number (suffix, k, &U, NULL))
10337 *modulus = (ULONGEST) U + 1;
10341 /* Assuming ada_is_modular_type (TYPE), the modulus of TYPE. */
10344 ada_modulus (struct type *type)
10346 return (ULONGEST) TYPE_HIGH_BOUND (type) + 1;
10350 /* Ada exception catchpoint support:
10351 ---------------------------------
10353 We support 3 kinds of exception catchpoints:
10354 . catchpoints on Ada exceptions
10355 . catchpoints on unhandled Ada exceptions
10356 . catchpoints on failed assertions
10358 Exceptions raised during failed assertions, or unhandled exceptions
10359 could perfectly be caught with the general catchpoint on Ada exceptions.
10360 However, we can easily differentiate these two special cases, and having
10361 the option to distinguish these two cases from the rest can be useful
10362 to zero-in on certain situations.
10364 Exception catchpoints are a specialized form of breakpoint,
10365 since they rely on inserting breakpoints inside known routines
10366 of the GNAT runtime. The implementation therefore uses a standard
10367 breakpoint structure of the BP_BREAKPOINT type, but with its own set
10370 Support in the runtime for exception catchpoints have been changed
10371 a few times already, and these changes affect the implementation
10372 of these catchpoints. In order to be able to support several
10373 variants of the runtime, we use a sniffer that will determine
10374 the runtime variant used by the program being debugged.
10376 At this time, we do not support the use of conditions on Ada exception
10377 catchpoints. The COND and COND_STRING fields are therefore set
10378 to NULL (most of the time, see below).
10380 Conditions where EXP_STRING, COND, and COND_STRING are used:
10382 When a user specifies the name of a specific exception in the case
10383 of catchpoints on Ada exceptions, we store the name of that exception
10384 in the EXP_STRING. We then translate this request into an actual
10385 condition stored in COND_STRING, and then parse it into an expression
10388 /* The different types of catchpoints that we introduced for catching
10391 enum exception_catchpoint_kind
10393 ex_catch_exception,
10394 ex_catch_exception_unhandled,
10398 /* Ada's standard exceptions. */
10400 static char *standard_exc[] = {
10401 "constraint_error",
10407 typedef CORE_ADDR (ada_unhandled_exception_name_addr_ftype) (void);
10409 /* A structure that describes how to support exception catchpoints
10410 for a given executable. */
10412 struct exception_support_info
10414 /* The name of the symbol to break on in order to insert
10415 a catchpoint on exceptions. */
10416 const char *catch_exception_sym;
10418 /* The name of the symbol to break on in order to insert
10419 a catchpoint on unhandled exceptions. */
10420 const char *catch_exception_unhandled_sym;
10422 /* The name of the symbol to break on in order to insert
10423 a catchpoint on failed assertions. */
10424 const char *catch_assert_sym;
10426 /* Assuming that the inferior just triggered an unhandled exception
10427 catchpoint, this function is responsible for returning the address
10428 in inferior memory where the name of that exception is stored.
10429 Return zero if the address could not be computed. */
10430 ada_unhandled_exception_name_addr_ftype *unhandled_exception_name_addr;
10433 static CORE_ADDR ada_unhandled_exception_name_addr (void);
10434 static CORE_ADDR ada_unhandled_exception_name_addr_from_raise (void);
10436 /* The following exception support info structure describes how to
10437 implement exception catchpoints with the latest version of the
10438 Ada runtime (as of 2007-03-06). */
10440 static const struct exception_support_info default_exception_support_info =
10442 "__gnat_debug_raise_exception", /* catch_exception_sym */
10443 "__gnat_unhandled_exception", /* catch_exception_unhandled_sym */
10444 "__gnat_debug_raise_assert_failure", /* catch_assert_sym */
10445 ada_unhandled_exception_name_addr
10448 /* The following exception support info structure describes how to
10449 implement exception catchpoints with a slightly older version
10450 of the Ada runtime. */
10452 static const struct exception_support_info exception_support_info_fallback =
10454 "__gnat_raise_nodefer_with_msg", /* catch_exception_sym */
10455 "__gnat_unhandled_exception", /* catch_exception_unhandled_sym */
10456 "system__assertions__raise_assert_failure", /* catch_assert_sym */
10457 ada_unhandled_exception_name_addr_from_raise
10460 /* For each executable, we sniff which exception info structure to use
10461 and cache it in the following global variable. */
10463 static const struct exception_support_info *exception_info = NULL;
10465 /* Inspect the Ada runtime and determine which exception info structure
10466 should be used to provide support for exception catchpoints.
10468 This function will always set exception_info, or raise an error. */
10471 ada_exception_support_info_sniffer (void)
10473 struct symbol *sym;
10475 /* If the exception info is already known, then no need to recompute it. */
10476 if (exception_info != NULL)
10479 /* Check the latest (default) exception support info. */
10480 sym = standard_lookup (default_exception_support_info.catch_exception_sym,
10484 exception_info = &default_exception_support_info;
10488 /* Try our fallback exception suport info. */
10489 sym = standard_lookup (exception_support_info_fallback.catch_exception_sym,
10493 exception_info = &exception_support_info_fallback;
10497 /* Sometimes, it is normal for us to not be able to find the routine
10498 we are looking for. This happens when the program is linked with
10499 the shared version of the GNAT runtime, and the program has not been
10500 started yet. Inform the user of these two possible causes if
10503 if (ada_update_initial_language (language_unknown) != language_ada)
10504 error (_("Unable to insert catchpoint. Is this an Ada main program?"));
10506 /* If the symbol does not exist, then check that the program is
10507 already started, to make sure that shared libraries have been
10508 loaded. If it is not started, this may mean that the symbol is
10509 in a shared library. */
10511 if (ptid_get_pid (inferior_ptid) == 0)
10512 error (_("Unable to insert catchpoint. Try to start the program first."));
10514 /* At this point, we know that we are debugging an Ada program and
10515 that the inferior has been started, but we still are not able to
10516 find the run-time symbols. That can mean that we are in
10517 configurable run time mode, or that a-except as been optimized
10518 out by the linker... In any case, at this point it is not worth
10519 supporting this feature. */
10521 error (_("Cannot insert catchpoints in this configuration."));
10524 /* An observer of "executable_changed" events.
10525 Its role is to clear certain cached values that need to be recomputed
10526 each time a new executable is loaded by GDB. */
10529 ada_executable_changed_observer (void)
10531 /* If the executable changed, then it is possible that the Ada runtime
10532 is different. So we need to invalidate the exception support info
10534 exception_info = NULL;
10537 /* True iff FRAME is very likely to be that of a function that is
10538 part of the runtime system. This is all very heuristic, but is
10539 intended to be used as advice as to what frames are uninteresting
10543 is_known_support_routine (struct frame_info *frame)
10545 struct symtab_and_line sal;
10547 enum language func_lang;
10550 /* If this code does not have any debugging information (no symtab),
10551 This cannot be any user code. */
10553 find_frame_sal (frame, &sal);
10554 if (sal.symtab == NULL)
10557 /* If there is a symtab, but the associated source file cannot be
10558 located, then assume this is not user code: Selecting a frame
10559 for which we cannot display the code would not be very helpful
10560 for the user. This should also take care of case such as VxWorks
10561 where the kernel has some debugging info provided for a few units. */
10563 if (symtab_to_fullname (sal.symtab) == NULL)
10566 /* Check the unit filename againt the Ada runtime file naming.
10567 We also check the name of the objfile against the name of some
10568 known system libraries that sometimes come with debugging info
10571 for (i = 0; known_runtime_file_name_patterns[i] != NULL; i += 1)
10573 re_comp (known_runtime_file_name_patterns[i]);
10574 if (re_exec (sal.symtab->filename))
10576 if (sal.symtab->objfile != NULL
10577 && re_exec (sal.symtab->objfile->name))
10581 /* Check whether the function is a GNAT-generated entity. */
10583 find_frame_funname (frame, &func_name, &func_lang, NULL);
10584 if (func_name == NULL)
10587 for (i = 0; known_auxiliary_function_name_patterns[i] != NULL; i += 1)
10589 re_comp (known_auxiliary_function_name_patterns[i]);
10590 if (re_exec (func_name))
10597 /* Find the first frame that contains debugging information and that is not
10598 part of the Ada run-time, starting from FI and moving upward. */
10601 ada_find_printable_frame (struct frame_info *fi)
10603 for (; fi != NULL; fi = get_prev_frame (fi))
10605 if (!is_known_support_routine (fi))
10614 /* Assuming that the inferior just triggered an unhandled exception
10615 catchpoint, return the address in inferior memory where the name
10616 of the exception is stored.
10618 Return zero if the address could not be computed. */
10621 ada_unhandled_exception_name_addr (void)
10623 return parse_and_eval_address ("e.full_name");
10626 /* Same as ada_unhandled_exception_name_addr, except that this function
10627 should be used when the inferior uses an older version of the runtime,
10628 where the exception name needs to be extracted from a specific frame
10629 several frames up in the callstack. */
10632 ada_unhandled_exception_name_addr_from_raise (void)
10635 struct frame_info *fi;
10637 /* To determine the name of this exception, we need to select
10638 the frame corresponding to RAISE_SYM_NAME. This frame is
10639 at least 3 levels up, so we simply skip the first 3 frames
10640 without checking the name of their associated function. */
10641 fi = get_current_frame ();
10642 for (frame_level = 0; frame_level < 3; frame_level += 1)
10644 fi = get_prev_frame (fi);
10649 enum language func_lang;
10651 find_frame_funname (fi, &func_name, &func_lang, NULL);
10652 if (func_name != NULL
10653 && strcmp (func_name, exception_info->catch_exception_sym) == 0)
10654 break; /* We found the frame we were looking for... */
10655 fi = get_prev_frame (fi);
10662 return parse_and_eval_address ("id.full_name");
10665 /* Assuming the inferior just triggered an Ada exception catchpoint
10666 (of any type), return the address in inferior memory where the name
10667 of the exception is stored, if applicable.
10669 Return zero if the address could not be computed, or if not relevant. */
10672 ada_exception_name_addr_1 (enum exception_catchpoint_kind ex,
10673 struct breakpoint *b)
10677 case ex_catch_exception:
10678 return (parse_and_eval_address ("e.full_name"));
10681 case ex_catch_exception_unhandled:
10682 return exception_info->unhandled_exception_name_addr ();
10685 case ex_catch_assert:
10686 return 0; /* Exception name is not relevant in this case. */
10690 internal_error (__FILE__, __LINE__, _("unexpected catchpoint type"));
10694 return 0; /* Should never be reached. */
10697 /* Same as ada_exception_name_addr_1, except that it intercepts and contains
10698 any error that ada_exception_name_addr_1 might cause to be thrown.
10699 When an error is intercepted, a warning with the error message is printed,
10700 and zero is returned. */
10703 ada_exception_name_addr (enum exception_catchpoint_kind ex,
10704 struct breakpoint *b)
10706 struct gdb_exception e;
10707 CORE_ADDR result = 0;
10709 TRY_CATCH (e, RETURN_MASK_ERROR)
10711 result = ada_exception_name_addr_1 (ex, b);
10716 warning (_("failed to get exception name: %s"), e.message);
10723 /* Implement the PRINT_IT method in the breakpoint_ops structure
10724 for all exception catchpoint kinds. */
10726 static enum print_stop_action
10727 print_it_exception (enum exception_catchpoint_kind ex, struct breakpoint *b)
10729 const CORE_ADDR addr = ada_exception_name_addr (ex, b);
10730 char exception_name[256];
10734 read_memory (addr, exception_name, sizeof (exception_name) - 1);
10735 exception_name [sizeof (exception_name) - 1] = '\0';
10738 ada_find_printable_frame (get_current_frame ());
10740 annotate_catchpoint (b->number);
10743 case ex_catch_exception:
10745 printf_filtered (_("\nCatchpoint %d, %s at "),
10746 b->number, exception_name);
10748 printf_filtered (_("\nCatchpoint %d, exception at "), b->number);
10750 case ex_catch_exception_unhandled:
10752 printf_filtered (_("\nCatchpoint %d, unhandled %s at "),
10753 b->number, exception_name);
10755 printf_filtered (_("\nCatchpoint %d, unhandled exception at "),
10758 case ex_catch_assert:
10759 printf_filtered (_("\nCatchpoint %d, failed assertion at "),
10764 return PRINT_SRC_AND_LOC;
10767 /* Implement the PRINT_ONE method in the breakpoint_ops structure
10768 for all exception catchpoint kinds. */
10771 print_one_exception (enum exception_catchpoint_kind ex,
10772 struct breakpoint *b, struct bp_location **last_loc)
10774 struct value_print_options opts;
10776 get_user_print_options (&opts);
10777 if (opts.addressprint)
10779 annotate_field (4);
10780 ui_out_field_core_addr (uiout, "addr", b->loc->gdbarch, b->loc->address);
10783 annotate_field (5);
10784 *last_loc = b->loc;
10787 case ex_catch_exception:
10788 if (b->exp_string != NULL)
10790 char *msg = xstrprintf (_("`%s' Ada exception"), b->exp_string);
10792 ui_out_field_string (uiout, "what", msg);
10796 ui_out_field_string (uiout, "what", "all Ada exceptions");
10800 case ex_catch_exception_unhandled:
10801 ui_out_field_string (uiout, "what", "unhandled Ada exceptions");
10804 case ex_catch_assert:
10805 ui_out_field_string (uiout, "what", "failed Ada assertions");
10809 internal_error (__FILE__, __LINE__, _("unexpected catchpoint type"));
10814 /* Implement the PRINT_MENTION method in the breakpoint_ops structure
10815 for all exception catchpoint kinds. */
10818 print_mention_exception (enum exception_catchpoint_kind ex,
10819 struct breakpoint *b)
10823 case ex_catch_exception:
10824 if (b->exp_string != NULL)
10825 printf_filtered (_("Catchpoint %d: `%s' Ada exception"),
10826 b->number, b->exp_string);
10828 printf_filtered (_("Catchpoint %d: all Ada exceptions"), b->number);
10832 case ex_catch_exception_unhandled:
10833 printf_filtered (_("Catchpoint %d: unhandled Ada exceptions"),
10837 case ex_catch_assert:
10838 printf_filtered (_("Catchpoint %d: failed Ada assertions"), b->number);
10842 internal_error (__FILE__, __LINE__, _("unexpected catchpoint type"));
10847 /* Implement the PRINT_RECREATE method in the breakpoint_ops structure
10848 for all exception catchpoint kinds. */
10851 print_recreate_exception (enum exception_catchpoint_kind ex,
10852 struct breakpoint *b, struct ui_file *fp)
10856 case ex_catch_exception:
10857 fprintf_filtered (fp, "catch exception");
10858 if (b->exp_string != NULL)
10859 fprintf_filtered (fp, " %s", b->exp_string);
10862 case ex_catch_exception_unhandled:
10863 fprintf_filtered (fp, "catch exception unhandled");
10866 case ex_catch_assert:
10867 fprintf_filtered (fp, "catch assert");
10871 internal_error (__FILE__, __LINE__, _("unexpected catchpoint type"));
10875 /* Virtual table for "catch exception" breakpoints. */
10877 static enum print_stop_action
10878 print_it_catch_exception (struct breakpoint *b)
10880 return print_it_exception (ex_catch_exception, b);
10884 print_one_catch_exception (struct breakpoint *b, struct bp_location **last_loc)
10886 print_one_exception (ex_catch_exception, b, last_loc);
10890 print_mention_catch_exception (struct breakpoint *b)
10892 print_mention_exception (ex_catch_exception, b);
10896 print_recreate_catch_exception (struct breakpoint *b, struct ui_file *fp)
10898 print_recreate_exception (ex_catch_exception, b, fp);
10901 static struct breakpoint_ops catch_exception_breakpoint_ops =
10905 NULL, /* breakpoint_hit */
10906 NULL, /* resources_needed */
10907 print_it_catch_exception,
10908 print_one_catch_exception,
10909 print_mention_catch_exception,
10910 print_recreate_catch_exception
10913 /* Virtual table for "catch exception unhandled" breakpoints. */
10915 static enum print_stop_action
10916 print_it_catch_exception_unhandled (struct breakpoint *b)
10918 return print_it_exception (ex_catch_exception_unhandled, b);
10922 print_one_catch_exception_unhandled (struct breakpoint *b,
10923 struct bp_location **last_loc)
10925 print_one_exception (ex_catch_exception_unhandled, b, last_loc);
10929 print_mention_catch_exception_unhandled (struct breakpoint *b)
10931 print_mention_exception (ex_catch_exception_unhandled, b);
10935 print_recreate_catch_exception_unhandled (struct breakpoint *b,
10936 struct ui_file *fp)
10938 print_recreate_exception (ex_catch_exception_unhandled, b, fp);
10941 static struct breakpoint_ops catch_exception_unhandled_breakpoint_ops = {
10944 NULL, /* breakpoint_hit */
10945 NULL, /* resources_needed */
10946 print_it_catch_exception_unhandled,
10947 print_one_catch_exception_unhandled,
10948 print_mention_catch_exception_unhandled,
10949 print_recreate_catch_exception_unhandled
10952 /* Virtual table for "catch assert" breakpoints. */
10954 static enum print_stop_action
10955 print_it_catch_assert (struct breakpoint *b)
10957 return print_it_exception (ex_catch_assert, b);
10961 print_one_catch_assert (struct breakpoint *b, struct bp_location **last_loc)
10963 print_one_exception (ex_catch_assert, b, last_loc);
10967 print_mention_catch_assert (struct breakpoint *b)
10969 print_mention_exception (ex_catch_assert, b);
10973 print_recreate_catch_assert (struct breakpoint *b, struct ui_file *fp)
10975 print_recreate_exception (ex_catch_assert, b, fp);
10978 static struct breakpoint_ops catch_assert_breakpoint_ops = {
10981 NULL, /* breakpoint_hit */
10982 NULL, /* resources_needed */
10983 print_it_catch_assert,
10984 print_one_catch_assert,
10985 print_mention_catch_assert,
10986 print_recreate_catch_assert
10989 /* Return non-zero if B is an Ada exception catchpoint. */
10992 ada_exception_catchpoint_p (struct breakpoint *b)
10994 return (b->ops == &catch_exception_breakpoint_ops
10995 || b->ops == &catch_exception_unhandled_breakpoint_ops
10996 || b->ops == &catch_assert_breakpoint_ops);
10999 /* Return a newly allocated copy of the first space-separated token
11000 in ARGSP, and then adjust ARGSP to point immediately after that
11003 Return NULL if ARGPS does not contain any more tokens. */
11006 ada_get_next_arg (char **argsp)
11008 char *args = *argsp;
11012 /* Skip any leading white space. */
11014 while (isspace (*args))
11017 if (args[0] == '\0')
11018 return NULL; /* No more arguments. */
11020 /* Find the end of the current argument. */
11023 while (*end != '\0' && !isspace (*end))
11026 /* Adjust ARGSP to point to the start of the next argument. */
11030 /* Make a copy of the current argument and return it. */
11032 result = xmalloc (end - args + 1);
11033 strncpy (result, args, end - args);
11034 result[end - args] = '\0';
11039 /* Split the arguments specified in a "catch exception" command.
11040 Set EX to the appropriate catchpoint type.
11041 Set EXP_STRING to the name of the specific exception if
11042 specified by the user. */
11045 catch_ada_exception_command_split (char *args,
11046 enum exception_catchpoint_kind *ex,
11049 struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
11050 char *exception_name;
11052 exception_name = ada_get_next_arg (&args);
11053 make_cleanup (xfree, exception_name);
11055 /* Check that we do not have any more arguments. Anything else
11058 while (isspace (*args))
11061 if (args[0] != '\0')
11062 error (_("Junk at end of expression"));
11064 discard_cleanups (old_chain);
11066 if (exception_name == NULL)
11068 /* Catch all exceptions. */
11069 *ex = ex_catch_exception;
11070 *exp_string = NULL;
11072 else if (strcmp (exception_name, "unhandled") == 0)
11074 /* Catch unhandled exceptions. */
11075 *ex = ex_catch_exception_unhandled;
11076 *exp_string = NULL;
11080 /* Catch a specific exception. */
11081 *ex = ex_catch_exception;
11082 *exp_string = exception_name;
11086 /* Return the name of the symbol on which we should break in order to
11087 implement a catchpoint of the EX kind. */
11089 static const char *
11090 ada_exception_sym_name (enum exception_catchpoint_kind ex)
11092 gdb_assert (exception_info != NULL);
11096 case ex_catch_exception:
11097 return (exception_info->catch_exception_sym);
11099 case ex_catch_exception_unhandled:
11100 return (exception_info->catch_exception_unhandled_sym);
11102 case ex_catch_assert:
11103 return (exception_info->catch_assert_sym);
11106 internal_error (__FILE__, __LINE__,
11107 _("unexpected catchpoint kind (%d)"), ex);
11111 /* Return the breakpoint ops "virtual table" used for catchpoints
11114 static struct breakpoint_ops *
11115 ada_exception_breakpoint_ops (enum exception_catchpoint_kind ex)
11119 case ex_catch_exception:
11120 return (&catch_exception_breakpoint_ops);
11122 case ex_catch_exception_unhandled:
11123 return (&catch_exception_unhandled_breakpoint_ops);
11125 case ex_catch_assert:
11126 return (&catch_assert_breakpoint_ops);
11129 internal_error (__FILE__, __LINE__,
11130 _("unexpected catchpoint kind (%d)"), ex);
11134 /* Return the condition that will be used to match the current exception
11135 being raised with the exception that the user wants to catch. This
11136 assumes that this condition is used when the inferior just triggered
11137 an exception catchpoint.
11139 The string returned is a newly allocated string that needs to be
11140 deallocated later. */
11143 ada_exception_catchpoint_cond_string (const char *exp_string)
11147 /* The standard exceptions are a special case. They are defined in
11148 runtime units that have been compiled without debugging info; if
11149 EXP_STRING is the not-fully-qualified name of a standard
11150 exception (e.g. "constraint_error") then, during the evaluation
11151 of the condition expression, the symbol lookup on this name would
11152 *not* return this standard exception. The catchpoint condition
11153 may then be set only on user-defined exceptions which have the
11154 same not-fully-qualified name (e.g. my_package.constraint_error).
11156 To avoid this unexcepted behavior, these standard exceptions are
11157 systematically prefixed by "standard". This means that "catch
11158 exception constraint_error" is rewritten into "catch exception
11159 standard.constraint_error".
11161 If an exception named contraint_error is defined in another package of
11162 the inferior program, then the only way to specify this exception as a
11163 breakpoint condition is to use its fully-qualified named:
11164 e.g. my_package.constraint_error. */
11166 for (i = 0; i < sizeof (standard_exc) / sizeof (char *); i++)
11168 if (strcmp (standard_exc [i], exp_string) == 0)
11170 return xstrprintf ("long_integer (e) = long_integer (&standard.%s)",
11174 return xstrprintf ("long_integer (e) = long_integer (&%s)", exp_string);
11177 /* Return the expression corresponding to COND_STRING evaluated at SAL. */
11179 static struct expression *
11180 ada_parse_catchpoint_condition (char *cond_string,
11181 struct symtab_and_line sal)
11183 return (parse_exp_1 (&cond_string, block_for_pc (sal.pc), 0));
11186 /* Return the symtab_and_line that should be used to insert an exception
11187 catchpoint of the TYPE kind.
11189 EX_STRING should contain the name of a specific exception
11190 that the catchpoint should catch, or NULL otherwise.
11192 The idea behind all the remaining parameters is that their names match
11193 the name of certain fields in the breakpoint structure that are used to
11194 handle exception catchpoints. This function returns the value to which
11195 these fields should be set, depending on the type of catchpoint we need
11198 If COND and COND_STRING are both non-NULL, any value they might
11199 hold will be free'ed, and then replaced by newly allocated ones.
11200 These parameters are left untouched otherwise. */
11202 static struct symtab_and_line
11203 ada_exception_sal (enum exception_catchpoint_kind ex, char *exp_string,
11204 char **addr_string, char **cond_string,
11205 struct expression **cond, struct breakpoint_ops **ops)
11207 const char *sym_name;
11208 struct symbol *sym;
11209 struct symtab_and_line sal;
11211 /* First, find out which exception support info to use. */
11212 ada_exception_support_info_sniffer ();
11214 /* Then lookup the function on which we will break in order to catch
11215 the Ada exceptions requested by the user. */
11217 sym_name = ada_exception_sym_name (ex);
11218 sym = standard_lookup (sym_name, NULL, VAR_DOMAIN);
11220 /* The symbol we're looking up is provided by a unit in the GNAT runtime
11221 that should be compiled with debugging information. As a result, we
11222 expect to find that symbol in the symtabs. If we don't find it, then
11223 the target most likely does not support Ada exceptions, or we cannot
11224 insert exception breakpoints yet, because the GNAT runtime hasn't been
11227 /* brobecker/2006-12-26: It is conceivable that the runtime was compiled
11228 in such a way that no debugging information is produced for the symbol
11229 we are looking for. In this case, we could search the minimal symbols
11230 as a fall-back mechanism. This would still be operating in degraded
11231 mode, however, as we would still be missing the debugging information
11232 that is needed in order to extract the name of the exception being
11233 raised (this name is printed in the catchpoint message, and is also
11234 used when trying to catch a specific exception). We do not handle
11235 this case for now. */
11238 error (_("Unable to break on '%s' in this configuration."), sym_name);
11240 /* Make sure that the symbol we found corresponds to a function. */
11241 if (SYMBOL_CLASS (sym) != LOC_BLOCK)
11242 error (_("Symbol \"%s\" is not a function (class = %d)"),
11243 sym_name, SYMBOL_CLASS (sym));
11245 sal = find_function_start_sal (sym, 1);
11247 /* Set ADDR_STRING. */
11249 *addr_string = xstrdup (sym_name);
11251 /* Set the COND and COND_STRING (if not NULL). */
11253 if (cond_string != NULL && cond != NULL)
11255 if (*cond_string != NULL)
11257 xfree (*cond_string);
11258 *cond_string = NULL;
11265 if (exp_string != NULL)
11267 *cond_string = ada_exception_catchpoint_cond_string (exp_string);
11268 *cond = ada_parse_catchpoint_condition (*cond_string, sal);
11273 *ops = ada_exception_breakpoint_ops (ex);
11278 /* Parse the arguments (ARGS) of the "catch exception" command.
11280 Set TYPE to the appropriate exception catchpoint type.
11281 If the user asked the catchpoint to catch only a specific
11282 exception, then save the exception name in ADDR_STRING.
11284 See ada_exception_sal for a description of all the remaining
11285 function arguments of this function. */
11287 struct symtab_and_line
11288 ada_decode_exception_location (char *args, char **addr_string,
11289 char **exp_string, char **cond_string,
11290 struct expression **cond,
11291 struct breakpoint_ops **ops)
11293 enum exception_catchpoint_kind ex;
11295 catch_ada_exception_command_split (args, &ex, exp_string);
11296 return ada_exception_sal (ex, *exp_string, addr_string, cond_string,
11300 struct symtab_and_line
11301 ada_decode_assert_location (char *args, char **addr_string,
11302 struct breakpoint_ops **ops)
11304 /* Check that no argument where provided at the end of the command. */
11308 while (isspace (*args))
11311 error (_("Junk at end of arguments."));
11314 return ada_exception_sal (ex_catch_assert, NULL, addr_string, NULL, NULL,
11319 /* Information about operators given special treatment in functions
11321 /* Format: OP_DEFN (<operator>, <operator length>, <# args>, <binop>). */
11323 #define ADA_OPERATORS \
11324 OP_DEFN (OP_VAR_VALUE, 4, 0, 0) \
11325 OP_DEFN (BINOP_IN_BOUNDS, 3, 2, 0) \
11326 OP_DEFN (TERNOP_IN_RANGE, 1, 3, 0) \
11327 OP_DEFN (OP_ATR_FIRST, 1, 2, 0) \
11328 OP_DEFN (OP_ATR_LAST, 1, 2, 0) \
11329 OP_DEFN (OP_ATR_LENGTH, 1, 2, 0) \
11330 OP_DEFN (OP_ATR_IMAGE, 1, 2, 0) \
11331 OP_DEFN (OP_ATR_MAX, 1, 3, 0) \
11332 OP_DEFN (OP_ATR_MIN, 1, 3, 0) \
11333 OP_DEFN (OP_ATR_MODULUS, 1, 1, 0) \
11334 OP_DEFN (OP_ATR_POS, 1, 2, 0) \
11335 OP_DEFN (OP_ATR_SIZE, 1, 1, 0) \
11336 OP_DEFN (OP_ATR_TAG, 1, 1, 0) \
11337 OP_DEFN (OP_ATR_VAL, 1, 2, 0) \
11338 OP_DEFN (UNOP_QUAL, 3, 1, 0) \
11339 OP_DEFN (UNOP_IN_RANGE, 3, 1, 0) \
11340 OP_DEFN (OP_OTHERS, 1, 1, 0) \
11341 OP_DEFN (OP_POSITIONAL, 3, 1, 0) \
11342 OP_DEFN (OP_DISCRETE_RANGE, 1, 2, 0)
11345 ada_operator_length (const struct expression *exp, int pc, int *oplenp,
11348 switch (exp->elts[pc - 1].opcode)
11351 operator_length_standard (exp, pc, oplenp, argsp);
11354 #define OP_DEFN(op, len, args, binop) \
11355 case op: *oplenp = len; *argsp = args; break;
11361 *argsp = longest_to_int (exp->elts[pc - 2].longconst);
11366 *argsp = longest_to_int (exp->elts[pc - 2].longconst) + 1;
11371 /* Implementation of the exp_descriptor method operator_check. */
11374 ada_operator_check (struct expression *exp, int pos,
11375 int (*objfile_func) (struct objfile *objfile, void *data),
11378 const union exp_element *const elts = exp->elts;
11379 struct type *type = NULL;
11381 switch (elts[pos].opcode)
11383 case UNOP_IN_RANGE:
11385 type = elts[pos + 1].type;
11389 return operator_check_standard (exp, pos, objfile_func, data);
11392 /* Invoke callbacks for TYPE and OBJFILE if they were set as non-NULL. */
11394 if (type && TYPE_OBJFILE (type)
11395 && (*objfile_func) (TYPE_OBJFILE (type), data))
11402 ada_op_name (enum exp_opcode opcode)
11407 return op_name_standard (opcode);
11409 #define OP_DEFN(op, len, args, binop) case op: return #op;
11414 return "OP_AGGREGATE";
11416 return "OP_CHOICES";
11422 /* As for operator_length, but assumes PC is pointing at the first
11423 element of the operator, and gives meaningful results only for the
11424 Ada-specific operators, returning 0 for *OPLENP and *ARGSP otherwise. */
11427 ada_forward_operator_length (struct expression *exp, int pc,
11428 int *oplenp, int *argsp)
11430 switch (exp->elts[pc].opcode)
11433 *oplenp = *argsp = 0;
11436 #define OP_DEFN(op, len, args, binop) \
11437 case op: *oplenp = len; *argsp = args; break;
11443 *argsp = longest_to_int (exp->elts[pc + 1].longconst);
11448 *argsp = longest_to_int (exp->elts[pc + 1].longconst) + 1;
11454 int len = longest_to_int (exp->elts[pc + 1].longconst);
11456 *oplenp = 4 + BYTES_TO_EXP_ELEM (len + 1);
11464 ada_dump_subexp_body (struct expression *exp, struct ui_file *stream, int elt)
11466 enum exp_opcode op = exp->elts[elt].opcode;
11471 ada_forward_operator_length (exp, elt, &oplen, &nargs);
11475 /* Ada attributes ('Foo). */
11478 case OP_ATR_LENGTH:
11482 case OP_ATR_MODULUS:
11489 case UNOP_IN_RANGE:
11491 /* XXX: gdb_sprint_host_address, type_sprint */
11492 fprintf_filtered (stream, _("Type @"));
11493 gdb_print_host_address (exp->elts[pc + 1].type, stream);
11494 fprintf_filtered (stream, " (");
11495 type_print (exp->elts[pc + 1].type, NULL, stream, 0);
11496 fprintf_filtered (stream, ")");
11498 case BINOP_IN_BOUNDS:
11499 fprintf_filtered (stream, " (%d)",
11500 longest_to_int (exp->elts[pc + 2].longconst));
11502 case TERNOP_IN_RANGE:
11507 case OP_DISCRETE_RANGE:
11508 case OP_POSITIONAL:
11515 char *name = &exp->elts[elt + 2].string;
11516 int len = longest_to_int (exp->elts[elt + 1].longconst);
11518 fprintf_filtered (stream, "Text: `%.*s'", len, name);
11523 return dump_subexp_body_standard (exp, stream, elt);
11527 for (i = 0; i < nargs; i += 1)
11528 elt = dump_subexp (exp, stream, elt);
11533 /* The Ada extension of print_subexp (q.v.). */
11536 ada_print_subexp (struct expression *exp, int *pos,
11537 struct ui_file *stream, enum precedence prec)
11539 int oplen, nargs, i;
11541 enum exp_opcode op = exp->elts[pc].opcode;
11543 ada_forward_operator_length (exp, pc, &oplen, &nargs);
11550 print_subexp_standard (exp, pos, stream, prec);
11554 fputs_filtered (SYMBOL_NATURAL_NAME (exp->elts[pc + 2].symbol), stream);
11557 case BINOP_IN_BOUNDS:
11558 /* XXX: sprint_subexp */
11559 print_subexp (exp, pos, stream, PREC_SUFFIX);
11560 fputs_filtered (" in ", stream);
11561 print_subexp (exp, pos, stream, PREC_SUFFIX);
11562 fputs_filtered ("'range", stream);
11563 if (exp->elts[pc + 1].longconst > 1)
11564 fprintf_filtered (stream, "(%ld)",
11565 (long) exp->elts[pc + 1].longconst);
11568 case TERNOP_IN_RANGE:
11569 if (prec >= PREC_EQUAL)
11570 fputs_filtered ("(", stream);
11571 /* XXX: sprint_subexp */
11572 print_subexp (exp, pos, stream, PREC_SUFFIX);
11573 fputs_filtered (" in ", stream);
11574 print_subexp (exp, pos, stream, PREC_EQUAL);
11575 fputs_filtered (" .. ", stream);
11576 print_subexp (exp, pos, stream, PREC_EQUAL);
11577 if (prec >= PREC_EQUAL)
11578 fputs_filtered (")", stream);
11583 case OP_ATR_LENGTH:
11587 case OP_ATR_MODULUS:
11592 if (exp->elts[*pos].opcode == OP_TYPE)
11594 if (TYPE_CODE (exp->elts[*pos + 1].type) != TYPE_CODE_VOID)
11595 LA_PRINT_TYPE (exp->elts[*pos + 1].type, "", stream, 0, 0);
11599 print_subexp (exp, pos, stream, PREC_SUFFIX);
11600 fprintf_filtered (stream, "'%s", ada_attribute_name (op));
11605 for (tem = 1; tem < nargs; tem += 1)
11607 fputs_filtered ((tem == 1) ? " (" : ", ", stream);
11608 print_subexp (exp, pos, stream, PREC_ABOVE_COMMA);
11610 fputs_filtered (")", stream);
11615 type_print (exp->elts[pc + 1].type, "", stream, 0);
11616 fputs_filtered ("'(", stream);
11617 print_subexp (exp, pos, stream, PREC_PREFIX);
11618 fputs_filtered (")", stream);
11621 case UNOP_IN_RANGE:
11622 /* XXX: sprint_subexp */
11623 print_subexp (exp, pos, stream, PREC_SUFFIX);
11624 fputs_filtered (" in ", stream);
11625 LA_PRINT_TYPE (exp->elts[pc + 1].type, "", stream, 1, 0);
11628 case OP_DISCRETE_RANGE:
11629 print_subexp (exp, pos, stream, PREC_SUFFIX);
11630 fputs_filtered ("..", stream);
11631 print_subexp (exp, pos, stream, PREC_SUFFIX);
11635 fputs_filtered ("others => ", stream);
11636 print_subexp (exp, pos, stream, PREC_SUFFIX);
11640 for (i = 0; i < nargs-1; i += 1)
11643 fputs_filtered ("|", stream);
11644 print_subexp (exp, pos, stream, PREC_SUFFIX);
11646 fputs_filtered (" => ", stream);
11647 print_subexp (exp, pos, stream, PREC_SUFFIX);
11650 case OP_POSITIONAL:
11651 print_subexp (exp, pos, stream, PREC_SUFFIX);
11655 fputs_filtered ("(", stream);
11656 for (i = 0; i < nargs; i += 1)
11659 fputs_filtered (", ", stream);
11660 print_subexp (exp, pos, stream, PREC_SUFFIX);
11662 fputs_filtered (")", stream);
11667 /* Table mapping opcodes into strings for printing operators
11668 and precedences of the operators. */
11670 static const struct op_print ada_op_print_tab[] = {
11671 {":=", BINOP_ASSIGN, PREC_ASSIGN, 1},
11672 {"or else", BINOP_LOGICAL_OR, PREC_LOGICAL_OR, 0},
11673 {"and then", BINOP_LOGICAL_AND, PREC_LOGICAL_AND, 0},
11674 {"or", BINOP_BITWISE_IOR, PREC_BITWISE_IOR, 0},
11675 {"xor", BINOP_BITWISE_XOR, PREC_BITWISE_XOR, 0},
11676 {"and", BINOP_BITWISE_AND, PREC_BITWISE_AND, 0},
11677 {"=", BINOP_EQUAL, PREC_EQUAL, 0},
11678 {"/=", BINOP_NOTEQUAL, PREC_EQUAL, 0},
11679 {"<=", BINOP_LEQ, PREC_ORDER, 0},
11680 {">=", BINOP_GEQ, PREC_ORDER, 0},
11681 {">", BINOP_GTR, PREC_ORDER, 0},
11682 {"<", BINOP_LESS, PREC_ORDER, 0},
11683 {">>", BINOP_RSH, PREC_SHIFT, 0},
11684 {"<<", BINOP_LSH, PREC_SHIFT, 0},
11685 {"+", BINOP_ADD, PREC_ADD, 0},
11686 {"-", BINOP_SUB, PREC_ADD, 0},
11687 {"&", BINOP_CONCAT, PREC_ADD, 0},
11688 {"*", BINOP_MUL, PREC_MUL, 0},
11689 {"/", BINOP_DIV, PREC_MUL, 0},
11690 {"rem", BINOP_REM, PREC_MUL, 0},
11691 {"mod", BINOP_MOD, PREC_MUL, 0},
11692 {"**", BINOP_EXP, PREC_REPEAT, 0},
11693 {"@", BINOP_REPEAT, PREC_REPEAT, 0},
11694 {"-", UNOP_NEG, PREC_PREFIX, 0},
11695 {"+", UNOP_PLUS, PREC_PREFIX, 0},
11696 {"not ", UNOP_LOGICAL_NOT, PREC_PREFIX, 0},
11697 {"not ", UNOP_COMPLEMENT, PREC_PREFIX, 0},
11698 {"abs ", UNOP_ABS, PREC_PREFIX, 0},
11699 {".all", UNOP_IND, PREC_SUFFIX, 1},
11700 {"'access", UNOP_ADDR, PREC_SUFFIX, 1},
11701 {"'size", OP_ATR_SIZE, PREC_SUFFIX, 1},
11705 enum ada_primitive_types {
11706 ada_primitive_type_int,
11707 ada_primitive_type_long,
11708 ada_primitive_type_short,
11709 ada_primitive_type_char,
11710 ada_primitive_type_float,
11711 ada_primitive_type_double,
11712 ada_primitive_type_void,
11713 ada_primitive_type_long_long,
11714 ada_primitive_type_long_double,
11715 ada_primitive_type_natural,
11716 ada_primitive_type_positive,
11717 ada_primitive_type_system_address,
11718 nr_ada_primitive_types
11722 ada_language_arch_info (struct gdbarch *gdbarch,
11723 struct language_arch_info *lai)
11725 const struct builtin_type *builtin = builtin_type (gdbarch);
11727 lai->primitive_type_vector
11728 = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_ada_primitive_types + 1,
11731 lai->primitive_type_vector [ada_primitive_type_int]
11732 = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
11734 lai->primitive_type_vector [ada_primitive_type_long]
11735 = arch_integer_type (gdbarch, gdbarch_long_bit (gdbarch),
11736 0, "long_integer");
11737 lai->primitive_type_vector [ada_primitive_type_short]
11738 = arch_integer_type (gdbarch, gdbarch_short_bit (gdbarch),
11739 0, "short_integer");
11740 lai->string_char_type
11741 = lai->primitive_type_vector [ada_primitive_type_char]
11742 = arch_integer_type (gdbarch, TARGET_CHAR_BIT, 0, "character");
11743 lai->primitive_type_vector [ada_primitive_type_float]
11744 = arch_float_type (gdbarch, gdbarch_float_bit (gdbarch),
11746 lai->primitive_type_vector [ada_primitive_type_double]
11747 = arch_float_type (gdbarch, gdbarch_double_bit (gdbarch),
11748 "long_float", NULL);
11749 lai->primitive_type_vector [ada_primitive_type_long_long]
11750 = arch_integer_type (gdbarch, gdbarch_long_long_bit (gdbarch),
11751 0, "long_long_integer");
11752 lai->primitive_type_vector [ada_primitive_type_long_double]
11753 = arch_float_type (gdbarch, gdbarch_double_bit (gdbarch),
11754 "long_long_float", NULL);
11755 lai->primitive_type_vector [ada_primitive_type_natural]
11756 = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
11758 lai->primitive_type_vector [ada_primitive_type_positive]
11759 = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
11761 lai->primitive_type_vector [ada_primitive_type_void]
11762 = builtin->builtin_void;
11764 lai->primitive_type_vector [ada_primitive_type_system_address]
11765 = lookup_pointer_type (arch_type (gdbarch, TYPE_CODE_VOID, 1, "void"));
11766 TYPE_NAME (lai->primitive_type_vector [ada_primitive_type_system_address])
11767 = "system__address";
11769 lai->bool_type_symbol = NULL;
11770 lai->bool_type_default = builtin->builtin_bool;
11773 /* Language vector */
11775 /* Not really used, but needed in the ada_language_defn. */
11778 emit_char (int c, struct type *type, struct ui_file *stream, int quoter)
11780 ada_emit_char (c, type, stream, quoter, 1);
11786 warnings_issued = 0;
11787 return ada_parse ();
11790 static const struct exp_descriptor ada_exp_descriptor = {
11792 ada_operator_length,
11793 ada_operator_check,
11795 ada_dump_subexp_body,
11796 ada_evaluate_subexp
11799 const struct language_defn ada_language_defn = {
11800 "ada", /* Language name */
11804 case_sensitive_on, /* Yes, Ada is case-insensitive, but
11805 that's not quite what this means. */
11807 macro_expansion_no,
11808 &ada_exp_descriptor,
11812 ada_printchar, /* Print a character constant */
11813 ada_printstr, /* Function to print string constant */
11814 emit_char, /* Function to print single char (not used) */
11815 ada_print_type, /* Print a type using appropriate syntax */
11816 ada_print_typedef, /* Print a typedef using appropriate syntax */
11817 ada_val_print, /* Print a value using appropriate syntax */
11818 ada_value_print, /* Print a top-level value */
11819 NULL, /* Language specific skip_trampoline */
11820 NULL, /* name_of_this */
11821 ada_lookup_symbol_nonlocal, /* Looking up non-local symbols. */
11822 basic_lookup_transparent_type, /* lookup_transparent_type */
11823 ada_la_decode, /* Language specific symbol demangler */
11824 NULL, /* Language specific
11825 class_name_from_physname */
11826 ada_op_print_tab, /* expression operators for printing */
11827 0, /* c-style arrays */
11828 1, /* String lower bound */
11829 ada_get_gdb_completer_word_break_characters,
11830 ada_make_symbol_completion_list,
11831 ada_language_arch_info,
11832 ada_print_array_index,
11833 default_pass_by_reference,
11838 /* Provide a prototype to silence -Wmissing-prototypes. */
11839 extern initialize_file_ftype _initialize_ada_language;
11841 /* Command-list for the "set/show ada" prefix command. */
11842 static struct cmd_list_element *set_ada_list;
11843 static struct cmd_list_element *show_ada_list;
11845 /* Implement the "set ada" prefix command. */
11848 set_ada_command (char *arg, int from_tty)
11850 printf_unfiltered (_(\
11851 "\"set ada\" must be followed by the name of a setting.\n"));
11852 help_list (set_ada_list, "set ada ", -1, gdb_stdout);
11855 /* Implement the "show ada" prefix command. */
11858 show_ada_command (char *args, int from_tty)
11860 cmd_show_list (show_ada_list, from_tty, "");
11864 _initialize_ada_language (void)
11866 add_language (&ada_language_defn);
11868 add_prefix_cmd ("ada", no_class, set_ada_command,
11869 _("Prefix command for changing Ada-specfic settings"),
11870 &set_ada_list, "set ada ", 0, &setlist);
11872 add_prefix_cmd ("ada", no_class, show_ada_command,
11873 _("Generic command for showing Ada-specific settings."),
11874 &show_ada_list, "show ada ", 0, &showlist);
11876 add_setshow_boolean_cmd ("trust-PAD-over-XVS", class_obscure,
11877 &trust_pad_over_xvs, _("\
11878 Enable or disable an optimization trusting PAD types over XVS types"), _("\
11879 Show whether an optimization trusting PAD types over XVS types is activated"),
11881 This is related to the encoding used by the GNAT compiler. The debugger\n\
11882 should normally trust the contents of PAD types, but certain older versions\n\
11883 of GNAT have a bug that sometimes causes the information in the PAD type\n\
11884 to be incorrect. Turning this setting \"off\" allows the debugger to\n\
11885 work around this bug. It is always safe to turn this option \"off\", but\n\
11886 this incurs a slight performance penalty, so it is recommended to NOT change\n\
11887 this option to \"off\" unless necessary."),
11888 NULL, NULL, &set_ada_list, &show_ada_list);
11890 varsize_limit = 65536;
11892 obstack_init (&symbol_list_obstack);
11894 decoded_names_store = htab_create_alloc
11895 (256, htab_hash_string, (int (*)(const void *, const void *)) streq,
11896 NULL, xcalloc, xfree);
11898 observer_attach_executable_changed (ada_executable_changed_observer);
11900 /* Setup per-inferior data. */
11901 observer_attach_inferior_exit (ada_inferior_exit);
11903 = register_inferior_data_with_cleanup (ada_inferior_data_cleanup);