1 /* Ada language support routines for GDB, the GNU debugger. Copyright (C)
3 1992, 1993, 1994, 1997, 1998, 1999, 2000, 2003, 2004, 2005, 2007
4 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "gdb_string.h"
28 #include "gdb_regex.h"
33 #include "expression.h"
34 #include "parser-defs.h"
40 #include "breakpoint.h"
43 #include "gdb_obstack.h"
45 #include "completer.h"
52 #include "dictionary.h"
53 #include "exceptions.h"
59 #ifndef ADA_RETAIN_DOTS
60 #define ADA_RETAIN_DOTS 0
63 /* Define whether or not the C operator '/' truncates towards zero for
64 differently signed operands (truncation direction is undefined in C).
65 Copied from valarith.c. */
67 #ifndef TRUNCATION_TOWARDS_ZERO
68 #define TRUNCATION_TOWARDS_ZERO ((-5 / 2) == -2)
71 /* A structure that contains a vector of strings.
72 The main purpose of this type is to group the vector and its
73 associated parameters in one structure. This makes it easier
74 to handle and pass around.
76 brobecker/2008-02-04: GDB does provide a generic VEC which should be
77 preferable. But we are using the string_vector structure in the context
78 of symbol completion, and the current infrastructure is such that it's
79 more convenient to use the string vector for now. It would become
80 advantageous to switch to VECs if the rest of the completion-related
81 code switches to VECs as well. */
85 char **array
; /* The vector itself. */
86 int index
; /* Index of the next available element in the array. */
87 size_t size
; /* The number of entries allocated in the array. */
90 static void extract_string (CORE_ADDR addr
, char *buf
);
92 static void modify_general_field (char *, LONGEST
, int, int);
94 static struct type
*desc_base_type (struct type
*);
96 static struct type
*desc_bounds_type (struct type
*);
98 static struct value
*desc_bounds (struct value
*);
100 static int fat_pntr_bounds_bitpos (struct type
*);
102 static int fat_pntr_bounds_bitsize (struct type
*);
104 static struct type
*desc_data_type (struct type
*);
106 static struct value
*desc_data (struct value
*);
108 static int fat_pntr_data_bitpos (struct type
*);
110 static int fat_pntr_data_bitsize (struct type
*);
112 static struct value
*desc_one_bound (struct value
*, int, int);
114 static int desc_bound_bitpos (struct type
*, int, int);
116 static int desc_bound_bitsize (struct type
*, int, int);
118 static struct type
*desc_index_type (struct type
*, int);
120 static int desc_arity (struct type
*);
122 static int ada_type_match (struct type
*, struct type
*, int);
124 static int ada_args_match (struct symbol
*, struct value
**, int);
126 static struct value
*ensure_lval (struct value
*, CORE_ADDR
*);
128 static struct value
*convert_actual (struct value
*, struct type
*,
131 static struct value
*make_array_descriptor (struct type
*, struct value
*,
134 static void ada_add_block_symbols (struct obstack
*,
135 struct block
*, const char *,
136 domain_enum
, struct objfile
*,
137 struct symtab
*, int);
139 static int is_nonfunction (struct ada_symbol_info
*, int);
141 static void add_defn_to_vec (struct obstack
*, struct symbol
*,
142 struct block
*, struct symtab
*);
144 static int num_defns_collected (struct obstack
*);
146 static struct ada_symbol_info
*defns_collected (struct obstack
*, int);
148 static struct partial_symbol
*ada_lookup_partial_symbol (struct partial_symtab
149 *, const char *, int,
152 static struct symtab
*symtab_for_sym (struct symbol
*);
154 static struct value
*resolve_subexp (struct expression
**, int *, int,
157 static void replace_operator_with_call (struct expression
**, int, int, int,
158 struct symbol
*, struct block
*);
160 static int possible_user_operator_p (enum exp_opcode
, struct value
**);
162 static char *ada_op_name (enum exp_opcode
);
164 static const char *ada_decoded_op_name (enum exp_opcode
);
166 static int numeric_type_p (struct type
*);
168 static int integer_type_p (struct type
*);
170 static int scalar_type_p (struct type
*);
172 static int discrete_type_p (struct type
*);
174 static enum ada_renaming_category
parse_old_style_renaming (struct type
*,
179 static struct symbol
*find_old_style_renaming_symbol (const char *,
182 static struct type
*ada_lookup_struct_elt_type (struct type
*, char *,
185 static struct value
*evaluate_subexp (struct type
*, struct expression
*,
188 static struct value
*evaluate_subexp_type (struct expression
*, int *);
190 static int is_dynamic_field (struct type
*, int);
192 static struct type
*to_fixed_variant_branch_type (struct type
*,
194 CORE_ADDR
, struct value
*);
196 static struct type
*to_fixed_array_type (struct type
*, struct value
*, int);
198 static struct type
*to_fixed_range_type (char *, struct value
*,
201 static struct type
*to_static_fixed_type (struct type
*);
202 static struct type
*static_unwrap_type (struct type
*type
);
204 static struct value
*unwrap_value (struct value
*);
206 static struct type
*packed_array_type (struct type
*, long *);
208 static struct type
*decode_packed_array_type (struct type
*);
210 static struct value
*decode_packed_array (struct value
*);
212 static struct value
*value_subscript_packed (struct value
*, int,
215 static void move_bits (gdb_byte
*, int, const gdb_byte
*, int, int);
217 static struct value
*coerce_unspec_val_to_type (struct value
*,
220 static struct value
*get_var_value (char *, char *);
222 static int lesseq_defined_than (struct symbol
*, struct symbol
*);
224 static int equiv_types (struct type
*, struct type
*);
226 static int is_name_suffix (const char *);
228 static int wild_match (const char *, int, const char *);
230 static struct value
*ada_coerce_ref (struct value
*);
232 static LONGEST
pos_atr (struct value
*);
234 static struct value
*value_pos_atr (struct value
*);
236 static struct value
*value_val_atr (struct type
*, struct value
*);
238 static struct symbol
*standard_lookup (const char *, const struct block
*,
241 static struct value
*ada_search_struct_field (char *, struct value
*, int,
244 static struct value
*ada_value_primitive_field (struct value
*, int, int,
247 static int find_struct_field (char *, struct type
*, int,
248 struct type
**, int *, int *, int *, int *);
250 static struct value
*ada_to_fixed_value_create (struct type
*, CORE_ADDR
,
253 static struct value
*ada_to_fixed_value (struct value
*);
255 static int ada_resolve_function (struct ada_symbol_info
*, int,
256 struct value
**, int, const char *,
259 static struct value
*ada_coerce_to_simple_array (struct value
*);
261 static int ada_is_direct_array_type (struct type
*);
263 static void ada_language_arch_info (struct gdbarch
*,
264 struct language_arch_info
*);
266 static void check_size (const struct type
*);
268 static struct value
*ada_index_struct_field (int, struct value
*, int,
271 static struct value
*assign_aggregate (struct value
*, struct value
*,
272 struct expression
*, int *, enum noside
);
274 static void aggregate_assign_from_choices (struct value
*, struct value
*,
276 int *, LONGEST
*, int *,
277 int, LONGEST
, LONGEST
);
279 static void aggregate_assign_positional (struct value
*, struct value
*,
281 int *, LONGEST
*, int *, int,
285 static void aggregate_assign_others (struct value
*, struct value
*,
287 int *, LONGEST
*, int, LONGEST
, LONGEST
);
290 static void add_component_interval (LONGEST
, LONGEST
, LONGEST
*, int *, int);
293 static struct value
*ada_evaluate_subexp (struct type
*, struct expression
*,
296 static void ada_forward_operator_length (struct expression
*, int, int *,
301 /* Maximum-sized dynamic type. */
302 static unsigned int varsize_limit
;
304 /* FIXME: brobecker/2003-09-17: No longer a const because it is
305 returned by a function that does not return a const char *. */
306 static char *ada_completer_word_break_characters
=
308 " \t\n!@#%^&*()+=|~`}{[]\";:?/,-";
310 " \t\n!@#$%^&*()+=|~`}{[]\";:?/,-";
313 /* The name of the symbol to use to get the name of the main subprogram. */
314 static const char ADA_MAIN_PROGRAM_SYMBOL_NAME
[]
315 = "__gnat_ada_main_program_name";
317 /* Limit on the number of warnings to raise per expression evaluation. */
318 static int warning_limit
= 2;
320 /* Number of warning messages issued; reset to 0 by cleanups after
321 expression evaluation. */
322 static int warnings_issued
= 0;
324 static const char *known_runtime_file_name_patterns
[] = {
325 ADA_KNOWN_RUNTIME_FILE_NAME_PATTERNS NULL
328 static const char *known_auxiliary_function_name_patterns
[] = {
329 ADA_KNOWN_AUXILIARY_FUNCTION_NAME_PATTERNS NULL
332 /* Space for allocating results of ada_lookup_symbol_list. */
333 static struct obstack symbol_list_obstack
;
337 /* Create a new empty string_vector struct with an initial size of
340 static struct string_vector
341 new_string_vector (int initial_size
)
343 struct string_vector result
;
345 result
.array
= (char **) xmalloc ((initial_size
+ 1) * sizeof (char *));
347 result
.size
= initial_size
;
352 /* Add STR at the end of the given string vector SV. If SV is already
353 full, its size is automatically increased (doubled). */
356 string_vector_append (struct string_vector
*sv
, char *str
)
358 if (sv
->index
>= sv
->size
)
359 GROW_VECT (sv
->array
, sv
->size
, sv
->size
* 2);
361 sv
->array
[sv
->index
] = str
;
365 /* Given DECODED_NAME a string holding a symbol name in its
366 decoded form (ie using the Ada dotted notation), returns
367 its unqualified name. */
370 ada_unqualified_name (const char *decoded_name
)
372 const char *result
= strrchr (decoded_name
, '.');
375 result
++; /* Skip the dot... */
377 result
= decoded_name
;
382 /* Return a string starting with '<', followed by STR, and '>'.
383 The result is good until the next call. */
386 add_angle_brackets (const char *str
)
388 static char *result
= NULL
;
391 result
= (char *) xmalloc ((strlen (str
) + 3) * sizeof (char));
393 sprintf (result
, "<%s>", str
);
398 ada_get_gdb_completer_word_break_characters (void)
400 return ada_completer_word_break_characters
;
403 /* Print an array element index using the Ada syntax. */
406 ada_print_array_index (struct value
*index_value
, struct ui_file
*stream
,
407 int format
, enum val_prettyprint pretty
)
409 LA_VALUE_PRINT (index_value
, stream
, format
, pretty
);
410 fprintf_filtered (stream
, " => ");
413 /* Read the string located at ADDR from the inferior and store the
417 extract_string (CORE_ADDR addr
, char *buf
)
421 /* Loop, reading one byte at a time, until we reach the '\000'
422 end-of-string marker. */
425 target_read_memory (addr
+ char_index
* sizeof (char),
426 buf
+ char_index
* sizeof (char), sizeof (char));
429 while (buf
[char_index
- 1] != '\000');
432 /* Assuming VECT points to an array of *SIZE objects of size
433 ELEMENT_SIZE, grow it to contain at least MIN_SIZE objects,
434 updating *SIZE as necessary and returning the (new) array. */
437 grow_vect (void *vect
, size_t *size
, size_t min_size
, int element_size
)
439 if (*size
< min_size
)
442 if (*size
< min_size
)
444 vect
= xrealloc (vect
, *size
* element_size
);
449 /* True (non-zero) iff TARGET matches FIELD_NAME up to any trailing
450 suffix of FIELD_NAME beginning "___". */
453 field_name_match (const char *field_name
, const char *target
)
455 int len
= strlen (target
);
457 (strncmp (field_name
, target
, len
) == 0
458 && (field_name
[len
] == '\0'
459 || (strncmp (field_name
+ len
, "___", 3) == 0
460 && strcmp (field_name
+ strlen (field_name
) - 6,
465 /* Assuming TYPE is a TYPE_CODE_STRUCT, find the field whose name matches
466 FIELD_NAME, and return its index. This function also handles fields
467 whose name have ___ suffixes because the compiler sometimes alters
468 their name by adding such a suffix to represent fields with certain
469 constraints. If the field could not be found, return a negative
470 number if MAYBE_MISSING is set. Otherwise raise an error. */
473 ada_get_field_index (const struct type
*type
, const char *field_name
,
477 for (fieldno
= 0; fieldno
< TYPE_NFIELDS (type
); fieldno
++)
478 if (field_name_match (TYPE_FIELD_NAME (type
, fieldno
), field_name
))
482 error (_("Unable to find field %s in struct %s. Aborting"),
483 field_name
, TYPE_NAME (type
));
488 /* The length of the prefix of NAME prior to any "___" suffix. */
491 ada_name_prefix_len (const char *name
)
497 const char *p
= strstr (name
, "___");
499 return strlen (name
);
505 /* Return non-zero if SUFFIX is a suffix of STR.
506 Return zero if STR is null. */
509 is_suffix (const char *str
, const char *suffix
)
515 len2
= strlen (suffix
);
516 return (len1
>= len2
&& strcmp (str
+ len1
- len2
, suffix
) == 0);
519 /* Create a value of type TYPE whose contents come from VALADDR, if it
520 is non-null, and whose memory address (in the inferior) is
524 value_from_contents_and_address (struct type
*type
,
525 const gdb_byte
*valaddr
,
528 struct value
*v
= allocate_value (type
);
530 set_value_lazy (v
, 1);
532 memcpy (value_contents_raw (v
), valaddr
, TYPE_LENGTH (type
));
533 VALUE_ADDRESS (v
) = address
;
535 VALUE_LVAL (v
) = lval_memory
;
539 /* The contents of value VAL, treated as a value of type TYPE. The
540 result is an lval in memory if VAL is. */
542 static struct value
*
543 coerce_unspec_val_to_type (struct value
*val
, struct type
*type
)
545 type
= ada_check_typedef (type
);
546 if (value_type (val
) == type
)
550 struct value
*result
;
552 /* Make sure that the object size is not unreasonable before
553 trying to allocate some memory for it. */
556 result
= allocate_value (type
);
557 VALUE_LVAL (result
) = VALUE_LVAL (val
);
558 set_value_bitsize (result
, value_bitsize (val
));
559 set_value_bitpos (result
, value_bitpos (val
));
560 VALUE_ADDRESS (result
) = VALUE_ADDRESS (val
) + value_offset (val
);
562 || TYPE_LENGTH (type
) > TYPE_LENGTH (value_type (val
)))
563 set_value_lazy (result
, 1);
565 memcpy (value_contents_raw (result
), value_contents (val
),
571 static const gdb_byte
*
572 cond_offset_host (const gdb_byte
*valaddr
, long offset
)
577 return valaddr
+ offset
;
581 cond_offset_target (CORE_ADDR address
, long offset
)
586 return address
+ offset
;
589 /* Issue a warning (as for the definition of warning in utils.c, but
590 with exactly one argument rather than ...), unless the limit on the
591 number of warnings has passed during the evaluation of the current
594 /* FIXME: cagney/2004-10-10: This function is mimicking the behavior
595 provided by "complaint". */
596 static void lim_warning (const char *format
, ...) ATTR_FORMAT (printf
, 1, 2);
599 lim_warning (const char *format
, ...)
602 va_start (args
, format
);
604 warnings_issued
+= 1;
605 if (warnings_issued
<= warning_limit
)
606 vwarning (format
, args
);
611 /* Issue an error if the size of an object of type T is unreasonable,
612 i.e. if it would be a bad idea to allocate a value of this type in
616 check_size (const struct type
*type
)
618 if (TYPE_LENGTH (type
) > varsize_limit
)
619 error (_("object size is larger than varsize-limit"));
623 /* Note: would have used MAX_OF_TYPE and MIN_OF_TYPE macros from
624 gdbtypes.h, but some of the necessary definitions in that file
625 seem to have gone missing. */
627 /* Maximum value of a SIZE-byte signed integer type. */
629 max_of_size (int size
)
631 LONGEST top_bit
= (LONGEST
) 1 << (size
* 8 - 2);
632 return top_bit
| (top_bit
- 1);
635 /* Minimum value of a SIZE-byte signed integer type. */
637 min_of_size (int size
)
639 return -max_of_size (size
) - 1;
642 /* Maximum value of a SIZE-byte unsigned integer type. */
644 umax_of_size (int size
)
646 ULONGEST top_bit
= (ULONGEST
) 1 << (size
* 8 - 1);
647 return top_bit
| (top_bit
- 1);
650 /* Maximum value of integral type T, as a signed quantity. */
652 max_of_type (struct type
*t
)
654 if (TYPE_UNSIGNED (t
))
655 return (LONGEST
) umax_of_size (TYPE_LENGTH (t
));
657 return max_of_size (TYPE_LENGTH (t
));
660 /* Minimum value of integral type T, as a signed quantity. */
662 min_of_type (struct type
*t
)
664 if (TYPE_UNSIGNED (t
))
667 return min_of_size (TYPE_LENGTH (t
));
670 /* The largest value in the domain of TYPE, a discrete type, as an integer. */
671 static struct value
*
672 discrete_type_high_bound (struct type
*type
)
674 switch (TYPE_CODE (type
))
676 case TYPE_CODE_RANGE
:
677 return value_from_longest (TYPE_TARGET_TYPE (type
),
678 TYPE_HIGH_BOUND (type
));
681 value_from_longest (type
,
682 TYPE_FIELD_BITPOS (type
,
683 TYPE_NFIELDS (type
) - 1));
685 return value_from_longest (type
, max_of_type (type
));
687 error (_("Unexpected type in discrete_type_high_bound."));
691 /* The largest value in the domain of TYPE, a discrete type, as an integer. */
692 static struct value
*
693 discrete_type_low_bound (struct type
*type
)
695 switch (TYPE_CODE (type
))
697 case TYPE_CODE_RANGE
:
698 return value_from_longest (TYPE_TARGET_TYPE (type
),
699 TYPE_LOW_BOUND (type
));
701 return value_from_longest (type
, TYPE_FIELD_BITPOS (type
, 0));
703 return value_from_longest (type
, min_of_type (type
));
705 error (_("Unexpected type in discrete_type_low_bound."));
709 /* The identity on non-range types. For range types, the underlying
710 non-range scalar type. */
713 base_type (struct type
*type
)
715 while (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_RANGE
)
717 if (type
== TYPE_TARGET_TYPE (type
) || TYPE_TARGET_TYPE (type
) == NULL
)
719 type
= TYPE_TARGET_TYPE (type
);
725 /* Language Selection */
727 /* If the main program is in Ada, return language_ada, otherwise return LANG
728 (the main program is in Ada iif the adainit symbol is found).
730 MAIN_PST is not used. */
733 ada_update_initial_language (enum language lang
,
734 struct partial_symtab
*main_pst
)
736 if (lookup_minimal_symbol ("adainit", (const char *) NULL
,
737 (struct objfile
*) NULL
) != NULL
)
743 /* If the main procedure is written in Ada, then return its name.
744 The result is good until the next call. Return NULL if the main
745 procedure doesn't appear to be in Ada. */
750 struct minimal_symbol
*msym
;
751 CORE_ADDR main_program_name_addr
;
752 static char main_program_name
[1024];
754 /* For Ada, the name of the main procedure is stored in a specific
755 string constant, generated by the binder. Look for that symbol,
756 extract its address, and then read that string. If we didn't find
757 that string, then most probably the main procedure is not written
759 msym
= lookup_minimal_symbol (ADA_MAIN_PROGRAM_SYMBOL_NAME
, NULL
, NULL
);
763 main_program_name_addr
= SYMBOL_VALUE_ADDRESS (msym
);
764 if (main_program_name_addr
== 0)
765 error (_("Invalid address for Ada main program name."));
767 extract_string (main_program_name_addr
, main_program_name
);
768 return main_program_name
;
771 /* The main procedure doesn't seem to be in Ada. */
777 /* Table of Ada operators and their GNAT-encoded names. Last entry is pair
780 const struct ada_opname_map ada_opname_table
[] = {
781 {"Oadd", "\"+\"", BINOP_ADD
},
782 {"Osubtract", "\"-\"", BINOP_SUB
},
783 {"Omultiply", "\"*\"", BINOP_MUL
},
784 {"Odivide", "\"/\"", BINOP_DIV
},
785 {"Omod", "\"mod\"", BINOP_MOD
},
786 {"Orem", "\"rem\"", BINOP_REM
},
787 {"Oexpon", "\"**\"", BINOP_EXP
},
788 {"Olt", "\"<\"", BINOP_LESS
},
789 {"Ole", "\"<=\"", BINOP_LEQ
},
790 {"Ogt", "\">\"", BINOP_GTR
},
791 {"Oge", "\">=\"", BINOP_GEQ
},
792 {"Oeq", "\"=\"", BINOP_EQUAL
},
793 {"One", "\"/=\"", BINOP_NOTEQUAL
},
794 {"Oand", "\"and\"", BINOP_BITWISE_AND
},
795 {"Oor", "\"or\"", BINOP_BITWISE_IOR
},
796 {"Oxor", "\"xor\"", BINOP_BITWISE_XOR
},
797 {"Oconcat", "\"&\"", BINOP_CONCAT
},
798 {"Oabs", "\"abs\"", UNOP_ABS
},
799 {"Onot", "\"not\"", UNOP_LOGICAL_NOT
},
800 {"Oadd", "\"+\"", UNOP_PLUS
},
801 {"Osubtract", "\"-\"", UNOP_NEG
},
805 /* Return non-zero if STR should be suppressed in info listings. */
808 is_suppressed_name (const char *str
)
810 if (strncmp (str
, "_ada_", 5) == 0)
812 if (str
[0] == '_' || str
[0] == '\000')
817 const char *suffix
= strstr (str
, "___");
818 if (suffix
!= NULL
&& suffix
[3] != 'X')
821 suffix
= str
+ strlen (str
);
822 for (p
= suffix
- 1; p
!= str
; p
-= 1)
826 if (p
[0] == 'X' && p
[-1] != '_')
830 for (i
= 0; ada_opname_table
[i
].encoded
!= NULL
; i
+= 1)
831 if (strncmp (ada_opname_table
[i
].encoded
, p
,
832 strlen (ada_opname_table
[i
].encoded
)) == 0)
841 /* The "encoded" form of DECODED, according to GNAT conventions.
842 The result is valid until the next call to ada_encode. */
845 ada_encode (const char *decoded
)
847 static char *encoding_buffer
= NULL
;
848 static size_t encoding_buffer_size
= 0;
855 GROW_VECT (encoding_buffer
, encoding_buffer_size
,
856 2 * strlen (decoded
) + 10);
859 for (p
= decoded
; *p
!= '\0'; p
+= 1)
861 if (!ADA_RETAIN_DOTS
&& *p
== '.')
863 encoding_buffer
[k
] = encoding_buffer
[k
+ 1] = '_';
868 const struct ada_opname_map
*mapping
;
870 for (mapping
= ada_opname_table
;
871 mapping
->encoded
!= NULL
872 && strncmp (mapping
->decoded
, p
,
873 strlen (mapping
->decoded
)) != 0; mapping
+= 1)
875 if (mapping
->encoded
== NULL
)
876 error (_("invalid Ada operator name: %s"), p
);
877 strcpy (encoding_buffer
+ k
, mapping
->encoded
);
878 k
+= strlen (mapping
->encoded
);
883 encoding_buffer
[k
] = *p
;
888 encoding_buffer
[k
] = '\0';
889 return encoding_buffer
;
892 /* Return NAME folded to lower case, or, if surrounded by single
893 quotes, unfolded, but with the quotes stripped away. Result good
897 ada_fold_name (const char *name
)
899 static char *fold_buffer
= NULL
;
900 static size_t fold_buffer_size
= 0;
902 int len
= strlen (name
);
903 GROW_VECT (fold_buffer
, fold_buffer_size
, len
+ 1);
907 strncpy (fold_buffer
, name
+ 1, len
- 2);
908 fold_buffer
[len
- 2] = '\000';
913 for (i
= 0; i
<= len
; i
+= 1)
914 fold_buffer
[i
] = tolower (name
[i
]);
920 /* Return nonzero if C is either a digit or a lowercase alphabet character. */
923 is_lower_alphanum (const char c
)
925 return (isdigit (c
) || (isalpha (c
) && islower (c
)));
928 /* Remove either of these suffixes:
933 These are suffixes introduced by the compiler for entities such as
934 nested subprogram for instance, in order to avoid name clashes.
935 They do not serve any purpose for the debugger. */
938 ada_remove_trailing_digits (const char *encoded
, int *len
)
940 if (*len
> 1 && isdigit (encoded
[*len
- 1]))
943 while (i
> 0 && isdigit (encoded
[i
]))
945 if (i
>= 0 && encoded
[i
] == '.')
947 else if (i
>= 0 && encoded
[i
] == '$')
949 else if (i
>= 2 && strncmp (encoded
+ i
- 2, "___", 3) == 0)
951 else if (i
>= 1 && strncmp (encoded
+ i
- 1, "__", 2) == 0)
956 /* Remove the suffix introduced by the compiler for protected object
960 ada_remove_po_subprogram_suffix (const char *encoded
, int *len
)
962 /* Remove trailing N. */
964 /* Protected entry subprograms are broken into two
965 separate subprograms: The first one is unprotected, and has
966 a 'N' suffix; the second is the protected version, and has
967 the 'P' suffix. The second calls the first one after handling
968 the protection. Since the P subprograms are internally generated,
969 we leave these names undecoded, giving the user a clue that this
970 entity is internal. */
973 && encoded
[*len
- 1] == 'N'
974 && (isdigit (encoded
[*len
- 2]) || islower (encoded
[*len
- 2])))
978 /* If ENCODED follows the GNAT entity encoding conventions, then return
979 the decoded form of ENCODED. Otherwise, return "<%s>" where "%s" is
982 The resulting string is valid until the next call of ada_decode.
983 If the string is unchanged by decoding, the original string pointer
987 ada_decode (const char *encoded
)
994 static char *decoding_buffer
= NULL
;
995 static size_t decoding_buffer_size
= 0;
997 /* The name of the Ada main procedure starts with "_ada_".
998 This prefix is not part of the decoded name, so skip this part
999 if we see this prefix. */
1000 if (strncmp (encoded
, "_ada_", 5) == 0)
1003 /* If the name starts with '_', then it is not a properly encoded
1004 name, so do not attempt to decode it. Similarly, if the name
1005 starts with '<', the name should not be decoded. */
1006 if (encoded
[0] == '_' || encoded
[0] == '<')
1009 len0
= strlen (encoded
);
1011 ada_remove_trailing_digits (encoded
, &len0
);
1012 ada_remove_po_subprogram_suffix (encoded
, &len0
);
1014 /* Remove the ___X.* suffix if present. Do not forget to verify that
1015 the suffix is located before the current "end" of ENCODED. We want
1016 to avoid re-matching parts of ENCODED that have previously been
1017 marked as discarded (by decrementing LEN0). */
1018 p
= strstr (encoded
, "___");
1019 if (p
!= NULL
&& p
- encoded
< len0
- 3)
1027 /* Remove any trailing TKB suffix. It tells us that this symbol
1028 is for the body of a task, but that information does not actually
1029 appear in the decoded name. */
1031 if (len0
> 3 && strncmp (encoded
+ len0
- 3, "TKB", 3) == 0)
1034 /* Remove trailing "B" suffixes. */
1035 /* FIXME: brobecker/2006-04-19: Not sure what this are used for... */
1037 if (len0
> 1 && strncmp (encoded
+ len0
- 1, "B", 1) == 0)
1040 /* Make decoded big enough for possible expansion by operator name. */
1042 GROW_VECT (decoding_buffer
, decoding_buffer_size
, 2 * len0
+ 1);
1043 decoded
= decoding_buffer
;
1045 /* Remove trailing __{digit}+ or trailing ${digit}+. */
1047 if (len0
> 1 && isdigit (encoded
[len0
- 1]))
1050 while ((i
>= 0 && isdigit (encoded
[i
]))
1051 || (i
>= 1 && encoded
[i
] == '_' && isdigit (encoded
[i
- 1])))
1053 if (i
> 1 && encoded
[i
] == '_' && encoded
[i
- 1] == '_')
1055 else if (encoded
[i
] == '$')
1059 /* The first few characters that are not alphabetic are not part
1060 of any encoding we use, so we can copy them over verbatim. */
1062 for (i
= 0, j
= 0; i
< len0
&& !isalpha (encoded
[i
]); i
+= 1, j
+= 1)
1063 decoded
[j
] = encoded
[i
];
1068 /* Is this a symbol function? */
1069 if (at_start_name
&& encoded
[i
] == 'O')
1072 for (k
= 0; ada_opname_table
[k
].encoded
!= NULL
; k
+= 1)
1074 int op_len
= strlen (ada_opname_table
[k
].encoded
);
1075 if ((strncmp (ada_opname_table
[k
].encoded
+ 1, encoded
+ i
+ 1,
1077 && !isalnum (encoded
[i
+ op_len
]))
1079 strcpy (decoded
+ j
, ada_opname_table
[k
].decoded
);
1082 j
+= strlen (ada_opname_table
[k
].decoded
);
1086 if (ada_opname_table
[k
].encoded
!= NULL
)
1091 /* Replace "TK__" with "__", which will eventually be translated
1092 into "." (just below). */
1094 if (i
< len0
- 4 && strncmp (encoded
+ i
, "TK__", 4) == 0)
1097 /* Replace "__B_{DIGITS}+__" sequences by "__", which will eventually
1098 be translated into "." (just below). These are internal names
1099 generated for anonymous blocks inside which our symbol is nested. */
1101 if (len0
- i
> 5 && encoded
[i
] == '_' && encoded
[i
+1] == '_'
1102 && encoded
[i
+2] == 'B' && encoded
[i
+3] == '_'
1103 && isdigit (encoded
[i
+4]))
1107 while (k
< len0
&& isdigit (encoded
[k
]))
1108 k
++; /* Skip any extra digit. */
1110 /* Double-check that the "__B_{DIGITS}+" sequence we found
1111 is indeed followed by "__". */
1112 if (len0
- k
> 2 && encoded
[k
] == '_' && encoded
[k
+1] == '_')
1116 /* Remove _E{DIGITS}+[sb] */
1118 /* Just as for protected object subprograms, there are 2 categories
1119 of subprograms created by the compiler for each entry. The first
1120 one implements the actual entry code, and has a suffix following
1121 the convention above; the second one implements the barrier and
1122 uses the same convention as above, except that the 'E' is replaced
1125 Just as above, we do not decode the name of barrier functions
1126 to give the user a clue that the code he is debugging has been
1127 internally generated. */
1129 if (len0
- i
> 3 && encoded
[i
] == '_' && encoded
[i
+1] == 'E'
1130 && isdigit (encoded
[i
+2]))
1134 while (k
< len0
&& isdigit (encoded
[k
]))
1138 && (encoded
[k
] == 'b' || encoded
[k
] == 's'))
1141 /* Just as an extra precaution, make sure that if this
1142 suffix is followed by anything else, it is a '_'.
1143 Otherwise, we matched this sequence by accident. */
1145 || (k
< len0
&& encoded
[k
] == '_'))
1150 /* Remove trailing "N" in [a-z0-9]+N__. The N is added by
1151 the GNAT front-end in protected object subprograms. */
1154 && encoded
[i
] == 'N' && encoded
[i
+1] == '_' && encoded
[i
+2] == '_')
1156 /* Backtrack a bit up until we reach either the begining of
1157 the encoded name, or "__". Make sure that we only find
1158 digits or lowercase characters. */
1159 const char *ptr
= encoded
+ i
- 1;
1161 while (ptr
>= encoded
&& is_lower_alphanum (ptr
[0]))
1164 || (ptr
> encoded
&& ptr
[0] == '_' && ptr
[-1] == '_'))
1168 if (encoded
[i
] == 'X' && i
!= 0 && isalnum (encoded
[i
- 1]))
1170 /* This is a X[bn]* sequence not separated from the previous
1171 part of the name with a non-alpha-numeric character (in other
1172 words, immediately following an alpha-numeric character), then
1173 verify that it is placed at the end of the encoded name. If
1174 not, then the encoding is not valid and we should abort the
1175 decoding. Otherwise, just skip it, it is used in body-nested
1179 while (i
< len0
&& (encoded
[i
] == 'b' || encoded
[i
] == 'n'));
1183 else if (!ADA_RETAIN_DOTS
1184 && i
< len0
- 2 && encoded
[i
] == '_' && encoded
[i
+ 1] == '_')
1186 /* Replace '__' by '.'. */
1194 /* It's a character part of the decoded name, so just copy it
1196 decoded
[j
] = encoded
[i
];
1201 decoded
[j
] = '\000';
1203 /* Decoded names should never contain any uppercase character.
1204 Double-check this, and abort the decoding if we find one. */
1206 for (i
= 0; decoded
[i
] != '\0'; i
+= 1)
1207 if (isupper (decoded
[i
]) || decoded
[i
] == ' ')
1210 if (strcmp (decoded
, encoded
) == 0)
1216 GROW_VECT (decoding_buffer
, decoding_buffer_size
, strlen (encoded
) + 3);
1217 decoded
= decoding_buffer
;
1218 if (encoded
[0] == '<')
1219 strcpy (decoded
, encoded
);
1221 sprintf (decoded
, "<%s>", encoded
);
1226 /* Table for keeping permanent unique copies of decoded names. Once
1227 allocated, names in this table are never released. While this is a
1228 storage leak, it should not be significant unless there are massive
1229 changes in the set of decoded names in successive versions of a
1230 symbol table loaded during a single session. */
1231 static struct htab
*decoded_names_store
;
1233 /* Returns the decoded name of GSYMBOL, as for ada_decode, caching it
1234 in the language-specific part of GSYMBOL, if it has not been
1235 previously computed. Tries to save the decoded name in the same
1236 obstack as GSYMBOL, if possible, and otherwise on the heap (so that,
1237 in any case, the decoded symbol has a lifetime at least that of
1239 The GSYMBOL parameter is "mutable" in the C++ sense: logically
1240 const, but nevertheless modified to a semantically equivalent form
1241 when a decoded name is cached in it.
1245 ada_decode_symbol (const struct general_symbol_info
*gsymbol
)
1248 (char **) &gsymbol
->language_specific
.cplus_specific
.demangled_name
;
1249 if (*resultp
== NULL
)
1251 const char *decoded
= ada_decode (gsymbol
->name
);
1252 if (gsymbol
->bfd_section
!= NULL
)
1254 bfd
*obfd
= gsymbol
->bfd_section
->owner
;
1257 struct objfile
*objf
;
1260 if (obfd
== objf
->obfd
)
1262 *resultp
= obsavestring (decoded
, strlen (decoded
),
1263 &objf
->objfile_obstack
);
1269 /* Sometimes, we can't find a corresponding objfile, in which
1270 case, we put the result on the heap. Since we only decode
1271 when needed, we hope this usually does not cause a
1272 significant memory leak (FIXME). */
1273 if (*resultp
== NULL
)
1275 char **slot
= (char **) htab_find_slot (decoded_names_store
,
1278 *slot
= xstrdup (decoded
);
1287 ada_la_decode (const char *encoded
, int options
)
1289 return xstrdup (ada_decode (encoded
));
1292 /* Returns non-zero iff SYM_NAME matches NAME, ignoring any trailing
1293 suffixes that encode debugging information or leading _ada_ on
1294 SYM_NAME (see is_name_suffix commentary for the debugging
1295 information that is ignored). If WILD, then NAME need only match a
1296 suffix of SYM_NAME minus the same suffixes. Also returns 0 if
1297 either argument is NULL. */
1300 ada_match_name (const char *sym_name
, const char *name
, int wild
)
1302 if (sym_name
== NULL
|| name
== NULL
)
1305 return wild_match (name
, strlen (name
), sym_name
);
1308 int len_name
= strlen (name
);
1309 return (strncmp (sym_name
, name
, len_name
) == 0
1310 && is_name_suffix (sym_name
+ len_name
))
1311 || (strncmp (sym_name
, "_ada_", 5) == 0
1312 && strncmp (sym_name
+ 5, name
, len_name
) == 0
1313 && is_name_suffix (sym_name
+ len_name
+ 5));
1317 /* True (non-zero) iff, in Ada mode, the symbol SYM should be
1318 suppressed in info listings. */
1321 ada_suppress_symbol_printing (struct symbol
*sym
)
1323 if (SYMBOL_DOMAIN (sym
) == STRUCT_DOMAIN
)
1326 return is_suppressed_name (SYMBOL_LINKAGE_NAME (sym
));
1332 /* Names of MAX_ADA_DIMENS bounds in P_BOUNDS fields of array descriptors. */
1334 static char *bound_name
[] = {
1335 "LB0", "UB0", "LB1", "UB1", "LB2", "UB2", "LB3", "UB3",
1336 "LB4", "UB4", "LB5", "UB5", "LB6", "UB6", "LB7", "UB7"
1339 /* Maximum number of array dimensions we are prepared to handle. */
1341 #define MAX_ADA_DIMENS (sizeof(bound_name) / (2*sizeof(char *)))
1343 /* Like modify_field, but allows bitpos > wordlength. */
1346 modify_general_field (char *addr
, LONGEST fieldval
, int bitpos
, int bitsize
)
1348 modify_field (addr
+ bitpos
/ 8, fieldval
, bitpos
% 8, bitsize
);
1352 /* The desc_* routines return primitive portions of array descriptors
1355 /* The descriptor or array type, if any, indicated by TYPE; removes
1356 level of indirection, if needed. */
1358 static struct type
*
1359 desc_base_type (struct type
*type
)
1363 type
= ada_check_typedef (type
);
1365 && (TYPE_CODE (type
) == TYPE_CODE_PTR
1366 || TYPE_CODE (type
) == TYPE_CODE_REF
))
1367 return ada_check_typedef (TYPE_TARGET_TYPE (type
));
1372 /* True iff TYPE indicates a "thin" array pointer type. */
1375 is_thin_pntr (struct type
*type
)
1378 is_suffix (ada_type_name (desc_base_type (type
)), "___XUT")
1379 || is_suffix (ada_type_name (desc_base_type (type
)), "___XUT___XVE");
1382 /* The descriptor type for thin pointer type TYPE. */
1384 static struct type
*
1385 thin_descriptor_type (struct type
*type
)
1387 struct type
*base_type
= desc_base_type (type
);
1388 if (base_type
== NULL
)
1390 if (is_suffix (ada_type_name (base_type
), "___XVE"))
1394 struct type
*alt_type
= ada_find_parallel_type (base_type
, "___XVE");
1395 if (alt_type
== NULL
)
1402 /* A pointer to the array data for thin-pointer value VAL. */
1404 static struct value
*
1405 thin_data_pntr (struct value
*val
)
1407 struct type
*type
= value_type (val
);
1408 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
1409 return value_cast (desc_data_type (thin_descriptor_type (type
)),
1412 return value_from_longest (desc_data_type (thin_descriptor_type (type
)),
1413 VALUE_ADDRESS (val
) + value_offset (val
));
1416 /* True iff TYPE indicates a "thick" array pointer type. */
1419 is_thick_pntr (struct type
*type
)
1421 type
= desc_base_type (type
);
1422 return (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_STRUCT
1423 && lookup_struct_elt_type (type
, "P_BOUNDS", 1) != NULL
);
1426 /* If TYPE is the type of an array descriptor (fat or thin pointer) or a
1427 pointer to one, the type of its bounds data; otherwise, NULL. */
1429 static struct type
*
1430 desc_bounds_type (struct type
*type
)
1434 type
= desc_base_type (type
);
1438 else if (is_thin_pntr (type
))
1440 type
= thin_descriptor_type (type
);
1443 r
= lookup_struct_elt_type (type
, "BOUNDS", 1);
1445 return ada_check_typedef (r
);
1447 else if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
)
1449 r
= lookup_struct_elt_type (type
, "P_BOUNDS", 1);
1451 return ada_check_typedef (TYPE_TARGET_TYPE (ada_check_typedef (r
)));
1456 /* If ARR is an array descriptor (fat or thin pointer), or pointer to
1457 one, a pointer to its bounds data. Otherwise NULL. */
1459 static struct value
*
1460 desc_bounds (struct value
*arr
)
1462 struct type
*type
= ada_check_typedef (value_type (arr
));
1463 if (is_thin_pntr (type
))
1465 struct type
*bounds_type
=
1466 desc_bounds_type (thin_descriptor_type (type
));
1469 if (bounds_type
== NULL
)
1470 error (_("Bad GNAT array descriptor"));
1472 /* NOTE: The following calculation is not really kosher, but
1473 since desc_type is an XVE-encoded type (and shouldn't be),
1474 the correct calculation is a real pain. FIXME (and fix GCC). */
1475 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
1476 addr
= value_as_long (arr
);
1478 addr
= VALUE_ADDRESS (arr
) + value_offset (arr
);
1481 value_from_longest (lookup_pointer_type (bounds_type
),
1482 addr
- TYPE_LENGTH (bounds_type
));
1485 else if (is_thick_pntr (type
))
1486 return value_struct_elt (&arr
, NULL
, "P_BOUNDS", NULL
,
1487 _("Bad GNAT array descriptor"));
1492 /* If TYPE is the type of an array-descriptor (fat pointer), the bit
1493 position of the field containing the address of the bounds data. */
1496 fat_pntr_bounds_bitpos (struct type
*type
)
1498 return TYPE_FIELD_BITPOS (desc_base_type (type
), 1);
1501 /* If TYPE is the type of an array-descriptor (fat pointer), the bit
1502 size of the field containing the address of the bounds data. */
1505 fat_pntr_bounds_bitsize (struct type
*type
)
1507 type
= desc_base_type (type
);
1509 if (TYPE_FIELD_BITSIZE (type
, 1) > 0)
1510 return TYPE_FIELD_BITSIZE (type
, 1);
1512 return 8 * TYPE_LENGTH (ada_check_typedef (TYPE_FIELD_TYPE (type
, 1)));
1515 /* If TYPE is the type of an array descriptor (fat or thin pointer) or a
1516 pointer to one, the type of its array data (a
1517 pointer-to-array-with-no-bounds type); otherwise, NULL. Use
1518 ada_type_of_array to get an array type with bounds data. */
1520 static struct type
*
1521 desc_data_type (struct type
*type
)
1523 type
= desc_base_type (type
);
1525 /* NOTE: The following is bogus; see comment in desc_bounds. */
1526 if (is_thin_pntr (type
))
1527 return lookup_pointer_type
1528 (desc_base_type (TYPE_FIELD_TYPE (thin_descriptor_type (type
), 1)));
1529 else if (is_thick_pntr (type
))
1530 return lookup_struct_elt_type (type
, "P_ARRAY", 1);
1535 /* If ARR is an array descriptor (fat or thin pointer), a pointer to
1538 static struct value
*
1539 desc_data (struct value
*arr
)
1541 struct type
*type
= value_type (arr
);
1542 if (is_thin_pntr (type
))
1543 return thin_data_pntr (arr
);
1544 else if (is_thick_pntr (type
))
1545 return value_struct_elt (&arr
, NULL
, "P_ARRAY", NULL
,
1546 _("Bad GNAT array descriptor"));
1552 /* If TYPE is the type of an array-descriptor (fat pointer), the bit
1553 position of the field containing the address of the data. */
1556 fat_pntr_data_bitpos (struct type
*type
)
1558 return TYPE_FIELD_BITPOS (desc_base_type (type
), 0);
1561 /* If TYPE is the type of an array-descriptor (fat pointer), the bit
1562 size of the field containing the address of the data. */
1565 fat_pntr_data_bitsize (struct type
*type
)
1567 type
= desc_base_type (type
);
1569 if (TYPE_FIELD_BITSIZE (type
, 0) > 0)
1570 return TYPE_FIELD_BITSIZE (type
, 0);
1572 return TARGET_CHAR_BIT
* TYPE_LENGTH (TYPE_FIELD_TYPE (type
, 0));
1575 /* If BOUNDS is an array-bounds structure (or pointer to one), return
1576 the Ith lower bound stored in it, if WHICH is 0, and the Ith upper
1577 bound, if WHICH is 1. The first bound is I=1. */
1579 static struct value
*
1580 desc_one_bound (struct value
*bounds
, int i
, int which
)
1582 return value_struct_elt (&bounds
, NULL
, bound_name
[2 * i
+ which
- 2], NULL
,
1583 _("Bad GNAT array descriptor bounds"));
1586 /* If BOUNDS is an array-bounds structure type, return the bit position
1587 of the Ith lower bound stored in it, if WHICH is 0, and the Ith upper
1588 bound, if WHICH is 1. The first bound is I=1. */
1591 desc_bound_bitpos (struct type
*type
, int i
, int which
)
1593 return TYPE_FIELD_BITPOS (desc_base_type (type
), 2 * i
+ which
- 2);
1596 /* If BOUNDS is an array-bounds structure type, return the bit field size
1597 of the Ith lower bound stored in it, if WHICH is 0, and the Ith upper
1598 bound, if WHICH is 1. The first bound is I=1. */
1601 desc_bound_bitsize (struct type
*type
, int i
, int which
)
1603 type
= desc_base_type (type
);
1605 if (TYPE_FIELD_BITSIZE (type
, 2 * i
+ which
- 2) > 0)
1606 return TYPE_FIELD_BITSIZE (type
, 2 * i
+ which
- 2);
1608 return 8 * TYPE_LENGTH (TYPE_FIELD_TYPE (type
, 2 * i
+ which
- 2));
1611 /* If TYPE is the type of an array-bounds structure, the type of its
1612 Ith bound (numbering from 1). Otherwise, NULL. */
1614 static struct type
*
1615 desc_index_type (struct type
*type
, int i
)
1617 type
= desc_base_type (type
);
1619 if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
)
1620 return lookup_struct_elt_type (type
, bound_name
[2 * i
- 2], 1);
1625 /* The number of index positions in the array-bounds type TYPE.
1626 Return 0 if TYPE is NULL. */
1629 desc_arity (struct type
*type
)
1631 type
= desc_base_type (type
);
1634 return TYPE_NFIELDS (type
) / 2;
1638 /* Non-zero iff TYPE is a simple array type (not a pointer to one) or
1639 an array descriptor type (representing an unconstrained array
1643 ada_is_direct_array_type (struct type
*type
)
1647 type
= ada_check_typedef (type
);
1648 return (TYPE_CODE (type
) == TYPE_CODE_ARRAY
1649 || ada_is_array_descriptor_type (type
));
1652 /* Non-zero iff TYPE represents any kind of array in Ada, or a pointer
1656 ada_is_array_type (struct type
*type
)
1659 && (TYPE_CODE (type
) == TYPE_CODE_PTR
1660 || TYPE_CODE (type
) == TYPE_CODE_REF
))
1661 type
= TYPE_TARGET_TYPE (type
);
1662 return ada_is_direct_array_type (type
);
1665 /* Non-zero iff TYPE is a simple array type or pointer to one. */
1668 ada_is_simple_array_type (struct type
*type
)
1672 type
= ada_check_typedef (type
);
1673 return (TYPE_CODE (type
) == TYPE_CODE_ARRAY
1674 || (TYPE_CODE (type
) == TYPE_CODE_PTR
1675 && TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_ARRAY
));
1678 /* Non-zero iff TYPE belongs to a GNAT array descriptor. */
1681 ada_is_array_descriptor_type (struct type
*type
)
1683 struct type
*data_type
= desc_data_type (type
);
1687 type
= ada_check_typedef (type
);
1690 && ((TYPE_CODE (data_type
) == TYPE_CODE_PTR
1691 && TYPE_TARGET_TYPE (data_type
) != NULL
1692 && TYPE_CODE (TYPE_TARGET_TYPE (data_type
)) == TYPE_CODE_ARRAY
)
1693 || TYPE_CODE (data_type
) == TYPE_CODE_ARRAY
)
1694 && desc_arity (desc_bounds_type (type
)) > 0;
1697 /* Non-zero iff type is a partially mal-formed GNAT array
1698 descriptor. FIXME: This is to compensate for some problems with
1699 debugging output from GNAT. Re-examine periodically to see if it
1703 ada_is_bogus_array_descriptor (struct type
*type
)
1707 && TYPE_CODE (type
) == TYPE_CODE_STRUCT
1708 && (lookup_struct_elt_type (type
, "P_BOUNDS", 1) != NULL
1709 || lookup_struct_elt_type (type
, "P_ARRAY", 1) != NULL
)
1710 && !ada_is_array_descriptor_type (type
);
1714 /* If ARR has a record type in the form of a standard GNAT array descriptor,
1715 (fat pointer) returns the type of the array data described---specifically,
1716 a pointer-to-array type. If BOUNDS is non-zero, the bounds data are filled
1717 in from the descriptor; otherwise, they are left unspecified. If
1718 the ARR denotes a null array descriptor and BOUNDS is non-zero,
1719 returns NULL. The result is simply the type of ARR if ARR is not
1722 ada_type_of_array (struct value
*arr
, int bounds
)
1724 if (ada_is_packed_array_type (value_type (arr
)))
1725 return decode_packed_array_type (value_type (arr
));
1727 if (!ada_is_array_descriptor_type (value_type (arr
)))
1728 return value_type (arr
);
1732 ada_check_typedef (TYPE_TARGET_TYPE (desc_data_type (value_type (arr
))));
1735 struct type
*elt_type
;
1737 struct value
*descriptor
;
1738 struct objfile
*objf
= TYPE_OBJFILE (value_type (arr
));
1740 elt_type
= ada_array_element_type (value_type (arr
), -1);
1741 arity
= ada_array_arity (value_type (arr
));
1743 if (elt_type
== NULL
|| arity
== 0)
1744 return ada_check_typedef (value_type (arr
));
1746 descriptor
= desc_bounds (arr
);
1747 if (value_as_long (descriptor
) == 0)
1751 struct type
*range_type
= alloc_type (objf
);
1752 struct type
*array_type
= alloc_type (objf
);
1753 struct value
*low
= desc_one_bound (descriptor
, arity
, 0);
1754 struct value
*high
= desc_one_bound (descriptor
, arity
, 1);
1757 create_range_type (range_type
, value_type (low
),
1758 longest_to_int (value_as_long (low
)),
1759 longest_to_int (value_as_long (high
)));
1760 elt_type
= create_array_type (array_type
, elt_type
, range_type
);
1763 return lookup_pointer_type (elt_type
);
1767 /* If ARR does not represent an array, returns ARR unchanged.
1768 Otherwise, returns either a standard GDB array with bounds set
1769 appropriately or, if ARR is a non-null fat pointer, a pointer to a standard
1770 GDB array. Returns NULL if ARR is a null fat pointer. */
1773 ada_coerce_to_simple_array_ptr (struct value
*arr
)
1775 if (ada_is_array_descriptor_type (value_type (arr
)))
1777 struct type
*arrType
= ada_type_of_array (arr
, 1);
1778 if (arrType
== NULL
)
1780 return value_cast (arrType
, value_copy (desc_data (arr
)));
1782 else if (ada_is_packed_array_type (value_type (arr
)))
1783 return decode_packed_array (arr
);
1788 /* If ARR does not represent an array, returns ARR unchanged.
1789 Otherwise, returns a standard GDB array describing ARR (which may
1790 be ARR itself if it already is in the proper form). */
1792 static struct value
*
1793 ada_coerce_to_simple_array (struct value
*arr
)
1795 if (ada_is_array_descriptor_type (value_type (arr
)))
1797 struct value
*arrVal
= ada_coerce_to_simple_array_ptr (arr
);
1799 error (_("Bounds unavailable for null array pointer."));
1800 check_size (TYPE_TARGET_TYPE (value_type (arrVal
)));
1801 return value_ind (arrVal
);
1803 else if (ada_is_packed_array_type (value_type (arr
)))
1804 return decode_packed_array (arr
);
1809 /* If TYPE represents a GNAT array type, return it translated to an
1810 ordinary GDB array type (possibly with BITSIZE fields indicating
1811 packing). For other types, is the identity. */
1814 ada_coerce_to_simple_array_type (struct type
*type
)
1816 struct value
*mark
= value_mark ();
1817 struct value
*dummy
= value_from_longest (builtin_type_long
, 0);
1818 struct type
*result
;
1819 deprecated_set_value_type (dummy
, type
);
1820 result
= ada_type_of_array (dummy
, 0);
1821 value_free_to_mark (mark
);
1825 /* Non-zero iff TYPE represents a standard GNAT packed-array type. */
1828 ada_is_packed_array_type (struct type
*type
)
1832 type
= desc_base_type (type
);
1833 type
= ada_check_typedef (type
);
1835 ada_type_name (type
) != NULL
1836 && strstr (ada_type_name (type
), "___XP") != NULL
;
1839 /* Given that TYPE is a standard GDB array type with all bounds filled
1840 in, and that the element size of its ultimate scalar constituents
1841 (that is, either its elements, or, if it is an array of arrays, its
1842 elements' elements, etc.) is *ELT_BITS, return an identical type,
1843 but with the bit sizes of its elements (and those of any
1844 constituent arrays) recorded in the BITSIZE components of its
1845 TYPE_FIELD_BITSIZE values, and with *ELT_BITS set to its total size
1848 static struct type
*
1849 packed_array_type (struct type
*type
, long *elt_bits
)
1851 struct type
*new_elt_type
;
1852 struct type
*new_type
;
1853 LONGEST low_bound
, high_bound
;
1855 type
= ada_check_typedef (type
);
1856 if (TYPE_CODE (type
) != TYPE_CODE_ARRAY
)
1859 new_type
= alloc_type (TYPE_OBJFILE (type
));
1860 new_elt_type
= packed_array_type (ada_check_typedef (TYPE_TARGET_TYPE (type
)),
1862 create_array_type (new_type
, new_elt_type
, TYPE_FIELD_TYPE (type
, 0));
1863 TYPE_FIELD_BITSIZE (new_type
, 0) = *elt_bits
;
1864 TYPE_NAME (new_type
) = ada_type_name (type
);
1866 if (get_discrete_bounds (TYPE_FIELD_TYPE (type
, 0),
1867 &low_bound
, &high_bound
) < 0)
1868 low_bound
= high_bound
= 0;
1869 if (high_bound
< low_bound
)
1870 *elt_bits
= TYPE_LENGTH (new_type
) = 0;
1873 *elt_bits
*= (high_bound
- low_bound
+ 1);
1874 TYPE_LENGTH (new_type
) =
1875 (*elt_bits
+ HOST_CHAR_BIT
- 1) / HOST_CHAR_BIT
;
1878 TYPE_FLAGS (new_type
) |= TYPE_FLAG_FIXED_INSTANCE
;
1882 /* The array type encoded by TYPE, where ada_is_packed_array_type (TYPE). */
1884 static struct type
*
1885 decode_packed_array_type (struct type
*type
)
1888 struct block
**blocks
;
1889 char *raw_name
= ada_type_name (ada_check_typedef (type
));
1892 struct type
*shadow_type
;
1897 raw_name
= ada_type_name (desc_base_type (type
));
1902 name
= (char *) alloca (strlen (raw_name
) + 1);
1903 tail
= strstr (raw_name
, "___XP");
1904 type
= desc_base_type (type
);
1906 memcpy (name
, raw_name
, tail
- raw_name
);
1907 name
[tail
- raw_name
] = '\000';
1909 sym
= standard_lookup (name
, get_selected_block (0), VAR_DOMAIN
);
1910 if (sym
== NULL
|| SYMBOL_TYPE (sym
) == NULL
)
1912 lim_warning (_("could not find bounds information on packed array"));
1915 shadow_type
= SYMBOL_TYPE (sym
);
1917 if (TYPE_CODE (shadow_type
) != TYPE_CODE_ARRAY
)
1919 lim_warning (_("could not understand bounds information on packed array"));
1923 if (sscanf (tail
+ sizeof ("___XP") - 1, "%ld", &bits
) != 1)
1926 (_("could not understand bit size information on packed array"));
1930 return packed_array_type (shadow_type
, &bits
);
1933 /* Given that ARR is a struct value *indicating a GNAT packed array,
1934 returns a simple array that denotes that array. Its type is a
1935 standard GDB array type except that the BITSIZEs of the array
1936 target types are set to the number of bits in each element, and the
1937 type length is set appropriately. */
1939 static struct value
*
1940 decode_packed_array (struct value
*arr
)
1944 arr
= ada_coerce_ref (arr
);
1945 if (TYPE_CODE (value_type (arr
)) == TYPE_CODE_PTR
)
1946 arr
= ada_value_ind (arr
);
1948 type
= decode_packed_array_type (value_type (arr
));
1951 error (_("can't unpack array"));
1955 if (gdbarch_bits_big_endian (current_gdbarch
)
1956 && ada_is_modular_type (value_type (arr
)))
1958 /* This is a (right-justified) modular type representing a packed
1959 array with no wrapper. In order to interpret the value through
1960 the (left-justified) packed array type we just built, we must
1961 first left-justify it. */
1962 int bit_size
, bit_pos
;
1965 mod
= ada_modulus (value_type (arr
)) - 1;
1972 bit_pos
= HOST_CHAR_BIT
* TYPE_LENGTH (value_type (arr
)) - bit_size
;
1973 arr
= ada_value_primitive_packed_val (arr
, NULL
,
1974 bit_pos
/ HOST_CHAR_BIT
,
1975 bit_pos
% HOST_CHAR_BIT
,
1980 return coerce_unspec_val_to_type (arr
, type
);
1984 /* The value of the element of packed array ARR at the ARITY indices
1985 given in IND. ARR must be a simple array. */
1987 static struct value
*
1988 value_subscript_packed (struct value
*arr
, int arity
, struct value
**ind
)
1991 int bits
, elt_off
, bit_off
;
1992 long elt_total_bit_offset
;
1993 struct type
*elt_type
;
1997 elt_total_bit_offset
= 0;
1998 elt_type
= ada_check_typedef (value_type (arr
));
1999 for (i
= 0; i
< arity
; i
+= 1)
2001 if (TYPE_CODE (elt_type
) != TYPE_CODE_ARRAY
2002 || TYPE_FIELD_BITSIZE (elt_type
, 0) == 0)
2004 (_("attempt to do packed indexing of something other than a packed array"));
2007 struct type
*range_type
= TYPE_INDEX_TYPE (elt_type
);
2008 LONGEST lowerbound
, upperbound
;
2011 if (get_discrete_bounds (range_type
, &lowerbound
, &upperbound
) < 0)
2013 lim_warning (_("don't know bounds of array"));
2014 lowerbound
= upperbound
= 0;
2017 idx
= value_as_long (value_pos_atr (ind
[i
]));
2018 if (idx
< lowerbound
|| idx
> upperbound
)
2019 lim_warning (_("packed array index %ld out of bounds"), (long) idx
);
2020 bits
= TYPE_FIELD_BITSIZE (elt_type
, 0);
2021 elt_total_bit_offset
+= (idx
- lowerbound
) * bits
;
2022 elt_type
= ada_check_typedef (TYPE_TARGET_TYPE (elt_type
));
2025 elt_off
= elt_total_bit_offset
/ HOST_CHAR_BIT
;
2026 bit_off
= elt_total_bit_offset
% HOST_CHAR_BIT
;
2028 v
= ada_value_primitive_packed_val (arr
, NULL
, elt_off
, bit_off
,
2033 /* Non-zero iff TYPE includes negative integer values. */
2036 has_negatives (struct type
*type
)
2038 switch (TYPE_CODE (type
))
2043 return !TYPE_UNSIGNED (type
);
2044 case TYPE_CODE_RANGE
:
2045 return TYPE_LOW_BOUND (type
) < 0;
2050 /* Create a new value of type TYPE from the contents of OBJ starting
2051 at byte OFFSET, and bit offset BIT_OFFSET within that byte,
2052 proceeding for BIT_SIZE bits. If OBJ is an lval in memory, then
2053 assigning through the result will set the field fetched from.
2054 VALADDR is ignored unless OBJ is NULL, in which case,
2055 VALADDR+OFFSET must address the start of storage containing the
2056 packed value. The value returned in this case is never an lval.
2057 Assumes 0 <= BIT_OFFSET < HOST_CHAR_BIT. */
2060 ada_value_primitive_packed_val (struct value
*obj
, const gdb_byte
*valaddr
,
2061 long offset
, int bit_offset
, int bit_size
,
2065 int src
, /* Index into the source area */
2066 targ
, /* Index into the target area */
2067 srcBitsLeft
, /* Number of source bits left to move */
2068 nsrc
, ntarg
, /* Number of source and target bytes */
2069 unusedLS
, /* Number of bits in next significant
2070 byte of source that are unused */
2071 accumSize
; /* Number of meaningful bits in accum */
2072 unsigned char *bytes
; /* First byte containing data to unpack */
2073 unsigned char *unpacked
;
2074 unsigned long accum
; /* Staging area for bits being transferred */
2076 int len
= (bit_size
+ bit_offset
+ HOST_CHAR_BIT
- 1) / 8;
2077 /* Transmit bytes from least to most significant; delta is the direction
2078 the indices move. */
2079 int delta
= gdbarch_bits_big_endian (current_gdbarch
) ? -1 : 1;
2081 type
= ada_check_typedef (type
);
2085 v
= allocate_value (type
);
2086 bytes
= (unsigned char *) (valaddr
+ offset
);
2088 else if (value_lazy (obj
))
2091 VALUE_ADDRESS (obj
) + value_offset (obj
) + offset
);
2092 bytes
= (unsigned char *) alloca (len
);
2093 read_memory (VALUE_ADDRESS (v
), bytes
, len
);
2097 v
= allocate_value (type
);
2098 bytes
= (unsigned char *) value_contents (obj
) + offset
;
2103 VALUE_LVAL (v
) = VALUE_LVAL (obj
);
2104 if (VALUE_LVAL (obj
) == lval_internalvar
)
2105 VALUE_LVAL (v
) = lval_internalvar_component
;
2106 VALUE_ADDRESS (v
) = VALUE_ADDRESS (obj
) + value_offset (obj
) + offset
;
2107 set_value_bitpos (v
, bit_offset
+ value_bitpos (obj
));
2108 set_value_bitsize (v
, bit_size
);
2109 if (value_bitpos (v
) >= HOST_CHAR_BIT
)
2111 VALUE_ADDRESS (v
) += 1;
2112 set_value_bitpos (v
, value_bitpos (v
) - HOST_CHAR_BIT
);
2116 set_value_bitsize (v
, bit_size
);
2117 unpacked
= (unsigned char *) value_contents (v
);
2119 srcBitsLeft
= bit_size
;
2121 ntarg
= TYPE_LENGTH (type
);
2125 memset (unpacked
, 0, TYPE_LENGTH (type
));
2128 else if (gdbarch_bits_big_endian (current_gdbarch
))
2131 if (has_negatives (type
)
2132 && ((bytes
[0] << bit_offset
) & (1 << (HOST_CHAR_BIT
- 1))))
2136 (HOST_CHAR_BIT
- (bit_size
+ bit_offset
) % HOST_CHAR_BIT
)
2139 switch (TYPE_CODE (type
))
2141 case TYPE_CODE_ARRAY
:
2142 case TYPE_CODE_UNION
:
2143 case TYPE_CODE_STRUCT
:
2144 /* Non-scalar values must be aligned at a byte boundary... */
2146 (HOST_CHAR_BIT
- bit_size
% HOST_CHAR_BIT
) % HOST_CHAR_BIT
;
2147 /* ... And are placed at the beginning (most-significant) bytes
2149 targ
= (bit_size
+ HOST_CHAR_BIT
- 1) / HOST_CHAR_BIT
- 1;
2153 targ
= TYPE_LENGTH (type
) - 1;
2159 int sign_bit_offset
= (bit_size
+ bit_offset
- 1) % 8;
2162 unusedLS
= bit_offset
;
2165 if (has_negatives (type
) && (bytes
[len
- 1] & (1 << sign_bit_offset
)))
2172 /* Mask for removing bits of the next source byte that are not
2173 part of the value. */
2174 unsigned int unusedMSMask
=
2175 (1 << (srcBitsLeft
>= HOST_CHAR_BIT
? HOST_CHAR_BIT
: srcBitsLeft
)) -
2177 /* Sign-extend bits for this byte. */
2178 unsigned int signMask
= sign
& ~unusedMSMask
;
2180 (((bytes
[src
] >> unusedLS
) & unusedMSMask
) | signMask
) << accumSize
;
2181 accumSize
+= HOST_CHAR_BIT
- unusedLS
;
2182 if (accumSize
>= HOST_CHAR_BIT
)
2184 unpacked
[targ
] = accum
& ~(~0L << HOST_CHAR_BIT
);
2185 accumSize
-= HOST_CHAR_BIT
;
2186 accum
>>= HOST_CHAR_BIT
;
2190 srcBitsLeft
-= HOST_CHAR_BIT
- unusedLS
;
2197 accum
|= sign
<< accumSize
;
2198 unpacked
[targ
] = accum
& ~(~0L << HOST_CHAR_BIT
);
2199 accumSize
-= HOST_CHAR_BIT
;
2200 accum
>>= HOST_CHAR_BIT
;
2208 /* Move N bits from SOURCE, starting at bit offset SRC_OFFSET to
2209 TARGET, starting at bit offset TARG_OFFSET. SOURCE and TARGET must
2212 move_bits (gdb_byte
*target
, int targ_offset
, const gdb_byte
*source
,
2213 int src_offset
, int n
)
2215 unsigned int accum
, mask
;
2216 int accum_bits
, chunk_size
;
2218 target
+= targ_offset
/ HOST_CHAR_BIT
;
2219 targ_offset
%= HOST_CHAR_BIT
;
2220 source
+= src_offset
/ HOST_CHAR_BIT
;
2221 src_offset
%= HOST_CHAR_BIT
;
2222 if (gdbarch_bits_big_endian (current_gdbarch
))
2224 accum
= (unsigned char) *source
;
2226 accum_bits
= HOST_CHAR_BIT
- src_offset
;
2231 accum
= (accum
<< HOST_CHAR_BIT
) + (unsigned char) *source
;
2232 accum_bits
+= HOST_CHAR_BIT
;
2234 chunk_size
= HOST_CHAR_BIT
- targ_offset
;
2237 unused_right
= HOST_CHAR_BIT
- (chunk_size
+ targ_offset
);
2238 mask
= ((1 << chunk_size
) - 1) << unused_right
;
2241 | ((accum
>> (accum_bits
- chunk_size
- unused_right
)) & mask
);
2243 accum_bits
-= chunk_size
;
2250 accum
= (unsigned char) *source
>> src_offset
;
2252 accum_bits
= HOST_CHAR_BIT
- src_offset
;
2256 accum
= accum
+ ((unsigned char) *source
<< accum_bits
);
2257 accum_bits
+= HOST_CHAR_BIT
;
2259 chunk_size
= HOST_CHAR_BIT
- targ_offset
;
2262 mask
= ((1 << chunk_size
) - 1) << targ_offset
;
2263 *target
= (*target
& ~mask
) | ((accum
<< targ_offset
) & mask
);
2265 accum_bits
-= chunk_size
;
2266 accum
>>= chunk_size
;
2273 /* Store the contents of FROMVAL into the location of TOVAL.
2274 Return a new value with the location of TOVAL and contents of
2275 FROMVAL. Handles assignment into packed fields that have
2276 floating-point or non-scalar types. */
2278 static struct value
*
2279 ada_value_assign (struct value
*toval
, struct value
*fromval
)
2281 struct type
*type
= value_type (toval
);
2282 int bits
= value_bitsize (toval
);
2284 toval
= ada_coerce_ref (toval
);
2285 fromval
= ada_coerce_ref (fromval
);
2287 if (ada_is_direct_array_type (value_type (toval
)))
2288 toval
= ada_coerce_to_simple_array (toval
);
2289 if (ada_is_direct_array_type (value_type (fromval
)))
2290 fromval
= ada_coerce_to_simple_array (fromval
);
2292 if (!deprecated_value_modifiable (toval
))
2293 error (_("Left operand of assignment is not a modifiable lvalue."));
2295 if (VALUE_LVAL (toval
) == lval_memory
2297 && (TYPE_CODE (type
) == TYPE_CODE_FLT
2298 || TYPE_CODE (type
) == TYPE_CODE_STRUCT
))
2300 int len
= (value_bitpos (toval
)
2301 + bits
+ HOST_CHAR_BIT
- 1) / HOST_CHAR_BIT
;
2302 char *buffer
= (char *) alloca (len
);
2304 CORE_ADDR to_addr
= VALUE_ADDRESS (toval
) + value_offset (toval
);
2306 if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
2307 fromval
= value_cast (type
, fromval
);
2309 read_memory (to_addr
, buffer
, len
);
2310 if (gdbarch_bits_big_endian (current_gdbarch
))
2311 move_bits (buffer
, value_bitpos (toval
),
2312 value_contents (fromval
),
2313 TYPE_LENGTH (value_type (fromval
)) * TARGET_CHAR_BIT
-
2316 move_bits (buffer
, value_bitpos (toval
), value_contents (fromval
),
2318 write_memory (to_addr
, buffer
, len
);
2319 if (deprecated_memory_changed_hook
)
2320 deprecated_memory_changed_hook (to_addr
, len
);
2322 val
= value_copy (toval
);
2323 memcpy (value_contents_raw (val
), value_contents (fromval
),
2324 TYPE_LENGTH (type
));
2325 deprecated_set_value_type (val
, type
);
2330 return value_assign (toval
, fromval
);
2334 /* Given that COMPONENT is a memory lvalue that is part of the lvalue
2335 * CONTAINER, assign the contents of VAL to COMPONENTS's place in
2336 * CONTAINER. Modifies the VALUE_CONTENTS of CONTAINER only, not
2337 * COMPONENT, and not the inferior's memory. The current contents
2338 * of COMPONENT are ignored. */
2340 value_assign_to_component (struct value
*container
, struct value
*component
,
2343 LONGEST offset_in_container
=
2344 (LONGEST
) (VALUE_ADDRESS (component
) + value_offset (component
)
2345 - VALUE_ADDRESS (container
) - value_offset (container
));
2346 int bit_offset_in_container
=
2347 value_bitpos (component
) - value_bitpos (container
);
2350 val
= value_cast (value_type (component
), val
);
2352 if (value_bitsize (component
) == 0)
2353 bits
= TARGET_CHAR_BIT
* TYPE_LENGTH (value_type (component
));
2355 bits
= value_bitsize (component
);
2357 if (gdbarch_bits_big_endian (current_gdbarch
))
2358 move_bits (value_contents_writeable (container
) + offset_in_container
,
2359 value_bitpos (container
) + bit_offset_in_container
,
2360 value_contents (val
),
2361 TYPE_LENGTH (value_type (component
)) * TARGET_CHAR_BIT
- bits
,
2364 move_bits (value_contents_writeable (container
) + offset_in_container
,
2365 value_bitpos (container
) + bit_offset_in_container
,
2366 value_contents (val
), 0, bits
);
2369 /* The value of the element of array ARR at the ARITY indices given in IND.
2370 ARR may be either a simple array, GNAT array descriptor, or pointer
2374 ada_value_subscript (struct value
*arr
, int arity
, struct value
**ind
)
2378 struct type
*elt_type
;
2380 elt
= ada_coerce_to_simple_array (arr
);
2382 elt_type
= ada_check_typedef (value_type (elt
));
2383 if (TYPE_CODE (elt_type
) == TYPE_CODE_ARRAY
2384 && TYPE_FIELD_BITSIZE (elt_type
, 0) > 0)
2385 return value_subscript_packed (elt
, arity
, ind
);
2387 for (k
= 0; k
< arity
; k
+= 1)
2389 if (TYPE_CODE (elt_type
) != TYPE_CODE_ARRAY
)
2390 error (_("too many subscripts (%d expected)"), k
);
2391 elt
= value_subscript (elt
, value_pos_atr (ind
[k
]));
2396 /* Assuming ARR is a pointer to a standard GDB array of type TYPE, the
2397 value of the element of *ARR at the ARITY indices given in
2398 IND. Does not read the entire array into memory. */
2401 ada_value_ptr_subscript (struct value
*arr
, struct type
*type
, int arity
,
2406 for (k
= 0; k
< arity
; k
+= 1)
2411 if (TYPE_CODE (type
) != TYPE_CODE_ARRAY
)
2412 error (_("too many subscripts (%d expected)"), k
);
2413 arr
= value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (type
)),
2415 get_discrete_bounds (TYPE_INDEX_TYPE (type
), &lwb
, &upb
);
2416 idx
= value_pos_atr (ind
[k
]);
2418 idx
= value_sub (idx
, value_from_longest (builtin_type_int
, lwb
));
2419 arr
= value_add (arr
, idx
);
2420 type
= TYPE_TARGET_TYPE (type
);
2423 return value_ind (arr
);
2426 /* Given that ARRAY_PTR is a pointer or reference to an array of type TYPE (the
2427 actual type of ARRAY_PTR is ignored), returns a reference to
2428 the Ada slice of HIGH-LOW+1 elements starting at index LOW. The lower
2429 bound of this array is LOW, as per Ada rules. */
2430 static struct value
*
2431 ada_value_slice_ptr (struct value
*array_ptr
, struct type
*type
,
2434 CORE_ADDR base
= value_as_address (array_ptr
)
2435 + ((low
- TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type
)))
2436 * TYPE_LENGTH (TYPE_TARGET_TYPE (type
)));
2437 struct type
*index_type
=
2438 create_range_type (NULL
, TYPE_TARGET_TYPE (TYPE_INDEX_TYPE (type
)),
2440 struct type
*slice_type
=
2441 create_array_type (NULL
, TYPE_TARGET_TYPE (type
), index_type
);
2442 return value_from_pointer (lookup_reference_type (slice_type
), base
);
2446 static struct value
*
2447 ada_value_slice (struct value
*array
, int low
, int high
)
2449 struct type
*type
= value_type (array
);
2450 struct type
*index_type
=
2451 create_range_type (NULL
, TYPE_INDEX_TYPE (type
), low
, high
);
2452 struct type
*slice_type
=
2453 create_array_type (NULL
, TYPE_TARGET_TYPE (type
), index_type
);
2454 return value_cast (slice_type
, value_slice (array
, low
, high
- low
+ 1));
2457 /* If type is a record type in the form of a standard GNAT array
2458 descriptor, returns the number of dimensions for type. If arr is a
2459 simple array, returns the number of "array of"s that prefix its
2460 type designation. Otherwise, returns 0. */
2463 ada_array_arity (struct type
*type
)
2470 type
= desc_base_type (type
);
2473 if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
)
2474 return desc_arity (desc_bounds_type (type
));
2476 while (TYPE_CODE (type
) == TYPE_CODE_ARRAY
)
2479 type
= ada_check_typedef (TYPE_TARGET_TYPE (type
));
2485 /* If TYPE is a record type in the form of a standard GNAT array
2486 descriptor or a simple array type, returns the element type for
2487 TYPE after indexing by NINDICES indices, or by all indices if
2488 NINDICES is -1. Otherwise, returns NULL. */
2491 ada_array_element_type (struct type
*type
, int nindices
)
2493 type
= desc_base_type (type
);
2495 if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
)
2498 struct type
*p_array_type
;
2500 p_array_type
= desc_data_type (type
);
2502 k
= ada_array_arity (type
);
2506 /* Initially p_array_type = elt_type(*)[]...(k times)...[]. */
2507 if (nindices
>= 0 && k
> nindices
)
2509 p_array_type
= TYPE_TARGET_TYPE (p_array_type
);
2510 while (k
> 0 && p_array_type
!= NULL
)
2512 p_array_type
= ada_check_typedef (TYPE_TARGET_TYPE (p_array_type
));
2515 return p_array_type
;
2517 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
)
2519 while (nindices
!= 0 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
)
2521 type
= TYPE_TARGET_TYPE (type
);
2530 /* The type of nth index in arrays of given type (n numbering from 1).
2531 Does not examine memory. */
2534 ada_index_type (struct type
*type
, int n
)
2536 struct type
*result_type
;
2538 type
= desc_base_type (type
);
2540 if (n
> ada_array_arity (type
))
2543 if (ada_is_simple_array_type (type
))
2547 for (i
= 1; i
< n
; i
+= 1)
2548 type
= TYPE_TARGET_TYPE (type
);
2549 result_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
, 0));
2550 /* FIXME: The stabs type r(0,0);bound;bound in an array type
2551 has a target type of TYPE_CODE_UNDEF. We compensate here, but
2552 perhaps stabsread.c would make more sense. */
2553 if (result_type
== NULL
|| TYPE_CODE (result_type
) == TYPE_CODE_UNDEF
)
2554 result_type
= builtin_type_int
;
2559 return desc_index_type (desc_bounds_type (type
), n
);
2562 /* Given that arr is an array type, returns the lower bound of the
2563 Nth index (numbering from 1) if WHICH is 0, and the upper bound if
2564 WHICH is 1. This returns bounds 0 .. -1 if ARR_TYPE is an
2565 array-descriptor type. If TYPEP is non-null, *TYPEP is set to the
2566 bounds type. It works for other arrays with bounds supplied by
2567 run-time quantities other than discriminants. */
2570 ada_array_bound_from_type (struct type
* arr_type
, int n
, int which
,
2571 struct type
** typep
)
2574 struct type
*index_type_desc
;
2576 if (ada_is_packed_array_type (arr_type
))
2577 arr_type
= decode_packed_array_type (arr_type
);
2579 if (arr_type
== NULL
|| !ada_is_simple_array_type (arr_type
))
2582 *typep
= builtin_type_int
;
2583 return (LONGEST
) - which
;
2586 if (TYPE_CODE (arr_type
) == TYPE_CODE_PTR
)
2587 type
= TYPE_TARGET_TYPE (arr_type
);
2591 index_type_desc
= ada_find_parallel_type (type
, "___XA");
2592 if (index_type_desc
== NULL
)
2594 struct type
*index_type
;
2598 type
= TYPE_TARGET_TYPE (type
);
2602 index_type
= TYPE_INDEX_TYPE (type
);
2604 *typep
= index_type
;
2606 /* The index type is either a range type or an enumerated type.
2607 For the range type, we have some macros that allow us to
2608 extract the value of the low and high bounds. But they
2609 do now work for enumerated types. The expressions used
2610 below work for both range and enum types. */
2612 (LONGEST
) (which
== 0
2613 ? TYPE_FIELD_BITPOS (index_type
, 0)
2614 : TYPE_FIELD_BITPOS (index_type
,
2615 TYPE_NFIELDS (index_type
) - 1));
2619 struct type
*index_type
=
2620 to_fixed_range_type (TYPE_FIELD_NAME (index_type_desc
, n
- 1),
2621 NULL
, TYPE_OBJFILE (arr_type
));
2624 *typep
= index_type
;
2627 (LONGEST
) (which
== 0
2628 ? TYPE_LOW_BOUND (index_type
)
2629 : TYPE_HIGH_BOUND (index_type
));
2633 /* Given that arr is an array value, returns the lower bound of the
2634 nth index (numbering from 1) if WHICH is 0, and the upper bound if
2635 WHICH is 1. This routine will also work for arrays with bounds
2636 supplied by run-time quantities other than discriminants. */
2639 ada_array_bound (struct value
*arr
, int n
, int which
)
2641 struct type
*arr_type
= value_type (arr
);
2643 if (ada_is_packed_array_type (arr_type
))
2644 return ada_array_bound (decode_packed_array (arr
), n
, which
);
2645 else if (ada_is_simple_array_type (arr_type
))
2648 LONGEST v
= ada_array_bound_from_type (arr_type
, n
, which
, &type
);
2649 return value_from_longest (type
, v
);
2652 return desc_one_bound (desc_bounds (arr
), n
, which
);
2655 /* Given that arr is an array value, returns the length of the
2656 nth index. This routine will also work for arrays with bounds
2657 supplied by run-time quantities other than discriminants.
2658 Does not work for arrays indexed by enumeration types with representation
2659 clauses at the moment. */
2662 ada_array_length (struct value
*arr
, int n
)
2664 struct type
*arr_type
= ada_check_typedef (value_type (arr
));
2666 if (ada_is_packed_array_type (arr_type
))
2667 return ada_array_length (decode_packed_array (arr
), n
);
2669 if (ada_is_simple_array_type (arr_type
))
2673 ada_array_bound_from_type (arr_type
, n
, 1, &type
) -
2674 ada_array_bound_from_type (arr_type
, n
, 0, NULL
) + 1;
2675 return value_from_longest (type
, v
);
2679 value_from_longest (builtin_type_int
,
2680 value_as_long (desc_one_bound (desc_bounds (arr
),
2682 - value_as_long (desc_one_bound (desc_bounds (arr
),
2686 /* An empty array whose type is that of ARR_TYPE (an array type),
2687 with bounds LOW to LOW-1. */
2689 static struct value
*
2690 empty_array (struct type
*arr_type
, int low
)
2692 struct type
*index_type
=
2693 create_range_type (NULL
, TYPE_TARGET_TYPE (TYPE_INDEX_TYPE (arr_type
)),
2695 struct type
*elt_type
= ada_array_element_type (arr_type
, 1);
2696 return allocate_value (create_array_type (NULL
, elt_type
, index_type
));
2700 /* Name resolution */
2702 /* The "decoded" name for the user-definable Ada operator corresponding
2706 ada_decoded_op_name (enum exp_opcode op
)
2710 for (i
= 0; ada_opname_table
[i
].encoded
!= NULL
; i
+= 1)
2712 if (ada_opname_table
[i
].op
== op
)
2713 return ada_opname_table
[i
].decoded
;
2715 error (_("Could not find operator name for opcode"));
2719 /* Same as evaluate_type (*EXP), but resolves ambiguous symbol
2720 references (marked by OP_VAR_VALUE nodes in which the symbol has an
2721 undefined namespace) and converts operators that are
2722 user-defined into appropriate function calls. If CONTEXT_TYPE is
2723 non-null, it provides a preferred result type [at the moment, only
2724 type void has any effect---causing procedures to be preferred over
2725 functions in calls]. A null CONTEXT_TYPE indicates that a non-void
2726 return type is preferred. May change (expand) *EXP. */
2729 resolve (struct expression
**expp
, int void_context_p
)
2733 resolve_subexp (expp
, &pc
, 1, void_context_p
? builtin_type_void
: NULL
);
2736 /* Resolve the operator of the subexpression beginning at
2737 position *POS of *EXPP. "Resolving" consists of replacing
2738 the symbols that have undefined namespaces in OP_VAR_VALUE nodes
2739 with their resolutions, replacing built-in operators with
2740 function calls to user-defined operators, where appropriate, and,
2741 when DEPROCEDURE_P is non-zero, converting function-valued variables
2742 into parameterless calls. May expand *EXPP. The CONTEXT_TYPE functions
2743 are as in ada_resolve, above. */
2745 static struct value
*
2746 resolve_subexp (struct expression
**expp
, int *pos
, int deprocedure_p
,
2747 struct type
*context_type
)
2751 struct expression
*exp
; /* Convenience: == *expp. */
2752 enum exp_opcode op
= (*expp
)->elts
[pc
].opcode
;
2753 struct value
**argvec
; /* Vector of operand types (alloca'ed). */
2754 int nargs
; /* Number of operands. */
2761 /* Pass one: resolve operands, saving their types and updating *pos,
2766 if (exp
->elts
[pc
+ 3].opcode
== OP_VAR_VALUE
2767 && SYMBOL_DOMAIN (exp
->elts
[pc
+ 5].symbol
) == UNDEF_DOMAIN
)
2772 resolve_subexp (expp
, pos
, 0, NULL
);
2774 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
2779 resolve_subexp (expp
, pos
, 0, NULL
);
2784 resolve_subexp (expp
, pos
, 1, exp
->elts
[pc
+ 1].type
);
2787 case OP_ATR_MODULUS
:
2797 case TERNOP_IN_RANGE
:
2798 case BINOP_IN_BOUNDS
:
2804 case OP_DISCRETE_RANGE
:
2806 ada_forward_operator_length (exp
, pc
, &oplen
, &nargs
);
2815 arg1
= resolve_subexp (expp
, pos
, 0, NULL
);
2817 resolve_subexp (expp
, pos
, 1, NULL
);
2819 resolve_subexp (expp
, pos
, 1, value_type (arg1
));
2836 case BINOP_LOGICAL_AND
:
2837 case BINOP_LOGICAL_OR
:
2838 case BINOP_BITWISE_AND
:
2839 case BINOP_BITWISE_IOR
:
2840 case BINOP_BITWISE_XOR
:
2843 case BINOP_NOTEQUAL
:
2850 case BINOP_SUBSCRIPT
:
2858 case UNOP_LOGICAL_NOT
:
2874 case OP_INTERNALVAR
:
2884 *pos
+= 4 + BYTES_TO_EXP_ELEM (exp
->elts
[pc
+ 1].longconst
+ 1);
2887 case STRUCTOP_STRUCT
:
2888 *pos
+= 4 + BYTES_TO_EXP_ELEM (exp
->elts
[pc
+ 1].longconst
+ 1);
2901 error (_("Unexpected operator during name resolution"));
2904 argvec
= (struct value
* *) alloca (sizeof (struct value
*) * (nargs
+ 1));
2905 for (i
= 0; i
< nargs
; i
+= 1)
2906 argvec
[i
] = resolve_subexp (expp
, pos
, 1, NULL
);
2910 /* Pass two: perform any resolution on principal operator. */
2917 if (SYMBOL_DOMAIN (exp
->elts
[pc
+ 2].symbol
) == UNDEF_DOMAIN
)
2919 struct ada_symbol_info
*candidates
;
2923 ada_lookup_symbol_list (SYMBOL_LINKAGE_NAME
2924 (exp
->elts
[pc
+ 2].symbol
),
2925 exp
->elts
[pc
+ 1].block
, VAR_DOMAIN
,
2928 if (n_candidates
> 1)
2930 /* Types tend to get re-introduced locally, so if there
2931 are any local symbols that are not types, first filter
2934 for (j
= 0; j
< n_candidates
; j
+= 1)
2935 switch (SYMBOL_CLASS (candidates
[j
].sym
))
2941 case LOC_REGPARM_ADDR
:
2945 case LOC_BASEREG_ARG
:
2947 case LOC_COMPUTED_ARG
:
2953 if (j
< n_candidates
)
2956 while (j
< n_candidates
)
2958 if (SYMBOL_CLASS (candidates
[j
].sym
) == LOC_TYPEDEF
)
2960 candidates
[j
] = candidates
[n_candidates
- 1];
2969 if (n_candidates
== 0)
2970 error (_("No definition found for %s"),
2971 SYMBOL_PRINT_NAME (exp
->elts
[pc
+ 2].symbol
));
2972 else if (n_candidates
== 1)
2974 else if (deprocedure_p
2975 && !is_nonfunction (candidates
, n_candidates
))
2977 i
= ada_resolve_function
2978 (candidates
, n_candidates
, NULL
, 0,
2979 SYMBOL_LINKAGE_NAME (exp
->elts
[pc
+ 2].symbol
),
2982 error (_("Could not find a match for %s"),
2983 SYMBOL_PRINT_NAME (exp
->elts
[pc
+ 2].symbol
));
2987 printf_filtered (_("Multiple matches for %s\n"),
2988 SYMBOL_PRINT_NAME (exp
->elts
[pc
+ 2].symbol
));
2989 user_select_syms (candidates
, n_candidates
, 1);
2993 exp
->elts
[pc
+ 1].block
= candidates
[i
].block
;
2994 exp
->elts
[pc
+ 2].symbol
= candidates
[i
].sym
;
2995 if (innermost_block
== NULL
2996 || contained_in (candidates
[i
].block
, innermost_block
))
2997 innermost_block
= candidates
[i
].block
;
3001 && (TYPE_CODE (SYMBOL_TYPE (exp
->elts
[pc
+ 2].symbol
))
3004 replace_operator_with_call (expp
, pc
, 0, 0,
3005 exp
->elts
[pc
+ 2].symbol
,
3006 exp
->elts
[pc
+ 1].block
);
3013 if (exp
->elts
[pc
+ 3].opcode
== OP_VAR_VALUE
3014 && SYMBOL_DOMAIN (exp
->elts
[pc
+ 5].symbol
) == UNDEF_DOMAIN
)
3016 struct ada_symbol_info
*candidates
;
3020 ada_lookup_symbol_list (SYMBOL_LINKAGE_NAME
3021 (exp
->elts
[pc
+ 5].symbol
),
3022 exp
->elts
[pc
+ 4].block
, VAR_DOMAIN
,
3024 if (n_candidates
== 1)
3028 i
= ada_resolve_function
3029 (candidates
, n_candidates
,
3031 SYMBOL_LINKAGE_NAME (exp
->elts
[pc
+ 5].symbol
),
3034 error (_("Could not find a match for %s"),
3035 SYMBOL_PRINT_NAME (exp
->elts
[pc
+ 5].symbol
));
3038 exp
->elts
[pc
+ 4].block
= candidates
[i
].block
;
3039 exp
->elts
[pc
+ 5].symbol
= candidates
[i
].sym
;
3040 if (innermost_block
== NULL
3041 || contained_in (candidates
[i
].block
, innermost_block
))
3042 innermost_block
= candidates
[i
].block
;
3053 case BINOP_BITWISE_AND
:
3054 case BINOP_BITWISE_IOR
:
3055 case BINOP_BITWISE_XOR
:
3057 case BINOP_NOTEQUAL
:
3065 case UNOP_LOGICAL_NOT
:
3067 if (possible_user_operator_p (op
, argvec
))
3069 struct ada_symbol_info
*candidates
;
3073 ada_lookup_symbol_list (ada_encode (ada_decoded_op_name (op
)),
3074 (struct block
*) NULL
, VAR_DOMAIN
,
3076 i
= ada_resolve_function (candidates
, n_candidates
, argvec
, nargs
,
3077 ada_decoded_op_name (op
), NULL
);
3081 replace_operator_with_call (expp
, pc
, nargs
, 1,
3082 candidates
[i
].sym
, candidates
[i
].block
);
3093 return evaluate_subexp_type (exp
, pos
);
3096 /* Return non-zero if formal type FTYPE matches actual type ATYPE. If
3097 MAY_DEREF is non-zero, the formal may be a pointer and the actual
3098 a non-pointer. A type of 'void' (which is never a valid expression type)
3099 by convention matches anything. */
3100 /* The term "match" here is rather loose. The match is heuristic and
3101 liberal. FIXME: TOO liberal, in fact. */
3104 ada_type_match (struct type
*ftype
, struct type
*atype
, int may_deref
)
3106 ftype
= ada_check_typedef (ftype
);
3107 atype
= ada_check_typedef (atype
);
3109 if (TYPE_CODE (ftype
) == TYPE_CODE_REF
)
3110 ftype
= TYPE_TARGET_TYPE (ftype
);
3111 if (TYPE_CODE (atype
) == TYPE_CODE_REF
)
3112 atype
= TYPE_TARGET_TYPE (atype
);
3114 if (TYPE_CODE (ftype
) == TYPE_CODE_VOID
3115 || TYPE_CODE (atype
) == TYPE_CODE_VOID
)
3118 switch (TYPE_CODE (ftype
))
3123 if (TYPE_CODE (atype
) == TYPE_CODE_PTR
)
3124 return ada_type_match (TYPE_TARGET_TYPE (ftype
),
3125 TYPE_TARGET_TYPE (atype
), 0);
3128 && ada_type_match (TYPE_TARGET_TYPE (ftype
), atype
, 0));
3130 case TYPE_CODE_ENUM
:
3131 case TYPE_CODE_RANGE
:
3132 switch (TYPE_CODE (atype
))
3135 case TYPE_CODE_ENUM
:
3136 case TYPE_CODE_RANGE
:
3142 case TYPE_CODE_ARRAY
:
3143 return (TYPE_CODE (atype
) == TYPE_CODE_ARRAY
3144 || ada_is_array_descriptor_type (atype
));
3146 case TYPE_CODE_STRUCT
:
3147 if (ada_is_array_descriptor_type (ftype
))
3148 return (TYPE_CODE (atype
) == TYPE_CODE_ARRAY
3149 || ada_is_array_descriptor_type (atype
));
3151 return (TYPE_CODE (atype
) == TYPE_CODE_STRUCT
3152 && !ada_is_array_descriptor_type (atype
));
3154 case TYPE_CODE_UNION
:
3156 return (TYPE_CODE (atype
) == TYPE_CODE (ftype
));
3160 /* Return non-zero if the formals of FUNC "sufficiently match" the
3161 vector of actual argument types ACTUALS of size N_ACTUALS. FUNC
3162 may also be an enumeral, in which case it is treated as a 0-
3163 argument function. */
3166 ada_args_match (struct symbol
*func
, struct value
**actuals
, int n_actuals
)
3169 struct type
*func_type
= SYMBOL_TYPE (func
);
3171 if (SYMBOL_CLASS (func
) == LOC_CONST
3172 && TYPE_CODE (func_type
) == TYPE_CODE_ENUM
)
3173 return (n_actuals
== 0);
3174 else if (func_type
== NULL
|| TYPE_CODE (func_type
) != TYPE_CODE_FUNC
)
3177 if (TYPE_NFIELDS (func_type
) != n_actuals
)
3180 for (i
= 0; i
< n_actuals
; i
+= 1)
3182 if (actuals
[i
] == NULL
)
3186 struct type
*ftype
= ada_check_typedef (TYPE_FIELD_TYPE (func_type
, i
));
3187 struct type
*atype
= ada_check_typedef (value_type (actuals
[i
]));
3189 if (!ada_type_match (ftype
, atype
, 1))
3196 /* False iff function type FUNC_TYPE definitely does not produce a value
3197 compatible with type CONTEXT_TYPE. Conservatively returns 1 if
3198 FUNC_TYPE is not a valid function type with a non-null return type
3199 or an enumerated type. A null CONTEXT_TYPE indicates any non-void type. */
3202 return_match (struct type
*func_type
, struct type
*context_type
)
3204 struct type
*return_type
;
3206 if (func_type
== NULL
)
3209 if (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
)
3210 return_type
= base_type (TYPE_TARGET_TYPE (func_type
));
3212 return_type
= base_type (func_type
);
3213 if (return_type
== NULL
)
3216 context_type
= base_type (context_type
);
3218 if (TYPE_CODE (return_type
) == TYPE_CODE_ENUM
)
3219 return context_type
== NULL
|| return_type
== context_type
;
3220 else if (context_type
== NULL
)
3221 return TYPE_CODE (return_type
) != TYPE_CODE_VOID
;
3223 return TYPE_CODE (return_type
) == TYPE_CODE (context_type
);
3227 /* Returns the index in SYMS[0..NSYMS-1] that contains the symbol for the
3228 function (if any) that matches the types of the NARGS arguments in
3229 ARGS. If CONTEXT_TYPE is non-null and there is at least one match
3230 that returns that type, then eliminate matches that don't. If
3231 CONTEXT_TYPE is void and there is at least one match that does not
3232 return void, eliminate all matches that do.
3234 Asks the user if there is more than one match remaining. Returns -1
3235 if there is no such symbol or none is selected. NAME is used
3236 solely for messages. May re-arrange and modify SYMS in
3237 the process; the index returned is for the modified vector. */
3240 ada_resolve_function (struct ada_symbol_info syms
[],
3241 int nsyms
, struct value
**args
, int nargs
,
3242 const char *name
, struct type
*context_type
)
3245 int m
; /* Number of hits */
3246 struct type
*fallback
;
3247 struct type
*return_type
;
3249 return_type
= context_type
;
3250 if (context_type
== NULL
)
3251 fallback
= builtin_type_void
;
3258 for (k
= 0; k
< nsyms
; k
+= 1)
3260 struct type
*type
= ada_check_typedef (SYMBOL_TYPE (syms
[k
].sym
));
3262 if (ada_args_match (syms
[k
].sym
, args
, nargs
)
3263 && return_match (type
, return_type
))
3269 if (m
> 0 || return_type
== fallback
)
3272 return_type
= fallback
;
3279 printf_filtered (_("Multiple matches for %s\n"), name
);
3280 user_select_syms (syms
, m
, 1);
3286 /* Returns true (non-zero) iff decoded name N0 should appear before N1
3287 in a listing of choices during disambiguation (see sort_choices, below).
3288 The idea is that overloadings of a subprogram name from the
3289 same package should sort in their source order. We settle for ordering
3290 such symbols by their trailing number (__N or $N). */
3293 encoded_ordered_before (char *N0
, char *N1
)
3297 else if (N0
== NULL
)
3302 for (k0
= strlen (N0
) - 1; k0
> 0 && isdigit (N0
[k0
]); k0
-= 1)
3304 for (k1
= strlen (N1
) - 1; k1
> 0 && isdigit (N1
[k1
]); k1
-= 1)
3306 if ((N0
[k0
] == '_' || N0
[k0
] == '$') && N0
[k0
+ 1] != '\000'
3307 && (N1
[k1
] == '_' || N1
[k1
] == '$') && N1
[k1
+ 1] != '\000')
3311 while (N0
[n0
] == '_' && n0
> 0 && N0
[n0
- 1] == '_')
3314 while (N1
[n1
] == '_' && n1
> 0 && N1
[n1
- 1] == '_')
3316 if (n0
== n1
&& strncmp (N0
, N1
, n0
) == 0)
3317 return (atoi (N0
+ k0
+ 1) < atoi (N1
+ k1
+ 1));
3319 return (strcmp (N0
, N1
) < 0);
3323 /* Sort SYMS[0..NSYMS-1] to put the choices in a canonical order by the
3327 sort_choices (struct ada_symbol_info syms
[], int nsyms
)
3330 for (i
= 1; i
< nsyms
; i
+= 1)
3332 struct ada_symbol_info sym
= syms
[i
];
3335 for (j
= i
- 1; j
>= 0; j
-= 1)
3337 if (encoded_ordered_before (SYMBOL_LINKAGE_NAME (syms
[j
].sym
),
3338 SYMBOL_LINKAGE_NAME (sym
.sym
)))
3340 syms
[j
+ 1] = syms
[j
];
3346 /* Given a list of NSYMS symbols in SYMS, select up to MAX_RESULTS>0
3347 by asking the user (if necessary), returning the number selected,
3348 and setting the first elements of SYMS items. Error if no symbols
3351 /* NOTE: Adapted from decode_line_2 in symtab.c, with which it ought
3352 to be re-integrated one of these days. */
3355 user_select_syms (struct ada_symbol_info
*syms
, int nsyms
, int max_results
)
3358 int *chosen
= (int *) alloca (sizeof (int) * nsyms
);
3360 int first_choice
= (max_results
== 1) ? 1 : 2;
3362 if (max_results
< 1)
3363 error (_("Request to select 0 symbols!"));
3367 printf_unfiltered (_("[0] cancel\n"));
3368 if (max_results
> 1)
3369 printf_unfiltered (_("[1] all\n"));
3371 sort_choices (syms
, nsyms
);
3373 for (i
= 0; i
< nsyms
; i
+= 1)
3375 if (syms
[i
].sym
== NULL
)
3378 if (SYMBOL_CLASS (syms
[i
].sym
) == LOC_BLOCK
)
3380 struct symtab_and_line sal
=
3381 find_function_start_sal (syms
[i
].sym
, 1);
3382 if (sal
.symtab
== NULL
)
3383 printf_unfiltered (_("[%d] %s at <no source file available>:%d\n"),
3385 SYMBOL_PRINT_NAME (syms
[i
].sym
),
3388 printf_unfiltered (_("[%d] %s at %s:%d\n"), i
+ first_choice
,
3389 SYMBOL_PRINT_NAME (syms
[i
].sym
),
3390 sal
.symtab
->filename
, sal
.line
);
3396 (SYMBOL_CLASS (syms
[i
].sym
) == LOC_CONST
3397 && SYMBOL_TYPE (syms
[i
].sym
) != NULL
3398 && TYPE_CODE (SYMBOL_TYPE (syms
[i
].sym
)) == TYPE_CODE_ENUM
);
3399 struct symtab
*symtab
= symtab_for_sym (syms
[i
].sym
);
3401 if (SYMBOL_LINE (syms
[i
].sym
) != 0 && symtab
!= NULL
)
3402 printf_unfiltered (_("[%d] %s at %s:%d\n"),
3404 SYMBOL_PRINT_NAME (syms
[i
].sym
),
3405 symtab
->filename
, SYMBOL_LINE (syms
[i
].sym
));
3406 else if (is_enumeral
3407 && TYPE_NAME (SYMBOL_TYPE (syms
[i
].sym
)) != NULL
)
3409 printf_unfiltered (("[%d] "), i
+ first_choice
);
3410 ada_print_type (SYMBOL_TYPE (syms
[i
].sym
), NULL
,
3412 printf_unfiltered (_("'(%s) (enumeral)\n"),
3413 SYMBOL_PRINT_NAME (syms
[i
].sym
));
3415 else if (symtab
!= NULL
)
3416 printf_unfiltered (is_enumeral
3417 ? _("[%d] %s in %s (enumeral)\n")
3418 : _("[%d] %s at %s:?\n"),
3420 SYMBOL_PRINT_NAME (syms
[i
].sym
),
3423 printf_unfiltered (is_enumeral
3424 ? _("[%d] %s (enumeral)\n")
3425 : _("[%d] %s at ?\n"),
3427 SYMBOL_PRINT_NAME (syms
[i
].sym
));
3431 n_chosen
= get_selections (chosen
, nsyms
, max_results
, max_results
> 1,
3434 for (i
= 0; i
< n_chosen
; i
+= 1)
3435 syms
[i
] = syms
[chosen
[i
]];
3440 /* Read and validate a set of numeric choices from the user in the
3441 range 0 .. N_CHOICES-1. Place the results in increasing
3442 order in CHOICES[0 .. N-1], and return N.
3444 The user types choices as a sequence of numbers on one line
3445 separated by blanks, encoding them as follows:
3447 + A choice of 0 means to cancel the selection, throwing an error.
3448 + If IS_ALL_CHOICE, a choice of 1 selects the entire set 0 .. N_CHOICES-1.
3449 + The user chooses k by typing k+IS_ALL_CHOICE+1.
3451 The user is not allowed to choose more than MAX_RESULTS values.
3453 ANNOTATION_SUFFIX, if present, is used to annotate the input
3454 prompts (for use with the -f switch). */
3457 get_selections (int *choices
, int n_choices
, int max_results
,
3458 int is_all_choice
, char *annotation_suffix
)
3463 int first_choice
= is_all_choice
? 2 : 1;
3465 prompt
= getenv ("PS2");
3469 printf_unfiltered (("%s "), prompt
);
3470 gdb_flush (gdb_stdout
);
3472 args
= command_line_input ((char *) NULL
, 0, annotation_suffix
);
3475 error_no_arg (_("one or more choice numbers"));
3479 /* Set choices[0 .. n_chosen-1] to the users' choices in ascending
3480 order, as given in args. Choices are validated. */
3486 while (isspace (*args
))
3488 if (*args
== '\0' && n_chosen
== 0)
3489 error_no_arg (_("one or more choice numbers"));
3490 else if (*args
== '\0')
3493 choice
= strtol (args
, &args2
, 10);
3494 if (args
== args2
|| choice
< 0
3495 || choice
> n_choices
+ first_choice
- 1)
3496 error (_("Argument must be choice number"));
3500 error (_("cancelled"));
3502 if (choice
< first_choice
)
3504 n_chosen
= n_choices
;
3505 for (j
= 0; j
< n_choices
; j
+= 1)
3509 choice
-= first_choice
;
3511 for (j
= n_chosen
- 1; j
>= 0 && choice
< choices
[j
]; j
-= 1)
3515 if (j
< 0 || choice
!= choices
[j
])
3518 for (k
= n_chosen
- 1; k
> j
; k
-= 1)
3519 choices
[k
+ 1] = choices
[k
];
3520 choices
[j
+ 1] = choice
;
3525 if (n_chosen
> max_results
)
3526 error (_("Select no more than %d of the above"), max_results
);
3531 /* Replace the operator of length OPLEN at position PC in *EXPP with a call
3532 on the function identified by SYM and BLOCK, and taking NARGS
3533 arguments. Update *EXPP as needed to hold more space. */
3536 replace_operator_with_call (struct expression
**expp
, int pc
, int nargs
,
3537 int oplen
, struct symbol
*sym
,
3538 struct block
*block
)
3540 /* A new expression, with 6 more elements (3 for funcall, 4 for function
3541 symbol, -oplen for operator being replaced). */
3542 struct expression
*newexp
= (struct expression
*)
3543 xmalloc (sizeof (struct expression
)
3544 + EXP_ELEM_TO_BYTES ((*expp
)->nelts
+ 7 - oplen
));
3545 struct expression
*exp
= *expp
;
3547 newexp
->nelts
= exp
->nelts
+ 7 - oplen
;
3548 newexp
->language_defn
= exp
->language_defn
;
3549 memcpy (newexp
->elts
, exp
->elts
, EXP_ELEM_TO_BYTES (pc
));
3550 memcpy (newexp
->elts
+ pc
+ 7, exp
->elts
+ pc
+ oplen
,
3551 EXP_ELEM_TO_BYTES (exp
->nelts
- pc
- oplen
));
3553 newexp
->elts
[pc
].opcode
= newexp
->elts
[pc
+ 2].opcode
= OP_FUNCALL
;
3554 newexp
->elts
[pc
+ 1].longconst
= (LONGEST
) nargs
;
3556 newexp
->elts
[pc
+ 3].opcode
= newexp
->elts
[pc
+ 6].opcode
= OP_VAR_VALUE
;
3557 newexp
->elts
[pc
+ 4].block
= block
;
3558 newexp
->elts
[pc
+ 5].symbol
= sym
;
3564 /* Type-class predicates */
3566 /* True iff TYPE is numeric (i.e., an INT, RANGE (of numeric type),
3570 numeric_type_p (struct type
*type
)
3576 switch (TYPE_CODE (type
))
3581 case TYPE_CODE_RANGE
:
3582 return (type
== TYPE_TARGET_TYPE (type
)
3583 || numeric_type_p (TYPE_TARGET_TYPE (type
)));
3590 /* True iff TYPE is integral (an INT or RANGE of INTs). */
3593 integer_type_p (struct type
*type
)
3599 switch (TYPE_CODE (type
))
3603 case TYPE_CODE_RANGE
:
3604 return (type
== TYPE_TARGET_TYPE (type
)
3605 || integer_type_p (TYPE_TARGET_TYPE (type
)));
3612 /* True iff TYPE is scalar (INT, RANGE, FLOAT, ENUM). */
3615 scalar_type_p (struct type
*type
)
3621 switch (TYPE_CODE (type
))
3624 case TYPE_CODE_RANGE
:
3625 case TYPE_CODE_ENUM
:
3634 /* True iff TYPE is discrete (INT, RANGE, ENUM). */
3637 discrete_type_p (struct type
*type
)
3643 switch (TYPE_CODE (type
))
3646 case TYPE_CODE_RANGE
:
3647 case TYPE_CODE_ENUM
:
3655 /* Returns non-zero if OP with operands in the vector ARGS could be
3656 a user-defined function. Errs on the side of pre-defined operators
3657 (i.e., result 0). */
3660 possible_user_operator_p (enum exp_opcode op
, struct value
*args
[])
3662 struct type
*type0
=
3663 (args
[0] == NULL
) ? NULL
: ada_check_typedef (value_type (args
[0]));
3664 struct type
*type1
=
3665 (args
[1] == NULL
) ? NULL
: ada_check_typedef (value_type (args
[1]));
3679 return (!(numeric_type_p (type0
) && numeric_type_p (type1
)));
3683 case BINOP_BITWISE_AND
:
3684 case BINOP_BITWISE_IOR
:
3685 case BINOP_BITWISE_XOR
:
3686 return (!(integer_type_p (type0
) && integer_type_p (type1
)));
3689 case BINOP_NOTEQUAL
:
3694 return (!(scalar_type_p (type0
) && scalar_type_p (type1
)));
3697 return !ada_is_array_type (type0
) || !ada_is_array_type (type1
);
3700 return (!(numeric_type_p (type0
) && integer_type_p (type1
)));
3704 case UNOP_LOGICAL_NOT
:
3706 return (!numeric_type_p (type0
));
3715 1. In the following, we assume that a renaming type's name may
3716 have an ___XD suffix. It would be nice if this went away at some
3718 2. We handle both the (old) purely type-based representation of
3719 renamings and the (new) variable-based encoding. At some point,
3720 it is devoutly to be hoped that the former goes away
3721 (FIXME: hilfinger-2007-07-09).
3722 3. Subprogram renamings are not implemented, although the XRS
3723 suffix is recognized (FIXME: hilfinger-2007-07-09). */
3725 /* If SYM encodes a renaming,
3727 <renaming> renames <renamed entity>,
3729 sets *LEN to the length of the renamed entity's name,
3730 *RENAMED_ENTITY to that name (not null-terminated), and *RENAMING_EXPR to
3731 the string describing the subcomponent selected from the renamed
3732 entity. Returns ADA_NOT_RENAMING if SYM does not encode a renaming
3733 (in which case, the values of *RENAMED_ENTITY, *LEN, and *RENAMING_EXPR
3734 are undefined). Otherwise, returns a value indicating the category
3735 of entity renamed: an object (ADA_OBJECT_RENAMING), exception
3736 (ADA_EXCEPTION_RENAMING), package (ADA_PACKAGE_RENAMING), or
3737 subprogram (ADA_SUBPROGRAM_RENAMING). Does no allocation; the
3738 strings returned in *RENAMED_ENTITY and *RENAMING_EXPR should not be
3739 deallocated. The values of RENAMED_ENTITY, LEN, or RENAMING_EXPR
3740 may be NULL, in which case they are not assigned.
3742 [Currently, however, GCC does not generate subprogram renamings.] */
3744 enum ada_renaming_category
3745 ada_parse_renaming (struct symbol
*sym
,
3746 const char **renamed_entity
, int *len
,
3747 const char **renaming_expr
)
3749 enum ada_renaming_category kind
;
3754 return ADA_NOT_RENAMING
;
3755 switch (SYMBOL_CLASS (sym
))
3758 return ADA_NOT_RENAMING
;
3760 return parse_old_style_renaming (SYMBOL_TYPE (sym
),
3761 renamed_entity
, len
, renaming_expr
);
3765 case LOC_OPTIMIZED_OUT
:
3766 info
= strstr (SYMBOL_LINKAGE_NAME (sym
), "___XR");
3768 return ADA_NOT_RENAMING
;
3772 kind
= ADA_OBJECT_RENAMING
;
3776 kind
= ADA_EXCEPTION_RENAMING
;
3780 kind
= ADA_PACKAGE_RENAMING
;
3784 kind
= ADA_SUBPROGRAM_RENAMING
;
3788 return ADA_NOT_RENAMING
;
3792 if (renamed_entity
!= NULL
)
3793 *renamed_entity
= info
;
3794 suffix
= strstr (info
, "___XE");
3795 if (suffix
== NULL
|| suffix
== info
)
3796 return ADA_NOT_RENAMING
;
3798 *len
= strlen (info
) - strlen (suffix
);
3800 if (renaming_expr
!= NULL
)
3801 *renaming_expr
= suffix
;
3805 /* Assuming TYPE encodes a renaming according to the old encoding in
3806 exp_dbug.ads, returns details of that renaming in *RENAMED_ENTITY,
3807 *LEN, and *RENAMING_EXPR, as for ada_parse_renaming, above. Returns
3808 ADA_NOT_RENAMING otherwise. */
3809 static enum ada_renaming_category
3810 parse_old_style_renaming (struct type
*type
,
3811 const char **renamed_entity
, int *len
,
3812 const char **renaming_expr
)
3814 enum ada_renaming_category kind
;
3819 if (type
== NULL
|| TYPE_CODE (type
) != TYPE_CODE_ENUM
3820 || TYPE_NFIELDS (type
) != 1)
3821 return ADA_NOT_RENAMING
;
3823 name
= type_name_no_tag (type
);
3825 return ADA_NOT_RENAMING
;
3827 name
= strstr (name
, "___XR");
3829 return ADA_NOT_RENAMING
;
3834 kind
= ADA_OBJECT_RENAMING
;
3837 kind
= ADA_EXCEPTION_RENAMING
;
3840 kind
= ADA_PACKAGE_RENAMING
;
3843 kind
= ADA_SUBPROGRAM_RENAMING
;
3846 return ADA_NOT_RENAMING
;
3849 info
= TYPE_FIELD_NAME (type
, 0);
3851 return ADA_NOT_RENAMING
;
3852 if (renamed_entity
!= NULL
)
3853 *renamed_entity
= info
;
3854 suffix
= strstr (info
, "___XE");
3855 if (renaming_expr
!= NULL
)
3856 *renaming_expr
= suffix
+ 5;
3857 if (suffix
== NULL
|| suffix
== info
)
3858 return ADA_NOT_RENAMING
;
3860 *len
= suffix
- info
;
3866 /* Evaluation: Function Calls */
3868 /* Return an lvalue containing the value VAL. This is the identity on
3869 lvalues, and otherwise has the side-effect of pushing a copy of VAL
3870 on the stack, using and updating *SP as the stack pointer, and
3871 returning an lvalue whose VALUE_ADDRESS points to the copy. */
3873 static struct value
*
3874 ensure_lval (struct value
*val
, CORE_ADDR
*sp
)
3876 if (! VALUE_LVAL (val
))
3878 int len
= TYPE_LENGTH (ada_check_typedef (value_type (val
)));
3880 /* The following is taken from the structure-return code in
3881 call_function_by_hand. FIXME: Therefore, some refactoring seems
3883 if (gdbarch_inner_than (current_gdbarch
, 1, 2))
3885 /* Stack grows downward. Align SP and VALUE_ADDRESS (val) after
3886 reserving sufficient space. */
3888 if (gdbarch_frame_align_p (current_gdbarch
))
3889 *sp
= gdbarch_frame_align (current_gdbarch
, *sp
);
3890 VALUE_ADDRESS (val
) = *sp
;
3894 /* Stack grows upward. Align the frame, allocate space, and
3895 then again, re-align the frame. */
3896 if (gdbarch_frame_align_p (current_gdbarch
))
3897 *sp
= gdbarch_frame_align (current_gdbarch
, *sp
);
3898 VALUE_ADDRESS (val
) = *sp
;
3900 if (gdbarch_frame_align_p (current_gdbarch
))
3901 *sp
= gdbarch_frame_align (current_gdbarch
, *sp
);
3903 VALUE_LVAL (val
) = lval_memory
;
3905 write_memory (VALUE_ADDRESS (val
), value_contents_raw (val
), len
);
3911 /* Return the value ACTUAL, converted to be an appropriate value for a
3912 formal of type FORMAL_TYPE. Use *SP as a stack pointer for
3913 allocating any necessary descriptors (fat pointers), or copies of
3914 values not residing in memory, updating it as needed. */
3917 ada_convert_actual (struct value
*actual
, struct type
*formal_type0
,
3920 struct type
*actual_type
= ada_check_typedef (value_type (actual
));
3921 struct type
*formal_type
= ada_check_typedef (formal_type0
);
3922 struct type
*formal_target
=
3923 TYPE_CODE (formal_type
) == TYPE_CODE_PTR
3924 ? ada_check_typedef (TYPE_TARGET_TYPE (formal_type
)) : formal_type
;
3925 struct type
*actual_target
=
3926 TYPE_CODE (actual_type
) == TYPE_CODE_PTR
3927 ? ada_check_typedef (TYPE_TARGET_TYPE (actual_type
)) : actual_type
;
3929 if (ada_is_array_descriptor_type (formal_target
)
3930 && TYPE_CODE (actual_target
) == TYPE_CODE_ARRAY
)
3931 return make_array_descriptor (formal_type
, actual
, sp
);
3932 else if (TYPE_CODE (formal_type
) == TYPE_CODE_PTR
3933 || TYPE_CODE (formal_type
) == TYPE_CODE_REF
)
3935 struct value
*result
;
3936 if (TYPE_CODE (formal_target
) == TYPE_CODE_ARRAY
3937 && ada_is_array_descriptor_type (actual_target
))
3938 result
= desc_data (actual
);
3939 else if (TYPE_CODE (actual_type
) != TYPE_CODE_PTR
)
3941 if (VALUE_LVAL (actual
) != lval_memory
)
3944 actual_type
= ada_check_typedef (value_type (actual
));
3945 val
= allocate_value (actual_type
);
3946 memcpy ((char *) value_contents_raw (val
),
3947 (char *) value_contents (actual
),
3948 TYPE_LENGTH (actual_type
));
3949 actual
= ensure_lval (val
, sp
);
3951 result
= value_addr (actual
);
3955 return value_cast_pointers (formal_type
, result
);
3957 else if (TYPE_CODE (actual_type
) == TYPE_CODE_PTR
)
3958 return ada_value_ind (actual
);
3964 /* Push a descriptor of type TYPE for array value ARR on the stack at
3965 *SP, updating *SP to reflect the new descriptor. Return either
3966 an lvalue representing the new descriptor, or (if TYPE is a pointer-
3967 to-descriptor type rather than a descriptor type), a struct value *
3968 representing a pointer to this descriptor. */
3970 static struct value
*
3971 make_array_descriptor (struct type
*type
, struct value
*arr
, CORE_ADDR
*sp
)
3973 struct type
*bounds_type
= desc_bounds_type (type
);
3974 struct type
*desc_type
= desc_base_type (type
);
3975 struct value
*descriptor
= allocate_value (desc_type
);
3976 struct value
*bounds
= allocate_value (bounds_type
);
3979 for (i
= ada_array_arity (ada_check_typedef (value_type (arr
))); i
> 0; i
-= 1)
3981 modify_general_field (value_contents_writeable (bounds
),
3982 value_as_long (ada_array_bound (arr
, i
, 0)),
3983 desc_bound_bitpos (bounds_type
, i
, 0),
3984 desc_bound_bitsize (bounds_type
, i
, 0));
3985 modify_general_field (value_contents_writeable (bounds
),
3986 value_as_long (ada_array_bound (arr
, i
, 1)),
3987 desc_bound_bitpos (bounds_type
, i
, 1),
3988 desc_bound_bitsize (bounds_type
, i
, 1));
3991 bounds
= ensure_lval (bounds
, sp
);
3993 modify_general_field (value_contents_writeable (descriptor
),
3994 VALUE_ADDRESS (ensure_lval (arr
, sp
)),
3995 fat_pntr_data_bitpos (desc_type
),
3996 fat_pntr_data_bitsize (desc_type
));
3998 modify_general_field (value_contents_writeable (descriptor
),
3999 VALUE_ADDRESS (bounds
),
4000 fat_pntr_bounds_bitpos (desc_type
),
4001 fat_pntr_bounds_bitsize (desc_type
));
4003 descriptor
= ensure_lval (descriptor
, sp
);
4005 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
4006 return value_addr (descriptor
);
4011 /* Dummy definitions for an experimental caching module that is not
4012 * used in the public sources. */
4015 lookup_cached_symbol (const char *name
, domain_enum
namespace,
4016 struct symbol
**sym
, struct block
**block
,
4017 struct symtab
**symtab
)
4023 cache_symbol (const char *name
, domain_enum
namespace, struct symbol
*sym
,
4024 struct block
*block
, struct symtab
*symtab
)
4030 /* Return the result of a standard (literal, C-like) lookup of NAME in
4031 given DOMAIN, visible from lexical block BLOCK. */
4033 static struct symbol
*
4034 standard_lookup (const char *name
, const struct block
*block
,
4038 struct symtab
*symtab
;
4040 if (lookup_cached_symbol (name
, domain
, &sym
, NULL
, NULL
))
4043 lookup_symbol_in_language (name
, block
, domain
, language_c
, 0, &symtab
);
4044 cache_symbol (name
, domain
, sym
, block_found
, symtab
);
4049 /* Non-zero iff there is at least one non-function/non-enumeral symbol
4050 in the symbol fields of SYMS[0..N-1]. We treat enumerals as functions,
4051 since they contend in overloading in the same way. */
4053 is_nonfunction (struct ada_symbol_info syms
[], int n
)
4057 for (i
= 0; i
< n
; i
+= 1)
4058 if (TYPE_CODE (SYMBOL_TYPE (syms
[i
].sym
)) != TYPE_CODE_FUNC
4059 && (TYPE_CODE (SYMBOL_TYPE (syms
[i
].sym
)) != TYPE_CODE_ENUM
4060 || SYMBOL_CLASS (syms
[i
].sym
) != LOC_CONST
))
4066 /* If true (non-zero), then TYPE0 and TYPE1 represent equivalent
4067 struct types. Otherwise, they may not. */
4070 equiv_types (struct type
*type0
, struct type
*type1
)
4074 if (type0
== NULL
|| type1
== NULL
4075 || TYPE_CODE (type0
) != TYPE_CODE (type1
))
4077 if ((TYPE_CODE (type0
) == TYPE_CODE_STRUCT
4078 || TYPE_CODE (type0
) == TYPE_CODE_ENUM
)
4079 && ada_type_name (type0
) != NULL
&& ada_type_name (type1
) != NULL
4080 && strcmp (ada_type_name (type0
), ada_type_name (type1
)) == 0)
4086 /* True iff SYM0 represents the same entity as SYM1, or one that is
4087 no more defined than that of SYM1. */
4090 lesseq_defined_than (struct symbol
*sym0
, struct symbol
*sym1
)
4094 if (SYMBOL_DOMAIN (sym0
) != SYMBOL_DOMAIN (sym1
)
4095 || SYMBOL_CLASS (sym0
) != SYMBOL_CLASS (sym1
))
4098 switch (SYMBOL_CLASS (sym0
))
4104 struct type
*type0
= SYMBOL_TYPE (sym0
);
4105 struct type
*type1
= SYMBOL_TYPE (sym1
);
4106 char *name0
= SYMBOL_LINKAGE_NAME (sym0
);
4107 char *name1
= SYMBOL_LINKAGE_NAME (sym1
);
4108 int len0
= strlen (name0
);
4110 TYPE_CODE (type0
) == TYPE_CODE (type1
)
4111 && (equiv_types (type0
, type1
)
4112 || (len0
< strlen (name1
) && strncmp (name0
, name1
, len0
) == 0
4113 && strncmp (name1
+ len0
, "___XV", 5) == 0));
4116 return SYMBOL_VALUE (sym0
) == SYMBOL_VALUE (sym1
)
4117 && equiv_types (SYMBOL_TYPE (sym0
), SYMBOL_TYPE (sym1
));
4123 /* Append (SYM,BLOCK,SYMTAB) to the end of the array of struct ada_symbol_info
4124 records in OBSTACKP. Do nothing if SYM is a duplicate. */
4127 add_defn_to_vec (struct obstack
*obstackp
,
4129 struct block
*block
, struct symtab
*symtab
)
4133 struct ada_symbol_info
*prevDefns
= defns_collected (obstackp
, 0);
4135 /* Do not try to complete stub types, as the debugger is probably
4136 already scanning all symbols matching a certain name at the
4137 time when this function is called. Trying to replace the stub
4138 type by its associated full type will cause us to restart a scan
4139 which may lead to an infinite recursion. Instead, the client
4140 collecting the matching symbols will end up collecting several
4141 matches, with at least one of them complete. It can then filter
4142 out the stub ones if needed. */
4144 for (i
= num_defns_collected (obstackp
) - 1; i
>= 0; i
-= 1)
4146 if (lesseq_defined_than (sym
, prevDefns
[i
].sym
))
4148 else if (lesseq_defined_than (prevDefns
[i
].sym
, sym
))
4150 prevDefns
[i
].sym
= sym
;
4151 prevDefns
[i
].block
= block
;
4152 prevDefns
[i
].symtab
= symtab
;
4158 struct ada_symbol_info info
;
4162 info
.symtab
= symtab
;
4163 obstack_grow (obstackp
, &info
, sizeof (struct ada_symbol_info
));
4167 /* Number of ada_symbol_info structures currently collected in
4168 current vector in *OBSTACKP. */
4171 num_defns_collected (struct obstack
*obstackp
)
4173 return obstack_object_size (obstackp
) / sizeof (struct ada_symbol_info
);
4176 /* Vector of ada_symbol_info structures currently collected in current
4177 vector in *OBSTACKP. If FINISH, close off the vector and return
4178 its final address. */
4180 static struct ada_symbol_info
*
4181 defns_collected (struct obstack
*obstackp
, int finish
)
4184 return obstack_finish (obstackp
);
4186 return (struct ada_symbol_info
*) obstack_base (obstackp
);
4189 /* Look, in partial_symtab PST, for symbol NAME in given namespace.
4190 Check the global symbols if GLOBAL, the static symbols if not.
4191 Do wild-card match if WILD. */
4193 static struct partial_symbol
*
4194 ada_lookup_partial_symbol (struct partial_symtab
*pst
, const char *name
,
4195 int global
, domain_enum
namespace, int wild
)
4197 struct partial_symbol
**start
;
4198 int name_len
= strlen (name
);
4199 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
4208 pst
->objfile
->global_psymbols
.list
+ pst
->globals_offset
:
4209 pst
->objfile
->static_psymbols
.list
+ pst
->statics_offset
);
4213 for (i
= 0; i
< length
; i
+= 1)
4215 struct partial_symbol
*psym
= start
[i
];
4217 if (SYMBOL_DOMAIN (psym
) == namespace
4218 && wild_match (name
, name_len
, SYMBOL_LINKAGE_NAME (psym
)))
4232 int M
= (U
+ i
) >> 1;
4233 struct partial_symbol
*psym
= start
[M
];
4234 if (SYMBOL_LINKAGE_NAME (psym
)[0] < name
[0])
4236 else if (SYMBOL_LINKAGE_NAME (psym
)[0] > name
[0])
4238 else if (strcmp (SYMBOL_LINKAGE_NAME (psym
), name
) < 0)
4249 struct partial_symbol
*psym
= start
[i
];
4251 if (SYMBOL_DOMAIN (psym
) == namespace)
4253 int cmp
= strncmp (name
, SYMBOL_LINKAGE_NAME (psym
), name_len
);
4261 && is_name_suffix (SYMBOL_LINKAGE_NAME (psym
)
4275 int M
= (U
+ i
) >> 1;
4276 struct partial_symbol
*psym
= start
[M
];
4277 if (SYMBOL_LINKAGE_NAME (psym
)[0] < '_')
4279 else if (SYMBOL_LINKAGE_NAME (psym
)[0] > '_')
4281 else if (strcmp (SYMBOL_LINKAGE_NAME (psym
), "_ada_") < 0)
4292 struct partial_symbol
*psym
= start
[i
];
4294 if (SYMBOL_DOMAIN (psym
) == namespace)
4298 cmp
= (int) '_' - (int) SYMBOL_LINKAGE_NAME (psym
)[0];
4301 cmp
= strncmp ("_ada_", SYMBOL_LINKAGE_NAME (psym
), 5);
4303 cmp
= strncmp (name
, SYMBOL_LINKAGE_NAME (psym
) + 5,
4313 && is_name_suffix (SYMBOL_LINKAGE_NAME (psym
)
4323 /* Find a symbol table containing symbol SYM or NULL if none. */
4325 static struct symtab
*
4326 symtab_for_sym (struct symbol
*sym
)
4329 struct objfile
*objfile
;
4331 struct symbol
*tmp_sym
;
4332 struct dict_iterator iter
;
4335 ALL_PRIMARY_SYMTABS (objfile
, s
)
4337 switch (SYMBOL_CLASS (sym
))
4345 case LOC_CONST_BYTES
:
4346 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
);
4347 ALL_BLOCK_SYMBOLS (b
, iter
, tmp_sym
) if (sym
== tmp_sym
)
4349 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
);
4350 ALL_BLOCK_SYMBOLS (b
, iter
, tmp_sym
) if (sym
== tmp_sym
)
4356 switch (SYMBOL_CLASS (sym
))
4362 case LOC_REGPARM_ADDR
:
4367 case LOC_BASEREG_ARG
:
4369 case LOC_COMPUTED_ARG
:
4370 for (j
= FIRST_LOCAL_BLOCK
;
4371 j
< BLOCKVECTOR_NBLOCKS (BLOCKVECTOR (s
)); j
+= 1)
4373 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), j
);
4374 ALL_BLOCK_SYMBOLS (b
, iter
, tmp_sym
) if (sym
== tmp_sym
)
4385 /* Return a minimal symbol matching NAME according to Ada decoding
4386 rules. Returns NULL if there is no such minimal symbol. Names
4387 prefixed with "standard__" are handled specially: "standard__" is
4388 first stripped off, and only static and global symbols are searched. */
4390 struct minimal_symbol
*
4391 ada_lookup_simple_minsym (const char *name
)
4393 struct objfile
*objfile
;
4394 struct minimal_symbol
*msymbol
;
4397 if (strncmp (name
, "standard__", sizeof ("standard__") - 1) == 0)
4399 name
+= sizeof ("standard__") - 1;
4403 wild_match
= (strstr (name
, "__") == NULL
);
4405 ALL_MSYMBOLS (objfile
, msymbol
)
4407 if (ada_match_name (SYMBOL_LINKAGE_NAME (msymbol
), name
, wild_match
)
4408 && MSYMBOL_TYPE (msymbol
) != mst_solib_trampoline
)
4415 /* For all subprograms that statically enclose the subprogram of the
4416 selected frame, add symbols matching identifier NAME in DOMAIN
4417 and their blocks to the list of data in OBSTACKP, as for
4418 ada_add_block_symbols (q.v.). If WILD, treat as NAME with a
4422 add_symbols_from_enclosing_procs (struct obstack
*obstackp
,
4423 const char *name
, domain_enum
namespace,
4428 /* True if TYPE is definitely an artificial type supplied to a symbol
4429 for which no debugging information was given in the symbol file. */
4432 is_nondebugging_type (struct type
*type
)
4434 char *name
= ada_type_name (type
);
4435 return (name
!= NULL
&& strcmp (name
, "<variable, no debug info>") == 0);
4438 /* Remove any non-debugging symbols in SYMS[0 .. NSYMS-1] that definitely
4439 duplicate other symbols in the list (The only case I know of where
4440 this happens is when object files containing stabs-in-ecoff are
4441 linked with files containing ordinary ecoff debugging symbols (or no
4442 debugging symbols)). Modifies SYMS to squeeze out deleted entries.
4443 Returns the number of items in the modified list. */
4446 remove_extra_symbols (struct ada_symbol_info
*syms
, int nsyms
)
4453 if (SYMBOL_LINKAGE_NAME (syms
[i
].sym
) != NULL
4454 && SYMBOL_CLASS (syms
[i
].sym
) == LOC_STATIC
4455 && is_nondebugging_type (SYMBOL_TYPE (syms
[i
].sym
)))
4457 for (j
= 0; j
< nsyms
; j
+= 1)
4460 && SYMBOL_LINKAGE_NAME (syms
[j
].sym
) != NULL
4461 && strcmp (SYMBOL_LINKAGE_NAME (syms
[i
].sym
),
4462 SYMBOL_LINKAGE_NAME (syms
[j
].sym
)) == 0
4463 && SYMBOL_CLASS (syms
[i
].sym
) == SYMBOL_CLASS (syms
[j
].sym
)
4464 && SYMBOL_VALUE_ADDRESS (syms
[i
].sym
)
4465 == SYMBOL_VALUE_ADDRESS (syms
[j
].sym
))
4468 for (k
= i
+ 1; k
< nsyms
; k
+= 1)
4469 syms
[k
- 1] = syms
[k
];
4482 /* Given a type that corresponds to a renaming entity, use the type name
4483 to extract the scope (package name or function name, fully qualified,
4484 and following the GNAT encoding convention) where this renaming has been
4485 defined. The string returned needs to be deallocated after use. */
4488 xget_renaming_scope (struct type
*renaming_type
)
4490 /* The renaming types adhere to the following convention:
4491 <scope>__<rename>___<XR extension>.
4492 So, to extract the scope, we search for the "___XR" extension,
4493 and then backtrack until we find the first "__". */
4495 const char *name
= type_name_no_tag (renaming_type
);
4496 char *suffix
= strstr (name
, "___XR");
4501 /* Now, backtrack a bit until we find the first "__". Start looking
4502 at suffix - 3, as the <rename> part is at least one character long. */
4504 for (last
= suffix
- 3; last
> name
; last
--)
4505 if (last
[0] == '_' && last
[1] == '_')
4508 /* Make a copy of scope and return it. */
4510 scope_len
= last
- name
;
4511 scope
= (char *) xmalloc ((scope_len
+ 1) * sizeof (char));
4513 strncpy (scope
, name
, scope_len
);
4514 scope
[scope_len
] = '\0';
4519 /* Return nonzero if NAME corresponds to a package name. */
4522 is_package_name (const char *name
)
4524 /* Here, We take advantage of the fact that no symbols are generated
4525 for packages, while symbols are generated for each function.
4526 So the condition for NAME represent a package becomes equivalent
4527 to NAME not existing in our list of symbols. There is only one
4528 small complication with library-level functions (see below). */
4532 /* If it is a function that has not been defined at library level,
4533 then we should be able to look it up in the symbols. */
4534 if (standard_lookup (name
, NULL
, VAR_DOMAIN
) != NULL
)
4537 /* Library-level function names start with "_ada_". See if function
4538 "_ada_" followed by NAME can be found. */
4540 /* Do a quick check that NAME does not contain "__", since library-level
4541 functions names cannot contain "__" in them. */
4542 if (strstr (name
, "__") != NULL
)
4545 fun_name
= xstrprintf ("_ada_%s", name
);
4547 return (standard_lookup (fun_name
, NULL
, VAR_DOMAIN
) == NULL
);
4550 /* Return nonzero if SYM corresponds to a renaming entity that is
4551 not visible from FUNCTION_NAME. */
4554 old_renaming_is_invisible (const struct symbol
*sym
, char *function_name
)
4558 if (SYMBOL_CLASS (sym
) != LOC_TYPEDEF
)
4561 scope
= xget_renaming_scope (SYMBOL_TYPE (sym
));
4563 make_cleanup (xfree
, scope
);
4565 /* If the rename has been defined in a package, then it is visible. */
4566 if (is_package_name (scope
))
4569 /* Check that the rename is in the current function scope by checking
4570 that its name starts with SCOPE. */
4572 /* If the function name starts with "_ada_", it means that it is
4573 a library-level function. Strip this prefix before doing the
4574 comparison, as the encoding for the renaming does not contain
4576 if (strncmp (function_name
, "_ada_", 5) == 0)
4579 return (strncmp (function_name
, scope
, strlen (scope
)) != 0);
4582 /* Remove entries from SYMS that corresponds to a renaming entity that
4583 is not visible from the function associated with CURRENT_BLOCK or
4584 that is superfluous due to the presence of more specific renaming
4585 information. Places surviving symbols in the initial entries of
4586 SYMS and returns the number of surviving symbols.
4589 First, in cases where an object renaming is implemented as a
4590 reference variable, GNAT may produce both the actual reference
4591 variable and the renaming encoding. In this case, we discard the
4594 Second, GNAT emits a type following a specified encoding for each renaming
4595 entity. Unfortunately, STABS currently does not support the definition
4596 of types that are local to a given lexical block, so all renamings types
4597 are emitted at library level. As a consequence, if an application
4598 contains two renaming entities using the same name, and a user tries to
4599 print the value of one of these entities, the result of the ada symbol
4600 lookup will also contain the wrong renaming type.
4602 This function partially covers for this limitation by attempting to
4603 remove from the SYMS list renaming symbols that should be visible
4604 from CURRENT_BLOCK. However, there does not seem be a 100% reliable
4605 method with the current information available. The implementation
4606 below has a couple of limitations (FIXME: brobecker-2003-05-12):
4608 - When the user tries to print a rename in a function while there
4609 is another rename entity defined in a package: Normally, the
4610 rename in the function has precedence over the rename in the
4611 package, so the latter should be removed from the list. This is
4612 currently not the case.
4614 - This function will incorrectly remove valid renames if
4615 the CURRENT_BLOCK corresponds to a function which symbol name
4616 has been changed by an "Export" pragma. As a consequence,
4617 the user will be unable to print such rename entities. */
4620 remove_irrelevant_renamings (struct ada_symbol_info
*syms
,
4621 int nsyms
, const struct block
*current_block
)
4623 struct symbol
*current_function
;
4624 char *current_function_name
;
4626 int is_new_style_renaming
;
4628 /* If there is both a renaming foo___XR... encoded as a variable and
4629 a simple variable foo in the same block, discard the latter.
4630 First, zero out such symbols, then compress. */
4631 is_new_style_renaming
= 0;
4632 for (i
= 0; i
< nsyms
; i
+= 1)
4634 struct symbol
*sym
= syms
[i
].sym
;
4635 struct block
*block
= syms
[i
].block
;
4639 if (sym
== NULL
|| SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
4641 name
= SYMBOL_LINKAGE_NAME (sym
);
4642 suffix
= strstr (name
, "___XR");
4646 int name_len
= suffix
- name
;
4648 is_new_style_renaming
= 1;
4649 for (j
= 0; j
< nsyms
; j
+= 1)
4650 if (i
!= j
&& syms
[j
].sym
!= NULL
4651 && strncmp (name
, SYMBOL_LINKAGE_NAME (syms
[j
].sym
),
4653 && block
== syms
[j
].block
)
4657 if (is_new_style_renaming
)
4661 for (j
= k
= 0; j
< nsyms
; j
+= 1)
4662 if (syms
[j
].sym
!= NULL
)
4670 /* Extract the function name associated to CURRENT_BLOCK.
4671 Abort if unable to do so. */
4673 if (current_block
== NULL
)
4676 current_function
= block_function (current_block
);
4677 if (current_function
== NULL
)
4680 current_function_name
= SYMBOL_LINKAGE_NAME (current_function
);
4681 if (current_function_name
== NULL
)
4684 /* Check each of the symbols, and remove it from the list if it is
4685 a type corresponding to a renaming that is out of the scope of
4686 the current block. */
4691 if (ada_parse_renaming (syms
[i
].sym
, NULL
, NULL
, NULL
)
4692 == ADA_OBJECT_RENAMING
4693 && old_renaming_is_invisible (syms
[i
].sym
, current_function_name
))
4696 for (j
= i
+ 1; j
< nsyms
; j
+= 1)
4697 syms
[j
- 1] = syms
[j
];
4707 /* Find symbols in DOMAIN matching NAME0, in BLOCK0 and enclosing
4708 scope and in global scopes, returning the number of matches. Sets
4709 *RESULTS to point to a vector of (SYM,BLOCK,SYMTAB) triples,
4710 indicating the symbols found and the blocks and symbol tables (if
4711 any) in which they were found. This vector are transient---good only to
4712 the next call of ada_lookup_symbol_list. Any non-function/non-enumeral
4713 symbol match within the nest of blocks whose innermost member is BLOCK0,
4714 is the one match returned (no other matches in that or
4715 enclosing blocks is returned). If there are any matches in or
4716 surrounding BLOCK0, then these alone are returned. Otherwise, the
4717 search extends to global and file-scope (static) symbol tables.
4718 Names prefixed with "standard__" are handled specially: "standard__"
4719 is first stripped off, and only static and global symbols are searched. */
4722 ada_lookup_symbol_list (const char *name0
, const struct block
*block0
,
4723 domain_enum
namespace,
4724 struct ada_symbol_info
**results
)
4728 struct partial_symtab
*ps
;
4729 struct blockvector
*bv
;
4730 struct objfile
*objfile
;
4731 struct block
*block
;
4733 struct minimal_symbol
*msymbol
;
4739 obstack_free (&symbol_list_obstack
, NULL
);
4740 obstack_init (&symbol_list_obstack
);
4744 /* Search specified block and its superiors. */
4746 wild_match
= (strstr (name0
, "__") == NULL
);
4748 block
= (struct block
*) block0
; /* FIXME: No cast ought to be
4749 needed, but adding const will
4750 have a cascade effect. */
4751 if (strncmp (name0
, "standard__", sizeof ("standard__") - 1) == 0)
4755 name
= name0
+ sizeof ("standard__") - 1;
4759 while (block
!= NULL
)
4762 ada_add_block_symbols (&symbol_list_obstack
, block
, name
,
4763 namespace, NULL
, NULL
, wild_match
);
4765 /* If we found a non-function match, assume that's the one. */
4766 if (is_nonfunction (defns_collected (&symbol_list_obstack
, 0),
4767 num_defns_collected (&symbol_list_obstack
)))
4770 block
= BLOCK_SUPERBLOCK (block
);
4773 /* If no luck so far, try to find NAME as a local symbol in some lexically
4774 enclosing subprogram. */
4775 if (num_defns_collected (&symbol_list_obstack
) == 0 && block_depth
> 2)
4776 add_symbols_from_enclosing_procs (&symbol_list_obstack
,
4777 name
, namespace, wild_match
);
4779 /* If we found ANY matches among non-global symbols, we're done. */
4781 if (num_defns_collected (&symbol_list_obstack
) > 0)
4785 if (lookup_cached_symbol (name0
, namespace, &sym
, &block
, &s
))
4788 add_defn_to_vec (&symbol_list_obstack
, sym
, block
, s
);
4792 /* Now add symbols from all global blocks: symbol tables, minimal symbol
4793 tables, and psymtab's. */
4795 ALL_PRIMARY_SYMTABS (objfile
, s
)
4798 bv
= BLOCKVECTOR (s
);
4799 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
4800 ada_add_block_symbols (&symbol_list_obstack
, block
, name
, namespace,
4801 objfile
, s
, wild_match
);
4804 if (namespace == VAR_DOMAIN
)
4806 ALL_MSYMBOLS (objfile
, msymbol
)
4808 if (ada_match_name (SYMBOL_LINKAGE_NAME (msymbol
), name
, wild_match
))
4810 switch (MSYMBOL_TYPE (msymbol
))
4812 case mst_solib_trampoline
:
4815 s
= find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol
));
4818 int ndefns0
= num_defns_collected (&symbol_list_obstack
);
4820 bv
= BLOCKVECTOR (s
);
4821 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
4822 ada_add_block_symbols (&symbol_list_obstack
, block
,
4823 SYMBOL_LINKAGE_NAME (msymbol
),
4824 namespace, objfile
, s
, wild_match
);
4826 if (num_defns_collected (&symbol_list_obstack
) == ndefns0
)
4828 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
4829 ada_add_block_symbols (&symbol_list_obstack
, block
,
4830 SYMBOL_LINKAGE_NAME (msymbol
),
4831 namespace, objfile
, s
,
4840 ALL_PSYMTABS (objfile
, ps
)
4844 && ada_lookup_partial_symbol (ps
, name
, 1, namespace, wild_match
))
4846 s
= PSYMTAB_TO_SYMTAB (ps
);
4849 bv
= BLOCKVECTOR (s
);
4850 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
4851 ada_add_block_symbols (&symbol_list_obstack
, block
, name
,
4852 namespace, objfile
, s
, wild_match
);
4856 /* Now add symbols from all per-file blocks if we've gotten no hits
4857 (Not strictly correct, but perhaps better than an error).
4858 Do the symtabs first, then check the psymtabs. */
4860 if (num_defns_collected (&symbol_list_obstack
) == 0)
4863 ALL_PRIMARY_SYMTABS (objfile
, s
)
4866 bv
= BLOCKVECTOR (s
);
4867 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
4868 ada_add_block_symbols (&symbol_list_obstack
, block
, name
, namespace,
4869 objfile
, s
, wild_match
);
4872 ALL_PSYMTABS (objfile
, ps
)
4876 && ada_lookup_partial_symbol (ps
, name
, 0, namespace, wild_match
))
4878 s
= PSYMTAB_TO_SYMTAB (ps
);
4879 bv
= BLOCKVECTOR (s
);
4882 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
4883 ada_add_block_symbols (&symbol_list_obstack
, block
, name
,
4884 namespace, objfile
, s
, wild_match
);
4890 ndefns
= num_defns_collected (&symbol_list_obstack
);
4891 *results
= defns_collected (&symbol_list_obstack
, 1);
4893 ndefns
= remove_extra_symbols (*results
, ndefns
);
4896 cache_symbol (name0
, namespace, NULL
, NULL
, NULL
);
4898 if (ndefns
== 1 && cacheIfUnique
)
4899 cache_symbol (name0
, namespace, (*results
)[0].sym
, (*results
)[0].block
,
4900 (*results
)[0].symtab
);
4902 ndefns
= remove_irrelevant_renamings (*results
, ndefns
, block0
);
4908 ada_lookup_encoded_symbol (const char *name
, const struct block
*block0
,
4909 domain_enum
namespace,
4910 struct block
**block_found
, struct symtab
**symtab
)
4912 struct ada_symbol_info
*candidates
;
4915 n_candidates
= ada_lookup_symbol_list (name
, block0
, namespace, &candidates
);
4917 if (n_candidates
== 0)
4920 if (block_found
!= NULL
)
4921 *block_found
= candidates
[0].block
;
4925 *symtab
= candidates
[0].symtab
;
4926 if (*symtab
== NULL
&& candidates
[0].block
!= NULL
)
4928 struct objfile
*objfile
;
4931 struct blockvector
*bv
;
4933 /* Search the list of symtabs for one which contains the
4934 address of the start of this block. */
4935 ALL_PRIMARY_SYMTABS (objfile
, s
)
4937 bv
= BLOCKVECTOR (s
);
4938 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
4939 if (BLOCK_START (b
) <= BLOCK_START (candidates
[0].block
)
4940 && BLOCK_END (b
) > BLOCK_START (candidates
[0].block
))
4943 return fixup_symbol_section (candidates
[0].sym
, objfile
);
4946 /* FIXME: brobecker/2004-11-12: I think that we should never
4947 reach this point. I don't see a reason why we would not
4948 find a symtab for a given block, so I suggest raising an
4949 internal_error exception here. Otherwise, we end up
4950 returning a symbol but no symtab, which certain parts of
4951 the code that rely (indirectly) on this function do not
4952 expect, eventually causing a SEGV. */
4953 return fixup_symbol_section (candidates
[0].sym
, NULL
);
4956 return candidates
[0].sym
;
4959 /* Return a symbol in DOMAIN matching NAME, in BLOCK0 and enclosing
4960 scope and in global scopes, or NULL if none. NAME is folded and
4961 encoded first. Otherwise, the result is as for ada_lookup_symbol_list,
4962 choosing the first symbol if there are multiple choices.
4963 *IS_A_FIELD_OF_THIS is set to 0 and *SYMTAB is set to the symbol
4964 table in which the symbol was found (in both cases, these
4965 assignments occur only if the pointers are non-null). */
4967 ada_lookup_symbol (const char *name
, const struct block
*block0
,
4968 domain_enum
namespace, int *is_a_field_of_this
,
4969 struct symtab
**symtab
)
4971 if (is_a_field_of_this
!= NULL
)
4972 *is_a_field_of_this
= 0;
4975 ada_lookup_encoded_symbol (ada_encode (ada_fold_name (name
)),
4976 block0
, namespace, NULL
, symtab
);
4979 static struct symbol
*
4980 ada_lookup_symbol_nonlocal (const char *name
,
4981 const char *linkage_name
,
4982 const struct block
*block
,
4983 const domain_enum domain
, struct symtab
**symtab
)
4985 if (linkage_name
== NULL
)
4986 linkage_name
= name
;
4987 return ada_lookup_symbol (linkage_name
, block_static_block (block
), domain
,
4992 /* True iff STR is a possible encoded suffix of a normal Ada name
4993 that is to be ignored for matching purposes. Suffixes of parallel
4994 names (e.g., XVE) are not included here. Currently, the possible suffixes
4995 are given by either of the regular expression:
4997 [.$][0-9]+ [nested subprogram suffix, on platforms such as GNU/Linux]
4998 ___[0-9]+ [nested subprogram suffix, on platforms such as HP/UX]
4999 _E[0-9]+[bs]$ [protected object entry suffixes]
5000 (X[nb]*)?((\$|__)[0-9](_?[0-9]+)|___(JM|LJM|X([FDBUP].*|R[^T]?)))?$
5002 Also, any leading "__[0-9]+" sequence is skipped before the suffix
5003 match is performed. This sequence is used to differentiate homonyms,
5004 is an optional part of a valid name suffix. */
5007 is_name_suffix (const char *str
)
5010 const char *matching
;
5011 const int len
= strlen (str
);
5013 /* Skip optional leading __[0-9]+. */
5015 if (len
> 3 && str
[0] == '_' && str
[1] == '_' && isdigit (str
[2]))
5018 while (isdigit (str
[0]))
5024 if (str
[0] == '.' || str
[0] == '$')
5027 while (isdigit (matching
[0]))
5029 if (matching
[0] == '\0')
5035 if (len
> 3 && str
[0] == '_' && str
[1] == '_' && str
[2] == '_')
5038 while (isdigit (matching
[0]))
5040 if (matching
[0] == '\0')
5045 /* FIXME: brobecker/2005-09-23: Protected Object subprograms end
5046 with a N at the end. Unfortunately, the compiler uses the same
5047 convention for other internal types it creates. So treating
5048 all entity names that end with an "N" as a name suffix causes
5049 some regressions. For instance, consider the case of an enumerated
5050 type. To support the 'Image attribute, it creates an array whose
5052 Having a single character like this as a suffix carrying some
5053 information is a bit risky. Perhaps we should change the encoding
5054 to be something like "_N" instead. In the meantime, do not do
5055 the following check. */
5056 /* Protected Object Subprograms */
5057 if (len
== 1 && str
[0] == 'N')
5062 if (len
> 3 && str
[0] == '_' && str
[1] == 'E' && isdigit (str
[2]))
5065 while (isdigit (matching
[0]))
5067 if ((matching
[0] == 'b' || matching
[0] == 's')
5068 && matching
[1] == '\0')
5072 /* ??? We should not modify STR directly, as we are doing below. This
5073 is fine in this case, but may become problematic later if we find
5074 that this alternative did not work, and want to try matching
5075 another one from the begining of STR. Since we modified it, we
5076 won't be able to find the begining of the string anymore! */
5080 while (str
[0] != '_' && str
[0] != '\0')
5082 if (str
[0] != 'n' && str
[0] != 'b')
5088 if (str
[0] == '\000')
5093 if (str
[1] != '_' || str
[2] == '\000')
5097 if (strcmp (str
+ 3, "JM") == 0)
5099 /* FIXME: brobecker/2004-09-30: GNAT will soon stop using
5100 the LJM suffix in favor of the JM one. But we will
5101 still accept LJM as a valid suffix for a reasonable
5102 amount of time, just to allow ourselves to debug programs
5103 compiled using an older version of GNAT. */
5104 if (strcmp (str
+ 3, "LJM") == 0)
5108 if (str
[4] == 'F' || str
[4] == 'D' || str
[4] == 'B'
5109 || str
[4] == 'U' || str
[4] == 'P')
5111 if (str
[4] == 'R' && str
[5] != 'T')
5115 if (!isdigit (str
[2]))
5117 for (k
= 3; str
[k
] != '\0'; k
+= 1)
5118 if (!isdigit (str
[k
]) && str
[k
] != '_')
5122 if (str
[0] == '$' && isdigit (str
[1]))
5124 for (k
= 2; str
[k
] != '\0'; k
+= 1)
5125 if (!isdigit (str
[k
]) && str
[k
] != '_')
5132 /* Return nonzero if the given string starts with a dot ('.')
5133 followed by zero or more digits.
5135 Note: brobecker/2003-11-10: A forward declaration has not been
5136 added at the begining of this file yet, because this function
5137 is only used to work around a problem found during wild matching
5138 when trying to match minimal symbol names against symbol names
5139 obtained from dwarf-2 data. This function is therefore currently
5140 only used in wild_match() and is likely to be deleted when the
5141 problem in dwarf-2 is fixed. */
5144 is_dot_digits_suffix (const char *str
)
5150 while (isdigit (str
[0]))
5152 return (str
[0] == '\0');
5155 /* Return non-zero if the string starting at NAME and ending before
5156 NAME_END contains no capital letters. */
5159 is_valid_name_for_wild_match (const char *name0
)
5161 const char *decoded_name
= ada_decode (name0
);
5164 for (i
=0; decoded_name
[i
] != '\0'; i
++)
5165 if (isalpha (decoded_name
[i
]) && !islower (decoded_name
[i
]))
5171 /* True if NAME represents a name of the form A1.A2....An, n>=1 and
5172 PATN[0..PATN_LEN-1] = Ak.Ak+1.....An for some k >= 1. Ignores
5173 informational suffixes of NAME (i.e., for which is_name_suffix is
5177 wild_match (const char *patn0
, int patn_len
, const char *name0
)
5184 /* FIXME: brobecker/2003-11-10: For some reason, the symbol name
5185 stored in the symbol table for nested function names is sometimes
5186 different from the name of the associated entity stored in
5187 the dwarf-2 data: This is the case for nested subprograms, where
5188 the minimal symbol name contains a trailing ".[:digit:]+" suffix,
5189 while the symbol name from the dwarf-2 data does not.
5191 Although the DWARF-2 standard documents that entity names stored
5192 in the dwarf-2 data should be identical to the name as seen in
5193 the source code, GNAT takes a different approach as we already use
5194 a special encoding mechanism to convey the information so that
5195 a C debugger can still use the information generated to debug
5196 Ada programs. A corollary is that the symbol names in the dwarf-2
5197 data should match the names found in the symbol table. I therefore
5198 consider this issue as a compiler defect.
5200 Until the compiler is properly fixed, we work-around the problem
5201 by ignoring such suffixes during the match. We do so by making
5202 a copy of PATN0 and NAME0, and then by stripping such a suffix
5203 if present. We then perform the match on the resulting strings. */
5206 name_len
= strlen (name0
);
5208 name
= name_start
= (char *) alloca ((name_len
+ 1) * sizeof (char));
5209 strcpy (name
, name0
);
5210 dot
= strrchr (name
, '.');
5211 if (dot
!= NULL
&& is_dot_digits_suffix (dot
))
5214 patn
= (char *) alloca ((patn_len
+ 1) * sizeof (char));
5215 strncpy (patn
, patn0
, patn_len
);
5216 patn
[patn_len
] = '\0';
5217 dot
= strrchr (patn
, '.');
5218 if (dot
!= NULL
&& is_dot_digits_suffix (dot
))
5221 patn_len
= dot
- patn
;
5225 /* Now perform the wild match. */
5227 name_len
= strlen (name
);
5228 if (name_len
>= patn_len
+ 5 && strncmp (name
, "_ada_", 5) == 0
5229 && strncmp (patn
, name
+ 5, patn_len
) == 0
5230 && is_name_suffix (name
+ patn_len
+ 5))
5233 while (name_len
>= patn_len
)
5235 if (strncmp (patn
, name
, patn_len
) == 0
5236 && is_name_suffix (name
+ patn_len
))
5237 return (name
== name_start
|| is_valid_name_for_wild_match (name0
));
5244 && name
[0] != '.' && (name
[0] != '_' || name
[1] != '_'));
5249 if (!islower (name
[2]))
5256 if (!islower (name
[1]))
5267 /* Add symbols from BLOCK matching identifier NAME in DOMAIN to
5268 vector *defn_symbols, updating the list of symbols in OBSTACKP
5269 (if necessary). If WILD, treat as NAME with a wildcard prefix.
5270 OBJFILE is the section containing BLOCK.
5271 SYMTAB is recorded with each symbol added. */
5274 ada_add_block_symbols (struct obstack
*obstackp
,
5275 struct block
*block
, const char *name
,
5276 domain_enum domain
, struct objfile
*objfile
,
5277 struct symtab
*symtab
, int wild
)
5279 struct dict_iterator iter
;
5280 int name_len
= strlen (name
);
5281 /* A matching argument symbol, if any. */
5282 struct symbol
*arg_sym
;
5283 /* Set true when we find a matching non-argument symbol. */
5292 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
5294 if (SYMBOL_DOMAIN (sym
) == domain
5295 && wild_match (name
, name_len
, SYMBOL_LINKAGE_NAME (sym
)))
5297 switch (SYMBOL_CLASS (sym
))
5303 case LOC_REGPARM_ADDR
:
5304 case LOC_BASEREG_ARG
:
5305 case LOC_COMPUTED_ARG
:
5308 case LOC_UNRESOLVED
:
5312 add_defn_to_vec (obstackp
,
5313 fixup_symbol_section (sym
, objfile
),
5322 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
5324 if (SYMBOL_DOMAIN (sym
) == domain
)
5326 int cmp
= strncmp (name
, SYMBOL_LINKAGE_NAME (sym
), name_len
);
5328 && is_name_suffix (SYMBOL_LINKAGE_NAME (sym
) + name_len
))
5330 switch (SYMBOL_CLASS (sym
))
5336 case LOC_REGPARM_ADDR
:
5337 case LOC_BASEREG_ARG
:
5338 case LOC_COMPUTED_ARG
:
5341 case LOC_UNRESOLVED
:
5345 add_defn_to_vec (obstackp
,
5346 fixup_symbol_section (sym
, objfile
),
5355 if (!found_sym
&& arg_sym
!= NULL
)
5357 add_defn_to_vec (obstackp
,
5358 fixup_symbol_section (arg_sym
, objfile
),
5367 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
5369 if (SYMBOL_DOMAIN (sym
) == domain
)
5373 cmp
= (int) '_' - (int) SYMBOL_LINKAGE_NAME (sym
)[0];
5376 cmp
= strncmp ("_ada_", SYMBOL_LINKAGE_NAME (sym
), 5);
5378 cmp
= strncmp (name
, SYMBOL_LINKAGE_NAME (sym
) + 5,
5383 && is_name_suffix (SYMBOL_LINKAGE_NAME (sym
) + name_len
+ 5))
5385 switch (SYMBOL_CLASS (sym
))
5391 case LOC_REGPARM_ADDR
:
5392 case LOC_BASEREG_ARG
:
5393 case LOC_COMPUTED_ARG
:
5396 case LOC_UNRESOLVED
:
5400 add_defn_to_vec (obstackp
,
5401 fixup_symbol_section (sym
, objfile
),
5409 /* NOTE: This really shouldn't be needed for _ada_ symbols.
5410 They aren't parameters, right? */
5411 if (!found_sym
&& arg_sym
!= NULL
)
5413 add_defn_to_vec (obstackp
,
5414 fixup_symbol_section (arg_sym
, objfile
),
5421 /* Symbol Completion */
5423 /* If SYM_NAME is a completion candidate for TEXT, return this symbol
5424 name in a form that's appropriate for the completion. The result
5425 does not need to be deallocated, but is only good until the next call.
5427 TEXT_LEN is equal to the length of TEXT.
5428 Perform a wild match if WILD_MATCH is set.
5429 ENCODED should be set if TEXT represents the start of a symbol name
5430 in its encoded form. */
5433 symbol_completion_match (const char *sym_name
,
5434 const char *text
, int text_len
,
5435 int wild_match
, int encoded
)
5438 const int verbatim_match
= (text
[0] == '<');
5443 /* Strip the leading angle bracket. */
5448 /* First, test against the fully qualified name of the symbol. */
5450 if (strncmp (sym_name
, text
, text_len
) == 0)
5453 if (match
&& !encoded
)
5455 /* One needed check before declaring a positive match is to verify
5456 that iff we are doing a verbatim match, the decoded version
5457 of the symbol name starts with '<'. Otherwise, this symbol name
5458 is not a suitable completion. */
5459 const char *sym_name_copy
= sym_name
;
5460 int has_angle_bracket
;
5462 sym_name
= ada_decode (sym_name
);
5463 has_angle_bracket
= (sym_name
[0] == '<');
5464 match
= (has_angle_bracket
== verbatim_match
);
5465 sym_name
= sym_name_copy
;
5468 if (match
&& !verbatim_match
)
5470 /* When doing non-verbatim match, another check that needs to
5471 be done is to verify that the potentially matching symbol name
5472 does not include capital letters, because the ada-mode would
5473 not be able to understand these symbol names without the
5474 angle bracket notation. */
5477 for (tmp
= sym_name
; *tmp
!= '\0' && !isupper (*tmp
); tmp
++);
5482 /* Second: Try wild matching... */
5484 if (!match
&& wild_match
)
5486 /* Since we are doing wild matching, this means that TEXT
5487 may represent an unqualified symbol name. We therefore must
5488 also compare TEXT against the unqualified name of the symbol. */
5489 sym_name
= ada_unqualified_name (ada_decode (sym_name
));
5491 if (strncmp (sym_name
, text
, text_len
) == 0)
5495 /* Finally: If we found a mach, prepare the result to return. */
5501 sym_name
= add_angle_brackets (sym_name
);
5504 sym_name
= ada_decode (sym_name
);
5509 /* A companion function to ada_make_symbol_completion_list().
5510 Check if SYM_NAME represents a symbol which name would be suitable
5511 to complete TEXT (TEXT_LEN is the length of TEXT), in which case
5512 it is appended at the end of the given string vector SV.
5514 ORIG_TEXT is the string original string from the user command
5515 that needs to be completed. WORD is the entire command on which
5516 completion should be performed. These two parameters are used to
5517 determine which part of the symbol name should be added to the
5519 if WILD_MATCH is set, then wild matching is performed.
5520 ENCODED should be set if TEXT represents a symbol name in its
5521 encoded formed (in which case the completion should also be
5525 symbol_completion_add (struct string_vector
*sv
,
5526 const char *sym_name
,
5527 const char *text
, int text_len
,
5528 const char *orig_text
, const char *word
,
5529 int wild_match
, int encoded
)
5531 const char *match
= symbol_completion_match (sym_name
, text
, text_len
,
5532 wild_match
, encoded
);
5538 /* We found a match, so add the appropriate completion to the given
5541 if (word
== orig_text
)
5543 completion
= xmalloc (strlen (match
) + 5);
5544 strcpy (completion
, match
);
5546 else if (word
> orig_text
)
5548 /* Return some portion of sym_name. */
5549 completion
= xmalloc (strlen (match
) + 5);
5550 strcpy (completion
, match
+ (word
- orig_text
));
5554 /* Return some of ORIG_TEXT plus sym_name. */
5555 completion
= xmalloc (strlen (match
) + (orig_text
- word
) + 5);
5556 strncpy (completion
, word
, orig_text
- word
);
5557 completion
[orig_text
- word
] = '\0';
5558 strcat (completion
, match
);
5561 string_vector_append (sv
, completion
);
5564 /* Return a list of possible symbol names completing TEXT0. The list
5565 is NULL terminated. WORD is the entire command on which completion
5569 ada_make_symbol_completion_list (char *text0
, char *word
)
5575 struct string_vector result
= new_string_vector (128);
5578 struct partial_symtab
*ps
;
5579 struct minimal_symbol
*msymbol
;
5580 struct objfile
*objfile
;
5581 struct block
*b
, *surrounding_static_block
= 0;
5583 struct dict_iterator iter
;
5585 if (text0
[0] == '<')
5587 text
= xstrdup (text0
);
5588 make_cleanup (xfree
, text
);
5589 text_len
= strlen (text
);
5595 text
= xstrdup (ada_encode (text0
));
5596 make_cleanup (xfree
, text
);
5597 text_len
= strlen (text
);
5598 for (i
= 0; i
< text_len
; i
++)
5599 text
[i
] = tolower (text
[i
]);
5601 encoded
= (strstr (text0
, "__") != NULL
);
5602 /* If the name contains a ".", then the user is entering a fully
5603 qualified entity name, and the match must not be done in wild
5604 mode. Similarly, if the user wants to complete what looks like
5605 an encoded name, the match must not be done in wild mode. */
5606 wild_match
= (strchr (text0
, '.') == NULL
&& !encoded
);
5609 /* First, look at the partial symtab symbols. */
5610 ALL_PSYMTABS (objfile
, ps
)
5612 struct partial_symbol
**psym
;
5614 /* If the psymtab's been read in we'll get it when we search
5615 through the blockvector. */
5619 for (psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
5620 psym
< (objfile
->global_psymbols
.list
+ ps
->globals_offset
5621 + ps
->n_global_syms
); psym
++)
5624 symbol_completion_add (&result
, SYMBOL_LINKAGE_NAME (*psym
),
5625 text
, text_len
, text0
, word
,
5626 wild_match
, encoded
);
5629 for (psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
5630 psym
< (objfile
->static_psymbols
.list
+ ps
->statics_offset
5631 + ps
->n_static_syms
); psym
++)
5634 symbol_completion_add (&result
, SYMBOL_LINKAGE_NAME (*psym
),
5635 text
, text_len
, text0
, word
,
5636 wild_match
, encoded
);
5640 /* At this point scan through the misc symbol vectors and add each
5641 symbol you find to the list. Eventually we want to ignore
5642 anything that isn't a text symbol (everything else will be
5643 handled by the psymtab code above). */
5645 ALL_MSYMBOLS (objfile
, msymbol
)
5648 symbol_completion_add (&result
, SYMBOL_LINKAGE_NAME (msymbol
),
5649 text
, text_len
, text0
, word
, wild_match
, encoded
);
5652 /* Search upwards from currently selected frame (so that we can
5653 complete on local vars. */
5655 for (b
= get_selected_block (0); b
!= NULL
; b
= BLOCK_SUPERBLOCK (b
))
5657 if (!BLOCK_SUPERBLOCK (b
))
5658 surrounding_static_block
= b
; /* For elmin of dups */
5660 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
5662 symbol_completion_add (&result
, SYMBOL_LINKAGE_NAME (sym
),
5663 text
, text_len
, text0
, word
,
5664 wild_match
, encoded
);
5668 /* Go through the symtabs and check the externs and statics for
5669 symbols which match. */
5671 ALL_SYMTABS (objfile
, s
)
5674 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
);
5675 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
5677 symbol_completion_add (&result
, SYMBOL_LINKAGE_NAME (sym
),
5678 text
, text_len
, text0
, word
,
5679 wild_match
, encoded
);
5683 ALL_SYMTABS (objfile
, s
)
5686 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
);
5687 /* Don't do this block twice. */
5688 if (b
== surrounding_static_block
)
5690 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
5692 symbol_completion_add (&result
, SYMBOL_LINKAGE_NAME (sym
),
5693 text
, text_len
, text0
, word
,
5694 wild_match
, encoded
);
5698 /* Append the closing NULL entry. */
5699 string_vector_append (&result
, NULL
);
5701 return (result
.array
);
5706 /* Return non-zero if TYPE is a pointer to the GNAT dispatch table used
5707 for tagged types. */
5710 ada_is_dispatch_table_ptr_type (struct type
*type
)
5714 if (TYPE_CODE (type
) != TYPE_CODE_PTR
)
5717 name
= TYPE_NAME (TYPE_TARGET_TYPE (type
));
5721 return (strcmp (name
, "ada__tags__dispatch_table") == 0);
5724 /* True if field number FIELD_NUM in struct or union type TYPE is supposed
5725 to be invisible to users. */
5728 ada_is_ignored_field (struct type
*type
, int field_num
)
5730 if (field_num
< 0 || field_num
> TYPE_NFIELDS (type
))
5733 /* Check the name of that field. */
5735 const char *name
= TYPE_FIELD_NAME (type
, field_num
);
5737 /* Anonymous field names should not be printed.
5738 brobecker/2007-02-20: I don't think this can actually happen
5739 but we don't want to print the value of annonymous fields anyway. */
5743 /* A field named "_parent" is internally generated by GNAT for
5744 tagged types, and should not be printed either. */
5745 if (name
[0] == '_' && strncmp (name
, "_parent", 7) != 0)
5749 /* If this is the dispatch table of a tagged type, then ignore. */
5750 if (ada_is_tagged_type (type
, 1)
5751 && ada_is_dispatch_table_ptr_type (TYPE_FIELD_TYPE (type
, field_num
)))
5754 /* Not a special field, so it should not be ignored. */
5758 /* True iff TYPE has a tag field. If REFOK, then TYPE may also be a
5759 pointer or reference type whose ultimate target has a tag field. */
5762 ada_is_tagged_type (struct type
*type
, int refok
)
5764 return (ada_lookup_struct_elt_type (type
, "_tag", refok
, 1, NULL
) != NULL
);
5767 /* True iff TYPE represents the type of X'Tag */
5770 ada_is_tag_type (struct type
*type
)
5772 if (type
== NULL
|| TYPE_CODE (type
) != TYPE_CODE_PTR
)
5776 const char *name
= ada_type_name (TYPE_TARGET_TYPE (type
));
5777 return (name
!= NULL
5778 && strcmp (name
, "ada__tags__dispatch_table") == 0);
5782 /* The type of the tag on VAL. */
5785 ada_tag_type (struct value
*val
)
5787 return ada_lookup_struct_elt_type (value_type (val
), "_tag", 1, 0, NULL
);
5790 /* The value of the tag on VAL. */
5793 ada_value_tag (struct value
*val
)
5795 return ada_value_struct_elt (val
, "_tag", 0);
5798 /* The value of the tag on the object of type TYPE whose contents are
5799 saved at VALADDR, if it is non-null, or is at memory address
5802 static struct value
*
5803 value_tag_from_contents_and_address (struct type
*type
,
5804 const gdb_byte
*valaddr
,
5807 int tag_byte_offset
, dummy1
, dummy2
;
5808 struct type
*tag_type
;
5809 if (find_struct_field ("_tag", type
, 0, &tag_type
, &tag_byte_offset
,
5812 const gdb_byte
*valaddr1
= ((valaddr
== NULL
)
5814 : valaddr
+ tag_byte_offset
);
5815 CORE_ADDR address1
= (address
== 0) ? 0 : address
+ tag_byte_offset
;
5817 return value_from_contents_and_address (tag_type
, valaddr1
, address1
);
5822 static struct type
*
5823 type_from_tag (struct value
*tag
)
5825 const char *type_name
= ada_tag_name (tag
);
5826 if (type_name
!= NULL
)
5827 return ada_find_any_type (ada_encode (type_name
));
5838 static int ada_tag_name_1 (void *);
5839 static int ada_tag_name_2 (struct tag_args
*);
5841 /* Wrapper function used by ada_tag_name. Given a struct tag_args*
5842 value ARGS, sets ARGS->name to the tag name of ARGS->tag.
5843 The value stored in ARGS->name is valid until the next call to
5847 ada_tag_name_1 (void *args0
)
5849 struct tag_args
*args
= (struct tag_args
*) args0
;
5850 static char name
[1024];
5854 val
= ada_value_struct_elt (args
->tag
, "tsd", 1);
5856 return ada_tag_name_2 (args
);
5857 val
= ada_value_struct_elt (val
, "expanded_name", 1);
5860 read_memory_string (value_as_address (val
), name
, sizeof (name
) - 1);
5861 for (p
= name
; *p
!= '\0'; p
+= 1)
5868 /* Utility function for ada_tag_name_1 that tries the second
5869 representation for the dispatch table (in which there is no
5870 explicit 'tsd' field in the referent of the tag pointer, and instead
5871 the tsd pointer is stored just before the dispatch table. */
5874 ada_tag_name_2 (struct tag_args
*args
)
5876 struct type
*info_type
;
5877 static char name
[1024];
5879 struct value
*val
, *valp
;
5882 info_type
= ada_find_any_type ("ada__tags__type_specific_data");
5883 if (info_type
== NULL
)
5885 info_type
= lookup_pointer_type (lookup_pointer_type (info_type
));
5886 valp
= value_cast (info_type
, args
->tag
);
5889 val
= value_ind (value_add (valp
, value_from_longest (builtin_type_int
, -1)));
5892 val
= ada_value_struct_elt (val
, "expanded_name", 1);
5895 read_memory_string (value_as_address (val
), name
, sizeof (name
) - 1);
5896 for (p
= name
; *p
!= '\0'; p
+= 1)
5903 /* The type name of the dynamic type denoted by the 'tag value TAG, as
5907 ada_tag_name (struct value
*tag
)
5909 struct tag_args args
;
5910 if (!ada_is_tag_type (value_type (tag
)))
5914 catch_errors (ada_tag_name_1
, &args
, NULL
, RETURN_MASK_ALL
);
5918 /* The parent type of TYPE, or NULL if none. */
5921 ada_parent_type (struct type
*type
)
5925 type
= ada_check_typedef (type
);
5927 if (type
== NULL
|| TYPE_CODE (type
) != TYPE_CODE_STRUCT
)
5930 for (i
= 0; i
< TYPE_NFIELDS (type
); i
+= 1)
5931 if (ada_is_parent_field (type
, i
))
5932 return ada_check_typedef (TYPE_FIELD_TYPE (type
, i
));
5937 /* True iff field number FIELD_NUM of structure type TYPE contains the
5938 parent-type (inherited) fields of a derived type. Assumes TYPE is
5939 a structure type with at least FIELD_NUM+1 fields. */
5942 ada_is_parent_field (struct type
*type
, int field_num
)
5944 const char *name
= TYPE_FIELD_NAME (ada_check_typedef (type
), field_num
);
5945 return (name
!= NULL
5946 && (strncmp (name
, "PARENT", 6) == 0
5947 || strncmp (name
, "_parent", 7) == 0));
5950 /* True iff field number FIELD_NUM of structure type TYPE is a
5951 transparent wrapper field (which should be silently traversed when doing
5952 field selection and flattened when printing). Assumes TYPE is a
5953 structure type with at least FIELD_NUM+1 fields. Such fields are always
5957 ada_is_wrapper_field (struct type
*type
, int field_num
)
5959 const char *name
= TYPE_FIELD_NAME (type
, field_num
);
5960 return (name
!= NULL
5961 && (strncmp (name
, "PARENT", 6) == 0
5962 || strcmp (name
, "REP") == 0
5963 || strncmp (name
, "_parent", 7) == 0
5964 || name
[0] == 'S' || name
[0] == 'R' || name
[0] == 'O'));
5967 /* True iff field number FIELD_NUM of structure or union type TYPE
5968 is a variant wrapper. Assumes TYPE is a structure type with at least
5969 FIELD_NUM+1 fields. */
5972 ada_is_variant_part (struct type
*type
, int field_num
)
5974 struct type
*field_type
= TYPE_FIELD_TYPE (type
, field_num
);
5975 return (TYPE_CODE (field_type
) == TYPE_CODE_UNION
5976 || (is_dynamic_field (type
, field_num
)
5977 && (TYPE_CODE (TYPE_TARGET_TYPE (field_type
))
5978 == TYPE_CODE_UNION
)));
5981 /* Assuming that VAR_TYPE is a variant wrapper (type of the variant part)
5982 whose discriminants are contained in the record type OUTER_TYPE,
5983 returns the type of the controlling discriminant for the variant. */
5986 ada_variant_discrim_type (struct type
*var_type
, struct type
*outer_type
)
5988 char *name
= ada_variant_discrim_name (var_type
);
5990 ada_lookup_struct_elt_type (outer_type
, name
, 1, 1, NULL
);
5992 return builtin_type_int
;
5997 /* Assuming that TYPE is the type of a variant wrapper, and FIELD_NUM is a
5998 valid field number within it, returns 1 iff field FIELD_NUM of TYPE
5999 represents a 'when others' clause; otherwise 0. */
6002 ada_is_others_clause (struct type
*type
, int field_num
)
6004 const char *name
= TYPE_FIELD_NAME (type
, field_num
);
6005 return (name
!= NULL
&& name
[0] == 'O');
6008 /* Assuming that TYPE0 is the type of the variant part of a record,
6009 returns the name of the discriminant controlling the variant.
6010 The value is valid until the next call to ada_variant_discrim_name. */
6013 ada_variant_discrim_name (struct type
*type0
)
6015 static char *result
= NULL
;
6016 static size_t result_len
= 0;
6019 const char *discrim_end
;
6020 const char *discrim_start
;
6022 if (TYPE_CODE (type0
) == TYPE_CODE_PTR
)
6023 type
= TYPE_TARGET_TYPE (type0
);
6027 name
= ada_type_name (type
);
6029 if (name
== NULL
|| name
[0] == '\000')
6032 for (discrim_end
= name
+ strlen (name
) - 6; discrim_end
!= name
;
6035 if (strncmp (discrim_end
, "___XVN", 6) == 0)
6038 if (discrim_end
== name
)
6041 for (discrim_start
= discrim_end
; discrim_start
!= name
+ 3;
6044 if (discrim_start
== name
+ 1)
6046 if ((discrim_start
> name
+ 3
6047 && strncmp (discrim_start
- 3, "___", 3) == 0)
6048 || discrim_start
[-1] == '.')
6052 GROW_VECT (result
, result_len
, discrim_end
- discrim_start
+ 1);
6053 strncpy (result
, discrim_start
, discrim_end
- discrim_start
);
6054 result
[discrim_end
- discrim_start
] = '\0';
6058 /* Scan STR for a subtype-encoded number, beginning at position K.
6059 Put the position of the character just past the number scanned in
6060 *NEW_K, if NEW_K!=NULL. Put the scanned number in *R, if R!=NULL.
6061 Return 1 if there was a valid number at the given position, and 0
6062 otherwise. A "subtype-encoded" number consists of the absolute value
6063 in decimal, followed by the letter 'm' to indicate a negative number.
6064 Assumes 0m does not occur. */
6067 ada_scan_number (const char str
[], int k
, LONGEST
* R
, int *new_k
)
6071 if (!isdigit (str
[k
]))
6074 /* Do it the hard way so as not to make any assumption about
6075 the relationship of unsigned long (%lu scan format code) and
6078 while (isdigit (str
[k
]))
6080 RU
= RU
* 10 + (str
[k
] - '0');
6087 *R
= (-(LONGEST
) (RU
- 1)) - 1;
6093 /* NOTE on the above: Technically, C does not say what the results of
6094 - (LONGEST) RU or (LONGEST) -RU are for RU == largest positive
6095 number representable as a LONGEST (although either would probably work
6096 in most implementations). When RU>0, the locution in the then branch
6097 above is always equivalent to the negative of RU. */
6104 /* Assuming that TYPE is a variant part wrapper type (a VARIANTS field),
6105 and FIELD_NUM is a valid field number within it, returns 1 iff VAL is
6106 in the range encoded by field FIELD_NUM of TYPE; otherwise 0. */
6109 ada_in_variant (LONGEST val
, struct type
*type
, int field_num
)
6111 const char *name
= TYPE_FIELD_NAME (type
, field_num
);
6124 if (!ada_scan_number (name
, p
+ 1, &W
, &p
))
6133 if (!ada_scan_number (name
, p
+ 1, &L
, &p
)
6134 || name
[p
] != 'T' || !ada_scan_number (name
, p
+ 1, &U
, &p
))
6136 if (val
>= L
&& val
<= U
)
6148 /* FIXME: Lots of redundancy below. Try to consolidate. */
6150 /* Given a value ARG1 (offset by OFFSET bytes) of a struct or union type
6151 ARG_TYPE, extract and return the value of one of its (non-static)
6152 fields. FIELDNO says which field. Differs from value_primitive_field
6153 only in that it can handle packed values of arbitrary type. */
6155 static struct value
*
6156 ada_value_primitive_field (struct value
*arg1
, int offset
, int fieldno
,
6157 struct type
*arg_type
)
6161 arg_type
= ada_check_typedef (arg_type
);
6162 type
= TYPE_FIELD_TYPE (arg_type
, fieldno
);
6164 /* Handle packed fields. */
6166 if (TYPE_FIELD_BITSIZE (arg_type
, fieldno
) != 0)
6168 int bit_pos
= TYPE_FIELD_BITPOS (arg_type
, fieldno
);
6169 int bit_size
= TYPE_FIELD_BITSIZE (arg_type
, fieldno
);
6171 return ada_value_primitive_packed_val (arg1
, value_contents (arg1
),
6172 offset
+ bit_pos
/ 8,
6173 bit_pos
% 8, bit_size
, type
);
6176 return value_primitive_field (arg1
, offset
, fieldno
, arg_type
);
6179 /* Find field with name NAME in object of type TYPE. If found,
6180 set the following for each argument that is non-null:
6181 - *FIELD_TYPE_P to the field's type;
6182 - *BYTE_OFFSET_P to OFFSET + the byte offset of the field within
6183 an object of that type;
6184 - *BIT_OFFSET_P to the bit offset modulo byte size of the field;
6185 - *BIT_SIZE_P to its size in bits if the field is packed, and
6187 If INDEX_P is non-null, increment *INDEX_P by the number of source-visible
6188 fields up to but not including the desired field, or by the total
6189 number of fields if not found. A NULL value of NAME never
6190 matches; the function just counts visible fields in this case.
6192 Returns 1 if found, 0 otherwise. */
6195 find_struct_field (char *name
, struct type
*type
, int offset
,
6196 struct type
**field_type_p
,
6197 int *byte_offset_p
, int *bit_offset_p
, int *bit_size_p
,
6202 type
= ada_check_typedef (type
);
6204 if (field_type_p
!= NULL
)
6205 *field_type_p
= NULL
;
6206 if (byte_offset_p
!= NULL
)
6208 if (bit_offset_p
!= NULL
)
6210 if (bit_size_p
!= NULL
)
6213 for (i
= 0; i
< TYPE_NFIELDS (type
); i
+= 1)
6215 int bit_pos
= TYPE_FIELD_BITPOS (type
, i
);
6216 int fld_offset
= offset
+ bit_pos
/ 8;
6217 char *t_field_name
= TYPE_FIELD_NAME (type
, i
);
6219 if (t_field_name
== NULL
)
6222 else if (name
!= NULL
&& field_name_match (t_field_name
, name
))
6224 int bit_size
= TYPE_FIELD_BITSIZE (type
, i
);
6225 if (field_type_p
!= NULL
)
6226 *field_type_p
= TYPE_FIELD_TYPE (type
, i
);
6227 if (byte_offset_p
!= NULL
)
6228 *byte_offset_p
= fld_offset
;
6229 if (bit_offset_p
!= NULL
)
6230 *bit_offset_p
= bit_pos
% 8;
6231 if (bit_size_p
!= NULL
)
6232 *bit_size_p
= bit_size
;
6235 else if (ada_is_wrapper_field (type
, i
))
6237 if (find_struct_field (name
, TYPE_FIELD_TYPE (type
, i
), fld_offset
,
6238 field_type_p
, byte_offset_p
, bit_offset_p
,
6239 bit_size_p
, index_p
))
6242 else if (ada_is_variant_part (type
, i
))
6244 /* PNH: Wait. Do we ever execute this section, or is ARG always of
6247 struct type
*field_type
6248 = ada_check_typedef (TYPE_FIELD_TYPE (type
, i
));
6250 for (j
= 0; j
< TYPE_NFIELDS (field_type
); j
+= 1)
6252 if (find_struct_field (name
, TYPE_FIELD_TYPE (field_type
, j
),
6254 + TYPE_FIELD_BITPOS (field_type
, j
) / 8,
6255 field_type_p
, byte_offset_p
,
6256 bit_offset_p
, bit_size_p
, index_p
))
6260 else if (index_p
!= NULL
)
6266 /* Number of user-visible fields in record type TYPE. */
6269 num_visible_fields (struct type
*type
)
6273 find_struct_field (NULL
, type
, 0, NULL
, NULL
, NULL
, NULL
, &n
);
6277 /* Look for a field NAME in ARG. Adjust the address of ARG by OFFSET bytes,
6278 and search in it assuming it has (class) type TYPE.
6279 If found, return value, else return NULL.
6281 Searches recursively through wrapper fields (e.g., '_parent'). */
6283 static struct value
*
6284 ada_search_struct_field (char *name
, struct value
*arg
, int offset
,
6288 type
= ada_check_typedef (type
);
6290 for (i
= 0; i
< TYPE_NFIELDS (type
); i
+= 1)
6292 char *t_field_name
= TYPE_FIELD_NAME (type
, i
);
6294 if (t_field_name
== NULL
)
6297 else if (field_name_match (t_field_name
, name
))
6298 return ada_value_primitive_field (arg
, offset
, i
, type
);
6300 else if (ada_is_wrapper_field (type
, i
))
6302 struct value
*v
= /* Do not let indent join lines here. */
6303 ada_search_struct_field (name
, arg
,
6304 offset
+ TYPE_FIELD_BITPOS (type
, i
) / 8,
6305 TYPE_FIELD_TYPE (type
, i
));
6310 else if (ada_is_variant_part (type
, i
))
6312 /* PNH: Do we ever get here? See find_struct_field. */
6314 struct type
*field_type
= ada_check_typedef (TYPE_FIELD_TYPE (type
, i
));
6315 int var_offset
= offset
+ TYPE_FIELD_BITPOS (type
, i
) / 8;
6317 for (j
= 0; j
< TYPE_NFIELDS (field_type
); j
+= 1)
6319 struct value
*v
= ada_search_struct_field
/* Force line break. */
6321 var_offset
+ TYPE_FIELD_BITPOS (field_type
, j
) / 8,
6322 TYPE_FIELD_TYPE (field_type
, j
));
6331 static struct value
*ada_index_struct_field_1 (int *, struct value
*,
6332 int, struct type
*);
6335 /* Return field #INDEX in ARG, where the index is that returned by
6336 * find_struct_field through its INDEX_P argument. Adjust the address
6337 * of ARG by OFFSET bytes, and search in it assuming it has (class) type TYPE.
6338 * If found, return value, else return NULL. */
6340 static struct value
*
6341 ada_index_struct_field (int index
, struct value
*arg
, int offset
,
6344 return ada_index_struct_field_1 (&index
, arg
, offset
, type
);
6348 /* Auxiliary function for ada_index_struct_field. Like
6349 * ada_index_struct_field, but takes index from *INDEX_P and modifies
6352 static struct value
*
6353 ada_index_struct_field_1 (int *index_p
, struct value
*arg
, int offset
,
6357 type
= ada_check_typedef (type
);
6359 for (i
= 0; i
< TYPE_NFIELDS (type
); i
+= 1)
6361 if (TYPE_FIELD_NAME (type
, i
) == NULL
)
6363 else if (ada_is_wrapper_field (type
, i
))
6365 struct value
*v
= /* Do not let indent join lines here. */
6366 ada_index_struct_field_1 (index_p
, arg
,
6367 offset
+ TYPE_FIELD_BITPOS (type
, i
) / 8,
6368 TYPE_FIELD_TYPE (type
, i
));
6373 else if (ada_is_variant_part (type
, i
))
6375 /* PNH: Do we ever get here? See ada_search_struct_field,
6376 find_struct_field. */
6377 error (_("Cannot assign this kind of variant record"));
6379 else if (*index_p
== 0)
6380 return ada_value_primitive_field (arg
, offset
, i
, type
);
6387 /* Given ARG, a value of type (pointer or reference to a)*
6388 structure/union, extract the component named NAME from the ultimate
6389 target structure/union and return it as a value with its
6390 appropriate type. If ARG is a pointer or reference and the field
6391 is not packed, returns a reference to the field, otherwise the
6392 value of the field (an lvalue if ARG is an lvalue).
6394 The routine searches for NAME among all members of the structure itself
6395 and (recursively) among all members of any wrapper members
6398 If NO_ERR, then simply return NULL in case of error, rather than
6402 ada_value_struct_elt (struct value
*arg
, char *name
, int no_err
)
6404 struct type
*t
, *t1
;
6408 t1
= t
= ada_check_typedef (value_type (arg
));
6409 if (TYPE_CODE (t
) == TYPE_CODE_REF
)
6411 t1
= TYPE_TARGET_TYPE (t
);
6414 t1
= ada_check_typedef (t1
);
6415 if (TYPE_CODE (t1
) == TYPE_CODE_PTR
)
6417 arg
= coerce_ref (arg
);
6422 while (TYPE_CODE (t
) == TYPE_CODE_PTR
)
6424 t1
= TYPE_TARGET_TYPE (t
);
6427 t1
= ada_check_typedef (t1
);
6428 if (TYPE_CODE (t1
) == TYPE_CODE_PTR
)
6430 arg
= value_ind (arg
);
6437 if (TYPE_CODE (t1
) != TYPE_CODE_STRUCT
&& TYPE_CODE (t1
) != TYPE_CODE_UNION
)
6441 v
= ada_search_struct_field (name
, arg
, 0, t
);
6444 int bit_offset
, bit_size
, byte_offset
;
6445 struct type
*field_type
;
6448 if (TYPE_CODE (t
) == TYPE_CODE_PTR
)
6449 address
= value_as_address (arg
);
6451 address
= unpack_pointer (t
, value_contents (arg
));
6453 t1
= ada_to_fixed_type (ada_get_base_type (t1
), NULL
, address
, NULL
, 1);
6454 if (find_struct_field (name
, t1
, 0,
6455 &field_type
, &byte_offset
, &bit_offset
,
6460 if (TYPE_CODE (t
) == TYPE_CODE_REF
)
6461 arg
= ada_coerce_ref (arg
);
6463 arg
= ada_value_ind (arg
);
6464 v
= ada_value_primitive_packed_val (arg
, NULL
, byte_offset
,
6465 bit_offset
, bit_size
,
6469 v
= value_from_pointer (lookup_reference_type (field_type
),
6470 address
+ byte_offset
);
6474 if (v
!= NULL
|| no_err
)
6477 error (_("There is no member named %s."), name
);
6483 error (_("Attempt to extract a component of a value that is not a record."));
6486 /* Given a type TYPE, look up the type of the component of type named NAME.
6487 If DISPP is non-null, add its byte displacement from the beginning of a
6488 structure (pointed to by a value) of type TYPE to *DISPP (does not
6489 work for packed fields).
6491 Matches any field whose name has NAME as a prefix, possibly
6494 TYPE can be either a struct or union. If REFOK, TYPE may also
6495 be a (pointer or reference)+ to a struct or union, and the
6496 ultimate target type will be searched.
6498 Looks recursively into variant clauses and parent types.
6500 If NOERR is nonzero, return NULL if NAME is not suitably defined or
6501 TYPE is not a type of the right kind. */
6503 static struct type
*
6504 ada_lookup_struct_elt_type (struct type
*type
, char *name
, int refok
,
6505 int noerr
, int *dispp
)
6512 if (refok
&& type
!= NULL
)
6515 type
= ada_check_typedef (type
);
6516 if (TYPE_CODE (type
) != TYPE_CODE_PTR
6517 && TYPE_CODE (type
) != TYPE_CODE_REF
)
6519 type
= TYPE_TARGET_TYPE (type
);
6523 || (TYPE_CODE (type
) != TYPE_CODE_STRUCT
6524 && TYPE_CODE (type
) != TYPE_CODE_UNION
))
6530 target_terminal_ours ();
6531 gdb_flush (gdb_stdout
);
6533 error (_("Type (null) is not a structure or union type"));
6536 /* XXX: type_sprint */
6537 fprintf_unfiltered (gdb_stderr
, _("Type "));
6538 type_print (type
, "", gdb_stderr
, -1);
6539 error (_(" is not a structure or union type"));
6544 type
= to_static_fixed_type (type
);
6546 for (i
= 0; i
< TYPE_NFIELDS (type
); i
+= 1)
6548 char *t_field_name
= TYPE_FIELD_NAME (type
, i
);
6552 if (t_field_name
== NULL
)
6555 else if (field_name_match (t_field_name
, name
))
6558 *dispp
+= TYPE_FIELD_BITPOS (type
, i
) / 8;
6559 return ada_check_typedef (TYPE_FIELD_TYPE (type
, i
));
6562 else if (ada_is_wrapper_field (type
, i
))
6565 t
= ada_lookup_struct_elt_type (TYPE_FIELD_TYPE (type
, i
), name
,
6570 *dispp
+= disp
+ TYPE_FIELD_BITPOS (type
, i
) / 8;
6575 else if (ada_is_variant_part (type
, i
))
6578 struct type
*field_type
= ada_check_typedef (TYPE_FIELD_TYPE (type
, i
));
6580 for (j
= TYPE_NFIELDS (field_type
) - 1; j
>= 0; j
-= 1)
6583 t
= ada_lookup_struct_elt_type (TYPE_FIELD_TYPE (field_type
, j
),
6588 *dispp
+= disp
+ TYPE_FIELD_BITPOS (type
, i
) / 8;
6599 target_terminal_ours ();
6600 gdb_flush (gdb_stdout
);
6603 /* XXX: type_sprint */
6604 fprintf_unfiltered (gdb_stderr
, _("Type "));
6605 type_print (type
, "", gdb_stderr
, -1);
6606 error (_(" has no component named <null>"));
6610 /* XXX: type_sprint */
6611 fprintf_unfiltered (gdb_stderr
, _("Type "));
6612 type_print (type
, "", gdb_stderr
, -1);
6613 error (_(" has no component named %s"), name
);
6620 /* Assuming that VAR_TYPE is the type of a variant part of a record (a union),
6621 within a value of type OUTER_TYPE that is stored in GDB at
6622 OUTER_VALADDR, determine which variant clause (field number in VAR_TYPE,
6623 numbering from 0) is applicable. Returns -1 if none are. */
6626 ada_which_variant_applies (struct type
*var_type
, struct type
*outer_type
,
6627 const gdb_byte
*outer_valaddr
)
6631 char *discrim_name
= ada_variant_discrim_name (var_type
);
6632 struct value
*outer
;
6633 struct value
*discrim
;
6634 LONGEST discrim_val
;
6636 outer
= value_from_contents_and_address (outer_type
, outer_valaddr
, 0);
6637 discrim
= ada_value_struct_elt (outer
, discrim_name
, 1);
6638 if (discrim
== NULL
)
6640 discrim_val
= value_as_long (discrim
);
6643 for (i
= 0; i
< TYPE_NFIELDS (var_type
); i
+= 1)
6645 if (ada_is_others_clause (var_type
, i
))
6647 else if (ada_in_variant (discrim_val
, var_type
, i
))
6651 return others_clause
;
6656 /* Dynamic-Sized Records */
6658 /* Strategy: The type ostensibly attached to a value with dynamic size
6659 (i.e., a size that is not statically recorded in the debugging
6660 data) does not accurately reflect the size or layout of the value.
6661 Our strategy is to convert these values to values with accurate,
6662 conventional types that are constructed on the fly. */
6664 /* There is a subtle and tricky problem here. In general, we cannot
6665 determine the size of dynamic records without its data. However,
6666 the 'struct value' data structure, which GDB uses to represent
6667 quantities in the inferior process (the target), requires the size
6668 of the type at the time of its allocation in order to reserve space
6669 for GDB's internal copy of the data. That's why the
6670 'to_fixed_xxx_type' routines take (target) addresses as parameters,
6671 rather than struct value*s.
6673 However, GDB's internal history variables ($1, $2, etc.) are
6674 struct value*s containing internal copies of the data that are not, in
6675 general, the same as the data at their corresponding addresses in
6676 the target. Fortunately, the types we give to these values are all
6677 conventional, fixed-size types (as per the strategy described
6678 above), so that we don't usually have to perform the
6679 'to_fixed_xxx_type' conversions to look at their values.
6680 Unfortunately, there is one exception: if one of the internal
6681 history variables is an array whose elements are unconstrained
6682 records, then we will need to create distinct fixed types for each
6683 element selected. */
6685 /* The upshot of all of this is that many routines take a (type, host
6686 address, target address) triple as arguments to represent a value.
6687 The host address, if non-null, is supposed to contain an internal
6688 copy of the relevant data; otherwise, the program is to consult the
6689 target at the target address. */
6691 /* Assuming that VAL0 represents a pointer value, the result of
6692 dereferencing it. Differs from value_ind in its treatment of
6693 dynamic-sized types. */
6696 ada_value_ind (struct value
*val0
)
6698 struct value
*val
= unwrap_value (value_ind (val0
));
6699 return ada_to_fixed_value (val
);
6702 /* The value resulting from dereferencing any "reference to"
6703 qualifiers on VAL0. */
6705 static struct value
*
6706 ada_coerce_ref (struct value
*val0
)
6708 if (TYPE_CODE (value_type (val0
)) == TYPE_CODE_REF
)
6710 struct value
*val
= val0
;
6711 val
= coerce_ref (val
);
6712 val
= unwrap_value (val
);
6713 return ada_to_fixed_value (val
);
6719 /* Return OFF rounded upward if necessary to a multiple of
6720 ALIGNMENT (a power of 2). */
6723 align_value (unsigned int off
, unsigned int alignment
)
6725 return (off
+ alignment
- 1) & ~(alignment
- 1);
6728 /* Return the bit alignment required for field #F of template type TYPE. */
6731 field_alignment (struct type
*type
, int f
)
6733 const char *name
= TYPE_FIELD_NAME (type
, f
);
6737 /* The field name should never be null, unless the debugging information
6738 is somehow malformed. In this case, we assume the field does not
6739 require any alignment. */
6743 len
= strlen (name
);
6745 if (!isdigit (name
[len
- 1]))
6748 if (isdigit (name
[len
- 2]))
6749 align_offset
= len
- 2;
6751 align_offset
= len
- 1;
6753 if (align_offset
< 7 || strncmp ("___XV", name
+ align_offset
- 6, 5) != 0)
6754 return TARGET_CHAR_BIT
;
6756 return atoi (name
+ align_offset
) * TARGET_CHAR_BIT
;
6759 /* Find a symbol named NAME. Ignores ambiguity. */
6762 ada_find_any_symbol (const char *name
)
6766 sym
= standard_lookup (name
, get_selected_block (NULL
), VAR_DOMAIN
);
6767 if (sym
!= NULL
&& SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
6770 sym
= standard_lookup (name
, NULL
, STRUCT_DOMAIN
);
6774 /* Find a type named NAME. Ignores ambiguity. */
6777 ada_find_any_type (const char *name
)
6779 struct symbol
*sym
= ada_find_any_symbol (name
);
6782 return SYMBOL_TYPE (sym
);
6787 /* Given NAME and an associated BLOCK, search all symbols for
6788 NAME suffixed with "___XR", which is the ``renaming'' symbol
6789 associated to NAME. Return this symbol if found, return
6793 ada_find_renaming_symbol (const char *name
, struct block
*block
)
6797 sym
= find_old_style_renaming_symbol (name
, block
);
6802 /* Not right yet. FIXME pnh 7/20/2007. */
6803 sym
= ada_find_any_symbol (name
);
6804 if (sym
!= NULL
&& strstr (SYMBOL_LINKAGE_NAME (sym
), "___XR") != NULL
)
6810 static struct symbol
*
6811 find_old_style_renaming_symbol (const char *name
, struct block
*block
)
6813 const struct symbol
*function_sym
= block_function (block
);
6816 if (function_sym
!= NULL
)
6818 /* If the symbol is defined inside a function, NAME is not fully
6819 qualified. This means we need to prepend the function name
6820 as well as adding the ``___XR'' suffix to build the name of
6821 the associated renaming symbol. */
6822 char *function_name
= SYMBOL_LINKAGE_NAME (function_sym
);
6823 /* Function names sometimes contain suffixes used
6824 for instance to qualify nested subprograms. When building
6825 the XR type name, we need to make sure that this suffix is
6826 not included. So do not include any suffix in the function
6827 name length below. */
6828 const int function_name_len
= ada_name_prefix_len (function_name
);
6829 const int rename_len
= function_name_len
+ 2 /* "__" */
6830 + strlen (name
) + 6 /* "___XR\0" */ ;
6832 /* Strip the suffix if necessary. */
6833 function_name
[function_name_len
] = '\0';
6835 /* Library-level functions are a special case, as GNAT adds
6836 a ``_ada_'' prefix to the function name to avoid namespace
6837 pollution. However, the renaming symbols themselves do not
6838 have this prefix, so we need to skip this prefix if present. */
6839 if (function_name_len
> 5 /* "_ada_" */
6840 && strstr (function_name
, "_ada_") == function_name
)
6841 function_name
= function_name
+ 5;
6843 rename
= (char *) alloca (rename_len
* sizeof (char));
6844 sprintf (rename
, "%s__%s___XR", function_name
, name
);
6848 const int rename_len
= strlen (name
) + 6;
6849 rename
= (char *) alloca (rename_len
* sizeof (char));
6850 sprintf (rename
, "%s___XR", name
);
6853 return ada_find_any_symbol (rename
);
6856 /* Because of GNAT encoding conventions, several GDB symbols may match a
6857 given type name. If the type denoted by TYPE0 is to be preferred to
6858 that of TYPE1 for purposes of type printing, return non-zero;
6859 otherwise return 0. */
6862 ada_prefer_type (struct type
*type0
, struct type
*type1
)
6866 else if (type0
== NULL
)
6868 else if (TYPE_CODE (type1
) == TYPE_CODE_VOID
)
6870 else if (TYPE_CODE (type0
) == TYPE_CODE_VOID
)
6872 else if (TYPE_NAME (type1
) == NULL
&& TYPE_NAME (type0
) != NULL
)
6874 else if (ada_is_packed_array_type (type0
))
6876 else if (ada_is_array_descriptor_type (type0
)
6877 && !ada_is_array_descriptor_type (type1
))
6881 const char *type0_name
= type_name_no_tag (type0
);
6882 const char *type1_name
= type_name_no_tag (type1
);
6884 if (type0_name
!= NULL
&& strstr (type0_name
, "___XR") != NULL
6885 && (type1_name
== NULL
|| strstr (type1_name
, "___XR") == NULL
))
6891 /* The name of TYPE, which is either its TYPE_NAME, or, if that is
6892 null, its TYPE_TAG_NAME. Null if TYPE is null. */
6895 ada_type_name (struct type
*type
)
6899 else if (TYPE_NAME (type
) != NULL
)
6900 return TYPE_NAME (type
);
6902 return TYPE_TAG_NAME (type
);
6905 /* Find a parallel type to TYPE whose name is formed by appending
6906 SUFFIX to the name of TYPE. */
6909 ada_find_parallel_type (struct type
*type
, const char *suffix
)
6912 static size_t name_len
= 0;
6914 char *typename
= ada_type_name (type
);
6916 if (typename
== NULL
)
6919 len
= strlen (typename
);
6921 GROW_VECT (name
, name_len
, len
+ strlen (suffix
) + 1);
6923 strcpy (name
, typename
);
6924 strcpy (name
+ len
, suffix
);
6926 return ada_find_any_type (name
);
6930 /* If TYPE is a variable-size record type, return the corresponding template
6931 type describing its fields. Otherwise, return NULL. */
6933 static struct type
*
6934 dynamic_template_type (struct type
*type
)
6936 type
= ada_check_typedef (type
);
6938 if (type
== NULL
|| TYPE_CODE (type
) != TYPE_CODE_STRUCT
6939 || ada_type_name (type
) == NULL
)
6943 int len
= strlen (ada_type_name (type
));
6944 if (len
> 6 && strcmp (ada_type_name (type
) + len
- 6, "___XVE") == 0)
6947 return ada_find_parallel_type (type
, "___XVE");
6951 /* Assuming that TEMPL_TYPE is a union or struct type, returns
6952 non-zero iff field FIELD_NUM of TEMPL_TYPE has dynamic size. */
6955 is_dynamic_field (struct type
*templ_type
, int field_num
)
6957 const char *name
= TYPE_FIELD_NAME (templ_type
, field_num
);
6959 && TYPE_CODE (TYPE_FIELD_TYPE (templ_type
, field_num
)) == TYPE_CODE_PTR
6960 && strstr (name
, "___XVL") != NULL
;
6963 /* The index of the variant field of TYPE, or -1 if TYPE does not
6964 represent a variant record type. */
6967 variant_field_index (struct type
*type
)
6971 if (type
== NULL
|| TYPE_CODE (type
) != TYPE_CODE_STRUCT
)
6974 for (f
= 0; f
< TYPE_NFIELDS (type
); f
+= 1)
6976 if (ada_is_variant_part (type
, f
))
6982 /* A record type with no fields. */
6984 static struct type
*
6985 empty_record (struct objfile
*objfile
)
6987 struct type
*type
= alloc_type (objfile
);
6988 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
6989 TYPE_NFIELDS (type
) = 0;
6990 TYPE_FIELDS (type
) = NULL
;
6991 TYPE_NAME (type
) = "<empty>";
6992 TYPE_TAG_NAME (type
) = NULL
;
6993 TYPE_FLAGS (type
) = 0;
6994 TYPE_LENGTH (type
) = 0;
6998 /* An ordinary record type (with fixed-length fields) that describes
6999 the value of type TYPE at VALADDR or ADDRESS (see comments at
7000 the beginning of this section) VAL according to GNAT conventions.
7001 DVAL0 should describe the (portion of a) record that contains any
7002 necessary discriminants. It should be NULL if value_type (VAL) is
7003 an outer-level type (i.e., as opposed to a branch of a variant.) A
7004 variant field (unless unchecked) is replaced by a particular branch
7007 If not KEEP_DYNAMIC_FIELDS, then all fields whose position or
7008 length are not statically known are discarded. As a consequence,
7009 VALADDR, ADDRESS and DVAL0 are ignored.
7011 NOTE: Limitations: For now, we assume that dynamic fields and
7012 variants occupy whole numbers of bytes. However, they need not be
7016 ada_template_to_fixed_record_type_1 (struct type
*type
,
7017 const gdb_byte
*valaddr
,
7018 CORE_ADDR address
, struct value
*dval0
,
7019 int keep_dynamic_fields
)
7021 struct value
*mark
= value_mark ();
7024 int nfields
, bit_len
;
7027 int fld_bit_len
, bit_incr
;
7030 /* Compute the number of fields in this record type that are going
7031 to be processed: unless keep_dynamic_fields, this includes only
7032 fields whose position and length are static will be processed. */
7033 if (keep_dynamic_fields
)
7034 nfields
= TYPE_NFIELDS (type
);
7038 while (nfields
< TYPE_NFIELDS (type
)
7039 && !ada_is_variant_part (type
, nfields
)
7040 && !is_dynamic_field (type
, nfields
))
7044 rtype
= alloc_type (TYPE_OBJFILE (type
));
7045 TYPE_CODE (rtype
) = TYPE_CODE_STRUCT
;
7046 INIT_CPLUS_SPECIFIC (rtype
);
7047 TYPE_NFIELDS (rtype
) = nfields
;
7048 TYPE_FIELDS (rtype
) = (struct field
*)
7049 TYPE_ALLOC (rtype
, nfields
* sizeof (struct field
));
7050 memset (TYPE_FIELDS (rtype
), 0, sizeof (struct field
) * nfields
);
7051 TYPE_NAME (rtype
) = ada_type_name (type
);
7052 TYPE_TAG_NAME (rtype
) = NULL
;
7053 TYPE_FLAGS (rtype
) |= TYPE_FLAG_FIXED_INSTANCE
;
7059 for (f
= 0; f
< nfields
; f
+= 1)
7061 off
= align_value (off
, field_alignment (type
, f
))
7062 + TYPE_FIELD_BITPOS (type
, f
);
7063 TYPE_FIELD_BITPOS (rtype
, f
) = off
;
7064 TYPE_FIELD_BITSIZE (rtype
, f
) = 0;
7066 if (ada_is_variant_part (type
, f
))
7069 fld_bit_len
= bit_incr
= 0;
7071 else if (is_dynamic_field (type
, f
))
7074 dval
= value_from_contents_and_address (rtype
, valaddr
, address
);
7078 /* Get the fixed type of the field. Note that, in this case, we
7079 do not want to get the real type out of the tag: if the current
7080 field is the parent part of a tagged record, we will get the
7081 tag of the object. Clearly wrong: the real type of the parent
7082 is not the real type of the child. We would end up in an infinite
7084 TYPE_FIELD_TYPE (rtype
, f
) =
7087 (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
, f
))),
7088 cond_offset_host (valaddr
, off
/ TARGET_CHAR_BIT
),
7089 cond_offset_target (address
, off
/ TARGET_CHAR_BIT
), dval
, 0);
7090 TYPE_FIELD_NAME (rtype
, f
) = TYPE_FIELD_NAME (type
, f
);
7091 bit_incr
= fld_bit_len
=
7092 TYPE_LENGTH (TYPE_FIELD_TYPE (rtype
, f
)) * TARGET_CHAR_BIT
;
7096 TYPE_FIELD_TYPE (rtype
, f
) = TYPE_FIELD_TYPE (type
, f
);
7097 TYPE_FIELD_NAME (rtype
, f
) = TYPE_FIELD_NAME (type
, f
);
7098 if (TYPE_FIELD_BITSIZE (type
, f
) > 0)
7099 bit_incr
= fld_bit_len
=
7100 TYPE_FIELD_BITSIZE (rtype
, f
) = TYPE_FIELD_BITSIZE (type
, f
);
7102 bit_incr
= fld_bit_len
=
7103 TYPE_LENGTH (TYPE_FIELD_TYPE (type
, f
)) * TARGET_CHAR_BIT
;
7105 if (off
+ fld_bit_len
> bit_len
)
7106 bit_len
= off
+ fld_bit_len
;
7108 TYPE_LENGTH (rtype
) =
7109 align_value (bit_len
, TARGET_CHAR_BIT
) / TARGET_CHAR_BIT
;
7112 /* We handle the variant part, if any, at the end because of certain
7113 odd cases in which it is re-ordered so as NOT the last field of
7114 the record. This can happen in the presence of representation
7116 if (variant_field
>= 0)
7118 struct type
*branch_type
;
7120 off
= TYPE_FIELD_BITPOS (rtype
, variant_field
);
7123 dval
= value_from_contents_and_address (rtype
, valaddr
, address
);
7128 to_fixed_variant_branch_type
7129 (TYPE_FIELD_TYPE (type
, variant_field
),
7130 cond_offset_host (valaddr
, off
/ TARGET_CHAR_BIT
),
7131 cond_offset_target (address
, off
/ TARGET_CHAR_BIT
), dval
);
7132 if (branch_type
== NULL
)
7134 for (f
= variant_field
+ 1; f
< TYPE_NFIELDS (rtype
); f
+= 1)
7135 TYPE_FIELDS (rtype
)[f
- 1] = TYPE_FIELDS (rtype
)[f
];
7136 TYPE_NFIELDS (rtype
) -= 1;
7140 TYPE_FIELD_TYPE (rtype
, variant_field
) = branch_type
;
7141 TYPE_FIELD_NAME (rtype
, variant_field
) = "S";
7143 TYPE_LENGTH (TYPE_FIELD_TYPE (rtype
, variant_field
)) *
7145 if (off
+ fld_bit_len
> bit_len
)
7146 bit_len
= off
+ fld_bit_len
;
7147 TYPE_LENGTH (rtype
) =
7148 align_value (bit_len
, TARGET_CHAR_BIT
) / TARGET_CHAR_BIT
;
7152 /* According to exp_dbug.ads, the size of TYPE for variable-size records
7153 should contain the alignment of that record, which should be a strictly
7154 positive value. If null or negative, then something is wrong, most
7155 probably in the debug info. In that case, we don't round up the size
7156 of the resulting type. If this record is not part of another structure,
7157 the current RTYPE length might be good enough for our purposes. */
7158 if (TYPE_LENGTH (type
) <= 0)
7160 if (TYPE_NAME (rtype
))
7161 warning (_("Invalid type size for `%s' detected: %d."),
7162 TYPE_NAME (rtype
), TYPE_LENGTH (type
));
7164 warning (_("Invalid type size for <unnamed> detected: %d."),
7165 TYPE_LENGTH (type
));
7169 TYPE_LENGTH (rtype
) = align_value (TYPE_LENGTH (rtype
),
7170 TYPE_LENGTH (type
));
7173 value_free_to_mark (mark
);
7174 if (TYPE_LENGTH (rtype
) > varsize_limit
)
7175 error (_("record type with dynamic size is larger than varsize-limit"));
7179 /* As for ada_template_to_fixed_record_type_1 with KEEP_DYNAMIC_FIELDS
7182 static struct type
*
7183 template_to_fixed_record_type (struct type
*type
, const gdb_byte
*valaddr
,
7184 CORE_ADDR address
, struct value
*dval0
)
7186 return ada_template_to_fixed_record_type_1 (type
, valaddr
,
7190 /* An ordinary record type in which ___XVL-convention fields and
7191 ___XVU- and ___XVN-convention field types in TYPE0 are replaced with
7192 static approximations, containing all possible fields. Uses
7193 no runtime values. Useless for use in values, but that's OK,
7194 since the results are used only for type determinations. Works on both
7195 structs and unions. Representation note: to save space, we memorize
7196 the result of this function in the TYPE_TARGET_TYPE of the
7199 static struct type
*
7200 template_to_static_fixed_type (struct type
*type0
)
7206 if (TYPE_TARGET_TYPE (type0
) != NULL
)
7207 return TYPE_TARGET_TYPE (type0
);
7209 nfields
= TYPE_NFIELDS (type0
);
7212 for (f
= 0; f
< nfields
; f
+= 1)
7214 struct type
*field_type
= ada_check_typedef (TYPE_FIELD_TYPE (type0
, f
));
7215 struct type
*new_type
;
7217 if (is_dynamic_field (type0
, f
))
7218 new_type
= to_static_fixed_type (TYPE_TARGET_TYPE (field_type
));
7220 new_type
= static_unwrap_type (field_type
);
7221 if (type
== type0
&& new_type
!= field_type
)
7223 TYPE_TARGET_TYPE (type0
) = type
= alloc_type (TYPE_OBJFILE (type0
));
7224 TYPE_CODE (type
) = TYPE_CODE (type0
);
7225 INIT_CPLUS_SPECIFIC (type
);
7226 TYPE_NFIELDS (type
) = nfields
;
7227 TYPE_FIELDS (type
) = (struct field
*)
7228 TYPE_ALLOC (type
, nfields
* sizeof (struct field
));
7229 memcpy (TYPE_FIELDS (type
), TYPE_FIELDS (type0
),
7230 sizeof (struct field
) * nfields
);
7231 TYPE_NAME (type
) = ada_type_name (type0
);
7232 TYPE_TAG_NAME (type
) = NULL
;
7233 TYPE_FLAGS (type
) |= TYPE_FLAG_FIXED_INSTANCE
;
7234 TYPE_LENGTH (type
) = 0;
7236 TYPE_FIELD_TYPE (type
, f
) = new_type
;
7237 TYPE_FIELD_NAME (type
, f
) = TYPE_FIELD_NAME (type0
, f
);
7242 /* Given an object of type TYPE whose contents are at VALADDR and
7243 whose address in memory is ADDRESS, returns a revision of TYPE --
7244 a non-dynamic-sized record with a variant part -- in which
7245 the variant part is replaced with the appropriate branch. Looks
7246 for discriminant values in DVAL0, which can be NULL if the record
7247 contains the necessary discriminant values. */
7249 static struct type
*
7250 to_record_with_fixed_variant_part (struct type
*type
, const gdb_byte
*valaddr
,
7251 CORE_ADDR address
, struct value
*dval0
)
7253 struct value
*mark
= value_mark ();
7256 struct type
*branch_type
;
7257 int nfields
= TYPE_NFIELDS (type
);
7258 int variant_field
= variant_field_index (type
);
7260 if (variant_field
== -1)
7264 dval
= value_from_contents_and_address (type
, valaddr
, address
);
7268 rtype
= alloc_type (TYPE_OBJFILE (type
));
7269 TYPE_CODE (rtype
) = TYPE_CODE_STRUCT
;
7270 INIT_CPLUS_SPECIFIC (rtype
);
7271 TYPE_NFIELDS (rtype
) = nfields
;
7272 TYPE_FIELDS (rtype
) =
7273 (struct field
*) TYPE_ALLOC (rtype
, nfields
* sizeof (struct field
));
7274 memcpy (TYPE_FIELDS (rtype
), TYPE_FIELDS (type
),
7275 sizeof (struct field
) * nfields
);
7276 TYPE_NAME (rtype
) = ada_type_name (type
);
7277 TYPE_TAG_NAME (rtype
) = NULL
;
7278 TYPE_FLAGS (rtype
) |= TYPE_FLAG_FIXED_INSTANCE
;
7279 TYPE_LENGTH (rtype
) = TYPE_LENGTH (type
);
7281 branch_type
= to_fixed_variant_branch_type
7282 (TYPE_FIELD_TYPE (type
, variant_field
),
7283 cond_offset_host (valaddr
,
7284 TYPE_FIELD_BITPOS (type
, variant_field
)
7286 cond_offset_target (address
,
7287 TYPE_FIELD_BITPOS (type
, variant_field
)
7288 / TARGET_CHAR_BIT
), dval
);
7289 if (branch_type
== NULL
)
7292 for (f
= variant_field
+ 1; f
< nfields
; f
+= 1)
7293 TYPE_FIELDS (rtype
)[f
- 1] = TYPE_FIELDS (rtype
)[f
];
7294 TYPE_NFIELDS (rtype
) -= 1;
7298 TYPE_FIELD_TYPE (rtype
, variant_field
) = branch_type
;
7299 TYPE_FIELD_NAME (rtype
, variant_field
) = "S";
7300 TYPE_FIELD_BITSIZE (rtype
, variant_field
) = 0;
7301 TYPE_LENGTH (rtype
) += TYPE_LENGTH (branch_type
);
7303 TYPE_LENGTH (rtype
) -= TYPE_LENGTH (TYPE_FIELD_TYPE (type
, variant_field
));
7305 value_free_to_mark (mark
);
7309 /* An ordinary record type (with fixed-length fields) that describes
7310 the value at (TYPE0, VALADDR, ADDRESS) [see explanation at
7311 beginning of this section]. Any necessary discriminants' values
7312 should be in DVAL, a record value; it may be NULL if the object
7313 at ADDR itself contains any necessary discriminant values.
7314 Additionally, VALADDR and ADDRESS may also be NULL if no discriminant
7315 values from the record are needed. Except in the case that DVAL,
7316 VALADDR, and ADDRESS are all 0 or NULL, a variant field (unless
7317 unchecked) is replaced by a particular branch of the variant.
7319 NOTE: the case in which DVAL and VALADDR are NULL and ADDRESS is 0
7320 is questionable and may be removed. It can arise during the
7321 processing of an unconstrained-array-of-record type where all the
7322 variant branches have exactly the same size. This is because in
7323 such cases, the compiler does not bother to use the XVS convention
7324 when encoding the record. I am currently dubious of this
7325 shortcut and suspect the compiler should be altered. FIXME. */
7327 static struct type
*
7328 to_fixed_record_type (struct type
*type0
, const gdb_byte
*valaddr
,
7329 CORE_ADDR address
, struct value
*dval
)
7331 struct type
*templ_type
;
7333 if (TYPE_FLAGS (type0
) & TYPE_FLAG_FIXED_INSTANCE
)
7336 templ_type
= dynamic_template_type (type0
);
7338 if (templ_type
!= NULL
)
7339 return template_to_fixed_record_type (templ_type
, valaddr
, address
, dval
);
7340 else if (variant_field_index (type0
) >= 0)
7342 if (dval
== NULL
&& valaddr
== NULL
&& address
== 0)
7344 return to_record_with_fixed_variant_part (type0
, valaddr
, address
,
7349 TYPE_FLAGS (type0
) |= TYPE_FLAG_FIXED_INSTANCE
;
7355 /* An ordinary record type (with fixed-length fields) that describes
7356 the value at (VAR_TYPE0, VALADDR, ADDRESS), where VAR_TYPE0 is a
7357 union type. Any necessary discriminants' values should be in DVAL,
7358 a record value. That is, this routine selects the appropriate
7359 branch of the union at ADDR according to the discriminant value
7360 indicated in the union's type name. */
7362 static struct type
*
7363 to_fixed_variant_branch_type (struct type
*var_type0
, const gdb_byte
*valaddr
,
7364 CORE_ADDR address
, struct value
*dval
)
7367 struct type
*templ_type
;
7368 struct type
*var_type
;
7370 if (TYPE_CODE (var_type0
) == TYPE_CODE_PTR
)
7371 var_type
= TYPE_TARGET_TYPE (var_type0
);
7373 var_type
= var_type0
;
7375 templ_type
= ada_find_parallel_type (var_type
, "___XVU");
7377 if (templ_type
!= NULL
)
7378 var_type
= templ_type
;
7381 ada_which_variant_applies (var_type
,
7382 value_type (dval
), value_contents (dval
));
7385 return empty_record (TYPE_OBJFILE (var_type
));
7386 else if (is_dynamic_field (var_type
, which
))
7387 return to_fixed_record_type
7388 (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (var_type
, which
)),
7389 valaddr
, address
, dval
);
7390 else if (variant_field_index (TYPE_FIELD_TYPE (var_type
, which
)) >= 0)
7392 to_fixed_record_type
7393 (TYPE_FIELD_TYPE (var_type
, which
), valaddr
, address
, dval
);
7395 return TYPE_FIELD_TYPE (var_type
, which
);
7398 /* Assuming that TYPE0 is an array type describing the type of a value
7399 at ADDR, and that DVAL describes a record containing any
7400 discriminants used in TYPE0, returns a type for the value that
7401 contains no dynamic components (that is, no components whose sizes
7402 are determined by run-time quantities). Unless IGNORE_TOO_BIG is
7403 true, gives an error message if the resulting type's size is over
7406 static struct type
*
7407 to_fixed_array_type (struct type
*type0
, struct value
*dval
,
7410 struct type
*index_type_desc
;
7411 struct type
*result
;
7413 if (ada_is_packed_array_type (type0
) /* revisit? */
7414 || (TYPE_FLAGS (type0
) & TYPE_FLAG_FIXED_INSTANCE
))
7417 index_type_desc
= ada_find_parallel_type (type0
, "___XA");
7418 if (index_type_desc
== NULL
)
7420 struct type
*elt_type0
= ada_check_typedef (TYPE_TARGET_TYPE (type0
));
7421 /* NOTE: elt_type---the fixed version of elt_type0---should never
7422 depend on the contents of the array in properly constructed
7424 /* Create a fixed version of the array element type.
7425 We're not providing the address of an element here,
7426 and thus the actual object value cannot be inspected to do
7427 the conversion. This should not be a problem, since arrays of
7428 unconstrained objects are not allowed. In particular, all
7429 the elements of an array of a tagged type should all be of
7430 the same type specified in the debugging info. No need to
7431 consult the object tag. */
7432 struct type
*elt_type
= ada_to_fixed_type (elt_type0
, 0, 0, dval
, 1);
7434 if (elt_type0
== elt_type
)
7437 result
= create_array_type (alloc_type (TYPE_OBJFILE (type0
)),
7438 elt_type
, TYPE_INDEX_TYPE (type0
));
7443 struct type
*elt_type0
;
7446 for (i
= TYPE_NFIELDS (index_type_desc
); i
> 0; i
-= 1)
7447 elt_type0
= TYPE_TARGET_TYPE (elt_type0
);
7449 /* NOTE: result---the fixed version of elt_type0---should never
7450 depend on the contents of the array in properly constructed
7452 /* Create a fixed version of the array element type.
7453 We're not providing the address of an element here,
7454 and thus the actual object value cannot be inspected to do
7455 the conversion. This should not be a problem, since arrays of
7456 unconstrained objects are not allowed. In particular, all
7457 the elements of an array of a tagged type should all be of
7458 the same type specified in the debugging info. No need to
7459 consult the object tag. */
7461 ada_to_fixed_type (ada_check_typedef (elt_type0
), 0, 0, dval
, 1);
7462 for (i
= TYPE_NFIELDS (index_type_desc
) - 1; i
>= 0; i
-= 1)
7464 struct type
*range_type
=
7465 to_fixed_range_type (TYPE_FIELD_NAME (index_type_desc
, i
),
7466 dval
, TYPE_OBJFILE (type0
));
7467 result
= create_array_type (alloc_type (TYPE_OBJFILE (type0
)),
7468 result
, range_type
);
7470 if (!ignore_too_big
&& TYPE_LENGTH (result
) > varsize_limit
)
7471 error (_("array type with dynamic size is larger than varsize-limit"));
7474 TYPE_FLAGS (result
) |= TYPE_FLAG_FIXED_INSTANCE
;
7479 /* A standard type (containing no dynamically sized components)
7480 corresponding to TYPE for the value (TYPE, VALADDR, ADDRESS)
7481 DVAL describes a record containing any discriminants used in TYPE0,
7482 and may be NULL if there are none, or if the object of type TYPE at
7483 ADDRESS or in VALADDR contains these discriminants.
7485 If CHECK_TAG is not null, in the case of tagged types, this function
7486 attempts to locate the object's tag and use it to compute the actual
7487 type. However, when ADDRESS is null, we cannot use it to determine the
7488 location of the tag, and therefore compute the tagged type's actual type.
7489 So we return the tagged type without consulting the tag. */
7491 static struct type
*
7492 ada_to_fixed_type_1 (struct type
*type
, const gdb_byte
*valaddr
,
7493 CORE_ADDR address
, struct value
*dval
, int check_tag
)
7495 type
= ada_check_typedef (type
);
7496 switch (TYPE_CODE (type
))
7500 case TYPE_CODE_STRUCT
:
7502 struct type
*static_type
= to_static_fixed_type (type
);
7503 struct type
*fixed_record_type
=
7504 to_fixed_record_type (type
, valaddr
, address
, NULL
);
7505 /* If STATIC_TYPE is a tagged type and we know the object's address,
7506 then we can determine its tag, and compute the object's actual
7507 type from there. Note that we have to use the fixed record
7508 type (the parent part of the record may have dynamic fields
7509 and the way the location of _tag is expressed may depend on
7512 if (check_tag
&& address
!= 0 && ada_is_tagged_type (static_type
, 0))
7514 struct type
*real_type
=
7515 type_from_tag (value_tag_from_contents_and_address
7519 if (real_type
!= NULL
)
7520 return to_fixed_record_type (real_type
, valaddr
, address
, NULL
);
7522 return fixed_record_type
;
7524 case TYPE_CODE_ARRAY
:
7525 return to_fixed_array_type (type
, dval
, 1);
7526 case TYPE_CODE_UNION
:
7530 return to_fixed_variant_branch_type (type
, valaddr
, address
, dval
);
7534 /* The same as ada_to_fixed_type_1, except that it preserves the type
7535 if it is a TYPE_CODE_TYPEDEF of a type that is already fixed.
7536 ada_to_fixed_type_1 would return the type referenced by TYPE. */
7539 ada_to_fixed_type (struct type
*type
, const gdb_byte
*valaddr
,
7540 CORE_ADDR address
, struct value
*dval
, int check_tag
)
7543 struct type
*fixed_type
=
7544 ada_to_fixed_type_1 (type
, valaddr
, address
, dval
, check_tag
);
7546 if (TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
7547 && TYPE_TARGET_TYPE (type
) == fixed_type
)
7553 /* A standard (static-sized) type corresponding as well as possible to
7554 TYPE0, but based on no runtime data. */
7556 static struct type
*
7557 to_static_fixed_type (struct type
*type0
)
7564 if (TYPE_FLAGS (type0
) & TYPE_FLAG_FIXED_INSTANCE
)
7567 type0
= ada_check_typedef (type0
);
7569 switch (TYPE_CODE (type0
))
7573 case TYPE_CODE_STRUCT
:
7574 type
= dynamic_template_type (type0
);
7576 return template_to_static_fixed_type (type
);
7578 return template_to_static_fixed_type (type0
);
7579 case TYPE_CODE_UNION
:
7580 type
= ada_find_parallel_type (type0
, "___XVU");
7582 return template_to_static_fixed_type (type
);
7584 return template_to_static_fixed_type (type0
);
7588 /* A static approximation of TYPE with all type wrappers removed. */
7590 static struct type
*
7591 static_unwrap_type (struct type
*type
)
7593 if (ada_is_aligner_type (type
))
7595 struct type
*type1
= TYPE_FIELD_TYPE (ada_check_typedef (type
), 0);
7596 if (ada_type_name (type1
) == NULL
)
7597 TYPE_NAME (type1
) = ada_type_name (type
);
7599 return static_unwrap_type (type1
);
7603 struct type
*raw_real_type
= ada_get_base_type (type
);
7604 if (raw_real_type
== type
)
7607 return to_static_fixed_type (raw_real_type
);
7611 /* In some cases, incomplete and private types require
7612 cross-references that are not resolved as records (for example,
7614 type FooP is access Foo;
7616 type Foo is array ...;
7617 ). In these cases, since there is no mechanism for producing
7618 cross-references to such types, we instead substitute for FooP a
7619 stub enumeration type that is nowhere resolved, and whose tag is
7620 the name of the actual type. Call these types "non-record stubs". */
7622 /* A type equivalent to TYPE that is not a non-record stub, if one
7623 exists, otherwise TYPE. */
7626 ada_check_typedef (struct type
*type
)
7631 CHECK_TYPEDEF (type
);
7632 if (type
== NULL
|| TYPE_CODE (type
) != TYPE_CODE_ENUM
7633 || !TYPE_STUB (type
)
7634 || TYPE_TAG_NAME (type
) == NULL
)
7638 char *name
= TYPE_TAG_NAME (type
);
7639 struct type
*type1
= ada_find_any_type (name
);
7640 return (type1
== NULL
) ? type
: type1
;
7644 /* A value representing the data at VALADDR/ADDRESS as described by
7645 type TYPE0, but with a standard (static-sized) type that correctly
7646 describes it. If VAL0 is not NULL and TYPE0 already is a standard
7647 type, then return VAL0 [this feature is simply to avoid redundant
7648 creation of struct values]. */
7650 static struct value
*
7651 ada_to_fixed_value_create (struct type
*type0
, CORE_ADDR address
,
7654 struct type
*type
= ada_to_fixed_type (type0
, 0, address
, NULL
, 1);
7655 if (type
== type0
&& val0
!= NULL
)
7658 return value_from_contents_and_address (type
, 0, address
);
7661 /* A value representing VAL, but with a standard (static-sized) type
7662 that correctly describes it. Does not necessarily create a new
7665 static struct value
*
7666 ada_to_fixed_value (struct value
*val
)
7668 return ada_to_fixed_value_create (value_type (val
),
7669 VALUE_ADDRESS (val
) + value_offset (val
),
7673 /* A value representing VAL, but with a standard (static-sized) type
7674 chosen to approximate the real type of VAL as well as possible, but
7675 without consulting any runtime values. For Ada dynamic-sized
7676 types, therefore, the type of the result is likely to be inaccurate. */
7679 ada_to_static_fixed_value (struct value
*val
)
7682 to_static_fixed_type (static_unwrap_type (value_type (val
)));
7683 if (type
== value_type (val
))
7686 return coerce_unspec_val_to_type (val
, type
);
7692 /* Table mapping attribute numbers to names.
7693 NOTE: Keep up to date with enum ada_attribute definition in ada-lang.h. */
7695 static const char *attribute_names
[] = {
7713 ada_attribute_name (enum exp_opcode n
)
7715 if (n
>= OP_ATR_FIRST
&& n
<= (int) OP_ATR_VAL
)
7716 return attribute_names
[n
- OP_ATR_FIRST
+ 1];
7718 return attribute_names
[0];
7721 /* Evaluate the 'POS attribute applied to ARG. */
7724 pos_atr (struct value
*arg
)
7726 struct type
*type
= value_type (arg
);
7728 if (!discrete_type_p (type
))
7729 error (_("'POS only defined on discrete types"));
7731 if (TYPE_CODE (type
) == TYPE_CODE_ENUM
)
7734 LONGEST v
= value_as_long (arg
);
7736 for (i
= 0; i
< TYPE_NFIELDS (type
); i
+= 1)
7738 if (v
== TYPE_FIELD_BITPOS (type
, i
))
7741 error (_("enumeration value is invalid: can't find 'POS"));
7744 return value_as_long (arg
);
7747 static struct value
*
7748 value_pos_atr (struct value
*arg
)
7750 return value_from_longest (builtin_type_int
, pos_atr (arg
));
7753 /* Evaluate the TYPE'VAL attribute applied to ARG. */
7755 static struct value
*
7756 value_val_atr (struct type
*type
, struct value
*arg
)
7758 if (!discrete_type_p (type
))
7759 error (_("'VAL only defined on discrete types"));
7760 if (!integer_type_p (value_type (arg
)))
7761 error (_("'VAL requires integral argument"));
7763 if (TYPE_CODE (type
) == TYPE_CODE_ENUM
)
7765 long pos
= value_as_long (arg
);
7766 if (pos
< 0 || pos
>= TYPE_NFIELDS (type
))
7767 error (_("argument to 'VAL out of range"));
7768 return value_from_longest (type
, TYPE_FIELD_BITPOS (type
, pos
));
7771 return value_from_longest (type
, value_as_long (arg
));
7777 /* True if TYPE appears to be an Ada character type.
7778 [At the moment, this is true only for Character and Wide_Character;
7779 It is a heuristic test that could stand improvement]. */
7782 ada_is_character_type (struct type
*type
)
7786 /* If the type code says it's a character, then assume it really is,
7787 and don't check any further. */
7788 if (TYPE_CODE (type
) == TYPE_CODE_CHAR
)
7791 /* Otherwise, assume it's a character type iff it is a discrete type
7792 with a known character type name. */
7793 name
= ada_type_name (type
);
7794 return (name
!= NULL
7795 && (TYPE_CODE (type
) == TYPE_CODE_INT
7796 || TYPE_CODE (type
) == TYPE_CODE_RANGE
)
7797 && (strcmp (name
, "character") == 0
7798 || strcmp (name
, "wide_character") == 0
7799 || strcmp (name
, "wide_wide_character") == 0
7800 || strcmp (name
, "unsigned char") == 0));
7803 /* True if TYPE appears to be an Ada string type. */
7806 ada_is_string_type (struct type
*type
)
7808 type
= ada_check_typedef (type
);
7810 && TYPE_CODE (type
) != TYPE_CODE_PTR
7811 && (ada_is_simple_array_type (type
)
7812 || ada_is_array_descriptor_type (type
))
7813 && ada_array_arity (type
) == 1)
7815 struct type
*elttype
= ada_array_element_type (type
, 1);
7817 return ada_is_character_type (elttype
);
7824 /* True if TYPE is a struct type introduced by the compiler to force the
7825 alignment of a value. Such types have a single field with a
7826 distinctive name. */
7829 ada_is_aligner_type (struct type
*type
)
7831 type
= ada_check_typedef (type
);
7833 /* If we can find a parallel XVS type, then the XVS type should
7834 be used instead of this type. And hence, this is not an aligner
7836 if (ada_find_parallel_type (type
, "___XVS") != NULL
)
7839 return (TYPE_CODE (type
) == TYPE_CODE_STRUCT
7840 && TYPE_NFIELDS (type
) == 1
7841 && strcmp (TYPE_FIELD_NAME (type
, 0), "F") == 0);
7844 /* If there is an ___XVS-convention type parallel to SUBTYPE, return
7845 the parallel type. */
7848 ada_get_base_type (struct type
*raw_type
)
7850 struct type
*real_type_namer
;
7851 struct type
*raw_real_type
;
7853 if (raw_type
== NULL
|| TYPE_CODE (raw_type
) != TYPE_CODE_STRUCT
)
7856 real_type_namer
= ada_find_parallel_type (raw_type
, "___XVS");
7857 if (real_type_namer
== NULL
7858 || TYPE_CODE (real_type_namer
) != TYPE_CODE_STRUCT
7859 || TYPE_NFIELDS (real_type_namer
) != 1)
7862 raw_real_type
= ada_find_any_type (TYPE_FIELD_NAME (real_type_namer
, 0));
7863 if (raw_real_type
== NULL
)
7866 return raw_real_type
;
7869 /* The type of value designated by TYPE, with all aligners removed. */
7872 ada_aligned_type (struct type
*type
)
7874 if (ada_is_aligner_type (type
))
7875 return ada_aligned_type (TYPE_FIELD_TYPE (type
, 0));
7877 return ada_get_base_type (type
);
7881 /* The address of the aligned value in an object at address VALADDR
7882 having type TYPE. Assumes ada_is_aligner_type (TYPE). */
7885 ada_aligned_value_addr (struct type
*type
, const gdb_byte
*valaddr
)
7887 if (ada_is_aligner_type (type
))
7888 return ada_aligned_value_addr (TYPE_FIELD_TYPE (type
, 0),
7890 TYPE_FIELD_BITPOS (type
,
7891 0) / TARGET_CHAR_BIT
);
7898 /* The printed representation of an enumeration literal with encoded
7899 name NAME. The value is good to the next call of ada_enum_name. */
7901 ada_enum_name (const char *name
)
7903 static char *result
;
7904 static size_t result_len
= 0;
7907 /* First, unqualify the enumeration name:
7908 1. Search for the last '.' character. If we find one, then skip
7909 all the preceeding characters, the unqualified name starts
7910 right after that dot.
7911 2. Otherwise, we may be debugging on a target where the compiler
7912 translates dots into "__". Search forward for double underscores,
7913 but stop searching when we hit an overloading suffix, which is
7914 of the form "__" followed by digits. */
7916 tmp
= strrchr (name
, '.');
7921 while ((tmp
= strstr (name
, "__")) != NULL
)
7923 if (isdigit (tmp
[2]))
7933 if (name
[1] == 'U' || name
[1] == 'W')
7935 if (sscanf (name
+ 2, "%x", &v
) != 1)
7941 GROW_VECT (result
, result_len
, 16);
7942 if (isascii (v
) && isprint (v
))
7943 sprintf (result
, "'%c'", v
);
7944 else if (name
[1] == 'U')
7945 sprintf (result
, "[\"%02x\"]", v
);
7947 sprintf (result
, "[\"%04x\"]", v
);
7953 tmp
= strstr (name
, "__");
7955 tmp
= strstr (name
, "$");
7958 GROW_VECT (result
, result_len
, tmp
- name
+ 1);
7959 strncpy (result
, name
, tmp
- name
);
7960 result
[tmp
- name
] = '\0';
7968 static struct value
*
7969 evaluate_subexp (struct type
*expect_type
, struct expression
*exp
, int *pos
,
7972 return (*exp
->language_defn
->la_exp_desc
->evaluate_exp
)
7973 (expect_type
, exp
, pos
, noside
);
7976 /* Evaluate the subexpression of EXP starting at *POS as for
7977 evaluate_type, updating *POS to point just past the evaluated
7980 static struct value
*
7981 evaluate_subexp_type (struct expression
*exp
, int *pos
)
7983 return (*exp
->language_defn
->la_exp_desc
->evaluate_exp
)
7984 (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
7987 /* If VAL is wrapped in an aligner or subtype wrapper, return the
7990 static struct value
*
7991 unwrap_value (struct value
*val
)
7993 struct type
*type
= ada_check_typedef (value_type (val
));
7994 if (ada_is_aligner_type (type
))
7996 struct value
*v
= value_struct_elt (&val
, NULL
, "F",
7997 NULL
, "internal structure");
7998 struct type
*val_type
= ada_check_typedef (value_type (v
));
7999 if (ada_type_name (val_type
) == NULL
)
8000 TYPE_NAME (val_type
) = ada_type_name (type
);
8002 return unwrap_value (v
);
8006 struct type
*raw_real_type
=
8007 ada_check_typedef (ada_get_base_type (type
));
8009 if (type
== raw_real_type
)
8013 coerce_unspec_val_to_type
8014 (val
, ada_to_fixed_type (raw_real_type
, 0,
8015 VALUE_ADDRESS (val
) + value_offset (val
),
8020 static struct value
*
8021 cast_to_fixed (struct type
*type
, struct value
*arg
)
8025 if (type
== value_type (arg
))
8027 else if (ada_is_fixed_point_type (value_type (arg
)))
8028 val
= ada_float_to_fixed (type
,
8029 ada_fixed_to_float (value_type (arg
),
8030 value_as_long (arg
)));
8034 value_as_double (value_cast (builtin_type_double
, value_copy (arg
)));
8035 val
= ada_float_to_fixed (type
, argd
);
8038 return value_from_longest (type
, val
);
8041 static struct value
*
8042 cast_from_fixed_to_double (struct value
*arg
)
8044 DOUBLEST val
= ada_fixed_to_float (value_type (arg
),
8045 value_as_long (arg
));
8046 return value_from_double (builtin_type_double
, val
);
8049 /* Coerce VAL as necessary for assignment to an lval of type TYPE, and
8050 return the converted value. */
8052 static struct value
*
8053 coerce_for_assign (struct type
*type
, struct value
*val
)
8055 struct type
*type2
= value_type (val
);
8059 type2
= ada_check_typedef (type2
);
8060 type
= ada_check_typedef (type
);
8062 if (TYPE_CODE (type2
) == TYPE_CODE_PTR
8063 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
)
8065 val
= ada_value_ind (val
);
8066 type2
= value_type (val
);
8069 if (TYPE_CODE (type2
) == TYPE_CODE_ARRAY
8070 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
)
8072 if (TYPE_LENGTH (type2
) != TYPE_LENGTH (type
)
8073 || TYPE_LENGTH (TYPE_TARGET_TYPE (type2
))
8074 != TYPE_LENGTH (TYPE_TARGET_TYPE (type2
)))
8075 error (_("Incompatible types in assignment"));
8076 deprecated_set_value_type (val
, type
);
8081 static struct value
*
8082 ada_value_binop (struct value
*arg1
, struct value
*arg2
, enum exp_opcode op
)
8085 struct type
*type1
, *type2
;
8088 arg1
= coerce_ref (arg1
);
8089 arg2
= coerce_ref (arg2
);
8090 type1
= base_type (ada_check_typedef (value_type (arg1
)));
8091 type2
= base_type (ada_check_typedef (value_type (arg2
)));
8093 if (TYPE_CODE (type1
) != TYPE_CODE_INT
8094 || TYPE_CODE (type2
) != TYPE_CODE_INT
)
8095 return value_binop (arg1
, arg2
, op
);
8104 return value_binop (arg1
, arg2
, op
);
8107 v2
= value_as_long (arg2
);
8109 error (_("second operand of %s must not be zero."), op_string (op
));
8111 if (TYPE_UNSIGNED (type1
) || op
== BINOP_MOD
)
8112 return value_binop (arg1
, arg2
, op
);
8114 v1
= value_as_long (arg1
);
8119 if (!TRUNCATION_TOWARDS_ZERO
&& v1
* (v1
% v2
) < 0)
8120 v
+= v
> 0 ? -1 : 1;
8128 /* Should not reach this point. */
8132 val
= allocate_value (type1
);
8133 store_unsigned_integer (value_contents_raw (val
),
8134 TYPE_LENGTH (value_type (val
)), v
);
8139 ada_value_equal (struct value
*arg1
, struct value
*arg2
)
8141 if (ada_is_direct_array_type (value_type (arg1
))
8142 || ada_is_direct_array_type (value_type (arg2
)))
8144 /* Automatically dereference any array reference before
8145 we attempt to perform the comparison. */
8146 arg1
= ada_coerce_ref (arg1
);
8147 arg2
= ada_coerce_ref (arg2
);
8149 arg1
= ada_coerce_to_simple_array (arg1
);
8150 arg2
= ada_coerce_to_simple_array (arg2
);
8151 if (TYPE_CODE (value_type (arg1
)) != TYPE_CODE_ARRAY
8152 || TYPE_CODE (value_type (arg2
)) != TYPE_CODE_ARRAY
)
8153 error (_("Attempt to compare array with non-array"));
8154 /* FIXME: The following works only for types whose
8155 representations use all bits (no padding or undefined bits)
8156 and do not have user-defined equality. */
8158 TYPE_LENGTH (value_type (arg1
)) == TYPE_LENGTH (value_type (arg2
))
8159 && memcmp (value_contents (arg1
), value_contents (arg2
),
8160 TYPE_LENGTH (value_type (arg1
))) == 0;
8162 return value_equal (arg1
, arg2
);
8165 /* Total number of component associations in the aggregate starting at
8166 index PC in EXP. Assumes that index PC is the start of an
8170 num_component_specs (struct expression
*exp
, int pc
)
8173 m
= exp
->elts
[pc
+ 1].longconst
;
8176 for (i
= 0; i
< m
; i
+= 1)
8178 switch (exp
->elts
[pc
].opcode
)
8184 n
+= exp
->elts
[pc
+ 1].longconst
;
8187 ada_evaluate_subexp (NULL
, exp
, &pc
, EVAL_SKIP
);
8192 /* Assign the result of evaluating EXP starting at *POS to the INDEXth
8193 component of LHS (a simple array or a record), updating *POS past
8194 the expression, assuming that LHS is contained in CONTAINER. Does
8195 not modify the inferior's memory, nor does it modify LHS (unless
8196 LHS == CONTAINER). */
8199 assign_component (struct value
*container
, struct value
*lhs
, LONGEST index
,
8200 struct expression
*exp
, int *pos
)
8202 struct value
*mark
= value_mark ();
8204 if (TYPE_CODE (value_type (lhs
)) == TYPE_CODE_ARRAY
)
8206 struct value
*index_val
= value_from_longest (builtin_type_int
, index
);
8207 elt
= unwrap_value (ada_value_subscript (lhs
, 1, &index_val
));
8211 elt
= ada_index_struct_field (index
, lhs
, 0, value_type (lhs
));
8212 elt
= ada_to_fixed_value (unwrap_value (elt
));
8215 if (exp
->elts
[*pos
].opcode
== OP_AGGREGATE
)
8216 assign_aggregate (container
, elt
, exp
, pos
, EVAL_NORMAL
);
8218 value_assign_to_component (container
, elt
,
8219 ada_evaluate_subexp (NULL
, exp
, pos
,
8222 value_free_to_mark (mark
);
8225 /* Assuming that LHS represents an lvalue having a record or array
8226 type, and EXP->ELTS[*POS] is an OP_AGGREGATE, evaluate an assignment
8227 of that aggregate's value to LHS, advancing *POS past the
8228 aggregate. NOSIDE is as for evaluate_subexp. CONTAINER is an
8229 lvalue containing LHS (possibly LHS itself). Does not modify
8230 the inferior's memory, nor does it modify the contents of
8231 LHS (unless == CONTAINER). Returns the modified CONTAINER. */
8233 static struct value
*
8234 assign_aggregate (struct value
*container
,
8235 struct value
*lhs
, struct expression
*exp
,
8236 int *pos
, enum noside noside
)
8238 struct type
*lhs_type
;
8239 int n
= exp
->elts
[*pos
+1].longconst
;
8240 LONGEST low_index
, high_index
;
8243 int max_indices
, num_indices
;
8244 int is_array_aggregate
;
8246 struct value
*mark
= value_mark ();
8249 if (noside
!= EVAL_NORMAL
)
8252 for (i
= 0; i
< n
; i
+= 1)
8253 ada_evaluate_subexp (NULL
, exp
, pos
, noside
);
8257 container
= ada_coerce_ref (container
);
8258 if (ada_is_direct_array_type (value_type (container
)))
8259 container
= ada_coerce_to_simple_array (container
);
8260 lhs
= ada_coerce_ref (lhs
);
8261 if (!deprecated_value_modifiable (lhs
))
8262 error (_("Left operand of assignment is not a modifiable lvalue."));
8264 lhs_type
= value_type (lhs
);
8265 if (ada_is_direct_array_type (lhs_type
))
8267 lhs
= ada_coerce_to_simple_array (lhs
);
8268 lhs_type
= value_type (lhs
);
8269 low_index
= TYPE_ARRAY_LOWER_BOUND_VALUE (lhs_type
);
8270 high_index
= TYPE_ARRAY_UPPER_BOUND_VALUE (lhs_type
);
8271 is_array_aggregate
= 1;
8273 else if (TYPE_CODE (lhs_type
) == TYPE_CODE_STRUCT
)
8276 high_index
= num_visible_fields (lhs_type
) - 1;
8277 is_array_aggregate
= 0;
8280 error (_("Left-hand side must be array or record."));
8282 num_specs
= num_component_specs (exp
, *pos
- 3);
8283 max_indices
= 4 * num_specs
+ 4;
8284 indices
= alloca (max_indices
* sizeof (indices
[0]));
8285 indices
[0] = indices
[1] = low_index
- 1;
8286 indices
[2] = indices
[3] = high_index
+ 1;
8289 for (i
= 0; i
< n
; i
+= 1)
8291 switch (exp
->elts
[*pos
].opcode
)
8294 aggregate_assign_from_choices (container
, lhs
, exp
, pos
, indices
,
8295 &num_indices
, max_indices
,
8296 low_index
, high_index
);
8299 aggregate_assign_positional (container
, lhs
, exp
, pos
, indices
,
8300 &num_indices
, max_indices
,
8301 low_index
, high_index
);
8305 error (_("Misplaced 'others' clause"));
8306 aggregate_assign_others (container
, lhs
, exp
, pos
, indices
,
8307 num_indices
, low_index
, high_index
);
8310 error (_("Internal error: bad aggregate clause"));
8317 /* Assign into the component of LHS indexed by the OP_POSITIONAL
8318 construct at *POS, updating *POS past the construct, given that
8319 the positions are relative to lower bound LOW, where HIGH is the
8320 upper bound. Record the position in INDICES[0 .. MAX_INDICES-1]
8321 updating *NUM_INDICES as needed. CONTAINER is as for
8322 assign_aggregate. */
8324 aggregate_assign_positional (struct value
*container
,
8325 struct value
*lhs
, struct expression
*exp
,
8326 int *pos
, LONGEST
*indices
, int *num_indices
,
8327 int max_indices
, LONGEST low
, LONGEST high
)
8329 LONGEST ind
= longest_to_int (exp
->elts
[*pos
+ 1].longconst
) + low
;
8331 if (ind
- 1 == high
)
8332 warning (_("Extra components in aggregate ignored."));
8335 add_component_interval (ind
, ind
, indices
, num_indices
, max_indices
);
8337 assign_component (container
, lhs
, ind
, exp
, pos
);
8340 ada_evaluate_subexp (NULL
, exp
, pos
, EVAL_SKIP
);
8343 /* Assign into the components of LHS indexed by the OP_CHOICES
8344 construct at *POS, updating *POS past the construct, given that
8345 the allowable indices are LOW..HIGH. Record the indices assigned
8346 to in INDICES[0 .. MAX_INDICES-1], updating *NUM_INDICES as
8347 needed. CONTAINER is as for assign_aggregate. */
8349 aggregate_assign_from_choices (struct value
*container
,
8350 struct value
*lhs
, struct expression
*exp
,
8351 int *pos
, LONGEST
*indices
, int *num_indices
,
8352 int max_indices
, LONGEST low
, LONGEST high
)
8355 int n_choices
= longest_to_int (exp
->elts
[*pos
+1].longconst
);
8356 int choice_pos
, expr_pc
;
8357 int is_array
= ada_is_direct_array_type (value_type (lhs
));
8359 choice_pos
= *pos
+= 3;
8361 for (j
= 0; j
< n_choices
; j
+= 1)
8362 ada_evaluate_subexp (NULL
, exp
, pos
, EVAL_SKIP
);
8364 ada_evaluate_subexp (NULL
, exp
, pos
, EVAL_SKIP
);
8366 for (j
= 0; j
< n_choices
; j
+= 1)
8368 LONGEST lower
, upper
;
8369 enum exp_opcode op
= exp
->elts
[choice_pos
].opcode
;
8370 if (op
== OP_DISCRETE_RANGE
)
8373 lower
= value_as_long (ada_evaluate_subexp (NULL
, exp
, pos
,
8375 upper
= value_as_long (ada_evaluate_subexp (NULL
, exp
, pos
,
8380 lower
= value_as_long (ada_evaluate_subexp (NULL
, exp
, &choice_pos
,
8391 name
= &exp
->elts
[choice_pos
+ 2].string
;
8394 name
= SYMBOL_NATURAL_NAME (exp
->elts
[choice_pos
+ 2].symbol
);
8397 error (_("Invalid record component association."));
8399 ada_evaluate_subexp (NULL
, exp
, &choice_pos
, EVAL_SKIP
);
8401 if (! find_struct_field (name
, value_type (lhs
), 0,
8402 NULL
, NULL
, NULL
, NULL
, &ind
))
8403 error (_("Unknown component name: %s."), name
);
8404 lower
= upper
= ind
;
8407 if (lower
<= upper
&& (lower
< low
|| upper
> high
))
8408 error (_("Index in component association out of bounds."));
8410 add_component_interval (lower
, upper
, indices
, num_indices
,
8412 while (lower
<= upper
)
8416 assign_component (container
, lhs
, lower
, exp
, &pos1
);
8422 /* Assign the value of the expression in the OP_OTHERS construct in
8423 EXP at *POS into the components of LHS indexed from LOW .. HIGH that
8424 have not been previously assigned. The index intervals already assigned
8425 are in INDICES[0 .. NUM_INDICES-1]. Updates *POS to after the
8426 OP_OTHERS clause. CONTAINER is as for assign_aggregate*/
8428 aggregate_assign_others (struct value
*container
,
8429 struct value
*lhs
, struct expression
*exp
,
8430 int *pos
, LONGEST
*indices
, int num_indices
,
8431 LONGEST low
, LONGEST high
)
8434 int expr_pc
= *pos
+1;
8436 for (i
= 0; i
< num_indices
- 2; i
+= 2)
8439 for (ind
= indices
[i
+ 1] + 1; ind
< indices
[i
+ 2]; ind
+= 1)
8443 assign_component (container
, lhs
, ind
, exp
, &pos
);
8446 ada_evaluate_subexp (NULL
, exp
, pos
, EVAL_SKIP
);
8449 /* Add the interval [LOW .. HIGH] to the sorted set of intervals
8450 [ INDICES[0] .. INDICES[1] ],..., [ INDICES[*SIZE-2] .. INDICES[*SIZE-1] ],
8451 modifying *SIZE as needed. It is an error if *SIZE exceeds
8452 MAX_SIZE. The resulting intervals do not overlap. */
8454 add_component_interval (LONGEST low
, LONGEST high
,
8455 LONGEST
* indices
, int *size
, int max_size
)
8458 for (i
= 0; i
< *size
; i
+= 2) {
8459 if (high
>= indices
[i
] && low
<= indices
[i
+ 1])
8462 for (kh
= i
+ 2; kh
< *size
; kh
+= 2)
8463 if (high
< indices
[kh
])
8465 if (low
< indices
[i
])
8467 indices
[i
+ 1] = indices
[kh
- 1];
8468 if (high
> indices
[i
+ 1])
8469 indices
[i
+ 1] = high
;
8470 memcpy (indices
+ i
+ 2, indices
+ kh
, *size
- kh
);
8471 *size
-= kh
- i
- 2;
8474 else if (high
< indices
[i
])
8478 if (*size
== max_size
)
8479 error (_("Internal error: miscounted aggregate components."));
8481 for (j
= *size
-1; j
>= i
+2; j
-= 1)
8482 indices
[j
] = indices
[j
- 2];
8484 indices
[i
+ 1] = high
;
8487 /* Perform and Ada cast of ARG2 to type TYPE if the type of ARG2
8490 static struct value
*
8491 ada_value_cast (struct type
*type
, struct value
*arg2
, enum noside noside
)
8493 if (type
== ada_check_typedef (value_type (arg2
)))
8496 if (ada_is_fixed_point_type (type
))
8497 return (cast_to_fixed (type
, arg2
));
8499 if (ada_is_fixed_point_type (value_type (arg2
)))
8500 return value_cast (type
, cast_from_fixed_to_double (arg2
));
8502 return value_cast (type
, arg2
);
8505 static struct value
*
8506 ada_evaluate_subexp (struct type
*expect_type
, struct expression
*exp
,
8507 int *pos
, enum noside noside
)
8510 int tem
, tem2
, tem3
;
8512 struct value
*arg1
= NULL
, *arg2
= NULL
, *arg3
;
8515 struct value
**argvec
;
8519 op
= exp
->elts
[pc
].opcode
;
8525 arg1
= evaluate_subexp_standard (expect_type
, exp
, pos
, noside
);
8526 arg1
= unwrap_value (arg1
);
8528 /* If evaluating an OP_DOUBLE and an EXPECT_TYPE was provided,
8529 then we need to perform the conversion manually, because
8530 evaluate_subexp_standard doesn't do it. This conversion is
8531 necessary in Ada because the different kinds of float/fixed
8532 types in Ada have different representations.
8534 Similarly, we need to perform the conversion from OP_LONG
8536 if ((op
== OP_DOUBLE
|| op
== OP_LONG
) && expect_type
!= NULL
)
8537 arg1
= ada_value_cast (expect_type
, arg1
, noside
);
8543 struct value
*result
;
8545 result
= evaluate_subexp_standard (expect_type
, exp
, pos
, noside
);
8546 /* The result type will have code OP_STRING, bashed there from
8547 OP_ARRAY. Bash it back. */
8548 if (TYPE_CODE (value_type (result
)) == TYPE_CODE_STRING
)
8549 TYPE_CODE (value_type (result
)) = TYPE_CODE_ARRAY
;
8555 type
= exp
->elts
[pc
+ 1].type
;
8556 arg1
= evaluate_subexp (type
, exp
, pos
, noside
);
8557 if (noside
== EVAL_SKIP
)
8559 arg1
= ada_value_cast (type
, arg1
, noside
);
8564 type
= exp
->elts
[pc
+ 1].type
;
8565 return ada_evaluate_subexp (type
, exp
, pos
, noside
);
8568 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
8569 if (exp
->elts
[*pos
].opcode
== OP_AGGREGATE
)
8571 arg1
= assign_aggregate (arg1
, arg1
, exp
, pos
, noside
);
8572 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
8574 return ada_value_assign (arg1
, arg1
);
8576 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
8577 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
8579 if (ada_is_fixed_point_type (value_type (arg1
)))
8580 arg2
= cast_to_fixed (value_type (arg1
), arg2
);
8581 else if (ada_is_fixed_point_type (value_type (arg2
)))
8583 (_("Fixed-point values must be assigned to fixed-point variables"));
8585 arg2
= coerce_for_assign (value_type (arg1
), arg2
);
8586 return ada_value_assign (arg1
, arg2
);
8589 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
8590 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
8591 if (noside
== EVAL_SKIP
)
8593 if ((ada_is_fixed_point_type (value_type (arg1
))
8594 || ada_is_fixed_point_type (value_type (arg2
)))
8595 && value_type (arg1
) != value_type (arg2
))
8596 error (_("Operands of fixed-point addition must have the same type"));
8597 /* Do the addition, and cast the result to the type of the first
8598 argument. We cannot cast the result to a reference type, so if
8599 ARG1 is a reference type, find its underlying type. */
8600 type
= value_type (arg1
);
8601 while (TYPE_CODE (type
) == TYPE_CODE_REF
)
8602 type
= TYPE_TARGET_TYPE (type
);
8603 return value_cast (type
, value_add (arg1
, arg2
));
8606 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
8607 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
8608 if (noside
== EVAL_SKIP
)
8610 if ((ada_is_fixed_point_type (value_type (arg1
))
8611 || ada_is_fixed_point_type (value_type (arg2
)))
8612 && value_type (arg1
) != value_type (arg2
))
8613 error (_("Operands of fixed-point subtraction must have the same type"));
8614 /* Do the substraction, and cast the result to the type of the first
8615 argument. We cannot cast the result to a reference type, so if
8616 ARG1 is a reference type, find its underlying type. */
8617 type
= value_type (arg1
);
8618 while (TYPE_CODE (type
) == TYPE_CODE_REF
)
8619 type
= TYPE_TARGET_TYPE (type
);
8620 return value_cast (type
, value_sub (arg1
, arg2
));
8624 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
8625 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
8626 if (noside
== EVAL_SKIP
)
8628 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
8629 && (op
== BINOP_DIV
|| op
== BINOP_REM
|| op
== BINOP_MOD
))
8630 return value_zero (value_type (arg1
), not_lval
);
8633 if (ada_is_fixed_point_type (value_type (arg1
)))
8634 arg1
= cast_from_fixed_to_double (arg1
);
8635 if (ada_is_fixed_point_type (value_type (arg2
)))
8636 arg2
= cast_from_fixed_to_double (arg2
);
8637 return ada_value_binop (arg1
, arg2
, op
);
8642 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
8643 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
8644 if (noside
== EVAL_SKIP
)
8646 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
8647 && (op
== BINOP_DIV
|| op
== BINOP_REM
|| op
== BINOP_MOD
))
8648 return value_zero (value_type (arg1
), not_lval
);
8650 return ada_value_binop (arg1
, arg2
, op
);
8653 case BINOP_NOTEQUAL
:
8654 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
8655 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
8656 if (noside
== EVAL_SKIP
)
8658 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
8661 tem
= ada_value_equal (arg1
, arg2
);
8662 if (op
== BINOP_NOTEQUAL
)
8664 return value_from_longest (LA_BOOL_TYPE
, (LONGEST
) tem
);
8667 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
8668 if (noside
== EVAL_SKIP
)
8670 else if (ada_is_fixed_point_type (value_type (arg1
)))
8671 return value_cast (value_type (arg1
), value_neg (arg1
));
8673 return value_neg (arg1
);
8675 case BINOP_LOGICAL_AND
:
8676 case BINOP_LOGICAL_OR
:
8677 case UNOP_LOGICAL_NOT
:
8682 val
= evaluate_subexp_standard (expect_type
, exp
, pos
, noside
);
8683 return value_cast (LA_BOOL_TYPE
, val
);
8686 case BINOP_BITWISE_AND
:
8687 case BINOP_BITWISE_IOR
:
8688 case BINOP_BITWISE_XOR
:
8692 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
8694 val
= evaluate_subexp_standard (expect_type
, exp
, pos
, noside
);
8696 return value_cast (value_type (arg1
), val
);
8702 /* Tagged types are a little special in the fact that the real type
8703 is dynamic and can only be determined by inspecting the object
8704 value. So even if we're support to do an EVAL_AVOID_SIDE_EFFECTS
8705 evaluation, we force an EVAL_NORMAL evaluation for tagged types. */
8706 if (noside
== EVAL_AVOID_SIDE_EFFECTS
8707 && ada_is_tagged_type (SYMBOL_TYPE (exp
->elts
[pc
+ 2].symbol
), 1))
8708 noside
= EVAL_NORMAL
;
8710 if (noside
== EVAL_SKIP
)
8715 else if (SYMBOL_DOMAIN (exp
->elts
[pc
+ 2].symbol
) == UNDEF_DOMAIN
)
8716 /* Only encountered when an unresolved symbol occurs in a
8717 context other than a function call, in which case, it is
8719 error (_("Unexpected unresolved symbol, %s, during evaluation"),
8720 SYMBOL_PRINT_NAME (exp
->elts
[pc
+ 2].symbol
));
8721 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
8725 (to_static_fixed_type
8726 (static_unwrap_type (SYMBOL_TYPE (exp
->elts
[pc
+ 2].symbol
))),
8732 unwrap_value (evaluate_subexp_standard
8733 (expect_type
, exp
, pos
, noside
));
8734 return ada_to_fixed_value (arg1
);
8740 /* Allocate arg vector, including space for the function to be
8741 called in argvec[0] and a terminating NULL. */
8742 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
8744 (struct value
**) alloca (sizeof (struct value
*) * (nargs
+ 2));
8746 if (exp
->elts
[*pos
].opcode
== OP_VAR_VALUE
8747 && SYMBOL_DOMAIN (exp
->elts
[pc
+ 5].symbol
) == UNDEF_DOMAIN
)
8748 error (_("Unexpected unresolved symbol, %s, during evaluation"),
8749 SYMBOL_PRINT_NAME (exp
->elts
[pc
+ 5].symbol
));
8752 for (tem
= 0; tem
<= nargs
; tem
+= 1)
8753 argvec
[tem
] = evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
8756 if (noside
== EVAL_SKIP
)
8760 if (ada_is_packed_array_type (desc_base_type (value_type (argvec
[0]))))
8761 argvec
[0] = ada_coerce_to_simple_array (argvec
[0]);
8762 else if (TYPE_CODE (value_type (argvec
[0])) == TYPE_CODE_REF
8763 || (TYPE_CODE (value_type (argvec
[0])) == TYPE_CODE_ARRAY
8764 && VALUE_LVAL (argvec
[0]) == lval_memory
))
8765 argvec
[0] = value_addr (argvec
[0]);
8767 type
= ada_check_typedef (value_type (argvec
[0]));
8768 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
8770 switch (TYPE_CODE (ada_check_typedef (TYPE_TARGET_TYPE (type
))))
8772 case TYPE_CODE_FUNC
:
8773 type
= ada_check_typedef (TYPE_TARGET_TYPE (type
));
8775 case TYPE_CODE_ARRAY
:
8777 case TYPE_CODE_STRUCT
:
8778 if (noside
!= EVAL_AVOID_SIDE_EFFECTS
)
8779 argvec
[0] = ada_value_ind (argvec
[0]);
8780 type
= ada_check_typedef (TYPE_TARGET_TYPE (type
));
8783 error (_("cannot subscript or call something of type `%s'"),
8784 ada_type_name (value_type (argvec
[0])));
8789 switch (TYPE_CODE (type
))
8791 case TYPE_CODE_FUNC
:
8792 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
8793 return allocate_value (TYPE_TARGET_TYPE (type
));
8794 return call_function_by_hand (argvec
[0], nargs
, argvec
+ 1);
8795 case TYPE_CODE_STRUCT
:
8799 arity
= ada_array_arity (type
);
8800 type
= ada_array_element_type (type
, nargs
);
8802 error (_("cannot subscript or call a record"));
8804 error (_("wrong number of subscripts; expecting %d"), arity
);
8805 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
8806 return value_zero (ada_aligned_type (type
), lval_memory
);
8808 unwrap_value (ada_value_subscript
8809 (argvec
[0], nargs
, argvec
+ 1));
8811 case TYPE_CODE_ARRAY
:
8812 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
8814 type
= ada_array_element_type (type
, nargs
);
8816 error (_("element type of array unknown"));
8818 return value_zero (ada_aligned_type (type
), lval_memory
);
8821 unwrap_value (ada_value_subscript
8822 (ada_coerce_to_simple_array (argvec
[0]),
8823 nargs
, argvec
+ 1));
8824 case TYPE_CODE_PTR
: /* Pointer to array */
8825 type
= to_fixed_array_type (TYPE_TARGET_TYPE (type
), NULL
, 1);
8826 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
8828 type
= ada_array_element_type (type
, nargs
);
8830 error (_("element type of array unknown"));
8832 return value_zero (ada_aligned_type (type
), lval_memory
);
8835 unwrap_value (ada_value_ptr_subscript (argvec
[0], type
,
8836 nargs
, argvec
+ 1));
8839 error (_("Attempt to index or call something other than an "
8840 "array or function"));
8845 struct value
*array
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
8846 struct value
*low_bound_val
=
8847 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
8848 struct value
*high_bound_val
=
8849 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
8852 low_bound_val
= coerce_ref (low_bound_val
);
8853 high_bound_val
= coerce_ref (high_bound_val
);
8854 low_bound
= pos_atr (low_bound_val
);
8855 high_bound
= pos_atr (high_bound_val
);
8857 if (noside
== EVAL_SKIP
)
8860 /* If this is a reference to an aligner type, then remove all
8862 if (TYPE_CODE (value_type (array
)) == TYPE_CODE_REF
8863 && ada_is_aligner_type (TYPE_TARGET_TYPE (value_type (array
))))
8864 TYPE_TARGET_TYPE (value_type (array
)) =
8865 ada_aligned_type (TYPE_TARGET_TYPE (value_type (array
)));
8867 if (ada_is_packed_array_type (value_type (array
)))
8868 error (_("cannot slice a packed array"));
8870 /* If this is a reference to an array or an array lvalue,
8871 convert to a pointer. */
8872 if (TYPE_CODE (value_type (array
)) == TYPE_CODE_REF
8873 || (TYPE_CODE (value_type (array
)) == TYPE_CODE_ARRAY
8874 && VALUE_LVAL (array
) == lval_memory
))
8875 array
= value_addr (array
);
8877 if (noside
== EVAL_AVOID_SIDE_EFFECTS
8878 && ada_is_array_descriptor_type (ada_check_typedef
8879 (value_type (array
))))
8880 return empty_array (ada_type_of_array (array
, 0), low_bound
);
8882 array
= ada_coerce_to_simple_array_ptr (array
);
8884 /* If we have more than one level of pointer indirection,
8885 dereference the value until we get only one level. */
8886 while (TYPE_CODE (value_type (array
)) == TYPE_CODE_PTR
8887 && (TYPE_CODE (TYPE_TARGET_TYPE (value_type (array
)))
8889 array
= value_ind (array
);
8891 /* Make sure we really do have an array type before going further,
8892 to avoid a SEGV when trying to get the index type or the target
8893 type later down the road if the debug info generated by
8894 the compiler is incorrect or incomplete. */
8895 if (!ada_is_simple_array_type (value_type (array
)))
8896 error (_("cannot take slice of non-array"));
8898 if (TYPE_CODE (value_type (array
)) == TYPE_CODE_PTR
)
8900 if (high_bound
< low_bound
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
8901 return empty_array (TYPE_TARGET_TYPE (value_type (array
)),
8905 struct type
*arr_type0
=
8906 to_fixed_array_type (TYPE_TARGET_TYPE (value_type (array
)),
8908 return ada_value_slice_ptr (array
, arr_type0
,
8909 longest_to_int (low_bound
),
8910 longest_to_int (high_bound
));
8913 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
8915 else if (high_bound
< low_bound
)
8916 return empty_array (value_type (array
), low_bound
);
8918 return ada_value_slice (array
, longest_to_int (low_bound
),
8919 longest_to_int (high_bound
));
8924 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
8925 type
= exp
->elts
[pc
+ 1].type
;
8927 if (noside
== EVAL_SKIP
)
8930 switch (TYPE_CODE (type
))
8933 lim_warning (_("Membership test incompletely implemented; "
8934 "always returns true"));
8935 return value_from_longest (builtin_type_int
, (LONGEST
) 1);
8937 case TYPE_CODE_RANGE
:
8938 arg2
= value_from_longest (builtin_type_int
, TYPE_LOW_BOUND (type
));
8939 arg3
= value_from_longest (builtin_type_int
,
8940 TYPE_HIGH_BOUND (type
));
8942 value_from_longest (builtin_type_int
,
8943 (value_less (arg1
, arg3
)
8944 || value_equal (arg1
, arg3
))
8945 && (value_less (arg2
, arg1
)
8946 || value_equal (arg2
, arg1
)));
8949 case BINOP_IN_BOUNDS
:
8951 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
8952 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
8954 if (noside
== EVAL_SKIP
)
8957 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
8958 return value_zero (builtin_type_int
, not_lval
);
8960 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
8962 if (tem
< 1 || tem
> ada_array_arity (value_type (arg2
)))
8963 error (_("invalid dimension number to 'range"));
8965 arg3
= ada_array_bound (arg2
, tem
, 1);
8966 arg2
= ada_array_bound (arg2
, tem
, 0);
8969 value_from_longest (builtin_type_int
,
8970 (value_less (arg1
, arg3
)
8971 || value_equal (arg1
, arg3
))
8972 && (value_less (arg2
, arg1
)
8973 || value_equal (arg2
, arg1
)));
8975 case TERNOP_IN_RANGE
:
8976 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
8977 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
8978 arg3
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
8980 if (noside
== EVAL_SKIP
)
8984 value_from_longest (builtin_type_int
,
8985 (value_less (arg1
, arg3
)
8986 || value_equal (arg1
, arg3
))
8987 && (value_less (arg2
, arg1
)
8988 || value_equal (arg2
, arg1
)));
8994 struct type
*type_arg
;
8995 if (exp
->elts
[*pos
].opcode
== OP_TYPE
)
8997 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
8999 type_arg
= exp
->elts
[pc
+ 2].type
;
9003 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
9007 if (exp
->elts
[*pos
].opcode
!= OP_LONG
)
9008 error (_("Invalid operand to '%s"), ada_attribute_name (op
));
9009 tem
= longest_to_int (exp
->elts
[*pos
+ 2].longconst
);
9012 if (noside
== EVAL_SKIP
)
9015 if (type_arg
== NULL
)
9017 arg1
= ada_coerce_ref (arg1
);
9019 if (ada_is_packed_array_type (value_type (arg1
)))
9020 arg1
= ada_coerce_to_simple_array (arg1
);
9022 if (tem
< 1 || tem
> ada_array_arity (value_type (arg1
)))
9023 error (_("invalid dimension number to '%s"),
9024 ada_attribute_name (op
));
9026 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
9028 type
= ada_index_type (value_type (arg1
), tem
);
9031 (_("attempt to take bound of something that is not an array"));
9032 return allocate_value (type
);
9037 default: /* Should never happen. */
9038 error (_("unexpected attribute encountered"));
9040 return ada_array_bound (arg1
, tem
, 0);
9042 return ada_array_bound (arg1
, tem
, 1);
9044 return ada_array_length (arg1
, tem
);
9047 else if (discrete_type_p (type_arg
))
9049 struct type
*range_type
;
9050 char *name
= ada_type_name (type_arg
);
9052 if (name
!= NULL
&& TYPE_CODE (type_arg
) != TYPE_CODE_ENUM
)
9054 to_fixed_range_type (name
, NULL
, TYPE_OBJFILE (type_arg
));
9055 if (range_type
== NULL
)
9056 range_type
= type_arg
;
9060 error (_("unexpected attribute encountered"));
9062 return discrete_type_low_bound (range_type
);
9064 return discrete_type_high_bound (range_type
);
9066 error (_("the 'length attribute applies only to array types"));
9069 else if (TYPE_CODE (type_arg
) == TYPE_CODE_FLT
)
9070 error (_("unimplemented type attribute"));
9075 if (ada_is_packed_array_type (type_arg
))
9076 type_arg
= decode_packed_array_type (type_arg
);
9078 if (tem
< 1 || tem
> ada_array_arity (type_arg
))
9079 error (_("invalid dimension number to '%s"),
9080 ada_attribute_name (op
));
9082 type
= ada_index_type (type_arg
, tem
);
9085 (_("attempt to take bound of something that is not an array"));
9086 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
9087 return allocate_value (type
);
9092 error (_("unexpected attribute encountered"));
9094 low
= ada_array_bound_from_type (type_arg
, tem
, 0, &type
);
9095 return value_from_longest (type
, low
);
9097 high
= ada_array_bound_from_type (type_arg
, tem
, 1, &type
);
9098 return value_from_longest (type
, high
);
9100 low
= ada_array_bound_from_type (type_arg
, tem
, 0, &type
);
9101 high
= ada_array_bound_from_type (type_arg
, tem
, 1, NULL
);
9102 return value_from_longest (type
, high
- low
+ 1);
9108 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
9109 if (noside
== EVAL_SKIP
)
9112 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
9113 return value_zero (ada_tag_type (arg1
), not_lval
);
9115 return ada_value_tag (arg1
);
9119 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
9120 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
9121 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
9122 if (noside
== EVAL_SKIP
)
9124 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
9125 return value_zero (value_type (arg1
), not_lval
);
9127 return value_binop (arg1
, arg2
,
9128 op
== OP_ATR_MIN
? BINOP_MIN
: BINOP_MAX
);
9130 case OP_ATR_MODULUS
:
9132 struct type
*type_arg
= exp
->elts
[pc
+ 2].type
;
9133 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
9135 if (noside
== EVAL_SKIP
)
9138 if (!ada_is_modular_type (type_arg
))
9139 error (_("'modulus must be applied to modular type"));
9141 return value_from_longest (TYPE_TARGET_TYPE (type_arg
),
9142 ada_modulus (type_arg
));
9147 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
9148 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
9149 if (noside
== EVAL_SKIP
)
9151 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
9152 return value_zero (builtin_type_int
, not_lval
);
9154 return value_pos_atr (arg1
);
9157 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
9158 if (noside
== EVAL_SKIP
)
9160 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
9161 return value_zero (builtin_type_int
, not_lval
);
9163 return value_from_longest (builtin_type_int
,
9165 * TYPE_LENGTH (value_type (arg1
)));
9168 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
9169 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
9170 type
= exp
->elts
[pc
+ 2].type
;
9171 if (noside
== EVAL_SKIP
)
9173 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
9174 return value_zero (type
, not_lval
);
9176 return value_val_atr (type
, arg1
);
9179 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
9180 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
9181 if (noside
== EVAL_SKIP
)
9183 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
9184 return value_zero (value_type (arg1
), not_lval
);
9186 return value_binop (arg1
, arg2
, op
);
9189 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
9190 if (noside
== EVAL_SKIP
)
9196 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
9197 if (noside
== EVAL_SKIP
)
9199 if (value_less (arg1
, value_zero (value_type (arg1
), not_lval
)))
9200 return value_neg (arg1
);
9205 if (expect_type
&& TYPE_CODE (expect_type
) == TYPE_CODE_PTR
)
9206 expect_type
= TYPE_TARGET_TYPE (ada_check_typedef (expect_type
));
9207 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
9208 if (noside
== EVAL_SKIP
)
9210 type
= ada_check_typedef (value_type (arg1
));
9211 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
9213 if (ada_is_array_descriptor_type (type
))
9214 /* GDB allows dereferencing GNAT array descriptors. */
9216 struct type
*arrType
= ada_type_of_array (arg1
, 0);
9217 if (arrType
== NULL
)
9218 error (_("Attempt to dereference null array pointer."));
9219 return value_at_lazy (arrType
, 0);
9221 else if (TYPE_CODE (type
) == TYPE_CODE_PTR
9222 || TYPE_CODE (type
) == TYPE_CODE_REF
9223 /* In C you can dereference an array to get the 1st elt. */
9224 || TYPE_CODE (type
) == TYPE_CODE_ARRAY
)
9226 type
= to_static_fixed_type
9228 (ada_check_typedef (TYPE_TARGET_TYPE (type
))));
9230 return value_zero (type
, lval_memory
);
9232 else if (TYPE_CODE (type
) == TYPE_CODE_INT
)
9233 /* GDB allows dereferencing an int. */
9234 return value_zero (builtin_type_int
, lval_memory
);
9236 error (_("Attempt to take contents of a non-pointer value."));
9238 arg1
= ada_coerce_ref (arg1
); /* FIXME: What is this for?? */
9239 type
= ada_check_typedef (value_type (arg1
));
9241 if (ada_is_array_descriptor_type (type
))
9242 /* GDB allows dereferencing GNAT array descriptors. */
9243 return ada_coerce_to_simple_array (arg1
);
9245 return ada_value_ind (arg1
);
9247 case STRUCTOP_STRUCT
:
9248 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
9249 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
9250 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
9251 if (noside
== EVAL_SKIP
)
9253 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
9255 struct type
*type1
= value_type (arg1
);
9256 if (ada_is_tagged_type (type1
, 1))
9258 type
= ada_lookup_struct_elt_type (type1
,
9259 &exp
->elts
[pc
+ 2].string
,
9262 /* In this case, we assume that the field COULD exist
9263 in some extension of the type. Return an object of
9264 "type" void, which will match any formal
9265 (see ada_type_match). */
9266 return value_zero (builtin_type_void
, lval_memory
);
9270 ada_lookup_struct_elt_type (type1
, &exp
->elts
[pc
+ 2].string
, 1,
9273 return value_zero (ada_aligned_type (type
), lval_memory
);
9277 ada_to_fixed_value (unwrap_value
9278 (ada_value_struct_elt
9279 (arg1
, &exp
->elts
[pc
+ 2].string
, 0)));
9281 /* The value is not supposed to be used. This is here to make it
9282 easier to accommodate expressions that contain types. */
9284 if (noside
== EVAL_SKIP
)
9286 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
9287 return allocate_value (exp
->elts
[pc
+ 1].type
);
9289 error (_("Attempt to use a type name as an expression"));
9294 case OP_DISCRETE_RANGE
:
9297 if (noside
== EVAL_NORMAL
)
9301 error (_("Undefined name, ambiguous name, or renaming used in "
9302 "component association: %s."), &exp
->elts
[pc
+2].string
);
9304 error (_("Aggregates only allowed on the right of an assignment"));
9306 internal_error (__FILE__
, __LINE__
, _("aggregate apparently mangled"));
9309 ada_forward_operator_length (exp
, pc
, &oplen
, &nargs
);
9311 for (tem
= 0; tem
< nargs
; tem
+= 1)
9312 ada_evaluate_subexp (NULL
, exp
, pos
, noside
);
9317 return value_from_longest (builtin_type_long
, (LONGEST
) 1);
9323 /* If TYPE encodes an Ada fixed-point type, return the suffix of the
9324 type name that encodes the 'small and 'delta information.
9325 Otherwise, return NULL. */
9328 fixed_type_info (struct type
*type
)
9330 const char *name
= ada_type_name (type
);
9331 enum type_code code
= (type
== NULL
) ? TYPE_CODE_UNDEF
: TYPE_CODE (type
);
9333 if ((code
== TYPE_CODE_INT
|| code
== TYPE_CODE_RANGE
) && name
!= NULL
)
9335 const char *tail
= strstr (name
, "___XF_");
9341 else if (code
== TYPE_CODE_RANGE
&& TYPE_TARGET_TYPE (type
) != type
)
9342 return fixed_type_info (TYPE_TARGET_TYPE (type
));
9347 /* Returns non-zero iff TYPE represents an Ada fixed-point type. */
9350 ada_is_fixed_point_type (struct type
*type
)
9352 return fixed_type_info (type
) != NULL
;
9355 /* Return non-zero iff TYPE represents a System.Address type. */
9358 ada_is_system_address_type (struct type
*type
)
9360 return (TYPE_NAME (type
)
9361 && strcmp (TYPE_NAME (type
), "system__address") == 0);
9364 /* Assuming that TYPE is the representation of an Ada fixed-point
9365 type, return its delta, or -1 if the type is malformed and the
9366 delta cannot be determined. */
9369 ada_delta (struct type
*type
)
9371 const char *encoding
= fixed_type_info (type
);
9374 if (sscanf (encoding
, "_%ld_%ld", &num
, &den
) < 2)
9377 return (DOUBLEST
) num
/ (DOUBLEST
) den
;
9380 /* Assuming that ada_is_fixed_point_type (TYPE), return the scaling
9381 factor ('SMALL value) associated with the type. */
9384 scaling_factor (struct type
*type
)
9386 const char *encoding
= fixed_type_info (type
);
9387 unsigned long num0
, den0
, num1
, den1
;
9390 n
= sscanf (encoding
, "_%lu_%lu_%lu_%lu", &num0
, &den0
, &num1
, &den1
);
9395 return (DOUBLEST
) num1
/ (DOUBLEST
) den1
;
9397 return (DOUBLEST
) num0
/ (DOUBLEST
) den0
;
9401 /* Assuming that X is the representation of a value of fixed-point
9402 type TYPE, return its floating-point equivalent. */
9405 ada_fixed_to_float (struct type
*type
, LONGEST x
)
9407 return (DOUBLEST
) x
*scaling_factor (type
);
9410 /* The representation of a fixed-point value of type TYPE
9411 corresponding to the value X. */
9414 ada_float_to_fixed (struct type
*type
, DOUBLEST x
)
9416 return (LONGEST
) (x
/ scaling_factor (type
) + 0.5);
9420 /* VAX floating formats */
9422 /* Non-zero iff TYPE represents one of the special VAX floating-point
9426 ada_is_vax_floating_type (struct type
*type
)
9429 (ada_type_name (type
) == NULL
) ? 0 : strlen (ada_type_name (type
));
9432 && (TYPE_CODE (type
) == TYPE_CODE_INT
9433 || TYPE_CODE (type
) == TYPE_CODE_RANGE
)
9434 && strncmp (ada_type_name (type
) + name_len
- 6, "___XF", 5) == 0;
9437 /* The type of special VAX floating-point type this is, assuming
9438 ada_is_vax_floating_point. */
9441 ada_vax_float_type_suffix (struct type
*type
)
9443 return ada_type_name (type
)[strlen (ada_type_name (type
)) - 1];
9446 /* A value representing the special debugging function that outputs
9447 VAX floating-point values of the type represented by TYPE. Assumes
9448 ada_is_vax_floating_type (TYPE). */
9451 ada_vax_float_print_function (struct type
*type
)
9453 switch (ada_vax_float_type_suffix (type
))
9456 return get_var_value ("DEBUG_STRING_F", 0);
9458 return get_var_value ("DEBUG_STRING_D", 0);
9460 return get_var_value ("DEBUG_STRING_G", 0);
9462 error (_("invalid VAX floating-point type"));
9469 /* Scan STR beginning at position K for a discriminant name, and
9470 return the value of that discriminant field of DVAL in *PX. If
9471 PNEW_K is not null, put the position of the character beyond the
9472 name scanned in *PNEW_K. Return 1 if successful; return 0 and do
9473 not alter *PX and *PNEW_K if unsuccessful. */
9476 scan_discrim_bound (char *str
, int k
, struct value
*dval
, LONGEST
* px
,
9479 static char *bound_buffer
= NULL
;
9480 static size_t bound_buffer_len
= 0;
9483 struct value
*bound_val
;
9485 if (dval
== NULL
|| str
== NULL
|| str
[k
] == '\0')
9488 pend
= strstr (str
+ k
, "__");
9492 k
+= strlen (bound
);
9496 GROW_VECT (bound_buffer
, bound_buffer_len
, pend
- (str
+ k
) + 1);
9497 bound
= bound_buffer
;
9498 strncpy (bound_buffer
, str
+ k
, pend
- (str
+ k
));
9499 bound
[pend
- (str
+ k
)] = '\0';
9503 bound_val
= ada_search_struct_field (bound
, dval
, 0, value_type (dval
));
9504 if (bound_val
== NULL
)
9507 *px
= value_as_long (bound_val
);
9513 /* Value of variable named NAME in the current environment. If
9514 no such variable found, then if ERR_MSG is null, returns 0, and
9515 otherwise causes an error with message ERR_MSG. */
9517 static struct value
*
9518 get_var_value (char *name
, char *err_msg
)
9520 struct ada_symbol_info
*syms
;
9523 nsyms
= ada_lookup_symbol_list (name
, get_selected_block (0), VAR_DOMAIN
,
9528 if (err_msg
== NULL
)
9531 error (("%s"), err_msg
);
9534 return value_of_variable (syms
[0].sym
, syms
[0].block
);
9537 /* Value of integer variable named NAME in the current environment. If
9538 no such variable found, returns 0, and sets *FLAG to 0. If
9539 successful, sets *FLAG to 1. */
9542 get_int_var_value (char *name
, int *flag
)
9544 struct value
*var_val
= get_var_value (name
, 0);
9556 return value_as_long (var_val
);
9561 /* Return a range type whose base type is that of the range type named
9562 NAME in the current environment, and whose bounds are calculated
9563 from NAME according to the GNAT range encoding conventions.
9564 Extract discriminant values, if needed, from DVAL. If a new type
9565 must be created, allocate in OBJFILE's space. The bounds
9566 information, in general, is encoded in NAME, the base type given in
9567 the named range type. */
9569 static struct type
*
9570 to_fixed_range_type (char *name
, struct value
*dval
, struct objfile
*objfile
)
9572 struct type
*raw_type
= ada_find_any_type (name
);
9573 struct type
*base_type
;
9576 if (raw_type
== NULL
)
9577 base_type
= builtin_type_int
;
9578 else if (TYPE_CODE (raw_type
) == TYPE_CODE_RANGE
)
9579 base_type
= TYPE_TARGET_TYPE (raw_type
);
9581 base_type
= raw_type
;
9583 subtype_info
= strstr (name
, "___XD");
9584 if (subtype_info
== NULL
)
9588 static char *name_buf
= NULL
;
9589 static size_t name_len
= 0;
9590 int prefix_len
= subtype_info
- name
;
9596 GROW_VECT (name_buf
, name_len
, prefix_len
+ 5);
9597 strncpy (name_buf
, name
, prefix_len
);
9598 name_buf
[prefix_len
] = '\0';
9601 bounds_str
= strchr (subtype_info
, '_');
9604 if (*subtype_info
== 'L')
9606 if (!ada_scan_number (bounds_str
, n
, &L
, &n
)
9607 && !scan_discrim_bound (bounds_str
, n
, dval
, &L
, &n
))
9609 if (bounds_str
[n
] == '_')
9611 else if (bounds_str
[n
] == '.') /* FIXME? SGI Workshop kludge. */
9618 strcpy (name_buf
+ prefix_len
, "___L");
9619 L
= get_int_var_value (name_buf
, &ok
);
9622 lim_warning (_("Unknown lower bound, using 1."));
9627 if (*subtype_info
== 'U')
9629 if (!ada_scan_number (bounds_str
, n
, &U
, &n
)
9630 && !scan_discrim_bound (bounds_str
, n
, dval
, &U
, &n
))
9636 strcpy (name_buf
+ prefix_len
, "___U");
9637 U
= get_int_var_value (name_buf
, &ok
);
9640 lim_warning (_("Unknown upper bound, using %ld."), (long) L
);
9645 if (objfile
== NULL
)
9646 objfile
= TYPE_OBJFILE (base_type
);
9647 type
= create_range_type (alloc_type (objfile
), base_type
, L
, U
);
9648 TYPE_NAME (type
) = name
;
9653 /* True iff NAME is the name of a range type. */
9656 ada_is_range_type_name (const char *name
)
9658 return (name
!= NULL
&& strstr (name
, "___XD"));
9664 /* True iff TYPE is an Ada modular type. */
9667 ada_is_modular_type (struct type
*type
)
9669 struct type
*subranged_type
= base_type (type
);
9671 return (subranged_type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_RANGE
9672 && TYPE_CODE (subranged_type
) != TYPE_CODE_ENUM
9673 && TYPE_UNSIGNED (subranged_type
));
9676 /* Assuming ada_is_modular_type (TYPE), the modulus of TYPE. */
9679 ada_modulus (struct type
* type
)
9681 return (ULONGEST
) TYPE_HIGH_BOUND (type
) + 1;
9685 /* Ada exception catchpoint support:
9686 ---------------------------------
9688 We support 3 kinds of exception catchpoints:
9689 . catchpoints on Ada exceptions
9690 . catchpoints on unhandled Ada exceptions
9691 . catchpoints on failed assertions
9693 Exceptions raised during failed assertions, or unhandled exceptions
9694 could perfectly be caught with the general catchpoint on Ada exceptions.
9695 However, we can easily differentiate these two special cases, and having
9696 the option to distinguish these two cases from the rest can be useful
9697 to zero-in on certain situations.
9699 Exception catchpoints are a specialized form of breakpoint,
9700 since they rely on inserting breakpoints inside known routines
9701 of the GNAT runtime. The implementation therefore uses a standard
9702 breakpoint structure of the BP_BREAKPOINT type, but with its own set
9705 Support in the runtime for exception catchpoints have been changed
9706 a few times already, and these changes affect the implementation
9707 of these catchpoints. In order to be able to support several
9708 variants of the runtime, we use a sniffer that will determine
9709 the runtime variant used by the program being debugged.
9711 At this time, we do not support the use of conditions on Ada exception
9712 catchpoints. The COND and COND_STRING fields are therefore set
9713 to NULL (most of the time, see below).
9715 Conditions where EXP_STRING, COND, and COND_STRING are used:
9717 When a user specifies the name of a specific exception in the case
9718 of catchpoints on Ada exceptions, we store the name of that exception
9719 in the EXP_STRING. We then translate this request into an actual
9720 condition stored in COND_STRING, and then parse it into an expression
9723 /* The different types of catchpoints that we introduced for catching
9726 enum exception_catchpoint_kind
9729 ex_catch_exception_unhandled
,
9733 typedef CORE_ADDR (ada_unhandled_exception_name_addr_ftype
) (void);
9735 /* A structure that describes how to support exception catchpoints
9736 for a given executable. */
9738 struct exception_support_info
9740 /* The name of the symbol to break on in order to insert
9741 a catchpoint on exceptions. */
9742 const char *catch_exception_sym
;
9744 /* The name of the symbol to break on in order to insert
9745 a catchpoint on unhandled exceptions. */
9746 const char *catch_exception_unhandled_sym
;
9748 /* The name of the symbol to break on in order to insert
9749 a catchpoint on failed assertions. */
9750 const char *catch_assert_sym
;
9752 /* Assuming that the inferior just triggered an unhandled exception
9753 catchpoint, this function is responsible for returning the address
9754 in inferior memory where the name of that exception is stored.
9755 Return zero if the address could not be computed. */
9756 ada_unhandled_exception_name_addr_ftype
*unhandled_exception_name_addr
;
9759 static CORE_ADDR
ada_unhandled_exception_name_addr (void);
9760 static CORE_ADDR
ada_unhandled_exception_name_addr_from_raise (void);
9762 /* The following exception support info structure describes how to
9763 implement exception catchpoints with the latest version of the
9764 Ada runtime (as of 2007-03-06). */
9766 static const struct exception_support_info default_exception_support_info
=
9768 "__gnat_debug_raise_exception", /* catch_exception_sym */
9769 "__gnat_unhandled_exception", /* catch_exception_unhandled_sym */
9770 "__gnat_debug_raise_assert_failure", /* catch_assert_sym */
9771 ada_unhandled_exception_name_addr
9774 /* The following exception support info structure describes how to
9775 implement exception catchpoints with a slightly older version
9776 of the Ada runtime. */
9778 static const struct exception_support_info exception_support_info_fallback
=
9780 "__gnat_raise_nodefer_with_msg", /* catch_exception_sym */
9781 "__gnat_unhandled_exception", /* catch_exception_unhandled_sym */
9782 "system__assertions__raise_assert_failure", /* catch_assert_sym */
9783 ada_unhandled_exception_name_addr_from_raise
9786 /* For each executable, we sniff which exception info structure to use
9787 and cache it in the following global variable. */
9789 static const struct exception_support_info
*exception_info
= NULL
;
9791 /* Inspect the Ada runtime and determine which exception info structure
9792 should be used to provide support for exception catchpoints.
9794 This function will always set exception_info, or raise an error. */
9797 ada_exception_support_info_sniffer (void)
9801 /* If the exception info is already known, then no need to recompute it. */
9802 if (exception_info
!= NULL
)
9805 /* Check the latest (default) exception support info. */
9806 sym
= standard_lookup (default_exception_support_info
.catch_exception_sym
,
9810 exception_info
= &default_exception_support_info
;
9814 /* Try our fallback exception suport info. */
9815 sym
= standard_lookup (exception_support_info_fallback
.catch_exception_sym
,
9819 exception_info
= &exception_support_info_fallback
;
9823 /* Sometimes, it is normal for us to not be able to find the routine
9824 we are looking for. This happens when the program is linked with
9825 the shared version of the GNAT runtime, and the program has not been
9826 started yet. Inform the user of these two possible causes if
9829 if (ada_update_initial_language (language_unknown
, NULL
) != language_ada
)
9830 error (_("Unable to insert catchpoint. Is this an Ada main program?"));
9832 /* If the symbol does not exist, then check that the program is
9833 already started, to make sure that shared libraries have been
9834 loaded. If it is not started, this may mean that the symbol is
9835 in a shared library. */
9837 if (ptid_get_pid (inferior_ptid
) == 0)
9838 error (_("Unable to insert catchpoint. Try to start the program first."));
9840 /* At this point, we know that we are debugging an Ada program and
9841 that the inferior has been started, but we still are not able to
9842 find the run-time symbols. That can mean that we are in
9843 configurable run time mode, or that a-except as been optimized
9844 out by the linker... In any case, at this point it is not worth
9845 supporting this feature. */
9847 error (_("Cannot insert catchpoints in this configuration."));
9850 /* An observer of "executable_changed" events.
9851 Its role is to clear certain cached values that need to be recomputed
9852 each time a new executable is loaded by GDB. */
9855 ada_executable_changed_observer (void *unused
)
9857 /* If the executable changed, then it is possible that the Ada runtime
9858 is different. So we need to invalidate the exception support info
9860 exception_info
= NULL
;
9863 /* Return the name of the function at PC, NULL if could not find it.
9864 This function only checks the debugging information, not the symbol
9868 function_name_from_pc (CORE_ADDR pc
)
9872 if (!find_pc_partial_function (pc
, &func_name
, NULL
, NULL
))
9878 /* True iff FRAME is very likely to be that of a function that is
9879 part of the runtime system. This is all very heuristic, but is
9880 intended to be used as advice as to what frames are uninteresting
9884 is_known_support_routine (struct frame_info
*frame
)
9886 struct symtab_and_line sal
;
9890 /* If this code does not have any debugging information (no symtab),
9891 This cannot be any user code. */
9893 find_frame_sal (frame
, &sal
);
9894 if (sal
.symtab
== NULL
)
9897 /* If there is a symtab, but the associated source file cannot be
9898 located, then assume this is not user code: Selecting a frame
9899 for which we cannot display the code would not be very helpful
9900 for the user. This should also take care of case such as VxWorks
9901 where the kernel has some debugging info provided for a few units. */
9903 if (symtab_to_fullname (sal
.symtab
) == NULL
)
9906 /* Check the unit filename againt the Ada runtime file naming.
9907 We also check the name of the objfile against the name of some
9908 known system libraries that sometimes come with debugging info
9911 for (i
= 0; known_runtime_file_name_patterns
[i
] != NULL
; i
+= 1)
9913 re_comp (known_runtime_file_name_patterns
[i
]);
9914 if (re_exec (sal
.symtab
->filename
))
9916 if (sal
.symtab
->objfile
!= NULL
9917 && re_exec (sal
.symtab
->objfile
->name
))
9921 /* Check whether the function is a GNAT-generated entity. */
9923 func_name
= function_name_from_pc (get_frame_address_in_block (frame
));
9924 if (func_name
== NULL
)
9927 for (i
= 0; known_auxiliary_function_name_patterns
[i
] != NULL
; i
+= 1)
9929 re_comp (known_auxiliary_function_name_patterns
[i
]);
9930 if (re_exec (func_name
))
9937 /* Find the first frame that contains debugging information and that is not
9938 part of the Ada run-time, starting from FI and moving upward. */
9941 ada_find_printable_frame (struct frame_info
*fi
)
9943 for (; fi
!= NULL
; fi
= get_prev_frame (fi
))
9945 if (!is_known_support_routine (fi
))
9954 /* Assuming that the inferior just triggered an unhandled exception
9955 catchpoint, return the address in inferior memory where the name
9956 of the exception is stored.
9958 Return zero if the address could not be computed. */
9961 ada_unhandled_exception_name_addr (void)
9963 return parse_and_eval_address ("e.full_name");
9966 /* Same as ada_unhandled_exception_name_addr, except that this function
9967 should be used when the inferior uses an older version of the runtime,
9968 where the exception name needs to be extracted from a specific frame
9969 several frames up in the callstack. */
9972 ada_unhandled_exception_name_addr_from_raise (void)
9975 struct frame_info
*fi
;
9977 /* To determine the name of this exception, we need to select
9978 the frame corresponding to RAISE_SYM_NAME. This frame is
9979 at least 3 levels up, so we simply skip the first 3 frames
9980 without checking the name of their associated function. */
9981 fi
= get_current_frame ();
9982 for (frame_level
= 0; frame_level
< 3; frame_level
+= 1)
9984 fi
= get_prev_frame (fi
);
9988 const char *func_name
=
9989 function_name_from_pc (get_frame_address_in_block (fi
));
9990 if (func_name
!= NULL
9991 && strcmp (func_name
, exception_info
->catch_exception_sym
) == 0)
9992 break; /* We found the frame we were looking for... */
9993 fi
= get_prev_frame (fi
);
10000 return parse_and_eval_address ("id.full_name");
10003 /* Assuming the inferior just triggered an Ada exception catchpoint
10004 (of any type), return the address in inferior memory where the name
10005 of the exception is stored, if applicable.
10007 Return zero if the address could not be computed, or if not relevant. */
10010 ada_exception_name_addr_1 (enum exception_catchpoint_kind ex
,
10011 struct breakpoint
*b
)
10015 case ex_catch_exception
:
10016 return (parse_and_eval_address ("e.full_name"));
10019 case ex_catch_exception_unhandled
:
10020 return exception_info
->unhandled_exception_name_addr ();
10023 case ex_catch_assert
:
10024 return 0; /* Exception name is not relevant in this case. */
10028 internal_error (__FILE__
, __LINE__
, _("unexpected catchpoint type"));
10032 return 0; /* Should never be reached. */
10035 /* Same as ada_exception_name_addr_1, except that it intercepts and contains
10036 any error that ada_exception_name_addr_1 might cause to be thrown.
10037 When an error is intercepted, a warning with the error message is printed,
10038 and zero is returned. */
10041 ada_exception_name_addr (enum exception_catchpoint_kind ex
,
10042 struct breakpoint
*b
)
10044 struct gdb_exception e
;
10045 CORE_ADDR result
= 0;
10047 TRY_CATCH (e
, RETURN_MASK_ERROR
)
10049 result
= ada_exception_name_addr_1 (ex
, b
);
10054 warning (_("failed to get exception name: %s"), e
.message
);
10061 /* Implement the PRINT_IT method in the breakpoint_ops structure
10062 for all exception catchpoint kinds. */
10064 static enum print_stop_action
10065 print_it_exception (enum exception_catchpoint_kind ex
, struct breakpoint
*b
)
10067 const CORE_ADDR addr
= ada_exception_name_addr (ex
, b
);
10068 char exception_name
[256];
10072 read_memory (addr
, exception_name
, sizeof (exception_name
) - 1);
10073 exception_name
[sizeof (exception_name
) - 1] = '\0';
10076 ada_find_printable_frame (get_current_frame ());
10078 annotate_catchpoint (b
->number
);
10081 case ex_catch_exception
:
10083 printf_filtered (_("\nCatchpoint %d, %s at "),
10084 b
->number
, exception_name
);
10086 printf_filtered (_("\nCatchpoint %d, exception at "), b
->number
);
10088 case ex_catch_exception_unhandled
:
10090 printf_filtered (_("\nCatchpoint %d, unhandled %s at "),
10091 b
->number
, exception_name
);
10093 printf_filtered (_("\nCatchpoint %d, unhandled exception at "),
10096 case ex_catch_assert
:
10097 printf_filtered (_("\nCatchpoint %d, failed assertion at "),
10102 return PRINT_SRC_AND_LOC
;
10105 /* Implement the PRINT_ONE method in the breakpoint_ops structure
10106 for all exception catchpoint kinds. */
10109 print_one_exception (enum exception_catchpoint_kind ex
,
10110 struct breakpoint
*b
, CORE_ADDR
*last_addr
)
10114 annotate_field (4);
10115 ui_out_field_core_addr (uiout
, "addr", b
->loc
->address
);
10118 annotate_field (5);
10119 *last_addr
= b
->loc
->address
;
10122 case ex_catch_exception
:
10123 if (b
->exp_string
!= NULL
)
10125 char *msg
= xstrprintf (_("`%s' Ada exception"), b
->exp_string
);
10127 ui_out_field_string (uiout
, "what", msg
);
10131 ui_out_field_string (uiout
, "what", "all Ada exceptions");
10135 case ex_catch_exception_unhandled
:
10136 ui_out_field_string (uiout
, "what", "unhandled Ada exceptions");
10139 case ex_catch_assert
:
10140 ui_out_field_string (uiout
, "what", "failed Ada assertions");
10144 internal_error (__FILE__
, __LINE__
, _("unexpected catchpoint type"));
10149 /* Implement the PRINT_MENTION method in the breakpoint_ops structure
10150 for all exception catchpoint kinds. */
10153 print_mention_exception (enum exception_catchpoint_kind ex
,
10154 struct breakpoint
*b
)
10158 case ex_catch_exception
:
10159 if (b
->exp_string
!= NULL
)
10160 printf_filtered (_("Catchpoint %d: `%s' Ada exception"),
10161 b
->number
, b
->exp_string
);
10163 printf_filtered (_("Catchpoint %d: all Ada exceptions"), b
->number
);
10167 case ex_catch_exception_unhandled
:
10168 printf_filtered (_("Catchpoint %d: unhandled Ada exceptions"),
10172 case ex_catch_assert
:
10173 printf_filtered (_("Catchpoint %d: failed Ada assertions"), b
->number
);
10177 internal_error (__FILE__
, __LINE__
, _("unexpected catchpoint type"));
10182 /* Virtual table for "catch exception" breakpoints. */
10184 static enum print_stop_action
10185 print_it_catch_exception (struct breakpoint
*b
)
10187 return print_it_exception (ex_catch_exception
, b
);
10191 print_one_catch_exception (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
10193 print_one_exception (ex_catch_exception
, b
, last_addr
);
10197 print_mention_catch_exception (struct breakpoint
*b
)
10199 print_mention_exception (ex_catch_exception
, b
);
10202 static struct breakpoint_ops catch_exception_breakpoint_ops
=
10204 print_it_catch_exception
,
10205 print_one_catch_exception
,
10206 print_mention_catch_exception
10209 /* Virtual table for "catch exception unhandled" breakpoints. */
10211 static enum print_stop_action
10212 print_it_catch_exception_unhandled (struct breakpoint
*b
)
10214 return print_it_exception (ex_catch_exception_unhandled
, b
);
10218 print_one_catch_exception_unhandled (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
10220 print_one_exception (ex_catch_exception_unhandled
, b
, last_addr
);
10224 print_mention_catch_exception_unhandled (struct breakpoint
*b
)
10226 print_mention_exception (ex_catch_exception_unhandled
, b
);
10229 static struct breakpoint_ops catch_exception_unhandled_breakpoint_ops
= {
10230 print_it_catch_exception_unhandled
,
10231 print_one_catch_exception_unhandled
,
10232 print_mention_catch_exception_unhandled
10235 /* Virtual table for "catch assert" breakpoints. */
10237 static enum print_stop_action
10238 print_it_catch_assert (struct breakpoint
*b
)
10240 return print_it_exception (ex_catch_assert
, b
);
10244 print_one_catch_assert (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
10246 print_one_exception (ex_catch_assert
, b
, last_addr
);
10250 print_mention_catch_assert (struct breakpoint
*b
)
10252 print_mention_exception (ex_catch_assert
, b
);
10255 static struct breakpoint_ops catch_assert_breakpoint_ops
= {
10256 print_it_catch_assert
,
10257 print_one_catch_assert
,
10258 print_mention_catch_assert
10261 /* Return non-zero if B is an Ada exception catchpoint. */
10264 ada_exception_catchpoint_p (struct breakpoint
*b
)
10266 return (b
->ops
== &catch_exception_breakpoint_ops
10267 || b
->ops
== &catch_exception_unhandled_breakpoint_ops
10268 || b
->ops
== &catch_assert_breakpoint_ops
);
10271 /* Return a newly allocated copy of the first space-separated token
10272 in ARGSP, and then adjust ARGSP to point immediately after that
10275 Return NULL if ARGPS does not contain any more tokens. */
10278 ada_get_next_arg (char **argsp
)
10280 char *args
= *argsp
;
10284 /* Skip any leading white space. */
10286 while (isspace (*args
))
10289 if (args
[0] == '\0')
10290 return NULL
; /* No more arguments. */
10292 /* Find the end of the current argument. */
10295 while (*end
!= '\0' && !isspace (*end
))
10298 /* Adjust ARGSP to point to the start of the next argument. */
10302 /* Make a copy of the current argument and return it. */
10304 result
= xmalloc (end
- args
+ 1);
10305 strncpy (result
, args
, end
- args
);
10306 result
[end
- args
] = '\0';
10311 /* Split the arguments specified in a "catch exception" command.
10312 Set EX to the appropriate catchpoint type.
10313 Set EXP_STRING to the name of the specific exception if
10314 specified by the user. */
10317 catch_ada_exception_command_split (char *args
,
10318 enum exception_catchpoint_kind
*ex
,
10321 struct cleanup
*old_chain
= make_cleanup (null_cleanup
, NULL
);
10322 char *exception_name
;
10324 exception_name
= ada_get_next_arg (&args
);
10325 make_cleanup (xfree
, exception_name
);
10327 /* Check that we do not have any more arguments. Anything else
10330 while (isspace (*args
))
10333 if (args
[0] != '\0')
10334 error (_("Junk at end of expression"));
10336 discard_cleanups (old_chain
);
10338 if (exception_name
== NULL
)
10340 /* Catch all exceptions. */
10341 *ex
= ex_catch_exception
;
10342 *exp_string
= NULL
;
10344 else if (strcmp (exception_name
, "unhandled") == 0)
10346 /* Catch unhandled exceptions. */
10347 *ex
= ex_catch_exception_unhandled
;
10348 *exp_string
= NULL
;
10352 /* Catch a specific exception. */
10353 *ex
= ex_catch_exception
;
10354 *exp_string
= exception_name
;
10358 /* Return the name of the symbol on which we should break in order to
10359 implement a catchpoint of the EX kind. */
10361 static const char *
10362 ada_exception_sym_name (enum exception_catchpoint_kind ex
)
10364 gdb_assert (exception_info
!= NULL
);
10368 case ex_catch_exception
:
10369 return (exception_info
->catch_exception_sym
);
10371 case ex_catch_exception_unhandled
:
10372 return (exception_info
->catch_exception_unhandled_sym
);
10374 case ex_catch_assert
:
10375 return (exception_info
->catch_assert_sym
);
10378 internal_error (__FILE__
, __LINE__
,
10379 _("unexpected catchpoint kind (%d)"), ex
);
10383 /* Return the breakpoint ops "virtual table" used for catchpoints
10386 static struct breakpoint_ops
*
10387 ada_exception_breakpoint_ops (enum exception_catchpoint_kind ex
)
10391 case ex_catch_exception
:
10392 return (&catch_exception_breakpoint_ops
);
10394 case ex_catch_exception_unhandled
:
10395 return (&catch_exception_unhandled_breakpoint_ops
);
10397 case ex_catch_assert
:
10398 return (&catch_assert_breakpoint_ops
);
10401 internal_error (__FILE__
, __LINE__
,
10402 _("unexpected catchpoint kind (%d)"), ex
);
10406 /* Return the condition that will be used to match the current exception
10407 being raised with the exception that the user wants to catch. This
10408 assumes that this condition is used when the inferior just triggered
10409 an exception catchpoint.
10411 The string returned is a newly allocated string that needs to be
10412 deallocated later. */
10415 ada_exception_catchpoint_cond_string (const char *exp_string
)
10417 return xstrprintf ("long_integer (e) = long_integer (&%s)", exp_string
);
10420 /* Return the expression corresponding to COND_STRING evaluated at SAL. */
10422 static struct expression
*
10423 ada_parse_catchpoint_condition (char *cond_string
,
10424 struct symtab_and_line sal
)
10426 return (parse_exp_1 (&cond_string
, block_for_pc (sal
.pc
), 0));
10429 /* Return the symtab_and_line that should be used to insert an exception
10430 catchpoint of the TYPE kind.
10432 EX_STRING should contain the name of a specific exception
10433 that the catchpoint should catch, or NULL otherwise.
10435 The idea behind all the remaining parameters is that their names match
10436 the name of certain fields in the breakpoint structure that are used to
10437 handle exception catchpoints. This function returns the value to which
10438 these fields should be set, depending on the type of catchpoint we need
10441 If COND and COND_STRING are both non-NULL, any value they might
10442 hold will be free'ed, and then replaced by newly allocated ones.
10443 These parameters are left untouched otherwise. */
10445 static struct symtab_and_line
10446 ada_exception_sal (enum exception_catchpoint_kind ex
, char *exp_string
,
10447 char **addr_string
, char **cond_string
,
10448 struct expression
**cond
, struct breakpoint_ops
**ops
)
10450 const char *sym_name
;
10451 struct symbol
*sym
;
10452 struct symtab_and_line sal
;
10454 /* First, find out which exception support info to use. */
10455 ada_exception_support_info_sniffer ();
10457 /* Then lookup the function on which we will break in order to catch
10458 the Ada exceptions requested by the user. */
10460 sym_name
= ada_exception_sym_name (ex
);
10461 sym
= standard_lookup (sym_name
, NULL
, VAR_DOMAIN
);
10463 /* The symbol we're looking up is provided by a unit in the GNAT runtime
10464 that should be compiled with debugging information. As a result, we
10465 expect to find that symbol in the symtabs. If we don't find it, then
10466 the target most likely does not support Ada exceptions, or we cannot
10467 insert exception breakpoints yet, because the GNAT runtime hasn't been
10470 /* brobecker/2006-12-26: It is conceivable that the runtime was compiled
10471 in such a way that no debugging information is produced for the symbol
10472 we are looking for. In this case, we could search the minimal symbols
10473 as a fall-back mechanism. This would still be operating in degraded
10474 mode, however, as we would still be missing the debugging information
10475 that is needed in order to extract the name of the exception being
10476 raised (this name is printed in the catchpoint message, and is also
10477 used when trying to catch a specific exception). We do not handle
10478 this case for now. */
10481 error (_("Unable to break on '%s' in this configuration."), sym_name
);
10483 /* Make sure that the symbol we found corresponds to a function. */
10484 if (SYMBOL_CLASS (sym
) != LOC_BLOCK
)
10485 error (_("Symbol \"%s\" is not a function (class = %d)"),
10486 sym_name
, SYMBOL_CLASS (sym
));
10488 sal
= find_function_start_sal (sym
, 1);
10490 /* Set ADDR_STRING. */
10492 *addr_string
= xstrdup (sym_name
);
10494 /* Set the COND and COND_STRING (if not NULL). */
10496 if (cond_string
!= NULL
&& cond
!= NULL
)
10498 if (*cond_string
!= NULL
)
10500 xfree (*cond_string
);
10501 *cond_string
= NULL
;
10508 if (exp_string
!= NULL
)
10510 *cond_string
= ada_exception_catchpoint_cond_string (exp_string
);
10511 *cond
= ada_parse_catchpoint_condition (*cond_string
, sal
);
10516 *ops
= ada_exception_breakpoint_ops (ex
);
10521 /* Parse the arguments (ARGS) of the "catch exception" command.
10523 Set TYPE to the appropriate exception catchpoint type.
10524 If the user asked the catchpoint to catch only a specific
10525 exception, then save the exception name in ADDR_STRING.
10527 See ada_exception_sal for a description of all the remaining
10528 function arguments of this function. */
10530 struct symtab_and_line
10531 ada_decode_exception_location (char *args
, char **addr_string
,
10532 char **exp_string
, char **cond_string
,
10533 struct expression
**cond
,
10534 struct breakpoint_ops
**ops
)
10536 enum exception_catchpoint_kind ex
;
10538 catch_ada_exception_command_split (args
, &ex
, exp_string
);
10539 return ada_exception_sal (ex
, *exp_string
, addr_string
, cond_string
,
10543 struct symtab_and_line
10544 ada_decode_assert_location (char *args
, char **addr_string
,
10545 struct breakpoint_ops
**ops
)
10547 /* Check that no argument where provided at the end of the command. */
10551 while (isspace (*args
))
10554 error (_("Junk at end of arguments."));
10557 return ada_exception_sal (ex_catch_assert
, NULL
, addr_string
, NULL
, NULL
,
10562 /* Information about operators given special treatment in functions
10564 /* Format: OP_DEFN (<operator>, <operator length>, <# args>, <binop>). */
10566 #define ADA_OPERATORS \
10567 OP_DEFN (OP_VAR_VALUE, 4, 0, 0) \
10568 OP_DEFN (BINOP_IN_BOUNDS, 3, 2, 0) \
10569 OP_DEFN (TERNOP_IN_RANGE, 1, 3, 0) \
10570 OP_DEFN (OP_ATR_FIRST, 1, 2, 0) \
10571 OP_DEFN (OP_ATR_LAST, 1, 2, 0) \
10572 OP_DEFN (OP_ATR_LENGTH, 1, 2, 0) \
10573 OP_DEFN (OP_ATR_IMAGE, 1, 2, 0) \
10574 OP_DEFN (OP_ATR_MAX, 1, 3, 0) \
10575 OP_DEFN (OP_ATR_MIN, 1, 3, 0) \
10576 OP_DEFN (OP_ATR_MODULUS, 1, 1, 0) \
10577 OP_DEFN (OP_ATR_POS, 1, 2, 0) \
10578 OP_DEFN (OP_ATR_SIZE, 1, 1, 0) \
10579 OP_DEFN (OP_ATR_TAG, 1, 1, 0) \
10580 OP_DEFN (OP_ATR_VAL, 1, 2, 0) \
10581 OP_DEFN (UNOP_QUAL, 3, 1, 0) \
10582 OP_DEFN (UNOP_IN_RANGE, 3, 1, 0) \
10583 OP_DEFN (OP_OTHERS, 1, 1, 0) \
10584 OP_DEFN (OP_POSITIONAL, 3, 1, 0) \
10585 OP_DEFN (OP_DISCRETE_RANGE, 1, 2, 0)
10588 ada_operator_length (struct expression
*exp
, int pc
, int *oplenp
, int *argsp
)
10590 switch (exp
->elts
[pc
- 1].opcode
)
10593 operator_length_standard (exp
, pc
, oplenp
, argsp
);
10596 #define OP_DEFN(op, len, args, binop) \
10597 case op: *oplenp = len; *argsp = args; break;
10603 *argsp
= longest_to_int (exp
->elts
[pc
- 2].longconst
);
10608 *argsp
= longest_to_int (exp
->elts
[pc
- 2].longconst
) + 1;
10614 ada_op_name (enum exp_opcode opcode
)
10619 return op_name_standard (opcode
);
10621 #define OP_DEFN(op, len, args, binop) case op: return #op;
10626 return "OP_AGGREGATE";
10628 return "OP_CHOICES";
10634 /* As for operator_length, but assumes PC is pointing at the first
10635 element of the operator, and gives meaningful results only for the
10636 Ada-specific operators, returning 0 for *OPLENP and *ARGSP otherwise. */
10639 ada_forward_operator_length (struct expression
*exp
, int pc
,
10640 int *oplenp
, int *argsp
)
10642 switch (exp
->elts
[pc
].opcode
)
10645 *oplenp
= *argsp
= 0;
10648 #define OP_DEFN(op, len, args, binop) \
10649 case op: *oplenp = len; *argsp = args; break;
10655 *argsp
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
10660 *argsp
= longest_to_int (exp
->elts
[pc
+ 1].longconst
) + 1;
10666 int len
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
10667 *oplenp
= 4 + BYTES_TO_EXP_ELEM (len
+ 1);
10675 ada_dump_subexp_body (struct expression
*exp
, struct ui_file
*stream
, int elt
)
10677 enum exp_opcode op
= exp
->elts
[elt
].opcode
;
10682 ada_forward_operator_length (exp
, elt
, &oplen
, &nargs
);
10686 /* Ada attributes ('Foo). */
10689 case OP_ATR_LENGTH
:
10693 case OP_ATR_MODULUS
:
10700 case UNOP_IN_RANGE
:
10702 /* XXX: gdb_sprint_host_address, type_sprint */
10703 fprintf_filtered (stream
, _("Type @"));
10704 gdb_print_host_address (exp
->elts
[pc
+ 1].type
, stream
);
10705 fprintf_filtered (stream
, " (");
10706 type_print (exp
->elts
[pc
+ 1].type
, NULL
, stream
, 0);
10707 fprintf_filtered (stream
, ")");
10709 case BINOP_IN_BOUNDS
:
10710 fprintf_filtered (stream
, " (%d)",
10711 longest_to_int (exp
->elts
[pc
+ 2].longconst
));
10713 case TERNOP_IN_RANGE
:
10718 case OP_DISCRETE_RANGE
:
10719 case OP_POSITIONAL
:
10726 char *name
= &exp
->elts
[elt
+ 2].string
;
10727 int len
= longest_to_int (exp
->elts
[elt
+ 1].longconst
);
10728 fprintf_filtered (stream
, "Text: `%.*s'", len
, name
);
10733 return dump_subexp_body_standard (exp
, stream
, elt
);
10737 for (i
= 0; i
< nargs
; i
+= 1)
10738 elt
= dump_subexp (exp
, stream
, elt
);
10743 /* The Ada extension of print_subexp (q.v.). */
10746 ada_print_subexp (struct expression
*exp
, int *pos
,
10747 struct ui_file
*stream
, enum precedence prec
)
10749 int oplen
, nargs
, i
;
10751 enum exp_opcode op
= exp
->elts
[pc
].opcode
;
10753 ada_forward_operator_length (exp
, pc
, &oplen
, &nargs
);
10760 print_subexp_standard (exp
, pos
, stream
, prec
);
10764 fputs_filtered (SYMBOL_NATURAL_NAME (exp
->elts
[pc
+ 2].symbol
), stream
);
10767 case BINOP_IN_BOUNDS
:
10768 /* XXX: sprint_subexp */
10769 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
10770 fputs_filtered (" in ", stream
);
10771 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
10772 fputs_filtered ("'range", stream
);
10773 if (exp
->elts
[pc
+ 1].longconst
> 1)
10774 fprintf_filtered (stream
, "(%ld)",
10775 (long) exp
->elts
[pc
+ 1].longconst
);
10778 case TERNOP_IN_RANGE
:
10779 if (prec
>= PREC_EQUAL
)
10780 fputs_filtered ("(", stream
);
10781 /* XXX: sprint_subexp */
10782 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
10783 fputs_filtered (" in ", stream
);
10784 print_subexp (exp
, pos
, stream
, PREC_EQUAL
);
10785 fputs_filtered (" .. ", stream
);
10786 print_subexp (exp
, pos
, stream
, PREC_EQUAL
);
10787 if (prec
>= PREC_EQUAL
)
10788 fputs_filtered (")", stream
);
10793 case OP_ATR_LENGTH
:
10797 case OP_ATR_MODULUS
:
10802 if (exp
->elts
[*pos
].opcode
== OP_TYPE
)
10804 if (TYPE_CODE (exp
->elts
[*pos
+ 1].type
) != TYPE_CODE_VOID
)
10805 LA_PRINT_TYPE (exp
->elts
[*pos
+ 1].type
, "", stream
, 0, 0);
10809 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
10810 fprintf_filtered (stream
, "'%s", ada_attribute_name (op
));
10814 for (tem
= 1; tem
< nargs
; tem
+= 1)
10816 fputs_filtered ((tem
== 1) ? " (" : ", ", stream
);
10817 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
10819 fputs_filtered (")", stream
);
10824 type_print (exp
->elts
[pc
+ 1].type
, "", stream
, 0);
10825 fputs_filtered ("'(", stream
);
10826 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
10827 fputs_filtered (")", stream
);
10830 case UNOP_IN_RANGE
:
10831 /* XXX: sprint_subexp */
10832 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
10833 fputs_filtered (" in ", stream
);
10834 LA_PRINT_TYPE (exp
->elts
[pc
+ 1].type
, "", stream
, 1, 0);
10837 case OP_DISCRETE_RANGE
:
10838 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
10839 fputs_filtered ("..", stream
);
10840 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
10844 fputs_filtered ("others => ", stream
);
10845 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
10849 for (i
= 0; i
< nargs
-1; i
+= 1)
10852 fputs_filtered ("|", stream
);
10853 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
10855 fputs_filtered (" => ", stream
);
10856 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
10859 case OP_POSITIONAL
:
10860 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
10864 fputs_filtered ("(", stream
);
10865 for (i
= 0; i
< nargs
; i
+= 1)
10868 fputs_filtered (", ", stream
);
10869 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
10871 fputs_filtered (")", stream
);
10876 /* Table mapping opcodes into strings for printing operators
10877 and precedences of the operators. */
10879 static const struct op_print ada_op_print_tab
[] = {
10880 {":=", BINOP_ASSIGN
, PREC_ASSIGN
, 1},
10881 {"or else", BINOP_LOGICAL_OR
, PREC_LOGICAL_OR
, 0},
10882 {"and then", BINOP_LOGICAL_AND
, PREC_LOGICAL_AND
, 0},
10883 {"or", BINOP_BITWISE_IOR
, PREC_BITWISE_IOR
, 0},
10884 {"xor", BINOP_BITWISE_XOR
, PREC_BITWISE_XOR
, 0},
10885 {"and", BINOP_BITWISE_AND
, PREC_BITWISE_AND
, 0},
10886 {"=", BINOP_EQUAL
, PREC_EQUAL
, 0},
10887 {"/=", BINOP_NOTEQUAL
, PREC_EQUAL
, 0},
10888 {"<=", BINOP_LEQ
, PREC_ORDER
, 0},
10889 {">=", BINOP_GEQ
, PREC_ORDER
, 0},
10890 {">", BINOP_GTR
, PREC_ORDER
, 0},
10891 {"<", BINOP_LESS
, PREC_ORDER
, 0},
10892 {">>", BINOP_RSH
, PREC_SHIFT
, 0},
10893 {"<<", BINOP_LSH
, PREC_SHIFT
, 0},
10894 {"+", BINOP_ADD
, PREC_ADD
, 0},
10895 {"-", BINOP_SUB
, PREC_ADD
, 0},
10896 {"&", BINOP_CONCAT
, PREC_ADD
, 0},
10897 {"*", BINOP_MUL
, PREC_MUL
, 0},
10898 {"/", BINOP_DIV
, PREC_MUL
, 0},
10899 {"rem", BINOP_REM
, PREC_MUL
, 0},
10900 {"mod", BINOP_MOD
, PREC_MUL
, 0},
10901 {"**", BINOP_EXP
, PREC_REPEAT
, 0},
10902 {"@", BINOP_REPEAT
, PREC_REPEAT
, 0},
10903 {"-", UNOP_NEG
, PREC_PREFIX
, 0},
10904 {"+", UNOP_PLUS
, PREC_PREFIX
, 0},
10905 {"not ", UNOP_LOGICAL_NOT
, PREC_PREFIX
, 0},
10906 {"not ", UNOP_COMPLEMENT
, PREC_PREFIX
, 0},
10907 {"abs ", UNOP_ABS
, PREC_PREFIX
, 0},
10908 {".all", UNOP_IND
, PREC_SUFFIX
, 1},
10909 {"'access", UNOP_ADDR
, PREC_SUFFIX
, 1},
10910 {"'size", OP_ATR_SIZE
, PREC_SUFFIX
, 1},
10914 enum ada_primitive_types
{
10915 ada_primitive_type_int
,
10916 ada_primitive_type_long
,
10917 ada_primitive_type_short
,
10918 ada_primitive_type_char
,
10919 ada_primitive_type_float
,
10920 ada_primitive_type_double
,
10921 ada_primitive_type_void
,
10922 ada_primitive_type_long_long
,
10923 ada_primitive_type_long_double
,
10924 ada_primitive_type_natural
,
10925 ada_primitive_type_positive
,
10926 ada_primitive_type_system_address
,
10927 nr_ada_primitive_types
10931 ada_language_arch_info (struct gdbarch
*gdbarch
,
10932 struct language_arch_info
*lai
)
10934 const struct builtin_type
*builtin
= builtin_type (gdbarch
);
10935 lai
->primitive_type_vector
10936 = GDBARCH_OBSTACK_CALLOC (gdbarch
, nr_ada_primitive_types
+ 1,
10938 lai
->primitive_type_vector
[ada_primitive_type_int
] =
10939 init_type (TYPE_CODE_INT
,
10940 gdbarch_int_bit (gdbarch
) / TARGET_CHAR_BIT
,
10941 0, "integer", (struct objfile
*) NULL
);
10942 lai
->primitive_type_vector
[ada_primitive_type_long
] =
10943 init_type (TYPE_CODE_INT
,
10944 gdbarch_long_bit (gdbarch
) / TARGET_CHAR_BIT
,
10945 0, "long_integer", (struct objfile
*) NULL
);
10946 lai
->primitive_type_vector
[ada_primitive_type_short
] =
10947 init_type (TYPE_CODE_INT
,
10948 gdbarch_short_bit (gdbarch
) / TARGET_CHAR_BIT
,
10949 0, "short_integer", (struct objfile
*) NULL
);
10950 lai
->string_char_type
=
10951 lai
->primitive_type_vector
[ada_primitive_type_char
] =
10952 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
10953 0, "character", (struct objfile
*) NULL
);
10954 lai
->primitive_type_vector
[ada_primitive_type_float
] =
10955 init_type (TYPE_CODE_FLT
,
10956 gdbarch_float_bit (gdbarch
)/ TARGET_CHAR_BIT
,
10957 0, "float", (struct objfile
*) NULL
);
10958 lai
->primitive_type_vector
[ada_primitive_type_double
] =
10959 init_type (TYPE_CODE_FLT
,
10960 gdbarch_double_bit (gdbarch
) / TARGET_CHAR_BIT
,
10961 0, "long_float", (struct objfile
*) NULL
);
10962 lai
->primitive_type_vector
[ada_primitive_type_long_long
] =
10963 init_type (TYPE_CODE_INT
,
10964 gdbarch_long_long_bit (gdbarch
) / TARGET_CHAR_BIT
,
10965 0, "long_long_integer", (struct objfile
*) NULL
);
10966 lai
->primitive_type_vector
[ada_primitive_type_long_double
] =
10967 init_type (TYPE_CODE_FLT
,
10968 gdbarch_double_bit (gdbarch
) / TARGET_CHAR_BIT
,
10969 0, "long_long_float", (struct objfile
*) NULL
);
10970 lai
->primitive_type_vector
[ada_primitive_type_natural
] =
10971 init_type (TYPE_CODE_INT
,
10972 gdbarch_int_bit (gdbarch
) / TARGET_CHAR_BIT
,
10973 0, "natural", (struct objfile
*) NULL
);
10974 lai
->primitive_type_vector
[ada_primitive_type_positive
] =
10975 init_type (TYPE_CODE_INT
,
10976 gdbarch_int_bit (gdbarch
) / TARGET_CHAR_BIT
,
10977 0, "positive", (struct objfile
*) NULL
);
10978 lai
->primitive_type_vector
[ada_primitive_type_void
] = builtin
->builtin_void
;
10980 lai
->primitive_type_vector
[ada_primitive_type_system_address
] =
10981 lookup_pointer_type (init_type (TYPE_CODE_VOID
, 1, 0, "void",
10982 (struct objfile
*) NULL
));
10983 TYPE_NAME (lai
->primitive_type_vector
[ada_primitive_type_system_address
])
10984 = "system__address";
10987 /* Language vector */
10989 /* Not really used, but needed in the ada_language_defn. */
10992 emit_char (int c
, struct ui_file
*stream
, int quoter
)
10994 ada_emit_char (c
, stream
, quoter
, 1);
11000 warnings_issued
= 0;
11001 return ada_parse ();
11004 static const struct exp_descriptor ada_exp_descriptor
= {
11006 ada_operator_length
,
11008 ada_dump_subexp_body
,
11009 ada_evaluate_subexp
11012 const struct language_defn ada_language_defn
= {
11013 "ada", /* Language name */
11017 case_sensitive_on
, /* Yes, Ada is case-insensitive, but
11018 that's not quite what this means. */
11020 &ada_exp_descriptor
,
11024 ada_printchar
, /* Print a character constant */
11025 ada_printstr
, /* Function to print string constant */
11026 emit_char
, /* Function to print single char (not used) */
11027 ada_print_type
, /* Print a type using appropriate syntax */
11028 ada_val_print
, /* Print a value using appropriate syntax */
11029 ada_value_print
, /* Print a top-level value */
11030 NULL
, /* Language specific skip_trampoline */
11031 NULL
, /* value_of_this */
11032 ada_lookup_symbol_nonlocal
, /* Looking up non-local symbols. */
11033 basic_lookup_transparent_type
, /* lookup_transparent_type */
11034 ada_la_decode
, /* Language specific symbol demangler */
11035 NULL
, /* Language specific class_name_from_physname */
11036 ada_op_print_tab
, /* expression operators for printing */
11037 0, /* c-style arrays */
11038 1, /* String lower bound */
11039 ada_get_gdb_completer_word_break_characters
,
11040 ada_make_symbol_completion_list
,
11041 ada_language_arch_info
,
11042 ada_print_array_index
,
11043 default_pass_by_reference
,
11048 _initialize_ada_language (void)
11050 add_language (&ada_language_defn
);
11052 varsize_limit
= 65536;
11054 obstack_init (&symbol_list_obstack
);
11056 decoded_names_store
= htab_create_alloc
11057 (256, htab_hash_string
, (int (*)(const void *, const void *)) streq
,
11058 NULL
, xcalloc
, xfree
);
11060 observer_attach_executable_changed (ada_executable_changed_observer
);