1 /* Ada language support routines for GDB, the GNU debugger.
3 Copyright (C) 1992-2021 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #include "gdb_regex.h"
28 #include "expression.h"
29 #include "parser-defs.h"
35 #include "breakpoint.h"
38 #include "gdb_obstack.h"
40 #include "completer.h"
47 #include "observable.h"
49 #include "typeprint.h"
50 #include "namespace.h"
51 #include "cli/cli-style.h"
54 #include "mi/mi-common.h"
55 #include "arch-utils.h"
56 #include "cli/cli-utils.h"
57 #include "gdbsupport/function-view.h"
58 #include "gdbsupport/byte-vector.h"
62 /* Define whether or not the C operator '/' truncates towards zero for
63 differently signed operands (truncation direction is undefined in C).
64 Copied from valarith.c. */
66 #ifndef TRUNCATION_TOWARDS_ZERO
67 #define TRUNCATION_TOWARDS_ZERO ((-5 / 2) == -2)
70 static struct type
*desc_base_type (struct type
*);
72 static struct type
*desc_bounds_type (struct type
*);
74 static struct value
*desc_bounds (struct value
*);
76 static int fat_pntr_bounds_bitpos (struct type
*);
78 static int fat_pntr_bounds_bitsize (struct type
*);
80 static struct type
*desc_data_target_type (struct type
*);
82 static struct value
*desc_data (struct value
*);
84 static int fat_pntr_data_bitpos (struct type
*);
86 static int fat_pntr_data_bitsize (struct type
*);
88 static struct value
*desc_one_bound (struct value
*, int, int);
90 static int desc_bound_bitpos (struct type
*, int, int);
92 static int desc_bound_bitsize (struct type
*, int, int);
94 static struct type
*desc_index_type (struct type
*, int);
96 static int desc_arity (struct type
*);
98 static int ada_type_match (struct type
*, struct type
*, int);
100 static int ada_args_match (struct symbol
*, struct value
**, int);
102 static struct value
*make_array_descriptor (struct type
*, struct value
*);
104 static void ada_add_block_symbols (std::vector
<struct block_symbol
> &,
105 const struct block
*,
106 const lookup_name_info
&lookup_name
,
107 domain_enum
, struct objfile
*);
109 static void ada_add_all_symbols (std::vector
<struct block_symbol
> &,
110 const struct block
*,
111 const lookup_name_info
&lookup_name
,
112 domain_enum
, int, int *);
114 static int is_nonfunction (const std::vector
<struct block_symbol
> &);
116 static void add_defn_to_vec (std::vector
<struct block_symbol
> &,
118 const struct block
*);
120 static struct value
*resolve_subexp (expression_up
*, int *, int,
122 innermost_block_tracker
*);
124 static void replace_operator_with_call (expression_up
*, int, int, int,
125 struct symbol
*, const struct block
*);
127 static int possible_user_operator_p (enum exp_opcode
, struct value
**);
129 static const char *ada_decoded_op_name (enum exp_opcode
);
131 static int numeric_type_p (struct type
*);
133 static int integer_type_p (struct type
*);
135 static int scalar_type_p (struct type
*);
137 static int discrete_type_p (struct type
*);
139 static struct type
*ada_lookup_struct_elt_type (struct type
*, const char *,
142 static struct value
*evaluate_subexp_type (struct expression
*, int *);
144 static struct type
*ada_find_parallel_type_with_name (struct type
*,
147 static int is_dynamic_field (struct type
*, int);
149 static struct type
*to_fixed_variant_branch_type (struct type
*,
151 CORE_ADDR
, struct value
*);
153 static struct type
*to_fixed_array_type (struct type
*, struct value
*, int);
155 static struct type
*to_fixed_range_type (struct type
*, struct value
*);
157 static struct type
*to_static_fixed_type (struct type
*);
158 static struct type
*static_unwrap_type (struct type
*type
);
160 static struct value
*unwrap_value (struct value
*);
162 static struct type
*constrained_packed_array_type (struct type
*, long *);
164 static struct type
*decode_constrained_packed_array_type (struct type
*);
166 static long decode_packed_array_bitsize (struct type
*);
168 static struct value
*decode_constrained_packed_array (struct value
*);
170 static int ada_is_unconstrained_packed_array_type (struct type
*);
172 static struct value
*value_subscript_packed (struct value
*, int,
175 static struct value
*coerce_unspec_val_to_type (struct value
*,
178 static int lesseq_defined_than (struct symbol
*, struct symbol
*);
180 static int equiv_types (struct type
*, struct type
*);
182 static int is_name_suffix (const char *);
184 static int advance_wild_match (const char **, const char *, char);
186 static bool wild_match (const char *name
, const char *patn
);
188 static struct value
*ada_coerce_ref (struct value
*);
190 static LONGEST
pos_atr (struct value
*);
192 static struct value
*val_atr (struct type
*, LONGEST
);
194 static struct symbol
*standard_lookup (const char *, const struct block
*,
197 static struct value
*ada_search_struct_field (const char *, struct value
*, int,
200 static int find_struct_field (const char *, struct type
*, int,
201 struct type
**, int *, int *, int *, int *);
203 static int ada_resolve_function (std::vector
<struct block_symbol
> &,
204 struct value
**, int, const char *,
207 static int ada_is_direct_array_type (struct type
*);
209 static struct value
*ada_index_struct_field (int, struct value
*, int,
212 static struct value
*assign_aggregate (struct value
*, struct value
*,
216 static void aggregate_assign_from_choices (struct value
*, struct value
*,
218 int *, std::vector
<LONGEST
> &,
221 static void aggregate_assign_positional (struct value
*, struct value
*,
223 int *, std::vector
<LONGEST
> &,
227 static void aggregate_assign_others (struct value
*, struct value
*,
229 int *, std::vector
<LONGEST
> &,
233 static void add_component_interval (LONGEST
, LONGEST
, std::vector
<LONGEST
> &);
236 static struct value
*ada_evaluate_subexp (struct type
*, struct expression
*,
239 static void ada_forward_operator_length (struct expression
*, int, int *,
242 static struct type
*ada_find_any_type (const char *name
);
244 static symbol_name_matcher_ftype
*ada_get_symbol_name_matcher
245 (const lookup_name_info
&lookup_name
);
249 /* The result of a symbol lookup to be stored in our symbol cache. */
253 /* The name used to perform the lookup. */
255 /* The namespace used during the lookup. */
257 /* The symbol returned by the lookup, or NULL if no matching symbol
260 /* The block where the symbol was found, or NULL if no matching
262 const struct block
*block
;
263 /* A pointer to the next entry with the same hash. */
264 struct cache_entry
*next
;
267 /* The Ada symbol cache, used to store the result of Ada-mode symbol
268 lookups in the course of executing the user's commands.
270 The cache is implemented using a simple, fixed-sized hash.
271 The size is fixed on the grounds that there are not likely to be
272 all that many symbols looked up during any given session, regardless
273 of the size of the symbol table. If we decide to go to a resizable
274 table, let's just use the stuff from libiberty instead. */
276 #define HASH_SIZE 1009
278 struct ada_symbol_cache
280 /* An obstack used to store the entries in our cache. */
281 struct auto_obstack cache_space
;
283 /* The root of the hash table used to implement our symbol cache. */
284 struct cache_entry
*root
[HASH_SIZE
] {};
287 /* Maximum-sized dynamic type. */
288 static unsigned int varsize_limit
;
290 static const char ada_completer_word_break_characters
[] =
292 " \t\n!@#%^&*()+=|~`}{[]\";:?/,-";
294 " \t\n!@#$%^&*()+=|~`}{[]\";:?/,-";
297 /* The name of the symbol to use to get the name of the main subprogram. */
298 static const char ADA_MAIN_PROGRAM_SYMBOL_NAME
[]
299 = "__gnat_ada_main_program_name";
301 /* Limit on the number of warnings to raise per expression evaluation. */
302 static int warning_limit
= 2;
304 /* Number of warning messages issued; reset to 0 by cleanups after
305 expression evaluation. */
306 static int warnings_issued
= 0;
308 static const char * const known_runtime_file_name_patterns
[] = {
309 ADA_KNOWN_RUNTIME_FILE_NAME_PATTERNS NULL
312 static const char * const known_auxiliary_function_name_patterns
[] = {
313 ADA_KNOWN_AUXILIARY_FUNCTION_NAME_PATTERNS NULL
316 /* Maintenance-related settings for this module. */
318 static struct cmd_list_element
*maint_set_ada_cmdlist
;
319 static struct cmd_list_element
*maint_show_ada_cmdlist
;
321 /* The "maintenance ada set/show ignore-descriptive-type" value. */
323 static bool ada_ignore_descriptive_types_p
= false;
325 /* Inferior-specific data. */
327 /* Per-inferior data for this module. */
329 struct ada_inferior_data
331 /* The ada__tags__type_specific_data type, which is used when decoding
332 tagged types. With older versions of GNAT, this type was directly
333 accessible through a component ("tsd") in the object tag. But this
334 is no longer the case, so we cache it for each inferior. */
335 struct type
*tsd_type
= nullptr;
337 /* The exception_support_info data. This data is used to determine
338 how to implement support for Ada exception catchpoints in a given
340 const struct exception_support_info
*exception_info
= nullptr;
343 /* Our key to this module's inferior data. */
344 static const struct inferior_key
<ada_inferior_data
> ada_inferior_data
;
346 /* Return our inferior data for the given inferior (INF).
348 This function always returns a valid pointer to an allocated
349 ada_inferior_data structure. If INF's inferior data has not
350 been previously set, this functions creates a new one with all
351 fields set to zero, sets INF's inferior to it, and then returns
352 a pointer to that newly allocated ada_inferior_data. */
354 static struct ada_inferior_data
*
355 get_ada_inferior_data (struct inferior
*inf
)
357 struct ada_inferior_data
*data
;
359 data
= ada_inferior_data
.get (inf
);
361 data
= ada_inferior_data
.emplace (inf
);
366 /* Perform all necessary cleanups regarding our module's inferior data
367 that is required after the inferior INF just exited. */
370 ada_inferior_exit (struct inferior
*inf
)
372 ada_inferior_data
.clear (inf
);
376 /* program-space-specific data. */
378 /* This module's per-program-space data. */
379 struct ada_pspace_data
381 /* The Ada symbol cache. */
382 std::unique_ptr
<ada_symbol_cache
> sym_cache
;
385 /* Key to our per-program-space data. */
386 static const struct program_space_key
<ada_pspace_data
> ada_pspace_data_handle
;
388 /* Return this module's data for the given program space (PSPACE).
389 If not is found, add a zero'ed one now.
391 This function always returns a valid object. */
393 static struct ada_pspace_data
*
394 get_ada_pspace_data (struct program_space
*pspace
)
396 struct ada_pspace_data
*data
;
398 data
= ada_pspace_data_handle
.get (pspace
);
400 data
= ada_pspace_data_handle
.emplace (pspace
);
407 /* If TYPE is a TYPE_CODE_TYPEDEF type, return the target type after
408 all typedef layers have been peeled. Otherwise, return TYPE.
410 Normally, we really expect a typedef type to only have 1 typedef layer.
411 In other words, we really expect the target type of a typedef type to be
412 a non-typedef type. This is particularly true for Ada units, because
413 the language does not have a typedef vs not-typedef distinction.
414 In that respect, the Ada compiler has been trying to eliminate as many
415 typedef definitions in the debugging information, since they generally
416 do not bring any extra information (we still use typedef under certain
417 circumstances related mostly to the GNAT encoding).
419 Unfortunately, we have seen situations where the debugging information
420 generated by the compiler leads to such multiple typedef layers. For
421 instance, consider the following example with stabs:
423 .stabs "pck__float_array___XUP:Tt(0,46)=s16P_ARRAY:(0,47)=[...]"[...]
424 .stabs "pck__float_array___XUP:t(0,36)=(0,46)",128,0,6,0
426 This is an error in the debugging information which causes type
427 pck__float_array___XUP to be defined twice, and the second time,
428 it is defined as a typedef of a typedef.
430 This is on the fringe of legality as far as debugging information is
431 concerned, and certainly unexpected. But it is easy to handle these
432 situations correctly, so we can afford to be lenient in this case. */
435 ada_typedef_target_type (struct type
*type
)
437 while (type
->code () == TYPE_CODE_TYPEDEF
)
438 type
= TYPE_TARGET_TYPE (type
);
442 /* Given DECODED_NAME a string holding a symbol name in its
443 decoded form (ie using the Ada dotted notation), returns
444 its unqualified name. */
447 ada_unqualified_name (const char *decoded_name
)
451 /* If the decoded name starts with '<', it means that the encoded
452 name does not follow standard naming conventions, and thus that
453 it is not your typical Ada symbol name. Trying to unqualify it
454 is therefore pointless and possibly erroneous. */
455 if (decoded_name
[0] == '<')
458 result
= strrchr (decoded_name
, '.');
460 result
++; /* Skip the dot... */
462 result
= decoded_name
;
467 /* Return a string starting with '<', followed by STR, and '>'. */
470 add_angle_brackets (const char *str
)
472 return string_printf ("<%s>", str
);
475 /* True (non-zero) iff TARGET matches FIELD_NAME up to any trailing
476 suffix of FIELD_NAME beginning "___". */
479 field_name_match (const char *field_name
, const char *target
)
481 int len
= strlen (target
);
484 (strncmp (field_name
, target
, len
) == 0
485 && (field_name
[len
] == '\0'
486 || (startswith (field_name
+ len
, "___")
487 && strcmp (field_name
+ strlen (field_name
) - 6,
492 /* Assuming TYPE is a TYPE_CODE_STRUCT or a TYPE_CODE_TYPDEF to
493 a TYPE_CODE_STRUCT, find the field whose name matches FIELD_NAME,
494 and return its index. This function also handles fields whose name
495 have ___ suffixes because the compiler sometimes alters their name
496 by adding such a suffix to represent fields with certain constraints.
497 If the field could not be found, return a negative number if
498 MAYBE_MISSING is set. Otherwise raise an error. */
501 ada_get_field_index (const struct type
*type
, const char *field_name
,
505 struct type
*struct_type
= check_typedef ((struct type
*) type
);
507 for (fieldno
= 0; fieldno
< struct_type
->num_fields (); fieldno
++)
508 if (field_name_match (TYPE_FIELD_NAME (struct_type
, fieldno
), field_name
))
512 error (_("Unable to find field %s in struct %s. Aborting"),
513 field_name
, struct_type
->name ());
518 /* The length of the prefix of NAME prior to any "___" suffix. */
521 ada_name_prefix_len (const char *name
)
527 const char *p
= strstr (name
, "___");
530 return strlen (name
);
536 /* Return non-zero if SUFFIX is a suffix of STR.
537 Return zero if STR is null. */
540 is_suffix (const char *str
, const char *suffix
)
547 len2
= strlen (suffix
);
548 return (len1
>= len2
&& strcmp (str
+ len1
- len2
, suffix
) == 0);
551 /* The contents of value VAL, treated as a value of type TYPE. The
552 result is an lval in memory if VAL is. */
554 static struct value
*
555 coerce_unspec_val_to_type (struct value
*val
, struct type
*type
)
557 type
= ada_check_typedef (type
);
558 if (value_type (val
) == type
)
562 struct value
*result
;
564 /* Make sure that the object size is not unreasonable before
565 trying to allocate some memory for it. */
566 ada_ensure_varsize_limit (type
);
568 if (value_optimized_out (val
))
569 result
= allocate_optimized_out_value (type
);
570 else if (value_lazy (val
)
571 /* Be careful not to make a lazy not_lval value. */
572 || (VALUE_LVAL (val
) != not_lval
573 && TYPE_LENGTH (type
) > TYPE_LENGTH (value_type (val
))))
574 result
= allocate_value_lazy (type
);
577 result
= allocate_value (type
);
578 value_contents_copy (result
, 0, val
, 0, TYPE_LENGTH (type
));
580 set_value_component_location (result
, val
);
581 set_value_bitsize (result
, value_bitsize (val
));
582 set_value_bitpos (result
, value_bitpos (val
));
583 if (VALUE_LVAL (result
) == lval_memory
)
584 set_value_address (result
, value_address (val
));
589 static const gdb_byte
*
590 cond_offset_host (const gdb_byte
*valaddr
, long offset
)
595 return valaddr
+ offset
;
599 cond_offset_target (CORE_ADDR address
, long offset
)
604 return address
+ offset
;
607 /* Issue a warning (as for the definition of warning in utils.c, but
608 with exactly one argument rather than ...), unless the limit on the
609 number of warnings has passed during the evaluation of the current
612 /* FIXME: cagney/2004-10-10: This function is mimicking the behavior
613 provided by "complaint". */
614 static void lim_warning (const char *format
, ...) ATTRIBUTE_PRINTF (1, 2);
617 lim_warning (const char *format
, ...)
621 va_start (args
, format
);
622 warnings_issued
+= 1;
623 if (warnings_issued
<= warning_limit
)
624 vwarning (format
, args
);
629 /* Issue an error if the size of an object of type T is unreasonable,
630 i.e. if it would be a bad idea to allocate a value of this type in
634 ada_ensure_varsize_limit (const struct type
*type
)
636 if (TYPE_LENGTH (type
) > varsize_limit
)
637 error (_("object size is larger than varsize-limit"));
640 /* Maximum value of a SIZE-byte signed integer type. */
642 max_of_size (int size
)
644 LONGEST top_bit
= (LONGEST
) 1 << (size
* 8 - 2);
646 return top_bit
| (top_bit
- 1);
649 /* Minimum value of a SIZE-byte signed integer type. */
651 min_of_size (int size
)
653 return -max_of_size (size
) - 1;
656 /* Maximum value of a SIZE-byte unsigned integer type. */
658 umax_of_size (int size
)
660 ULONGEST top_bit
= (ULONGEST
) 1 << (size
* 8 - 1);
662 return top_bit
| (top_bit
- 1);
665 /* Maximum value of integral type T, as a signed quantity. */
667 max_of_type (struct type
*t
)
669 if (t
->is_unsigned ())
670 return (LONGEST
) umax_of_size (TYPE_LENGTH (t
));
672 return max_of_size (TYPE_LENGTH (t
));
675 /* Minimum value of integral type T, as a signed quantity. */
677 min_of_type (struct type
*t
)
679 if (t
->is_unsigned ())
682 return min_of_size (TYPE_LENGTH (t
));
685 /* The largest value in the domain of TYPE, a discrete type, as an integer. */
687 ada_discrete_type_high_bound (struct type
*type
)
689 type
= resolve_dynamic_type (type
, {}, 0);
690 switch (type
->code ())
692 case TYPE_CODE_RANGE
:
694 const dynamic_prop
&high
= type
->bounds ()->high
;
696 if (high
.kind () == PROP_CONST
)
697 return high
.const_val ();
700 gdb_assert (high
.kind () == PROP_UNDEFINED
);
702 /* This happens when trying to evaluate a type's dynamic bound
703 without a live target. There is nothing relevant for us to
704 return here, so return 0. */
709 return TYPE_FIELD_ENUMVAL (type
, type
->num_fields () - 1);
714 return max_of_type (type
);
716 error (_("Unexpected type in ada_discrete_type_high_bound."));
720 /* The smallest value in the domain of TYPE, a discrete type, as an integer. */
722 ada_discrete_type_low_bound (struct type
*type
)
724 type
= resolve_dynamic_type (type
, {}, 0);
725 switch (type
->code ())
727 case TYPE_CODE_RANGE
:
729 const dynamic_prop
&low
= type
->bounds ()->low
;
731 if (low
.kind () == PROP_CONST
)
732 return low
.const_val ();
735 gdb_assert (low
.kind () == PROP_UNDEFINED
);
737 /* This happens when trying to evaluate a type's dynamic bound
738 without a live target. There is nothing relevant for us to
739 return here, so return 0. */
744 return TYPE_FIELD_ENUMVAL (type
, 0);
749 return min_of_type (type
);
751 error (_("Unexpected type in ada_discrete_type_low_bound."));
755 /* The identity on non-range types. For range types, the underlying
756 non-range scalar type. */
759 get_base_type (struct type
*type
)
761 while (type
!= NULL
&& type
->code () == TYPE_CODE_RANGE
)
763 if (type
== TYPE_TARGET_TYPE (type
) || TYPE_TARGET_TYPE (type
) == NULL
)
765 type
= TYPE_TARGET_TYPE (type
);
770 /* Return a decoded version of the given VALUE. This means returning
771 a value whose type is obtained by applying all the GNAT-specific
772 encodings, making the resulting type a static but standard description
773 of the initial type. */
776 ada_get_decoded_value (struct value
*value
)
778 struct type
*type
= ada_check_typedef (value_type (value
));
780 if (ada_is_array_descriptor_type (type
)
781 || (ada_is_constrained_packed_array_type (type
)
782 && type
->code () != TYPE_CODE_PTR
))
784 if (type
->code () == TYPE_CODE_TYPEDEF
) /* array access type. */
785 value
= ada_coerce_to_simple_array_ptr (value
);
787 value
= ada_coerce_to_simple_array (value
);
790 value
= ada_to_fixed_value (value
);
795 /* Same as ada_get_decoded_value, but with the given TYPE.
796 Because there is no associated actual value for this type,
797 the resulting type might be a best-effort approximation in
798 the case of dynamic types. */
801 ada_get_decoded_type (struct type
*type
)
803 type
= to_static_fixed_type (type
);
804 if (ada_is_constrained_packed_array_type (type
))
805 type
= ada_coerce_to_simple_array_type (type
);
811 /* Language Selection */
813 /* If the main program is in Ada, return language_ada, otherwise return LANG
814 (the main program is in Ada iif the adainit symbol is found). */
817 ada_update_initial_language (enum language lang
)
819 if (lookup_minimal_symbol ("adainit", NULL
, NULL
).minsym
!= NULL
)
825 /* If the main procedure is written in Ada, then return its name.
826 The result is good until the next call. Return NULL if the main
827 procedure doesn't appear to be in Ada. */
832 struct bound_minimal_symbol msym
;
833 static gdb::unique_xmalloc_ptr
<char> main_program_name
;
835 /* For Ada, the name of the main procedure is stored in a specific
836 string constant, generated by the binder. Look for that symbol,
837 extract its address, and then read that string. If we didn't find
838 that string, then most probably the main procedure is not written
840 msym
= lookup_minimal_symbol (ADA_MAIN_PROGRAM_SYMBOL_NAME
, NULL
, NULL
);
842 if (msym
.minsym
!= NULL
)
844 CORE_ADDR main_program_name_addr
= BMSYMBOL_VALUE_ADDRESS (msym
);
845 if (main_program_name_addr
== 0)
846 error (_("Invalid address for Ada main program name."));
848 main_program_name
= target_read_string (main_program_name_addr
, 1024);
849 return main_program_name
.get ();
852 /* The main procedure doesn't seem to be in Ada. */
858 /* Table of Ada operators and their GNAT-encoded names. Last entry is pair
861 const struct ada_opname_map ada_opname_table
[] = {
862 {"Oadd", "\"+\"", BINOP_ADD
},
863 {"Osubtract", "\"-\"", BINOP_SUB
},
864 {"Omultiply", "\"*\"", BINOP_MUL
},
865 {"Odivide", "\"/\"", BINOP_DIV
},
866 {"Omod", "\"mod\"", BINOP_MOD
},
867 {"Orem", "\"rem\"", BINOP_REM
},
868 {"Oexpon", "\"**\"", BINOP_EXP
},
869 {"Olt", "\"<\"", BINOP_LESS
},
870 {"Ole", "\"<=\"", BINOP_LEQ
},
871 {"Ogt", "\">\"", BINOP_GTR
},
872 {"Oge", "\">=\"", BINOP_GEQ
},
873 {"Oeq", "\"=\"", BINOP_EQUAL
},
874 {"One", "\"/=\"", BINOP_NOTEQUAL
},
875 {"Oand", "\"and\"", BINOP_BITWISE_AND
},
876 {"Oor", "\"or\"", BINOP_BITWISE_IOR
},
877 {"Oxor", "\"xor\"", BINOP_BITWISE_XOR
},
878 {"Oconcat", "\"&\"", BINOP_CONCAT
},
879 {"Oabs", "\"abs\"", UNOP_ABS
},
880 {"Onot", "\"not\"", UNOP_LOGICAL_NOT
},
881 {"Oadd", "\"+\"", UNOP_PLUS
},
882 {"Osubtract", "\"-\"", UNOP_NEG
},
886 /* The "encoded" form of DECODED, according to GNAT conventions. If
887 THROW_ERRORS, throw an error if invalid operator name is found.
888 Otherwise, return the empty string in that case. */
891 ada_encode_1 (const char *decoded
, bool throw_errors
)
896 std::string encoding_buffer
;
897 for (const char *p
= decoded
; *p
!= '\0'; p
+= 1)
900 encoding_buffer
.append ("__");
903 const struct ada_opname_map
*mapping
;
905 for (mapping
= ada_opname_table
;
906 mapping
->encoded
!= NULL
907 && !startswith (p
, mapping
->decoded
); mapping
+= 1)
909 if (mapping
->encoded
== NULL
)
912 error (_("invalid Ada operator name: %s"), p
);
916 encoding_buffer
.append (mapping
->encoded
);
920 encoding_buffer
.push_back (*p
);
923 return encoding_buffer
;
926 /* The "encoded" form of DECODED, according to GNAT conventions. */
929 ada_encode (const char *decoded
)
931 return ada_encode_1 (decoded
, true);
934 /* Return NAME folded to lower case, or, if surrounded by single
935 quotes, unfolded, but with the quotes stripped away. Result good
939 ada_fold_name (gdb::string_view name
)
941 static std::string fold_storage
;
943 if (!name
.empty () && name
[0] == '\'')
944 fold_storage
= gdb::to_string (name
.substr (1, name
.size () - 2));
947 fold_storage
= gdb::to_string (name
);
948 for (int i
= 0; i
< name
.size (); i
+= 1)
949 fold_storage
[i
] = tolower (fold_storage
[i
]);
952 return fold_storage
.c_str ();
955 /* Return nonzero if C is either a digit or a lowercase alphabet character. */
958 is_lower_alphanum (const char c
)
960 return (isdigit (c
) || (isalpha (c
) && islower (c
)));
963 /* ENCODED is the linkage name of a symbol and LEN contains its length.
964 This function saves in LEN the length of that same symbol name but
965 without either of these suffixes:
971 These are suffixes introduced by the compiler for entities such as
972 nested subprogram for instance, in order to avoid name clashes.
973 They do not serve any purpose for the debugger. */
976 ada_remove_trailing_digits (const char *encoded
, int *len
)
978 if (*len
> 1 && isdigit (encoded
[*len
- 1]))
982 while (i
> 0 && isdigit (encoded
[i
]))
984 if (i
>= 0 && encoded
[i
] == '.')
986 else if (i
>= 0 && encoded
[i
] == '$')
988 else if (i
>= 2 && startswith (encoded
+ i
- 2, "___"))
990 else if (i
>= 1 && startswith (encoded
+ i
- 1, "__"))
995 /* Remove the suffix introduced by the compiler for protected object
999 ada_remove_po_subprogram_suffix (const char *encoded
, int *len
)
1001 /* Remove trailing N. */
1003 /* Protected entry subprograms are broken into two
1004 separate subprograms: The first one is unprotected, and has
1005 a 'N' suffix; the second is the protected version, and has
1006 the 'P' suffix. The second calls the first one after handling
1007 the protection. Since the P subprograms are internally generated,
1008 we leave these names undecoded, giving the user a clue that this
1009 entity is internal. */
1012 && encoded
[*len
- 1] == 'N'
1013 && (isdigit (encoded
[*len
- 2]) || islower (encoded
[*len
- 2])))
1017 /* If ENCODED follows the GNAT entity encoding conventions, then return
1018 the decoded form of ENCODED. Otherwise, return "<%s>" where "%s" is
1019 replaced by ENCODED. */
1022 ada_decode (const char *encoded
)
1028 std::string decoded
;
1030 /* With function descriptors on PPC64, the value of a symbol named
1031 ".FN", if it exists, is the entry point of the function "FN". */
1032 if (encoded
[0] == '.')
1035 /* The name of the Ada main procedure starts with "_ada_".
1036 This prefix is not part of the decoded name, so skip this part
1037 if we see this prefix. */
1038 if (startswith (encoded
, "_ada_"))
1041 /* If the name starts with '_', then it is not a properly encoded
1042 name, so do not attempt to decode it. Similarly, if the name
1043 starts with '<', the name should not be decoded. */
1044 if (encoded
[0] == '_' || encoded
[0] == '<')
1047 len0
= strlen (encoded
);
1049 ada_remove_trailing_digits (encoded
, &len0
);
1050 ada_remove_po_subprogram_suffix (encoded
, &len0
);
1052 /* Remove the ___X.* suffix if present. Do not forget to verify that
1053 the suffix is located before the current "end" of ENCODED. We want
1054 to avoid re-matching parts of ENCODED that have previously been
1055 marked as discarded (by decrementing LEN0). */
1056 p
= strstr (encoded
, "___");
1057 if (p
!= NULL
&& p
- encoded
< len0
- 3)
1065 /* Remove any trailing TKB suffix. It tells us that this symbol
1066 is for the body of a task, but that information does not actually
1067 appear in the decoded name. */
1069 if (len0
> 3 && startswith (encoded
+ len0
- 3, "TKB"))
1072 /* Remove any trailing TB suffix. The TB suffix is slightly different
1073 from the TKB suffix because it is used for non-anonymous task
1076 if (len0
> 2 && startswith (encoded
+ len0
- 2, "TB"))
1079 /* Remove trailing "B" suffixes. */
1080 /* FIXME: brobecker/2006-04-19: Not sure what this are used for... */
1082 if (len0
> 1 && startswith (encoded
+ len0
- 1, "B"))
1085 /* Make decoded big enough for possible expansion by operator name. */
1087 decoded
.resize (2 * len0
+ 1, 'X');
1089 /* Remove trailing __{digit}+ or trailing ${digit}+. */
1091 if (len0
> 1 && isdigit (encoded
[len0
- 1]))
1094 while ((i
>= 0 && isdigit (encoded
[i
]))
1095 || (i
>= 1 && encoded
[i
] == '_' && isdigit (encoded
[i
- 1])))
1097 if (i
> 1 && encoded
[i
] == '_' && encoded
[i
- 1] == '_')
1099 else if (encoded
[i
] == '$')
1103 /* The first few characters that are not alphabetic are not part
1104 of any encoding we use, so we can copy them over verbatim. */
1106 for (i
= 0, j
= 0; i
< len0
&& !isalpha (encoded
[i
]); i
+= 1, j
+= 1)
1107 decoded
[j
] = encoded
[i
];
1112 /* Is this a symbol function? */
1113 if (at_start_name
&& encoded
[i
] == 'O')
1117 for (k
= 0; ada_opname_table
[k
].encoded
!= NULL
; k
+= 1)
1119 int op_len
= strlen (ada_opname_table
[k
].encoded
);
1120 if ((strncmp (ada_opname_table
[k
].encoded
+ 1, encoded
+ i
+ 1,
1122 && !isalnum (encoded
[i
+ op_len
]))
1124 strcpy (&decoded
.front() + j
, ada_opname_table
[k
].decoded
);
1127 j
+= strlen (ada_opname_table
[k
].decoded
);
1131 if (ada_opname_table
[k
].encoded
!= NULL
)
1136 /* Replace "TK__" with "__", which will eventually be translated
1137 into "." (just below). */
1139 if (i
< len0
- 4 && startswith (encoded
+ i
, "TK__"))
1142 /* Replace "__B_{DIGITS}+__" sequences by "__", which will eventually
1143 be translated into "." (just below). These are internal names
1144 generated for anonymous blocks inside which our symbol is nested. */
1146 if (len0
- i
> 5 && encoded
[i
] == '_' && encoded
[i
+1] == '_'
1147 && encoded
[i
+2] == 'B' && encoded
[i
+3] == '_'
1148 && isdigit (encoded
[i
+4]))
1152 while (k
< len0
&& isdigit (encoded
[k
]))
1153 k
++; /* Skip any extra digit. */
1155 /* Double-check that the "__B_{DIGITS}+" sequence we found
1156 is indeed followed by "__". */
1157 if (len0
- k
> 2 && encoded
[k
] == '_' && encoded
[k
+1] == '_')
1161 /* Remove _E{DIGITS}+[sb] */
1163 /* Just as for protected object subprograms, there are 2 categories
1164 of subprograms created by the compiler for each entry. The first
1165 one implements the actual entry code, and has a suffix following
1166 the convention above; the second one implements the barrier and
1167 uses the same convention as above, except that the 'E' is replaced
1170 Just as above, we do not decode the name of barrier functions
1171 to give the user a clue that the code he is debugging has been
1172 internally generated. */
1174 if (len0
- i
> 3 && encoded
[i
] == '_' && encoded
[i
+1] == 'E'
1175 && isdigit (encoded
[i
+2]))
1179 while (k
< len0
&& isdigit (encoded
[k
]))
1183 && (encoded
[k
] == 'b' || encoded
[k
] == 's'))
1186 /* Just as an extra precaution, make sure that if this
1187 suffix is followed by anything else, it is a '_'.
1188 Otherwise, we matched this sequence by accident. */
1190 || (k
< len0
&& encoded
[k
] == '_'))
1195 /* Remove trailing "N" in [a-z0-9]+N__. The N is added by
1196 the GNAT front-end in protected object subprograms. */
1199 && encoded
[i
] == 'N' && encoded
[i
+1] == '_' && encoded
[i
+2] == '_')
1201 /* Backtrack a bit up until we reach either the begining of
1202 the encoded name, or "__". Make sure that we only find
1203 digits or lowercase characters. */
1204 const char *ptr
= encoded
+ i
- 1;
1206 while (ptr
>= encoded
&& is_lower_alphanum (ptr
[0]))
1209 || (ptr
> encoded
&& ptr
[0] == '_' && ptr
[-1] == '_'))
1213 if (encoded
[i
] == 'X' && i
!= 0 && isalnum (encoded
[i
- 1]))
1215 /* This is a X[bn]* sequence not separated from the previous
1216 part of the name with a non-alpha-numeric character (in other
1217 words, immediately following an alpha-numeric character), then
1218 verify that it is placed at the end of the encoded name. If
1219 not, then the encoding is not valid and we should abort the
1220 decoding. Otherwise, just skip it, it is used in body-nested
1224 while (i
< len0
&& (encoded
[i
] == 'b' || encoded
[i
] == 'n'));
1228 else if (i
< len0
- 2 && encoded
[i
] == '_' && encoded
[i
+ 1] == '_')
1230 /* Replace '__' by '.'. */
1238 /* It's a character part of the decoded name, so just copy it
1240 decoded
[j
] = encoded
[i
];
1247 /* Decoded names should never contain any uppercase character.
1248 Double-check this, and abort the decoding if we find one. */
1250 for (i
= 0; i
< decoded
.length(); ++i
)
1251 if (isupper (decoded
[i
]) || decoded
[i
] == ' ')
1257 if (encoded
[0] == '<')
1260 decoded
= '<' + std::string(encoded
) + '>';
1265 /* Table for keeping permanent unique copies of decoded names. Once
1266 allocated, names in this table are never released. While this is a
1267 storage leak, it should not be significant unless there are massive
1268 changes in the set of decoded names in successive versions of a
1269 symbol table loaded during a single session. */
1270 static struct htab
*decoded_names_store
;
1272 /* Returns the decoded name of GSYMBOL, as for ada_decode, caching it
1273 in the language-specific part of GSYMBOL, if it has not been
1274 previously computed. Tries to save the decoded name in the same
1275 obstack as GSYMBOL, if possible, and otherwise on the heap (so that,
1276 in any case, the decoded symbol has a lifetime at least that of
1278 The GSYMBOL parameter is "mutable" in the C++ sense: logically
1279 const, but nevertheless modified to a semantically equivalent form
1280 when a decoded name is cached in it. */
1283 ada_decode_symbol (const struct general_symbol_info
*arg
)
1285 struct general_symbol_info
*gsymbol
= (struct general_symbol_info
*) arg
;
1286 const char **resultp
=
1287 &gsymbol
->language_specific
.demangled_name
;
1289 if (!gsymbol
->ada_mangled
)
1291 std::string decoded
= ada_decode (gsymbol
->linkage_name ());
1292 struct obstack
*obstack
= gsymbol
->language_specific
.obstack
;
1294 gsymbol
->ada_mangled
= 1;
1296 if (obstack
!= NULL
)
1297 *resultp
= obstack_strdup (obstack
, decoded
.c_str ());
1300 /* Sometimes, we can't find a corresponding objfile, in
1301 which case, we put the result on the heap. Since we only
1302 decode when needed, we hope this usually does not cause a
1303 significant memory leak (FIXME). */
1305 char **slot
= (char **) htab_find_slot (decoded_names_store
,
1306 decoded
.c_str (), INSERT
);
1309 *slot
= xstrdup (decoded
.c_str ());
1318 ada_la_decode (const char *encoded
, int options
)
1320 return xstrdup (ada_decode (encoded
).c_str ());
1327 /* Assuming that INDEX_DESC_TYPE is an ___XA structure, a structure
1328 generated by the GNAT compiler to describe the index type used
1329 for each dimension of an array, check whether it follows the latest
1330 known encoding. If not, fix it up to conform to the latest encoding.
1331 Otherwise, do nothing. This function also does nothing if
1332 INDEX_DESC_TYPE is NULL.
1334 The GNAT encoding used to describe the array index type evolved a bit.
1335 Initially, the information would be provided through the name of each
1336 field of the structure type only, while the type of these fields was
1337 described as unspecified and irrelevant. The debugger was then expected
1338 to perform a global type lookup using the name of that field in order
1339 to get access to the full index type description. Because these global
1340 lookups can be very expensive, the encoding was later enhanced to make
1341 the global lookup unnecessary by defining the field type as being
1342 the full index type description.
1344 The purpose of this routine is to allow us to support older versions
1345 of the compiler by detecting the use of the older encoding, and by
1346 fixing up the INDEX_DESC_TYPE to follow the new one (at this point,
1347 we essentially replace each field's meaningless type by the associated
1351 ada_fixup_array_indexes_type (struct type
*index_desc_type
)
1355 if (index_desc_type
== NULL
)
1357 gdb_assert (index_desc_type
->num_fields () > 0);
1359 /* Check if INDEX_DESC_TYPE follows the older encoding (it is sufficient
1360 to check one field only, no need to check them all). If not, return
1363 If our INDEX_DESC_TYPE was generated using the older encoding,
1364 the field type should be a meaningless integer type whose name
1365 is not equal to the field name. */
1366 if (index_desc_type
->field (0).type ()->name () != NULL
1367 && strcmp (index_desc_type
->field (0).type ()->name (),
1368 TYPE_FIELD_NAME (index_desc_type
, 0)) == 0)
1371 /* Fixup each field of INDEX_DESC_TYPE. */
1372 for (i
= 0; i
< index_desc_type
->num_fields (); i
++)
1374 const char *name
= TYPE_FIELD_NAME (index_desc_type
, i
);
1375 struct type
*raw_type
= ada_check_typedef (ada_find_any_type (name
));
1378 index_desc_type
->field (i
).set_type (raw_type
);
1382 /* The desc_* routines return primitive portions of array descriptors
1385 /* The descriptor or array type, if any, indicated by TYPE; removes
1386 level of indirection, if needed. */
1388 static struct type
*
1389 desc_base_type (struct type
*type
)
1393 type
= ada_check_typedef (type
);
1394 if (type
->code () == TYPE_CODE_TYPEDEF
)
1395 type
= ada_typedef_target_type (type
);
1398 && (type
->code () == TYPE_CODE_PTR
1399 || type
->code () == TYPE_CODE_REF
))
1400 return ada_check_typedef (TYPE_TARGET_TYPE (type
));
1405 /* True iff TYPE indicates a "thin" array pointer type. */
1408 is_thin_pntr (struct type
*type
)
1411 is_suffix (ada_type_name (desc_base_type (type
)), "___XUT")
1412 || is_suffix (ada_type_name (desc_base_type (type
)), "___XUT___XVE");
1415 /* The descriptor type for thin pointer type TYPE. */
1417 static struct type
*
1418 thin_descriptor_type (struct type
*type
)
1420 struct type
*base_type
= desc_base_type (type
);
1422 if (base_type
== NULL
)
1424 if (is_suffix (ada_type_name (base_type
), "___XVE"))
1428 struct type
*alt_type
= ada_find_parallel_type (base_type
, "___XVE");
1430 if (alt_type
== NULL
)
1437 /* A pointer to the array data for thin-pointer value VAL. */
1439 static struct value
*
1440 thin_data_pntr (struct value
*val
)
1442 struct type
*type
= ada_check_typedef (value_type (val
));
1443 struct type
*data_type
= desc_data_target_type (thin_descriptor_type (type
));
1445 data_type
= lookup_pointer_type (data_type
);
1447 if (type
->code () == TYPE_CODE_PTR
)
1448 return value_cast (data_type
, value_copy (val
));
1450 return value_from_longest (data_type
, value_address (val
));
1453 /* True iff TYPE indicates a "thick" array pointer type. */
1456 is_thick_pntr (struct type
*type
)
1458 type
= desc_base_type (type
);
1459 return (type
!= NULL
&& type
->code () == TYPE_CODE_STRUCT
1460 && lookup_struct_elt_type (type
, "P_BOUNDS", 1) != NULL
);
1463 /* If TYPE is the type of an array descriptor (fat or thin pointer) or a
1464 pointer to one, the type of its bounds data; otherwise, NULL. */
1466 static struct type
*
1467 desc_bounds_type (struct type
*type
)
1471 type
= desc_base_type (type
);
1475 else if (is_thin_pntr (type
))
1477 type
= thin_descriptor_type (type
);
1480 r
= lookup_struct_elt_type (type
, "BOUNDS", 1);
1482 return ada_check_typedef (r
);
1484 else if (type
->code () == TYPE_CODE_STRUCT
)
1486 r
= lookup_struct_elt_type (type
, "P_BOUNDS", 1);
1488 return ada_check_typedef (TYPE_TARGET_TYPE (ada_check_typedef (r
)));
1493 /* If ARR is an array descriptor (fat or thin pointer), or pointer to
1494 one, a pointer to its bounds data. Otherwise NULL. */
1496 static struct value
*
1497 desc_bounds (struct value
*arr
)
1499 struct type
*type
= ada_check_typedef (value_type (arr
));
1501 if (is_thin_pntr (type
))
1503 struct type
*bounds_type
=
1504 desc_bounds_type (thin_descriptor_type (type
));
1507 if (bounds_type
== NULL
)
1508 error (_("Bad GNAT array descriptor"));
1510 /* NOTE: The following calculation is not really kosher, but
1511 since desc_type is an XVE-encoded type (and shouldn't be),
1512 the correct calculation is a real pain. FIXME (and fix GCC). */
1513 if (type
->code () == TYPE_CODE_PTR
)
1514 addr
= value_as_long (arr
);
1516 addr
= value_address (arr
);
1519 value_from_longest (lookup_pointer_type (bounds_type
),
1520 addr
- TYPE_LENGTH (bounds_type
));
1523 else if (is_thick_pntr (type
))
1525 struct value
*p_bounds
= value_struct_elt (&arr
, NULL
, "P_BOUNDS", NULL
,
1526 _("Bad GNAT array descriptor"));
1527 struct type
*p_bounds_type
= value_type (p_bounds
);
1530 && p_bounds_type
->code () == TYPE_CODE_PTR
)
1532 struct type
*target_type
= TYPE_TARGET_TYPE (p_bounds_type
);
1534 if (target_type
->is_stub ())
1535 p_bounds
= value_cast (lookup_pointer_type
1536 (ada_check_typedef (target_type
)),
1540 error (_("Bad GNAT array descriptor"));
1548 /* If TYPE is the type of an array-descriptor (fat pointer), the bit
1549 position of the field containing the address of the bounds data. */
1552 fat_pntr_bounds_bitpos (struct type
*type
)
1554 return TYPE_FIELD_BITPOS (desc_base_type (type
), 1);
1557 /* If TYPE is the type of an array-descriptor (fat pointer), the bit
1558 size of the field containing the address of the bounds data. */
1561 fat_pntr_bounds_bitsize (struct type
*type
)
1563 type
= desc_base_type (type
);
1565 if (TYPE_FIELD_BITSIZE (type
, 1) > 0)
1566 return TYPE_FIELD_BITSIZE (type
, 1);
1568 return 8 * TYPE_LENGTH (ada_check_typedef (type
->field (1).type ()));
1571 /* If TYPE is the type of an array descriptor (fat or thin pointer) or a
1572 pointer to one, the type of its array data (a array-with-no-bounds type);
1573 otherwise, NULL. Use ada_type_of_array to get an array type with bounds
1576 static struct type
*
1577 desc_data_target_type (struct type
*type
)
1579 type
= desc_base_type (type
);
1581 /* NOTE: The following is bogus; see comment in desc_bounds. */
1582 if (is_thin_pntr (type
))
1583 return desc_base_type (thin_descriptor_type (type
)->field (1).type ());
1584 else if (is_thick_pntr (type
))
1586 struct type
*data_type
= lookup_struct_elt_type (type
, "P_ARRAY", 1);
1589 && ada_check_typedef (data_type
)->code () == TYPE_CODE_PTR
)
1590 return ada_check_typedef (TYPE_TARGET_TYPE (data_type
));
1596 /* If ARR is an array descriptor (fat or thin pointer), a pointer to
1599 static struct value
*
1600 desc_data (struct value
*arr
)
1602 struct type
*type
= value_type (arr
);
1604 if (is_thin_pntr (type
))
1605 return thin_data_pntr (arr
);
1606 else if (is_thick_pntr (type
))
1607 return value_struct_elt (&arr
, NULL
, "P_ARRAY", NULL
,
1608 _("Bad GNAT array descriptor"));
1614 /* If TYPE is the type of an array-descriptor (fat pointer), the bit
1615 position of the field containing the address of the data. */
1618 fat_pntr_data_bitpos (struct type
*type
)
1620 return TYPE_FIELD_BITPOS (desc_base_type (type
), 0);
1623 /* If TYPE is the type of an array-descriptor (fat pointer), the bit
1624 size of the field containing the address of the data. */
1627 fat_pntr_data_bitsize (struct type
*type
)
1629 type
= desc_base_type (type
);
1631 if (TYPE_FIELD_BITSIZE (type
, 0) > 0)
1632 return TYPE_FIELD_BITSIZE (type
, 0);
1634 return TARGET_CHAR_BIT
* TYPE_LENGTH (type
->field (0).type ());
1637 /* If BOUNDS is an array-bounds structure (or pointer to one), return
1638 the Ith lower bound stored in it, if WHICH is 0, and the Ith upper
1639 bound, if WHICH is 1. The first bound is I=1. */
1641 static struct value
*
1642 desc_one_bound (struct value
*bounds
, int i
, int which
)
1644 char bound_name
[20];
1645 xsnprintf (bound_name
, sizeof (bound_name
), "%cB%d",
1646 which
? 'U' : 'L', i
- 1);
1647 return value_struct_elt (&bounds
, NULL
, bound_name
, NULL
,
1648 _("Bad GNAT array descriptor bounds"));
1651 /* If BOUNDS is an array-bounds structure type, return the bit position
1652 of the Ith lower bound stored in it, if WHICH is 0, and the Ith upper
1653 bound, if WHICH is 1. The first bound is I=1. */
1656 desc_bound_bitpos (struct type
*type
, int i
, int which
)
1658 return TYPE_FIELD_BITPOS (desc_base_type (type
), 2 * i
+ which
- 2);
1661 /* If BOUNDS is an array-bounds structure type, return the bit field size
1662 of the Ith lower bound stored in it, if WHICH is 0, and the Ith upper
1663 bound, if WHICH is 1. The first bound is I=1. */
1666 desc_bound_bitsize (struct type
*type
, int i
, int which
)
1668 type
= desc_base_type (type
);
1670 if (TYPE_FIELD_BITSIZE (type
, 2 * i
+ which
- 2) > 0)
1671 return TYPE_FIELD_BITSIZE (type
, 2 * i
+ which
- 2);
1673 return 8 * TYPE_LENGTH (type
->field (2 * i
+ which
- 2).type ());
1676 /* If TYPE is the type of an array-bounds structure, the type of its
1677 Ith bound (numbering from 1). Otherwise, NULL. */
1679 static struct type
*
1680 desc_index_type (struct type
*type
, int i
)
1682 type
= desc_base_type (type
);
1684 if (type
->code () == TYPE_CODE_STRUCT
)
1686 char bound_name
[20];
1687 xsnprintf (bound_name
, sizeof (bound_name
), "LB%d", i
- 1);
1688 return lookup_struct_elt_type (type
, bound_name
, 1);
1694 /* The number of index positions in the array-bounds type TYPE.
1695 Return 0 if TYPE is NULL. */
1698 desc_arity (struct type
*type
)
1700 type
= desc_base_type (type
);
1703 return type
->num_fields () / 2;
1707 /* Non-zero iff TYPE is a simple array type (not a pointer to one) or
1708 an array descriptor type (representing an unconstrained array
1712 ada_is_direct_array_type (struct type
*type
)
1716 type
= ada_check_typedef (type
);
1717 return (type
->code () == TYPE_CODE_ARRAY
1718 || ada_is_array_descriptor_type (type
));
1721 /* Non-zero iff TYPE represents any kind of array in Ada, or a pointer
1725 ada_is_array_type (struct type
*type
)
1728 && (type
->code () == TYPE_CODE_PTR
1729 || type
->code () == TYPE_CODE_REF
))
1730 type
= TYPE_TARGET_TYPE (type
);
1731 return ada_is_direct_array_type (type
);
1734 /* Non-zero iff TYPE is a simple array type or pointer to one. */
1737 ada_is_simple_array_type (struct type
*type
)
1741 type
= ada_check_typedef (type
);
1742 return (type
->code () == TYPE_CODE_ARRAY
1743 || (type
->code () == TYPE_CODE_PTR
1744 && (ada_check_typedef (TYPE_TARGET_TYPE (type
))->code ()
1745 == TYPE_CODE_ARRAY
)));
1748 /* Non-zero iff TYPE belongs to a GNAT array descriptor. */
1751 ada_is_array_descriptor_type (struct type
*type
)
1753 struct type
*data_type
= desc_data_target_type (type
);
1757 type
= ada_check_typedef (type
);
1758 return (data_type
!= NULL
1759 && data_type
->code () == TYPE_CODE_ARRAY
1760 && desc_arity (desc_bounds_type (type
)) > 0);
1763 /* Non-zero iff type is a partially mal-formed GNAT array
1764 descriptor. FIXME: This is to compensate for some problems with
1765 debugging output from GNAT. Re-examine periodically to see if it
1769 ada_is_bogus_array_descriptor (struct type
*type
)
1773 && type
->code () == TYPE_CODE_STRUCT
1774 && (lookup_struct_elt_type (type
, "P_BOUNDS", 1) != NULL
1775 || lookup_struct_elt_type (type
, "P_ARRAY", 1) != NULL
)
1776 && !ada_is_array_descriptor_type (type
);
1780 /* If ARR has a record type in the form of a standard GNAT array descriptor,
1781 (fat pointer) returns the type of the array data described---specifically,
1782 a pointer-to-array type. If BOUNDS is non-zero, the bounds data are filled
1783 in from the descriptor; otherwise, they are left unspecified. If
1784 the ARR denotes a null array descriptor and BOUNDS is non-zero,
1785 returns NULL. The result is simply the type of ARR if ARR is not
1788 static struct type
*
1789 ada_type_of_array (struct value
*arr
, int bounds
)
1791 if (ada_is_constrained_packed_array_type (value_type (arr
)))
1792 return decode_constrained_packed_array_type (value_type (arr
));
1794 if (!ada_is_array_descriptor_type (value_type (arr
)))
1795 return value_type (arr
);
1799 struct type
*array_type
=
1800 ada_check_typedef (desc_data_target_type (value_type (arr
)));
1802 if (ada_is_unconstrained_packed_array_type (value_type (arr
)))
1803 TYPE_FIELD_BITSIZE (array_type
, 0) =
1804 decode_packed_array_bitsize (value_type (arr
));
1810 struct type
*elt_type
;
1812 struct value
*descriptor
;
1814 elt_type
= ada_array_element_type (value_type (arr
), -1);
1815 arity
= ada_array_arity (value_type (arr
));
1817 if (elt_type
== NULL
|| arity
== 0)
1818 return ada_check_typedef (value_type (arr
));
1820 descriptor
= desc_bounds (arr
);
1821 if (value_as_long (descriptor
) == 0)
1825 struct type
*range_type
= alloc_type_copy (value_type (arr
));
1826 struct type
*array_type
= alloc_type_copy (value_type (arr
));
1827 struct value
*low
= desc_one_bound (descriptor
, arity
, 0);
1828 struct value
*high
= desc_one_bound (descriptor
, arity
, 1);
1831 create_static_range_type (range_type
, value_type (low
),
1832 longest_to_int (value_as_long (low
)),
1833 longest_to_int (value_as_long (high
)));
1834 elt_type
= create_array_type (array_type
, elt_type
, range_type
);
1836 if (ada_is_unconstrained_packed_array_type (value_type (arr
)))
1838 /* We need to store the element packed bitsize, as well as
1839 recompute the array size, because it was previously
1840 computed based on the unpacked element size. */
1841 LONGEST lo
= value_as_long (low
);
1842 LONGEST hi
= value_as_long (high
);
1844 TYPE_FIELD_BITSIZE (elt_type
, 0) =
1845 decode_packed_array_bitsize (value_type (arr
));
1846 /* If the array has no element, then the size is already
1847 zero, and does not need to be recomputed. */
1851 (hi
- lo
+ 1) * TYPE_FIELD_BITSIZE (elt_type
, 0);
1853 TYPE_LENGTH (array_type
) = (array_bitsize
+ 7) / 8;
1858 return lookup_pointer_type (elt_type
);
1862 /* If ARR does not represent an array, returns ARR unchanged.
1863 Otherwise, returns either a standard GDB array with bounds set
1864 appropriately or, if ARR is a non-null fat pointer, a pointer to a standard
1865 GDB array. Returns NULL if ARR is a null fat pointer. */
1868 ada_coerce_to_simple_array_ptr (struct value
*arr
)
1870 if (ada_is_array_descriptor_type (value_type (arr
)))
1872 struct type
*arrType
= ada_type_of_array (arr
, 1);
1874 if (arrType
== NULL
)
1876 return value_cast (arrType
, value_copy (desc_data (arr
)));
1878 else if (ada_is_constrained_packed_array_type (value_type (arr
)))
1879 return decode_constrained_packed_array (arr
);
1884 /* If ARR does not represent an array, returns ARR unchanged.
1885 Otherwise, returns a standard GDB array describing ARR (which may
1886 be ARR itself if it already is in the proper form). */
1889 ada_coerce_to_simple_array (struct value
*arr
)
1891 if (ada_is_array_descriptor_type (value_type (arr
)))
1893 struct value
*arrVal
= ada_coerce_to_simple_array_ptr (arr
);
1896 error (_("Bounds unavailable for null array pointer."));
1897 ada_ensure_varsize_limit (TYPE_TARGET_TYPE (value_type (arrVal
)));
1898 return value_ind (arrVal
);
1900 else if (ada_is_constrained_packed_array_type (value_type (arr
)))
1901 return decode_constrained_packed_array (arr
);
1906 /* If TYPE represents a GNAT array type, return it translated to an
1907 ordinary GDB array type (possibly with BITSIZE fields indicating
1908 packing). For other types, is the identity. */
1911 ada_coerce_to_simple_array_type (struct type
*type
)
1913 if (ada_is_constrained_packed_array_type (type
))
1914 return decode_constrained_packed_array_type (type
);
1916 if (ada_is_array_descriptor_type (type
))
1917 return ada_check_typedef (desc_data_target_type (type
));
1922 /* Non-zero iff TYPE represents a standard GNAT packed-array type. */
1925 ada_is_gnat_encoded_packed_array_type (struct type
*type
)
1929 type
= desc_base_type (type
);
1930 type
= ada_check_typedef (type
);
1932 ada_type_name (type
) != NULL
1933 && strstr (ada_type_name (type
), "___XP") != NULL
;
1936 /* Non-zero iff TYPE represents a standard GNAT constrained
1937 packed-array type. */
1940 ada_is_constrained_packed_array_type (struct type
*type
)
1942 return ada_is_gnat_encoded_packed_array_type (type
)
1943 && !ada_is_array_descriptor_type (type
);
1946 /* Non-zero iff TYPE represents an array descriptor for a
1947 unconstrained packed-array type. */
1950 ada_is_unconstrained_packed_array_type (struct type
*type
)
1952 if (!ada_is_array_descriptor_type (type
))
1955 if (ada_is_gnat_encoded_packed_array_type (type
))
1958 /* If we saw GNAT encodings, then the above code is sufficient.
1959 However, with minimal encodings, we will just have a thick
1961 if (is_thick_pntr (type
))
1963 type
= desc_base_type (type
);
1964 /* The structure's first field is a pointer to an array, so this
1965 fetches the array type. */
1966 type
= TYPE_TARGET_TYPE (type
->field (0).type ());
1967 /* Now we can see if the array elements are packed. */
1968 return TYPE_FIELD_BITSIZE (type
, 0) > 0;
1974 /* Return true if TYPE is a (Gnat-encoded) constrained packed array
1975 type, or if it is an ordinary (non-Gnat-encoded) packed array. */
1978 ada_is_any_packed_array_type (struct type
*type
)
1980 return (ada_is_constrained_packed_array_type (type
)
1981 || (type
->code () == TYPE_CODE_ARRAY
1982 && TYPE_FIELD_BITSIZE (type
, 0) % 8 != 0));
1985 /* Given that TYPE encodes a packed array type (constrained or unconstrained),
1986 return the size of its elements in bits. */
1989 decode_packed_array_bitsize (struct type
*type
)
1991 const char *raw_name
;
1995 /* Access to arrays implemented as fat pointers are encoded as a typedef
1996 of the fat pointer type. We need the name of the fat pointer type
1997 to do the decoding, so strip the typedef layer. */
1998 if (type
->code () == TYPE_CODE_TYPEDEF
)
1999 type
= ada_typedef_target_type (type
);
2001 raw_name
= ada_type_name (ada_check_typedef (type
));
2003 raw_name
= ada_type_name (desc_base_type (type
));
2008 tail
= strstr (raw_name
, "___XP");
2009 if (tail
== nullptr)
2011 gdb_assert (is_thick_pntr (type
));
2012 /* The structure's first field is a pointer to an array, so this
2013 fetches the array type. */
2014 type
= TYPE_TARGET_TYPE (type
->field (0).type ());
2015 /* Now we can see if the array elements are packed. */
2016 return TYPE_FIELD_BITSIZE (type
, 0);
2019 if (sscanf (tail
+ sizeof ("___XP") - 1, "%ld", &bits
) != 1)
2022 (_("could not understand bit size information on packed array"));
2029 /* Given that TYPE is a standard GDB array type with all bounds filled
2030 in, and that the element size of its ultimate scalar constituents
2031 (that is, either its elements, or, if it is an array of arrays, its
2032 elements' elements, etc.) is *ELT_BITS, return an identical type,
2033 but with the bit sizes of its elements (and those of any
2034 constituent arrays) recorded in the BITSIZE components of its
2035 TYPE_FIELD_BITSIZE values, and with *ELT_BITS set to its total size
2038 Note that, for arrays whose index type has an XA encoding where
2039 a bound references a record discriminant, getting that discriminant,
2040 and therefore the actual value of that bound, is not possible
2041 because none of the given parameters gives us access to the record.
2042 This function assumes that it is OK in the context where it is being
2043 used to return an array whose bounds are still dynamic and where
2044 the length is arbitrary. */
2046 static struct type
*
2047 constrained_packed_array_type (struct type
*type
, long *elt_bits
)
2049 struct type
*new_elt_type
;
2050 struct type
*new_type
;
2051 struct type
*index_type_desc
;
2052 struct type
*index_type
;
2053 LONGEST low_bound
, high_bound
;
2055 type
= ada_check_typedef (type
);
2056 if (type
->code () != TYPE_CODE_ARRAY
)
2059 index_type_desc
= ada_find_parallel_type (type
, "___XA");
2060 if (index_type_desc
)
2061 index_type
= to_fixed_range_type (index_type_desc
->field (0).type (),
2064 index_type
= type
->index_type ();
2066 new_type
= alloc_type_copy (type
);
2068 constrained_packed_array_type (ada_check_typedef (TYPE_TARGET_TYPE (type
)),
2070 create_array_type (new_type
, new_elt_type
, index_type
);
2071 TYPE_FIELD_BITSIZE (new_type
, 0) = *elt_bits
;
2072 new_type
->set_name (ada_type_name (type
));
2074 if ((check_typedef (index_type
)->code () == TYPE_CODE_RANGE
2075 && is_dynamic_type (check_typedef (index_type
)))
2076 || !get_discrete_bounds (index_type
, &low_bound
, &high_bound
))
2077 low_bound
= high_bound
= 0;
2078 if (high_bound
< low_bound
)
2079 *elt_bits
= TYPE_LENGTH (new_type
) = 0;
2082 *elt_bits
*= (high_bound
- low_bound
+ 1);
2083 TYPE_LENGTH (new_type
) =
2084 (*elt_bits
+ HOST_CHAR_BIT
- 1) / HOST_CHAR_BIT
;
2087 new_type
->set_is_fixed_instance (true);
2091 /* The array type encoded by TYPE, where
2092 ada_is_constrained_packed_array_type (TYPE). */
2094 static struct type
*
2095 decode_constrained_packed_array_type (struct type
*type
)
2097 const char *raw_name
= ada_type_name (ada_check_typedef (type
));
2100 struct type
*shadow_type
;
2104 raw_name
= ada_type_name (desc_base_type (type
));
2109 name
= (char *) alloca (strlen (raw_name
) + 1);
2110 tail
= strstr (raw_name
, "___XP");
2111 type
= desc_base_type (type
);
2113 memcpy (name
, raw_name
, tail
- raw_name
);
2114 name
[tail
- raw_name
] = '\000';
2116 shadow_type
= ada_find_parallel_type_with_name (type
, name
);
2118 if (shadow_type
== NULL
)
2120 lim_warning (_("could not find bounds information on packed array"));
2123 shadow_type
= check_typedef (shadow_type
);
2125 if (shadow_type
->code () != TYPE_CODE_ARRAY
)
2127 lim_warning (_("could not understand bounds "
2128 "information on packed array"));
2132 bits
= decode_packed_array_bitsize (type
);
2133 return constrained_packed_array_type (shadow_type
, &bits
);
2136 /* Helper function for decode_constrained_packed_array. Set the field
2137 bitsize on a series of packed arrays. Returns the number of
2138 elements in TYPE. */
2141 recursively_update_array_bitsize (struct type
*type
)
2143 gdb_assert (type
->code () == TYPE_CODE_ARRAY
);
2146 if (!get_discrete_bounds (type
->index_type (), &low
, &high
)
2149 LONGEST our_len
= high
- low
+ 1;
2151 struct type
*elt_type
= TYPE_TARGET_TYPE (type
);
2152 if (elt_type
->code () == TYPE_CODE_ARRAY
)
2154 LONGEST elt_len
= recursively_update_array_bitsize (elt_type
);
2155 LONGEST elt_bitsize
= elt_len
* TYPE_FIELD_BITSIZE (elt_type
, 0);
2156 TYPE_FIELD_BITSIZE (type
, 0) = elt_bitsize
;
2158 TYPE_LENGTH (type
) = ((our_len
* elt_bitsize
+ HOST_CHAR_BIT
- 1)
2165 /* Given that ARR is a struct value *indicating a GNAT constrained packed
2166 array, returns a simple array that denotes that array. Its type is a
2167 standard GDB array type except that the BITSIZEs of the array
2168 target types are set to the number of bits in each element, and the
2169 type length is set appropriately. */
2171 static struct value
*
2172 decode_constrained_packed_array (struct value
*arr
)
2176 /* If our value is a pointer, then dereference it. Likewise if
2177 the value is a reference. Make sure that this operation does not
2178 cause the target type to be fixed, as this would indirectly cause
2179 this array to be decoded. The rest of the routine assumes that
2180 the array hasn't been decoded yet, so we use the basic "coerce_ref"
2181 and "value_ind" routines to perform the dereferencing, as opposed
2182 to using "ada_coerce_ref" or "ada_value_ind". */
2183 arr
= coerce_ref (arr
);
2184 if (ada_check_typedef (value_type (arr
))->code () == TYPE_CODE_PTR
)
2185 arr
= value_ind (arr
);
2187 type
= decode_constrained_packed_array_type (value_type (arr
));
2190 error (_("can't unpack array"));
2194 /* Decoding the packed array type could not correctly set the field
2195 bitsizes for any dimension except the innermost, because the
2196 bounds may be variable and were not passed to that function. So,
2197 we further resolve the array bounds here and then update the
2199 const gdb_byte
*valaddr
= value_contents_for_printing (arr
);
2200 CORE_ADDR address
= value_address (arr
);
2201 gdb::array_view
<const gdb_byte
> view
2202 = gdb::make_array_view (valaddr
, TYPE_LENGTH (type
));
2203 type
= resolve_dynamic_type (type
, view
, address
);
2204 recursively_update_array_bitsize (type
);
2206 if (type_byte_order (value_type (arr
)) == BFD_ENDIAN_BIG
2207 && ada_is_modular_type (value_type (arr
)))
2209 /* This is a (right-justified) modular type representing a packed
2210 array with no wrapper. In order to interpret the value through
2211 the (left-justified) packed array type we just built, we must
2212 first left-justify it. */
2213 int bit_size
, bit_pos
;
2216 mod
= ada_modulus (value_type (arr
)) - 1;
2223 bit_pos
= HOST_CHAR_BIT
* TYPE_LENGTH (value_type (arr
)) - bit_size
;
2224 arr
= ada_value_primitive_packed_val (arr
, NULL
,
2225 bit_pos
/ HOST_CHAR_BIT
,
2226 bit_pos
% HOST_CHAR_BIT
,
2231 return coerce_unspec_val_to_type (arr
, type
);
2235 /* The value of the element of packed array ARR at the ARITY indices
2236 given in IND. ARR must be a simple array. */
2238 static struct value
*
2239 value_subscript_packed (struct value
*arr
, int arity
, struct value
**ind
)
2242 int bits
, elt_off
, bit_off
;
2243 long elt_total_bit_offset
;
2244 struct type
*elt_type
;
2248 elt_total_bit_offset
= 0;
2249 elt_type
= ada_check_typedef (value_type (arr
));
2250 for (i
= 0; i
< arity
; i
+= 1)
2252 if (elt_type
->code () != TYPE_CODE_ARRAY
2253 || TYPE_FIELD_BITSIZE (elt_type
, 0) == 0)
2255 (_("attempt to do packed indexing of "
2256 "something other than a packed array"));
2259 struct type
*range_type
= elt_type
->index_type ();
2260 LONGEST lowerbound
, upperbound
;
2263 if (!get_discrete_bounds (range_type
, &lowerbound
, &upperbound
))
2265 lim_warning (_("don't know bounds of array"));
2266 lowerbound
= upperbound
= 0;
2269 idx
= pos_atr (ind
[i
]);
2270 if (idx
< lowerbound
|| idx
> upperbound
)
2271 lim_warning (_("packed array index %ld out of bounds"),
2273 bits
= TYPE_FIELD_BITSIZE (elt_type
, 0);
2274 elt_total_bit_offset
+= (idx
- lowerbound
) * bits
;
2275 elt_type
= ada_check_typedef (TYPE_TARGET_TYPE (elt_type
));
2278 elt_off
= elt_total_bit_offset
/ HOST_CHAR_BIT
;
2279 bit_off
= elt_total_bit_offset
% HOST_CHAR_BIT
;
2281 v
= ada_value_primitive_packed_val (arr
, NULL
, elt_off
, bit_off
,
2286 /* Non-zero iff TYPE includes negative integer values. */
2289 has_negatives (struct type
*type
)
2291 switch (type
->code ())
2296 return !type
->is_unsigned ();
2297 case TYPE_CODE_RANGE
:
2298 return type
->bounds ()->low
.const_val () - type
->bounds ()->bias
< 0;
2302 /* With SRC being a buffer containing BIT_SIZE bits of data at BIT_OFFSET,
2303 unpack that data into UNPACKED. UNPACKED_LEN is the size in bytes of
2304 the unpacked buffer.
2306 The size of the unpacked buffer (UNPACKED_LEN) is expected to be large
2307 enough to contain at least BIT_OFFSET bits. If not, an error is raised.
2309 IS_BIG_ENDIAN is nonzero if the data is stored in big endian mode,
2312 IS_SIGNED_TYPE is nonzero if the data corresponds to a signed type.
2314 IS_SCALAR is nonzero if the data corresponds to a signed type. */
2317 ada_unpack_from_contents (const gdb_byte
*src
, int bit_offset
, int bit_size
,
2318 gdb_byte
*unpacked
, int unpacked_len
,
2319 int is_big_endian
, int is_signed_type
,
2322 int src_len
= (bit_size
+ bit_offset
+ HOST_CHAR_BIT
- 1) / 8;
2323 int src_idx
; /* Index into the source area */
2324 int src_bytes_left
; /* Number of source bytes left to process. */
2325 int srcBitsLeft
; /* Number of source bits left to move */
2326 int unusedLS
; /* Number of bits in next significant
2327 byte of source that are unused */
2329 int unpacked_idx
; /* Index into the unpacked buffer */
2330 int unpacked_bytes_left
; /* Number of bytes left to set in unpacked. */
2332 unsigned long accum
; /* Staging area for bits being transferred */
2333 int accumSize
; /* Number of meaningful bits in accum */
2336 /* Transmit bytes from least to most significant; delta is the direction
2337 the indices move. */
2338 int delta
= is_big_endian
? -1 : 1;
2340 /* Make sure that unpacked is large enough to receive the BIT_SIZE
2342 if ((bit_size
+ HOST_CHAR_BIT
- 1) / HOST_CHAR_BIT
> unpacked_len
)
2343 error (_("Cannot unpack %d bits into buffer of %d bytes"),
2344 bit_size
, unpacked_len
);
2346 srcBitsLeft
= bit_size
;
2347 src_bytes_left
= src_len
;
2348 unpacked_bytes_left
= unpacked_len
;
2353 src_idx
= src_len
- 1;
2355 && ((src
[0] << bit_offset
) & (1 << (HOST_CHAR_BIT
- 1))))
2359 (HOST_CHAR_BIT
- (bit_size
+ bit_offset
) % HOST_CHAR_BIT
)
2365 unpacked_idx
= unpacked_len
- 1;
2369 /* Non-scalar values must be aligned at a byte boundary... */
2371 (HOST_CHAR_BIT
- bit_size
% HOST_CHAR_BIT
) % HOST_CHAR_BIT
;
2372 /* ... And are placed at the beginning (most-significant) bytes
2374 unpacked_idx
= (bit_size
+ HOST_CHAR_BIT
- 1) / HOST_CHAR_BIT
- 1;
2375 unpacked_bytes_left
= unpacked_idx
+ 1;
2380 int sign_bit_offset
= (bit_size
+ bit_offset
- 1) % 8;
2382 src_idx
= unpacked_idx
= 0;
2383 unusedLS
= bit_offset
;
2386 if (is_signed_type
&& (src
[src_len
- 1] & (1 << sign_bit_offset
)))
2391 while (src_bytes_left
> 0)
2393 /* Mask for removing bits of the next source byte that are not
2394 part of the value. */
2395 unsigned int unusedMSMask
=
2396 (1 << (srcBitsLeft
>= HOST_CHAR_BIT
? HOST_CHAR_BIT
: srcBitsLeft
)) -
2398 /* Sign-extend bits for this byte. */
2399 unsigned int signMask
= sign
& ~unusedMSMask
;
2402 (((src
[src_idx
] >> unusedLS
) & unusedMSMask
) | signMask
) << accumSize
;
2403 accumSize
+= HOST_CHAR_BIT
- unusedLS
;
2404 if (accumSize
>= HOST_CHAR_BIT
)
2406 unpacked
[unpacked_idx
] = accum
& ~(~0UL << HOST_CHAR_BIT
);
2407 accumSize
-= HOST_CHAR_BIT
;
2408 accum
>>= HOST_CHAR_BIT
;
2409 unpacked_bytes_left
-= 1;
2410 unpacked_idx
+= delta
;
2412 srcBitsLeft
-= HOST_CHAR_BIT
- unusedLS
;
2414 src_bytes_left
-= 1;
2417 while (unpacked_bytes_left
> 0)
2419 accum
|= sign
<< accumSize
;
2420 unpacked
[unpacked_idx
] = accum
& ~(~0UL << HOST_CHAR_BIT
);
2421 accumSize
-= HOST_CHAR_BIT
;
2424 accum
>>= HOST_CHAR_BIT
;
2425 unpacked_bytes_left
-= 1;
2426 unpacked_idx
+= delta
;
2430 /* Create a new value of type TYPE from the contents of OBJ starting
2431 at byte OFFSET, and bit offset BIT_OFFSET within that byte,
2432 proceeding for BIT_SIZE bits. If OBJ is an lval in memory, then
2433 assigning through the result will set the field fetched from.
2434 VALADDR is ignored unless OBJ is NULL, in which case,
2435 VALADDR+OFFSET must address the start of storage containing the
2436 packed value. The value returned in this case is never an lval.
2437 Assumes 0 <= BIT_OFFSET < HOST_CHAR_BIT. */
2440 ada_value_primitive_packed_val (struct value
*obj
, const gdb_byte
*valaddr
,
2441 long offset
, int bit_offset
, int bit_size
,
2445 const gdb_byte
*src
; /* First byte containing data to unpack */
2447 const int is_scalar
= is_scalar_type (type
);
2448 const int is_big_endian
= type_byte_order (type
) == BFD_ENDIAN_BIG
;
2449 gdb::byte_vector staging
;
2451 type
= ada_check_typedef (type
);
2454 src
= valaddr
+ offset
;
2456 src
= value_contents (obj
) + offset
;
2458 if (is_dynamic_type (type
))
2460 /* The length of TYPE might by dynamic, so we need to resolve
2461 TYPE in order to know its actual size, which we then use
2462 to create the contents buffer of the value we return.
2463 The difficulty is that the data containing our object is
2464 packed, and therefore maybe not at a byte boundary. So, what
2465 we do, is unpack the data into a byte-aligned buffer, and then
2466 use that buffer as our object's value for resolving the type. */
2467 int staging_len
= (bit_size
+ HOST_CHAR_BIT
- 1) / HOST_CHAR_BIT
;
2468 staging
.resize (staging_len
);
2470 ada_unpack_from_contents (src
, bit_offset
, bit_size
,
2471 staging
.data (), staging
.size (),
2472 is_big_endian
, has_negatives (type
),
2474 type
= resolve_dynamic_type (type
, staging
, 0);
2475 if (TYPE_LENGTH (type
) < (bit_size
+ HOST_CHAR_BIT
- 1) / HOST_CHAR_BIT
)
2477 /* This happens when the length of the object is dynamic,
2478 and is actually smaller than the space reserved for it.
2479 For instance, in an array of variant records, the bit_size
2480 we're given is the array stride, which is constant and
2481 normally equal to the maximum size of its element.
2482 But, in reality, each element only actually spans a portion
2484 bit_size
= TYPE_LENGTH (type
) * HOST_CHAR_BIT
;
2490 v
= allocate_value (type
);
2491 src
= valaddr
+ offset
;
2493 else if (VALUE_LVAL (obj
) == lval_memory
&& value_lazy (obj
))
2495 int src_len
= (bit_size
+ bit_offset
+ HOST_CHAR_BIT
- 1) / 8;
2498 v
= value_at (type
, value_address (obj
) + offset
);
2499 buf
= (gdb_byte
*) alloca (src_len
);
2500 read_memory (value_address (v
), buf
, src_len
);
2505 v
= allocate_value (type
);
2506 src
= value_contents (obj
) + offset
;
2511 long new_offset
= offset
;
2513 set_value_component_location (v
, obj
);
2514 set_value_bitpos (v
, bit_offset
+ value_bitpos (obj
));
2515 set_value_bitsize (v
, bit_size
);
2516 if (value_bitpos (v
) >= HOST_CHAR_BIT
)
2519 set_value_bitpos (v
, value_bitpos (v
) - HOST_CHAR_BIT
);
2521 set_value_offset (v
, new_offset
);
2523 /* Also set the parent value. This is needed when trying to
2524 assign a new value (in inferior memory). */
2525 set_value_parent (v
, obj
);
2528 set_value_bitsize (v
, bit_size
);
2529 unpacked
= value_contents_writeable (v
);
2533 memset (unpacked
, 0, TYPE_LENGTH (type
));
2537 if (staging
.size () == TYPE_LENGTH (type
))
2539 /* Small short-cut: If we've unpacked the data into a buffer
2540 of the same size as TYPE's length, then we can reuse that,
2541 instead of doing the unpacking again. */
2542 memcpy (unpacked
, staging
.data (), staging
.size ());
2545 ada_unpack_from_contents (src
, bit_offset
, bit_size
,
2546 unpacked
, TYPE_LENGTH (type
),
2547 is_big_endian
, has_negatives (type
), is_scalar
);
2552 /* Store the contents of FROMVAL into the location of TOVAL.
2553 Return a new value with the location of TOVAL and contents of
2554 FROMVAL. Handles assignment into packed fields that have
2555 floating-point or non-scalar types. */
2557 static struct value
*
2558 ada_value_assign (struct value
*toval
, struct value
*fromval
)
2560 struct type
*type
= value_type (toval
);
2561 int bits
= value_bitsize (toval
);
2563 toval
= ada_coerce_ref (toval
);
2564 fromval
= ada_coerce_ref (fromval
);
2566 if (ada_is_direct_array_type (value_type (toval
)))
2567 toval
= ada_coerce_to_simple_array (toval
);
2568 if (ada_is_direct_array_type (value_type (fromval
)))
2569 fromval
= ada_coerce_to_simple_array (fromval
);
2571 if (!deprecated_value_modifiable (toval
))
2572 error (_("Left operand of assignment is not a modifiable lvalue."));
2574 if (VALUE_LVAL (toval
) == lval_memory
2576 && (type
->code () == TYPE_CODE_FLT
2577 || type
->code () == TYPE_CODE_STRUCT
))
2579 int len
= (value_bitpos (toval
)
2580 + bits
+ HOST_CHAR_BIT
- 1) / HOST_CHAR_BIT
;
2582 gdb_byte
*buffer
= (gdb_byte
*) alloca (len
);
2584 CORE_ADDR to_addr
= value_address (toval
);
2586 if (type
->code () == TYPE_CODE_FLT
)
2587 fromval
= value_cast (type
, fromval
);
2589 read_memory (to_addr
, buffer
, len
);
2590 from_size
= value_bitsize (fromval
);
2592 from_size
= TYPE_LENGTH (value_type (fromval
)) * TARGET_CHAR_BIT
;
2594 const int is_big_endian
= type_byte_order (type
) == BFD_ENDIAN_BIG
;
2595 ULONGEST from_offset
= 0;
2596 if (is_big_endian
&& is_scalar_type (value_type (fromval
)))
2597 from_offset
= from_size
- bits
;
2598 copy_bitwise (buffer
, value_bitpos (toval
),
2599 value_contents (fromval
), from_offset
,
2600 bits
, is_big_endian
);
2601 write_memory_with_notification (to_addr
, buffer
, len
);
2603 val
= value_copy (toval
);
2604 memcpy (value_contents_raw (val
), value_contents (fromval
),
2605 TYPE_LENGTH (type
));
2606 deprecated_set_value_type (val
, type
);
2611 return value_assign (toval
, fromval
);
2615 /* Given that COMPONENT is a memory lvalue that is part of the lvalue
2616 CONTAINER, assign the contents of VAL to COMPONENTS's place in
2617 CONTAINER. Modifies the VALUE_CONTENTS of CONTAINER only, not
2618 COMPONENT, and not the inferior's memory. The current contents
2619 of COMPONENT are ignored.
2621 Although not part of the initial design, this function also works
2622 when CONTAINER and COMPONENT are not_lval's: it works as if CONTAINER
2623 had a null address, and COMPONENT had an address which is equal to
2624 its offset inside CONTAINER. */
2627 value_assign_to_component (struct value
*container
, struct value
*component
,
2630 LONGEST offset_in_container
=
2631 (LONGEST
) (value_address (component
) - value_address (container
));
2632 int bit_offset_in_container
=
2633 value_bitpos (component
) - value_bitpos (container
);
2636 val
= value_cast (value_type (component
), val
);
2638 if (value_bitsize (component
) == 0)
2639 bits
= TARGET_CHAR_BIT
* TYPE_LENGTH (value_type (component
));
2641 bits
= value_bitsize (component
);
2643 if (type_byte_order (value_type (container
)) == BFD_ENDIAN_BIG
)
2647 if (is_scalar_type (check_typedef (value_type (component
))))
2649 = TYPE_LENGTH (value_type (component
)) * TARGET_CHAR_BIT
- bits
;
2652 copy_bitwise (value_contents_writeable (container
) + offset_in_container
,
2653 value_bitpos (container
) + bit_offset_in_container
,
2654 value_contents (val
), src_offset
, bits
, 1);
2657 copy_bitwise (value_contents_writeable (container
) + offset_in_container
,
2658 value_bitpos (container
) + bit_offset_in_container
,
2659 value_contents (val
), 0, bits
, 0);
2662 /* Determine if TYPE is an access to an unconstrained array. */
2665 ada_is_access_to_unconstrained_array (struct type
*type
)
2667 return (type
->code () == TYPE_CODE_TYPEDEF
2668 && is_thick_pntr (ada_typedef_target_type (type
)));
2671 /* The value of the element of array ARR at the ARITY indices given in IND.
2672 ARR may be either a simple array, GNAT array descriptor, or pointer
2676 ada_value_subscript (struct value
*arr
, int arity
, struct value
**ind
)
2680 struct type
*elt_type
;
2682 elt
= ada_coerce_to_simple_array (arr
);
2684 elt_type
= ada_check_typedef (value_type (elt
));
2685 if (elt_type
->code () == TYPE_CODE_ARRAY
2686 && TYPE_FIELD_BITSIZE (elt_type
, 0) > 0)
2687 return value_subscript_packed (elt
, arity
, ind
);
2689 for (k
= 0; k
< arity
; k
+= 1)
2691 struct type
*saved_elt_type
= TYPE_TARGET_TYPE (elt_type
);
2693 if (elt_type
->code () != TYPE_CODE_ARRAY
)
2694 error (_("too many subscripts (%d expected)"), k
);
2696 elt
= value_subscript (elt
, pos_atr (ind
[k
]));
2698 if (ada_is_access_to_unconstrained_array (saved_elt_type
)
2699 && value_type (elt
)->code () != TYPE_CODE_TYPEDEF
)
2701 /* The element is a typedef to an unconstrained array,
2702 except that the value_subscript call stripped the
2703 typedef layer. The typedef layer is GNAT's way to
2704 specify that the element is, at the source level, an
2705 access to the unconstrained array, rather than the
2706 unconstrained array. So, we need to restore that
2707 typedef layer, which we can do by forcing the element's
2708 type back to its original type. Otherwise, the returned
2709 value is going to be printed as the array, rather
2710 than as an access. Another symptom of the same issue
2711 would be that an expression trying to dereference the
2712 element would also be improperly rejected. */
2713 deprecated_set_value_type (elt
, saved_elt_type
);
2716 elt_type
= ada_check_typedef (value_type (elt
));
2722 /* Assuming ARR is a pointer to a GDB array, the value of the element
2723 of *ARR at the ARITY indices given in IND.
2724 Does not read the entire array into memory.
2726 Note: Unlike what one would expect, this function is used instead of
2727 ada_value_subscript for basically all non-packed array types. The reason
2728 for this is that a side effect of doing our own pointer arithmetics instead
2729 of relying on value_subscript is that there is no implicit typedef peeling.
2730 This is important for arrays of array accesses, where it allows us to
2731 preserve the fact that the array's element is an array access, where the
2732 access part os encoded in a typedef layer. */
2734 static struct value
*
2735 ada_value_ptr_subscript (struct value
*arr
, int arity
, struct value
**ind
)
2738 struct value
*array_ind
= ada_value_ind (arr
);
2740 = check_typedef (value_enclosing_type (array_ind
));
2742 if (type
->code () == TYPE_CODE_ARRAY
2743 && TYPE_FIELD_BITSIZE (type
, 0) > 0)
2744 return value_subscript_packed (array_ind
, arity
, ind
);
2746 for (k
= 0; k
< arity
; k
+= 1)
2750 if (type
->code () != TYPE_CODE_ARRAY
)
2751 error (_("too many subscripts (%d expected)"), k
);
2752 arr
= value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (type
)),
2754 get_discrete_bounds (type
->index_type (), &lwb
, &upb
);
2755 arr
= value_ptradd (arr
, pos_atr (ind
[k
]) - lwb
);
2756 type
= TYPE_TARGET_TYPE (type
);
2759 return value_ind (arr
);
2762 /* Given that ARRAY_PTR is a pointer or reference to an array of type TYPE (the
2763 actual type of ARRAY_PTR is ignored), returns the Ada slice of
2764 HIGH'Pos-LOW'Pos+1 elements starting at index LOW. The lower bound of
2765 this array is LOW, as per Ada rules. */
2766 static struct value
*
2767 ada_value_slice_from_ptr (struct value
*array_ptr
, struct type
*type
,
2770 struct type
*type0
= ada_check_typedef (type
);
2771 struct type
*base_index_type
= TYPE_TARGET_TYPE (type0
->index_type ());
2772 struct type
*index_type
2773 = create_static_range_type (NULL
, base_index_type
, low
, high
);
2774 struct type
*slice_type
= create_array_type_with_stride
2775 (NULL
, TYPE_TARGET_TYPE (type0
), index_type
,
2776 type0
->dyn_prop (DYN_PROP_BYTE_STRIDE
),
2777 TYPE_FIELD_BITSIZE (type0
, 0));
2778 int base_low
= ada_discrete_type_low_bound (type0
->index_type ());
2779 gdb::optional
<LONGEST
> base_low_pos
, low_pos
;
2782 low_pos
= discrete_position (base_index_type
, low
);
2783 base_low_pos
= discrete_position (base_index_type
, base_low
);
2785 if (!low_pos
.has_value () || !base_low_pos
.has_value ())
2787 warning (_("unable to get positions in slice, use bounds instead"));
2789 base_low_pos
= base_low
;
2792 ULONGEST stride
= TYPE_FIELD_BITSIZE (slice_type
, 0) / 8;
2794 stride
= TYPE_LENGTH (TYPE_TARGET_TYPE (type0
));
2796 base
= value_as_address (array_ptr
) + (*low_pos
- *base_low_pos
) * stride
;
2797 return value_at_lazy (slice_type
, base
);
2801 static struct value
*
2802 ada_value_slice (struct value
*array
, int low
, int high
)
2804 struct type
*type
= ada_check_typedef (value_type (array
));
2805 struct type
*base_index_type
= TYPE_TARGET_TYPE (type
->index_type ());
2806 struct type
*index_type
2807 = create_static_range_type (NULL
, type
->index_type (), low
, high
);
2808 struct type
*slice_type
= create_array_type_with_stride
2809 (NULL
, TYPE_TARGET_TYPE (type
), index_type
,
2810 type
->dyn_prop (DYN_PROP_BYTE_STRIDE
),
2811 TYPE_FIELD_BITSIZE (type
, 0));
2812 gdb::optional
<LONGEST
> low_pos
, high_pos
;
2815 low_pos
= discrete_position (base_index_type
, low
);
2816 high_pos
= discrete_position (base_index_type
, high
);
2818 if (!low_pos
.has_value () || !high_pos
.has_value ())
2820 warning (_("unable to get positions in slice, use bounds instead"));
2825 return value_cast (slice_type
,
2826 value_slice (array
, low
, *high_pos
- *low_pos
+ 1));
2829 /* If type is a record type in the form of a standard GNAT array
2830 descriptor, returns the number of dimensions for type. If arr is a
2831 simple array, returns the number of "array of"s that prefix its
2832 type designation. Otherwise, returns 0. */
2835 ada_array_arity (struct type
*type
)
2842 type
= desc_base_type (type
);
2845 if (type
->code () == TYPE_CODE_STRUCT
)
2846 return desc_arity (desc_bounds_type (type
));
2848 while (type
->code () == TYPE_CODE_ARRAY
)
2851 type
= ada_check_typedef (TYPE_TARGET_TYPE (type
));
2857 /* If TYPE is a record type in the form of a standard GNAT array
2858 descriptor or a simple array type, returns the element type for
2859 TYPE after indexing by NINDICES indices, or by all indices if
2860 NINDICES is -1. Otherwise, returns NULL. */
2863 ada_array_element_type (struct type
*type
, int nindices
)
2865 type
= desc_base_type (type
);
2867 if (type
->code () == TYPE_CODE_STRUCT
)
2870 struct type
*p_array_type
;
2872 p_array_type
= desc_data_target_type (type
);
2874 k
= ada_array_arity (type
);
2878 /* Initially p_array_type = elt_type(*)[]...(k times)...[]. */
2879 if (nindices
>= 0 && k
> nindices
)
2881 while (k
> 0 && p_array_type
!= NULL
)
2883 p_array_type
= ada_check_typedef (TYPE_TARGET_TYPE (p_array_type
));
2886 return p_array_type
;
2888 else if (type
->code () == TYPE_CODE_ARRAY
)
2890 while (nindices
!= 0 && type
->code () == TYPE_CODE_ARRAY
)
2892 type
= TYPE_TARGET_TYPE (type
);
2901 /* See ada-lang.h. */
2904 ada_index_type (struct type
*type
, int n
, const char *name
)
2906 struct type
*result_type
;
2908 type
= desc_base_type (type
);
2910 if (n
< 0 || n
> ada_array_arity (type
))
2911 error (_("invalid dimension number to '%s"), name
);
2913 if (ada_is_simple_array_type (type
))
2917 for (i
= 1; i
< n
; i
+= 1)
2918 type
= TYPE_TARGET_TYPE (type
);
2919 result_type
= TYPE_TARGET_TYPE (type
->index_type ());
2920 /* FIXME: The stabs type r(0,0);bound;bound in an array type
2921 has a target type of TYPE_CODE_UNDEF. We compensate here, but
2922 perhaps stabsread.c would make more sense. */
2923 if (result_type
&& result_type
->code () == TYPE_CODE_UNDEF
)
2928 result_type
= desc_index_type (desc_bounds_type (type
), n
);
2929 if (result_type
== NULL
)
2930 error (_("attempt to take bound of something that is not an array"));
2936 /* Given that arr is an array type, returns the lower bound of the
2937 Nth index (numbering from 1) if WHICH is 0, and the upper bound if
2938 WHICH is 1. This returns bounds 0 .. -1 if ARR_TYPE is an
2939 array-descriptor type. It works for other arrays with bounds supplied
2940 by run-time quantities other than discriminants. */
2943 ada_array_bound_from_type (struct type
*arr_type
, int n
, int which
)
2945 struct type
*type
, *index_type_desc
, *index_type
;
2948 gdb_assert (which
== 0 || which
== 1);
2950 if (ada_is_constrained_packed_array_type (arr_type
))
2951 arr_type
= decode_constrained_packed_array_type (arr_type
);
2953 if (arr_type
== NULL
|| !ada_is_simple_array_type (arr_type
))
2954 return (LONGEST
) - which
;
2956 if (arr_type
->code () == TYPE_CODE_PTR
)
2957 type
= TYPE_TARGET_TYPE (arr_type
);
2961 if (type
->is_fixed_instance ())
2963 /* The array has already been fixed, so we do not need to
2964 check the parallel ___XA type again. That encoding has
2965 already been applied, so ignore it now. */
2966 index_type_desc
= NULL
;
2970 index_type_desc
= ada_find_parallel_type (type
, "___XA");
2971 ada_fixup_array_indexes_type (index_type_desc
);
2974 if (index_type_desc
!= NULL
)
2975 index_type
= to_fixed_range_type (index_type_desc
->field (n
- 1).type (),
2979 struct type
*elt_type
= check_typedef (type
);
2981 for (i
= 1; i
< n
; i
++)
2982 elt_type
= check_typedef (TYPE_TARGET_TYPE (elt_type
));
2984 index_type
= elt_type
->index_type ();
2988 (LONGEST
) (which
== 0
2989 ? ada_discrete_type_low_bound (index_type
)
2990 : ada_discrete_type_high_bound (index_type
));
2993 /* Given that arr is an array value, returns the lower bound of the
2994 nth index (numbering from 1) if WHICH is 0, and the upper bound if
2995 WHICH is 1. This routine will also work for arrays with bounds
2996 supplied by run-time quantities other than discriminants. */
2999 ada_array_bound (struct value
*arr
, int n
, int which
)
3001 struct type
*arr_type
;
3003 if (check_typedef (value_type (arr
))->code () == TYPE_CODE_PTR
)
3004 arr
= value_ind (arr
);
3005 arr_type
= value_enclosing_type (arr
);
3007 if (ada_is_constrained_packed_array_type (arr_type
))
3008 return ada_array_bound (decode_constrained_packed_array (arr
), n
, which
);
3009 else if (ada_is_simple_array_type (arr_type
))
3010 return ada_array_bound_from_type (arr_type
, n
, which
);
3012 return value_as_long (desc_one_bound (desc_bounds (arr
), n
, which
));
3015 /* Given that arr is an array value, returns the length of the
3016 nth index. This routine will also work for arrays with bounds
3017 supplied by run-time quantities other than discriminants.
3018 Does not work for arrays indexed by enumeration types with representation
3019 clauses at the moment. */
3022 ada_array_length (struct value
*arr
, int n
)
3024 struct type
*arr_type
, *index_type
;
3027 if (check_typedef (value_type (arr
))->code () == TYPE_CODE_PTR
)
3028 arr
= value_ind (arr
);
3029 arr_type
= value_enclosing_type (arr
);
3031 if (ada_is_constrained_packed_array_type (arr_type
))
3032 return ada_array_length (decode_constrained_packed_array (arr
), n
);
3034 if (ada_is_simple_array_type (arr_type
))
3036 low
= ada_array_bound_from_type (arr_type
, n
, 0);
3037 high
= ada_array_bound_from_type (arr_type
, n
, 1);
3041 low
= value_as_long (desc_one_bound (desc_bounds (arr
), n
, 0));
3042 high
= value_as_long (desc_one_bound (desc_bounds (arr
), n
, 1));
3045 arr_type
= check_typedef (arr_type
);
3046 index_type
= ada_index_type (arr_type
, n
, "length");
3047 if (index_type
!= NULL
)
3049 struct type
*base_type
;
3050 if (index_type
->code () == TYPE_CODE_RANGE
)
3051 base_type
= TYPE_TARGET_TYPE (index_type
);
3053 base_type
= index_type
;
3055 low
= pos_atr (value_from_longest (base_type
, low
));
3056 high
= pos_atr (value_from_longest (base_type
, high
));
3058 return high
- low
+ 1;
3061 /* An array whose type is that of ARR_TYPE (an array type), with
3062 bounds LOW to HIGH, but whose contents are unimportant. If HIGH is
3063 less than LOW, then LOW-1 is used. */
3065 static struct value
*
3066 empty_array (struct type
*arr_type
, int low
, int high
)
3068 struct type
*arr_type0
= ada_check_typedef (arr_type
);
3069 struct type
*index_type
3070 = create_static_range_type
3071 (NULL
, TYPE_TARGET_TYPE (arr_type0
->index_type ()), low
,
3072 high
< low
? low
- 1 : high
);
3073 struct type
*elt_type
= ada_array_element_type (arr_type0
, 1);
3075 return allocate_value (create_array_type (NULL
, elt_type
, index_type
));
3079 /* Name resolution */
3081 /* The "decoded" name for the user-definable Ada operator corresponding
3085 ada_decoded_op_name (enum exp_opcode op
)
3089 for (i
= 0; ada_opname_table
[i
].encoded
!= NULL
; i
+= 1)
3091 if (ada_opname_table
[i
].op
== op
)
3092 return ada_opname_table
[i
].decoded
;
3094 error (_("Could not find operator name for opcode"));
3097 /* Returns true (non-zero) iff decoded name N0 should appear before N1
3098 in a listing of choices during disambiguation (see sort_choices, below).
3099 The idea is that overloadings of a subprogram name from the
3100 same package should sort in their source order. We settle for ordering
3101 such symbols by their trailing number (__N or $N). */
3104 encoded_ordered_before (const char *N0
, const char *N1
)
3108 else if (N0
== NULL
)
3114 for (k0
= strlen (N0
) - 1; k0
> 0 && isdigit (N0
[k0
]); k0
-= 1)
3116 for (k1
= strlen (N1
) - 1; k1
> 0 && isdigit (N1
[k1
]); k1
-= 1)
3118 if ((N0
[k0
] == '_' || N0
[k0
] == '$') && N0
[k0
+ 1] != '\000'
3119 && (N1
[k1
] == '_' || N1
[k1
] == '$') && N1
[k1
+ 1] != '\000')
3124 while (N0
[n0
] == '_' && n0
> 0 && N0
[n0
- 1] == '_')
3127 while (N1
[n1
] == '_' && n1
> 0 && N1
[n1
- 1] == '_')
3129 if (n0
== n1
&& strncmp (N0
, N1
, n0
) == 0)
3130 return (atoi (N0
+ k0
+ 1) < atoi (N1
+ k1
+ 1));
3132 return (strcmp (N0
, N1
) < 0);
3136 /* Sort SYMS[0..NSYMS-1] to put the choices in a canonical order by the
3140 sort_choices (struct block_symbol syms
[], int nsyms
)
3144 for (i
= 1; i
< nsyms
; i
+= 1)
3146 struct block_symbol sym
= syms
[i
];
3149 for (j
= i
- 1; j
>= 0; j
-= 1)
3151 if (encoded_ordered_before (syms
[j
].symbol
->linkage_name (),
3152 sym
.symbol
->linkage_name ()))
3154 syms
[j
+ 1] = syms
[j
];
3160 /* Whether GDB should display formals and return types for functions in the
3161 overloads selection menu. */
3162 static bool print_signatures
= true;
3164 /* Print the signature for SYM on STREAM according to the FLAGS options. For
3165 all but functions, the signature is just the name of the symbol. For
3166 functions, this is the name of the function, the list of types for formals
3167 and the return type (if any). */
3170 ada_print_symbol_signature (struct ui_file
*stream
, struct symbol
*sym
,
3171 const struct type_print_options
*flags
)
3173 struct type
*type
= SYMBOL_TYPE (sym
);
3175 fprintf_filtered (stream
, "%s", sym
->print_name ());
3176 if (!print_signatures
3178 || type
->code () != TYPE_CODE_FUNC
)
3181 if (type
->num_fields () > 0)
3185 fprintf_filtered (stream
, " (");
3186 for (i
= 0; i
< type
->num_fields (); ++i
)
3189 fprintf_filtered (stream
, "; ");
3190 ada_print_type (type
->field (i
).type (), NULL
, stream
, -1, 0,
3193 fprintf_filtered (stream
, ")");
3195 if (TYPE_TARGET_TYPE (type
) != NULL
3196 && TYPE_TARGET_TYPE (type
)->code () != TYPE_CODE_VOID
)
3198 fprintf_filtered (stream
, " return ");
3199 ada_print_type (TYPE_TARGET_TYPE (type
), NULL
, stream
, -1, 0, flags
);
3203 /* Read and validate a set of numeric choices from the user in the
3204 range 0 .. N_CHOICES-1. Place the results in increasing
3205 order in CHOICES[0 .. N-1], and return N.
3207 The user types choices as a sequence of numbers on one line
3208 separated by blanks, encoding them as follows:
3210 + A choice of 0 means to cancel the selection, throwing an error.
3211 + If IS_ALL_CHOICE, a choice of 1 selects the entire set 0 .. N_CHOICES-1.
3212 + The user chooses k by typing k+IS_ALL_CHOICE+1.
3214 The user is not allowed to choose more than MAX_RESULTS values.
3216 ANNOTATION_SUFFIX, if present, is used to annotate the input
3217 prompts (for use with the -f switch). */
3220 get_selections (int *choices
, int n_choices
, int max_results
,
3221 int is_all_choice
, const char *annotation_suffix
)
3226 int first_choice
= is_all_choice
? 2 : 1;
3228 prompt
= getenv ("PS2");
3232 args
= command_line_input (prompt
, annotation_suffix
);
3235 error_no_arg (_("one or more choice numbers"));
3239 /* Set choices[0 .. n_chosen-1] to the users' choices in ascending
3240 order, as given in args. Choices are validated. */
3246 args
= skip_spaces (args
);
3247 if (*args
== '\0' && n_chosen
== 0)
3248 error_no_arg (_("one or more choice numbers"));
3249 else if (*args
== '\0')
3252 choice
= strtol (args
, &args2
, 10);
3253 if (args
== args2
|| choice
< 0
3254 || choice
> n_choices
+ first_choice
- 1)
3255 error (_("Argument must be choice number"));
3259 error (_("cancelled"));
3261 if (choice
< first_choice
)
3263 n_chosen
= n_choices
;
3264 for (j
= 0; j
< n_choices
; j
+= 1)
3268 choice
-= first_choice
;
3270 for (j
= n_chosen
- 1; j
>= 0 && choice
< choices
[j
]; j
-= 1)
3274 if (j
< 0 || choice
!= choices
[j
])
3278 for (k
= n_chosen
- 1; k
> j
; k
-= 1)
3279 choices
[k
+ 1] = choices
[k
];
3280 choices
[j
+ 1] = choice
;
3285 if (n_chosen
> max_results
)
3286 error (_("Select no more than %d of the above"), max_results
);
3291 /* Given a list of NSYMS symbols in SYMS, select up to MAX_RESULTS>0
3292 by asking the user (if necessary), returning the number selected,
3293 and setting the first elements of SYMS items. Error if no symbols
3296 /* NOTE: Adapted from decode_line_2 in symtab.c, with which it ought
3297 to be re-integrated one of these days. */
3300 user_select_syms (struct block_symbol
*syms
, int nsyms
, int max_results
)
3303 int *chosen
= XALLOCAVEC (int , nsyms
);
3305 int first_choice
= (max_results
== 1) ? 1 : 2;
3306 const char *select_mode
= multiple_symbols_select_mode ();
3308 if (max_results
< 1)
3309 error (_("Request to select 0 symbols!"));
3313 if (select_mode
== multiple_symbols_cancel
)
3315 canceled because the command is ambiguous\n\
3316 See set/show multiple-symbol."));
3318 /* If select_mode is "all", then return all possible symbols.
3319 Only do that if more than one symbol can be selected, of course.
3320 Otherwise, display the menu as usual. */
3321 if (select_mode
== multiple_symbols_all
&& max_results
> 1)
3324 printf_filtered (_("[0] cancel\n"));
3325 if (max_results
> 1)
3326 printf_filtered (_("[1] all\n"));
3328 sort_choices (syms
, nsyms
);
3330 for (i
= 0; i
< nsyms
; i
+= 1)
3332 if (syms
[i
].symbol
== NULL
)
3335 if (SYMBOL_CLASS (syms
[i
].symbol
) == LOC_BLOCK
)
3337 struct symtab_and_line sal
=
3338 find_function_start_sal (syms
[i
].symbol
, 1);
3340 printf_filtered ("[%d] ", i
+ first_choice
);
3341 ada_print_symbol_signature (gdb_stdout
, syms
[i
].symbol
,
3342 &type_print_raw_options
);
3343 if (sal
.symtab
== NULL
)
3344 printf_filtered (_(" at %p[<no source file available>%p]:%d\n"),
3345 metadata_style
.style ().ptr (), nullptr, sal
.line
);
3349 styled_string (file_name_style
.style (),
3350 symtab_to_filename_for_display (sal
.symtab
)),
3357 (SYMBOL_CLASS (syms
[i
].symbol
) == LOC_CONST
3358 && SYMBOL_TYPE (syms
[i
].symbol
) != NULL
3359 && SYMBOL_TYPE (syms
[i
].symbol
)->code () == TYPE_CODE_ENUM
);
3360 struct symtab
*symtab
= NULL
;
3362 if (SYMBOL_OBJFILE_OWNED (syms
[i
].symbol
))
3363 symtab
= symbol_symtab (syms
[i
].symbol
);
3365 if (SYMBOL_LINE (syms
[i
].symbol
) != 0 && symtab
!= NULL
)
3367 printf_filtered ("[%d] ", i
+ first_choice
);
3368 ada_print_symbol_signature (gdb_stdout
, syms
[i
].symbol
,
3369 &type_print_raw_options
);
3370 printf_filtered (_(" at %s:%d\n"),
3371 symtab_to_filename_for_display (symtab
),
3372 SYMBOL_LINE (syms
[i
].symbol
));
3374 else if (is_enumeral
3375 && SYMBOL_TYPE (syms
[i
].symbol
)->name () != NULL
)
3377 printf_filtered (("[%d] "), i
+ first_choice
);
3378 ada_print_type (SYMBOL_TYPE (syms
[i
].symbol
), NULL
,
3379 gdb_stdout
, -1, 0, &type_print_raw_options
);
3380 printf_filtered (_("'(%s) (enumeral)\n"),
3381 syms
[i
].symbol
->print_name ());
3385 printf_filtered ("[%d] ", i
+ first_choice
);
3386 ada_print_symbol_signature (gdb_stdout
, syms
[i
].symbol
,
3387 &type_print_raw_options
);
3390 printf_filtered (is_enumeral
3391 ? _(" in %s (enumeral)\n")
3393 symtab_to_filename_for_display (symtab
));
3395 printf_filtered (is_enumeral
3396 ? _(" (enumeral)\n")
3402 n_chosen
= get_selections (chosen
, nsyms
, max_results
, max_results
> 1,
3405 for (i
= 0; i
< n_chosen
; i
+= 1)
3406 syms
[i
] = syms
[chosen
[i
]];
3411 /* See ada-lang.h. */
3414 ada_find_operator_symbol (enum exp_opcode op
, int parse_completion
,
3415 int nargs
, value
*argvec
[])
3417 if (possible_user_operator_p (op
, argvec
))
3419 std::vector
<struct block_symbol
> candidates
3420 = ada_lookup_symbol_list (ada_decoded_op_name (op
),
3423 int i
= ada_resolve_function (candidates
, argvec
,
3424 nargs
, ada_decoded_op_name (op
), NULL
,
3427 return candidates
[i
];
3432 /* See ada-lang.h. */
3435 ada_resolve_funcall (struct symbol
*sym
, const struct block
*block
,
3436 struct type
*context_type
,
3437 int parse_completion
,
3438 int nargs
, value
*argvec
[],
3439 innermost_block_tracker
*tracker
)
3441 std::vector
<struct block_symbol
> candidates
3442 = ada_lookup_symbol_list (sym
->linkage_name (), block
, VAR_DOMAIN
);
3445 if (candidates
.size () == 1)
3449 i
= ada_resolve_function
3452 sym
->linkage_name (),
3453 context_type
, parse_completion
);
3455 error (_("Could not find a match for %s"), sym
->print_name ());
3458 tracker
->update (candidates
[i
]);
3459 return candidates
[i
];
3462 /* See ada-lang.h. */
3465 ada_resolve_variable (struct symbol
*sym
, const struct block
*block
,
3466 struct type
*context_type
,
3467 int parse_completion
,
3469 innermost_block_tracker
*tracker
)
3471 std::vector
<struct block_symbol
> candidates
3472 = ada_lookup_symbol_list (sym
->linkage_name (), block
, VAR_DOMAIN
);
3474 if (std::any_of (candidates
.begin (),
3476 [] (block_symbol
&bsym
)
3478 switch (SYMBOL_CLASS (bsym
.symbol
))
3483 case LOC_REGPARM_ADDR
:
3492 /* Types tend to get re-introduced locally, so if there
3493 are any local symbols that are not types, first filter
3497 (candidates
.begin (),
3499 [] (block_symbol
&bsym
)
3501 return SYMBOL_CLASS (bsym
.symbol
) == LOC_TYPEDEF
;
3507 if (candidates
.empty ())
3508 error (_("No definition found for %s"), sym
->print_name ());
3509 else if (candidates
.size () == 1)
3511 else if (deprocedure_p
&& !is_nonfunction (candidates
))
3513 i
= ada_resolve_function
3514 (candidates
, NULL
, 0,
3515 sym
->linkage_name (),
3516 context_type
, parse_completion
);
3518 error (_("Could not find a match for %s"), sym
->print_name ());
3522 printf_filtered (_("Multiple matches for %s\n"), sym
->print_name ());
3523 user_select_syms (candidates
.data (), candidates
.size (), 1);
3527 tracker
->update (candidates
[i
]);
3528 return candidates
[i
];
3531 /* Resolve the operator of the subexpression beginning at
3532 position *POS of *EXPP. "Resolving" consists of replacing
3533 the symbols that have undefined namespaces in OP_VAR_VALUE nodes
3534 with their resolutions, replacing built-in operators with
3535 function calls to user-defined operators, where appropriate, and,
3536 when DEPROCEDURE_P is non-zero, converting function-valued variables
3537 into parameterless calls. May expand *EXPP. The CONTEXT_TYPE functions
3538 are as in ada_resolve, above. */
3540 static struct value
*
3541 resolve_subexp (expression_up
*expp
, int *pos
, int deprocedure_p
,
3542 struct type
*context_type
, int parse_completion
,
3543 innermost_block_tracker
*tracker
)
3547 struct expression
*exp
; /* Convenience: == *expp. */
3548 enum exp_opcode op
= (*expp
)->elts
[pc
].opcode
;
3549 struct value
**argvec
; /* Vector of operand types (alloca'ed). */
3550 int nargs
; /* Number of operands. */
3552 /* If we're resolving an expression like ARRAY(ARG...), then we set
3553 this to the type of the array, so we can use the index types as
3554 the expected types for resolution. */
3555 struct type
*array_type
= nullptr;
3556 /* The arity of ARRAY_TYPE. */
3557 int array_arity
= 0;
3563 /* Pass one: resolve operands, saving their types and updating *pos,
3568 if (exp
->elts
[pc
+ 3].opcode
== OP_VAR_VALUE
3569 && SYMBOL_DOMAIN (exp
->elts
[pc
+ 5].symbol
) == UNDEF_DOMAIN
)
3574 struct value
*lhs
= resolve_subexp (expp
, pos
, 0, NULL
,
3575 parse_completion
, tracker
);
3576 struct type
*lhstype
= ada_check_typedef (value_type (lhs
));
3577 array_arity
= ada_array_arity (lhstype
);
3578 if (array_arity
> 0)
3579 array_type
= lhstype
;
3581 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
3586 resolve_subexp (expp
, pos
, 0, NULL
, parse_completion
, tracker
);
3591 resolve_subexp (expp
, pos
, 1, check_typedef (exp
->elts
[pc
+ 1].type
),
3592 parse_completion
, tracker
);
3595 case OP_ATR_MODULUS
:
3605 case TERNOP_IN_RANGE
:
3606 case BINOP_IN_BOUNDS
:
3612 case OP_DISCRETE_RANGE
:
3614 ada_forward_operator_length (exp
, pc
, &oplen
, &nargs
);
3623 arg1
= resolve_subexp (expp
, pos
, 0, NULL
, parse_completion
, tracker
);
3625 resolve_subexp (expp
, pos
, 1, NULL
, parse_completion
, tracker
);
3627 resolve_subexp (expp
, pos
, 1, value_type (arg1
), parse_completion
,
3645 case BINOP_LOGICAL_AND
:
3646 case BINOP_LOGICAL_OR
:
3647 case BINOP_BITWISE_AND
:
3648 case BINOP_BITWISE_IOR
:
3649 case BINOP_BITWISE_XOR
:
3652 case BINOP_NOTEQUAL
:
3659 case BINOP_SUBSCRIPT
:
3667 case UNOP_LOGICAL_NOT
:
3677 case OP_VAR_MSYM_VALUE
:
3684 case OP_INTERNALVAR
:
3694 *pos
+= 4 + BYTES_TO_EXP_ELEM (exp
->elts
[pc
+ 1].longconst
+ 1);
3697 case STRUCTOP_STRUCT
:
3698 *pos
+= 4 + BYTES_TO_EXP_ELEM (exp
->elts
[pc
+ 1].longconst
+ 1);
3711 error (_("Unexpected operator during name resolution"));
3714 argvec
= XALLOCAVEC (struct value
*, nargs
+ 1);
3715 for (i
= 0; i
< nargs
; i
+= 1)
3717 struct type
*subtype
= nullptr;
3718 if (i
< array_arity
)
3719 subtype
= ada_index_type (array_type
, i
+ 1, "array type");
3720 argvec
[i
] = resolve_subexp (expp
, pos
, 1, subtype
, parse_completion
,
3726 /* Pass two: perform any resolution on principal operator. */
3733 if (SYMBOL_DOMAIN (exp
->elts
[pc
+ 2].symbol
) == UNDEF_DOMAIN
)
3735 block_symbol resolved
3736 = ada_resolve_variable (exp
->elts
[pc
+ 2].symbol
,
3737 exp
->elts
[pc
+ 1].block
,
3738 context_type
, parse_completion
,
3739 deprocedure_p
, tracker
);
3740 exp
->elts
[pc
+ 1].block
= resolved
.block
;
3741 exp
->elts
[pc
+ 2].symbol
= resolved
.symbol
;
3745 && (SYMBOL_TYPE (exp
->elts
[pc
+ 2].symbol
)->code ()
3748 replace_operator_with_call (expp
, pc
, 0, 4,
3749 exp
->elts
[pc
+ 2].symbol
,
3750 exp
->elts
[pc
+ 1].block
);
3757 if (exp
->elts
[pc
+ 3].opcode
== OP_VAR_VALUE
3758 && SYMBOL_DOMAIN (exp
->elts
[pc
+ 5].symbol
) == UNDEF_DOMAIN
)
3760 block_symbol resolved
3761 = ada_resolve_funcall (exp
->elts
[pc
+ 5].symbol
,
3762 exp
->elts
[pc
+ 4].block
,
3763 context_type
, parse_completion
,
3766 exp
->elts
[pc
+ 4].block
= resolved
.block
;
3767 exp
->elts
[pc
+ 5].symbol
= resolved
.symbol
;
3778 case BINOP_BITWISE_AND
:
3779 case BINOP_BITWISE_IOR
:
3780 case BINOP_BITWISE_XOR
:
3782 case BINOP_NOTEQUAL
:
3790 case UNOP_LOGICAL_NOT
:
3793 block_symbol found
= ada_find_operator_symbol (op
, parse_completion
,
3795 if (found
.symbol
== nullptr)
3798 replace_operator_with_call (expp
, pc
, nargs
, 1,
3799 found
.symbol
, found
.block
);
3810 if (exp
->elts
[pc
].opcode
== OP_VAR_MSYM_VALUE
)
3811 return evaluate_var_msym_value (EVAL_AVOID_SIDE_EFFECTS
,
3812 exp
->elts
[pc
+ 1].objfile
,
3813 exp
->elts
[pc
+ 2].msymbol
);
3815 return evaluate_subexp_type (exp
, pos
);
3818 /* Return non-zero if formal type FTYPE matches actual type ATYPE. If
3819 MAY_DEREF is non-zero, the formal may be a pointer and the actual
3821 /* The term "match" here is rather loose. The match is heuristic and
3825 ada_type_match (struct type
*ftype
, struct type
*atype
, int may_deref
)
3827 ftype
= ada_check_typedef (ftype
);
3828 atype
= ada_check_typedef (atype
);
3830 if (ftype
->code () == TYPE_CODE_REF
)
3831 ftype
= TYPE_TARGET_TYPE (ftype
);
3832 if (atype
->code () == TYPE_CODE_REF
)
3833 atype
= TYPE_TARGET_TYPE (atype
);
3835 switch (ftype
->code ())
3838 return ftype
->code () == atype
->code ();
3840 if (atype
->code () == TYPE_CODE_PTR
)
3841 return ada_type_match (TYPE_TARGET_TYPE (ftype
),
3842 TYPE_TARGET_TYPE (atype
), 0);
3845 && ada_type_match (TYPE_TARGET_TYPE (ftype
), atype
, 0));
3847 case TYPE_CODE_ENUM
:
3848 case TYPE_CODE_RANGE
:
3849 switch (atype
->code ())
3852 case TYPE_CODE_ENUM
:
3853 case TYPE_CODE_RANGE
:
3859 case TYPE_CODE_ARRAY
:
3860 return (atype
->code () == TYPE_CODE_ARRAY
3861 || ada_is_array_descriptor_type (atype
));
3863 case TYPE_CODE_STRUCT
:
3864 if (ada_is_array_descriptor_type (ftype
))
3865 return (atype
->code () == TYPE_CODE_ARRAY
3866 || ada_is_array_descriptor_type (atype
));
3868 return (atype
->code () == TYPE_CODE_STRUCT
3869 && !ada_is_array_descriptor_type (atype
));
3871 case TYPE_CODE_UNION
:
3873 return (atype
->code () == ftype
->code ());
3877 /* Return non-zero if the formals of FUNC "sufficiently match" the
3878 vector of actual argument types ACTUALS of size N_ACTUALS. FUNC
3879 may also be an enumeral, in which case it is treated as a 0-
3880 argument function. */
3883 ada_args_match (struct symbol
*func
, struct value
**actuals
, int n_actuals
)
3886 struct type
*func_type
= SYMBOL_TYPE (func
);
3888 if (SYMBOL_CLASS (func
) == LOC_CONST
3889 && func_type
->code () == TYPE_CODE_ENUM
)
3890 return (n_actuals
== 0);
3891 else if (func_type
== NULL
|| func_type
->code () != TYPE_CODE_FUNC
)
3894 if (func_type
->num_fields () != n_actuals
)
3897 for (i
= 0; i
< n_actuals
; i
+= 1)
3899 if (actuals
[i
] == NULL
)
3903 struct type
*ftype
= ada_check_typedef (func_type
->field (i
).type ());
3904 struct type
*atype
= ada_check_typedef (value_type (actuals
[i
]));
3906 if (!ada_type_match (ftype
, atype
, 1))
3913 /* False iff function type FUNC_TYPE definitely does not produce a value
3914 compatible with type CONTEXT_TYPE. Conservatively returns 1 if
3915 FUNC_TYPE is not a valid function type with a non-null return type
3916 or an enumerated type. A null CONTEXT_TYPE indicates any non-void type. */
3919 return_match (struct type
*func_type
, struct type
*context_type
)
3921 struct type
*return_type
;
3923 if (func_type
== NULL
)
3926 if (func_type
->code () == TYPE_CODE_FUNC
)
3927 return_type
= get_base_type (TYPE_TARGET_TYPE (func_type
));
3929 return_type
= get_base_type (func_type
);
3930 if (return_type
== NULL
)
3933 context_type
= get_base_type (context_type
);
3935 if (return_type
->code () == TYPE_CODE_ENUM
)
3936 return context_type
== NULL
|| return_type
== context_type
;
3937 else if (context_type
== NULL
)
3938 return return_type
->code () != TYPE_CODE_VOID
;
3940 return return_type
->code () == context_type
->code ();
3944 /* Returns the index in SYMS that contains the symbol for the
3945 function (if any) that matches the types of the NARGS arguments in
3946 ARGS. If CONTEXT_TYPE is non-null and there is at least one match
3947 that returns that type, then eliminate matches that don't. If
3948 CONTEXT_TYPE is void and there is at least one match that does not
3949 return void, eliminate all matches that do.
3951 Asks the user if there is more than one match remaining. Returns -1
3952 if there is no such symbol or none is selected. NAME is used
3953 solely for messages. May re-arrange and modify SYMS in
3954 the process; the index returned is for the modified vector. */
3957 ada_resolve_function (std::vector
<struct block_symbol
> &syms
,
3958 struct value
**args
, int nargs
,
3959 const char *name
, struct type
*context_type
,
3960 int parse_completion
)
3964 int m
; /* Number of hits */
3967 /* In the first pass of the loop, we only accept functions matching
3968 context_type. If none are found, we add a second pass of the loop
3969 where every function is accepted. */
3970 for (fallback
= 0; m
== 0 && fallback
< 2; fallback
++)
3972 for (k
= 0; k
< syms
.size (); k
+= 1)
3974 struct type
*type
= ada_check_typedef (SYMBOL_TYPE (syms
[k
].symbol
));
3976 if (ada_args_match (syms
[k
].symbol
, args
, nargs
)
3977 && (fallback
|| return_match (type
, context_type
)))
3985 /* If we got multiple matches, ask the user which one to use. Don't do this
3986 interactive thing during completion, though, as the purpose of the
3987 completion is providing a list of all possible matches. Prompting the
3988 user to filter it down would be completely unexpected in this case. */
3991 else if (m
> 1 && !parse_completion
)
3993 printf_filtered (_("Multiple matches for %s\n"), name
);
3994 user_select_syms (syms
.data (), m
, 1);
4000 /* Replace the operator of length OPLEN at position PC in *EXPP with a call
4001 on the function identified by SYM and BLOCK, and taking NARGS
4002 arguments. Update *EXPP as needed to hold more space. */
4005 replace_operator_with_call (expression_up
*expp
, int pc
, int nargs
,
4006 int oplen
, struct symbol
*sym
,
4007 const struct block
*block
)
4009 /* We want to add 6 more elements (3 for funcall, 4 for function
4010 symbol, -OPLEN for operator being replaced) to the
4012 struct expression
*exp
= expp
->get ();
4013 int save_nelts
= exp
->nelts
;
4014 int extra_elts
= 7 - oplen
;
4015 exp
->nelts
+= extra_elts
;
4018 exp
->resize (exp
->nelts
);
4019 memmove (exp
->elts
+ pc
+ 7, exp
->elts
+ pc
+ oplen
,
4020 EXP_ELEM_TO_BYTES (save_nelts
- pc
- oplen
));
4022 exp
->resize (exp
->nelts
);
4024 exp
->elts
[pc
].opcode
= exp
->elts
[pc
+ 2].opcode
= OP_FUNCALL
;
4025 exp
->elts
[pc
+ 1].longconst
= (LONGEST
) nargs
;
4027 exp
->elts
[pc
+ 3].opcode
= exp
->elts
[pc
+ 6].opcode
= OP_VAR_VALUE
;
4028 exp
->elts
[pc
+ 4].block
= block
;
4029 exp
->elts
[pc
+ 5].symbol
= sym
;
4032 /* Type-class predicates */
4034 /* True iff TYPE is numeric (i.e., an INT, RANGE (of numeric type),
4038 numeric_type_p (struct type
*type
)
4044 switch (type
->code ())
4049 case TYPE_CODE_RANGE
:
4050 return (type
== TYPE_TARGET_TYPE (type
)
4051 || numeric_type_p (TYPE_TARGET_TYPE (type
)));
4058 /* True iff TYPE is integral (an INT or RANGE of INTs). */
4061 integer_type_p (struct type
*type
)
4067 switch (type
->code ())
4071 case TYPE_CODE_RANGE
:
4072 return (type
== TYPE_TARGET_TYPE (type
)
4073 || integer_type_p (TYPE_TARGET_TYPE (type
)));
4080 /* True iff TYPE is scalar (INT, RANGE, FLOAT, ENUM). */
4083 scalar_type_p (struct type
*type
)
4089 switch (type
->code ())
4092 case TYPE_CODE_RANGE
:
4093 case TYPE_CODE_ENUM
:
4102 /* True iff TYPE is discrete (INT, RANGE, ENUM). */
4105 discrete_type_p (struct type
*type
)
4111 switch (type
->code ())
4114 case TYPE_CODE_RANGE
:
4115 case TYPE_CODE_ENUM
:
4116 case TYPE_CODE_BOOL
:
4124 /* Returns non-zero if OP with operands in the vector ARGS could be
4125 a user-defined function. Errs on the side of pre-defined operators
4126 (i.e., result 0). */
4129 possible_user_operator_p (enum exp_opcode op
, struct value
*args
[])
4131 struct type
*type0
=
4132 (args
[0] == NULL
) ? NULL
: ada_check_typedef (value_type (args
[0]));
4133 struct type
*type1
=
4134 (args
[1] == NULL
) ? NULL
: ada_check_typedef (value_type (args
[1]));
4148 return (!(numeric_type_p (type0
) && numeric_type_p (type1
)));
4152 case BINOP_BITWISE_AND
:
4153 case BINOP_BITWISE_IOR
:
4154 case BINOP_BITWISE_XOR
:
4155 return (!(integer_type_p (type0
) && integer_type_p (type1
)));
4158 case BINOP_NOTEQUAL
:
4163 return (!(scalar_type_p (type0
) && scalar_type_p (type1
)));
4166 return !ada_is_array_type (type0
) || !ada_is_array_type (type1
);
4169 return (!(numeric_type_p (type0
) && integer_type_p (type1
)));
4173 case UNOP_LOGICAL_NOT
:
4175 return (!numeric_type_p (type0
));
4184 1. In the following, we assume that a renaming type's name may
4185 have an ___XD suffix. It would be nice if this went away at some
4187 2. We handle both the (old) purely type-based representation of
4188 renamings and the (new) variable-based encoding. At some point,
4189 it is devoutly to be hoped that the former goes away
4190 (FIXME: hilfinger-2007-07-09).
4191 3. Subprogram renamings are not implemented, although the XRS
4192 suffix is recognized (FIXME: hilfinger-2007-07-09). */
4194 /* If SYM encodes a renaming,
4196 <renaming> renames <renamed entity>,
4198 sets *LEN to the length of the renamed entity's name,
4199 *RENAMED_ENTITY to that name (not null-terminated), and *RENAMING_EXPR to
4200 the string describing the subcomponent selected from the renamed
4201 entity. Returns ADA_NOT_RENAMING if SYM does not encode a renaming
4202 (in which case, the values of *RENAMED_ENTITY, *LEN, and *RENAMING_EXPR
4203 are undefined). Otherwise, returns a value indicating the category
4204 of entity renamed: an object (ADA_OBJECT_RENAMING), exception
4205 (ADA_EXCEPTION_RENAMING), package (ADA_PACKAGE_RENAMING), or
4206 subprogram (ADA_SUBPROGRAM_RENAMING). Does no allocation; the
4207 strings returned in *RENAMED_ENTITY and *RENAMING_EXPR should not be
4208 deallocated. The values of RENAMED_ENTITY, LEN, or RENAMING_EXPR
4209 may be NULL, in which case they are not assigned.
4211 [Currently, however, GCC does not generate subprogram renamings.] */
4213 enum ada_renaming_category
4214 ada_parse_renaming (struct symbol
*sym
,
4215 const char **renamed_entity
, int *len
,
4216 const char **renaming_expr
)
4218 enum ada_renaming_category kind
;
4223 return ADA_NOT_RENAMING
;
4224 switch (SYMBOL_CLASS (sym
))
4227 return ADA_NOT_RENAMING
;
4231 case LOC_OPTIMIZED_OUT
:
4232 info
= strstr (sym
->linkage_name (), "___XR");
4234 return ADA_NOT_RENAMING
;
4238 kind
= ADA_OBJECT_RENAMING
;
4242 kind
= ADA_EXCEPTION_RENAMING
;
4246 kind
= ADA_PACKAGE_RENAMING
;
4250 kind
= ADA_SUBPROGRAM_RENAMING
;
4254 return ADA_NOT_RENAMING
;
4258 if (renamed_entity
!= NULL
)
4259 *renamed_entity
= info
;
4260 suffix
= strstr (info
, "___XE");
4261 if (suffix
== NULL
|| suffix
== info
)
4262 return ADA_NOT_RENAMING
;
4264 *len
= strlen (info
) - strlen (suffix
);
4266 if (renaming_expr
!= NULL
)
4267 *renaming_expr
= suffix
;
4271 /* Compute the value of the given RENAMING_SYM, which is expected to
4272 be a symbol encoding a renaming expression. BLOCK is the block
4273 used to evaluate the renaming. */
4275 static struct value
*
4276 ada_read_renaming_var_value (struct symbol
*renaming_sym
,
4277 const struct block
*block
)
4279 const char *sym_name
;
4281 sym_name
= renaming_sym
->linkage_name ();
4282 expression_up expr
= parse_exp_1 (&sym_name
, 0, block
, 0);
4283 return evaluate_expression (expr
.get ());
4287 /* Evaluation: Function Calls */
4289 /* Return an lvalue containing the value VAL. This is the identity on
4290 lvalues, and otherwise has the side-effect of allocating memory
4291 in the inferior where a copy of the value contents is copied. */
4293 static struct value
*
4294 ensure_lval (struct value
*val
)
4296 if (VALUE_LVAL (val
) == not_lval
4297 || VALUE_LVAL (val
) == lval_internalvar
)
4299 int len
= TYPE_LENGTH (ada_check_typedef (value_type (val
)));
4300 const CORE_ADDR addr
=
4301 value_as_long (value_allocate_space_in_inferior (len
));
4303 VALUE_LVAL (val
) = lval_memory
;
4304 set_value_address (val
, addr
);
4305 write_memory (addr
, value_contents (val
), len
);
4311 /* Given ARG, a value of type (pointer or reference to a)*
4312 structure/union, extract the component named NAME from the ultimate
4313 target structure/union and return it as a value with its
4316 The routine searches for NAME among all members of the structure itself
4317 and (recursively) among all members of any wrapper members
4320 If NO_ERR, then simply return NULL in case of error, rather than
4323 static struct value
*
4324 ada_value_struct_elt (struct value
*arg
, const char *name
, int no_err
)
4326 struct type
*t
, *t1
;
4331 t1
= t
= ada_check_typedef (value_type (arg
));
4332 if (t
->code () == TYPE_CODE_REF
)
4334 t1
= TYPE_TARGET_TYPE (t
);
4337 t1
= ada_check_typedef (t1
);
4338 if (t1
->code () == TYPE_CODE_PTR
)
4340 arg
= coerce_ref (arg
);
4345 while (t
->code () == TYPE_CODE_PTR
)
4347 t1
= TYPE_TARGET_TYPE (t
);
4350 t1
= ada_check_typedef (t1
);
4351 if (t1
->code () == TYPE_CODE_PTR
)
4353 arg
= value_ind (arg
);
4360 if (t1
->code () != TYPE_CODE_STRUCT
&& t1
->code () != TYPE_CODE_UNION
)
4364 v
= ada_search_struct_field (name
, arg
, 0, t
);
4367 int bit_offset
, bit_size
, byte_offset
;
4368 struct type
*field_type
;
4371 if (t
->code () == TYPE_CODE_PTR
)
4372 address
= value_address (ada_value_ind (arg
));
4374 address
= value_address (ada_coerce_ref (arg
));
4376 /* Check to see if this is a tagged type. We also need to handle
4377 the case where the type is a reference to a tagged type, but
4378 we have to be careful to exclude pointers to tagged types.
4379 The latter should be shown as usual (as a pointer), whereas
4380 a reference should mostly be transparent to the user. */
4382 if (ada_is_tagged_type (t1
, 0)
4383 || (t1
->code () == TYPE_CODE_REF
4384 && ada_is_tagged_type (TYPE_TARGET_TYPE (t1
), 0)))
4386 /* We first try to find the searched field in the current type.
4387 If not found then let's look in the fixed type. */
4389 if (!find_struct_field (name
, t1
, 0,
4390 &field_type
, &byte_offset
, &bit_offset
,
4399 /* Convert to fixed type in all cases, so that we have proper
4400 offsets to each field in unconstrained record types. */
4401 t1
= ada_to_fixed_type (ada_get_base_type (t1
), NULL
,
4402 address
, NULL
, check_tag
);
4404 /* Resolve the dynamic type as well. */
4405 arg
= value_from_contents_and_address (t1
, nullptr, address
);
4406 t1
= value_type (arg
);
4408 if (find_struct_field (name
, t1
, 0,
4409 &field_type
, &byte_offset
, &bit_offset
,
4414 if (t
->code () == TYPE_CODE_REF
)
4415 arg
= ada_coerce_ref (arg
);
4417 arg
= ada_value_ind (arg
);
4418 v
= ada_value_primitive_packed_val (arg
, NULL
, byte_offset
,
4419 bit_offset
, bit_size
,
4423 v
= value_at_lazy (field_type
, address
+ byte_offset
);
4427 if (v
!= NULL
|| no_err
)
4430 error (_("There is no member named %s."), name
);
4436 error (_("Attempt to extract a component of "
4437 "a value that is not a record."));
4440 /* Return the value ACTUAL, converted to be an appropriate value for a
4441 formal of type FORMAL_TYPE. Use *SP as a stack pointer for
4442 allocating any necessary descriptors (fat pointers), or copies of
4443 values not residing in memory, updating it as needed. */
4446 ada_convert_actual (struct value
*actual
, struct type
*formal_type0
)
4448 struct type
*actual_type
= ada_check_typedef (value_type (actual
));
4449 struct type
*formal_type
= ada_check_typedef (formal_type0
);
4450 struct type
*formal_target
=
4451 formal_type
->code () == TYPE_CODE_PTR
4452 ? ada_check_typedef (TYPE_TARGET_TYPE (formal_type
)) : formal_type
;
4453 struct type
*actual_target
=
4454 actual_type
->code () == TYPE_CODE_PTR
4455 ? ada_check_typedef (TYPE_TARGET_TYPE (actual_type
)) : actual_type
;
4457 if (ada_is_array_descriptor_type (formal_target
)
4458 && actual_target
->code () == TYPE_CODE_ARRAY
)
4459 return make_array_descriptor (formal_type
, actual
);
4460 else if (formal_type
->code () == TYPE_CODE_PTR
4461 || formal_type
->code () == TYPE_CODE_REF
)
4463 struct value
*result
;
4465 if (formal_target
->code () == TYPE_CODE_ARRAY
4466 && ada_is_array_descriptor_type (actual_target
))
4467 result
= desc_data (actual
);
4468 else if (formal_type
->code () != TYPE_CODE_PTR
)
4470 if (VALUE_LVAL (actual
) != lval_memory
)
4474 actual_type
= ada_check_typedef (value_type (actual
));
4475 val
= allocate_value (actual_type
);
4476 memcpy ((char *) value_contents_raw (val
),
4477 (char *) value_contents (actual
),
4478 TYPE_LENGTH (actual_type
));
4479 actual
= ensure_lval (val
);
4481 result
= value_addr (actual
);
4485 return value_cast_pointers (formal_type
, result
, 0);
4487 else if (actual_type
->code () == TYPE_CODE_PTR
)
4488 return ada_value_ind (actual
);
4489 else if (ada_is_aligner_type (formal_type
))
4491 /* We need to turn this parameter into an aligner type
4493 struct value
*aligner
= allocate_value (formal_type
);
4494 struct value
*component
= ada_value_struct_elt (aligner
, "F", 0);
4496 value_assign_to_component (aligner
, component
, actual
);
4503 /* Convert VALUE (which must be an address) to a CORE_ADDR that is a pointer of
4504 type TYPE. This is usually an inefficient no-op except on some targets
4505 (such as AVR) where the representation of a pointer and an address
4509 value_pointer (struct value
*value
, struct type
*type
)
4511 unsigned len
= TYPE_LENGTH (type
);
4512 gdb_byte
*buf
= (gdb_byte
*) alloca (len
);
4515 addr
= value_address (value
);
4516 gdbarch_address_to_pointer (type
->arch (), type
, buf
, addr
);
4517 addr
= extract_unsigned_integer (buf
, len
, type_byte_order (type
));
4522 /* Push a descriptor of type TYPE for array value ARR on the stack at
4523 *SP, updating *SP to reflect the new descriptor. Return either
4524 an lvalue representing the new descriptor, or (if TYPE is a pointer-
4525 to-descriptor type rather than a descriptor type), a struct value *
4526 representing a pointer to this descriptor. */
4528 static struct value
*
4529 make_array_descriptor (struct type
*type
, struct value
*arr
)
4531 struct type
*bounds_type
= desc_bounds_type (type
);
4532 struct type
*desc_type
= desc_base_type (type
);
4533 struct value
*descriptor
= allocate_value (desc_type
);
4534 struct value
*bounds
= allocate_value (bounds_type
);
4537 for (i
= ada_array_arity (ada_check_typedef (value_type (arr
)));
4540 modify_field (value_type (bounds
), value_contents_writeable (bounds
),
4541 ada_array_bound (arr
, i
, 0),
4542 desc_bound_bitpos (bounds_type
, i
, 0),
4543 desc_bound_bitsize (bounds_type
, i
, 0));
4544 modify_field (value_type (bounds
), value_contents_writeable (bounds
),
4545 ada_array_bound (arr
, i
, 1),
4546 desc_bound_bitpos (bounds_type
, i
, 1),
4547 desc_bound_bitsize (bounds_type
, i
, 1));
4550 bounds
= ensure_lval (bounds
);
4552 modify_field (value_type (descriptor
),
4553 value_contents_writeable (descriptor
),
4554 value_pointer (ensure_lval (arr
),
4555 desc_type
->field (0).type ()),
4556 fat_pntr_data_bitpos (desc_type
),
4557 fat_pntr_data_bitsize (desc_type
));
4559 modify_field (value_type (descriptor
),
4560 value_contents_writeable (descriptor
),
4561 value_pointer (bounds
,
4562 desc_type
->field (1).type ()),
4563 fat_pntr_bounds_bitpos (desc_type
),
4564 fat_pntr_bounds_bitsize (desc_type
));
4566 descriptor
= ensure_lval (descriptor
);
4568 if (type
->code () == TYPE_CODE_PTR
)
4569 return value_addr (descriptor
);
4574 /* Symbol Cache Module */
4576 /* Performance measurements made as of 2010-01-15 indicate that
4577 this cache does bring some noticeable improvements. Depending
4578 on the type of entity being printed, the cache can make it as much
4579 as an order of magnitude faster than without it.
4581 The descriptive type DWARF extension has significantly reduced
4582 the need for this cache, at least when DWARF is being used. However,
4583 even in this case, some expensive name-based symbol searches are still
4584 sometimes necessary - to find an XVZ variable, mostly. */
4586 /* Return the symbol cache associated to the given program space PSPACE.
4587 If not allocated for this PSPACE yet, allocate and initialize one. */
4589 static struct ada_symbol_cache
*
4590 ada_get_symbol_cache (struct program_space
*pspace
)
4592 struct ada_pspace_data
*pspace_data
= get_ada_pspace_data (pspace
);
4594 if (pspace_data
->sym_cache
== nullptr)
4595 pspace_data
->sym_cache
.reset (new ada_symbol_cache
);
4597 return pspace_data
->sym_cache
.get ();
4600 /* Clear all entries from the symbol cache. */
4603 ada_clear_symbol_cache ()
4605 struct ada_pspace_data
*pspace_data
4606 = get_ada_pspace_data (current_program_space
);
4608 if (pspace_data
->sym_cache
!= nullptr)
4609 pspace_data
->sym_cache
.reset ();
4612 /* Search our cache for an entry matching NAME and DOMAIN.
4613 Return it if found, or NULL otherwise. */
4615 static struct cache_entry
**
4616 find_entry (const char *name
, domain_enum domain
)
4618 struct ada_symbol_cache
*sym_cache
4619 = ada_get_symbol_cache (current_program_space
);
4620 int h
= msymbol_hash (name
) % HASH_SIZE
;
4621 struct cache_entry
**e
;
4623 for (e
= &sym_cache
->root
[h
]; *e
!= NULL
; e
= &(*e
)->next
)
4625 if (domain
== (*e
)->domain
&& strcmp (name
, (*e
)->name
) == 0)
4631 /* Search the symbol cache for an entry matching NAME and DOMAIN.
4632 Return 1 if found, 0 otherwise.
4634 If an entry was found and SYM is not NULL, set *SYM to the entry's
4635 SYM. Same principle for BLOCK if not NULL. */
4638 lookup_cached_symbol (const char *name
, domain_enum domain
,
4639 struct symbol
**sym
, const struct block
**block
)
4641 struct cache_entry
**e
= find_entry (name
, domain
);
4648 *block
= (*e
)->block
;
4652 /* Assuming that (SYM, BLOCK) is the result of the lookup of NAME
4653 in domain DOMAIN, save this result in our symbol cache. */
4656 cache_symbol (const char *name
, domain_enum domain
, struct symbol
*sym
,
4657 const struct block
*block
)
4659 struct ada_symbol_cache
*sym_cache
4660 = ada_get_symbol_cache (current_program_space
);
4662 struct cache_entry
*e
;
4664 /* Symbols for builtin types don't have a block.
4665 For now don't cache such symbols. */
4666 if (sym
!= NULL
&& !SYMBOL_OBJFILE_OWNED (sym
))
4669 /* If the symbol is a local symbol, then do not cache it, as a search
4670 for that symbol depends on the context. To determine whether
4671 the symbol is local or not, we check the block where we found it
4672 against the global and static blocks of its associated symtab. */
4674 && BLOCKVECTOR_BLOCK (SYMTAB_BLOCKVECTOR (symbol_symtab (sym
)),
4675 GLOBAL_BLOCK
) != block
4676 && BLOCKVECTOR_BLOCK (SYMTAB_BLOCKVECTOR (symbol_symtab (sym
)),
4677 STATIC_BLOCK
) != block
)
4680 h
= msymbol_hash (name
) % HASH_SIZE
;
4681 e
= XOBNEW (&sym_cache
->cache_space
, cache_entry
);
4682 e
->next
= sym_cache
->root
[h
];
4683 sym_cache
->root
[h
] = e
;
4684 e
->name
= obstack_strdup (&sym_cache
->cache_space
, name
);
4692 /* Return the symbol name match type that should be used used when
4693 searching for all symbols matching LOOKUP_NAME.
4695 LOOKUP_NAME is expected to be a symbol name after transformation
4698 static symbol_name_match_type
4699 name_match_type_from_name (const char *lookup_name
)
4701 return (strstr (lookup_name
, "__") == NULL
4702 ? symbol_name_match_type::WILD
4703 : symbol_name_match_type::FULL
);
4706 /* Return the result of a standard (literal, C-like) lookup of NAME in
4707 given DOMAIN, visible from lexical block BLOCK. */
4709 static struct symbol
*
4710 standard_lookup (const char *name
, const struct block
*block
,
4713 /* Initialize it just to avoid a GCC false warning. */
4714 struct block_symbol sym
= {};
4716 if (lookup_cached_symbol (name
, domain
, &sym
.symbol
, NULL
))
4718 ada_lookup_encoded_symbol (name
, block
, domain
, &sym
);
4719 cache_symbol (name
, domain
, sym
.symbol
, sym
.block
);
4724 /* Non-zero iff there is at least one non-function/non-enumeral symbol
4725 in the symbol fields of SYMS. We treat enumerals as functions,
4726 since they contend in overloading in the same way. */
4728 is_nonfunction (const std::vector
<struct block_symbol
> &syms
)
4730 for (const block_symbol
&sym
: syms
)
4731 if (SYMBOL_TYPE (sym
.symbol
)->code () != TYPE_CODE_FUNC
4732 && (SYMBOL_TYPE (sym
.symbol
)->code () != TYPE_CODE_ENUM
4733 || SYMBOL_CLASS (sym
.symbol
) != LOC_CONST
))
4739 /* If true (non-zero), then TYPE0 and TYPE1 represent equivalent
4740 struct types. Otherwise, they may not. */
4743 equiv_types (struct type
*type0
, struct type
*type1
)
4747 if (type0
== NULL
|| type1
== NULL
4748 || type0
->code () != type1
->code ())
4750 if ((type0
->code () == TYPE_CODE_STRUCT
4751 || type0
->code () == TYPE_CODE_ENUM
)
4752 && ada_type_name (type0
) != NULL
&& ada_type_name (type1
) != NULL
4753 && strcmp (ada_type_name (type0
), ada_type_name (type1
)) == 0)
4759 /* True iff SYM0 represents the same entity as SYM1, or one that is
4760 no more defined than that of SYM1. */
4763 lesseq_defined_than (struct symbol
*sym0
, struct symbol
*sym1
)
4767 if (SYMBOL_DOMAIN (sym0
) != SYMBOL_DOMAIN (sym1
)
4768 || SYMBOL_CLASS (sym0
) != SYMBOL_CLASS (sym1
))
4771 switch (SYMBOL_CLASS (sym0
))
4777 struct type
*type0
= SYMBOL_TYPE (sym0
);
4778 struct type
*type1
= SYMBOL_TYPE (sym1
);
4779 const char *name0
= sym0
->linkage_name ();
4780 const char *name1
= sym1
->linkage_name ();
4781 int len0
= strlen (name0
);
4784 type0
->code () == type1
->code ()
4785 && (equiv_types (type0
, type1
)
4786 || (len0
< strlen (name1
) && strncmp (name0
, name1
, len0
) == 0
4787 && startswith (name1
+ len0
, "___XV")));
4790 return SYMBOL_VALUE (sym0
) == SYMBOL_VALUE (sym1
)
4791 && equiv_types (SYMBOL_TYPE (sym0
), SYMBOL_TYPE (sym1
));
4795 const char *name0
= sym0
->linkage_name ();
4796 const char *name1
= sym1
->linkage_name ();
4797 return (strcmp (name0
, name1
) == 0
4798 && SYMBOL_VALUE_ADDRESS (sym0
) == SYMBOL_VALUE_ADDRESS (sym1
));
4806 /* Append (SYM,BLOCK) to the end of the array of struct block_symbol
4807 records in RESULT. Do nothing if SYM is a duplicate. */
4810 add_defn_to_vec (std::vector
<struct block_symbol
> &result
,
4812 const struct block
*block
)
4814 /* Do not try to complete stub types, as the debugger is probably
4815 already scanning all symbols matching a certain name at the
4816 time when this function is called. Trying to replace the stub
4817 type by its associated full type will cause us to restart a scan
4818 which may lead to an infinite recursion. Instead, the client
4819 collecting the matching symbols will end up collecting several
4820 matches, with at least one of them complete. It can then filter
4821 out the stub ones if needed. */
4823 for (int i
= result
.size () - 1; i
>= 0; i
-= 1)
4825 if (lesseq_defined_than (sym
, result
[i
].symbol
))
4827 else if (lesseq_defined_than (result
[i
].symbol
, sym
))
4829 result
[i
].symbol
= sym
;
4830 result
[i
].block
= block
;
4835 struct block_symbol info
;
4838 result
.push_back (info
);
4841 /* Return a bound minimal symbol matching NAME according to Ada
4842 decoding rules. Returns an invalid symbol if there is no such
4843 minimal symbol. Names prefixed with "standard__" are handled
4844 specially: "standard__" is first stripped off, and only static and
4845 global symbols are searched. */
4847 struct bound_minimal_symbol
4848 ada_lookup_simple_minsym (const char *name
)
4850 struct bound_minimal_symbol result
;
4852 memset (&result
, 0, sizeof (result
));
4854 symbol_name_match_type match_type
= name_match_type_from_name (name
);
4855 lookup_name_info
lookup_name (name
, match_type
);
4857 symbol_name_matcher_ftype
*match_name
4858 = ada_get_symbol_name_matcher (lookup_name
);
4860 for (objfile
*objfile
: current_program_space
->objfiles ())
4862 for (minimal_symbol
*msymbol
: objfile
->msymbols ())
4864 if (match_name (msymbol
->linkage_name (), lookup_name
, NULL
)
4865 && MSYMBOL_TYPE (msymbol
) != mst_solib_trampoline
)
4867 result
.minsym
= msymbol
;
4868 result
.objfile
= objfile
;
4877 /* For all subprograms that statically enclose the subprogram of the
4878 selected frame, add symbols matching identifier NAME in DOMAIN
4879 and their blocks to the list of data in RESULT, as for
4880 ada_add_block_symbols (q.v.). If WILD_MATCH_P, treat as NAME
4881 with a wildcard prefix. */
4884 add_symbols_from_enclosing_procs (std::vector
<struct block_symbol
> &result
,
4885 const lookup_name_info
&lookup_name
,
4890 /* True if TYPE is definitely an artificial type supplied to a symbol
4891 for which no debugging information was given in the symbol file. */
4894 is_nondebugging_type (struct type
*type
)
4896 const char *name
= ada_type_name (type
);
4898 return (name
!= NULL
&& strcmp (name
, "<variable, no debug info>") == 0);
4901 /* Return nonzero if TYPE1 and TYPE2 are two enumeration types
4902 that are deemed "identical" for practical purposes.
4904 This function assumes that TYPE1 and TYPE2 are both TYPE_CODE_ENUM
4905 types and that their number of enumerals is identical (in other
4906 words, type1->num_fields () == type2->num_fields ()). */
4909 ada_identical_enum_types_p (struct type
*type1
, struct type
*type2
)
4913 /* The heuristic we use here is fairly conservative. We consider
4914 that 2 enumerate types are identical if they have the same
4915 number of enumerals and that all enumerals have the same
4916 underlying value and name. */
4918 /* All enums in the type should have an identical underlying value. */
4919 for (i
= 0; i
< type1
->num_fields (); i
++)
4920 if (TYPE_FIELD_ENUMVAL (type1
, i
) != TYPE_FIELD_ENUMVAL (type2
, i
))
4923 /* All enumerals should also have the same name (modulo any numerical
4925 for (i
= 0; i
< type1
->num_fields (); i
++)
4927 const char *name_1
= TYPE_FIELD_NAME (type1
, i
);
4928 const char *name_2
= TYPE_FIELD_NAME (type2
, i
);
4929 int len_1
= strlen (name_1
);
4930 int len_2
= strlen (name_2
);
4932 ada_remove_trailing_digits (TYPE_FIELD_NAME (type1
, i
), &len_1
);
4933 ada_remove_trailing_digits (TYPE_FIELD_NAME (type2
, i
), &len_2
);
4935 || strncmp (TYPE_FIELD_NAME (type1
, i
),
4936 TYPE_FIELD_NAME (type2
, i
),
4944 /* Return nonzero if all the symbols in SYMS are all enumeral symbols
4945 that are deemed "identical" for practical purposes. Sometimes,
4946 enumerals are not strictly identical, but their types are so similar
4947 that they can be considered identical.
4949 For instance, consider the following code:
4951 type Color is (Black, Red, Green, Blue, White);
4952 type RGB_Color is new Color range Red .. Blue;
4954 Type RGB_Color is a subrange of an implicit type which is a copy
4955 of type Color. If we call that implicit type RGB_ColorB ("B" is
4956 for "Base Type"), then type RGB_ColorB is a copy of type Color.
4957 As a result, when an expression references any of the enumeral
4958 by name (Eg. "print green"), the expression is technically
4959 ambiguous and the user should be asked to disambiguate. But
4960 doing so would only hinder the user, since it wouldn't matter
4961 what choice he makes, the outcome would always be the same.
4962 So, for practical purposes, we consider them as the same. */
4965 symbols_are_identical_enums (const std::vector
<struct block_symbol
> &syms
)
4969 /* Before performing a thorough comparison check of each type,
4970 we perform a series of inexpensive checks. We expect that these
4971 checks will quickly fail in the vast majority of cases, and thus
4972 help prevent the unnecessary use of a more expensive comparison.
4973 Said comparison also expects us to make some of these checks
4974 (see ada_identical_enum_types_p). */
4976 /* Quick check: All symbols should have an enum type. */
4977 for (i
= 0; i
< syms
.size (); i
++)
4978 if (SYMBOL_TYPE (syms
[i
].symbol
)->code () != TYPE_CODE_ENUM
)
4981 /* Quick check: They should all have the same value. */
4982 for (i
= 1; i
< syms
.size (); i
++)
4983 if (SYMBOL_VALUE (syms
[i
].symbol
) != SYMBOL_VALUE (syms
[0].symbol
))
4986 /* Quick check: They should all have the same number of enumerals. */
4987 for (i
= 1; i
< syms
.size (); i
++)
4988 if (SYMBOL_TYPE (syms
[i
].symbol
)->num_fields ()
4989 != SYMBOL_TYPE (syms
[0].symbol
)->num_fields ())
4992 /* All the sanity checks passed, so we might have a set of
4993 identical enumeration types. Perform a more complete
4994 comparison of the type of each symbol. */
4995 for (i
= 1; i
< syms
.size (); i
++)
4996 if (!ada_identical_enum_types_p (SYMBOL_TYPE (syms
[i
].symbol
),
4997 SYMBOL_TYPE (syms
[0].symbol
)))
5003 /* Remove any non-debugging symbols in SYMS that definitely
5004 duplicate other symbols in the list (The only case I know of where
5005 this happens is when object files containing stabs-in-ecoff are
5006 linked with files containing ordinary ecoff debugging symbols (or no
5007 debugging symbols)). Modifies SYMS to squeeze out deleted entries. */
5010 remove_extra_symbols (std::vector
<struct block_symbol
> *syms
)
5014 /* We should never be called with less than 2 symbols, as there
5015 cannot be any extra symbol in that case. But it's easy to
5016 handle, since we have nothing to do in that case. */
5017 if (syms
->size () < 2)
5021 while (i
< syms
->size ())
5025 /* If two symbols have the same name and one of them is a stub type,
5026 the get rid of the stub. */
5028 if (SYMBOL_TYPE ((*syms
)[i
].symbol
)->is_stub ()
5029 && (*syms
)[i
].symbol
->linkage_name () != NULL
)
5031 for (j
= 0; j
< syms
->size (); j
++)
5034 && !SYMBOL_TYPE ((*syms
)[j
].symbol
)->is_stub ()
5035 && (*syms
)[j
].symbol
->linkage_name () != NULL
5036 && strcmp ((*syms
)[i
].symbol
->linkage_name (),
5037 (*syms
)[j
].symbol
->linkage_name ()) == 0)
5042 /* Two symbols with the same name, same class and same address
5043 should be identical. */
5045 else if ((*syms
)[i
].symbol
->linkage_name () != NULL
5046 && SYMBOL_CLASS ((*syms
)[i
].symbol
) == LOC_STATIC
5047 && is_nondebugging_type (SYMBOL_TYPE ((*syms
)[i
].symbol
)))
5049 for (j
= 0; j
< syms
->size (); j
+= 1)
5052 && (*syms
)[j
].symbol
->linkage_name () != NULL
5053 && strcmp ((*syms
)[i
].symbol
->linkage_name (),
5054 (*syms
)[j
].symbol
->linkage_name ()) == 0
5055 && SYMBOL_CLASS ((*syms
)[i
].symbol
)
5056 == SYMBOL_CLASS ((*syms
)[j
].symbol
)
5057 && SYMBOL_VALUE_ADDRESS ((*syms
)[i
].symbol
)
5058 == SYMBOL_VALUE_ADDRESS ((*syms
)[j
].symbol
))
5064 syms
->erase (syms
->begin () + i
);
5069 /* If all the remaining symbols are identical enumerals, then
5070 just keep the first one and discard the rest.
5072 Unlike what we did previously, we do not discard any entry
5073 unless they are ALL identical. This is because the symbol
5074 comparison is not a strict comparison, but rather a practical
5075 comparison. If all symbols are considered identical, then
5076 we can just go ahead and use the first one and discard the rest.
5077 But if we cannot reduce the list to a single element, we have
5078 to ask the user to disambiguate anyways. And if we have to
5079 present a multiple-choice menu, it's less confusing if the list
5080 isn't missing some choices that were identical and yet distinct. */
5081 if (symbols_are_identical_enums (*syms
))
5085 /* Given a type that corresponds to a renaming entity, use the type name
5086 to extract the scope (package name or function name, fully qualified,
5087 and following the GNAT encoding convention) where this renaming has been
5091 xget_renaming_scope (struct type
*renaming_type
)
5093 /* The renaming types adhere to the following convention:
5094 <scope>__<rename>___<XR extension>.
5095 So, to extract the scope, we search for the "___XR" extension,
5096 and then backtrack until we find the first "__". */
5098 const char *name
= renaming_type
->name ();
5099 const char *suffix
= strstr (name
, "___XR");
5102 /* Now, backtrack a bit until we find the first "__". Start looking
5103 at suffix - 3, as the <rename> part is at least one character long. */
5105 for (last
= suffix
- 3; last
> name
; last
--)
5106 if (last
[0] == '_' && last
[1] == '_')
5109 /* Make a copy of scope and return it. */
5110 return std::string (name
, last
);
5113 /* Return nonzero if NAME corresponds to a package name. */
5116 is_package_name (const char *name
)
5118 /* Here, We take advantage of the fact that no symbols are generated
5119 for packages, while symbols are generated for each function.
5120 So the condition for NAME represent a package becomes equivalent
5121 to NAME not existing in our list of symbols. There is only one
5122 small complication with library-level functions (see below). */
5124 /* If it is a function that has not been defined at library level,
5125 then we should be able to look it up in the symbols. */
5126 if (standard_lookup (name
, NULL
, VAR_DOMAIN
) != NULL
)
5129 /* Library-level function names start with "_ada_". See if function
5130 "_ada_" followed by NAME can be found. */
5132 /* Do a quick check that NAME does not contain "__", since library-level
5133 functions names cannot contain "__" in them. */
5134 if (strstr (name
, "__") != NULL
)
5137 std::string fun_name
= string_printf ("_ada_%s", name
);
5139 return (standard_lookup (fun_name
.c_str (), NULL
, VAR_DOMAIN
) == NULL
);
5142 /* Return nonzero if SYM corresponds to a renaming entity that is
5143 not visible from FUNCTION_NAME. */
5146 old_renaming_is_invisible (const struct symbol
*sym
, const char *function_name
)
5148 if (SYMBOL_CLASS (sym
) != LOC_TYPEDEF
)
5151 std::string scope
= xget_renaming_scope (SYMBOL_TYPE (sym
));
5153 /* If the rename has been defined in a package, then it is visible. */
5154 if (is_package_name (scope
.c_str ()))
5157 /* Check that the rename is in the current function scope by checking
5158 that its name starts with SCOPE. */
5160 /* If the function name starts with "_ada_", it means that it is
5161 a library-level function. Strip this prefix before doing the
5162 comparison, as the encoding for the renaming does not contain
5164 if (startswith (function_name
, "_ada_"))
5167 return !startswith (function_name
, scope
.c_str ());
5170 /* Remove entries from SYMS that corresponds to a renaming entity that
5171 is not visible from the function associated with CURRENT_BLOCK or
5172 that is superfluous due to the presence of more specific renaming
5173 information. Places surviving symbols in the initial entries of
5177 First, in cases where an object renaming is implemented as a
5178 reference variable, GNAT may produce both the actual reference
5179 variable and the renaming encoding. In this case, we discard the
5182 Second, GNAT emits a type following a specified encoding for each renaming
5183 entity. Unfortunately, STABS currently does not support the definition
5184 of types that are local to a given lexical block, so all renamings types
5185 are emitted at library level. As a consequence, if an application
5186 contains two renaming entities using the same name, and a user tries to
5187 print the value of one of these entities, the result of the ada symbol
5188 lookup will also contain the wrong renaming type.
5190 This function partially covers for this limitation by attempting to
5191 remove from the SYMS list renaming symbols that should be visible
5192 from CURRENT_BLOCK. However, there does not seem be a 100% reliable
5193 method with the current information available. The implementation
5194 below has a couple of limitations (FIXME: brobecker-2003-05-12):
5196 - When the user tries to print a rename in a function while there
5197 is another rename entity defined in a package: Normally, the
5198 rename in the function has precedence over the rename in the
5199 package, so the latter should be removed from the list. This is
5200 currently not the case.
5202 - This function will incorrectly remove valid renames if
5203 the CURRENT_BLOCK corresponds to a function which symbol name
5204 has been changed by an "Export" pragma. As a consequence,
5205 the user will be unable to print such rename entities. */
5208 remove_irrelevant_renamings (std::vector
<struct block_symbol
> *syms
,
5209 const struct block
*current_block
)
5211 struct symbol
*current_function
;
5212 const char *current_function_name
;
5214 int is_new_style_renaming
;
5216 /* If there is both a renaming foo___XR... encoded as a variable and
5217 a simple variable foo in the same block, discard the latter.
5218 First, zero out such symbols, then compress. */
5219 is_new_style_renaming
= 0;
5220 for (i
= 0; i
< syms
->size (); i
+= 1)
5222 struct symbol
*sym
= (*syms
)[i
].symbol
;
5223 const struct block
*block
= (*syms
)[i
].block
;
5227 if (sym
== NULL
|| SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
5229 name
= sym
->linkage_name ();
5230 suffix
= strstr (name
, "___XR");
5234 int name_len
= suffix
- name
;
5237 is_new_style_renaming
= 1;
5238 for (j
= 0; j
< syms
->size (); j
+= 1)
5239 if (i
!= j
&& (*syms
)[j
].symbol
!= NULL
5240 && strncmp (name
, (*syms
)[j
].symbol
->linkage_name (),
5242 && block
== (*syms
)[j
].block
)
5243 (*syms
)[j
].symbol
= NULL
;
5246 if (is_new_style_renaming
)
5250 for (j
= k
= 0; j
< syms
->size (); j
+= 1)
5251 if ((*syms
)[j
].symbol
!= NULL
)
5253 (*syms
)[k
] = (*syms
)[j
];
5260 /* Extract the function name associated to CURRENT_BLOCK.
5261 Abort if unable to do so. */
5263 if (current_block
== NULL
)
5266 current_function
= block_linkage_function (current_block
);
5267 if (current_function
== NULL
)
5270 current_function_name
= current_function
->linkage_name ();
5271 if (current_function_name
== NULL
)
5274 /* Check each of the symbols, and remove it from the list if it is
5275 a type corresponding to a renaming that is out of the scope of
5276 the current block. */
5279 while (i
< syms
->size ())
5281 if (ada_parse_renaming ((*syms
)[i
].symbol
, NULL
, NULL
, NULL
)
5282 == ADA_OBJECT_RENAMING
5283 && old_renaming_is_invisible ((*syms
)[i
].symbol
,
5284 current_function_name
))
5285 syms
->erase (syms
->begin () + i
);
5291 /* Add to RESULT all symbols from BLOCK (and its super-blocks)
5292 whose name and domain match NAME and DOMAIN respectively.
5293 If no match was found, then extend the search to "enclosing"
5294 routines (in other words, if we're inside a nested function,
5295 search the symbols defined inside the enclosing functions).
5296 If WILD_MATCH_P is nonzero, perform the naming matching in
5297 "wild" mode (see function "wild_match" for more info).
5299 Note: This function assumes that RESULT has 0 (zero) element in it. */
5302 ada_add_local_symbols (std::vector
<struct block_symbol
> &result
,
5303 const lookup_name_info
&lookup_name
,
5304 const struct block
*block
, domain_enum domain
)
5306 int block_depth
= 0;
5308 while (block
!= NULL
)
5311 ada_add_block_symbols (result
, block
, lookup_name
, domain
, NULL
);
5313 /* If we found a non-function match, assume that's the one. */
5314 if (is_nonfunction (result
))
5317 block
= BLOCK_SUPERBLOCK (block
);
5320 /* If no luck so far, try to find NAME as a local symbol in some lexically
5321 enclosing subprogram. */
5322 if (result
.empty () && block_depth
> 2)
5323 add_symbols_from_enclosing_procs (result
, lookup_name
, domain
);
5326 /* An object of this type is used as the user_data argument when
5327 calling the map_matching_symbols method. */
5331 explicit match_data (std::vector
<struct block_symbol
> *rp
)
5335 DISABLE_COPY_AND_ASSIGN (match_data
);
5337 struct objfile
*objfile
= nullptr;
5338 std::vector
<struct block_symbol
> *resultp
;
5339 struct symbol
*arg_sym
= nullptr;
5340 bool found_sym
= false;
5343 /* A callback for add_nonlocal_symbols that adds symbol, found in BSYM,
5344 to a list of symbols. DATA is a pointer to a struct match_data *
5345 containing the vector that collects the symbol list, the file that SYM
5346 must come from, a flag indicating whether a non-argument symbol has
5347 been found in the current block, and the last argument symbol
5348 passed in SYM within the current block (if any). When SYM is null,
5349 marking the end of a block, the argument symbol is added if no
5350 other has been found. */
5353 aux_add_nonlocal_symbols (struct block_symbol
*bsym
,
5354 struct match_data
*data
)
5356 const struct block
*block
= bsym
->block
;
5357 struct symbol
*sym
= bsym
->symbol
;
5361 if (!data
->found_sym
&& data
->arg_sym
!= NULL
)
5362 add_defn_to_vec (*data
->resultp
,
5363 fixup_symbol_section (data
->arg_sym
, data
->objfile
),
5365 data
->found_sym
= false;
5366 data
->arg_sym
= NULL
;
5370 if (SYMBOL_CLASS (sym
) == LOC_UNRESOLVED
)
5372 else if (SYMBOL_IS_ARGUMENT (sym
))
5373 data
->arg_sym
= sym
;
5376 data
->found_sym
= true;
5377 add_defn_to_vec (*data
->resultp
,
5378 fixup_symbol_section (sym
, data
->objfile
),
5385 /* Helper for add_nonlocal_symbols. Find symbols in DOMAIN which are
5386 targeted by renamings matching LOOKUP_NAME in BLOCK. Add these
5387 symbols to RESULT. Return whether we found such symbols. */
5390 ada_add_block_renamings (std::vector
<struct block_symbol
> &result
,
5391 const struct block
*block
,
5392 const lookup_name_info
&lookup_name
,
5395 struct using_direct
*renaming
;
5396 int defns_mark
= result
.size ();
5398 symbol_name_matcher_ftype
*name_match
5399 = ada_get_symbol_name_matcher (lookup_name
);
5401 for (renaming
= block_using (block
);
5403 renaming
= renaming
->next
)
5407 /* Avoid infinite recursions: skip this renaming if we are actually
5408 already traversing it.
5410 Currently, symbol lookup in Ada don't use the namespace machinery from
5411 C++/Fortran support: skip namespace imports that use them. */
5412 if (renaming
->searched
5413 || (renaming
->import_src
!= NULL
5414 && renaming
->import_src
[0] != '\0')
5415 || (renaming
->import_dest
!= NULL
5416 && renaming
->import_dest
[0] != '\0'))
5418 renaming
->searched
= 1;
5420 /* TODO: here, we perform another name-based symbol lookup, which can
5421 pull its own multiple overloads. In theory, we should be able to do
5422 better in this case since, in DWARF, DW_AT_import is a DIE reference,
5423 not a simple name. But in order to do this, we would need to enhance
5424 the DWARF reader to associate a symbol to this renaming, instead of a
5425 name. So, for now, we do something simpler: re-use the C++/Fortran
5426 namespace machinery. */
5427 r_name
= (renaming
->alias
!= NULL
5429 : renaming
->declaration
);
5430 if (name_match (r_name
, lookup_name
, NULL
))
5432 lookup_name_info
decl_lookup_name (renaming
->declaration
,
5433 lookup_name
.match_type ());
5434 ada_add_all_symbols (result
, block
, decl_lookup_name
, domain
,
5437 renaming
->searched
= 0;
5439 return result
.size () != defns_mark
;
5442 /* Implements compare_names, but only applying the comparision using
5443 the given CASING. */
5446 compare_names_with_case (const char *string1
, const char *string2
,
5447 enum case_sensitivity casing
)
5449 while (*string1
!= '\0' && *string2
!= '\0')
5453 if (isspace (*string1
) || isspace (*string2
))
5454 return strcmp_iw_ordered (string1
, string2
);
5456 if (casing
== case_sensitive_off
)
5458 c1
= tolower (*string1
);
5459 c2
= tolower (*string2
);
5476 return strcmp_iw_ordered (string1
, string2
);
5478 if (*string2
== '\0')
5480 if (is_name_suffix (string1
))
5487 if (*string2
== '(')
5488 return strcmp_iw_ordered (string1
, string2
);
5491 if (casing
== case_sensitive_off
)
5492 return tolower (*string1
) - tolower (*string2
);
5494 return *string1
- *string2
;
5499 /* Compare STRING1 to STRING2, with results as for strcmp.
5500 Compatible with strcmp_iw_ordered in that...
5502 strcmp_iw_ordered (STRING1, STRING2) <= 0
5506 compare_names (STRING1, STRING2) <= 0
5508 (they may differ as to what symbols compare equal). */
5511 compare_names (const char *string1
, const char *string2
)
5515 /* Similar to what strcmp_iw_ordered does, we need to perform
5516 a case-insensitive comparison first, and only resort to
5517 a second, case-sensitive, comparison if the first one was
5518 not sufficient to differentiate the two strings. */
5520 result
= compare_names_with_case (string1
, string2
, case_sensitive_off
);
5522 result
= compare_names_with_case (string1
, string2
, case_sensitive_on
);
5527 /* Convenience function to get at the Ada encoded lookup name for
5528 LOOKUP_NAME, as a C string. */
5531 ada_lookup_name (const lookup_name_info
&lookup_name
)
5533 return lookup_name
.ada ().lookup_name ().c_str ();
5536 /* Add to RESULT all non-local symbols whose name and domain match
5537 LOOKUP_NAME and DOMAIN respectively. The search is performed on
5538 GLOBAL_BLOCK symbols if GLOBAL is non-zero, or on STATIC_BLOCK
5539 symbols otherwise. */
5542 add_nonlocal_symbols (std::vector
<struct block_symbol
> &result
,
5543 const lookup_name_info
&lookup_name
,
5544 domain_enum domain
, int global
)
5546 struct match_data
data (&result
);
5548 bool is_wild_match
= lookup_name
.ada ().wild_match_p ();
5550 auto callback
= [&] (struct block_symbol
*bsym
)
5552 return aux_add_nonlocal_symbols (bsym
, &data
);
5555 for (objfile
*objfile
: current_program_space
->objfiles ())
5557 data
.objfile
= objfile
;
5559 if (objfile
->sf
!= nullptr)
5560 objfile
->sf
->qf
->map_matching_symbols (objfile
, lookup_name
,
5561 domain
, global
, callback
,
5563 ? NULL
: compare_names
));
5565 for (compunit_symtab
*cu
: objfile
->compunits ())
5567 const struct block
*global_block
5568 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cu
), GLOBAL_BLOCK
);
5570 if (ada_add_block_renamings (result
, global_block
, lookup_name
,
5572 data
.found_sym
= true;
5576 if (result
.empty () && global
&& !is_wild_match
)
5578 const char *name
= ada_lookup_name (lookup_name
);
5579 std::string bracket_name
= std::string ("<_ada_") + name
+ '>';
5580 lookup_name_info
name1 (bracket_name
, symbol_name_match_type::FULL
);
5582 for (objfile
*objfile
: current_program_space
->objfiles ())
5584 data
.objfile
= objfile
;
5585 if (objfile
->sf
!= nullptr)
5586 objfile
->sf
->qf
->map_matching_symbols (objfile
, name1
,
5587 domain
, global
, callback
,
5593 /* Find symbols in DOMAIN matching LOOKUP_NAME, in BLOCK and, if
5594 FULL_SEARCH is non-zero, enclosing scope and in global scopes,
5595 returning the number of matches. Add these to RESULT.
5597 When FULL_SEARCH is non-zero, any non-function/non-enumeral
5598 symbol match within the nest of blocks whose innermost member is BLOCK,
5599 is the one match returned (no other matches in that or
5600 enclosing blocks is returned). If there are any matches in or
5601 surrounding BLOCK, then these alone are returned.
5603 Names prefixed with "standard__" are handled specially:
5604 "standard__" is first stripped off (by the lookup_name
5605 constructor), and only static and global symbols are searched.
5607 If MADE_GLOBAL_LOOKUP_P is non-null, set it before return to whether we had
5608 to lookup global symbols. */
5611 ada_add_all_symbols (std::vector
<struct block_symbol
> &result
,
5612 const struct block
*block
,
5613 const lookup_name_info
&lookup_name
,
5616 int *made_global_lookup_p
)
5620 if (made_global_lookup_p
)
5621 *made_global_lookup_p
= 0;
5623 /* Special case: If the user specifies a symbol name inside package
5624 Standard, do a non-wild matching of the symbol name without
5625 the "standard__" prefix. This was primarily introduced in order
5626 to allow the user to specifically access the standard exceptions
5627 using, for instance, Standard.Constraint_Error when Constraint_Error
5628 is ambiguous (due to the user defining its own Constraint_Error
5629 entity inside its program). */
5630 if (lookup_name
.ada ().standard_p ())
5633 /* Check the non-global symbols. If we have ANY match, then we're done. */
5638 ada_add_local_symbols (result
, lookup_name
, block
, domain
);
5641 /* In the !full_search case we're are being called by
5642 iterate_over_symbols, and we don't want to search
5644 ada_add_block_symbols (result
, block
, lookup_name
, domain
, NULL
);
5646 if (!result
.empty () || !full_search
)
5650 /* No non-global symbols found. Check our cache to see if we have
5651 already performed this search before. If we have, then return
5654 if (lookup_cached_symbol (ada_lookup_name (lookup_name
),
5655 domain
, &sym
, &block
))
5658 add_defn_to_vec (result
, sym
, block
);
5662 if (made_global_lookup_p
)
5663 *made_global_lookup_p
= 1;
5665 /* Search symbols from all global blocks. */
5667 add_nonlocal_symbols (result
, lookup_name
, domain
, 1);
5669 /* Now add symbols from all per-file blocks if we've gotten no hits
5670 (not strictly correct, but perhaps better than an error). */
5672 if (result
.empty ())
5673 add_nonlocal_symbols (result
, lookup_name
, domain
, 0);
5676 /* Find symbols in DOMAIN matching LOOKUP_NAME, in BLOCK and, if FULL_SEARCH
5677 is non-zero, enclosing scope and in global scopes.
5679 Returns (SYM,BLOCK) tuples, indicating the symbols found and the
5680 blocks and symbol tables (if any) in which they were found.
5682 When full_search is non-zero, any non-function/non-enumeral
5683 symbol match within the nest of blocks whose innermost member is BLOCK,
5684 is the one match returned (no other matches in that or
5685 enclosing blocks is returned). If there are any matches in or
5686 surrounding BLOCK, then these alone are returned.
5688 Names prefixed with "standard__" are handled specially: "standard__"
5689 is first stripped off, and only static and global symbols are searched. */
5691 static std::vector
<struct block_symbol
>
5692 ada_lookup_symbol_list_worker (const lookup_name_info
&lookup_name
,
5693 const struct block
*block
,
5697 int syms_from_global_search
;
5698 std::vector
<struct block_symbol
> results
;
5700 ada_add_all_symbols (results
, block
, lookup_name
,
5701 domain
, full_search
, &syms_from_global_search
);
5703 remove_extra_symbols (&results
);
5705 if (results
.empty () && full_search
&& syms_from_global_search
)
5706 cache_symbol (ada_lookup_name (lookup_name
), domain
, NULL
, NULL
);
5708 if (results
.size () == 1 && full_search
&& syms_from_global_search
)
5709 cache_symbol (ada_lookup_name (lookup_name
), domain
,
5710 results
[0].symbol
, results
[0].block
);
5712 remove_irrelevant_renamings (&results
, block
);
5716 /* Find symbols in DOMAIN matching NAME, in BLOCK and enclosing scope and
5717 in global scopes, returning (SYM,BLOCK) tuples.
5719 See ada_lookup_symbol_list_worker for further details. */
5721 std::vector
<struct block_symbol
>
5722 ada_lookup_symbol_list (const char *name
, const struct block
*block
,
5725 symbol_name_match_type name_match_type
= name_match_type_from_name (name
);
5726 lookup_name_info
lookup_name (name
, name_match_type
);
5728 return ada_lookup_symbol_list_worker (lookup_name
, block
, domain
, 1);
5731 /* The result is as for ada_lookup_symbol_list with FULL_SEARCH set
5732 to 1, but choosing the first symbol found if there are multiple
5735 The result is stored in *INFO, which must be non-NULL.
5736 If no match is found, INFO->SYM is set to NULL. */
5739 ada_lookup_encoded_symbol (const char *name
, const struct block
*block
,
5741 struct block_symbol
*info
)
5743 /* Since we already have an encoded name, wrap it in '<>' to force a
5744 verbatim match. Otherwise, if the name happens to not look like
5745 an encoded name (because it doesn't include a "__"),
5746 ada_lookup_name_info would re-encode/fold it again, and that
5747 would e.g., incorrectly lowercase object renaming names like
5748 "R28b" -> "r28b". */
5749 std::string verbatim
= add_angle_brackets (name
);
5751 gdb_assert (info
!= NULL
);
5752 *info
= ada_lookup_symbol (verbatim
.c_str (), block
, domain
);
5755 /* Return a symbol in DOMAIN matching NAME, in BLOCK0 and enclosing
5756 scope and in global scopes, or NULL if none. NAME is folded and
5757 encoded first. Otherwise, the result is as for ada_lookup_symbol_list,
5758 choosing the first symbol if there are multiple choices. */
5761 ada_lookup_symbol (const char *name
, const struct block
*block0
,
5764 std::vector
<struct block_symbol
> candidates
5765 = ada_lookup_symbol_list (name
, block0
, domain
);
5767 if (candidates
.empty ())
5770 block_symbol info
= candidates
[0];
5771 info
.symbol
= fixup_symbol_section (info
.symbol
, NULL
);
5776 /* True iff STR is a possible encoded suffix of a normal Ada name
5777 that is to be ignored for matching purposes. Suffixes of parallel
5778 names (e.g., XVE) are not included here. Currently, the possible suffixes
5779 are given by any of the regular expressions:
5781 [.$][0-9]+ [nested subprogram suffix, on platforms such as GNU/Linux]
5782 ___[0-9]+ [nested subprogram suffix, on platforms such as HP/UX]
5783 TKB [subprogram suffix for task bodies]
5784 _E[0-9]+[bs]$ [protected object entry suffixes]
5785 (X[nb]*)?((\$|__)[0-9](_?[0-9]+)|___(JM|LJM|X([FDBUP].*|R[^T]?)))?$
5787 Also, any leading "__[0-9]+" sequence is skipped before the suffix
5788 match is performed. This sequence is used to differentiate homonyms,
5789 is an optional part of a valid name suffix. */
5792 is_name_suffix (const char *str
)
5795 const char *matching
;
5796 const int len
= strlen (str
);
5798 /* Skip optional leading __[0-9]+. */
5800 if (len
> 3 && str
[0] == '_' && str
[1] == '_' && isdigit (str
[2]))
5803 while (isdigit (str
[0]))
5809 if (str
[0] == '.' || str
[0] == '$')
5812 while (isdigit (matching
[0]))
5814 if (matching
[0] == '\0')
5820 if (len
> 3 && str
[0] == '_' && str
[1] == '_' && str
[2] == '_')
5823 while (isdigit (matching
[0]))
5825 if (matching
[0] == '\0')
5829 /* "TKB" suffixes are used for subprograms implementing task bodies. */
5831 if (strcmp (str
, "TKB") == 0)
5835 /* FIXME: brobecker/2005-09-23: Protected Object subprograms end
5836 with a N at the end. Unfortunately, the compiler uses the same
5837 convention for other internal types it creates. So treating
5838 all entity names that end with an "N" as a name suffix causes
5839 some regressions. For instance, consider the case of an enumerated
5840 type. To support the 'Image attribute, it creates an array whose
5842 Having a single character like this as a suffix carrying some
5843 information is a bit risky. Perhaps we should change the encoding
5844 to be something like "_N" instead. In the meantime, do not do
5845 the following check. */
5846 /* Protected Object Subprograms */
5847 if (len
== 1 && str
[0] == 'N')
5852 if (len
> 3 && str
[0] == '_' && str
[1] == 'E' && isdigit (str
[2]))
5855 while (isdigit (matching
[0]))
5857 if ((matching
[0] == 'b' || matching
[0] == 's')
5858 && matching
[1] == '\0')
5862 /* ??? We should not modify STR directly, as we are doing below. This
5863 is fine in this case, but may become problematic later if we find
5864 that this alternative did not work, and want to try matching
5865 another one from the begining of STR. Since we modified it, we
5866 won't be able to find the begining of the string anymore! */
5870 while (str
[0] != '_' && str
[0] != '\0')
5872 if (str
[0] != 'n' && str
[0] != 'b')
5878 if (str
[0] == '\000')
5883 if (str
[1] != '_' || str
[2] == '\000')
5887 if (strcmp (str
+ 3, "JM") == 0)
5889 /* FIXME: brobecker/2004-09-30: GNAT will soon stop using
5890 the LJM suffix in favor of the JM one. But we will
5891 still accept LJM as a valid suffix for a reasonable
5892 amount of time, just to allow ourselves to debug programs
5893 compiled using an older version of GNAT. */
5894 if (strcmp (str
+ 3, "LJM") == 0)
5898 if (str
[4] == 'F' || str
[4] == 'D' || str
[4] == 'B'
5899 || str
[4] == 'U' || str
[4] == 'P')
5901 if (str
[4] == 'R' && str
[5] != 'T')
5905 if (!isdigit (str
[2]))
5907 for (k
= 3; str
[k
] != '\0'; k
+= 1)
5908 if (!isdigit (str
[k
]) && str
[k
] != '_')
5912 if (str
[0] == '$' && isdigit (str
[1]))
5914 for (k
= 2; str
[k
] != '\0'; k
+= 1)
5915 if (!isdigit (str
[k
]) && str
[k
] != '_')
5922 /* Return non-zero if the string starting at NAME and ending before
5923 NAME_END contains no capital letters. */
5926 is_valid_name_for_wild_match (const char *name0
)
5928 std::string decoded_name
= ada_decode (name0
);
5931 /* If the decoded name starts with an angle bracket, it means that
5932 NAME0 does not follow the GNAT encoding format. It should then
5933 not be allowed as a possible wild match. */
5934 if (decoded_name
[0] == '<')
5937 for (i
=0; decoded_name
[i
] != '\0'; i
++)
5938 if (isalpha (decoded_name
[i
]) && !islower (decoded_name
[i
]))
5944 /* Advance *NAMEP to next occurrence in the string NAME0 of the TARGET0
5945 character which could start a simple name. Assumes that *NAMEP points
5946 somewhere inside the string beginning at NAME0. */
5949 advance_wild_match (const char **namep
, const char *name0
, char target0
)
5951 const char *name
= *namep
;
5961 if ((t1
>= 'a' && t1
<= 'z') || (t1
>= '0' && t1
<= '9'))
5964 if (name
== name0
+ 5 && startswith (name0
, "_ada"))
5969 else if (t1
== '_' && ((name
[2] >= 'a' && name
[2] <= 'z')
5970 || name
[2] == target0
))
5975 else if (t1
== '_' && name
[2] == 'B' && name
[3] == '_')
5977 /* Names like "pkg__B_N__name", where N is a number, are
5978 block-local. We can handle these by simply skipping
5985 else if ((t0
>= 'a' && t0
<= 'z') || (t0
>= '0' && t0
<= '9'))
5995 /* Return true iff NAME encodes a name of the form prefix.PATN.
5996 Ignores any informational suffixes of NAME (i.e., for which
5997 is_name_suffix is true). Assumes that PATN is a lower-cased Ada
6001 wild_match (const char *name
, const char *patn
)
6004 const char *name0
= name
;
6008 const char *match
= name
;
6012 for (name
+= 1, p
= patn
+ 1; *p
!= '\0'; name
+= 1, p
+= 1)
6015 if (*p
== '\0' && is_name_suffix (name
))
6016 return match
== name0
|| is_valid_name_for_wild_match (name0
);
6018 if (name
[-1] == '_')
6021 if (!advance_wild_match (&name
, name0
, *patn
))
6026 /* Add symbols from BLOCK matching LOOKUP_NAME in DOMAIN to RESULT (if
6027 necessary). OBJFILE is the section containing BLOCK. */
6030 ada_add_block_symbols (std::vector
<struct block_symbol
> &result
,
6031 const struct block
*block
,
6032 const lookup_name_info
&lookup_name
,
6033 domain_enum domain
, struct objfile
*objfile
)
6035 struct block_iterator iter
;
6036 /* A matching argument symbol, if any. */
6037 struct symbol
*arg_sym
;
6038 /* Set true when we find a matching non-argument symbol. */
6044 for (sym
= block_iter_match_first (block
, lookup_name
, &iter
);
6046 sym
= block_iter_match_next (lookup_name
, &iter
))
6048 if (symbol_matches_domain (sym
->language (), SYMBOL_DOMAIN (sym
), domain
))
6050 if (SYMBOL_CLASS (sym
) != LOC_UNRESOLVED
)
6052 if (SYMBOL_IS_ARGUMENT (sym
))
6057 add_defn_to_vec (result
,
6058 fixup_symbol_section (sym
, objfile
),
6065 /* Handle renamings. */
6067 if (ada_add_block_renamings (result
, block
, lookup_name
, domain
))
6070 if (!found_sym
&& arg_sym
!= NULL
)
6072 add_defn_to_vec (result
,
6073 fixup_symbol_section (arg_sym
, objfile
),
6077 if (!lookup_name
.ada ().wild_match_p ())
6081 const std::string
&ada_lookup_name
= lookup_name
.ada ().lookup_name ();
6082 const char *name
= ada_lookup_name
.c_str ();
6083 size_t name_len
= ada_lookup_name
.size ();
6085 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
6087 if (symbol_matches_domain (sym
->language (),
6088 SYMBOL_DOMAIN (sym
), domain
))
6092 cmp
= (int) '_' - (int) sym
->linkage_name ()[0];
6095 cmp
= !startswith (sym
->linkage_name (), "_ada_");
6097 cmp
= strncmp (name
, sym
->linkage_name () + 5,
6102 && is_name_suffix (sym
->linkage_name () + name_len
+ 5))
6104 if (SYMBOL_CLASS (sym
) != LOC_UNRESOLVED
)
6106 if (SYMBOL_IS_ARGUMENT (sym
))
6111 add_defn_to_vec (result
,
6112 fixup_symbol_section (sym
, objfile
),
6120 /* NOTE: This really shouldn't be needed for _ada_ symbols.
6121 They aren't parameters, right? */
6122 if (!found_sym
&& arg_sym
!= NULL
)
6124 add_defn_to_vec (result
,
6125 fixup_symbol_section (arg_sym
, objfile
),
6132 /* Symbol Completion */
6137 ada_lookup_name_info::matches
6138 (const char *sym_name
,
6139 symbol_name_match_type match_type
,
6140 completion_match_result
*comp_match_res
) const
6143 const char *text
= m_encoded_name
.c_str ();
6144 size_t text_len
= m_encoded_name
.size ();
6146 /* First, test against the fully qualified name of the symbol. */
6148 if (strncmp (sym_name
, text
, text_len
) == 0)
6151 std::string decoded_name
= ada_decode (sym_name
);
6152 if (match
&& !m_encoded_p
)
6154 /* One needed check before declaring a positive match is to verify
6155 that iff we are doing a verbatim match, the decoded version
6156 of the symbol name starts with '<'. Otherwise, this symbol name
6157 is not a suitable completion. */
6159 bool has_angle_bracket
= (decoded_name
[0] == '<');
6160 match
= (has_angle_bracket
== m_verbatim_p
);
6163 if (match
&& !m_verbatim_p
)
6165 /* When doing non-verbatim match, another check that needs to
6166 be done is to verify that the potentially matching symbol name
6167 does not include capital letters, because the ada-mode would
6168 not be able to understand these symbol names without the
6169 angle bracket notation. */
6172 for (tmp
= sym_name
; *tmp
!= '\0' && !isupper (*tmp
); tmp
++);
6177 /* Second: Try wild matching... */
6179 if (!match
&& m_wild_match_p
)
6181 /* Since we are doing wild matching, this means that TEXT
6182 may represent an unqualified symbol name. We therefore must
6183 also compare TEXT against the unqualified name of the symbol. */
6184 sym_name
= ada_unqualified_name (decoded_name
.c_str ());
6186 if (strncmp (sym_name
, text
, text_len
) == 0)
6190 /* Finally: If we found a match, prepare the result to return. */
6195 if (comp_match_res
!= NULL
)
6197 std::string
&match_str
= comp_match_res
->match
.storage ();
6200 match_str
= ada_decode (sym_name
);
6204 match_str
= add_angle_brackets (sym_name
);
6206 match_str
= sym_name
;
6210 comp_match_res
->set_match (match_str
.c_str ());
6218 /* Return non-zero if TYPE is a pointer to the GNAT dispatch table used
6219 for tagged types. */
6222 ada_is_dispatch_table_ptr_type (struct type
*type
)
6226 if (type
->code () != TYPE_CODE_PTR
)
6229 name
= TYPE_TARGET_TYPE (type
)->name ();
6233 return (strcmp (name
, "ada__tags__dispatch_table") == 0);
6236 /* Return non-zero if TYPE is an interface tag. */
6239 ada_is_interface_tag (struct type
*type
)
6241 const char *name
= type
->name ();
6246 return (strcmp (name
, "ada__tags__interface_tag") == 0);
6249 /* True if field number FIELD_NUM in struct or union type TYPE is supposed
6250 to be invisible to users. */
6253 ada_is_ignored_field (struct type
*type
, int field_num
)
6255 if (field_num
< 0 || field_num
> type
->num_fields ())
6258 /* Check the name of that field. */
6260 const char *name
= TYPE_FIELD_NAME (type
, field_num
);
6262 /* Anonymous field names should not be printed.
6263 brobecker/2007-02-20: I don't think this can actually happen
6264 but we don't want to print the value of anonymous fields anyway. */
6268 /* Normally, fields whose name start with an underscore ("_")
6269 are fields that have been internally generated by the compiler,
6270 and thus should not be printed. The "_parent" field is special,
6271 however: This is a field internally generated by the compiler
6272 for tagged types, and it contains the components inherited from
6273 the parent type. This field should not be printed as is, but
6274 should not be ignored either. */
6275 if (name
[0] == '_' && !startswith (name
, "_parent"))
6279 /* If this is the dispatch table of a tagged type or an interface tag,
6281 if (ada_is_tagged_type (type
, 1)
6282 && (ada_is_dispatch_table_ptr_type (type
->field (field_num
).type ())
6283 || ada_is_interface_tag (type
->field (field_num
).type ())))
6286 /* Not a special field, so it should not be ignored. */
6290 /* True iff TYPE has a tag field. If REFOK, then TYPE may also be a
6291 pointer or reference type whose ultimate target has a tag field. */
6294 ada_is_tagged_type (struct type
*type
, int refok
)
6296 return (ada_lookup_struct_elt_type (type
, "_tag", refok
, 1) != NULL
);
6299 /* True iff TYPE represents the type of X'Tag */
6302 ada_is_tag_type (struct type
*type
)
6304 type
= ada_check_typedef (type
);
6306 if (type
== NULL
|| type
->code () != TYPE_CODE_PTR
)
6310 const char *name
= ada_type_name (TYPE_TARGET_TYPE (type
));
6312 return (name
!= NULL
6313 && strcmp (name
, "ada__tags__dispatch_table") == 0);
6317 /* The type of the tag on VAL. */
6319 static struct type
*
6320 ada_tag_type (struct value
*val
)
6322 return ada_lookup_struct_elt_type (value_type (val
), "_tag", 1, 0);
6325 /* Return 1 if TAG follows the old scheme for Ada tags (used for Ada 95,
6326 retired at Ada 05). */
6329 is_ada95_tag (struct value
*tag
)
6331 return ada_value_struct_elt (tag
, "tsd", 1) != NULL
;
6334 /* The value of the tag on VAL. */
6336 static struct value
*
6337 ada_value_tag (struct value
*val
)
6339 return ada_value_struct_elt (val
, "_tag", 0);
6342 /* The value of the tag on the object of type TYPE whose contents are
6343 saved at VALADDR, if it is non-null, or is at memory address
6346 static struct value
*
6347 value_tag_from_contents_and_address (struct type
*type
,
6348 const gdb_byte
*valaddr
,
6351 int tag_byte_offset
;
6352 struct type
*tag_type
;
6354 if (find_struct_field ("_tag", type
, 0, &tag_type
, &tag_byte_offset
,
6357 const gdb_byte
*valaddr1
= ((valaddr
== NULL
)
6359 : valaddr
+ tag_byte_offset
);
6360 CORE_ADDR address1
= (address
== 0) ? 0 : address
+ tag_byte_offset
;
6362 return value_from_contents_and_address (tag_type
, valaddr1
, address1
);
6367 static struct type
*
6368 type_from_tag (struct value
*tag
)
6370 gdb::unique_xmalloc_ptr
<char> type_name
= ada_tag_name (tag
);
6372 if (type_name
!= NULL
)
6373 return ada_find_any_type (ada_encode (type_name
.get ()).c_str ());
6377 /* Given a value OBJ of a tagged type, return a value of this
6378 type at the base address of the object. The base address, as
6379 defined in Ada.Tags, it is the address of the primary tag of
6380 the object, and therefore where the field values of its full
6381 view can be fetched. */
6384 ada_tag_value_at_base_address (struct value
*obj
)
6387 LONGEST offset_to_top
= 0;
6388 struct type
*ptr_type
, *obj_type
;
6390 CORE_ADDR base_address
;
6392 obj_type
= value_type (obj
);
6394 /* It is the responsability of the caller to deref pointers. */
6396 if (obj_type
->code () == TYPE_CODE_PTR
|| obj_type
->code () == TYPE_CODE_REF
)
6399 tag
= ada_value_tag (obj
);
6403 /* Base addresses only appeared with Ada 05 and multiple inheritance. */
6405 if (is_ada95_tag (tag
))
6408 ptr_type
= language_lookup_primitive_type
6409 (language_def (language_ada
), target_gdbarch(), "storage_offset");
6410 ptr_type
= lookup_pointer_type (ptr_type
);
6411 val
= value_cast (ptr_type
, tag
);
6415 /* It is perfectly possible that an exception be raised while
6416 trying to determine the base address, just like for the tag;
6417 see ada_tag_name for more details. We do not print the error
6418 message for the same reason. */
6422 offset_to_top
= value_as_long (value_ind (value_ptradd (val
, -2)));
6425 catch (const gdb_exception_error
&e
)
6430 /* If offset is null, nothing to do. */
6432 if (offset_to_top
== 0)
6435 /* -1 is a special case in Ada.Tags; however, what should be done
6436 is not quite clear from the documentation. So do nothing for
6439 if (offset_to_top
== -1)
6442 /* OFFSET_TO_TOP used to be a positive value to be subtracted
6443 from the base address. This was however incompatible with
6444 C++ dispatch table: C++ uses a *negative* value to *add*
6445 to the base address. Ada's convention has therefore been
6446 changed in GNAT 19.0w 20171023: since then, C++ and Ada
6447 use the same convention. Here, we support both cases by
6448 checking the sign of OFFSET_TO_TOP. */
6450 if (offset_to_top
> 0)
6451 offset_to_top
= -offset_to_top
;
6453 base_address
= value_address (obj
) + offset_to_top
;
6454 tag
= value_tag_from_contents_and_address (obj_type
, NULL
, base_address
);
6456 /* Make sure that we have a proper tag at the new address.
6457 Otherwise, offset_to_top is bogus (which can happen when
6458 the object is not initialized yet). */
6463 obj_type
= type_from_tag (tag
);
6468 return value_from_contents_and_address (obj_type
, NULL
, base_address
);
6471 /* Return the "ada__tags__type_specific_data" type. */
6473 static struct type
*
6474 ada_get_tsd_type (struct inferior
*inf
)
6476 struct ada_inferior_data
*data
= get_ada_inferior_data (inf
);
6478 if (data
->tsd_type
== 0)
6479 data
->tsd_type
= ada_find_any_type ("ada__tags__type_specific_data");
6480 return data
->tsd_type
;
6483 /* Return the TSD (type-specific data) associated to the given TAG.
6484 TAG is assumed to be the tag of a tagged-type entity.
6486 May return NULL if we are unable to get the TSD. */
6488 static struct value
*
6489 ada_get_tsd_from_tag (struct value
*tag
)
6494 /* First option: The TSD is simply stored as a field of our TAG.
6495 Only older versions of GNAT would use this format, but we have
6496 to test it first, because there are no visible markers for
6497 the current approach except the absence of that field. */
6499 val
= ada_value_struct_elt (tag
, "tsd", 1);
6503 /* Try the second representation for the dispatch table (in which
6504 there is no explicit 'tsd' field in the referent of the tag pointer,
6505 and instead the tsd pointer is stored just before the dispatch
6508 type
= ada_get_tsd_type (current_inferior());
6511 type
= lookup_pointer_type (lookup_pointer_type (type
));
6512 val
= value_cast (type
, tag
);
6515 return value_ind (value_ptradd (val
, -1));
6518 /* Given the TSD of a tag (type-specific data), return a string
6519 containing the name of the associated type.
6521 May return NULL if we are unable to determine the tag name. */
6523 static gdb::unique_xmalloc_ptr
<char>
6524 ada_tag_name_from_tsd (struct value
*tsd
)
6529 val
= ada_value_struct_elt (tsd
, "expanded_name", 1);
6532 gdb::unique_xmalloc_ptr
<char> buffer
6533 = target_read_string (value_as_address (val
), INT_MAX
);
6534 if (buffer
== nullptr)
6537 for (p
= buffer
.get (); *p
!= '\0'; ++p
)
6546 /* The type name of the dynamic type denoted by the 'tag value TAG, as
6549 Return NULL if the TAG is not an Ada tag, or if we were unable to
6550 determine the name of that tag. */
6552 gdb::unique_xmalloc_ptr
<char>
6553 ada_tag_name (struct value
*tag
)
6555 gdb::unique_xmalloc_ptr
<char> name
;
6557 if (!ada_is_tag_type (value_type (tag
)))
6560 /* It is perfectly possible that an exception be raised while trying
6561 to determine the TAG's name, even under normal circumstances:
6562 The associated variable may be uninitialized or corrupted, for
6563 instance. We do not let any exception propagate past this point.
6564 instead we return NULL.
6566 We also do not print the error message either (which often is very
6567 low-level (Eg: "Cannot read memory at 0x[...]"), but instead let
6568 the caller print a more meaningful message if necessary. */
6571 struct value
*tsd
= ada_get_tsd_from_tag (tag
);
6574 name
= ada_tag_name_from_tsd (tsd
);
6576 catch (const gdb_exception_error
&e
)
6583 /* The parent type of TYPE, or NULL if none. */
6586 ada_parent_type (struct type
*type
)
6590 type
= ada_check_typedef (type
);
6592 if (type
== NULL
|| type
->code () != TYPE_CODE_STRUCT
)
6595 for (i
= 0; i
< type
->num_fields (); i
+= 1)
6596 if (ada_is_parent_field (type
, i
))
6598 struct type
*parent_type
= type
->field (i
).type ();
6600 /* If the _parent field is a pointer, then dereference it. */
6601 if (parent_type
->code () == TYPE_CODE_PTR
)
6602 parent_type
= TYPE_TARGET_TYPE (parent_type
);
6603 /* If there is a parallel XVS type, get the actual base type. */
6604 parent_type
= ada_get_base_type (parent_type
);
6606 return ada_check_typedef (parent_type
);
6612 /* True iff field number FIELD_NUM of structure type TYPE contains the
6613 parent-type (inherited) fields of a derived type. Assumes TYPE is
6614 a structure type with at least FIELD_NUM+1 fields. */
6617 ada_is_parent_field (struct type
*type
, int field_num
)
6619 const char *name
= TYPE_FIELD_NAME (ada_check_typedef (type
), field_num
);
6621 return (name
!= NULL
6622 && (startswith (name
, "PARENT")
6623 || startswith (name
, "_parent")));
6626 /* True iff field number FIELD_NUM of structure type TYPE is a
6627 transparent wrapper field (which should be silently traversed when doing
6628 field selection and flattened when printing). Assumes TYPE is a
6629 structure type with at least FIELD_NUM+1 fields. Such fields are always
6633 ada_is_wrapper_field (struct type
*type
, int field_num
)
6635 const char *name
= TYPE_FIELD_NAME (type
, field_num
);
6637 if (name
!= NULL
&& strcmp (name
, "RETVAL") == 0)
6639 /* This happens in functions with "out" or "in out" parameters
6640 which are passed by copy. For such functions, GNAT describes
6641 the function's return type as being a struct where the return
6642 value is in a field called RETVAL, and where the other "out"
6643 or "in out" parameters are fields of that struct. This is not
6648 return (name
!= NULL
6649 && (startswith (name
, "PARENT")
6650 || strcmp (name
, "REP") == 0
6651 || startswith (name
, "_parent")
6652 || name
[0] == 'S' || name
[0] == 'R' || name
[0] == 'O'));
6655 /* True iff field number FIELD_NUM of structure or union type TYPE
6656 is a variant wrapper. Assumes TYPE is a structure type with at least
6657 FIELD_NUM+1 fields. */
6660 ada_is_variant_part (struct type
*type
, int field_num
)
6662 /* Only Ada types are eligible. */
6663 if (!ADA_TYPE_P (type
))
6666 struct type
*field_type
= type
->field (field_num
).type ();
6668 return (field_type
->code () == TYPE_CODE_UNION
6669 || (is_dynamic_field (type
, field_num
)
6670 && (TYPE_TARGET_TYPE (field_type
)->code ()
6671 == TYPE_CODE_UNION
)));
6674 /* Assuming that VAR_TYPE is a variant wrapper (type of the variant part)
6675 whose discriminants are contained in the record type OUTER_TYPE,
6676 returns the type of the controlling discriminant for the variant.
6677 May return NULL if the type could not be found. */
6680 ada_variant_discrim_type (struct type
*var_type
, struct type
*outer_type
)
6682 const char *name
= ada_variant_discrim_name (var_type
);
6684 return ada_lookup_struct_elt_type (outer_type
, name
, 1, 1);
6687 /* Assuming that TYPE is the type of a variant wrapper, and FIELD_NUM is a
6688 valid field number within it, returns 1 iff field FIELD_NUM of TYPE
6689 represents a 'when others' clause; otherwise 0. */
6692 ada_is_others_clause (struct type
*type
, int field_num
)
6694 const char *name
= TYPE_FIELD_NAME (type
, field_num
);
6696 return (name
!= NULL
&& name
[0] == 'O');
6699 /* Assuming that TYPE0 is the type of the variant part of a record,
6700 returns the name of the discriminant controlling the variant.
6701 The value is valid until the next call to ada_variant_discrim_name. */
6704 ada_variant_discrim_name (struct type
*type0
)
6706 static std::string result
;
6709 const char *discrim_end
;
6710 const char *discrim_start
;
6712 if (type0
->code () == TYPE_CODE_PTR
)
6713 type
= TYPE_TARGET_TYPE (type0
);
6717 name
= ada_type_name (type
);
6719 if (name
== NULL
|| name
[0] == '\000')
6722 for (discrim_end
= name
+ strlen (name
) - 6; discrim_end
!= name
;
6725 if (startswith (discrim_end
, "___XVN"))
6728 if (discrim_end
== name
)
6731 for (discrim_start
= discrim_end
; discrim_start
!= name
+ 3;
6734 if (discrim_start
== name
+ 1)
6736 if ((discrim_start
> name
+ 3
6737 && startswith (discrim_start
- 3, "___"))
6738 || discrim_start
[-1] == '.')
6742 result
= std::string (discrim_start
, discrim_end
- discrim_start
);
6743 return result
.c_str ();
6746 /* Scan STR for a subtype-encoded number, beginning at position K.
6747 Put the position of the character just past the number scanned in
6748 *NEW_K, if NEW_K!=NULL. Put the scanned number in *R, if R!=NULL.
6749 Return 1 if there was a valid number at the given position, and 0
6750 otherwise. A "subtype-encoded" number consists of the absolute value
6751 in decimal, followed by the letter 'm' to indicate a negative number.
6752 Assumes 0m does not occur. */
6755 ada_scan_number (const char str
[], int k
, LONGEST
* R
, int *new_k
)
6759 if (!isdigit (str
[k
]))
6762 /* Do it the hard way so as not to make any assumption about
6763 the relationship of unsigned long (%lu scan format code) and
6766 while (isdigit (str
[k
]))
6768 RU
= RU
* 10 + (str
[k
] - '0');
6775 *R
= (-(LONGEST
) (RU
- 1)) - 1;
6781 /* NOTE on the above: Technically, C does not say what the results of
6782 - (LONGEST) RU or (LONGEST) -RU are for RU == largest positive
6783 number representable as a LONGEST (although either would probably work
6784 in most implementations). When RU>0, the locution in the then branch
6785 above is always equivalent to the negative of RU. */
6792 /* Assuming that TYPE is a variant part wrapper type (a VARIANTS field),
6793 and FIELD_NUM is a valid field number within it, returns 1 iff VAL is
6794 in the range encoded by field FIELD_NUM of TYPE; otherwise 0. */
6797 ada_in_variant (LONGEST val
, struct type
*type
, int field_num
)
6799 const char *name
= TYPE_FIELD_NAME (type
, field_num
);
6813 if (!ada_scan_number (name
, p
+ 1, &W
, &p
))
6823 if (!ada_scan_number (name
, p
+ 1, &L
, &p
)
6824 || name
[p
] != 'T' || !ada_scan_number (name
, p
+ 1, &U
, &p
))
6826 if (val
>= L
&& val
<= U
)
6838 /* FIXME: Lots of redundancy below. Try to consolidate. */
6840 /* Given a value ARG1 (offset by OFFSET bytes) of a struct or union type
6841 ARG_TYPE, extract and return the value of one of its (non-static)
6842 fields. FIELDNO says which field. Differs from value_primitive_field
6843 only in that it can handle packed values of arbitrary type. */
6846 ada_value_primitive_field (struct value
*arg1
, int offset
, int fieldno
,
6847 struct type
*arg_type
)
6851 arg_type
= ada_check_typedef (arg_type
);
6852 type
= arg_type
->field (fieldno
).type ();
6854 /* Handle packed fields. It might be that the field is not packed
6855 relative to its containing structure, but the structure itself is
6856 packed; in this case we must take the bit-field path. */
6857 if (TYPE_FIELD_BITSIZE (arg_type
, fieldno
) != 0 || value_bitpos (arg1
) != 0)
6859 int bit_pos
= TYPE_FIELD_BITPOS (arg_type
, fieldno
);
6860 int bit_size
= TYPE_FIELD_BITSIZE (arg_type
, fieldno
);
6862 return ada_value_primitive_packed_val (arg1
, value_contents (arg1
),
6863 offset
+ bit_pos
/ 8,
6864 bit_pos
% 8, bit_size
, type
);
6867 return value_primitive_field (arg1
, offset
, fieldno
, arg_type
);
6870 /* Find field with name NAME in object of type TYPE. If found,
6871 set the following for each argument that is non-null:
6872 - *FIELD_TYPE_P to the field's type;
6873 - *BYTE_OFFSET_P to OFFSET + the byte offset of the field within
6874 an object of that type;
6875 - *BIT_OFFSET_P to the bit offset modulo byte size of the field;
6876 - *BIT_SIZE_P to its size in bits if the field is packed, and
6878 If INDEX_P is non-null, increment *INDEX_P by the number of source-visible
6879 fields up to but not including the desired field, or by the total
6880 number of fields if not found. A NULL value of NAME never
6881 matches; the function just counts visible fields in this case.
6883 Notice that we need to handle when a tagged record hierarchy
6884 has some components with the same name, like in this scenario:
6886 type Top_T is tagged record
6892 type Middle_T is new Top.Top_T with record
6893 N : Character := 'a';
6897 type Bottom_T is new Middle.Middle_T with record
6899 C : Character := '5';
6901 A : Character := 'J';
6904 Let's say we now have a variable declared and initialized as follow:
6906 TC : Top_A := new Bottom_T;
6908 And then we use this variable to call this function
6910 procedure Assign (Obj: in out Top_T; TV : Integer);
6914 Assign (Top_T (B), 12);
6916 Now, we're in the debugger, and we're inside that procedure
6917 then and we want to print the value of obj.c:
6919 Usually, the tagged record or one of the parent type owns the
6920 component to print and there's no issue but in this particular
6921 case, what does it mean to ask for Obj.C? Since the actual
6922 type for object is type Bottom_T, it could mean two things: type
6923 component C from the Middle_T view, but also component C from
6924 Bottom_T. So in that "undefined" case, when the component is
6925 not found in the non-resolved type (which includes all the
6926 components of the parent type), then resolve it and see if we
6927 get better luck once expanded.
6929 In the case of homonyms in the derived tagged type, we don't
6930 guaranty anything, and pick the one that's easiest for us
6933 Returns 1 if found, 0 otherwise. */
6936 find_struct_field (const char *name
, struct type
*type
, int offset
,
6937 struct type
**field_type_p
,
6938 int *byte_offset_p
, int *bit_offset_p
, int *bit_size_p
,
6942 int parent_offset
= -1;
6944 type
= ada_check_typedef (type
);
6946 if (field_type_p
!= NULL
)
6947 *field_type_p
= NULL
;
6948 if (byte_offset_p
!= NULL
)
6950 if (bit_offset_p
!= NULL
)
6952 if (bit_size_p
!= NULL
)
6955 for (i
= 0; i
< type
->num_fields (); i
+= 1)
6957 int bit_pos
= TYPE_FIELD_BITPOS (type
, i
);
6958 int fld_offset
= offset
+ bit_pos
/ 8;
6959 const char *t_field_name
= TYPE_FIELD_NAME (type
, i
);
6961 if (t_field_name
== NULL
)
6964 else if (ada_is_parent_field (type
, i
))
6966 /* This is a field pointing us to the parent type of a tagged
6967 type. As hinted in this function's documentation, we give
6968 preference to fields in the current record first, so what
6969 we do here is just record the index of this field before
6970 we skip it. If it turns out we couldn't find our field
6971 in the current record, then we'll get back to it and search
6972 inside it whether the field might exist in the parent. */
6978 else if (name
!= NULL
&& field_name_match (t_field_name
, name
))
6980 int bit_size
= TYPE_FIELD_BITSIZE (type
, i
);
6982 if (field_type_p
!= NULL
)
6983 *field_type_p
= type
->field (i
).type ();
6984 if (byte_offset_p
!= NULL
)
6985 *byte_offset_p
= fld_offset
;
6986 if (bit_offset_p
!= NULL
)
6987 *bit_offset_p
= bit_pos
% 8;
6988 if (bit_size_p
!= NULL
)
6989 *bit_size_p
= bit_size
;
6992 else if (ada_is_wrapper_field (type
, i
))
6994 if (find_struct_field (name
, type
->field (i
).type (), fld_offset
,
6995 field_type_p
, byte_offset_p
, bit_offset_p
,
6996 bit_size_p
, index_p
))
6999 else if (ada_is_variant_part (type
, i
))
7001 /* PNH: Wait. Do we ever execute this section, or is ARG always of
7004 struct type
*field_type
7005 = ada_check_typedef (type
->field (i
).type ());
7007 for (j
= 0; j
< field_type
->num_fields (); j
+= 1)
7009 if (find_struct_field (name
, field_type
->field (j
).type (),
7011 + TYPE_FIELD_BITPOS (field_type
, j
) / 8,
7012 field_type_p
, byte_offset_p
,
7013 bit_offset_p
, bit_size_p
, index_p
))
7017 else if (index_p
!= NULL
)
7021 /* Field not found so far. If this is a tagged type which
7022 has a parent, try finding that field in the parent now. */
7024 if (parent_offset
!= -1)
7026 int bit_pos
= TYPE_FIELD_BITPOS (type
, parent_offset
);
7027 int fld_offset
= offset
+ bit_pos
/ 8;
7029 if (find_struct_field (name
, type
->field (parent_offset
).type (),
7030 fld_offset
, field_type_p
, byte_offset_p
,
7031 bit_offset_p
, bit_size_p
, index_p
))
7038 /* Number of user-visible fields in record type TYPE. */
7041 num_visible_fields (struct type
*type
)
7046 find_struct_field (NULL
, type
, 0, NULL
, NULL
, NULL
, NULL
, &n
);
7050 /* Look for a field NAME in ARG. Adjust the address of ARG by OFFSET bytes,
7051 and search in it assuming it has (class) type TYPE.
7052 If found, return value, else return NULL.
7054 Searches recursively through wrapper fields (e.g., '_parent').
7056 In the case of homonyms in the tagged types, please refer to the
7057 long explanation in find_struct_field's function documentation. */
7059 static struct value
*
7060 ada_search_struct_field (const char *name
, struct value
*arg
, int offset
,
7064 int parent_offset
= -1;
7066 type
= ada_check_typedef (type
);
7067 for (i
= 0; i
< type
->num_fields (); i
+= 1)
7069 const char *t_field_name
= TYPE_FIELD_NAME (type
, i
);
7071 if (t_field_name
== NULL
)
7074 else if (ada_is_parent_field (type
, i
))
7076 /* This is a field pointing us to the parent type of a tagged
7077 type. As hinted in this function's documentation, we give
7078 preference to fields in the current record first, so what
7079 we do here is just record the index of this field before
7080 we skip it. If it turns out we couldn't find our field
7081 in the current record, then we'll get back to it and search
7082 inside it whether the field might exist in the parent. */
7088 else if (field_name_match (t_field_name
, name
))
7089 return ada_value_primitive_field (arg
, offset
, i
, type
);
7091 else if (ada_is_wrapper_field (type
, i
))
7093 struct value
*v
= /* Do not let indent join lines here. */
7094 ada_search_struct_field (name
, arg
,
7095 offset
+ TYPE_FIELD_BITPOS (type
, i
) / 8,
7096 type
->field (i
).type ());
7102 else if (ada_is_variant_part (type
, i
))
7104 /* PNH: Do we ever get here? See find_struct_field. */
7106 struct type
*field_type
= ada_check_typedef (type
->field (i
).type ());
7107 int var_offset
= offset
+ TYPE_FIELD_BITPOS (type
, i
) / 8;
7109 for (j
= 0; j
< field_type
->num_fields (); j
+= 1)
7111 struct value
*v
= ada_search_struct_field
/* Force line
7114 var_offset
+ TYPE_FIELD_BITPOS (field_type
, j
) / 8,
7115 field_type
->field (j
).type ());
7123 /* Field not found so far. If this is a tagged type which
7124 has a parent, try finding that field in the parent now. */
7126 if (parent_offset
!= -1)
7128 struct value
*v
= ada_search_struct_field (
7129 name
, arg
, offset
+ TYPE_FIELD_BITPOS (type
, parent_offset
) / 8,
7130 type
->field (parent_offset
).type ());
7139 static struct value
*ada_index_struct_field_1 (int *, struct value
*,
7140 int, struct type
*);
7143 /* Return field #INDEX in ARG, where the index is that returned by
7144 * find_struct_field through its INDEX_P argument. Adjust the address
7145 * of ARG by OFFSET bytes, and search in it assuming it has (class) type TYPE.
7146 * If found, return value, else return NULL. */
7148 static struct value
*
7149 ada_index_struct_field (int index
, struct value
*arg
, int offset
,
7152 return ada_index_struct_field_1 (&index
, arg
, offset
, type
);
7156 /* Auxiliary function for ada_index_struct_field. Like
7157 * ada_index_struct_field, but takes index from *INDEX_P and modifies
7160 static struct value
*
7161 ada_index_struct_field_1 (int *index_p
, struct value
*arg
, int offset
,
7165 type
= ada_check_typedef (type
);
7167 for (i
= 0; i
< type
->num_fields (); i
+= 1)
7169 if (TYPE_FIELD_NAME (type
, i
) == NULL
)
7171 else if (ada_is_wrapper_field (type
, i
))
7173 struct value
*v
= /* Do not let indent join lines here. */
7174 ada_index_struct_field_1 (index_p
, arg
,
7175 offset
+ TYPE_FIELD_BITPOS (type
, i
) / 8,
7176 type
->field (i
).type ());
7182 else if (ada_is_variant_part (type
, i
))
7184 /* PNH: Do we ever get here? See ada_search_struct_field,
7185 find_struct_field. */
7186 error (_("Cannot assign this kind of variant record"));
7188 else if (*index_p
== 0)
7189 return ada_value_primitive_field (arg
, offset
, i
, type
);
7196 /* Return a string representation of type TYPE. */
7199 type_as_string (struct type
*type
)
7201 string_file tmp_stream
;
7203 type_print (type
, "", &tmp_stream
, -1);
7205 return std::move (tmp_stream
.string ());
7208 /* Given a type TYPE, look up the type of the component of type named NAME.
7209 If DISPP is non-null, add its byte displacement from the beginning of a
7210 structure (pointed to by a value) of type TYPE to *DISPP (does not
7211 work for packed fields).
7213 Matches any field whose name has NAME as a prefix, possibly
7216 TYPE can be either a struct or union. If REFOK, TYPE may also
7217 be a (pointer or reference)+ to a struct or union, and the
7218 ultimate target type will be searched.
7220 Looks recursively into variant clauses and parent types.
7222 In the case of homonyms in the tagged types, please refer to the
7223 long explanation in find_struct_field's function documentation.
7225 If NOERR is nonzero, return NULL if NAME is not suitably defined or
7226 TYPE is not a type of the right kind. */
7228 static struct type
*
7229 ada_lookup_struct_elt_type (struct type
*type
, const char *name
, int refok
,
7233 int parent_offset
= -1;
7238 if (refok
&& type
!= NULL
)
7241 type
= ada_check_typedef (type
);
7242 if (type
->code () != TYPE_CODE_PTR
&& type
->code () != TYPE_CODE_REF
)
7244 type
= TYPE_TARGET_TYPE (type
);
7248 || (type
->code () != TYPE_CODE_STRUCT
7249 && type
->code () != TYPE_CODE_UNION
))
7254 error (_("Type %s is not a structure or union type"),
7255 type
!= NULL
? type_as_string (type
).c_str () : _("(null)"));
7258 type
= to_static_fixed_type (type
);
7260 for (i
= 0; i
< type
->num_fields (); i
+= 1)
7262 const char *t_field_name
= TYPE_FIELD_NAME (type
, i
);
7265 if (t_field_name
== NULL
)
7268 else if (ada_is_parent_field (type
, i
))
7270 /* This is a field pointing us to the parent type of a tagged
7271 type. As hinted in this function's documentation, we give
7272 preference to fields in the current record first, so what
7273 we do here is just record the index of this field before
7274 we skip it. If it turns out we couldn't find our field
7275 in the current record, then we'll get back to it and search
7276 inside it whether the field might exist in the parent. */
7282 else if (field_name_match (t_field_name
, name
))
7283 return type
->field (i
).type ();
7285 else if (ada_is_wrapper_field (type
, i
))
7287 t
= ada_lookup_struct_elt_type (type
->field (i
).type (), name
,
7293 else if (ada_is_variant_part (type
, i
))
7296 struct type
*field_type
= ada_check_typedef (type
->field (i
).type ());
7298 for (j
= field_type
->num_fields () - 1; j
>= 0; j
-= 1)
7300 /* FIXME pnh 2008/01/26: We check for a field that is
7301 NOT wrapped in a struct, since the compiler sometimes
7302 generates these for unchecked variant types. Revisit
7303 if the compiler changes this practice. */
7304 const char *v_field_name
= TYPE_FIELD_NAME (field_type
, j
);
7306 if (v_field_name
!= NULL
7307 && field_name_match (v_field_name
, name
))
7308 t
= field_type
->field (j
).type ();
7310 t
= ada_lookup_struct_elt_type (field_type
->field (j
).type (),
7320 /* Field not found so far. If this is a tagged type which
7321 has a parent, try finding that field in the parent now. */
7323 if (parent_offset
!= -1)
7327 t
= ada_lookup_struct_elt_type (type
->field (parent_offset
).type (),
7336 const char *name_str
= name
!= NULL
? name
: _("<null>");
7338 error (_("Type %s has no component named %s"),
7339 type_as_string (type
).c_str (), name_str
);
7345 /* Assuming that VAR_TYPE is the type of a variant part of a record (a union),
7346 within a value of type OUTER_TYPE, return true iff VAR_TYPE
7347 represents an unchecked union (that is, the variant part of a
7348 record that is named in an Unchecked_Union pragma). */
7351 is_unchecked_variant (struct type
*var_type
, struct type
*outer_type
)
7353 const char *discrim_name
= ada_variant_discrim_name (var_type
);
7355 return (ada_lookup_struct_elt_type (outer_type
, discrim_name
, 0, 1) == NULL
);
7359 /* Assuming that VAR_TYPE is the type of a variant part of a record (a union),
7360 within OUTER, determine which variant clause (field number in VAR_TYPE,
7361 numbering from 0) is applicable. Returns -1 if none are. */
7364 ada_which_variant_applies (struct type
*var_type
, struct value
*outer
)
7368 const char *discrim_name
= ada_variant_discrim_name (var_type
);
7369 struct value
*discrim
;
7370 LONGEST discrim_val
;
7372 /* Using plain value_from_contents_and_address here causes problems
7373 because we will end up trying to resolve a type that is currently
7374 being constructed. */
7375 discrim
= ada_value_struct_elt (outer
, discrim_name
, 1);
7376 if (discrim
== NULL
)
7378 discrim_val
= value_as_long (discrim
);
7381 for (i
= 0; i
< var_type
->num_fields (); i
+= 1)
7383 if (ada_is_others_clause (var_type
, i
))
7385 else if (ada_in_variant (discrim_val
, var_type
, i
))
7389 return others_clause
;
7394 /* Dynamic-Sized Records */
7396 /* Strategy: The type ostensibly attached to a value with dynamic size
7397 (i.e., a size that is not statically recorded in the debugging
7398 data) does not accurately reflect the size or layout of the value.
7399 Our strategy is to convert these values to values with accurate,
7400 conventional types that are constructed on the fly. */
7402 /* There is a subtle and tricky problem here. In general, we cannot
7403 determine the size of dynamic records without its data. However,
7404 the 'struct value' data structure, which GDB uses to represent
7405 quantities in the inferior process (the target), requires the size
7406 of the type at the time of its allocation in order to reserve space
7407 for GDB's internal copy of the data. That's why the
7408 'to_fixed_xxx_type' routines take (target) addresses as parameters,
7409 rather than struct value*s.
7411 However, GDB's internal history variables ($1, $2, etc.) are
7412 struct value*s containing internal copies of the data that are not, in
7413 general, the same as the data at their corresponding addresses in
7414 the target. Fortunately, the types we give to these values are all
7415 conventional, fixed-size types (as per the strategy described
7416 above), so that we don't usually have to perform the
7417 'to_fixed_xxx_type' conversions to look at their values.
7418 Unfortunately, there is one exception: if one of the internal
7419 history variables is an array whose elements are unconstrained
7420 records, then we will need to create distinct fixed types for each
7421 element selected. */
7423 /* The upshot of all of this is that many routines take a (type, host
7424 address, target address) triple as arguments to represent a value.
7425 The host address, if non-null, is supposed to contain an internal
7426 copy of the relevant data; otherwise, the program is to consult the
7427 target at the target address. */
7429 /* Assuming that VAL0 represents a pointer value, the result of
7430 dereferencing it. Differs from value_ind in its treatment of
7431 dynamic-sized types. */
7434 ada_value_ind (struct value
*val0
)
7436 struct value
*val
= value_ind (val0
);
7438 if (ada_is_tagged_type (value_type (val
), 0))
7439 val
= ada_tag_value_at_base_address (val
);
7441 return ada_to_fixed_value (val
);
7444 /* The value resulting from dereferencing any "reference to"
7445 qualifiers on VAL0. */
7447 static struct value
*
7448 ada_coerce_ref (struct value
*val0
)
7450 if (value_type (val0
)->code () == TYPE_CODE_REF
)
7452 struct value
*val
= val0
;
7454 val
= coerce_ref (val
);
7456 if (ada_is_tagged_type (value_type (val
), 0))
7457 val
= ada_tag_value_at_base_address (val
);
7459 return ada_to_fixed_value (val
);
7465 /* Return the bit alignment required for field #F of template type TYPE. */
7468 field_alignment (struct type
*type
, int f
)
7470 const char *name
= TYPE_FIELD_NAME (type
, f
);
7474 /* The field name should never be null, unless the debugging information
7475 is somehow malformed. In this case, we assume the field does not
7476 require any alignment. */
7480 len
= strlen (name
);
7482 if (!isdigit (name
[len
- 1]))
7485 if (isdigit (name
[len
- 2]))
7486 align_offset
= len
- 2;
7488 align_offset
= len
- 1;
7490 if (align_offset
< 7 || !startswith (name
+ align_offset
- 6, "___XV"))
7491 return TARGET_CHAR_BIT
;
7493 return atoi (name
+ align_offset
) * TARGET_CHAR_BIT
;
7496 /* Find a typedef or tag symbol named NAME. Ignores ambiguity. */
7498 static struct symbol
*
7499 ada_find_any_type_symbol (const char *name
)
7503 sym
= standard_lookup (name
, get_selected_block (NULL
), VAR_DOMAIN
);
7504 if (sym
!= NULL
&& SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
7507 sym
= standard_lookup (name
, NULL
, STRUCT_DOMAIN
);
7511 /* Find a type named NAME. Ignores ambiguity. This routine will look
7512 solely for types defined by debug info, it will not search the GDB
7515 static struct type
*
7516 ada_find_any_type (const char *name
)
7518 struct symbol
*sym
= ada_find_any_type_symbol (name
);
7521 return SYMBOL_TYPE (sym
);
7526 /* Given NAME_SYM and an associated BLOCK, find a "renaming" symbol
7527 associated with NAME_SYM's name. NAME_SYM may itself be a renaming
7528 symbol, in which case it is returned. Otherwise, this looks for
7529 symbols whose name is that of NAME_SYM suffixed with "___XR".
7530 Return symbol if found, and NULL otherwise. */
7533 ada_is_renaming_symbol (struct symbol
*name_sym
)
7535 const char *name
= name_sym
->linkage_name ();
7536 return strstr (name
, "___XR") != NULL
;
7539 /* Because of GNAT encoding conventions, several GDB symbols may match a
7540 given type name. If the type denoted by TYPE0 is to be preferred to
7541 that of TYPE1 for purposes of type printing, return non-zero;
7542 otherwise return 0. */
7545 ada_prefer_type (struct type
*type0
, struct type
*type1
)
7549 else if (type0
== NULL
)
7551 else if (type1
->code () == TYPE_CODE_VOID
)
7553 else if (type0
->code () == TYPE_CODE_VOID
)
7555 else if (type1
->name () == NULL
&& type0
->name () != NULL
)
7557 else if (ada_is_constrained_packed_array_type (type0
))
7559 else if (ada_is_array_descriptor_type (type0
)
7560 && !ada_is_array_descriptor_type (type1
))
7564 const char *type0_name
= type0
->name ();
7565 const char *type1_name
= type1
->name ();
7567 if (type0_name
!= NULL
&& strstr (type0_name
, "___XR") != NULL
7568 && (type1_name
== NULL
|| strstr (type1_name
, "___XR") == NULL
))
7574 /* The name of TYPE, which is its TYPE_NAME. Null if TYPE is
7578 ada_type_name (struct type
*type
)
7582 return type
->name ();
7585 /* Search the list of "descriptive" types associated to TYPE for a type
7586 whose name is NAME. */
7588 static struct type
*
7589 find_parallel_type_by_descriptive_type (struct type
*type
, const char *name
)
7591 struct type
*result
, *tmp
;
7593 if (ada_ignore_descriptive_types_p
)
7596 /* If there no descriptive-type info, then there is no parallel type
7598 if (!HAVE_GNAT_AUX_INFO (type
))
7601 result
= TYPE_DESCRIPTIVE_TYPE (type
);
7602 while (result
!= NULL
)
7604 const char *result_name
= ada_type_name (result
);
7606 if (result_name
== NULL
)
7608 warning (_("unexpected null name on descriptive type"));
7612 /* If the names match, stop. */
7613 if (strcmp (result_name
, name
) == 0)
7616 /* Otherwise, look at the next item on the list, if any. */
7617 if (HAVE_GNAT_AUX_INFO (result
))
7618 tmp
= TYPE_DESCRIPTIVE_TYPE (result
);
7622 /* If not found either, try after having resolved the typedef. */
7627 result
= check_typedef (result
);
7628 if (HAVE_GNAT_AUX_INFO (result
))
7629 result
= TYPE_DESCRIPTIVE_TYPE (result
);
7635 /* If we didn't find a match, see whether this is a packed array. With
7636 older compilers, the descriptive type information is either absent or
7637 irrelevant when it comes to packed arrays so the above lookup fails.
7638 Fall back to using a parallel lookup by name in this case. */
7639 if (result
== NULL
&& ada_is_constrained_packed_array_type (type
))
7640 return ada_find_any_type (name
);
7645 /* Find a parallel type to TYPE with the specified NAME, using the
7646 descriptive type taken from the debugging information, if available,
7647 and otherwise using the (slower) name-based method. */
7649 static struct type
*
7650 ada_find_parallel_type_with_name (struct type
*type
, const char *name
)
7652 struct type
*result
= NULL
;
7654 if (HAVE_GNAT_AUX_INFO (type
))
7655 result
= find_parallel_type_by_descriptive_type (type
, name
);
7657 result
= ada_find_any_type (name
);
7662 /* Same as above, but specify the name of the parallel type by appending
7663 SUFFIX to the name of TYPE. */
7666 ada_find_parallel_type (struct type
*type
, const char *suffix
)
7669 const char *type_name
= ada_type_name (type
);
7672 if (type_name
== NULL
)
7675 len
= strlen (type_name
);
7677 name
= (char *) alloca (len
+ strlen (suffix
) + 1);
7679 strcpy (name
, type_name
);
7680 strcpy (name
+ len
, suffix
);
7682 return ada_find_parallel_type_with_name (type
, name
);
7685 /* If TYPE is a variable-size record type, return the corresponding template
7686 type describing its fields. Otherwise, return NULL. */
7688 static struct type
*
7689 dynamic_template_type (struct type
*type
)
7691 type
= ada_check_typedef (type
);
7693 if (type
== NULL
|| type
->code () != TYPE_CODE_STRUCT
7694 || ada_type_name (type
) == NULL
)
7698 int len
= strlen (ada_type_name (type
));
7700 if (len
> 6 && strcmp (ada_type_name (type
) + len
- 6, "___XVE") == 0)
7703 return ada_find_parallel_type (type
, "___XVE");
7707 /* Assuming that TEMPL_TYPE is a union or struct type, returns
7708 non-zero iff field FIELD_NUM of TEMPL_TYPE has dynamic size. */
7711 is_dynamic_field (struct type
*templ_type
, int field_num
)
7713 const char *name
= TYPE_FIELD_NAME (templ_type
, field_num
);
7716 && templ_type
->field (field_num
).type ()->code () == TYPE_CODE_PTR
7717 && strstr (name
, "___XVL") != NULL
;
7720 /* The index of the variant field of TYPE, or -1 if TYPE does not
7721 represent a variant record type. */
7724 variant_field_index (struct type
*type
)
7728 if (type
== NULL
|| type
->code () != TYPE_CODE_STRUCT
)
7731 for (f
= 0; f
< type
->num_fields (); f
+= 1)
7733 if (ada_is_variant_part (type
, f
))
7739 /* A record type with no fields. */
7741 static struct type
*
7742 empty_record (struct type
*templ
)
7744 struct type
*type
= alloc_type_copy (templ
);
7746 type
->set_code (TYPE_CODE_STRUCT
);
7747 INIT_NONE_SPECIFIC (type
);
7748 type
->set_name ("<empty>");
7749 TYPE_LENGTH (type
) = 0;
7753 /* An ordinary record type (with fixed-length fields) that describes
7754 the value of type TYPE at VALADDR or ADDRESS (see comments at
7755 the beginning of this section) VAL according to GNAT conventions.
7756 DVAL0 should describe the (portion of a) record that contains any
7757 necessary discriminants. It should be NULL if value_type (VAL) is
7758 an outer-level type (i.e., as opposed to a branch of a variant.) A
7759 variant field (unless unchecked) is replaced by a particular branch
7762 If not KEEP_DYNAMIC_FIELDS, then all fields whose position or
7763 length are not statically known are discarded. As a consequence,
7764 VALADDR, ADDRESS and DVAL0 are ignored.
7766 NOTE: Limitations: For now, we assume that dynamic fields and
7767 variants occupy whole numbers of bytes. However, they need not be
7771 ada_template_to_fixed_record_type_1 (struct type
*type
,
7772 const gdb_byte
*valaddr
,
7773 CORE_ADDR address
, struct value
*dval0
,
7774 int keep_dynamic_fields
)
7776 struct value
*mark
= value_mark ();
7779 int nfields
, bit_len
;
7785 /* Compute the number of fields in this record type that are going
7786 to be processed: unless keep_dynamic_fields, this includes only
7787 fields whose position and length are static will be processed. */
7788 if (keep_dynamic_fields
)
7789 nfields
= type
->num_fields ();
7793 while (nfields
< type
->num_fields ()
7794 && !ada_is_variant_part (type
, nfields
)
7795 && !is_dynamic_field (type
, nfields
))
7799 rtype
= alloc_type_copy (type
);
7800 rtype
->set_code (TYPE_CODE_STRUCT
);
7801 INIT_NONE_SPECIFIC (rtype
);
7802 rtype
->set_num_fields (nfields
);
7804 ((struct field
*) TYPE_ZALLOC (rtype
, nfields
* sizeof (struct field
)));
7805 rtype
->set_name (ada_type_name (type
));
7806 rtype
->set_is_fixed_instance (true);
7812 for (f
= 0; f
< nfields
; f
+= 1)
7814 off
= align_up (off
, field_alignment (type
, f
))
7815 + TYPE_FIELD_BITPOS (type
, f
);
7816 SET_FIELD_BITPOS (rtype
->field (f
), off
);
7817 TYPE_FIELD_BITSIZE (rtype
, f
) = 0;
7819 if (ada_is_variant_part (type
, f
))
7824 else if (is_dynamic_field (type
, f
))
7826 const gdb_byte
*field_valaddr
= valaddr
;
7827 CORE_ADDR field_address
= address
;
7828 struct type
*field_type
=
7829 TYPE_TARGET_TYPE (type
->field (f
).type ());
7833 /* rtype's length is computed based on the run-time
7834 value of discriminants. If the discriminants are not
7835 initialized, the type size may be completely bogus and
7836 GDB may fail to allocate a value for it. So check the
7837 size first before creating the value. */
7838 ada_ensure_varsize_limit (rtype
);
7839 /* Using plain value_from_contents_and_address here
7840 causes problems because we will end up trying to
7841 resolve a type that is currently being
7843 dval
= value_from_contents_and_address_unresolved (rtype
,
7846 rtype
= value_type (dval
);
7851 /* If the type referenced by this field is an aligner type, we need
7852 to unwrap that aligner type, because its size might not be set.
7853 Keeping the aligner type would cause us to compute the wrong
7854 size for this field, impacting the offset of the all the fields
7855 that follow this one. */
7856 if (ada_is_aligner_type (field_type
))
7858 long field_offset
= TYPE_FIELD_BITPOS (field_type
, f
);
7860 field_valaddr
= cond_offset_host (field_valaddr
, field_offset
);
7861 field_address
= cond_offset_target (field_address
, field_offset
);
7862 field_type
= ada_aligned_type (field_type
);
7865 field_valaddr
= cond_offset_host (field_valaddr
,
7866 off
/ TARGET_CHAR_BIT
);
7867 field_address
= cond_offset_target (field_address
,
7868 off
/ TARGET_CHAR_BIT
);
7870 /* Get the fixed type of the field. Note that, in this case,
7871 we do not want to get the real type out of the tag: if
7872 the current field is the parent part of a tagged record,
7873 we will get the tag of the object. Clearly wrong: the real
7874 type of the parent is not the real type of the child. We
7875 would end up in an infinite loop. */
7876 field_type
= ada_get_base_type (field_type
);
7877 field_type
= ada_to_fixed_type (field_type
, field_valaddr
,
7878 field_address
, dval
, 0);
7879 /* If the field size is already larger than the maximum
7880 object size, then the record itself will necessarily
7881 be larger than the maximum object size. We need to make
7882 this check now, because the size might be so ridiculously
7883 large (due to an uninitialized variable in the inferior)
7884 that it would cause an overflow when adding it to the
7886 ada_ensure_varsize_limit (field_type
);
7888 rtype
->field (f
).set_type (field_type
);
7889 TYPE_FIELD_NAME (rtype
, f
) = TYPE_FIELD_NAME (type
, f
);
7890 /* The multiplication can potentially overflow. But because
7891 the field length has been size-checked just above, and
7892 assuming that the maximum size is a reasonable value,
7893 an overflow should not happen in practice. So rather than
7894 adding overflow recovery code to this already complex code,
7895 we just assume that it's not going to happen. */
7897 TYPE_LENGTH (rtype
->field (f
).type ()) * TARGET_CHAR_BIT
;
7901 /* Note: If this field's type is a typedef, it is important
7902 to preserve the typedef layer.
7904 Otherwise, we might be transforming a typedef to a fat
7905 pointer (encoding a pointer to an unconstrained array),
7906 into a basic fat pointer (encoding an unconstrained
7907 array). As both types are implemented using the same
7908 structure, the typedef is the only clue which allows us
7909 to distinguish between the two options. Stripping it
7910 would prevent us from printing this field appropriately. */
7911 rtype
->field (f
).set_type (type
->field (f
).type ());
7912 TYPE_FIELD_NAME (rtype
, f
) = TYPE_FIELD_NAME (type
, f
);
7913 if (TYPE_FIELD_BITSIZE (type
, f
) > 0)
7915 TYPE_FIELD_BITSIZE (rtype
, f
) = TYPE_FIELD_BITSIZE (type
, f
);
7918 struct type
*field_type
= type
->field (f
).type ();
7920 /* We need to be careful of typedefs when computing
7921 the length of our field. If this is a typedef,
7922 get the length of the target type, not the length
7924 if (field_type
->code () == TYPE_CODE_TYPEDEF
)
7925 field_type
= ada_typedef_target_type (field_type
);
7928 TYPE_LENGTH (ada_check_typedef (field_type
)) * TARGET_CHAR_BIT
;
7931 if (off
+ fld_bit_len
> bit_len
)
7932 bit_len
= off
+ fld_bit_len
;
7934 TYPE_LENGTH (rtype
) =
7935 align_up (bit_len
, TARGET_CHAR_BIT
) / TARGET_CHAR_BIT
;
7938 /* We handle the variant part, if any, at the end because of certain
7939 odd cases in which it is re-ordered so as NOT to be the last field of
7940 the record. This can happen in the presence of representation
7942 if (variant_field
>= 0)
7944 struct type
*branch_type
;
7946 off
= TYPE_FIELD_BITPOS (rtype
, variant_field
);
7950 /* Using plain value_from_contents_and_address here causes
7951 problems because we will end up trying to resolve a type
7952 that is currently being constructed. */
7953 dval
= value_from_contents_and_address_unresolved (rtype
, valaddr
,
7955 rtype
= value_type (dval
);
7961 to_fixed_variant_branch_type
7962 (type
->field (variant_field
).type (),
7963 cond_offset_host (valaddr
, off
/ TARGET_CHAR_BIT
),
7964 cond_offset_target (address
, off
/ TARGET_CHAR_BIT
), dval
);
7965 if (branch_type
== NULL
)
7967 for (f
= variant_field
+ 1; f
< rtype
->num_fields (); f
+= 1)
7968 rtype
->field (f
- 1) = rtype
->field (f
);
7969 rtype
->set_num_fields (rtype
->num_fields () - 1);
7973 rtype
->field (variant_field
).set_type (branch_type
);
7974 TYPE_FIELD_NAME (rtype
, variant_field
) = "S";
7976 TYPE_LENGTH (rtype
->field (variant_field
).type ()) *
7978 if (off
+ fld_bit_len
> bit_len
)
7979 bit_len
= off
+ fld_bit_len
;
7980 TYPE_LENGTH (rtype
) =
7981 align_up (bit_len
, TARGET_CHAR_BIT
) / TARGET_CHAR_BIT
;
7985 /* According to exp_dbug.ads, the size of TYPE for variable-size records
7986 should contain the alignment of that record, which should be a strictly
7987 positive value. If null or negative, then something is wrong, most
7988 probably in the debug info. In that case, we don't round up the size
7989 of the resulting type. If this record is not part of another structure,
7990 the current RTYPE length might be good enough for our purposes. */
7991 if (TYPE_LENGTH (type
) <= 0)
7994 warning (_("Invalid type size for `%s' detected: %s."),
7995 rtype
->name (), pulongest (TYPE_LENGTH (type
)));
7997 warning (_("Invalid type size for <unnamed> detected: %s."),
7998 pulongest (TYPE_LENGTH (type
)));
8002 TYPE_LENGTH (rtype
) = align_up (TYPE_LENGTH (rtype
),
8003 TYPE_LENGTH (type
));
8006 value_free_to_mark (mark
);
8007 if (TYPE_LENGTH (rtype
) > varsize_limit
)
8008 error (_("record type with dynamic size is larger than varsize-limit"));
8012 /* As for ada_template_to_fixed_record_type_1 with KEEP_DYNAMIC_FIELDS
8015 static struct type
*
8016 template_to_fixed_record_type (struct type
*type
, const gdb_byte
*valaddr
,
8017 CORE_ADDR address
, struct value
*dval0
)
8019 return ada_template_to_fixed_record_type_1 (type
, valaddr
,
8023 /* An ordinary record type in which ___XVL-convention fields and
8024 ___XVU- and ___XVN-convention field types in TYPE0 are replaced with
8025 static approximations, containing all possible fields. Uses
8026 no runtime values. Useless for use in values, but that's OK,
8027 since the results are used only for type determinations. Works on both
8028 structs and unions. Representation note: to save space, we memorize
8029 the result of this function in the TYPE_TARGET_TYPE of the
8032 static struct type
*
8033 template_to_static_fixed_type (struct type
*type0
)
8039 /* No need no do anything if the input type is already fixed. */
8040 if (type0
->is_fixed_instance ())
8043 /* Likewise if we already have computed the static approximation. */
8044 if (TYPE_TARGET_TYPE (type0
) != NULL
)
8045 return TYPE_TARGET_TYPE (type0
);
8047 /* Don't clone TYPE0 until we are sure we are going to need a copy. */
8049 nfields
= type0
->num_fields ();
8051 /* Whether or not we cloned TYPE0, cache the result so that we don't do
8052 recompute all over next time. */
8053 TYPE_TARGET_TYPE (type0
) = type
;
8055 for (f
= 0; f
< nfields
; f
+= 1)
8057 struct type
*field_type
= type0
->field (f
).type ();
8058 struct type
*new_type
;
8060 if (is_dynamic_field (type0
, f
))
8062 field_type
= ada_check_typedef (field_type
);
8063 new_type
= to_static_fixed_type (TYPE_TARGET_TYPE (field_type
));
8066 new_type
= static_unwrap_type (field_type
);
8068 if (new_type
!= field_type
)
8070 /* Clone TYPE0 only the first time we get a new field type. */
8073 TYPE_TARGET_TYPE (type0
) = type
= alloc_type_copy (type0
);
8074 type
->set_code (type0
->code ());
8075 INIT_NONE_SPECIFIC (type
);
8076 type
->set_num_fields (nfields
);
8080 TYPE_ALLOC (type
, nfields
* sizeof (struct field
)));
8081 memcpy (fields
, type0
->fields (),
8082 sizeof (struct field
) * nfields
);
8083 type
->set_fields (fields
);
8085 type
->set_name (ada_type_name (type0
));
8086 type
->set_is_fixed_instance (true);
8087 TYPE_LENGTH (type
) = 0;
8089 type
->field (f
).set_type (new_type
);
8090 TYPE_FIELD_NAME (type
, f
) = TYPE_FIELD_NAME (type0
, f
);
8097 /* Given an object of type TYPE whose contents are at VALADDR and
8098 whose address in memory is ADDRESS, returns a revision of TYPE,
8099 which should be a non-dynamic-sized record, in which the variant
8100 part, if any, is replaced with the appropriate branch. Looks
8101 for discriminant values in DVAL0, which can be NULL if the record
8102 contains the necessary discriminant values. */
8104 static struct type
*
8105 to_record_with_fixed_variant_part (struct type
*type
, const gdb_byte
*valaddr
,
8106 CORE_ADDR address
, struct value
*dval0
)
8108 struct value
*mark
= value_mark ();
8111 struct type
*branch_type
;
8112 int nfields
= type
->num_fields ();
8113 int variant_field
= variant_field_index (type
);
8115 if (variant_field
== -1)
8120 dval
= value_from_contents_and_address (type
, valaddr
, address
);
8121 type
= value_type (dval
);
8126 rtype
= alloc_type_copy (type
);
8127 rtype
->set_code (TYPE_CODE_STRUCT
);
8128 INIT_NONE_SPECIFIC (rtype
);
8129 rtype
->set_num_fields (nfields
);
8132 (struct field
*) TYPE_ALLOC (rtype
, nfields
* sizeof (struct field
));
8133 memcpy (fields
, type
->fields (), sizeof (struct field
) * nfields
);
8134 rtype
->set_fields (fields
);
8136 rtype
->set_name (ada_type_name (type
));
8137 rtype
->set_is_fixed_instance (true);
8138 TYPE_LENGTH (rtype
) = TYPE_LENGTH (type
);
8140 branch_type
= to_fixed_variant_branch_type
8141 (type
->field (variant_field
).type (),
8142 cond_offset_host (valaddr
,
8143 TYPE_FIELD_BITPOS (type
, variant_field
)
8145 cond_offset_target (address
,
8146 TYPE_FIELD_BITPOS (type
, variant_field
)
8147 / TARGET_CHAR_BIT
), dval
);
8148 if (branch_type
== NULL
)
8152 for (f
= variant_field
+ 1; f
< nfields
; f
+= 1)
8153 rtype
->field (f
- 1) = rtype
->field (f
);
8154 rtype
->set_num_fields (rtype
->num_fields () - 1);
8158 rtype
->field (variant_field
).set_type (branch_type
);
8159 TYPE_FIELD_NAME (rtype
, variant_field
) = "S";
8160 TYPE_FIELD_BITSIZE (rtype
, variant_field
) = 0;
8161 TYPE_LENGTH (rtype
) += TYPE_LENGTH (branch_type
);
8163 TYPE_LENGTH (rtype
) -= TYPE_LENGTH (type
->field (variant_field
).type ());
8165 value_free_to_mark (mark
);
8169 /* An ordinary record type (with fixed-length fields) that describes
8170 the value at (TYPE0, VALADDR, ADDRESS) [see explanation at
8171 beginning of this section]. Any necessary discriminants' values
8172 should be in DVAL, a record value; it may be NULL if the object
8173 at ADDR itself contains any necessary discriminant values.
8174 Additionally, VALADDR and ADDRESS may also be NULL if no discriminant
8175 values from the record are needed. Except in the case that DVAL,
8176 VALADDR, and ADDRESS are all 0 or NULL, a variant field (unless
8177 unchecked) is replaced by a particular branch of the variant.
8179 NOTE: the case in which DVAL and VALADDR are NULL and ADDRESS is 0
8180 is questionable and may be removed. It can arise during the
8181 processing of an unconstrained-array-of-record type where all the
8182 variant branches have exactly the same size. This is because in
8183 such cases, the compiler does not bother to use the XVS convention
8184 when encoding the record. I am currently dubious of this
8185 shortcut and suspect the compiler should be altered. FIXME. */
8187 static struct type
*
8188 to_fixed_record_type (struct type
*type0
, const gdb_byte
*valaddr
,
8189 CORE_ADDR address
, struct value
*dval
)
8191 struct type
*templ_type
;
8193 if (type0
->is_fixed_instance ())
8196 templ_type
= dynamic_template_type (type0
);
8198 if (templ_type
!= NULL
)
8199 return template_to_fixed_record_type (templ_type
, valaddr
, address
, dval
);
8200 else if (variant_field_index (type0
) >= 0)
8202 if (dval
== NULL
&& valaddr
== NULL
&& address
== 0)
8204 return to_record_with_fixed_variant_part (type0
, valaddr
, address
,
8209 type0
->set_is_fixed_instance (true);
8215 /* An ordinary record type (with fixed-length fields) that describes
8216 the value at (VAR_TYPE0, VALADDR, ADDRESS), where VAR_TYPE0 is a
8217 union type. Any necessary discriminants' values should be in DVAL,
8218 a record value. That is, this routine selects the appropriate
8219 branch of the union at ADDR according to the discriminant value
8220 indicated in the union's type name. Returns VAR_TYPE0 itself if
8221 it represents a variant subject to a pragma Unchecked_Union. */
8223 static struct type
*
8224 to_fixed_variant_branch_type (struct type
*var_type0
, const gdb_byte
*valaddr
,
8225 CORE_ADDR address
, struct value
*dval
)
8228 struct type
*templ_type
;
8229 struct type
*var_type
;
8231 if (var_type0
->code () == TYPE_CODE_PTR
)
8232 var_type
= TYPE_TARGET_TYPE (var_type0
);
8234 var_type
= var_type0
;
8236 templ_type
= ada_find_parallel_type (var_type
, "___XVU");
8238 if (templ_type
!= NULL
)
8239 var_type
= templ_type
;
8241 if (is_unchecked_variant (var_type
, value_type (dval
)))
8243 which
= ada_which_variant_applies (var_type
, dval
);
8246 return empty_record (var_type
);
8247 else if (is_dynamic_field (var_type
, which
))
8248 return to_fixed_record_type
8249 (TYPE_TARGET_TYPE (var_type
->field (which
).type ()),
8250 valaddr
, address
, dval
);
8251 else if (variant_field_index (var_type
->field (which
).type ()) >= 0)
8253 to_fixed_record_type
8254 (var_type
->field (which
).type (), valaddr
, address
, dval
);
8256 return var_type
->field (which
).type ();
8259 /* Assuming RANGE_TYPE is a TYPE_CODE_RANGE, return nonzero if
8260 ENCODING_TYPE, a type following the GNAT conventions for discrete
8261 type encodings, only carries redundant information. */
8264 ada_is_redundant_range_encoding (struct type
*range_type
,
8265 struct type
*encoding_type
)
8267 const char *bounds_str
;
8271 gdb_assert (range_type
->code () == TYPE_CODE_RANGE
);
8273 if (get_base_type (range_type
)->code ()
8274 != get_base_type (encoding_type
)->code ())
8276 /* The compiler probably used a simple base type to describe
8277 the range type instead of the range's actual base type,
8278 expecting us to get the real base type from the encoding
8279 anyway. In this situation, the encoding cannot be ignored
8284 if (is_dynamic_type (range_type
))
8287 if (encoding_type
->name () == NULL
)
8290 bounds_str
= strstr (encoding_type
->name (), "___XDLU_");
8291 if (bounds_str
== NULL
)
8294 n
= 8; /* Skip "___XDLU_". */
8295 if (!ada_scan_number (bounds_str
, n
, &lo
, &n
))
8297 if (range_type
->bounds ()->low
.const_val () != lo
)
8300 n
+= 2; /* Skip the "__" separator between the two bounds. */
8301 if (!ada_scan_number (bounds_str
, n
, &hi
, &n
))
8303 if (range_type
->bounds ()->high
.const_val () != hi
)
8309 /* Given the array type ARRAY_TYPE, return nonzero if DESC_TYPE,
8310 a type following the GNAT encoding for describing array type
8311 indices, only carries redundant information. */
8314 ada_is_redundant_index_type_desc (struct type
*array_type
,
8315 struct type
*desc_type
)
8317 struct type
*this_layer
= check_typedef (array_type
);
8320 for (i
= 0; i
< desc_type
->num_fields (); i
++)
8322 if (!ada_is_redundant_range_encoding (this_layer
->index_type (),
8323 desc_type
->field (i
).type ()))
8325 this_layer
= check_typedef (TYPE_TARGET_TYPE (this_layer
));
8331 /* Assuming that TYPE0 is an array type describing the type of a value
8332 at ADDR, and that DVAL describes a record containing any
8333 discriminants used in TYPE0, returns a type for the value that
8334 contains no dynamic components (that is, no components whose sizes
8335 are determined by run-time quantities). Unless IGNORE_TOO_BIG is
8336 true, gives an error message if the resulting type's size is over
8339 static struct type
*
8340 to_fixed_array_type (struct type
*type0
, struct value
*dval
,
8343 struct type
*index_type_desc
;
8344 struct type
*result
;
8345 int constrained_packed_array_p
;
8346 static const char *xa_suffix
= "___XA";
8348 type0
= ada_check_typedef (type0
);
8349 if (type0
->is_fixed_instance ())
8352 constrained_packed_array_p
= ada_is_constrained_packed_array_type (type0
);
8353 if (constrained_packed_array_p
)
8355 type0
= decode_constrained_packed_array_type (type0
);
8356 if (type0
== nullptr)
8357 error (_("could not decode constrained packed array type"));
8360 index_type_desc
= ada_find_parallel_type (type0
, xa_suffix
);
8362 /* As mentioned in exp_dbug.ads, for non bit-packed arrays an
8363 encoding suffixed with 'P' may still be generated. If so,
8364 it should be used to find the XA type. */
8366 if (index_type_desc
== NULL
)
8368 const char *type_name
= ada_type_name (type0
);
8370 if (type_name
!= NULL
)
8372 const int len
= strlen (type_name
);
8373 char *name
= (char *) alloca (len
+ strlen (xa_suffix
));
8375 if (type_name
[len
- 1] == 'P')
8377 strcpy (name
, type_name
);
8378 strcpy (name
+ len
- 1, xa_suffix
);
8379 index_type_desc
= ada_find_parallel_type_with_name (type0
, name
);
8384 ada_fixup_array_indexes_type (index_type_desc
);
8385 if (index_type_desc
!= NULL
8386 && ada_is_redundant_index_type_desc (type0
, index_type_desc
))
8388 /* Ignore this ___XA parallel type, as it does not bring any
8389 useful information. This allows us to avoid creating fixed
8390 versions of the array's index types, which would be identical
8391 to the original ones. This, in turn, can also help avoid
8392 the creation of fixed versions of the array itself. */
8393 index_type_desc
= NULL
;
8396 if (index_type_desc
== NULL
)
8398 struct type
*elt_type0
= ada_check_typedef (TYPE_TARGET_TYPE (type0
));
8400 /* NOTE: elt_type---the fixed version of elt_type0---should never
8401 depend on the contents of the array in properly constructed
8403 /* Create a fixed version of the array element type.
8404 We're not providing the address of an element here,
8405 and thus the actual object value cannot be inspected to do
8406 the conversion. This should not be a problem, since arrays of
8407 unconstrained objects are not allowed. In particular, all
8408 the elements of an array of a tagged type should all be of
8409 the same type specified in the debugging info. No need to
8410 consult the object tag. */
8411 struct type
*elt_type
= ada_to_fixed_type (elt_type0
, 0, 0, dval
, 1);
8413 /* Make sure we always create a new array type when dealing with
8414 packed array types, since we're going to fix-up the array
8415 type length and element bitsize a little further down. */
8416 if (elt_type0
== elt_type
&& !constrained_packed_array_p
)
8419 result
= create_array_type (alloc_type_copy (type0
),
8420 elt_type
, type0
->index_type ());
8425 struct type
*elt_type0
;
8428 for (i
= index_type_desc
->num_fields (); i
> 0; i
-= 1)
8429 elt_type0
= TYPE_TARGET_TYPE (elt_type0
);
8431 /* NOTE: result---the fixed version of elt_type0---should never
8432 depend on the contents of the array in properly constructed
8434 /* Create a fixed version of the array element type.
8435 We're not providing the address of an element here,
8436 and thus the actual object value cannot be inspected to do
8437 the conversion. This should not be a problem, since arrays of
8438 unconstrained objects are not allowed. In particular, all
8439 the elements of an array of a tagged type should all be of
8440 the same type specified in the debugging info. No need to
8441 consult the object tag. */
8443 ada_to_fixed_type (ada_check_typedef (elt_type0
), 0, 0, dval
, 1);
8446 for (i
= index_type_desc
->num_fields () - 1; i
>= 0; i
-= 1)
8448 struct type
*range_type
=
8449 to_fixed_range_type (index_type_desc
->field (i
).type (), dval
);
8451 result
= create_array_type (alloc_type_copy (elt_type0
),
8452 result
, range_type
);
8453 elt_type0
= TYPE_TARGET_TYPE (elt_type0
);
8455 if (!ignore_too_big
&& TYPE_LENGTH (result
) > varsize_limit
)
8456 error (_("array type with dynamic size is larger than varsize-limit"));
8459 /* We want to preserve the type name. This can be useful when
8460 trying to get the type name of a value that has already been
8461 printed (for instance, if the user did "print VAR; whatis $". */
8462 result
->set_name (type0
->name ());
8464 if (constrained_packed_array_p
)
8466 /* So far, the resulting type has been created as if the original
8467 type was a regular (non-packed) array type. As a result, the
8468 bitsize of the array elements needs to be set again, and the array
8469 length needs to be recomputed based on that bitsize. */
8470 int len
= TYPE_LENGTH (result
) / TYPE_LENGTH (TYPE_TARGET_TYPE (result
));
8471 int elt_bitsize
= TYPE_FIELD_BITSIZE (type0
, 0);
8473 TYPE_FIELD_BITSIZE (result
, 0) = TYPE_FIELD_BITSIZE (type0
, 0);
8474 TYPE_LENGTH (result
) = len
* elt_bitsize
/ HOST_CHAR_BIT
;
8475 if (TYPE_LENGTH (result
) * HOST_CHAR_BIT
< len
* elt_bitsize
)
8476 TYPE_LENGTH (result
)++;
8479 result
->set_is_fixed_instance (true);
8484 /* A standard type (containing no dynamically sized components)
8485 corresponding to TYPE for the value (TYPE, VALADDR, ADDRESS)
8486 DVAL describes a record containing any discriminants used in TYPE0,
8487 and may be NULL if there are none, or if the object of type TYPE at
8488 ADDRESS or in VALADDR contains these discriminants.
8490 If CHECK_TAG is not null, in the case of tagged types, this function
8491 attempts to locate the object's tag and use it to compute the actual
8492 type. However, when ADDRESS is null, we cannot use it to determine the
8493 location of the tag, and therefore compute the tagged type's actual type.
8494 So we return the tagged type without consulting the tag. */
8496 static struct type
*
8497 ada_to_fixed_type_1 (struct type
*type
, const gdb_byte
*valaddr
,
8498 CORE_ADDR address
, struct value
*dval
, int check_tag
)
8500 type
= ada_check_typedef (type
);
8502 /* Only un-fixed types need to be handled here. */
8503 if (!HAVE_GNAT_AUX_INFO (type
))
8506 switch (type
->code ())
8510 case TYPE_CODE_STRUCT
:
8512 struct type
*static_type
= to_static_fixed_type (type
);
8513 struct type
*fixed_record_type
=
8514 to_fixed_record_type (type
, valaddr
, address
, NULL
);
8516 /* If STATIC_TYPE is a tagged type and we know the object's address,
8517 then we can determine its tag, and compute the object's actual
8518 type from there. Note that we have to use the fixed record
8519 type (the parent part of the record may have dynamic fields
8520 and the way the location of _tag is expressed may depend on
8523 if (check_tag
&& address
!= 0 && ada_is_tagged_type (static_type
, 0))
8526 value_tag_from_contents_and_address
8530 struct type
*real_type
= type_from_tag (tag
);
8532 value_from_contents_and_address (fixed_record_type
,
8535 fixed_record_type
= value_type (obj
);
8536 if (real_type
!= NULL
)
8537 return to_fixed_record_type
8539 value_address (ada_tag_value_at_base_address (obj
)), NULL
);
8542 /* Check to see if there is a parallel ___XVZ variable.
8543 If there is, then it provides the actual size of our type. */
8544 else if (ada_type_name (fixed_record_type
) != NULL
)
8546 const char *name
= ada_type_name (fixed_record_type
);
8548 = (char *) alloca (strlen (name
) + 7 /* "___XVZ\0" */);
8549 bool xvz_found
= false;
8552 xsnprintf (xvz_name
, strlen (name
) + 7, "%s___XVZ", name
);
8555 xvz_found
= get_int_var_value (xvz_name
, size
);
8557 catch (const gdb_exception_error
&except
)
8559 /* We found the variable, but somehow failed to read
8560 its value. Rethrow the same error, but with a little
8561 bit more information, to help the user understand
8562 what went wrong (Eg: the variable might have been
8564 throw_error (except
.error
,
8565 _("unable to read value of %s (%s)"),
8566 xvz_name
, except
.what ());
8569 if (xvz_found
&& TYPE_LENGTH (fixed_record_type
) != size
)
8571 fixed_record_type
= copy_type (fixed_record_type
);
8572 TYPE_LENGTH (fixed_record_type
) = size
;
8574 /* The FIXED_RECORD_TYPE may have be a stub. We have
8575 observed this when the debugging info is STABS, and
8576 apparently it is something that is hard to fix.
8578 In practice, we don't need the actual type definition
8579 at all, because the presence of the XVZ variable allows us
8580 to assume that there must be a XVS type as well, which we
8581 should be able to use later, when we need the actual type
8584 In the meantime, pretend that the "fixed" type we are
8585 returning is NOT a stub, because this can cause trouble
8586 when using this type to create new types targeting it.
8587 Indeed, the associated creation routines often check
8588 whether the target type is a stub and will try to replace
8589 it, thus using a type with the wrong size. This, in turn,
8590 might cause the new type to have the wrong size too.
8591 Consider the case of an array, for instance, where the size
8592 of the array is computed from the number of elements in
8593 our array multiplied by the size of its element. */
8594 fixed_record_type
->set_is_stub (false);
8597 return fixed_record_type
;
8599 case TYPE_CODE_ARRAY
:
8600 return to_fixed_array_type (type
, dval
, 1);
8601 case TYPE_CODE_UNION
:
8605 return to_fixed_variant_branch_type (type
, valaddr
, address
, dval
);
8609 /* The same as ada_to_fixed_type_1, except that it preserves the type
8610 if it is a TYPE_CODE_TYPEDEF of a type that is already fixed.
8612 The typedef layer needs be preserved in order to differentiate between
8613 arrays and array pointers when both types are implemented using the same
8614 fat pointer. In the array pointer case, the pointer is encoded as
8615 a typedef of the pointer type. For instance, considering:
8617 type String_Access is access String;
8618 S1 : String_Access := null;
8620 To the debugger, S1 is defined as a typedef of type String. But
8621 to the user, it is a pointer. So if the user tries to print S1,
8622 we should not dereference the array, but print the array address
8625 If we didn't preserve the typedef layer, we would lose the fact that
8626 the type is to be presented as a pointer (needs de-reference before
8627 being printed). And we would also use the source-level type name. */
8630 ada_to_fixed_type (struct type
*type
, const gdb_byte
*valaddr
,
8631 CORE_ADDR address
, struct value
*dval
, int check_tag
)
8634 struct type
*fixed_type
=
8635 ada_to_fixed_type_1 (type
, valaddr
, address
, dval
, check_tag
);
8637 /* If TYPE is a typedef and its target type is the same as the FIXED_TYPE,
8638 then preserve the typedef layer.
8640 Implementation note: We can only check the main-type portion of
8641 the TYPE and FIXED_TYPE, because eliminating the typedef layer
8642 from TYPE now returns a type that has the same instance flags
8643 as TYPE. For instance, if TYPE is a "typedef const", and its
8644 target type is a "struct", then the typedef elimination will return
8645 a "const" version of the target type. See check_typedef for more
8646 details about how the typedef layer elimination is done.
8648 brobecker/2010-11-19: It seems to me that the only case where it is
8649 useful to preserve the typedef layer is when dealing with fat pointers.
8650 Perhaps, we could add a check for that and preserve the typedef layer
8651 only in that situation. But this seems unnecessary so far, probably
8652 because we call check_typedef/ada_check_typedef pretty much everywhere.
8654 if (type
->code () == TYPE_CODE_TYPEDEF
8655 && (TYPE_MAIN_TYPE (ada_typedef_target_type (type
))
8656 == TYPE_MAIN_TYPE (fixed_type
)))
8662 /* A standard (static-sized) type corresponding as well as possible to
8663 TYPE0, but based on no runtime data. */
8665 static struct type
*
8666 to_static_fixed_type (struct type
*type0
)
8673 if (type0
->is_fixed_instance ())
8676 type0
= ada_check_typedef (type0
);
8678 switch (type0
->code ())
8682 case TYPE_CODE_STRUCT
:
8683 type
= dynamic_template_type (type0
);
8685 return template_to_static_fixed_type (type
);
8687 return template_to_static_fixed_type (type0
);
8688 case TYPE_CODE_UNION
:
8689 type
= ada_find_parallel_type (type0
, "___XVU");
8691 return template_to_static_fixed_type (type
);
8693 return template_to_static_fixed_type (type0
);
8697 /* A static approximation of TYPE with all type wrappers removed. */
8699 static struct type
*
8700 static_unwrap_type (struct type
*type
)
8702 if (ada_is_aligner_type (type
))
8704 struct type
*type1
= ada_check_typedef (type
)->field (0).type ();
8705 if (ada_type_name (type1
) == NULL
)
8706 type1
->set_name (ada_type_name (type
));
8708 return static_unwrap_type (type1
);
8712 struct type
*raw_real_type
= ada_get_base_type (type
);
8714 if (raw_real_type
== type
)
8717 return to_static_fixed_type (raw_real_type
);
8721 /* In some cases, incomplete and private types require
8722 cross-references that are not resolved as records (for example,
8724 type FooP is access Foo;
8726 type Foo is array ...;
8727 ). In these cases, since there is no mechanism for producing
8728 cross-references to such types, we instead substitute for FooP a
8729 stub enumeration type that is nowhere resolved, and whose tag is
8730 the name of the actual type. Call these types "non-record stubs". */
8732 /* A type equivalent to TYPE that is not a non-record stub, if one
8733 exists, otherwise TYPE. */
8736 ada_check_typedef (struct type
*type
)
8741 /* If our type is an access to an unconstrained array, which is encoded
8742 as a TYPE_CODE_TYPEDEF of a fat pointer, then we're done.
8743 We don't want to strip the TYPE_CODE_TYPDEF layer, because this is
8744 what allows us to distinguish between fat pointers that represent
8745 array types, and fat pointers that represent array access types
8746 (in both cases, the compiler implements them as fat pointers). */
8747 if (ada_is_access_to_unconstrained_array (type
))
8750 type
= check_typedef (type
);
8751 if (type
== NULL
|| type
->code () != TYPE_CODE_ENUM
8752 || !type
->is_stub ()
8753 || type
->name () == NULL
)
8757 const char *name
= type
->name ();
8758 struct type
*type1
= ada_find_any_type (name
);
8763 /* TYPE1 might itself be a TYPE_CODE_TYPEDEF (this can happen with
8764 stubs pointing to arrays, as we don't create symbols for array
8765 types, only for the typedef-to-array types). If that's the case,
8766 strip the typedef layer. */
8767 if (type1
->code () == TYPE_CODE_TYPEDEF
)
8768 type1
= ada_check_typedef (type1
);
8774 /* A value representing the data at VALADDR/ADDRESS as described by
8775 type TYPE0, but with a standard (static-sized) type that correctly
8776 describes it. If VAL0 is not NULL and TYPE0 already is a standard
8777 type, then return VAL0 [this feature is simply to avoid redundant
8778 creation of struct values]. */
8780 static struct value
*
8781 ada_to_fixed_value_create (struct type
*type0
, CORE_ADDR address
,
8784 struct type
*type
= ada_to_fixed_type (type0
, 0, address
, NULL
, 1);
8786 if (type
== type0
&& val0
!= NULL
)
8789 if (VALUE_LVAL (val0
) != lval_memory
)
8791 /* Our value does not live in memory; it could be a convenience
8792 variable, for instance. Create a not_lval value using val0's
8794 return value_from_contents (type
, value_contents (val0
));
8797 return value_from_contents_and_address (type
, 0, address
);
8800 /* A value representing VAL, but with a standard (static-sized) type
8801 that correctly describes it. Does not necessarily create a new
8805 ada_to_fixed_value (struct value
*val
)
8807 val
= unwrap_value (val
);
8808 val
= ada_to_fixed_value_create (value_type (val
), value_address (val
), val
);
8815 /* Table mapping attribute numbers to names.
8816 NOTE: Keep up to date with enum ada_attribute definition in ada-lang.h. */
8818 static const char * const attribute_names
[] = {
8836 ada_attribute_name (enum exp_opcode n
)
8838 if (n
>= OP_ATR_FIRST
&& n
<= (int) OP_ATR_VAL
)
8839 return attribute_names
[n
- OP_ATR_FIRST
+ 1];
8841 return attribute_names
[0];
8844 /* Evaluate the 'POS attribute applied to ARG. */
8847 pos_atr (struct value
*arg
)
8849 struct value
*val
= coerce_ref (arg
);
8850 struct type
*type
= value_type (val
);
8852 if (!discrete_type_p (type
))
8853 error (_("'POS only defined on discrete types"));
8855 gdb::optional
<LONGEST
> result
= discrete_position (type
, value_as_long (val
));
8856 if (!result
.has_value ())
8857 error (_("enumeration value is invalid: can't find 'POS"));
8863 ada_pos_atr (struct type
*expect_type
,
8864 struct expression
*exp
,
8865 enum noside noside
, enum exp_opcode op
,
8868 struct type
*type
= builtin_type (exp
->gdbarch
)->builtin_int
;
8869 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
8870 return value_zero (type
, not_lval
);
8871 return value_from_longest (type
, pos_atr (arg
));
8874 /* Evaluate the TYPE'VAL attribute applied to ARG. */
8876 static struct value
*
8877 val_atr (struct type
*type
, LONGEST val
)
8879 gdb_assert (discrete_type_p (type
));
8880 if (type
->code () == TYPE_CODE_RANGE
)
8881 type
= TYPE_TARGET_TYPE (type
);
8882 if (type
->code () == TYPE_CODE_ENUM
)
8884 if (val
< 0 || val
>= type
->num_fields ())
8885 error (_("argument to 'VAL out of range"));
8886 val
= TYPE_FIELD_ENUMVAL (type
, val
);
8888 return value_from_longest (type
, val
);
8892 ada_val_atr (enum noside noside
, struct type
*type
, struct value
*arg
)
8894 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
8895 return value_zero (type
, not_lval
);
8897 if (!discrete_type_p (type
))
8898 error (_("'VAL only defined on discrete types"));
8899 if (!integer_type_p (value_type (arg
)))
8900 error (_("'VAL requires integral argument"));
8902 return val_atr (type
, value_as_long (arg
));
8908 /* True if TYPE appears to be an Ada character type.
8909 [At the moment, this is true only for Character and Wide_Character;
8910 It is a heuristic test that could stand improvement]. */
8913 ada_is_character_type (struct type
*type
)
8917 /* If the type code says it's a character, then assume it really is,
8918 and don't check any further. */
8919 if (type
->code () == TYPE_CODE_CHAR
)
8922 /* Otherwise, assume it's a character type iff it is a discrete type
8923 with a known character type name. */
8924 name
= ada_type_name (type
);
8925 return (name
!= NULL
8926 && (type
->code () == TYPE_CODE_INT
8927 || type
->code () == TYPE_CODE_RANGE
)
8928 && (strcmp (name
, "character") == 0
8929 || strcmp (name
, "wide_character") == 0
8930 || strcmp (name
, "wide_wide_character") == 0
8931 || strcmp (name
, "unsigned char") == 0));
8934 /* True if TYPE appears to be an Ada string type. */
8937 ada_is_string_type (struct type
*type
)
8939 type
= ada_check_typedef (type
);
8941 && type
->code () != TYPE_CODE_PTR
8942 && (ada_is_simple_array_type (type
)
8943 || ada_is_array_descriptor_type (type
))
8944 && ada_array_arity (type
) == 1)
8946 struct type
*elttype
= ada_array_element_type (type
, 1);
8948 return ada_is_character_type (elttype
);
8954 /* The compiler sometimes provides a parallel XVS type for a given
8955 PAD type. Normally, it is safe to follow the PAD type directly,
8956 but older versions of the compiler have a bug that causes the offset
8957 of its "F" field to be wrong. Following that field in that case
8958 would lead to incorrect results, but this can be worked around
8959 by ignoring the PAD type and using the associated XVS type instead.
8961 Set to True if the debugger should trust the contents of PAD types.
8962 Otherwise, ignore the PAD type if there is a parallel XVS type. */
8963 static bool trust_pad_over_xvs
= true;
8965 /* True if TYPE is a struct type introduced by the compiler to force the
8966 alignment of a value. Such types have a single field with a
8967 distinctive name. */
8970 ada_is_aligner_type (struct type
*type
)
8972 type
= ada_check_typedef (type
);
8974 if (!trust_pad_over_xvs
&& ada_find_parallel_type (type
, "___XVS") != NULL
)
8977 return (type
->code () == TYPE_CODE_STRUCT
8978 && type
->num_fields () == 1
8979 && strcmp (TYPE_FIELD_NAME (type
, 0), "F") == 0);
8982 /* If there is an ___XVS-convention type parallel to SUBTYPE, return
8983 the parallel type. */
8986 ada_get_base_type (struct type
*raw_type
)
8988 struct type
*real_type_namer
;
8989 struct type
*raw_real_type
;
8991 if (raw_type
== NULL
|| raw_type
->code () != TYPE_CODE_STRUCT
)
8994 if (ada_is_aligner_type (raw_type
))
8995 /* The encoding specifies that we should always use the aligner type.
8996 So, even if this aligner type has an associated XVS type, we should
8999 According to the compiler gurus, an XVS type parallel to an aligner
9000 type may exist because of a stabs limitation. In stabs, aligner
9001 types are empty because the field has a variable-sized type, and
9002 thus cannot actually be used as an aligner type. As a result,
9003 we need the associated parallel XVS type to decode the type.
9004 Since the policy in the compiler is to not change the internal
9005 representation based on the debugging info format, we sometimes
9006 end up having a redundant XVS type parallel to the aligner type. */
9009 real_type_namer
= ada_find_parallel_type (raw_type
, "___XVS");
9010 if (real_type_namer
== NULL
9011 || real_type_namer
->code () != TYPE_CODE_STRUCT
9012 || real_type_namer
->num_fields () != 1)
9015 if (real_type_namer
->field (0).type ()->code () != TYPE_CODE_REF
)
9017 /* This is an older encoding form where the base type needs to be
9018 looked up by name. We prefer the newer encoding because it is
9020 raw_real_type
= ada_find_any_type (TYPE_FIELD_NAME (real_type_namer
, 0));
9021 if (raw_real_type
== NULL
)
9024 return raw_real_type
;
9027 /* The field in our XVS type is a reference to the base type. */
9028 return TYPE_TARGET_TYPE (real_type_namer
->field (0).type ());
9031 /* The type of value designated by TYPE, with all aligners removed. */
9034 ada_aligned_type (struct type
*type
)
9036 if (ada_is_aligner_type (type
))
9037 return ada_aligned_type (type
->field (0).type ());
9039 return ada_get_base_type (type
);
9043 /* The address of the aligned value in an object at address VALADDR
9044 having type TYPE. Assumes ada_is_aligner_type (TYPE). */
9047 ada_aligned_value_addr (struct type
*type
, const gdb_byte
*valaddr
)
9049 if (ada_is_aligner_type (type
))
9050 return ada_aligned_value_addr (type
->field (0).type (),
9052 TYPE_FIELD_BITPOS (type
,
9053 0) / TARGET_CHAR_BIT
);
9060 /* The printed representation of an enumeration literal with encoded
9061 name NAME. The value is good to the next call of ada_enum_name. */
9063 ada_enum_name (const char *name
)
9065 static std::string storage
;
9068 /* First, unqualify the enumeration name:
9069 1. Search for the last '.' character. If we find one, then skip
9070 all the preceding characters, the unqualified name starts
9071 right after that dot.
9072 2. Otherwise, we may be debugging on a target where the compiler
9073 translates dots into "__". Search forward for double underscores,
9074 but stop searching when we hit an overloading suffix, which is
9075 of the form "__" followed by digits. */
9077 tmp
= strrchr (name
, '.');
9082 while ((tmp
= strstr (name
, "__")) != NULL
)
9084 if (isdigit (tmp
[2]))
9095 if (name
[1] == 'U' || name
[1] == 'W')
9097 if (sscanf (name
+ 2, "%x", &v
) != 1)
9100 else if (((name
[1] >= '0' && name
[1] <= '9')
9101 || (name
[1] >= 'a' && name
[1] <= 'z'))
9104 storage
= string_printf ("'%c'", name
[1]);
9105 return storage
.c_str ();
9110 if (isascii (v
) && isprint (v
))
9111 storage
= string_printf ("'%c'", v
);
9112 else if (name
[1] == 'U')
9113 storage
= string_printf ("[\"%02x\"]", v
);
9115 storage
= string_printf ("[\"%04x\"]", v
);
9117 return storage
.c_str ();
9121 tmp
= strstr (name
, "__");
9123 tmp
= strstr (name
, "$");
9126 storage
= std::string (name
, tmp
- name
);
9127 return storage
.c_str ();
9134 /* Evaluate the subexpression of EXP starting at *POS as for
9135 evaluate_type, updating *POS to point just past the evaluated
9138 static struct value
*
9139 evaluate_subexp_type (struct expression
*exp
, int *pos
)
9141 return evaluate_subexp (nullptr, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
9144 /* If VAL is wrapped in an aligner or subtype wrapper, return the
9147 static struct value
*
9148 unwrap_value (struct value
*val
)
9150 struct type
*type
= ada_check_typedef (value_type (val
));
9152 if (ada_is_aligner_type (type
))
9154 struct value
*v
= ada_value_struct_elt (val
, "F", 0);
9155 struct type
*val_type
= ada_check_typedef (value_type (v
));
9157 if (ada_type_name (val_type
) == NULL
)
9158 val_type
->set_name (ada_type_name (type
));
9160 return unwrap_value (v
);
9164 struct type
*raw_real_type
=
9165 ada_check_typedef (ada_get_base_type (type
));
9167 /* If there is no parallel XVS or XVE type, then the value is
9168 already unwrapped. Return it without further modification. */
9169 if ((type
== raw_real_type
)
9170 && ada_find_parallel_type (type
, "___XVE") == NULL
)
9174 coerce_unspec_val_to_type
9175 (val
, ada_to_fixed_type (raw_real_type
, 0,
9176 value_address (val
),
9181 /* Given two array types T1 and T2, return nonzero iff both arrays
9182 contain the same number of elements. */
9185 ada_same_array_size_p (struct type
*t1
, struct type
*t2
)
9187 LONGEST lo1
, hi1
, lo2
, hi2
;
9189 /* Get the array bounds in order to verify that the size of
9190 the two arrays match. */
9191 if (!get_array_bounds (t1
, &lo1
, &hi1
)
9192 || !get_array_bounds (t2
, &lo2
, &hi2
))
9193 error (_("unable to determine array bounds"));
9195 /* To make things easier for size comparison, normalize a bit
9196 the case of empty arrays by making sure that the difference
9197 between upper bound and lower bound is always -1. */
9203 return (hi1
- lo1
== hi2
- lo2
);
9206 /* Assuming that VAL is an array of integrals, and TYPE represents
9207 an array with the same number of elements, but with wider integral
9208 elements, return an array "casted" to TYPE. In practice, this
9209 means that the returned array is built by casting each element
9210 of the original array into TYPE's (wider) element type. */
9212 static struct value
*
9213 ada_promote_array_of_integrals (struct type
*type
, struct value
*val
)
9215 struct type
*elt_type
= TYPE_TARGET_TYPE (type
);
9220 /* Verify that both val and type are arrays of scalars, and
9221 that the size of val's elements is smaller than the size
9222 of type's element. */
9223 gdb_assert (type
->code () == TYPE_CODE_ARRAY
);
9224 gdb_assert (is_integral_type (TYPE_TARGET_TYPE (type
)));
9225 gdb_assert (value_type (val
)->code () == TYPE_CODE_ARRAY
);
9226 gdb_assert (is_integral_type (TYPE_TARGET_TYPE (value_type (val
))));
9227 gdb_assert (TYPE_LENGTH (TYPE_TARGET_TYPE (type
))
9228 > TYPE_LENGTH (TYPE_TARGET_TYPE (value_type (val
))));
9230 if (!get_array_bounds (type
, &lo
, &hi
))
9231 error (_("unable to determine array bounds"));
9233 res
= allocate_value (type
);
9235 /* Promote each array element. */
9236 for (i
= 0; i
< hi
- lo
+ 1; i
++)
9238 struct value
*elt
= value_cast (elt_type
, value_subscript (val
, lo
+ i
));
9240 memcpy (value_contents_writeable (res
) + (i
* TYPE_LENGTH (elt_type
)),
9241 value_contents_all (elt
), TYPE_LENGTH (elt_type
));
9247 /* Coerce VAL as necessary for assignment to an lval of type TYPE, and
9248 return the converted value. */
9250 static struct value
*
9251 coerce_for_assign (struct type
*type
, struct value
*val
)
9253 struct type
*type2
= value_type (val
);
9258 type2
= ada_check_typedef (type2
);
9259 type
= ada_check_typedef (type
);
9261 if (type2
->code () == TYPE_CODE_PTR
9262 && type
->code () == TYPE_CODE_ARRAY
)
9264 val
= ada_value_ind (val
);
9265 type2
= value_type (val
);
9268 if (type2
->code () == TYPE_CODE_ARRAY
9269 && type
->code () == TYPE_CODE_ARRAY
)
9271 if (!ada_same_array_size_p (type
, type2
))
9272 error (_("cannot assign arrays of different length"));
9274 if (is_integral_type (TYPE_TARGET_TYPE (type
))
9275 && is_integral_type (TYPE_TARGET_TYPE (type2
))
9276 && TYPE_LENGTH (TYPE_TARGET_TYPE (type2
))
9277 < TYPE_LENGTH (TYPE_TARGET_TYPE (type
)))
9279 /* Allow implicit promotion of the array elements to
9281 return ada_promote_array_of_integrals (type
, val
);
9284 if (TYPE_LENGTH (TYPE_TARGET_TYPE (type2
))
9285 != TYPE_LENGTH (TYPE_TARGET_TYPE (type
)))
9286 error (_("Incompatible types in assignment"));
9287 deprecated_set_value_type (val
, type
);
9292 static struct value
*
9293 ada_value_binop (struct value
*arg1
, struct value
*arg2
, enum exp_opcode op
)
9296 struct type
*type1
, *type2
;
9299 arg1
= coerce_ref (arg1
);
9300 arg2
= coerce_ref (arg2
);
9301 type1
= get_base_type (ada_check_typedef (value_type (arg1
)));
9302 type2
= get_base_type (ada_check_typedef (value_type (arg2
)));
9304 if (type1
->code () != TYPE_CODE_INT
9305 || type2
->code () != TYPE_CODE_INT
)
9306 return value_binop (arg1
, arg2
, op
);
9315 return value_binop (arg1
, arg2
, op
);
9318 v2
= value_as_long (arg2
);
9322 if (op
== BINOP_MOD
)
9324 else if (op
== BINOP_DIV
)
9328 gdb_assert (op
== BINOP_REM
);
9332 error (_("second operand of %s must not be zero."), name
);
9335 if (type1
->is_unsigned () || op
== BINOP_MOD
)
9336 return value_binop (arg1
, arg2
, op
);
9338 v1
= value_as_long (arg1
);
9343 if (!TRUNCATION_TOWARDS_ZERO
&& v1
* (v1
% v2
) < 0)
9344 v
+= v
> 0 ? -1 : 1;
9352 /* Should not reach this point. */
9356 val
= allocate_value (type1
);
9357 store_unsigned_integer (value_contents_raw (val
),
9358 TYPE_LENGTH (value_type (val
)),
9359 type_byte_order (type1
), v
);
9364 ada_value_equal (struct value
*arg1
, struct value
*arg2
)
9366 if (ada_is_direct_array_type (value_type (arg1
))
9367 || ada_is_direct_array_type (value_type (arg2
)))
9369 struct type
*arg1_type
, *arg2_type
;
9371 /* Automatically dereference any array reference before
9372 we attempt to perform the comparison. */
9373 arg1
= ada_coerce_ref (arg1
);
9374 arg2
= ada_coerce_ref (arg2
);
9376 arg1
= ada_coerce_to_simple_array (arg1
);
9377 arg2
= ada_coerce_to_simple_array (arg2
);
9379 arg1_type
= ada_check_typedef (value_type (arg1
));
9380 arg2_type
= ada_check_typedef (value_type (arg2
));
9382 if (arg1_type
->code () != TYPE_CODE_ARRAY
9383 || arg2_type
->code () != TYPE_CODE_ARRAY
)
9384 error (_("Attempt to compare array with non-array"));
9385 /* FIXME: The following works only for types whose
9386 representations use all bits (no padding or undefined bits)
9387 and do not have user-defined equality. */
9388 return (TYPE_LENGTH (arg1_type
) == TYPE_LENGTH (arg2_type
)
9389 && memcmp (value_contents (arg1
), value_contents (arg2
),
9390 TYPE_LENGTH (arg1_type
)) == 0);
9392 return value_equal (arg1
, arg2
);
9395 /* Assign the result of evaluating EXP starting at *POS to the INDEXth
9396 component of LHS (a simple array or a record), updating *POS past
9397 the expression, assuming that LHS is contained in CONTAINER. Does
9398 not modify the inferior's memory, nor does it modify LHS (unless
9399 LHS == CONTAINER). */
9402 assign_component (struct value
*container
, struct value
*lhs
, LONGEST index
,
9403 struct expression
*exp
, int *pos
)
9405 struct value
*mark
= value_mark ();
9407 struct type
*lhs_type
= check_typedef (value_type (lhs
));
9409 if (lhs_type
->code () == TYPE_CODE_ARRAY
)
9411 struct type
*index_type
= builtin_type (exp
->gdbarch
)->builtin_int
;
9412 struct value
*index_val
= value_from_longest (index_type
, index
);
9414 elt
= unwrap_value (ada_value_subscript (lhs
, 1, &index_val
));
9418 elt
= ada_index_struct_field (index
, lhs
, 0, value_type (lhs
));
9419 elt
= ada_to_fixed_value (elt
);
9422 if (exp
->elts
[*pos
].opcode
== OP_AGGREGATE
)
9423 assign_aggregate (container
, elt
, exp
, pos
, EVAL_NORMAL
);
9425 value_assign_to_component (container
, elt
,
9426 ada_evaluate_subexp (NULL
, exp
, pos
,
9429 value_free_to_mark (mark
);
9432 /* Assuming that LHS represents an lvalue having a record or array
9433 type, and EXP->ELTS[*POS] is an OP_AGGREGATE, evaluate an assignment
9434 of that aggregate's value to LHS, advancing *POS past the
9435 aggregate. NOSIDE is as for evaluate_subexp. CONTAINER is an
9436 lvalue containing LHS (possibly LHS itself). Does not modify
9437 the inferior's memory, nor does it modify the contents of
9438 LHS (unless == CONTAINER). Returns the modified CONTAINER. */
9440 static struct value
*
9441 assign_aggregate (struct value
*container
,
9442 struct value
*lhs
, struct expression
*exp
,
9443 int *pos
, enum noside noside
)
9445 struct type
*lhs_type
;
9446 int n
= exp
->elts
[*pos
+1].longconst
;
9447 LONGEST low_index
, high_index
;
9451 if (noside
!= EVAL_NORMAL
)
9453 for (i
= 0; i
< n
; i
+= 1)
9454 ada_evaluate_subexp (NULL
, exp
, pos
, noside
);
9458 container
= ada_coerce_ref (container
);
9459 if (ada_is_direct_array_type (value_type (container
)))
9460 container
= ada_coerce_to_simple_array (container
);
9461 lhs
= ada_coerce_ref (lhs
);
9462 if (!deprecated_value_modifiable (lhs
))
9463 error (_("Left operand of assignment is not a modifiable lvalue."));
9465 lhs_type
= check_typedef (value_type (lhs
));
9466 if (ada_is_direct_array_type (lhs_type
))
9468 lhs
= ada_coerce_to_simple_array (lhs
);
9469 lhs_type
= check_typedef (value_type (lhs
));
9470 low_index
= lhs_type
->bounds ()->low
.const_val ();
9471 high_index
= lhs_type
->bounds ()->high
.const_val ();
9473 else if (lhs_type
->code () == TYPE_CODE_STRUCT
)
9476 high_index
= num_visible_fields (lhs_type
) - 1;
9479 error (_("Left-hand side must be array or record."));
9481 std::vector
<LONGEST
> indices (4);
9482 indices
[0] = indices
[1] = low_index
- 1;
9483 indices
[2] = indices
[3] = high_index
+ 1;
9485 for (i
= 0; i
< n
; i
+= 1)
9487 switch (exp
->elts
[*pos
].opcode
)
9490 aggregate_assign_from_choices (container
, lhs
, exp
, pos
, indices
,
9491 low_index
, high_index
);
9494 aggregate_assign_positional (container
, lhs
, exp
, pos
, indices
,
9495 low_index
, high_index
);
9499 error (_("Misplaced 'others' clause"));
9500 aggregate_assign_others (container
, lhs
, exp
, pos
, indices
,
9501 low_index
, high_index
);
9504 error (_("Internal error: bad aggregate clause"));
9511 /* Assign into the component of LHS indexed by the OP_POSITIONAL
9512 construct at *POS, updating *POS past the construct, given that
9513 the positions are relative to lower bound LOW, where HIGH is the
9514 upper bound. Record the position in INDICES. CONTAINER is as for
9515 assign_aggregate. */
9517 aggregate_assign_positional (struct value
*container
,
9518 struct value
*lhs
, struct expression
*exp
,
9519 int *pos
, std::vector
<LONGEST
> &indices
,
9520 LONGEST low
, LONGEST high
)
9522 LONGEST ind
= longest_to_int (exp
->elts
[*pos
+ 1].longconst
) + low
;
9524 if (ind
- 1 == high
)
9525 warning (_("Extra components in aggregate ignored."));
9528 add_component_interval (ind
, ind
, indices
);
9530 assign_component (container
, lhs
, ind
, exp
, pos
);
9533 ada_evaluate_subexp (NULL
, exp
, pos
, EVAL_SKIP
);
9536 /* Assign into the components of LHS indexed by the OP_CHOICES
9537 construct at *POS, updating *POS past the construct, given that
9538 the allowable indices are LOW..HIGH. Record the indices assigned
9539 to in INDICES. CONTAINER is as for assign_aggregate. */
9541 aggregate_assign_from_choices (struct value
*container
,
9542 struct value
*lhs
, struct expression
*exp
,
9543 int *pos
, std::vector
<LONGEST
> &indices
,
9544 LONGEST low
, LONGEST high
)
9547 int n_choices
= longest_to_int (exp
->elts
[*pos
+1].longconst
);
9548 int choice_pos
, expr_pc
;
9549 int is_array
= ada_is_direct_array_type (value_type (lhs
));
9551 choice_pos
= *pos
+= 3;
9553 for (j
= 0; j
< n_choices
; j
+= 1)
9554 ada_evaluate_subexp (NULL
, exp
, pos
, EVAL_SKIP
);
9556 ada_evaluate_subexp (NULL
, exp
, pos
, EVAL_SKIP
);
9558 for (j
= 0; j
< n_choices
; j
+= 1)
9560 LONGEST lower
, upper
;
9561 enum exp_opcode op
= exp
->elts
[choice_pos
].opcode
;
9563 if (op
== OP_DISCRETE_RANGE
)
9566 lower
= value_as_long (ada_evaluate_subexp (NULL
, exp
, pos
,
9568 upper
= value_as_long (ada_evaluate_subexp (NULL
, exp
, pos
,
9573 lower
= value_as_long (ada_evaluate_subexp (NULL
, exp
, &choice_pos
,
9585 name
= &exp
->elts
[choice_pos
+ 2].string
;
9588 name
= exp
->elts
[choice_pos
+ 2].symbol
->natural_name ();
9591 error (_("Invalid record component association."));
9593 ada_evaluate_subexp (NULL
, exp
, &choice_pos
, EVAL_SKIP
);
9595 if (! find_struct_field (name
, value_type (lhs
), 0,
9596 NULL
, NULL
, NULL
, NULL
, &ind
))
9597 error (_("Unknown component name: %s."), name
);
9598 lower
= upper
= ind
;
9601 if (lower
<= upper
&& (lower
< low
|| upper
> high
))
9602 error (_("Index in component association out of bounds."));
9604 add_component_interval (lower
, upper
, indices
);
9605 while (lower
<= upper
)
9610 assign_component (container
, lhs
, lower
, exp
, &pos1
);
9616 /* Assign the value of the expression in the OP_OTHERS construct in
9617 EXP at *POS into the components of LHS indexed from LOW .. HIGH that
9618 have not been previously assigned. The index intervals already assigned
9619 are in INDICES. Updates *POS to after the OP_OTHERS clause.
9620 CONTAINER is as for assign_aggregate. */
9622 aggregate_assign_others (struct value
*container
,
9623 struct value
*lhs
, struct expression
*exp
,
9624 int *pos
, std::vector
<LONGEST
> &indices
,
9625 LONGEST low
, LONGEST high
)
9628 int expr_pc
= *pos
+ 1;
9630 int num_indices
= indices
.size ();
9631 for (i
= 0; i
< num_indices
- 2; i
+= 2)
9635 for (ind
= indices
[i
+ 1] + 1; ind
< indices
[i
+ 2]; ind
+= 1)
9640 assign_component (container
, lhs
, ind
, exp
, &localpos
);
9643 ada_evaluate_subexp (NULL
, exp
, pos
, EVAL_SKIP
);
9650 check_objfile (const std::unique_ptr
<ada_component
> &comp
,
9651 struct objfile
*objfile
)
9653 return comp
->uses_objfile (objfile
);
9656 /* Assign the result of evaluating ARG starting at *POS to the INDEXth
9657 component of LHS (a simple array or a record). Does not modify the
9658 inferior's memory, nor does it modify LHS (unless LHS ==
9662 assign_component (struct value
*container
, struct value
*lhs
, LONGEST index
,
9663 struct expression
*exp
, operation_up
&arg
)
9665 scoped_value_mark mark
;
9668 struct type
*lhs_type
= check_typedef (value_type (lhs
));
9670 if (lhs_type
->code () == TYPE_CODE_ARRAY
)
9672 struct type
*index_type
= builtin_type (exp
->gdbarch
)->builtin_int
;
9673 struct value
*index_val
= value_from_longest (index_type
, index
);
9675 elt
= unwrap_value (ada_value_subscript (lhs
, 1, &index_val
));
9679 elt
= ada_index_struct_field (index
, lhs
, 0, value_type (lhs
));
9680 elt
= ada_to_fixed_value (elt
);
9683 ada_aggregate_operation
*ag_op
9684 = dynamic_cast<ada_aggregate_operation
*> (arg
.get ());
9685 if (ag_op
!= nullptr)
9686 ag_op
->assign_aggregate (container
, elt
, exp
);
9688 value_assign_to_component (container
, elt
,
9689 arg
->evaluate (nullptr, exp
,
9694 ada_aggregate_component::uses_objfile (struct objfile
*objfile
)
9696 for (const auto &item
: m_components
)
9697 if (item
->uses_objfile (objfile
))
9703 ada_aggregate_component::dump (ui_file
*stream
, int depth
)
9705 fprintf_filtered (stream
, _("%*sAggregate\n"), depth
, "");
9706 for (const auto &item
: m_components
)
9707 item
->dump (stream
, depth
+ 1);
9711 ada_aggregate_component::assign (struct value
*container
,
9712 struct value
*lhs
, struct expression
*exp
,
9713 std::vector
<LONGEST
> &indices
,
9714 LONGEST low
, LONGEST high
)
9716 for (auto &item
: m_components
)
9717 item
->assign (container
, lhs
, exp
, indices
, low
, high
);
9721 ada_aggregate_operation::assign_aggregate (struct value
*container
,
9723 struct expression
*exp
)
9725 struct type
*lhs_type
;
9726 LONGEST low_index
, high_index
;
9728 container
= ada_coerce_ref (container
);
9729 if (ada_is_direct_array_type (value_type (container
)))
9730 container
= ada_coerce_to_simple_array (container
);
9731 lhs
= ada_coerce_ref (lhs
);
9732 if (!deprecated_value_modifiable (lhs
))
9733 error (_("Left operand of assignment is not a modifiable lvalue."));
9735 lhs_type
= check_typedef (value_type (lhs
));
9736 if (ada_is_direct_array_type (lhs_type
))
9738 lhs
= ada_coerce_to_simple_array (lhs
);
9739 lhs_type
= check_typedef (value_type (lhs
));
9740 low_index
= lhs_type
->bounds ()->low
.const_val ();
9741 high_index
= lhs_type
->bounds ()->high
.const_val ();
9743 else if (lhs_type
->code () == TYPE_CODE_STRUCT
)
9746 high_index
= num_visible_fields (lhs_type
) - 1;
9749 error (_("Left-hand side must be array or record."));
9751 std::vector
<LONGEST
> indices (4);
9752 indices
[0] = indices
[1] = low_index
- 1;
9753 indices
[2] = indices
[3] = high_index
+ 1;
9755 std::get
<0> (m_storage
)->assign (container
, lhs
, exp
, indices
,
9756 low_index
, high_index
);
9760 ada_positional_component::uses_objfile (struct objfile
*objfile
)
9762 return m_op
->uses_objfile (objfile
);
9766 ada_positional_component::dump (ui_file
*stream
, int depth
)
9768 fprintf_filtered (stream
, _("%*sPositional, index = %d\n"),
9769 depth
, "", m_index
);
9770 m_op
->dump (stream
, depth
+ 1);
9773 /* Assign into the component of LHS indexed by the OP_POSITIONAL
9774 construct, given that the positions are relative to lower bound
9775 LOW, where HIGH is the upper bound. Record the position in
9776 INDICES. CONTAINER is as for assign_aggregate. */
9778 ada_positional_component::assign (struct value
*container
,
9779 struct value
*lhs
, struct expression
*exp
,
9780 std::vector
<LONGEST
> &indices
,
9781 LONGEST low
, LONGEST high
)
9783 LONGEST ind
= m_index
+ low
;
9785 if (ind
- 1 == high
)
9786 warning (_("Extra components in aggregate ignored."));
9789 add_component_interval (ind
, ind
, indices
);
9790 assign_component (container
, lhs
, ind
, exp
, m_op
);
9795 ada_discrete_range_association::uses_objfile (struct objfile
*objfile
)
9797 return m_low
->uses_objfile (objfile
) || m_high
->uses_objfile (objfile
);
9801 ada_discrete_range_association::dump (ui_file
*stream
, int depth
)
9803 fprintf_filtered (stream
, _("%*sDiscrete range:\n"), depth
, "");
9804 m_low
->dump (stream
, depth
+ 1);
9805 m_high
->dump (stream
, depth
+ 1);
9809 ada_discrete_range_association::assign (struct value
*container
,
9811 struct expression
*exp
,
9812 std::vector
<LONGEST
> &indices
,
9813 LONGEST low
, LONGEST high
,
9816 LONGEST lower
= value_as_long (m_low
->evaluate (nullptr, exp
, EVAL_NORMAL
));
9817 LONGEST upper
= value_as_long (m_high
->evaluate (nullptr, exp
, EVAL_NORMAL
));
9819 if (lower
<= upper
&& (lower
< low
|| upper
> high
))
9820 error (_("Index in component association out of bounds."));
9822 add_component_interval (lower
, upper
, indices
);
9823 while (lower
<= upper
)
9825 assign_component (container
, lhs
, lower
, exp
, op
);
9831 ada_name_association::uses_objfile (struct objfile
*objfile
)
9833 return m_val
->uses_objfile (objfile
);
9837 ada_name_association::dump (ui_file
*stream
, int depth
)
9839 fprintf_filtered (stream
, _("%*sName:\n"), depth
, "");
9840 m_val
->dump (stream
, depth
+ 1);
9844 ada_name_association::assign (struct value
*container
,
9846 struct expression
*exp
,
9847 std::vector
<LONGEST
> &indices
,
9848 LONGEST low
, LONGEST high
,
9853 if (ada_is_direct_array_type (value_type (lhs
)))
9854 index
= longest_to_int (value_as_long (m_val
->evaluate (nullptr, exp
,
9858 ada_string_operation
*strop
9859 = dynamic_cast<ada_string_operation
*> (m_val
.get ());
9862 if (strop
!= nullptr)
9863 name
= strop
->get_name ();
9866 ada_var_value_operation
*vvo
9867 = dynamic_cast<ada_var_value_operation
*> (m_val
.get ());
9869 error (_("Invalid record component association."));
9870 name
= vvo
->get_symbol ()->natural_name ();
9874 if (! find_struct_field (name
, value_type (lhs
), 0,
9875 NULL
, NULL
, NULL
, NULL
, &index
))
9876 error (_("Unknown component name: %s."), name
);
9879 add_component_interval (index
, index
, indices
);
9880 assign_component (container
, lhs
, index
, exp
, op
);
9884 ada_choices_component::uses_objfile (struct objfile
*objfile
)
9886 if (m_op
->uses_objfile (objfile
))
9888 for (const auto &item
: m_assocs
)
9889 if (item
->uses_objfile (objfile
))
9895 ada_choices_component::dump (ui_file
*stream
, int depth
)
9897 fprintf_filtered (stream
, _("%*sChoices:\n"), depth
, "");
9898 m_op
->dump (stream
, depth
+ 1);
9899 for (const auto &item
: m_assocs
)
9900 item
->dump (stream
, depth
+ 1);
9903 /* Assign into the components of LHS indexed by the OP_CHOICES
9904 construct at *POS, updating *POS past the construct, given that
9905 the allowable indices are LOW..HIGH. Record the indices assigned
9906 to in INDICES. CONTAINER is as for assign_aggregate. */
9908 ada_choices_component::assign (struct value
*container
,
9909 struct value
*lhs
, struct expression
*exp
,
9910 std::vector
<LONGEST
> &indices
,
9911 LONGEST low
, LONGEST high
)
9913 for (auto &item
: m_assocs
)
9914 item
->assign (container
, lhs
, exp
, indices
, low
, high
, m_op
);
9918 ada_others_component::uses_objfile (struct objfile
*objfile
)
9920 return m_op
->uses_objfile (objfile
);
9924 ada_others_component::dump (ui_file
*stream
, int depth
)
9926 fprintf_filtered (stream
, _("%*sOthers:\n"), depth
, "");
9927 m_op
->dump (stream
, depth
+ 1);
9930 /* Assign the value of the expression in the OP_OTHERS construct in
9931 EXP at *POS into the components of LHS indexed from LOW .. HIGH that
9932 have not been previously assigned. The index intervals already assigned
9933 are in INDICES. CONTAINER is as for assign_aggregate. */
9935 ada_others_component::assign (struct value
*container
,
9936 struct value
*lhs
, struct expression
*exp
,
9937 std::vector
<LONGEST
> &indices
,
9938 LONGEST low
, LONGEST high
)
9940 int num_indices
= indices
.size ();
9941 for (int i
= 0; i
< num_indices
- 2; i
+= 2)
9943 for (LONGEST ind
= indices
[i
+ 1] + 1; ind
< indices
[i
+ 2]; ind
+= 1)
9944 assign_component (container
, lhs
, ind
, exp
, m_op
);
9949 ada_assign_operation::evaluate (struct type
*expect_type
,
9950 struct expression
*exp
,
9953 value
*arg1
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
9955 ada_aggregate_operation
*ag_op
9956 = dynamic_cast<ada_aggregate_operation
*> (std::get
<1> (m_storage
).get ());
9957 if (ag_op
!= nullptr)
9959 if (noside
!= EVAL_NORMAL
)
9962 ag_op
->assign_aggregate (arg1
, arg1
, exp
);
9963 return ada_value_assign (arg1
, arg1
);
9965 /* Force the evaluation of the rhs ARG2 to the type of the lhs ARG1,
9966 except if the lhs of our assignment is a convenience variable.
9967 In the case of assigning to a convenience variable, the lhs
9968 should be exactly the result of the evaluation of the rhs. */
9969 struct type
*type
= value_type (arg1
);
9970 if (VALUE_LVAL (arg1
) == lval_internalvar
)
9972 value
*arg2
= std::get
<1> (m_storage
)->evaluate (type
, exp
, noside
);
9973 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
9975 if (VALUE_LVAL (arg1
) == lval_internalvar
)
9980 arg2
= coerce_for_assign (value_type (arg1
), arg2
);
9981 return ada_value_assign (arg1
, arg2
);
9984 } /* namespace expr */
9986 /* Add the interval [LOW .. HIGH] to the sorted set of intervals
9987 [ INDICES[0] .. INDICES[1] ],... The resulting intervals do not
9990 add_component_interval (LONGEST low
, LONGEST high
,
9991 std::vector
<LONGEST
> &indices
)
9995 int size
= indices
.size ();
9996 for (i
= 0; i
< size
; i
+= 2) {
9997 if (high
>= indices
[i
] && low
<= indices
[i
+ 1])
10001 for (kh
= i
+ 2; kh
< size
; kh
+= 2)
10002 if (high
< indices
[kh
])
10004 if (low
< indices
[i
])
10006 indices
[i
+ 1] = indices
[kh
- 1];
10007 if (high
> indices
[i
+ 1])
10008 indices
[i
+ 1] = high
;
10009 memcpy (indices
.data () + i
+ 2, indices
.data () + kh
, size
- kh
);
10010 indices
.resize (kh
- i
- 2);
10013 else if (high
< indices
[i
])
10017 indices
.resize (indices
.size () + 2);
10018 for (j
= indices
.size () - 1; j
>= i
+ 2; j
-= 1)
10019 indices
[j
] = indices
[j
- 2];
10021 indices
[i
+ 1] = high
;
10024 /* Perform and Ada cast of ARG2 to type TYPE if the type of ARG2
10027 static struct value
*
10028 ada_value_cast (struct type
*type
, struct value
*arg2
)
10030 if (type
== ada_check_typedef (value_type (arg2
)))
10033 return value_cast (type
, arg2
);
10036 /* Evaluating Ada expressions, and printing their result.
10037 ------------------------------------------------------
10042 We usually evaluate an Ada expression in order to print its value.
10043 We also evaluate an expression in order to print its type, which
10044 happens during the EVAL_AVOID_SIDE_EFFECTS phase of the evaluation,
10045 but we'll focus mostly on the EVAL_NORMAL phase. In practice, the
10046 EVAL_AVOID_SIDE_EFFECTS phase allows us to simplify certain aspects of
10047 the evaluation compared to the EVAL_NORMAL, but is otherwise very
10050 Evaluating expressions is a little more complicated for Ada entities
10051 than it is for entities in languages such as C. The main reason for
10052 this is that Ada provides types whose definition might be dynamic.
10053 One example of such types is variant records. Or another example
10054 would be an array whose bounds can only be known at run time.
10056 The following description is a general guide as to what should be
10057 done (and what should NOT be done) in order to evaluate an expression
10058 involving such types, and when. This does not cover how the semantic
10059 information is encoded by GNAT as this is covered separatly. For the
10060 document used as the reference for the GNAT encoding, see exp_dbug.ads
10061 in the GNAT sources.
10063 Ideally, we should embed each part of this description next to its
10064 associated code. Unfortunately, the amount of code is so vast right
10065 now that it's hard to see whether the code handling a particular
10066 situation might be duplicated or not. One day, when the code is
10067 cleaned up, this guide might become redundant with the comments
10068 inserted in the code, and we might want to remove it.
10070 2. ``Fixing'' an Entity, the Simple Case:
10071 -----------------------------------------
10073 When evaluating Ada expressions, the tricky issue is that they may
10074 reference entities whose type contents and size are not statically
10075 known. Consider for instance a variant record:
10077 type Rec (Empty : Boolean := True) is record
10080 when False => Value : Integer;
10083 Yes : Rec := (Empty => False, Value => 1);
10084 No : Rec := (empty => True);
10086 The size and contents of that record depends on the value of the
10087 descriminant (Rec.Empty). At this point, neither the debugging
10088 information nor the associated type structure in GDB are able to
10089 express such dynamic types. So what the debugger does is to create
10090 "fixed" versions of the type that applies to the specific object.
10091 We also informally refer to this operation as "fixing" an object,
10092 which means creating its associated fixed type.
10094 Example: when printing the value of variable "Yes" above, its fixed
10095 type would look like this:
10102 On the other hand, if we printed the value of "No", its fixed type
10109 Things become a little more complicated when trying to fix an entity
10110 with a dynamic type that directly contains another dynamic type,
10111 such as an array of variant records, for instance. There are
10112 two possible cases: Arrays, and records.
10114 3. ``Fixing'' Arrays:
10115 ---------------------
10117 The type structure in GDB describes an array in terms of its bounds,
10118 and the type of its elements. By design, all elements in the array
10119 have the same type and we cannot represent an array of variant elements
10120 using the current type structure in GDB. When fixing an array,
10121 we cannot fix the array element, as we would potentially need one
10122 fixed type per element of the array. As a result, the best we can do
10123 when fixing an array is to produce an array whose bounds and size
10124 are correct (allowing us to read it from memory), but without having
10125 touched its element type. Fixing each element will be done later,
10126 when (if) necessary.
10128 Arrays are a little simpler to handle than records, because the same
10129 amount of memory is allocated for each element of the array, even if
10130 the amount of space actually used by each element differs from element
10131 to element. Consider for instance the following array of type Rec:
10133 type Rec_Array is array (1 .. 2) of Rec;
10135 The actual amount of memory occupied by each element might be different
10136 from element to element, depending on the value of their discriminant.
10137 But the amount of space reserved for each element in the array remains
10138 fixed regardless. So we simply need to compute that size using
10139 the debugging information available, from which we can then determine
10140 the array size (we multiply the number of elements of the array by
10141 the size of each element).
10143 The simplest case is when we have an array of a constrained element
10144 type. For instance, consider the following type declarations:
10146 type Bounded_String (Max_Size : Integer) is
10148 Buffer : String (1 .. Max_Size);
10150 type Bounded_String_Array is array (1 ..2) of Bounded_String (80);
10152 In this case, the compiler describes the array as an array of
10153 variable-size elements (identified by its XVS suffix) for which
10154 the size can be read in the parallel XVZ variable.
10156 In the case of an array of an unconstrained element type, the compiler
10157 wraps the array element inside a private PAD type. This type should not
10158 be shown to the user, and must be "unwrap"'ed before printing. Note
10159 that we also use the adjective "aligner" in our code to designate
10160 these wrapper types.
10162 In some cases, the size allocated for each element is statically
10163 known. In that case, the PAD type already has the correct size,
10164 and the array element should remain unfixed.
10166 But there are cases when this size is not statically known.
10167 For instance, assuming that "Five" is an integer variable:
10169 type Dynamic is array (1 .. Five) of Integer;
10170 type Wrapper (Has_Length : Boolean := False) is record
10173 when True => Length : Integer;
10174 when False => null;
10177 type Wrapper_Array is array (1 .. 2) of Wrapper;
10179 Hello : Wrapper_Array := (others => (Has_Length => True,
10180 Data => (others => 17),
10184 The debugging info would describe variable Hello as being an
10185 array of a PAD type. The size of that PAD type is not statically
10186 known, but can be determined using a parallel XVZ variable.
10187 In that case, a copy of the PAD type with the correct size should
10188 be used for the fixed array.
10190 3. ``Fixing'' record type objects:
10191 ----------------------------------
10193 Things are slightly different from arrays in the case of dynamic
10194 record types. In this case, in order to compute the associated
10195 fixed type, we need to determine the size and offset of each of
10196 its components. This, in turn, requires us to compute the fixed
10197 type of each of these components.
10199 Consider for instance the example:
10201 type Bounded_String (Max_Size : Natural) is record
10202 Str : String (1 .. Max_Size);
10205 My_String : Bounded_String (Max_Size => 10);
10207 In that case, the position of field "Length" depends on the size
10208 of field Str, which itself depends on the value of the Max_Size
10209 discriminant. In order to fix the type of variable My_String,
10210 we need to fix the type of field Str. Therefore, fixing a variant
10211 record requires us to fix each of its components.
10213 However, if a component does not have a dynamic size, the component
10214 should not be fixed. In particular, fields that use a PAD type
10215 should not fixed. Here is an example where this might happen
10216 (assuming type Rec above):
10218 type Container (Big : Boolean) is record
10222 when True => Another : Integer;
10223 when False => null;
10226 My_Container : Container := (Big => False,
10227 First => (Empty => True),
10230 In that example, the compiler creates a PAD type for component First,
10231 whose size is constant, and then positions the component After just
10232 right after it. The offset of component After is therefore constant
10235 The debugger computes the position of each field based on an algorithm
10236 that uses, among other things, the actual position and size of the field
10237 preceding it. Let's now imagine that the user is trying to print
10238 the value of My_Container. If the type fixing was recursive, we would
10239 end up computing the offset of field After based on the size of the
10240 fixed version of field First. And since in our example First has
10241 only one actual field, the size of the fixed type is actually smaller
10242 than the amount of space allocated to that field, and thus we would
10243 compute the wrong offset of field After.
10245 To make things more complicated, we need to watch out for dynamic
10246 components of variant records (identified by the ___XVL suffix in
10247 the component name). Even if the target type is a PAD type, the size
10248 of that type might not be statically known. So the PAD type needs
10249 to be unwrapped and the resulting type needs to be fixed. Otherwise,
10250 we might end up with the wrong size for our component. This can be
10251 observed with the following type declarations:
10253 type Octal is new Integer range 0 .. 7;
10254 type Octal_Array is array (Positive range <>) of Octal;
10255 pragma Pack (Octal_Array);
10257 type Octal_Buffer (Size : Positive) is record
10258 Buffer : Octal_Array (1 .. Size);
10262 In that case, Buffer is a PAD type whose size is unset and needs
10263 to be computed by fixing the unwrapped type.
10265 4. When to ``Fix'' un-``Fixed'' sub-elements of an entity:
10266 ----------------------------------------------------------
10268 Lastly, when should the sub-elements of an entity that remained unfixed
10269 thus far, be actually fixed?
10271 The answer is: Only when referencing that element. For instance
10272 when selecting one component of a record, this specific component
10273 should be fixed at that point in time. Or when printing the value
10274 of a record, each component should be fixed before its value gets
10275 printed. Similarly for arrays, the element of the array should be
10276 fixed when printing each element of the array, or when extracting
10277 one element out of that array. On the other hand, fixing should
10278 not be performed on the elements when taking a slice of an array!
10280 Note that one of the side effects of miscomputing the offset and
10281 size of each field is that we end up also miscomputing the size
10282 of the containing type. This can have adverse results when computing
10283 the value of an entity. GDB fetches the value of an entity based
10284 on the size of its type, and thus a wrong size causes GDB to fetch
10285 the wrong amount of memory. In the case where the computed size is
10286 too small, GDB fetches too little data to print the value of our
10287 entity. Results in this case are unpredictable, as we usually read
10288 past the buffer containing the data =:-o. */
10290 /* Evaluate a subexpression of EXP, at index *POS, and return a value
10291 for that subexpression cast to TO_TYPE. Advance *POS over the
10295 ada_evaluate_subexp_for_cast (expression
*exp
, int *pos
,
10296 enum noside noside
, struct type
*to_type
)
10300 if (exp
->elts
[pc
].opcode
== OP_VAR_MSYM_VALUE
10301 || exp
->elts
[pc
].opcode
== OP_VAR_VALUE
)
10306 if (exp
->elts
[pc
].opcode
== OP_VAR_MSYM_VALUE
)
10308 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
10309 return value_zero (to_type
, not_lval
);
10311 val
= evaluate_var_msym_value (noside
,
10312 exp
->elts
[pc
+ 1].objfile
,
10313 exp
->elts
[pc
+ 2].msymbol
);
10316 val
= evaluate_var_value (noside
,
10317 exp
->elts
[pc
+ 1].block
,
10318 exp
->elts
[pc
+ 2].symbol
);
10320 if (noside
== EVAL_SKIP
)
10321 return eval_skip_value (exp
);
10323 val
= ada_value_cast (to_type
, val
);
10325 /* Follow the Ada language semantics that do not allow taking
10326 an address of the result of a cast (view conversion in Ada). */
10327 if (VALUE_LVAL (val
) == lval_memory
)
10329 if (value_lazy (val
))
10330 value_fetch_lazy (val
);
10331 VALUE_LVAL (val
) = not_lval
;
10336 value
*val
= evaluate_subexp (to_type
, exp
, pos
, noside
);
10337 if (noside
== EVAL_SKIP
)
10338 return eval_skip_value (exp
);
10339 return ada_value_cast (to_type
, val
);
10342 /* A helper function for TERNOP_IN_RANGE. */
10345 eval_ternop_in_range (struct type
*expect_type
, struct expression
*exp
,
10346 enum noside noside
,
10347 value
*arg1
, value
*arg2
, value
*arg3
)
10349 if (noside
== EVAL_SKIP
)
10350 return eval_skip_value (exp
);
10352 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
10353 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg3
);
10354 struct type
*type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
10356 value_from_longest (type
,
10357 (value_less (arg1
, arg3
)
10358 || value_equal (arg1
, arg3
))
10359 && (value_less (arg2
, arg1
)
10360 || value_equal (arg2
, arg1
)));
10363 /* A helper function for UNOP_NEG. */
10366 ada_unop_neg (struct type
*expect_type
,
10367 struct expression
*exp
,
10368 enum noside noside
, enum exp_opcode op
,
10369 struct value
*arg1
)
10371 if (noside
== EVAL_SKIP
)
10372 return eval_skip_value (exp
);
10373 unop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
);
10374 return value_neg (arg1
);
10377 /* A helper function for UNOP_IN_RANGE. */
10380 ada_unop_in_range (struct type
*expect_type
,
10381 struct expression
*exp
,
10382 enum noside noside
, enum exp_opcode op
,
10383 struct value
*arg1
, struct type
*type
)
10385 if (noside
== EVAL_SKIP
)
10386 return eval_skip_value (exp
);
10388 struct value
*arg2
, *arg3
;
10389 switch (type
->code ())
10392 lim_warning (_("Membership test incompletely implemented; "
10393 "always returns true"));
10394 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
10395 return value_from_longest (type
, (LONGEST
) 1);
10397 case TYPE_CODE_RANGE
:
10398 arg2
= value_from_longest (type
,
10399 type
->bounds ()->low
.const_val ());
10400 arg3
= value_from_longest (type
,
10401 type
->bounds ()->high
.const_val ());
10402 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
10403 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg3
);
10404 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
10406 value_from_longest (type
,
10407 (value_less (arg1
, arg3
)
10408 || value_equal (arg1
, arg3
))
10409 && (value_less (arg2
, arg1
)
10410 || value_equal (arg2
, arg1
)));
10414 /* A helper function for OP_ATR_TAG. */
10417 ada_atr_tag (struct type
*expect_type
,
10418 struct expression
*exp
,
10419 enum noside noside
, enum exp_opcode op
,
10420 struct value
*arg1
)
10422 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
10423 return value_zero (ada_tag_type (arg1
), not_lval
);
10425 return ada_value_tag (arg1
);
10428 /* A helper function for OP_ATR_SIZE. */
10431 ada_atr_size (struct type
*expect_type
,
10432 struct expression
*exp
,
10433 enum noside noside
, enum exp_opcode op
,
10434 struct value
*arg1
)
10436 struct type
*type
= value_type (arg1
);
10438 /* If the argument is a reference, then dereference its type, since
10439 the user is really asking for the size of the actual object,
10440 not the size of the pointer. */
10441 if (type
->code () == TYPE_CODE_REF
)
10442 type
= TYPE_TARGET_TYPE (type
);
10444 if (noside
== EVAL_SKIP
)
10445 return eval_skip_value (exp
);
10446 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
10447 return value_zero (builtin_type (exp
->gdbarch
)->builtin_int
, not_lval
);
10449 return value_from_longest (builtin_type (exp
->gdbarch
)->builtin_int
,
10450 TARGET_CHAR_BIT
* TYPE_LENGTH (type
));
10453 /* A helper function for UNOP_ABS. */
10456 ada_abs (struct type
*expect_type
,
10457 struct expression
*exp
,
10458 enum noside noside
, enum exp_opcode op
,
10459 struct value
*arg1
)
10461 unop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
);
10462 if (value_less (arg1
, value_zero (value_type (arg1
), not_lval
)))
10463 return value_neg (arg1
);
10468 /* A helper function for BINOP_MUL. */
10471 ada_mult_binop (struct type
*expect_type
,
10472 struct expression
*exp
,
10473 enum noside noside
, enum exp_opcode op
,
10474 struct value
*arg1
, struct value
*arg2
)
10476 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
10478 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
10479 return value_zero (value_type (arg1
), not_lval
);
10483 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
10484 return ada_value_binop (arg1
, arg2
, op
);
10488 /* A helper function for BINOP_EQUAL and BINOP_NOTEQUAL. */
10491 ada_equal_binop (struct type
*expect_type
,
10492 struct expression
*exp
,
10493 enum noside noside
, enum exp_opcode op
,
10494 struct value
*arg1
, struct value
*arg2
)
10497 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
10501 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
10502 tem
= ada_value_equal (arg1
, arg2
);
10504 if (op
== BINOP_NOTEQUAL
)
10506 struct type
*type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
10507 return value_from_longest (type
, (LONGEST
) tem
);
10510 /* A helper function for TERNOP_SLICE. */
10513 ada_ternop_slice (struct expression
*exp
,
10514 enum noside noside
,
10515 struct value
*array
, struct value
*low_bound_val
,
10516 struct value
*high_bound_val
)
10519 LONGEST high_bound
;
10521 low_bound_val
= coerce_ref (low_bound_val
);
10522 high_bound_val
= coerce_ref (high_bound_val
);
10523 low_bound
= value_as_long (low_bound_val
);
10524 high_bound
= value_as_long (high_bound_val
);
10526 /* If this is a reference to an aligner type, then remove all
10528 if (value_type (array
)->code () == TYPE_CODE_REF
10529 && ada_is_aligner_type (TYPE_TARGET_TYPE (value_type (array
))))
10530 TYPE_TARGET_TYPE (value_type (array
)) =
10531 ada_aligned_type (TYPE_TARGET_TYPE (value_type (array
)));
10533 if (ada_is_any_packed_array_type (value_type (array
)))
10534 error (_("cannot slice a packed array"));
10536 /* If this is a reference to an array or an array lvalue,
10537 convert to a pointer. */
10538 if (value_type (array
)->code () == TYPE_CODE_REF
10539 || (value_type (array
)->code () == TYPE_CODE_ARRAY
10540 && VALUE_LVAL (array
) == lval_memory
))
10541 array
= value_addr (array
);
10543 if (noside
== EVAL_AVOID_SIDE_EFFECTS
10544 && ada_is_array_descriptor_type (ada_check_typedef
10545 (value_type (array
))))
10546 return empty_array (ada_type_of_array (array
, 0), low_bound
,
10549 array
= ada_coerce_to_simple_array_ptr (array
);
10551 /* If we have more than one level of pointer indirection,
10552 dereference the value until we get only one level. */
10553 while (value_type (array
)->code () == TYPE_CODE_PTR
10554 && (TYPE_TARGET_TYPE (value_type (array
))->code ()
10556 array
= value_ind (array
);
10558 /* Make sure we really do have an array type before going further,
10559 to avoid a SEGV when trying to get the index type or the target
10560 type later down the road if the debug info generated by
10561 the compiler is incorrect or incomplete. */
10562 if (!ada_is_simple_array_type (value_type (array
)))
10563 error (_("cannot take slice of non-array"));
10565 if (ada_check_typedef (value_type (array
))->code ()
10568 struct type
*type0
= ada_check_typedef (value_type (array
));
10570 if (high_bound
< low_bound
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
10571 return empty_array (TYPE_TARGET_TYPE (type0
), low_bound
, high_bound
);
10574 struct type
*arr_type0
=
10575 to_fixed_array_type (TYPE_TARGET_TYPE (type0
), NULL
, 1);
10577 return ada_value_slice_from_ptr (array
, arr_type0
,
10578 longest_to_int (low_bound
),
10579 longest_to_int (high_bound
));
10582 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
10584 else if (high_bound
< low_bound
)
10585 return empty_array (value_type (array
), low_bound
, high_bound
);
10587 return ada_value_slice (array
, longest_to_int (low_bound
),
10588 longest_to_int (high_bound
));
10591 /* A helper function for BINOP_IN_BOUNDS. */
10594 ada_binop_in_bounds (struct expression
*exp
, enum noside noside
,
10595 struct value
*arg1
, struct value
*arg2
, int n
)
10597 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
10599 struct type
*type
= language_bool_type (exp
->language_defn
,
10601 return value_zero (type
, not_lval
);
10604 struct type
*type
= ada_index_type (value_type (arg2
), n
, "range");
10606 type
= value_type (arg1
);
10608 value
*arg3
= value_from_longest (type
, ada_array_bound (arg2
, n
, 1));
10609 arg2
= value_from_longest (type
, ada_array_bound (arg2
, n
, 0));
10611 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
10612 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg3
);
10613 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
10614 return value_from_longest (type
,
10615 (value_less (arg1
, arg3
)
10616 || value_equal (arg1
, arg3
))
10617 && (value_less (arg2
, arg1
)
10618 || value_equal (arg2
, arg1
)));
10621 /* A helper function for some attribute operations. */
10624 ada_unop_atr (struct expression
*exp
, enum noside noside
, enum exp_opcode op
,
10625 struct value
*arg1
, struct type
*type_arg
, int tem
)
10627 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
10629 if (type_arg
== NULL
)
10630 type_arg
= value_type (arg1
);
10632 if (ada_is_constrained_packed_array_type (type_arg
))
10633 type_arg
= decode_constrained_packed_array_type (type_arg
);
10635 if (!discrete_type_p (type_arg
))
10639 default: /* Should never happen. */
10640 error (_("unexpected attribute encountered"));
10643 type_arg
= ada_index_type (type_arg
, tem
,
10644 ada_attribute_name (op
));
10646 case OP_ATR_LENGTH
:
10647 type_arg
= builtin_type (exp
->gdbarch
)->builtin_int
;
10652 return value_zero (type_arg
, not_lval
);
10654 else if (type_arg
== NULL
)
10656 arg1
= ada_coerce_ref (arg1
);
10658 if (ada_is_constrained_packed_array_type (value_type (arg1
)))
10659 arg1
= ada_coerce_to_simple_array (arg1
);
10662 if (op
== OP_ATR_LENGTH
)
10663 type
= builtin_type (exp
->gdbarch
)->builtin_int
;
10666 type
= ada_index_type (value_type (arg1
), tem
,
10667 ada_attribute_name (op
));
10669 type
= builtin_type (exp
->gdbarch
)->builtin_int
;
10674 default: /* Should never happen. */
10675 error (_("unexpected attribute encountered"));
10677 return value_from_longest
10678 (type
, ada_array_bound (arg1
, tem
, 0));
10680 return value_from_longest
10681 (type
, ada_array_bound (arg1
, tem
, 1));
10682 case OP_ATR_LENGTH
:
10683 return value_from_longest
10684 (type
, ada_array_length (arg1
, tem
));
10687 else if (discrete_type_p (type_arg
))
10689 struct type
*range_type
;
10690 const char *name
= ada_type_name (type_arg
);
10693 if (name
!= NULL
&& type_arg
->code () != TYPE_CODE_ENUM
)
10694 range_type
= to_fixed_range_type (type_arg
, NULL
);
10695 if (range_type
== NULL
)
10696 range_type
= type_arg
;
10700 error (_("unexpected attribute encountered"));
10702 return value_from_longest
10703 (range_type
, ada_discrete_type_low_bound (range_type
));
10705 return value_from_longest
10706 (range_type
, ada_discrete_type_high_bound (range_type
));
10707 case OP_ATR_LENGTH
:
10708 error (_("the 'length attribute applies only to array types"));
10711 else if (type_arg
->code () == TYPE_CODE_FLT
)
10712 error (_("unimplemented type attribute"));
10717 if (ada_is_constrained_packed_array_type (type_arg
))
10718 type_arg
= decode_constrained_packed_array_type (type_arg
);
10721 if (op
== OP_ATR_LENGTH
)
10722 type
= builtin_type (exp
->gdbarch
)->builtin_int
;
10725 type
= ada_index_type (type_arg
, tem
, ada_attribute_name (op
));
10727 type
= builtin_type (exp
->gdbarch
)->builtin_int
;
10733 error (_("unexpected attribute encountered"));
10735 low
= ada_array_bound_from_type (type_arg
, tem
, 0);
10736 return value_from_longest (type
, low
);
10738 high
= ada_array_bound_from_type (type_arg
, tem
, 1);
10739 return value_from_longest (type
, high
);
10740 case OP_ATR_LENGTH
:
10741 low
= ada_array_bound_from_type (type_arg
, tem
, 0);
10742 high
= ada_array_bound_from_type (type_arg
, tem
, 1);
10743 return value_from_longest (type
, high
- low
+ 1);
10748 /* A helper function for OP_ATR_MIN and OP_ATR_MAX. */
10751 ada_binop_minmax (struct type
*expect_type
,
10752 struct expression
*exp
,
10753 enum noside noside
, enum exp_opcode op
,
10754 struct value
*arg1
, struct value
*arg2
)
10756 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
10757 return value_zero (value_type (arg1
), not_lval
);
10760 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
10761 return value_binop (arg1
, arg2
,
10762 op
== OP_ATR_MIN
? BINOP_MIN
: BINOP_MAX
);
10766 /* A helper function for BINOP_EXP. */
10769 ada_binop_exp (struct type
*expect_type
,
10770 struct expression
*exp
,
10771 enum noside noside
, enum exp_opcode op
,
10772 struct value
*arg1
, struct value
*arg2
)
10774 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
10775 return value_zero (value_type (arg1
), not_lval
);
10778 /* For integer exponentiation operations,
10779 only promote the first argument. */
10780 if (is_integral_type (value_type (arg2
)))
10781 unop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
);
10783 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
10785 return value_binop (arg1
, arg2
, op
);
10793 ada_wrapped_operation::evaluate (struct type
*expect_type
,
10794 struct expression
*exp
,
10795 enum noside noside
)
10797 value
*result
= std::get
<0> (m_storage
)->evaluate (expect_type
, exp
, noside
);
10798 if (noside
== EVAL_NORMAL
)
10799 result
= unwrap_value (result
);
10801 /* If evaluating an OP_FLOAT and an EXPECT_TYPE was provided,
10802 then we need to perform the conversion manually, because
10803 evaluate_subexp_standard doesn't do it. This conversion is
10804 necessary in Ada because the different kinds of float/fixed
10805 types in Ada have different representations.
10807 Similarly, we need to perform the conversion from OP_LONG
10809 if ((opcode () == OP_FLOAT
|| opcode () == OP_LONG
) && expect_type
!= NULL
)
10810 result
= ada_value_cast (expect_type
, result
);
10816 ada_string_operation::evaluate (struct type
*expect_type
,
10817 struct expression
*exp
,
10818 enum noside noside
)
10820 value
*result
= string_operation::evaluate (expect_type
, exp
, noside
);
10821 /* The result type will have code OP_STRING, bashed there from
10822 OP_ARRAY. Bash it back. */
10823 if (value_type (result
)->code () == TYPE_CODE_STRING
)
10824 value_type (result
)->set_code (TYPE_CODE_ARRAY
);
10829 ada_qual_operation::evaluate (struct type
*expect_type
,
10830 struct expression
*exp
,
10831 enum noside noside
)
10833 struct type
*type
= std::get
<1> (m_storage
);
10834 return std::get
<0> (m_storage
)->evaluate (type
, exp
, noside
);
10838 ada_ternop_range_operation::evaluate (struct type
*expect_type
,
10839 struct expression
*exp
,
10840 enum noside noside
)
10842 value
*arg0
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
10843 value
*arg1
= std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
10844 value
*arg2
= std::get
<2> (m_storage
)->evaluate (nullptr, exp
, noside
);
10845 return eval_ternop_in_range (expect_type
, exp
, noside
, arg0
, arg1
, arg2
);
10849 ada_binop_addsub_operation::evaluate (struct type
*expect_type
,
10850 struct expression
*exp
,
10851 enum noside noside
)
10853 value
*arg1
= std::get
<1> (m_storage
)->evaluate_with_coercion (exp
, noside
);
10854 value
*arg2
= std::get
<2> (m_storage
)->evaluate_with_coercion (exp
, noside
);
10856 auto do_op
= [=] (LONGEST x
, LONGEST y
)
10858 if (std::get
<0> (m_storage
) == BINOP_ADD
)
10863 if (value_type (arg1
)->code () == TYPE_CODE_PTR
)
10864 return (value_from_longest
10865 (value_type (arg1
),
10866 do_op (value_as_long (arg1
), value_as_long (arg2
))));
10867 if (value_type (arg2
)->code () == TYPE_CODE_PTR
)
10868 return (value_from_longest
10869 (value_type (arg2
),
10870 do_op (value_as_long (arg1
), value_as_long (arg2
))));
10871 /* Preserve the original type for use by the range case below.
10872 We cannot cast the result to a reference type, so if ARG1 is
10873 a reference type, find its underlying type. */
10874 struct type
*type
= value_type (arg1
);
10875 while (type
->code () == TYPE_CODE_REF
)
10876 type
= TYPE_TARGET_TYPE (type
);
10877 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
10878 arg1
= value_binop (arg1
, arg2
, std::get
<0> (m_storage
));
10879 /* We need to special-case the result with a range.
10880 This is done for the benefit of "ptype". gdb's Ada support
10881 historically used the LHS to set the result type here, so
10882 preserve this behavior. */
10883 if (type
->code () == TYPE_CODE_RANGE
)
10884 arg1
= value_cast (type
, arg1
);
10889 ada_unop_atr_operation::evaluate (struct type
*expect_type
,
10890 struct expression
*exp
,
10891 enum noside noside
)
10893 struct type
*type_arg
= nullptr;
10894 value
*val
= nullptr;
10896 if (std::get
<0> (m_storage
)->opcode () == OP_TYPE
)
10898 value
*tem
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
10899 EVAL_AVOID_SIDE_EFFECTS
);
10900 type_arg
= value_type (tem
);
10903 val
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
10905 return ada_unop_atr (exp
, noside
, std::get
<1> (m_storage
),
10906 val
, type_arg
, std::get
<2> (m_storage
));
10910 ada_var_msym_value_operation::evaluate_for_cast (struct type
*expect_type
,
10911 struct expression
*exp
,
10912 enum noside noside
)
10914 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
10915 return value_zero (expect_type
, not_lval
);
10917 value
*val
= evaluate_var_msym_value (noside
,
10918 std::get
<1> (m_storage
),
10919 std::get
<0> (m_storage
));
10921 val
= ada_value_cast (expect_type
, val
);
10923 /* Follow the Ada language semantics that do not allow taking
10924 an address of the result of a cast (view conversion in Ada). */
10925 if (VALUE_LVAL (val
) == lval_memory
)
10927 if (value_lazy (val
))
10928 value_fetch_lazy (val
);
10929 VALUE_LVAL (val
) = not_lval
;
10935 ada_var_value_operation::evaluate_for_cast (struct type
*expect_type
,
10936 struct expression
*exp
,
10937 enum noside noside
)
10939 value
*val
= evaluate_var_value (noside
,
10940 std::get
<1> (m_storage
),
10941 std::get
<0> (m_storage
));
10943 val
= ada_value_cast (expect_type
, val
);
10945 /* Follow the Ada language semantics that do not allow taking
10946 an address of the result of a cast (view conversion in Ada). */
10947 if (VALUE_LVAL (val
) == lval_memory
)
10949 if (value_lazy (val
))
10950 value_fetch_lazy (val
);
10951 VALUE_LVAL (val
) = not_lval
;
10957 ada_var_value_operation::evaluate (struct type
*expect_type
,
10958 struct expression
*exp
,
10959 enum noside noside
)
10961 symbol
*sym
= std::get
<0> (m_storage
);
10963 if (SYMBOL_DOMAIN (sym
) == UNDEF_DOMAIN
)
10964 /* Only encountered when an unresolved symbol occurs in a
10965 context other than a function call, in which case, it is
10967 error (_("Unexpected unresolved symbol, %s, during evaluation"),
10968 sym
->print_name ());
10970 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
10972 struct type
*type
= static_unwrap_type (SYMBOL_TYPE (sym
));
10973 /* Check to see if this is a tagged type. We also need to handle
10974 the case where the type is a reference to a tagged type, but
10975 we have to be careful to exclude pointers to tagged types.
10976 The latter should be shown as usual (as a pointer), whereas
10977 a reference should mostly be transparent to the user. */
10978 if (ada_is_tagged_type (type
, 0)
10979 || (type
->code () == TYPE_CODE_REF
10980 && ada_is_tagged_type (TYPE_TARGET_TYPE (type
), 0)))
10982 /* Tagged types are a little special in the fact that the real
10983 type is dynamic and can only be determined by inspecting the
10984 object's tag. This means that we need to get the object's
10985 value first (EVAL_NORMAL) and then extract the actual object
10988 Note that we cannot skip the final step where we extract
10989 the object type from its tag, because the EVAL_NORMAL phase
10990 results in dynamic components being resolved into fixed ones.
10991 This can cause problems when trying to print the type
10992 description of tagged types whose parent has a dynamic size:
10993 We use the type name of the "_parent" component in order
10994 to print the name of the ancestor type in the type description.
10995 If that component had a dynamic size, the resolution into
10996 a fixed type would result in the loss of that type name,
10997 thus preventing us from printing the name of the ancestor
10998 type in the type description. */
10999 value
*arg1
= var_value_operation::evaluate (nullptr, exp
,
11002 if (type
->code () != TYPE_CODE_REF
)
11004 struct type
*actual_type
;
11006 actual_type
= type_from_tag (ada_value_tag (arg1
));
11007 if (actual_type
== NULL
)
11008 /* If, for some reason, we were unable to determine
11009 the actual type from the tag, then use the static
11010 approximation that we just computed as a fallback.
11011 This can happen if the debugging information is
11012 incomplete, for instance. */
11013 actual_type
= type
;
11014 return value_zero (actual_type
, not_lval
);
11018 /* In the case of a ref, ada_coerce_ref takes care
11019 of determining the actual type. But the evaluation
11020 should return a ref as it should be valid to ask
11021 for its address; so rebuild a ref after coerce. */
11022 arg1
= ada_coerce_ref (arg1
);
11023 return value_ref (arg1
, TYPE_CODE_REF
);
11027 /* Records and unions for which GNAT encodings have been
11028 generated need to be statically fixed as well.
11029 Otherwise, non-static fixing produces a type where
11030 all dynamic properties are removed, which prevents "ptype"
11031 from being able to completely describe the type.
11032 For instance, a case statement in a variant record would be
11033 replaced by the relevant components based on the actual
11034 value of the discriminants. */
11035 if ((type
->code () == TYPE_CODE_STRUCT
11036 && dynamic_template_type (type
) != NULL
)
11037 || (type
->code () == TYPE_CODE_UNION
11038 && ada_find_parallel_type (type
, "___XVU") != NULL
))
11039 return value_zero (to_static_fixed_type (type
), not_lval
);
11042 value
*arg1
= var_value_operation::evaluate (expect_type
, exp
, noside
);
11043 return ada_to_fixed_value (arg1
);
11047 ada_var_value_operation::resolve (struct expression
*exp
,
11048 bool deprocedure_p
,
11049 bool parse_completion
,
11050 innermost_block_tracker
*tracker
,
11051 struct type
*context_type
)
11053 symbol
*sym
= std::get
<0> (m_storage
);
11054 if (SYMBOL_DOMAIN (sym
) == UNDEF_DOMAIN
)
11056 block_symbol resolved
11057 = ada_resolve_variable (sym
, std::get
<1> (m_storage
),
11058 context_type
, parse_completion
,
11059 deprocedure_p
, tracker
);
11060 std::get
<0> (m_storage
) = resolved
.symbol
;
11061 std::get
<1> (m_storage
) = resolved
.block
;
11065 && SYMBOL_TYPE (std::get
<0> (m_storage
))->code () == TYPE_CODE_FUNC
)
11072 ada_atr_val_operation::evaluate (struct type
*expect_type
,
11073 struct expression
*exp
,
11074 enum noside noside
)
11076 value
*arg
= std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
11077 return ada_val_atr (noside
, std::get
<0> (m_storage
), arg
);
11081 ada_unop_ind_operation::evaluate (struct type
*expect_type
,
11082 struct expression
*exp
,
11083 enum noside noside
)
11085 value
*arg1
= std::get
<0> (m_storage
)->evaluate (expect_type
, exp
, noside
);
11087 struct type
*type
= ada_check_typedef (value_type (arg1
));
11088 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
11090 if (ada_is_array_descriptor_type (type
))
11091 /* GDB allows dereferencing GNAT array descriptors. */
11093 struct type
*arrType
= ada_type_of_array (arg1
, 0);
11095 if (arrType
== NULL
)
11096 error (_("Attempt to dereference null array pointer."));
11097 return value_at_lazy (arrType
, 0);
11099 else if (type
->code () == TYPE_CODE_PTR
11100 || type
->code () == TYPE_CODE_REF
11101 /* In C you can dereference an array to get the 1st elt. */
11102 || type
->code () == TYPE_CODE_ARRAY
)
11104 /* As mentioned in the OP_VAR_VALUE case, tagged types can
11105 only be determined by inspecting the object's tag.
11106 This means that we need to evaluate completely the
11107 expression in order to get its type. */
11109 if ((type
->code () == TYPE_CODE_REF
11110 || type
->code () == TYPE_CODE_PTR
)
11111 && ada_is_tagged_type (TYPE_TARGET_TYPE (type
), 0))
11113 arg1
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
11115 type
= value_type (ada_value_ind (arg1
));
11119 type
= to_static_fixed_type
11121 (ada_check_typedef (TYPE_TARGET_TYPE (type
))));
11123 ada_ensure_varsize_limit (type
);
11124 return value_zero (type
, lval_memory
);
11126 else if (type
->code () == TYPE_CODE_INT
)
11128 /* GDB allows dereferencing an int. */
11129 if (expect_type
== NULL
)
11130 return value_zero (builtin_type (exp
->gdbarch
)->builtin_int
,
11135 to_static_fixed_type (ada_aligned_type (expect_type
));
11136 return value_zero (expect_type
, lval_memory
);
11140 error (_("Attempt to take contents of a non-pointer value."));
11142 arg1
= ada_coerce_ref (arg1
); /* FIXME: What is this for?? */
11143 type
= ada_check_typedef (value_type (arg1
));
11145 if (type
->code () == TYPE_CODE_INT
)
11146 /* GDB allows dereferencing an int. If we were given
11147 the expect_type, then use that as the target type.
11148 Otherwise, assume that the target type is an int. */
11150 if (expect_type
!= NULL
)
11151 return ada_value_ind (value_cast (lookup_pointer_type (expect_type
),
11154 return value_at_lazy (builtin_type (exp
->gdbarch
)->builtin_int
,
11155 (CORE_ADDR
) value_as_address (arg1
));
11158 if (ada_is_array_descriptor_type (type
))
11159 /* GDB allows dereferencing GNAT array descriptors. */
11160 return ada_coerce_to_simple_array (arg1
);
11162 return ada_value_ind (arg1
);
11166 ada_structop_operation::evaluate (struct type
*expect_type
,
11167 struct expression
*exp
,
11168 enum noside noside
)
11170 value
*arg1
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
11171 const char *str
= std::get
<1> (m_storage
).c_str ();
11172 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
11175 struct type
*type1
= value_type (arg1
);
11177 if (ada_is_tagged_type (type1
, 1))
11179 type
= ada_lookup_struct_elt_type (type1
, str
, 1, 1);
11181 /* If the field is not found, check if it exists in the
11182 extension of this object's type. This means that we
11183 need to evaluate completely the expression. */
11187 arg1
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
11189 arg1
= ada_value_struct_elt (arg1
, str
, 0);
11190 arg1
= unwrap_value (arg1
);
11191 type
= value_type (ada_to_fixed_value (arg1
));
11195 type
= ada_lookup_struct_elt_type (type1
, str
, 1, 0);
11197 return value_zero (ada_aligned_type (type
), lval_memory
);
11201 arg1
= ada_value_struct_elt (arg1
, str
, 0);
11202 arg1
= unwrap_value (arg1
);
11203 return ada_to_fixed_value (arg1
);
11208 ada_funcall_operation::evaluate (struct type
*expect_type
,
11209 struct expression
*exp
,
11210 enum noside noside
)
11212 const std::vector
<operation_up
> &args_up
= std::get
<1> (m_storage
);
11213 int nargs
= args_up
.size ();
11214 std::vector
<value
*> argvec (nargs
);
11215 operation_up
&callee_op
= std::get
<0> (m_storage
);
11217 ada_var_value_operation
*avv
11218 = dynamic_cast<ada_var_value_operation
*> (callee_op
.get ());
11220 && SYMBOL_DOMAIN (avv
->get_symbol ()) == UNDEF_DOMAIN
)
11221 error (_("Unexpected unresolved symbol, %s, during evaluation"),
11222 avv
->get_symbol ()->print_name ());
11224 value
*callee
= callee_op
->evaluate (nullptr, exp
, noside
);
11225 for (int i
= 0; i
< args_up
.size (); ++i
)
11226 argvec
[i
] = args_up
[i
]->evaluate (nullptr, exp
, noside
);
11228 if (ada_is_constrained_packed_array_type
11229 (desc_base_type (value_type (callee
))))
11230 callee
= ada_coerce_to_simple_array (callee
);
11231 else if (value_type (callee
)->code () == TYPE_CODE_ARRAY
11232 && TYPE_FIELD_BITSIZE (value_type (callee
), 0) != 0)
11233 /* This is a packed array that has already been fixed, and
11234 therefore already coerced to a simple array. Nothing further
11237 else if (value_type (callee
)->code () == TYPE_CODE_REF
)
11239 /* Make sure we dereference references so that all the code below
11240 feels like it's really handling the referenced value. Wrapping
11241 types (for alignment) may be there, so make sure we strip them as
11243 callee
= ada_to_fixed_value (coerce_ref (callee
));
11245 else if (value_type (callee
)->code () == TYPE_CODE_ARRAY
11246 && VALUE_LVAL (callee
) == lval_memory
)
11247 callee
= value_addr (callee
);
11249 struct type
*type
= ada_check_typedef (value_type (callee
));
11251 /* Ada allows us to implicitly dereference arrays when subscripting
11252 them. So, if this is an array typedef (encoding use for array
11253 access types encoded as fat pointers), strip it now. */
11254 if (type
->code () == TYPE_CODE_TYPEDEF
)
11255 type
= ada_typedef_target_type (type
);
11257 if (type
->code () == TYPE_CODE_PTR
)
11259 switch (ada_check_typedef (TYPE_TARGET_TYPE (type
))->code ())
11261 case TYPE_CODE_FUNC
:
11262 type
= ada_check_typedef (TYPE_TARGET_TYPE (type
));
11264 case TYPE_CODE_ARRAY
:
11266 case TYPE_CODE_STRUCT
:
11267 if (noside
!= EVAL_AVOID_SIDE_EFFECTS
)
11268 callee
= ada_value_ind (callee
);
11269 type
= ada_check_typedef (TYPE_TARGET_TYPE (type
));
11272 error (_("cannot subscript or call something of type `%s'"),
11273 ada_type_name (value_type (callee
)));
11278 switch (type
->code ())
11280 case TYPE_CODE_FUNC
:
11281 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
11283 if (TYPE_TARGET_TYPE (type
) == NULL
)
11284 error_call_unknown_return_type (NULL
);
11285 return allocate_value (TYPE_TARGET_TYPE (type
));
11287 return call_function_by_hand (callee
, NULL
, argvec
);
11288 case TYPE_CODE_INTERNAL_FUNCTION
:
11289 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
11290 /* We don't know anything about what the internal
11291 function might return, but we have to return
11293 return value_zero (builtin_type (exp
->gdbarch
)->builtin_int
,
11296 return call_internal_function (exp
->gdbarch
, exp
->language_defn
,
11300 case TYPE_CODE_STRUCT
:
11304 arity
= ada_array_arity (type
);
11305 type
= ada_array_element_type (type
, nargs
);
11307 error (_("cannot subscript or call a record"));
11308 if (arity
!= nargs
)
11309 error (_("wrong number of subscripts; expecting %d"), arity
);
11310 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
11311 return value_zero (ada_aligned_type (type
), lval_memory
);
11313 unwrap_value (ada_value_subscript
11314 (callee
, nargs
, argvec
.data ()));
11316 case TYPE_CODE_ARRAY
:
11317 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
11319 type
= ada_array_element_type (type
, nargs
);
11321 error (_("element type of array unknown"));
11323 return value_zero (ada_aligned_type (type
), lval_memory
);
11326 unwrap_value (ada_value_subscript
11327 (ada_coerce_to_simple_array (callee
),
11328 nargs
, argvec
.data ()));
11329 case TYPE_CODE_PTR
: /* Pointer to array */
11330 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
11332 type
= to_fixed_array_type (TYPE_TARGET_TYPE (type
), NULL
, 1);
11333 type
= ada_array_element_type (type
, nargs
);
11335 error (_("element type of array unknown"));
11337 return value_zero (ada_aligned_type (type
), lval_memory
);
11340 unwrap_value (ada_value_ptr_subscript (callee
, nargs
,
11344 error (_("Attempt to index or call something other than an "
11345 "array or function"));
11350 ada_funcall_operation::resolve (struct expression
*exp
,
11351 bool deprocedure_p
,
11352 bool parse_completion
,
11353 innermost_block_tracker
*tracker
,
11354 struct type
*context_type
)
11356 operation_up
&callee_op
= std::get
<0> (m_storage
);
11358 ada_var_value_operation
*avv
11359 = dynamic_cast<ada_var_value_operation
*> (callee_op
.get ());
11360 if (avv
== nullptr)
11363 symbol
*sym
= avv
->get_symbol ();
11364 if (SYMBOL_DOMAIN (sym
) != UNDEF_DOMAIN
)
11367 const std::vector
<operation_up
> &args_up
= std::get
<1> (m_storage
);
11368 int nargs
= args_up
.size ();
11369 std::vector
<value
*> argvec (nargs
);
11371 for (int i
= 0; i
< args_up
.size (); ++i
)
11372 argvec
[i
] = args_up
[i
]->evaluate (nullptr, exp
, EVAL_AVOID_SIDE_EFFECTS
);
11374 const block
*block
= avv
->get_block ();
11375 block_symbol resolved
11376 = ada_resolve_funcall (sym
, block
,
11377 context_type
, parse_completion
,
11378 nargs
, argvec
.data (),
11381 std::get
<0> (m_storage
)
11382 = make_operation
<ada_var_value_operation
> (resolved
.symbol
,
11388 ada_ternop_slice_operation::resolve (struct expression
*exp
,
11389 bool deprocedure_p
,
11390 bool parse_completion
,
11391 innermost_block_tracker
*tracker
,
11392 struct type
*context_type
)
11394 /* Historically this check was done during resolution, so we
11395 continue that here. */
11396 value
*v
= std::get
<0> (m_storage
)->evaluate (context_type
, exp
,
11397 EVAL_AVOID_SIDE_EFFECTS
);
11398 if (ada_is_any_packed_array_type (value_type (v
)))
11399 error (_("cannot slice a packed array"));
11405 /* Implement the evaluate_exp routine in the exp_descriptor structure
11406 for the Ada language. */
11408 static struct value
*
11409 ada_evaluate_subexp (struct type
*expect_type
, struct expression
*exp
,
11410 int *pos
, enum noside noside
)
11412 enum exp_opcode op
;
11416 struct value
*arg1
= NULL
, *arg2
= NULL
, *arg3
;
11419 struct value
**argvec
;
11423 op
= exp
->elts
[pc
].opcode
;
11429 arg1
= evaluate_subexp_standard (expect_type
, exp
, pos
, noside
);
11431 if (noside
== EVAL_NORMAL
)
11432 arg1
= unwrap_value (arg1
);
11434 /* If evaluating an OP_FLOAT and an EXPECT_TYPE was provided,
11435 then we need to perform the conversion manually, because
11436 evaluate_subexp_standard doesn't do it. This conversion is
11437 necessary in Ada because the different kinds of float/fixed
11438 types in Ada have different representations.
11440 Similarly, we need to perform the conversion from OP_LONG
11442 if ((op
== OP_FLOAT
|| op
== OP_LONG
) && expect_type
!= NULL
)
11443 arg1
= ada_value_cast (expect_type
, arg1
);
11449 struct value
*result
;
11452 result
= evaluate_subexp_standard (expect_type
, exp
, pos
, noside
);
11453 /* The result type will have code OP_STRING, bashed there from
11454 OP_ARRAY. Bash it back. */
11455 if (value_type (result
)->code () == TYPE_CODE_STRING
)
11456 value_type (result
)->set_code (TYPE_CODE_ARRAY
);
11462 type
= exp
->elts
[pc
+ 1].type
;
11463 return ada_evaluate_subexp_for_cast (exp
, pos
, noside
, type
);
11467 type
= exp
->elts
[pc
+ 1].type
;
11468 return ada_evaluate_subexp (type
, exp
, pos
, noside
);
11471 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
11472 if (exp
->elts
[*pos
].opcode
== OP_AGGREGATE
)
11474 arg1
= assign_aggregate (arg1
, arg1
, exp
, pos
, noside
);
11475 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
11477 return ada_value_assign (arg1
, arg1
);
11479 /* Force the evaluation of the rhs ARG2 to the type of the lhs ARG1,
11480 except if the lhs of our assignment is a convenience variable.
11481 In the case of assigning to a convenience variable, the lhs
11482 should be exactly the result of the evaluation of the rhs. */
11483 type
= value_type (arg1
);
11484 if (VALUE_LVAL (arg1
) == lval_internalvar
)
11486 arg2
= evaluate_subexp (type
, exp
, pos
, noside
);
11487 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
11489 if (VALUE_LVAL (arg1
) == lval_internalvar
)
11494 arg2
= coerce_for_assign (value_type (arg1
), arg2
);
11495 return ada_value_assign (arg1
, arg2
);
11498 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
11499 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
11500 if (noside
== EVAL_SKIP
)
11502 if (value_type (arg1
)->code () == TYPE_CODE_PTR
)
11503 return (value_from_longest
11504 (value_type (arg1
),
11505 value_as_long (arg1
) + value_as_long (arg2
)));
11506 if (value_type (arg2
)->code () == TYPE_CODE_PTR
)
11507 return (value_from_longest
11508 (value_type (arg2
),
11509 value_as_long (arg1
) + value_as_long (arg2
)));
11510 /* Preserve the original type for use by the range case below.
11511 We cannot cast the result to a reference type, so if ARG1 is
11512 a reference type, find its underlying type. */
11513 type
= value_type (arg1
);
11514 while (type
->code () == TYPE_CODE_REF
)
11515 type
= TYPE_TARGET_TYPE (type
);
11516 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
11517 arg1
= value_binop (arg1
, arg2
, BINOP_ADD
);
11518 /* We need to special-case the result of adding to a range.
11519 This is done for the benefit of "ptype". gdb's Ada support
11520 historically used the LHS to set the result type here, so
11521 preserve this behavior. */
11522 if (type
->code () == TYPE_CODE_RANGE
)
11523 arg1
= value_cast (type
, arg1
);
11527 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
11528 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
11529 if (noside
== EVAL_SKIP
)
11531 if (value_type (arg1
)->code () == TYPE_CODE_PTR
)
11532 return (value_from_longest
11533 (value_type (arg1
),
11534 value_as_long (arg1
) - value_as_long (arg2
)));
11535 if (value_type (arg2
)->code () == TYPE_CODE_PTR
)
11536 return (value_from_longest
11537 (value_type (arg2
),
11538 value_as_long (arg1
) - value_as_long (arg2
)));
11539 /* Preserve the original type for use by the range case below.
11540 We cannot cast the result to a reference type, so if ARG1 is
11541 a reference type, find its underlying type. */
11542 type
= value_type (arg1
);
11543 while (type
->code () == TYPE_CODE_REF
)
11544 type
= TYPE_TARGET_TYPE (type
);
11545 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
11546 arg1
= value_binop (arg1
, arg2
, BINOP_SUB
);
11547 /* We need to special-case the result of adding to a range.
11548 This is done for the benefit of "ptype". gdb's Ada support
11549 historically used the LHS to set the result type here, so
11550 preserve this behavior. */
11551 if (type
->code () == TYPE_CODE_RANGE
)
11552 arg1
= value_cast (type
, arg1
);
11559 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
11560 arg2
= evaluate_subexp (nullptr, exp
, pos
, noside
);
11561 if (noside
== EVAL_SKIP
)
11563 return ada_mult_binop (expect_type
, exp
, noside
, op
,
11567 case BINOP_NOTEQUAL
:
11568 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
11569 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
11570 if (noside
== EVAL_SKIP
)
11572 return ada_equal_binop (expect_type
, exp
, noside
, op
, arg1
, arg2
);
11575 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
11576 return ada_unop_neg (expect_type
, exp
, noside
, op
, arg1
);
11578 case BINOP_LOGICAL_AND
:
11579 case BINOP_LOGICAL_OR
:
11580 case UNOP_LOGICAL_NOT
:
11585 val
= evaluate_subexp_standard (expect_type
, exp
, pos
, noside
);
11586 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
11587 return value_cast (type
, val
);
11590 case BINOP_BITWISE_AND
:
11591 case BINOP_BITWISE_IOR
:
11592 case BINOP_BITWISE_XOR
:
11596 arg1
= evaluate_subexp (nullptr, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
11598 val
= evaluate_subexp_standard (expect_type
, exp
, pos
, noside
);
11600 return value_cast (value_type (arg1
), val
);
11606 if (noside
== EVAL_SKIP
)
11612 if (SYMBOL_DOMAIN (exp
->elts
[pc
+ 2].symbol
) == UNDEF_DOMAIN
)
11613 /* Only encountered when an unresolved symbol occurs in a
11614 context other than a function call, in which case, it is
11616 error (_("Unexpected unresolved symbol, %s, during evaluation"),
11617 exp
->elts
[pc
+ 2].symbol
->print_name ());
11619 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
11621 type
= static_unwrap_type (SYMBOL_TYPE (exp
->elts
[pc
+ 2].symbol
));
11622 /* Check to see if this is a tagged type. We also need to handle
11623 the case where the type is a reference to a tagged type, but
11624 we have to be careful to exclude pointers to tagged types.
11625 The latter should be shown as usual (as a pointer), whereas
11626 a reference should mostly be transparent to the user. */
11627 if (ada_is_tagged_type (type
, 0)
11628 || (type
->code () == TYPE_CODE_REF
11629 && ada_is_tagged_type (TYPE_TARGET_TYPE (type
), 0)))
11631 /* Tagged types are a little special in the fact that the real
11632 type is dynamic and can only be determined by inspecting the
11633 object's tag. This means that we need to get the object's
11634 value first (EVAL_NORMAL) and then extract the actual object
11637 Note that we cannot skip the final step where we extract
11638 the object type from its tag, because the EVAL_NORMAL phase
11639 results in dynamic components being resolved into fixed ones.
11640 This can cause problems when trying to print the type
11641 description of tagged types whose parent has a dynamic size:
11642 We use the type name of the "_parent" component in order
11643 to print the name of the ancestor type in the type description.
11644 If that component had a dynamic size, the resolution into
11645 a fixed type would result in the loss of that type name,
11646 thus preventing us from printing the name of the ancestor
11647 type in the type description. */
11648 arg1
= evaluate_subexp (nullptr, exp
, pos
, EVAL_NORMAL
);
11650 if (type
->code () != TYPE_CODE_REF
)
11652 struct type
*actual_type
;
11654 actual_type
= type_from_tag (ada_value_tag (arg1
));
11655 if (actual_type
== NULL
)
11656 /* If, for some reason, we were unable to determine
11657 the actual type from the tag, then use the static
11658 approximation that we just computed as a fallback.
11659 This can happen if the debugging information is
11660 incomplete, for instance. */
11661 actual_type
= type
;
11662 return value_zero (actual_type
, not_lval
);
11666 /* In the case of a ref, ada_coerce_ref takes care
11667 of determining the actual type. But the evaluation
11668 should return a ref as it should be valid to ask
11669 for its address; so rebuild a ref after coerce. */
11670 arg1
= ada_coerce_ref (arg1
);
11671 return value_ref (arg1
, TYPE_CODE_REF
);
11675 /* Records and unions for which GNAT encodings have been
11676 generated need to be statically fixed as well.
11677 Otherwise, non-static fixing produces a type where
11678 all dynamic properties are removed, which prevents "ptype"
11679 from being able to completely describe the type.
11680 For instance, a case statement in a variant record would be
11681 replaced by the relevant components based on the actual
11682 value of the discriminants. */
11683 if ((type
->code () == TYPE_CODE_STRUCT
11684 && dynamic_template_type (type
) != NULL
)
11685 || (type
->code () == TYPE_CODE_UNION
11686 && ada_find_parallel_type (type
, "___XVU") != NULL
))
11689 return value_zero (to_static_fixed_type (type
), not_lval
);
11693 arg1
= evaluate_subexp_standard (expect_type
, exp
, pos
, noside
);
11694 return ada_to_fixed_value (arg1
);
11699 /* Allocate arg vector, including space for the function to be
11700 called in argvec[0] and a terminating NULL. */
11701 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
11702 argvec
= XALLOCAVEC (struct value
*, nargs
+ 2);
11704 if (exp
->elts
[*pos
].opcode
== OP_VAR_VALUE
11705 && SYMBOL_DOMAIN (exp
->elts
[pc
+ 5].symbol
) == UNDEF_DOMAIN
)
11706 error (_("Unexpected unresolved symbol, %s, during evaluation"),
11707 exp
->elts
[pc
+ 5].symbol
->print_name ());
11710 for (tem
= 0; tem
<= nargs
; tem
+= 1)
11711 argvec
[tem
] = evaluate_subexp (nullptr, exp
, pos
, noside
);
11714 if (noside
== EVAL_SKIP
)
11718 if (ada_is_constrained_packed_array_type
11719 (desc_base_type (value_type (argvec
[0]))))
11720 argvec
[0] = ada_coerce_to_simple_array (argvec
[0]);
11721 else if (value_type (argvec
[0])->code () == TYPE_CODE_ARRAY
11722 && TYPE_FIELD_BITSIZE (value_type (argvec
[0]), 0) != 0)
11723 /* This is a packed array that has already been fixed, and
11724 therefore already coerced to a simple array. Nothing further
11727 else if (value_type (argvec
[0])->code () == TYPE_CODE_REF
)
11729 /* Make sure we dereference references so that all the code below
11730 feels like it's really handling the referenced value. Wrapping
11731 types (for alignment) may be there, so make sure we strip them as
11733 argvec
[0] = ada_to_fixed_value (coerce_ref (argvec
[0]));
11735 else if (value_type (argvec
[0])->code () == TYPE_CODE_ARRAY
11736 && VALUE_LVAL (argvec
[0]) == lval_memory
)
11737 argvec
[0] = value_addr (argvec
[0]);
11739 type
= ada_check_typedef (value_type (argvec
[0]));
11741 /* Ada allows us to implicitly dereference arrays when subscripting
11742 them. So, if this is an array typedef (encoding use for array
11743 access types encoded as fat pointers), strip it now. */
11744 if (type
->code () == TYPE_CODE_TYPEDEF
)
11745 type
= ada_typedef_target_type (type
);
11747 if (type
->code () == TYPE_CODE_PTR
)
11749 switch (ada_check_typedef (TYPE_TARGET_TYPE (type
))->code ())
11751 case TYPE_CODE_FUNC
:
11752 type
= ada_check_typedef (TYPE_TARGET_TYPE (type
));
11754 case TYPE_CODE_ARRAY
:
11756 case TYPE_CODE_STRUCT
:
11757 if (noside
!= EVAL_AVOID_SIDE_EFFECTS
)
11758 argvec
[0] = ada_value_ind (argvec
[0]);
11759 type
= ada_check_typedef (TYPE_TARGET_TYPE (type
));
11762 error (_("cannot subscript or call something of type `%s'"),
11763 ada_type_name (value_type (argvec
[0])));
11768 switch (type
->code ())
11770 case TYPE_CODE_FUNC
:
11771 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
11773 if (TYPE_TARGET_TYPE (type
) == NULL
)
11774 error_call_unknown_return_type (NULL
);
11775 return allocate_value (TYPE_TARGET_TYPE (type
));
11777 return call_function_by_hand (argvec
[0], NULL
,
11778 gdb::make_array_view (argvec
+ 1,
11780 case TYPE_CODE_INTERNAL_FUNCTION
:
11781 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
11782 /* We don't know anything about what the internal
11783 function might return, but we have to return
11785 return value_zero (builtin_type (exp
->gdbarch
)->builtin_int
,
11788 return call_internal_function (exp
->gdbarch
, exp
->language_defn
,
11789 argvec
[0], nargs
, argvec
+ 1);
11791 case TYPE_CODE_STRUCT
:
11795 arity
= ada_array_arity (type
);
11796 type
= ada_array_element_type (type
, nargs
);
11798 error (_("cannot subscript or call a record"));
11799 if (arity
!= nargs
)
11800 error (_("wrong number of subscripts; expecting %d"), arity
);
11801 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
11802 return value_zero (ada_aligned_type (type
), lval_memory
);
11804 unwrap_value (ada_value_subscript
11805 (argvec
[0], nargs
, argvec
+ 1));
11807 case TYPE_CODE_ARRAY
:
11808 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
11810 type
= ada_array_element_type (type
, nargs
);
11812 error (_("element type of array unknown"));
11814 return value_zero (ada_aligned_type (type
), lval_memory
);
11817 unwrap_value (ada_value_subscript
11818 (ada_coerce_to_simple_array (argvec
[0]),
11819 nargs
, argvec
+ 1));
11820 case TYPE_CODE_PTR
: /* Pointer to array */
11821 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
11823 type
= to_fixed_array_type (TYPE_TARGET_TYPE (type
), NULL
, 1);
11824 type
= ada_array_element_type (type
, nargs
);
11826 error (_("element type of array unknown"));
11828 return value_zero (ada_aligned_type (type
), lval_memory
);
11831 unwrap_value (ada_value_ptr_subscript (argvec
[0],
11832 nargs
, argvec
+ 1));
11835 error (_("Attempt to index or call something other than an "
11836 "array or function"));
11841 struct value
*array
= evaluate_subexp (nullptr, exp
, pos
, noside
);
11842 struct value
*low_bound_val
11843 = evaluate_subexp (nullptr, exp
, pos
, noside
);
11844 struct value
*high_bound_val
11845 = evaluate_subexp (nullptr, exp
, pos
, noside
);
11847 if (noside
== EVAL_SKIP
)
11850 return ada_ternop_slice (exp
, noside
, array
, low_bound_val
,
11854 case UNOP_IN_RANGE
:
11856 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
11857 type
= check_typedef (exp
->elts
[pc
+ 1].type
);
11858 return ada_unop_in_range (expect_type
, exp
, noside
, op
, arg1
, type
);
11860 case BINOP_IN_BOUNDS
:
11862 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
11863 arg2
= evaluate_subexp (nullptr, exp
, pos
, noside
);
11865 if (noside
== EVAL_SKIP
)
11868 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
11870 return ada_binop_in_bounds (exp
, noside
, arg1
, arg2
, tem
);
11872 case TERNOP_IN_RANGE
:
11873 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
11874 arg2
= evaluate_subexp (nullptr, exp
, pos
, noside
);
11875 arg3
= evaluate_subexp (nullptr, exp
, pos
, noside
);
11877 return eval_ternop_in_range (expect_type
, exp
, noside
, arg1
, arg2
, arg3
);
11881 case OP_ATR_LENGTH
:
11883 struct type
*type_arg
;
11885 if (exp
->elts
[*pos
].opcode
== OP_TYPE
)
11887 evaluate_subexp (nullptr, exp
, pos
, EVAL_SKIP
);
11889 type_arg
= check_typedef (exp
->elts
[pc
+ 2].type
);
11893 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
11897 if (exp
->elts
[*pos
].opcode
!= OP_LONG
)
11898 error (_("Invalid operand to '%s"), ada_attribute_name (op
));
11899 tem
= longest_to_int (exp
->elts
[*pos
+ 2].longconst
);
11902 if (noside
== EVAL_SKIP
)
11905 return ada_unop_atr (exp
, noside
, op
, arg1
, type_arg
, tem
);
11909 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
11910 if (noside
== EVAL_SKIP
)
11912 return ada_atr_tag (expect_type
, exp
, noside
, op
, arg1
);
11916 evaluate_subexp (nullptr, exp
, pos
, EVAL_SKIP
);
11917 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
11918 arg2
= evaluate_subexp (nullptr, exp
, pos
, noside
);
11919 if (noside
== EVAL_SKIP
)
11921 return ada_binop_minmax (expect_type
, exp
, noside
, op
, arg1
, arg2
);
11923 case OP_ATR_MODULUS
:
11925 struct type
*type_arg
= check_typedef (exp
->elts
[pc
+ 2].type
);
11927 evaluate_subexp (nullptr, exp
, pos
, EVAL_SKIP
);
11928 if (noside
== EVAL_SKIP
)
11931 if (!ada_is_modular_type (type_arg
))
11932 error (_("'modulus must be applied to modular type"));
11934 return value_from_longest (TYPE_TARGET_TYPE (type_arg
),
11935 ada_modulus (type_arg
));
11940 evaluate_subexp (nullptr, exp
, pos
, EVAL_SKIP
);
11941 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
11942 if (noside
== EVAL_SKIP
)
11944 return ada_pos_atr (expect_type
, exp
, noside
, op
, arg1
);
11947 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
11948 return ada_atr_size (expect_type
, exp
, noside
, op
, arg1
);
11951 evaluate_subexp (nullptr, exp
, pos
, EVAL_SKIP
);
11952 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
11953 type
= exp
->elts
[pc
+ 2].type
;
11954 if (noside
== EVAL_SKIP
)
11956 return ada_val_atr (noside
, type
, arg1
);
11959 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
11960 arg2
= evaluate_subexp (nullptr, exp
, pos
, noside
);
11961 if (noside
== EVAL_SKIP
)
11963 return ada_binop_exp (expect_type
, exp
, noside
, op
, arg1
, arg2
);
11966 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
11967 if (noside
== EVAL_SKIP
)
11973 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
11974 if (noside
== EVAL_SKIP
)
11976 return ada_abs (expect_type
, exp
, noside
, op
, arg1
);
11979 preeval_pos
= *pos
;
11980 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
11981 if (noside
== EVAL_SKIP
)
11983 type
= ada_check_typedef (value_type (arg1
));
11984 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
11986 if (ada_is_array_descriptor_type (type
))
11987 /* GDB allows dereferencing GNAT array descriptors. */
11989 struct type
*arrType
= ada_type_of_array (arg1
, 0);
11991 if (arrType
== NULL
)
11992 error (_("Attempt to dereference null array pointer."));
11993 return value_at_lazy (arrType
, 0);
11995 else if (type
->code () == TYPE_CODE_PTR
11996 || type
->code () == TYPE_CODE_REF
11997 /* In C you can dereference an array to get the 1st elt. */
11998 || type
->code () == TYPE_CODE_ARRAY
)
12000 /* As mentioned in the OP_VAR_VALUE case, tagged types can
12001 only be determined by inspecting the object's tag.
12002 This means that we need to evaluate completely the
12003 expression in order to get its type. */
12005 if ((type
->code () == TYPE_CODE_REF
12006 || type
->code () == TYPE_CODE_PTR
)
12007 && ada_is_tagged_type (TYPE_TARGET_TYPE (type
), 0))
12010 = evaluate_subexp (nullptr, exp
, &preeval_pos
, EVAL_NORMAL
);
12011 type
= value_type (ada_value_ind (arg1
));
12015 type
= to_static_fixed_type
12017 (ada_check_typedef (TYPE_TARGET_TYPE (type
))));
12019 ada_ensure_varsize_limit (type
);
12020 return value_zero (type
, lval_memory
);
12022 else if (type
->code () == TYPE_CODE_INT
)
12024 /* GDB allows dereferencing an int. */
12025 if (expect_type
== NULL
)
12026 return value_zero (builtin_type (exp
->gdbarch
)->builtin_int
,
12031 to_static_fixed_type (ada_aligned_type (expect_type
));
12032 return value_zero (expect_type
, lval_memory
);
12036 error (_("Attempt to take contents of a non-pointer value."));
12038 arg1
= ada_coerce_ref (arg1
); /* FIXME: What is this for?? */
12039 type
= ada_check_typedef (value_type (arg1
));
12041 if (type
->code () == TYPE_CODE_INT
)
12042 /* GDB allows dereferencing an int. If we were given
12043 the expect_type, then use that as the target type.
12044 Otherwise, assume that the target type is an int. */
12046 if (expect_type
!= NULL
)
12047 return ada_value_ind (value_cast (lookup_pointer_type (expect_type
),
12050 return value_at_lazy (builtin_type (exp
->gdbarch
)->builtin_int
,
12051 (CORE_ADDR
) value_as_address (arg1
));
12054 if (ada_is_array_descriptor_type (type
))
12055 /* GDB allows dereferencing GNAT array descriptors. */
12056 return ada_coerce_to_simple_array (arg1
);
12058 return ada_value_ind (arg1
);
12060 case STRUCTOP_STRUCT
:
12061 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
12062 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
12063 preeval_pos
= *pos
;
12064 arg1
= evaluate_subexp (nullptr, exp
, pos
, noside
);
12065 if (noside
== EVAL_SKIP
)
12067 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
12069 struct type
*type1
= value_type (arg1
);
12071 if (ada_is_tagged_type (type1
, 1))
12073 type
= ada_lookup_struct_elt_type (type1
,
12074 &exp
->elts
[pc
+ 2].string
,
12077 /* If the field is not found, check if it exists in the
12078 extension of this object's type. This means that we
12079 need to evaluate completely the expression. */
12084 = evaluate_subexp (nullptr, exp
, &preeval_pos
, EVAL_NORMAL
);
12085 arg1
= ada_value_struct_elt (arg1
,
12086 &exp
->elts
[pc
+ 2].string
,
12088 arg1
= unwrap_value (arg1
);
12089 type
= value_type (ada_to_fixed_value (arg1
));
12094 ada_lookup_struct_elt_type (type1
, &exp
->elts
[pc
+ 2].string
, 1,
12097 return value_zero (ada_aligned_type (type
), lval_memory
);
12101 arg1
= ada_value_struct_elt (arg1
, &exp
->elts
[pc
+ 2].string
, 0);
12102 arg1
= unwrap_value (arg1
);
12103 return ada_to_fixed_value (arg1
);
12107 /* The value is not supposed to be used. This is here to make it
12108 easier to accommodate expressions that contain types. */
12110 if (noside
== EVAL_SKIP
)
12112 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
12113 return allocate_value (exp
->elts
[pc
+ 1].type
);
12115 error (_("Attempt to use a type name as an expression"));
12120 case OP_DISCRETE_RANGE
:
12121 case OP_POSITIONAL
:
12123 if (noside
== EVAL_NORMAL
)
12127 error (_("Undefined name, ambiguous name, or renaming used in "
12128 "component association: %s."), &exp
->elts
[pc
+2].string
);
12130 error (_("Aggregates only allowed on the right of an assignment"));
12132 internal_error (__FILE__
, __LINE__
,
12133 _("aggregate apparently mangled"));
12136 ada_forward_operator_length (exp
, pc
, &oplen
, &nargs
);
12138 for (tem
= 0; tem
< nargs
; tem
+= 1)
12139 ada_evaluate_subexp (NULL
, exp
, pos
, noside
);
12144 return eval_skip_value (exp
);
12148 /* Return non-zero iff TYPE represents a System.Address type. */
12151 ada_is_system_address_type (struct type
*type
)
12153 return (type
->name () && strcmp (type
->name (), "system__address") == 0);
12160 /* Scan STR beginning at position K for a discriminant name, and
12161 return the value of that discriminant field of DVAL in *PX. If
12162 PNEW_K is not null, put the position of the character beyond the
12163 name scanned in *PNEW_K. Return 1 if successful; return 0 and do
12164 not alter *PX and *PNEW_K if unsuccessful. */
12167 scan_discrim_bound (const char *str
, int k
, struct value
*dval
, LONGEST
* px
,
12170 static std::string storage
;
12171 const char *pstart
, *pend
, *bound
;
12172 struct value
*bound_val
;
12174 if (dval
== NULL
|| str
== NULL
|| str
[k
] == '\0')
12178 pend
= strstr (pstart
, "__");
12182 k
+= strlen (bound
);
12186 int len
= pend
- pstart
;
12188 /* Strip __ and beyond. */
12189 storage
= std::string (pstart
, len
);
12190 bound
= storage
.c_str ();
12194 bound_val
= ada_search_struct_field (bound
, dval
, 0, value_type (dval
));
12195 if (bound_val
== NULL
)
12198 *px
= value_as_long (bound_val
);
12199 if (pnew_k
!= NULL
)
12204 /* Value of variable named NAME. Only exact matches are considered.
12205 If no such variable found, then if ERR_MSG is null, returns 0, and
12206 otherwise causes an error with message ERR_MSG. */
12208 static struct value
*
12209 get_var_value (const char *name
, const char *err_msg
)
12211 std::string quoted_name
= add_angle_brackets (name
);
12213 lookup_name_info
lookup_name (quoted_name
, symbol_name_match_type::FULL
);
12215 std::vector
<struct block_symbol
> syms
12216 = ada_lookup_symbol_list_worker (lookup_name
,
12217 get_selected_block (0),
12220 if (syms
.size () != 1)
12222 if (err_msg
== NULL
)
12225 error (("%s"), err_msg
);
12228 return value_of_variable (syms
[0].symbol
, syms
[0].block
);
12231 /* Value of integer variable named NAME in the current environment.
12232 If no such variable is found, returns false. Otherwise, sets VALUE
12233 to the variable's value and returns true. */
12236 get_int_var_value (const char *name
, LONGEST
&value
)
12238 struct value
*var_val
= get_var_value (name
, 0);
12243 value
= value_as_long (var_val
);
12248 /* Return a range type whose base type is that of the range type named
12249 NAME in the current environment, and whose bounds are calculated
12250 from NAME according to the GNAT range encoding conventions.
12251 Extract discriminant values, if needed, from DVAL. ORIG_TYPE is the
12252 corresponding range type from debug information; fall back to using it
12253 if symbol lookup fails. If a new type must be created, allocate it
12254 like ORIG_TYPE was. The bounds information, in general, is encoded
12255 in NAME, the base type given in the named range type. */
12257 static struct type
*
12258 to_fixed_range_type (struct type
*raw_type
, struct value
*dval
)
12261 struct type
*base_type
;
12262 const char *subtype_info
;
12264 gdb_assert (raw_type
!= NULL
);
12265 gdb_assert (raw_type
->name () != NULL
);
12267 if (raw_type
->code () == TYPE_CODE_RANGE
)
12268 base_type
= TYPE_TARGET_TYPE (raw_type
);
12270 base_type
= raw_type
;
12272 name
= raw_type
->name ();
12273 subtype_info
= strstr (name
, "___XD");
12274 if (subtype_info
== NULL
)
12276 LONGEST L
= ada_discrete_type_low_bound (raw_type
);
12277 LONGEST U
= ada_discrete_type_high_bound (raw_type
);
12279 if (L
< INT_MIN
|| U
> INT_MAX
)
12282 return create_static_range_type (alloc_type_copy (raw_type
), raw_type
,
12287 int prefix_len
= subtype_info
- name
;
12290 const char *bounds_str
;
12294 bounds_str
= strchr (subtype_info
, '_');
12297 if (*subtype_info
== 'L')
12299 if (!ada_scan_number (bounds_str
, n
, &L
, &n
)
12300 && !scan_discrim_bound (bounds_str
, n
, dval
, &L
, &n
))
12302 if (bounds_str
[n
] == '_')
12304 else if (bounds_str
[n
] == '.') /* FIXME? SGI Workshop kludge. */
12310 std::string name_buf
= std::string (name
, prefix_len
) + "___L";
12311 if (!get_int_var_value (name_buf
.c_str (), L
))
12313 lim_warning (_("Unknown lower bound, using 1."));
12318 if (*subtype_info
== 'U')
12320 if (!ada_scan_number (bounds_str
, n
, &U
, &n
)
12321 && !scan_discrim_bound (bounds_str
, n
, dval
, &U
, &n
))
12326 std::string name_buf
= std::string (name
, prefix_len
) + "___U";
12327 if (!get_int_var_value (name_buf
.c_str (), U
))
12329 lim_warning (_("Unknown upper bound, using %ld."), (long) L
);
12334 type
= create_static_range_type (alloc_type_copy (raw_type
),
12336 /* create_static_range_type alters the resulting type's length
12337 to match the size of the base_type, which is not what we want.
12338 Set it back to the original range type's length. */
12339 TYPE_LENGTH (type
) = TYPE_LENGTH (raw_type
);
12340 type
->set_name (name
);
12345 /* True iff NAME is the name of a range type. */
12348 ada_is_range_type_name (const char *name
)
12350 return (name
!= NULL
&& strstr (name
, "___XD"));
12354 /* Modular types */
12356 /* True iff TYPE is an Ada modular type. */
12359 ada_is_modular_type (struct type
*type
)
12361 struct type
*subranged_type
= get_base_type (type
);
12363 return (subranged_type
!= NULL
&& type
->code () == TYPE_CODE_RANGE
12364 && subranged_type
->code () == TYPE_CODE_INT
12365 && subranged_type
->is_unsigned ());
12368 /* Assuming ada_is_modular_type (TYPE), the modulus of TYPE. */
12371 ada_modulus (struct type
*type
)
12373 const dynamic_prop
&high
= type
->bounds ()->high
;
12375 if (high
.kind () == PROP_CONST
)
12376 return (ULONGEST
) high
.const_val () + 1;
12378 /* If TYPE is unresolved, the high bound might be a location list. Return
12379 0, for lack of a better value to return. */
12384 /* Ada exception catchpoint support:
12385 ---------------------------------
12387 We support 3 kinds of exception catchpoints:
12388 . catchpoints on Ada exceptions
12389 . catchpoints on unhandled Ada exceptions
12390 . catchpoints on failed assertions
12392 Exceptions raised during failed assertions, or unhandled exceptions
12393 could perfectly be caught with the general catchpoint on Ada exceptions.
12394 However, we can easily differentiate these two special cases, and having
12395 the option to distinguish these two cases from the rest can be useful
12396 to zero-in on certain situations.
12398 Exception catchpoints are a specialized form of breakpoint,
12399 since they rely on inserting breakpoints inside known routines
12400 of the GNAT runtime. The implementation therefore uses a standard
12401 breakpoint structure of the BP_BREAKPOINT type, but with its own set
12404 Support in the runtime for exception catchpoints have been changed
12405 a few times already, and these changes affect the implementation
12406 of these catchpoints. In order to be able to support several
12407 variants of the runtime, we use a sniffer that will determine
12408 the runtime variant used by the program being debugged. */
12410 /* Ada's standard exceptions.
12412 The Ada 83 standard also defined Numeric_Error. But there so many
12413 situations where it was unclear from the Ada 83 Reference Manual
12414 (RM) whether Constraint_Error or Numeric_Error should be raised,
12415 that the ARG (Ada Rapporteur Group) eventually issued a Binding
12416 Interpretation saying that anytime the RM says that Numeric_Error
12417 should be raised, the implementation may raise Constraint_Error.
12418 Ada 95 went one step further and pretty much removed Numeric_Error
12419 from the list of standard exceptions (it made it a renaming of
12420 Constraint_Error, to help preserve compatibility when compiling
12421 an Ada83 compiler). As such, we do not include Numeric_Error from
12422 this list of standard exceptions. */
12424 static const char * const standard_exc
[] = {
12425 "constraint_error",
12431 typedef CORE_ADDR (ada_unhandled_exception_name_addr_ftype
) (void);
12433 /* A structure that describes how to support exception catchpoints
12434 for a given executable. */
12436 struct exception_support_info
12438 /* The name of the symbol to break on in order to insert
12439 a catchpoint on exceptions. */
12440 const char *catch_exception_sym
;
12442 /* The name of the symbol to break on in order to insert
12443 a catchpoint on unhandled exceptions. */
12444 const char *catch_exception_unhandled_sym
;
12446 /* The name of the symbol to break on in order to insert
12447 a catchpoint on failed assertions. */
12448 const char *catch_assert_sym
;
12450 /* The name of the symbol to break on in order to insert
12451 a catchpoint on exception handling. */
12452 const char *catch_handlers_sym
;
12454 /* Assuming that the inferior just triggered an unhandled exception
12455 catchpoint, this function is responsible for returning the address
12456 in inferior memory where the name of that exception is stored.
12457 Return zero if the address could not be computed. */
12458 ada_unhandled_exception_name_addr_ftype
*unhandled_exception_name_addr
;
12461 static CORE_ADDR
ada_unhandled_exception_name_addr (void);
12462 static CORE_ADDR
ada_unhandled_exception_name_addr_from_raise (void);
12464 /* The following exception support info structure describes how to
12465 implement exception catchpoints with the latest version of the
12466 Ada runtime (as of 2019-08-??). */
12468 static const struct exception_support_info default_exception_support_info
=
12470 "__gnat_debug_raise_exception", /* catch_exception_sym */
12471 "__gnat_unhandled_exception", /* catch_exception_unhandled_sym */
12472 "__gnat_debug_raise_assert_failure", /* catch_assert_sym */
12473 "__gnat_begin_handler_v1", /* catch_handlers_sym */
12474 ada_unhandled_exception_name_addr
12477 /* The following exception support info structure describes how to
12478 implement exception catchpoints with an earlier version of the
12479 Ada runtime (as of 2007-03-06) using v0 of the EH ABI. */
12481 static const struct exception_support_info exception_support_info_v0
=
12483 "__gnat_debug_raise_exception", /* catch_exception_sym */
12484 "__gnat_unhandled_exception", /* catch_exception_unhandled_sym */
12485 "__gnat_debug_raise_assert_failure", /* catch_assert_sym */
12486 "__gnat_begin_handler", /* catch_handlers_sym */
12487 ada_unhandled_exception_name_addr
12490 /* The following exception support info structure describes how to
12491 implement exception catchpoints with a slightly older version
12492 of the Ada runtime. */
12494 static const struct exception_support_info exception_support_info_fallback
=
12496 "__gnat_raise_nodefer_with_msg", /* catch_exception_sym */
12497 "__gnat_unhandled_exception", /* catch_exception_unhandled_sym */
12498 "system__assertions__raise_assert_failure", /* catch_assert_sym */
12499 "__gnat_begin_handler", /* catch_handlers_sym */
12500 ada_unhandled_exception_name_addr_from_raise
12503 /* Return nonzero if we can detect the exception support routines
12504 described in EINFO.
12506 This function errors out if an abnormal situation is detected
12507 (for instance, if we find the exception support routines, but
12508 that support is found to be incomplete). */
12511 ada_has_this_exception_support (const struct exception_support_info
*einfo
)
12513 struct symbol
*sym
;
12515 /* The symbol we're looking up is provided by a unit in the GNAT runtime
12516 that should be compiled with debugging information. As a result, we
12517 expect to find that symbol in the symtabs. */
12519 sym
= standard_lookup (einfo
->catch_exception_sym
, NULL
, VAR_DOMAIN
);
12522 /* Perhaps we did not find our symbol because the Ada runtime was
12523 compiled without debugging info, or simply stripped of it.
12524 It happens on some GNU/Linux distributions for instance, where
12525 users have to install a separate debug package in order to get
12526 the runtime's debugging info. In that situation, let the user
12527 know why we cannot insert an Ada exception catchpoint.
12529 Note: Just for the purpose of inserting our Ada exception
12530 catchpoint, we could rely purely on the associated minimal symbol.
12531 But we would be operating in degraded mode anyway, since we are
12532 still lacking the debugging info needed later on to extract
12533 the name of the exception being raised (this name is printed in
12534 the catchpoint message, and is also used when trying to catch
12535 a specific exception). We do not handle this case for now. */
12536 struct bound_minimal_symbol msym
12537 = lookup_minimal_symbol (einfo
->catch_exception_sym
, NULL
, NULL
);
12539 if (msym
.minsym
&& MSYMBOL_TYPE (msym
.minsym
) != mst_solib_trampoline
)
12540 error (_("Your Ada runtime appears to be missing some debugging "
12541 "information.\nCannot insert Ada exception catchpoint "
12542 "in this configuration."));
12547 /* Make sure that the symbol we found corresponds to a function. */
12549 if (SYMBOL_CLASS (sym
) != LOC_BLOCK
)
12551 error (_("Symbol \"%s\" is not a function (class = %d)"),
12552 sym
->linkage_name (), SYMBOL_CLASS (sym
));
12556 sym
= standard_lookup (einfo
->catch_handlers_sym
, NULL
, VAR_DOMAIN
);
12559 struct bound_minimal_symbol msym
12560 = lookup_minimal_symbol (einfo
->catch_handlers_sym
, NULL
, NULL
);
12562 if (msym
.minsym
&& MSYMBOL_TYPE (msym
.minsym
) != mst_solib_trampoline
)
12563 error (_("Your Ada runtime appears to be missing some debugging "
12564 "information.\nCannot insert Ada exception catchpoint "
12565 "in this configuration."));
12570 /* Make sure that the symbol we found corresponds to a function. */
12572 if (SYMBOL_CLASS (sym
) != LOC_BLOCK
)
12574 error (_("Symbol \"%s\" is not a function (class = %d)"),
12575 sym
->linkage_name (), SYMBOL_CLASS (sym
));
12582 /* Inspect the Ada runtime and determine which exception info structure
12583 should be used to provide support for exception catchpoints.
12585 This function will always set the per-inferior exception_info,
12586 or raise an error. */
12589 ada_exception_support_info_sniffer (void)
12591 struct ada_inferior_data
*data
= get_ada_inferior_data (current_inferior ());
12593 /* If the exception info is already known, then no need to recompute it. */
12594 if (data
->exception_info
!= NULL
)
12597 /* Check the latest (default) exception support info. */
12598 if (ada_has_this_exception_support (&default_exception_support_info
))
12600 data
->exception_info
= &default_exception_support_info
;
12604 /* Try the v0 exception suport info. */
12605 if (ada_has_this_exception_support (&exception_support_info_v0
))
12607 data
->exception_info
= &exception_support_info_v0
;
12611 /* Try our fallback exception suport info. */
12612 if (ada_has_this_exception_support (&exception_support_info_fallback
))
12614 data
->exception_info
= &exception_support_info_fallback
;
12618 /* Sometimes, it is normal for us to not be able to find the routine
12619 we are looking for. This happens when the program is linked with
12620 the shared version of the GNAT runtime, and the program has not been
12621 started yet. Inform the user of these two possible causes if
12624 if (ada_update_initial_language (language_unknown
) != language_ada
)
12625 error (_("Unable to insert catchpoint. Is this an Ada main program?"));
12627 /* If the symbol does not exist, then check that the program is
12628 already started, to make sure that shared libraries have been
12629 loaded. If it is not started, this may mean that the symbol is
12630 in a shared library. */
12632 if (inferior_ptid
.pid () == 0)
12633 error (_("Unable to insert catchpoint. Try to start the program first."));
12635 /* At this point, we know that we are debugging an Ada program and
12636 that the inferior has been started, but we still are not able to
12637 find the run-time symbols. That can mean that we are in
12638 configurable run time mode, or that a-except as been optimized
12639 out by the linker... In any case, at this point it is not worth
12640 supporting this feature. */
12642 error (_("Cannot insert Ada exception catchpoints in this configuration."));
12645 /* True iff FRAME is very likely to be that of a function that is
12646 part of the runtime system. This is all very heuristic, but is
12647 intended to be used as advice as to what frames are uninteresting
12651 is_known_support_routine (struct frame_info
*frame
)
12653 enum language func_lang
;
12655 const char *fullname
;
12657 /* If this code does not have any debugging information (no symtab),
12658 This cannot be any user code. */
12660 symtab_and_line sal
= find_frame_sal (frame
);
12661 if (sal
.symtab
== NULL
)
12664 /* If there is a symtab, but the associated source file cannot be
12665 located, then assume this is not user code: Selecting a frame
12666 for which we cannot display the code would not be very helpful
12667 for the user. This should also take care of case such as VxWorks
12668 where the kernel has some debugging info provided for a few units. */
12670 fullname
= symtab_to_fullname (sal
.symtab
);
12671 if (access (fullname
, R_OK
) != 0)
12674 /* Check the unit filename against the Ada runtime file naming.
12675 We also check the name of the objfile against the name of some
12676 known system libraries that sometimes come with debugging info
12679 for (i
= 0; known_runtime_file_name_patterns
[i
] != NULL
; i
+= 1)
12681 re_comp (known_runtime_file_name_patterns
[i
]);
12682 if (re_exec (lbasename (sal
.symtab
->filename
)))
12684 if (SYMTAB_OBJFILE (sal
.symtab
) != NULL
12685 && re_exec (objfile_name (SYMTAB_OBJFILE (sal
.symtab
))))
12689 /* Check whether the function is a GNAT-generated entity. */
12691 gdb::unique_xmalloc_ptr
<char> func_name
12692 = find_frame_funname (frame
, &func_lang
, NULL
);
12693 if (func_name
== NULL
)
12696 for (i
= 0; known_auxiliary_function_name_patterns
[i
] != NULL
; i
+= 1)
12698 re_comp (known_auxiliary_function_name_patterns
[i
]);
12699 if (re_exec (func_name
.get ()))
12706 /* Find the first frame that contains debugging information and that is not
12707 part of the Ada run-time, starting from FI and moving upward. */
12710 ada_find_printable_frame (struct frame_info
*fi
)
12712 for (; fi
!= NULL
; fi
= get_prev_frame (fi
))
12714 if (!is_known_support_routine (fi
))
12723 /* Assuming that the inferior just triggered an unhandled exception
12724 catchpoint, return the address in inferior memory where the name
12725 of the exception is stored.
12727 Return zero if the address could not be computed. */
12730 ada_unhandled_exception_name_addr (void)
12732 return parse_and_eval_address ("e.full_name");
12735 /* Same as ada_unhandled_exception_name_addr, except that this function
12736 should be used when the inferior uses an older version of the runtime,
12737 where the exception name needs to be extracted from a specific frame
12738 several frames up in the callstack. */
12741 ada_unhandled_exception_name_addr_from_raise (void)
12744 struct frame_info
*fi
;
12745 struct ada_inferior_data
*data
= get_ada_inferior_data (current_inferior ());
12747 /* To determine the name of this exception, we need to select
12748 the frame corresponding to RAISE_SYM_NAME. This frame is
12749 at least 3 levels up, so we simply skip the first 3 frames
12750 without checking the name of their associated function. */
12751 fi
= get_current_frame ();
12752 for (frame_level
= 0; frame_level
< 3; frame_level
+= 1)
12754 fi
= get_prev_frame (fi
);
12758 enum language func_lang
;
12760 gdb::unique_xmalloc_ptr
<char> func_name
12761 = find_frame_funname (fi
, &func_lang
, NULL
);
12762 if (func_name
!= NULL
)
12764 if (strcmp (func_name
.get (),
12765 data
->exception_info
->catch_exception_sym
) == 0)
12766 break; /* We found the frame we were looking for... */
12768 fi
= get_prev_frame (fi
);
12775 return parse_and_eval_address ("id.full_name");
12778 /* Assuming the inferior just triggered an Ada exception catchpoint
12779 (of any type), return the address in inferior memory where the name
12780 of the exception is stored, if applicable.
12782 Assumes the selected frame is the current frame.
12784 Return zero if the address could not be computed, or if not relevant. */
12787 ada_exception_name_addr_1 (enum ada_exception_catchpoint_kind ex
,
12788 struct breakpoint
*b
)
12790 struct ada_inferior_data
*data
= get_ada_inferior_data (current_inferior ());
12794 case ada_catch_exception
:
12795 return (parse_and_eval_address ("e.full_name"));
12798 case ada_catch_exception_unhandled
:
12799 return data
->exception_info
->unhandled_exception_name_addr ();
12802 case ada_catch_handlers
:
12803 return 0; /* The runtimes does not provide access to the exception
12807 case ada_catch_assert
:
12808 return 0; /* Exception name is not relevant in this case. */
12812 internal_error (__FILE__
, __LINE__
, _("unexpected catchpoint type"));
12816 return 0; /* Should never be reached. */
12819 /* Assuming the inferior is stopped at an exception catchpoint,
12820 return the message which was associated to the exception, if
12821 available. Return NULL if the message could not be retrieved.
12823 Note: The exception message can be associated to an exception
12824 either through the use of the Raise_Exception function, or
12825 more simply (Ada 2005 and later), via:
12827 raise Exception_Name with "exception message";
12831 static gdb::unique_xmalloc_ptr
<char>
12832 ada_exception_message_1 (void)
12834 struct value
*e_msg_val
;
12837 /* For runtimes that support this feature, the exception message
12838 is passed as an unbounded string argument called "message". */
12839 e_msg_val
= parse_and_eval ("message");
12840 if (e_msg_val
== NULL
)
12841 return NULL
; /* Exception message not supported. */
12843 e_msg_val
= ada_coerce_to_simple_array (e_msg_val
);
12844 gdb_assert (e_msg_val
!= NULL
);
12845 e_msg_len
= TYPE_LENGTH (value_type (e_msg_val
));
12847 /* If the message string is empty, then treat it as if there was
12848 no exception message. */
12849 if (e_msg_len
<= 0)
12852 gdb::unique_xmalloc_ptr
<char> e_msg ((char *) xmalloc (e_msg_len
+ 1));
12853 read_memory (value_address (e_msg_val
), (gdb_byte
*) e_msg
.get (),
12855 e_msg
.get ()[e_msg_len
] = '\0';
12860 /* Same as ada_exception_message_1, except that all exceptions are
12861 contained here (returning NULL instead). */
12863 static gdb::unique_xmalloc_ptr
<char>
12864 ada_exception_message (void)
12866 gdb::unique_xmalloc_ptr
<char> e_msg
;
12870 e_msg
= ada_exception_message_1 ();
12872 catch (const gdb_exception_error
&e
)
12874 e_msg
.reset (nullptr);
12880 /* Same as ada_exception_name_addr_1, except that it intercepts and contains
12881 any error that ada_exception_name_addr_1 might cause to be thrown.
12882 When an error is intercepted, a warning with the error message is printed,
12883 and zero is returned. */
12886 ada_exception_name_addr (enum ada_exception_catchpoint_kind ex
,
12887 struct breakpoint
*b
)
12889 CORE_ADDR result
= 0;
12893 result
= ada_exception_name_addr_1 (ex
, b
);
12896 catch (const gdb_exception_error
&e
)
12898 warning (_("failed to get exception name: %s"), e
.what ());
12905 static std::string ada_exception_catchpoint_cond_string
12906 (const char *excep_string
,
12907 enum ada_exception_catchpoint_kind ex
);
12909 /* Ada catchpoints.
12911 In the case of catchpoints on Ada exceptions, the catchpoint will
12912 stop the target on every exception the program throws. When a user
12913 specifies the name of a specific exception, we translate this
12914 request into a condition expression (in text form), and then parse
12915 it into an expression stored in each of the catchpoint's locations.
12916 We then use this condition to check whether the exception that was
12917 raised is the one the user is interested in. If not, then the
12918 target is resumed again. We store the name of the requested
12919 exception, in order to be able to re-set the condition expression
12920 when symbols change. */
12922 /* An instance of this type is used to represent an Ada catchpoint
12923 breakpoint location. */
12925 class ada_catchpoint_location
: public bp_location
12928 ada_catchpoint_location (breakpoint
*owner
)
12929 : bp_location (owner
, bp_loc_software_breakpoint
)
12932 /* The condition that checks whether the exception that was raised
12933 is the specific exception the user specified on catchpoint
12935 expression_up excep_cond_expr
;
12938 /* An instance of this type is used to represent an Ada catchpoint. */
12940 struct ada_catchpoint
: public breakpoint
12942 explicit ada_catchpoint (enum ada_exception_catchpoint_kind kind
)
12947 /* The name of the specific exception the user specified. */
12948 std::string excep_string
;
12950 /* What kind of catchpoint this is. */
12951 enum ada_exception_catchpoint_kind m_kind
;
12954 /* Parse the exception condition string in the context of each of the
12955 catchpoint's locations, and store them for later evaluation. */
12958 create_excep_cond_exprs (struct ada_catchpoint
*c
,
12959 enum ada_exception_catchpoint_kind ex
)
12961 struct bp_location
*bl
;
12963 /* Nothing to do if there's no specific exception to catch. */
12964 if (c
->excep_string
.empty ())
12967 /* Same if there are no locations... */
12968 if (c
->loc
== NULL
)
12971 /* Compute the condition expression in text form, from the specific
12972 expection we want to catch. */
12973 std::string cond_string
12974 = ada_exception_catchpoint_cond_string (c
->excep_string
.c_str (), ex
);
12976 /* Iterate over all the catchpoint's locations, and parse an
12977 expression for each. */
12978 for (bl
= c
->loc
; bl
!= NULL
; bl
= bl
->next
)
12980 struct ada_catchpoint_location
*ada_loc
12981 = (struct ada_catchpoint_location
*) bl
;
12984 if (!bl
->shlib_disabled
)
12988 s
= cond_string
.c_str ();
12991 exp
= parse_exp_1 (&s
, bl
->address
,
12992 block_for_pc (bl
->address
),
12995 catch (const gdb_exception_error
&e
)
12997 warning (_("failed to reevaluate internal exception condition "
12998 "for catchpoint %d: %s"),
12999 c
->number
, e
.what ());
13003 ada_loc
->excep_cond_expr
= std::move (exp
);
13007 /* Implement the ALLOCATE_LOCATION method in the breakpoint_ops
13008 structure for all exception catchpoint kinds. */
13010 static struct bp_location
*
13011 allocate_location_exception (struct breakpoint
*self
)
13013 return new ada_catchpoint_location (self
);
13016 /* Implement the RE_SET method in the breakpoint_ops structure for all
13017 exception catchpoint kinds. */
13020 re_set_exception (struct breakpoint
*b
)
13022 struct ada_catchpoint
*c
= (struct ada_catchpoint
*) b
;
13024 /* Call the base class's method. This updates the catchpoint's
13026 bkpt_breakpoint_ops
.re_set (b
);
13028 /* Reparse the exception conditional expressions. One for each
13030 create_excep_cond_exprs (c
, c
->m_kind
);
13033 /* Returns true if we should stop for this breakpoint hit. If the
13034 user specified a specific exception, we only want to cause a stop
13035 if the program thrown that exception. */
13038 should_stop_exception (const struct bp_location
*bl
)
13040 struct ada_catchpoint
*c
= (struct ada_catchpoint
*) bl
->owner
;
13041 const struct ada_catchpoint_location
*ada_loc
13042 = (const struct ada_catchpoint_location
*) bl
;
13045 struct internalvar
*var
= lookup_internalvar ("_ada_exception");
13046 if (c
->m_kind
== ada_catch_assert
)
13047 clear_internalvar (var
);
13054 if (c
->m_kind
== ada_catch_handlers
)
13055 expr
= ("GNAT_GCC_exception_Access(gcc_exception)"
13056 ".all.occurrence.id");
13060 struct value
*exc
= parse_and_eval (expr
);
13061 set_internalvar (var
, exc
);
13063 catch (const gdb_exception_error
&ex
)
13065 clear_internalvar (var
);
13069 /* With no specific exception, should always stop. */
13070 if (c
->excep_string
.empty ())
13073 if (ada_loc
->excep_cond_expr
== NULL
)
13075 /* We will have a NULL expression if back when we were creating
13076 the expressions, this location's had failed to parse. */
13083 struct value
*mark
;
13085 mark
= value_mark ();
13086 stop
= value_true (evaluate_expression (ada_loc
->excep_cond_expr
.get ()));
13087 value_free_to_mark (mark
);
13089 catch (const gdb_exception
&ex
)
13091 exception_fprintf (gdb_stderr
, ex
,
13092 _("Error in testing exception condition:\n"));
13098 /* Implement the CHECK_STATUS method in the breakpoint_ops structure
13099 for all exception catchpoint kinds. */
13102 check_status_exception (bpstat bs
)
13104 bs
->stop
= should_stop_exception (bs
->bp_location_at
.get ());
13107 /* Implement the PRINT_IT method in the breakpoint_ops structure
13108 for all exception catchpoint kinds. */
13110 static enum print_stop_action
13111 print_it_exception (bpstat bs
)
13113 struct ui_out
*uiout
= current_uiout
;
13114 struct breakpoint
*b
= bs
->breakpoint_at
;
13116 annotate_catchpoint (b
->number
);
13118 if (uiout
->is_mi_like_p ())
13120 uiout
->field_string ("reason",
13121 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
13122 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
13125 uiout
->text (b
->disposition
== disp_del
13126 ? "\nTemporary catchpoint " : "\nCatchpoint ");
13127 uiout
->field_signed ("bkptno", b
->number
);
13128 uiout
->text (", ");
13130 /* ada_exception_name_addr relies on the selected frame being the
13131 current frame. Need to do this here because this function may be
13132 called more than once when printing a stop, and below, we'll
13133 select the first frame past the Ada run-time (see
13134 ada_find_printable_frame). */
13135 select_frame (get_current_frame ());
13137 struct ada_catchpoint
*c
= (struct ada_catchpoint
*) b
;
13140 case ada_catch_exception
:
13141 case ada_catch_exception_unhandled
:
13142 case ada_catch_handlers
:
13144 const CORE_ADDR addr
= ada_exception_name_addr (c
->m_kind
, b
);
13145 char exception_name
[256];
13149 read_memory (addr
, (gdb_byte
*) exception_name
,
13150 sizeof (exception_name
) - 1);
13151 exception_name
[sizeof (exception_name
) - 1] = '\0';
13155 /* For some reason, we were unable to read the exception
13156 name. This could happen if the Runtime was compiled
13157 without debugging info, for instance. In that case,
13158 just replace the exception name by the generic string
13159 "exception" - it will read as "an exception" in the
13160 notification we are about to print. */
13161 memcpy (exception_name
, "exception", sizeof ("exception"));
13163 /* In the case of unhandled exception breakpoints, we print
13164 the exception name as "unhandled EXCEPTION_NAME", to make
13165 it clearer to the user which kind of catchpoint just got
13166 hit. We used ui_out_text to make sure that this extra
13167 info does not pollute the exception name in the MI case. */
13168 if (c
->m_kind
== ada_catch_exception_unhandled
)
13169 uiout
->text ("unhandled ");
13170 uiout
->field_string ("exception-name", exception_name
);
13173 case ada_catch_assert
:
13174 /* In this case, the name of the exception is not really
13175 important. Just print "failed assertion" to make it clearer
13176 that his program just hit an assertion-failure catchpoint.
13177 We used ui_out_text because this info does not belong in
13179 uiout
->text ("failed assertion");
13183 gdb::unique_xmalloc_ptr
<char> exception_message
= ada_exception_message ();
13184 if (exception_message
!= NULL
)
13186 uiout
->text (" (");
13187 uiout
->field_string ("exception-message", exception_message
.get ());
13191 uiout
->text (" at ");
13192 ada_find_printable_frame (get_current_frame ());
13194 return PRINT_SRC_AND_LOC
;
13197 /* Implement the PRINT_ONE method in the breakpoint_ops structure
13198 for all exception catchpoint kinds. */
13201 print_one_exception (struct breakpoint
*b
, struct bp_location
**last_loc
)
13203 struct ui_out
*uiout
= current_uiout
;
13204 struct ada_catchpoint
*c
= (struct ada_catchpoint
*) b
;
13205 struct value_print_options opts
;
13207 get_user_print_options (&opts
);
13209 if (opts
.addressprint
)
13210 uiout
->field_skip ("addr");
13212 annotate_field (5);
13215 case ada_catch_exception
:
13216 if (!c
->excep_string
.empty ())
13218 std::string msg
= string_printf (_("`%s' Ada exception"),
13219 c
->excep_string
.c_str ());
13221 uiout
->field_string ("what", msg
);
13224 uiout
->field_string ("what", "all Ada exceptions");
13228 case ada_catch_exception_unhandled
:
13229 uiout
->field_string ("what", "unhandled Ada exceptions");
13232 case ada_catch_handlers
:
13233 if (!c
->excep_string
.empty ())
13235 uiout
->field_fmt ("what",
13236 _("`%s' Ada exception handlers"),
13237 c
->excep_string
.c_str ());
13240 uiout
->field_string ("what", "all Ada exceptions handlers");
13243 case ada_catch_assert
:
13244 uiout
->field_string ("what", "failed Ada assertions");
13248 internal_error (__FILE__
, __LINE__
, _("unexpected catchpoint type"));
13253 /* Implement the PRINT_MENTION method in the breakpoint_ops structure
13254 for all exception catchpoint kinds. */
13257 print_mention_exception (struct breakpoint
*b
)
13259 struct ada_catchpoint
*c
= (struct ada_catchpoint
*) b
;
13260 struct ui_out
*uiout
= current_uiout
;
13262 uiout
->text (b
->disposition
== disp_del
? _("Temporary catchpoint ")
13263 : _("Catchpoint "));
13264 uiout
->field_signed ("bkptno", b
->number
);
13265 uiout
->text (": ");
13269 case ada_catch_exception
:
13270 if (!c
->excep_string
.empty ())
13272 std::string info
= string_printf (_("`%s' Ada exception"),
13273 c
->excep_string
.c_str ());
13274 uiout
->text (info
.c_str ());
13277 uiout
->text (_("all Ada exceptions"));
13280 case ada_catch_exception_unhandled
:
13281 uiout
->text (_("unhandled Ada exceptions"));
13284 case ada_catch_handlers
:
13285 if (!c
->excep_string
.empty ())
13288 = string_printf (_("`%s' Ada exception handlers"),
13289 c
->excep_string
.c_str ());
13290 uiout
->text (info
.c_str ());
13293 uiout
->text (_("all Ada exceptions handlers"));
13296 case ada_catch_assert
:
13297 uiout
->text (_("failed Ada assertions"));
13301 internal_error (__FILE__
, __LINE__
, _("unexpected catchpoint type"));
13306 /* Implement the PRINT_RECREATE method in the breakpoint_ops structure
13307 for all exception catchpoint kinds. */
13310 print_recreate_exception (struct breakpoint
*b
, struct ui_file
*fp
)
13312 struct ada_catchpoint
*c
= (struct ada_catchpoint
*) b
;
13316 case ada_catch_exception
:
13317 fprintf_filtered (fp
, "catch exception");
13318 if (!c
->excep_string
.empty ())
13319 fprintf_filtered (fp
, " %s", c
->excep_string
.c_str ());
13322 case ada_catch_exception_unhandled
:
13323 fprintf_filtered (fp
, "catch exception unhandled");
13326 case ada_catch_handlers
:
13327 fprintf_filtered (fp
, "catch handlers");
13330 case ada_catch_assert
:
13331 fprintf_filtered (fp
, "catch assert");
13335 internal_error (__FILE__
, __LINE__
, _("unexpected catchpoint type"));
13337 print_recreate_thread (b
, fp
);
13340 /* Virtual tables for various breakpoint types. */
13341 static struct breakpoint_ops catch_exception_breakpoint_ops
;
13342 static struct breakpoint_ops catch_exception_unhandled_breakpoint_ops
;
13343 static struct breakpoint_ops catch_assert_breakpoint_ops
;
13344 static struct breakpoint_ops catch_handlers_breakpoint_ops
;
13346 /* See ada-lang.h. */
13349 is_ada_exception_catchpoint (breakpoint
*bp
)
13351 return (bp
->ops
== &catch_exception_breakpoint_ops
13352 || bp
->ops
== &catch_exception_unhandled_breakpoint_ops
13353 || bp
->ops
== &catch_assert_breakpoint_ops
13354 || bp
->ops
== &catch_handlers_breakpoint_ops
);
13357 /* Split the arguments specified in a "catch exception" command.
13358 Set EX to the appropriate catchpoint type.
13359 Set EXCEP_STRING to the name of the specific exception if
13360 specified by the user.
13361 IS_CATCH_HANDLERS_CMD: True if the arguments are for a
13362 "catch handlers" command. False otherwise.
13363 If a condition is found at the end of the arguments, the condition
13364 expression is stored in COND_STRING (memory must be deallocated
13365 after use). Otherwise COND_STRING is set to NULL. */
13368 catch_ada_exception_command_split (const char *args
,
13369 bool is_catch_handlers_cmd
,
13370 enum ada_exception_catchpoint_kind
*ex
,
13371 std::string
*excep_string
,
13372 std::string
*cond_string
)
13374 std::string exception_name
;
13376 exception_name
= extract_arg (&args
);
13377 if (exception_name
== "if")
13379 /* This is not an exception name; this is the start of a condition
13380 expression for a catchpoint on all exceptions. So, "un-get"
13381 this token, and set exception_name to NULL. */
13382 exception_name
.clear ();
13386 /* Check to see if we have a condition. */
13388 args
= skip_spaces (args
);
13389 if (startswith (args
, "if")
13390 && (isspace (args
[2]) || args
[2] == '\0'))
13393 args
= skip_spaces (args
);
13395 if (args
[0] == '\0')
13396 error (_("Condition missing after `if' keyword"));
13397 *cond_string
= args
;
13399 args
+= strlen (args
);
13402 /* Check that we do not have any more arguments. Anything else
13405 if (args
[0] != '\0')
13406 error (_("Junk at end of expression"));
13408 if (is_catch_handlers_cmd
)
13410 /* Catch handling of exceptions. */
13411 *ex
= ada_catch_handlers
;
13412 *excep_string
= exception_name
;
13414 else if (exception_name
.empty ())
13416 /* Catch all exceptions. */
13417 *ex
= ada_catch_exception
;
13418 excep_string
->clear ();
13420 else if (exception_name
== "unhandled")
13422 /* Catch unhandled exceptions. */
13423 *ex
= ada_catch_exception_unhandled
;
13424 excep_string
->clear ();
13428 /* Catch a specific exception. */
13429 *ex
= ada_catch_exception
;
13430 *excep_string
= exception_name
;
13434 /* Return the name of the symbol on which we should break in order to
13435 implement a catchpoint of the EX kind. */
13437 static const char *
13438 ada_exception_sym_name (enum ada_exception_catchpoint_kind ex
)
13440 struct ada_inferior_data
*data
= get_ada_inferior_data (current_inferior ());
13442 gdb_assert (data
->exception_info
!= NULL
);
13446 case ada_catch_exception
:
13447 return (data
->exception_info
->catch_exception_sym
);
13449 case ada_catch_exception_unhandled
:
13450 return (data
->exception_info
->catch_exception_unhandled_sym
);
13452 case ada_catch_assert
:
13453 return (data
->exception_info
->catch_assert_sym
);
13455 case ada_catch_handlers
:
13456 return (data
->exception_info
->catch_handlers_sym
);
13459 internal_error (__FILE__
, __LINE__
,
13460 _("unexpected catchpoint kind (%d)"), ex
);
13464 /* Return the breakpoint ops "virtual table" used for catchpoints
13467 static const struct breakpoint_ops
*
13468 ada_exception_breakpoint_ops (enum ada_exception_catchpoint_kind ex
)
13472 case ada_catch_exception
:
13473 return (&catch_exception_breakpoint_ops
);
13475 case ada_catch_exception_unhandled
:
13476 return (&catch_exception_unhandled_breakpoint_ops
);
13478 case ada_catch_assert
:
13479 return (&catch_assert_breakpoint_ops
);
13481 case ada_catch_handlers
:
13482 return (&catch_handlers_breakpoint_ops
);
13485 internal_error (__FILE__
, __LINE__
,
13486 _("unexpected catchpoint kind (%d)"), ex
);
13490 /* Return the condition that will be used to match the current exception
13491 being raised with the exception that the user wants to catch. This
13492 assumes that this condition is used when the inferior just triggered
13493 an exception catchpoint.
13494 EX: the type of catchpoints used for catching Ada exceptions. */
13497 ada_exception_catchpoint_cond_string (const char *excep_string
,
13498 enum ada_exception_catchpoint_kind ex
)
13501 bool is_standard_exc
= false;
13502 std::string result
;
13504 if (ex
== ada_catch_handlers
)
13506 /* For exception handlers catchpoints, the condition string does
13507 not use the same parameter as for the other exceptions. */
13508 result
= ("long_integer (GNAT_GCC_exception_Access"
13509 "(gcc_exception).all.occurrence.id)");
13512 result
= "long_integer (e)";
13514 /* The standard exceptions are a special case. They are defined in
13515 runtime units that have been compiled without debugging info; if
13516 EXCEP_STRING is the not-fully-qualified name of a standard
13517 exception (e.g. "constraint_error") then, during the evaluation
13518 of the condition expression, the symbol lookup on this name would
13519 *not* return this standard exception. The catchpoint condition
13520 may then be set only on user-defined exceptions which have the
13521 same not-fully-qualified name (e.g. my_package.constraint_error).
13523 To avoid this unexcepted behavior, these standard exceptions are
13524 systematically prefixed by "standard". This means that "catch
13525 exception constraint_error" is rewritten into "catch exception
13526 standard.constraint_error".
13528 If an exception named constraint_error is defined in another package of
13529 the inferior program, then the only way to specify this exception as a
13530 breakpoint condition is to use its fully-qualified named:
13531 e.g. my_package.constraint_error. */
13533 for (i
= 0; i
< sizeof (standard_exc
) / sizeof (char *); i
++)
13535 if (strcmp (standard_exc
[i
], excep_string
) == 0)
13537 is_standard_exc
= true;
13544 if (is_standard_exc
)
13545 string_appendf (result
, "long_integer (&standard.%s)", excep_string
);
13547 string_appendf (result
, "long_integer (&%s)", excep_string
);
13552 /* Return the symtab_and_line that should be used to insert an exception
13553 catchpoint of the TYPE kind.
13555 ADDR_STRING returns the name of the function where the real
13556 breakpoint that implements the catchpoints is set, depending on the
13557 type of catchpoint we need to create. */
13559 static struct symtab_and_line
13560 ada_exception_sal (enum ada_exception_catchpoint_kind ex
,
13561 std::string
*addr_string
, const struct breakpoint_ops
**ops
)
13563 const char *sym_name
;
13564 struct symbol
*sym
;
13566 /* First, find out which exception support info to use. */
13567 ada_exception_support_info_sniffer ();
13569 /* Then lookup the function on which we will break in order to catch
13570 the Ada exceptions requested by the user. */
13571 sym_name
= ada_exception_sym_name (ex
);
13572 sym
= standard_lookup (sym_name
, NULL
, VAR_DOMAIN
);
13575 error (_("Catchpoint symbol not found: %s"), sym_name
);
13577 if (SYMBOL_CLASS (sym
) != LOC_BLOCK
)
13578 error (_("Unable to insert catchpoint. %s is not a function."), sym_name
);
13580 /* Set ADDR_STRING. */
13581 *addr_string
= sym_name
;
13584 *ops
= ada_exception_breakpoint_ops (ex
);
13586 return find_function_start_sal (sym
, 1);
13589 /* Create an Ada exception catchpoint.
13591 EX_KIND is the kind of exception catchpoint to be created.
13593 If EXCEPT_STRING is empty, this catchpoint is expected to trigger
13594 for all exceptions. Otherwise, EXCEPT_STRING indicates the name
13595 of the exception to which this catchpoint applies.
13597 COND_STRING, if not empty, is the catchpoint condition.
13599 TEMPFLAG, if nonzero, means that the underlying breakpoint
13600 should be temporary.
13602 FROM_TTY is the usual argument passed to all commands implementations. */
13605 create_ada_exception_catchpoint (struct gdbarch
*gdbarch
,
13606 enum ada_exception_catchpoint_kind ex_kind
,
13607 const std::string
&excep_string
,
13608 const std::string
&cond_string
,
13613 std::string addr_string
;
13614 const struct breakpoint_ops
*ops
= NULL
;
13615 struct symtab_and_line sal
= ada_exception_sal (ex_kind
, &addr_string
, &ops
);
13617 std::unique_ptr
<ada_catchpoint
> c (new ada_catchpoint (ex_kind
));
13618 init_ada_exception_breakpoint (c
.get (), gdbarch
, sal
, addr_string
.c_str (),
13619 ops
, tempflag
, disabled
, from_tty
);
13620 c
->excep_string
= excep_string
;
13621 create_excep_cond_exprs (c
.get (), ex_kind
);
13622 if (!cond_string
.empty ())
13623 set_breakpoint_condition (c
.get (), cond_string
.c_str (), from_tty
, false);
13624 install_breakpoint (0, std::move (c
), 1);
13627 /* Implement the "catch exception" command. */
13630 catch_ada_exception_command (const char *arg_entry
, int from_tty
,
13631 struct cmd_list_element
*command
)
13633 const char *arg
= arg_entry
;
13634 struct gdbarch
*gdbarch
= get_current_arch ();
13636 enum ada_exception_catchpoint_kind ex_kind
;
13637 std::string excep_string
;
13638 std::string cond_string
;
13640 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
13644 catch_ada_exception_command_split (arg
, false, &ex_kind
, &excep_string
,
13646 create_ada_exception_catchpoint (gdbarch
, ex_kind
,
13647 excep_string
, cond_string
,
13648 tempflag
, 1 /* enabled */,
13652 /* Implement the "catch handlers" command. */
13655 catch_ada_handlers_command (const char *arg_entry
, int from_tty
,
13656 struct cmd_list_element
*command
)
13658 const char *arg
= arg_entry
;
13659 struct gdbarch
*gdbarch
= get_current_arch ();
13661 enum ada_exception_catchpoint_kind ex_kind
;
13662 std::string excep_string
;
13663 std::string cond_string
;
13665 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
13669 catch_ada_exception_command_split (arg
, true, &ex_kind
, &excep_string
,
13671 create_ada_exception_catchpoint (gdbarch
, ex_kind
,
13672 excep_string
, cond_string
,
13673 tempflag
, 1 /* enabled */,
13677 /* Completion function for the Ada "catch" commands. */
13680 catch_ada_completer (struct cmd_list_element
*cmd
, completion_tracker
&tracker
,
13681 const char *text
, const char *word
)
13683 std::vector
<ada_exc_info
> exceptions
= ada_exceptions_list (NULL
);
13685 for (const ada_exc_info
&info
: exceptions
)
13687 if (startswith (info
.name
, word
))
13688 tracker
.add_completion (make_unique_xstrdup (info
.name
));
13692 /* Split the arguments specified in a "catch assert" command.
13694 ARGS contains the command's arguments (or the empty string if
13695 no arguments were passed).
13697 If ARGS contains a condition, set COND_STRING to that condition
13698 (the memory needs to be deallocated after use). */
13701 catch_ada_assert_command_split (const char *args
, std::string
&cond_string
)
13703 args
= skip_spaces (args
);
13705 /* Check whether a condition was provided. */
13706 if (startswith (args
, "if")
13707 && (isspace (args
[2]) || args
[2] == '\0'))
13710 args
= skip_spaces (args
);
13711 if (args
[0] == '\0')
13712 error (_("condition missing after `if' keyword"));
13713 cond_string
.assign (args
);
13716 /* Otherwise, there should be no other argument at the end of
13718 else if (args
[0] != '\0')
13719 error (_("Junk at end of arguments."));
13722 /* Implement the "catch assert" command. */
13725 catch_assert_command (const char *arg_entry
, int from_tty
,
13726 struct cmd_list_element
*command
)
13728 const char *arg
= arg_entry
;
13729 struct gdbarch
*gdbarch
= get_current_arch ();
13731 std::string cond_string
;
13733 tempflag
= get_cmd_context (command
) == CATCH_TEMPORARY
;
13737 catch_ada_assert_command_split (arg
, cond_string
);
13738 create_ada_exception_catchpoint (gdbarch
, ada_catch_assert
,
13740 tempflag
, 1 /* enabled */,
13744 /* Return non-zero if the symbol SYM is an Ada exception object. */
13747 ada_is_exception_sym (struct symbol
*sym
)
13749 const char *type_name
= SYMBOL_TYPE (sym
)->name ();
13751 return (SYMBOL_CLASS (sym
) != LOC_TYPEDEF
13752 && SYMBOL_CLASS (sym
) != LOC_BLOCK
13753 && SYMBOL_CLASS (sym
) != LOC_CONST
13754 && SYMBOL_CLASS (sym
) != LOC_UNRESOLVED
13755 && type_name
!= NULL
&& strcmp (type_name
, "exception") == 0);
13758 /* Given a global symbol SYM, return non-zero iff SYM is a non-standard
13759 Ada exception object. This matches all exceptions except the ones
13760 defined by the Ada language. */
13763 ada_is_non_standard_exception_sym (struct symbol
*sym
)
13767 if (!ada_is_exception_sym (sym
))
13770 for (i
= 0; i
< ARRAY_SIZE (standard_exc
); i
++)
13771 if (strcmp (sym
->linkage_name (), standard_exc
[i
]) == 0)
13772 return 0; /* A standard exception. */
13774 /* Numeric_Error is also a standard exception, so exclude it.
13775 See the STANDARD_EXC description for more details as to why
13776 this exception is not listed in that array. */
13777 if (strcmp (sym
->linkage_name (), "numeric_error") == 0)
13783 /* A helper function for std::sort, comparing two struct ada_exc_info
13786 The comparison is determined first by exception name, and then
13787 by exception address. */
13790 ada_exc_info::operator< (const ada_exc_info
&other
) const
13794 result
= strcmp (name
, other
.name
);
13797 if (result
== 0 && addr
< other
.addr
)
13803 ada_exc_info::operator== (const ada_exc_info
&other
) const
13805 return addr
== other
.addr
&& strcmp (name
, other
.name
) == 0;
13808 /* Sort EXCEPTIONS using compare_ada_exception_info as the comparison
13809 routine, but keeping the first SKIP elements untouched.
13811 All duplicates are also removed. */
13814 sort_remove_dups_ada_exceptions_list (std::vector
<ada_exc_info
> *exceptions
,
13817 std::sort (exceptions
->begin () + skip
, exceptions
->end ());
13818 exceptions
->erase (std::unique (exceptions
->begin () + skip
, exceptions
->end ()),
13819 exceptions
->end ());
13822 /* Add all exceptions defined by the Ada standard whose name match
13823 a regular expression.
13825 If PREG is not NULL, then this regexp_t object is used to
13826 perform the symbol name matching. Otherwise, no name-based
13827 filtering is performed.
13829 EXCEPTIONS is a vector of exceptions to which matching exceptions
13833 ada_add_standard_exceptions (compiled_regex
*preg
,
13834 std::vector
<ada_exc_info
> *exceptions
)
13838 for (i
= 0; i
< ARRAY_SIZE (standard_exc
); i
++)
13841 || preg
->exec (standard_exc
[i
], 0, NULL
, 0) == 0)
13843 struct bound_minimal_symbol msymbol
13844 = ada_lookup_simple_minsym (standard_exc
[i
]);
13846 if (msymbol
.minsym
!= NULL
)
13848 struct ada_exc_info info
13849 = {standard_exc
[i
], BMSYMBOL_VALUE_ADDRESS (msymbol
)};
13851 exceptions
->push_back (info
);
13857 /* Add all Ada exceptions defined locally and accessible from the given
13860 If PREG is not NULL, then this regexp_t object is used to
13861 perform the symbol name matching. Otherwise, no name-based
13862 filtering is performed.
13864 EXCEPTIONS is a vector of exceptions to which matching exceptions
13868 ada_add_exceptions_from_frame (compiled_regex
*preg
,
13869 struct frame_info
*frame
,
13870 std::vector
<ada_exc_info
> *exceptions
)
13872 const struct block
*block
= get_frame_block (frame
, 0);
13876 struct block_iterator iter
;
13877 struct symbol
*sym
;
13879 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
13881 switch (SYMBOL_CLASS (sym
))
13888 if (ada_is_exception_sym (sym
))
13890 struct ada_exc_info info
= {sym
->print_name (),
13891 SYMBOL_VALUE_ADDRESS (sym
)};
13893 exceptions
->push_back (info
);
13897 if (BLOCK_FUNCTION (block
) != NULL
)
13899 block
= BLOCK_SUPERBLOCK (block
);
13903 /* Return true if NAME matches PREG or if PREG is NULL. */
13906 name_matches_regex (const char *name
, compiled_regex
*preg
)
13908 return (preg
== NULL
13909 || preg
->exec (ada_decode (name
).c_str (), 0, NULL
, 0) == 0);
13912 /* Add all exceptions defined globally whose name name match
13913 a regular expression, excluding standard exceptions.
13915 The reason we exclude standard exceptions is that they need
13916 to be handled separately: Standard exceptions are defined inside
13917 a runtime unit which is normally not compiled with debugging info,
13918 and thus usually do not show up in our symbol search. However,
13919 if the unit was in fact built with debugging info, we need to
13920 exclude them because they would duplicate the entry we found
13921 during the special loop that specifically searches for those
13922 standard exceptions.
13924 If PREG is not NULL, then this regexp_t object is used to
13925 perform the symbol name matching. Otherwise, no name-based
13926 filtering is performed.
13928 EXCEPTIONS is a vector of exceptions to which matching exceptions
13932 ada_add_global_exceptions (compiled_regex
*preg
,
13933 std::vector
<ada_exc_info
> *exceptions
)
13935 /* In Ada, the symbol "search name" is a linkage name, whereas the
13936 regular expression used to do the matching refers to the natural
13937 name. So match against the decoded name. */
13938 expand_symtabs_matching (NULL
,
13939 lookup_name_info::match_any (),
13940 [&] (const char *search_name
)
13942 std::string decoded
= ada_decode (search_name
);
13943 return name_matches_regex (decoded
.c_str (), preg
);
13948 for (objfile
*objfile
: current_program_space
->objfiles ())
13950 for (compunit_symtab
*s
: objfile
->compunits ())
13952 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (s
);
13955 for (i
= GLOBAL_BLOCK
; i
<= STATIC_BLOCK
; i
++)
13957 const struct block
*b
= BLOCKVECTOR_BLOCK (bv
, i
);
13958 struct block_iterator iter
;
13959 struct symbol
*sym
;
13961 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
13962 if (ada_is_non_standard_exception_sym (sym
)
13963 && name_matches_regex (sym
->natural_name (), preg
))
13965 struct ada_exc_info info
13966 = {sym
->print_name (), SYMBOL_VALUE_ADDRESS (sym
)};
13968 exceptions
->push_back (info
);
13975 /* Implements ada_exceptions_list with the regular expression passed
13976 as a regex_t, rather than a string.
13978 If not NULL, PREG is used to filter out exceptions whose names
13979 do not match. Otherwise, all exceptions are listed. */
13981 static std::vector
<ada_exc_info
>
13982 ada_exceptions_list_1 (compiled_regex
*preg
)
13984 std::vector
<ada_exc_info
> result
;
13987 /* First, list the known standard exceptions. These exceptions
13988 need to be handled separately, as they are usually defined in
13989 runtime units that have been compiled without debugging info. */
13991 ada_add_standard_exceptions (preg
, &result
);
13993 /* Next, find all exceptions whose scope is local and accessible
13994 from the currently selected frame. */
13996 if (has_stack_frames ())
13998 prev_len
= result
.size ();
13999 ada_add_exceptions_from_frame (preg
, get_selected_frame (NULL
),
14001 if (result
.size () > prev_len
)
14002 sort_remove_dups_ada_exceptions_list (&result
, prev_len
);
14005 /* Add all exceptions whose scope is global. */
14007 prev_len
= result
.size ();
14008 ada_add_global_exceptions (preg
, &result
);
14009 if (result
.size () > prev_len
)
14010 sort_remove_dups_ada_exceptions_list (&result
, prev_len
);
14015 /* Return a vector of ada_exc_info.
14017 If REGEXP is NULL, all exceptions are included in the result.
14018 Otherwise, it should contain a valid regular expression,
14019 and only the exceptions whose names match that regular expression
14020 are included in the result.
14022 The exceptions are sorted in the following order:
14023 - Standard exceptions (defined by the Ada language), in
14024 alphabetical order;
14025 - Exceptions only visible from the current frame, in
14026 alphabetical order;
14027 - Exceptions whose scope is global, in alphabetical order. */
14029 std::vector
<ada_exc_info
>
14030 ada_exceptions_list (const char *regexp
)
14032 if (regexp
== NULL
)
14033 return ada_exceptions_list_1 (NULL
);
14035 compiled_regex
reg (regexp
, REG_NOSUB
, _("invalid regular expression"));
14036 return ada_exceptions_list_1 (®
);
14039 /* Implement the "info exceptions" command. */
14042 info_exceptions_command (const char *regexp
, int from_tty
)
14044 struct gdbarch
*gdbarch
= get_current_arch ();
14046 std::vector
<ada_exc_info
> exceptions
= ada_exceptions_list (regexp
);
14048 if (regexp
!= NULL
)
14050 (_("All Ada exceptions matching regular expression \"%s\":\n"), regexp
);
14052 printf_filtered (_("All defined Ada exceptions:\n"));
14054 for (const ada_exc_info
&info
: exceptions
)
14055 printf_filtered ("%s: %s\n", info
.name
, paddress (gdbarch
, info
.addr
));
14059 /* Information about operators given special treatment in functions
14061 /* Format: OP_DEFN (<operator>, <operator length>, <# args>, <binop>). */
14063 #define ADA_OPERATORS \
14064 OP_DEFN (OP_VAR_VALUE, 4, 0, 0) \
14065 OP_DEFN (BINOP_IN_BOUNDS, 3, 2, 0) \
14066 OP_DEFN (TERNOP_IN_RANGE, 1, 3, 0) \
14067 OP_DEFN (OP_ATR_FIRST, 1, 2, 0) \
14068 OP_DEFN (OP_ATR_LAST, 1, 2, 0) \
14069 OP_DEFN (OP_ATR_LENGTH, 1, 2, 0) \
14070 OP_DEFN (OP_ATR_IMAGE, 1, 2, 0) \
14071 OP_DEFN (OP_ATR_MAX, 1, 3, 0) \
14072 OP_DEFN (OP_ATR_MIN, 1, 3, 0) \
14073 OP_DEFN (OP_ATR_MODULUS, 1, 1, 0) \
14074 OP_DEFN (OP_ATR_POS, 1, 2, 0) \
14075 OP_DEFN (OP_ATR_SIZE, 1, 1, 0) \
14076 OP_DEFN (OP_ATR_TAG, 1, 1, 0) \
14077 OP_DEFN (OP_ATR_VAL, 1, 2, 0) \
14078 OP_DEFN (UNOP_QUAL, 3, 1, 0) \
14079 OP_DEFN (UNOP_IN_RANGE, 3, 1, 0) \
14080 OP_DEFN (OP_OTHERS, 1, 1, 0) \
14081 OP_DEFN (OP_POSITIONAL, 3, 1, 0) \
14082 OP_DEFN (OP_DISCRETE_RANGE, 1, 2, 0)
14085 ada_operator_length (const struct expression
*exp
, int pc
, int *oplenp
,
14088 switch (exp
->elts
[pc
- 1].opcode
)
14091 operator_length_standard (exp
, pc
, oplenp
, argsp
);
14094 #define OP_DEFN(op, len, args, binop) \
14095 case op: *oplenp = len; *argsp = args; break;
14101 *argsp
= longest_to_int (exp
->elts
[pc
- 2].longconst
);
14106 *argsp
= longest_to_int (exp
->elts
[pc
- 2].longconst
) + 1;
14111 /* Implementation of the exp_descriptor method operator_check. */
14114 ada_operator_check (struct expression
*exp
, int pos
,
14115 int (*objfile_func
) (struct objfile
*objfile
, void *data
),
14118 const union exp_element
*const elts
= exp
->elts
;
14119 struct type
*type
= NULL
;
14121 switch (elts
[pos
].opcode
)
14123 case UNOP_IN_RANGE
:
14125 type
= elts
[pos
+ 1].type
;
14129 return operator_check_standard (exp
, pos
, objfile_func
, data
);
14132 /* Invoke callbacks for TYPE and OBJFILE if they were set as non-NULL. */
14134 if (type
!= nullptr && type
->objfile_owner () != nullptr
14135 && objfile_func (type
->objfile_owner (), data
))
14141 /* As for operator_length, but assumes PC is pointing at the first
14142 element of the operator, and gives meaningful results only for the
14143 Ada-specific operators, returning 0 for *OPLENP and *ARGSP otherwise. */
14146 ada_forward_operator_length (struct expression
*exp
, int pc
,
14147 int *oplenp
, int *argsp
)
14149 switch (exp
->elts
[pc
].opcode
)
14152 *oplenp
= *argsp
= 0;
14155 #define OP_DEFN(op, len, args, binop) \
14156 case op: *oplenp = len; *argsp = args; break;
14162 *argsp
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
14167 *argsp
= longest_to_int (exp
->elts
[pc
+ 1].longconst
) + 1;
14173 int len
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
14175 *oplenp
= 4 + BYTES_TO_EXP_ELEM (len
+ 1);
14183 ada_dump_subexp_body (struct expression
*exp
, struct ui_file
*stream
, int elt
)
14185 enum exp_opcode op
= exp
->elts
[elt
].opcode
;
14190 ada_forward_operator_length (exp
, elt
, &oplen
, &nargs
);
14194 /* Ada attributes ('Foo). */
14197 case OP_ATR_LENGTH
:
14201 case OP_ATR_MODULUS
:
14208 case UNOP_IN_RANGE
:
14210 /* XXX: gdb_sprint_host_address, type_sprint */
14211 fprintf_filtered (stream
, _("Type @"));
14212 gdb_print_host_address (exp
->elts
[pc
+ 1].type
, stream
);
14213 fprintf_filtered (stream
, " (");
14214 type_print (exp
->elts
[pc
+ 1].type
, NULL
, stream
, 0);
14215 fprintf_filtered (stream
, ")");
14217 case BINOP_IN_BOUNDS
:
14218 fprintf_filtered (stream
, " (%d)",
14219 longest_to_int (exp
->elts
[pc
+ 2].longconst
));
14221 case TERNOP_IN_RANGE
:
14226 case OP_DISCRETE_RANGE
:
14227 case OP_POSITIONAL
:
14234 char *name
= &exp
->elts
[elt
+ 2].string
;
14235 int len
= longest_to_int (exp
->elts
[elt
+ 1].longconst
);
14237 fprintf_filtered (stream
, "Text: `%.*s'", len
, name
);
14242 return dump_subexp_body_standard (exp
, stream
, elt
);
14246 for (i
= 0; i
< nargs
; i
+= 1)
14247 elt
= dump_subexp (exp
, stream
, elt
);
14252 /* The Ada extension of print_subexp (q.v.). */
14255 ada_print_subexp (struct expression
*exp
, int *pos
,
14256 struct ui_file
*stream
, enum precedence prec
)
14258 int oplen
, nargs
, i
;
14260 enum exp_opcode op
= exp
->elts
[pc
].opcode
;
14262 ada_forward_operator_length (exp
, pc
, &oplen
, &nargs
);
14269 print_subexp_standard (exp
, pos
, stream
, prec
);
14273 fputs_filtered (exp
->elts
[pc
+ 2].symbol
->natural_name (), stream
);
14276 case BINOP_IN_BOUNDS
:
14277 /* XXX: sprint_subexp */
14278 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
14279 fputs_filtered (" in ", stream
);
14280 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
14281 fputs_filtered ("'range", stream
);
14282 if (exp
->elts
[pc
+ 1].longconst
> 1)
14283 fprintf_filtered (stream
, "(%ld)",
14284 (long) exp
->elts
[pc
+ 1].longconst
);
14287 case TERNOP_IN_RANGE
:
14288 if (prec
>= PREC_EQUAL
)
14289 fputs_filtered ("(", stream
);
14290 /* XXX: sprint_subexp */
14291 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
14292 fputs_filtered (" in ", stream
);
14293 print_subexp (exp
, pos
, stream
, PREC_EQUAL
);
14294 fputs_filtered (" .. ", stream
);
14295 print_subexp (exp
, pos
, stream
, PREC_EQUAL
);
14296 if (prec
>= PREC_EQUAL
)
14297 fputs_filtered (")", stream
);
14302 case OP_ATR_LENGTH
:
14306 case OP_ATR_MODULUS
:
14311 if (exp
->elts
[*pos
].opcode
== OP_TYPE
)
14313 if (exp
->elts
[*pos
+ 1].type
->code () != TYPE_CODE_VOID
)
14314 LA_PRINT_TYPE (exp
->elts
[*pos
+ 1].type
, "", stream
, 0, 0,
14315 &type_print_raw_options
);
14319 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
14320 fprintf_filtered (stream
, "'%s", ada_attribute_name (op
));
14325 for (tem
= 1; tem
< nargs
; tem
+= 1)
14327 fputs_filtered ((tem
== 1) ? " (" : ", ", stream
);
14328 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
14330 fputs_filtered (")", stream
);
14335 type_print (exp
->elts
[pc
+ 1].type
, "", stream
, 0);
14336 fputs_filtered ("'(", stream
);
14337 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
14338 fputs_filtered (")", stream
);
14341 case UNOP_IN_RANGE
:
14342 /* XXX: sprint_subexp */
14343 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
14344 fputs_filtered (" in ", stream
);
14345 LA_PRINT_TYPE (exp
->elts
[pc
+ 1].type
, "", stream
, 1, 0,
14346 &type_print_raw_options
);
14349 case OP_DISCRETE_RANGE
:
14350 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
14351 fputs_filtered ("..", stream
);
14352 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
14356 fputs_filtered ("others => ", stream
);
14357 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
14361 for (i
= 0; i
< nargs
-1; i
+= 1)
14364 fputs_filtered ("|", stream
);
14365 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
14367 fputs_filtered (" => ", stream
);
14368 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
14371 case OP_POSITIONAL
:
14372 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
14376 fputs_filtered ("(", stream
);
14377 for (i
= 0; i
< nargs
; i
+= 1)
14380 fputs_filtered (", ", stream
);
14381 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
14383 fputs_filtered (")", stream
);
14388 /* Table mapping opcodes into strings for printing operators
14389 and precedences of the operators. */
14391 static const struct op_print ada_op_print_tab
[] = {
14392 {":=", BINOP_ASSIGN
, PREC_ASSIGN
, 1},
14393 {"or else", BINOP_LOGICAL_OR
, PREC_LOGICAL_OR
, 0},
14394 {"and then", BINOP_LOGICAL_AND
, PREC_LOGICAL_AND
, 0},
14395 {"or", BINOP_BITWISE_IOR
, PREC_BITWISE_IOR
, 0},
14396 {"xor", BINOP_BITWISE_XOR
, PREC_BITWISE_XOR
, 0},
14397 {"and", BINOP_BITWISE_AND
, PREC_BITWISE_AND
, 0},
14398 {"=", BINOP_EQUAL
, PREC_EQUAL
, 0},
14399 {"/=", BINOP_NOTEQUAL
, PREC_EQUAL
, 0},
14400 {"<=", BINOP_LEQ
, PREC_ORDER
, 0},
14401 {">=", BINOP_GEQ
, PREC_ORDER
, 0},
14402 {">", BINOP_GTR
, PREC_ORDER
, 0},
14403 {"<", BINOP_LESS
, PREC_ORDER
, 0},
14404 {">>", BINOP_RSH
, PREC_SHIFT
, 0},
14405 {"<<", BINOP_LSH
, PREC_SHIFT
, 0},
14406 {"+", BINOP_ADD
, PREC_ADD
, 0},
14407 {"-", BINOP_SUB
, PREC_ADD
, 0},
14408 {"&", BINOP_CONCAT
, PREC_ADD
, 0},
14409 {"*", BINOP_MUL
, PREC_MUL
, 0},
14410 {"/", BINOP_DIV
, PREC_MUL
, 0},
14411 {"rem", BINOP_REM
, PREC_MUL
, 0},
14412 {"mod", BINOP_MOD
, PREC_MUL
, 0},
14413 {"**", BINOP_EXP
, PREC_REPEAT
, 0},
14414 {"@", BINOP_REPEAT
, PREC_REPEAT
, 0},
14415 {"-", UNOP_NEG
, PREC_PREFIX
, 0},
14416 {"+", UNOP_PLUS
, PREC_PREFIX
, 0},
14417 {"not ", UNOP_LOGICAL_NOT
, PREC_PREFIX
, 0},
14418 {"not ", UNOP_COMPLEMENT
, PREC_PREFIX
, 0},
14419 {"abs ", UNOP_ABS
, PREC_PREFIX
, 0},
14420 {".all", UNOP_IND
, PREC_SUFFIX
, 1},
14421 {"'access", UNOP_ADDR
, PREC_SUFFIX
, 1},
14422 {"'size", OP_ATR_SIZE
, PREC_SUFFIX
, 1},
14423 {NULL
, OP_NULL
, PREC_SUFFIX
, 0}
14426 /* Language vector */
14428 static const struct exp_descriptor ada_exp_descriptor
= {
14430 ada_operator_length
,
14431 ada_operator_check
,
14432 ada_dump_subexp_body
,
14433 ada_evaluate_subexp
14436 /* symbol_name_matcher_ftype adapter for wild_match. */
14439 do_wild_match (const char *symbol_search_name
,
14440 const lookup_name_info
&lookup_name
,
14441 completion_match_result
*comp_match_res
)
14443 return wild_match (symbol_search_name
, ada_lookup_name (lookup_name
));
14446 /* symbol_name_matcher_ftype adapter for full_match. */
14449 do_full_match (const char *symbol_search_name
,
14450 const lookup_name_info
&lookup_name
,
14451 completion_match_result
*comp_match_res
)
14453 const char *lname
= lookup_name
.ada ().lookup_name ().c_str ();
14455 /* If both symbols start with "_ada_", just let the loop below
14456 handle the comparison. However, if only the symbol name starts
14457 with "_ada_", skip the prefix and let the match proceed as
14459 if (startswith (symbol_search_name
, "_ada_")
14460 && !startswith (lname
, "_ada"))
14461 symbol_search_name
+= 5;
14463 int uscore_count
= 0;
14464 while (*lname
!= '\0')
14466 if (*symbol_search_name
!= *lname
)
14468 if (*symbol_search_name
== 'B' && uscore_count
== 2
14469 && symbol_search_name
[1] == '_')
14471 symbol_search_name
+= 2;
14472 while (isdigit (*symbol_search_name
))
14473 ++symbol_search_name
;
14474 if (symbol_search_name
[0] == '_'
14475 && symbol_search_name
[1] == '_')
14477 symbol_search_name
+= 2;
14484 if (*symbol_search_name
== '_')
14489 ++symbol_search_name
;
14493 return is_name_suffix (symbol_search_name
);
14496 /* symbol_name_matcher_ftype for exact (verbatim) matches. */
14499 do_exact_match (const char *symbol_search_name
,
14500 const lookup_name_info
&lookup_name
,
14501 completion_match_result
*comp_match_res
)
14503 return strcmp (symbol_search_name
, ada_lookup_name (lookup_name
)) == 0;
14506 /* Build the Ada lookup name for LOOKUP_NAME. */
14508 ada_lookup_name_info::ada_lookup_name_info (const lookup_name_info
&lookup_name
)
14510 gdb::string_view user_name
= lookup_name
.name ();
14512 if (!user_name
.empty () && user_name
[0] == '<')
14514 if (user_name
.back () == '>')
14516 = gdb::to_string (user_name
.substr (1, user_name
.size () - 2));
14519 = gdb::to_string (user_name
.substr (1, user_name
.size () - 1));
14520 m_encoded_p
= true;
14521 m_verbatim_p
= true;
14522 m_wild_match_p
= false;
14523 m_standard_p
= false;
14527 m_verbatim_p
= false;
14529 m_encoded_p
= user_name
.find ("__") != gdb::string_view::npos
;
14533 const char *folded
= ada_fold_name (user_name
);
14534 m_encoded_name
= ada_encode_1 (folded
, false);
14535 if (m_encoded_name
.empty ())
14536 m_encoded_name
= gdb::to_string (user_name
);
14539 m_encoded_name
= gdb::to_string (user_name
);
14541 /* Handle the 'package Standard' special case. See description
14542 of m_standard_p. */
14543 if (startswith (m_encoded_name
.c_str (), "standard__"))
14545 m_encoded_name
= m_encoded_name
.substr (sizeof ("standard__") - 1);
14546 m_standard_p
= true;
14549 m_standard_p
= false;
14551 /* If the name contains a ".", then the user is entering a fully
14552 qualified entity name, and the match must not be done in wild
14553 mode. Similarly, if the user wants to complete what looks
14554 like an encoded name, the match must not be done in wild
14555 mode. Also, in the standard__ special case always do
14556 non-wild matching. */
14558 = (lookup_name
.match_type () != symbol_name_match_type::FULL
14561 && user_name
.find ('.') == std::string::npos
);
14565 /* symbol_name_matcher_ftype method for Ada. This only handles
14566 completion mode. */
14569 ada_symbol_name_matches (const char *symbol_search_name
,
14570 const lookup_name_info
&lookup_name
,
14571 completion_match_result
*comp_match_res
)
14573 return lookup_name
.ada ().matches (symbol_search_name
,
14574 lookup_name
.match_type (),
14578 /* A name matcher that matches the symbol name exactly, with
14582 literal_symbol_name_matcher (const char *symbol_search_name
,
14583 const lookup_name_info
&lookup_name
,
14584 completion_match_result
*comp_match_res
)
14586 gdb::string_view name_view
= lookup_name
.name ();
14588 if (lookup_name
.completion_mode ()
14589 ? (strncmp (symbol_search_name
, name_view
.data (),
14590 name_view
.size ()) == 0)
14591 : symbol_search_name
== name_view
)
14593 if (comp_match_res
!= NULL
)
14594 comp_match_res
->set_match (symbol_search_name
);
14601 /* Implement the "get_symbol_name_matcher" language_defn method for
14604 static symbol_name_matcher_ftype
*
14605 ada_get_symbol_name_matcher (const lookup_name_info
&lookup_name
)
14607 if (lookup_name
.match_type () == symbol_name_match_type::SEARCH_NAME
)
14608 return literal_symbol_name_matcher
;
14610 if (lookup_name
.completion_mode ())
14611 return ada_symbol_name_matches
;
14614 if (lookup_name
.ada ().wild_match_p ())
14615 return do_wild_match
;
14616 else if (lookup_name
.ada ().verbatim_p ())
14617 return do_exact_match
;
14619 return do_full_match
;
14623 /* Class representing the Ada language. */
14625 class ada_language
: public language_defn
14629 : language_defn (language_ada
)
14632 /* See language.h. */
14634 const char *name () const override
14637 /* See language.h. */
14639 const char *natural_name () const override
14642 /* See language.h. */
14644 const std::vector
<const char *> &filename_extensions () const override
14646 static const std::vector
<const char *> extensions
14647 = { ".adb", ".ads", ".a", ".ada", ".dg" };
14651 /* Print an array element index using the Ada syntax. */
14653 void print_array_index (struct type
*index_type
,
14655 struct ui_file
*stream
,
14656 const value_print_options
*options
) const override
14658 struct value
*index_value
= val_atr (index_type
, index
);
14660 value_print (index_value
, stream
, options
);
14661 fprintf_filtered (stream
, " => ");
14664 /* Implement the "read_var_value" language_defn method for Ada. */
14666 struct value
*read_var_value (struct symbol
*var
,
14667 const struct block
*var_block
,
14668 struct frame_info
*frame
) const override
14670 /* The only case where default_read_var_value is not sufficient
14671 is when VAR is a renaming... */
14672 if (frame
!= nullptr)
14674 const struct block
*frame_block
= get_frame_block (frame
, NULL
);
14675 if (frame_block
!= nullptr && ada_is_renaming_symbol (var
))
14676 return ada_read_renaming_var_value (var
, frame_block
);
14679 /* This is a typical case where we expect the default_read_var_value
14680 function to work. */
14681 return language_defn::read_var_value (var
, var_block
, frame
);
14684 /* See language.h. */
14685 void language_arch_info (struct gdbarch
*gdbarch
,
14686 struct language_arch_info
*lai
) const override
14688 const struct builtin_type
*builtin
= builtin_type (gdbarch
);
14690 /* Helper function to allow shorter lines below. */
14691 auto add
= [&] (struct type
*t
)
14693 lai
->add_primitive_type (t
);
14696 add (arch_integer_type (gdbarch
, gdbarch_int_bit (gdbarch
),
14698 add (arch_integer_type (gdbarch
, gdbarch_long_bit (gdbarch
),
14699 0, "long_integer"));
14700 add (arch_integer_type (gdbarch
, gdbarch_short_bit (gdbarch
),
14701 0, "short_integer"));
14702 struct type
*char_type
= arch_character_type (gdbarch
, TARGET_CHAR_BIT
,
14704 lai
->set_string_char_type (char_type
);
14706 add (arch_float_type (gdbarch
, gdbarch_float_bit (gdbarch
),
14707 "float", gdbarch_float_format (gdbarch
)));
14708 add (arch_float_type (gdbarch
, gdbarch_double_bit (gdbarch
),
14709 "long_float", gdbarch_double_format (gdbarch
)));
14710 add (arch_integer_type (gdbarch
, gdbarch_long_long_bit (gdbarch
),
14711 0, "long_long_integer"));
14712 add (arch_float_type (gdbarch
, gdbarch_long_double_bit (gdbarch
),
14714 gdbarch_long_double_format (gdbarch
)));
14715 add (arch_integer_type (gdbarch
, gdbarch_int_bit (gdbarch
),
14717 add (arch_integer_type (gdbarch
, gdbarch_int_bit (gdbarch
),
14719 add (builtin
->builtin_void
);
14721 struct type
*system_addr_ptr
14722 = lookup_pointer_type (arch_type (gdbarch
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
,
14724 system_addr_ptr
->set_name ("system__address");
14725 add (system_addr_ptr
);
14727 /* Create the equivalent of the System.Storage_Elements.Storage_Offset
14728 type. This is a signed integral type whose size is the same as
14729 the size of addresses. */
14730 unsigned int addr_length
= TYPE_LENGTH (system_addr_ptr
);
14731 add (arch_integer_type (gdbarch
, addr_length
* HOST_CHAR_BIT
, 0,
14732 "storage_offset"));
14734 lai
->set_bool_type (builtin
->builtin_bool
);
14737 /* See language.h. */
14739 bool iterate_over_symbols
14740 (const struct block
*block
, const lookup_name_info
&name
,
14741 domain_enum domain
,
14742 gdb::function_view
<symbol_found_callback_ftype
> callback
) const override
14744 std::vector
<struct block_symbol
> results
14745 = ada_lookup_symbol_list_worker (name
, block
, domain
, 0);
14746 for (block_symbol
&sym
: results
)
14748 if (!callback (&sym
))
14755 /* See language.h. */
14756 bool sniff_from_mangled_name (const char *mangled
,
14757 char **out
) const override
14759 std::string demangled
= ada_decode (mangled
);
14763 if (demangled
!= mangled
&& demangled
[0] != '<')
14765 /* Set the gsymbol language to Ada, but still return 0.
14766 Two reasons for that:
14768 1. For Ada, we prefer computing the symbol's decoded name
14769 on the fly rather than pre-compute it, in order to save
14770 memory (Ada projects are typically very large).
14772 2. There are some areas in the definition of the GNAT
14773 encoding where, with a bit of bad luck, we might be able
14774 to decode a non-Ada symbol, generating an incorrect
14775 demangled name (Eg: names ending with "TB" for instance
14776 are identified as task bodies and so stripped from
14777 the decoded name returned).
14779 Returning true, here, but not setting *DEMANGLED, helps us get
14780 a little bit of the best of both worlds. Because we're last,
14781 we should not affect any of the other languages that were
14782 able to demangle the symbol before us; we get to correctly
14783 tag Ada symbols as such; and even if we incorrectly tagged a
14784 non-Ada symbol, which should be rare, any routing through the
14785 Ada language should be transparent (Ada tries to behave much
14786 like C/C++ with non-Ada symbols). */
14793 /* See language.h. */
14795 char *demangle_symbol (const char *mangled
, int options
) const override
14797 return ada_la_decode (mangled
, options
);
14800 /* See language.h. */
14802 void print_type (struct type
*type
, const char *varstring
,
14803 struct ui_file
*stream
, int show
, int level
,
14804 const struct type_print_options
*flags
) const override
14806 ada_print_type (type
, varstring
, stream
, show
, level
, flags
);
14809 /* See language.h. */
14811 const char *word_break_characters (void) const override
14813 return ada_completer_word_break_characters
;
14816 /* See language.h. */
14818 void collect_symbol_completion_matches (completion_tracker
&tracker
,
14819 complete_symbol_mode mode
,
14820 symbol_name_match_type name_match_type
,
14821 const char *text
, const char *word
,
14822 enum type_code code
) const override
14824 struct symbol
*sym
;
14825 const struct block
*b
, *surrounding_static_block
= 0;
14826 struct block_iterator iter
;
14828 gdb_assert (code
== TYPE_CODE_UNDEF
);
14830 lookup_name_info
lookup_name (text
, name_match_type
, true);
14832 /* First, look at the partial symtab symbols. */
14833 expand_symtabs_matching (NULL
,
14839 /* At this point scan through the misc symbol vectors and add each
14840 symbol you find to the list. Eventually we want to ignore
14841 anything that isn't a text symbol (everything else will be
14842 handled by the psymtab code above). */
14844 for (objfile
*objfile
: current_program_space
->objfiles ())
14846 for (minimal_symbol
*msymbol
: objfile
->msymbols ())
14850 if (completion_skip_symbol (mode
, msymbol
))
14853 language symbol_language
= msymbol
->language ();
14855 /* Ada minimal symbols won't have their language set to Ada. If
14856 we let completion_list_add_name compare using the
14857 default/C-like matcher, then when completing e.g., symbols in a
14858 package named "pck", we'd match internal Ada symbols like
14859 "pckS", which are invalid in an Ada expression, unless you wrap
14860 them in '<' '>' to request a verbatim match.
14862 Unfortunately, some Ada encoded names successfully demangle as
14863 C++ symbols (using an old mangling scheme), such as "name__2Xn"
14864 -> "Xn::name(void)" and thus some Ada minimal symbols end up
14865 with the wrong language set. Paper over that issue here. */
14866 if (symbol_language
== language_auto
14867 || symbol_language
== language_cplus
)
14868 symbol_language
= language_ada
;
14870 completion_list_add_name (tracker
,
14872 msymbol
->linkage_name (),
14873 lookup_name
, text
, word
);
14877 /* Search upwards from currently selected frame (so that we can
14878 complete on local vars. */
14880 for (b
= get_selected_block (0); b
!= NULL
; b
= BLOCK_SUPERBLOCK (b
))
14882 if (!BLOCK_SUPERBLOCK (b
))
14883 surrounding_static_block
= b
; /* For elmin of dups */
14885 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
14887 if (completion_skip_symbol (mode
, sym
))
14890 completion_list_add_name (tracker
,
14892 sym
->linkage_name (),
14893 lookup_name
, text
, word
);
14897 /* Go through the symtabs and check the externs and statics for
14898 symbols which match. */
14900 for (objfile
*objfile
: current_program_space
->objfiles ())
14902 for (compunit_symtab
*s
: objfile
->compunits ())
14905 b
= BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (s
), GLOBAL_BLOCK
);
14906 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
14908 if (completion_skip_symbol (mode
, sym
))
14911 completion_list_add_name (tracker
,
14913 sym
->linkage_name (),
14914 lookup_name
, text
, word
);
14919 for (objfile
*objfile
: current_program_space
->objfiles ())
14921 for (compunit_symtab
*s
: objfile
->compunits ())
14924 b
= BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (s
), STATIC_BLOCK
);
14925 /* Don't do this block twice. */
14926 if (b
== surrounding_static_block
)
14928 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
14930 if (completion_skip_symbol (mode
, sym
))
14933 completion_list_add_name (tracker
,
14935 sym
->linkage_name (),
14936 lookup_name
, text
, word
);
14942 /* See language.h. */
14944 gdb::unique_xmalloc_ptr
<char> watch_location_expression
14945 (struct type
*type
, CORE_ADDR addr
) const override
14947 type
= check_typedef (TYPE_TARGET_TYPE (check_typedef (type
)));
14948 std::string name
= type_to_string (type
);
14949 return gdb::unique_xmalloc_ptr
<char>
14950 (xstrprintf ("{%s} %s", name
.c_str (), core_addr_to_string (addr
)));
14953 /* See language.h. */
14955 void value_print (struct value
*val
, struct ui_file
*stream
,
14956 const struct value_print_options
*options
) const override
14958 return ada_value_print (val
, stream
, options
);
14961 /* See language.h. */
14963 void value_print_inner
14964 (struct value
*val
, struct ui_file
*stream
, int recurse
,
14965 const struct value_print_options
*options
) const override
14967 return ada_value_print_inner (val
, stream
, recurse
, options
);
14970 /* See language.h. */
14972 struct block_symbol lookup_symbol_nonlocal
14973 (const char *name
, const struct block
*block
,
14974 const domain_enum domain
) const override
14976 struct block_symbol sym
;
14978 sym
= ada_lookup_symbol (name
, block_static_block (block
), domain
);
14979 if (sym
.symbol
!= NULL
)
14982 /* If we haven't found a match at this point, try the primitive
14983 types. In other languages, this search is performed before
14984 searching for global symbols in order to short-circuit that
14985 global-symbol search if it happens that the name corresponds
14986 to a primitive type. But we cannot do the same in Ada, because
14987 it is perfectly legitimate for a program to declare a type which
14988 has the same name as a standard type. If looking up a type in
14989 that situation, we have traditionally ignored the primitive type
14990 in favor of user-defined types. This is why, unlike most other
14991 languages, we search the primitive types this late and only after
14992 having searched the global symbols without success. */
14994 if (domain
== VAR_DOMAIN
)
14996 struct gdbarch
*gdbarch
;
14999 gdbarch
= target_gdbarch ();
15001 gdbarch
= block_gdbarch (block
);
15003 = language_lookup_primitive_type_as_symbol (this, gdbarch
, name
);
15004 if (sym
.symbol
!= NULL
)
15011 /* See language.h. */
15013 int parser (struct parser_state
*ps
) const override
15015 warnings_issued
= 0;
15016 return ada_parse (ps
);
15021 Same as evaluate_type (*EXP), but resolves ambiguous symbol references
15022 (marked by OP_VAR_VALUE nodes in which the symbol has an undefined
15023 namespace) and converts operators that are user-defined into
15024 appropriate function calls. If CONTEXT_TYPE is non-null, it provides
15025 a preferred result type [at the moment, only type void has any
15026 effect---causing procedures to be preferred over functions in calls].
15027 A null CONTEXT_TYPE indicates that a non-void return type is
15028 preferred. May change (expand) *EXP. */
15030 void post_parser (expression_up
*expp
, struct parser_state
*ps
)
15033 struct type
*context_type
= NULL
;
15036 if (ps
->void_context_p
)
15037 context_type
= builtin_type ((*expp
)->gdbarch
)->builtin_void
;
15039 resolve_subexp (expp
, &pc
, 1, context_type
, ps
->parse_completion
,
15040 ps
->block_tracker
);
15043 /* See language.h. */
15045 void emitchar (int ch
, struct type
*chtype
,
15046 struct ui_file
*stream
, int quoter
) const override
15048 ada_emit_char (ch
, chtype
, stream
, quoter
, 1);
15051 /* See language.h. */
15053 void printchar (int ch
, struct type
*chtype
,
15054 struct ui_file
*stream
) const override
15056 ada_printchar (ch
, chtype
, stream
);
15059 /* See language.h. */
15061 void printstr (struct ui_file
*stream
, struct type
*elttype
,
15062 const gdb_byte
*string
, unsigned int length
,
15063 const char *encoding
, int force_ellipses
,
15064 const struct value_print_options
*options
) const override
15066 ada_printstr (stream
, elttype
, string
, length
, encoding
,
15067 force_ellipses
, options
);
15070 /* See language.h. */
15072 void print_typedef (struct type
*type
, struct symbol
*new_symbol
,
15073 struct ui_file
*stream
) const override
15075 ada_print_typedef (type
, new_symbol
, stream
);
15078 /* See language.h. */
15080 bool is_string_type_p (struct type
*type
) const override
15082 return ada_is_string_type (type
);
15085 /* See language.h. */
15087 const char *struct_too_deep_ellipsis () const override
15088 { return "(...)"; }
15090 /* See language.h. */
15092 bool c_style_arrays_p () const override
15095 /* See language.h. */
15097 bool store_sym_names_in_linkage_form_p () const override
15100 /* See language.h. */
15102 const struct lang_varobj_ops
*varobj_ops () const override
15103 { return &ada_varobj_ops
; }
15105 /* See language.h. */
15107 const struct exp_descriptor
*expression_ops () const override
15108 { return &ada_exp_descriptor
; }
15110 /* See language.h. */
15112 const struct op_print
*opcode_print_table () const override
15113 { return ada_op_print_tab
; }
15116 /* See language.h. */
15118 symbol_name_matcher_ftype
*get_symbol_name_matcher_inner
15119 (const lookup_name_info
&lookup_name
) const override
15121 return ada_get_symbol_name_matcher (lookup_name
);
15125 /* Single instance of the Ada language class. */
15127 static ada_language ada_language_defn
;
15129 /* Command-list for the "set/show ada" prefix command. */
15130 static struct cmd_list_element
*set_ada_list
;
15131 static struct cmd_list_element
*show_ada_list
;
15134 initialize_ada_catchpoint_ops (void)
15136 struct breakpoint_ops
*ops
;
15138 initialize_breakpoint_ops ();
15140 ops
= &catch_exception_breakpoint_ops
;
15141 *ops
= bkpt_breakpoint_ops
;
15142 ops
->allocate_location
= allocate_location_exception
;
15143 ops
->re_set
= re_set_exception
;
15144 ops
->check_status
= check_status_exception
;
15145 ops
->print_it
= print_it_exception
;
15146 ops
->print_one
= print_one_exception
;
15147 ops
->print_mention
= print_mention_exception
;
15148 ops
->print_recreate
= print_recreate_exception
;
15150 ops
= &catch_exception_unhandled_breakpoint_ops
;
15151 *ops
= bkpt_breakpoint_ops
;
15152 ops
->allocate_location
= allocate_location_exception
;
15153 ops
->re_set
= re_set_exception
;
15154 ops
->check_status
= check_status_exception
;
15155 ops
->print_it
= print_it_exception
;
15156 ops
->print_one
= print_one_exception
;
15157 ops
->print_mention
= print_mention_exception
;
15158 ops
->print_recreate
= print_recreate_exception
;
15160 ops
= &catch_assert_breakpoint_ops
;
15161 *ops
= bkpt_breakpoint_ops
;
15162 ops
->allocate_location
= allocate_location_exception
;
15163 ops
->re_set
= re_set_exception
;
15164 ops
->check_status
= check_status_exception
;
15165 ops
->print_it
= print_it_exception
;
15166 ops
->print_one
= print_one_exception
;
15167 ops
->print_mention
= print_mention_exception
;
15168 ops
->print_recreate
= print_recreate_exception
;
15170 ops
= &catch_handlers_breakpoint_ops
;
15171 *ops
= bkpt_breakpoint_ops
;
15172 ops
->allocate_location
= allocate_location_exception
;
15173 ops
->re_set
= re_set_exception
;
15174 ops
->check_status
= check_status_exception
;
15175 ops
->print_it
= print_it_exception
;
15176 ops
->print_one
= print_one_exception
;
15177 ops
->print_mention
= print_mention_exception
;
15178 ops
->print_recreate
= print_recreate_exception
;
15181 /* This module's 'new_objfile' observer. */
15184 ada_new_objfile_observer (struct objfile
*objfile
)
15186 ada_clear_symbol_cache ();
15189 /* This module's 'free_objfile' observer. */
15192 ada_free_objfile_observer (struct objfile
*objfile
)
15194 ada_clear_symbol_cache ();
15197 void _initialize_ada_language ();
15199 _initialize_ada_language ()
15201 initialize_ada_catchpoint_ops ();
15203 add_basic_prefix_cmd ("ada", no_class
,
15204 _("Prefix command for changing Ada-specific settings."),
15205 &set_ada_list
, "set ada ", 0, &setlist
);
15207 add_show_prefix_cmd ("ada", no_class
,
15208 _("Generic command for showing Ada-specific settings."),
15209 &show_ada_list
, "show ada ", 0, &showlist
);
15211 add_setshow_boolean_cmd ("trust-PAD-over-XVS", class_obscure
,
15212 &trust_pad_over_xvs
, _("\
15213 Enable or disable an optimization trusting PAD types over XVS types."), _("\
15214 Show whether an optimization trusting PAD types over XVS types is activated."),
15216 This is related to the encoding used by the GNAT compiler. The debugger\n\
15217 should normally trust the contents of PAD types, but certain older versions\n\
15218 of GNAT have a bug that sometimes causes the information in the PAD type\n\
15219 to be incorrect. Turning this setting \"off\" allows the debugger to\n\
15220 work around this bug. It is always safe to turn this option \"off\", but\n\
15221 this incurs a slight performance penalty, so it is recommended to NOT change\n\
15222 this option to \"off\" unless necessary."),
15223 NULL
, NULL
, &set_ada_list
, &show_ada_list
);
15225 add_setshow_boolean_cmd ("print-signatures", class_vars
,
15226 &print_signatures
, _("\
15227 Enable or disable the output of formal and return types for functions in the \
15228 overloads selection menu."), _("\
15229 Show whether the output of formal and return types for functions in the \
15230 overloads selection menu is activated."),
15231 NULL
, NULL
, NULL
, &set_ada_list
, &show_ada_list
);
15233 add_catch_command ("exception", _("\
15234 Catch Ada exceptions, when raised.\n\
15235 Usage: catch exception [ARG] [if CONDITION]\n\
15236 Without any argument, stop when any Ada exception is raised.\n\
15237 If ARG is \"unhandled\" (without the quotes), only stop when the exception\n\
15238 being raised does not have a handler (and will therefore lead to the task's\n\
15240 Otherwise, the catchpoint only stops when the name of the exception being\n\
15241 raised is the same as ARG.\n\
15242 CONDITION is a boolean expression that is evaluated to see whether the\n\
15243 exception should cause a stop."),
15244 catch_ada_exception_command
,
15245 catch_ada_completer
,
15249 add_catch_command ("handlers", _("\
15250 Catch Ada exceptions, when handled.\n\
15251 Usage: catch handlers [ARG] [if CONDITION]\n\
15252 Without any argument, stop when any Ada exception is handled.\n\
15253 With an argument, catch only exceptions with the given name.\n\
15254 CONDITION is a boolean expression that is evaluated to see whether the\n\
15255 exception should cause a stop."),
15256 catch_ada_handlers_command
,
15257 catch_ada_completer
,
15260 add_catch_command ("assert", _("\
15261 Catch failed Ada assertions, when raised.\n\
15262 Usage: catch assert [if CONDITION]\n\
15263 CONDITION is a boolean expression that is evaluated to see whether the\n\
15264 exception should cause a stop."),
15265 catch_assert_command
,
15270 varsize_limit
= 65536;
15271 add_setshow_uinteger_cmd ("varsize-limit", class_support
,
15272 &varsize_limit
, _("\
15273 Set the maximum number of bytes allowed in a variable-size object."), _("\
15274 Show the maximum number of bytes allowed in a variable-size object."), _("\
15275 Attempts to access an object whose size is not a compile-time constant\n\
15276 and exceeds this limit will cause an error."),
15277 NULL
, NULL
, &setlist
, &showlist
);
15279 add_info ("exceptions", info_exceptions_command
,
15281 List all Ada exception names.\n\
15282 Usage: info exceptions [REGEXP]\n\
15283 If a regular expression is passed as an argument, only those matching\n\
15284 the regular expression are listed."));
15286 add_basic_prefix_cmd ("ada", class_maintenance
,
15287 _("Set Ada maintenance-related variables."),
15288 &maint_set_ada_cmdlist
, "maintenance set ada ",
15289 0/*allow-unknown*/, &maintenance_set_cmdlist
);
15291 add_show_prefix_cmd ("ada", class_maintenance
,
15292 _("Show Ada maintenance-related variables."),
15293 &maint_show_ada_cmdlist
, "maintenance show ada ",
15294 0/*allow-unknown*/, &maintenance_show_cmdlist
);
15296 add_setshow_boolean_cmd
15297 ("ignore-descriptive-types", class_maintenance
,
15298 &ada_ignore_descriptive_types_p
,
15299 _("Set whether descriptive types generated by GNAT should be ignored."),
15300 _("Show whether descriptive types generated by GNAT should be ignored."),
15302 When enabled, the debugger will stop using the DW_AT_GNAT_descriptive_type\n\
15303 DWARF attribute."),
15304 NULL
, NULL
, &maint_set_ada_cmdlist
, &maint_show_ada_cmdlist
);
15306 decoded_names_store
= htab_create_alloc (256, htab_hash_string
, streq_hash
,
15307 NULL
, xcalloc
, xfree
);
15309 /* The ada-lang observers. */
15310 gdb::observers::new_objfile
.attach (ada_new_objfile_observer
);
15311 gdb::observers::free_objfile
.attach (ada_free_objfile_observer
);
15312 gdb::observers::inferior_exit
.attach (ada_inferior_exit
);