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"
52 #include "cli/cli-decode.h"
55 #include "mi/mi-common.h"
56 #include "arch-utils.h"
57 #include "cli/cli-utils.h"
58 #include "gdbsupport/function-view.h"
59 #include "gdbsupport/byte-vector.h"
63 /* Define whether or not the C operator '/' truncates towards zero for
64 differently signed operands (truncation direction is undefined in C).
65 Copied from valarith.c. */
67 #ifndef TRUNCATION_TOWARDS_ZERO
68 #define TRUNCATION_TOWARDS_ZERO ((-5 / 2) == -2)
71 static struct type
*desc_base_type (struct type
*);
73 static struct type
*desc_bounds_type (struct type
*);
75 static struct value
*desc_bounds (struct value
*);
77 static int fat_pntr_bounds_bitpos (struct type
*);
79 static int fat_pntr_bounds_bitsize (struct type
*);
81 static struct type
*desc_data_target_type (struct type
*);
83 static struct value
*desc_data (struct value
*);
85 static int fat_pntr_data_bitpos (struct type
*);
87 static int fat_pntr_data_bitsize (struct type
*);
89 static struct value
*desc_one_bound (struct value
*, int, int);
91 static int desc_bound_bitpos (struct type
*, int, int);
93 static int desc_bound_bitsize (struct type
*, int, int);
95 static struct type
*desc_index_type (struct type
*, int);
97 static int desc_arity (struct type
*);
99 static int ada_args_match (struct symbol
*, struct value
**, int);
101 static struct value
*make_array_descriptor (struct type
*, struct value
*);
103 static void ada_add_block_symbols (std::vector
<struct block_symbol
> &,
104 const struct block
*,
105 const lookup_name_info
&lookup_name
,
106 domain_enum
, struct objfile
*);
108 static void ada_add_all_symbols (std::vector
<struct block_symbol
> &,
109 const struct block
*,
110 const lookup_name_info
&lookup_name
,
111 domain_enum
, int, int *);
113 static int is_nonfunction (const std::vector
<struct block_symbol
> &);
115 static void add_defn_to_vec (std::vector
<struct block_symbol
> &,
117 const struct block
*);
119 static int possible_user_operator_p (enum exp_opcode
, struct value
**);
121 static const char *ada_decoded_op_name (enum exp_opcode
);
123 static int numeric_type_p (struct type
*);
125 static int integer_type_p (struct type
*);
127 static int scalar_type_p (struct type
*);
129 static int discrete_type_p (struct type
*);
131 static struct type
*ada_lookup_struct_elt_type (struct type
*, const char *,
134 static struct type
*ada_find_parallel_type_with_name (struct type
*,
137 static int is_dynamic_field (struct type
*, int);
139 static struct type
*to_fixed_variant_branch_type (struct type
*,
141 CORE_ADDR
, struct value
*);
143 static struct type
*to_fixed_array_type (struct type
*, struct value
*, int);
145 static struct type
*to_fixed_range_type (struct type
*, struct value
*);
147 static struct type
*to_static_fixed_type (struct type
*);
148 static struct type
*static_unwrap_type (struct type
*type
);
150 static struct value
*unwrap_value (struct value
*);
152 static struct type
*constrained_packed_array_type (struct type
*, long *);
154 static struct type
*decode_constrained_packed_array_type (struct type
*);
156 static long decode_packed_array_bitsize (struct type
*);
158 static struct value
*decode_constrained_packed_array (struct value
*);
160 static int ada_is_unconstrained_packed_array_type (struct type
*);
162 static struct value
*value_subscript_packed (struct value
*, int,
165 static struct value
*coerce_unspec_val_to_type (struct value
*,
168 static int lesseq_defined_than (struct symbol
*, struct symbol
*);
170 static int equiv_types (struct type
*, struct type
*);
172 static int is_name_suffix (const char *);
174 static int advance_wild_match (const char **, const char *, char);
176 static bool wild_match (const char *name
, const char *patn
);
178 static struct value
*ada_coerce_ref (struct value
*);
180 static LONGEST
pos_atr (struct value
*);
182 static struct value
*val_atr (struct type
*, LONGEST
);
184 static struct symbol
*standard_lookup (const char *, const struct block
*,
187 static struct value
*ada_search_struct_field (const char *, struct value
*, int,
190 static int find_struct_field (const char *, struct type
*, int,
191 struct type
**, int *, int *, int *, int *);
193 static int ada_resolve_function (std::vector
<struct block_symbol
> &,
194 struct value
**, int, const char *,
195 struct type
*, bool);
197 static int ada_is_direct_array_type (struct type
*);
199 static struct value
*ada_index_struct_field (int, struct value
*, int,
202 static void add_component_interval (LONGEST
, LONGEST
, std::vector
<LONGEST
> &);
205 static struct type
*ada_find_any_type (const char *name
);
207 static symbol_name_matcher_ftype
*ada_get_symbol_name_matcher
208 (const lookup_name_info
&lookup_name
);
212 /* The result of a symbol lookup to be stored in our symbol cache. */
216 /* The name used to perform the lookup. */
218 /* The namespace used during the lookup. */
220 /* The symbol returned by the lookup, or NULL if no matching symbol
223 /* The block where the symbol was found, or NULL if no matching
225 const struct block
*block
;
226 /* A pointer to the next entry with the same hash. */
227 struct cache_entry
*next
;
230 /* The Ada symbol cache, used to store the result of Ada-mode symbol
231 lookups in the course of executing the user's commands.
233 The cache is implemented using a simple, fixed-sized hash.
234 The size is fixed on the grounds that there are not likely to be
235 all that many symbols looked up during any given session, regardless
236 of the size of the symbol table. If we decide to go to a resizable
237 table, let's just use the stuff from libiberty instead. */
239 #define HASH_SIZE 1009
241 struct ada_symbol_cache
243 /* An obstack used to store the entries in our cache. */
244 struct auto_obstack cache_space
;
246 /* The root of the hash table used to implement our symbol cache. */
247 struct cache_entry
*root
[HASH_SIZE
] {};
250 static const char ada_completer_word_break_characters
[] =
252 " \t\n!@#%^&*()+=|~`}{[]\";:?/,-";
254 " \t\n!@#$%^&*()+=|~`}{[]\";:?/,-";
257 /* The name of the symbol to use to get the name of the main subprogram. */
258 static const char ADA_MAIN_PROGRAM_SYMBOL_NAME
[]
259 = "__gnat_ada_main_program_name";
261 /* Limit on the number of warnings to raise per expression evaluation. */
262 static int warning_limit
= 2;
264 /* Number of warning messages issued; reset to 0 by cleanups after
265 expression evaluation. */
266 static int warnings_issued
= 0;
268 static const char * const known_runtime_file_name_patterns
[] = {
269 ADA_KNOWN_RUNTIME_FILE_NAME_PATTERNS NULL
272 static const char * const known_auxiliary_function_name_patterns
[] = {
273 ADA_KNOWN_AUXILIARY_FUNCTION_NAME_PATTERNS NULL
276 /* Maintenance-related settings for this module. */
278 static struct cmd_list_element
*maint_set_ada_cmdlist
;
279 static struct cmd_list_element
*maint_show_ada_cmdlist
;
281 /* The "maintenance ada set/show ignore-descriptive-type" value. */
283 static bool ada_ignore_descriptive_types_p
= false;
285 /* Inferior-specific data. */
287 /* Per-inferior data for this module. */
289 struct ada_inferior_data
291 /* The ada__tags__type_specific_data type, which is used when decoding
292 tagged types. With older versions of GNAT, this type was directly
293 accessible through a component ("tsd") in the object tag. But this
294 is no longer the case, so we cache it for each inferior. */
295 struct type
*tsd_type
= nullptr;
297 /* The exception_support_info data. This data is used to determine
298 how to implement support for Ada exception catchpoints in a given
300 const struct exception_support_info
*exception_info
= nullptr;
303 /* Our key to this module's inferior data. */
304 static const struct inferior_key
<ada_inferior_data
> ada_inferior_data
;
306 /* Return our inferior data for the given inferior (INF).
308 This function always returns a valid pointer to an allocated
309 ada_inferior_data structure. If INF's inferior data has not
310 been previously set, this functions creates a new one with all
311 fields set to zero, sets INF's inferior to it, and then returns
312 a pointer to that newly allocated ada_inferior_data. */
314 static struct ada_inferior_data
*
315 get_ada_inferior_data (struct inferior
*inf
)
317 struct ada_inferior_data
*data
;
319 data
= ada_inferior_data
.get (inf
);
321 data
= ada_inferior_data
.emplace (inf
);
326 /* Perform all necessary cleanups regarding our module's inferior data
327 that is required after the inferior INF just exited. */
330 ada_inferior_exit (struct inferior
*inf
)
332 ada_inferior_data
.clear (inf
);
336 /* program-space-specific data. */
338 /* This module's per-program-space data. */
339 struct ada_pspace_data
341 /* The Ada symbol cache. */
342 std::unique_ptr
<ada_symbol_cache
> sym_cache
;
345 /* Key to our per-program-space data. */
346 static const struct program_space_key
<ada_pspace_data
> ada_pspace_data_handle
;
348 /* Return this module's data for the given program space (PSPACE).
349 If not is found, add a zero'ed one now.
351 This function always returns a valid object. */
353 static struct ada_pspace_data
*
354 get_ada_pspace_data (struct program_space
*pspace
)
356 struct ada_pspace_data
*data
;
358 data
= ada_pspace_data_handle
.get (pspace
);
360 data
= ada_pspace_data_handle
.emplace (pspace
);
367 /* If TYPE is a TYPE_CODE_TYPEDEF type, return the target type after
368 all typedef layers have been peeled. Otherwise, return TYPE.
370 Normally, we really expect a typedef type to only have 1 typedef layer.
371 In other words, we really expect the target type of a typedef type to be
372 a non-typedef type. This is particularly true for Ada units, because
373 the language does not have a typedef vs not-typedef distinction.
374 In that respect, the Ada compiler has been trying to eliminate as many
375 typedef definitions in the debugging information, since they generally
376 do not bring any extra information (we still use typedef under certain
377 circumstances related mostly to the GNAT encoding).
379 Unfortunately, we have seen situations where the debugging information
380 generated by the compiler leads to such multiple typedef layers. For
381 instance, consider the following example with stabs:
383 .stabs "pck__float_array___XUP:Tt(0,46)=s16P_ARRAY:(0,47)=[...]"[...]
384 .stabs "pck__float_array___XUP:t(0,36)=(0,46)",128,0,6,0
386 This is an error in the debugging information which causes type
387 pck__float_array___XUP to be defined twice, and the second time,
388 it is defined as a typedef of a typedef.
390 This is on the fringe of legality as far as debugging information is
391 concerned, and certainly unexpected. But it is easy to handle these
392 situations correctly, so we can afford to be lenient in this case. */
395 ada_typedef_target_type (struct type
*type
)
397 while (type
->code () == TYPE_CODE_TYPEDEF
)
398 type
= TYPE_TARGET_TYPE (type
);
402 /* Given DECODED_NAME a string holding a symbol name in its
403 decoded form (ie using the Ada dotted notation), returns
404 its unqualified name. */
407 ada_unqualified_name (const char *decoded_name
)
411 /* If the decoded name starts with '<', it means that the encoded
412 name does not follow standard naming conventions, and thus that
413 it is not your typical Ada symbol name. Trying to unqualify it
414 is therefore pointless and possibly erroneous. */
415 if (decoded_name
[0] == '<')
418 result
= strrchr (decoded_name
, '.');
420 result
++; /* Skip the dot... */
422 result
= decoded_name
;
427 /* Return a string starting with '<', followed by STR, and '>'. */
430 add_angle_brackets (const char *str
)
432 return string_printf ("<%s>", str
);
435 /* True (non-zero) iff TARGET matches FIELD_NAME up to any trailing
436 suffix of FIELD_NAME beginning "___". */
439 field_name_match (const char *field_name
, const char *target
)
441 int len
= strlen (target
);
444 (strncmp (field_name
, target
, len
) == 0
445 && (field_name
[len
] == '\0'
446 || (startswith (field_name
+ len
, "___")
447 && strcmp (field_name
+ strlen (field_name
) - 6,
452 /* Assuming TYPE is a TYPE_CODE_STRUCT or a TYPE_CODE_TYPDEF to
453 a TYPE_CODE_STRUCT, find the field whose name matches FIELD_NAME,
454 and return its index. This function also handles fields whose name
455 have ___ suffixes because the compiler sometimes alters their name
456 by adding such a suffix to represent fields with certain constraints.
457 If the field could not be found, return a negative number if
458 MAYBE_MISSING is set. Otherwise raise an error. */
461 ada_get_field_index (const struct type
*type
, const char *field_name
,
465 struct type
*struct_type
= check_typedef ((struct type
*) type
);
467 for (fieldno
= 0; fieldno
< struct_type
->num_fields (); fieldno
++)
468 if (field_name_match (struct_type
->field (fieldno
).name (), field_name
))
472 error (_("Unable to find field %s in struct %s. Aborting"),
473 field_name
, struct_type
->name ());
478 /* The length of the prefix of NAME prior to any "___" suffix. */
481 ada_name_prefix_len (const char *name
)
487 const char *p
= strstr (name
, "___");
490 return strlen (name
);
496 /* Return non-zero if SUFFIX is a suffix of STR.
497 Return zero if STR is null. */
500 is_suffix (const char *str
, const char *suffix
)
507 len2
= strlen (suffix
);
508 return (len1
>= len2
&& strcmp (str
+ len1
- len2
, suffix
) == 0);
511 /* The contents of value VAL, treated as a value of type TYPE. The
512 result is an lval in memory if VAL is. */
514 static struct value
*
515 coerce_unspec_val_to_type (struct value
*val
, struct type
*type
)
517 type
= ada_check_typedef (type
);
518 if (value_type (val
) == type
)
522 struct value
*result
;
524 if (value_optimized_out (val
))
525 result
= allocate_optimized_out_value (type
);
526 else if (value_lazy (val
)
527 /* Be careful not to make a lazy not_lval value. */
528 || (VALUE_LVAL (val
) != not_lval
529 && TYPE_LENGTH (type
) > TYPE_LENGTH (value_type (val
))))
530 result
= allocate_value_lazy (type
);
533 result
= allocate_value (type
);
534 value_contents_copy (result
, 0, val
, 0, TYPE_LENGTH (type
));
536 set_value_component_location (result
, val
);
537 set_value_bitsize (result
, value_bitsize (val
));
538 set_value_bitpos (result
, value_bitpos (val
));
539 if (VALUE_LVAL (result
) == lval_memory
)
540 set_value_address (result
, value_address (val
));
545 static const gdb_byte
*
546 cond_offset_host (const gdb_byte
*valaddr
, long offset
)
551 return valaddr
+ offset
;
555 cond_offset_target (CORE_ADDR address
, long offset
)
560 return address
+ offset
;
563 /* Issue a warning (as for the definition of warning in utils.c, but
564 with exactly one argument rather than ...), unless the limit on the
565 number of warnings has passed during the evaluation of the current
568 /* FIXME: cagney/2004-10-10: This function is mimicking the behavior
569 provided by "complaint". */
570 static void lim_warning (const char *format
, ...) ATTRIBUTE_PRINTF (1, 2);
573 lim_warning (const char *format
, ...)
577 va_start (args
, format
);
578 warnings_issued
+= 1;
579 if (warnings_issued
<= warning_limit
)
580 vwarning (format
, args
);
585 /* Maximum value of a SIZE-byte signed integer type. */
587 max_of_size (int size
)
589 LONGEST top_bit
= (LONGEST
) 1 << (size
* 8 - 2);
591 return top_bit
| (top_bit
- 1);
594 /* Minimum value of a SIZE-byte signed integer type. */
596 min_of_size (int size
)
598 return -max_of_size (size
) - 1;
601 /* Maximum value of a SIZE-byte unsigned integer type. */
603 umax_of_size (int size
)
605 ULONGEST top_bit
= (ULONGEST
) 1 << (size
* 8 - 1);
607 return top_bit
| (top_bit
- 1);
610 /* Maximum value of integral type T, as a signed quantity. */
612 max_of_type (struct type
*t
)
614 if (t
->is_unsigned ())
615 return (LONGEST
) umax_of_size (TYPE_LENGTH (t
));
617 return max_of_size (TYPE_LENGTH (t
));
620 /* Minimum value of integral type T, as a signed quantity. */
622 min_of_type (struct type
*t
)
624 if (t
->is_unsigned ())
627 return min_of_size (TYPE_LENGTH (t
));
630 /* The largest value in the domain of TYPE, a discrete type, as an integer. */
632 ada_discrete_type_high_bound (struct type
*type
)
634 type
= resolve_dynamic_type (type
, {}, 0);
635 switch (type
->code ())
637 case TYPE_CODE_RANGE
:
639 const dynamic_prop
&high
= type
->bounds ()->high
;
641 if (high
.kind () == PROP_CONST
)
642 return high
.const_val ();
645 gdb_assert (high
.kind () == PROP_UNDEFINED
);
647 /* This happens when trying to evaluate a type's dynamic bound
648 without a live target. There is nothing relevant for us to
649 return here, so return 0. */
654 return type
->field (type
->num_fields () - 1).loc_enumval ();
659 return max_of_type (type
);
661 error (_("Unexpected type in ada_discrete_type_high_bound."));
665 /* The smallest value in the domain of TYPE, a discrete type, as an integer. */
667 ada_discrete_type_low_bound (struct type
*type
)
669 type
= resolve_dynamic_type (type
, {}, 0);
670 switch (type
->code ())
672 case TYPE_CODE_RANGE
:
674 const dynamic_prop
&low
= type
->bounds ()->low
;
676 if (low
.kind () == PROP_CONST
)
677 return low
.const_val ();
680 gdb_assert (low
.kind () == PROP_UNDEFINED
);
682 /* This happens when trying to evaluate a type's dynamic bound
683 without a live target. There is nothing relevant for us to
684 return here, so return 0. */
689 return type
->field (0).loc_enumval ();
694 return min_of_type (type
);
696 error (_("Unexpected type in ada_discrete_type_low_bound."));
700 /* The identity on non-range types. For range types, the underlying
701 non-range scalar type. */
704 get_base_type (struct type
*type
)
706 while (type
!= NULL
&& type
->code () == TYPE_CODE_RANGE
)
708 if (type
== TYPE_TARGET_TYPE (type
) || TYPE_TARGET_TYPE (type
) == NULL
)
710 type
= TYPE_TARGET_TYPE (type
);
715 /* Return a decoded version of the given VALUE. This means returning
716 a value whose type is obtained by applying all the GNAT-specific
717 encodings, making the resulting type a static but standard description
718 of the initial type. */
721 ada_get_decoded_value (struct value
*value
)
723 struct type
*type
= ada_check_typedef (value_type (value
));
725 if (ada_is_array_descriptor_type (type
)
726 || (ada_is_constrained_packed_array_type (type
)
727 && type
->code () != TYPE_CODE_PTR
))
729 if (type
->code () == TYPE_CODE_TYPEDEF
) /* array access type. */
730 value
= ada_coerce_to_simple_array_ptr (value
);
732 value
= ada_coerce_to_simple_array (value
);
735 value
= ada_to_fixed_value (value
);
740 /* Same as ada_get_decoded_value, but with the given TYPE.
741 Because there is no associated actual value for this type,
742 the resulting type might be a best-effort approximation in
743 the case of dynamic types. */
746 ada_get_decoded_type (struct type
*type
)
748 type
= to_static_fixed_type (type
);
749 if (ada_is_constrained_packed_array_type (type
))
750 type
= ada_coerce_to_simple_array_type (type
);
756 /* Language Selection */
758 /* If the main program is in Ada, return language_ada, otherwise return LANG
759 (the main program is in Ada iif the adainit symbol is found). */
762 ada_update_initial_language (enum language lang
)
764 if (lookup_minimal_symbol ("adainit", NULL
, NULL
).minsym
!= NULL
)
770 /* If the main procedure is written in Ada, then return its name.
771 The result is good until the next call. Return NULL if the main
772 procedure doesn't appear to be in Ada. */
777 struct bound_minimal_symbol msym
;
778 static gdb::unique_xmalloc_ptr
<char> main_program_name
;
780 /* For Ada, the name of the main procedure is stored in a specific
781 string constant, generated by the binder. Look for that symbol,
782 extract its address, and then read that string. If we didn't find
783 that string, then most probably the main procedure is not written
785 msym
= lookup_minimal_symbol (ADA_MAIN_PROGRAM_SYMBOL_NAME
, NULL
, NULL
);
787 if (msym
.minsym
!= NULL
)
789 CORE_ADDR main_program_name_addr
= BMSYMBOL_VALUE_ADDRESS (msym
);
790 if (main_program_name_addr
== 0)
791 error (_("Invalid address for Ada main program name."));
793 main_program_name
= target_read_string (main_program_name_addr
, 1024);
794 return main_program_name
.get ();
797 /* The main procedure doesn't seem to be in Ada. */
803 /* Table of Ada operators and their GNAT-encoded names. Last entry is pair
806 const struct ada_opname_map ada_opname_table
[] = {
807 {"Oadd", "\"+\"", BINOP_ADD
},
808 {"Osubtract", "\"-\"", BINOP_SUB
},
809 {"Omultiply", "\"*\"", BINOP_MUL
},
810 {"Odivide", "\"/\"", BINOP_DIV
},
811 {"Omod", "\"mod\"", BINOP_MOD
},
812 {"Orem", "\"rem\"", BINOP_REM
},
813 {"Oexpon", "\"**\"", BINOP_EXP
},
814 {"Olt", "\"<\"", BINOP_LESS
},
815 {"Ole", "\"<=\"", BINOP_LEQ
},
816 {"Ogt", "\">\"", BINOP_GTR
},
817 {"Oge", "\">=\"", BINOP_GEQ
},
818 {"Oeq", "\"=\"", BINOP_EQUAL
},
819 {"One", "\"/=\"", BINOP_NOTEQUAL
},
820 {"Oand", "\"and\"", BINOP_BITWISE_AND
},
821 {"Oor", "\"or\"", BINOP_BITWISE_IOR
},
822 {"Oxor", "\"xor\"", BINOP_BITWISE_XOR
},
823 {"Oconcat", "\"&\"", BINOP_CONCAT
},
824 {"Oabs", "\"abs\"", UNOP_ABS
},
825 {"Onot", "\"not\"", UNOP_LOGICAL_NOT
},
826 {"Oadd", "\"+\"", UNOP_PLUS
},
827 {"Osubtract", "\"-\"", UNOP_NEG
},
831 /* If STR is a decoded version of a compiler-provided suffix (like the
832 "[cold]" in "symbol[cold]"), return true. Otherwise, return
836 is_compiler_suffix (const char *str
)
838 gdb_assert (*str
== '[');
840 while (*str
!= '\0' && isalpha (*str
))
842 /* We accept a missing "]" in order to support completion. */
843 return *str
== '\0' || (str
[0] == ']' && str
[1] == '\0');
846 /* The "encoded" form of DECODED, according to GNAT conventions. If
847 THROW_ERRORS, throw an error if invalid operator name is found.
848 Otherwise, return the empty string in that case. */
851 ada_encode_1 (const char *decoded
, bool throw_errors
)
856 std::string encoding_buffer
;
857 for (const char *p
= decoded
; *p
!= '\0'; p
+= 1)
860 encoding_buffer
.append ("__");
861 else if (*p
== '[' && is_compiler_suffix (p
))
863 encoding_buffer
= encoding_buffer
+ "." + (p
+ 1);
864 if (encoding_buffer
.back () == ']')
865 encoding_buffer
.pop_back ();
870 const struct ada_opname_map
*mapping
;
872 for (mapping
= ada_opname_table
;
873 mapping
->encoded
!= NULL
874 && !startswith (p
, mapping
->decoded
); mapping
+= 1)
876 if (mapping
->encoded
== NULL
)
879 error (_("invalid Ada operator name: %s"), p
);
883 encoding_buffer
.append (mapping
->encoded
);
887 encoding_buffer
.push_back (*p
);
890 return encoding_buffer
;
893 /* The "encoded" form of DECODED, according to GNAT conventions. */
896 ada_encode (const char *decoded
)
898 return ada_encode_1 (decoded
, true);
901 /* Return NAME folded to lower case, or, if surrounded by single
902 quotes, unfolded, but with the quotes stripped away. Result good
906 ada_fold_name (gdb::string_view name
)
908 static std::string fold_storage
;
910 if (!name
.empty () && name
[0] == '\'')
911 fold_storage
= gdb::to_string (name
.substr (1, name
.size () - 2));
914 fold_storage
= gdb::to_string (name
);
915 for (int i
= 0; i
< name
.size (); i
+= 1)
916 fold_storage
[i
] = tolower (fold_storage
[i
]);
919 return fold_storage
.c_str ();
922 /* Return nonzero if C is either a digit or a lowercase alphabet character. */
925 is_lower_alphanum (const char c
)
927 return (isdigit (c
) || (isalpha (c
) && islower (c
)));
930 /* ENCODED is the linkage name of a symbol and LEN contains its length.
931 This function saves in LEN the length of that same symbol name but
932 without either of these suffixes:
938 These are suffixes introduced by the compiler for entities such as
939 nested subprogram for instance, in order to avoid name clashes.
940 They do not serve any purpose for the debugger. */
943 ada_remove_trailing_digits (const char *encoded
, int *len
)
945 if (*len
> 1 && isdigit (encoded
[*len
- 1]))
949 while (i
> 0 && isdigit (encoded
[i
]))
951 if (i
>= 0 && encoded
[i
] == '.')
953 else if (i
>= 0 && encoded
[i
] == '$')
955 else if (i
>= 2 && startswith (encoded
+ i
- 2, "___"))
957 else if (i
>= 1 && startswith (encoded
+ i
- 1, "__"))
962 /* Remove the suffix introduced by the compiler for protected object
966 ada_remove_po_subprogram_suffix (const char *encoded
, int *len
)
968 /* Remove trailing N. */
970 /* Protected entry subprograms are broken into two
971 separate subprograms: The first one is unprotected, and has
972 a 'N' suffix; the second is the protected version, and has
973 the 'P' suffix. The second calls the first one after handling
974 the protection. Since the P subprograms are internally generated,
975 we leave these names undecoded, giving the user a clue that this
976 entity is internal. */
979 && encoded
[*len
- 1] == 'N'
980 && (isdigit (encoded
[*len
- 2]) || islower (encoded
[*len
- 2])))
984 /* If ENCODED ends with a compiler-provided suffix (like ".cold"),
985 then update *LEN to remove the suffix and return the offset of the
986 character just past the ".". Otherwise, return -1. */
989 remove_compiler_suffix (const char *encoded
, int *len
)
991 int offset
= *len
- 1;
992 while (offset
> 0 && isalpha (encoded
[offset
]))
994 if (offset
> 0 && encoded
[offset
] == '.')
1002 /* See ada-lang.h. */
1005 ada_decode (const char *encoded
, bool wrap
)
1011 std::string decoded
;
1014 /* With function descriptors on PPC64, the value of a symbol named
1015 ".FN", if it exists, is the entry point of the function "FN". */
1016 if (encoded
[0] == '.')
1019 /* The name of the Ada main procedure starts with "_ada_".
1020 This prefix is not part of the decoded name, so skip this part
1021 if we see this prefix. */
1022 if (startswith (encoded
, "_ada_"))
1025 /* If the name starts with '_', then it is not a properly encoded
1026 name, so do not attempt to decode it. Similarly, if the name
1027 starts with '<', the name should not be decoded. */
1028 if (encoded
[0] == '_' || encoded
[0] == '<')
1031 len0
= strlen (encoded
);
1033 suffix
= remove_compiler_suffix (encoded
, &len0
);
1035 ada_remove_trailing_digits (encoded
, &len0
);
1036 ada_remove_po_subprogram_suffix (encoded
, &len0
);
1038 /* Remove the ___X.* suffix if present. Do not forget to verify that
1039 the suffix is located before the current "end" of ENCODED. We want
1040 to avoid re-matching parts of ENCODED that have previously been
1041 marked as discarded (by decrementing LEN0). */
1042 p
= strstr (encoded
, "___");
1043 if (p
!= NULL
&& p
- encoded
< len0
- 3)
1051 /* Remove any trailing TKB suffix. It tells us that this symbol
1052 is for the body of a task, but that information does not actually
1053 appear in the decoded name. */
1055 if (len0
> 3 && startswith (encoded
+ len0
- 3, "TKB"))
1058 /* Remove any trailing TB suffix. The TB suffix is slightly different
1059 from the TKB suffix because it is used for non-anonymous task
1062 if (len0
> 2 && startswith (encoded
+ len0
- 2, "TB"))
1065 /* Remove trailing "B" suffixes. */
1066 /* FIXME: brobecker/2006-04-19: Not sure what this are used for... */
1068 if (len0
> 1 && startswith (encoded
+ len0
- 1, "B"))
1071 /* Make decoded big enough for possible expansion by operator name. */
1073 decoded
.resize (2 * len0
+ 1, 'X');
1075 /* Remove trailing __{digit}+ or trailing ${digit}+. */
1077 if (len0
> 1 && isdigit (encoded
[len0
- 1]))
1080 while ((i
>= 0 && isdigit (encoded
[i
]))
1081 || (i
>= 1 && encoded
[i
] == '_' && isdigit (encoded
[i
- 1])))
1083 if (i
> 1 && encoded
[i
] == '_' && encoded
[i
- 1] == '_')
1085 else if (encoded
[i
] == '$')
1089 /* The first few characters that are not alphabetic are not part
1090 of any encoding we use, so we can copy them over verbatim. */
1092 for (i
= 0, j
= 0; i
< len0
&& !isalpha (encoded
[i
]); i
+= 1, j
+= 1)
1093 decoded
[j
] = encoded
[i
];
1098 /* Is this a symbol function? */
1099 if (at_start_name
&& encoded
[i
] == 'O')
1103 for (k
= 0; ada_opname_table
[k
].encoded
!= NULL
; k
+= 1)
1105 int op_len
= strlen (ada_opname_table
[k
].encoded
);
1106 if ((strncmp (ada_opname_table
[k
].encoded
+ 1, encoded
+ i
+ 1,
1108 && !isalnum (encoded
[i
+ op_len
]))
1110 strcpy (&decoded
.front() + j
, ada_opname_table
[k
].decoded
);
1113 j
+= strlen (ada_opname_table
[k
].decoded
);
1117 if (ada_opname_table
[k
].encoded
!= NULL
)
1122 /* Replace "TK__" with "__", which will eventually be translated
1123 into "." (just below). */
1125 if (i
< len0
- 4 && startswith (encoded
+ i
, "TK__"))
1128 /* Replace "__B_{DIGITS}+__" sequences by "__", which will eventually
1129 be translated into "." (just below). These are internal names
1130 generated for anonymous blocks inside which our symbol is nested. */
1132 if (len0
- i
> 5 && encoded
[i
] == '_' && encoded
[i
+1] == '_'
1133 && encoded
[i
+2] == 'B' && encoded
[i
+3] == '_'
1134 && isdigit (encoded
[i
+4]))
1138 while (k
< len0
&& isdigit (encoded
[k
]))
1139 k
++; /* Skip any extra digit. */
1141 /* Double-check that the "__B_{DIGITS}+" sequence we found
1142 is indeed followed by "__". */
1143 if (len0
- k
> 2 && encoded
[k
] == '_' && encoded
[k
+1] == '_')
1147 /* Remove _E{DIGITS}+[sb] */
1149 /* Just as for protected object subprograms, there are 2 categories
1150 of subprograms created by the compiler for each entry. The first
1151 one implements the actual entry code, and has a suffix following
1152 the convention above; the second one implements the barrier and
1153 uses the same convention as above, except that the 'E' is replaced
1156 Just as above, we do not decode the name of barrier functions
1157 to give the user a clue that the code he is debugging has been
1158 internally generated. */
1160 if (len0
- i
> 3 && encoded
[i
] == '_' && encoded
[i
+1] == 'E'
1161 && isdigit (encoded
[i
+2]))
1165 while (k
< len0
&& isdigit (encoded
[k
]))
1169 && (encoded
[k
] == 'b' || encoded
[k
] == 's'))
1172 /* Just as an extra precaution, make sure that if this
1173 suffix is followed by anything else, it is a '_'.
1174 Otherwise, we matched this sequence by accident. */
1176 || (k
< len0
&& encoded
[k
] == '_'))
1181 /* Remove trailing "N" in [a-z0-9]+N__. The N is added by
1182 the GNAT front-end in protected object subprograms. */
1185 && encoded
[i
] == 'N' && encoded
[i
+1] == '_' && encoded
[i
+2] == '_')
1187 /* Backtrack a bit up until we reach either the begining of
1188 the encoded name, or "__". Make sure that we only find
1189 digits or lowercase characters. */
1190 const char *ptr
= encoded
+ i
- 1;
1192 while (ptr
>= encoded
&& is_lower_alphanum (ptr
[0]))
1195 || (ptr
> encoded
&& ptr
[0] == '_' && ptr
[-1] == '_'))
1199 if (encoded
[i
] == 'X' && i
!= 0 && isalnum (encoded
[i
- 1]))
1201 /* This is a X[bn]* sequence not separated from the previous
1202 part of the name with a non-alpha-numeric character (in other
1203 words, immediately following an alpha-numeric character), then
1204 verify that it is placed at the end of the encoded name. If
1205 not, then the encoding is not valid and we should abort the
1206 decoding. Otherwise, just skip it, it is used in body-nested
1210 while (i
< len0
&& (encoded
[i
] == 'b' || encoded
[i
] == 'n'));
1214 else if (i
< len0
- 2 && encoded
[i
] == '_' && encoded
[i
+ 1] == '_')
1216 /* Replace '__' by '.'. */
1224 /* It's a character part of the decoded name, so just copy it
1226 decoded
[j
] = encoded
[i
];
1233 /* Decoded names should never contain any uppercase character.
1234 Double-check this, and abort the decoding if we find one. */
1236 for (i
= 0; i
< decoded
.length(); ++i
)
1237 if (isupper (decoded
[i
]) || decoded
[i
] == ' ')
1240 /* If the compiler added a suffix, append it now. */
1242 decoded
= decoded
+ "[" + &encoded
[suffix
] + "]";
1250 if (encoded
[0] == '<')
1253 decoded
= '<' + std::string(encoded
) + '>';
1257 /* Table for keeping permanent unique copies of decoded names. Once
1258 allocated, names in this table are never released. While this is a
1259 storage leak, it should not be significant unless there are massive
1260 changes in the set of decoded names in successive versions of a
1261 symbol table loaded during a single session. */
1262 static struct htab
*decoded_names_store
;
1264 /* Returns the decoded name of GSYMBOL, as for ada_decode, caching it
1265 in the language-specific part of GSYMBOL, if it has not been
1266 previously computed. Tries to save the decoded name in the same
1267 obstack as GSYMBOL, if possible, and otherwise on the heap (so that,
1268 in any case, the decoded symbol has a lifetime at least that of
1270 The GSYMBOL parameter is "mutable" in the C++ sense: logically
1271 const, but nevertheless modified to a semantically equivalent form
1272 when a decoded name is cached in it. */
1275 ada_decode_symbol (const struct general_symbol_info
*arg
)
1277 struct general_symbol_info
*gsymbol
= (struct general_symbol_info
*) arg
;
1278 const char **resultp
=
1279 &gsymbol
->language_specific
.demangled_name
;
1281 if (!gsymbol
->ada_mangled
)
1283 std::string decoded
= ada_decode (gsymbol
->linkage_name ());
1284 struct obstack
*obstack
= gsymbol
->language_specific
.obstack
;
1286 gsymbol
->ada_mangled
= 1;
1288 if (obstack
!= NULL
)
1289 *resultp
= obstack_strdup (obstack
, decoded
.c_str ());
1292 /* Sometimes, we can't find a corresponding objfile, in
1293 which case, we put the result on the heap. Since we only
1294 decode when needed, we hope this usually does not cause a
1295 significant memory leak (FIXME). */
1297 char **slot
= (char **) htab_find_slot (decoded_names_store
,
1298 decoded
.c_str (), INSERT
);
1301 *slot
= xstrdup (decoded
.c_str ());
1313 /* Assuming that INDEX_DESC_TYPE is an ___XA structure, a structure
1314 generated by the GNAT compiler to describe the index type used
1315 for each dimension of an array, check whether it follows the latest
1316 known encoding. If not, fix it up to conform to the latest encoding.
1317 Otherwise, do nothing. This function also does nothing if
1318 INDEX_DESC_TYPE is NULL.
1320 The GNAT encoding used to describe the array index type evolved a bit.
1321 Initially, the information would be provided through the name of each
1322 field of the structure type only, while the type of these fields was
1323 described as unspecified and irrelevant. The debugger was then expected
1324 to perform a global type lookup using the name of that field in order
1325 to get access to the full index type description. Because these global
1326 lookups can be very expensive, the encoding was later enhanced to make
1327 the global lookup unnecessary by defining the field type as being
1328 the full index type description.
1330 The purpose of this routine is to allow us to support older versions
1331 of the compiler by detecting the use of the older encoding, and by
1332 fixing up the INDEX_DESC_TYPE to follow the new one (at this point,
1333 we essentially replace each field's meaningless type by the associated
1337 ada_fixup_array_indexes_type (struct type
*index_desc_type
)
1341 if (index_desc_type
== NULL
)
1343 gdb_assert (index_desc_type
->num_fields () > 0);
1345 /* Check if INDEX_DESC_TYPE follows the older encoding (it is sufficient
1346 to check one field only, no need to check them all). If not, return
1349 If our INDEX_DESC_TYPE was generated using the older encoding,
1350 the field type should be a meaningless integer type whose name
1351 is not equal to the field name. */
1352 if (index_desc_type
->field (0).type ()->name () != NULL
1353 && strcmp (index_desc_type
->field (0).type ()->name (),
1354 index_desc_type
->field (0).name ()) == 0)
1357 /* Fixup each field of INDEX_DESC_TYPE. */
1358 for (i
= 0; i
< index_desc_type
->num_fields (); i
++)
1360 const char *name
= index_desc_type
->field (i
).name ();
1361 struct type
*raw_type
= ada_check_typedef (ada_find_any_type (name
));
1364 index_desc_type
->field (i
).set_type (raw_type
);
1368 /* The desc_* routines return primitive portions of array descriptors
1371 /* The descriptor or array type, if any, indicated by TYPE; removes
1372 level of indirection, if needed. */
1374 static struct type
*
1375 desc_base_type (struct type
*type
)
1379 type
= ada_check_typedef (type
);
1380 if (type
->code () == TYPE_CODE_TYPEDEF
)
1381 type
= ada_typedef_target_type (type
);
1384 && (type
->code () == TYPE_CODE_PTR
1385 || type
->code () == TYPE_CODE_REF
))
1386 return ada_check_typedef (TYPE_TARGET_TYPE (type
));
1391 /* True iff TYPE indicates a "thin" array pointer type. */
1394 is_thin_pntr (struct type
*type
)
1397 is_suffix (ada_type_name (desc_base_type (type
)), "___XUT")
1398 || is_suffix (ada_type_name (desc_base_type (type
)), "___XUT___XVE");
1401 /* The descriptor type for thin pointer type TYPE. */
1403 static struct type
*
1404 thin_descriptor_type (struct type
*type
)
1406 struct type
*base_type
= desc_base_type (type
);
1408 if (base_type
== NULL
)
1410 if (is_suffix (ada_type_name (base_type
), "___XVE"))
1414 struct type
*alt_type
= ada_find_parallel_type (base_type
, "___XVE");
1416 if (alt_type
== NULL
)
1423 /* A pointer to the array data for thin-pointer value VAL. */
1425 static struct value
*
1426 thin_data_pntr (struct value
*val
)
1428 struct type
*type
= ada_check_typedef (value_type (val
));
1429 struct type
*data_type
= desc_data_target_type (thin_descriptor_type (type
));
1431 data_type
= lookup_pointer_type (data_type
);
1433 if (type
->code () == TYPE_CODE_PTR
)
1434 return value_cast (data_type
, value_copy (val
));
1436 return value_from_longest (data_type
, value_address (val
));
1439 /* True iff TYPE indicates a "thick" array pointer type. */
1442 is_thick_pntr (struct type
*type
)
1444 type
= desc_base_type (type
);
1445 return (type
!= NULL
&& type
->code () == TYPE_CODE_STRUCT
1446 && lookup_struct_elt_type (type
, "P_BOUNDS", 1) != NULL
);
1449 /* If TYPE is the type of an array descriptor (fat or thin pointer) or a
1450 pointer to one, the type of its bounds data; otherwise, NULL. */
1452 static struct type
*
1453 desc_bounds_type (struct type
*type
)
1457 type
= desc_base_type (type
);
1461 else if (is_thin_pntr (type
))
1463 type
= thin_descriptor_type (type
);
1466 r
= lookup_struct_elt_type (type
, "BOUNDS", 1);
1468 return ada_check_typedef (r
);
1470 else if (type
->code () == TYPE_CODE_STRUCT
)
1472 r
= lookup_struct_elt_type (type
, "P_BOUNDS", 1);
1474 return ada_check_typedef (TYPE_TARGET_TYPE (ada_check_typedef (r
)));
1479 /* If ARR is an array descriptor (fat or thin pointer), or pointer to
1480 one, a pointer to its bounds data. Otherwise NULL. */
1482 static struct value
*
1483 desc_bounds (struct value
*arr
)
1485 struct type
*type
= ada_check_typedef (value_type (arr
));
1487 if (is_thin_pntr (type
))
1489 struct type
*bounds_type
=
1490 desc_bounds_type (thin_descriptor_type (type
));
1493 if (bounds_type
== NULL
)
1494 error (_("Bad GNAT array descriptor"));
1496 /* NOTE: The following calculation is not really kosher, but
1497 since desc_type is an XVE-encoded type (and shouldn't be),
1498 the correct calculation is a real pain. FIXME (and fix GCC). */
1499 if (type
->code () == TYPE_CODE_PTR
)
1500 addr
= value_as_long (arr
);
1502 addr
= value_address (arr
);
1505 value_from_longest (lookup_pointer_type (bounds_type
),
1506 addr
- TYPE_LENGTH (bounds_type
));
1509 else if (is_thick_pntr (type
))
1511 struct value
*p_bounds
= value_struct_elt (&arr
, {}, "P_BOUNDS", NULL
,
1512 _("Bad GNAT array descriptor"));
1513 struct type
*p_bounds_type
= value_type (p_bounds
);
1516 && p_bounds_type
->code () == TYPE_CODE_PTR
)
1518 struct type
*target_type
= TYPE_TARGET_TYPE (p_bounds_type
);
1520 if (target_type
->is_stub ())
1521 p_bounds
= value_cast (lookup_pointer_type
1522 (ada_check_typedef (target_type
)),
1526 error (_("Bad GNAT array descriptor"));
1534 /* If TYPE is the type of an array-descriptor (fat pointer), the bit
1535 position of the field containing the address of the bounds data. */
1538 fat_pntr_bounds_bitpos (struct type
*type
)
1540 return desc_base_type (type
)->field (1).loc_bitpos ();
1543 /* If TYPE is the type of an array-descriptor (fat pointer), the bit
1544 size of the field containing the address of the bounds data. */
1547 fat_pntr_bounds_bitsize (struct type
*type
)
1549 type
= desc_base_type (type
);
1551 if (TYPE_FIELD_BITSIZE (type
, 1) > 0)
1552 return TYPE_FIELD_BITSIZE (type
, 1);
1554 return 8 * TYPE_LENGTH (ada_check_typedef (type
->field (1).type ()));
1557 /* If TYPE is the type of an array descriptor (fat or thin pointer) or a
1558 pointer to one, the type of its array data (a array-with-no-bounds type);
1559 otherwise, NULL. Use ada_type_of_array to get an array type with bounds
1562 static struct type
*
1563 desc_data_target_type (struct type
*type
)
1565 type
= desc_base_type (type
);
1567 /* NOTE: The following is bogus; see comment in desc_bounds. */
1568 if (is_thin_pntr (type
))
1569 return desc_base_type (thin_descriptor_type (type
)->field (1).type ());
1570 else if (is_thick_pntr (type
))
1572 struct type
*data_type
= lookup_struct_elt_type (type
, "P_ARRAY", 1);
1575 && ada_check_typedef (data_type
)->code () == TYPE_CODE_PTR
)
1576 return ada_check_typedef (TYPE_TARGET_TYPE (data_type
));
1582 /* If ARR is an array descriptor (fat or thin pointer), a pointer to
1585 static struct value
*
1586 desc_data (struct value
*arr
)
1588 struct type
*type
= value_type (arr
);
1590 if (is_thin_pntr (type
))
1591 return thin_data_pntr (arr
);
1592 else if (is_thick_pntr (type
))
1593 return value_struct_elt (&arr
, {}, "P_ARRAY", NULL
,
1594 _("Bad GNAT array descriptor"));
1600 /* If TYPE is the type of an array-descriptor (fat pointer), the bit
1601 position of the field containing the address of the data. */
1604 fat_pntr_data_bitpos (struct type
*type
)
1606 return desc_base_type (type
)->field (0).loc_bitpos ();
1609 /* If TYPE is the type of an array-descriptor (fat pointer), the bit
1610 size of the field containing the address of the data. */
1613 fat_pntr_data_bitsize (struct type
*type
)
1615 type
= desc_base_type (type
);
1617 if (TYPE_FIELD_BITSIZE (type
, 0) > 0)
1618 return TYPE_FIELD_BITSIZE (type
, 0);
1620 return TARGET_CHAR_BIT
* TYPE_LENGTH (type
->field (0).type ());
1623 /* If BOUNDS is an array-bounds structure (or pointer to one), return
1624 the Ith lower bound stored in it, if WHICH is 0, and the Ith upper
1625 bound, if WHICH is 1. The first bound is I=1. */
1627 static struct value
*
1628 desc_one_bound (struct value
*bounds
, int i
, int which
)
1630 char bound_name
[20];
1631 xsnprintf (bound_name
, sizeof (bound_name
), "%cB%d",
1632 which
? 'U' : 'L', i
- 1);
1633 return value_struct_elt (&bounds
, {}, bound_name
, NULL
,
1634 _("Bad GNAT array descriptor bounds"));
1637 /* If BOUNDS is an array-bounds structure type, return the bit position
1638 of 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. */
1642 desc_bound_bitpos (struct type
*type
, int i
, int which
)
1644 return desc_base_type (type
)->field (2 * i
+ which
- 2).loc_bitpos ();
1647 /* If BOUNDS is an array-bounds structure type, return the bit field size
1648 of the Ith lower bound stored in it, if WHICH is 0, and the Ith upper
1649 bound, if WHICH is 1. The first bound is I=1. */
1652 desc_bound_bitsize (struct type
*type
, int i
, int which
)
1654 type
= desc_base_type (type
);
1656 if (TYPE_FIELD_BITSIZE (type
, 2 * i
+ which
- 2) > 0)
1657 return TYPE_FIELD_BITSIZE (type
, 2 * i
+ which
- 2);
1659 return 8 * TYPE_LENGTH (type
->field (2 * i
+ which
- 2).type ());
1662 /* If TYPE is the type of an array-bounds structure, the type of its
1663 Ith bound (numbering from 1). Otherwise, NULL. */
1665 static struct type
*
1666 desc_index_type (struct type
*type
, int i
)
1668 type
= desc_base_type (type
);
1670 if (type
->code () == TYPE_CODE_STRUCT
)
1672 char bound_name
[20];
1673 xsnprintf (bound_name
, sizeof (bound_name
), "LB%d", i
- 1);
1674 return lookup_struct_elt_type (type
, bound_name
, 1);
1680 /* The number of index positions in the array-bounds type TYPE.
1681 Return 0 if TYPE is NULL. */
1684 desc_arity (struct type
*type
)
1686 type
= desc_base_type (type
);
1689 return type
->num_fields () / 2;
1693 /* Non-zero iff TYPE is a simple array type (not a pointer to one) or
1694 an array descriptor type (representing an unconstrained array
1698 ada_is_direct_array_type (struct type
*type
)
1702 type
= ada_check_typedef (type
);
1703 return (type
->code () == TYPE_CODE_ARRAY
1704 || ada_is_array_descriptor_type (type
));
1707 /* Non-zero iff TYPE represents any kind of array in Ada, or a pointer
1711 ada_is_array_type (struct type
*type
)
1714 && (type
->code () == TYPE_CODE_PTR
1715 || type
->code () == TYPE_CODE_REF
))
1716 type
= TYPE_TARGET_TYPE (type
);
1717 return ada_is_direct_array_type (type
);
1720 /* Non-zero iff TYPE is a simple array type or pointer to one. */
1723 ada_is_simple_array_type (struct type
*type
)
1727 type
= ada_check_typedef (type
);
1728 return (type
->code () == TYPE_CODE_ARRAY
1729 || (type
->code () == TYPE_CODE_PTR
1730 && (ada_check_typedef (TYPE_TARGET_TYPE (type
))->code ()
1731 == TYPE_CODE_ARRAY
)));
1734 /* Non-zero iff TYPE belongs to a GNAT array descriptor. */
1737 ada_is_array_descriptor_type (struct type
*type
)
1739 struct type
*data_type
= desc_data_target_type (type
);
1743 type
= ada_check_typedef (type
);
1744 return (data_type
!= NULL
1745 && data_type
->code () == TYPE_CODE_ARRAY
1746 && desc_arity (desc_bounds_type (type
)) > 0);
1749 /* Non-zero iff type is a partially mal-formed GNAT array
1750 descriptor. FIXME: This is to compensate for some problems with
1751 debugging output from GNAT. Re-examine periodically to see if it
1755 ada_is_bogus_array_descriptor (struct type
*type
)
1759 && type
->code () == TYPE_CODE_STRUCT
1760 && (lookup_struct_elt_type (type
, "P_BOUNDS", 1) != NULL
1761 || lookup_struct_elt_type (type
, "P_ARRAY", 1) != NULL
)
1762 && !ada_is_array_descriptor_type (type
);
1766 /* If ARR has a record type in the form of a standard GNAT array descriptor,
1767 (fat pointer) returns the type of the array data described---specifically,
1768 a pointer-to-array type. If BOUNDS is non-zero, the bounds data are filled
1769 in from the descriptor; otherwise, they are left unspecified. If
1770 the ARR denotes a null array descriptor and BOUNDS is non-zero,
1771 returns NULL. The result is simply the type of ARR if ARR is not
1774 static struct type
*
1775 ada_type_of_array (struct value
*arr
, int bounds
)
1777 if (ada_is_constrained_packed_array_type (value_type (arr
)))
1778 return decode_constrained_packed_array_type (value_type (arr
));
1780 if (!ada_is_array_descriptor_type (value_type (arr
)))
1781 return value_type (arr
);
1785 struct type
*array_type
=
1786 ada_check_typedef (desc_data_target_type (value_type (arr
)));
1788 if (ada_is_unconstrained_packed_array_type (value_type (arr
)))
1789 TYPE_FIELD_BITSIZE (array_type
, 0) =
1790 decode_packed_array_bitsize (value_type (arr
));
1796 struct type
*elt_type
;
1798 struct value
*descriptor
;
1800 elt_type
= ada_array_element_type (value_type (arr
), -1);
1801 arity
= ada_array_arity (value_type (arr
));
1803 if (elt_type
== NULL
|| arity
== 0)
1804 return ada_check_typedef (value_type (arr
));
1806 descriptor
= desc_bounds (arr
);
1807 if (value_as_long (descriptor
) == 0)
1811 struct type
*range_type
= alloc_type_copy (value_type (arr
));
1812 struct type
*array_type
= alloc_type_copy (value_type (arr
));
1813 struct value
*low
= desc_one_bound (descriptor
, arity
, 0);
1814 struct value
*high
= desc_one_bound (descriptor
, arity
, 1);
1817 create_static_range_type (range_type
, value_type (low
),
1818 longest_to_int (value_as_long (low
)),
1819 longest_to_int (value_as_long (high
)));
1820 elt_type
= create_array_type (array_type
, elt_type
, range_type
);
1822 if (ada_is_unconstrained_packed_array_type (value_type (arr
)))
1824 /* We need to store the element packed bitsize, as well as
1825 recompute the array size, because it was previously
1826 computed based on the unpacked element size. */
1827 LONGEST lo
= value_as_long (low
);
1828 LONGEST hi
= value_as_long (high
);
1830 TYPE_FIELD_BITSIZE (elt_type
, 0) =
1831 decode_packed_array_bitsize (value_type (arr
));
1832 /* If the array has no element, then the size is already
1833 zero, and does not need to be recomputed. */
1837 (hi
- lo
+ 1) * TYPE_FIELD_BITSIZE (elt_type
, 0);
1839 TYPE_LENGTH (array_type
) = (array_bitsize
+ 7) / 8;
1844 return lookup_pointer_type (elt_type
);
1848 /* If ARR does not represent an array, returns ARR unchanged.
1849 Otherwise, returns either a standard GDB array with bounds set
1850 appropriately or, if ARR is a non-null fat pointer, a pointer to a standard
1851 GDB array. Returns NULL if ARR is a null fat pointer. */
1854 ada_coerce_to_simple_array_ptr (struct value
*arr
)
1856 if (ada_is_array_descriptor_type (value_type (arr
)))
1858 struct type
*arrType
= ada_type_of_array (arr
, 1);
1860 if (arrType
== NULL
)
1862 return value_cast (arrType
, value_copy (desc_data (arr
)));
1864 else if (ada_is_constrained_packed_array_type (value_type (arr
)))
1865 return decode_constrained_packed_array (arr
);
1870 /* If ARR does not represent an array, returns ARR unchanged.
1871 Otherwise, returns a standard GDB array describing ARR (which may
1872 be ARR itself if it already is in the proper form). */
1875 ada_coerce_to_simple_array (struct value
*arr
)
1877 if (ada_is_array_descriptor_type (value_type (arr
)))
1879 struct value
*arrVal
= ada_coerce_to_simple_array_ptr (arr
);
1882 error (_("Bounds unavailable for null array pointer."));
1883 return value_ind (arrVal
);
1885 else if (ada_is_constrained_packed_array_type (value_type (arr
)))
1886 return decode_constrained_packed_array (arr
);
1891 /* If TYPE represents a GNAT array type, return it translated to an
1892 ordinary GDB array type (possibly with BITSIZE fields indicating
1893 packing). For other types, is the identity. */
1896 ada_coerce_to_simple_array_type (struct type
*type
)
1898 if (ada_is_constrained_packed_array_type (type
))
1899 return decode_constrained_packed_array_type (type
);
1901 if (ada_is_array_descriptor_type (type
))
1902 return ada_check_typedef (desc_data_target_type (type
));
1907 /* Non-zero iff TYPE represents a standard GNAT packed-array type. */
1910 ada_is_gnat_encoded_packed_array_type (struct type
*type
)
1914 type
= desc_base_type (type
);
1915 type
= ada_check_typedef (type
);
1917 ada_type_name (type
) != NULL
1918 && strstr (ada_type_name (type
), "___XP") != NULL
;
1921 /* Non-zero iff TYPE represents a standard GNAT constrained
1922 packed-array type. */
1925 ada_is_constrained_packed_array_type (struct type
*type
)
1927 return ada_is_gnat_encoded_packed_array_type (type
)
1928 && !ada_is_array_descriptor_type (type
);
1931 /* Non-zero iff TYPE represents an array descriptor for a
1932 unconstrained packed-array type. */
1935 ada_is_unconstrained_packed_array_type (struct type
*type
)
1937 if (!ada_is_array_descriptor_type (type
))
1940 if (ada_is_gnat_encoded_packed_array_type (type
))
1943 /* If we saw GNAT encodings, then the above code is sufficient.
1944 However, with minimal encodings, we will just have a thick
1946 if (is_thick_pntr (type
))
1948 type
= desc_base_type (type
);
1949 /* The structure's first field is a pointer to an array, so this
1950 fetches the array type. */
1951 type
= TYPE_TARGET_TYPE (type
->field (0).type ());
1952 /* Now we can see if the array elements are packed. */
1953 return TYPE_FIELD_BITSIZE (type
, 0) > 0;
1959 /* Return true if TYPE is a (Gnat-encoded) constrained packed array
1960 type, or if it is an ordinary (non-Gnat-encoded) packed array. */
1963 ada_is_any_packed_array_type (struct type
*type
)
1965 return (ada_is_constrained_packed_array_type (type
)
1966 || (type
->code () == TYPE_CODE_ARRAY
1967 && TYPE_FIELD_BITSIZE (type
, 0) % 8 != 0));
1970 /* Given that TYPE encodes a packed array type (constrained or unconstrained),
1971 return the size of its elements in bits. */
1974 decode_packed_array_bitsize (struct type
*type
)
1976 const char *raw_name
;
1980 /* Access to arrays implemented as fat pointers are encoded as a typedef
1981 of the fat pointer type. We need the name of the fat pointer type
1982 to do the decoding, so strip the typedef layer. */
1983 if (type
->code () == TYPE_CODE_TYPEDEF
)
1984 type
= ada_typedef_target_type (type
);
1986 raw_name
= ada_type_name (ada_check_typedef (type
));
1988 raw_name
= ada_type_name (desc_base_type (type
));
1993 tail
= strstr (raw_name
, "___XP");
1994 if (tail
== nullptr)
1996 gdb_assert (is_thick_pntr (type
));
1997 /* The structure's first field is a pointer to an array, so this
1998 fetches the array type. */
1999 type
= TYPE_TARGET_TYPE (type
->field (0).type ());
2000 /* Now we can see if the array elements are packed. */
2001 return TYPE_FIELD_BITSIZE (type
, 0);
2004 if (sscanf (tail
+ sizeof ("___XP") - 1, "%ld", &bits
) != 1)
2007 (_("could not understand bit size information on packed array"));
2014 /* Given that TYPE is a standard GDB array type with all bounds filled
2015 in, and that the element size of its ultimate scalar constituents
2016 (that is, either its elements, or, if it is an array of arrays, its
2017 elements' elements, etc.) is *ELT_BITS, return an identical type,
2018 but with the bit sizes of its elements (and those of any
2019 constituent arrays) recorded in the BITSIZE components of its
2020 TYPE_FIELD_BITSIZE values, and with *ELT_BITS set to its total size
2023 Note that, for arrays whose index type has an XA encoding where
2024 a bound references a record discriminant, getting that discriminant,
2025 and therefore the actual value of that bound, is not possible
2026 because none of the given parameters gives us access to the record.
2027 This function assumes that it is OK in the context where it is being
2028 used to return an array whose bounds are still dynamic and where
2029 the length is arbitrary. */
2031 static struct type
*
2032 constrained_packed_array_type (struct type
*type
, long *elt_bits
)
2034 struct type
*new_elt_type
;
2035 struct type
*new_type
;
2036 struct type
*index_type_desc
;
2037 struct type
*index_type
;
2038 LONGEST low_bound
, high_bound
;
2040 type
= ada_check_typedef (type
);
2041 if (type
->code () != TYPE_CODE_ARRAY
)
2044 index_type_desc
= ada_find_parallel_type (type
, "___XA");
2045 if (index_type_desc
)
2046 index_type
= to_fixed_range_type (index_type_desc
->field (0).type (),
2049 index_type
= type
->index_type ();
2051 new_type
= alloc_type_copy (type
);
2053 constrained_packed_array_type (ada_check_typedef (TYPE_TARGET_TYPE (type
)),
2055 create_array_type (new_type
, new_elt_type
, index_type
);
2056 TYPE_FIELD_BITSIZE (new_type
, 0) = *elt_bits
;
2057 new_type
->set_name (ada_type_name (type
));
2059 if ((check_typedef (index_type
)->code () == TYPE_CODE_RANGE
2060 && is_dynamic_type (check_typedef (index_type
)))
2061 || !get_discrete_bounds (index_type
, &low_bound
, &high_bound
))
2062 low_bound
= high_bound
= 0;
2063 if (high_bound
< low_bound
)
2064 *elt_bits
= TYPE_LENGTH (new_type
) = 0;
2067 *elt_bits
*= (high_bound
- low_bound
+ 1);
2068 TYPE_LENGTH (new_type
) =
2069 (*elt_bits
+ HOST_CHAR_BIT
- 1) / HOST_CHAR_BIT
;
2072 new_type
->set_is_fixed_instance (true);
2076 /* The array type encoded by TYPE, where
2077 ada_is_constrained_packed_array_type (TYPE). */
2079 static struct type
*
2080 decode_constrained_packed_array_type (struct type
*type
)
2082 const char *raw_name
= ada_type_name (ada_check_typedef (type
));
2085 struct type
*shadow_type
;
2089 raw_name
= ada_type_name (desc_base_type (type
));
2094 name
= (char *) alloca (strlen (raw_name
) + 1);
2095 tail
= strstr (raw_name
, "___XP");
2096 type
= desc_base_type (type
);
2098 memcpy (name
, raw_name
, tail
- raw_name
);
2099 name
[tail
- raw_name
] = '\000';
2101 shadow_type
= ada_find_parallel_type_with_name (type
, name
);
2103 if (shadow_type
== NULL
)
2105 lim_warning (_("could not find bounds information on packed array"));
2108 shadow_type
= check_typedef (shadow_type
);
2110 if (shadow_type
->code () != TYPE_CODE_ARRAY
)
2112 lim_warning (_("could not understand bounds "
2113 "information on packed array"));
2117 bits
= decode_packed_array_bitsize (type
);
2118 return constrained_packed_array_type (shadow_type
, &bits
);
2121 /* Helper function for decode_constrained_packed_array. Set the field
2122 bitsize on a series of packed arrays. Returns the number of
2123 elements in TYPE. */
2126 recursively_update_array_bitsize (struct type
*type
)
2128 gdb_assert (type
->code () == TYPE_CODE_ARRAY
);
2131 if (!get_discrete_bounds (type
->index_type (), &low
, &high
)
2134 LONGEST our_len
= high
- low
+ 1;
2136 struct type
*elt_type
= TYPE_TARGET_TYPE (type
);
2137 if (elt_type
->code () == TYPE_CODE_ARRAY
)
2139 LONGEST elt_len
= recursively_update_array_bitsize (elt_type
);
2140 LONGEST elt_bitsize
= elt_len
* TYPE_FIELD_BITSIZE (elt_type
, 0);
2141 TYPE_FIELD_BITSIZE (type
, 0) = elt_bitsize
;
2143 TYPE_LENGTH (type
) = ((our_len
* elt_bitsize
+ HOST_CHAR_BIT
- 1)
2150 /* Given that ARR is a struct value *indicating a GNAT constrained packed
2151 array, returns a simple array that denotes that array. Its type is a
2152 standard GDB array type except that the BITSIZEs of the array
2153 target types are set to the number of bits in each element, and the
2154 type length is set appropriately. */
2156 static struct value
*
2157 decode_constrained_packed_array (struct value
*arr
)
2161 /* If our value is a pointer, then dereference it. Likewise if
2162 the value is a reference. Make sure that this operation does not
2163 cause the target type to be fixed, as this would indirectly cause
2164 this array to be decoded. The rest of the routine assumes that
2165 the array hasn't been decoded yet, so we use the basic "coerce_ref"
2166 and "value_ind" routines to perform the dereferencing, as opposed
2167 to using "ada_coerce_ref" or "ada_value_ind". */
2168 arr
= coerce_ref (arr
);
2169 if (ada_check_typedef (value_type (arr
))->code () == TYPE_CODE_PTR
)
2170 arr
= value_ind (arr
);
2172 type
= decode_constrained_packed_array_type (value_type (arr
));
2175 error (_("can't unpack array"));
2179 /* Decoding the packed array type could not correctly set the field
2180 bitsizes for any dimension except the innermost, because the
2181 bounds may be variable and were not passed to that function. So,
2182 we further resolve the array bounds here and then update the
2184 const gdb_byte
*valaddr
= value_contents_for_printing (arr
).data ();
2185 CORE_ADDR address
= value_address (arr
);
2186 gdb::array_view
<const gdb_byte
> view
2187 = gdb::make_array_view (valaddr
, TYPE_LENGTH (type
));
2188 type
= resolve_dynamic_type (type
, view
, address
);
2189 recursively_update_array_bitsize (type
);
2191 if (type_byte_order (value_type (arr
)) == BFD_ENDIAN_BIG
2192 && ada_is_modular_type (value_type (arr
)))
2194 /* This is a (right-justified) modular type representing a packed
2195 array with no wrapper. In order to interpret the value through
2196 the (left-justified) packed array type we just built, we must
2197 first left-justify it. */
2198 int bit_size
, bit_pos
;
2201 mod
= ada_modulus (value_type (arr
)) - 1;
2208 bit_pos
= HOST_CHAR_BIT
* TYPE_LENGTH (value_type (arr
)) - bit_size
;
2209 arr
= ada_value_primitive_packed_val (arr
, NULL
,
2210 bit_pos
/ HOST_CHAR_BIT
,
2211 bit_pos
% HOST_CHAR_BIT
,
2216 return coerce_unspec_val_to_type (arr
, type
);
2220 /* The value of the element of packed array ARR at the ARITY indices
2221 given in IND. ARR must be a simple array. */
2223 static struct value
*
2224 value_subscript_packed (struct value
*arr
, int arity
, struct value
**ind
)
2227 int bits
, elt_off
, bit_off
;
2228 long elt_total_bit_offset
;
2229 struct type
*elt_type
;
2233 elt_total_bit_offset
= 0;
2234 elt_type
= ada_check_typedef (value_type (arr
));
2235 for (i
= 0; i
< arity
; i
+= 1)
2237 if (elt_type
->code () != TYPE_CODE_ARRAY
2238 || TYPE_FIELD_BITSIZE (elt_type
, 0) == 0)
2240 (_("attempt to do packed indexing of "
2241 "something other than a packed array"));
2244 struct type
*range_type
= elt_type
->index_type ();
2245 LONGEST lowerbound
, upperbound
;
2248 if (!get_discrete_bounds (range_type
, &lowerbound
, &upperbound
))
2250 lim_warning (_("don't know bounds of array"));
2251 lowerbound
= upperbound
= 0;
2254 idx
= pos_atr (ind
[i
]);
2255 if (idx
< lowerbound
|| idx
> upperbound
)
2256 lim_warning (_("packed array index %ld out of bounds"),
2258 bits
= TYPE_FIELD_BITSIZE (elt_type
, 0);
2259 elt_total_bit_offset
+= (idx
- lowerbound
) * bits
;
2260 elt_type
= ada_check_typedef (TYPE_TARGET_TYPE (elt_type
));
2263 elt_off
= elt_total_bit_offset
/ HOST_CHAR_BIT
;
2264 bit_off
= elt_total_bit_offset
% HOST_CHAR_BIT
;
2266 v
= ada_value_primitive_packed_val (arr
, NULL
, elt_off
, bit_off
,
2271 /* Non-zero iff TYPE includes negative integer values. */
2274 has_negatives (struct type
*type
)
2276 switch (type
->code ())
2281 return !type
->is_unsigned ();
2282 case TYPE_CODE_RANGE
:
2283 return type
->bounds ()->low
.const_val () - type
->bounds ()->bias
< 0;
2287 /* With SRC being a buffer containing BIT_SIZE bits of data at BIT_OFFSET,
2288 unpack that data into UNPACKED. UNPACKED_LEN is the size in bytes of
2289 the unpacked buffer.
2291 The size of the unpacked buffer (UNPACKED_LEN) is expected to be large
2292 enough to contain at least BIT_OFFSET bits. If not, an error is raised.
2294 IS_BIG_ENDIAN is nonzero if the data is stored in big endian mode,
2297 IS_SIGNED_TYPE is nonzero if the data corresponds to a signed type.
2299 IS_SCALAR is nonzero if the data corresponds to a signed type. */
2302 ada_unpack_from_contents (const gdb_byte
*src
, int bit_offset
, int bit_size
,
2303 gdb_byte
*unpacked
, int unpacked_len
,
2304 int is_big_endian
, int is_signed_type
,
2307 int src_len
= (bit_size
+ bit_offset
+ HOST_CHAR_BIT
- 1) / 8;
2308 int src_idx
; /* Index into the source area */
2309 int src_bytes_left
; /* Number of source bytes left to process. */
2310 int srcBitsLeft
; /* Number of source bits left to move */
2311 int unusedLS
; /* Number of bits in next significant
2312 byte of source that are unused */
2314 int unpacked_idx
; /* Index into the unpacked buffer */
2315 int unpacked_bytes_left
; /* Number of bytes left to set in unpacked. */
2317 unsigned long accum
; /* Staging area for bits being transferred */
2318 int accumSize
; /* Number of meaningful bits in accum */
2321 /* Transmit bytes from least to most significant; delta is the direction
2322 the indices move. */
2323 int delta
= is_big_endian
? -1 : 1;
2325 /* Make sure that unpacked is large enough to receive the BIT_SIZE
2327 if ((bit_size
+ HOST_CHAR_BIT
- 1) / HOST_CHAR_BIT
> unpacked_len
)
2328 error (_("Cannot unpack %d bits into buffer of %d bytes"),
2329 bit_size
, unpacked_len
);
2331 srcBitsLeft
= bit_size
;
2332 src_bytes_left
= src_len
;
2333 unpacked_bytes_left
= unpacked_len
;
2338 src_idx
= src_len
- 1;
2340 && ((src
[0] << bit_offset
) & (1 << (HOST_CHAR_BIT
- 1))))
2344 (HOST_CHAR_BIT
- (bit_size
+ bit_offset
) % HOST_CHAR_BIT
)
2350 unpacked_idx
= unpacked_len
- 1;
2354 /* Non-scalar values must be aligned at a byte boundary... */
2356 (HOST_CHAR_BIT
- bit_size
% HOST_CHAR_BIT
) % HOST_CHAR_BIT
;
2357 /* ... And are placed at the beginning (most-significant) bytes
2359 unpacked_idx
= (bit_size
+ HOST_CHAR_BIT
- 1) / HOST_CHAR_BIT
- 1;
2360 unpacked_bytes_left
= unpacked_idx
+ 1;
2365 int sign_bit_offset
= (bit_size
+ bit_offset
- 1) % 8;
2367 src_idx
= unpacked_idx
= 0;
2368 unusedLS
= bit_offset
;
2371 if (is_signed_type
&& (src
[src_len
- 1] & (1 << sign_bit_offset
)))
2376 while (src_bytes_left
> 0)
2378 /* Mask for removing bits of the next source byte that are not
2379 part of the value. */
2380 unsigned int unusedMSMask
=
2381 (1 << (srcBitsLeft
>= HOST_CHAR_BIT
? HOST_CHAR_BIT
: srcBitsLeft
)) -
2383 /* Sign-extend bits for this byte. */
2384 unsigned int signMask
= sign
& ~unusedMSMask
;
2387 (((src
[src_idx
] >> unusedLS
) & unusedMSMask
) | signMask
) << accumSize
;
2388 accumSize
+= HOST_CHAR_BIT
- unusedLS
;
2389 if (accumSize
>= HOST_CHAR_BIT
)
2391 unpacked
[unpacked_idx
] = accum
& ~(~0UL << HOST_CHAR_BIT
);
2392 accumSize
-= HOST_CHAR_BIT
;
2393 accum
>>= HOST_CHAR_BIT
;
2394 unpacked_bytes_left
-= 1;
2395 unpacked_idx
+= delta
;
2397 srcBitsLeft
-= HOST_CHAR_BIT
- unusedLS
;
2399 src_bytes_left
-= 1;
2402 while (unpacked_bytes_left
> 0)
2404 accum
|= sign
<< accumSize
;
2405 unpacked
[unpacked_idx
] = accum
& ~(~0UL << HOST_CHAR_BIT
);
2406 accumSize
-= HOST_CHAR_BIT
;
2409 accum
>>= HOST_CHAR_BIT
;
2410 unpacked_bytes_left
-= 1;
2411 unpacked_idx
+= delta
;
2415 /* Create a new value of type TYPE from the contents of OBJ starting
2416 at byte OFFSET, and bit offset BIT_OFFSET within that byte,
2417 proceeding for BIT_SIZE bits. If OBJ is an lval in memory, then
2418 assigning through the result will set the field fetched from.
2419 VALADDR is ignored unless OBJ is NULL, in which case,
2420 VALADDR+OFFSET must address the start of storage containing the
2421 packed value. The value returned in this case is never an lval.
2422 Assumes 0 <= BIT_OFFSET < HOST_CHAR_BIT. */
2425 ada_value_primitive_packed_val (struct value
*obj
, const gdb_byte
*valaddr
,
2426 long offset
, int bit_offset
, int bit_size
,
2430 const gdb_byte
*src
; /* First byte containing data to unpack */
2432 const int is_scalar
= is_scalar_type (type
);
2433 const int is_big_endian
= type_byte_order (type
) == BFD_ENDIAN_BIG
;
2434 gdb::byte_vector staging
;
2436 type
= ada_check_typedef (type
);
2439 src
= valaddr
+ offset
;
2441 src
= value_contents (obj
).data () + offset
;
2443 if (is_dynamic_type (type
))
2445 /* The length of TYPE might by dynamic, so we need to resolve
2446 TYPE in order to know its actual size, which we then use
2447 to create the contents buffer of the value we return.
2448 The difficulty is that the data containing our object is
2449 packed, and therefore maybe not at a byte boundary. So, what
2450 we do, is unpack the data into a byte-aligned buffer, and then
2451 use that buffer as our object's value for resolving the type. */
2452 int staging_len
= (bit_size
+ HOST_CHAR_BIT
- 1) / HOST_CHAR_BIT
;
2453 staging
.resize (staging_len
);
2455 ada_unpack_from_contents (src
, bit_offset
, bit_size
,
2456 staging
.data (), staging
.size (),
2457 is_big_endian
, has_negatives (type
),
2459 type
= resolve_dynamic_type (type
, staging
, 0);
2460 if (TYPE_LENGTH (type
) < (bit_size
+ HOST_CHAR_BIT
- 1) / HOST_CHAR_BIT
)
2462 /* This happens when the length of the object is dynamic,
2463 and is actually smaller than the space reserved for it.
2464 For instance, in an array of variant records, the bit_size
2465 we're given is the array stride, which is constant and
2466 normally equal to the maximum size of its element.
2467 But, in reality, each element only actually spans a portion
2469 bit_size
= TYPE_LENGTH (type
) * HOST_CHAR_BIT
;
2475 v
= allocate_value (type
);
2476 src
= valaddr
+ offset
;
2478 else if (VALUE_LVAL (obj
) == lval_memory
&& value_lazy (obj
))
2480 int src_len
= (bit_size
+ bit_offset
+ HOST_CHAR_BIT
- 1) / 8;
2483 v
= value_at (type
, value_address (obj
) + offset
);
2484 buf
= (gdb_byte
*) alloca (src_len
);
2485 read_memory (value_address (v
), buf
, src_len
);
2490 v
= allocate_value (type
);
2491 src
= value_contents (obj
).data () + offset
;
2496 long new_offset
= offset
;
2498 set_value_component_location (v
, obj
);
2499 set_value_bitpos (v
, bit_offset
+ value_bitpos (obj
));
2500 set_value_bitsize (v
, bit_size
);
2501 if (value_bitpos (v
) >= HOST_CHAR_BIT
)
2504 set_value_bitpos (v
, value_bitpos (v
) - HOST_CHAR_BIT
);
2506 set_value_offset (v
, new_offset
);
2508 /* Also set the parent value. This is needed when trying to
2509 assign a new value (in inferior memory). */
2510 set_value_parent (v
, obj
);
2513 set_value_bitsize (v
, bit_size
);
2514 unpacked
= value_contents_writeable (v
).data ();
2518 memset (unpacked
, 0, TYPE_LENGTH (type
));
2522 if (staging
.size () == TYPE_LENGTH (type
))
2524 /* Small short-cut: If we've unpacked the data into a buffer
2525 of the same size as TYPE's length, then we can reuse that,
2526 instead of doing the unpacking again. */
2527 memcpy (unpacked
, staging
.data (), staging
.size ());
2530 ada_unpack_from_contents (src
, bit_offset
, bit_size
,
2531 unpacked
, TYPE_LENGTH (type
),
2532 is_big_endian
, has_negatives (type
), is_scalar
);
2537 /* Store the contents of FROMVAL into the location of TOVAL.
2538 Return a new value with the location of TOVAL and contents of
2539 FROMVAL. Handles assignment into packed fields that have
2540 floating-point or non-scalar types. */
2542 static struct value
*
2543 ada_value_assign (struct value
*toval
, struct value
*fromval
)
2545 struct type
*type
= value_type (toval
);
2546 int bits
= value_bitsize (toval
);
2548 toval
= ada_coerce_ref (toval
);
2549 fromval
= ada_coerce_ref (fromval
);
2551 if (ada_is_direct_array_type (value_type (toval
)))
2552 toval
= ada_coerce_to_simple_array (toval
);
2553 if (ada_is_direct_array_type (value_type (fromval
)))
2554 fromval
= ada_coerce_to_simple_array (fromval
);
2556 if (!deprecated_value_modifiable (toval
))
2557 error (_("Left operand of assignment is not a modifiable lvalue."));
2559 if (VALUE_LVAL (toval
) == lval_memory
2561 && (type
->code () == TYPE_CODE_FLT
2562 || type
->code () == TYPE_CODE_STRUCT
))
2564 int len
= (value_bitpos (toval
)
2565 + bits
+ HOST_CHAR_BIT
- 1) / HOST_CHAR_BIT
;
2567 gdb_byte
*buffer
= (gdb_byte
*) alloca (len
);
2569 CORE_ADDR to_addr
= value_address (toval
);
2571 if (type
->code () == TYPE_CODE_FLT
)
2572 fromval
= value_cast (type
, fromval
);
2574 read_memory (to_addr
, buffer
, len
);
2575 from_size
= value_bitsize (fromval
);
2577 from_size
= TYPE_LENGTH (value_type (fromval
)) * TARGET_CHAR_BIT
;
2579 const int is_big_endian
= type_byte_order (type
) == BFD_ENDIAN_BIG
;
2580 ULONGEST from_offset
= 0;
2581 if (is_big_endian
&& is_scalar_type (value_type (fromval
)))
2582 from_offset
= from_size
- bits
;
2583 copy_bitwise (buffer
, value_bitpos (toval
),
2584 value_contents (fromval
).data (), from_offset
,
2585 bits
, is_big_endian
);
2586 write_memory_with_notification (to_addr
, buffer
, len
);
2588 val
= value_copy (toval
);
2589 memcpy (value_contents_raw (val
).data (),
2590 value_contents (fromval
).data (),
2591 TYPE_LENGTH (type
));
2592 deprecated_set_value_type (val
, type
);
2597 return value_assign (toval
, fromval
);
2601 /* Given that COMPONENT is a memory lvalue that is part of the lvalue
2602 CONTAINER, assign the contents of VAL to COMPONENTS's place in
2603 CONTAINER. Modifies the VALUE_CONTENTS of CONTAINER only, not
2604 COMPONENT, and not the inferior's memory. The current contents
2605 of COMPONENT are ignored.
2607 Although not part of the initial design, this function also works
2608 when CONTAINER and COMPONENT are not_lval's: it works as if CONTAINER
2609 had a null address, and COMPONENT had an address which is equal to
2610 its offset inside CONTAINER. */
2613 value_assign_to_component (struct value
*container
, struct value
*component
,
2616 LONGEST offset_in_container
=
2617 (LONGEST
) (value_address (component
) - value_address (container
));
2618 int bit_offset_in_container
=
2619 value_bitpos (component
) - value_bitpos (container
);
2622 val
= value_cast (value_type (component
), val
);
2624 if (value_bitsize (component
) == 0)
2625 bits
= TARGET_CHAR_BIT
* TYPE_LENGTH (value_type (component
));
2627 bits
= value_bitsize (component
);
2629 if (type_byte_order (value_type (container
)) == BFD_ENDIAN_BIG
)
2633 if (is_scalar_type (check_typedef (value_type (component
))))
2635 = TYPE_LENGTH (value_type (component
)) * TARGET_CHAR_BIT
- bits
;
2638 copy_bitwise ((value_contents_writeable (container
).data ()
2639 + offset_in_container
),
2640 value_bitpos (container
) + bit_offset_in_container
,
2641 value_contents (val
).data (), src_offset
, bits
, 1);
2644 copy_bitwise ((value_contents_writeable (container
).data ()
2645 + offset_in_container
),
2646 value_bitpos (container
) + bit_offset_in_container
,
2647 value_contents (val
).data (), 0, bits
, 0);
2650 /* Determine if TYPE is an access to an unconstrained array. */
2653 ada_is_access_to_unconstrained_array (struct type
*type
)
2655 return (type
->code () == TYPE_CODE_TYPEDEF
2656 && is_thick_pntr (ada_typedef_target_type (type
)));
2659 /* The value of the element of array ARR at the ARITY indices given in IND.
2660 ARR may be either a simple array, GNAT array descriptor, or pointer
2664 ada_value_subscript (struct value
*arr
, int arity
, struct value
**ind
)
2668 struct type
*elt_type
;
2670 elt
= ada_coerce_to_simple_array (arr
);
2672 elt_type
= ada_check_typedef (value_type (elt
));
2673 if (elt_type
->code () == TYPE_CODE_ARRAY
2674 && TYPE_FIELD_BITSIZE (elt_type
, 0) > 0)
2675 return value_subscript_packed (elt
, arity
, ind
);
2677 for (k
= 0; k
< arity
; k
+= 1)
2679 struct type
*saved_elt_type
= TYPE_TARGET_TYPE (elt_type
);
2681 if (elt_type
->code () != TYPE_CODE_ARRAY
)
2682 error (_("too many subscripts (%d expected)"), k
);
2684 elt
= value_subscript (elt
, pos_atr (ind
[k
]));
2686 if (ada_is_access_to_unconstrained_array (saved_elt_type
)
2687 && value_type (elt
)->code () != TYPE_CODE_TYPEDEF
)
2689 /* The element is a typedef to an unconstrained array,
2690 except that the value_subscript call stripped the
2691 typedef layer. The typedef layer is GNAT's way to
2692 specify that the element is, at the source level, an
2693 access to the unconstrained array, rather than the
2694 unconstrained array. So, we need to restore that
2695 typedef layer, which we can do by forcing the element's
2696 type back to its original type. Otherwise, the returned
2697 value is going to be printed as the array, rather
2698 than as an access. Another symptom of the same issue
2699 would be that an expression trying to dereference the
2700 element would also be improperly rejected. */
2701 deprecated_set_value_type (elt
, saved_elt_type
);
2704 elt_type
= ada_check_typedef (value_type (elt
));
2710 /* Assuming ARR is a pointer to a GDB array, the value of the element
2711 of *ARR at the ARITY indices given in IND.
2712 Does not read the entire array into memory.
2714 Note: Unlike what one would expect, this function is used instead of
2715 ada_value_subscript for basically all non-packed array types. The reason
2716 for this is that a side effect of doing our own pointer arithmetics instead
2717 of relying on value_subscript is that there is no implicit typedef peeling.
2718 This is important for arrays of array accesses, where it allows us to
2719 preserve the fact that the array's element is an array access, where the
2720 access part os encoded in a typedef layer. */
2722 static struct value
*
2723 ada_value_ptr_subscript (struct value
*arr
, int arity
, struct value
**ind
)
2726 struct value
*array_ind
= ada_value_ind (arr
);
2728 = check_typedef (value_enclosing_type (array_ind
));
2730 if (type
->code () == TYPE_CODE_ARRAY
2731 && TYPE_FIELD_BITSIZE (type
, 0) > 0)
2732 return value_subscript_packed (array_ind
, arity
, ind
);
2734 for (k
= 0; k
< arity
; k
+= 1)
2738 if (type
->code () != TYPE_CODE_ARRAY
)
2739 error (_("too many subscripts (%d expected)"), k
);
2740 arr
= value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (type
)),
2742 get_discrete_bounds (type
->index_type (), &lwb
, &upb
);
2743 arr
= value_ptradd (arr
, pos_atr (ind
[k
]) - lwb
);
2744 type
= TYPE_TARGET_TYPE (type
);
2747 return value_ind (arr
);
2750 /* Given that ARRAY_PTR is a pointer or reference to an array of type TYPE (the
2751 actual type of ARRAY_PTR is ignored), returns the Ada slice of
2752 HIGH'Pos-LOW'Pos+1 elements starting at index LOW. The lower bound of
2753 this array is LOW, as per Ada rules. */
2754 static struct value
*
2755 ada_value_slice_from_ptr (struct value
*array_ptr
, struct type
*type
,
2758 struct type
*type0
= ada_check_typedef (type
);
2759 struct type
*base_index_type
= TYPE_TARGET_TYPE (type0
->index_type ());
2760 struct type
*index_type
2761 = create_static_range_type (NULL
, base_index_type
, low
, high
);
2762 struct type
*slice_type
= create_array_type_with_stride
2763 (NULL
, TYPE_TARGET_TYPE (type0
), index_type
,
2764 type0
->dyn_prop (DYN_PROP_BYTE_STRIDE
),
2765 TYPE_FIELD_BITSIZE (type0
, 0));
2766 int base_low
= ada_discrete_type_low_bound (type0
->index_type ());
2767 gdb::optional
<LONGEST
> base_low_pos
, low_pos
;
2770 low_pos
= discrete_position (base_index_type
, low
);
2771 base_low_pos
= discrete_position (base_index_type
, base_low
);
2773 if (!low_pos
.has_value () || !base_low_pos
.has_value ())
2775 warning (_("unable to get positions in slice, use bounds instead"));
2777 base_low_pos
= base_low
;
2780 ULONGEST stride
= TYPE_FIELD_BITSIZE (slice_type
, 0) / 8;
2782 stride
= TYPE_LENGTH (TYPE_TARGET_TYPE (type0
));
2784 base
= value_as_address (array_ptr
) + (*low_pos
- *base_low_pos
) * stride
;
2785 return value_at_lazy (slice_type
, base
);
2789 static struct value
*
2790 ada_value_slice (struct value
*array
, int low
, int high
)
2792 struct type
*type
= ada_check_typedef (value_type (array
));
2793 struct type
*base_index_type
= TYPE_TARGET_TYPE (type
->index_type ());
2794 struct type
*index_type
2795 = create_static_range_type (NULL
, type
->index_type (), low
, high
);
2796 struct type
*slice_type
= create_array_type_with_stride
2797 (NULL
, TYPE_TARGET_TYPE (type
), index_type
,
2798 type
->dyn_prop (DYN_PROP_BYTE_STRIDE
),
2799 TYPE_FIELD_BITSIZE (type
, 0));
2800 gdb::optional
<LONGEST
> low_pos
, high_pos
;
2803 low_pos
= discrete_position (base_index_type
, low
);
2804 high_pos
= discrete_position (base_index_type
, high
);
2806 if (!low_pos
.has_value () || !high_pos
.has_value ())
2808 warning (_("unable to get positions in slice, use bounds instead"));
2813 return value_cast (slice_type
,
2814 value_slice (array
, low
, *high_pos
- *low_pos
+ 1));
2817 /* If type is a record type in the form of a standard GNAT array
2818 descriptor, returns the number of dimensions for type. If arr is a
2819 simple array, returns the number of "array of"s that prefix its
2820 type designation. Otherwise, returns 0. */
2823 ada_array_arity (struct type
*type
)
2830 type
= desc_base_type (type
);
2833 if (type
->code () == TYPE_CODE_STRUCT
)
2834 return desc_arity (desc_bounds_type (type
));
2836 while (type
->code () == TYPE_CODE_ARRAY
)
2839 type
= ada_check_typedef (TYPE_TARGET_TYPE (type
));
2845 /* If TYPE is a record type in the form of a standard GNAT array
2846 descriptor or a simple array type, returns the element type for
2847 TYPE after indexing by NINDICES indices, or by all indices if
2848 NINDICES is -1. Otherwise, returns NULL. */
2851 ada_array_element_type (struct type
*type
, int nindices
)
2853 type
= desc_base_type (type
);
2855 if (type
->code () == TYPE_CODE_STRUCT
)
2858 struct type
*p_array_type
;
2860 p_array_type
= desc_data_target_type (type
);
2862 k
= ada_array_arity (type
);
2866 /* Initially p_array_type = elt_type(*)[]...(k times)...[]. */
2867 if (nindices
>= 0 && k
> nindices
)
2869 while (k
> 0 && p_array_type
!= NULL
)
2871 p_array_type
= ada_check_typedef (TYPE_TARGET_TYPE (p_array_type
));
2874 return p_array_type
;
2876 else if (type
->code () == TYPE_CODE_ARRAY
)
2878 while (nindices
!= 0 && type
->code () == TYPE_CODE_ARRAY
)
2880 type
= TYPE_TARGET_TYPE (type
);
2889 /* See ada-lang.h. */
2892 ada_index_type (struct type
*type
, int n
, const char *name
)
2894 struct type
*result_type
;
2896 type
= desc_base_type (type
);
2898 if (n
< 0 || n
> ada_array_arity (type
))
2899 error (_("invalid dimension number to '%s"), name
);
2901 if (ada_is_simple_array_type (type
))
2905 for (i
= 1; i
< n
; i
+= 1)
2907 type
= ada_check_typedef (type
);
2908 type
= TYPE_TARGET_TYPE (type
);
2910 result_type
= TYPE_TARGET_TYPE (ada_check_typedef (type
)->index_type ());
2911 /* FIXME: The stabs type r(0,0);bound;bound in an array type
2912 has a target type of TYPE_CODE_UNDEF. We compensate here, but
2913 perhaps stabsread.c would make more sense. */
2914 if (result_type
&& result_type
->code () == TYPE_CODE_UNDEF
)
2919 result_type
= desc_index_type (desc_bounds_type (type
), n
);
2920 if (result_type
== NULL
)
2921 error (_("attempt to take bound of something that is not an array"));
2927 /* Given that arr is an array type, returns the lower bound of the
2928 Nth index (numbering from 1) if WHICH is 0, and the upper bound if
2929 WHICH is 1. This returns bounds 0 .. -1 if ARR_TYPE is an
2930 array-descriptor type. It works for other arrays with bounds supplied
2931 by run-time quantities other than discriminants. */
2934 ada_array_bound_from_type (struct type
*arr_type
, int n
, int which
)
2936 struct type
*type
, *index_type_desc
, *index_type
;
2939 gdb_assert (which
== 0 || which
== 1);
2941 if (ada_is_constrained_packed_array_type (arr_type
))
2942 arr_type
= decode_constrained_packed_array_type (arr_type
);
2944 if (arr_type
== NULL
|| !ada_is_simple_array_type (arr_type
))
2945 return (LONGEST
) - which
;
2947 if (arr_type
->code () == TYPE_CODE_PTR
)
2948 type
= TYPE_TARGET_TYPE (arr_type
);
2952 if (type
->is_fixed_instance ())
2954 /* The array has already been fixed, so we do not need to
2955 check the parallel ___XA type again. That encoding has
2956 already been applied, so ignore it now. */
2957 index_type_desc
= NULL
;
2961 index_type_desc
= ada_find_parallel_type (type
, "___XA");
2962 ada_fixup_array_indexes_type (index_type_desc
);
2965 if (index_type_desc
!= NULL
)
2966 index_type
= to_fixed_range_type (index_type_desc
->field (n
- 1).type (),
2970 struct type
*elt_type
= check_typedef (type
);
2972 for (i
= 1; i
< n
; i
++)
2973 elt_type
= check_typedef (TYPE_TARGET_TYPE (elt_type
));
2975 index_type
= elt_type
->index_type ();
2979 (LONGEST
) (which
== 0
2980 ? ada_discrete_type_low_bound (index_type
)
2981 : ada_discrete_type_high_bound (index_type
));
2984 /* Given that arr is an array value, returns the lower bound of the
2985 nth index (numbering from 1) if WHICH is 0, and the upper bound if
2986 WHICH is 1. This routine will also work for arrays with bounds
2987 supplied by run-time quantities other than discriminants. */
2990 ada_array_bound (struct value
*arr
, int n
, int which
)
2992 struct type
*arr_type
;
2994 if (check_typedef (value_type (arr
))->code () == TYPE_CODE_PTR
)
2995 arr
= value_ind (arr
);
2996 arr_type
= value_enclosing_type (arr
);
2998 if (ada_is_constrained_packed_array_type (arr_type
))
2999 return ada_array_bound (decode_constrained_packed_array (arr
), n
, which
);
3000 else if (ada_is_simple_array_type (arr_type
))
3001 return ada_array_bound_from_type (arr_type
, n
, which
);
3003 return value_as_long (desc_one_bound (desc_bounds (arr
), n
, which
));
3006 /* Given that arr is an array value, returns the length of the
3007 nth index. This routine will also work for arrays with bounds
3008 supplied by run-time quantities other than discriminants.
3009 Does not work for arrays indexed by enumeration types with representation
3010 clauses at the moment. */
3013 ada_array_length (struct value
*arr
, int n
)
3015 struct type
*arr_type
, *index_type
;
3018 if (check_typedef (value_type (arr
))->code () == TYPE_CODE_PTR
)
3019 arr
= value_ind (arr
);
3020 arr_type
= value_enclosing_type (arr
);
3022 if (ada_is_constrained_packed_array_type (arr_type
))
3023 return ada_array_length (decode_constrained_packed_array (arr
), n
);
3025 if (ada_is_simple_array_type (arr_type
))
3027 low
= ada_array_bound_from_type (arr_type
, n
, 0);
3028 high
= ada_array_bound_from_type (arr_type
, n
, 1);
3032 low
= value_as_long (desc_one_bound (desc_bounds (arr
), n
, 0));
3033 high
= value_as_long (desc_one_bound (desc_bounds (arr
), n
, 1));
3036 arr_type
= check_typedef (arr_type
);
3037 index_type
= ada_index_type (arr_type
, n
, "length");
3038 if (index_type
!= NULL
)
3040 struct type
*base_type
;
3041 if (index_type
->code () == TYPE_CODE_RANGE
)
3042 base_type
= TYPE_TARGET_TYPE (index_type
);
3044 base_type
= index_type
;
3046 low
= pos_atr (value_from_longest (base_type
, low
));
3047 high
= pos_atr (value_from_longest (base_type
, high
));
3049 return high
- low
+ 1;
3052 /* An array whose type is that of ARR_TYPE (an array type), with
3053 bounds LOW to HIGH, but whose contents are unimportant. If HIGH is
3054 less than LOW, then LOW-1 is used. */
3056 static struct value
*
3057 empty_array (struct type
*arr_type
, int low
, int high
)
3059 struct type
*arr_type0
= ada_check_typedef (arr_type
);
3060 struct type
*index_type
3061 = create_static_range_type
3062 (NULL
, TYPE_TARGET_TYPE (arr_type0
->index_type ()), low
,
3063 high
< low
? low
- 1 : high
);
3064 struct type
*elt_type
= ada_array_element_type (arr_type0
, 1);
3066 return allocate_value (create_array_type (NULL
, elt_type
, index_type
));
3070 /* Name resolution */
3072 /* The "decoded" name for the user-definable Ada operator corresponding
3076 ada_decoded_op_name (enum exp_opcode op
)
3080 for (i
= 0; ada_opname_table
[i
].encoded
!= NULL
; i
+= 1)
3082 if (ada_opname_table
[i
].op
== op
)
3083 return ada_opname_table
[i
].decoded
;
3085 error (_("Could not find operator name for opcode"));
3088 /* Returns true (non-zero) iff decoded name N0 should appear before N1
3089 in a listing of choices during disambiguation (see sort_choices, below).
3090 The idea is that overloadings of a subprogram name from the
3091 same package should sort in their source order. We settle for ordering
3092 such symbols by their trailing number (__N or $N). */
3095 encoded_ordered_before (const char *N0
, const char *N1
)
3099 else if (N0
== NULL
)
3105 for (k0
= strlen (N0
) - 1; k0
> 0 && isdigit (N0
[k0
]); k0
-= 1)
3107 for (k1
= strlen (N1
) - 1; k1
> 0 && isdigit (N1
[k1
]); k1
-= 1)
3109 if ((N0
[k0
] == '_' || N0
[k0
] == '$') && N0
[k0
+ 1] != '\000'
3110 && (N1
[k1
] == '_' || N1
[k1
] == '$') && N1
[k1
+ 1] != '\000')
3115 while (N0
[n0
] == '_' && n0
> 0 && N0
[n0
- 1] == '_')
3118 while (N1
[n1
] == '_' && n1
> 0 && N1
[n1
- 1] == '_')
3120 if (n0
== n1
&& strncmp (N0
, N1
, n0
) == 0)
3121 return (atoi (N0
+ k0
+ 1) < atoi (N1
+ k1
+ 1));
3123 return (strcmp (N0
, N1
) < 0);
3127 /* Sort SYMS[0..NSYMS-1] to put the choices in a canonical order by the
3131 sort_choices (struct block_symbol syms
[], int nsyms
)
3135 for (i
= 1; i
< nsyms
; i
+= 1)
3137 struct block_symbol sym
= syms
[i
];
3140 for (j
= i
- 1; j
>= 0; j
-= 1)
3142 if (encoded_ordered_before (syms
[j
].symbol
->linkage_name (),
3143 sym
.symbol
->linkage_name ()))
3145 syms
[j
+ 1] = syms
[j
];
3151 /* Whether GDB should display formals and return types for functions in the
3152 overloads selection menu. */
3153 static bool print_signatures
= true;
3155 /* Print the signature for SYM on STREAM according to the FLAGS options. For
3156 all but functions, the signature is just the name of the symbol. For
3157 functions, this is the name of the function, the list of types for formals
3158 and the return type (if any). */
3161 ada_print_symbol_signature (struct ui_file
*stream
, struct symbol
*sym
,
3162 const struct type_print_options
*flags
)
3164 struct type
*type
= SYMBOL_TYPE (sym
);
3166 fprintf_filtered (stream
, "%s", sym
->print_name ());
3167 if (!print_signatures
3169 || type
->code () != TYPE_CODE_FUNC
)
3172 if (type
->num_fields () > 0)
3176 fprintf_filtered (stream
, " (");
3177 for (i
= 0; i
< type
->num_fields (); ++i
)
3180 fprintf_filtered (stream
, "; ");
3181 ada_print_type (type
->field (i
).type (), NULL
, stream
, -1, 0,
3184 fprintf_filtered (stream
, ")");
3186 if (TYPE_TARGET_TYPE (type
) != NULL
3187 && TYPE_TARGET_TYPE (type
)->code () != TYPE_CODE_VOID
)
3189 fprintf_filtered (stream
, " return ");
3190 ada_print_type (TYPE_TARGET_TYPE (type
), NULL
, stream
, -1, 0, flags
);
3194 /* Read and validate a set of numeric choices from the user in the
3195 range 0 .. N_CHOICES-1. Place the results in increasing
3196 order in CHOICES[0 .. N-1], and return N.
3198 The user types choices as a sequence of numbers on one line
3199 separated by blanks, encoding them as follows:
3201 + A choice of 0 means to cancel the selection, throwing an error.
3202 + If IS_ALL_CHOICE, a choice of 1 selects the entire set 0 .. N_CHOICES-1.
3203 + The user chooses k by typing k+IS_ALL_CHOICE+1.
3205 The user is not allowed to choose more than MAX_RESULTS values.
3207 ANNOTATION_SUFFIX, if present, is used to annotate the input
3208 prompts (for use with the -f switch). */
3211 get_selections (int *choices
, int n_choices
, int max_results
,
3212 int is_all_choice
, const char *annotation_suffix
)
3217 int first_choice
= is_all_choice
? 2 : 1;
3219 prompt
= getenv ("PS2");
3223 args
= command_line_input (prompt
, annotation_suffix
);
3226 error_no_arg (_("one or more choice numbers"));
3230 /* Set choices[0 .. n_chosen-1] to the users' choices in ascending
3231 order, as given in args. Choices are validated. */
3237 args
= skip_spaces (args
);
3238 if (*args
== '\0' && n_chosen
== 0)
3239 error_no_arg (_("one or more choice numbers"));
3240 else if (*args
== '\0')
3243 choice
= strtol (args
, &args2
, 10);
3244 if (args
== args2
|| choice
< 0
3245 || choice
> n_choices
+ first_choice
- 1)
3246 error (_("Argument must be choice number"));
3250 error (_("cancelled"));
3252 if (choice
< first_choice
)
3254 n_chosen
= n_choices
;
3255 for (j
= 0; j
< n_choices
; j
+= 1)
3259 choice
-= first_choice
;
3261 for (j
= n_chosen
- 1; j
>= 0 && choice
< choices
[j
]; j
-= 1)
3265 if (j
< 0 || choice
!= choices
[j
])
3269 for (k
= n_chosen
- 1; k
> j
; k
-= 1)
3270 choices
[k
+ 1] = choices
[k
];
3271 choices
[j
+ 1] = choice
;
3276 if (n_chosen
> max_results
)
3277 error (_("Select no more than %d of the above"), max_results
);
3282 /* Given a list of NSYMS symbols in SYMS, select up to MAX_RESULTS>0
3283 by asking the user (if necessary), returning the number selected,
3284 and setting the first elements of SYMS items. Error if no symbols
3287 /* NOTE: Adapted from decode_line_2 in symtab.c, with which it ought
3288 to be re-integrated one of these days. */
3291 user_select_syms (struct block_symbol
*syms
, int nsyms
, int max_results
)
3294 int *chosen
= XALLOCAVEC (int , nsyms
);
3296 int first_choice
= (max_results
== 1) ? 1 : 2;
3297 const char *select_mode
= multiple_symbols_select_mode ();
3299 if (max_results
< 1)
3300 error (_("Request to select 0 symbols!"));
3304 if (select_mode
== multiple_symbols_cancel
)
3306 canceled because the command is ambiguous\n\
3307 See set/show multiple-symbol."));
3309 /* If select_mode is "all", then return all possible symbols.
3310 Only do that if more than one symbol can be selected, of course.
3311 Otherwise, display the menu as usual. */
3312 if (select_mode
== multiple_symbols_all
&& max_results
> 1)
3315 printf_filtered (_("[0] cancel\n"));
3316 if (max_results
> 1)
3317 printf_filtered (_("[1] all\n"));
3319 sort_choices (syms
, nsyms
);
3321 for (i
= 0; i
< nsyms
; i
+= 1)
3323 if (syms
[i
].symbol
== NULL
)
3326 if (SYMBOL_CLASS (syms
[i
].symbol
) == LOC_BLOCK
)
3328 struct symtab_and_line sal
=
3329 find_function_start_sal (syms
[i
].symbol
, 1);
3331 printf_filtered ("[%d] ", i
+ first_choice
);
3332 ada_print_symbol_signature (gdb_stdout
, syms
[i
].symbol
,
3333 &type_print_raw_options
);
3334 if (sal
.symtab
== NULL
)
3335 printf_filtered (_(" at %p[<no source file available>%p]:%d\n"),
3336 metadata_style
.style ().ptr (), nullptr, sal
.line
);
3340 styled_string (file_name_style
.style (),
3341 symtab_to_filename_for_display (sal
.symtab
)),
3348 (SYMBOL_CLASS (syms
[i
].symbol
) == LOC_CONST
3349 && SYMBOL_TYPE (syms
[i
].symbol
) != NULL
3350 && SYMBOL_TYPE (syms
[i
].symbol
)->code () == TYPE_CODE_ENUM
);
3351 struct symtab
*symtab
= NULL
;
3353 if (SYMBOL_OBJFILE_OWNED (syms
[i
].symbol
))
3354 symtab
= symbol_symtab (syms
[i
].symbol
);
3356 if (SYMBOL_LINE (syms
[i
].symbol
) != 0 && symtab
!= NULL
)
3358 printf_filtered ("[%d] ", i
+ first_choice
);
3359 ada_print_symbol_signature (gdb_stdout
, syms
[i
].symbol
,
3360 &type_print_raw_options
);
3361 printf_filtered (_(" at %s:%d\n"),
3362 symtab_to_filename_for_display (symtab
),
3363 SYMBOL_LINE (syms
[i
].symbol
));
3365 else if (is_enumeral
3366 && SYMBOL_TYPE (syms
[i
].symbol
)->name () != NULL
)
3368 printf_filtered (("[%d] "), i
+ first_choice
);
3369 ada_print_type (SYMBOL_TYPE (syms
[i
].symbol
), NULL
,
3370 gdb_stdout
, -1, 0, &type_print_raw_options
);
3371 printf_filtered (_("'(%s) (enumeral)\n"),
3372 syms
[i
].symbol
->print_name ());
3376 printf_filtered ("[%d] ", i
+ first_choice
);
3377 ada_print_symbol_signature (gdb_stdout
, syms
[i
].symbol
,
3378 &type_print_raw_options
);
3381 printf_filtered (is_enumeral
3382 ? _(" in %s (enumeral)\n")
3384 symtab_to_filename_for_display (symtab
));
3386 printf_filtered (is_enumeral
3387 ? _(" (enumeral)\n")
3393 n_chosen
= get_selections (chosen
, nsyms
, max_results
, max_results
> 1,
3396 for (i
= 0; i
< n_chosen
; i
+= 1)
3397 syms
[i
] = syms
[chosen
[i
]];
3402 /* See ada-lang.h. */
3405 ada_find_operator_symbol (enum exp_opcode op
, bool parse_completion
,
3406 int nargs
, value
*argvec
[])
3408 if (possible_user_operator_p (op
, argvec
))
3410 std::vector
<struct block_symbol
> candidates
3411 = ada_lookup_symbol_list (ada_decoded_op_name (op
),
3414 int i
= ada_resolve_function (candidates
, argvec
,
3415 nargs
, ada_decoded_op_name (op
), NULL
,
3418 return candidates
[i
];
3423 /* See ada-lang.h. */
3426 ada_resolve_funcall (struct symbol
*sym
, const struct block
*block
,
3427 struct type
*context_type
,
3428 bool parse_completion
,
3429 int nargs
, value
*argvec
[],
3430 innermost_block_tracker
*tracker
)
3432 std::vector
<struct block_symbol
> candidates
3433 = ada_lookup_symbol_list (sym
->linkage_name (), block
, VAR_DOMAIN
);
3436 if (candidates
.size () == 1)
3440 i
= ada_resolve_function
3443 sym
->linkage_name (),
3444 context_type
, parse_completion
);
3446 error (_("Could not find a match for %s"), sym
->print_name ());
3449 tracker
->update (candidates
[i
]);
3450 return candidates
[i
];
3453 /* Resolve a mention of a name where the context type is an
3454 enumeration type. */
3457 ada_resolve_enum (std::vector
<struct block_symbol
> &syms
,
3458 const char *name
, struct type
*context_type
,
3459 bool parse_completion
)
3461 gdb_assert (context_type
->code () == TYPE_CODE_ENUM
);
3462 context_type
= ada_check_typedef (context_type
);
3464 for (int i
= 0; i
< syms
.size (); ++i
)
3466 /* We already know the name matches, so we're just looking for
3467 an element of the correct enum type. */
3468 if (ada_check_typedef (SYMBOL_TYPE (syms
[i
].symbol
)) == context_type
)
3472 error (_("No name '%s' in enumeration type '%s'"), name
,
3473 ada_type_name (context_type
));
3476 /* See ada-lang.h. */
3479 ada_resolve_variable (struct symbol
*sym
, const struct block
*block
,
3480 struct type
*context_type
,
3481 bool parse_completion
,
3483 innermost_block_tracker
*tracker
)
3485 std::vector
<struct block_symbol
> candidates
3486 = ada_lookup_symbol_list (sym
->linkage_name (), block
, VAR_DOMAIN
);
3488 if (std::any_of (candidates
.begin (),
3490 [] (block_symbol
&bsym
)
3492 switch (SYMBOL_CLASS (bsym
.symbol
))
3497 case LOC_REGPARM_ADDR
:
3506 /* Types tend to get re-introduced locally, so if there
3507 are any local symbols that are not types, first filter
3511 (candidates
.begin (),
3513 [] (block_symbol
&bsym
)
3515 return SYMBOL_CLASS (bsym
.symbol
) == LOC_TYPEDEF
;
3520 /* Filter out artificial symbols. */
3523 (candidates
.begin (),
3525 [] (block_symbol
&bsym
)
3527 return bsym
.symbol
->artificial
;
3532 if (candidates
.empty ())
3533 error (_("No definition found for %s"), sym
->print_name ());
3534 else if (candidates
.size () == 1)
3536 else if (context_type
!= nullptr
3537 && context_type
->code () == TYPE_CODE_ENUM
)
3538 i
= ada_resolve_enum (candidates
, sym
->linkage_name (), context_type
,
3540 else if (deprocedure_p
&& !is_nonfunction (candidates
))
3542 i
= ada_resolve_function
3543 (candidates
, NULL
, 0,
3544 sym
->linkage_name (),
3545 context_type
, parse_completion
);
3547 error (_("Could not find a match for %s"), sym
->print_name ());
3551 printf_filtered (_("Multiple matches for %s\n"), sym
->print_name ());
3552 user_select_syms (candidates
.data (), candidates
.size (), 1);
3556 tracker
->update (candidates
[i
]);
3557 return candidates
[i
];
3560 /* Return non-zero if formal type FTYPE matches actual type ATYPE. */
3561 /* The term "match" here is rather loose. The match is heuristic and
3565 ada_type_match (struct type
*ftype
, struct type
*atype
)
3567 ftype
= ada_check_typedef (ftype
);
3568 atype
= ada_check_typedef (atype
);
3570 if (ftype
->code () == TYPE_CODE_REF
)
3571 ftype
= TYPE_TARGET_TYPE (ftype
);
3572 if (atype
->code () == TYPE_CODE_REF
)
3573 atype
= TYPE_TARGET_TYPE (atype
);
3575 switch (ftype
->code ())
3578 return ftype
->code () == atype
->code ();
3580 if (atype
->code () != TYPE_CODE_PTR
)
3582 atype
= TYPE_TARGET_TYPE (atype
);
3583 /* This can only happen if the actual argument is 'null'. */
3584 if (atype
->code () == TYPE_CODE_INT
&& TYPE_LENGTH (atype
) == 0)
3586 return ada_type_match (TYPE_TARGET_TYPE (ftype
), atype
);
3588 case TYPE_CODE_ENUM
:
3589 case TYPE_CODE_RANGE
:
3590 switch (atype
->code ())
3593 case TYPE_CODE_ENUM
:
3594 case TYPE_CODE_RANGE
:
3600 case TYPE_CODE_ARRAY
:
3601 return (atype
->code () == TYPE_CODE_ARRAY
3602 || ada_is_array_descriptor_type (atype
));
3604 case TYPE_CODE_STRUCT
:
3605 if (ada_is_array_descriptor_type (ftype
))
3606 return (atype
->code () == TYPE_CODE_ARRAY
3607 || ada_is_array_descriptor_type (atype
));
3609 return (atype
->code () == TYPE_CODE_STRUCT
3610 && !ada_is_array_descriptor_type (atype
));
3612 case TYPE_CODE_UNION
:
3614 return (atype
->code () == ftype
->code ());
3618 /* Return non-zero if the formals of FUNC "sufficiently match" the
3619 vector of actual argument types ACTUALS of size N_ACTUALS. FUNC
3620 may also be an enumeral, in which case it is treated as a 0-
3621 argument function. */
3624 ada_args_match (struct symbol
*func
, struct value
**actuals
, int n_actuals
)
3627 struct type
*func_type
= SYMBOL_TYPE (func
);
3629 if (SYMBOL_CLASS (func
) == LOC_CONST
3630 && func_type
->code () == TYPE_CODE_ENUM
)
3631 return (n_actuals
== 0);
3632 else if (func_type
== NULL
|| func_type
->code () != TYPE_CODE_FUNC
)
3635 if (func_type
->num_fields () != n_actuals
)
3638 for (i
= 0; i
< n_actuals
; i
+= 1)
3640 if (actuals
[i
] == NULL
)
3644 struct type
*ftype
= ada_check_typedef (func_type
->field (i
).type ());
3645 struct type
*atype
= ada_check_typedef (value_type (actuals
[i
]));
3647 if (!ada_type_match (ftype
, atype
))
3654 /* False iff function type FUNC_TYPE definitely does not produce a value
3655 compatible with type CONTEXT_TYPE. Conservatively returns 1 if
3656 FUNC_TYPE is not a valid function type with a non-null return type
3657 or an enumerated type. A null CONTEXT_TYPE indicates any non-void type. */
3660 return_match (struct type
*func_type
, struct type
*context_type
)
3662 struct type
*return_type
;
3664 if (func_type
== NULL
)
3667 if (func_type
->code () == TYPE_CODE_FUNC
)
3668 return_type
= get_base_type (TYPE_TARGET_TYPE (func_type
));
3670 return_type
= get_base_type (func_type
);
3671 if (return_type
== NULL
)
3674 context_type
= get_base_type (context_type
);
3676 if (return_type
->code () == TYPE_CODE_ENUM
)
3677 return context_type
== NULL
|| return_type
== context_type
;
3678 else if (context_type
== NULL
)
3679 return return_type
->code () != TYPE_CODE_VOID
;
3681 return return_type
->code () == context_type
->code ();
3685 /* Returns the index in SYMS that contains the symbol for the
3686 function (if any) that matches the types of the NARGS arguments in
3687 ARGS. If CONTEXT_TYPE is non-null and there is at least one match
3688 that returns that type, then eliminate matches that don't. If
3689 CONTEXT_TYPE is void and there is at least one match that does not
3690 return void, eliminate all matches that do.
3692 Asks the user if there is more than one match remaining. Returns -1
3693 if there is no such symbol or none is selected. NAME is used
3694 solely for messages. May re-arrange and modify SYMS in
3695 the process; the index returned is for the modified vector. */
3698 ada_resolve_function (std::vector
<struct block_symbol
> &syms
,
3699 struct value
**args
, int nargs
,
3700 const char *name
, struct type
*context_type
,
3701 bool parse_completion
)
3705 int m
; /* Number of hits */
3708 /* In the first pass of the loop, we only accept functions matching
3709 context_type. If none are found, we add a second pass of the loop
3710 where every function is accepted. */
3711 for (fallback
= 0; m
== 0 && fallback
< 2; fallback
++)
3713 for (k
= 0; k
< syms
.size (); k
+= 1)
3715 struct type
*type
= ada_check_typedef (SYMBOL_TYPE (syms
[k
].symbol
));
3717 if (ada_args_match (syms
[k
].symbol
, args
, nargs
)
3718 && (fallback
|| return_match (type
, context_type
)))
3726 /* If we got multiple matches, ask the user which one to use. Don't do this
3727 interactive thing during completion, though, as the purpose of the
3728 completion is providing a list of all possible matches. Prompting the
3729 user to filter it down would be completely unexpected in this case. */
3732 else if (m
> 1 && !parse_completion
)
3734 printf_filtered (_("Multiple matches for %s\n"), name
);
3735 user_select_syms (syms
.data (), m
, 1);
3741 /* Type-class predicates */
3743 /* True iff TYPE is numeric (i.e., an INT, RANGE (of numeric type),
3747 numeric_type_p (struct type
*type
)
3753 switch (type
->code ())
3757 case TYPE_CODE_FIXED_POINT
:
3759 case TYPE_CODE_RANGE
:
3760 return (type
== TYPE_TARGET_TYPE (type
)
3761 || numeric_type_p (TYPE_TARGET_TYPE (type
)));
3768 /* True iff TYPE is integral (an INT or RANGE of INTs). */
3771 integer_type_p (struct type
*type
)
3777 switch (type
->code ())
3781 case TYPE_CODE_RANGE
:
3782 return (type
== TYPE_TARGET_TYPE (type
)
3783 || integer_type_p (TYPE_TARGET_TYPE (type
)));
3790 /* True iff TYPE is scalar (INT, RANGE, FLOAT, ENUM). */
3793 scalar_type_p (struct type
*type
)
3799 switch (type
->code ())
3802 case TYPE_CODE_RANGE
:
3803 case TYPE_CODE_ENUM
:
3805 case TYPE_CODE_FIXED_POINT
:
3813 /* True iff TYPE is discrete (INT, RANGE, ENUM). */
3816 discrete_type_p (struct type
*type
)
3822 switch (type
->code ())
3825 case TYPE_CODE_RANGE
:
3826 case TYPE_CODE_ENUM
:
3827 case TYPE_CODE_BOOL
:
3835 /* Returns non-zero if OP with operands in the vector ARGS could be
3836 a user-defined function. Errs on the side of pre-defined operators
3837 (i.e., result 0). */
3840 possible_user_operator_p (enum exp_opcode op
, struct value
*args
[])
3842 struct type
*type0
=
3843 (args
[0] == NULL
) ? NULL
: ada_check_typedef (value_type (args
[0]));
3844 struct type
*type1
=
3845 (args
[1] == NULL
) ? NULL
: ada_check_typedef (value_type (args
[1]));
3859 return (!(numeric_type_p (type0
) && numeric_type_p (type1
)));
3863 case BINOP_BITWISE_AND
:
3864 case BINOP_BITWISE_IOR
:
3865 case BINOP_BITWISE_XOR
:
3866 return (!(integer_type_p (type0
) && integer_type_p (type1
)));
3869 case BINOP_NOTEQUAL
:
3874 return (!(scalar_type_p (type0
) && scalar_type_p (type1
)));
3877 return !ada_is_array_type (type0
) || !ada_is_array_type (type1
);
3880 return (!(numeric_type_p (type0
) && integer_type_p (type1
)));
3884 case UNOP_LOGICAL_NOT
:
3886 return (!numeric_type_p (type0
));
3895 1. In the following, we assume that a renaming type's name may
3896 have an ___XD suffix. It would be nice if this went away at some
3898 2. We handle both the (old) purely type-based representation of
3899 renamings and the (new) variable-based encoding. At some point,
3900 it is devoutly to be hoped that the former goes away
3901 (FIXME: hilfinger-2007-07-09).
3902 3. Subprogram renamings are not implemented, although the XRS
3903 suffix is recognized (FIXME: hilfinger-2007-07-09). */
3905 /* If SYM encodes a renaming,
3907 <renaming> renames <renamed entity>,
3909 sets *LEN to the length of the renamed entity's name,
3910 *RENAMED_ENTITY to that name (not null-terminated), and *RENAMING_EXPR to
3911 the string describing the subcomponent selected from the renamed
3912 entity. Returns ADA_NOT_RENAMING if SYM does not encode a renaming
3913 (in which case, the values of *RENAMED_ENTITY, *LEN, and *RENAMING_EXPR
3914 are undefined). Otherwise, returns a value indicating the category
3915 of entity renamed: an object (ADA_OBJECT_RENAMING), exception
3916 (ADA_EXCEPTION_RENAMING), package (ADA_PACKAGE_RENAMING), or
3917 subprogram (ADA_SUBPROGRAM_RENAMING). Does no allocation; the
3918 strings returned in *RENAMED_ENTITY and *RENAMING_EXPR should not be
3919 deallocated. The values of RENAMED_ENTITY, LEN, or RENAMING_EXPR
3920 may be NULL, in which case they are not assigned.
3922 [Currently, however, GCC does not generate subprogram renamings.] */
3924 enum ada_renaming_category
3925 ada_parse_renaming (struct symbol
*sym
,
3926 const char **renamed_entity
, int *len
,
3927 const char **renaming_expr
)
3929 enum ada_renaming_category kind
;
3934 return ADA_NOT_RENAMING
;
3935 switch (SYMBOL_CLASS (sym
))
3938 return ADA_NOT_RENAMING
;
3942 case LOC_OPTIMIZED_OUT
:
3943 info
= strstr (sym
->linkage_name (), "___XR");
3945 return ADA_NOT_RENAMING
;
3949 kind
= ADA_OBJECT_RENAMING
;
3953 kind
= ADA_EXCEPTION_RENAMING
;
3957 kind
= ADA_PACKAGE_RENAMING
;
3961 kind
= ADA_SUBPROGRAM_RENAMING
;
3965 return ADA_NOT_RENAMING
;
3969 if (renamed_entity
!= NULL
)
3970 *renamed_entity
= info
;
3971 suffix
= strstr (info
, "___XE");
3972 if (suffix
== NULL
|| suffix
== info
)
3973 return ADA_NOT_RENAMING
;
3975 *len
= strlen (info
) - strlen (suffix
);
3977 if (renaming_expr
!= NULL
)
3978 *renaming_expr
= suffix
;
3982 /* Compute the value of the given RENAMING_SYM, which is expected to
3983 be a symbol encoding a renaming expression. BLOCK is the block
3984 used to evaluate the renaming. */
3986 static struct value
*
3987 ada_read_renaming_var_value (struct symbol
*renaming_sym
,
3988 const struct block
*block
)
3990 const char *sym_name
;
3992 sym_name
= renaming_sym
->linkage_name ();
3993 expression_up expr
= parse_exp_1 (&sym_name
, 0, block
, 0);
3994 return evaluate_expression (expr
.get ());
3998 /* Evaluation: Function Calls */
4000 /* Return an lvalue containing the value VAL. This is the identity on
4001 lvalues, and otherwise has the side-effect of allocating memory
4002 in the inferior where a copy of the value contents is copied. */
4004 static struct value
*
4005 ensure_lval (struct value
*val
)
4007 if (VALUE_LVAL (val
) == not_lval
4008 || VALUE_LVAL (val
) == lval_internalvar
)
4010 int len
= TYPE_LENGTH (ada_check_typedef (value_type (val
)));
4011 const CORE_ADDR addr
=
4012 value_as_long (value_allocate_space_in_inferior (len
));
4014 VALUE_LVAL (val
) = lval_memory
;
4015 set_value_address (val
, addr
);
4016 write_memory (addr
, value_contents (val
).data (), len
);
4022 /* Given ARG, a value of type (pointer or reference to a)*
4023 structure/union, extract the component named NAME from the ultimate
4024 target structure/union and return it as a value with its
4027 The routine searches for NAME among all members of the structure itself
4028 and (recursively) among all members of any wrapper members
4031 If NO_ERR, then simply return NULL in case of error, rather than
4034 static struct value
*
4035 ada_value_struct_elt (struct value
*arg
, const char *name
, int no_err
)
4037 struct type
*t
, *t1
;
4042 t1
= t
= ada_check_typedef (value_type (arg
));
4043 if (t
->code () == TYPE_CODE_REF
)
4045 t1
= TYPE_TARGET_TYPE (t
);
4048 t1
= ada_check_typedef (t1
);
4049 if (t1
->code () == TYPE_CODE_PTR
)
4051 arg
= coerce_ref (arg
);
4056 while (t
->code () == TYPE_CODE_PTR
)
4058 t1
= TYPE_TARGET_TYPE (t
);
4061 t1
= ada_check_typedef (t1
);
4062 if (t1
->code () == TYPE_CODE_PTR
)
4064 arg
= value_ind (arg
);
4071 if (t1
->code () != TYPE_CODE_STRUCT
&& t1
->code () != TYPE_CODE_UNION
)
4075 v
= ada_search_struct_field (name
, arg
, 0, t
);
4078 int bit_offset
, bit_size
, byte_offset
;
4079 struct type
*field_type
;
4082 if (t
->code () == TYPE_CODE_PTR
)
4083 address
= value_address (ada_value_ind (arg
));
4085 address
= value_address (ada_coerce_ref (arg
));
4087 /* Check to see if this is a tagged type. We also need to handle
4088 the case where the type is a reference to a tagged type, but
4089 we have to be careful to exclude pointers to tagged types.
4090 The latter should be shown as usual (as a pointer), whereas
4091 a reference should mostly be transparent to the user. */
4093 if (ada_is_tagged_type (t1
, 0)
4094 || (t1
->code () == TYPE_CODE_REF
4095 && ada_is_tagged_type (TYPE_TARGET_TYPE (t1
), 0)))
4097 /* We first try to find the searched field in the current type.
4098 If not found then let's look in the fixed type. */
4100 if (!find_struct_field (name
, t1
, 0,
4101 nullptr, nullptr, nullptr,
4110 /* Convert to fixed type in all cases, so that we have proper
4111 offsets to each field in unconstrained record types. */
4112 t1
= ada_to_fixed_type (ada_get_base_type (t1
), NULL
,
4113 address
, NULL
, check_tag
);
4115 /* Resolve the dynamic type as well. */
4116 arg
= value_from_contents_and_address (t1
, nullptr, address
);
4117 t1
= value_type (arg
);
4119 if (find_struct_field (name
, t1
, 0,
4120 &field_type
, &byte_offset
, &bit_offset
,
4125 if (t
->code () == TYPE_CODE_REF
)
4126 arg
= ada_coerce_ref (arg
);
4128 arg
= ada_value_ind (arg
);
4129 v
= ada_value_primitive_packed_val (arg
, NULL
, byte_offset
,
4130 bit_offset
, bit_size
,
4134 v
= value_at_lazy (field_type
, address
+ byte_offset
);
4138 if (v
!= NULL
|| no_err
)
4141 error (_("There is no member named %s."), name
);
4147 error (_("Attempt to extract a component of "
4148 "a value that is not a record."));
4151 /* Return the value ACTUAL, converted to be an appropriate value for a
4152 formal of type FORMAL_TYPE. Use *SP as a stack pointer for
4153 allocating any necessary descriptors (fat pointers), or copies of
4154 values not residing in memory, updating it as needed. */
4157 ada_convert_actual (struct value
*actual
, struct type
*formal_type0
)
4159 struct type
*actual_type
= ada_check_typedef (value_type (actual
));
4160 struct type
*formal_type
= ada_check_typedef (formal_type0
);
4161 struct type
*formal_target
=
4162 formal_type
->code () == TYPE_CODE_PTR
4163 ? ada_check_typedef (TYPE_TARGET_TYPE (formal_type
)) : formal_type
;
4164 struct type
*actual_target
=
4165 actual_type
->code () == TYPE_CODE_PTR
4166 ? ada_check_typedef (TYPE_TARGET_TYPE (actual_type
)) : actual_type
;
4168 if (ada_is_array_descriptor_type (formal_target
)
4169 && actual_target
->code () == TYPE_CODE_ARRAY
)
4170 return make_array_descriptor (formal_type
, actual
);
4171 else if (formal_type
->code () == TYPE_CODE_PTR
4172 || formal_type
->code () == TYPE_CODE_REF
)
4174 struct value
*result
;
4176 if (formal_target
->code () == TYPE_CODE_ARRAY
4177 && ada_is_array_descriptor_type (actual_target
))
4178 result
= desc_data (actual
);
4179 else if (formal_type
->code () != TYPE_CODE_PTR
)
4181 if (VALUE_LVAL (actual
) != lval_memory
)
4185 actual_type
= ada_check_typedef (value_type (actual
));
4186 val
= allocate_value (actual_type
);
4187 memcpy ((char *) value_contents_raw (val
).data (),
4188 (char *) value_contents (actual
).data (),
4189 TYPE_LENGTH (actual_type
));
4190 actual
= ensure_lval (val
);
4192 result
= value_addr (actual
);
4196 return value_cast_pointers (formal_type
, result
, 0);
4198 else if (actual_type
->code () == TYPE_CODE_PTR
)
4199 return ada_value_ind (actual
);
4200 else if (ada_is_aligner_type (formal_type
))
4202 /* We need to turn this parameter into an aligner type
4204 struct value
*aligner
= allocate_value (formal_type
);
4205 struct value
*component
= ada_value_struct_elt (aligner
, "F", 0);
4207 value_assign_to_component (aligner
, component
, actual
);
4214 /* Convert VALUE (which must be an address) to a CORE_ADDR that is a pointer of
4215 type TYPE. This is usually an inefficient no-op except on some targets
4216 (such as AVR) where the representation of a pointer and an address
4220 value_pointer (struct value
*value
, struct type
*type
)
4222 unsigned len
= TYPE_LENGTH (type
);
4223 gdb_byte
*buf
= (gdb_byte
*) alloca (len
);
4226 addr
= value_address (value
);
4227 gdbarch_address_to_pointer (type
->arch (), type
, buf
, addr
);
4228 addr
= extract_unsigned_integer (buf
, len
, type_byte_order (type
));
4233 /* Push a descriptor of type TYPE for array value ARR on the stack at
4234 *SP, updating *SP to reflect the new descriptor. Return either
4235 an lvalue representing the new descriptor, or (if TYPE is a pointer-
4236 to-descriptor type rather than a descriptor type), a struct value *
4237 representing a pointer to this descriptor. */
4239 static struct value
*
4240 make_array_descriptor (struct type
*type
, struct value
*arr
)
4242 struct type
*bounds_type
= desc_bounds_type (type
);
4243 struct type
*desc_type
= desc_base_type (type
);
4244 struct value
*descriptor
= allocate_value (desc_type
);
4245 struct value
*bounds
= allocate_value (bounds_type
);
4248 for (i
= ada_array_arity (ada_check_typedef (value_type (arr
)));
4251 modify_field (value_type (bounds
),
4252 value_contents_writeable (bounds
).data (),
4253 ada_array_bound (arr
, i
, 0),
4254 desc_bound_bitpos (bounds_type
, i
, 0),
4255 desc_bound_bitsize (bounds_type
, i
, 0));
4256 modify_field (value_type (bounds
),
4257 value_contents_writeable (bounds
).data (),
4258 ada_array_bound (arr
, i
, 1),
4259 desc_bound_bitpos (bounds_type
, i
, 1),
4260 desc_bound_bitsize (bounds_type
, i
, 1));
4263 bounds
= ensure_lval (bounds
);
4265 modify_field (value_type (descriptor
),
4266 value_contents_writeable (descriptor
).data (),
4267 value_pointer (ensure_lval (arr
),
4268 desc_type
->field (0).type ()),
4269 fat_pntr_data_bitpos (desc_type
),
4270 fat_pntr_data_bitsize (desc_type
));
4272 modify_field (value_type (descriptor
),
4273 value_contents_writeable (descriptor
).data (),
4274 value_pointer (bounds
,
4275 desc_type
->field (1).type ()),
4276 fat_pntr_bounds_bitpos (desc_type
),
4277 fat_pntr_bounds_bitsize (desc_type
));
4279 descriptor
= ensure_lval (descriptor
);
4281 if (type
->code () == TYPE_CODE_PTR
)
4282 return value_addr (descriptor
);
4287 /* Symbol Cache Module */
4289 /* Performance measurements made as of 2010-01-15 indicate that
4290 this cache does bring some noticeable improvements. Depending
4291 on the type of entity being printed, the cache can make it as much
4292 as an order of magnitude faster than without it.
4294 The descriptive type DWARF extension has significantly reduced
4295 the need for this cache, at least when DWARF is being used. However,
4296 even in this case, some expensive name-based symbol searches are still
4297 sometimes necessary - to find an XVZ variable, mostly. */
4299 /* Return the symbol cache associated to the given program space PSPACE.
4300 If not allocated for this PSPACE yet, allocate and initialize one. */
4302 static struct ada_symbol_cache
*
4303 ada_get_symbol_cache (struct program_space
*pspace
)
4305 struct ada_pspace_data
*pspace_data
= get_ada_pspace_data (pspace
);
4307 if (pspace_data
->sym_cache
== nullptr)
4308 pspace_data
->sym_cache
.reset (new ada_symbol_cache
);
4310 return pspace_data
->sym_cache
.get ();
4313 /* Clear all entries from the symbol cache. */
4316 ada_clear_symbol_cache ()
4318 struct ada_pspace_data
*pspace_data
4319 = get_ada_pspace_data (current_program_space
);
4321 if (pspace_data
->sym_cache
!= nullptr)
4322 pspace_data
->sym_cache
.reset ();
4325 /* Search our cache for an entry matching NAME and DOMAIN.
4326 Return it if found, or NULL otherwise. */
4328 static struct cache_entry
**
4329 find_entry (const char *name
, domain_enum domain
)
4331 struct ada_symbol_cache
*sym_cache
4332 = ada_get_symbol_cache (current_program_space
);
4333 int h
= msymbol_hash (name
) % HASH_SIZE
;
4334 struct cache_entry
**e
;
4336 for (e
= &sym_cache
->root
[h
]; *e
!= NULL
; e
= &(*e
)->next
)
4338 if (domain
== (*e
)->domain
&& strcmp (name
, (*e
)->name
) == 0)
4344 /* Search the symbol cache for an entry matching NAME and DOMAIN.
4345 Return 1 if found, 0 otherwise.
4347 If an entry was found and SYM is not NULL, set *SYM to the entry's
4348 SYM. Same principle for BLOCK if not NULL. */
4351 lookup_cached_symbol (const char *name
, domain_enum domain
,
4352 struct symbol
**sym
, const struct block
**block
)
4354 struct cache_entry
**e
= find_entry (name
, domain
);
4361 *block
= (*e
)->block
;
4365 /* Assuming that (SYM, BLOCK) is the result of the lookup of NAME
4366 in domain DOMAIN, save this result in our symbol cache. */
4369 cache_symbol (const char *name
, domain_enum domain
, struct symbol
*sym
,
4370 const struct block
*block
)
4372 struct ada_symbol_cache
*sym_cache
4373 = ada_get_symbol_cache (current_program_space
);
4375 struct cache_entry
*e
;
4377 /* Symbols for builtin types don't have a block.
4378 For now don't cache such symbols. */
4379 if (sym
!= NULL
&& !SYMBOL_OBJFILE_OWNED (sym
))
4382 /* If the symbol is a local symbol, then do not cache it, as a search
4383 for that symbol depends on the context. To determine whether
4384 the symbol is local or not, we check the block where we found it
4385 against the global and static blocks of its associated symtab. */
4387 && BLOCKVECTOR_BLOCK (SYMTAB_BLOCKVECTOR (symbol_symtab (sym
)),
4388 GLOBAL_BLOCK
) != block
4389 && BLOCKVECTOR_BLOCK (SYMTAB_BLOCKVECTOR (symbol_symtab (sym
)),
4390 STATIC_BLOCK
) != block
)
4393 h
= msymbol_hash (name
) % HASH_SIZE
;
4394 e
= XOBNEW (&sym_cache
->cache_space
, cache_entry
);
4395 e
->next
= sym_cache
->root
[h
];
4396 sym_cache
->root
[h
] = e
;
4397 e
->name
= obstack_strdup (&sym_cache
->cache_space
, name
);
4405 /* Return the symbol name match type that should be used used when
4406 searching for all symbols matching LOOKUP_NAME.
4408 LOOKUP_NAME is expected to be a symbol name after transformation
4411 static symbol_name_match_type
4412 name_match_type_from_name (const char *lookup_name
)
4414 return (strstr (lookup_name
, "__") == NULL
4415 ? symbol_name_match_type::WILD
4416 : symbol_name_match_type::FULL
);
4419 /* Return the result of a standard (literal, C-like) lookup of NAME in
4420 given DOMAIN, visible from lexical block BLOCK. */
4422 static struct symbol
*
4423 standard_lookup (const char *name
, const struct block
*block
,
4426 /* Initialize it just to avoid a GCC false warning. */
4427 struct block_symbol sym
= {};
4429 if (lookup_cached_symbol (name
, domain
, &sym
.symbol
, NULL
))
4431 ada_lookup_encoded_symbol (name
, block
, domain
, &sym
);
4432 cache_symbol (name
, domain
, sym
.symbol
, sym
.block
);
4437 /* Non-zero iff there is at least one non-function/non-enumeral symbol
4438 in the symbol fields of SYMS. We treat enumerals as functions,
4439 since they contend in overloading in the same way. */
4441 is_nonfunction (const std::vector
<struct block_symbol
> &syms
)
4443 for (const block_symbol
&sym
: syms
)
4444 if (SYMBOL_TYPE (sym
.symbol
)->code () != TYPE_CODE_FUNC
4445 && (SYMBOL_TYPE (sym
.symbol
)->code () != TYPE_CODE_ENUM
4446 || SYMBOL_CLASS (sym
.symbol
) != LOC_CONST
))
4452 /* If true (non-zero), then TYPE0 and TYPE1 represent equivalent
4453 struct types. Otherwise, they may not. */
4456 equiv_types (struct type
*type0
, struct type
*type1
)
4460 if (type0
== NULL
|| type1
== NULL
4461 || type0
->code () != type1
->code ())
4463 if ((type0
->code () == TYPE_CODE_STRUCT
4464 || type0
->code () == TYPE_CODE_ENUM
)
4465 && ada_type_name (type0
) != NULL
&& ada_type_name (type1
) != NULL
4466 && strcmp (ada_type_name (type0
), ada_type_name (type1
)) == 0)
4472 /* True iff SYM0 represents the same entity as SYM1, or one that is
4473 no more defined than that of SYM1. */
4476 lesseq_defined_than (struct symbol
*sym0
, struct symbol
*sym1
)
4480 if (SYMBOL_DOMAIN (sym0
) != SYMBOL_DOMAIN (sym1
)
4481 || SYMBOL_CLASS (sym0
) != SYMBOL_CLASS (sym1
))
4484 switch (SYMBOL_CLASS (sym0
))
4490 struct type
*type0
= SYMBOL_TYPE (sym0
);
4491 struct type
*type1
= SYMBOL_TYPE (sym1
);
4492 const char *name0
= sym0
->linkage_name ();
4493 const char *name1
= sym1
->linkage_name ();
4494 int len0
= strlen (name0
);
4497 type0
->code () == type1
->code ()
4498 && (equiv_types (type0
, type1
)
4499 || (len0
< strlen (name1
) && strncmp (name0
, name1
, len0
) == 0
4500 && startswith (name1
+ len0
, "___XV")));
4503 return SYMBOL_VALUE (sym0
) == SYMBOL_VALUE (sym1
)
4504 && equiv_types (SYMBOL_TYPE (sym0
), SYMBOL_TYPE (sym1
));
4508 const char *name0
= sym0
->linkage_name ();
4509 const char *name1
= sym1
->linkage_name ();
4510 return (strcmp (name0
, name1
) == 0
4511 && SYMBOL_VALUE_ADDRESS (sym0
) == SYMBOL_VALUE_ADDRESS (sym1
));
4519 /* Append (SYM,BLOCK) to the end of the array of struct block_symbol
4520 records in RESULT. Do nothing if SYM is a duplicate. */
4523 add_defn_to_vec (std::vector
<struct block_symbol
> &result
,
4525 const struct block
*block
)
4527 /* Do not try to complete stub types, as the debugger is probably
4528 already scanning all symbols matching a certain name at the
4529 time when this function is called. Trying to replace the stub
4530 type by its associated full type will cause us to restart a scan
4531 which may lead to an infinite recursion. Instead, the client
4532 collecting the matching symbols will end up collecting several
4533 matches, with at least one of them complete. It can then filter
4534 out the stub ones if needed. */
4536 for (int i
= result
.size () - 1; i
>= 0; i
-= 1)
4538 if (lesseq_defined_than (sym
, result
[i
].symbol
))
4540 else if (lesseq_defined_than (result
[i
].symbol
, sym
))
4542 result
[i
].symbol
= sym
;
4543 result
[i
].block
= block
;
4548 struct block_symbol info
;
4551 result
.push_back (info
);
4554 /* Return a bound minimal symbol matching NAME according to Ada
4555 decoding rules. Returns an invalid symbol if there is no such
4556 minimal symbol. Names prefixed with "standard__" are handled
4557 specially: "standard__" is first stripped off, and only static and
4558 global symbols are searched. */
4560 struct bound_minimal_symbol
4561 ada_lookup_simple_minsym (const char *name
)
4563 struct bound_minimal_symbol result
;
4565 memset (&result
, 0, sizeof (result
));
4567 symbol_name_match_type match_type
= name_match_type_from_name (name
);
4568 lookup_name_info
lookup_name (name
, match_type
);
4570 symbol_name_matcher_ftype
*match_name
4571 = ada_get_symbol_name_matcher (lookup_name
);
4573 for (objfile
*objfile
: current_program_space
->objfiles ())
4575 for (minimal_symbol
*msymbol
: objfile
->msymbols ())
4577 if (match_name (msymbol
->linkage_name (), lookup_name
, NULL
)
4578 && MSYMBOL_TYPE (msymbol
) != mst_solib_trampoline
)
4580 result
.minsym
= msymbol
;
4581 result
.objfile
= objfile
;
4590 /* True if TYPE is definitely an artificial type supplied to a symbol
4591 for which no debugging information was given in the symbol file. */
4594 is_nondebugging_type (struct type
*type
)
4596 const char *name
= ada_type_name (type
);
4598 return (name
!= NULL
&& strcmp (name
, "<variable, no debug info>") == 0);
4601 /* Return nonzero if TYPE1 and TYPE2 are two enumeration types
4602 that are deemed "identical" for practical purposes.
4604 This function assumes that TYPE1 and TYPE2 are both TYPE_CODE_ENUM
4605 types and that their number of enumerals is identical (in other
4606 words, type1->num_fields () == type2->num_fields ()). */
4609 ada_identical_enum_types_p (struct type
*type1
, struct type
*type2
)
4613 /* The heuristic we use here is fairly conservative. We consider
4614 that 2 enumerate types are identical if they have the same
4615 number of enumerals and that all enumerals have the same
4616 underlying value and name. */
4618 /* All enums in the type should have an identical underlying value. */
4619 for (i
= 0; i
< type1
->num_fields (); i
++)
4620 if (type1
->field (i
).loc_enumval () != type2
->field (i
).loc_enumval ())
4623 /* All enumerals should also have the same name (modulo any numerical
4625 for (i
= 0; i
< type1
->num_fields (); i
++)
4627 const char *name_1
= type1
->field (i
).name ();
4628 const char *name_2
= type2
->field (i
).name ();
4629 int len_1
= strlen (name_1
);
4630 int len_2
= strlen (name_2
);
4632 ada_remove_trailing_digits (type1
->field (i
).name (), &len_1
);
4633 ada_remove_trailing_digits (type2
->field (i
).name (), &len_2
);
4635 || strncmp (type1
->field (i
).name (),
4636 type2
->field (i
).name (),
4644 /* Return nonzero if all the symbols in SYMS are all enumeral symbols
4645 that are deemed "identical" for practical purposes. Sometimes,
4646 enumerals are not strictly identical, but their types are so similar
4647 that they can be considered identical.
4649 For instance, consider the following code:
4651 type Color is (Black, Red, Green, Blue, White);
4652 type RGB_Color is new Color range Red .. Blue;
4654 Type RGB_Color is a subrange of an implicit type which is a copy
4655 of type Color. If we call that implicit type RGB_ColorB ("B" is
4656 for "Base Type"), then type RGB_ColorB is a copy of type Color.
4657 As a result, when an expression references any of the enumeral
4658 by name (Eg. "print green"), the expression is technically
4659 ambiguous and the user should be asked to disambiguate. But
4660 doing so would only hinder the user, since it wouldn't matter
4661 what choice he makes, the outcome would always be the same.
4662 So, for practical purposes, we consider them as the same. */
4665 symbols_are_identical_enums (const std::vector
<struct block_symbol
> &syms
)
4669 /* Before performing a thorough comparison check of each type,
4670 we perform a series of inexpensive checks. We expect that these
4671 checks will quickly fail in the vast majority of cases, and thus
4672 help prevent the unnecessary use of a more expensive comparison.
4673 Said comparison also expects us to make some of these checks
4674 (see ada_identical_enum_types_p). */
4676 /* Quick check: All symbols should have an enum type. */
4677 for (i
= 0; i
< syms
.size (); i
++)
4678 if (SYMBOL_TYPE (syms
[i
].symbol
)->code () != TYPE_CODE_ENUM
)
4681 /* Quick check: They should all have the same value. */
4682 for (i
= 1; i
< syms
.size (); i
++)
4683 if (SYMBOL_VALUE (syms
[i
].symbol
) != SYMBOL_VALUE (syms
[0].symbol
))
4686 /* Quick check: They should all have the same number of enumerals. */
4687 for (i
= 1; i
< syms
.size (); i
++)
4688 if (SYMBOL_TYPE (syms
[i
].symbol
)->num_fields ()
4689 != SYMBOL_TYPE (syms
[0].symbol
)->num_fields ())
4692 /* All the sanity checks passed, so we might have a set of
4693 identical enumeration types. Perform a more complete
4694 comparison of the type of each symbol. */
4695 for (i
= 1; i
< syms
.size (); i
++)
4696 if (!ada_identical_enum_types_p (SYMBOL_TYPE (syms
[i
].symbol
),
4697 SYMBOL_TYPE (syms
[0].symbol
)))
4703 /* Remove any non-debugging symbols in SYMS that definitely
4704 duplicate other symbols in the list (The only case I know of where
4705 this happens is when object files containing stabs-in-ecoff are
4706 linked with files containing ordinary ecoff debugging symbols (or no
4707 debugging symbols)). Modifies SYMS to squeeze out deleted entries. */
4710 remove_extra_symbols (std::vector
<struct block_symbol
> *syms
)
4714 /* We should never be called with less than 2 symbols, as there
4715 cannot be any extra symbol in that case. But it's easy to
4716 handle, since we have nothing to do in that case. */
4717 if (syms
->size () < 2)
4721 while (i
< syms
->size ())
4725 /* If two symbols have the same name and one of them is a stub type,
4726 the get rid of the stub. */
4728 if (SYMBOL_TYPE ((*syms
)[i
].symbol
)->is_stub ()
4729 && (*syms
)[i
].symbol
->linkage_name () != NULL
)
4731 for (j
= 0; j
< syms
->size (); j
++)
4734 && !SYMBOL_TYPE ((*syms
)[j
].symbol
)->is_stub ()
4735 && (*syms
)[j
].symbol
->linkage_name () != NULL
4736 && strcmp ((*syms
)[i
].symbol
->linkage_name (),
4737 (*syms
)[j
].symbol
->linkage_name ()) == 0)
4742 /* Two symbols with the same name, same class and same address
4743 should be identical. */
4745 else if ((*syms
)[i
].symbol
->linkage_name () != NULL
4746 && SYMBOL_CLASS ((*syms
)[i
].symbol
) == LOC_STATIC
4747 && is_nondebugging_type (SYMBOL_TYPE ((*syms
)[i
].symbol
)))
4749 for (j
= 0; j
< syms
->size (); j
+= 1)
4752 && (*syms
)[j
].symbol
->linkage_name () != NULL
4753 && strcmp ((*syms
)[i
].symbol
->linkage_name (),
4754 (*syms
)[j
].symbol
->linkage_name ()) == 0
4755 && SYMBOL_CLASS ((*syms
)[i
].symbol
)
4756 == SYMBOL_CLASS ((*syms
)[j
].symbol
)
4757 && SYMBOL_VALUE_ADDRESS ((*syms
)[i
].symbol
)
4758 == SYMBOL_VALUE_ADDRESS ((*syms
)[j
].symbol
))
4764 syms
->erase (syms
->begin () + i
);
4769 /* If all the remaining symbols are identical enumerals, then
4770 just keep the first one and discard the rest.
4772 Unlike what we did previously, we do not discard any entry
4773 unless they are ALL identical. This is because the symbol
4774 comparison is not a strict comparison, but rather a practical
4775 comparison. If all symbols are considered identical, then
4776 we can just go ahead and use the first one and discard the rest.
4777 But if we cannot reduce the list to a single element, we have
4778 to ask the user to disambiguate anyways. And if we have to
4779 present a multiple-choice menu, it's less confusing if the list
4780 isn't missing some choices that were identical and yet distinct. */
4781 if (symbols_are_identical_enums (*syms
))
4785 /* Given a type that corresponds to a renaming entity, use the type name
4786 to extract the scope (package name or function name, fully qualified,
4787 and following the GNAT encoding convention) where this renaming has been
4791 xget_renaming_scope (struct type
*renaming_type
)
4793 /* The renaming types adhere to the following convention:
4794 <scope>__<rename>___<XR extension>.
4795 So, to extract the scope, we search for the "___XR" extension,
4796 and then backtrack until we find the first "__". */
4798 const char *name
= renaming_type
->name ();
4799 const char *suffix
= strstr (name
, "___XR");
4802 /* Now, backtrack a bit until we find the first "__". Start looking
4803 at suffix - 3, as the <rename> part is at least one character long. */
4805 for (last
= suffix
- 3; last
> name
; last
--)
4806 if (last
[0] == '_' && last
[1] == '_')
4809 /* Make a copy of scope and return it. */
4810 return std::string (name
, last
);
4813 /* Return nonzero if NAME corresponds to a package name. */
4816 is_package_name (const char *name
)
4818 /* Here, We take advantage of the fact that no symbols are generated
4819 for packages, while symbols are generated for each function.
4820 So the condition for NAME represent a package becomes equivalent
4821 to NAME not existing in our list of symbols. There is only one
4822 small complication with library-level functions (see below). */
4824 /* If it is a function that has not been defined at library level,
4825 then we should be able to look it up in the symbols. */
4826 if (standard_lookup (name
, NULL
, VAR_DOMAIN
) != NULL
)
4829 /* Library-level function names start with "_ada_". See if function
4830 "_ada_" followed by NAME can be found. */
4832 /* Do a quick check that NAME does not contain "__", since library-level
4833 functions names cannot contain "__" in them. */
4834 if (strstr (name
, "__") != NULL
)
4837 std::string fun_name
= string_printf ("_ada_%s", name
);
4839 return (standard_lookup (fun_name
.c_str (), NULL
, VAR_DOMAIN
) == NULL
);
4842 /* Return nonzero if SYM corresponds to a renaming entity that is
4843 not visible from FUNCTION_NAME. */
4846 old_renaming_is_invisible (const struct symbol
*sym
, const char *function_name
)
4848 if (SYMBOL_CLASS (sym
) != LOC_TYPEDEF
)
4851 std::string scope
= xget_renaming_scope (SYMBOL_TYPE (sym
));
4853 /* If the rename has been defined in a package, then it is visible. */
4854 if (is_package_name (scope
.c_str ()))
4857 /* Check that the rename is in the current function scope by checking
4858 that its name starts with SCOPE. */
4860 /* If the function name starts with "_ada_", it means that it is
4861 a library-level function. Strip this prefix before doing the
4862 comparison, as the encoding for the renaming does not contain
4864 if (startswith (function_name
, "_ada_"))
4867 return !startswith (function_name
, scope
.c_str ());
4870 /* Remove entries from SYMS that corresponds to a renaming entity that
4871 is not visible from the function associated with CURRENT_BLOCK or
4872 that is superfluous due to the presence of more specific renaming
4873 information. Places surviving symbols in the initial entries of
4877 First, in cases where an object renaming is implemented as a
4878 reference variable, GNAT may produce both the actual reference
4879 variable and the renaming encoding. In this case, we discard the
4882 Second, GNAT emits a type following a specified encoding for each renaming
4883 entity. Unfortunately, STABS currently does not support the definition
4884 of types that are local to a given lexical block, so all renamings types
4885 are emitted at library level. As a consequence, if an application
4886 contains two renaming entities using the same name, and a user tries to
4887 print the value of one of these entities, the result of the ada symbol
4888 lookup will also contain the wrong renaming type.
4890 This function partially covers for this limitation by attempting to
4891 remove from the SYMS list renaming symbols that should be visible
4892 from CURRENT_BLOCK. However, there does not seem be a 100% reliable
4893 method with the current information available. The implementation
4894 below has a couple of limitations (FIXME: brobecker-2003-05-12):
4896 - When the user tries to print a rename in a function while there
4897 is another rename entity defined in a package: Normally, the
4898 rename in the function has precedence over the rename in the
4899 package, so the latter should be removed from the list. This is
4900 currently not the case.
4902 - This function will incorrectly remove valid renames if
4903 the CURRENT_BLOCK corresponds to a function which symbol name
4904 has been changed by an "Export" pragma. As a consequence,
4905 the user will be unable to print such rename entities. */
4908 remove_irrelevant_renamings (std::vector
<struct block_symbol
> *syms
,
4909 const struct block
*current_block
)
4911 struct symbol
*current_function
;
4912 const char *current_function_name
;
4914 int is_new_style_renaming
;
4916 /* If there is both a renaming foo___XR... encoded as a variable and
4917 a simple variable foo in the same block, discard the latter.
4918 First, zero out such symbols, then compress. */
4919 is_new_style_renaming
= 0;
4920 for (i
= 0; i
< syms
->size (); i
+= 1)
4922 struct symbol
*sym
= (*syms
)[i
].symbol
;
4923 const struct block
*block
= (*syms
)[i
].block
;
4927 if (sym
== NULL
|| SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
4929 name
= sym
->linkage_name ();
4930 suffix
= strstr (name
, "___XR");
4934 int name_len
= suffix
- name
;
4937 is_new_style_renaming
= 1;
4938 for (j
= 0; j
< syms
->size (); j
+= 1)
4939 if (i
!= j
&& (*syms
)[j
].symbol
!= NULL
4940 && strncmp (name
, (*syms
)[j
].symbol
->linkage_name (),
4942 && block
== (*syms
)[j
].block
)
4943 (*syms
)[j
].symbol
= NULL
;
4946 if (is_new_style_renaming
)
4950 for (j
= k
= 0; j
< syms
->size (); j
+= 1)
4951 if ((*syms
)[j
].symbol
!= NULL
)
4953 (*syms
)[k
] = (*syms
)[j
];
4960 /* Extract the function name associated to CURRENT_BLOCK.
4961 Abort if unable to do so. */
4963 if (current_block
== NULL
)
4966 current_function
= block_linkage_function (current_block
);
4967 if (current_function
== NULL
)
4970 current_function_name
= current_function
->linkage_name ();
4971 if (current_function_name
== NULL
)
4974 /* Check each of the symbols, and remove it from the list if it is
4975 a type corresponding to a renaming that is out of the scope of
4976 the current block. */
4979 while (i
< syms
->size ())
4981 if (ada_parse_renaming ((*syms
)[i
].symbol
, NULL
, NULL
, NULL
)
4982 == ADA_OBJECT_RENAMING
4983 && old_renaming_is_invisible ((*syms
)[i
].symbol
,
4984 current_function_name
))
4985 syms
->erase (syms
->begin () + i
);
4991 /* Add to RESULT all symbols from BLOCK (and its super-blocks)
4992 whose name and domain match LOOKUP_NAME and DOMAIN respectively.
4994 Note: This function assumes that RESULT is empty. */
4997 ada_add_local_symbols (std::vector
<struct block_symbol
> &result
,
4998 const lookup_name_info
&lookup_name
,
4999 const struct block
*block
, domain_enum domain
)
5001 while (block
!= NULL
)
5003 ada_add_block_symbols (result
, block
, lookup_name
, domain
, NULL
);
5005 /* If we found a non-function match, assume that's the one. We
5006 only check this when finding a function boundary, so that we
5007 can accumulate all results from intervening blocks first. */
5008 if (BLOCK_FUNCTION (block
) != nullptr && is_nonfunction (result
))
5011 block
= BLOCK_SUPERBLOCK (block
);
5015 /* An object of this type is used as the callback argument when
5016 calling the map_matching_symbols method. */
5020 explicit match_data (std::vector
<struct block_symbol
> *rp
)
5024 DISABLE_COPY_AND_ASSIGN (match_data
);
5026 bool operator() (struct block_symbol
*bsym
);
5028 struct objfile
*objfile
= nullptr;
5029 std::vector
<struct block_symbol
> *resultp
;
5030 struct symbol
*arg_sym
= nullptr;
5031 bool found_sym
= false;
5034 /* A callback for add_nonlocal_symbols that adds symbol, found in
5035 BSYM, to a list of symbols. */
5038 match_data::operator() (struct block_symbol
*bsym
)
5040 const struct block
*block
= bsym
->block
;
5041 struct symbol
*sym
= bsym
->symbol
;
5045 if (!found_sym
&& arg_sym
!= NULL
)
5046 add_defn_to_vec (*resultp
,
5047 fixup_symbol_section (arg_sym
, objfile
),
5054 if (SYMBOL_CLASS (sym
) == LOC_UNRESOLVED
)
5056 else if (SYMBOL_IS_ARGUMENT (sym
))
5061 add_defn_to_vec (*resultp
,
5062 fixup_symbol_section (sym
, objfile
),
5069 /* Helper for add_nonlocal_symbols. Find symbols in DOMAIN which are
5070 targeted by renamings matching LOOKUP_NAME in BLOCK. Add these
5071 symbols to RESULT. Return whether we found such symbols. */
5074 ada_add_block_renamings (std::vector
<struct block_symbol
> &result
,
5075 const struct block
*block
,
5076 const lookup_name_info
&lookup_name
,
5079 struct using_direct
*renaming
;
5080 int defns_mark
= result
.size ();
5082 symbol_name_matcher_ftype
*name_match
5083 = ada_get_symbol_name_matcher (lookup_name
);
5085 for (renaming
= block_using (block
);
5087 renaming
= renaming
->next
)
5091 /* Avoid infinite recursions: skip this renaming if we are actually
5092 already traversing it.
5094 Currently, symbol lookup in Ada don't use the namespace machinery from
5095 C++/Fortran support: skip namespace imports that use them. */
5096 if (renaming
->searched
5097 || (renaming
->import_src
!= NULL
5098 && renaming
->import_src
[0] != '\0')
5099 || (renaming
->import_dest
!= NULL
5100 && renaming
->import_dest
[0] != '\0'))
5102 renaming
->searched
= 1;
5104 /* TODO: here, we perform another name-based symbol lookup, which can
5105 pull its own multiple overloads. In theory, we should be able to do
5106 better in this case since, in DWARF, DW_AT_import is a DIE reference,
5107 not a simple name. But in order to do this, we would need to enhance
5108 the DWARF reader to associate a symbol to this renaming, instead of a
5109 name. So, for now, we do something simpler: re-use the C++/Fortran
5110 namespace machinery. */
5111 r_name
= (renaming
->alias
!= NULL
5113 : renaming
->declaration
);
5114 if (name_match (r_name
, lookup_name
, NULL
))
5116 lookup_name_info
decl_lookup_name (renaming
->declaration
,
5117 lookup_name
.match_type ());
5118 ada_add_all_symbols (result
, block
, decl_lookup_name
, domain
,
5121 renaming
->searched
= 0;
5123 return result
.size () != defns_mark
;
5126 /* Implements compare_names, but only applying the comparision using
5127 the given CASING. */
5130 compare_names_with_case (const char *string1
, const char *string2
,
5131 enum case_sensitivity casing
)
5133 while (*string1
!= '\0' && *string2
!= '\0')
5137 if (isspace (*string1
) || isspace (*string2
))
5138 return strcmp_iw_ordered (string1
, string2
);
5140 if (casing
== case_sensitive_off
)
5142 c1
= tolower (*string1
);
5143 c2
= tolower (*string2
);
5160 return strcmp_iw_ordered (string1
, string2
);
5162 if (*string2
== '\0')
5164 if (is_name_suffix (string1
))
5171 if (*string2
== '(')
5172 return strcmp_iw_ordered (string1
, string2
);
5175 if (casing
== case_sensitive_off
)
5176 return tolower (*string1
) - tolower (*string2
);
5178 return *string1
- *string2
;
5183 /* Compare STRING1 to STRING2, with results as for strcmp.
5184 Compatible with strcmp_iw_ordered in that...
5186 strcmp_iw_ordered (STRING1, STRING2) <= 0
5190 compare_names (STRING1, STRING2) <= 0
5192 (they may differ as to what symbols compare equal). */
5195 compare_names (const char *string1
, const char *string2
)
5199 /* Similar to what strcmp_iw_ordered does, we need to perform
5200 a case-insensitive comparison first, and only resort to
5201 a second, case-sensitive, comparison if the first one was
5202 not sufficient to differentiate the two strings. */
5204 result
= compare_names_with_case (string1
, string2
, case_sensitive_off
);
5206 result
= compare_names_with_case (string1
, string2
, case_sensitive_on
);
5211 /* Convenience function to get at the Ada encoded lookup name for
5212 LOOKUP_NAME, as a C string. */
5215 ada_lookup_name (const lookup_name_info
&lookup_name
)
5217 return lookup_name
.ada ().lookup_name ().c_str ();
5220 /* A helper for add_nonlocal_symbols. Call expand_matching_symbols
5221 for OBJFILE, then walk the objfile's symtabs and update the
5225 map_matching_symbols (struct objfile
*objfile
,
5226 const lookup_name_info
&lookup_name
,
5232 data
.objfile
= objfile
;
5233 objfile
->expand_matching_symbols (lookup_name
, domain
, global
,
5234 is_wild_match
? nullptr : compare_names
);
5236 const int block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
5237 for (compunit_symtab
*symtab
: objfile
->compunits ())
5239 const struct block
*block
5240 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (symtab
), block_kind
);
5241 if (!iterate_over_symbols_terminated (block
, lookup_name
,
5247 /* Add to RESULT all non-local symbols whose name and domain match
5248 LOOKUP_NAME and DOMAIN respectively. The search is performed on
5249 GLOBAL_BLOCK symbols if GLOBAL is non-zero, or on STATIC_BLOCK
5250 symbols otherwise. */
5253 add_nonlocal_symbols (std::vector
<struct block_symbol
> &result
,
5254 const lookup_name_info
&lookup_name
,
5255 domain_enum domain
, int global
)
5257 struct match_data
data (&result
);
5259 bool is_wild_match
= lookup_name
.ada ().wild_match_p ();
5261 for (objfile
*objfile
: current_program_space
->objfiles ())
5263 map_matching_symbols (objfile
, lookup_name
, is_wild_match
, domain
,
5266 for (compunit_symtab
*cu
: objfile
->compunits ())
5268 const struct block
*global_block
5269 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cu
), GLOBAL_BLOCK
);
5271 if (ada_add_block_renamings (result
, global_block
, lookup_name
,
5273 data
.found_sym
= true;
5277 if (result
.empty () && global
&& !is_wild_match
)
5279 const char *name
= ada_lookup_name (lookup_name
);
5280 std::string bracket_name
= std::string ("<_ada_") + name
+ '>';
5281 lookup_name_info
name1 (bracket_name
, symbol_name_match_type::FULL
);
5283 for (objfile
*objfile
: current_program_space
->objfiles ())
5284 map_matching_symbols (objfile
, name1
, false, domain
, global
, data
);
5288 /* Find symbols in DOMAIN matching LOOKUP_NAME, in BLOCK and, if
5289 FULL_SEARCH is non-zero, enclosing scope and in global scopes,
5290 returning the number of matches. Add these to RESULT.
5292 When FULL_SEARCH is non-zero, any non-function/non-enumeral
5293 symbol match within the nest of blocks whose innermost member is BLOCK,
5294 is the one match returned (no other matches in that or
5295 enclosing blocks is returned). If there are any matches in or
5296 surrounding BLOCK, then these alone are returned.
5298 Names prefixed with "standard__" are handled specially:
5299 "standard__" is first stripped off (by the lookup_name
5300 constructor), and only static and global symbols are searched.
5302 If MADE_GLOBAL_LOOKUP_P is non-null, set it before return to whether we had
5303 to lookup global symbols. */
5306 ada_add_all_symbols (std::vector
<struct block_symbol
> &result
,
5307 const struct block
*block
,
5308 const lookup_name_info
&lookup_name
,
5311 int *made_global_lookup_p
)
5315 if (made_global_lookup_p
)
5316 *made_global_lookup_p
= 0;
5318 /* Special case: If the user specifies a symbol name inside package
5319 Standard, do a non-wild matching of the symbol name without
5320 the "standard__" prefix. This was primarily introduced in order
5321 to allow the user to specifically access the standard exceptions
5322 using, for instance, Standard.Constraint_Error when Constraint_Error
5323 is ambiguous (due to the user defining its own Constraint_Error
5324 entity inside its program). */
5325 if (lookup_name
.ada ().standard_p ())
5328 /* Check the non-global symbols. If we have ANY match, then we're done. */
5333 ada_add_local_symbols (result
, lookup_name
, block
, domain
);
5336 /* In the !full_search case we're are being called by
5337 iterate_over_symbols, and we don't want to search
5339 ada_add_block_symbols (result
, block
, lookup_name
, domain
, NULL
);
5341 if (!result
.empty () || !full_search
)
5345 /* No non-global symbols found. Check our cache to see if we have
5346 already performed this search before. If we have, then return
5349 if (lookup_cached_symbol (ada_lookup_name (lookup_name
),
5350 domain
, &sym
, &block
))
5353 add_defn_to_vec (result
, sym
, block
);
5357 if (made_global_lookup_p
)
5358 *made_global_lookup_p
= 1;
5360 /* Search symbols from all global blocks. */
5362 add_nonlocal_symbols (result
, lookup_name
, domain
, 1);
5364 /* Now add symbols from all per-file blocks if we've gotten no hits
5365 (not strictly correct, but perhaps better than an error). */
5367 if (result
.empty ())
5368 add_nonlocal_symbols (result
, lookup_name
, domain
, 0);
5371 /* Find symbols in DOMAIN matching LOOKUP_NAME, in BLOCK and, if FULL_SEARCH
5372 is non-zero, enclosing scope and in global scopes.
5374 Returns (SYM,BLOCK) tuples, indicating the symbols found and the
5375 blocks and symbol tables (if any) in which they were found.
5377 When full_search is non-zero, any non-function/non-enumeral
5378 symbol match within the nest of blocks whose innermost member is BLOCK,
5379 is the one match returned (no other matches in that or
5380 enclosing blocks is returned). If there are any matches in or
5381 surrounding BLOCK, then these alone are returned.
5383 Names prefixed with "standard__" are handled specially: "standard__"
5384 is first stripped off, and only static and global symbols are searched. */
5386 static std::vector
<struct block_symbol
>
5387 ada_lookup_symbol_list_worker (const lookup_name_info
&lookup_name
,
5388 const struct block
*block
,
5392 int syms_from_global_search
;
5393 std::vector
<struct block_symbol
> results
;
5395 ada_add_all_symbols (results
, block
, lookup_name
,
5396 domain
, full_search
, &syms_from_global_search
);
5398 remove_extra_symbols (&results
);
5400 if (results
.empty () && full_search
&& syms_from_global_search
)
5401 cache_symbol (ada_lookup_name (lookup_name
), domain
, NULL
, NULL
);
5403 if (results
.size () == 1 && full_search
&& syms_from_global_search
)
5404 cache_symbol (ada_lookup_name (lookup_name
), domain
,
5405 results
[0].symbol
, results
[0].block
);
5407 remove_irrelevant_renamings (&results
, block
);
5411 /* Find symbols in DOMAIN matching NAME, in BLOCK and enclosing scope and
5412 in global scopes, returning (SYM,BLOCK) tuples.
5414 See ada_lookup_symbol_list_worker for further details. */
5416 std::vector
<struct block_symbol
>
5417 ada_lookup_symbol_list (const char *name
, const struct block
*block
,
5420 symbol_name_match_type name_match_type
= name_match_type_from_name (name
);
5421 lookup_name_info
lookup_name (name
, name_match_type
);
5423 return ada_lookup_symbol_list_worker (lookup_name
, block
, domain
, 1);
5426 /* The result is as for ada_lookup_symbol_list with FULL_SEARCH set
5427 to 1, but choosing the first symbol found if there are multiple
5430 The result is stored in *INFO, which must be non-NULL.
5431 If no match is found, INFO->SYM is set to NULL. */
5434 ada_lookup_encoded_symbol (const char *name
, const struct block
*block
,
5436 struct block_symbol
*info
)
5438 /* Since we already have an encoded name, wrap it in '<>' to force a
5439 verbatim match. Otherwise, if the name happens to not look like
5440 an encoded name (because it doesn't include a "__"),
5441 ada_lookup_name_info would re-encode/fold it again, and that
5442 would e.g., incorrectly lowercase object renaming names like
5443 "R28b" -> "r28b". */
5444 std::string verbatim
= add_angle_brackets (name
);
5446 gdb_assert (info
!= NULL
);
5447 *info
= ada_lookup_symbol (verbatim
.c_str (), block
, domain
);
5450 /* Return a symbol in DOMAIN matching NAME, in BLOCK0 and enclosing
5451 scope and in global scopes, or NULL if none. NAME is folded and
5452 encoded first. Otherwise, the result is as for ada_lookup_symbol_list,
5453 choosing the first symbol if there are multiple choices. */
5456 ada_lookup_symbol (const char *name
, const struct block
*block0
,
5459 std::vector
<struct block_symbol
> candidates
5460 = ada_lookup_symbol_list (name
, block0
, domain
);
5462 if (candidates
.empty ())
5465 block_symbol info
= candidates
[0];
5466 info
.symbol
= fixup_symbol_section (info
.symbol
, NULL
);
5471 /* True iff STR is a possible encoded suffix of a normal Ada name
5472 that is to be ignored for matching purposes. Suffixes of parallel
5473 names (e.g., XVE) are not included here. Currently, the possible suffixes
5474 are given by any of the regular expressions:
5476 [.$][0-9]+ [nested subprogram suffix, on platforms such as GNU/Linux]
5477 ___[0-9]+ [nested subprogram suffix, on platforms such as HP/UX]
5478 TKB [subprogram suffix for task bodies]
5479 _E[0-9]+[bs]$ [protected object entry suffixes]
5480 (X[nb]*)?((\$|__)[0-9](_?[0-9]+)|___(JM|LJM|X([FDBUP].*|R[^T]?)))?$
5482 Also, any leading "__[0-9]+" sequence is skipped before the suffix
5483 match is performed. This sequence is used to differentiate homonyms,
5484 is an optional part of a valid name suffix. */
5487 is_name_suffix (const char *str
)
5490 const char *matching
;
5491 const int len
= strlen (str
);
5493 /* Skip optional leading __[0-9]+. */
5495 if (len
> 3 && str
[0] == '_' && str
[1] == '_' && isdigit (str
[2]))
5498 while (isdigit (str
[0]))
5504 if (str
[0] == '.' || str
[0] == '$')
5507 while (isdigit (matching
[0]))
5509 if (matching
[0] == '\0')
5515 if (len
> 3 && str
[0] == '_' && str
[1] == '_' && str
[2] == '_')
5518 while (isdigit (matching
[0]))
5520 if (matching
[0] == '\0')
5524 /* "TKB" suffixes are used for subprograms implementing task bodies. */
5526 if (strcmp (str
, "TKB") == 0)
5530 /* FIXME: brobecker/2005-09-23: Protected Object subprograms end
5531 with a N at the end. Unfortunately, the compiler uses the same
5532 convention for other internal types it creates. So treating
5533 all entity names that end with an "N" as a name suffix causes
5534 some regressions. For instance, consider the case of an enumerated
5535 type. To support the 'Image attribute, it creates an array whose
5537 Having a single character like this as a suffix carrying some
5538 information is a bit risky. Perhaps we should change the encoding
5539 to be something like "_N" instead. In the meantime, do not do
5540 the following check. */
5541 /* Protected Object Subprograms */
5542 if (len
== 1 && str
[0] == 'N')
5547 if (len
> 3 && str
[0] == '_' && str
[1] == 'E' && isdigit (str
[2]))
5550 while (isdigit (matching
[0]))
5552 if ((matching
[0] == 'b' || matching
[0] == 's')
5553 && matching
[1] == '\0')
5557 /* ??? We should not modify STR directly, as we are doing below. This
5558 is fine in this case, but may become problematic later if we find
5559 that this alternative did not work, and want to try matching
5560 another one from the begining of STR. Since we modified it, we
5561 won't be able to find the begining of the string anymore! */
5565 while (str
[0] != '_' && str
[0] != '\0')
5567 if (str
[0] != 'n' && str
[0] != 'b')
5573 if (str
[0] == '\000')
5578 if (str
[1] != '_' || str
[2] == '\000')
5582 if (strcmp (str
+ 3, "JM") == 0)
5584 /* FIXME: brobecker/2004-09-30: GNAT will soon stop using
5585 the LJM suffix in favor of the JM one. But we will
5586 still accept LJM as a valid suffix for a reasonable
5587 amount of time, just to allow ourselves to debug programs
5588 compiled using an older version of GNAT. */
5589 if (strcmp (str
+ 3, "LJM") == 0)
5593 if (str
[4] == 'F' || str
[4] == 'D' || str
[4] == 'B'
5594 || str
[4] == 'U' || str
[4] == 'P')
5596 if (str
[4] == 'R' && str
[5] != 'T')
5600 if (!isdigit (str
[2]))
5602 for (k
= 3; str
[k
] != '\0'; k
+= 1)
5603 if (!isdigit (str
[k
]) && str
[k
] != '_')
5607 if (str
[0] == '$' && isdigit (str
[1]))
5609 for (k
= 2; str
[k
] != '\0'; k
+= 1)
5610 if (!isdigit (str
[k
]) && str
[k
] != '_')
5617 /* Return non-zero if the string starting at NAME and ending before
5618 NAME_END contains no capital letters. */
5621 is_valid_name_for_wild_match (const char *name0
)
5623 std::string decoded_name
= ada_decode (name0
);
5626 /* If the decoded name starts with an angle bracket, it means that
5627 NAME0 does not follow the GNAT encoding format. It should then
5628 not be allowed as a possible wild match. */
5629 if (decoded_name
[0] == '<')
5632 for (i
=0; decoded_name
[i
] != '\0'; i
++)
5633 if (isalpha (decoded_name
[i
]) && !islower (decoded_name
[i
]))
5639 /* Advance *NAMEP to next occurrence in the string NAME0 of the TARGET0
5640 character which could start a simple name. Assumes that *NAMEP points
5641 somewhere inside the string beginning at NAME0. */
5644 advance_wild_match (const char **namep
, const char *name0
, char target0
)
5646 const char *name
= *namep
;
5656 if ((t1
>= 'a' && t1
<= 'z') || (t1
>= '0' && t1
<= '9'))
5659 if (name
== name0
+ 5 && startswith (name0
, "_ada"))
5664 else if (t1
== '_' && ((name
[2] >= 'a' && name
[2] <= 'z')
5665 || name
[2] == target0
))
5670 else if (t1
== '_' && name
[2] == 'B' && name
[3] == '_')
5672 /* Names like "pkg__B_N__name", where N is a number, are
5673 block-local. We can handle these by simply skipping
5680 else if ((t0
>= 'a' && t0
<= 'z') || (t0
>= '0' && t0
<= '9'))
5690 /* Return true iff NAME encodes a name of the form prefix.PATN.
5691 Ignores any informational suffixes of NAME (i.e., for which
5692 is_name_suffix is true). Assumes that PATN is a lower-cased Ada
5696 wild_match (const char *name
, const char *patn
)
5699 const char *name0
= name
;
5703 const char *match
= name
;
5707 for (name
+= 1, p
= patn
+ 1; *p
!= '\0'; name
+= 1, p
+= 1)
5710 if (*p
== '\0' && is_name_suffix (name
))
5711 return match
== name0
|| is_valid_name_for_wild_match (name0
);
5713 if (name
[-1] == '_')
5716 if (!advance_wild_match (&name
, name0
, *patn
))
5721 /* Add symbols from BLOCK matching LOOKUP_NAME in DOMAIN to RESULT (if
5722 necessary). OBJFILE is the section containing BLOCK. */
5725 ada_add_block_symbols (std::vector
<struct block_symbol
> &result
,
5726 const struct block
*block
,
5727 const lookup_name_info
&lookup_name
,
5728 domain_enum domain
, struct objfile
*objfile
)
5730 struct block_iterator iter
;
5731 /* A matching argument symbol, if any. */
5732 struct symbol
*arg_sym
;
5733 /* Set true when we find a matching non-argument symbol. */
5739 for (sym
= block_iter_match_first (block
, lookup_name
, &iter
);
5741 sym
= block_iter_match_next (lookup_name
, &iter
))
5743 if (symbol_matches_domain (sym
->language (), SYMBOL_DOMAIN (sym
), domain
))
5745 if (SYMBOL_CLASS (sym
) != LOC_UNRESOLVED
)
5747 if (SYMBOL_IS_ARGUMENT (sym
))
5752 add_defn_to_vec (result
,
5753 fixup_symbol_section (sym
, objfile
),
5760 /* Handle renamings. */
5762 if (ada_add_block_renamings (result
, block
, lookup_name
, domain
))
5765 if (!found_sym
&& arg_sym
!= NULL
)
5767 add_defn_to_vec (result
,
5768 fixup_symbol_section (arg_sym
, objfile
),
5772 if (!lookup_name
.ada ().wild_match_p ())
5776 const std::string
&ada_lookup_name
= lookup_name
.ada ().lookup_name ();
5777 const char *name
= ada_lookup_name
.c_str ();
5778 size_t name_len
= ada_lookup_name
.size ();
5780 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
5782 if (symbol_matches_domain (sym
->language (),
5783 SYMBOL_DOMAIN (sym
), domain
))
5787 cmp
= (int) '_' - (int) sym
->linkage_name ()[0];
5790 cmp
= !startswith (sym
->linkage_name (), "_ada_");
5792 cmp
= strncmp (name
, sym
->linkage_name () + 5,
5797 && is_name_suffix (sym
->linkage_name () + name_len
+ 5))
5799 if (SYMBOL_CLASS (sym
) != LOC_UNRESOLVED
)
5801 if (SYMBOL_IS_ARGUMENT (sym
))
5806 add_defn_to_vec (result
,
5807 fixup_symbol_section (sym
, objfile
),
5815 /* NOTE: This really shouldn't be needed for _ada_ symbols.
5816 They aren't parameters, right? */
5817 if (!found_sym
&& arg_sym
!= NULL
)
5819 add_defn_to_vec (result
,
5820 fixup_symbol_section (arg_sym
, objfile
),
5827 /* Symbol Completion */
5832 ada_lookup_name_info::matches
5833 (const char *sym_name
,
5834 symbol_name_match_type match_type
,
5835 completion_match_result
*comp_match_res
) const
5838 const char *text
= m_encoded_name
.c_str ();
5839 size_t text_len
= m_encoded_name
.size ();
5841 /* First, test against the fully qualified name of the symbol. */
5843 if (strncmp (sym_name
, text
, text_len
) == 0)
5846 std::string decoded_name
= ada_decode (sym_name
);
5847 if (match
&& !m_encoded_p
)
5849 /* One needed check before declaring a positive match is to verify
5850 that iff we are doing a verbatim match, the decoded version
5851 of the symbol name starts with '<'. Otherwise, this symbol name
5852 is not a suitable completion. */
5854 bool has_angle_bracket
= (decoded_name
[0] == '<');
5855 match
= (has_angle_bracket
== m_verbatim_p
);
5858 if (match
&& !m_verbatim_p
)
5860 /* When doing non-verbatim match, another check that needs to
5861 be done is to verify that the potentially matching symbol name
5862 does not include capital letters, because the ada-mode would
5863 not be able to understand these symbol names without the
5864 angle bracket notation. */
5867 for (tmp
= sym_name
; *tmp
!= '\0' && !isupper (*tmp
); tmp
++);
5872 /* Second: Try wild matching... */
5874 if (!match
&& m_wild_match_p
)
5876 /* Since we are doing wild matching, this means that TEXT
5877 may represent an unqualified symbol name. We therefore must
5878 also compare TEXT against the unqualified name of the symbol. */
5879 sym_name
= ada_unqualified_name (decoded_name
.c_str ());
5881 if (strncmp (sym_name
, text
, text_len
) == 0)
5885 /* Finally: If we found a match, prepare the result to return. */
5890 if (comp_match_res
!= NULL
)
5892 std::string
&match_str
= comp_match_res
->match
.storage ();
5895 match_str
= ada_decode (sym_name
);
5899 match_str
= add_angle_brackets (sym_name
);
5901 match_str
= sym_name
;
5905 comp_match_res
->set_match (match_str
.c_str ());
5913 /* Return non-zero if TYPE is a pointer to the GNAT dispatch table used
5914 for tagged types. */
5917 ada_is_dispatch_table_ptr_type (struct type
*type
)
5921 if (type
->code () != TYPE_CODE_PTR
)
5924 name
= TYPE_TARGET_TYPE (type
)->name ();
5928 return (strcmp (name
, "ada__tags__dispatch_table") == 0);
5931 /* Return non-zero if TYPE is an interface tag. */
5934 ada_is_interface_tag (struct type
*type
)
5936 const char *name
= type
->name ();
5941 return (strcmp (name
, "ada__tags__interface_tag") == 0);
5944 /* True if field number FIELD_NUM in struct or union type TYPE is supposed
5945 to be invisible to users. */
5948 ada_is_ignored_field (struct type
*type
, int field_num
)
5950 if (field_num
< 0 || field_num
> type
->num_fields ())
5953 /* Check the name of that field. */
5955 const char *name
= type
->field (field_num
).name ();
5957 /* Anonymous field names should not be printed.
5958 brobecker/2007-02-20: I don't think this can actually happen
5959 but we don't want to print the value of anonymous fields anyway. */
5963 /* Normally, fields whose name start with an underscore ("_")
5964 are fields that have been internally generated by the compiler,
5965 and thus should not be printed. The "_parent" field is special,
5966 however: This is a field internally generated by the compiler
5967 for tagged types, and it contains the components inherited from
5968 the parent type. This field should not be printed as is, but
5969 should not be ignored either. */
5970 if (name
[0] == '_' && !startswith (name
, "_parent"))
5974 /* If this is the dispatch table of a tagged type or an interface tag,
5976 if (ada_is_tagged_type (type
, 1)
5977 && (ada_is_dispatch_table_ptr_type (type
->field (field_num
).type ())
5978 || ada_is_interface_tag (type
->field (field_num
).type ())))
5981 /* Not a special field, so it should not be ignored. */
5985 /* True iff TYPE has a tag field. If REFOK, then TYPE may also be a
5986 pointer or reference type whose ultimate target has a tag field. */
5989 ada_is_tagged_type (struct type
*type
, int refok
)
5991 return (ada_lookup_struct_elt_type (type
, "_tag", refok
, 1) != NULL
);
5994 /* True iff TYPE represents the type of X'Tag */
5997 ada_is_tag_type (struct type
*type
)
5999 type
= ada_check_typedef (type
);
6001 if (type
== NULL
|| type
->code () != TYPE_CODE_PTR
)
6005 const char *name
= ada_type_name (TYPE_TARGET_TYPE (type
));
6007 return (name
!= NULL
6008 && strcmp (name
, "ada__tags__dispatch_table") == 0);
6012 /* The type of the tag on VAL. */
6014 static struct type
*
6015 ada_tag_type (struct value
*val
)
6017 return ada_lookup_struct_elt_type (value_type (val
), "_tag", 1, 0);
6020 /* Return 1 if TAG follows the old scheme for Ada tags (used for Ada 95,
6021 retired at Ada 05). */
6024 is_ada95_tag (struct value
*tag
)
6026 return ada_value_struct_elt (tag
, "tsd", 1) != NULL
;
6029 /* The value of the tag on VAL. */
6031 static struct value
*
6032 ada_value_tag (struct value
*val
)
6034 return ada_value_struct_elt (val
, "_tag", 0);
6037 /* The value of the tag on the object of type TYPE whose contents are
6038 saved at VALADDR, if it is non-null, or is at memory address
6041 static struct value
*
6042 value_tag_from_contents_and_address (struct type
*type
,
6043 const gdb_byte
*valaddr
,
6046 int tag_byte_offset
;
6047 struct type
*tag_type
;
6049 gdb::array_view
<const gdb_byte
> contents
;
6050 if (valaddr
!= nullptr)
6051 contents
= gdb::make_array_view (valaddr
, TYPE_LENGTH (type
));
6052 struct type
*resolved_type
= resolve_dynamic_type (type
, contents
, address
);
6053 if (find_struct_field ("_tag", resolved_type
, 0, &tag_type
, &tag_byte_offset
,
6056 const gdb_byte
*valaddr1
= ((valaddr
== NULL
)
6058 : valaddr
+ tag_byte_offset
);
6059 CORE_ADDR address1
= (address
== 0) ? 0 : address
+ tag_byte_offset
;
6061 return value_from_contents_and_address (tag_type
, valaddr1
, address1
);
6066 static struct type
*
6067 type_from_tag (struct value
*tag
)
6069 gdb::unique_xmalloc_ptr
<char> type_name
= ada_tag_name (tag
);
6071 if (type_name
!= NULL
)
6072 return ada_find_any_type (ada_encode (type_name
.get ()).c_str ());
6076 /* Given a value OBJ of a tagged type, return a value of this
6077 type at the base address of the object. The base address, as
6078 defined in Ada.Tags, it is the address of the primary tag of
6079 the object, and therefore where the field values of its full
6080 view can be fetched. */
6083 ada_tag_value_at_base_address (struct value
*obj
)
6086 LONGEST offset_to_top
= 0;
6087 struct type
*ptr_type
, *obj_type
;
6089 CORE_ADDR base_address
;
6091 obj_type
= value_type (obj
);
6093 /* It is the responsability of the caller to deref pointers. */
6095 if (obj_type
->code () == TYPE_CODE_PTR
|| obj_type
->code () == TYPE_CODE_REF
)
6098 tag
= ada_value_tag (obj
);
6102 /* Base addresses only appeared with Ada 05 and multiple inheritance. */
6104 if (is_ada95_tag (tag
))
6107 ptr_type
= language_lookup_primitive_type
6108 (language_def (language_ada
), target_gdbarch(), "storage_offset");
6109 ptr_type
= lookup_pointer_type (ptr_type
);
6110 val
= value_cast (ptr_type
, tag
);
6114 /* It is perfectly possible that an exception be raised while
6115 trying to determine the base address, just like for the tag;
6116 see ada_tag_name for more details. We do not print the error
6117 message for the same reason. */
6121 offset_to_top
= value_as_long (value_ind (value_ptradd (val
, -2)));
6124 catch (const gdb_exception_error
&e
)
6129 /* If offset is null, nothing to do. */
6131 if (offset_to_top
== 0)
6134 /* -1 is a special case in Ada.Tags; however, what should be done
6135 is not quite clear from the documentation. So do nothing for
6138 if (offset_to_top
== -1)
6141 /* OFFSET_TO_TOP used to be a positive value to be subtracted
6142 from the base address. This was however incompatible with
6143 C++ dispatch table: C++ uses a *negative* value to *add*
6144 to the base address. Ada's convention has therefore been
6145 changed in GNAT 19.0w 20171023: since then, C++ and Ada
6146 use the same convention. Here, we support both cases by
6147 checking the sign of OFFSET_TO_TOP. */
6149 if (offset_to_top
> 0)
6150 offset_to_top
= -offset_to_top
;
6152 base_address
= value_address (obj
) + offset_to_top
;
6153 tag
= value_tag_from_contents_and_address (obj_type
, NULL
, base_address
);
6155 /* Make sure that we have a proper tag at the new address.
6156 Otherwise, offset_to_top is bogus (which can happen when
6157 the object is not initialized yet). */
6162 obj_type
= type_from_tag (tag
);
6167 return value_from_contents_and_address (obj_type
, NULL
, base_address
);
6170 /* Return the "ada__tags__type_specific_data" type. */
6172 static struct type
*
6173 ada_get_tsd_type (struct inferior
*inf
)
6175 struct ada_inferior_data
*data
= get_ada_inferior_data (inf
);
6177 if (data
->tsd_type
== 0)
6178 data
->tsd_type
= ada_find_any_type ("ada__tags__type_specific_data");
6179 return data
->tsd_type
;
6182 /* Return the TSD (type-specific data) associated to the given TAG.
6183 TAG is assumed to be the tag of a tagged-type entity.
6185 May return NULL if we are unable to get the TSD. */
6187 static struct value
*
6188 ada_get_tsd_from_tag (struct value
*tag
)
6193 /* First option: The TSD is simply stored as a field of our TAG.
6194 Only older versions of GNAT would use this format, but we have
6195 to test it first, because there are no visible markers for
6196 the current approach except the absence of that field. */
6198 val
= ada_value_struct_elt (tag
, "tsd", 1);
6202 /* Try the second representation for the dispatch table (in which
6203 there is no explicit 'tsd' field in the referent of the tag pointer,
6204 and instead the tsd pointer is stored just before the dispatch
6207 type
= ada_get_tsd_type (current_inferior());
6210 type
= lookup_pointer_type (lookup_pointer_type (type
));
6211 val
= value_cast (type
, tag
);
6214 return value_ind (value_ptradd (val
, -1));
6217 /* Given the TSD of a tag (type-specific data), return a string
6218 containing the name of the associated type.
6220 May return NULL if we are unable to determine the tag name. */
6222 static gdb::unique_xmalloc_ptr
<char>
6223 ada_tag_name_from_tsd (struct value
*tsd
)
6228 val
= ada_value_struct_elt (tsd
, "expanded_name", 1);
6231 gdb::unique_xmalloc_ptr
<char> buffer
6232 = target_read_string (value_as_address (val
), INT_MAX
);
6233 if (buffer
== nullptr)
6236 for (p
= buffer
.get (); *p
!= '\0'; ++p
)
6245 /* The type name of the dynamic type denoted by the 'tag value TAG, as
6248 Return NULL if the TAG is not an Ada tag, or if we were unable to
6249 determine the name of that tag. */
6251 gdb::unique_xmalloc_ptr
<char>
6252 ada_tag_name (struct value
*tag
)
6254 gdb::unique_xmalloc_ptr
<char> name
;
6256 if (!ada_is_tag_type (value_type (tag
)))
6259 /* It is perfectly possible that an exception be raised while trying
6260 to determine the TAG's name, even under normal circumstances:
6261 The associated variable may be uninitialized or corrupted, for
6262 instance. We do not let any exception propagate past this point.
6263 instead we return NULL.
6265 We also do not print the error message either (which often is very
6266 low-level (Eg: "Cannot read memory at 0x[...]"), but instead let
6267 the caller print a more meaningful message if necessary. */
6270 struct value
*tsd
= ada_get_tsd_from_tag (tag
);
6273 name
= ada_tag_name_from_tsd (tsd
);
6275 catch (const gdb_exception_error
&e
)
6282 /* The parent type of TYPE, or NULL if none. */
6285 ada_parent_type (struct type
*type
)
6289 type
= ada_check_typedef (type
);
6291 if (type
== NULL
|| type
->code () != TYPE_CODE_STRUCT
)
6294 for (i
= 0; i
< type
->num_fields (); i
+= 1)
6295 if (ada_is_parent_field (type
, i
))
6297 struct type
*parent_type
= type
->field (i
).type ();
6299 /* If the _parent field is a pointer, then dereference it. */
6300 if (parent_type
->code () == TYPE_CODE_PTR
)
6301 parent_type
= TYPE_TARGET_TYPE (parent_type
);
6302 /* If there is a parallel XVS type, get the actual base type. */
6303 parent_type
= ada_get_base_type (parent_type
);
6305 return ada_check_typedef (parent_type
);
6311 /* True iff field number FIELD_NUM of structure type TYPE contains the
6312 parent-type (inherited) fields of a derived type. Assumes TYPE is
6313 a structure type with at least FIELD_NUM+1 fields. */
6316 ada_is_parent_field (struct type
*type
, int field_num
)
6318 const char *name
= ada_check_typedef (type
)->field (field_num
).name ();
6320 return (name
!= NULL
6321 && (startswith (name
, "PARENT")
6322 || startswith (name
, "_parent")));
6325 /* True iff field number FIELD_NUM of structure type TYPE is a
6326 transparent wrapper field (which should be silently traversed when doing
6327 field selection and flattened when printing). Assumes TYPE is a
6328 structure type with at least FIELD_NUM+1 fields. Such fields are always
6332 ada_is_wrapper_field (struct type
*type
, int field_num
)
6334 const char *name
= type
->field (field_num
).name ();
6336 if (name
!= NULL
&& strcmp (name
, "RETVAL") == 0)
6338 /* This happens in functions with "out" or "in out" parameters
6339 which are passed by copy. For such functions, GNAT describes
6340 the function's return type as being a struct where the return
6341 value is in a field called RETVAL, and where the other "out"
6342 or "in out" parameters are fields of that struct. This is not
6347 return (name
!= NULL
6348 && (startswith (name
, "PARENT")
6349 || strcmp (name
, "REP") == 0
6350 || startswith (name
, "_parent")
6351 || name
[0] == 'S' || name
[0] == 'R' || name
[0] == 'O'));
6354 /* True iff field number FIELD_NUM of structure or union type TYPE
6355 is a variant wrapper. Assumes TYPE is a structure type with at least
6356 FIELD_NUM+1 fields. */
6359 ada_is_variant_part (struct type
*type
, int field_num
)
6361 /* Only Ada types are eligible. */
6362 if (!ADA_TYPE_P (type
))
6365 struct type
*field_type
= type
->field (field_num
).type ();
6367 return (field_type
->code () == TYPE_CODE_UNION
6368 || (is_dynamic_field (type
, field_num
)
6369 && (TYPE_TARGET_TYPE (field_type
)->code ()
6370 == TYPE_CODE_UNION
)));
6373 /* Assuming that VAR_TYPE is a variant wrapper (type of the variant part)
6374 whose discriminants are contained in the record type OUTER_TYPE,
6375 returns the type of the controlling discriminant for the variant.
6376 May return NULL if the type could not be found. */
6379 ada_variant_discrim_type (struct type
*var_type
, struct type
*outer_type
)
6381 const char *name
= ada_variant_discrim_name (var_type
);
6383 return ada_lookup_struct_elt_type (outer_type
, name
, 1, 1);
6386 /* Assuming that TYPE is the type of a variant wrapper, and FIELD_NUM is a
6387 valid field number within it, returns 1 iff field FIELD_NUM of TYPE
6388 represents a 'when others' clause; otherwise 0. */
6391 ada_is_others_clause (struct type
*type
, int field_num
)
6393 const char *name
= type
->field (field_num
).name ();
6395 return (name
!= NULL
&& name
[0] == 'O');
6398 /* Assuming that TYPE0 is the type of the variant part of a record,
6399 returns the name of the discriminant controlling the variant.
6400 The value is valid until the next call to ada_variant_discrim_name. */
6403 ada_variant_discrim_name (struct type
*type0
)
6405 static std::string result
;
6408 const char *discrim_end
;
6409 const char *discrim_start
;
6411 if (type0
->code () == TYPE_CODE_PTR
)
6412 type
= TYPE_TARGET_TYPE (type0
);
6416 name
= ada_type_name (type
);
6418 if (name
== NULL
|| name
[0] == '\000')
6421 for (discrim_end
= name
+ strlen (name
) - 6; discrim_end
!= name
;
6424 if (startswith (discrim_end
, "___XVN"))
6427 if (discrim_end
== name
)
6430 for (discrim_start
= discrim_end
; discrim_start
!= name
+ 3;
6433 if (discrim_start
== name
+ 1)
6435 if ((discrim_start
> name
+ 3
6436 && startswith (discrim_start
- 3, "___"))
6437 || discrim_start
[-1] == '.')
6441 result
= std::string (discrim_start
, discrim_end
- discrim_start
);
6442 return result
.c_str ();
6445 /* Scan STR for a subtype-encoded number, beginning at position K.
6446 Put the position of the character just past the number scanned in
6447 *NEW_K, if NEW_K!=NULL. Put the scanned number in *R, if R!=NULL.
6448 Return 1 if there was a valid number at the given position, and 0
6449 otherwise. A "subtype-encoded" number consists of the absolute value
6450 in decimal, followed by the letter 'm' to indicate a negative number.
6451 Assumes 0m does not occur. */
6454 ada_scan_number (const char str
[], int k
, LONGEST
* R
, int *new_k
)
6458 if (!isdigit (str
[k
]))
6461 /* Do it the hard way so as not to make any assumption about
6462 the relationship of unsigned long (%lu scan format code) and
6465 while (isdigit (str
[k
]))
6467 RU
= RU
* 10 + (str
[k
] - '0');
6474 *R
= (-(LONGEST
) (RU
- 1)) - 1;
6480 /* NOTE on the above: Technically, C does not say what the results of
6481 - (LONGEST) RU or (LONGEST) -RU are for RU == largest positive
6482 number representable as a LONGEST (although either would probably work
6483 in most implementations). When RU>0, the locution in the then branch
6484 above is always equivalent to the negative of RU. */
6491 /* Assuming that TYPE is a variant part wrapper type (a VARIANTS field),
6492 and FIELD_NUM is a valid field number within it, returns 1 iff VAL is
6493 in the range encoded by field FIELD_NUM of TYPE; otherwise 0. */
6496 ada_in_variant (LONGEST val
, struct type
*type
, int field_num
)
6498 const char *name
= type
->field (field_num
).name ();
6512 if (!ada_scan_number (name
, p
+ 1, &W
, &p
))
6522 if (!ada_scan_number (name
, p
+ 1, &L
, &p
)
6523 || name
[p
] != 'T' || !ada_scan_number (name
, p
+ 1, &U
, &p
))
6525 if (val
>= L
&& val
<= U
)
6537 /* FIXME: Lots of redundancy below. Try to consolidate. */
6539 /* Given a value ARG1 (offset by OFFSET bytes) of a struct or union type
6540 ARG_TYPE, extract and return the value of one of its (non-static)
6541 fields. FIELDNO says which field. Differs from value_primitive_field
6542 only in that it can handle packed values of arbitrary type. */
6545 ada_value_primitive_field (struct value
*arg1
, int offset
, int fieldno
,
6546 struct type
*arg_type
)
6550 arg_type
= ada_check_typedef (arg_type
);
6551 type
= arg_type
->field (fieldno
).type ();
6553 /* Handle packed fields. It might be that the field is not packed
6554 relative to its containing structure, but the structure itself is
6555 packed; in this case we must take the bit-field path. */
6556 if (TYPE_FIELD_BITSIZE (arg_type
, fieldno
) != 0 || value_bitpos (arg1
) != 0)
6558 int bit_pos
= arg_type
->field (fieldno
).loc_bitpos ();
6559 int bit_size
= TYPE_FIELD_BITSIZE (arg_type
, fieldno
);
6561 return ada_value_primitive_packed_val (arg1
,
6562 value_contents (arg1
).data (),
6563 offset
+ bit_pos
/ 8,
6564 bit_pos
% 8, bit_size
, type
);
6567 return value_primitive_field (arg1
, offset
, fieldno
, arg_type
);
6570 /* Find field with name NAME in object of type TYPE. If found,
6571 set the following for each argument that is non-null:
6572 - *FIELD_TYPE_P to the field's type;
6573 - *BYTE_OFFSET_P to OFFSET + the byte offset of the field within
6574 an object of that type;
6575 - *BIT_OFFSET_P to the bit offset modulo byte size of the field;
6576 - *BIT_SIZE_P to its size in bits if the field is packed, and
6578 If INDEX_P is non-null, increment *INDEX_P by the number of source-visible
6579 fields up to but not including the desired field, or by the total
6580 number of fields if not found. A NULL value of NAME never
6581 matches; the function just counts visible fields in this case.
6583 Notice that we need to handle when a tagged record hierarchy
6584 has some components with the same name, like in this scenario:
6586 type Top_T is tagged record
6592 type Middle_T is new Top.Top_T with record
6593 N : Character := 'a';
6597 type Bottom_T is new Middle.Middle_T with record
6599 C : Character := '5';
6601 A : Character := 'J';
6604 Let's say we now have a variable declared and initialized as follow:
6606 TC : Top_A := new Bottom_T;
6608 And then we use this variable to call this function
6610 procedure Assign (Obj: in out Top_T; TV : Integer);
6614 Assign (Top_T (B), 12);
6616 Now, we're in the debugger, and we're inside that procedure
6617 then and we want to print the value of obj.c:
6619 Usually, the tagged record or one of the parent type owns the
6620 component to print and there's no issue but in this particular
6621 case, what does it mean to ask for Obj.C? Since the actual
6622 type for object is type Bottom_T, it could mean two things: type
6623 component C from the Middle_T view, but also component C from
6624 Bottom_T. So in that "undefined" case, when the component is
6625 not found in the non-resolved type (which includes all the
6626 components of the parent type), then resolve it and see if we
6627 get better luck once expanded.
6629 In the case of homonyms in the derived tagged type, we don't
6630 guaranty anything, and pick the one that's easiest for us
6633 Returns 1 if found, 0 otherwise. */
6636 find_struct_field (const char *name
, struct type
*type
, int offset
,
6637 struct type
**field_type_p
,
6638 int *byte_offset_p
, int *bit_offset_p
, int *bit_size_p
,
6642 int parent_offset
= -1;
6644 type
= ada_check_typedef (type
);
6646 if (field_type_p
!= NULL
)
6647 *field_type_p
= NULL
;
6648 if (byte_offset_p
!= NULL
)
6650 if (bit_offset_p
!= NULL
)
6652 if (bit_size_p
!= NULL
)
6655 for (i
= 0; i
< type
->num_fields (); i
+= 1)
6657 /* These can't be computed using TYPE_FIELD_BITPOS for a dynamic
6658 type. However, we only need the values to be correct when
6659 the caller asks for them. */
6660 int bit_pos
= 0, fld_offset
= 0;
6661 if (byte_offset_p
!= nullptr || bit_offset_p
!= nullptr)
6663 bit_pos
= type
->field (i
).loc_bitpos ();
6664 fld_offset
= offset
+ bit_pos
/ 8;
6667 const char *t_field_name
= type
->field (i
).name ();
6669 if (t_field_name
== NULL
)
6672 else if (ada_is_parent_field (type
, i
))
6674 /* This is a field pointing us to the parent type of a tagged
6675 type. As hinted in this function's documentation, we give
6676 preference to fields in the current record first, so what
6677 we do here is just record the index of this field before
6678 we skip it. If it turns out we couldn't find our field
6679 in the current record, then we'll get back to it and search
6680 inside it whether the field might exist in the parent. */
6686 else if (name
!= NULL
&& field_name_match (t_field_name
, name
))
6688 int bit_size
= TYPE_FIELD_BITSIZE (type
, i
);
6690 if (field_type_p
!= NULL
)
6691 *field_type_p
= type
->field (i
).type ();
6692 if (byte_offset_p
!= NULL
)
6693 *byte_offset_p
= fld_offset
;
6694 if (bit_offset_p
!= NULL
)
6695 *bit_offset_p
= bit_pos
% 8;
6696 if (bit_size_p
!= NULL
)
6697 *bit_size_p
= bit_size
;
6700 else if (ada_is_wrapper_field (type
, i
))
6702 if (find_struct_field (name
, type
->field (i
).type (), fld_offset
,
6703 field_type_p
, byte_offset_p
, bit_offset_p
,
6704 bit_size_p
, index_p
))
6707 else if (ada_is_variant_part (type
, i
))
6709 /* PNH: Wait. Do we ever execute this section, or is ARG always of
6712 struct type
*field_type
6713 = ada_check_typedef (type
->field (i
).type ());
6715 for (j
= 0; j
< field_type
->num_fields (); j
+= 1)
6717 if (find_struct_field (name
, field_type
->field (j
).type (),
6719 + field_type
->field (j
).loc_bitpos () / 8,
6720 field_type_p
, byte_offset_p
,
6721 bit_offset_p
, bit_size_p
, index_p
))
6725 else if (index_p
!= NULL
)
6729 /* Field not found so far. If this is a tagged type which
6730 has a parent, try finding that field in the parent now. */
6732 if (parent_offset
!= -1)
6734 /* As above, only compute the offset when truly needed. */
6735 int fld_offset
= offset
;
6736 if (byte_offset_p
!= nullptr || bit_offset_p
!= nullptr)
6738 int bit_pos
= type
->field (parent_offset
).loc_bitpos ();
6739 fld_offset
+= bit_pos
/ 8;
6742 if (find_struct_field (name
, type
->field (parent_offset
).type (),
6743 fld_offset
, field_type_p
, byte_offset_p
,
6744 bit_offset_p
, bit_size_p
, index_p
))
6751 /* Number of user-visible fields in record type TYPE. */
6754 num_visible_fields (struct type
*type
)
6759 find_struct_field (NULL
, type
, 0, NULL
, NULL
, NULL
, NULL
, &n
);
6763 /* Look for a field NAME in ARG. Adjust the address of ARG by OFFSET bytes,
6764 and search in it assuming it has (class) type TYPE.
6765 If found, return value, else return NULL.
6767 Searches recursively through wrapper fields (e.g., '_parent').
6769 In the case of homonyms in the tagged types, please refer to the
6770 long explanation in find_struct_field's function documentation. */
6772 static struct value
*
6773 ada_search_struct_field (const char *name
, struct value
*arg
, int offset
,
6777 int parent_offset
= -1;
6779 type
= ada_check_typedef (type
);
6780 for (i
= 0; i
< type
->num_fields (); i
+= 1)
6782 const char *t_field_name
= type
->field (i
).name ();
6784 if (t_field_name
== NULL
)
6787 else if (ada_is_parent_field (type
, i
))
6789 /* This is a field pointing us to the parent type of a tagged
6790 type. As hinted in this function's documentation, we give
6791 preference to fields in the current record first, so what
6792 we do here is just record the index of this field before
6793 we skip it. If it turns out we couldn't find our field
6794 in the current record, then we'll get back to it and search
6795 inside it whether the field might exist in the parent. */
6801 else if (field_name_match (t_field_name
, name
))
6802 return ada_value_primitive_field (arg
, offset
, i
, type
);
6804 else if (ada_is_wrapper_field (type
, i
))
6806 struct value
*v
= /* Do not let indent join lines here. */
6807 ada_search_struct_field (name
, arg
,
6808 offset
+ type
->field (i
).loc_bitpos () / 8,
6809 type
->field (i
).type ());
6815 else if (ada_is_variant_part (type
, i
))
6817 /* PNH: Do we ever get here? See find_struct_field. */
6819 struct type
*field_type
= ada_check_typedef (type
->field (i
).type ());
6820 int var_offset
= offset
+ type
->field (i
).loc_bitpos () / 8;
6822 for (j
= 0; j
< field_type
->num_fields (); j
+= 1)
6824 struct value
*v
= ada_search_struct_field
/* Force line
6827 var_offset
+ field_type
->field (j
).loc_bitpos () / 8,
6828 field_type
->field (j
).type ());
6836 /* Field not found so far. If this is a tagged type which
6837 has a parent, try finding that field in the parent now. */
6839 if (parent_offset
!= -1)
6841 struct value
*v
= ada_search_struct_field (
6842 name
, arg
, offset
+ type
->field (parent_offset
).loc_bitpos () / 8,
6843 type
->field (parent_offset
).type ());
6852 static struct value
*ada_index_struct_field_1 (int *, struct value
*,
6853 int, struct type
*);
6856 /* Return field #INDEX in ARG, where the index is that returned by
6857 * find_struct_field through its INDEX_P argument. Adjust the address
6858 * of ARG by OFFSET bytes, and search in it assuming it has (class) type TYPE.
6859 * If found, return value, else return NULL. */
6861 static struct value
*
6862 ada_index_struct_field (int index
, struct value
*arg
, int offset
,
6865 return ada_index_struct_field_1 (&index
, arg
, offset
, type
);
6869 /* Auxiliary function for ada_index_struct_field. Like
6870 * ada_index_struct_field, but takes index from *INDEX_P and modifies
6873 static struct value
*
6874 ada_index_struct_field_1 (int *index_p
, struct value
*arg
, int offset
,
6878 type
= ada_check_typedef (type
);
6880 for (i
= 0; i
< type
->num_fields (); i
+= 1)
6882 if (type
->field (i
).name () == NULL
)
6884 else if (ada_is_wrapper_field (type
, i
))
6886 struct value
*v
= /* Do not let indent join lines here. */
6887 ada_index_struct_field_1 (index_p
, arg
,
6888 offset
+ type
->field (i
).loc_bitpos () / 8,
6889 type
->field (i
).type ());
6895 else if (ada_is_variant_part (type
, i
))
6897 /* PNH: Do we ever get here? See ada_search_struct_field,
6898 find_struct_field. */
6899 error (_("Cannot assign this kind of variant record"));
6901 else if (*index_p
== 0)
6902 return ada_value_primitive_field (arg
, offset
, i
, type
);
6909 /* Return a string representation of type TYPE. */
6912 type_as_string (struct type
*type
)
6914 string_file tmp_stream
;
6916 type_print (type
, "", &tmp_stream
, -1);
6918 return std::move (tmp_stream
.string ());
6921 /* Given a type TYPE, look up the type of the component of type named NAME.
6922 If DISPP is non-null, add its byte displacement from the beginning of a
6923 structure (pointed to by a value) of type TYPE to *DISPP (does not
6924 work for packed fields).
6926 Matches any field whose name has NAME as a prefix, possibly
6929 TYPE can be either a struct or union. If REFOK, TYPE may also
6930 be a (pointer or reference)+ to a struct or union, and the
6931 ultimate target type will be searched.
6933 Looks recursively into variant clauses and parent types.
6935 In the case of homonyms in the tagged types, please refer to the
6936 long explanation in find_struct_field's function documentation.
6938 If NOERR is nonzero, return NULL if NAME is not suitably defined or
6939 TYPE is not a type of the right kind. */
6941 static struct type
*
6942 ada_lookup_struct_elt_type (struct type
*type
, const char *name
, int refok
,
6946 int parent_offset
= -1;
6951 if (refok
&& type
!= NULL
)
6954 type
= ada_check_typedef (type
);
6955 if (type
->code () != TYPE_CODE_PTR
&& type
->code () != TYPE_CODE_REF
)
6957 type
= TYPE_TARGET_TYPE (type
);
6961 || (type
->code () != TYPE_CODE_STRUCT
6962 && type
->code () != TYPE_CODE_UNION
))
6967 error (_("Type %s is not a structure or union type"),
6968 type
!= NULL
? type_as_string (type
).c_str () : _("(null)"));
6971 type
= to_static_fixed_type (type
);
6973 for (i
= 0; i
< type
->num_fields (); i
+= 1)
6975 const char *t_field_name
= type
->field (i
).name ();
6978 if (t_field_name
== NULL
)
6981 else if (ada_is_parent_field (type
, i
))
6983 /* This is a field pointing us to the parent type of a tagged
6984 type. As hinted in this function's documentation, we give
6985 preference to fields in the current record first, so what
6986 we do here is just record the index of this field before
6987 we skip it. If it turns out we couldn't find our field
6988 in the current record, then we'll get back to it and search
6989 inside it whether the field might exist in the parent. */
6995 else if (field_name_match (t_field_name
, name
))
6996 return type
->field (i
).type ();
6998 else if (ada_is_wrapper_field (type
, i
))
7000 t
= ada_lookup_struct_elt_type (type
->field (i
).type (), name
,
7006 else if (ada_is_variant_part (type
, i
))
7009 struct type
*field_type
= ada_check_typedef (type
->field (i
).type ());
7011 for (j
= field_type
->num_fields () - 1; j
>= 0; j
-= 1)
7013 /* FIXME pnh 2008/01/26: We check for a field that is
7014 NOT wrapped in a struct, since the compiler sometimes
7015 generates these for unchecked variant types. Revisit
7016 if the compiler changes this practice. */
7017 const char *v_field_name
= field_type
->field (j
).name ();
7019 if (v_field_name
!= NULL
7020 && field_name_match (v_field_name
, name
))
7021 t
= field_type
->field (j
).type ();
7023 t
= ada_lookup_struct_elt_type (field_type
->field (j
).type (),
7033 /* Field not found so far. If this is a tagged type which
7034 has a parent, try finding that field in the parent now. */
7036 if (parent_offset
!= -1)
7040 t
= ada_lookup_struct_elt_type (type
->field (parent_offset
).type (),
7049 const char *name_str
= name
!= NULL
? name
: _("<null>");
7051 error (_("Type %s has no component named %s"),
7052 type_as_string (type
).c_str (), name_str
);
7058 /* Assuming that VAR_TYPE is the type of a variant part of a record (a union),
7059 within a value of type OUTER_TYPE, return true iff VAR_TYPE
7060 represents an unchecked union (that is, the variant part of a
7061 record that is named in an Unchecked_Union pragma). */
7064 is_unchecked_variant (struct type
*var_type
, struct type
*outer_type
)
7066 const char *discrim_name
= ada_variant_discrim_name (var_type
);
7068 return (ada_lookup_struct_elt_type (outer_type
, discrim_name
, 0, 1) == NULL
);
7072 /* Assuming that VAR_TYPE is the type of a variant part of a record (a union),
7073 within OUTER, determine which variant clause (field number in VAR_TYPE,
7074 numbering from 0) is applicable. Returns -1 if none are. */
7077 ada_which_variant_applies (struct type
*var_type
, struct value
*outer
)
7081 const char *discrim_name
= ada_variant_discrim_name (var_type
);
7082 struct value
*discrim
;
7083 LONGEST discrim_val
;
7085 /* Using plain value_from_contents_and_address here causes problems
7086 because we will end up trying to resolve a type that is currently
7087 being constructed. */
7088 discrim
= ada_value_struct_elt (outer
, discrim_name
, 1);
7089 if (discrim
== NULL
)
7091 discrim_val
= value_as_long (discrim
);
7094 for (i
= 0; i
< var_type
->num_fields (); i
+= 1)
7096 if (ada_is_others_clause (var_type
, i
))
7098 else if (ada_in_variant (discrim_val
, var_type
, i
))
7102 return others_clause
;
7107 /* Dynamic-Sized Records */
7109 /* Strategy: The type ostensibly attached to a value with dynamic size
7110 (i.e., a size that is not statically recorded in the debugging
7111 data) does not accurately reflect the size or layout of the value.
7112 Our strategy is to convert these values to values with accurate,
7113 conventional types that are constructed on the fly. */
7115 /* There is a subtle and tricky problem here. In general, we cannot
7116 determine the size of dynamic records without its data. However,
7117 the 'struct value' data structure, which GDB uses to represent
7118 quantities in the inferior process (the target), requires the size
7119 of the type at the time of its allocation in order to reserve space
7120 for GDB's internal copy of the data. That's why the
7121 'to_fixed_xxx_type' routines take (target) addresses as parameters,
7122 rather than struct value*s.
7124 However, GDB's internal history variables ($1, $2, etc.) are
7125 struct value*s containing internal copies of the data that are not, in
7126 general, the same as the data at their corresponding addresses in
7127 the target. Fortunately, the types we give to these values are all
7128 conventional, fixed-size types (as per the strategy described
7129 above), so that we don't usually have to perform the
7130 'to_fixed_xxx_type' conversions to look at their values.
7131 Unfortunately, there is one exception: if one of the internal
7132 history variables is an array whose elements are unconstrained
7133 records, then we will need to create distinct fixed types for each
7134 element selected. */
7136 /* The upshot of all of this is that many routines take a (type, host
7137 address, target address) triple as arguments to represent a value.
7138 The host address, if non-null, is supposed to contain an internal
7139 copy of the relevant data; otherwise, the program is to consult the
7140 target at the target address. */
7142 /* Assuming that VAL0 represents a pointer value, the result of
7143 dereferencing it. Differs from value_ind in its treatment of
7144 dynamic-sized types. */
7147 ada_value_ind (struct value
*val0
)
7149 struct value
*val
= value_ind (val0
);
7151 if (ada_is_tagged_type (value_type (val
), 0))
7152 val
= ada_tag_value_at_base_address (val
);
7154 return ada_to_fixed_value (val
);
7157 /* The value resulting from dereferencing any "reference to"
7158 qualifiers on VAL0. */
7160 static struct value
*
7161 ada_coerce_ref (struct value
*val0
)
7163 if (value_type (val0
)->code () == TYPE_CODE_REF
)
7165 struct value
*val
= val0
;
7167 val
= coerce_ref (val
);
7169 if (ada_is_tagged_type (value_type (val
), 0))
7170 val
= ada_tag_value_at_base_address (val
);
7172 return ada_to_fixed_value (val
);
7178 /* Return the bit alignment required for field #F of template type TYPE. */
7181 field_alignment (struct type
*type
, int f
)
7183 const char *name
= type
->field (f
).name ();
7187 /* The field name should never be null, unless the debugging information
7188 is somehow malformed. In this case, we assume the field does not
7189 require any alignment. */
7193 len
= strlen (name
);
7195 if (!isdigit (name
[len
- 1]))
7198 if (isdigit (name
[len
- 2]))
7199 align_offset
= len
- 2;
7201 align_offset
= len
- 1;
7203 if (align_offset
< 7 || !startswith (name
+ align_offset
- 6, "___XV"))
7204 return TARGET_CHAR_BIT
;
7206 return atoi (name
+ align_offset
) * TARGET_CHAR_BIT
;
7209 /* Find a typedef or tag symbol named NAME. Ignores ambiguity. */
7211 static struct symbol
*
7212 ada_find_any_type_symbol (const char *name
)
7216 sym
= standard_lookup (name
, get_selected_block (NULL
), VAR_DOMAIN
);
7217 if (sym
!= NULL
&& SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
7220 sym
= standard_lookup (name
, NULL
, STRUCT_DOMAIN
);
7224 /* Find a type named NAME. Ignores ambiguity. This routine will look
7225 solely for types defined by debug info, it will not search the GDB
7228 static struct type
*
7229 ada_find_any_type (const char *name
)
7231 struct symbol
*sym
= ada_find_any_type_symbol (name
);
7234 return SYMBOL_TYPE (sym
);
7239 /* Given NAME_SYM and an associated BLOCK, find a "renaming" symbol
7240 associated with NAME_SYM's name. NAME_SYM may itself be a renaming
7241 symbol, in which case it is returned. Otherwise, this looks for
7242 symbols whose name is that of NAME_SYM suffixed with "___XR".
7243 Return symbol if found, and NULL otherwise. */
7246 ada_is_renaming_symbol (struct symbol
*name_sym
)
7248 const char *name
= name_sym
->linkage_name ();
7249 return strstr (name
, "___XR") != NULL
;
7252 /* Because of GNAT encoding conventions, several GDB symbols may match a
7253 given type name. If the type denoted by TYPE0 is to be preferred to
7254 that of TYPE1 for purposes of type printing, return non-zero;
7255 otherwise return 0. */
7258 ada_prefer_type (struct type
*type0
, struct type
*type1
)
7262 else if (type0
== NULL
)
7264 else if (type1
->code () == TYPE_CODE_VOID
)
7266 else if (type0
->code () == TYPE_CODE_VOID
)
7268 else if (type1
->name () == NULL
&& type0
->name () != NULL
)
7270 else if (ada_is_constrained_packed_array_type (type0
))
7272 else if (ada_is_array_descriptor_type (type0
)
7273 && !ada_is_array_descriptor_type (type1
))
7277 const char *type0_name
= type0
->name ();
7278 const char *type1_name
= type1
->name ();
7280 if (type0_name
!= NULL
&& strstr (type0_name
, "___XR") != NULL
7281 && (type1_name
== NULL
|| strstr (type1_name
, "___XR") == NULL
))
7287 /* The name of TYPE, which is its TYPE_NAME. Null if TYPE is
7291 ada_type_name (struct type
*type
)
7295 return type
->name ();
7298 /* Search the list of "descriptive" types associated to TYPE for a type
7299 whose name is NAME. */
7301 static struct type
*
7302 find_parallel_type_by_descriptive_type (struct type
*type
, const char *name
)
7304 struct type
*result
, *tmp
;
7306 if (ada_ignore_descriptive_types_p
)
7309 /* If there no descriptive-type info, then there is no parallel type
7311 if (!HAVE_GNAT_AUX_INFO (type
))
7314 result
= TYPE_DESCRIPTIVE_TYPE (type
);
7315 while (result
!= NULL
)
7317 const char *result_name
= ada_type_name (result
);
7319 if (result_name
== NULL
)
7321 warning (_("unexpected null name on descriptive type"));
7325 /* If the names match, stop. */
7326 if (strcmp (result_name
, name
) == 0)
7329 /* Otherwise, look at the next item on the list, if any. */
7330 if (HAVE_GNAT_AUX_INFO (result
))
7331 tmp
= TYPE_DESCRIPTIVE_TYPE (result
);
7335 /* If not found either, try after having resolved the typedef. */
7340 result
= check_typedef (result
);
7341 if (HAVE_GNAT_AUX_INFO (result
))
7342 result
= TYPE_DESCRIPTIVE_TYPE (result
);
7348 /* If we didn't find a match, see whether this is a packed array. With
7349 older compilers, the descriptive type information is either absent or
7350 irrelevant when it comes to packed arrays so the above lookup fails.
7351 Fall back to using a parallel lookup by name in this case. */
7352 if (result
== NULL
&& ada_is_constrained_packed_array_type (type
))
7353 return ada_find_any_type (name
);
7358 /* Find a parallel type to TYPE with the specified NAME, using the
7359 descriptive type taken from the debugging information, if available,
7360 and otherwise using the (slower) name-based method. */
7362 static struct type
*
7363 ada_find_parallel_type_with_name (struct type
*type
, const char *name
)
7365 struct type
*result
= NULL
;
7367 if (HAVE_GNAT_AUX_INFO (type
))
7368 result
= find_parallel_type_by_descriptive_type (type
, name
);
7370 result
= ada_find_any_type (name
);
7375 /* Same as above, but specify the name of the parallel type by appending
7376 SUFFIX to the name of TYPE. */
7379 ada_find_parallel_type (struct type
*type
, const char *suffix
)
7382 const char *type_name
= ada_type_name (type
);
7385 if (type_name
== NULL
)
7388 len
= strlen (type_name
);
7390 name
= (char *) alloca (len
+ strlen (suffix
) + 1);
7392 strcpy (name
, type_name
);
7393 strcpy (name
+ len
, suffix
);
7395 return ada_find_parallel_type_with_name (type
, name
);
7398 /* If TYPE is a variable-size record type, return the corresponding template
7399 type describing its fields. Otherwise, return NULL. */
7401 static struct type
*
7402 dynamic_template_type (struct type
*type
)
7404 type
= ada_check_typedef (type
);
7406 if (type
== NULL
|| type
->code () != TYPE_CODE_STRUCT
7407 || ada_type_name (type
) == NULL
)
7411 int len
= strlen (ada_type_name (type
));
7413 if (len
> 6 && strcmp (ada_type_name (type
) + len
- 6, "___XVE") == 0)
7416 return ada_find_parallel_type (type
, "___XVE");
7420 /* Assuming that TEMPL_TYPE is a union or struct type, returns
7421 non-zero iff field FIELD_NUM of TEMPL_TYPE has dynamic size. */
7424 is_dynamic_field (struct type
*templ_type
, int field_num
)
7426 const char *name
= templ_type
->field (field_num
).name ();
7429 && templ_type
->field (field_num
).type ()->code () == TYPE_CODE_PTR
7430 && strstr (name
, "___XVL") != NULL
;
7433 /* The index of the variant field of TYPE, or -1 if TYPE does not
7434 represent a variant record type. */
7437 variant_field_index (struct type
*type
)
7441 if (type
== NULL
|| type
->code () != TYPE_CODE_STRUCT
)
7444 for (f
= 0; f
< type
->num_fields (); f
+= 1)
7446 if (ada_is_variant_part (type
, f
))
7452 /* A record type with no fields. */
7454 static struct type
*
7455 empty_record (struct type
*templ
)
7457 struct type
*type
= alloc_type_copy (templ
);
7459 type
->set_code (TYPE_CODE_STRUCT
);
7460 INIT_NONE_SPECIFIC (type
);
7461 type
->set_name ("<empty>");
7462 TYPE_LENGTH (type
) = 0;
7466 /* An ordinary record type (with fixed-length fields) that describes
7467 the value of type TYPE at VALADDR or ADDRESS (see comments at
7468 the beginning of this section) VAL according to GNAT conventions.
7469 DVAL0 should describe the (portion of a) record that contains any
7470 necessary discriminants. It should be NULL if value_type (VAL) is
7471 an outer-level type (i.e., as opposed to a branch of a variant.) A
7472 variant field (unless unchecked) is replaced by a particular branch
7475 If not KEEP_DYNAMIC_FIELDS, then all fields whose position or
7476 length are not statically known are discarded. As a consequence,
7477 VALADDR, ADDRESS and DVAL0 are ignored.
7479 NOTE: Limitations: For now, we assume that dynamic fields and
7480 variants occupy whole numbers of bytes. However, they need not be
7484 ada_template_to_fixed_record_type_1 (struct type
*type
,
7485 const gdb_byte
*valaddr
,
7486 CORE_ADDR address
, struct value
*dval0
,
7487 int keep_dynamic_fields
)
7489 struct value
*mark
= value_mark ();
7492 int nfields
, bit_len
;
7498 /* Compute the number of fields in this record type that are going
7499 to be processed: unless keep_dynamic_fields, this includes only
7500 fields whose position and length are static will be processed. */
7501 if (keep_dynamic_fields
)
7502 nfields
= type
->num_fields ();
7506 while (nfields
< type
->num_fields ()
7507 && !ada_is_variant_part (type
, nfields
)
7508 && !is_dynamic_field (type
, nfields
))
7512 rtype
= alloc_type_copy (type
);
7513 rtype
->set_code (TYPE_CODE_STRUCT
);
7514 INIT_NONE_SPECIFIC (rtype
);
7515 rtype
->set_num_fields (nfields
);
7517 ((struct field
*) TYPE_ZALLOC (rtype
, nfields
* sizeof (struct field
)));
7518 rtype
->set_name (ada_type_name (type
));
7519 rtype
->set_is_fixed_instance (true);
7525 for (f
= 0; f
< nfields
; f
+= 1)
7527 off
= align_up (off
, field_alignment (type
, f
))
7528 + type
->field (f
).loc_bitpos ();
7529 rtype
->field (f
).set_loc_bitpos (off
);
7530 TYPE_FIELD_BITSIZE (rtype
, f
) = 0;
7532 if (ada_is_variant_part (type
, f
))
7537 else if (is_dynamic_field (type
, f
))
7539 const gdb_byte
*field_valaddr
= valaddr
;
7540 CORE_ADDR field_address
= address
;
7541 struct type
*field_type
=
7542 TYPE_TARGET_TYPE (type
->field (f
).type ());
7546 /* Using plain value_from_contents_and_address here
7547 causes problems because we will end up trying to
7548 resolve a type that is currently being
7550 dval
= value_from_contents_and_address_unresolved (rtype
,
7553 rtype
= value_type (dval
);
7558 /* If the type referenced by this field is an aligner type, we need
7559 to unwrap that aligner type, because its size might not be set.
7560 Keeping the aligner type would cause us to compute the wrong
7561 size for this field, impacting the offset of the all the fields
7562 that follow this one. */
7563 if (ada_is_aligner_type (field_type
))
7565 long field_offset
= type
->field (f
).loc_bitpos ();
7567 field_valaddr
= cond_offset_host (field_valaddr
, field_offset
);
7568 field_address
= cond_offset_target (field_address
, field_offset
);
7569 field_type
= ada_aligned_type (field_type
);
7572 field_valaddr
= cond_offset_host (field_valaddr
,
7573 off
/ TARGET_CHAR_BIT
);
7574 field_address
= cond_offset_target (field_address
,
7575 off
/ TARGET_CHAR_BIT
);
7577 /* Get the fixed type of the field. Note that, in this case,
7578 we do not want to get the real type out of the tag: if
7579 the current field is the parent part of a tagged record,
7580 we will get the tag of the object. Clearly wrong: the real
7581 type of the parent is not the real type of the child. We
7582 would end up in an infinite loop. */
7583 field_type
= ada_get_base_type (field_type
);
7584 field_type
= ada_to_fixed_type (field_type
, field_valaddr
,
7585 field_address
, dval
, 0);
7587 rtype
->field (f
).set_type (field_type
);
7588 rtype
->field (f
).set_name (type
->field (f
).name ());
7589 /* The multiplication can potentially overflow. But because
7590 the field length has been size-checked just above, and
7591 assuming that the maximum size is a reasonable value,
7592 an overflow should not happen in practice. So rather than
7593 adding overflow recovery code to this already complex code,
7594 we just assume that it's not going to happen. */
7596 TYPE_LENGTH (rtype
->field (f
).type ()) * TARGET_CHAR_BIT
;
7600 /* Note: If this field's type is a typedef, it is important
7601 to preserve the typedef layer.
7603 Otherwise, we might be transforming a typedef to a fat
7604 pointer (encoding a pointer to an unconstrained array),
7605 into a basic fat pointer (encoding an unconstrained
7606 array). As both types are implemented using the same
7607 structure, the typedef is the only clue which allows us
7608 to distinguish between the two options. Stripping it
7609 would prevent us from printing this field appropriately. */
7610 rtype
->field (f
).set_type (type
->field (f
).type ());
7611 rtype
->field (f
).set_name (type
->field (f
).name ());
7612 if (TYPE_FIELD_BITSIZE (type
, f
) > 0)
7614 TYPE_FIELD_BITSIZE (rtype
, f
) = TYPE_FIELD_BITSIZE (type
, f
);
7617 struct type
*field_type
= type
->field (f
).type ();
7619 /* We need to be careful of typedefs when computing
7620 the length of our field. If this is a typedef,
7621 get the length of the target type, not the length
7623 if (field_type
->code () == TYPE_CODE_TYPEDEF
)
7624 field_type
= ada_typedef_target_type (field_type
);
7627 TYPE_LENGTH (ada_check_typedef (field_type
)) * TARGET_CHAR_BIT
;
7630 if (off
+ fld_bit_len
> bit_len
)
7631 bit_len
= off
+ fld_bit_len
;
7633 TYPE_LENGTH (rtype
) =
7634 align_up (bit_len
, TARGET_CHAR_BIT
) / TARGET_CHAR_BIT
;
7637 /* We handle the variant part, if any, at the end because of certain
7638 odd cases in which it is re-ordered so as NOT to be the last field of
7639 the record. This can happen in the presence of representation
7641 if (variant_field
>= 0)
7643 struct type
*branch_type
;
7645 off
= rtype
->field (variant_field
).loc_bitpos ();
7649 /* Using plain value_from_contents_and_address here causes
7650 problems because we will end up trying to resolve a type
7651 that is currently being constructed. */
7652 dval
= value_from_contents_and_address_unresolved (rtype
, valaddr
,
7654 rtype
= value_type (dval
);
7660 to_fixed_variant_branch_type
7661 (type
->field (variant_field
).type (),
7662 cond_offset_host (valaddr
, off
/ TARGET_CHAR_BIT
),
7663 cond_offset_target (address
, off
/ TARGET_CHAR_BIT
), dval
);
7664 if (branch_type
== NULL
)
7666 for (f
= variant_field
+ 1; f
< rtype
->num_fields (); f
+= 1)
7667 rtype
->field (f
- 1) = rtype
->field (f
);
7668 rtype
->set_num_fields (rtype
->num_fields () - 1);
7672 rtype
->field (variant_field
).set_type (branch_type
);
7673 rtype
->field (variant_field
).set_name ("S");
7675 TYPE_LENGTH (rtype
->field (variant_field
).type ()) *
7677 if (off
+ fld_bit_len
> bit_len
)
7678 bit_len
= off
+ fld_bit_len
;
7679 TYPE_LENGTH (rtype
) =
7680 align_up (bit_len
, TARGET_CHAR_BIT
) / TARGET_CHAR_BIT
;
7684 /* According to exp_dbug.ads, the size of TYPE for variable-size records
7685 should contain the alignment of that record, which should be a strictly
7686 positive value. If null or negative, then something is wrong, most
7687 probably in the debug info. In that case, we don't round up the size
7688 of the resulting type. If this record is not part of another structure,
7689 the current RTYPE length might be good enough for our purposes. */
7690 if (TYPE_LENGTH (type
) <= 0)
7693 warning (_("Invalid type size for `%s' detected: %s."),
7694 rtype
->name (), pulongest (TYPE_LENGTH (type
)));
7696 warning (_("Invalid type size for <unnamed> detected: %s."),
7697 pulongest (TYPE_LENGTH (type
)));
7701 TYPE_LENGTH (rtype
) = align_up (TYPE_LENGTH (rtype
),
7702 TYPE_LENGTH (type
));
7705 value_free_to_mark (mark
);
7709 /* As for ada_template_to_fixed_record_type_1 with KEEP_DYNAMIC_FIELDS
7712 static struct type
*
7713 template_to_fixed_record_type (struct type
*type
, const gdb_byte
*valaddr
,
7714 CORE_ADDR address
, struct value
*dval0
)
7716 return ada_template_to_fixed_record_type_1 (type
, valaddr
,
7720 /* An ordinary record type in which ___XVL-convention fields and
7721 ___XVU- and ___XVN-convention field types in TYPE0 are replaced with
7722 static approximations, containing all possible fields. Uses
7723 no runtime values. Useless for use in values, but that's OK,
7724 since the results are used only for type determinations. Works on both
7725 structs and unions. Representation note: to save space, we memorize
7726 the result of this function in the TYPE_TARGET_TYPE of the
7729 static struct type
*
7730 template_to_static_fixed_type (struct type
*type0
)
7736 /* No need no do anything if the input type is already fixed. */
7737 if (type0
->is_fixed_instance ())
7740 /* Likewise if we already have computed the static approximation. */
7741 if (TYPE_TARGET_TYPE (type0
) != NULL
)
7742 return TYPE_TARGET_TYPE (type0
);
7744 /* Don't clone TYPE0 until we are sure we are going to need a copy. */
7746 nfields
= type0
->num_fields ();
7748 /* Whether or not we cloned TYPE0, cache the result so that we don't do
7749 recompute all over next time. */
7750 TYPE_TARGET_TYPE (type0
) = type
;
7752 for (f
= 0; f
< nfields
; f
+= 1)
7754 struct type
*field_type
= type0
->field (f
).type ();
7755 struct type
*new_type
;
7757 if (is_dynamic_field (type0
, f
))
7759 field_type
= ada_check_typedef (field_type
);
7760 new_type
= to_static_fixed_type (TYPE_TARGET_TYPE (field_type
));
7763 new_type
= static_unwrap_type (field_type
);
7765 if (new_type
!= field_type
)
7767 /* Clone TYPE0 only the first time we get a new field type. */
7770 TYPE_TARGET_TYPE (type0
) = type
= alloc_type_copy (type0
);
7771 type
->set_code (type0
->code ());
7772 INIT_NONE_SPECIFIC (type
);
7773 type
->set_num_fields (nfields
);
7777 TYPE_ALLOC (type
, nfields
* sizeof (struct field
)));
7778 memcpy (fields
, type0
->fields (),
7779 sizeof (struct field
) * nfields
);
7780 type
->set_fields (fields
);
7782 type
->set_name (ada_type_name (type0
));
7783 type
->set_is_fixed_instance (true);
7784 TYPE_LENGTH (type
) = 0;
7786 type
->field (f
).set_type (new_type
);
7787 type
->field (f
).set_name (type0
->field (f
).name ());
7794 /* Given an object of type TYPE whose contents are at VALADDR and
7795 whose address in memory is ADDRESS, returns a revision of TYPE,
7796 which should be a non-dynamic-sized record, in which the variant
7797 part, if any, is replaced with the appropriate branch. Looks
7798 for discriminant values in DVAL0, which can be NULL if the record
7799 contains the necessary discriminant values. */
7801 static struct type
*
7802 to_record_with_fixed_variant_part (struct type
*type
, const gdb_byte
*valaddr
,
7803 CORE_ADDR address
, struct value
*dval0
)
7805 struct value
*mark
= value_mark ();
7808 struct type
*branch_type
;
7809 int nfields
= type
->num_fields ();
7810 int variant_field
= variant_field_index (type
);
7812 if (variant_field
== -1)
7817 dval
= value_from_contents_and_address (type
, valaddr
, address
);
7818 type
= value_type (dval
);
7823 rtype
= alloc_type_copy (type
);
7824 rtype
->set_code (TYPE_CODE_STRUCT
);
7825 INIT_NONE_SPECIFIC (rtype
);
7826 rtype
->set_num_fields (nfields
);
7829 (struct field
*) TYPE_ALLOC (rtype
, nfields
* sizeof (struct field
));
7830 memcpy (fields
, type
->fields (), sizeof (struct field
) * nfields
);
7831 rtype
->set_fields (fields
);
7833 rtype
->set_name (ada_type_name (type
));
7834 rtype
->set_is_fixed_instance (true);
7835 TYPE_LENGTH (rtype
) = TYPE_LENGTH (type
);
7837 branch_type
= to_fixed_variant_branch_type
7838 (type
->field (variant_field
).type (),
7839 cond_offset_host (valaddr
,
7840 type
->field (variant_field
).loc_bitpos ()
7842 cond_offset_target (address
,
7843 type
->field (variant_field
).loc_bitpos ()
7844 / TARGET_CHAR_BIT
), dval
);
7845 if (branch_type
== NULL
)
7849 for (f
= variant_field
+ 1; f
< nfields
; f
+= 1)
7850 rtype
->field (f
- 1) = rtype
->field (f
);
7851 rtype
->set_num_fields (rtype
->num_fields () - 1);
7855 rtype
->field (variant_field
).set_type (branch_type
);
7856 rtype
->field (variant_field
).set_name ("S");
7857 TYPE_FIELD_BITSIZE (rtype
, variant_field
) = 0;
7858 TYPE_LENGTH (rtype
) += TYPE_LENGTH (branch_type
);
7860 TYPE_LENGTH (rtype
) -= TYPE_LENGTH (type
->field (variant_field
).type ());
7862 value_free_to_mark (mark
);
7866 /* An ordinary record type (with fixed-length fields) that describes
7867 the value at (TYPE0, VALADDR, ADDRESS) [see explanation at
7868 beginning of this section]. Any necessary discriminants' values
7869 should be in DVAL, a record value; it may be NULL if the object
7870 at ADDR itself contains any necessary discriminant values.
7871 Additionally, VALADDR and ADDRESS may also be NULL if no discriminant
7872 values from the record are needed. Except in the case that DVAL,
7873 VALADDR, and ADDRESS are all 0 or NULL, a variant field (unless
7874 unchecked) is replaced by a particular branch of the variant.
7876 NOTE: the case in which DVAL and VALADDR are NULL and ADDRESS is 0
7877 is questionable and may be removed. It can arise during the
7878 processing of an unconstrained-array-of-record type where all the
7879 variant branches have exactly the same size. This is because in
7880 such cases, the compiler does not bother to use the XVS convention
7881 when encoding the record. I am currently dubious of this
7882 shortcut and suspect the compiler should be altered. FIXME. */
7884 static struct type
*
7885 to_fixed_record_type (struct type
*type0
, const gdb_byte
*valaddr
,
7886 CORE_ADDR address
, struct value
*dval
)
7888 struct type
*templ_type
;
7890 if (type0
->is_fixed_instance ())
7893 templ_type
= dynamic_template_type (type0
);
7895 if (templ_type
!= NULL
)
7896 return template_to_fixed_record_type (templ_type
, valaddr
, address
, dval
);
7897 else if (variant_field_index (type0
) >= 0)
7899 if (dval
== NULL
&& valaddr
== NULL
&& address
== 0)
7901 return to_record_with_fixed_variant_part (type0
, valaddr
, address
,
7906 type0
->set_is_fixed_instance (true);
7912 /* An ordinary record type (with fixed-length fields) that describes
7913 the value at (VAR_TYPE0, VALADDR, ADDRESS), where VAR_TYPE0 is a
7914 union type. Any necessary discriminants' values should be in DVAL,
7915 a record value. That is, this routine selects the appropriate
7916 branch of the union at ADDR according to the discriminant value
7917 indicated in the union's type name. Returns VAR_TYPE0 itself if
7918 it represents a variant subject to a pragma Unchecked_Union. */
7920 static struct type
*
7921 to_fixed_variant_branch_type (struct type
*var_type0
, const gdb_byte
*valaddr
,
7922 CORE_ADDR address
, struct value
*dval
)
7925 struct type
*templ_type
;
7926 struct type
*var_type
;
7928 if (var_type0
->code () == TYPE_CODE_PTR
)
7929 var_type
= TYPE_TARGET_TYPE (var_type0
);
7931 var_type
= var_type0
;
7933 templ_type
= ada_find_parallel_type (var_type
, "___XVU");
7935 if (templ_type
!= NULL
)
7936 var_type
= templ_type
;
7938 if (is_unchecked_variant (var_type
, value_type (dval
)))
7940 which
= ada_which_variant_applies (var_type
, dval
);
7943 return empty_record (var_type
);
7944 else if (is_dynamic_field (var_type
, which
))
7945 return to_fixed_record_type
7946 (TYPE_TARGET_TYPE (var_type
->field (which
).type ()),
7947 valaddr
, address
, dval
);
7948 else if (variant_field_index (var_type
->field (which
).type ()) >= 0)
7950 to_fixed_record_type
7951 (var_type
->field (which
).type (), valaddr
, address
, dval
);
7953 return var_type
->field (which
).type ();
7956 /* Assuming RANGE_TYPE is a TYPE_CODE_RANGE, return nonzero if
7957 ENCODING_TYPE, a type following the GNAT conventions for discrete
7958 type encodings, only carries redundant information. */
7961 ada_is_redundant_range_encoding (struct type
*range_type
,
7962 struct type
*encoding_type
)
7964 const char *bounds_str
;
7968 gdb_assert (range_type
->code () == TYPE_CODE_RANGE
);
7970 if (get_base_type (range_type
)->code ()
7971 != get_base_type (encoding_type
)->code ())
7973 /* The compiler probably used a simple base type to describe
7974 the range type instead of the range's actual base type,
7975 expecting us to get the real base type from the encoding
7976 anyway. In this situation, the encoding cannot be ignored
7981 if (is_dynamic_type (range_type
))
7984 if (encoding_type
->name () == NULL
)
7987 bounds_str
= strstr (encoding_type
->name (), "___XDLU_");
7988 if (bounds_str
== NULL
)
7991 n
= 8; /* Skip "___XDLU_". */
7992 if (!ada_scan_number (bounds_str
, n
, &lo
, &n
))
7994 if (range_type
->bounds ()->low
.const_val () != lo
)
7997 n
+= 2; /* Skip the "__" separator between the two bounds. */
7998 if (!ada_scan_number (bounds_str
, n
, &hi
, &n
))
8000 if (range_type
->bounds ()->high
.const_val () != hi
)
8006 /* Given the array type ARRAY_TYPE, return nonzero if DESC_TYPE,
8007 a type following the GNAT encoding for describing array type
8008 indices, only carries redundant information. */
8011 ada_is_redundant_index_type_desc (struct type
*array_type
,
8012 struct type
*desc_type
)
8014 struct type
*this_layer
= check_typedef (array_type
);
8017 for (i
= 0; i
< desc_type
->num_fields (); i
++)
8019 if (!ada_is_redundant_range_encoding (this_layer
->index_type (),
8020 desc_type
->field (i
).type ()))
8022 this_layer
= check_typedef (TYPE_TARGET_TYPE (this_layer
));
8028 /* Assuming that TYPE0 is an array type describing the type of a value
8029 at ADDR, and that DVAL describes a record containing any
8030 discriminants used in TYPE0, returns a type for the value that
8031 contains no dynamic components (that is, no components whose sizes
8032 are determined by run-time quantities). Unless IGNORE_TOO_BIG is
8033 true, gives an error message if the resulting type's size is over
8036 static struct type
*
8037 to_fixed_array_type (struct type
*type0
, struct value
*dval
,
8040 struct type
*index_type_desc
;
8041 struct type
*result
;
8042 int constrained_packed_array_p
;
8043 static const char *xa_suffix
= "___XA";
8045 type0
= ada_check_typedef (type0
);
8046 if (type0
->is_fixed_instance ())
8049 constrained_packed_array_p
= ada_is_constrained_packed_array_type (type0
);
8050 if (constrained_packed_array_p
)
8052 type0
= decode_constrained_packed_array_type (type0
);
8053 if (type0
== nullptr)
8054 error (_("could not decode constrained packed array type"));
8057 index_type_desc
= ada_find_parallel_type (type0
, xa_suffix
);
8059 /* As mentioned in exp_dbug.ads, for non bit-packed arrays an
8060 encoding suffixed with 'P' may still be generated. If so,
8061 it should be used to find the XA type. */
8063 if (index_type_desc
== NULL
)
8065 const char *type_name
= ada_type_name (type0
);
8067 if (type_name
!= NULL
)
8069 const int len
= strlen (type_name
);
8070 char *name
= (char *) alloca (len
+ strlen (xa_suffix
));
8072 if (type_name
[len
- 1] == 'P')
8074 strcpy (name
, type_name
);
8075 strcpy (name
+ len
- 1, xa_suffix
);
8076 index_type_desc
= ada_find_parallel_type_with_name (type0
, name
);
8081 ada_fixup_array_indexes_type (index_type_desc
);
8082 if (index_type_desc
!= NULL
8083 && ada_is_redundant_index_type_desc (type0
, index_type_desc
))
8085 /* Ignore this ___XA parallel type, as it does not bring any
8086 useful information. This allows us to avoid creating fixed
8087 versions of the array's index types, which would be identical
8088 to the original ones. This, in turn, can also help avoid
8089 the creation of fixed versions of the array itself. */
8090 index_type_desc
= NULL
;
8093 if (index_type_desc
== NULL
)
8095 struct type
*elt_type0
= ada_check_typedef (TYPE_TARGET_TYPE (type0
));
8097 /* NOTE: elt_type---the fixed version of elt_type0---should never
8098 depend on the contents of the array in properly constructed
8100 /* Create a fixed version of the array element type.
8101 We're not providing the address of an element here,
8102 and thus the actual object value cannot be inspected to do
8103 the conversion. This should not be a problem, since arrays of
8104 unconstrained objects are not allowed. In particular, all
8105 the elements of an array of a tagged type should all be of
8106 the same type specified in the debugging info. No need to
8107 consult the object tag. */
8108 struct type
*elt_type
= ada_to_fixed_type (elt_type0
, 0, 0, dval
, 1);
8110 /* Make sure we always create a new array type when dealing with
8111 packed array types, since we're going to fix-up the array
8112 type length and element bitsize a little further down. */
8113 if (elt_type0
== elt_type
&& !constrained_packed_array_p
)
8116 result
= create_array_type (alloc_type_copy (type0
),
8117 elt_type
, type0
->index_type ());
8122 struct type
*elt_type0
;
8125 for (i
= index_type_desc
->num_fields (); i
> 0; i
-= 1)
8126 elt_type0
= TYPE_TARGET_TYPE (elt_type0
);
8128 /* NOTE: result---the fixed version of elt_type0---should never
8129 depend on the contents of the array in properly constructed
8131 /* Create a fixed version of the array element type.
8132 We're not providing the address of an element here,
8133 and thus the actual object value cannot be inspected to do
8134 the conversion. This should not be a problem, since arrays of
8135 unconstrained objects are not allowed. In particular, all
8136 the elements of an array of a tagged type should all be of
8137 the same type specified in the debugging info. No need to
8138 consult the object tag. */
8140 ada_to_fixed_type (ada_check_typedef (elt_type0
), 0, 0, dval
, 1);
8143 for (i
= index_type_desc
->num_fields () - 1; i
>= 0; i
-= 1)
8145 struct type
*range_type
=
8146 to_fixed_range_type (index_type_desc
->field (i
).type (), dval
);
8148 result
= create_array_type (alloc_type_copy (elt_type0
),
8149 result
, range_type
);
8150 elt_type0
= TYPE_TARGET_TYPE (elt_type0
);
8154 /* We want to preserve the type name. This can be useful when
8155 trying to get the type name of a value that has already been
8156 printed (for instance, if the user did "print VAR; whatis $". */
8157 result
->set_name (type0
->name ());
8159 if (constrained_packed_array_p
)
8161 /* So far, the resulting type has been created as if the original
8162 type was a regular (non-packed) array type. As a result, the
8163 bitsize of the array elements needs to be set again, and the array
8164 length needs to be recomputed based on that bitsize. */
8165 int len
= TYPE_LENGTH (result
) / TYPE_LENGTH (TYPE_TARGET_TYPE (result
));
8166 int elt_bitsize
= TYPE_FIELD_BITSIZE (type0
, 0);
8168 TYPE_FIELD_BITSIZE (result
, 0) = TYPE_FIELD_BITSIZE (type0
, 0);
8169 TYPE_LENGTH (result
) = len
* elt_bitsize
/ HOST_CHAR_BIT
;
8170 if (TYPE_LENGTH (result
) * HOST_CHAR_BIT
< len
* elt_bitsize
)
8171 TYPE_LENGTH (result
)++;
8174 result
->set_is_fixed_instance (true);
8179 /* A standard type (containing no dynamically sized components)
8180 corresponding to TYPE for the value (TYPE, VALADDR, ADDRESS)
8181 DVAL describes a record containing any discriminants used in TYPE0,
8182 and may be NULL if there are none, or if the object of type TYPE at
8183 ADDRESS or in VALADDR contains these discriminants.
8185 If CHECK_TAG is not null, in the case of tagged types, this function
8186 attempts to locate the object's tag and use it to compute the actual
8187 type. However, when ADDRESS is null, we cannot use it to determine the
8188 location of the tag, and therefore compute the tagged type's actual type.
8189 So we return the tagged type without consulting the tag. */
8191 static struct type
*
8192 ada_to_fixed_type_1 (struct type
*type
, const gdb_byte
*valaddr
,
8193 CORE_ADDR address
, struct value
*dval
, int check_tag
)
8195 type
= ada_check_typedef (type
);
8197 /* Only un-fixed types need to be handled here. */
8198 if (!HAVE_GNAT_AUX_INFO (type
))
8201 switch (type
->code ())
8205 case TYPE_CODE_STRUCT
:
8207 struct type
*static_type
= to_static_fixed_type (type
);
8208 struct type
*fixed_record_type
=
8209 to_fixed_record_type (type
, valaddr
, address
, NULL
);
8211 /* If STATIC_TYPE is a tagged type and we know the object's address,
8212 then we can determine its tag, and compute the object's actual
8213 type from there. Note that we have to use the fixed record
8214 type (the parent part of the record may have dynamic fields
8215 and the way the location of _tag is expressed may depend on
8218 if (check_tag
&& address
!= 0 && ada_is_tagged_type (static_type
, 0))
8221 value_tag_from_contents_and_address
8225 struct type
*real_type
= type_from_tag (tag
);
8227 value_from_contents_and_address (fixed_record_type
,
8230 fixed_record_type
= value_type (obj
);
8231 if (real_type
!= NULL
)
8232 return to_fixed_record_type
8234 value_address (ada_tag_value_at_base_address (obj
)), NULL
);
8237 /* Check to see if there is a parallel ___XVZ variable.
8238 If there is, then it provides the actual size of our type. */
8239 else if (ada_type_name (fixed_record_type
) != NULL
)
8241 const char *name
= ada_type_name (fixed_record_type
);
8243 = (char *) alloca (strlen (name
) + 7 /* "___XVZ\0" */);
8244 bool xvz_found
= false;
8247 xsnprintf (xvz_name
, strlen (name
) + 7, "%s___XVZ", name
);
8250 xvz_found
= get_int_var_value (xvz_name
, size
);
8252 catch (const gdb_exception_error
&except
)
8254 /* We found the variable, but somehow failed to read
8255 its value. Rethrow the same error, but with a little
8256 bit more information, to help the user understand
8257 what went wrong (Eg: the variable might have been
8259 throw_error (except
.error
,
8260 _("unable to read value of %s (%s)"),
8261 xvz_name
, except
.what ());
8264 if (xvz_found
&& TYPE_LENGTH (fixed_record_type
) != size
)
8266 fixed_record_type
= copy_type (fixed_record_type
);
8267 TYPE_LENGTH (fixed_record_type
) = size
;
8269 /* The FIXED_RECORD_TYPE may have be a stub. We have
8270 observed this when the debugging info is STABS, and
8271 apparently it is something that is hard to fix.
8273 In practice, we don't need the actual type definition
8274 at all, because the presence of the XVZ variable allows us
8275 to assume that there must be a XVS type as well, which we
8276 should be able to use later, when we need the actual type
8279 In the meantime, pretend that the "fixed" type we are
8280 returning is NOT a stub, because this can cause trouble
8281 when using this type to create new types targeting it.
8282 Indeed, the associated creation routines often check
8283 whether the target type is a stub and will try to replace
8284 it, thus using a type with the wrong size. This, in turn,
8285 might cause the new type to have the wrong size too.
8286 Consider the case of an array, for instance, where the size
8287 of the array is computed from the number of elements in
8288 our array multiplied by the size of its element. */
8289 fixed_record_type
->set_is_stub (false);
8292 return fixed_record_type
;
8294 case TYPE_CODE_ARRAY
:
8295 return to_fixed_array_type (type
, dval
, 1);
8296 case TYPE_CODE_UNION
:
8300 return to_fixed_variant_branch_type (type
, valaddr
, address
, dval
);
8304 /* The same as ada_to_fixed_type_1, except that it preserves the type
8305 if it is a TYPE_CODE_TYPEDEF of a type that is already fixed.
8307 The typedef layer needs be preserved in order to differentiate between
8308 arrays and array pointers when both types are implemented using the same
8309 fat pointer. In the array pointer case, the pointer is encoded as
8310 a typedef of the pointer type. For instance, considering:
8312 type String_Access is access String;
8313 S1 : String_Access := null;
8315 To the debugger, S1 is defined as a typedef of type String. But
8316 to the user, it is a pointer. So if the user tries to print S1,
8317 we should not dereference the array, but print the array address
8320 If we didn't preserve the typedef layer, we would lose the fact that
8321 the type is to be presented as a pointer (needs de-reference before
8322 being printed). And we would also use the source-level type name. */
8325 ada_to_fixed_type (struct type
*type
, const gdb_byte
*valaddr
,
8326 CORE_ADDR address
, struct value
*dval
, int check_tag
)
8329 struct type
*fixed_type
=
8330 ada_to_fixed_type_1 (type
, valaddr
, address
, dval
, check_tag
);
8332 /* If TYPE is a typedef and its target type is the same as the FIXED_TYPE,
8333 then preserve the typedef layer.
8335 Implementation note: We can only check the main-type portion of
8336 the TYPE and FIXED_TYPE, because eliminating the typedef layer
8337 from TYPE now returns a type that has the same instance flags
8338 as TYPE. For instance, if TYPE is a "typedef const", and its
8339 target type is a "struct", then the typedef elimination will return
8340 a "const" version of the target type. See check_typedef for more
8341 details about how the typedef layer elimination is done.
8343 brobecker/2010-11-19: It seems to me that the only case where it is
8344 useful to preserve the typedef layer is when dealing with fat pointers.
8345 Perhaps, we could add a check for that and preserve the typedef layer
8346 only in that situation. But this seems unnecessary so far, probably
8347 because we call check_typedef/ada_check_typedef pretty much everywhere.
8349 if (type
->code () == TYPE_CODE_TYPEDEF
8350 && (TYPE_MAIN_TYPE (ada_typedef_target_type (type
))
8351 == TYPE_MAIN_TYPE (fixed_type
)))
8357 /* A standard (static-sized) type corresponding as well as possible to
8358 TYPE0, but based on no runtime data. */
8360 static struct type
*
8361 to_static_fixed_type (struct type
*type0
)
8368 if (type0
->is_fixed_instance ())
8371 type0
= ada_check_typedef (type0
);
8373 switch (type0
->code ())
8377 case TYPE_CODE_STRUCT
:
8378 type
= dynamic_template_type (type0
);
8380 return template_to_static_fixed_type (type
);
8382 return template_to_static_fixed_type (type0
);
8383 case TYPE_CODE_UNION
:
8384 type
= ada_find_parallel_type (type0
, "___XVU");
8386 return template_to_static_fixed_type (type
);
8388 return template_to_static_fixed_type (type0
);
8392 /* A static approximation of TYPE with all type wrappers removed. */
8394 static struct type
*
8395 static_unwrap_type (struct type
*type
)
8397 if (ada_is_aligner_type (type
))
8399 struct type
*type1
= ada_check_typedef (type
)->field (0).type ();
8400 if (ada_type_name (type1
) == NULL
)
8401 type1
->set_name (ada_type_name (type
));
8403 return static_unwrap_type (type1
);
8407 struct type
*raw_real_type
= ada_get_base_type (type
);
8409 if (raw_real_type
== type
)
8412 return to_static_fixed_type (raw_real_type
);
8416 /* In some cases, incomplete and private types require
8417 cross-references that are not resolved as records (for example,
8419 type FooP is access Foo;
8421 type Foo is array ...;
8422 ). In these cases, since there is no mechanism for producing
8423 cross-references to such types, we instead substitute for FooP a
8424 stub enumeration type that is nowhere resolved, and whose tag is
8425 the name of the actual type. Call these types "non-record stubs". */
8427 /* A type equivalent to TYPE that is not a non-record stub, if one
8428 exists, otherwise TYPE. */
8431 ada_check_typedef (struct type
*type
)
8436 /* If our type is an access to an unconstrained array, which is encoded
8437 as a TYPE_CODE_TYPEDEF of a fat pointer, then we're done.
8438 We don't want to strip the TYPE_CODE_TYPDEF layer, because this is
8439 what allows us to distinguish between fat pointers that represent
8440 array types, and fat pointers that represent array access types
8441 (in both cases, the compiler implements them as fat pointers). */
8442 if (ada_is_access_to_unconstrained_array (type
))
8445 type
= check_typedef (type
);
8446 if (type
== NULL
|| type
->code () != TYPE_CODE_ENUM
8447 || !type
->is_stub ()
8448 || type
->name () == NULL
)
8452 const char *name
= type
->name ();
8453 struct type
*type1
= ada_find_any_type (name
);
8458 /* TYPE1 might itself be a TYPE_CODE_TYPEDEF (this can happen with
8459 stubs pointing to arrays, as we don't create symbols for array
8460 types, only for the typedef-to-array types). If that's the case,
8461 strip the typedef layer. */
8462 if (type1
->code () == TYPE_CODE_TYPEDEF
)
8463 type1
= ada_check_typedef (type1
);
8469 /* A value representing the data at VALADDR/ADDRESS as described by
8470 type TYPE0, but with a standard (static-sized) type that correctly
8471 describes it. If VAL0 is not NULL and TYPE0 already is a standard
8472 type, then return VAL0 [this feature is simply to avoid redundant
8473 creation of struct values]. */
8475 static struct value
*
8476 ada_to_fixed_value_create (struct type
*type0
, CORE_ADDR address
,
8479 struct type
*type
= ada_to_fixed_type (type0
, 0, address
, NULL
, 1);
8481 if (type
== type0
&& val0
!= NULL
)
8484 if (VALUE_LVAL (val0
) != lval_memory
)
8486 /* Our value does not live in memory; it could be a convenience
8487 variable, for instance. Create a not_lval value using val0's
8489 return value_from_contents (type
, value_contents (val0
).data ());
8492 return value_from_contents_and_address (type
, 0, address
);
8495 /* A value representing VAL, but with a standard (static-sized) type
8496 that correctly describes it. Does not necessarily create a new
8500 ada_to_fixed_value (struct value
*val
)
8502 val
= unwrap_value (val
);
8503 val
= ada_to_fixed_value_create (value_type (val
), value_address (val
), val
);
8510 /* Table mapping attribute numbers to names.
8511 NOTE: Keep up to date with enum ada_attribute definition in ada-lang.h. */
8513 static const char * const attribute_names
[] = {
8531 ada_attribute_name (enum exp_opcode n
)
8533 if (n
>= OP_ATR_FIRST
&& n
<= (int) OP_ATR_VAL
)
8534 return attribute_names
[n
- OP_ATR_FIRST
+ 1];
8536 return attribute_names
[0];
8539 /* Evaluate the 'POS attribute applied to ARG. */
8542 pos_atr (struct value
*arg
)
8544 struct value
*val
= coerce_ref (arg
);
8545 struct type
*type
= value_type (val
);
8547 if (!discrete_type_p (type
))
8548 error (_("'POS only defined on discrete types"));
8550 gdb::optional
<LONGEST
> result
= discrete_position (type
, value_as_long (val
));
8551 if (!result
.has_value ())
8552 error (_("enumeration value is invalid: can't find 'POS"));
8558 ada_pos_atr (struct type
*expect_type
,
8559 struct expression
*exp
,
8560 enum noside noside
, enum exp_opcode op
,
8563 struct type
*type
= builtin_type (exp
->gdbarch
)->builtin_int
;
8564 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
8565 return value_zero (type
, not_lval
);
8566 return value_from_longest (type
, pos_atr (arg
));
8569 /* Evaluate the TYPE'VAL attribute applied to ARG. */
8571 static struct value
*
8572 val_atr (struct type
*type
, LONGEST val
)
8574 gdb_assert (discrete_type_p (type
));
8575 if (type
->code () == TYPE_CODE_RANGE
)
8576 type
= TYPE_TARGET_TYPE (type
);
8577 if (type
->code () == TYPE_CODE_ENUM
)
8579 if (val
< 0 || val
>= type
->num_fields ())
8580 error (_("argument to 'VAL out of range"));
8581 val
= type
->field (val
).loc_enumval ();
8583 return value_from_longest (type
, val
);
8587 ada_val_atr (enum noside noside
, struct type
*type
, struct value
*arg
)
8589 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
8590 return value_zero (type
, not_lval
);
8592 if (!discrete_type_p (type
))
8593 error (_("'VAL only defined on discrete types"));
8594 if (!integer_type_p (value_type (arg
)))
8595 error (_("'VAL requires integral argument"));
8597 return val_atr (type
, value_as_long (arg
));
8603 /* True if TYPE appears to be an Ada character type.
8604 [At the moment, this is true only for Character and Wide_Character;
8605 It is a heuristic test that could stand improvement]. */
8608 ada_is_character_type (struct type
*type
)
8612 /* If the type code says it's a character, then assume it really is,
8613 and don't check any further. */
8614 if (type
->code () == TYPE_CODE_CHAR
)
8617 /* Otherwise, assume it's a character type iff it is a discrete type
8618 with a known character type name. */
8619 name
= ada_type_name (type
);
8620 return (name
!= NULL
8621 && (type
->code () == TYPE_CODE_INT
8622 || type
->code () == TYPE_CODE_RANGE
)
8623 && (strcmp (name
, "character") == 0
8624 || strcmp (name
, "wide_character") == 0
8625 || strcmp (name
, "wide_wide_character") == 0
8626 || strcmp (name
, "unsigned char") == 0));
8629 /* True if TYPE appears to be an Ada string type. */
8632 ada_is_string_type (struct type
*type
)
8634 type
= ada_check_typedef (type
);
8636 && type
->code () != TYPE_CODE_PTR
8637 && (ada_is_simple_array_type (type
)
8638 || ada_is_array_descriptor_type (type
))
8639 && ada_array_arity (type
) == 1)
8641 struct type
*elttype
= ada_array_element_type (type
, 1);
8643 return ada_is_character_type (elttype
);
8649 /* The compiler sometimes provides a parallel XVS type for a given
8650 PAD type. Normally, it is safe to follow the PAD type directly,
8651 but older versions of the compiler have a bug that causes the offset
8652 of its "F" field to be wrong. Following that field in that case
8653 would lead to incorrect results, but this can be worked around
8654 by ignoring the PAD type and using the associated XVS type instead.
8656 Set to True if the debugger should trust the contents of PAD types.
8657 Otherwise, ignore the PAD type if there is a parallel XVS type. */
8658 static bool trust_pad_over_xvs
= true;
8660 /* True if TYPE is a struct type introduced by the compiler to force the
8661 alignment of a value. Such types have a single field with a
8662 distinctive name. */
8665 ada_is_aligner_type (struct type
*type
)
8667 type
= ada_check_typedef (type
);
8669 if (!trust_pad_over_xvs
&& ada_find_parallel_type (type
, "___XVS") != NULL
)
8672 return (type
->code () == TYPE_CODE_STRUCT
8673 && type
->num_fields () == 1
8674 && strcmp (type
->field (0).name (), "F") == 0);
8677 /* If there is an ___XVS-convention type parallel to SUBTYPE, return
8678 the parallel type. */
8681 ada_get_base_type (struct type
*raw_type
)
8683 struct type
*real_type_namer
;
8684 struct type
*raw_real_type
;
8686 if (raw_type
== NULL
|| raw_type
->code () != TYPE_CODE_STRUCT
)
8689 if (ada_is_aligner_type (raw_type
))
8690 /* The encoding specifies that we should always use the aligner type.
8691 So, even if this aligner type has an associated XVS type, we should
8694 According to the compiler gurus, an XVS type parallel to an aligner
8695 type may exist because of a stabs limitation. In stabs, aligner
8696 types are empty because the field has a variable-sized type, and
8697 thus cannot actually be used as an aligner type. As a result,
8698 we need the associated parallel XVS type to decode the type.
8699 Since the policy in the compiler is to not change the internal
8700 representation based on the debugging info format, we sometimes
8701 end up having a redundant XVS type parallel to the aligner type. */
8704 real_type_namer
= ada_find_parallel_type (raw_type
, "___XVS");
8705 if (real_type_namer
== NULL
8706 || real_type_namer
->code () != TYPE_CODE_STRUCT
8707 || real_type_namer
->num_fields () != 1)
8710 if (real_type_namer
->field (0).type ()->code () != TYPE_CODE_REF
)
8712 /* This is an older encoding form where the base type needs to be
8713 looked up by name. We prefer the newer encoding because it is
8715 raw_real_type
= ada_find_any_type (real_type_namer
->field (0).name ());
8716 if (raw_real_type
== NULL
)
8719 return raw_real_type
;
8722 /* The field in our XVS type is a reference to the base type. */
8723 return TYPE_TARGET_TYPE (real_type_namer
->field (0).type ());
8726 /* The type of value designated by TYPE, with all aligners removed. */
8729 ada_aligned_type (struct type
*type
)
8731 if (ada_is_aligner_type (type
))
8732 return ada_aligned_type (type
->field (0).type ());
8734 return ada_get_base_type (type
);
8738 /* The address of the aligned value in an object at address VALADDR
8739 having type TYPE. Assumes ada_is_aligner_type (TYPE). */
8742 ada_aligned_value_addr (struct type
*type
, const gdb_byte
*valaddr
)
8744 if (ada_is_aligner_type (type
))
8745 return ada_aligned_value_addr
8746 (type
->field (0).type (),
8747 valaddr
+ type
->field (0).loc_bitpos () / TARGET_CHAR_BIT
);
8754 /* The printed representation of an enumeration literal with encoded
8755 name NAME. The value is good to the next call of ada_enum_name. */
8757 ada_enum_name (const char *name
)
8759 static std::string storage
;
8762 /* First, unqualify the enumeration name:
8763 1. Search for the last '.' character. If we find one, then skip
8764 all the preceding characters, the unqualified name starts
8765 right after that dot.
8766 2. Otherwise, we may be debugging on a target where the compiler
8767 translates dots into "__". Search forward for double underscores,
8768 but stop searching when we hit an overloading suffix, which is
8769 of the form "__" followed by digits. */
8771 tmp
= strrchr (name
, '.');
8776 while ((tmp
= strstr (name
, "__")) != NULL
)
8778 if (isdigit (tmp
[2]))
8789 if (name
[1] == 'U' || name
[1] == 'W')
8791 if (sscanf (name
+ 2, "%x", &v
) != 1)
8794 else if (((name
[1] >= '0' && name
[1] <= '9')
8795 || (name
[1] >= 'a' && name
[1] <= 'z'))
8798 storage
= string_printf ("'%c'", name
[1]);
8799 return storage
.c_str ();
8804 if (isascii (v
) && isprint (v
))
8805 storage
= string_printf ("'%c'", v
);
8806 else if (name
[1] == 'U')
8807 storage
= string_printf ("[\"%02x\"]", v
);
8809 storage
= string_printf ("[\"%04x\"]", v
);
8811 return storage
.c_str ();
8815 tmp
= strstr (name
, "__");
8817 tmp
= strstr (name
, "$");
8820 storage
= std::string (name
, tmp
- name
);
8821 return storage
.c_str ();
8828 /* If VAL is wrapped in an aligner or subtype wrapper, return the
8831 static struct value
*
8832 unwrap_value (struct value
*val
)
8834 struct type
*type
= ada_check_typedef (value_type (val
));
8836 if (ada_is_aligner_type (type
))
8838 struct value
*v
= ada_value_struct_elt (val
, "F", 0);
8839 struct type
*val_type
= ada_check_typedef (value_type (v
));
8841 if (ada_type_name (val_type
) == NULL
)
8842 val_type
->set_name (ada_type_name (type
));
8844 return unwrap_value (v
);
8848 struct type
*raw_real_type
=
8849 ada_check_typedef (ada_get_base_type (type
));
8851 /* If there is no parallel XVS or XVE type, then the value is
8852 already unwrapped. Return it without further modification. */
8853 if ((type
== raw_real_type
)
8854 && ada_find_parallel_type (type
, "___XVE") == NULL
)
8858 coerce_unspec_val_to_type
8859 (val
, ada_to_fixed_type (raw_real_type
, 0,
8860 value_address (val
),
8865 /* Given two array types T1 and T2, return nonzero iff both arrays
8866 contain the same number of elements. */
8869 ada_same_array_size_p (struct type
*t1
, struct type
*t2
)
8871 LONGEST lo1
, hi1
, lo2
, hi2
;
8873 /* Get the array bounds in order to verify that the size of
8874 the two arrays match. */
8875 if (!get_array_bounds (t1
, &lo1
, &hi1
)
8876 || !get_array_bounds (t2
, &lo2
, &hi2
))
8877 error (_("unable to determine array bounds"));
8879 /* To make things easier for size comparison, normalize a bit
8880 the case of empty arrays by making sure that the difference
8881 between upper bound and lower bound is always -1. */
8887 return (hi1
- lo1
== hi2
- lo2
);
8890 /* Assuming that VAL is an array of integrals, and TYPE represents
8891 an array with the same number of elements, but with wider integral
8892 elements, return an array "casted" to TYPE. In practice, this
8893 means that the returned array is built by casting each element
8894 of the original array into TYPE's (wider) element type. */
8896 static struct value
*
8897 ada_promote_array_of_integrals (struct type
*type
, struct value
*val
)
8899 struct type
*elt_type
= TYPE_TARGET_TYPE (type
);
8904 /* Verify that both val and type are arrays of scalars, and
8905 that the size of val's elements is smaller than the size
8906 of type's element. */
8907 gdb_assert (type
->code () == TYPE_CODE_ARRAY
);
8908 gdb_assert (is_integral_type (TYPE_TARGET_TYPE (type
)));
8909 gdb_assert (value_type (val
)->code () == TYPE_CODE_ARRAY
);
8910 gdb_assert (is_integral_type (TYPE_TARGET_TYPE (value_type (val
))));
8911 gdb_assert (TYPE_LENGTH (TYPE_TARGET_TYPE (type
))
8912 > TYPE_LENGTH (TYPE_TARGET_TYPE (value_type (val
))));
8914 if (!get_array_bounds (type
, &lo
, &hi
))
8915 error (_("unable to determine array bounds"));
8917 res
= allocate_value (type
);
8919 /* Promote each array element. */
8920 for (i
= 0; i
< hi
- lo
+ 1; i
++)
8922 struct value
*elt
= value_cast (elt_type
, value_subscript (val
, lo
+ i
));
8924 memcpy ((value_contents_writeable (res
).data ()
8925 + (i
* TYPE_LENGTH (elt_type
))),
8926 value_contents_all (elt
).data (), TYPE_LENGTH (elt_type
));
8932 /* Coerce VAL as necessary for assignment to an lval of type TYPE, and
8933 return the converted value. */
8935 static struct value
*
8936 coerce_for_assign (struct type
*type
, struct value
*val
)
8938 struct type
*type2
= value_type (val
);
8943 type2
= ada_check_typedef (type2
);
8944 type
= ada_check_typedef (type
);
8946 if (type2
->code () == TYPE_CODE_PTR
8947 && type
->code () == TYPE_CODE_ARRAY
)
8949 val
= ada_value_ind (val
);
8950 type2
= value_type (val
);
8953 if (type2
->code () == TYPE_CODE_ARRAY
8954 && type
->code () == TYPE_CODE_ARRAY
)
8956 if (!ada_same_array_size_p (type
, type2
))
8957 error (_("cannot assign arrays of different length"));
8959 if (is_integral_type (TYPE_TARGET_TYPE (type
))
8960 && is_integral_type (TYPE_TARGET_TYPE (type2
))
8961 && TYPE_LENGTH (TYPE_TARGET_TYPE (type2
))
8962 < TYPE_LENGTH (TYPE_TARGET_TYPE (type
)))
8964 /* Allow implicit promotion of the array elements to
8966 return ada_promote_array_of_integrals (type
, val
);
8969 if (TYPE_LENGTH (TYPE_TARGET_TYPE (type2
))
8970 != TYPE_LENGTH (TYPE_TARGET_TYPE (type
)))
8971 error (_("Incompatible types in assignment"));
8972 deprecated_set_value_type (val
, type
);
8977 static struct value
*
8978 ada_value_binop (struct value
*arg1
, struct value
*arg2
, enum exp_opcode op
)
8981 struct type
*type1
, *type2
;
8984 arg1
= coerce_ref (arg1
);
8985 arg2
= coerce_ref (arg2
);
8986 type1
= get_base_type (ada_check_typedef (value_type (arg1
)));
8987 type2
= get_base_type (ada_check_typedef (value_type (arg2
)));
8989 if (type1
->code () != TYPE_CODE_INT
8990 || type2
->code () != TYPE_CODE_INT
)
8991 return value_binop (arg1
, arg2
, op
);
9000 return value_binop (arg1
, arg2
, op
);
9003 v2
= value_as_long (arg2
);
9007 if (op
== BINOP_MOD
)
9009 else if (op
== BINOP_DIV
)
9013 gdb_assert (op
== BINOP_REM
);
9017 error (_("second operand of %s must not be zero."), name
);
9020 if (type1
->is_unsigned () || op
== BINOP_MOD
)
9021 return value_binop (arg1
, arg2
, op
);
9023 v1
= value_as_long (arg1
);
9028 if (!TRUNCATION_TOWARDS_ZERO
&& v1
* (v1
% v2
) < 0)
9029 v
+= v
> 0 ? -1 : 1;
9037 /* Should not reach this point. */
9041 val
= allocate_value (type1
);
9042 store_unsigned_integer (value_contents_raw (val
).data (),
9043 TYPE_LENGTH (value_type (val
)),
9044 type_byte_order (type1
), v
);
9049 ada_value_equal (struct value
*arg1
, struct value
*arg2
)
9051 if (ada_is_direct_array_type (value_type (arg1
))
9052 || ada_is_direct_array_type (value_type (arg2
)))
9054 struct type
*arg1_type
, *arg2_type
;
9056 /* Automatically dereference any array reference before
9057 we attempt to perform the comparison. */
9058 arg1
= ada_coerce_ref (arg1
);
9059 arg2
= ada_coerce_ref (arg2
);
9061 arg1
= ada_coerce_to_simple_array (arg1
);
9062 arg2
= ada_coerce_to_simple_array (arg2
);
9064 arg1_type
= ada_check_typedef (value_type (arg1
));
9065 arg2_type
= ada_check_typedef (value_type (arg2
));
9067 if (arg1_type
->code () != TYPE_CODE_ARRAY
9068 || arg2_type
->code () != TYPE_CODE_ARRAY
)
9069 error (_("Attempt to compare array with non-array"));
9070 /* FIXME: The following works only for types whose
9071 representations use all bits (no padding or undefined bits)
9072 and do not have user-defined equality. */
9073 return (TYPE_LENGTH (arg1_type
) == TYPE_LENGTH (arg2_type
)
9074 && memcmp (value_contents (arg1
).data (),
9075 value_contents (arg2
).data (),
9076 TYPE_LENGTH (arg1_type
)) == 0);
9078 return value_equal (arg1
, arg2
);
9085 check_objfile (const std::unique_ptr
<ada_component
> &comp
,
9086 struct objfile
*objfile
)
9088 return comp
->uses_objfile (objfile
);
9091 /* Assign the result of evaluating ARG starting at *POS to the INDEXth
9092 component of LHS (a simple array or a record). Does not modify the
9093 inferior's memory, nor does it modify LHS (unless LHS ==
9097 assign_component (struct value
*container
, struct value
*lhs
, LONGEST index
,
9098 struct expression
*exp
, operation_up
&arg
)
9100 scoped_value_mark mark
;
9103 struct type
*lhs_type
= check_typedef (value_type (lhs
));
9105 if (lhs_type
->code () == TYPE_CODE_ARRAY
)
9107 struct type
*index_type
= builtin_type (exp
->gdbarch
)->builtin_int
;
9108 struct value
*index_val
= value_from_longest (index_type
, index
);
9110 elt
= unwrap_value (ada_value_subscript (lhs
, 1, &index_val
));
9114 elt
= ada_index_struct_field (index
, lhs
, 0, value_type (lhs
));
9115 elt
= ada_to_fixed_value (elt
);
9118 ada_aggregate_operation
*ag_op
9119 = dynamic_cast<ada_aggregate_operation
*> (arg
.get ());
9120 if (ag_op
!= nullptr)
9121 ag_op
->assign_aggregate (container
, elt
, exp
);
9123 value_assign_to_component (container
, elt
,
9124 arg
->evaluate (nullptr, exp
,
9129 ada_aggregate_component::uses_objfile (struct objfile
*objfile
)
9131 for (const auto &item
: m_components
)
9132 if (item
->uses_objfile (objfile
))
9138 ada_aggregate_component::dump (ui_file
*stream
, int depth
)
9140 fprintf_filtered (stream
, _("%*sAggregate\n"), depth
, "");
9141 for (const auto &item
: m_components
)
9142 item
->dump (stream
, depth
+ 1);
9146 ada_aggregate_component::assign (struct value
*container
,
9147 struct value
*lhs
, struct expression
*exp
,
9148 std::vector
<LONGEST
> &indices
,
9149 LONGEST low
, LONGEST high
)
9151 for (auto &item
: m_components
)
9152 item
->assign (container
, lhs
, exp
, indices
, low
, high
);
9155 /* See ada-exp.h. */
9158 ada_aggregate_operation::assign_aggregate (struct value
*container
,
9160 struct expression
*exp
)
9162 struct type
*lhs_type
;
9163 LONGEST low_index
, high_index
;
9165 container
= ada_coerce_ref (container
);
9166 if (ada_is_direct_array_type (value_type (container
)))
9167 container
= ada_coerce_to_simple_array (container
);
9168 lhs
= ada_coerce_ref (lhs
);
9169 if (!deprecated_value_modifiable (lhs
))
9170 error (_("Left operand of assignment is not a modifiable lvalue."));
9172 lhs_type
= check_typedef (value_type (lhs
));
9173 if (ada_is_direct_array_type (lhs_type
))
9175 lhs
= ada_coerce_to_simple_array (lhs
);
9176 lhs_type
= check_typedef (value_type (lhs
));
9177 low_index
= lhs_type
->bounds ()->low
.const_val ();
9178 high_index
= lhs_type
->bounds ()->high
.const_val ();
9180 else if (lhs_type
->code () == TYPE_CODE_STRUCT
)
9183 high_index
= num_visible_fields (lhs_type
) - 1;
9186 error (_("Left-hand side must be array or record."));
9188 std::vector
<LONGEST
> indices (4);
9189 indices
[0] = indices
[1] = low_index
- 1;
9190 indices
[2] = indices
[3] = high_index
+ 1;
9192 std::get
<0> (m_storage
)->assign (container
, lhs
, exp
, indices
,
9193 low_index
, high_index
);
9199 ada_positional_component::uses_objfile (struct objfile
*objfile
)
9201 return m_op
->uses_objfile (objfile
);
9205 ada_positional_component::dump (ui_file
*stream
, int depth
)
9207 fprintf_filtered (stream
, _("%*sPositional, index = %d\n"),
9208 depth
, "", m_index
);
9209 m_op
->dump (stream
, depth
+ 1);
9212 /* Assign into the component of LHS indexed by the OP_POSITIONAL
9213 construct, given that the positions are relative to lower bound
9214 LOW, where HIGH is the upper bound. Record the position in
9215 INDICES. CONTAINER is as for assign_aggregate. */
9217 ada_positional_component::assign (struct value
*container
,
9218 struct value
*lhs
, struct expression
*exp
,
9219 std::vector
<LONGEST
> &indices
,
9220 LONGEST low
, LONGEST high
)
9222 LONGEST ind
= m_index
+ low
;
9224 if (ind
- 1 == high
)
9225 warning (_("Extra components in aggregate ignored."));
9228 add_component_interval (ind
, ind
, indices
);
9229 assign_component (container
, lhs
, ind
, exp
, m_op
);
9234 ada_discrete_range_association::uses_objfile (struct objfile
*objfile
)
9236 return m_low
->uses_objfile (objfile
) || m_high
->uses_objfile (objfile
);
9240 ada_discrete_range_association::dump (ui_file
*stream
, int depth
)
9242 fprintf_filtered (stream
, _("%*sDiscrete range:\n"), depth
, "");
9243 m_low
->dump (stream
, depth
+ 1);
9244 m_high
->dump (stream
, depth
+ 1);
9248 ada_discrete_range_association::assign (struct value
*container
,
9250 struct expression
*exp
,
9251 std::vector
<LONGEST
> &indices
,
9252 LONGEST low
, LONGEST high
,
9255 LONGEST lower
= value_as_long (m_low
->evaluate (nullptr, exp
, EVAL_NORMAL
));
9256 LONGEST upper
= value_as_long (m_high
->evaluate (nullptr, exp
, EVAL_NORMAL
));
9258 if (lower
<= upper
&& (lower
< low
|| upper
> high
))
9259 error (_("Index in component association out of bounds."));
9261 add_component_interval (lower
, upper
, indices
);
9262 while (lower
<= upper
)
9264 assign_component (container
, lhs
, lower
, exp
, op
);
9270 ada_name_association::uses_objfile (struct objfile
*objfile
)
9272 return m_val
->uses_objfile (objfile
);
9276 ada_name_association::dump (ui_file
*stream
, int depth
)
9278 fprintf_filtered (stream
, _("%*sName:\n"), depth
, "");
9279 m_val
->dump (stream
, depth
+ 1);
9283 ada_name_association::assign (struct value
*container
,
9285 struct expression
*exp
,
9286 std::vector
<LONGEST
> &indices
,
9287 LONGEST low
, LONGEST high
,
9292 if (ada_is_direct_array_type (value_type (lhs
)))
9293 index
= longest_to_int (value_as_long (m_val
->evaluate (nullptr, exp
,
9297 ada_string_operation
*strop
9298 = dynamic_cast<ada_string_operation
*> (m_val
.get ());
9301 if (strop
!= nullptr)
9302 name
= strop
->get_name ();
9305 ada_var_value_operation
*vvo
9306 = dynamic_cast<ada_var_value_operation
*> (m_val
.get ());
9308 error (_("Invalid record component association."));
9309 name
= vvo
->get_symbol ()->natural_name ();
9313 if (! find_struct_field (name
, value_type (lhs
), 0,
9314 NULL
, NULL
, NULL
, NULL
, &index
))
9315 error (_("Unknown component name: %s."), name
);
9318 add_component_interval (index
, index
, indices
);
9319 assign_component (container
, lhs
, index
, exp
, op
);
9323 ada_choices_component::uses_objfile (struct objfile
*objfile
)
9325 if (m_op
->uses_objfile (objfile
))
9327 for (const auto &item
: m_assocs
)
9328 if (item
->uses_objfile (objfile
))
9334 ada_choices_component::dump (ui_file
*stream
, int depth
)
9336 fprintf_filtered (stream
, _("%*sChoices:\n"), depth
, "");
9337 m_op
->dump (stream
, depth
+ 1);
9338 for (const auto &item
: m_assocs
)
9339 item
->dump (stream
, depth
+ 1);
9342 /* Assign into the components of LHS indexed by the OP_CHOICES
9343 construct at *POS, updating *POS past the construct, given that
9344 the allowable indices are LOW..HIGH. Record the indices assigned
9345 to in INDICES. CONTAINER is as for assign_aggregate. */
9347 ada_choices_component::assign (struct value
*container
,
9348 struct value
*lhs
, struct expression
*exp
,
9349 std::vector
<LONGEST
> &indices
,
9350 LONGEST low
, LONGEST high
)
9352 for (auto &item
: m_assocs
)
9353 item
->assign (container
, lhs
, exp
, indices
, low
, high
, m_op
);
9357 ada_others_component::uses_objfile (struct objfile
*objfile
)
9359 return m_op
->uses_objfile (objfile
);
9363 ada_others_component::dump (ui_file
*stream
, int depth
)
9365 fprintf_filtered (stream
, _("%*sOthers:\n"), depth
, "");
9366 m_op
->dump (stream
, depth
+ 1);
9369 /* Assign the value of the expression in the OP_OTHERS construct in
9370 EXP at *POS into the components of LHS indexed from LOW .. HIGH that
9371 have not been previously assigned. The index intervals already assigned
9372 are in INDICES. CONTAINER is as for assign_aggregate. */
9374 ada_others_component::assign (struct value
*container
,
9375 struct value
*lhs
, struct expression
*exp
,
9376 std::vector
<LONGEST
> &indices
,
9377 LONGEST low
, LONGEST high
)
9379 int num_indices
= indices
.size ();
9380 for (int i
= 0; i
< num_indices
- 2; i
+= 2)
9382 for (LONGEST ind
= indices
[i
+ 1] + 1; ind
< indices
[i
+ 2]; ind
+= 1)
9383 assign_component (container
, lhs
, ind
, exp
, m_op
);
9388 ada_assign_operation::evaluate (struct type
*expect_type
,
9389 struct expression
*exp
,
9392 value
*arg1
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
9394 ada_aggregate_operation
*ag_op
9395 = dynamic_cast<ada_aggregate_operation
*> (std::get
<1> (m_storage
).get ());
9396 if (ag_op
!= nullptr)
9398 if (noside
!= EVAL_NORMAL
)
9401 arg1
= ag_op
->assign_aggregate (arg1
, arg1
, exp
);
9402 return ada_value_assign (arg1
, arg1
);
9404 /* Force the evaluation of the rhs ARG2 to the type of the lhs ARG1,
9405 except if the lhs of our assignment is a convenience variable.
9406 In the case of assigning to a convenience variable, the lhs
9407 should be exactly the result of the evaluation of the rhs. */
9408 struct type
*type
= value_type (arg1
);
9409 if (VALUE_LVAL (arg1
) == lval_internalvar
)
9411 value
*arg2
= std::get
<1> (m_storage
)->evaluate (type
, exp
, noside
);
9412 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
9414 if (VALUE_LVAL (arg1
) == lval_internalvar
)
9419 arg2
= coerce_for_assign (value_type (arg1
), arg2
);
9420 return ada_value_assign (arg1
, arg2
);
9423 } /* namespace expr */
9425 /* Add the interval [LOW .. HIGH] to the sorted set of intervals
9426 [ INDICES[0] .. INDICES[1] ],... The resulting intervals do not
9429 add_component_interval (LONGEST low
, LONGEST high
,
9430 std::vector
<LONGEST
> &indices
)
9434 int size
= indices
.size ();
9435 for (i
= 0; i
< size
; i
+= 2) {
9436 if (high
>= indices
[i
] && low
<= indices
[i
+ 1])
9440 for (kh
= i
+ 2; kh
< size
; kh
+= 2)
9441 if (high
< indices
[kh
])
9443 if (low
< indices
[i
])
9445 indices
[i
+ 1] = indices
[kh
- 1];
9446 if (high
> indices
[i
+ 1])
9447 indices
[i
+ 1] = high
;
9448 memcpy (indices
.data () + i
+ 2, indices
.data () + kh
, size
- kh
);
9449 indices
.resize (kh
- i
- 2);
9452 else if (high
< indices
[i
])
9456 indices
.resize (indices
.size () + 2);
9457 for (j
= indices
.size () - 1; j
>= i
+ 2; j
-= 1)
9458 indices
[j
] = indices
[j
- 2];
9460 indices
[i
+ 1] = high
;
9463 /* Perform and Ada cast of ARG2 to type TYPE if the type of ARG2
9466 static struct value
*
9467 ada_value_cast (struct type
*type
, struct value
*arg2
)
9469 if (type
== ada_check_typedef (value_type (arg2
)))
9472 return value_cast (type
, arg2
);
9475 /* Evaluating Ada expressions, and printing their result.
9476 ------------------------------------------------------
9481 We usually evaluate an Ada expression in order to print its value.
9482 We also evaluate an expression in order to print its type, which
9483 happens during the EVAL_AVOID_SIDE_EFFECTS phase of the evaluation,
9484 but we'll focus mostly on the EVAL_NORMAL phase. In practice, the
9485 EVAL_AVOID_SIDE_EFFECTS phase allows us to simplify certain aspects of
9486 the evaluation compared to the EVAL_NORMAL, but is otherwise very
9489 Evaluating expressions is a little more complicated for Ada entities
9490 than it is for entities in languages such as C. The main reason for
9491 this is that Ada provides types whose definition might be dynamic.
9492 One example of such types is variant records. Or another example
9493 would be an array whose bounds can only be known at run time.
9495 The following description is a general guide as to what should be
9496 done (and what should NOT be done) in order to evaluate an expression
9497 involving such types, and when. This does not cover how the semantic
9498 information is encoded by GNAT as this is covered separatly. For the
9499 document used as the reference for the GNAT encoding, see exp_dbug.ads
9500 in the GNAT sources.
9502 Ideally, we should embed each part of this description next to its
9503 associated code. Unfortunately, the amount of code is so vast right
9504 now that it's hard to see whether the code handling a particular
9505 situation might be duplicated or not. One day, when the code is
9506 cleaned up, this guide might become redundant with the comments
9507 inserted in the code, and we might want to remove it.
9509 2. ``Fixing'' an Entity, the Simple Case:
9510 -----------------------------------------
9512 When evaluating Ada expressions, the tricky issue is that they may
9513 reference entities whose type contents and size are not statically
9514 known. Consider for instance a variant record:
9516 type Rec (Empty : Boolean := True) is record
9519 when False => Value : Integer;
9522 Yes : Rec := (Empty => False, Value => 1);
9523 No : Rec := (empty => True);
9525 The size and contents of that record depends on the value of the
9526 descriminant (Rec.Empty). At this point, neither the debugging
9527 information nor the associated type structure in GDB are able to
9528 express such dynamic types. So what the debugger does is to create
9529 "fixed" versions of the type that applies to the specific object.
9530 We also informally refer to this operation as "fixing" an object,
9531 which means creating its associated fixed type.
9533 Example: when printing the value of variable "Yes" above, its fixed
9534 type would look like this:
9541 On the other hand, if we printed the value of "No", its fixed type
9548 Things become a little more complicated when trying to fix an entity
9549 with a dynamic type that directly contains another dynamic type,
9550 such as an array of variant records, for instance. There are
9551 two possible cases: Arrays, and records.
9553 3. ``Fixing'' Arrays:
9554 ---------------------
9556 The type structure in GDB describes an array in terms of its bounds,
9557 and the type of its elements. By design, all elements in the array
9558 have the same type and we cannot represent an array of variant elements
9559 using the current type structure in GDB. When fixing an array,
9560 we cannot fix the array element, as we would potentially need one
9561 fixed type per element of the array. As a result, the best we can do
9562 when fixing an array is to produce an array whose bounds and size
9563 are correct (allowing us to read it from memory), but without having
9564 touched its element type. Fixing each element will be done later,
9565 when (if) necessary.
9567 Arrays are a little simpler to handle than records, because the same
9568 amount of memory is allocated for each element of the array, even if
9569 the amount of space actually used by each element differs from element
9570 to element. Consider for instance the following array of type Rec:
9572 type Rec_Array is array (1 .. 2) of Rec;
9574 The actual amount of memory occupied by each element might be different
9575 from element to element, depending on the value of their discriminant.
9576 But the amount of space reserved for each element in the array remains
9577 fixed regardless. So we simply need to compute that size using
9578 the debugging information available, from which we can then determine
9579 the array size (we multiply the number of elements of the array by
9580 the size of each element).
9582 The simplest case is when we have an array of a constrained element
9583 type. For instance, consider the following type declarations:
9585 type Bounded_String (Max_Size : Integer) is
9587 Buffer : String (1 .. Max_Size);
9589 type Bounded_String_Array is array (1 ..2) of Bounded_String (80);
9591 In this case, the compiler describes the array as an array of
9592 variable-size elements (identified by its XVS suffix) for which
9593 the size can be read in the parallel XVZ variable.
9595 In the case of an array of an unconstrained element type, the compiler
9596 wraps the array element inside a private PAD type. This type should not
9597 be shown to the user, and must be "unwrap"'ed before printing. Note
9598 that we also use the adjective "aligner" in our code to designate
9599 these wrapper types.
9601 In some cases, the size allocated for each element is statically
9602 known. In that case, the PAD type already has the correct size,
9603 and the array element should remain unfixed.
9605 But there are cases when this size is not statically known.
9606 For instance, assuming that "Five" is an integer variable:
9608 type Dynamic is array (1 .. Five) of Integer;
9609 type Wrapper (Has_Length : Boolean := False) is record
9612 when True => Length : Integer;
9616 type Wrapper_Array is array (1 .. 2) of Wrapper;
9618 Hello : Wrapper_Array := (others => (Has_Length => True,
9619 Data => (others => 17),
9623 The debugging info would describe variable Hello as being an
9624 array of a PAD type. The size of that PAD type is not statically
9625 known, but can be determined using a parallel XVZ variable.
9626 In that case, a copy of the PAD type with the correct size should
9627 be used for the fixed array.
9629 3. ``Fixing'' record type objects:
9630 ----------------------------------
9632 Things are slightly different from arrays in the case of dynamic
9633 record types. In this case, in order to compute the associated
9634 fixed type, we need to determine the size and offset of each of
9635 its components. This, in turn, requires us to compute the fixed
9636 type of each of these components.
9638 Consider for instance the example:
9640 type Bounded_String (Max_Size : Natural) is record
9641 Str : String (1 .. Max_Size);
9644 My_String : Bounded_String (Max_Size => 10);
9646 In that case, the position of field "Length" depends on the size
9647 of field Str, which itself depends on the value of the Max_Size
9648 discriminant. In order to fix the type of variable My_String,
9649 we need to fix the type of field Str. Therefore, fixing a variant
9650 record requires us to fix each of its components.
9652 However, if a component does not have a dynamic size, the component
9653 should not be fixed. In particular, fields that use a PAD type
9654 should not fixed. Here is an example where this might happen
9655 (assuming type Rec above):
9657 type Container (Big : Boolean) is record
9661 when True => Another : Integer;
9665 My_Container : Container := (Big => False,
9666 First => (Empty => True),
9669 In that example, the compiler creates a PAD type for component First,
9670 whose size is constant, and then positions the component After just
9671 right after it. The offset of component After is therefore constant
9674 The debugger computes the position of each field based on an algorithm
9675 that uses, among other things, the actual position and size of the field
9676 preceding it. Let's now imagine that the user is trying to print
9677 the value of My_Container. If the type fixing was recursive, we would
9678 end up computing the offset of field After based on the size of the
9679 fixed version of field First. And since in our example First has
9680 only one actual field, the size of the fixed type is actually smaller
9681 than the amount of space allocated to that field, and thus we would
9682 compute the wrong offset of field After.
9684 To make things more complicated, we need to watch out for dynamic
9685 components of variant records (identified by the ___XVL suffix in
9686 the component name). Even if the target type is a PAD type, the size
9687 of that type might not be statically known. So the PAD type needs
9688 to be unwrapped and the resulting type needs to be fixed. Otherwise,
9689 we might end up with the wrong size for our component. This can be
9690 observed with the following type declarations:
9692 type Octal is new Integer range 0 .. 7;
9693 type Octal_Array is array (Positive range <>) of Octal;
9694 pragma Pack (Octal_Array);
9696 type Octal_Buffer (Size : Positive) is record
9697 Buffer : Octal_Array (1 .. Size);
9701 In that case, Buffer is a PAD type whose size is unset and needs
9702 to be computed by fixing the unwrapped type.
9704 4. When to ``Fix'' un-``Fixed'' sub-elements of an entity:
9705 ----------------------------------------------------------
9707 Lastly, when should the sub-elements of an entity that remained unfixed
9708 thus far, be actually fixed?
9710 The answer is: Only when referencing that element. For instance
9711 when selecting one component of a record, this specific component
9712 should be fixed at that point in time. Or when printing the value
9713 of a record, each component should be fixed before its value gets
9714 printed. Similarly for arrays, the element of the array should be
9715 fixed when printing each element of the array, or when extracting
9716 one element out of that array. On the other hand, fixing should
9717 not be performed on the elements when taking a slice of an array!
9719 Note that one of the side effects of miscomputing the offset and
9720 size of each field is that we end up also miscomputing the size
9721 of the containing type. This can have adverse results when computing
9722 the value of an entity. GDB fetches the value of an entity based
9723 on the size of its type, and thus a wrong size causes GDB to fetch
9724 the wrong amount of memory. In the case where the computed size is
9725 too small, GDB fetches too little data to print the value of our
9726 entity. Results in this case are unpredictable, as we usually read
9727 past the buffer containing the data =:-o. */
9729 /* A helper function for TERNOP_IN_RANGE. */
9732 eval_ternop_in_range (struct type
*expect_type
, struct expression
*exp
,
9734 value
*arg1
, value
*arg2
, value
*arg3
)
9736 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
9737 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg3
);
9738 struct type
*type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
9740 value_from_longest (type
,
9741 (value_less (arg1
, arg3
)
9742 || value_equal (arg1
, arg3
))
9743 && (value_less (arg2
, arg1
)
9744 || value_equal (arg2
, arg1
)));
9747 /* A helper function for UNOP_NEG. */
9750 ada_unop_neg (struct type
*expect_type
,
9751 struct expression
*exp
,
9752 enum noside noside
, enum exp_opcode op
,
9755 unop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
);
9756 return value_neg (arg1
);
9759 /* A helper function for UNOP_IN_RANGE. */
9762 ada_unop_in_range (struct type
*expect_type
,
9763 struct expression
*exp
,
9764 enum noside noside
, enum exp_opcode op
,
9765 struct value
*arg1
, struct type
*type
)
9767 struct value
*arg2
, *arg3
;
9768 switch (type
->code ())
9771 lim_warning (_("Membership test incompletely implemented; "
9772 "always returns true"));
9773 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
9774 return value_from_longest (type
, (LONGEST
) 1);
9776 case TYPE_CODE_RANGE
:
9777 arg2
= value_from_longest (type
,
9778 type
->bounds ()->low
.const_val ());
9779 arg3
= value_from_longest (type
,
9780 type
->bounds ()->high
.const_val ());
9781 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
9782 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg3
);
9783 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
9785 value_from_longest (type
,
9786 (value_less (arg1
, arg3
)
9787 || value_equal (arg1
, arg3
))
9788 && (value_less (arg2
, arg1
)
9789 || value_equal (arg2
, arg1
)));
9793 /* A helper function for OP_ATR_TAG. */
9796 ada_atr_tag (struct type
*expect_type
,
9797 struct expression
*exp
,
9798 enum noside noside
, enum exp_opcode op
,
9801 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
9802 return value_zero (ada_tag_type (arg1
), not_lval
);
9804 return ada_value_tag (arg1
);
9807 /* A helper function for OP_ATR_SIZE. */
9810 ada_atr_size (struct type
*expect_type
,
9811 struct expression
*exp
,
9812 enum noside noside
, enum exp_opcode op
,
9815 struct type
*type
= value_type (arg1
);
9817 /* If the argument is a reference, then dereference its type, since
9818 the user is really asking for the size of the actual object,
9819 not the size of the pointer. */
9820 if (type
->code () == TYPE_CODE_REF
)
9821 type
= TYPE_TARGET_TYPE (type
);
9823 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
9824 return value_zero (builtin_type (exp
->gdbarch
)->builtin_int
, not_lval
);
9826 return value_from_longest (builtin_type (exp
->gdbarch
)->builtin_int
,
9827 TARGET_CHAR_BIT
* TYPE_LENGTH (type
));
9830 /* A helper function for UNOP_ABS. */
9833 ada_abs (struct type
*expect_type
,
9834 struct expression
*exp
,
9835 enum noside noside
, enum exp_opcode op
,
9838 unop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
);
9839 if (value_less (arg1
, value_zero (value_type (arg1
), not_lval
)))
9840 return value_neg (arg1
);
9845 /* A helper function for BINOP_MUL. */
9848 ada_mult_binop (struct type
*expect_type
,
9849 struct expression
*exp
,
9850 enum noside noside
, enum exp_opcode op
,
9851 struct value
*arg1
, struct value
*arg2
)
9853 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
9855 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
9856 return value_zero (value_type (arg1
), not_lval
);
9860 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
9861 return ada_value_binop (arg1
, arg2
, op
);
9865 /* A helper function for BINOP_EQUAL and BINOP_NOTEQUAL. */
9868 ada_equal_binop (struct type
*expect_type
,
9869 struct expression
*exp
,
9870 enum noside noside
, enum exp_opcode op
,
9871 struct value
*arg1
, struct value
*arg2
)
9874 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
9878 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
9879 tem
= ada_value_equal (arg1
, arg2
);
9881 if (op
== BINOP_NOTEQUAL
)
9883 struct type
*type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
9884 return value_from_longest (type
, (LONGEST
) tem
);
9887 /* A helper function for TERNOP_SLICE. */
9890 ada_ternop_slice (struct expression
*exp
,
9892 struct value
*array
, struct value
*low_bound_val
,
9893 struct value
*high_bound_val
)
9898 low_bound_val
= coerce_ref (low_bound_val
);
9899 high_bound_val
= coerce_ref (high_bound_val
);
9900 low_bound
= value_as_long (low_bound_val
);
9901 high_bound
= value_as_long (high_bound_val
);
9903 /* If this is a reference to an aligner type, then remove all
9905 if (value_type (array
)->code () == TYPE_CODE_REF
9906 && ada_is_aligner_type (TYPE_TARGET_TYPE (value_type (array
))))
9907 TYPE_TARGET_TYPE (value_type (array
)) =
9908 ada_aligned_type (TYPE_TARGET_TYPE (value_type (array
)));
9910 if (ada_is_any_packed_array_type (value_type (array
)))
9911 error (_("cannot slice a packed array"));
9913 /* If this is a reference to an array or an array lvalue,
9914 convert to a pointer. */
9915 if (value_type (array
)->code () == TYPE_CODE_REF
9916 || (value_type (array
)->code () == TYPE_CODE_ARRAY
9917 && VALUE_LVAL (array
) == lval_memory
))
9918 array
= value_addr (array
);
9920 if (noside
== EVAL_AVOID_SIDE_EFFECTS
9921 && ada_is_array_descriptor_type (ada_check_typedef
9922 (value_type (array
))))
9923 return empty_array (ada_type_of_array (array
, 0), low_bound
,
9926 array
= ada_coerce_to_simple_array_ptr (array
);
9928 /* If we have more than one level of pointer indirection,
9929 dereference the value until we get only one level. */
9930 while (value_type (array
)->code () == TYPE_CODE_PTR
9931 && (TYPE_TARGET_TYPE (value_type (array
))->code ()
9933 array
= value_ind (array
);
9935 /* Make sure we really do have an array type before going further,
9936 to avoid a SEGV when trying to get the index type or the target
9937 type later down the road if the debug info generated by
9938 the compiler is incorrect or incomplete. */
9939 if (!ada_is_simple_array_type (value_type (array
)))
9940 error (_("cannot take slice of non-array"));
9942 if (ada_check_typedef (value_type (array
))->code ()
9945 struct type
*type0
= ada_check_typedef (value_type (array
));
9947 if (high_bound
< low_bound
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
9948 return empty_array (TYPE_TARGET_TYPE (type0
), low_bound
, high_bound
);
9951 struct type
*arr_type0
=
9952 to_fixed_array_type (TYPE_TARGET_TYPE (type0
), NULL
, 1);
9954 return ada_value_slice_from_ptr (array
, arr_type0
,
9955 longest_to_int (low_bound
),
9956 longest_to_int (high_bound
));
9959 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
9961 else if (high_bound
< low_bound
)
9962 return empty_array (value_type (array
), low_bound
, high_bound
);
9964 return ada_value_slice (array
, longest_to_int (low_bound
),
9965 longest_to_int (high_bound
));
9968 /* A helper function for BINOP_IN_BOUNDS. */
9971 ada_binop_in_bounds (struct expression
*exp
, enum noside noside
,
9972 struct value
*arg1
, struct value
*arg2
, int n
)
9974 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
9976 struct type
*type
= language_bool_type (exp
->language_defn
,
9978 return value_zero (type
, not_lval
);
9981 struct type
*type
= ada_index_type (value_type (arg2
), n
, "range");
9983 type
= value_type (arg1
);
9985 value
*arg3
= value_from_longest (type
, ada_array_bound (arg2
, n
, 1));
9986 arg2
= value_from_longest (type
, ada_array_bound (arg2
, n
, 0));
9988 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
9989 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg3
);
9990 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
9991 return value_from_longest (type
,
9992 (value_less (arg1
, arg3
)
9993 || value_equal (arg1
, arg3
))
9994 && (value_less (arg2
, arg1
)
9995 || value_equal (arg2
, arg1
)));
9998 /* A helper function for some attribute operations. */
10001 ada_unop_atr (struct expression
*exp
, enum noside noside
, enum exp_opcode op
,
10002 struct value
*arg1
, struct type
*type_arg
, int tem
)
10004 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
10006 if (type_arg
== NULL
)
10007 type_arg
= value_type (arg1
);
10009 if (ada_is_constrained_packed_array_type (type_arg
))
10010 type_arg
= decode_constrained_packed_array_type (type_arg
);
10012 if (!discrete_type_p (type_arg
))
10016 default: /* Should never happen. */
10017 error (_("unexpected attribute encountered"));
10020 type_arg
= ada_index_type (type_arg
, tem
,
10021 ada_attribute_name (op
));
10023 case OP_ATR_LENGTH
:
10024 type_arg
= builtin_type (exp
->gdbarch
)->builtin_int
;
10029 return value_zero (type_arg
, not_lval
);
10031 else if (type_arg
== NULL
)
10033 arg1
= ada_coerce_ref (arg1
);
10035 if (ada_is_constrained_packed_array_type (value_type (arg1
)))
10036 arg1
= ada_coerce_to_simple_array (arg1
);
10039 if (op
== OP_ATR_LENGTH
)
10040 type
= builtin_type (exp
->gdbarch
)->builtin_int
;
10043 type
= ada_index_type (value_type (arg1
), tem
,
10044 ada_attribute_name (op
));
10046 type
= builtin_type (exp
->gdbarch
)->builtin_int
;
10051 default: /* Should never happen. */
10052 error (_("unexpected attribute encountered"));
10054 return value_from_longest
10055 (type
, ada_array_bound (arg1
, tem
, 0));
10057 return value_from_longest
10058 (type
, ada_array_bound (arg1
, tem
, 1));
10059 case OP_ATR_LENGTH
:
10060 return value_from_longest
10061 (type
, ada_array_length (arg1
, tem
));
10064 else if (discrete_type_p (type_arg
))
10066 struct type
*range_type
;
10067 const char *name
= ada_type_name (type_arg
);
10070 if (name
!= NULL
&& type_arg
->code () != TYPE_CODE_ENUM
)
10071 range_type
= to_fixed_range_type (type_arg
, NULL
);
10072 if (range_type
== NULL
)
10073 range_type
= type_arg
;
10077 error (_("unexpected attribute encountered"));
10079 return value_from_longest
10080 (range_type
, ada_discrete_type_low_bound (range_type
));
10082 return value_from_longest
10083 (range_type
, ada_discrete_type_high_bound (range_type
));
10084 case OP_ATR_LENGTH
:
10085 error (_("the 'length attribute applies only to array types"));
10088 else if (type_arg
->code () == TYPE_CODE_FLT
)
10089 error (_("unimplemented type attribute"));
10094 if (ada_is_constrained_packed_array_type (type_arg
))
10095 type_arg
= decode_constrained_packed_array_type (type_arg
);
10098 if (op
== OP_ATR_LENGTH
)
10099 type
= builtin_type (exp
->gdbarch
)->builtin_int
;
10102 type
= ada_index_type (type_arg
, tem
, ada_attribute_name (op
));
10104 type
= builtin_type (exp
->gdbarch
)->builtin_int
;
10110 error (_("unexpected attribute encountered"));
10112 low
= ada_array_bound_from_type (type_arg
, tem
, 0);
10113 return value_from_longest (type
, low
);
10115 high
= ada_array_bound_from_type (type_arg
, tem
, 1);
10116 return value_from_longest (type
, high
);
10117 case OP_ATR_LENGTH
:
10118 low
= ada_array_bound_from_type (type_arg
, tem
, 0);
10119 high
= ada_array_bound_from_type (type_arg
, tem
, 1);
10120 return value_from_longest (type
, high
- low
+ 1);
10125 /* A helper function for OP_ATR_MIN and OP_ATR_MAX. */
10128 ada_binop_minmax (struct type
*expect_type
,
10129 struct expression
*exp
,
10130 enum noside noside
, enum exp_opcode op
,
10131 struct value
*arg1
, struct value
*arg2
)
10133 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
10134 return value_zero (value_type (arg1
), not_lval
);
10137 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
10138 return value_binop (arg1
, arg2
, op
);
10142 /* A helper function for BINOP_EXP. */
10145 ada_binop_exp (struct type
*expect_type
,
10146 struct expression
*exp
,
10147 enum noside noside
, enum exp_opcode op
,
10148 struct value
*arg1
, struct value
*arg2
)
10150 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
10151 return value_zero (value_type (arg1
), not_lval
);
10154 /* For integer exponentiation operations,
10155 only promote the first argument. */
10156 if (is_integral_type (value_type (arg2
)))
10157 unop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
);
10159 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
10161 return value_binop (arg1
, arg2
, op
);
10168 /* See ada-exp.h. */
10171 ada_resolvable::replace (operation_up
&&owner
,
10172 struct expression
*exp
,
10173 bool deprocedure_p
,
10174 bool parse_completion
,
10175 innermost_block_tracker
*tracker
,
10176 struct type
*context_type
)
10178 if (resolve (exp
, deprocedure_p
, parse_completion
, tracker
, context_type
))
10179 return (make_operation
<ada_funcall_operation
>
10180 (std::move (owner
),
10181 std::vector
<operation_up
> ()));
10182 return std::move (owner
);
10185 /* Convert the character literal whose ASCII value would be VAL to the
10186 appropriate value of type TYPE, if there is a translation.
10187 Otherwise return VAL. Hence, in an enumeration type ('A', 'B'),
10188 the literal 'A' (VAL == 65), returns 0. */
10191 convert_char_literal (struct type
*type
, LONGEST val
)
10198 type
= check_typedef (type
);
10199 if (type
->code () != TYPE_CODE_ENUM
)
10202 if ((val
>= 'a' && val
<= 'z') || (val
>= '0' && val
<= '9'))
10203 xsnprintf (name
, sizeof (name
), "Q%c", (int) val
);
10205 xsnprintf (name
, sizeof (name
), "QU%02x", (int) val
);
10206 size_t len
= strlen (name
);
10207 for (f
= 0; f
< type
->num_fields (); f
+= 1)
10209 /* Check the suffix because an enum constant in a package will
10210 have a name like "pkg__QUxx". This is safe enough because we
10211 already have the correct type, and because mangling means
10212 there can't be clashes. */
10213 const char *ename
= type
->field (f
).name ();
10214 size_t elen
= strlen (ename
);
10216 if (elen
>= len
&& strcmp (name
, ename
+ elen
- len
) == 0)
10217 return type
->field (f
).loc_enumval ();
10222 /* See ada-exp.h. */
10225 ada_char_operation::replace (operation_up
&&owner
,
10226 struct expression
*exp
,
10227 bool deprocedure_p
,
10228 bool parse_completion
,
10229 innermost_block_tracker
*tracker
,
10230 struct type
*context_type
)
10232 operation_up result
= std::move (owner
);
10234 if (context_type
!= nullptr && context_type
->code () == TYPE_CODE_ENUM
)
10236 gdb_assert (result
.get () == this);
10237 std::get
<0> (m_storage
) = context_type
;
10238 std::get
<1> (m_storage
)
10239 = convert_char_literal (context_type
, std::get
<1> (m_storage
));
10242 return make_operation
<ada_wrapped_operation
> (std::move (result
));
10246 ada_wrapped_operation::evaluate (struct type
*expect_type
,
10247 struct expression
*exp
,
10248 enum noside noside
)
10250 value
*result
= std::get
<0> (m_storage
)->evaluate (expect_type
, exp
, noside
);
10251 if (noside
== EVAL_NORMAL
)
10252 result
= unwrap_value (result
);
10254 /* If evaluating an OP_FLOAT and an EXPECT_TYPE was provided,
10255 then we need to perform the conversion manually, because
10256 evaluate_subexp_standard doesn't do it. This conversion is
10257 necessary in Ada because the different kinds of float/fixed
10258 types in Ada have different representations.
10260 Similarly, we need to perform the conversion from OP_LONG
10262 if ((opcode () == OP_FLOAT
|| opcode () == OP_LONG
) && expect_type
!= NULL
)
10263 result
= ada_value_cast (expect_type
, result
);
10269 ada_string_operation::evaluate (struct type
*expect_type
,
10270 struct expression
*exp
,
10271 enum noside noside
)
10273 value
*result
= string_operation::evaluate (expect_type
, exp
, noside
);
10274 /* The result type will have code OP_STRING, bashed there from
10275 OP_ARRAY. Bash it back. */
10276 if (value_type (result
)->code () == TYPE_CODE_STRING
)
10277 value_type (result
)->set_code (TYPE_CODE_ARRAY
);
10282 ada_qual_operation::evaluate (struct type
*expect_type
,
10283 struct expression
*exp
,
10284 enum noside noside
)
10286 struct type
*type
= std::get
<1> (m_storage
);
10287 return std::get
<0> (m_storage
)->evaluate (type
, exp
, noside
);
10291 ada_ternop_range_operation::evaluate (struct type
*expect_type
,
10292 struct expression
*exp
,
10293 enum noside noside
)
10295 value
*arg0
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
10296 value
*arg1
= std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
10297 value
*arg2
= std::get
<2> (m_storage
)->evaluate (nullptr, exp
, noside
);
10298 return eval_ternop_in_range (expect_type
, exp
, noside
, arg0
, arg1
, arg2
);
10302 ada_binop_addsub_operation::evaluate (struct type
*expect_type
,
10303 struct expression
*exp
,
10304 enum noside noside
)
10306 value
*arg1
= std::get
<1> (m_storage
)->evaluate_with_coercion (exp
, noside
);
10307 value
*arg2
= std::get
<2> (m_storage
)->evaluate_with_coercion (exp
, noside
);
10309 auto do_op
= [=] (LONGEST x
, LONGEST y
)
10311 if (std::get
<0> (m_storage
) == BINOP_ADD
)
10316 if (value_type (arg1
)->code () == TYPE_CODE_PTR
)
10317 return (value_from_longest
10318 (value_type (arg1
),
10319 do_op (value_as_long (arg1
), value_as_long (arg2
))));
10320 if (value_type (arg2
)->code () == TYPE_CODE_PTR
)
10321 return (value_from_longest
10322 (value_type (arg2
),
10323 do_op (value_as_long (arg1
), value_as_long (arg2
))));
10324 /* Preserve the original type for use by the range case below.
10325 We cannot cast the result to a reference type, so if ARG1 is
10326 a reference type, find its underlying type. */
10327 struct type
*type
= value_type (arg1
);
10328 while (type
->code () == TYPE_CODE_REF
)
10329 type
= TYPE_TARGET_TYPE (type
);
10330 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
10331 arg1
= value_binop (arg1
, arg2
, std::get
<0> (m_storage
));
10332 /* We need to special-case the result with a range.
10333 This is done for the benefit of "ptype". gdb's Ada support
10334 historically used the LHS to set the result type here, so
10335 preserve this behavior. */
10336 if (type
->code () == TYPE_CODE_RANGE
)
10337 arg1
= value_cast (type
, arg1
);
10342 ada_unop_atr_operation::evaluate (struct type
*expect_type
,
10343 struct expression
*exp
,
10344 enum noside noside
)
10346 struct type
*type_arg
= nullptr;
10347 value
*val
= nullptr;
10349 if (std::get
<0> (m_storage
)->opcode () == OP_TYPE
)
10351 value
*tem
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
10352 EVAL_AVOID_SIDE_EFFECTS
);
10353 type_arg
= value_type (tem
);
10356 val
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
10358 return ada_unop_atr (exp
, noside
, std::get
<1> (m_storage
),
10359 val
, type_arg
, std::get
<2> (m_storage
));
10363 ada_var_msym_value_operation::evaluate_for_cast (struct type
*expect_type
,
10364 struct expression
*exp
,
10365 enum noside noside
)
10367 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
10368 return value_zero (expect_type
, not_lval
);
10370 const bound_minimal_symbol
&b
= std::get
<0> (m_storage
);
10371 value
*val
= evaluate_var_msym_value (noside
, b
.objfile
, b
.minsym
);
10373 val
= ada_value_cast (expect_type
, val
);
10375 /* Follow the Ada language semantics that do not allow taking
10376 an address of the result of a cast (view conversion in Ada). */
10377 if (VALUE_LVAL (val
) == lval_memory
)
10379 if (value_lazy (val
))
10380 value_fetch_lazy (val
);
10381 VALUE_LVAL (val
) = not_lval
;
10387 ada_var_value_operation::evaluate_for_cast (struct type
*expect_type
,
10388 struct expression
*exp
,
10389 enum noside noside
)
10391 value
*val
= evaluate_var_value (noside
,
10392 std::get
<0> (m_storage
).block
,
10393 std::get
<0> (m_storage
).symbol
);
10395 val
= ada_value_cast (expect_type
, val
);
10397 /* Follow the Ada language semantics that do not allow taking
10398 an address of the result of a cast (view conversion in Ada). */
10399 if (VALUE_LVAL (val
) == lval_memory
)
10401 if (value_lazy (val
))
10402 value_fetch_lazy (val
);
10403 VALUE_LVAL (val
) = not_lval
;
10409 ada_var_value_operation::evaluate (struct type
*expect_type
,
10410 struct expression
*exp
,
10411 enum noside noside
)
10413 symbol
*sym
= std::get
<0> (m_storage
).symbol
;
10415 if (SYMBOL_DOMAIN (sym
) == UNDEF_DOMAIN
)
10416 /* Only encountered when an unresolved symbol occurs in a
10417 context other than a function call, in which case, it is
10419 error (_("Unexpected unresolved symbol, %s, during evaluation"),
10420 sym
->print_name ());
10422 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
10424 struct type
*type
= static_unwrap_type (SYMBOL_TYPE (sym
));
10425 /* Check to see if this is a tagged type. We also need to handle
10426 the case where the type is a reference to a tagged type, but
10427 we have to be careful to exclude pointers to tagged types.
10428 The latter should be shown as usual (as a pointer), whereas
10429 a reference should mostly be transparent to the user. */
10430 if (ada_is_tagged_type (type
, 0)
10431 || (type
->code () == TYPE_CODE_REF
10432 && ada_is_tagged_type (TYPE_TARGET_TYPE (type
), 0)))
10434 /* Tagged types are a little special in the fact that the real
10435 type is dynamic and can only be determined by inspecting the
10436 object's tag. This means that we need to get the object's
10437 value first (EVAL_NORMAL) and then extract the actual object
10440 Note that we cannot skip the final step where we extract
10441 the object type from its tag, because the EVAL_NORMAL phase
10442 results in dynamic components being resolved into fixed ones.
10443 This can cause problems when trying to print the type
10444 description of tagged types whose parent has a dynamic size:
10445 We use the type name of the "_parent" component in order
10446 to print the name of the ancestor type in the type description.
10447 If that component had a dynamic size, the resolution into
10448 a fixed type would result in the loss of that type name,
10449 thus preventing us from printing the name of the ancestor
10450 type in the type description. */
10451 value
*arg1
= evaluate (nullptr, exp
, EVAL_NORMAL
);
10453 if (type
->code () != TYPE_CODE_REF
)
10455 struct type
*actual_type
;
10457 actual_type
= type_from_tag (ada_value_tag (arg1
));
10458 if (actual_type
== NULL
)
10459 /* If, for some reason, we were unable to determine
10460 the actual type from the tag, then use the static
10461 approximation that we just computed as a fallback.
10462 This can happen if the debugging information is
10463 incomplete, for instance. */
10464 actual_type
= type
;
10465 return value_zero (actual_type
, not_lval
);
10469 /* In the case of a ref, ada_coerce_ref takes care
10470 of determining the actual type. But the evaluation
10471 should return a ref as it should be valid to ask
10472 for its address; so rebuild a ref after coerce. */
10473 arg1
= ada_coerce_ref (arg1
);
10474 return value_ref (arg1
, TYPE_CODE_REF
);
10478 /* Records and unions for which GNAT encodings have been
10479 generated need to be statically fixed as well.
10480 Otherwise, non-static fixing produces a type where
10481 all dynamic properties are removed, which prevents "ptype"
10482 from being able to completely describe the type.
10483 For instance, a case statement in a variant record would be
10484 replaced by the relevant components based on the actual
10485 value of the discriminants. */
10486 if ((type
->code () == TYPE_CODE_STRUCT
10487 && dynamic_template_type (type
) != NULL
)
10488 || (type
->code () == TYPE_CODE_UNION
10489 && ada_find_parallel_type (type
, "___XVU") != NULL
))
10490 return value_zero (to_static_fixed_type (type
), not_lval
);
10493 value
*arg1
= var_value_operation::evaluate (expect_type
, exp
, noside
);
10494 return ada_to_fixed_value (arg1
);
10498 ada_var_value_operation::resolve (struct expression
*exp
,
10499 bool deprocedure_p
,
10500 bool parse_completion
,
10501 innermost_block_tracker
*tracker
,
10502 struct type
*context_type
)
10504 symbol
*sym
= std::get
<0> (m_storage
).symbol
;
10505 if (SYMBOL_DOMAIN (sym
) == UNDEF_DOMAIN
)
10507 block_symbol resolved
10508 = ada_resolve_variable (sym
, std::get
<0> (m_storage
).block
,
10509 context_type
, parse_completion
,
10510 deprocedure_p
, tracker
);
10511 std::get
<0> (m_storage
) = resolved
;
10515 && (SYMBOL_TYPE (std::get
<0> (m_storage
).symbol
)->code ()
10516 == TYPE_CODE_FUNC
))
10523 ada_atr_val_operation::evaluate (struct type
*expect_type
,
10524 struct expression
*exp
,
10525 enum noside noside
)
10527 value
*arg
= std::get
<1> (m_storage
)->evaluate (nullptr, exp
, noside
);
10528 return ada_val_atr (noside
, std::get
<0> (m_storage
), arg
);
10532 ada_unop_ind_operation::evaluate (struct type
*expect_type
,
10533 struct expression
*exp
,
10534 enum noside noside
)
10536 value
*arg1
= std::get
<0> (m_storage
)->evaluate (expect_type
, exp
, noside
);
10538 struct type
*type
= ada_check_typedef (value_type (arg1
));
10539 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
10541 if (ada_is_array_descriptor_type (type
))
10542 /* GDB allows dereferencing GNAT array descriptors. */
10544 struct type
*arrType
= ada_type_of_array (arg1
, 0);
10546 if (arrType
== NULL
)
10547 error (_("Attempt to dereference null array pointer."));
10548 return value_at_lazy (arrType
, 0);
10550 else if (type
->code () == TYPE_CODE_PTR
10551 || type
->code () == TYPE_CODE_REF
10552 /* In C you can dereference an array to get the 1st elt. */
10553 || type
->code () == TYPE_CODE_ARRAY
)
10555 /* As mentioned in the OP_VAR_VALUE case, tagged types can
10556 only be determined by inspecting the object's tag.
10557 This means that we need to evaluate completely the
10558 expression in order to get its type. */
10560 if ((type
->code () == TYPE_CODE_REF
10561 || type
->code () == TYPE_CODE_PTR
)
10562 && ada_is_tagged_type (TYPE_TARGET_TYPE (type
), 0))
10564 arg1
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
10566 type
= value_type (ada_value_ind (arg1
));
10570 type
= to_static_fixed_type
10572 (ada_check_typedef (TYPE_TARGET_TYPE (type
))));
10574 return value_zero (type
, lval_memory
);
10576 else if (type
->code () == TYPE_CODE_INT
)
10578 /* GDB allows dereferencing an int. */
10579 if (expect_type
== NULL
)
10580 return value_zero (builtin_type (exp
->gdbarch
)->builtin_int
,
10585 to_static_fixed_type (ada_aligned_type (expect_type
));
10586 return value_zero (expect_type
, lval_memory
);
10590 error (_("Attempt to take contents of a non-pointer value."));
10592 arg1
= ada_coerce_ref (arg1
); /* FIXME: What is this for?? */
10593 type
= ada_check_typedef (value_type (arg1
));
10595 if (type
->code () == TYPE_CODE_INT
)
10596 /* GDB allows dereferencing an int. If we were given
10597 the expect_type, then use that as the target type.
10598 Otherwise, assume that the target type is an int. */
10600 if (expect_type
!= NULL
)
10601 return ada_value_ind (value_cast (lookup_pointer_type (expect_type
),
10604 return value_at_lazy (builtin_type (exp
->gdbarch
)->builtin_int
,
10605 (CORE_ADDR
) value_as_address (arg1
));
10608 if (ada_is_array_descriptor_type (type
))
10609 /* GDB allows dereferencing GNAT array descriptors. */
10610 return ada_coerce_to_simple_array (arg1
);
10612 return ada_value_ind (arg1
);
10616 ada_structop_operation::evaluate (struct type
*expect_type
,
10617 struct expression
*exp
,
10618 enum noside noside
)
10620 value
*arg1
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
, noside
);
10621 const char *str
= std::get
<1> (m_storage
).c_str ();
10622 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
10625 struct type
*type1
= value_type (arg1
);
10627 if (ada_is_tagged_type (type1
, 1))
10629 type
= ada_lookup_struct_elt_type (type1
, str
, 1, 1);
10631 /* If the field is not found, check if it exists in the
10632 extension of this object's type. This means that we
10633 need to evaluate completely the expression. */
10637 arg1
= std::get
<0> (m_storage
)->evaluate (nullptr, exp
,
10639 arg1
= ada_value_struct_elt (arg1
, str
, 0);
10640 arg1
= unwrap_value (arg1
);
10641 type
= value_type (ada_to_fixed_value (arg1
));
10645 type
= ada_lookup_struct_elt_type (type1
, str
, 1, 0);
10647 return value_zero (ada_aligned_type (type
), lval_memory
);
10651 arg1
= ada_value_struct_elt (arg1
, str
, 0);
10652 arg1
= unwrap_value (arg1
);
10653 return ada_to_fixed_value (arg1
);
10658 ada_funcall_operation::evaluate (struct type
*expect_type
,
10659 struct expression
*exp
,
10660 enum noside noside
)
10662 const std::vector
<operation_up
> &args_up
= std::get
<1> (m_storage
);
10663 int nargs
= args_up
.size ();
10664 std::vector
<value
*> argvec (nargs
);
10665 operation_up
&callee_op
= std::get
<0> (m_storage
);
10667 ada_var_value_operation
*avv
10668 = dynamic_cast<ada_var_value_operation
*> (callee_op
.get ());
10670 && SYMBOL_DOMAIN (avv
->get_symbol ()) == UNDEF_DOMAIN
)
10671 error (_("Unexpected unresolved symbol, %s, during evaluation"),
10672 avv
->get_symbol ()->print_name ());
10674 value
*callee
= callee_op
->evaluate (nullptr, exp
, noside
);
10675 for (int i
= 0; i
< args_up
.size (); ++i
)
10676 argvec
[i
] = args_up
[i
]->evaluate (nullptr, exp
, noside
);
10678 if (ada_is_constrained_packed_array_type
10679 (desc_base_type (value_type (callee
))))
10680 callee
= ada_coerce_to_simple_array (callee
);
10681 else if (value_type (callee
)->code () == TYPE_CODE_ARRAY
10682 && TYPE_FIELD_BITSIZE (value_type (callee
), 0) != 0)
10683 /* This is a packed array that has already been fixed, and
10684 therefore already coerced to a simple array. Nothing further
10687 else if (value_type (callee
)->code () == TYPE_CODE_REF
)
10689 /* Make sure we dereference references so that all the code below
10690 feels like it's really handling the referenced value. Wrapping
10691 types (for alignment) may be there, so make sure we strip them as
10693 callee
= ada_to_fixed_value (coerce_ref (callee
));
10695 else if (value_type (callee
)->code () == TYPE_CODE_ARRAY
10696 && VALUE_LVAL (callee
) == lval_memory
)
10697 callee
= value_addr (callee
);
10699 struct type
*type
= ada_check_typedef (value_type (callee
));
10701 /* Ada allows us to implicitly dereference arrays when subscripting
10702 them. So, if this is an array typedef (encoding use for array
10703 access types encoded as fat pointers), strip it now. */
10704 if (type
->code () == TYPE_CODE_TYPEDEF
)
10705 type
= ada_typedef_target_type (type
);
10707 if (type
->code () == TYPE_CODE_PTR
)
10709 switch (ada_check_typedef (TYPE_TARGET_TYPE (type
))->code ())
10711 case TYPE_CODE_FUNC
:
10712 type
= ada_check_typedef (TYPE_TARGET_TYPE (type
));
10714 case TYPE_CODE_ARRAY
:
10716 case TYPE_CODE_STRUCT
:
10717 if (noside
!= EVAL_AVOID_SIDE_EFFECTS
)
10718 callee
= ada_value_ind (callee
);
10719 type
= ada_check_typedef (TYPE_TARGET_TYPE (type
));
10722 error (_("cannot subscript or call something of type `%s'"),
10723 ada_type_name (value_type (callee
)));
10728 switch (type
->code ())
10730 case TYPE_CODE_FUNC
:
10731 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
10733 if (TYPE_TARGET_TYPE (type
) == NULL
)
10734 error_call_unknown_return_type (NULL
);
10735 return allocate_value (TYPE_TARGET_TYPE (type
));
10737 return call_function_by_hand (callee
, NULL
, argvec
);
10738 case TYPE_CODE_INTERNAL_FUNCTION
:
10739 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
10740 /* We don't know anything about what the internal
10741 function might return, but we have to return
10743 return value_zero (builtin_type (exp
->gdbarch
)->builtin_int
,
10746 return call_internal_function (exp
->gdbarch
, exp
->language_defn
,
10750 case TYPE_CODE_STRUCT
:
10754 arity
= ada_array_arity (type
);
10755 type
= ada_array_element_type (type
, nargs
);
10757 error (_("cannot subscript or call a record"));
10758 if (arity
!= nargs
)
10759 error (_("wrong number of subscripts; expecting %d"), arity
);
10760 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
10761 return value_zero (ada_aligned_type (type
), lval_memory
);
10763 unwrap_value (ada_value_subscript
10764 (callee
, nargs
, argvec
.data ()));
10766 case TYPE_CODE_ARRAY
:
10767 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
10769 type
= ada_array_element_type (type
, nargs
);
10771 error (_("element type of array unknown"));
10773 return value_zero (ada_aligned_type (type
), lval_memory
);
10776 unwrap_value (ada_value_subscript
10777 (ada_coerce_to_simple_array (callee
),
10778 nargs
, argvec
.data ()));
10779 case TYPE_CODE_PTR
: /* Pointer to array */
10780 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
10782 type
= to_fixed_array_type (TYPE_TARGET_TYPE (type
), NULL
, 1);
10783 type
= ada_array_element_type (type
, nargs
);
10785 error (_("element type of array unknown"));
10787 return value_zero (ada_aligned_type (type
), lval_memory
);
10790 unwrap_value (ada_value_ptr_subscript (callee
, nargs
,
10794 error (_("Attempt to index or call something other than an "
10795 "array or function"));
10800 ada_funcall_operation::resolve (struct expression
*exp
,
10801 bool deprocedure_p
,
10802 bool parse_completion
,
10803 innermost_block_tracker
*tracker
,
10804 struct type
*context_type
)
10806 operation_up
&callee_op
= std::get
<0> (m_storage
);
10808 ada_var_value_operation
*avv
10809 = dynamic_cast<ada_var_value_operation
*> (callee_op
.get ());
10810 if (avv
== nullptr)
10813 symbol
*sym
= avv
->get_symbol ();
10814 if (SYMBOL_DOMAIN (sym
) != UNDEF_DOMAIN
)
10817 const std::vector
<operation_up
> &args_up
= std::get
<1> (m_storage
);
10818 int nargs
= args_up
.size ();
10819 std::vector
<value
*> argvec (nargs
);
10821 for (int i
= 0; i
< args_up
.size (); ++i
)
10822 argvec
[i
] = args_up
[i
]->evaluate (nullptr, exp
, EVAL_AVOID_SIDE_EFFECTS
);
10824 const block
*block
= avv
->get_block ();
10825 block_symbol resolved
10826 = ada_resolve_funcall (sym
, block
,
10827 context_type
, parse_completion
,
10828 nargs
, argvec
.data (),
10831 std::get
<0> (m_storage
)
10832 = make_operation
<ada_var_value_operation
> (resolved
);
10837 ada_ternop_slice_operation::resolve (struct expression
*exp
,
10838 bool deprocedure_p
,
10839 bool parse_completion
,
10840 innermost_block_tracker
*tracker
,
10841 struct type
*context_type
)
10843 /* Historically this check was done during resolution, so we
10844 continue that here. */
10845 value
*v
= std::get
<0> (m_storage
)->evaluate (context_type
, exp
,
10846 EVAL_AVOID_SIDE_EFFECTS
);
10847 if (ada_is_any_packed_array_type (value_type (v
)))
10848 error (_("cannot slice a packed array"));
10856 /* Return non-zero iff TYPE represents a System.Address type. */
10859 ada_is_system_address_type (struct type
*type
)
10861 return (type
->name () && strcmp (type
->name (), "system__address") == 0);
10868 /* Scan STR beginning at position K for a discriminant name, and
10869 return the value of that discriminant field of DVAL in *PX. If
10870 PNEW_K is not null, put the position of the character beyond the
10871 name scanned in *PNEW_K. Return 1 if successful; return 0 and do
10872 not alter *PX and *PNEW_K if unsuccessful. */
10875 scan_discrim_bound (const char *str
, int k
, struct value
*dval
, LONGEST
* px
,
10878 static std::string storage
;
10879 const char *pstart
, *pend
, *bound
;
10880 struct value
*bound_val
;
10882 if (dval
== NULL
|| str
== NULL
|| str
[k
] == '\0')
10886 pend
= strstr (pstart
, "__");
10890 k
+= strlen (bound
);
10894 int len
= pend
- pstart
;
10896 /* Strip __ and beyond. */
10897 storage
= std::string (pstart
, len
);
10898 bound
= storage
.c_str ();
10902 bound_val
= ada_search_struct_field (bound
, dval
, 0, value_type (dval
));
10903 if (bound_val
== NULL
)
10906 *px
= value_as_long (bound_val
);
10907 if (pnew_k
!= NULL
)
10912 /* Value of variable named NAME. Only exact matches are considered.
10913 If no such variable found, then if ERR_MSG is null, returns 0, and
10914 otherwise causes an error with message ERR_MSG. */
10916 static struct value
*
10917 get_var_value (const char *name
, const char *err_msg
)
10919 std::string quoted_name
= add_angle_brackets (name
);
10921 lookup_name_info
lookup_name (quoted_name
, symbol_name_match_type::FULL
);
10923 std::vector
<struct block_symbol
> syms
10924 = ada_lookup_symbol_list_worker (lookup_name
,
10925 get_selected_block (0),
10928 if (syms
.size () != 1)
10930 if (err_msg
== NULL
)
10933 error (("%s"), err_msg
);
10936 return value_of_variable (syms
[0].symbol
, syms
[0].block
);
10939 /* Value of integer variable named NAME in the current environment.
10940 If no such variable is found, returns false. Otherwise, sets VALUE
10941 to the variable's value and returns true. */
10944 get_int_var_value (const char *name
, LONGEST
&value
)
10946 struct value
*var_val
= get_var_value (name
, 0);
10951 value
= value_as_long (var_val
);
10956 /* Return a range type whose base type is that of the range type named
10957 NAME in the current environment, and whose bounds are calculated
10958 from NAME according to the GNAT range encoding conventions.
10959 Extract discriminant values, if needed, from DVAL. ORIG_TYPE is the
10960 corresponding range type from debug information; fall back to using it
10961 if symbol lookup fails. If a new type must be created, allocate it
10962 like ORIG_TYPE was. The bounds information, in general, is encoded
10963 in NAME, the base type given in the named range type. */
10965 static struct type
*
10966 to_fixed_range_type (struct type
*raw_type
, struct value
*dval
)
10969 struct type
*base_type
;
10970 const char *subtype_info
;
10972 gdb_assert (raw_type
!= NULL
);
10973 gdb_assert (raw_type
->name () != NULL
);
10975 if (raw_type
->code () == TYPE_CODE_RANGE
)
10976 base_type
= TYPE_TARGET_TYPE (raw_type
);
10978 base_type
= raw_type
;
10980 name
= raw_type
->name ();
10981 subtype_info
= strstr (name
, "___XD");
10982 if (subtype_info
== NULL
)
10984 LONGEST L
= ada_discrete_type_low_bound (raw_type
);
10985 LONGEST U
= ada_discrete_type_high_bound (raw_type
);
10987 if (L
< INT_MIN
|| U
> INT_MAX
)
10990 return create_static_range_type (alloc_type_copy (raw_type
), raw_type
,
10995 int prefix_len
= subtype_info
- name
;
10998 const char *bounds_str
;
11002 bounds_str
= strchr (subtype_info
, '_');
11005 if (*subtype_info
== 'L')
11007 if (!ada_scan_number (bounds_str
, n
, &L
, &n
)
11008 && !scan_discrim_bound (bounds_str
, n
, dval
, &L
, &n
))
11010 if (bounds_str
[n
] == '_')
11012 else if (bounds_str
[n
] == '.') /* FIXME? SGI Workshop kludge. */
11018 std::string name_buf
= std::string (name
, prefix_len
) + "___L";
11019 if (!get_int_var_value (name_buf
.c_str (), L
))
11021 lim_warning (_("Unknown lower bound, using 1."));
11026 if (*subtype_info
== 'U')
11028 if (!ada_scan_number (bounds_str
, n
, &U
, &n
)
11029 && !scan_discrim_bound (bounds_str
, n
, dval
, &U
, &n
))
11034 std::string name_buf
= std::string (name
, prefix_len
) + "___U";
11035 if (!get_int_var_value (name_buf
.c_str (), U
))
11037 lim_warning (_("Unknown upper bound, using %ld."), (long) L
);
11042 type
= create_static_range_type (alloc_type_copy (raw_type
),
11044 /* create_static_range_type alters the resulting type's length
11045 to match the size of the base_type, which is not what we want.
11046 Set it back to the original range type's length. */
11047 TYPE_LENGTH (type
) = TYPE_LENGTH (raw_type
);
11048 type
->set_name (name
);
11053 /* True iff NAME is the name of a range type. */
11056 ada_is_range_type_name (const char *name
)
11058 return (name
!= NULL
&& strstr (name
, "___XD"));
11062 /* Modular types */
11064 /* True iff TYPE is an Ada modular type. */
11067 ada_is_modular_type (struct type
*type
)
11069 struct type
*subranged_type
= get_base_type (type
);
11071 return (subranged_type
!= NULL
&& type
->code () == TYPE_CODE_RANGE
11072 && subranged_type
->code () == TYPE_CODE_INT
11073 && subranged_type
->is_unsigned ());
11076 /* Assuming ada_is_modular_type (TYPE), the modulus of TYPE. */
11079 ada_modulus (struct type
*type
)
11081 const dynamic_prop
&high
= type
->bounds ()->high
;
11083 if (high
.kind () == PROP_CONST
)
11084 return (ULONGEST
) high
.const_val () + 1;
11086 /* If TYPE is unresolved, the high bound might be a location list. Return
11087 0, for lack of a better value to return. */
11092 /* Ada exception catchpoint support:
11093 ---------------------------------
11095 We support 3 kinds of exception catchpoints:
11096 . catchpoints on Ada exceptions
11097 . catchpoints on unhandled Ada exceptions
11098 . catchpoints on failed assertions
11100 Exceptions raised during failed assertions, or unhandled exceptions
11101 could perfectly be caught with the general catchpoint on Ada exceptions.
11102 However, we can easily differentiate these two special cases, and having
11103 the option to distinguish these two cases from the rest can be useful
11104 to zero-in on certain situations.
11106 Exception catchpoints are a specialized form of breakpoint,
11107 since they rely on inserting breakpoints inside known routines
11108 of the GNAT runtime. The implementation therefore uses a standard
11109 breakpoint structure of the BP_BREAKPOINT type, but with its own set
11112 Support in the runtime for exception catchpoints have been changed
11113 a few times already, and these changes affect the implementation
11114 of these catchpoints. In order to be able to support several
11115 variants of the runtime, we use a sniffer that will determine
11116 the runtime variant used by the program being debugged. */
11118 /* Ada's standard exceptions.
11120 The Ada 83 standard also defined Numeric_Error. But there so many
11121 situations where it was unclear from the Ada 83 Reference Manual
11122 (RM) whether Constraint_Error or Numeric_Error should be raised,
11123 that the ARG (Ada Rapporteur Group) eventually issued a Binding
11124 Interpretation saying that anytime the RM says that Numeric_Error
11125 should be raised, the implementation may raise Constraint_Error.
11126 Ada 95 went one step further and pretty much removed Numeric_Error
11127 from the list of standard exceptions (it made it a renaming of
11128 Constraint_Error, to help preserve compatibility when compiling
11129 an Ada83 compiler). As such, we do not include Numeric_Error from
11130 this list of standard exceptions. */
11132 static const char * const standard_exc
[] = {
11133 "constraint_error",
11139 typedef CORE_ADDR (ada_unhandled_exception_name_addr_ftype
) (void);
11141 /* A structure that describes how to support exception catchpoints
11142 for a given executable. */
11144 struct exception_support_info
11146 /* The name of the symbol to break on in order to insert
11147 a catchpoint on exceptions. */
11148 const char *catch_exception_sym
;
11150 /* The name of the symbol to break on in order to insert
11151 a catchpoint on unhandled exceptions. */
11152 const char *catch_exception_unhandled_sym
;
11154 /* The name of the symbol to break on in order to insert
11155 a catchpoint on failed assertions. */
11156 const char *catch_assert_sym
;
11158 /* The name of the symbol to break on in order to insert
11159 a catchpoint on exception handling. */
11160 const char *catch_handlers_sym
;
11162 /* Assuming that the inferior just triggered an unhandled exception
11163 catchpoint, this function is responsible for returning the address
11164 in inferior memory where the name of that exception is stored.
11165 Return zero if the address could not be computed. */
11166 ada_unhandled_exception_name_addr_ftype
*unhandled_exception_name_addr
;
11169 static CORE_ADDR
ada_unhandled_exception_name_addr (void);
11170 static CORE_ADDR
ada_unhandled_exception_name_addr_from_raise (void);
11172 /* The following exception support info structure describes how to
11173 implement exception catchpoints with the latest version of the
11174 Ada runtime (as of 2019-08-??). */
11176 static const struct exception_support_info default_exception_support_info
=
11178 "__gnat_debug_raise_exception", /* catch_exception_sym */
11179 "__gnat_unhandled_exception", /* catch_exception_unhandled_sym */
11180 "__gnat_debug_raise_assert_failure", /* catch_assert_sym */
11181 "__gnat_begin_handler_v1", /* catch_handlers_sym */
11182 ada_unhandled_exception_name_addr
11185 /* The following exception support info structure describes how to
11186 implement exception catchpoints with an earlier version of the
11187 Ada runtime (as of 2007-03-06) using v0 of the EH ABI. */
11189 static const struct exception_support_info exception_support_info_v0
=
11191 "__gnat_debug_raise_exception", /* catch_exception_sym */
11192 "__gnat_unhandled_exception", /* catch_exception_unhandled_sym */
11193 "__gnat_debug_raise_assert_failure", /* catch_assert_sym */
11194 "__gnat_begin_handler", /* catch_handlers_sym */
11195 ada_unhandled_exception_name_addr
11198 /* The following exception support info structure describes how to
11199 implement exception catchpoints with a slightly older version
11200 of the Ada runtime. */
11202 static const struct exception_support_info exception_support_info_fallback
=
11204 "__gnat_raise_nodefer_with_msg", /* catch_exception_sym */
11205 "__gnat_unhandled_exception", /* catch_exception_unhandled_sym */
11206 "system__assertions__raise_assert_failure", /* catch_assert_sym */
11207 "__gnat_begin_handler", /* catch_handlers_sym */
11208 ada_unhandled_exception_name_addr_from_raise
11211 /* Return nonzero if we can detect the exception support routines
11212 described in EINFO.
11214 This function errors out if an abnormal situation is detected
11215 (for instance, if we find the exception support routines, but
11216 that support is found to be incomplete). */
11219 ada_has_this_exception_support (const struct exception_support_info
*einfo
)
11221 struct symbol
*sym
;
11223 /* The symbol we're looking up is provided by a unit in the GNAT runtime
11224 that should be compiled with debugging information. As a result, we
11225 expect to find that symbol in the symtabs. */
11227 sym
= standard_lookup (einfo
->catch_exception_sym
, NULL
, VAR_DOMAIN
);
11230 /* Perhaps we did not find our symbol because the Ada runtime was
11231 compiled without debugging info, or simply stripped of it.
11232 It happens on some GNU/Linux distributions for instance, where
11233 users have to install a separate debug package in order to get
11234 the runtime's debugging info. In that situation, let the user
11235 know why we cannot insert an Ada exception catchpoint.
11237 Note: Just for the purpose of inserting our Ada exception
11238 catchpoint, we could rely purely on the associated minimal symbol.
11239 But we would be operating in degraded mode anyway, since we are
11240 still lacking the debugging info needed later on to extract
11241 the name of the exception being raised (this name is printed in
11242 the catchpoint message, and is also used when trying to catch
11243 a specific exception). We do not handle this case for now. */
11244 struct bound_minimal_symbol msym
11245 = lookup_minimal_symbol (einfo
->catch_exception_sym
, NULL
, NULL
);
11247 if (msym
.minsym
&& MSYMBOL_TYPE (msym
.minsym
) != mst_solib_trampoline
)
11248 error (_("Your Ada runtime appears to be missing some debugging "
11249 "information.\nCannot insert Ada exception catchpoint "
11250 "in this configuration."));
11255 /* Make sure that the symbol we found corresponds to a function. */
11257 if (SYMBOL_CLASS (sym
) != LOC_BLOCK
)
11259 error (_("Symbol \"%s\" is not a function (class = %d)"),
11260 sym
->linkage_name (), SYMBOL_CLASS (sym
));
11264 sym
= standard_lookup (einfo
->catch_handlers_sym
, NULL
, VAR_DOMAIN
);
11267 struct bound_minimal_symbol msym
11268 = lookup_minimal_symbol (einfo
->catch_handlers_sym
, NULL
, NULL
);
11270 if (msym
.minsym
&& MSYMBOL_TYPE (msym
.minsym
) != mst_solib_trampoline
)
11271 error (_("Your Ada runtime appears to be missing some debugging "
11272 "information.\nCannot insert Ada exception catchpoint "
11273 "in this configuration."));
11278 /* Make sure that the symbol we found corresponds to a function. */
11280 if (SYMBOL_CLASS (sym
) != LOC_BLOCK
)
11282 error (_("Symbol \"%s\" is not a function (class = %d)"),
11283 sym
->linkage_name (), SYMBOL_CLASS (sym
));
11290 /* Inspect the Ada runtime and determine which exception info structure
11291 should be used to provide support for exception catchpoints.
11293 This function will always set the per-inferior exception_info,
11294 or raise an error. */
11297 ada_exception_support_info_sniffer (void)
11299 struct ada_inferior_data
*data
= get_ada_inferior_data (current_inferior ());
11301 /* If the exception info is already known, then no need to recompute it. */
11302 if (data
->exception_info
!= NULL
)
11305 /* Check the latest (default) exception support info. */
11306 if (ada_has_this_exception_support (&default_exception_support_info
))
11308 data
->exception_info
= &default_exception_support_info
;
11312 /* Try the v0 exception suport info. */
11313 if (ada_has_this_exception_support (&exception_support_info_v0
))
11315 data
->exception_info
= &exception_support_info_v0
;
11319 /* Try our fallback exception suport info. */
11320 if (ada_has_this_exception_support (&exception_support_info_fallback
))
11322 data
->exception_info
= &exception_support_info_fallback
;
11326 /* Sometimes, it is normal for us to not be able to find the routine
11327 we are looking for. This happens when the program is linked with
11328 the shared version of the GNAT runtime, and the program has not been
11329 started yet. Inform the user of these two possible causes if
11332 if (ada_update_initial_language (language_unknown
) != language_ada
)
11333 error (_("Unable to insert catchpoint. Is this an Ada main program?"));
11335 /* If the symbol does not exist, then check that the program is
11336 already started, to make sure that shared libraries have been
11337 loaded. If it is not started, this may mean that the symbol is
11338 in a shared library. */
11340 if (inferior_ptid
.pid () == 0)
11341 error (_("Unable to insert catchpoint. Try to start the program first."));
11343 /* At this point, we know that we are debugging an Ada program and
11344 that the inferior has been started, but we still are not able to
11345 find the run-time symbols. That can mean that we are in
11346 configurable run time mode, or that a-except as been optimized
11347 out by the linker... In any case, at this point it is not worth
11348 supporting this feature. */
11350 error (_("Cannot insert Ada exception catchpoints in this configuration."));
11353 /* True iff FRAME is very likely to be that of a function that is
11354 part of the runtime system. This is all very heuristic, but is
11355 intended to be used as advice as to what frames are uninteresting
11359 is_known_support_routine (struct frame_info
*frame
)
11361 enum language func_lang
;
11363 const char *fullname
;
11365 /* If this code does not have any debugging information (no symtab),
11366 This cannot be any user code. */
11368 symtab_and_line sal
= find_frame_sal (frame
);
11369 if (sal
.symtab
== NULL
)
11372 /* If there is a symtab, but the associated source file cannot be
11373 located, then assume this is not user code: Selecting a frame
11374 for which we cannot display the code would not be very helpful
11375 for the user. This should also take care of case such as VxWorks
11376 where the kernel has some debugging info provided for a few units. */
11378 fullname
= symtab_to_fullname (sal
.symtab
);
11379 if (access (fullname
, R_OK
) != 0)
11382 /* Check the unit filename against the Ada runtime file naming.
11383 We also check the name of the objfile against the name of some
11384 known system libraries that sometimes come with debugging info
11387 for (i
= 0; known_runtime_file_name_patterns
[i
] != NULL
; i
+= 1)
11389 re_comp (known_runtime_file_name_patterns
[i
]);
11390 if (re_exec (lbasename (sal
.symtab
->filename
)))
11392 if (SYMTAB_OBJFILE (sal
.symtab
) != NULL
11393 && re_exec (objfile_name (SYMTAB_OBJFILE (sal
.symtab
))))
11397 /* Check whether the function is a GNAT-generated entity. */
11399 gdb::unique_xmalloc_ptr
<char> func_name
11400 = find_frame_funname (frame
, &func_lang
, NULL
);
11401 if (func_name
== NULL
)
11404 for (i
= 0; known_auxiliary_function_name_patterns
[i
] != NULL
; i
+= 1)
11406 re_comp (known_auxiliary_function_name_patterns
[i
]);
11407 if (re_exec (func_name
.get ()))
11414 /* Find the first frame that contains debugging information and that is not
11415 part of the Ada run-time, starting from FI and moving upward. */
11418 ada_find_printable_frame (struct frame_info
*fi
)
11420 for (; fi
!= NULL
; fi
= get_prev_frame (fi
))
11422 if (!is_known_support_routine (fi
))
11431 /* Assuming that the inferior just triggered an unhandled exception
11432 catchpoint, return the address in inferior memory where the name
11433 of the exception is stored.
11435 Return zero if the address could not be computed. */
11438 ada_unhandled_exception_name_addr (void)
11440 return parse_and_eval_address ("e.full_name");
11443 /* Same as ada_unhandled_exception_name_addr, except that this function
11444 should be used when the inferior uses an older version of the runtime,
11445 where the exception name needs to be extracted from a specific frame
11446 several frames up in the callstack. */
11449 ada_unhandled_exception_name_addr_from_raise (void)
11452 struct frame_info
*fi
;
11453 struct ada_inferior_data
*data
= get_ada_inferior_data (current_inferior ());
11455 /* To determine the name of this exception, we need to select
11456 the frame corresponding to RAISE_SYM_NAME. This frame is
11457 at least 3 levels up, so we simply skip the first 3 frames
11458 without checking the name of their associated function. */
11459 fi
= get_current_frame ();
11460 for (frame_level
= 0; frame_level
< 3; frame_level
+= 1)
11462 fi
= get_prev_frame (fi
);
11466 enum language func_lang
;
11468 gdb::unique_xmalloc_ptr
<char> func_name
11469 = find_frame_funname (fi
, &func_lang
, NULL
);
11470 if (func_name
!= NULL
)
11472 if (strcmp (func_name
.get (),
11473 data
->exception_info
->catch_exception_sym
) == 0)
11474 break; /* We found the frame we were looking for... */
11476 fi
= get_prev_frame (fi
);
11483 return parse_and_eval_address ("id.full_name");
11486 /* Assuming the inferior just triggered an Ada exception catchpoint
11487 (of any type), return the address in inferior memory where the name
11488 of the exception is stored, if applicable.
11490 Assumes the selected frame is the current frame.
11492 Return zero if the address could not be computed, or if not relevant. */
11495 ada_exception_name_addr_1 (enum ada_exception_catchpoint_kind ex
,
11496 struct breakpoint
*b
)
11498 struct ada_inferior_data
*data
= get_ada_inferior_data (current_inferior ());
11502 case ada_catch_exception
:
11503 return (parse_and_eval_address ("e.full_name"));
11506 case ada_catch_exception_unhandled
:
11507 return data
->exception_info
->unhandled_exception_name_addr ();
11510 case ada_catch_handlers
:
11511 return 0; /* The runtimes does not provide access to the exception
11515 case ada_catch_assert
:
11516 return 0; /* Exception name is not relevant in this case. */
11520 internal_error (__FILE__
, __LINE__
, _("unexpected catchpoint type"));
11524 return 0; /* Should never be reached. */
11527 /* Assuming the inferior is stopped at an exception catchpoint,
11528 return the message which was associated to the exception, if
11529 available. Return NULL if the message could not be retrieved.
11531 Note: The exception message can be associated to an exception
11532 either through the use of the Raise_Exception function, or
11533 more simply (Ada 2005 and later), via:
11535 raise Exception_Name with "exception message";
11539 static gdb::unique_xmalloc_ptr
<char>
11540 ada_exception_message_1 (void)
11542 struct value
*e_msg_val
;
11545 /* For runtimes that support this feature, the exception message
11546 is passed as an unbounded string argument called "message". */
11547 e_msg_val
= parse_and_eval ("message");
11548 if (e_msg_val
== NULL
)
11549 return NULL
; /* Exception message not supported. */
11551 e_msg_val
= ada_coerce_to_simple_array (e_msg_val
);
11552 gdb_assert (e_msg_val
!= NULL
);
11553 e_msg_len
= TYPE_LENGTH (value_type (e_msg_val
));
11555 /* If the message string is empty, then treat it as if there was
11556 no exception message. */
11557 if (e_msg_len
<= 0)
11560 gdb::unique_xmalloc_ptr
<char> e_msg ((char *) xmalloc (e_msg_len
+ 1));
11561 read_memory (value_address (e_msg_val
), (gdb_byte
*) e_msg
.get (),
11563 e_msg
.get ()[e_msg_len
] = '\0';
11568 /* Same as ada_exception_message_1, except that all exceptions are
11569 contained here (returning NULL instead). */
11571 static gdb::unique_xmalloc_ptr
<char>
11572 ada_exception_message (void)
11574 gdb::unique_xmalloc_ptr
<char> e_msg
;
11578 e_msg
= ada_exception_message_1 ();
11580 catch (const gdb_exception_error
&e
)
11582 e_msg
.reset (nullptr);
11588 /* Same as ada_exception_name_addr_1, except that it intercepts and contains
11589 any error that ada_exception_name_addr_1 might cause to be thrown.
11590 When an error is intercepted, a warning with the error message is printed,
11591 and zero is returned. */
11594 ada_exception_name_addr (enum ada_exception_catchpoint_kind ex
,
11595 struct breakpoint
*b
)
11597 CORE_ADDR result
= 0;
11601 result
= ada_exception_name_addr_1 (ex
, b
);
11604 catch (const gdb_exception_error
&e
)
11606 warning (_("failed to get exception name: %s"), e
.what ());
11613 static std::string ada_exception_catchpoint_cond_string
11614 (const char *excep_string
,
11615 enum ada_exception_catchpoint_kind ex
);
11617 /* Ada catchpoints.
11619 In the case of catchpoints on Ada exceptions, the catchpoint will
11620 stop the target on every exception the program throws. When a user
11621 specifies the name of a specific exception, we translate this
11622 request into a condition expression (in text form), and then parse
11623 it into an expression stored in each of the catchpoint's locations.
11624 We then use this condition to check whether the exception that was
11625 raised is the one the user is interested in. If not, then the
11626 target is resumed again. We store the name of the requested
11627 exception, in order to be able to re-set the condition expression
11628 when symbols change. */
11630 /* An instance of this type is used to represent an Ada catchpoint
11631 breakpoint location. */
11633 class ada_catchpoint_location
: public bp_location
11636 ada_catchpoint_location (breakpoint
*owner
)
11637 : bp_location (owner
, bp_loc_software_breakpoint
)
11640 /* The condition that checks whether the exception that was raised
11641 is the specific exception the user specified on catchpoint
11643 expression_up excep_cond_expr
;
11646 /* An instance of this type is used to represent an Ada catchpoint. */
11648 struct ada_catchpoint
: public breakpoint
11650 explicit ada_catchpoint (enum ada_exception_catchpoint_kind kind
)
11655 /* The name of the specific exception the user specified. */
11656 std::string excep_string
;
11658 /* What kind of catchpoint this is. */
11659 enum ada_exception_catchpoint_kind m_kind
;
11662 /* Parse the exception condition string in the context of each of the
11663 catchpoint's locations, and store them for later evaluation. */
11666 create_excep_cond_exprs (struct ada_catchpoint
*c
,
11667 enum ada_exception_catchpoint_kind ex
)
11669 /* Nothing to do if there's no specific exception to catch. */
11670 if (c
->excep_string
.empty ())
11673 /* Same if there are no locations... */
11674 if (c
->loc
== NULL
)
11677 /* Compute the condition expression in text form, from the specific
11678 expection we want to catch. */
11679 std::string cond_string
11680 = ada_exception_catchpoint_cond_string (c
->excep_string
.c_str (), ex
);
11682 /* Iterate over all the catchpoint's locations, and parse an
11683 expression for each. */
11684 for (bp_location
*bl
: c
->locations ())
11686 struct ada_catchpoint_location
*ada_loc
11687 = (struct ada_catchpoint_location
*) bl
;
11690 if (!bl
->shlib_disabled
)
11694 s
= cond_string
.c_str ();
11697 exp
= parse_exp_1 (&s
, bl
->address
,
11698 block_for_pc (bl
->address
),
11701 catch (const gdb_exception_error
&e
)
11703 warning (_("failed to reevaluate internal exception condition "
11704 "for catchpoint %d: %s"),
11705 c
->number
, e
.what ());
11709 ada_loc
->excep_cond_expr
= std::move (exp
);
11713 /* Implement the ALLOCATE_LOCATION method in the breakpoint_ops
11714 structure for all exception catchpoint kinds. */
11716 static struct bp_location
*
11717 allocate_location_exception (struct breakpoint
*self
)
11719 return new ada_catchpoint_location (self
);
11722 /* Implement the RE_SET method in the breakpoint_ops structure for all
11723 exception catchpoint kinds. */
11726 re_set_exception (struct breakpoint
*b
)
11728 struct ada_catchpoint
*c
= (struct ada_catchpoint
*) b
;
11730 /* Call the base class's method. This updates the catchpoint's
11732 bkpt_breakpoint_ops
.re_set (b
);
11734 /* Reparse the exception conditional expressions. One for each
11736 create_excep_cond_exprs (c
, c
->m_kind
);
11739 /* Returns true if we should stop for this breakpoint hit. If the
11740 user specified a specific exception, we only want to cause a stop
11741 if the program thrown that exception. */
11744 should_stop_exception (const struct bp_location
*bl
)
11746 struct ada_catchpoint
*c
= (struct ada_catchpoint
*) bl
->owner
;
11747 const struct ada_catchpoint_location
*ada_loc
11748 = (const struct ada_catchpoint_location
*) bl
;
11751 struct internalvar
*var
= lookup_internalvar ("_ada_exception");
11752 if (c
->m_kind
== ada_catch_assert
)
11753 clear_internalvar (var
);
11760 if (c
->m_kind
== ada_catch_handlers
)
11761 expr
= ("GNAT_GCC_exception_Access(gcc_exception)"
11762 ".all.occurrence.id");
11766 struct value
*exc
= parse_and_eval (expr
);
11767 set_internalvar (var
, exc
);
11769 catch (const gdb_exception_error
&ex
)
11771 clear_internalvar (var
);
11775 /* With no specific exception, should always stop. */
11776 if (c
->excep_string
.empty ())
11779 if (ada_loc
->excep_cond_expr
== NULL
)
11781 /* We will have a NULL expression if back when we were creating
11782 the expressions, this location's had failed to parse. */
11789 struct value
*mark
;
11791 mark
= value_mark ();
11792 stop
= value_true (evaluate_expression (ada_loc
->excep_cond_expr
.get ()));
11793 value_free_to_mark (mark
);
11795 catch (const gdb_exception
&ex
)
11797 exception_fprintf (gdb_stderr
, ex
,
11798 _("Error in testing exception condition:\n"));
11804 /* Implement the CHECK_STATUS method in the breakpoint_ops structure
11805 for all exception catchpoint kinds. */
11808 check_status_exception (bpstat
*bs
)
11810 bs
->stop
= should_stop_exception (bs
->bp_location_at
.get ());
11813 /* Implement the PRINT_IT method in the breakpoint_ops structure
11814 for all exception catchpoint kinds. */
11816 static enum print_stop_action
11817 print_it_exception (bpstat
*bs
)
11819 struct ui_out
*uiout
= current_uiout
;
11820 struct breakpoint
*b
= bs
->breakpoint_at
;
11822 annotate_catchpoint (b
->number
);
11824 if (uiout
->is_mi_like_p ())
11826 uiout
->field_string ("reason",
11827 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT
));
11828 uiout
->field_string ("disp", bpdisp_text (b
->disposition
));
11831 uiout
->text (b
->disposition
== disp_del
11832 ? "\nTemporary catchpoint " : "\nCatchpoint ");
11833 uiout
->field_signed ("bkptno", b
->number
);
11834 uiout
->text (", ");
11836 /* ada_exception_name_addr relies on the selected frame being the
11837 current frame. Need to do this here because this function may be
11838 called more than once when printing a stop, and below, we'll
11839 select the first frame past the Ada run-time (see
11840 ada_find_printable_frame). */
11841 select_frame (get_current_frame ());
11843 struct ada_catchpoint
*c
= (struct ada_catchpoint
*) b
;
11846 case ada_catch_exception
:
11847 case ada_catch_exception_unhandled
:
11848 case ada_catch_handlers
:
11850 const CORE_ADDR addr
= ada_exception_name_addr (c
->m_kind
, b
);
11851 char exception_name
[256];
11855 read_memory (addr
, (gdb_byte
*) exception_name
,
11856 sizeof (exception_name
) - 1);
11857 exception_name
[sizeof (exception_name
) - 1] = '\0';
11861 /* For some reason, we were unable to read the exception
11862 name. This could happen if the Runtime was compiled
11863 without debugging info, for instance. In that case,
11864 just replace the exception name by the generic string
11865 "exception" - it will read as "an exception" in the
11866 notification we are about to print. */
11867 memcpy (exception_name
, "exception", sizeof ("exception"));
11869 /* In the case of unhandled exception breakpoints, we print
11870 the exception name as "unhandled EXCEPTION_NAME", to make
11871 it clearer to the user which kind of catchpoint just got
11872 hit. We used ui_out_text to make sure that this extra
11873 info does not pollute the exception name in the MI case. */
11874 if (c
->m_kind
== ada_catch_exception_unhandled
)
11875 uiout
->text ("unhandled ");
11876 uiout
->field_string ("exception-name", exception_name
);
11879 case ada_catch_assert
:
11880 /* In this case, the name of the exception is not really
11881 important. Just print "failed assertion" to make it clearer
11882 that his program just hit an assertion-failure catchpoint.
11883 We used ui_out_text because this info does not belong in
11885 uiout
->text ("failed assertion");
11889 gdb::unique_xmalloc_ptr
<char> exception_message
= ada_exception_message ();
11890 if (exception_message
!= NULL
)
11892 uiout
->text (" (");
11893 uiout
->field_string ("exception-message", exception_message
.get ());
11897 uiout
->text (" at ");
11898 ada_find_printable_frame (get_current_frame ());
11900 return PRINT_SRC_AND_LOC
;
11903 /* Implement the PRINT_ONE method in the breakpoint_ops structure
11904 for all exception catchpoint kinds. */
11907 print_one_exception (struct breakpoint
*b
, struct bp_location
**last_loc
)
11909 struct ui_out
*uiout
= current_uiout
;
11910 struct ada_catchpoint
*c
= (struct ada_catchpoint
*) b
;
11911 struct value_print_options opts
;
11913 get_user_print_options (&opts
);
11915 if (opts
.addressprint
)
11916 uiout
->field_skip ("addr");
11918 annotate_field (5);
11921 case ada_catch_exception
:
11922 if (!c
->excep_string
.empty ())
11924 std::string msg
= string_printf (_("`%s' Ada exception"),
11925 c
->excep_string
.c_str ());
11927 uiout
->field_string ("what", msg
);
11930 uiout
->field_string ("what", "all Ada exceptions");
11934 case ada_catch_exception_unhandled
:
11935 uiout
->field_string ("what", "unhandled Ada exceptions");
11938 case ada_catch_handlers
:
11939 if (!c
->excep_string
.empty ())
11941 uiout
->field_fmt ("what",
11942 _("`%s' Ada exception handlers"),
11943 c
->excep_string
.c_str ());
11946 uiout
->field_string ("what", "all Ada exceptions handlers");
11949 case ada_catch_assert
:
11950 uiout
->field_string ("what", "failed Ada assertions");
11954 internal_error (__FILE__
, __LINE__
, _("unexpected catchpoint type"));
11959 /* Implement the PRINT_MENTION method in the breakpoint_ops structure
11960 for all exception catchpoint kinds. */
11963 print_mention_exception (struct breakpoint
*b
)
11965 struct ada_catchpoint
*c
= (struct ada_catchpoint
*) b
;
11966 struct ui_out
*uiout
= current_uiout
;
11968 uiout
->text (b
->disposition
== disp_del
? _("Temporary catchpoint ")
11969 : _("Catchpoint "));
11970 uiout
->field_signed ("bkptno", b
->number
);
11971 uiout
->text (": ");
11975 case ada_catch_exception
:
11976 if (!c
->excep_string
.empty ())
11978 std::string info
= string_printf (_("`%s' Ada exception"),
11979 c
->excep_string
.c_str ());
11980 uiout
->text (info
);
11983 uiout
->text (_("all Ada exceptions"));
11986 case ada_catch_exception_unhandled
:
11987 uiout
->text (_("unhandled Ada exceptions"));
11990 case ada_catch_handlers
:
11991 if (!c
->excep_string
.empty ())
11994 = string_printf (_("`%s' Ada exception handlers"),
11995 c
->excep_string
.c_str ());
11996 uiout
->text (info
);
11999 uiout
->text (_("all Ada exceptions handlers"));
12002 case ada_catch_assert
:
12003 uiout
->text (_("failed Ada assertions"));
12007 internal_error (__FILE__
, __LINE__
, _("unexpected catchpoint type"));
12012 /* Implement the PRINT_RECREATE method in the breakpoint_ops structure
12013 for all exception catchpoint kinds. */
12016 print_recreate_exception (struct breakpoint
*b
, struct ui_file
*fp
)
12018 struct ada_catchpoint
*c
= (struct ada_catchpoint
*) b
;
12022 case ada_catch_exception
:
12023 fprintf_filtered (fp
, "catch exception");
12024 if (!c
->excep_string
.empty ())
12025 fprintf_filtered (fp
, " %s", c
->excep_string
.c_str ());
12028 case ada_catch_exception_unhandled
:
12029 fprintf_filtered (fp
, "catch exception unhandled");
12032 case ada_catch_handlers
:
12033 fprintf_filtered (fp
, "catch handlers");
12036 case ada_catch_assert
:
12037 fprintf_filtered (fp
, "catch assert");
12041 internal_error (__FILE__
, __LINE__
, _("unexpected catchpoint type"));
12043 print_recreate_thread (b
, fp
);
12046 /* Virtual tables for various breakpoint types. */
12047 static struct breakpoint_ops catch_exception_breakpoint_ops
;
12048 static struct breakpoint_ops catch_exception_unhandled_breakpoint_ops
;
12049 static struct breakpoint_ops catch_assert_breakpoint_ops
;
12050 static struct breakpoint_ops catch_handlers_breakpoint_ops
;
12052 /* See ada-lang.h. */
12055 is_ada_exception_catchpoint (breakpoint
*bp
)
12057 return (bp
->ops
== &catch_exception_breakpoint_ops
12058 || bp
->ops
== &catch_exception_unhandled_breakpoint_ops
12059 || bp
->ops
== &catch_assert_breakpoint_ops
12060 || bp
->ops
== &catch_handlers_breakpoint_ops
);
12063 /* Split the arguments specified in a "catch exception" command.
12064 Set EX to the appropriate catchpoint type.
12065 Set EXCEP_STRING to the name of the specific exception if
12066 specified by the user.
12067 IS_CATCH_HANDLERS_CMD: True if the arguments are for a
12068 "catch handlers" command. False otherwise.
12069 If a condition is found at the end of the arguments, the condition
12070 expression is stored in COND_STRING (memory must be deallocated
12071 after use). Otherwise COND_STRING is set to NULL. */
12074 catch_ada_exception_command_split (const char *args
,
12075 bool is_catch_handlers_cmd
,
12076 enum ada_exception_catchpoint_kind
*ex
,
12077 std::string
*excep_string
,
12078 std::string
*cond_string
)
12080 std::string exception_name
;
12082 exception_name
= extract_arg (&args
);
12083 if (exception_name
== "if")
12085 /* This is not an exception name; this is the start of a condition
12086 expression for a catchpoint on all exceptions. So, "un-get"
12087 this token, and set exception_name to NULL. */
12088 exception_name
.clear ();
12092 /* Check to see if we have a condition. */
12094 args
= skip_spaces (args
);
12095 if (startswith (args
, "if")
12096 && (isspace (args
[2]) || args
[2] == '\0'))
12099 args
= skip_spaces (args
);
12101 if (args
[0] == '\0')
12102 error (_("Condition missing after `if' keyword"));
12103 *cond_string
= args
;
12105 args
+= strlen (args
);
12108 /* Check that we do not have any more arguments. Anything else
12111 if (args
[0] != '\0')
12112 error (_("Junk at end of expression"));
12114 if (is_catch_handlers_cmd
)
12116 /* Catch handling of exceptions. */
12117 *ex
= ada_catch_handlers
;
12118 *excep_string
= exception_name
;
12120 else if (exception_name
.empty ())
12122 /* Catch all exceptions. */
12123 *ex
= ada_catch_exception
;
12124 excep_string
->clear ();
12126 else if (exception_name
== "unhandled")
12128 /* Catch unhandled exceptions. */
12129 *ex
= ada_catch_exception_unhandled
;
12130 excep_string
->clear ();
12134 /* Catch a specific exception. */
12135 *ex
= ada_catch_exception
;
12136 *excep_string
= exception_name
;
12140 /* Return the name of the symbol on which we should break in order to
12141 implement a catchpoint of the EX kind. */
12143 static const char *
12144 ada_exception_sym_name (enum ada_exception_catchpoint_kind ex
)
12146 struct ada_inferior_data
*data
= get_ada_inferior_data (current_inferior ());
12148 gdb_assert (data
->exception_info
!= NULL
);
12152 case ada_catch_exception
:
12153 return (data
->exception_info
->catch_exception_sym
);
12155 case ada_catch_exception_unhandled
:
12156 return (data
->exception_info
->catch_exception_unhandled_sym
);
12158 case ada_catch_assert
:
12159 return (data
->exception_info
->catch_assert_sym
);
12161 case ada_catch_handlers
:
12162 return (data
->exception_info
->catch_handlers_sym
);
12165 internal_error (__FILE__
, __LINE__
,
12166 _("unexpected catchpoint kind (%d)"), ex
);
12170 /* Return the breakpoint ops "virtual table" used for catchpoints
12173 static const struct breakpoint_ops
*
12174 ada_exception_breakpoint_ops (enum ada_exception_catchpoint_kind ex
)
12178 case ada_catch_exception
:
12179 return (&catch_exception_breakpoint_ops
);
12181 case ada_catch_exception_unhandled
:
12182 return (&catch_exception_unhandled_breakpoint_ops
);
12184 case ada_catch_assert
:
12185 return (&catch_assert_breakpoint_ops
);
12187 case ada_catch_handlers
:
12188 return (&catch_handlers_breakpoint_ops
);
12191 internal_error (__FILE__
, __LINE__
,
12192 _("unexpected catchpoint kind (%d)"), ex
);
12196 /* Return the condition that will be used to match the current exception
12197 being raised with the exception that the user wants to catch. This
12198 assumes that this condition is used when the inferior just triggered
12199 an exception catchpoint.
12200 EX: the type of catchpoints used for catching Ada exceptions. */
12203 ada_exception_catchpoint_cond_string (const char *excep_string
,
12204 enum ada_exception_catchpoint_kind ex
)
12207 bool is_standard_exc
= false;
12208 std::string result
;
12210 if (ex
== ada_catch_handlers
)
12212 /* For exception handlers catchpoints, the condition string does
12213 not use the same parameter as for the other exceptions. */
12214 result
= ("long_integer (GNAT_GCC_exception_Access"
12215 "(gcc_exception).all.occurrence.id)");
12218 result
= "long_integer (e)";
12220 /* The standard exceptions are a special case. They are defined in
12221 runtime units that have been compiled without debugging info; if
12222 EXCEP_STRING is the not-fully-qualified name of a standard
12223 exception (e.g. "constraint_error") then, during the evaluation
12224 of the condition expression, the symbol lookup on this name would
12225 *not* return this standard exception. The catchpoint condition
12226 may then be set only on user-defined exceptions which have the
12227 same not-fully-qualified name (e.g. my_package.constraint_error).
12229 To avoid this unexcepted behavior, these standard exceptions are
12230 systematically prefixed by "standard". This means that "catch
12231 exception constraint_error" is rewritten into "catch exception
12232 standard.constraint_error".
12234 If an exception named constraint_error is defined in another package of
12235 the inferior program, then the only way to specify this exception as a
12236 breakpoint condition is to use its fully-qualified named:
12237 e.g. my_package.constraint_error. */
12239 for (i
= 0; i
< sizeof (standard_exc
) / sizeof (char *); i
++)
12241 if (strcmp (standard_exc
[i
], excep_string
) == 0)
12243 is_standard_exc
= true;
12250 if (is_standard_exc
)
12251 string_appendf (result
, "long_integer (&standard.%s)", excep_string
);
12253 string_appendf (result
, "long_integer (&%s)", excep_string
);
12258 /* Return the symtab_and_line that should be used to insert an exception
12259 catchpoint of the TYPE kind.
12261 ADDR_STRING returns the name of the function where the real
12262 breakpoint that implements the catchpoints is set, depending on the
12263 type of catchpoint we need to create. */
12265 static struct symtab_and_line
12266 ada_exception_sal (enum ada_exception_catchpoint_kind ex
,
12267 std::string
*addr_string
, const struct breakpoint_ops
**ops
)
12269 const char *sym_name
;
12270 struct symbol
*sym
;
12272 /* First, find out which exception support info to use. */
12273 ada_exception_support_info_sniffer ();
12275 /* Then lookup the function on which we will break in order to catch
12276 the Ada exceptions requested by the user. */
12277 sym_name
= ada_exception_sym_name (ex
);
12278 sym
= standard_lookup (sym_name
, NULL
, VAR_DOMAIN
);
12281 error (_("Catchpoint symbol not found: %s"), sym_name
);
12283 if (SYMBOL_CLASS (sym
) != LOC_BLOCK
)
12284 error (_("Unable to insert catchpoint. %s is not a function."), sym_name
);
12286 /* Set ADDR_STRING. */
12287 *addr_string
= sym_name
;
12290 *ops
= ada_exception_breakpoint_ops (ex
);
12292 return find_function_start_sal (sym
, 1);
12295 /* Create an Ada exception catchpoint.
12297 EX_KIND is the kind of exception catchpoint to be created.
12299 If EXCEPT_STRING is empty, this catchpoint is expected to trigger
12300 for all exceptions. Otherwise, EXCEPT_STRING indicates the name
12301 of the exception to which this catchpoint applies.
12303 COND_STRING, if not empty, is the catchpoint condition.
12305 TEMPFLAG, if nonzero, means that the underlying breakpoint
12306 should be temporary.
12308 FROM_TTY is the usual argument passed to all commands implementations. */
12311 create_ada_exception_catchpoint (struct gdbarch
*gdbarch
,
12312 enum ada_exception_catchpoint_kind ex_kind
,
12313 const std::string
&excep_string
,
12314 const std::string
&cond_string
,
12319 std::string addr_string
;
12320 const struct breakpoint_ops
*ops
= NULL
;
12321 struct symtab_and_line sal
= ada_exception_sal (ex_kind
, &addr_string
, &ops
);
12323 std::unique_ptr
<ada_catchpoint
> c (new ada_catchpoint (ex_kind
));
12324 init_ada_exception_breakpoint (c
.get (), gdbarch
, sal
, addr_string
.c_str (),
12325 ops
, tempflag
, disabled
, from_tty
);
12326 c
->excep_string
= excep_string
;
12327 create_excep_cond_exprs (c
.get (), ex_kind
);
12328 if (!cond_string
.empty ())
12329 set_breakpoint_condition (c
.get (), cond_string
.c_str (), from_tty
, false);
12330 install_breakpoint (0, std::move (c
), 1);
12333 /* Implement the "catch exception" command. */
12336 catch_ada_exception_command (const char *arg_entry
, int from_tty
,
12337 struct cmd_list_element
*command
)
12339 const char *arg
= arg_entry
;
12340 struct gdbarch
*gdbarch
= get_current_arch ();
12342 enum ada_exception_catchpoint_kind ex_kind
;
12343 std::string excep_string
;
12344 std::string cond_string
;
12346 tempflag
= command
->context () == CATCH_TEMPORARY
;
12350 catch_ada_exception_command_split (arg
, false, &ex_kind
, &excep_string
,
12352 create_ada_exception_catchpoint (gdbarch
, ex_kind
,
12353 excep_string
, cond_string
,
12354 tempflag
, 1 /* enabled */,
12358 /* Implement the "catch handlers" command. */
12361 catch_ada_handlers_command (const char *arg_entry
, int from_tty
,
12362 struct cmd_list_element
*command
)
12364 const char *arg
= arg_entry
;
12365 struct gdbarch
*gdbarch
= get_current_arch ();
12367 enum ada_exception_catchpoint_kind ex_kind
;
12368 std::string excep_string
;
12369 std::string cond_string
;
12371 tempflag
= command
->context () == CATCH_TEMPORARY
;
12375 catch_ada_exception_command_split (arg
, true, &ex_kind
, &excep_string
,
12377 create_ada_exception_catchpoint (gdbarch
, ex_kind
,
12378 excep_string
, cond_string
,
12379 tempflag
, 1 /* enabled */,
12383 /* Completion function for the Ada "catch" commands. */
12386 catch_ada_completer (struct cmd_list_element
*cmd
, completion_tracker
&tracker
,
12387 const char *text
, const char *word
)
12389 std::vector
<ada_exc_info
> exceptions
= ada_exceptions_list (NULL
);
12391 for (const ada_exc_info
&info
: exceptions
)
12393 if (startswith (info
.name
, word
))
12394 tracker
.add_completion (make_unique_xstrdup (info
.name
));
12398 /* Split the arguments specified in a "catch assert" command.
12400 ARGS contains the command's arguments (or the empty string if
12401 no arguments were passed).
12403 If ARGS contains a condition, set COND_STRING to that condition
12404 (the memory needs to be deallocated after use). */
12407 catch_ada_assert_command_split (const char *args
, std::string
&cond_string
)
12409 args
= skip_spaces (args
);
12411 /* Check whether a condition was provided. */
12412 if (startswith (args
, "if")
12413 && (isspace (args
[2]) || args
[2] == '\0'))
12416 args
= skip_spaces (args
);
12417 if (args
[0] == '\0')
12418 error (_("condition missing after `if' keyword"));
12419 cond_string
.assign (args
);
12422 /* Otherwise, there should be no other argument at the end of
12424 else if (args
[0] != '\0')
12425 error (_("Junk at end of arguments."));
12428 /* Implement the "catch assert" command. */
12431 catch_assert_command (const char *arg_entry
, int from_tty
,
12432 struct cmd_list_element
*command
)
12434 const char *arg
= arg_entry
;
12435 struct gdbarch
*gdbarch
= get_current_arch ();
12437 std::string cond_string
;
12439 tempflag
= command
->context () == CATCH_TEMPORARY
;
12443 catch_ada_assert_command_split (arg
, cond_string
);
12444 create_ada_exception_catchpoint (gdbarch
, ada_catch_assert
,
12446 tempflag
, 1 /* enabled */,
12450 /* Return non-zero if the symbol SYM is an Ada exception object. */
12453 ada_is_exception_sym (struct symbol
*sym
)
12455 const char *type_name
= SYMBOL_TYPE (sym
)->name ();
12457 return (SYMBOL_CLASS (sym
) != LOC_TYPEDEF
12458 && SYMBOL_CLASS (sym
) != LOC_BLOCK
12459 && SYMBOL_CLASS (sym
) != LOC_CONST
12460 && SYMBOL_CLASS (sym
) != LOC_UNRESOLVED
12461 && type_name
!= NULL
&& strcmp (type_name
, "exception") == 0);
12464 /* Given a global symbol SYM, return non-zero iff SYM is a non-standard
12465 Ada exception object. This matches all exceptions except the ones
12466 defined by the Ada language. */
12469 ada_is_non_standard_exception_sym (struct symbol
*sym
)
12473 if (!ada_is_exception_sym (sym
))
12476 for (i
= 0; i
< ARRAY_SIZE (standard_exc
); i
++)
12477 if (strcmp (sym
->linkage_name (), standard_exc
[i
]) == 0)
12478 return 0; /* A standard exception. */
12480 /* Numeric_Error is also a standard exception, so exclude it.
12481 See the STANDARD_EXC description for more details as to why
12482 this exception is not listed in that array. */
12483 if (strcmp (sym
->linkage_name (), "numeric_error") == 0)
12489 /* A helper function for std::sort, comparing two struct ada_exc_info
12492 The comparison is determined first by exception name, and then
12493 by exception address. */
12496 ada_exc_info::operator< (const ada_exc_info
&other
) const
12500 result
= strcmp (name
, other
.name
);
12503 if (result
== 0 && addr
< other
.addr
)
12509 ada_exc_info::operator== (const ada_exc_info
&other
) const
12511 return addr
== other
.addr
&& strcmp (name
, other
.name
) == 0;
12514 /* Sort EXCEPTIONS using compare_ada_exception_info as the comparison
12515 routine, but keeping the first SKIP elements untouched.
12517 All duplicates are also removed. */
12520 sort_remove_dups_ada_exceptions_list (std::vector
<ada_exc_info
> *exceptions
,
12523 std::sort (exceptions
->begin () + skip
, exceptions
->end ());
12524 exceptions
->erase (std::unique (exceptions
->begin () + skip
, exceptions
->end ()),
12525 exceptions
->end ());
12528 /* Add all exceptions defined by the Ada standard whose name match
12529 a regular expression.
12531 If PREG is not NULL, then this regexp_t object is used to
12532 perform the symbol name matching. Otherwise, no name-based
12533 filtering is performed.
12535 EXCEPTIONS is a vector of exceptions to which matching exceptions
12539 ada_add_standard_exceptions (compiled_regex
*preg
,
12540 std::vector
<ada_exc_info
> *exceptions
)
12544 for (i
= 0; i
< ARRAY_SIZE (standard_exc
); i
++)
12547 || preg
->exec (standard_exc
[i
], 0, NULL
, 0) == 0)
12549 struct bound_minimal_symbol msymbol
12550 = ada_lookup_simple_minsym (standard_exc
[i
]);
12552 if (msymbol
.minsym
!= NULL
)
12554 struct ada_exc_info info
12555 = {standard_exc
[i
], BMSYMBOL_VALUE_ADDRESS (msymbol
)};
12557 exceptions
->push_back (info
);
12563 /* Add all Ada exceptions defined locally and accessible from the given
12566 If PREG is not NULL, then this regexp_t object is used to
12567 perform the symbol name matching. Otherwise, no name-based
12568 filtering is performed.
12570 EXCEPTIONS is a vector of exceptions to which matching exceptions
12574 ada_add_exceptions_from_frame (compiled_regex
*preg
,
12575 struct frame_info
*frame
,
12576 std::vector
<ada_exc_info
> *exceptions
)
12578 const struct block
*block
= get_frame_block (frame
, 0);
12582 struct block_iterator iter
;
12583 struct symbol
*sym
;
12585 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
12587 switch (SYMBOL_CLASS (sym
))
12594 if (ada_is_exception_sym (sym
))
12596 struct ada_exc_info info
= {sym
->print_name (),
12597 SYMBOL_VALUE_ADDRESS (sym
)};
12599 exceptions
->push_back (info
);
12603 if (BLOCK_FUNCTION (block
) != NULL
)
12605 block
= BLOCK_SUPERBLOCK (block
);
12609 /* Return true if NAME matches PREG or if PREG is NULL. */
12612 name_matches_regex (const char *name
, compiled_regex
*preg
)
12614 return (preg
== NULL
12615 || preg
->exec (ada_decode (name
).c_str (), 0, NULL
, 0) == 0);
12618 /* Add all exceptions defined globally whose name name match
12619 a regular expression, excluding standard exceptions.
12621 The reason we exclude standard exceptions is that they need
12622 to be handled separately: Standard exceptions are defined inside
12623 a runtime unit which is normally not compiled with debugging info,
12624 and thus usually do not show up in our symbol search. However,
12625 if the unit was in fact built with debugging info, we need to
12626 exclude them because they would duplicate the entry we found
12627 during the special loop that specifically searches for those
12628 standard exceptions.
12630 If PREG is not NULL, then this regexp_t object is used to
12631 perform the symbol name matching. Otherwise, no name-based
12632 filtering is performed.
12634 EXCEPTIONS is a vector of exceptions to which matching exceptions
12638 ada_add_global_exceptions (compiled_regex
*preg
,
12639 std::vector
<ada_exc_info
> *exceptions
)
12641 /* In Ada, the symbol "search name" is a linkage name, whereas the
12642 regular expression used to do the matching refers to the natural
12643 name. So match against the decoded name. */
12644 expand_symtabs_matching (NULL
,
12645 lookup_name_info::match_any (),
12646 [&] (const char *search_name
)
12648 std::string decoded
= ada_decode (search_name
);
12649 return name_matches_regex (decoded
.c_str (), preg
);
12652 SEARCH_GLOBAL_BLOCK
| SEARCH_STATIC_BLOCK
,
12655 for (objfile
*objfile
: current_program_space
->objfiles ())
12657 for (compunit_symtab
*s
: objfile
->compunits ())
12659 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (s
);
12662 for (i
= GLOBAL_BLOCK
; i
<= STATIC_BLOCK
; i
++)
12664 const struct block
*b
= BLOCKVECTOR_BLOCK (bv
, i
);
12665 struct block_iterator iter
;
12666 struct symbol
*sym
;
12668 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
12669 if (ada_is_non_standard_exception_sym (sym
)
12670 && name_matches_regex (sym
->natural_name (), preg
))
12672 struct ada_exc_info info
12673 = {sym
->print_name (), SYMBOL_VALUE_ADDRESS (sym
)};
12675 exceptions
->push_back (info
);
12682 /* Implements ada_exceptions_list with the regular expression passed
12683 as a regex_t, rather than a string.
12685 If not NULL, PREG is used to filter out exceptions whose names
12686 do not match. Otherwise, all exceptions are listed. */
12688 static std::vector
<ada_exc_info
>
12689 ada_exceptions_list_1 (compiled_regex
*preg
)
12691 std::vector
<ada_exc_info
> result
;
12694 /* First, list the known standard exceptions. These exceptions
12695 need to be handled separately, as they are usually defined in
12696 runtime units that have been compiled without debugging info. */
12698 ada_add_standard_exceptions (preg
, &result
);
12700 /* Next, find all exceptions whose scope is local and accessible
12701 from the currently selected frame. */
12703 if (has_stack_frames ())
12705 prev_len
= result
.size ();
12706 ada_add_exceptions_from_frame (preg
, get_selected_frame (NULL
),
12708 if (result
.size () > prev_len
)
12709 sort_remove_dups_ada_exceptions_list (&result
, prev_len
);
12712 /* Add all exceptions whose scope is global. */
12714 prev_len
= result
.size ();
12715 ada_add_global_exceptions (preg
, &result
);
12716 if (result
.size () > prev_len
)
12717 sort_remove_dups_ada_exceptions_list (&result
, prev_len
);
12722 /* Return a vector of ada_exc_info.
12724 If REGEXP is NULL, all exceptions are included in the result.
12725 Otherwise, it should contain a valid regular expression,
12726 and only the exceptions whose names match that regular expression
12727 are included in the result.
12729 The exceptions are sorted in the following order:
12730 - Standard exceptions (defined by the Ada language), in
12731 alphabetical order;
12732 - Exceptions only visible from the current frame, in
12733 alphabetical order;
12734 - Exceptions whose scope is global, in alphabetical order. */
12736 std::vector
<ada_exc_info
>
12737 ada_exceptions_list (const char *regexp
)
12739 if (regexp
== NULL
)
12740 return ada_exceptions_list_1 (NULL
);
12742 compiled_regex
reg (regexp
, REG_NOSUB
, _("invalid regular expression"));
12743 return ada_exceptions_list_1 (®
);
12746 /* Implement the "info exceptions" command. */
12749 info_exceptions_command (const char *regexp
, int from_tty
)
12751 struct gdbarch
*gdbarch
= get_current_arch ();
12753 std::vector
<ada_exc_info
> exceptions
= ada_exceptions_list (regexp
);
12755 if (regexp
!= NULL
)
12757 (_("All Ada exceptions matching regular expression \"%s\":\n"), regexp
);
12759 printf_filtered (_("All defined Ada exceptions:\n"));
12761 for (const ada_exc_info
&info
: exceptions
)
12762 printf_filtered ("%s: %s\n", info
.name
, paddress (gdbarch
, info
.addr
));
12766 /* Language vector */
12768 /* symbol_name_matcher_ftype adapter for wild_match. */
12771 do_wild_match (const char *symbol_search_name
,
12772 const lookup_name_info
&lookup_name
,
12773 completion_match_result
*comp_match_res
)
12775 return wild_match (symbol_search_name
, ada_lookup_name (lookup_name
));
12778 /* symbol_name_matcher_ftype adapter for full_match. */
12781 do_full_match (const char *symbol_search_name
,
12782 const lookup_name_info
&lookup_name
,
12783 completion_match_result
*comp_match_res
)
12785 const char *lname
= lookup_name
.ada ().lookup_name ().c_str ();
12787 /* If both symbols start with "_ada_", just let the loop below
12788 handle the comparison. However, if only the symbol name starts
12789 with "_ada_", skip the prefix and let the match proceed as
12791 if (startswith (symbol_search_name
, "_ada_")
12792 && !startswith (lname
, "_ada"))
12793 symbol_search_name
+= 5;
12795 int uscore_count
= 0;
12796 while (*lname
!= '\0')
12798 if (*symbol_search_name
!= *lname
)
12800 if (*symbol_search_name
== 'B' && uscore_count
== 2
12801 && symbol_search_name
[1] == '_')
12803 symbol_search_name
+= 2;
12804 while (isdigit (*symbol_search_name
))
12805 ++symbol_search_name
;
12806 if (symbol_search_name
[0] == '_'
12807 && symbol_search_name
[1] == '_')
12809 symbol_search_name
+= 2;
12816 if (*symbol_search_name
== '_')
12821 ++symbol_search_name
;
12825 return is_name_suffix (symbol_search_name
);
12828 /* symbol_name_matcher_ftype for exact (verbatim) matches. */
12831 do_exact_match (const char *symbol_search_name
,
12832 const lookup_name_info
&lookup_name
,
12833 completion_match_result
*comp_match_res
)
12835 return strcmp (symbol_search_name
, ada_lookup_name (lookup_name
)) == 0;
12838 /* Build the Ada lookup name for LOOKUP_NAME. */
12840 ada_lookup_name_info::ada_lookup_name_info (const lookup_name_info
&lookup_name
)
12842 gdb::string_view user_name
= lookup_name
.name ();
12844 if (!user_name
.empty () && user_name
[0] == '<')
12846 if (user_name
.back () == '>')
12848 = gdb::to_string (user_name
.substr (1, user_name
.size () - 2));
12851 = gdb::to_string (user_name
.substr (1, user_name
.size () - 1));
12852 m_encoded_p
= true;
12853 m_verbatim_p
= true;
12854 m_wild_match_p
= false;
12855 m_standard_p
= false;
12859 m_verbatim_p
= false;
12861 m_encoded_p
= user_name
.find ("__") != gdb::string_view::npos
;
12865 const char *folded
= ada_fold_name (user_name
);
12866 m_encoded_name
= ada_encode_1 (folded
, false);
12867 if (m_encoded_name
.empty ())
12868 m_encoded_name
= gdb::to_string (user_name
);
12871 m_encoded_name
= gdb::to_string (user_name
);
12873 /* Handle the 'package Standard' special case. See description
12874 of m_standard_p. */
12875 if (startswith (m_encoded_name
.c_str (), "standard__"))
12877 m_encoded_name
= m_encoded_name
.substr (sizeof ("standard__") - 1);
12878 m_standard_p
= true;
12881 m_standard_p
= false;
12883 /* If the name contains a ".", then the user is entering a fully
12884 qualified entity name, and the match must not be done in wild
12885 mode. Similarly, if the user wants to complete what looks
12886 like an encoded name, the match must not be done in wild
12887 mode. Also, in the standard__ special case always do
12888 non-wild matching. */
12890 = (lookup_name
.match_type () != symbol_name_match_type::FULL
12893 && user_name
.find ('.') == std::string::npos
);
12897 /* symbol_name_matcher_ftype method for Ada. This only handles
12898 completion mode. */
12901 ada_symbol_name_matches (const char *symbol_search_name
,
12902 const lookup_name_info
&lookup_name
,
12903 completion_match_result
*comp_match_res
)
12905 return lookup_name
.ada ().matches (symbol_search_name
,
12906 lookup_name
.match_type (),
12910 /* A name matcher that matches the symbol name exactly, with
12914 literal_symbol_name_matcher (const char *symbol_search_name
,
12915 const lookup_name_info
&lookup_name
,
12916 completion_match_result
*comp_match_res
)
12918 gdb::string_view name_view
= lookup_name
.name ();
12920 if (lookup_name
.completion_mode ()
12921 ? (strncmp (symbol_search_name
, name_view
.data (),
12922 name_view
.size ()) == 0)
12923 : symbol_search_name
== name_view
)
12925 if (comp_match_res
!= NULL
)
12926 comp_match_res
->set_match (symbol_search_name
);
12933 /* Implement the "get_symbol_name_matcher" language_defn method for
12936 static symbol_name_matcher_ftype
*
12937 ada_get_symbol_name_matcher (const lookup_name_info
&lookup_name
)
12939 if (lookup_name
.match_type () == symbol_name_match_type::SEARCH_NAME
)
12940 return literal_symbol_name_matcher
;
12942 if (lookup_name
.completion_mode ())
12943 return ada_symbol_name_matches
;
12946 if (lookup_name
.ada ().wild_match_p ())
12947 return do_wild_match
;
12948 else if (lookup_name
.ada ().verbatim_p ())
12949 return do_exact_match
;
12951 return do_full_match
;
12955 /* Class representing the Ada language. */
12957 class ada_language
: public language_defn
12961 : language_defn (language_ada
)
12964 /* See language.h. */
12966 const char *name () const override
12969 /* See language.h. */
12971 const char *natural_name () const override
12974 /* See language.h. */
12976 const std::vector
<const char *> &filename_extensions () const override
12978 static const std::vector
<const char *> extensions
12979 = { ".adb", ".ads", ".a", ".ada", ".dg" };
12983 /* Print an array element index using the Ada syntax. */
12985 void print_array_index (struct type
*index_type
,
12987 struct ui_file
*stream
,
12988 const value_print_options
*options
) const override
12990 struct value
*index_value
= val_atr (index_type
, index
);
12992 value_print (index_value
, stream
, options
);
12993 fprintf_filtered (stream
, " => ");
12996 /* Implement the "read_var_value" language_defn method for Ada. */
12998 struct value
*read_var_value (struct symbol
*var
,
12999 const struct block
*var_block
,
13000 struct frame_info
*frame
) const override
13002 /* The only case where default_read_var_value is not sufficient
13003 is when VAR is a renaming... */
13004 if (frame
!= nullptr)
13006 const struct block
*frame_block
= get_frame_block (frame
, NULL
);
13007 if (frame_block
!= nullptr && ada_is_renaming_symbol (var
))
13008 return ada_read_renaming_var_value (var
, frame_block
);
13011 /* This is a typical case where we expect the default_read_var_value
13012 function to work. */
13013 return language_defn::read_var_value (var
, var_block
, frame
);
13016 /* See language.h. */
13017 virtual bool symbol_printing_suppressed (struct symbol
*symbol
) const override
13019 return symbol
->artificial
;
13022 /* See language.h. */
13023 void language_arch_info (struct gdbarch
*gdbarch
,
13024 struct language_arch_info
*lai
) const override
13026 const struct builtin_type
*builtin
= builtin_type (gdbarch
);
13028 /* Helper function to allow shorter lines below. */
13029 auto add
= [&] (struct type
*t
)
13031 lai
->add_primitive_type (t
);
13034 add (arch_integer_type (gdbarch
, gdbarch_int_bit (gdbarch
),
13036 add (arch_integer_type (gdbarch
, gdbarch_long_bit (gdbarch
),
13037 0, "long_integer"));
13038 add (arch_integer_type (gdbarch
, gdbarch_short_bit (gdbarch
),
13039 0, "short_integer"));
13040 struct type
*char_type
= arch_character_type (gdbarch
, TARGET_CHAR_BIT
,
13042 lai
->set_string_char_type (char_type
);
13044 add (arch_float_type (gdbarch
, gdbarch_float_bit (gdbarch
),
13045 "float", gdbarch_float_format (gdbarch
)));
13046 add (arch_float_type (gdbarch
, gdbarch_double_bit (gdbarch
),
13047 "long_float", gdbarch_double_format (gdbarch
)));
13048 add (arch_integer_type (gdbarch
, gdbarch_long_long_bit (gdbarch
),
13049 0, "long_long_integer"));
13050 add (arch_float_type (gdbarch
, gdbarch_long_double_bit (gdbarch
),
13052 gdbarch_long_double_format (gdbarch
)));
13053 add (arch_integer_type (gdbarch
, gdbarch_int_bit (gdbarch
),
13055 add (arch_integer_type (gdbarch
, gdbarch_int_bit (gdbarch
),
13057 add (builtin
->builtin_void
);
13059 struct type
*system_addr_ptr
13060 = lookup_pointer_type (arch_type (gdbarch
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
,
13062 system_addr_ptr
->set_name ("system__address");
13063 add (system_addr_ptr
);
13065 /* Create the equivalent of the System.Storage_Elements.Storage_Offset
13066 type. This is a signed integral type whose size is the same as
13067 the size of addresses. */
13068 unsigned int addr_length
= TYPE_LENGTH (system_addr_ptr
);
13069 add (arch_integer_type (gdbarch
, addr_length
* HOST_CHAR_BIT
, 0,
13070 "storage_offset"));
13072 lai
->set_bool_type (builtin
->builtin_bool
);
13075 /* See language.h. */
13077 bool iterate_over_symbols
13078 (const struct block
*block
, const lookup_name_info
&name
,
13079 domain_enum domain
,
13080 gdb::function_view
<symbol_found_callback_ftype
> callback
) const override
13082 std::vector
<struct block_symbol
> results
13083 = ada_lookup_symbol_list_worker (name
, block
, domain
, 0);
13084 for (block_symbol
&sym
: results
)
13086 if (!callback (&sym
))
13093 /* See language.h. */
13094 bool sniff_from_mangled_name
13095 (const char *mangled
,
13096 gdb::unique_xmalloc_ptr
<char> *out
) const override
13098 std::string demangled
= ada_decode (mangled
);
13102 if (demangled
!= mangled
&& demangled
[0] != '<')
13104 /* Set the gsymbol language to Ada, but still return 0.
13105 Two reasons for that:
13107 1. For Ada, we prefer computing the symbol's decoded name
13108 on the fly rather than pre-compute it, in order to save
13109 memory (Ada projects are typically very large).
13111 2. There are some areas in the definition of the GNAT
13112 encoding where, with a bit of bad luck, we might be able
13113 to decode a non-Ada symbol, generating an incorrect
13114 demangled name (Eg: names ending with "TB" for instance
13115 are identified as task bodies and so stripped from
13116 the decoded name returned).
13118 Returning true, here, but not setting *DEMANGLED, helps us get
13119 a little bit of the best of both worlds. Because we're last,
13120 we should not affect any of the other languages that were
13121 able to demangle the symbol before us; we get to correctly
13122 tag Ada symbols as such; and even if we incorrectly tagged a
13123 non-Ada symbol, which should be rare, any routing through the
13124 Ada language should be transparent (Ada tries to behave much
13125 like C/C++ with non-Ada symbols). */
13132 /* See language.h. */
13134 gdb::unique_xmalloc_ptr
<char> demangle_symbol (const char *mangled
,
13135 int options
) const override
13137 return make_unique_xstrdup (ada_decode (mangled
).c_str ());
13140 /* See language.h. */
13142 void print_type (struct type
*type
, const char *varstring
,
13143 struct ui_file
*stream
, int show
, int level
,
13144 const struct type_print_options
*flags
) const override
13146 ada_print_type (type
, varstring
, stream
, show
, level
, flags
);
13149 /* See language.h. */
13151 const char *word_break_characters (void) const override
13153 return ada_completer_word_break_characters
;
13156 /* See language.h. */
13158 void collect_symbol_completion_matches (completion_tracker
&tracker
,
13159 complete_symbol_mode mode
,
13160 symbol_name_match_type name_match_type
,
13161 const char *text
, const char *word
,
13162 enum type_code code
) const override
13164 struct symbol
*sym
;
13165 const struct block
*b
, *surrounding_static_block
= 0;
13166 struct block_iterator iter
;
13168 gdb_assert (code
== TYPE_CODE_UNDEF
);
13170 lookup_name_info
lookup_name (text
, name_match_type
, true);
13172 /* First, look at the partial symtab symbols. */
13173 expand_symtabs_matching (NULL
,
13177 SEARCH_GLOBAL_BLOCK
| SEARCH_STATIC_BLOCK
,
13180 /* At this point scan through the misc symbol vectors and add each
13181 symbol you find to the list. Eventually we want to ignore
13182 anything that isn't a text symbol (everything else will be
13183 handled by the psymtab code above). */
13185 for (objfile
*objfile
: current_program_space
->objfiles ())
13187 for (minimal_symbol
*msymbol
: objfile
->msymbols ())
13191 if (completion_skip_symbol (mode
, msymbol
))
13194 language symbol_language
= msymbol
->language ();
13196 /* Ada minimal symbols won't have their language set to Ada. If
13197 we let completion_list_add_name compare using the
13198 default/C-like matcher, then when completing e.g., symbols in a
13199 package named "pck", we'd match internal Ada symbols like
13200 "pckS", which are invalid in an Ada expression, unless you wrap
13201 them in '<' '>' to request a verbatim match.
13203 Unfortunately, some Ada encoded names successfully demangle as
13204 C++ symbols (using an old mangling scheme), such as "name__2Xn"
13205 -> "Xn::name(void)" and thus some Ada minimal symbols end up
13206 with the wrong language set. Paper over that issue here. */
13207 if (symbol_language
== language_auto
13208 || symbol_language
== language_cplus
)
13209 symbol_language
= language_ada
;
13211 completion_list_add_name (tracker
,
13213 msymbol
->linkage_name (),
13214 lookup_name
, text
, word
);
13218 /* Search upwards from currently selected frame (so that we can
13219 complete on local vars. */
13221 for (b
= get_selected_block (0); b
!= NULL
; b
= BLOCK_SUPERBLOCK (b
))
13223 if (!BLOCK_SUPERBLOCK (b
))
13224 surrounding_static_block
= b
; /* For elmin of dups */
13226 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
13228 if (completion_skip_symbol (mode
, sym
))
13231 completion_list_add_name (tracker
,
13233 sym
->linkage_name (),
13234 lookup_name
, text
, word
);
13238 /* Go through the symtabs and check the externs and statics for
13239 symbols which match. */
13241 for (objfile
*objfile
: current_program_space
->objfiles ())
13243 for (compunit_symtab
*s
: objfile
->compunits ())
13246 b
= BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (s
), GLOBAL_BLOCK
);
13247 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
13249 if (completion_skip_symbol (mode
, sym
))
13252 completion_list_add_name (tracker
,
13254 sym
->linkage_name (),
13255 lookup_name
, text
, word
);
13260 for (objfile
*objfile
: current_program_space
->objfiles ())
13262 for (compunit_symtab
*s
: objfile
->compunits ())
13265 b
= BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (s
), STATIC_BLOCK
);
13266 /* Don't do this block twice. */
13267 if (b
== surrounding_static_block
)
13269 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
13271 if (completion_skip_symbol (mode
, sym
))
13274 completion_list_add_name (tracker
,
13276 sym
->linkage_name (),
13277 lookup_name
, text
, word
);
13283 /* See language.h. */
13285 gdb::unique_xmalloc_ptr
<char> watch_location_expression
13286 (struct type
*type
, CORE_ADDR addr
) const override
13288 type
= check_typedef (TYPE_TARGET_TYPE (check_typedef (type
)));
13289 std::string name
= type_to_string (type
);
13290 return gdb::unique_xmalloc_ptr
<char>
13291 (xstrprintf ("{%s} %s", name
.c_str (), core_addr_to_string (addr
)));
13294 /* See language.h. */
13296 void value_print (struct value
*val
, struct ui_file
*stream
,
13297 const struct value_print_options
*options
) const override
13299 return ada_value_print (val
, stream
, options
);
13302 /* See language.h. */
13304 void value_print_inner
13305 (struct value
*val
, struct ui_file
*stream
, int recurse
,
13306 const struct value_print_options
*options
) const override
13308 return ada_value_print_inner (val
, stream
, recurse
, options
);
13311 /* See language.h. */
13313 struct block_symbol lookup_symbol_nonlocal
13314 (const char *name
, const struct block
*block
,
13315 const domain_enum domain
) const override
13317 struct block_symbol sym
;
13319 sym
= ada_lookup_symbol (name
, block_static_block (block
), domain
);
13320 if (sym
.symbol
!= NULL
)
13323 /* If we haven't found a match at this point, try the primitive
13324 types. In other languages, this search is performed before
13325 searching for global symbols in order to short-circuit that
13326 global-symbol search if it happens that the name corresponds
13327 to a primitive type. But we cannot do the same in Ada, because
13328 it is perfectly legitimate for a program to declare a type which
13329 has the same name as a standard type. If looking up a type in
13330 that situation, we have traditionally ignored the primitive type
13331 in favor of user-defined types. This is why, unlike most other
13332 languages, we search the primitive types this late and only after
13333 having searched the global symbols without success. */
13335 if (domain
== VAR_DOMAIN
)
13337 struct gdbarch
*gdbarch
;
13340 gdbarch
= target_gdbarch ();
13342 gdbarch
= block_gdbarch (block
);
13344 = language_lookup_primitive_type_as_symbol (this, gdbarch
, name
);
13345 if (sym
.symbol
!= NULL
)
13352 /* See language.h. */
13354 int parser (struct parser_state
*ps
) const override
13356 warnings_issued
= 0;
13357 return ada_parse (ps
);
13360 /* See language.h. */
13362 void emitchar (int ch
, struct type
*chtype
,
13363 struct ui_file
*stream
, int quoter
) const override
13365 ada_emit_char (ch
, chtype
, stream
, quoter
, 1);
13368 /* See language.h. */
13370 void printchar (int ch
, struct type
*chtype
,
13371 struct ui_file
*stream
) const override
13373 ada_printchar (ch
, chtype
, stream
);
13376 /* See language.h. */
13378 void printstr (struct ui_file
*stream
, struct type
*elttype
,
13379 const gdb_byte
*string
, unsigned int length
,
13380 const char *encoding
, int force_ellipses
,
13381 const struct value_print_options
*options
) const override
13383 ada_printstr (stream
, elttype
, string
, length
, encoding
,
13384 force_ellipses
, options
);
13387 /* See language.h. */
13389 void print_typedef (struct type
*type
, struct symbol
*new_symbol
,
13390 struct ui_file
*stream
) const override
13392 ada_print_typedef (type
, new_symbol
, stream
);
13395 /* See language.h. */
13397 bool is_string_type_p (struct type
*type
) const override
13399 return ada_is_string_type (type
);
13402 /* See language.h. */
13404 const char *struct_too_deep_ellipsis () const override
13405 { return "(...)"; }
13407 /* See language.h. */
13409 bool c_style_arrays_p () const override
13412 /* See language.h. */
13414 bool store_sym_names_in_linkage_form_p () const override
13417 /* See language.h. */
13419 const struct lang_varobj_ops
*varobj_ops () const override
13420 { return &ada_varobj_ops
; }
13423 /* See language.h. */
13425 symbol_name_matcher_ftype
*get_symbol_name_matcher_inner
13426 (const lookup_name_info
&lookup_name
) const override
13428 return ada_get_symbol_name_matcher (lookup_name
);
13432 /* Single instance of the Ada language class. */
13434 static ada_language ada_language_defn
;
13436 /* Command-list for the "set/show ada" prefix command. */
13437 static struct cmd_list_element
*set_ada_list
;
13438 static struct cmd_list_element
*show_ada_list
;
13441 initialize_ada_catchpoint_ops (void)
13443 struct breakpoint_ops
*ops
;
13445 initialize_breakpoint_ops ();
13447 ops
= &catch_exception_breakpoint_ops
;
13448 *ops
= bkpt_breakpoint_ops
;
13449 ops
->allocate_location
= allocate_location_exception
;
13450 ops
->re_set
= re_set_exception
;
13451 ops
->check_status
= check_status_exception
;
13452 ops
->print_it
= print_it_exception
;
13453 ops
->print_one
= print_one_exception
;
13454 ops
->print_mention
= print_mention_exception
;
13455 ops
->print_recreate
= print_recreate_exception
;
13457 ops
= &catch_exception_unhandled_breakpoint_ops
;
13458 *ops
= bkpt_breakpoint_ops
;
13459 ops
->allocate_location
= allocate_location_exception
;
13460 ops
->re_set
= re_set_exception
;
13461 ops
->check_status
= check_status_exception
;
13462 ops
->print_it
= print_it_exception
;
13463 ops
->print_one
= print_one_exception
;
13464 ops
->print_mention
= print_mention_exception
;
13465 ops
->print_recreate
= print_recreate_exception
;
13467 ops
= &catch_assert_breakpoint_ops
;
13468 *ops
= bkpt_breakpoint_ops
;
13469 ops
->allocate_location
= allocate_location_exception
;
13470 ops
->re_set
= re_set_exception
;
13471 ops
->check_status
= check_status_exception
;
13472 ops
->print_it
= print_it_exception
;
13473 ops
->print_one
= print_one_exception
;
13474 ops
->print_mention
= print_mention_exception
;
13475 ops
->print_recreate
= print_recreate_exception
;
13477 ops
= &catch_handlers_breakpoint_ops
;
13478 *ops
= bkpt_breakpoint_ops
;
13479 ops
->allocate_location
= allocate_location_exception
;
13480 ops
->re_set
= re_set_exception
;
13481 ops
->check_status
= check_status_exception
;
13482 ops
->print_it
= print_it_exception
;
13483 ops
->print_one
= print_one_exception
;
13484 ops
->print_mention
= print_mention_exception
;
13485 ops
->print_recreate
= print_recreate_exception
;
13488 /* This module's 'new_objfile' observer. */
13491 ada_new_objfile_observer (struct objfile
*objfile
)
13493 ada_clear_symbol_cache ();
13496 /* This module's 'free_objfile' observer. */
13499 ada_free_objfile_observer (struct objfile
*objfile
)
13501 ada_clear_symbol_cache ();
13504 void _initialize_ada_language ();
13506 _initialize_ada_language ()
13508 initialize_ada_catchpoint_ops ();
13510 add_setshow_prefix_cmd
13512 _("Prefix command for changing Ada-specific settings."),
13513 _("Generic command for showing Ada-specific settings."),
13514 &set_ada_list
, &show_ada_list
,
13515 &setlist
, &showlist
);
13517 add_setshow_boolean_cmd ("trust-PAD-over-XVS", class_obscure
,
13518 &trust_pad_over_xvs
, _("\
13519 Enable or disable an optimization trusting PAD types over XVS types."), _("\
13520 Show whether an optimization trusting PAD types over XVS types is activated."),
13522 This is related to the encoding used by the GNAT compiler. The debugger\n\
13523 should normally trust the contents of PAD types, but certain older versions\n\
13524 of GNAT have a bug that sometimes causes the information in the PAD type\n\
13525 to be incorrect. Turning this setting \"off\" allows the debugger to\n\
13526 work around this bug. It is always safe to turn this option \"off\", but\n\
13527 this incurs a slight performance penalty, so it is recommended to NOT change\n\
13528 this option to \"off\" unless necessary."),
13529 NULL
, NULL
, &set_ada_list
, &show_ada_list
);
13531 add_setshow_boolean_cmd ("print-signatures", class_vars
,
13532 &print_signatures
, _("\
13533 Enable or disable the output of formal and return types for functions in the \
13534 overloads selection menu."), _("\
13535 Show whether the output of formal and return types for functions in the \
13536 overloads selection menu is activated."),
13537 NULL
, NULL
, NULL
, &set_ada_list
, &show_ada_list
);
13539 add_catch_command ("exception", _("\
13540 Catch Ada exceptions, when raised.\n\
13541 Usage: catch exception [ARG] [if CONDITION]\n\
13542 Without any argument, stop when any Ada exception is raised.\n\
13543 If ARG is \"unhandled\" (without the quotes), only stop when the exception\n\
13544 being raised does not have a handler (and will therefore lead to the task's\n\
13546 Otherwise, the catchpoint only stops when the name of the exception being\n\
13547 raised is the same as ARG.\n\
13548 CONDITION is a boolean expression that is evaluated to see whether the\n\
13549 exception should cause a stop."),
13550 catch_ada_exception_command
,
13551 catch_ada_completer
,
13555 add_catch_command ("handlers", _("\
13556 Catch Ada exceptions, when handled.\n\
13557 Usage: catch handlers [ARG] [if CONDITION]\n\
13558 Without any argument, stop when any Ada exception is handled.\n\
13559 With an argument, catch only exceptions with the given name.\n\
13560 CONDITION is a boolean expression that is evaluated to see whether the\n\
13561 exception should cause a stop."),
13562 catch_ada_handlers_command
,
13563 catch_ada_completer
,
13566 add_catch_command ("assert", _("\
13567 Catch failed Ada assertions, when raised.\n\
13568 Usage: catch assert [if CONDITION]\n\
13569 CONDITION is a boolean expression that is evaluated to see whether the\n\
13570 exception should cause a stop."),
13571 catch_assert_command
,
13576 add_info ("exceptions", info_exceptions_command
,
13578 List all Ada exception names.\n\
13579 Usage: info exceptions [REGEXP]\n\
13580 If a regular expression is passed as an argument, only those matching\n\
13581 the regular expression are listed."));
13583 add_setshow_prefix_cmd ("ada", class_maintenance
,
13584 _("Set Ada maintenance-related variables."),
13585 _("Show Ada maintenance-related variables."),
13586 &maint_set_ada_cmdlist
, &maint_show_ada_cmdlist
,
13587 &maintenance_set_cmdlist
, &maintenance_show_cmdlist
);
13589 add_setshow_boolean_cmd
13590 ("ignore-descriptive-types", class_maintenance
,
13591 &ada_ignore_descriptive_types_p
,
13592 _("Set whether descriptive types generated by GNAT should be ignored."),
13593 _("Show whether descriptive types generated by GNAT should be ignored."),
13595 When enabled, the debugger will stop using the DW_AT_GNAT_descriptive_type\n\
13596 DWARF attribute."),
13597 NULL
, NULL
, &maint_set_ada_cmdlist
, &maint_show_ada_cmdlist
);
13599 decoded_names_store
= htab_create_alloc (256, htab_hash_string
,
13601 NULL
, xcalloc
, xfree
);
13603 /* The ada-lang observers. */
13604 gdb::observers::new_objfile
.attach (ada_new_objfile_observer
, "ada-lang");
13605 gdb::observers::free_objfile
.attach (ada_free_objfile_observer
, "ada-lang");
13606 gdb::observers::inferior_exit
.attach (ada_inferior_exit
, "ada-lang");