1a45ae5f8SJohn Marino /* Ada language support routines for GDB, the GNU debugger.
25796c8dcSSimon Schubert
3*ef5ccd6cSJohn Marino Copyright (C) 1992-2013 Free Software Foundation, Inc.
45796c8dcSSimon Schubert
55796c8dcSSimon Schubert This file is part of GDB.
65796c8dcSSimon Schubert
75796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify
85796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by
95796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or
105796c8dcSSimon Schubert (at your option) any later version.
115796c8dcSSimon Schubert
125796c8dcSSimon Schubert This program is distributed in the hope that it will be useful,
135796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of
145796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
155796c8dcSSimon Schubert GNU General Public License for more details.
165796c8dcSSimon Schubert
175796c8dcSSimon Schubert You should have received a copy of the GNU General Public License
185796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */
195796c8dcSSimon Schubert
205796c8dcSSimon Schubert
215796c8dcSSimon Schubert #include "defs.h"
225796c8dcSSimon Schubert #include <stdio.h>
235796c8dcSSimon Schubert #include "gdb_string.h"
245796c8dcSSimon Schubert #include <ctype.h>
255796c8dcSSimon Schubert #include <stdarg.h>
265796c8dcSSimon Schubert #include "demangle.h"
275796c8dcSSimon Schubert #include "gdb_regex.h"
285796c8dcSSimon Schubert #include "frame.h"
295796c8dcSSimon Schubert #include "symtab.h"
305796c8dcSSimon Schubert #include "gdbtypes.h"
315796c8dcSSimon Schubert #include "gdbcmd.h"
325796c8dcSSimon Schubert #include "expression.h"
335796c8dcSSimon Schubert #include "parser-defs.h"
345796c8dcSSimon Schubert #include "language.h"
355796c8dcSSimon Schubert #include "c-lang.h"
365796c8dcSSimon Schubert #include "inferior.h"
375796c8dcSSimon Schubert #include "symfile.h"
385796c8dcSSimon Schubert #include "objfiles.h"
395796c8dcSSimon Schubert #include "breakpoint.h"
405796c8dcSSimon Schubert #include "gdbcore.h"
415796c8dcSSimon Schubert #include "hashtab.h"
425796c8dcSSimon Schubert #include "gdb_obstack.h"
435796c8dcSSimon Schubert #include "ada-lang.h"
445796c8dcSSimon Schubert #include "completer.h"
455796c8dcSSimon Schubert #include "gdb_stat.h"
465796c8dcSSimon Schubert #ifdef UI_OUT
475796c8dcSSimon Schubert #include "ui-out.h"
485796c8dcSSimon Schubert #endif
495796c8dcSSimon Schubert #include "block.h"
505796c8dcSSimon Schubert #include "infcall.h"
515796c8dcSSimon Schubert #include "dictionary.h"
525796c8dcSSimon Schubert #include "exceptions.h"
535796c8dcSSimon Schubert #include "annotate.h"
545796c8dcSSimon Schubert #include "valprint.h"
555796c8dcSSimon Schubert #include "source.h"
565796c8dcSSimon Schubert #include "observer.h"
575796c8dcSSimon Schubert #include "vec.h"
58cf7f2e2dSJohn Marino #include "stack.h"
59*ef5ccd6cSJohn Marino #include "gdb_vecs.h"
60*ef5ccd6cSJohn Marino #include "typeprint.h"
61cf7f2e2dSJohn Marino
62cf7f2e2dSJohn Marino #include "psymtab.h"
63c50c785cSJohn Marino #include "value.h"
64c50c785cSJohn Marino #include "mi/mi-common.h"
65a45ae5f8SJohn Marino #include "arch-utils.h"
66a45ae5f8SJohn Marino #include "exceptions.h"
67*ef5ccd6cSJohn Marino #include "cli/cli-utils.h"
685796c8dcSSimon Schubert
695796c8dcSSimon Schubert /* Define whether or not the C operator '/' truncates towards zero for
705796c8dcSSimon Schubert differently signed operands (truncation direction is undefined in C).
715796c8dcSSimon Schubert Copied from valarith.c. */
725796c8dcSSimon Schubert
735796c8dcSSimon Schubert #ifndef TRUNCATION_TOWARDS_ZERO
745796c8dcSSimon Schubert #define TRUNCATION_TOWARDS_ZERO ((-5 / 2) == -2)
755796c8dcSSimon Schubert #endif
765796c8dcSSimon Schubert
775796c8dcSSimon Schubert static struct type *desc_base_type (struct type *);
785796c8dcSSimon Schubert
795796c8dcSSimon Schubert static struct type *desc_bounds_type (struct type *);
805796c8dcSSimon Schubert
815796c8dcSSimon Schubert static struct value *desc_bounds (struct value *);
825796c8dcSSimon Schubert
835796c8dcSSimon Schubert static int fat_pntr_bounds_bitpos (struct type *);
845796c8dcSSimon Schubert
855796c8dcSSimon Schubert static int fat_pntr_bounds_bitsize (struct type *);
865796c8dcSSimon Schubert
875796c8dcSSimon Schubert static struct type *desc_data_target_type (struct type *);
885796c8dcSSimon Schubert
895796c8dcSSimon Schubert static struct value *desc_data (struct value *);
905796c8dcSSimon Schubert
915796c8dcSSimon Schubert static int fat_pntr_data_bitpos (struct type *);
925796c8dcSSimon Schubert
935796c8dcSSimon Schubert static int fat_pntr_data_bitsize (struct type *);
945796c8dcSSimon Schubert
955796c8dcSSimon Schubert static struct value *desc_one_bound (struct value *, int, int);
965796c8dcSSimon Schubert
975796c8dcSSimon Schubert static int desc_bound_bitpos (struct type *, int, int);
985796c8dcSSimon Schubert
995796c8dcSSimon Schubert static int desc_bound_bitsize (struct type *, int, int);
1005796c8dcSSimon Schubert
1015796c8dcSSimon Schubert static struct type *desc_index_type (struct type *, int);
1025796c8dcSSimon Schubert
1035796c8dcSSimon Schubert static int desc_arity (struct type *);
1045796c8dcSSimon Schubert
1055796c8dcSSimon Schubert static int ada_type_match (struct type *, struct type *, int);
1065796c8dcSSimon Schubert
1075796c8dcSSimon Schubert static int ada_args_match (struct symbol *, struct value **, int);
1085796c8dcSSimon Schubert
109c50c785cSJohn Marino static int full_match (const char *, const char *);
1105796c8dcSSimon Schubert
111c50c785cSJohn Marino static struct value *make_array_descriptor (struct type *, struct value *);
1125796c8dcSSimon Schubert
1135796c8dcSSimon Schubert static void ada_add_block_symbols (struct obstack *,
1145796c8dcSSimon Schubert struct block *, const char *,
1155796c8dcSSimon Schubert domain_enum, struct objfile *, int);
1165796c8dcSSimon Schubert
1175796c8dcSSimon Schubert static int is_nonfunction (struct ada_symbol_info *, int);
1185796c8dcSSimon Schubert
1195796c8dcSSimon Schubert static void add_defn_to_vec (struct obstack *, struct symbol *,
1205796c8dcSSimon Schubert struct block *);
1215796c8dcSSimon Schubert
1225796c8dcSSimon Schubert static int num_defns_collected (struct obstack *);
1235796c8dcSSimon Schubert
1245796c8dcSSimon Schubert static struct ada_symbol_info *defns_collected (struct obstack *, int);
1255796c8dcSSimon Schubert
1265796c8dcSSimon Schubert static struct value *resolve_subexp (struct expression **, int *, int,
1275796c8dcSSimon Schubert struct type *);
1285796c8dcSSimon Schubert
1295796c8dcSSimon Schubert static void replace_operator_with_call (struct expression **, int, int, int,
130*ef5ccd6cSJohn Marino struct symbol *, const struct block *);
1315796c8dcSSimon Schubert
1325796c8dcSSimon Schubert static int possible_user_operator_p (enum exp_opcode, struct value **);
1335796c8dcSSimon Schubert
1345796c8dcSSimon Schubert static char *ada_op_name (enum exp_opcode);
1355796c8dcSSimon Schubert
1365796c8dcSSimon Schubert static const char *ada_decoded_op_name (enum exp_opcode);
1375796c8dcSSimon Schubert
1385796c8dcSSimon Schubert static int numeric_type_p (struct type *);
1395796c8dcSSimon Schubert
1405796c8dcSSimon Schubert static int integer_type_p (struct type *);
1415796c8dcSSimon Schubert
1425796c8dcSSimon Schubert static int scalar_type_p (struct type *);
1435796c8dcSSimon Schubert
1445796c8dcSSimon Schubert static int discrete_type_p (struct type *);
1455796c8dcSSimon Schubert
1465796c8dcSSimon Schubert static enum ada_renaming_category parse_old_style_renaming (struct type *,
1475796c8dcSSimon Schubert const char **,
1485796c8dcSSimon Schubert int *,
1495796c8dcSSimon Schubert const char **);
1505796c8dcSSimon Schubert
1515796c8dcSSimon Schubert static struct symbol *find_old_style_renaming_symbol (const char *,
152*ef5ccd6cSJohn Marino const struct block *);
1535796c8dcSSimon Schubert
1545796c8dcSSimon Schubert static struct type *ada_lookup_struct_elt_type (struct type *, char *,
1555796c8dcSSimon Schubert int, int, int *);
1565796c8dcSSimon Schubert
1575796c8dcSSimon Schubert static struct value *evaluate_subexp_type (struct expression *, int *);
1585796c8dcSSimon Schubert
159cf7f2e2dSJohn Marino static struct type *ada_find_parallel_type_with_name (struct type *,
160cf7f2e2dSJohn Marino const char *);
161cf7f2e2dSJohn Marino
1625796c8dcSSimon Schubert static int is_dynamic_field (struct type *, int);
1635796c8dcSSimon Schubert
1645796c8dcSSimon Schubert static struct type *to_fixed_variant_branch_type (struct type *,
1655796c8dcSSimon Schubert const gdb_byte *,
1665796c8dcSSimon Schubert CORE_ADDR, struct value *);
1675796c8dcSSimon Schubert
1685796c8dcSSimon Schubert static struct type *to_fixed_array_type (struct type *, struct value *, int);
1695796c8dcSSimon Schubert
170cf7f2e2dSJohn Marino static struct type *to_fixed_range_type (struct type *, struct value *);
1715796c8dcSSimon Schubert
1725796c8dcSSimon Schubert static struct type *to_static_fixed_type (struct type *);
1735796c8dcSSimon Schubert static struct type *static_unwrap_type (struct type *type);
1745796c8dcSSimon Schubert
1755796c8dcSSimon Schubert static struct value *unwrap_value (struct value *);
1765796c8dcSSimon Schubert
177cf7f2e2dSJohn Marino static struct type *constrained_packed_array_type (struct type *, long *);
1785796c8dcSSimon Schubert
179cf7f2e2dSJohn Marino static struct type *decode_constrained_packed_array_type (struct type *);
1805796c8dcSSimon Schubert
181cf7f2e2dSJohn Marino static long decode_packed_array_bitsize (struct type *);
182cf7f2e2dSJohn Marino
183cf7f2e2dSJohn Marino static struct value *decode_constrained_packed_array (struct value *);
184cf7f2e2dSJohn Marino
185cf7f2e2dSJohn Marino static int ada_is_packed_array_type (struct type *);
186cf7f2e2dSJohn Marino
187cf7f2e2dSJohn Marino static int ada_is_unconstrained_packed_array_type (struct type *);
1885796c8dcSSimon Schubert
1895796c8dcSSimon Schubert static struct value *value_subscript_packed (struct value *, int,
1905796c8dcSSimon Schubert struct value **);
1915796c8dcSSimon Schubert
1925796c8dcSSimon Schubert static void move_bits (gdb_byte *, int, const gdb_byte *, int, int, int);
1935796c8dcSSimon Schubert
1945796c8dcSSimon Schubert static struct value *coerce_unspec_val_to_type (struct value *,
1955796c8dcSSimon Schubert struct type *);
1965796c8dcSSimon Schubert
1975796c8dcSSimon Schubert static struct value *get_var_value (char *, char *);
1985796c8dcSSimon Schubert
1995796c8dcSSimon Schubert static int lesseq_defined_than (struct symbol *, struct symbol *);
2005796c8dcSSimon Schubert
2015796c8dcSSimon Schubert static int equiv_types (struct type *, struct type *);
2025796c8dcSSimon Schubert
2035796c8dcSSimon Schubert static int is_name_suffix (const char *);
2045796c8dcSSimon Schubert
205c50c785cSJohn Marino static int advance_wild_match (const char **, const char *, int);
206c50c785cSJohn Marino
207c50c785cSJohn Marino static int wild_match (const char *, const char *);
2085796c8dcSSimon Schubert
2095796c8dcSSimon Schubert static struct value *ada_coerce_ref (struct value *);
2105796c8dcSSimon Schubert
2115796c8dcSSimon Schubert static LONGEST pos_atr (struct value *);
2125796c8dcSSimon Schubert
2135796c8dcSSimon Schubert static struct value *value_pos_atr (struct type *, struct value *);
2145796c8dcSSimon Schubert
2155796c8dcSSimon Schubert static struct value *value_val_atr (struct type *, struct value *);
2165796c8dcSSimon Schubert
2175796c8dcSSimon Schubert static struct symbol *standard_lookup (const char *, const struct block *,
2185796c8dcSSimon Schubert domain_enum);
2195796c8dcSSimon Schubert
2205796c8dcSSimon Schubert static struct value *ada_search_struct_field (char *, struct value *, int,
2215796c8dcSSimon Schubert struct type *);
2225796c8dcSSimon Schubert
2235796c8dcSSimon Schubert static struct value *ada_value_primitive_field (struct value *, int, int,
2245796c8dcSSimon Schubert struct type *);
2255796c8dcSSimon Schubert
226*ef5ccd6cSJohn Marino static int find_struct_field (const char *, struct type *, int,
2275796c8dcSSimon Schubert struct type **, int *, int *, int *, int *);
2285796c8dcSSimon Schubert
2295796c8dcSSimon Schubert static struct value *ada_to_fixed_value_create (struct type *, CORE_ADDR,
2305796c8dcSSimon Schubert struct value *);
2315796c8dcSSimon Schubert
2325796c8dcSSimon Schubert static int ada_resolve_function (struct ada_symbol_info *, int,
2335796c8dcSSimon Schubert struct value **, int, const char *,
2345796c8dcSSimon Schubert struct type *);
2355796c8dcSSimon Schubert
2365796c8dcSSimon Schubert static int ada_is_direct_array_type (struct type *);
2375796c8dcSSimon Schubert
2385796c8dcSSimon Schubert static void ada_language_arch_info (struct gdbarch *,
2395796c8dcSSimon Schubert struct language_arch_info *);
2405796c8dcSSimon Schubert
2415796c8dcSSimon Schubert static void check_size (const struct type *);
2425796c8dcSSimon Schubert
2435796c8dcSSimon Schubert static struct value *ada_index_struct_field (int, struct value *, int,
2445796c8dcSSimon Schubert struct type *);
2455796c8dcSSimon Schubert
2465796c8dcSSimon Schubert static struct value *assign_aggregate (struct value *, struct value *,
247c50c785cSJohn Marino struct expression *,
248c50c785cSJohn Marino int *, enum noside);
2495796c8dcSSimon Schubert
2505796c8dcSSimon Schubert static void aggregate_assign_from_choices (struct value *, struct value *,
2515796c8dcSSimon Schubert struct expression *,
2525796c8dcSSimon Schubert int *, LONGEST *, int *,
2535796c8dcSSimon Schubert int, LONGEST, LONGEST);
2545796c8dcSSimon Schubert
2555796c8dcSSimon Schubert static void aggregate_assign_positional (struct value *, struct value *,
2565796c8dcSSimon Schubert struct expression *,
2575796c8dcSSimon Schubert int *, LONGEST *, int *, int,
2585796c8dcSSimon Schubert LONGEST, LONGEST);
2595796c8dcSSimon Schubert
2605796c8dcSSimon Schubert
2615796c8dcSSimon Schubert static void aggregate_assign_others (struct value *, struct value *,
2625796c8dcSSimon Schubert struct expression *,
2635796c8dcSSimon Schubert int *, LONGEST *, int, LONGEST, LONGEST);
2645796c8dcSSimon Schubert
2655796c8dcSSimon Schubert
2665796c8dcSSimon Schubert static void add_component_interval (LONGEST, LONGEST, LONGEST *, int *, int);
2675796c8dcSSimon Schubert
2685796c8dcSSimon Schubert
2695796c8dcSSimon Schubert static struct value *ada_evaluate_subexp (struct type *, struct expression *,
2705796c8dcSSimon Schubert int *, enum noside);
2715796c8dcSSimon Schubert
2725796c8dcSSimon Schubert static void ada_forward_operator_length (struct expression *, int, int *,
2735796c8dcSSimon Schubert int *);
274*ef5ccd6cSJohn Marino
275*ef5ccd6cSJohn Marino static struct type *ada_find_any_type (const char *name);
2765796c8dcSSimon Schubert
2775796c8dcSSimon Schubert
2785796c8dcSSimon Schubert
2795796c8dcSSimon Schubert /* Maximum-sized dynamic type. */
2805796c8dcSSimon Schubert static unsigned int varsize_limit;
2815796c8dcSSimon Schubert
2825796c8dcSSimon Schubert /* FIXME: brobecker/2003-09-17: No longer a const because it is
2835796c8dcSSimon Schubert returned by a function that does not return a const char *. */
2845796c8dcSSimon Schubert static char *ada_completer_word_break_characters =
2855796c8dcSSimon Schubert #ifdef VMS
2865796c8dcSSimon Schubert " \t\n!@#%^&*()+=|~`}{[]\";:?/,-";
2875796c8dcSSimon Schubert #else
2885796c8dcSSimon Schubert " \t\n!@#$%^&*()+=|~`}{[]\";:?/,-";
2895796c8dcSSimon Schubert #endif
2905796c8dcSSimon Schubert
2915796c8dcSSimon Schubert /* The name of the symbol to use to get the name of the main subprogram. */
2925796c8dcSSimon Schubert static const char ADA_MAIN_PROGRAM_SYMBOL_NAME[]
2935796c8dcSSimon Schubert = "__gnat_ada_main_program_name";
2945796c8dcSSimon Schubert
2955796c8dcSSimon Schubert /* Limit on the number of warnings to raise per expression evaluation. */
2965796c8dcSSimon Schubert static int warning_limit = 2;
2975796c8dcSSimon Schubert
2985796c8dcSSimon Schubert /* Number of warning messages issued; reset to 0 by cleanups after
2995796c8dcSSimon Schubert expression evaluation. */
3005796c8dcSSimon Schubert static int warnings_issued = 0;
3015796c8dcSSimon Schubert
3025796c8dcSSimon Schubert static const char *known_runtime_file_name_patterns[] = {
3035796c8dcSSimon Schubert ADA_KNOWN_RUNTIME_FILE_NAME_PATTERNS NULL
3045796c8dcSSimon Schubert };
3055796c8dcSSimon Schubert
3065796c8dcSSimon Schubert static const char *known_auxiliary_function_name_patterns[] = {
3075796c8dcSSimon Schubert ADA_KNOWN_AUXILIARY_FUNCTION_NAME_PATTERNS NULL
3085796c8dcSSimon Schubert };
3095796c8dcSSimon Schubert
3105796c8dcSSimon Schubert /* Space for allocating results of ada_lookup_symbol_list. */
3115796c8dcSSimon Schubert static struct obstack symbol_list_obstack;
3125796c8dcSSimon Schubert
313cf7f2e2dSJohn Marino /* Inferior-specific data. */
314cf7f2e2dSJohn Marino
315cf7f2e2dSJohn Marino /* Per-inferior data for this module. */
316cf7f2e2dSJohn Marino
317cf7f2e2dSJohn Marino struct ada_inferior_data
318cf7f2e2dSJohn Marino {
319cf7f2e2dSJohn Marino /* The ada__tags__type_specific_data type, which is used when decoding
320cf7f2e2dSJohn Marino tagged types. With older versions of GNAT, this type was directly
321cf7f2e2dSJohn Marino accessible through a component ("tsd") in the object tag. But this
322cf7f2e2dSJohn Marino is no longer the case, so we cache it for each inferior. */
323cf7f2e2dSJohn Marino struct type *tsd_type;
324a45ae5f8SJohn Marino
325a45ae5f8SJohn Marino /* The exception_support_info data. This data is used to determine
326a45ae5f8SJohn Marino how to implement support for Ada exception catchpoints in a given
327a45ae5f8SJohn Marino inferior. */
328a45ae5f8SJohn Marino const struct exception_support_info *exception_info;
329cf7f2e2dSJohn Marino };
330cf7f2e2dSJohn Marino
331cf7f2e2dSJohn Marino /* Our key to this module's inferior data. */
332cf7f2e2dSJohn Marino static const struct inferior_data *ada_inferior_data;
333cf7f2e2dSJohn Marino
334cf7f2e2dSJohn Marino /* A cleanup routine for our inferior data. */
335cf7f2e2dSJohn Marino static void
ada_inferior_data_cleanup(struct inferior * inf,void * arg)336cf7f2e2dSJohn Marino ada_inferior_data_cleanup (struct inferior *inf, void *arg)
337cf7f2e2dSJohn Marino {
338cf7f2e2dSJohn Marino struct ada_inferior_data *data;
339cf7f2e2dSJohn Marino
340cf7f2e2dSJohn Marino data = inferior_data (inf, ada_inferior_data);
341cf7f2e2dSJohn Marino if (data != NULL)
342cf7f2e2dSJohn Marino xfree (data);
343cf7f2e2dSJohn Marino }
344cf7f2e2dSJohn Marino
345cf7f2e2dSJohn Marino /* Return our inferior data for the given inferior (INF).
346cf7f2e2dSJohn Marino
347cf7f2e2dSJohn Marino This function always returns a valid pointer to an allocated
348cf7f2e2dSJohn Marino ada_inferior_data structure. If INF's inferior data has not
349cf7f2e2dSJohn Marino been previously set, this functions creates a new one with all
350cf7f2e2dSJohn Marino fields set to zero, sets INF's inferior to it, and then returns
351cf7f2e2dSJohn Marino a pointer to that newly allocated ada_inferior_data. */
352cf7f2e2dSJohn Marino
353cf7f2e2dSJohn Marino static struct ada_inferior_data *
get_ada_inferior_data(struct inferior * inf)354cf7f2e2dSJohn Marino get_ada_inferior_data (struct inferior *inf)
355cf7f2e2dSJohn Marino {
356cf7f2e2dSJohn Marino struct ada_inferior_data *data;
357cf7f2e2dSJohn Marino
358cf7f2e2dSJohn Marino data = inferior_data (inf, ada_inferior_data);
359cf7f2e2dSJohn Marino if (data == NULL)
360cf7f2e2dSJohn Marino {
361cf7f2e2dSJohn Marino data = XZALLOC (struct ada_inferior_data);
362cf7f2e2dSJohn Marino set_inferior_data (inf, ada_inferior_data, data);
363cf7f2e2dSJohn Marino }
364cf7f2e2dSJohn Marino
365cf7f2e2dSJohn Marino return data;
366cf7f2e2dSJohn Marino }
367cf7f2e2dSJohn Marino
368cf7f2e2dSJohn Marino /* Perform all necessary cleanups regarding our module's inferior data
369cf7f2e2dSJohn Marino that is required after the inferior INF just exited. */
370cf7f2e2dSJohn Marino
371cf7f2e2dSJohn Marino static void
ada_inferior_exit(struct inferior * inf)372cf7f2e2dSJohn Marino ada_inferior_exit (struct inferior *inf)
373cf7f2e2dSJohn Marino {
374cf7f2e2dSJohn Marino ada_inferior_data_cleanup (inf, NULL);
375cf7f2e2dSJohn Marino set_inferior_data (inf, ada_inferior_data, NULL);
376cf7f2e2dSJohn Marino }
377cf7f2e2dSJohn Marino
3785796c8dcSSimon Schubert /* Utilities */
3795796c8dcSSimon Schubert
380c50c785cSJohn Marino /* If TYPE is a TYPE_CODE_TYPEDEF type, return the target type after
381c50c785cSJohn Marino all typedef layers have been peeled. Otherwise, return TYPE.
382c50c785cSJohn Marino
383c50c785cSJohn Marino Normally, we really expect a typedef type to only have 1 typedef layer.
384c50c785cSJohn Marino In other words, we really expect the target type of a typedef type to be
385c50c785cSJohn Marino a non-typedef type. This is particularly true for Ada units, because
386c50c785cSJohn Marino the language does not have a typedef vs not-typedef distinction.
387c50c785cSJohn Marino In that respect, the Ada compiler has been trying to eliminate as many
388c50c785cSJohn Marino typedef definitions in the debugging information, since they generally
389c50c785cSJohn Marino do not bring any extra information (we still use typedef under certain
390c50c785cSJohn Marino circumstances related mostly to the GNAT encoding).
391c50c785cSJohn Marino
392c50c785cSJohn Marino Unfortunately, we have seen situations where the debugging information
393c50c785cSJohn Marino generated by the compiler leads to such multiple typedef layers. For
394c50c785cSJohn Marino instance, consider the following example with stabs:
395c50c785cSJohn Marino
396c50c785cSJohn Marino .stabs "pck__float_array___XUP:Tt(0,46)=s16P_ARRAY:(0,47)=[...]"[...]
397c50c785cSJohn Marino .stabs "pck__float_array___XUP:t(0,36)=(0,46)",128,0,6,0
398c50c785cSJohn Marino
399c50c785cSJohn Marino This is an error in the debugging information which causes type
400c50c785cSJohn Marino pck__float_array___XUP to be defined twice, and the second time,
401c50c785cSJohn Marino it is defined as a typedef of a typedef.
402c50c785cSJohn Marino
403c50c785cSJohn Marino This is on the fringe of legality as far as debugging information is
404c50c785cSJohn Marino concerned, and certainly unexpected. But it is easy to handle these
405c50c785cSJohn Marino situations correctly, so we can afford to be lenient in this case. */
406c50c785cSJohn Marino
407c50c785cSJohn Marino static struct type *
ada_typedef_target_type(struct type * type)408c50c785cSJohn Marino ada_typedef_target_type (struct type *type)
409c50c785cSJohn Marino {
410c50c785cSJohn Marino while (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
411c50c785cSJohn Marino type = TYPE_TARGET_TYPE (type);
412c50c785cSJohn Marino return type;
413c50c785cSJohn Marino }
414c50c785cSJohn Marino
4155796c8dcSSimon Schubert /* Given DECODED_NAME a string holding a symbol name in its
4165796c8dcSSimon Schubert decoded form (ie using the Ada dotted notation), returns
4175796c8dcSSimon Schubert its unqualified name. */
4185796c8dcSSimon Schubert
4195796c8dcSSimon Schubert static const char *
ada_unqualified_name(const char * decoded_name)4205796c8dcSSimon Schubert ada_unqualified_name (const char *decoded_name)
4215796c8dcSSimon Schubert {
4225796c8dcSSimon Schubert const char *result = strrchr (decoded_name, '.');
4235796c8dcSSimon Schubert
4245796c8dcSSimon Schubert if (result != NULL)
4255796c8dcSSimon Schubert result++; /* Skip the dot... */
4265796c8dcSSimon Schubert else
4275796c8dcSSimon Schubert result = decoded_name;
4285796c8dcSSimon Schubert
4295796c8dcSSimon Schubert return result;
4305796c8dcSSimon Schubert }
4315796c8dcSSimon Schubert
4325796c8dcSSimon Schubert /* Return a string starting with '<', followed by STR, and '>'.
4335796c8dcSSimon Schubert The result is good until the next call. */
4345796c8dcSSimon Schubert
4355796c8dcSSimon Schubert static char *
add_angle_brackets(const char * str)4365796c8dcSSimon Schubert add_angle_brackets (const char *str)
4375796c8dcSSimon Schubert {
4385796c8dcSSimon Schubert static char *result = NULL;
4395796c8dcSSimon Schubert
4405796c8dcSSimon Schubert xfree (result);
4415796c8dcSSimon Schubert result = xstrprintf ("<%s>", str);
4425796c8dcSSimon Schubert return result;
4435796c8dcSSimon Schubert }
4445796c8dcSSimon Schubert
4455796c8dcSSimon Schubert static char *
ada_get_gdb_completer_word_break_characters(void)4465796c8dcSSimon Schubert ada_get_gdb_completer_word_break_characters (void)
4475796c8dcSSimon Schubert {
4485796c8dcSSimon Schubert return ada_completer_word_break_characters;
4495796c8dcSSimon Schubert }
4505796c8dcSSimon Schubert
4515796c8dcSSimon Schubert /* Print an array element index using the Ada syntax. */
4525796c8dcSSimon Schubert
4535796c8dcSSimon Schubert static void
ada_print_array_index(struct value * index_value,struct ui_file * stream,const struct value_print_options * options)4545796c8dcSSimon Schubert ada_print_array_index (struct value *index_value, struct ui_file *stream,
4555796c8dcSSimon Schubert const struct value_print_options *options)
4565796c8dcSSimon Schubert {
4575796c8dcSSimon Schubert LA_VALUE_PRINT (index_value, stream, options);
4585796c8dcSSimon Schubert fprintf_filtered (stream, " => ");
4595796c8dcSSimon Schubert }
4605796c8dcSSimon Schubert
4615796c8dcSSimon Schubert /* Assuming VECT points to an array of *SIZE objects of size
4625796c8dcSSimon Schubert ELEMENT_SIZE, grow it to contain at least MIN_SIZE objects,
4635796c8dcSSimon Schubert updating *SIZE as necessary and returning the (new) array. */
4645796c8dcSSimon Schubert
4655796c8dcSSimon Schubert void *
grow_vect(void * vect,size_t * size,size_t min_size,int element_size)4665796c8dcSSimon Schubert grow_vect (void *vect, size_t *size, size_t min_size, int element_size)
4675796c8dcSSimon Schubert {
4685796c8dcSSimon Schubert if (*size < min_size)
4695796c8dcSSimon Schubert {
4705796c8dcSSimon Schubert *size *= 2;
4715796c8dcSSimon Schubert if (*size < min_size)
4725796c8dcSSimon Schubert *size = min_size;
4735796c8dcSSimon Schubert vect = xrealloc (vect, *size * element_size);
4745796c8dcSSimon Schubert }
4755796c8dcSSimon Schubert return vect;
4765796c8dcSSimon Schubert }
4775796c8dcSSimon Schubert
4785796c8dcSSimon Schubert /* True (non-zero) iff TARGET matches FIELD_NAME up to any trailing
4795796c8dcSSimon Schubert suffix of FIELD_NAME beginning "___". */
4805796c8dcSSimon Schubert
4815796c8dcSSimon Schubert static int
field_name_match(const char * field_name,const char * target)4825796c8dcSSimon Schubert field_name_match (const char *field_name, const char *target)
4835796c8dcSSimon Schubert {
4845796c8dcSSimon Schubert int len = strlen (target);
485cf7f2e2dSJohn Marino
4865796c8dcSSimon Schubert return
4875796c8dcSSimon Schubert (strncmp (field_name, target, len) == 0
4885796c8dcSSimon Schubert && (field_name[len] == '\0'
4895796c8dcSSimon Schubert || (strncmp (field_name + len, "___", 3) == 0
4905796c8dcSSimon Schubert && strcmp (field_name + strlen (field_name) - 6,
4915796c8dcSSimon Schubert "___XVN") != 0)));
4925796c8dcSSimon Schubert }
4935796c8dcSSimon Schubert
4945796c8dcSSimon Schubert
4955796c8dcSSimon Schubert /* Assuming TYPE is a TYPE_CODE_STRUCT or a TYPE_CODE_TYPDEF to
4965796c8dcSSimon Schubert a TYPE_CODE_STRUCT, find the field whose name matches FIELD_NAME,
4975796c8dcSSimon Schubert and return its index. This function also handles fields whose name
4985796c8dcSSimon Schubert have ___ suffixes because the compiler sometimes alters their name
4995796c8dcSSimon Schubert by adding such a suffix to represent fields with certain constraints.
5005796c8dcSSimon Schubert If the field could not be found, return a negative number if
5015796c8dcSSimon Schubert MAYBE_MISSING is set. Otherwise raise an error. */
5025796c8dcSSimon Schubert
5035796c8dcSSimon Schubert int
ada_get_field_index(const struct type * type,const char * field_name,int maybe_missing)5045796c8dcSSimon Schubert ada_get_field_index (const struct type *type, const char *field_name,
5055796c8dcSSimon Schubert int maybe_missing)
5065796c8dcSSimon Schubert {
5075796c8dcSSimon Schubert int fieldno;
5085796c8dcSSimon Schubert struct type *struct_type = check_typedef ((struct type *) type);
5095796c8dcSSimon Schubert
5105796c8dcSSimon Schubert for (fieldno = 0; fieldno < TYPE_NFIELDS (struct_type); fieldno++)
5115796c8dcSSimon Schubert if (field_name_match (TYPE_FIELD_NAME (struct_type, fieldno), field_name))
5125796c8dcSSimon Schubert return fieldno;
5135796c8dcSSimon Schubert
5145796c8dcSSimon Schubert if (!maybe_missing)
5155796c8dcSSimon Schubert error (_("Unable to find field %s in struct %s. Aborting"),
5165796c8dcSSimon Schubert field_name, TYPE_NAME (struct_type));
5175796c8dcSSimon Schubert
5185796c8dcSSimon Schubert return -1;
5195796c8dcSSimon Schubert }
5205796c8dcSSimon Schubert
5215796c8dcSSimon Schubert /* The length of the prefix of NAME prior to any "___" suffix. */
5225796c8dcSSimon Schubert
5235796c8dcSSimon Schubert int
ada_name_prefix_len(const char * name)5245796c8dcSSimon Schubert ada_name_prefix_len (const char *name)
5255796c8dcSSimon Schubert {
5265796c8dcSSimon Schubert if (name == NULL)
5275796c8dcSSimon Schubert return 0;
5285796c8dcSSimon Schubert else
5295796c8dcSSimon Schubert {
5305796c8dcSSimon Schubert const char *p = strstr (name, "___");
531cf7f2e2dSJohn Marino
5325796c8dcSSimon Schubert if (p == NULL)
5335796c8dcSSimon Schubert return strlen (name);
5345796c8dcSSimon Schubert else
5355796c8dcSSimon Schubert return p - name;
5365796c8dcSSimon Schubert }
5375796c8dcSSimon Schubert }
5385796c8dcSSimon Schubert
5395796c8dcSSimon Schubert /* Return non-zero if SUFFIX is a suffix of STR.
5405796c8dcSSimon Schubert Return zero if STR is null. */
5415796c8dcSSimon Schubert
5425796c8dcSSimon Schubert static int
is_suffix(const char * str,const char * suffix)5435796c8dcSSimon Schubert is_suffix (const char *str, const char *suffix)
5445796c8dcSSimon Schubert {
5455796c8dcSSimon Schubert int len1, len2;
546cf7f2e2dSJohn Marino
5475796c8dcSSimon Schubert if (str == NULL)
5485796c8dcSSimon Schubert return 0;
5495796c8dcSSimon Schubert len1 = strlen (str);
5505796c8dcSSimon Schubert len2 = strlen (suffix);
5515796c8dcSSimon Schubert return (len1 >= len2 && strcmp (str + len1 - len2, suffix) == 0);
5525796c8dcSSimon Schubert }
5535796c8dcSSimon Schubert
5545796c8dcSSimon Schubert /* The contents of value VAL, treated as a value of type TYPE. The
5555796c8dcSSimon Schubert result is an lval in memory if VAL is. */
5565796c8dcSSimon Schubert
5575796c8dcSSimon Schubert static struct value *
coerce_unspec_val_to_type(struct value * val,struct type * type)5585796c8dcSSimon Schubert coerce_unspec_val_to_type (struct value *val, struct type *type)
5595796c8dcSSimon Schubert {
5605796c8dcSSimon Schubert type = ada_check_typedef (type);
5615796c8dcSSimon Schubert if (value_type (val) == type)
5625796c8dcSSimon Schubert return val;
5635796c8dcSSimon Schubert else
5645796c8dcSSimon Schubert {
5655796c8dcSSimon Schubert struct value *result;
5665796c8dcSSimon Schubert
5675796c8dcSSimon Schubert /* Make sure that the object size is not unreasonable before
5685796c8dcSSimon Schubert trying to allocate some memory for it. */
5695796c8dcSSimon Schubert check_size (type);
5705796c8dcSSimon Schubert
571c50c785cSJohn Marino if (value_lazy (val)
572c50c785cSJohn Marino || TYPE_LENGTH (type) > TYPE_LENGTH (value_type (val)))
573c50c785cSJohn Marino result = allocate_value_lazy (type);
574c50c785cSJohn Marino else
575c50c785cSJohn Marino {
5765796c8dcSSimon Schubert result = allocate_value (type);
577c50c785cSJohn Marino memcpy (value_contents_raw (result), value_contents (val),
578c50c785cSJohn Marino TYPE_LENGTH (type));
579c50c785cSJohn Marino }
5805796c8dcSSimon Schubert set_value_component_location (result, val);
5815796c8dcSSimon Schubert set_value_bitsize (result, value_bitsize (val));
5825796c8dcSSimon Schubert set_value_bitpos (result, value_bitpos (val));
5835796c8dcSSimon Schubert set_value_address (result, value_address (val));
584*ef5ccd6cSJohn Marino set_value_optimized_out (result, value_optimized_out (val));
5855796c8dcSSimon Schubert return result;
5865796c8dcSSimon Schubert }
5875796c8dcSSimon Schubert }
5885796c8dcSSimon Schubert
5895796c8dcSSimon Schubert static const gdb_byte *
cond_offset_host(const gdb_byte * valaddr,long offset)5905796c8dcSSimon Schubert cond_offset_host (const gdb_byte *valaddr, long offset)
5915796c8dcSSimon Schubert {
5925796c8dcSSimon Schubert if (valaddr == NULL)
5935796c8dcSSimon Schubert return NULL;
5945796c8dcSSimon Schubert else
5955796c8dcSSimon Schubert return valaddr + offset;
5965796c8dcSSimon Schubert }
5975796c8dcSSimon Schubert
5985796c8dcSSimon Schubert static CORE_ADDR
cond_offset_target(CORE_ADDR address,long offset)5995796c8dcSSimon Schubert cond_offset_target (CORE_ADDR address, long offset)
6005796c8dcSSimon Schubert {
6015796c8dcSSimon Schubert if (address == 0)
6025796c8dcSSimon Schubert return 0;
6035796c8dcSSimon Schubert else
6045796c8dcSSimon Schubert return address + offset;
6055796c8dcSSimon Schubert }
6065796c8dcSSimon Schubert
6075796c8dcSSimon Schubert /* Issue a warning (as for the definition of warning in utils.c, but
6085796c8dcSSimon Schubert with exactly one argument rather than ...), unless the limit on the
6095796c8dcSSimon Schubert number of warnings has passed during the evaluation of the current
6105796c8dcSSimon Schubert expression. */
6115796c8dcSSimon Schubert
6125796c8dcSSimon Schubert /* FIXME: cagney/2004-10-10: This function is mimicking the behavior
6135796c8dcSSimon Schubert provided by "complaint". */
614cf7f2e2dSJohn Marino static void lim_warning (const char *format, ...) ATTRIBUTE_PRINTF (1, 2);
6155796c8dcSSimon Schubert
6165796c8dcSSimon Schubert static void
lim_warning(const char * format,...)6175796c8dcSSimon Schubert lim_warning (const char *format, ...)
6185796c8dcSSimon Schubert {
6195796c8dcSSimon Schubert va_list args;
6205796c8dcSSimon Schubert
621cf7f2e2dSJohn Marino va_start (args, format);
6225796c8dcSSimon Schubert warnings_issued += 1;
6235796c8dcSSimon Schubert if (warnings_issued <= warning_limit)
6245796c8dcSSimon Schubert vwarning (format, args);
6255796c8dcSSimon Schubert
6265796c8dcSSimon Schubert va_end (args);
6275796c8dcSSimon Schubert }
6285796c8dcSSimon Schubert
6295796c8dcSSimon Schubert /* Issue an error if the size of an object of type T is unreasonable,
6305796c8dcSSimon Schubert i.e. if it would be a bad idea to allocate a value of this type in
6315796c8dcSSimon Schubert GDB. */
6325796c8dcSSimon Schubert
6335796c8dcSSimon Schubert static void
check_size(const struct type * type)6345796c8dcSSimon Schubert check_size (const struct type *type)
6355796c8dcSSimon Schubert {
6365796c8dcSSimon Schubert if (TYPE_LENGTH (type) > varsize_limit)
6375796c8dcSSimon Schubert error (_("object size is larger than varsize-limit"));
6385796c8dcSSimon Schubert }
6395796c8dcSSimon Schubert
6405796c8dcSSimon Schubert /* Maximum value of a SIZE-byte signed integer type. */
6415796c8dcSSimon Schubert static LONGEST
max_of_size(int size)6425796c8dcSSimon Schubert max_of_size (int size)
6435796c8dcSSimon Schubert {
6445796c8dcSSimon Schubert LONGEST top_bit = (LONGEST) 1 << (size * 8 - 2);
645cf7f2e2dSJohn Marino
6465796c8dcSSimon Schubert return top_bit | (top_bit - 1);
6475796c8dcSSimon Schubert }
6485796c8dcSSimon Schubert
6495796c8dcSSimon Schubert /* Minimum value of a SIZE-byte signed integer type. */
6505796c8dcSSimon Schubert static LONGEST
min_of_size(int size)6515796c8dcSSimon Schubert min_of_size (int size)
6525796c8dcSSimon Schubert {
6535796c8dcSSimon Schubert return -max_of_size (size) - 1;
6545796c8dcSSimon Schubert }
6555796c8dcSSimon Schubert
6565796c8dcSSimon Schubert /* Maximum value of a SIZE-byte unsigned integer type. */
6575796c8dcSSimon Schubert static ULONGEST
umax_of_size(int size)6585796c8dcSSimon Schubert umax_of_size (int size)
6595796c8dcSSimon Schubert {
6605796c8dcSSimon Schubert ULONGEST top_bit = (ULONGEST) 1 << (size * 8 - 1);
661cf7f2e2dSJohn Marino
6625796c8dcSSimon Schubert return top_bit | (top_bit - 1);
6635796c8dcSSimon Schubert }
6645796c8dcSSimon Schubert
6655796c8dcSSimon Schubert /* Maximum value of integral type T, as a signed quantity. */
6665796c8dcSSimon Schubert static LONGEST
max_of_type(struct type * t)6675796c8dcSSimon Schubert max_of_type (struct type *t)
6685796c8dcSSimon Schubert {
6695796c8dcSSimon Schubert if (TYPE_UNSIGNED (t))
6705796c8dcSSimon Schubert return (LONGEST) umax_of_size (TYPE_LENGTH (t));
6715796c8dcSSimon Schubert else
6725796c8dcSSimon Schubert return max_of_size (TYPE_LENGTH (t));
6735796c8dcSSimon Schubert }
6745796c8dcSSimon Schubert
6755796c8dcSSimon Schubert /* Minimum value of integral type T, as a signed quantity. */
6765796c8dcSSimon Schubert static LONGEST
min_of_type(struct type * t)6775796c8dcSSimon Schubert min_of_type (struct type *t)
6785796c8dcSSimon Schubert {
6795796c8dcSSimon Schubert if (TYPE_UNSIGNED (t))
6805796c8dcSSimon Schubert return 0;
6815796c8dcSSimon Schubert else
6825796c8dcSSimon Schubert return min_of_size (TYPE_LENGTH (t));
6835796c8dcSSimon Schubert }
6845796c8dcSSimon Schubert
6855796c8dcSSimon Schubert /* The largest value in the domain of TYPE, a discrete type, as an integer. */
686cf7f2e2dSJohn Marino LONGEST
ada_discrete_type_high_bound(struct type * type)687cf7f2e2dSJohn Marino ada_discrete_type_high_bound (struct type *type)
6885796c8dcSSimon Schubert {
6895796c8dcSSimon Schubert switch (TYPE_CODE (type))
6905796c8dcSSimon Schubert {
6915796c8dcSSimon Schubert case TYPE_CODE_RANGE:
6925796c8dcSSimon Schubert return TYPE_HIGH_BOUND (type);
6935796c8dcSSimon Schubert case TYPE_CODE_ENUM:
694*ef5ccd6cSJohn Marino return TYPE_FIELD_ENUMVAL (type, TYPE_NFIELDS (type) - 1);
6955796c8dcSSimon Schubert case TYPE_CODE_BOOL:
6965796c8dcSSimon Schubert return 1;
6975796c8dcSSimon Schubert case TYPE_CODE_CHAR:
6985796c8dcSSimon Schubert case TYPE_CODE_INT:
6995796c8dcSSimon Schubert return max_of_type (type);
7005796c8dcSSimon Schubert default:
701cf7f2e2dSJohn Marino error (_("Unexpected type in ada_discrete_type_high_bound."));
7025796c8dcSSimon Schubert }
7035796c8dcSSimon Schubert }
7045796c8dcSSimon Schubert
705*ef5ccd6cSJohn Marino /* The smallest value in the domain of TYPE, a discrete type, as an integer. */
706cf7f2e2dSJohn Marino LONGEST
ada_discrete_type_low_bound(struct type * type)707cf7f2e2dSJohn Marino ada_discrete_type_low_bound (struct type *type)
7085796c8dcSSimon Schubert {
7095796c8dcSSimon Schubert switch (TYPE_CODE (type))
7105796c8dcSSimon Schubert {
7115796c8dcSSimon Schubert case TYPE_CODE_RANGE:
7125796c8dcSSimon Schubert return TYPE_LOW_BOUND (type);
7135796c8dcSSimon Schubert case TYPE_CODE_ENUM:
714*ef5ccd6cSJohn Marino return TYPE_FIELD_ENUMVAL (type, 0);
7155796c8dcSSimon Schubert case TYPE_CODE_BOOL:
7165796c8dcSSimon Schubert return 0;
7175796c8dcSSimon Schubert case TYPE_CODE_CHAR:
7185796c8dcSSimon Schubert case TYPE_CODE_INT:
7195796c8dcSSimon Schubert return min_of_type (type);
7205796c8dcSSimon Schubert default:
721cf7f2e2dSJohn Marino error (_("Unexpected type in ada_discrete_type_low_bound."));
7225796c8dcSSimon Schubert }
7235796c8dcSSimon Schubert }
7245796c8dcSSimon Schubert
7255796c8dcSSimon Schubert /* The identity on non-range types. For range types, the underlying
7265796c8dcSSimon Schubert non-range scalar type. */
7275796c8dcSSimon Schubert
7285796c8dcSSimon Schubert static struct type *
get_base_type(struct type * type)729a45ae5f8SJohn Marino get_base_type (struct type *type)
7305796c8dcSSimon Schubert {
7315796c8dcSSimon Schubert while (type != NULL && TYPE_CODE (type) == TYPE_CODE_RANGE)
7325796c8dcSSimon Schubert {
7335796c8dcSSimon Schubert if (type == TYPE_TARGET_TYPE (type) || TYPE_TARGET_TYPE (type) == NULL)
7345796c8dcSSimon Schubert return type;
7355796c8dcSSimon Schubert type = TYPE_TARGET_TYPE (type);
7365796c8dcSSimon Schubert }
7375796c8dcSSimon Schubert return type;
7385796c8dcSSimon Schubert }
739*ef5ccd6cSJohn Marino
740*ef5ccd6cSJohn Marino /* Return a decoded version of the given VALUE. This means returning
741*ef5ccd6cSJohn Marino a value whose type is obtained by applying all the GNAT-specific
742*ef5ccd6cSJohn Marino encondings, making the resulting type a static but standard description
743*ef5ccd6cSJohn Marino of the initial type. */
744*ef5ccd6cSJohn Marino
745*ef5ccd6cSJohn Marino struct value *
ada_get_decoded_value(struct value * value)746*ef5ccd6cSJohn Marino ada_get_decoded_value (struct value *value)
747*ef5ccd6cSJohn Marino {
748*ef5ccd6cSJohn Marino struct type *type = ada_check_typedef (value_type (value));
749*ef5ccd6cSJohn Marino
750*ef5ccd6cSJohn Marino if (ada_is_array_descriptor_type (type)
751*ef5ccd6cSJohn Marino || (ada_is_constrained_packed_array_type (type)
752*ef5ccd6cSJohn Marino && TYPE_CODE (type) != TYPE_CODE_PTR))
753*ef5ccd6cSJohn Marino {
754*ef5ccd6cSJohn Marino if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF) /* array access type. */
755*ef5ccd6cSJohn Marino value = ada_coerce_to_simple_array_ptr (value);
756*ef5ccd6cSJohn Marino else
757*ef5ccd6cSJohn Marino value = ada_coerce_to_simple_array (value);
758*ef5ccd6cSJohn Marino }
759*ef5ccd6cSJohn Marino else
760*ef5ccd6cSJohn Marino value = ada_to_fixed_value (value);
761*ef5ccd6cSJohn Marino
762*ef5ccd6cSJohn Marino return value;
763*ef5ccd6cSJohn Marino }
764*ef5ccd6cSJohn Marino
765*ef5ccd6cSJohn Marino /* Same as ada_get_decoded_value, but with the given TYPE.
766*ef5ccd6cSJohn Marino Because there is no associated actual value for this type,
767*ef5ccd6cSJohn Marino the resulting type might be a best-effort approximation in
768*ef5ccd6cSJohn Marino the case of dynamic types. */
769*ef5ccd6cSJohn Marino
770*ef5ccd6cSJohn Marino struct type *
ada_get_decoded_type(struct type * type)771*ef5ccd6cSJohn Marino ada_get_decoded_type (struct type *type)
772*ef5ccd6cSJohn Marino {
773*ef5ccd6cSJohn Marino type = to_static_fixed_type (type);
774*ef5ccd6cSJohn Marino if (ada_is_constrained_packed_array_type (type))
775*ef5ccd6cSJohn Marino type = ada_coerce_to_simple_array_type (type);
776*ef5ccd6cSJohn Marino return type;
777*ef5ccd6cSJohn Marino }
778*ef5ccd6cSJohn Marino
7795796c8dcSSimon Schubert
7805796c8dcSSimon Schubert
7815796c8dcSSimon Schubert /* Language Selection */
7825796c8dcSSimon Schubert
7835796c8dcSSimon Schubert /* If the main program is in Ada, return language_ada, otherwise return LANG
784cf7f2e2dSJohn Marino (the main program is in Ada iif the adainit symbol is found). */
7855796c8dcSSimon Schubert
7865796c8dcSSimon Schubert enum language
ada_update_initial_language(enum language lang)787cf7f2e2dSJohn Marino ada_update_initial_language (enum language lang)
7885796c8dcSSimon Schubert {
7895796c8dcSSimon Schubert if (lookup_minimal_symbol ("adainit", (const char *) NULL,
7905796c8dcSSimon Schubert (struct objfile *) NULL) != NULL)
7915796c8dcSSimon Schubert return language_ada;
7925796c8dcSSimon Schubert
7935796c8dcSSimon Schubert return lang;
7945796c8dcSSimon Schubert }
7955796c8dcSSimon Schubert
7965796c8dcSSimon Schubert /* If the main procedure is written in Ada, then return its name.
7975796c8dcSSimon Schubert The result is good until the next call. Return NULL if the main
7985796c8dcSSimon Schubert procedure doesn't appear to be in Ada. */
7995796c8dcSSimon Schubert
8005796c8dcSSimon Schubert char *
ada_main_name(void)8015796c8dcSSimon Schubert ada_main_name (void)
8025796c8dcSSimon Schubert {
8035796c8dcSSimon Schubert struct minimal_symbol *msym;
8045796c8dcSSimon Schubert static char *main_program_name = NULL;
8055796c8dcSSimon Schubert
8065796c8dcSSimon Schubert /* For Ada, the name of the main procedure is stored in a specific
8075796c8dcSSimon Schubert string constant, generated by the binder. Look for that symbol,
8085796c8dcSSimon Schubert extract its address, and then read that string. If we didn't find
8095796c8dcSSimon Schubert that string, then most probably the main procedure is not written
8105796c8dcSSimon Schubert in Ada. */
8115796c8dcSSimon Schubert msym = lookup_minimal_symbol (ADA_MAIN_PROGRAM_SYMBOL_NAME, NULL, NULL);
8125796c8dcSSimon Schubert
8135796c8dcSSimon Schubert if (msym != NULL)
8145796c8dcSSimon Schubert {
8155796c8dcSSimon Schubert CORE_ADDR main_program_name_addr;
8165796c8dcSSimon Schubert int err_code;
8175796c8dcSSimon Schubert
8185796c8dcSSimon Schubert main_program_name_addr = SYMBOL_VALUE_ADDRESS (msym);
8195796c8dcSSimon Schubert if (main_program_name_addr == 0)
8205796c8dcSSimon Schubert error (_("Invalid address for Ada main program name."));
8215796c8dcSSimon Schubert
8225796c8dcSSimon Schubert xfree (main_program_name);
8235796c8dcSSimon Schubert target_read_string (main_program_name_addr, &main_program_name,
8245796c8dcSSimon Schubert 1024, &err_code);
8255796c8dcSSimon Schubert
8265796c8dcSSimon Schubert if (err_code != 0)
8275796c8dcSSimon Schubert return NULL;
8285796c8dcSSimon Schubert return main_program_name;
8295796c8dcSSimon Schubert }
8305796c8dcSSimon Schubert
8315796c8dcSSimon Schubert /* The main procedure doesn't seem to be in Ada. */
8325796c8dcSSimon Schubert return NULL;
8335796c8dcSSimon Schubert }
8345796c8dcSSimon Schubert
8355796c8dcSSimon Schubert /* Symbols */
8365796c8dcSSimon Schubert
8375796c8dcSSimon Schubert /* Table of Ada operators and their GNAT-encoded names. Last entry is pair
8385796c8dcSSimon Schubert of NULLs. */
8395796c8dcSSimon Schubert
8405796c8dcSSimon Schubert const struct ada_opname_map ada_opname_table[] = {
8415796c8dcSSimon Schubert {"Oadd", "\"+\"", BINOP_ADD},
8425796c8dcSSimon Schubert {"Osubtract", "\"-\"", BINOP_SUB},
8435796c8dcSSimon Schubert {"Omultiply", "\"*\"", BINOP_MUL},
8445796c8dcSSimon Schubert {"Odivide", "\"/\"", BINOP_DIV},
8455796c8dcSSimon Schubert {"Omod", "\"mod\"", BINOP_MOD},
8465796c8dcSSimon Schubert {"Orem", "\"rem\"", BINOP_REM},
8475796c8dcSSimon Schubert {"Oexpon", "\"**\"", BINOP_EXP},
8485796c8dcSSimon Schubert {"Olt", "\"<\"", BINOP_LESS},
8495796c8dcSSimon Schubert {"Ole", "\"<=\"", BINOP_LEQ},
8505796c8dcSSimon Schubert {"Ogt", "\">\"", BINOP_GTR},
8515796c8dcSSimon Schubert {"Oge", "\">=\"", BINOP_GEQ},
8525796c8dcSSimon Schubert {"Oeq", "\"=\"", BINOP_EQUAL},
8535796c8dcSSimon Schubert {"One", "\"/=\"", BINOP_NOTEQUAL},
8545796c8dcSSimon Schubert {"Oand", "\"and\"", BINOP_BITWISE_AND},
8555796c8dcSSimon Schubert {"Oor", "\"or\"", BINOP_BITWISE_IOR},
8565796c8dcSSimon Schubert {"Oxor", "\"xor\"", BINOP_BITWISE_XOR},
8575796c8dcSSimon Schubert {"Oconcat", "\"&\"", BINOP_CONCAT},
8585796c8dcSSimon Schubert {"Oabs", "\"abs\"", UNOP_ABS},
8595796c8dcSSimon Schubert {"Onot", "\"not\"", UNOP_LOGICAL_NOT},
8605796c8dcSSimon Schubert {"Oadd", "\"+\"", UNOP_PLUS},
8615796c8dcSSimon Schubert {"Osubtract", "\"-\"", UNOP_NEG},
8625796c8dcSSimon Schubert {NULL, NULL}
8635796c8dcSSimon Schubert };
8645796c8dcSSimon Schubert
8655796c8dcSSimon Schubert /* The "encoded" form of DECODED, according to GNAT conventions.
8665796c8dcSSimon Schubert The result is valid until the next call to ada_encode. */
8675796c8dcSSimon Schubert
8685796c8dcSSimon Schubert char *
ada_encode(const char * decoded)8695796c8dcSSimon Schubert ada_encode (const char *decoded)
8705796c8dcSSimon Schubert {
8715796c8dcSSimon Schubert static char *encoding_buffer = NULL;
8725796c8dcSSimon Schubert static size_t encoding_buffer_size = 0;
8735796c8dcSSimon Schubert const char *p;
8745796c8dcSSimon Schubert int k;
8755796c8dcSSimon Schubert
8765796c8dcSSimon Schubert if (decoded == NULL)
8775796c8dcSSimon Schubert return NULL;
8785796c8dcSSimon Schubert
8795796c8dcSSimon Schubert GROW_VECT (encoding_buffer, encoding_buffer_size,
8805796c8dcSSimon Schubert 2 * strlen (decoded) + 10);
8815796c8dcSSimon Schubert
8825796c8dcSSimon Schubert k = 0;
8835796c8dcSSimon Schubert for (p = decoded; *p != '\0'; p += 1)
8845796c8dcSSimon Schubert {
8855796c8dcSSimon Schubert if (*p == '.')
8865796c8dcSSimon Schubert {
8875796c8dcSSimon Schubert encoding_buffer[k] = encoding_buffer[k + 1] = '_';
8885796c8dcSSimon Schubert k += 2;
8895796c8dcSSimon Schubert }
8905796c8dcSSimon Schubert else if (*p == '"')
8915796c8dcSSimon Schubert {
8925796c8dcSSimon Schubert const struct ada_opname_map *mapping;
8935796c8dcSSimon Schubert
8945796c8dcSSimon Schubert for (mapping = ada_opname_table;
8955796c8dcSSimon Schubert mapping->encoded != NULL
8965796c8dcSSimon Schubert && strncmp (mapping->decoded, p,
8975796c8dcSSimon Schubert strlen (mapping->decoded)) != 0; mapping += 1)
8985796c8dcSSimon Schubert ;
8995796c8dcSSimon Schubert if (mapping->encoded == NULL)
9005796c8dcSSimon Schubert error (_("invalid Ada operator name: %s"), p);
9015796c8dcSSimon Schubert strcpy (encoding_buffer + k, mapping->encoded);
9025796c8dcSSimon Schubert k += strlen (mapping->encoded);
9035796c8dcSSimon Schubert break;
9045796c8dcSSimon Schubert }
9055796c8dcSSimon Schubert else
9065796c8dcSSimon Schubert {
9075796c8dcSSimon Schubert encoding_buffer[k] = *p;
9085796c8dcSSimon Schubert k += 1;
9095796c8dcSSimon Schubert }
9105796c8dcSSimon Schubert }
9115796c8dcSSimon Schubert
9125796c8dcSSimon Schubert encoding_buffer[k] = '\0';
9135796c8dcSSimon Schubert return encoding_buffer;
9145796c8dcSSimon Schubert }
9155796c8dcSSimon Schubert
9165796c8dcSSimon Schubert /* Return NAME folded to lower case, or, if surrounded by single
9175796c8dcSSimon Schubert quotes, unfolded, but with the quotes stripped away. Result good
9185796c8dcSSimon Schubert to next call. */
9195796c8dcSSimon Schubert
9205796c8dcSSimon Schubert char *
ada_fold_name(const char * name)9215796c8dcSSimon Schubert ada_fold_name (const char *name)
9225796c8dcSSimon Schubert {
9235796c8dcSSimon Schubert static char *fold_buffer = NULL;
9245796c8dcSSimon Schubert static size_t fold_buffer_size = 0;
9255796c8dcSSimon Schubert
9265796c8dcSSimon Schubert int len = strlen (name);
9275796c8dcSSimon Schubert GROW_VECT (fold_buffer, fold_buffer_size, len + 1);
9285796c8dcSSimon Schubert
9295796c8dcSSimon Schubert if (name[0] == '\'')
9305796c8dcSSimon Schubert {
9315796c8dcSSimon Schubert strncpy (fold_buffer, name + 1, len - 2);
9325796c8dcSSimon Schubert fold_buffer[len - 2] = '\000';
9335796c8dcSSimon Schubert }
9345796c8dcSSimon Schubert else
9355796c8dcSSimon Schubert {
9365796c8dcSSimon Schubert int i;
937cf7f2e2dSJohn Marino
9385796c8dcSSimon Schubert for (i = 0; i <= len; i += 1)
9395796c8dcSSimon Schubert fold_buffer[i] = tolower (name[i]);
9405796c8dcSSimon Schubert }
9415796c8dcSSimon Schubert
9425796c8dcSSimon Schubert return fold_buffer;
9435796c8dcSSimon Schubert }
9445796c8dcSSimon Schubert
9455796c8dcSSimon Schubert /* Return nonzero if C is either a digit or a lowercase alphabet character. */
9465796c8dcSSimon Schubert
9475796c8dcSSimon Schubert static int
is_lower_alphanum(const char c)9485796c8dcSSimon Schubert is_lower_alphanum (const char c)
9495796c8dcSSimon Schubert {
9505796c8dcSSimon Schubert return (isdigit (c) || (isalpha (c) && islower (c)));
9515796c8dcSSimon Schubert }
9525796c8dcSSimon Schubert
953a45ae5f8SJohn Marino /* ENCODED is the linkage name of a symbol and LEN contains its length.
954a45ae5f8SJohn Marino This function saves in LEN the length of that same symbol name but
955a45ae5f8SJohn Marino without either of these suffixes:
9565796c8dcSSimon Schubert . .{DIGIT}+
9575796c8dcSSimon Schubert . ${DIGIT}+
9585796c8dcSSimon Schubert . ___{DIGIT}+
9595796c8dcSSimon Schubert . __{DIGIT}+.
960a45ae5f8SJohn Marino
9615796c8dcSSimon Schubert These are suffixes introduced by the compiler for entities such as
9625796c8dcSSimon Schubert nested subprogram for instance, in order to avoid name clashes.
9635796c8dcSSimon Schubert They do not serve any purpose for the debugger. */
9645796c8dcSSimon Schubert
9655796c8dcSSimon Schubert static void
ada_remove_trailing_digits(const char * encoded,int * len)9665796c8dcSSimon Schubert ada_remove_trailing_digits (const char *encoded, int *len)
9675796c8dcSSimon Schubert {
9685796c8dcSSimon Schubert if (*len > 1 && isdigit (encoded[*len - 1]))
9695796c8dcSSimon Schubert {
9705796c8dcSSimon Schubert int i = *len - 2;
971cf7f2e2dSJohn Marino
9725796c8dcSSimon Schubert while (i > 0 && isdigit (encoded[i]))
9735796c8dcSSimon Schubert i--;
9745796c8dcSSimon Schubert if (i >= 0 && encoded[i] == '.')
9755796c8dcSSimon Schubert *len = i;
9765796c8dcSSimon Schubert else if (i >= 0 && encoded[i] == '$')
9775796c8dcSSimon Schubert *len = i;
9785796c8dcSSimon Schubert else if (i >= 2 && strncmp (encoded + i - 2, "___", 3) == 0)
9795796c8dcSSimon Schubert *len = i - 2;
9805796c8dcSSimon Schubert else if (i >= 1 && strncmp (encoded + i - 1, "__", 2) == 0)
9815796c8dcSSimon Schubert *len = i - 1;
9825796c8dcSSimon Schubert }
9835796c8dcSSimon Schubert }
9845796c8dcSSimon Schubert
9855796c8dcSSimon Schubert /* Remove the suffix introduced by the compiler for protected object
9865796c8dcSSimon Schubert subprograms. */
9875796c8dcSSimon Schubert
9885796c8dcSSimon Schubert static void
ada_remove_po_subprogram_suffix(const char * encoded,int * len)9895796c8dcSSimon Schubert ada_remove_po_subprogram_suffix (const char *encoded, int *len)
9905796c8dcSSimon Schubert {
9915796c8dcSSimon Schubert /* Remove trailing N. */
9925796c8dcSSimon Schubert
9935796c8dcSSimon Schubert /* Protected entry subprograms are broken into two
9945796c8dcSSimon Schubert separate subprograms: The first one is unprotected, and has
9955796c8dcSSimon Schubert a 'N' suffix; the second is the protected version, and has
9965796c8dcSSimon Schubert the 'P' suffix. The second calls the first one after handling
9975796c8dcSSimon Schubert the protection. Since the P subprograms are internally generated,
9985796c8dcSSimon Schubert we leave these names undecoded, giving the user a clue that this
9995796c8dcSSimon Schubert entity is internal. */
10005796c8dcSSimon Schubert
10015796c8dcSSimon Schubert if (*len > 1
10025796c8dcSSimon Schubert && encoded[*len - 1] == 'N'
10035796c8dcSSimon Schubert && (isdigit (encoded[*len - 2]) || islower (encoded[*len - 2])))
10045796c8dcSSimon Schubert *len = *len - 1;
10055796c8dcSSimon Schubert }
10065796c8dcSSimon Schubert
1007cf7f2e2dSJohn Marino /* Remove trailing X[bn]* suffixes (indicating names in package bodies). */
1008cf7f2e2dSJohn Marino
1009cf7f2e2dSJohn Marino static void
ada_remove_Xbn_suffix(const char * encoded,int * len)1010cf7f2e2dSJohn Marino ada_remove_Xbn_suffix (const char *encoded, int *len)
1011cf7f2e2dSJohn Marino {
1012cf7f2e2dSJohn Marino int i = *len - 1;
1013cf7f2e2dSJohn Marino
1014cf7f2e2dSJohn Marino while (i > 0 && (encoded[i] == 'b' || encoded[i] == 'n'))
1015cf7f2e2dSJohn Marino i--;
1016cf7f2e2dSJohn Marino
1017cf7f2e2dSJohn Marino if (encoded[i] != 'X')
1018cf7f2e2dSJohn Marino return;
1019cf7f2e2dSJohn Marino
1020cf7f2e2dSJohn Marino if (i == 0)
1021cf7f2e2dSJohn Marino return;
1022cf7f2e2dSJohn Marino
1023cf7f2e2dSJohn Marino if (isalnum (encoded[i-1]))
1024cf7f2e2dSJohn Marino *len = i;
1025cf7f2e2dSJohn Marino }
1026cf7f2e2dSJohn Marino
10275796c8dcSSimon Schubert /* If ENCODED follows the GNAT entity encoding conventions, then return
10285796c8dcSSimon Schubert the decoded form of ENCODED. Otherwise, return "<%s>" where "%s" is
10295796c8dcSSimon Schubert replaced by ENCODED.
10305796c8dcSSimon Schubert
10315796c8dcSSimon Schubert The resulting string is valid until the next call of ada_decode.
10325796c8dcSSimon Schubert If the string is unchanged by decoding, the original string pointer
10335796c8dcSSimon Schubert is returned. */
10345796c8dcSSimon Schubert
10355796c8dcSSimon Schubert const char *
ada_decode(const char * encoded)10365796c8dcSSimon Schubert ada_decode (const char *encoded)
10375796c8dcSSimon Schubert {
10385796c8dcSSimon Schubert int i, j;
10395796c8dcSSimon Schubert int len0;
10405796c8dcSSimon Schubert const char *p;
10415796c8dcSSimon Schubert char *decoded;
10425796c8dcSSimon Schubert int at_start_name;
10435796c8dcSSimon Schubert static char *decoding_buffer = NULL;
10445796c8dcSSimon Schubert static size_t decoding_buffer_size = 0;
10455796c8dcSSimon Schubert
10465796c8dcSSimon Schubert /* The name of the Ada main procedure starts with "_ada_".
10475796c8dcSSimon Schubert This prefix is not part of the decoded name, so skip this part
10485796c8dcSSimon Schubert if we see this prefix. */
10495796c8dcSSimon Schubert if (strncmp (encoded, "_ada_", 5) == 0)
10505796c8dcSSimon Schubert encoded += 5;
10515796c8dcSSimon Schubert
10525796c8dcSSimon Schubert /* If the name starts with '_', then it is not a properly encoded
10535796c8dcSSimon Schubert name, so do not attempt to decode it. Similarly, if the name
10545796c8dcSSimon Schubert starts with '<', the name should not be decoded. */
10555796c8dcSSimon Schubert if (encoded[0] == '_' || encoded[0] == '<')
10565796c8dcSSimon Schubert goto Suppress;
10575796c8dcSSimon Schubert
10585796c8dcSSimon Schubert len0 = strlen (encoded);
10595796c8dcSSimon Schubert
10605796c8dcSSimon Schubert ada_remove_trailing_digits (encoded, &len0);
10615796c8dcSSimon Schubert ada_remove_po_subprogram_suffix (encoded, &len0);
10625796c8dcSSimon Schubert
10635796c8dcSSimon Schubert /* Remove the ___X.* suffix if present. Do not forget to verify that
10645796c8dcSSimon Schubert the suffix is located before the current "end" of ENCODED. We want
10655796c8dcSSimon Schubert to avoid re-matching parts of ENCODED that have previously been
10665796c8dcSSimon Schubert marked as discarded (by decrementing LEN0). */
10675796c8dcSSimon Schubert p = strstr (encoded, "___");
10685796c8dcSSimon Schubert if (p != NULL && p - encoded < len0 - 3)
10695796c8dcSSimon Schubert {
10705796c8dcSSimon Schubert if (p[3] == 'X')
10715796c8dcSSimon Schubert len0 = p - encoded;
10725796c8dcSSimon Schubert else
10735796c8dcSSimon Schubert goto Suppress;
10745796c8dcSSimon Schubert }
10755796c8dcSSimon Schubert
10765796c8dcSSimon Schubert /* Remove any trailing TKB suffix. It tells us that this symbol
10775796c8dcSSimon Schubert is for the body of a task, but that information does not actually
10785796c8dcSSimon Schubert appear in the decoded name. */
10795796c8dcSSimon Schubert
10805796c8dcSSimon Schubert if (len0 > 3 && strncmp (encoded + len0 - 3, "TKB", 3) == 0)
10815796c8dcSSimon Schubert len0 -= 3;
10825796c8dcSSimon Schubert
1083cf7f2e2dSJohn Marino /* Remove any trailing TB suffix. The TB suffix is slightly different
1084cf7f2e2dSJohn Marino from the TKB suffix because it is used for non-anonymous task
1085cf7f2e2dSJohn Marino bodies. */
1086cf7f2e2dSJohn Marino
1087cf7f2e2dSJohn Marino if (len0 > 2 && strncmp (encoded + len0 - 2, "TB", 2) == 0)
1088cf7f2e2dSJohn Marino len0 -= 2;
1089cf7f2e2dSJohn Marino
10905796c8dcSSimon Schubert /* Remove trailing "B" suffixes. */
10915796c8dcSSimon Schubert /* FIXME: brobecker/2006-04-19: Not sure what this are used for... */
10925796c8dcSSimon Schubert
10935796c8dcSSimon Schubert if (len0 > 1 && strncmp (encoded + len0 - 1, "B", 1) == 0)
10945796c8dcSSimon Schubert len0 -= 1;
10955796c8dcSSimon Schubert
10965796c8dcSSimon Schubert /* Make decoded big enough for possible expansion by operator name. */
10975796c8dcSSimon Schubert
10985796c8dcSSimon Schubert GROW_VECT (decoding_buffer, decoding_buffer_size, 2 * len0 + 1);
10995796c8dcSSimon Schubert decoded = decoding_buffer;
11005796c8dcSSimon Schubert
11015796c8dcSSimon Schubert /* Remove trailing __{digit}+ or trailing ${digit}+. */
11025796c8dcSSimon Schubert
11035796c8dcSSimon Schubert if (len0 > 1 && isdigit (encoded[len0 - 1]))
11045796c8dcSSimon Schubert {
11055796c8dcSSimon Schubert i = len0 - 2;
11065796c8dcSSimon Schubert while ((i >= 0 && isdigit (encoded[i]))
11075796c8dcSSimon Schubert || (i >= 1 && encoded[i] == '_' && isdigit (encoded[i - 1])))
11085796c8dcSSimon Schubert i -= 1;
11095796c8dcSSimon Schubert if (i > 1 && encoded[i] == '_' && encoded[i - 1] == '_')
11105796c8dcSSimon Schubert len0 = i - 1;
11115796c8dcSSimon Schubert else if (encoded[i] == '$')
11125796c8dcSSimon Schubert len0 = i;
11135796c8dcSSimon Schubert }
11145796c8dcSSimon Schubert
11155796c8dcSSimon Schubert /* The first few characters that are not alphabetic are not part
11165796c8dcSSimon Schubert of any encoding we use, so we can copy them over verbatim. */
11175796c8dcSSimon Schubert
11185796c8dcSSimon Schubert for (i = 0, j = 0; i < len0 && !isalpha (encoded[i]); i += 1, j += 1)
11195796c8dcSSimon Schubert decoded[j] = encoded[i];
11205796c8dcSSimon Schubert
11215796c8dcSSimon Schubert at_start_name = 1;
11225796c8dcSSimon Schubert while (i < len0)
11235796c8dcSSimon Schubert {
11245796c8dcSSimon Schubert /* Is this a symbol function? */
11255796c8dcSSimon Schubert if (at_start_name && encoded[i] == 'O')
11265796c8dcSSimon Schubert {
11275796c8dcSSimon Schubert int k;
1128cf7f2e2dSJohn Marino
11295796c8dcSSimon Schubert for (k = 0; ada_opname_table[k].encoded != NULL; k += 1)
11305796c8dcSSimon Schubert {
11315796c8dcSSimon Schubert int op_len = strlen (ada_opname_table[k].encoded);
11325796c8dcSSimon Schubert if ((strncmp (ada_opname_table[k].encoded + 1, encoded + i + 1,
11335796c8dcSSimon Schubert op_len - 1) == 0)
11345796c8dcSSimon Schubert && !isalnum (encoded[i + op_len]))
11355796c8dcSSimon Schubert {
11365796c8dcSSimon Schubert strcpy (decoded + j, ada_opname_table[k].decoded);
11375796c8dcSSimon Schubert at_start_name = 0;
11385796c8dcSSimon Schubert i += op_len;
11395796c8dcSSimon Schubert j += strlen (ada_opname_table[k].decoded);
11405796c8dcSSimon Schubert break;
11415796c8dcSSimon Schubert }
11425796c8dcSSimon Schubert }
11435796c8dcSSimon Schubert if (ada_opname_table[k].encoded != NULL)
11445796c8dcSSimon Schubert continue;
11455796c8dcSSimon Schubert }
11465796c8dcSSimon Schubert at_start_name = 0;
11475796c8dcSSimon Schubert
11485796c8dcSSimon Schubert /* Replace "TK__" with "__", which will eventually be translated
11495796c8dcSSimon Schubert into "." (just below). */
11505796c8dcSSimon Schubert
11515796c8dcSSimon Schubert if (i < len0 - 4 && strncmp (encoded + i, "TK__", 4) == 0)
11525796c8dcSSimon Schubert i += 2;
11535796c8dcSSimon Schubert
11545796c8dcSSimon Schubert /* Replace "__B_{DIGITS}+__" sequences by "__", which will eventually
11555796c8dcSSimon Schubert be translated into "." (just below). These are internal names
11565796c8dcSSimon Schubert generated for anonymous blocks inside which our symbol is nested. */
11575796c8dcSSimon Schubert
11585796c8dcSSimon Schubert if (len0 - i > 5 && encoded [i] == '_' && encoded [i+1] == '_'
11595796c8dcSSimon Schubert && encoded [i+2] == 'B' && encoded [i+3] == '_'
11605796c8dcSSimon Schubert && isdigit (encoded [i+4]))
11615796c8dcSSimon Schubert {
11625796c8dcSSimon Schubert int k = i + 5;
11635796c8dcSSimon Schubert
11645796c8dcSSimon Schubert while (k < len0 && isdigit (encoded[k]))
11655796c8dcSSimon Schubert k++; /* Skip any extra digit. */
11665796c8dcSSimon Schubert
11675796c8dcSSimon Schubert /* Double-check that the "__B_{DIGITS}+" sequence we found
11685796c8dcSSimon Schubert is indeed followed by "__". */
11695796c8dcSSimon Schubert if (len0 - k > 2 && encoded [k] == '_' && encoded [k+1] == '_')
11705796c8dcSSimon Schubert i = k;
11715796c8dcSSimon Schubert }
11725796c8dcSSimon Schubert
11735796c8dcSSimon Schubert /* Remove _E{DIGITS}+[sb] */
11745796c8dcSSimon Schubert
11755796c8dcSSimon Schubert /* Just as for protected object subprograms, there are 2 categories
11765796c8dcSSimon Schubert of subprograms created by the compiler for each entry. The first
11775796c8dcSSimon Schubert one implements the actual entry code, and has a suffix following
11785796c8dcSSimon Schubert the convention above; the second one implements the barrier and
11795796c8dcSSimon Schubert uses the same convention as above, except that the 'E' is replaced
11805796c8dcSSimon Schubert by a 'B'.
11815796c8dcSSimon Schubert
11825796c8dcSSimon Schubert Just as above, we do not decode the name of barrier functions
11835796c8dcSSimon Schubert to give the user a clue that the code he is debugging has been
11845796c8dcSSimon Schubert internally generated. */
11855796c8dcSSimon Schubert
11865796c8dcSSimon Schubert if (len0 - i > 3 && encoded [i] == '_' && encoded[i+1] == 'E'
11875796c8dcSSimon Schubert && isdigit (encoded[i+2]))
11885796c8dcSSimon Schubert {
11895796c8dcSSimon Schubert int k = i + 3;
11905796c8dcSSimon Schubert
11915796c8dcSSimon Schubert while (k < len0 && isdigit (encoded[k]))
11925796c8dcSSimon Schubert k++;
11935796c8dcSSimon Schubert
11945796c8dcSSimon Schubert if (k < len0
11955796c8dcSSimon Schubert && (encoded[k] == 'b' || encoded[k] == 's'))
11965796c8dcSSimon Schubert {
11975796c8dcSSimon Schubert k++;
11985796c8dcSSimon Schubert /* Just as an extra precaution, make sure that if this
11995796c8dcSSimon Schubert suffix is followed by anything else, it is a '_'.
12005796c8dcSSimon Schubert Otherwise, we matched this sequence by accident. */
12015796c8dcSSimon Schubert if (k == len0
12025796c8dcSSimon Schubert || (k < len0 && encoded[k] == '_'))
12035796c8dcSSimon Schubert i = k;
12045796c8dcSSimon Schubert }
12055796c8dcSSimon Schubert }
12065796c8dcSSimon Schubert
12075796c8dcSSimon Schubert /* Remove trailing "N" in [a-z0-9]+N__. The N is added by
12085796c8dcSSimon Schubert the GNAT front-end in protected object subprograms. */
12095796c8dcSSimon Schubert
12105796c8dcSSimon Schubert if (i < len0 + 3
12115796c8dcSSimon Schubert && encoded[i] == 'N' && encoded[i+1] == '_' && encoded[i+2] == '_')
12125796c8dcSSimon Schubert {
12135796c8dcSSimon Schubert /* Backtrack a bit up until we reach either the begining of
12145796c8dcSSimon Schubert the encoded name, or "__". Make sure that we only find
12155796c8dcSSimon Schubert digits or lowercase characters. */
12165796c8dcSSimon Schubert const char *ptr = encoded + i - 1;
12175796c8dcSSimon Schubert
12185796c8dcSSimon Schubert while (ptr >= encoded && is_lower_alphanum (ptr[0]))
12195796c8dcSSimon Schubert ptr--;
12205796c8dcSSimon Schubert if (ptr < encoded
12215796c8dcSSimon Schubert || (ptr > encoded && ptr[0] == '_' && ptr[-1] == '_'))
12225796c8dcSSimon Schubert i++;
12235796c8dcSSimon Schubert }
12245796c8dcSSimon Schubert
12255796c8dcSSimon Schubert if (encoded[i] == 'X' && i != 0 && isalnum (encoded[i - 1]))
12265796c8dcSSimon Schubert {
12275796c8dcSSimon Schubert /* This is a X[bn]* sequence not separated from the previous
12285796c8dcSSimon Schubert part of the name with a non-alpha-numeric character (in other
12295796c8dcSSimon Schubert words, immediately following an alpha-numeric character), then
12305796c8dcSSimon Schubert verify that it is placed at the end of the encoded name. If
12315796c8dcSSimon Schubert not, then the encoding is not valid and we should abort the
12325796c8dcSSimon Schubert decoding. Otherwise, just skip it, it is used in body-nested
12335796c8dcSSimon Schubert package names. */
12345796c8dcSSimon Schubert do
12355796c8dcSSimon Schubert i += 1;
12365796c8dcSSimon Schubert while (i < len0 && (encoded[i] == 'b' || encoded[i] == 'n'));
12375796c8dcSSimon Schubert if (i < len0)
12385796c8dcSSimon Schubert goto Suppress;
12395796c8dcSSimon Schubert }
12405796c8dcSSimon Schubert else if (i < len0 - 2 && encoded[i] == '_' && encoded[i + 1] == '_')
12415796c8dcSSimon Schubert {
12425796c8dcSSimon Schubert /* Replace '__' by '.'. */
12435796c8dcSSimon Schubert decoded[j] = '.';
12445796c8dcSSimon Schubert at_start_name = 1;
12455796c8dcSSimon Schubert i += 2;
12465796c8dcSSimon Schubert j += 1;
12475796c8dcSSimon Schubert }
12485796c8dcSSimon Schubert else
12495796c8dcSSimon Schubert {
12505796c8dcSSimon Schubert /* It's a character part of the decoded name, so just copy it
12515796c8dcSSimon Schubert over. */
12525796c8dcSSimon Schubert decoded[j] = encoded[i];
12535796c8dcSSimon Schubert i += 1;
12545796c8dcSSimon Schubert j += 1;
12555796c8dcSSimon Schubert }
12565796c8dcSSimon Schubert }
12575796c8dcSSimon Schubert decoded[j] = '\000';
12585796c8dcSSimon Schubert
12595796c8dcSSimon Schubert /* Decoded names should never contain any uppercase character.
12605796c8dcSSimon Schubert Double-check this, and abort the decoding if we find one. */
12615796c8dcSSimon Schubert
12625796c8dcSSimon Schubert for (i = 0; decoded[i] != '\0'; i += 1)
12635796c8dcSSimon Schubert if (isupper (decoded[i]) || decoded[i] == ' ')
12645796c8dcSSimon Schubert goto Suppress;
12655796c8dcSSimon Schubert
12665796c8dcSSimon Schubert if (strcmp (decoded, encoded) == 0)
12675796c8dcSSimon Schubert return encoded;
12685796c8dcSSimon Schubert else
12695796c8dcSSimon Schubert return decoded;
12705796c8dcSSimon Schubert
12715796c8dcSSimon Schubert Suppress:
12725796c8dcSSimon Schubert GROW_VECT (decoding_buffer, decoding_buffer_size, strlen (encoded) + 3);
12735796c8dcSSimon Schubert decoded = decoding_buffer;
12745796c8dcSSimon Schubert if (encoded[0] == '<')
12755796c8dcSSimon Schubert strcpy (decoded, encoded);
12765796c8dcSSimon Schubert else
12775796c8dcSSimon Schubert xsnprintf (decoded, decoding_buffer_size, "<%s>", encoded);
12785796c8dcSSimon Schubert return decoded;
12795796c8dcSSimon Schubert
12805796c8dcSSimon Schubert }
12815796c8dcSSimon Schubert
12825796c8dcSSimon Schubert /* Table for keeping permanent unique copies of decoded names. Once
12835796c8dcSSimon Schubert allocated, names in this table are never released. While this is a
12845796c8dcSSimon Schubert storage leak, it should not be significant unless there are massive
12855796c8dcSSimon Schubert changes in the set of decoded names in successive versions of a
12865796c8dcSSimon Schubert symbol table loaded during a single session. */
12875796c8dcSSimon Schubert static struct htab *decoded_names_store;
12885796c8dcSSimon Schubert
12895796c8dcSSimon Schubert /* Returns the decoded name of GSYMBOL, as for ada_decode, caching it
12905796c8dcSSimon Schubert in the language-specific part of GSYMBOL, if it has not been
12915796c8dcSSimon Schubert previously computed. Tries to save the decoded name in the same
12925796c8dcSSimon Schubert obstack as GSYMBOL, if possible, and otherwise on the heap (so that,
12935796c8dcSSimon Schubert in any case, the decoded symbol has a lifetime at least that of
12945796c8dcSSimon Schubert GSYMBOL).
12955796c8dcSSimon Schubert The GSYMBOL parameter is "mutable" in the C++ sense: logically
12965796c8dcSSimon Schubert const, but nevertheless modified to a semantically equivalent form
1297c50c785cSJohn Marino when a decoded name is cached in it. */
12985796c8dcSSimon Schubert
1299*ef5ccd6cSJohn Marino const char *
ada_decode_symbol(const struct general_symbol_info * gsymbol)13005796c8dcSSimon Schubert ada_decode_symbol (const struct general_symbol_info *gsymbol)
13015796c8dcSSimon Schubert {
1302*ef5ccd6cSJohn Marino const char **resultp =
1303*ef5ccd6cSJohn Marino (const char **) &gsymbol->language_specific.mangled_lang.demangled_name;
1304cf7f2e2dSJohn Marino
13055796c8dcSSimon Schubert if (*resultp == NULL)
13065796c8dcSSimon Schubert {
13075796c8dcSSimon Schubert const char *decoded = ada_decode (gsymbol->name);
1308cf7f2e2dSJohn Marino
13095796c8dcSSimon Schubert if (gsymbol->obj_section != NULL)
13105796c8dcSSimon Schubert {
13115796c8dcSSimon Schubert struct objfile *objf = gsymbol->obj_section->objfile;
1312cf7f2e2dSJohn Marino
1313*ef5ccd6cSJohn Marino *resultp = obstack_copy0 (&objf->objfile_obstack,
1314*ef5ccd6cSJohn Marino decoded, strlen (decoded));
13155796c8dcSSimon Schubert }
13165796c8dcSSimon Schubert /* Sometimes, we can't find a corresponding objfile, in which
13175796c8dcSSimon Schubert case, we put the result on the heap. Since we only decode
13185796c8dcSSimon Schubert when needed, we hope this usually does not cause a
13195796c8dcSSimon Schubert significant memory leak (FIXME). */
13205796c8dcSSimon Schubert if (*resultp == NULL)
13215796c8dcSSimon Schubert {
13225796c8dcSSimon Schubert char **slot = (char **) htab_find_slot (decoded_names_store,
13235796c8dcSSimon Schubert decoded, INSERT);
1324cf7f2e2dSJohn Marino
13255796c8dcSSimon Schubert if (*slot == NULL)
13265796c8dcSSimon Schubert *slot = xstrdup (decoded);
13275796c8dcSSimon Schubert *resultp = *slot;
13285796c8dcSSimon Schubert }
13295796c8dcSSimon Schubert }
13305796c8dcSSimon Schubert
13315796c8dcSSimon Schubert return *resultp;
13325796c8dcSSimon Schubert }
13335796c8dcSSimon Schubert
13345796c8dcSSimon Schubert static char *
ada_la_decode(const char * encoded,int options)13355796c8dcSSimon Schubert ada_la_decode (const char *encoded, int options)
13365796c8dcSSimon Schubert {
13375796c8dcSSimon Schubert return xstrdup (ada_decode (encoded));
13385796c8dcSSimon Schubert }
13395796c8dcSSimon Schubert
13405796c8dcSSimon Schubert /* Returns non-zero iff SYM_NAME matches NAME, ignoring any trailing
13415796c8dcSSimon Schubert suffixes that encode debugging information or leading _ada_ on
13425796c8dcSSimon Schubert SYM_NAME (see is_name_suffix commentary for the debugging
13435796c8dcSSimon Schubert information that is ignored). If WILD, then NAME need only match a
13445796c8dcSSimon Schubert suffix of SYM_NAME minus the same suffixes. Also returns 0 if
13455796c8dcSSimon Schubert either argument is NULL. */
13465796c8dcSSimon Schubert
13475796c8dcSSimon Schubert static int
match_name(const char * sym_name,const char * name,int wild)1348c50c785cSJohn Marino match_name (const char *sym_name, const char *name, int wild)
13495796c8dcSSimon Schubert {
13505796c8dcSSimon Schubert if (sym_name == NULL || name == NULL)
13515796c8dcSSimon Schubert return 0;
13525796c8dcSSimon Schubert else if (wild)
1353c50c785cSJohn Marino return wild_match (sym_name, name) == 0;
13545796c8dcSSimon Schubert else
13555796c8dcSSimon Schubert {
13565796c8dcSSimon Schubert int len_name = strlen (name);
1357cf7f2e2dSJohn Marino
13585796c8dcSSimon Schubert return (strncmp (sym_name, name, len_name) == 0
13595796c8dcSSimon Schubert && is_name_suffix (sym_name + len_name))
13605796c8dcSSimon Schubert || (strncmp (sym_name, "_ada_", 5) == 0
13615796c8dcSSimon Schubert && strncmp (sym_name + 5, name, len_name) == 0
13625796c8dcSSimon Schubert && is_name_suffix (sym_name + len_name + 5));
13635796c8dcSSimon Schubert }
13645796c8dcSSimon Schubert }
13655796c8dcSSimon Schubert
13665796c8dcSSimon Schubert
13675796c8dcSSimon Schubert /* Arrays */
13685796c8dcSSimon Schubert
1369cf7f2e2dSJohn Marino /* Assuming that INDEX_DESC_TYPE is an ___XA structure, a structure
1370cf7f2e2dSJohn Marino generated by the GNAT compiler to describe the index type used
1371cf7f2e2dSJohn Marino for each dimension of an array, check whether it follows the latest
1372cf7f2e2dSJohn Marino known encoding. If not, fix it up to conform to the latest encoding.
1373cf7f2e2dSJohn Marino Otherwise, do nothing. This function also does nothing if
1374cf7f2e2dSJohn Marino INDEX_DESC_TYPE is NULL.
1375cf7f2e2dSJohn Marino
1376cf7f2e2dSJohn Marino The GNAT encoding used to describle the array index type evolved a bit.
1377cf7f2e2dSJohn Marino Initially, the information would be provided through the name of each
1378cf7f2e2dSJohn Marino field of the structure type only, while the type of these fields was
1379cf7f2e2dSJohn Marino described as unspecified and irrelevant. The debugger was then expected
1380cf7f2e2dSJohn Marino to perform a global type lookup using the name of that field in order
1381cf7f2e2dSJohn Marino to get access to the full index type description. Because these global
1382cf7f2e2dSJohn Marino lookups can be very expensive, the encoding was later enhanced to make
1383cf7f2e2dSJohn Marino the global lookup unnecessary by defining the field type as being
1384cf7f2e2dSJohn Marino the full index type description.
1385cf7f2e2dSJohn Marino
1386cf7f2e2dSJohn Marino The purpose of this routine is to allow us to support older versions
1387cf7f2e2dSJohn Marino of the compiler by detecting the use of the older encoding, and by
1388cf7f2e2dSJohn Marino fixing up the INDEX_DESC_TYPE to follow the new one (at this point,
1389cf7f2e2dSJohn Marino we essentially replace each field's meaningless type by the associated
1390cf7f2e2dSJohn Marino index subtype). */
1391cf7f2e2dSJohn Marino
1392cf7f2e2dSJohn Marino void
ada_fixup_array_indexes_type(struct type * index_desc_type)1393cf7f2e2dSJohn Marino ada_fixup_array_indexes_type (struct type *index_desc_type)
1394cf7f2e2dSJohn Marino {
1395cf7f2e2dSJohn Marino int i;
1396cf7f2e2dSJohn Marino
1397cf7f2e2dSJohn Marino if (index_desc_type == NULL)
1398cf7f2e2dSJohn Marino return;
1399cf7f2e2dSJohn Marino gdb_assert (TYPE_NFIELDS (index_desc_type) > 0);
1400cf7f2e2dSJohn Marino
1401cf7f2e2dSJohn Marino /* Check if INDEX_DESC_TYPE follows the older encoding (it is sufficient
1402cf7f2e2dSJohn Marino to check one field only, no need to check them all). If not, return
1403cf7f2e2dSJohn Marino now.
1404cf7f2e2dSJohn Marino
1405cf7f2e2dSJohn Marino If our INDEX_DESC_TYPE was generated using the older encoding,
1406cf7f2e2dSJohn Marino the field type should be a meaningless integer type whose name
1407cf7f2e2dSJohn Marino is not equal to the field name. */
1408cf7f2e2dSJohn Marino if (TYPE_NAME (TYPE_FIELD_TYPE (index_desc_type, 0)) != NULL
1409cf7f2e2dSJohn Marino && strcmp (TYPE_NAME (TYPE_FIELD_TYPE (index_desc_type, 0)),
1410cf7f2e2dSJohn Marino TYPE_FIELD_NAME (index_desc_type, 0)) == 0)
1411cf7f2e2dSJohn Marino return;
1412cf7f2e2dSJohn Marino
1413cf7f2e2dSJohn Marino /* Fixup each field of INDEX_DESC_TYPE. */
1414cf7f2e2dSJohn Marino for (i = 0; i < TYPE_NFIELDS (index_desc_type); i++)
1415cf7f2e2dSJohn Marino {
1416*ef5ccd6cSJohn Marino const char *name = TYPE_FIELD_NAME (index_desc_type, i);
1417cf7f2e2dSJohn Marino struct type *raw_type = ada_check_typedef (ada_find_any_type (name));
1418cf7f2e2dSJohn Marino
1419cf7f2e2dSJohn Marino if (raw_type)
1420cf7f2e2dSJohn Marino TYPE_FIELD_TYPE (index_desc_type, i) = raw_type;
1421cf7f2e2dSJohn Marino }
1422cf7f2e2dSJohn Marino }
1423cf7f2e2dSJohn Marino
14245796c8dcSSimon Schubert /* Names of MAX_ADA_DIMENS bounds in P_BOUNDS fields of array descriptors. */
14255796c8dcSSimon Schubert
14265796c8dcSSimon Schubert static char *bound_name[] = {
14275796c8dcSSimon Schubert "LB0", "UB0", "LB1", "UB1", "LB2", "UB2", "LB3", "UB3",
14285796c8dcSSimon Schubert "LB4", "UB4", "LB5", "UB5", "LB6", "UB6", "LB7", "UB7"
14295796c8dcSSimon Schubert };
14305796c8dcSSimon Schubert
14315796c8dcSSimon Schubert /* Maximum number of array dimensions we are prepared to handle. */
14325796c8dcSSimon Schubert
14335796c8dcSSimon Schubert #define MAX_ADA_DIMENS (sizeof(bound_name) / (2*sizeof(char *)))
14345796c8dcSSimon Schubert
14355796c8dcSSimon Schubert
14365796c8dcSSimon Schubert /* The desc_* routines return primitive portions of array descriptors
14375796c8dcSSimon Schubert (fat pointers). */
14385796c8dcSSimon Schubert
14395796c8dcSSimon Schubert /* The descriptor or array type, if any, indicated by TYPE; removes
14405796c8dcSSimon Schubert level of indirection, if needed. */
14415796c8dcSSimon Schubert
14425796c8dcSSimon Schubert static struct type *
desc_base_type(struct type * type)14435796c8dcSSimon Schubert desc_base_type (struct type *type)
14445796c8dcSSimon Schubert {
14455796c8dcSSimon Schubert if (type == NULL)
14465796c8dcSSimon Schubert return NULL;
14475796c8dcSSimon Schubert type = ada_check_typedef (type);
1448c50c785cSJohn Marino if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
1449c50c785cSJohn Marino type = ada_typedef_target_type (type);
1450c50c785cSJohn Marino
14515796c8dcSSimon Schubert if (type != NULL
14525796c8dcSSimon Schubert && (TYPE_CODE (type) == TYPE_CODE_PTR
14535796c8dcSSimon Schubert || TYPE_CODE (type) == TYPE_CODE_REF))
14545796c8dcSSimon Schubert return ada_check_typedef (TYPE_TARGET_TYPE (type));
14555796c8dcSSimon Schubert else
14565796c8dcSSimon Schubert return type;
14575796c8dcSSimon Schubert }
14585796c8dcSSimon Schubert
14595796c8dcSSimon Schubert /* True iff TYPE indicates a "thin" array pointer type. */
14605796c8dcSSimon Schubert
14615796c8dcSSimon Schubert static int
is_thin_pntr(struct type * type)14625796c8dcSSimon Schubert is_thin_pntr (struct type *type)
14635796c8dcSSimon Schubert {
14645796c8dcSSimon Schubert return
14655796c8dcSSimon Schubert is_suffix (ada_type_name (desc_base_type (type)), "___XUT")
14665796c8dcSSimon Schubert || is_suffix (ada_type_name (desc_base_type (type)), "___XUT___XVE");
14675796c8dcSSimon Schubert }
14685796c8dcSSimon Schubert
14695796c8dcSSimon Schubert /* The descriptor type for thin pointer type TYPE. */
14705796c8dcSSimon Schubert
14715796c8dcSSimon Schubert static struct type *
thin_descriptor_type(struct type * type)14725796c8dcSSimon Schubert thin_descriptor_type (struct type *type)
14735796c8dcSSimon Schubert {
14745796c8dcSSimon Schubert struct type *base_type = desc_base_type (type);
1475cf7f2e2dSJohn Marino
14765796c8dcSSimon Schubert if (base_type == NULL)
14775796c8dcSSimon Schubert return NULL;
14785796c8dcSSimon Schubert if (is_suffix (ada_type_name (base_type), "___XVE"))
14795796c8dcSSimon Schubert return base_type;
14805796c8dcSSimon Schubert else
14815796c8dcSSimon Schubert {
14825796c8dcSSimon Schubert struct type *alt_type = ada_find_parallel_type (base_type, "___XVE");
1483cf7f2e2dSJohn Marino
14845796c8dcSSimon Schubert if (alt_type == NULL)
14855796c8dcSSimon Schubert return base_type;
14865796c8dcSSimon Schubert else
14875796c8dcSSimon Schubert return alt_type;
14885796c8dcSSimon Schubert }
14895796c8dcSSimon Schubert }
14905796c8dcSSimon Schubert
14915796c8dcSSimon Schubert /* A pointer to the array data for thin-pointer value VAL. */
14925796c8dcSSimon Schubert
14935796c8dcSSimon Schubert static struct value *
thin_data_pntr(struct value * val)14945796c8dcSSimon Schubert thin_data_pntr (struct value *val)
14955796c8dcSSimon Schubert {
1496a45ae5f8SJohn Marino struct type *type = ada_check_typedef (value_type (val));
14975796c8dcSSimon Schubert struct type *data_type = desc_data_target_type (thin_descriptor_type (type));
1498cf7f2e2dSJohn Marino
14995796c8dcSSimon Schubert data_type = lookup_pointer_type (data_type);
15005796c8dcSSimon Schubert
15015796c8dcSSimon Schubert if (TYPE_CODE (type) == TYPE_CODE_PTR)
15025796c8dcSSimon Schubert return value_cast (data_type, value_copy (val));
15035796c8dcSSimon Schubert else
15045796c8dcSSimon Schubert return value_from_longest (data_type, value_address (val));
15055796c8dcSSimon Schubert }
15065796c8dcSSimon Schubert
15075796c8dcSSimon Schubert /* True iff TYPE indicates a "thick" array pointer type. */
15085796c8dcSSimon Schubert
15095796c8dcSSimon Schubert static int
is_thick_pntr(struct type * type)15105796c8dcSSimon Schubert is_thick_pntr (struct type *type)
15115796c8dcSSimon Schubert {
15125796c8dcSSimon Schubert type = desc_base_type (type);
15135796c8dcSSimon Schubert return (type != NULL && TYPE_CODE (type) == TYPE_CODE_STRUCT
15145796c8dcSSimon Schubert && lookup_struct_elt_type (type, "P_BOUNDS", 1) != NULL);
15155796c8dcSSimon Schubert }
15165796c8dcSSimon Schubert
15175796c8dcSSimon Schubert /* If TYPE is the type of an array descriptor (fat or thin pointer) or a
15185796c8dcSSimon Schubert pointer to one, the type of its bounds data; otherwise, NULL. */
15195796c8dcSSimon Schubert
15205796c8dcSSimon Schubert static struct type *
desc_bounds_type(struct type * type)15215796c8dcSSimon Schubert desc_bounds_type (struct type *type)
15225796c8dcSSimon Schubert {
15235796c8dcSSimon Schubert struct type *r;
15245796c8dcSSimon Schubert
15255796c8dcSSimon Schubert type = desc_base_type (type);
15265796c8dcSSimon Schubert
15275796c8dcSSimon Schubert if (type == NULL)
15285796c8dcSSimon Schubert return NULL;
15295796c8dcSSimon Schubert else if (is_thin_pntr (type))
15305796c8dcSSimon Schubert {
15315796c8dcSSimon Schubert type = thin_descriptor_type (type);
15325796c8dcSSimon Schubert if (type == NULL)
15335796c8dcSSimon Schubert return NULL;
15345796c8dcSSimon Schubert r = lookup_struct_elt_type (type, "BOUNDS", 1);
15355796c8dcSSimon Schubert if (r != NULL)
15365796c8dcSSimon Schubert return ada_check_typedef (r);
15375796c8dcSSimon Schubert }
15385796c8dcSSimon Schubert else if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
15395796c8dcSSimon Schubert {
15405796c8dcSSimon Schubert r = lookup_struct_elt_type (type, "P_BOUNDS", 1);
15415796c8dcSSimon Schubert if (r != NULL)
15425796c8dcSSimon Schubert return ada_check_typedef (TYPE_TARGET_TYPE (ada_check_typedef (r)));
15435796c8dcSSimon Schubert }
15445796c8dcSSimon Schubert return NULL;
15455796c8dcSSimon Schubert }
15465796c8dcSSimon Schubert
15475796c8dcSSimon Schubert /* If ARR is an array descriptor (fat or thin pointer), or pointer to
15485796c8dcSSimon Schubert one, a pointer to its bounds data. Otherwise NULL. */
15495796c8dcSSimon Schubert
15505796c8dcSSimon Schubert static struct value *
desc_bounds(struct value * arr)15515796c8dcSSimon Schubert desc_bounds (struct value *arr)
15525796c8dcSSimon Schubert {
15535796c8dcSSimon Schubert struct type *type = ada_check_typedef (value_type (arr));
1554cf7f2e2dSJohn Marino
15555796c8dcSSimon Schubert if (is_thin_pntr (type))
15565796c8dcSSimon Schubert {
15575796c8dcSSimon Schubert struct type *bounds_type =
15585796c8dcSSimon Schubert desc_bounds_type (thin_descriptor_type (type));
15595796c8dcSSimon Schubert LONGEST addr;
15605796c8dcSSimon Schubert
15615796c8dcSSimon Schubert if (bounds_type == NULL)
15625796c8dcSSimon Schubert error (_("Bad GNAT array descriptor"));
15635796c8dcSSimon Schubert
15645796c8dcSSimon Schubert /* NOTE: The following calculation is not really kosher, but
15655796c8dcSSimon Schubert since desc_type is an XVE-encoded type (and shouldn't be),
15665796c8dcSSimon Schubert the correct calculation is a real pain. FIXME (and fix GCC). */
15675796c8dcSSimon Schubert if (TYPE_CODE (type) == TYPE_CODE_PTR)
15685796c8dcSSimon Schubert addr = value_as_long (arr);
15695796c8dcSSimon Schubert else
15705796c8dcSSimon Schubert addr = value_address (arr);
15715796c8dcSSimon Schubert
15725796c8dcSSimon Schubert return
15735796c8dcSSimon Schubert value_from_longest (lookup_pointer_type (bounds_type),
15745796c8dcSSimon Schubert addr - TYPE_LENGTH (bounds_type));
15755796c8dcSSimon Schubert }
15765796c8dcSSimon Schubert
15775796c8dcSSimon Schubert else if (is_thick_pntr (type))
1578c50c785cSJohn Marino {
1579c50c785cSJohn Marino struct value *p_bounds = value_struct_elt (&arr, NULL, "P_BOUNDS", NULL,
15805796c8dcSSimon Schubert _("Bad GNAT array descriptor"));
1581c50c785cSJohn Marino struct type *p_bounds_type = value_type (p_bounds);
1582c50c785cSJohn Marino
1583c50c785cSJohn Marino if (p_bounds_type
1584c50c785cSJohn Marino && TYPE_CODE (p_bounds_type) == TYPE_CODE_PTR)
1585c50c785cSJohn Marino {
1586c50c785cSJohn Marino struct type *target_type = TYPE_TARGET_TYPE (p_bounds_type);
1587c50c785cSJohn Marino
1588c50c785cSJohn Marino if (TYPE_STUB (target_type))
1589c50c785cSJohn Marino p_bounds = value_cast (lookup_pointer_type
1590c50c785cSJohn Marino (ada_check_typedef (target_type)),
1591c50c785cSJohn Marino p_bounds);
1592c50c785cSJohn Marino }
1593c50c785cSJohn Marino else
1594c50c785cSJohn Marino error (_("Bad GNAT array descriptor"));
1595c50c785cSJohn Marino
1596c50c785cSJohn Marino return p_bounds;
1597c50c785cSJohn Marino }
15985796c8dcSSimon Schubert else
15995796c8dcSSimon Schubert return NULL;
16005796c8dcSSimon Schubert }
16015796c8dcSSimon Schubert
16025796c8dcSSimon Schubert /* If TYPE is the type of an array-descriptor (fat pointer), the bit
16035796c8dcSSimon Schubert position of the field containing the address of the bounds data. */
16045796c8dcSSimon Schubert
16055796c8dcSSimon Schubert static int
fat_pntr_bounds_bitpos(struct type * type)16065796c8dcSSimon Schubert fat_pntr_bounds_bitpos (struct type *type)
16075796c8dcSSimon Schubert {
16085796c8dcSSimon Schubert return TYPE_FIELD_BITPOS (desc_base_type (type), 1);
16095796c8dcSSimon Schubert }
16105796c8dcSSimon Schubert
16115796c8dcSSimon Schubert /* If TYPE is the type of an array-descriptor (fat pointer), the bit
16125796c8dcSSimon Schubert size of the field containing the address of the bounds data. */
16135796c8dcSSimon Schubert
16145796c8dcSSimon Schubert static int
fat_pntr_bounds_bitsize(struct type * type)16155796c8dcSSimon Schubert fat_pntr_bounds_bitsize (struct type *type)
16165796c8dcSSimon Schubert {
16175796c8dcSSimon Schubert type = desc_base_type (type);
16185796c8dcSSimon Schubert
16195796c8dcSSimon Schubert if (TYPE_FIELD_BITSIZE (type, 1) > 0)
16205796c8dcSSimon Schubert return TYPE_FIELD_BITSIZE (type, 1);
16215796c8dcSSimon Schubert else
16225796c8dcSSimon Schubert return 8 * TYPE_LENGTH (ada_check_typedef (TYPE_FIELD_TYPE (type, 1)));
16235796c8dcSSimon Schubert }
16245796c8dcSSimon Schubert
16255796c8dcSSimon Schubert /* If TYPE is the type of an array descriptor (fat or thin pointer) or a
16265796c8dcSSimon Schubert pointer to one, the type of its array data (a array-with-no-bounds type);
16275796c8dcSSimon Schubert otherwise, NULL. Use ada_type_of_array to get an array type with bounds
16285796c8dcSSimon Schubert data. */
16295796c8dcSSimon Schubert
16305796c8dcSSimon Schubert static struct type *
desc_data_target_type(struct type * type)16315796c8dcSSimon Schubert desc_data_target_type (struct type *type)
16325796c8dcSSimon Schubert {
16335796c8dcSSimon Schubert type = desc_base_type (type);
16345796c8dcSSimon Schubert
16355796c8dcSSimon Schubert /* NOTE: The following is bogus; see comment in desc_bounds. */
16365796c8dcSSimon Schubert if (is_thin_pntr (type))
16375796c8dcSSimon Schubert return desc_base_type (TYPE_FIELD_TYPE (thin_descriptor_type (type), 1));
16385796c8dcSSimon Schubert else if (is_thick_pntr (type))
16395796c8dcSSimon Schubert {
16405796c8dcSSimon Schubert struct type *data_type = lookup_struct_elt_type (type, "P_ARRAY", 1);
16415796c8dcSSimon Schubert
16425796c8dcSSimon Schubert if (data_type
16435796c8dcSSimon Schubert && TYPE_CODE (ada_check_typedef (data_type)) == TYPE_CODE_PTR)
1644c50c785cSJohn Marino return ada_check_typedef (TYPE_TARGET_TYPE (data_type));
16455796c8dcSSimon Schubert }
16465796c8dcSSimon Schubert
16475796c8dcSSimon Schubert return NULL;
16485796c8dcSSimon Schubert }
16495796c8dcSSimon Schubert
16505796c8dcSSimon Schubert /* If ARR is an array descriptor (fat or thin pointer), a pointer to
16515796c8dcSSimon Schubert its array data. */
16525796c8dcSSimon Schubert
16535796c8dcSSimon Schubert static struct value *
desc_data(struct value * arr)16545796c8dcSSimon Schubert desc_data (struct value *arr)
16555796c8dcSSimon Schubert {
16565796c8dcSSimon Schubert struct type *type = value_type (arr);
1657cf7f2e2dSJohn Marino
16585796c8dcSSimon Schubert if (is_thin_pntr (type))
16595796c8dcSSimon Schubert return thin_data_pntr (arr);
16605796c8dcSSimon Schubert else if (is_thick_pntr (type))
16615796c8dcSSimon Schubert return value_struct_elt (&arr, NULL, "P_ARRAY", NULL,
16625796c8dcSSimon Schubert _("Bad GNAT array descriptor"));
16635796c8dcSSimon Schubert else
16645796c8dcSSimon Schubert return NULL;
16655796c8dcSSimon Schubert }
16665796c8dcSSimon Schubert
16675796c8dcSSimon Schubert
16685796c8dcSSimon Schubert /* If TYPE is the type of an array-descriptor (fat pointer), the bit
16695796c8dcSSimon Schubert position of the field containing the address of the data. */
16705796c8dcSSimon Schubert
16715796c8dcSSimon Schubert static int
fat_pntr_data_bitpos(struct type * type)16725796c8dcSSimon Schubert fat_pntr_data_bitpos (struct type *type)
16735796c8dcSSimon Schubert {
16745796c8dcSSimon Schubert return TYPE_FIELD_BITPOS (desc_base_type (type), 0);
16755796c8dcSSimon Schubert }
16765796c8dcSSimon Schubert
16775796c8dcSSimon Schubert /* If TYPE is the type of an array-descriptor (fat pointer), the bit
16785796c8dcSSimon Schubert size of the field containing the address of the data. */
16795796c8dcSSimon Schubert
16805796c8dcSSimon Schubert static int
fat_pntr_data_bitsize(struct type * type)16815796c8dcSSimon Schubert fat_pntr_data_bitsize (struct type *type)
16825796c8dcSSimon Schubert {
16835796c8dcSSimon Schubert type = desc_base_type (type);
16845796c8dcSSimon Schubert
16855796c8dcSSimon Schubert if (TYPE_FIELD_BITSIZE (type, 0) > 0)
16865796c8dcSSimon Schubert return TYPE_FIELD_BITSIZE (type, 0);
16875796c8dcSSimon Schubert else
16885796c8dcSSimon Schubert return TARGET_CHAR_BIT * TYPE_LENGTH (TYPE_FIELD_TYPE (type, 0));
16895796c8dcSSimon Schubert }
16905796c8dcSSimon Schubert
16915796c8dcSSimon Schubert /* If BOUNDS is an array-bounds structure (or pointer to one), return
16925796c8dcSSimon Schubert the Ith lower bound stored in it, if WHICH is 0, and the Ith upper
16935796c8dcSSimon Schubert bound, if WHICH is 1. The first bound is I=1. */
16945796c8dcSSimon Schubert
16955796c8dcSSimon Schubert static struct value *
desc_one_bound(struct value * bounds,int i,int which)16965796c8dcSSimon Schubert desc_one_bound (struct value *bounds, int i, int which)
16975796c8dcSSimon Schubert {
16985796c8dcSSimon Schubert return value_struct_elt (&bounds, NULL, bound_name[2 * i + which - 2], NULL,
16995796c8dcSSimon Schubert _("Bad GNAT array descriptor bounds"));
17005796c8dcSSimon Schubert }
17015796c8dcSSimon Schubert
17025796c8dcSSimon Schubert /* If BOUNDS is an array-bounds structure type, return the bit position
17035796c8dcSSimon Schubert of the Ith lower bound stored in it, if WHICH is 0, and the Ith upper
17045796c8dcSSimon Schubert bound, if WHICH is 1. The first bound is I=1. */
17055796c8dcSSimon Schubert
17065796c8dcSSimon Schubert static int
desc_bound_bitpos(struct type * type,int i,int which)17075796c8dcSSimon Schubert desc_bound_bitpos (struct type *type, int i, int which)
17085796c8dcSSimon Schubert {
17095796c8dcSSimon Schubert return TYPE_FIELD_BITPOS (desc_base_type (type), 2 * i + which - 2);
17105796c8dcSSimon Schubert }
17115796c8dcSSimon Schubert
17125796c8dcSSimon Schubert /* If BOUNDS is an array-bounds structure type, return the bit field size
17135796c8dcSSimon Schubert of the Ith lower bound stored in it, if WHICH is 0, and the Ith upper
17145796c8dcSSimon Schubert bound, if WHICH is 1. The first bound is I=1. */
17155796c8dcSSimon Schubert
17165796c8dcSSimon Schubert static int
desc_bound_bitsize(struct type * type,int i,int which)17175796c8dcSSimon Schubert desc_bound_bitsize (struct type *type, int i, int which)
17185796c8dcSSimon Schubert {
17195796c8dcSSimon Schubert type = desc_base_type (type);
17205796c8dcSSimon Schubert
17215796c8dcSSimon Schubert if (TYPE_FIELD_BITSIZE (type, 2 * i + which - 2) > 0)
17225796c8dcSSimon Schubert return TYPE_FIELD_BITSIZE (type, 2 * i + which - 2);
17235796c8dcSSimon Schubert else
17245796c8dcSSimon Schubert return 8 * TYPE_LENGTH (TYPE_FIELD_TYPE (type, 2 * i + which - 2));
17255796c8dcSSimon Schubert }
17265796c8dcSSimon Schubert
17275796c8dcSSimon Schubert /* If TYPE is the type of an array-bounds structure, the type of its
17285796c8dcSSimon Schubert Ith bound (numbering from 1). Otherwise, NULL. */
17295796c8dcSSimon Schubert
17305796c8dcSSimon Schubert static struct type *
desc_index_type(struct type * type,int i)17315796c8dcSSimon Schubert desc_index_type (struct type *type, int i)
17325796c8dcSSimon Schubert {
17335796c8dcSSimon Schubert type = desc_base_type (type);
17345796c8dcSSimon Schubert
17355796c8dcSSimon Schubert if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
17365796c8dcSSimon Schubert return lookup_struct_elt_type (type, bound_name[2 * i - 2], 1);
17375796c8dcSSimon Schubert else
17385796c8dcSSimon Schubert return NULL;
17395796c8dcSSimon Schubert }
17405796c8dcSSimon Schubert
17415796c8dcSSimon Schubert /* The number of index positions in the array-bounds type TYPE.
17425796c8dcSSimon Schubert Return 0 if TYPE is NULL. */
17435796c8dcSSimon Schubert
17445796c8dcSSimon Schubert static int
desc_arity(struct type * type)17455796c8dcSSimon Schubert desc_arity (struct type *type)
17465796c8dcSSimon Schubert {
17475796c8dcSSimon Schubert type = desc_base_type (type);
17485796c8dcSSimon Schubert
17495796c8dcSSimon Schubert if (type != NULL)
17505796c8dcSSimon Schubert return TYPE_NFIELDS (type) / 2;
17515796c8dcSSimon Schubert return 0;
17525796c8dcSSimon Schubert }
17535796c8dcSSimon Schubert
17545796c8dcSSimon Schubert /* Non-zero iff TYPE is a simple array type (not a pointer to one) or
17555796c8dcSSimon Schubert an array descriptor type (representing an unconstrained array
17565796c8dcSSimon Schubert type). */
17575796c8dcSSimon Schubert
17585796c8dcSSimon Schubert static int
ada_is_direct_array_type(struct type * type)17595796c8dcSSimon Schubert ada_is_direct_array_type (struct type *type)
17605796c8dcSSimon Schubert {
17615796c8dcSSimon Schubert if (type == NULL)
17625796c8dcSSimon Schubert return 0;
17635796c8dcSSimon Schubert type = ada_check_typedef (type);
17645796c8dcSSimon Schubert return (TYPE_CODE (type) == TYPE_CODE_ARRAY
17655796c8dcSSimon Schubert || ada_is_array_descriptor_type (type));
17665796c8dcSSimon Schubert }
17675796c8dcSSimon Schubert
17685796c8dcSSimon Schubert /* Non-zero iff TYPE represents any kind of array in Ada, or a pointer
17695796c8dcSSimon Schubert * to one. */
17705796c8dcSSimon Schubert
17715796c8dcSSimon Schubert static int
ada_is_array_type(struct type * type)17725796c8dcSSimon Schubert ada_is_array_type (struct type *type)
17735796c8dcSSimon Schubert {
17745796c8dcSSimon Schubert while (type != NULL
17755796c8dcSSimon Schubert && (TYPE_CODE (type) == TYPE_CODE_PTR
17765796c8dcSSimon Schubert || TYPE_CODE (type) == TYPE_CODE_REF))
17775796c8dcSSimon Schubert type = TYPE_TARGET_TYPE (type);
17785796c8dcSSimon Schubert return ada_is_direct_array_type (type);
17795796c8dcSSimon Schubert }
17805796c8dcSSimon Schubert
17815796c8dcSSimon Schubert /* Non-zero iff TYPE is a simple array type or pointer to one. */
17825796c8dcSSimon Schubert
17835796c8dcSSimon Schubert int
ada_is_simple_array_type(struct type * type)17845796c8dcSSimon Schubert ada_is_simple_array_type (struct type *type)
17855796c8dcSSimon Schubert {
17865796c8dcSSimon Schubert if (type == NULL)
17875796c8dcSSimon Schubert return 0;
17885796c8dcSSimon Schubert type = ada_check_typedef (type);
17895796c8dcSSimon Schubert return (TYPE_CODE (type) == TYPE_CODE_ARRAY
17905796c8dcSSimon Schubert || (TYPE_CODE (type) == TYPE_CODE_PTR
1791c50c785cSJohn Marino && TYPE_CODE (ada_check_typedef (TYPE_TARGET_TYPE (type)))
1792c50c785cSJohn Marino == TYPE_CODE_ARRAY));
17935796c8dcSSimon Schubert }
17945796c8dcSSimon Schubert
17955796c8dcSSimon Schubert /* Non-zero iff TYPE belongs to a GNAT array descriptor. */
17965796c8dcSSimon Schubert
17975796c8dcSSimon Schubert int
ada_is_array_descriptor_type(struct type * type)17985796c8dcSSimon Schubert ada_is_array_descriptor_type (struct type *type)
17995796c8dcSSimon Schubert {
18005796c8dcSSimon Schubert struct type *data_type = desc_data_target_type (type);
18015796c8dcSSimon Schubert
18025796c8dcSSimon Schubert if (type == NULL)
18035796c8dcSSimon Schubert return 0;
18045796c8dcSSimon Schubert type = ada_check_typedef (type);
18055796c8dcSSimon Schubert return (data_type != NULL
18065796c8dcSSimon Schubert && TYPE_CODE (data_type) == TYPE_CODE_ARRAY
18075796c8dcSSimon Schubert && desc_arity (desc_bounds_type (type)) > 0);
18085796c8dcSSimon Schubert }
18095796c8dcSSimon Schubert
18105796c8dcSSimon Schubert /* Non-zero iff type is a partially mal-formed GNAT array
18115796c8dcSSimon Schubert descriptor. FIXME: This is to compensate for some problems with
18125796c8dcSSimon Schubert debugging output from GNAT. Re-examine periodically to see if it
18135796c8dcSSimon Schubert is still needed. */
18145796c8dcSSimon Schubert
18155796c8dcSSimon Schubert int
ada_is_bogus_array_descriptor(struct type * type)18165796c8dcSSimon Schubert ada_is_bogus_array_descriptor (struct type *type)
18175796c8dcSSimon Schubert {
18185796c8dcSSimon Schubert return
18195796c8dcSSimon Schubert type != NULL
18205796c8dcSSimon Schubert && TYPE_CODE (type) == TYPE_CODE_STRUCT
18215796c8dcSSimon Schubert && (lookup_struct_elt_type (type, "P_BOUNDS", 1) != NULL
18225796c8dcSSimon Schubert || lookup_struct_elt_type (type, "P_ARRAY", 1) != NULL)
18235796c8dcSSimon Schubert && !ada_is_array_descriptor_type (type);
18245796c8dcSSimon Schubert }
18255796c8dcSSimon Schubert
18265796c8dcSSimon Schubert
18275796c8dcSSimon Schubert /* If ARR has a record type in the form of a standard GNAT array descriptor,
18285796c8dcSSimon Schubert (fat pointer) returns the type of the array data described---specifically,
18295796c8dcSSimon Schubert a pointer-to-array type. If BOUNDS is non-zero, the bounds data are filled
18305796c8dcSSimon Schubert in from the descriptor; otherwise, they are left unspecified. If
18315796c8dcSSimon Schubert the ARR denotes a null array descriptor and BOUNDS is non-zero,
18325796c8dcSSimon Schubert returns NULL. The result is simply the type of ARR if ARR is not
18335796c8dcSSimon Schubert a descriptor. */
18345796c8dcSSimon Schubert struct type *
ada_type_of_array(struct value * arr,int bounds)18355796c8dcSSimon Schubert ada_type_of_array (struct value *arr, int bounds)
18365796c8dcSSimon Schubert {
1837cf7f2e2dSJohn Marino if (ada_is_constrained_packed_array_type (value_type (arr)))
1838cf7f2e2dSJohn Marino return decode_constrained_packed_array_type (value_type (arr));
18395796c8dcSSimon Schubert
18405796c8dcSSimon Schubert if (!ada_is_array_descriptor_type (value_type (arr)))
18415796c8dcSSimon Schubert return value_type (arr);
18425796c8dcSSimon Schubert
18435796c8dcSSimon Schubert if (!bounds)
1844cf7f2e2dSJohn Marino {
1845cf7f2e2dSJohn Marino struct type *array_type =
18465796c8dcSSimon Schubert ada_check_typedef (desc_data_target_type (value_type (arr)));
1847cf7f2e2dSJohn Marino
1848cf7f2e2dSJohn Marino if (ada_is_unconstrained_packed_array_type (value_type (arr)))
1849cf7f2e2dSJohn Marino TYPE_FIELD_BITSIZE (array_type, 0) =
1850cf7f2e2dSJohn Marino decode_packed_array_bitsize (value_type (arr));
1851cf7f2e2dSJohn Marino
1852cf7f2e2dSJohn Marino return array_type;
1853cf7f2e2dSJohn Marino }
18545796c8dcSSimon Schubert else
18555796c8dcSSimon Schubert {
18565796c8dcSSimon Schubert struct type *elt_type;
18575796c8dcSSimon Schubert int arity;
18585796c8dcSSimon Schubert struct value *descriptor;
18595796c8dcSSimon Schubert
18605796c8dcSSimon Schubert elt_type = ada_array_element_type (value_type (arr), -1);
18615796c8dcSSimon Schubert arity = ada_array_arity (value_type (arr));
18625796c8dcSSimon Schubert
18635796c8dcSSimon Schubert if (elt_type == NULL || arity == 0)
18645796c8dcSSimon Schubert return ada_check_typedef (value_type (arr));
18655796c8dcSSimon Schubert
18665796c8dcSSimon Schubert descriptor = desc_bounds (arr);
18675796c8dcSSimon Schubert if (value_as_long (descriptor) == 0)
18685796c8dcSSimon Schubert return NULL;
18695796c8dcSSimon Schubert while (arity > 0)
18705796c8dcSSimon Schubert {
18715796c8dcSSimon Schubert struct type *range_type = alloc_type_copy (value_type (arr));
18725796c8dcSSimon Schubert struct type *array_type = alloc_type_copy (value_type (arr));
18735796c8dcSSimon Schubert struct value *low = desc_one_bound (descriptor, arity, 0);
18745796c8dcSSimon Schubert struct value *high = desc_one_bound (descriptor, arity, 1);
18755796c8dcSSimon Schubert
1876cf7f2e2dSJohn Marino arity -= 1;
18775796c8dcSSimon Schubert create_range_type (range_type, value_type (low),
18785796c8dcSSimon Schubert longest_to_int (value_as_long (low)),
18795796c8dcSSimon Schubert longest_to_int (value_as_long (high)));
18805796c8dcSSimon Schubert elt_type = create_array_type (array_type, elt_type, range_type);
1881cf7f2e2dSJohn Marino
1882cf7f2e2dSJohn Marino if (ada_is_unconstrained_packed_array_type (value_type (arr)))
1883c50c785cSJohn Marino {
1884c50c785cSJohn Marino /* We need to store the element packed bitsize, as well as
1885c50c785cSJohn Marino recompute the array size, because it was previously
1886c50c785cSJohn Marino computed based on the unpacked element size. */
1887c50c785cSJohn Marino LONGEST lo = value_as_long (low);
1888c50c785cSJohn Marino LONGEST hi = value_as_long (high);
1889c50c785cSJohn Marino
1890cf7f2e2dSJohn Marino TYPE_FIELD_BITSIZE (elt_type, 0) =
1891cf7f2e2dSJohn Marino decode_packed_array_bitsize (value_type (arr));
1892c50c785cSJohn Marino /* If the array has no element, then the size is already
1893c50c785cSJohn Marino zero, and does not need to be recomputed. */
1894c50c785cSJohn Marino if (lo < hi)
1895c50c785cSJohn Marino {
1896c50c785cSJohn Marino int array_bitsize =
1897c50c785cSJohn Marino (hi - lo + 1) * TYPE_FIELD_BITSIZE (elt_type, 0);
1898c50c785cSJohn Marino
1899c50c785cSJohn Marino TYPE_LENGTH (array_type) = (array_bitsize + 7) / 8;
1900c50c785cSJohn Marino }
1901c50c785cSJohn Marino }
19025796c8dcSSimon Schubert }
19035796c8dcSSimon Schubert
19045796c8dcSSimon Schubert return lookup_pointer_type (elt_type);
19055796c8dcSSimon Schubert }
19065796c8dcSSimon Schubert }
19075796c8dcSSimon Schubert
19085796c8dcSSimon Schubert /* If ARR does not represent an array, returns ARR unchanged.
19095796c8dcSSimon Schubert Otherwise, returns either a standard GDB array with bounds set
19105796c8dcSSimon Schubert appropriately or, if ARR is a non-null fat pointer, a pointer to a standard
19115796c8dcSSimon Schubert GDB array. Returns NULL if ARR is a null fat pointer. */
19125796c8dcSSimon Schubert
19135796c8dcSSimon Schubert struct value *
ada_coerce_to_simple_array_ptr(struct value * arr)19145796c8dcSSimon Schubert ada_coerce_to_simple_array_ptr (struct value *arr)
19155796c8dcSSimon Schubert {
19165796c8dcSSimon Schubert if (ada_is_array_descriptor_type (value_type (arr)))
19175796c8dcSSimon Schubert {
19185796c8dcSSimon Schubert struct type *arrType = ada_type_of_array (arr, 1);
1919cf7f2e2dSJohn Marino
19205796c8dcSSimon Schubert if (arrType == NULL)
19215796c8dcSSimon Schubert return NULL;
19225796c8dcSSimon Schubert return value_cast (arrType, value_copy (desc_data (arr)));
19235796c8dcSSimon Schubert }
1924cf7f2e2dSJohn Marino else if (ada_is_constrained_packed_array_type (value_type (arr)))
1925cf7f2e2dSJohn Marino return decode_constrained_packed_array (arr);
19265796c8dcSSimon Schubert else
19275796c8dcSSimon Schubert return arr;
19285796c8dcSSimon Schubert }
19295796c8dcSSimon Schubert
19305796c8dcSSimon Schubert /* If ARR does not represent an array, returns ARR unchanged.
19315796c8dcSSimon Schubert Otherwise, returns a standard GDB array describing ARR (which may
19325796c8dcSSimon Schubert be ARR itself if it already is in the proper form). */
19335796c8dcSSimon Schubert
1934c50c785cSJohn Marino struct value *
ada_coerce_to_simple_array(struct value * arr)19355796c8dcSSimon Schubert ada_coerce_to_simple_array (struct value *arr)
19365796c8dcSSimon Schubert {
19375796c8dcSSimon Schubert if (ada_is_array_descriptor_type (value_type (arr)))
19385796c8dcSSimon Schubert {
19395796c8dcSSimon Schubert struct value *arrVal = ada_coerce_to_simple_array_ptr (arr);
1940cf7f2e2dSJohn Marino
19415796c8dcSSimon Schubert if (arrVal == NULL)
19425796c8dcSSimon Schubert error (_("Bounds unavailable for null array pointer."));
19435796c8dcSSimon Schubert check_size (TYPE_TARGET_TYPE (value_type (arrVal)));
19445796c8dcSSimon Schubert return value_ind (arrVal);
19455796c8dcSSimon Schubert }
1946cf7f2e2dSJohn Marino else if (ada_is_constrained_packed_array_type (value_type (arr)))
1947cf7f2e2dSJohn Marino return decode_constrained_packed_array (arr);
19485796c8dcSSimon Schubert else
19495796c8dcSSimon Schubert return arr;
19505796c8dcSSimon Schubert }
19515796c8dcSSimon Schubert
19525796c8dcSSimon Schubert /* If TYPE represents a GNAT array type, return it translated to an
19535796c8dcSSimon Schubert ordinary GDB array type (possibly with BITSIZE fields indicating
19545796c8dcSSimon Schubert packing). For other types, is the identity. */
19555796c8dcSSimon Schubert
19565796c8dcSSimon Schubert struct type *
ada_coerce_to_simple_array_type(struct type * type)19575796c8dcSSimon Schubert ada_coerce_to_simple_array_type (struct type *type)
19585796c8dcSSimon Schubert {
1959cf7f2e2dSJohn Marino if (ada_is_constrained_packed_array_type (type))
1960cf7f2e2dSJohn Marino return decode_constrained_packed_array_type (type);
19615796c8dcSSimon Schubert
19625796c8dcSSimon Schubert if (ada_is_array_descriptor_type (type))
19635796c8dcSSimon Schubert return ada_check_typedef (desc_data_target_type (type));
19645796c8dcSSimon Schubert
19655796c8dcSSimon Schubert return type;
19665796c8dcSSimon Schubert }
19675796c8dcSSimon Schubert
19685796c8dcSSimon Schubert /* Non-zero iff TYPE represents a standard GNAT packed-array type. */
19695796c8dcSSimon Schubert
1970cf7f2e2dSJohn Marino static int
ada_is_packed_array_type(struct type * type)19715796c8dcSSimon Schubert ada_is_packed_array_type (struct type *type)
19725796c8dcSSimon Schubert {
19735796c8dcSSimon Schubert if (type == NULL)
19745796c8dcSSimon Schubert return 0;
19755796c8dcSSimon Schubert type = desc_base_type (type);
19765796c8dcSSimon Schubert type = ada_check_typedef (type);
19775796c8dcSSimon Schubert return
19785796c8dcSSimon Schubert ada_type_name (type) != NULL
19795796c8dcSSimon Schubert && strstr (ada_type_name (type), "___XP") != NULL;
19805796c8dcSSimon Schubert }
19815796c8dcSSimon Schubert
1982cf7f2e2dSJohn Marino /* Non-zero iff TYPE represents a standard GNAT constrained
1983cf7f2e2dSJohn Marino packed-array type. */
1984cf7f2e2dSJohn Marino
1985cf7f2e2dSJohn Marino int
ada_is_constrained_packed_array_type(struct type * type)1986cf7f2e2dSJohn Marino ada_is_constrained_packed_array_type (struct type *type)
1987cf7f2e2dSJohn Marino {
1988cf7f2e2dSJohn Marino return ada_is_packed_array_type (type)
1989cf7f2e2dSJohn Marino && !ada_is_array_descriptor_type (type);
1990cf7f2e2dSJohn Marino }
1991cf7f2e2dSJohn Marino
1992cf7f2e2dSJohn Marino /* Non-zero iff TYPE represents an array descriptor for a
1993cf7f2e2dSJohn Marino unconstrained packed-array type. */
1994cf7f2e2dSJohn Marino
1995cf7f2e2dSJohn Marino static int
ada_is_unconstrained_packed_array_type(struct type * type)1996cf7f2e2dSJohn Marino ada_is_unconstrained_packed_array_type (struct type *type)
1997cf7f2e2dSJohn Marino {
1998cf7f2e2dSJohn Marino return ada_is_packed_array_type (type)
1999cf7f2e2dSJohn Marino && ada_is_array_descriptor_type (type);
2000cf7f2e2dSJohn Marino }
2001cf7f2e2dSJohn Marino
2002cf7f2e2dSJohn Marino /* Given that TYPE encodes a packed array type (constrained or unconstrained),
2003cf7f2e2dSJohn Marino return the size of its elements in bits. */
2004cf7f2e2dSJohn Marino
2005cf7f2e2dSJohn Marino static long
decode_packed_array_bitsize(struct type * type)2006cf7f2e2dSJohn Marino decode_packed_array_bitsize (struct type *type)
2007cf7f2e2dSJohn Marino {
2008*ef5ccd6cSJohn Marino const char *raw_name;
2009*ef5ccd6cSJohn Marino const char *tail;
2010cf7f2e2dSJohn Marino long bits;
2011cf7f2e2dSJohn Marino
2012c50c785cSJohn Marino /* Access to arrays implemented as fat pointers are encoded as a typedef
2013c50c785cSJohn Marino of the fat pointer type. We need the name of the fat pointer type
2014c50c785cSJohn Marino to do the decoding, so strip the typedef layer. */
2015c50c785cSJohn Marino if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
2016c50c785cSJohn Marino type = ada_typedef_target_type (type);
2017c50c785cSJohn Marino
2018c50c785cSJohn Marino raw_name = ada_type_name (ada_check_typedef (type));
2019cf7f2e2dSJohn Marino if (!raw_name)
2020cf7f2e2dSJohn Marino raw_name = ada_type_name (desc_base_type (type));
2021cf7f2e2dSJohn Marino
2022cf7f2e2dSJohn Marino if (!raw_name)
2023cf7f2e2dSJohn Marino return 0;
2024cf7f2e2dSJohn Marino
2025cf7f2e2dSJohn Marino tail = strstr (raw_name, "___XP");
2026c50c785cSJohn Marino gdb_assert (tail != NULL);
2027cf7f2e2dSJohn Marino
2028cf7f2e2dSJohn Marino if (sscanf (tail + sizeof ("___XP") - 1, "%ld", &bits) != 1)
2029cf7f2e2dSJohn Marino {
2030cf7f2e2dSJohn Marino lim_warning
2031cf7f2e2dSJohn Marino (_("could not understand bit size information on packed array"));
2032cf7f2e2dSJohn Marino return 0;
2033cf7f2e2dSJohn Marino }
2034cf7f2e2dSJohn Marino
2035cf7f2e2dSJohn Marino return bits;
2036cf7f2e2dSJohn Marino }
2037cf7f2e2dSJohn Marino
20385796c8dcSSimon Schubert /* Given that TYPE is a standard GDB array type with all bounds filled
20395796c8dcSSimon Schubert in, and that the element size of its ultimate scalar constituents
20405796c8dcSSimon Schubert (that is, either its elements, or, if it is an array of arrays, its
20415796c8dcSSimon Schubert elements' elements, etc.) is *ELT_BITS, return an identical type,
20425796c8dcSSimon Schubert but with the bit sizes of its elements (and those of any
20435796c8dcSSimon Schubert constituent arrays) recorded in the BITSIZE components of its
20445796c8dcSSimon Schubert TYPE_FIELD_BITSIZE values, and with *ELT_BITS set to its total size
20455796c8dcSSimon Schubert in bits. */
20465796c8dcSSimon Schubert
20475796c8dcSSimon Schubert static struct type *
constrained_packed_array_type(struct type * type,long * elt_bits)2048cf7f2e2dSJohn Marino constrained_packed_array_type (struct type *type, long *elt_bits)
20495796c8dcSSimon Schubert {
20505796c8dcSSimon Schubert struct type *new_elt_type;
20515796c8dcSSimon Schubert struct type *new_type;
2052*ef5ccd6cSJohn Marino struct type *index_type_desc;
2053*ef5ccd6cSJohn Marino struct type *index_type;
20545796c8dcSSimon Schubert LONGEST low_bound, high_bound;
20555796c8dcSSimon Schubert
20565796c8dcSSimon Schubert type = ada_check_typedef (type);
20575796c8dcSSimon Schubert if (TYPE_CODE (type) != TYPE_CODE_ARRAY)
20585796c8dcSSimon Schubert return type;
20595796c8dcSSimon Schubert
2060*ef5ccd6cSJohn Marino index_type_desc = ada_find_parallel_type (type, "___XA");
2061*ef5ccd6cSJohn Marino if (index_type_desc)
2062*ef5ccd6cSJohn Marino index_type = to_fixed_range_type (TYPE_FIELD_TYPE (index_type_desc, 0),
2063*ef5ccd6cSJohn Marino NULL);
2064*ef5ccd6cSJohn Marino else
2065*ef5ccd6cSJohn Marino index_type = TYPE_INDEX_TYPE (type);
2066*ef5ccd6cSJohn Marino
20675796c8dcSSimon Schubert new_type = alloc_type_copy (type);
2068cf7f2e2dSJohn Marino new_elt_type =
2069cf7f2e2dSJohn Marino constrained_packed_array_type (ada_check_typedef (TYPE_TARGET_TYPE (type)),
20705796c8dcSSimon Schubert elt_bits);
2071*ef5ccd6cSJohn Marino create_array_type (new_type, new_elt_type, index_type);
20725796c8dcSSimon Schubert TYPE_FIELD_BITSIZE (new_type, 0) = *elt_bits;
20735796c8dcSSimon Schubert TYPE_NAME (new_type) = ada_type_name (type);
20745796c8dcSSimon Schubert
2075*ef5ccd6cSJohn Marino if (get_discrete_bounds (index_type, &low_bound, &high_bound) < 0)
20765796c8dcSSimon Schubert low_bound = high_bound = 0;
20775796c8dcSSimon Schubert if (high_bound < low_bound)
20785796c8dcSSimon Schubert *elt_bits = TYPE_LENGTH (new_type) = 0;
20795796c8dcSSimon Schubert else
20805796c8dcSSimon Schubert {
20815796c8dcSSimon Schubert *elt_bits *= (high_bound - low_bound + 1);
20825796c8dcSSimon Schubert TYPE_LENGTH (new_type) =
20835796c8dcSSimon Schubert (*elt_bits + HOST_CHAR_BIT - 1) / HOST_CHAR_BIT;
20845796c8dcSSimon Schubert }
20855796c8dcSSimon Schubert
20865796c8dcSSimon Schubert TYPE_FIXED_INSTANCE (new_type) = 1;
20875796c8dcSSimon Schubert return new_type;
20885796c8dcSSimon Schubert }
20895796c8dcSSimon Schubert
2090cf7f2e2dSJohn Marino /* The array type encoded by TYPE, where
2091cf7f2e2dSJohn Marino ada_is_constrained_packed_array_type (TYPE). */
20925796c8dcSSimon Schubert
20935796c8dcSSimon Schubert static struct type *
decode_constrained_packed_array_type(struct type * type)2094cf7f2e2dSJohn Marino decode_constrained_packed_array_type (struct type *type)
20955796c8dcSSimon Schubert {
2096*ef5ccd6cSJohn Marino const char *raw_name = ada_type_name (ada_check_typedef (type));
20975796c8dcSSimon Schubert char *name;
2098*ef5ccd6cSJohn Marino const char *tail;
20995796c8dcSSimon Schubert struct type *shadow_type;
21005796c8dcSSimon Schubert long bits;
21015796c8dcSSimon Schubert
21025796c8dcSSimon Schubert if (!raw_name)
21035796c8dcSSimon Schubert raw_name = ada_type_name (desc_base_type (type));
21045796c8dcSSimon Schubert
21055796c8dcSSimon Schubert if (!raw_name)
21065796c8dcSSimon Schubert return NULL;
21075796c8dcSSimon Schubert
21085796c8dcSSimon Schubert name = (char *) alloca (strlen (raw_name) + 1);
21095796c8dcSSimon Schubert tail = strstr (raw_name, "___XP");
21105796c8dcSSimon Schubert type = desc_base_type (type);
21115796c8dcSSimon Schubert
21125796c8dcSSimon Schubert memcpy (name, raw_name, tail - raw_name);
21135796c8dcSSimon Schubert name[tail - raw_name] = '\000';
21145796c8dcSSimon Schubert
2115cf7f2e2dSJohn Marino shadow_type = ada_find_parallel_type_with_name (type, name);
2116cf7f2e2dSJohn Marino
2117cf7f2e2dSJohn Marino if (shadow_type == NULL)
21185796c8dcSSimon Schubert {
21195796c8dcSSimon Schubert lim_warning (_("could not find bounds information on packed array"));
21205796c8dcSSimon Schubert return NULL;
21215796c8dcSSimon Schubert }
21225796c8dcSSimon Schubert CHECK_TYPEDEF (shadow_type);
21235796c8dcSSimon Schubert
21245796c8dcSSimon Schubert if (TYPE_CODE (shadow_type) != TYPE_CODE_ARRAY)
21255796c8dcSSimon Schubert {
2126c50c785cSJohn Marino lim_warning (_("could not understand bounds "
2127c50c785cSJohn Marino "information on packed array"));
21285796c8dcSSimon Schubert return NULL;
21295796c8dcSSimon Schubert }
21305796c8dcSSimon Schubert
2131cf7f2e2dSJohn Marino bits = decode_packed_array_bitsize (type);
2132cf7f2e2dSJohn Marino return constrained_packed_array_type (shadow_type, &bits);
21335796c8dcSSimon Schubert }
21345796c8dcSSimon Schubert
2135cf7f2e2dSJohn Marino /* Given that ARR is a struct value *indicating a GNAT constrained packed
2136cf7f2e2dSJohn Marino array, returns a simple array that denotes that array. Its type is a
21375796c8dcSSimon Schubert standard GDB array type except that the BITSIZEs of the array
21385796c8dcSSimon Schubert target types are set to the number of bits in each element, and the
21395796c8dcSSimon Schubert type length is set appropriately. */
21405796c8dcSSimon Schubert
21415796c8dcSSimon Schubert static struct value *
decode_constrained_packed_array(struct value * arr)2142cf7f2e2dSJohn Marino decode_constrained_packed_array (struct value *arr)
21435796c8dcSSimon Schubert {
21445796c8dcSSimon Schubert struct type *type;
21455796c8dcSSimon Schubert
21465796c8dcSSimon Schubert arr = ada_coerce_ref (arr);
21475796c8dcSSimon Schubert
21485796c8dcSSimon Schubert /* If our value is a pointer, then dererence it. Make sure that
21495796c8dcSSimon Schubert this operation does not cause the target type to be fixed, as
21505796c8dcSSimon Schubert this would indirectly cause this array to be decoded. The rest
21515796c8dcSSimon Schubert of the routine assumes that the array hasn't been decoded yet,
21525796c8dcSSimon Schubert so we use the basic "value_ind" routine to perform the dereferencing,
21535796c8dcSSimon Schubert as opposed to using "ada_value_ind". */
2154a45ae5f8SJohn Marino if (TYPE_CODE (ada_check_typedef (value_type (arr))) == TYPE_CODE_PTR)
21555796c8dcSSimon Schubert arr = value_ind (arr);
21565796c8dcSSimon Schubert
2157cf7f2e2dSJohn Marino type = decode_constrained_packed_array_type (value_type (arr));
21585796c8dcSSimon Schubert if (type == NULL)
21595796c8dcSSimon Schubert {
21605796c8dcSSimon Schubert error (_("can't unpack array"));
21615796c8dcSSimon Schubert return NULL;
21625796c8dcSSimon Schubert }
21635796c8dcSSimon Schubert
21645796c8dcSSimon Schubert if (gdbarch_bits_big_endian (get_type_arch (value_type (arr)))
21655796c8dcSSimon Schubert && ada_is_modular_type (value_type (arr)))
21665796c8dcSSimon Schubert {
21675796c8dcSSimon Schubert /* This is a (right-justified) modular type representing a packed
21685796c8dcSSimon Schubert array with no wrapper. In order to interpret the value through
21695796c8dcSSimon Schubert the (left-justified) packed array type we just built, we must
21705796c8dcSSimon Schubert first left-justify it. */
21715796c8dcSSimon Schubert int bit_size, bit_pos;
21725796c8dcSSimon Schubert ULONGEST mod;
21735796c8dcSSimon Schubert
21745796c8dcSSimon Schubert mod = ada_modulus (value_type (arr)) - 1;
21755796c8dcSSimon Schubert bit_size = 0;
21765796c8dcSSimon Schubert while (mod > 0)
21775796c8dcSSimon Schubert {
21785796c8dcSSimon Schubert bit_size += 1;
21795796c8dcSSimon Schubert mod >>= 1;
21805796c8dcSSimon Schubert }
21815796c8dcSSimon Schubert bit_pos = HOST_CHAR_BIT * TYPE_LENGTH (value_type (arr)) - bit_size;
21825796c8dcSSimon Schubert arr = ada_value_primitive_packed_val (arr, NULL,
21835796c8dcSSimon Schubert bit_pos / HOST_CHAR_BIT,
21845796c8dcSSimon Schubert bit_pos % HOST_CHAR_BIT,
21855796c8dcSSimon Schubert bit_size,
21865796c8dcSSimon Schubert type);
21875796c8dcSSimon Schubert }
21885796c8dcSSimon Schubert
21895796c8dcSSimon Schubert return coerce_unspec_val_to_type (arr, type);
21905796c8dcSSimon Schubert }
21915796c8dcSSimon Schubert
21925796c8dcSSimon Schubert
21935796c8dcSSimon Schubert /* The value of the element of packed array ARR at the ARITY indices
21945796c8dcSSimon Schubert given in IND. ARR must be a simple array. */
21955796c8dcSSimon Schubert
21965796c8dcSSimon Schubert static struct value *
value_subscript_packed(struct value * arr,int arity,struct value ** ind)21975796c8dcSSimon Schubert value_subscript_packed (struct value *arr, int arity, struct value **ind)
21985796c8dcSSimon Schubert {
21995796c8dcSSimon Schubert int i;
22005796c8dcSSimon Schubert int bits, elt_off, bit_off;
22015796c8dcSSimon Schubert long elt_total_bit_offset;
22025796c8dcSSimon Schubert struct type *elt_type;
22035796c8dcSSimon Schubert struct value *v;
22045796c8dcSSimon Schubert
22055796c8dcSSimon Schubert bits = 0;
22065796c8dcSSimon Schubert elt_total_bit_offset = 0;
22075796c8dcSSimon Schubert elt_type = ada_check_typedef (value_type (arr));
22085796c8dcSSimon Schubert for (i = 0; i < arity; i += 1)
22095796c8dcSSimon Schubert {
22105796c8dcSSimon Schubert if (TYPE_CODE (elt_type) != TYPE_CODE_ARRAY
22115796c8dcSSimon Schubert || TYPE_FIELD_BITSIZE (elt_type, 0) == 0)
22125796c8dcSSimon Schubert error
2213c50c785cSJohn Marino (_("attempt to do packed indexing of "
2214c50c785cSJohn Marino "something other than a packed array"));
22155796c8dcSSimon Schubert else
22165796c8dcSSimon Schubert {
22175796c8dcSSimon Schubert struct type *range_type = TYPE_INDEX_TYPE (elt_type);
22185796c8dcSSimon Schubert LONGEST lowerbound, upperbound;
22195796c8dcSSimon Schubert LONGEST idx;
22205796c8dcSSimon Schubert
22215796c8dcSSimon Schubert if (get_discrete_bounds (range_type, &lowerbound, &upperbound) < 0)
22225796c8dcSSimon Schubert {
22235796c8dcSSimon Schubert lim_warning (_("don't know bounds of array"));
22245796c8dcSSimon Schubert lowerbound = upperbound = 0;
22255796c8dcSSimon Schubert }
22265796c8dcSSimon Schubert
22275796c8dcSSimon Schubert idx = pos_atr (ind[i]);
22285796c8dcSSimon Schubert if (idx < lowerbound || idx > upperbound)
2229c50c785cSJohn Marino lim_warning (_("packed array index %ld out of bounds"),
2230c50c785cSJohn Marino (long) idx);
22315796c8dcSSimon Schubert bits = TYPE_FIELD_BITSIZE (elt_type, 0);
22325796c8dcSSimon Schubert elt_total_bit_offset += (idx - lowerbound) * bits;
22335796c8dcSSimon Schubert elt_type = ada_check_typedef (TYPE_TARGET_TYPE (elt_type));
22345796c8dcSSimon Schubert }
22355796c8dcSSimon Schubert }
22365796c8dcSSimon Schubert elt_off = elt_total_bit_offset / HOST_CHAR_BIT;
22375796c8dcSSimon Schubert bit_off = elt_total_bit_offset % HOST_CHAR_BIT;
22385796c8dcSSimon Schubert
22395796c8dcSSimon Schubert v = ada_value_primitive_packed_val (arr, NULL, elt_off, bit_off,
22405796c8dcSSimon Schubert bits, elt_type);
22415796c8dcSSimon Schubert return v;
22425796c8dcSSimon Schubert }
22435796c8dcSSimon Schubert
22445796c8dcSSimon Schubert /* Non-zero iff TYPE includes negative integer values. */
22455796c8dcSSimon Schubert
22465796c8dcSSimon Schubert static int
has_negatives(struct type * type)22475796c8dcSSimon Schubert has_negatives (struct type *type)
22485796c8dcSSimon Schubert {
22495796c8dcSSimon Schubert switch (TYPE_CODE (type))
22505796c8dcSSimon Schubert {
22515796c8dcSSimon Schubert default:
22525796c8dcSSimon Schubert return 0;
22535796c8dcSSimon Schubert case TYPE_CODE_INT:
22545796c8dcSSimon Schubert return !TYPE_UNSIGNED (type);
22555796c8dcSSimon Schubert case TYPE_CODE_RANGE:
22565796c8dcSSimon Schubert return TYPE_LOW_BOUND (type) < 0;
22575796c8dcSSimon Schubert }
22585796c8dcSSimon Schubert }
22595796c8dcSSimon Schubert
22605796c8dcSSimon Schubert
22615796c8dcSSimon Schubert /* Create a new value of type TYPE from the contents of OBJ starting
22625796c8dcSSimon Schubert at byte OFFSET, and bit offset BIT_OFFSET within that byte,
22635796c8dcSSimon Schubert proceeding for BIT_SIZE bits. If OBJ is an lval in memory, then
22645796c8dcSSimon Schubert assigning through the result will set the field fetched from.
22655796c8dcSSimon Schubert VALADDR is ignored unless OBJ is NULL, in which case,
22665796c8dcSSimon Schubert VALADDR+OFFSET must address the start of storage containing the
22675796c8dcSSimon Schubert packed value. The value returned in this case is never an lval.
22685796c8dcSSimon Schubert Assumes 0 <= BIT_OFFSET < HOST_CHAR_BIT. */
22695796c8dcSSimon Schubert
22705796c8dcSSimon Schubert struct value *
ada_value_primitive_packed_val(struct value * obj,const gdb_byte * valaddr,long offset,int bit_offset,int bit_size,struct type * type)22715796c8dcSSimon Schubert ada_value_primitive_packed_val (struct value *obj, const gdb_byte *valaddr,
22725796c8dcSSimon Schubert long offset, int bit_offset, int bit_size,
22735796c8dcSSimon Schubert struct type *type)
22745796c8dcSSimon Schubert {
22755796c8dcSSimon Schubert struct value *v;
22765796c8dcSSimon Schubert int src, /* Index into the source area */
22775796c8dcSSimon Schubert targ, /* Index into the target area */
22785796c8dcSSimon Schubert srcBitsLeft, /* Number of source bits left to move */
22795796c8dcSSimon Schubert nsrc, ntarg, /* Number of source and target bytes */
22805796c8dcSSimon Schubert unusedLS, /* Number of bits in next significant
22815796c8dcSSimon Schubert byte of source that are unused */
22825796c8dcSSimon Schubert accumSize; /* Number of meaningful bits in accum */
22835796c8dcSSimon Schubert unsigned char *bytes; /* First byte containing data to unpack */
22845796c8dcSSimon Schubert unsigned char *unpacked;
22855796c8dcSSimon Schubert unsigned long accum; /* Staging area for bits being transferred */
22865796c8dcSSimon Schubert unsigned char sign;
22875796c8dcSSimon Schubert int len = (bit_size + bit_offset + HOST_CHAR_BIT - 1) / 8;
22885796c8dcSSimon Schubert /* Transmit bytes from least to most significant; delta is the direction
22895796c8dcSSimon Schubert the indices move. */
22905796c8dcSSimon Schubert int delta = gdbarch_bits_big_endian (get_type_arch (type)) ? -1 : 1;
22915796c8dcSSimon Schubert
22925796c8dcSSimon Schubert type = ada_check_typedef (type);
22935796c8dcSSimon Schubert
22945796c8dcSSimon Schubert if (obj == NULL)
22955796c8dcSSimon Schubert {
22965796c8dcSSimon Schubert v = allocate_value (type);
22975796c8dcSSimon Schubert bytes = (unsigned char *) (valaddr + offset);
22985796c8dcSSimon Schubert }
22995796c8dcSSimon Schubert else if (VALUE_LVAL (obj) == lval_memory && value_lazy (obj))
23005796c8dcSSimon Schubert {
2301*ef5ccd6cSJohn Marino v = value_at (type, value_address (obj));
23025796c8dcSSimon Schubert bytes = (unsigned char *) alloca (len);
2303*ef5ccd6cSJohn Marino read_memory (value_address (v) + offset, bytes, len);
23045796c8dcSSimon Schubert }
23055796c8dcSSimon Schubert else
23065796c8dcSSimon Schubert {
23075796c8dcSSimon Schubert v = allocate_value (type);
23085796c8dcSSimon Schubert bytes = (unsigned char *) value_contents (obj) + offset;
23095796c8dcSSimon Schubert }
23105796c8dcSSimon Schubert
23115796c8dcSSimon Schubert if (obj != NULL)
23125796c8dcSSimon Schubert {
2313*ef5ccd6cSJohn Marino long new_offset = offset;
2314cf7f2e2dSJohn Marino
23155796c8dcSSimon Schubert set_value_component_location (v, obj);
23165796c8dcSSimon Schubert set_value_bitpos (v, bit_offset + value_bitpos (obj));
23175796c8dcSSimon Schubert set_value_bitsize (v, bit_size);
23185796c8dcSSimon Schubert if (value_bitpos (v) >= HOST_CHAR_BIT)
23195796c8dcSSimon Schubert {
2320*ef5ccd6cSJohn Marino ++new_offset;
23215796c8dcSSimon Schubert set_value_bitpos (v, value_bitpos (v) - HOST_CHAR_BIT);
23225796c8dcSSimon Schubert }
2323*ef5ccd6cSJohn Marino set_value_offset (v, new_offset);
2324*ef5ccd6cSJohn Marino
2325*ef5ccd6cSJohn Marino /* Also set the parent value. This is needed when trying to
2326*ef5ccd6cSJohn Marino assign a new value (in inferior memory). */
2327*ef5ccd6cSJohn Marino set_value_parent (v, obj);
2328*ef5ccd6cSJohn Marino value_incref (obj);
23295796c8dcSSimon Schubert }
23305796c8dcSSimon Schubert else
23315796c8dcSSimon Schubert set_value_bitsize (v, bit_size);
23325796c8dcSSimon Schubert unpacked = (unsigned char *) value_contents (v);
23335796c8dcSSimon Schubert
23345796c8dcSSimon Schubert srcBitsLeft = bit_size;
23355796c8dcSSimon Schubert nsrc = len;
23365796c8dcSSimon Schubert ntarg = TYPE_LENGTH (type);
23375796c8dcSSimon Schubert sign = 0;
23385796c8dcSSimon Schubert if (bit_size == 0)
23395796c8dcSSimon Schubert {
23405796c8dcSSimon Schubert memset (unpacked, 0, TYPE_LENGTH (type));
23415796c8dcSSimon Schubert return v;
23425796c8dcSSimon Schubert }
23435796c8dcSSimon Schubert else if (gdbarch_bits_big_endian (get_type_arch (type)))
23445796c8dcSSimon Schubert {
23455796c8dcSSimon Schubert src = len - 1;
23465796c8dcSSimon Schubert if (has_negatives (type)
23475796c8dcSSimon Schubert && ((bytes[0] << bit_offset) & (1 << (HOST_CHAR_BIT - 1))))
23485796c8dcSSimon Schubert sign = ~0;
23495796c8dcSSimon Schubert
23505796c8dcSSimon Schubert unusedLS =
23515796c8dcSSimon Schubert (HOST_CHAR_BIT - (bit_size + bit_offset) % HOST_CHAR_BIT)
23525796c8dcSSimon Schubert % HOST_CHAR_BIT;
23535796c8dcSSimon Schubert
23545796c8dcSSimon Schubert switch (TYPE_CODE (type))
23555796c8dcSSimon Schubert {
23565796c8dcSSimon Schubert case TYPE_CODE_ARRAY:
23575796c8dcSSimon Schubert case TYPE_CODE_UNION:
23585796c8dcSSimon Schubert case TYPE_CODE_STRUCT:
23595796c8dcSSimon Schubert /* Non-scalar values must be aligned at a byte boundary... */
23605796c8dcSSimon Schubert accumSize =
23615796c8dcSSimon Schubert (HOST_CHAR_BIT - bit_size % HOST_CHAR_BIT) % HOST_CHAR_BIT;
23625796c8dcSSimon Schubert /* ... And are placed at the beginning (most-significant) bytes
23635796c8dcSSimon Schubert of the target. */
23645796c8dcSSimon Schubert targ = (bit_size + HOST_CHAR_BIT - 1) / HOST_CHAR_BIT - 1;
23655796c8dcSSimon Schubert ntarg = targ + 1;
23665796c8dcSSimon Schubert break;
23675796c8dcSSimon Schubert default:
23685796c8dcSSimon Schubert accumSize = 0;
23695796c8dcSSimon Schubert targ = TYPE_LENGTH (type) - 1;
23705796c8dcSSimon Schubert break;
23715796c8dcSSimon Schubert }
23725796c8dcSSimon Schubert }
23735796c8dcSSimon Schubert else
23745796c8dcSSimon Schubert {
23755796c8dcSSimon Schubert int sign_bit_offset = (bit_size + bit_offset - 1) % 8;
23765796c8dcSSimon Schubert
23775796c8dcSSimon Schubert src = targ = 0;
23785796c8dcSSimon Schubert unusedLS = bit_offset;
23795796c8dcSSimon Schubert accumSize = 0;
23805796c8dcSSimon Schubert
23815796c8dcSSimon Schubert if (has_negatives (type) && (bytes[len - 1] & (1 << sign_bit_offset)))
23825796c8dcSSimon Schubert sign = ~0;
23835796c8dcSSimon Schubert }
23845796c8dcSSimon Schubert
23855796c8dcSSimon Schubert accum = 0;
23865796c8dcSSimon Schubert while (nsrc > 0)
23875796c8dcSSimon Schubert {
23885796c8dcSSimon Schubert /* Mask for removing bits of the next source byte that are not
23895796c8dcSSimon Schubert part of the value. */
23905796c8dcSSimon Schubert unsigned int unusedMSMask =
23915796c8dcSSimon Schubert (1 << (srcBitsLeft >= HOST_CHAR_BIT ? HOST_CHAR_BIT : srcBitsLeft)) -
23925796c8dcSSimon Schubert 1;
23935796c8dcSSimon Schubert /* Sign-extend bits for this byte. */
23945796c8dcSSimon Schubert unsigned int signMask = sign & ~unusedMSMask;
2395cf7f2e2dSJohn Marino
23965796c8dcSSimon Schubert accum |=
23975796c8dcSSimon Schubert (((bytes[src] >> unusedLS) & unusedMSMask) | signMask) << accumSize;
23985796c8dcSSimon Schubert accumSize += HOST_CHAR_BIT - unusedLS;
23995796c8dcSSimon Schubert if (accumSize >= HOST_CHAR_BIT)
24005796c8dcSSimon Schubert {
24015796c8dcSSimon Schubert unpacked[targ] = accum & ~(~0L << HOST_CHAR_BIT);
24025796c8dcSSimon Schubert accumSize -= HOST_CHAR_BIT;
24035796c8dcSSimon Schubert accum >>= HOST_CHAR_BIT;
24045796c8dcSSimon Schubert ntarg -= 1;
24055796c8dcSSimon Schubert targ += delta;
24065796c8dcSSimon Schubert }
24075796c8dcSSimon Schubert srcBitsLeft -= HOST_CHAR_BIT - unusedLS;
24085796c8dcSSimon Schubert unusedLS = 0;
24095796c8dcSSimon Schubert nsrc -= 1;
24105796c8dcSSimon Schubert src += delta;
24115796c8dcSSimon Schubert }
24125796c8dcSSimon Schubert while (ntarg > 0)
24135796c8dcSSimon Schubert {
24145796c8dcSSimon Schubert accum |= sign << accumSize;
24155796c8dcSSimon Schubert unpacked[targ] = accum & ~(~0L << HOST_CHAR_BIT);
24165796c8dcSSimon Schubert accumSize -= HOST_CHAR_BIT;
24175796c8dcSSimon Schubert accum >>= HOST_CHAR_BIT;
24185796c8dcSSimon Schubert ntarg -= 1;
24195796c8dcSSimon Schubert targ += delta;
24205796c8dcSSimon Schubert }
24215796c8dcSSimon Schubert
24225796c8dcSSimon Schubert return v;
24235796c8dcSSimon Schubert }
24245796c8dcSSimon Schubert
24255796c8dcSSimon Schubert /* Move N bits from SOURCE, starting at bit offset SRC_OFFSET to
24265796c8dcSSimon Schubert TARGET, starting at bit offset TARG_OFFSET. SOURCE and TARGET must
24275796c8dcSSimon Schubert not overlap. */
24285796c8dcSSimon Schubert static void
move_bits(gdb_byte * target,int targ_offset,const gdb_byte * source,int src_offset,int n,int bits_big_endian_p)24295796c8dcSSimon Schubert move_bits (gdb_byte *target, int targ_offset, const gdb_byte *source,
24305796c8dcSSimon Schubert int src_offset, int n, int bits_big_endian_p)
24315796c8dcSSimon Schubert {
24325796c8dcSSimon Schubert unsigned int accum, mask;
24335796c8dcSSimon Schubert int accum_bits, chunk_size;
24345796c8dcSSimon Schubert
24355796c8dcSSimon Schubert target += targ_offset / HOST_CHAR_BIT;
24365796c8dcSSimon Schubert targ_offset %= HOST_CHAR_BIT;
24375796c8dcSSimon Schubert source += src_offset / HOST_CHAR_BIT;
24385796c8dcSSimon Schubert src_offset %= HOST_CHAR_BIT;
24395796c8dcSSimon Schubert if (bits_big_endian_p)
24405796c8dcSSimon Schubert {
24415796c8dcSSimon Schubert accum = (unsigned char) *source;
24425796c8dcSSimon Schubert source += 1;
24435796c8dcSSimon Schubert accum_bits = HOST_CHAR_BIT - src_offset;
24445796c8dcSSimon Schubert
24455796c8dcSSimon Schubert while (n > 0)
24465796c8dcSSimon Schubert {
24475796c8dcSSimon Schubert int unused_right;
2448cf7f2e2dSJohn Marino
24495796c8dcSSimon Schubert accum = (accum << HOST_CHAR_BIT) + (unsigned char) *source;
24505796c8dcSSimon Schubert accum_bits += HOST_CHAR_BIT;
24515796c8dcSSimon Schubert source += 1;
24525796c8dcSSimon Schubert chunk_size = HOST_CHAR_BIT - targ_offset;
24535796c8dcSSimon Schubert if (chunk_size > n)
24545796c8dcSSimon Schubert chunk_size = n;
24555796c8dcSSimon Schubert unused_right = HOST_CHAR_BIT - (chunk_size + targ_offset);
24565796c8dcSSimon Schubert mask = ((1 << chunk_size) - 1) << unused_right;
24575796c8dcSSimon Schubert *target =
24585796c8dcSSimon Schubert (*target & ~mask)
24595796c8dcSSimon Schubert | ((accum >> (accum_bits - chunk_size - unused_right)) & mask);
24605796c8dcSSimon Schubert n -= chunk_size;
24615796c8dcSSimon Schubert accum_bits -= chunk_size;
24625796c8dcSSimon Schubert target += 1;
24635796c8dcSSimon Schubert targ_offset = 0;
24645796c8dcSSimon Schubert }
24655796c8dcSSimon Schubert }
24665796c8dcSSimon Schubert else
24675796c8dcSSimon Schubert {
24685796c8dcSSimon Schubert accum = (unsigned char) *source >> src_offset;
24695796c8dcSSimon Schubert source += 1;
24705796c8dcSSimon Schubert accum_bits = HOST_CHAR_BIT - src_offset;
24715796c8dcSSimon Schubert
24725796c8dcSSimon Schubert while (n > 0)
24735796c8dcSSimon Schubert {
24745796c8dcSSimon Schubert accum = accum + ((unsigned char) *source << accum_bits);
24755796c8dcSSimon Schubert accum_bits += HOST_CHAR_BIT;
24765796c8dcSSimon Schubert source += 1;
24775796c8dcSSimon Schubert chunk_size = HOST_CHAR_BIT - targ_offset;
24785796c8dcSSimon Schubert if (chunk_size > n)
24795796c8dcSSimon Schubert chunk_size = n;
24805796c8dcSSimon Schubert mask = ((1 << chunk_size) - 1) << targ_offset;
24815796c8dcSSimon Schubert *target = (*target & ~mask) | ((accum << targ_offset) & mask);
24825796c8dcSSimon Schubert n -= chunk_size;
24835796c8dcSSimon Schubert accum_bits -= chunk_size;
24845796c8dcSSimon Schubert accum >>= chunk_size;
24855796c8dcSSimon Schubert target += 1;
24865796c8dcSSimon Schubert targ_offset = 0;
24875796c8dcSSimon Schubert }
24885796c8dcSSimon Schubert }
24895796c8dcSSimon Schubert }
24905796c8dcSSimon Schubert
24915796c8dcSSimon Schubert /* Store the contents of FROMVAL into the location of TOVAL.
24925796c8dcSSimon Schubert Return a new value with the location of TOVAL and contents of
24935796c8dcSSimon Schubert FROMVAL. Handles assignment into packed fields that have
24945796c8dcSSimon Schubert floating-point or non-scalar types. */
24955796c8dcSSimon Schubert
24965796c8dcSSimon Schubert static struct value *
ada_value_assign(struct value * toval,struct value * fromval)24975796c8dcSSimon Schubert ada_value_assign (struct value *toval, struct value *fromval)
24985796c8dcSSimon Schubert {
24995796c8dcSSimon Schubert struct type *type = value_type (toval);
25005796c8dcSSimon Schubert int bits = value_bitsize (toval);
25015796c8dcSSimon Schubert
25025796c8dcSSimon Schubert toval = ada_coerce_ref (toval);
25035796c8dcSSimon Schubert fromval = ada_coerce_ref (fromval);
25045796c8dcSSimon Schubert
25055796c8dcSSimon Schubert if (ada_is_direct_array_type (value_type (toval)))
25065796c8dcSSimon Schubert toval = ada_coerce_to_simple_array (toval);
25075796c8dcSSimon Schubert if (ada_is_direct_array_type (value_type (fromval)))
25085796c8dcSSimon Schubert fromval = ada_coerce_to_simple_array (fromval);
25095796c8dcSSimon Schubert
25105796c8dcSSimon Schubert if (!deprecated_value_modifiable (toval))
25115796c8dcSSimon Schubert error (_("Left operand of assignment is not a modifiable lvalue."));
25125796c8dcSSimon Schubert
25135796c8dcSSimon Schubert if (VALUE_LVAL (toval) == lval_memory
25145796c8dcSSimon Schubert && bits > 0
25155796c8dcSSimon Schubert && (TYPE_CODE (type) == TYPE_CODE_FLT
25165796c8dcSSimon Schubert || TYPE_CODE (type) == TYPE_CODE_STRUCT))
25175796c8dcSSimon Schubert {
25185796c8dcSSimon Schubert int len = (value_bitpos (toval)
25195796c8dcSSimon Schubert + bits + HOST_CHAR_BIT - 1) / HOST_CHAR_BIT;
25205796c8dcSSimon Schubert int from_size;
25215796c8dcSSimon Schubert char *buffer = (char *) alloca (len);
25225796c8dcSSimon Schubert struct value *val;
25235796c8dcSSimon Schubert CORE_ADDR to_addr = value_address (toval);
25245796c8dcSSimon Schubert
25255796c8dcSSimon Schubert if (TYPE_CODE (type) == TYPE_CODE_FLT)
25265796c8dcSSimon Schubert fromval = value_cast (type, fromval);
25275796c8dcSSimon Schubert
25285796c8dcSSimon Schubert read_memory (to_addr, buffer, len);
25295796c8dcSSimon Schubert from_size = value_bitsize (fromval);
25305796c8dcSSimon Schubert if (from_size == 0)
25315796c8dcSSimon Schubert from_size = TYPE_LENGTH (value_type (fromval)) * TARGET_CHAR_BIT;
25325796c8dcSSimon Schubert if (gdbarch_bits_big_endian (get_type_arch (type)))
25335796c8dcSSimon Schubert move_bits (buffer, value_bitpos (toval),
25345796c8dcSSimon Schubert value_contents (fromval), from_size - bits, bits, 1);
25355796c8dcSSimon Schubert else
25365796c8dcSSimon Schubert move_bits (buffer, value_bitpos (toval),
25375796c8dcSSimon Schubert value_contents (fromval), 0, bits, 0);
2538*ef5ccd6cSJohn Marino write_memory_with_notification (to_addr, buffer, len);
25395796c8dcSSimon Schubert
25405796c8dcSSimon Schubert val = value_copy (toval);
25415796c8dcSSimon Schubert memcpy (value_contents_raw (val), value_contents (fromval),
25425796c8dcSSimon Schubert TYPE_LENGTH (type));
25435796c8dcSSimon Schubert deprecated_set_value_type (val, type);
25445796c8dcSSimon Schubert
25455796c8dcSSimon Schubert return val;
25465796c8dcSSimon Schubert }
25475796c8dcSSimon Schubert
25485796c8dcSSimon Schubert return value_assign (toval, fromval);
25495796c8dcSSimon Schubert }
25505796c8dcSSimon Schubert
25515796c8dcSSimon Schubert
25525796c8dcSSimon Schubert /* Given that COMPONENT is a memory lvalue that is part of the lvalue
25535796c8dcSSimon Schubert * CONTAINER, assign the contents of VAL to COMPONENTS's place in
25545796c8dcSSimon Schubert * CONTAINER. Modifies the VALUE_CONTENTS of CONTAINER only, not
25555796c8dcSSimon Schubert * COMPONENT, and not the inferior's memory. The current contents
25565796c8dcSSimon Schubert * of COMPONENT are ignored. */
25575796c8dcSSimon Schubert static void
value_assign_to_component(struct value * container,struct value * component,struct value * val)25585796c8dcSSimon Schubert value_assign_to_component (struct value *container, struct value *component,
25595796c8dcSSimon Schubert struct value *val)
25605796c8dcSSimon Schubert {
25615796c8dcSSimon Schubert LONGEST offset_in_container =
25625796c8dcSSimon Schubert (LONGEST) (value_address (component) - value_address (container));
25635796c8dcSSimon Schubert int bit_offset_in_container =
25645796c8dcSSimon Schubert value_bitpos (component) - value_bitpos (container);
25655796c8dcSSimon Schubert int bits;
25665796c8dcSSimon Schubert
25675796c8dcSSimon Schubert val = value_cast (value_type (component), val);
25685796c8dcSSimon Schubert
25695796c8dcSSimon Schubert if (value_bitsize (component) == 0)
25705796c8dcSSimon Schubert bits = TARGET_CHAR_BIT * TYPE_LENGTH (value_type (component));
25715796c8dcSSimon Schubert else
25725796c8dcSSimon Schubert bits = value_bitsize (component);
25735796c8dcSSimon Schubert
25745796c8dcSSimon Schubert if (gdbarch_bits_big_endian (get_type_arch (value_type (container))))
25755796c8dcSSimon Schubert move_bits (value_contents_writeable (container) + offset_in_container,
25765796c8dcSSimon Schubert value_bitpos (container) + bit_offset_in_container,
25775796c8dcSSimon Schubert value_contents (val),
25785796c8dcSSimon Schubert TYPE_LENGTH (value_type (component)) * TARGET_CHAR_BIT - bits,
25795796c8dcSSimon Schubert bits, 1);
25805796c8dcSSimon Schubert else
25815796c8dcSSimon Schubert move_bits (value_contents_writeable (container) + offset_in_container,
25825796c8dcSSimon Schubert value_bitpos (container) + bit_offset_in_container,
25835796c8dcSSimon Schubert value_contents (val), 0, bits, 0);
25845796c8dcSSimon Schubert }
25855796c8dcSSimon Schubert
25865796c8dcSSimon Schubert /* The value of the element of array ARR at the ARITY indices given in IND.
25875796c8dcSSimon Schubert ARR may be either a simple array, GNAT array descriptor, or pointer
25885796c8dcSSimon Schubert thereto. */
25895796c8dcSSimon Schubert
25905796c8dcSSimon Schubert struct value *
ada_value_subscript(struct value * arr,int arity,struct value ** ind)25915796c8dcSSimon Schubert ada_value_subscript (struct value *arr, int arity, struct value **ind)
25925796c8dcSSimon Schubert {
25935796c8dcSSimon Schubert int k;
25945796c8dcSSimon Schubert struct value *elt;
25955796c8dcSSimon Schubert struct type *elt_type;
25965796c8dcSSimon Schubert
25975796c8dcSSimon Schubert elt = ada_coerce_to_simple_array (arr);
25985796c8dcSSimon Schubert
25995796c8dcSSimon Schubert elt_type = ada_check_typedef (value_type (elt));
26005796c8dcSSimon Schubert if (TYPE_CODE (elt_type) == TYPE_CODE_ARRAY
26015796c8dcSSimon Schubert && TYPE_FIELD_BITSIZE (elt_type, 0) > 0)
26025796c8dcSSimon Schubert return value_subscript_packed (elt, arity, ind);
26035796c8dcSSimon Schubert
26045796c8dcSSimon Schubert for (k = 0; k < arity; k += 1)
26055796c8dcSSimon Schubert {
26065796c8dcSSimon Schubert if (TYPE_CODE (elt_type) != TYPE_CODE_ARRAY)
26075796c8dcSSimon Schubert error (_("too many subscripts (%d expected)"), k);
26085796c8dcSSimon Schubert elt = value_subscript (elt, pos_atr (ind[k]));
26095796c8dcSSimon Schubert }
26105796c8dcSSimon Schubert return elt;
26115796c8dcSSimon Schubert }
26125796c8dcSSimon Schubert
26135796c8dcSSimon Schubert /* Assuming ARR is a pointer to a standard GDB array of type TYPE, the
26145796c8dcSSimon Schubert value of the element of *ARR at the ARITY indices given in
26155796c8dcSSimon Schubert IND. Does not read the entire array into memory. */
26165796c8dcSSimon Schubert
26175796c8dcSSimon Schubert static struct value *
ada_value_ptr_subscript(struct value * arr,struct type * type,int arity,struct value ** ind)26185796c8dcSSimon Schubert ada_value_ptr_subscript (struct value *arr, struct type *type, int arity,
26195796c8dcSSimon Schubert struct value **ind)
26205796c8dcSSimon Schubert {
26215796c8dcSSimon Schubert int k;
26225796c8dcSSimon Schubert
26235796c8dcSSimon Schubert for (k = 0; k < arity; k += 1)
26245796c8dcSSimon Schubert {
26255796c8dcSSimon Schubert LONGEST lwb, upb;
26265796c8dcSSimon Schubert
26275796c8dcSSimon Schubert if (TYPE_CODE (type) != TYPE_CODE_ARRAY)
26285796c8dcSSimon Schubert error (_("too many subscripts (%d expected)"), k);
26295796c8dcSSimon Schubert arr = value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
26305796c8dcSSimon Schubert value_copy (arr));
26315796c8dcSSimon Schubert get_discrete_bounds (TYPE_INDEX_TYPE (type), &lwb, &upb);
26325796c8dcSSimon Schubert arr = value_ptradd (arr, pos_atr (ind[k]) - lwb);
26335796c8dcSSimon Schubert type = TYPE_TARGET_TYPE (type);
26345796c8dcSSimon Schubert }
26355796c8dcSSimon Schubert
26365796c8dcSSimon Schubert return value_ind (arr);
26375796c8dcSSimon Schubert }
26385796c8dcSSimon Schubert
26395796c8dcSSimon Schubert /* Given that ARRAY_PTR is a pointer or reference to an array of type TYPE (the
26405796c8dcSSimon Schubert actual type of ARRAY_PTR is ignored), returns the Ada slice of HIGH-LOW+1
26415796c8dcSSimon Schubert elements starting at index LOW. The lower bound of this array is LOW, as
26425796c8dcSSimon Schubert per Ada rules. */
26435796c8dcSSimon Schubert static struct value *
ada_value_slice_from_ptr(struct value * array_ptr,struct type * type,int low,int high)26445796c8dcSSimon Schubert ada_value_slice_from_ptr (struct value *array_ptr, struct type *type,
26455796c8dcSSimon Schubert int low, int high)
26465796c8dcSSimon Schubert {
2647c50c785cSJohn Marino struct type *type0 = ada_check_typedef (type);
26485796c8dcSSimon Schubert CORE_ADDR base = value_as_address (array_ptr)
2649c50c785cSJohn Marino + ((low - ada_discrete_type_low_bound (TYPE_INDEX_TYPE (type0)))
2650c50c785cSJohn Marino * TYPE_LENGTH (TYPE_TARGET_TYPE (type0)));
26515796c8dcSSimon Schubert struct type *index_type =
2652c50c785cSJohn Marino create_range_type (NULL, TYPE_TARGET_TYPE (TYPE_INDEX_TYPE (type0)),
26535796c8dcSSimon Schubert low, high);
26545796c8dcSSimon Schubert struct type *slice_type =
2655c50c785cSJohn Marino create_array_type (NULL, TYPE_TARGET_TYPE (type0), index_type);
2656cf7f2e2dSJohn Marino
26575796c8dcSSimon Schubert return value_at_lazy (slice_type, base);
26585796c8dcSSimon Schubert }
26595796c8dcSSimon Schubert
26605796c8dcSSimon Schubert
26615796c8dcSSimon Schubert static struct value *
ada_value_slice(struct value * array,int low,int high)26625796c8dcSSimon Schubert ada_value_slice (struct value *array, int low, int high)
26635796c8dcSSimon Schubert {
2664c50c785cSJohn Marino struct type *type = ada_check_typedef (value_type (array));
26655796c8dcSSimon Schubert struct type *index_type =
26665796c8dcSSimon Schubert create_range_type (NULL, TYPE_INDEX_TYPE (type), low, high);
26675796c8dcSSimon Schubert struct type *slice_type =
26685796c8dcSSimon Schubert create_array_type (NULL, TYPE_TARGET_TYPE (type), index_type);
2669cf7f2e2dSJohn Marino
26705796c8dcSSimon Schubert return value_cast (slice_type, value_slice (array, low, high - low + 1));
26715796c8dcSSimon Schubert }
26725796c8dcSSimon Schubert
26735796c8dcSSimon Schubert /* If type is a record type in the form of a standard GNAT array
26745796c8dcSSimon Schubert descriptor, returns the number of dimensions for type. If arr is a
26755796c8dcSSimon Schubert simple array, returns the number of "array of"s that prefix its
26765796c8dcSSimon Schubert type designation. Otherwise, returns 0. */
26775796c8dcSSimon Schubert
26785796c8dcSSimon Schubert int
ada_array_arity(struct type * type)26795796c8dcSSimon Schubert ada_array_arity (struct type *type)
26805796c8dcSSimon Schubert {
26815796c8dcSSimon Schubert int arity;
26825796c8dcSSimon Schubert
26835796c8dcSSimon Schubert if (type == NULL)
26845796c8dcSSimon Schubert return 0;
26855796c8dcSSimon Schubert
26865796c8dcSSimon Schubert type = desc_base_type (type);
26875796c8dcSSimon Schubert
26885796c8dcSSimon Schubert arity = 0;
26895796c8dcSSimon Schubert if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
26905796c8dcSSimon Schubert return desc_arity (desc_bounds_type (type));
26915796c8dcSSimon Schubert else
26925796c8dcSSimon Schubert while (TYPE_CODE (type) == TYPE_CODE_ARRAY)
26935796c8dcSSimon Schubert {
26945796c8dcSSimon Schubert arity += 1;
26955796c8dcSSimon Schubert type = ada_check_typedef (TYPE_TARGET_TYPE (type));
26965796c8dcSSimon Schubert }
26975796c8dcSSimon Schubert
26985796c8dcSSimon Schubert return arity;
26995796c8dcSSimon Schubert }
27005796c8dcSSimon Schubert
27015796c8dcSSimon Schubert /* If TYPE is a record type in the form of a standard GNAT array
27025796c8dcSSimon Schubert descriptor or a simple array type, returns the element type for
27035796c8dcSSimon Schubert TYPE after indexing by NINDICES indices, or by all indices if
27045796c8dcSSimon Schubert NINDICES is -1. Otherwise, returns NULL. */
27055796c8dcSSimon Schubert
27065796c8dcSSimon Schubert struct type *
ada_array_element_type(struct type * type,int nindices)27075796c8dcSSimon Schubert ada_array_element_type (struct type *type, int nindices)
27085796c8dcSSimon Schubert {
27095796c8dcSSimon Schubert type = desc_base_type (type);
27105796c8dcSSimon Schubert
27115796c8dcSSimon Schubert if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
27125796c8dcSSimon Schubert {
27135796c8dcSSimon Schubert int k;
27145796c8dcSSimon Schubert struct type *p_array_type;
27155796c8dcSSimon Schubert
27165796c8dcSSimon Schubert p_array_type = desc_data_target_type (type);
27175796c8dcSSimon Schubert
27185796c8dcSSimon Schubert k = ada_array_arity (type);
27195796c8dcSSimon Schubert if (k == 0)
27205796c8dcSSimon Schubert return NULL;
27215796c8dcSSimon Schubert
27225796c8dcSSimon Schubert /* Initially p_array_type = elt_type(*)[]...(k times)...[]. */
27235796c8dcSSimon Schubert if (nindices >= 0 && k > nindices)
27245796c8dcSSimon Schubert k = nindices;
27255796c8dcSSimon Schubert while (k > 0 && p_array_type != NULL)
27265796c8dcSSimon Schubert {
27275796c8dcSSimon Schubert p_array_type = ada_check_typedef (TYPE_TARGET_TYPE (p_array_type));
27285796c8dcSSimon Schubert k -= 1;
27295796c8dcSSimon Schubert }
27305796c8dcSSimon Schubert return p_array_type;
27315796c8dcSSimon Schubert }
27325796c8dcSSimon Schubert else if (TYPE_CODE (type) == TYPE_CODE_ARRAY)
27335796c8dcSSimon Schubert {
27345796c8dcSSimon Schubert while (nindices != 0 && TYPE_CODE (type) == TYPE_CODE_ARRAY)
27355796c8dcSSimon Schubert {
27365796c8dcSSimon Schubert type = TYPE_TARGET_TYPE (type);
27375796c8dcSSimon Schubert nindices -= 1;
27385796c8dcSSimon Schubert }
27395796c8dcSSimon Schubert return type;
27405796c8dcSSimon Schubert }
27415796c8dcSSimon Schubert
27425796c8dcSSimon Schubert return NULL;
27435796c8dcSSimon Schubert }
27445796c8dcSSimon Schubert
27455796c8dcSSimon Schubert /* The type of nth index in arrays of given type (n numbering from 1).
27465796c8dcSSimon Schubert Does not examine memory. Throws an error if N is invalid or TYPE
27475796c8dcSSimon Schubert is not an array type. NAME is the name of the Ada attribute being
27485796c8dcSSimon Schubert evaluated ('range, 'first, 'last, or 'length); it is used in building
27495796c8dcSSimon Schubert the error message. */
27505796c8dcSSimon Schubert
27515796c8dcSSimon Schubert static struct type *
ada_index_type(struct type * type,int n,const char * name)27525796c8dcSSimon Schubert ada_index_type (struct type *type, int n, const char *name)
27535796c8dcSSimon Schubert {
27545796c8dcSSimon Schubert struct type *result_type;
27555796c8dcSSimon Schubert
27565796c8dcSSimon Schubert type = desc_base_type (type);
27575796c8dcSSimon Schubert
27585796c8dcSSimon Schubert if (n < 0 || n > ada_array_arity (type))
27595796c8dcSSimon Schubert error (_("invalid dimension number to '%s"), name);
27605796c8dcSSimon Schubert
27615796c8dcSSimon Schubert if (ada_is_simple_array_type (type))
27625796c8dcSSimon Schubert {
27635796c8dcSSimon Schubert int i;
27645796c8dcSSimon Schubert
27655796c8dcSSimon Schubert for (i = 1; i < n; i += 1)
27665796c8dcSSimon Schubert type = TYPE_TARGET_TYPE (type);
27675796c8dcSSimon Schubert result_type = TYPE_TARGET_TYPE (TYPE_INDEX_TYPE (type));
27685796c8dcSSimon Schubert /* FIXME: The stabs type r(0,0);bound;bound in an array type
27695796c8dcSSimon Schubert has a target type of TYPE_CODE_UNDEF. We compensate here, but
27705796c8dcSSimon Schubert perhaps stabsread.c would make more sense. */
27715796c8dcSSimon Schubert if (result_type && TYPE_CODE (result_type) == TYPE_CODE_UNDEF)
27725796c8dcSSimon Schubert result_type = NULL;
27735796c8dcSSimon Schubert }
27745796c8dcSSimon Schubert else
27755796c8dcSSimon Schubert {
27765796c8dcSSimon Schubert result_type = desc_index_type (desc_bounds_type (type), n);
27775796c8dcSSimon Schubert if (result_type == NULL)
27785796c8dcSSimon Schubert error (_("attempt to take bound of something that is not an array"));
27795796c8dcSSimon Schubert }
27805796c8dcSSimon Schubert
27815796c8dcSSimon Schubert return result_type;
27825796c8dcSSimon Schubert }
27835796c8dcSSimon Schubert
27845796c8dcSSimon Schubert /* Given that arr is an array type, returns the lower bound of the
27855796c8dcSSimon Schubert Nth index (numbering from 1) if WHICH is 0, and the upper bound if
27865796c8dcSSimon Schubert WHICH is 1. This returns bounds 0 .. -1 if ARR_TYPE is an
27875796c8dcSSimon Schubert array-descriptor type. It works for other arrays with bounds supplied
27885796c8dcSSimon Schubert by run-time quantities other than discriminants. */
27895796c8dcSSimon Schubert
27905796c8dcSSimon Schubert static LONGEST
ada_array_bound_from_type(struct type * arr_type,int n,int which)27915796c8dcSSimon Schubert ada_array_bound_from_type (struct type * arr_type, int n, int which)
27925796c8dcSSimon Schubert {
27935796c8dcSSimon Schubert struct type *type, *elt_type, *index_type_desc, *index_type;
27945796c8dcSSimon Schubert int i;
27955796c8dcSSimon Schubert
27965796c8dcSSimon Schubert gdb_assert (which == 0 || which == 1);
27975796c8dcSSimon Schubert
2798cf7f2e2dSJohn Marino if (ada_is_constrained_packed_array_type (arr_type))
2799cf7f2e2dSJohn Marino arr_type = decode_constrained_packed_array_type (arr_type);
28005796c8dcSSimon Schubert
28015796c8dcSSimon Schubert if (arr_type == NULL || !ada_is_simple_array_type (arr_type))
28025796c8dcSSimon Schubert return (LONGEST) - which;
28035796c8dcSSimon Schubert
28045796c8dcSSimon Schubert if (TYPE_CODE (arr_type) == TYPE_CODE_PTR)
28055796c8dcSSimon Schubert type = TYPE_TARGET_TYPE (arr_type);
28065796c8dcSSimon Schubert else
28075796c8dcSSimon Schubert type = arr_type;
28085796c8dcSSimon Schubert
28095796c8dcSSimon Schubert elt_type = type;
28105796c8dcSSimon Schubert for (i = n; i > 1; i--)
28115796c8dcSSimon Schubert elt_type = TYPE_TARGET_TYPE (type);
28125796c8dcSSimon Schubert
28135796c8dcSSimon Schubert index_type_desc = ada_find_parallel_type (type, "___XA");
2814cf7f2e2dSJohn Marino ada_fixup_array_indexes_type (index_type_desc);
28155796c8dcSSimon Schubert if (index_type_desc != NULL)
2816cf7f2e2dSJohn Marino index_type = to_fixed_range_type (TYPE_FIELD_TYPE (index_type_desc, n - 1),
2817cf7f2e2dSJohn Marino NULL);
28185796c8dcSSimon Schubert else
28195796c8dcSSimon Schubert index_type = TYPE_INDEX_TYPE (elt_type);
28205796c8dcSSimon Schubert
2821cf7f2e2dSJohn Marino return
2822cf7f2e2dSJohn Marino (LONGEST) (which == 0
2823cf7f2e2dSJohn Marino ? ada_discrete_type_low_bound (index_type)
2824cf7f2e2dSJohn Marino : ada_discrete_type_high_bound (index_type));
28255796c8dcSSimon Schubert }
28265796c8dcSSimon Schubert
28275796c8dcSSimon Schubert /* Given that arr is an array value, returns the lower bound of the
28285796c8dcSSimon Schubert nth index (numbering from 1) if WHICH is 0, and the upper bound if
28295796c8dcSSimon Schubert WHICH is 1. This routine will also work for arrays with bounds
28305796c8dcSSimon Schubert supplied by run-time quantities other than discriminants. */
28315796c8dcSSimon Schubert
28325796c8dcSSimon Schubert static LONGEST
ada_array_bound(struct value * arr,int n,int which)28335796c8dcSSimon Schubert ada_array_bound (struct value *arr, int n, int which)
28345796c8dcSSimon Schubert {
28355796c8dcSSimon Schubert struct type *arr_type = value_type (arr);
28365796c8dcSSimon Schubert
2837cf7f2e2dSJohn Marino if (ada_is_constrained_packed_array_type (arr_type))
2838cf7f2e2dSJohn Marino return ada_array_bound (decode_constrained_packed_array (arr), n, which);
28395796c8dcSSimon Schubert else if (ada_is_simple_array_type (arr_type))
28405796c8dcSSimon Schubert return ada_array_bound_from_type (arr_type, n, which);
28415796c8dcSSimon Schubert else
28425796c8dcSSimon Schubert return value_as_long (desc_one_bound (desc_bounds (arr), n, which));
28435796c8dcSSimon Schubert }
28445796c8dcSSimon Schubert
28455796c8dcSSimon Schubert /* Given that arr is an array value, returns the length of the
28465796c8dcSSimon Schubert nth index. This routine will also work for arrays with bounds
28475796c8dcSSimon Schubert supplied by run-time quantities other than discriminants.
28485796c8dcSSimon Schubert Does not work for arrays indexed by enumeration types with representation
28495796c8dcSSimon Schubert clauses at the moment. */
28505796c8dcSSimon Schubert
28515796c8dcSSimon Schubert static LONGEST
ada_array_length(struct value * arr,int n)28525796c8dcSSimon Schubert ada_array_length (struct value *arr, int n)
28535796c8dcSSimon Schubert {
28545796c8dcSSimon Schubert struct type *arr_type = ada_check_typedef (value_type (arr));
28555796c8dcSSimon Schubert
2856cf7f2e2dSJohn Marino if (ada_is_constrained_packed_array_type (arr_type))
2857cf7f2e2dSJohn Marino return ada_array_length (decode_constrained_packed_array (arr), n);
28585796c8dcSSimon Schubert
28595796c8dcSSimon Schubert if (ada_is_simple_array_type (arr_type))
28605796c8dcSSimon Schubert return (ada_array_bound_from_type (arr_type, n, 1)
28615796c8dcSSimon Schubert - ada_array_bound_from_type (arr_type, n, 0) + 1);
28625796c8dcSSimon Schubert else
28635796c8dcSSimon Schubert return (value_as_long (desc_one_bound (desc_bounds (arr), n, 1))
28645796c8dcSSimon Schubert - value_as_long (desc_one_bound (desc_bounds (arr), n, 0)) + 1);
28655796c8dcSSimon Schubert }
28665796c8dcSSimon Schubert
28675796c8dcSSimon Schubert /* An empty array whose type is that of ARR_TYPE (an array type),
28685796c8dcSSimon Schubert with bounds LOW to LOW-1. */
28695796c8dcSSimon Schubert
28705796c8dcSSimon Schubert static struct value *
empty_array(struct type * arr_type,int low)28715796c8dcSSimon Schubert empty_array (struct type *arr_type, int low)
28725796c8dcSSimon Schubert {
2873c50c785cSJohn Marino struct type *arr_type0 = ada_check_typedef (arr_type);
28745796c8dcSSimon Schubert struct type *index_type =
2875c50c785cSJohn Marino create_range_type (NULL, TYPE_TARGET_TYPE (TYPE_INDEX_TYPE (arr_type0)),
28765796c8dcSSimon Schubert low, low - 1);
2877c50c785cSJohn Marino struct type *elt_type = ada_array_element_type (arr_type0, 1);
2878cf7f2e2dSJohn Marino
28795796c8dcSSimon Schubert return allocate_value (create_array_type (NULL, elt_type, index_type));
28805796c8dcSSimon Schubert }
28815796c8dcSSimon Schubert
28825796c8dcSSimon Schubert
28835796c8dcSSimon Schubert /* Name resolution */
28845796c8dcSSimon Schubert
28855796c8dcSSimon Schubert /* The "decoded" name for the user-definable Ada operator corresponding
28865796c8dcSSimon Schubert to OP. */
28875796c8dcSSimon Schubert
28885796c8dcSSimon Schubert static const char *
ada_decoded_op_name(enum exp_opcode op)28895796c8dcSSimon Schubert ada_decoded_op_name (enum exp_opcode op)
28905796c8dcSSimon Schubert {
28915796c8dcSSimon Schubert int i;
28925796c8dcSSimon Schubert
28935796c8dcSSimon Schubert for (i = 0; ada_opname_table[i].encoded != NULL; i += 1)
28945796c8dcSSimon Schubert {
28955796c8dcSSimon Schubert if (ada_opname_table[i].op == op)
28965796c8dcSSimon Schubert return ada_opname_table[i].decoded;
28975796c8dcSSimon Schubert }
28985796c8dcSSimon Schubert error (_("Could not find operator name for opcode"));
28995796c8dcSSimon Schubert }
29005796c8dcSSimon Schubert
29015796c8dcSSimon Schubert
29025796c8dcSSimon Schubert /* Same as evaluate_type (*EXP), but resolves ambiguous symbol
29035796c8dcSSimon Schubert references (marked by OP_VAR_VALUE nodes in which the symbol has an
29045796c8dcSSimon Schubert undefined namespace) and converts operators that are
29055796c8dcSSimon Schubert user-defined into appropriate function calls. If CONTEXT_TYPE is
29065796c8dcSSimon Schubert non-null, it provides a preferred result type [at the moment, only
29075796c8dcSSimon Schubert type void has any effect---causing procedures to be preferred over
29085796c8dcSSimon Schubert functions in calls]. A null CONTEXT_TYPE indicates that a non-void
29095796c8dcSSimon Schubert return type is preferred. May change (expand) *EXP. */
29105796c8dcSSimon Schubert
29115796c8dcSSimon Schubert static void
resolve(struct expression ** expp,int void_context_p)29125796c8dcSSimon Schubert resolve (struct expression **expp, int void_context_p)
29135796c8dcSSimon Schubert {
29145796c8dcSSimon Schubert struct type *context_type = NULL;
29155796c8dcSSimon Schubert int pc = 0;
29165796c8dcSSimon Schubert
29175796c8dcSSimon Schubert if (void_context_p)
29185796c8dcSSimon Schubert context_type = builtin_type ((*expp)->gdbarch)->builtin_void;
29195796c8dcSSimon Schubert
29205796c8dcSSimon Schubert resolve_subexp (expp, &pc, 1, context_type);
29215796c8dcSSimon Schubert }
29225796c8dcSSimon Schubert
29235796c8dcSSimon Schubert /* Resolve the operator of the subexpression beginning at
29245796c8dcSSimon Schubert position *POS of *EXPP. "Resolving" consists of replacing
29255796c8dcSSimon Schubert the symbols that have undefined namespaces in OP_VAR_VALUE nodes
29265796c8dcSSimon Schubert with their resolutions, replacing built-in operators with
29275796c8dcSSimon Schubert function calls to user-defined operators, where appropriate, and,
29285796c8dcSSimon Schubert when DEPROCEDURE_P is non-zero, converting function-valued variables
29295796c8dcSSimon Schubert into parameterless calls. May expand *EXPP. The CONTEXT_TYPE functions
29305796c8dcSSimon Schubert are as in ada_resolve, above. */
29315796c8dcSSimon Schubert
29325796c8dcSSimon Schubert static struct value *
resolve_subexp(struct expression ** expp,int * pos,int deprocedure_p,struct type * context_type)29335796c8dcSSimon Schubert resolve_subexp (struct expression **expp, int *pos, int deprocedure_p,
29345796c8dcSSimon Schubert struct type *context_type)
29355796c8dcSSimon Schubert {
29365796c8dcSSimon Schubert int pc = *pos;
29375796c8dcSSimon Schubert int i;
29385796c8dcSSimon Schubert struct expression *exp; /* Convenience: == *expp. */
29395796c8dcSSimon Schubert enum exp_opcode op = (*expp)->elts[pc].opcode;
29405796c8dcSSimon Schubert struct value **argvec; /* Vector of operand types (alloca'ed). */
29415796c8dcSSimon Schubert int nargs; /* Number of operands. */
29425796c8dcSSimon Schubert int oplen;
29435796c8dcSSimon Schubert
29445796c8dcSSimon Schubert argvec = NULL;
29455796c8dcSSimon Schubert nargs = 0;
29465796c8dcSSimon Schubert exp = *expp;
29475796c8dcSSimon Schubert
29485796c8dcSSimon Schubert /* Pass one: resolve operands, saving their types and updating *pos,
29495796c8dcSSimon Schubert if needed. */
29505796c8dcSSimon Schubert switch (op)
29515796c8dcSSimon Schubert {
29525796c8dcSSimon Schubert case OP_FUNCALL:
29535796c8dcSSimon Schubert if (exp->elts[pc + 3].opcode == OP_VAR_VALUE
29545796c8dcSSimon Schubert && SYMBOL_DOMAIN (exp->elts[pc + 5].symbol) == UNDEF_DOMAIN)
29555796c8dcSSimon Schubert *pos += 7;
29565796c8dcSSimon Schubert else
29575796c8dcSSimon Schubert {
29585796c8dcSSimon Schubert *pos += 3;
29595796c8dcSSimon Schubert resolve_subexp (expp, pos, 0, NULL);
29605796c8dcSSimon Schubert }
29615796c8dcSSimon Schubert nargs = longest_to_int (exp->elts[pc + 1].longconst);
29625796c8dcSSimon Schubert break;
29635796c8dcSSimon Schubert
29645796c8dcSSimon Schubert case UNOP_ADDR:
29655796c8dcSSimon Schubert *pos += 1;
29665796c8dcSSimon Schubert resolve_subexp (expp, pos, 0, NULL);
29675796c8dcSSimon Schubert break;
29685796c8dcSSimon Schubert
29695796c8dcSSimon Schubert case UNOP_QUAL:
29705796c8dcSSimon Schubert *pos += 3;
29715796c8dcSSimon Schubert resolve_subexp (expp, pos, 1, check_typedef (exp->elts[pc + 1].type));
29725796c8dcSSimon Schubert break;
29735796c8dcSSimon Schubert
29745796c8dcSSimon Schubert case OP_ATR_MODULUS:
29755796c8dcSSimon Schubert case OP_ATR_SIZE:
29765796c8dcSSimon Schubert case OP_ATR_TAG:
29775796c8dcSSimon Schubert case OP_ATR_FIRST:
29785796c8dcSSimon Schubert case OP_ATR_LAST:
29795796c8dcSSimon Schubert case OP_ATR_LENGTH:
29805796c8dcSSimon Schubert case OP_ATR_POS:
29815796c8dcSSimon Schubert case OP_ATR_VAL:
29825796c8dcSSimon Schubert case OP_ATR_MIN:
29835796c8dcSSimon Schubert case OP_ATR_MAX:
29845796c8dcSSimon Schubert case TERNOP_IN_RANGE:
29855796c8dcSSimon Schubert case BINOP_IN_BOUNDS:
29865796c8dcSSimon Schubert case UNOP_IN_RANGE:
29875796c8dcSSimon Schubert case OP_AGGREGATE:
29885796c8dcSSimon Schubert case OP_OTHERS:
29895796c8dcSSimon Schubert case OP_CHOICES:
29905796c8dcSSimon Schubert case OP_POSITIONAL:
29915796c8dcSSimon Schubert case OP_DISCRETE_RANGE:
29925796c8dcSSimon Schubert case OP_NAME:
29935796c8dcSSimon Schubert ada_forward_operator_length (exp, pc, &oplen, &nargs);
29945796c8dcSSimon Schubert *pos += oplen;
29955796c8dcSSimon Schubert break;
29965796c8dcSSimon Schubert
29975796c8dcSSimon Schubert case BINOP_ASSIGN:
29985796c8dcSSimon Schubert {
29995796c8dcSSimon Schubert struct value *arg1;
30005796c8dcSSimon Schubert
30015796c8dcSSimon Schubert *pos += 1;
30025796c8dcSSimon Schubert arg1 = resolve_subexp (expp, pos, 0, NULL);
30035796c8dcSSimon Schubert if (arg1 == NULL)
30045796c8dcSSimon Schubert resolve_subexp (expp, pos, 1, NULL);
30055796c8dcSSimon Schubert else
30065796c8dcSSimon Schubert resolve_subexp (expp, pos, 1, value_type (arg1));
30075796c8dcSSimon Schubert break;
30085796c8dcSSimon Schubert }
30095796c8dcSSimon Schubert
30105796c8dcSSimon Schubert case UNOP_CAST:
30115796c8dcSSimon Schubert *pos += 3;
30125796c8dcSSimon Schubert nargs = 1;
30135796c8dcSSimon Schubert break;
30145796c8dcSSimon Schubert
30155796c8dcSSimon Schubert case BINOP_ADD:
30165796c8dcSSimon Schubert case BINOP_SUB:
30175796c8dcSSimon Schubert case BINOP_MUL:
30185796c8dcSSimon Schubert case BINOP_DIV:
30195796c8dcSSimon Schubert case BINOP_REM:
30205796c8dcSSimon Schubert case BINOP_MOD:
30215796c8dcSSimon Schubert case BINOP_EXP:
30225796c8dcSSimon Schubert case BINOP_CONCAT:
30235796c8dcSSimon Schubert case BINOP_LOGICAL_AND:
30245796c8dcSSimon Schubert case BINOP_LOGICAL_OR:
30255796c8dcSSimon Schubert case BINOP_BITWISE_AND:
30265796c8dcSSimon Schubert case BINOP_BITWISE_IOR:
30275796c8dcSSimon Schubert case BINOP_BITWISE_XOR:
30285796c8dcSSimon Schubert
30295796c8dcSSimon Schubert case BINOP_EQUAL:
30305796c8dcSSimon Schubert case BINOP_NOTEQUAL:
30315796c8dcSSimon Schubert case BINOP_LESS:
30325796c8dcSSimon Schubert case BINOP_GTR:
30335796c8dcSSimon Schubert case BINOP_LEQ:
30345796c8dcSSimon Schubert case BINOP_GEQ:
30355796c8dcSSimon Schubert
30365796c8dcSSimon Schubert case BINOP_REPEAT:
30375796c8dcSSimon Schubert case BINOP_SUBSCRIPT:
30385796c8dcSSimon Schubert case BINOP_COMMA:
30395796c8dcSSimon Schubert *pos += 1;
30405796c8dcSSimon Schubert nargs = 2;
30415796c8dcSSimon Schubert break;
30425796c8dcSSimon Schubert
30435796c8dcSSimon Schubert case UNOP_NEG:
30445796c8dcSSimon Schubert case UNOP_PLUS:
30455796c8dcSSimon Schubert case UNOP_LOGICAL_NOT:
30465796c8dcSSimon Schubert case UNOP_ABS:
30475796c8dcSSimon Schubert case UNOP_IND:
30485796c8dcSSimon Schubert *pos += 1;
30495796c8dcSSimon Schubert nargs = 1;
30505796c8dcSSimon Schubert break;
30515796c8dcSSimon Schubert
30525796c8dcSSimon Schubert case OP_LONG:
30535796c8dcSSimon Schubert case OP_DOUBLE:
30545796c8dcSSimon Schubert case OP_VAR_VALUE:
30555796c8dcSSimon Schubert *pos += 4;
30565796c8dcSSimon Schubert break;
30575796c8dcSSimon Schubert
30585796c8dcSSimon Schubert case OP_TYPE:
30595796c8dcSSimon Schubert case OP_BOOL:
30605796c8dcSSimon Schubert case OP_LAST:
30615796c8dcSSimon Schubert case OP_INTERNALVAR:
30625796c8dcSSimon Schubert *pos += 3;
30635796c8dcSSimon Schubert break;
30645796c8dcSSimon Schubert
30655796c8dcSSimon Schubert case UNOP_MEMVAL:
30665796c8dcSSimon Schubert *pos += 3;
30675796c8dcSSimon Schubert nargs = 1;
30685796c8dcSSimon Schubert break;
30695796c8dcSSimon Schubert
30705796c8dcSSimon Schubert case OP_REGISTER:
30715796c8dcSSimon Schubert *pos += 4 + BYTES_TO_EXP_ELEM (exp->elts[pc + 1].longconst + 1);
30725796c8dcSSimon Schubert break;
30735796c8dcSSimon Schubert
30745796c8dcSSimon Schubert case STRUCTOP_STRUCT:
30755796c8dcSSimon Schubert *pos += 4 + BYTES_TO_EXP_ELEM (exp->elts[pc + 1].longconst + 1);
30765796c8dcSSimon Schubert nargs = 1;
30775796c8dcSSimon Schubert break;
30785796c8dcSSimon Schubert
30795796c8dcSSimon Schubert case TERNOP_SLICE:
30805796c8dcSSimon Schubert *pos += 1;
30815796c8dcSSimon Schubert nargs = 3;
30825796c8dcSSimon Schubert break;
30835796c8dcSSimon Schubert
30845796c8dcSSimon Schubert case OP_STRING:
30855796c8dcSSimon Schubert break;
30865796c8dcSSimon Schubert
30875796c8dcSSimon Schubert default:
30885796c8dcSSimon Schubert error (_("Unexpected operator during name resolution"));
30895796c8dcSSimon Schubert }
30905796c8dcSSimon Schubert
30915796c8dcSSimon Schubert argvec = (struct value * *) alloca (sizeof (struct value *) * (nargs + 1));
30925796c8dcSSimon Schubert for (i = 0; i < nargs; i += 1)
30935796c8dcSSimon Schubert argvec[i] = resolve_subexp (expp, pos, 1, NULL);
30945796c8dcSSimon Schubert argvec[i] = NULL;
30955796c8dcSSimon Schubert exp = *expp;
30965796c8dcSSimon Schubert
30975796c8dcSSimon Schubert /* Pass two: perform any resolution on principal operator. */
30985796c8dcSSimon Schubert switch (op)
30995796c8dcSSimon Schubert {
31005796c8dcSSimon Schubert default:
31015796c8dcSSimon Schubert break;
31025796c8dcSSimon Schubert
31035796c8dcSSimon Schubert case OP_VAR_VALUE:
31045796c8dcSSimon Schubert if (SYMBOL_DOMAIN (exp->elts[pc + 2].symbol) == UNDEF_DOMAIN)
31055796c8dcSSimon Schubert {
31065796c8dcSSimon Schubert struct ada_symbol_info *candidates;
31075796c8dcSSimon Schubert int n_candidates;
31085796c8dcSSimon Schubert
31095796c8dcSSimon Schubert n_candidates =
31105796c8dcSSimon Schubert ada_lookup_symbol_list (SYMBOL_LINKAGE_NAME
31115796c8dcSSimon Schubert (exp->elts[pc + 2].symbol),
31125796c8dcSSimon Schubert exp->elts[pc + 1].block, VAR_DOMAIN,
31135796c8dcSSimon Schubert &candidates);
31145796c8dcSSimon Schubert
31155796c8dcSSimon Schubert if (n_candidates > 1)
31165796c8dcSSimon Schubert {
31175796c8dcSSimon Schubert /* Types tend to get re-introduced locally, so if there
31185796c8dcSSimon Schubert are any local symbols that are not types, first filter
31195796c8dcSSimon Schubert out all types. */
31205796c8dcSSimon Schubert int j;
31215796c8dcSSimon Schubert for (j = 0; j < n_candidates; j += 1)
31225796c8dcSSimon Schubert switch (SYMBOL_CLASS (candidates[j].sym))
31235796c8dcSSimon Schubert {
31245796c8dcSSimon Schubert case LOC_REGISTER:
31255796c8dcSSimon Schubert case LOC_ARG:
31265796c8dcSSimon Schubert case LOC_REF_ARG:
31275796c8dcSSimon Schubert case LOC_REGPARM_ADDR:
31285796c8dcSSimon Schubert case LOC_LOCAL:
31295796c8dcSSimon Schubert case LOC_COMPUTED:
31305796c8dcSSimon Schubert goto FoundNonType;
31315796c8dcSSimon Schubert default:
31325796c8dcSSimon Schubert break;
31335796c8dcSSimon Schubert }
31345796c8dcSSimon Schubert FoundNonType:
31355796c8dcSSimon Schubert if (j < n_candidates)
31365796c8dcSSimon Schubert {
31375796c8dcSSimon Schubert j = 0;
31385796c8dcSSimon Schubert while (j < n_candidates)
31395796c8dcSSimon Schubert {
31405796c8dcSSimon Schubert if (SYMBOL_CLASS (candidates[j].sym) == LOC_TYPEDEF)
31415796c8dcSSimon Schubert {
31425796c8dcSSimon Schubert candidates[j] = candidates[n_candidates - 1];
31435796c8dcSSimon Schubert n_candidates -= 1;
31445796c8dcSSimon Schubert }
31455796c8dcSSimon Schubert else
31465796c8dcSSimon Schubert j += 1;
31475796c8dcSSimon Schubert }
31485796c8dcSSimon Schubert }
31495796c8dcSSimon Schubert }
31505796c8dcSSimon Schubert
31515796c8dcSSimon Schubert if (n_candidates == 0)
31525796c8dcSSimon Schubert error (_("No definition found for %s"),
31535796c8dcSSimon Schubert SYMBOL_PRINT_NAME (exp->elts[pc + 2].symbol));
31545796c8dcSSimon Schubert else if (n_candidates == 1)
31555796c8dcSSimon Schubert i = 0;
31565796c8dcSSimon Schubert else if (deprocedure_p
31575796c8dcSSimon Schubert && !is_nonfunction (candidates, n_candidates))
31585796c8dcSSimon Schubert {
31595796c8dcSSimon Schubert i = ada_resolve_function
31605796c8dcSSimon Schubert (candidates, n_candidates, NULL, 0,
31615796c8dcSSimon Schubert SYMBOL_LINKAGE_NAME (exp->elts[pc + 2].symbol),
31625796c8dcSSimon Schubert context_type);
31635796c8dcSSimon Schubert if (i < 0)
31645796c8dcSSimon Schubert error (_("Could not find a match for %s"),
31655796c8dcSSimon Schubert SYMBOL_PRINT_NAME (exp->elts[pc + 2].symbol));
31665796c8dcSSimon Schubert }
31675796c8dcSSimon Schubert else
31685796c8dcSSimon Schubert {
31695796c8dcSSimon Schubert printf_filtered (_("Multiple matches for %s\n"),
31705796c8dcSSimon Schubert SYMBOL_PRINT_NAME (exp->elts[pc + 2].symbol));
31715796c8dcSSimon Schubert user_select_syms (candidates, n_candidates, 1);
31725796c8dcSSimon Schubert i = 0;
31735796c8dcSSimon Schubert }
31745796c8dcSSimon Schubert
31755796c8dcSSimon Schubert exp->elts[pc + 1].block = candidates[i].block;
31765796c8dcSSimon Schubert exp->elts[pc + 2].symbol = candidates[i].sym;
31775796c8dcSSimon Schubert if (innermost_block == NULL
31785796c8dcSSimon Schubert || contained_in (candidates[i].block, innermost_block))
31795796c8dcSSimon Schubert innermost_block = candidates[i].block;
31805796c8dcSSimon Schubert }
31815796c8dcSSimon Schubert
31825796c8dcSSimon Schubert if (deprocedure_p
31835796c8dcSSimon Schubert && (TYPE_CODE (SYMBOL_TYPE (exp->elts[pc + 2].symbol))
31845796c8dcSSimon Schubert == TYPE_CODE_FUNC))
31855796c8dcSSimon Schubert {
31865796c8dcSSimon Schubert replace_operator_with_call (expp, pc, 0, 0,
31875796c8dcSSimon Schubert exp->elts[pc + 2].symbol,
31885796c8dcSSimon Schubert exp->elts[pc + 1].block);
31895796c8dcSSimon Schubert exp = *expp;
31905796c8dcSSimon Schubert }
31915796c8dcSSimon Schubert break;
31925796c8dcSSimon Schubert
31935796c8dcSSimon Schubert case OP_FUNCALL:
31945796c8dcSSimon Schubert {
31955796c8dcSSimon Schubert if (exp->elts[pc + 3].opcode == OP_VAR_VALUE
31965796c8dcSSimon Schubert && SYMBOL_DOMAIN (exp->elts[pc + 5].symbol) == UNDEF_DOMAIN)
31975796c8dcSSimon Schubert {
31985796c8dcSSimon Schubert struct ada_symbol_info *candidates;
31995796c8dcSSimon Schubert int n_candidates;
32005796c8dcSSimon Schubert
32015796c8dcSSimon Schubert n_candidates =
32025796c8dcSSimon Schubert ada_lookup_symbol_list (SYMBOL_LINKAGE_NAME
32035796c8dcSSimon Schubert (exp->elts[pc + 5].symbol),
32045796c8dcSSimon Schubert exp->elts[pc + 4].block, VAR_DOMAIN,
32055796c8dcSSimon Schubert &candidates);
32065796c8dcSSimon Schubert if (n_candidates == 1)
32075796c8dcSSimon Schubert i = 0;
32085796c8dcSSimon Schubert else
32095796c8dcSSimon Schubert {
32105796c8dcSSimon Schubert i = ada_resolve_function
32115796c8dcSSimon Schubert (candidates, n_candidates,
32125796c8dcSSimon Schubert argvec, nargs,
32135796c8dcSSimon Schubert SYMBOL_LINKAGE_NAME (exp->elts[pc + 5].symbol),
32145796c8dcSSimon Schubert context_type);
32155796c8dcSSimon Schubert if (i < 0)
32165796c8dcSSimon Schubert error (_("Could not find a match for %s"),
32175796c8dcSSimon Schubert SYMBOL_PRINT_NAME (exp->elts[pc + 5].symbol));
32185796c8dcSSimon Schubert }
32195796c8dcSSimon Schubert
32205796c8dcSSimon Schubert exp->elts[pc + 4].block = candidates[i].block;
32215796c8dcSSimon Schubert exp->elts[pc + 5].symbol = candidates[i].sym;
32225796c8dcSSimon Schubert if (innermost_block == NULL
32235796c8dcSSimon Schubert || contained_in (candidates[i].block, innermost_block))
32245796c8dcSSimon Schubert innermost_block = candidates[i].block;
32255796c8dcSSimon Schubert }
32265796c8dcSSimon Schubert }
32275796c8dcSSimon Schubert break;
32285796c8dcSSimon Schubert case BINOP_ADD:
32295796c8dcSSimon Schubert case BINOP_SUB:
32305796c8dcSSimon Schubert case BINOP_MUL:
32315796c8dcSSimon Schubert case BINOP_DIV:
32325796c8dcSSimon Schubert case BINOP_REM:
32335796c8dcSSimon Schubert case BINOP_MOD:
32345796c8dcSSimon Schubert case BINOP_CONCAT:
32355796c8dcSSimon Schubert case BINOP_BITWISE_AND:
32365796c8dcSSimon Schubert case BINOP_BITWISE_IOR:
32375796c8dcSSimon Schubert case BINOP_BITWISE_XOR:
32385796c8dcSSimon Schubert case BINOP_EQUAL:
32395796c8dcSSimon Schubert case BINOP_NOTEQUAL:
32405796c8dcSSimon Schubert case BINOP_LESS:
32415796c8dcSSimon Schubert case BINOP_GTR:
32425796c8dcSSimon Schubert case BINOP_LEQ:
32435796c8dcSSimon Schubert case BINOP_GEQ:
32445796c8dcSSimon Schubert case BINOP_EXP:
32455796c8dcSSimon Schubert case UNOP_NEG:
32465796c8dcSSimon Schubert case UNOP_PLUS:
32475796c8dcSSimon Schubert case UNOP_LOGICAL_NOT:
32485796c8dcSSimon Schubert case UNOP_ABS:
32495796c8dcSSimon Schubert if (possible_user_operator_p (op, argvec))
32505796c8dcSSimon Schubert {
32515796c8dcSSimon Schubert struct ada_symbol_info *candidates;
32525796c8dcSSimon Schubert int n_candidates;
32535796c8dcSSimon Schubert
32545796c8dcSSimon Schubert n_candidates =
32555796c8dcSSimon Schubert ada_lookup_symbol_list (ada_encode (ada_decoded_op_name (op)),
32565796c8dcSSimon Schubert (struct block *) NULL, VAR_DOMAIN,
32575796c8dcSSimon Schubert &candidates);
32585796c8dcSSimon Schubert i = ada_resolve_function (candidates, n_candidates, argvec, nargs,
32595796c8dcSSimon Schubert ada_decoded_op_name (op), NULL);
32605796c8dcSSimon Schubert if (i < 0)
32615796c8dcSSimon Schubert break;
32625796c8dcSSimon Schubert
32635796c8dcSSimon Schubert replace_operator_with_call (expp, pc, nargs, 1,
32645796c8dcSSimon Schubert candidates[i].sym, candidates[i].block);
32655796c8dcSSimon Schubert exp = *expp;
32665796c8dcSSimon Schubert }
32675796c8dcSSimon Schubert break;
32685796c8dcSSimon Schubert
32695796c8dcSSimon Schubert case OP_TYPE:
32705796c8dcSSimon Schubert case OP_REGISTER:
32715796c8dcSSimon Schubert return NULL;
32725796c8dcSSimon Schubert }
32735796c8dcSSimon Schubert
32745796c8dcSSimon Schubert *pos = pc;
32755796c8dcSSimon Schubert return evaluate_subexp_type (exp, pos);
32765796c8dcSSimon Schubert }
32775796c8dcSSimon Schubert
32785796c8dcSSimon Schubert /* Return non-zero if formal type FTYPE matches actual type ATYPE. If
32795796c8dcSSimon Schubert MAY_DEREF is non-zero, the formal may be a pointer and the actual
3280cf7f2e2dSJohn Marino a non-pointer. */
32815796c8dcSSimon Schubert /* The term "match" here is rather loose. The match is heuristic and
3282cf7f2e2dSJohn Marino liberal. */
32835796c8dcSSimon Schubert
32845796c8dcSSimon Schubert static int
ada_type_match(struct type * ftype,struct type * atype,int may_deref)32855796c8dcSSimon Schubert ada_type_match (struct type *ftype, struct type *atype, int may_deref)
32865796c8dcSSimon Schubert {
32875796c8dcSSimon Schubert ftype = ada_check_typedef (ftype);
32885796c8dcSSimon Schubert atype = ada_check_typedef (atype);
32895796c8dcSSimon Schubert
32905796c8dcSSimon Schubert if (TYPE_CODE (ftype) == TYPE_CODE_REF)
32915796c8dcSSimon Schubert ftype = TYPE_TARGET_TYPE (ftype);
32925796c8dcSSimon Schubert if (TYPE_CODE (atype) == TYPE_CODE_REF)
32935796c8dcSSimon Schubert atype = TYPE_TARGET_TYPE (atype);
32945796c8dcSSimon Schubert
32955796c8dcSSimon Schubert switch (TYPE_CODE (ftype))
32965796c8dcSSimon Schubert {
32975796c8dcSSimon Schubert default:
3298cf7f2e2dSJohn Marino return TYPE_CODE (ftype) == TYPE_CODE (atype);
32995796c8dcSSimon Schubert case TYPE_CODE_PTR:
33005796c8dcSSimon Schubert if (TYPE_CODE (atype) == TYPE_CODE_PTR)
33015796c8dcSSimon Schubert return ada_type_match (TYPE_TARGET_TYPE (ftype),
33025796c8dcSSimon Schubert TYPE_TARGET_TYPE (atype), 0);
33035796c8dcSSimon Schubert else
33045796c8dcSSimon Schubert return (may_deref
33055796c8dcSSimon Schubert && ada_type_match (TYPE_TARGET_TYPE (ftype), atype, 0));
33065796c8dcSSimon Schubert case TYPE_CODE_INT:
33075796c8dcSSimon Schubert case TYPE_CODE_ENUM:
33085796c8dcSSimon Schubert case TYPE_CODE_RANGE:
33095796c8dcSSimon Schubert switch (TYPE_CODE (atype))
33105796c8dcSSimon Schubert {
33115796c8dcSSimon Schubert case TYPE_CODE_INT:
33125796c8dcSSimon Schubert case TYPE_CODE_ENUM:
33135796c8dcSSimon Schubert case TYPE_CODE_RANGE:
33145796c8dcSSimon Schubert return 1;
33155796c8dcSSimon Schubert default:
33165796c8dcSSimon Schubert return 0;
33175796c8dcSSimon Schubert }
33185796c8dcSSimon Schubert
33195796c8dcSSimon Schubert case TYPE_CODE_ARRAY:
33205796c8dcSSimon Schubert return (TYPE_CODE (atype) == TYPE_CODE_ARRAY
33215796c8dcSSimon Schubert || ada_is_array_descriptor_type (atype));
33225796c8dcSSimon Schubert
33235796c8dcSSimon Schubert case TYPE_CODE_STRUCT:
33245796c8dcSSimon Schubert if (ada_is_array_descriptor_type (ftype))
33255796c8dcSSimon Schubert return (TYPE_CODE (atype) == TYPE_CODE_ARRAY
33265796c8dcSSimon Schubert || ada_is_array_descriptor_type (atype));
33275796c8dcSSimon Schubert else
33285796c8dcSSimon Schubert return (TYPE_CODE (atype) == TYPE_CODE_STRUCT
33295796c8dcSSimon Schubert && !ada_is_array_descriptor_type (atype));
33305796c8dcSSimon Schubert
33315796c8dcSSimon Schubert case TYPE_CODE_UNION:
33325796c8dcSSimon Schubert case TYPE_CODE_FLT:
33335796c8dcSSimon Schubert return (TYPE_CODE (atype) == TYPE_CODE (ftype));
33345796c8dcSSimon Schubert }
33355796c8dcSSimon Schubert }
33365796c8dcSSimon Schubert
33375796c8dcSSimon Schubert /* Return non-zero if the formals of FUNC "sufficiently match" the
33385796c8dcSSimon Schubert vector of actual argument types ACTUALS of size N_ACTUALS. FUNC
33395796c8dcSSimon Schubert may also be an enumeral, in which case it is treated as a 0-
33405796c8dcSSimon Schubert argument function. */
33415796c8dcSSimon Schubert
33425796c8dcSSimon Schubert static int
ada_args_match(struct symbol * func,struct value ** actuals,int n_actuals)33435796c8dcSSimon Schubert ada_args_match (struct symbol *func, struct value **actuals, int n_actuals)
33445796c8dcSSimon Schubert {
33455796c8dcSSimon Schubert int i;
33465796c8dcSSimon Schubert struct type *func_type = SYMBOL_TYPE (func);
33475796c8dcSSimon Schubert
33485796c8dcSSimon Schubert if (SYMBOL_CLASS (func) == LOC_CONST
33495796c8dcSSimon Schubert && TYPE_CODE (func_type) == TYPE_CODE_ENUM)
33505796c8dcSSimon Schubert return (n_actuals == 0);
33515796c8dcSSimon Schubert else if (func_type == NULL || TYPE_CODE (func_type) != TYPE_CODE_FUNC)
33525796c8dcSSimon Schubert return 0;
33535796c8dcSSimon Schubert
33545796c8dcSSimon Schubert if (TYPE_NFIELDS (func_type) != n_actuals)
33555796c8dcSSimon Schubert return 0;
33565796c8dcSSimon Schubert
33575796c8dcSSimon Schubert for (i = 0; i < n_actuals; i += 1)
33585796c8dcSSimon Schubert {
33595796c8dcSSimon Schubert if (actuals[i] == NULL)
33605796c8dcSSimon Schubert return 0;
33615796c8dcSSimon Schubert else
33625796c8dcSSimon Schubert {
3363cf7f2e2dSJohn Marino struct type *ftype = ada_check_typedef (TYPE_FIELD_TYPE (func_type,
3364cf7f2e2dSJohn Marino i));
33655796c8dcSSimon Schubert struct type *atype = ada_check_typedef (value_type (actuals[i]));
33665796c8dcSSimon Schubert
33675796c8dcSSimon Schubert if (!ada_type_match (ftype, atype, 1))
33685796c8dcSSimon Schubert return 0;
33695796c8dcSSimon Schubert }
33705796c8dcSSimon Schubert }
33715796c8dcSSimon Schubert return 1;
33725796c8dcSSimon Schubert }
33735796c8dcSSimon Schubert
33745796c8dcSSimon Schubert /* False iff function type FUNC_TYPE definitely does not produce a value
33755796c8dcSSimon Schubert compatible with type CONTEXT_TYPE. Conservatively returns 1 if
33765796c8dcSSimon Schubert FUNC_TYPE is not a valid function type with a non-null return type
33775796c8dcSSimon Schubert or an enumerated type. A null CONTEXT_TYPE indicates any non-void type. */
33785796c8dcSSimon Schubert
33795796c8dcSSimon Schubert static int
return_match(struct type * func_type,struct type * context_type)33805796c8dcSSimon Schubert return_match (struct type *func_type, struct type *context_type)
33815796c8dcSSimon Schubert {
33825796c8dcSSimon Schubert struct type *return_type;
33835796c8dcSSimon Schubert
33845796c8dcSSimon Schubert if (func_type == NULL)
33855796c8dcSSimon Schubert return 1;
33865796c8dcSSimon Schubert
33875796c8dcSSimon Schubert if (TYPE_CODE (func_type) == TYPE_CODE_FUNC)
3388a45ae5f8SJohn Marino return_type = get_base_type (TYPE_TARGET_TYPE (func_type));
33895796c8dcSSimon Schubert else
3390a45ae5f8SJohn Marino return_type = get_base_type (func_type);
33915796c8dcSSimon Schubert if (return_type == NULL)
33925796c8dcSSimon Schubert return 1;
33935796c8dcSSimon Schubert
3394a45ae5f8SJohn Marino context_type = get_base_type (context_type);
33955796c8dcSSimon Schubert
33965796c8dcSSimon Schubert if (TYPE_CODE (return_type) == TYPE_CODE_ENUM)
33975796c8dcSSimon Schubert return context_type == NULL || return_type == context_type;
33985796c8dcSSimon Schubert else if (context_type == NULL)
33995796c8dcSSimon Schubert return TYPE_CODE (return_type) != TYPE_CODE_VOID;
34005796c8dcSSimon Schubert else
34015796c8dcSSimon Schubert return TYPE_CODE (return_type) == TYPE_CODE (context_type);
34025796c8dcSSimon Schubert }
34035796c8dcSSimon Schubert
34045796c8dcSSimon Schubert
34055796c8dcSSimon Schubert /* Returns the index in SYMS[0..NSYMS-1] that contains the symbol for the
34065796c8dcSSimon Schubert function (if any) that matches the types of the NARGS arguments in
34075796c8dcSSimon Schubert ARGS. If CONTEXT_TYPE is non-null and there is at least one match
34085796c8dcSSimon Schubert that returns that type, then eliminate matches that don't. If
34095796c8dcSSimon Schubert CONTEXT_TYPE is void and there is at least one match that does not
34105796c8dcSSimon Schubert return void, eliminate all matches that do.
34115796c8dcSSimon Schubert
34125796c8dcSSimon Schubert Asks the user if there is more than one match remaining. Returns -1
34135796c8dcSSimon Schubert if there is no such symbol or none is selected. NAME is used
34145796c8dcSSimon Schubert solely for messages. May re-arrange and modify SYMS in
34155796c8dcSSimon Schubert the process; the index returned is for the modified vector. */
34165796c8dcSSimon Schubert
34175796c8dcSSimon Schubert static int
ada_resolve_function(struct ada_symbol_info syms[],int nsyms,struct value ** args,int nargs,const char * name,struct type * context_type)34185796c8dcSSimon Schubert ada_resolve_function (struct ada_symbol_info syms[],
34195796c8dcSSimon Schubert int nsyms, struct value **args, int nargs,
34205796c8dcSSimon Schubert const char *name, struct type *context_type)
34215796c8dcSSimon Schubert {
34225796c8dcSSimon Schubert int fallback;
34235796c8dcSSimon Schubert int k;
34245796c8dcSSimon Schubert int m; /* Number of hits */
34255796c8dcSSimon Schubert
34265796c8dcSSimon Schubert m = 0;
34275796c8dcSSimon Schubert /* In the first pass of the loop, we only accept functions matching
34285796c8dcSSimon Schubert context_type. If none are found, we add a second pass of the loop
34295796c8dcSSimon Schubert where every function is accepted. */
34305796c8dcSSimon Schubert for (fallback = 0; m == 0 && fallback < 2; fallback++)
34315796c8dcSSimon Schubert {
34325796c8dcSSimon Schubert for (k = 0; k < nsyms; k += 1)
34335796c8dcSSimon Schubert {
34345796c8dcSSimon Schubert struct type *type = ada_check_typedef (SYMBOL_TYPE (syms[k].sym));
34355796c8dcSSimon Schubert
34365796c8dcSSimon Schubert if (ada_args_match (syms[k].sym, args, nargs)
34375796c8dcSSimon Schubert && (fallback || return_match (type, context_type)))
34385796c8dcSSimon Schubert {
34395796c8dcSSimon Schubert syms[m] = syms[k];
34405796c8dcSSimon Schubert m += 1;
34415796c8dcSSimon Schubert }
34425796c8dcSSimon Schubert }
34435796c8dcSSimon Schubert }
34445796c8dcSSimon Schubert
34455796c8dcSSimon Schubert if (m == 0)
34465796c8dcSSimon Schubert return -1;
34475796c8dcSSimon Schubert else if (m > 1)
34485796c8dcSSimon Schubert {
34495796c8dcSSimon Schubert printf_filtered (_("Multiple matches for %s\n"), name);
34505796c8dcSSimon Schubert user_select_syms (syms, m, 1);
34515796c8dcSSimon Schubert return 0;
34525796c8dcSSimon Schubert }
34535796c8dcSSimon Schubert return 0;
34545796c8dcSSimon Schubert }
34555796c8dcSSimon Schubert
34565796c8dcSSimon Schubert /* Returns true (non-zero) iff decoded name N0 should appear before N1
34575796c8dcSSimon Schubert in a listing of choices during disambiguation (see sort_choices, below).
34585796c8dcSSimon Schubert The idea is that overloadings of a subprogram name from the
34595796c8dcSSimon Schubert same package should sort in their source order. We settle for ordering
34605796c8dcSSimon Schubert such symbols by their trailing number (__N or $N). */
34615796c8dcSSimon Schubert
34625796c8dcSSimon Schubert static int
encoded_ordered_before(const char * N0,const char * N1)3463*ef5ccd6cSJohn Marino encoded_ordered_before (const char *N0, const char *N1)
34645796c8dcSSimon Schubert {
34655796c8dcSSimon Schubert if (N1 == NULL)
34665796c8dcSSimon Schubert return 0;
34675796c8dcSSimon Schubert else if (N0 == NULL)
34685796c8dcSSimon Schubert return 1;
34695796c8dcSSimon Schubert else
34705796c8dcSSimon Schubert {
34715796c8dcSSimon Schubert int k0, k1;
3472cf7f2e2dSJohn Marino
34735796c8dcSSimon Schubert for (k0 = strlen (N0) - 1; k0 > 0 && isdigit (N0[k0]); k0 -= 1)
34745796c8dcSSimon Schubert ;
34755796c8dcSSimon Schubert for (k1 = strlen (N1) - 1; k1 > 0 && isdigit (N1[k1]); k1 -= 1)
34765796c8dcSSimon Schubert ;
34775796c8dcSSimon Schubert if ((N0[k0] == '_' || N0[k0] == '$') && N0[k0 + 1] != '\000'
34785796c8dcSSimon Schubert && (N1[k1] == '_' || N1[k1] == '$') && N1[k1 + 1] != '\000')
34795796c8dcSSimon Schubert {
34805796c8dcSSimon Schubert int n0, n1;
3481cf7f2e2dSJohn Marino
34825796c8dcSSimon Schubert n0 = k0;
34835796c8dcSSimon Schubert while (N0[n0] == '_' && n0 > 0 && N0[n0 - 1] == '_')
34845796c8dcSSimon Schubert n0 -= 1;
34855796c8dcSSimon Schubert n1 = k1;
34865796c8dcSSimon Schubert while (N1[n1] == '_' && n1 > 0 && N1[n1 - 1] == '_')
34875796c8dcSSimon Schubert n1 -= 1;
34885796c8dcSSimon Schubert if (n0 == n1 && strncmp (N0, N1, n0) == 0)
34895796c8dcSSimon Schubert return (atoi (N0 + k0 + 1) < atoi (N1 + k1 + 1));
34905796c8dcSSimon Schubert }
34915796c8dcSSimon Schubert return (strcmp (N0, N1) < 0);
34925796c8dcSSimon Schubert }
34935796c8dcSSimon Schubert }
34945796c8dcSSimon Schubert
34955796c8dcSSimon Schubert /* Sort SYMS[0..NSYMS-1] to put the choices in a canonical order by the
34965796c8dcSSimon Schubert encoded names. */
34975796c8dcSSimon Schubert
34985796c8dcSSimon Schubert static void
sort_choices(struct ada_symbol_info syms[],int nsyms)34995796c8dcSSimon Schubert sort_choices (struct ada_symbol_info syms[], int nsyms)
35005796c8dcSSimon Schubert {
35015796c8dcSSimon Schubert int i;
3502cf7f2e2dSJohn Marino
35035796c8dcSSimon Schubert for (i = 1; i < nsyms; i += 1)
35045796c8dcSSimon Schubert {
35055796c8dcSSimon Schubert struct ada_symbol_info sym = syms[i];
35065796c8dcSSimon Schubert int j;
35075796c8dcSSimon Schubert
35085796c8dcSSimon Schubert for (j = i - 1; j >= 0; j -= 1)
35095796c8dcSSimon Schubert {
35105796c8dcSSimon Schubert if (encoded_ordered_before (SYMBOL_LINKAGE_NAME (syms[j].sym),
35115796c8dcSSimon Schubert SYMBOL_LINKAGE_NAME (sym.sym)))
35125796c8dcSSimon Schubert break;
35135796c8dcSSimon Schubert syms[j + 1] = syms[j];
35145796c8dcSSimon Schubert }
35155796c8dcSSimon Schubert syms[j + 1] = sym;
35165796c8dcSSimon Schubert }
35175796c8dcSSimon Schubert }
35185796c8dcSSimon Schubert
35195796c8dcSSimon Schubert /* Given a list of NSYMS symbols in SYMS, select up to MAX_RESULTS>0
35205796c8dcSSimon Schubert by asking the user (if necessary), returning the number selected,
35215796c8dcSSimon Schubert and setting the first elements of SYMS items. Error if no symbols
35225796c8dcSSimon Schubert selected. */
35235796c8dcSSimon Schubert
35245796c8dcSSimon Schubert /* NOTE: Adapted from decode_line_2 in symtab.c, with which it ought
35255796c8dcSSimon Schubert to be re-integrated one of these days. */
35265796c8dcSSimon Schubert
35275796c8dcSSimon Schubert int
user_select_syms(struct ada_symbol_info * syms,int nsyms,int max_results)35285796c8dcSSimon Schubert user_select_syms (struct ada_symbol_info *syms, int nsyms, int max_results)
35295796c8dcSSimon Schubert {
35305796c8dcSSimon Schubert int i;
35315796c8dcSSimon Schubert int *chosen = (int *) alloca (sizeof (int) * nsyms);
35325796c8dcSSimon Schubert int n_chosen;
35335796c8dcSSimon Schubert int first_choice = (max_results == 1) ? 1 : 2;
35345796c8dcSSimon Schubert const char *select_mode = multiple_symbols_select_mode ();
35355796c8dcSSimon Schubert
35365796c8dcSSimon Schubert if (max_results < 1)
35375796c8dcSSimon Schubert error (_("Request to select 0 symbols!"));
35385796c8dcSSimon Schubert if (nsyms <= 1)
35395796c8dcSSimon Schubert return nsyms;
35405796c8dcSSimon Schubert
35415796c8dcSSimon Schubert if (select_mode == multiple_symbols_cancel)
35425796c8dcSSimon Schubert error (_("\
35435796c8dcSSimon Schubert canceled because the command is ambiguous\n\
35445796c8dcSSimon Schubert See set/show multiple-symbol."));
35455796c8dcSSimon Schubert
35465796c8dcSSimon Schubert /* If select_mode is "all", then return all possible symbols.
35475796c8dcSSimon Schubert Only do that if more than one symbol can be selected, of course.
35485796c8dcSSimon Schubert Otherwise, display the menu as usual. */
35495796c8dcSSimon Schubert if (select_mode == multiple_symbols_all && max_results > 1)
35505796c8dcSSimon Schubert return nsyms;
35515796c8dcSSimon Schubert
35525796c8dcSSimon Schubert printf_unfiltered (_("[0] cancel\n"));
35535796c8dcSSimon Schubert if (max_results > 1)
35545796c8dcSSimon Schubert printf_unfiltered (_("[1] all\n"));
35555796c8dcSSimon Schubert
35565796c8dcSSimon Schubert sort_choices (syms, nsyms);
35575796c8dcSSimon Schubert
35585796c8dcSSimon Schubert for (i = 0; i < nsyms; i += 1)
35595796c8dcSSimon Schubert {
35605796c8dcSSimon Schubert if (syms[i].sym == NULL)
35615796c8dcSSimon Schubert continue;
35625796c8dcSSimon Schubert
35635796c8dcSSimon Schubert if (SYMBOL_CLASS (syms[i].sym) == LOC_BLOCK)
35645796c8dcSSimon Schubert {
35655796c8dcSSimon Schubert struct symtab_and_line sal =
35665796c8dcSSimon Schubert find_function_start_sal (syms[i].sym, 1);
3567cf7f2e2dSJohn Marino
35685796c8dcSSimon Schubert if (sal.symtab == NULL)
35695796c8dcSSimon Schubert printf_unfiltered (_("[%d] %s at <no source file available>:%d\n"),
35705796c8dcSSimon Schubert i + first_choice,
35715796c8dcSSimon Schubert SYMBOL_PRINT_NAME (syms[i].sym),
35725796c8dcSSimon Schubert sal.line);
35735796c8dcSSimon Schubert else
35745796c8dcSSimon Schubert printf_unfiltered (_("[%d] %s at %s:%d\n"), i + first_choice,
35755796c8dcSSimon Schubert SYMBOL_PRINT_NAME (syms[i].sym),
3576*ef5ccd6cSJohn Marino symtab_to_filename_for_display (sal.symtab),
3577*ef5ccd6cSJohn Marino sal.line);
35785796c8dcSSimon Schubert continue;
35795796c8dcSSimon Schubert }
35805796c8dcSSimon Schubert else
35815796c8dcSSimon Schubert {
35825796c8dcSSimon Schubert int is_enumeral =
35835796c8dcSSimon Schubert (SYMBOL_CLASS (syms[i].sym) == LOC_CONST
35845796c8dcSSimon Schubert && SYMBOL_TYPE (syms[i].sym) != NULL
35855796c8dcSSimon Schubert && TYPE_CODE (SYMBOL_TYPE (syms[i].sym)) == TYPE_CODE_ENUM);
3586*ef5ccd6cSJohn Marino struct symtab *symtab = SYMBOL_SYMTAB (syms[i].sym);
35875796c8dcSSimon Schubert
35885796c8dcSSimon Schubert if (SYMBOL_LINE (syms[i].sym) != 0 && symtab != NULL)
35895796c8dcSSimon Schubert printf_unfiltered (_("[%d] %s at %s:%d\n"),
35905796c8dcSSimon Schubert i + first_choice,
35915796c8dcSSimon Schubert SYMBOL_PRINT_NAME (syms[i].sym),
3592*ef5ccd6cSJohn Marino symtab_to_filename_for_display (symtab),
3593*ef5ccd6cSJohn Marino SYMBOL_LINE (syms[i].sym));
35945796c8dcSSimon Schubert else if (is_enumeral
35955796c8dcSSimon Schubert && TYPE_NAME (SYMBOL_TYPE (syms[i].sym)) != NULL)
35965796c8dcSSimon Schubert {
35975796c8dcSSimon Schubert printf_unfiltered (("[%d] "), i + first_choice);
35985796c8dcSSimon Schubert ada_print_type (SYMBOL_TYPE (syms[i].sym), NULL,
3599*ef5ccd6cSJohn Marino gdb_stdout, -1, 0, &type_print_raw_options);
36005796c8dcSSimon Schubert printf_unfiltered (_("'(%s) (enumeral)\n"),
36015796c8dcSSimon Schubert SYMBOL_PRINT_NAME (syms[i].sym));
36025796c8dcSSimon Schubert }
36035796c8dcSSimon Schubert else if (symtab != NULL)
36045796c8dcSSimon Schubert printf_unfiltered (is_enumeral
36055796c8dcSSimon Schubert ? _("[%d] %s in %s (enumeral)\n")
36065796c8dcSSimon Schubert : _("[%d] %s at %s:?\n"),
36075796c8dcSSimon Schubert i + first_choice,
36085796c8dcSSimon Schubert SYMBOL_PRINT_NAME (syms[i].sym),
3609*ef5ccd6cSJohn Marino symtab_to_filename_for_display (symtab));
36105796c8dcSSimon Schubert else
36115796c8dcSSimon Schubert printf_unfiltered (is_enumeral
36125796c8dcSSimon Schubert ? _("[%d] %s (enumeral)\n")
36135796c8dcSSimon Schubert : _("[%d] %s at ?\n"),
36145796c8dcSSimon Schubert i + first_choice,
36155796c8dcSSimon Schubert SYMBOL_PRINT_NAME (syms[i].sym));
36165796c8dcSSimon Schubert }
36175796c8dcSSimon Schubert }
36185796c8dcSSimon Schubert
36195796c8dcSSimon Schubert n_chosen = get_selections (chosen, nsyms, max_results, max_results > 1,
36205796c8dcSSimon Schubert "overload-choice");
36215796c8dcSSimon Schubert
36225796c8dcSSimon Schubert for (i = 0; i < n_chosen; i += 1)
36235796c8dcSSimon Schubert syms[i] = syms[chosen[i]];
36245796c8dcSSimon Schubert
36255796c8dcSSimon Schubert return n_chosen;
36265796c8dcSSimon Schubert }
36275796c8dcSSimon Schubert
36285796c8dcSSimon Schubert /* Read and validate a set of numeric choices from the user in the
36295796c8dcSSimon Schubert range 0 .. N_CHOICES-1. Place the results in increasing
36305796c8dcSSimon Schubert order in CHOICES[0 .. N-1], and return N.
36315796c8dcSSimon Schubert
36325796c8dcSSimon Schubert The user types choices as a sequence of numbers on one line
36335796c8dcSSimon Schubert separated by blanks, encoding them as follows:
36345796c8dcSSimon Schubert
36355796c8dcSSimon Schubert + A choice of 0 means to cancel the selection, throwing an error.
36365796c8dcSSimon Schubert + If IS_ALL_CHOICE, a choice of 1 selects the entire set 0 .. N_CHOICES-1.
36375796c8dcSSimon Schubert + The user chooses k by typing k+IS_ALL_CHOICE+1.
36385796c8dcSSimon Schubert
36395796c8dcSSimon Schubert The user is not allowed to choose more than MAX_RESULTS values.
36405796c8dcSSimon Schubert
36415796c8dcSSimon Schubert ANNOTATION_SUFFIX, if present, is used to annotate the input
36425796c8dcSSimon Schubert prompts (for use with the -f switch). */
36435796c8dcSSimon Schubert
36445796c8dcSSimon Schubert int
get_selections(int * choices,int n_choices,int max_results,int is_all_choice,char * annotation_suffix)36455796c8dcSSimon Schubert get_selections (int *choices, int n_choices, int max_results,
36465796c8dcSSimon Schubert int is_all_choice, char *annotation_suffix)
36475796c8dcSSimon Schubert {
36485796c8dcSSimon Schubert char *args;
36495796c8dcSSimon Schubert char *prompt;
36505796c8dcSSimon Schubert int n_chosen;
36515796c8dcSSimon Schubert int first_choice = is_all_choice ? 2 : 1;
36525796c8dcSSimon Schubert
36535796c8dcSSimon Schubert prompt = getenv ("PS2");
36545796c8dcSSimon Schubert if (prompt == NULL)
36555796c8dcSSimon Schubert prompt = "> ";
36565796c8dcSSimon Schubert
36575796c8dcSSimon Schubert args = command_line_input (prompt, 0, annotation_suffix);
36585796c8dcSSimon Schubert
36595796c8dcSSimon Schubert if (args == NULL)
36605796c8dcSSimon Schubert error_no_arg (_("one or more choice numbers"));
36615796c8dcSSimon Schubert
36625796c8dcSSimon Schubert n_chosen = 0;
36635796c8dcSSimon Schubert
36645796c8dcSSimon Schubert /* Set choices[0 .. n_chosen-1] to the users' choices in ascending
36655796c8dcSSimon Schubert order, as given in args. Choices are validated. */
36665796c8dcSSimon Schubert while (1)
36675796c8dcSSimon Schubert {
36685796c8dcSSimon Schubert char *args2;
36695796c8dcSSimon Schubert int choice, j;
36705796c8dcSSimon Schubert
3671*ef5ccd6cSJohn Marino args = skip_spaces (args);
36725796c8dcSSimon Schubert if (*args == '\0' && n_chosen == 0)
36735796c8dcSSimon Schubert error_no_arg (_("one or more choice numbers"));
36745796c8dcSSimon Schubert else if (*args == '\0')
36755796c8dcSSimon Schubert break;
36765796c8dcSSimon Schubert
36775796c8dcSSimon Schubert choice = strtol (args, &args2, 10);
36785796c8dcSSimon Schubert if (args == args2 || choice < 0
36795796c8dcSSimon Schubert || choice > n_choices + first_choice - 1)
36805796c8dcSSimon Schubert error (_("Argument must be choice number"));
36815796c8dcSSimon Schubert args = args2;
36825796c8dcSSimon Schubert
36835796c8dcSSimon Schubert if (choice == 0)
36845796c8dcSSimon Schubert error (_("cancelled"));
36855796c8dcSSimon Schubert
36865796c8dcSSimon Schubert if (choice < first_choice)
36875796c8dcSSimon Schubert {
36885796c8dcSSimon Schubert n_chosen = n_choices;
36895796c8dcSSimon Schubert for (j = 0; j < n_choices; j += 1)
36905796c8dcSSimon Schubert choices[j] = j;
36915796c8dcSSimon Schubert break;
36925796c8dcSSimon Schubert }
36935796c8dcSSimon Schubert choice -= first_choice;
36945796c8dcSSimon Schubert
36955796c8dcSSimon Schubert for (j = n_chosen - 1; j >= 0 && choice < choices[j]; j -= 1)
36965796c8dcSSimon Schubert {
36975796c8dcSSimon Schubert }
36985796c8dcSSimon Schubert
36995796c8dcSSimon Schubert if (j < 0 || choice != choices[j])
37005796c8dcSSimon Schubert {
37015796c8dcSSimon Schubert int k;
3702cf7f2e2dSJohn Marino
37035796c8dcSSimon Schubert for (k = n_chosen - 1; k > j; k -= 1)
37045796c8dcSSimon Schubert choices[k + 1] = choices[k];
37055796c8dcSSimon Schubert choices[j + 1] = choice;
37065796c8dcSSimon Schubert n_chosen += 1;
37075796c8dcSSimon Schubert }
37085796c8dcSSimon Schubert }
37095796c8dcSSimon Schubert
37105796c8dcSSimon Schubert if (n_chosen > max_results)
37115796c8dcSSimon Schubert error (_("Select no more than %d of the above"), max_results);
37125796c8dcSSimon Schubert
37135796c8dcSSimon Schubert return n_chosen;
37145796c8dcSSimon Schubert }
37155796c8dcSSimon Schubert
37165796c8dcSSimon Schubert /* Replace the operator of length OPLEN at position PC in *EXPP with a call
37175796c8dcSSimon Schubert on the function identified by SYM and BLOCK, and taking NARGS
37185796c8dcSSimon Schubert arguments. Update *EXPP as needed to hold more space. */
37195796c8dcSSimon Schubert
37205796c8dcSSimon Schubert static void
replace_operator_with_call(struct expression ** expp,int pc,int nargs,int oplen,struct symbol * sym,const struct block * block)37215796c8dcSSimon Schubert replace_operator_with_call (struct expression **expp, int pc, int nargs,
37225796c8dcSSimon Schubert int oplen, struct symbol *sym,
3723*ef5ccd6cSJohn Marino const struct block *block)
37245796c8dcSSimon Schubert {
37255796c8dcSSimon Schubert /* A new expression, with 6 more elements (3 for funcall, 4 for function
37265796c8dcSSimon Schubert symbol, -oplen for operator being replaced). */
37275796c8dcSSimon Schubert struct expression *newexp = (struct expression *)
3728c50c785cSJohn Marino xzalloc (sizeof (struct expression)
37295796c8dcSSimon Schubert + EXP_ELEM_TO_BYTES ((*expp)->nelts + 7 - oplen));
37305796c8dcSSimon Schubert struct expression *exp = *expp;
37315796c8dcSSimon Schubert
37325796c8dcSSimon Schubert newexp->nelts = exp->nelts + 7 - oplen;
37335796c8dcSSimon Schubert newexp->language_defn = exp->language_defn;
3734c50c785cSJohn Marino newexp->gdbarch = exp->gdbarch;
37355796c8dcSSimon Schubert memcpy (newexp->elts, exp->elts, EXP_ELEM_TO_BYTES (pc));
37365796c8dcSSimon Schubert memcpy (newexp->elts + pc + 7, exp->elts + pc + oplen,
37375796c8dcSSimon Schubert EXP_ELEM_TO_BYTES (exp->nelts - pc - oplen));
37385796c8dcSSimon Schubert
37395796c8dcSSimon Schubert newexp->elts[pc].opcode = newexp->elts[pc + 2].opcode = OP_FUNCALL;
37405796c8dcSSimon Schubert newexp->elts[pc + 1].longconst = (LONGEST) nargs;
37415796c8dcSSimon Schubert
37425796c8dcSSimon Schubert newexp->elts[pc + 3].opcode = newexp->elts[pc + 6].opcode = OP_VAR_VALUE;
37435796c8dcSSimon Schubert newexp->elts[pc + 4].block = block;
37445796c8dcSSimon Schubert newexp->elts[pc + 5].symbol = sym;
37455796c8dcSSimon Schubert
37465796c8dcSSimon Schubert *expp = newexp;
37475796c8dcSSimon Schubert xfree (exp);
37485796c8dcSSimon Schubert }
37495796c8dcSSimon Schubert
37505796c8dcSSimon Schubert /* Type-class predicates */
37515796c8dcSSimon Schubert
37525796c8dcSSimon Schubert /* True iff TYPE is numeric (i.e., an INT, RANGE (of numeric type),
37535796c8dcSSimon Schubert or FLOAT). */
37545796c8dcSSimon Schubert
37555796c8dcSSimon Schubert static int
numeric_type_p(struct type * type)37565796c8dcSSimon Schubert numeric_type_p (struct type *type)
37575796c8dcSSimon Schubert {
37585796c8dcSSimon Schubert if (type == NULL)
37595796c8dcSSimon Schubert return 0;
37605796c8dcSSimon Schubert else
37615796c8dcSSimon Schubert {
37625796c8dcSSimon Schubert switch (TYPE_CODE (type))
37635796c8dcSSimon Schubert {
37645796c8dcSSimon Schubert case TYPE_CODE_INT:
37655796c8dcSSimon Schubert case TYPE_CODE_FLT:
37665796c8dcSSimon Schubert return 1;
37675796c8dcSSimon Schubert case TYPE_CODE_RANGE:
37685796c8dcSSimon Schubert return (type == TYPE_TARGET_TYPE (type)
37695796c8dcSSimon Schubert || numeric_type_p (TYPE_TARGET_TYPE (type)));
37705796c8dcSSimon Schubert default:
37715796c8dcSSimon Schubert return 0;
37725796c8dcSSimon Schubert }
37735796c8dcSSimon Schubert }
37745796c8dcSSimon Schubert }
37755796c8dcSSimon Schubert
37765796c8dcSSimon Schubert /* True iff TYPE is integral (an INT or RANGE of INTs). */
37775796c8dcSSimon Schubert
37785796c8dcSSimon Schubert static int
integer_type_p(struct type * type)37795796c8dcSSimon Schubert integer_type_p (struct type *type)
37805796c8dcSSimon Schubert {
37815796c8dcSSimon Schubert if (type == NULL)
37825796c8dcSSimon Schubert return 0;
37835796c8dcSSimon Schubert else
37845796c8dcSSimon Schubert {
37855796c8dcSSimon Schubert switch (TYPE_CODE (type))
37865796c8dcSSimon Schubert {
37875796c8dcSSimon Schubert case TYPE_CODE_INT:
37885796c8dcSSimon Schubert return 1;
37895796c8dcSSimon Schubert case TYPE_CODE_RANGE:
37905796c8dcSSimon Schubert return (type == TYPE_TARGET_TYPE (type)
37915796c8dcSSimon Schubert || integer_type_p (TYPE_TARGET_TYPE (type)));
37925796c8dcSSimon Schubert default:
37935796c8dcSSimon Schubert return 0;
37945796c8dcSSimon Schubert }
37955796c8dcSSimon Schubert }
37965796c8dcSSimon Schubert }
37975796c8dcSSimon Schubert
37985796c8dcSSimon Schubert /* True iff TYPE is scalar (INT, RANGE, FLOAT, ENUM). */
37995796c8dcSSimon Schubert
38005796c8dcSSimon Schubert static int
scalar_type_p(struct type * type)38015796c8dcSSimon Schubert scalar_type_p (struct type *type)
38025796c8dcSSimon Schubert {
38035796c8dcSSimon Schubert if (type == NULL)
38045796c8dcSSimon Schubert return 0;
38055796c8dcSSimon Schubert else
38065796c8dcSSimon Schubert {
38075796c8dcSSimon Schubert switch (TYPE_CODE (type))
38085796c8dcSSimon Schubert {
38095796c8dcSSimon Schubert case TYPE_CODE_INT:
38105796c8dcSSimon Schubert case TYPE_CODE_RANGE:
38115796c8dcSSimon Schubert case TYPE_CODE_ENUM:
38125796c8dcSSimon Schubert case TYPE_CODE_FLT:
38135796c8dcSSimon Schubert return 1;
38145796c8dcSSimon Schubert default:
38155796c8dcSSimon Schubert return 0;
38165796c8dcSSimon Schubert }
38175796c8dcSSimon Schubert }
38185796c8dcSSimon Schubert }
38195796c8dcSSimon Schubert
38205796c8dcSSimon Schubert /* True iff TYPE is discrete (INT, RANGE, ENUM). */
38215796c8dcSSimon Schubert
38225796c8dcSSimon Schubert static int
discrete_type_p(struct type * type)38235796c8dcSSimon Schubert discrete_type_p (struct type *type)
38245796c8dcSSimon Schubert {
38255796c8dcSSimon Schubert if (type == NULL)
38265796c8dcSSimon Schubert return 0;
38275796c8dcSSimon Schubert else
38285796c8dcSSimon Schubert {
38295796c8dcSSimon Schubert switch (TYPE_CODE (type))
38305796c8dcSSimon Schubert {
38315796c8dcSSimon Schubert case TYPE_CODE_INT:
38325796c8dcSSimon Schubert case TYPE_CODE_RANGE:
38335796c8dcSSimon Schubert case TYPE_CODE_ENUM:
3834cf7f2e2dSJohn Marino case TYPE_CODE_BOOL:
38355796c8dcSSimon Schubert return 1;
38365796c8dcSSimon Schubert default:
38375796c8dcSSimon Schubert return 0;
38385796c8dcSSimon Schubert }
38395796c8dcSSimon Schubert }
38405796c8dcSSimon Schubert }
38415796c8dcSSimon Schubert
38425796c8dcSSimon Schubert /* Returns non-zero if OP with operands in the vector ARGS could be
38435796c8dcSSimon Schubert a user-defined function. Errs on the side of pre-defined operators
38445796c8dcSSimon Schubert (i.e., result 0). */
38455796c8dcSSimon Schubert
38465796c8dcSSimon Schubert static int
possible_user_operator_p(enum exp_opcode op,struct value * args[])38475796c8dcSSimon Schubert possible_user_operator_p (enum exp_opcode op, struct value *args[])
38485796c8dcSSimon Schubert {
38495796c8dcSSimon Schubert struct type *type0 =
38505796c8dcSSimon Schubert (args[0] == NULL) ? NULL : ada_check_typedef (value_type (args[0]));
38515796c8dcSSimon Schubert struct type *type1 =
38525796c8dcSSimon Schubert (args[1] == NULL) ? NULL : ada_check_typedef (value_type (args[1]));
38535796c8dcSSimon Schubert
38545796c8dcSSimon Schubert if (type0 == NULL)
38555796c8dcSSimon Schubert return 0;
38565796c8dcSSimon Schubert
38575796c8dcSSimon Schubert switch (op)
38585796c8dcSSimon Schubert {
38595796c8dcSSimon Schubert default:
38605796c8dcSSimon Schubert return 0;
38615796c8dcSSimon Schubert
38625796c8dcSSimon Schubert case BINOP_ADD:
38635796c8dcSSimon Schubert case BINOP_SUB:
38645796c8dcSSimon Schubert case BINOP_MUL:
38655796c8dcSSimon Schubert case BINOP_DIV:
38665796c8dcSSimon Schubert return (!(numeric_type_p (type0) && numeric_type_p (type1)));
38675796c8dcSSimon Schubert
38685796c8dcSSimon Schubert case BINOP_REM:
38695796c8dcSSimon Schubert case BINOP_MOD:
38705796c8dcSSimon Schubert case BINOP_BITWISE_AND:
38715796c8dcSSimon Schubert case BINOP_BITWISE_IOR:
38725796c8dcSSimon Schubert case BINOP_BITWISE_XOR:
38735796c8dcSSimon Schubert return (!(integer_type_p (type0) && integer_type_p (type1)));
38745796c8dcSSimon Schubert
38755796c8dcSSimon Schubert case BINOP_EQUAL:
38765796c8dcSSimon Schubert case BINOP_NOTEQUAL:
38775796c8dcSSimon Schubert case BINOP_LESS:
38785796c8dcSSimon Schubert case BINOP_GTR:
38795796c8dcSSimon Schubert case BINOP_LEQ:
38805796c8dcSSimon Schubert case BINOP_GEQ:
38815796c8dcSSimon Schubert return (!(scalar_type_p (type0) && scalar_type_p (type1)));
38825796c8dcSSimon Schubert
38835796c8dcSSimon Schubert case BINOP_CONCAT:
38845796c8dcSSimon Schubert return !ada_is_array_type (type0) || !ada_is_array_type (type1);
38855796c8dcSSimon Schubert
38865796c8dcSSimon Schubert case BINOP_EXP:
38875796c8dcSSimon Schubert return (!(numeric_type_p (type0) && integer_type_p (type1)));
38885796c8dcSSimon Schubert
38895796c8dcSSimon Schubert case UNOP_NEG:
38905796c8dcSSimon Schubert case UNOP_PLUS:
38915796c8dcSSimon Schubert case UNOP_LOGICAL_NOT:
38925796c8dcSSimon Schubert case UNOP_ABS:
38935796c8dcSSimon Schubert return (!numeric_type_p (type0));
38945796c8dcSSimon Schubert
38955796c8dcSSimon Schubert }
38965796c8dcSSimon Schubert }
38975796c8dcSSimon Schubert
38985796c8dcSSimon Schubert /* Renaming */
38995796c8dcSSimon Schubert
39005796c8dcSSimon Schubert /* NOTES:
39015796c8dcSSimon Schubert
39025796c8dcSSimon Schubert 1. In the following, we assume that a renaming type's name may
39035796c8dcSSimon Schubert have an ___XD suffix. It would be nice if this went away at some
39045796c8dcSSimon Schubert point.
39055796c8dcSSimon Schubert 2. We handle both the (old) purely type-based representation of
39065796c8dcSSimon Schubert renamings and the (new) variable-based encoding. At some point,
39075796c8dcSSimon Schubert it is devoutly to be hoped that the former goes away
39085796c8dcSSimon Schubert (FIXME: hilfinger-2007-07-09).
39095796c8dcSSimon Schubert 3. Subprogram renamings are not implemented, although the XRS
39105796c8dcSSimon Schubert suffix is recognized (FIXME: hilfinger-2007-07-09). */
39115796c8dcSSimon Schubert
39125796c8dcSSimon Schubert /* If SYM encodes a renaming,
39135796c8dcSSimon Schubert
39145796c8dcSSimon Schubert <renaming> renames <renamed entity>,
39155796c8dcSSimon Schubert
39165796c8dcSSimon Schubert sets *LEN to the length of the renamed entity's name,
39175796c8dcSSimon Schubert *RENAMED_ENTITY to that name (not null-terminated), and *RENAMING_EXPR to
39185796c8dcSSimon Schubert the string describing the subcomponent selected from the renamed
39195796c8dcSSimon Schubert entity. Returns ADA_NOT_RENAMING if SYM does not encode a renaming
39205796c8dcSSimon Schubert (in which case, the values of *RENAMED_ENTITY, *LEN, and *RENAMING_EXPR
39215796c8dcSSimon Schubert are undefined). Otherwise, returns a value indicating the category
39225796c8dcSSimon Schubert of entity renamed: an object (ADA_OBJECT_RENAMING), exception
39235796c8dcSSimon Schubert (ADA_EXCEPTION_RENAMING), package (ADA_PACKAGE_RENAMING), or
39245796c8dcSSimon Schubert subprogram (ADA_SUBPROGRAM_RENAMING). Does no allocation; the
39255796c8dcSSimon Schubert strings returned in *RENAMED_ENTITY and *RENAMING_EXPR should not be
39265796c8dcSSimon Schubert deallocated. The values of RENAMED_ENTITY, LEN, or RENAMING_EXPR
39275796c8dcSSimon Schubert may be NULL, in which case they are not assigned.
39285796c8dcSSimon Schubert
39295796c8dcSSimon Schubert [Currently, however, GCC does not generate subprogram renamings.] */
39305796c8dcSSimon Schubert
39315796c8dcSSimon Schubert enum ada_renaming_category
ada_parse_renaming(struct symbol * sym,const char ** renamed_entity,int * len,const char ** renaming_expr)39325796c8dcSSimon Schubert ada_parse_renaming (struct symbol *sym,
39335796c8dcSSimon Schubert const char **renamed_entity, int *len,
39345796c8dcSSimon Schubert const char **renaming_expr)
39355796c8dcSSimon Schubert {
39365796c8dcSSimon Schubert enum ada_renaming_category kind;
39375796c8dcSSimon Schubert const char *info;
39385796c8dcSSimon Schubert const char *suffix;
39395796c8dcSSimon Schubert
39405796c8dcSSimon Schubert if (sym == NULL)
39415796c8dcSSimon Schubert return ADA_NOT_RENAMING;
39425796c8dcSSimon Schubert switch (SYMBOL_CLASS (sym))
39435796c8dcSSimon Schubert {
39445796c8dcSSimon Schubert default:
39455796c8dcSSimon Schubert return ADA_NOT_RENAMING;
39465796c8dcSSimon Schubert case LOC_TYPEDEF:
39475796c8dcSSimon Schubert return parse_old_style_renaming (SYMBOL_TYPE (sym),
39485796c8dcSSimon Schubert renamed_entity, len, renaming_expr);
39495796c8dcSSimon Schubert case LOC_LOCAL:
39505796c8dcSSimon Schubert case LOC_STATIC:
39515796c8dcSSimon Schubert case LOC_COMPUTED:
39525796c8dcSSimon Schubert case LOC_OPTIMIZED_OUT:
39535796c8dcSSimon Schubert info = strstr (SYMBOL_LINKAGE_NAME (sym), "___XR");
39545796c8dcSSimon Schubert if (info == NULL)
39555796c8dcSSimon Schubert return ADA_NOT_RENAMING;
39565796c8dcSSimon Schubert switch (info[5])
39575796c8dcSSimon Schubert {
39585796c8dcSSimon Schubert case '_':
39595796c8dcSSimon Schubert kind = ADA_OBJECT_RENAMING;
39605796c8dcSSimon Schubert info += 6;
39615796c8dcSSimon Schubert break;
39625796c8dcSSimon Schubert case 'E':
39635796c8dcSSimon Schubert kind = ADA_EXCEPTION_RENAMING;
39645796c8dcSSimon Schubert info += 7;
39655796c8dcSSimon Schubert break;
39665796c8dcSSimon Schubert case 'P':
39675796c8dcSSimon Schubert kind = ADA_PACKAGE_RENAMING;
39685796c8dcSSimon Schubert info += 7;
39695796c8dcSSimon Schubert break;
39705796c8dcSSimon Schubert case 'S':
39715796c8dcSSimon Schubert kind = ADA_SUBPROGRAM_RENAMING;
39725796c8dcSSimon Schubert info += 7;
39735796c8dcSSimon Schubert break;
39745796c8dcSSimon Schubert default:
39755796c8dcSSimon Schubert return ADA_NOT_RENAMING;
39765796c8dcSSimon Schubert }
39775796c8dcSSimon Schubert }
39785796c8dcSSimon Schubert
39795796c8dcSSimon Schubert if (renamed_entity != NULL)
39805796c8dcSSimon Schubert *renamed_entity = info;
39815796c8dcSSimon Schubert suffix = strstr (info, "___XE");
39825796c8dcSSimon Schubert if (suffix == NULL || suffix == info)
39835796c8dcSSimon Schubert return ADA_NOT_RENAMING;
39845796c8dcSSimon Schubert if (len != NULL)
39855796c8dcSSimon Schubert *len = strlen (info) - strlen (suffix);
39865796c8dcSSimon Schubert suffix += 5;
39875796c8dcSSimon Schubert if (renaming_expr != NULL)
39885796c8dcSSimon Schubert *renaming_expr = suffix;
39895796c8dcSSimon Schubert return kind;
39905796c8dcSSimon Schubert }
39915796c8dcSSimon Schubert
39925796c8dcSSimon Schubert /* Assuming TYPE encodes a renaming according to the old encoding in
39935796c8dcSSimon Schubert exp_dbug.ads, returns details of that renaming in *RENAMED_ENTITY,
39945796c8dcSSimon Schubert *LEN, and *RENAMING_EXPR, as for ada_parse_renaming, above. Returns
39955796c8dcSSimon Schubert ADA_NOT_RENAMING otherwise. */
39965796c8dcSSimon Schubert static enum ada_renaming_category
parse_old_style_renaming(struct type * type,const char ** renamed_entity,int * len,const char ** renaming_expr)39975796c8dcSSimon Schubert parse_old_style_renaming (struct type *type,
39985796c8dcSSimon Schubert const char **renamed_entity, int *len,
39995796c8dcSSimon Schubert const char **renaming_expr)
40005796c8dcSSimon Schubert {
40015796c8dcSSimon Schubert enum ada_renaming_category kind;
40025796c8dcSSimon Schubert const char *name;
40035796c8dcSSimon Schubert const char *info;
40045796c8dcSSimon Schubert const char *suffix;
40055796c8dcSSimon Schubert
40065796c8dcSSimon Schubert if (type == NULL || TYPE_CODE (type) != TYPE_CODE_ENUM
40075796c8dcSSimon Schubert || TYPE_NFIELDS (type) != 1)
40085796c8dcSSimon Schubert return ADA_NOT_RENAMING;
40095796c8dcSSimon Schubert
40105796c8dcSSimon Schubert name = type_name_no_tag (type);
40115796c8dcSSimon Schubert if (name == NULL)
40125796c8dcSSimon Schubert return ADA_NOT_RENAMING;
40135796c8dcSSimon Schubert
40145796c8dcSSimon Schubert name = strstr (name, "___XR");
40155796c8dcSSimon Schubert if (name == NULL)
40165796c8dcSSimon Schubert return ADA_NOT_RENAMING;
40175796c8dcSSimon Schubert switch (name[5])
40185796c8dcSSimon Schubert {
40195796c8dcSSimon Schubert case '\0':
40205796c8dcSSimon Schubert case '_':
40215796c8dcSSimon Schubert kind = ADA_OBJECT_RENAMING;
40225796c8dcSSimon Schubert break;
40235796c8dcSSimon Schubert case 'E':
40245796c8dcSSimon Schubert kind = ADA_EXCEPTION_RENAMING;
40255796c8dcSSimon Schubert break;
40265796c8dcSSimon Schubert case 'P':
40275796c8dcSSimon Schubert kind = ADA_PACKAGE_RENAMING;
40285796c8dcSSimon Schubert break;
40295796c8dcSSimon Schubert case 'S':
40305796c8dcSSimon Schubert kind = ADA_SUBPROGRAM_RENAMING;
40315796c8dcSSimon Schubert break;
40325796c8dcSSimon Schubert default:
40335796c8dcSSimon Schubert return ADA_NOT_RENAMING;
40345796c8dcSSimon Schubert }
40355796c8dcSSimon Schubert
40365796c8dcSSimon Schubert info = TYPE_FIELD_NAME (type, 0);
40375796c8dcSSimon Schubert if (info == NULL)
40385796c8dcSSimon Schubert return ADA_NOT_RENAMING;
40395796c8dcSSimon Schubert if (renamed_entity != NULL)
40405796c8dcSSimon Schubert *renamed_entity = info;
40415796c8dcSSimon Schubert suffix = strstr (info, "___XE");
40425796c8dcSSimon Schubert if (renaming_expr != NULL)
40435796c8dcSSimon Schubert *renaming_expr = suffix + 5;
40445796c8dcSSimon Schubert if (suffix == NULL || suffix == info)
40455796c8dcSSimon Schubert return ADA_NOT_RENAMING;
40465796c8dcSSimon Schubert if (len != NULL)
40475796c8dcSSimon Schubert *len = suffix - info;
40485796c8dcSSimon Schubert return kind;
40495796c8dcSSimon Schubert }
40505796c8dcSSimon Schubert
4051*ef5ccd6cSJohn Marino /* Compute the value of the given RENAMING_SYM, which is expected to
4052*ef5ccd6cSJohn Marino be a symbol encoding a renaming expression. BLOCK is the block
4053*ef5ccd6cSJohn Marino used to evaluate the renaming. */
4054*ef5ccd6cSJohn Marino
4055*ef5ccd6cSJohn Marino static struct value *
ada_read_renaming_var_value(struct symbol * renaming_sym,struct block * block)4056*ef5ccd6cSJohn Marino ada_read_renaming_var_value (struct symbol *renaming_sym,
4057*ef5ccd6cSJohn Marino struct block *block)
4058*ef5ccd6cSJohn Marino {
4059*ef5ccd6cSJohn Marino const char *sym_name;
4060*ef5ccd6cSJohn Marino struct expression *expr;
4061*ef5ccd6cSJohn Marino struct value *value;
4062*ef5ccd6cSJohn Marino struct cleanup *old_chain = NULL;
4063*ef5ccd6cSJohn Marino
4064*ef5ccd6cSJohn Marino sym_name = SYMBOL_LINKAGE_NAME (renaming_sym);
4065*ef5ccd6cSJohn Marino expr = parse_exp_1 (&sym_name, 0, block, 0);
4066*ef5ccd6cSJohn Marino old_chain = make_cleanup (free_current_contents, &expr);
4067*ef5ccd6cSJohn Marino value = evaluate_expression (expr);
4068*ef5ccd6cSJohn Marino
4069*ef5ccd6cSJohn Marino do_cleanups (old_chain);
4070*ef5ccd6cSJohn Marino return value;
4071*ef5ccd6cSJohn Marino }
40725796c8dcSSimon Schubert
40735796c8dcSSimon Schubert
40745796c8dcSSimon Schubert /* Evaluation: Function Calls */
40755796c8dcSSimon Schubert
40765796c8dcSSimon Schubert /* Return an lvalue containing the value VAL. This is the identity on
4077c50c785cSJohn Marino lvalues, and otherwise has the side-effect of allocating memory
4078c50c785cSJohn Marino in the inferior where a copy of the value contents is copied. */
40795796c8dcSSimon Schubert
40805796c8dcSSimon Schubert static struct value *
ensure_lval(struct value * val)4081c50c785cSJohn Marino ensure_lval (struct value *val)
40825796c8dcSSimon Schubert {
4083c50c785cSJohn Marino if (VALUE_LVAL (val) == not_lval
4084c50c785cSJohn Marino || VALUE_LVAL (val) == lval_internalvar)
40855796c8dcSSimon Schubert {
40865796c8dcSSimon Schubert int len = TYPE_LENGTH (ada_check_typedef (value_type (val)));
4087c50c785cSJohn Marino const CORE_ADDR addr =
4088c50c785cSJohn Marino value_as_long (value_allocate_space_in_inferior (len));
40895796c8dcSSimon Schubert
4090c50c785cSJohn Marino set_value_address (val, addr);
40915796c8dcSSimon Schubert VALUE_LVAL (val) = lval_memory;
4092c50c785cSJohn Marino write_memory (addr, value_contents (val), len);
40935796c8dcSSimon Schubert }
40945796c8dcSSimon Schubert
40955796c8dcSSimon Schubert return val;
40965796c8dcSSimon Schubert }
40975796c8dcSSimon Schubert
40985796c8dcSSimon Schubert /* Return the value ACTUAL, converted to be an appropriate value for a
40995796c8dcSSimon Schubert formal of type FORMAL_TYPE. Use *SP as a stack pointer for
41005796c8dcSSimon Schubert allocating any necessary descriptors (fat pointers), or copies of
41015796c8dcSSimon Schubert values not residing in memory, updating it as needed. */
41025796c8dcSSimon Schubert
41035796c8dcSSimon Schubert struct value *
ada_convert_actual(struct value * actual,struct type * formal_type0)4104c50c785cSJohn Marino ada_convert_actual (struct value *actual, struct type *formal_type0)
41055796c8dcSSimon Schubert {
41065796c8dcSSimon Schubert struct type *actual_type = ada_check_typedef (value_type (actual));
41075796c8dcSSimon Schubert struct type *formal_type = ada_check_typedef (formal_type0);
41085796c8dcSSimon Schubert struct type *formal_target =
41095796c8dcSSimon Schubert TYPE_CODE (formal_type) == TYPE_CODE_PTR
41105796c8dcSSimon Schubert ? ada_check_typedef (TYPE_TARGET_TYPE (formal_type)) : formal_type;
41115796c8dcSSimon Schubert struct type *actual_target =
41125796c8dcSSimon Schubert TYPE_CODE (actual_type) == TYPE_CODE_PTR
41135796c8dcSSimon Schubert ? ada_check_typedef (TYPE_TARGET_TYPE (actual_type)) : actual_type;
41145796c8dcSSimon Schubert
41155796c8dcSSimon Schubert if (ada_is_array_descriptor_type (formal_target)
41165796c8dcSSimon Schubert && TYPE_CODE (actual_target) == TYPE_CODE_ARRAY)
4117c50c785cSJohn Marino return make_array_descriptor (formal_type, actual);
41185796c8dcSSimon Schubert else if (TYPE_CODE (formal_type) == TYPE_CODE_PTR
41195796c8dcSSimon Schubert || TYPE_CODE (formal_type) == TYPE_CODE_REF)
41205796c8dcSSimon Schubert {
41215796c8dcSSimon Schubert struct value *result;
4122cf7f2e2dSJohn Marino
41235796c8dcSSimon Schubert if (TYPE_CODE (formal_target) == TYPE_CODE_ARRAY
41245796c8dcSSimon Schubert && ada_is_array_descriptor_type (actual_target))
41255796c8dcSSimon Schubert result = desc_data (actual);
41265796c8dcSSimon Schubert else if (TYPE_CODE (actual_type) != TYPE_CODE_PTR)
41275796c8dcSSimon Schubert {
41285796c8dcSSimon Schubert if (VALUE_LVAL (actual) != lval_memory)
41295796c8dcSSimon Schubert {
41305796c8dcSSimon Schubert struct value *val;
4131cf7f2e2dSJohn Marino
41325796c8dcSSimon Schubert actual_type = ada_check_typedef (value_type (actual));
41335796c8dcSSimon Schubert val = allocate_value (actual_type);
41345796c8dcSSimon Schubert memcpy ((char *) value_contents_raw (val),
41355796c8dcSSimon Schubert (char *) value_contents (actual),
41365796c8dcSSimon Schubert TYPE_LENGTH (actual_type));
4137c50c785cSJohn Marino actual = ensure_lval (val);
41385796c8dcSSimon Schubert }
41395796c8dcSSimon Schubert result = value_addr (actual);
41405796c8dcSSimon Schubert }
41415796c8dcSSimon Schubert else
41425796c8dcSSimon Schubert return actual;
4143*ef5ccd6cSJohn Marino return value_cast_pointers (formal_type, result, 0);
41445796c8dcSSimon Schubert }
41455796c8dcSSimon Schubert else if (TYPE_CODE (actual_type) == TYPE_CODE_PTR)
41465796c8dcSSimon Schubert return ada_value_ind (actual);
41475796c8dcSSimon Schubert
41485796c8dcSSimon Schubert return actual;
41495796c8dcSSimon Schubert }
41505796c8dcSSimon Schubert
4151cf7f2e2dSJohn Marino /* Convert VALUE (which must be an address) to a CORE_ADDR that is a pointer of
4152cf7f2e2dSJohn Marino type TYPE. This is usually an inefficient no-op except on some targets
4153cf7f2e2dSJohn Marino (such as AVR) where the representation of a pointer and an address
4154cf7f2e2dSJohn Marino differs. */
4155cf7f2e2dSJohn Marino
4156cf7f2e2dSJohn Marino static CORE_ADDR
value_pointer(struct value * value,struct type * type)4157cf7f2e2dSJohn Marino value_pointer (struct value *value, struct type *type)
4158cf7f2e2dSJohn Marino {
4159cf7f2e2dSJohn Marino struct gdbarch *gdbarch = get_type_arch (type);
4160cf7f2e2dSJohn Marino unsigned len = TYPE_LENGTH (type);
4161cf7f2e2dSJohn Marino gdb_byte *buf = alloca (len);
4162cf7f2e2dSJohn Marino CORE_ADDR addr;
4163cf7f2e2dSJohn Marino
4164cf7f2e2dSJohn Marino addr = value_address (value);
4165cf7f2e2dSJohn Marino gdbarch_address_to_pointer (gdbarch, type, buf, addr);
4166cf7f2e2dSJohn Marino addr = extract_unsigned_integer (buf, len, gdbarch_byte_order (gdbarch));
4167cf7f2e2dSJohn Marino return addr;
4168cf7f2e2dSJohn Marino }
4169cf7f2e2dSJohn Marino
41705796c8dcSSimon Schubert
41715796c8dcSSimon Schubert /* Push a descriptor of type TYPE for array value ARR on the stack at
41725796c8dcSSimon Schubert *SP, updating *SP to reflect the new descriptor. Return either
41735796c8dcSSimon Schubert an lvalue representing the new descriptor, or (if TYPE is a pointer-
41745796c8dcSSimon Schubert to-descriptor type rather than a descriptor type), a struct value *
41755796c8dcSSimon Schubert representing a pointer to this descriptor. */
41765796c8dcSSimon Schubert
41775796c8dcSSimon Schubert static struct value *
make_array_descriptor(struct type * type,struct value * arr)4178c50c785cSJohn Marino make_array_descriptor (struct type *type, struct value *arr)
41795796c8dcSSimon Schubert {
41805796c8dcSSimon Schubert struct type *bounds_type = desc_bounds_type (type);
41815796c8dcSSimon Schubert struct type *desc_type = desc_base_type (type);
41825796c8dcSSimon Schubert struct value *descriptor = allocate_value (desc_type);
41835796c8dcSSimon Schubert struct value *bounds = allocate_value (bounds_type);
41845796c8dcSSimon Schubert int i;
41855796c8dcSSimon Schubert
4186c50c785cSJohn Marino for (i = ada_array_arity (ada_check_typedef (value_type (arr)));
4187c50c785cSJohn Marino i > 0; i -= 1)
41885796c8dcSSimon Schubert {
4189c50c785cSJohn Marino modify_field (value_type (bounds), value_contents_writeable (bounds),
41905796c8dcSSimon Schubert ada_array_bound (arr, i, 0),
41915796c8dcSSimon Schubert desc_bound_bitpos (bounds_type, i, 0),
41925796c8dcSSimon Schubert desc_bound_bitsize (bounds_type, i, 0));
4193c50c785cSJohn Marino modify_field (value_type (bounds), value_contents_writeable (bounds),
41945796c8dcSSimon Schubert ada_array_bound (arr, i, 1),
41955796c8dcSSimon Schubert desc_bound_bitpos (bounds_type, i, 1),
41965796c8dcSSimon Schubert desc_bound_bitsize (bounds_type, i, 1));
41975796c8dcSSimon Schubert }
41985796c8dcSSimon Schubert
4199c50c785cSJohn Marino bounds = ensure_lval (bounds);
42005796c8dcSSimon Schubert
4201c50c785cSJohn Marino modify_field (value_type (descriptor),
42025796c8dcSSimon Schubert value_contents_writeable (descriptor),
4203c50c785cSJohn Marino value_pointer (ensure_lval (arr),
4204cf7f2e2dSJohn Marino TYPE_FIELD_TYPE (desc_type, 0)),
42055796c8dcSSimon Schubert fat_pntr_data_bitpos (desc_type),
42065796c8dcSSimon Schubert fat_pntr_data_bitsize (desc_type));
42075796c8dcSSimon Schubert
4208c50c785cSJohn Marino modify_field (value_type (descriptor),
42095796c8dcSSimon Schubert value_contents_writeable (descriptor),
4210cf7f2e2dSJohn Marino value_pointer (bounds,
4211cf7f2e2dSJohn Marino TYPE_FIELD_TYPE (desc_type, 1)),
42125796c8dcSSimon Schubert fat_pntr_bounds_bitpos (desc_type),
42135796c8dcSSimon Schubert fat_pntr_bounds_bitsize (desc_type));
42145796c8dcSSimon Schubert
4215c50c785cSJohn Marino descriptor = ensure_lval (descriptor);
42165796c8dcSSimon Schubert
42175796c8dcSSimon Schubert if (TYPE_CODE (type) == TYPE_CODE_PTR)
42185796c8dcSSimon Schubert return value_addr (descriptor);
42195796c8dcSSimon Schubert else
42205796c8dcSSimon Schubert return descriptor;
42215796c8dcSSimon Schubert }
42225796c8dcSSimon Schubert
42235796c8dcSSimon Schubert /* Dummy definitions for an experimental caching module that is not
42245796c8dcSSimon Schubert * used in the public sources. */
42255796c8dcSSimon Schubert
42265796c8dcSSimon Schubert static int
lookup_cached_symbol(const char * name,domain_enum namespace,struct symbol ** sym,struct block ** block)42275796c8dcSSimon Schubert lookup_cached_symbol (const char *name, domain_enum namespace,
42285796c8dcSSimon Schubert struct symbol **sym, struct block **block)
42295796c8dcSSimon Schubert {
42305796c8dcSSimon Schubert return 0;
42315796c8dcSSimon Schubert }
42325796c8dcSSimon Schubert
42335796c8dcSSimon Schubert static void
cache_symbol(const char * name,domain_enum namespace,struct symbol * sym,const struct block * block)42345796c8dcSSimon Schubert cache_symbol (const char *name, domain_enum namespace, struct symbol *sym,
4235*ef5ccd6cSJohn Marino const struct block *block)
42365796c8dcSSimon Schubert {
42375796c8dcSSimon Schubert }
42385796c8dcSSimon Schubert
42395796c8dcSSimon Schubert /* Symbol Lookup */
42405796c8dcSSimon Schubert
4241*ef5ccd6cSJohn Marino /* Return nonzero if wild matching should be used when searching for
4242*ef5ccd6cSJohn Marino all symbols matching LOOKUP_NAME.
4243*ef5ccd6cSJohn Marino
4244*ef5ccd6cSJohn Marino LOOKUP_NAME is expected to be a symbol name after transformation
4245*ef5ccd6cSJohn Marino for Ada lookups (see ada_name_for_lookup). */
4246*ef5ccd6cSJohn Marino
4247*ef5ccd6cSJohn Marino static int
should_use_wild_match(const char * lookup_name)4248*ef5ccd6cSJohn Marino should_use_wild_match (const char *lookup_name)
4249*ef5ccd6cSJohn Marino {
4250*ef5ccd6cSJohn Marino return (strstr (lookup_name, "__") == NULL);
4251*ef5ccd6cSJohn Marino }
4252*ef5ccd6cSJohn Marino
42535796c8dcSSimon Schubert /* Return the result of a standard (literal, C-like) lookup of NAME in
42545796c8dcSSimon Schubert given DOMAIN, visible from lexical block BLOCK. */
42555796c8dcSSimon Schubert
42565796c8dcSSimon Schubert static struct symbol *
standard_lookup(const char * name,const struct block * block,domain_enum domain)42575796c8dcSSimon Schubert standard_lookup (const char *name, const struct block *block,
42585796c8dcSSimon Schubert domain_enum domain)
42595796c8dcSSimon Schubert {
4260*ef5ccd6cSJohn Marino /* Initialize it just to avoid a GCC false warning. */
4261*ef5ccd6cSJohn Marino struct symbol *sym = NULL;
42625796c8dcSSimon Schubert
42635796c8dcSSimon Schubert if (lookup_cached_symbol (name, domain, &sym, NULL))
42645796c8dcSSimon Schubert return sym;
42655796c8dcSSimon Schubert sym = lookup_symbol_in_language (name, block, domain, language_c, 0);
42665796c8dcSSimon Schubert cache_symbol (name, domain, sym, block_found);
42675796c8dcSSimon Schubert return sym;
42685796c8dcSSimon Schubert }
42695796c8dcSSimon Schubert
42705796c8dcSSimon Schubert
42715796c8dcSSimon Schubert /* Non-zero iff there is at least one non-function/non-enumeral symbol
42725796c8dcSSimon Schubert in the symbol fields of SYMS[0..N-1]. We treat enumerals as functions,
42735796c8dcSSimon Schubert since they contend in overloading in the same way. */
42745796c8dcSSimon Schubert static int
is_nonfunction(struct ada_symbol_info syms[],int n)42755796c8dcSSimon Schubert is_nonfunction (struct ada_symbol_info syms[], int n)
42765796c8dcSSimon Schubert {
42775796c8dcSSimon Schubert int i;
42785796c8dcSSimon Schubert
42795796c8dcSSimon Schubert for (i = 0; i < n; i += 1)
42805796c8dcSSimon Schubert if (TYPE_CODE (SYMBOL_TYPE (syms[i].sym)) != TYPE_CODE_FUNC
42815796c8dcSSimon Schubert && (TYPE_CODE (SYMBOL_TYPE (syms[i].sym)) != TYPE_CODE_ENUM
42825796c8dcSSimon Schubert || SYMBOL_CLASS (syms[i].sym) != LOC_CONST))
42835796c8dcSSimon Schubert return 1;
42845796c8dcSSimon Schubert
42855796c8dcSSimon Schubert return 0;
42865796c8dcSSimon Schubert }
42875796c8dcSSimon Schubert
42885796c8dcSSimon Schubert /* If true (non-zero), then TYPE0 and TYPE1 represent equivalent
42895796c8dcSSimon Schubert struct types. Otherwise, they may not. */
42905796c8dcSSimon Schubert
42915796c8dcSSimon Schubert static int
equiv_types(struct type * type0,struct type * type1)42925796c8dcSSimon Schubert equiv_types (struct type *type0, struct type *type1)
42935796c8dcSSimon Schubert {
42945796c8dcSSimon Schubert if (type0 == type1)
42955796c8dcSSimon Schubert return 1;
42965796c8dcSSimon Schubert if (type0 == NULL || type1 == NULL
42975796c8dcSSimon Schubert || TYPE_CODE (type0) != TYPE_CODE (type1))
42985796c8dcSSimon Schubert return 0;
42995796c8dcSSimon Schubert if ((TYPE_CODE (type0) == TYPE_CODE_STRUCT
43005796c8dcSSimon Schubert || TYPE_CODE (type0) == TYPE_CODE_ENUM)
43015796c8dcSSimon Schubert && ada_type_name (type0) != NULL && ada_type_name (type1) != NULL
43025796c8dcSSimon Schubert && strcmp (ada_type_name (type0), ada_type_name (type1)) == 0)
43035796c8dcSSimon Schubert return 1;
43045796c8dcSSimon Schubert
43055796c8dcSSimon Schubert return 0;
43065796c8dcSSimon Schubert }
43075796c8dcSSimon Schubert
43085796c8dcSSimon Schubert /* True iff SYM0 represents the same entity as SYM1, or one that is
43095796c8dcSSimon Schubert no more defined than that of SYM1. */
43105796c8dcSSimon Schubert
43115796c8dcSSimon Schubert static int
lesseq_defined_than(struct symbol * sym0,struct symbol * sym1)43125796c8dcSSimon Schubert lesseq_defined_than (struct symbol *sym0, struct symbol *sym1)
43135796c8dcSSimon Schubert {
43145796c8dcSSimon Schubert if (sym0 == sym1)
43155796c8dcSSimon Schubert return 1;
43165796c8dcSSimon Schubert if (SYMBOL_DOMAIN (sym0) != SYMBOL_DOMAIN (sym1)
43175796c8dcSSimon Schubert || SYMBOL_CLASS (sym0) != SYMBOL_CLASS (sym1))
43185796c8dcSSimon Schubert return 0;
43195796c8dcSSimon Schubert
43205796c8dcSSimon Schubert switch (SYMBOL_CLASS (sym0))
43215796c8dcSSimon Schubert {
43225796c8dcSSimon Schubert case LOC_UNDEF:
43235796c8dcSSimon Schubert return 1;
43245796c8dcSSimon Schubert case LOC_TYPEDEF:
43255796c8dcSSimon Schubert {
43265796c8dcSSimon Schubert struct type *type0 = SYMBOL_TYPE (sym0);
43275796c8dcSSimon Schubert struct type *type1 = SYMBOL_TYPE (sym1);
4328*ef5ccd6cSJohn Marino const char *name0 = SYMBOL_LINKAGE_NAME (sym0);
4329*ef5ccd6cSJohn Marino const char *name1 = SYMBOL_LINKAGE_NAME (sym1);
43305796c8dcSSimon Schubert int len0 = strlen (name0);
4331cf7f2e2dSJohn Marino
43325796c8dcSSimon Schubert return
43335796c8dcSSimon Schubert TYPE_CODE (type0) == TYPE_CODE (type1)
43345796c8dcSSimon Schubert && (equiv_types (type0, type1)
43355796c8dcSSimon Schubert || (len0 < strlen (name1) && strncmp (name0, name1, len0) == 0
43365796c8dcSSimon Schubert && strncmp (name1 + len0, "___XV", 5) == 0));
43375796c8dcSSimon Schubert }
43385796c8dcSSimon Schubert case LOC_CONST:
43395796c8dcSSimon Schubert return SYMBOL_VALUE (sym0) == SYMBOL_VALUE (sym1)
43405796c8dcSSimon Schubert && equiv_types (SYMBOL_TYPE (sym0), SYMBOL_TYPE (sym1));
43415796c8dcSSimon Schubert default:
43425796c8dcSSimon Schubert return 0;
43435796c8dcSSimon Schubert }
43445796c8dcSSimon Schubert }
43455796c8dcSSimon Schubert
43465796c8dcSSimon Schubert /* Append (SYM,BLOCK,SYMTAB) to the end of the array of struct ada_symbol_info
43475796c8dcSSimon Schubert records in OBSTACKP. Do nothing if SYM is a duplicate. */
43485796c8dcSSimon Schubert
43495796c8dcSSimon Schubert static void
add_defn_to_vec(struct obstack * obstackp,struct symbol * sym,struct block * block)43505796c8dcSSimon Schubert add_defn_to_vec (struct obstack *obstackp,
43515796c8dcSSimon Schubert struct symbol *sym,
43525796c8dcSSimon Schubert struct block *block)
43535796c8dcSSimon Schubert {
43545796c8dcSSimon Schubert int i;
43555796c8dcSSimon Schubert struct ada_symbol_info *prevDefns = defns_collected (obstackp, 0);
43565796c8dcSSimon Schubert
43575796c8dcSSimon Schubert /* Do not try to complete stub types, as the debugger is probably
43585796c8dcSSimon Schubert already scanning all symbols matching a certain name at the
43595796c8dcSSimon Schubert time when this function is called. Trying to replace the stub
43605796c8dcSSimon Schubert type by its associated full type will cause us to restart a scan
43615796c8dcSSimon Schubert which may lead to an infinite recursion. Instead, the client
43625796c8dcSSimon Schubert collecting the matching symbols will end up collecting several
43635796c8dcSSimon Schubert matches, with at least one of them complete. It can then filter
43645796c8dcSSimon Schubert out the stub ones if needed. */
43655796c8dcSSimon Schubert
43665796c8dcSSimon Schubert for (i = num_defns_collected (obstackp) - 1; i >= 0; i -= 1)
43675796c8dcSSimon Schubert {
43685796c8dcSSimon Schubert if (lesseq_defined_than (sym, prevDefns[i].sym))
43695796c8dcSSimon Schubert return;
43705796c8dcSSimon Schubert else if (lesseq_defined_than (prevDefns[i].sym, sym))
43715796c8dcSSimon Schubert {
43725796c8dcSSimon Schubert prevDefns[i].sym = sym;
43735796c8dcSSimon Schubert prevDefns[i].block = block;
43745796c8dcSSimon Schubert return;
43755796c8dcSSimon Schubert }
43765796c8dcSSimon Schubert }
43775796c8dcSSimon Schubert
43785796c8dcSSimon Schubert {
43795796c8dcSSimon Schubert struct ada_symbol_info info;
43805796c8dcSSimon Schubert
43815796c8dcSSimon Schubert info.sym = sym;
43825796c8dcSSimon Schubert info.block = block;
43835796c8dcSSimon Schubert obstack_grow (obstackp, &info, sizeof (struct ada_symbol_info));
43845796c8dcSSimon Schubert }
43855796c8dcSSimon Schubert }
43865796c8dcSSimon Schubert
43875796c8dcSSimon Schubert /* Number of ada_symbol_info structures currently collected in
43885796c8dcSSimon Schubert current vector in *OBSTACKP. */
43895796c8dcSSimon Schubert
43905796c8dcSSimon Schubert static int
num_defns_collected(struct obstack * obstackp)43915796c8dcSSimon Schubert num_defns_collected (struct obstack *obstackp)
43925796c8dcSSimon Schubert {
43935796c8dcSSimon Schubert return obstack_object_size (obstackp) / sizeof (struct ada_symbol_info);
43945796c8dcSSimon Schubert }
43955796c8dcSSimon Schubert
43965796c8dcSSimon Schubert /* Vector of ada_symbol_info structures currently collected in current
43975796c8dcSSimon Schubert vector in *OBSTACKP. If FINISH, close off the vector and return
43985796c8dcSSimon Schubert its final address. */
43995796c8dcSSimon Schubert
44005796c8dcSSimon Schubert static struct ada_symbol_info *
defns_collected(struct obstack * obstackp,int finish)44015796c8dcSSimon Schubert defns_collected (struct obstack *obstackp, int finish)
44025796c8dcSSimon Schubert {
44035796c8dcSSimon Schubert if (finish)
44045796c8dcSSimon Schubert return obstack_finish (obstackp);
44055796c8dcSSimon Schubert else
44065796c8dcSSimon Schubert return (struct ada_symbol_info *) obstack_base (obstackp);
44075796c8dcSSimon Schubert }
44085796c8dcSSimon Schubert
44095796c8dcSSimon Schubert /* Return a minimal symbol matching NAME according to Ada decoding
44105796c8dcSSimon Schubert rules. Returns NULL if there is no such minimal symbol. Names
44115796c8dcSSimon Schubert prefixed with "standard__" are handled specially: "standard__" is
44125796c8dcSSimon Schubert first stripped off, and only static and global symbols are searched. */
44135796c8dcSSimon Schubert
44145796c8dcSSimon Schubert struct minimal_symbol *
ada_lookup_simple_minsym(const char * name)44155796c8dcSSimon Schubert ada_lookup_simple_minsym (const char *name)
44165796c8dcSSimon Schubert {
44175796c8dcSSimon Schubert struct objfile *objfile;
44185796c8dcSSimon Schubert struct minimal_symbol *msymbol;
4419*ef5ccd6cSJohn Marino const int wild_match_p = should_use_wild_match (name);
44205796c8dcSSimon Schubert
4421*ef5ccd6cSJohn Marino /* Special case: If the user specifies a symbol name inside package
4422*ef5ccd6cSJohn Marino Standard, do a non-wild matching of the symbol name without
4423*ef5ccd6cSJohn Marino the "standard__" prefix. This was primarily introduced in order
4424*ef5ccd6cSJohn Marino to allow the user to specifically access the standard exceptions
4425*ef5ccd6cSJohn Marino using, for instance, Standard.Constraint_Error when Constraint_Error
4426*ef5ccd6cSJohn Marino is ambiguous (due to the user defining its own Constraint_Error
4427*ef5ccd6cSJohn Marino entity inside its program). */
44285796c8dcSSimon Schubert if (strncmp (name, "standard__", sizeof ("standard__") - 1) == 0)
44295796c8dcSSimon Schubert name += sizeof ("standard__") - 1;
44305796c8dcSSimon Schubert
44315796c8dcSSimon Schubert ALL_MSYMBOLS (objfile, msymbol)
44325796c8dcSSimon Schubert {
4433*ef5ccd6cSJohn Marino if (match_name (SYMBOL_LINKAGE_NAME (msymbol), name, wild_match_p)
44345796c8dcSSimon Schubert && MSYMBOL_TYPE (msymbol) != mst_solib_trampoline)
44355796c8dcSSimon Schubert return msymbol;
44365796c8dcSSimon Schubert }
44375796c8dcSSimon Schubert
44385796c8dcSSimon Schubert return NULL;
44395796c8dcSSimon Schubert }
44405796c8dcSSimon Schubert
44415796c8dcSSimon Schubert /* For all subprograms that statically enclose the subprogram of the
44425796c8dcSSimon Schubert selected frame, add symbols matching identifier NAME in DOMAIN
44435796c8dcSSimon Schubert and their blocks to the list of data in OBSTACKP, as for
4444*ef5ccd6cSJohn Marino ada_add_block_symbols (q.v.). If WILD_MATCH_P, treat as NAME
4445*ef5ccd6cSJohn Marino with a wildcard prefix. */
44465796c8dcSSimon Schubert
44475796c8dcSSimon Schubert static void
add_symbols_from_enclosing_procs(struct obstack * obstackp,const char * name,domain_enum namespace,int wild_match_p)44485796c8dcSSimon Schubert add_symbols_from_enclosing_procs (struct obstack *obstackp,
44495796c8dcSSimon Schubert const char *name, domain_enum namespace,
4450*ef5ccd6cSJohn Marino int wild_match_p)
44515796c8dcSSimon Schubert {
44525796c8dcSSimon Schubert }
44535796c8dcSSimon Schubert
44545796c8dcSSimon Schubert /* True if TYPE is definitely an artificial type supplied to a symbol
44555796c8dcSSimon Schubert for which no debugging information was given in the symbol file. */
44565796c8dcSSimon Schubert
44575796c8dcSSimon Schubert static int
is_nondebugging_type(struct type * type)44585796c8dcSSimon Schubert is_nondebugging_type (struct type *type)
44595796c8dcSSimon Schubert {
4460*ef5ccd6cSJohn Marino const char *name = ada_type_name (type);
4461cf7f2e2dSJohn Marino
44625796c8dcSSimon Schubert return (name != NULL && strcmp (name, "<variable, no debug info>") == 0);
44635796c8dcSSimon Schubert }
44645796c8dcSSimon Schubert
4465a45ae5f8SJohn Marino /* Return nonzero if TYPE1 and TYPE2 are two enumeration types
4466a45ae5f8SJohn Marino that are deemed "identical" for practical purposes.
4467a45ae5f8SJohn Marino
4468a45ae5f8SJohn Marino This function assumes that TYPE1 and TYPE2 are both TYPE_CODE_ENUM
4469a45ae5f8SJohn Marino types and that their number of enumerals is identical (in other
4470a45ae5f8SJohn Marino words, TYPE_NFIELDS (type1) == TYPE_NFIELDS (type2)). */
4471a45ae5f8SJohn Marino
4472a45ae5f8SJohn Marino static int
ada_identical_enum_types_p(struct type * type1,struct type * type2)4473a45ae5f8SJohn Marino ada_identical_enum_types_p (struct type *type1, struct type *type2)
4474a45ae5f8SJohn Marino {
4475a45ae5f8SJohn Marino int i;
4476a45ae5f8SJohn Marino
4477a45ae5f8SJohn Marino /* The heuristic we use here is fairly conservative. We consider
4478a45ae5f8SJohn Marino that 2 enumerate types are identical if they have the same
4479a45ae5f8SJohn Marino number of enumerals and that all enumerals have the same
4480a45ae5f8SJohn Marino underlying value and name. */
4481a45ae5f8SJohn Marino
4482a45ae5f8SJohn Marino /* All enums in the type should have an identical underlying value. */
4483a45ae5f8SJohn Marino for (i = 0; i < TYPE_NFIELDS (type1); i++)
4484*ef5ccd6cSJohn Marino if (TYPE_FIELD_ENUMVAL (type1, i) != TYPE_FIELD_ENUMVAL (type2, i))
4485a45ae5f8SJohn Marino return 0;
4486a45ae5f8SJohn Marino
4487a45ae5f8SJohn Marino /* All enumerals should also have the same name (modulo any numerical
4488a45ae5f8SJohn Marino suffix). */
4489a45ae5f8SJohn Marino for (i = 0; i < TYPE_NFIELDS (type1); i++)
4490a45ae5f8SJohn Marino {
4491*ef5ccd6cSJohn Marino const char *name_1 = TYPE_FIELD_NAME (type1, i);
4492*ef5ccd6cSJohn Marino const char *name_2 = TYPE_FIELD_NAME (type2, i);
4493a45ae5f8SJohn Marino int len_1 = strlen (name_1);
4494a45ae5f8SJohn Marino int len_2 = strlen (name_2);
4495a45ae5f8SJohn Marino
4496a45ae5f8SJohn Marino ada_remove_trailing_digits (TYPE_FIELD_NAME (type1, i), &len_1);
4497a45ae5f8SJohn Marino ada_remove_trailing_digits (TYPE_FIELD_NAME (type2, i), &len_2);
4498a45ae5f8SJohn Marino if (len_1 != len_2
4499a45ae5f8SJohn Marino || strncmp (TYPE_FIELD_NAME (type1, i),
4500a45ae5f8SJohn Marino TYPE_FIELD_NAME (type2, i),
4501a45ae5f8SJohn Marino len_1) != 0)
4502a45ae5f8SJohn Marino return 0;
4503a45ae5f8SJohn Marino }
4504a45ae5f8SJohn Marino
4505a45ae5f8SJohn Marino return 1;
4506a45ae5f8SJohn Marino }
4507a45ae5f8SJohn Marino
4508a45ae5f8SJohn Marino /* Return nonzero if all the symbols in SYMS are all enumeral symbols
4509a45ae5f8SJohn Marino that are deemed "identical" for practical purposes. Sometimes,
4510a45ae5f8SJohn Marino enumerals are not strictly identical, but their types are so similar
4511a45ae5f8SJohn Marino that they can be considered identical.
4512a45ae5f8SJohn Marino
4513a45ae5f8SJohn Marino For instance, consider the following code:
4514a45ae5f8SJohn Marino
4515a45ae5f8SJohn Marino type Color is (Black, Red, Green, Blue, White);
4516a45ae5f8SJohn Marino type RGB_Color is new Color range Red .. Blue;
4517a45ae5f8SJohn Marino
4518a45ae5f8SJohn Marino Type RGB_Color is a subrange of an implicit type which is a copy
4519a45ae5f8SJohn Marino of type Color. If we call that implicit type RGB_ColorB ("B" is
4520a45ae5f8SJohn Marino for "Base Type"), then type RGB_ColorB is a copy of type Color.
4521a45ae5f8SJohn Marino As a result, when an expression references any of the enumeral
4522a45ae5f8SJohn Marino by name (Eg. "print green"), the expression is technically
4523a45ae5f8SJohn Marino ambiguous and the user should be asked to disambiguate. But
4524a45ae5f8SJohn Marino doing so would only hinder the user, since it wouldn't matter
4525a45ae5f8SJohn Marino what choice he makes, the outcome would always be the same.
4526a45ae5f8SJohn Marino So, for practical purposes, we consider them as the same. */
4527a45ae5f8SJohn Marino
4528a45ae5f8SJohn Marino static int
symbols_are_identical_enums(struct ada_symbol_info * syms,int nsyms)4529a45ae5f8SJohn Marino symbols_are_identical_enums (struct ada_symbol_info *syms, int nsyms)
4530a45ae5f8SJohn Marino {
4531a45ae5f8SJohn Marino int i;
4532a45ae5f8SJohn Marino
4533a45ae5f8SJohn Marino /* Before performing a thorough comparison check of each type,
4534a45ae5f8SJohn Marino we perform a series of inexpensive checks. We expect that these
4535a45ae5f8SJohn Marino checks will quickly fail in the vast majority of cases, and thus
4536a45ae5f8SJohn Marino help prevent the unnecessary use of a more expensive comparison.
4537a45ae5f8SJohn Marino Said comparison also expects us to make some of these checks
4538a45ae5f8SJohn Marino (see ada_identical_enum_types_p). */
4539a45ae5f8SJohn Marino
4540a45ae5f8SJohn Marino /* Quick check: All symbols should have an enum type. */
4541a45ae5f8SJohn Marino for (i = 0; i < nsyms; i++)
4542a45ae5f8SJohn Marino if (TYPE_CODE (SYMBOL_TYPE (syms[i].sym)) != TYPE_CODE_ENUM)
4543a45ae5f8SJohn Marino return 0;
4544a45ae5f8SJohn Marino
4545a45ae5f8SJohn Marino /* Quick check: They should all have the same value. */
4546a45ae5f8SJohn Marino for (i = 1; i < nsyms; i++)
4547a45ae5f8SJohn Marino if (SYMBOL_VALUE (syms[i].sym) != SYMBOL_VALUE (syms[0].sym))
4548a45ae5f8SJohn Marino return 0;
4549a45ae5f8SJohn Marino
4550a45ae5f8SJohn Marino /* Quick check: They should all have the same number of enumerals. */
4551a45ae5f8SJohn Marino for (i = 1; i < nsyms; i++)
4552a45ae5f8SJohn Marino if (TYPE_NFIELDS (SYMBOL_TYPE (syms[i].sym))
4553a45ae5f8SJohn Marino != TYPE_NFIELDS (SYMBOL_TYPE (syms[0].sym)))
4554a45ae5f8SJohn Marino return 0;
4555a45ae5f8SJohn Marino
4556a45ae5f8SJohn Marino /* All the sanity checks passed, so we might have a set of
4557a45ae5f8SJohn Marino identical enumeration types. Perform a more complete
4558a45ae5f8SJohn Marino comparison of the type of each symbol. */
4559a45ae5f8SJohn Marino for (i = 1; i < nsyms; i++)
4560a45ae5f8SJohn Marino if (!ada_identical_enum_types_p (SYMBOL_TYPE (syms[i].sym),
4561a45ae5f8SJohn Marino SYMBOL_TYPE (syms[0].sym)))
4562a45ae5f8SJohn Marino return 0;
4563a45ae5f8SJohn Marino
4564a45ae5f8SJohn Marino return 1;
4565a45ae5f8SJohn Marino }
4566a45ae5f8SJohn Marino
45675796c8dcSSimon Schubert /* Remove any non-debugging symbols in SYMS[0 .. NSYMS-1] that definitely
45685796c8dcSSimon Schubert duplicate other symbols in the list (The only case I know of where
45695796c8dcSSimon Schubert this happens is when object files containing stabs-in-ecoff are
45705796c8dcSSimon Schubert linked with files containing ordinary ecoff debugging symbols (or no
45715796c8dcSSimon Schubert debugging symbols)). Modifies SYMS to squeeze out deleted entries.
45725796c8dcSSimon Schubert Returns the number of items in the modified list. */
45735796c8dcSSimon Schubert
45745796c8dcSSimon Schubert static int
remove_extra_symbols(struct ada_symbol_info * syms,int nsyms)45755796c8dcSSimon Schubert remove_extra_symbols (struct ada_symbol_info *syms, int nsyms)
45765796c8dcSSimon Schubert {
45775796c8dcSSimon Schubert int i, j;
45785796c8dcSSimon Schubert
4579a45ae5f8SJohn Marino /* We should never be called with less than 2 symbols, as there
4580a45ae5f8SJohn Marino cannot be any extra symbol in that case. But it's easy to
4581a45ae5f8SJohn Marino handle, since we have nothing to do in that case. */
4582a45ae5f8SJohn Marino if (nsyms < 2)
4583a45ae5f8SJohn Marino return nsyms;
4584a45ae5f8SJohn Marino
45855796c8dcSSimon Schubert i = 0;
45865796c8dcSSimon Schubert while (i < nsyms)
45875796c8dcSSimon Schubert {
4588a45ae5f8SJohn Marino int remove_p = 0;
45895796c8dcSSimon Schubert
45905796c8dcSSimon Schubert /* If two symbols have the same name and one of them is a stub type,
45915796c8dcSSimon Schubert the get rid of the stub. */
45925796c8dcSSimon Schubert
45935796c8dcSSimon Schubert if (TYPE_STUB (SYMBOL_TYPE (syms[i].sym))
45945796c8dcSSimon Schubert && SYMBOL_LINKAGE_NAME (syms[i].sym) != NULL)
45955796c8dcSSimon Schubert {
45965796c8dcSSimon Schubert for (j = 0; j < nsyms; j++)
45975796c8dcSSimon Schubert {
45985796c8dcSSimon Schubert if (j != i
45995796c8dcSSimon Schubert && !TYPE_STUB (SYMBOL_TYPE (syms[j].sym))
46005796c8dcSSimon Schubert && SYMBOL_LINKAGE_NAME (syms[j].sym) != NULL
46015796c8dcSSimon Schubert && strcmp (SYMBOL_LINKAGE_NAME (syms[i].sym),
46025796c8dcSSimon Schubert SYMBOL_LINKAGE_NAME (syms[j].sym)) == 0)
4603a45ae5f8SJohn Marino remove_p = 1;
46045796c8dcSSimon Schubert }
46055796c8dcSSimon Schubert }
46065796c8dcSSimon Schubert
46075796c8dcSSimon Schubert /* Two symbols with the same name, same class and same address
46085796c8dcSSimon Schubert should be identical. */
46095796c8dcSSimon Schubert
46105796c8dcSSimon Schubert else if (SYMBOL_LINKAGE_NAME (syms[i].sym) != NULL
46115796c8dcSSimon Schubert && SYMBOL_CLASS (syms[i].sym) == LOC_STATIC
46125796c8dcSSimon Schubert && is_nondebugging_type (SYMBOL_TYPE (syms[i].sym)))
46135796c8dcSSimon Schubert {
46145796c8dcSSimon Schubert for (j = 0; j < nsyms; j += 1)
46155796c8dcSSimon Schubert {
46165796c8dcSSimon Schubert if (i != j
46175796c8dcSSimon Schubert && SYMBOL_LINKAGE_NAME (syms[j].sym) != NULL
46185796c8dcSSimon Schubert && strcmp (SYMBOL_LINKAGE_NAME (syms[i].sym),
46195796c8dcSSimon Schubert SYMBOL_LINKAGE_NAME (syms[j].sym)) == 0
46205796c8dcSSimon Schubert && SYMBOL_CLASS (syms[i].sym) == SYMBOL_CLASS (syms[j].sym)
46215796c8dcSSimon Schubert && SYMBOL_VALUE_ADDRESS (syms[i].sym)
46225796c8dcSSimon Schubert == SYMBOL_VALUE_ADDRESS (syms[j].sym))
4623a45ae5f8SJohn Marino remove_p = 1;
46245796c8dcSSimon Schubert }
46255796c8dcSSimon Schubert }
46265796c8dcSSimon Schubert
4627a45ae5f8SJohn Marino if (remove_p)
46285796c8dcSSimon Schubert {
46295796c8dcSSimon Schubert for (j = i + 1; j < nsyms; j += 1)
46305796c8dcSSimon Schubert syms[j - 1] = syms[j];
46315796c8dcSSimon Schubert nsyms -= 1;
46325796c8dcSSimon Schubert }
46335796c8dcSSimon Schubert
46345796c8dcSSimon Schubert i += 1;
46355796c8dcSSimon Schubert }
4636a45ae5f8SJohn Marino
4637a45ae5f8SJohn Marino /* If all the remaining symbols are identical enumerals, then
4638a45ae5f8SJohn Marino just keep the first one and discard the rest.
4639a45ae5f8SJohn Marino
4640a45ae5f8SJohn Marino Unlike what we did previously, we do not discard any entry
4641a45ae5f8SJohn Marino unless they are ALL identical. This is because the symbol
4642a45ae5f8SJohn Marino comparison is not a strict comparison, but rather a practical
4643a45ae5f8SJohn Marino comparison. If all symbols are considered identical, then
4644a45ae5f8SJohn Marino we can just go ahead and use the first one and discard the rest.
4645a45ae5f8SJohn Marino But if we cannot reduce the list to a single element, we have
4646a45ae5f8SJohn Marino to ask the user to disambiguate anyways. And if we have to
4647a45ae5f8SJohn Marino present a multiple-choice menu, it's less confusing if the list
4648a45ae5f8SJohn Marino isn't missing some choices that were identical and yet distinct. */
4649a45ae5f8SJohn Marino if (symbols_are_identical_enums (syms, nsyms))
4650a45ae5f8SJohn Marino nsyms = 1;
4651a45ae5f8SJohn Marino
46525796c8dcSSimon Schubert return nsyms;
46535796c8dcSSimon Schubert }
46545796c8dcSSimon Schubert
46555796c8dcSSimon Schubert /* Given a type that corresponds to a renaming entity, use the type name
46565796c8dcSSimon Schubert to extract the scope (package name or function name, fully qualified,
46575796c8dcSSimon Schubert and following the GNAT encoding convention) where this renaming has been
46585796c8dcSSimon Schubert defined. The string returned needs to be deallocated after use. */
46595796c8dcSSimon Schubert
46605796c8dcSSimon Schubert static char *
xget_renaming_scope(struct type * renaming_type)46615796c8dcSSimon Schubert xget_renaming_scope (struct type *renaming_type)
46625796c8dcSSimon Schubert {
46635796c8dcSSimon Schubert /* The renaming types adhere to the following convention:
46645796c8dcSSimon Schubert <scope>__<rename>___<XR extension>.
46655796c8dcSSimon Schubert So, to extract the scope, we search for the "___XR" extension,
46665796c8dcSSimon Schubert and then backtrack until we find the first "__". */
46675796c8dcSSimon Schubert
46685796c8dcSSimon Schubert const char *name = type_name_no_tag (renaming_type);
46695796c8dcSSimon Schubert char *suffix = strstr (name, "___XR");
46705796c8dcSSimon Schubert char *last;
46715796c8dcSSimon Schubert int scope_len;
46725796c8dcSSimon Schubert char *scope;
46735796c8dcSSimon Schubert
46745796c8dcSSimon Schubert /* Now, backtrack a bit until we find the first "__". Start looking
46755796c8dcSSimon Schubert at suffix - 3, as the <rename> part is at least one character long. */
46765796c8dcSSimon Schubert
46775796c8dcSSimon Schubert for (last = suffix - 3; last > name; last--)
46785796c8dcSSimon Schubert if (last[0] == '_' && last[1] == '_')
46795796c8dcSSimon Schubert break;
46805796c8dcSSimon Schubert
46815796c8dcSSimon Schubert /* Make a copy of scope and return it. */
46825796c8dcSSimon Schubert
46835796c8dcSSimon Schubert scope_len = last - name;
46845796c8dcSSimon Schubert scope = (char *) xmalloc ((scope_len + 1) * sizeof (char));
46855796c8dcSSimon Schubert
46865796c8dcSSimon Schubert strncpy (scope, name, scope_len);
46875796c8dcSSimon Schubert scope[scope_len] = '\0';
46885796c8dcSSimon Schubert
46895796c8dcSSimon Schubert return scope;
46905796c8dcSSimon Schubert }
46915796c8dcSSimon Schubert
46925796c8dcSSimon Schubert /* Return nonzero if NAME corresponds to a package name. */
46935796c8dcSSimon Schubert
46945796c8dcSSimon Schubert static int
is_package_name(const char * name)46955796c8dcSSimon Schubert is_package_name (const char *name)
46965796c8dcSSimon Schubert {
46975796c8dcSSimon Schubert /* Here, We take advantage of the fact that no symbols are generated
46985796c8dcSSimon Schubert for packages, while symbols are generated for each function.
46995796c8dcSSimon Schubert So the condition for NAME represent a package becomes equivalent
47005796c8dcSSimon Schubert to NAME not existing in our list of symbols. There is only one
47015796c8dcSSimon Schubert small complication with library-level functions (see below). */
47025796c8dcSSimon Schubert
47035796c8dcSSimon Schubert char *fun_name;
47045796c8dcSSimon Schubert
47055796c8dcSSimon Schubert /* If it is a function that has not been defined at library level,
47065796c8dcSSimon Schubert then we should be able to look it up in the symbols. */
47075796c8dcSSimon Schubert if (standard_lookup (name, NULL, VAR_DOMAIN) != NULL)
47085796c8dcSSimon Schubert return 0;
47095796c8dcSSimon Schubert
47105796c8dcSSimon Schubert /* Library-level function names start with "_ada_". See if function
47115796c8dcSSimon Schubert "_ada_" followed by NAME can be found. */
47125796c8dcSSimon Schubert
47135796c8dcSSimon Schubert /* Do a quick check that NAME does not contain "__", since library-level
47145796c8dcSSimon Schubert functions names cannot contain "__" in them. */
47155796c8dcSSimon Schubert if (strstr (name, "__") != NULL)
47165796c8dcSSimon Schubert return 0;
47175796c8dcSSimon Schubert
47185796c8dcSSimon Schubert fun_name = xstrprintf ("_ada_%s", name);
47195796c8dcSSimon Schubert
47205796c8dcSSimon Schubert return (standard_lookup (fun_name, NULL, VAR_DOMAIN) == NULL);
47215796c8dcSSimon Schubert }
47225796c8dcSSimon Schubert
47235796c8dcSSimon Schubert /* Return nonzero if SYM corresponds to a renaming entity that is
47245796c8dcSSimon Schubert not visible from FUNCTION_NAME. */
47255796c8dcSSimon Schubert
47265796c8dcSSimon Schubert static int
old_renaming_is_invisible(const struct symbol * sym,const char * function_name)4727*ef5ccd6cSJohn Marino old_renaming_is_invisible (const struct symbol *sym, const char *function_name)
47285796c8dcSSimon Schubert {
47295796c8dcSSimon Schubert char *scope;
47305796c8dcSSimon Schubert
47315796c8dcSSimon Schubert if (SYMBOL_CLASS (sym) != LOC_TYPEDEF)
47325796c8dcSSimon Schubert return 0;
47335796c8dcSSimon Schubert
47345796c8dcSSimon Schubert scope = xget_renaming_scope (SYMBOL_TYPE (sym));
47355796c8dcSSimon Schubert
47365796c8dcSSimon Schubert make_cleanup (xfree, scope);
47375796c8dcSSimon Schubert
47385796c8dcSSimon Schubert /* If the rename has been defined in a package, then it is visible. */
47395796c8dcSSimon Schubert if (is_package_name (scope))
47405796c8dcSSimon Schubert return 0;
47415796c8dcSSimon Schubert
47425796c8dcSSimon Schubert /* Check that the rename is in the current function scope by checking
47435796c8dcSSimon Schubert that its name starts with SCOPE. */
47445796c8dcSSimon Schubert
47455796c8dcSSimon Schubert /* If the function name starts with "_ada_", it means that it is
47465796c8dcSSimon Schubert a library-level function. Strip this prefix before doing the
47475796c8dcSSimon Schubert comparison, as the encoding for the renaming does not contain
47485796c8dcSSimon Schubert this prefix. */
47495796c8dcSSimon Schubert if (strncmp (function_name, "_ada_", 5) == 0)
47505796c8dcSSimon Schubert function_name += 5;
47515796c8dcSSimon Schubert
47525796c8dcSSimon Schubert return (strncmp (function_name, scope, strlen (scope)) != 0);
47535796c8dcSSimon Schubert }
47545796c8dcSSimon Schubert
47555796c8dcSSimon Schubert /* Remove entries from SYMS that corresponds to a renaming entity that
47565796c8dcSSimon Schubert is not visible from the function associated with CURRENT_BLOCK or
47575796c8dcSSimon Schubert that is superfluous due to the presence of more specific renaming
47585796c8dcSSimon Schubert information. Places surviving symbols in the initial entries of
47595796c8dcSSimon Schubert SYMS and returns the number of surviving symbols.
47605796c8dcSSimon Schubert
47615796c8dcSSimon Schubert Rationale:
47625796c8dcSSimon Schubert First, in cases where an object renaming is implemented as a
47635796c8dcSSimon Schubert reference variable, GNAT may produce both the actual reference
47645796c8dcSSimon Schubert variable and the renaming encoding. In this case, we discard the
47655796c8dcSSimon Schubert latter.
47665796c8dcSSimon Schubert
47675796c8dcSSimon Schubert Second, GNAT emits a type following a specified encoding for each renaming
47685796c8dcSSimon Schubert entity. Unfortunately, STABS currently does not support the definition
47695796c8dcSSimon Schubert of types that are local to a given lexical block, so all renamings types
47705796c8dcSSimon Schubert are emitted at library level. As a consequence, if an application
47715796c8dcSSimon Schubert contains two renaming entities using the same name, and a user tries to
47725796c8dcSSimon Schubert print the value of one of these entities, the result of the ada symbol
47735796c8dcSSimon Schubert lookup will also contain the wrong renaming type.
47745796c8dcSSimon Schubert
47755796c8dcSSimon Schubert This function partially covers for this limitation by attempting to
47765796c8dcSSimon Schubert remove from the SYMS list renaming symbols that should be visible
47775796c8dcSSimon Schubert from CURRENT_BLOCK. However, there does not seem be a 100% reliable
47785796c8dcSSimon Schubert method with the current information available. The implementation
47795796c8dcSSimon Schubert below has a couple of limitations (FIXME: brobecker-2003-05-12):
47805796c8dcSSimon Schubert
47815796c8dcSSimon Schubert - When the user tries to print a rename in a function while there
47825796c8dcSSimon Schubert is another rename entity defined in a package: Normally, the
47835796c8dcSSimon Schubert rename in the function has precedence over the rename in the
47845796c8dcSSimon Schubert package, so the latter should be removed from the list. This is
47855796c8dcSSimon Schubert currently not the case.
47865796c8dcSSimon Schubert
47875796c8dcSSimon Schubert - This function will incorrectly remove valid renames if
47885796c8dcSSimon Schubert the CURRENT_BLOCK corresponds to a function which symbol name
47895796c8dcSSimon Schubert has been changed by an "Export" pragma. As a consequence,
47905796c8dcSSimon Schubert the user will be unable to print such rename entities. */
47915796c8dcSSimon Schubert
47925796c8dcSSimon Schubert static int
remove_irrelevant_renamings(struct ada_symbol_info * syms,int nsyms,const struct block * current_block)47935796c8dcSSimon Schubert remove_irrelevant_renamings (struct ada_symbol_info *syms,
47945796c8dcSSimon Schubert int nsyms, const struct block *current_block)
47955796c8dcSSimon Schubert {
47965796c8dcSSimon Schubert struct symbol *current_function;
4797*ef5ccd6cSJohn Marino const char *current_function_name;
47985796c8dcSSimon Schubert int i;
47995796c8dcSSimon Schubert int is_new_style_renaming;
48005796c8dcSSimon Schubert
48015796c8dcSSimon Schubert /* If there is both a renaming foo___XR... encoded as a variable and
48025796c8dcSSimon Schubert a simple variable foo in the same block, discard the latter.
48035796c8dcSSimon Schubert First, zero out such symbols, then compress. */
48045796c8dcSSimon Schubert is_new_style_renaming = 0;
48055796c8dcSSimon Schubert for (i = 0; i < nsyms; i += 1)
48065796c8dcSSimon Schubert {
48075796c8dcSSimon Schubert struct symbol *sym = syms[i].sym;
4808*ef5ccd6cSJohn Marino const struct block *block = syms[i].block;
48095796c8dcSSimon Schubert const char *name;
48105796c8dcSSimon Schubert const char *suffix;
48115796c8dcSSimon Schubert
48125796c8dcSSimon Schubert if (sym == NULL || SYMBOL_CLASS (sym) == LOC_TYPEDEF)
48135796c8dcSSimon Schubert continue;
48145796c8dcSSimon Schubert name = SYMBOL_LINKAGE_NAME (sym);
48155796c8dcSSimon Schubert suffix = strstr (name, "___XR");
48165796c8dcSSimon Schubert
48175796c8dcSSimon Schubert if (suffix != NULL)
48185796c8dcSSimon Schubert {
48195796c8dcSSimon Schubert int name_len = suffix - name;
48205796c8dcSSimon Schubert int j;
4821cf7f2e2dSJohn Marino
48225796c8dcSSimon Schubert is_new_style_renaming = 1;
48235796c8dcSSimon Schubert for (j = 0; j < nsyms; j += 1)
48245796c8dcSSimon Schubert if (i != j && syms[j].sym != NULL
48255796c8dcSSimon Schubert && strncmp (name, SYMBOL_LINKAGE_NAME (syms[j].sym),
48265796c8dcSSimon Schubert name_len) == 0
48275796c8dcSSimon Schubert && block == syms[j].block)
48285796c8dcSSimon Schubert syms[j].sym = NULL;
48295796c8dcSSimon Schubert }
48305796c8dcSSimon Schubert }
48315796c8dcSSimon Schubert if (is_new_style_renaming)
48325796c8dcSSimon Schubert {
48335796c8dcSSimon Schubert int j, k;
48345796c8dcSSimon Schubert
48355796c8dcSSimon Schubert for (j = k = 0; j < nsyms; j += 1)
48365796c8dcSSimon Schubert if (syms[j].sym != NULL)
48375796c8dcSSimon Schubert {
48385796c8dcSSimon Schubert syms[k] = syms[j];
48395796c8dcSSimon Schubert k += 1;
48405796c8dcSSimon Schubert }
48415796c8dcSSimon Schubert return k;
48425796c8dcSSimon Schubert }
48435796c8dcSSimon Schubert
48445796c8dcSSimon Schubert /* Extract the function name associated to CURRENT_BLOCK.
48455796c8dcSSimon Schubert Abort if unable to do so. */
48465796c8dcSSimon Schubert
48475796c8dcSSimon Schubert if (current_block == NULL)
48485796c8dcSSimon Schubert return nsyms;
48495796c8dcSSimon Schubert
48505796c8dcSSimon Schubert current_function = block_linkage_function (current_block);
48515796c8dcSSimon Schubert if (current_function == NULL)
48525796c8dcSSimon Schubert return nsyms;
48535796c8dcSSimon Schubert
48545796c8dcSSimon Schubert current_function_name = SYMBOL_LINKAGE_NAME (current_function);
48555796c8dcSSimon Schubert if (current_function_name == NULL)
48565796c8dcSSimon Schubert return nsyms;
48575796c8dcSSimon Schubert
48585796c8dcSSimon Schubert /* Check each of the symbols, and remove it from the list if it is
48595796c8dcSSimon Schubert a type corresponding to a renaming that is out of the scope of
48605796c8dcSSimon Schubert the current block. */
48615796c8dcSSimon Schubert
48625796c8dcSSimon Schubert i = 0;
48635796c8dcSSimon Schubert while (i < nsyms)
48645796c8dcSSimon Schubert {
48655796c8dcSSimon Schubert if (ada_parse_renaming (syms[i].sym, NULL, NULL, NULL)
48665796c8dcSSimon Schubert == ADA_OBJECT_RENAMING
48675796c8dcSSimon Schubert && old_renaming_is_invisible (syms[i].sym, current_function_name))
48685796c8dcSSimon Schubert {
48695796c8dcSSimon Schubert int j;
4870cf7f2e2dSJohn Marino
48715796c8dcSSimon Schubert for (j = i + 1; j < nsyms; j += 1)
48725796c8dcSSimon Schubert syms[j - 1] = syms[j];
48735796c8dcSSimon Schubert nsyms -= 1;
48745796c8dcSSimon Schubert }
48755796c8dcSSimon Schubert else
48765796c8dcSSimon Schubert i += 1;
48775796c8dcSSimon Schubert }
48785796c8dcSSimon Schubert
48795796c8dcSSimon Schubert return nsyms;
48805796c8dcSSimon Schubert }
48815796c8dcSSimon Schubert
48825796c8dcSSimon Schubert /* Add to OBSTACKP all symbols from BLOCK (and its super-blocks)
48835796c8dcSSimon Schubert whose name and domain match NAME and DOMAIN respectively.
48845796c8dcSSimon Schubert If no match was found, then extend the search to "enclosing"
48855796c8dcSSimon Schubert routines (in other words, if we're inside a nested function,
48865796c8dcSSimon Schubert search the symbols defined inside the enclosing functions).
4887*ef5ccd6cSJohn Marino If WILD_MATCH_P is nonzero, perform the naming matching in
4888*ef5ccd6cSJohn Marino "wild" mode (see function "wild_match" for more info).
48895796c8dcSSimon Schubert
48905796c8dcSSimon Schubert Note: This function assumes that OBSTACKP has 0 (zero) element in it. */
48915796c8dcSSimon Schubert
48925796c8dcSSimon Schubert static void
ada_add_local_symbols(struct obstack * obstackp,const char * name,struct block * block,domain_enum domain,int wild_match_p)48935796c8dcSSimon Schubert ada_add_local_symbols (struct obstack *obstackp, const char *name,
48945796c8dcSSimon Schubert struct block *block, domain_enum domain,
4895*ef5ccd6cSJohn Marino int wild_match_p)
48965796c8dcSSimon Schubert {
48975796c8dcSSimon Schubert int block_depth = 0;
48985796c8dcSSimon Schubert
48995796c8dcSSimon Schubert while (block != NULL)
49005796c8dcSSimon Schubert {
49015796c8dcSSimon Schubert block_depth += 1;
4902*ef5ccd6cSJohn Marino ada_add_block_symbols (obstackp, block, name, domain, NULL,
4903*ef5ccd6cSJohn Marino wild_match_p);
49045796c8dcSSimon Schubert
49055796c8dcSSimon Schubert /* If we found a non-function match, assume that's the one. */
49065796c8dcSSimon Schubert if (is_nonfunction (defns_collected (obstackp, 0),
49075796c8dcSSimon Schubert num_defns_collected (obstackp)))
49085796c8dcSSimon Schubert return;
49095796c8dcSSimon Schubert
49105796c8dcSSimon Schubert block = BLOCK_SUPERBLOCK (block);
49115796c8dcSSimon Schubert }
49125796c8dcSSimon Schubert
49135796c8dcSSimon Schubert /* If no luck so far, try to find NAME as a local symbol in some lexically
49145796c8dcSSimon Schubert enclosing subprogram. */
49155796c8dcSSimon Schubert if (num_defns_collected (obstackp) == 0 && block_depth > 2)
4916*ef5ccd6cSJohn Marino add_symbols_from_enclosing_procs (obstackp, name, domain, wild_match_p);
49175796c8dcSSimon Schubert }
49185796c8dcSSimon Schubert
4919cf7f2e2dSJohn Marino /* An object of this type is used as the user_data argument when
4920c50c785cSJohn Marino calling the map_matching_symbols method. */
4921cf7f2e2dSJohn Marino
4922c50c785cSJohn Marino struct match_data
4923cf7f2e2dSJohn Marino {
4924c50c785cSJohn Marino struct objfile *objfile;
4925cf7f2e2dSJohn Marino struct obstack *obstackp;
4926c50c785cSJohn Marino struct symbol *arg_sym;
4927c50c785cSJohn Marino int found_sym;
4928cf7f2e2dSJohn Marino };
4929cf7f2e2dSJohn Marino
4930c50c785cSJohn Marino /* A callback for add_matching_symbols that adds SYM, found in BLOCK,
4931c50c785cSJohn Marino to a list of symbols. DATA0 is a pointer to a struct match_data *
4932c50c785cSJohn Marino containing the obstack that collects the symbol list, the file that SYM
4933c50c785cSJohn Marino must come from, a flag indicating whether a non-argument symbol has
4934c50c785cSJohn Marino been found in the current block, and the last argument symbol
4935c50c785cSJohn Marino passed in SYM within the current block (if any). When SYM is null,
4936c50c785cSJohn Marino marking the end of a block, the argument symbol is added if no
4937c50c785cSJohn Marino other has been found. */
4938cf7f2e2dSJohn Marino
4939c50c785cSJohn Marino static int
aux_add_nonlocal_symbols(struct block * block,struct symbol * sym,void * data0)4940c50c785cSJohn Marino aux_add_nonlocal_symbols (struct block *block, struct symbol *sym, void *data0)
4941cf7f2e2dSJohn Marino {
4942c50c785cSJohn Marino struct match_data *data = (struct match_data *) data0;
4943cf7f2e2dSJohn Marino
4944c50c785cSJohn Marino if (sym == NULL)
4945c50c785cSJohn Marino {
4946c50c785cSJohn Marino if (!data->found_sym && data->arg_sym != NULL)
4947c50c785cSJohn Marino add_defn_to_vec (data->obstackp,
4948c50c785cSJohn Marino fixup_symbol_section (data->arg_sym, data->objfile),
4949c50c785cSJohn Marino block);
4950c50c785cSJohn Marino data->found_sym = 0;
4951c50c785cSJohn Marino data->arg_sym = NULL;
4952c50c785cSJohn Marino }
4953c50c785cSJohn Marino else
4954c50c785cSJohn Marino {
4955c50c785cSJohn Marino if (SYMBOL_CLASS (sym) == LOC_UNRESOLVED)
4956c50c785cSJohn Marino return 0;
4957c50c785cSJohn Marino else if (SYMBOL_IS_ARGUMENT (sym))
4958c50c785cSJohn Marino data->arg_sym = sym;
4959c50c785cSJohn Marino else
4960c50c785cSJohn Marino {
4961c50c785cSJohn Marino data->found_sym = 1;
4962c50c785cSJohn Marino add_defn_to_vec (data->obstackp,
4963c50c785cSJohn Marino fixup_symbol_section (sym, data->objfile),
4964c50c785cSJohn Marino block);
4965c50c785cSJohn Marino }
4966c50c785cSJohn Marino }
4967c50c785cSJohn Marino return 0;
4968c50c785cSJohn Marino }
4969c50c785cSJohn Marino
4970c50c785cSJohn Marino /* Compare STRING1 to STRING2, with results as for strcmp.
4971c50c785cSJohn Marino Compatible with strcmp_iw in that strcmp_iw (STRING1, STRING2) <= 0
4972c50c785cSJohn Marino implies compare_names (STRING1, STRING2) (they may differ as to
4973c50c785cSJohn Marino what symbols compare equal). */
4974c50c785cSJohn Marino
4975c50c785cSJohn Marino static int
compare_names(const char * string1,const char * string2)4976c50c785cSJohn Marino compare_names (const char *string1, const char *string2)
4977c50c785cSJohn Marino {
4978c50c785cSJohn Marino while (*string1 != '\0' && *string2 != '\0')
4979c50c785cSJohn Marino {
4980c50c785cSJohn Marino if (isspace (*string1) || isspace (*string2))
4981c50c785cSJohn Marino return strcmp_iw_ordered (string1, string2);
4982c50c785cSJohn Marino if (*string1 != *string2)
4983c50c785cSJohn Marino break;
4984c50c785cSJohn Marino string1 += 1;
4985c50c785cSJohn Marino string2 += 1;
4986c50c785cSJohn Marino }
4987c50c785cSJohn Marino switch (*string1)
4988c50c785cSJohn Marino {
4989c50c785cSJohn Marino case '(':
4990c50c785cSJohn Marino return strcmp_iw_ordered (string1, string2);
4991c50c785cSJohn Marino case '_':
4992c50c785cSJohn Marino if (*string2 == '\0')
4993c50c785cSJohn Marino {
4994c50c785cSJohn Marino if (is_name_suffix (string1))
4995c50c785cSJohn Marino return 0;
4996c50c785cSJohn Marino else
4997a45ae5f8SJohn Marino return 1;
4998c50c785cSJohn Marino }
4999c50c785cSJohn Marino /* FALLTHROUGH */
5000c50c785cSJohn Marino default:
5001c50c785cSJohn Marino if (*string2 == '(')
5002c50c785cSJohn Marino return strcmp_iw_ordered (string1, string2);
5003c50c785cSJohn Marino else
5004c50c785cSJohn Marino return *string1 - *string2;
5005c50c785cSJohn Marino }
5006cf7f2e2dSJohn Marino }
5007cf7f2e2dSJohn Marino
50085796c8dcSSimon Schubert /* Add to OBSTACKP all non-local symbols whose name and domain match
50095796c8dcSSimon Schubert NAME and DOMAIN respectively. The search is performed on GLOBAL_BLOCK
50105796c8dcSSimon Schubert symbols if GLOBAL is non-zero, or on STATIC_BLOCK symbols otherwise. */
50115796c8dcSSimon Schubert
50125796c8dcSSimon Schubert static void
add_nonlocal_symbols(struct obstack * obstackp,const char * name,domain_enum domain,int global,int is_wild_match)5013c50c785cSJohn Marino add_nonlocal_symbols (struct obstack *obstackp, const char *name,
50145796c8dcSSimon Schubert domain_enum domain, int global,
5015cf7f2e2dSJohn Marino int is_wild_match)
50165796c8dcSSimon Schubert {
50175796c8dcSSimon Schubert struct objfile *objfile;
5018c50c785cSJohn Marino struct match_data data;
50195796c8dcSSimon Schubert
5020*ef5ccd6cSJohn Marino memset (&data, 0, sizeof data);
5021cf7f2e2dSJohn Marino data.obstackp = obstackp;
50225796c8dcSSimon Schubert
5023cf7f2e2dSJohn Marino ALL_OBJFILES (objfile)
5024cf7f2e2dSJohn Marino {
5025c50c785cSJohn Marino data.objfile = objfile;
5026c50c785cSJohn Marino
5027c50c785cSJohn Marino if (is_wild_match)
5028c50c785cSJohn Marino objfile->sf->qf->map_matching_symbols (name, domain, objfile, global,
5029c50c785cSJohn Marino aux_add_nonlocal_symbols, &data,
5030c50c785cSJohn Marino wild_match, NULL);
5031c50c785cSJohn Marino else
5032c50c785cSJohn Marino objfile->sf->qf->map_matching_symbols (name, domain, objfile, global,
5033c50c785cSJohn Marino aux_add_nonlocal_symbols, &data,
5034c50c785cSJohn Marino full_match, compare_names);
5035c50c785cSJohn Marino }
5036c50c785cSJohn Marino
5037c50c785cSJohn Marino if (num_defns_collected (obstackp) == 0 && global && !is_wild_match)
5038c50c785cSJohn Marino {
5039c50c785cSJohn Marino ALL_OBJFILES (objfile)
5040c50c785cSJohn Marino {
5041c50c785cSJohn Marino char *name1 = alloca (strlen (name) + sizeof ("_ada_"));
5042c50c785cSJohn Marino strcpy (name1, "_ada_");
5043c50c785cSJohn Marino strcpy (name1 + sizeof ("_ada_") - 1, name);
5044c50c785cSJohn Marino data.objfile = objfile;
5045c50c785cSJohn Marino objfile->sf->qf->map_matching_symbols (name1, domain,
5046c50c785cSJohn Marino objfile, global,
5047c50c785cSJohn Marino aux_add_nonlocal_symbols,
5048c50c785cSJohn Marino &data,
5049c50c785cSJohn Marino full_match, compare_names);
5050c50c785cSJohn Marino }
50515796c8dcSSimon Schubert }
50525796c8dcSSimon Schubert }
50535796c8dcSSimon Schubert
5054*ef5ccd6cSJohn Marino /* Find symbols in DOMAIN matching NAME0, in BLOCK0 and, if full_search is
5055*ef5ccd6cSJohn Marino non-zero, enclosing scope and in global scopes, returning the number of
5056*ef5ccd6cSJohn Marino matches.
5057*ef5ccd6cSJohn Marino Sets *RESULTS to point to a vector of (SYM,BLOCK) tuples,
50585796c8dcSSimon Schubert indicating the symbols found and the blocks and symbol tables (if
5059*ef5ccd6cSJohn Marino any) in which they were found. This vector is transient---good only to
5060*ef5ccd6cSJohn Marino the next call of ada_lookup_symbol_list.
5061*ef5ccd6cSJohn Marino
5062*ef5ccd6cSJohn Marino When full_search is non-zero, any non-function/non-enumeral
50635796c8dcSSimon Schubert symbol match within the nest of blocks whose innermost member is BLOCK0,
50645796c8dcSSimon Schubert is the one match returned (no other matches in that or
50655796c8dcSSimon Schubert enclosing blocks is returned). If there are any matches in or
5066*ef5ccd6cSJohn Marino surrounding BLOCK0, then these alone are returned.
5067*ef5ccd6cSJohn Marino
50685796c8dcSSimon Schubert Names prefixed with "standard__" are handled specially: "standard__"
50695796c8dcSSimon Schubert is first stripped off, and only static and global symbols are searched. */
50705796c8dcSSimon Schubert
5071*ef5ccd6cSJohn Marino static int
ada_lookup_symbol_list_worker(const char * name0,const struct block * block0,domain_enum namespace,struct ada_symbol_info ** results,int full_search)5072*ef5ccd6cSJohn Marino ada_lookup_symbol_list_worker (const char *name0, const struct block *block0,
50735796c8dcSSimon Schubert domain_enum namespace,
5074*ef5ccd6cSJohn Marino struct ada_symbol_info **results,
5075*ef5ccd6cSJohn Marino int full_search)
50765796c8dcSSimon Schubert {
50775796c8dcSSimon Schubert struct symbol *sym;
50785796c8dcSSimon Schubert struct block *block;
50795796c8dcSSimon Schubert const char *name;
5080*ef5ccd6cSJohn Marino const int wild_match_p = should_use_wild_match (name0);
50815796c8dcSSimon Schubert int cacheIfUnique;
50825796c8dcSSimon Schubert int ndefns;
50835796c8dcSSimon Schubert
50845796c8dcSSimon Schubert obstack_free (&symbol_list_obstack, NULL);
50855796c8dcSSimon Schubert obstack_init (&symbol_list_obstack);
50865796c8dcSSimon Schubert
50875796c8dcSSimon Schubert cacheIfUnique = 0;
50885796c8dcSSimon Schubert
50895796c8dcSSimon Schubert /* Search specified block and its superiors. */
50905796c8dcSSimon Schubert
50915796c8dcSSimon Schubert name = name0;
50925796c8dcSSimon Schubert block = (struct block *) block0; /* FIXME: No cast ought to be
50935796c8dcSSimon Schubert needed, but adding const will
50945796c8dcSSimon Schubert have a cascade effect. */
50955796c8dcSSimon Schubert
50965796c8dcSSimon Schubert /* Special case: If the user specifies a symbol name inside package
50975796c8dcSSimon Schubert Standard, do a non-wild matching of the symbol name without
50985796c8dcSSimon Schubert the "standard__" prefix. This was primarily introduced in order
50995796c8dcSSimon Schubert to allow the user to specifically access the standard exceptions
51005796c8dcSSimon Schubert using, for instance, Standard.Constraint_Error when Constraint_Error
51015796c8dcSSimon Schubert is ambiguous (due to the user defining its own Constraint_Error
51025796c8dcSSimon Schubert entity inside its program). */
51035796c8dcSSimon Schubert if (strncmp (name0, "standard__", sizeof ("standard__") - 1) == 0)
51045796c8dcSSimon Schubert {
51055796c8dcSSimon Schubert block = NULL;
51065796c8dcSSimon Schubert name = name0 + sizeof ("standard__") - 1;
51075796c8dcSSimon Schubert }
51085796c8dcSSimon Schubert
51095796c8dcSSimon Schubert /* Check the non-global symbols. If we have ANY match, then we're done. */
51105796c8dcSSimon Schubert
5111*ef5ccd6cSJohn Marino if (block != NULL)
5112*ef5ccd6cSJohn Marino {
5113*ef5ccd6cSJohn Marino if (full_search)
5114*ef5ccd6cSJohn Marino {
5115*ef5ccd6cSJohn Marino ada_add_local_symbols (&symbol_list_obstack, name, block,
5116*ef5ccd6cSJohn Marino namespace, wild_match_p);
5117*ef5ccd6cSJohn Marino }
5118*ef5ccd6cSJohn Marino else
5119*ef5ccd6cSJohn Marino {
5120*ef5ccd6cSJohn Marino /* In the !full_search case we're are being called by
5121*ef5ccd6cSJohn Marino ada_iterate_over_symbols, and we don't want to search
5122*ef5ccd6cSJohn Marino superblocks. */
5123*ef5ccd6cSJohn Marino ada_add_block_symbols (&symbol_list_obstack, block, name,
5124*ef5ccd6cSJohn Marino namespace, NULL, wild_match_p);
5125*ef5ccd6cSJohn Marino }
5126*ef5ccd6cSJohn Marino if (num_defns_collected (&symbol_list_obstack) > 0 || !full_search)
51275796c8dcSSimon Schubert goto done;
5128*ef5ccd6cSJohn Marino }
51295796c8dcSSimon Schubert
51305796c8dcSSimon Schubert /* No non-global symbols found. Check our cache to see if we have
51315796c8dcSSimon Schubert already performed this search before. If we have, then return
51325796c8dcSSimon Schubert the same result. */
51335796c8dcSSimon Schubert
51345796c8dcSSimon Schubert cacheIfUnique = 1;
51355796c8dcSSimon Schubert if (lookup_cached_symbol (name0, namespace, &sym, &block))
51365796c8dcSSimon Schubert {
51375796c8dcSSimon Schubert if (sym != NULL)
51385796c8dcSSimon Schubert add_defn_to_vec (&symbol_list_obstack, sym, block);
51395796c8dcSSimon Schubert goto done;
51405796c8dcSSimon Schubert }
51415796c8dcSSimon Schubert
51425796c8dcSSimon Schubert /* Search symbols from all global blocks. */
51435796c8dcSSimon Schubert
5144c50c785cSJohn Marino add_nonlocal_symbols (&symbol_list_obstack, name, namespace, 1,
5145*ef5ccd6cSJohn Marino wild_match_p);
51465796c8dcSSimon Schubert
51475796c8dcSSimon Schubert /* Now add symbols from all per-file blocks if we've gotten no hits
51485796c8dcSSimon Schubert (not strictly correct, but perhaps better than an error). */
51495796c8dcSSimon Schubert
51505796c8dcSSimon Schubert if (num_defns_collected (&symbol_list_obstack) == 0)
5151c50c785cSJohn Marino add_nonlocal_symbols (&symbol_list_obstack, name, namespace, 0,
5152*ef5ccd6cSJohn Marino wild_match_p);
51535796c8dcSSimon Schubert
51545796c8dcSSimon Schubert done:
51555796c8dcSSimon Schubert ndefns = num_defns_collected (&symbol_list_obstack);
51565796c8dcSSimon Schubert *results = defns_collected (&symbol_list_obstack, 1);
51575796c8dcSSimon Schubert
51585796c8dcSSimon Schubert ndefns = remove_extra_symbols (*results, ndefns);
51595796c8dcSSimon Schubert
5160*ef5ccd6cSJohn Marino if (ndefns == 0 && full_search)
51615796c8dcSSimon Schubert cache_symbol (name0, namespace, NULL, NULL);
51625796c8dcSSimon Schubert
5163*ef5ccd6cSJohn Marino if (ndefns == 1 && full_search && cacheIfUnique)
51645796c8dcSSimon Schubert cache_symbol (name0, namespace, (*results)[0].sym, (*results)[0].block);
51655796c8dcSSimon Schubert
51665796c8dcSSimon Schubert ndefns = remove_irrelevant_renamings (*results, ndefns, block0);
51675796c8dcSSimon Schubert
51685796c8dcSSimon Schubert return ndefns;
51695796c8dcSSimon Schubert }
51705796c8dcSSimon Schubert
5171*ef5ccd6cSJohn Marino /* Find symbols in DOMAIN matching NAME0, in BLOCK0 and enclosing scope and
5172*ef5ccd6cSJohn Marino in global scopes, returning the number of matches, and setting *RESULTS
5173*ef5ccd6cSJohn Marino to a vector of (SYM,BLOCK) tuples.
5174*ef5ccd6cSJohn Marino See ada_lookup_symbol_list_worker for further details. */
5175*ef5ccd6cSJohn Marino
5176*ef5ccd6cSJohn Marino int
ada_lookup_symbol_list(const char * name0,const struct block * block0,domain_enum domain,struct ada_symbol_info ** results)5177*ef5ccd6cSJohn Marino ada_lookup_symbol_list (const char *name0, const struct block *block0,
5178*ef5ccd6cSJohn Marino domain_enum domain, struct ada_symbol_info **results)
5179*ef5ccd6cSJohn Marino {
5180*ef5ccd6cSJohn Marino return ada_lookup_symbol_list_worker (name0, block0, domain, results, 1);
5181*ef5ccd6cSJohn Marino }
5182*ef5ccd6cSJohn Marino
5183*ef5ccd6cSJohn Marino /* Implementation of the la_iterate_over_symbols method. */
5184*ef5ccd6cSJohn Marino
5185*ef5ccd6cSJohn Marino static void
ada_iterate_over_symbols(const struct block * block,const char * name,domain_enum domain,symbol_found_callback_ftype * callback,void * data)5186*ef5ccd6cSJohn Marino ada_iterate_over_symbols (const struct block *block,
5187*ef5ccd6cSJohn Marino const char *name, domain_enum domain,
5188*ef5ccd6cSJohn Marino symbol_found_callback_ftype *callback,
5189*ef5ccd6cSJohn Marino void *data)
5190*ef5ccd6cSJohn Marino {
5191*ef5ccd6cSJohn Marino int ndefs, i;
5192*ef5ccd6cSJohn Marino struct ada_symbol_info *results;
5193*ef5ccd6cSJohn Marino
5194*ef5ccd6cSJohn Marino ndefs = ada_lookup_symbol_list_worker (name, block, domain, &results, 0);
5195*ef5ccd6cSJohn Marino for (i = 0; i < ndefs; ++i)
5196*ef5ccd6cSJohn Marino {
5197*ef5ccd6cSJohn Marino if (! (*callback) (results[i].sym, data))
5198*ef5ccd6cSJohn Marino break;
5199*ef5ccd6cSJohn Marino }
5200*ef5ccd6cSJohn Marino }
5201*ef5ccd6cSJohn Marino
5202a45ae5f8SJohn Marino /* If NAME is the name of an entity, return a string that should
5203a45ae5f8SJohn Marino be used to look that entity up in Ada units. This string should
5204a45ae5f8SJohn Marino be deallocated after use using xfree.
5205a45ae5f8SJohn Marino
5206a45ae5f8SJohn Marino NAME can have any form that the "break" or "print" commands might
5207a45ae5f8SJohn Marino recognize. In other words, it does not have to be the "natural"
5208a45ae5f8SJohn Marino name, or the "encoded" name. */
5209a45ae5f8SJohn Marino
5210a45ae5f8SJohn Marino char *
ada_name_for_lookup(const char * name)5211a45ae5f8SJohn Marino ada_name_for_lookup (const char *name)
5212a45ae5f8SJohn Marino {
5213a45ae5f8SJohn Marino char *canon;
5214a45ae5f8SJohn Marino int nlen = strlen (name);
5215a45ae5f8SJohn Marino
5216a45ae5f8SJohn Marino if (name[0] == '<' && name[nlen - 1] == '>')
5217a45ae5f8SJohn Marino {
5218a45ae5f8SJohn Marino canon = xmalloc (nlen - 1);
5219a45ae5f8SJohn Marino memcpy (canon, name + 1, nlen - 2);
5220a45ae5f8SJohn Marino canon[nlen - 2] = '\0';
5221a45ae5f8SJohn Marino }
5222a45ae5f8SJohn Marino else
5223a45ae5f8SJohn Marino canon = xstrdup (ada_encode (ada_fold_name (name)));
5224a45ae5f8SJohn Marino return canon;
5225a45ae5f8SJohn Marino }
5226a45ae5f8SJohn Marino
5227*ef5ccd6cSJohn Marino /* The result is as for ada_lookup_symbol_list with FULL_SEARCH set
5228*ef5ccd6cSJohn Marino to 1, but choosing the first symbol found if there are multiple
5229*ef5ccd6cSJohn Marino choices.
5230a45ae5f8SJohn Marino
5231*ef5ccd6cSJohn Marino The result is stored in *INFO, which must be non-NULL.
5232*ef5ccd6cSJohn Marino If no match is found, INFO->SYM is set to NULL. */
5233a45ae5f8SJohn Marino
5234*ef5ccd6cSJohn Marino void
ada_lookup_encoded_symbol(const char * name,const struct block * block,domain_enum namespace,struct ada_symbol_info * info)5235*ef5ccd6cSJohn Marino ada_lookup_encoded_symbol (const char *name, const struct block *block,
5236*ef5ccd6cSJohn Marino domain_enum namespace,
5237*ef5ccd6cSJohn Marino struct ada_symbol_info *info)
52385796c8dcSSimon Schubert {
52395796c8dcSSimon Schubert struct ada_symbol_info *candidates;
52405796c8dcSSimon Schubert int n_candidates;
52415796c8dcSSimon Schubert
5242*ef5ccd6cSJohn Marino gdb_assert (info != NULL);
5243*ef5ccd6cSJohn Marino memset (info, 0, sizeof (struct ada_symbol_info));
52445796c8dcSSimon Schubert
5245*ef5ccd6cSJohn Marino n_candidates = ada_lookup_symbol_list (name, block, namespace, &candidates);
52465796c8dcSSimon Schubert if (n_candidates == 0)
5247*ef5ccd6cSJohn Marino return;
52485796c8dcSSimon Schubert
5249*ef5ccd6cSJohn Marino *info = candidates[0];
5250*ef5ccd6cSJohn Marino info->sym = fixup_symbol_section (info->sym, NULL);
52515796c8dcSSimon Schubert }
52525796c8dcSSimon Schubert
52535796c8dcSSimon Schubert /* Return a symbol in DOMAIN matching NAME, in BLOCK0 and enclosing
52545796c8dcSSimon Schubert scope and in global scopes, or NULL if none. NAME is folded and
52555796c8dcSSimon Schubert encoded first. Otherwise, the result is as for ada_lookup_symbol_list,
52565796c8dcSSimon Schubert choosing the first symbol if there are multiple choices.
5257*ef5ccd6cSJohn Marino If IS_A_FIELD_OF_THIS is not NULL, it is set to zero. */
5258*ef5ccd6cSJohn Marino
52595796c8dcSSimon Schubert struct symbol *
ada_lookup_symbol(const char * name,const struct block * block0,domain_enum namespace,int * is_a_field_of_this)52605796c8dcSSimon Schubert ada_lookup_symbol (const char *name, const struct block *block0,
52615796c8dcSSimon Schubert domain_enum namespace, int *is_a_field_of_this)
52625796c8dcSSimon Schubert {
5263*ef5ccd6cSJohn Marino struct ada_symbol_info info;
5264*ef5ccd6cSJohn Marino
52655796c8dcSSimon Schubert if (is_a_field_of_this != NULL)
52665796c8dcSSimon Schubert *is_a_field_of_this = 0;
52675796c8dcSSimon Schubert
52685796c8dcSSimon Schubert ada_lookup_encoded_symbol (ada_encode (ada_fold_name (name)),
5269*ef5ccd6cSJohn Marino block0, namespace, &info);
5270*ef5ccd6cSJohn Marino return info.sym;
52715796c8dcSSimon Schubert }
52725796c8dcSSimon Schubert
52735796c8dcSSimon Schubert static struct symbol *
ada_lookup_symbol_nonlocal(const char * name,const struct block * block,const domain_enum domain)52745796c8dcSSimon Schubert ada_lookup_symbol_nonlocal (const char *name,
52755796c8dcSSimon Schubert const struct block *block,
52765796c8dcSSimon Schubert const domain_enum domain)
52775796c8dcSSimon Schubert {
5278cf7f2e2dSJohn Marino return ada_lookup_symbol (name, block_static_block (block), domain, NULL);
52795796c8dcSSimon Schubert }
52805796c8dcSSimon Schubert
52815796c8dcSSimon Schubert
52825796c8dcSSimon Schubert /* True iff STR is a possible encoded suffix of a normal Ada name
52835796c8dcSSimon Schubert that is to be ignored for matching purposes. Suffixes of parallel
52845796c8dcSSimon Schubert names (e.g., XVE) are not included here. Currently, the possible suffixes
52855796c8dcSSimon Schubert are given by any of the regular expressions:
52865796c8dcSSimon Schubert
52875796c8dcSSimon Schubert [.$][0-9]+ [nested subprogram suffix, on platforms such as GNU/Linux]
52885796c8dcSSimon Schubert ___[0-9]+ [nested subprogram suffix, on platforms such as HP/UX]
5289*ef5ccd6cSJohn Marino TKB [subprogram suffix for task bodies]
52905796c8dcSSimon Schubert _E[0-9]+[bs]$ [protected object entry suffixes]
52915796c8dcSSimon Schubert (X[nb]*)?((\$|__)[0-9](_?[0-9]+)|___(JM|LJM|X([FDBUP].*|R[^T]?)))?$
52925796c8dcSSimon Schubert
52935796c8dcSSimon Schubert Also, any leading "__[0-9]+" sequence is skipped before the suffix
52945796c8dcSSimon Schubert match is performed. This sequence is used to differentiate homonyms,
52955796c8dcSSimon Schubert is an optional part of a valid name suffix. */
52965796c8dcSSimon Schubert
52975796c8dcSSimon Schubert static int
is_name_suffix(const char * str)52985796c8dcSSimon Schubert is_name_suffix (const char *str)
52995796c8dcSSimon Schubert {
53005796c8dcSSimon Schubert int k;
53015796c8dcSSimon Schubert const char *matching;
53025796c8dcSSimon Schubert const int len = strlen (str);
53035796c8dcSSimon Schubert
53045796c8dcSSimon Schubert /* Skip optional leading __[0-9]+. */
53055796c8dcSSimon Schubert
53065796c8dcSSimon Schubert if (len > 3 && str[0] == '_' && str[1] == '_' && isdigit (str[2]))
53075796c8dcSSimon Schubert {
53085796c8dcSSimon Schubert str += 3;
53095796c8dcSSimon Schubert while (isdigit (str[0]))
53105796c8dcSSimon Schubert str += 1;
53115796c8dcSSimon Schubert }
53125796c8dcSSimon Schubert
53135796c8dcSSimon Schubert /* [.$][0-9]+ */
53145796c8dcSSimon Schubert
53155796c8dcSSimon Schubert if (str[0] == '.' || str[0] == '$')
53165796c8dcSSimon Schubert {
53175796c8dcSSimon Schubert matching = str + 1;
53185796c8dcSSimon Schubert while (isdigit (matching[0]))
53195796c8dcSSimon Schubert matching += 1;
53205796c8dcSSimon Schubert if (matching[0] == '\0')
53215796c8dcSSimon Schubert return 1;
53225796c8dcSSimon Schubert }
53235796c8dcSSimon Schubert
53245796c8dcSSimon Schubert /* ___[0-9]+ */
53255796c8dcSSimon Schubert
53265796c8dcSSimon Schubert if (len > 3 && str[0] == '_' && str[1] == '_' && str[2] == '_')
53275796c8dcSSimon Schubert {
53285796c8dcSSimon Schubert matching = str + 3;
53295796c8dcSSimon Schubert while (isdigit (matching[0]))
53305796c8dcSSimon Schubert matching += 1;
53315796c8dcSSimon Schubert if (matching[0] == '\0')
53325796c8dcSSimon Schubert return 1;
53335796c8dcSSimon Schubert }
53345796c8dcSSimon Schubert
5335*ef5ccd6cSJohn Marino /* "TKB" suffixes are used for subprograms implementing task bodies. */
5336*ef5ccd6cSJohn Marino
5337*ef5ccd6cSJohn Marino if (strcmp (str, "TKB") == 0)
5338*ef5ccd6cSJohn Marino return 1;
5339*ef5ccd6cSJohn Marino
53405796c8dcSSimon Schubert #if 0
53415796c8dcSSimon Schubert /* FIXME: brobecker/2005-09-23: Protected Object subprograms end
53425796c8dcSSimon Schubert with a N at the end. Unfortunately, the compiler uses the same
53435796c8dcSSimon Schubert convention for other internal types it creates. So treating
53445796c8dcSSimon Schubert all entity names that end with an "N" as a name suffix causes
53455796c8dcSSimon Schubert some regressions. For instance, consider the case of an enumerated
53465796c8dcSSimon Schubert type. To support the 'Image attribute, it creates an array whose
53475796c8dcSSimon Schubert name ends with N.
53485796c8dcSSimon Schubert Having a single character like this as a suffix carrying some
53495796c8dcSSimon Schubert information is a bit risky. Perhaps we should change the encoding
53505796c8dcSSimon Schubert to be something like "_N" instead. In the meantime, do not do
53515796c8dcSSimon Schubert the following check. */
53525796c8dcSSimon Schubert /* Protected Object Subprograms */
53535796c8dcSSimon Schubert if (len == 1 && str [0] == 'N')
53545796c8dcSSimon Schubert return 1;
53555796c8dcSSimon Schubert #endif
53565796c8dcSSimon Schubert
53575796c8dcSSimon Schubert /* _E[0-9]+[bs]$ */
53585796c8dcSSimon Schubert if (len > 3 && str[0] == '_' && str [1] == 'E' && isdigit (str[2]))
53595796c8dcSSimon Schubert {
53605796c8dcSSimon Schubert matching = str + 3;
53615796c8dcSSimon Schubert while (isdigit (matching[0]))
53625796c8dcSSimon Schubert matching += 1;
53635796c8dcSSimon Schubert if ((matching[0] == 'b' || matching[0] == 's')
53645796c8dcSSimon Schubert && matching [1] == '\0')
53655796c8dcSSimon Schubert return 1;
53665796c8dcSSimon Schubert }
53675796c8dcSSimon Schubert
53685796c8dcSSimon Schubert /* ??? We should not modify STR directly, as we are doing below. This
53695796c8dcSSimon Schubert is fine in this case, but may become problematic later if we find
53705796c8dcSSimon Schubert that this alternative did not work, and want to try matching
53715796c8dcSSimon Schubert another one from the begining of STR. Since we modified it, we
53725796c8dcSSimon Schubert won't be able to find the begining of the string anymore! */
53735796c8dcSSimon Schubert if (str[0] == 'X')
53745796c8dcSSimon Schubert {
53755796c8dcSSimon Schubert str += 1;
53765796c8dcSSimon Schubert while (str[0] != '_' && str[0] != '\0')
53775796c8dcSSimon Schubert {
53785796c8dcSSimon Schubert if (str[0] != 'n' && str[0] != 'b')
53795796c8dcSSimon Schubert return 0;
53805796c8dcSSimon Schubert str += 1;
53815796c8dcSSimon Schubert }
53825796c8dcSSimon Schubert }
53835796c8dcSSimon Schubert
53845796c8dcSSimon Schubert if (str[0] == '\000')
53855796c8dcSSimon Schubert return 1;
53865796c8dcSSimon Schubert
53875796c8dcSSimon Schubert if (str[0] == '_')
53885796c8dcSSimon Schubert {
53895796c8dcSSimon Schubert if (str[1] != '_' || str[2] == '\000')
53905796c8dcSSimon Schubert return 0;
53915796c8dcSSimon Schubert if (str[2] == '_')
53925796c8dcSSimon Schubert {
53935796c8dcSSimon Schubert if (strcmp (str + 3, "JM") == 0)
53945796c8dcSSimon Schubert return 1;
53955796c8dcSSimon Schubert /* FIXME: brobecker/2004-09-30: GNAT will soon stop using
53965796c8dcSSimon Schubert the LJM suffix in favor of the JM one. But we will
53975796c8dcSSimon Schubert still accept LJM as a valid suffix for a reasonable
53985796c8dcSSimon Schubert amount of time, just to allow ourselves to debug programs
53995796c8dcSSimon Schubert compiled using an older version of GNAT. */
54005796c8dcSSimon Schubert if (strcmp (str + 3, "LJM") == 0)
54015796c8dcSSimon Schubert return 1;
54025796c8dcSSimon Schubert if (str[3] != 'X')
54035796c8dcSSimon Schubert return 0;
54045796c8dcSSimon Schubert if (str[4] == 'F' || str[4] == 'D' || str[4] == 'B'
54055796c8dcSSimon Schubert || str[4] == 'U' || str[4] == 'P')
54065796c8dcSSimon Schubert return 1;
54075796c8dcSSimon Schubert if (str[4] == 'R' && str[5] != 'T')
54085796c8dcSSimon Schubert return 1;
54095796c8dcSSimon Schubert return 0;
54105796c8dcSSimon Schubert }
54115796c8dcSSimon Schubert if (!isdigit (str[2]))
54125796c8dcSSimon Schubert return 0;
54135796c8dcSSimon Schubert for (k = 3; str[k] != '\0'; k += 1)
54145796c8dcSSimon Schubert if (!isdigit (str[k]) && str[k] != '_')
54155796c8dcSSimon Schubert return 0;
54165796c8dcSSimon Schubert return 1;
54175796c8dcSSimon Schubert }
54185796c8dcSSimon Schubert if (str[0] == '$' && isdigit (str[1]))
54195796c8dcSSimon Schubert {
54205796c8dcSSimon Schubert for (k = 2; str[k] != '\0'; k += 1)
54215796c8dcSSimon Schubert if (!isdigit (str[k]) && str[k] != '_')
54225796c8dcSSimon Schubert return 0;
54235796c8dcSSimon Schubert return 1;
54245796c8dcSSimon Schubert }
54255796c8dcSSimon Schubert return 0;
54265796c8dcSSimon Schubert }
54275796c8dcSSimon Schubert
54285796c8dcSSimon Schubert /* Return non-zero if the string starting at NAME and ending before
54295796c8dcSSimon Schubert NAME_END contains no capital letters. */
54305796c8dcSSimon Schubert
54315796c8dcSSimon Schubert static int
is_valid_name_for_wild_match(const char * name0)54325796c8dcSSimon Schubert is_valid_name_for_wild_match (const char *name0)
54335796c8dcSSimon Schubert {
54345796c8dcSSimon Schubert const char *decoded_name = ada_decode (name0);
54355796c8dcSSimon Schubert int i;
54365796c8dcSSimon Schubert
54375796c8dcSSimon Schubert /* If the decoded name starts with an angle bracket, it means that
54385796c8dcSSimon Schubert NAME0 does not follow the GNAT encoding format. It should then
54395796c8dcSSimon Schubert not be allowed as a possible wild match. */
54405796c8dcSSimon Schubert if (decoded_name[0] == '<')
54415796c8dcSSimon Schubert return 0;
54425796c8dcSSimon Schubert
54435796c8dcSSimon Schubert for (i=0; decoded_name[i] != '\0'; i++)
54445796c8dcSSimon Schubert if (isalpha (decoded_name[i]) && !islower (decoded_name[i]))
54455796c8dcSSimon Schubert return 0;
54465796c8dcSSimon Schubert
54475796c8dcSSimon Schubert return 1;
54485796c8dcSSimon Schubert }
54495796c8dcSSimon Schubert
5450c50c785cSJohn Marino /* Advance *NAMEP to next occurrence of TARGET0 in the string NAME0
5451c50c785cSJohn Marino that could start a simple name. Assumes that *NAMEP points into
5452c50c785cSJohn Marino the string beginning at NAME0. */
54535796c8dcSSimon Schubert
54545796c8dcSSimon Schubert static int
advance_wild_match(const char ** namep,const char * name0,int target0)5455c50c785cSJohn Marino advance_wild_match (const char **namep, const char *name0, int target0)
54565796c8dcSSimon Schubert {
5457c50c785cSJohn Marino const char *name = *namep;
5458cf7f2e2dSJohn Marino
54595796c8dcSSimon Schubert while (1)
54605796c8dcSSimon Schubert {
5461c50c785cSJohn Marino int t0, t1;
5462c50c785cSJohn Marino
5463c50c785cSJohn Marino t0 = *name;
5464c50c785cSJohn Marino if (t0 == '_')
5465c50c785cSJohn Marino {
5466c50c785cSJohn Marino t1 = name[1];
5467c50c785cSJohn Marino if ((t1 >= 'a' && t1 <= 'z') || (t1 >= '0' && t1 <= '9'))
5468c50c785cSJohn Marino {
5469c50c785cSJohn Marino name += 1;
5470c50c785cSJohn Marino if (name == name0 + 5 && strncmp (name0, "_ada", 4) == 0)
5471c50c785cSJohn Marino break;
5472c50c785cSJohn Marino else
5473c50c785cSJohn Marino name += 1;
5474c50c785cSJohn Marino }
5475c50c785cSJohn Marino else if (t1 == '_' && ((name[2] >= 'a' && name[2] <= 'z')
5476c50c785cSJohn Marino || name[2] == target0))
5477c50c785cSJohn Marino {
5478c50c785cSJohn Marino name += 2;
5479c50c785cSJohn Marino break;
5480c50c785cSJohn Marino }
5481c50c785cSJohn Marino else
54825796c8dcSSimon Schubert return 0;
5483c50c785cSJohn Marino }
5484c50c785cSJohn Marino else if ((t0 >= 'a' && t0 <= 'z') || (t0 >= '0' && t0 <= '9'))
5485c50c785cSJohn Marino name += 1;
5486c50c785cSJohn Marino else
5487c50c785cSJohn Marino return 0;
5488c50c785cSJohn Marino }
5489c50c785cSJohn Marino
5490c50c785cSJohn Marino *namep = name;
5491c50c785cSJohn Marino return 1;
5492c50c785cSJohn Marino }
5493c50c785cSJohn Marino
5494c50c785cSJohn Marino /* Return 0 iff NAME encodes a name of the form prefix.PATN. Ignores any
5495c50c785cSJohn Marino informational suffixes of NAME (i.e., for which is_name_suffix is
5496c50c785cSJohn Marino true). Assumes that PATN is a lower-cased Ada simple name. */
5497c50c785cSJohn Marino
5498c50c785cSJohn Marino static int
wild_match(const char * name,const char * patn)5499c50c785cSJohn Marino wild_match (const char *name, const char *patn)
5500c50c785cSJohn Marino {
5501*ef5ccd6cSJohn Marino const char *p;
5502c50c785cSJohn Marino const char *name0 = name;
5503c50c785cSJohn Marino
5504c50c785cSJohn Marino while (1)
5505c50c785cSJohn Marino {
5506c50c785cSJohn Marino const char *match = name;
5507c50c785cSJohn Marino
5508c50c785cSJohn Marino if (*name == *patn)
5509c50c785cSJohn Marino {
5510c50c785cSJohn Marino for (name += 1, p = patn + 1; *p != '\0'; name += 1, p += 1)
5511c50c785cSJohn Marino if (*p != *name)
5512c50c785cSJohn Marino break;
5513c50c785cSJohn Marino if (*p == '\0' && is_name_suffix (name))
5514c50c785cSJohn Marino return match != name0 && !is_valid_name_for_wild_match (name0);
5515c50c785cSJohn Marino
5516c50c785cSJohn Marino if (name[-1] == '_')
5517c50c785cSJohn Marino name -= 1;
5518c50c785cSJohn Marino }
5519c50c785cSJohn Marino if (!advance_wild_match (&name, name0, *patn))
5520c50c785cSJohn Marino return 1;
55215796c8dcSSimon Schubert }
55225796c8dcSSimon Schubert }
55235796c8dcSSimon Schubert
5524c50c785cSJohn Marino /* Returns 0 iff symbol name SYM_NAME matches SEARCH_NAME, apart from
5525c50c785cSJohn Marino informational suffix. */
5526c50c785cSJohn Marino
5527c50c785cSJohn Marino static int
full_match(const char * sym_name,const char * search_name)5528c50c785cSJohn Marino full_match (const char *sym_name, const char *search_name)
5529c50c785cSJohn Marino {
5530c50c785cSJohn Marino return !match_name (sym_name, search_name, 0);
5531c50c785cSJohn Marino }
5532c50c785cSJohn Marino
5533c50c785cSJohn Marino
55345796c8dcSSimon Schubert /* Add symbols from BLOCK matching identifier NAME in DOMAIN to
55355796c8dcSSimon Schubert vector *defn_symbols, updating the list of symbols in OBSTACKP
55365796c8dcSSimon Schubert (if necessary). If WILD, treat as NAME with a wildcard prefix.
5537*ef5ccd6cSJohn Marino OBJFILE is the section containing BLOCK. */
55385796c8dcSSimon Schubert
55395796c8dcSSimon Schubert static void
ada_add_block_symbols(struct obstack * obstackp,struct block * block,const char * name,domain_enum domain,struct objfile * objfile,int wild)55405796c8dcSSimon Schubert ada_add_block_symbols (struct obstack *obstackp,
55415796c8dcSSimon Schubert struct block *block, const char *name,
55425796c8dcSSimon Schubert domain_enum domain, struct objfile *objfile,
55435796c8dcSSimon Schubert int wild)
55445796c8dcSSimon Schubert {
5545*ef5ccd6cSJohn Marino struct block_iterator iter;
55465796c8dcSSimon Schubert int name_len = strlen (name);
55475796c8dcSSimon Schubert /* A matching argument symbol, if any. */
55485796c8dcSSimon Schubert struct symbol *arg_sym;
55495796c8dcSSimon Schubert /* Set true when we find a matching non-argument symbol. */
55505796c8dcSSimon Schubert int found_sym;
55515796c8dcSSimon Schubert struct symbol *sym;
55525796c8dcSSimon Schubert
55535796c8dcSSimon Schubert arg_sym = NULL;
55545796c8dcSSimon Schubert found_sym = 0;
55555796c8dcSSimon Schubert if (wild)
55565796c8dcSSimon Schubert {
5557*ef5ccd6cSJohn Marino for (sym = block_iter_match_first (block, name, wild_match, &iter);
5558*ef5ccd6cSJohn Marino sym != NULL; sym = block_iter_match_next (name, wild_match, &iter))
55595796c8dcSSimon Schubert {
55605796c8dcSSimon Schubert if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
55615796c8dcSSimon Schubert SYMBOL_DOMAIN (sym), domain)
5562c50c785cSJohn Marino && wild_match (SYMBOL_LINKAGE_NAME (sym), name) == 0)
55635796c8dcSSimon Schubert {
55645796c8dcSSimon Schubert if (SYMBOL_CLASS (sym) == LOC_UNRESOLVED)
55655796c8dcSSimon Schubert continue;
55665796c8dcSSimon Schubert else if (SYMBOL_IS_ARGUMENT (sym))
55675796c8dcSSimon Schubert arg_sym = sym;
55685796c8dcSSimon Schubert else
55695796c8dcSSimon Schubert {
55705796c8dcSSimon Schubert found_sym = 1;
55715796c8dcSSimon Schubert add_defn_to_vec (obstackp,
55725796c8dcSSimon Schubert fixup_symbol_section (sym, objfile),
55735796c8dcSSimon Schubert block);
55745796c8dcSSimon Schubert }
55755796c8dcSSimon Schubert }
55765796c8dcSSimon Schubert }
55775796c8dcSSimon Schubert }
55785796c8dcSSimon Schubert else
55795796c8dcSSimon Schubert {
5580*ef5ccd6cSJohn Marino for (sym = block_iter_match_first (block, name, full_match, &iter);
5581*ef5ccd6cSJohn Marino sym != NULL; sym = block_iter_match_next (name, full_match, &iter))
55825796c8dcSSimon Schubert {
55835796c8dcSSimon Schubert if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
55845796c8dcSSimon Schubert SYMBOL_DOMAIN (sym), domain))
55855796c8dcSSimon Schubert {
55865796c8dcSSimon Schubert if (SYMBOL_CLASS (sym) != LOC_UNRESOLVED)
55875796c8dcSSimon Schubert {
55885796c8dcSSimon Schubert if (SYMBOL_IS_ARGUMENT (sym))
55895796c8dcSSimon Schubert arg_sym = sym;
55905796c8dcSSimon Schubert else
55915796c8dcSSimon Schubert {
55925796c8dcSSimon Schubert found_sym = 1;
55935796c8dcSSimon Schubert add_defn_to_vec (obstackp,
55945796c8dcSSimon Schubert fixup_symbol_section (sym, objfile),
55955796c8dcSSimon Schubert block);
55965796c8dcSSimon Schubert }
55975796c8dcSSimon Schubert }
55985796c8dcSSimon Schubert }
55995796c8dcSSimon Schubert }
56005796c8dcSSimon Schubert }
56015796c8dcSSimon Schubert
56025796c8dcSSimon Schubert if (!found_sym && arg_sym != NULL)
56035796c8dcSSimon Schubert {
56045796c8dcSSimon Schubert add_defn_to_vec (obstackp,
56055796c8dcSSimon Schubert fixup_symbol_section (arg_sym, objfile),
56065796c8dcSSimon Schubert block);
56075796c8dcSSimon Schubert }
56085796c8dcSSimon Schubert
56095796c8dcSSimon Schubert if (!wild)
56105796c8dcSSimon Schubert {
56115796c8dcSSimon Schubert arg_sym = NULL;
56125796c8dcSSimon Schubert found_sym = 0;
56135796c8dcSSimon Schubert
56145796c8dcSSimon Schubert ALL_BLOCK_SYMBOLS (block, iter, sym)
56155796c8dcSSimon Schubert {
56165796c8dcSSimon Schubert if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
56175796c8dcSSimon Schubert SYMBOL_DOMAIN (sym), domain))
56185796c8dcSSimon Schubert {
56195796c8dcSSimon Schubert int cmp;
56205796c8dcSSimon Schubert
56215796c8dcSSimon Schubert cmp = (int) '_' - (int) SYMBOL_LINKAGE_NAME (sym)[0];
56225796c8dcSSimon Schubert if (cmp == 0)
56235796c8dcSSimon Schubert {
56245796c8dcSSimon Schubert cmp = strncmp ("_ada_", SYMBOL_LINKAGE_NAME (sym), 5);
56255796c8dcSSimon Schubert if (cmp == 0)
56265796c8dcSSimon Schubert cmp = strncmp (name, SYMBOL_LINKAGE_NAME (sym) + 5,
56275796c8dcSSimon Schubert name_len);
56285796c8dcSSimon Schubert }
56295796c8dcSSimon Schubert
56305796c8dcSSimon Schubert if (cmp == 0
56315796c8dcSSimon Schubert && is_name_suffix (SYMBOL_LINKAGE_NAME (sym) + name_len + 5))
56325796c8dcSSimon Schubert {
56335796c8dcSSimon Schubert if (SYMBOL_CLASS (sym) != LOC_UNRESOLVED)
56345796c8dcSSimon Schubert {
56355796c8dcSSimon Schubert if (SYMBOL_IS_ARGUMENT (sym))
56365796c8dcSSimon Schubert arg_sym = sym;
56375796c8dcSSimon Schubert else
56385796c8dcSSimon Schubert {
56395796c8dcSSimon Schubert found_sym = 1;
56405796c8dcSSimon Schubert add_defn_to_vec (obstackp,
56415796c8dcSSimon Schubert fixup_symbol_section (sym, objfile),
56425796c8dcSSimon Schubert block);
56435796c8dcSSimon Schubert }
56445796c8dcSSimon Schubert }
56455796c8dcSSimon Schubert }
56465796c8dcSSimon Schubert }
56475796c8dcSSimon Schubert }
56485796c8dcSSimon Schubert
56495796c8dcSSimon Schubert /* NOTE: This really shouldn't be needed for _ada_ symbols.
56505796c8dcSSimon Schubert They aren't parameters, right? */
56515796c8dcSSimon Schubert if (!found_sym && arg_sym != NULL)
56525796c8dcSSimon Schubert {
56535796c8dcSSimon Schubert add_defn_to_vec (obstackp,
56545796c8dcSSimon Schubert fixup_symbol_section (arg_sym, objfile),
56555796c8dcSSimon Schubert block);
56565796c8dcSSimon Schubert }
56575796c8dcSSimon Schubert }
56585796c8dcSSimon Schubert }
56595796c8dcSSimon Schubert
56605796c8dcSSimon Schubert
56615796c8dcSSimon Schubert /* Symbol Completion */
56625796c8dcSSimon Schubert
56635796c8dcSSimon Schubert /* If SYM_NAME is a completion candidate for TEXT, return this symbol
56645796c8dcSSimon Schubert name in a form that's appropriate for the completion. The result
56655796c8dcSSimon Schubert does not need to be deallocated, but is only good until the next call.
56665796c8dcSSimon Schubert
56675796c8dcSSimon Schubert TEXT_LEN is equal to the length of TEXT.
5668*ef5ccd6cSJohn Marino Perform a wild match if WILD_MATCH_P is set.
5669*ef5ccd6cSJohn Marino ENCODED_P should be set if TEXT represents the start of a symbol name
56705796c8dcSSimon Schubert in its encoded form. */
56715796c8dcSSimon Schubert
56725796c8dcSSimon Schubert static const char *
symbol_completion_match(const char * sym_name,const char * text,int text_len,int wild_match_p,int encoded_p)56735796c8dcSSimon Schubert symbol_completion_match (const char *sym_name,
56745796c8dcSSimon Schubert const char *text, int text_len,
5675*ef5ccd6cSJohn Marino int wild_match_p, int encoded_p)
56765796c8dcSSimon Schubert {
56775796c8dcSSimon Schubert const int verbatim_match = (text[0] == '<');
56785796c8dcSSimon Schubert int match = 0;
56795796c8dcSSimon Schubert
56805796c8dcSSimon Schubert if (verbatim_match)
56815796c8dcSSimon Schubert {
56825796c8dcSSimon Schubert /* Strip the leading angle bracket. */
56835796c8dcSSimon Schubert text = text + 1;
56845796c8dcSSimon Schubert text_len--;
56855796c8dcSSimon Schubert }
56865796c8dcSSimon Schubert
56875796c8dcSSimon Schubert /* First, test against the fully qualified name of the symbol. */
56885796c8dcSSimon Schubert
56895796c8dcSSimon Schubert if (strncmp (sym_name, text, text_len) == 0)
56905796c8dcSSimon Schubert match = 1;
56915796c8dcSSimon Schubert
5692*ef5ccd6cSJohn Marino if (match && !encoded_p)
56935796c8dcSSimon Schubert {
56945796c8dcSSimon Schubert /* One needed check before declaring a positive match is to verify
56955796c8dcSSimon Schubert that iff we are doing a verbatim match, the decoded version
56965796c8dcSSimon Schubert of the symbol name starts with '<'. Otherwise, this symbol name
56975796c8dcSSimon Schubert is not a suitable completion. */
56985796c8dcSSimon Schubert const char *sym_name_copy = sym_name;
56995796c8dcSSimon Schubert int has_angle_bracket;
57005796c8dcSSimon Schubert
57015796c8dcSSimon Schubert sym_name = ada_decode (sym_name);
57025796c8dcSSimon Schubert has_angle_bracket = (sym_name[0] == '<');
57035796c8dcSSimon Schubert match = (has_angle_bracket == verbatim_match);
57045796c8dcSSimon Schubert sym_name = sym_name_copy;
57055796c8dcSSimon Schubert }
57065796c8dcSSimon Schubert
57075796c8dcSSimon Schubert if (match && !verbatim_match)
57085796c8dcSSimon Schubert {
57095796c8dcSSimon Schubert /* When doing non-verbatim match, another check that needs to
57105796c8dcSSimon Schubert be done is to verify that the potentially matching symbol name
57115796c8dcSSimon Schubert does not include capital letters, because the ada-mode would
57125796c8dcSSimon Schubert not be able to understand these symbol names without the
57135796c8dcSSimon Schubert angle bracket notation. */
57145796c8dcSSimon Schubert const char *tmp;
57155796c8dcSSimon Schubert
57165796c8dcSSimon Schubert for (tmp = sym_name; *tmp != '\0' && !isupper (*tmp); tmp++);
57175796c8dcSSimon Schubert if (*tmp != '\0')
57185796c8dcSSimon Schubert match = 0;
57195796c8dcSSimon Schubert }
57205796c8dcSSimon Schubert
57215796c8dcSSimon Schubert /* Second: Try wild matching... */
57225796c8dcSSimon Schubert
5723*ef5ccd6cSJohn Marino if (!match && wild_match_p)
57245796c8dcSSimon Schubert {
57255796c8dcSSimon Schubert /* Since we are doing wild matching, this means that TEXT
57265796c8dcSSimon Schubert may represent an unqualified symbol name. We therefore must
57275796c8dcSSimon Schubert also compare TEXT against the unqualified name of the symbol. */
57285796c8dcSSimon Schubert sym_name = ada_unqualified_name (ada_decode (sym_name));
57295796c8dcSSimon Schubert
57305796c8dcSSimon Schubert if (strncmp (sym_name, text, text_len) == 0)
57315796c8dcSSimon Schubert match = 1;
57325796c8dcSSimon Schubert }
57335796c8dcSSimon Schubert
57345796c8dcSSimon Schubert /* Finally: If we found a mach, prepare the result to return. */
57355796c8dcSSimon Schubert
57365796c8dcSSimon Schubert if (!match)
57375796c8dcSSimon Schubert return NULL;
57385796c8dcSSimon Schubert
57395796c8dcSSimon Schubert if (verbatim_match)
57405796c8dcSSimon Schubert sym_name = add_angle_brackets (sym_name);
57415796c8dcSSimon Schubert
5742*ef5ccd6cSJohn Marino if (!encoded_p)
57435796c8dcSSimon Schubert sym_name = ada_decode (sym_name);
57445796c8dcSSimon Schubert
57455796c8dcSSimon Schubert return sym_name;
57465796c8dcSSimon Schubert }
57475796c8dcSSimon Schubert
57485796c8dcSSimon Schubert /* A companion function to ada_make_symbol_completion_list().
57495796c8dcSSimon Schubert Check if SYM_NAME represents a symbol which name would be suitable
57505796c8dcSSimon Schubert to complete TEXT (TEXT_LEN is the length of TEXT), in which case
57515796c8dcSSimon Schubert it is appended at the end of the given string vector SV.
57525796c8dcSSimon Schubert
57535796c8dcSSimon Schubert ORIG_TEXT is the string original string from the user command
57545796c8dcSSimon Schubert that needs to be completed. WORD is the entire command on which
57555796c8dcSSimon Schubert completion should be performed. These two parameters are used to
57565796c8dcSSimon Schubert determine which part of the symbol name should be added to the
57575796c8dcSSimon Schubert completion vector.
5758*ef5ccd6cSJohn Marino if WILD_MATCH_P is set, then wild matching is performed.
5759*ef5ccd6cSJohn Marino ENCODED_P should be set if TEXT represents a symbol name in its
57605796c8dcSSimon Schubert encoded formed (in which case the completion should also be
57615796c8dcSSimon Schubert encoded). */
57625796c8dcSSimon Schubert
57635796c8dcSSimon Schubert static void
symbol_completion_add(VEC (char_ptr)** sv,const char * sym_name,const char * text,int text_len,const char * orig_text,const char * word,int wild_match_p,int encoded_p)57645796c8dcSSimon Schubert symbol_completion_add (VEC(char_ptr) **sv,
57655796c8dcSSimon Schubert const char *sym_name,
57665796c8dcSSimon Schubert const char *text, int text_len,
57675796c8dcSSimon Schubert const char *orig_text, const char *word,
5768*ef5ccd6cSJohn Marino int wild_match_p, int encoded_p)
57695796c8dcSSimon Schubert {
57705796c8dcSSimon Schubert const char *match = symbol_completion_match (sym_name, text, text_len,
5771*ef5ccd6cSJohn Marino wild_match_p, encoded_p);
57725796c8dcSSimon Schubert char *completion;
57735796c8dcSSimon Schubert
57745796c8dcSSimon Schubert if (match == NULL)
57755796c8dcSSimon Schubert return;
57765796c8dcSSimon Schubert
57775796c8dcSSimon Schubert /* We found a match, so add the appropriate completion to the given
57785796c8dcSSimon Schubert string vector. */
57795796c8dcSSimon Schubert
57805796c8dcSSimon Schubert if (word == orig_text)
57815796c8dcSSimon Schubert {
57825796c8dcSSimon Schubert completion = xmalloc (strlen (match) + 5);
57835796c8dcSSimon Schubert strcpy (completion, match);
57845796c8dcSSimon Schubert }
57855796c8dcSSimon Schubert else if (word > orig_text)
57865796c8dcSSimon Schubert {
57875796c8dcSSimon Schubert /* Return some portion of sym_name. */
57885796c8dcSSimon Schubert completion = xmalloc (strlen (match) + 5);
57895796c8dcSSimon Schubert strcpy (completion, match + (word - orig_text));
57905796c8dcSSimon Schubert }
57915796c8dcSSimon Schubert else
57925796c8dcSSimon Schubert {
57935796c8dcSSimon Schubert /* Return some of ORIG_TEXT plus sym_name. */
57945796c8dcSSimon Schubert completion = xmalloc (strlen (match) + (orig_text - word) + 5);
57955796c8dcSSimon Schubert strncpy (completion, word, orig_text - word);
57965796c8dcSSimon Schubert completion[orig_text - word] = '\0';
57975796c8dcSSimon Schubert strcat (completion, match);
57985796c8dcSSimon Schubert }
57995796c8dcSSimon Schubert
58005796c8dcSSimon Schubert VEC_safe_push (char_ptr, *sv, completion);
58015796c8dcSSimon Schubert }
58025796c8dcSSimon Schubert
5803cf7f2e2dSJohn Marino /* An object of this type is passed as the user_data argument to the
5804c50c785cSJohn Marino expand_partial_symbol_names method. */
5805cf7f2e2dSJohn Marino struct add_partial_datum
5806cf7f2e2dSJohn Marino {
5807cf7f2e2dSJohn Marino VEC(char_ptr) **completions;
5808cf7f2e2dSJohn Marino char *text;
5809cf7f2e2dSJohn Marino int text_len;
5810cf7f2e2dSJohn Marino char *text0;
5811cf7f2e2dSJohn Marino char *word;
5812cf7f2e2dSJohn Marino int wild_match;
5813cf7f2e2dSJohn Marino int encoded;
5814cf7f2e2dSJohn Marino };
5815cf7f2e2dSJohn Marino
5816c50c785cSJohn Marino /* A callback for expand_partial_symbol_names. */
5817c50c785cSJohn Marino static int
ada_expand_partial_symbol_name(const char * name,void * user_data)5818*ef5ccd6cSJohn Marino ada_expand_partial_symbol_name (const char *name, void *user_data)
5819cf7f2e2dSJohn Marino {
5820cf7f2e2dSJohn Marino struct add_partial_datum *data = user_data;
5821cf7f2e2dSJohn Marino
5822c50c785cSJohn Marino return symbol_completion_match (name, data->text, data->text_len,
5823c50c785cSJohn Marino data->wild_match, data->encoded) != NULL;
5824cf7f2e2dSJohn Marino }
5825cf7f2e2dSJohn Marino
5826*ef5ccd6cSJohn Marino /* Return a list of possible symbol names completing TEXT0. WORD is
5827*ef5ccd6cSJohn Marino the entire command on which completion is made. */
58285796c8dcSSimon Schubert
VEC(char_ptr)5829*ef5ccd6cSJohn Marino static VEC (char_ptr) *
5830*ef5ccd6cSJohn Marino ada_make_symbol_completion_list (char *text0, char *word, enum type_code code)
58315796c8dcSSimon Schubert {
58325796c8dcSSimon Schubert char *text;
58335796c8dcSSimon Schubert int text_len;
5834*ef5ccd6cSJohn Marino int wild_match_p;
5835*ef5ccd6cSJohn Marino int encoded_p;
58365796c8dcSSimon Schubert VEC(char_ptr) *completions = VEC_alloc (char_ptr, 128);
58375796c8dcSSimon Schubert struct symbol *sym;
58385796c8dcSSimon Schubert struct symtab *s;
58395796c8dcSSimon Schubert struct minimal_symbol *msymbol;
58405796c8dcSSimon Schubert struct objfile *objfile;
58415796c8dcSSimon Schubert struct block *b, *surrounding_static_block = 0;
58425796c8dcSSimon Schubert int i;
5843*ef5ccd6cSJohn Marino struct block_iterator iter;
5844*ef5ccd6cSJohn Marino
5845*ef5ccd6cSJohn Marino gdb_assert (code == TYPE_CODE_UNDEF);
58465796c8dcSSimon Schubert
58475796c8dcSSimon Schubert if (text0[0] == '<')
58485796c8dcSSimon Schubert {
58495796c8dcSSimon Schubert text = xstrdup (text0);
58505796c8dcSSimon Schubert make_cleanup (xfree, text);
58515796c8dcSSimon Schubert text_len = strlen (text);
5852*ef5ccd6cSJohn Marino wild_match_p = 0;
5853*ef5ccd6cSJohn Marino encoded_p = 1;
58545796c8dcSSimon Schubert }
58555796c8dcSSimon Schubert else
58565796c8dcSSimon Schubert {
58575796c8dcSSimon Schubert text = xstrdup (ada_encode (text0));
58585796c8dcSSimon Schubert make_cleanup (xfree, text);
58595796c8dcSSimon Schubert text_len = strlen (text);
58605796c8dcSSimon Schubert for (i = 0; i < text_len; i++)
58615796c8dcSSimon Schubert text[i] = tolower (text[i]);
58625796c8dcSSimon Schubert
5863*ef5ccd6cSJohn Marino encoded_p = (strstr (text0, "__") != NULL);
58645796c8dcSSimon Schubert /* If the name contains a ".", then the user is entering a fully
58655796c8dcSSimon Schubert qualified entity name, and the match must not be done in wild
58665796c8dcSSimon Schubert mode. Similarly, if the user wants to complete what looks like
58675796c8dcSSimon Schubert an encoded name, the match must not be done in wild mode. */
5868*ef5ccd6cSJohn Marino wild_match_p = (strchr (text0, '.') == NULL && !encoded_p);
58695796c8dcSSimon Schubert }
58705796c8dcSSimon Schubert
58715796c8dcSSimon Schubert /* First, look at the partial symtab symbols. */
58725796c8dcSSimon Schubert {
5873cf7f2e2dSJohn Marino struct add_partial_datum data;
58745796c8dcSSimon Schubert
5875cf7f2e2dSJohn Marino data.completions = &completions;
5876cf7f2e2dSJohn Marino data.text = text;
5877cf7f2e2dSJohn Marino data.text_len = text_len;
5878cf7f2e2dSJohn Marino data.text0 = text0;
5879cf7f2e2dSJohn Marino data.word = word;
5880*ef5ccd6cSJohn Marino data.wild_match = wild_match_p;
5881*ef5ccd6cSJohn Marino data.encoded = encoded_p;
5882c50c785cSJohn Marino expand_partial_symbol_names (ada_expand_partial_symbol_name, &data);
58835796c8dcSSimon Schubert }
58845796c8dcSSimon Schubert
58855796c8dcSSimon Schubert /* At this point scan through the misc symbol vectors and add each
58865796c8dcSSimon Schubert symbol you find to the list. Eventually we want to ignore
58875796c8dcSSimon Schubert anything that isn't a text symbol (everything else will be
58885796c8dcSSimon Schubert handled by the psymtab code above). */
58895796c8dcSSimon Schubert
58905796c8dcSSimon Schubert ALL_MSYMBOLS (objfile, msymbol)
58915796c8dcSSimon Schubert {
58925796c8dcSSimon Schubert QUIT;
58935796c8dcSSimon Schubert symbol_completion_add (&completions, SYMBOL_LINKAGE_NAME (msymbol),
5894*ef5ccd6cSJohn Marino text, text_len, text0, word, wild_match_p,
5895*ef5ccd6cSJohn Marino encoded_p);
58965796c8dcSSimon Schubert }
58975796c8dcSSimon Schubert
58985796c8dcSSimon Schubert /* Search upwards from currently selected frame (so that we can
58995796c8dcSSimon Schubert complete on local vars. */
59005796c8dcSSimon Schubert
59015796c8dcSSimon Schubert for (b = get_selected_block (0); b != NULL; b = BLOCK_SUPERBLOCK (b))
59025796c8dcSSimon Schubert {
59035796c8dcSSimon Schubert if (!BLOCK_SUPERBLOCK (b))
59045796c8dcSSimon Schubert surrounding_static_block = b; /* For elmin of dups */
59055796c8dcSSimon Schubert
59065796c8dcSSimon Schubert ALL_BLOCK_SYMBOLS (b, iter, sym)
59075796c8dcSSimon Schubert {
59085796c8dcSSimon Schubert symbol_completion_add (&completions, SYMBOL_LINKAGE_NAME (sym),
59095796c8dcSSimon Schubert text, text_len, text0, word,
5910*ef5ccd6cSJohn Marino wild_match_p, encoded_p);
59115796c8dcSSimon Schubert }
59125796c8dcSSimon Schubert }
59135796c8dcSSimon Schubert
59145796c8dcSSimon Schubert /* Go through the symtabs and check the externs and statics for
59155796c8dcSSimon Schubert symbols which match. */
59165796c8dcSSimon Schubert
59175796c8dcSSimon Schubert ALL_SYMTABS (objfile, s)
59185796c8dcSSimon Schubert {
59195796c8dcSSimon Schubert QUIT;
59205796c8dcSSimon Schubert b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK);
59215796c8dcSSimon Schubert ALL_BLOCK_SYMBOLS (b, iter, sym)
59225796c8dcSSimon Schubert {
59235796c8dcSSimon Schubert symbol_completion_add (&completions, SYMBOL_LINKAGE_NAME (sym),
59245796c8dcSSimon Schubert text, text_len, text0, word,
5925*ef5ccd6cSJohn Marino wild_match_p, encoded_p);
59265796c8dcSSimon Schubert }
59275796c8dcSSimon Schubert }
59285796c8dcSSimon Schubert
59295796c8dcSSimon Schubert ALL_SYMTABS (objfile, s)
59305796c8dcSSimon Schubert {
59315796c8dcSSimon Schubert QUIT;
59325796c8dcSSimon Schubert b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK);
59335796c8dcSSimon Schubert /* Don't do this block twice. */
59345796c8dcSSimon Schubert if (b == surrounding_static_block)
59355796c8dcSSimon Schubert continue;
59365796c8dcSSimon Schubert ALL_BLOCK_SYMBOLS (b, iter, sym)
59375796c8dcSSimon Schubert {
59385796c8dcSSimon Schubert symbol_completion_add (&completions, SYMBOL_LINKAGE_NAME (sym),
59395796c8dcSSimon Schubert text, text_len, text0, word,
5940*ef5ccd6cSJohn Marino wild_match_p, encoded_p);
59415796c8dcSSimon Schubert }
59425796c8dcSSimon Schubert }
59435796c8dcSSimon Schubert
5944*ef5ccd6cSJohn Marino return completions;
59455796c8dcSSimon Schubert }
59465796c8dcSSimon Schubert
59475796c8dcSSimon Schubert /* Field Access */
59485796c8dcSSimon Schubert
59495796c8dcSSimon Schubert /* Return non-zero if TYPE is a pointer to the GNAT dispatch table used
59505796c8dcSSimon Schubert for tagged types. */
59515796c8dcSSimon Schubert
59525796c8dcSSimon Schubert static int
ada_is_dispatch_table_ptr_type(struct type * type)59535796c8dcSSimon Schubert ada_is_dispatch_table_ptr_type (struct type *type)
59545796c8dcSSimon Schubert {
5955*ef5ccd6cSJohn Marino const char *name;
59565796c8dcSSimon Schubert
59575796c8dcSSimon Schubert if (TYPE_CODE (type) != TYPE_CODE_PTR)
59585796c8dcSSimon Schubert return 0;
59595796c8dcSSimon Schubert
59605796c8dcSSimon Schubert name = TYPE_NAME (TYPE_TARGET_TYPE (type));
59615796c8dcSSimon Schubert if (name == NULL)
59625796c8dcSSimon Schubert return 0;
59635796c8dcSSimon Schubert
59645796c8dcSSimon Schubert return (strcmp (name, "ada__tags__dispatch_table") == 0);
59655796c8dcSSimon Schubert }
59665796c8dcSSimon Schubert
5967*ef5ccd6cSJohn Marino /* Return non-zero if TYPE is an interface tag. */
5968*ef5ccd6cSJohn Marino
5969*ef5ccd6cSJohn Marino static int
ada_is_interface_tag(struct type * type)5970*ef5ccd6cSJohn Marino ada_is_interface_tag (struct type *type)
5971*ef5ccd6cSJohn Marino {
5972*ef5ccd6cSJohn Marino const char *name = TYPE_NAME (type);
5973*ef5ccd6cSJohn Marino
5974*ef5ccd6cSJohn Marino if (name == NULL)
5975*ef5ccd6cSJohn Marino return 0;
5976*ef5ccd6cSJohn Marino
5977*ef5ccd6cSJohn Marino return (strcmp (name, "ada__tags__interface_tag") == 0);
5978*ef5ccd6cSJohn Marino }
5979*ef5ccd6cSJohn Marino
59805796c8dcSSimon Schubert /* True if field number FIELD_NUM in struct or union type TYPE is supposed
59815796c8dcSSimon Schubert to be invisible to users. */
59825796c8dcSSimon Schubert
59835796c8dcSSimon Schubert int
ada_is_ignored_field(struct type * type,int field_num)59845796c8dcSSimon Schubert ada_is_ignored_field (struct type *type, int field_num)
59855796c8dcSSimon Schubert {
59865796c8dcSSimon Schubert if (field_num < 0 || field_num > TYPE_NFIELDS (type))
59875796c8dcSSimon Schubert return 1;
59885796c8dcSSimon Schubert
59895796c8dcSSimon Schubert /* Check the name of that field. */
59905796c8dcSSimon Schubert {
59915796c8dcSSimon Schubert const char *name = TYPE_FIELD_NAME (type, field_num);
59925796c8dcSSimon Schubert
59935796c8dcSSimon Schubert /* Anonymous field names should not be printed.
59945796c8dcSSimon Schubert brobecker/2007-02-20: I don't think this can actually happen
59955796c8dcSSimon Schubert but we don't want to print the value of annonymous fields anyway. */
59965796c8dcSSimon Schubert if (name == NULL)
59975796c8dcSSimon Schubert return 1;
59985796c8dcSSimon Schubert
5999*ef5ccd6cSJohn Marino /* Normally, fields whose name start with an underscore ("_")
6000*ef5ccd6cSJohn Marino are fields that have been internally generated by the compiler,
6001*ef5ccd6cSJohn Marino and thus should not be printed. The "_parent" field is special,
6002*ef5ccd6cSJohn Marino however: This is a field internally generated by the compiler
6003*ef5ccd6cSJohn Marino for tagged types, and it contains the components inherited from
6004*ef5ccd6cSJohn Marino the parent type. This field should not be printed as is, but
6005*ef5ccd6cSJohn Marino should not be ignored either. */
60065796c8dcSSimon Schubert if (name[0] == '_' && strncmp (name, "_parent", 7) != 0)
60075796c8dcSSimon Schubert return 1;
60085796c8dcSSimon Schubert }
60095796c8dcSSimon Schubert
6010*ef5ccd6cSJohn Marino /* If this is the dispatch table of a tagged type or an interface tag,
6011*ef5ccd6cSJohn Marino then ignore. */
60125796c8dcSSimon Schubert if (ada_is_tagged_type (type, 1)
6013*ef5ccd6cSJohn Marino && (ada_is_dispatch_table_ptr_type (TYPE_FIELD_TYPE (type, field_num))
6014*ef5ccd6cSJohn Marino || ada_is_interface_tag (TYPE_FIELD_TYPE (type, field_num))))
60155796c8dcSSimon Schubert return 1;
60165796c8dcSSimon Schubert
60175796c8dcSSimon Schubert /* Not a special field, so it should not be ignored. */
60185796c8dcSSimon Schubert return 0;
60195796c8dcSSimon Schubert }
60205796c8dcSSimon Schubert
60215796c8dcSSimon Schubert /* True iff TYPE has a tag field. If REFOK, then TYPE may also be a
60225796c8dcSSimon Schubert pointer or reference type whose ultimate target has a tag field. */
60235796c8dcSSimon Schubert
60245796c8dcSSimon Schubert int
ada_is_tagged_type(struct type * type,int refok)60255796c8dcSSimon Schubert ada_is_tagged_type (struct type *type, int refok)
60265796c8dcSSimon Schubert {
60275796c8dcSSimon Schubert return (ada_lookup_struct_elt_type (type, "_tag", refok, 1, NULL) != NULL);
60285796c8dcSSimon Schubert }
60295796c8dcSSimon Schubert
60305796c8dcSSimon Schubert /* True iff TYPE represents the type of X'Tag */
60315796c8dcSSimon Schubert
60325796c8dcSSimon Schubert int
ada_is_tag_type(struct type * type)60335796c8dcSSimon Schubert ada_is_tag_type (struct type *type)
60345796c8dcSSimon Schubert {
60355796c8dcSSimon Schubert if (type == NULL || TYPE_CODE (type) != TYPE_CODE_PTR)
60365796c8dcSSimon Schubert return 0;
60375796c8dcSSimon Schubert else
60385796c8dcSSimon Schubert {
60395796c8dcSSimon Schubert const char *name = ada_type_name (TYPE_TARGET_TYPE (type));
6040cf7f2e2dSJohn Marino
60415796c8dcSSimon Schubert return (name != NULL
60425796c8dcSSimon Schubert && strcmp (name, "ada__tags__dispatch_table") == 0);
60435796c8dcSSimon Schubert }
60445796c8dcSSimon Schubert }
60455796c8dcSSimon Schubert
60465796c8dcSSimon Schubert /* The type of the tag on VAL. */
60475796c8dcSSimon Schubert
60485796c8dcSSimon Schubert struct type *
ada_tag_type(struct value * val)60495796c8dcSSimon Schubert ada_tag_type (struct value *val)
60505796c8dcSSimon Schubert {
60515796c8dcSSimon Schubert return ada_lookup_struct_elt_type (value_type (val), "_tag", 1, 0, NULL);
60525796c8dcSSimon Schubert }
60535796c8dcSSimon Schubert
6054*ef5ccd6cSJohn Marino /* Return 1 if TAG follows the old scheme for Ada tags (used for Ada 95,
6055*ef5ccd6cSJohn Marino retired at Ada 05). */
6056*ef5ccd6cSJohn Marino
6057*ef5ccd6cSJohn Marino static int
is_ada95_tag(struct value * tag)6058*ef5ccd6cSJohn Marino is_ada95_tag (struct value *tag)
6059*ef5ccd6cSJohn Marino {
6060*ef5ccd6cSJohn Marino return ada_value_struct_elt (tag, "tsd", 1) != NULL;
6061*ef5ccd6cSJohn Marino }
6062*ef5ccd6cSJohn Marino
60635796c8dcSSimon Schubert /* The value of the tag on VAL. */
60645796c8dcSSimon Schubert
60655796c8dcSSimon Schubert struct value *
ada_value_tag(struct value * val)60665796c8dcSSimon Schubert ada_value_tag (struct value *val)
60675796c8dcSSimon Schubert {
60685796c8dcSSimon Schubert return ada_value_struct_elt (val, "_tag", 0);
60695796c8dcSSimon Schubert }
60705796c8dcSSimon Schubert
60715796c8dcSSimon Schubert /* The value of the tag on the object of type TYPE whose contents are
60725796c8dcSSimon Schubert saved at VALADDR, if it is non-null, or is at memory address
60735796c8dcSSimon Schubert ADDRESS. */
60745796c8dcSSimon Schubert
60755796c8dcSSimon Schubert static struct value *
value_tag_from_contents_and_address(struct type * type,const gdb_byte * valaddr,CORE_ADDR address)60765796c8dcSSimon Schubert value_tag_from_contents_and_address (struct type *type,
60775796c8dcSSimon Schubert const gdb_byte *valaddr,
60785796c8dcSSimon Schubert CORE_ADDR address)
60795796c8dcSSimon Schubert {
6080cf7f2e2dSJohn Marino int tag_byte_offset;
60815796c8dcSSimon Schubert struct type *tag_type;
6082cf7f2e2dSJohn Marino
60835796c8dcSSimon Schubert if (find_struct_field ("_tag", type, 0, &tag_type, &tag_byte_offset,
60845796c8dcSSimon Schubert NULL, NULL, NULL))
60855796c8dcSSimon Schubert {
60865796c8dcSSimon Schubert const gdb_byte *valaddr1 = ((valaddr == NULL)
60875796c8dcSSimon Schubert ? NULL
60885796c8dcSSimon Schubert : valaddr + tag_byte_offset);
60895796c8dcSSimon Schubert CORE_ADDR address1 = (address == 0) ? 0 : address + tag_byte_offset;
60905796c8dcSSimon Schubert
60915796c8dcSSimon Schubert return value_from_contents_and_address (tag_type, valaddr1, address1);
60925796c8dcSSimon Schubert }
60935796c8dcSSimon Schubert return NULL;
60945796c8dcSSimon Schubert }
60955796c8dcSSimon Schubert
60965796c8dcSSimon Schubert static struct type *
type_from_tag(struct value * tag)60975796c8dcSSimon Schubert type_from_tag (struct value *tag)
60985796c8dcSSimon Schubert {
60995796c8dcSSimon Schubert const char *type_name = ada_tag_name (tag);
6100cf7f2e2dSJohn Marino
61015796c8dcSSimon Schubert if (type_name != NULL)
61025796c8dcSSimon Schubert return ada_find_any_type (ada_encode (type_name));
61035796c8dcSSimon Schubert return NULL;
61045796c8dcSSimon Schubert }
61055796c8dcSSimon Schubert
6106*ef5ccd6cSJohn Marino /* Given a value OBJ of a tagged type, return a value of this
6107*ef5ccd6cSJohn Marino type at the base address of the object. The base address, as
6108*ef5ccd6cSJohn Marino defined in Ada.Tags, it is the address of the primary tag of
6109*ef5ccd6cSJohn Marino the object, and therefore where the field values of its full
6110*ef5ccd6cSJohn Marino view can be fetched. */
6111*ef5ccd6cSJohn Marino
6112*ef5ccd6cSJohn Marino struct value *
ada_tag_value_at_base_address(struct value * obj)6113*ef5ccd6cSJohn Marino ada_tag_value_at_base_address (struct value *obj)
61145796c8dcSSimon Schubert {
6115*ef5ccd6cSJohn Marino volatile struct gdb_exception e;
61165796c8dcSSimon Schubert struct value *val;
6117*ef5ccd6cSJohn Marino LONGEST offset_to_top = 0;
6118*ef5ccd6cSJohn Marino struct type *ptr_type, *obj_type;
6119*ef5ccd6cSJohn Marino struct value *tag;
6120*ef5ccd6cSJohn Marino CORE_ADDR base_address;
6121cf7f2e2dSJohn Marino
6122*ef5ccd6cSJohn Marino obj_type = value_type (obj);
6123*ef5ccd6cSJohn Marino
6124*ef5ccd6cSJohn Marino /* It is the responsability of the caller to deref pointers. */
6125*ef5ccd6cSJohn Marino
6126*ef5ccd6cSJohn Marino if (TYPE_CODE (obj_type) == TYPE_CODE_PTR
6127*ef5ccd6cSJohn Marino || TYPE_CODE (obj_type) == TYPE_CODE_REF)
6128*ef5ccd6cSJohn Marino return obj;
6129*ef5ccd6cSJohn Marino
6130*ef5ccd6cSJohn Marino tag = ada_value_tag (obj);
6131*ef5ccd6cSJohn Marino if (!tag)
6132*ef5ccd6cSJohn Marino return obj;
6133*ef5ccd6cSJohn Marino
6134*ef5ccd6cSJohn Marino /* Base addresses only appeared with Ada 05 and multiple inheritance. */
6135*ef5ccd6cSJohn Marino
6136*ef5ccd6cSJohn Marino if (is_ada95_tag (tag))
6137*ef5ccd6cSJohn Marino return obj;
6138*ef5ccd6cSJohn Marino
6139*ef5ccd6cSJohn Marino ptr_type = builtin_type (target_gdbarch ())->builtin_data_ptr;
6140*ef5ccd6cSJohn Marino ptr_type = lookup_pointer_type (ptr_type);
6141*ef5ccd6cSJohn Marino val = value_cast (ptr_type, tag);
6142*ef5ccd6cSJohn Marino if (!val)
6143*ef5ccd6cSJohn Marino return obj;
6144*ef5ccd6cSJohn Marino
6145*ef5ccd6cSJohn Marino /* It is perfectly possible that an exception be raised while
6146*ef5ccd6cSJohn Marino trying to determine the base address, just like for the tag;
6147*ef5ccd6cSJohn Marino see ada_tag_name for more details. We do not print the error
6148*ef5ccd6cSJohn Marino message for the same reason. */
6149*ef5ccd6cSJohn Marino
6150*ef5ccd6cSJohn Marino TRY_CATCH (e, RETURN_MASK_ERROR)
6151*ef5ccd6cSJohn Marino {
6152*ef5ccd6cSJohn Marino offset_to_top = value_as_long (value_ind (value_ptradd (val, -2)));
6153*ef5ccd6cSJohn Marino }
6154*ef5ccd6cSJohn Marino
6155*ef5ccd6cSJohn Marino if (e.reason < 0)
6156*ef5ccd6cSJohn Marino return obj;
6157*ef5ccd6cSJohn Marino
6158*ef5ccd6cSJohn Marino /* If offset is null, nothing to do. */
6159*ef5ccd6cSJohn Marino
6160*ef5ccd6cSJohn Marino if (offset_to_top == 0)
6161*ef5ccd6cSJohn Marino return obj;
6162*ef5ccd6cSJohn Marino
6163*ef5ccd6cSJohn Marino /* -1 is a special case in Ada.Tags; however, what should be done
6164*ef5ccd6cSJohn Marino is not quite clear from the documentation. So do nothing for
6165*ef5ccd6cSJohn Marino now. */
6166*ef5ccd6cSJohn Marino
6167*ef5ccd6cSJohn Marino if (offset_to_top == -1)
6168*ef5ccd6cSJohn Marino return obj;
6169*ef5ccd6cSJohn Marino
6170*ef5ccd6cSJohn Marino base_address = value_address (obj) - offset_to_top;
6171*ef5ccd6cSJohn Marino tag = value_tag_from_contents_and_address (obj_type, NULL, base_address);
6172*ef5ccd6cSJohn Marino
6173*ef5ccd6cSJohn Marino /* Make sure that we have a proper tag at the new address.
6174*ef5ccd6cSJohn Marino Otherwise, offset_to_top is bogus (which can happen when
6175*ef5ccd6cSJohn Marino the object is not initialized yet). */
6176*ef5ccd6cSJohn Marino
6177*ef5ccd6cSJohn Marino if (!tag)
6178*ef5ccd6cSJohn Marino return obj;
6179*ef5ccd6cSJohn Marino
6180*ef5ccd6cSJohn Marino obj_type = type_from_tag (tag);
6181*ef5ccd6cSJohn Marino
6182*ef5ccd6cSJohn Marino if (!obj_type)
6183*ef5ccd6cSJohn Marino return obj;
6184*ef5ccd6cSJohn Marino
6185*ef5ccd6cSJohn Marino return value_from_contents_and_address (obj_type, NULL, base_address);
61865796c8dcSSimon Schubert }
61875796c8dcSSimon Schubert
6188cf7f2e2dSJohn Marino /* Return the "ada__tags__type_specific_data" type. */
6189cf7f2e2dSJohn Marino
6190cf7f2e2dSJohn Marino static struct type *
ada_get_tsd_type(struct inferior * inf)6191cf7f2e2dSJohn Marino ada_get_tsd_type (struct inferior *inf)
6192cf7f2e2dSJohn Marino {
6193cf7f2e2dSJohn Marino struct ada_inferior_data *data = get_ada_inferior_data (inf);
6194cf7f2e2dSJohn Marino
6195cf7f2e2dSJohn Marino if (data->tsd_type == 0)
6196cf7f2e2dSJohn Marino data->tsd_type = ada_find_any_type ("ada__tags__type_specific_data");
6197cf7f2e2dSJohn Marino return data->tsd_type;
6198cf7f2e2dSJohn Marino }
6199cf7f2e2dSJohn Marino
6200*ef5ccd6cSJohn Marino /* Return the TSD (type-specific data) associated to the given TAG.
6201*ef5ccd6cSJohn Marino TAG is assumed to be the tag of a tagged-type entity.
62025796c8dcSSimon Schubert
6203*ef5ccd6cSJohn Marino May return NULL if we are unable to get the TSD. */
6204*ef5ccd6cSJohn Marino
6205*ef5ccd6cSJohn Marino static struct value *
ada_get_tsd_from_tag(struct value * tag)6206*ef5ccd6cSJohn Marino ada_get_tsd_from_tag (struct value *tag)
62075796c8dcSSimon Schubert {
6208*ef5ccd6cSJohn Marino struct value *val;
6209*ef5ccd6cSJohn Marino struct type *type;
6210*ef5ccd6cSJohn Marino
6211*ef5ccd6cSJohn Marino /* First option: The TSD is simply stored as a field of our TAG.
6212*ef5ccd6cSJohn Marino Only older versions of GNAT would use this format, but we have
6213*ef5ccd6cSJohn Marino to test it first, because there are no visible markers for
6214*ef5ccd6cSJohn Marino the current approach except the absence of that field. */
6215*ef5ccd6cSJohn Marino
6216*ef5ccd6cSJohn Marino val = ada_value_struct_elt (tag, "tsd", 1);
6217*ef5ccd6cSJohn Marino if (val)
6218*ef5ccd6cSJohn Marino return val;
6219*ef5ccd6cSJohn Marino
6220*ef5ccd6cSJohn Marino /* Try the second representation for the dispatch table (in which
6221*ef5ccd6cSJohn Marino there is no explicit 'tsd' field in the referent of the tag pointer,
6222*ef5ccd6cSJohn Marino and instead the tsd pointer is stored just before the dispatch
6223*ef5ccd6cSJohn Marino table. */
6224*ef5ccd6cSJohn Marino
6225*ef5ccd6cSJohn Marino type = ada_get_tsd_type (current_inferior());
6226*ef5ccd6cSJohn Marino if (type == NULL)
6227*ef5ccd6cSJohn Marino return NULL;
6228*ef5ccd6cSJohn Marino type = lookup_pointer_type (lookup_pointer_type (type));
6229*ef5ccd6cSJohn Marino val = value_cast (type, tag);
6230*ef5ccd6cSJohn Marino if (val == NULL)
6231*ef5ccd6cSJohn Marino return NULL;
6232*ef5ccd6cSJohn Marino return value_ind (value_ptradd (val, -1));
6233*ef5ccd6cSJohn Marino }
6234*ef5ccd6cSJohn Marino
6235*ef5ccd6cSJohn Marino /* Given the TSD of a tag (type-specific data), return a string
6236*ef5ccd6cSJohn Marino containing the name of the associated type.
6237*ef5ccd6cSJohn Marino
6238*ef5ccd6cSJohn Marino The returned value is good until the next call. May return NULL
6239*ef5ccd6cSJohn Marino if we are unable to determine the tag name. */
6240*ef5ccd6cSJohn Marino
6241*ef5ccd6cSJohn Marino static char *
ada_tag_name_from_tsd(struct value * tsd)6242*ef5ccd6cSJohn Marino ada_tag_name_from_tsd (struct value *tsd)
6243*ef5ccd6cSJohn Marino {
62445796c8dcSSimon Schubert static char name[1024];
62455796c8dcSSimon Schubert char *p;
6246*ef5ccd6cSJohn Marino struct value *val;
62475796c8dcSSimon Schubert
6248*ef5ccd6cSJohn Marino val = ada_value_struct_elt (tsd, "expanded_name", 1);
62495796c8dcSSimon Schubert if (val == NULL)
6250*ef5ccd6cSJohn Marino return NULL;
62515796c8dcSSimon Schubert read_memory_string (value_as_address (val), name, sizeof (name) - 1);
62525796c8dcSSimon Schubert for (p = name; *p != '\0'; p += 1)
62535796c8dcSSimon Schubert if (isalpha (*p))
62545796c8dcSSimon Schubert *p = tolower (*p);
6255*ef5ccd6cSJohn Marino return name;
62565796c8dcSSimon Schubert }
62575796c8dcSSimon Schubert
62585796c8dcSSimon Schubert /* The type name of the dynamic type denoted by the 'tag value TAG, as
6259*ef5ccd6cSJohn Marino a C string.
6260*ef5ccd6cSJohn Marino
6261*ef5ccd6cSJohn Marino Return NULL if the TAG is not an Ada tag, or if we were unable to
6262*ef5ccd6cSJohn Marino determine the name of that tag. The result is good until the next
6263*ef5ccd6cSJohn Marino call. */
62645796c8dcSSimon Schubert
62655796c8dcSSimon Schubert const char *
ada_tag_name(struct value * tag)62665796c8dcSSimon Schubert ada_tag_name (struct value *tag)
62675796c8dcSSimon Schubert {
6268*ef5ccd6cSJohn Marino volatile struct gdb_exception e;
6269*ef5ccd6cSJohn Marino char *name = NULL;
6270cf7f2e2dSJohn Marino
62715796c8dcSSimon Schubert if (!ada_is_tag_type (value_type (tag)))
62725796c8dcSSimon Schubert return NULL;
6273*ef5ccd6cSJohn Marino
6274*ef5ccd6cSJohn Marino /* It is perfectly possible that an exception be raised while trying
6275*ef5ccd6cSJohn Marino to determine the TAG's name, even under normal circumstances:
6276*ef5ccd6cSJohn Marino The associated variable may be uninitialized or corrupted, for
6277*ef5ccd6cSJohn Marino instance. We do not let any exception propagate past this point.
6278*ef5ccd6cSJohn Marino instead we return NULL.
6279*ef5ccd6cSJohn Marino
6280*ef5ccd6cSJohn Marino We also do not print the error message either (which often is very
6281*ef5ccd6cSJohn Marino low-level (Eg: "Cannot read memory at 0x[...]"), but instead let
6282*ef5ccd6cSJohn Marino the caller print a more meaningful message if necessary. */
6283*ef5ccd6cSJohn Marino TRY_CATCH (e, RETURN_MASK_ERROR)
6284*ef5ccd6cSJohn Marino {
6285*ef5ccd6cSJohn Marino struct value *tsd = ada_get_tsd_from_tag (tag);
6286*ef5ccd6cSJohn Marino
6287*ef5ccd6cSJohn Marino if (tsd != NULL)
6288*ef5ccd6cSJohn Marino name = ada_tag_name_from_tsd (tsd);
6289*ef5ccd6cSJohn Marino }
6290*ef5ccd6cSJohn Marino
6291*ef5ccd6cSJohn Marino return name;
62925796c8dcSSimon Schubert }
62935796c8dcSSimon Schubert
62945796c8dcSSimon Schubert /* The parent type of TYPE, or NULL if none. */
62955796c8dcSSimon Schubert
62965796c8dcSSimon Schubert struct type *
ada_parent_type(struct type * type)62975796c8dcSSimon Schubert ada_parent_type (struct type *type)
62985796c8dcSSimon Schubert {
62995796c8dcSSimon Schubert int i;
63005796c8dcSSimon Schubert
63015796c8dcSSimon Schubert type = ada_check_typedef (type);
63025796c8dcSSimon Schubert
63035796c8dcSSimon Schubert if (type == NULL || TYPE_CODE (type) != TYPE_CODE_STRUCT)
63045796c8dcSSimon Schubert return NULL;
63055796c8dcSSimon Schubert
63065796c8dcSSimon Schubert for (i = 0; i < TYPE_NFIELDS (type); i += 1)
63075796c8dcSSimon Schubert if (ada_is_parent_field (type, i))
63085796c8dcSSimon Schubert {
63095796c8dcSSimon Schubert struct type *parent_type = TYPE_FIELD_TYPE (type, i);
63105796c8dcSSimon Schubert
63115796c8dcSSimon Schubert /* If the _parent field is a pointer, then dereference it. */
63125796c8dcSSimon Schubert if (TYPE_CODE (parent_type) == TYPE_CODE_PTR)
63135796c8dcSSimon Schubert parent_type = TYPE_TARGET_TYPE (parent_type);
63145796c8dcSSimon Schubert /* If there is a parallel XVS type, get the actual base type. */
63155796c8dcSSimon Schubert parent_type = ada_get_base_type (parent_type);
63165796c8dcSSimon Schubert
63175796c8dcSSimon Schubert return ada_check_typedef (parent_type);
63185796c8dcSSimon Schubert }
63195796c8dcSSimon Schubert
63205796c8dcSSimon Schubert return NULL;
63215796c8dcSSimon Schubert }
63225796c8dcSSimon Schubert
63235796c8dcSSimon Schubert /* True iff field number FIELD_NUM of structure type TYPE contains the
63245796c8dcSSimon Schubert parent-type (inherited) fields of a derived type. Assumes TYPE is
63255796c8dcSSimon Schubert a structure type with at least FIELD_NUM+1 fields. */
63265796c8dcSSimon Schubert
63275796c8dcSSimon Schubert int
ada_is_parent_field(struct type * type,int field_num)63285796c8dcSSimon Schubert ada_is_parent_field (struct type *type, int field_num)
63295796c8dcSSimon Schubert {
63305796c8dcSSimon Schubert const char *name = TYPE_FIELD_NAME (ada_check_typedef (type), field_num);
6331cf7f2e2dSJohn Marino
63325796c8dcSSimon Schubert return (name != NULL
63335796c8dcSSimon Schubert && (strncmp (name, "PARENT", 6) == 0
63345796c8dcSSimon Schubert || strncmp (name, "_parent", 7) == 0));
63355796c8dcSSimon Schubert }
63365796c8dcSSimon Schubert
63375796c8dcSSimon Schubert /* True iff field number FIELD_NUM of structure type TYPE is a
63385796c8dcSSimon Schubert transparent wrapper field (which should be silently traversed when doing
63395796c8dcSSimon Schubert field selection and flattened when printing). Assumes TYPE is a
63405796c8dcSSimon Schubert structure type with at least FIELD_NUM+1 fields. Such fields are always
63415796c8dcSSimon Schubert structures. */
63425796c8dcSSimon Schubert
63435796c8dcSSimon Schubert int
ada_is_wrapper_field(struct type * type,int field_num)63445796c8dcSSimon Schubert ada_is_wrapper_field (struct type *type, int field_num)
63455796c8dcSSimon Schubert {
63465796c8dcSSimon Schubert const char *name = TYPE_FIELD_NAME (type, field_num);
6347cf7f2e2dSJohn Marino
63485796c8dcSSimon Schubert return (name != NULL
63495796c8dcSSimon Schubert && (strncmp (name, "PARENT", 6) == 0
63505796c8dcSSimon Schubert || strcmp (name, "REP") == 0
63515796c8dcSSimon Schubert || strncmp (name, "_parent", 7) == 0
63525796c8dcSSimon Schubert || name[0] == 'S' || name[0] == 'R' || name[0] == 'O'));
63535796c8dcSSimon Schubert }
63545796c8dcSSimon Schubert
63555796c8dcSSimon Schubert /* True iff field number FIELD_NUM of structure or union type TYPE
63565796c8dcSSimon Schubert is a variant wrapper. Assumes TYPE is a structure type with at least
63575796c8dcSSimon Schubert FIELD_NUM+1 fields. */
63585796c8dcSSimon Schubert
63595796c8dcSSimon Schubert int
ada_is_variant_part(struct type * type,int field_num)63605796c8dcSSimon Schubert ada_is_variant_part (struct type *type, int field_num)
63615796c8dcSSimon Schubert {
63625796c8dcSSimon Schubert struct type *field_type = TYPE_FIELD_TYPE (type, field_num);
6363cf7f2e2dSJohn Marino
63645796c8dcSSimon Schubert return (TYPE_CODE (field_type) == TYPE_CODE_UNION
63655796c8dcSSimon Schubert || (is_dynamic_field (type, field_num)
63665796c8dcSSimon Schubert && (TYPE_CODE (TYPE_TARGET_TYPE (field_type))
63675796c8dcSSimon Schubert == TYPE_CODE_UNION)));
63685796c8dcSSimon Schubert }
63695796c8dcSSimon Schubert
63705796c8dcSSimon Schubert /* Assuming that VAR_TYPE is a variant wrapper (type of the variant part)
63715796c8dcSSimon Schubert whose discriminants are contained in the record type OUTER_TYPE,
63725796c8dcSSimon Schubert returns the type of the controlling discriminant for the variant.
63735796c8dcSSimon Schubert May return NULL if the type could not be found. */
63745796c8dcSSimon Schubert
63755796c8dcSSimon Schubert struct type *
ada_variant_discrim_type(struct type * var_type,struct type * outer_type)63765796c8dcSSimon Schubert ada_variant_discrim_type (struct type *var_type, struct type *outer_type)
63775796c8dcSSimon Schubert {
63785796c8dcSSimon Schubert char *name = ada_variant_discrim_name (var_type);
6379cf7f2e2dSJohn Marino
63805796c8dcSSimon Schubert return ada_lookup_struct_elt_type (outer_type, name, 1, 1, NULL);
63815796c8dcSSimon Schubert }
63825796c8dcSSimon Schubert
63835796c8dcSSimon Schubert /* Assuming that TYPE is the type of a variant wrapper, and FIELD_NUM is a
63845796c8dcSSimon Schubert valid field number within it, returns 1 iff field FIELD_NUM of TYPE
63855796c8dcSSimon Schubert represents a 'when others' clause; otherwise 0. */
63865796c8dcSSimon Schubert
63875796c8dcSSimon Schubert int
ada_is_others_clause(struct type * type,int field_num)63885796c8dcSSimon Schubert ada_is_others_clause (struct type *type, int field_num)
63895796c8dcSSimon Schubert {
63905796c8dcSSimon Schubert const char *name = TYPE_FIELD_NAME (type, field_num);
6391cf7f2e2dSJohn Marino
63925796c8dcSSimon Schubert return (name != NULL && name[0] == 'O');
63935796c8dcSSimon Schubert }
63945796c8dcSSimon Schubert
63955796c8dcSSimon Schubert /* Assuming that TYPE0 is the type of the variant part of a record,
63965796c8dcSSimon Schubert returns the name of the discriminant controlling the variant.
63975796c8dcSSimon Schubert The value is valid until the next call to ada_variant_discrim_name. */
63985796c8dcSSimon Schubert
63995796c8dcSSimon Schubert char *
ada_variant_discrim_name(struct type * type0)64005796c8dcSSimon Schubert ada_variant_discrim_name (struct type *type0)
64015796c8dcSSimon Schubert {
64025796c8dcSSimon Schubert static char *result = NULL;
64035796c8dcSSimon Schubert static size_t result_len = 0;
64045796c8dcSSimon Schubert struct type *type;
64055796c8dcSSimon Schubert const char *name;
64065796c8dcSSimon Schubert const char *discrim_end;
64075796c8dcSSimon Schubert const char *discrim_start;
64085796c8dcSSimon Schubert
64095796c8dcSSimon Schubert if (TYPE_CODE (type0) == TYPE_CODE_PTR)
64105796c8dcSSimon Schubert type = TYPE_TARGET_TYPE (type0);
64115796c8dcSSimon Schubert else
64125796c8dcSSimon Schubert type = type0;
64135796c8dcSSimon Schubert
64145796c8dcSSimon Schubert name = ada_type_name (type);
64155796c8dcSSimon Schubert
64165796c8dcSSimon Schubert if (name == NULL || name[0] == '\000')
64175796c8dcSSimon Schubert return "";
64185796c8dcSSimon Schubert
64195796c8dcSSimon Schubert for (discrim_end = name + strlen (name) - 6; discrim_end != name;
64205796c8dcSSimon Schubert discrim_end -= 1)
64215796c8dcSSimon Schubert {
64225796c8dcSSimon Schubert if (strncmp (discrim_end, "___XVN", 6) == 0)
64235796c8dcSSimon Schubert break;
64245796c8dcSSimon Schubert }
64255796c8dcSSimon Schubert if (discrim_end == name)
64265796c8dcSSimon Schubert return "";
64275796c8dcSSimon Schubert
64285796c8dcSSimon Schubert for (discrim_start = discrim_end; discrim_start != name + 3;
64295796c8dcSSimon Schubert discrim_start -= 1)
64305796c8dcSSimon Schubert {
64315796c8dcSSimon Schubert if (discrim_start == name + 1)
64325796c8dcSSimon Schubert return "";
64335796c8dcSSimon Schubert if ((discrim_start > name + 3
64345796c8dcSSimon Schubert && strncmp (discrim_start - 3, "___", 3) == 0)
64355796c8dcSSimon Schubert || discrim_start[-1] == '.')
64365796c8dcSSimon Schubert break;
64375796c8dcSSimon Schubert }
64385796c8dcSSimon Schubert
64395796c8dcSSimon Schubert GROW_VECT (result, result_len, discrim_end - discrim_start + 1);
64405796c8dcSSimon Schubert strncpy (result, discrim_start, discrim_end - discrim_start);
64415796c8dcSSimon Schubert result[discrim_end - discrim_start] = '\0';
64425796c8dcSSimon Schubert return result;
64435796c8dcSSimon Schubert }
64445796c8dcSSimon Schubert
64455796c8dcSSimon Schubert /* Scan STR for a subtype-encoded number, beginning at position K.
64465796c8dcSSimon Schubert Put the position of the character just past the number scanned in
64475796c8dcSSimon Schubert *NEW_K, if NEW_K!=NULL. Put the scanned number in *R, if R!=NULL.
64485796c8dcSSimon Schubert Return 1 if there was a valid number at the given position, and 0
64495796c8dcSSimon Schubert otherwise. A "subtype-encoded" number consists of the absolute value
64505796c8dcSSimon Schubert in decimal, followed by the letter 'm' to indicate a negative number.
64515796c8dcSSimon Schubert Assumes 0m does not occur. */
64525796c8dcSSimon Schubert
64535796c8dcSSimon Schubert int
ada_scan_number(const char str[],int k,LONGEST * R,int * new_k)64545796c8dcSSimon Schubert ada_scan_number (const char str[], int k, LONGEST * R, int *new_k)
64555796c8dcSSimon Schubert {
64565796c8dcSSimon Schubert ULONGEST RU;
64575796c8dcSSimon Schubert
64585796c8dcSSimon Schubert if (!isdigit (str[k]))
64595796c8dcSSimon Schubert return 0;
64605796c8dcSSimon Schubert
64615796c8dcSSimon Schubert /* Do it the hard way so as not to make any assumption about
64625796c8dcSSimon Schubert the relationship of unsigned long (%lu scan format code) and
64635796c8dcSSimon Schubert LONGEST. */
64645796c8dcSSimon Schubert RU = 0;
64655796c8dcSSimon Schubert while (isdigit (str[k]))
64665796c8dcSSimon Schubert {
64675796c8dcSSimon Schubert RU = RU * 10 + (str[k] - '0');
64685796c8dcSSimon Schubert k += 1;
64695796c8dcSSimon Schubert }
64705796c8dcSSimon Schubert
64715796c8dcSSimon Schubert if (str[k] == 'm')
64725796c8dcSSimon Schubert {
64735796c8dcSSimon Schubert if (R != NULL)
64745796c8dcSSimon Schubert *R = (-(LONGEST) (RU - 1)) - 1;
64755796c8dcSSimon Schubert k += 1;
64765796c8dcSSimon Schubert }
64775796c8dcSSimon Schubert else if (R != NULL)
64785796c8dcSSimon Schubert *R = (LONGEST) RU;
64795796c8dcSSimon Schubert
64805796c8dcSSimon Schubert /* NOTE on the above: Technically, C does not say what the results of
64815796c8dcSSimon Schubert - (LONGEST) RU or (LONGEST) -RU are for RU == largest positive
64825796c8dcSSimon Schubert number representable as a LONGEST (although either would probably work
64835796c8dcSSimon Schubert in most implementations). When RU>0, the locution in the then branch
64845796c8dcSSimon Schubert above is always equivalent to the negative of RU. */
64855796c8dcSSimon Schubert
64865796c8dcSSimon Schubert if (new_k != NULL)
64875796c8dcSSimon Schubert *new_k = k;
64885796c8dcSSimon Schubert return 1;
64895796c8dcSSimon Schubert }
64905796c8dcSSimon Schubert
64915796c8dcSSimon Schubert /* Assuming that TYPE is a variant part wrapper type (a VARIANTS field),
64925796c8dcSSimon Schubert and FIELD_NUM is a valid field number within it, returns 1 iff VAL is
64935796c8dcSSimon Schubert in the range encoded by field FIELD_NUM of TYPE; otherwise 0. */
64945796c8dcSSimon Schubert
64955796c8dcSSimon Schubert int
ada_in_variant(LONGEST val,struct type * type,int field_num)64965796c8dcSSimon Schubert ada_in_variant (LONGEST val, struct type *type, int field_num)
64975796c8dcSSimon Schubert {
64985796c8dcSSimon Schubert const char *name = TYPE_FIELD_NAME (type, field_num);
64995796c8dcSSimon Schubert int p;
65005796c8dcSSimon Schubert
65015796c8dcSSimon Schubert p = 0;
65025796c8dcSSimon Schubert while (1)
65035796c8dcSSimon Schubert {
65045796c8dcSSimon Schubert switch (name[p])
65055796c8dcSSimon Schubert {
65065796c8dcSSimon Schubert case '\0':
65075796c8dcSSimon Schubert return 0;
65085796c8dcSSimon Schubert case 'S':
65095796c8dcSSimon Schubert {
65105796c8dcSSimon Schubert LONGEST W;
6511cf7f2e2dSJohn Marino
65125796c8dcSSimon Schubert if (!ada_scan_number (name, p + 1, &W, &p))
65135796c8dcSSimon Schubert return 0;
65145796c8dcSSimon Schubert if (val == W)
65155796c8dcSSimon Schubert return 1;
65165796c8dcSSimon Schubert break;
65175796c8dcSSimon Schubert }
65185796c8dcSSimon Schubert case 'R':
65195796c8dcSSimon Schubert {
65205796c8dcSSimon Schubert LONGEST L, U;
6521cf7f2e2dSJohn Marino
65225796c8dcSSimon Schubert if (!ada_scan_number (name, p + 1, &L, &p)
65235796c8dcSSimon Schubert || name[p] != 'T' || !ada_scan_number (name, p + 1, &U, &p))
65245796c8dcSSimon Schubert return 0;
65255796c8dcSSimon Schubert if (val >= L && val <= U)
65265796c8dcSSimon Schubert return 1;
65275796c8dcSSimon Schubert break;
65285796c8dcSSimon Schubert }
65295796c8dcSSimon Schubert case 'O':
65305796c8dcSSimon Schubert return 1;
65315796c8dcSSimon Schubert default:
65325796c8dcSSimon Schubert return 0;
65335796c8dcSSimon Schubert }
65345796c8dcSSimon Schubert }
65355796c8dcSSimon Schubert }
65365796c8dcSSimon Schubert
65375796c8dcSSimon Schubert /* FIXME: Lots of redundancy below. Try to consolidate. */
65385796c8dcSSimon Schubert
65395796c8dcSSimon Schubert /* Given a value ARG1 (offset by OFFSET bytes) of a struct or union type
65405796c8dcSSimon Schubert ARG_TYPE, extract and return the value of one of its (non-static)
65415796c8dcSSimon Schubert fields. FIELDNO says which field. Differs from value_primitive_field
65425796c8dcSSimon Schubert only in that it can handle packed values of arbitrary type. */
65435796c8dcSSimon Schubert
65445796c8dcSSimon Schubert static struct value *
ada_value_primitive_field(struct value * arg1,int offset,int fieldno,struct type * arg_type)65455796c8dcSSimon Schubert ada_value_primitive_field (struct value *arg1, int offset, int fieldno,
65465796c8dcSSimon Schubert struct type *arg_type)
65475796c8dcSSimon Schubert {
65485796c8dcSSimon Schubert struct type *type;
65495796c8dcSSimon Schubert
65505796c8dcSSimon Schubert arg_type = ada_check_typedef (arg_type);
65515796c8dcSSimon Schubert type = TYPE_FIELD_TYPE (arg_type, fieldno);
65525796c8dcSSimon Schubert
65535796c8dcSSimon Schubert /* Handle packed fields. */
65545796c8dcSSimon Schubert
65555796c8dcSSimon Schubert if (TYPE_FIELD_BITSIZE (arg_type, fieldno) != 0)
65565796c8dcSSimon Schubert {
65575796c8dcSSimon Schubert int bit_pos = TYPE_FIELD_BITPOS (arg_type, fieldno);
65585796c8dcSSimon Schubert int bit_size = TYPE_FIELD_BITSIZE (arg_type, fieldno);
65595796c8dcSSimon Schubert
65605796c8dcSSimon Schubert return ada_value_primitive_packed_val (arg1, value_contents (arg1),
65615796c8dcSSimon Schubert offset + bit_pos / 8,
65625796c8dcSSimon Schubert bit_pos % 8, bit_size, type);
65635796c8dcSSimon Schubert }
65645796c8dcSSimon Schubert else
65655796c8dcSSimon Schubert return value_primitive_field (arg1, offset, fieldno, arg_type);
65665796c8dcSSimon Schubert }
65675796c8dcSSimon Schubert
65685796c8dcSSimon Schubert /* Find field with name NAME in object of type TYPE. If found,
65695796c8dcSSimon Schubert set the following for each argument that is non-null:
65705796c8dcSSimon Schubert - *FIELD_TYPE_P to the field's type;
65715796c8dcSSimon Schubert - *BYTE_OFFSET_P to OFFSET + the byte offset of the field within
65725796c8dcSSimon Schubert an object of that type;
65735796c8dcSSimon Schubert - *BIT_OFFSET_P to the bit offset modulo byte size of the field;
65745796c8dcSSimon Schubert - *BIT_SIZE_P to its size in bits if the field is packed, and
65755796c8dcSSimon Schubert 0 otherwise;
65765796c8dcSSimon Schubert If INDEX_P is non-null, increment *INDEX_P by the number of source-visible
65775796c8dcSSimon Schubert fields up to but not including the desired field, or by the total
65785796c8dcSSimon Schubert number of fields if not found. A NULL value of NAME never
65795796c8dcSSimon Schubert matches; the function just counts visible fields in this case.
65805796c8dcSSimon Schubert
65815796c8dcSSimon Schubert Returns 1 if found, 0 otherwise. */
65825796c8dcSSimon Schubert
65835796c8dcSSimon Schubert static int
find_struct_field(const char * name,struct type * type,int offset,struct type ** field_type_p,int * byte_offset_p,int * bit_offset_p,int * bit_size_p,int * index_p)6584*ef5ccd6cSJohn Marino find_struct_field (const char *name, struct type *type, int offset,
65855796c8dcSSimon Schubert struct type **field_type_p,
65865796c8dcSSimon Schubert int *byte_offset_p, int *bit_offset_p, int *bit_size_p,
65875796c8dcSSimon Schubert int *index_p)
65885796c8dcSSimon Schubert {
65895796c8dcSSimon Schubert int i;
65905796c8dcSSimon Schubert
65915796c8dcSSimon Schubert type = ada_check_typedef (type);
65925796c8dcSSimon Schubert
65935796c8dcSSimon Schubert if (field_type_p != NULL)
65945796c8dcSSimon Schubert *field_type_p = NULL;
65955796c8dcSSimon Schubert if (byte_offset_p != NULL)
65965796c8dcSSimon Schubert *byte_offset_p = 0;
65975796c8dcSSimon Schubert if (bit_offset_p != NULL)
65985796c8dcSSimon Schubert *bit_offset_p = 0;
65995796c8dcSSimon Schubert if (bit_size_p != NULL)
66005796c8dcSSimon Schubert *bit_size_p = 0;
66015796c8dcSSimon Schubert
66025796c8dcSSimon Schubert for (i = 0; i < TYPE_NFIELDS (type); i += 1)
66035796c8dcSSimon Schubert {
66045796c8dcSSimon Schubert int bit_pos = TYPE_FIELD_BITPOS (type, i);
66055796c8dcSSimon Schubert int fld_offset = offset + bit_pos / 8;
6606*ef5ccd6cSJohn Marino const char *t_field_name = TYPE_FIELD_NAME (type, i);
66075796c8dcSSimon Schubert
66085796c8dcSSimon Schubert if (t_field_name == NULL)
66095796c8dcSSimon Schubert continue;
66105796c8dcSSimon Schubert
66115796c8dcSSimon Schubert else if (name != NULL && field_name_match (t_field_name, name))
66125796c8dcSSimon Schubert {
66135796c8dcSSimon Schubert int bit_size = TYPE_FIELD_BITSIZE (type, i);
6614cf7f2e2dSJohn Marino
66155796c8dcSSimon Schubert if (field_type_p != NULL)
66165796c8dcSSimon Schubert *field_type_p = TYPE_FIELD_TYPE (type, i);
66175796c8dcSSimon Schubert if (byte_offset_p != NULL)
66185796c8dcSSimon Schubert *byte_offset_p = fld_offset;
66195796c8dcSSimon Schubert if (bit_offset_p != NULL)
66205796c8dcSSimon Schubert *bit_offset_p = bit_pos % 8;
66215796c8dcSSimon Schubert if (bit_size_p != NULL)
66225796c8dcSSimon Schubert *bit_size_p = bit_size;
66235796c8dcSSimon Schubert return 1;
66245796c8dcSSimon Schubert }
66255796c8dcSSimon Schubert else if (ada_is_wrapper_field (type, i))
66265796c8dcSSimon Schubert {
66275796c8dcSSimon Schubert if (find_struct_field (name, TYPE_FIELD_TYPE (type, i), fld_offset,
66285796c8dcSSimon Schubert field_type_p, byte_offset_p, bit_offset_p,
66295796c8dcSSimon Schubert bit_size_p, index_p))
66305796c8dcSSimon Schubert return 1;
66315796c8dcSSimon Schubert }
66325796c8dcSSimon Schubert else if (ada_is_variant_part (type, i))
66335796c8dcSSimon Schubert {
66345796c8dcSSimon Schubert /* PNH: Wait. Do we ever execute this section, or is ARG always of
66355796c8dcSSimon Schubert fixed type?? */
66365796c8dcSSimon Schubert int j;
66375796c8dcSSimon Schubert struct type *field_type
66385796c8dcSSimon Schubert = ada_check_typedef (TYPE_FIELD_TYPE (type, i));
66395796c8dcSSimon Schubert
66405796c8dcSSimon Schubert for (j = 0; j < TYPE_NFIELDS (field_type); j += 1)
66415796c8dcSSimon Schubert {
66425796c8dcSSimon Schubert if (find_struct_field (name, TYPE_FIELD_TYPE (field_type, j),
66435796c8dcSSimon Schubert fld_offset
66445796c8dcSSimon Schubert + TYPE_FIELD_BITPOS (field_type, j) / 8,
66455796c8dcSSimon Schubert field_type_p, byte_offset_p,
66465796c8dcSSimon Schubert bit_offset_p, bit_size_p, index_p))
66475796c8dcSSimon Schubert return 1;
66485796c8dcSSimon Schubert }
66495796c8dcSSimon Schubert }
66505796c8dcSSimon Schubert else if (index_p != NULL)
66515796c8dcSSimon Schubert *index_p += 1;
66525796c8dcSSimon Schubert }
66535796c8dcSSimon Schubert return 0;
66545796c8dcSSimon Schubert }
66555796c8dcSSimon Schubert
66565796c8dcSSimon Schubert /* Number of user-visible fields in record type TYPE. */
66575796c8dcSSimon Schubert
66585796c8dcSSimon Schubert static int
num_visible_fields(struct type * type)66595796c8dcSSimon Schubert num_visible_fields (struct type *type)
66605796c8dcSSimon Schubert {
66615796c8dcSSimon Schubert int n;
6662cf7f2e2dSJohn Marino
66635796c8dcSSimon Schubert n = 0;
66645796c8dcSSimon Schubert find_struct_field (NULL, type, 0, NULL, NULL, NULL, NULL, &n);
66655796c8dcSSimon Schubert return n;
66665796c8dcSSimon Schubert }
66675796c8dcSSimon Schubert
66685796c8dcSSimon Schubert /* Look for a field NAME in ARG. Adjust the address of ARG by OFFSET bytes,
66695796c8dcSSimon Schubert and search in it assuming it has (class) type TYPE.
66705796c8dcSSimon Schubert If found, return value, else return NULL.
66715796c8dcSSimon Schubert
66725796c8dcSSimon Schubert Searches recursively through wrapper fields (e.g., '_parent'). */
66735796c8dcSSimon Schubert
66745796c8dcSSimon Schubert static struct value *
ada_search_struct_field(char * name,struct value * arg,int offset,struct type * type)66755796c8dcSSimon Schubert ada_search_struct_field (char *name, struct value *arg, int offset,
66765796c8dcSSimon Schubert struct type *type)
66775796c8dcSSimon Schubert {
66785796c8dcSSimon Schubert int i;
66795796c8dcSSimon Schubert
6680cf7f2e2dSJohn Marino type = ada_check_typedef (type);
66815796c8dcSSimon Schubert for (i = 0; i < TYPE_NFIELDS (type); i += 1)
66825796c8dcSSimon Schubert {
6683*ef5ccd6cSJohn Marino const char *t_field_name = TYPE_FIELD_NAME (type, i);
66845796c8dcSSimon Schubert
66855796c8dcSSimon Schubert if (t_field_name == NULL)
66865796c8dcSSimon Schubert continue;
66875796c8dcSSimon Schubert
66885796c8dcSSimon Schubert else if (field_name_match (t_field_name, name))
66895796c8dcSSimon Schubert return ada_value_primitive_field (arg, offset, i, type);
66905796c8dcSSimon Schubert
66915796c8dcSSimon Schubert else if (ada_is_wrapper_field (type, i))
66925796c8dcSSimon Schubert {
66935796c8dcSSimon Schubert struct value *v = /* Do not let indent join lines here. */
66945796c8dcSSimon Schubert ada_search_struct_field (name, arg,
66955796c8dcSSimon Schubert offset + TYPE_FIELD_BITPOS (type, i) / 8,
66965796c8dcSSimon Schubert TYPE_FIELD_TYPE (type, i));
6697cf7f2e2dSJohn Marino
66985796c8dcSSimon Schubert if (v != NULL)
66995796c8dcSSimon Schubert return v;
67005796c8dcSSimon Schubert }
67015796c8dcSSimon Schubert
67025796c8dcSSimon Schubert else if (ada_is_variant_part (type, i))
67035796c8dcSSimon Schubert {
67045796c8dcSSimon Schubert /* PNH: Do we ever get here? See find_struct_field. */
67055796c8dcSSimon Schubert int j;
6706cf7f2e2dSJohn Marino struct type *field_type = ada_check_typedef (TYPE_FIELD_TYPE (type,
6707cf7f2e2dSJohn Marino i));
67085796c8dcSSimon Schubert int var_offset = offset + TYPE_FIELD_BITPOS (type, i) / 8;
67095796c8dcSSimon Schubert
67105796c8dcSSimon Schubert for (j = 0; j < TYPE_NFIELDS (field_type); j += 1)
67115796c8dcSSimon Schubert {
6712c50c785cSJohn Marino struct value *v = ada_search_struct_field /* Force line
6713c50c785cSJohn Marino break. */
67145796c8dcSSimon Schubert (name, arg,
67155796c8dcSSimon Schubert var_offset + TYPE_FIELD_BITPOS (field_type, j) / 8,
67165796c8dcSSimon Schubert TYPE_FIELD_TYPE (field_type, j));
6717cf7f2e2dSJohn Marino
67185796c8dcSSimon Schubert if (v != NULL)
67195796c8dcSSimon Schubert return v;
67205796c8dcSSimon Schubert }
67215796c8dcSSimon Schubert }
67225796c8dcSSimon Schubert }
67235796c8dcSSimon Schubert return NULL;
67245796c8dcSSimon Schubert }
67255796c8dcSSimon Schubert
67265796c8dcSSimon Schubert static struct value *ada_index_struct_field_1 (int *, struct value *,
67275796c8dcSSimon Schubert int, struct type *);
67285796c8dcSSimon Schubert
67295796c8dcSSimon Schubert
67305796c8dcSSimon Schubert /* Return field #INDEX in ARG, where the index is that returned by
67315796c8dcSSimon Schubert * find_struct_field through its INDEX_P argument. Adjust the address
67325796c8dcSSimon Schubert * of ARG by OFFSET bytes, and search in it assuming it has (class) type TYPE.
67335796c8dcSSimon Schubert * If found, return value, else return NULL. */
67345796c8dcSSimon Schubert
67355796c8dcSSimon Schubert static struct value *
ada_index_struct_field(int index,struct value * arg,int offset,struct type * type)67365796c8dcSSimon Schubert ada_index_struct_field (int index, struct value *arg, int offset,
67375796c8dcSSimon Schubert struct type *type)
67385796c8dcSSimon Schubert {
67395796c8dcSSimon Schubert return ada_index_struct_field_1 (&index, arg, offset, type);
67405796c8dcSSimon Schubert }
67415796c8dcSSimon Schubert
67425796c8dcSSimon Schubert
67435796c8dcSSimon Schubert /* Auxiliary function for ada_index_struct_field. Like
67445796c8dcSSimon Schubert * ada_index_struct_field, but takes index from *INDEX_P and modifies
67455796c8dcSSimon Schubert * *INDEX_P. */
67465796c8dcSSimon Schubert
67475796c8dcSSimon Schubert static struct value *
ada_index_struct_field_1(int * index_p,struct value * arg,int offset,struct type * type)67485796c8dcSSimon Schubert ada_index_struct_field_1 (int *index_p, struct value *arg, int offset,
67495796c8dcSSimon Schubert struct type *type)
67505796c8dcSSimon Schubert {
67515796c8dcSSimon Schubert int i;
67525796c8dcSSimon Schubert type = ada_check_typedef (type);
67535796c8dcSSimon Schubert
67545796c8dcSSimon Schubert for (i = 0; i < TYPE_NFIELDS (type); i += 1)
67555796c8dcSSimon Schubert {
67565796c8dcSSimon Schubert if (TYPE_FIELD_NAME (type, i) == NULL)
67575796c8dcSSimon Schubert continue;
67585796c8dcSSimon Schubert else if (ada_is_wrapper_field (type, i))
67595796c8dcSSimon Schubert {
67605796c8dcSSimon Schubert struct value *v = /* Do not let indent join lines here. */
67615796c8dcSSimon Schubert ada_index_struct_field_1 (index_p, arg,
67625796c8dcSSimon Schubert offset + TYPE_FIELD_BITPOS (type, i) / 8,
67635796c8dcSSimon Schubert TYPE_FIELD_TYPE (type, i));
6764cf7f2e2dSJohn Marino
67655796c8dcSSimon Schubert if (v != NULL)
67665796c8dcSSimon Schubert return v;
67675796c8dcSSimon Schubert }
67685796c8dcSSimon Schubert
67695796c8dcSSimon Schubert else if (ada_is_variant_part (type, i))
67705796c8dcSSimon Schubert {
67715796c8dcSSimon Schubert /* PNH: Do we ever get here? See ada_search_struct_field,
67725796c8dcSSimon Schubert find_struct_field. */
67735796c8dcSSimon Schubert error (_("Cannot assign this kind of variant record"));
67745796c8dcSSimon Schubert }
67755796c8dcSSimon Schubert else if (*index_p == 0)
67765796c8dcSSimon Schubert return ada_value_primitive_field (arg, offset, i, type);
67775796c8dcSSimon Schubert else
67785796c8dcSSimon Schubert *index_p -= 1;
67795796c8dcSSimon Schubert }
67805796c8dcSSimon Schubert return NULL;
67815796c8dcSSimon Schubert }
67825796c8dcSSimon Schubert
67835796c8dcSSimon Schubert /* Given ARG, a value of type (pointer or reference to a)*
67845796c8dcSSimon Schubert structure/union, extract the component named NAME from the ultimate
67855796c8dcSSimon Schubert target structure/union and return it as a value with its
67865796c8dcSSimon Schubert appropriate type.
67875796c8dcSSimon Schubert
67885796c8dcSSimon Schubert The routine searches for NAME among all members of the structure itself
67895796c8dcSSimon Schubert and (recursively) among all members of any wrapper members
67905796c8dcSSimon Schubert (e.g., '_parent').
67915796c8dcSSimon Schubert
67925796c8dcSSimon Schubert If NO_ERR, then simply return NULL in case of error, rather than
67935796c8dcSSimon Schubert calling error. */
67945796c8dcSSimon Schubert
67955796c8dcSSimon Schubert struct value *
ada_value_struct_elt(struct value * arg,char * name,int no_err)67965796c8dcSSimon Schubert ada_value_struct_elt (struct value *arg, char *name, int no_err)
67975796c8dcSSimon Schubert {
67985796c8dcSSimon Schubert struct type *t, *t1;
67995796c8dcSSimon Schubert struct value *v;
68005796c8dcSSimon Schubert
68015796c8dcSSimon Schubert v = NULL;
68025796c8dcSSimon Schubert t1 = t = ada_check_typedef (value_type (arg));
68035796c8dcSSimon Schubert if (TYPE_CODE (t) == TYPE_CODE_REF)
68045796c8dcSSimon Schubert {
68055796c8dcSSimon Schubert t1 = TYPE_TARGET_TYPE (t);
68065796c8dcSSimon Schubert if (t1 == NULL)
68075796c8dcSSimon Schubert goto BadValue;
68085796c8dcSSimon Schubert t1 = ada_check_typedef (t1);
68095796c8dcSSimon Schubert if (TYPE_CODE (t1) == TYPE_CODE_PTR)
68105796c8dcSSimon Schubert {
68115796c8dcSSimon Schubert arg = coerce_ref (arg);
68125796c8dcSSimon Schubert t = t1;
68135796c8dcSSimon Schubert }
68145796c8dcSSimon Schubert }
68155796c8dcSSimon Schubert
68165796c8dcSSimon Schubert while (TYPE_CODE (t) == TYPE_CODE_PTR)
68175796c8dcSSimon Schubert {
68185796c8dcSSimon Schubert t1 = TYPE_TARGET_TYPE (t);
68195796c8dcSSimon Schubert if (t1 == NULL)
68205796c8dcSSimon Schubert goto BadValue;
68215796c8dcSSimon Schubert t1 = ada_check_typedef (t1);
68225796c8dcSSimon Schubert if (TYPE_CODE (t1) == TYPE_CODE_PTR)
68235796c8dcSSimon Schubert {
68245796c8dcSSimon Schubert arg = value_ind (arg);
68255796c8dcSSimon Schubert t = t1;
68265796c8dcSSimon Schubert }
68275796c8dcSSimon Schubert else
68285796c8dcSSimon Schubert break;
68295796c8dcSSimon Schubert }
68305796c8dcSSimon Schubert
68315796c8dcSSimon Schubert if (TYPE_CODE (t1) != TYPE_CODE_STRUCT && TYPE_CODE (t1) != TYPE_CODE_UNION)
68325796c8dcSSimon Schubert goto BadValue;
68335796c8dcSSimon Schubert
68345796c8dcSSimon Schubert if (t1 == t)
68355796c8dcSSimon Schubert v = ada_search_struct_field (name, arg, 0, t);
68365796c8dcSSimon Schubert else
68375796c8dcSSimon Schubert {
68385796c8dcSSimon Schubert int bit_offset, bit_size, byte_offset;
68395796c8dcSSimon Schubert struct type *field_type;
68405796c8dcSSimon Schubert CORE_ADDR address;
68415796c8dcSSimon Schubert
68425796c8dcSSimon Schubert if (TYPE_CODE (t) == TYPE_CODE_PTR)
6843*ef5ccd6cSJohn Marino address = value_address (ada_value_ind (arg));
68445796c8dcSSimon Schubert else
6845*ef5ccd6cSJohn Marino address = value_address (ada_coerce_ref (arg));
68465796c8dcSSimon Schubert
68475796c8dcSSimon Schubert t1 = ada_to_fixed_type (ada_get_base_type (t1), NULL, address, NULL, 1);
68485796c8dcSSimon Schubert if (find_struct_field (name, t1, 0,
68495796c8dcSSimon Schubert &field_type, &byte_offset, &bit_offset,
68505796c8dcSSimon Schubert &bit_size, NULL))
68515796c8dcSSimon Schubert {
68525796c8dcSSimon Schubert if (bit_size != 0)
68535796c8dcSSimon Schubert {
68545796c8dcSSimon Schubert if (TYPE_CODE (t) == TYPE_CODE_REF)
68555796c8dcSSimon Schubert arg = ada_coerce_ref (arg);
68565796c8dcSSimon Schubert else
68575796c8dcSSimon Schubert arg = ada_value_ind (arg);
68585796c8dcSSimon Schubert v = ada_value_primitive_packed_val (arg, NULL, byte_offset,
68595796c8dcSSimon Schubert bit_offset, bit_size,
68605796c8dcSSimon Schubert field_type);
68615796c8dcSSimon Schubert }
68625796c8dcSSimon Schubert else
68635796c8dcSSimon Schubert v = value_at_lazy (field_type, address + byte_offset);
68645796c8dcSSimon Schubert }
68655796c8dcSSimon Schubert }
68665796c8dcSSimon Schubert
68675796c8dcSSimon Schubert if (v != NULL || no_err)
68685796c8dcSSimon Schubert return v;
68695796c8dcSSimon Schubert else
68705796c8dcSSimon Schubert error (_("There is no member named %s."), name);
68715796c8dcSSimon Schubert
68725796c8dcSSimon Schubert BadValue:
68735796c8dcSSimon Schubert if (no_err)
68745796c8dcSSimon Schubert return NULL;
68755796c8dcSSimon Schubert else
6876c50c785cSJohn Marino error (_("Attempt to extract a component of "
6877c50c785cSJohn Marino "a value that is not a record."));
68785796c8dcSSimon Schubert }
68795796c8dcSSimon Schubert
68805796c8dcSSimon Schubert /* Given a type TYPE, look up the type of the component of type named NAME.
68815796c8dcSSimon Schubert If DISPP is non-null, add its byte displacement from the beginning of a
68825796c8dcSSimon Schubert structure (pointed to by a value) of type TYPE to *DISPP (does not
68835796c8dcSSimon Schubert work for packed fields).
68845796c8dcSSimon Schubert
68855796c8dcSSimon Schubert Matches any field whose name has NAME as a prefix, possibly
68865796c8dcSSimon Schubert followed by "___".
68875796c8dcSSimon Schubert
68885796c8dcSSimon Schubert TYPE can be either a struct or union. If REFOK, TYPE may also
68895796c8dcSSimon Schubert be a (pointer or reference)+ to a struct or union, and the
68905796c8dcSSimon Schubert ultimate target type will be searched.
68915796c8dcSSimon Schubert
68925796c8dcSSimon Schubert Looks recursively into variant clauses and parent types.
68935796c8dcSSimon Schubert
68945796c8dcSSimon Schubert If NOERR is nonzero, return NULL if NAME is not suitably defined or
68955796c8dcSSimon Schubert TYPE is not a type of the right kind. */
68965796c8dcSSimon Schubert
68975796c8dcSSimon Schubert static struct type *
ada_lookup_struct_elt_type(struct type * type,char * name,int refok,int noerr,int * dispp)68985796c8dcSSimon Schubert ada_lookup_struct_elt_type (struct type *type, char *name, int refok,
68995796c8dcSSimon Schubert int noerr, int *dispp)
69005796c8dcSSimon Schubert {
69015796c8dcSSimon Schubert int i;
69025796c8dcSSimon Schubert
69035796c8dcSSimon Schubert if (name == NULL)
69045796c8dcSSimon Schubert goto BadName;
69055796c8dcSSimon Schubert
69065796c8dcSSimon Schubert if (refok && type != NULL)
69075796c8dcSSimon Schubert while (1)
69085796c8dcSSimon Schubert {
69095796c8dcSSimon Schubert type = ada_check_typedef (type);
69105796c8dcSSimon Schubert if (TYPE_CODE (type) != TYPE_CODE_PTR
69115796c8dcSSimon Schubert && TYPE_CODE (type) != TYPE_CODE_REF)
69125796c8dcSSimon Schubert break;
69135796c8dcSSimon Schubert type = TYPE_TARGET_TYPE (type);
69145796c8dcSSimon Schubert }
69155796c8dcSSimon Schubert
69165796c8dcSSimon Schubert if (type == NULL
69175796c8dcSSimon Schubert || (TYPE_CODE (type) != TYPE_CODE_STRUCT
69185796c8dcSSimon Schubert && TYPE_CODE (type) != TYPE_CODE_UNION))
69195796c8dcSSimon Schubert {
69205796c8dcSSimon Schubert if (noerr)
69215796c8dcSSimon Schubert return NULL;
69225796c8dcSSimon Schubert else
69235796c8dcSSimon Schubert {
69245796c8dcSSimon Schubert target_terminal_ours ();
69255796c8dcSSimon Schubert gdb_flush (gdb_stdout);
69265796c8dcSSimon Schubert if (type == NULL)
69275796c8dcSSimon Schubert error (_("Type (null) is not a structure or union type"));
69285796c8dcSSimon Schubert else
69295796c8dcSSimon Schubert {
69305796c8dcSSimon Schubert /* XXX: type_sprint */
69315796c8dcSSimon Schubert fprintf_unfiltered (gdb_stderr, _("Type "));
69325796c8dcSSimon Schubert type_print (type, "", gdb_stderr, -1);
69335796c8dcSSimon Schubert error (_(" is not a structure or union type"));
69345796c8dcSSimon Schubert }
69355796c8dcSSimon Schubert }
69365796c8dcSSimon Schubert }
69375796c8dcSSimon Schubert
69385796c8dcSSimon Schubert type = to_static_fixed_type (type);
69395796c8dcSSimon Schubert
69405796c8dcSSimon Schubert for (i = 0; i < TYPE_NFIELDS (type); i += 1)
69415796c8dcSSimon Schubert {
6942*ef5ccd6cSJohn Marino const char *t_field_name = TYPE_FIELD_NAME (type, i);
69435796c8dcSSimon Schubert struct type *t;
69445796c8dcSSimon Schubert int disp;
69455796c8dcSSimon Schubert
69465796c8dcSSimon Schubert if (t_field_name == NULL)
69475796c8dcSSimon Schubert continue;
69485796c8dcSSimon Schubert
69495796c8dcSSimon Schubert else if (field_name_match (t_field_name, name))
69505796c8dcSSimon Schubert {
69515796c8dcSSimon Schubert if (dispp != NULL)
69525796c8dcSSimon Schubert *dispp += TYPE_FIELD_BITPOS (type, i) / 8;
69535796c8dcSSimon Schubert return ada_check_typedef (TYPE_FIELD_TYPE (type, i));
69545796c8dcSSimon Schubert }
69555796c8dcSSimon Schubert
69565796c8dcSSimon Schubert else if (ada_is_wrapper_field (type, i))
69575796c8dcSSimon Schubert {
69585796c8dcSSimon Schubert disp = 0;
69595796c8dcSSimon Schubert t = ada_lookup_struct_elt_type (TYPE_FIELD_TYPE (type, i), name,
69605796c8dcSSimon Schubert 0, 1, &disp);
69615796c8dcSSimon Schubert if (t != NULL)
69625796c8dcSSimon Schubert {
69635796c8dcSSimon Schubert if (dispp != NULL)
69645796c8dcSSimon Schubert *dispp += disp + TYPE_FIELD_BITPOS (type, i) / 8;
69655796c8dcSSimon Schubert return t;
69665796c8dcSSimon Schubert }
69675796c8dcSSimon Schubert }
69685796c8dcSSimon Schubert
69695796c8dcSSimon Schubert else if (ada_is_variant_part (type, i))
69705796c8dcSSimon Schubert {
69715796c8dcSSimon Schubert int j;
6972cf7f2e2dSJohn Marino struct type *field_type = ada_check_typedef (TYPE_FIELD_TYPE (type,
6973cf7f2e2dSJohn Marino i));
69745796c8dcSSimon Schubert
69755796c8dcSSimon Schubert for (j = TYPE_NFIELDS (field_type) - 1; j >= 0; j -= 1)
69765796c8dcSSimon Schubert {
69775796c8dcSSimon Schubert /* FIXME pnh 2008/01/26: We check for a field that is
69785796c8dcSSimon Schubert NOT wrapped in a struct, since the compiler sometimes
69795796c8dcSSimon Schubert generates these for unchecked variant types. Revisit
69805796c8dcSSimon Schubert if the compiler changes this practice. */
6981*ef5ccd6cSJohn Marino const char *v_field_name = TYPE_FIELD_NAME (field_type, j);
69825796c8dcSSimon Schubert disp = 0;
69835796c8dcSSimon Schubert if (v_field_name != NULL
69845796c8dcSSimon Schubert && field_name_match (v_field_name, name))
69855796c8dcSSimon Schubert t = ada_check_typedef (TYPE_FIELD_TYPE (field_type, j));
69865796c8dcSSimon Schubert else
6987c50c785cSJohn Marino t = ada_lookup_struct_elt_type (TYPE_FIELD_TYPE (field_type,
6988c50c785cSJohn Marino j),
69895796c8dcSSimon Schubert name, 0, 1, &disp);
69905796c8dcSSimon Schubert
69915796c8dcSSimon Schubert if (t != NULL)
69925796c8dcSSimon Schubert {
69935796c8dcSSimon Schubert if (dispp != NULL)
69945796c8dcSSimon Schubert *dispp += disp + TYPE_FIELD_BITPOS (type, i) / 8;
69955796c8dcSSimon Schubert return t;
69965796c8dcSSimon Schubert }
69975796c8dcSSimon Schubert }
69985796c8dcSSimon Schubert }
69995796c8dcSSimon Schubert
70005796c8dcSSimon Schubert }
70015796c8dcSSimon Schubert
70025796c8dcSSimon Schubert BadName:
70035796c8dcSSimon Schubert if (!noerr)
70045796c8dcSSimon Schubert {
70055796c8dcSSimon Schubert target_terminal_ours ();
70065796c8dcSSimon Schubert gdb_flush (gdb_stdout);
70075796c8dcSSimon Schubert if (name == NULL)
70085796c8dcSSimon Schubert {
70095796c8dcSSimon Schubert /* XXX: type_sprint */
70105796c8dcSSimon Schubert fprintf_unfiltered (gdb_stderr, _("Type "));
70115796c8dcSSimon Schubert type_print (type, "", gdb_stderr, -1);
70125796c8dcSSimon Schubert error (_(" has no component named <null>"));
70135796c8dcSSimon Schubert }
70145796c8dcSSimon Schubert else
70155796c8dcSSimon Schubert {
70165796c8dcSSimon Schubert /* XXX: type_sprint */
70175796c8dcSSimon Schubert fprintf_unfiltered (gdb_stderr, _("Type "));
70185796c8dcSSimon Schubert type_print (type, "", gdb_stderr, -1);
70195796c8dcSSimon Schubert error (_(" has no component named %s"), name);
70205796c8dcSSimon Schubert }
70215796c8dcSSimon Schubert }
70225796c8dcSSimon Schubert
70235796c8dcSSimon Schubert return NULL;
70245796c8dcSSimon Schubert }
70255796c8dcSSimon Schubert
70265796c8dcSSimon Schubert /* Assuming that VAR_TYPE is the type of a variant part of a record (a union),
70275796c8dcSSimon Schubert within a value of type OUTER_TYPE, return true iff VAR_TYPE
70285796c8dcSSimon Schubert represents an unchecked union (that is, the variant part of a
70295796c8dcSSimon Schubert record that is named in an Unchecked_Union pragma). */
70305796c8dcSSimon Schubert
70315796c8dcSSimon Schubert static int
is_unchecked_variant(struct type * var_type,struct type * outer_type)70325796c8dcSSimon Schubert is_unchecked_variant (struct type *var_type, struct type *outer_type)
70335796c8dcSSimon Schubert {
70345796c8dcSSimon Schubert char *discrim_name = ada_variant_discrim_name (var_type);
7035cf7f2e2dSJohn Marino
70365796c8dcSSimon Schubert return (ada_lookup_struct_elt_type (outer_type, discrim_name, 0, 1, NULL)
70375796c8dcSSimon Schubert == NULL);
70385796c8dcSSimon Schubert }
70395796c8dcSSimon Schubert
70405796c8dcSSimon Schubert
70415796c8dcSSimon Schubert /* Assuming that VAR_TYPE is the type of a variant part of a record (a union),
70425796c8dcSSimon Schubert within a value of type OUTER_TYPE that is stored in GDB at
70435796c8dcSSimon Schubert OUTER_VALADDR, determine which variant clause (field number in VAR_TYPE,
70445796c8dcSSimon Schubert numbering from 0) is applicable. Returns -1 if none are. */
70455796c8dcSSimon Schubert
70465796c8dcSSimon Schubert int
ada_which_variant_applies(struct type * var_type,struct type * outer_type,const gdb_byte * outer_valaddr)70475796c8dcSSimon Schubert ada_which_variant_applies (struct type *var_type, struct type *outer_type,
70485796c8dcSSimon Schubert const gdb_byte *outer_valaddr)
70495796c8dcSSimon Schubert {
70505796c8dcSSimon Schubert int others_clause;
70515796c8dcSSimon Schubert int i;
70525796c8dcSSimon Schubert char *discrim_name = ada_variant_discrim_name (var_type);
70535796c8dcSSimon Schubert struct value *outer;
70545796c8dcSSimon Schubert struct value *discrim;
70555796c8dcSSimon Schubert LONGEST discrim_val;
70565796c8dcSSimon Schubert
70575796c8dcSSimon Schubert outer = value_from_contents_and_address (outer_type, outer_valaddr, 0);
70585796c8dcSSimon Schubert discrim = ada_value_struct_elt (outer, discrim_name, 1);
70595796c8dcSSimon Schubert if (discrim == NULL)
70605796c8dcSSimon Schubert return -1;
70615796c8dcSSimon Schubert discrim_val = value_as_long (discrim);
70625796c8dcSSimon Schubert
70635796c8dcSSimon Schubert others_clause = -1;
70645796c8dcSSimon Schubert for (i = 0; i < TYPE_NFIELDS (var_type); i += 1)
70655796c8dcSSimon Schubert {
70665796c8dcSSimon Schubert if (ada_is_others_clause (var_type, i))
70675796c8dcSSimon Schubert others_clause = i;
70685796c8dcSSimon Schubert else if (ada_in_variant (discrim_val, var_type, i))
70695796c8dcSSimon Schubert return i;
70705796c8dcSSimon Schubert }
70715796c8dcSSimon Schubert
70725796c8dcSSimon Schubert return others_clause;
70735796c8dcSSimon Schubert }
70745796c8dcSSimon Schubert
70755796c8dcSSimon Schubert
70765796c8dcSSimon Schubert
70775796c8dcSSimon Schubert /* Dynamic-Sized Records */
70785796c8dcSSimon Schubert
70795796c8dcSSimon Schubert /* Strategy: The type ostensibly attached to a value with dynamic size
70805796c8dcSSimon Schubert (i.e., a size that is not statically recorded in the debugging
70815796c8dcSSimon Schubert data) does not accurately reflect the size or layout of the value.
70825796c8dcSSimon Schubert Our strategy is to convert these values to values with accurate,
70835796c8dcSSimon Schubert conventional types that are constructed on the fly. */
70845796c8dcSSimon Schubert
70855796c8dcSSimon Schubert /* There is a subtle and tricky problem here. In general, we cannot
70865796c8dcSSimon Schubert determine the size of dynamic records without its data. However,
70875796c8dcSSimon Schubert the 'struct value' data structure, which GDB uses to represent
70885796c8dcSSimon Schubert quantities in the inferior process (the target), requires the size
70895796c8dcSSimon Schubert of the type at the time of its allocation in order to reserve space
70905796c8dcSSimon Schubert for GDB's internal copy of the data. That's why the
70915796c8dcSSimon Schubert 'to_fixed_xxx_type' routines take (target) addresses as parameters,
70925796c8dcSSimon Schubert rather than struct value*s.
70935796c8dcSSimon Schubert
70945796c8dcSSimon Schubert However, GDB's internal history variables ($1, $2, etc.) are
70955796c8dcSSimon Schubert struct value*s containing internal copies of the data that are not, in
70965796c8dcSSimon Schubert general, the same as the data at their corresponding addresses in
70975796c8dcSSimon Schubert the target. Fortunately, the types we give to these values are all
70985796c8dcSSimon Schubert conventional, fixed-size types (as per the strategy described
70995796c8dcSSimon Schubert above), so that we don't usually have to perform the
71005796c8dcSSimon Schubert 'to_fixed_xxx_type' conversions to look at their values.
71015796c8dcSSimon Schubert Unfortunately, there is one exception: if one of the internal
71025796c8dcSSimon Schubert history variables is an array whose elements are unconstrained
71035796c8dcSSimon Schubert records, then we will need to create distinct fixed types for each
71045796c8dcSSimon Schubert element selected. */
71055796c8dcSSimon Schubert
71065796c8dcSSimon Schubert /* The upshot of all of this is that many routines take a (type, host
71075796c8dcSSimon Schubert address, target address) triple as arguments to represent a value.
71085796c8dcSSimon Schubert The host address, if non-null, is supposed to contain an internal
71095796c8dcSSimon Schubert copy of the relevant data; otherwise, the program is to consult the
71105796c8dcSSimon Schubert target at the target address. */
71115796c8dcSSimon Schubert
71125796c8dcSSimon Schubert /* Assuming that VAL0 represents a pointer value, the result of
71135796c8dcSSimon Schubert dereferencing it. Differs from value_ind in its treatment of
71145796c8dcSSimon Schubert dynamic-sized types. */
71155796c8dcSSimon Schubert
71165796c8dcSSimon Schubert struct value *
ada_value_ind(struct value * val0)71175796c8dcSSimon Schubert ada_value_ind (struct value *val0)
71185796c8dcSSimon Schubert {
7119*ef5ccd6cSJohn Marino struct value *val = value_ind (val0);
7120*ef5ccd6cSJohn Marino
7121*ef5ccd6cSJohn Marino if (ada_is_tagged_type (value_type (val), 0))
7122*ef5ccd6cSJohn Marino val = ada_tag_value_at_base_address (val);
7123cf7f2e2dSJohn Marino
71245796c8dcSSimon Schubert return ada_to_fixed_value (val);
71255796c8dcSSimon Schubert }
71265796c8dcSSimon Schubert
71275796c8dcSSimon Schubert /* The value resulting from dereferencing any "reference to"
71285796c8dcSSimon Schubert qualifiers on VAL0. */
71295796c8dcSSimon Schubert
71305796c8dcSSimon Schubert static struct value *
ada_coerce_ref(struct value * val0)71315796c8dcSSimon Schubert ada_coerce_ref (struct value *val0)
71325796c8dcSSimon Schubert {
71335796c8dcSSimon Schubert if (TYPE_CODE (value_type (val0)) == TYPE_CODE_REF)
71345796c8dcSSimon Schubert {
71355796c8dcSSimon Schubert struct value *val = val0;
7136cf7f2e2dSJohn Marino
71375796c8dcSSimon Schubert val = coerce_ref (val);
7138*ef5ccd6cSJohn Marino
7139*ef5ccd6cSJohn Marino if (ada_is_tagged_type (value_type (val), 0))
7140*ef5ccd6cSJohn Marino val = ada_tag_value_at_base_address (val);
7141*ef5ccd6cSJohn Marino
71425796c8dcSSimon Schubert return ada_to_fixed_value (val);
71435796c8dcSSimon Schubert }
71445796c8dcSSimon Schubert else
71455796c8dcSSimon Schubert return val0;
71465796c8dcSSimon Schubert }
71475796c8dcSSimon Schubert
71485796c8dcSSimon Schubert /* Return OFF rounded upward if necessary to a multiple of
71495796c8dcSSimon Schubert ALIGNMENT (a power of 2). */
71505796c8dcSSimon Schubert
71515796c8dcSSimon Schubert static unsigned int
align_value(unsigned int off,unsigned int alignment)71525796c8dcSSimon Schubert align_value (unsigned int off, unsigned int alignment)
71535796c8dcSSimon Schubert {
71545796c8dcSSimon Schubert return (off + alignment - 1) & ~(alignment - 1);
71555796c8dcSSimon Schubert }
71565796c8dcSSimon Schubert
71575796c8dcSSimon Schubert /* Return the bit alignment required for field #F of template type TYPE. */
71585796c8dcSSimon Schubert
71595796c8dcSSimon Schubert static unsigned int
field_alignment(struct type * type,int f)71605796c8dcSSimon Schubert field_alignment (struct type *type, int f)
71615796c8dcSSimon Schubert {
71625796c8dcSSimon Schubert const char *name = TYPE_FIELD_NAME (type, f);
71635796c8dcSSimon Schubert int len;
71645796c8dcSSimon Schubert int align_offset;
71655796c8dcSSimon Schubert
71665796c8dcSSimon Schubert /* The field name should never be null, unless the debugging information
71675796c8dcSSimon Schubert is somehow malformed. In this case, we assume the field does not
71685796c8dcSSimon Schubert require any alignment. */
71695796c8dcSSimon Schubert if (name == NULL)
71705796c8dcSSimon Schubert return 1;
71715796c8dcSSimon Schubert
71725796c8dcSSimon Schubert len = strlen (name);
71735796c8dcSSimon Schubert
71745796c8dcSSimon Schubert if (!isdigit (name[len - 1]))
71755796c8dcSSimon Schubert return 1;
71765796c8dcSSimon Schubert
71775796c8dcSSimon Schubert if (isdigit (name[len - 2]))
71785796c8dcSSimon Schubert align_offset = len - 2;
71795796c8dcSSimon Schubert else
71805796c8dcSSimon Schubert align_offset = len - 1;
71815796c8dcSSimon Schubert
71825796c8dcSSimon Schubert if (align_offset < 7 || strncmp ("___XV", name + align_offset - 6, 5) != 0)
71835796c8dcSSimon Schubert return TARGET_CHAR_BIT;
71845796c8dcSSimon Schubert
71855796c8dcSSimon Schubert return atoi (name + align_offset) * TARGET_CHAR_BIT;
71865796c8dcSSimon Schubert }
71875796c8dcSSimon Schubert
7188*ef5ccd6cSJohn Marino /* Find a typedef or tag symbol named NAME. Ignores ambiguity. */
71895796c8dcSSimon Schubert
7190*ef5ccd6cSJohn Marino static struct symbol *
ada_find_any_type_symbol(const char * name)7191*ef5ccd6cSJohn Marino ada_find_any_type_symbol (const char *name)
71925796c8dcSSimon Schubert {
71935796c8dcSSimon Schubert struct symbol *sym;
71945796c8dcSSimon Schubert
71955796c8dcSSimon Schubert sym = standard_lookup (name, get_selected_block (NULL), VAR_DOMAIN);
71965796c8dcSSimon Schubert if (sym != NULL && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
71975796c8dcSSimon Schubert return sym;
71985796c8dcSSimon Schubert
71995796c8dcSSimon Schubert sym = standard_lookup (name, NULL, STRUCT_DOMAIN);
72005796c8dcSSimon Schubert return sym;
72015796c8dcSSimon Schubert }
72025796c8dcSSimon Schubert
72035796c8dcSSimon Schubert /* Find a type named NAME. Ignores ambiguity. This routine will look
72045796c8dcSSimon Schubert solely for types defined by debug info, it will not search the GDB
72055796c8dcSSimon Schubert primitive types. */
72065796c8dcSSimon Schubert
7207*ef5ccd6cSJohn Marino static struct type *
ada_find_any_type(const char * name)72085796c8dcSSimon Schubert ada_find_any_type (const char *name)
72095796c8dcSSimon Schubert {
7210*ef5ccd6cSJohn Marino struct symbol *sym = ada_find_any_type_symbol (name);
72115796c8dcSSimon Schubert
72125796c8dcSSimon Schubert if (sym != NULL)
72135796c8dcSSimon Schubert return SYMBOL_TYPE (sym);
72145796c8dcSSimon Schubert
72155796c8dcSSimon Schubert return NULL;
72165796c8dcSSimon Schubert }
72175796c8dcSSimon Schubert
7218*ef5ccd6cSJohn Marino /* Given NAME_SYM and an associated BLOCK, find a "renaming" symbol
7219*ef5ccd6cSJohn Marino associated with NAME_SYM's name. NAME_SYM may itself be a renaming
7220*ef5ccd6cSJohn Marino symbol, in which case it is returned. Otherwise, this looks for
7221*ef5ccd6cSJohn Marino symbols whose name is that of NAME_SYM suffixed with "___XR".
7222*ef5ccd6cSJohn Marino Return symbol if found, and NULL otherwise. */
72235796c8dcSSimon Schubert
72245796c8dcSSimon Schubert struct symbol *
ada_find_renaming_symbol(struct symbol * name_sym,const struct block * block)7225*ef5ccd6cSJohn Marino ada_find_renaming_symbol (struct symbol *name_sym, const struct block *block)
72265796c8dcSSimon Schubert {
7227*ef5ccd6cSJohn Marino const char *name = SYMBOL_LINKAGE_NAME (name_sym);
72285796c8dcSSimon Schubert struct symbol *sym;
72295796c8dcSSimon Schubert
7230*ef5ccd6cSJohn Marino if (strstr (name, "___XR") != NULL)
7231*ef5ccd6cSJohn Marino return name_sym;
7232*ef5ccd6cSJohn Marino
72335796c8dcSSimon Schubert sym = find_old_style_renaming_symbol (name, block);
72345796c8dcSSimon Schubert
72355796c8dcSSimon Schubert if (sym != NULL)
72365796c8dcSSimon Schubert return sym;
72375796c8dcSSimon Schubert
72385796c8dcSSimon Schubert /* Not right yet. FIXME pnh 7/20/2007. */
7239*ef5ccd6cSJohn Marino sym = ada_find_any_type_symbol (name);
72405796c8dcSSimon Schubert if (sym != NULL && strstr (SYMBOL_LINKAGE_NAME (sym), "___XR") != NULL)
72415796c8dcSSimon Schubert return sym;
72425796c8dcSSimon Schubert else
72435796c8dcSSimon Schubert return NULL;
72445796c8dcSSimon Schubert }
72455796c8dcSSimon Schubert
72465796c8dcSSimon Schubert static struct symbol *
find_old_style_renaming_symbol(const char * name,const struct block * block)7247*ef5ccd6cSJohn Marino find_old_style_renaming_symbol (const char *name, const struct block *block)
72485796c8dcSSimon Schubert {
72495796c8dcSSimon Schubert const struct symbol *function_sym = block_linkage_function (block);
72505796c8dcSSimon Schubert char *rename;
72515796c8dcSSimon Schubert
72525796c8dcSSimon Schubert if (function_sym != NULL)
72535796c8dcSSimon Schubert {
72545796c8dcSSimon Schubert /* If the symbol is defined inside a function, NAME is not fully
72555796c8dcSSimon Schubert qualified. This means we need to prepend the function name
72565796c8dcSSimon Schubert as well as adding the ``___XR'' suffix to build the name of
72575796c8dcSSimon Schubert the associated renaming symbol. */
7258*ef5ccd6cSJohn Marino const char *function_name = SYMBOL_LINKAGE_NAME (function_sym);
72595796c8dcSSimon Schubert /* Function names sometimes contain suffixes used
72605796c8dcSSimon Schubert for instance to qualify nested subprograms. When building
72615796c8dcSSimon Schubert the XR type name, we need to make sure that this suffix is
72625796c8dcSSimon Schubert not included. So do not include any suffix in the function
72635796c8dcSSimon Schubert name length below. */
7264cf7f2e2dSJohn Marino int function_name_len = ada_name_prefix_len (function_name);
72655796c8dcSSimon Schubert const int rename_len = function_name_len + 2 /* "__" */
72665796c8dcSSimon Schubert + strlen (name) + 6 /* "___XR\0" */ ;
72675796c8dcSSimon Schubert
72685796c8dcSSimon Schubert /* Strip the suffix if necessary. */
7269cf7f2e2dSJohn Marino ada_remove_trailing_digits (function_name, &function_name_len);
7270cf7f2e2dSJohn Marino ada_remove_po_subprogram_suffix (function_name, &function_name_len);
7271cf7f2e2dSJohn Marino ada_remove_Xbn_suffix (function_name, &function_name_len);
72725796c8dcSSimon Schubert
72735796c8dcSSimon Schubert /* Library-level functions are a special case, as GNAT adds
72745796c8dcSSimon Schubert a ``_ada_'' prefix to the function name to avoid namespace
72755796c8dcSSimon Schubert pollution. However, the renaming symbols themselves do not
72765796c8dcSSimon Schubert have this prefix, so we need to skip this prefix if present. */
72775796c8dcSSimon Schubert if (function_name_len > 5 /* "_ada_" */
72785796c8dcSSimon Schubert && strstr (function_name, "_ada_") == function_name)
7279cf7f2e2dSJohn Marino {
7280cf7f2e2dSJohn Marino function_name += 5;
7281cf7f2e2dSJohn Marino function_name_len -= 5;
7282cf7f2e2dSJohn Marino }
72835796c8dcSSimon Schubert
72845796c8dcSSimon Schubert rename = (char *) alloca (rename_len * sizeof (char));
7285cf7f2e2dSJohn Marino strncpy (rename, function_name, function_name_len);
7286cf7f2e2dSJohn Marino xsnprintf (rename + function_name_len, rename_len - function_name_len,
7287cf7f2e2dSJohn Marino "__%s___XR", name);
72885796c8dcSSimon Schubert }
72895796c8dcSSimon Schubert else
72905796c8dcSSimon Schubert {
72915796c8dcSSimon Schubert const int rename_len = strlen (name) + 6;
7292cf7f2e2dSJohn Marino
72935796c8dcSSimon Schubert rename = (char *) alloca (rename_len * sizeof (char));
72945796c8dcSSimon Schubert xsnprintf (rename, rename_len * sizeof (char), "%s___XR", name);
72955796c8dcSSimon Schubert }
72965796c8dcSSimon Schubert
7297*ef5ccd6cSJohn Marino return ada_find_any_type_symbol (rename);
72985796c8dcSSimon Schubert }
72995796c8dcSSimon Schubert
73005796c8dcSSimon Schubert /* Because of GNAT encoding conventions, several GDB symbols may match a
73015796c8dcSSimon Schubert given type name. If the type denoted by TYPE0 is to be preferred to
73025796c8dcSSimon Schubert that of TYPE1 for purposes of type printing, return non-zero;
73035796c8dcSSimon Schubert otherwise return 0. */
73045796c8dcSSimon Schubert
73055796c8dcSSimon Schubert int
ada_prefer_type(struct type * type0,struct type * type1)73065796c8dcSSimon Schubert ada_prefer_type (struct type *type0, struct type *type1)
73075796c8dcSSimon Schubert {
73085796c8dcSSimon Schubert if (type1 == NULL)
73095796c8dcSSimon Schubert return 1;
73105796c8dcSSimon Schubert else if (type0 == NULL)
73115796c8dcSSimon Schubert return 0;
73125796c8dcSSimon Schubert else if (TYPE_CODE (type1) == TYPE_CODE_VOID)
73135796c8dcSSimon Schubert return 1;
73145796c8dcSSimon Schubert else if (TYPE_CODE (type0) == TYPE_CODE_VOID)
73155796c8dcSSimon Schubert return 0;
73165796c8dcSSimon Schubert else if (TYPE_NAME (type1) == NULL && TYPE_NAME (type0) != NULL)
73175796c8dcSSimon Schubert return 1;
7318cf7f2e2dSJohn Marino else if (ada_is_constrained_packed_array_type (type0))
73195796c8dcSSimon Schubert return 1;
73205796c8dcSSimon Schubert else if (ada_is_array_descriptor_type (type0)
73215796c8dcSSimon Schubert && !ada_is_array_descriptor_type (type1))
73225796c8dcSSimon Schubert return 1;
73235796c8dcSSimon Schubert else
73245796c8dcSSimon Schubert {
73255796c8dcSSimon Schubert const char *type0_name = type_name_no_tag (type0);
73265796c8dcSSimon Schubert const char *type1_name = type_name_no_tag (type1);
73275796c8dcSSimon Schubert
73285796c8dcSSimon Schubert if (type0_name != NULL && strstr (type0_name, "___XR") != NULL
73295796c8dcSSimon Schubert && (type1_name == NULL || strstr (type1_name, "___XR") == NULL))
73305796c8dcSSimon Schubert return 1;
73315796c8dcSSimon Schubert }
73325796c8dcSSimon Schubert return 0;
73335796c8dcSSimon Schubert }
73345796c8dcSSimon Schubert
73355796c8dcSSimon Schubert /* The name of TYPE, which is either its TYPE_NAME, or, if that is
73365796c8dcSSimon Schubert null, its TYPE_TAG_NAME. Null if TYPE is null. */
73375796c8dcSSimon Schubert
7338*ef5ccd6cSJohn Marino const char *
ada_type_name(struct type * type)73395796c8dcSSimon Schubert ada_type_name (struct type *type)
73405796c8dcSSimon Schubert {
73415796c8dcSSimon Schubert if (type == NULL)
73425796c8dcSSimon Schubert return NULL;
73435796c8dcSSimon Schubert else if (TYPE_NAME (type) != NULL)
73445796c8dcSSimon Schubert return TYPE_NAME (type);
73455796c8dcSSimon Schubert else
73465796c8dcSSimon Schubert return TYPE_TAG_NAME (type);
73475796c8dcSSimon Schubert }
73485796c8dcSSimon Schubert
7349cf7f2e2dSJohn Marino /* Search the list of "descriptive" types associated to TYPE for a type
7350cf7f2e2dSJohn Marino whose name is NAME. */
7351cf7f2e2dSJohn Marino
7352cf7f2e2dSJohn Marino static struct type *
find_parallel_type_by_descriptive_type(struct type * type,const char * name)7353cf7f2e2dSJohn Marino find_parallel_type_by_descriptive_type (struct type *type, const char *name)
7354cf7f2e2dSJohn Marino {
7355cf7f2e2dSJohn Marino struct type *result;
7356cf7f2e2dSJohn Marino
7357cf7f2e2dSJohn Marino /* If there no descriptive-type info, then there is no parallel type
7358cf7f2e2dSJohn Marino to be found. */
7359cf7f2e2dSJohn Marino if (!HAVE_GNAT_AUX_INFO (type))
7360cf7f2e2dSJohn Marino return NULL;
7361cf7f2e2dSJohn Marino
7362cf7f2e2dSJohn Marino result = TYPE_DESCRIPTIVE_TYPE (type);
7363cf7f2e2dSJohn Marino while (result != NULL)
7364cf7f2e2dSJohn Marino {
7365*ef5ccd6cSJohn Marino const char *result_name = ada_type_name (result);
7366cf7f2e2dSJohn Marino
7367cf7f2e2dSJohn Marino if (result_name == NULL)
7368cf7f2e2dSJohn Marino {
7369cf7f2e2dSJohn Marino warning (_("unexpected null name on descriptive type"));
7370cf7f2e2dSJohn Marino return NULL;
7371cf7f2e2dSJohn Marino }
7372cf7f2e2dSJohn Marino
7373cf7f2e2dSJohn Marino /* If the names match, stop. */
7374cf7f2e2dSJohn Marino if (strcmp (result_name, name) == 0)
7375cf7f2e2dSJohn Marino break;
7376cf7f2e2dSJohn Marino
7377cf7f2e2dSJohn Marino /* Otherwise, look at the next item on the list, if any. */
7378cf7f2e2dSJohn Marino if (HAVE_GNAT_AUX_INFO (result))
7379cf7f2e2dSJohn Marino result = TYPE_DESCRIPTIVE_TYPE (result);
7380cf7f2e2dSJohn Marino else
7381cf7f2e2dSJohn Marino result = NULL;
7382cf7f2e2dSJohn Marino }
7383cf7f2e2dSJohn Marino
7384cf7f2e2dSJohn Marino /* If we didn't find a match, see whether this is a packed array. With
7385cf7f2e2dSJohn Marino older compilers, the descriptive type information is either absent or
7386cf7f2e2dSJohn Marino irrelevant when it comes to packed arrays so the above lookup fails.
7387cf7f2e2dSJohn Marino Fall back to using a parallel lookup by name in this case. */
7388cf7f2e2dSJohn Marino if (result == NULL && ada_is_constrained_packed_array_type (type))
7389cf7f2e2dSJohn Marino return ada_find_any_type (name);
7390cf7f2e2dSJohn Marino
7391cf7f2e2dSJohn Marino return result;
7392cf7f2e2dSJohn Marino }
7393cf7f2e2dSJohn Marino
7394cf7f2e2dSJohn Marino /* Find a parallel type to TYPE with the specified NAME, using the
7395cf7f2e2dSJohn Marino descriptive type taken from the debugging information, if available,
7396cf7f2e2dSJohn Marino and otherwise using the (slower) name-based method. */
7397cf7f2e2dSJohn Marino
7398cf7f2e2dSJohn Marino static struct type *
ada_find_parallel_type_with_name(struct type * type,const char * name)7399cf7f2e2dSJohn Marino ada_find_parallel_type_with_name (struct type *type, const char *name)
7400cf7f2e2dSJohn Marino {
7401cf7f2e2dSJohn Marino struct type *result = NULL;
7402cf7f2e2dSJohn Marino
7403cf7f2e2dSJohn Marino if (HAVE_GNAT_AUX_INFO (type))
7404cf7f2e2dSJohn Marino result = find_parallel_type_by_descriptive_type (type, name);
7405cf7f2e2dSJohn Marino else
7406cf7f2e2dSJohn Marino result = ada_find_any_type (name);
7407cf7f2e2dSJohn Marino
7408cf7f2e2dSJohn Marino return result;
7409cf7f2e2dSJohn Marino }
7410cf7f2e2dSJohn Marino
7411cf7f2e2dSJohn Marino /* Same as above, but specify the name of the parallel type by appending
74125796c8dcSSimon Schubert SUFFIX to the name of TYPE. */
74135796c8dcSSimon Schubert
74145796c8dcSSimon Schubert struct type *
ada_find_parallel_type(struct type * type,const char * suffix)74155796c8dcSSimon Schubert ada_find_parallel_type (struct type *type, const char *suffix)
74165796c8dcSSimon Schubert {
7417*ef5ccd6cSJohn Marino char *name;
7418*ef5ccd6cSJohn Marino const char *typename = ada_type_name (type);
74195796c8dcSSimon Schubert int len;
74205796c8dcSSimon Schubert
74215796c8dcSSimon Schubert if (typename == NULL)
74225796c8dcSSimon Schubert return NULL;
74235796c8dcSSimon Schubert
74245796c8dcSSimon Schubert len = strlen (typename);
74255796c8dcSSimon Schubert
7426cf7f2e2dSJohn Marino name = (char *) alloca (len + strlen (suffix) + 1);
74275796c8dcSSimon Schubert
74285796c8dcSSimon Schubert strcpy (name, typename);
74295796c8dcSSimon Schubert strcpy (name + len, suffix);
74305796c8dcSSimon Schubert
7431cf7f2e2dSJohn Marino return ada_find_parallel_type_with_name (type, name);
74325796c8dcSSimon Schubert }
74335796c8dcSSimon Schubert
74345796c8dcSSimon Schubert /* If TYPE is a variable-size record type, return the corresponding template
74355796c8dcSSimon Schubert type describing its fields. Otherwise, return NULL. */
74365796c8dcSSimon Schubert
74375796c8dcSSimon Schubert static struct type *
dynamic_template_type(struct type * type)74385796c8dcSSimon Schubert dynamic_template_type (struct type *type)
74395796c8dcSSimon Schubert {
74405796c8dcSSimon Schubert type = ada_check_typedef (type);
74415796c8dcSSimon Schubert
74425796c8dcSSimon Schubert if (type == NULL || TYPE_CODE (type) != TYPE_CODE_STRUCT
74435796c8dcSSimon Schubert || ada_type_name (type) == NULL)
74445796c8dcSSimon Schubert return NULL;
74455796c8dcSSimon Schubert else
74465796c8dcSSimon Schubert {
74475796c8dcSSimon Schubert int len = strlen (ada_type_name (type));
7448cf7f2e2dSJohn Marino
74495796c8dcSSimon Schubert if (len > 6 && strcmp (ada_type_name (type) + len - 6, "___XVE") == 0)
74505796c8dcSSimon Schubert return type;
74515796c8dcSSimon Schubert else
74525796c8dcSSimon Schubert return ada_find_parallel_type (type, "___XVE");
74535796c8dcSSimon Schubert }
74545796c8dcSSimon Schubert }
74555796c8dcSSimon Schubert
74565796c8dcSSimon Schubert /* Assuming that TEMPL_TYPE is a union or struct type, returns
74575796c8dcSSimon Schubert non-zero iff field FIELD_NUM of TEMPL_TYPE has dynamic size. */
74585796c8dcSSimon Schubert
74595796c8dcSSimon Schubert static int
is_dynamic_field(struct type * templ_type,int field_num)74605796c8dcSSimon Schubert is_dynamic_field (struct type *templ_type, int field_num)
74615796c8dcSSimon Schubert {
74625796c8dcSSimon Schubert const char *name = TYPE_FIELD_NAME (templ_type, field_num);
7463cf7f2e2dSJohn Marino
74645796c8dcSSimon Schubert return name != NULL
74655796c8dcSSimon Schubert && TYPE_CODE (TYPE_FIELD_TYPE (templ_type, field_num)) == TYPE_CODE_PTR
74665796c8dcSSimon Schubert && strstr (name, "___XVL") != NULL;
74675796c8dcSSimon Schubert }
74685796c8dcSSimon Schubert
74695796c8dcSSimon Schubert /* The index of the variant field of TYPE, or -1 if TYPE does not
74705796c8dcSSimon Schubert represent a variant record type. */
74715796c8dcSSimon Schubert
74725796c8dcSSimon Schubert static int
variant_field_index(struct type * type)74735796c8dcSSimon Schubert variant_field_index (struct type *type)
74745796c8dcSSimon Schubert {
74755796c8dcSSimon Schubert int f;
74765796c8dcSSimon Schubert
74775796c8dcSSimon Schubert if (type == NULL || TYPE_CODE (type) != TYPE_CODE_STRUCT)
74785796c8dcSSimon Schubert return -1;
74795796c8dcSSimon Schubert
74805796c8dcSSimon Schubert for (f = 0; f < TYPE_NFIELDS (type); f += 1)
74815796c8dcSSimon Schubert {
74825796c8dcSSimon Schubert if (ada_is_variant_part (type, f))
74835796c8dcSSimon Schubert return f;
74845796c8dcSSimon Schubert }
74855796c8dcSSimon Schubert return -1;
74865796c8dcSSimon Schubert }
74875796c8dcSSimon Schubert
74885796c8dcSSimon Schubert /* A record type with no fields. */
74895796c8dcSSimon Schubert
74905796c8dcSSimon Schubert static struct type *
empty_record(struct type * template)74915796c8dcSSimon Schubert empty_record (struct type *template)
74925796c8dcSSimon Schubert {
74935796c8dcSSimon Schubert struct type *type = alloc_type_copy (template);
7494cf7f2e2dSJohn Marino
74955796c8dcSSimon Schubert TYPE_CODE (type) = TYPE_CODE_STRUCT;
74965796c8dcSSimon Schubert TYPE_NFIELDS (type) = 0;
74975796c8dcSSimon Schubert TYPE_FIELDS (type) = NULL;
74985796c8dcSSimon Schubert INIT_CPLUS_SPECIFIC (type);
74995796c8dcSSimon Schubert TYPE_NAME (type) = "<empty>";
75005796c8dcSSimon Schubert TYPE_TAG_NAME (type) = NULL;
75015796c8dcSSimon Schubert TYPE_LENGTH (type) = 0;
75025796c8dcSSimon Schubert return type;
75035796c8dcSSimon Schubert }
75045796c8dcSSimon Schubert
75055796c8dcSSimon Schubert /* An ordinary record type (with fixed-length fields) that describes
75065796c8dcSSimon Schubert the value of type TYPE at VALADDR or ADDRESS (see comments at
75075796c8dcSSimon Schubert the beginning of this section) VAL according to GNAT conventions.
75085796c8dcSSimon Schubert DVAL0 should describe the (portion of a) record that contains any
75095796c8dcSSimon Schubert necessary discriminants. It should be NULL if value_type (VAL) is
75105796c8dcSSimon Schubert an outer-level type (i.e., as opposed to a branch of a variant.) A
75115796c8dcSSimon Schubert variant field (unless unchecked) is replaced by a particular branch
75125796c8dcSSimon Schubert of the variant.
75135796c8dcSSimon Schubert
75145796c8dcSSimon Schubert If not KEEP_DYNAMIC_FIELDS, then all fields whose position or
75155796c8dcSSimon Schubert length are not statically known are discarded. As a consequence,
75165796c8dcSSimon Schubert VALADDR, ADDRESS and DVAL0 are ignored.
75175796c8dcSSimon Schubert
75185796c8dcSSimon Schubert NOTE: Limitations: For now, we assume that dynamic fields and
75195796c8dcSSimon Schubert variants occupy whole numbers of bytes. However, they need not be
75205796c8dcSSimon Schubert byte-aligned. */
75215796c8dcSSimon Schubert
75225796c8dcSSimon Schubert struct type *
ada_template_to_fixed_record_type_1(struct type * type,const gdb_byte * valaddr,CORE_ADDR address,struct value * dval0,int keep_dynamic_fields)75235796c8dcSSimon Schubert ada_template_to_fixed_record_type_1 (struct type *type,
75245796c8dcSSimon Schubert const gdb_byte *valaddr,
75255796c8dcSSimon Schubert CORE_ADDR address, struct value *dval0,
75265796c8dcSSimon Schubert int keep_dynamic_fields)
75275796c8dcSSimon Schubert {
75285796c8dcSSimon Schubert struct value *mark = value_mark ();
75295796c8dcSSimon Schubert struct value *dval;
75305796c8dcSSimon Schubert struct type *rtype;
75315796c8dcSSimon Schubert int nfields, bit_len;
75325796c8dcSSimon Schubert int variant_field;
75335796c8dcSSimon Schubert long off;
7534c50c785cSJohn Marino int fld_bit_len;
75355796c8dcSSimon Schubert int f;
75365796c8dcSSimon Schubert
75375796c8dcSSimon Schubert /* Compute the number of fields in this record type that are going
75385796c8dcSSimon Schubert to be processed: unless keep_dynamic_fields, this includes only
75395796c8dcSSimon Schubert fields whose position and length are static will be processed. */
75405796c8dcSSimon Schubert if (keep_dynamic_fields)
75415796c8dcSSimon Schubert nfields = TYPE_NFIELDS (type);
75425796c8dcSSimon Schubert else
75435796c8dcSSimon Schubert {
75445796c8dcSSimon Schubert nfields = 0;
75455796c8dcSSimon Schubert while (nfields < TYPE_NFIELDS (type)
75465796c8dcSSimon Schubert && !ada_is_variant_part (type, nfields)
75475796c8dcSSimon Schubert && !is_dynamic_field (type, nfields))
75485796c8dcSSimon Schubert nfields++;
75495796c8dcSSimon Schubert }
75505796c8dcSSimon Schubert
75515796c8dcSSimon Schubert rtype = alloc_type_copy (type);
75525796c8dcSSimon Schubert TYPE_CODE (rtype) = TYPE_CODE_STRUCT;
75535796c8dcSSimon Schubert INIT_CPLUS_SPECIFIC (rtype);
75545796c8dcSSimon Schubert TYPE_NFIELDS (rtype) = nfields;
75555796c8dcSSimon Schubert TYPE_FIELDS (rtype) = (struct field *)
75565796c8dcSSimon Schubert TYPE_ALLOC (rtype, nfields * sizeof (struct field));
75575796c8dcSSimon Schubert memset (TYPE_FIELDS (rtype), 0, sizeof (struct field) * nfields);
75585796c8dcSSimon Schubert TYPE_NAME (rtype) = ada_type_name (type);
75595796c8dcSSimon Schubert TYPE_TAG_NAME (rtype) = NULL;
75605796c8dcSSimon Schubert TYPE_FIXED_INSTANCE (rtype) = 1;
75615796c8dcSSimon Schubert
75625796c8dcSSimon Schubert off = 0;
75635796c8dcSSimon Schubert bit_len = 0;
75645796c8dcSSimon Schubert variant_field = -1;
75655796c8dcSSimon Schubert
75665796c8dcSSimon Schubert for (f = 0; f < nfields; f += 1)
75675796c8dcSSimon Schubert {
75685796c8dcSSimon Schubert off = align_value (off, field_alignment (type, f))
75695796c8dcSSimon Schubert + TYPE_FIELD_BITPOS (type, f);
7570*ef5ccd6cSJohn Marino SET_FIELD_BITPOS (TYPE_FIELD (rtype, f), off);
75715796c8dcSSimon Schubert TYPE_FIELD_BITSIZE (rtype, f) = 0;
75725796c8dcSSimon Schubert
75735796c8dcSSimon Schubert if (ada_is_variant_part (type, f))
75745796c8dcSSimon Schubert {
75755796c8dcSSimon Schubert variant_field = f;
7576c50c785cSJohn Marino fld_bit_len = 0;
75775796c8dcSSimon Schubert }
75785796c8dcSSimon Schubert else if (is_dynamic_field (type, f))
75795796c8dcSSimon Schubert {
75805796c8dcSSimon Schubert const gdb_byte *field_valaddr = valaddr;
75815796c8dcSSimon Schubert CORE_ADDR field_address = address;
75825796c8dcSSimon Schubert struct type *field_type =
75835796c8dcSSimon Schubert TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, f));
75845796c8dcSSimon Schubert
75855796c8dcSSimon Schubert if (dval0 == NULL)
75865796c8dcSSimon Schubert {
75875796c8dcSSimon Schubert /* rtype's length is computed based on the run-time
75885796c8dcSSimon Schubert value of discriminants. If the discriminants are not
75895796c8dcSSimon Schubert initialized, the type size may be completely bogus and
75905796c8dcSSimon Schubert GDB may fail to allocate a value for it. So check the
75915796c8dcSSimon Schubert size first before creating the value. */
75925796c8dcSSimon Schubert check_size (rtype);
75935796c8dcSSimon Schubert dval = value_from_contents_and_address (rtype, valaddr, address);
75945796c8dcSSimon Schubert }
75955796c8dcSSimon Schubert else
75965796c8dcSSimon Schubert dval = dval0;
75975796c8dcSSimon Schubert
75985796c8dcSSimon Schubert /* If the type referenced by this field is an aligner type, we need
75995796c8dcSSimon Schubert to unwrap that aligner type, because its size might not be set.
76005796c8dcSSimon Schubert Keeping the aligner type would cause us to compute the wrong
76015796c8dcSSimon Schubert size for this field, impacting the offset of the all the fields
76025796c8dcSSimon Schubert that follow this one. */
76035796c8dcSSimon Schubert if (ada_is_aligner_type (field_type))
76045796c8dcSSimon Schubert {
76055796c8dcSSimon Schubert long field_offset = TYPE_FIELD_BITPOS (field_type, f);
76065796c8dcSSimon Schubert
76075796c8dcSSimon Schubert field_valaddr = cond_offset_host (field_valaddr, field_offset);
76085796c8dcSSimon Schubert field_address = cond_offset_target (field_address, field_offset);
76095796c8dcSSimon Schubert field_type = ada_aligned_type (field_type);
76105796c8dcSSimon Schubert }
76115796c8dcSSimon Schubert
76125796c8dcSSimon Schubert field_valaddr = cond_offset_host (field_valaddr,
76135796c8dcSSimon Schubert off / TARGET_CHAR_BIT);
76145796c8dcSSimon Schubert field_address = cond_offset_target (field_address,
76155796c8dcSSimon Schubert off / TARGET_CHAR_BIT);
76165796c8dcSSimon Schubert
76175796c8dcSSimon Schubert /* Get the fixed type of the field. Note that, in this case,
76185796c8dcSSimon Schubert we do not want to get the real type out of the tag: if
76195796c8dcSSimon Schubert the current field is the parent part of a tagged record,
76205796c8dcSSimon Schubert we will get the tag of the object. Clearly wrong: the real
76215796c8dcSSimon Schubert type of the parent is not the real type of the child. We
76225796c8dcSSimon Schubert would end up in an infinite loop. */
76235796c8dcSSimon Schubert field_type = ada_get_base_type (field_type);
76245796c8dcSSimon Schubert field_type = ada_to_fixed_type (field_type, field_valaddr,
76255796c8dcSSimon Schubert field_address, dval, 0);
7626c50c785cSJohn Marino /* If the field size is already larger than the maximum
7627c50c785cSJohn Marino object size, then the record itself will necessarily
7628c50c785cSJohn Marino be larger than the maximum object size. We need to make
7629c50c785cSJohn Marino this check now, because the size might be so ridiculously
7630c50c785cSJohn Marino large (due to an uninitialized variable in the inferior)
7631c50c785cSJohn Marino that it would cause an overflow when adding it to the
7632c50c785cSJohn Marino record size. */
7633c50c785cSJohn Marino check_size (field_type);
76345796c8dcSSimon Schubert
76355796c8dcSSimon Schubert TYPE_FIELD_TYPE (rtype, f) = field_type;
76365796c8dcSSimon Schubert TYPE_FIELD_NAME (rtype, f) = TYPE_FIELD_NAME (type, f);
7637c50c785cSJohn Marino /* The multiplication can potentially overflow. But because
7638c50c785cSJohn Marino the field length has been size-checked just above, and
7639c50c785cSJohn Marino assuming that the maximum size is a reasonable value,
7640c50c785cSJohn Marino an overflow should not happen in practice. So rather than
7641c50c785cSJohn Marino adding overflow recovery code to this already complex code,
7642c50c785cSJohn Marino we just assume that it's not going to happen. */
7643c50c785cSJohn Marino fld_bit_len =
76445796c8dcSSimon Schubert TYPE_LENGTH (TYPE_FIELD_TYPE (rtype, f)) * TARGET_CHAR_BIT;
76455796c8dcSSimon Schubert }
76465796c8dcSSimon Schubert else
76475796c8dcSSimon Schubert {
7648*ef5ccd6cSJohn Marino /* Note: If this field's type is a typedef, it is important
7649*ef5ccd6cSJohn Marino to preserve the typedef layer.
7650cf7f2e2dSJohn Marino
7651*ef5ccd6cSJohn Marino Otherwise, we might be transforming a typedef to a fat
7652*ef5ccd6cSJohn Marino pointer (encoding a pointer to an unconstrained array),
7653*ef5ccd6cSJohn Marino into a basic fat pointer (encoding an unconstrained
7654*ef5ccd6cSJohn Marino array). As both types are implemented using the same
7655*ef5ccd6cSJohn Marino structure, the typedef is the only clue which allows us
7656*ef5ccd6cSJohn Marino to distinguish between the two options. Stripping it
7657*ef5ccd6cSJohn Marino would prevent us from printing this field appropriately. */
7658*ef5ccd6cSJohn Marino TYPE_FIELD_TYPE (rtype, f) = TYPE_FIELD_TYPE (type, f);
76595796c8dcSSimon Schubert TYPE_FIELD_NAME (rtype, f) = TYPE_FIELD_NAME (type, f);
76605796c8dcSSimon Schubert if (TYPE_FIELD_BITSIZE (type, f) > 0)
7661c50c785cSJohn Marino fld_bit_len =
76625796c8dcSSimon Schubert TYPE_FIELD_BITSIZE (rtype, f) = TYPE_FIELD_BITSIZE (type, f);
76635796c8dcSSimon Schubert else
7664*ef5ccd6cSJohn Marino {
7665*ef5ccd6cSJohn Marino struct type *field_type = TYPE_FIELD_TYPE (type, f);
7666*ef5ccd6cSJohn Marino
7667*ef5ccd6cSJohn Marino /* We need to be careful of typedefs when computing
7668*ef5ccd6cSJohn Marino the length of our field. If this is a typedef,
7669*ef5ccd6cSJohn Marino get the length of the target type, not the length
7670*ef5ccd6cSJohn Marino of the typedef. */
7671*ef5ccd6cSJohn Marino if (TYPE_CODE (field_type) == TYPE_CODE_TYPEDEF)
7672*ef5ccd6cSJohn Marino field_type = ada_typedef_target_type (field_type);
7673*ef5ccd6cSJohn Marino
7674c50c785cSJohn Marino fld_bit_len =
7675cf7f2e2dSJohn Marino TYPE_LENGTH (ada_check_typedef (field_type)) * TARGET_CHAR_BIT;
76765796c8dcSSimon Schubert }
7677*ef5ccd6cSJohn Marino }
76785796c8dcSSimon Schubert if (off + fld_bit_len > bit_len)
76795796c8dcSSimon Schubert bit_len = off + fld_bit_len;
7680c50c785cSJohn Marino off += fld_bit_len;
76815796c8dcSSimon Schubert TYPE_LENGTH (rtype) =
76825796c8dcSSimon Schubert align_value (bit_len, TARGET_CHAR_BIT) / TARGET_CHAR_BIT;
76835796c8dcSSimon Schubert }
76845796c8dcSSimon Schubert
76855796c8dcSSimon Schubert /* We handle the variant part, if any, at the end because of certain
76865796c8dcSSimon Schubert odd cases in which it is re-ordered so as NOT to be the last field of
76875796c8dcSSimon Schubert the record. This can happen in the presence of representation
76885796c8dcSSimon Schubert clauses. */
76895796c8dcSSimon Schubert if (variant_field >= 0)
76905796c8dcSSimon Schubert {
76915796c8dcSSimon Schubert struct type *branch_type;
76925796c8dcSSimon Schubert
76935796c8dcSSimon Schubert off = TYPE_FIELD_BITPOS (rtype, variant_field);
76945796c8dcSSimon Schubert
76955796c8dcSSimon Schubert if (dval0 == NULL)
76965796c8dcSSimon Schubert dval = value_from_contents_and_address (rtype, valaddr, address);
76975796c8dcSSimon Schubert else
76985796c8dcSSimon Schubert dval = dval0;
76995796c8dcSSimon Schubert
77005796c8dcSSimon Schubert branch_type =
77015796c8dcSSimon Schubert to_fixed_variant_branch_type
77025796c8dcSSimon Schubert (TYPE_FIELD_TYPE (type, variant_field),
77035796c8dcSSimon Schubert cond_offset_host (valaddr, off / TARGET_CHAR_BIT),
77045796c8dcSSimon Schubert cond_offset_target (address, off / TARGET_CHAR_BIT), dval);
77055796c8dcSSimon Schubert if (branch_type == NULL)
77065796c8dcSSimon Schubert {
77075796c8dcSSimon Schubert for (f = variant_field + 1; f < TYPE_NFIELDS (rtype); f += 1)
77085796c8dcSSimon Schubert TYPE_FIELDS (rtype)[f - 1] = TYPE_FIELDS (rtype)[f];
77095796c8dcSSimon Schubert TYPE_NFIELDS (rtype) -= 1;
77105796c8dcSSimon Schubert }
77115796c8dcSSimon Schubert else
77125796c8dcSSimon Schubert {
77135796c8dcSSimon Schubert TYPE_FIELD_TYPE (rtype, variant_field) = branch_type;
77145796c8dcSSimon Schubert TYPE_FIELD_NAME (rtype, variant_field) = "S";
77155796c8dcSSimon Schubert fld_bit_len =
77165796c8dcSSimon Schubert TYPE_LENGTH (TYPE_FIELD_TYPE (rtype, variant_field)) *
77175796c8dcSSimon Schubert TARGET_CHAR_BIT;
77185796c8dcSSimon Schubert if (off + fld_bit_len > bit_len)
77195796c8dcSSimon Schubert bit_len = off + fld_bit_len;
77205796c8dcSSimon Schubert TYPE_LENGTH (rtype) =
77215796c8dcSSimon Schubert align_value (bit_len, TARGET_CHAR_BIT) / TARGET_CHAR_BIT;
77225796c8dcSSimon Schubert }
77235796c8dcSSimon Schubert }
77245796c8dcSSimon Schubert
77255796c8dcSSimon Schubert /* According to exp_dbug.ads, the size of TYPE for variable-size records
77265796c8dcSSimon Schubert should contain the alignment of that record, which should be a strictly
77275796c8dcSSimon Schubert positive value. If null or negative, then something is wrong, most
77285796c8dcSSimon Schubert probably in the debug info. In that case, we don't round up the size
77295796c8dcSSimon Schubert of the resulting type. If this record is not part of another structure,
77305796c8dcSSimon Schubert the current RTYPE length might be good enough for our purposes. */
77315796c8dcSSimon Schubert if (TYPE_LENGTH (type) <= 0)
77325796c8dcSSimon Schubert {
77335796c8dcSSimon Schubert if (TYPE_NAME (rtype))
77345796c8dcSSimon Schubert warning (_("Invalid type size for `%s' detected: %d."),
77355796c8dcSSimon Schubert TYPE_NAME (rtype), TYPE_LENGTH (type));
77365796c8dcSSimon Schubert else
77375796c8dcSSimon Schubert warning (_("Invalid type size for <unnamed> detected: %d."),
77385796c8dcSSimon Schubert TYPE_LENGTH (type));
77395796c8dcSSimon Schubert }
77405796c8dcSSimon Schubert else
77415796c8dcSSimon Schubert {
77425796c8dcSSimon Schubert TYPE_LENGTH (rtype) = align_value (TYPE_LENGTH (rtype),
77435796c8dcSSimon Schubert TYPE_LENGTH (type));
77445796c8dcSSimon Schubert }
77455796c8dcSSimon Schubert
77465796c8dcSSimon Schubert value_free_to_mark (mark);
77475796c8dcSSimon Schubert if (TYPE_LENGTH (rtype) > varsize_limit)
77485796c8dcSSimon Schubert error (_("record type with dynamic size is larger than varsize-limit"));
77495796c8dcSSimon Schubert return rtype;
77505796c8dcSSimon Schubert }
77515796c8dcSSimon Schubert
77525796c8dcSSimon Schubert /* As for ada_template_to_fixed_record_type_1 with KEEP_DYNAMIC_FIELDS
77535796c8dcSSimon Schubert of 1. */
77545796c8dcSSimon Schubert
77555796c8dcSSimon Schubert static struct type *
template_to_fixed_record_type(struct type * type,const gdb_byte * valaddr,CORE_ADDR address,struct value * dval0)77565796c8dcSSimon Schubert template_to_fixed_record_type (struct type *type, const gdb_byte *valaddr,
77575796c8dcSSimon Schubert CORE_ADDR address, struct value *dval0)
77585796c8dcSSimon Schubert {
77595796c8dcSSimon Schubert return ada_template_to_fixed_record_type_1 (type, valaddr,
77605796c8dcSSimon Schubert address, dval0, 1);
77615796c8dcSSimon Schubert }
77625796c8dcSSimon Schubert
77635796c8dcSSimon Schubert /* An ordinary record type in which ___XVL-convention fields and
77645796c8dcSSimon Schubert ___XVU- and ___XVN-convention field types in TYPE0 are replaced with
77655796c8dcSSimon Schubert static approximations, containing all possible fields. Uses
77665796c8dcSSimon Schubert no runtime values. Useless for use in values, but that's OK,
77675796c8dcSSimon Schubert since the results are used only for type determinations. Works on both
77685796c8dcSSimon Schubert structs and unions. Representation note: to save space, we memorize
77695796c8dcSSimon Schubert the result of this function in the TYPE_TARGET_TYPE of the
77705796c8dcSSimon Schubert template type. */
77715796c8dcSSimon Schubert
77725796c8dcSSimon Schubert static struct type *
template_to_static_fixed_type(struct type * type0)77735796c8dcSSimon Schubert template_to_static_fixed_type (struct type *type0)
77745796c8dcSSimon Schubert {
77755796c8dcSSimon Schubert struct type *type;
77765796c8dcSSimon Schubert int nfields;
77775796c8dcSSimon Schubert int f;
77785796c8dcSSimon Schubert
77795796c8dcSSimon Schubert if (TYPE_TARGET_TYPE (type0) != NULL)
77805796c8dcSSimon Schubert return TYPE_TARGET_TYPE (type0);
77815796c8dcSSimon Schubert
77825796c8dcSSimon Schubert nfields = TYPE_NFIELDS (type0);
77835796c8dcSSimon Schubert type = type0;
77845796c8dcSSimon Schubert
77855796c8dcSSimon Schubert for (f = 0; f < nfields; f += 1)
77865796c8dcSSimon Schubert {
77875796c8dcSSimon Schubert struct type *field_type = ada_check_typedef (TYPE_FIELD_TYPE (type0, f));
77885796c8dcSSimon Schubert struct type *new_type;
77895796c8dcSSimon Schubert
77905796c8dcSSimon Schubert if (is_dynamic_field (type0, f))
77915796c8dcSSimon Schubert new_type = to_static_fixed_type (TYPE_TARGET_TYPE (field_type));
77925796c8dcSSimon Schubert else
77935796c8dcSSimon Schubert new_type = static_unwrap_type (field_type);
77945796c8dcSSimon Schubert if (type == type0 && new_type != field_type)
77955796c8dcSSimon Schubert {
77965796c8dcSSimon Schubert TYPE_TARGET_TYPE (type0) = type = alloc_type_copy (type0);
77975796c8dcSSimon Schubert TYPE_CODE (type) = TYPE_CODE (type0);
77985796c8dcSSimon Schubert INIT_CPLUS_SPECIFIC (type);
77995796c8dcSSimon Schubert TYPE_NFIELDS (type) = nfields;
78005796c8dcSSimon Schubert TYPE_FIELDS (type) = (struct field *)
78015796c8dcSSimon Schubert TYPE_ALLOC (type, nfields * sizeof (struct field));
78025796c8dcSSimon Schubert memcpy (TYPE_FIELDS (type), TYPE_FIELDS (type0),
78035796c8dcSSimon Schubert sizeof (struct field) * nfields);
78045796c8dcSSimon Schubert TYPE_NAME (type) = ada_type_name (type0);
78055796c8dcSSimon Schubert TYPE_TAG_NAME (type) = NULL;
78065796c8dcSSimon Schubert TYPE_FIXED_INSTANCE (type) = 1;
78075796c8dcSSimon Schubert TYPE_LENGTH (type) = 0;
78085796c8dcSSimon Schubert }
78095796c8dcSSimon Schubert TYPE_FIELD_TYPE (type, f) = new_type;
78105796c8dcSSimon Schubert TYPE_FIELD_NAME (type, f) = TYPE_FIELD_NAME (type0, f);
78115796c8dcSSimon Schubert }
78125796c8dcSSimon Schubert return type;
78135796c8dcSSimon Schubert }
78145796c8dcSSimon Schubert
78155796c8dcSSimon Schubert /* Given an object of type TYPE whose contents are at VALADDR and
78165796c8dcSSimon Schubert whose address in memory is ADDRESS, returns a revision of TYPE,
78175796c8dcSSimon Schubert which should be a non-dynamic-sized record, in which the variant
78185796c8dcSSimon Schubert part, if any, is replaced with the appropriate branch. Looks
78195796c8dcSSimon Schubert for discriminant values in DVAL0, which can be NULL if the record
78205796c8dcSSimon Schubert contains the necessary discriminant values. */
78215796c8dcSSimon Schubert
78225796c8dcSSimon Schubert static struct type *
to_record_with_fixed_variant_part(struct type * type,const gdb_byte * valaddr,CORE_ADDR address,struct value * dval0)78235796c8dcSSimon Schubert to_record_with_fixed_variant_part (struct type *type, const gdb_byte *valaddr,
78245796c8dcSSimon Schubert CORE_ADDR address, struct value *dval0)
78255796c8dcSSimon Schubert {
78265796c8dcSSimon Schubert struct value *mark = value_mark ();
78275796c8dcSSimon Schubert struct value *dval;
78285796c8dcSSimon Schubert struct type *rtype;
78295796c8dcSSimon Schubert struct type *branch_type;
78305796c8dcSSimon Schubert int nfields = TYPE_NFIELDS (type);
78315796c8dcSSimon Schubert int variant_field = variant_field_index (type);
78325796c8dcSSimon Schubert
78335796c8dcSSimon Schubert if (variant_field == -1)
78345796c8dcSSimon Schubert return type;
78355796c8dcSSimon Schubert
78365796c8dcSSimon Schubert if (dval0 == NULL)
78375796c8dcSSimon Schubert dval = value_from_contents_and_address (type, valaddr, address);
78385796c8dcSSimon Schubert else
78395796c8dcSSimon Schubert dval = dval0;
78405796c8dcSSimon Schubert
78415796c8dcSSimon Schubert rtype = alloc_type_copy (type);
78425796c8dcSSimon Schubert TYPE_CODE (rtype) = TYPE_CODE_STRUCT;
78435796c8dcSSimon Schubert INIT_CPLUS_SPECIFIC (rtype);
78445796c8dcSSimon Schubert TYPE_NFIELDS (rtype) = nfields;
78455796c8dcSSimon Schubert TYPE_FIELDS (rtype) =
78465796c8dcSSimon Schubert (struct field *) TYPE_ALLOC (rtype, nfields * sizeof (struct field));
78475796c8dcSSimon Schubert memcpy (TYPE_FIELDS (rtype), TYPE_FIELDS (type),
78485796c8dcSSimon Schubert sizeof (struct field) * nfields);
78495796c8dcSSimon Schubert TYPE_NAME (rtype) = ada_type_name (type);
78505796c8dcSSimon Schubert TYPE_TAG_NAME (rtype) = NULL;
78515796c8dcSSimon Schubert TYPE_FIXED_INSTANCE (rtype) = 1;
78525796c8dcSSimon Schubert TYPE_LENGTH (rtype) = TYPE_LENGTH (type);
78535796c8dcSSimon Schubert
78545796c8dcSSimon Schubert branch_type = to_fixed_variant_branch_type
78555796c8dcSSimon Schubert (TYPE_FIELD_TYPE (type, variant_field),
78565796c8dcSSimon Schubert cond_offset_host (valaddr,
78575796c8dcSSimon Schubert TYPE_FIELD_BITPOS (type, variant_field)
78585796c8dcSSimon Schubert / TARGET_CHAR_BIT),
78595796c8dcSSimon Schubert cond_offset_target (address,
78605796c8dcSSimon Schubert TYPE_FIELD_BITPOS (type, variant_field)
78615796c8dcSSimon Schubert / TARGET_CHAR_BIT), dval);
78625796c8dcSSimon Schubert if (branch_type == NULL)
78635796c8dcSSimon Schubert {
78645796c8dcSSimon Schubert int f;
7865cf7f2e2dSJohn Marino
78665796c8dcSSimon Schubert for (f = variant_field + 1; f < nfields; f += 1)
78675796c8dcSSimon Schubert TYPE_FIELDS (rtype)[f - 1] = TYPE_FIELDS (rtype)[f];
78685796c8dcSSimon Schubert TYPE_NFIELDS (rtype) -= 1;
78695796c8dcSSimon Schubert }
78705796c8dcSSimon Schubert else
78715796c8dcSSimon Schubert {
78725796c8dcSSimon Schubert TYPE_FIELD_TYPE (rtype, variant_field) = branch_type;
78735796c8dcSSimon Schubert TYPE_FIELD_NAME (rtype, variant_field) = "S";
78745796c8dcSSimon Schubert TYPE_FIELD_BITSIZE (rtype, variant_field) = 0;
78755796c8dcSSimon Schubert TYPE_LENGTH (rtype) += TYPE_LENGTH (branch_type);
78765796c8dcSSimon Schubert }
78775796c8dcSSimon Schubert TYPE_LENGTH (rtype) -= TYPE_LENGTH (TYPE_FIELD_TYPE (type, variant_field));
78785796c8dcSSimon Schubert
78795796c8dcSSimon Schubert value_free_to_mark (mark);
78805796c8dcSSimon Schubert return rtype;
78815796c8dcSSimon Schubert }
78825796c8dcSSimon Schubert
78835796c8dcSSimon Schubert /* An ordinary record type (with fixed-length fields) that describes
78845796c8dcSSimon Schubert the value at (TYPE0, VALADDR, ADDRESS) [see explanation at
78855796c8dcSSimon Schubert beginning of this section]. Any necessary discriminants' values
78865796c8dcSSimon Schubert should be in DVAL, a record value; it may be NULL if the object
78875796c8dcSSimon Schubert at ADDR itself contains any necessary discriminant values.
78885796c8dcSSimon Schubert Additionally, VALADDR and ADDRESS may also be NULL if no discriminant
78895796c8dcSSimon Schubert values from the record are needed. Except in the case that DVAL,
78905796c8dcSSimon Schubert VALADDR, and ADDRESS are all 0 or NULL, a variant field (unless
78915796c8dcSSimon Schubert unchecked) is replaced by a particular branch of the variant.
78925796c8dcSSimon Schubert
78935796c8dcSSimon Schubert NOTE: the case in which DVAL and VALADDR are NULL and ADDRESS is 0
78945796c8dcSSimon Schubert is questionable and may be removed. It can arise during the
78955796c8dcSSimon Schubert processing of an unconstrained-array-of-record type where all the
78965796c8dcSSimon Schubert variant branches have exactly the same size. This is because in
78975796c8dcSSimon Schubert such cases, the compiler does not bother to use the XVS convention
78985796c8dcSSimon Schubert when encoding the record. I am currently dubious of this
78995796c8dcSSimon Schubert shortcut and suspect the compiler should be altered. FIXME. */
79005796c8dcSSimon Schubert
79015796c8dcSSimon Schubert static struct type *
to_fixed_record_type(struct type * type0,const gdb_byte * valaddr,CORE_ADDR address,struct value * dval)79025796c8dcSSimon Schubert to_fixed_record_type (struct type *type0, const gdb_byte *valaddr,
79035796c8dcSSimon Schubert CORE_ADDR address, struct value *dval)
79045796c8dcSSimon Schubert {
79055796c8dcSSimon Schubert struct type *templ_type;
79065796c8dcSSimon Schubert
79075796c8dcSSimon Schubert if (TYPE_FIXED_INSTANCE (type0))
79085796c8dcSSimon Schubert return type0;
79095796c8dcSSimon Schubert
79105796c8dcSSimon Schubert templ_type = dynamic_template_type (type0);
79115796c8dcSSimon Schubert
79125796c8dcSSimon Schubert if (templ_type != NULL)
79135796c8dcSSimon Schubert return template_to_fixed_record_type (templ_type, valaddr, address, dval);
79145796c8dcSSimon Schubert else if (variant_field_index (type0) >= 0)
79155796c8dcSSimon Schubert {
79165796c8dcSSimon Schubert if (dval == NULL && valaddr == NULL && address == 0)
79175796c8dcSSimon Schubert return type0;
79185796c8dcSSimon Schubert return to_record_with_fixed_variant_part (type0, valaddr, address,
79195796c8dcSSimon Schubert dval);
79205796c8dcSSimon Schubert }
79215796c8dcSSimon Schubert else
79225796c8dcSSimon Schubert {
79235796c8dcSSimon Schubert TYPE_FIXED_INSTANCE (type0) = 1;
79245796c8dcSSimon Schubert return type0;
79255796c8dcSSimon Schubert }
79265796c8dcSSimon Schubert
79275796c8dcSSimon Schubert }
79285796c8dcSSimon Schubert
79295796c8dcSSimon Schubert /* An ordinary record type (with fixed-length fields) that describes
79305796c8dcSSimon Schubert the value at (VAR_TYPE0, VALADDR, ADDRESS), where VAR_TYPE0 is a
79315796c8dcSSimon Schubert union type. Any necessary discriminants' values should be in DVAL,
79325796c8dcSSimon Schubert a record value. That is, this routine selects the appropriate
79335796c8dcSSimon Schubert branch of the union at ADDR according to the discriminant value
79345796c8dcSSimon Schubert indicated in the union's type name. Returns VAR_TYPE0 itself if
79355796c8dcSSimon Schubert it represents a variant subject to a pragma Unchecked_Union. */
79365796c8dcSSimon Schubert
79375796c8dcSSimon Schubert static struct type *
to_fixed_variant_branch_type(struct type * var_type0,const gdb_byte * valaddr,CORE_ADDR address,struct value * dval)79385796c8dcSSimon Schubert to_fixed_variant_branch_type (struct type *var_type0, const gdb_byte *valaddr,
79395796c8dcSSimon Schubert CORE_ADDR address, struct value *dval)
79405796c8dcSSimon Schubert {
79415796c8dcSSimon Schubert int which;
79425796c8dcSSimon Schubert struct type *templ_type;
79435796c8dcSSimon Schubert struct type *var_type;
79445796c8dcSSimon Schubert
79455796c8dcSSimon Schubert if (TYPE_CODE (var_type0) == TYPE_CODE_PTR)
79465796c8dcSSimon Schubert var_type = TYPE_TARGET_TYPE (var_type0);
79475796c8dcSSimon Schubert else
79485796c8dcSSimon Schubert var_type = var_type0;
79495796c8dcSSimon Schubert
79505796c8dcSSimon Schubert templ_type = ada_find_parallel_type (var_type, "___XVU");
79515796c8dcSSimon Schubert
79525796c8dcSSimon Schubert if (templ_type != NULL)
79535796c8dcSSimon Schubert var_type = templ_type;
79545796c8dcSSimon Schubert
79555796c8dcSSimon Schubert if (is_unchecked_variant (var_type, value_type (dval)))
79565796c8dcSSimon Schubert return var_type0;
79575796c8dcSSimon Schubert which =
79585796c8dcSSimon Schubert ada_which_variant_applies (var_type,
79595796c8dcSSimon Schubert value_type (dval), value_contents (dval));
79605796c8dcSSimon Schubert
79615796c8dcSSimon Schubert if (which < 0)
79625796c8dcSSimon Schubert return empty_record (var_type);
79635796c8dcSSimon Schubert else if (is_dynamic_field (var_type, which))
79645796c8dcSSimon Schubert return to_fixed_record_type
79655796c8dcSSimon Schubert (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (var_type, which)),
79665796c8dcSSimon Schubert valaddr, address, dval);
79675796c8dcSSimon Schubert else if (variant_field_index (TYPE_FIELD_TYPE (var_type, which)) >= 0)
79685796c8dcSSimon Schubert return
79695796c8dcSSimon Schubert to_fixed_record_type
79705796c8dcSSimon Schubert (TYPE_FIELD_TYPE (var_type, which), valaddr, address, dval);
79715796c8dcSSimon Schubert else
79725796c8dcSSimon Schubert return TYPE_FIELD_TYPE (var_type, which);
79735796c8dcSSimon Schubert }
79745796c8dcSSimon Schubert
79755796c8dcSSimon Schubert /* Assuming that TYPE0 is an array type describing the type of a value
79765796c8dcSSimon Schubert at ADDR, and that DVAL describes a record containing any
79775796c8dcSSimon Schubert discriminants used in TYPE0, returns a type for the value that
79785796c8dcSSimon Schubert contains no dynamic components (that is, no components whose sizes
79795796c8dcSSimon Schubert are determined by run-time quantities). Unless IGNORE_TOO_BIG is
79805796c8dcSSimon Schubert true, gives an error message if the resulting type's size is over
79815796c8dcSSimon Schubert varsize_limit. */
79825796c8dcSSimon Schubert
79835796c8dcSSimon Schubert static struct type *
to_fixed_array_type(struct type * type0,struct value * dval,int ignore_too_big)79845796c8dcSSimon Schubert to_fixed_array_type (struct type *type0, struct value *dval,
79855796c8dcSSimon Schubert int ignore_too_big)
79865796c8dcSSimon Schubert {
79875796c8dcSSimon Schubert struct type *index_type_desc;
79885796c8dcSSimon Schubert struct type *result;
7989cf7f2e2dSJohn Marino int constrained_packed_array_p;
79905796c8dcSSimon Schubert
7991c50c785cSJohn Marino type0 = ada_check_typedef (type0);
79925796c8dcSSimon Schubert if (TYPE_FIXED_INSTANCE (type0))
79935796c8dcSSimon Schubert return type0;
79945796c8dcSSimon Schubert
7995cf7f2e2dSJohn Marino constrained_packed_array_p = ada_is_constrained_packed_array_type (type0);
7996cf7f2e2dSJohn Marino if (constrained_packed_array_p)
7997cf7f2e2dSJohn Marino type0 = decode_constrained_packed_array_type (type0);
79985796c8dcSSimon Schubert
79995796c8dcSSimon Schubert index_type_desc = ada_find_parallel_type (type0, "___XA");
8000cf7f2e2dSJohn Marino ada_fixup_array_indexes_type (index_type_desc);
80015796c8dcSSimon Schubert if (index_type_desc == NULL)
80025796c8dcSSimon Schubert {
80035796c8dcSSimon Schubert struct type *elt_type0 = ada_check_typedef (TYPE_TARGET_TYPE (type0));
8004cf7f2e2dSJohn Marino
80055796c8dcSSimon Schubert /* NOTE: elt_type---the fixed version of elt_type0---should never
80065796c8dcSSimon Schubert depend on the contents of the array in properly constructed
80075796c8dcSSimon Schubert debugging data. */
80085796c8dcSSimon Schubert /* Create a fixed version of the array element type.
80095796c8dcSSimon Schubert We're not providing the address of an element here,
80105796c8dcSSimon Schubert and thus the actual object value cannot be inspected to do
80115796c8dcSSimon Schubert the conversion. This should not be a problem, since arrays of
80125796c8dcSSimon Schubert unconstrained objects are not allowed. In particular, all
80135796c8dcSSimon Schubert the elements of an array of a tagged type should all be of
80145796c8dcSSimon Schubert the same type specified in the debugging info. No need to
80155796c8dcSSimon Schubert consult the object tag. */
80165796c8dcSSimon Schubert struct type *elt_type = ada_to_fixed_type (elt_type0, 0, 0, dval, 1);
80175796c8dcSSimon Schubert
80185796c8dcSSimon Schubert /* Make sure we always create a new array type when dealing with
80195796c8dcSSimon Schubert packed array types, since we're going to fix-up the array
80205796c8dcSSimon Schubert type length and element bitsize a little further down. */
8021cf7f2e2dSJohn Marino if (elt_type0 == elt_type && !constrained_packed_array_p)
80225796c8dcSSimon Schubert result = type0;
80235796c8dcSSimon Schubert else
80245796c8dcSSimon Schubert result = create_array_type (alloc_type_copy (type0),
80255796c8dcSSimon Schubert elt_type, TYPE_INDEX_TYPE (type0));
80265796c8dcSSimon Schubert }
80275796c8dcSSimon Schubert else
80285796c8dcSSimon Schubert {
80295796c8dcSSimon Schubert int i;
80305796c8dcSSimon Schubert struct type *elt_type0;
80315796c8dcSSimon Schubert
80325796c8dcSSimon Schubert elt_type0 = type0;
80335796c8dcSSimon Schubert for (i = TYPE_NFIELDS (index_type_desc); i > 0; i -= 1)
80345796c8dcSSimon Schubert elt_type0 = TYPE_TARGET_TYPE (elt_type0);
80355796c8dcSSimon Schubert
80365796c8dcSSimon Schubert /* NOTE: result---the fixed version of elt_type0---should never
80375796c8dcSSimon Schubert depend on the contents of the array in properly constructed
80385796c8dcSSimon Schubert debugging data. */
80395796c8dcSSimon Schubert /* Create a fixed version of the array element type.
80405796c8dcSSimon Schubert We're not providing the address of an element here,
80415796c8dcSSimon Schubert and thus the actual object value cannot be inspected to do
80425796c8dcSSimon Schubert the conversion. This should not be a problem, since arrays of
80435796c8dcSSimon Schubert unconstrained objects are not allowed. In particular, all
80445796c8dcSSimon Schubert the elements of an array of a tagged type should all be of
80455796c8dcSSimon Schubert the same type specified in the debugging info. No need to
80465796c8dcSSimon Schubert consult the object tag. */
80475796c8dcSSimon Schubert result =
80485796c8dcSSimon Schubert ada_to_fixed_type (ada_check_typedef (elt_type0), 0, 0, dval, 1);
80495796c8dcSSimon Schubert
80505796c8dcSSimon Schubert elt_type0 = type0;
80515796c8dcSSimon Schubert for (i = TYPE_NFIELDS (index_type_desc) - 1; i >= 0; i -= 1)
80525796c8dcSSimon Schubert {
80535796c8dcSSimon Schubert struct type *range_type =
8054cf7f2e2dSJohn Marino to_fixed_range_type (TYPE_FIELD_TYPE (index_type_desc, i), dval);
8055cf7f2e2dSJohn Marino
80565796c8dcSSimon Schubert result = create_array_type (alloc_type_copy (elt_type0),
80575796c8dcSSimon Schubert result, range_type);
80585796c8dcSSimon Schubert elt_type0 = TYPE_TARGET_TYPE (elt_type0);
80595796c8dcSSimon Schubert }
80605796c8dcSSimon Schubert if (!ignore_too_big && TYPE_LENGTH (result) > varsize_limit)
80615796c8dcSSimon Schubert error (_("array type with dynamic size is larger than varsize-limit"));
80625796c8dcSSimon Schubert }
80635796c8dcSSimon Schubert
8064*ef5ccd6cSJohn Marino /* We want to preserve the type name. This can be useful when
8065*ef5ccd6cSJohn Marino trying to get the type name of a value that has already been
8066*ef5ccd6cSJohn Marino printed (for instance, if the user did "print VAR; whatis $". */
8067*ef5ccd6cSJohn Marino TYPE_NAME (result) = TYPE_NAME (type0);
8068*ef5ccd6cSJohn Marino
8069cf7f2e2dSJohn Marino if (constrained_packed_array_p)
80705796c8dcSSimon Schubert {
80715796c8dcSSimon Schubert /* So far, the resulting type has been created as if the original
80725796c8dcSSimon Schubert type was a regular (non-packed) array type. As a result, the
80735796c8dcSSimon Schubert bitsize of the array elements needs to be set again, and the array
80745796c8dcSSimon Schubert length needs to be recomputed based on that bitsize. */
80755796c8dcSSimon Schubert int len = TYPE_LENGTH (result) / TYPE_LENGTH (TYPE_TARGET_TYPE (result));
80765796c8dcSSimon Schubert int elt_bitsize = TYPE_FIELD_BITSIZE (type0, 0);
80775796c8dcSSimon Schubert
80785796c8dcSSimon Schubert TYPE_FIELD_BITSIZE (result, 0) = TYPE_FIELD_BITSIZE (type0, 0);
80795796c8dcSSimon Schubert TYPE_LENGTH (result) = len * elt_bitsize / HOST_CHAR_BIT;
80805796c8dcSSimon Schubert if (TYPE_LENGTH (result) * HOST_CHAR_BIT < len * elt_bitsize)
80815796c8dcSSimon Schubert TYPE_LENGTH (result)++;
80825796c8dcSSimon Schubert }
80835796c8dcSSimon Schubert
80845796c8dcSSimon Schubert TYPE_FIXED_INSTANCE (result) = 1;
80855796c8dcSSimon Schubert return result;
80865796c8dcSSimon Schubert }
80875796c8dcSSimon Schubert
80885796c8dcSSimon Schubert
80895796c8dcSSimon Schubert /* A standard type (containing no dynamically sized components)
80905796c8dcSSimon Schubert corresponding to TYPE for the value (TYPE, VALADDR, ADDRESS)
80915796c8dcSSimon Schubert DVAL describes a record containing any discriminants used in TYPE0,
80925796c8dcSSimon Schubert and may be NULL if there are none, or if the object of type TYPE at
80935796c8dcSSimon Schubert ADDRESS or in VALADDR contains these discriminants.
80945796c8dcSSimon Schubert
80955796c8dcSSimon Schubert If CHECK_TAG is not null, in the case of tagged types, this function
80965796c8dcSSimon Schubert attempts to locate the object's tag and use it to compute the actual
80975796c8dcSSimon Schubert type. However, when ADDRESS is null, we cannot use it to determine the
80985796c8dcSSimon Schubert location of the tag, and therefore compute the tagged type's actual type.
80995796c8dcSSimon Schubert So we return the tagged type without consulting the tag. */
81005796c8dcSSimon Schubert
81015796c8dcSSimon Schubert static struct type *
ada_to_fixed_type_1(struct type * type,const gdb_byte * valaddr,CORE_ADDR address,struct value * dval,int check_tag)81025796c8dcSSimon Schubert ada_to_fixed_type_1 (struct type *type, const gdb_byte *valaddr,
81035796c8dcSSimon Schubert CORE_ADDR address, struct value *dval, int check_tag)
81045796c8dcSSimon Schubert {
81055796c8dcSSimon Schubert type = ada_check_typedef (type);
81065796c8dcSSimon Schubert switch (TYPE_CODE (type))
81075796c8dcSSimon Schubert {
81085796c8dcSSimon Schubert default:
81095796c8dcSSimon Schubert return type;
81105796c8dcSSimon Schubert case TYPE_CODE_STRUCT:
81115796c8dcSSimon Schubert {
81125796c8dcSSimon Schubert struct type *static_type = to_static_fixed_type (type);
81135796c8dcSSimon Schubert struct type *fixed_record_type =
81145796c8dcSSimon Schubert to_fixed_record_type (type, valaddr, address, NULL);
8115cf7f2e2dSJohn Marino
81165796c8dcSSimon Schubert /* If STATIC_TYPE is a tagged type and we know the object's address,
81175796c8dcSSimon Schubert then we can determine its tag, and compute the object's actual
81185796c8dcSSimon Schubert type from there. Note that we have to use the fixed record
81195796c8dcSSimon Schubert type (the parent part of the record may have dynamic fields
81205796c8dcSSimon Schubert and the way the location of _tag is expressed may depend on
81215796c8dcSSimon Schubert them). */
81225796c8dcSSimon Schubert
81235796c8dcSSimon Schubert if (check_tag && address != 0 && ada_is_tagged_type (static_type, 0))
81245796c8dcSSimon Schubert {
8125*ef5ccd6cSJohn Marino struct value *tag =
8126*ef5ccd6cSJohn Marino value_tag_from_contents_and_address
81275796c8dcSSimon Schubert (fixed_record_type,
81285796c8dcSSimon Schubert valaddr,
8129*ef5ccd6cSJohn Marino address);
8130*ef5ccd6cSJohn Marino struct type *real_type = type_from_tag (tag);
8131*ef5ccd6cSJohn Marino struct value *obj =
8132*ef5ccd6cSJohn Marino value_from_contents_and_address (fixed_record_type,
8133*ef5ccd6cSJohn Marino valaddr,
8134*ef5ccd6cSJohn Marino address);
81355796c8dcSSimon Schubert if (real_type != NULL)
8136*ef5ccd6cSJohn Marino return to_fixed_record_type
8137*ef5ccd6cSJohn Marino (real_type, NULL,
8138*ef5ccd6cSJohn Marino value_address (ada_tag_value_at_base_address (obj)), NULL);
81395796c8dcSSimon Schubert }
81405796c8dcSSimon Schubert
81415796c8dcSSimon Schubert /* Check to see if there is a parallel ___XVZ variable.
81425796c8dcSSimon Schubert If there is, then it provides the actual size of our type. */
81435796c8dcSSimon Schubert else if (ada_type_name (fixed_record_type) != NULL)
81445796c8dcSSimon Schubert {
8145*ef5ccd6cSJohn Marino const char *name = ada_type_name (fixed_record_type);
81465796c8dcSSimon Schubert char *xvz_name = alloca (strlen (name) + 7 /* "___XVZ\0" */);
81475796c8dcSSimon Schubert int xvz_found = 0;
81485796c8dcSSimon Schubert LONGEST size;
81495796c8dcSSimon Schubert
81505796c8dcSSimon Schubert xsnprintf (xvz_name, strlen (name) + 7, "%s___XVZ", name);
81515796c8dcSSimon Schubert size = get_int_var_value (xvz_name, &xvz_found);
81525796c8dcSSimon Schubert if (xvz_found && TYPE_LENGTH (fixed_record_type) != size)
81535796c8dcSSimon Schubert {
81545796c8dcSSimon Schubert fixed_record_type = copy_type (fixed_record_type);
81555796c8dcSSimon Schubert TYPE_LENGTH (fixed_record_type) = size;
81565796c8dcSSimon Schubert
81575796c8dcSSimon Schubert /* The FIXED_RECORD_TYPE may have be a stub. We have
81585796c8dcSSimon Schubert observed this when the debugging info is STABS, and
81595796c8dcSSimon Schubert apparently it is something that is hard to fix.
81605796c8dcSSimon Schubert
81615796c8dcSSimon Schubert In practice, we don't need the actual type definition
81625796c8dcSSimon Schubert at all, because the presence of the XVZ variable allows us
81635796c8dcSSimon Schubert to assume that there must be a XVS type as well, which we
81645796c8dcSSimon Schubert should be able to use later, when we need the actual type
81655796c8dcSSimon Schubert definition.
81665796c8dcSSimon Schubert
81675796c8dcSSimon Schubert In the meantime, pretend that the "fixed" type we are
81685796c8dcSSimon Schubert returning is NOT a stub, because this can cause trouble
81695796c8dcSSimon Schubert when using this type to create new types targeting it.
81705796c8dcSSimon Schubert Indeed, the associated creation routines often check
81715796c8dcSSimon Schubert whether the target type is a stub and will try to replace
81725796c8dcSSimon Schubert it, thus using a type with the wrong size. This, in turn,
81735796c8dcSSimon Schubert might cause the new type to have the wrong size too.
81745796c8dcSSimon Schubert Consider the case of an array, for instance, where the size
81755796c8dcSSimon Schubert of the array is computed from the number of elements in
81765796c8dcSSimon Schubert our array multiplied by the size of its element. */
81775796c8dcSSimon Schubert TYPE_STUB (fixed_record_type) = 0;
81785796c8dcSSimon Schubert }
81795796c8dcSSimon Schubert }
81805796c8dcSSimon Schubert return fixed_record_type;
81815796c8dcSSimon Schubert }
81825796c8dcSSimon Schubert case TYPE_CODE_ARRAY:
81835796c8dcSSimon Schubert return to_fixed_array_type (type, dval, 1);
81845796c8dcSSimon Schubert case TYPE_CODE_UNION:
81855796c8dcSSimon Schubert if (dval == NULL)
81865796c8dcSSimon Schubert return type;
81875796c8dcSSimon Schubert else
81885796c8dcSSimon Schubert return to_fixed_variant_branch_type (type, valaddr, address, dval);
81895796c8dcSSimon Schubert }
81905796c8dcSSimon Schubert }
81915796c8dcSSimon Schubert
81925796c8dcSSimon Schubert /* The same as ada_to_fixed_type_1, except that it preserves the type
81935796c8dcSSimon Schubert if it is a TYPE_CODE_TYPEDEF of a type that is already fixed.
8194c50c785cSJohn Marino
8195c50c785cSJohn Marino The typedef layer needs be preserved in order to differentiate between
8196c50c785cSJohn Marino arrays and array pointers when both types are implemented using the same
8197c50c785cSJohn Marino fat pointer. In the array pointer case, the pointer is encoded as
8198c50c785cSJohn Marino a typedef of the pointer type. For instance, considering:
8199c50c785cSJohn Marino
8200c50c785cSJohn Marino type String_Access is access String;
8201c50c785cSJohn Marino S1 : String_Access := null;
8202c50c785cSJohn Marino
8203c50c785cSJohn Marino To the debugger, S1 is defined as a typedef of type String. But
8204c50c785cSJohn Marino to the user, it is a pointer. So if the user tries to print S1,
8205c50c785cSJohn Marino we should not dereference the array, but print the array address
8206c50c785cSJohn Marino instead.
8207c50c785cSJohn Marino
8208c50c785cSJohn Marino If we didn't preserve the typedef layer, we would lose the fact that
8209c50c785cSJohn Marino the type is to be presented as a pointer (needs de-reference before
8210c50c785cSJohn Marino being printed). And we would also use the source-level type name. */
82115796c8dcSSimon Schubert
82125796c8dcSSimon Schubert struct type *
ada_to_fixed_type(struct type * type,const gdb_byte * valaddr,CORE_ADDR address,struct value * dval,int check_tag)82135796c8dcSSimon Schubert ada_to_fixed_type (struct type *type, const gdb_byte *valaddr,
82145796c8dcSSimon Schubert CORE_ADDR address, struct value *dval, int check_tag)
82155796c8dcSSimon Schubert
82165796c8dcSSimon Schubert {
82175796c8dcSSimon Schubert struct type *fixed_type =
82185796c8dcSSimon Schubert ada_to_fixed_type_1 (type, valaddr, address, dval, check_tag);
82195796c8dcSSimon Schubert
8220c50c785cSJohn Marino /* If TYPE is a typedef and its target type is the same as the FIXED_TYPE,
8221c50c785cSJohn Marino then preserve the typedef layer.
8222c50c785cSJohn Marino
8223c50c785cSJohn Marino Implementation note: We can only check the main-type portion of
8224c50c785cSJohn Marino the TYPE and FIXED_TYPE, because eliminating the typedef layer
8225c50c785cSJohn Marino from TYPE now returns a type that has the same instance flags
8226c50c785cSJohn Marino as TYPE. For instance, if TYPE is a "typedef const", and its
8227c50c785cSJohn Marino target type is a "struct", then the typedef elimination will return
8228c50c785cSJohn Marino a "const" version of the target type. See check_typedef for more
8229c50c785cSJohn Marino details about how the typedef layer elimination is done.
8230c50c785cSJohn Marino
8231c50c785cSJohn Marino brobecker/2010-11-19: It seems to me that the only case where it is
8232c50c785cSJohn Marino useful to preserve the typedef layer is when dealing with fat pointers.
8233c50c785cSJohn Marino Perhaps, we could add a check for that and preserve the typedef layer
8234c50c785cSJohn Marino only in that situation. But this seems unecessary so far, probably
8235c50c785cSJohn Marino because we call check_typedef/ada_check_typedef pretty much everywhere.
8236c50c785cSJohn Marino */
82375796c8dcSSimon Schubert if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF
8238c50c785cSJohn Marino && (TYPE_MAIN_TYPE (ada_typedef_target_type (type))
8239c50c785cSJohn Marino == TYPE_MAIN_TYPE (fixed_type)))
82405796c8dcSSimon Schubert return type;
82415796c8dcSSimon Schubert
82425796c8dcSSimon Schubert return fixed_type;
82435796c8dcSSimon Schubert }
82445796c8dcSSimon Schubert
82455796c8dcSSimon Schubert /* A standard (static-sized) type corresponding as well as possible to
82465796c8dcSSimon Schubert TYPE0, but based on no runtime data. */
82475796c8dcSSimon Schubert
82485796c8dcSSimon Schubert static struct type *
to_static_fixed_type(struct type * type0)82495796c8dcSSimon Schubert to_static_fixed_type (struct type *type0)
82505796c8dcSSimon Schubert {
82515796c8dcSSimon Schubert struct type *type;
82525796c8dcSSimon Schubert
82535796c8dcSSimon Schubert if (type0 == NULL)
82545796c8dcSSimon Schubert return NULL;
82555796c8dcSSimon Schubert
82565796c8dcSSimon Schubert if (TYPE_FIXED_INSTANCE (type0))
82575796c8dcSSimon Schubert return type0;
82585796c8dcSSimon Schubert
82595796c8dcSSimon Schubert type0 = ada_check_typedef (type0);
82605796c8dcSSimon Schubert
82615796c8dcSSimon Schubert switch (TYPE_CODE (type0))
82625796c8dcSSimon Schubert {
82635796c8dcSSimon Schubert default:
82645796c8dcSSimon Schubert return type0;
82655796c8dcSSimon Schubert case TYPE_CODE_STRUCT:
82665796c8dcSSimon Schubert type = dynamic_template_type (type0);
82675796c8dcSSimon Schubert if (type != NULL)
82685796c8dcSSimon Schubert return template_to_static_fixed_type (type);
82695796c8dcSSimon Schubert else
82705796c8dcSSimon Schubert return template_to_static_fixed_type (type0);
82715796c8dcSSimon Schubert case TYPE_CODE_UNION:
82725796c8dcSSimon Schubert type = ada_find_parallel_type (type0, "___XVU");
82735796c8dcSSimon Schubert if (type != NULL)
82745796c8dcSSimon Schubert return template_to_static_fixed_type (type);
82755796c8dcSSimon Schubert else
82765796c8dcSSimon Schubert return template_to_static_fixed_type (type0);
82775796c8dcSSimon Schubert }
82785796c8dcSSimon Schubert }
82795796c8dcSSimon Schubert
82805796c8dcSSimon Schubert /* A static approximation of TYPE with all type wrappers removed. */
82815796c8dcSSimon Schubert
82825796c8dcSSimon Schubert static struct type *
static_unwrap_type(struct type * type)82835796c8dcSSimon Schubert static_unwrap_type (struct type *type)
82845796c8dcSSimon Schubert {
82855796c8dcSSimon Schubert if (ada_is_aligner_type (type))
82865796c8dcSSimon Schubert {
82875796c8dcSSimon Schubert struct type *type1 = TYPE_FIELD_TYPE (ada_check_typedef (type), 0);
82885796c8dcSSimon Schubert if (ada_type_name (type1) == NULL)
82895796c8dcSSimon Schubert TYPE_NAME (type1) = ada_type_name (type);
82905796c8dcSSimon Schubert
82915796c8dcSSimon Schubert return static_unwrap_type (type1);
82925796c8dcSSimon Schubert }
82935796c8dcSSimon Schubert else
82945796c8dcSSimon Schubert {
82955796c8dcSSimon Schubert struct type *raw_real_type = ada_get_base_type (type);
8296cf7f2e2dSJohn Marino
82975796c8dcSSimon Schubert if (raw_real_type == type)
82985796c8dcSSimon Schubert return type;
82995796c8dcSSimon Schubert else
83005796c8dcSSimon Schubert return to_static_fixed_type (raw_real_type);
83015796c8dcSSimon Schubert }
83025796c8dcSSimon Schubert }
83035796c8dcSSimon Schubert
83045796c8dcSSimon Schubert /* In some cases, incomplete and private types require
83055796c8dcSSimon Schubert cross-references that are not resolved as records (for example,
83065796c8dcSSimon Schubert type Foo;
83075796c8dcSSimon Schubert type FooP is access Foo;
83085796c8dcSSimon Schubert V: FooP;
83095796c8dcSSimon Schubert type Foo is array ...;
83105796c8dcSSimon Schubert ). In these cases, since there is no mechanism for producing
83115796c8dcSSimon Schubert cross-references to such types, we instead substitute for FooP a
83125796c8dcSSimon Schubert stub enumeration type that is nowhere resolved, and whose tag is
83135796c8dcSSimon Schubert the name of the actual type. Call these types "non-record stubs". */
83145796c8dcSSimon Schubert
83155796c8dcSSimon Schubert /* A type equivalent to TYPE that is not a non-record stub, if one
83165796c8dcSSimon Schubert exists, otherwise TYPE. */
83175796c8dcSSimon Schubert
83185796c8dcSSimon Schubert struct type *
ada_check_typedef(struct type * type)83195796c8dcSSimon Schubert ada_check_typedef (struct type *type)
83205796c8dcSSimon Schubert {
83215796c8dcSSimon Schubert if (type == NULL)
83225796c8dcSSimon Schubert return NULL;
83235796c8dcSSimon Schubert
8324c50c785cSJohn Marino /* If our type is a typedef type of a fat pointer, then we're done.
8325c50c785cSJohn Marino We don't want to strip the TYPE_CODE_TYPDEF layer, because this is
8326c50c785cSJohn Marino what allows us to distinguish between fat pointers that represent
8327c50c785cSJohn Marino array types, and fat pointers that represent array access types
8328c50c785cSJohn Marino (in both cases, the compiler implements them as fat pointers). */
8329c50c785cSJohn Marino if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF
8330c50c785cSJohn Marino && is_thick_pntr (ada_typedef_target_type (type)))
8331c50c785cSJohn Marino return type;
8332c50c785cSJohn Marino
83335796c8dcSSimon Schubert CHECK_TYPEDEF (type);
83345796c8dcSSimon Schubert if (type == NULL || TYPE_CODE (type) != TYPE_CODE_ENUM
83355796c8dcSSimon Schubert || !TYPE_STUB (type)
83365796c8dcSSimon Schubert || TYPE_TAG_NAME (type) == NULL)
83375796c8dcSSimon Schubert return type;
83385796c8dcSSimon Schubert else
83395796c8dcSSimon Schubert {
8340*ef5ccd6cSJohn Marino const char *name = TYPE_TAG_NAME (type);
83415796c8dcSSimon Schubert struct type *type1 = ada_find_any_type (name);
8342cf7f2e2dSJohn Marino
8343c50c785cSJohn Marino if (type1 == NULL)
8344c50c785cSJohn Marino return type;
8345c50c785cSJohn Marino
8346c50c785cSJohn Marino /* TYPE1 might itself be a TYPE_CODE_TYPEDEF (this can happen with
8347c50c785cSJohn Marino stubs pointing to arrays, as we don't create symbols for array
8348c50c785cSJohn Marino types, only for the typedef-to-array types). If that's the case,
8349c50c785cSJohn Marino strip the typedef layer. */
8350c50c785cSJohn Marino if (TYPE_CODE (type1) == TYPE_CODE_TYPEDEF)
8351c50c785cSJohn Marino type1 = ada_check_typedef (type1);
8352c50c785cSJohn Marino
8353c50c785cSJohn Marino return type1;
83545796c8dcSSimon Schubert }
83555796c8dcSSimon Schubert }
83565796c8dcSSimon Schubert
83575796c8dcSSimon Schubert /* A value representing the data at VALADDR/ADDRESS as described by
83585796c8dcSSimon Schubert type TYPE0, but with a standard (static-sized) type that correctly
83595796c8dcSSimon Schubert describes it. If VAL0 is not NULL and TYPE0 already is a standard
83605796c8dcSSimon Schubert type, then return VAL0 [this feature is simply to avoid redundant
83615796c8dcSSimon Schubert creation of struct values]. */
83625796c8dcSSimon Schubert
83635796c8dcSSimon Schubert static struct value *
ada_to_fixed_value_create(struct type * type0,CORE_ADDR address,struct value * val0)83645796c8dcSSimon Schubert ada_to_fixed_value_create (struct type *type0, CORE_ADDR address,
83655796c8dcSSimon Schubert struct value *val0)
83665796c8dcSSimon Schubert {
83675796c8dcSSimon Schubert struct type *type = ada_to_fixed_type (type0, 0, address, NULL, 1);
8368cf7f2e2dSJohn Marino
83695796c8dcSSimon Schubert if (type == type0 && val0 != NULL)
83705796c8dcSSimon Schubert return val0;
83715796c8dcSSimon Schubert else
83725796c8dcSSimon Schubert return value_from_contents_and_address (type, 0, address);
83735796c8dcSSimon Schubert }
83745796c8dcSSimon Schubert
83755796c8dcSSimon Schubert /* A value representing VAL, but with a standard (static-sized) type
83765796c8dcSSimon Schubert that correctly describes it. Does not necessarily create a new
83775796c8dcSSimon Schubert value. */
83785796c8dcSSimon Schubert
8379cf7f2e2dSJohn Marino struct value *
ada_to_fixed_value(struct value * val)83805796c8dcSSimon Schubert ada_to_fixed_value (struct value *val)
83815796c8dcSSimon Schubert {
8382*ef5ccd6cSJohn Marino val = unwrap_value (val);
8383*ef5ccd6cSJohn Marino val = ada_to_fixed_value_create (value_type (val),
83845796c8dcSSimon Schubert value_address (val),
83855796c8dcSSimon Schubert val);
8386*ef5ccd6cSJohn Marino return val;
83875796c8dcSSimon Schubert }
83885796c8dcSSimon Schubert
83895796c8dcSSimon Schubert
83905796c8dcSSimon Schubert /* Attributes */
83915796c8dcSSimon Schubert
83925796c8dcSSimon Schubert /* Table mapping attribute numbers to names.
83935796c8dcSSimon Schubert NOTE: Keep up to date with enum ada_attribute definition in ada-lang.h. */
83945796c8dcSSimon Schubert
83955796c8dcSSimon Schubert static const char *attribute_names[] = {
83965796c8dcSSimon Schubert "<?>",
83975796c8dcSSimon Schubert
83985796c8dcSSimon Schubert "first",
83995796c8dcSSimon Schubert "last",
84005796c8dcSSimon Schubert "length",
84015796c8dcSSimon Schubert "image",
84025796c8dcSSimon Schubert "max",
84035796c8dcSSimon Schubert "min",
84045796c8dcSSimon Schubert "modulus",
84055796c8dcSSimon Schubert "pos",
84065796c8dcSSimon Schubert "size",
84075796c8dcSSimon Schubert "tag",
84085796c8dcSSimon Schubert "val",
84095796c8dcSSimon Schubert 0
84105796c8dcSSimon Schubert };
84115796c8dcSSimon Schubert
84125796c8dcSSimon Schubert const char *
ada_attribute_name(enum exp_opcode n)84135796c8dcSSimon Schubert ada_attribute_name (enum exp_opcode n)
84145796c8dcSSimon Schubert {
84155796c8dcSSimon Schubert if (n >= OP_ATR_FIRST && n <= (int) OP_ATR_VAL)
84165796c8dcSSimon Schubert return attribute_names[n - OP_ATR_FIRST + 1];
84175796c8dcSSimon Schubert else
84185796c8dcSSimon Schubert return attribute_names[0];
84195796c8dcSSimon Schubert }
84205796c8dcSSimon Schubert
84215796c8dcSSimon Schubert /* Evaluate the 'POS attribute applied to ARG. */
84225796c8dcSSimon Schubert
84235796c8dcSSimon Schubert static LONGEST
pos_atr(struct value * arg)84245796c8dcSSimon Schubert pos_atr (struct value *arg)
84255796c8dcSSimon Schubert {
84265796c8dcSSimon Schubert struct value *val = coerce_ref (arg);
84275796c8dcSSimon Schubert struct type *type = value_type (val);
84285796c8dcSSimon Schubert
84295796c8dcSSimon Schubert if (!discrete_type_p (type))
84305796c8dcSSimon Schubert error (_("'POS only defined on discrete types"));
84315796c8dcSSimon Schubert
84325796c8dcSSimon Schubert if (TYPE_CODE (type) == TYPE_CODE_ENUM)
84335796c8dcSSimon Schubert {
84345796c8dcSSimon Schubert int i;
84355796c8dcSSimon Schubert LONGEST v = value_as_long (val);
84365796c8dcSSimon Schubert
84375796c8dcSSimon Schubert for (i = 0; i < TYPE_NFIELDS (type); i += 1)
84385796c8dcSSimon Schubert {
8439*ef5ccd6cSJohn Marino if (v == TYPE_FIELD_ENUMVAL (type, i))
84405796c8dcSSimon Schubert return i;
84415796c8dcSSimon Schubert }
84425796c8dcSSimon Schubert error (_("enumeration value is invalid: can't find 'POS"));
84435796c8dcSSimon Schubert }
84445796c8dcSSimon Schubert else
84455796c8dcSSimon Schubert return value_as_long (val);
84465796c8dcSSimon Schubert }
84475796c8dcSSimon Schubert
84485796c8dcSSimon Schubert static struct value *
value_pos_atr(struct type * type,struct value * arg)84495796c8dcSSimon Schubert value_pos_atr (struct type *type, struct value *arg)
84505796c8dcSSimon Schubert {
84515796c8dcSSimon Schubert return value_from_longest (type, pos_atr (arg));
84525796c8dcSSimon Schubert }
84535796c8dcSSimon Schubert
84545796c8dcSSimon Schubert /* Evaluate the TYPE'VAL attribute applied to ARG. */
84555796c8dcSSimon Schubert
84565796c8dcSSimon Schubert static struct value *
value_val_atr(struct type * type,struct value * arg)84575796c8dcSSimon Schubert value_val_atr (struct type *type, struct value *arg)
84585796c8dcSSimon Schubert {
84595796c8dcSSimon Schubert if (!discrete_type_p (type))
84605796c8dcSSimon Schubert error (_("'VAL only defined on discrete types"));
84615796c8dcSSimon Schubert if (!integer_type_p (value_type (arg)))
84625796c8dcSSimon Schubert error (_("'VAL requires integral argument"));
84635796c8dcSSimon Schubert
84645796c8dcSSimon Schubert if (TYPE_CODE (type) == TYPE_CODE_ENUM)
84655796c8dcSSimon Schubert {
84665796c8dcSSimon Schubert long pos = value_as_long (arg);
8467cf7f2e2dSJohn Marino
84685796c8dcSSimon Schubert if (pos < 0 || pos >= TYPE_NFIELDS (type))
84695796c8dcSSimon Schubert error (_("argument to 'VAL out of range"));
8470*ef5ccd6cSJohn Marino return value_from_longest (type, TYPE_FIELD_ENUMVAL (type, pos));
84715796c8dcSSimon Schubert }
84725796c8dcSSimon Schubert else
84735796c8dcSSimon Schubert return value_from_longest (type, value_as_long (arg));
84745796c8dcSSimon Schubert }
84755796c8dcSSimon Schubert
84765796c8dcSSimon Schubert
84775796c8dcSSimon Schubert /* Evaluation */
84785796c8dcSSimon Schubert
84795796c8dcSSimon Schubert /* True if TYPE appears to be an Ada character type.
84805796c8dcSSimon Schubert [At the moment, this is true only for Character and Wide_Character;
84815796c8dcSSimon Schubert It is a heuristic test that could stand improvement]. */
84825796c8dcSSimon Schubert
84835796c8dcSSimon Schubert int
ada_is_character_type(struct type * type)84845796c8dcSSimon Schubert ada_is_character_type (struct type *type)
84855796c8dcSSimon Schubert {
84865796c8dcSSimon Schubert const char *name;
84875796c8dcSSimon Schubert
84885796c8dcSSimon Schubert /* If the type code says it's a character, then assume it really is,
84895796c8dcSSimon Schubert and don't check any further. */
84905796c8dcSSimon Schubert if (TYPE_CODE (type) == TYPE_CODE_CHAR)
84915796c8dcSSimon Schubert return 1;
84925796c8dcSSimon Schubert
84935796c8dcSSimon Schubert /* Otherwise, assume it's a character type iff it is a discrete type
84945796c8dcSSimon Schubert with a known character type name. */
84955796c8dcSSimon Schubert name = ada_type_name (type);
84965796c8dcSSimon Schubert return (name != NULL
84975796c8dcSSimon Schubert && (TYPE_CODE (type) == TYPE_CODE_INT
84985796c8dcSSimon Schubert || TYPE_CODE (type) == TYPE_CODE_RANGE)
84995796c8dcSSimon Schubert && (strcmp (name, "character") == 0
85005796c8dcSSimon Schubert || strcmp (name, "wide_character") == 0
85015796c8dcSSimon Schubert || strcmp (name, "wide_wide_character") == 0
85025796c8dcSSimon Schubert || strcmp (name, "unsigned char") == 0));
85035796c8dcSSimon Schubert }
85045796c8dcSSimon Schubert
85055796c8dcSSimon Schubert /* True if TYPE appears to be an Ada string type. */
85065796c8dcSSimon Schubert
85075796c8dcSSimon Schubert int
ada_is_string_type(struct type * type)85085796c8dcSSimon Schubert ada_is_string_type (struct type *type)
85095796c8dcSSimon Schubert {
85105796c8dcSSimon Schubert type = ada_check_typedef (type);
85115796c8dcSSimon Schubert if (type != NULL
85125796c8dcSSimon Schubert && TYPE_CODE (type) != TYPE_CODE_PTR
85135796c8dcSSimon Schubert && (ada_is_simple_array_type (type)
85145796c8dcSSimon Schubert || ada_is_array_descriptor_type (type))
85155796c8dcSSimon Schubert && ada_array_arity (type) == 1)
85165796c8dcSSimon Schubert {
85175796c8dcSSimon Schubert struct type *elttype = ada_array_element_type (type, 1);
85185796c8dcSSimon Schubert
85195796c8dcSSimon Schubert return ada_is_character_type (elttype);
85205796c8dcSSimon Schubert }
85215796c8dcSSimon Schubert else
85225796c8dcSSimon Schubert return 0;
85235796c8dcSSimon Schubert }
85245796c8dcSSimon Schubert
8525cf7f2e2dSJohn Marino /* The compiler sometimes provides a parallel XVS type for a given
8526cf7f2e2dSJohn Marino PAD type. Normally, it is safe to follow the PAD type directly,
8527cf7f2e2dSJohn Marino but older versions of the compiler have a bug that causes the offset
8528cf7f2e2dSJohn Marino of its "F" field to be wrong. Following that field in that case
8529cf7f2e2dSJohn Marino would lead to incorrect results, but this can be worked around
8530cf7f2e2dSJohn Marino by ignoring the PAD type and using the associated XVS type instead.
8531cf7f2e2dSJohn Marino
8532cf7f2e2dSJohn Marino Set to True if the debugger should trust the contents of PAD types.
8533cf7f2e2dSJohn Marino Otherwise, ignore the PAD type if there is a parallel XVS type. */
8534cf7f2e2dSJohn Marino static int trust_pad_over_xvs = 1;
85355796c8dcSSimon Schubert
85365796c8dcSSimon Schubert /* True if TYPE is a struct type introduced by the compiler to force the
85375796c8dcSSimon Schubert alignment of a value. Such types have a single field with a
85385796c8dcSSimon Schubert distinctive name. */
85395796c8dcSSimon Schubert
85405796c8dcSSimon Schubert int
ada_is_aligner_type(struct type * type)85415796c8dcSSimon Schubert ada_is_aligner_type (struct type *type)
85425796c8dcSSimon Schubert {
85435796c8dcSSimon Schubert type = ada_check_typedef (type);
85445796c8dcSSimon Schubert
8545cf7f2e2dSJohn Marino if (!trust_pad_over_xvs && ada_find_parallel_type (type, "___XVS") != NULL)
85465796c8dcSSimon Schubert return 0;
85475796c8dcSSimon Schubert
85485796c8dcSSimon Schubert return (TYPE_CODE (type) == TYPE_CODE_STRUCT
85495796c8dcSSimon Schubert && TYPE_NFIELDS (type) == 1
85505796c8dcSSimon Schubert && strcmp (TYPE_FIELD_NAME (type, 0), "F") == 0);
85515796c8dcSSimon Schubert }
85525796c8dcSSimon Schubert
85535796c8dcSSimon Schubert /* If there is an ___XVS-convention type parallel to SUBTYPE, return
85545796c8dcSSimon Schubert the parallel type. */
85555796c8dcSSimon Schubert
85565796c8dcSSimon Schubert struct type *
ada_get_base_type(struct type * raw_type)85575796c8dcSSimon Schubert ada_get_base_type (struct type *raw_type)
85585796c8dcSSimon Schubert {
85595796c8dcSSimon Schubert struct type *real_type_namer;
85605796c8dcSSimon Schubert struct type *raw_real_type;
85615796c8dcSSimon Schubert
85625796c8dcSSimon Schubert if (raw_type == NULL || TYPE_CODE (raw_type) != TYPE_CODE_STRUCT)
85635796c8dcSSimon Schubert return raw_type;
85645796c8dcSSimon Schubert
85655796c8dcSSimon Schubert if (ada_is_aligner_type (raw_type))
85665796c8dcSSimon Schubert /* The encoding specifies that we should always use the aligner type.
85675796c8dcSSimon Schubert So, even if this aligner type has an associated XVS type, we should
85685796c8dcSSimon Schubert simply ignore it.
85695796c8dcSSimon Schubert
85705796c8dcSSimon Schubert According to the compiler gurus, an XVS type parallel to an aligner
85715796c8dcSSimon Schubert type may exist because of a stabs limitation. In stabs, aligner
85725796c8dcSSimon Schubert types are empty because the field has a variable-sized type, and
85735796c8dcSSimon Schubert thus cannot actually be used as an aligner type. As a result,
85745796c8dcSSimon Schubert we need the associated parallel XVS type to decode the type.
85755796c8dcSSimon Schubert Since the policy in the compiler is to not change the internal
85765796c8dcSSimon Schubert representation based on the debugging info format, we sometimes
85775796c8dcSSimon Schubert end up having a redundant XVS type parallel to the aligner type. */
85785796c8dcSSimon Schubert return raw_type;
85795796c8dcSSimon Schubert
85805796c8dcSSimon Schubert real_type_namer = ada_find_parallel_type (raw_type, "___XVS");
85815796c8dcSSimon Schubert if (real_type_namer == NULL
85825796c8dcSSimon Schubert || TYPE_CODE (real_type_namer) != TYPE_CODE_STRUCT
85835796c8dcSSimon Schubert || TYPE_NFIELDS (real_type_namer) != 1)
85845796c8dcSSimon Schubert return raw_type;
85855796c8dcSSimon Schubert
8586cf7f2e2dSJohn Marino if (TYPE_CODE (TYPE_FIELD_TYPE (real_type_namer, 0)) != TYPE_CODE_REF)
8587cf7f2e2dSJohn Marino {
8588cf7f2e2dSJohn Marino /* This is an older encoding form where the base type needs to be
8589cf7f2e2dSJohn Marino looked up by name. We prefer the newer enconding because it is
8590cf7f2e2dSJohn Marino more efficient. */
85915796c8dcSSimon Schubert raw_real_type = ada_find_any_type (TYPE_FIELD_NAME (real_type_namer, 0));
85925796c8dcSSimon Schubert if (raw_real_type == NULL)
85935796c8dcSSimon Schubert return raw_type;
85945796c8dcSSimon Schubert else
85955796c8dcSSimon Schubert return raw_real_type;
85965796c8dcSSimon Schubert }
85975796c8dcSSimon Schubert
8598cf7f2e2dSJohn Marino /* The field in our XVS type is a reference to the base type. */
8599cf7f2e2dSJohn Marino return TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (real_type_namer, 0));
8600cf7f2e2dSJohn Marino }
8601cf7f2e2dSJohn Marino
86025796c8dcSSimon Schubert /* The type of value designated by TYPE, with all aligners removed. */
86035796c8dcSSimon Schubert
86045796c8dcSSimon Schubert struct type *
ada_aligned_type(struct type * type)86055796c8dcSSimon Schubert ada_aligned_type (struct type *type)
86065796c8dcSSimon Schubert {
86075796c8dcSSimon Schubert if (ada_is_aligner_type (type))
86085796c8dcSSimon Schubert return ada_aligned_type (TYPE_FIELD_TYPE (type, 0));
86095796c8dcSSimon Schubert else
86105796c8dcSSimon Schubert return ada_get_base_type (type);
86115796c8dcSSimon Schubert }
86125796c8dcSSimon Schubert
86135796c8dcSSimon Schubert
86145796c8dcSSimon Schubert /* The address of the aligned value in an object at address VALADDR
86155796c8dcSSimon Schubert having type TYPE. Assumes ada_is_aligner_type (TYPE). */
86165796c8dcSSimon Schubert
86175796c8dcSSimon Schubert const gdb_byte *
ada_aligned_value_addr(struct type * type,const gdb_byte * valaddr)86185796c8dcSSimon Schubert ada_aligned_value_addr (struct type *type, const gdb_byte *valaddr)
86195796c8dcSSimon Schubert {
86205796c8dcSSimon Schubert if (ada_is_aligner_type (type))
86215796c8dcSSimon Schubert return ada_aligned_value_addr (TYPE_FIELD_TYPE (type, 0),
86225796c8dcSSimon Schubert valaddr +
86235796c8dcSSimon Schubert TYPE_FIELD_BITPOS (type,
86245796c8dcSSimon Schubert 0) / TARGET_CHAR_BIT);
86255796c8dcSSimon Schubert else
86265796c8dcSSimon Schubert return valaddr;
86275796c8dcSSimon Schubert }
86285796c8dcSSimon Schubert
86295796c8dcSSimon Schubert
86305796c8dcSSimon Schubert
86315796c8dcSSimon Schubert /* The printed representation of an enumeration literal with encoded
86325796c8dcSSimon Schubert name NAME. The value is good to the next call of ada_enum_name. */
86335796c8dcSSimon Schubert const char *
ada_enum_name(const char * name)86345796c8dcSSimon Schubert ada_enum_name (const char *name)
86355796c8dcSSimon Schubert {
86365796c8dcSSimon Schubert static char *result;
86375796c8dcSSimon Schubert static size_t result_len = 0;
86385796c8dcSSimon Schubert char *tmp;
86395796c8dcSSimon Schubert
86405796c8dcSSimon Schubert /* First, unqualify the enumeration name:
86415796c8dcSSimon Schubert 1. Search for the last '.' character. If we find one, then skip
8642a45ae5f8SJohn Marino all the preceding characters, the unqualified name starts
86435796c8dcSSimon Schubert right after that dot.
86445796c8dcSSimon Schubert 2. Otherwise, we may be debugging on a target where the compiler
86455796c8dcSSimon Schubert translates dots into "__". Search forward for double underscores,
86465796c8dcSSimon Schubert but stop searching when we hit an overloading suffix, which is
86475796c8dcSSimon Schubert of the form "__" followed by digits. */
86485796c8dcSSimon Schubert
86495796c8dcSSimon Schubert tmp = strrchr (name, '.');
86505796c8dcSSimon Schubert if (tmp != NULL)
86515796c8dcSSimon Schubert name = tmp + 1;
86525796c8dcSSimon Schubert else
86535796c8dcSSimon Schubert {
86545796c8dcSSimon Schubert while ((tmp = strstr (name, "__")) != NULL)
86555796c8dcSSimon Schubert {
86565796c8dcSSimon Schubert if (isdigit (tmp[2]))
86575796c8dcSSimon Schubert break;
86585796c8dcSSimon Schubert else
86595796c8dcSSimon Schubert name = tmp + 2;
86605796c8dcSSimon Schubert }
86615796c8dcSSimon Schubert }
86625796c8dcSSimon Schubert
86635796c8dcSSimon Schubert if (name[0] == 'Q')
86645796c8dcSSimon Schubert {
86655796c8dcSSimon Schubert int v;
8666cf7f2e2dSJohn Marino
86675796c8dcSSimon Schubert if (name[1] == 'U' || name[1] == 'W')
86685796c8dcSSimon Schubert {
86695796c8dcSSimon Schubert if (sscanf (name + 2, "%x", &v) != 1)
86705796c8dcSSimon Schubert return name;
86715796c8dcSSimon Schubert }
86725796c8dcSSimon Schubert else
86735796c8dcSSimon Schubert return name;
86745796c8dcSSimon Schubert
86755796c8dcSSimon Schubert GROW_VECT (result, result_len, 16);
86765796c8dcSSimon Schubert if (isascii (v) && isprint (v))
86775796c8dcSSimon Schubert xsnprintf (result, result_len, "'%c'", v);
86785796c8dcSSimon Schubert else if (name[1] == 'U')
86795796c8dcSSimon Schubert xsnprintf (result, result_len, "[\"%02x\"]", v);
86805796c8dcSSimon Schubert else
86815796c8dcSSimon Schubert xsnprintf (result, result_len, "[\"%04x\"]", v);
86825796c8dcSSimon Schubert
86835796c8dcSSimon Schubert return result;
86845796c8dcSSimon Schubert }
86855796c8dcSSimon Schubert else
86865796c8dcSSimon Schubert {
86875796c8dcSSimon Schubert tmp = strstr (name, "__");
86885796c8dcSSimon Schubert if (tmp == NULL)
86895796c8dcSSimon Schubert tmp = strstr (name, "$");
86905796c8dcSSimon Schubert if (tmp != NULL)
86915796c8dcSSimon Schubert {
86925796c8dcSSimon Schubert GROW_VECT (result, result_len, tmp - name + 1);
86935796c8dcSSimon Schubert strncpy (result, name, tmp - name);
86945796c8dcSSimon Schubert result[tmp - name] = '\0';
86955796c8dcSSimon Schubert return result;
86965796c8dcSSimon Schubert }
86975796c8dcSSimon Schubert
86985796c8dcSSimon Schubert return name;
86995796c8dcSSimon Schubert }
87005796c8dcSSimon Schubert }
87015796c8dcSSimon Schubert
87025796c8dcSSimon Schubert /* Evaluate the subexpression of EXP starting at *POS as for
87035796c8dcSSimon Schubert evaluate_type, updating *POS to point just past the evaluated
87045796c8dcSSimon Schubert expression. */
87055796c8dcSSimon Schubert
87065796c8dcSSimon Schubert static struct value *
evaluate_subexp_type(struct expression * exp,int * pos)87075796c8dcSSimon Schubert evaluate_subexp_type (struct expression *exp, int *pos)
87085796c8dcSSimon Schubert {
87095796c8dcSSimon Schubert return evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
87105796c8dcSSimon Schubert }
87115796c8dcSSimon Schubert
87125796c8dcSSimon Schubert /* If VAL is wrapped in an aligner or subtype wrapper, return the
87135796c8dcSSimon Schubert value it wraps. */
87145796c8dcSSimon Schubert
87155796c8dcSSimon Schubert static struct value *
unwrap_value(struct value * val)87165796c8dcSSimon Schubert unwrap_value (struct value *val)
87175796c8dcSSimon Schubert {
87185796c8dcSSimon Schubert struct type *type = ada_check_typedef (value_type (val));
8719cf7f2e2dSJohn Marino
87205796c8dcSSimon Schubert if (ada_is_aligner_type (type))
87215796c8dcSSimon Schubert {
87225796c8dcSSimon Schubert struct value *v = ada_value_struct_elt (val, "F", 0);
87235796c8dcSSimon Schubert struct type *val_type = ada_check_typedef (value_type (v));
8724cf7f2e2dSJohn Marino
87255796c8dcSSimon Schubert if (ada_type_name (val_type) == NULL)
87265796c8dcSSimon Schubert TYPE_NAME (val_type) = ada_type_name (type);
87275796c8dcSSimon Schubert
87285796c8dcSSimon Schubert return unwrap_value (v);
87295796c8dcSSimon Schubert }
87305796c8dcSSimon Schubert else
87315796c8dcSSimon Schubert {
87325796c8dcSSimon Schubert struct type *raw_real_type =
87335796c8dcSSimon Schubert ada_check_typedef (ada_get_base_type (type));
87345796c8dcSSimon Schubert
8735cf7f2e2dSJohn Marino /* If there is no parallel XVS or XVE type, then the value is
8736cf7f2e2dSJohn Marino already unwrapped. Return it without further modification. */
8737cf7f2e2dSJohn Marino if ((type == raw_real_type)
8738cf7f2e2dSJohn Marino && ada_find_parallel_type (type, "___XVE") == NULL)
87395796c8dcSSimon Schubert return val;
87405796c8dcSSimon Schubert
87415796c8dcSSimon Schubert return
87425796c8dcSSimon Schubert coerce_unspec_val_to_type
87435796c8dcSSimon Schubert (val, ada_to_fixed_type (raw_real_type, 0,
87445796c8dcSSimon Schubert value_address (val),
87455796c8dcSSimon Schubert NULL, 1));
87465796c8dcSSimon Schubert }
87475796c8dcSSimon Schubert }
87485796c8dcSSimon Schubert
87495796c8dcSSimon Schubert static struct value *
cast_to_fixed(struct type * type,struct value * arg)87505796c8dcSSimon Schubert cast_to_fixed (struct type *type, struct value *arg)
87515796c8dcSSimon Schubert {
87525796c8dcSSimon Schubert LONGEST val;
87535796c8dcSSimon Schubert
87545796c8dcSSimon Schubert if (type == value_type (arg))
87555796c8dcSSimon Schubert return arg;
87565796c8dcSSimon Schubert else if (ada_is_fixed_point_type (value_type (arg)))
87575796c8dcSSimon Schubert val = ada_float_to_fixed (type,
87585796c8dcSSimon Schubert ada_fixed_to_float (value_type (arg),
87595796c8dcSSimon Schubert value_as_long (arg)));
87605796c8dcSSimon Schubert else
87615796c8dcSSimon Schubert {
87625796c8dcSSimon Schubert DOUBLEST argd = value_as_double (arg);
8763cf7f2e2dSJohn Marino
87645796c8dcSSimon Schubert val = ada_float_to_fixed (type, argd);
87655796c8dcSSimon Schubert }
87665796c8dcSSimon Schubert
87675796c8dcSSimon Schubert return value_from_longest (type, val);
87685796c8dcSSimon Schubert }
87695796c8dcSSimon Schubert
87705796c8dcSSimon Schubert static struct value *
cast_from_fixed(struct type * type,struct value * arg)87715796c8dcSSimon Schubert cast_from_fixed (struct type *type, struct value *arg)
87725796c8dcSSimon Schubert {
87735796c8dcSSimon Schubert DOUBLEST val = ada_fixed_to_float (value_type (arg),
87745796c8dcSSimon Schubert value_as_long (arg));
8775cf7f2e2dSJohn Marino
87765796c8dcSSimon Schubert return value_from_double (type, val);
87775796c8dcSSimon Schubert }
87785796c8dcSSimon Schubert
8779*ef5ccd6cSJohn Marino /* Given two array types T1 and T2, return nonzero iff both arrays
8780*ef5ccd6cSJohn Marino contain the same number of elements. */
8781*ef5ccd6cSJohn Marino
8782*ef5ccd6cSJohn Marino static int
ada_same_array_size_p(struct type * t1,struct type * t2)8783*ef5ccd6cSJohn Marino ada_same_array_size_p (struct type *t1, struct type *t2)
8784*ef5ccd6cSJohn Marino {
8785*ef5ccd6cSJohn Marino LONGEST lo1, hi1, lo2, hi2;
8786*ef5ccd6cSJohn Marino
8787*ef5ccd6cSJohn Marino /* Get the array bounds in order to verify that the size of
8788*ef5ccd6cSJohn Marino the two arrays match. */
8789*ef5ccd6cSJohn Marino if (!get_array_bounds (t1, &lo1, &hi1)
8790*ef5ccd6cSJohn Marino || !get_array_bounds (t2, &lo2, &hi2))
8791*ef5ccd6cSJohn Marino error (_("unable to determine array bounds"));
8792*ef5ccd6cSJohn Marino
8793*ef5ccd6cSJohn Marino /* To make things easier for size comparison, normalize a bit
8794*ef5ccd6cSJohn Marino the case of empty arrays by making sure that the difference
8795*ef5ccd6cSJohn Marino between upper bound and lower bound is always -1. */
8796*ef5ccd6cSJohn Marino if (lo1 > hi1)
8797*ef5ccd6cSJohn Marino hi1 = lo1 - 1;
8798*ef5ccd6cSJohn Marino if (lo2 > hi2)
8799*ef5ccd6cSJohn Marino hi2 = lo2 - 1;
8800*ef5ccd6cSJohn Marino
8801*ef5ccd6cSJohn Marino return (hi1 - lo1 == hi2 - lo2);
8802*ef5ccd6cSJohn Marino }
8803*ef5ccd6cSJohn Marino
8804*ef5ccd6cSJohn Marino /* Assuming that VAL is an array of integrals, and TYPE represents
8805*ef5ccd6cSJohn Marino an array with the same number of elements, but with wider integral
8806*ef5ccd6cSJohn Marino elements, return an array "casted" to TYPE. In practice, this
8807*ef5ccd6cSJohn Marino means that the returned array is built by casting each element
8808*ef5ccd6cSJohn Marino of the original array into TYPE's (wider) element type. */
8809*ef5ccd6cSJohn Marino
8810*ef5ccd6cSJohn Marino static struct value *
ada_promote_array_of_integrals(struct type * type,struct value * val)8811*ef5ccd6cSJohn Marino ada_promote_array_of_integrals (struct type *type, struct value *val)
8812*ef5ccd6cSJohn Marino {
8813*ef5ccd6cSJohn Marino struct type *elt_type = TYPE_TARGET_TYPE (type);
8814*ef5ccd6cSJohn Marino LONGEST lo, hi;
8815*ef5ccd6cSJohn Marino struct value *res;
8816*ef5ccd6cSJohn Marino LONGEST i;
8817*ef5ccd6cSJohn Marino
8818*ef5ccd6cSJohn Marino /* Verify that both val and type are arrays of scalars, and
8819*ef5ccd6cSJohn Marino that the size of val's elements is smaller than the size
8820*ef5ccd6cSJohn Marino of type's element. */
8821*ef5ccd6cSJohn Marino gdb_assert (TYPE_CODE (type) == TYPE_CODE_ARRAY);
8822*ef5ccd6cSJohn Marino gdb_assert (is_integral_type (TYPE_TARGET_TYPE (type)));
8823*ef5ccd6cSJohn Marino gdb_assert (TYPE_CODE (value_type (val)) == TYPE_CODE_ARRAY);
8824*ef5ccd6cSJohn Marino gdb_assert (is_integral_type (TYPE_TARGET_TYPE (value_type (val))));
8825*ef5ccd6cSJohn Marino gdb_assert (TYPE_LENGTH (TYPE_TARGET_TYPE (type))
8826*ef5ccd6cSJohn Marino > TYPE_LENGTH (TYPE_TARGET_TYPE (value_type (val))));
8827*ef5ccd6cSJohn Marino
8828*ef5ccd6cSJohn Marino if (!get_array_bounds (type, &lo, &hi))
8829*ef5ccd6cSJohn Marino error (_("unable to determine array bounds"));
8830*ef5ccd6cSJohn Marino
8831*ef5ccd6cSJohn Marino res = allocate_value (type);
8832*ef5ccd6cSJohn Marino
8833*ef5ccd6cSJohn Marino /* Promote each array element. */
8834*ef5ccd6cSJohn Marino for (i = 0; i < hi - lo + 1; i++)
8835*ef5ccd6cSJohn Marino {
8836*ef5ccd6cSJohn Marino struct value *elt = value_cast (elt_type, value_subscript (val, lo + i));
8837*ef5ccd6cSJohn Marino
8838*ef5ccd6cSJohn Marino memcpy (value_contents_writeable (res) + (i * TYPE_LENGTH (elt_type)),
8839*ef5ccd6cSJohn Marino value_contents_all (elt), TYPE_LENGTH (elt_type));
8840*ef5ccd6cSJohn Marino }
8841*ef5ccd6cSJohn Marino
8842*ef5ccd6cSJohn Marino return res;
8843*ef5ccd6cSJohn Marino }
8844*ef5ccd6cSJohn Marino
88455796c8dcSSimon Schubert /* Coerce VAL as necessary for assignment to an lval of type TYPE, and
88465796c8dcSSimon Schubert return the converted value. */
88475796c8dcSSimon Schubert
88485796c8dcSSimon Schubert static struct value *
coerce_for_assign(struct type * type,struct value * val)88495796c8dcSSimon Schubert coerce_for_assign (struct type *type, struct value *val)
88505796c8dcSSimon Schubert {
88515796c8dcSSimon Schubert struct type *type2 = value_type (val);
8852cf7f2e2dSJohn Marino
88535796c8dcSSimon Schubert if (type == type2)
88545796c8dcSSimon Schubert return val;
88555796c8dcSSimon Schubert
88565796c8dcSSimon Schubert type2 = ada_check_typedef (type2);
88575796c8dcSSimon Schubert type = ada_check_typedef (type);
88585796c8dcSSimon Schubert
88595796c8dcSSimon Schubert if (TYPE_CODE (type2) == TYPE_CODE_PTR
88605796c8dcSSimon Schubert && TYPE_CODE (type) == TYPE_CODE_ARRAY)
88615796c8dcSSimon Schubert {
88625796c8dcSSimon Schubert val = ada_value_ind (val);
88635796c8dcSSimon Schubert type2 = value_type (val);
88645796c8dcSSimon Schubert }
88655796c8dcSSimon Schubert
88665796c8dcSSimon Schubert if (TYPE_CODE (type2) == TYPE_CODE_ARRAY
88675796c8dcSSimon Schubert && TYPE_CODE (type) == TYPE_CODE_ARRAY)
88685796c8dcSSimon Schubert {
8869*ef5ccd6cSJohn Marino if (!ada_same_array_size_p (type, type2))
8870*ef5ccd6cSJohn Marino error (_("cannot assign arrays of different length"));
8871*ef5ccd6cSJohn Marino
8872*ef5ccd6cSJohn Marino if (is_integral_type (TYPE_TARGET_TYPE (type))
8873*ef5ccd6cSJohn Marino && is_integral_type (TYPE_TARGET_TYPE (type2))
8874*ef5ccd6cSJohn Marino && TYPE_LENGTH (TYPE_TARGET_TYPE (type2))
8875*ef5ccd6cSJohn Marino < TYPE_LENGTH (TYPE_TARGET_TYPE (type)))
8876*ef5ccd6cSJohn Marino {
8877*ef5ccd6cSJohn Marino /* Allow implicit promotion of the array elements to
8878*ef5ccd6cSJohn Marino a wider type. */
8879*ef5ccd6cSJohn Marino return ada_promote_array_of_integrals (type, val);
8880*ef5ccd6cSJohn Marino }
8881*ef5ccd6cSJohn Marino
8882*ef5ccd6cSJohn Marino if (TYPE_LENGTH (TYPE_TARGET_TYPE (type2))
8883*ef5ccd6cSJohn Marino != TYPE_LENGTH (TYPE_TARGET_TYPE (type)))
88845796c8dcSSimon Schubert error (_("Incompatible types in assignment"));
88855796c8dcSSimon Schubert deprecated_set_value_type (val, type);
88865796c8dcSSimon Schubert }
88875796c8dcSSimon Schubert return val;
88885796c8dcSSimon Schubert }
88895796c8dcSSimon Schubert
88905796c8dcSSimon Schubert static struct value *
ada_value_binop(struct value * arg1,struct value * arg2,enum exp_opcode op)88915796c8dcSSimon Schubert ada_value_binop (struct value *arg1, struct value *arg2, enum exp_opcode op)
88925796c8dcSSimon Schubert {
88935796c8dcSSimon Schubert struct value *val;
88945796c8dcSSimon Schubert struct type *type1, *type2;
88955796c8dcSSimon Schubert LONGEST v, v1, v2;
88965796c8dcSSimon Schubert
88975796c8dcSSimon Schubert arg1 = coerce_ref (arg1);
88985796c8dcSSimon Schubert arg2 = coerce_ref (arg2);
8899a45ae5f8SJohn Marino type1 = get_base_type (ada_check_typedef (value_type (arg1)));
8900a45ae5f8SJohn Marino type2 = get_base_type (ada_check_typedef (value_type (arg2)));
89015796c8dcSSimon Schubert
89025796c8dcSSimon Schubert if (TYPE_CODE (type1) != TYPE_CODE_INT
89035796c8dcSSimon Schubert || TYPE_CODE (type2) != TYPE_CODE_INT)
89045796c8dcSSimon Schubert return value_binop (arg1, arg2, op);
89055796c8dcSSimon Schubert
89065796c8dcSSimon Schubert switch (op)
89075796c8dcSSimon Schubert {
89085796c8dcSSimon Schubert case BINOP_MOD:
89095796c8dcSSimon Schubert case BINOP_DIV:
89105796c8dcSSimon Schubert case BINOP_REM:
89115796c8dcSSimon Schubert break;
89125796c8dcSSimon Schubert default:
89135796c8dcSSimon Schubert return value_binop (arg1, arg2, op);
89145796c8dcSSimon Schubert }
89155796c8dcSSimon Schubert
89165796c8dcSSimon Schubert v2 = value_as_long (arg2);
89175796c8dcSSimon Schubert if (v2 == 0)
89185796c8dcSSimon Schubert error (_("second operand of %s must not be zero."), op_string (op));
89195796c8dcSSimon Schubert
89205796c8dcSSimon Schubert if (TYPE_UNSIGNED (type1) || op == BINOP_MOD)
89215796c8dcSSimon Schubert return value_binop (arg1, arg2, op);
89225796c8dcSSimon Schubert
89235796c8dcSSimon Schubert v1 = value_as_long (arg1);
89245796c8dcSSimon Schubert switch (op)
89255796c8dcSSimon Schubert {
89265796c8dcSSimon Schubert case BINOP_DIV:
89275796c8dcSSimon Schubert v = v1 / v2;
89285796c8dcSSimon Schubert if (!TRUNCATION_TOWARDS_ZERO && v1 * (v1 % v2) < 0)
89295796c8dcSSimon Schubert v += v > 0 ? -1 : 1;
89305796c8dcSSimon Schubert break;
89315796c8dcSSimon Schubert case BINOP_REM:
89325796c8dcSSimon Schubert v = v1 % v2;
89335796c8dcSSimon Schubert if (v * v1 < 0)
89345796c8dcSSimon Schubert v -= v2;
89355796c8dcSSimon Schubert break;
89365796c8dcSSimon Schubert default:
89375796c8dcSSimon Schubert /* Should not reach this point. */
89385796c8dcSSimon Schubert v = 0;
89395796c8dcSSimon Schubert }
89405796c8dcSSimon Schubert
89415796c8dcSSimon Schubert val = allocate_value (type1);
89425796c8dcSSimon Schubert store_unsigned_integer (value_contents_raw (val),
89435796c8dcSSimon Schubert TYPE_LENGTH (value_type (val)),
89445796c8dcSSimon Schubert gdbarch_byte_order (get_type_arch (type1)), v);
89455796c8dcSSimon Schubert return val;
89465796c8dcSSimon Schubert }
89475796c8dcSSimon Schubert
89485796c8dcSSimon Schubert static int
ada_value_equal(struct value * arg1,struct value * arg2)89495796c8dcSSimon Schubert ada_value_equal (struct value *arg1, struct value *arg2)
89505796c8dcSSimon Schubert {
89515796c8dcSSimon Schubert if (ada_is_direct_array_type (value_type (arg1))
89525796c8dcSSimon Schubert || ada_is_direct_array_type (value_type (arg2)))
89535796c8dcSSimon Schubert {
89545796c8dcSSimon Schubert /* Automatically dereference any array reference before
89555796c8dcSSimon Schubert we attempt to perform the comparison. */
89565796c8dcSSimon Schubert arg1 = ada_coerce_ref (arg1);
89575796c8dcSSimon Schubert arg2 = ada_coerce_ref (arg2);
89585796c8dcSSimon Schubert
89595796c8dcSSimon Schubert arg1 = ada_coerce_to_simple_array (arg1);
89605796c8dcSSimon Schubert arg2 = ada_coerce_to_simple_array (arg2);
89615796c8dcSSimon Schubert if (TYPE_CODE (value_type (arg1)) != TYPE_CODE_ARRAY
89625796c8dcSSimon Schubert || TYPE_CODE (value_type (arg2)) != TYPE_CODE_ARRAY)
89635796c8dcSSimon Schubert error (_("Attempt to compare array with non-array"));
89645796c8dcSSimon Schubert /* FIXME: The following works only for types whose
89655796c8dcSSimon Schubert representations use all bits (no padding or undefined bits)
89665796c8dcSSimon Schubert and do not have user-defined equality. */
89675796c8dcSSimon Schubert return
89685796c8dcSSimon Schubert TYPE_LENGTH (value_type (arg1)) == TYPE_LENGTH (value_type (arg2))
89695796c8dcSSimon Schubert && memcmp (value_contents (arg1), value_contents (arg2),
89705796c8dcSSimon Schubert TYPE_LENGTH (value_type (arg1))) == 0;
89715796c8dcSSimon Schubert }
89725796c8dcSSimon Schubert return value_equal (arg1, arg2);
89735796c8dcSSimon Schubert }
89745796c8dcSSimon Schubert
89755796c8dcSSimon Schubert /* Total number of component associations in the aggregate starting at
89765796c8dcSSimon Schubert index PC in EXP. Assumes that index PC is the start of an
89775796c8dcSSimon Schubert OP_AGGREGATE. */
89785796c8dcSSimon Schubert
89795796c8dcSSimon Schubert static int
num_component_specs(struct expression * exp,int pc)89805796c8dcSSimon Schubert num_component_specs (struct expression *exp, int pc)
89815796c8dcSSimon Schubert {
89825796c8dcSSimon Schubert int n, m, i;
8983cf7f2e2dSJohn Marino
89845796c8dcSSimon Schubert m = exp->elts[pc + 1].longconst;
89855796c8dcSSimon Schubert pc += 3;
89865796c8dcSSimon Schubert n = 0;
89875796c8dcSSimon Schubert for (i = 0; i < m; i += 1)
89885796c8dcSSimon Schubert {
89895796c8dcSSimon Schubert switch (exp->elts[pc].opcode)
89905796c8dcSSimon Schubert {
89915796c8dcSSimon Schubert default:
89925796c8dcSSimon Schubert n += 1;
89935796c8dcSSimon Schubert break;
89945796c8dcSSimon Schubert case OP_CHOICES:
89955796c8dcSSimon Schubert n += exp->elts[pc + 1].longconst;
89965796c8dcSSimon Schubert break;
89975796c8dcSSimon Schubert }
89985796c8dcSSimon Schubert ada_evaluate_subexp (NULL, exp, &pc, EVAL_SKIP);
89995796c8dcSSimon Schubert }
90005796c8dcSSimon Schubert return n;
90015796c8dcSSimon Schubert }
90025796c8dcSSimon Schubert
90035796c8dcSSimon Schubert /* Assign the result of evaluating EXP starting at *POS to the INDEXth
90045796c8dcSSimon Schubert component of LHS (a simple array or a record), updating *POS past
90055796c8dcSSimon Schubert the expression, assuming that LHS is contained in CONTAINER. Does
90065796c8dcSSimon Schubert not modify the inferior's memory, nor does it modify LHS (unless
90075796c8dcSSimon Schubert LHS == CONTAINER). */
90085796c8dcSSimon Schubert
90095796c8dcSSimon Schubert static void
assign_component(struct value * container,struct value * lhs,LONGEST index,struct expression * exp,int * pos)90105796c8dcSSimon Schubert assign_component (struct value *container, struct value *lhs, LONGEST index,
90115796c8dcSSimon Schubert struct expression *exp, int *pos)
90125796c8dcSSimon Schubert {
90135796c8dcSSimon Schubert struct value *mark = value_mark ();
90145796c8dcSSimon Schubert struct value *elt;
9015cf7f2e2dSJohn Marino
90165796c8dcSSimon Schubert if (TYPE_CODE (value_type (lhs)) == TYPE_CODE_ARRAY)
90175796c8dcSSimon Schubert {
90185796c8dcSSimon Schubert struct type *index_type = builtin_type (exp->gdbarch)->builtin_int;
90195796c8dcSSimon Schubert struct value *index_val = value_from_longest (index_type, index);
9020cf7f2e2dSJohn Marino
90215796c8dcSSimon Schubert elt = unwrap_value (ada_value_subscript (lhs, 1, &index_val));
90225796c8dcSSimon Schubert }
90235796c8dcSSimon Schubert else
90245796c8dcSSimon Schubert {
90255796c8dcSSimon Schubert elt = ada_index_struct_field (index, lhs, 0, value_type (lhs));
9026*ef5ccd6cSJohn Marino elt = ada_to_fixed_value (elt);
90275796c8dcSSimon Schubert }
90285796c8dcSSimon Schubert
90295796c8dcSSimon Schubert if (exp->elts[*pos].opcode == OP_AGGREGATE)
90305796c8dcSSimon Schubert assign_aggregate (container, elt, exp, pos, EVAL_NORMAL);
90315796c8dcSSimon Schubert else
90325796c8dcSSimon Schubert value_assign_to_component (container, elt,
90335796c8dcSSimon Schubert ada_evaluate_subexp (NULL, exp, pos,
90345796c8dcSSimon Schubert EVAL_NORMAL));
90355796c8dcSSimon Schubert
90365796c8dcSSimon Schubert value_free_to_mark (mark);
90375796c8dcSSimon Schubert }
90385796c8dcSSimon Schubert
90395796c8dcSSimon Schubert /* Assuming that LHS represents an lvalue having a record or array
90405796c8dcSSimon Schubert type, and EXP->ELTS[*POS] is an OP_AGGREGATE, evaluate an assignment
90415796c8dcSSimon Schubert of that aggregate's value to LHS, advancing *POS past the
90425796c8dcSSimon Schubert aggregate. NOSIDE is as for evaluate_subexp. CONTAINER is an
90435796c8dcSSimon Schubert lvalue containing LHS (possibly LHS itself). Does not modify
90445796c8dcSSimon Schubert the inferior's memory, nor does it modify the contents of
90455796c8dcSSimon Schubert LHS (unless == CONTAINER). Returns the modified CONTAINER. */
90465796c8dcSSimon Schubert
90475796c8dcSSimon Schubert static struct value *
assign_aggregate(struct value * container,struct value * lhs,struct expression * exp,int * pos,enum noside noside)90485796c8dcSSimon Schubert assign_aggregate (struct value *container,
90495796c8dcSSimon Schubert struct value *lhs, struct expression *exp,
90505796c8dcSSimon Schubert int *pos, enum noside noside)
90515796c8dcSSimon Schubert {
90525796c8dcSSimon Schubert struct type *lhs_type;
90535796c8dcSSimon Schubert int n = exp->elts[*pos+1].longconst;
90545796c8dcSSimon Schubert LONGEST low_index, high_index;
90555796c8dcSSimon Schubert int num_specs;
90565796c8dcSSimon Schubert LONGEST *indices;
90575796c8dcSSimon Schubert int max_indices, num_indices;
90585796c8dcSSimon Schubert int i;
90595796c8dcSSimon Schubert
90605796c8dcSSimon Schubert *pos += 3;
90615796c8dcSSimon Schubert if (noside != EVAL_NORMAL)
90625796c8dcSSimon Schubert {
90635796c8dcSSimon Schubert for (i = 0; i < n; i += 1)
90645796c8dcSSimon Schubert ada_evaluate_subexp (NULL, exp, pos, noside);
90655796c8dcSSimon Schubert return container;
90665796c8dcSSimon Schubert }
90675796c8dcSSimon Schubert
90685796c8dcSSimon Schubert container = ada_coerce_ref (container);
90695796c8dcSSimon Schubert if (ada_is_direct_array_type (value_type (container)))
90705796c8dcSSimon Schubert container = ada_coerce_to_simple_array (container);
90715796c8dcSSimon Schubert lhs = ada_coerce_ref (lhs);
90725796c8dcSSimon Schubert if (!deprecated_value_modifiable (lhs))
90735796c8dcSSimon Schubert error (_("Left operand of assignment is not a modifiable lvalue."));
90745796c8dcSSimon Schubert
90755796c8dcSSimon Schubert lhs_type = value_type (lhs);
90765796c8dcSSimon Schubert if (ada_is_direct_array_type (lhs_type))
90775796c8dcSSimon Schubert {
90785796c8dcSSimon Schubert lhs = ada_coerce_to_simple_array (lhs);
90795796c8dcSSimon Schubert lhs_type = value_type (lhs);
90805796c8dcSSimon Schubert low_index = TYPE_ARRAY_LOWER_BOUND_VALUE (lhs_type);
90815796c8dcSSimon Schubert high_index = TYPE_ARRAY_UPPER_BOUND_VALUE (lhs_type);
90825796c8dcSSimon Schubert }
90835796c8dcSSimon Schubert else if (TYPE_CODE (lhs_type) == TYPE_CODE_STRUCT)
90845796c8dcSSimon Schubert {
90855796c8dcSSimon Schubert low_index = 0;
90865796c8dcSSimon Schubert high_index = num_visible_fields (lhs_type) - 1;
90875796c8dcSSimon Schubert }
90885796c8dcSSimon Schubert else
90895796c8dcSSimon Schubert error (_("Left-hand side must be array or record."));
90905796c8dcSSimon Schubert
90915796c8dcSSimon Schubert num_specs = num_component_specs (exp, *pos - 3);
90925796c8dcSSimon Schubert max_indices = 4 * num_specs + 4;
90935796c8dcSSimon Schubert indices = alloca (max_indices * sizeof (indices[0]));
90945796c8dcSSimon Schubert indices[0] = indices[1] = low_index - 1;
90955796c8dcSSimon Schubert indices[2] = indices[3] = high_index + 1;
90965796c8dcSSimon Schubert num_indices = 4;
90975796c8dcSSimon Schubert
90985796c8dcSSimon Schubert for (i = 0; i < n; i += 1)
90995796c8dcSSimon Schubert {
91005796c8dcSSimon Schubert switch (exp->elts[*pos].opcode)
91015796c8dcSSimon Schubert {
91025796c8dcSSimon Schubert case OP_CHOICES:
91035796c8dcSSimon Schubert aggregate_assign_from_choices (container, lhs, exp, pos, indices,
91045796c8dcSSimon Schubert &num_indices, max_indices,
91055796c8dcSSimon Schubert low_index, high_index);
91065796c8dcSSimon Schubert break;
91075796c8dcSSimon Schubert case OP_POSITIONAL:
91085796c8dcSSimon Schubert aggregate_assign_positional (container, lhs, exp, pos, indices,
91095796c8dcSSimon Schubert &num_indices, max_indices,
91105796c8dcSSimon Schubert low_index, high_index);
91115796c8dcSSimon Schubert break;
91125796c8dcSSimon Schubert case OP_OTHERS:
91135796c8dcSSimon Schubert if (i != n-1)
91145796c8dcSSimon Schubert error (_("Misplaced 'others' clause"));
91155796c8dcSSimon Schubert aggregate_assign_others (container, lhs, exp, pos, indices,
91165796c8dcSSimon Schubert num_indices, low_index, high_index);
91175796c8dcSSimon Schubert break;
91185796c8dcSSimon Schubert default:
91195796c8dcSSimon Schubert error (_("Internal error: bad aggregate clause"));
91205796c8dcSSimon Schubert }
91215796c8dcSSimon Schubert }
91225796c8dcSSimon Schubert
91235796c8dcSSimon Schubert return container;
91245796c8dcSSimon Schubert }
91255796c8dcSSimon Schubert
91265796c8dcSSimon Schubert /* Assign into the component of LHS indexed by the OP_POSITIONAL
91275796c8dcSSimon Schubert construct at *POS, updating *POS past the construct, given that
91285796c8dcSSimon Schubert the positions are relative to lower bound LOW, where HIGH is the
91295796c8dcSSimon Schubert upper bound. Record the position in INDICES[0 .. MAX_INDICES-1]
91305796c8dcSSimon Schubert updating *NUM_INDICES as needed. CONTAINER is as for
91315796c8dcSSimon Schubert assign_aggregate. */
91325796c8dcSSimon Schubert static void
aggregate_assign_positional(struct value * container,struct value * lhs,struct expression * exp,int * pos,LONGEST * indices,int * num_indices,int max_indices,LONGEST low,LONGEST high)91335796c8dcSSimon Schubert aggregate_assign_positional (struct value *container,
91345796c8dcSSimon Schubert struct value *lhs, struct expression *exp,
91355796c8dcSSimon Schubert int *pos, LONGEST *indices, int *num_indices,
91365796c8dcSSimon Schubert int max_indices, LONGEST low, LONGEST high)
91375796c8dcSSimon Schubert {
91385796c8dcSSimon Schubert LONGEST ind = longest_to_int (exp->elts[*pos + 1].longconst) + low;
91395796c8dcSSimon Schubert
91405796c8dcSSimon Schubert if (ind - 1 == high)
91415796c8dcSSimon Schubert warning (_("Extra components in aggregate ignored."));
91425796c8dcSSimon Schubert if (ind <= high)
91435796c8dcSSimon Schubert {
91445796c8dcSSimon Schubert add_component_interval (ind, ind, indices, num_indices, max_indices);
91455796c8dcSSimon Schubert *pos += 3;
91465796c8dcSSimon Schubert assign_component (container, lhs, ind, exp, pos);
91475796c8dcSSimon Schubert }
91485796c8dcSSimon Schubert else
91495796c8dcSSimon Schubert ada_evaluate_subexp (NULL, exp, pos, EVAL_SKIP);
91505796c8dcSSimon Schubert }
91515796c8dcSSimon Schubert
91525796c8dcSSimon Schubert /* Assign into the components of LHS indexed by the OP_CHOICES
91535796c8dcSSimon Schubert construct at *POS, updating *POS past the construct, given that
91545796c8dcSSimon Schubert the allowable indices are LOW..HIGH. Record the indices assigned
91555796c8dcSSimon Schubert to in INDICES[0 .. MAX_INDICES-1], updating *NUM_INDICES as
91565796c8dcSSimon Schubert needed. CONTAINER is as for assign_aggregate. */
91575796c8dcSSimon Schubert static void
aggregate_assign_from_choices(struct value * container,struct value * lhs,struct expression * exp,int * pos,LONGEST * indices,int * num_indices,int max_indices,LONGEST low,LONGEST high)91585796c8dcSSimon Schubert aggregate_assign_from_choices (struct value *container,
91595796c8dcSSimon Schubert struct value *lhs, struct expression *exp,
91605796c8dcSSimon Schubert int *pos, LONGEST *indices, int *num_indices,
91615796c8dcSSimon Schubert int max_indices, LONGEST low, LONGEST high)
91625796c8dcSSimon Schubert {
91635796c8dcSSimon Schubert int j;
91645796c8dcSSimon Schubert int n_choices = longest_to_int (exp->elts[*pos+1].longconst);
91655796c8dcSSimon Schubert int choice_pos, expr_pc;
91665796c8dcSSimon Schubert int is_array = ada_is_direct_array_type (value_type (lhs));
91675796c8dcSSimon Schubert
91685796c8dcSSimon Schubert choice_pos = *pos += 3;
91695796c8dcSSimon Schubert
91705796c8dcSSimon Schubert for (j = 0; j < n_choices; j += 1)
91715796c8dcSSimon Schubert ada_evaluate_subexp (NULL, exp, pos, EVAL_SKIP);
91725796c8dcSSimon Schubert expr_pc = *pos;
91735796c8dcSSimon Schubert ada_evaluate_subexp (NULL, exp, pos, EVAL_SKIP);
91745796c8dcSSimon Schubert
91755796c8dcSSimon Schubert for (j = 0; j < n_choices; j += 1)
91765796c8dcSSimon Schubert {
91775796c8dcSSimon Schubert LONGEST lower, upper;
91785796c8dcSSimon Schubert enum exp_opcode op = exp->elts[choice_pos].opcode;
9179cf7f2e2dSJohn Marino
91805796c8dcSSimon Schubert if (op == OP_DISCRETE_RANGE)
91815796c8dcSSimon Schubert {
91825796c8dcSSimon Schubert choice_pos += 1;
91835796c8dcSSimon Schubert lower = value_as_long (ada_evaluate_subexp (NULL, exp, pos,
91845796c8dcSSimon Schubert EVAL_NORMAL));
91855796c8dcSSimon Schubert upper = value_as_long (ada_evaluate_subexp (NULL, exp, pos,
91865796c8dcSSimon Schubert EVAL_NORMAL));
91875796c8dcSSimon Schubert }
91885796c8dcSSimon Schubert else if (is_array)
91895796c8dcSSimon Schubert {
91905796c8dcSSimon Schubert lower = value_as_long (ada_evaluate_subexp (NULL, exp, &choice_pos,
91915796c8dcSSimon Schubert EVAL_NORMAL));
91925796c8dcSSimon Schubert upper = lower;
91935796c8dcSSimon Schubert }
91945796c8dcSSimon Schubert else
91955796c8dcSSimon Schubert {
91965796c8dcSSimon Schubert int ind;
9197*ef5ccd6cSJohn Marino const char *name;
9198cf7f2e2dSJohn Marino
91995796c8dcSSimon Schubert switch (op)
92005796c8dcSSimon Schubert {
92015796c8dcSSimon Schubert case OP_NAME:
92025796c8dcSSimon Schubert name = &exp->elts[choice_pos + 2].string;
92035796c8dcSSimon Schubert break;
92045796c8dcSSimon Schubert case OP_VAR_VALUE:
92055796c8dcSSimon Schubert name = SYMBOL_NATURAL_NAME (exp->elts[choice_pos + 2].symbol);
92065796c8dcSSimon Schubert break;
92075796c8dcSSimon Schubert default:
92085796c8dcSSimon Schubert error (_("Invalid record component association."));
92095796c8dcSSimon Schubert }
92105796c8dcSSimon Schubert ada_evaluate_subexp (NULL, exp, &choice_pos, EVAL_SKIP);
92115796c8dcSSimon Schubert ind = 0;
92125796c8dcSSimon Schubert if (! find_struct_field (name, value_type (lhs), 0,
92135796c8dcSSimon Schubert NULL, NULL, NULL, NULL, &ind))
92145796c8dcSSimon Schubert error (_("Unknown component name: %s."), name);
92155796c8dcSSimon Schubert lower = upper = ind;
92165796c8dcSSimon Schubert }
92175796c8dcSSimon Schubert
92185796c8dcSSimon Schubert if (lower <= upper && (lower < low || upper > high))
92195796c8dcSSimon Schubert error (_("Index in component association out of bounds."));
92205796c8dcSSimon Schubert
92215796c8dcSSimon Schubert add_component_interval (lower, upper, indices, num_indices,
92225796c8dcSSimon Schubert max_indices);
92235796c8dcSSimon Schubert while (lower <= upper)
92245796c8dcSSimon Schubert {
92255796c8dcSSimon Schubert int pos1;
9226cf7f2e2dSJohn Marino
92275796c8dcSSimon Schubert pos1 = expr_pc;
92285796c8dcSSimon Schubert assign_component (container, lhs, lower, exp, &pos1);
92295796c8dcSSimon Schubert lower += 1;
92305796c8dcSSimon Schubert }
92315796c8dcSSimon Schubert }
92325796c8dcSSimon Schubert }
92335796c8dcSSimon Schubert
92345796c8dcSSimon Schubert /* Assign the value of the expression in the OP_OTHERS construct in
92355796c8dcSSimon Schubert EXP at *POS into the components of LHS indexed from LOW .. HIGH that
92365796c8dcSSimon Schubert have not been previously assigned. The index intervals already assigned
92375796c8dcSSimon Schubert are in INDICES[0 .. NUM_INDICES-1]. Updates *POS to after the
9238c50c785cSJohn Marino OP_OTHERS clause. CONTAINER is as for assign_aggregate. */
92395796c8dcSSimon Schubert static void
aggregate_assign_others(struct value * container,struct value * lhs,struct expression * exp,int * pos,LONGEST * indices,int num_indices,LONGEST low,LONGEST high)92405796c8dcSSimon Schubert aggregate_assign_others (struct value *container,
92415796c8dcSSimon Schubert struct value *lhs, struct expression *exp,
92425796c8dcSSimon Schubert int *pos, LONGEST *indices, int num_indices,
92435796c8dcSSimon Schubert LONGEST low, LONGEST high)
92445796c8dcSSimon Schubert {
92455796c8dcSSimon Schubert int i;
92465796c8dcSSimon Schubert int expr_pc = *pos + 1;
92475796c8dcSSimon Schubert
92485796c8dcSSimon Schubert for (i = 0; i < num_indices - 2; i += 2)
92495796c8dcSSimon Schubert {
92505796c8dcSSimon Schubert LONGEST ind;
9251cf7f2e2dSJohn Marino
92525796c8dcSSimon Schubert for (ind = indices[i + 1] + 1; ind < indices[i + 2]; ind += 1)
92535796c8dcSSimon Schubert {
9254c50c785cSJohn Marino int localpos;
9255cf7f2e2dSJohn Marino
9256c50c785cSJohn Marino localpos = expr_pc;
9257c50c785cSJohn Marino assign_component (container, lhs, ind, exp, &localpos);
92585796c8dcSSimon Schubert }
92595796c8dcSSimon Schubert }
92605796c8dcSSimon Schubert ada_evaluate_subexp (NULL, exp, pos, EVAL_SKIP);
92615796c8dcSSimon Schubert }
92625796c8dcSSimon Schubert
92635796c8dcSSimon Schubert /* Add the interval [LOW .. HIGH] to the sorted set of intervals
92645796c8dcSSimon Schubert [ INDICES[0] .. INDICES[1] ],..., [ INDICES[*SIZE-2] .. INDICES[*SIZE-1] ],
92655796c8dcSSimon Schubert modifying *SIZE as needed. It is an error if *SIZE exceeds
92665796c8dcSSimon Schubert MAX_SIZE. The resulting intervals do not overlap. */
92675796c8dcSSimon Schubert static void
add_component_interval(LONGEST low,LONGEST high,LONGEST * indices,int * size,int max_size)92685796c8dcSSimon Schubert add_component_interval (LONGEST low, LONGEST high,
92695796c8dcSSimon Schubert LONGEST* indices, int *size, int max_size)
92705796c8dcSSimon Schubert {
92715796c8dcSSimon Schubert int i, j;
9272cf7f2e2dSJohn Marino
92735796c8dcSSimon Schubert for (i = 0; i < *size; i += 2) {
92745796c8dcSSimon Schubert if (high >= indices[i] && low <= indices[i + 1])
92755796c8dcSSimon Schubert {
92765796c8dcSSimon Schubert int kh;
9277cf7f2e2dSJohn Marino
92785796c8dcSSimon Schubert for (kh = i + 2; kh < *size; kh += 2)
92795796c8dcSSimon Schubert if (high < indices[kh])
92805796c8dcSSimon Schubert break;
92815796c8dcSSimon Schubert if (low < indices[i])
92825796c8dcSSimon Schubert indices[i] = low;
92835796c8dcSSimon Schubert indices[i + 1] = indices[kh - 1];
92845796c8dcSSimon Schubert if (high > indices[i + 1])
92855796c8dcSSimon Schubert indices[i + 1] = high;
92865796c8dcSSimon Schubert memcpy (indices + i + 2, indices + kh, *size - kh);
92875796c8dcSSimon Schubert *size -= kh - i - 2;
92885796c8dcSSimon Schubert return;
92895796c8dcSSimon Schubert }
92905796c8dcSSimon Schubert else if (high < indices[i])
92915796c8dcSSimon Schubert break;
92925796c8dcSSimon Schubert }
92935796c8dcSSimon Schubert
92945796c8dcSSimon Schubert if (*size == max_size)
92955796c8dcSSimon Schubert error (_("Internal error: miscounted aggregate components."));
92965796c8dcSSimon Schubert *size += 2;
92975796c8dcSSimon Schubert for (j = *size-1; j >= i+2; j -= 1)
92985796c8dcSSimon Schubert indices[j] = indices[j - 2];
92995796c8dcSSimon Schubert indices[i] = low;
93005796c8dcSSimon Schubert indices[i + 1] = high;
93015796c8dcSSimon Schubert }
93025796c8dcSSimon Schubert
93035796c8dcSSimon Schubert /* Perform and Ada cast of ARG2 to type TYPE if the type of ARG2
93045796c8dcSSimon Schubert is different. */
93055796c8dcSSimon Schubert
93065796c8dcSSimon Schubert static struct value *
ada_value_cast(struct type * type,struct value * arg2,enum noside noside)93075796c8dcSSimon Schubert ada_value_cast (struct type *type, struct value *arg2, enum noside noside)
93085796c8dcSSimon Schubert {
93095796c8dcSSimon Schubert if (type == ada_check_typedef (value_type (arg2)))
93105796c8dcSSimon Schubert return arg2;
93115796c8dcSSimon Schubert
93125796c8dcSSimon Schubert if (ada_is_fixed_point_type (type))
93135796c8dcSSimon Schubert return (cast_to_fixed (type, arg2));
93145796c8dcSSimon Schubert
93155796c8dcSSimon Schubert if (ada_is_fixed_point_type (value_type (arg2)))
93165796c8dcSSimon Schubert return cast_from_fixed (type, arg2);
93175796c8dcSSimon Schubert
93185796c8dcSSimon Schubert return value_cast (type, arg2);
93195796c8dcSSimon Schubert }
93205796c8dcSSimon Schubert
93215796c8dcSSimon Schubert /* Evaluating Ada expressions, and printing their result.
93225796c8dcSSimon Schubert ------------------------------------------------------
93235796c8dcSSimon Schubert
9324cf7f2e2dSJohn Marino 1. Introduction:
9325cf7f2e2dSJohn Marino ----------------
9326cf7f2e2dSJohn Marino
93275796c8dcSSimon Schubert We usually evaluate an Ada expression in order to print its value.
93285796c8dcSSimon Schubert We also evaluate an expression in order to print its type, which
93295796c8dcSSimon Schubert happens during the EVAL_AVOID_SIDE_EFFECTS phase of the evaluation,
93305796c8dcSSimon Schubert but we'll focus mostly on the EVAL_NORMAL phase. In practice, the
93315796c8dcSSimon Schubert EVAL_AVOID_SIDE_EFFECTS phase allows us to simplify certain aspects of
93325796c8dcSSimon Schubert the evaluation compared to the EVAL_NORMAL, but is otherwise very
93335796c8dcSSimon Schubert similar.
93345796c8dcSSimon Schubert
93355796c8dcSSimon Schubert Evaluating expressions is a little more complicated for Ada entities
93365796c8dcSSimon Schubert than it is for entities in languages such as C. The main reason for
93375796c8dcSSimon Schubert this is that Ada provides types whose definition might be dynamic.
93385796c8dcSSimon Schubert One example of such types is variant records. Or another example
93395796c8dcSSimon Schubert would be an array whose bounds can only be known at run time.
93405796c8dcSSimon Schubert
93415796c8dcSSimon Schubert The following description is a general guide as to what should be
93425796c8dcSSimon Schubert done (and what should NOT be done) in order to evaluate an expression
93435796c8dcSSimon Schubert involving such types, and when. This does not cover how the semantic
93445796c8dcSSimon Schubert information is encoded by GNAT as this is covered separatly. For the
93455796c8dcSSimon Schubert document used as the reference for the GNAT encoding, see exp_dbug.ads
93465796c8dcSSimon Schubert in the GNAT sources.
93475796c8dcSSimon Schubert
93485796c8dcSSimon Schubert Ideally, we should embed each part of this description next to its
93495796c8dcSSimon Schubert associated code. Unfortunately, the amount of code is so vast right
93505796c8dcSSimon Schubert now that it's hard to see whether the code handling a particular
93515796c8dcSSimon Schubert situation might be duplicated or not. One day, when the code is
93525796c8dcSSimon Schubert cleaned up, this guide might become redundant with the comments
93535796c8dcSSimon Schubert inserted in the code, and we might want to remove it.
93545796c8dcSSimon Schubert
9355cf7f2e2dSJohn Marino 2. ``Fixing'' an Entity, the Simple Case:
9356cf7f2e2dSJohn Marino -----------------------------------------
9357cf7f2e2dSJohn Marino
93585796c8dcSSimon Schubert When evaluating Ada expressions, the tricky issue is that they may
93595796c8dcSSimon Schubert reference entities whose type contents and size are not statically
93605796c8dcSSimon Schubert known. Consider for instance a variant record:
93615796c8dcSSimon Schubert
93625796c8dcSSimon Schubert type Rec (Empty : Boolean := True) is record
93635796c8dcSSimon Schubert case Empty is
93645796c8dcSSimon Schubert when True => null;
93655796c8dcSSimon Schubert when False => Value : Integer;
93665796c8dcSSimon Schubert end case;
93675796c8dcSSimon Schubert end record;
93685796c8dcSSimon Schubert Yes : Rec := (Empty => False, Value => 1);
93695796c8dcSSimon Schubert No : Rec := (empty => True);
93705796c8dcSSimon Schubert
93715796c8dcSSimon Schubert The size and contents of that record depends on the value of the
93725796c8dcSSimon Schubert descriminant (Rec.Empty). At this point, neither the debugging
93735796c8dcSSimon Schubert information nor the associated type structure in GDB are able to
93745796c8dcSSimon Schubert express such dynamic types. So what the debugger does is to create
93755796c8dcSSimon Schubert "fixed" versions of the type that applies to the specific object.
93765796c8dcSSimon Schubert We also informally refer to this opperation as "fixing" an object,
93775796c8dcSSimon Schubert which means creating its associated fixed type.
93785796c8dcSSimon Schubert
93795796c8dcSSimon Schubert Example: when printing the value of variable "Yes" above, its fixed
93805796c8dcSSimon Schubert type would look like this:
93815796c8dcSSimon Schubert
93825796c8dcSSimon Schubert type Rec is record
93835796c8dcSSimon Schubert Empty : Boolean;
93845796c8dcSSimon Schubert Value : Integer;
93855796c8dcSSimon Schubert end record;
93865796c8dcSSimon Schubert
93875796c8dcSSimon Schubert On the other hand, if we printed the value of "No", its fixed type
93885796c8dcSSimon Schubert would become:
93895796c8dcSSimon Schubert
93905796c8dcSSimon Schubert type Rec is record
93915796c8dcSSimon Schubert Empty : Boolean;
93925796c8dcSSimon Schubert end record;
93935796c8dcSSimon Schubert
93945796c8dcSSimon Schubert Things become a little more complicated when trying to fix an entity
93955796c8dcSSimon Schubert with a dynamic type that directly contains another dynamic type,
93965796c8dcSSimon Schubert such as an array of variant records, for instance. There are
93975796c8dcSSimon Schubert two possible cases: Arrays, and records.
93985796c8dcSSimon Schubert
9399cf7f2e2dSJohn Marino 3. ``Fixing'' Arrays:
9400cf7f2e2dSJohn Marino ---------------------
9401cf7f2e2dSJohn Marino
9402cf7f2e2dSJohn Marino The type structure in GDB describes an array in terms of its bounds,
9403cf7f2e2dSJohn Marino and the type of its elements. By design, all elements in the array
9404cf7f2e2dSJohn Marino have the same type and we cannot represent an array of variant elements
9405cf7f2e2dSJohn Marino using the current type structure in GDB. When fixing an array,
9406cf7f2e2dSJohn Marino we cannot fix the array element, as we would potentially need one
9407cf7f2e2dSJohn Marino fixed type per element of the array. As a result, the best we can do
9408cf7f2e2dSJohn Marino when fixing an array is to produce an array whose bounds and size
9409cf7f2e2dSJohn Marino are correct (allowing us to read it from memory), but without having
9410cf7f2e2dSJohn Marino touched its element type. Fixing each element will be done later,
9411cf7f2e2dSJohn Marino when (if) necessary.
9412cf7f2e2dSJohn Marino
9413cf7f2e2dSJohn Marino Arrays are a little simpler to handle than records, because the same
9414cf7f2e2dSJohn Marino amount of memory is allocated for each element of the array, even if
9415cf7f2e2dSJohn Marino the amount of space actually used by each element differs from element
9416cf7f2e2dSJohn Marino to element. Consider for instance the following array of type Rec:
94175796c8dcSSimon Schubert
94185796c8dcSSimon Schubert type Rec_Array is array (1 .. 2) of Rec;
94195796c8dcSSimon Schubert
9420cf7f2e2dSJohn Marino The actual amount of memory occupied by each element might be different
9421cf7f2e2dSJohn Marino from element to element, depending on the value of their discriminant.
9422cf7f2e2dSJohn Marino But the amount of space reserved for each element in the array remains
9423cf7f2e2dSJohn Marino fixed regardless. So we simply need to compute that size using
9424cf7f2e2dSJohn Marino the debugging information available, from which we can then determine
9425cf7f2e2dSJohn Marino the array size (we multiply the number of elements of the array by
9426cf7f2e2dSJohn Marino the size of each element).
94275796c8dcSSimon Schubert
9428cf7f2e2dSJohn Marino The simplest case is when we have an array of a constrained element
9429cf7f2e2dSJohn Marino type. For instance, consider the following type declarations:
9430cf7f2e2dSJohn Marino
9431cf7f2e2dSJohn Marino type Bounded_String (Max_Size : Integer) is
9432cf7f2e2dSJohn Marino Length : Integer;
9433cf7f2e2dSJohn Marino Buffer : String (1 .. Max_Size);
9434cf7f2e2dSJohn Marino end record;
9435cf7f2e2dSJohn Marino type Bounded_String_Array is array (1 ..2) of Bounded_String (80);
9436cf7f2e2dSJohn Marino
9437cf7f2e2dSJohn Marino In this case, the compiler describes the array as an array of
9438cf7f2e2dSJohn Marino variable-size elements (identified by its XVS suffix) for which
9439cf7f2e2dSJohn Marino the size can be read in the parallel XVZ variable.
9440cf7f2e2dSJohn Marino
9441cf7f2e2dSJohn Marino In the case of an array of an unconstrained element type, the compiler
9442cf7f2e2dSJohn Marino wraps the array element inside a private PAD type. This type should not
94435796c8dcSSimon Schubert be shown to the user, and must be "unwrap"'ed before printing. Note
94445796c8dcSSimon Schubert that we also use the adjective "aligner" in our code to designate
94455796c8dcSSimon Schubert these wrapper types.
94465796c8dcSSimon Schubert
9447cf7f2e2dSJohn Marino In some cases, the size allocated for each element is statically
9448cf7f2e2dSJohn Marino known. In that case, the PAD type already has the correct size,
9449cf7f2e2dSJohn Marino and the array element should remain unfixed.
9450cf7f2e2dSJohn Marino
9451cf7f2e2dSJohn Marino But there are cases when this size is not statically known.
9452cf7f2e2dSJohn Marino For instance, assuming that "Five" is an integer variable:
94535796c8dcSSimon Schubert
94545796c8dcSSimon Schubert type Dynamic is array (1 .. Five) of Integer;
94555796c8dcSSimon Schubert type Wrapper (Has_Length : Boolean := False) is record
94565796c8dcSSimon Schubert Data : Dynamic;
94575796c8dcSSimon Schubert case Has_Length is
94585796c8dcSSimon Schubert when True => Length : Integer;
94595796c8dcSSimon Schubert when False => null;
94605796c8dcSSimon Schubert end case;
94615796c8dcSSimon Schubert end record;
94625796c8dcSSimon Schubert type Wrapper_Array is array (1 .. 2) of Wrapper;
94635796c8dcSSimon Schubert
94645796c8dcSSimon Schubert Hello : Wrapper_Array := (others => (Has_Length => True,
94655796c8dcSSimon Schubert Data => (others => 17),
94665796c8dcSSimon Schubert Length => 1));
94675796c8dcSSimon Schubert
94685796c8dcSSimon Schubert
94695796c8dcSSimon Schubert The debugging info would describe variable Hello as being an
94705796c8dcSSimon Schubert array of a PAD type. The size of that PAD type is not statically
94715796c8dcSSimon Schubert known, but can be determined using a parallel XVZ variable.
94725796c8dcSSimon Schubert In that case, a copy of the PAD type with the correct size should
94735796c8dcSSimon Schubert be used for the fixed array.
94745796c8dcSSimon Schubert
9475cf7f2e2dSJohn Marino 3. ``Fixing'' record type objects:
9476cf7f2e2dSJohn Marino ----------------------------------
9477cf7f2e2dSJohn Marino
9478cf7f2e2dSJohn Marino Things are slightly different from arrays in the case of dynamic
94795796c8dcSSimon Schubert record types. In this case, in order to compute the associated
94805796c8dcSSimon Schubert fixed type, we need to determine the size and offset of each of
94815796c8dcSSimon Schubert its components. This, in turn, requires us to compute the fixed
94825796c8dcSSimon Schubert type of each of these components.
94835796c8dcSSimon Schubert
94845796c8dcSSimon Schubert Consider for instance the example:
94855796c8dcSSimon Schubert
94865796c8dcSSimon Schubert type Bounded_String (Max_Size : Natural) is record
94875796c8dcSSimon Schubert Str : String (1 .. Max_Size);
94885796c8dcSSimon Schubert Length : Natural;
94895796c8dcSSimon Schubert end record;
94905796c8dcSSimon Schubert My_String : Bounded_String (Max_Size => 10);
94915796c8dcSSimon Schubert
94925796c8dcSSimon Schubert In that case, the position of field "Length" depends on the size
94935796c8dcSSimon Schubert of field Str, which itself depends on the value of the Max_Size
94945796c8dcSSimon Schubert discriminant. In order to fix the type of variable My_String,
94955796c8dcSSimon Schubert we need to fix the type of field Str. Therefore, fixing a variant
94965796c8dcSSimon Schubert record requires us to fix each of its components.
94975796c8dcSSimon Schubert
94985796c8dcSSimon Schubert However, if a component does not have a dynamic size, the component
94995796c8dcSSimon Schubert should not be fixed. In particular, fields that use a PAD type
95005796c8dcSSimon Schubert should not fixed. Here is an example where this might happen
95015796c8dcSSimon Schubert (assuming type Rec above):
95025796c8dcSSimon Schubert
95035796c8dcSSimon Schubert type Container (Big : Boolean) is record
95045796c8dcSSimon Schubert First : Rec;
95055796c8dcSSimon Schubert After : Integer;
95065796c8dcSSimon Schubert case Big is
95075796c8dcSSimon Schubert when True => Another : Integer;
95085796c8dcSSimon Schubert when False => null;
95095796c8dcSSimon Schubert end case;
95105796c8dcSSimon Schubert end record;
95115796c8dcSSimon Schubert My_Container : Container := (Big => False,
95125796c8dcSSimon Schubert First => (Empty => True),
95135796c8dcSSimon Schubert After => 42);
95145796c8dcSSimon Schubert
95155796c8dcSSimon Schubert In that example, the compiler creates a PAD type for component First,
95165796c8dcSSimon Schubert whose size is constant, and then positions the component After just
95175796c8dcSSimon Schubert right after it. The offset of component After is therefore constant
95185796c8dcSSimon Schubert in this case.
95195796c8dcSSimon Schubert
95205796c8dcSSimon Schubert The debugger computes the position of each field based on an algorithm
95215796c8dcSSimon Schubert that uses, among other things, the actual position and size of the field
9522cf7f2e2dSJohn Marino preceding it. Let's now imagine that the user is trying to print
9523cf7f2e2dSJohn Marino the value of My_Container. If the type fixing was recursive, we would
95245796c8dcSSimon Schubert end up computing the offset of field After based on the size of the
95255796c8dcSSimon Schubert fixed version of field First. And since in our example First has
95265796c8dcSSimon Schubert only one actual field, the size of the fixed type is actually smaller
95275796c8dcSSimon Schubert than the amount of space allocated to that field, and thus we would
95285796c8dcSSimon Schubert compute the wrong offset of field After.
95295796c8dcSSimon Schubert
9530cf7f2e2dSJohn Marino To make things more complicated, we need to watch out for dynamic
9531cf7f2e2dSJohn Marino components of variant records (identified by the ___XVL suffix in
9532cf7f2e2dSJohn Marino the component name). Even if the target type is a PAD type, the size
9533cf7f2e2dSJohn Marino of that type might not be statically known. So the PAD type needs
9534cf7f2e2dSJohn Marino to be unwrapped and the resulting type needs to be fixed. Otherwise,
9535cf7f2e2dSJohn Marino we might end up with the wrong size for our component. This can be
9536cf7f2e2dSJohn Marino observed with the following type declarations:
95375796c8dcSSimon Schubert
95385796c8dcSSimon Schubert type Octal is new Integer range 0 .. 7;
95395796c8dcSSimon Schubert type Octal_Array is array (Positive range <>) of Octal;
95405796c8dcSSimon Schubert pragma Pack (Octal_Array);
95415796c8dcSSimon Schubert
95425796c8dcSSimon Schubert type Octal_Buffer (Size : Positive) is record
95435796c8dcSSimon Schubert Buffer : Octal_Array (1 .. Size);
95445796c8dcSSimon Schubert Length : Integer;
95455796c8dcSSimon Schubert end record;
95465796c8dcSSimon Schubert
95475796c8dcSSimon Schubert In that case, Buffer is a PAD type whose size is unset and needs
95485796c8dcSSimon Schubert to be computed by fixing the unwrapped type.
95495796c8dcSSimon Schubert
9550cf7f2e2dSJohn Marino 4. When to ``Fix'' un-``Fixed'' sub-elements of an entity:
9551cf7f2e2dSJohn Marino ----------------------------------------------------------
9552cf7f2e2dSJohn Marino
9553cf7f2e2dSJohn Marino Lastly, when should the sub-elements of an entity that remained unfixed
95545796c8dcSSimon Schubert thus far, be actually fixed?
95555796c8dcSSimon Schubert
95565796c8dcSSimon Schubert The answer is: Only when referencing that element. For instance
95575796c8dcSSimon Schubert when selecting one component of a record, this specific component
95585796c8dcSSimon Schubert should be fixed at that point in time. Or when printing the value
95595796c8dcSSimon Schubert of a record, each component should be fixed before its value gets
95605796c8dcSSimon Schubert printed. Similarly for arrays, the element of the array should be
95615796c8dcSSimon Schubert fixed when printing each element of the array, or when extracting
95625796c8dcSSimon Schubert one element out of that array. On the other hand, fixing should
95635796c8dcSSimon Schubert not be performed on the elements when taking a slice of an array!
95645796c8dcSSimon Schubert
95655796c8dcSSimon Schubert Note that one of the side-effects of miscomputing the offset and
95665796c8dcSSimon Schubert size of each field is that we end up also miscomputing the size
95675796c8dcSSimon Schubert of the containing type. This can have adverse results when computing
95685796c8dcSSimon Schubert the value of an entity. GDB fetches the value of an entity based
95695796c8dcSSimon Schubert on the size of its type, and thus a wrong size causes GDB to fetch
95705796c8dcSSimon Schubert the wrong amount of memory. In the case where the computed size is
95715796c8dcSSimon Schubert too small, GDB fetches too little data to print the value of our
95725796c8dcSSimon Schubert entiry. Results in this case as unpredicatble, as we usually read
95735796c8dcSSimon Schubert past the buffer containing the data =:-o. */
95745796c8dcSSimon Schubert
95755796c8dcSSimon Schubert /* Implement the evaluate_exp routine in the exp_descriptor structure
95765796c8dcSSimon Schubert for the Ada language. */
95775796c8dcSSimon Schubert
95785796c8dcSSimon Schubert static struct value *
ada_evaluate_subexp(struct type * expect_type,struct expression * exp,int * pos,enum noside noside)95795796c8dcSSimon Schubert ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
95805796c8dcSSimon Schubert int *pos, enum noside noside)
95815796c8dcSSimon Schubert {
95825796c8dcSSimon Schubert enum exp_opcode op;
9583cf7f2e2dSJohn Marino int tem;
95845796c8dcSSimon Schubert int pc;
95855796c8dcSSimon Schubert struct value *arg1 = NULL, *arg2 = NULL, *arg3;
95865796c8dcSSimon Schubert struct type *type;
95875796c8dcSSimon Schubert int nargs, oplen;
95885796c8dcSSimon Schubert struct value **argvec;
95895796c8dcSSimon Schubert
95905796c8dcSSimon Schubert pc = *pos;
95915796c8dcSSimon Schubert *pos += 1;
95925796c8dcSSimon Schubert op = exp->elts[pc].opcode;
95935796c8dcSSimon Schubert
95945796c8dcSSimon Schubert switch (op)
95955796c8dcSSimon Schubert {
95965796c8dcSSimon Schubert default:
95975796c8dcSSimon Schubert *pos -= 1;
95985796c8dcSSimon Schubert arg1 = evaluate_subexp_standard (expect_type, exp, pos, noside);
9599*ef5ccd6cSJohn Marino
9600*ef5ccd6cSJohn Marino if (noside == EVAL_NORMAL)
96015796c8dcSSimon Schubert arg1 = unwrap_value (arg1);
96025796c8dcSSimon Schubert
96035796c8dcSSimon Schubert /* If evaluating an OP_DOUBLE and an EXPECT_TYPE was provided,
96045796c8dcSSimon Schubert then we need to perform the conversion manually, because
96055796c8dcSSimon Schubert evaluate_subexp_standard doesn't do it. This conversion is
96065796c8dcSSimon Schubert necessary in Ada because the different kinds of float/fixed
96075796c8dcSSimon Schubert types in Ada have different representations.
96085796c8dcSSimon Schubert
96095796c8dcSSimon Schubert Similarly, we need to perform the conversion from OP_LONG
96105796c8dcSSimon Schubert ourselves. */
96115796c8dcSSimon Schubert if ((op == OP_DOUBLE || op == OP_LONG) && expect_type != NULL)
96125796c8dcSSimon Schubert arg1 = ada_value_cast (expect_type, arg1, noside);
96135796c8dcSSimon Schubert
96145796c8dcSSimon Schubert return arg1;
96155796c8dcSSimon Schubert
96165796c8dcSSimon Schubert case OP_STRING:
96175796c8dcSSimon Schubert {
96185796c8dcSSimon Schubert struct value *result;
9619cf7f2e2dSJohn Marino
96205796c8dcSSimon Schubert *pos -= 1;
96215796c8dcSSimon Schubert result = evaluate_subexp_standard (expect_type, exp, pos, noside);
96225796c8dcSSimon Schubert /* The result type will have code OP_STRING, bashed there from
96235796c8dcSSimon Schubert OP_ARRAY. Bash it back. */
96245796c8dcSSimon Schubert if (TYPE_CODE (value_type (result)) == TYPE_CODE_STRING)
96255796c8dcSSimon Schubert TYPE_CODE (value_type (result)) = TYPE_CODE_ARRAY;
96265796c8dcSSimon Schubert return result;
96275796c8dcSSimon Schubert }
96285796c8dcSSimon Schubert
96295796c8dcSSimon Schubert case UNOP_CAST:
96305796c8dcSSimon Schubert (*pos) += 2;
96315796c8dcSSimon Schubert type = exp->elts[pc + 1].type;
96325796c8dcSSimon Schubert arg1 = evaluate_subexp (type, exp, pos, noside);
96335796c8dcSSimon Schubert if (noside == EVAL_SKIP)
96345796c8dcSSimon Schubert goto nosideret;
96355796c8dcSSimon Schubert arg1 = ada_value_cast (type, arg1, noside);
96365796c8dcSSimon Schubert return arg1;
96375796c8dcSSimon Schubert
96385796c8dcSSimon Schubert case UNOP_QUAL:
96395796c8dcSSimon Schubert (*pos) += 2;
96405796c8dcSSimon Schubert type = exp->elts[pc + 1].type;
96415796c8dcSSimon Schubert return ada_evaluate_subexp (type, exp, pos, noside);
96425796c8dcSSimon Schubert
96435796c8dcSSimon Schubert case BINOP_ASSIGN:
96445796c8dcSSimon Schubert arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
96455796c8dcSSimon Schubert if (exp->elts[*pos].opcode == OP_AGGREGATE)
96465796c8dcSSimon Schubert {
96475796c8dcSSimon Schubert arg1 = assign_aggregate (arg1, arg1, exp, pos, noside);
96485796c8dcSSimon Schubert if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
96495796c8dcSSimon Schubert return arg1;
96505796c8dcSSimon Schubert return ada_value_assign (arg1, arg1);
96515796c8dcSSimon Schubert }
96525796c8dcSSimon Schubert /* Force the evaluation of the rhs ARG2 to the type of the lhs ARG1,
96535796c8dcSSimon Schubert except if the lhs of our assignment is a convenience variable.
96545796c8dcSSimon Schubert In the case of assigning to a convenience variable, the lhs
96555796c8dcSSimon Schubert should be exactly the result of the evaluation of the rhs. */
96565796c8dcSSimon Schubert type = value_type (arg1);
96575796c8dcSSimon Schubert if (VALUE_LVAL (arg1) == lval_internalvar)
96585796c8dcSSimon Schubert type = NULL;
96595796c8dcSSimon Schubert arg2 = evaluate_subexp (type, exp, pos, noside);
96605796c8dcSSimon Schubert if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
96615796c8dcSSimon Schubert return arg1;
96625796c8dcSSimon Schubert if (ada_is_fixed_point_type (value_type (arg1)))
96635796c8dcSSimon Schubert arg2 = cast_to_fixed (value_type (arg1), arg2);
96645796c8dcSSimon Schubert else if (ada_is_fixed_point_type (value_type (arg2)))
96655796c8dcSSimon Schubert error
96665796c8dcSSimon Schubert (_("Fixed-point values must be assigned to fixed-point variables"));
96675796c8dcSSimon Schubert else
96685796c8dcSSimon Schubert arg2 = coerce_for_assign (value_type (arg1), arg2);
96695796c8dcSSimon Schubert return ada_value_assign (arg1, arg2);
96705796c8dcSSimon Schubert
96715796c8dcSSimon Schubert case BINOP_ADD:
96725796c8dcSSimon Schubert arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
96735796c8dcSSimon Schubert arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
96745796c8dcSSimon Schubert if (noside == EVAL_SKIP)
96755796c8dcSSimon Schubert goto nosideret;
96765796c8dcSSimon Schubert if (TYPE_CODE (value_type (arg1)) == TYPE_CODE_PTR)
96775796c8dcSSimon Schubert return (value_from_longest
96785796c8dcSSimon Schubert (value_type (arg1),
96795796c8dcSSimon Schubert value_as_long (arg1) + value_as_long (arg2)));
96805796c8dcSSimon Schubert if ((ada_is_fixed_point_type (value_type (arg1))
96815796c8dcSSimon Schubert || ada_is_fixed_point_type (value_type (arg2)))
96825796c8dcSSimon Schubert && value_type (arg1) != value_type (arg2))
96835796c8dcSSimon Schubert error (_("Operands of fixed-point addition must have the same type"));
96845796c8dcSSimon Schubert /* Do the addition, and cast the result to the type of the first
96855796c8dcSSimon Schubert argument. We cannot cast the result to a reference type, so if
96865796c8dcSSimon Schubert ARG1 is a reference type, find its underlying type. */
96875796c8dcSSimon Schubert type = value_type (arg1);
96885796c8dcSSimon Schubert while (TYPE_CODE (type) == TYPE_CODE_REF)
96895796c8dcSSimon Schubert type = TYPE_TARGET_TYPE (type);
96905796c8dcSSimon Schubert binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
96915796c8dcSSimon Schubert return value_cast (type, value_binop (arg1, arg2, BINOP_ADD));
96925796c8dcSSimon Schubert
96935796c8dcSSimon Schubert case BINOP_SUB:
96945796c8dcSSimon Schubert arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
96955796c8dcSSimon Schubert arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
96965796c8dcSSimon Schubert if (noside == EVAL_SKIP)
96975796c8dcSSimon Schubert goto nosideret;
96985796c8dcSSimon Schubert if (TYPE_CODE (value_type (arg1)) == TYPE_CODE_PTR)
96995796c8dcSSimon Schubert return (value_from_longest
97005796c8dcSSimon Schubert (value_type (arg1),
97015796c8dcSSimon Schubert value_as_long (arg1) - value_as_long (arg2)));
97025796c8dcSSimon Schubert if ((ada_is_fixed_point_type (value_type (arg1))
97035796c8dcSSimon Schubert || ada_is_fixed_point_type (value_type (arg2)))
97045796c8dcSSimon Schubert && value_type (arg1) != value_type (arg2))
9705c50c785cSJohn Marino error (_("Operands of fixed-point subtraction "
9706c50c785cSJohn Marino "must have the same type"));
97075796c8dcSSimon Schubert /* Do the substraction, and cast the result to the type of the first
97085796c8dcSSimon Schubert argument. We cannot cast the result to a reference type, so if
97095796c8dcSSimon Schubert ARG1 is a reference type, find its underlying type. */
97105796c8dcSSimon Schubert type = value_type (arg1);
97115796c8dcSSimon Schubert while (TYPE_CODE (type) == TYPE_CODE_REF)
97125796c8dcSSimon Schubert type = TYPE_TARGET_TYPE (type);
97135796c8dcSSimon Schubert binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
97145796c8dcSSimon Schubert return value_cast (type, value_binop (arg1, arg2, BINOP_SUB));
97155796c8dcSSimon Schubert
97165796c8dcSSimon Schubert case BINOP_MUL:
97175796c8dcSSimon Schubert case BINOP_DIV:
97185796c8dcSSimon Schubert case BINOP_REM:
97195796c8dcSSimon Schubert case BINOP_MOD:
97205796c8dcSSimon Schubert arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
97215796c8dcSSimon Schubert arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
97225796c8dcSSimon Schubert if (noside == EVAL_SKIP)
97235796c8dcSSimon Schubert goto nosideret;
97245796c8dcSSimon Schubert else if (noside == EVAL_AVOID_SIDE_EFFECTS)
97255796c8dcSSimon Schubert {
97265796c8dcSSimon Schubert binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
97275796c8dcSSimon Schubert return value_zero (value_type (arg1), not_lval);
97285796c8dcSSimon Schubert }
97295796c8dcSSimon Schubert else
97305796c8dcSSimon Schubert {
97315796c8dcSSimon Schubert type = builtin_type (exp->gdbarch)->builtin_double;
97325796c8dcSSimon Schubert if (ada_is_fixed_point_type (value_type (arg1)))
97335796c8dcSSimon Schubert arg1 = cast_from_fixed (type, arg1);
97345796c8dcSSimon Schubert if (ada_is_fixed_point_type (value_type (arg2)))
97355796c8dcSSimon Schubert arg2 = cast_from_fixed (type, arg2);
97365796c8dcSSimon Schubert binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
97375796c8dcSSimon Schubert return ada_value_binop (arg1, arg2, op);
97385796c8dcSSimon Schubert }
97395796c8dcSSimon Schubert
97405796c8dcSSimon Schubert case BINOP_EQUAL:
97415796c8dcSSimon Schubert case BINOP_NOTEQUAL:
97425796c8dcSSimon Schubert arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
97435796c8dcSSimon Schubert arg2 = evaluate_subexp (value_type (arg1), exp, pos, noside);
97445796c8dcSSimon Schubert if (noside == EVAL_SKIP)
97455796c8dcSSimon Schubert goto nosideret;
97465796c8dcSSimon Schubert if (noside == EVAL_AVOID_SIDE_EFFECTS)
97475796c8dcSSimon Schubert tem = 0;
97485796c8dcSSimon Schubert else
97495796c8dcSSimon Schubert {
97505796c8dcSSimon Schubert binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
97515796c8dcSSimon Schubert tem = ada_value_equal (arg1, arg2);
97525796c8dcSSimon Schubert }
97535796c8dcSSimon Schubert if (op == BINOP_NOTEQUAL)
97545796c8dcSSimon Schubert tem = !tem;
97555796c8dcSSimon Schubert type = language_bool_type (exp->language_defn, exp->gdbarch);
97565796c8dcSSimon Schubert return value_from_longest (type, (LONGEST) tem);
97575796c8dcSSimon Schubert
97585796c8dcSSimon Schubert case UNOP_NEG:
97595796c8dcSSimon Schubert arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
97605796c8dcSSimon Schubert if (noside == EVAL_SKIP)
97615796c8dcSSimon Schubert goto nosideret;
97625796c8dcSSimon Schubert else if (ada_is_fixed_point_type (value_type (arg1)))
97635796c8dcSSimon Schubert return value_cast (value_type (arg1), value_neg (arg1));
97645796c8dcSSimon Schubert else
97655796c8dcSSimon Schubert {
97665796c8dcSSimon Schubert unop_promote (exp->language_defn, exp->gdbarch, &arg1);
97675796c8dcSSimon Schubert return value_neg (arg1);
97685796c8dcSSimon Schubert }
97695796c8dcSSimon Schubert
97705796c8dcSSimon Schubert case BINOP_LOGICAL_AND:
97715796c8dcSSimon Schubert case BINOP_LOGICAL_OR:
97725796c8dcSSimon Schubert case UNOP_LOGICAL_NOT:
97735796c8dcSSimon Schubert {
97745796c8dcSSimon Schubert struct value *val;
97755796c8dcSSimon Schubert
97765796c8dcSSimon Schubert *pos -= 1;
97775796c8dcSSimon Schubert val = evaluate_subexp_standard (expect_type, exp, pos, noside);
97785796c8dcSSimon Schubert type = language_bool_type (exp->language_defn, exp->gdbarch);
97795796c8dcSSimon Schubert return value_cast (type, val);
97805796c8dcSSimon Schubert }
97815796c8dcSSimon Schubert
97825796c8dcSSimon Schubert case BINOP_BITWISE_AND:
97835796c8dcSSimon Schubert case BINOP_BITWISE_IOR:
97845796c8dcSSimon Schubert case BINOP_BITWISE_XOR:
97855796c8dcSSimon Schubert {
97865796c8dcSSimon Schubert struct value *val;
97875796c8dcSSimon Schubert
97885796c8dcSSimon Schubert arg1 = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
97895796c8dcSSimon Schubert *pos = pc;
97905796c8dcSSimon Schubert val = evaluate_subexp_standard (expect_type, exp, pos, noside);
97915796c8dcSSimon Schubert
97925796c8dcSSimon Schubert return value_cast (value_type (arg1), val);
97935796c8dcSSimon Schubert }
97945796c8dcSSimon Schubert
97955796c8dcSSimon Schubert case OP_VAR_VALUE:
97965796c8dcSSimon Schubert *pos -= 1;
97975796c8dcSSimon Schubert
97985796c8dcSSimon Schubert if (noside == EVAL_SKIP)
97995796c8dcSSimon Schubert {
98005796c8dcSSimon Schubert *pos += 4;
98015796c8dcSSimon Schubert goto nosideret;
98025796c8dcSSimon Schubert }
98035796c8dcSSimon Schubert else if (SYMBOL_DOMAIN (exp->elts[pc + 2].symbol) == UNDEF_DOMAIN)
98045796c8dcSSimon Schubert /* Only encountered when an unresolved symbol occurs in a
98055796c8dcSSimon Schubert context other than a function call, in which case, it is
98065796c8dcSSimon Schubert invalid. */
98075796c8dcSSimon Schubert error (_("Unexpected unresolved symbol, %s, during evaluation"),
98085796c8dcSSimon Schubert SYMBOL_PRINT_NAME (exp->elts[pc + 2].symbol));
98095796c8dcSSimon Schubert else if (noside == EVAL_AVOID_SIDE_EFFECTS)
98105796c8dcSSimon Schubert {
98115796c8dcSSimon Schubert type = static_unwrap_type (SYMBOL_TYPE (exp->elts[pc + 2].symbol));
9812cf7f2e2dSJohn Marino /* Check to see if this is a tagged type. We also need to handle
9813cf7f2e2dSJohn Marino the case where the type is a reference to a tagged type, but
9814cf7f2e2dSJohn Marino we have to be careful to exclude pointers to tagged types.
9815cf7f2e2dSJohn Marino The latter should be shown as usual (as a pointer), whereas
9816cf7f2e2dSJohn Marino a reference should mostly be transparent to the user. */
9817cf7f2e2dSJohn Marino if (ada_is_tagged_type (type, 0)
9818cf7f2e2dSJohn Marino || (TYPE_CODE(type) == TYPE_CODE_REF
9819cf7f2e2dSJohn Marino && ada_is_tagged_type (TYPE_TARGET_TYPE (type), 0)))
98205796c8dcSSimon Schubert {
98215796c8dcSSimon Schubert /* Tagged types are a little special in the fact that the real
98225796c8dcSSimon Schubert type is dynamic and can only be determined by inspecting the
98235796c8dcSSimon Schubert object's tag. This means that we need to get the object's
98245796c8dcSSimon Schubert value first (EVAL_NORMAL) and then extract the actual object
98255796c8dcSSimon Schubert type from its tag.
98265796c8dcSSimon Schubert
98275796c8dcSSimon Schubert Note that we cannot skip the final step where we extract
98285796c8dcSSimon Schubert the object type from its tag, because the EVAL_NORMAL phase
98295796c8dcSSimon Schubert results in dynamic components being resolved into fixed ones.
98305796c8dcSSimon Schubert This can cause problems when trying to print the type
98315796c8dcSSimon Schubert description of tagged types whose parent has a dynamic size:
98325796c8dcSSimon Schubert We use the type name of the "_parent" component in order
98335796c8dcSSimon Schubert to print the name of the ancestor type in the type description.
98345796c8dcSSimon Schubert If that component had a dynamic size, the resolution into
98355796c8dcSSimon Schubert a fixed type would result in the loss of that type name,
98365796c8dcSSimon Schubert thus preventing us from printing the name of the ancestor
98375796c8dcSSimon Schubert type in the type description. */
9838*ef5ccd6cSJohn Marino arg1 = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_NORMAL);
9839*ef5ccd6cSJohn Marino
9840*ef5ccd6cSJohn Marino if (TYPE_CODE (type) != TYPE_CODE_REF)
9841*ef5ccd6cSJohn Marino {
98425796c8dcSSimon Schubert struct type *actual_type;
98435796c8dcSSimon Schubert
98445796c8dcSSimon Schubert actual_type = type_from_tag (ada_value_tag (arg1));
98455796c8dcSSimon Schubert if (actual_type == NULL)
98465796c8dcSSimon Schubert /* If, for some reason, we were unable to determine
98475796c8dcSSimon Schubert the actual type from the tag, then use the static
98485796c8dcSSimon Schubert approximation that we just computed as a fallback.
98495796c8dcSSimon Schubert This can happen if the debugging information is
98505796c8dcSSimon Schubert incomplete, for instance. */
98515796c8dcSSimon Schubert actual_type = type;
98525796c8dcSSimon Schubert return value_zero (actual_type, not_lval);
98535796c8dcSSimon Schubert }
9854*ef5ccd6cSJohn Marino else
9855*ef5ccd6cSJohn Marino {
9856*ef5ccd6cSJohn Marino /* In the case of a ref, ada_coerce_ref takes care
9857*ef5ccd6cSJohn Marino of determining the actual type. But the evaluation
9858*ef5ccd6cSJohn Marino should return a ref as it should be valid to ask
9859*ef5ccd6cSJohn Marino for its address; so rebuild a ref after coerce. */
9860*ef5ccd6cSJohn Marino arg1 = ada_coerce_ref (arg1);
9861*ef5ccd6cSJohn Marino return value_ref (arg1);
9862*ef5ccd6cSJohn Marino }
9863*ef5ccd6cSJohn Marino }
98645796c8dcSSimon Schubert
98655796c8dcSSimon Schubert *pos += 4;
98665796c8dcSSimon Schubert return value_zero
98675796c8dcSSimon Schubert (to_static_fixed_type
98685796c8dcSSimon Schubert (static_unwrap_type (SYMBOL_TYPE (exp->elts[pc + 2].symbol))),
98695796c8dcSSimon Schubert not_lval);
98705796c8dcSSimon Schubert }
98715796c8dcSSimon Schubert else
98725796c8dcSSimon Schubert {
98735796c8dcSSimon Schubert arg1 = evaluate_subexp_standard (expect_type, exp, pos, noside);
98745796c8dcSSimon Schubert return ada_to_fixed_value (arg1);
98755796c8dcSSimon Schubert }
98765796c8dcSSimon Schubert
98775796c8dcSSimon Schubert case OP_FUNCALL:
98785796c8dcSSimon Schubert (*pos) += 2;
98795796c8dcSSimon Schubert
98805796c8dcSSimon Schubert /* Allocate arg vector, including space for the function to be
98815796c8dcSSimon Schubert called in argvec[0] and a terminating NULL. */
98825796c8dcSSimon Schubert nargs = longest_to_int (exp->elts[pc + 1].longconst);
98835796c8dcSSimon Schubert argvec =
98845796c8dcSSimon Schubert (struct value **) alloca (sizeof (struct value *) * (nargs + 2));
98855796c8dcSSimon Schubert
98865796c8dcSSimon Schubert if (exp->elts[*pos].opcode == OP_VAR_VALUE
98875796c8dcSSimon Schubert && SYMBOL_DOMAIN (exp->elts[pc + 5].symbol) == UNDEF_DOMAIN)
98885796c8dcSSimon Schubert error (_("Unexpected unresolved symbol, %s, during evaluation"),
98895796c8dcSSimon Schubert SYMBOL_PRINT_NAME (exp->elts[pc + 5].symbol));
98905796c8dcSSimon Schubert else
98915796c8dcSSimon Schubert {
98925796c8dcSSimon Schubert for (tem = 0; tem <= nargs; tem += 1)
98935796c8dcSSimon Schubert argvec[tem] = evaluate_subexp (NULL_TYPE, exp, pos, noside);
98945796c8dcSSimon Schubert argvec[tem] = 0;
98955796c8dcSSimon Schubert
98965796c8dcSSimon Schubert if (noside == EVAL_SKIP)
98975796c8dcSSimon Schubert goto nosideret;
98985796c8dcSSimon Schubert }
98995796c8dcSSimon Schubert
9900cf7f2e2dSJohn Marino if (ada_is_constrained_packed_array_type
9901cf7f2e2dSJohn Marino (desc_base_type (value_type (argvec[0]))))
99025796c8dcSSimon Schubert argvec[0] = ada_coerce_to_simple_array (argvec[0]);
99035796c8dcSSimon Schubert else if (TYPE_CODE (value_type (argvec[0])) == TYPE_CODE_ARRAY
99045796c8dcSSimon Schubert && TYPE_FIELD_BITSIZE (value_type (argvec[0]), 0) != 0)
99055796c8dcSSimon Schubert /* This is a packed array that has already been fixed, and
99065796c8dcSSimon Schubert therefore already coerced to a simple array. Nothing further
99075796c8dcSSimon Schubert to do. */
99085796c8dcSSimon Schubert ;
99095796c8dcSSimon Schubert else if (TYPE_CODE (value_type (argvec[0])) == TYPE_CODE_REF
99105796c8dcSSimon Schubert || (TYPE_CODE (value_type (argvec[0])) == TYPE_CODE_ARRAY
99115796c8dcSSimon Schubert && VALUE_LVAL (argvec[0]) == lval_memory))
99125796c8dcSSimon Schubert argvec[0] = value_addr (argvec[0]);
99135796c8dcSSimon Schubert
99145796c8dcSSimon Schubert type = ada_check_typedef (value_type (argvec[0]));
9915c50c785cSJohn Marino
9916c50c785cSJohn Marino /* Ada allows us to implicitly dereference arrays when subscripting
9917a45ae5f8SJohn Marino them. So, if this is an array typedef (encoding use for array
9918a45ae5f8SJohn Marino access types encoded as fat pointers), strip it now. */
9919c50c785cSJohn Marino if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
9920c50c785cSJohn Marino type = ada_typedef_target_type (type);
9921c50c785cSJohn Marino
99225796c8dcSSimon Schubert if (TYPE_CODE (type) == TYPE_CODE_PTR)
99235796c8dcSSimon Schubert {
99245796c8dcSSimon Schubert switch (TYPE_CODE (ada_check_typedef (TYPE_TARGET_TYPE (type))))
99255796c8dcSSimon Schubert {
99265796c8dcSSimon Schubert case TYPE_CODE_FUNC:
99275796c8dcSSimon Schubert type = ada_check_typedef (TYPE_TARGET_TYPE (type));
99285796c8dcSSimon Schubert break;
99295796c8dcSSimon Schubert case TYPE_CODE_ARRAY:
99305796c8dcSSimon Schubert break;
99315796c8dcSSimon Schubert case TYPE_CODE_STRUCT:
99325796c8dcSSimon Schubert if (noside != EVAL_AVOID_SIDE_EFFECTS)
99335796c8dcSSimon Schubert argvec[0] = ada_value_ind (argvec[0]);
99345796c8dcSSimon Schubert type = ada_check_typedef (TYPE_TARGET_TYPE (type));
99355796c8dcSSimon Schubert break;
99365796c8dcSSimon Schubert default:
99375796c8dcSSimon Schubert error (_("cannot subscript or call something of type `%s'"),
99385796c8dcSSimon Schubert ada_type_name (value_type (argvec[0])));
99395796c8dcSSimon Schubert break;
99405796c8dcSSimon Schubert }
99415796c8dcSSimon Schubert }
99425796c8dcSSimon Schubert
99435796c8dcSSimon Schubert switch (TYPE_CODE (type))
99445796c8dcSSimon Schubert {
99455796c8dcSSimon Schubert case TYPE_CODE_FUNC:
99465796c8dcSSimon Schubert if (noside == EVAL_AVOID_SIDE_EFFECTS)
9947*ef5ccd6cSJohn Marino {
9948*ef5ccd6cSJohn Marino struct type *rtype = TYPE_TARGET_TYPE (type);
9949*ef5ccd6cSJohn Marino
9950*ef5ccd6cSJohn Marino if (TYPE_GNU_IFUNC (type))
9951*ef5ccd6cSJohn Marino return allocate_value (TYPE_TARGET_TYPE (rtype));
9952*ef5ccd6cSJohn Marino return allocate_value (rtype);
9953*ef5ccd6cSJohn Marino }
99545796c8dcSSimon Schubert return call_function_by_hand (argvec[0], nargs, argvec + 1);
9955*ef5ccd6cSJohn Marino case TYPE_CODE_INTERNAL_FUNCTION:
9956*ef5ccd6cSJohn Marino if (noside == EVAL_AVOID_SIDE_EFFECTS)
9957*ef5ccd6cSJohn Marino /* We don't know anything about what the internal
9958*ef5ccd6cSJohn Marino function might return, but we have to return
9959*ef5ccd6cSJohn Marino something. */
9960*ef5ccd6cSJohn Marino return value_zero (builtin_type (exp->gdbarch)->builtin_int,
9961*ef5ccd6cSJohn Marino not_lval);
9962*ef5ccd6cSJohn Marino else
9963*ef5ccd6cSJohn Marino return call_internal_function (exp->gdbarch, exp->language_defn,
9964*ef5ccd6cSJohn Marino argvec[0], nargs, argvec + 1);
9965*ef5ccd6cSJohn Marino
99665796c8dcSSimon Schubert case TYPE_CODE_STRUCT:
99675796c8dcSSimon Schubert {
99685796c8dcSSimon Schubert int arity;
99695796c8dcSSimon Schubert
99705796c8dcSSimon Schubert arity = ada_array_arity (type);
99715796c8dcSSimon Schubert type = ada_array_element_type (type, nargs);
99725796c8dcSSimon Schubert if (type == NULL)
99735796c8dcSSimon Schubert error (_("cannot subscript or call a record"));
99745796c8dcSSimon Schubert if (arity != nargs)
99755796c8dcSSimon Schubert error (_("wrong number of subscripts; expecting %d"), arity);
99765796c8dcSSimon Schubert if (noside == EVAL_AVOID_SIDE_EFFECTS)
99775796c8dcSSimon Schubert return value_zero (ada_aligned_type (type), lval_memory);
99785796c8dcSSimon Schubert return
99795796c8dcSSimon Schubert unwrap_value (ada_value_subscript
99805796c8dcSSimon Schubert (argvec[0], nargs, argvec + 1));
99815796c8dcSSimon Schubert }
99825796c8dcSSimon Schubert case TYPE_CODE_ARRAY:
99835796c8dcSSimon Schubert if (noside == EVAL_AVOID_SIDE_EFFECTS)
99845796c8dcSSimon Schubert {
99855796c8dcSSimon Schubert type = ada_array_element_type (type, nargs);
99865796c8dcSSimon Schubert if (type == NULL)
99875796c8dcSSimon Schubert error (_("element type of array unknown"));
99885796c8dcSSimon Schubert else
99895796c8dcSSimon Schubert return value_zero (ada_aligned_type (type), lval_memory);
99905796c8dcSSimon Schubert }
99915796c8dcSSimon Schubert return
99925796c8dcSSimon Schubert unwrap_value (ada_value_subscript
99935796c8dcSSimon Schubert (ada_coerce_to_simple_array (argvec[0]),
99945796c8dcSSimon Schubert nargs, argvec + 1));
99955796c8dcSSimon Schubert case TYPE_CODE_PTR: /* Pointer to array */
99965796c8dcSSimon Schubert type = to_fixed_array_type (TYPE_TARGET_TYPE (type), NULL, 1);
99975796c8dcSSimon Schubert if (noside == EVAL_AVOID_SIDE_EFFECTS)
99985796c8dcSSimon Schubert {
99995796c8dcSSimon Schubert type = ada_array_element_type (type, nargs);
100005796c8dcSSimon Schubert if (type == NULL)
100015796c8dcSSimon Schubert error (_("element type of array unknown"));
100025796c8dcSSimon Schubert else
100035796c8dcSSimon Schubert return value_zero (ada_aligned_type (type), lval_memory);
100045796c8dcSSimon Schubert }
100055796c8dcSSimon Schubert return
100065796c8dcSSimon Schubert unwrap_value (ada_value_ptr_subscript (argvec[0], type,
100075796c8dcSSimon Schubert nargs, argvec + 1));
100085796c8dcSSimon Schubert
100095796c8dcSSimon Schubert default:
100105796c8dcSSimon Schubert error (_("Attempt to index or call something other than an "
100115796c8dcSSimon Schubert "array or function"));
100125796c8dcSSimon Schubert }
100135796c8dcSSimon Schubert
100145796c8dcSSimon Schubert case TERNOP_SLICE:
100155796c8dcSSimon Schubert {
100165796c8dcSSimon Schubert struct value *array = evaluate_subexp (NULL_TYPE, exp, pos, noside);
100175796c8dcSSimon Schubert struct value *low_bound_val =
100185796c8dcSSimon Schubert evaluate_subexp (NULL_TYPE, exp, pos, noside);
100195796c8dcSSimon Schubert struct value *high_bound_val =
100205796c8dcSSimon Schubert evaluate_subexp (NULL_TYPE, exp, pos, noside);
100215796c8dcSSimon Schubert LONGEST low_bound;
100225796c8dcSSimon Schubert LONGEST high_bound;
10023cf7f2e2dSJohn Marino
100245796c8dcSSimon Schubert low_bound_val = coerce_ref (low_bound_val);
100255796c8dcSSimon Schubert high_bound_val = coerce_ref (high_bound_val);
100265796c8dcSSimon Schubert low_bound = pos_atr (low_bound_val);
100275796c8dcSSimon Schubert high_bound = pos_atr (high_bound_val);
100285796c8dcSSimon Schubert
100295796c8dcSSimon Schubert if (noside == EVAL_SKIP)
100305796c8dcSSimon Schubert goto nosideret;
100315796c8dcSSimon Schubert
100325796c8dcSSimon Schubert /* If this is a reference to an aligner type, then remove all
100335796c8dcSSimon Schubert the aligners. */
100345796c8dcSSimon Schubert if (TYPE_CODE (value_type (array)) == TYPE_CODE_REF
100355796c8dcSSimon Schubert && ada_is_aligner_type (TYPE_TARGET_TYPE (value_type (array))))
100365796c8dcSSimon Schubert TYPE_TARGET_TYPE (value_type (array)) =
100375796c8dcSSimon Schubert ada_aligned_type (TYPE_TARGET_TYPE (value_type (array)));
100385796c8dcSSimon Schubert
10039cf7f2e2dSJohn Marino if (ada_is_constrained_packed_array_type (value_type (array)))
100405796c8dcSSimon Schubert error (_("cannot slice a packed array"));
100415796c8dcSSimon Schubert
100425796c8dcSSimon Schubert /* If this is a reference to an array or an array lvalue,
100435796c8dcSSimon Schubert convert to a pointer. */
100445796c8dcSSimon Schubert if (TYPE_CODE (value_type (array)) == TYPE_CODE_REF
100455796c8dcSSimon Schubert || (TYPE_CODE (value_type (array)) == TYPE_CODE_ARRAY
100465796c8dcSSimon Schubert && VALUE_LVAL (array) == lval_memory))
100475796c8dcSSimon Schubert array = value_addr (array);
100485796c8dcSSimon Schubert
100495796c8dcSSimon Schubert if (noside == EVAL_AVOID_SIDE_EFFECTS
100505796c8dcSSimon Schubert && ada_is_array_descriptor_type (ada_check_typedef
100515796c8dcSSimon Schubert (value_type (array))))
100525796c8dcSSimon Schubert return empty_array (ada_type_of_array (array, 0), low_bound);
100535796c8dcSSimon Schubert
100545796c8dcSSimon Schubert array = ada_coerce_to_simple_array_ptr (array);
100555796c8dcSSimon Schubert
100565796c8dcSSimon Schubert /* If we have more than one level of pointer indirection,
100575796c8dcSSimon Schubert dereference the value until we get only one level. */
100585796c8dcSSimon Schubert while (TYPE_CODE (value_type (array)) == TYPE_CODE_PTR
100595796c8dcSSimon Schubert && (TYPE_CODE (TYPE_TARGET_TYPE (value_type (array)))
100605796c8dcSSimon Schubert == TYPE_CODE_PTR))
100615796c8dcSSimon Schubert array = value_ind (array);
100625796c8dcSSimon Schubert
100635796c8dcSSimon Schubert /* Make sure we really do have an array type before going further,
100645796c8dcSSimon Schubert to avoid a SEGV when trying to get the index type or the target
100655796c8dcSSimon Schubert type later down the road if the debug info generated by
100665796c8dcSSimon Schubert the compiler is incorrect or incomplete. */
100675796c8dcSSimon Schubert if (!ada_is_simple_array_type (value_type (array)))
100685796c8dcSSimon Schubert error (_("cannot take slice of non-array"));
100695796c8dcSSimon Schubert
10070a45ae5f8SJohn Marino if (TYPE_CODE (ada_check_typedef (value_type (array)))
10071a45ae5f8SJohn Marino == TYPE_CODE_PTR)
100725796c8dcSSimon Schubert {
10073a45ae5f8SJohn Marino struct type *type0 = ada_check_typedef (value_type (array));
10074a45ae5f8SJohn Marino
100755796c8dcSSimon Schubert if (high_bound < low_bound || noside == EVAL_AVOID_SIDE_EFFECTS)
10076a45ae5f8SJohn Marino return empty_array (TYPE_TARGET_TYPE (type0), low_bound);
100775796c8dcSSimon Schubert else
100785796c8dcSSimon Schubert {
100795796c8dcSSimon Schubert struct type *arr_type0 =
10080a45ae5f8SJohn Marino to_fixed_array_type (TYPE_TARGET_TYPE (type0), NULL, 1);
10081cf7f2e2dSJohn Marino
100825796c8dcSSimon Schubert return ada_value_slice_from_ptr (array, arr_type0,
100835796c8dcSSimon Schubert longest_to_int (low_bound),
100845796c8dcSSimon Schubert longest_to_int (high_bound));
100855796c8dcSSimon Schubert }
100865796c8dcSSimon Schubert }
100875796c8dcSSimon Schubert else if (noside == EVAL_AVOID_SIDE_EFFECTS)
100885796c8dcSSimon Schubert return array;
100895796c8dcSSimon Schubert else if (high_bound < low_bound)
100905796c8dcSSimon Schubert return empty_array (value_type (array), low_bound);
100915796c8dcSSimon Schubert else
100925796c8dcSSimon Schubert return ada_value_slice (array, longest_to_int (low_bound),
100935796c8dcSSimon Schubert longest_to_int (high_bound));
100945796c8dcSSimon Schubert }
100955796c8dcSSimon Schubert
100965796c8dcSSimon Schubert case UNOP_IN_RANGE:
100975796c8dcSSimon Schubert (*pos) += 2;
100985796c8dcSSimon Schubert arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
100995796c8dcSSimon Schubert type = check_typedef (exp->elts[pc + 1].type);
101005796c8dcSSimon Schubert
101015796c8dcSSimon Schubert if (noside == EVAL_SKIP)
101025796c8dcSSimon Schubert goto nosideret;
101035796c8dcSSimon Schubert
101045796c8dcSSimon Schubert switch (TYPE_CODE (type))
101055796c8dcSSimon Schubert {
101065796c8dcSSimon Schubert default:
101075796c8dcSSimon Schubert lim_warning (_("Membership test incompletely implemented; "
101085796c8dcSSimon Schubert "always returns true"));
101095796c8dcSSimon Schubert type = language_bool_type (exp->language_defn, exp->gdbarch);
101105796c8dcSSimon Schubert return value_from_longest (type, (LONGEST) 1);
101115796c8dcSSimon Schubert
101125796c8dcSSimon Schubert case TYPE_CODE_RANGE:
101135796c8dcSSimon Schubert arg2 = value_from_longest (type, TYPE_LOW_BOUND (type));
101145796c8dcSSimon Schubert arg3 = value_from_longest (type, TYPE_HIGH_BOUND (type));
101155796c8dcSSimon Schubert binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
101165796c8dcSSimon Schubert binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg3);
101175796c8dcSSimon Schubert type = language_bool_type (exp->language_defn, exp->gdbarch);
101185796c8dcSSimon Schubert return
101195796c8dcSSimon Schubert value_from_longest (type,
101205796c8dcSSimon Schubert (value_less (arg1, arg3)
101215796c8dcSSimon Schubert || value_equal (arg1, arg3))
101225796c8dcSSimon Schubert && (value_less (arg2, arg1)
101235796c8dcSSimon Schubert || value_equal (arg2, arg1)));
101245796c8dcSSimon Schubert }
101255796c8dcSSimon Schubert
101265796c8dcSSimon Schubert case BINOP_IN_BOUNDS:
101275796c8dcSSimon Schubert (*pos) += 2;
101285796c8dcSSimon Schubert arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
101295796c8dcSSimon Schubert arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
101305796c8dcSSimon Schubert
101315796c8dcSSimon Schubert if (noside == EVAL_SKIP)
101325796c8dcSSimon Schubert goto nosideret;
101335796c8dcSSimon Schubert
101345796c8dcSSimon Schubert if (noside == EVAL_AVOID_SIDE_EFFECTS)
101355796c8dcSSimon Schubert {
101365796c8dcSSimon Schubert type = language_bool_type (exp->language_defn, exp->gdbarch);
101375796c8dcSSimon Schubert return value_zero (type, not_lval);
101385796c8dcSSimon Schubert }
101395796c8dcSSimon Schubert
101405796c8dcSSimon Schubert tem = longest_to_int (exp->elts[pc + 1].longconst);
101415796c8dcSSimon Schubert
101425796c8dcSSimon Schubert type = ada_index_type (value_type (arg2), tem, "range");
101435796c8dcSSimon Schubert if (!type)
101445796c8dcSSimon Schubert type = value_type (arg1);
101455796c8dcSSimon Schubert
101465796c8dcSSimon Schubert arg3 = value_from_longest (type, ada_array_bound (arg2, tem, 1));
101475796c8dcSSimon Schubert arg2 = value_from_longest (type, ada_array_bound (arg2, tem, 0));
101485796c8dcSSimon Schubert
101495796c8dcSSimon Schubert binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
101505796c8dcSSimon Schubert binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg3);
101515796c8dcSSimon Schubert type = language_bool_type (exp->language_defn, exp->gdbarch);
101525796c8dcSSimon Schubert return
101535796c8dcSSimon Schubert value_from_longest (type,
101545796c8dcSSimon Schubert (value_less (arg1, arg3)
101555796c8dcSSimon Schubert || value_equal (arg1, arg3))
101565796c8dcSSimon Schubert && (value_less (arg2, arg1)
101575796c8dcSSimon Schubert || value_equal (arg2, arg1)));
101585796c8dcSSimon Schubert
101595796c8dcSSimon Schubert case TERNOP_IN_RANGE:
101605796c8dcSSimon Schubert arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
101615796c8dcSSimon Schubert arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
101625796c8dcSSimon Schubert arg3 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
101635796c8dcSSimon Schubert
101645796c8dcSSimon Schubert if (noside == EVAL_SKIP)
101655796c8dcSSimon Schubert goto nosideret;
101665796c8dcSSimon Schubert
101675796c8dcSSimon Schubert binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
101685796c8dcSSimon Schubert binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg3);
101695796c8dcSSimon Schubert type = language_bool_type (exp->language_defn, exp->gdbarch);
101705796c8dcSSimon Schubert return
101715796c8dcSSimon Schubert value_from_longest (type,
101725796c8dcSSimon Schubert (value_less (arg1, arg3)
101735796c8dcSSimon Schubert || value_equal (arg1, arg3))
101745796c8dcSSimon Schubert && (value_less (arg2, arg1)
101755796c8dcSSimon Schubert || value_equal (arg2, arg1)));
101765796c8dcSSimon Schubert
101775796c8dcSSimon Schubert case OP_ATR_FIRST:
101785796c8dcSSimon Schubert case OP_ATR_LAST:
101795796c8dcSSimon Schubert case OP_ATR_LENGTH:
101805796c8dcSSimon Schubert {
101815796c8dcSSimon Schubert struct type *type_arg;
10182cf7f2e2dSJohn Marino
101835796c8dcSSimon Schubert if (exp->elts[*pos].opcode == OP_TYPE)
101845796c8dcSSimon Schubert {
101855796c8dcSSimon Schubert evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
101865796c8dcSSimon Schubert arg1 = NULL;
101875796c8dcSSimon Schubert type_arg = check_typedef (exp->elts[pc + 2].type);
101885796c8dcSSimon Schubert }
101895796c8dcSSimon Schubert else
101905796c8dcSSimon Schubert {
101915796c8dcSSimon Schubert arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
101925796c8dcSSimon Schubert type_arg = NULL;
101935796c8dcSSimon Schubert }
101945796c8dcSSimon Schubert
101955796c8dcSSimon Schubert if (exp->elts[*pos].opcode != OP_LONG)
101965796c8dcSSimon Schubert error (_("Invalid operand to '%s"), ada_attribute_name (op));
101975796c8dcSSimon Schubert tem = longest_to_int (exp->elts[*pos + 2].longconst);
101985796c8dcSSimon Schubert *pos += 4;
101995796c8dcSSimon Schubert
102005796c8dcSSimon Schubert if (noside == EVAL_SKIP)
102015796c8dcSSimon Schubert goto nosideret;
102025796c8dcSSimon Schubert
102035796c8dcSSimon Schubert if (type_arg == NULL)
102045796c8dcSSimon Schubert {
102055796c8dcSSimon Schubert arg1 = ada_coerce_ref (arg1);
102065796c8dcSSimon Schubert
10207cf7f2e2dSJohn Marino if (ada_is_constrained_packed_array_type (value_type (arg1)))
102085796c8dcSSimon Schubert arg1 = ada_coerce_to_simple_array (arg1);
102095796c8dcSSimon Schubert
102105796c8dcSSimon Schubert type = ada_index_type (value_type (arg1), tem,
102115796c8dcSSimon Schubert ada_attribute_name (op));
102125796c8dcSSimon Schubert if (type == NULL)
102135796c8dcSSimon Schubert type = builtin_type (exp->gdbarch)->builtin_int;
102145796c8dcSSimon Schubert
102155796c8dcSSimon Schubert if (noside == EVAL_AVOID_SIDE_EFFECTS)
102165796c8dcSSimon Schubert return allocate_value (type);
102175796c8dcSSimon Schubert
102185796c8dcSSimon Schubert switch (op)
102195796c8dcSSimon Schubert {
102205796c8dcSSimon Schubert default: /* Should never happen. */
102215796c8dcSSimon Schubert error (_("unexpected attribute encountered"));
102225796c8dcSSimon Schubert case OP_ATR_FIRST:
102235796c8dcSSimon Schubert return value_from_longest
102245796c8dcSSimon Schubert (type, ada_array_bound (arg1, tem, 0));
102255796c8dcSSimon Schubert case OP_ATR_LAST:
102265796c8dcSSimon Schubert return value_from_longest
102275796c8dcSSimon Schubert (type, ada_array_bound (arg1, tem, 1));
102285796c8dcSSimon Schubert case OP_ATR_LENGTH:
102295796c8dcSSimon Schubert return value_from_longest
102305796c8dcSSimon Schubert (type, ada_array_length (arg1, tem));
102315796c8dcSSimon Schubert }
102325796c8dcSSimon Schubert }
102335796c8dcSSimon Schubert else if (discrete_type_p (type_arg))
102345796c8dcSSimon Schubert {
102355796c8dcSSimon Schubert struct type *range_type;
10236*ef5ccd6cSJohn Marino const char *name = ada_type_name (type_arg);
10237cf7f2e2dSJohn Marino
102385796c8dcSSimon Schubert range_type = NULL;
102395796c8dcSSimon Schubert if (name != NULL && TYPE_CODE (type_arg) != TYPE_CODE_ENUM)
10240cf7f2e2dSJohn Marino range_type = to_fixed_range_type (type_arg, NULL);
102415796c8dcSSimon Schubert if (range_type == NULL)
102425796c8dcSSimon Schubert range_type = type_arg;
102435796c8dcSSimon Schubert switch (op)
102445796c8dcSSimon Schubert {
102455796c8dcSSimon Schubert default:
102465796c8dcSSimon Schubert error (_("unexpected attribute encountered"));
102475796c8dcSSimon Schubert case OP_ATR_FIRST:
102485796c8dcSSimon Schubert return value_from_longest
10249cf7f2e2dSJohn Marino (range_type, ada_discrete_type_low_bound (range_type));
102505796c8dcSSimon Schubert case OP_ATR_LAST:
102515796c8dcSSimon Schubert return value_from_longest
10252cf7f2e2dSJohn Marino (range_type, ada_discrete_type_high_bound (range_type));
102535796c8dcSSimon Schubert case OP_ATR_LENGTH:
102545796c8dcSSimon Schubert error (_("the 'length attribute applies only to array types"));
102555796c8dcSSimon Schubert }
102565796c8dcSSimon Schubert }
102575796c8dcSSimon Schubert else if (TYPE_CODE (type_arg) == TYPE_CODE_FLT)
102585796c8dcSSimon Schubert error (_("unimplemented type attribute"));
102595796c8dcSSimon Schubert else
102605796c8dcSSimon Schubert {
102615796c8dcSSimon Schubert LONGEST low, high;
102625796c8dcSSimon Schubert
10263cf7f2e2dSJohn Marino if (ada_is_constrained_packed_array_type (type_arg))
10264cf7f2e2dSJohn Marino type_arg = decode_constrained_packed_array_type (type_arg);
102655796c8dcSSimon Schubert
102665796c8dcSSimon Schubert type = ada_index_type (type_arg, tem, ada_attribute_name (op));
102675796c8dcSSimon Schubert if (type == NULL)
102685796c8dcSSimon Schubert type = builtin_type (exp->gdbarch)->builtin_int;
102695796c8dcSSimon Schubert
102705796c8dcSSimon Schubert if (noside == EVAL_AVOID_SIDE_EFFECTS)
102715796c8dcSSimon Schubert return allocate_value (type);
102725796c8dcSSimon Schubert
102735796c8dcSSimon Schubert switch (op)
102745796c8dcSSimon Schubert {
102755796c8dcSSimon Schubert default:
102765796c8dcSSimon Schubert error (_("unexpected attribute encountered"));
102775796c8dcSSimon Schubert case OP_ATR_FIRST:
102785796c8dcSSimon Schubert low = ada_array_bound_from_type (type_arg, tem, 0);
102795796c8dcSSimon Schubert return value_from_longest (type, low);
102805796c8dcSSimon Schubert case OP_ATR_LAST:
102815796c8dcSSimon Schubert high = ada_array_bound_from_type (type_arg, tem, 1);
102825796c8dcSSimon Schubert return value_from_longest (type, high);
102835796c8dcSSimon Schubert case OP_ATR_LENGTH:
102845796c8dcSSimon Schubert low = ada_array_bound_from_type (type_arg, tem, 0);
102855796c8dcSSimon Schubert high = ada_array_bound_from_type (type_arg, tem, 1);
102865796c8dcSSimon Schubert return value_from_longest (type, high - low + 1);
102875796c8dcSSimon Schubert }
102885796c8dcSSimon Schubert }
102895796c8dcSSimon Schubert }
102905796c8dcSSimon Schubert
102915796c8dcSSimon Schubert case OP_ATR_TAG:
102925796c8dcSSimon Schubert arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
102935796c8dcSSimon Schubert if (noside == EVAL_SKIP)
102945796c8dcSSimon Schubert goto nosideret;
102955796c8dcSSimon Schubert
102965796c8dcSSimon Schubert if (noside == EVAL_AVOID_SIDE_EFFECTS)
102975796c8dcSSimon Schubert return value_zero (ada_tag_type (arg1), not_lval);
102985796c8dcSSimon Schubert
102995796c8dcSSimon Schubert return ada_value_tag (arg1);
103005796c8dcSSimon Schubert
103015796c8dcSSimon Schubert case OP_ATR_MIN:
103025796c8dcSSimon Schubert case OP_ATR_MAX:
103035796c8dcSSimon Schubert evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
103045796c8dcSSimon Schubert arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
103055796c8dcSSimon Schubert arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
103065796c8dcSSimon Schubert if (noside == EVAL_SKIP)
103075796c8dcSSimon Schubert goto nosideret;
103085796c8dcSSimon Schubert else if (noside == EVAL_AVOID_SIDE_EFFECTS)
103095796c8dcSSimon Schubert return value_zero (value_type (arg1), not_lval);
103105796c8dcSSimon Schubert else
103115796c8dcSSimon Schubert {
103125796c8dcSSimon Schubert binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
103135796c8dcSSimon Schubert return value_binop (arg1, arg2,
103145796c8dcSSimon Schubert op == OP_ATR_MIN ? BINOP_MIN : BINOP_MAX);
103155796c8dcSSimon Schubert }
103165796c8dcSSimon Schubert
103175796c8dcSSimon Schubert case OP_ATR_MODULUS:
103185796c8dcSSimon Schubert {
103195796c8dcSSimon Schubert struct type *type_arg = check_typedef (exp->elts[pc + 2].type);
103205796c8dcSSimon Schubert
10321cf7f2e2dSJohn Marino evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
103225796c8dcSSimon Schubert if (noside == EVAL_SKIP)
103235796c8dcSSimon Schubert goto nosideret;
103245796c8dcSSimon Schubert
103255796c8dcSSimon Schubert if (!ada_is_modular_type (type_arg))
103265796c8dcSSimon Schubert error (_("'modulus must be applied to modular type"));
103275796c8dcSSimon Schubert
103285796c8dcSSimon Schubert return value_from_longest (TYPE_TARGET_TYPE (type_arg),
103295796c8dcSSimon Schubert ada_modulus (type_arg));
103305796c8dcSSimon Schubert }
103315796c8dcSSimon Schubert
103325796c8dcSSimon Schubert
103335796c8dcSSimon Schubert case OP_ATR_POS:
103345796c8dcSSimon Schubert evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
103355796c8dcSSimon Schubert arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
103365796c8dcSSimon Schubert if (noside == EVAL_SKIP)
103375796c8dcSSimon Schubert goto nosideret;
103385796c8dcSSimon Schubert type = builtin_type (exp->gdbarch)->builtin_int;
103395796c8dcSSimon Schubert if (noside == EVAL_AVOID_SIDE_EFFECTS)
103405796c8dcSSimon Schubert return value_zero (type, not_lval);
103415796c8dcSSimon Schubert else
103425796c8dcSSimon Schubert return value_pos_atr (type, arg1);
103435796c8dcSSimon Schubert
103445796c8dcSSimon Schubert case OP_ATR_SIZE:
103455796c8dcSSimon Schubert arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
103465796c8dcSSimon Schubert type = value_type (arg1);
103475796c8dcSSimon Schubert
103485796c8dcSSimon Schubert /* If the argument is a reference, then dereference its type, since
103495796c8dcSSimon Schubert the user is really asking for the size of the actual object,
103505796c8dcSSimon Schubert not the size of the pointer. */
103515796c8dcSSimon Schubert if (TYPE_CODE (type) == TYPE_CODE_REF)
103525796c8dcSSimon Schubert type = TYPE_TARGET_TYPE (type);
103535796c8dcSSimon Schubert
103545796c8dcSSimon Schubert if (noside == EVAL_SKIP)
103555796c8dcSSimon Schubert goto nosideret;
103565796c8dcSSimon Schubert else if (noside == EVAL_AVOID_SIDE_EFFECTS)
103575796c8dcSSimon Schubert return value_zero (builtin_type (exp->gdbarch)->builtin_int, not_lval);
103585796c8dcSSimon Schubert else
103595796c8dcSSimon Schubert return value_from_longest (builtin_type (exp->gdbarch)->builtin_int,
103605796c8dcSSimon Schubert TARGET_CHAR_BIT * TYPE_LENGTH (type));
103615796c8dcSSimon Schubert
103625796c8dcSSimon Schubert case OP_ATR_VAL:
103635796c8dcSSimon Schubert evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
103645796c8dcSSimon Schubert arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
103655796c8dcSSimon Schubert type = exp->elts[pc + 2].type;
103665796c8dcSSimon Schubert if (noside == EVAL_SKIP)
103675796c8dcSSimon Schubert goto nosideret;
103685796c8dcSSimon Schubert else if (noside == EVAL_AVOID_SIDE_EFFECTS)
103695796c8dcSSimon Schubert return value_zero (type, not_lval);
103705796c8dcSSimon Schubert else
103715796c8dcSSimon Schubert return value_val_atr (type, arg1);
103725796c8dcSSimon Schubert
103735796c8dcSSimon Schubert case BINOP_EXP:
103745796c8dcSSimon Schubert arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
103755796c8dcSSimon Schubert arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
103765796c8dcSSimon Schubert if (noside == EVAL_SKIP)
103775796c8dcSSimon Schubert goto nosideret;
103785796c8dcSSimon Schubert else if (noside == EVAL_AVOID_SIDE_EFFECTS)
103795796c8dcSSimon Schubert return value_zero (value_type (arg1), not_lval);
103805796c8dcSSimon Schubert else
103815796c8dcSSimon Schubert {
103825796c8dcSSimon Schubert /* For integer exponentiation operations,
103835796c8dcSSimon Schubert only promote the first argument. */
103845796c8dcSSimon Schubert if (is_integral_type (value_type (arg2)))
103855796c8dcSSimon Schubert unop_promote (exp->language_defn, exp->gdbarch, &arg1);
103865796c8dcSSimon Schubert else
103875796c8dcSSimon Schubert binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
103885796c8dcSSimon Schubert
103895796c8dcSSimon Schubert return value_binop (arg1, arg2, op);
103905796c8dcSSimon Schubert }
103915796c8dcSSimon Schubert
103925796c8dcSSimon Schubert case UNOP_PLUS:
103935796c8dcSSimon Schubert arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
103945796c8dcSSimon Schubert if (noside == EVAL_SKIP)
103955796c8dcSSimon Schubert goto nosideret;
103965796c8dcSSimon Schubert else
103975796c8dcSSimon Schubert return arg1;
103985796c8dcSSimon Schubert
103995796c8dcSSimon Schubert case UNOP_ABS:
104005796c8dcSSimon Schubert arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
104015796c8dcSSimon Schubert if (noside == EVAL_SKIP)
104025796c8dcSSimon Schubert goto nosideret;
104035796c8dcSSimon Schubert unop_promote (exp->language_defn, exp->gdbarch, &arg1);
104045796c8dcSSimon Schubert if (value_less (arg1, value_zero (value_type (arg1), not_lval)))
104055796c8dcSSimon Schubert return value_neg (arg1);
104065796c8dcSSimon Schubert else
104075796c8dcSSimon Schubert return arg1;
104085796c8dcSSimon Schubert
104095796c8dcSSimon Schubert case UNOP_IND:
104105796c8dcSSimon Schubert arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
104115796c8dcSSimon Schubert if (noside == EVAL_SKIP)
104125796c8dcSSimon Schubert goto nosideret;
104135796c8dcSSimon Schubert type = ada_check_typedef (value_type (arg1));
104145796c8dcSSimon Schubert if (noside == EVAL_AVOID_SIDE_EFFECTS)
104155796c8dcSSimon Schubert {
104165796c8dcSSimon Schubert if (ada_is_array_descriptor_type (type))
104175796c8dcSSimon Schubert /* GDB allows dereferencing GNAT array descriptors. */
104185796c8dcSSimon Schubert {
104195796c8dcSSimon Schubert struct type *arrType = ada_type_of_array (arg1, 0);
10420cf7f2e2dSJohn Marino
104215796c8dcSSimon Schubert if (arrType == NULL)
104225796c8dcSSimon Schubert error (_("Attempt to dereference null array pointer."));
104235796c8dcSSimon Schubert return value_at_lazy (arrType, 0);
104245796c8dcSSimon Schubert }
104255796c8dcSSimon Schubert else if (TYPE_CODE (type) == TYPE_CODE_PTR
104265796c8dcSSimon Schubert || TYPE_CODE (type) == TYPE_CODE_REF
104275796c8dcSSimon Schubert /* In C you can dereference an array to get the 1st elt. */
104285796c8dcSSimon Schubert || TYPE_CODE (type) == TYPE_CODE_ARRAY)
104295796c8dcSSimon Schubert {
104305796c8dcSSimon Schubert type = to_static_fixed_type
104315796c8dcSSimon Schubert (ada_aligned_type
104325796c8dcSSimon Schubert (ada_check_typedef (TYPE_TARGET_TYPE (type))));
104335796c8dcSSimon Schubert check_size (type);
104345796c8dcSSimon Schubert return value_zero (type, lval_memory);
104355796c8dcSSimon Schubert }
104365796c8dcSSimon Schubert else if (TYPE_CODE (type) == TYPE_CODE_INT)
104375796c8dcSSimon Schubert {
104385796c8dcSSimon Schubert /* GDB allows dereferencing an int. */
104395796c8dcSSimon Schubert if (expect_type == NULL)
104405796c8dcSSimon Schubert return value_zero (builtin_type (exp->gdbarch)->builtin_int,
104415796c8dcSSimon Schubert lval_memory);
104425796c8dcSSimon Schubert else
104435796c8dcSSimon Schubert {
104445796c8dcSSimon Schubert expect_type =
104455796c8dcSSimon Schubert to_static_fixed_type (ada_aligned_type (expect_type));
104465796c8dcSSimon Schubert return value_zero (expect_type, lval_memory);
104475796c8dcSSimon Schubert }
104485796c8dcSSimon Schubert }
104495796c8dcSSimon Schubert else
104505796c8dcSSimon Schubert error (_("Attempt to take contents of a non-pointer value."));
104515796c8dcSSimon Schubert }
104525796c8dcSSimon Schubert arg1 = ada_coerce_ref (arg1); /* FIXME: What is this for?? */
104535796c8dcSSimon Schubert type = ada_check_typedef (value_type (arg1));
104545796c8dcSSimon Schubert
104555796c8dcSSimon Schubert if (TYPE_CODE (type) == TYPE_CODE_INT)
104565796c8dcSSimon Schubert /* GDB allows dereferencing an int. If we were given
104575796c8dcSSimon Schubert the expect_type, then use that as the target type.
104585796c8dcSSimon Schubert Otherwise, assume that the target type is an int. */
104595796c8dcSSimon Schubert {
104605796c8dcSSimon Schubert if (expect_type != NULL)
104615796c8dcSSimon Schubert return ada_value_ind (value_cast (lookup_pointer_type (expect_type),
104625796c8dcSSimon Schubert arg1));
104635796c8dcSSimon Schubert else
104645796c8dcSSimon Schubert return value_at_lazy (builtin_type (exp->gdbarch)->builtin_int,
104655796c8dcSSimon Schubert (CORE_ADDR) value_as_address (arg1));
104665796c8dcSSimon Schubert }
104675796c8dcSSimon Schubert
104685796c8dcSSimon Schubert if (ada_is_array_descriptor_type (type))
104695796c8dcSSimon Schubert /* GDB allows dereferencing GNAT array descriptors. */
104705796c8dcSSimon Schubert return ada_coerce_to_simple_array (arg1);
104715796c8dcSSimon Schubert else
104725796c8dcSSimon Schubert return ada_value_ind (arg1);
104735796c8dcSSimon Schubert
104745796c8dcSSimon Schubert case STRUCTOP_STRUCT:
104755796c8dcSSimon Schubert tem = longest_to_int (exp->elts[pc + 1].longconst);
104765796c8dcSSimon Schubert (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
104775796c8dcSSimon Schubert arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
104785796c8dcSSimon Schubert if (noside == EVAL_SKIP)
104795796c8dcSSimon Schubert goto nosideret;
104805796c8dcSSimon Schubert if (noside == EVAL_AVOID_SIDE_EFFECTS)
104815796c8dcSSimon Schubert {
104825796c8dcSSimon Schubert struct type *type1 = value_type (arg1);
10483cf7f2e2dSJohn Marino
104845796c8dcSSimon Schubert if (ada_is_tagged_type (type1, 1))
104855796c8dcSSimon Schubert {
104865796c8dcSSimon Schubert type = ada_lookup_struct_elt_type (type1,
104875796c8dcSSimon Schubert &exp->elts[pc + 2].string,
104885796c8dcSSimon Schubert 1, 1, NULL);
104895796c8dcSSimon Schubert if (type == NULL)
104905796c8dcSSimon Schubert /* In this case, we assume that the field COULD exist
104915796c8dcSSimon Schubert in some extension of the type. Return an object of
104925796c8dcSSimon Schubert "type" void, which will match any formal
104935796c8dcSSimon Schubert (see ada_type_match). */
104945796c8dcSSimon Schubert return value_zero (builtin_type (exp->gdbarch)->builtin_void,
104955796c8dcSSimon Schubert lval_memory);
104965796c8dcSSimon Schubert }
104975796c8dcSSimon Schubert else
104985796c8dcSSimon Schubert type =
104995796c8dcSSimon Schubert ada_lookup_struct_elt_type (type1, &exp->elts[pc + 2].string, 1,
105005796c8dcSSimon Schubert 0, NULL);
105015796c8dcSSimon Schubert
105025796c8dcSSimon Schubert return value_zero (ada_aligned_type (type), lval_memory);
105035796c8dcSSimon Schubert }
105045796c8dcSSimon Schubert else
105055796c8dcSSimon Schubert arg1 = ada_value_struct_elt (arg1, &exp->elts[pc + 2].string, 0);
105065796c8dcSSimon Schubert arg1 = unwrap_value (arg1);
105075796c8dcSSimon Schubert return ada_to_fixed_value (arg1);
105085796c8dcSSimon Schubert
105095796c8dcSSimon Schubert case OP_TYPE:
105105796c8dcSSimon Schubert /* The value is not supposed to be used. This is here to make it
105115796c8dcSSimon Schubert easier to accommodate expressions that contain types. */
105125796c8dcSSimon Schubert (*pos) += 2;
105135796c8dcSSimon Schubert if (noside == EVAL_SKIP)
105145796c8dcSSimon Schubert goto nosideret;
105155796c8dcSSimon Schubert else if (noside == EVAL_AVOID_SIDE_EFFECTS)
105165796c8dcSSimon Schubert return allocate_value (exp->elts[pc + 1].type);
105175796c8dcSSimon Schubert else
105185796c8dcSSimon Schubert error (_("Attempt to use a type name as an expression"));
105195796c8dcSSimon Schubert
105205796c8dcSSimon Schubert case OP_AGGREGATE:
105215796c8dcSSimon Schubert case OP_CHOICES:
105225796c8dcSSimon Schubert case OP_OTHERS:
105235796c8dcSSimon Schubert case OP_DISCRETE_RANGE:
105245796c8dcSSimon Schubert case OP_POSITIONAL:
105255796c8dcSSimon Schubert case OP_NAME:
105265796c8dcSSimon Schubert if (noside == EVAL_NORMAL)
105275796c8dcSSimon Schubert switch (op)
105285796c8dcSSimon Schubert {
105295796c8dcSSimon Schubert case OP_NAME:
105305796c8dcSSimon Schubert error (_("Undefined name, ambiguous name, or renaming used in "
105315796c8dcSSimon Schubert "component association: %s."), &exp->elts[pc+2].string);
105325796c8dcSSimon Schubert case OP_AGGREGATE:
105335796c8dcSSimon Schubert error (_("Aggregates only allowed on the right of an assignment"));
105345796c8dcSSimon Schubert default:
10535c50c785cSJohn Marino internal_error (__FILE__, __LINE__,
10536c50c785cSJohn Marino _("aggregate apparently mangled"));
105375796c8dcSSimon Schubert }
105385796c8dcSSimon Schubert
105395796c8dcSSimon Schubert ada_forward_operator_length (exp, pc, &oplen, &nargs);
105405796c8dcSSimon Schubert *pos += oplen - 1;
105415796c8dcSSimon Schubert for (tem = 0; tem < nargs; tem += 1)
105425796c8dcSSimon Schubert ada_evaluate_subexp (NULL, exp, pos, noside);
105435796c8dcSSimon Schubert goto nosideret;
105445796c8dcSSimon Schubert }
105455796c8dcSSimon Schubert
105465796c8dcSSimon Schubert nosideret:
105475796c8dcSSimon Schubert return value_from_longest (builtin_type (exp->gdbarch)->builtin_int, 1);
105485796c8dcSSimon Schubert }
105495796c8dcSSimon Schubert
105505796c8dcSSimon Schubert
105515796c8dcSSimon Schubert /* Fixed point */
105525796c8dcSSimon Schubert
105535796c8dcSSimon Schubert /* If TYPE encodes an Ada fixed-point type, return the suffix of the
105545796c8dcSSimon Schubert type name that encodes the 'small and 'delta information.
105555796c8dcSSimon Schubert Otherwise, return NULL. */
105565796c8dcSSimon Schubert
105575796c8dcSSimon Schubert static const char *
fixed_type_info(struct type * type)105585796c8dcSSimon Schubert fixed_type_info (struct type *type)
105595796c8dcSSimon Schubert {
105605796c8dcSSimon Schubert const char *name = ada_type_name (type);
105615796c8dcSSimon Schubert enum type_code code = (type == NULL) ? TYPE_CODE_UNDEF : TYPE_CODE (type);
105625796c8dcSSimon Schubert
105635796c8dcSSimon Schubert if ((code == TYPE_CODE_INT || code == TYPE_CODE_RANGE) && name != NULL)
105645796c8dcSSimon Schubert {
105655796c8dcSSimon Schubert const char *tail = strstr (name, "___XF_");
10566cf7f2e2dSJohn Marino
105675796c8dcSSimon Schubert if (tail == NULL)
105685796c8dcSSimon Schubert return NULL;
105695796c8dcSSimon Schubert else
105705796c8dcSSimon Schubert return tail + 5;
105715796c8dcSSimon Schubert }
105725796c8dcSSimon Schubert else if (code == TYPE_CODE_RANGE && TYPE_TARGET_TYPE (type) != type)
105735796c8dcSSimon Schubert return fixed_type_info (TYPE_TARGET_TYPE (type));
105745796c8dcSSimon Schubert else
105755796c8dcSSimon Schubert return NULL;
105765796c8dcSSimon Schubert }
105775796c8dcSSimon Schubert
105785796c8dcSSimon Schubert /* Returns non-zero iff TYPE represents an Ada fixed-point type. */
105795796c8dcSSimon Schubert
105805796c8dcSSimon Schubert int
ada_is_fixed_point_type(struct type * type)105815796c8dcSSimon Schubert ada_is_fixed_point_type (struct type *type)
105825796c8dcSSimon Schubert {
105835796c8dcSSimon Schubert return fixed_type_info (type) != NULL;
105845796c8dcSSimon Schubert }
105855796c8dcSSimon Schubert
105865796c8dcSSimon Schubert /* Return non-zero iff TYPE represents a System.Address type. */
105875796c8dcSSimon Schubert
105885796c8dcSSimon Schubert int
ada_is_system_address_type(struct type * type)105895796c8dcSSimon Schubert ada_is_system_address_type (struct type *type)
105905796c8dcSSimon Schubert {
105915796c8dcSSimon Schubert return (TYPE_NAME (type)
105925796c8dcSSimon Schubert && strcmp (TYPE_NAME (type), "system__address") == 0);
105935796c8dcSSimon Schubert }
105945796c8dcSSimon Schubert
105955796c8dcSSimon Schubert /* Assuming that TYPE is the representation of an Ada fixed-point
105965796c8dcSSimon Schubert type, return its delta, or -1 if the type is malformed and the
105975796c8dcSSimon Schubert delta cannot be determined. */
105985796c8dcSSimon Schubert
105995796c8dcSSimon Schubert DOUBLEST
ada_delta(struct type * type)106005796c8dcSSimon Schubert ada_delta (struct type *type)
106015796c8dcSSimon Schubert {
106025796c8dcSSimon Schubert const char *encoding = fixed_type_info (type);
106035796c8dcSSimon Schubert DOUBLEST num, den;
106045796c8dcSSimon Schubert
106055796c8dcSSimon Schubert /* Strictly speaking, num and den are encoded as integer. However,
106065796c8dcSSimon Schubert they may not fit into a long, and they will have to be converted
106075796c8dcSSimon Schubert to DOUBLEST anyway. So scan them as DOUBLEST. */
106085796c8dcSSimon Schubert if (sscanf (encoding, "_%" DOUBLEST_SCAN_FORMAT "_%" DOUBLEST_SCAN_FORMAT,
106095796c8dcSSimon Schubert &num, &den) < 2)
106105796c8dcSSimon Schubert return -1.0;
106115796c8dcSSimon Schubert else
106125796c8dcSSimon Schubert return num / den;
106135796c8dcSSimon Schubert }
106145796c8dcSSimon Schubert
106155796c8dcSSimon Schubert /* Assuming that ada_is_fixed_point_type (TYPE), return the scaling
106165796c8dcSSimon Schubert factor ('SMALL value) associated with the type. */
106175796c8dcSSimon Schubert
106185796c8dcSSimon Schubert static DOUBLEST
scaling_factor(struct type * type)106195796c8dcSSimon Schubert scaling_factor (struct type *type)
106205796c8dcSSimon Schubert {
106215796c8dcSSimon Schubert const char *encoding = fixed_type_info (type);
106225796c8dcSSimon Schubert DOUBLEST num0, den0, num1, den1;
106235796c8dcSSimon Schubert int n;
106245796c8dcSSimon Schubert
106255796c8dcSSimon Schubert /* Strictly speaking, num's and den's are encoded as integer. However,
106265796c8dcSSimon Schubert they may not fit into a long, and they will have to be converted
106275796c8dcSSimon Schubert to DOUBLEST anyway. So scan them as DOUBLEST. */
106285796c8dcSSimon Schubert n = sscanf (encoding,
106295796c8dcSSimon Schubert "_%" DOUBLEST_SCAN_FORMAT "_%" DOUBLEST_SCAN_FORMAT
106305796c8dcSSimon Schubert "_%" DOUBLEST_SCAN_FORMAT "_%" DOUBLEST_SCAN_FORMAT,
106315796c8dcSSimon Schubert &num0, &den0, &num1, &den1);
106325796c8dcSSimon Schubert
106335796c8dcSSimon Schubert if (n < 2)
106345796c8dcSSimon Schubert return 1.0;
106355796c8dcSSimon Schubert else if (n == 4)
106365796c8dcSSimon Schubert return num1 / den1;
106375796c8dcSSimon Schubert else
106385796c8dcSSimon Schubert return num0 / den0;
106395796c8dcSSimon Schubert }
106405796c8dcSSimon Schubert
106415796c8dcSSimon Schubert
106425796c8dcSSimon Schubert /* Assuming that X is the representation of a value of fixed-point
106435796c8dcSSimon Schubert type TYPE, return its floating-point equivalent. */
106445796c8dcSSimon Schubert
106455796c8dcSSimon Schubert DOUBLEST
ada_fixed_to_float(struct type * type,LONGEST x)106465796c8dcSSimon Schubert ada_fixed_to_float (struct type *type, LONGEST x)
106475796c8dcSSimon Schubert {
106485796c8dcSSimon Schubert return (DOUBLEST) x *scaling_factor (type);
106495796c8dcSSimon Schubert }
106505796c8dcSSimon Schubert
106515796c8dcSSimon Schubert /* The representation of a fixed-point value of type TYPE
106525796c8dcSSimon Schubert corresponding to the value X. */
106535796c8dcSSimon Schubert
106545796c8dcSSimon Schubert LONGEST
ada_float_to_fixed(struct type * type,DOUBLEST x)106555796c8dcSSimon Schubert ada_float_to_fixed (struct type *type, DOUBLEST x)
106565796c8dcSSimon Schubert {
106575796c8dcSSimon Schubert return (LONGEST) (x / scaling_factor (type) + 0.5);
106585796c8dcSSimon Schubert }
106595796c8dcSSimon Schubert
106605796c8dcSSimon Schubert
106615796c8dcSSimon Schubert
106625796c8dcSSimon Schubert /* Range types */
106635796c8dcSSimon Schubert
106645796c8dcSSimon Schubert /* Scan STR beginning at position K for a discriminant name, and
106655796c8dcSSimon Schubert return the value of that discriminant field of DVAL in *PX. If
106665796c8dcSSimon Schubert PNEW_K is not null, put the position of the character beyond the
106675796c8dcSSimon Schubert name scanned in *PNEW_K. Return 1 if successful; return 0 and do
106685796c8dcSSimon Schubert not alter *PX and *PNEW_K if unsuccessful. */
106695796c8dcSSimon Schubert
106705796c8dcSSimon Schubert static int
scan_discrim_bound(char * str,int k,struct value * dval,LONGEST * px,int * pnew_k)106715796c8dcSSimon Schubert scan_discrim_bound (char *str, int k, struct value *dval, LONGEST * px,
106725796c8dcSSimon Schubert int *pnew_k)
106735796c8dcSSimon Schubert {
106745796c8dcSSimon Schubert static char *bound_buffer = NULL;
106755796c8dcSSimon Schubert static size_t bound_buffer_len = 0;
106765796c8dcSSimon Schubert char *bound;
106775796c8dcSSimon Schubert char *pend;
106785796c8dcSSimon Schubert struct value *bound_val;
106795796c8dcSSimon Schubert
106805796c8dcSSimon Schubert if (dval == NULL || str == NULL || str[k] == '\0')
106815796c8dcSSimon Schubert return 0;
106825796c8dcSSimon Schubert
106835796c8dcSSimon Schubert pend = strstr (str + k, "__");
106845796c8dcSSimon Schubert if (pend == NULL)
106855796c8dcSSimon Schubert {
106865796c8dcSSimon Schubert bound = str + k;
106875796c8dcSSimon Schubert k += strlen (bound);
106885796c8dcSSimon Schubert }
106895796c8dcSSimon Schubert else
106905796c8dcSSimon Schubert {
106915796c8dcSSimon Schubert GROW_VECT (bound_buffer, bound_buffer_len, pend - (str + k) + 1);
106925796c8dcSSimon Schubert bound = bound_buffer;
106935796c8dcSSimon Schubert strncpy (bound_buffer, str + k, pend - (str + k));
106945796c8dcSSimon Schubert bound[pend - (str + k)] = '\0';
106955796c8dcSSimon Schubert k = pend - str;
106965796c8dcSSimon Schubert }
106975796c8dcSSimon Schubert
106985796c8dcSSimon Schubert bound_val = ada_search_struct_field (bound, dval, 0, value_type (dval));
106995796c8dcSSimon Schubert if (bound_val == NULL)
107005796c8dcSSimon Schubert return 0;
107015796c8dcSSimon Schubert
107025796c8dcSSimon Schubert *px = value_as_long (bound_val);
107035796c8dcSSimon Schubert if (pnew_k != NULL)
107045796c8dcSSimon Schubert *pnew_k = k;
107055796c8dcSSimon Schubert return 1;
107065796c8dcSSimon Schubert }
107075796c8dcSSimon Schubert
107085796c8dcSSimon Schubert /* Value of variable named NAME in the current environment. If
107095796c8dcSSimon Schubert no such variable found, then if ERR_MSG is null, returns 0, and
107105796c8dcSSimon Schubert otherwise causes an error with message ERR_MSG. */
107115796c8dcSSimon Schubert
107125796c8dcSSimon Schubert static struct value *
get_var_value(char * name,char * err_msg)107135796c8dcSSimon Schubert get_var_value (char *name, char *err_msg)
107145796c8dcSSimon Schubert {
107155796c8dcSSimon Schubert struct ada_symbol_info *syms;
107165796c8dcSSimon Schubert int nsyms;
107175796c8dcSSimon Schubert
107185796c8dcSSimon Schubert nsyms = ada_lookup_symbol_list (name, get_selected_block (0), VAR_DOMAIN,
107195796c8dcSSimon Schubert &syms);
107205796c8dcSSimon Schubert
107215796c8dcSSimon Schubert if (nsyms != 1)
107225796c8dcSSimon Schubert {
107235796c8dcSSimon Schubert if (err_msg == NULL)
107245796c8dcSSimon Schubert return 0;
107255796c8dcSSimon Schubert else
107265796c8dcSSimon Schubert error (("%s"), err_msg);
107275796c8dcSSimon Schubert }
107285796c8dcSSimon Schubert
107295796c8dcSSimon Schubert return value_of_variable (syms[0].sym, syms[0].block);
107305796c8dcSSimon Schubert }
107315796c8dcSSimon Schubert
107325796c8dcSSimon Schubert /* Value of integer variable named NAME in the current environment. If
107335796c8dcSSimon Schubert no such variable found, returns 0, and sets *FLAG to 0. If
107345796c8dcSSimon Schubert successful, sets *FLAG to 1. */
107355796c8dcSSimon Schubert
107365796c8dcSSimon Schubert LONGEST
get_int_var_value(char * name,int * flag)107375796c8dcSSimon Schubert get_int_var_value (char *name, int *flag)
107385796c8dcSSimon Schubert {
107395796c8dcSSimon Schubert struct value *var_val = get_var_value (name, 0);
107405796c8dcSSimon Schubert
107415796c8dcSSimon Schubert if (var_val == 0)
107425796c8dcSSimon Schubert {
107435796c8dcSSimon Schubert if (flag != NULL)
107445796c8dcSSimon Schubert *flag = 0;
107455796c8dcSSimon Schubert return 0;
107465796c8dcSSimon Schubert }
107475796c8dcSSimon Schubert else
107485796c8dcSSimon Schubert {
107495796c8dcSSimon Schubert if (flag != NULL)
107505796c8dcSSimon Schubert *flag = 1;
107515796c8dcSSimon Schubert return value_as_long (var_val);
107525796c8dcSSimon Schubert }
107535796c8dcSSimon Schubert }
107545796c8dcSSimon Schubert
107555796c8dcSSimon Schubert
107565796c8dcSSimon Schubert /* Return a range type whose base type is that of the range type named
107575796c8dcSSimon Schubert NAME in the current environment, and whose bounds are calculated
107585796c8dcSSimon Schubert from NAME according to the GNAT range encoding conventions.
107595796c8dcSSimon Schubert Extract discriminant values, if needed, from DVAL. ORIG_TYPE is the
107605796c8dcSSimon Schubert corresponding range type from debug information; fall back to using it
107615796c8dcSSimon Schubert if symbol lookup fails. If a new type must be created, allocate it
107625796c8dcSSimon Schubert like ORIG_TYPE was. The bounds information, in general, is encoded
107635796c8dcSSimon Schubert in NAME, the base type given in the named range type. */
107645796c8dcSSimon Schubert
107655796c8dcSSimon Schubert static struct type *
to_fixed_range_type(struct type * raw_type,struct value * dval)10766cf7f2e2dSJohn Marino to_fixed_range_type (struct type *raw_type, struct value *dval)
107675796c8dcSSimon Schubert {
10768*ef5ccd6cSJohn Marino const char *name;
107695796c8dcSSimon Schubert struct type *base_type;
107705796c8dcSSimon Schubert char *subtype_info;
107715796c8dcSSimon Schubert
10772cf7f2e2dSJohn Marino gdb_assert (raw_type != NULL);
10773cf7f2e2dSJohn Marino gdb_assert (TYPE_NAME (raw_type) != NULL);
107745796c8dcSSimon Schubert
107755796c8dcSSimon Schubert if (TYPE_CODE (raw_type) == TYPE_CODE_RANGE)
107765796c8dcSSimon Schubert base_type = TYPE_TARGET_TYPE (raw_type);
107775796c8dcSSimon Schubert else
107785796c8dcSSimon Schubert base_type = raw_type;
107795796c8dcSSimon Schubert
10780cf7f2e2dSJohn Marino name = TYPE_NAME (raw_type);
107815796c8dcSSimon Schubert subtype_info = strstr (name, "___XD");
107825796c8dcSSimon Schubert if (subtype_info == NULL)
107835796c8dcSSimon Schubert {
10784cf7f2e2dSJohn Marino LONGEST L = ada_discrete_type_low_bound (raw_type);
10785cf7f2e2dSJohn Marino LONGEST U = ada_discrete_type_high_bound (raw_type);
10786cf7f2e2dSJohn Marino
107875796c8dcSSimon Schubert if (L < INT_MIN || U > INT_MAX)
107885796c8dcSSimon Schubert return raw_type;
107895796c8dcSSimon Schubert else
10790cf7f2e2dSJohn Marino return create_range_type (alloc_type_copy (raw_type), raw_type,
10791cf7f2e2dSJohn Marino ada_discrete_type_low_bound (raw_type),
10792cf7f2e2dSJohn Marino ada_discrete_type_high_bound (raw_type));
107935796c8dcSSimon Schubert }
107945796c8dcSSimon Schubert else
107955796c8dcSSimon Schubert {
107965796c8dcSSimon Schubert static char *name_buf = NULL;
107975796c8dcSSimon Schubert static size_t name_len = 0;
107985796c8dcSSimon Schubert int prefix_len = subtype_info - name;
107995796c8dcSSimon Schubert LONGEST L, U;
108005796c8dcSSimon Schubert struct type *type;
108015796c8dcSSimon Schubert char *bounds_str;
108025796c8dcSSimon Schubert int n;
108035796c8dcSSimon Schubert
108045796c8dcSSimon Schubert GROW_VECT (name_buf, name_len, prefix_len + 5);
108055796c8dcSSimon Schubert strncpy (name_buf, name, prefix_len);
108065796c8dcSSimon Schubert name_buf[prefix_len] = '\0';
108075796c8dcSSimon Schubert
108085796c8dcSSimon Schubert subtype_info += 5;
108095796c8dcSSimon Schubert bounds_str = strchr (subtype_info, '_');
108105796c8dcSSimon Schubert n = 1;
108115796c8dcSSimon Schubert
108125796c8dcSSimon Schubert if (*subtype_info == 'L')
108135796c8dcSSimon Schubert {
108145796c8dcSSimon Schubert if (!ada_scan_number (bounds_str, n, &L, &n)
108155796c8dcSSimon Schubert && !scan_discrim_bound (bounds_str, n, dval, &L, &n))
108165796c8dcSSimon Schubert return raw_type;
108175796c8dcSSimon Schubert if (bounds_str[n] == '_')
108185796c8dcSSimon Schubert n += 2;
108195796c8dcSSimon Schubert else if (bounds_str[n] == '.') /* FIXME? SGI Workshop kludge. */
108205796c8dcSSimon Schubert n += 1;
108215796c8dcSSimon Schubert subtype_info += 1;
108225796c8dcSSimon Schubert }
108235796c8dcSSimon Schubert else
108245796c8dcSSimon Schubert {
108255796c8dcSSimon Schubert int ok;
10826cf7f2e2dSJohn Marino
108275796c8dcSSimon Schubert strcpy (name_buf + prefix_len, "___L");
108285796c8dcSSimon Schubert L = get_int_var_value (name_buf, &ok);
108295796c8dcSSimon Schubert if (!ok)
108305796c8dcSSimon Schubert {
108315796c8dcSSimon Schubert lim_warning (_("Unknown lower bound, using 1."));
108325796c8dcSSimon Schubert L = 1;
108335796c8dcSSimon Schubert }
108345796c8dcSSimon Schubert }
108355796c8dcSSimon Schubert
108365796c8dcSSimon Schubert if (*subtype_info == 'U')
108375796c8dcSSimon Schubert {
108385796c8dcSSimon Schubert if (!ada_scan_number (bounds_str, n, &U, &n)
108395796c8dcSSimon Schubert && !scan_discrim_bound (bounds_str, n, dval, &U, &n))
108405796c8dcSSimon Schubert return raw_type;
108415796c8dcSSimon Schubert }
108425796c8dcSSimon Schubert else
108435796c8dcSSimon Schubert {
108445796c8dcSSimon Schubert int ok;
10845cf7f2e2dSJohn Marino
108465796c8dcSSimon Schubert strcpy (name_buf + prefix_len, "___U");
108475796c8dcSSimon Schubert U = get_int_var_value (name_buf, &ok);
108485796c8dcSSimon Schubert if (!ok)
108495796c8dcSSimon Schubert {
108505796c8dcSSimon Schubert lim_warning (_("Unknown upper bound, using %ld."), (long) L);
108515796c8dcSSimon Schubert U = L;
108525796c8dcSSimon Schubert }
108535796c8dcSSimon Schubert }
108545796c8dcSSimon Schubert
10855cf7f2e2dSJohn Marino type = create_range_type (alloc_type_copy (raw_type), base_type, L, U);
108565796c8dcSSimon Schubert TYPE_NAME (type) = name;
108575796c8dcSSimon Schubert return type;
108585796c8dcSSimon Schubert }
108595796c8dcSSimon Schubert }
108605796c8dcSSimon Schubert
108615796c8dcSSimon Schubert /* True iff NAME is the name of a range type. */
108625796c8dcSSimon Schubert
108635796c8dcSSimon Schubert int
ada_is_range_type_name(const char * name)108645796c8dcSSimon Schubert ada_is_range_type_name (const char *name)
108655796c8dcSSimon Schubert {
108665796c8dcSSimon Schubert return (name != NULL && strstr (name, "___XD"));
108675796c8dcSSimon Schubert }
108685796c8dcSSimon Schubert
108695796c8dcSSimon Schubert
108705796c8dcSSimon Schubert /* Modular types */
108715796c8dcSSimon Schubert
108725796c8dcSSimon Schubert /* True iff TYPE is an Ada modular type. */
108735796c8dcSSimon Schubert
108745796c8dcSSimon Schubert int
ada_is_modular_type(struct type * type)108755796c8dcSSimon Schubert ada_is_modular_type (struct type *type)
108765796c8dcSSimon Schubert {
10877a45ae5f8SJohn Marino struct type *subranged_type = get_base_type (type);
108785796c8dcSSimon Schubert
108795796c8dcSSimon Schubert return (subranged_type != NULL && TYPE_CODE (type) == TYPE_CODE_RANGE
108805796c8dcSSimon Schubert && TYPE_CODE (subranged_type) == TYPE_CODE_INT
108815796c8dcSSimon Schubert && TYPE_UNSIGNED (subranged_type));
108825796c8dcSSimon Schubert }
108835796c8dcSSimon Schubert
108845796c8dcSSimon Schubert /* Assuming ada_is_modular_type (TYPE), the modulus of TYPE. */
108855796c8dcSSimon Schubert
108865796c8dcSSimon Schubert ULONGEST
ada_modulus(struct type * type)108875796c8dcSSimon Schubert ada_modulus (struct type *type)
108885796c8dcSSimon Schubert {
10889cf7f2e2dSJohn Marino return (ULONGEST) TYPE_HIGH_BOUND (type) + 1;
108905796c8dcSSimon Schubert }
108915796c8dcSSimon Schubert
108925796c8dcSSimon Schubert
108935796c8dcSSimon Schubert /* Ada exception catchpoint support:
108945796c8dcSSimon Schubert ---------------------------------
108955796c8dcSSimon Schubert
108965796c8dcSSimon Schubert We support 3 kinds of exception catchpoints:
108975796c8dcSSimon Schubert . catchpoints on Ada exceptions
108985796c8dcSSimon Schubert . catchpoints on unhandled Ada exceptions
108995796c8dcSSimon Schubert . catchpoints on failed assertions
109005796c8dcSSimon Schubert
109015796c8dcSSimon Schubert Exceptions raised during failed assertions, or unhandled exceptions
109025796c8dcSSimon Schubert could perfectly be caught with the general catchpoint on Ada exceptions.
109035796c8dcSSimon Schubert However, we can easily differentiate these two special cases, and having
109045796c8dcSSimon Schubert the option to distinguish these two cases from the rest can be useful
109055796c8dcSSimon Schubert to zero-in on certain situations.
109065796c8dcSSimon Schubert
109075796c8dcSSimon Schubert Exception catchpoints are a specialized form of breakpoint,
109085796c8dcSSimon Schubert since they rely on inserting breakpoints inside known routines
109095796c8dcSSimon Schubert of the GNAT runtime. The implementation therefore uses a standard
109105796c8dcSSimon Schubert breakpoint structure of the BP_BREAKPOINT type, but with its own set
109115796c8dcSSimon Schubert of breakpoint_ops.
109125796c8dcSSimon Schubert
109135796c8dcSSimon Schubert Support in the runtime for exception catchpoints have been changed
109145796c8dcSSimon Schubert a few times already, and these changes affect the implementation
109155796c8dcSSimon Schubert of these catchpoints. In order to be able to support several
109165796c8dcSSimon Schubert variants of the runtime, we use a sniffer that will determine
10917a45ae5f8SJohn Marino the runtime variant used by the program being debugged. */
109185796c8dcSSimon Schubert
109195796c8dcSSimon Schubert /* The different types of catchpoints that we introduced for catching
109205796c8dcSSimon Schubert Ada exceptions. */
109215796c8dcSSimon Schubert
109225796c8dcSSimon Schubert enum exception_catchpoint_kind
109235796c8dcSSimon Schubert {
109245796c8dcSSimon Schubert ex_catch_exception,
109255796c8dcSSimon Schubert ex_catch_exception_unhandled,
109265796c8dcSSimon Schubert ex_catch_assert
109275796c8dcSSimon Schubert };
109285796c8dcSSimon Schubert
109295796c8dcSSimon Schubert /* Ada's standard exceptions. */
109305796c8dcSSimon Schubert
109315796c8dcSSimon Schubert static char *standard_exc[] = {
109325796c8dcSSimon Schubert "constraint_error",
109335796c8dcSSimon Schubert "program_error",
109345796c8dcSSimon Schubert "storage_error",
109355796c8dcSSimon Schubert "tasking_error"
109365796c8dcSSimon Schubert };
109375796c8dcSSimon Schubert
109385796c8dcSSimon Schubert typedef CORE_ADDR (ada_unhandled_exception_name_addr_ftype) (void);
109395796c8dcSSimon Schubert
109405796c8dcSSimon Schubert /* A structure that describes how to support exception catchpoints
109415796c8dcSSimon Schubert for a given executable. */
109425796c8dcSSimon Schubert
109435796c8dcSSimon Schubert struct exception_support_info
109445796c8dcSSimon Schubert {
109455796c8dcSSimon Schubert /* The name of the symbol to break on in order to insert
109465796c8dcSSimon Schubert a catchpoint on exceptions. */
109475796c8dcSSimon Schubert const char *catch_exception_sym;
109485796c8dcSSimon Schubert
109495796c8dcSSimon Schubert /* The name of the symbol to break on in order to insert
109505796c8dcSSimon Schubert a catchpoint on unhandled exceptions. */
109515796c8dcSSimon Schubert const char *catch_exception_unhandled_sym;
109525796c8dcSSimon Schubert
109535796c8dcSSimon Schubert /* The name of the symbol to break on in order to insert
109545796c8dcSSimon Schubert a catchpoint on failed assertions. */
109555796c8dcSSimon Schubert const char *catch_assert_sym;
109565796c8dcSSimon Schubert
109575796c8dcSSimon Schubert /* Assuming that the inferior just triggered an unhandled exception
109585796c8dcSSimon Schubert catchpoint, this function is responsible for returning the address
109595796c8dcSSimon Schubert in inferior memory where the name of that exception is stored.
109605796c8dcSSimon Schubert Return zero if the address could not be computed. */
109615796c8dcSSimon Schubert ada_unhandled_exception_name_addr_ftype *unhandled_exception_name_addr;
109625796c8dcSSimon Schubert };
109635796c8dcSSimon Schubert
109645796c8dcSSimon Schubert static CORE_ADDR ada_unhandled_exception_name_addr (void);
109655796c8dcSSimon Schubert static CORE_ADDR ada_unhandled_exception_name_addr_from_raise (void);
109665796c8dcSSimon Schubert
109675796c8dcSSimon Schubert /* The following exception support info structure describes how to
109685796c8dcSSimon Schubert implement exception catchpoints with the latest version of the
109695796c8dcSSimon Schubert Ada runtime (as of 2007-03-06). */
109705796c8dcSSimon Schubert
109715796c8dcSSimon Schubert static const struct exception_support_info default_exception_support_info =
109725796c8dcSSimon Schubert {
109735796c8dcSSimon Schubert "__gnat_debug_raise_exception", /* catch_exception_sym */
109745796c8dcSSimon Schubert "__gnat_unhandled_exception", /* catch_exception_unhandled_sym */
109755796c8dcSSimon Schubert "__gnat_debug_raise_assert_failure", /* catch_assert_sym */
109765796c8dcSSimon Schubert ada_unhandled_exception_name_addr
109775796c8dcSSimon Schubert };
109785796c8dcSSimon Schubert
109795796c8dcSSimon Schubert /* The following exception support info structure describes how to
109805796c8dcSSimon Schubert implement exception catchpoints with a slightly older version
109815796c8dcSSimon Schubert of the Ada runtime. */
109825796c8dcSSimon Schubert
109835796c8dcSSimon Schubert static const struct exception_support_info exception_support_info_fallback =
109845796c8dcSSimon Schubert {
109855796c8dcSSimon Schubert "__gnat_raise_nodefer_with_msg", /* catch_exception_sym */
109865796c8dcSSimon Schubert "__gnat_unhandled_exception", /* catch_exception_unhandled_sym */
109875796c8dcSSimon Schubert "system__assertions__raise_assert_failure", /* catch_assert_sym */
109885796c8dcSSimon Schubert ada_unhandled_exception_name_addr_from_raise
109895796c8dcSSimon Schubert };
109905796c8dcSSimon Schubert
10991a45ae5f8SJohn Marino /* Return nonzero if we can detect the exception support routines
10992a45ae5f8SJohn Marino described in EINFO.
109935796c8dcSSimon Schubert
10994a45ae5f8SJohn Marino This function errors out if an abnormal situation is detected
10995a45ae5f8SJohn Marino (for instance, if we find the exception support routines, but
10996a45ae5f8SJohn Marino that support is found to be incomplete). */
10997a45ae5f8SJohn Marino
10998a45ae5f8SJohn Marino static int
ada_has_this_exception_support(const struct exception_support_info * einfo)10999a45ae5f8SJohn Marino ada_has_this_exception_support (const struct exception_support_info *einfo)
11000a45ae5f8SJohn Marino {
11001a45ae5f8SJohn Marino struct symbol *sym;
11002a45ae5f8SJohn Marino
11003a45ae5f8SJohn Marino /* The symbol we're looking up is provided by a unit in the GNAT runtime
11004a45ae5f8SJohn Marino that should be compiled with debugging information. As a result, we
11005a45ae5f8SJohn Marino expect to find that symbol in the symtabs. */
11006a45ae5f8SJohn Marino
11007a45ae5f8SJohn Marino sym = standard_lookup (einfo->catch_exception_sym, NULL, VAR_DOMAIN);
11008a45ae5f8SJohn Marino if (sym == NULL)
11009a45ae5f8SJohn Marino {
11010a45ae5f8SJohn Marino /* Perhaps we did not find our symbol because the Ada runtime was
11011a45ae5f8SJohn Marino compiled without debugging info, or simply stripped of it.
11012a45ae5f8SJohn Marino It happens on some GNU/Linux distributions for instance, where
11013a45ae5f8SJohn Marino users have to install a separate debug package in order to get
11014a45ae5f8SJohn Marino the runtime's debugging info. In that situation, let the user
11015a45ae5f8SJohn Marino know why we cannot insert an Ada exception catchpoint.
11016a45ae5f8SJohn Marino
11017a45ae5f8SJohn Marino Note: Just for the purpose of inserting our Ada exception
11018a45ae5f8SJohn Marino catchpoint, we could rely purely on the associated minimal symbol.
11019a45ae5f8SJohn Marino But we would be operating in degraded mode anyway, since we are
11020a45ae5f8SJohn Marino still lacking the debugging info needed later on to extract
11021a45ae5f8SJohn Marino the name of the exception being raised (this name is printed in
11022a45ae5f8SJohn Marino the catchpoint message, and is also used when trying to catch
11023a45ae5f8SJohn Marino a specific exception). We do not handle this case for now. */
11024a45ae5f8SJohn Marino if (lookup_minimal_symbol (einfo->catch_exception_sym, NULL, NULL))
11025a45ae5f8SJohn Marino error (_("Your Ada runtime appears to be missing some debugging "
11026a45ae5f8SJohn Marino "information.\nCannot insert Ada exception catchpoint "
11027a45ae5f8SJohn Marino "in this configuration."));
11028a45ae5f8SJohn Marino
11029a45ae5f8SJohn Marino return 0;
11030a45ae5f8SJohn Marino }
11031a45ae5f8SJohn Marino
11032a45ae5f8SJohn Marino /* Make sure that the symbol we found corresponds to a function. */
11033a45ae5f8SJohn Marino
11034a45ae5f8SJohn Marino if (SYMBOL_CLASS (sym) != LOC_BLOCK)
11035a45ae5f8SJohn Marino error (_("Symbol \"%s\" is not a function (class = %d)"),
11036a45ae5f8SJohn Marino SYMBOL_LINKAGE_NAME (sym), SYMBOL_CLASS (sym));
11037a45ae5f8SJohn Marino
11038a45ae5f8SJohn Marino return 1;
11039a45ae5f8SJohn Marino }
110405796c8dcSSimon Schubert
110415796c8dcSSimon Schubert /* Inspect the Ada runtime and determine which exception info structure
110425796c8dcSSimon Schubert should be used to provide support for exception catchpoints.
110435796c8dcSSimon Schubert
11044a45ae5f8SJohn Marino This function will always set the per-inferior exception_info,
11045a45ae5f8SJohn Marino or raise an error. */
110465796c8dcSSimon Schubert
110475796c8dcSSimon Schubert static void
ada_exception_support_info_sniffer(void)110485796c8dcSSimon Schubert ada_exception_support_info_sniffer (void)
110495796c8dcSSimon Schubert {
11050a45ae5f8SJohn Marino struct ada_inferior_data *data = get_ada_inferior_data (current_inferior ());
110515796c8dcSSimon Schubert
110525796c8dcSSimon Schubert /* If the exception info is already known, then no need to recompute it. */
11053a45ae5f8SJohn Marino if (data->exception_info != NULL)
110545796c8dcSSimon Schubert return;
110555796c8dcSSimon Schubert
110565796c8dcSSimon Schubert /* Check the latest (default) exception support info. */
11057a45ae5f8SJohn Marino if (ada_has_this_exception_support (&default_exception_support_info))
110585796c8dcSSimon Schubert {
11059a45ae5f8SJohn Marino data->exception_info = &default_exception_support_info;
110605796c8dcSSimon Schubert return;
110615796c8dcSSimon Schubert }
110625796c8dcSSimon Schubert
110635796c8dcSSimon Schubert /* Try our fallback exception suport info. */
11064a45ae5f8SJohn Marino if (ada_has_this_exception_support (&exception_support_info_fallback))
110655796c8dcSSimon Schubert {
11066a45ae5f8SJohn Marino data->exception_info = &exception_support_info_fallback;
110675796c8dcSSimon Schubert return;
110685796c8dcSSimon Schubert }
110695796c8dcSSimon Schubert
110705796c8dcSSimon Schubert /* Sometimes, it is normal for us to not be able to find the routine
110715796c8dcSSimon Schubert we are looking for. This happens when the program is linked with
110725796c8dcSSimon Schubert the shared version of the GNAT runtime, and the program has not been
110735796c8dcSSimon Schubert started yet. Inform the user of these two possible causes if
110745796c8dcSSimon Schubert applicable. */
110755796c8dcSSimon Schubert
11076cf7f2e2dSJohn Marino if (ada_update_initial_language (language_unknown) != language_ada)
110775796c8dcSSimon Schubert error (_("Unable to insert catchpoint. Is this an Ada main program?"));
110785796c8dcSSimon Schubert
110795796c8dcSSimon Schubert /* If the symbol does not exist, then check that the program is
110805796c8dcSSimon Schubert already started, to make sure that shared libraries have been
110815796c8dcSSimon Schubert loaded. If it is not started, this may mean that the symbol is
110825796c8dcSSimon Schubert in a shared library. */
110835796c8dcSSimon Schubert
110845796c8dcSSimon Schubert if (ptid_get_pid (inferior_ptid) == 0)
110855796c8dcSSimon Schubert error (_("Unable to insert catchpoint. Try to start the program first."));
110865796c8dcSSimon Schubert
110875796c8dcSSimon Schubert /* At this point, we know that we are debugging an Ada program and
110885796c8dcSSimon Schubert that the inferior has been started, but we still are not able to
110895796c8dcSSimon Schubert find the run-time symbols. That can mean that we are in
110905796c8dcSSimon Schubert configurable run time mode, or that a-except as been optimized
110915796c8dcSSimon Schubert out by the linker... In any case, at this point it is not worth
110925796c8dcSSimon Schubert supporting this feature. */
110935796c8dcSSimon Schubert
11094a45ae5f8SJohn Marino error (_("Cannot insert Ada exception catchpoints in this configuration."));
110955796c8dcSSimon Schubert }
110965796c8dcSSimon Schubert
110975796c8dcSSimon Schubert /* True iff FRAME is very likely to be that of a function that is
110985796c8dcSSimon Schubert part of the runtime system. This is all very heuristic, but is
110995796c8dcSSimon Schubert intended to be used as advice as to what frames are uninteresting
111005796c8dcSSimon Schubert to most users. */
111015796c8dcSSimon Schubert
111025796c8dcSSimon Schubert static int
is_known_support_routine(struct frame_info * frame)111035796c8dcSSimon Schubert is_known_support_routine (struct frame_info *frame)
111045796c8dcSSimon Schubert {
111055796c8dcSSimon Schubert struct symtab_and_line sal;
11106*ef5ccd6cSJohn Marino const char *func_name;
11107cf7f2e2dSJohn Marino enum language func_lang;
111085796c8dcSSimon Schubert int i;
11109*ef5ccd6cSJohn Marino const char *fullname;
111105796c8dcSSimon Schubert
111115796c8dcSSimon Schubert /* If this code does not have any debugging information (no symtab),
111125796c8dcSSimon Schubert This cannot be any user code. */
111135796c8dcSSimon Schubert
111145796c8dcSSimon Schubert find_frame_sal (frame, &sal);
111155796c8dcSSimon Schubert if (sal.symtab == NULL)
111165796c8dcSSimon Schubert return 1;
111175796c8dcSSimon Schubert
111185796c8dcSSimon Schubert /* If there is a symtab, but the associated source file cannot be
111195796c8dcSSimon Schubert located, then assume this is not user code: Selecting a frame
111205796c8dcSSimon Schubert for which we cannot display the code would not be very helpful
111215796c8dcSSimon Schubert for the user. This should also take care of case such as VxWorks
111225796c8dcSSimon Schubert where the kernel has some debugging info provided for a few units. */
111235796c8dcSSimon Schubert
11124*ef5ccd6cSJohn Marino fullname = symtab_to_fullname (sal.symtab);
11125*ef5ccd6cSJohn Marino if (access (fullname, R_OK) != 0)
111265796c8dcSSimon Schubert return 1;
111275796c8dcSSimon Schubert
111285796c8dcSSimon Schubert /* Check the unit filename againt the Ada runtime file naming.
111295796c8dcSSimon Schubert We also check the name of the objfile against the name of some
111305796c8dcSSimon Schubert known system libraries that sometimes come with debugging info
111315796c8dcSSimon Schubert too. */
111325796c8dcSSimon Schubert
111335796c8dcSSimon Schubert for (i = 0; known_runtime_file_name_patterns[i] != NULL; i += 1)
111345796c8dcSSimon Schubert {
111355796c8dcSSimon Schubert re_comp (known_runtime_file_name_patterns[i]);
11136*ef5ccd6cSJohn Marino if (re_exec (lbasename (sal.symtab->filename)))
111375796c8dcSSimon Schubert return 1;
111385796c8dcSSimon Schubert if (sal.symtab->objfile != NULL
111395796c8dcSSimon Schubert && re_exec (sal.symtab->objfile->name))
111405796c8dcSSimon Schubert return 1;
111415796c8dcSSimon Schubert }
111425796c8dcSSimon Schubert
111435796c8dcSSimon Schubert /* Check whether the function is a GNAT-generated entity. */
111445796c8dcSSimon Schubert
11145c50c785cSJohn Marino find_frame_funname (frame, &func_name, &func_lang, NULL);
111465796c8dcSSimon Schubert if (func_name == NULL)
111475796c8dcSSimon Schubert return 1;
111485796c8dcSSimon Schubert
111495796c8dcSSimon Schubert for (i = 0; known_auxiliary_function_name_patterns[i] != NULL; i += 1)
111505796c8dcSSimon Schubert {
111515796c8dcSSimon Schubert re_comp (known_auxiliary_function_name_patterns[i]);
111525796c8dcSSimon Schubert if (re_exec (func_name))
111535796c8dcSSimon Schubert return 1;
111545796c8dcSSimon Schubert }
111555796c8dcSSimon Schubert
111565796c8dcSSimon Schubert return 0;
111575796c8dcSSimon Schubert }
111585796c8dcSSimon Schubert
111595796c8dcSSimon Schubert /* Find the first frame that contains debugging information and that is not
111605796c8dcSSimon Schubert part of the Ada run-time, starting from FI and moving upward. */
111615796c8dcSSimon Schubert
111625796c8dcSSimon Schubert void
ada_find_printable_frame(struct frame_info * fi)111635796c8dcSSimon Schubert ada_find_printable_frame (struct frame_info *fi)
111645796c8dcSSimon Schubert {
111655796c8dcSSimon Schubert for (; fi != NULL; fi = get_prev_frame (fi))
111665796c8dcSSimon Schubert {
111675796c8dcSSimon Schubert if (!is_known_support_routine (fi))
111685796c8dcSSimon Schubert {
111695796c8dcSSimon Schubert select_frame (fi);
111705796c8dcSSimon Schubert break;
111715796c8dcSSimon Schubert }
111725796c8dcSSimon Schubert }
111735796c8dcSSimon Schubert
111745796c8dcSSimon Schubert }
111755796c8dcSSimon Schubert
111765796c8dcSSimon Schubert /* Assuming that the inferior just triggered an unhandled exception
111775796c8dcSSimon Schubert catchpoint, return the address in inferior memory where the name
111785796c8dcSSimon Schubert of the exception is stored.
111795796c8dcSSimon Schubert
111805796c8dcSSimon Schubert Return zero if the address could not be computed. */
111815796c8dcSSimon Schubert
111825796c8dcSSimon Schubert static CORE_ADDR
ada_unhandled_exception_name_addr(void)111835796c8dcSSimon Schubert ada_unhandled_exception_name_addr (void)
111845796c8dcSSimon Schubert {
111855796c8dcSSimon Schubert return parse_and_eval_address ("e.full_name");
111865796c8dcSSimon Schubert }
111875796c8dcSSimon Schubert
111885796c8dcSSimon Schubert /* Same as ada_unhandled_exception_name_addr, except that this function
111895796c8dcSSimon Schubert should be used when the inferior uses an older version of the runtime,
111905796c8dcSSimon Schubert where the exception name needs to be extracted from a specific frame
111915796c8dcSSimon Schubert several frames up in the callstack. */
111925796c8dcSSimon Schubert
111935796c8dcSSimon Schubert static CORE_ADDR
ada_unhandled_exception_name_addr_from_raise(void)111945796c8dcSSimon Schubert ada_unhandled_exception_name_addr_from_raise (void)
111955796c8dcSSimon Schubert {
111965796c8dcSSimon Schubert int frame_level;
111975796c8dcSSimon Schubert struct frame_info *fi;
11198a45ae5f8SJohn Marino struct ada_inferior_data *data = get_ada_inferior_data (current_inferior ());
111995796c8dcSSimon Schubert
112005796c8dcSSimon Schubert /* To determine the name of this exception, we need to select
112015796c8dcSSimon Schubert the frame corresponding to RAISE_SYM_NAME. This frame is
112025796c8dcSSimon Schubert at least 3 levels up, so we simply skip the first 3 frames
112035796c8dcSSimon Schubert without checking the name of their associated function. */
112045796c8dcSSimon Schubert fi = get_current_frame ();
112055796c8dcSSimon Schubert for (frame_level = 0; frame_level < 3; frame_level += 1)
112065796c8dcSSimon Schubert if (fi != NULL)
112075796c8dcSSimon Schubert fi = get_prev_frame (fi);
112085796c8dcSSimon Schubert
112095796c8dcSSimon Schubert while (fi != NULL)
112105796c8dcSSimon Schubert {
11211*ef5ccd6cSJohn Marino const char *func_name;
11212cf7f2e2dSJohn Marino enum language func_lang;
11213cf7f2e2dSJohn Marino
11214c50c785cSJohn Marino find_frame_funname (fi, &func_name, &func_lang, NULL);
112155796c8dcSSimon Schubert if (func_name != NULL
11216a45ae5f8SJohn Marino && strcmp (func_name, data->exception_info->catch_exception_sym) == 0)
112175796c8dcSSimon Schubert break; /* We found the frame we were looking for... */
112185796c8dcSSimon Schubert fi = get_prev_frame (fi);
112195796c8dcSSimon Schubert }
112205796c8dcSSimon Schubert
112215796c8dcSSimon Schubert if (fi == NULL)
112225796c8dcSSimon Schubert return 0;
112235796c8dcSSimon Schubert
112245796c8dcSSimon Schubert select_frame (fi);
112255796c8dcSSimon Schubert return parse_and_eval_address ("id.full_name");
112265796c8dcSSimon Schubert }
112275796c8dcSSimon Schubert
112285796c8dcSSimon Schubert /* Assuming the inferior just triggered an Ada exception catchpoint
112295796c8dcSSimon Schubert (of any type), return the address in inferior memory where the name
112305796c8dcSSimon Schubert of the exception is stored, if applicable.
112315796c8dcSSimon Schubert
112325796c8dcSSimon Schubert Return zero if the address could not be computed, or if not relevant. */
112335796c8dcSSimon Schubert
112345796c8dcSSimon Schubert static CORE_ADDR
ada_exception_name_addr_1(enum exception_catchpoint_kind ex,struct breakpoint * b)112355796c8dcSSimon Schubert ada_exception_name_addr_1 (enum exception_catchpoint_kind ex,
112365796c8dcSSimon Schubert struct breakpoint *b)
112375796c8dcSSimon Schubert {
11238a45ae5f8SJohn Marino struct ada_inferior_data *data = get_ada_inferior_data (current_inferior ());
11239a45ae5f8SJohn Marino
112405796c8dcSSimon Schubert switch (ex)
112415796c8dcSSimon Schubert {
112425796c8dcSSimon Schubert case ex_catch_exception:
112435796c8dcSSimon Schubert return (parse_and_eval_address ("e.full_name"));
112445796c8dcSSimon Schubert break;
112455796c8dcSSimon Schubert
112465796c8dcSSimon Schubert case ex_catch_exception_unhandled:
11247a45ae5f8SJohn Marino return data->exception_info->unhandled_exception_name_addr ();
112485796c8dcSSimon Schubert break;
112495796c8dcSSimon Schubert
112505796c8dcSSimon Schubert case ex_catch_assert:
112515796c8dcSSimon Schubert return 0; /* Exception name is not relevant in this case. */
112525796c8dcSSimon Schubert break;
112535796c8dcSSimon Schubert
112545796c8dcSSimon Schubert default:
112555796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, _("unexpected catchpoint type"));
112565796c8dcSSimon Schubert break;
112575796c8dcSSimon Schubert }
112585796c8dcSSimon Schubert
112595796c8dcSSimon Schubert return 0; /* Should never be reached. */
112605796c8dcSSimon Schubert }
112615796c8dcSSimon Schubert
112625796c8dcSSimon Schubert /* Same as ada_exception_name_addr_1, except that it intercepts and contains
112635796c8dcSSimon Schubert any error that ada_exception_name_addr_1 might cause to be thrown.
112645796c8dcSSimon Schubert When an error is intercepted, a warning with the error message is printed,
112655796c8dcSSimon Schubert and zero is returned. */
112665796c8dcSSimon Schubert
112675796c8dcSSimon Schubert static CORE_ADDR
ada_exception_name_addr(enum exception_catchpoint_kind ex,struct breakpoint * b)112685796c8dcSSimon Schubert ada_exception_name_addr (enum exception_catchpoint_kind ex,
112695796c8dcSSimon Schubert struct breakpoint *b)
112705796c8dcSSimon Schubert {
11271*ef5ccd6cSJohn Marino volatile struct gdb_exception e;
112725796c8dcSSimon Schubert CORE_ADDR result = 0;
112735796c8dcSSimon Schubert
112745796c8dcSSimon Schubert TRY_CATCH (e, RETURN_MASK_ERROR)
112755796c8dcSSimon Schubert {
112765796c8dcSSimon Schubert result = ada_exception_name_addr_1 (ex, b);
112775796c8dcSSimon Schubert }
112785796c8dcSSimon Schubert
112795796c8dcSSimon Schubert if (e.reason < 0)
112805796c8dcSSimon Schubert {
112815796c8dcSSimon Schubert warning (_("failed to get exception name: %s"), e.message);
112825796c8dcSSimon Schubert return 0;
112835796c8dcSSimon Schubert }
112845796c8dcSSimon Schubert
112855796c8dcSSimon Schubert return result;
112865796c8dcSSimon Schubert }
112875796c8dcSSimon Schubert
11288a45ae5f8SJohn Marino static struct symtab_and_line ada_exception_sal (enum exception_catchpoint_kind,
11289a45ae5f8SJohn Marino char *, char **,
11290a45ae5f8SJohn Marino const struct breakpoint_ops **);
11291a45ae5f8SJohn Marino static char *ada_exception_catchpoint_cond_string (const char *excep_string);
11292a45ae5f8SJohn Marino
11293a45ae5f8SJohn Marino /* Ada catchpoints.
11294a45ae5f8SJohn Marino
11295a45ae5f8SJohn Marino In the case of catchpoints on Ada exceptions, the catchpoint will
11296a45ae5f8SJohn Marino stop the target on every exception the program throws. When a user
11297a45ae5f8SJohn Marino specifies the name of a specific exception, we translate this
11298a45ae5f8SJohn Marino request into a condition expression (in text form), and then parse
11299a45ae5f8SJohn Marino it into an expression stored in each of the catchpoint's locations.
11300a45ae5f8SJohn Marino We then use this condition to check whether the exception that was
11301a45ae5f8SJohn Marino raised is the one the user is interested in. If not, then the
11302a45ae5f8SJohn Marino target is resumed again. We store the name of the requested
11303a45ae5f8SJohn Marino exception, in order to be able to re-set the condition expression
11304a45ae5f8SJohn Marino when symbols change. */
11305a45ae5f8SJohn Marino
11306a45ae5f8SJohn Marino /* An instance of this type is used to represent an Ada catchpoint
11307a45ae5f8SJohn Marino breakpoint location. It includes a "struct bp_location" as a kind
11308a45ae5f8SJohn Marino of base class; users downcast to "struct bp_location *" when
11309a45ae5f8SJohn Marino needed. */
11310a45ae5f8SJohn Marino
11311a45ae5f8SJohn Marino struct ada_catchpoint_location
11312a45ae5f8SJohn Marino {
11313a45ae5f8SJohn Marino /* The base class. */
11314a45ae5f8SJohn Marino struct bp_location base;
11315a45ae5f8SJohn Marino
11316a45ae5f8SJohn Marino /* The condition that checks whether the exception that was raised
11317a45ae5f8SJohn Marino is the specific exception the user specified on catchpoint
11318a45ae5f8SJohn Marino creation. */
11319a45ae5f8SJohn Marino struct expression *excep_cond_expr;
11320a45ae5f8SJohn Marino };
11321a45ae5f8SJohn Marino
11322a45ae5f8SJohn Marino /* Implement the DTOR method in the bp_location_ops structure for all
11323a45ae5f8SJohn Marino Ada exception catchpoint kinds. */
11324a45ae5f8SJohn Marino
11325a45ae5f8SJohn Marino static void
ada_catchpoint_location_dtor(struct bp_location * bl)11326a45ae5f8SJohn Marino ada_catchpoint_location_dtor (struct bp_location *bl)
11327a45ae5f8SJohn Marino {
11328a45ae5f8SJohn Marino struct ada_catchpoint_location *al = (struct ada_catchpoint_location *) bl;
11329a45ae5f8SJohn Marino
11330a45ae5f8SJohn Marino xfree (al->excep_cond_expr);
11331a45ae5f8SJohn Marino }
11332a45ae5f8SJohn Marino
11333a45ae5f8SJohn Marino /* The vtable to be used in Ada catchpoint locations. */
11334a45ae5f8SJohn Marino
11335a45ae5f8SJohn Marino static const struct bp_location_ops ada_catchpoint_location_ops =
11336a45ae5f8SJohn Marino {
11337a45ae5f8SJohn Marino ada_catchpoint_location_dtor
11338a45ae5f8SJohn Marino };
11339a45ae5f8SJohn Marino
11340a45ae5f8SJohn Marino /* An instance of this type is used to represent an Ada catchpoint.
11341a45ae5f8SJohn Marino It includes a "struct breakpoint" as a kind of base class; users
11342a45ae5f8SJohn Marino downcast to "struct breakpoint *" when needed. */
11343a45ae5f8SJohn Marino
11344a45ae5f8SJohn Marino struct ada_catchpoint
11345a45ae5f8SJohn Marino {
11346a45ae5f8SJohn Marino /* The base class. */
11347a45ae5f8SJohn Marino struct breakpoint base;
11348a45ae5f8SJohn Marino
11349a45ae5f8SJohn Marino /* The name of the specific exception the user specified. */
11350a45ae5f8SJohn Marino char *excep_string;
11351a45ae5f8SJohn Marino };
11352a45ae5f8SJohn Marino
11353a45ae5f8SJohn Marino /* Parse the exception condition string in the context of each of the
11354a45ae5f8SJohn Marino catchpoint's locations, and store them for later evaluation. */
11355a45ae5f8SJohn Marino
11356a45ae5f8SJohn Marino static void
create_excep_cond_exprs(struct ada_catchpoint * c)11357a45ae5f8SJohn Marino create_excep_cond_exprs (struct ada_catchpoint *c)
11358a45ae5f8SJohn Marino {
11359a45ae5f8SJohn Marino struct cleanup *old_chain;
11360a45ae5f8SJohn Marino struct bp_location *bl;
11361a45ae5f8SJohn Marino char *cond_string;
11362a45ae5f8SJohn Marino
11363a45ae5f8SJohn Marino /* Nothing to do if there's no specific exception to catch. */
11364a45ae5f8SJohn Marino if (c->excep_string == NULL)
11365a45ae5f8SJohn Marino return;
11366a45ae5f8SJohn Marino
11367a45ae5f8SJohn Marino /* Same if there are no locations... */
11368a45ae5f8SJohn Marino if (c->base.loc == NULL)
11369a45ae5f8SJohn Marino return;
11370a45ae5f8SJohn Marino
11371a45ae5f8SJohn Marino /* Compute the condition expression in text form, from the specific
11372a45ae5f8SJohn Marino expection we want to catch. */
11373a45ae5f8SJohn Marino cond_string = ada_exception_catchpoint_cond_string (c->excep_string);
11374a45ae5f8SJohn Marino old_chain = make_cleanup (xfree, cond_string);
11375a45ae5f8SJohn Marino
11376a45ae5f8SJohn Marino /* Iterate over all the catchpoint's locations, and parse an
11377a45ae5f8SJohn Marino expression for each. */
11378a45ae5f8SJohn Marino for (bl = c->base.loc; bl != NULL; bl = bl->next)
11379a45ae5f8SJohn Marino {
11380a45ae5f8SJohn Marino struct ada_catchpoint_location *ada_loc
11381a45ae5f8SJohn Marino = (struct ada_catchpoint_location *) bl;
11382a45ae5f8SJohn Marino struct expression *exp = NULL;
11383a45ae5f8SJohn Marino
11384a45ae5f8SJohn Marino if (!bl->shlib_disabled)
11385a45ae5f8SJohn Marino {
11386a45ae5f8SJohn Marino volatile struct gdb_exception e;
11387*ef5ccd6cSJohn Marino const char *s;
11388a45ae5f8SJohn Marino
11389a45ae5f8SJohn Marino s = cond_string;
11390a45ae5f8SJohn Marino TRY_CATCH (e, RETURN_MASK_ERROR)
11391a45ae5f8SJohn Marino {
11392*ef5ccd6cSJohn Marino exp = parse_exp_1 (&s, bl->address,
11393*ef5ccd6cSJohn Marino block_for_pc (bl->address), 0);
11394a45ae5f8SJohn Marino }
11395a45ae5f8SJohn Marino if (e.reason < 0)
11396a45ae5f8SJohn Marino warning (_("failed to reevaluate internal exception condition "
11397a45ae5f8SJohn Marino "for catchpoint %d: %s"),
11398a45ae5f8SJohn Marino c->base.number, e.message);
11399a45ae5f8SJohn Marino }
11400a45ae5f8SJohn Marino
11401a45ae5f8SJohn Marino ada_loc->excep_cond_expr = exp;
11402a45ae5f8SJohn Marino }
11403a45ae5f8SJohn Marino
11404a45ae5f8SJohn Marino do_cleanups (old_chain);
11405a45ae5f8SJohn Marino }
11406a45ae5f8SJohn Marino
11407a45ae5f8SJohn Marino /* Implement the DTOR method in the breakpoint_ops structure for all
11408a45ae5f8SJohn Marino exception catchpoint kinds. */
11409a45ae5f8SJohn Marino
11410a45ae5f8SJohn Marino static void
dtor_exception(enum exception_catchpoint_kind ex,struct breakpoint * b)11411a45ae5f8SJohn Marino dtor_exception (enum exception_catchpoint_kind ex, struct breakpoint *b)
11412a45ae5f8SJohn Marino {
11413a45ae5f8SJohn Marino struct ada_catchpoint *c = (struct ada_catchpoint *) b;
11414a45ae5f8SJohn Marino
11415a45ae5f8SJohn Marino xfree (c->excep_string);
11416a45ae5f8SJohn Marino
11417a45ae5f8SJohn Marino bkpt_breakpoint_ops.dtor (b);
11418a45ae5f8SJohn Marino }
11419a45ae5f8SJohn Marino
11420a45ae5f8SJohn Marino /* Implement the ALLOCATE_LOCATION method in the breakpoint_ops
11421a45ae5f8SJohn Marino structure for all exception catchpoint kinds. */
11422a45ae5f8SJohn Marino
11423a45ae5f8SJohn Marino static struct bp_location *
allocate_location_exception(enum exception_catchpoint_kind ex,struct breakpoint * self)11424a45ae5f8SJohn Marino allocate_location_exception (enum exception_catchpoint_kind ex,
11425a45ae5f8SJohn Marino struct breakpoint *self)
11426a45ae5f8SJohn Marino {
11427a45ae5f8SJohn Marino struct ada_catchpoint_location *loc;
11428a45ae5f8SJohn Marino
11429a45ae5f8SJohn Marino loc = XNEW (struct ada_catchpoint_location);
11430a45ae5f8SJohn Marino init_bp_location (&loc->base, &ada_catchpoint_location_ops, self);
11431a45ae5f8SJohn Marino loc->excep_cond_expr = NULL;
11432a45ae5f8SJohn Marino return &loc->base;
11433a45ae5f8SJohn Marino }
11434a45ae5f8SJohn Marino
11435a45ae5f8SJohn Marino /* Implement the RE_SET method in the breakpoint_ops structure for all
11436a45ae5f8SJohn Marino exception catchpoint kinds. */
11437a45ae5f8SJohn Marino
11438a45ae5f8SJohn Marino static void
re_set_exception(enum exception_catchpoint_kind ex,struct breakpoint * b)11439a45ae5f8SJohn Marino re_set_exception (enum exception_catchpoint_kind ex, struct breakpoint *b)
11440a45ae5f8SJohn Marino {
11441a45ae5f8SJohn Marino struct ada_catchpoint *c = (struct ada_catchpoint *) b;
11442a45ae5f8SJohn Marino
11443a45ae5f8SJohn Marino /* Call the base class's method. This updates the catchpoint's
11444a45ae5f8SJohn Marino locations. */
11445a45ae5f8SJohn Marino bkpt_breakpoint_ops.re_set (b);
11446a45ae5f8SJohn Marino
11447a45ae5f8SJohn Marino /* Reparse the exception conditional expressions. One for each
11448a45ae5f8SJohn Marino location. */
11449a45ae5f8SJohn Marino create_excep_cond_exprs (c);
11450a45ae5f8SJohn Marino }
11451a45ae5f8SJohn Marino
11452a45ae5f8SJohn Marino /* Returns true if we should stop for this breakpoint hit. If the
11453a45ae5f8SJohn Marino user specified a specific exception, we only want to cause a stop
11454a45ae5f8SJohn Marino if the program thrown that exception. */
11455a45ae5f8SJohn Marino
11456a45ae5f8SJohn Marino static int
should_stop_exception(const struct bp_location * bl)11457a45ae5f8SJohn Marino should_stop_exception (const struct bp_location *bl)
11458a45ae5f8SJohn Marino {
11459a45ae5f8SJohn Marino struct ada_catchpoint *c = (struct ada_catchpoint *) bl->owner;
11460a45ae5f8SJohn Marino const struct ada_catchpoint_location *ada_loc
11461a45ae5f8SJohn Marino = (const struct ada_catchpoint_location *) bl;
11462a45ae5f8SJohn Marino volatile struct gdb_exception ex;
11463a45ae5f8SJohn Marino int stop;
11464a45ae5f8SJohn Marino
11465a45ae5f8SJohn Marino /* With no specific exception, should always stop. */
11466a45ae5f8SJohn Marino if (c->excep_string == NULL)
11467a45ae5f8SJohn Marino return 1;
11468a45ae5f8SJohn Marino
11469a45ae5f8SJohn Marino if (ada_loc->excep_cond_expr == NULL)
11470a45ae5f8SJohn Marino {
11471a45ae5f8SJohn Marino /* We will have a NULL expression if back when we were creating
11472a45ae5f8SJohn Marino the expressions, this location's had failed to parse. */
11473a45ae5f8SJohn Marino return 1;
11474a45ae5f8SJohn Marino }
11475a45ae5f8SJohn Marino
11476a45ae5f8SJohn Marino stop = 1;
11477a45ae5f8SJohn Marino TRY_CATCH (ex, RETURN_MASK_ALL)
11478a45ae5f8SJohn Marino {
11479a45ae5f8SJohn Marino struct value *mark;
11480a45ae5f8SJohn Marino
11481a45ae5f8SJohn Marino mark = value_mark ();
11482a45ae5f8SJohn Marino stop = value_true (evaluate_expression (ada_loc->excep_cond_expr));
11483a45ae5f8SJohn Marino value_free_to_mark (mark);
11484a45ae5f8SJohn Marino }
11485a45ae5f8SJohn Marino if (ex.reason < 0)
11486a45ae5f8SJohn Marino exception_fprintf (gdb_stderr, ex,
11487a45ae5f8SJohn Marino _("Error in testing exception condition:\n"));
11488a45ae5f8SJohn Marino return stop;
11489a45ae5f8SJohn Marino }
11490a45ae5f8SJohn Marino
11491a45ae5f8SJohn Marino /* Implement the CHECK_STATUS method in the breakpoint_ops structure
11492a45ae5f8SJohn Marino for all exception catchpoint kinds. */
11493a45ae5f8SJohn Marino
11494a45ae5f8SJohn Marino static void
check_status_exception(enum exception_catchpoint_kind ex,bpstat bs)11495a45ae5f8SJohn Marino check_status_exception (enum exception_catchpoint_kind ex, bpstat bs)
11496a45ae5f8SJohn Marino {
11497a45ae5f8SJohn Marino bs->stop = should_stop_exception (bs->bp_location_at);
11498a45ae5f8SJohn Marino }
11499a45ae5f8SJohn Marino
115005796c8dcSSimon Schubert /* Implement the PRINT_IT method in the breakpoint_ops structure
115015796c8dcSSimon Schubert for all exception catchpoint kinds. */
115025796c8dcSSimon Schubert
115035796c8dcSSimon Schubert static enum print_stop_action
print_it_exception(enum exception_catchpoint_kind ex,bpstat bs)11504a45ae5f8SJohn Marino print_it_exception (enum exception_catchpoint_kind ex, bpstat bs)
115055796c8dcSSimon Schubert {
11506a45ae5f8SJohn Marino struct ui_out *uiout = current_uiout;
11507a45ae5f8SJohn Marino struct breakpoint *b = bs->breakpoint_at;
11508a45ae5f8SJohn Marino
11509c50c785cSJohn Marino annotate_catchpoint (b->number);
11510c50c785cSJohn Marino
11511c50c785cSJohn Marino if (ui_out_is_mi_like_p (uiout))
11512c50c785cSJohn Marino {
11513c50c785cSJohn Marino ui_out_field_string (uiout, "reason",
11514c50c785cSJohn Marino async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
11515c50c785cSJohn Marino ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
11516c50c785cSJohn Marino }
11517c50c785cSJohn Marino
11518a45ae5f8SJohn Marino ui_out_text (uiout,
11519a45ae5f8SJohn Marino b->disposition == disp_del ? "\nTemporary catchpoint "
11520a45ae5f8SJohn Marino : "\nCatchpoint ");
11521c50c785cSJohn Marino ui_out_field_int (uiout, "bkptno", b->number);
11522c50c785cSJohn Marino ui_out_text (uiout, ", ");
11523c50c785cSJohn Marino
11524c50c785cSJohn Marino switch (ex)
11525c50c785cSJohn Marino {
11526c50c785cSJohn Marino case ex_catch_exception:
11527c50c785cSJohn Marino case ex_catch_exception_unhandled:
11528c50c785cSJohn Marino {
115295796c8dcSSimon Schubert const CORE_ADDR addr = ada_exception_name_addr (ex, b);
115305796c8dcSSimon Schubert char exception_name[256];
115315796c8dcSSimon Schubert
115325796c8dcSSimon Schubert if (addr != 0)
115335796c8dcSSimon Schubert {
115345796c8dcSSimon Schubert read_memory (addr, exception_name, sizeof (exception_name) - 1);
115355796c8dcSSimon Schubert exception_name [sizeof (exception_name) - 1] = '\0';
115365796c8dcSSimon Schubert }
11537c50c785cSJohn Marino else
115385796c8dcSSimon Schubert {
11539c50c785cSJohn Marino /* For some reason, we were unable to read the exception
11540c50c785cSJohn Marino name. This could happen if the Runtime was compiled
11541c50c785cSJohn Marino without debugging info, for instance. In that case,
11542c50c785cSJohn Marino just replace the exception name by the generic string
11543c50c785cSJohn Marino "exception" - it will read as "an exception" in the
11544c50c785cSJohn Marino notification we are about to print. */
11545a45ae5f8SJohn Marino memcpy (exception_name, "exception", sizeof ("exception"));
11546c50c785cSJohn Marino }
11547c50c785cSJohn Marino /* In the case of unhandled exception breakpoints, we print
11548c50c785cSJohn Marino the exception name as "unhandled EXCEPTION_NAME", to make
11549c50c785cSJohn Marino it clearer to the user which kind of catchpoint just got
11550c50c785cSJohn Marino hit. We used ui_out_text to make sure that this extra
11551c50c785cSJohn Marino info does not pollute the exception name in the MI case. */
11552c50c785cSJohn Marino if (ex == ex_catch_exception_unhandled)
11553c50c785cSJohn Marino ui_out_text (uiout, "unhandled ");
11554c50c785cSJohn Marino ui_out_field_string (uiout, "exception-name", exception_name);
11555c50c785cSJohn Marino }
115565796c8dcSSimon Schubert break;
115575796c8dcSSimon Schubert case ex_catch_assert:
11558c50c785cSJohn Marino /* In this case, the name of the exception is not really
11559c50c785cSJohn Marino important. Just print "failed assertion" to make it clearer
11560c50c785cSJohn Marino that his program just hit an assertion-failure catchpoint.
11561c50c785cSJohn Marino We used ui_out_text because this info does not belong in
11562c50c785cSJohn Marino the MI output. */
11563c50c785cSJohn Marino ui_out_text (uiout, "failed assertion");
115645796c8dcSSimon Schubert break;
115655796c8dcSSimon Schubert }
11566c50c785cSJohn Marino ui_out_text (uiout, " at ");
11567c50c785cSJohn Marino ada_find_printable_frame (get_current_frame ());
115685796c8dcSSimon Schubert
115695796c8dcSSimon Schubert return PRINT_SRC_AND_LOC;
115705796c8dcSSimon Schubert }
115715796c8dcSSimon Schubert
115725796c8dcSSimon Schubert /* Implement the PRINT_ONE method in the breakpoint_ops structure
115735796c8dcSSimon Schubert for all exception catchpoint kinds. */
115745796c8dcSSimon Schubert
115755796c8dcSSimon Schubert static void
print_one_exception(enum exception_catchpoint_kind ex,struct breakpoint * b,struct bp_location ** last_loc)115765796c8dcSSimon Schubert print_one_exception (enum exception_catchpoint_kind ex,
115775796c8dcSSimon Schubert struct breakpoint *b, struct bp_location **last_loc)
115785796c8dcSSimon Schubert {
11579a45ae5f8SJohn Marino struct ui_out *uiout = current_uiout;
11580a45ae5f8SJohn Marino struct ada_catchpoint *c = (struct ada_catchpoint *) b;
115815796c8dcSSimon Schubert struct value_print_options opts;
115825796c8dcSSimon Schubert
115835796c8dcSSimon Schubert get_user_print_options (&opts);
115845796c8dcSSimon Schubert if (opts.addressprint)
115855796c8dcSSimon Schubert {
115865796c8dcSSimon Schubert annotate_field (4);
115875796c8dcSSimon Schubert ui_out_field_core_addr (uiout, "addr", b->loc->gdbarch, b->loc->address);
115885796c8dcSSimon Schubert }
115895796c8dcSSimon Schubert
115905796c8dcSSimon Schubert annotate_field (5);
115915796c8dcSSimon Schubert *last_loc = b->loc;
115925796c8dcSSimon Schubert switch (ex)
115935796c8dcSSimon Schubert {
115945796c8dcSSimon Schubert case ex_catch_exception:
11595a45ae5f8SJohn Marino if (c->excep_string != NULL)
115965796c8dcSSimon Schubert {
11597a45ae5f8SJohn Marino char *msg = xstrprintf (_("`%s' Ada exception"), c->excep_string);
115985796c8dcSSimon Schubert
115995796c8dcSSimon Schubert ui_out_field_string (uiout, "what", msg);
116005796c8dcSSimon Schubert xfree (msg);
116015796c8dcSSimon Schubert }
116025796c8dcSSimon Schubert else
116035796c8dcSSimon Schubert ui_out_field_string (uiout, "what", "all Ada exceptions");
116045796c8dcSSimon Schubert
116055796c8dcSSimon Schubert break;
116065796c8dcSSimon Schubert
116075796c8dcSSimon Schubert case ex_catch_exception_unhandled:
116085796c8dcSSimon Schubert ui_out_field_string (uiout, "what", "unhandled Ada exceptions");
116095796c8dcSSimon Schubert break;
116105796c8dcSSimon Schubert
116115796c8dcSSimon Schubert case ex_catch_assert:
116125796c8dcSSimon Schubert ui_out_field_string (uiout, "what", "failed Ada assertions");
116135796c8dcSSimon Schubert break;
116145796c8dcSSimon Schubert
116155796c8dcSSimon Schubert default:
116165796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, _("unexpected catchpoint type"));
116175796c8dcSSimon Schubert break;
116185796c8dcSSimon Schubert }
116195796c8dcSSimon Schubert }
116205796c8dcSSimon Schubert
116215796c8dcSSimon Schubert /* Implement the PRINT_MENTION method in the breakpoint_ops structure
116225796c8dcSSimon Schubert for all exception catchpoint kinds. */
116235796c8dcSSimon Schubert
116245796c8dcSSimon Schubert static void
print_mention_exception(enum exception_catchpoint_kind ex,struct breakpoint * b)116255796c8dcSSimon Schubert print_mention_exception (enum exception_catchpoint_kind ex,
116265796c8dcSSimon Schubert struct breakpoint *b)
116275796c8dcSSimon Schubert {
11628a45ae5f8SJohn Marino struct ada_catchpoint *c = (struct ada_catchpoint *) b;
11629a45ae5f8SJohn Marino struct ui_out *uiout = current_uiout;
11630a45ae5f8SJohn Marino
11631a45ae5f8SJohn Marino ui_out_text (uiout, b->disposition == disp_del ? _("Temporary catchpoint ")
11632a45ae5f8SJohn Marino : _("Catchpoint "));
11633a45ae5f8SJohn Marino ui_out_field_int (uiout, "bkptno", b->number);
11634a45ae5f8SJohn Marino ui_out_text (uiout, ": ");
11635a45ae5f8SJohn Marino
116365796c8dcSSimon Schubert switch (ex)
116375796c8dcSSimon Schubert {
116385796c8dcSSimon Schubert case ex_catch_exception:
11639a45ae5f8SJohn Marino if (c->excep_string != NULL)
11640a45ae5f8SJohn Marino {
11641a45ae5f8SJohn Marino char *info = xstrprintf (_("`%s' Ada exception"), c->excep_string);
11642a45ae5f8SJohn Marino struct cleanup *old_chain = make_cleanup (xfree, info);
116435796c8dcSSimon Schubert
11644a45ae5f8SJohn Marino ui_out_text (uiout, info);
11645a45ae5f8SJohn Marino do_cleanups (old_chain);
11646a45ae5f8SJohn Marino }
11647a45ae5f8SJohn Marino else
11648a45ae5f8SJohn Marino ui_out_text (uiout, _("all Ada exceptions"));
116495796c8dcSSimon Schubert break;
116505796c8dcSSimon Schubert
116515796c8dcSSimon Schubert case ex_catch_exception_unhandled:
11652a45ae5f8SJohn Marino ui_out_text (uiout, _("unhandled Ada exceptions"));
116535796c8dcSSimon Schubert break;
116545796c8dcSSimon Schubert
116555796c8dcSSimon Schubert case ex_catch_assert:
11656a45ae5f8SJohn Marino ui_out_text (uiout, _("failed Ada assertions"));
116575796c8dcSSimon Schubert break;
116585796c8dcSSimon Schubert
116595796c8dcSSimon Schubert default:
116605796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, _("unexpected catchpoint type"));
116615796c8dcSSimon Schubert break;
116625796c8dcSSimon Schubert }
116635796c8dcSSimon Schubert }
116645796c8dcSSimon Schubert
11665cf7f2e2dSJohn Marino /* Implement the PRINT_RECREATE method in the breakpoint_ops structure
11666cf7f2e2dSJohn Marino for all exception catchpoint kinds. */
11667cf7f2e2dSJohn Marino
11668cf7f2e2dSJohn Marino static void
print_recreate_exception(enum exception_catchpoint_kind ex,struct breakpoint * b,struct ui_file * fp)11669cf7f2e2dSJohn Marino print_recreate_exception (enum exception_catchpoint_kind ex,
11670cf7f2e2dSJohn Marino struct breakpoint *b, struct ui_file *fp)
11671cf7f2e2dSJohn Marino {
11672a45ae5f8SJohn Marino struct ada_catchpoint *c = (struct ada_catchpoint *) b;
11673a45ae5f8SJohn Marino
11674cf7f2e2dSJohn Marino switch (ex)
11675cf7f2e2dSJohn Marino {
11676cf7f2e2dSJohn Marino case ex_catch_exception:
11677cf7f2e2dSJohn Marino fprintf_filtered (fp, "catch exception");
11678a45ae5f8SJohn Marino if (c->excep_string != NULL)
11679a45ae5f8SJohn Marino fprintf_filtered (fp, " %s", c->excep_string);
11680cf7f2e2dSJohn Marino break;
11681cf7f2e2dSJohn Marino
11682cf7f2e2dSJohn Marino case ex_catch_exception_unhandled:
11683cf7f2e2dSJohn Marino fprintf_filtered (fp, "catch exception unhandled");
11684cf7f2e2dSJohn Marino break;
11685cf7f2e2dSJohn Marino
11686cf7f2e2dSJohn Marino case ex_catch_assert:
11687cf7f2e2dSJohn Marino fprintf_filtered (fp, "catch assert");
11688cf7f2e2dSJohn Marino break;
11689cf7f2e2dSJohn Marino
11690cf7f2e2dSJohn Marino default:
11691cf7f2e2dSJohn Marino internal_error (__FILE__, __LINE__, _("unexpected catchpoint type"));
11692cf7f2e2dSJohn Marino }
11693a45ae5f8SJohn Marino print_recreate_thread (b, fp);
11694cf7f2e2dSJohn Marino }
11695cf7f2e2dSJohn Marino
116965796c8dcSSimon Schubert /* Virtual table for "catch exception" breakpoints. */
116975796c8dcSSimon Schubert
11698a45ae5f8SJohn Marino static void
dtor_catch_exception(struct breakpoint * b)11699a45ae5f8SJohn Marino dtor_catch_exception (struct breakpoint *b)
117005796c8dcSSimon Schubert {
11701a45ae5f8SJohn Marino dtor_exception (ex_catch_exception, b);
11702a45ae5f8SJohn Marino }
11703a45ae5f8SJohn Marino
11704a45ae5f8SJohn Marino static struct bp_location *
allocate_location_catch_exception(struct breakpoint * self)11705a45ae5f8SJohn Marino allocate_location_catch_exception (struct breakpoint *self)
11706a45ae5f8SJohn Marino {
11707a45ae5f8SJohn Marino return allocate_location_exception (ex_catch_exception, self);
11708a45ae5f8SJohn Marino }
11709a45ae5f8SJohn Marino
11710a45ae5f8SJohn Marino static void
re_set_catch_exception(struct breakpoint * b)11711a45ae5f8SJohn Marino re_set_catch_exception (struct breakpoint *b)
11712a45ae5f8SJohn Marino {
11713a45ae5f8SJohn Marino re_set_exception (ex_catch_exception, b);
11714a45ae5f8SJohn Marino }
11715a45ae5f8SJohn Marino
11716a45ae5f8SJohn Marino static void
check_status_catch_exception(bpstat bs)11717a45ae5f8SJohn Marino check_status_catch_exception (bpstat bs)
11718a45ae5f8SJohn Marino {
11719a45ae5f8SJohn Marino check_status_exception (ex_catch_exception, bs);
11720a45ae5f8SJohn Marino }
11721a45ae5f8SJohn Marino
11722a45ae5f8SJohn Marino static enum print_stop_action
print_it_catch_exception(bpstat bs)11723a45ae5f8SJohn Marino print_it_catch_exception (bpstat bs)
11724a45ae5f8SJohn Marino {
11725a45ae5f8SJohn Marino return print_it_exception (ex_catch_exception, bs);
117265796c8dcSSimon Schubert }
117275796c8dcSSimon Schubert
117285796c8dcSSimon Schubert static void
print_one_catch_exception(struct breakpoint * b,struct bp_location ** last_loc)117295796c8dcSSimon Schubert print_one_catch_exception (struct breakpoint *b, struct bp_location **last_loc)
117305796c8dcSSimon Schubert {
117315796c8dcSSimon Schubert print_one_exception (ex_catch_exception, b, last_loc);
117325796c8dcSSimon Schubert }
117335796c8dcSSimon Schubert
117345796c8dcSSimon Schubert static void
print_mention_catch_exception(struct breakpoint * b)117355796c8dcSSimon Schubert print_mention_catch_exception (struct breakpoint *b)
117365796c8dcSSimon Schubert {
117375796c8dcSSimon Schubert print_mention_exception (ex_catch_exception, b);
117385796c8dcSSimon Schubert }
117395796c8dcSSimon Schubert
11740cf7f2e2dSJohn Marino static void
print_recreate_catch_exception(struct breakpoint * b,struct ui_file * fp)11741cf7f2e2dSJohn Marino print_recreate_catch_exception (struct breakpoint *b, struct ui_file *fp)
11742cf7f2e2dSJohn Marino {
11743cf7f2e2dSJohn Marino print_recreate_exception (ex_catch_exception, b, fp);
11744cf7f2e2dSJohn Marino }
11745cf7f2e2dSJohn Marino
11746a45ae5f8SJohn Marino static struct breakpoint_ops catch_exception_breakpoint_ops;
117475796c8dcSSimon Schubert
117485796c8dcSSimon Schubert /* Virtual table for "catch exception unhandled" breakpoints. */
117495796c8dcSSimon Schubert
11750a45ae5f8SJohn Marino static void
dtor_catch_exception_unhandled(struct breakpoint * b)11751a45ae5f8SJohn Marino dtor_catch_exception_unhandled (struct breakpoint *b)
117525796c8dcSSimon Schubert {
11753a45ae5f8SJohn Marino dtor_exception (ex_catch_exception_unhandled, b);
11754a45ae5f8SJohn Marino }
11755a45ae5f8SJohn Marino
11756a45ae5f8SJohn Marino static struct bp_location *
allocate_location_catch_exception_unhandled(struct breakpoint * self)11757a45ae5f8SJohn Marino allocate_location_catch_exception_unhandled (struct breakpoint *self)
11758a45ae5f8SJohn Marino {
11759a45ae5f8SJohn Marino return allocate_location_exception (ex_catch_exception_unhandled, self);
11760a45ae5f8SJohn Marino }
11761a45ae5f8SJohn Marino
11762a45ae5f8SJohn Marino static void
re_set_catch_exception_unhandled(struct breakpoint * b)11763a45ae5f8SJohn Marino re_set_catch_exception_unhandled (struct breakpoint *b)
11764a45ae5f8SJohn Marino {
11765a45ae5f8SJohn Marino re_set_exception (ex_catch_exception_unhandled, b);
11766a45ae5f8SJohn Marino }
11767a45ae5f8SJohn Marino
11768a45ae5f8SJohn Marino static void
check_status_catch_exception_unhandled(bpstat bs)11769a45ae5f8SJohn Marino check_status_catch_exception_unhandled (bpstat bs)
11770a45ae5f8SJohn Marino {
11771a45ae5f8SJohn Marino check_status_exception (ex_catch_exception_unhandled, bs);
11772a45ae5f8SJohn Marino }
11773a45ae5f8SJohn Marino
11774a45ae5f8SJohn Marino static enum print_stop_action
print_it_catch_exception_unhandled(bpstat bs)11775a45ae5f8SJohn Marino print_it_catch_exception_unhandled (bpstat bs)
11776a45ae5f8SJohn Marino {
11777a45ae5f8SJohn Marino return print_it_exception (ex_catch_exception_unhandled, bs);
117785796c8dcSSimon Schubert }
117795796c8dcSSimon Schubert
117805796c8dcSSimon Schubert static void
print_one_catch_exception_unhandled(struct breakpoint * b,struct bp_location ** last_loc)117815796c8dcSSimon Schubert print_one_catch_exception_unhandled (struct breakpoint *b,
117825796c8dcSSimon Schubert struct bp_location **last_loc)
117835796c8dcSSimon Schubert {
117845796c8dcSSimon Schubert print_one_exception (ex_catch_exception_unhandled, b, last_loc);
117855796c8dcSSimon Schubert }
117865796c8dcSSimon Schubert
117875796c8dcSSimon Schubert static void
print_mention_catch_exception_unhandled(struct breakpoint * b)117885796c8dcSSimon Schubert print_mention_catch_exception_unhandled (struct breakpoint *b)
117895796c8dcSSimon Schubert {
117905796c8dcSSimon Schubert print_mention_exception (ex_catch_exception_unhandled, b);
117915796c8dcSSimon Schubert }
117925796c8dcSSimon Schubert
11793cf7f2e2dSJohn Marino static void
print_recreate_catch_exception_unhandled(struct breakpoint * b,struct ui_file * fp)11794cf7f2e2dSJohn Marino print_recreate_catch_exception_unhandled (struct breakpoint *b,
11795cf7f2e2dSJohn Marino struct ui_file *fp)
11796cf7f2e2dSJohn Marino {
11797cf7f2e2dSJohn Marino print_recreate_exception (ex_catch_exception_unhandled, b, fp);
11798cf7f2e2dSJohn Marino }
11799cf7f2e2dSJohn Marino
11800a45ae5f8SJohn Marino static struct breakpoint_ops catch_exception_unhandled_breakpoint_ops;
118015796c8dcSSimon Schubert
118025796c8dcSSimon Schubert /* Virtual table for "catch assert" breakpoints. */
118035796c8dcSSimon Schubert
11804a45ae5f8SJohn Marino static void
dtor_catch_assert(struct breakpoint * b)11805a45ae5f8SJohn Marino dtor_catch_assert (struct breakpoint *b)
118065796c8dcSSimon Schubert {
11807a45ae5f8SJohn Marino dtor_exception (ex_catch_assert, b);
11808a45ae5f8SJohn Marino }
11809a45ae5f8SJohn Marino
11810a45ae5f8SJohn Marino static struct bp_location *
allocate_location_catch_assert(struct breakpoint * self)11811a45ae5f8SJohn Marino allocate_location_catch_assert (struct breakpoint *self)
11812a45ae5f8SJohn Marino {
11813a45ae5f8SJohn Marino return allocate_location_exception (ex_catch_assert, self);
11814a45ae5f8SJohn Marino }
11815a45ae5f8SJohn Marino
11816a45ae5f8SJohn Marino static void
re_set_catch_assert(struct breakpoint * b)11817a45ae5f8SJohn Marino re_set_catch_assert (struct breakpoint *b)
11818a45ae5f8SJohn Marino {
11819*ef5ccd6cSJohn Marino re_set_exception (ex_catch_assert, b);
11820a45ae5f8SJohn Marino }
11821a45ae5f8SJohn Marino
11822a45ae5f8SJohn Marino static void
check_status_catch_assert(bpstat bs)11823a45ae5f8SJohn Marino check_status_catch_assert (bpstat bs)
11824a45ae5f8SJohn Marino {
11825a45ae5f8SJohn Marino check_status_exception (ex_catch_assert, bs);
11826a45ae5f8SJohn Marino }
11827a45ae5f8SJohn Marino
11828a45ae5f8SJohn Marino static enum print_stop_action
print_it_catch_assert(bpstat bs)11829a45ae5f8SJohn Marino print_it_catch_assert (bpstat bs)
11830a45ae5f8SJohn Marino {
11831a45ae5f8SJohn Marino return print_it_exception (ex_catch_assert, bs);
118325796c8dcSSimon Schubert }
118335796c8dcSSimon Schubert
118345796c8dcSSimon Schubert static void
print_one_catch_assert(struct breakpoint * b,struct bp_location ** last_loc)118355796c8dcSSimon Schubert print_one_catch_assert (struct breakpoint *b, struct bp_location **last_loc)
118365796c8dcSSimon Schubert {
118375796c8dcSSimon Schubert print_one_exception (ex_catch_assert, b, last_loc);
118385796c8dcSSimon Schubert }
118395796c8dcSSimon Schubert
118405796c8dcSSimon Schubert static void
print_mention_catch_assert(struct breakpoint * b)118415796c8dcSSimon Schubert print_mention_catch_assert (struct breakpoint *b)
118425796c8dcSSimon Schubert {
118435796c8dcSSimon Schubert print_mention_exception (ex_catch_assert, b);
118445796c8dcSSimon Schubert }
118455796c8dcSSimon Schubert
11846cf7f2e2dSJohn Marino static void
print_recreate_catch_assert(struct breakpoint * b,struct ui_file * fp)11847cf7f2e2dSJohn Marino print_recreate_catch_assert (struct breakpoint *b, struct ui_file *fp)
11848cf7f2e2dSJohn Marino {
11849cf7f2e2dSJohn Marino print_recreate_exception (ex_catch_assert, b, fp);
11850cf7f2e2dSJohn Marino }
11851cf7f2e2dSJohn Marino
11852a45ae5f8SJohn Marino static struct breakpoint_ops catch_assert_breakpoint_ops;
118535796c8dcSSimon Schubert
118545796c8dcSSimon Schubert /* Return a newly allocated copy of the first space-separated token
118555796c8dcSSimon Schubert in ARGSP, and then adjust ARGSP to point immediately after that
118565796c8dcSSimon Schubert token.
118575796c8dcSSimon Schubert
118585796c8dcSSimon Schubert Return NULL if ARGPS does not contain any more tokens. */
118595796c8dcSSimon Schubert
118605796c8dcSSimon Schubert static char *
ada_get_next_arg(char ** argsp)118615796c8dcSSimon Schubert ada_get_next_arg (char **argsp)
118625796c8dcSSimon Schubert {
118635796c8dcSSimon Schubert char *args = *argsp;
118645796c8dcSSimon Schubert char *end;
118655796c8dcSSimon Schubert char *result;
118665796c8dcSSimon Schubert
11867*ef5ccd6cSJohn Marino args = skip_spaces (args);
118685796c8dcSSimon Schubert if (args[0] == '\0')
118695796c8dcSSimon Schubert return NULL; /* No more arguments. */
118705796c8dcSSimon Schubert
118715796c8dcSSimon Schubert /* Find the end of the current argument. */
118725796c8dcSSimon Schubert
11873*ef5ccd6cSJohn Marino end = skip_to_space (args);
118745796c8dcSSimon Schubert
118755796c8dcSSimon Schubert /* Adjust ARGSP to point to the start of the next argument. */
118765796c8dcSSimon Schubert
118775796c8dcSSimon Schubert *argsp = end;
118785796c8dcSSimon Schubert
118795796c8dcSSimon Schubert /* Make a copy of the current argument and return it. */
118805796c8dcSSimon Schubert
118815796c8dcSSimon Schubert result = xmalloc (end - args + 1);
118825796c8dcSSimon Schubert strncpy (result, args, end - args);
118835796c8dcSSimon Schubert result[end - args] = '\0';
118845796c8dcSSimon Schubert
118855796c8dcSSimon Schubert return result;
118865796c8dcSSimon Schubert }
118875796c8dcSSimon Schubert
118885796c8dcSSimon Schubert /* Split the arguments specified in a "catch exception" command.
118895796c8dcSSimon Schubert Set EX to the appropriate catchpoint type.
11890a45ae5f8SJohn Marino Set EXCEP_STRING to the name of the specific exception if
11891*ef5ccd6cSJohn Marino specified by the user.
11892*ef5ccd6cSJohn Marino If a condition is found at the end of the arguments, the condition
11893*ef5ccd6cSJohn Marino expression is stored in COND_STRING (memory must be deallocated
11894*ef5ccd6cSJohn Marino after use). Otherwise COND_STRING is set to NULL. */
118955796c8dcSSimon Schubert
118965796c8dcSSimon Schubert static void
catch_ada_exception_command_split(char * args,enum exception_catchpoint_kind * ex,char ** excep_string,char ** cond_string)118975796c8dcSSimon Schubert catch_ada_exception_command_split (char *args,
118985796c8dcSSimon Schubert enum exception_catchpoint_kind *ex,
11899*ef5ccd6cSJohn Marino char **excep_string,
11900*ef5ccd6cSJohn Marino char **cond_string)
119015796c8dcSSimon Schubert {
119025796c8dcSSimon Schubert struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
119035796c8dcSSimon Schubert char *exception_name;
11904*ef5ccd6cSJohn Marino char *cond = NULL;
119055796c8dcSSimon Schubert
119065796c8dcSSimon Schubert exception_name = ada_get_next_arg (&args);
11907*ef5ccd6cSJohn Marino if (exception_name != NULL && strcmp (exception_name, "if") == 0)
11908*ef5ccd6cSJohn Marino {
11909*ef5ccd6cSJohn Marino /* This is not an exception name; this is the start of a condition
11910*ef5ccd6cSJohn Marino expression for a catchpoint on all exceptions. So, "un-get"
11911*ef5ccd6cSJohn Marino this token, and set exception_name to NULL. */
11912*ef5ccd6cSJohn Marino xfree (exception_name);
11913*ef5ccd6cSJohn Marino exception_name = NULL;
11914*ef5ccd6cSJohn Marino args -= 2;
11915*ef5ccd6cSJohn Marino }
119165796c8dcSSimon Schubert make_cleanup (xfree, exception_name);
119175796c8dcSSimon Schubert
11918*ef5ccd6cSJohn Marino /* Check to see if we have a condition. */
11919*ef5ccd6cSJohn Marino
11920*ef5ccd6cSJohn Marino args = skip_spaces (args);
11921*ef5ccd6cSJohn Marino if (strncmp (args, "if", 2) == 0
11922*ef5ccd6cSJohn Marino && (isspace (args[2]) || args[2] == '\0'))
11923*ef5ccd6cSJohn Marino {
11924*ef5ccd6cSJohn Marino args += 2;
11925*ef5ccd6cSJohn Marino args = skip_spaces (args);
11926*ef5ccd6cSJohn Marino
11927*ef5ccd6cSJohn Marino if (args[0] == '\0')
11928*ef5ccd6cSJohn Marino error (_("Condition missing after `if' keyword"));
11929*ef5ccd6cSJohn Marino cond = xstrdup (args);
11930*ef5ccd6cSJohn Marino make_cleanup (xfree, cond);
11931*ef5ccd6cSJohn Marino
11932*ef5ccd6cSJohn Marino args += strlen (args);
11933*ef5ccd6cSJohn Marino }
11934*ef5ccd6cSJohn Marino
119355796c8dcSSimon Schubert /* Check that we do not have any more arguments. Anything else
119365796c8dcSSimon Schubert is unexpected. */
119375796c8dcSSimon Schubert
119385796c8dcSSimon Schubert if (args[0] != '\0')
119395796c8dcSSimon Schubert error (_("Junk at end of expression"));
119405796c8dcSSimon Schubert
119415796c8dcSSimon Schubert discard_cleanups (old_chain);
119425796c8dcSSimon Schubert
119435796c8dcSSimon Schubert if (exception_name == NULL)
119445796c8dcSSimon Schubert {
119455796c8dcSSimon Schubert /* Catch all exceptions. */
119465796c8dcSSimon Schubert *ex = ex_catch_exception;
11947a45ae5f8SJohn Marino *excep_string = NULL;
119485796c8dcSSimon Schubert }
119495796c8dcSSimon Schubert else if (strcmp (exception_name, "unhandled") == 0)
119505796c8dcSSimon Schubert {
119515796c8dcSSimon Schubert /* Catch unhandled exceptions. */
119525796c8dcSSimon Schubert *ex = ex_catch_exception_unhandled;
11953a45ae5f8SJohn Marino *excep_string = NULL;
119545796c8dcSSimon Schubert }
119555796c8dcSSimon Schubert else
119565796c8dcSSimon Schubert {
119575796c8dcSSimon Schubert /* Catch a specific exception. */
119585796c8dcSSimon Schubert *ex = ex_catch_exception;
11959a45ae5f8SJohn Marino *excep_string = exception_name;
119605796c8dcSSimon Schubert }
11961*ef5ccd6cSJohn Marino *cond_string = cond;
119625796c8dcSSimon Schubert }
119635796c8dcSSimon Schubert
119645796c8dcSSimon Schubert /* Return the name of the symbol on which we should break in order to
119655796c8dcSSimon Schubert implement a catchpoint of the EX kind. */
119665796c8dcSSimon Schubert
119675796c8dcSSimon Schubert static const char *
ada_exception_sym_name(enum exception_catchpoint_kind ex)119685796c8dcSSimon Schubert ada_exception_sym_name (enum exception_catchpoint_kind ex)
119695796c8dcSSimon Schubert {
11970a45ae5f8SJohn Marino struct ada_inferior_data *data = get_ada_inferior_data (current_inferior ());
11971a45ae5f8SJohn Marino
11972a45ae5f8SJohn Marino gdb_assert (data->exception_info != NULL);
119735796c8dcSSimon Schubert
119745796c8dcSSimon Schubert switch (ex)
119755796c8dcSSimon Schubert {
119765796c8dcSSimon Schubert case ex_catch_exception:
11977a45ae5f8SJohn Marino return (data->exception_info->catch_exception_sym);
119785796c8dcSSimon Schubert break;
119795796c8dcSSimon Schubert case ex_catch_exception_unhandled:
11980a45ae5f8SJohn Marino return (data->exception_info->catch_exception_unhandled_sym);
119815796c8dcSSimon Schubert break;
119825796c8dcSSimon Schubert case ex_catch_assert:
11983a45ae5f8SJohn Marino return (data->exception_info->catch_assert_sym);
119845796c8dcSSimon Schubert break;
119855796c8dcSSimon Schubert default:
119865796c8dcSSimon Schubert internal_error (__FILE__, __LINE__,
119875796c8dcSSimon Schubert _("unexpected catchpoint kind (%d)"), ex);
119885796c8dcSSimon Schubert }
119895796c8dcSSimon Schubert }
119905796c8dcSSimon Schubert
119915796c8dcSSimon Schubert /* Return the breakpoint ops "virtual table" used for catchpoints
119925796c8dcSSimon Schubert of the EX kind. */
119935796c8dcSSimon Schubert
11994a45ae5f8SJohn Marino static const struct breakpoint_ops *
ada_exception_breakpoint_ops(enum exception_catchpoint_kind ex)119955796c8dcSSimon Schubert ada_exception_breakpoint_ops (enum exception_catchpoint_kind ex)
119965796c8dcSSimon Schubert {
119975796c8dcSSimon Schubert switch (ex)
119985796c8dcSSimon Schubert {
119995796c8dcSSimon Schubert case ex_catch_exception:
120005796c8dcSSimon Schubert return (&catch_exception_breakpoint_ops);
120015796c8dcSSimon Schubert break;
120025796c8dcSSimon Schubert case ex_catch_exception_unhandled:
120035796c8dcSSimon Schubert return (&catch_exception_unhandled_breakpoint_ops);
120045796c8dcSSimon Schubert break;
120055796c8dcSSimon Schubert case ex_catch_assert:
120065796c8dcSSimon Schubert return (&catch_assert_breakpoint_ops);
120075796c8dcSSimon Schubert break;
120085796c8dcSSimon Schubert default:
120095796c8dcSSimon Schubert internal_error (__FILE__, __LINE__,
120105796c8dcSSimon Schubert _("unexpected catchpoint kind (%d)"), ex);
120115796c8dcSSimon Schubert }
120125796c8dcSSimon Schubert }
120135796c8dcSSimon Schubert
120145796c8dcSSimon Schubert /* Return the condition that will be used to match the current exception
120155796c8dcSSimon Schubert being raised with the exception that the user wants to catch. This
120165796c8dcSSimon Schubert assumes that this condition is used when the inferior just triggered
120175796c8dcSSimon Schubert an exception catchpoint.
120185796c8dcSSimon Schubert
120195796c8dcSSimon Schubert The string returned is a newly allocated string that needs to be
120205796c8dcSSimon Schubert deallocated later. */
120215796c8dcSSimon Schubert
120225796c8dcSSimon Schubert static char *
ada_exception_catchpoint_cond_string(const char * excep_string)12023a45ae5f8SJohn Marino ada_exception_catchpoint_cond_string (const char *excep_string)
120245796c8dcSSimon Schubert {
120255796c8dcSSimon Schubert int i;
120265796c8dcSSimon Schubert
120275796c8dcSSimon Schubert /* The standard exceptions are a special case. They are defined in
120285796c8dcSSimon Schubert runtime units that have been compiled without debugging info; if
12029a45ae5f8SJohn Marino EXCEP_STRING is the not-fully-qualified name of a standard
120305796c8dcSSimon Schubert exception (e.g. "constraint_error") then, during the evaluation
120315796c8dcSSimon Schubert of the condition expression, the symbol lookup on this name would
120325796c8dcSSimon Schubert *not* return this standard exception. The catchpoint condition
120335796c8dcSSimon Schubert may then be set only on user-defined exceptions which have the
120345796c8dcSSimon Schubert same not-fully-qualified name (e.g. my_package.constraint_error).
120355796c8dcSSimon Schubert
120365796c8dcSSimon Schubert To avoid this unexcepted behavior, these standard exceptions are
120375796c8dcSSimon Schubert systematically prefixed by "standard". This means that "catch
120385796c8dcSSimon Schubert exception constraint_error" is rewritten into "catch exception
120395796c8dcSSimon Schubert standard.constraint_error".
120405796c8dcSSimon Schubert
120415796c8dcSSimon Schubert If an exception named contraint_error is defined in another package of
120425796c8dcSSimon Schubert the inferior program, then the only way to specify this exception as a
120435796c8dcSSimon Schubert breakpoint condition is to use its fully-qualified named:
120445796c8dcSSimon Schubert e.g. my_package.constraint_error. */
120455796c8dcSSimon Schubert
120465796c8dcSSimon Schubert for (i = 0; i < sizeof (standard_exc) / sizeof (char *); i++)
120475796c8dcSSimon Schubert {
12048a45ae5f8SJohn Marino if (strcmp (standard_exc [i], excep_string) == 0)
120495796c8dcSSimon Schubert {
120505796c8dcSSimon Schubert return xstrprintf ("long_integer (e) = long_integer (&standard.%s)",
12051a45ae5f8SJohn Marino excep_string);
120525796c8dcSSimon Schubert }
120535796c8dcSSimon Schubert }
12054a45ae5f8SJohn Marino return xstrprintf ("long_integer (e) = long_integer (&%s)", excep_string);
120555796c8dcSSimon Schubert }
120565796c8dcSSimon Schubert
120575796c8dcSSimon Schubert /* Return the symtab_and_line that should be used to insert an exception
120585796c8dcSSimon Schubert catchpoint of the TYPE kind.
120595796c8dcSSimon Schubert
12060a45ae5f8SJohn Marino EXCEP_STRING should contain the name of a specific exception that
12061a45ae5f8SJohn Marino the catchpoint should catch, or NULL otherwise.
120625796c8dcSSimon Schubert
12063a45ae5f8SJohn Marino ADDR_STRING returns the name of the function where the real
12064a45ae5f8SJohn Marino breakpoint that implements the catchpoints is set, depending on the
12065a45ae5f8SJohn Marino type of catchpoint we need to create. */
120665796c8dcSSimon Schubert
120675796c8dcSSimon Schubert static struct symtab_and_line
ada_exception_sal(enum exception_catchpoint_kind ex,char * excep_string,char ** addr_string,const struct breakpoint_ops ** ops)12068a45ae5f8SJohn Marino ada_exception_sal (enum exception_catchpoint_kind ex, char *excep_string,
12069a45ae5f8SJohn Marino char **addr_string, const struct breakpoint_ops **ops)
120705796c8dcSSimon Schubert {
120715796c8dcSSimon Schubert const char *sym_name;
120725796c8dcSSimon Schubert struct symbol *sym;
120735796c8dcSSimon Schubert
120745796c8dcSSimon Schubert /* First, find out which exception support info to use. */
120755796c8dcSSimon Schubert ada_exception_support_info_sniffer ();
120765796c8dcSSimon Schubert
120775796c8dcSSimon Schubert /* Then lookup the function on which we will break in order to catch
120785796c8dcSSimon Schubert the Ada exceptions requested by the user. */
120795796c8dcSSimon Schubert sym_name = ada_exception_sym_name (ex);
120805796c8dcSSimon Schubert sym = standard_lookup (sym_name, NULL, VAR_DOMAIN);
120815796c8dcSSimon Schubert
12082a45ae5f8SJohn Marino /* We can assume that SYM is not NULL at this stage. If the symbol
12083a45ae5f8SJohn Marino did not exist, ada_exception_support_info_sniffer would have
12084a45ae5f8SJohn Marino raised an exception.
120855796c8dcSSimon Schubert
12086a45ae5f8SJohn Marino Also, ada_exception_support_info_sniffer should have already
12087a45ae5f8SJohn Marino verified that SYM is a function symbol. */
12088a45ae5f8SJohn Marino gdb_assert (sym != NULL);
12089a45ae5f8SJohn Marino gdb_assert (SYMBOL_CLASS (sym) == LOC_BLOCK);
120905796c8dcSSimon Schubert
120915796c8dcSSimon Schubert /* Set ADDR_STRING. */
120925796c8dcSSimon Schubert *addr_string = xstrdup (sym_name);
120935796c8dcSSimon Schubert
120945796c8dcSSimon Schubert /* Set OPS. */
120955796c8dcSSimon Schubert *ops = ada_exception_breakpoint_ops (ex);
120965796c8dcSSimon Schubert
12097a45ae5f8SJohn Marino return find_function_start_sal (sym, 1);
120985796c8dcSSimon Schubert }
120995796c8dcSSimon Schubert
121005796c8dcSSimon Schubert /* Parse the arguments (ARGS) of the "catch exception" command.
121015796c8dcSSimon Schubert
121025796c8dcSSimon Schubert If the user asked the catchpoint to catch only a specific
121035796c8dcSSimon Schubert exception, then save the exception name in ADDR_STRING.
121045796c8dcSSimon Schubert
12105*ef5ccd6cSJohn Marino If the user provided a condition, then set COND_STRING to
12106*ef5ccd6cSJohn Marino that condition expression (the memory must be deallocated
12107*ef5ccd6cSJohn Marino after use). Otherwise, set COND_STRING to NULL.
12108*ef5ccd6cSJohn Marino
121095796c8dcSSimon Schubert See ada_exception_sal for a description of all the remaining
121105796c8dcSSimon Schubert function arguments of this function. */
121115796c8dcSSimon Schubert
12112a45ae5f8SJohn Marino static struct symtab_and_line
ada_decode_exception_location(char * args,char ** addr_string,char ** excep_string,char ** cond_string,const struct breakpoint_ops ** ops)121135796c8dcSSimon Schubert ada_decode_exception_location (char *args, char **addr_string,
12114a45ae5f8SJohn Marino char **excep_string,
12115*ef5ccd6cSJohn Marino char **cond_string,
12116a45ae5f8SJohn Marino const struct breakpoint_ops **ops)
121175796c8dcSSimon Schubert {
121185796c8dcSSimon Schubert enum exception_catchpoint_kind ex;
121195796c8dcSSimon Schubert
12120*ef5ccd6cSJohn Marino catch_ada_exception_command_split (args, &ex, excep_string, cond_string);
12121a45ae5f8SJohn Marino return ada_exception_sal (ex, *excep_string, addr_string, ops);
121225796c8dcSSimon Schubert }
121235796c8dcSSimon Schubert
12124a45ae5f8SJohn Marino /* Create an Ada exception catchpoint. */
12125a45ae5f8SJohn Marino
12126a45ae5f8SJohn Marino static void
create_ada_exception_catchpoint(struct gdbarch * gdbarch,struct symtab_and_line sal,char * addr_string,char * excep_string,char * cond_string,const struct breakpoint_ops * ops,int tempflag,int from_tty)12127a45ae5f8SJohn Marino create_ada_exception_catchpoint (struct gdbarch *gdbarch,
12128a45ae5f8SJohn Marino struct symtab_and_line sal,
12129a45ae5f8SJohn Marino char *addr_string,
12130a45ae5f8SJohn Marino char *excep_string,
12131*ef5ccd6cSJohn Marino char *cond_string,
12132a45ae5f8SJohn Marino const struct breakpoint_ops *ops,
12133a45ae5f8SJohn Marino int tempflag,
12134a45ae5f8SJohn Marino int from_tty)
12135a45ae5f8SJohn Marino {
12136a45ae5f8SJohn Marino struct ada_catchpoint *c;
12137a45ae5f8SJohn Marino
12138a45ae5f8SJohn Marino c = XNEW (struct ada_catchpoint);
12139a45ae5f8SJohn Marino init_ada_exception_breakpoint (&c->base, gdbarch, sal, addr_string,
12140a45ae5f8SJohn Marino ops, tempflag, from_tty);
12141a45ae5f8SJohn Marino c->excep_string = excep_string;
12142a45ae5f8SJohn Marino create_excep_cond_exprs (c);
12143*ef5ccd6cSJohn Marino if (cond_string != NULL)
12144*ef5ccd6cSJohn Marino set_breakpoint_condition (&c->base, cond_string, from_tty);
12145a45ae5f8SJohn Marino install_breakpoint (0, &c->base, 1);
12146a45ae5f8SJohn Marino }
12147a45ae5f8SJohn Marino
12148a45ae5f8SJohn Marino /* Implement the "catch exception" command. */
12149a45ae5f8SJohn Marino
12150a45ae5f8SJohn Marino static void
catch_ada_exception_command(char * arg,int from_tty,struct cmd_list_element * command)12151a45ae5f8SJohn Marino catch_ada_exception_command (char *arg, int from_tty,
12152a45ae5f8SJohn Marino struct cmd_list_element *command)
12153a45ae5f8SJohn Marino {
12154a45ae5f8SJohn Marino struct gdbarch *gdbarch = get_current_arch ();
12155a45ae5f8SJohn Marino int tempflag;
12156a45ae5f8SJohn Marino struct symtab_and_line sal;
12157a45ae5f8SJohn Marino char *addr_string = NULL;
12158a45ae5f8SJohn Marino char *excep_string = NULL;
12159*ef5ccd6cSJohn Marino char *cond_string = NULL;
12160a45ae5f8SJohn Marino const struct breakpoint_ops *ops = NULL;
12161a45ae5f8SJohn Marino
12162a45ae5f8SJohn Marino tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
12163a45ae5f8SJohn Marino
12164a45ae5f8SJohn Marino if (!arg)
12165a45ae5f8SJohn Marino arg = "";
12166*ef5ccd6cSJohn Marino sal = ada_decode_exception_location (arg, &addr_string, &excep_string,
12167*ef5ccd6cSJohn Marino &cond_string, &ops);
12168a45ae5f8SJohn Marino create_ada_exception_catchpoint (gdbarch, sal, addr_string,
12169*ef5ccd6cSJohn Marino excep_string, cond_string, ops,
12170*ef5ccd6cSJohn Marino tempflag, from_tty);
12171a45ae5f8SJohn Marino }
12172a45ae5f8SJohn Marino
12173*ef5ccd6cSJohn Marino /* Assuming that ARGS contains the arguments of a "catch assert"
12174*ef5ccd6cSJohn Marino command, parse those arguments and return a symtab_and_line object
12175*ef5ccd6cSJohn Marino for a failed assertion catchpoint.
12176*ef5ccd6cSJohn Marino
12177*ef5ccd6cSJohn Marino Set ADDR_STRING to the name of the function where the real
12178*ef5ccd6cSJohn Marino breakpoint that implements the catchpoint is set.
12179*ef5ccd6cSJohn Marino
12180*ef5ccd6cSJohn Marino If ARGS contains a condition, set COND_STRING to that condition
12181*ef5ccd6cSJohn Marino (the memory needs to be deallocated after use). Otherwise, set
12182*ef5ccd6cSJohn Marino COND_STRING to NULL. */
12183*ef5ccd6cSJohn Marino
12184a45ae5f8SJohn Marino static struct symtab_and_line
ada_decode_assert_location(char * args,char ** addr_string,char ** cond_string,const struct breakpoint_ops ** ops)121855796c8dcSSimon Schubert ada_decode_assert_location (char *args, char **addr_string,
12186*ef5ccd6cSJohn Marino char **cond_string,
12187a45ae5f8SJohn Marino const struct breakpoint_ops **ops)
121885796c8dcSSimon Schubert {
12189*ef5ccd6cSJohn Marino args = skip_spaces (args);
121905796c8dcSSimon Schubert
12191*ef5ccd6cSJohn Marino /* Check whether a condition was provided. */
12192*ef5ccd6cSJohn Marino if (strncmp (args, "if", 2) == 0
12193*ef5ccd6cSJohn Marino && (isspace (args[2]) || args[2] == '\0'))
121945796c8dcSSimon Schubert {
12195*ef5ccd6cSJohn Marino args += 2;
12196*ef5ccd6cSJohn Marino args = skip_spaces (args);
12197*ef5ccd6cSJohn Marino if (args[0] == '\0')
12198*ef5ccd6cSJohn Marino error (_("condition missing after `if' keyword"));
12199*ef5ccd6cSJohn Marino *cond_string = xstrdup (args);
122005796c8dcSSimon Schubert }
122015796c8dcSSimon Schubert
12202*ef5ccd6cSJohn Marino /* Otherwise, there should be no other argument at the end of
12203*ef5ccd6cSJohn Marino the command. */
12204*ef5ccd6cSJohn Marino else if (args[0] != '\0')
12205*ef5ccd6cSJohn Marino error (_("Junk at end of arguments."));
12206*ef5ccd6cSJohn Marino
12207a45ae5f8SJohn Marino return ada_exception_sal (ex_catch_assert, NULL, addr_string, ops);
122085796c8dcSSimon Schubert }
122095796c8dcSSimon Schubert
12210a45ae5f8SJohn Marino /* Implement the "catch assert" command. */
12211a45ae5f8SJohn Marino
12212a45ae5f8SJohn Marino static void
catch_assert_command(char * arg,int from_tty,struct cmd_list_element * command)12213a45ae5f8SJohn Marino catch_assert_command (char *arg, int from_tty,
12214a45ae5f8SJohn Marino struct cmd_list_element *command)
12215a45ae5f8SJohn Marino {
12216a45ae5f8SJohn Marino struct gdbarch *gdbarch = get_current_arch ();
12217a45ae5f8SJohn Marino int tempflag;
12218a45ae5f8SJohn Marino struct symtab_and_line sal;
12219a45ae5f8SJohn Marino char *addr_string = NULL;
12220*ef5ccd6cSJohn Marino char *cond_string = NULL;
12221a45ae5f8SJohn Marino const struct breakpoint_ops *ops = NULL;
12222a45ae5f8SJohn Marino
12223a45ae5f8SJohn Marino tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
12224a45ae5f8SJohn Marino
12225a45ae5f8SJohn Marino if (!arg)
12226a45ae5f8SJohn Marino arg = "";
12227*ef5ccd6cSJohn Marino sal = ada_decode_assert_location (arg, &addr_string, &cond_string, &ops);
12228a45ae5f8SJohn Marino create_ada_exception_catchpoint (gdbarch, sal, addr_string,
12229*ef5ccd6cSJohn Marino NULL, cond_string, ops, tempflag,
12230*ef5ccd6cSJohn Marino from_tty);
12231a45ae5f8SJohn Marino }
122325796c8dcSSimon Schubert /* Operators */
122335796c8dcSSimon Schubert /* Information about operators given special treatment in functions
122345796c8dcSSimon Schubert below. */
122355796c8dcSSimon Schubert /* Format: OP_DEFN (<operator>, <operator length>, <# args>, <binop>). */
122365796c8dcSSimon Schubert
122375796c8dcSSimon Schubert #define ADA_OPERATORS \
122385796c8dcSSimon Schubert OP_DEFN (OP_VAR_VALUE, 4, 0, 0) \
122395796c8dcSSimon Schubert OP_DEFN (BINOP_IN_BOUNDS, 3, 2, 0) \
122405796c8dcSSimon Schubert OP_DEFN (TERNOP_IN_RANGE, 1, 3, 0) \
122415796c8dcSSimon Schubert OP_DEFN (OP_ATR_FIRST, 1, 2, 0) \
122425796c8dcSSimon Schubert OP_DEFN (OP_ATR_LAST, 1, 2, 0) \
122435796c8dcSSimon Schubert OP_DEFN (OP_ATR_LENGTH, 1, 2, 0) \
122445796c8dcSSimon Schubert OP_DEFN (OP_ATR_IMAGE, 1, 2, 0) \
122455796c8dcSSimon Schubert OP_DEFN (OP_ATR_MAX, 1, 3, 0) \
122465796c8dcSSimon Schubert OP_DEFN (OP_ATR_MIN, 1, 3, 0) \
122475796c8dcSSimon Schubert OP_DEFN (OP_ATR_MODULUS, 1, 1, 0) \
122485796c8dcSSimon Schubert OP_DEFN (OP_ATR_POS, 1, 2, 0) \
122495796c8dcSSimon Schubert OP_DEFN (OP_ATR_SIZE, 1, 1, 0) \
122505796c8dcSSimon Schubert OP_DEFN (OP_ATR_TAG, 1, 1, 0) \
122515796c8dcSSimon Schubert OP_DEFN (OP_ATR_VAL, 1, 2, 0) \
122525796c8dcSSimon Schubert OP_DEFN (UNOP_QUAL, 3, 1, 0) \
122535796c8dcSSimon Schubert OP_DEFN (UNOP_IN_RANGE, 3, 1, 0) \
122545796c8dcSSimon Schubert OP_DEFN (OP_OTHERS, 1, 1, 0) \
122555796c8dcSSimon Schubert OP_DEFN (OP_POSITIONAL, 3, 1, 0) \
122565796c8dcSSimon Schubert OP_DEFN (OP_DISCRETE_RANGE, 1, 2, 0)
122575796c8dcSSimon Schubert
122585796c8dcSSimon Schubert static void
ada_operator_length(const struct expression * exp,int pc,int * oplenp,int * argsp)12259cf7f2e2dSJohn Marino ada_operator_length (const struct expression *exp, int pc, int *oplenp,
12260cf7f2e2dSJohn Marino int *argsp)
122615796c8dcSSimon Schubert {
122625796c8dcSSimon Schubert switch (exp->elts[pc - 1].opcode)
122635796c8dcSSimon Schubert {
122645796c8dcSSimon Schubert default:
122655796c8dcSSimon Schubert operator_length_standard (exp, pc, oplenp, argsp);
122665796c8dcSSimon Schubert break;
122675796c8dcSSimon Schubert
122685796c8dcSSimon Schubert #define OP_DEFN(op, len, args, binop) \
122695796c8dcSSimon Schubert case op: *oplenp = len; *argsp = args; break;
122705796c8dcSSimon Schubert ADA_OPERATORS;
122715796c8dcSSimon Schubert #undef OP_DEFN
122725796c8dcSSimon Schubert
122735796c8dcSSimon Schubert case OP_AGGREGATE:
122745796c8dcSSimon Schubert *oplenp = 3;
122755796c8dcSSimon Schubert *argsp = longest_to_int (exp->elts[pc - 2].longconst);
122765796c8dcSSimon Schubert break;
122775796c8dcSSimon Schubert
122785796c8dcSSimon Schubert case OP_CHOICES:
122795796c8dcSSimon Schubert *oplenp = 3;
122805796c8dcSSimon Schubert *argsp = longest_to_int (exp->elts[pc - 2].longconst) + 1;
122815796c8dcSSimon Schubert break;
122825796c8dcSSimon Schubert }
122835796c8dcSSimon Schubert }
122845796c8dcSSimon Schubert
12285cf7f2e2dSJohn Marino /* Implementation of the exp_descriptor method operator_check. */
12286cf7f2e2dSJohn Marino
12287cf7f2e2dSJohn Marino static int
ada_operator_check(struct expression * exp,int pos,int (* objfile_func)(struct objfile * objfile,void * data),void * data)12288cf7f2e2dSJohn Marino ada_operator_check (struct expression *exp, int pos,
12289cf7f2e2dSJohn Marino int (*objfile_func) (struct objfile *objfile, void *data),
12290cf7f2e2dSJohn Marino void *data)
12291cf7f2e2dSJohn Marino {
12292cf7f2e2dSJohn Marino const union exp_element *const elts = exp->elts;
12293cf7f2e2dSJohn Marino struct type *type = NULL;
12294cf7f2e2dSJohn Marino
12295cf7f2e2dSJohn Marino switch (elts[pos].opcode)
12296cf7f2e2dSJohn Marino {
12297cf7f2e2dSJohn Marino case UNOP_IN_RANGE:
12298cf7f2e2dSJohn Marino case UNOP_QUAL:
12299cf7f2e2dSJohn Marino type = elts[pos + 1].type;
12300cf7f2e2dSJohn Marino break;
12301cf7f2e2dSJohn Marino
12302cf7f2e2dSJohn Marino default:
12303cf7f2e2dSJohn Marino return operator_check_standard (exp, pos, objfile_func, data);
12304cf7f2e2dSJohn Marino }
12305cf7f2e2dSJohn Marino
12306cf7f2e2dSJohn Marino /* Invoke callbacks for TYPE and OBJFILE if they were set as non-NULL. */
12307cf7f2e2dSJohn Marino
12308cf7f2e2dSJohn Marino if (type && TYPE_OBJFILE (type)
12309cf7f2e2dSJohn Marino && (*objfile_func) (TYPE_OBJFILE (type), data))
12310cf7f2e2dSJohn Marino return 1;
12311cf7f2e2dSJohn Marino
12312cf7f2e2dSJohn Marino return 0;
12313cf7f2e2dSJohn Marino }
12314cf7f2e2dSJohn Marino
123155796c8dcSSimon Schubert static char *
ada_op_name(enum exp_opcode opcode)123165796c8dcSSimon Schubert ada_op_name (enum exp_opcode opcode)
123175796c8dcSSimon Schubert {
123185796c8dcSSimon Schubert switch (opcode)
123195796c8dcSSimon Schubert {
123205796c8dcSSimon Schubert default:
123215796c8dcSSimon Schubert return op_name_standard (opcode);
123225796c8dcSSimon Schubert
123235796c8dcSSimon Schubert #define OP_DEFN(op, len, args, binop) case op: return #op;
123245796c8dcSSimon Schubert ADA_OPERATORS;
123255796c8dcSSimon Schubert #undef OP_DEFN
123265796c8dcSSimon Schubert
123275796c8dcSSimon Schubert case OP_AGGREGATE:
123285796c8dcSSimon Schubert return "OP_AGGREGATE";
123295796c8dcSSimon Schubert case OP_CHOICES:
123305796c8dcSSimon Schubert return "OP_CHOICES";
123315796c8dcSSimon Schubert case OP_NAME:
123325796c8dcSSimon Schubert return "OP_NAME";
123335796c8dcSSimon Schubert }
123345796c8dcSSimon Schubert }
123355796c8dcSSimon Schubert
123365796c8dcSSimon Schubert /* As for operator_length, but assumes PC is pointing at the first
123375796c8dcSSimon Schubert element of the operator, and gives meaningful results only for the
123385796c8dcSSimon Schubert Ada-specific operators, returning 0 for *OPLENP and *ARGSP otherwise. */
123395796c8dcSSimon Schubert
123405796c8dcSSimon Schubert static void
ada_forward_operator_length(struct expression * exp,int pc,int * oplenp,int * argsp)123415796c8dcSSimon Schubert ada_forward_operator_length (struct expression *exp, int pc,
123425796c8dcSSimon Schubert int *oplenp, int *argsp)
123435796c8dcSSimon Schubert {
123445796c8dcSSimon Schubert switch (exp->elts[pc].opcode)
123455796c8dcSSimon Schubert {
123465796c8dcSSimon Schubert default:
123475796c8dcSSimon Schubert *oplenp = *argsp = 0;
123485796c8dcSSimon Schubert break;
123495796c8dcSSimon Schubert
123505796c8dcSSimon Schubert #define OP_DEFN(op, len, args, binop) \
123515796c8dcSSimon Schubert case op: *oplenp = len; *argsp = args; break;
123525796c8dcSSimon Schubert ADA_OPERATORS;
123535796c8dcSSimon Schubert #undef OP_DEFN
123545796c8dcSSimon Schubert
123555796c8dcSSimon Schubert case OP_AGGREGATE:
123565796c8dcSSimon Schubert *oplenp = 3;
123575796c8dcSSimon Schubert *argsp = longest_to_int (exp->elts[pc + 1].longconst);
123585796c8dcSSimon Schubert break;
123595796c8dcSSimon Schubert
123605796c8dcSSimon Schubert case OP_CHOICES:
123615796c8dcSSimon Schubert *oplenp = 3;
123625796c8dcSSimon Schubert *argsp = longest_to_int (exp->elts[pc + 1].longconst) + 1;
123635796c8dcSSimon Schubert break;
123645796c8dcSSimon Schubert
123655796c8dcSSimon Schubert case OP_STRING:
123665796c8dcSSimon Schubert case OP_NAME:
123675796c8dcSSimon Schubert {
123685796c8dcSSimon Schubert int len = longest_to_int (exp->elts[pc + 1].longconst);
12369cf7f2e2dSJohn Marino
123705796c8dcSSimon Schubert *oplenp = 4 + BYTES_TO_EXP_ELEM (len + 1);
123715796c8dcSSimon Schubert *argsp = 0;
123725796c8dcSSimon Schubert break;
123735796c8dcSSimon Schubert }
123745796c8dcSSimon Schubert }
123755796c8dcSSimon Schubert }
123765796c8dcSSimon Schubert
123775796c8dcSSimon Schubert static int
ada_dump_subexp_body(struct expression * exp,struct ui_file * stream,int elt)123785796c8dcSSimon Schubert ada_dump_subexp_body (struct expression *exp, struct ui_file *stream, int elt)
123795796c8dcSSimon Schubert {
123805796c8dcSSimon Schubert enum exp_opcode op = exp->elts[elt].opcode;
123815796c8dcSSimon Schubert int oplen, nargs;
123825796c8dcSSimon Schubert int pc = elt;
123835796c8dcSSimon Schubert int i;
123845796c8dcSSimon Schubert
123855796c8dcSSimon Schubert ada_forward_operator_length (exp, elt, &oplen, &nargs);
123865796c8dcSSimon Schubert
123875796c8dcSSimon Schubert switch (op)
123885796c8dcSSimon Schubert {
123895796c8dcSSimon Schubert /* Ada attributes ('Foo). */
123905796c8dcSSimon Schubert case OP_ATR_FIRST:
123915796c8dcSSimon Schubert case OP_ATR_LAST:
123925796c8dcSSimon Schubert case OP_ATR_LENGTH:
123935796c8dcSSimon Schubert case OP_ATR_IMAGE:
123945796c8dcSSimon Schubert case OP_ATR_MAX:
123955796c8dcSSimon Schubert case OP_ATR_MIN:
123965796c8dcSSimon Schubert case OP_ATR_MODULUS:
123975796c8dcSSimon Schubert case OP_ATR_POS:
123985796c8dcSSimon Schubert case OP_ATR_SIZE:
123995796c8dcSSimon Schubert case OP_ATR_TAG:
124005796c8dcSSimon Schubert case OP_ATR_VAL:
124015796c8dcSSimon Schubert break;
124025796c8dcSSimon Schubert
124035796c8dcSSimon Schubert case UNOP_IN_RANGE:
124045796c8dcSSimon Schubert case UNOP_QUAL:
124055796c8dcSSimon Schubert /* XXX: gdb_sprint_host_address, type_sprint */
124065796c8dcSSimon Schubert fprintf_filtered (stream, _("Type @"));
124075796c8dcSSimon Schubert gdb_print_host_address (exp->elts[pc + 1].type, stream);
124085796c8dcSSimon Schubert fprintf_filtered (stream, " (");
124095796c8dcSSimon Schubert type_print (exp->elts[pc + 1].type, NULL, stream, 0);
124105796c8dcSSimon Schubert fprintf_filtered (stream, ")");
124115796c8dcSSimon Schubert break;
124125796c8dcSSimon Schubert case BINOP_IN_BOUNDS:
124135796c8dcSSimon Schubert fprintf_filtered (stream, " (%d)",
124145796c8dcSSimon Schubert longest_to_int (exp->elts[pc + 2].longconst));
124155796c8dcSSimon Schubert break;
124165796c8dcSSimon Schubert case TERNOP_IN_RANGE:
124175796c8dcSSimon Schubert break;
124185796c8dcSSimon Schubert
124195796c8dcSSimon Schubert case OP_AGGREGATE:
124205796c8dcSSimon Schubert case OP_OTHERS:
124215796c8dcSSimon Schubert case OP_DISCRETE_RANGE:
124225796c8dcSSimon Schubert case OP_POSITIONAL:
124235796c8dcSSimon Schubert case OP_CHOICES:
124245796c8dcSSimon Schubert break;
124255796c8dcSSimon Schubert
124265796c8dcSSimon Schubert case OP_NAME:
124275796c8dcSSimon Schubert case OP_STRING:
124285796c8dcSSimon Schubert {
124295796c8dcSSimon Schubert char *name = &exp->elts[elt + 2].string;
124305796c8dcSSimon Schubert int len = longest_to_int (exp->elts[elt + 1].longconst);
12431cf7f2e2dSJohn Marino
124325796c8dcSSimon Schubert fprintf_filtered (stream, "Text: `%.*s'", len, name);
124335796c8dcSSimon Schubert break;
124345796c8dcSSimon Schubert }
124355796c8dcSSimon Schubert
124365796c8dcSSimon Schubert default:
124375796c8dcSSimon Schubert return dump_subexp_body_standard (exp, stream, elt);
124385796c8dcSSimon Schubert }
124395796c8dcSSimon Schubert
124405796c8dcSSimon Schubert elt += oplen;
124415796c8dcSSimon Schubert for (i = 0; i < nargs; i += 1)
124425796c8dcSSimon Schubert elt = dump_subexp (exp, stream, elt);
124435796c8dcSSimon Schubert
124445796c8dcSSimon Schubert return elt;
124455796c8dcSSimon Schubert }
124465796c8dcSSimon Schubert
124475796c8dcSSimon Schubert /* The Ada extension of print_subexp (q.v.). */
124485796c8dcSSimon Schubert
124495796c8dcSSimon Schubert static void
ada_print_subexp(struct expression * exp,int * pos,struct ui_file * stream,enum precedence prec)124505796c8dcSSimon Schubert ada_print_subexp (struct expression *exp, int *pos,
124515796c8dcSSimon Schubert struct ui_file *stream, enum precedence prec)
124525796c8dcSSimon Schubert {
124535796c8dcSSimon Schubert int oplen, nargs, i;
124545796c8dcSSimon Schubert int pc = *pos;
124555796c8dcSSimon Schubert enum exp_opcode op = exp->elts[pc].opcode;
124565796c8dcSSimon Schubert
124575796c8dcSSimon Schubert ada_forward_operator_length (exp, pc, &oplen, &nargs);
124585796c8dcSSimon Schubert
124595796c8dcSSimon Schubert *pos += oplen;
124605796c8dcSSimon Schubert switch (op)
124615796c8dcSSimon Schubert {
124625796c8dcSSimon Schubert default:
124635796c8dcSSimon Schubert *pos -= oplen;
124645796c8dcSSimon Schubert print_subexp_standard (exp, pos, stream, prec);
124655796c8dcSSimon Schubert return;
124665796c8dcSSimon Schubert
124675796c8dcSSimon Schubert case OP_VAR_VALUE:
124685796c8dcSSimon Schubert fputs_filtered (SYMBOL_NATURAL_NAME (exp->elts[pc + 2].symbol), stream);
124695796c8dcSSimon Schubert return;
124705796c8dcSSimon Schubert
124715796c8dcSSimon Schubert case BINOP_IN_BOUNDS:
124725796c8dcSSimon Schubert /* XXX: sprint_subexp */
124735796c8dcSSimon Schubert print_subexp (exp, pos, stream, PREC_SUFFIX);
124745796c8dcSSimon Schubert fputs_filtered (" in ", stream);
124755796c8dcSSimon Schubert print_subexp (exp, pos, stream, PREC_SUFFIX);
124765796c8dcSSimon Schubert fputs_filtered ("'range", stream);
124775796c8dcSSimon Schubert if (exp->elts[pc + 1].longconst > 1)
124785796c8dcSSimon Schubert fprintf_filtered (stream, "(%ld)",
124795796c8dcSSimon Schubert (long) exp->elts[pc + 1].longconst);
124805796c8dcSSimon Schubert return;
124815796c8dcSSimon Schubert
124825796c8dcSSimon Schubert case TERNOP_IN_RANGE:
124835796c8dcSSimon Schubert if (prec >= PREC_EQUAL)
124845796c8dcSSimon Schubert fputs_filtered ("(", stream);
124855796c8dcSSimon Schubert /* XXX: sprint_subexp */
124865796c8dcSSimon Schubert print_subexp (exp, pos, stream, PREC_SUFFIX);
124875796c8dcSSimon Schubert fputs_filtered (" in ", stream);
124885796c8dcSSimon Schubert print_subexp (exp, pos, stream, PREC_EQUAL);
124895796c8dcSSimon Schubert fputs_filtered (" .. ", stream);
124905796c8dcSSimon Schubert print_subexp (exp, pos, stream, PREC_EQUAL);
124915796c8dcSSimon Schubert if (prec >= PREC_EQUAL)
124925796c8dcSSimon Schubert fputs_filtered (")", stream);
124935796c8dcSSimon Schubert return;
124945796c8dcSSimon Schubert
124955796c8dcSSimon Schubert case OP_ATR_FIRST:
124965796c8dcSSimon Schubert case OP_ATR_LAST:
124975796c8dcSSimon Schubert case OP_ATR_LENGTH:
124985796c8dcSSimon Schubert case OP_ATR_IMAGE:
124995796c8dcSSimon Schubert case OP_ATR_MAX:
125005796c8dcSSimon Schubert case OP_ATR_MIN:
125015796c8dcSSimon Schubert case OP_ATR_MODULUS:
125025796c8dcSSimon Schubert case OP_ATR_POS:
125035796c8dcSSimon Schubert case OP_ATR_SIZE:
125045796c8dcSSimon Schubert case OP_ATR_TAG:
125055796c8dcSSimon Schubert case OP_ATR_VAL:
125065796c8dcSSimon Schubert if (exp->elts[*pos].opcode == OP_TYPE)
125075796c8dcSSimon Schubert {
125085796c8dcSSimon Schubert if (TYPE_CODE (exp->elts[*pos + 1].type) != TYPE_CODE_VOID)
12509*ef5ccd6cSJohn Marino LA_PRINT_TYPE (exp->elts[*pos + 1].type, "", stream, 0, 0,
12510*ef5ccd6cSJohn Marino &type_print_raw_options);
125115796c8dcSSimon Schubert *pos += 3;
125125796c8dcSSimon Schubert }
125135796c8dcSSimon Schubert else
125145796c8dcSSimon Schubert print_subexp (exp, pos, stream, PREC_SUFFIX);
125155796c8dcSSimon Schubert fprintf_filtered (stream, "'%s", ada_attribute_name (op));
125165796c8dcSSimon Schubert if (nargs > 1)
125175796c8dcSSimon Schubert {
125185796c8dcSSimon Schubert int tem;
12519cf7f2e2dSJohn Marino
125205796c8dcSSimon Schubert for (tem = 1; tem < nargs; tem += 1)
125215796c8dcSSimon Schubert {
125225796c8dcSSimon Schubert fputs_filtered ((tem == 1) ? " (" : ", ", stream);
125235796c8dcSSimon Schubert print_subexp (exp, pos, stream, PREC_ABOVE_COMMA);
125245796c8dcSSimon Schubert }
125255796c8dcSSimon Schubert fputs_filtered (")", stream);
125265796c8dcSSimon Schubert }
125275796c8dcSSimon Schubert return;
125285796c8dcSSimon Schubert
125295796c8dcSSimon Schubert case UNOP_QUAL:
125305796c8dcSSimon Schubert type_print (exp->elts[pc + 1].type, "", stream, 0);
125315796c8dcSSimon Schubert fputs_filtered ("'(", stream);
125325796c8dcSSimon Schubert print_subexp (exp, pos, stream, PREC_PREFIX);
125335796c8dcSSimon Schubert fputs_filtered (")", stream);
125345796c8dcSSimon Schubert return;
125355796c8dcSSimon Schubert
125365796c8dcSSimon Schubert case UNOP_IN_RANGE:
125375796c8dcSSimon Schubert /* XXX: sprint_subexp */
125385796c8dcSSimon Schubert print_subexp (exp, pos, stream, PREC_SUFFIX);
125395796c8dcSSimon Schubert fputs_filtered (" in ", stream);
12540*ef5ccd6cSJohn Marino LA_PRINT_TYPE (exp->elts[pc + 1].type, "", stream, 1, 0,
12541*ef5ccd6cSJohn Marino &type_print_raw_options);
125425796c8dcSSimon Schubert return;
125435796c8dcSSimon Schubert
125445796c8dcSSimon Schubert case OP_DISCRETE_RANGE:
125455796c8dcSSimon Schubert print_subexp (exp, pos, stream, PREC_SUFFIX);
125465796c8dcSSimon Schubert fputs_filtered ("..", stream);
125475796c8dcSSimon Schubert print_subexp (exp, pos, stream, PREC_SUFFIX);
125485796c8dcSSimon Schubert return;
125495796c8dcSSimon Schubert
125505796c8dcSSimon Schubert case OP_OTHERS:
125515796c8dcSSimon Schubert fputs_filtered ("others => ", stream);
125525796c8dcSSimon Schubert print_subexp (exp, pos, stream, PREC_SUFFIX);
125535796c8dcSSimon Schubert return;
125545796c8dcSSimon Schubert
125555796c8dcSSimon Schubert case OP_CHOICES:
125565796c8dcSSimon Schubert for (i = 0; i < nargs-1; i += 1)
125575796c8dcSSimon Schubert {
125585796c8dcSSimon Schubert if (i > 0)
125595796c8dcSSimon Schubert fputs_filtered ("|", stream);
125605796c8dcSSimon Schubert print_subexp (exp, pos, stream, PREC_SUFFIX);
125615796c8dcSSimon Schubert }
125625796c8dcSSimon Schubert fputs_filtered (" => ", stream);
125635796c8dcSSimon Schubert print_subexp (exp, pos, stream, PREC_SUFFIX);
125645796c8dcSSimon Schubert return;
125655796c8dcSSimon Schubert
125665796c8dcSSimon Schubert case OP_POSITIONAL:
125675796c8dcSSimon Schubert print_subexp (exp, pos, stream, PREC_SUFFIX);
125685796c8dcSSimon Schubert return;
125695796c8dcSSimon Schubert
125705796c8dcSSimon Schubert case OP_AGGREGATE:
125715796c8dcSSimon Schubert fputs_filtered ("(", stream);
125725796c8dcSSimon Schubert for (i = 0; i < nargs; i += 1)
125735796c8dcSSimon Schubert {
125745796c8dcSSimon Schubert if (i > 0)
125755796c8dcSSimon Schubert fputs_filtered (", ", stream);
125765796c8dcSSimon Schubert print_subexp (exp, pos, stream, PREC_SUFFIX);
125775796c8dcSSimon Schubert }
125785796c8dcSSimon Schubert fputs_filtered (")", stream);
125795796c8dcSSimon Schubert return;
125805796c8dcSSimon Schubert }
125815796c8dcSSimon Schubert }
125825796c8dcSSimon Schubert
125835796c8dcSSimon Schubert /* Table mapping opcodes into strings for printing operators
125845796c8dcSSimon Schubert and precedences of the operators. */
125855796c8dcSSimon Schubert
125865796c8dcSSimon Schubert static const struct op_print ada_op_print_tab[] = {
125875796c8dcSSimon Schubert {":=", BINOP_ASSIGN, PREC_ASSIGN, 1},
125885796c8dcSSimon Schubert {"or else", BINOP_LOGICAL_OR, PREC_LOGICAL_OR, 0},
125895796c8dcSSimon Schubert {"and then", BINOP_LOGICAL_AND, PREC_LOGICAL_AND, 0},
125905796c8dcSSimon Schubert {"or", BINOP_BITWISE_IOR, PREC_BITWISE_IOR, 0},
125915796c8dcSSimon Schubert {"xor", BINOP_BITWISE_XOR, PREC_BITWISE_XOR, 0},
125925796c8dcSSimon Schubert {"and", BINOP_BITWISE_AND, PREC_BITWISE_AND, 0},
125935796c8dcSSimon Schubert {"=", BINOP_EQUAL, PREC_EQUAL, 0},
125945796c8dcSSimon Schubert {"/=", BINOP_NOTEQUAL, PREC_EQUAL, 0},
125955796c8dcSSimon Schubert {"<=", BINOP_LEQ, PREC_ORDER, 0},
125965796c8dcSSimon Schubert {">=", BINOP_GEQ, PREC_ORDER, 0},
125975796c8dcSSimon Schubert {">", BINOP_GTR, PREC_ORDER, 0},
125985796c8dcSSimon Schubert {"<", BINOP_LESS, PREC_ORDER, 0},
125995796c8dcSSimon Schubert {">>", BINOP_RSH, PREC_SHIFT, 0},
126005796c8dcSSimon Schubert {"<<", BINOP_LSH, PREC_SHIFT, 0},
126015796c8dcSSimon Schubert {"+", BINOP_ADD, PREC_ADD, 0},
126025796c8dcSSimon Schubert {"-", BINOP_SUB, PREC_ADD, 0},
126035796c8dcSSimon Schubert {"&", BINOP_CONCAT, PREC_ADD, 0},
126045796c8dcSSimon Schubert {"*", BINOP_MUL, PREC_MUL, 0},
126055796c8dcSSimon Schubert {"/", BINOP_DIV, PREC_MUL, 0},
126065796c8dcSSimon Schubert {"rem", BINOP_REM, PREC_MUL, 0},
126075796c8dcSSimon Schubert {"mod", BINOP_MOD, PREC_MUL, 0},
126085796c8dcSSimon Schubert {"**", BINOP_EXP, PREC_REPEAT, 0},
126095796c8dcSSimon Schubert {"@", BINOP_REPEAT, PREC_REPEAT, 0},
126105796c8dcSSimon Schubert {"-", UNOP_NEG, PREC_PREFIX, 0},
126115796c8dcSSimon Schubert {"+", UNOP_PLUS, PREC_PREFIX, 0},
126125796c8dcSSimon Schubert {"not ", UNOP_LOGICAL_NOT, PREC_PREFIX, 0},
126135796c8dcSSimon Schubert {"not ", UNOP_COMPLEMENT, PREC_PREFIX, 0},
126145796c8dcSSimon Schubert {"abs ", UNOP_ABS, PREC_PREFIX, 0},
126155796c8dcSSimon Schubert {".all", UNOP_IND, PREC_SUFFIX, 1},
126165796c8dcSSimon Schubert {"'access", UNOP_ADDR, PREC_SUFFIX, 1},
126175796c8dcSSimon Schubert {"'size", OP_ATR_SIZE, PREC_SUFFIX, 1},
126185796c8dcSSimon Schubert {NULL, 0, 0, 0}
126195796c8dcSSimon Schubert };
126205796c8dcSSimon Schubert
126215796c8dcSSimon Schubert enum ada_primitive_types {
126225796c8dcSSimon Schubert ada_primitive_type_int,
126235796c8dcSSimon Schubert ada_primitive_type_long,
126245796c8dcSSimon Schubert ada_primitive_type_short,
126255796c8dcSSimon Schubert ada_primitive_type_char,
126265796c8dcSSimon Schubert ada_primitive_type_float,
126275796c8dcSSimon Schubert ada_primitive_type_double,
126285796c8dcSSimon Schubert ada_primitive_type_void,
126295796c8dcSSimon Schubert ada_primitive_type_long_long,
126305796c8dcSSimon Schubert ada_primitive_type_long_double,
126315796c8dcSSimon Schubert ada_primitive_type_natural,
126325796c8dcSSimon Schubert ada_primitive_type_positive,
126335796c8dcSSimon Schubert ada_primitive_type_system_address,
126345796c8dcSSimon Schubert nr_ada_primitive_types
126355796c8dcSSimon Schubert };
126365796c8dcSSimon Schubert
126375796c8dcSSimon Schubert static void
ada_language_arch_info(struct gdbarch * gdbarch,struct language_arch_info * lai)126385796c8dcSSimon Schubert ada_language_arch_info (struct gdbarch *gdbarch,
126395796c8dcSSimon Schubert struct language_arch_info *lai)
126405796c8dcSSimon Schubert {
126415796c8dcSSimon Schubert const struct builtin_type *builtin = builtin_type (gdbarch);
12642cf7f2e2dSJohn Marino
126435796c8dcSSimon Schubert lai->primitive_type_vector
126445796c8dcSSimon Schubert = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_ada_primitive_types + 1,
126455796c8dcSSimon Schubert struct type *);
126465796c8dcSSimon Schubert
126475796c8dcSSimon Schubert lai->primitive_type_vector [ada_primitive_type_int]
126485796c8dcSSimon Schubert = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
126495796c8dcSSimon Schubert 0, "integer");
126505796c8dcSSimon Schubert lai->primitive_type_vector [ada_primitive_type_long]
126515796c8dcSSimon Schubert = arch_integer_type (gdbarch, gdbarch_long_bit (gdbarch),
126525796c8dcSSimon Schubert 0, "long_integer");
126535796c8dcSSimon Schubert lai->primitive_type_vector [ada_primitive_type_short]
126545796c8dcSSimon Schubert = arch_integer_type (gdbarch, gdbarch_short_bit (gdbarch),
126555796c8dcSSimon Schubert 0, "short_integer");
126565796c8dcSSimon Schubert lai->string_char_type
126575796c8dcSSimon Schubert = lai->primitive_type_vector [ada_primitive_type_char]
126585796c8dcSSimon Schubert = arch_integer_type (gdbarch, TARGET_CHAR_BIT, 0, "character");
126595796c8dcSSimon Schubert lai->primitive_type_vector [ada_primitive_type_float]
126605796c8dcSSimon Schubert = arch_float_type (gdbarch, gdbarch_float_bit (gdbarch),
126615796c8dcSSimon Schubert "float", NULL);
126625796c8dcSSimon Schubert lai->primitive_type_vector [ada_primitive_type_double]
126635796c8dcSSimon Schubert = arch_float_type (gdbarch, gdbarch_double_bit (gdbarch),
126645796c8dcSSimon Schubert "long_float", NULL);
126655796c8dcSSimon Schubert lai->primitive_type_vector [ada_primitive_type_long_long]
126665796c8dcSSimon Schubert = arch_integer_type (gdbarch, gdbarch_long_long_bit (gdbarch),
126675796c8dcSSimon Schubert 0, "long_long_integer");
126685796c8dcSSimon Schubert lai->primitive_type_vector [ada_primitive_type_long_double]
126695796c8dcSSimon Schubert = arch_float_type (gdbarch, gdbarch_double_bit (gdbarch),
126705796c8dcSSimon Schubert "long_long_float", NULL);
126715796c8dcSSimon Schubert lai->primitive_type_vector [ada_primitive_type_natural]
126725796c8dcSSimon Schubert = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
126735796c8dcSSimon Schubert 0, "natural");
126745796c8dcSSimon Schubert lai->primitive_type_vector [ada_primitive_type_positive]
126755796c8dcSSimon Schubert = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
126765796c8dcSSimon Schubert 0, "positive");
126775796c8dcSSimon Schubert lai->primitive_type_vector [ada_primitive_type_void]
126785796c8dcSSimon Schubert = builtin->builtin_void;
126795796c8dcSSimon Schubert
126805796c8dcSSimon Schubert lai->primitive_type_vector [ada_primitive_type_system_address]
126815796c8dcSSimon Schubert = lookup_pointer_type (arch_type (gdbarch, TYPE_CODE_VOID, 1, "void"));
126825796c8dcSSimon Schubert TYPE_NAME (lai->primitive_type_vector [ada_primitive_type_system_address])
126835796c8dcSSimon Schubert = "system__address";
126845796c8dcSSimon Schubert
126855796c8dcSSimon Schubert lai->bool_type_symbol = NULL;
126865796c8dcSSimon Schubert lai->bool_type_default = builtin->builtin_bool;
126875796c8dcSSimon Schubert }
126885796c8dcSSimon Schubert
126895796c8dcSSimon Schubert /* Language vector */
126905796c8dcSSimon Schubert
126915796c8dcSSimon Schubert /* Not really used, but needed in the ada_language_defn. */
126925796c8dcSSimon Schubert
126935796c8dcSSimon Schubert static void
emit_char(int c,struct type * type,struct ui_file * stream,int quoter)126945796c8dcSSimon Schubert emit_char (int c, struct type *type, struct ui_file *stream, int quoter)
126955796c8dcSSimon Schubert {
126965796c8dcSSimon Schubert ada_emit_char (c, type, stream, quoter, 1);
126975796c8dcSSimon Schubert }
126985796c8dcSSimon Schubert
126995796c8dcSSimon Schubert static int
parse(void)127005796c8dcSSimon Schubert parse (void)
127015796c8dcSSimon Schubert {
127025796c8dcSSimon Schubert warnings_issued = 0;
127035796c8dcSSimon Schubert return ada_parse ();
127045796c8dcSSimon Schubert }
127055796c8dcSSimon Schubert
127065796c8dcSSimon Schubert static const struct exp_descriptor ada_exp_descriptor = {
127075796c8dcSSimon Schubert ada_print_subexp,
127085796c8dcSSimon Schubert ada_operator_length,
12709cf7f2e2dSJohn Marino ada_operator_check,
127105796c8dcSSimon Schubert ada_op_name,
127115796c8dcSSimon Schubert ada_dump_subexp_body,
127125796c8dcSSimon Schubert ada_evaluate_subexp
127135796c8dcSSimon Schubert };
127145796c8dcSSimon Schubert
12715*ef5ccd6cSJohn Marino /* Implement the "la_get_symbol_name_cmp" language_defn method
12716*ef5ccd6cSJohn Marino for Ada. */
12717*ef5ccd6cSJohn Marino
12718*ef5ccd6cSJohn Marino static symbol_name_cmp_ftype
ada_get_symbol_name_cmp(const char * lookup_name)12719*ef5ccd6cSJohn Marino ada_get_symbol_name_cmp (const char *lookup_name)
12720*ef5ccd6cSJohn Marino {
12721*ef5ccd6cSJohn Marino if (should_use_wild_match (lookup_name))
12722*ef5ccd6cSJohn Marino return wild_match;
12723*ef5ccd6cSJohn Marino else
12724*ef5ccd6cSJohn Marino return compare_names;
12725*ef5ccd6cSJohn Marino }
12726*ef5ccd6cSJohn Marino
12727*ef5ccd6cSJohn Marino /* Implement the "la_read_var_value" language_defn method for Ada. */
12728*ef5ccd6cSJohn Marino
12729*ef5ccd6cSJohn Marino static struct value *
ada_read_var_value(struct symbol * var,struct frame_info * frame)12730*ef5ccd6cSJohn Marino ada_read_var_value (struct symbol *var, struct frame_info *frame)
12731*ef5ccd6cSJohn Marino {
12732*ef5ccd6cSJohn Marino struct block *frame_block = NULL;
12733*ef5ccd6cSJohn Marino struct symbol *renaming_sym = NULL;
12734*ef5ccd6cSJohn Marino
12735*ef5ccd6cSJohn Marino /* The only case where default_read_var_value is not sufficient
12736*ef5ccd6cSJohn Marino is when VAR is a renaming... */
12737*ef5ccd6cSJohn Marino if (frame)
12738*ef5ccd6cSJohn Marino frame_block = get_frame_block (frame, NULL);
12739*ef5ccd6cSJohn Marino if (frame_block)
12740*ef5ccd6cSJohn Marino renaming_sym = ada_find_renaming_symbol (var, frame_block);
12741*ef5ccd6cSJohn Marino if (renaming_sym != NULL)
12742*ef5ccd6cSJohn Marino return ada_read_renaming_var_value (renaming_sym, frame_block);
12743*ef5ccd6cSJohn Marino
12744*ef5ccd6cSJohn Marino /* This is a typical case where we expect the default_read_var_value
12745*ef5ccd6cSJohn Marino function to work. */
12746*ef5ccd6cSJohn Marino return default_read_var_value (var, frame);
12747*ef5ccd6cSJohn Marino }
12748*ef5ccd6cSJohn Marino
127495796c8dcSSimon Schubert const struct language_defn ada_language_defn = {
127505796c8dcSSimon Schubert "ada", /* Language name */
127515796c8dcSSimon Schubert language_ada,
127525796c8dcSSimon Schubert range_check_off,
127535796c8dcSSimon Schubert case_sensitive_on, /* Yes, Ada is case-insensitive, but
127545796c8dcSSimon Schubert that's not quite what this means. */
127555796c8dcSSimon Schubert array_row_major,
127565796c8dcSSimon Schubert macro_expansion_no,
127575796c8dcSSimon Schubert &ada_exp_descriptor,
127585796c8dcSSimon Schubert parse,
127595796c8dcSSimon Schubert ada_error,
127605796c8dcSSimon Schubert resolve,
127615796c8dcSSimon Schubert ada_printchar, /* Print a character constant */
127625796c8dcSSimon Schubert ada_printstr, /* Function to print string constant */
127635796c8dcSSimon Schubert emit_char, /* Function to print single char (not used) */
127645796c8dcSSimon Schubert ada_print_type, /* Print a type using appropriate syntax */
12765cf7f2e2dSJohn Marino ada_print_typedef, /* Print a typedef using appropriate syntax */
127665796c8dcSSimon Schubert ada_val_print, /* Print a value using appropriate syntax */
127675796c8dcSSimon Schubert ada_value_print, /* Print a top-level value */
12768*ef5ccd6cSJohn Marino ada_read_var_value, /* la_read_var_value */
127695796c8dcSSimon Schubert NULL, /* Language specific skip_trampoline */
127705796c8dcSSimon Schubert NULL, /* name_of_this */
127715796c8dcSSimon Schubert ada_lookup_symbol_nonlocal, /* Looking up non-local symbols. */
127725796c8dcSSimon Schubert basic_lookup_transparent_type, /* lookup_transparent_type */
127735796c8dcSSimon Schubert ada_la_decode, /* Language specific symbol demangler */
12774c50c785cSJohn Marino NULL, /* Language specific
12775c50c785cSJohn Marino class_name_from_physname */
127765796c8dcSSimon Schubert ada_op_print_tab, /* expression operators for printing */
127775796c8dcSSimon Schubert 0, /* c-style arrays */
127785796c8dcSSimon Schubert 1, /* String lower bound */
127795796c8dcSSimon Schubert ada_get_gdb_completer_word_break_characters,
127805796c8dcSSimon Schubert ada_make_symbol_completion_list,
127815796c8dcSSimon Schubert ada_language_arch_info,
127825796c8dcSSimon Schubert ada_print_array_index,
127835796c8dcSSimon Schubert default_pass_by_reference,
127845796c8dcSSimon Schubert c_get_string,
12785*ef5ccd6cSJohn Marino ada_get_symbol_name_cmp, /* la_get_symbol_name_cmp */
12786a45ae5f8SJohn Marino ada_iterate_over_symbols,
127875796c8dcSSimon Schubert LANG_MAGIC
127885796c8dcSSimon Schubert };
127895796c8dcSSimon Schubert
127905796c8dcSSimon Schubert /* Provide a prototype to silence -Wmissing-prototypes. */
127915796c8dcSSimon Schubert extern initialize_file_ftype _initialize_ada_language;
127925796c8dcSSimon Schubert
12793cf7f2e2dSJohn Marino /* Command-list for the "set/show ada" prefix command. */
12794cf7f2e2dSJohn Marino static struct cmd_list_element *set_ada_list;
12795cf7f2e2dSJohn Marino static struct cmd_list_element *show_ada_list;
12796cf7f2e2dSJohn Marino
12797cf7f2e2dSJohn Marino /* Implement the "set ada" prefix command. */
12798cf7f2e2dSJohn Marino
12799cf7f2e2dSJohn Marino static void
set_ada_command(char * arg,int from_tty)12800cf7f2e2dSJohn Marino set_ada_command (char *arg, int from_tty)
12801cf7f2e2dSJohn Marino {
12802cf7f2e2dSJohn Marino printf_unfiltered (_(\
12803cf7f2e2dSJohn Marino "\"set ada\" must be followed by the name of a setting.\n"));
12804cf7f2e2dSJohn Marino help_list (set_ada_list, "set ada ", -1, gdb_stdout);
12805cf7f2e2dSJohn Marino }
12806cf7f2e2dSJohn Marino
12807cf7f2e2dSJohn Marino /* Implement the "show ada" prefix command. */
12808cf7f2e2dSJohn Marino
12809cf7f2e2dSJohn Marino static void
show_ada_command(char * args,int from_tty)12810cf7f2e2dSJohn Marino show_ada_command (char *args, int from_tty)
12811cf7f2e2dSJohn Marino {
12812cf7f2e2dSJohn Marino cmd_show_list (show_ada_list, from_tty, "");
12813cf7f2e2dSJohn Marino }
12814cf7f2e2dSJohn Marino
12815a45ae5f8SJohn Marino static void
initialize_ada_catchpoint_ops(void)12816a45ae5f8SJohn Marino initialize_ada_catchpoint_ops (void)
12817a45ae5f8SJohn Marino {
12818a45ae5f8SJohn Marino struct breakpoint_ops *ops;
12819a45ae5f8SJohn Marino
12820a45ae5f8SJohn Marino initialize_breakpoint_ops ();
12821a45ae5f8SJohn Marino
12822a45ae5f8SJohn Marino ops = &catch_exception_breakpoint_ops;
12823a45ae5f8SJohn Marino *ops = bkpt_breakpoint_ops;
12824a45ae5f8SJohn Marino ops->dtor = dtor_catch_exception;
12825a45ae5f8SJohn Marino ops->allocate_location = allocate_location_catch_exception;
12826a45ae5f8SJohn Marino ops->re_set = re_set_catch_exception;
12827a45ae5f8SJohn Marino ops->check_status = check_status_catch_exception;
12828a45ae5f8SJohn Marino ops->print_it = print_it_catch_exception;
12829a45ae5f8SJohn Marino ops->print_one = print_one_catch_exception;
12830a45ae5f8SJohn Marino ops->print_mention = print_mention_catch_exception;
12831a45ae5f8SJohn Marino ops->print_recreate = print_recreate_catch_exception;
12832a45ae5f8SJohn Marino
12833a45ae5f8SJohn Marino ops = &catch_exception_unhandled_breakpoint_ops;
12834a45ae5f8SJohn Marino *ops = bkpt_breakpoint_ops;
12835a45ae5f8SJohn Marino ops->dtor = dtor_catch_exception_unhandled;
12836a45ae5f8SJohn Marino ops->allocate_location = allocate_location_catch_exception_unhandled;
12837a45ae5f8SJohn Marino ops->re_set = re_set_catch_exception_unhandled;
12838a45ae5f8SJohn Marino ops->check_status = check_status_catch_exception_unhandled;
12839a45ae5f8SJohn Marino ops->print_it = print_it_catch_exception_unhandled;
12840a45ae5f8SJohn Marino ops->print_one = print_one_catch_exception_unhandled;
12841a45ae5f8SJohn Marino ops->print_mention = print_mention_catch_exception_unhandled;
12842a45ae5f8SJohn Marino ops->print_recreate = print_recreate_catch_exception_unhandled;
12843a45ae5f8SJohn Marino
12844a45ae5f8SJohn Marino ops = &catch_assert_breakpoint_ops;
12845a45ae5f8SJohn Marino *ops = bkpt_breakpoint_ops;
12846a45ae5f8SJohn Marino ops->dtor = dtor_catch_assert;
12847a45ae5f8SJohn Marino ops->allocate_location = allocate_location_catch_assert;
12848a45ae5f8SJohn Marino ops->re_set = re_set_catch_assert;
12849a45ae5f8SJohn Marino ops->check_status = check_status_catch_assert;
12850a45ae5f8SJohn Marino ops->print_it = print_it_catch_assert;
12851a45ae5f8SJohn Marino ops->print_one = print_one_catch_assert;
12852a45ae5f8SJohn Marino ops->print_mention = print_mention_catch_assert;
12853a45ae5f8SJohn Marino ops->print_recreate = print_recreate_catch_assert;
12854a45ae5f8SJohn Marino }
12855a45ae5f8SJohn Marino
128565796c8dcSSimon Schubert void
_initialize_ada_language(void)128575796c8dcSSimon Schubert _initialize_ada_language (void)
128585796c8dcSSimon Schubert {
128595796c8dcSSimon Schubert add_language (&ada_language_defn);
128605796c8dcSSimon Schubert
12861a45ae5f8SJohn Marino initialize_ada_catchpoint_ops ();
12862a45ae5f8SJohn Marino
12863cf7f2e2dSJohn Marino add_prefix_cmd ("ada", no_class, set_ada_command,
12864cf7f2e2dSJohn Marino _("Prefix command for changing Ada-specfic settings"),
12865cf7f2e2dSJohn Marino &set_ada_list, "set ada ", 0, &setlist);
12866cf7f2e2dSJohn Marino
12867cf7f2e2dSJohn Marino add_prefix_cmd ("ada", no_class, show_ada_command,
12868cf7f2e2dSJohn Marino _("Generic command for showing Ada-specific settings."),
12869cf7f2e2dSJohn Marino &show_ada_list, "show ada ", 0, &showlist);
12870cf7f2e2dSJohn Marino
12871cf7f2e2dSJohn Marino add_setshow_boolean_cmd ("trust-PAD-over-XVS", class_obscure,
12872cf7f2e2dSJohn Marino &trust_pad_over_xvs, _("\
12873cf7f2e2dSJohn Marino Enable or disable an optimization trusting PAD types over XVS types"), _("\
12874cf7f2e2dSJohn Marino Show whether an optimization trusting PAD types over XVS types is activated"),
12875cf7f2e2dSJohn Marino _("\
12876cf7f2e2dSJohn Marino This is related to the encoding used by the GNAT compiler. The debugger\n\
12877cf7f2e2dSJohn Marino should normally trust the contents of PAD types, but certain older versions\n\
12878cf7f2e2dSJohn Marino of GNAT have a bug that sometimes causes the information in the PAD type\n\
12879cf7f2e2dSJohn Marino to be incorrect. Turning this setting \"off\" allows the debugger to\n\
12880cf7f2e2dSJohn Marino work around this bug. It is always safe to turn this option \"off\", but\n\
12881cf7f2e2dSJohn Marino this incurs a slight performance penalty, so it is recommended to NOT change\n\
12882cf7f2e2dSJohn Marino this option to \"off\" unless necessary."),
12883cf7f2e2dSJohn Marino NULL, NULL, &set_ada_list, &show_ada_list);
12884cf7f2e2dSJohn Marino
12885a45ae5f8SJohn Marino add_catch_command ("exception", _("\
12886a45ae5f8SJohn Marino Catch Ada exceptions, when raised.\n\
12887a45ae5f8SJohn Marino With an argument, catch only exceptions with the given name."),
12888a45ae5f8SJohn Marino catch_ada_exception_command,
12889a45ae5f8SJohn Marino NULL,
12890a45ae5f8SJohn Marino CATCH_PERMANENT,
12891a45ae5f8SJohn Marino CATCH_TEMPORARY);
12892a45ae5f8SJohn Marino add_catch_command ("assert", _("\
12893a45ae5f8SJohn Marino Catch failed Ada assertions, when raised.\n\
12894a45ae5f8SJohn Marino With an argument, catch only exceptions with the given name."),
12895a45ae5f8SJohn Marino catch_assert_command,
12896a45ae5f8SJohn Marino NULL,
12897a45ae5f8SJohn Marino CATCH_PERMANENT,
12898a45ae5f8SJohn Marino CATCH_TEMPORARY);
12899a45ae5f8SJohn Marino
129005796c8dcSSimon Schubert varsize_limit = 65536;
129015796c8dcSSimon Schubert
129025796c8dcSSimon Schubert obstack_init (&symbol_list_obstack);
129035796c8dcSSimon Schubert
129045796c8dcSSimon Schubert decoded_names_store = htab_create_alloc
129055796c8dcSSimon Schubert (256, htab_hash_string, (int (*)(const void *, const void *)) streq,
129065796c8dcSSimon Schubert NULL, xcalloc, xfree);
129075796c8dcSSimon Schubert
12908cf7f2e2dSJohn Marino /* Setup per-inferior data. */
12909cf7f2e2dSJohn Marino observer_attach_inferior_exit (ada_inferior_exit);
12910cf7f2e2dSJohn Marino ada_inferior_data
12911*ef5ccd6cSJohn Marino = register_inferior_data_with_cleanup (NULL, ada_inferior_data_cleanup);
129125796c8dcSSimon Schubert }
12913