1 /* Ada language support routines for GDB, the GNU debugger. Copyright (C)
3 1992, 1993, 1994, 1997, 1998, 1999, 2000, 2003, 2004, 2005, 2007, 2008,
4 2009 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "gdb_string.h"
28 #include "gdb_regex.h"
33 #include "expression.h"
34 #include "parser-defs.h"
40 #include "breakpoint.h"
43 #include "gdb_obstack.h"
45 #include "completer.h"
52 #include "dictionary.h"
53 #include "exceptions.h"
60 /* Define whether or not the C operator '/' truncates towards zero for
61 differently signed operands (truncation direction is undefined in C).
62 Copied from valarith.c. */
64 #ifndef TRUNCATION_TOWARDS_ZERO
65 #define TRUNCATION_TOWARDS_ZERO ((-5 / 2) == -2)
68 static void extract_string (CORE_ADDR addr
, char *buf
);
70 static void modify_general_field (char *, LONGEST
, int, int);
72 static struct type
*desc_base_type (struct type
*);
74 static struct type
*desc_bounds_type (struct type
*);
76 static struct value
*desc_bounds (struct value
*);
78 static int fat_pntr_bounds_bitpos (struct type
*);
80 static int fat_pntr_bounds_bitsize (struct type
*);
82 static struct type
*desc_data_type (struct type
*);
84 static struct value
*desc_data (struct value
*);
86 static int fat_pntr_data_bitpos (struct type
*);
88 static int fat_pntr_data_bitsize (struct type
*);
90 static struct value
*desc_one_bound (struct value
*, int, int);
92 static int desc_bound_bitpos (struct type
*, int, int);
94 static int desc_bound_bitsize (struct type
*, int, int);
96 static struct type
*desc_index_type (struct type
*, int);
98 static int desc_arity (struct type
*);
100 static int ada_type_match (struct type
*, struct type
*, int);
102 static int ada_args_match (struct symbol
*, struct value
**, int);
104 static struct value
*ensure_lval (struct value
*, CORE_ADDR
*);
106 static struct value
*convert_actual (struct value
*, struct type
*,
109 static struct value
*make_array_descriptor (struct type
*, struct value
*,
112 static void ada_add_block_symbols (struct obstack
*,
113 struct block
*, const char *,
114 domain_enum
, struct objfile
*, int);
116 static int is_nonfunction (struct ada_symbol_info
*, int);
118 static void add_defn_to_vec (struct obstack
*, struct symbol
*,
121 static int num_defns_collected (struct obstack
*);
123 static struct ada_symbol_info
*defns_collected (struct obstack
*, int);
125 static struct partial_symbol
*ada_lookup_partial_symbol (struct partial_symtab
126 *, const char *, int,
129 static struct symtab
*symtab_for_sym (struct symbol
*);
131 static struct value
*resolve_subexp (struct expression
**, int *, int,
134 static void replace_operator_with_call (struct expression
**, int, int, int,
135 struct symbol
*, struct block
*);
137 static int possible_user_operator_p (enum exp_opcode
, struct value
**);
139 static char *ada_op_name (enum exp_opcode
);
141 static const char *ada_decoded_op_name (enum exp_opcode
);
143 static int numeric_type_p (struct type
*);
145 static int integer_type_p (struct type
*);
147 static int scalar_type_p (struct type
*);
149 static int discrete_type_p (struct type
*);
151 static enum ada_renaming_category
parse_old_style_renaming (struct type
*,
156 static struct symbol
*find_old_style_renaming_symbol (const char *,
159 static struct type
*ada_lookup_struct_elt_type (struct type
*, char *,
162 static struct value
*evaluate_subexp (struct type
*, struct expression
*,
165 static struct value
*evaluate_subexp_type (struct expression
*, int *);
167 static int is_dynamic_field (struct type
*, int);
169 static struct type
*to_fixed_variant_branch_type (struct type
*,
171 CORE_ADDR
, struct value
*);
173 static struct type
*to_fixed_array_type (struct type
*, struct value
*, int);
175 static struct type
*to_fixed_range_type (char *, struct value
*,
178 static struct type
*to_static_fixed_type (struct type
*);
179 static struct type
*static_unwrap_type (struct type
*type
);
181 static struct value
*unwrap_value (struct value
*);
183 static struct type
*packed_array_type (struct type
*, long *);
185 static struct type
*decode_packed_array_type (struct type
*);
187 static struct value
*decode_packed_array (struct value
*);
189 static struct value
*value_subscript_packed (struct value
*, int,
192 static void move_bits (gdb_byte
*, int, const gdb_byte
*, int, int);
194 static struct value
*coerce_unspec_val_to_type (struct value
*,
197 static struct value
*get_var_value (char *, char *);
199 static int lesseq_defined_than (struct symbol
*, struct symbol
*);
201 static int equiv_types (struct type
*, struct type
*);
203 static int is_name_suffix (const char *);
205 static int wild_match (const char *, int, const char *);
207 static struct value
*ada_coerce_ref (struct value
*);
209 static LONGEST
pos_atr (struct value
*);
211 static struct value
*value_pos_atr (struct type
*, struct value
*);
213 static struct value
*value_val_atr (struct type
*, struct value
*);
215 static struct symbol
*standard_lookup (const char *, const struct block
*,
218 static struct value
*ada_search_struct_field (char *, struct value
*, int,
221 static struct value
*ada_value_primitive_field (struct value
*, int, int,
224 static int find_struct_field (char *, struct type
*, int,
225 struct type
**, int *, int *, int *, int *);
227 static struct value
*ada_to_fixed_value_create (struct type
*, CORE_ADDR
,
230 static struct value
*ada_to_fixed_value (struct value
*);
232 static int ada_resolve_function (struct ada_symbol_info
*, int,
233 struct value
**, int, const char *,
236 static struct value
*ada_coerce_to_simple_array (struct value
*);
238 static int ada_is_direct_array_type (struct type
*);
240 static void ada_language_arch_info (struct gdbarch
*,
241 struct language_arch_info
*);
243 static void check_size (const struct type
*);
245 static struct value
*ada_index_struct_field (int, struct value
*, int,
248 static struct value
*assign_aggregate (struct value
*, struct value
*,
249 struct expression
*, int *, enum noside
);
251 static void aggregate_assign_from_choices (struct value
*, struct value
*,
253 int *, LONGEST
*, int *,
254 int, LONGEST
, LONGEST
);
256 static void aggregate_assign_positional (struct value
*, struct value
*,
258 int *, LONGEST
*, int *, int,
262 static void aggregate_assign_others (struct value
*, struct value
*,
264 int *, LONGEST
*, int, LONGEST
, LONGEST
);
267 static void add_component_interval (LONGEST
, LONGEST
, LONGEST
*, int *, int);
270 static struct value
*ada_evaluate_subexp (struct type
*, struct expression
*,
273 static void ada_forward_operator_length (struct expression
*, int, int *,
278 /* Maximum-sized dynamic type. */
279 static unsigned int varsize_limit
;
281 /* FIXME: brobecker/2003-09-17: No longer a const because it is
282 returned by a function that does not return a const char *. */
283 static char *ada_completer_word_break_characters
=
285 " \t\n!@#%^&*()+=|~`}{[]\";:?/,-";
287 " \t\n!@#$%^&*()+=|~`}{[]\";:?/,-";
290 /* The name of the symbol to use to get the name of the main subprogram. */
291 static const char ADA_MAIN_PROGRAM_SYMBOL_NAME
[]
292 = "__gnat_ada_main_program_name";
294 /* Limit on the number of warnings to raise per expression evaluation. */
295 static int warning_limit
= 2;
297 /* Number of warning messages issued; reset to 0 by cleanups after
298 expression evaluation. */
299 static int warnings_issued
= 0;
301 static const char *known_runtime_file_name_patterns
[] = {
302 ADA_KNOWN_RUNTIME_FILE_NAME_PATTERNS NULL
305 static const char *known_auxiliary_function_name_patterns
[] = {
306 ADA_KNOWN_AUXILIARY_FUNCTION_NAME_PATTERNS NULL
309 /* Space for allocating results of ada_lookup_symbol_list. */
310 static struct obstack symbol_list_obstack
;
314 /* Given DECODED_NAME a string holding a symbol name in its
315 decoded form (ie using the Ada dotted notation), returns
316 its unqualified name. */
319 ada_unqualified_name (const char *decoded_name
)
321 const char *result
= strrchr (decoded_name
, '.');
324 result
++; /* Skip the dot... */
326 result
= decoded_name
;
331 /* Return a string starting with '<', followed by STR, and '>'.
332 The result is good until the next call. */
335 add_angle_brackets (const char *str
)
337 static char *result
= NULL
;
340 result
= (char *) xmalloc ((strlen (str
) + 3) * sizeof (char));
342 sprintf (result
, "<%s>", str
);
347 ada_get_gdb_completer_word_break_characters (void)
349 return ada_completer_word_break_characters
;
352 /* Print an array element index using the Ada syntax. */
355 ada_print_array_index (struct value
*index_value
, struct ui_file
*stream
,
356 const struct value_print_options
*options
)
358 LA_VALUE_PRINT (index_value
, stream
, options
);
359 fprintf_filtered (stream
, " => ");
362 /* Read the string located at ADDR from the inferior and store the
366 extract_string (CORE_ADDR addr
, char *buf
)
370 /* Loop, reading one byte at a time, until we reach the '\000'
371 end-of-string marker. */
374 target_read_memory (addr
+ char_index
* sizeof (char),
375 buf
+ char_index
* sizeof (char), sizeof (char));
378 while (buf
[char_index
- 1] != '\000');
381 /* Assuming VECT points to an array of *SIZE objects of size
382 ELEMENT_SIZE, grow it to contain at least MIN_SIZE objects,
383 updating *SIZE as necessary and returning the (new) array. */
386 grow_vect (void *vect
, size_t *size
, size_t min_size
, int element_size
)
388 if (*size
< min_size
)
391 if (*size
< min_size
)
393 vect
= xrealloc (vect
, *size
* element_size
);
398 /* True (non-zero) iff TARGET matches FIELD_NAME up to any trailing
399 suffix of FIELD_NAME beginning "___". */
402 field_name_match (const char *field_name
, const char *target
)
404 int len
= strlen (target
);
406 (strncmp (field_name
, target
, len
) == 0
407 && (field_name
[len
] == '\0'
408 || (strncmp (field_name
+ len
, "___", 3) == 0
409 && strcmp (field_name
+ strlen (field_name
) - 6,
414 /* Assuming TYPE is a TYPE_CODE_STRUCT or a TYPE_CODE_TYPDEF to
415 a TYPE_CODE_STRUCT, find the field whose name matches FIELD_NAME,
416 and return its index. This function also handles fields whose name
417 have ___ suffixes because the compiler sometimes alters their name
418 by adding such a suffix to represent fields with certain constraints.
419 If the field could not be found, return a negative number if
420 MAYBE_MISSING is set. Otherwise raise an error. */
423 ada_get_field_index (const struct type
*type
, const char *field_name
,
427 struct type
*struct_type
= check_typedef ((struct type
*) type
);
429 for (fieldno
= 0; fieldno
< TYPE_NFIELDS (struct_type
); fieldno
++)
430 if (field_name_match (TYPE_FIELD_NAME (struct_type
, fieldno
), field_name
))
434 error (_("Unable to find field %s in struct %s. Aborting"),
435 field_name
, TYPE_NAME (struct_type
));
440 /* The length of the prefix of NAME prior to any "___" suffix. */
443 ada_name_prefix_len (const char *name
)
449 const char *p
= strstr (name
, "___");
451 return strlen (name
);
457 /* Return non-zero if SUFFIX is a suffix of STR.
458 Return zero if STR is null. */
461 is_suffix (const char *str
, const char *suffix
)
467 len2
= strlen (suffix
);
468 return (len1
>= len2
&& strcmp (str
+ len1
- len2
, suffix
) == 0);
471 /* The contents of value VAL, treated as a value of type TYPE. The
472 result is an lval in memory if VAL is. */
474 static struct value
*
475 coerce_unspec_val_to_type (struct value
*val
, struct type
*type
)
477 type
= ada_check_typedef (type
);
478 if (value_type (val
) == type
)
482 struct value
*result
;
484 /* Make sure that the object size is not unreasonable before
485 trying to allocate some memory for it. */
488 result
= allocate_value (type
);
489 set_value_component_location (result
, val
);
490 set_value_bitsize (result
, value_bitsize (val
));
491 set_value_bitpos (result
, value_bitpos (val
));
492 VALUE_ADDRESS (result
) += value_offset (val
);
494 || TYPE_LENGTH (type
) > TYPE_LENGTH (value_type (val
)))
495 set_value_lazy (result
, 1);
497 memcpy (value_contents_raw (result
), value_contents (val
),
503 static const gdb_byte
*
504 cond_offset_host (const gdb_byte
*valaddr
, long offset
)
509 return valaddr
+ offset
;
513 cond_offset_target (CORE_ADDR address
, long offset
)
518 return address
+ offset
;
521 /* Issue a warning (as for the definition of warning in utils.c, but
522 with exactly one argument rather than ...), unless the limit on the
523 number of warnings has passed during the evaluation of the current
526 /* FIXME: cagney/2004-10-10: This function is mimicking the behavior
527 provided by "complaint". */
528 static void lim_warning (const char *format
, ...) ATTR_FORMAT (printf
, 1, 2);
531 lim_warning (const char *format
, ...)
534 va_start (args
, format
);
536 warnings_issued
+= 1;
537 if (warnings_issued
<= warning_limit
)
538 vwarning (format
, args
);
543 /* Issue an error if the size of an object of type T is unreasonable,
544 i.e. if it would be a bad idea to allocate a value of this type in
548 check_size (const struct type
*type
)
550 if (TYPE_LENGTH (type
) > varsize_limit
)
551 error (_("object size is larger than varsize-limit"));
555 /* Note: would have used MAX_OF_TYPE and MIN_OF_TYPE macros from
556 gdbtypes.h, but some of the necessary definitions in that file
557 seem to have gone missing. */
559 /* Maximum value of a SIZE-byte signed integer type. */
561 max_of_size (int size
)
563 LONGEST top_bit
= (LONGEST
) 1 << (size
* 8 - 2);
564 return top_bit
| (top_bit
- 1);
567 /* Minimum value of a SIZE-byte signed integer type. */
569 min_of_size (int size
)
571 return -max_of_size (size
) - 1;
574 /* Maximum value of a SIZE-byte unsigned integer type. */
576 umax_of_size (int size
)
578 ULONGEST top_bit
= (ULONGEST
) 1 << (size
* 8 - 1);
579 return top_bit
| (top_bit
- 1);
582 /* Maximum value of integral type T, as a signed quantity. */
584 max_of_type (struct type
*t
)
586 if (TYPE_UNSIGNED (t
))
587 return (LONGEST
) umax_of_size (TYPE_LENGTH (t
));
589 return max_of_size (TYPE_LENGTH (t
));
592 /* Minimum value of integral type T, as a signed quantity. */
594 min_of_type (struct type
*t
)
596 if (TYPE_UNSIGNED (t
))
599 return min_of_size (TYPE_LENGTH (t
));
602 /* The largest value in the domain of TYPE, a discrete type, as an integer. */
604 discrete_type_high_bound (struct type
*type
)
606 switch (TYPE_CODE (type
))
608 case TYPE_CODE_RANGE
:
609 return TYPE_HIGH_BOUND (type
);
611 return TYPE_FIELD_BITPOS (type
, TYPE_NFIELDS (type
) - 1);
616 return max_of_type (type
);
618 error (_("Unexpected type in discrete_type_high_bound."));
622 /* The largest value in the domain of TYPE, a discrete type, as an integer. */
624 discrete_type_low_bound (struct type
*type
)
626 switch (TYPE_CODE (type
))
628 case TYPE_CODE_RANGE
:
629 return TYPE_LOW_BOUND (type
);
631 return TYPE_FIELD_BITPOS (type
, 0);
636 return min_of_type (type
);
638 error (_("Unexpected type in discrete_type_low_bound."));
642 /* The identity on non-range types. For range types, the underlying
643 non-range scalar type. */
646 base_type (struct type
*type
)
648 while (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_RANGE
)
650 if (type
== TYPE_TARGET_TYPE (type
) || TYPE_TARGET_TYPE (type
) == NULL
)
652 type
= TYPE_TARGET_TYPE (type
);
658 /* Language Selection */
660 /* If the main program is in Ada, return language_ada, otherwise return LANG
661 (the main program is in Ada iif the adainit symbol is found).
663 MAIN_PST is not used. */
666 ada_update_initial_language (enum language lang
,
667 struct partial_symtab
*main_pst
)
669 if (lookup_minimal_symbol ("adainit", (const char *) NULL
,
670 (struct objfile
*) NULL
) != NULL
)
676 /* If the main procedure is written in Ada, then return its name.
677 The result is good until the next call. Return NULL if the main
678 procedure doesn't appear to be in Ada. */
683 struct minimal_symbol
*msym
;
684 CORE_ADDR main_program_name_addr
;
685 static char main_program_name
[1024];
687 /* For Ada, the name of the main procedure is stored in a specific
688 string constant, generated by the binder. Look for that symbol,
689 extract its address, and then read that string. If we didn't find
690 that string, then most probably the main procedure is not written
692 msym
= lookup_minimal_symbol (ADA_MAIN_PROGRAM_SYMBOL_NAME
, NULL
, NULL
);
696 main_program_name_addr
= SYMBOL_VALUE_ADDRESS (msym
);
697 if (main_program_name_addr
== 0)
698 error (_("Invalid address for Ada main program name."));
700 extract_string (main_program_name_addr
, main_program_name
);
701 return main_program_name
;
704 /* The main procedure doesn't seem to be in Ada. */
710 /* Table of Ada operators and their GNAT-encoded names. Last entry is pair
713 const struct ada_opname_map ada_opname_table
[] = {
714 {"Oadd", "\"+\"", BINOP_ADD
},
715 {"Osubtract", "\"-\"", BINOP_SUB
},
716 {"Omultiply", "\"*\"", BINOP_MUL
},
717 {"Odivide", "\"/\"", BINOP_DIV
},
718 {"Omod", "\"mod\"", BINOP_MOD
},
719 {"Orem", "\"rem\"", BINOP_REM
},
720 {"Oexpon", "\"**\"", BINOP_EXP
},
721 {"Olt", "\"<\"", BINOP_LESS
},
722 {"Ole", "\"<=\"", BINOP_LEQ
},
723 {"Ogt", "\">\"", BINOP_GTR
},
724 {"Oge", "\">=\"", BINOP_GEQ
},
725 {"Oeq", "\"=\"", BINOP_EQUAL
},
726 {"One", "\"/=\"", BINOP_NOTEQUAL
},
727 {"Oand", "\"and\"", BINOP_BITWISE_AND
},
728 {"Oor", "\"or\"", BINOP_BITWISE_IOR
},
729 {"Oxor", "\"xor\"", BINOP_BITWISE_XOR
},
730 {"Oconcat", "\"&\"", BINOP_CONCAT
},
731 {"Oabs", "\"abs\"", UNOP_ABS
},
732 {"Onot", "\"not\"", UNOP_LOGICAL_NOT
},
733 {"Oadd", "\"+\"", UNOP_PLUS
},
734 {"Osubtract", "\"-\"", UNOP_NEG
},
738 /* The "encoded" form of DECODED, according to GNAT conventions.
739 The result is valid until the next call to ada_encode. */
742 ada_encode (const char *decoded
)
744 static char *encoding_buffer
= NULL
;
745 static size_t encoding_buffer_size
= 0;
752 GROW_VECT (encoding_buffer
, encoding_buffer_size
,
753 2 * strlen (decoded
) + 10);
756 for (p
= decoded
; *p
!= '\0'; p
+= 1)
760 encoding_buffer
[k
] = encoding_buffer
[k
+ 1] = '_';
765 const struct ada_opname_map
*mapping
;
767 for (mapping
= ada_opname_table
;
768 mapping
->encoded
!= NULL
769 && strncmp (mapping
->decoded
, p
,
770 strlen (mapping
->decoded
)) != 0; mapping
+= 1)
772 if (mapping
->encoded
== NULL
)
773 error (_("invalid Ada operator name: %s"), p
);
774 strcpy (encoding_buffer
+ k
, mapping
->encoded
);
775 k
+= strlen (mapping
->encoded
);
780 encoding_buffer
[k
] = *p
;
785 encoding_buffer
[k
] = '\0';
786 return encoding_buffer
;
789 /* Return NAME folded to lower case, or, if surrounded by single
790 quotes, unfolded, but with the quotes stripped away. Result good
794 ada_fold_name (const char *name
)
796 static char *fold_buffer
= NULL
;
797 static size_t fold_buffer_size
= 0;
799 int len
= strlen (name
);
800 GROW_VECT (fold_buffer
, fold_buffer_size
, len
+ 1);
804 strncpy (fold_buffer
, name
+ 1, len
- 2);
805 fold_buffer
[len
- 2] = '\000';
810 for (i
= 0; i
<= len
; i
+= 1)
811 fold_buffer
[i
] = tolower (name
[i
]);
817 /* Return nonzero if C is either a digit or a lowercase alphabet character. */
820 is_lower_alphanum (const char c
)
822 return (isdigit (c
) || (isalpha (c
) && islower (c
)));
825 /* Remove either of these suffixes:
830 These are suffixes introduced by the compiler for entities such as
831 nested subprogram for instance, in order to avoid name clashes.
832 They do not serve any purpose for the debugger. */
835 ada_remove_trailing_digits (const char *encoded
, int *len
)
837 if (*len
> 1 && isdigit (encoded
[*len
- 1]))
840 while (i
> 0 && isdigit (encoded
[i
]))
842 if (i
>= 0 && encoded
[i
] == '.')
844 else if (i
>= 0 && encoded
[i
] == '$')
846 else if (i
>= 2 && strncmp (encoded
+ i
- 2, "___", 3) == 0)
848 else if (i
>= 1 && strncmp (encoded
+ i
- 1, "__", 2) == 0)
853 /* Remove the suffix introduced by the compiler for protected object
857 ada_remove_po_subprogram_suffix (const char *encoded
, int *len
)
859 /* Remove trailing N. */
861 /* Protected entry subprograms are broken into two
862 separate subprograms: The first one is unprotected, and has
863 a 'N' suffix; the second is the protected version, and has
864 the 'P' suffix. The second calls the first one after handling
865 the protection. Since the P subprograms are internally generated,
866 we leave these names undecoded, giving the user a clue that this
867 entity is internal. */
870 && encoded
[*len
- 1] == 'N'
871 && (isdigit (encoded
[*len
- 2]) || islower (encoded
[*len
- 2])))
875 /* If ENCODED follows the GNAT entity encoding conventions, then return
876 the decoded form of ENCODED. Otherwise, return "<%s>" where "%s" is
879 The resulting string is valid until the next call of ada_decode.
880 If the string is unchanged by decoding, the original string pointer
884 ada_decode (const char *encoded
)
891 static char *decoding_buffer
= NULL
;
892 static size_t decoding_buffer_size
= 0;
894 /* The name of the Ada main procedure starts with "_ada_".
895 This prefix is not part of the decoded name, so skip this part
896 if we see this prefix. */
897 if (strncmp (encoded
, "_ada_", 5) == 0)
900 /* If the name starts with '_', then it is not a properly encoded
901 name, so do not attempt to decode it. Similarly, if the name
902 starts with '<', the name should not be decoded. */
903 if (encoded
[0] == '_' || encoded
[0] == '<')
906 len0
= strlen (encoded
);
908 ada_remove_trailing_digits (encoded
, &len0
);
909 ada_remove_po_subprogram_suffix (encoded
, &len0
);
911 /* Remove the ___X.* suffix if present. Do not forget to verify that
912 the suffix is located before the current "end" of ENCODED. We want
913 to avoid re-matching parts of ENCODED that have previously been
914 marked as discarded (by decrementing LEN0). */
915 p
= strstr (encoded
, "___");
916 if (p
!= NULL
&& p
- encoded
< len0
- 3)
924 /* Remove any trailing TKB suffix. It tells us that this symbol
925 is for the body of a task, but that information does not actually
926 appear in the decoded name. */
928 if (len0
> 3 && strncmp (encoded
+ len0
- 3, "TKB", 3) == 0)
931 /* Remove trailing "B" suffixes. */
932 /* FIXME: brobecker/2006-04-19: Not sure what this are used for... */
934 if (len0
> 1 && strncmp (encoded
+ len0
- 1, "B", 1) == 0)
937 /* Make decoded big enough for possible expansion by operator name. */
939 GROW_VECT (decoding_buffer
, decoding_buffer_size
, 2 * len0
+ 1);
940 decoded
= decoding_buffer
;
942 /* Remove trailing __{digit}+ or trailing ${digit}+. */
944 if (len0
> 1 && isdigit (encoded
[len0
- 1]))
947 while ((i
>= 0 && isdigit (encoded
[i
]))
948 || (i
>= 1 && encoded
[i
] == '_' && isdigit (encoded
[i
- 1])))
950 if (i
> 1 && encoded
[i
] == '_' && encoded
[i
- 1] == '_')
952 else if (encoded
[i
] == '$')
956 /* The first few characters that are not alphabetic are not part
957 of any encoding we use, so we can copy them over verbatim. */
959 for (i
= 0, j
= 0; i
< len0
&& !isalpha (encoded
[i
]); i
+= 1, j
+= 1)
960 decoded
[j
] = encoded
[i
];
965 /* Is this a symbol function? */
966 if (at_start_name
&& encoded
[i
] == 'O')
969 for (k
= 0; ada_opname_table
[k
].encoded
!= NULL
; k
+= 1)
971 int op_len
= strlen (ada_opname_table
[k
].encoded
);
972 if ((strncmp (ada_opname_table
[k
].encoded
+ 1, encoded
+ i
+ 1,
974 && !isalnum (encoded
[i
+ op_len
]))
976 strcpy (decoded
+ j
, ada_opname_table
[k
].decoded
);
979 j
+= strlen (ada_opname_table
[k
].decoded
);
983 if (ada_opname_table
[k
].encoded
!= NULL
)
988 /* Replace "TK__" with "__", which will eventually be translated
989 into "." (just below). */
991 if (i
< len0
- 4 && strncmp (encoded
+ i
, "TK__", 4) == 0)
994 /* Replace "__B_{DIGITS}+__" sequences by "__", which will eventually
995 be translated into "." (just below). These are internal names
996 generated for anonymous blocks inside which our symbol is nested. */
998 if (len0
- i
> 5 && encoded
[i
] == '_' && encoded
[i
+1] == '_'
999 && encoded
[i
+2] == 'B' && encoded
[i
+3] == '_'
1000 && isdigit (encoded
[i
+4]))
1004 while (k
< len0
&& isdigit (encoded
[k
]))
1005 k
++; /* Skip any extra digit. */
1007 /* Double-check that the "__B_{DIGITS}+" sequence we found
1008 is indeed followed by "__". */
1009 if (len0
- k
> 2 && encoded
[k
] == '_' && encoded
[k
+1] == '_')
1013 /* Remove _E{DIGITS}+[sb] */
1015 /* Just as for protected object subprograms, there are 2 categories
1016 of subprograms created by the compiler for each entry. The first
1017 one implements the actual entry code, and has a suffix following
1018 the convention above; the second one implements the barrier and
1019 uses the same convention as above, except that the 'E' is replaced
1022 Just as above, we do not decode the name of barrier functions
1023 to give the user a clue that the code he is debugging has been
1024 internally generated. */
1026 if (len0
- i
> 3 && encoded
[i
] == '_' && encoded
[i
+1] == 'E'
1027 && isdigit (encoded
[i
+2]))
1031 while (k
< len0
&& isdigit (encoded
[k
]))
1035 && (encoded
[k
] == 'b' || encoded
[k
] == 's'))
1038 /* Just as an extra precaution, make sure that if this
1039 suffix is followed by anything else, it is a '_'.
1040 Otherwise, we matched this sequence by accident. */
1042 || (k
< len0
&& encoded
[k
] == '_'))
1047 /* Remove trailing "N" in [a-z0-9]+N__. The N is added by
1048 the GNAT front-end in protected object subprograms. */
1051 && encoded
[i
] == 'N' && encoded
[i
+1] == '_' && encoded
[i
+2] == '_')
1053 /* Backtrack a bit up until we reach either the begining of
1054 the encoded name, or "__". Make sure that we only find
1055 digits or lowercase characters. */
1056 const char *ptr
= encoded
+ i
- 1;
1058 while (ptr
>= encoded
&& is_lower_alphanum (ptr
[0]))
1061 || (ptr
> encoded
&& ptr
[0] == '_' && ptr
[-1] == '_'))
1065 if (encoded
[i
] == 'X' && i
!= 0 && isalnum (encoded
[i
- 1]))
1067 /* This is a X[bn]* sequence not separated from the previous
1068 part of the name with a non-alpha-numeric character (in other
1069 words, immediately following an alpha-numeric character), then
1070 verify that it is placed at the end of the encoded name. If
1071 not, then the encoding is not valid and we should abort the
1072 decoding. Otherwise, just skip it, it is used in body-nested
1076 while (i
< len0
&& (encoded
[i
] == 'b' || encoded
[i
] == 'n'));
1080 else if (i
< len0
- 2 && encoded
[i
] == '_' && encoded
[i
+ 1] == '_')
1082 /* Replace '__' by '.'. */
1090 /* It's a character part of the decoded name, so just copy it
1092 decoded
[j
] = encoded
[i
];
1097 decoded
[j
] = '\000';
1099 /* Decoded names should never contain any uppercase character.
1100 Double-check this, and abort the decoding if we find one. */
1102 for (i
= 0; decoded
[i
] != '\0'; i
+= 1)
1103 if (isupper (decoded
[i
]) || decoded
[i
] == ' ')
1106 if (strcmp (decoded
, encoded
) == 0)
1112 GROW_VECT (decoding_buffer
, decoding_buffer_size
, strlen (encoded
) + 3);
1113 decoded
= decoding_buffer
;
1114 if (encoded
[0] == '<')
1115 strcpy (decoded
, encoded
);
1117 sprintf (decoded
, "<%s>", encoded
);
1122 /* Table for keeping permanent unique copies of decoded names. Once
1123 allocated, names in this table are never released. While this is a
1124 storage leak, it should not be significant unless there are massive
1125 changes in the set of decoded names in successive versions of a
1126 symbol table loaded during a single session. */
1127 static struct htab
*decoded_names_store
;
1129 /* Returns the decoded name of GSYMBOL, as for ada_decode, caching it
1130 in the language-specific part of GSYMBOL, if it has not been
1131 previously computed. Tries to save the decoded name in the same
1132 obstack as GSYMBOL, if possible, and otherwise on the heap (so that,
1133 in any case, the decoded symbol has a lifetime at least that of
1135 The GSYMBOL parameter is "mutable" in the C++ sense: logically
1136 const, but nevertheless modified to a semantically equivalent form
1137 when a decoded name is cached in it.
1141 ada_decode_symbol (const struct general_symbol_info
*gsymbol
)
1144 (char **) &gsymbol
->language_specific
.cplus_specific
.demangled_name
;
1145 if (*resultp
== NULL
)
1147 const char *decoded
= ada_decode (gsymbol
->name
);
1148 if (gsymbol
->obj_section
!= NULL
)
1150 struct objfile
*objf
= gsymbol
->obj_section
->objfile
;
1151 *resultp
= obsavestring (decoded
, strlen (decoded
),
1152 &objf
->objfile_obstack
);
1154 /* Sometimes, we can't find a corresponding objfile, in which
1155 case, we put the result on the heap. Since we only decode
1156 when needed, we hope this usually does not cause a
1157 significant memory leak (FIXME). */
1158 if (*resultp
== NULL
)
1160 char **slot
= (char **) htab_find_slot (decoded_names_store
,
1163 *slot
= xstrdup (decoded
);
1172 ada_la_decode (const char *encoded
, int options
)
1174 return xstrdup (ada_decode (encoded
));
1177 /* Returns non-zero iff SYM_NAME matches NAME, ignoring any trailing
1178 suffixes that encode debugging information or leading _ada_ on
1179 SYM_NAME (see is_name_suffix commentary for the debugging
1180 information that is ignored). If WILD, then NAME need only match a
1181 suffix of SYM_NAME minus the same suffixes. Also returns 0 if
1182 either argument is NULL. */
1185 ada_match_name (const char *sym_name
, const char *name
, int wild
)
1187 if (sym_name
== NULL
|| name
== NULL
)
1190 return wild_match (name
, strlen (name
), sym_name
);
1193 int len_name
= strlen (name
);
1194 return (strncmp (sym_name
, name
, len_name
) == 0
1195 && is_name_suffix (sym_name
+ len_name
))
1196 || (strncmp (sym_name
, "_ada_", 5) == 0
1197 && strncmp (sym_name
+ 5, name
, len_name
) == 0
1198 && is_name_suffix (sym_name
+ len_name
+ 5));
1205 /* Names of MAX_ADA_DIMENS bounds in P_BOUNDS fields of array descriptors. */
1207 static char *bound_name
[] = {
1208 "LB0", "UB0", "LB1", "UB1", "LB2", "UB2", "LB3", "UB3",
1209 "LB4", "UB4", "LB5", "UB5", "LB6", "UB6", "LB7", "UB7"
1212 /* Maximum number of array dimensions we are prepared to handle. */
1214 #define MAX_ADA_DIMENS (sizeof(bound_name) / (2*sizeof(char *)))
1216 /* Like modify_field, but allows bitpos > wordlength. */
1219 modify_general_field (char *addr
, LONGEST fieldval
, int bitpos
, int bitsize
)
1221 modify_field (addr
+ bitpos
/ 8, fieldval
, bitpos
% 8, bitsize
);
1225 /* The desc_* routines return primitive portions of array descriptors
1228 /* The descriptor or array type, if any, indicated by TYPE; removes
1229 level of indirection, if needed. */
1231 static struct type
*
1232 desc_base_type (struct type
*type
)
1236 type
= ada_check_typedef (type
);
1238 && (TYPE_CODE (type
) == TYPE_CODE_PTR
1239 || TYPE_CODE (type
) == TYPE_CODE_REF
))
1240 return ada_check_typedef (TYPE_TARGET_TYPE (type
));
1245 /* True iff TYPE indicates a "thin" array pointer type. */
1248 is_thin_pntr (struct type
*type
)
1251 is_suffix (ada_type_name (desc_base_type (type
)), "___XUT")
1252 || is_suffix (ada_type_name (desc_base_type (type
)), "___XUT___XVE");
1255 /* The descriptor type for thin pointer type TYPE. */
1257 static struct type
*
1258 thin_descriptor_type (struct type
*type
)
1260 struct type
*base_type
= desc_base_type (type
);
1261 if (base_type
== NULL
)
1263 if (is_suffix (ada_type_name (base_type
), "___XVE"))
1267 struct type
*alt_type
= ada_find_parallel_type (base_type
, "___XVE");
1268 if (alt_type
== NULL
)
1275 /* A pointer to the array data for thin-pointer value VAL. */
1277 static struct value
*
1278 thin_data_pntr (struct value
*val
)
1280 struct type
*type
= value_type (val
);
1281 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
1282 return value_cast (desc_data_type (thin_descriptor_type (type
)),
1285 return value_from_longest (desc_data_type (thin_descriptor_type (type
)),
1286 VALUE_ADDRESS (val
) + value_offset (val
));
1289 /* True iff TYPE indicates a "thick" array pointer type. */
1292 is_thick_pntr (struct type
*type
)
1294 type
= desc_base_type (type
);
1295 return (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_STRUCT
1296 && lookup_struct_elt_type (type
, "P_BOUNDS", 1) != NULL
);
1299 /* If TYPE is the type of an array descriptor (fat or thin pointer) or a
1300 pointer to one, the type of its bounds data; otherwise, NULL. */
1302 static struct type
*
1303 desc_bounds_type (struct type
*type
)
1307 type
= desc_base_type (type
);
1311 else if (is_thin_pntr (type
))
1313 type
= thin_descriptor_type (type
);
1316 r
= lookup_struct_elt_type (type
, "BOUNDS", 1);
1318 return ada_check_typedef (r
);
1320 else if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
)
1322 r
= lookup_struct_elt_type (type
, "P_BOUNDS", 1);
1324 return ada_check_typedef (TYPE_TARGET_TYPE (ada_check_typedef (r
)));
1329 /* If ARR is an array descriptor (fat or thin pointer), or pointer to
1330 one, a pointer to its bounds data. Otherwise NULL. */
1332 static struct value
*
1333 desc_bounds (struct value
*arr
)
1335 struct type
*type
= ada_check_typedef (value_type (arr
));
1336 if (is_thin_pntr (type
))
1338 struct type
*bounds_type
=
1339 desc_bounds_type (thin_descriptor_type (type
));
1342 if (bounds_type
== NULL
)
1343 error (_("Bad GNAT array descriptor"));
1345 /* NOTE: The following calculation is not really kosher, but
1346 since desc_type is an XVE-encoded type (and shouldn't be),
1347 the correct calculation is a real pain. FIXME (and fix GCC). */
1348 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
1349 addr
= value_as_long (arr
);
1351 addr
= VALUE_ADDRESS (arr
) + value_offset (arr
);
1354 value_from_longest (lookup_pointer_type (bounds_type
),
1355 addr
- TYPE_LENGTH (bounds_type
));
1358 else if (is_thick_pntr (type
))
1359 return value_struct_elt (&arr
, NULL
, "P_BOUNDS", NULL
,
1360 _("Bad GNAT array descriptor"));
1365 /* If TYPE is the type of an array-descriptor (fat pointer), the bit
1366 position of the field containing the address of the bounds data. */
1369 fat_pntr_bounds_bitpos (struct type
*type
)
1371 return TYPE_FIELD_BITPOS (desc_base_type (type
), 1);
1374 /* If TYPE is the type of an array-descriptor (fat pointer), the bit
1375 size of the field containing the address of the bounds data. */
1378 fat_pntr_bounds_bitsize (struct type
*type
)
1380 type
= desc_base_type (type
);
1382 if (TYPE_FIELD_BITSIZE (type
, 1) > 0)
1383 return TYPE_FIELD_BITSIZE (type
, 1);
1385 return 8 * TYPE_LENGTH (ada_check_typedef (TYPE_FIELD_TYPE (type
, 1)));
1388 /* If TYPE is the type of an array descriptor (fat or thin pointer) or a
1389 pointer to one, the type of its array data (a
1390 pointer-to-array-with-no-bounds type); otherwise, NULL. Use
1391 ada_type_of_array to get an array type with bounds data. */
1393 static struct type
*
1394 desc_data_type (struct type
*type
)
1396 type
= desc_base_type (type
);
1398 /* NOTE: The following is bogus; see comment in desc_bounds. */
1399 if (is_thin_pntr (type
))
1400 return lookup_pointer_type
1401 (desc_base_type (TYPE_FIELD_TYPE (thin_descriptor_type (type
), 1)));
1402 else if (is_thick_pntr (type
))
1403 return lookup_struct_elt_type (type
, "P_ARRAY", 1);
1408 /* If ARR is an array descriptor (fat or thin pointer), a pointer to
1411 static struct value
*
1412 desc_data (struct value
*arr
)
1414 struct type
*type
= value_type (arr
);
1415 if (is_thin_pntr (type
))
1416 return thin_data_pntr (arr
);
1417 else if (is_thick_pntr (type
))
1418 return value_struct_elt (&arr
, NULL
, "P_ARRAY", NULL
,
1419 _("Bad GNAT array descriptor"));
1425 /* If TYPE is the type of an array-descriptor (fat pointer), the bit
1426 position of the field containing the address of the data. */
1429 fat_pntr_data_bitpos (struct type
*type
)
1431 return TYPE_FIELD_BITPOS (desc_base_type (type
), 0);
1434 /* If TYPE is the type of an array-descriptor (fat pointer), the bit
1435 size of the field containing the address of the data. */
1438 fat_pntr_data_bitsize (struct type
*type
)
1440 type
= desc_base_type (type
);
1442 if (TYPE_FIELD_BITSIZE (type
, 0) > 0)
1443 return TYPE_FIELD_BITSIZE (type
, 0);
1445 return TARGET_CHAR_BIT
* TYPE_LENGTH (TYPE_FIELD_TYPE (type
, 0));
1448 /* If BOUNDS is an array-bounds structure (or pointer to one), return
1449 the Ith lower bound stored in it, if WHICH is 0, and the Ith upper
1450 bound, if WHICH is 1. The first bound is I=1. */
1452 static struct value
*
1453 desc_one_bound (struct value
*bounds
, int i
, int which
)
1455 return value_struct_elt (&bounds
, NULL
, bound_name
[2 * i
+ which
- 2], NULL
,
1456 _("Bad GNAT array descriptor bounds"));
1459 /* If BOUNDS is an array-bounds structure type, return the bit position
1460 of the Ith lower bound stored in it, if WHICH is 0, and the Ith upper
1461 bound, if WHICH is 1. The first bound is I=1. */
1464 desc_bound_bitpos (struct type
*type
, int i
, int which
)
1466 return TYPE_FIELD_BITPOS (desc_base_type (type
), 2 * i
+ which
- 2);
1469 /* If BOUNDS is an array-bounds structure type, return the bit field size
1470 of the Ith lower bound stored in it, if WHICH is 0, and the Ith upper
1471 bound, if WHICH is 1. The first bound is I=1. */
1474 desc_bound_bitsize (struct type
*type
, int i
, int which
)
1476 type
= desc_base_type (type
);
1478 if (TYPE_FIELD_BITSIZE (type
, 2 * i
+ which
- 2) > 0)
1479 return TYPE_FIELD_BITSIZE (type
, 2 * i
+ which
- 2);
1481 return 8 * TYPE_LENGTH (TYPE_FIELD_TYPE (type
, 2 * i
+ which
- 2));
1484 /* If TYPE is the type of an array-bounds structure, the type of its
1485 Ith bound (numbering from 1). Otherwise, NULL. */
1487 static struct type
*
1488 desc_index_type (struct type
*type
, int i
)
1490 type
= desc_base_type (type
);
1492 if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
)
1493 return lookup_struct_elt_type (type
, bound_name
[2 * i
- 2], 1);
1498 /* The number of index positions in the array-bounds type TYPE.
1499 Return 0 if TYPE is NULL. */
1502 desc_arity (struct type
*type
)
1504 type
= desc_base_type (type
);
1507 return TYPE_NFIELDS (type
) / 2;
1511 /* Non-zero iff TYPE is a simple array type (not a pointer to one) or
1512 an array descriptor type (representing an unconstrained array
1516 ada_is_direct_array_type (struct type
*type
)
1520 type
= ada_check_typedef (type
);
1521 return (TYPE_CODE (type
) == TYPE_CODE_ARRAY
1522 || ada_is_array_descriptor_type (type
));
1525 /* Non-zero iff TYPE represents any kind of array in Ada, or a pointer
1529 ada_is_array_type (struct type
*type
)
1532 && (TYPE_CODE (type
) == TYPE_CODE_PTR
1533 || TYPE_CODE (type
) == TYPE_CODE_REF
))
1534 type
= TYPE_TARGET_TYPE (type
);
1535 return ada_is_direct_array_type (type
);
1538 /* Non-zero iff TYPE is a simple array type or pointer to one. */
1541 ada_is_simple_array_type (struct type
*type
)
1545 type
= ada_check_typedef (type
);
1546 return (TYPE_CODE (type
) == TYPE_CODE_ARRAY
1547 || (TYPE_CODE (type
) == TYPE_CODE_PTR
1548 && TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_ARRAY
));
1551 /* Non-zero iff TYPE belongs to a GNAT array descriptor. */
1554 ada_is_array_descriptor_type (struct type
*type
)
1556 struct type
*data_type
= desc_data_type (type
);
1560 type
= ada_check_typedef (type
);
1563 && ((TYPE_CODE (data_type
) == TYPE_CODE_PTR
1564 && TYPE_TARGET_TYPE (data_type
) != NULL
1565 && TYPE_CODE (TYPE_TARGET_TYPE (data_type
)) == TYPE_CODE_ARRAY
)
1566 || TYPE_CODE (data_type
) == TYPE_CODE_ARRAY
)
1567 && desc_arity (desc_bounds_type (type
)) > 0;
1570 /* Non-zero iff type is a partially mal-formed GNAT array
1571 descriptor. FIXME: This is to compensate for some problems with
1572 debugging output from GNAT. Re-examine periodically to see if it
1576 ada_is_bogus_array_descriptor (struct type
*type
)
1580 && TYPE_CODE (type
) == TYPE_CODE_STRUCT
1581 && (lookup_struct_elt_type (type
, "P_BOUNDS", 1) != NULL
1582 || lookup_struct_elt_type (type
, "P_ARRAY", 1) != NULL
)
1583 && !ada_is_array_descriptor_type (type
);
1587 /* If ARR has a record type in the form of a standard GNAT array descriptor,
1588 (fat pointer) returns the type of the array data described---specifically,
1589 a pointer-to-array type. If BOUNDS is non-zero, the bounds data are filled
1590 in from the descriptor; otherwise, they are left unspecified. If
1591 the ARR denotes a null array descriptor and BOUNDS is non-zero,
1592 returns NULL. The result is simply the type of ARR if ARR is not
1595 ada_type_of_array (struct value
*arr
, int bounds
)
1597 if (ada_is_packed_array_type (value_type (arr
)))
1598 return decode_packed_array_type (value_type (arr
));
1600 if (!ada_is_array_descriptor_type (value_type (arr
)))
1601 return value_type (arr
);
1605 ada_check_typedef (TYPE_TARGET_TYPE (desc_data_type (value_type (arr
))));
1608 struct type
*elt_type
;
1610 struct value
*descriptor
;
1611 struct objfile
*objf
= TYPE_OBJFILE (value_type (arr
));
1613 elt_type
= ada_array_element_type (value_type (arr
), -1);
1614 arity
= ada_array_arity (value_type (arr
));
1616 if (elt_type
== NULL
|| arity
== 0)
1617 return ada_check_typedef (value_type (arr
));
1619 descriptor
= desc_bounds (arr
);
1620 if (value_as_long (descriptor
) == 0)
1624 struct type
*range_type
= alloc_type (objf
);
1625 struct type
*array_type
= alloc_type (objf
);
1626 struct value
*low
= desc_one_bound (descriptor
, arity
, 0);
1627 struct value
*high
= desc_one_bound (descriptor
, arity
, 1);
1630 create_range_type (range_type
, value_type (low
),
1631 longest_to_int (value_as_long (low
)),
1632 longest_to_int (value_as_long (high
)));
1633 elt_type
= create_array_type (array_type
, elt_type
, range_type
);
1636 return lookup_pointer_type (elt_type
);
1640 /* If ARR does not represent an array, returns ARR unchanged.
1641 Otherwise, returns either a standard GDB array with bounds set
1642 appropriately or, if ARR is a non-null fat pointer, a pointer to a standard
1643 GDB array. Returns NULL if ARR is a null fat pointer. */
1646 ada_coerce_to_simple_array_ptr (struct value
*arr
)
1648 if (ada_is_array_descriptor_type (value_type (arr
)))
1650 struct type
*arrType
= ada_type_of_array (arr
, 1);
1651 if (arrType
== NULL
)
1653 return value_cast (arrType
, value_copy (desc_data (arr
)));
1655 else if (ada_is_packed_array_type (value_type (arr
)))
1656 return decode_packed_array (arr
);
1661 /* If ARR does not represent an array, returns ARR unchanged.
1662 Otherwise, returns a standard GDB array describing ARR (which may
1663 be ARR itself if it already is in the proper form). */
1665 static struct value
*
1666 ada_coerce_to_simple_array (struct value
*arr
)
1668 if (ada_is_array_descriptor_type (value_type (arr
)))
1670 struct value
*arrVal
= ada_coerce_to_simple_array_ptr (arr
);
1672 error (_("Bounds unavailable for null array pointer."));
1673 check_size (TYPE_TARGET_TYPE (value_type (arrVal
)));
1674 return value_ind (arrVal
);
1676 else if (ada_is_packed_array_type (value_type (arr
)))
1677 return decode_packed_array (arr
);
1682 /* If TYPE represents a GNAT array type, return it translated to an
1683 ordinary GDB array type (possibly with BITSIZE fields indicating
1684 packing). For other types, is the identity. */
1687 ada_coerce_to_simple_array_type (struct type
*type
)
1689 struct value
*mark
= value_mark ();
1690 struct value
*dummy
= value_from_longest (builtin_type_int32
, 0);
1691 struct type
*result
;
1692 deprecated_set_value_type (dummy
, type
);
1693 result
= ada_type_of_array (dummy
, 0);
1694 value_free_to_mark (mark
);
1698 /* Non-zero iff TYPE represents a standard GNAT packed-array type. */
1701 ada_is_packed_array_type (struct type
*type
)
1705 type
= desc_base_type (type
);
1706 type
= ada_check_typedef (type
);
1708 ada_type_name (type
) != NULL
1709 && strstr (ada_type_name (type
), "___XP") != NULL
;
1712 /* Given that TYPE is a standard GDB array type with all bounds filled
1713 in, and that the element size of its ultimate scalar constituents
1714 (that is, either its elements, or, if it is an array of arrays, its
1715 elements' elements, etc.) is *ELT_BITS, return an identical type,
1716 but with the bit sizes of its elements (and those of any
1717 constituent arrays) recorded in the BITSIZE components of its
1718 TYPE_FIELD_BITSIZE values, and with *ELT_BITS set to its total size
1721 static struct type
*
1722 packed_array_type (struct type
*type
, long *elt_bits
)
1724 struct type
*new_elt_type
;
1725 struct type
*new_type
;
1726 LONGEST low_bound
, high_bound
;
1728 type
= ada_check_typedef (type
);
1729 if (TYPE_CODE (type
) != TYPE_CODE_ARRAY
)
1732 new_type
= alloc_type (TYPE_OBJFILE (type
));
1733 new_elt_type
= packed_array_type (ada_check_typedef (TYPE_TARGET_TYPE (type
)),
1735 create_array_type (new_type
, new_elt_type
, TYPE_INDEX_TYPE (type
));
1736 TYPE_FIELD_BITSIZE (new_type
, 0) = *elt_bits
;
1737 TYPE_NAME (new_type
) = ada_type_name (type
);
1739 if (get_discrete_bounds (TYPE_INDEX_TYPE (type
),
1740 &low_bound
, &high_bound
) < 0)
1741 low_bound
= high_bound
= 0;
1742 if (high_bound
< low_bound
)
1743 *elt_bits
= TYPE_LENGTH (new_type
) = 0;
1746 *elt_bits
*= (high_bound
- low_bound
+ 1);
1747 TYPE_LENGTH (new_type
) =
1748 (*elt_bits
+ HOST_CHAR_BIT
- 1) / HOST_CHAR_BIT
;
1751 TYPE_FIXED_INSTANCE (new_type
) = 1;
1755 /* The array type encoded by TYPE, where ada_is_packed_array_type (TYPE). */
1757 static struct type
*
1758 decode_packed_array_type (struct type
*type
)
1761 struct block
**blocks
;
1762 char *raw_name
= ada_type_name (ada_check_typedef (type
));
1765 struct type
*shadow_type
;
1770 raw_name
= ada_type_name (desc_base_type (type
));
1775 name
= (char *) alloca (strlen (raw_name
) + 1);
1776 tail
= strstr (raw_name
, "___XP");
1777 type
= desc_base_type (type
);
1779 memcpy (name
, raw_name
, tail
- raw_name
);
1780 name
[tail
- raw_name
] = '\000';
1782 sym
= standard_lookup (name
, get_selected_block (0), VAR_DOMAIN
);
1783 if (sym
== NULL
|| SYMBOL_TYPE (sym
) == NULL
)
1785 lim_warning (_("could not find bounds information on packed array"));
1788 shadow_type
= SYMBOL_TYPE (sym
);
1789 CHECK_TYPEDEF (shadow_type
);
1791 if (TYPE_CODE (shadow_type
) != TYPE_CODE_ARRAY
)
1793 lim_warning (_("could not understand bounds information on packed array"));
1797 if (sscanf (tail
+ sizeof ("___XP") - 1, "%ld", &bits
) != 1)
1800 (_("could not understand bit size information on packed array"));
1804 return packed_array_type (shadow_type
, &bits
);
1807 /* Given that ARR is a struct value *indicating a GNAT packed array,
1808 returns a simple array that denotes that array. Its type is a
1809 standard GDB array type except that the BITSIZEs of the array
1810 target types are set to the number of bits in each element, and the
1811 type length is set appropriately. */
1813 static struct value
*
1814 decode_packed_array (struct value
*arr
)
1818 arr
= ada_coerce_ref (arr
);
1819 if (TYPE_CODE (value_type (arr
)) == TYPE_CODE_PTR
)
1820 arr
= ada_value_ind (arr
);
1822 type
= decode_packed_array_type (value_type (arr
));
1825 error (_("can't unpack array"));
1829 if (gdbarch_bits_big_endian (current_gdbarch
)
1830 && ada_is_modular_type (value_type (arr
)))
1832 /* This is a (right-justified) modular type representing a packed
1833 array with no wrapper. In order to interpret the value through
1834 the (left-justified) packed array type we just built, we must
1835 first left-justify it. */
1836 int bit_size
, bit_pos
;
1839 mod
= ada_modulus (value_type (arr
)) - 1;
1846 bit_pos
= HOST_CHAR_BIT
* TYPE_LENGTH (value_type (arr
)) - bit_size
;
1847 arr
= ada_value_primitive_packed_val (arr
, NULL
,
1848 bit_pos
/ HOST_CHAR_BIT
,
1849 bit_pos
% HOST_CHAR_BIT
,
1854 return coerce_unspec_val_to_type (arr
, type
);
1858 /* The value of the element of packed array ARR at the ARITY indices
1859 given in IND. ARR must be a simple array. */
1861 static struct value
*
1862 value_subscript_packed (struct value
*arr
, int arity
, struct value
**ind
)
1865 int bits
, elt_off
, bit_off
;
1866 long elt_total_bit_offset
;
1867 struct type
*elt_type
;
1871 elt_total_bit_offset
= 0;
1872 elt_type
= ada_check_typedef (value_type (arr
));
1873 for (i
= 0; i
< arity
; i
+= 1)
1875 if (TYPE_CODE (elt_type
) != TYPE_CODE_ARRAY
1876 || TYPE_FIELD_BITSIZE (elt_type
, 0) == 0)
1878 (_("attempt to do packed indexing of something other than a packed array"));
1881 struct type
*range_type
= TYPE_INDEX_TYPE (elt_type
);
1882 LONGEST lowerbound
, upperbound
;
1885 if (get_discrete_bounds (range_type
, &lowerbound
, &upperbound
) < 0)
1887 lim_warning (_("don't know bounds of array"));
1888 lowerbound
= upperbound
= 0;
1891 idx
= pos_atr (ind
[i
]);
1892 if (idx
< lowerbound
|| idx
> upperbound
)
1893 lim_warning (_("packed array index %ld out of bounds"), (long) idx
);
1894 bits
= TYPE_FIELD_BITSIZE (elt_type
, 0);
1895 elt_total_bit_offset
+= (idx
- lowerbound
) * bits
;
1896 elt_type
= ada_check_typedef (TYPE_TARGET_TYPE (elt_type
));
1899 elt_off
= elt_total_bit_offset
/ HOST_CHAR_BIT
;
1900 bit_off
= elt_total_bit_offset
% HOST_CHAR_BIT
;
1902 v
= ada_value_primitive_packed_val (arr
, NULL
, elt_off
, bit_off
,
1907 /* Non-zero iff TYPE includes negative integer values. */
1910 has_negatives (struct type
*type
)
1912 switch (TYPE_CODE (type
))
1917 return !TYPE_UNSIGNED (type
);
1918 case TYPE_CODE_RANGE
:
1919 return TYPE_LOW_BOUND (type
) < 0;
1924 /* Create a new value of type TYPE from the contents of OBJ starting
1925 at byte OFFSET, and bit offset BIT_OFFSET within that byte,
1926 proceeding for BIT_SIZE bits. If OBJ is an lval in memory, then
1927 assigning through the result will set the field fetched from.
1928 VALADDR is ignored unless OBJ is NULL, in which case,
1929 VALADDR+OFFSET must address the start of storage containing the
1930 packed value. The value returned in this case is never an lval.
1931 Assumes 0 <= BIT_OFFSET < HOST_CHAR_BIT. */
1934 ada_value_primitive_packed_val (struct value
*obj
, const gdb_byte
*valaddr
,
1935 long offset
, int bit_offset
, int bit_size
,
1939 int src
, /* Index into the source area */
1940 targ
, /* Index into the target area */
1941 srcBitsLeft
, /* Number of source bits left to move */
1942 nsrc
, ntarg
, /* Number of source and target bytes */
1943 unusedLS
, /* Number of bits in next significant
1944 byte of source that are unused */
1945 accumSize
; /* Number of meaningful bits in accum */
1946 unsigned char *bytes
; /* First byte containing data to unpack */
1947 unsigned char *unpacked
;
1948 unsigned long accum
; /* Staging area for bits being transferred */
1950 int len
= (bit_size
+ bit_offset
+ HOST_CHAR_BIT
- 1) / 8;
1951 /* Transmit bytes from least to most significant; delta is the direction
1952 the indices move. */
1953 int delta
= gdbarch_bits_big_endian (current_gdbarch
) ? -1 : 1;
1955 type
= ada_check_typedef (type
);
1959 v
= allocate_value (type
);
1960 bytes
= (unsigned char *) (valaddr
+ offset
);
1962 else if (VALUE_LVAL (obj
) == lval_memory
&& value_lazy (obj
))
1965 VALUE_ADDRESS (obj
) + value_offset (obj
) + offset
);
1966 bytes
= (unsigned char *) alloca (len
);
1967 read_memory (VALUE_ADDRESS (v
), bytes
, len
);
1971 v
= allocate_value (type
);
1972 bytes
= (unsigned char *) value_contents (obj
) + offset
;
1977 set_value_component_location (v
, obj
);
1978 VALUE_ADDRESS (v
) += value_offset (obj
) + offset
;
1979 set_value_bitpos (v
, bit_offset
+ value_bitpos (obj
));
1980 set_value_bitsize (v
, bit_size
);
1981 if (value_bitpos (v
) >= HOST_CHAR_BIT
)
1983 VALUE_ADDRESS (v
) += 1;
1984 set_value_bitpos (v
, value_bitpos (v
) - HOST_CHAR_BIT
);
1988 set_value_bitsize (v
, bit_size
);
1989 unpacked
= (unsigned char *) value_contents (v
);
1991 srcBitsLeft
= bit_size
;
1993 ntarg
= TYPE_LENGTH (type
);
1997 memset (unpacked
, 0, TYPE_LENGTH (type
));
2000 else if (gdbarch_bits_big_endian (current_gdbarch
))
2003 if (has_negatives (type
)
2004 && ((bytes
[0] << bit_offset
) & (1 << (HOST_CHAR_BIT
- 1))))
2008 (HOST_CHAR_BIT
- (bit_size
+ bit_offset
) % HOST_CHAR_BIT
)
2011 switch (TYPE_CODE (type
))
2013 case TYPE_CODE_ARRAY
:
2014 case TYPE_CODE_UNION
:
2015 case TYPE_CODE_STRUCT
:
2016 /* Non-scalar values must be aligned at a byte boundary... */
2018 (HOST_CHAR_BIT
- bit_size
% HOST_CHAR_BIT
) % HOST_CHAR_BIT
;
2019 /* ... And are placed at the beginning (most-significant) bytes
2021 targ
= (bit_size
+ HOST_CHAR_BIT
- 1) / HOST_CHAR_BIT
- 1;
2026 targ
= TYPE_LENGTH (type
) - 1;
2032 int sign_bit_offset
= (bit_size
+ bit_offset
- 1) % 8;
2035 unusedLS
= bit_offset
;
2038 if (has_negatives (type
) && (bytes
[len
- 1] & (1 << sign_bit_offset
)))
2045 /* Mask for removing bits of the next source byte that are not
2046 part of the value. */
2047 unsigned int unusedMSMask
=
2048 (1 << (srcBitsLeft
>= HOST_CHAR_BIT
? HOST_CHAR_BIT
: srcBitsLeft
)) -
2050 /* Sign-extend bits for this byte. */
2051 unsigned int signMask
= sign
& ~unusedMSMask
;
2053 (((bytes
[src
] >> unusedLS
) & unusedMSMask
) | signMask
) << accumSize
;
2054 accumSize
+= HOST_CHAR_BIT
- unusedLS
;
2055 if (accumSize
>= HOST_CHAR_BIT
)
2057 unpacked
[targ
] = accum
& ~(~0L << HOST_CHAR_BIT
);
2058 accumSize
-= HOST_CHAR_BIT
;
2059 accum
>>= HOST_CHAR_BIT
;
2063 srcBitsLeft
-= HOST_CHAR_BIT
- unusedLS
;
2070 accum
|= sign
<< accumSize
;
2071 unpacked
[targ
] = accum
& ~(~0L << HOST_CHAR_BIT
);
2072 accumSize
-= HOST_CHAR_BIT
;
2073 accum
>>= HOST_CHAR_BIT
;
2081 /* Move N bits from SOURCE, starting at bit offset SRC_OFFSET to
2082 TARGET, starting at bit offset TARG_OFFSET. SOURCE and TARGET must
2085 move_bits (gdb_byte
*target
, int targ_offset
, const gdb_byte
*source
,
2086 int src_offset
, int n
)
2088 unsigned int accum
, mask
;
2089 int accum_bits
, chunk_size
;
2091 target
+= targ_offset
/ HOST_CHAR_BIT
;
2092 targ_offset
%= HOST_CHAR_BIT
;
2093 source
+= src_offset
/ HOST_CHAR_BIT
;
2094 src_offset
%= HOST_CHAR_BIT
;
2095 if (gdbarch_bits_big_endian (current_gdbarch
))
2097 accum
= (unsigned char) *source
;
2099 accum_bits
= HOST_CHAR_BIT
- src_offset
;
2104 accum
= (accum
<< HOST_CHAR_BIT
) + (unsigned char) *source
;
2105 accum_bits
+= HOST_CHAR_BIT
;
2107 chunk_size
= HOST_CHAR_BIT
- targ_offset
;
2110 unused_right
= HOST_CHAR_BIT
- (chunk_size
+ targ_offset
);
2111 mask
= ((1 << chunk_size
) - 1) << unused_right
;
2114 | ((accum
>> (accum_bits
- chunk_size
- unused_right
)) & mask
);
2116 accum_bits
-= chunk_size
;
2123 accum
= (unsigned char) *source
>> src_offset
;
2125 accum_bits
= HOST_CHAR_BIT
- src_offset
;
2129 accum
= accum
+ ((unsigned char) *source
<< accum_bits
);
2130 accum_bits
+= HOST_CHAR_BIT
;
2132 chunk_size
= HOST_CHAR_BIT
- targ_offset
;
2135 mask
= ((1 << chunk_size
) - 1) << targ_offset
;
2136 *target
= (*target
& ~mask
) | ((accum
<< targ_offset
) & mask
);
2138 accum_bits
-= chunk_size
;
2139 accum
>>= chunk_size
;
2146 /* Store the contents of FROMVAL into the location of TOVAL.
2147 Return a new value with the location of TOVAL and contents of
2148 FROMVAL. Handles assignment into packed fields that have
2149 floating-point or non-scalar types. */
2151 static struct value
*
2152 ada_value_assign (struct value
*toval
, struct value
*fromval
)
2154 struct type
*type
= value_type (toval
);
2155 int bits
= value_bitsize (toval
);
2157 toval
= ada_coerce_ref (toval
);
2158 fromval
= ada_coerce_ref (fromval
);
2160 if (ada_is_direct_array_type (value_type (toval
)))
2161 toval
= ada_coerce_to_simple_array (toval
);
2162 if (ada_is_direct_array_type (value_type (fromval
)))
2163 fromval
= ada_coerce_to_simple_array (fromval
);
2165 if (!deprecated_value_modifiable (toval
))
2166 error (_("Left operand of assignment is not a modifiable lvalue."));
2168 if (VALUE_LVAL (toval
) == lval_memory
2170 && (TYPE_CODE (type
) == TYPE_CODE_FLT
2171 || TYPE_CODE (type
) == TYPE_CODE_STRUCT
))
2173 int len
= (value_bitpos (toval
)
2174 + bits
+ HOST_CHAR_BIT
- 1) / HOST_CHAR_BIT
;
2176 char *buffer
= (char *) alloca (len
);
2178 CORE_ADDR to_addr
= VALUE_ADDRESS (toval
) + value_offset (toval
);
2180 if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
2181 fromval
= value_cast (type
, fromval
);
2183 read_memory (to_addr
, buffer
, len
);
2184 from_size
= value_bitsize (fromval
);
2186 from_size
= TYPE_LENGTH (value_type (fromval
)) * TARGET_CHAR_BIT
;
2187 if (gdbarch_bits_big_endian (current_gdbarch
))
2188 move_bits (buffer
, value_bitpos (toval
),
2189 value_contents (fromval
), from_size
- bits
, bits
);
2191 move_bits (buffer
, value_bitpos (toval
), value_contents (fromval
),
2193 write_memory (to_addr
, buffer
, len
);
2194 if (deprecated_memory_changed_hook
)
2195 deprecated_memory_changed_hook (to_addr
, len
);
2197 val
= value_copy (toval
);
2198 memcpy (value_contents_raw (val
), value_contents (fromval
),
2199 TYPE_LENGTH (type
));
2200 deprecated_set_value_type (val
, type
);
2205 return value_assign (toval
, fromval
);
2209 /* Given that COMPONENT is a memory lvalue that is part of the lvalue
2210 * CONTAINER, assign the contents of VAL to COMPONENTS's place in
2211 * CONTAINER. Modifies the VALUE_CONTENTS of CONTAINER only, not
2212 * COMPONENT, and not the inferior's memory. The current contents
2213 * of COMPONENT are ignored. */
2215 value_assign_to_component (struct value
*container
, struct value
*component
,
2218 LONGEST offset_in_container
=
2219 (LONGEST
) (VALUE_ADDRESS (component
) + value_offset (component
)
2220 - VALUE_ADDRESS (container
) - value_offset (container
));
2221 int bit_offset_in_container
=
2222 value_bitpos (component
) - value_bitpos (container
);
2225 val
= value_cast (value_type (component
), val
);
2227 if (value_bitsize (component
) == 0)
2228 bits
= TARGET_CHAR_BIT
* TYPE_LENGTH (value_type (component
));
2230 bits
= value_bitsize (component
);
2232 if (gdbarch_bits_big_endian (current_gdbarch
))
2233 move_bits (value_contents_writeable (container
) + offset_in_container
,
2234 value_bitpos (container
) + bit_offset_in_container
,
2235 value_contents (val
),
2236 TYPE_LENGTH (value_type (component
)) * TARGET_CHAR_BIT
- bits
,
2239 move_bits (value_contents_writeable (container
) + offset_in_container
,
2240 value_bitpos (container
) + bit_offset_in_container
,
2241 value_contents (val
), 0, bits
);
2244 /* The value of the element of array ARR at the ARITY indices given in IND.
2245 ARR may be either a simple array, GNAT array descriptor, or pointer
2249 ada_value_subscript (struct value
*arr
, int arity
, struct value
**ind
)
2253 struct type
*elt_type
;
2255 elt
= ada_coerce_to_simple_array (arr
);
2257 elt_type
= ada_check_typedef (value_type (elt
));
2258 if (TYPE_CODE (elt_type
) == TYPE_CODE_ARRAY
2259 && TYPE_FIELD_BITSIZE (elt_type
, 0) > 0)
2260 return value_subscript_packed (elt
, arity
, ind
);
2262 for (k
= 0; k
< arity
; k
+= 1)
2264 if (TYPE_CODE (elt_type
) != TYPE_CODE_ARRAY
)
2265 error (_("too many subscripts (%d expected)"), k
);
2266 elt
= value_subscript (elt
, value_pos_atr (builtin_type_int32
, ind
[k
]));
2271 /* Assuming ARR is a pointer to a standard GDB array of type TYPE, the
2272 value of the element of *ARR at the ARITY indices given in
2273 IND. Does not read the entire array into memory. */
2275 static struct value
*
2276 ada_value_ptr_subscript (struct value
*arr
, struct type
*type
, int arity
,
2281 for (k
= 0; k
< arity
; k
+= 1)
2286 if (TYPE_CODE (type
) != TYPE_CODE_ARRAY
)
2287 error (_("too many subscripts (%d expected)"), k
);
2288 arr
= value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (type
)),
2290 get_discrete_bounds (TYPE_INDEX_TYPE (type
), &lwb
, &upb
);
2291 idx
= value_pos_atr (builtin_type_int32
, ind
[k
]);
2293 idx
= value_binop (idx
, value_from_longest (value_type (idx
), lwb
),
2296 arr
= value_ptradd (arr
, idx
);
2297 type
= TYPE_TARGET_TYPE (type
);
2300 return value_ind (arr
);
2303 /* Given that ARRAY_PTR is a pointer or reference to an array of type TYPE (the
2304 actual type of ARRAY_PTR is ignored), returns the Ada slice of HIGH-LOW+1
2305 elements starting at index LOW. The lower bound of this array is LOW, as
2307 static struct value
*
2308 ada_value_slice_from_ptr (struct value
*array_ptr
, struct type
*type
,
2311 CORE_ADDR base
= value_as_address (array_ptr
)
2312 + ((low
- TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type
)))
2313 * TYPE_LENGTH (TYPE_TARGET_TYPE (type
)));
2314 struct type
*index_type
=
2315 create_range_type (NULL
, TYPE_TARGET_TYPE (TYPE_INDEX_TYPE (type
)),
2317 struct type
*slice_type
=
2318 create_array_type (NULL
, TYPE_TARGET_TYPE (type
), index_type
);
2319 return value_at_lazy (slice_type
, base
);
2323 static struct value
*
2324 ada_value_slice (struct value
*array
, int low
, int high
)
2326 struct type
*type
= value_type (array
);
2327 struct type
*index_type
=
2328 create_range_type (NULL
, TYPE_INDEX_TYPE (type
), low
, high
);
2329 struct type
*slice_type
=
2330 create_array_type (NULL
, TYPE_TARGET_TYPE (type
), index_type
);
2331 return value_cast (slice_type
, value_slice (array
, low
, high
- low
+ 1));
2334 /* If type is a record type in the form of a standard GNAT array
2335 descriptor, returns the number of dimensions for type. If arr is a
2336 simple array, returns the number of "array of"s that prefix its
2337 type designation. Otherwise, returns 0. */
2340 ada_array_arity (struct type
*type
)
2347 type
= desc_base_type (type
);
2350 if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
)
2351 return desc_arity (desc_bounds_type (type
));
2353 while (TYPE_CODE (type
) == TYPE_CODE_ARRAY
)
2356 type
= ada_check_typedef (TYPE_TARGET_TYPE (type
));
2362 /* If TYPE is a record type in the form of a standard GNAT array
2363 descriptor or a simple array type, returns the element type for
2364 TYPE after indexing by NINDICES indices, or by all indices if
2365 NINDICES is -1. Otherwise, returns NULL. */
2368 ada_array_element_type (struct type
*type
, int nindices
)
2370 type
= desc_base_type (type
);
2372 if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
)
2375 struct type
*p_array_type
;
2377 p_array_type
= desc_data_type (type
);
2379 k
= ada_array_arity (type
);
2383 /* Initially p_array_type = elt_type(*)[]...(k times)...[]. */
2384 if (nindices
>= 0 && k
> nindices
)
2386 p_array_type
= TYPE_TARGET_TYPE (p_array_type
);
2387 while (k
> 0 && p_array_type
!= NULL
)
2389 p_array_type
= ada_check_typedef (TYPE_TARGET_TYPE (p_array_type
));
2392 return p_array_type
;
2394 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
)
2396 while (nindices
!= 0 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
)
2398 type
= TYPE_TARGET_TYPE (type
);
2407 /* The type of nth index in arrays of given type (n numbering from 1).
2408 Does not examine memory. */
2411 ada_index_type (struct type
*type
, int n
)
2413 struct type
*result_type
;
2415 type
= desc_base_type (type
);
2417 if (n
> ada_array_arity (type
))
2420 if (ada_is_simple_array_type (type
))
2424 for (i
= 1; i
< n
; i
+= 1)
2425 type
= TYPE_TARGET_TYPE (type
);
2426 result_type
= TYPE_TARGET_TYPE (TYPE_INDEX_TYPE (type
));
2427 /* FIXME: The stabs type r(0,0);bound;bound in an array type
2428 has a target type of TYPE_CODE_UNDEF. We compensate here, but
2429 perhaps stabsread.c would make more sense. */
2430 if (result_type
== NULL
|| TYPE_CODE (result_type
) == TYPE_CODE_UNDEF
)
2431 result_type
= builtin_type_int32
;
2436 return desc_index_type (desc_bounds_type (type
), n
);
2439 /* Given that arr is an array type, returns the lower bound of the
2440 Nth index (numbering from 1) if WHICH is 0, and the upper bound if
2441 WHICH is 1. This returns bounds 0 .. -1 if ARR_TYPE is an
2442 array-descriptor type. If TYPEP is non-null, *TYPEP is set to the
2443 bounds type. It works for other arrays with bounds supplied by
2444 run-time quantities other than discriminants. */
2447 ada_array_bound_from_type (struct type
* arr_type
, int n
, int which
,
2448 struct type
** typep
)
2450 struct type
*type
, *index_type_desc
, *index_type
;
2453 gdb_assert (which
== 0 || which
== 1);
2455 if (ada_is_packed_array_type (arr_type
))
2456 arr_type
= decode_packed_array_type (arr_type
);
2458 if (arr_type
== NULL
|| !ada_is_simple_array_type (arr_type
))
2461 *typep
= builtin_type_int32
;
2462 return (LONGEST
) - which
;
2465 if (TYPE_CODE (arr_type
) == TYPE_CODE_PTR
)
2466 type
= TYPE_TARGET_TYPE (arr_type
);
2470 index_type_desc
= ada_find_parallel_type (type
, "___XA");
2471 if (index_type_desc
!= NULL
)
2472 index_type
= to_fixed_range_type (TYPE_FIELD_NAME (index_type_desc
, n
- 1),
2473 NULL
, TYPE_OBJFILE (arr_type
));
2478 type
= TYPE_TARGET_TYPE (type
);
2482 index_type
= TYPE_INDEX_TYPE (type
);
2485 switch (TYPE_CODE (index_type
))
2487 case TYPE_CODE_RANGE
:
2488 retval
= which
== 0 ? TYPE_LOW_BOUND (index_type
)
2489 : TYPE_HIGH_BOUND (index_type
);
2491 case TYPE_CODE_ENUM
:
2492 retval
= which
== 0 ? TYPE_FIELD_BITPOS (index_type
, 0)
2493 : TYPE_FIELD_BITPOS (index_type
,
2494 TYPE_NFIELDS (index_type
) - 1);
2497 internal_error (__FILE__
, __LINE__
, _("invalid type code of index type"));
2501 *typep
= index_type
;
2506 /* Given that arr is an array value, returns the lower bound of the
2507 nth index (numbering from 1) if WHICH is 0, and the upper bound if
2508 WHICH is 1. This routine will also work for arrays with bounds
2509 supplied by run-time quantities other than discriminants. */
2512 ada_array_bound (struct value
*arr
, int n
, int which
)
2514 struct type
*arr_type
= value_type (arr
);
2516 if (ada_is_packed_array_type (arr_type
))
2517 return ada_array_bound (decode_packed_array (arr
), n
, which
);
2518 else if (ada_is_simple_array_type (arr_type
))
2521 LONGEST v
= ada_array_bound_from_type (arr_type
, n
, which
, &type
);
2522 return value_from_longest (type
, v
);
2525 return desc_one_bound (desc_bounds (arr
), n
, which
);
2528 /* Given that arr is an array value, returns the length of the
2529 nth index. This routine will also work for arrays with bounds
2530 supplied by run-time quantities other than discriminants.
2531 Does not work for arrays indexed by enumeration types with representation
2532 clauses at the moment. */
2534 static struct value
*
2535 ada_array_length (struct value
*arr
, int n
)
2537 struct type
*arr_type
= ada_check_typedef (value_type (arr
));
2539 if (ada_is_packed_array_type (arr_type
))
2540 return ada_array_length (decode_packed_array (arr
), n
);
2542 if (ada_is_simple_array_type (arr_type
))
2546 ada_array_bound_from_type (arr_type
, n
, 1, &type
) -
2547 ada_array_bound_from_type (arr_type
, n
, 0, NULL
) + 1;
2548 return value_from_longest (type
, v
);
2552 value_from_longest (builtin_type_int32
,
2553 value_as_long (desc_one_bound (desc_bounds (arr
),
2555 - value_as_long (desc_one_bound (desc_bounds (arr
),
2559 /* An empty array whose type is that of ARR_TYPE (an array type),
2560 with bounds LOW to LOW-1. */
2562 static struct value
*
2563 empty_array (struct type
*arr_type
, int low
)
2565 struct type
*index_type
=
2566 create_range_type (NULL
, TYPE_TARGET_TYPE (TYPE_INDEX_TYPE (arr_type
)),
2568 struct type
*elt_type
= ada_array_element_type (arr_type
, 1);
2569 return allocate_value (create_array_type (NULL
, elt_type
, index_type
));
2573 /* Name resolution */
2575 /* The "decoded" name for the user-definable Ada operator corresponding
2579 ada_decoded_op_name (enum exp_opcode op
)
2583 for (i
= 0; ada_opname_table
[i
].encoded
!= NULL
; i
+= 1)
2585 if (ada_opname_table
[i
].op
== op
)
2586 return ada_opname_table
[i
].decoded
;
2588 error (_("Could not find operator name for opcode"));
2592 /* Same as evaluate_type (*EXP), but resolves ambiguous symbol
2593 references (marked by OP_VAR_VALUE nodes in which the symbol has an
2594 undefined namespace) and converts operators that are
2595 user-defined into appropriate function calls. If CONTEXT_TYPE is
2596 non-null, it provides a preferred result type [at the moment, only
2597 type void has any effect---causing procedures to be preferred over
2598 functions in calls]. A null CONTEXT_TYPE indicates that a non-void
2599 return type is preferred. May change (expand) *EXP. */
2602 resolve (struct expression
**expp
, int void_context_p
)
2606 resolve_subexp (expp
, &pc
, 1, void_context_p
? builtin_type_void
: NULL
);
2609 /* Resolve the operator of the subexpression beginning at
2610 position *POS of *EXPP. "Resolving" consists of replacing
2611 the symbols that have undefined namespaces in OP_VAR_VALUE nodes
2612 with their resolutions, replacing built-in operators with
2613 function calls to user-defined operators, where appropriate, and,
2614 when DEPROCEDURE_P is non-zero, converting function-valued variables
2615 into parameterless calls. May expand *EXPP. The CONTEXT_TYPE functions
2616 are as in ada_resolve, above. */
2618 static struct value
*
2619 resolve_subexp (struct expression
**expp
, int *pos
, int deprocedure_p
,
2620 struct type
*context_type
)
2624 struct expression
*exp
; /* Convenience: == *expp. */
2625 enum exp_opcode op
= (*expp
)->elts
[pc
].opcode
;
2626 struct value
**argvec
; /* Vector of operand types (alloca'ed). */
2627 int nargs
; /* Number of operands. */
2634 /* Pass one: resolve operands, saving their types and updating *pos,
2639 if (exp
->elts
[pc
+ 3].opcode
== OP_VAR_VALUE
2640 && SYMBOL_DOMAIN (exp
->elts
[pc
+ 5].symbol
) == UNDEF_DOMAIN
)
2645 resolve_subexp (expp
, pos
, 0, NULL
);
2647 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
2652 resolve_subexp (expp
, pos
, 0, NULL
);
2657 resolve_subexp (expp
, pos
, 1, check_typedef (exp
->elts
[pc
+ 1].type
));
2660 case OP_ATR_MODULUS
:
2670 case TERNOP_IN_RANGE
:
2671 case BINOP_IN_BOUNDS
:
2677 case OP_DISCRETE_RANGE
:
2679 ada_forward_operator_length (exp
, pc
, &oplen
, &nargs
);
2688 arg1
= resolve_subexp (expp
, pos
, 0, NULL
);
2690 resolve_subexp (expp
, pos
, 1, NULL
);
2692 resolve_subexp (expp
, pos
, 1, value_type (arg1
));
2709 case BINOP_LOGICAL_AND
:
2710 case BINOP_LOGICAL_OR
:
2711 case BINOP_BITWISE_AND
:
2712 case BINOP_BITWISE_IOR
:
2713 case BINOP_BITWISE_XOR
:
2716 case BINOP_NOTEQUAL
:
2723 case BINOP_SUBSCRIPT
:
2731 case UNOP_LOGICAL_NOT
:
2747 case OP_INTERNALVAR
:
2757 *pos
+= 4 + BYTES_TO_EXP_ELEM (exp
->elts
[pc
+ 1].longconst
+ 1);
2760 case STRUCTOP_STRUCT
:
2761 *pos
+= 4 + BYTES_TO_EXP_ELEM (exp
->elts
[pc
+ 1].longconst
+ 1);
2774 error (_("Unexpected operator during name resolution"));
2777 argvec
= (struct value
* *) alloca (sizeof (struct value
*) * (nargs
+ 1));
2778 for (i
= 0; i
< nargs
; i
+= 1)
2779 argvec
[i
] = resolve_subexp (expp
, pos
, 1, NULL
);
2783 /* Pass two: perform any resolution on principal operator. */
2790 if (SYMBOL_DOMAIN (exp
->elts
[pc
+ 2].symbol
) == UNDEF_DOMAIN
)
2792 struct ada_symbol_info
*candidates
;
2796 ada_lookup_symbol_list (SYMBOL_LINKAGE_NAME
2797 (exp
->elts
[pc
+ 2].symbol
),
2798 exp
->elts
[pc
+ 1].block
, VAR_DOMAIN
,
2801 if (n_candidates
> 1)
2803 /* Types tend to get re-introduced locally, so if there
2804 are any local symbols that are not types, first filter
2807 for (j
= 0; j
< n_candidates
; j
+= 1)
2808 switch (SYMBOL_CLASS (candidates
[j
].sym
))
2813 case LOC_REGPARM_ADDR
:
2821 if (j
< n_candidates
)
2824 while (j
< n_candidates
)
2826 if (SYMBOL_CLASS (candidates
[j
].sym
) == LOC_TYPEDEF
)
2828 candidates
[j
] = candidates
[n_candidates
- 1];
2837 if (n_candidates
== 0)
2838 error (_("No definition found for %s"),
2839 SYMBOL_PRINT_NAME (exp
->elts
[pc
+ 2].symbol
));
2840 else if (n_candidates
== 1)
2842 else if (deprocedure_p
2843 && !is_nonfunction (candidates
, n_candidates
))
2845 i
= ada_resolve_function
2846 (candidates
, n_candidates
, NULL
, 0,
2847 SYMBOL_LINKAGE_NAME (exp
->elts
[pc
+ 2].symbol
),
2850 error (_("Could not find a match for %s"),
2851 SYMBOL_PRINT_NAME (exp
->elts
[pc
+ 2].symbol
));
2855 printf_filtered (_("Multiple matches for %s\n"),
2856 SYMBOL_PRINT_NAME (exp
->elts
[pc
+ 2].symbol
));
2857 user_select_syms (candidates
, n_candidates
, 1);
2861 exp
->elts
[pc
+ 1].block
= candidates
[i
].block
;
2862 exp
->elts
[pc
+ 2].symbol
= candidates
[i
].sym
;
2863 if (innermost_block
== NULL
2864 || contained_in (candidates
[i
].block
, innermost_block
))
2865 innermost_block
= candidates
[i
].block
;
2869 && (TYPE_CODE (SYMBOL_TYPE (exp
->elts
[pc
+ 2].symbol
))
2872 replace_operator_with_call (expp
, pc
, 0, 0,
2873 exp
->elts
[pc
+ 2].symbol
,
2874 exp
->elts
[pc
+ 1].block
);
2881 if (exp
->elts
[pc
+ 3].opcode
== OP_VAR_VALUE
2882 && SYMBOL_DOMAIN (exp
->elts
[pc
+ 5].symbol
) == UNDEF_DOMAIN
)
2884 struct ada_symbol_info
*candidates
;
2888 ada_lookup_symbol_list (SYMBOL_LINKAGE_NAME
2889 (exp
->elts
[pc
+ 5].symbol
),
2890 exp
->elts
[pc
+ 4].block
, VAR_DOMAIN
,
2892 if (n_candidates
== 1)
2896 i
= ada_resolve_function
2897 (candidates
, n_candidates
,
2899 SYMBOL_LINKAGE_NAME (exp
->elts
[pc
+ 5].symbol
),
2902 error (_("Could not find a match for %s"),
2903 SYMBOL_PRINT_NAME (exp
->elts
[pc
+ 5].symbol
));
2906 exp
->elts
[pc
+ 4].block
= candidates
[i
].block
;
2907 exp
->elts
[pc
+ 5].symbol
= candidates
[i
].sym
;
2908 if (innermost_block
== NULL
2909 || contained_in (candidates
[i
].block
, innermost_block
))
2910 innermost_block
= candidates
[i
].block
;
2921 case BINOP_BITWISE_AND
:
2922 case BINOP_BITWISE_IOR
:
2923 case BINOP_BITWISE_XOR
:
2925 case BINOP_NOTEQUAL
:
2933 case UNOP_LOGICAL_NOT
:
2935 if (possible_user_operator_p (op
, argvec
))
2937 struct ada_symbol_info
*candidates
;
2941 ada_lookup_symbol_list (ada_encode (ada_decoded_op_name (op
)),
2942 (struct block
*) NULL
, VAR_DOMAIN
,
2944 i
= ada_resolve_function (candidates
, n_candidates
, argvec
, nargs
,
2945 ada_decoded_op_name (op
), NULL
);
2949 replace_operator_with_call (expp
, pc
, nargs
, 1,
2950 candidates
[i
].sym
, candidates
[i
].block
);
2961 return evaluate_subexp_type (exp
, pos
);
2964 /* Return non-zero if formal type FTYPE matches actual type ATYPE. If
2965 MAY_DEREF is non-zero, the formal may be a pointer and the actual
2966 a non-pointer. A type of 'void' (which is never a valid expression type)
2967 by convention matches anything. */
2968 /* The term "match" here is rather loose. The match is heuristic and
2969 liberal. FIXME: TOO liberal, in fact. */
2972 ada_type_match (struct type
*ftype
, struct type
*atype
, int may_deref
)
2974 ftype
= ada_check_typedef (ftype
);
2975 atype
= ada_check_typedef (atype
);
2977 if (TYPE_CODE (ftype
) == TYPE_CODE_REF
)
2978 ftype
= TYPE_TARGET_TYPE (ftype
);
2979 if (TYPE_CODE (atype
) == TYPE_CODE_REF
)
2980 atype
= TYPE_TARGET_TYPE (atype
);
2982 if (TYPE_CODE (ftype
) == TYPE_CODE_VOID
2983 || TYPE_CODE (atype
) == TYPE_CODE_VOID
)
2986 switch (TYPE_CODE (ftype
))
2991 if (TYPE_CODE (atype
) == TYPE_CODE_PTR
)
2992 return ada_type_match (TYPE_TARGET_TYPE (ftype
),
2993 TYPE_TARGET_TYPE (atype
), 0);
2996 && ada_type_match (TYPE_TARGET_TYPE (ftype
), atype
, 0));
2998 case TYPE_CODE_ENUM
:
2999 case TYPE_CODE_RANGE
:
3000 switch (TYPE_CODE (atype
))
3003 case TYPE_CODE_ENUM
:
3004 case TYPE_CODE_RANGE
:
3010 case TYPE_CODE_ARRAY
:
3011 return (TYPE_CODE (atype
) == TYPE_CODE_ARRAY
3012 || ada_is_array_descriptor_type (atype
));
3014 case TYPE_CODE_STRUCT
:
3015 if (ada_is_array_descriptor_type (ftype
))
3016 return (TYPE_CODE (atype
) == TYPE_CODE_ARRAY
3017 || ada_is_array_descriptor_type (atype
));
3019 return (TYPE_CODE (atype
) == TYPE_CODE_STRUCT
3020 && !ada_is_array_descriptor_type (atype
));
3022 case TYPE_CODE_UNION
:
3024 return (TYPE_CODE (atype
) == TYPE_CODE (ftype
));
3028 /* Return non-zero if the formals of FUNC "sufficiently match" the
3029 vector of actual argument types ACTUALS of size N_ACTUALS. FUNC
3030 may also be an enumeral, in which case it is treated as a 0-
3031 argument function. */
3034 ada_args_match (struct symbol
*func
, struct value
**actuals
, int n_actuals
)
3037 struct type
*func_type
= SYMBOL_TYPE (func
);
3039 if (SYMBOL_CLASS (func
) == LOC_CONST
3040 && TYPE_CODE (func_type
) == TYPE_CODE_ENUM
)
3041 return (n_actuals
== 0);
3042 else if (func_type
== NULL
|| TYPE_CODE (func_type
) != TYPE_CODE_FUNC
)
3045 if (TYPE_NFIELDS (func_type
) != n_actuals
)
3048 for (i
= 0; i
< n_actuals
; i
+= 1)
3050 if (actuals
[i
] == NULL
)
3054 struct type
*ftype
= ada_check_typedef (TYPE_FIELD_TYPE (func_type
, i
));
3055 struct type
*atype
= ada_check_typedef (value_type (actuals
[i
]));
3057 if (!ada_type_match (ftype
, atype
, 1))
3064 /* False iff function type FUNC_TYPE definitely does not produce a value
3065 compatible with type CONTEXT_TYPE. Conservatively returns 1 if
3066 FUNC_TYPE is not a valid function type with a non-null return type
3067 or an enumerated type. A null CONTEXT_TYPE indicates any non-void type. */
3070 return_match (struct type
*func_type
, struct type
*context_type
)
3072 struct type
*return_type
;
3074 if (func_type
== NULL
)
3077 if (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
)
3078 return_type
= base_type (TYPE_TARGET_TYPE (func_type
));
3080 return_type
= base_type (func_type
);
3081 if (return_type
== NULL
)
3084 context_type
= base_type (context_type
);
3086 if (TYPE_CODE (return_type
) == TYPE_CODE_ENUM
)
3087 return context_type
== NULL
|| return_type
== context_type
;
3088 else if (context_type
== NULL
)
3089 return TYPE_CODE (return_type
) != TYPE_CODE_VOID
;
3091 return TYPE_CODE (return_type
) == TYPE_CODE (context_type
);
3095 /* Returns the index in SYMS[0..NSYMS-1] that contains the symbol for the
3096 function (if any) that matches the types of the NARGS arguments in
3097 ARGS. If CONTEXT_TYPE is non-null and there is at least one match
3098 that returns that type, then eliminate matches that don't. If
3099 CONTEXT_TYPE is void and there is at least one match that does not
3100 return void, eliminate all matches that do.
3102 Asks the user if there is more than one match remaining. Returns -1
3103 if there is no such symbol or none is selected. NAME is used
3104 solely for messages. May re-arrange and modify SYMS in
3105 the process; the index returned is for the modified vector. */
3108 ada_resolve_function (struct ada_symbol_info syms
[],
3109 int nsyms
, struct value
**args
, int nargs
,
3110 const char *name
, struct type
*context_type
)
3113 int m
; /* Number of hits */
3114 struct type
*fallback
;
3115 struct type
*return_type
;
3117 return_type
= context_type
;
3118 if (context_type
== NULL
)
3119 fallback
= builtin_type_void
;
3126 for (k
= 0; k
< nsyms
; k
+= 1)
3128 struct type
*type
= ada_check_typedef (SYMBOL_TYPE (syms
[k
].sym
));
3130 if (ada_args_match (syms
[k
].sym
, args
, nargs
)
3131 && return_match (type
, return_type
))
3137 if (m
> 0 || return_type
== fallback
)
3140 return_type
= fallback
;
3147 printf_filtered (_("Multiple matches for %s\n"), name
);
3148 user_select_syms (syms
, m
, 1);
3154 /* Returns true (non-zero) iff decoded name N0 should appear before N1
3155 in a listing of choices during disambiguation (see sort_choices, below).
3156 The idea is that overloadings of a subprogram name from the
3157 same package should sort in their source order. We settle for ordering
3158 such symbols by their trailing number (__N or $N). */
3161 encoded_ordered_before (char *N0
, char *N1
)
3165 else if (N0
== NULL
)
3170 for (k0
= strlen (N0
) - 1; k0
> 0 && isdigit (N0
[k0
]); k0
-= 1)
3172 for (k1
= strlen (N1
) - 1; k1
> 0 && isdigit (N1
[k1
]); k1
-= 1)
3174 if ((N0
[k0
] == '_' || N0
[k0
] == '$') && N0
[k0
+ 1] != '\000'
3175 && (N1
[k1
] == '_' || N1
[k1
] == '$') && N1
[k1
+ 1] != '\000')
3179 while (N0
[n0
] == '_' && n0
> 0 && N0
[n0
- 1] == '_')
3182 while (N1
[n1
] == '_' && n1
> 0 && N1
[n1
- 1] == '_')
3184 if (n0
== n1
&& strncmp (N0
, N1
, n0
) == 0)
3185 return (atoi (N0
+ k0
+ 1) < atoi (N1
+ k1
+ 1));
3187 return (strcmp (N0
, N1
) < 0);
3191 /* Sort SYMS[0..NSYMS-1] to put the choices in a canonical order by the
3195 sort_choices (struct ada_symbol_info syms
[], int nsyms
)
3198 for (i
= 1; i
< nsyms
; i
+= 1)
3200 struct ada_symbol_info sym
= syms
[i
];
3203 for (j
= i
- 1; j
>= 0; j
-= 1)
3205 if (encoded_ordered_before (SYMBOL_LINKAGE_NAME (syms
[j
].sym
),
3206 SYMBOL_LINKAGE_NAME (sym
.sym
)))
3208 syms
[j
+ 1] = syms
[j
];
3214 /* Given a list of NSYMS symbols in SYMS, select up to MAX_RESULTS>0
3215 by asking the user (if necessary), returning the number selected,
3216 and setting the first elements of SYMS items. Error if no symbols
3219 /* NOTE: Adapted from decode_line_2 in symtab.c, with which it ought
3220 to be re-integrated one of these days. */
3223 user_select_syms (struct ada_symbol_info
*syms
, int nsyms
, int max_results
)
3226 int *chosen
= (int *) alloca (sizeof (int) * nsyms
);
3228 int first_choice
= (max_results
== 1) ? 1 : 2;
3229 const char *select_mode
= multiple_symbols_select_mode ();
3231 if (max_results
< 1)
3232 error (_("Request to select 0 symbols!"));
3236 if (select_mode
== multiple_symbols_cancel
)
3238 canceled because the command is ambiguous\n\
3239 See set/show multiple-symbol."));
3241 /* If select_mode is "all", then return all possible symbols.
3242 Only do that if more than one symbol can be selected, of course.
3243 Otherwise, display the menu as usual. */
3244 if (select_mode
== multiple_symbols_all
&& max_results
> 1)
3247 printf_unfiltered (_("[0] cancel\n"));
3248 if (max_results
> 1)
3249 printf_unfiltered (_("[1] all\n"));
3251 sort_choices (syms
, nsyms
);
3253 for (i
= 0; i
< nsyms
; i
+= 1)
3255 if (syms
[i
].sym
== NULL
)
3258 if (SYMBOL_CLASS (syms
[i
].sym
) == LOC_BLOCK
)
3260 struct symtab_and_line sal
=
3261 find_function_start_sal (syms
[i
].sym
, 1);
3262 if (sal
.symtab
== NULL
)
3263 printf_unfiltered (_("[%d] %s at <no source file available>:%d\n"),
3265 SYMBOL_PRINT_NAME (syms
[i
].sym
),
3268 printf_unfiltered (_("[%d] %s at %s:%d\n"), i
+ first_choice
,
3269 SYMBOL_PRINT_NAME (syms
[i
].sym
),
3270 sal
.symtab
->filename
, sal
.line
);
3276 (SYMBOL_CLASS (syms
[i
].sym
) == LOC_CONST
3277 && SYMBOL_TYPE (syms
[i
].sym
) != NULL
3278 && TYPE_CODE (SYMBOL_TYPE (syms
[i
].sym
)) == TYPE_CODE_ENUM
);
3279 struct symtab
*symtab
= symtab_for_sym (syms
[i
].sym
);
3281 if (SYMBOL_LINE (syms
[i
].sym
) != 0 && symtab
!= NULL
)
3282 printf_unfiltered (_("[%d] %s at %s:%d\n"),
3284 SYMBOL_PRINT_NAME (syms
[i
].sym
),
3285 symtab
->filename
, SYMBOL_LINE (syms
[i
].sym
));
3286 else if (is_enumeral
3287 && TYPE_NAME (SYMBOL_TYPE (syms
[i
].sym
)) != NULL
)
3289 printf_unfiltered (("[%d] "), i
+ first_choice
);
3290 ada_print_type (SYMBOL_TYPE (syms
[i
].sym
), NULL
,
3292 printf_unfiltered (_("'(%s) (enumeral)\n"),
3293 SYMBOL_PRINT_NAME (syms
[i
].sym
));
3295 else if (symtab
!= NULL
)
3296 printf_unfiltered (is_enumeral
3297 ? _("[%d] %s in %s (enumeral)\n")
3298 : _("[%d] %s at %s:?\n"),
3300 SYMBOL_PRINT_NAME (syms
[i
].sym
),
3303 printf_unfiltered (is_enumeral
3304 ? _("[%d] %s (enumeral)\n")
3305 : _("[%d] %s at ?\n"),
3307 SYMBOL_PRINT_NAME (syms
[i
].sym
));
3311 n_chosen
= get_selections (chosen
, nsyms
, max_results
, max_results
> 1,
3314 for (i
= 0; i
< n_chosen
; i
+= 1)
3315 syms
[i
] = syms
[chosen
[i
]];
3320 /* Read and validate a set of numeric choices from the user in the
3321 range 0 .. N_CHOICES-1. Place the results in increasing
3322 order in CHOICES[0 .. N-1], and return N.
3324 The user types choices as a sequence of numbers on one line
3325 separated by blanks, encoding them as follows:
3327 + A choice of 0 means to cancel the selection, throwing an error.
3328 + If IS_ALL_CHOICE, a choice of 1 selects the entire set 0 .. N_CHOICES-1.
3329 + The user chooses k by typing k+IS_ALL_CHOICE+1.
3331 The user is not allowed to choose more than MAX_RESULTS values.
3333 ANNOTATION_SUFFIX, if present, is used to annotate the input
3334 prompts (for use with the -f switch). */
3337 get_selections (int *choices
, int n_choices
, int max_results
,
3338 int is_all_choice
, char *annotation_suffix
)
3343 int first_choice
= is_all_choice
? 2 : 1;
3345 prompt
= getenv ("PS2");
3349 args
= command_line_input (prompt
, 0, annotation_suffix
);
3352 error_no_arg (_("one or more choice numbers"));
3356 /* Set choices[0 .. n_chosen-1] to the users' choices in ascending
3357 order, as given in args. Choices are validated. */
3363 while (isspace (*args
))
3365 if (*args
== '\0' && n_chosen
== 0)
3366 error_no_arg (_("one or more choice numbers"));
3367 else if (*args
== '\0')
3370 choice
= strtol (args
, &args2
, 10);
3371 if (args
== args2
|| choice
< 0
3372 || choice
> n_choices
+ first_choice
- 1)
3373 error (_("Argument must be choice number"));
3377 error (_("cancelled"));
3379 if (choice
< first_choice
)
3381 n_chosen
= n_choices
;
3382 for (j
= 0; j
< n_choices
; j
+= 1)
3386 choice
-= first_choice
;
3388 for (j
= n_chosen
- 1; j
>= 0 && choice
< choices
[j
]; j
-= 1)
3392 if (j
< 0 || choice
!= choices
[j
])
3395 for (k
= n_chosen
- 1; k
> j
; k
-= 1)
3396 choices
[k
+ 1] = choices
[k
];
3397 choices
[j
+ 1] = choice
;
3402 if (n_chosen
> max_results
)
3403 error (_("Select no more than %d of the above"), max_results
);
3408 /* Replace the operator of length OPLEN at position PC in *EXPP with a call
3409 on the function identified by SYM and BLOCK, and taking NARGS
3410 arguments. Update *EXPP as needed to hold more space. */
3413 replace_operator_with_call (struct expression
**expp
, int pc
, int nargs
,
3414 int oplen
, struct symbol
*sym
,
3415 struct block
*block
)
3417 /* A new expression, with 6 more elements (3 for funcall, 4 for function
3418 symbol, -oplen for operator being replaced). */
3419 struct expression
*newexp
= (struct expression
*)
3420 xmalloc (sizeof (struct expression
)
3421 + EXP_ELEM_TO_BYTES ((*expp
)->nelts
+ 7 - oplen
));
3422 struct expression
*exp
= *expp
;
3424 newexp
->nelts
= exp
->nelts
+ 7 - oplen
;
3425 newexp
->language_defn
= exp
->language_defn
;
3426 memcpy (newexp
->elts
, exp
->elts
, EXP_ELEM_TO_BYTES (pc
));
3427 memcpy (newexp
->elts
+ pc
+ 7, exp
->elts
+ pc
+ oplen
,
3428 EXP_ELEM_TO_BYTES (exp
->nelts
- pc
- oplen
));
3430 newexp
->elts
[pc
].opcode
= newexp
->elts
[pc
+ 2].opcode
= OP_FUNCALL
;
3431 newexp
->elts
[pc
+ 1].longconst
= (LONGEST
) nargs
;
3433 newexp
->elts
[pc
+ 3].opcode
= newexp
->elts
[pc
+ 6].opcode
= OP_VAR_VALUE
;
3434 newexp
->elts
[pc
+ 4].block
= block
;
3435 newexp
->elts
[pc
+ 5].symbol
= sym
;
3441 /* Type-class predicates */
3443 /* True iff TYPE is numeric (i.e., an INT, RANGE (of numeric type),
3447 numeric_type_p (struct type
*type
)
3453 switch (TYPE_CODE (type
))
3458 case TYPE_CODE_RANGE
:
3459 return (type
== TYPE_TARGET_TYPE (type
)
3460 || numeric_type_p (TYPE_TARGET_TYPE (type
)));
3467 /* True iff TYPE is integral (an INT or RANGE of INTs). */
3470 integer_type_p (struct type
*type
)
3476 switch (TYPE_CODE (type
))
3480 case TYPE_CODE_RANGE
:
3481 return (type
== TYPE_TARGET_TYPE (type
)
3482 || integer_type_p (TYPE_TARGET_TYPE (type
)));
3489 /* True iff TYPE is scalar (INT, RANGE, FLOAT, ENUM). */
3492 scalar_type_p (struct type
*type
)
3498 switch (TYPE_CODE (type
))
3501 case TYPE_CODE_RANGE
:
3502 case TYPE_CODE_ENUM
:
3511 /* True iff TYPE is discrete (INT, RANGE, ENUM). */
3514 discrete_type_p (struct type
*type
)
3520 switch (TYPE_CODE (type
))
3523 case TYPE_CODE_RANGE
:
3524 case TYPE_CODE_ENUM
:
3532 /* Returns non-zero if OP with operands in the vector ARGS could be
3533 a user-defined function. Errs on the side of pre-defined operators
3534 (i.e., result 0). */
3537 possible_user_operator_p (enum exp_opcode op
, struct value
*args
[])
3539 struct type
*type0
=
3540 (args
[0] == NULL
) ? NULL
: ada_check_typedef (value_type (args
[0]));
3541 struct type
*type1
=
3542 (args
[1] == NULL
) ? NULL
: ada_check_typedef (value_type (args
[1]));
3556 return (!(numeric_type_p (type0
) && numeric_type_p (type1
)));
3560 case BINOP_BITWISE_AND
:
3561 case BINOP_BITWISE_IOR
:
3562 case BINOP_BITWISE_XOR
:
3563 return (!(integer_type_p (type0
) && integer_type_p (type1
)));
3566 case BINOP_NOTEQUAL
:
3571 return (!(scalar_type_p (type0
) && scalar_type_p (type1
)));
3574 return !ada_is_array_type (type0
) || !ada_is_array_type (type1
);
3577 return (!(numeric_type_p (type0
) && integer_type_p (type1
)));
3581 case UNOP_LOGICAL_NOT
:
3583 return (!numeric_type_p (type0
));
3592 1. In the following, we assume that a renaming type's name may
3593 have an ___XD suffix. It would be nice if this went away at some
3595 2. We handle both the (old) purely type-based representation of
3596 renamings and the (new) variable-based encoding. At some point,
3597 it is devoutly to be hoped that the former goes away
3598 (FIXME: hilfinger-2007-07-09).
3599 3. Subprogram renamings are not implemented, although the XRS
3600 suffix is recognized (FIXME: hilfinger-2007-07-09). */
3602 /* If SYM encodes a renaming,
3604 <renaming> renames <renamed entity>,
3606 sets *LEN to the length of the renamed entity's name,
3607 *RENAMED_ENTITY to that name (not null-terminated), and *RENAMING_EXPR to
3608 the string describing the subcomponent selected from the renamed
3609 entity. Returns ADA_NOT_RENAMING if SYM does not encode a renaming
3610 (in which case, the values of *RENAMED_ENTITY, *LEN, and *RENAMING_EXPR
3611 are undefined). Otherwise, returns a value indicating the category
3612 of entity renamed: an object (ADA_OBJECT_RENAMING), exception
3613 (ADA_EXCEPTION_RENAMING), package (ADA_PACKAGE_RENAMING), or
3614 subprogram (ADA_SUBPROGRAM_RENAMING). Does no allocation; the
3615 strings returned in *RENAMED_ENTITY and *RENAMING_EXPR should not be
3616 deallocated. The values of RENAMED_ENTITY, LEN, or RENAMING_EXPR
3617 may be NULL, in which case they are not assigned.
3619 [Currently, however, GCC does not generate subprogram renamings.] */
3621 enum ada_renaming_category
3622 ada_parse_renaming (struct symbol
*sym
,
3623 const char **renamed_entity
, int *len
,
3624 const char **renaming_expr
)
3626 enum ada_renaming_category kind
;
3631 return ADA_NOT_RENAMING
;
3632 switch (SYMBOL_CLASS (sym
))
3635 return ADA_NOT_RENAMING
;
3637 return parse_old_style_renaming (SYMBOL_TYPE (sym
),
3638 renamed_entity
, len
, renaming_expr
);
3642 case LOC_OPTIMIZED_OUT
:
3643 info
= strstr (SYMBOL_LINKAGE_NAME (sym
), "___XR");
3645 return ADA_NOT_RENAMING
;
3649 kind
= ADA_OBJECT_RENAMING
;
3653 kind
= ADA_EXCEPTION_RENAMING
;
3657 kind
= ADA_PACKAGE_RENAMING
;
3661 kind
= ADA_SUBPROGRAM_RENAMING
;
3665 return ADA_NOT_RENAMING
;
3669 if (renamed_entity
!= NULL
)
3670 *renamed_entity
= info
;
3671 suffix
= strstr (info
, "___XE");
3672 if (suffix
== NULL
|| suffix
== info
)
3673 return ADA_NOT_RENAMING
;
3675 *len
= strlen (info
) - strlen (suffix
);
3677 if (renaming_expr
!= NULL
)
3678 *renaming_expr
= suffix
;
3682 /* Assuming TYPE encodes a renaming according to the old encoding in
3683 exp_dbug.ads, returns details of that renaming in *RENAMED_ENTITY,
3684 *LEN, and *RENAMING_EXPR, as for ada_parse_renaming, above. Returns
3685 ADA_NOT_RENAMING otherwise. */
3686 static enum ada_renaming_category
3687 parse_old_style_renaming (struct type
*type
,
3688 const char **renamed_entity
, int *len
,
3689 const char **renaming_expr
)
3691 enum ada_renaming_category kind
;
3696 if (type
== NULL
|| TYPE_CODE (type
) != TYPE_CODE_ENUM
3697 || TYPE_NFIELDS (type
) != 1)
3698 return ADA_NOT_RENAMING
;
3700 name
= type_name_no_tag (type
);
3702 return ADA_NOT_RENAMING
;
3704 name
= strstr (name
, "___XR");
3706 return ADA_NOT_RENAMING
;
3711 kind
= ADA_OBJECT_RENAMING
;
3714 kind
= ADA_EXCEPTION_RENAMING
;
3717 kind
= ADA_PACKAGE_RENAMING
;
3720 kind
= ADA_SUBPROGRAM_RENAMING
;
3723 return ADA_NOT_RENAMING
;
3726 info
= TYPE_FIELD_NAME (type
, 0);
3728 return ADA_NOT_RENAMING
;
3729 if (renamed_entity
!= NULL
)
3730 *renamed_entity
= info
;
3731 suffix
= strstr (info
, "___XE");
3732 if (renaming_expr
!= NULL
)
3733 *renaming_expr
= suffix
+ 5;
3734 if (suffix
== NULL
|| suffix
== info
)
3735 return ADA_NOT_RENAMING
;
3737 *len
= suffix
- info
;
3743 /* Evaluation: Function Calls */
3745 /* Return an lvalue containing the value VAL. This is the identity on
3746 lvalues, and otherwise has the side-effect of pushing a copy of VAL
3747 on the stack, using and updating *SP as the stack pointer, and
3748 returning an lvalue whose VALUE_ADDRESS points to the copy. */
3750 static struct value
*
3751 ensure_lval (struct value
*val
, CORE_ADDR
*sp
)
3753 if (! VALUE_LVAL (val
))
3755 int len
= TYPE_LENGTH (ada_check_typedef (value_type (val
)));
3757 /* The following is taken from the structure-return code in
3758 call_function_by_hand. FIXME: Therefore, some refactoring seems
3760 if (gdbarch_inner_than (current_gdbarch
, 1, 2))
3762 /* Stack grows downward. Align SP and VALUE_ADDRESS (val) after
3763 reserving sufficient space. */
3765 if (gdbarch_frame_align_p (current_gdbarch
))
3766 *sp
= gdbarch_frame_align (current_gdbarch
, *sp
);
3767 VALUE_ADDRESS (val
) = *sp
;
3771 /* Stack grows upward. Align the frame, allocate space, and
3772 then again, re-align the frame. */
3773 if (gdbarch_frame_align_p (current_gdbarch
))
3774 *sp
= gdbarch_frame_align (current_gdbarch
, *sp
);
3775 VALUE_ADDRESS (val
) = *sp
;
3777 if (gdbarch_frame_align_p (current_gdbarch
))
3778 *sp
= gdbarch_frame_align (current_gdbarch
, *sp
);
3780 VALUE_LVAL (val
) = lval_memory
;
3782 write_memory (VALUE_ADDRESS (val
), value_contents_raw (val
), len
);
3788 /* Return the value ACTUAL, converted to be an appropriate value for a
3789 formal of type FORMAL_TYPE. Use *SP as a stack pointer for
3790 allocating any necessary descriptors (fat pointers), or copies of
3791 values not residing in memory, updating it as needed. */
3794 ada_convert_actual (struct value
*actual
, struct type
*formal_type0
,
3797 struct type
*actual_type
= ada_check_typedef (value_type (actual
));
3798 struct type
*formal_type
= ada_check_typedef (formal_type0
);
3799 struct type
*formal_target
=
3800 TYPE_CODE (formal_type
) == TYPE_CODE_PTR
3801 ? ada_check_typedef (TYPE_TARGET_TYPE (formal_type
)) : formal_type
;
3802 struct type
*actual_target
=
3803 TYPE_CODE (actual_type
) == TYPE_CODE_PTR
3804 ? ada_check_typedef (TYPE_TARGET_TYPE (actual_type
)) : actual_type
;
3806 if (ada_is_array_descriptor_type (formal_target
)
3807 && TYPE_CODE (actual_target
) == TYPE_CODE_ARRAY
)
3808 return make_array_descriptor (formal_type
, actual
, sp
);
3809 else if (TYPE_CODE (formal_type
) == TYPE_CODE_PTR
3810 || TYPE_CODE (formal_type
) == TYPE_CODE_REF
)
3812 struct value
*result
;
3813 if (TYPE_CODE (formal_target
) == TYPE_CODE_ARRAY
3814 && ada_is_array_descriptor_type (actual_target
))
3815 result
= desc_data (actual
);
3816 else if (TYPE_CODE (actual_type
) != TYPE_CODE_PTR
)
3818 if (VALUE_LVAL (actual
) != lval_memory
)
3821 actual_type
= ada_check_typedef (value_type (actual
));
3822 val
= allocate_value (actual_type
);
3823 memcpy ((char *) value_contents_raw (val
),
3824 (char *) value_contents (actual
),
3825 TYPE_LENGTH (actual_type
));
3826 actual
= ensure_lval (val
, sp
);
3828 result
= value_addr (actual
);
3832 return value_cast_pointers (formal_type
, result
);
3834 else if (TYPE_CODE (actual_type
) == TYPE_CODE_PTR
)
3835 return ada_value_ind (actual
);
3841 /* Push a descriptor of type TYPE for array value ARR on the stack at
3842 *SP, updating *SP to reflect the new descriptor. Return either
3843 an lvalue representing the new descriptor, or (if TYPE is a pointer-
3844 to-descriptor type rather than a descriptor type), a struct value *
3845 representing a pointer to this descriptor. */
3847 static struct value
*
3848 make_array_descriptor (struct type
*type
, struct value
*arr
, CORE_ADDR
*sp
)
3850 struct type
*bounds_type
= desc_bounds_type (type
);
3851 struct type
*desc_type
= desc_base_type (type
);
3852 struct value
*descriptor
= allocate_value (desc_type
);
3853 struct value
*bounds
= allocate_value (bounds_type
);
3856 for (i
= ada_array_arity (ada_check_typedef (value_type (arr
))); i
> 0; i
-= 1)
3858 modify_general_field (value_contents_writeable (bounds
),
3859 value_as_long (ada_array_bound (arr
, i
, 0)),
3860 desc_bound_bitpos (bounds_type
, i
, 0),
3861 desc_bound_bitsize (bounds_type
, i
, 0));
3862 modify_general_field (value_contents_writeable (bounds
),
3863 value_as_long (ada_array_bound (arr
, i
, 1)),
3864 desc_bound_bitpos (bounds_type
, i
, 1),
3865 desc_bound_bitsize (bounds_type
, i
, 1));
3868 bounds
= ensure_lval (bounds
, sp
);
3870 modify_general_field (value_contents_writeable (descriptor
),
3871 VALUE_ADDRESS (ensure_lval (arr
, sp
)),
3872 fat_pntr_data_bitpos (desc_type
),
3873 fat_pntr_data_bitsize (desc_type
));
3875 modify_general_field (value_contents_writeable (descriptor
),
3876 VALUE_ADDRESS (bounds
),
3877 fat_pntr_bounds_bitpos (desc_type
),
3878 fat_pntr_bounds_bitsize (desc_type
));
3880 descriptor
= ensure_lval (descriptor
, sp
);
3882 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
3883 return value_addr (descriptor
);
3888 /* Dummy definitions for an experimental caching module that is not
3889 * used in the public sources. */
3892 lookup_cached_symbol (const char *name
, domain_enum
namespace,
3893 struct symbol
**sym
, struct block
**block
)
3899 cache_symbol (const char *name
, domain_enum
namespace, struct symbol
*sym
,
3900 struct block
*block
)
3906 /* Return the result of a standard (literal, C-like) lookup of NAME in
3907 given DOMAIN, visible from lexical block BLOCK. */
3909 static struct symbol
*
3910 standard_lookup (const char *name
, const struct block
*block
,
3915 if (lookup_cached_symbol (name
, domain
, &sym
, NULL
))
3917 sym
= lookup_symbol_in_language (name
, block
, domain
, language_c
, 0);
3918 cache_symbol (name
, domain
, sym
, block_found
);
3923 /* Non-zero iff there is at least one non-function/non-enumeral symbol
3924 in the symbol fields of SYMS[0..N-1]. We treat enumerals as functions,
3925 since they contend in overloading in the same way. */
3927 is_nonfunction (struct ada_symbol_info syms
[], int n
)
3931 for (i
= 0; i
< n
; i
+= 1)
3932 if (TYPE_CODE (SYMBOL_TYPE (syms
[i
].sym
)) != TYPE_CODE_FUNC
3933 && (TYPE_CODE (SYMBOL_TYPE (syms
[i
].sym
)) != TYPE_CODE_ENUM
3934 || SYMBOL_CLASS (syms
[i
].sym
) != LOC_CONST
))
3940 /* If true (non-zero), then TYPE0 and TYPE1 represent equivalent
3941 struct types. Otherwise, they may not. */
3944 equiv_types (struct type
*type0
, struct type
*type1
)
3948 if (type0
== NULL
|| type1
== NULL
3949 || TYPE_CODE (type0
) != TYPE_CODE (type1
))
3951 if ((TYPE_CODE (type0
) == TYPE_CODE_STRUCT
3952 || TYPE_CODE (type0
) == TYPE_CODE_ENUM
)
3953 && ada_type_name (type0
) != NULL
&& ada_type_name (type1
) != NULL
3954 && strcmp (ada_type_name (type0
), ada_type_name (type1
)) == 0)
3960 /* True iff SYM0 represents the same entity as SYM1, or one that is
3961 no more defined than that of SYM1. */
3964 lesseq_defined_than (struct symbol
*sym0
, struct symbol
*sym1
)
3968 if (SYMBOL_DOMAIN (sym0
) != SYMBOL_DOMAIN (sym1
)
3969 || SYMBOL_CLASS (sym0
) != SYMBOL_CLASS (sym1
))
3972 switch (SYMBOL_CLASS (sym0
))
3978 struct type
*type0
= SYMBOL_TYPE (sym0
);
3979 struct type
*type1
= SYMBOL_TYPE (sym1
);
3980 char *name0
= SYMBOL_LINKAGE_NAME (sym0
);
3981 char *name1
= SYMBOL_LINKAGE_NAME (sym1
);
3982 int len0
= strlen (name0
);
3984 TYPE_CODE (type0
) == TYPE_CODE (type1
)
3985 && (equiv_types (type0
, type1
)
3986 || (len0
< strlen (name1
) && strncmp (name0
, name1
, len0
) == 0
3987 && strncmp (name1
+ len0
, "___XV", 5) == 0));
3990 return SYMBOL_VALUE (sym0
) == SYMBOL_VALUE (sym1
)
3991 && equiv_types (SYMBOL_TYPE (sym0
), SYMBOL_TYPE (sym1
));
3997 /* Append (SYM,BLOCK,SYMTAB) to the end of the array of struct ada_symbol_info
3998 records in OBSTACKP. Do nothing if SYM is a duplicate. */
4001 add_defn_to_vec (struct obstack
*obstackp
,
4003 struct block
*block
)
4007 struct ada_symbol_info
*prevDefns
= defns_collected (obstackp
, 0);
4009 /* Do not try to complete stub types, as the debugger is probably
4010 already scanning all symbols matching a certain name at the
4011 time when this function is called. Trying to replace the stub
4012 type by its associated full type will cause us to restart a scan
4013 which may lead to an infinite recursion. Instead, the client
4014 collecting the matching symbols will end up collecting several
4015 matches, with at least one of them complete. It can then filter
4016 out the stub ones if needed. */
4018 for (i
= num_defns_collected (obstackp
) - 1; i
>= 0; i
-= 1)
4020 if (lesseq_defined_than (sym
, prevDefns
[i
].sym
))
4022 else if (lesseq_defined_than (prevDefns
[i
].sym
, sym
))
4024 prevDefns
[i
].sym
= sym
;
4025 prevDefns
[i
].block
= block
;
4031 struct ada_symbol_info info
;
4035 obstack_grow (obstackp
, &info
, sizeof (struct ada_symbol_info
));
4039 /* Number of ada_symbol_info structures currently collected in
4040 current vector in *OBSTACKP. */
4043 num_defns_collected (struct obstack
*obstackp
)
4045 return obstack_object_size (obstackp
) / sizeof (struct ada_symbol_info
);
4048 /* Vector of ada_symbol_info structures currently collected in current
4049 vector in *OBSTACKP. If FINISH, close off the vector and return
4050 its final address. */
4052 static struct ada_symbol_info
*
4053 defns_collected (struct obstack
*obstackp
, int finish
)
4056 return obstack_finish (obstackp
);
4058 return (struct ada_symbol_info
*) obstack_base (obstackp
);
4061 /* Look, in partial_symtab PST, for symbol NAME in given namespace.
4062 Check the global symbols if GLOBAL, the static symbols if not.
4063 Do wild-card match if WILD. */
4065 static struct partial_symbol
*
4066 ada_lookup_partial_symbol (struct partial_symtab
*pst
, const char *name
,
4067 int global
, domain_enum
namespace, int wild
)
4069 struct partial_symbol
**start
;
4070 int name_len
= strlen (name
);
4071 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
4080 pst
->objfile
->global_psymbols
.list
+ pst
->globals_offset
:
4081 pst
->objfile
->static_psymbols
.list
+ pst
->statics_offset
);
4085 for (i
= 0; i
< length
; i
+= 1)
4087 struct partial_symbol
*psym
= start
[i
];
4089 if (symbol_matches_domain (SYMBOL_LANGUAGE (psym
),
4090 SYMBOL_DOMAIN (psym
), namespace)
4091 && wild_match (name
, name_len
, SYMBOL_LINKAGE_NAME (psym
)))
4105 int M
= (U
+ i
) >> 1;
4106 struct partial_symbol
*psym
= start
[M
];
4107 if (SYMBOL_LINKAGE_NAME (psym
)[0] < name
[0])
4109 else if (SYMBOL_LINKAGE_NAME (psym
)[0] > name
[0])
4111 else if (strcmp (SYMBOL_LINKAGE_NAME (psym
), name
) < 0)
4122 struct partial_symbol
*psym
= start
[i
];
4124 if (symbol_matches_domain (SYMBOL_LANGUAGE (psym
),
4125 SYMBOL_DOMAIN (psym
), namespace))
4127 int cmp
= strncmp (name
, SYMBOL_LINKAGE_NAME (psym
), name_len
);
4135 && is_name_suffix (SYMBOL_LINKAGE_NAME (psym
)
4149 int M
= (U
+ i
) >> 1;
4150 struct partial_symbol
*psym
= start
[M
];
4151 if (SYMBOL_LINKAGE_NAME (psym
)[0] < '_')
4153 else if (SYMBOL_LINKAGE_NAME (psym
)[0] > '_')
4155 else if (strcmp (SYMBOL_LINKAGE_NAME (psym
), "_ada_") < 0)
4166 struct partial_symbol
*psym
= start
[i
];
4168 if (symbol_matches_domain (SYMBOL_LANGUAGE (psym
),
4169 SYMBOL_DOMAIN (psym
), namespace))
4173 cmp
= (int) '_' - (int) SYMBOL_LINKAGE_NAME (psym
)[0];
4176 cmp
= strncmp ("_ada_", SYMBOL_LINKAGE_NAME (psym
), 5);
4178 cmp
= strncmp (name
, SYMBOL_LINKAGE_NAME (psym
) + 5,
4188 && is_name_suffix (SYMBOL_LINKAGE_NAME (psym
)
4198 /* Find a symbol table containing symbol SYM or NULL if none. */
4200 static struct symtab
*
4201 symtab_for_sym (struct symbol
*sym
)
4204 struct objfile
*objfile
;
4206 struct symbol
*tmp_sym
;
4207 struct dict_iterator iter
;
4210 ALL_PRIMARY_SYMTABS (objfile
, s
)
4212 switch (SYMBOL_CLASS (sym
))
4220 case LOC_CONST_BYTES
:
4221 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
);
4222 ALL_BLOCK_SYMBOLS (b
, iter
, tmp_sym
) if (sym
== tmp_sym
)
4224 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
);
4225 ALL_BLOCK_SYMBOLS (b
, iter
, tmp_sym
) if (sym
== tmp_sym
)
4231 switch (SYMBOL_CLASS (sym
))
4236 case LOC_REGPARM_ADDR
:
4240 for (j
= FIRST_LOCAL_BLOCK
;
4241 j
< BLOCKVECTOR_NBLOCKS (BLOCKVECTOR (s
)); j
+= 1)
4243 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), j
);
4244 ALL_BLOCK_SYMBOLS (b
, iter
, tmp_sym
) if (sym
== tmp_sym
)
4255 /* Return a minimal symbol matching NAME according to Ada decoding
4256 rules. Returns NULL if there is no such minimal symbol. Names
4257 prefixed with "standard__" are handled specially: "standard__" is
4258 first stripped off, and only static and global symbols are searched. */
4260 struct minimal_symbol
*
4261 ada_lookup_simple_minsym (const char *name
)
4263 struct objfile
*objfile
;
4264 struct minimal_symbol
*msymbol
;
4267 if (strncmp (name
, "standard__", sizeof ("standard__") - 1) == 0)
4269 name
+= sizeof ("standard__") - 1;
4273 wild_match
= (strstr (name
, "__") == NULL
);
4275 ALL_MSYMBOLS (objfile
, msymbol
)
4277 if (ada_match_name (SYMBOL_LINKAGE_NAME (msymbol
), name
, wild_match
)
4278 && MSYMBOL_TYPE (msymbol
) != mst_solib_trampoline
)
4285 /* For all subprograms that statically enclose the subprogram of the
4286 selected frame, add symbols matching identifier NAME in DOMAIN
4287 and their blocks to the list of data in OBSTACKP, as for
4288 ada_add_block_symbols (q.v.). If WILD, treat as NAME with a
4292 add_symbols_from_enclosing_procs (struct obstack
*obstackp
,
4293 const char *name
, domain_enum
namespace,
4298 /* True if TYPE is definitely an artificial type supplied to a symbol
4299 for which no debugging information was given in the symbol file. */
4302 is_nondebugging_type (struct type
*type
)
4304 char *name
= ada_type_name (type
);
4305 return (name
!= NULL
&& strcmp (name
, "<variable, no debug info>") == 0);
4308 /* Remove any non-debugging symbols in SYMS[0 .. NSYMS-1] that definitely
4309 duplicate other symbols in the list (The only case I know of where
4310 this happens is when object files containing stabs-in-ecoff are
4311 linked with files containing ordinary ecoff debugging symbols (or no
4312 debugging symbols)). Modifies SYMS to squeeze out deleted entries.
4313 Returns the number of items in the modified list. */
4316 remove_extra_symbols (struct ada_symbol_info
*syms
, int nsyms
)
4325 /* If two symbols have the same name and one of them is a stub type,
4326 the get rid of the stub. */
4328 if (TYPE_STUB (SYMBOL_TYPE (syms
[i
].sym
))
4329 && SYMBOL_LINKAGE_NAME (syms
[i
].sym
) != NULL
)
4331 for (j
= 0; j
< nsyms
; j
++)
4334 && !TYPE_STUB (SYMBOL_TYPE (syms
[j
].sym
))
4335 && SYMBOL_LINKAGE_NAME (syms
[j
].sym
) != NULL
4336 && strcmp (SYMBOL_LINKAGE_NAME (syms
[i
].sym
),
4337 SYMBOL_LINKAGE_NAME (syms
[j
].sym
)) == 0)
4342 /* Two symbols with the same name, same class and same address
4343 should be identical. */
4345 else if (SYMBOL_LINKAGE_NAME (syms
[i
].sym
) != NULL
4346 && SYMBOL_CLASS (syms
[i
].sym
) == LOC_STATIC
4347 && is_nondebugging_type (SYMBOL_TYPE (syms
[i
].sym
)))
4349 for (j
= 0; j
< nsyms
; j
+= 1)
4352 && SYMBOL_LINKAGE_NAME (syms
[j
].sym
) != NULL
4353 && strcmp (SYMBOL_LINKAGE_NAME (syms
[i
].sym
),
4354 SYMBOL_LINKAGE_NAME (syms
[j
].sym
)) == 0
4355 && SYMBOL_CLASS (syms
[i
].sym
) == SYMBOL_CLASS (syms
[j
].sym
)
4356 && SYMBOL_VALUE_ADDRESS (syms
[i
].sym
)
4357 == SYMBOL_VALUE_ADDRESS (syms
[j
].sym
))
4364 for (j
= i
+ 1; j
< nsyms
; j
+= 1)
4365 syms
[j
- 1] = syms
[j
];
4374 /* Given a type that corresponds to a renaming entity, use the type name
4375 to extract the scope (package name or function name, fully qualified,
4376 and following the GNAT encoding convention) where this renaming has been
4377 defined. The string returned needs to be deallocated after use. */
4380 xget_renaming_scope (struct type
*renaming_type
)
4382 /* The renaming types adhere to the following convention:
4383 <scope>__<rename>___<XR extension>.
4384 So, to extract the scope, we search for the "___XR" extension,
4385 and then backtrack until we find the first "__". */
4387 const char *name
= type_name_no_tag (renaming_type
);
4388 char *suffix
= strstr (name
, "___XR");
4393 /* Now, backtrack a bit until we find the first "__". Start looking
4394 at suffix - 3, as the <rename> part is at least one character long. */
4396 for (last
= suffix
- 3; last
> name
; last
--)
4397 if (last
[0] == '_' && last
[1] == '_')
4400 /* Make a copy of scope and return it. */
4402 scope_len
= last
- name
;
4403 scope
= (char *) xmalloc ((scope_len
+ 1) * sizeof (char));
4405 strncpy (scope
, name
, scope_len
);
4406 scope
[scope_len
] = '\0';
4411 /* Return nonzero if NAME corresponds to a package name. */
4414 is_package_name (const char *name
)
4416 /* Here, We take advantage of the fact that no symbols are generated
4417 for packages, while symbols are generated for each function.
4418 So the condition for NAME represent a package becomes equivalent
4419 to NAME not existing in our list of symbols. There is only one
4420 small complication with library-level functions (see below). */
4424 /* If it is a function that has not been defined at library level,
4425 then we should be able to look it up in the symbols. */
4426 if (standard_lookup (name
, NULL
, VAR_DOMAIN
) != NULL
)
4429 /* Library-level function names start with "_ada_". See if function
4430 "_ada_" followed by NAME can be found. */
4432 /* Do a quick check that NAME does not contain "__", since library-level
4433 functions names cannot contain "__" in them. */
4434 if (strstr (name
, "__") != NULL
)
4437 fun_name
= xstrprintf ("_ada_%s", name
);
4439 return (standard_lookup (fun_name
, NULL
, VAR_DOMAIN
) == NULL
);
4442 /* Return nonzero if SYM corresponds to a renaming entity that is
4443 not visible from FUNCTION_NAME. */
4446 old_renaming_is_invisible (const struct symbol
*sym
, char *function_name
)
4450 if (SYMBOL_CLASS (sym
) != LOC_TYPEDEF
)
4453 scope
= xget_renaming_scope (SYMBOL_TYPE (sym
));
4455 make_cleanup (xfree
, scope
);
4457 /* If the rename has been defined in a package, then it is visible. */
4458 if (is_package_name (scope
))
4461 /* Check that the rename is in the current function scope by checking
4462 that its name starts with SCOPE. */
4464 /* If the function name starts with "_ada_", it means that it is
4465 a library-level function. Strip this prefix before doing the
4466 comparison, as the encoding for the renaming does not contain
4468 if (strncmp (function_name
, "_ada_", 5) == 0)
4471 return (strncmp (function_name
, scope
, strlen (scope
)) != 0);
4474 /* Remove entries from SYMS that corresponds to a renaming entity that
4475 is not visible from the function associated with CURRENT_BLOCK or
4476 that is superfluous due to the presence of more specific renaming
4477 information. Places surviving symbols in the initial entries of
4478 SYMS and returns the number of surviving symbols.
4481 First, in cases where an object renaming is implemented as a
4482 reference variable, GNAT may produce both the actual reference
4483 variable and the renaming encoding. In this case, we discard the
4486 Second, GNAT emits a type following a specified encoding for each renaming
4487 entity. Unfortunately, STABS currently does not support the definition
4488 of types that are local to a given lexical block, so all renamings types
4489 are emitted at library level. As a consequence, if an application
4490 contains two renaming entities using the same name, and a user tries to
4491 print the value of one of these entities, the result of the ada symbol
4492 lookup will also contain the wrong renaming type.
4494 This function partially covers for this limitation by attempting to
4495 remove from the SYMS list renaming symbols that should be visible
4496 from CURRENT_BLOCK. However, there does not seem be a 100% reliable
4497 method with the current information available. The implementation
4498 below has a couple of limitations (FIXME: brobecker-2003-05-12):
4500 - When the user tries to print a rename in a function while there
4501 is another rename entity defined in a package: Normally, the
4502 rename in the function has precedence over the rename in the
4503 package, so the latter should be removed from the list. This is
4504 currently not the case.
4506 - This function will incorrectly remove valid renames if
4507 the CURRENT_BLOCK corresponds to a function which symbol name
4508 has been changed by an "Export" pragma. As a consequence,
4509 the user will be unable to print such rename entities. */
4512 remove_irrelevant_renamings (struct ada_symbol_info
*syms
,
4513 int nsyms
, const struct block
*current_block
)
4515 struct symbol
*current_function
;
4516 char *current_function_name
;
4518 int is_new_style_renaming
;
4520 /* If there is both a renaming foo___XR... encoded as a variable and
4521 a simple variable foo in the same block, discard the latter.
4522 First, zero out such symbols, then compress. */
4523 is_new_style_renaming
= 0;
4524 for (i
= 0; i
< nsyms
; i
+= 1)
4526 struct symbol
*sym
= syms
[i
].sym
;
4527 struct block
*block
= syms
[i
].block
;
4531 if (sym
== NULL
|| SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
4533 name
= SYMBOL_LINKAGE_NAME (sym
);
4534 suffix
= strstr (name
, "___XR");
4538 int name_len
= suffix
- name
;
4540 is_new_style_renaming
= 1;
4541 for (j
= 0; j
< nsyms
; j
+= 1)
4542 if (i
!= j
&& syms
[j
].sym
!= NULL
4543 && strncmp (name
, SYMBOL_LINKAGE_NAME (syms
[j
].sym
),
4545 && block
== syms
[j
].block
)
4549 if (is_new_style_renaming
)
4553 for (j
= k
= 0; j
< nsyms
; j
+= 1)
4554 if (syms
[j
].sym
!= NULL
)
4562 /* Extract the function name associated to CURRENT_BLOCK.
4563 Abort if unable to do so. */
4565 if (current_block
== NULL
)
4568 current_function
= block_linkage_function (current_block
);
4569 if (current_function
== NULL
)
4572 current_function_name
= SYMBOL_LINKAGE_NAME (current_function
);
4573 if (current_function_name
== NULL
)
4576 /* Check each of the symbols, and remove it from the list if it is
4577 a type corresponding to a renaming that is out of the scope of
4578 the current block. */
4583 if (ada_parse_renaming (syms
[i
].sym
, NULL
, NULL
, NULL
)
4584 == ADA_OBJECT_RENAMING
4585 && old_renaming_is_invisible (syms
[i
].sym
, current_function_name
))
4588 for (j
= i
+ 1; j
< nsyms
; j
+= 1)
4589 syms
[j
- 1] = syms
[j
];
4599 /* Add to OBSTACKP all symbols from BLOCK (and its super-blocks)
4600 whose name and domain match NAME and DOMAIN respectively.
4601 If no match was found, then extend the search to "enclosing"
4602 routines (in other words, if we're inside a nested function,
4603 search the symbols defined inside the enclosing functions).
4605 Note: This function assumes that OBSTACKP has 0 (zero) element in it. */
4608 ada_add_local_symbols (struct obstack
*obstackp
, const char *name
,
4609 struct block
*block
, domain_enum domain
,
4612 int block_depth
= 0;
4614 while (block
!= NULL
)
4617 ada_add_block_symbols (obstackp
, block
, name
, domain
, NULL
, wild_match
);
4619 /* If we found a non-function match, assume that's the one. */
4620 if (is_nonfunction (defns_collected (obstackp
, 0),
4621 num_defns_collected (obstackp
)))
4624 block
= BLOCK_SUPERBLOCK (block
);
4627 /* If no luck so far, try to find NAME as a local symbol in some lexically
4628 enclosing subprogram. */
4629 if (num_defns_collected (obstackp
) == 0 && block_depth
> 2)
4630 add_symbols_from_enclosing_procs (obstackp
, name
, domain
, wild_match
);
4633 /* Add to OBSTACKP all non-local symbols whose name and domain match
4634 NAME and DOMAIN respectively. The search is performed on GLOBAL_BLOCK
4635 symbols if GLOBAL is non-zero, or on STATIC_BLOCK symbols otherwise. */
4638 ada_add_non_local_symbols (struct obstack
*obstackp
, const char *name
,
4639 domain_enum domain
, int global
,
4642 struct objfile
*objfile
;
4643 struct partial_symtab
*ps
;
4645 ALL_PSYMTABS (objfile
, ps
)
4649 || ada_lookup_partial_symbol (ps
, name
, global
, domain
, wild_match
))
4651 struct symtab
*s
= PSYMTAB_TO_SYMTAB (ps
);
4652 const int block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
4654 if (s
== NULL
|| !s
->primary
)
4656 ada_add_block_symbols (obstackp
,
4657 BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), block_kind
),
4658 name
, domain
, objfile
, wild_match
);
4663 /* Find symbols in DOMAIN matching NAME0, in BLOCK0 and enclosing
4664 scope and in global scopes, returning the number of matches. Sets
4665 *RESULTS to point to a vector of (SYM,BLOCK) tuples,
4666 indicating the symbols found and the blocks and symbol tables (if
4667 any) in which they were found. This vector are transient---good only to
4668 the next call of ada_lookup_symbol_list. Any non-function/non-enumeral
4669 symbol match within the nest of blocks whose innermost member is BLOCK0,
4670 is the one match returned (no other matches in that or
4671 enclosing blocks is returned). If there are any matches in or
4672 surrounding BLOCK0, then these alone are returned. Otherwise, the
4673 search extends to global and file-scope (static) symbol tables.
4674 Names prefixed with "standard__" are handled specially: "standard__"
4675 is first stripped off, and only static and global symbols are searched. */
4678 ada_lookup_symbol_list (const char *name0
, const struct block
*block0
,
4679 domain_enum
namespace,
4680 struct ada_symbol_info
**results
)
4683 struct block
*block
;
4689 obstack_free (&symbol_list_obstack
, NULL
);
4690 obstack_init (&symbol_list_obstack
);
4694 /* Search specified block and its superiors. */
4696 wild_match
= (strstr (name0
, "__") == NULL
);
4698 block
= (struct block
*) block0
; /* FIXME: No cast ought to be
4699 needed, but adding const will
4700 have a cascade effect. */
4702 /* Special case: If the user specifies a symbol name inside package
4703 Standard, do a non-wild matching of the symbol name without
4704 the "standard__" prefix. This was primarily introduced in order
4705 to allow the user to specifically access the standard exceptions
4706 using, for instance, Standard.Constraint_Error when Constraint_Error
4707 is ambiguous (due to the user defining its own Constraint_Error
4708 entity inside its program). */
4709 if (strncmp (name0
, "standard__", sizeof ("standard__") - 1) == 0)
4713 name
= name0
+ sizeof ("standard__") - 1;
4716 /* Check the non-global symbols. If we have ANY match, then we're done. */
4718 ada_add_local_symbols (&symbol_list_obstack
, name
, block
, namespace,
4720 if (num_defns_collected (&symbol_list_obstack
) > 0)
4723 /* No non-global symbols found. Check our cache to see if we have
4724 already performed this search before. If we have, then return
4728 if (lookup_cached_symbol (name0
, namespace, &sym
, &block
))
4731 add_defn_to_vec (&symbol_list_obstack
, sym
, block
);
4735 /* Search symbols from all global blocks. */
4737 ada_add_non_local_symbols (&symbol_list_obstack
, name
, namespace, 1,
4740 /* Now add symbols from all per-file blocks if we've gotten no hits
4741 (not strictly correct, but perhaps better than an error). */
4743 if (num_defns_collected (&symbol_list_obstack
) == 0)
4744 ada_add_non_local_symbols (&symbol_list_obstack
, name
, namespace, 0,
4748 ndefns
= num_defns_collected (&symbol_list_obstack
);
4749 *results
= defns_collected (&symbol_list_obstack
, 1);
4751 ndefns
= remove_extra_symbols (*results
, ndefns
);
4754 cache_symbol (name0
, namespace, NULL
, NULL
);
4756 if (ndefns
== 1 && cacheIfUnique
)
4757 cache_symbol (name0
, namespace, (*results
)[0].sym
, (*results
)[0].block
);
4759 ndefns
= remove_irrelevant_renamings (*results
, ndefns
, block0
);
4765 ada_lookup_encoded_symbol (const char *name
, const struct block
*block0
,
4766 domain_enum
namespace, struct block
**block_found
)
4768 struct ada_symbol_info
*candidates
;
4771 n_candidates
= ada_lookup_symbol_list (name
, block0
, namespace, &candidates
);
4773 if (n_candidates
== 0)
4776 if (block_found
!= NULL
)
4777 *block_found
= candidates
[0].block
;
4779 return fixup_symbol_section (candidates
[0].sym
, NULL
);
4782 /* Return a symbol in DOMAIN matching NAME, in BLOCK0 and enclosing
4783 scope and in global scopes, or NULL if none. NAME is folded and
4784 encoded first. Otherwise, the result is as for ada_lookup_symbol_list,
4785 choosing the first symbol if there are multiple choices.
4786 *IS_A_FIELD_OF_THIS is set to 0 and *SYMTAB is set to the symbol
4787 table in which the symbol was found (in both cases, these
4788 assignments occur only if the pointers are non-null). */
4790 ada_lookup_symbol (const char *name
, const struct block
*block0
,
4791 domain_enum
namespace, int *is_a_field_of_this
)
4793 if (is_a_field_of_this
!= NULL
)
4794 *is_a_field_of_this
= 0;
4797 ada_lookup_encoded_symbol (ada_encode (ada_fold_name (name
)),
4798 block0
, namespace, NULL
);
4801 static struct symbol
*
4802 ada_lookup_symbol_nonlocal (const char *name
,
4803 const char *linkage_name
,
4804 const struct block
*block
,
4805 const domain_enum domain
)
4807 if (linkage_name
== NULL
)
4808 linkage_name
= name
;
4809 return ada_lookup_symbol (linkage_name
, block_static_block (block
), domain
,
4814 /* True iff STR is a possible encoded suffix of a normal Ada name
4815 that is to be ignored for matching purposes. Suffixes of parallel
4816 names (e.g., XVE) are not included here. Currently, the possible suffixes
4817 are given by any of the regular expressions:
4819 [.$][0-9]+ [nested subprogram suffix, on platforms such as GNU/Linux]
4820 ___[0-9]+ [nested subprogram suffix, on platforms such as HP/UX]
4821 _E[0-9]+[bs]$ [protected object entry suffixes]
4822 (X[nb]*)?((\$|__)[0-9](_?[0-9]+)|___(JM|LJM|X([FDBUP].*|R[^T]?)))?$
4824 Also, any leading "__[0-9]+" sequence is skipped before the suffix
4825 match is performed. This sequence is used to differentiate homonyms,
4826 is an optional part of a valid name suffix. */
4829 is_name_suffix (const char *str
)
4832 const char *matching
;
4833 const int len
= strlen (str
);
4835 /* Skip optional leading __[0-9]+. */
4837 if (len
> 3 && str
[0] == '_' && str
[1] == '_' && isdigit (str
[2]))
4840 while (isdigit (str
[0]))
4846 if (str
[0] == '.' || str
[0] == '$')
4849 while (isdigit (matching
[0]))
4851 if (matching
[0] == '\0')
4857 if (len
> 3 && str
[0] == '_' && str
[1] == '_' && str
[2] == '_')
4860 while (isdigit (matching
[0]))
4862 if (matching
[0] == '\0')
4867 /* FIXME: brobecker/2005-09-23: Protected Object subprograms end
4868 with a N at the end. Unfortunately, the compiler uses the same
4869 convention for other internal types it creates. So treating
4870 all entity names that end with an "N" as a name suffix causes
4871 some regressions. For instance, consider the case of an enumerated
4872 type. To support the 'Image attribute, it creates an array whose
4874 Having a single character like this as a suffix carrying some
4875 information is a bit risky. Perhaps we should change the encoding
4876 to be something like "_N" instead. In the meantime, do not do
4877 the following check. */
4878 /* Protected Object Subprograms */
4879 if (len
== 1 && str
[0] == 'N')
4884 if (len
> 3 && str
[0] == '_' && str
[1] == 'E' && isdigit (str
[2]))
4887 while (isdigit (matching
[0]))
4889 if ((matching
[0] == 'b' || matching
[0] == 's')
4890 && matching
[1] == '\0')
4894 /* ??? We should not modify STR directly, as we are doing below. This
4895 is fine in this case, but may become problematic later if we find
4896 that this alternative did not work, and want to try matching
4897 another one from the begining of STR. Since we modified it, we
4898 won't be able to find the begining of the string anymore! */
4902 while (str
[0] != '_' && str
[0] != '\0')
4904 if (str
[0] != 'n' && str
[0] != 'b')
4910 if (str
[0] == '\000')
4915 if (str
[1] != '_' || str
[2] == '\000')
4919 if (strcmp (str
+ 3, "JM") == 0)
4921 /* FIXME: brobecker/2004-09-30: GNAT will soon stop using
4922 the LJM suffix in favor of the JM one. But we will
4923 still accept LJM as a valid suffix for a reasonable
4924 amount of time, just to allow ourselves to debug programs
4925 compiled using an older version of GNAT. */
4926 if (strcmp (str
+ 3, "LJM") == 0)
4930 if (str
[4] == 'F' || str
[4] == 'D' || str
[4] == 'B'
4931 || str
[4] == 'U' || str
[4] == 'P')
4933 if (str
[4] == 'R' && str
[5] != 'T')
4937 if (!isdigit (str
[2]))
4939 for (k
= 3; str
[k
] != '\0'; k
+= 1)
4940 if (!isdigit (str
[k
]) && str
[k
] != '_')
4944 if (str
[0] == '$' && isdigit (str
[1]))
4946 for (k
= 2; str
[k
] != '\0'; k
+= 1)
4947 if (!isdigit (str
[k
]) && str
[k
] != '_')
4954 /* Return non-zero if the string starting at NAME and ending before
4955 NAME_END contains no capital letters. */
4958 is_valid_name_for_wild_match (const char *name0
)
4960 const char *decoded_name
= ada_decode (name0
);
4963 /* If the decoded name starts with an angle bracket, it means that
4964 NAME0 does not follow the GNAT encoding format. It should then
4965 not be allowed as a possible wild match. */
4966 if (decoded_name
[0] == '<')
4969 for (i
=0; decoded_name
[i
] != '\0'; i
++)
4970 if (isalpha (decoded_name
[i
]) && !islower (decoded_name
[i
]))
4976 /* True if NAME represents a name of the form A1.A2....An, n>=1 and
4977 PATN[0..PATN_LEN-1] = Ak.Ak+1.....An for some k >= 1. Ignores
4978 informational suffixes of NAME (i.e., for which is_name_suffix is
4982 wild_match (const char *patn0
, int patn_len
, const char *name0
)
4989 match
= strstr (start
, patn0
);
4994 || (match
> name0
+ 1 && match
[-1] == '_' && match
[-2] == '_')
4995 || (match
== name0
+ 5 && strncmp ("_ada_", name0
, 5) == 0))
4996 && is_name_suffix (match
+ patn_len
))
4997 return (match
== name0
|| is_valid_name_for_wild_match (name0
));
5003 /* Add symbols from BLOCK matching identifier NAME in DOMAIN to
5004 vector *defn_symbols, updating the list of symbols in OBSTACKP
5005 (if necessary). If WILD, treat as NAME with a wildcard prefix.
5006 OBJFILE is the section containing BLOCK.
5007 SYMTAB is recorded with each symbol added. */
5010 ada_add_block_symbols (struct obstack
*obstackp
,
5011 struct block
*block
, const char *name
,
5012 domain_enum domain
, struct objfile
*objfile
,
5015 struct dict_iterator iter
;
5016 int name_len
= strlen (name
);
5017 /* A matching argument symbol, if any. */
5018 struct symbol
*arg_sym
;
5019 /* Set true when we find a matching non-argument symbol. */
5028 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
5030 if (symbol_matches_domain (SYMBOL_LANGUAGE (sym
),
5031 SYMBOL_DOMAIN (sym
), domain
)
5032 && wild_match (name
, name_len
, SYMBOL_LINKAGE_NAME (sym
)))
5034 if (SYMBOL_CLASS (sym
) == LOC_UNRESOLVED
)
5036 else if (SYMBOL_IS_ARGUMENT (sym
))
5041 add_defn_to_vec (obstackp
,
5042 fixup_symbol_section (sym
, objfile
),
5050 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
5052 if (symbol_matches_domain (SYMBOL_LANGUAGE (sym
),
5053 SYMBOL_DOMAIN (sym
), domain
))
5055 int cmp
= strncmp (name
, SYMBOL_LINKAGE_NAME (sym
), name_len
);
5057 && is_name_suffix (SYMBOL_LINKAGE_NAME (sym
) + name_len
))
5059 if (SYMBOL_CLASS (sym
) != LOC_UNRESOLVED
)
5061 if (SYMBOL_IS_ARGUMENT (sym
))
5066 add_defn_to_vec (obstackp
,
5067 fixup_symbol_section (sym
, objfile
),
5076 if (!found_sym
&& arg_sym
!= NULL
)
5078 add_defn_to_vec (obstackp
,
5079 fixup_symbol_section (arg_sym
, objfile
),
5088 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
5090 if (symbol_matches_domain (SYMBOL_LANGUAGE (sym
),
5091 SYMBOL_DOMAIN (sym
), domain
))
5095 cmp
= (int) '_' - (int) SYMBOL_LINKAGE_NAME (sym
)[0];
5098 cmp
= strncmp ("_ada_", SYMBOL_LINKAGE_NAME (sym
), 5);
5100 cmp
= strncmp (name
, SYMBOL_LINKAGE_NAME (sym
) + 5,
5105 && is_name_suffix (SYMBOL_LINKAGE_NAME (sym
) + name_len
+ 5))
5107 if (SYMBOL_CLASS (sym
) != LOC_UNRESOLVED
)
5109 if (SYMBOL_IS_ARGUMENT (sym
))
5114 add_defn_to_vec (obstackp
,
5115 fixup_symbol_section (sym
, objfile
),
5123 /* NOTE: This really shouldn't be needed for _ada_ symbols.
5124 They aren't parameters, right? */
5125 if (!found_sym
&& arg_sym
!= NULL
)
5127 add_defn_to_vec (obstackp
,
5128 fixup_symbol_section (arg_sym
, objfile
),
5135 /* Symbol Completion */
5137 /* If SYM_NAME is a completion candidate for TEXT, return this symbol
5138 name in a form that's appropriate for the completion. The result
5139 does not need to be deallocated, but is only good until the next call.
5141 TEXT_LEN is equal to the length of TEXT.
5142 Perform a wild match if WILD_MATCH is set.
5143 ENCODED should be set if TEXT represents the start of a symbol name
5144 in its encoded form. */
5147 symbol_completion_match (const char *sym_name
,
5148 const char *text
, int text_len
,
5149 int wild_match
, int encoded
)
5152 const int verbatim_match
= (text
[0] == '<');
5157 /* Strip the leading angle bracket. */
5162 /* First, test against the fully qualified name of the symbol. */
5164 if (strncmp (sym_name
, text
, text_len
) == 0)
5167 if (match
&& !encoded
)
5169 /* One needed check before declaring a positive match is to verify
5170 that iff we are doing a verbatim match, the decoded version
5171 of the symbol name starts with '<'. Otherwise, this symbol name
5172 is not a suitable completion. */
5173 const char *sym_name_copy
= sym_name
;
5174 int has_angle_bracket
;
5176 sym_name
= ada_decode (sym_name
);
5177 has_angle_bracket
= (sym_name
[0] == '<');
5178 match
= (has_angle_bracket
== verbatim_match
);
5179 sym_name
= sym_name_copy
;
5182 if (match
&& !verbatim_match
)
5184 /* When doing non-verbatim match, another check that needs to
5185 be done is to verify that the potentially matching symbol name
5186 does not include capital letters, because the ada-mode would
5187 not be able to understand these symbol names without the
5188 angle bracket notation. */
5191 for (tmp
= sym_name
; *tmp
!= '\0' && !isupper (*tmp
); tmp
++);
5196 /* Second: Try wild matching... */
5198 if (!match
&& wild_match
)
5200 /* Since we are doing wild matching, this means that TEXT
5201 may represent an unqualified symbol name. We therefore must
5202 also compare TEXT against the unqualified name of the symbol. */
5203 sym_name
= ada_unqualified_name (ada_decode (sym_name
));
5205 if (strncmp (sym_name
, text
, text_len
) == 0)
5209 /* Finally: If we found a mach, prepare the result to return. */
5215 sym_name
= add_angle_brackets (sym_name
);
5218 sym_name
= ada_decode (sym_name
);
5223 typedef char *char_ptr
;
5224 DEF_VEC_P (char_ptr
);
5226 /* A companion function to ada_make_symbol_completion_list().
5227 Check if SYM_NAME represents a symbol which name would be suitable
5228 to complete TEXT (TEXT_LEN is the length of TEXT), in which case
5229 it is appended at the end of the given string vector SV.
5231 ORIG_TEXT is the string original string from the user command
5232 that needs to be completed. WORD is the entire command on which
5233 completion should be performed. These two parameters are used to
5234 determine which part of the symbol name should be added to the
5236 if WILD_MATCH is set, then wild matching is performed.
5237 ENCODED should be set if TEXT represents a symbol name in its
5238 encoded formed (in which case the completion should also be
5242 symbol_completion_add (VEC(char_ptr
) **sv
,
5243 const char *sym_name
,
5244 const char *text
, int text_len
,
5245 const char *orig_text
, const char *word
,
5246 int wild_match
, int encoded
)
5248 const char *match
= symbol_completion_match (sym_name
, text
, text_len
,
5249 wild_match
, encoded
);
5255 /* We found a match, so add the appropriate completion to the given
5258 if (word
== orig_text
)
5260 completion
= xmalloc (strlen (match
) + 5);
5261 strcpy (completion
, match
);
5263 else if (word
> orig_text
)
5265 /* Return some portion of sym_name. */
5266 completion
= xmalloc (strlen (match
) + 5);
5267 strcpy (completion
, match
+ (word
- orig_text
));
5271 /* Return some of ORIG_TEXT plus sym_name. */
5272 completion
= xmalloc (strlen (match
) + (orig_text
- word
) + 5);
5273 strncpy (completion
, word
, orig_text
- word
);
5274 completion
[orig_text
- word
] = '\0';
5275 strcat (completion
, match
);
5278 VEC_safe_push (char_ptr
, *sv
, completion
);
5281 /* Return a list of possible symbol names completing TEXT0. The list
5282 is NULL terminated. WORD is the entire command on which completion
5286 ada_make_symbol_completion_list (char *text0
, char *word
)
5292 VEC(char_ptr
) *completions
= VEC_alloc (char_ptr
, 128);
5295 struct partial_symtab
*ps
;
5296 struct minimal_symbol
*msymbol
;
5297 struct objfile
*objfile
;
5298 struct block
*b
, *surrounding_static_block
= 0;
5300 struct dict_iterator iter
;
5302 if (text0
[0] == '<')
5304 text
= xstrdup (text0
);
5305 make_cleanup (xfree
, text
);
5306 text_len
= strlen (text
);
5312 text
= xstrdup (ada_encode (text0
));
5313 make_cleanup (xfree
, text
);
5314 text_len
= strlen (text
);
5315 for (i
= 0; i
< text_len
; i
++)
5316 text
[i
] = tolower (text
[i
]);
5318 encoded
= (strstr (text0
, "__") != NULL
);
5319 /* If the name contains a ".", then the user is entering a fully
5320 qualified entity name, and the match must not be done in wild
5321 mode. Similarly, if the user wants to complete what looks like
5322 an encoded name, the match must not be done in wild mode. */
5323 wild_match
= (strchr (text0
, '.') == NULL
&& !encoded
);
5326 /* First, look at the partial symtab symbols. */
5327 ALL_PSYMTABS (objfile
, ps
)
5329 struct partial_symbol
**psym
;
5331 /* If the psymtab's been read in we'll get it when we search
5332 through the blockvector. */
5336 for (psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
5337 psym
< (objfile
->global_psymbols
.list
+ ps
->globals_offset
5338 + ps
->n_global_syms
); psym
++)
5341 symbol_completion_add (&completions
, SYMBOL_LINKAGE_NAME (*psym
),
5342 text
, text_len
, text0
, word
,
5343 wild_match
, encoded
);
5346 for (psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
5347 psym
< (objfile
->static_psymbols
.list
+ ps
->statics_offset
5348 + ps
->n_static_syms
); psym
++)
5351 symbol_completion_add (&completions
, SYMBOL_LINKAGE_NAME (*psym
),
5352 text
, text_len
, text0
, word
,
5353 wild_match
, encoded
);
5357 /* At this point scan through the misc symbol vectors and add each
5358 symbol you find to the list. Eventually we want to ignore
5359 anything that isn't a text symbol (everything else will be
5360 handled by the psymtab code above). */
5362 ALL_MSYMBOLS (objfile
, msymbol
)
5365 symbol_completion_add (&completions
, SYMBOL_LINKAGE_NAME (msymbol
),
5366 text
, text_len
, text0
, word
, wild_match
, encoded
);
5369 /* Search upwards from currently selected frame (so that we can
5370 complete on local vars. */
5372 for (b
= get_selected_block (0); b
!= NULL
; b
= BLOCK_SUPERBLOCK (b
))
5374 if (!BLOCK_SUPERBLOCK (b
))
5375 surrounding_static_block
= b
; /* For elmin of dups */
5377 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
5379 symbol_completion_add (&completions
, SYMBOL_LINKAGE_NAME (sym
),
5380 text
, text_len
, text0
, word
,
5381 wild_match
, encoded
);
5385 /* Go through the symtabs and check the externs and statics for
5386 symbols which match. */
5388 ALL_SYMTABS (objfile
, s
)
5391 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
);
5392 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
5394 symbol_completion_add (&completions
, SYMBOL_LINKAGE_NAME (sym
),
5395 text
, text_len
, text0
, word
,
5396 wild_match
, encoded
);
5400 ALL_SYMTABS (objfile
, s
)
5403 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
);
5404 /* Don't do this block twice. */
5405 if (b
== surrounding_static_block
)
5407 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
5409 symbol_completion_add (&completions
, SYMBOL_LINKAGE_NAME (sym
),
5410 text
, text_len
, text0
, word
,
5411 wild_match
, encoded
);
5415 /* Append the closing NULL entry. */
5416 VEC_safe_push (char_ptr
, completions
, NULL
);
5418 /* Make a copy of the COMPLETIONS VEC before we free it, and then
5419 return the copy. It's unfortunate that we have to make a copy
5420 of an array that we're about to destroy, but there is nothing much
5421 we can do about it. Fortunately, it's typically not a very large
5424 const size_t completions_size
=
5425 VEC_length (char_ptr
, completions
) * sizeof (char *);
5426 char **result
= malloc (completions_size
);
5428 memcpy (result
, VEC_address (char_ptr
, completions
), completions_size
);
5430 VEC_free (char_ptr
, completions
);
5437 /* Return non-zero if TYPE is a pointer to the GNAT dispatch table used
5438 for tagged types. */
5441 ada_is_dispatch_table_ptr_type (struct type
*type
)
5445 if (TYPE_CODE (type
) != TYPE_CODE_PTR
)
5448 name
= TYPE_NAME (TYPE_TARGET_TYPE (type
));
5452 return (strcmp (name
, "ada__tags__dispatch_table") == 0);
5455 /* True if field number FIELD_NUM in struct or union type TYPE is supposed
5456 to be invisible to users. */
5459 ada_is_ignored_field (struct type
*type
, int field_num
)
5461 if (field_num
< 0 || field_num
> TYPE_NFIELDS (type
))
5464 /* Check the name of that field. */
5466 const char *name
= TYPE_FIELD_NAME (type
, field_num
);
5468 /* Anonymous field names should not be printed.
5469 brobecker/2007-02-20: I don't think this can actually happen
5470 but we don't want to print the value of annonymous fields anyway. */
5474 /* A field named "_parent" is internally generated by GNAT for
5475 tagged types, and should not be printed either. */
5476 if (name
[0] == '_' && strncmp (name
, "_parent", 7) != 0)
5480 /* If this is the dispatch table of a tagged type, then ignore. */
5481 if (ada_is_tagged_type (type
, 1)
5482 && ada_is_dispatch_table_ptr_type (TYPE_FIELD_TYPE (type
, field_num
)))
5485 /* Not a special field, so it should not be ignored. */
5489 /* True iff TYPE has a tag field. If REFOK, then TYPE may also be a
5490 pointer or reference type whose ultimate target has a tag field. */
5493 ada_is_tagged_type (struct type
*type
, int refok
)
5495 return (ada_lookup_struct_elt_type (type
, "_tag", refok
, 1, NULL
) != NULL
);
5498 /* True iff TYPE represents the type of X'Tag */
5501 ada_is_tag_type (struct type
*type
)
5503 if (type
== NULL
|| TYPE_CODE (type
) != TYPE_CODE_PTR
)
5507 const char *name
= ada_type_name (TYPE_TARGET_TYPE (type
));
5508 return (name
!= NULL
5509 && strcmp (name
, "ada__tags__dispatch_table") == 0);
5513 /* The type of the tag on VAL. */
5516 ada_tag_type (struct value
*val
)
5518 return ada_lookup_struct_elt_type (value_type (val
), "_tag", 1, 0, NULL
);
5521 /* The value of the tag on VAL. */
5524 ada_value_tag (struct value
*val
)
5526 return ada_value_struct_elt (val
, "_tag", 0);
5529 /* The value of the tag on the object of type TYPE whose contents are
5530 saved at VALADDR, if it is non-null, or is at memory address
5533 static struct value
*
5534 value_tag_from_contents_and_address (struct type
*type
,
5535 const gdb_byte
*valaddr
,
5538 int tag_byte_offset
, dummy1
, dummy2
;
5539 struct type
*tag_type
;
5540 if (find_struct_field ("_tag", type
, 0, &tag_type
, &tag_byte_offset
,
5543 const gdb_byte
*valaddr1
= ((valaddr
== NULL
)
5545 : valaddr
+ tag_byte_offset
);
5546 CORE_ADDR address1
= (address
== 0) ? 0 : address
+ tag_byte_offset
;
5548 return value_from_contents_and_address (tag_type
, valaddr1
, address1
);
5553 static struct type
*
5554 type_from_tag (struct value
*tag
)
5556 const char *type_name
= ada_tag_name (tag
);
5557 if (type_name
!= NULL
)
5558 return ada_find_any_type (ada_encode (type_name
));
5569 static int ada_tag_name_1 (void *);
5570 static int ada_tag_name_2 (struct tag_args
*);
5572 /* Wrapper function used by ada_tag_name. Given a struct tag_args*
5573 value ARGS, sets ARGS->name to the tag name of ARGS->tag.
5574 The value stored in ARGS->name is valid until the next call to
5578 ada_tag_name_1 (void *args0
)
5580 struct tag_args
*args
= (struct tag_args
*) args0
;
5581 static char name
[1024];
5585 val
= ada_value_struct_elt (args
->tag
, "tsd", 1);
5587 return ada_tag_name_2 (args
);
5588 val
= ada_value_struct_elt (val
, "expanded_name", 1);
5591 read_memory_string (value_as_address (val
), name
, sizeof (name
) - 1);
5592 for (p
= name
; *p
!= '\0'; p
+= 1)
5599 /* Utility function for ada_tag_name_1 that tries the second
5600 representation for the dispatch table (in which there is no
5601 explicit 'tsd' field in the referent of the tag pointer, and instead
5602 the tsd pointer is stored just before the dispatch table. */
5605 ada_tag_name_2 (struct tag_args
*args
)
5607 struct type
*info_type
;
5608 static char name
[1024];
5610 struct value
*val
, *valp
;
5613 info_type
= ada_find_any_type ("ada__tags__type_specific_data");
5614 if (info_type
== NULL
)
5616 info_type
= lookup_pointer_type (lookup_pointer_type (info_type
));
5617 valp
= value_cast (info_type
, args
->tag
);
5620 val
= value_ind (value_ptradd (valp
,
5621 value_from_longest (builtin_type_int8
, -1)));
5624 val
= ada_value_struct_elt (val
, "expanded_name", 1);
5627 read_memory_string (value_as_address (val
), name
, sizeof (name
) - 1);
5628 for (p
= name
; *p
!= '\0'; p
+= 1)
5635 /* The type name of the dynamic type denoted by the 'tag value TAG, as
5639 ada_tag_name (struct value
*tag
)
5641 struct tag_args args
;
5642 if (!ada_is_tag_type (value_type (tag
)))
5646 catch_errors (ada_tag_name_1
, &args
, NULL
, RETURN_MASK_ALL
);
5650 /* The parent type of TYPE, or NULL if none. */
5653 ada_parent_type (struct type
*type
)
5657 type
= ada_check_typedef (type
);
5659 if (type
== NULL
|| TYPE_CODE (type
) != TYPE_CODE_STRUCT
)
5662 for (i
= 0; i
< TYPE_NFIELDS (type
); i
+= 1)
5663 if (ada_is_parent_field (type
, i
))
5665 struct type
*parent_type
= TYPE_FIELD_TYPE (type
, i
);
5667 /* If the _parent field is a pointer, then dereference it. */
5668 if (TYPE_CODE (parent_type
) == TYPE_CODE_PTR
)
5669 parent_type
= TYPE_TARGET_TYPE (parent_type
);
5670 /* If there is a parallel XVS type, get the actual base type. */
5671 parent_type
= ada_get_base_type (parent_type
);
5673 return ada_check_typedef (parent_type
);
5679 /* True iff field number FIELD_NUM of structure type TYPE contains the
5680 parent-type (inherited) fields of a derived type. Assumes TYPE is
5681 a structure type with at least FIELD_NUM+1 fields. */
5684 ada_is_parent_field (struct type
*type
, int field_num
)
5686 const char *name
= TYPE_FIELD_NAME (ada_check_typedef (type
), field_num
);
5687 return (name
!= NULL
5688 && (strncmp (name
, "PARENT", 6) == 0
5689 || strncmp (name
, "_parent", 7) == 0));
5692 /* True iff field number FIELD_NUM of structure type TYPE is a
5693 transparent wrapper field (which should be silently traversed when doing
5694 field selection and flattened when printing). Assumes TYPE is a
5695 structure type with at least FIELD_NUM+1 fields. Such fields are always
5699 ada_is_wrapper_field (struct type
*type
, int field_num
)
5701 const char *name
= TYPE_FIELD_NAME (type
, field_num
);
5702 return (name
!= NULL
5703 && (strncmp (name
, "PARENT", 6) == 0
5704 || strcmp (name
, "REP") == 0
5705 || strncmp (name
, "_parent", 7) == 0
5706 || name
[0] == 'S' || name
[0] == 'R' || name
[0] == 'O'));
5709 /* True iff field number FIELD_NUM of structure or union type TYPE
5710 is a variant wrapper. Assumes TYPE is a structure type with at least
5711 FIELD_NUM+1 fields. */
5714 ada_is_variant_part (struct type
*type
, int field_num
)
5716 struct type
*field_type
= TYPE_FIELD_TYPE (type
, field_num
);
5717 return (TYPE_CODE (field_type
) == TYPE_CODE_UNION
5718 || (is_dynamic_field (type
, field_num
)
5719 && (TYPE_CODE (TYPE_TARGET_TYPE (field_type
))
5720 == TYPE_CODE_UNION
)));
5723 /* Assuming that VAR_TYPE is a variant wrapper (type of the variant part)
5724 whose discriminants are contained in the record type OUTER_TYPE,
5725 returns the type of the controlling discriminant for the variant. */
5728 ada_variant_discrim_type (struct type
*var_type
, struct type
*outer_type
)
5730 char *name
= ada_variant_discrim_name (var_type
);
5732 ada_lookup_struct_elt_type (outer_type
, name
, 1, 1, NULL
);
5734 return builtin_type_int32
;
5739 /* Assuming that TYPE is the type of a variant wrapper, and FIELD_NUM is a
5740 valid field number within it, returns 1 iff field FIELD_NUM of TYPE
5741 represents a 'when others' clause; otherwise 0. */
5744 ada_is_others_clause (struct type
*type
, int field_num
)
5746 const char *name
= TYPE_FIELD_NAME (type
, field_num
);
5747 return (name
!= NULL
&& name
[0] == 'O');
5750 /* Assuming that TYPE0 is the type of the variant part of a record,
5751 returns the name of the discriminant controlling the variant.
5752 The value is valid until the next call to ada_variant_discrim_name. */
5755 ada_variant_discrim_name (struct type
*type0
)
5757 static char *result
= NULL
;
5758 static size_t result_len
= 0;
5761 const char *discrim_end
;
5762 const char *discrim_start
;
5764 if (TYPE_CODE (type0
) == TYPE_CODE_PTR
)
5765 type
= TYPE_TARGET_TYPE (type0
);
5769 name
= ada_type_name (type
);
5771 if (name
== NULL
|| name
[0] == '\000')
5774 for (discrim_end
= name
+ strlen (name
) - 6; discrim_end
!= name
;
5777 if (strncmp (discrim_end
, "___XVN", 6) == 0)
5780 if (discrim_end
== name
)
5783 for (discrim_start
= discrim_end
; discrim_start
!= name
+ 3;
5786 if (discrim_start
== name
+ 1)
5788 if ((discrim_start
> name
+ 3
5789 && strncmp (discrim_start
- 3, "___", 3) == 0)
5790 || discrim_start
[-1] == '.')
5794 GROW_VECT (result
, result_len
, discrim_end
- discrim_start
+ 1);
5795 strncpy (result
, discrim_start
, discrim_end
- discrim_start
);
5796 result
[discrim_end
- discrim_start
] = '\0';
5800 /* Scan STR for a subtype-encoded number, beginning at position K.
5801 Put the position of the character just past the number scanned in
5802 *NEW_K, if NEW_K!=NULL. Put the scanned number in *R, if R!=NULL.
5803 Return 1 if there was a valid number at the given position, and 0
5804 otherwise. A "subtype-encoded" number consists of the absolute value
5805 in decimal, followed by the letter 'm' to indicate a negative number.
5806 Assumes 0m does not occur. */
5809 ada_scan_number (const char str
[], int k
, LONGEST
* R
, int *new_k
)
5813 if (!isdigit (str
[k
]))
5816 /* Do it the hard way so as not to make any assumption about
5817 the relationship of unsigned long (%lu scan format code) and
5820 while (isdigit (str
[k
]))
5822 RU
= RU
* 10 + (str
[k
] - '0');
5829 *R
= (-(LONGEST
) (RU
- 1)) - 1;
5835 /* NOTE on the above: Technically, C does not say what the results of
5836 - (LONGEST) RU or (LONGEST) -RU are for RU == largest positive
5837 number representable as a LONGEST (although either would probably work
5838 in most implementations). When RU>0, the locution in the then branch
5839 above is always equivalent to the negative of RU. */
5846 /* Assuming that TYPE is a variant part wrapper type (a VARIANTS field),
5847 and FIELD_NUM is a valid field number within it, returns 1 iff VAL is
5848 in the range encoded by field FIELD_NUM of TYPE; otherwise 0. */
5851 ada_in_variant (LONGEST val
, struct type
*type
, int field_num
)
5853 const char *name
= TYPE_FIELD_NAME (type
, field_num
);
5866 if (!ada_scan_number (name
, p
+ 1, &W
, &p
))
5875 if (!ada_scan_number (name
, p
+ 1, &L
, &p
)
5876 || name
[p
] != 'T' || !ada_scan_number (name
, p
+ 1, &U
, &p
))
5878 if (val
>= L
&& val
<= U
)
5890 /* FIXME: Lots of redundancy below. Try to consolidate. */
5892 /* Given a value ARG1 (offset by OFFSET bytes) of a struct or union type
5893 ARG_TYPE, extract and return the value of one of its (non-static)
5894 fields. FIELDNO says which field. Differs from value_primitive_field
5895 only in that it can handle packed values of arbitrary type. */
5897 static struct value
*
5898 ada_value_primitive_field (struct value
*arg1
, int offset
, int fieldno
,
5899 struct type
*arg_type
)
5903 arg_type
= ada_check_typedef (arg_type
);
5904 type
= TYPE_FIELD_TYPE (arg_type
, fieldno
);
5906 /* Handle packed fields. */
5908 if (TYPE_FIELD_BITSIZE (arg_type
, fieldno
) != 0)
5910 int bit_pos
= TYPE_FIELD_BITPOS (arg_type
, fieldno
);
5911 int bit_size
= TYPE_FIELD_BITSIZE (arg_type
, fieldno
);
5913 return ada_value_primitive_packed_val (arg1
, value_contents (arg1
),
5914 offset
+ bit_pos
/ 8,
5915 bit_pos
% 8, bit_size
, type
);
5918 return value_primitive_field (arg1
, offset
, fieldno
, arg_type
);
5921 /* Find field with name NAME in object of type TYPE. If found,
5922 set the following for each argument that is non-null:
5923 - *FIELD_TYPE_P to the field's type;
5924 - *BYTE_OFFSET_P to OFFSET + the byte offset of the field within
5925 an object of that type;
5926 - *BIT_OFFSET_P to the bit offset modulo byte size of the field;
5927 - *BIT_SIZE_P to its size in bits if the field is packed, and
5929 If INDEX_P is non-null, increment *INDEX_P by the number of source-visible
5930 fields up to but not including the desired field, or by the total
5931 number of fields if not found. A NULL value of NAME never
5932 matches; the function just counts visible fields in this case.
5934 Returns 1 if found, 0 otherwise. */
5937 find_struct_field (char *name
, struct type
*type
, int offset
,
5938 struct type
**field_type_p
,
5939 int *byte_offset_p
, int *bit_offset_p
, int *bit_size_p
,
5944 type
= ada_check_typedef (type
);
5946 if (field_type_p
!= NULL
)
5947 *field_type_p
= NULL
;
5948 if (byte_offset_p
!= NULL
)
5950 if (bit_offset_p
!= NULL
)
5952 if (bit_size_p
!= NULL
)
5955 for (i
= 0; i
< TYPE_NFIELDS (type
); i
+= 1)
5957 int bit_pos
= TYPE_FIELD_BITPOS (type
, i
);
5958 int fld_offset
= offset
+ bit_pos
/ 8;
5959 char *t_field_name
= TYPE_FIELD_NAME (type
, i
);
5961 if (t_field_name
== NULL
)
5964 else if (name
!= NULL
&& field_name_match (t_field_name
, name
))
5966 int bit_size
= TYPE_FIELD_BITSIZE (type
, i
);
5967 if (field_type_p
!= NULL
)
5968 *field_type_p
= TYPE_FIELD_TYPE (type
, i
);
5969 if (byte_offset_p
!= NULL
)
5970 *byte_offset_p
= fld_offset
;
5971 if (bit_offset_p
!= NULL
)
5972 *bit_offset_p
= bit_pos
% 8;
5973 if (bit_size_p
!= NULL
)
5974 *bit_size_p
= bit_size
;
5977 else if (ada_is_wrapper_field (type
, i
))
5979 if (find_struct_field (name
, TYPE_FIELD_TYPE (type
, i
), fld_offset
,
5980 field_type_p
, byte_offset_p
, bit_offset_p
,
5981 bit_size_p
, index_p
))
5984 else if (ada_is_variant_part (type
, i
))
5986 /* PNH: Wait. Do we ever execute this section, or is ARG always of
5989 struct type
*field_type
5990 = ada_check_typedef (TYPE_FIELD_TYPE (type
, i
));
5992 for (j
= 0; j
< TYPE_NFIELDS (field_type
); j
+= 1)
5994 if (find_struct_field (name
, TYPE_FIELD_TYPE (field_type
, j
),
5996 + TYPE_FIELD_BITPOS (field_type
, j
) / 8,
5997 field_type_p
, byte_offset_p
,
5998 bit_offset_p
, bit_size_p
, index_p
))
6002 else if (index_p
!= NULL
)
6008 /* Number of user-visible fields in record type TYPE. */
6011 num_visible_fields (struct type
*type
)
6015 find_struct_field (NULL
, type
, 0, NULL
, NULL
, NULL
, NULL
, &n
);
6019 /* Look for a field NAME in ARG. Adjust the address of ARG by OFFSET bytes,
6020 and search in it assuming it has (class) type TYPE.
6021 If found, return value, else return NULL.
6023 Searches recursively through wrapper fields (e.g., '_parent'). */
6025 static struct value
*
6026 ada_search_struct_field (char *name
, struct value
*arg
, int offset
,
6030 type
= ada_check_typedef (type
);
6032 for (i
= 0; i
< TYPE_NFIELDS (type
); i
+= 1)
6034 char *t_field_name
= TYPE_FIELD_NAME (type
, i
);
6036 if (t_field_name
== NULL
)
6039 else if (field_name_match (t_field_name
, name
))
6040 return ada_value_primitive_field (arg
, offset
, i
, type
);
6042 else if (ada_is_wrapper_field (type
, i
))
6044 struct value
*v
= /* Do not let indent join lines here. */
6045 ada_search_struct_field (name
, arg
,
6046 offset
+ TYPE_FIELD_BITPOS (type
, i
) / 8,
6047 TYPE_FIELD_TYPE (type
, i
));
6052 else if (ada_is_variant_part (type
, i
))
6054 /* PNH: Do we ever get here? See find_struct_field. */
6056 struct type
*field_type
= ada_check_typedef (TYPE_FIELD_TYPE (type
, i
));
6057 int var_offset
= offset
+ TYPE_FIELD_BITPOS (type
, i
) / 8;
6059 for (j
= 0; j
< TYPE_NFIELDS (field_type
); j
+= 1)
6061 struct value
*v
= ada_search_struct_field
/* Force line break. */
6063 var_offset
+ TYPE_FIELD_BITPOS (field_type
, j
) / 8,
6064 TYPE_FIELD_TYPE (field_type
, j
));
6073 static struct value
*ada_index_struct_field_1 (int *, struct value
*,
6074 int, struct type
*);
6077 /* Return field #INDEX in ARG, where the index is that returned by
6078 * find_struct_field through its INDEX_P argument. Adjust the address
6079 * of ARG by OFFSET bytes, and search in it assuming it has (class) type TYPE.
6080 * If found, return value, else return NULL. */
6082 static struct value
*
6083 ada_index_struct_field (int index
, struct value
*arg
, int offset
,
6086 return ada_index_struct_field_1 (&index
, arg
, offset
, type
);
6090 /* Auxiliary function for ada_index_struct_field. Like
6091 * ada_index_struct_field, but takes index from *INDEX_P and modifies
6094 static struct value
*
6095 ada_index_struct_field_1 (int *index_p
, struct value
*arg
, int offset
,
6099 type
= ada_check_typedef (type
);
6101 for (i
= 0; i
< TYPE_NFIELDS (type
); i
+= 1)
6103 if (TYPE_FIELD_NAME (type
, i
) == NULL
)
6105 else if (ada_is_wrapper_field (type
, i
))
6107 struct value
*v
= /* Do not let indent join lines here. */
6108 ada_index_struct_field_1 (index_p
, arg
,
6109 offset
+ TYPE_FIELD_BITPOS (type
, i
) / 8,
6110 TYPE_FIELD_TYPE (type
, i
));
6115 else if (ada_is_variant_part (type
, i
))
6117 /* PNH: Do we ever get here? See ada_search_struct_field,
6118 find_struct_field. */
6119 error (_("Cannot assign this kind of variant record"));
6121 else if (*index_p
== 0)
6122 return ada_value_primitive_field (arg
, offset
, i
, type
);
6129 /* Given ARG, a value of type (pointer or reference to a)*
6130 structure/union, extract the component named NAME from the ultimate
6131 target structure/union and return it as a value with its
6134 The routine searches for NAME among all members of the structure itself
6135 and (recursively) among all members of any wrapper members
6138 If NO_ERR, then simply return NULL in case of error, rather than
6142 ada_value_struct_elt (struct value
*arg
, char *name
, int no_err
)
6144 struct type
*t
, *t1
;
6148 t1
= t
= ada_check_typedef (value_type (arg
));
6149 if (TYPE_CODE (t
) == TYPE_CODE_REF
)
6151 t1
= TYPE_TARGET_TYPE (t
);
6154 t1
= ada_check_typedef (t1
);
6155 if (TYPE_CODE (t1
) == TYPE_CODE_PTR
)
6157 arg
= coerce_ref (arg
);
6162 while (TYPE_CODE (t
) == TYPE_CODE_PTR
)
6164 t1
= TYPE_TARGET_TYPE (t
);
6167 t1
= ada_check_typedef (t1
);
6168 if (TYPE_CODE (t1
) == TYPE_CODE_PTR
)
6170 arg
= value_ind (arg
);
6177 if (TYPE_CODE (t1
) != TYPE_CODE_STRUCT
&& TYPE_CODE (t1
) != TYPE_CODE_UNION
)
6181 v
= ada_search_struct_field (name
, arg
, 0, t
);
6184 int bit_offset
, bit_size
, byte_offset
;
6185 struct type
*field_type
;
6188 if (TYPE_CODE (t
) == TYPE_CODE_PTR
)
6189 address
= value_as_address (arg
);
6191 address
= unpack_pointer (t
, value_contents (arg
));
6193 t1
= ada_to_fixed_type (ada_get_base_type (t1
), NULL
, address
, NULL
, 1);
6194 if (find_struct_field (name
, t1
, 0,
6195 &field_type
, &byte_offset
, &bit_offset
,
6200 if (TYPE_CODE (t
) == TYPE_CODE_REF
)
6201 arg
= ada_coerce_ref (arg
);
6203 arg
= ada_value_ind (arg
);
6204 v
= ada_value_primitive_packed_val (arg
, NULL
, byte_offset
,
6205 bit_offset
, bit_size
,
6209 v
= value_at_lazy (field_type
, address
+ byte_offset
);
6213 if (v
!= NULL
|| no_err
)
6216 error (_("There is no member named %s."), name
);
6222 error (_("Attempt to extract a component of a value that is not a record."));
6225 /* Given a type TYPE, look up the type of the component of type named NAME.
6226 If DISPP is non-null, add its byte displacement from the beginning of a
6227 structure (pointed to by a value) of type TYPE to *DISPP (does not
6228 work for packed fields).
6230 Matches any field whose name has NAME as a prefix, possibly
6233 TYPE can be either a struct or union. If REFOK, TYPE may also
6234 be a (pointer or reference)+ to a struct or union, and the
6235 ultimate target type will be searched.
6237 Looks recursively into variant clauses and parent types.
6239 If NOERR is nonzero, return NULL if NAME is not suitably defined or
6240 TYPE is not a type of the right kind. */
6242 static struct type
*
6243 ada_lookup_struct_elt_type (struct type
*type
, char *name
, int refok
,
6244 int noerr
, int *dispp
)
6251 if (refok
&& type
!= NULL
)
6254 type
= ada_check_typedef (type
);
6255 if (TYPE_CODE (type
) != TYPE_CODE_PTR
6256 && TYPE_CODE (type
) != TYPE_CODE_REF
)
6258 type
= TYPE_TARGET_TYPE (type
);
6262 || (TYPE_CODE (type
) != TYPE_CODE_STRUCT
6263 && TYPE_CODE (type
) != TYPE_CODE_UNION
))
6269 target_terminal_ours ();
6270 gdb_flush (gdb_stdout
);
6272 error (_("Type (null) is not a structure or union type"));
6275 /* XXX: type_sprint */
6276 fprintf_unfiltered (gdb_stderr
, _("Type "));
6277 type_print (type
, "", gdb_stderr
, -1);
6278 error (_(" is not a structure or union type"));
6283 type
= to_static_fixed_type (type
);
6285 for (i
= 0; i
< TYPE_NFIELDS (type
); i
+= 1)
6287 char *t_field_name
= TYPE_FIELD_NAME (type
, i
);
6291 if (t_field_name
== NULL
)
6294 else if (field_name_match (t_field_name
, name
))
6297 *dispp
+= TYPE_FIELD_BITPOS (type
, i
) / 8;
6298 return ada_check_typedef (TYPE_FIELD_TYPE (type
, i
));
6301 else if (ada_is_wrapper_field (type
, i
))
6304 t
= ada_lookup_struct_elt_type (TYPE_FIELD_TYPE (type
, i
), name
,
6309 *dispp
+= disp
+ TYPE_FIELD_BITPOS (type
, i
) / 8;
6314 else if (ada_is_variant_part (type
, i
))
6317 struct type
*field_type
= ada_check_typedef (TYPE_FIELD_TYPE (type
, i
));
6319 for (j
= TYPE_NFIELDS (field_type
) - 1; j
>= 0; j
-= 1)
6321 /* FIXME pnh 2008/01/26: We check for a field that is
6322 NOT wrapped in a struct, since the compiler sometimes
6323 generates these for unchecked variant types. Revisit
6324 if the compiler changes this practice. */
6325 char *v_field_name
= TYPE_FIELD_NAME (field_type
, j
);
6327 if (v_field_name
!= NULL
6328 && field_name_match (v_field_name
, name
))
6329 t
= ada_check_typedef (TYPE_FIELD_TYPE (field_type
, j
));
6331 t
= ada_lookup_struct_elt_type (TYPE_FIELD_TYPE (field_type
, j
),
6337 *dispp
+= disp
+ TYPE_FIELD_BITPOS (type
, i
) / 8;
6348 target_terminal_ours ();
6349 gdb_flush (gdb_stdout
);
6352 /* XXX: type_sprint */
6353 fprintf_unfiltered (gdb_stderr
, _("Type "));
6354 type_print (type
, "", gdb_stderr
, -1);
6355 error (_(" has no component named <null>"));
6359 /* XXX: type_sprint */
6360 fprintf_unfiltered (gdb_stderr
, _("Type "));
6361 type_print (type
, "", gdb_stderr
, -1);
6362 error (_(" has no component named %s"), name
);
6369 /* Assuming that VAR_TYPE is the type of a variant part of a record (a union),
6370 within a value of type OUTER_TYPE, return true iff VAR_TYPE
6371 represents an unchecked union (that is, the variant part of a
6372 record that is named in an Unchecked_Union pragma). */
6375 is_unchecked_variant (struct type
*var_type
, struct type
*outer_type
)
6377 char *discrim_name
= ada_variant_discrim_name (var_type
);
6378 return (ada_lookup_struct_elt_type (outer_type
, discrim_name
, 0, 1, NULL
)
6383 /* Assuming that VAR_TYPE is the type of a variant part of a record (a union),
6384 within a value of type OUTER_TYPE that is stored in GDB at
6385 OUTER_VALADDR, determine which variant clause (field number in VAR_TYPE,
6386 numbering from 0) is applicable. Returns -1 if none are. */
6389 ada_which_variant_applies (struct type
*var_type
, struct type
*outer_type
,
6390 const gdb_byte
*outer_valaddr
)
6394 char *discrim_name
= ada_variant_discrim_name (var_type
);
6395 struct value
*outer
;
6396 struct value
*discrim
;
6397 LONGEST discrim_val
;
6399 outer
= value_from_contents_and_address (outer_type
, outer_valaddr
, 0);
6400 discrim
= ada_value_struct_elt (outer
, discrim_name
, 1);
6401 if (discrim
== NULL
)
6403 discrim_val
= value_as_long (discrim
);
6406 for (i
= 0; i
< TYPE_NFIELDS (var_type
); i
+= 1)
6408 if (ada_is_others_clause (var_type
, i
))
6410 else if (ada_in_variant (discrim_val
, var_type
, i
))
6414 return others_clause
;
6419 /* Dynamic-Sized Records */
6421 /* Strategy: The type ostensibly attached to a value with dynamic size
6422 (i.e., a size that is not statically recorded in the debugging
6423 data) does not accurately reflect the size or layout of the value.
6424 Our strategy is to convert these values to values with accurate,
6425 conventional types that are constructed on the fly. */
6427 /* There is a subtle and tricky problem here. In general, we cannot
6428 determine the size of dynamic records without its data. However,
6429 the 'struct value' data structure, which GDB uses to represent
6430 quantities in the inferior process (the target), requires the size
6431 of the type at the time of its allocation in order to reserve space
6432 for GDB's internal copy of the data. That's why the
6433 'to_fixed_xxx_type' routines take (target) addresses as parameters,
6434 rather than struct value*s.
6436 However, GDB's internal history variables ($1, $2, etc.) are
6437 struct value*s containing internal copies of the data that are not, in
6438 general, the same as the data at their corresponding addresses in
6439 the target. Fortunately, the types we give to these values are all
6440 conventional, fixed-size types (as per the strategy described
6441 above), so that we don't usually have to perform the
6442 'to_fixed_xxx_type' conversions to look at their values.
6443 Unfortunately, there is one exception: if one of the internal
6444 history variables is an array whose elements are unconstrained
6445 records, then we will need to create distinct fixed types for each
6446 element selected. */
6448 /* The upshot of all of this is that many routines take a (type, host
6449 address, target address) triple as arguments to represent a value.
6450 The host address, if non-null, is supposed to contain an internal
6451 copy of the relevant data; otherwise, the program is to consult the
6452 target at the target address. */
6454 /* Assuming that VAL0 represents a pointer value, the result of
6455 dereferencing it. Differs from value_ind in its treatment of
6456 dynamic-sized types. */
6459 ada_value_ind (struct value
*val0
)
6461 struct value
*val
= unwrap_value (value_ind (val0
));
6462 return ada_to_fixed_value (val
);
6465 /* The value resulting from dereferencing any "reference to"
6466 qualifiers on VAL0. */
6468 static struct value
*
6469 ada_coerce_ref (struct value
*val0
)
6471 if (TYPE_CODE (value_type (val0
)) == TYPE_CODE_REF
)
6473 struct value
*val
= val0
;
6474 val
= coerce_ref (val
);
6475 val
= unwrap_value (val
);
6476 return ada_to_fixed_value (val
);
6482 /* Return OFF rounded upward if necessary to a multiple of
6483 ALIGNMENT (a power of 2). */
6486 align_value (unsigned int off
, unsigned int alignment
)
6488 return (off
+ alignment
- 1) & ~(alignment
- 1);
6491 /* Return the bit alignment required for field #F of template type TYPE. */
6494 field_alignment (struct type
*type
, int f
)
6496 const char *name
= TYPE_FIELD_NAME (type
, f
);
6500 /* The field name should never be null, unless the debugging information
6501 is somehow malformed. In this case, we assume the field does not
6502 require any alignment. */
6506 len
= strlen (name
);
6508 if (!isdigit (name
[len
- 1]))
6511 if (isdigit (name
[len
- 2]))
6512 align_offset
= len
- 2;
6514 align_offset
= len
- 1;
6516 if (align_offset
< 7 || strncmp ("___XV", name
+ align_offset
- 6, 5) != 0)
6517 return TARGET_CHAR_BIT
;
6519 return atoi (name
+ align_offset
) * TARGET_CHAR_BIT
;
6522 /* Find a symbol named NAME. Ignores ambiguity. */
6525 ada_find_any_symbol (const char *name
)
6529 sym
= standard_lookup (name
, get_selected_block (NULL
), VAR_DOMAIN
);
6530 if (sym
!= NULL
&& SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
6533 sym
= standard_lookup (name
, NULL
, STRUCT_DOMAIN
);
6537 /* Find a type named NAME. Ignores ambiguity. */
6540 ada_find_any_type (const char *name
)
6542 struct symbol
*sym
= ada_find_any_symbol (name
);
6543 struct type
*type
= NULL
;
6546 type
= SYMBOL_TYPE (sym
);
6549 type
= language_lookup_primitive_type_by_name
6550 (language_def (language_ada
), current_gdbarch
, name
);
6555 /* Given NAME and an associated BLOCK, search all symbols for
6556 NAME suffixed with "___XR", which is the ``renaming'' symbol
6557 associated to NAME. Return this symbol if found, return
6561 ada_find_renaming_symbol (const char *name
, struct block
*block
)
6565 sym
= find_old_style_renaming_symbol (name
, block
);
6570 /* Not right yet. FIXME pnh 7/20/2007. */
6571 sym
= ada_find_any_symbol (name
);
6572 if (sym
!= NULL
&& strstr (SYMBOL_LINKAGE_NAME (sym
), "___XR") != NULL
)
6578 static struct symbol
*
6579 find_old_style_renaming_symbol (const char *name
, struct block
*block
)
6581 const struct symbol
*function_sym
= block_linkage_function (block
);
6584 if (function_sym
!= NULL
)
6586 /* If the symbol is defined inside a function, NAME is not fully
6587 qualified. This means we need to prepend the function name
6588 as well as adding the ``___XR'' suffix to build the name of
6589 the associated renaming symbol. */
6590 char *function_name
= SYMBOL_LINKAGE_NAME (function_sym
);
6591 /* Function names sometimes contain suffixes used
6592 for instance to qualify nested subprograms. When building
6593 the XR type name, we need to make sure that this suffix is
6594 not included. So do not include any suffix in the function
6595 name length below. */
6596 const int function_name_len
= ada_name_prefix_len (function_name
);
6597 const int rename_len
= function_name_len
+ 2 /* "__" */
6598 + strlen (name
) + 6 /* "___XR\0" */ ;
6600 /* Strip the suffix if necessary. */
6601 function_name
[function_name_len
] = '\0';
6603 /* Library-level functions are a special case, as GNAT adds
6604 a ``_ada_'' prefix to the function name to avoid namespace
6605 pollution. However, the renaming symbols themselves do not
6606 have this prefix, so we need to skip this prefix if present. */
6607 if (function_name_len
> 5 /* "_ada_" */
6608 && strstr (function_name
, "_ada_") == function_name
)
6609 function_name
= function_name
+ 5;
6611 rename
= (char *) alloca (rename_len
* sizeof (char));
6612 sprintf (rename
, "%s__%s___XR", function_name
, name
);
6616 const int rename_len
= strlen (name
) + 6;
6617 rename
= (char *) alloca (rename_len
* sizeof (char));
6618 sprintf (rename
, "%s___XR", name
);
6621 return ada_find_any_symbol (rename
);
6624 /* Because of GNAT encoding conventions, several GDB symbols may match a
6625 given type name. If the type denoted by TYPE0 is to be preferred to
6626 that of TYPE1 for purposes of type printing, return non-zero;
6627 otherwise return 0. */
6630 ada_prefer_type (struct type
*type0
, struct type
*type1
)
6634 else if (type0
== NULL
)
6636 else if (TYPE_CODE (type1
) == TYPE_CODE_VOID
)
6638 else if (TYPE_CODE (type0
) == TYPE_CODE_VOID
)
6640 else if (TYPE_NAME (type1
) == NULL
&& TYPE_NAME (type0
) != NULL
)
6642 else if (ada_is_packed_array_type (type0
))
6644 else if (ada_is_array_descriptor_type (type0
)
6645 && !ada_is_array_descriptor_type (type1
))
6649 const char *type0_name
= type_name_no_tag (type0
);
6650 const char *type1_name
= type_name_no_tag (type1
);
6652 if (type0_name
!= NULL
&& strstr (type0_name
, "___XR") != NULL
6653 && (type1_name
== NULL
|| strstr (type1_name
, "___XR") == NULL
))
6659 /* The name of TYPE, which is either its TYPE_NAME, or, if that is
6660 null, its TYPE_TAG_NAME. Null if TYPE is null. */
6663 ada_type_name (struct type
*type
)
6667 else if (TYPE_NAME (type
) != NULL
)
6668 return TYPE_NAME (type
);
6670 return TYPE_TAG_NAME (type
);
6673 /* Find a parallel type to TYPE whose name is formed by appending
6674 SUFFIX to the name of TYPE. */
6677 ada_find_parallel_type (struct type
*type
, const char *suffix
)
6680 static size_t name_len
= 0;
6682 char *typename
= ada_type_name (type
);
6684 if (typename
== NULL
)
6687 len
= strlen (typename
);
6689 GROW_VECT (name
, name_len
, len
+ strlen (suffix
) + 1);
6691 strcpy (name
, typename
);
6692 strcpy (name
+ len
, suffix
);
6694 return ada_find_any_type (name
);
6698 /* If TYPE is a variable-size record type, return the corresponding template
6699 type describing its fields. Otherwise, return NULL. */
6701 static struct type
*
6702 dynamic_template_type (struct type
*type
)
6704 type
= ada_check_typedef (type
);
6706 if (type
== NULL
|| TYPE_CODE (type
) != TYPE_CODE_STRUCT
6707 || ada_type_name (type
) == NULL
)
6711 int len
= strlen (ada_type_name (type
));
6712 if (len
> 6 && strcmp (ada_type_name (type
) + len
- 6, "___XVE") == 0)
6715 return ada_find_parallel_type (type
, "___XVE");
6719 /* Assuming that TEMPL_TYPE is a union or struct type, returns
6720 non-zero iff field FIELD_NUM of TEMPL_TYPE has dynamic size. */
6723 is_dynamic_field (struct type
*templ_type
, int field_num
)
6725 const char *name
= TYPE_FIELD_NAME (templ_type
, field_num
);
6727 && TYPE_CODE (TYPE_FIELD_TYPE (templ_type
, field_num
)) == TYPE_CODE_PTR
6728 && strstr (name
, "___XVL") != NULL
;
6731 /* The index of the variant field of TYPE, or -1 if TYPE does not
6732 represent a variant record type. */
6735 variant_field_index (struct type
*type
)
6739 if (type
== NULL
|| TYPE_CODE (type
) != TYPE_CODE_STRUCT
)
6742 for (f
= 0; f
< TYPE_NFIELDS (type
); f
+= 1)
6744 if (ada_is_variant_part (type
, f
))
6750 /* A record type with no fields. */
6752 static struct type
*
6753 empty_record (struct objfile
*objfile
)
6755 struct type
*type
= alloc_type (objfile
);
6756 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
6757 TYPE_NFIELDS (type
) = 0;
6758 TYPE_FIELDS (type
) = NULL
;
6759 INIT_CPLUS_SPECIFIC (type
);
6760 TYPE_NAME (type
) = "<empty>";
6761 TYPE_TAG_NAME (type
) = NULL
;
6762 TYPE_LENGTH (type
) = 0;
6766 /* An ordinary record type (with fixed-length fields) that describes
6767 the value of type TYPE at VALADDR or ADDRESS (see comments at
6768 the beginning of this section) VAL according to GNAT conventions.
6769 DVAL0 should describe the (portion of a) record that contains any
6770 necessary discriminants. It should be NULL if value_type (VAL) is
6771 an outer-level type (i.e., as opposed to a branch of a variant.) A
6772 variant field (unless unchecked) is replaced by a particular branch
6775 If not KEEP_DYNAMIC_FIELDS, then all fields whose position or
6776 length are not statically known are discarded. As a consequence,
6777 VALADDR, ADDRESS and DVAL0 are ignored.
6779 NOTE: Limitations: For now, we assume that dynamic fields and
6780 variants occupy whole numbers of bytes. However, they need not be
6784 ada_template_to_fixed_record_type_1 (struct type
*type
,
6785 const gdb_byte
*valaddr
,
6786 CORE_ADDR address
, struct value
*dval0
,
6787 int keep_dynamic_fields
)
6789 struct value
*mark
= value_mark ();
6792 int nfields
, bit_len
;
6795 int fld_bit_len
, bit_incr
;
6798 /* Compute the number of fields in this record type that are going
6799 to be processed: unless keep_dynamic_fields, this includes only
6800 fields whose position and length are static will be processed. */
6801 if (keep_dynamic_fields
)
6802 nfields
= TYPE_NFIELDS (type
);
6806 while (nfields
< TYPE_NFIELDS (type
)
6807 && !ada_is_variant_part (type
, nfields
)
6808 && !is_dynamic_field (type
, nfields
))
6812 rtype
= alloc_type (TYPE_OBJFILE (type
));
6813 TYPE_CODE (rtype
) = TYPE_CODE_STRUCT
;
6814 INIT_CPLUS_SPECIFIC (rtype
);
6815 TYPE_NFIELDS (rtype
) = nfields
;
6816 TYPE_FIELDS (rtype
) = (struct field
*)
6817 TYPE_ALLOC (rtype
, nfields
* sizeof (struct field
));
6818 memset (TYPE_FIELDS (rtype
), 0, sizeof (struct field
) * nfields
);
6819 TYPE_NAME (rtype
) = ada_type_name (type
);
6820 TYPE_TAG_NAME (rtype
) = NULL
;
6821 TYPE_FIXED_INSTANCE (rtype
) = 1;
6827 for (f
= 0; f
< nfields
; f
+= 1)
6829 off
= align_value (off
, field_alignment (type
, f
))
6830 + TYPE_FIELD_BITPOS (type
, f
);
6831 TYPE_FIELD_BITPOS (rtype
, f
) = off
;
6832 TYPE_FIELD_BITSIZE (rtype
, f
) = 0;
6834 if (ada_is_variant_part (type
, f
))
6837 fld_bit_len
= bit_incr
= 0;
6839 else if (is_dynamic_field (type
, f
))
6843 /* rtype's length is computed based on the run-time
6844 value of discriminants. If the discriminants are not
6845 initialized, the type size may be completely bogus and
6846 GDB may fail to allocate a value for it. So check the
6847 size first before creating the value. */
6849 dval
= value_from_contents_and_address (rtype
, valaddr
, address
);
6854 /* Get the fixed type of the field. Note that, in this case, we
6855 do not want to get the real type out of the tag: if the current
6856 field is the parent part of a tagged record, we will get the
6857 tag of the object. Clearly wrong: the real type of the parent
6858 is not the real type of the child. We would end up in an infinite
6860 TYPE_FIELD_TYPE (rtype
, f
) =
6863 (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
, f
))),
6864 cond_offset_host (valaddr
, off
/ TARGET_CHAR_BIT
),
6865 cond_offset_target (address
, off
/ TARGET_CHAR_BIT
), dval
, 0);
6866 TYPE_FIELD_NAME (rtype
, f
) = TYPE_FIELD_NAME (type
, f
);
6867 bit_incr
= fld_bit_len
=
6868 TYPE_LENGTH (TYPE_FIELD_TYPE (rtype
, f
)) * TARGET_CHAR_BIT
;
6872 TYPE_FIELD_TYPE (rtype
, f
) = TYPE_FIELD_TYPE (type
, f
);
6873 TYPE_FIELD_NAME (rtype
, f
) = TYPE_FIELD_NAME (type
, f
);
6874 if (TYPE_FIELD_BITSIZE (type
, f
) > 0)
6875 bit_incr
= fld_bit_len
=
6876 TYPE_FIELD_BITSIZE (rtype
, f
) = TYPE_FIELD_BITSIZE (type
, f
);
6878 bit_incr
= fld_bit_len
=
6879 TYPE_LENGTH (TYPE_FIELD_TYPE (type
, f
)) * TARGET_CHAR_BIT
;
6881 if (off
+ fld_bit_len
> bit_len
)
6882 bit_len
= off
+ fld_bit_len
;
6884 TYPE_LENGTH (rtype
) =
6885 align_value (bit_len
, TARGET_CHAR_BIT
) / TARGET_CHAR_BIT
;
6888 /* We handle the variant part, if any, at the end because of certain
6889 odd cases in which it is re-ordered so as NOT to be the last field of
6890 the record. This can happen in the presence of representation
6892 if (variant_field
>= 0)
6894 struct type
*branch_type
;
6896 off
= TYPE_FIELD_BITPOS (rtype
, variant_field
);
6899 dval
= value_from_contents_and_address (rtype
, valaddr
, address
);
6904 to_fixed_variant_branch_type
6905 (TYPE_FIELD_TYPE (type
, variant_field
),
6906 cond_offset_host (valaddr
, off
/ TARGET_CHAR_BIT
),
6907 cond_offset_target (address
, off
/ TARGET_CHAR_BIT
), dval
);
6908 if (branch_type
== NULL
)
6910 for (f
= variant_field
+ 1; f
< TYPE_NFIELDS (rtype
); f
+= 1)
6911 TYPE_FIELDS (rtype
)[f
- 1] = TYPE_FIELDS (rtype
)[f
];
6912 TYPE_NFIELDS (rtype
) -= 1;
6916 TYPE_FIELD_TYPE (rtype
, variant_field
) = branch_type
;
6917 TYPE_FIELD_NAME (rtype
, variant_field
) = "S";
6919 TYPE_LENGTH (TYPE_FIELD_TYPE (rtype
, variant_field
)) *
6921 if (off
+ fld_bit_len
> bit_len
)
6922 bit_len
= off
+ fld_bit_len
;
6923 TYPE_LENGTH (rtype
) =
6924 align_value (bit_len
, TARGET_CHAR_BIT
) / TARGET_CHAR_BIT
;
6928 /* According to exp_dbug.ads, the size of TYPE for variable-size records
6929 should contain the alignment of that record, which should be a strictly
6930 positive value. If null or negative, then something is wrong, most
6931 probably in the debug info. In that case, we don't round up the size
6932 of the resulting type. If this record is not part of another structure,
6933 the current RTYPE length might be good enough for our purposes. */
6934 if (TYPE_LENGTH (type
) <= 0)
6936 if (TYPE_NAME (rtype
))
6937 warning (_("Invalid type size for `%s' detected: %d."),
6938 TYPE_NAME (rtype
), TYPE_LENGTH (type
));
6940 warning (_("Invalid type size for <unnamed> detected: %d."),
6941 TYPE_LENGTH (type
));
6945 TYPE_LENGTH (rtype
) = align_value (TYPE_LENGTH (rtype
),
6946 TYPE_LENGTH (type
));
6949 value_free_to_mark (mark
);
6950 if (TYPE_LENGTH (rtype
) > varsize_limit
)
6951 error (_("record type with dynamic size is larger than varsize-limit"));
6955 /* As for ada_template_to_fixed_record_type_1 with KEEP_DYNAMIC_FIELDS
6958 static struct type
*
6959 template_to_fixed_record_type (struct type
*type
, const gdb_byte
*valaddr
,
6960 CORE_ADDR address
, struct value
*dval0
)
6962 return ada_template_to_fixed_record_type_1 (type
, valaddr
,
6966 /* An ordinary record type in which ___XVL-convention fields and
6967 ___XVU- and ___XVN-convention field types in TYPE0 are replaced with
6968 static approximations, containing all possible fields. Uses
6969 no runtime values. Useless for use in values, but that's OK,
6970 since the results are used only for type determinations. Works on both
6971 structs and unions. Representation note: to save space, we memorize
6972 the result of this function in the TYPE_TARGET_TYPE of the
6975 static struct type
*
6976 template_to_static_fixed_type (struct type
*type0
)
6982 if (TYPE_TARGET_TYPE (type0
) != NULL
)
6983 return TYPE_TARGET_TYPE (type0
);
6985 nfields
= TYPE_NFIELDS (type0
);
6988 for (f
= 0; f
< nfields
; f
+= 1)
6990 struct type
*field_type
= ada_check_typedef (TYPE_FIELD_TYPE (type0
, f
));
6991 struct type
*new_type
;
6993 if (is_dynamic_field (type0
, f
))
6994 new_type
= to_static_fixed_type (TYPE_TARGET_TYPE (field_type
));
6996 new_type
= static_unwrap_type (field_type
);
6997 if (type
== type0
&& new_type
!= field_type
)
6999 TYPE_TARGET_TYPE (type0
) = type
= alloc_type (TYPE_OBJFILE (type0
));
7000 TYPE_CODE (type
) = TYPE_CODE (type0
);
7001 INIT_CPLUS_SPECIFIC (type
);
7002 TYPE_NFIELDS (type
) = nfields
;
7003 TYPE_FIELDS (type
) = (struct field
*)
7004 TYPE_ALLOC (type
, nfields
* sizeof (struct field
));
7005 memcpy (TYPE_FIELDS (type
), TYPE_FIELDS (type0
),
7006 sizeof (struct field
) * nfields
);
7007 TYPE_NAME (type
) = ada_type_name (type0
);
7008 TYPE_TAG_NAME (type
) = NULL
;
7009 TYPE_FIXED_INSTANCE (type
) = 1;
7010 TYPE_LENGTH (type
) = 0;
7012 TYPE_FIELD_TYPE (type
, f
) = new_type
;
7013 TYPE_FIELD_NAME (type
, f
) = TYPE_FIELD_NAME (type0
, f
);
7018 /* Given an object of type TYPE whose contents are at VALADDR and
7019 whose address in memory is ADDRESS, returns a revision of TYPE,
7020 which should be a non-dynamic-sized record, in which the variant
7021 part, if any, is replaced with the appropriate branch. Looks
7022 for discriminant values in DVAL0, which can be NULL if the record
7023 contains the necessary discriminant values. */
7025 static struct type
*
7026 to_record_with_fixed_variant_part (struct type
*type
, const gdb_byte
*valaddr
,
7027 CORE_ADDR address
, struct value
*dval0
)
7029 struct value
*mark
= value_mark ();
7032 struct type
*branch_type
;
7033 int nfields
= TYPE_NFIELDS (type
);
7034 int variant_field
= variant_field_index (type
);
7036 if (variant_field
== -1)
7040 dval
= value_from_contents_and_address (type
, valaddr
, address
);
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
) =
7049 (struct field
*) TYPE_ALLOC (rtype
, nfields
* sizeof (struct field
));
7050 memcpy (TYPE_FIELDS (rtype
), TYPE_FIELDS (type
),
7051 sizeof (struct field
) * nfields
);
7052 TYPE_NAME (rtype
) = ada_type_name (type
);
7053 TYPE_TAG_NAME (rtype
) = NULL
;
7054 TYPE_FIXED_INSTANCE (rtype
) = 1;
7055 TYPE_LENGTH (rtype
) = TYPE_LENGTH (type
);
7057 branch_type
= to_fixed_variant_branch_type
7058 (TYPE_FIELD_TYPE (type
, variant_field
),
7059 cond_offset_host (valaddr
,
7060 TYPE_FIELD_BITPOS (type
, variant_field
)
7062 cond_offset_target (address
,
7063 TYPE_FIELD_BITPOS (type
, variant_field
)
7064 / TARGET_CHAR_BIT
), dval
);
7065 if (branch_type
== NULL
)
7068 for (f
= variant_field
+ 1; f
< nfields
; f
+= 1)
7069 TYPE_FIELDS (rtype
)[f
- 1] = TYPE_FIELDS (rtype
)[f
];
7070 TYPE_NFIELDS (rtype
) -= 1;
7074 TYPE_FIELD_TYPE (rtype
, variant_field
) = branch_type
;
7075 TYPE_FIELD_NAME (rtype
, variant_field
) = "S";
7076 TYPE_FIELD_BITSIZE (rtype
, variant_field
) = 0;
7077 TYPE_LENGTH (rtype
) += TYPE_LENGTH (branch_type
);
7079 TYPE_LENGTH (rtype
) -= TYPE_LENGTH (TYPE_FIELD_TYPE (type
, variant_field
));
7081 value_free_to_mark (mark
);
7085 /* An ordinary record type (with fixed-length fields) that describes
7086 the value at (TYPE0, VALADDR, ADDRESS) [see explanation at
7087 beginning of this section]. Any necessary discriminants' values
7088 should be in DVAL, a record value; it may be NULL if the object
7089 at ADDR itself contains any necessary discriminant values.
7090 Additionally, VALADDR and ADDRESS may also be NULL if no discriminant
7091 values from the record are needed. Except in the case that DVAL,
7092 VALADDR, and ADDRESS are all 0 or NULL, a variant field (unless
7093 unchecked) is replaced by a particular branch of the variant.
7095 NOTE: the case in which DVAL and VALADDR are NULL and ADDRESS is 0
7096 is questionable and may be removed. It can arise during the
7097 processing of an unconstrained-array-of-record type where all the
7098 variant branches have exactly the same size. This is because in
7099 such cases, the compiler does not bother to use the XVS convention
7100 when encoding the record. I am currently dubious of this
7101 shortcut and suspect the compiler should be altered. FIXME. */
7103 static struct type
*
7104 to_fixed_record_type (struct type
*type0
, const gdb_byte
*valaddr
,
7105 CORE_ADDR address
, struct value
*dval
)
7107 struct type
*templ_type
;
7109 if (TYPE_FIXED_INSTANCE (type0
))
7112 templ_type
= dynamic_template_type (type0
);
7114 if (templ_type
!= NULL
)
7115 return template_to_fixed_record_type (templ_type
, valaddr
, address
, dval
);
7116 else if (variant_field_index (type0
) >= 0)
7118 if (dval
== NULL
&& valaddr
== NULL
&& address
== 0)
7120 return to_record_with_fixed_variant_part (type0
, valaddr
, address
,
7125 TYPE_FIXED_INSTANCE (type0
) = 1;
7131 /* An ordinary record type (with fixed-length fields) that describes
7132 the value at (VAR_TYPE0, VALADDR, ADDRESS), where VAR_TYPE0 is a
7133 union type. Any necessary discriminants' values should be in DVAL,
7134 a record value. That is, this routine selects the appropriate
7135 branch of the union at ADDR according to the discriminant value
7136 indicated in the union's type name. Returns VAR_TYPE0 itself if
7137 it represents a variant subject to a pragma Unchecked_Union. */
7139 static struct type
*
7140 to_fixed_variant_branch_type (struct type
*var_type0
, const gdb_byte
*valaddr
,
7141 CORE_ADDR address
, struct value
*dval
)
7144 struct type
*templ_type
;
7145 struct type
*var_type
;
7147 if (TYPE_CODE (var_type0
) == TYPE_CODE_PTR
)
7148 var_type
= TYPE_TARGET_TYPE (var_type0
);
7150 var_type
= var_type0
;
7152 templ_type
= ada_find_parallel_type (var_type
, "___XVU");
7154 if (templ_type
!= NULL
)
7155 var_type
= templ_type
;
7157 if (is_unchecked_variant (var_type
, value_type (dval
)))
7160 ada_which_variant_applies (var_type
,
7161 value_type (dval
), value_contents (dval
));
7164 return empty_record (TYPE_OBJFILE (var_type
));
7165 else if (is_dynamic_field (var_type
, which
))
7166 return to_fixed_record_type
7167 (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (var_type
, which
)),
7168 valaddr
, address
, dval
);
7169 else if (variant_field_index (TYPE_FIELD_TYPE (var_type
, which
)) >= 0)
7171 to_fixed_record_type
7172 (TYPE_FIELD_TYPE (var_type
, which
), valaddr
, address
, dval
);
7174 return TYPE_FIELD_TYPE (var_type
, which
);
7177 /* Assuming that TYPE0 is an array type describing the type of a value
7178 at ADDR, and that DVAL describes a record containing any
7179 discriminants used in TYPE0, returns a type for the value that
7180 contains no dynamic components (that is, no components whose sizes
7181 are determined by run-time quantities). Unless IGNORE_TOO_BIG is
7182 true, gives an error message if the resulting type's size is over
7185 static struct type
*
7186 to_fixed_array_type (struct type
*type0
, struct value
*dval
,
7189 struct type
*index_type_desc
;
7190 struct type
*result
;
7192 if (ada_is_packed_array_type (type0
) /* revisit? */
7193 || TYPE_FIXED_INSTANCE (type0
))
7196 index_type_desc
= ada_find_parallel_type (type0
, "___XA");
7197 if (index_type_desc
== NULL
)
7199 struct type
*elt_type0
= ada_check_typedef (TYPE_TARGET_TYPE (type0
));
7200 /* NOTE: elt_type---the fixed version of elt_type0---should never
7201 depend on the contents of the array in properly constructed
7203 /* Create a fixed version of the array element type.
7204 We're not providing the address of an element here,
7205 and thus the actual object value cannot be inspected to do
7206 the conversion. This should not be a problem, since arrays of
7207 unconstrained objects are not allowed. In particular, all
7208 the elements of an array of a tagged type should all be of
7209 the same type specified in the debugging info. No need to
7210 consult the object tag. */
7211 struct type
*elt_type
= ada_to_fixed_type (elt_type0
, 0, 0, dval
, 1);
7213 if (elt_type0
== elt_type
)
7216 result
= create_array_type (alloc_type (TYPE_OBJFILE (type0
)),
7217 elt_type
, TYPE_INDEX_TYPE (type0
));
7222 struct type
*elt_type0
;
7225 for (i
= TYPE_NFIELDS (index_type_desc
); i
> 0; i
-= 1)
7226 elt_type0
= TYPE_TARGET_TYPE (elt_type0
);
7228 /* NOTE: result---the fixed version of elt_type0---should never
7229 depend on the contents of the array in properly constructed
7231 /* Create a fixed version of the array element type.
7232 We're not providing the address of an element here,
7233 and thus the actual object value cannot be inspected to do
7234 the conversion. This should not be a problem, since arrays of
7235 unconstrained objects are not allowed. In particular, all
7236 the elements of an array of a tagged type should all be of
7237 the same type specified in the debugging info. No need to
7238 consult the object tag. */
7240 ada_to_fixed_type (ada_check_typedef (elt_type0
), 0, 0, dval
, 1);
7241 for (i
= TYPE_NFIELDS (index_type_desc
) - 1; i
>= 0; i
-= 1)
7243 struct type
*range_type
=
7244 to_fixed_range_type (TYPE_FIELD_NAME (index_type_desc
, i
),
7245 dval
, TYPE_OBJFILE (type0
));
7246 result
= create_array_type (alloc_type (TYPE_OBJFILE (type0
)),
7247 result
, range_type
);
7249 if (!ignore_too_big
&& TYPE_LENGTH (result
) > varsize_limit
)
7250 error (_("array type with dynamic size is larger than varsize-limit"));
7253 TYPE_FIXED_INSTANCE (result
) = 1;
7258 /* A standard type (containing no dynamically sized components)
7259 corresponding to TYPE for the value (TYPE, VALADDR, ADDRESS)
7260 DVAL describes a record containing any discriminants used in TYPE0,
7261 and may be NULL if there are none, or if the object of type TYPE at
7262 ADDRESS or in VALADDR contains these discriminants.
7264 If CHECK_TAG is not null, in the case of tagged types, this function
7265 attempts to locate the object's tag and use it to compute the actual
7266 type. However, when ADDRESS is null, we cannot use it to determine the
7267 location of the tag, and therefore compute the tagged type's actual type.
7268 So we return the tagged type without consulting the tag. */
7270 static struct type
*
7271 ada_to_fixed_type_1 (struct type
*type
, const gdb_byte
*valaddr
,
7272 CORE_ADDR address
, struct value
*dval
, int check_tag
)
7274 type
= ada_check_typedef (type
);
7275 switch (TYPE_CODE (type
))
7279 case TYPE_CODE_STRUCT
:
7281 struct type
*static_type
= to_static_fixed_type (type
);
7282 struct type
*fixed_record_type
=
7283 to_fixed_record_type (type
, valaddr
, address
, NULL
);
7284 /* If STATIC_TYPE is a tagged type and we know the object's address,
7285 then we can determine its tag, and compute the object's actual
7286 type from there. Note that we have to use the fixed record
7287 type (the parent part of the record may have dynamic fields
7288 and the way the location of _tag is expressed may depend on
7291 if (check_tag
&& address
!= 0 && ada_is_tagged_type (static_type
, 0))
7293 struct type
*real_type
=
7294 type_from_tag (value_tag_from_contents_and_address
7298 if (real_type
!= NULL
)
7299 return to_fixed_record_type (real_type
, valaddr
, address
, NULL
);
7302 /* Check to see if there is a parallel ___XVZ variable.
7303 If there is, then it provides the actual size of our type. */
7304 else if (ada_type_name (fixed_record_type
) != NULL
)
7306 char *name
= ada_type_name (fixed_record_type
);
7307 char *xvz_name
= alloca (strlen (name
) + 7 /* "___XVZ\0" */);
7311 sprintf (xvz_name
, "%s___XVZ", name
);
7312 size
= get_int_var_value (xvz_name
, &xvz_found
);
7313 if (xvz_found
&& TYPE_LENGTH (fixed_record_type
) != size
)
7315 fixed_record_type
= copy_type (fixed_record_type
);
7316 TYPE_LENGTH (fixed_record_type
) = size
;
7318 /* The FIXED_RECORD_TYPE may have be a stub. We have
7319 observed this when the debugging info is STABS, and
7320 apparently it is something that is hard to fix.
7322 In practice, we don't need the actual type definition
7323 at all, because the presence of the XVZ variable allows us
7324 to assume that there must be a XVS type as well, which we
7325 should be able to use later, when we need the actual type
7328 In the meantime, pretend that the "fixed" type we are
7329 returning is NOT a stub, because this can cause trouble
7330 when using this type to create new types targeting it.
7331 Indeed, the associated creation routines often check
7332 whether the target type is a stub and will try to replace
7333 it, thus using a type with the wrong size. This, in turn,
7334 might cause the new type to have the wrong size too.
7335 Consider the case of an array, for instance, where the size
7336 of the array is computed from the number of elements in
7337 our array multiplied by the size of its element. */
7338 TYPE_STUB (fixed_record_type
) = 0;
7341 return fixed_record_type
;
7343 case TYPE_CODE_ARRAY
:
7344 return to_fixed_array_type (type
, dval
, 1);
7345 case TYPE_CODE_UNION
:
7349 return to_fixed_variant_branch_type (type
, valaddr
, address
, dval
);
7353 /* The same as ada_to_fixed_type_1, except that it preserves the type
7354 if it is a TYPE_CODE_TYPEDEF of a type that is already fixed.
7355 ada_to_fixed_type_1 would return the type referenced by TYPE. */
7358 ada_to_fixed_type (struct type
*type
, const gdb_byte
*valaddr
,
7359 CORE_ADDR address
, struct value
*dval
, int check_tag
)
7362 struct type
*fixed_type
=
7363 ada_to_fixed_type_1 (type
, valaddr
, address
, dval
, check_tag
);
7365 if (TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
7366 && TYPE_TARGET_TYPE (type
) == fixed_type
)
7372 /* A standard (static-sized) type corresponding as well as possible to
7373 TYPE0, but based on no runtime data. */
7375 static struct type
*
7376 to_static_fixed_type (struct type
*type0
)
7383 if (TYPE_FIXED_INSTANCE (type0
))
7386 type0
= ada_check_typedef (type0
);
7388 switch (TYPE_CODE (type0
))
7392 case TYPE_CODE_STRUCT
:
7393 type
= dynamic_template_type (type0
);
7395 return template_to_static_fixed_type (type
);
7397 return template_to_static_fixed_type (type0
);
7398 case TYPE_CODE_UNION
:
7399 type
= ada_find_parallel_type (type0
, "___XVU");
7401 return template_to_static_fixed_type (type
);
7403 return template_to_static_fixed_type (type0
);
7407 /* A static approximation of TYPE with all type wrappers removed. */
7409 static struct type
*
7410 static_unwrap_type (struct type
*type
)
7412 if (ada_is_aligner_type (type
))
7414 struct type
*type1
= TYPE_FIELD_TYPE (ada_check_typedef (type
), 0);
7415 if (ada_type_name (type1
) == NULL
)
7416 TYPE_NAME (type1
) = ada_type_name (type
);
7418 return static_unwrap_type (type1
);
7422 struct type
*raw_real_type
= ada_get_base_type (type
);
7423 if (raw_real_type
== type
)
7426 return to_static_fixed_type (raw_real_type
);
7430 /* In some cases, incomplete and private types require
7431 cross-references that are not resolved as records (for example,
7433 type FooP is access Foo;
7435 type Foo is array ...;
7436 ). In these cases, since there is no mechanism for producing
7437 cross-references to such types, we instead substitute for FooP a
7438 stub enumeration type that is nowhere resolved, and whose tag is
7439 the name of the actual type. Call these types "non-record stubs". */
7441 /* A type equivalent to TYPE that is not a non-record stub, if one
7442 exists, otherwise TYPE. */
7445 ada_check_typedef (struct type
*type
)
7450 CHECK_TYPEDEF (type
);
7451 if (type
== NULL
|| TYPE_CODE (type
) != TYPE_CODE_ENUM
7452 || !TYPE_STUB (type
)
7453 || TYPE_TAG_NAME (type
) == NULL
)
7457 char *name
= TYPE_TAG_NAME (type
);
7458 struct type
*type1
= ada_find_any_type (name
);
7459 return (type1
== NULL
) ? type
: type1
;
7463 /* A value representing the data at VALADDR/ADDRESS as described by
7464 type TYPE0, but with a standard (static-sized) type that correctly
7465 describes it. If VAL0 is not NULL and TYPE0 already is a standard
7466 type, then return VAL0 [this feature is simply to avoid redundant
7467 creation of struct values]. */
7469 static struct value
*
7470 ada_to_fixed_value_create (struct type
*type0
, CORE_ADDR address
,
7473 struct type
*type
= ada_to_fixed_type (type0
, 0, address
, NULL
, 1);
7474 if (type
== type0
&& val0
!= NULL
)
7477 return value_from_contents_and_address (type
, 0, address
);
7480 /* A value representing VAL, but with a standard (static-sized) type
7481 that correctly describes it. Does not necessarily create a new
7484 static struct value
*
7485 ada_to_fixed_value (struct value
*val
)
7487 return ada_to_fixed_value_create (value_type (val
),
7488 VALUE_ADDRESS (val
) + value_offset (val
),
7492 /* A value representing VAL, but with a standard (static-sized) type
7493 chosen to approximate the real type of VAL as well as possible, but
7494 without consulting any runtime values. For Ada dynamic-sized
7495 types, therefore, the type of the result is likely to be inaccurate. */
7497 static struct value
*
7498 ada_to_static_fixed_value (struct value
*val
)
7501 to_static_fixed_type (static_unwrap_type (value_type (val
)));
7502 if (type
== value_type (val
))
7505 return coerce_unspec_val_to_type (val
, type
);
7511 /* Table mapping attribute numbers to names.
7512 NOTE: Keep up to date with enum ada_attribute definition in ada-lang.h. */
7514 static const char *attribute_names
[] = {
7532 ada_attribute_name (enum exp_opcode n
)
7534 if (n
>= OP_ATR_FIRST
&& n
<= (int) OP_ATR_VAL
)
7535 return attribute_names
[n
- OP_ATR_FIRST
+ 1];
7537 return attribute_names
[0];
7540 /* Evaluate the 'POS attribute applied to ARG. */
7543 pos_atr (struct value
*arg
)
7545 struct value
*val
= coerce_ref (arg
);
7546 struct type
*type
= value_type (val
);
7548 if (!discrete_type_p (type
))
7549 error (_("'POS only defined on discrete types"));
7551 if (TYPE_CODE (type
) == TYPE_CODE_ENUM
)
7554 LONGEST v
= value_as_long (val
);
7556 for (i
= 0; i
< TYPE_NFIELDS (type
); i
+= 1)
7558 if (v
== TYPE_FIELD_BITPOS (type
, i
))
7561 error (_("enumeration value is invalid: can't find 'POS"));
7564 return value_as_long (val
);
7567 static struct value
*
7568 value_pos_atr (struct type
*type
, struct value
*arg
)
7570 return value_from_longest (type
, pos_atr (arg
));
7573 /* Evaluate the TYPE'VAL attribute applied to ARG. */
7575 static struct value
*
7576 value_val_atr (struct type
*type
, struct value
*arg
)
7578 if (!discrete_type_p (type
))
7579 error (_("'VAL only defined on discrete types"));
7580 if (!integer_type_p (value_type (arg
)))
7581 error (_("'VAL requires integral argument"));
7583 if (TYPE_CODE (type
) == TYPE_CODE_ENUM
)
7585 long pos
= value_as_long (arg
);
7586 if (pos
< 0 || pos
>= TYPE_NFIELDS (type
))
7587 error (_("argument to 'VAL out of range"));
7588 return value_from_longest (type
, TYPE_FIELD_BITPOS (type
, pos
));
7591 return value_from_longest (type
, value_as_long (arg
));
7597 /* True if TYPE appears to be an Ada character type.
7598 [At the moment, this is true only for Character and Wide_Character;
7599 It is a heuristic test that could stand improvement]. */
7602 ada_is_character_type (struct type
*type
)
7606 /* If the type code says it's a character, then assume it really is,
7607 and don't check any further. */
7608 if (TYPE_CODE (type
) == TYPE_CODE_CHAR
)
7611 /* Otherwise, assume it's a character type iff it is a discrete type
7612 with a known character type name. */
7613 name
= ada_type_name (type
);
7614 return (name
!= NULL
7615 && (TYPE_CODE (type
) == TYPE_CODE_INT
7616 || TYPE_CODE (type
) == TYPE_CODE_RANGE
)
7617 && (strcmp (name
, "character") == 0
7618 || strcmp (name
, "wide_character") == 0
7619 || strcmp (name
, "wide_wide_character") == 0
7620 || strcmp (name
, "unsigned char") == 0));
7623 /* True if TYPE appears to be an Ada string type. */
7626 ada_is_string_type (struct type
*type
)
7628 type
= ada_check_typedef (type
);
7630 && TYPE_CODE (type
) != TYPE_CODE_PTR
7631 && (ada_is_simple_array_type (type
)
7632 || ada_is_array_descriptor_type (type
))
7633 && ada_array_arity (type
) == 1)
7635 struct type
*elttype
= ada_array_element_type (type
, 1);
7637 return ada_is_character_type (elttype
);
7644 /* True if TYPE is a struct type introduced by the compiler to force the
7645 alignment of a value. Such types have a single field with a
7646 distinctive name. */
7649 ada_is_aligner_type (struct type
*type
)
7651 type
= ada_check_typedef (type
);
7653 /* If we can find a parallel XVS type, then the XVS type should
7654 be used instead of this type. And hence, this is not an aligner
7656 if (ada_find_parallel_type (type
, "___XVS") != NULL
)
7659 return (TYPE_CODE (type
) == TYPE_CODE_STRUCT
7660 && TYPE_NFIELDS (type
) == 1
7661 && strcmp (TYPE_FIELD_NAME (type
, 0), "F") == 0);
7664 /* If there is an ___XVS-convention type parallel to SUBTYPE, return
7665 the parallel type. */
7668 ada_get_base_type (struct type
*raw_type
)
7670 struct type
*real_type_namer
;
7671 struct type
*raw_real_type
;
7673 if (raw_type
== NULL
|| TYPE_CODE (raw_type
) != TYPE_CODE_STRUCT
)
7676 real_type_namer
= ada_find_parallel_type (raw_type
, "___XVS");
7677 if (real_type_namer
== NULL
7678 || TYPE_CODE (real_type_namer
) != TYPE_CODE_STRUCT
7679 || TYPE_NFIELDS (real_type_namer
) != 1)
7682 raw_real_type
= ada_find_any_type (TYPE_FIELD_NAME (real_type_namer
, 0));
7683 if (raw_real_type
== NULL
)
7686 return raw_real_type
;
7689 /* The type of value designated by TYPE, with all aligners removed. */
7692 ada_aligned_type (struct type
*type
)
7694 if (ada_is_aligner_type (type
))
7695 return ada_aligned_type (TYPE_FIELD_TYPE (type
, 0));
7697 return ada_get_base_type (type
);
7701 /* The address of the aligned value in an object at address VALADDR
7702 having type TYPE. Assumes ada_is_aligner_type (TYPE). */
7705 ada_aligned_value_addr (struct type
*type
, const gdb_byte
*valaddr
)
7707 if (ada_is_aligner_type (type
))
7708 return ada_aligned_value_addr (TYPE_FIELD_TYPE (type
, 0),
7710 TYPE_FIELD_BITPOS (type
,
7711 0) / TARGET_CHAR_BIT
);
7718 /* The printed representation of an enumeration literal with encoded
7719 name NAME. The value is good to the next call of ada_enum_name. */
7721 ada_enum_name (const char *name
)
7723 static char *result
;
7724 static size_t result_len
= 0;
7727 /* First, unqualify the enumeration name:
7728 1. Search for the last '.' character. If we find one, then skip
7729 all the preceeding characters, the unqualified name starts
7730 right after that dot.
7731 2. Otherwise, we may be debugging on a target where the compiler
7732 translates dots into "__". Search forward for double underscores,
7733 but stop searching when we hit an overloading suffix, which is
7734 of the form "__" followed by digits. */
7736 tmp
= strrchr (name
, '.');
7741 while ((tmp
= strstr (name
, "__")) != NULL
)
7743 if (isdigit (tmp
[2]))
7753 if (name
[1] == 'U' || name
[1] == 'W')
7755 if (sscanf (name
+ 2, "%x", &v
) != 1)
7761 GROW_VECT (result
, result_len
, 16);
7762 if (isascii (v
) && isprint (v
))
7763 sprintf (result
, "'%c'", v
);
7764 else if (name
[1] == 'U')
7765 sprintf (result
, "[\"%02x\"]", v
);
7767 sprintf (result
, "[\"%04x\"]", v
);
7773 tmp
= strstr (name
, "__");
7775 tmp
= strstr (name
, "$");
7778 GROW_VECT (result
, result_len
, tmp
- name
+ 1);
7779 strncpy (result
, name
, tmp
- name
);
7780 result
[tmp
- name
] = '\0';
7788 static struct value
*
7789 evaluate_subexp (struct type
*expect_type
, struct expression
*exp
, int *pos
,
7792 return (*exp
->language_defn
->la_exp_desc
->evaluate_exp
)
7793 (expect_type
, exp
, pos
, noside
);
7796 /* Evaluate the subexpression of EXP starting at *POS as for
7797 evaluate_type, updating *POS to point just past the evaluated
7800 static struct value
*
7801 evaluate_subexp_type (struct expression
*exp
, int *pos
)
7803 return (*exp
->language_defn
->la_exp_desc
->evaluate_exp
)
7804 (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
7807 /* If VAL is wrapped in an aligner or subtype wrapper, return the
7810 static struct value
*
7811 unwrap_value (struct value
*val
)
7813 struct type
*type
= ada_check_typedef (value_type (val
));
7814 if (ada_is_aligner_type (type
))
7816 struct value
*v
= ada_value_struct_elt (val
, "F", 0);
7817 struct type
*val_type
= ada_check_typedef (value_type (v
));
7818 if (ada_type_name (val_type
) == NULL
)
7819 TYPE_NAME (val_type
) = ada_type_name (type
);
7821 return unwrap_value (v
);
7825 struct type
*raw_real_type
=
7826 ada_check_typedef (ada_get_base_type (type
));
7828 if (type
== raw_real_type
)
7832 coerce_unspec_val_to_type
7833 (val
, ada_to_fixed_type (raw_real_type
, 0,
7834 VALUE_ADDRESS (val
) + value_offset (val
),
7839 static struct value
*
7840 cast_to_fixed (struct type
*type
, struct value
*arg
)
7844 if (type
== value_type (arg
))
7846 else if (ada_is_fixed_point_type (value_type (arg
)))
7847 val
= ada_float_to_fixed (type
,
7848 ada_fixed_to_float (value_type (arg
),
7849 value_as_long (arg
)));
7852 DOUBLEST argd
= value_as_double (arg
);
7853 val
= ada_float_to_fixed (type
, argd
);
7856 return value_from_longest (type
, val
);
7859 static struct value
*
7860 cast_from_fixed (struct type
*type
, struct value
*arg
)
7862 DOUBLEST val
= ada_fixed_to_float (value_type (arg
),
7863 value_as_long (arg
));
7864 return value_from_double (type
, val
);
7867 /* Coerce VAL as necessary for assignment to an lval of type TYPE, and
7868 return the converted value. */
7870 static struct value
*
7871 coerce_for_assign (struct type
*type
, struct value
*val
)
7873 struct type
*type2
= value_type (val
);
7877 type2
= ada_check_typedef (type2
);
7878 type
= ada_check_typedef (type
);
7880 if (TYPE_CODE (type2
) == TYPE_CODE_PTR
7881 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
)
7883 val
= ada_value_ind (val
);
7884 type2
= value_type (val
);
7887 if (TYPE_CODE (type2
) == TYPE_CODE_ARRAY
7888 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
)
7890 if (TYPE_LENGTH (type2
) != TYPE_LENGTH (type
)
7891 || TYPE_LENGTH (TYPE_TARGET_TYPE (type2
))
7892 != TYPE_LENGTH (TYPE_TARGET_TYPE (type2
)))
7893 error (_("Incompatible types in assignment"));
7894 deprecated_set_value_type (val
, type
);
7899 static struct value
*
7900 ada_value_binop (struct value
*arg1
, struct value
*arg2
, enum exp_opcode op
)
7903 struct type
*type1
, *type2
;
7906 arg1
= coerce_ref (arg1
);
7907 arg2
= coerce_ref (arg2
);
7908 type1
= base_type (ada_check_typedef (value_type (arg1
)));
7909 type2
= base_type (ada_check_typedef (value_type (arg2
)));
7911 if (TYPE_CODE (type1
) != TYPE_CODE_INT
7912 || TYPE_CODE (type2
) != TYPE_CODE_INT
)
7913 return value_binop (arg1
, arg2
, op
);
7922 return value_binop (arg1
, arg2
, op
);
7925 v2
= value_as_long (arg2
);
7927 error (_("second operand of %s must not be zero."), op_string (op
));
7929 if (TYPE_UNSIGNED (type1
) || op
== BINOP_MOD
)
7930 return value_binop (arg1
, arg2
, op
);
7932 v1
= value_as_long (arg1
);
7937 if (!TRUNCATION_TOWARDS_ZERO
&& v1
* (v1
% v2
) < 0)
7938 v
+= v
> 0 ? -1 : 1;
7946 /* Should not reach this point. */
7950 val
= allocate_value (type1
);
7951 store_unsigned_integer (value_contents_raw (val
),
7952 TYPE_LENGTH (value_type (val
)), v
);
7957 ada_value_equal (struct value
*arg1
, struct value
*arg2
)
7959 if (ada_is_direct_array_type (value_type (arg1
))
7960 || ada_is_direct_array_type (value_type (arg2
)))
7962 /* Automatically dereference any array reference before
7963 we attempt to perform the comparison. */
7964 arg1
= ada_coerce_ref (arg1
);
7965 arg2
= ada_coerce_ref (arg2
);
7967 arg1
= ada_coerce_to_simple_array (arg1
);
7968 arg2
= ada_coerce_to_simple_array (arg2
);
7969 if (TYPE_CODE (value_type (arg1
)) != TYPE_CODE_ARRAY
7970 || TYPE_CODE (value_type (arg2
)) != TYPE_CODE_ARRAY
)
7971 error (_("Attempt to compare array with non-array"));
7972 /* FIXME: The following works only for types whose
7973 representations use all bits (no padding or undefined bits)
7974 and do not have user-defined equality. */
7976 TYPE_LENGTH (value_type (arg1
)) == TYPE_LENGTH (value_type (arg2
))
7977 && memcmp (value_contents (arg1
), value_contents (arg2
),
7978 TYPE_LENGTH (value_type (arg1
))) == 0;
7980 return value_equal (arg1
, arg2
);
7983 /* Total number of component associations in the aggregate starting at
7984 index PC in EXP. Assumes that index PC is the start of an
7988 num_component_specs (struct expression
*exp
, int pc
)
7991 m
= exp
->elts
[pc
+ 1].longconst
;
7994 for (i
= 0; i
< m
; i
+= 1)
7996 switch (exp
->elts
[pc
].opcode
)
8002 n
+= exp
->elts
[pc
+ 1].longconst
;
8005 ada_evaluate_subexp (NULL
, exp
, &pc
, EVAL_SKIP
);
8010 /* Assign the result of evaluating EXP starting at *POS to the INDEXth
8011 component of LHS (a simple array or a record), updating *POS past
8012 the expression, assuming that LHS is contained in CONTAINER. Does
8013 not modify the inferior's memory, nor does it modify LHS (unless
8014 LHS == CONTAINER). */
8017 assign_component (struct value
*container
, struct value
*lhs
, LONGEST index
,
8018 struct expression
*exp
, int *pos
)
8020 struct value
*mark
= value_mark ();
8022 if (TYPE_CODE (value_type (lhs
)) == TYPE_CODE_ARRAY
)
8024 struct value
*index_val
= value_from_longest (builtin_type_int32
, index
);
8025 elt
= unwrap_value (ada_value_subscript (lhs
, 1, &index_val
));
8029 elt
= ada_index_struct_field (index
, lhs
, 0, value_type (lhs
));
8030 elt
= ada_to_fixed_value (unwrap_value (elt
));
8033 if (exp
->elts
[*pos
].opcode
== OP_AGGREGATE
)
8034 assign_aggregate (container
, elt
, exp
, pos
, EVAL_NORMAL
);
8036 value_assign_to_component (container
, elt
,
8037 ada_evaluate_subexp (NULL
, exp
, pos
,
8040 value_free_to_mark (mark
);
8043 /* Assuming that LHS represents an lvalue having a record or array
8044 type, and EXP->ELTS[*POS] is an OP_AGGREGATE, evaluate an assignment
8045 of that aggregate's value to LHS, advancing *POS past the
8046 aggregate. NOSIDE is as for evaluate_subexp. CONTAINER is an
8047 lvalue containing LHS (possibly LHS itself). Does not modify
8048 the inferior's memory, nor does it modify the contents of
8049 LHS (unless == CONTAINER). Returns the modified CONTAINER. */
8051 static struct value
*
8052 assign_aggregate (struct value
*container
,
8053 struct value
*lhs
, struct expression
*exp
,
8054 int *pos
, enum noside noside
)
8056 struct type
*lhs_type
;
8057 int n
= exp
->elts
[*pos
+1].longconst
;
8058 LONGEST low_index
, high_index
;
8061 int max_indices
, num_indices
;
8062 int is_array_aggregate
;
8064 struct value
*mark
= value_mark ();
8067 if (noside
!= EVAL_NORMAL
)
8070 for (i
= 0; i
< n
; i
+= 1)
8071 ada_evaluate_subexp (NULL
, exp
, pos
, noside
);
8075 container
= ada_coerce_ref (container
);
8076 if (ada_is_direct_array_type (value_type (container
)))
8077 container
= ada_coerce_to_simple_array (container
);
8078 lhs
= ada_coerce_ref (lhs
);
8079 if (!deprecated_value_modifiable (lhs
))
8080 error (_("Left operand of assignment is not a modifiable lvalue."));
8082 lhs_type
= value_type (lhs
);
8083 if (ada_is_direct_array_type (lhs_type
))
8085 lhs
= ada_coerce_to_simple_array (lhs
);
8086 lhs_type
= value_type (lhs
);
8087 low_index
= TYPE_ARRAY_LOWER_BOUND_VALUE (lhs_type
);
8088 high_index
= TYPE_ARRAY_UPPER_BOUND_VALUE (lhs_type
);
8089 is_array_aggregate
= 1;
8091 else if (TYPE_CODE (lhs_type
) == TYPE_CODE_STRUCT
)
8094 high_index
= num_visible_fields (lhs_type
) - 1;
8095 is_array_aggregate
= 0;
8098 error (_("Left-hand side must be array or record."));
8100 num_specs
= num_component_specs (exp
, *pos
- 3);
8101 max_indices
= 4 * num_specs
+ 4;
8102 indices
= alloca (max_indices
* sizeof (indices
[0]));
8103 indices
[0] = indices
[1] = low_index
- 1;
8104 indices
[2] = indices
[3] = high_index
+ 1;
8107 for (i
= 0; i
< n
; i
+= 1)
8109 switch (exp
->elts
[*pos
].opcode
)
8112 aggregate_assign_from_choices (container
, lhs
, exp
, pos
, indices
,
8113 &num_indices
, max_indices
,
8114 low_index
, high_index
);
8117 aggregate_assign_positional (container
, lhs
, exp
, pos
, indices
,
8118 &num_indices
, max_indices
,
8119 low_index
, high_index
);
8123 error (_("Misplaced 'others' clause"));
8124 aggregate_assign_others (container
, lhs
, exp
, pos
, indices
,
8125 num_indices
, low_index
, high_index
);
8128 error (_("Internal error: bad aggregate clause"));
8135 /* Assign into the component of LHS indexed by the OP_POSITIONAL
8136 construct at *POS, updating *POS past the construct, given that
8137 the positions are relative to lower bound LOW, where HIGH is the
8138 upper bound. Record the position in INDICES[0 .. MAX_INDICES-1]
8139 updating *NUM_INDICES as needed. CONTAINER is as for
8140 assign_aggregate. */
8142 aggregate_assign_positional (struct value
*container
,
8143 struct value
*lhs
, struct expression
*exp
,
8144 int *pos
, LONGEST
*indices
, int *num_indices
,
8145 int max_indices
, LONGEST low
, LONGEST high
)
8147 LONGEST ind
= longest_to_int (exp
->elts
[*pos
+ 1].longconst
) + low
;
8149 if (ind
- 1 == high
)
8150 warning (_("Extra components in aggregate ignored."));
8153 add_component_interval (ind
, ind
, indices
, num_indices
, max_indices
);
8155 assign_component (container
, lhs
, ind
, exp
, pos
);
8158 ada_evaluate_subexp (NULL
, exp
, pos
, EVAL_SKIP
);
8161 /* Assign into the components of LHS indexed by the OP_CHOICES
8162 construct at *POS, updating *POS past the construct, given that
8163 the allowable indices are LOW..HIGH. Record the indices assigned
8164 to in INDICES[0 .. MAX_INDICES-1], updating *NUM_INDICES as
8165 needed. CONTAINER is as for assign_aggregate. */
8167 aggregate_assign_from_choices (struct value
*container
,
8168 struct value
*lhs
, struct expression
*exp
,
8169 int *pos
, LONGEST
*indices
, int *num_indices
,
8170 int max_indices
, LONGEST low
, LONGEST high
)
8173 int n_choices
= longest_to_int (exp
->elts
[*pos
+1].longconst
);
8174 int choice_pos
, expr_pc
;
8175 int is_array
= ada_is_direct_array_type (value_type (lhs
));
8177 choice_pos
= *pos
+= 3;
8179 for (j
= 0; j
< n_choices
; j
+= 1)
8180 ada_evaluate_subexp (NULL
, exp
, pos
, EVAL_SKIP
);
8182 ada_evaluate_subexp (NULL
, exp
, pos
, EVAL_SKIP
);
8184 for (j
= 0; j
< n_choices
; j
+= 1)
8186 LONGEST lower
, upper
;
8187 enum exp_opcode op
= exp
->elts
[choice_pos
].opcode
;
8188 if (op
== OP_DISCRETE_RANGE
)
8191 lower
= value_as_long (ada_evaluate_subexp (NULL
, exp
, pos
,
8193 upper
= value_as_long (ada_evaluate_subexp (NULL
, exp
, pos
,
8198 lower
= value_as_long (ada_evaluate_subexp (NULL
, exp
, &choice_pos
,
8209 name
= &exp
->elts
[choice_pos
+ 2].string
;
8212 name
= SYMBOL_NATURAL_NAME (exp
->elts
[choice_pos
+ 2].symbol
);
8215 error (_("Invalid record component association."));
8217 ada_evaluate_subexp (NULL
, exp
, &choice_pos
, EVAL_SKIP
);
8219 if (! find_struct_field (name
, value_type (lhs
), 0,
8220 NULL
, NULL
, NULL
, NULL
, &ind
))
8221 error (_("Unknown component name: %s."), name
);
8222 lower
= upper
= ind
;
8225 if (lower
<= upper
&& (lower
< low
|| upper
> high
))
8226 error (_("Index in component association out of bounds."));
8228 add_component_interval (lower
, upper
, indices
, num_indices
,
8230 while (lower
<= upper
)
8234 assign_component (container
, lhs
, lower
, exp
, &pos1
);
8240 /* Assign the value of the expression in the OP_OTHERS construct in
8241 EXP at *POS into the components of LHS indexed from LOW .. HIGH that
8242 have not been previously assigned. The index intervals already assigned
8243 are in INDICES[0 .. NUM_INDICES-1]. Updates *POS to after the
8244 OP_OTHERS clause. CONTAINER is as for assign_aggregate*/
8246 aggregate_assign_others (struct value
*container
,
8247 struct value
*lhs
, struct expression
*exp
,
8248 int *pos
, LONGEST
*indices
, int num_indices
,
8249 LONGEST low
, LONGEST high
)
8252 int expr_pc
= *pos
+1;
8254 for (i
= 0; i
< num_indices
- 2; i
+= 2)
8257 for (ind
= indices
[i
+ 1] + 1; ind
< indices
[i
+ 2]; ind
+= 1)
8261 assign_component (container
, lhs
, ind
, exp
, &pos
);
8264 ada_evaluate_subexp (NULL
, exp
, pos
, EVAL_SKIP
);
8267 /* Add the interval [LOW .. HIGH] to the sorted set of intervals
8268 [ INDICES[0] .. INDICES[1] ],..., [ INDICES[*SIZE-2] .. INDICES[*SIZE-1] ],
8269 modifying *SIZE as needed. It is an error if *SIZE exceeds
8270 MAX_SIZE. The resulting intervals do not overlap. */
8272 add_component_interval (LONGEST low
, LONGEST high
,
8273 LONGEST
* indices
, int *size
, int max_size
)
8276 for (i
= 0; i
< *size
; i
+= 2) {
8277 if (high
>= indices
[i
] && low
<= indices
[i
+ 1])
8280 for (kh
= i
+ 2; kh
< *size
; kh
+= 2)
8281 if (high
< indices
[kh
])
8283 if (low
< indices
[i
])
8285 indices
[i
+ 1] = indices
[kh
- 1];
8286 if (high
> indices
[i
+ 1])
8287 indices
[i
+ 1] = high
;
8288 memcpy (indices
+ i
+ 2, indices
+ kh
, *size
- kh
);
8289 *size
-= kh
- i
- 2;
8292 else if (high
< indices
[i
])
8296 if (*size
== max_size
)
8297 error (_("Internal error: miscounted aggregate components."));
8299 for (j
= *size
-1; j
>= i
+2; j
-= 1)
8300 indices
[j
] = indices
[j
- 2];
8302 indices
[i
+ 1] = high
;
8305 /* Perform and Ada cast of ARG2 to type TYPE if the type of ARG2
8308 static struct value
*
8309 ada_value_cast (struct type
*type
, struct value
*arg2
, enum noside noside
)
8311 if (type
== ada_check_typedef (value_type (arg2
)))
8314 if (ada_is_fixed_point_type (type
))
8315 return (cast_to_fixed (type
, arg2
));
8317 if (ada_is_fixed_point_type (value_type (arg2
)))
8318 return cast_from_fixed (type
, arg2
);
8320 return value_cast (type
, arg2
);
8323 static struct value
*
8324 ada_evaluate_subexp (struct type
*expect_type
, struct expression
*exp
,
8325 int *pos
, enum noside noside
)
8328 int tem
, tem2
, tem3
;
8330 struct value
*arg1
= NULL
, *arg2
= NULL
, *arg3
;
8333 struct value
**argvec
;
8337 op
= exp
->elts
[pc
].opcode
;
8343 arg1
= evaluate_subexp_standard (expect_type
, exp
, pos
, noside
);
8344 arg1
= unwrap_value (arg1
);
8346 /* If evaluating an OP_DOUBLE and an EXPECT_TYPE was provided,
8347 then we need to perform the conversion manually, because
8348 evaluate_subexp_standard doesn't do it. This conversion is
8349 necessary in Ada because the different kinds of float/fixed
8350 types in Ada have different representations.
8352 Similarly, we need to perform the conversion from OP_LONG
8354 if ((op
== OP_DOUBLE
|| op
== OP_LONG
) && expect_type
!= NULL
)
8355 arg1
= ada_value_cast (expect_type
, arg1
, noside
);
8361 struct value
*result
;
8363 result
= evaluate_subexp_standard (expect_type
, exp
, pos
, noside
);
8364 /* The result type will have code OP_STRING, bashed there from
8365 OP_ARRAY. Bash it back. */
8366 if (TYPE_CODE (value_type (result
)) == TYPE_CODE_STRING
)
8367 TYPE_CODE (value_type (result
)) = TYPE_CODE_ARRAY
;
8373 type
= exp
->elts
[pc
+ 1].type
;
8374 arg1
= evaluate_subexp (type
, exp
, pos
, noside
);
8375 if (noside
== EVAL_SKIP
)
8377 arg1
= ada_value_cast (type
, arg1
, noside
);
8382 type
= exp
->elts
[pc
+ 1].type
;
8383 return ada_evaluate_subexp (type
, exp
, pos
, noside
);
8386 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
8387 if (exp
->elts
[*pos
].opcode
== OP_AGGREGATE
)
8389 arg1
= assign_aggregate (arg1
, arg1
, exp
, pos
, noside
);
8390 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
8392 return ada_value_assign (arg1
, arg1
);
8394 /* Force the evaluation of the rhs ARG2 to the type of the lhs ARG1,
8395 except if the lhs of our assignment is a convenience variable.
8396 In the case of assigning to a convenience variable, the lhs
8397 should be exactly the result of the evaluation of the rhs. */
8398 type
= value_type (arg1
);
8399 if (VALUE_LVAL (arg1
) == lval_internalvar
)
8401 arg2
= evaluate_subexp (type
, exp
, pos
, noside
);
8402 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
8404 if (ada_is_fixed_point_type (value_type (arg1
)))
8405 arg2
= cast_to_fixed (value_type (arg1
), arg2
);
8406 else if (ada_is_fixed_point_type (value_type (arg2
)))
8408 (_("Fixed-point values must be assigned to fixed-point variables"));
8410 arg2
= coerce_for_assign (value_type (arg1
), arg2
);
8411 return ada_value_assign (arg1
, arg2
);
8414 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
8415 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
8416 if (noside
== EVAL_SKIP
)
8418 if (TYPE_CODE (value_type (arg1
)) == TYPE_CODE_PTR
)
8419 return (value_from_longest
8421 value_as_long (arg1
) + value_as_long (arg2
)));
8422 if ((ada_is_fixed_point_type (value_type (arg1
))
8423 || ada_is_fixed_point_type (value_type (arg2
)))
8424 && value_type (arg1
) != value_type (arg2
))
8425 error (_("Operands of fixed-point addition must have the same type"));
8426 /* Do the addition, and cast the result to the type of the first
8427 argument. We cannot cast the result to a reference type, so if
8428 ARG1 is a reference type, find its underlying type. */
8429 type
= value_type (arg1
);
8430 while (TYPE_CODE (type
) == TYPE_CODE_REF
)
8431 type
= TYPE_TARGET_TYPE (type
);
8432 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
8433 return value_cast (type
, value_binop (arg1
, arg2
, BINOP_ADD
));
8436 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
8437 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
8438 if (noside
== EVAL_SKIP
)
8440 if (TYPE_CODE (value_type (arg1
)) == TYPE_CODE_PTR
)
8441 return (value_from_longest
8443 value_as_long (arg1
) - value_as_long (arg2
)));
8444 if ((ada_is_fixed_point_type (value_type (arg1
))
8445 || ada_is_fixed_point_type (value_type (arg2
)))
8446 && value_type (arg1
) != value_type (arg2
))
8447 error (_("Operands of fixed-point subtraction must have the same type"));
8448 /* Do the substraction, and cast the result to the type of the first
8449 argument. We cannot cast the result to a reference type, so if
8450 ARG1 is a reference type, find its underlying type. */
8451 type
= value_type (arg1
);
8452 while (TYPE_CODE (type
) == TYPE_CODE_REF
)
8453 type
= TYPE_TARGET_TYPE (type
);
8454 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
8455 return value_cast (type
, value_binop (arg1
, arg2
, BINOP_SUB
));
8461 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
8462 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
8463 if (noside
== EVAL_SKIP
)
8465 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
8467 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
8468 return value_zero (value_type (arg1
), not_lval
);
8472 type
= builtin_type (exp
->gdbarch
)->builtin_double
;
8473 if (ada_is_fixed_point_type (value_type (arg1
)))
8474 arg1
= cast_from_fixed (type
, arg1
);
8475 if (ada_is_fixed_point_type (value_type (arg2
)))
8476 arg2
= cast_from_fixed (type
, arg2
);
8477 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
8478 return ada_value_binop (arg1
, arg2
, op
);
8482 case BINOP_NOTEQUAL
:
8483 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
8484 arg2
= evaluate_subexp (value_type (arg1
), exp
, pos
, noside
);
8485 if (noside
== EVAL_SKIP
)
8487 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
8491 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
8492 tem
= ada_value_equal (arg1
, arg2
);
8494 if (op
== BINOP_NOTEQUAL
)
8496 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
8497 return value_from_longest (type
, (LONGEST
) tem
);
8500 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
8501 if (noside
== EVAL_SKIP
)
8503 else if (ada_is_fixed_point_type (value_type (arg1
)))
8504 return value_cast (value_type (arg1
), value_neg (arg1
));
8507 unop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
);
8508 return value_neg (arg1
);
8511 case BINOP_LOGICAL_AND
:
8512 case BINOP_LOGICAL_OR
:
8513 case UNOP_LOGICAL_NOT
:
8518 val
= evaluate_subexp_standard (expect_type
, exp
, pos
, noside
);
8519 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
8520 return value_cast (type
, val
);
8523 case BINOP_BITWISE_AND
:
8524 case BINOP_BITWISE_IOR
:
8525 case BINOP_BITWISE_XOR
:
8529 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
8531 val
= evaluate_subexp_standard (expect_type
, exp
, pos
, noside
);
8533 return value_cast (value_type (arg1
), val
);
8539 if (noside
== EVAL_SKIP
)
8544 else if (SYMBOL_DOMAIN (exp
->elts
[pc
+ 2].symbol
) == UNDEF_DOMAIN
)
8545 /* Only encountered when an unresolved symbol occurs in a
8546 context other than a function call, in which case, it is
8548 error (_("Unexpected unresolved symbol, %s, during evaluation"),
8549 SYMBOL_PRINT_NAME (exp
->elts
[pc
+ 2].symbol
));
8550 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
8552 type
= static_unwrap_type (SYMBOL_TYPE (exp
->elts
[pc
+ 2].symbol
));
8553 if (ada_is_tagged_type (type
, 0))
8555 /* Tagged types are a little special in the fact that the real
8556 type is dynamic and can only be determined by inspecting the
8557 object's tag. This means that we need to get the object's
8558 value first (EVAL_NORMAL) and then extract the actual object
8561 Note that we cannot skip the final step where we extract
8562 the object type from its tag, because the EVAL_NORMAL phase
8563 results in dynamic components being resolved into fixed ones.
8564 This can cause problems when trying to print the type
8565 description of tagged types whose parent has a dynamic size:
8566 We use the type name of the "_parent" component in order
8567 to print the name of the ancestor type in the type description.
8568 If that component had a dynamic size, the resolution into
8569 a fixed type would result in the loss of that type name,
8570 thus preventing us from printing the name of the ancestor
8571 type in the type description. */
8572 struct type
*actual_type
;
8574 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_NORMAL
);
8575 actual_type
= type_from_tag (ada_value_tag (arg1
));
8576 if (actual_type
== NULL
)
8577 /* If, for some reason, we were unable to determine
8578 the actual type from the tag, then use the static
8579 approximation that we just computed as a fallback.
8580 This can happen if the debugging information is
8581 incomplete, for instance. */
8584 return value_zero (actual_type
, not_lval
);
8589 (to_static_fixed_type
8590 (static_unwrap_type (SYMBOL_TYPE (exp
->elts
[pc
+ 2].symbol
))),
8596 unwrap_value (evaluate_subexp_standard
8597 (expect_type
, exp
, pos
, noside
));
8598 return ada_to_fixed_value (arg1
);
8604 /* Allocate arg vector, including space for the function to be
8605 called in argvec[0] and a terminating NULL. */
8606 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
8608 (struct value
**) alloca (sizeof (struct value
*) * (nargs
+ 2));
8610 if (exp
->elts
[*pos
].opcode
== OP_VAR_VALUE
8611 && SYMBOL_DOMAIN (exp
->elts
[pc
+ 5].symbol
) == UNDEF_DOMAIN
)
8612 error (_("Unexpected unresolved symbol, %s, during evaluation"),
8613 SYMBOL_PRINT_NAME (exp
->elts
[pc
+ 5].symbol
));
8616 for (tem
= 0; tem
<= nargs
; tem
+= 1)
8617 argvec
[tem
] = evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
8620 if (noside
== EVAL_SKIP
)
8624 if (ada_is_packed_array_type (desc_base_type (value_type (argvec
[0]))))
8625 argvec
[0] = ada_coerce_to_simple_array (argvec
[0]);
8626 else if (TYPE_CODE (value_type (argvec
[0])) == TYPE_CODE_REF
8627 || (TYPE_CODE (value_type (argvec
[0])) == TYPE_CODE_ARRAY
8628 && VALUE_LVAL (argvec
[0]) == lval_memory
))
8629 argvec
[0] = value_addr (argvec
[0]);
8631 type
= ada_check_typedef (value_type (argvec
[0]));
8632 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
8634 switch (TYPE_CODE (ada_check_typedef (TYPE_TARGET_TYPE (type
))))
8636 case TYPE_CODE_FUNC
:
8637 type
= ada_check_typedef (TYPE_TARGET_TYPE (type
));
8639 case TYPE_CODE_ARRAY
:
8641 case TYPE_CODE_STRUCT
:
8642 if (noside
!= EVAL_AVOID_SIDE_EFFECTS
)
8643 argvec
[0] = ada_value_ind (argvec
[0]);
8644 type
= ada_check_typedef (TYPE_TARGET_TYPE (type
));
8647 error (_("cannot subscript or call something of type `%s'"),
8648 ada_type_name (value_type (argvec
[0])));
8653 switch (TYPE_CODE (type
))
8655 case TYPE_CODE_FUNC
:
8656 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
8657 return allocate_value (TYPE_TARGET_TYPE (type
));
8658 return call_function_by_hand (argvec
[0], nargs
, argvec
+ 1);
8659 case TYPE_CODE_STRUCT
:
8663 arity
= ada_array_arity (type
);
8664 type
= ada_array_element_type (type
, nargs
);
8666 error (_("cannot subscript or call a record"));
8668 error (_("wrong number of subscripts; expecting %d"), arity
);
8669 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
8670 return value_zero (ada_aligned_type (type
), lval_memory
);
8672 unwrap_value (ada_value_subscript
8673 (argvec
[0], nargs
, argvec
+ 1));
8675 case TYPE_CODE_ARRAY
:
8676 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
8678 type
= ada_array_element_type (type
, nargs
);
8680 error (_("element type of array unknown"));
8682 return value_zero (ada_aligned_type (type
), lval_memory
);
8685 unwrap_value (ada_value_subscript
8686 (ada_coerce_to_simple_array (argvec
[0]),
8687 nargs
, argvec
+ 1));
8688 case TYPE_CODE_PTR
: /* Pointer to array */
8689 type
= to_fixed_array_type (TYPE_TARGET_TYPE (type
), NULL
, 1);
8690 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
8692 type
= ada_array_element_type (type
, nargs
);
8694 error (_("element type of array unknown"));
8696 return value_zero (ada_aligned_type (type
), lval_memory
);
8699 unwrap_value (ada_value_ptr_subscript (argvec
[0], type
,
8700 nargs
, argvec
+ 1));
8703 error (_("Attempt to index or call something other than an "
8704 "array or function"));
8709 struct value
*array
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
8710 struct value
*low_bound_val
=
8711 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
8712 struct value
*high_bound_val
=
8713 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
8716 low_bound_val
= coerce_ref (low_bound_val
);
8717 high_bound_val
= coerce_ref (high_bound_val
);
8718 low_bound
= pos_atr (low_bound_val
);
8719 high_bound
= pos_atr (high_bound_val
);
8721 if (noside
== EVAL_SKIP
)
8724 /* If this is a reference to an aligner type, then remove all
8726 if (TYPE_CODE (value_type (array
)) == TYPE_CODE_REF
8727 && ada_is_aligner_type (TYPE_TARGET_TYPE (value_type (array
))))
8728 TYPE_TARGET_TYPE (value_type (array
)) =
8729 ada_aligned_type (TYPE_TARGET_TYPE (value_type (array
)));
8731 if (ada_is_packed_array_type (value_type (array
)))
8732 error (_("cannot slice a packed array"));
8734 /* If this is a reference to an array or an array lvalue,
8735 convert to a pointer. */
8736 if (TYPE_CODE (value_type (array
)) == TYPE_CODE_REF
8737 || (TYPE_CODE (value_type (array
)) == TYPE_CODE_ARRAY
8738 && VALUE_LVAL (array
) == lval_memory
))
8739 array
= value_addr (array
);
8741 if (noside
== EVAL_AVOID_SIDE_EFFECTS
8742 && ada_is_array_descriptor_type (ada_check_typedef
8743 (value_type (array
))))
8744 return empty_array (ada_type_of_array (array
, 0), low_bound
);
8746 array
= ada_coerce_to_simple_array_ptr (array
);
8748 /* If we have more than one level of pointer indirection,
8749 dereference the value until we get only one level. */
8750 while (TYPE_CODE (value_type (array
)) == TYPE_CODE_PTR
8751 && (TYPE_CODE (TYPE_TARGET_TYPE (value_type (array
)))
8753 array
= value_ind (array
);
8755 /* Make sure we really do have an array type before going further,
8756 to avoid a SEGV when trying to get the index type or the target
8757 type later down the road if the debug info generated by
8758 the compiler is incorrect or incomplete. */
8759 if (!ada_is_simple_array_type (value_type (array
)))
8760 error (_("cannot take slice of non-array"));
8762 if (TYPE_CODE (value_type (array
)) == TYPE_CODE_PTR
)
8764 if (high_bound
< low_bound
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
8765 return empty_array (TYPE_TARGET_TYPE (value_type (array
)),
8769 struct type
*arr_type0
=
8770 to_fixed_array_type (TYPE_TARGET_TYPE (value_type (array
)),
8772 return ada_value_slice_from_ptr (array
, arr_type0
,
8773 longest_to_int (low_bound
),
8774 longest_to_int (high_bound
));
8777 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
8779 else if (high_bound
< low_bound
)
8780 return empty_array (value_type (array
), low_bound
);
8782 return ada_value_slice (array
, longest_to_int (low_bound
),
8783 longest_to_int (high_bound
));
8788 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
8789 type
= check_typedef (exp
->elts
[pc
+ 1].type
);
8791 if (noside
== EVAL_SKIP
)
8794 switch (TYPE_CODE (type
))
8797 lim_warning (_("Membership test incompletely implemented; "
8798 "always returns true"));
8799 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
8800 return value_from_longest (type
, (LONGEST
) 1);
8802 case TYPE_CODE_RANGE
:
8803 arg2
= value_from_longest (type
, TYPE_LOW_BOUND (type
));
8804 arg3
= value_from_longest (type
, TYPE_HIGH_BOUND (type
));
8805 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
8806 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg3
);
8807 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
8809 value_from_longest (type
,
8810 (value_less (arg1
, arg3
)
8811 || value_equal (arg1
, arg3
))
8812 && (value_less (arg2
, arg1
)
8813 || value_equal (arg2
, arg1
)));
8816 case BINOP_IN_BOUNDS
:
8818 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
8819 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
8821 if (noside
== EVAL_SKIP
)
8824 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
8826 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
8827 return value_zero (type
, not_lval
);
8830 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
8832 if (tem
< 1 || tem
> ada_array_arity (value_type (arg2
)))
8833 error (_("invalid dimension number to 'range"));
8835 arg3
= ada_array_bound (arg2
, tem
, 1);
8836 arg2
= ada_array_bound (arg2
, tem
, 0);
8838 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
8839 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg3
);
8840 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
8842 value_from_longest (type
,
8843 (value_less (arg1
, arg3
)
8844 || value_equal (arg1
, arg3
))
8845 && (value_less (arg2
, arg1
)
8846 || value_equal (arg2
, arg1
)));
8848 case TERNOP_IN_RANGE
:
8849 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
8850 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
8851 arg3
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
8853 if (noside
== EVAL_SKIP
)
8856 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
8857 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg3
);
8858 type
= language_bool_type (exp
->language_defn
, exp
->gdbarch
);
8860 value_from_longest (type
,
8861 (value_less (arg1
, arg3
)
8862 || value_equal (arg1
, arg3
))
8863 && (value_less (arg2
, arg1
)
8864 || value_equal (arg2
, arg1
)));
8870 struct type
*type_arg
;
8871 if (exp
->elts
[*pos
].opcode
== OP_TYPE
)
8873 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
8875 type_arg
= check_typedef (exp
->elts
[pc
+ 2].type
);
8879 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
8883 if (exp
->elts
[*pos
].opcode
!= OP_LONG
)
8884 error (_("Invalid operand to '%s"), ada_attribute_name (op
));
8885 tem
= longest_to_int (exp
->elts
[*pos
+ 2].longconst
);
8888 if (noside
== EVAL_SKIP
)
8891 if (type_arg
== NULL
)
8893 arg1
= ada_coerce_ref (arg1
);
8895 if (ada_is_packed_array_type (value_type (arg1
)))
8896 arg1
= ada_coerce_to_simple_array (arg1
);
8898 if (tem
< 1 || tem
> ada_array_arity (value_type (arg1
)))
8899 error (_("invalid dimension number to '%s"),
8900 ada_attribute_name (op
));
8902 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
8904 type
= ada_index_type (value_type (arg1
), tem
);
8907 (_("attempt to take bound of something that is not an array"));
8908 return allocate_value (type
);
8913 default: /* Should never happen. */
8914 error (_("unexpected attribute encountered"));
8916 return ada_array_bound (arg1
, tem
, 0);
8918 return ada_array_bound (arg1
, tem
, 1);
8920 return ada_array_length (arg1
, tem
);
8923 else if (discrete_type_p (type_arg
))
8925 struct type
*range_type
;
8926 char *name
= ada_type_name (type_arg
);
8928 if (name
!= NULL
&& TYPE_CODE (type_arg
) != TYPE_CODE_ENUM
)
8930 to_fixed_range_type (name
, NULL
, TYPE_OBJFILE (type_arg
));
8931 if (range_type
== NULL
)
8932 range_type
= type_arg
;
8936 error (_("unexpected attribute encountered"));
8938 return value_from_longest
8939 (range_type
, discrete_type_low_bound (range_type
));
8941 return value_from_longest
8942 (range_type
, discrete_type_high_bound (range_type
));
8944 error (_("the 'length attribute applies only to array types"));
8947 else if (TYPE_CODE (type_arg
) == TYPE_CODE_FLT
)
8948 error (_("unimplemented type attribute"));
8953 if (ada_is_packed_array_type (type_arg
))
8954 type_arg
= decode_packed_array_type (type_arg
);
8956 if (tem
< 1 || tem
> ada_array_arity (type_arg
))
8957 error (_("invalid dimension number to '%s"),
8958 ada_attribute_name (op
));
8960 type
= ada_index_type (type_arg
, tem
);
8963 (_("attempt to take bound of something that is not an array"));
8964 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
8965 return allocate_value (type
);
8970 error (_("unexpected attribute encountered"));
8972 low
= ada_array_bound_from_type (type_arg
, tem
, 0, &type
);
8973 return value_from_longest (type
, low
);
8975 high
= ada_array_bound_from_type (type_arg
, tem
, 1, &type
);
8976 return value_from_longest (type
, high
);
8978 low
= ada_array_bound_from_type (type_arg
, tem
, 0, &type
);
8979 high
= ada_array_bound_from_type (type_arg
, tem
, 1, NULL
);
8980 return value_from_longest (type
, high
- low
+ 1);
8986 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
8987 if (noside
== EVAL_SKIP
)
8990 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
8991 return value_zero (ada_tag_type (arg1
), not_lval
);
8993 return ada_value_tag (arg1
);
8997 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
8998 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
8999 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
9000 if (noside
== EVAL_SKIP
)
9002 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
9003 return value_zero (value_type (arg1
), not_lval
);
9006 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
9007 return value_binop (arg1
, arg2
,
9008 op
== OP_ATR_MIN
? BINOP_MIN
: BINOP_MAX
);
9011 case OP_ATR_MODULUS
:
9013 struct type
*type_arg
= check_typedef (exp
->elts
[pc
+ 2].type
);
9014 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
9016 if (noside
== EVAL_SKIP
)
9019 if (!ada_is_modular_type (type_arg
))
9020 error (_("'modulus must be applied to modular type"));
9022 return value_from_longest (TYPE_TARGET_TYPE (type_arg
),
9023 ada_modulus (type_arg
));
9028 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
9029 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
9030 if (noside
== EVAL_SKIP
)
9032 type
= builtin_type (exp
->gdbarch
)->builtin_int
;
9033 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
9034 return value_zero (type
, not_lval
);
9036 return value_pos_atr (type
, arg1
);
9039 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
9040 type
= value_type (arg1
);
9042 /* If the argument is a reference, then dereference its type, since
9043 the user is really asking for the size of the actual object,
9044 not the size of the pointer. */
9045 if (TYPE_CODE (type
) == TYPE_CODE_REF
)
9046 type
= TYPE_TARGET_TYPE (type
);
9048 if (noside
== EVAL_SKIP
)
9050 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
9051 return value_zero (builtin_type_int32
, not_lval
);
9053 return value_from_longest (builtin_type_int32
,
9054 TARGET_CHAR_BIT
* TYPE_LENGTH (type
));
9057 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
9058 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
9059 type
= exp
->elts
[pc
+ 2].type
;
9060 if (noside
== EVAL_SKIP
)
9062 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
9063 return value_zero (type
, not_lval
);
9065 return value_val_atr (type
, arg1
);
9068 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
9069 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
9070 if (noside
== EVAL_SKIP
)
9072 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
9073 return value_zero (value_type (arg1
), not_lval
);
9076 /* For integer exponentiation operations,
9077 only promote the first argument. */
9078 if (is_integral_type (value_type (arg2
)))
9079 unop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
);
9081 binop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
, &arg2
);
9083 return value_binop (arg1
, arg2
, op
);
9087 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
9088 if (noside
== EVAL_SKIP
)
9094 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
9095 if (noside
== EVAL_SKIP
)
9097 unop_promote (exp
->language_defn
, exp
->gdbarch
, &arg1
);
9098 if (value_less (arg1
, value_zero (value_type (arg1
), not_lval
)))
9099 return value_neg (arg1
);
9104 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
9105 if (noside
== EVAL_SKIP
)
9107 type
= ada_check_typedef (value_type (arg1
));
9108 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
9110 if (ada_is_array_descriptor_type (type
))
9111 /* GDB allows dereferencing GNAT array descriptors. */
9113 struct type
*arrType
= ada_type_of_array (arg1
, 0);
9114 if (arrType
== NULL
)
9115 error (_("Attempt to dereference null array pointer."));
9116 return value_at_lazy (arrType
, 0);
9118 else if (TYPE_CODE (type
) == TYPE_CODE_PTR
9119 || TYPE_CODE (type
) == TYPE_CODE_REF
9120 /* In C you can dereference an array to get the 1st elt. */
9121 || TYPE_CODE (type
) == TYPE_CODE_ARRAY
)
9123 type
= to_static_fixed_type
9125 (ada_check_typedef (TYPE_TARGET_TYPE (type
))));
9127 return value_zero (type
, lval_memory
);
9129 else if (TYPE_CODE (type
) == TYPE_CODE_INT
)
9131 /* GDB allows dereferencing an int. */
9132 if (expect_type
== NULL
)
9133 return value_zero (builtin_type (exp
->gdbarch
)->builtin_int
,
9138 to_static_fixed_type (ada_aligned_type (expect_type
));
9139 return value_zero (expect_type
, lval_memory
);
9143 error (_("Attempt to take contents of a non-pointer value."));
9145 arg1
= ada_coerce_ref (arg1
); /* FIXME: What is this for?? */
9146 type
= ada_check_typedef (value_type (arg1
));
9148 if (TYPE_CODE (type
) == TYPE_CODE_INT
)
9149 /* GDB allows dereferencing an int. If we were given
9150 the expect_type, then use that as the target type.
9151 Otherwise, assume that the target type is an int. */
9153 if (expect_type
!= NULL
)
9154 return ada_value_ind (value_cast (lookup_pointer_type (expect_type
),
9157 return value_at_lazy (builtin_type (exp
->gdbarch
)->builtin_int
,
9158 (CORE_ADDR
) value_as_address (arg1
));
9161 if (ada_is_array_descriptor_type (type
))
9162 /* GDB allows dereferencing GNAT array descriptors. */
9163 return ada_coerce_to_simple_array (arg1
);
9165 return ada_value_ind (arg1
);
9167 case STRUCTOP_STRUCT
:
9168 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
9169 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
9170 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
9171 if (noside
== EVAL_SKIP
)
9173 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
9175 struct type
*type1
= value_type (arg1
);
9176 if (ada_is_tagged_type (type1
, 1))
9178 type
= ada_lookup_struct_elt_type (type1
,
9179 &exp
->elts
[pc
+ 2].string
,
9182 /* In this case, we assume that the field COULD exist
9183 in some extension of the type. Return an object of
9184 "type" void, which will match any formal
9185 (see ada_type_match). */
9186 return value_zero (builtin_type_void
, lval_memory
);
9190 ada_lookup_struct_elt_type (type1
, &exp
->elts
[pc
+ 2].string
, 1,
9193 return value_zero (ada_aligned_type (type
), lval_memory
);
9197 ada_to_fixed_value (unwrap_value
9198 (ada_value_struct_elt
9199 (arg1
, &exp
->elts
[pc
+ 2].string
, 0)));
9201 /* The value is not supposed to be used. This is here to make it
9202 easier to accommodate expressions that contain types. */
9204 if (noside
== EVAL_SKIP
)
9206 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
9207 return allocate_value (exp
->elts
[pc
+ 1].type
);
9209 error (_("Attempt to use a type name as an expression"));
9214 case OP_DISCRETE_RANGE
:
9217 if (noside
== EVAL_NORMAL
)
9221 error (_("Undefined name, ambiguous name, or renaming used in "
9222 "component association: %s."), &exp
->elts
[pc
+2].string
);
9224 error (_("Aggregates only allowed on the right of an assignment"));
9226 internal_error (__FILE__
, __LINE__
, _("aggregate apparently mangled"));
9229 ada_forward_operator_length (exp
, pc
, &oplen
, &nargs
);
9231 for (tem
= 0; tem
< nargs
; tem
+= 1)
9232 ada_evaluate_subexp (NULL
, exp
, pos
, noside
);
9237 return value_from_longest (builtin_type_int8
, (LONGEST
) 1);
9243 /* If TYPE encodes an Ada fixed-point type, return the suffix of the
9244 type name that encodes the 'small and 'delta information.
9245 Otherwise, return NULL. */
9248 fixed_type_info (struct type
*type
)
9250 const char *name
= ada_type_name (type
);
9251 enum type_code code
= (type
== NULL
) ? TYPE_CODE_UNDEF
: TYPE_CODE (type
);
9253 if ((code
== TYPE_CODE_INT
|| code
== TYPE_CODE_RANGE
) && name
!= NULL
)
9255 const char *tail
= strstr (name
, "___XF_");
9261 else if (code
== TYPE_CODE_RANGE
&& TYPE_TARGET_TYPE (type
) != type
)
9262 return fixed_type_info (TYPE_TARGET_TYPE (type
));
9267 /* Returns non-zero iff TYPE represents an Ada fixed-point type. */
9270 ada_is_fixed_point_type (struct type
*type
)
9272 return fixed_type_info (type
) != NULL
;
9275 /* Return non-zero iff TYPE represents a System.Address type. */
9278 ada_is_system_address_type (struct type
*type
)
9280 return (TYPE_NAME (type
)
9281 && strcmp (TYPE_NAME (type
), "system__address") == 0);
9284 /* Assuming that TYPE is the representation of an Ada fixed-point
9285 type, return its delta, or -1 if the type is malformed and the
9286 delta cannot be determined. */
9289 ada_delta (struct type
*type
)
9291 const char *encoding
= fixed_type_info (type
);
9294 /* Strictly speaking, num and den are encoded as integer. However,
9295 they may not fit into a long, and they will have to be converted
9296 to DOUBLEST anyway. So scan them as DOUBLEST. */
9297 if (sscanf (encoding
, "_%" DOUBLEST_SCAN_FORMAT
"_%" DOUBLEST_SCAN_FORMAT
,
9304 /* Assuming that ada_is_fixed_point_type (TYPE), return the scaling
9305 factor ('SMALL value) associated with the type. */
9308 scaling_factor (struct type
*type
)
9310 const char *encoding
= fixed_type_info (type
);
9311 DOUBLEST num0
, den0
, num1
, den1
;
9314 /* Strictly speaking, num's and den's are encoded as integer. However,
9315 they may not fit into a long, and they will have to be converted
9316 to DOUBLEST anyway. So scan them as DOUBLEST. */
9317 n
= sscanf (encoding
,
9318 "_%" DOUBLEST_SCAN_FORMAT
"_%" DOUBLEST_SCAN_FORMAT
9319 "_%" DOUBLEST_SCAN_FORMAT
"_%" DOUBLEST_SCAN_FORMAT
,
9320 &num0
, &den0
, &num1
, &den1
);
9331 /* Assuming that X is the representation of a value of fixed-point
9332 type TYPE, return its floating-point equivalent. */
9335 ada_fixed_to_float (struct type
*type
, LONGEST x
)
9337 return (DOUBLEST
) x
*scaling_factor (type
);
9340 /* The representation of a fixed-point value of type TYPE
9341 corresponding to the value X. */
9344 ada_float_to_fixed (struct type
*type
, DOUBLEST x
)
9346 return (LONGEST
) (x
/ scaling_factor (type
) + 0.5);
9350 /* VAX floating formats */
9352 /* Non-zero iff TYPE represents one of the special VAX floating-point
9356 ada_is_vax_floating_type (struct type
*type
)
9359 (ada_type_name (type
) == NULL
) ? 0 : strlen (ada_type_name (type
));
9362 && (TYPE_CODE (type
) == TYPE_CODE_INT
9363 || TYPE_CODE (type
) == TYPE_CODE_RANGE
)
9364 && strncmp (ada_type_name (type
) + name_len
- 6, "___XF", 5) == 0;
9367 /* The type of special VAX floating-point type this is, assuming
9368 ada_is_vax_floating_point. */
9371 ada_vax_float_type_suffix (struct type
*type
)
9373 return ada_type_name (type
)[strlen (ada_type_name (type
)) - 1];
9376 /* A value representing the special debugging function that outputs
9377 VAX floating-point values of the type represented by TYPE. Assumes
9378 ada_is_vax_floating_type (TYPE). */
9381 ada_vax_float_print_function (struct type
*type
)
9383 switch (ada_vax_float_type_suffix (type
))
9386 return get_var_value ("DEBUG_STRING_F", 0);
9388 return get_var_value ("DEBUG_STRING_D", 0);
9390 return get_var_value ("DEBUG_STRING_G", 0);
9392 error (_("invalid VAX floating-point type"));
9399 /* Scan STR beginning at position K for a discriminant name, and
9400 return the value of that discriminant field of DVAL in *PX. If
9401 PNEW_K is not null, put the position of the character beyond the
9402 name scanned in *PNEW_K. Return 1 if successful; return 0 and do
9403 not alter *PX and *PNEW_K if unsuccessful. */
9406 scan_discrim_bound (char *str
, int k
, struct value
*dval
, LONGEST
* px
,
9409 static char *bound_buffer
= NULL
;
9410 static size_t bound_buffer_len
= 0;
9413 struct value
*bound_val
;
9415 if (dval
== NULL
|| str
== NULL
|| str
[k
] == '\0')
9418 pend
= strstr (str
+ k
, "__");
9422 k
+= strlen (bound
);
9426 GROW_VECT (bound_buffer
, bound_buffer_len
, pend
- (str
+ k
) + 1);
9427 bound
= bound_buffer
;
9428 strncpy (bound_buffer
, str
+ k
, pend
- (str
+ k
));
9429 bound
[pend
- (str
+ k
)] = '\0';
9433 bound_val
= ada_search_struct_field (bound
, dval
, 0, value_type (dval
));
9434 if (bound_val
== NULL
)
9437 *px
= value_as_long (bound_val
);
9443 /* Value of variable named NAME in the current environment. If
9444 no such variable found, then if ERR_MSG is null, returns 0, and
9445 otherwise causes an error with message ERR_MSG. */
9447 static struct value
*
9448 get_var_value (char *name
, char *err_msg
)
9450 struct ada_symbol_info
*syms
;
9453 nsyms
= ada_lookup_symbol_list (name
, get_selected_block (0), VAR_DOMAIN
,
9458 if (err_msg
== NULL
)
9461 error (("%s"), err_msg
);
9464 return value_of_variable (syms
[0].sym
, syms
[0].block
);
9467 /* Value of integer variable named NAME in the current environment. If
9468 no such variable found, returns 0, and sets *FLAG to 0. If
9469 successful, sets *FLAG to 1. */
9472 get_int_var_value (char *name
, int *flag
)
9474 struct value
*var_val
= get_var_value (name
, 0);
9486 return value_as_long (var_val
);
9491 /* Return a range type whose base type is that of the range type named
9492 NAME in the current environment, and whose bounds are calculated
9493 from NAME according to the GNAT range encoding conventions.
9494 Extract discriminant values, if needed, from DVAL. If a new type
9495 must be created, allocate in OBJFILE's space. The bounds
9496 information, in general, is encoded in NAME, the base type given in
9497 the named range type. */
9499 static struct type
*
9500 to_fixed_range_type (char *name
, struct value
*dval
, struct objfile
*objfile
)
9502 struct type
*raw_type
= ada_find_any_type (name
);
9503 struct type
*base_type
;
9506 if (raw_type
== NULL
)
9507 base_type
= builtin_type_int32
;
9508 else if (TYPE_CODE (raw_type
) == TYPE_CODE_RANGE
)
9509 base_type
= TYPE_TARGET_TYPE (raw_type
);
9511 base_type
= raw_type
;
9513 subtype_info
= strstr (name
, "___XD");
9514 if (subtype_info
== NULL
)
9516 LONGEST L
= discrete_type_low_bound (raw_type
);
9517 LONGEST U
= discrete_type_high_bound (raw_type
);
9518 if (L
< INT_MIN
|| U
> INT_MAX
)
9521 return create_range_type (alloc_type (objfile
), raw_type
,
9522 discrete_type_low_bound (raw_type
),
9523 discrete_type_high_bound (raw_type
));
9527 static char *name_buf
= NULL
;
9528 static size_t name_len
= 0;
9529 int prefix_len
= subtype_info
- name
;
9535 GROW_VECT (name_buf
, name_len
, prefix_len
+ 5);
9536 strncpy (name_buf
, name
, prefix_len
);
9537 name_buf
[prefix_len
] = '\0';
9540 bounds_str
= strchr (subtype_info
, '_');
9543 if (*subtype_info
== 'L')
9545 if (!ada_scan_number (bounds_str
, n
, &L
, &n
)
9546 && !scan_discrim_bound (bounds_str
, n
, dval
, &L
, &n
))
9548 if (bounds_str
[n
] == '_')
9550 else if (bounds_str
[n
] == '.') /* FIXME? SGI Workshop kludge. */
9557 strcpy (name_buf
+ prefix_len
, "___L");
9558 L
= get_int_var_value (name_buf
, &ok
);
9561 lim_warning (_("Unknown lower bound, using 1."));
9566 if (*subtype_info
== 'U')
9568 if (!ada_scan_number (bounds_str
, n
, &U
, &n
)
9569 && !scan_discrim_bound (bounds_str
, n
, dval
, &U
, &n
))
9575 strcpy (name_buf
+ prefix_len
, "___U");
9576 U
= get_int_var_value (name_buf
, &ok
);
9579 lim_warning (_("Unknown upper bound, using %ld."), (long) L
);
9584 if (objfile
== NULL
)
9585 objfile
= TYPE_OBJFILE (base_type
);
9586 type
= create_range_type (alloc_type (objfile
), base_type
, L
, U
);
9587 TYPE_NAME (type
) = name
;
9592 /* True iff NAME is the name of a range type. */
9595 ada_is_range_type_name (const char *name
)
9597 return (name
!= NULL
&& strstr (name
, "___XD"));
9603 /* True iff TYPE is an Ada modular type. */
9606 ada_is_modular_type (struct type
*type
)
9608 struct type
*subranged_type
= base_type (type
);
9610 return (subranged_type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_RANGE
9611 && TYPE_CODE (subranged_type
) == TYPE_CODE_INT
9612 && TYPE_UNSIGNED (subranged_type
));
9615 /* Try to determine the lower and upper bounds of the given modular type
9616 using the type name only. Return non-zero and set L and U as the lower
9617 and upper bounds (respectively) if successful. */
9620 ada_modulus_from_name (struct type
*type
, ULONGEST
*modulus
)
9622 char *name
= ada_type_name (type
);
9630 /* Discrete type bounds are encoded using an __XD suffix. In our case,
9631 we are looking for static bounds, which means an __XDLU suffix.
9632 Moreover, we know that the lower bound of modular types is always
9633 zero, so the actual suffix should start with "__XDLU_0__", and
9634 then be followed by the upper bound value. */
9635 suffix
= strstr (name
, "__XDLU_0__");
9639 if (!ada_scan_number (suffix
, k
, &U
, NULL
))
9642 *modulus
= (ULONGEST
) U
+ 1;
9646 /* Assuming ada_is_modular_type (TYPE), the modulus of TYPE. */
9649 ada_modulus (struct type
*type
)
9653 /* Normally, the modulus of a modular type is equal to the value of
9654 its upper bound + 1. However, the upper bound is currently stored
9655 as an int, which is not always big enough to hold the actual bound
9656 value. To workaround this, try to take advantage of the encoding
9657 that GNAT uses with with discrete types. To avoid some unnecessary
9658 parsing, we do this only when the size of TYPE is greater than
9659 the size of the field holding the bound. */
9660 if (TYPE_LENGTH (type
) > sizeof (TYPE_HIGH_BOUND (type
))
9661 && ada_modulus_from_name (type
, &modulus
))
9664 return (ULONGEST
) (unsigned int) TYPE_HIGH_BOUND (type
) + 1;
9668 /* Ada exception catchpoint support:
9669 ---------------------------------
9671 We support 3 kinds of exception catchpoints:
9672 . catchpoints on Ada exceptions
9673 . catchpoints on unhandled Ada exceptions
9674 . catchpoints on failed assertions
9676 Exceptions raised during failed assertions, or unhandled exceptions
9677 could perfectly be caught with the general catchpoint on Ada exceptions.
9678 However, we can easily differentiate these two special cases, and having
9679 the option to distinguish these two cases from the rest can be useful
9680 to zero-in on certain situations.
9682 Exception catchpoints are a specialized form of breakpoint,
9683 since they rely on inserting breakpoints inside known routines
9684 of the GNAT runtime. The implementation therefore uses a standard
9685 breakpoint structure of the BP_BREAKPOINT type, but with its own set
9688 Support in the runtime for exception catchpoints have been changed
9689 a few times already, and these changes affect the implementation
9690 of these catchpoints. In order to be able to support several
9691 variants of the runtime, we use a sniffer that will determine
9692 the runtime variant used by the program being debugged.
9694 At this time, we do not support the use of conditions on Ada exception
9695 catchpoints. The COND and COND_STRING fields are therefore set
9696 to NULL (most of the time, see below).
9698 Conditions where EXP_STRING, COND, and COND_STRING are used:
9700 When a user specifies the name of a specific exception in the case
9701 of catchpoints on Ada exceptions, we store the name of that exception
9702 in the EXP_STRING. We then translate this request into an actual
9703 condition stored in COND_STRING, and then parse it into an expression
9706 /* The different types of catchpoints that we introduced for catching
9709 enum exception_catchpoint_kind
9712 ex_catch_exception_unhandled
,
9716 /* Ada's standard exceptions. */
9718 static char *standard_exc
[] = {
9725 typedef CORE_ADDR (ada_unhandled_exception_name_addr_ftype
) (void);
9727 /* A structure that describes how to support exception catchpoints
9728 for a given executable. */
9730 struct exception_support_info
9732 /* The name of the symbol to break on in order to insert
9733 a catchpoint on exceptions. */
9734 const char *catch_exception_sym
;
9736 /* The name of the symbol to break on in order to insert
9737 a catchpoint on unhandled exceptions. */
9738 const char *catch_exception_unhandled_sym
;
9740 /* The name of the symbol to break on in order to insert
9741 a catchpoint on failed assertions. */
9742 const char *catch_assert_sym
;
9744 /* Assuming that the inferior just triggered an unhandled exception
9745 catchpoint, this function is responsible for returning the address
9746 in inferior memory where the name of that exception is stored.
9747 Return zero if the address could not be computed. */
9748 ada_unhandled_exception_name_addr_ftype
*unhandled_exception_name_addr
;
9751 static CORE_ADDR
ada_unhandled_exception_name_addr (void);
9752 static CORE_ADDR
ada_unhandled_exception_name_addr_from_raise (void);
9754 /* The following exception support info structure describes how to
9755 implement exception catchpoints with the latest version of the
9756 Ada runtime (as of 2007-03-06). */
9758 static const struct exception_support_info default_exception_support_info
=
9760 "__gnat_debug_raise_exception", /* catch_exception_sym */
9761 "__gnat_unhandled_exception", /* catch_exception_unhandled_sym */
9762 "__gnat_debug_raise_assert_failure", /* catch_assert_sym */
9763 ada_unhandled_exception_name_addr
9766 /* The following exception support info structure describes how to
9767 implement exception catchpoints with a slightly older version
9768 of the Ada runtime. */
9770 static const struct exception_support_info exception_support_info_fallback
=
9772 "__gnat_raise_nodefer_with_msg", /* catch_exception_sym */
9773 "__gnat_unhandled_exception", /* catch_exception_unhandled_sym */
9774 "system__assertions__raise_assert_failure", /* catch_assert_sym */
9775 ada_unhandled_exception_name_addr_from_raise
9778 /* For each executable, we sniff which exception info structure to use
9779 and cache it in the following global variable. */
9781 static const struct exception_support_info
*exception_info
= NULL
;
9783 /* Inspect the Ada runtime and determine which exception info structure
9784 should be used to provide support for exception catchpoints.
9786 This function will always set exception_info, or raise an error. */
9789 ada_exception_support_info_sniffer (void)
9793 /* If the exception info is already known, then no need to recompute it. */
9794 if (exception_info
!= NULL
)
9797 /* Check the latest (default) exception support info. */
9798 sym
= standard_lookup (default_exception_support_info
.catch_exception_sym
,
9802 exception_info
= &default_exception_support_info
;
9806 /* Try our fallback exception suport info. */
9807 sym
= standard_lookup (exception_support_info_fallback
.catch_exception_sym
,
9811 exception_info
= &exception_support_info_fallback
;
9815 /* Sometimes, it is normal for us to not be able to find the routine
9816 we are looking for. This happens when the program is linked with
9817 the shared version of the GNAT runtime, and the program has not been
9818 started yet. Inform the user of these two possible causes if
9821 if (ada_update_initial_language (language_unknown
, NULL
) != language_ada
)
9822 error (_("Unable to insert catchpoint. Is this an Ada main program?"));
9824 /* If the symbol does not exist, then check that the program is
9825 already started, to make sure that shared libraries have been
9826 loaded. If it is not started, this may mean that the symbol is
9827 in a shared library. */
9829 if (ptid_get_pid (inferior_ptid
) == 0)
9830 error (_("Unable to insert catchpoint. Try to start the program first."));
9832 /* At this point, we know that we are debugging an Ada program and
9833 that the inferior has been started, but we still are not able to
9834 find the run-time symbols. That can mean that we are in
9835 configurable run time mode, or that a-except as been optimized
9836 out by the linker... In any case, at this point it is not worth
9837 supporting this feature. */
9839 error (_("Cannot insert catchpoints in this configuration."));
9842 /* An observer of "executable_changed" events.
9843 Its role is to clear certain cached values that need to be recomputed
9844 each time a new executable is loaded by GDB. */
9847 ada_executable_changed_observer (void)
9849 /* If the executable changed, then it is possible that the Ada runtime
9850 is different. So we need to invalidate the exception support info
9852 exception_info
= NULL
;
9855 /* Return the name of the function at PC, NULL if could not find it.
9856 This function only checks the debugging information, not the symbol
9860 function_name_from_pc (CORE_ADDR pc
)
9864 if (!find_pc_partial_function (pc
, &func_name
, NULL
, NULL
))
9870 /* True iff FRAME is very likely to be that of a function that is
9871 part of the runtime system. This is all very heuristic, but is
9872 intended to be used as advice as to what frames are uninteresting
9876 is_known_support_routine (struct frame_info
*frame
)
9878 struct symtab_and_line sal
;
9882 /* If this code does not have any debugging information (no symtab),
9883 This cannot be any user code. */
9885 find_frame_sal (frame
, &sal
);
9886 if (sal
.symtab
== NULL
)
9889 /* If there is a symtab, but the associated source file cannot be
9890 located, then assume this is not user code: Selecting a frame
9891 for which we cannot display the code would not be very helpful
9892 for the user. This should also take care of case such as VxWorks
9893 where the kernel has some debugging info provided for a few units. */
9895 if (symtab_to_fullname (sal
.symtab
) == NULL
)
9898 /* Check the unit filename againt the Ada runtime file naming.
9899 We also check the name of the objfile against the name of some
9900 known system libraries that sometimes come with debugging info
9903 for (i
= 0; known_runtime_file_name_patterns
[i
] != NULL
; i
+= 1)
9905 re_comp (known_runtime_file_name_patterns
[i
]);
9906 if (re_exec (sal
.symtab
->filename
))
9908 if (sal
.symtab
->objfile
!= NULL
9909 && re_exec (sal
.symtab
->objfile
->name
))
9913 /* Check whether the function is a GNAT-generated entity. */
9915 func_name
= function_name_from_pc (get_frame_address_in_block (frame
));
9916 if (func_name
== NULL
)
9919 for (i
= 0; known_auxiliary_function_name_patterns
[i
] != NULL
; i
+= 1)
9921 re_comp (known_auxiliary_function_name_patterns
[i
]);
9922 if (re_exec (func_name
))
9929 /* Find the first frame that contains debugging information and that is not
9930 part of the Ada run-time, starting from FI and moving upward. */
9933 ada_find_printable_frame (struct frame_info
*fi
)
9935 for (; fi
!= NULL
; fi
= get_prev_frame (fi
))
9937 if (!is_known_support_routine (fi
))
9946 /* Assuming that the inferior just triggered an unhandled exception
9947 catchpoint, return the address in inferior memory where the name
9948 of the exception is stored.
9950 Return zero if the address could not be computed. */
9953 ada_unhandled_exception_name_addr (void)
9955 return parse_and_eval_address ("e.full_name");
9958 /* Same as ada_unhandled_exception_name_addr, except that this function
9959 should be used when the inferior uses an older version of the runtime,
9960 where the exception name needs to be extracted from a specific frame
9961 several frames up in the callstack. */
9964 ada_unhandled_exception_name_addr_from_raise (void)
9967 struct frame_info
*fi
;
9969 /* To determine the name of this exception, we need to select
9970 the frame corresponding to RAISE_SYM_NAME. This frame is
9971 at least 3 levels up, so we simply skip the first 3 frames
9972 without checking the name of their associated function. */
9973 fi
= get_current_frame ();
9974 for (frame_level
= 0; frame_level
< 3; frame_level
+= 1)
9976 fi
= get_prev_frame (fi
);
9980 const char *func_name
=
9981 function_name_from_pc (get_frame_address_in_block (fi
));
9982 if (func_name
!= NULL
9983 && strcmp (func_name
, exception_info
->catch_exception_sym
) == 0)
9984 break; /* We found the frame we were looking for... */
9985 fi
= get_prev_frame (fi
);
9992 return parse_and_eval_address ("id.full_name");
9995 /* Assuming the inferior just triggered an Ada exception catchpoint
9996 (of any type), return the address in inferior memory where the name
9997 of the exception is stored, if applicable.
9999 Return zero if the address could not be computed, or if not relevant. */
10002 ada_exception_name_addr_1 (enum exception_catchpoint_kind ex
,
10003 struct breakpoint
*b
)
10007 case ex_catch_exception
:
10008 return (parse_and_eval_address ("e.full_name"));
10011 case ex_catch_exception_unhandled
:
10012 return exception_info
->unhandled_exception_name_addr ();
10015 case ex_catch_assert
:
10016 return 0; /* Exception name is not relevant in this case. */
10020 internal_error (__FILE__
, __LINE__
, _("unexpected catchpoint type"));
10024 return 0; /* Should never be reached. */
10027 /* Same as ada_exception_name_addr_1, except that it intercepts and contains
10028 any error that ada_exception_name_addr_1 might cause to be thrown.
10029 When an error is intercepted, a warning with the error message is printed,
10030 and zero is returned. */
10033 ada_exception_name_addr (enum exception_catchpoint_kind ex
,
10034 struct breakpoint
*b
)
10036 struct gdb_exception e
;
10037 CORE_ADDR result
= 0;
10039 TRY_CATCH (e
, RETURN_MASK_ERROR
)
10041 result
= ada_exception_name_addr_1 (ex
, b
);
10046 warning (_("failed to get exception name: %s"), e
.message
);
10053 /* Implement the PRINT_IT method in the breakpoint_ops structure
10054 for all exception catchpoint kinds. */
10056 static enum print_stop_action
10057 print_it_exception (enum exception_catchpoint_kind ex
, struct breakpoint
*b
)
10059 const CORE_ADDR addr
= ada_exception_name_addr (ex
, b
);
10060 char exception_name
[256];
10064 read_memory (addr
, exception_name
, sizeof (exception_name
) - 1);
10065 exception_name
[sizeof (exception_name
) - 1] = '\0';
10068 ada_find_printable_frame (get_current_frame ());
10070 annotate_catchpoint (b
->number
);
10073 case ex_catch_exception
:
10075 printf_filtered (_("\nCatchpoint %d, %s at "),
10076 b
->number
, exception_name
);
10078 printf_filtered (_("\nCatchpoint %d, exception at "), b
->number
);
10080 case ex_catch_exception_unhandled
:
10082 printf_filtered (_("\nCatchpoint %d, unhandled %s at "),
10083 b
->number
, exception_name
);
10085 printf_filtered (_("\nCatchpoint %d, unhandled exception at "),
10088 case ex_catch_assert
:
10089 printf_filtered (_("\nCatchpoint %d, failed assertion at "),
10094 return PRINT_SRC_AND_LOC
;
10097 /* Implement the PRINT_ONE method in the breakpoint_ops structure
10098 for all exception catchpoint kinds. */
10101 print_one_exception (enum exception_catchpoint_kind ex
,
10102 struct breakpoint
*b
, CORE_ADDR
*last_addr
)
10104 struct value_print_options opts
;
10106 get_user_print_options (&opts
);
10107 if (opts
.addressprint
)
10109 annotate_field (4);
10110 ui_out_field_core_addr (uiout
, "addr", b
->loc
->address
);
10113 annotate_field (5);
10114 *last_addr
= b
->loc
->address
;
10117 case ex_catch_exception
:
10118 if (b
->exp_string
!= NULL
)
10120 char *msg
= xstrprintf (_("`%s' Ada exception"), b
->exp_string
);
10122 ui_out_field_string (uiout
, "what", msg
);
10126 ui_out_field_string (uiout
, "what", "all Ada exceptions");
10130 case ex_catch_exception_unhandled
:
10131 ui_out_field_string (uiout
, "what", "unhandled Ada exceptions");
10134 case ex_catch_assert
:
10135 ui_out_field_string (uiout
, "what", "failed Ada assertions");
10139 internal_error (__FILE__
, __LINE__
, _("unexpected catchpoint type"));
10144 /* Implement the PRINT_MENTION method in the breakpoint_ops structure
10145 for all exception catchpoint kinds. */
10148 print_mention_exception (enum exception_catchpoint_kind ex
,
10149 struct breakpoint
*b
)
10153 case ex_catch_exception
:
10154 if (b
->exp_string
!= NULL
)
10155 printf_filtered (_("Catchpoint %d: `%s' Ada exception"),
10156 b
->number
, b
->exp_string
);
10158 printf_filtered (_("Catchpoint %d: all Ada exceptions"), b
->number
);
10162 case ex_catch_exception_unhandled
:
10163 printf_filtered (_("Catchpoint %d: unhandled Ada exceptions"),
10167 case ex_catch_assert
:
10168 printf_filtered (_("Catchpoint %d: failed Ada assertions"), b
->number
);
10172 internal_error (__FILE__
, __LINE__
, _("unexpected catchpoint type"));
10177 /* Virtual table for "catch exception" breakpoints. */
10179 static enum print_stop_action
10180 print_it_catch_exception (struct breakpoint
*b
)
10182 return print_it_exception (ex_catch_exception
, b
);
10186 print_one_catch_exception (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
10188 print_one_exception (ex_catch_exception
, b
, last_addr
);
10192 print_mention_catch_exception (struct breakpoint
*b
)
10194 print_mention_exception (ex_catch_exception
, b
);
10197 static struct breakpoint_ops catch_exception_breakpoint_ops
=
10201 NULL
, /* breakpoint_hit */
10202 print_it_catch_exception
,
10203 print_one_catch_exception
,
10204 print_mention_catch_exception
10207 /* Virtual table for "catch exception unhandled" breakpoints. */
10209 static enum print_stop_action
10210 print_it_catch_exception_unhandled (struct breakpoint
*b
)
10212 return print_it_exception (ex_catch_exception_unhandled
, b
);
10216 print_one_catch_exception_unhandled (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
10218 print_one_exception (ex_catch_exception_unhandled
, b
, last_addr
);
10222 print_mention_catch_exception_unhandled (struct breakpoint
*b
)
10224 print_mention_exception (ex_catch_exception_unhandled
, b
);
10227 static struct breakpoint_ops catch_exception_unhandled_breakpoint_ops
= {
10230 NULL
, /* breakpoint_hit */
10231 print_it_catch_exception_unhandled
,
10232 print_one_catch_exception_unhandled
,
10233 print_mention_catch_exception_unhandled
10236 /* Virtual table for "catch assert" breakpoints. */
10238 static enum print_stop_action
10239 print_it_catch_assert (struct breakpoint
*b
)
10241 return print_it_exception (ex_catch_assert
, b
);
10245 print_one_catch_assert (struct breakpoint
*b
, CORE_ADDR
*last_addr
)
10247 print_one_exception (ex_catch_assert
, b
, last_addr
);
10251 print_mention_catch_assert (struct breakpoint
*b
)
10253 print_mention_exception (ex_catch_assert
, b
);
10256 static struct breakpoint_ops catch_assert_breakpoint_ops
= {
10259 NULL
, /* breakpoint_hit */
10260 print_it_catch_assert
,
10261 print_one_catch_assert
,
10262 print_mention_catch_assert
10265 /* Return non-zero if B is an Ada exception catchpoint. */
10268 ada_exception_catchpoint_p (struct breakpoint
*b
)
10270 return (b
->ops
== &catch_exception_breakpoint_ops
10271 || b
->ops
== &catch_exception_unhandled_breakpoint_ops
10272 || b
->ops
== &catch_assert_breakpoint_ops
);
10275 /* Return a newly allocated copy of the first space-separated token
10276 in ARGSP, and then adjust ARGSP to point immediately after that
10279 Return NULL if ARGPS does not contain any more tokens. */
10282 ada_get_next_arg (char **argsp
)
10284 char *args
= *argsp
;
10288 /* Skip any leading white space. */
10290 while (isspace (*args
))
10293 if (args
[0] == '\0')
10294 return NULL
; /* No more arguments. */
10296 /* Find the end of the current argument. */
10299 while (*end
!= '\0' && !isspace (*end
))
10302 /* Adjust ARGSP to point to the start of the next argument. */
10306 /* Make a copy of the current argument and return it. */
10308 result
= xmalloc (end
- args
+ 1);
10309 strncpy (result
, args
, end
- args
);
10310 result
[end
- args
] = '\0';
10315 /* Split the arguments specified in a "catch exception" command.
10316 Set EX to the appropriate catchpoint type.
10317 Set EXP_STRING to the name of the specific exception if
10318 specified by the user. */
10321 catch_ada_exception_command_split (char *args
,
10322 enum exception_catchpoint_kind
*ex
,
10325 struct cleanup
*old_chain
= make_cleanup (null_cleanup
, NULL
);
10326 char *exception_name
;
10328 exception_name
= ada_get_next_arg (&args
);
10329 make_cleanup (xfree
, exception_name
);
10331 /* Check that we do not have any more arguments. Anything else
10334 while (isspace (*args
))
10337 if (args
[0] != '\0')
10338 error (_("Junk at end of expression"));
10340 discard_cleanups (old_chain
);
10342 if (exception_name
== NULL
)
10344 /* Catch all exceptions. */
10345 *ex
= ex_catch_exception
;
10346 *exp_string
= NULL
;
10348 else if (strcmp (exception_name
, "unhandled") == 0)
10350 /* Catch unhandled exceptions. */
10351 *ex
= ex_catch_exception_unhandled
;
10352 *exp_string
= NULL
;
10356 /* Catch a specific exception. */
10357 *ex
= ex_catch_exception
;
10358 *exp_string
= exception_name
;
10362 /* Return the name of the symbol on which we should break in order to
10363 implement a catchpoint of the EX kind. */
10365 static const char *
10366 ada_exception_sym_name (enum exception_catchpoint_kind ex
)
10368 gdb_assert (exception_info
!= NULL
);
10372 case ex_catch_exception
:
10373 return (exception_info
->catch_exception_sym
);
10375 case ex_catch_exception_unhandled
:
10376 return (exception_info
->catch_exception_unhandled_sym
);
10378 case ex_catch_assert
:
10379 return (exception_info
->catch_assert_sym
);
10382 internal_error (__FILE__
, __LINE__
,
10383 _("unexpected catchpoint kind (%d)"), ex
);
10387 /* Return the breakpoint ops "virtual table" used for catchpoints
10390 static struct breakpoint_ops
*
10391 ada_exception_breakpoint_ops (enum exception_catchpoint_kind ex
)
10395 case ex_catch_exception
:
10396 return (&catch_exception_breakpoint_ops
);
10398 case ex_catch_exception_unhandled
:
10399 return (&catch_exception_unhandled_breakpoint_ops
);
10401 case ex_catch_assert
:
10402 return (&catch_assert_breakpoint_ops
);
10405 internal_error (__FILE__
, __LINE__
,
10406 _("unexpected catchpoint kind (%d)"), ex
);
10410 /* Return the condition that will be used to match the current exception
10411 being raised with the exception that the user wants to catch. This
10412 assumes that this condition is used when the inferior just triggered
10413 an exception catchpoint.
10415 The string returned is a newly allocated string that needs to be
10416 deallocated later. */
10419 ada_exception_catchpoint_cond_string (const char *exp_string
)
10423 /* The standard exceptions are a special case. They are defined in
10424 runtime units that have been compiled without debugging info; if
10425 EXP_STRING is the not-fully-qualified name of a standard
10426 exception (e.g. "constraint_error") then, during the evaluation
10427 of the condition expression, the symbol lookup on this name would
10428 *not* return this standard exception. The catchpoint condition
10429 may then be set only on user-defined exceptions which have the
10430 same not-fully-qualified name (e.g. my_package.constraint_error).
10432 To avoid this unexcepted behavior, these standard exceptions are
10433 systematically prefixed by "standard". This means that "catch
10434 exception constraint_error" is rewritten into "catch exception
10435 standard.constraint_error".
10437 If an exception named contraint_error is defined in another package of
10438 the inferior program, then the only way to specify this exception as a
10439 breakpoint condition is to use its fully-qualified named:
10440 e.g. my_package.constraint_error. */
10442 for (i
= 0; i
< sizeof (standard_exc
) / sizeof (char *); i
++)
10444 if (strcmp (standard_exc
[i
], exp_string
) == 0)
10446 return xstrprintf ("long_integer (e) = long_integer (&standard.%s)",
10450 return xstrprintf ("long_integer (e) = long_integer (&%s)", exp_string
);
10453 /* Return the expression corresponding to COND_STRING evaluated at SAL. */
10455 static struct expression
*
10456 ada_parse_catchpoint_condition (char *cond_string
,
10457 struct symtab_and_line sal
)
10459 return (parse_exp_1 (&cond_string
, block_for_pc (sal
.pc
), 0));
10462 /* Return the symtab_and_line that should be used to insert an exception
10463 catchpoint of the TYPE kind.
10465 EX_STRING should contain the name of a specific exception
10466 that the catchpoint should catch, or NULL otherwise.
10468 The idea behind all the remaining parameters is that their names match
10469 the name of certain fields in the breakpoint structure that are used to
10470 handle exception catchpoints. This function returns the value to which
10471 these fields should be set, depending on the type of catchpoint we need
10474 If COND and COND_STRING are both non-NULL, any value they might
10475 hold will be free'ed, and then replaced by newly allocated ones.
10476 These parameters are left untouched otherwise. */
10478 static struct symtab_and_line
10479 ada_exception_sal (enum exception_catchpoint_kind ex
, char *exp_string
,
10480 char **addr_string
, char **cond_string
,
10481 struct expression
**cond
, struct breakpoint_ops
**ops
)
10483 const char *sym_name
;
10484 struct symbol
*sym
;
10485 struct symtab_and_line sal
;
10487 /* First, find out which exception support info to use. */
10488 ada_exception_support_info_sniffer ();
10490 /* Then lookup the function on which we will break in order to catch
10491 the Ada exceptions requested by the user. */
10493 sym_name
= ada_exception_sym_name (ex
);
10494 sym
= standard_lookup (sym_name
, NULL
, VAR_DOMAIN
);
10496 /* The symbol we're looking up is provided by a unit in the GNAT runtime
10497 that should be compiled with debugging information. As a result, we
10498 expect to find that symbol in the symtabs. If we don't find it, then
10499 the target most likely does not support Ada exceptions, or we cannot
10500 insert exception breakpoints yet, because the GNAT runtime hasn't been
10503 /* brobecker/2006-12-26: It is conceivable that the runtime was compiled
10504 in such a way that no debugging information is produced for the symbol
10505 we are looking for. In this case, we could search the minimal symbols
10506 as a fall-back mechanism. This would still be operating in degraded
10507 mode, however, as we would still be missing the debugging information
10508 that is needed in order to extract the name of the exception being
10509 raised (this name is printed in the catchpoint message, and is also
10510 used when trying to catch a specific exception). We do not handle
10511 this case for now. */
10514 error (_("Unable to break on '%s' in this configuration."), sym_name
);
10516 /* Make sure that the symbol we found corresponds to a function. */
10517 if (SYMBOL_CLASS (sym
) != LOC_BLOCK
)
10518 error (_("Symbol \"%s\" is not a function (class = %d)"),
10519 sym_name
, SYMBOL_CLASS (sym
));
10521 sal
= find_function_start_sal (sym
, 1);
10523 /* Set ADDR_STRING. */
10525 *addr_string
= xstrdup (sym_name
);
10527 /* Set the COND and COND_STRING (if not NULL). */
10529 if (cond_string
!= NULL
&& cond
!= NULL
)
10531 if (*cond_string
!= NULL
)
10533 xfree (*cond_string
);
10534 *cond_string
= NULL
;
10541 if (exp_string
!= NULL
)
10543 *cond_string
= ada_exception_catchpoint_cond_string (exp_string
);
10544 *cond
= ada_parse_catchpoint_condition (*cond_string
, sal
);
10549 *ops
= ada_exception_breakpoint_ops (ex
);
10554 /* Parse the arguments (ARGS) of the "catch exception" command.
10556 Set TYPE to the appropriate exception catchpoint type.
10557 If the user asked the catchpoint to catch only a specific
10558 exception, then save the exception name in ADDR_STRING.
10560 See ada_exception_sal for a description of all the remaining
10561 function arguments of this function. */
10563 struct symtab_and_line
10564 ada_decode_exception_location (char *args
, char **addr_string
,
10565 char **exp_string
, char **cond_string
,
10566 struct expression
**cond
,
10567 struct breakpoint_ops
**ops
)
10569 enum exception_catchpoint_kind ex
;
10571 catch_ada_exception_command_split (args
, &ex
, exp_string
);
10572 return ada_exception_sal (ex
, *exp_string
, addr_string
, cond_string
,
10576 struct symtab_and_line
10577 ada_decode_assert_location (char *args
, char **addr_string
,
10578 struct breakpoint_ops
**ops
)
10580 /* Check that no argument where provided at the end of the command. */
10584 while (isspace (*args
))
10587 error (_("Junk at end of arguments."));
10590 return ada_exception_sal (ex_catch_assert
, NULL
, addr_string
, NULL
, NULL
,
10595 /* Information about operators given special treatment in functions
10597 /* Format: OP_DEFN (<operator>, <operator length>, <# args>, <binop>). */
10599 #define ADA_OPERATORS \
10600 OP_DEFN (OP_VAR_VALUE, 4, 0, 0) \
10601 OP_DEFN (BINOP_IN_BOUNDS, 3, 2, 0) \
10602 OP_DEFN (TERNOP_IN_RANGE, 1, 3, 0) \
10603 OP_DEFN (OP_ATR_FIRST, 1, 2, 0) \
10604 OP_DEFN (OP_ATR_LAST, 1, 2, 0) \
10605 OP_DEFN (OP_ATR_LENGTH, 1, 2, 0) \
10606 OP_DEFN (OP_ATR_IMAGE, 1, 2, 0) \
10607 OP_DEFN (OP_ATR_MAX, 1, 3, 0) \
10608 OP_DEFN (OP_ATR_MIN, 1, 3, 0) \
10609 OP_DEFN (OP_ATR_MODULUS, 1, 1, 0) \
10610 OP_DEFN (OP_ATR_POS, 1, 2, 0) \
10611 OP_DEFN (OP_ATR_SIZE, 1, 1, 0) \
10612 OP_DEFN (OP_ATR_TAG, 1, 1, 0) \
10613 OP_DEFN (OP_ATR_VAL, 1, 2, 0) \
10614 OP_DEFN (UNOP_QUAL, 3, 1, 0) \
10615 OP_DEFN (UNOP_IN_RANGE, 3, 1, 0) \
10616 OP_DEFN (OP_OTHERS, 1, 1, 0) \
10617 OP_DEFN (OP_POSITIONAL, 3, 1, 0) \
10618 OP_DEFN (OP_DISCRETE_RANGE, 1, 2, 0)
10621 ada_operator_length (struct expression
*exp
, int pc
, int *oplenp
, int *argsp
)
10623 switch (exp
->elts
[pc
- 1].opcode
)
10626 operator_length_standard (exp
, pc
, oplenp
, argsp
);
10629 #define OP_DEFN(op, len, args, binop) \
10630 case op: *oplenp = len; *argsp = args; break;
10636 *argsp
= longest_to_int (exp
->elts
[pc
- 2].longconst
);
10641 *argsp
= longest_to_int (exp
->elts
[pc
- 2].longconst
) + 1;
10647 ada_op_name (enum exp_opcode opcode
)
10652 return op_name_standard (opcode
);
10654 #define OP_DEFN(op, len, args, binop) case op: return #op;
10659 return "OP_AGGREGATE";
10661 return "OP_CHOICES";
10667 /* As for operator_length, but assumes PC is pointing at the first
10668 element of the operator, and gives meaningful results only for the
10669 Ada-specific operators, returning 0 for *OPLENP and *ARGSP otherwise. */
10672 ada_forward_operator_length (struct expression
*exp
, int pc
,
10673 int *oplenp
, int *argsp
)
10675 switch (exp
->elts
[pc
].opcode
)
10678 *oplenp
= *argsp
= 0;
10681 #define OP_DEFN(op, len, args, binop) \
10682 case op: *oplenp = len; *argsp = args; break;
10688 *argsp
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
10693 *argsp
= longest_to_int (exp
->elts
[pc
+ 1].longconst
) + 1;
10699 int len
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
10700 *oplenp
= 4 + BYTES_TO_EXP_ELEM (len
+ 1);
10708 ada_dump_subexp_body (struct expression
*exp
, struct ui_file
*stream
, int elt
)
10710 enum exp_opcode op
= exp
->elts
[elt
].opcode
;
10715 ada_forward_operator_length (exp
, elt
, &oplen
, &nargs
);
10719 /* Ada attributes ('Foo). */
10722 case OP_ATR_LENGTH
:
10726 case OP_ATR_MODULUS
:
10733 case UNOP_IN_RANGE
:
10735 /* XXX: gdb_sprint_host_address, type_sprint */
10736 fprintf_filtered (stream
, _("Type @"));
10737 gdb_print_host_address (exp
->elts
[pc
+ 1].type
, stream
);
10738 fprintf_filtered (stream
, " (");
10739 type_print (exp
->elts
[pc
+ 1].type
, NULL
, stream
, 0);
10740 fprintf_filtered (stream
, ")");
10742 case BINOP_IN_BOUNDS
:
10743 fprintf_filtered (stream
, " (%d)",
10744 longest_to_int (exp
->elts
[pc
+ 2].longconst
));
10746 case TERNOP_IN_RANGE
:
10751 case OP_DISCRETE_RANGE
:
10752 case OP_POSITIONAL
:
10759 char *name
= &exp
->elts
[elt
+ 2].string
;
10760 int len
= longest_to_int (exp
->elts
[elt
+ 1].longconst
);
10761 fprintf_filtered (stream
, "Text: `%.*s'", len
, name
);
10766 return dump_subexp_body_standard (exp
, stream
, elt
);
10770 for (i
= 0; i
< nargs
; i
+= 1)
10771 elt
= dump_subexp (exp
, stream
, elt
);
10776 /* The Ada extension of print_subexp (q.v.). */
10779 ada_print_subexp (struct expression
*exp
, int *pos
,
10780 struct ui_file
*stream
, enum precedence prec
)
10782 int oplen
, nargs
, i
;
10784 enum exp_opcode op
= exp
->elts
[pc
].opcode
;
10786 ada_forward_operator_length (exp
, pc
, &oplen
, &nargs
);
10793 print_subexp_standard (exp
, pos
, stream
, prec
);
10797 fputs_filtered (SYMBOL_NATURAL_NAME (exp
->elts
[pc
+ 2].symbol
), stream
);
10800 case BINOP_IN_BOUNDS
:
10801 /* XXX: sprint_subexp */
10802 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
10803 fputs_filtered (" in ", stream
);
10804 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
10805 fputs_filtered ("'range", stream
);
10806 if (exp
->elts
[pc
+ 1].longconst
> 1)
10807 fprintf_filtered (stream
, "(%ld)",
10808 (long) exp
->elts
[pc
+ 1].longconst
);
10811 case TERNOP_IN_RANGE
:
10812 if (prec
>= PREC_EQUAL
)
10813 fputs_filtered ("(", stream
);
10814 /* XXX: sprint_subexp */
10815 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
10816 fputs_filtered (" in ", stream
);
10817 print_subexp (exp
, pos
, stream
, PREC_EQUAL
);
10818 fputs_filtered (" .. ", stream
);
10819 print_subexp (exp
, pos
, stream
, PREC_EQUAL
);
10820 if (prec
>= PREC_EQUAL
)
10821 fputs_filtered (")", stream
);
10826 case OP_ATR_LENGTH
:
10830 case OP_ATR_MODULUS
:
10835 if (exp
->elts
[*pos
].opcode
== OP_TYPE
)
10837 if (TYPE_CODE (exp
->elts
[*pos
+ 1].type
) != TYPE_CODE_VOID
)
10838 LA_PRINT_TYPE (exp
->elts
[*pos
+ 1].type
, "", stream
, 0, 0);
10842 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
10843 fprintf_filtered (stream
, "'%s", ada_attribute_name (op
));
10847 for (tem
= 1; tem
< nargs
; tem
+= 1)
10849 fputs_filtered ((tem
== 1) ? " (" : ", ", stream
);
10850 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
10852 fputs_filtered (")", stream
);
10857 type_print (exp
->elts
[pc
+ 1].type
, "", stream
, 0);
10858 fputs_filtered ("'(", stream
);
10859 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
10860 fputs_filtered (")", stream
);
10863 case UNOP_IN_RANGE
:
10864 /* XXX: sprint_subexp */
10865 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
10866 fputs_filtered (" in ", stream
);
10867 LA_PRINT_TYPE (exp
->elts
[pc
+ 1].type
, "", stream
, 1, 0);
10870 case OP_DISCRETE_RANGE
:
10871 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
10872 fputs_filtered ("..", stream
);
10873 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
10877 fputs_filtered ("others => ", stream
);
10878 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
10882 for (i
= 0; i
< nargs
-1; i
+= 1)
10885 fputs_filtered ("|", stream
);
10886 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
10888 fputs_filtered (" => ", stream
);
10889 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
10892 case OP_POSITIONAL
:
10893 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
10897 fputs_filtered ("(", stream
);
10898 for (i
= 0; i
< nargs
; i
+= 1)
10901 fputs_filtered (", ", stream
);
10902 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
10904 fputs_filtered (")", stream
);
10909 /* Table mapping opcodes into strings for printing operators
10910 and precedences of the operators. */
10912 static const struct op_print ada_op_print_tab
[] = {
10913 {":=", BINOP_ASSIGN
, PREC_ASSIGN
, 1},
10914 {"or else", BINOP_LOGICAL_OR
, PREC_LOGICAL_OR
, 0},
10915 {"and then", BINOP_LOGICAL_AND
, PREC_LOGICAL_AND
, 0},
10916 {"or", BINOP_BITWISE_IOR
, PREC_BITWISE_IOR
, 0},
10917 {"xor", BINOP_BITWISE_XOR
, PREC_BITWISE_XOR
, 0},
10918 {"and", BINOP_BITWISE_AND
, PREC_BITWISE_AND
, 0},
10919 {"=", BINOP_EQUAL
, PREC_EQUAL
, 0},
10920 {"/=", BINOP_NOTEQUAL
, PREC_EQUAL
, 0},
10921 {"<=", BINOP_LEQ
, PREC_ORDER
, 0},
10922 {">=", BINOP_GEQ
, PREC_ORDER
, 0},
10923 {">", BINOP_GTR
, PREC_ORDER
, 0},
10924 {"<", BINOP_LESS
, PREC_ORDER
, 0},
10925 {">>", BINOP_RSH
, PREC_SHIFT
, 0},
10926 {"<<", BINOP_LSH
, PREC_SHIFT
, 0},
10927 {"+", BINOP_ADD
, PREC_ADD
, 0},
10928 {"-", BINOP_SUB
, PREC_ADD
, 0},
10929 {"&", BINOP_CONCAT
, PREC_ADD
, 0},
10930 {"*", BINOP_MUL
, PREC_MUL
, 0},
10931 {"/", BINOP_DIV
, PREC_MUL
, 0},
10932 {"rem", BINOP_REM
, PREC_MUL
, 0},
10933 {"mod", BINOP_MOD
, PREC_MUL
, 0},
10934 {"**", BINOP_EXP
, PREC_REPEAT
, 0},
10935 {"@", BINOP_REPEAT
, PREC_REPEAT
, 0},
10936 {"-", UNOP_NEG
, PREC_PREFIX
, 0},
10937 {"+", UNOP_PLUS
, PREC_PREFIX
, 0},
10938 {"not ", UNOP_LOGICAL_NOT
, PREC_PREFIX
, 0},
10939 {"not ", UNOP_COMPLEMENT
, PREC_PREFIX
, 0},
10940 {"abs ", UNOP_ABS
, PREC_PREFIX
, 0},
10941 {".all", UNOP_IND
, PREC_SUFFIX
, 1},
10942 {"'access", UNOP_ADDR
, PREC_SUFFIX
, 1},
10943 {"'size", OP_ATR_SIZE
, PREC_SUFFIX
, 1},
10947 enum ada_primitive_types
{
10948 ada_primitive_type_int
,
10949 ada_primitive_type_long
,
10950 ada_primitive_type_short
,
10951 ada_primitive_type_char
,
10952 ada_primitive_type_float
,
10953 ada_primitive_type_double
,
10954 ada_primitive_type_void
,
10955 ada_primitive_type_long_long
,
10956 ada_primitive_type_long_double
,
10957 ada_primitive_type_natural
,
10958 ada_primitive_type_positive
,
10959 ada_primitive_type_system_address
,
10960 nr_ada_primitive_types
10964 ada_language_arch_info (struct gdbarch
*gdbarch
,
10965 struct language_arch_info
*lai
)
10967 const struct builtin_type
*builtin
= builtin_type (gdbarch
);
10968 lai
->primitive_type_vector
10969 = GDBARCH_OBSTACK_CALLOC (gdbarch
, nr_ada_primitive_types
+ 1,
10971 lai
->primitive_type_vector
[ada_primitive_type_int
] =
10972 init_type (TYPE_CODE_INT
,
10973 gdbarch_int_bit (gdbarch
) / TARGET_CHAR_BIT
,
10974 0, "integer", (struct objfile
*) NULL
);
10975 lai
->primitive_type_vector
[ada_primitive_type_long
] =
10976 init_type (TYPE_CODE_INT
,
10977 gdbarch_long_bit (gdbarch
) / TARGET_CHAR_BIT
,
10978 0, "long_integer", (struct objfile
*) NULL
);
10979 lai
->primitive_type_vector
[ada_primitive_type_short
] =
10980 init_type (TYPE_CODE_INT
,
10981 gdbarch_short_bit (gdbarch
) / TARGET_CHAR_BIT
,
10982 0, "short_integer", (struct objfile
*) NULL
);
10983 lai
->string_char_type
=
10984 lai
->primitive_type_vector
[ada_primitive_type_char
] =
10985 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
10986 0, "character", (struct objfile
*) NULL
);
10987 lai
->primitive_type_vector
[ada_primitive_type_float
] =
10988 init_type (TYPE_CODE_FLT
,
10989 gdbarch_float_bit (gdbarch
)/ TARGET_CHAR_BIT
,
10990 0, "float", (struct objfile
*) NULL
);
10991 lai
->primitive_type_vector
[ada_primitive_type_double
] =
10992 init_type (TYPE_CODE_FLT
,
10993 gdbarch_double_bit (gdbarch
) / TARGET_CHAR_BIT
,
10994 0, "long_float", (struct objfile
*) NULL
);
10995 lai
->primitive_type_vector
[ada_primitive_type_long_long
] =
10996 init_type (TYPE_CODE_INT
,
10997 gdbarch_long_long_bit (gdbarch
) / TARGET_CHAR_BIT
,
10998 0, "long_long_integer", (struct objfile
*) NULL
);
10999 lai
->primitive_type_vector
[ada_primitive_type_long_double
] =
11000 init_type (TYPE_CODE_FLT
,
11001 gdbarch_double_bit (gdbarch
) / TARGET_CHAR_BIT
,
11002 0, "long_long_float", (struct objfile
*) NULL
);
11003 lai
->primitive_type_vector
[ada_primitive_type_natural
] =
11004 init_type (TYPE_CODE_INT
,
11005 gdbarch_int_bit (gdbarch
) / TARGET_CHAR_BIT
,
11006 0, "natural", (struct objfile
*) NULL
);
11007 lai
->primitive_type_vector
[ada_primitive_type_positive
] =
11008 init_type (TYPE_CODE_INT
,
11009 gdbarch_int_bit (gdbarch
) / TARGET_CHAR_BIT
,
11010 0, "positive", (struct objfile
*) NULL
);
11011 lai
->primitive_type_vector
[ada_primitive_type_void
] = builtin
->builtin_void
;
11013 lai
->primitive_type_vector
[ada_primitive_type_system_address
] =
11014 lookup_pointer_type (init_type (TYPE_CODE_VOID
, 1, 0, "void",
11015 (struct objfile
*) NULL
));
11016 TYPE_NAME (lai
->primitive_type_vector
[ada_primitive_type_system_address
])
11017 = "system__address";
11019 lai
->bool_type_symbol
= NULL
;
11020 lai
->bool_type_default
= builtin
->builtin_bool
;
11023 /* Language vector */
11025 /* Not really used, but needed in the ada_language_defn. */
11028 emit_char (int c
, struct type
*type
, struct ui_file
*stream
, int quoter
)
11030 ada_emit_char (c
, type
, stream
, quoter
, 1);
11036 warnings_issued
= 0;
11037 return ada_parse ();
11040 static const struct exp_descriptor ada_exp_descriptor
= {
11042 ada_operator_length
,
11044 ada_dump_subexp_body
,
11045 ada_evaluate_subexp
11048 const struct language_defn ada_language_defn
= {
11049 "ada", /* Language name */
11053 case_sensitive_on
, /* Yes, Ada is case-insensitive, but
11054 that's not quite what this means. */
11056 macro_expansion_no
,
11057 &ada_exp_descriptor
,
11061 ada_printchar
, /* Print a character constant */
11062 ada_printstr
, /* Function to print string constant */
11063 emit_char
, /* Function to print single char (not used) */
11064 ada_print_type
, /* Print a type using appropriate syntax */
11065 default_print_typedef
, /* Print a typedef using appropriate syntax */
11066 ada_val_print
, /* Print a value using appropriate syntax */
11067 ada_value_print
, /* Print a top-level value */
11068 NULL
, /* Language specific skip_trampoline */
11069 NULL
, /* name_of_this */
11070 ada_lookup_symbol_nonlocal
, /* Looking up non-local symbols. */
11071 basic_lookup_transparent_type
, /* lookup_transparent_type */
11072 ada_la_decode
, /* Language specific symbol demangler */
11073 NULL
, /* Language specific class_name_from_physname */
11074 ada_op_print_tab
, /* expression operators for printing */
11075 0, /* c-style arrays */
11076 1, /* String lower bound */
11077 ada_get_gdb_completer_word_break_characters
,
11078 ada_make_symbol_completion_list
,
11079 ada_language_arch_info
,
11080 ada_print_array_index
,
11081 default_pass_by_reference
,
11086 /* Provide a prototype to silence -Wmissing-prototypes. */
11087 extern initialize_file_ftype _initialize_ada_language
;
11090 _initialize_ada_language (void)
11092 add_language (&ada_language_defn
);
11094 varsize_limit
= 65536;
11096 obstack_init (&symbol_list_obstack
);
11098 decoded_names_store
= htab_create_alloc
11099 (256, htab_hash_string
, (int (*)(const void *, const void *)) streq
,
11100 NULL
, xcalloc
, xfree
);
11102 observer_attach_executable_changed (ada_executable_changed_observer
);