1 /* Ada language support routines for GDB, the GNU debugger. Copyright
2 1992, 1993, 1994, 1997, 1998, 1999, 2000, 2003, 2004.
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
23 #include "gdb_string.h"
27 #include "gdb_regex.h"
32 #include "expression.h"
33 #include "parser-defs.h"
39 #include "breakpoint.h"
42 #include "gdb_obstack.h"
44 #include "completer.h"
51 #include "dictionary.h"
53 #ifndef ADA_RETAIN_DOTS
54 #define ADA_RETAIN_DOTS 0
57 /* Define whether or not the C operator '/' truncates towards zero for
58 differently signed operands (truncation direction is undefined in C).
59 Copied from valarith.c. */
61 #ifndef TRUNCATION_TOWARDS_ZERO
62 #define TRUNCATION_TOWARDS_ZERO ((-5 / 2) == -2)
65 /* A structure that contains a vector of strings.
66 The main purpose of this type is to group the vector and its
67 associated parameters in one structure. This makes it easier
68 to handle and pass around. */
72 char **array
; /* The vector itself. */
73 int index
; /* Index of the next available element in the array. */
74 size_t size
; /* The number of entries allocated in the array. */
77 static struct string_vector
xnew_string_vector (int initial_size
);
78 static void string_vector_append (struct string_vector
*sv
, char *str
);
80 static const char *ada_unqualified_name (const char *decoded_name
);
81 static char *add_angle_brackets (const char *str
);
82 static void extract_string (CORE_ADDR addr
, char *buf
);
83 static char *function_name_from_pc (CORE_ADDR pc
);
85 static struct type
*ada_create_fundamental_type (struct objfile
*, int);
87 static void modify_general_field (char *, LONGEST
, int, int);
89 static struct type
*desc_base_type (struct type
*);
91 static struct type
*desc_bounds_type (struct type
*);
93 static struct value
*desc_bounds (struct value
*);
95 static int fat_pntr_bounds_bitpos (struct type
*);
97 static int fat_pntr_bounds_bitsize (struct type
*);
99 static struct type
*desc_data_type (struct type
*);
101 static struct value
*desc_data (struct value
*);
103 static int fat_pntr_data_bitpos (struct type
*);
105 static int fat_pntr_data_bitsize (struct type
*);
107 static struct value
*desc_one_bound (struct value
*, int, int);
109 static int desc_bound_bitpos (struct type
*, int, int);
111 static int desc_bound_bitsize (struct type
*, int, int);
113 static struct type
*desc_index_type (struct type
*, int);
115 static int desc_arity (struct type
*);
117 static int ada_type_match (struct type
*, struct type
*, int);
119 static int ada_args_match (struct symbol
*, struct value
**, int);
121 static struct value
*ensure_lval (struct value
*, CORE_ADDR
*);
123 static struct value
*convert_actual (struct value
*, struct type
*,
126 static struct value
*make_array_descriptor (struct type
*, struct value
*,
129 static void ada_add_block_symbols (struct obstack
*,
130 struct block
*, const char *,
131 domain_enum
, struct objfile
*,
132 struct symtab
*, int);
134 static int is_nonfunction (struct ada_symbol_info
*, int);
136 static void add_defn_to_vec (struct obstack
*, struct symbol
*, struct block
*,
139 static int num_defns_collected (struct obstack
*);
141 static struct ada_symbol_info
*defns_collected (struct obstack
*, int);
143 static struct partial_symbol
*ada_lookup_partial_symbol (struct partial_symtab
144 *, const char *, int,
147 static struct symtab
*symtab_for_sym (struct symbol
*);
149 static struct value
*resolve_subexp (struct expression
**, int *, int,
152 static void replace_operator_with_call (struct expression
**, int, int, int,
153 struct symbol
*, struct block
*);
155 static int possible_user_operator_p (enum exp_opcode
, struct value
**);
157 static char *ada_op_name (enum exp_opcode
);
159 static const char *ada_decoded_op_name (enum exp_opcode
);
161 static int numeric_type_p (struct type
*);
163 static int integer_type_p (struct type
*);
165 static int scalar_type_p (struct type
*);
167 static int discrete_type_p (struct type
*);
169 static struct type
*ada_lookup_struct_elt_type (struct type
*, char *,
172 static char *extended_canonical_line_spec (struct symtab_and_line
,
175 static struct value
*evaluate_subexp (struct type
*, struct expression
*,
178 static struct value
*evaluate_subexp_type (struct expression
*, int *);
180 static struct type
*ada_create_fundamental_type (struct objfile
*, int);
182 static int is_dynamic_field (struct type
*, int);
184 static struct type
*to_fixed_variant_branch_type (struct type
*, char *,
185 CORE_ADDR
, struct value
*);
187 static struct type
*to_fixed_array_type (struct type
*, struct value
*, int);
189 static struct type
*to_fixed_range_type (char *, struct value
*,
192 static struct type
*to_static_fixed_type (struct type
*);
194 static struct value
*unwrap_value (struct value
*);
196 static struct type
*packed_array_type (struct type
*, long *);
198 static struct type
*decode_packed_array_type (struct type
*);
200 static struct value
*decode_packed_array (struct value
*);
202 static struct value
*value_subscript_packed (struct value
*, int,
205 static struct value
*coerce_unspec_val_to_type (struct value
*,
208 static struct value
*get_var_value (char *, char *);
210 static int lesseq_defined_than (struct symbol
*, struct symbol
*);
212 static int equiv_types (struct type
*, struct type
*);
214 static int is_name_suffix (const char *);
216 static int wild_match (const char *, int, const char *);
218 static struct symtabs_and_lines
219 find_sal_from_funcs_and_line (const char *, int,
220 struct ada_symbol_info
*, int);
222 static int find_line_in_linetable (struct linetable
*, int,
223 struct ada_symbol_info
*,
226 static int find_next_line_in_linetable (struct linetable
*, int, int, int);
228 static void read_all_symtabs (const char *);
230 static int is_plausible_func_for_line (struct symbol
*, int);
232 static struct value
*ada_coerce_ref (struct value
*);
234 static LONGEST
pos_atr (struct value
*);
236 static struct value
*value_pos_atr (struct value
*);
238 static struct value
*value_val_atr (struct type
*, struct value
*);
240 static struct symbol
*standard_lookup (const char *, const struct block
*,
243 extern void symtab_symbol_info (char *regexp
, domain_enum kind
,
246 static struct value
*ada_search_struct_field (char *, struct value
*, int,
249 static struct value
*ada_value_primitive_field (struct value
*, int, int,
252 static int find_struct_field (char *, struct type
*, int,
253 struct type
**, int *, int *, int *);
255 static struct value
*ada_to_fixed_value_create (struct type
*, CORE_ADDR
,
258 static struct value
*ada_to_fixed_value (struct value
*);
260 static void adjust_pc_past_prologue (CORE_ADDR
*);
262 static int ada_resolve_function (struct ada_symbol_info
*, int,
263 struct value
**, int, const char *,
266 static struct value
*ada_coerce_to_simple_array (struct value
*);
268 static int ada_is_direct_array_type (struct type
*);
270 static void error_breakpoint_runtime_sym_not_found (const char *err_desc
);
272 static int is_runtime_sym_defined (const char *name
, int allow_tramp
);
276 /* Maximum-sized dynamic type. */
277 static unsigned int varsize_limit
;
279 /* FIXME: brobecker/2003-09-17: No longer a const because it is
280 returned by a function that does not return a const char *. */
281 static char *ada_completer_word_break_characters
=
283 " \t\n!@#%^&*()+=|~`}{[]\";:?/,-";
285 " \t\n!@#$%^&*()+=|~`}{[]\";:?/,-";
288 /* The name of the symbol to use to get the name of the main subprogram. */
289 static const char ADA_MAIN_PROGRAM_SYMBOL_NAME
[]
290 = "__gnat_ada_main_program_name";
292 /* The name of the runtime function called when an exception is raised. */
293 static const char raise_sym_name
[] = "__gnat_raise_nodefer_with_msg";
295 /* The name of the runtime function called when an unhandled exception
297 static const char raise_unhandled_sym_name
[] = "__gnat_unhandled_exception";
299 /* The name of the runtime function called when an assert failure is
301 static const char raise_assert_sym_name
[] =
302 "system__assertions__raise_assert_failure";
304 /* When GDB stops on an unhandled exception, GDB will go up the stack until
305 if finds a frame corresponding to this function, in order to extract the
306 name of the exception that has been raised from one of the parameters. */
307 static const char process_raise_exception_name
[] =
308 "ada__exceptions__process_raise_exception";
310 /* A string that reflects the longest exception expression rewrite,
311 aside from the exception name. */
312 static const char longest_exception_template
[] =
313 "'__gnat_raise_nodefer_with_msg' if long_integer(e) = long_integer(&)";
315 /* Limit on the number of warnings to raise per expression evaluation. */
316 static int warning_limit
= 2;
318 /* Number of warning messages issued; reset to 0 by cleanups after
319 expression evaluation. */
320 static int warnings_issued
= 0;
322 static const char *known_runtime_file_name_patterns
[] = {
323 ADA_KNOWN_RUNTIME_FILE_NAME_PATTERNS NULL
326 static const char *known_auxiliary_function_name_patterns
[] = {
327 ADA_KNOWN_AUXILIARY_FUNCTION_NAME_PATTERNS NULL
330 /* Space for allocating results of ada_lookup_symbol_list. */
331 static struct obstack symbol_list_obstack
;
335 /* Create a new empty string_vector struct with an initial size of
338 static struct string_vector
339 xnew_string_vector (int initial_size
)
341 struct string_vector result
;
343 result
.array
= (char **) xmalloc ((initial_size
+ 1) * sizeof (char *));
345 result
.size
= initial_size
;
350 /* Add STR at the end of the given string vector SV. If SV is already
351 full, its size is automatically increased (doubled). */
354 string_vector_append (struct string_vector
*sv
, char *str
)
356 if (sv
->index
>= sv
->size
)
357 GROW_VECT (sv
->array
, sv
->size
, sv
->size
* 2);
359 sv
->array
[sv
->index
] = str
;
363 /* Given DECODED_NAME a string holding a symbol name in its
364 decoded form (ie using the Ada dotted notation), returns
365 its unqualified name. */
368 ada_unqualified_name (const char *decoded_name
)
370 const char *result
= strrchr (decoded_name
, '.');
373 result
++; /* Skip the dot... */
375 result
= decoded_name
;
380 /* Return a string starting with '<', followed by STR, and '>'.
381 The result is good until the next call. */
384 add_angle_brackets (const char *str
)
386 static char *result
= NULL
;
389 result
= (char *) xmalloc ((strlen (str
) + 3) * sizeof (char));
391 sprintf (result
, "<%s>", str
);
396 ada_get_gdb_completer_word_break_characters (void)
398 return ada_completer_word_break_characters
;
401 /* Read the string located at ADDR from the inferior and store the
405 extract_string (CORE_ADDR addr
, char *buf
)
409 /* Loop, reading one byte at a time, until we reach the '\000'
410 end-of-string marker. */
413 target_read_memory (addr
+ char_index
* sizeof (char),
414 buf
+ char_index
* sizeof (char), sizeof (char));
417 while (buf
[char_index
- 1] != '\000');
420 /* Return the name of the function owning the instruction located at PC.
421 Return NULL if no such function could be found. */
424 function_name_from_pc (CORE_ADDR pc
)
428 if (!find_pc_partial_function (pc
, &func_name
, NULL
, NULL
))
434 /* Assuming *OLD_VECT points to an array of *SIZE objects of size
435 ELEMENT_SIZE, grow it to contain at least MIN_SIZE objects,
436 updating *OLD_VECT and *SIZE as necessary. */
439 grow_vect (void **old_vect
, size_t * size
, size_t min_size
, int element_size
)
441 if (*size
< min_size
)
444 if (*size
< min_size
)
446 *old_vect
= xrealloc (*old_vect
, *size
* element_size
);
450 /* True (non-zero) iff TARGET matches FIELD_NAME up to any trailing
451 suffix of FIELD_NAME beginning "___". */
454 field_name_match (const char *field_name
, const char *target
)
456 int len
= strlen (target
);
458 (strncmp (field_name
, target
, len
) == 0
459 && (field_name
[len
] == '\0'
460 || (strncmp (field_name
+ len
, "___", 3) == 0
461 && strcmp (field_name
+ strlen (field_name
) - 6, "___XVN") != 0)));
465 /* Assuming TYPE is a TYPE_CODE_STRUCT, find the field whose name matches
466 FIELD_NAME, and return its index. This function also handles fields
467 whose name have ___ suffixes because the compiler sometimes alters
468 their name by adding such a suffix to represent fields with certain
469 constraints. If the field could not be found, return a negative
470 number if MAYBE_MISSING is set. Otherwise raise an error. */
473 ada_get_field_index (const struct type
*type
, const char *field_name
,
477 for (fieldno
= 0; fieldno
< TYPE_NFIELDS (type
); fieldno
++)
478 if (field_name_match (TYPE_FIELD_NAME (type
, fieldno
), field_name
))
482 error ("Unable to find field %s in struct %s. Aborting",
483 field_name
, TYPE_NAME (type
));
488 /* The length of the prefix of NAME prior to any "___" suffix. */
491 ada_name_prefix_len (const char *name
)
497 const char *p
= strstr (name
, "___");
499 return strlen (name
);
505 /* Return non-zero if SUFFIX is a suffix of STR.
506 Return zero if STR is null. */
509 is_suffix (const char *str
, const char *suffix
)
515 len2
= strlen (suffix
);
516 return (len1
>= len2
&& strcmp (str
+ len1
- len2
, suffix
) == 0);
519 /* Create a value of type TYPE whose contents come from VALADDR, if it
520 is non-null, and whose memory address (in the inferior) is
524 value_from_contents_and_address (struct type
*type
, char *valaddr
,
527 struct value
*v
= allocate_value (type
);
531 memcpy (VALUE_CONTENTS_RAW (v
), valaddr
, TYPE_LENGTH (type
));
532 VALUE_ADDRESS (v
) = address
;
534 VALUE_LVAL (v
) = lval_memory
;
538 /* The contents of value VAL, treated as a value of type TYPE. The
539 result is an lval in memory if VAL is. */
541 static struct value
*
542 coerce_unspec_val_to_type (struct value
*val
, struct type
*type
)
544 CHECK_TYPEDEF (type
);
545 if (VALUE_TYPE (val
) == type
)
549 struct value
*result
;
551 /* Make sure that the object size is not unreasonable before
552 trying to allocate some memory for it. */
553 if (TYPE_LENGTH (type
) > varsize_limit
)
554 error ("object size is larger than varsize-limit");
556 result
= allocate_value (type
);
557 VALUE_LVAL (result
) = VALUE_LVAL (val
);
558 VALUE_BITSIZE (result
) = VALUE_BITSIZE (val
);
559 VALUE_BITPOS (result
) = VALUE_BITPOS (val
);
560 VALUE_ADDRESS (result
) = VALUE_ADDRESS (val
) + VALUE_OFFSET (val
);
561 if (VALUE_LAZY (val
) ||
562 TYPE_LENGTH (type
) > TYPE_LENGTH (VALUE_TYPE (val
)))
563 VALUE_LAZY (result
) = 1;
565 memcpy (VALUE_CONTENTS_RAW (result
), VALUE_CONTENTS (val
),
572 cond_offset_host (char *valaddr
, long offset
)
577 return valaddr
+ offset
;
581 cond_offset_target (CORE_ADDR address
, long offset
)
586 return address
+ offset
;
589 /* Issue a warning (as for the definition of warning in utils.c, but
590 with exactly one argument rather than ...), unless the limit on the
591 number of warnings has passed during the evaluation of the current
594 lim_warning (const char *format
, long arg
)
596 warnings_issued
+= 1;
597 if (warnings_issued
<= warning_limit
)
598 warning (format
, arg
);
602 ada_translate_error_message (const char *string
)
604 if (strcmp (string
, "Invalid cast.") == 0)
605 return "Invalid type conversion.";
611 MAX_OF_SIZE (int size
)
613 LONGEST top_bit
= (LONGEST
) 1 << (size
*8-2);
614 return top_bit
| (top_bit
-1);
618 MIN_OF_SIZE (int size
)
620 return - MAX_OF_SIZE (size
) - 1;
624 UMAX_OF_SIZE (int size
)
626 ULONGEST top_bit
= (ULONGEST
) 1 << (size
*8-1);
627 return top_bit
| (top_bit
-1);
631 UMIN_OF_SIZE (int size
)
636 /* The largest value in the domain of TYPE, a discrete type, as an integer. */
637 static struct value
*
638 discrete_type_high_bound (struct type
*type
)
640 switch (TYPE_CODE (type
))
642 case TYPE_CODE_RANGE
:
643 return value_from_longest (TYPE_TARGET_TYPE (type
),
644 TYPE_HIGH_BOUND (type
));
647 value_from_longest (type
,
648 TYPE_FIELD_BITPOS (type
, TYPE_NFIELDS (type
)-1));
650 return value_from_longest (type
, MAX_OF_TYPE (type
));
652 error ("Unexpected type in discrete_type_high_bound.");
656 /* The largest value in the domain of TYPE, a discrete type, as an integer. */
657 static struct value
*
658 discrete_type_low_bound (struct type
*type
)
660 switch (TYPE_CODE (type
))
662 case TYPE_CODE_RANGE
:
663 return value_from_longest (TYPE_TARGET_TYPE (type
),
664 TYPE_LOW_BOUND (type
));
666 return value_from_longest (type
, TYPE_FIELD_BITPOS (type
, 0));
668 return value_from_longest (type
, MIN_OF_TYPE (type
));
670 error ("Unexpected type in discrete_type_low_bound.");
674 /* The identity on non-range types. For range types, the underlying
675 non-range scalar type. */
678 base_type (struct type
*type
)
680 while (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_RANGE
)
682 if (type
== TYPE_TARGET_TYPE (type
)
683 || TYPE_TARGET_TYPE (type
) == NULL
)
685 type
= TYPE_TARGET_TYPE (type
);
691 /* Language Selection */
693 /* If the main program is in Ada, return language_ada, otherwise return LANG
694 (the main program is in Ada iif the adainit symbol is found).
696 MAIN_PST is not used. */
699 ada_update_initial_language (enum language lang
,
700 struct partial_symtab
*main_pst
)
702 if (lookup_minimal_symbol ("adainit", (const char *) NULL
,
703 (struct objfile
*) NULL
) != NULL
)
711 /* Table of Ada operators and their GNAT-encoded names. Last entry is pair
714 const struct ada_opname_map ada_opname_table
[] = {
715 {"Oadd", "\"+\"", BINOP_ADD
},
716 {"Osubtract", "\"-\"", BINOP_SUB
},
717 {"Omultiply", "\"*\"", BINOP_MUL
},
718 {"Odivide", "\"/\"", BINOP_DIV
},
719 {"Omod", "\"mod\"", BINOP_MOD
},
720 {"Orem", "\"rem\"", BINOP_REM
},
721 {"Oexpon", "\"**\"", BINOP_EXP
},
722 {"Olt", "\"<\"", BINOP_LESS
},
723 {"Ole", "\"<=\"", BINOP_LEQ
},
724 {"Ogt", "\">\"", BINOP_GTR
},
725 {"Oge", "\">=\"", BINOP_GEQ
},
726 {"Oeq", "\"=\"", BINOP_EQUAL
},
727 {"One", "\"/=\"", BINOP_NOTEQUAL
},
728 {"Oand", "\"and\"", BINOP_BITWISE_AND
},
729 {"Oor", "\"or\"", BINOP_BITWISE_IOR
},
730 {"Oxor", "\"xor\"", BINOP_BITWISE_XOR
},
731 {"Oconcat", "\"&\"", BINOP_CONCAT
},
732 {"Oabs", "\"abs\"", UNOP_ABS
},
733 {"Onot", "\"not\"", UNOP_LOGICAL_NOT
},
734 {"Oadd", "\"+\"", UNOP_PLUS
},
735 {"Osubtract", "\"-\"", UNOP_NEG
},
739 /* Return non-zero if STR should be suppressed in info listings. */
742 is_suppressed_name (const char *str
)
744 if (strncmp (str
, "_ada_", 5) == 0)
746 if (str
[0] == '_' || str
[0] == '\000')
751 const char *suffix
= strstr (str
, "___");
752 if (suffix
!= NULL
&& suffix
[3] != 'X')
755 suffix
= str
+ strlen (str
);
756 for (p
= suffix
- 1; p
!= str
; p
-= 1)
760 if (p
[0] == 'X' && p
[-1] != '_')
764 for (i
= 0; ada_opname_table
[i
].encoded
!= NULL
; i
+= 1)
765 if (strncmp (ada_opname_table
[i
].encoded
, p
,
766 strlen (ada_opname_table
[i
].encoded
)) == 0)
775 /* The "encoded" form of DECODED, according to GNAT conventions.
776 The result is valid until the next call to ada_encode. */
779 ada_encode (const char *decoded
)
781 static char *encoding_buffer
= NULL
;
782 static size_t encoding_buffer_size
= 0;
789 GROW_VECT (encoding_buffer
, encoding_buffer_size
,
790 2 * strlen (decoded
) + 10);
793 for (p
= decoded
; *p
!= '\0'; p
+= 1)
795 if (!ADA_RETAIN_DOTS
&& *p
== '.')
797 encoding_buffer
[k
] = encoding_buffer
[k
+ 1] = '_';
802 const struct ada_opname_map
*mapping
;
804 for (mapping
= ada_opname_table
;
805 mapping
->encoded
!= NULL
&&
806 strncmp (mapping
->decoded
, p
,
807 strlen (mapping
->decoded
)) != 0;
810 if (mapping
->encoded
== NULL
)
811 error ("invalid Ada operator name: %s", p
);
812 strcpy (encoding_buffer
+ k
, mapping
->encoded
);
813 k
+= strlen (mapping
->encoded
);
818 encoding_buffer
[k
] = *p
;
823 encoding_buffer
[k
] = '\0';
824 return encoding_buffer
;
827 /* Return NAME folded to lower case, or, if surrounded by single
828 quotes, unfolded, but with the quotes stripped away. Result good
832 ada_fold_name (const char *name
)
834 static char *fold_buffer
= NULL
;
835 static size_t fold_buffer_size
= 0;
837 int len
= strlen (name
);
838 GROW_VECT (fold_buffer
, fold_buffer_size
, len
+ 1);
842 strncpy (fold_buffer
, name
+ 1, len
- 2);
843 fold_buffer
[len
- 2] = '\000';
848 for (i
= 0; i
<= len
; i
+= 1)
849 fold_buffer
[i
] = tolower (name
[i
]);
856 0. Discard trailing .{DIGIT}+ or trailing ___{DIGIT}+
857 These are suffixes introduced by GNAT5 to nested subprogram
858 names, and do not serve any purpose for the debugger.
859 1. Discard final __{DIGIT}+ or $({DIGIT}+(__{DIGIT}+)*)
860 2. Convert other instances of embedded "__" to `.'.
861 3. Discard leading _ada_.
862 4. Convert operator names to the appropriate quoted symbols.
863 5. Remove everything after first ___ if it is followed by
865 6. Replace TK__ with __, and a trailing B or TKB with nothing.
866 7. Put symbols that should be suppressed in <...> brackets.
867 8. Remove trailing X[bn]* suffix (indicating names in package bodies).
869 The resulting string is valid until the next call of ada_decode.
870 If the string is unchanged by demangling, the original string pointer
874 ada_decode (const char *encoded
)
881 static char *decoding_buffer
= NULL
;
882 static size_t decoding_buffer_size
= 0;
884 if (strncmp (encoded
, "_ada_", 5) == 0)
887 if (encoded
[0] == '_' || encoded
[0] == '<')
890 /* Remove trailing .{DIGIT}+ or ___{DIGIT}+. */
891 len0
= strlen (encoded
);
892 if (len0
> 1 && isdigit (encoded
[len0
- 1]))
895 while (i
> 0 && isdigit (encoded
[i
]))
897 if (i
>= 0 && encoded
[i
] == '.')
899 else if (i
>= 2 && strncmp (encoded
+ i
- 2, "___", 3) == 0)
903 /* Remove the ___X.* suffix if present. Do not forget to verify that
904 the suffix is located before the current "end" of ENCODED. We want
905 to avoid re-matching parts of ENCODED that have previously been
906 marked as discarded (by decrementing LEN0). */
907 p
= strstr (encoded
, "___");
908 if (p
!= NULL
&& p
- encoded
< len0
- 3)
916 if (len0
> 3 && strncmp (encoded
+ len0
- 3, "TKB", 3) == 0)
919 if (len0
> 1 && strncmp (encoded
+ len0
- 1, "B", 1) == 0)
922 /* Make decoded big enough for possible expansion by operator name. */
923 GROW_VECT (decoding_buffer
, decoding_buffer_size
, 2 * len0
+ 1);
924 decoded
= decoding_buffer
;
926 if (len0
> 1 && isdigit (encoded
[len0
- 1]))
929 while ((i
>= 0 && isdigit (encoded
[i
]))
930 || (i
>= 1 && encoded
[i
] == '_' && isdigit (encoded
[i
- 1])))
932 if (i
> 1 && encoded
[i
] == '_' && encoded
[i
- 1] == '_')
934 else if (encoded
[i
] == '$')
938 for (i
= 0, j
= 0; i
< len0
&& !isalpha (encoded
[i
]); i
+= 1, j
+= 1)
939 decoded
[j
] = encoded
[i
];
944 if (at_start_name
&& encoded
[i
] == 'O')
947 for (k
= 0; ada_opname_table
[k
].encoded
!= NULL
; k
+= 1)
949 int op_len
= strlen (ada_opname_table
[k
].encoded
);
950 if (strncmp (ada_opname_table
[k
].encoded
+ 1, encoded
+ i
+ 1,
952 && !isalnum (encoded
[i
+ op_len
]))
954 strcpy (decoded
+ j
, ada_opname_table
[k
].decoded
);
957 j
+= strlen (ada_opname_table
[k
].decoded
);
961 if (ada_opname_table
[k
].encoded
!= NULL
)
966 if (i
< len0
- 4 && strncmp (encoded
+ i
, "TK__", 4) == 0)
968 if (encoded
[i
] == 'X' && i
!= 0 && isalnum (encoded
[i
- 1]))
972 while (i
< len0
&& (encoded
[i
] == 'b' || encoded
[i
] == 'n'));
976 else if (!ADA_RETAIN_DOTS
977 && i
< len0
- 2 && encoded
[i
] == '_' && encoded
[i
+ 1] == '_')
986 decoded
[j
] = encoded
[i
];
993 for (i
= 0; decoded
[i
] != '\0'; i
+= 1)
994 if (isupper (decoded
[i
]) || decoded
[i
] == ' ')
997 if (strcmp (decoded
, encoded
) == 0)
1003 GROW_VECT (decoding_buffer
, decoding_buffer_size
, strlen (encoded
) + 3);
1004 decoded
= decoding_buffer
;
1005 if (encoded
[0] == '<')
1006 strcpy (decoded
, encoded
);
1008 sprintf (decoded
, "<%s>", encoded
);
1013 /* Table for keeping permanent unique copies of decoded names. Once
1014 allocated, names in this table are never released. While this is a
1015 storage leak, it should not be significant unless there are massive
1016 changes in the set of decoded names in successive versions of a
1017 symbol table loaded during a single session. */
1018 static struct htab
*decoded_names_store
;
1020 /* Returns the decoded name of GSYMBOL, as for ada_decode, caching it
1021 in the language-specific part of GSYMBOL, if it has not been
1022 previously computed. Tries to save the decoded name in the same
1023 obstack as GSYMBOL, if possible, and otherwise on the heap (so that,
1024 in any case, the decoded symbol has a lifetime at least that of
1026 The GSYMBOL parameter is "mutable" in the C++ sense: logically
1027 const, but nevertheless modified to a semantically equivalent form
1028 when a decoded name is cached in it.
1031 char *ada_decode_symbol (const struct general_symbol_info
*gsymbol
)
1034 (char **) &gsymbol
->language_specific
.cplus_specific
.demangled_name
;
1035 if (*resultp
== NULL
)
1037 const char *decoded
= ada_decode (gsymbol
->name
);
1038 if (gsymbol
->bfd_section
!= NULL
)
1040 bfd
*obfd
= gsymbol
->bfd_section
->owner
;
1043 struct objfile
*objf
;
1046 if (obfd
== objf
->obfd
)
1048 *resultp
= obsavestring (decoded
, strlen (decoded
),
1049 &objf
->objfile_obstack
);
1055 /* Sometimes, we can't find a corresponding objfile, in which
1056 case, we put the result on the heap. Since we only decode
1057 when needed, we hope this usually does not cause a
1058 significant memory leak (FIXME). */
1059 if (*resultp
== NULL
)
1062 (char **) htab_find_slot (decoded_names_store
,
1065 *slot
= xstrdup (decoded
);
1073 char *ada_la_decode (const char *encoded
, int options
)
1075 return xstrdup (ada_decode (encoded
));
1078 /* Returns non-zero iff SYM_NAME matches NAME, ignoring any trailing
1079 suffixes that encode debugging information or leading _ada_ on
1080 SYM_NAME (see is_name_suffix commentary for the debugging
1081 information that is ignored). If WILD, then NAME need only match a
1082 suffix of SYM_NAME minus the same suffixes. Also returns 0 if
1083 either argument is NULL. */
1086 ada_match_name (const char *sym_name
, const char *name
, int wild
)
1088 if (sym_name
== NULL
|| name
== NULL
)
1091 return wild_match (name
, strlen (name
), sym_name
);
1094 int len_name
= strlen (name
);
1095 return (strncmp (sym_name
, name
, len_name
) == 0
1096 && is_name_suffix (sym_name
+ len_name
))
1097 || (strncmp (sym_name
, "_ada_", 5) == 0
1098 && strncmp (sym_name
+ 5, name
, len_name
) == 0
1099 && is_name_suffix (sym_name
+ len_name
+ 5));
1103 /* True (non-zero) iff, in Ada mode, the symbol SYM should be
1104 suppressed in info listings. */
1107 ada_suppress_symbol_printing (struct symbol
*sym
)
1109 if (SYMBOL_DOMAIN (sym
) == STRUCT_DOMAIN
)
1112 return is_suppressed_name (SYMBOL_LINKAGE_NAME (sym
));
1118 /* Names of MAX_ADA_DIMENS bounds in P_BOUNDS fields of array descriptors. */
1120 static char *bound_name
[] = {
1121 "LB0", "UB0", "LB1", "UB1", "LB2", "UB2", "LB3", "UB3",
1122 "LB4", "UB4", "LB5", "UB5", "LB6", "UB6", "LB7", "UB7"
1125 /* Maximum number of array dimensions we are prepared to handle. */
1127 #define MAX_ADA_DIMENS (sizeof(bound_name) / (2*sizeof(char *)))
1129 /* Like modify_field, but allows bitpos > wordlength. */
1132 modify_general_field (char *addr
, LONGEST fieldval
, int bitpos
, int bitsize
)
1134 modify_field (addr
+ bitpos
/ 8, fieldval
, bitpos
% 8, bitsize
);
1138 /* The desc_* routines return primitive portions of array descriptors
1141 /* The descriptor or array type, if any, indicated by TYPE; removes
1142 level of indirection, if needed. */
1144 static struct type
*
1145 desc_base_type (struct type
*type
)
1149 CHECK_TYPEDEF (type
);
1151 (TYPE_CODE (type
) == TYPE_CODE_PTR
1152 || TYPE_CODE (type
) == TYPE_CODE_REF
))
1153 return check_typedef (TYPE_TARGET_TYPE (type
));
1158 /* True iff TYPE indicates a "thin" array pointer type. */
1161 is_thin_pntr (struct type
*type
)
1164 is_suffix (ada_type_name (desc_base_type (type
)), "___XUT")
1165 || is_suffix (ada_type_name (desc_base_type (type
)), "___XUT___XVE");
1168 /* The descriptor type for thin pointer type TYPE. */
1170 static struct type
*
1171 thin_descriptor_type (struct type
*type
)
1173 struct type
*base_type
= desc_base_type (type
);
1174 if (base_type
== NULL
)
1176 if (is_suffix (ada_type_name (base_type
), "___XVE"))
1180 struct type
*alt_type
= ada_find_parallel_type (base_type
, "___XVE");
1181 if (alt_type
== NULL
)
1188 /* A pointer to the array data for thin-pointer value VAL. */
1190 static struct value
*
1191 thin_data_pntr (struct value
*val
)
1193 struct type
*type
= VALUE_TYPE (val
);
1194 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
1195 return value_cast (desc_data_type (thin_descriptor_type (type
)),
1198 return value_from_longest (desc_data_type (thin_descriptor_type (type
)),
1199 VALUE_ADDRESS (val
) + VALUE_OFFSET (val
));
1202 /* True iff TYPE indicates a "thick" array pointer type. */
1205 is_thick_pntr (struct type
*type
)
1207 type
= desc_base_type (type
);
1208 return (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_STRUCT
1209 && lookup_struct_elt_type (type
, "P_BOUNDS", 1) != NULL
);
1212 /* If TYPE is the type of an array descriptor (fat or thin pointer) or a
1213 pointer to one, the type of its bounds data; otherwise, NULL. */
1215 static struct type
*
1216 desc_bounds_type (struct type
*type
)
1220 type
= desc_base_type (type
);
1224 else if (is_thin_pntr (type
))
1226 type
= thin_descriptor_type (type
);
1229 r
= lookup_struct_elt_type (type
, "BOUNDS", 1);
1231 return check_typedef (r
);
1233 else if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
)
1235 r
= lookup_struct_elt_type (type
, "P_BOUNDS", 1);
1237 return check_typedef (TYPE_TARGET_TYPE (check_typedef (r
)));
1242 /* If ARR is an array descriptor (fat or thin pointer), or pointer to
1243 one, a pointer to its bounds data. Otherwise NULL. */
1245 static struct value
*
1246 desc_bounds (struct value
*arr
)
1248 struct type
*type
= check_typedef (VALUE_TYPE (arr
));
1249 if (is_thin_pntr (type
))
1251 struct type
*bounds_type
=
1252 desc_bounds_type (thin_descriptor_type (type
));
1255 if (desc_bounds_type
== NULL
)
1256 error ("Bad GNAT array descriptor");
1258 /* NOTE: The following calculation is not really kosher, but
1259 since desc_type is an XVE-encoded type (and shouldn't be),
1260 the correct calculation is a real pain. FIXME (and fix GCC). */
1261 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
1262 addr
= value_as_long (arr
);
1264 addr
= VALUE_ADDRESS (arr
) + VALUE_OFFSET (arr
);
1267 value_from_longest (lookup_pointer_type (bounds_type
),
1268 addr
- TYPE_LENGTH (bounds_type
));
1271 else if (is_thick_pntr (type
))
1272 return value_struct_elt (&arr
, NULL
, "P_BOUNDS", NULL
,
1273 "Bad GNAT array descriptor");
1278 /* If TYPE is the type of an array-descriptor (fat pointer), the bit
1279 position of the field containing the address of the bounds data. */
1282 fat_pntr_bounds_bitpos (struct type
*type
)
1284 return TYPE_FIELD_BITPOS (desc_base_type (type
), 1);
1287 /* If TYPE is the type of an array-descriptor (fat pointer), the bit
1288 size of the field containing the address of the bounds data. */
1291 fat_pntr_bounds_bitsize (struct type
*type
)
1293 type
= desc_base_type (type
);
1295 if (TYPE_FIELD_BITSIZE (type
, 1) > 0)
1296 return TYPE_FIELD_BITSIZE (type
, 1);
1298 return 8 * TYPE_LENGTH (check_typedef (TYPE_FIELD_TYPE (type
, 1)));
1301 /* If TYPE is the type of an array descriptor (fat or thin pointer) or a
1302 pointer to one, the type of its array data (a
1303 pointer-to-array-with-no-bounds type); otherwise, NULL. Use
1304 ada_type_of_array to get an array type with bounds data. */
1306 static struct type
*
1307 desc_data_type (struct type
*type
)
1309 type
= desc_base_type (type
);
1311 /* NOTE: The following is bogus; see comment in desc_bounds. */
1312 if (is_thin_pntr (type
))
1313 return lookup_pointer_type
1314 (desc_base_type (TYPE_FIELD_TYPE (thin_descriptor_type (type
), 1)));
1315 else if (is_thick_pntr (type
))
1316 return lookup_struct_elt_type (type
, "P_ARRAY", 1);
1321 /* If ARR is an array descriptor (fat or thin pointer), a pointer to
1324 static struct value
*
1325 desc_data (struct value
*arr
)
1327 struct type
*type
= VALUE_TYPE (arr
);
1328 if (is_thin_pntr (type
))
1329 return thin_data_pntr (arr
);
1330 else if (is_thick_pntr (type
))
1331 return value_struct_elt (&arr
, NULL
, "P_ARRAY", NULL
,
1332 "Bad GNAT array descriptor");
1338 /* If TYPE is the type of an array-descriptor (fat pointer), the bit
1339 position of the field containing the address of the data. */
1342 fat_pntr_data_bitpos (struct type
*type
)
1344 return TYPE_FIELD_BITPOS (desc_base_type (type
), 0);
1347 /* If TYPE is the type of an array-descriptor (fat pointer), the bit
1348 size of the field containing the address of the data. */
1351 fat_pntr_data_bitsize (struct type
*type
)
1353 type
= desc_base_type (type
);
1355 if (TYPE_FIELD_BITSIZE (type
, 0) > 0)
1356 return TYPE_FIELD_BITSIZE (type
, 0);
1358 return TARGET_CHAR_BIT
* TYPE_LENGTH (TYPE_FIELD_TYPE (type
, 0));
1361 /* If BOUNDS is an array-bounds structure (or pointer to one), return
1362 the Ith lower bound stored in it, if WHICH is 0, and the Ith upper
1363 bound, if WHICH is 1. The first bound is I=1. */
1365 static struct value
*
1366 desc_one_bound (struct value
*bounds
, int i
, int which
)
1368 return value_struct_elt (&bounds
, NULL
, bound_name
[2 * i
+ which
- 2], NULL
,
1369 "Bad GNAT array descriptor bounds");
1372 /* If BOUNDS is an array-bounds structure type, return the bit position
1373 of the Ith lower bound stored in it, if WHICH is 0, and the Ith upper
1374 bound, if WHICH is 1. The first bound is I=1. */
1377 desc_bound_bitpos (struct type
*type
, int i
, int which
)
1379 return TYPE_FIELD_BITPOS (desc_base_type (type
), 2 * i
+ which
- 2);
1382 /* If BOUNDS is an array-bounds structure type, return the bit field size
1383 of the Ith lower bound stored in it, if WHICH is 0, and the Ith upper
1384 bound, if WHICH is 1. The first bound is I=1. */
1387 desc_bound_bitsize (struct type
*type
, int i
, int which
)
1389 type
= desc_base_type (type
);
1391 if (TYPE_FIELD_BITSIZE (type
, 2 * i
+ which
- 2) > 0)
1392 return TYPE_FIELD_BITSIZE (type
, 2 * i
+ which
- 2);
1394 return 8 * TYPE_LENGTH (TYPE_FIELD_TYPE (type
, 2 * i
+ which
- 2));
1397 /* If TYPE is the type of an array-bounds structure, the type of its
1398 Ith bound (numbering from 1). Otherwise, NULL. */
1400 static struct type
*
1401 desc_index_type (struct type
*type
, int i
)
1403 type
= desc_base_type (type
);
1405 if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
)
1406 return lookup_struct_elt_type (type
, bound_name
[2 * i
- 2], 1);
1411 /* The number of index positions in the array-bounds type TYPE.
1412 Return 0 if TYPE is NULL. */
1415 desc_arity (struct type
*type
)
1417 type
= desc_base_type (type
);
1420 return TYPE_NFIELDS (type
) / 2;
1424 /* Non-zero iff TYPE is a simple array type (not a pointer to one) or
1425 an array descriptor type (representing an unconstrained array
1429 ada_is_direct_array_type (struct type
*type
)
1433 CHECK_TYPEDEF (type
);
1434 return (TYPE_CODE (type
) == TYPE_CODE_ARRAY
1435 || ada_is_array_descriptor_type (type
));
1438 /* Non-zero iff TYPE is a simple array type or pointer to one. */
1441 ada_is_simple_array_type (struct type
*type
)
1445 CHECK_TYPEDEF (type
);
1446 return (TYPE_CODE (type
) == TYPE_CODE_ARRAY
1447 || (TYPE_CODE (type
) == TYPE_CODE_PTR
1448 && TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_ARRAY
));
1451 /* Non-zero iff TYPE belongs to a GNAT array descriptor. */
1454 ada_is_array_descriptor_type (struct type
*type
)
1456 struct type
*data_type
= desc_data_type (type
);
1460 CHECK_TYPEDEF (type
);
1463 && ((TYPE_CODE (data_type
) == TYPE_CODE_PTR
1464 && TYPE_TARGET_TYPE (data_type
) != NULL
1465 && TYPE_CODE (TYPE_TARGET_TYPE (data_type
)) == TYPE_CODE_ARRAY
)
1467 TYPE_CODE (data_type
) == TYPE_CODE_ARRAY
)
1468 && desc_arity (desc_bounds_type (type
)) > 0;
1471 /* Non-zero iff type is a partially mal-formed GNAT array
1472 descriptor. FIXME: This is to compensate for some problems with
1473 debugging output from GNAT. Re-examine periodically to see if it
1477 ada_is_bogus_array_descriptor (struct type
*type
)
1481 && TYPE_CODE (type
) == TYPE_CODE_STRUCT
1482 && (lookup_struct_elt_type (type
, "P_BOUNDS", 1) != NULL
1483 || lookup_struct_elt_type (type
, "P_ARRAY", 1) != NULL
)
1484 && !ada_is_array_descriptor_type (type
);
1488 /* If ARR has a record type in the form of a standard GNAT array descriptor,
1489 (fat pointer) returns the type of the array data described---specifically,
1490 a pointer-to-array type. If BOUNDS is non-zero, the bounds data are filled
1491 in from the descriptor; otherwise, they are left unspecified. If
1492 the ARR denotes a null array descriptor and BOUNDS is non-zero,
1493 returns NULL. The result is simply the type of ARR if ARR is not
1496 ada_type_of_array (struct value
*arr
, int bounds
)
1498 if (ada_is_packed_array_type (VALUE_TYPE (arr
)))
1499 return decode_packed_array_type (VALUE_TYPE (arr
));
1501 if (!ada_is_array_descriptor_type (VALUE_TYPE (arr
)))
1502 return VALUE_TYPE (arr
);
1506 check_typedef (TYPE_TARGET_TYPE (desc_data_type (VALUE_TYPE (arr
))));
1509 struct type
*elt_type
;
1511 struct value
*descriptor
;
1512 struct objfile
*objf
= TYPE_OBJFILE (VALUE_TYPE (arr
));
1514 elt_type
= ada_array_element_type (VALUE_TYPE (arr
), -1);
1515 arity
= ada_array_arity (VALUE_TYPE (arr
));
1517 if (elt_type
== NULL
|| arity
== 0)
1518 return check_typedef (VALUE_TYPE (arr
));
1520 descriptor
= desc_bounds (arr
);
1521 if (value_as_long (descriptor
) == 0)
1525 struct type
*range_type
= alloc_type (objf
);
1526 struct type
*array_type
= alloc_type (objf
);
1527 struct value
*low
= desc_one_bound (descriptor
, arity
, 0);
1528 struct value
*high
= desc_one_bound (descriptor
, arity
, 1);
1531 create_range_type (range_type
, VALUE_TYPE (low
),
1532 (int) value_as_long (low
),
1533 (int) value_as_long (high
));
1534 elt_type
= create_array_type (array_type
, elt_type
, range_type
);
1537 return lookup_pointer_type (elt_type
);
1541 /* If ARR does not represent an array, returns ARR unchanged.
1542 Otherwise, returns either a standard GDB array with bounds set
1543 appropriately or, if ARR is a non-null fat pointer, a pointer to a standard
1544 GDB array. Returns NULL if ARR is a null fat pointer. */
1547 ada_coerce_to_simple_array_ptr (struct value
*arr
)
1549 if (ada_is_array_descriptor_type (VALUE_TYPE (arr
)))
1551 struct type
*arrType
= ada_type_of_array (arr
, 1);
1552 if (arrType
== NULL
)
1554 return value_cast (arrType
, value_copy (desc_data (arr
)));
1556 else if (ada_is_packed_array_type (VALUE_TYPE (arr
)))
1557 return decode_packed_array (arr
);
1562 /* If ARR does not represent an array, returns ARR unchanged.
1563 Otherwise, returns a standard GDB array describing ARR (which may
1564 be ARR itself if it already is in the proper form). */
1566 static struct value
*
1567 ada_coerce_to_simple_array (struct value
*arr
)
1569 if (ada_is_array_descriptor_type (VALUE_TYPE (arr
)))
1571 struct value
*arrVal
= ada_coerce_to_simple_array_ptr (arr
);
1573 error ("Bounds unavailable for null array pointer.");
1574 return value_ind (arrVal
);
1576 else if (ada_is_packed_array_type (VALUE_TYPE (arr
)))
1577 return decode_packed_array (arr
);
1582 /* If TYPE represents a GNAT array type, return it translated to an
1583 ordinary GDB array type (possibly with BITSIZE fields indicating
1584 packing). For other types, is the identity. */
1587 ada_coerce_to_simple_array_type (struct type
*type
)
1589 struct value
*mark
= value_mark ();
1590 struct value
*dummy
= value_from_longest (builtin_type_long
, 0);
1591 struct type
*result
;
1592 VALUE_TYPE (dummy
) = type
;
1593 result
= ada_type_of_array (dummy
, 0);
1594 value_free_to_mark (mark
);
1598 /* Non-zero iff TYPE represents a standard GNAT packed-array type. */
1601 ada_is_packed_array_type (struct type
*type
)
1605 type
= desc_base_type (type
);
1606 CHECK_TYPEDEF (type
);
1608 ada_type_name (type
) != NULL
1609 && strstr (ada_type_name (type
), "___XP") != NULL
;
1612 /* Given that TYPE is a standard GDB array type with all bounds filled
1613 in, and that the element size of its ultimate scalar constituents
1614 (that is, either its elements, or, if it is an array of arrays, its
1615 elements' elements, etc.) is *ELT_BITS, return an identical type,
1616 but with the bit sizes of its elements (and those of any
1617 constituent arrays) recorded in the BITSIZE components of its
1618 TYPE_FIELD_BITSIZE values, and with *ELT_BITS set to its total size
1621 static struct type
*
1622 packed_array_type (struct type
*type
, long *elt_bits
)
1624 struct type
*new_elt_type
;
1625 struct type
*new_type
;
1626 LONGEST low_bound
, high_bound
;
1628 CHECK_TYPEDEF (type
);
1629 if (TYPE_CODE (type
) != TYPE_CODE_ARRAY
)
1632 new_type
= alloc_type (TYPE_OBJFILE (type
));
1633 new_elt_type
= packed_array_type (check_typedef (TYPE_TARGET_TYPE (type
)),
1635 create_array_type (new_type
, new_elt_type
, TYPE_FIELD_TYPE (type
, 0));
1636 TYPE_FIELD_BITSIZE (new_type
, 0) = *elt_bits
;
1637 TYPE_NAME (new_type
) = ada_type_name (type
);
1639 if (get_discrete_bounds (TYPE_FIELD_TYPE (type
, 0),
1640 &low_bound
, &high_bound
) < 0)
1641 low_bound
= high_bound
= 0;
1642 if (high_bound
< low_bound
)
1643 *elt_bits
= TYPE_LENGTH (new_type
) = 0;
1646 *elt_bits
*= (high_bound
- low_bound
+ 1);
1647 TYPE_LENGTH (new_type
) =
1648 (*elt_bits
+ HOST_CHAR_BIT
- 1) / HOST_CHAR_BIT
;
1651 TYPE_FLAGS (new_type
) |= TYPE_FLAG_FIXED_INSTANCE
;
1655 /* The array type encoded by TYPE, where ada_is_packed_array_type (TYPE). */
1657 static struct type
*
1658 decode_packed_array_type (struct type
*type
)
1661 struct block
**blocks
;
1662 const char *raw_name
= ada_type_name (check_typedef (type
));
1663 char *name
= (char *) alloca (strlen (raw_name
) + 1);
1664 char *tail
= strstr (raw_name
, "___XP");
1665 struct type
*shadow_type
;
1669 type
= desc_base_type (type
);
1671 memcpy (name
, raw_name
, tail
- raw_name
);
1672 name
[tail
- raw_name
] = '\000';
1674 sym
= standard_lookup (name
, get_selected_block (0), VAR_DOMAIN
);
1675 if (sym
== NULL
|| SYMBOL_TYPE (sym
) == NULL
)
1677 lim_warning ("could not find bounds information on packed array", 0);
1680 shadow_type
= SYMBOL_TYPE (sym
);
1682 if (TYPE_CODE (shadow_type
) != TYPE_CODE_ARRAY
)
1684 lim_warning ("could not understand bounds information on packed array",
1689 if (sscanf (tail
+ sizeof ("___XP") - 1, "%ld", &bits
) != 1)
1692 ("could not understand bit size information on packed array", 0);
1696 return packed_array_type (shadow_type
, &bits
);
1699 /* Given that ARR is a struct value *indicating a GNAT packed array,
1700 returns a simple array that denotes that array. Its type is a
1701 standard GDB array type except that the BITSIZEs of the array
1702 target types are set to the number of bits in each element, and the
1703 type length is set appropriately. */
1705 static struct value
*
1706 decode_packed_array (struct value
*arr
)
1710 arr
= ada_coerce_ref (arr
);
1711 if (TYPE_CODE (VALUE_TYPE (arr
)) == TYPE_CODE_PTR
)
1712 arr
= ada_value_ind (arr
);
1714 type
= decode_packed_array_type (VALUE_TYPE (arr
));
1717 error ("can't unpack array");
1720 return coerce_unspec_val_to_type (arr
, type
);
1724 /* The value of the element of packed array ARR at the ARITY indices
1725 given in IND. ARR must be a simple array. */
1727 static struct value
*
1728 value_subscript_packed (struct value
*arr
, int arity
, struct value
**ind
)
1731 int bits
, elt_off
, bit_off
;
1732 long elt_total_bit_offset
;
1733 struct type
*elt_type
;
1737 elt_total_bit_offset
= 0;
1738 elt_type
= check_typedef (VALUE_TYPE (arr
));
1739 for (i
= 0; i
< arity
; i
+= 1)
1741 if (TYPE_CODE (elt_type
) != TYPE_CODE_ARRAY
1742 || TYPE_FIELD_BITSIZE (elt_type
, 0) == 0)
1744 ("attempt to do packed indexing of something other than a packed array");
1747 struct type
*range_type
= TYPE_INDEX_TYPE (elt_type
);
1748 LONGEST lowerbound
, upperbound
;
1751 if (get_discrete_bounds (range_type
, &lowerbound
, &upperbound
) < 0)
1753 lim_warning ("don't know bounds of array", 0);
1754 lowerbound
= upperbound
= 0;
1757 idx
= value_as_long (value_pos_atr (ind
[i
]));
1758 if (idx
< lowerbound
|| idx
> upperbound
)
1759 lim_warning ("packed array index %ld out of bounds", (long) idx
);
1760 bits
= TYPE_FIELD_BITSIZE (elt_type
, 0);
1761 elt_total_bit_offset
+= (idx
- lowerbound
) * bits
;
1762 elt_type
= check_typedef (TYPE_TARGET_TYPE (elt_type
));
1765 elt_off
= elt_total_bit_offset
/ HOST_CHAR_BIT
;
1766 bit_off
= elt_total_bit_offset
% HOST_CHAR_BIT
;
1768 v
= ada_value_primitive_packed_val (arr
, NULL
, elt_off
, bit_off
,
1770 if (VALUE_LVAL (arr
) == lval_internalvar
)
1771 VALUE_LVAL (v
) = lval_internalvar_component
;
1773 VALUE_LVAL (v
) = VALUE_LVAL (arr
);
1777 /* Non-zero iff TYPE includes negative integer values. */
1780 has_negatives (struct type
*type
)
1782 switch (TYPE_CODE (type
))
1787 return !TYPE_UNSIGNED (type
);
1788 case TYPE_CODE_RANGE
:
1789 return TYPE_LOW_BOUND (type
) < 0;
1794 /* Create a new value of type TYPE from the contents of OBJ starting
1795 at byte OFFSET, and bit offset BIT_OFFSET within that byte,
1796 proceeding for BIT_SIZE bits. If OBJ is an lval in memory, then
1797 assigning through the result will set the field fetched from.
1798 VALADDR is ignored unless OBJ is NULL, in which case,
1799 VALADDR+OFFSET must address the start of storage containing the
1800 packed value. The value returned in this case is never an lval.
1801 Assumes 0 <= BIT_OFFSET < HOST_CHAR_BIT. */
1804 ada_value_primitive_packed_val (struct value
*obj
, char *valaddr
, long offset
,
1805 int bit_offset
, int bit_size
,
1809 int src
, /* Index into the source area */
1810 targ
, /* Index into the target area */
1811 srcBitsLeft
, /* Number of source bits left to move */
1812 nsrc
, ntarg
, /* Number of source and target bytes */
1813 unusedLS
, /* Number of bits in next significant
1814 byte of source that are unused */
1815 accumSize
; /* Number of meaningful bits in accum */
1816 unsigned char *bytes
; /* First byte containing data to unpack */
1817 unsigned char *unpacked
;
1818 unsigned long accum
; /* Staging area for bits being transferred */
1820 int len
= (bit_size
+ bit_offset
+ HOST_CHAR_BIT
- 1) / 8;
1821 /* Transmit bytes from least to most significant; delta is the direction
1822 the indices move. */
1823 int delta
= BITS_BIG_ENDIAN
? -1 : 1;
1825 CHECK_TYPEDEF (type
);
1829 v
= allocate_value (type
);
1830 bytes
= (unsigned char *) (valaddr
+ offset
);
1832 else if (VALUE_LAZY (obj
))
1835 VALUE_ADDRESS (obj
) + VALUE_OFFSET (obj
) + offset
, NULL
);
1836 bytes
= (unsigned char *) alloca (len
);
1837 read_memory (VALUE_ADDRESS (v
), bytes
, len
);
1841 v
= allocate_value (type
);
1842 bytes
= (unsigned char *) VALUE_CONTENTS (obj
) + offset
;
1847 VALUE_LVAL (v
) = VALUE_LVAL (obj
);
1848 if (VALUE_LVAL (obj
) == lval_internalvar
)
1849 VALUE_LVAL (v
) = lval_internalvar_component
;
1850 VALUE_ADDRESS (v
) = VALUE_ADDRESS (obj
) + VALUE_OFFSET (obj
) + offset
;
1851 VALUE_BITPOS (v
) = bit_offset
+ VALUE_BITPOS (obj
);
1852 VALUE_BITSIZE (v
) = bit_size
;
1853 if (VALUE_BITPOS (v
) >= HOST_CHAR_BIT
)
1855 VALUE_ADDRESS (v
) += 1;
1856 VALUE_BITPOS (v
) -= HOST_CHAR_BIT
;
1860 VALUE_BITSIZE (v
) = bit_size
;
1861 unpacked
= (unsigned char *) VALUE_CONTENTS (v
);
1863 srcBitsLeft
= bit_size
;
1865 ntarg
= TYPE_LENGTH (type
);
1869 memset (unpacked
, 0, TYPE_LENGTH (type
));
1872 else if (BITS_BIG_ENDIAN
)
1875 if (has_negatives (type
) &&
1876 ((bytes
[0] << bit_offset
) & (1 << (HOST_CHAR_BIT
- 1))))
1880 (HOST_CHAR_BIT
- (bit_size
+ bit_offset
) % HOST_CHAR_BIT
)
1883 switch (TYPE_CODE (type
))
1885 case TYPE_CODE_ARRAY
:
1886 case TYPE_CODE_UNION
:
1887 case TYPE_CODE_STRUCT
:
1888 /* Non-scalar values must be aligned at a byte boundary... */
1890 (HOST_CHAR_BIT
- bit_size
% HOST_CHAR_BIT
) % HOST_CHAR_BIT
;
1891 /* ... And are placed at the beginning (most-significant) bytes
1897 targ
= TYPE_LENGTH (type
) - 1;
1903 int sign_bit_offset
= (bit_size
+ bit_offset
- 1) % 8;
1906 unusedLS
= bit_offset
;
1909 if (has_negatives (type
) && (bytes
[len
- 1] & (1 << sign_bit_offset
)))
1916 /* Mask for removing bits of the next source byte that are not
1917 part of the value. */
1918 unsigned int unusedMSMask
=
1919 (1 << (srcBitsLeft
>= HOST_CHAR_BIT
? HOST_CHAR_BIT
: srcBitsLeft
)) -
1921 /* Sign-extend bits for this byte. */
1922 unsigned int signMask
= sign
& ~unusedMSMask
;
1924 (((bytes
[src
] >> unusedLS
) & unusedMSMask
) | signMask
) << accumSize
;
1925 accumSize
+= HOST_CHAR_BIT
- unusedLS
;
1926 if (accumSize
>= HOST_CHAR_BIT
)
1928 unpacked
[targ
] = accum
& ~(~0L << HOST_CHAR_BIT
);
1929 accumSize
-= HOST_CHAR_BIT
;
1930 accum
>>= HOST_CHAR_BIT
;
1934 srcBitsLeft
-= HOST_CHAR_BIT
- unusedLS
;
1941 accum
|= sign
<< accumSize
;
1942 unpacked
[targ
] = accum
& ~(~0L << HOST_CHAR_BIT
);
1943 accumSize
-= HOST_CHAR_BIT
;
1944 accum
>>= HOST_CHAR_BIT
;
1952 /* Move N bits from SOURCE, starting at bit offset SRC_OFFSET to
1953 TARGET, starting at bit offset TARG_OFFSET. SOURCE and TARGET must
1956 move_bits (char *target
, int targ_offset
, char *source
, int src_offset
, int n
)
1958 unsigned int accum
, mask
;
1959 int accum_bits
, chunk_size
;
1961 target
+= targ_offset
/ HOST_CHAR_BIT
;
1962 targ_offset
%= HOST_CHAR_BIT
;
1963 source
+= src_offset
/ HOST_CHAR_BIT
;
1964 src_offset
%= HOST_CHAR_BIT
;
1965 if (BITS_BIG_ENDIAN
)
1967 accum
= (unsigned char) *source
;
1969 accum_bits
= HOST_CHAR_BIT
- src_offset
;
1974 accum
= (accum
<< HOST_CHAR_BIT
) + (unsigned char) *source
;
1975 accum_bits
+= HOST_CHAR_BIT
;
1977 chunk_size
= HOST_CHAR_BIT
- targ_offset
;
1980 unused_right
= HOST_CHAR_BIT
- (chunk_size
+ targ_offset
);
1981 mask
= ((1 << chunk_size
) - 1) << unused_right
;
1984 | ((accum
>> (accum_bits
- chunk_size
- unused_right
)) & mask
);
1986 accum_bits
-= chunk_size
;
1993 accum
= (unsigned char) *source
>> src_offset
;
1995 accum_bits
= HOST_CHAR_BIT
- src_offset
;
1999 accum
= accum
+ ((unsigned char) *source
<< accum_bits
);
2000 accum_bits
+= HOST_CHAR_BIT
;
2002 chunk_size
= HOST_CHAR_BIT
- targ_offset
;
2005 mask
= ((1 << chunk_size
) - 1) << targ_offset
;
2006 *target
= (*target
& ~mask
) | ((accum
<< targ_offset
) & mask
);
2008 accum_bits
-= chunk_size
;
2009 accum
>>= chunk_size
;
2017 /* Store the contents of FROMVAL into the location of TOVAL.
2018 Return a new value with the location of TOVAL and contents of
2019 FROMVAL. Handles assignment into packed fields that have
2020 floating-point or non-scalar types. */
2022 static struct value
*
2023 ada_value_assign (struct value
*toval
, struct value
*fromval
)
2025 struct type
*type
= VALUE_TYPE (toval
);
2026 int bits
= VALUE_BITSIZE (toval
);
2028 if (!toval
->modifiable
)
2029 error ("Left operand of assignment is not a modifiable lvalue.");
2033 if (VALUE_LVAL (toval
) == lval_memory
2035 && (TYPE_CODE (type
) == TYPE_CODE_FLT
2036 || TYPE_CODE (type
) == TYPE_CODE_STRUCT
))
2039 (VALUE_BITPOS (toval
) + bits
+ HOST_CHAR_BIT
- 1) / HOST_CHAR_BIT
;
2040 char *buffer
= (char *) alloca (len
);
2043 if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
2044 fromval
= value_cast (type
, fromval
);
2046 read_memory (VALUE_ADDRESS (toval
) + VALUE_OFFSET (toval
), buffer
, len
);
2047 if (BITS_BIG_ENDIAN
)
2048 move_bits (buffer
, VALUE_BITPOS (toval
),
2049 VALUE_CONTENTS (fromval
),
2050 TYPE_LENGTH (VALUE_TYPE (fromval
)) * TARGET_CHAR_BIT
-
2053 move_bits (buffer
, VALUE_BITPOS (toval
), VALUE_CONTENTS (fromval
),
2055 write_memory (VALUE_ADDRESS (toval
) + VALUE_OFFSET (toval
), buffer
,
2058 val
= value_copy (toval
);
2059 memcpy (VALUE_CONTENTS_RAW (val
), VALUE_CONTENTS (fromval
),
2060 TYPE_LENGTH (type
));
2061 VALUE_TYPE (val
) = type
;
2066 return value_assign (toval
, fromval
);
2070 /* The value of the element of array ARR at the ARITY indices given in IND.
2071 ARR may be either a simple array, GNAT array descriptor, or pointer
2075 ada_value_subscript (struct value
*arr
, int arity
, struct value
**ind
)
2079 struct type
*elt_type
;
2081 elt
= ada_coerce_to_simple_array (arr
);
2083 elt_type
= check_typedef (VALUE_TYPE (elt
));
2084 if (TYPE_CODE (elt_type
) == TYPE_CODE_ARRAY
2085 && TYPE_FIELD_BITSIZE (elt_type
, 0) > 0)
2086 return value_subscript_packed (elt
, arity
, ind
);
2088 for (k
= 0; k
< arity
; k
+= 1)
2090 if (TYPE_CODE (elt_type
) != TYPE_CODE_ARRAY
)
2091 error ("too many subscripts (%d expected)", k
);
2092 elt
= value_subscript (elt
, value_pos_atr (ind
[k
]));
2097 /* Assuming ARR is a pointer to a standard GDB array of type TYPE, the
2098 value of the element of *ARR at the ARITY indices given in
2099 IND. Does not read the entire array into memory. */
2102 ada_value_ptr_subscript (struct value
*arr
, struct type
*type
, int arity
,
2107 for (k
= 0; k
< arity
; k
+= 1)
2112 if (TYPE_CODE (type
) != TYPE_CODE_ARRAY
)
2113 error ("too many subscripts (%d expected)", k
);
2114 arr
= value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (type
)),
2116 get_discrete_bounds (TYPE_INDEX_TYPE (type
), &lwb
, &upb
);
2117 idx
= value_pos_atr (ind
[k
]);
2119 idx
= value_sub (idx
, value_from_longest (builtin_type_int
, lwb
));
2120 arr
= value_add (arr
, idx
);
2121 type
= TYPE_TARGET_TYPE (type
);
2124 return value_ind (arr
);
2127 /* If type is a record type in the form of a standard GNAT array
2128 descriptor, returns the number of dimensions for type. If arr is a
2129 simple array, returns the number of "array of"s that prefix its
2130 type designation. Otherwise, returns 0. */
2133 ada_array_arity (struct type
*type
)
2140 type
= desc_base_type (type
);
2143 if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
)
2144 return desc_arity (desc_bounds_type (type
));
2146 while (TYPE_CODE (type
) == TYPE_CODE_ARRAY
)
2149 type
= check_typedef (TYPE_TARGET_TYPE (type
));
2155 /* If TYPE is a record type in the form of a standard GNAT array
2156 descriptor or a simple array type, returns the element type for
2157 TYPE after indexing by NINDICES indices, or by all indices if
2158 NINDICES is -1. Otherwise, returns NULL. */
2161 ada_array_element_type (struct type
*type
, int nindices
)
2163 type
= desc_base_type (type
);
2165 if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
)
2168 struct type
*p_array_type
;
2170 p_array_type
= desc_data_type (type
);
2172 k
= ada_array_arity (type
);
2176 /* Initially p_array_type = elt_type(*)[]...(k times)...[]. */
2177 if (nindices
>= 0 && k
> nindices
)
2179 p_array_type
= TYPE_TARGET_TYPE (p_array_type
);
2180 while (k
> 0 && p_array_type
!= NULL
)
2182 p_array_type
= check_typedef (TYPE_TARGET_TYPE (p_array_type
));
2185 return p_array_type
;
2187 else if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
)
2189 while (nindices
!= 0 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
)
2191 type
= TYPE_TARGET_TYPE (type
);
2200 /* The type of nth index in arrays of given type (n numbering from 1).
2201 Does not examine memory. */
2204 ada_index_type (struct type
*type
, int n
)
2206 struct type
*result_type
;
2208 type
= desc_base_type (type
);
2210 if (n
> ada_array_arity (type
))
2213 if (ada_is_simple_array_type (type
))
2217 for (i
= 1; i
< n
; i
+= 1)
2218 type
= TYPE_TARGET_TYPE (type
);
2219 result_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
, 0));
2220 /* FIXME: The stabs type r(0,0);bound;bound in an array type
2221 has a target type of TYPE_CODE_UNDEF. We compensate here, but
2222 perhaps stabsread.c would make more sense. */
2223 if (result_type
== NULL
2224 || TYPE_CODE (result_type
) == TYPE_CODE_UNDEF
)
2225 result_type
= builtin_type_int
;
2230 return desc_index_type (desc_bounds_type (type
), n
);
2233 /* Given that arr is an array type, returns the lower bound of the
2234 Nth index (numbering from 1) if WHICH is 0, and the upper bound if
2235 WHICH is 1. This returns bounds 0 .. -1 if ARR_TYPE is an
2236 array-descriptor type. If TYPEP is non-null, *TYPEP is set to the
2237 bounds type. It works for other arrays with bounds supplied by
2238 run-time quantities other than discriminants. */
2241 ada_array_bound_from_type (struct type
* arr_type
, int n
, int which
,
2242 struct type
** typep
)
2245 struct type
*index_type_desc
;
2247 if (ada_is_packed_array_type (arr_type
))
2248 arr_type
= decode_packed_array_type (arr_type
);
2250 if (arr_type
== NULL
|| !ada_is_simple_array_type (arr_type
))
2253 *typep
= builtin_type_int
;
2254 return (LONGEST
) - which
;
2257 if (TYPE_CODE (arr_type
) == TYPE_CODE_PTR
)
2258 type
= TYPE_TARGET_TYPE (arr_type
);
2262 index_type_desc
= ada_find_parallel_type (type
, "___XA");
2263 if (index_type_desc
== NULL
)
2265 struct type
*range_type
;
2266 struct type
*index_type
;
2270 type
= TYPE_TARGET_TYPE (type
);
2274 range_type
= TYPE_INDEX_TYPE (type
);
2275 index_type
= TYPE_TARGET_TYPE (range_type
);
2276 if (TYPE_CODE (index_type
) == TYPE_CODE_UNDEF
)
2277 index_type
= builtin_type_long
;
2279 *typep
= index_type
;
2281 (LONGEST
) (which
== 0
2282 ? TYPE_LOW_BOUND (range_type
)
2283 : TYPE_HIGH_BOUND (range_type
));
2287 struct type
*index_type
=
2288 to_fixed_range_type (TYPE_FIELD_NAME (index_type_desc
, n
- 1),
2289 NULL
, TYPE_OBJFILE (arr_type
));
2291 *typep
= TYPE_TARGET_TYPE (index_type
);
2293 (LONGEST
) (which
== 0
2294 ? TYPE_LOW_BOUND (index_type
)
2295 : TYPE_HIGH_BOUND (index_type
));
2299 /* Given that arr is an array value, returns the lower bound of the
2300 nth index (numbering from 1) if which is 0, and the upper bound if
2301 which is 1. This routine will also work for arrays with bounds
2302 supplied by run-time quantities other than discriminants. */
2305 ada_array_bound (struct value
*arr
, int n
, int which
)
2307 struct type
*arr_type
= VALUE_TYPE (arr
);
2309 if (ada_is_packed_array_type (arr_type
))
2310 return ada_array_bound (decode_packed_array (arr
), n
, which
);
2311 else if (ada_is_simple_array_type (arr_type
))
2314 LONGEST v
= ada_array_bound_from_type (arr_type
, n
, which
, &type
);
2315 return value_from_longest (type
, v
);
2318 return desc_one_bound (desc_bounds (arr
), n
, which
);
2321 /* Given that arr is an array value, returns the length of the
2322 nth index. This routine will also work for arrays with bounds
2323 supplied by run-time quantities other than discriminants.
2324 Does not work for arrays indexed by enumeration types with representation
2325 clauses at the moment. */
2328 ada_array_length (struct value
*arr
, int n
)
2330 struct type
*arr_type
= check_typedef (VALUE_TYPE (arr
));
2332 if (ada_is_packed_array_type (arr_type
))
2333 return ada_array_length (decode_packed_array (arr
), n
);
2335 if (ada_is_simple_array_type (arr_type
))
2339 ada_array_bound_from_type (arr_type
, n
, 1, &type
) -
2340 ada_array_bound_from_type (arr_type
, n
, 0, NULL
) + 1;
2341 return value_from_longest (type
, v
);
2345 value_from_longest (builtin_type_ada_int
,
2346 value_as_long (desc_one_bound (desc_bounds (arr
),
2348 - value_as_long (desc_one_bound (desc_bounds (arr
),
2352 /* An empty array whose type is that of ARR_TYPE (an array type),
2353 with bounds LOW to LOW-1. */
2355 static struct value
*
2356 empty_array (struct type
*arr_type
, int low
)
2358 return allocate_value (create_range_type (NULL
, TYPE_INDEX_TYPE (arr_type
),
2363 /* Name resolution */
2365 /* The "decoded" name for the user-definable Ada operator corresponding
2369 ada_decoded_op_name (enum exp_opcode op
)
2373 for (i
= 0; ada_opname_table
[i
].encoded
!= NULL
; i
+= 1)
2375 if (ada_opname_table
[i
].op
== op
)
2376 return ada_opname_table
[i
].decoded
;
2378 error ("Could not find operator name for opcode");
2382 /* Same as evaluate_type (*EXP), but resolves ambiguous symbol
2383 references (marked by OP_VAR_VALUE nodes in which the symbol has an
2384 undefined namespace) and converts operators that are
2385 user-defined into appropriate function calls. If CONTEXT_TYPE is
2386 non-null, it provides a preferred result type [at the moment, only
2387 type void has any effect---causing procedures to be preferred over
2388 functions in calls]. A null CONTEXT_TYPE indicates that a non-void
2389 return type is preferred. May change (expand) *EXP. */
2392 resolve (struct expression
**expp
, int void_context_p
)
2396 resolve_subexp (expp
, &pc
, 1, void_context_p
? builtin_type_void
: NULL
);
2399 /* Resolve the operator of the subexpression beginning at
2400 position *POS of *EXPP. "Resolving" consists of replacing
2401 the symbols that have undefined namespaces in OP_VAR_VALUE nodes
2402 with their resolutions, replacing built-in operators with
2403 function calls to user-defined operators, where appropriate, and,
2404 when DEPROCEDURE_P is non-zero, converting function-valued variables
2405 into parameterless calls. May expand *EXPP. The CONTEXT_TYPE functions
2406 are as in ada_resolve, above. */
2408 static struct value
*
2409 resolve_subexp (struct expression
**expp
, int *pos
, int deprocedure_p
,
2410 struct type
*context_type
)
2414 struct expression
*exp
; /* Convenience: == *expp. */
2415 enum exp_opcode op
= (*expp
)->elts
[pc
].opcode
;
2416 struct value
**argvec
; /* Vector of operand types (alloca'ed). */
2417 int nargs
; /* Number of operands. */
2423 /* Pass one: resolve operands, saving their types and updating *pos. */
2427 if (exp
->elts
[pc
+ 3].opcode
== OP_VAR_VALUE
2428 && SYMBOL_DOMAIN (exp
->elts
[pc
+ 5].symbol
) == UNDEF_DOMAIN
)
2433 resolve_subexp (expp
, pos
, 0, NULL
);
2435 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
2440 resolve_subexp (expp
, pos
, 1, exp
->elts
[pc
+ 1].type
);
2445 resolve_subexp (expp
, pos
, 0, NULL
);
2448 case OP_ATR_MODULUS
:
2478 arg1
= resolve_subexp (expp
, pos
, 0, NULL
);
2480 resolve_subexp (expp
, pos
, 1, NULL
);
2482 resolve_subexp (expp
, pos
, 1, VALUE_TYPE (arg1
));
2500 case BINOP_LOGICAL_AND
:
2501 case BINOP_LOGICAL_OR
:
2502 case BINOP_BITWISE_AND
:
2503 case BINOP_BITWISE_IOR
:
2504 case BINOP_BITWISE_XOR
:
2507 case BINOP_NOTEQUAL
:
2514 case BINOP_SUBSCRIPT
:
2522 case UNOP_LOGICAL_NOT
:
2539 case OP_INTERNALVAR
:
2548 case STRUCTOP_STRUCT
:
2549 *pos
+= 4 + BYTES_TO_EXP_ELEM (exp
->elts
[pc
+ 1].longconst
+ 1);
2555 + BYTES_TO_EXP_ELEM (longest_to_int (exp
->elts
[pc
+ 1].longconst
) + 1);
2559 case TERNOP_IN_RANGE
:
2564 case BINOP_IN_BOUNDS
:
2570 error ("Unexpected operator during name resolution");
2574 (struct value
* *) alloca (sizeof (struct value
*) * (nargs
+ 1));
2575 for (i
= 0; i
< nargs
; i
+= 1)
2576 argvec
[i
] = resolve_subexp (expp
, pos
, 1, NULL
);
2580 /* Pass two: perform any resolution on principal operator. */
2587 if (SYMBOL_DOMAIN (exp
->elts
[pc
+ 2].symbol
) == UNDEF_DOMAIN
)
2589 struct ada_symbol_info
*candidates
;
2593 ada_lookup_symbol_list (SYMBOL_LINKAGE_NAME (exp
->elts
[pc
+ 2]
2595 exp
->elts
[pc
+ 1].block
,
2596 VAR_DOMAIN
, &candidates
);
2598 if (n_candidates
> 1)
2600 /* Types tend to get re-introduced locally, so if there
2601 are any local symbols that are not types, first filter
2604 for (j
= 0; j
< n_candidates
; j
+= 1)
2605 switch (SYMBOL_CLASS (candidates
[j
].sym
))
2611 case LOC_REGPARM_ADDR
:
2615 case LOC_BASEREG_ARG
:
2617 case LOC_COMPUTED_ARG
:
2623 if (j
< n_candidates
)
2626 while (j
< n_candidates
)
2628 if (SYMBOL_CLASS (candidates
[j
].sym
) == LOC_TYPEDEF
)
2630 candidates
[j
] = candidates
[n_candidates
- 1];
2639 if (n_candidates
== 0)
2640 error ("No definition found for %s",
2641 SYMBOL_PRINT_NAME (exp
->elts
[pc
+ 2].symbol
));
2642 else if (n_candidates
== 1)
2644 else if (deprocedure_p
2645 && !is_nonfunction (candidates
, n_candidates
))
2647 i
= ada_resolve_function (candidates
, n_candidates
, NULL
, 0,
2648 SYMBOL_LINKAGE_NAME (exp
->elts
[pc
+ 2]
2652 error ("Could not find a match for %s",
2653 SYMBOL_PRINT_NAME (exp
->elts
[pc
+ 2].symbol
));
2657 printf_filtered ("Multiple matches for %s\n",
2658 SYMBOL_PRINT_NAME (exp
->elts
[pc
+ 2].symbol
));
2659 user_select_syms (candidates
, n_candidates
, 1);
2663 exp
->elts
[pc
+ 1].block
= candidates
[i
].block
;
2664 exp
->elts
[pc
+ 2].symbol
= candidates
[i
].sym
;
2665 if (innermost_block
== NULL
||
2666 contained_in (candidates
[i
].block
, innermost_block
))
2667 innermost_block
= candidates
[i
].block
;
2671 && (TYPE_CODE (SYMBOL_TYPE (exp
->elts
[pc
+ 2].symbol
))
2674 replace_operator_with_call (expp
, pc
, 0, 0,
2675 exp
->elts
[pc
+ 2].symbol
,
2676 exp
->elts
[pc
+ 1].block
);
2683 if (exp
->elts
[pc
+ 3].opcode
== OP_VAR_VALUE
2684 && SYMBOL_DOMAIN (exp
->elts
[pc
+ 5].symbol
) == UNDEF_DOMAIN
)
2686 struct ada_symbol_info
*candidates
;
2690 ada_lookup_symbol_list (SYMBOL_LINKAGE_NAME (exp
->elts
[pc
+ 5]
2692 exp
->elts
[pc
+ 4].block
,
2693 VAR_DOMAIN
, &candidates
);
2694 if (n_candidates
== 1)
2698 i
= ada_resolve_function (candidates
, n_candidates
,
2700 SYMBOL_LINKAGE_NAME (exp
->elts
[pc
+5]
2704 error ("Could not find a match for %s",
2705 SYMBOL_PRINT_NAME (exp
->elts
[pc
+ 5].symbol
));
2708 exp
->elts
[pc
+ 4].block
= candidates
[i
].block
;
2709 exp
->elts
[pc
+ 5].symbol
= candidates
[i
].sym
;
2710 if (innermost_block
== NULL
||
2711 contained_in (candidates
[i
].block
, innermost_block
))
2712 innermost_block
= candidates
[i
].block
;
2723 case BINOP_BITWISE_AND
:
2724 case BINOP_BITWISE_IOR
:
2725 case BINOP_BITWISE_XOR
:
2727 case BINOP_NOTEQUAL
:
2735 case UNOP_LOGICAL_NOT
:
2737 if (possible_user_operator_p (op
, argvec
))
2739 struct ada_symbol_info
*candidates
;
2743 ada_lookup_symbol_list (ada_encode (ada_decoded_op_name (op
)),
2744 (struct block
*) NULL
, VAR_DOMAIN
,
2746 i
= ada_resolve_function (candidates
, n_candidates
, argvec
, nargs
,
2747 ada_decoded_op_name (op
), NULL
);
2751 replace_operator_with_call (expp
, pc
, nargs
, 1,
2752 candidates
[i
].sym
, candidates
[i
].block
);
2762 return evaluate_subexp_type (exp
, pos
);
2765 /* Return non-zero if formal type FTYPE matches actual type ATYPE. If
2766 MAY_DEREF is non-zero, the formal may be a pointer and the actual
2767 a non-pointer. A type of 'void' (which is never a valid expression type)
2768 by convention matches anything. */
2769 /* The term "match" here is rather loose. The match is heuristic and
2770 liberal. FIXME: TOO liberal, in fact. */
2773 ada_type_match (struct type
*ftype
, struct type
*atype
, int may_deref
)
2775 CHECK_TYPEDEF (ftype
);
2776 CHECK_TYPEDEF (atype
);
2778 if (TYPE_CODE (ftype
) == TYPE_CODE_REF
)
2779 ftype
= TYPE_TARGET_TYPE (ftype
);
2780 if (TYPE_CODE (atype
) == TYPE_CODE_REF
)
2781 atype
= TYPE_TARGET_TYPE (atype
);
2783 if (TYPE_CODE (ftype
) == TYPE_CODE_VOID
2784 || TYPE_CODE (atype
) == TYPE_CODE_VOID
)
2787 switch (TYPE_CODE (ftype
))
2792 if (TYPE_CODE (atype
) == TYPE_CODE_PTR
)
2793 return ada_type_match (TYPE_TARGET_TYPE (ftype
),
2794 TYPE_TARGET_TYPE (atype
), 0);
2796 return (may_deref
&&
2797 ada_type_match (TYPE_TARGET_TYPE (ftype
), atype
, 0));
2799 case TYPE_CODE_ENUM
:
2800 case TYPE_CODE_RANGE
:
2801 switch (TYPE_CODE (atype
))
2804 case TYPE_CODE_ENUM
:
2805 case TYPE_CODE_RANGE
:
2811 case TYPE_CODE_ARRAY
:
2812 return (TYPE_CODE (atype
) == TYPE_CODE_ARRAY
2813 || ada_is_array_descriptor_type (atype
));
2815 case TYPE_CODE_STRUCT
:
2816 if (ada_is_array_descriptor_type (ftype
))
2817 return (TYPE_CODE (atype
) == TYPE_CODE_ARRAY
2818 || ada_is_array_descriptor_type (atype
));
2820 return (TYPE_CODE (atype
) == TYPE_CODE_STRUCT
2821 && !ada_is_array_descriptor_type (atype
));
2823 case TYPE_CODE_UNION
:
2825 return (TYPE_CODE (atype
) == TYPE_CODE (ftype
));
2829 /* Return non-zero if the formals of FUNC "sufficiently match" the
2830 vector of actual argument types ACTUALS of size N_ACTUALS. FUNC
2831 may also be an enumeral, in which case it is treated as a 0-
2832 argument function. */
2835 ada_args_match (struct symbol
*func
, struct value
**actuals
, int n_actuals
)
2838 struct type
*func_type
= SYMBOL_TYPE (func
);
2840 if (SYMBOL_CLASS (func
) == LOC_CONST
&&
2841 TYPE_CODE (func_type
) == TYPE_CODE_ENUM
)
2842 return (n_actuals
== 0);
2843 else if (func_type
== NULL
|| TYPE_CODE (func_type
) != TYPE_CODE_FUNC
)
2846 if (TYPE_NFIELDS (func_type
) != n_actuals
)
2849 for (i
= 0; i
< n_actuals
; i
+= 1)
2851 if (actuals
[i
] == NULL
)
2855 struct type
*ftype
= check_typedef (TYPE_FIELD_TYPE (func_type
, i
));
2856 struct type
*atype
= check_typedef (VALUE_TYPE (actuals
[i
]));
2858 if (!ada_type_match (ftype
, atype
, 1))
2865 /* False iff function type FUNC_TYPE definitely does not produce a value
2866 compatible with type CONTEXT_TYPE. Conservatively returns 1 if
2867 FUNC_TYPE is not a valid function type with a non-null return type
2868 or an enumerated type. A null CONTEXT_TYPE indicates any non-void type. */
2871 return_match (struct type
*func_type
, struct type
*context_type
)
2873 struct type
*return_type
;
2875 if (func_type
== NULL
)
2878 if (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
)
2879 return_type
= base_type (TYPE_TARGET_TYPE (func_type
));
2881 return_type
= base_type (func_type
);
2882 if (return_type
== NULL
)
2885 context_type
= base_type (context_type
);
2887 if (TYPE_CODE (return_type
) == TYPE_CODE_ENUM
)
2888 return context_type
== NULL
|| return_type
== context_type
;
2889 else if (context_type
== NULL
)
2890 return TYPE_CODE (return_type
) != TYPE_CODE_VOID
;
2892 return TYPE_CODE (return_type
) == TYPE_CODE (context_type
);
2896 /* Returns the index in SYMS[0..NSYMS-1] that contains the symbol for the
2897 function (if any) that matches the types of the NARGS arguments in
2898 ARGS. If CONTEXT_TYPE is non-null and there is at least one match
2899 that returns that type, then eliminate matches that don't. If
2900 CONTEXT_TYPE is void and there is at least one match that does not
2901 return void, eliminate all matches that do.
2903 Asks the user if there is more than one match remaining. Returns -1
2904 if there is no such symbol or none is selected. NAME is used
2905 solely for messages. May re-arrange and modify SYMS in
2906 the process; the index returned is for the modified vector. */
2909 ada_resolve_function (struct ada_symbol_info syms
[],
2910 int nsyms
, struct value
**args
, int nargs
,
2911 const char *name
, struct type
*context_type
)
2914 int m
; /* Number of hits */
2915 struct type
*fallback
;
2916 struct type
*return_type
;
2918 return_type
= context_type
;
2919 if (context_type
== NULL
)
2920 fallback
= builtin_type_void
;
2927 for (k
= 0; k
< nsyms
; k
+= 1)
2929 struct type
*type
= check_typedef (SYMBOL_TYPE (syms
[k
].sym
));
2931 if (ada_args_match (syms
[k
].sym
, args
, nargs
)
2932 && return_match (type
, return_type
))
2938 if (m
> 0 || return_type
== fallback
)
2941 return_type
= fallback
;
2948 printf_filtered ("Multiple matches for %s\n", name
);
2949 user_select_syms (syms
, m
, 1);
2955 /* Returns true (non-zero) iff decoded name N0 should appear before N1
2956 in a listing of choices during disambiguation (see sort_choices, below).
2957 The idea is that overloadings of a subprogram name from the
2958 same package should sort in their source order. We settle for ordering
2959 such symbols by their trailing number (__N or $N). */
2962 encoded_ordered_before (char *N0
, char *N1
)
2966 else if (N0
== NULL
)
2971 for (k0
= strlen (N0
) - 1; k0
> 0 && isdigit (N0
[k0
]); k0
-= 1)
2973 for (k1
= strlen (N1
) - 1; k1
> 0 && isdigit (N1
[k1
]); k1
-= 1)
2975 if ((N0
[k0
] == '_' || N0
[k0
] == '$') && N0
[k0
+ 1] != '\000'
2976 && (N1
[k1
] == '_' || N1
[k1
] == '$') && N1
[k1
+ 1] != '\000')
2980 while (N0
[n0
] == '_' && n0
> 0 && N0
[n0
- 1] == '_')
2983 while (N1
[n1
] == '_' && n1
> 0 && N1
[n1
- 1] == '_')
2985 if (n0
== n1
&& strncmp (N0
, N1
, n0
) == 0)
2986 return (atoi (N0
+ k0
+ 1) < atoi (N1
+ k1
+ 1));
2988 return (strcmp (N0
, N1
) < 0);
2992 /* Sort SYMS[0..NSYMS-1] to put the choices in a canonical order by the
2996 sort_choices (struct ada_symbol_info syms
[], int nsyms
)
2999 for (i
= 1; i
< nsyms
; i
+= 1)
3001 struct ada_symbol_info sym
= syms
[i
];
3004 for (j
= i
- 1; j
>= 0; j
-= 1)
3006 if (encoded_ordered_before (SYMBOL_LINKAGE_NAME (syms
[j
].sym
),
3007 SYMBOL_LINKAGE_NAME (sym
.sym
)))
3009 syms
[j
+ 1] = syms
[j
];
3015 /* Given a list of NSYMS symbols in SYMS, select up to MAX_RESULTS>0
3016 by asking the user (if necessary), returning the number selected,
3017 and setting the first elements of SYMS items. Error if no symbols
3020 /* NOTE: Adapted from decode_line_2 in symtab.c, with which it ought
3021 to be re-integrated one of these days. */
3024 user_select_syms (struct ada_symbol_info
*syms
, int nsyms
, int max_results
)
3027 int *chosen
= (int *) alloca (sizeof (int) * nsyms
);
3029 int first_choice
= (max_results
== 1) ? 1 : 2;
3031 if (max_results
< 1)
3032 error ("Request to select 0 symbols!");
3036 printf_unfiltered ("[0] cancel\n");
3037 if (max_results
> 1)
3038 printf_unfiltered ("[1] all\n");
3040 sort_choices (syms
, nsyms
);
3042 for (i
= 0; i
< nsyms
; i
+= 1)
3044 if (syms
[i
].sym
== NULL
)
3047 if (SYMBOL_CLASS (syms
[i
].sym
) == LOC_BLOCK
)
3049 struct symtab_and_line sal
= find_function_start_sal (syms
[i
].sym
, 1);
3050 printf_unfiltered ("[%d] %s at %s:%d\n",
3052 SYMBOL_PRINT_NAME (syms
[i
].sym
),
3054 ? "<no source file available>"
3055 : sal
.symtab
->filename
, sal
.line
);
3061 (SYMBOL_CLASS (syms
[i
].sym
) == LOC_CONST
3062 && SYMBOL_TYPE (syms
[i
].sym
) != NULL
3063 && TYPE_CODE (SYMBOL_TYPE (syms
[i
].sym
)) == TYPE_CODE_ENUM
);
3064 struct symtab
*symtab
= symtab_for_sym (syms
[i
].sym
);
3066 if (SYMBOL_LINE (syms
[i
].sym
) != 0 && symtab
!= NULL
)
3067 printf_unfiltered ("[%d] %s at %s:%d\n",
3069 SYMBOL_PRINT_NAME (syms
[i
].sym
),
3070 symtab
->filename
, SYMBOL_LINE (syms
[i
].sym
));
3071 else if (is_enumeral
&& TYPE_NAME (SYMBOL_TYPE (syms
[i
].sym
)) != NULL
)
3073 printf_unfiltered ("[%d] ", i
+ first_choice
);
3074 ada_print_type (SYMBOL_TYPE (syms
[i
].sym
), NULL
,
3076 printf_unfiltered ("'(%s) (enumeral)\n",
3077 SYMBOL_PRINT_NAME (syms
[i
].sym
));
3079 else if (symtab
!= NULL
)
3080 printf_unfiltered (is_enumeral
3081 ? "[%d] %s in %s (enumeral)\n"
3082 : "[%d] %s at %s:?\n",
3084 SYMBOL_PRINT_NAME (syms
[i
].sym
),
3087 printf_unfiltered (is_enumeral
3088 ? "[%d] %s (enumeral)\n"
3091 SYMBOL_PRINT_NAME (syms
[i
].sym
));
3095 n_chosen
= get_selections (chosen
, nsyms
, max_results
, max_results
> 1,
3098 for (i
= 0; i
< n_chosen
; i
+= 1)
3099 syms
[i
] = syms
[chosen
[i
]];
3104 /* Read and validate a set of numeric choices from the user in the
3105 range 0 .. N_CHOICES-1. Place the results in increasing
3106 order in CHOICES[0 .. N-1], and return N.
3108 The user types choices as a sequence of numbers on one line
3109 separated by blanks, encoding them as follows:
3111 + A choice of 0 means to cancel the selection, throwing an error.
3112 + If IS_ALL_CHOICE, a choice of 1 selects the entire set 0 .. N_CHOICES-1.
3113 + The user chooses k by typing k+IS_ALL_CHOICE+1.
3115 The user is not allowed to choose more than MAX_RESULTS values.
3117 ANNOTATION_SUFFIX, if present, is used to annotate the input
3118 prompts (for use with the -f switch). */
3121 get_selections (int *choices
, int n_choices
, int max_results
,
3122 int is_all_choice
, char *annotation_suffix
)
3127 int first_choice
= is_all_choice
? 2 : 1;
3129 prompt
= getenv ("PS2");
3133 printf_unfiltered ("%s ", prompt
);
3134 gdb_flush (gdb_stdout
);
3136 args
= command_line_input ((char *) NULL
, 0, annotation_suffix
);
3139 error_no_arg ("one or more choice numbers");
3143 /* Set choices[0 .. n_chosen-1] to the users' choices in ascending
3144 order, as given in args. Choices are validated. */
3150 while (isspace (*args
))
3152 if (*args
== '\0' && n_chosen
== 0)
3153 error_no_arg ("one or more choice numbers");
3154 else if (*args
== '\0')
3157 choice
= strtol (args
, &args2
, 10);
3158 if (args
== args2
|| choice
< 0
3159 || choice
> n_choices
+ first_choice
- 1)
3160 error ("Argument must be choice number");
3164 error ("cancelled");
3166 if (choice
< first_choice
)
3168 n_chosen
= n_choices
;
3169 for (j
= 0; j
< n_choices
; j
+= 1)
3173 choice
-= first_choice
;
3175 for (j
= n_chosen
- 1; j
>= 0 && choice
< choices
[j
]; j
-= 1)
3179 if (j
< 0 || choice
!= choices
[j
])
3182 for (k
= n_chosen
- 1; k
> j
; k
-= 1)
3183 choices
[k
+ 1] = choices
[k
];
3184 choices
[j
+ 1] = choice
;
3189 if (n_chosen
> max_results
)
3190 error ("Select no more than %d of the above", max_results
);
3195 /* Replace the operator of length OPLEN at position PC in *EXPP with a call
3196 on the function identified by SYM and BLOCK, and taking NARGS
3197 arguments. Update *EXPP as needed to hold more space. */
3200 replace_operator_with_call (struct expression
**expp
, int pc
, int nargs
,
3201 int oplen
, struct symbol
*sym
,
3202 struct block
*block
)
3204 /* A new expression, with 6 more elements (3 for funcall, 4 for function
3205 symbol, -oplen for operator being replaced). */
3206 struct expression
*newexp
= (struct expression
*)
3207 xmalloc (sizeof (struct expression
)
3208 + EXP_ELEM_TO_BYTES ((*expp
)->nelts
+ 7 - oplen
));
3209 struct expression
*exp
= *expp
;
3211 newexp
->nelts
= exp
->nelts
+ 7 - oplen
;
3212 newexp
->language_defn
= exp
->language_defn
;
3213 memcpy (newexp
->elts
, exp
->elts
, EXP_ELEM_TO_BYTES (pc
));
3214 memcpy (newexp
->elts
+ pc
+ 7, exp
->elts
+ pc
+ oplen
,
3215 EXP_ELEM_TO_BYTES (exp
->nelts
- pc
- oplen
));
3217 newexp
->elts
[pc
].opcode
= newexp
->elts
[pc
+ 2].opcode
= OP_FUNCALL
;
3218 newexp
->elts
[pc
+ 1].longconst
= (LONGEST
) nargs
;
3220 newexp
->elts
[pc
+ 3].opcode
= newexp
->elts
[pc
+ 6].opcode
= OP_VAR_VALUE
;
3221 newexp
->elts
[pc
+ 4].block
= block
;
3222 newexp
->elts
[pc
+ 5].symbol
= sym
;
3228 /* Type-class predicates */
3230 /* True iff TYPE is numeric (i.e., an INT, RANGE (of numeric type),
3234 numeric_type_p (struct type
*type
)
3240 switch (TYPE_CODE (type
))
3245 case TYPE_CODE_RANGE
:
3246 return (type
== TYPE_TARGET_TYPE (type
)
3247 || numeric_type_p (TYPE_TARGET_TYPE (type
)));
3254 /* True iff TYPE is integral (an INT or RANGE of INTs). */
3257 integer_type_p (struct type
*type
)
3263 switch (TYPE_CODE (type
))
3267 case TYPE_CODE_RANGE
:
3268 return (type
== TYPE_TARGET_TYPE (type
)
3269 || integer_type_p (TYPE_TARGET_TYPE (type
)));
3276 /* True iff TYPE is scalar (INT, RANGE, FLOAT, ENUM). */
3279 scalar_type_p (struct type
*type
)
3285 switch (TYPE_CODE (type
))
3288 case TYPE_CODE_RANGE
:
3289 case TYPE_CODE_ENUM
:
3298 /* True iff TYPE is discrete (INT, RANGE, ENUM). */
3301 discrete_type_p (struct type
*type
)
3307 switch (TYPE_CODE (type
))
3310 case TYPE_CODE_RANGE
:
3311 case TYPE_CODE_ENUM
:
3319 /* Returns non-zero if OP with operands in the vector ARGS could be
3320 a user-defined function. Errs on the side of pre-defined operators
3321 (i.e., result 0). */
3324 possible_user_operator_p (enum exp_opcode op
, struct value
*args
[])
3326 struct type
*type0
=
3327 (args
[0] == NULL
) ? NULL
: check_typedef (VALUE_TYPE (args
[0]));
3328 struct type
*type1
=
3329 (args
[1] == NULL
) ? NULL
: check_typedef (VALUE_TYPE (args
[1]));
3343 return (!(numeric_type_p (type0
) && numeric_type_p (type1
)));
3347 case BINOP_BITWISE_AND
:
3348 case BINOP_BITWISE_IOR
:
3349 case BINOP_BITWISE_XOR
:
3350 return (!(integer_type_p (type0
) && integer_type_p (type1
)));
3353 case BINOP_NOTEQUAL
:
3358 return (!(scalar_type_p (type0
) && scalar_type_p (type1
)));
3361 return ((TYPE_CODE (type0
) != TYPE_CODE_ARRAY
&&
3362 (TYPE_CODE (type0
) != TYPE_CODE_PTR
||
3363 TYPE_CODE (TYPE_TARGET_TYPE (type0
))
3364 != TYPE_CODE_ARRAY
))
3365 || (TYPE_CODE (type1
) != TYPE_CODE_ARRAY
&&
3366 (TYPE_CODE (type1
) != TYPE_CODE_PTR
||
3367 TYPE_CODE (TYPE_TARGET_TYPE (type1
)) != TYPE_CODE_ARRAY
)));
3370 return (!(numeric_type_p (type0
) && integer_type_p (type1
)));
3374 case UNOP_LOGICAL_NOT
:
3376 return (!numeric_type_p (type0
));
3383 /* NOTE: In the following, we assume that a renaming type's name may
3384 have an ___XD suffix. It would be nice if this went away at some
3387 /* If TYPE encodes a renaming, returns the renaming suffix, which
3388 is XR for an object renaming, XRP for a procedure renaming, XRE for
3389 an exception renaming, and XRS for a subprogram renaming. Returns
3390 NULL if NAME encodes none of these. */
3393 ada_renaming_type (struct type
*type
)
3395 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_ENUM
)
3397 const char *name
= type_name_no_tag (type
);
3398 const char *suffix
= (name
== NULL
) ? NULL
: strstr (name
, "___XR");
3400 || (suffix
[5] != '\000' && strchr ("PES_", suffix
[5]) == NULL
))
3409 /* Return non-zero iff SYM encodes an object renaming. */
3412 ada_is_object_renaming (struct symbol
*sym
)
3414 const char *renaming_type
= ada_renaming_type (SYMBOL_TYPE (sym
));
3415 return renaming_type
!= NULL
3416 && (renaming_type
[2] == '\0' || renaming_type
[2] == '_');
3419 /* Assuming that SYM encodes a non-object renaming, returns the original
3420 name of the renamed entity. The name is good until the end of
3424 ada_simple_renamed_entity (struct symbol
*sym
)
3427 const char *raw_name
;
3431 type
= SYMBOL_TYPE (sym
);
3432 if (type
== NULL
|| TYPE_NFIELDS (type
) < 1)
3433 error ("Improperly encoded renaming.");
3435 raw_name
= TYPE_FIELD_NAME (type
, 0);
3436 len
= (raw_name
== NULL
? 0 : strlen (raw_name
)) - 5;
3438 error ("Improperly encoded renaming.");
3440 result
= xmalloc (len
+ 1);
3441 strncpy (result
, raw_name
, len
);
3442 result
[len
] = '\000';
3447 /* Evaluation: Function Calls */
3449 /* Return an lvalue containing the value VAL. This is the identity on
3450 lvalues, and otherwise has the side-effect of pushing a copy of VAL
3451 on the stack, using and updating *SP as the stack pointer, and
3452 returning an lvalue whose VALUE_ADDRESS points to the copy. */
3454 static struct value
*
3455 ensure_lval (struct value
*val
, CORE_ADDR
*sp
)
3457 CORE_ADDR old_sp
= *sp
;
3459 if (VALUE_LVAL (val
))
3462 if (DEPRECATED_STACK_ALIGN_P ())
3463 *sp
= push_bytes (*sp
, VALUE_CONTENTS_RAW (val
),
3464 DEPRECATED_STACK_ALIGN
3465 (TYPE_LENGTH (check_typedef (VALUE_TYPE (val
)))));
3467 *sp
= push_bytes (*sp
, VALUE_CONTENTS_RAW (val
),
3468 TYPE_LENGTH (check_typedef (VALUE_TYPE (val
))));
3470 VALUE_LVAL (val
) = lval_memory
;
3471 if (INNER_THAN (1, 2))
3472 VALUE_ADDRESS (val
) = *sp
;
3474 VALUE_ADDRESS (val
) = old_sp
;
3479 /* Return the value ACTUAL, converted to be an appropriate value for a
3480 formal of type FORMAL_TYPE. Use *SP as a stack pointer for
3481 allocating any necessary descriptors (fat pointers), or copies of
3482 values not residing in memory, updating it as needed. */
3484 static struct value
*
3485 convert_actual (struct value
*actual
, struct type
*formal_type0
,
3488 struct type
*actual_type
= check_typedef (VALUE_TYPE (actual
));
3489 struct type
*formal_type
= check_typedef (formal_type0
);
3490 struct type
*formal_target
=
3491 TYPE_CODE (formal_type
) == TYPE_CODE_PTR
3492 ? check_typedef (TYPE_TARGET_TYPE (formal_type
)) : formal_type
;
3493 struct type
*actual_target
=
3494 TYPE_CODE (actual_type
) == TYPE_CODE_PTR
3495 ? check_typedef (TYPE_TARGET_TYPE (actual_type
)) : actual_type
;
3497 if (ada_is_array_descriptor_type (formal_target
)
3498 && TYPE_CODE (actual_target
) == TYPE_CODE_ARRAY
)
3499 return make_array_descriptor (formal_type
, actual
, sp
);
3500 else if (TYPE_CODE (formal_type
) == TYPE_CODE_PTR
)
3502 if (TYPE_CODE (formal_target
) == TYPE_CODE_ARRAY
3503 && ada_is_array_descriptor_type (actual_target
))
3504 return desc_data (actual
);
3505 else if (TYPE_CODE (actual_type
) != TYPE_CODE_PTR
)
3507 if (VALUE_LVAL (actual
) != lval_memory
)
3510 actual_type
= check_typedef (VALUE_TYPE (actual
));
3511 val
= allocate_value (actual_type
);
3512 memcpy ((char *) VALUE_CONTENTS_RAW (val
),
3513 (char *) VALUE_CONTENTS (actual
),
3514 TYPE_LENGTH (actual_type
));
3515 actual
= ensure_lval (val
, sp
);
3517 return value_addr (actual
);
3520 else if (TYPE_CODE (actual_type
) == TYPE_CODE_PTR
)
3521 return ada_value_ind (actual
);
3527 /* Push a descriptor of type TYPE for array value ARR on the stack at
3528 *SP, updating *SP to reflect the new descriptor. Return either
3529 an lvalue representing the new descriptor, or (if TYPE is a pointer-
3530 to-descriptor type rather than a descriptor type), a struct value *
3531 representing a pointer to this descriptor. */
3533 static struct value
*
3534 make_array_descriptor (struct type
*type
, struct value
*arr
, CORE_ADDR
*sp
)
3536 struct type
*bounds_type
= desc_bounds_type (type
);
3537 struct type
*desc_type
= desc_base_type (type
);
3538 struct value
*descriptor
= allocate_value (desc_type
);
3539 struct value
*bounds
= allocate_value (bounds_type
);
3542 for (i
= ada_array_arity (check_typedef (VALUE_TYPE (arr
))); i
> 0; i
-= 1)
3544 modify_general_field (VALUE_CONTENTS (bounds
),
3545 value_as_long (ada_array_bound (arr
, i
, 0)),
3546 desc_bound_bitpos (bounds_type
, i
, 0),
3547 desc_bound_bitsize (bounds_type
, i
, 0));
3548 modify_general_field (VALUE_CONTENTS (bounds
),
3549 value_as_long (ada_array_bound (arr
, i
, 1)),
3550 desc_bound_bitpos (bounds_type
, i
, 1),
3551 desc_bound_bitsize (bounds_type
, i
, 1));
3554 bounds
= ensure_lval (bounds
, sp
);
3556 modify_general_field (VALUE_CONTENTS (descriptor
),
3557 VALUE_ADDRESS (ensure_lval (arr
, sp
)),
3558 fat_pntr_data_bitpos (desc_type
),
3559 fat_pntr_data_bitsize (desc_type
));
3561 modify_general_field (VALUE_CONTENTS (descriptor
),
3562 VALUE_ADDRESS (bounds
),
3563 fat_pntr_bounds_bitpos (desc_type
),
3564 fat_pntr_bounds_bitsize (desc_type
));
3566 descriptor
= ensure_lval (descriptor
, sp
);
3568 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
3569 return value_addr (descriptor
);
3575 /* Assuming a dummy frame has been established on the target, perform any
3576 conversions needed for calling function FUNC on the NARGS actual
3577 parameters in ARGS, other than standard C conversions. Does
3578 nothing if FUNC does not have Ada-style prototype data, or if NARGS
3579 does not match the number of arguments expected. Use *SP as a
3580 stack pointer for additional data that must be pushed, updating its
3584 ada_convert_actuals (struct value
*func
, int nargs
, struct value
*args
[],
3589 if (TYPE_NFIELDS (VALUE_TYPE (func
)) == 0
3590 || nargs
!= TYPE_NFIELDS (VALUE_TYPE (func
)))
3593 for (i
= 0; i
< nargs
; i
+= 1)
3595 convert_actual (args
[i
], TYPE_FIELD_TYPE (VALUE_TYPE (func
), i
), sp
);
3598 /* Experimental Symbol Cache Module */
3600 /* This section implements a simple, fixed-sized hash table for those
3601 Ada-mode symbols that get looked up in the course of executing the user's
3602 commands. The size is fixed on the grounds that there are not
3603 likely to be all that many symbols looked up during any given
3604 session, regardless of the size of the symbol table. If we decide
3605 to go to a resizable table, let's just use the stuff from libiberty
3608 #define HASH_SIZE 1009
3610 struct cache_entry
{
3612 domain_enum
namespace;
3614 struct symtab
*symtab
;
3615 struct block
*block
;
3616 struct cache_entry
*next
;
3619 static struct obstack cache_space
;
3621 static struct cache_entry
*cache
[HASH_SIZE
];
3623 /* Clear all entries from the symbol cache. */
3626 clear_ada_sym_cache (void)
3628 obstack_free (&cache_space
, NULL
);
3629 obstack_init (&cache_space
);
3630 memset (cache
, '\000', sizeof (cache
));
3633 static struct cache_entry
**
3634 find_entry (const char *name
, domain_enum
namespace)
3636 int h
= msymbol_hash (name
) % HASH_SIZE
;
3637 struct cache_entry
**e
;
3638 for (e
= &cache
[h
]; *e
!= NULL
; e
= &(*e
)->next
)
3640 if (namespace == (*e
)->namespace && strcmp (name
, (*e
)->name
) == 0)
3646 /* Return (in SYM) the last cached definition for global or static symbol NAME
3647 in namespace DOMAIN. Returns 1 if entry found, 0 otherwise.
3648 If SYMTAB is non-NULL, store the symbol
3649 table in which the symbol was found there, or NULL if not found.
3650 *BLOCK is set to the block in which NAME is found. */
3653 lookup_cached_symbol (const char *name
, domain_enum
namespace,
3654 struct symbol
**sym
, struct block
**block
,
3655 struct symtab
**symtab
)
3657 struct cache_entry
**e
= find_entry (name
, namespace);
3663 *block
= (*e
)->block
;
3665 *symtab
= (*e
)->symtab
;
3669 /* Set the cached definition of NAME in DOMAIN to SYM in block
3670 BLOCK and symbol table SYMTAB. */
3673 cache_symbol (const char *name
, domain_enum
namespace, struct symbol
*sym
,
3674 struct block
*block
, struct symtab
*symtab
)
3676 int h
= msymbol_hash (name
) % HASH_SIZE
;
3678 struct cache_entry
*e
=
3679 (struct cache_entry
*) obstack_alloc(&cache_space
, sizeof (*e
));
3682 e
->name
= copy
= obstack_alloc (&cache_space
, strlen (name
) + 1);
3683 strcpy (copy
, name
);
3685 e
->namespace = namespace;
3692 /* Return the result of a standard (literal, C-like) lookup of NAME in
3693 given DOMAIN, visible from lexical block BLOCK. */
3695 static struct symbol
*
3696 standard_lookup (const char *name
, const struct block
*block
,
3700 struct symtab
*symtab
;
3702 if (lookup_cached_symbol (name
, domain
, &sym
, NULL
, NULL
))
3704 sym
= lookup_symbol_in_language (name
, block
, domain
, language_c
, 0, &symtab
);
3705 cache_symbol (name
, domain
, sym
, block_found
, symtab
);
3710 /* Non-zero iff there is at least one non-function/non-enumeral symbol
3711 in the symbol fields of SYMS[0..N-1]. We treat enumerals as functions,
3712 since they contend in overloading in the same way. */
3714 is_nonfunction (struct ada_symbol_info syms
[], int n
)
3718 for (i
= 0; i
< n
; i
+= 1)
3719 if (TYPE_CODE (SYMBOL_TYPE (syms
[i
].sym
)) != TYPE_CODE_FUNC
3720 && (TYPE_CODE (SYMBOL_TYPE (syms
[i
].sym
)) != TYPE_CODE_ENUM
3721 || SYMBOL_CLASS (syms
[i
].sym
) != LOC_CONST
))
3727 /* If true (non-zero), then TYPE0 and TYPE1 represent equivalent
3728 struct types. Otherwise, they may not. */
3731 equiv_types (struct type
*type0
, struct type
*type1
)
3735 if (type0
== NULL
|| type1
== NULL
3736 || TYPE_CODE (type0
) != TYPE_CODE (type1
))
3738 if ((TYPE_CODE (type0
) == TYPE_CODE_STRUCT
3739 || TYPE_CODE (type0
) == TYPE_CODE_ENUM
)
3740 && ada_type_name (type0
) != NULL
&& ada_type_name (type1
) != NULL
3741 && strcmp (ada_type_name (type0
), ada_type_name (type1
)) == 0)
3747 /* True iff SYM0 represents the same entity as SYM1, or one that is
3748 no more defined than that of SYM1. */
3751 lesseq_defined_than (struct symbol
*sym0
, struct symbol
*sym1
)
3755 if (SYMBOL_DOMAIN (sym0
) != SYMBOL_DOMAIN (sym1
)
3756 || SYMBOL_CLASS (sym0
) != SYMBOL_CLASS (sym1
))
3759 switch (SYMBOL_CLASS (sym0
))
3765 struct type
*type0
= SYMBOL_TYPE (sym0
);
3766 struct type
*type1
= SYMBOL_TYPE (sym1
);
3767 char *name0
= SYMBOL_LINKAGE_NAME (sym0
);
3768 char *name1
= SYMBOL_LINKAGE_NAME (sym1
);
3769 int len0
= strlen (name0
);
3771 TYPE_CODE (type0
) == TYPE_CODE (type1
)
3772 && (equiv_types (type0
, type1
)
3773 || (len0
< strlen (name1
) && strncmp (name0
, name1
, len0
) == 0
3774 && strncmp (name1
+ len0
, "___XV", 5) == 0));
3777 return SYMBOL_VALUE (sym0
) == SYMBOL_VALUE (sym1
)
3778 && equiv_types (SYMBOL_TYPE (sym0
), SYMBOL_TYPE (sym1
));
3784 /* Append (SYM,BLOCK,SYMTAB) to the end of the array of struct ada_symbol_info
3785 records in OBSTACKP. Do nothing if SYM is a duplicate. */
3788 add_defn_to_vec (struct obstack
*obstackp
,
3790 struct block
*block
,
3791 struct symtab
*symtab
)
3795 struct ada_symbol_info
*prevDefns
= defns_collected (obstackp
, 0);
3797 if (SYMBOL_TYPE (sym
) != NULL
)
3798 CHECK_TYPEDEF (SYMBOL_TYPE (sym
));
3799 for (i
= num_defns_collected (obstackp
) - 1; i
>= 0; i
-= 1)
3801 if (lesseq_defined_than (sym
, prevDefns
[i
].sym
))
3803 else if (lesseq_defined_than (prevDefns
[i
].sym
, sym
))
3805 prevDefns
[i
].sym
= sym
;
3806 prevDefns
[i
].block
= block
;
3807 prevDefns
[i
].symtab
= symtab
;
3813 struct ada_symbol_info info
;
3817 info
.symtab
= symtab
;
3818 obstack_grow (obstackp
, &info
, sizeof (struct ada_symbol_info
));
3822 /* Number of ada_symbol_info structures currently collected in
3823 current vector in *OBSTACKP. */
3826 num_defns_collected (struct obstack
*obstackp
)
3828 return obstack_object_size (obstackp
) / sizeof (struct ada_symbol_info
);
3831 /* Vector of ada_symbol_info structures currently collected in current
3832 vector in *OBSTACKP. If FINISH, close off the vector and return
3833 its final address. */
3835 static struct ada_symbol_info
*
3836 defns_collected (struct obstack
*obstackp
, int finish
)
3839 return obstack_finish (obstackp
);
3841 return (struct ada_symbol_info
*) obstack_base (obstackp
);
3844 /* If SYM_NAME is a completion candidate for TEXT, return this symbol
3845 name in a form that's appropriate for the completion. The result
3846 does not need to be deallocated, but is only good until the next call.
3848 TEXT_LEN is equal to the length of TEXT.
3849 Perform a wild match if WILD_MATCH is set.
3850 ENCODED should be set if TEXT represents the start of a symbol name
3851 in its encoded form. */
3854 symbol_completion_match (const char *sym_name
,
3855 const char *text
, int text_len
,
3856 int wild_match
, int encoded
)
3859 const int verbatim_match
= (text
[0] == '<');
3864 /* Strip the leading angle bracket. */
3869 /* First, test against the fully qualified name of the symbol. */
3871 if (strncmp (sym_name
, text
, text_len
) == 0)
3874 if (match
&& !encoded
)
3876 /* One needed check before declaring a positive match is to verify
3877 that iff we are doing a verbatim match, the decoded version
3878 of the symbol name starts with '<'. Otherwise, this symbol name
3879 is not a suitable completion. */
3880 const char *sym_name_copy
= sym_name
;
3881 int has_angle_bracket
;
3883 sym_name
= ada_decode (sym_name
);
3884 has_angle_bracket
= (sym_name
[0] == '<');
3885 match
= (has_angle_bracket
== verbatim_match
);
3886 sym_name
= sym_name_copy
;
3889 if (match
&& !verbatim_match
)
3891 /* When doing non-verbatim match, another check that needs to
3892 be done is to verify that the potentially matching symbol name
3893 does not include capital letters, because the ada-mode would
3894 not be able to understand these symbol names without the
3895 angle bracket notation. */
3898 for (tmp
= sym_name
; *tmp
!= '\0' && !isupper (*tmp
); tmp
++);
3903 /* Second: Try wild matching... */
3905 if (!match
&& wild_match
)
3907 /* Since we are doing wild matching, this means that TEXT
3908 may represent an unqualified symbol name. We therefore must
3909 also compare TEXT against the unqualified name of the symbol. */
3910 sym_name
= ada_unqualified_name (ada_decode (sym_name
));
3912 if (strncmp (sym_name
, text
, text_len
) == 0)
3916 /* Finally: If we found a mach, prepare the result to return. */
3922 sym_name
= add_angle_brackets (sym_name
);
3925 sym_name
= ada_decode (sym_name
);
3930 /* A companion function to ada_make_symbol_completion_list().
3931 Check if SYM_NAME represents a symbol which name would be suitable
3932 to complete TEXT (TEXT_LEN is the length of TEXT), in which case
3933 it is appended at the end of the given string vector SV.
3935 ORIG_TEXT is the string original string from the user command
3936 that needs to be completed. WORD is the entire command on which
3937 completion should be performed. These two parameters are used to
3938 determine which part of the symbol name should be added to the
3940 if WILD_MATCH is set, then wild matching is performed.
3941 ENCODED should be set if TEXT represents a symbol name in its
3942 encoded formed (in which case the completion should also be
3946 symbol_completion_add (struct string_vector
*sv
,
3947 const char *sym_name
,
3948 const char *text
, int text_len
,
3949 const char *orig_text
, const char *word
,
3950 int wild_match
, int encoded
)
3952 const char *match
= symbol_completion_match (sym_name
, text
, text_len
,
3953 wild_match
, encoded
);
3959 /* We found a match, so add the appropriate completion to the given
3962 if (word
== orig_text
)
3964 completion
= xmalloc (strlen (match
) + 5);
3965 strcpy (completion
, match
);
3967 else if (word
> orig_text
)
3969 /* Return some portion of sym_name. */
3970 completion
= xmalloc (strlen (match
) + 5);
3971 strcpy (completion
, match
+ (word
- orig_text
));
3975 /* Return some of ORIG_TEXT plus sym_name. */
3976 completion
= xmalloc (strlen (match
) + (orig_text
- word
) + 5);
3977 strncpy (completion
, word
, orig_text
- word
);
3978 completion
[orig_text
- word
] = '\0';
3979 strcat (completion
, match
);
3982 string_vector_append (sv
, completion
);
3985 /* Return a list of possible symbol names completing TEXT0. The list
3986 is NULL terminated. WORD is the entire command on which completion
3990 ada_make_symbol_completion_list (const char *text0
, const char *word
)
3992 /* Note: This function is almost a copy of make_symbol_completion_list(),
3993 except it has been adapted for Ada. It is somewhat of a shame to
3994 duplicate so much code, but we don't really have the infrastructure
3995 yet to develop a language-aware version of he symbol completer... */
4000 struct string_vector result
= xnew_string_vector (128);
4003 struct partial_symtab
*ps
;
4004 struct minimal_symbol
*msymbol
;
4005 struct objfile
*objfile
;
4006 struct block
*b
, *surrounding_static_block
= 0;
4008 struct dict_iterator iter
;
4010 if (text0
[0] == '<')
4012 text
= xstrdup (text0
);
4013 make_cleanup (xfree
, text
);
4014 text_len
= strlen (text
);
4020 text
= xstrdup (ada_encode (text0
));
4021 make_cleanup (xfree
, text
);
4022 text_len
= strlen (text
);
4023 for (i
= 0; i
< text_len
; i
++)
4024 text
[i
] = tolower (text
[i
]);
4026 /* FIXME: brobecker/2003-09-17: When we get rid of ADA_RETAIN_DOTS,
4027 we can restrict the wild_match check to searching "__" only. */
4028 wild_match
= (strstr (text0
, "__") == NULL
4029 && strchr (text0
, '.') == NULL
);
4030 encoded
= (strstr (text0
, "__") != NULL
);
4033 /* First, look at the partial symtab symbols. */
4034 ALL_PSYMTABS (objfile
, ps
)
4036 struct partial_symbol
**psym
;
4038 /* If the psymtab's been read in we'll get it when we search
4039 through the blockvector. */
4043 for (psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
4044 psym
< (objfile
->global_psymbols
.list
+ ps
->globals_offset
4045 + ps
->n_global_syms
);
4049 symbol_completion_add (&result
, SYMBOL_LINKAGE_NAME (*psym
),
4050 text
, text_len
, text0
, word
,
4051 wild_match
, encoded
);
4054 for (psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
4055 psym
< (objfile
->static_psymbols
.list
+ ps
->statics_offset
4056 + ps
->n_static_syms
);
4060 symbol_completion_add (&result
, SYMBOL_LINKAGE_NAME (*psym
),
4061 text
, text_len
, text0
, word
,
4062 wild_match
, encoded
);
4066 /* At this point scan through the misc symbol vectors and add each
4067 symbol you find to the list. Eventually we want to ignore
4068 anything that isn't a text symbol (everything else will be
4069 handled by the psymtab code above). */
4071 ALL_MSYMBOLS (objfile
, msymbol
)
4074 symbol_completion_add (&result
, SYMBOL_LINKAGE_NAME (msymbol
),
4075 text
, text_len
, text0
, word
,
4076 wild_match
, encoded
);
4079 /* Search upwards from currently selected frame (so that we can
4080 complete on local vars. */
4082 for (b
= get_selected_block (0); b
!= NULL
; b
= BLOCK_SUPERBLOCK (b
))
4084 if (!BLOCK_SUPERBLOCK (b
))
4085 surrounding_static_block
= b
; /* For elmin of dups */
4087 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
4089 symbol_completion_add (&result
, SYMBOL_LINKAGE_NAME (sym
),
4090 text
, text_len
, text0
, word
,
4091 wild_match
, encoded
);
4095 /* Go through the symtabs and check the externs and statics for
4096 symbols which match. */
4098 ALL_SYMTABS (objfile
, s
)
4101 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
);
4102 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
4104 symbol_completion_add (&result
, SYMBOL_LINKAGE_NAME (sym
),
4105 text
, text_len
, text0
, word
,
4106 wild_match
, encoded
);
4110 ALL_SYMTABS (objfile
, s
)
4113 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
);
4114 /* Don't do this block twice. */
4115 if (b
== surrounding_static_block
)
4117 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
4119 symbol_completion_add (&result
, SYMBOL_LINKAGE_NAME (sym
),
4120 text
, text_len
, text0
, word
,
4121 wild_match
, encoded
);
4125 /* Append the closing NULL entry. */
4126 string_vector_append (&result
, NULL
);
4128 return (result
.array
);
4131 /* Look, in partial_symtab PST, for symbol NAME in given namespace.
4132 Check the global symbols if GLOBAL, the static symbols if not.
4133 Do wild-card match if WILD. */
4135 static struct partial_symbol
*
4136 ada_lookup_partial_symbol (struct partial_symtab
*pst
, const char *name
,
4137 int global
, domain_enum
namespace, int wild
)
4139 struct partial_symbol
**start
;
4140 int name_len
= strlen (name
);
4141 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
4150 pst
->objfile
->global_psymbols
.list
+ pst
->globals_offset
:
4151 pst
->objfile
->static_psymbols
.list
+ pst
->statics_offset
);
4155 for (i
= 0; i
< length
; i
+= 1)
4157 struct partial_symbol
*psym
= start
[i
];
4159 if (SYMBOL_DOMAIN (psym
) == namespace &&
4160 wild_match (name
, name_len
, SYMBOL_LINKAGE_NAME (psym
)))
4174 int M
= (U
+ i
) >> 1;
4175 struct partial_symbol
*psym
= start
[M
];
4176 if (SYMBOL_LINKAGE_NAME (psym
)[0] < name
[0])
4178 else if (SYMBOL_LINKAGE_NAME (psym
)[0] > name
[0])
4180 else if (strcmp (SYMBOL_LINKAGE_NAME (psym
), name
) < 0)
4191 struct partial_symbol
*psym
= start
[i
];
4193 if (SYMBOL_DOMAIN (psym
) == namespace)
4195 int cmp
= strncmp (name
, SYMBOL_LINKAGE_NAME (psym
), name_len
);
4203 && is_name_suffix (SYMBOL_LINKAGE_NAME (psym
)
4217 int M
= (U
+ i
) >> 1;
4218 struct partial_symbol
*psym
= start
[M
];
4219 if (SYMBOL_LINKAGE_NAME (psym
)[0] < '_')
4221 else if (SYMBOL_LINKAGE_NAME (psym
)[0] > '_')
4223 else if (strcmp (SYMBOL_LINKAGE_NAME (psym
), "_ada_") < 0)
4234 struct partial_symbol
*psym
= start
[i
];
4236 if (SYMBOL_DOMAIN (psym
) == namespace)
4240 cmp
= (int) '_' - (int) SYMBOL_LINKAGE_NAME (psym
)[0];
4243 cmp
= strncmp ("_ada_", SYMBOL_LINKAGE_NAME (psym
), 5);
4245 cmp
= strncmp (name
, SYMBOL_LINKAGE_NAME (psym
) + 5,
4255 && is_name_suffix (SYMBOL_LINKAGE_NAME (psym
)
4265 /* Find a symbol table containing symbol SYM or NULL if none. */
4267 static struct symtab
*
4268 symtab_for_sym (struct symbol
*sym
)
4271 struct objfile
*objfile
;
4273 struct symbol
*tmp_sym
;
4274 struct dict_iterator iter
;
4277 ALL_SYMTABS (objfile
, s
)
4279 switch (SYMBOL_CLASS (sym
))
4287 case LOC_CONST_BYTES
:
4288 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
);
4289 ALL_BLOCK_SYMBOLS (b
, iter
, tmp_sym
) if (sym
== tmp_sym
)
4291 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
);
4292 ALL_BLOCK_SYMBOLS (b
, iter
, tmp_sym
) if (sym
== tmp_sym
)
4298 switch (SYMBOL_CLASS (sym
))
4304 case LOC_REGPARM_ADDR
:
4309 case LOC_BASEREG_ARG
:
4311 case LOC_COMPUTED_ARG
:
4312 for (j
= FIRST_LOCAL_BLOCK
;
4313 j
< BLOCKVECTOR_NBLOCKS (BLOCKVECTOR (s
)); j
+= 1)
4315 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), j
);
4316 ALL_BLOCK_SYMBOLS (b
, iter
, tmp_sym
) if (sym
== tmp_sym
)
4327 /* Return a minimal symbol matching NAME according to Ada decoding
4328 rules. Returns NULL if there is no such minimal symbol. Names
4329 prefixed with "standard__" are handled specially: "standard__" is
4330 first stripped off, and only static and global symbols are searched. */
4332 struct minimal_symbol
*
4333 ada_lookup_simple_minsym (const char *name
)
4335 struct objfile
*objfile
;
4336 struct minimal_symbol
*msymbol
;
4339 if (strncmp (name
, "standard__", sizeof ("standard__") - 1) == 0)
4341 name
+= sizeof ("standard__") - 1;
4345 wild_match
= (strstr (name
, "__") == NULL
);
4347 ALL_MSYMBOLS (objfile
, msymbol
)
4349 if (ada_match_name (SYMBOL_LINKAGE_NAME (msymbol
), name
, wild_match
)
4350 && MSYMBOL_TYPE (msymbol
) != mst_solib_trampoline
)
4357 /* Return up minimal symbol for NAME, folded and encoded according to
4358 Ada conventions, or NULL if none. The last two arguments are ignored. */
4360 static struct minimal_symbol
*
4361 ada_lookup_minimal_symbol (const char *name
, const char *sfile
,
4362 struct objfile
*objf
)
4364 return ada_lookup_simple_minsym (ada_encode (name
));
4367 /* For all subprograms that statically enclose the subprogram of the
4368 selected frame, add symbols matching identifier NAME in DOMAIN
4369 and their blocks to the list of data in OBSTACKP, as for
4370 ada_add_block_symbols (q.v.). If WILD, treat as NAME with a
4374 add_symbols_from_enclosing_procs (struct obstack
*obstackp
,
4375 const char *name
, domain_enum
namespace,
4378 #ifdef HAVE_ADD_SYMBOLS_FROM_ENCLOSING_PROCS
4379 /* Use a heuristic to find the frames of enclosing subprograms: treat the
4380 pointer-sized value at location 0 from the local-variable base of a
4381 frame as a static link, and then search up the call stack for a
4382 frame with that same local-variable base. */
4383 static struct symbol static_link_sym
;
4384 static struct symbol
*static_link
;
4385 struct value
*target_link_val
;
4387 struct cleanup
*old_chain
= make_cleanup (null_cleanup
, NULL
);
4388 struct frame_info
*frame
;
4390 if (! target_has_stack
)
4393 if (static_link
== NULL
)
4395 /* Initialize the local variable symbol that stands for the
4396 static link (when there is one). */
4397 static_link
= &static_link_sym
;
4398 SYMBOL_LINKAGE_NAME (static_link
) = "";
4399 SYMBOL_LANGUAGE (static_link
) = language_unknown
;
4400 SYMBOL_CLASS (static_link
) = LOC_LOCAL
;
4401 SYMBOL_DOMAIN (static_link
) = VAR_DOMAIN
;
4402 SYMBOL_TYPE (static_link
) = lookup_pointer_type (builtin_type_void
);
4403 SYMBOL_VALUE (static_link
) =
4404 -(long) TYPE_LENGTH (SYMBOL_TYPE (static_link
));
4407 frame
= get_selected_frame ();
4409 || inside_main_func (get_frame_address_in_block (frame
)))
4412 target_link_val
= read_var_value (static_link
, frame
);
4413 while (target_link_val
!= NULL
4414 && num_defns_collected (obstackp
) == 0
4415 && frame_relative_level (frame
) <= MAX_ENCLOSING_FRAME_LEVELS
)
4417 CORE_ADDR target_link
= value_as_address (target_link_val
);
4419 frame
= get_prev_frame (frame
);
4423 if (get_frame_locals_address (frame
) == target_link
)
4425 struct block
*block
;
4429 block
= get_frame_block (frame
, 0);
4430 while (block
!= NULL
&& block_function (block
) != NULL
4431 && num_defns_collected (obstackp
) == 0)
4435 ada_add_block_symbols (obstackp
, block
, name
, namespace,
4436 NULL
, NULL
, wild_match
);
4438 block
= BLOCK_SUPERBLOCK (block
);
4443 do_cleanups (old_chain
);
4447 /* FIXME: The next two routines belong in symtab.c */
4449 static void restore_language (void* lang
)
4451 set_language ((enum language
) lang
);
4454 /* As for lookup_symbol, but performed as if the current language
4458 lookup_symbol_in_language (const char *name
, const struct block
*block
,
4459 domain_enum domain
, enum language lang
,
4460 int *is_a_field_of_this
, struct symtab
**symtab
)
4462 struct cleanup
*old_chain
4463 = make_cleanup (restore_language
, (void*) current_language
->la_language
);
4464 struct symbol
*result
;
4465 set_language (lang
);
4466 result
= lookup_symbol (name
, block
, domain
, is_a_field_of_this
, symtab
);
4467 do_cleanups (old_chain
);
4471 /* True if TYPE is definitely an artificial type supplied to a symbol
4472 for which no debugging information was given in the symbol file. */
4475 is_nondebugging_type (struct type
*type
)
4477 char *name
= ada_type_name (type
);
4478 return (name
!= NULL
&& strcmp (name
, "<variable, no debug info>") == 0);
4481 /* Remove any non-debugging symbols in SYMS[0 .. NSYMS-1] that definitely
4482 duplicate other symbols in the list (The only case I know of where
4483 this happens is when object files containing stabs-in-ecoff are
4484 linked with files containing ordinary ecoff debugging symbols (or no
4485 debugging symbols)). Modifies SYMS to squeeze out deleted entries.
4486 Returns the number of items in the modified list. */
4489 remove_extra_symbols (struct ada_symbol_info
*syms
, int nsyms
)
4496 if (SYMBOL_LINKAGE_NAME (syms
[i
].sym
) != NULL
4497 && SYMBOL_CLASS (syms
[i
].sym
) == LOC_STATIC
4498 && is_nondebugging_type (SYMBOL_TYPE (syms
[i
].sym
)))
4500 for (j
= 0; j
< nsyms
; j
+= 1)
4503 && SYMBOL_LINKAGE_NAME (syms
[j
].sym
) != NULL
4504 && strcmp (SYMBOL_LINKAGE_NAME (syms
[i
].sym
),
4505 SYMBOL_LINKAGE_NAME (syms
[j
].sym
)) == 0
4506 && SYMBOL_CLASS (syms
[i
].sym
) == SYMBOL_CLASS (syms
[j
].sym
)
4507 && SYMBOL_VALUE_ADDRESS (syms
[i
].sym
)
4508 == SYMBOL_VALUE_ADDRESS (syms
[j
].sym
))
4511 for (k
= i
+ 1; k
< nsyms
; k
+= 1)
4512 syms
[k
- 1] = syms
[k
];
4525 /* Given a type that corresponds to a renaming entity, use the type name
4526 to extract the scope (package name or function name, fully qualified,
4527 and following the GNAT encoding convention) where this renaming has been
4528 defined. The string returned needs to be deallocated after use. */
4531 xget_renaming_scope (struct type
*renaming_type
)
4533 /* The renaming types adhere to the following convention:
4534 <scope>__<rename>___<XR extension>.
4535 So, to extract the scope, we search for the "___XR" extension,
4536 and then backtrack until we find the first "__". */
4538 const char *name
= type_name_no_tag (renaming_type
);
4539 char *suffix
= strstr (name
, "___XR");
4544 /* Now, backtrack a bit until we find the first "__". Start looking
4545 at suffix - 3, as the <rename> part is at least one character long. */
4547 for (last
= suffix
- 3; last
> name
; last
--)
4548 if (last
[0] == '_' && last
[1] == '_')
4551 /* Make a copy of scope and return it. */
4553 scope_len
= last
- name
;
4554 scope
= (char *) xmalloc ((scope_len
+ 1) * sizeof (char));
4556 strncpy (scope
, name
, scope_len
);
4557 scope
[scope_len
] = '\0';
4562 /* Return nonzero if NAME corresponds to a package name. */
4565 is_package_name (const char *name
)
4567 /* Here, We take advantage of the fact that no symbols are generated
4568 for packages, while symbols are generated for each function.
4569 So the condition for NAME represent a package becomes equivalent
4570 to NAME not existing in our list of symbols. There is only one
4571 small complication with library-level functions (see below). */
4575 /* If it is a function that has not been defined at library level,
4576 then we should be able to look it up in the symbols. */
4577 if (standard_lookup (name
, NULL
, VAR_DOMAIN
) != NULL
)
4580 /* Library-level function names start with "_ada_". See if function
4581 "_ada_" followed by NAME can be found. */
4583 /* Do a quick check that NAME does not contain "__", since library-level
4584 functions names can not contain "__" in them. */
4585 if (strstr (name
, "__") != NULL
)
4588 fun_name
= (char *) alloca (strlen (name
) + 5 + 1);
4589 xasprintf (&fun_name
, "_ada_%s", name
);
4591 return (standard_lookup (fun_name
, NULL
, VAR_DOMAIN
) == NULL
);
4594 /* Return nonzero if SYM corresponds to a renaming entity that is
4595 visible from FUNCTION_NAME. */
4598 renaming_is_visible (const struct symbol
*sym
, char *function_name
)
4600 char *scope
= xget_renaming_scope (SYMBOL_TYPE (sym
));
4602 make_cleanup (xfree
, scope
);
4604 /* If the rename has been defined in a package, then it is visible. */
4605 if (is_package_name (scope
))
4608 /* Check that the rename is in the current function scope by checking
4609 that its name starts with SCOPE. */
4611 /* If the function name starts with "_ada_", it means that it is
4612 a library-level function. Strip this prefix before doing the
4613 comparison, as the encoding for the renaming does not contain
4615 if (strncmp (function_name
, "_ada_", 5) == 0)
4618 return (strncmp (function_name
, scope
, strlen (scope
)) == 0);
4621 /* Iterates over the SYMS list and remove any entry that corresponds to
4622 a renaming entity that is not visible from the function associated
4626 GNAT emits a type following a specified encoding for each renaming
4627 entity. Unfortunately, STABS currently does not support the definition
4628 of types that are local to a given lexical block, so all renamings types
4629 are emitted at library level. As a consequence, if an application
4630 contains two renaming entities using the same name, and a user tries to
4631 print the value of one of these entities, the result of the ada symbol
4632 lookup will also contain the wrong renaming type.
4634 This function partially covers for this limitation by attempting to
4635 remove from the SYMS list renaming symbols that should be visible
4636 from CURRENT_BLOCK. However, there does not seem be a 100% reliable
4637 method with the current information available. The implementation
4638 below has a couple of limitations (FIXME: brobecker-2003-05-12):
4640 - When the user tries to print a rename in a function while there
4641 is another rename entity defined in a package: Normally, the
4642 rename in the function has precedence over the rename in the
4643 package, so the latter should be removed from the list. This is
4644 currently not the case.
4646 - This function will incorrectly remove valid renames if
4647 the CURRENT_BLOCK corresponds to a function which symbol name
4648 has been changed by an "Export" pragma. As a consequence,
4649 the user will be unable to print such rename entities. */
4652 remove_out_of_scope_renamings (struct ada_symbol_info
*syms
,
4654 struct block
*current_block
)
4656 struct symbol
*current_function
;
4657 char *current_function_name
;
4660 /* Extract the function name associated to CURRENT_BLOCK.
4661 Abort if unable to do so. */
4663 if (current_block
== NULL
)
4666 current_function
= block_function (current_block
);
4667 if (current_function
== NULL
)
4670 current_function_name
= SYMBOL_LINKAGE_NAME (current_function
);
4671 if (current_function_name
== NULL
)
4674 /* Check each of the symbols, and remove it from the list if it is
4675 a type corresponding to a renaming that is out of the scope of
4676 the current block. */
4681 if (ada_is_object_renaming (syms
[i
].sym
)
4682 && !renaming_is_visible (syms
[i
].sym
, current_function_name
))
4685 for (j
= i
+ 1; j
< nsyms
; j
++)
4686 syms
[j
- 1] = syms
[j
];
4696 /* Find symbols in DOMAIN matching NAME0, in BLOCK0 and enclosing
4697 scope and in global scopes, returning the number of matches. Sets
4698 *RESULTS to point to a vector of (SYM,BLOCK,SYMTAB) triples,
4699 indicating the symbols found and the blocks and symbol tables (if
4700 any) in which they were found. This vector are transient---good only to
4701 the next call of ada_lookup_symbol_list. Any non-function/non-enumeral
4702 symbol match within the nest of blocks whose innermost member is BLOCK0,
4703 is the one match returned (no other matches in that or
4704 enclosing blocks is returned). If there are any matches in or
4705 surrounding BLOCK0, then these alone are returned. Otherwise, the
4706 search extends to global and file-scope (static) symbol tables.
4707 Names prefixed with "standard__" are handled specially: "standard__"
4708 is first stripped off, and only static and global symbols are searched. */
4711 ada_lookup_symbol_list (const char *name0
, const struct block
*block0
,
4712 domain_enum
namespace,
4713 struct ada_symbol_info
**results
)
4717 struct partial_symtab
*ps
;
4718 struct blockvector
*bv
;
4719 struct objfile
*objfile
;
4720 struct block
*block
;
4722 struct minimal_symbol
*msymbol
;
4728 obstack_free (&symbol_list_obstack
, NULL
);
4729 obstack_init (&symbol_list_obstack
);
4733 /* Search specified block and its superiors. */
4735 wild_match
= (strstr (name0
, "__") == NULL
);
4737 block
= (struct block
*) block0
; /* FIXME: No cast ought to be
4738 needed, but adding const will
4739 have a cascade effect. */
4740 if (strncmp (name0
, "standard__", sizeof ("standard__") - 1) == 0)
4744 name
= name0
+ sizeof ("standard__") - 1;
4748 while (block
!= NULL
)
4751 ada_add_block_symbols (&symbol_list_obstack
, block
, name
,
4752 namespace, NULL
, NULL
, wild_match
);
4754 /* If we found a non-function match, assume that's the one. */
4755 if (is_nonfunction (defns_collected (&symbol_list_obstack
, 0),
4756 num_defns_collected (&symbol_list_obstack
)))
4759 block
= BLOCK_SUPERBLOCK (block
);
4762 /* If no luck so far, try to find NAME as a local symbol in some lexically
4763 enclosing subprogram. */
4764 if (num_defns_collected (&symbol_list_obstack
) == 0 && block_depth
> 2)
4765 add_symbols_from_enclosing_procs (&symbol_list_obstack
,
4766 name
, namespace, wild_match
);
4768 /* If we found ANY matches among non-global symbols, we're done. */
4770 if (num_defns_collected (&symbol_list_obstack
) > 0)
4774 if (lookup_cached_symbol (name0
, namespace, &sym
, &block
, &s
))
4777 add_defn_to_vec (&symbol_list_obstack
, sym
, block
, s
);
4781 /* Now add symbols from all global blocks: symbol tables, minimal symbol
4782 tables, and psymtab's. */
4784 ALL_SYMTABS (objfile
, s
)
4789 bv
= BLOCKVECTOR (s
);
4790 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
4791 ada_add_block_symbols (&symbol_list_obstack
, block
, name
, namespace,
4792 objfile
, s
, wild_match
);
4795 if (namespace == VAR_DOMAIN
)
4797 ALL_MSYMBOLS (objfile
, msymbol
)
4799 if (ada_match_name (SYMBOL_LINKAGE_NAME (msymbol
), name
, wild_match
))
4801 switch (MSYMBOL_TYPE (msymbol
))
4803 case mst_solib_trampoline
:
4806 s
= find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol
));
4809 int ndefns0
= num_defns_collected (&symbol_list_obstack
);
4811 bv
= BLOCKVECTOR (s
);
4812 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
4813 ada_add_block_symbols (&symbol_list_obstack
, block
,
4814 SYMBOL_LINKAGE_NAME (msymbol
),
4815 namespace, objfile
, s
, wild_match
);
4817 if (num_defns_collected (&symbol_list_obstack
) == ndefns0
)
4819 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
4820 ada_add_block_symbols (&symbol_list_obstack
, block
,
4821 SYMBOL_LINKAGE_NAME (msymbol
),
4822 namespace, objfile
, s
,
4831 ALL_PSYMTABS (objfile
, ps
)
4835 && ada_lookup_partial_symbol (ps
, name
, 1, namespace, wild_match
))
4837 s
= PSYMTAB_TO_SYMTAB (ps
);
4840 bv
= BLOCKVECTOR (s
);
4841 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
4842 ada_add_block_symbols (&symbol_list_obstack
, block
, name
,
4843 namespace, objfile
, s
, wild_match
);
4847 /* Now add symbols from all per-file blocks if we've gotten no hits
4848 (Not strictly correct, but perhaps better than an error).
4849 Do the symtabs first, then check the psymtabs. */
4851 if (num_defns_collected (&symbol_list_obstack
) == 0)
4854 ALL_SYMTABS (objfile
, s
)
4859 bv
= BLOCKVECTOR (s
);
4860 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
4861 ada_add_block_symbols (&symbol_list_obstack
, block
, name
, namespace,
4862 objfile
, s
, wild_match
);
4865 ALL_PSYMTABS (objfile
, ps
)
4869 && ada_lookup_partial_symbol (ps
, name
, 0, namespace, wild_match
))
4871 s
= PSYMTAB_TO_SYMTAB (ps
);
4872 bv
= BLOCKVECTOR (s
);
4875 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
4876 ada_add_block_symbols (&symbol_list_obstack
, block
, name
,
4877 namespace, objfile
, s
, wild_match
);
4883 ndefns
= num_defns_collected (&symbol_list_obstack
);
4884 *results
= defns_collected (&symbol_list_obstack
, 1);
4886 ndefns
= remove_extra_symbols (*results
, ndefns
);
4889 cache_symbol (name0
, namespace, NULL
, NULL
, NULL
);
4891 if (ndefns
== 1 && cacheIfUnique
)
4892 cache_symbol (name0
, namespace, (*results
)[0].sym
, (*results
)[0].block
,
4893 (*results
)[0].symtab
);
4895 ndefns
= remove_out_of_scope_renamings (*results
, ndefns
,
4896 (struct block
*) block0
);
4901 /* Return a symbol in DOMAIN matching NAME, in BLOCK0 and enclosing
4902 scope and in global scopes, or NULL if none. NAME is folded and
4903 encoded first. Otherwise, the result is as for ada_lookup_symbol_list,
4904 but is disambiguated by user query if needed. *IS_A_FIELD_OF_THIS is
4905 set to 0 and *SYMTAB is set to the symbol table in which the symbol
4906 was found (in both cases, these assignments occur only if the
4907 pointers are non-null). */
4911 ada_lookup_symbol (const char *name
, const struct block
*block0
,
4912 domain_enum
namespace, int *is_a_field_of_this
,
4913 struct symtab
**symtab
)
4915 struct ada_symbol_info
*candidates
;
4918 n_candidates
= ada_lookup_symbol_list (ada_encode (ada_fold_name (name
)),
4919 block0
, namespace, &candidates
);
4921 if (n_candidates
== 0)
4923 else if (n_candidates
!= 1)
4924 user_select_syms (candidates
, n_candidates
, 1);
4926 if (is_a_field_of_this
!= NULL
)
4927 *is_a_field_of_this
= 0;
4931 *symtab
= candidates
[0].symtab
;
4932 if (*symtab
== NULL
&& candidates
[0].block
!= NULL
)
4934 struct objfile
*objfile
;
4937 struct blockvector
*bv
;
4939 /* Search the list of symtabs for one which contains the
4940 address of the start of this block. */
4941 ALL_SYMTABS (objfile
, s
)
4943 bv
= BLOCKVECTOR (s
);
4944 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
4945 if (BLOCK_START (b
) <= BLOCK_START (candidates
[0].block
)
4946 && BLOCK_END (b
) > BLOCK_START (candidates
[0].block
))
4949 return fixup_symbol_section (candidates
[0].sym
, objfile
);
4951 return fixup_symbol_section (candidates
[0].sym
, NULL
);
4955 return candidates
[0].sym
;
4958 static struct symbol
*
4959 ada_lookup_symbol_nonlocal (const char *name
,
4960 const char *linkage_name
,
4961 const struct block
*block
,
4962 const domain_enum domain
,
4963 struct symtab
**symtab
)
4965 if (linkage_name
== NULL
)
4966 linkage_name
= name
;
4967 return ada_lookup_symbol (linkage_name
, block_static_block (block
), domain
,
4972 /* True iff STR is a possible encoded suffix of a normal Ada name
4973 that is to be ignored for matching purposes. Suffixes of parallel
4974 names (e.g., XVE) are not included here. Currently, the possible suffixes
4975 are given by either of the regular expression:
4977 (__[0-9]+)?\.[0-9]+ [nested subprogram suffix, on platforms such as Linux]
4978 ___[0-9]+ [nested subprogram suffix, on platforms such as HP/UX]
4979 (X[nb]*)?((\$|__)[0-9](_?[0-9]+)|___(LJM|X([FDBUP].*|R[^T]?)))?$
4983 is_name_suffix (const char *str
)
4986 const char *matching
;
4987 const int len
= strlen (str
);
4989 /* (__[0-9]+)?\.[0-9]+ */
4991 if (len
> 3 && str
[0] == '_' && str
[1] == '_' && isdigit (str
[2]))
4994 while (isdigit (matching
[0]))
4996 if (matching
[0] == '\0')
5000 if (matching
[0] == '.')
5003 while (isdigit (matching
[0]))
5005 if (matching
[0] == '\0')
5010 if (len
> 3 && str
[0] == '_' && str
[1] == '_' && str
[2] == '_')
5013 while (isdigit (matching
[0]))
5015 if (matching
[0] == '\0')
5019 /* ??? We should not modify STR directly, as we are doing below. This
5020 is fine in this case, but may become problematic later if we find
5021 that this alternative did not work, and want to try matching
5022 another one from the begining of STR. Since we modified it, we
5023 won't be able to find the begining of the string anymore! */
5027 while (str
[0] != '_' && str
[0] != '\0')
5029 if (str
[0] != 'n' && str
[0] != 'b')
5034 if (str
[0] == '\000')
5038 if (str
[1] != '_' || str
[2] == '\000')
5042 if (strcmp (str
+ 3, "LJM") == 0)
5046 if (str
[4] == 'F' || str
[4] == 'D' || str
[4] == 'B' ||
5047 str
[4] == 'U' || str
[4] == 'P')
5049 if (str
[4] == 'R' && str
[5] != 'T')
5053 if (!isdigit (str
[2]))
5055 for (k
= 3; str
[k
] != '\0'; k
+= 1)
5056 if (!isdigit (str
[k
]) && str
[k
] != '_')
5060 if (str
[0] == '$' && isdigit (str
[1]))
5062 for (k
= 2; str
[k
] != '\0'; k
+= 1)
5063 if (!isdigit (str
[k
]) && str
[k
] != '_')
5070 /* Return nonzero if the given string starts with a dot ('.')
5071 followed by zero or more digits.
5073 Note: brobecker/2003-11-10: A forward declaration has not been
5074 added at the begining of this file yet, because this function
5075 is only used to work around a problem found during wild matching
5076 when trying to match minimal symbol names against symbol names
5077 obtained from dwarf-2 data. This function is therefore currently
5078 only used in wild_match() and is likely to be deleted when the
5079 problem in dwarf-2 is fixed. */
5082 is_dot_digits_suffix (const char *str
)
5088 while (isdigit (str
[0]))
5090 return (str
[0] == '\0');
5093 /* True if NAME represents a name of the form A1.A2....An, n>=1 and
5094 PATN[0..PATN_LEN-1] = Ak.Ak+1.....An for some k >= 1. Ignores
5095 informational suffixes of NAME (i.e., for which is_name_suffix is
5099 wild_match (const char *patn0
, int patn_len
, const char *name0
)
5105 /* FIXME: brobecker/2003-11-10: For some reason, the symbol name
5106 stored in the symbol table for nested function names is sometimes
5107 different from the name of the associated entity stored in
5108 the dwarf-2 data: This is the case for nested subprograms, where
5109 the minimal symbol name contains a trailing ".[:digit:]+" suffix,
5110 while the symbol name from the dwarf-2 data does not.
5112 Although the DWARF-2 standard documents that entity names stored
5113 in the dwarf-2 data should be identical to the name as seen in
5114 the source code, GNAT takes a different approach as we already use
5115 a special encoding mechanism to convey the information so that
5116 a C debugger can still use the information generated to debug
5117 Ada programs. A corollary is that the symbol names in the dwarf-2
5118 data should match the names found in the symbol table. I therefore
5119 consider this issue as a compiler defect.
5121 Until the compiler is properly fixed, we work-around the problem
5122 by ignoring such suffixes during the match. We do so by making
5123 a copy of PATN0 and NAME0, and then by stripping such a suffix
5124 if present. We then perform the match on the resulting strings. */
5127 name_len
= strlen (name0
);
5129 name
= (char *) alloca ((name_len
+ 1) * sizeof (char));
5130 strcpy (name
, name0
);
5131 dot
= strrchr (name
, '.');
5132 if (dot
!= NULL
&& is_dot_digits_suffix (dot
))
5135 patn
= (char *) alloca ((patn_len
+ 1) * sizeof (char));
5136 strncpy (patn
, patn0
, patn_len
);
5137 patn
[patn_len
] = '\0';
5138 dot
= strrchr (patn
, '.');
5139 if (dot
!= NULL
&& is_dot_digits_suffix (dot
))
5142 patn_len
= dot
- patn
;
5146 /* Now perform the wild match. */
5148 name_len
= strlen (name
);
5149 if (name_len
>= patn_len
+ 5 && strncmp (name
, "_ada_", 5) == 0
5150 && strncmp (patn
, name
+ 5, patn_len
) == 0
5151 && is_name_suffix (name
+ patn_len
+ 5))
5154 while (name_len
>= patn_len
)
5156 if (strncmp (patn
, name
, patn_len
) == 0
5157 && is_name_suffix (name
+ patn_len
))
5165 && name
[0] != '.' && (name
[0] != '_' || name
[1] != '_'));
5170 if (!islower (name
[2]))
5177 if (!islower (name
[1]))
5188 /* Add symbols from BLOCK matching identifier NAME in DOMAIN to
5189 vector *defn_symbols, updating the list of symbols in OBSTACKP
5190 (if necessary). If WILD, treat as NAME with a wildcard prefix.
5191 OBJFILE is the section containing BLOCK.
5192 SYMTAB is recorded with each symbol added. */
5195 ada_add_block_symbols (struct obstack
*obstackp
,
5196 struct block
*block
, const char *name
,
5197 domain_enum domain
, struct objfile
*objfile
,
5198 struct symtab
*symtab
, int wild
)
5200 struct dict_iterator iter
;
5201 int name_len
= strlen (name
);
5202 /* A matching argument symbol, if any. */
5203 struct symbol
*arg_sym
;
5204 /* Set true when we find a matching non-argument symbol. */
5213 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
5215 if (SYMBOL_DOMAIN (sym
) == domain
&&
5216 wild_match (name
, name_len
, SYMBOL_LINKAGE_NAME (sym
)))
5218 switch (SYMBOL_CLASS (sym
))
5224 case LOC_REGPARM_ADDR
:
5225 case LOC_BASEREG_ARG
:
5226 case LOC_COMPUTED_ARG
:
5229 case LOC_UNRESOLVED
:
5233 add_defn_to_vec (obstackp
,
5234 fixup_symbol_section (sym
, objfile
),
5243 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
5245 if (SYMBOL_DOMAIN (sym
) == domain
)
5247 int cmp
= strncmp (name
, SYMBOL_LINKAGE_NAME (sym
), name_len
);
5249 && is_name_suffix (SYMBOL_LINKAGE_NAME (sym
) + name_len
))
5251 switch (SYMBOL_CLASS (sym
))
5257 case LOC_REGPARM_ADDR
:
5258 case LOC_BASEREG_ARG
:
5259 case LOC_COMPUTED_ARG
:
5262 case LOC_UNRESOLVED
:
5266 add_defn_to_vec (obstackp
,
5267 fixup_symbol_section (sym
, objfile
),
5276 if (!found_sym
&& arg_sym
!= NULL
)
5278 add_defn_to_vec (obstackp
,
5279 fixup_symbol_section (arg_sym
, objfile
),
5288 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
5290 if (SYMBOL_DOMAIN (sym
) == domain
)
5294 cmp
= (int) '_' - (int) SYMBOL_LINKAGE_NAME (sym
)[0];
5297 cmp
= strncmp ("_ada_", SYMBOL_LINKAGE_NAME (sym
), 5);
5299 cmp
= strncmp (name
, SYMBOL_LINKAGE_NAME (sym
) + 5,
5304 && is_name_suffix (SYMBOL_LINKAGE_NAME (sym
) + name_len
+ 5))
5306 switch (SYMBOL_CLASS (sym
))
5312 case LOC_REGPARM_ADDR
:
5313 case LOC_BASEREG_ARG
:
5314 case LOC_COMPUTED_ARG
:
5317 case LOC_UNRESOLVED
:
5321 add_defn_to_vec (obstackp
,
5322 fixup_symbol_section (sym
, objfile
),
5331 /* NOTE: This really shouldn't be needed for _ada_ symbols.
5332 They aren't parameters, right? */
5333 if (!found_sym
&& arg_sym
!= NULL
)
5335 add_defn_to_vec (obstackp
,
5336 fixup_symbol_section (arg_sym
, objfile
),
5342 /* Breakpoint-related */
5344 /* Import message from symtab.c. */
5345 extern char no_symtab_msg
[];
5347 /* Assuming that LINE is pointing at the beginning of an argument to
5348 'break', return a pointer to the delimiter for the initial segment
5349 of that name. This is the first ':', ' ', or end of LINE. */
5352 ada_start_decode_line_1 (char *line
)
5354 /* NOTE: strpbrk would be more elegant, but I am reluctant to be
5355 the first to use such a library function in GDB code. */
5357 for (p
= line
; *p
!= '\000' && *p
!= ' ' && *p
!= ':'; p
+= 1)
5362 /* *SPEC points to a function and line number spec (as in a break
5363 command), following any initial file name specification.
5365 Return all symbol table/line specfications (sals) consistent with the
5366 information in *SPEC and FILE_TABLE in the following sense:
5367 + FILE_TABLE is null, or the sal refers to a line in the file
5368 named by FILE_TABLE.
5369 + If *SPEC points to an argument with a trailing ':LINENUM',
5370 then the sal refers to that line (or one following it as closely as
5372 + If *SPEC does not start with '*', the sal is in a function with
5375 Returns with 0 elements if no matching non-minimal symbols found.
5377 If *SPEC begins with a function name of the form <NAME>, then NAME
5378 is taken as a literal name; otherwise the function name is subject
5379 to the usual encoding.
5381 *SPEC is updated to point after the function/line number specification.
5383 FUNFIRSTLINE is non-zero if we desire the first line of real code
5386 If CANONICAL is non-NULL, and if any of the sals require a
5387 'canonical line spec', then *CANONICAL is set to point to an array
5388 of strings, corresponding to and equal in length to the returned
5389 list of sals, such that (*CANONICAL)[i] is non-null and contains a
5390 canonical line spec for the ith returned sal, if needed. If no
5391 canonical line specs are required and CANONICAL is non-null,
5392 *CANONICAL is set to NULL.
5394 A 'canonical line spec' is simply a name (in the format of the
5395 breakpoint command) that uniquely identifies a breakpoint position,
5396 with no further contextual information or user selection. It is
5397 needed whenever the file name, function name, and line number
5398 information supplied is insufficient for this unique
5399 identification. Currently overloaded functions, the name '*',
5400 or static functions without a filename yield a canonical line spec.
5401 The array and the line spec strings are allocated on the heap; it
5402 is the caller's responsibility to free them. */
5404 struct symtabs_and_lines
5405 ada_finish_decode_line_1 (char **spec
, struct symtab
*file_table
,
5406 int funfirstline
, char ***canonical
)
5408 struct ada_symbol_info
*symbols
;
5409 const struct block
*block
;
5410 int n_matches
, i
, line_num
;
5411 struct symtabs_and_lines selected
;
5412 struct cleanup
*old_chain
= make_cleanup (null_cleanup
, NULL
);
5418 char *unquoted_name
;
5420 if (file_table
== NULL
)
5421 block
= block_static_block (get_selected_block (0));
5423 block
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (file_table
), STATIC_BLOCK
);
5425 if (canonical
!= NULL
)
5426 *canonical
= (char **) NULL
;
5428 is_quoted
= (**spec
&& strchr (get_gdb_completer_quote_characters (),
5437 *spec
= skip_quoted (*spec
);
5438 while (**spec
!= '\000' &&
5439 !strchr (ada_completer_word_break_characters
, **spec
))
5445 if (file_table
!= NULL
&& (*spec
)[0] == ':' && isdigit ((*spec
)[1]))
5447 line_num
= strtol (*spec
+ 1, spec
, 10);
5448 while (**spec
== ' ' || **spec
== '\t')
5455 error ("Wild-card function with no line number or file name.");
5457 return ada_sals_for_line (file_table
->filename
, line_num
,
5458 funfirstline
, canonical
, 0);
5461 if (name
[0] == '\'')
5469 unquoted_name
= (char *) alloca (len
- 1);
5470 memcpy (unquoted_name
, name
+ 1, len
- 2);
5471 unquoted_name
[len
- 2] = '\000';
5476 unquoted_name
= (char *) alloca (len
+ 1);
5477 memcpy (unquoted_name
, name
, len
);
5478 unquoted_name
[len
] = '\000';
5479 lower_name
= (char *) alloca (len
+ 1);
5480 for (i
= 0; i
< len
; i
+= 1)
5481 lower_name
[i
] = tolower (name
[i
]);
5482 lower_name
[len
] = '\000';
5486 if (lower_name
!= NULL
)
5487 n_matches
= ada_lookup_symbol_list (ada_encode (lower_name
), block
,
5488 VAR_DOMAIN
, &symbols
);
5490 n_matches
= ada_lookup_symbol_list (unquoted_name
, block
,
5491 VAR_DOMAIN
, &symbols
);
5492 if (n_matches
== 0 && line_num
>= 0)
5493 error ("No line number information found for %s.", unquoted_name
);
5494 else if (n_matches
== 0)
5496 #ifdef HPPA_COMPILER_BUG
5497 /* FIXME: See comment in symtab.c::decode_line_1 */
5499 volatile struct symtab_and_line val
;
5500 #define volatile /*nothing */
5502 struct symtab_and_line val
;
5504 struct minimal_symbol
*msymbol
;
5509 if (lower_name
!= NULL
)
5510 msymbol
= ada_lookup_simple_minsym (ada_encode (lower_name
));
5511 if (msymbol
== NULL
)
5512 msymbol
= ada_lookup_simple_minsym (unquoted_name
);
5513 if (msymbol
!= NULL
)
5515 val
.pc
= SYMBOL_VALUE_ADDRESS (msymbol
);
5516 val
.section
= SYMBOL_BFD_SECTION (msymbol
);
5519 val
.pc
+= FUNCTION_START_OFFSET
;
5520 SKIP_PROLOGUE (val
.pc
);
5522 selected
.sals
= (struct symtab_and_line
*)
5523 xmalloc (sizeof (struct symtab_and_line
));
5524 selected
.sals
[0] = val
;
5529 if (!have_full_symbols () &&
5530 !have_partial_symbols () && !have_minimal_symbols ())
5531 error ("No symbol table is loaded. Use the \"file\" command.");
5533 error ("Function \"%s\" not defined.", unquoted_name
);
5534 return selected
; /* for lint */
5539 struct symtabs_and_lines best_sal
=
5540 find_sal_from_funcs_and_line (file_table
->filename
, line_num
,
5541 symbols
, n_matches
);
5543 adjust_pc_past_prologue (&best_sal
.sals
[0].pc
);
5549 user_select_syms (symbols
, n_matches
, n_matches
);
5552 selected
.sals
= (struct symtab_and_line
*)
5553 xmalloc (sizeof (struct symtab_and_line
) * selected
.nelts
);
5554 memset (selected
.sals
, 0, selected
.nelts
* sizeof (selected
.sals
[i
]));
5555 make_cleanup (xfree
, selected
.sals
);
5558 while (i
< selected
.nelts
)
5560 if (SYMBOL_CLASS (symbols
[i
].sym
) == LOC_BLOCK
)
5562 = find_function_start_sal (symbols
[i
].sym
, funfirstline
);
5563 else if (SYMBOL_LINE (symbols
[i
].sym
) != 0)
5565 selected
.sals
[i
].symtab
=
5567 ? symbols
[i
].symtab
: symtab_for_sym (symbols
[i
].sym
);
5568 selected
.sals
[i
].line
= SYMBOL_LINE (symbols
[i
].sym
);
5570 else if (line_num
>= 0)
5572 /* Ignore this choice */
5573 symbols
[i
] = symbols
[selected
.nelts
- 1];
5574 selected
.nelts
-= 1;
5578 error ("Line number not known for symbol \"%s\"", unquoted_name
);
5582 if (canonical
!= NULL
&& (line_num
>= 0 || n_matches
> 1))
5584 *canonical
= (char **) xmalloc (sizeof (char *) * selected
.nelts
);
5585 for (i
= 0; i
< selected
.nelts
; i
+= 1)
5587 extended_canonical_line_spec (selected
.sals
[i
],
5588 SYMBOL_PRINT_NAME (symbols
[i
].sym
));
5591 discard_cleanups (old_chain
);
5595 /* The (single) sal corresponding to line LINE_NUM in a symbol table
5596 with file name FILENAME that occurs in one of the functions listed
5597 in the symbol fields of SYMBOLS[0 .. NSYMS-1]. */
5599 static struct symtabs_and_lines
5600 find_sal_from_funcs_and_line (const char *filename
, int line_num
,
5601 struct ada_symbol_info
*symbols
, int nsyms
)
5603 struct symtabs_and_lines sals
;
5604 int best_index
, best
;
5605 struct linetable
*best_linetable
;
5606 struct objfile
*objfile
;
5608 struct symtab
*best_symtab
;
5610 read_all_symtabs (filename
);
5613 best_linetable
= NULL
;
5616 ALL_SYMTABS (objfile
, s
)
5618 struct linetable
*l
;
5623 if (strcmp (filename
, s
->filename
) != 0)
5626 ind
= find_line_in_linetable (l
, line_num
, symbols
, nsyms
, &exact
);
5636 if (best
== 0 || l
->item
[ind
].line
< best
)
5638 best
= l
->item
[ind
].line
;
5647 error ("Line number not found in designated function.");
5652 sals
.sals
= (struct symtab_and_line
*) xmalloc (sizeof (sals
.sals
[0]));
5654 init_sal (&sals
.sals
[0]);
5656 sals
.sals
[0].line
= best_linetable
->item
[best_index
].line
;
5657 sals
.sals
[0].pc
= best_linetable
->item
[best_index
].pc
;
5658 sals
.sals
[0].symtab
= best_symtab
;
5663 /* Return the index in LINETABLE of the best match for LINE_NUM whose
5664 pc falls within one of the functions denoted by the symbol fields
5665 of SYMBOLS[0..NSYMS-1]. Set *EXACTP to 1 if the match is exact,
5669 find_line_in_linetable (struct linetable
*linetable
, int line_num
,
5670 struct ada_symbol_info
*symbols
, int nsyms
, int *exactp
)
5672 int i
, len
, best_index
, best
;
5674 if (line_num
<= 0 || linetable
== NULL
)
5677 len
= linetable
->nitems
;
5678 for (i
= 0, best_index
= -1, best
= 0; i
< len
; i
+= 1)
5681 struct linetable_entry
*item
= &(linetable
->item
[i
]);
5683 for (k
= 0; k
< nsyms
; k
+= 1)
5685 if (symbols
[k
].sym
!= NULL
5686 && SYMBOL_CLASS (symbols
[k
].sym
) == LOC_BLOCK
5687 && item
->pc
>= BLOCK_START (SYMBOL_BLOCK_VALUE (symbols
[k
].sym
))
5688 && item
->pc
< BLOCK_END (SYMBOL_BLOCK_VALUE (symbols
[k
].sym
)))
5695 if (item
->line
== line_num
)
5701 if (item
->line
> line_num
&& (best
== 0 || item
->line
< best
))
5712 /* Find the smallest k >= LINE_NUM such that k is a line number in
5713 LINETABLE, and k falls strictly within a named function that begins at
5714 or before LINE_NUM. Return -1 if there is no such k. */
5717 nearest_line_number_in_linetable (struct linetable
*linetable
, int line_num
)
5721 if (line_num
<= 0 || linetable
== NULL
|| linetable
->nitems
== 0)
5723 len
= linetable
->nitems
;
5729 struct linetable_entry
*item
= &(linetable
->item
[i
]);
5731 if (item
->line
>= line_num
&& item
->line
< best
)
5734 CORE_ADDR start
, end
;
5737 find_pc_partial_function (item
->pc
, &func_name
, &start
, &end
);
5739 if (func_name
!= NULL
&& item
->pc
< end
)
5741 if (item
->line
== line_num
)
5745 struct symbol
*sym
=
5746 standard_lookup (func_name
, NULL
, VAR_DOMAIN
);
5747 if (is_plausible_func_for_line (sym
, line_num
))
5753 while (i
< len
&& linetable
->item
[i
].pc
< end
);
5763 return (best
== INT_MAX
) ? -1 : best
;
5767 /* Return the next higher index, k, into LINETABLE such that k > IND,
5768 entry k in LINETABLE has a line number equal to LINE_NUM, k
5769 corresponds to a PC that is in a function different from that
5770 corresponding to IND, and falls strictly within a named function
5771 that begins at a line at or preceding STARTING_LINE.
5772 Return -1 if there is no such k.
5773 IND == -1 corresponds to no function. */
5776 find_next_line_in_linetable (struct linetable
*linetable
, int line_num
,
5777 int starting_line
, int ind
)
5781 if (line_num
<= 0 || linetable
== NULL
|| ind
>= linetable
->nitems
)
5783 len
= linetable
->nitems
;
5787 CORE_ADDR start
, end
;
5789 if (find_pc_partial_function (linetable
->item
[ind
].pc
,
5790 (char **) NULL
, &start
, &end
))
5792 while (ind
< len
&& linetable
->item
[ind
].pc
< end
)
5804 struct linetable_entry
*item
= &(linetable
->item
[i
]);
5806 if (item
->line
>= line_num
)
5809 CORE_ADDR start
, end
;
5812 find_pc_partial_function (item
->pc
, &func_name
, &start
, &end
);
5814 if (func_name
!= NULL
&& item
->pc
< end
)
5816 if (item
->line
== line_num
)
5818 struct symbol
*sym
=
5819 standard_lookup (func_name
, NULL
, VAR_DOMAIN
);
5820 if (is_plausible_func_for_line (sym
, starting_line
))
5824 while ((i
+ 1) < len
&& linetable
->item
[i
+ 1].pc
< end
)
5836 /* True iff function symbol SYM starts somewhere at or before line #
5840 is_plausible_func_for_line (struct symbol
*sym
, int line_num
)
5842 struct symtab_and_line start_sal
;
5847 start_sal
= find_function_start_sal (sym
, 0);
5849 return (start_sal
.line
!= 0 && line_num
>= start_sal
.line
);
5852 /* Read in all symbol tables corresponding to partial symbol tables
5853 with file name FILENAME. */
5856 read_all_symtabs (const char *filename
)
5858 struct partial_symtab
*ps
;
5859 struct objfile
*objfile
;
5861 ALL_PSYMTABS (objfile
, ps
)
5865 if (strcmp (filename
, ps
->filename
) == 0)
5866 PSYMTAB_TO_SYMTAB (ps
);
5870 /* All sals corresponding to line LINE_NUM in a symbol table from file
5871 FILENAME, as filtered by the user. Filter out any lines that
5872 reside in functions with "suppressed" names (not corresponding to
5873 explicit Ada functions), if there is at least one in a function
5874 with a non-suppressed name. If CANONICAL is not null, set
5875 it to a corresponding array of canonical line specs.
5876 If ONE_LOCATION_ONLY is set and several matches are found for
5877 the given location, then automatically select the first match found
5878 instead of asking the user which instance should be returned. */
5880 struct symtabs_and_lines
5881 ada_sals_for_line (const char *filename
, int line_num
,
5882 int funfirstline
, char ***canonical
,
5883 int one_location_only
)
5885 struct symtabs_and_lines result
;
5886 struct objfile
*objfile
;
5888 struct cleanup
*old_chain
= make_cleanup (null_cleanup
, NULL
);
5891 read_all_symtabs (filename
);
5894 (struct symtab_and_line
*) xmalloc (4 * sizeof (result
.sals
[0]));
5897 make_cleanup (free_current_contents
, &result
.sals
);
5899 ALL_SYMTABS (objfile
, s
)
5901 int ind
, target_line_num
;
5905 if (strcmp (s
->filename
, filename
) != 0)
5909 nearest_line_number_in_linetable (LINETABLE (s
), line_num
);
5910 if (target_line_num
== -1)
5917 find_next_line_in_linetable (LINETABLE (s
),
5918 target_line_num
, line_num
, ind
);
5923 GROW_VECT (result
.sals
, len
, result
.nelts
+ 1);
5924 init_sal (&result
.sals
[result
.nelts
]);
5925 result
.sals
[result
.nelts
].line
= line_num
;
5926 result
.sals
[result
.nelts
].pc
= LINETABLE (s
)->item
[ind
].pc
;
5927 result
.sals
[result
.nelts
].symtab
= s
;
5930 adjust_pc_past_prologue (&result
.sals
[result
.nelts
].pc
);
5936 if (canonical
!= NULL
|| result
.nelts
> 1)
5939 char **func_names
= (char **) alloca (result
.nelts
* sizeof (char *));
5940 int first_choice
= (result
.nelts
> 1) ? 2 : 1;
5941 int *choices
= (int *) alloca (result
.nelts
* sizeof (int));
5943 for (k
= 0; k
< result
.nelts
; k
+= 1)
5945 find_pc_partial_function (result
.sals
[k
].pc
, &func_names
[k
],
5946 (CORE_ADDR
*) NULL
, (CORE_ADDR
*) NULL
);
5947 if (func_names
[k
] == NULL
)
5948 error ("Could not find function for one or more breakpoints.");
5951 /* Remove suppressed names, unless all are suppressed. */
5952 for (j
= 0; j
< result
.nelts
; j
+= 1)
5953 if (!is_suppressed_name (func_names
[j
]))
5955 /* At least one name is unsuppressed, so remove all
5956 suppressed names. */
5957 for (k
= n
= 0; k
< result
.nelts
; k
+= 1)
5958 if (!is_suppressed_name (func_names
[k
]))
5960 func_names
[n
] = func_names
[k
];
5961 result
.sals
[n
] = result
.sals
[k
];
5968 if (result
.nelts
> 1)
5970 if (one_location_only
)
5972 /* Automatically select the first of all possible choices. */
5978 printf_unfiltered ("[0] cancel\n");
5979 if (result
.nelts
> 1)
5980 printf_unfiltered ("[1] all\n");
5981 for (k
= 0; k
< result
.nelts
; k
+= 1)
5982 printf_unfiltered ("[%d] %s\n", k
+ first_choice
,
5983 ada_decode (func_names
[k
]));
5985 n
= get_selections (choices
, result
.nelts
, result
.nelts
,
5986 result
.nelts
> 1, "instance-choice");
5989 for (k
= 0; k
< n
; k
+= 1)
5991 result
.sals
[k
] = result
.sals
[choices
[k
]];
5992 func_names
[k
] = func_names
[choices
[k
]];
5997 if (canonical
!= NULL
&& result
.nelts
== 0)
5999 else if (canonical
!= NULL
)
6001 *canonical
= (char **) xmalloc (result
.nelts
* sizeof (char **));
6002 make_cleanup (xfree
, *canonical
);
6003 for (k
= 0; k
< result
.nelts
; k
+= 1)
6006 extended_canonical_line_spec (result
.sals
[k
], func_names
[k
]);
6007 if ((*canonical
)[k
] == NULL
)
6008 error ("Could not locate one or more breakpoints.");
6009 make_cleanup (xfree
, (*canonical
)[k
]);
6014 if (result
.nelts
== 0)
6016 do_cleanups (old_chain
);
6020 discard_cleanups (old_chain
);
6025 /* A canonical line specification of the form FILE:NAME:LINENUM for
6026 symbol table and line data SAL. NULL if insufficient
6027 information. The caller is responsible for releasing any space
6031 extended_canonical_line_spec (struct symtab_and_line sal
, const char *name
)
6035 if (sal
.symtab
== NULL
|| sal
.symtab
->filename
== NULL
|| sal
.line
<= 0)
6038 r
= (char *) xmalloc (strlen (name
) + strlen (sal
.symtab
->filename
)
6039 + sizeof (sal
.line
) * 3 + 3);
6040 sprintf (r
, "%s:'%s':%d", sal
.symtab
->filename
, name
, sal
.line
);
6044 /* If the main procedure is written in Ada, then return its name.
6045 The result is good until the next call. Return NULL if the main
6046 procedure doesn't appear to be in Ada. */
6049 ada_main_name (void)
6051 struct minimal_symbol
*msym
;
6052 CORE_ADDR main_program_name_addr
;
6053 static char main_program_name
[1024];
6054 /* For Ada, the name of the main procedure is stored in a specific
6055 string constant, generated by the binder. Look for that symbol,
6056 extract its address, and then read that string. If we didn't find
6057 that string, then most probably the main procedure is not written
6059 msym
= lookup_minimal_symbol (ADA_MAIN_PROGRAM_SYMBOL_NAME
, NULL
, NULL
);
6063 main_program_name_addr
= SYMBOL_VALUE_ADDRESS (msym
);
6064 if (main_program_name_addr
== 0)
6065 error ("Invalid address for Ada main program name.");
6067 extract_string (main_program_name_addr
, main_program_name
);
6068 return main_program_name
;
6071 /* The main procedure doesn't seem to be in Ada. */
6075 /* Return type of Ada breakpoint associated with bp_stat:
6076 0 if not an Ada-specific breakpoint, 1 for break on specific exception,
6077 2 for break on unhandled exception, 3 for assert. */
6080 ada_exception_breakpoint_type (bpstat bs
)
6083 return ((! bs
|| ! bs
->breakpoint_at
) ? 0
6084 : bs
->breakpoint_at
->break_on_exception
);
6090 /* True iff FRAME is very likely to be that of a function that is
6091 part of the runtime system. This is all very heuristic, but is
6092 intended to be used as advice as to what frames are uninteresting
6096 is_known_support_routine (struct frame_info
*frame
)
6098 struct frame_info
*next_frame
= get_next_frame (frame
);
6099 /* If frame is not innermost, that normally means that frame->pc
6100 points to *after* the call instruction, and we want to get the line
6101 containing the call, never the next line. But if the next frame is
6102 a signal_handler_caller or a dummy frame, then the next frame was
6103 not entered as the result of a call, and we want to get the line
6104 containing frame->pc. */
6105 const int pc_is_after_call
=
6107 && get_frame_type (next_frame
) != SIGTRAMP_FRAME
6108 && get_frame_type (next_frame
) != DUMMY_FRAME
;
6109 struct symtab_and_line sal
6110 = find_pc_line (get_frame_pc (frame
), pc_is_after_call
);
6116 1. The symtab is null (indicating no debugging symbols)
6117 2. The symtab's filename does not exist.
6118 3. The object file's name is one of the standard libraries.
6119 4. The symtab's file name has the form of an Ada library source file.
6120 5. The function at frame's PC has a GNAT-compiler-generated name. */
6122 if (sal
.symtab
== NULL
)
6125 /* On some systems (e.g. VxWorks), the kernel contains debugging
6126 symbols; in this case, the filename referenced by these symbols
6129 if (stat (sal
.symtab
->filename
, &st
))
6132 for (i
= 0; known_runtime_file_name_patterns
[i
] != NULL
; i
+= 1)
6134 re_comp (known_runtime_file_name_patterns
[i
]);
6135 if (re_exec (sal
.symtab
->filename
))
6138 if (sal
.symtab
->objfile
!= NULL
)
6140 for (i
= 0; known_runtime_file_name_patterns
[i
] != NULL
; i
+= 1)
6142 re_comp (known_runtime_file_name_patterns
[i
]);
6143 if (re_exec (sal
.symtab
->objfile
->name
))
6148 /* If the frame PC points after the call instruction, then we need to
6149 decrement it in order to search for the function associated to this
6150 PC. Otherwise, if the associated call was the last instruction of
6151 the function, we might either find the wrong function or even fail
6152 during the function name lookup. */
6153 if (pc_is_after_call
)
6154 func_name
= function_name_from_pc (get_frame_pc (frame
) - 1);
6156 func_name
= function_name_from_pc (get_frame_pc (frame
));
6158 if (func_name
== NULL
)
6161 for (i
= 0; known_auxiliary_function_name_patterns
[i
] != NULL
; i
+= 1)
6163 re_comp (known_auxiliary_function_name_patterns
[i
]);
6164 if (re_exec (func_name
))
6171 /* Find the first frame that contains debugging information and that is not
6172 part of the Ada run-time, starting from FI and moving upward. */
6175 ada_find_printable_frame (struct frame_info
*fi
)
6177 for (; fi
!= NULL
; fi
= get_prev_frame (fi
))
6179 if (!is_known_support_routine (fi
))
6188 /* Name found for exception associated with last bpstat sent to
6189 ada_adjust_exception_stop. Set to the null string if that bpstat
6190 did not correspond to an Ada exception or no name could be found. */
6192 static char last_exception_name
[256];
6194 /* If BS indicates a stop in an Ada exception, try to go up to a frame
6195 that will be meaningful to the user, and save the name of the last
6196 exception (truncated, if necessary) in last_exception_name. */
6199 ada_adjust_exception_stop (bpstat bs
)
6202 struct frame_info
*fi
;
6204 char *selected_frame_func
;
6207 last_exception_name
[0] = '\0';
6208 fi
= get_selected_frame ();
6209 selected_frame_func
= function_name_from_pc (get_frame_pc (fi
));
6211 switch (ada_exception_breakpoint_type (bs
))
6218 /* Unhandled exceptions. Select the frame corresponding to
6219 ada.exceptions.process_raise_exception. This frame is at
6220 least 2 levels up, so we simply skip the first 2 frames
6221 without checking the name of their associated function. */
6222 for (frame_level
= 0; frame_level
< 2; frame_level
+= 1)
6224 fi
= get_prev_frame (fi
);
6227 const char *func_name
= function_name_from_pc (get_frame_pc (fi
));
6228 if (func_name
!= NULL
6229 && strcmp (func_name
, process_raise_exception_name
) == 0)
6230 break; /* We found the frame we were looking for... */
6231 fi
= get_prev_frame (fi
);
6239 addr
= parse_and_eval_address ("e.full_name");
6242 read_memory (addr
, last_exception_name
,
6243 sizeof (last_exception_name
) - 1);
6244 last_exception_name
[sizeof (last_exception_name
) - 1] = '\0';
6245 ada_find_printable_frame (get_selected_frame ());
6248 /* Output Ada exception name (if any) associated with last call to
6249 ada_adjust_exception_stop. */
6252 ada_print_exception_stop (bpstat bs
)
6254 if (last_exception_name
[0] != '\000')
6256 ui_out_text (uiout
, last_exception_name
);
6257 ui_out_text (uiout
, " at ");
6261 /* Parses the CONDITION string associated with a breakpoint exception
6262 to get the name of the exception on which the breakpoint has been
6263 set. The returned string needs to be deallocated after use. */
6266 exception_name_from_cond (const char *condition
)
6268 char *start
, *end
, *exception_name
;
6269 int exception_name_len
;
6271 start
= strrchr (condition
, '&') + 1;
6272 end
= strchr (start
, ')') - 1;
6273 exception_name_len
= end
- start
+ 1;
6276 (char *) xmalloc ((exception_name_len
+ 1) * sizeof (char));
6277 sprintf (exception_name
, "%.*s", exception_name_len
, start
);
6279 return exception_name
;
6282 /* Print Ada-specific exception information about B, other than task
6283 clause. Return non-zero iff B was an Ada exception breakpoint. */
6286 ada_print_exception_breakpoint_nontask (struct breakpoint
*b
)
6289 if (b
->break_on_exception
== 1)
6291 if (b
->cond_string
) /* the breakpoint is on a specific exception. */
6293 char *exception_name
= exception_name_from_cond (b
->cond_string
);
6295 make_cleanup (xfree
, exception_name
);
6297 ui_out_text (uiout
, "on ");
6298 if (ui_out_is_mi_like_p (uiout
))
6299 ui_out_field_string (uiout
, "exception", exception_name
);
6302 ui_out_text (uiout
, "exception ");
6303 ui_out_text (uiout
, exception_name
);
6304 ui_out_text (uiout
, " ");
6308 ui_out_text (uiout
, "on all exceptions");
6310 else if (b
->break_on_exception
== 2)
6311 ui_out_text (uiout
, "on unhandled exception");
6312 else if (b
->break_on_exception
== 3)
6313 ui_out_text (uiout
, "on assert failure");
6322 /* Print task identifier for breakpoint B, if it is an Ada-specific
6323 breakpoint with non-zero tasking information. */
6326 ada_print_exception_breakpoint_task (struct breakpoint
*b
)
6331 ui_out_text (uiout
, " task ");
6332 ui_out_field_int (uiout
, "task", b
->task
);
6338 ada_is_exception_sym (struct symbol
*sym
)
6340 char *type_name
= type_name_no_tag (SYMBOL_TYPE (sym
));
6342 return (SYMBOL_CLASS (sym
) != LOC_TYPEDEF
6343 && SYMBOL_CLASS (sym
) != LOC_BLOCK
6344 && SYMBOL_CLASS (sym
) != LOC_CONST
6345 && type_name
!= NULL
&& strcmp (type_name
, "exception") == 0);
6349 ada_maybe_exception_partial_symbol (struct partial_symbol
*sym
)
6351 return (SYMBOL_CLASS (sym
) != LOC_TYPEDEF
6352 && SYMBOL_CLASS (sym
) != LOC_BLOCK
6353 && SYMBOL_CLASS (sym
) != LOC_CONST
);
6356 /* Cause the appropriate error if no appropriate runtime symbol is
6357 found to set a breakpoint, using ERR_DESC to describe the
6361 error_breakpoint_runtime_sym_not_found (const char *err_desc
)
6363 /* If we are not debugging an Ada program, we can not put exception
6366 if (ada_update_initial_language (language_unknown
, NULL
) != language_ada
)
6367 error ("Unable to break on %s. Is this an Ada main program?", err_desc
);
6369 /* If the symbol does not exist, then check that the program is
6370 already started, to make sure that shared libraries have been
6371 loaded. If it is not started, this may mean that the symbol is
6372 in a shared library. */
6374 if (ptid_get_pid (inferior_ptid
) == 0)
6375 error ("Unable to break on %s. Try to start the program first.", err_desc
);
6377 /* At this point, we know that we are debugging an Ada program and
6378 that the inferior has been started, but we still are not able to
6379 find the run-time symbols. That can mean that we are in
6380 configurable run time mode, or that a-except as been optimized
6381 out by the linker... In any case, at this point it is not worth
6382 supporting this feature. */
6384 error ("Cannot break on %s in this configuration.", err_desc
);
6387 /* Test if NAME is currently defined, and that either ALLOW_TRAMP or
6388 the symbol is not a shared-library trampoline. Return the result of
6392 is_runtime_sym_defined (const char *name
, int allow_tramp
)
6394 struct minimal_symbol
*msym
;
6396 msym
= lookup_minimal_symbol (name
, NULL
, NULL
);
6397 return (msym
!= NULL
&& msym
->type
!= mst_unknown
6398 && (allow_tramp
|| msym
->type
!= mst_solib_trampoline
));
6401 /* If ARG points to an Ada exception or assert breakpoint, rewrite
6402 into equivalent form. Return resulting argument string. Set
6403 *BREAK_ON_EXCEPTIONP to 1 for ordinary break on exception, 2 for
6404 break on unhandled, 3 for assert, 0 otherwise. */
6407 ada_breakpoint_rewrite (char *arg
, int *break_on_exceptionp
)
6411 *break_on_exceptionp
= 0;
6412 if (current_language
->la_language
== language_ada
6413 && strncmp (arg
, "exception", 9) == 0
6414 && (arg
[9] == ' ' || arg
[9] == '\t' || arg
[9] == '\0'))
6416 char *tok
, *end_tok
;
6418 int has_exception_propagation
=
6419 is_runtime_sym_defined (raise_sym_name
, 1);
6421 *break_on_exceptionp
= 1;
6424 while (*tok
== ' ' || *tok
== '\t')
6429 while (*end_tok
!= ' ' && *end_tok
!= '\t' && *end_tok
!= '\000')
6432 toklen
= end_tok
- tok
;
6434 arg
= (char *) xmalloc (sizeof (longest_exception_template
) + toklen
);
6435 make_cleanup (xfree
, arg
);
6438 if (has_exception_propagation
)
6439 sprintf (arg
, "'%s'", raise_sym_name
);
6441 error_breakpoint_runtime_sym_not_found ("exception");
6443 else if (strncmp (tok
, "unhandled", toklen
) == 0)
6445 if (is_runtime_sym_defined (raise_unhandled_sym_name
, 1))
6446 sprintf (arg
, "'%s'", raise_unhandled_sym_name
);
6448 error_breakpoint_runtime_sym_not_found ("exception");
6450 *break_on_exceptionp
= 2;
6454 if (is_runtime_sym_defined (raise_sym_name
, 0))
6455 sprintf (arg
, "'%s' if long_integer(e) = long_integer(&%.*s)",
6456 raise_sym_name
, toklen
, tok
);
6458 error_breakpoint_runtime_sym_not_found ("specific exception");
6461 else if (current_language
->la_language
== language_ada
6462 && strncmp (arg
, "assert", 6) == 0
6463 && (arg
[6] == ' ' || arg
[6] == '\t' || arg
[6] == '\0'))
6465 char *tok
= arg
+ 6;
6467 if (!is_runtime_sym_defined (raise_assert_sym_name
, 1))
6468 error_breakpoint_runtime_sym_not_found ("failed assertion");
6470 *break_on_exceptionp
= 3;
6473 (char *) xmalloc (sizeof (raise_assert_sym_name
) + strlen (tok
) + 2);
6474 make_cleanup (xfree
, arg
);
6475 sprintf (arg
, "'%s'%s", raise_assert_sym_name
, tok
);
6483 /* True if field number FIELD_NUM in struct or union type TYPE is supposed
6484 to be invisible to users. */
6487 ada_is_ignored_field (struct type
*type
, int field_num
)
6489 if (field_num
< 0 || field_num
> TYPE_NFIELDS (type
))
6493 const char *name
= TYPE_FIELD_NAME (type
, field_num
);
6494 return (name
== NULL
6495 || (name
[0] == '_' && strncmp (name
, "_parent", 7) != 0));
6499 /* True iff TYPE has a tag field. If REFOK, then TYPE may also be a
6500 pointer or reference type whose ultimate target has a tag field. */
6503 ada_is_tagged_type (struct type
*type
, int refok
)
6505 return (ada_lookup_struct_elt_type (type
, "_tag", refok
, 1, NULL
) != NULL
);
6508 /* True iff TYPE represents the type of X'Tag */
6511 ada_is_tag_type (struct type
*type
)
6513 if (type
== NULL
|| TYPE_CODE (type
) != TYPE_CODE_PTR
)
6516 const char *name
= ada_type_name (TYPE_TARGET_TYPE (type
));
6517 return (name
!= NULL
6518 && strcmp (name
, "ada__tags__dispatch_table") == 0);
6522 /* The type of the tag on VAL. */
6525 ada_tag_type (struct value
*val
)
6527 return ada_lookup_struct_elt_type (VALUE_TYPE (val
), "_tag", 1, 0, NULL
);
6530 /* The value of the tag on VAL. */
6533 ada_value_tag (struct value
*val
)
6535 return ada_value_struct_elt (val
, "_tag", "record");
6538 /* The value of the tag on the object of type TYPE whose contents are
6539 saved at VALADDR, if it is non-null, or is at memory address
6542 static struct value
*
6543 value_tag_from_contents_and_address (struct type
*type
, char *valaddr
,
6546 int tag_byte_offset
, dummy1
, dummy2
;
6547 struct type
*tag_type
;
6548 if (find_struct_field ("_tag", type
, 0, &tag_type
, &tag_byte_offset
,
6551 char *valaddr1
= (valaddr
== NULL
) ? NULL
: valaddr
+ tag_byte_offset
;
6552 CORE_ADDR address1
= (address
== 0) ? 0 : address
+ tag_byte_offset
;
6554 return value_from_contents_and_address (tag_type
, valaddr1
, address1
);
6559 static struct type
*
6560 type_from_tag (struct value
*tag
)
6562 const char *type_name
= ada_tag_name (tag
);
6563 if (type_name
!= NULL
)
6564 return ada_find_any_type (ada_encode (type_name
));
6573 /* Wrapper function used by ada_tag_name. Given a struct tag_args*
6574 value ARGS, sets ARGS->name to the tag name of ARGS->tag.
6575 The value stored in ARGS->name is valid until the next call to
6579 ada_tag_name_1 (void *args0
)
6581 struct tag_args
*args
= (struct tag_args
*) args0
;
6582 static char name
[1024];
6586 val
= ada_value_struct_elt (args
->tag
, "tsd", NULL
);
6589 val
= ada_value_struct_elt (val
, "expanded_name", NULL
);
6592 read_memory_string (value_as_address (val
), name
, sizeof (name
) - 1);
6593 for (p
= name
; *p
!= '\0'; p
+= 1)
6600 /* The type name of the dynamic type denoted by the 'tag value TAG, as
6604 ada_tag_name (struct value
*tag
)
6606 struct tag_args args
;
6607 if (! ada_is_tag_type (VALUE_TYPE (tag
)))
6611 catch_errors (ada_tag_name_1
, &args
, NULL
, RETURN_MASK_ALL
);
6615 /* The parent type of TYPE, or NULL if none. */
6618 ada_parent_type (struct type
*type
)
6622 CHECK_TYPEDEF (type
);
6624 if (type
== NULL
|| TYPE_CODE (type
) != TYPE_CODE_STRUCT
)
6627 for (i
= 0; i
< TYPE_NFIELDS (type
); i
+= 1)
6628 if (ada_is_parent_field (type
, i
))
6629 return check_typedef (TYPE_FIELD_TYPE (type
, i
));
6634 /* True iff field number FIELD_NUM of structure type TYPE contains the
6635 parent-type (inherited) fields of a derived type. Assumes TYPE is
6636 a structure type with at least FIELD_NUM+1 fields. */
6639 ada_is_parent_field (struct type
*type
, int field_num
)
6641 const char *name
= TYPE_FIELD_NAME (check_typedef (type
), field_num
);
6642 return (name
!= NULL
6643 && (strncmp (name
, "PARENT", 6) == 0
6644 || strncmp (name
, "_parent", 7) == 0));
6647 /* True iff field number FIELD_NUM of structure type TYPE is a
6648 transparent wrapper field (which should be silently traversed when doing
6649 field selection and flattened when printing). Assumes TYPE is a
6650 structure type with at least FIELD_NUM+1 fields. Such fields are always
6654 ada_is_wrapper_field (struct type
*type
, int field_num
)
6656 const char *name
= TYPE_FIELD_NAME (type
, field_num
);
6657 return (name
!= NULL
6658 && (strncmp (name
, "PARENT", 6) == 0
6659 || strcmp (name
, "REP") == 0
6660 || strncmp (name
, "_parent", 7) == 0
6661 || name
[0] == 'S' || name
[0] == 'R' || name
[0] == 'O'));
6664 /* True iff field number FIELD_NUM of structure or union type TYPE
6665 is a variant wrapper. Assumes TYPE is a structure type with at least
6666 FIELD_NUM+1 fields. */
6669 ada_is_variant_part (struct type
*type
, int field_num
)
6671 struct type
*field_type
= TYPE_FIELD_TYPE (type
, field_num
);
6672 return (TYPE_CODE (field_type
) == TYPE_CODE_UNION
6673 || (is_dynamic_field (type
, field_num
)
6674 && TYPE_CODE (TYPE_TARGET_TYPE (field_type
)) ==
6678 /* Assuming that VAR_TYPE is a variant wrapper (type of the variant part)
6679 whose discriminants are contained in the record type OUTER_TYPE,
6680 returns the type of the controlling discriminant for the variant. */
6683 ada_variant_discrim_type (struct type
*var_type
, struct type
*outer_type
)
6685 char *name
= ada_variant_discrim_name (var_type
);
6687 ada_lookup_struct_elt_type (outer_type
, name
, 1, 1, NULL
);
6689 return builtin_type_int
;
6694 /* Assuming that TYPE is the type of a variant wrapper, and FIELD_NUM is a
6695 valid field number within it, returns 1 iff field FIELD_NUM of TYPE
6696 represents a 'when others' clause; otherwise 0. */
6699 ada_is_others_clause (struct type
*type
, int field_num
)
6701 const char *name
= TYPE_FIELD_NAME (type
, field_num
);
6702 return (name
!= NULL
&& name
[0] == 'O');
6705 /* Assuming that TYPE0 is the type of the variant part of a record,
6706 returns the name of the discriminant controlling the variant.
6707 The value is valid until the next call to ada_variant_discrim_name. */
6710 ada_variant_discrim_name (struct type
*type0
)
6712 static char *result
= NULL
;
6713 static size_t result_len
= 0;
6716 const char *discrim_end
;
6717 const char *discrim_start
;
6719 if (TYPE_CODE (type0
) == TYPE_CODE_PTR
)
6720 type
= TYPE_TARGET_TYPE (type0
);
6724 name
= ada_type_name (type
);
6726 if (name
== NULL
|| name
[0] == '\000')
6729 for (discrim_end
= name
+ strlen (name
) - 6; discrim_end
!= name
;
6732 if (strncmp (discrim_end
, "___XVN", 6) == 0)
6735 if (discrim_end
== name
)
6738 for (discrim_start
= discrim_end
; discrim_start
!= name
+ 3;
6741 if (discrim_start
== name
+ 1)
6743 if ((discrim_start
> name
+ 3
6744 && strncmp (discrim_start
- 3, "___", 3) == 0)
6745 || discrim_start
[-1] == '.')
6749 GROW_VECT (result
, result_len
, discrim_end
- discrim_start
+ 1);
6750 strncpy (result
, discrim_start
, discrim_end
- discrim_start
);
6751 result
[discrim_end
- discrim_start
] = '\0';
6755 /* Scan STR for a subtype-encoded number, beginning at position K.
6756 Put the position of the character just past the number scanned in
6757 *NEW_K, if NEW_K!=NULL. Put the scanned number in *R, if R!=NULL.
6758 Return 1 if there was a valid number at the given position, and 0
6759 otherwise. A "subtype-encoded" number consists of the absolute value
6760 in decimal, followed by the letter 'm' to indicate a negative number.
6761 Assumes 0m does not occur. */
6764 ada_scan_number (const char str
[], int k
, LONGEST
* R
, int *new_k
)
6768 if (!isdigit (str
[k
]))
6771 /* Do it the hard way so as not to make any assumption about
6772 the relationship of unsigned long (%lu scan format code) and
6775 while (isdigit (str
[k
]))
6777 RU
= RU
* 10 + (str
[k
] - '0');
6784 *R
= (-(LONGEST
) (RU
- 1)) - 1;
6790 /* NOTE on the above: Technically, C does not say what the results of
6791 - (LONGEST) RU or (LONGEST) -RU are for RU == largest positive
6792 number representable as a LONGEST (although either would probably work
6793 in most implementations). When RU>0, the locution in the then branch
6794 above is always equivalent to the negative of RU. */
6801 /* Assuming that TYPE is a variant part wrapper type (a VARIANTS field),
6802 and FIELD_NUM is a valid field number within it, returns 1 iff VAL is
6803 in the range encoded by field FIELD_NUM of TYPE; otherwise 0. */
6806 ada_in_variant (LONGEST val
, struct type
*type
, int field_num
)
6808 const char *name
= TYPE_FIELD_NAME (type
, field_num
);
6821 if (!ada_scan_number (name
, p
+ 1, &W
, &p
))
6830 if (!ada_scan_number (name
, p
+ 1, &L
, &p
)
6831 || name
[p
] != 'T' || !ada_scan_number (name
, p
+ 1, &U
, &p
))
6833 if (val
>= L
&& val
<= U
)
6845 /* FIXME: Lots of redundancy below. Try to consolidate. */
6847 /* Given a value ARG1 (offset by OFFSET bytes) of a struct or union type
6848 ARG_TYPE, extract and return the value of one of its (non-static)
6849 fields. FIELDNO says which field. Differs from value_primitive_field
6850 only in that it can handle packed values of arbitrary type. */
6852 static struct value
*
6853 ada_value_primitive_field (struct value
*arg1
, int offset
, int fieldno
,
6854 struct type
*arg_type
)
6858 CHECK_TYPEDEF (arg_type
);
6859 type
= TYPE_FIELD_TYPE (arg_type
, fieldno
);
6861 /* Handle packed fields. */
6863 if (TYPE_FIELD_BITSIZE (arg_type
, fieldno
) != 0)
6865 int bit_pos
= TYPE_FIELD_BITPOS (arg_type
, fieldno
);
6866 int bit_size
= TYPE_FIELD_BITSIZE (arg_type
, fieldno
);
6868 return ada_value_primitive_packed_val (arg1
, VALUE_CONTENTS (arg1
),
6869 offset
+ bit_pos
/ 8,
6870 bit_pos
% 8, bit_size
, type
);
6873 return value_primitive_field (arg1
, offset
, fieldno
, arg_type
);
6876 /* Find field with name NAME in object of type TYPE. If found, return 1
6877 after setting *FIELD_TYPE_P to the field's type, *BYTE_OFFSET_P to
6878 OFFSET + the byte offset of the field within an object of that type,
6879 *BIT_OFFSET_P to the bit offset modulo byte size of the field, and
6880 *BIT_SIZE_P to its size in bits if the field is packed, and 0 otherwise.
6881 Looks inside wrappers for the field. Returns 0 if field not
6884 find_struct_field (char *name
, struct type
*type
, int offset
,
6885 struct type
**field_type_p
,
6886 int *byte_offset_p
, int *bit_offset_p
, int *bit_size_p
)
6890 CHECK_TYPEDEF (type
);
6891 *field_type_p
= NULL
;
6892 *byte_offset_p
= *bit_offset_p
= *bit_size_p
= 0;
6894 for (i
= TYPE_NFIELDS (type
) - 1; i
>= 0; i
-= 1)
6896 int bit_pos
= TYPE_FIELD_BITPOS (type
, i
);
6897 int fld_offset
= offset
+ bit_pos
/ 8;
6898 char *t_field_name
= TYPE_FIELD_NAME (type
, i
);
6900 if (t_field_name
== NULL
)
6903 else if (field_name_match (t_field_name
, name
))
6905 int bit_size
= TYPE_FIELD_BITSIZE (type
, i
);
6906 *field_type_p
= TYPE_FIELD_TYPE (type
, i
);
6907 *byte_offset_p
= fld_offset
;
6908 *bit_offset_p
= bit_pos
% 8;
6909 *bit_size_p
= bit_size
;
6912 else if (ada_is_wrapper_field (type
, i
))
6914 if (find_struct_field (name
, TYPE_FIELD_TYPE (type
, i
), fld_offset
,
6915 field_type_p
, byte_offset_p
, bit_offset_p
,
6919 else if (ada_is_variant_part (type
, i
))
6922 struct type
*field_type
= check_typedef (TYPE_FIELD_TYPE (type
, i
));
6924 for (j
= TYPE_NFIELDS (field_type
) - 1; j
>= 0; j
-= 1)
6926 if (find_struct_field (name
, TYPE_FIELD_TYPE (field_type
, j
),
6928 + TYPE_FIELD_BITPOS (field_type
, j
)/8,
6929 field_type_p
, byte_offset_p
, bit_offset_p
,
6940 /* Look for a field NAME in ARG. Adjust the address of ARG by OFFSET bytes,
6941 and search in it assuming it has (class) type TYPE.
6942 If found, return value, else return NULL.
6944 Searches recursively through wrapper fields (e.g., '_parent'). */
6946 static struct value
*
6947 ada_search_struct_field (char *name
, struct value
*arg
, int offset
,
6951 CHECK_TYPEDEF (type
);
6953 for (i
= TYPE_NFIELDS (type
) - 1; i
>= 0; i
-= 1)
6955 char *t_field_name
= TYPE_FIELD_NAME (type
, i
);
6957 if (t_field_name
== NULL
)
6960 else if (field_name_match (t_field_name
, name
))
6961 return ada_value_primitive_field (arg
, offset
, i
, type
);
6963 else if (ada_is_wrapper_field (type
, i
))
6966 ada_search_struct_field (name
, arg
,
6967 offset
+ TYPE_FIELD_BITPOS (type
, i
) / 8,
6968 TYPE_FIELD_TYPE (type
, i
));
6973 else if (ada_is_variant_part (type
, i
))
6976 struct type
*field_type
= check_typedef (TYPE_FIELD_TYPE (type
, i
));
6977 int var_offset
= offset
+ TYPE_FIELD_BITPOS (type
, i
) / 8;
6979 for (j
= TYPE_NFIELDS (field_type
) - 1; j
>= 0; j
-= 1)
6982 ada_search_struct_field (name
, arg
,
6984 + TYPE_FIELD_BITPOS (field_type
, j
)/8,
6985 TYPE_FIELD_TYPE (field_type
, j
));
6994 /* Given ARG, a value of type (pointer or reference to a)*
6995 structure/union, extract the component named NAME from the ultimate
6996 target structure/union and return it as a value with its
6997 appropriate type. If ARG is a pointer or reference and the field
6998 is not packed, returns a reference to the field, otherwise the
6999 value of the field (an lvalue if ARG is an lvalue).
7001 The routine searches for NAME among all members of the structure itself
7002 and (recursively) among all members of any wrapper members
7005 ERR is a name (for use in error messages) that identifies the class
7006 of entity that ARG is supposed to be. ERR may be null, indicating
7007 that on error, the function simply returns NULL, and does not
7008 throw an error. (FIXME: True only if ARG is a pointer or reference
7012 ada_value_struct_elt (struct value
*arg
, char *name
, char *err
)
7014 struct type
*t
, *t1
;
7018 t1
= t
= check_typedef (VALUE_TYPE (arg
));
7019 if (TYPE_CODE (t
) == TYPE_CODE_REF
)
7021 t1
= TYPE_TARGET_TYPE (t
);
7027 error ("Bad value type in a %s.", err
);
7030 if (TYPE_CODE (t1
) == TYPE_CODE_PTR
)
7037 while (TYPE_CODE (t
) == TYPE_CODE_PTR
)
7039 t1
= TYPE_TARGET_TYPE (t
);
7045 error ("Bad value type in a %s.", err
);
7048 if (TYPE_CODE (t1
) == TYPE_CODE_PTR
)
7050 arg
= value_ind (arg
);
7057 if (TYPE_CODE (t1
) != TYPE_CODE_STRUCT
&& TYPE_CODE (t1
) != TYPE_CODE_UNION
)
7062 error ("Attempt to extract a component of a value that is not a %s.",
7067 v
= ada_search_struct_field (name
, arg
, 0, t
);
7070 int bit_offset
, bit_size
, byte_offset
;
7071 struct type
*field_type
;
7074 if (TYPE_CODE (t
) == TYPE_CODE_PTR
)
7075 address
= value_as_address (arg
);
7077 address
= unpack_pointer (t
, VALUE_CONTENTS (arg
));
7079 t1
= ada_to_fixed_type (ada_get_base_type (t1
), NULL
, address
, NULL
);
7080 if (find_struct_field (name
, t1
, 0,
7081 &field_type
, &byte_offset
, &bit_offset
, &bit_size
))
7085 arg
= ada_value_ind (arg
);
7086 v
= ada_value_primitive_packed_val (arg
, NULL
, byte_offset
,
7087 bit_offset
, bit_size
,
7091 v
= value_from_pointer (lookup_reference_type (field_type
),
7092 address
+ byte_offset
);
7096 if (v
== NULL
&& err
!= NULL
)
7097 error ("There is no member named %s.", name
);
7102 /* Given a type TYPE, look up the type of the component of type named NAME.
7103 If DISPP is non-null, add its byte displacement from the beginning of a
7104 structure (pointed to by a value) of type TYPE to *DISPP (does not
7105 work for packed fields).
7107 Matches any field whose name has NAME as a prefix, possibly
7110 TYPE can be either a struct or union. If REFOK, TYPE may also
7111 be a (pointer or reference)+ to a struct or union, and the
7112 ultimate target type will be searched.
7114 Looks recursively into variant clauses and parent types.
7116 If NOERR is nonzero, return NULL if NAME is not suitably defined or
7117 TYPE is not a type of the right kind. */
7119 static struct type
*
7120 ada_lookup_struct_elt_type (struct type
*type
, char *name
, int refok
,
7121 int noerr
, int *dispp
)
7128 if (refok
&& type
!= NULL
)
7131 CHECK_TYPEDEF (type
);
7132 if (TYPE_CODE (type
) != TYPE_CODE_PTR
7133 && TYPE_CODE (type
) != TYPE_CODE_REF
)
7135 type
= TYPE_TARGET_TYPE (type
);
7139 || (TYPE_CODE (type
) != TYPE_CODE_STRUCT
&&
7140 TYPE_CODE (type
) != TYPE_CODE_UNION
))
7146 target_terminal_ours ();
7147 gdb_flush (gdb_stdout
);
7148 fprintf_unfiltered (gdb_stderr
, "Type ");
7150 fprintf_unfiltered (gdb_stderr
, "(null)");
7152 type_print (type
, "", gdb_stderr
, -1);
7153 error (" is not a structure or union type");
7157 type
= to_static_fixed_type (type
);
7159 for (i
= 0; i
< TYPE_NFIELDS (type
); i
+= 1)
7161 char *t_field_name
= TYPE_FIELD_NAME (type
, i
);
7165 if (t_field_name
== NULL
)
7168 else if (field_name_match (t_field_name
, name
))
7171 *dispp
+= TYPE_FIELD_BITPOS (type
, i
) / 8;
7172 return check_typedef (TYPE_FIELD_TYPE (type
, i
));
7175 else if (ada_is_wrapper_field (type
, i
))
7178 t
= ada_lookup_struct_elt_type (TYPE_FIELD_TYPE (type
, i
), name
,
7183 *dispp
+= disp
+ TYPE_FIELD_BITPOS (type
, i
) / 8;
7188 else if (ada_is_variant_part (type
, i
))
7191 struct type
*field_type
= check_typedef (TYPE_FIELD_TYPE (type
, i
));
7193 for (j
= TYPE_NFIELDS (field_type
) - 1; j
>= 0; j
-= 1)
7196 t
= ada_lookup_struct_elt_type (TYPE_FIELD_TYPE (field_type
, j
),
7201 *dispp
+= disp
+ TYPE_FIELD_BITPOS (type
, i
) / 8;
7212 target_terminal_ours ();
7213 gdb_flush (gdb_stdout
);
7214 fprintf_unfiltered (gdb_stderr
, "Type ");
7215 type_print (type
, "", gdb_stderr
, -1);
7216 fprintf_unfiltered (gdb_stderr
, " has no component named ");
7217 error ("%s", name
== NULL
? "<null>" : name
);
7223 /* Assuming that VAR_TYPE is the type of a variant part of a record (a union),
7224 within a value of type OUTER_TYPE that is stored in GDB at
7225 OUTER_VALADDR, determine which variant clause (field number in VAR_TYPE,
7226 numbering from 0) is applicable. Returns -1 if none are. */
7229 ada_which_variant_applies (struct type
*var_type
, struct type
*outer_type
,
7230 char *outer_valaddr
)
7235 struct type
*discrim_type
;
7236 char *discrim_name
= ada_variant_discrim_name (var_type
);
7237 LONGEST discrim_val
;
7241 ada_lookup_struct_elt_type (outer_type
, discrim_name
, 1, 1, &disp
);
7242 if (discrim_type
== NULL
)
7244 discrim_val
= unpack_long (discrim_type
, outer_valaddr
+ disp
);
7247 for (i
= 0; i
< TYPE_NFIELDS (var_type
); i
+= 1)
7249 if (ada_is_others_clause (var_type
, i
))
7251 else if (ada_in_variant (discrim_val
, var_type
, i
))
7255 return others_clause
;
7260 /* Dynamic-Sized Records */
7262 /* Strategy: The type ostensibly attached to a value with dynamic size
7263 (i.e., a size that is not statically recorded in the debugging
7264 data) does not accurately reflect the size or layout of the value.
7265 Our strategy is to convert these values to values with accurate,
7266 conventional types that are constructed on the fly. */
7268 /* There is a subtle and tricky problem here. In general, we cannot
7269 determine the size of dynamic records without its data. However,
7270 the 'struct value' data structure, which GDB uses to represent
7271 quantities in the inferior process (the target), requires the size
7272 of the type at the time of its allocation in order to reserve space
7273 for GDB's internal copy of the data. That's why the
7274 'to_fixed_xxx_type' routines take (target) addresses as parameters,
7275 rather than struct value*s.
7277 However, GDB's internal history variables ($1, $2, etc.) are
7278 struct value*s containing internal copies of the data that are not, in
7279 general, the same as the data at their corresponding addresses in
7280 the target. Fortunately, the types we give to these values are all
7281 conventional, fixed-size types (as per the strategy described
7282 above), so that we don't usually have to perform the
7283 'to_fixed_xxx_type' conversions to look at their values.
7284 Unfortunately, there is one exception: if one of the internal
7285 history variables is an array whose elements are unconstrained
7286 records, then we will need to create distinct fixed types for each
7287 element selected. */
7289 /* The upshot of all of this is that many routines take a (type, host
7290 address, target address) triple as arguments to represent a value.
7291 The host address, if non-null, is supposed to contain an internal
7292 copy of the relevant data; otherwise, the program is to consult the
7293 target at the target address. */
7295 /* Assuming that VAL0 represents a pointer value, the result of
7296 dereferencing it. Differs from value_ind in its treatment of
7297 dynamic-sized types. */
7300 ada_value_ind (struct value
*val0
)
7302 struct value
*val
= unwrap_value (value_ind (val0
));
7303 return ada_to_fixed_value (val
);
7306 /* The value resulting from dereferencing any "reference to"
7307 qualifiers on VAL0. */
7309 static struct value
*
7310 ada_coerce_ref (struct value
*val0
)
7312 if (TYPE_CODE (VALUE_TYPE (val0
)) == TYPE_CODE_REF
)
7314 struct value
*val
= val0
;
7316 val
= unwrap_value (val
);
7317 return ada_to_fixed_value (val
);
7323 /* Return OFF rounded upward if necessary to a multiple of
7324 ALIGNMENT (a power of 2). */
7327 align_value (unsigned int off
, unsigned int alignment
)
7329 return (off
+ alignment
- 1) & ~(alignment
- 1);
7332 /* Return the bit alignment required for field #F of template type TYPE. */
7335 field_alignment (struct type
*type
, int f
)
7337 const char *name
= TYPE_FIELD_NAME (type
, f
);
7338 int len
= (name
== NULL
) ? 0 : strlen (name
);
7341 if (!isdigit (name
[len
- 1]))
7344 if (isdigit (name
[len
- 2]))
7345 align_offset
= len
- 2;
7347 align_offset
= len
- 1;
7349 if (align_offset
< 7 || strncmp ("___XV", name
+ align_offset
- 6, 5) != 0)
7350 return TARGET_CHAR_BIT
;
7352 return atoi (name
+ align_offset
) * TARGET_CHAR_BIT
;
7355 /* Find a symbol named NAME. Ignores ambiguity. */
7358 ada_find_any_symbol (const char *name
)
7362 sym
= standard_lookup (name
, get_selected_block (NULL
), VAR_DOMAIN
);
7363 if (sym
!= NULL
&& SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
7366 sym
= standard_lookup (name
, NULL
, STRUCT_DOMAIN
);
7370 /* Find a type named NAME. Ignores ambiguity. */
7373 ada_find_any_type (const char *name
)
7375 struct symbol
*sym
= ada_find_any_symbol (name
);
7378 return SYMBOL_TYPE (sym
);
7383 /* Given a symbol NAME and its associated BLOCK, search all symbols
7384 for its ___XR counterpart, which is the ``renaming'' symbol
7385 associated to NAME. Return this symbol if found, return
7389 ada_find_renaming_symbol (const char *name
, struct block
*block
)
7391 const struct symbol
*function_sym
= block_function (block
);
7394 if (function_sym
!= NULL
)
7396 /* If the symbol is defined inside a function, NAME is not fully
7397 qualified. This means we need to prepend the function name
7398 as well as adding the ``___XR'' suffix to build the name of
7399 the associated renaming symbol. */
7400 char *function_name
= SYMBOL_LINKAGE_NAME (function_sym
);
7401 const int function_name_len
= strlen (function_name
);
7402 const int rename_len
= function_name_len
7405 + 6 /* "___XR\0" */;
7407 /* Library-level functions are a special case, as GNAT adds
7408 a ``_ada_'' prefix to the function name to avoid namespace
7409 pollution. However, the renaming symbol themselves do not
7410 have this prefix, so we need to skip this prefix if present. */
7411 if (function_name_len
> 5 /* "_ada_" */
7412 && strstr (function_name
, "_ada_") == function_name
)
7413 function_name
= function_name
+ 5;
7415 rename
= (char *) alloca (rename_len
* sizeof (char));
7416 sprintf (rename
, "%s__%s___XR", function_name
, name
);
7420 const int rename_len
= strlen (name
) + 6;
7421 rename
= (char *) alloca (rename_len
* sizeof (char));
7422 sprintf (rename
, "%s___XR", name
);
7425 return ada_find_any_symbol (rename
);
7428 /* Because of GNAT encoding conventions, several GDB symbols may match a
7429 given type name. If the type denoted by TYPE0 is to be preferred to
7430 that of TYPE1 for purposes of type printing, return non-zero;
7431 otherwise return 0. */
7434 ada_prefer_type (struct type
*type0
, struct type
*type1
)
7438 else if (type0
== NULL
)
7440 else if (TYPE_CODE (type1
) == TYPE_CODE_VOID
)
7442 else if (TYPE_CODE (type0
) == TYPE_CODE_VOID
)
7444 else if (TYPE_NAME (type1
) == NULL
&& TYPE_NAME (type0
) != NULL
)
7446 else if (ada_is_packed_array_type (type0
))
7448 else if (ada_is_array_descriptor_type (type0
)
7449 && !ada_is_array_descriptor_type (type1
))
7451 else if (ada_renaming_type (type0
) != NULL
7452 && ada_renaming_type (type1
) == NULL
)
7457 /* The name of TYPE, which is either its TYPE_NAME, or, if that is
7458 null, its TYPE_TAG_NAME. Null if TYPE is null. */
7461 ada_type_name (struct type
*type
)
7465 else if (TYPE_NAME (type
) != NULL
)
7466 return TYPE_NAME (type
);
7468 return TYPE_TAG_NAME (type
);
7471 /* Find a parallel type to TYPE whose name is formed by appending
7472 SUFFIX to the name of TYPE. */
7475 ada_find_parallel_type (struct type
*type
, const char *suffix
)
7478 static size_t name_len
= 0;
7480 char *typename
= ada_type_name (type
);
7482 if (typename
== NULL
)
7485 len
= strlen (typename
);
7487 GROW_VECT (name
, name_len
, len
+ strlen (suffix
) + 1);
7489 strcpy (name
, typename
);
7490 strcpy (name
+ len
, suffix
);
7492 return ada_find_any_type (name
);
7496 /* If TYPE is a variable-size record type, return the corresponding template
7497 type describing its fields. Otherwise, return NULL. */
7499 static struct type
*
7500 dynamic_template_type (struct type
*type
)
7502 CHECK_TYPEDEF (type
);
7504 if (type
== NULL
|| TYPE_CODE (type
) != TYPE_CODE_STRUCT
7505 || ada_type_name (type
) == NULL
)
7509 int len
= strlen (ada_type_name (type
));
7510 if (len
> 6 && strcmp (ada_type_name (type
) + len
- 6, "___XVE") == 0)
7513 return ada_find_parallel_type (type
, "___XVE");
7517 /* Assuming that TEMPL_TYPE is a union or struct type, returns
7518 non-zero iff field FIELD_NUM of TEMPL_TYPE has dynamic size. */
7521 is_dynamic_field (struct type
*templ_type
, int field_num
)
7523 const char *name
= TYPE_FIELD_NAME (templ_type
, field_num
);
7525 && TYPE_CODE (TYPE_FIELD_TYPE (templ_type
, field_num
)) == TYPE_CODE_PTR
7526 && strstr (name
, "___XVL") != NULL
;
7529 /* The index of the variant field of TYPE, or -1 if TYPE does not
7530 represent a variant record type. */
7533 variant_field_index (struct type
*type
)
7537 if (type
== NULL
|| TYPE_CODE (type
) != TYPE_CODE_STRUCT
)
7540 for (f
= 0; f
< TYPE_NFIELDS (type
); f
+= 1)
7542 if (ada_is_variant_part (type
, f
))
7548 /* A record type with no fields. */
7550 static struct type
*
7551 empty_record (struct objfile
*objfile
)
7553 struct type
*type
= alloc_type (objfile
);
7554 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
7555 TYPE_NFIELDS (type
) = 0;
7556 TYPE_FIELDS (type
) = NULL
;
7557 TYPE_NAME (type
) = "<empty>";
7558 TYPE_TAG_NAME (type
) = NULL
;
7559 TYPE_FLAGS (type
) = 0;
7560 TYPE_LENGTH (type
) = 0;
7564 /* An ordinary record type (with fixed-length fields) that describes
7565 the value of type TYPE at VALADDR or ADDRESS (see comments at
7566 the beginning of this section) VAL according to GNAT conventions.
7567 DVAL0 should describe the (portion of a) record that contains any
7568 necessary discriminants. It should be NULL if VALUE_TYPE (VAL) is
7569 an outer-level type (i.e., as opposed to a branch of a variant.) A
7570 variant field (unless unchecked) is replaced by a particular branch
7573 If not KEEP_DYNAMIC_FIELDS, then all fields whose position or
7574 length are not statically known are discarded. As a consequence,
7575 VALADDR, ADDRESS and DVAL0 are ignored.
7577 NOTE: Limitations: For now, we assume that dynamic fields and
7578 variants occupy whole numbers of bytes. However, they need not be
7582 ada_template_to_fixed_record_type_1 (struct type
*type
, char *valaddr
,
7583 CORE_ADDR address
, struct value
*dval0
,
7584 int keep_dynamic_fields
)
7586 struct value
*mark
= value_mark ();
7589 int nfields
, bit_len
;
7592 int fld_bit_len
, bit_incr
;
7595 /* Compute the number of fields in this record type that are going
7596 to be processed: unless keep_dynamic_fields, this includes only
7597 fields whose position and length are static will be processed. */
7598 if (keep_dynamic_fields
)
7599 nfields
= TYPE_NFIELDS (type
);
7603 while (nfields
< TYPE_NFIELDS (type
)
7604 && !ada_is_variant_part (type
, nfields
)
7605 && !is_dynamic_field (type
, nfields
))
7609 rtype
= alloc_type (TYPE_OBJFILE (type
));
7610 TYPE_CODE (rtype
) = TYPE_CODE_STRUCT
;
7611 INIT_CPLUS_SPECIFIC (rtype
);
7612 TYPE_NFIELDS (rtype
) = nfields
;
7613 TYPE_FIELDS (rtype
) = (struct field
*)
7614 TYPE_ALLOC (rtype
, nfields
* sizeof (struct field
));
7615 memset (TYPE_FIELDS (rtype
), 0, sizeof (struct field
) * nfields
);
7616 TYPE_NAME (rtype
) = ada_type_name (type
);
7617 TYPE_TAG_NAME (rtype
) = NULL
;
7618 TYPE_FLAGS (rtype
) |= TYPE_FLAG_FIXED_INSTANCE
;
7624 for (f
= 0; f
< nfields
; f
+= 1)
7628 field_alignment (type
, f
)) + TYPE_FIELD_BITPOS (type
, f
);
7629 TYPE_FIELD_BITPOS (rtype
, f
) = off
;
7630 TYPE_FIELD_BITSIZE (rtype
, f
) = 0;
7632 if (ada_is_variant_part (type
, f
))
7635 fld_bit_len
= bit_incr
= 0;
7637 else if (is_dynamic_field (type
, f
))
7640 dval
= value_from_contents_and_address (rtype
, valaddr
, address
);
7644 TYPE_FIELD_TYPE (rtype
, f
) =
7647 (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
, f
))),
7648 cond_offset_host (valaddr
, off
/ TARGET_CHAR_BIT
),
7649 cond_offset_target (address
, off
/ TARGET_CHAR_BIT
), dval
);
7650 TYPE_FIELD_NAME (rtype
, f
) = TYPE_FIELD_NAME (type
, f
);
7651 bit_incr
= fld_bit_len
=
7652 TYPE_LENGTH (TYPE_FIELD_TYPE (rtype
, f
)) * TARGET_CHAR_BIT
;
7656 TYPE_FIELD_TYPE (rtype
, f
) = TYPE_FIELD_TYPE (type
, f
);
7657 TYPE_FIELD_NAME (rtype
, f
) = TYPE_FIELD_NAME (type
, f
);
7658 if (TYPE_FIELD_BITSIZE (type
, f
) > 0)
7659 bit_incr
= fld_bit_len
=
7660 TYPE_FIELD_BITSIZE (rtype
, f
) = TYPE_FIELD_BITSIZE (type
, f
);
7662 bit_incr
= fld_bit_len
=
7663 TYPE_LENGTH (TYPE_FIELD_TYPE (type
, f
)) * TARGET_CHAR_BIT
;
7665 if (off
+ fld_bit_len
> bit_len
)
7666 bit_len
= off
+ fld_bit_len
;
7668 TYPE_LENGTH (rtype
) =
7669 align_value (bit_len
, TARGET_CHAR_BIT
) / TARGET_CHAR_BIT
;
7672 /* We handle the variant part, if any, at the end because of certain
7673 odd cases in which it is re-ordered so as NOT the last field of
7674 the record. This can happen in the presence of representation
7676 if (variant_field
>= 0)
7678 struct type
*branch_type
;
7680 off
= TYPE_FIELD_BITPOS (rtype
, variant_field
);
7683 dval
= value_from_contents_and_address (rtype
, valaddr
, address
);
7688 to_fixed_variant_branch_type
7689 (TYPE_FIELD_TYPE (type
, variant_field
),
7690 cond_offset_host (valaddr
, off
/ TARGET_CHAR_BIT
),
7691 cond_offset_target (address
, off
/ TARGET_CHAR_BIT
), dval
);
7692 if (branch_type
== NULL
)
7694 for (f
= variant_field
+ 1; f
< TYPE_NFIELDS (rtype
); f
+= 1)
7695 TYPE_FIELDS (rtype
)[f
- 1] = TYPE_FIELDS (rtype
)[f
];
7696 TYPE_NFIELDS (rtype
) -= 1;
7700 TYPE_FIELD_TYPE (rtype
, variant_field
) = branch_type
;
7701 TYPE_FIELD_NAME (rtype
, variant_field
) = "S";
7703 TYPE_LENGTH (TYPE_FIELD_TYPE (rtype
, variant_field
)) *
7705 if (off
+ fld_bit_len
> bit_len
)
7706 bit_len
= off
+ fld_bit_len
;
7707 TYPE_LENGTH (rtype
) =
7708 align_value (bit_len
, TARGET_CHAR_BIT
) / TARGET_CHAR_BIT
;
7712 TYPE_LENGTH (rtype
) = align_value (TYPE_LENGTH (rtype
), TYPE_LENGTH (type
));
7714 value_free_to_mark (mark
);
7715 if (TYPE_LENGTH (rtype
) > varsize_limit
)
7716 error ("record type with dynamic size is larger than varsize-limit");
7720 /* As for ada_template_to_fixed_record_type_1 with KEEP_DYNAMIC_FIELDS
7723 static struct type
*
7724 template_to_fixed_record_type (struct type
*type
, char *valaddr
,
7725 CORE_ADDR address
, struct value
*dval0
)
7727 return ada_template_to_fixed_record_type_1 (type
, valaddr
,
7731 /* An ordinary record type in which ___XVL-convention fields and
7732 ___XVU- and ___XVN-convention field types in TYPE0 are replaced with
7733 static approximations, containing all possible fields. Uses
7734 no runtime values. Useless for use in values, but that's OK,
7735 since the results are used only for type determinations. Works on both
7736 structs and unions. Representation note: to save space, we memorize
7737 the result of this function in the TYPE_TARGET_TYPE of the
7740 static struct type
*
7741 template_to_static_fixed_type (struct type
*type0
)
7747 if (TYPE_TARGET_TYPE (type0
) != NULL
)
7748 return TYPE_TARGET_TYPE (type0
);
7750 nfields
= TYPE_NFIELDS (type0
);
7753 for (f
= 0; f
< nfields
; f
+= 1)
7755 struct type
*field_type
= CHECK_TYPEDEF (TYPE_FIELD_TYPE (type0
, f
));
7756 struct type
*new_type
;
7758 if (is_dynamic_field (type0
, f
))
7759 new_type
= to_static_fixed_type (TYPE_TARGET_TYPE (field_type
));
7761 new_type
= to_static_fixed_type (field_type
);
7762 if (type
== type0
&& new_type
!= field_type
)
7764 TYPE_TARGET_TYPE (type0
) = type
= alloc_type (TYPE_OBJFILE (type0
));
7765 TYPE_CODE (type
) = TYPE_CODE (type0
);
7766 INIT_CPLUS_SPECIFIC (type
);
7767 TYPE_NFIELDS (type
) = nfields
;
7768 TYPE_FIELDS (type
) = (struct field
*)
7769 TYPE_ALLOC (type
, nfields
* sizeof (struct field
));
7770 memcpy (TYPE_FIELDS (type
), TYPE_FIELDS (type0
),
7771 sizeof (struct field
) * nfields
);
7772 TYPE_NAME (type
) = ada_type_name (type0
);
7773 TYPE_TAG_NAME (type
) = NULL
;
7774 TYPE_FLAGS (type
) |= TYPE_FLAG_FIXED_INSTANCE
;
7775 TYPE_LENGTH (type
) = 0;
7777 TYPE_FIELD_TYPE (type
, f
) = new_type
;
7778 TYPE_FIELD_NAME (type
, f
) = TYPE_FIELD_NAME (type0
, f
);
7783 /* Given an object of type TYPE whose contents are at VALADDR and
7784 whose address in memory is ADDRESS, returns a revision of TYPE --
7785 a non-dynamic-sized record with a variant part -- in which
7786 the variant part is replaced with the appropriate branch. Looks
7787 for discriminant values in DVAL0, which can be NULL if the record
7788 contains the necessary discriminant values. */
7790 static struct type
*
7791 to_record_with_fixed_variant_part (struct type
*type
, char *valaddr
,
7792 CORE_ADDR address
, struct value
*dval0
)
7794 struct value
*mark
= value_mark ();
7797 struct type
*branch_type
;
7798 int nfields
= TYPE_NFIELDS (type
);
7799 int variant_field
= variant_field_index (type
);
7801 if (variant_field
== -1)
7805 dval
= value_from_contents_and_address (type
, valaddr
, address
);
7809 rtype
= alloc_type (TYPE_OBJFILE (type
));
7810 TYPE_CODE (rtype
) = TYPE_CODE_STRUCT
;
7811 INIT_CPLUS_SPECIFIC (rtype
);
7812 TYPE_NFIELDS (rtype
) = nfields
;
7813 TYPE_FIELDS (rtype
) =
7814 (struct field
*) TYPE_ALLOC (rtype
, nfields
* sizeof (struct field
));
7815 memcpy (TYPE_FIELDS (rtype
), TYPE_FIELDS (type
),
7816 sizeof (struct field
) * nfields
);
7817 TYPE_NAME (rtype
) = ada_type_name (type
);
7818 TYPE_TAG_NAME (rtype
) = NULL
;
7819 TYPE_FLAGS (rtype
) |= TYPE_FLAG_FIXED_INSTANCE
;
7820 TYPE_LENGTH (rtype
) = TYPE_LENGTH (type
);
7822 branch_type
= to_fixed_variant_branch_type
7823 (TYPE_FIELD_TYPE (type
, variant_field
),
7824 cond_offset_host (valaddr
,
7825 TYPE_FIELD_BITPOS (type
, variant_field
)
7827 cond_offset_target (address
,
7828 TYPE_FIELD_BITPOS (type
, variant_field
)
7829 / TARGET_CHAR_BIT
), dval
);
7830 if (branch_type
== NULL
)
7833 for (f
= variant_field
+ 1; f
< nfields
; f
+= 1)
7834 TYPE_FIELDS (rtype
)[f
- 1] = TYPE_FIELDS (rtype
)[f
];
7835 TYPE_NFIELDS (rtype
) -= 1;
7839 TYPE_FIELD_TYPE (rtype
, variant_field
) = branch_type
;
7840 TYPE_FIELD_NAME (rtype
, variant_field
) = "S";
7841 TYPE_FIELD_BITSIZE (rtype
, variant_field
) = 0;
7842 TYPE_LENGTH (rtype
) += TYPE_LENGTH (branch_type
);
7844 TYPE_LENGTH (rtype
) -= TYPE_LENGTH (TYPE_FIELD_TYPE (type
, variant_field
));
7846 value_free_to_mark (mark
);
7850 /* An ordinary record type (with fixed-length fields) that describes
7851 the value at (TYPE0, VALADDR, ADDRESS) [see explanation at
7852 beginning of this section]. Any necessary discriminants' values
7853 should be in DVAL, a record value; it may be NULL if the object
7854 at ADDR itself contains any necessary discriminant values.
7855 Additionally, VALADDR and ADDRESS may also be NULL if no discriminant
7856 values from the record are needed. Except in the case that DVAL,
7857 VALADDR, and ADDRESS are all 0 or NULL, a variant field (unless
7858 unchecked) is replaced by a particular branch of the variant.
7860 NOTE: the case in which DVAL and VALADDR are NULL and ADDRESS is 0
7861 is questionable and may be removed. It can arise during the
7862 processing of an unconstrained-array-of-record type where all the
7863 variant branches have exactly the same size. This is because in
7864 such cases, the compiler does not bother to use the XVS convention
7865 when encoding the record. I am currently dubious of this
7866 shortcut and suspect the compiler should be altered. FIXME. */
7868 static struct type
*
7869 to_fixed_record_type (struct type
*type0
, char *valaddr
,
7870 CORE_ADDR address
, struct value
*dval
)
7872 struct type
*templ_type
;
7874 if (TYPE_FLAGS (type0
) & TYPE_FLAG_FIXED_INSTANCE
)
7877 templ_type
= dynamic_template_type (type0
);
7879 if (templ_type
!= NULL
)
7880 return template_to_fixed_record_type (templ_type
, valaddr
, address
, dval
);
7881 else if (variant_field_index (type0
) >= 0)
7883 if (dval
== NULL
&& valaddr
== NULL
&& address
== 0)
7885 return to_record_with_fixed_variant_part (type0
, valaddr
, address
,
7890 TYPE_FLAGS (type0
) |= TYPE_FLAG_FIXED_INSTANCE
;
7896 /* An ordinary record type (with fixed-length fields) that describes
7897 the value at (VAR_TYPE0, VALADDR, ADDRESS), where VAR_TYPE0 is a
7898 union type. Any necessary discriminants' values should be in DVAL,
7899 a record value. That is, this routine selects the appropriate
7900 branch of the union at ADDR according to the discriminant value
7901 indicated in the union's type name. */
7903 static struct type
*
7904 to_fixed_variant_branch_type (struct type
*var_type0
, char *valaddr
,
7905 CORE_ADDR address
, struct value
*dval
)
7908 struct type
*templ_type
;
7909 struct type
*var_type
;
7911 if (TYPE_CODE (var_type0
) == TYPE_CODE_PTR
)
7912 var_type
= TYPE_TARGET_TYPE (var_type0
);
7914 var_type
= var_type0
;
7916 templ_type
= ada_find_parallel_type (var_type
, "___XVU");
7918 if (templ_type
!= NULL
)
7919 var_type
= templ_type
;
7922 ada_which_variant_applies (var_type
,
7923 VALUE_TYPE (dval
), VALUE_CONTENTS (dval
));
7926 return empty_record (TYPE_OBJFILE (var_type
));
7927 else if (is_dynamic_field (var_type
, which
))
7928 return to_fixed_record_type
7929 (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (var_type
, which
)),
7930 valaddr
, address
, dval
);
7931 else if (variant_field_index (TYPE_FIELD_TYPE (var_type
, which
)) >= 0)
7933 to_fixed_record_type
7934 (TYPE_FIELD_TYPE (var_type
, which
), valaddr
, address
, dval
);
7936 return TYPE_FIELD_TYPE (var_type
, which
);
7939 /* Assuming that TYPE0 is an array type describing the type of a value
7940 at ADDR, and that DVAL describes a record containing any
7941 discriminants used in TYPE0, returns a type for the value that
7942 contains no dynamic components (that is, no components whose sizes
7943 are determined by run-time quantities). Unless IGNORE_TOO_BIG is
7944 true, gives an error message if the resulting type's size is over
7947 static struct type
*
7948 to_fixed_array_type (struct type
*type0
, struct value
*dval
,
7951 struct type
*index_type_desc
;
7952 struct type
*result
;
7954 if (ada_is_packed_array_type (type0
) /* revisit? */
7955 || (TYPE_FLAGS (type0
) & TYPE_FLAG_FIXED_INSTANCE
))
7958 index_type_desc
= ada_find_parallel_type (type0
, "___XA");
7959 if (index_type_desc
== NULL
)
7961 struct type
*elt_type0
= check_typedef (TYPE_TARGET_TYPE (type0
));
7962 /* NOTE: elt_type---the fixed version of elt_type0---should never
7963 depend on the contents of the array in properly constructed
7965 struct type
*elt_type
= ada_to_fixed_type (elt_type0
, 0, 0, dval
);
7967 if (elt_type0
== elt_type
)
7970 result
= create_array_type (alloc_type (TYPE_OBJFILE (type0
)),
7971 elt_type
, TYPE_INDEX_TYPE (type0
));
7976 struct type
*elt_type0
;
7979 for (i
= TYPE_NFIELDS (index_type_desc
); i
> 0; i
-= 1)
7980 elt_type0
= TYPE_TARGET_TYPE (elt_type0
);
7982 /* NOTE: result---the fixed version of elt_type0---should never
7983 depend on the contents of the array in properly constructed
7985 result
= ada_to_fixed_type (check_typedef (elt_type0
), 0, 0, dval
);
7986 for (i
= TYPE_NFIELDS (index_type_desc
) - 1; i
>= 0; i
-= 1)
7988 struct type
*range_type
=
7989 to_fixed_range_type (TYPE_FIELD_NAME (index_type_desc
, i
),
7990 dval
, TYPE_OBJFILE (type0
));
7991 result
= create_array_type (alloc_type (TYPE_OBJFILE (type0
)),
7992 result
, range_type
);
7994 if (!ignore_too_big
&& TYPE_LENGTH (result
) > varsize_limit
)
7995 error ("array type with dynamic size is larger than varsize-limit");
7998 TYPE_FLAGS (result
) |= TYPE_FLAG_FIXED_INSTANCE
;
8003 /* A standard type (containing no dynamically sized components)
8004 corresponding to TYPE for the value (TYPE, VALADDR, ADDRESS)
8005 DVAL describes a record containing any discriminants used in TYPE0,
8006 and may be NULL if there are none, or if the object of type TYPE at
8007 ADDRESS or in VALADDR contains these discriminants. */
8010 ada_to_fixed_type (struct type
*type
, char *valaddr
,
8011 CORE_ADDR address
, struct value
*dval
)
8013 CHECK_TYPEDEF (type
);
8014 switch (TYPE_CODE (type
))
8018 case TYPE_CODE_STRUCT
:
8020 struct type
*static_type
= to_static_fixed_type (type
);
8021 if (ada_is_tagged_type (static_type
, 0))
8023 struct type
*real_type
=
8024 type_from_tag (value_tag_from_contents_and_address (static_type
,
8027 if (real_type
!= NULL
)
8030 return to_fixed_record_type (type
, valaddr
, address
, NULL
);
8032 case TYPE_CODE_ARRAY
:
8033 return to_fixed_array_type (type
, dval
, 1);
8034 case TYPE_CODE_UNION
:
8038 return to_fixed_variant_branch_type (type
, valaddr
, address
, dval
);
8042 /* A standard (static-sized) type corresponding as well as possible to
8043 TYPE0, but based on no runtime data. */
8045 static struct type
*
8046 to_static_fixed_type (struct type
*type0
)
8053 if (TYPE_FLAGS (type0
) & TYPE_FLAG_FIXED_INSTANCE
)
8056 CHECK_TYPEDEF (type0
);
8058 switch (TYPE_CODE (type0
))
8062 case TYPE_CODE_STRUCT
:
8063 type
= dynamic_template_type (type0
);
8065 return template_to_static_fixed_type (type
);
8067 return template_to_static_fixed_type (type0
);
8068 case TYPE_CODE_UNION
:
8069 type
= ada_find_parallel_type (type0
, "___XVU");
8071 return template_to_static_fixed_type (type
);
8073 return template_to_static_fixed_type (type0
);
8077 /* A static approximation of TYPE with all type wrappers removed. */
8079 static struct type
*
8080 static_unwrap_type (struct type
*type
)
8082 if (ada_is_aligner_type (type
))
8084 struct type
*type1
= TYPE_FIELD_TYPE (check_typedef (type
), 0);
8085 if (ada_type_name (type1
) == NULL
)
8086 TYPE_NAME (type1
) = ada_type_name (type
);
8088 return static_unwrap_type (type1
);
8092 struct type
*raw_real_type
= ada_get_base_type (type
);
8093 if (raw_real_type
== type
)
8096 return to_static_fixed_type (raw_real_type
);
8100 /* In some cases, incomplete and private types require
8101 cross-references that are not resolved as records (for example,
8103 type FooP is access Foo;
8105 type Foo is array ...;
8106 ). In these cases, since there is no mechanism for producing
8107 cross-references to such types, we instead substitute for FooP a
8108 stub enumeration type that is nowhere resolved, and whose tag is
8109 the name of the actual type. Call these types "non-record stubs". */
8111 /* A type equivalent to TYPE that is not a non-record stub, if one
8112 exists, otherwise TYPE. */
8115 ada_completed_type (struct type
*type
)
8117 CHECK_TYPEDEF (type
);
8118 if (type
== NULL
|| TYPE_CODE (type
) != TYPE_CODE_ENUM
8119 || (TYPE_FLAGS (type
) & TYPE_FLAG_STUB
) == 0
8120 || TYPE_TAG_NAME (type
) == NULL
)
8124 char *name
= TYPE_TAG_NAME (type
);
8125 struct type
*type1
= ada_find_any_type (name
);
8126 return (type1
== NULL
) ? type
: type1
;
8130 /* A value representing the data at VALADDR/ADDRESS as described by
8131 type TYPE0, but with a standard (static-sized) type that correctly
8132 describes it. If VAL0 is not NULL and TYPE0 already is a standard
8133 type, then return VAL0 [this feature is simply to avoid redundant
8134 creation of struct values]. */
8136 static struct value
*
8137 ada_to_fixed_value_create (struct type
*type0
, CORE_ADDR address
,
8140 struct type
*type
= ada_to_fixed_type (type0
, 0, address
, NULL
);
8141 if (type
== type0
&& val0
!= NULL
)
8144 return value_from_contents_and_address (type
, 0, address
);
8147 /* A value representing VAL, but with a standard (static-sized) type
8148 that correctly describes it. Does not necessarily create a new
8151 static struct value
*
8152 ada_to_fixed_value (struct value
*val
)
8154 return ada_to_fixed_value_create (VALUE_TYPE (val
),
8155 VALUE_ADDRESS (val
) + VALUE_OFFSET (val
),
8159 /* If the PC is pointing inside a function prologue, then re-adjust it
8160 past this prologue. */
8163 adjust_pc_past_prologue (CORE_ADDR
*pc
)
8165 struct symbol
*func_sym
= find_pc_function (*pc
);
8169 const struct symtab_and_line sal
= find_function_start_sal (func_sym
, 1);
8176 /* A value representing VAL, but with a standard (static-sized) type
8177 chosen to approximate the real type of VAL as well as possible, but
8178 without consulting any runtime values. For Ada dynamic-sized
8179 types, therefore, the type of the result is likely to be inaccurate. */
8182 ada_to_static_fixed_value (struct value
*val
)
8185 to_static_fixed_type (static_unwrap_type (VALUE_TYPE (val
)));
8186 if (type
== VALUE_TYPE (val
))
8189 return coerce_unspec_val_to_type (val
, type
);
8195 /* Table mapping attribute numbers to names.
8196 NOTE: Keep up to date with enum ada_attribute definition in ada-lang.h. */
8198 static const char *attribute_names
[] = {
8216 ada_attribute_name (enum exp_opcode n
)
8218 if (n
>= OP_ATR_FIRST
&& n
<= (int) OP_ATR_VAL
)
8219 return attribute_names
[n
- OP_ATR_FIRST
+ 1];
8221 return attribute_names
[0];
8224 /* Evaluate the 'POS attribute applied to ARG. */
8227 pos_atr (struct value
*arg
)
8229 struct type
*type
= VALUE_TYPE (arg
);
8231 if (!discrete_type_p (type
))
8232 error ("'POS only defined on discrete types");
8234 if (TYPE_CODE (type
) == TYPE_CODE_ENUM
)
8237 LONGEST v
= value_as_long (arg
);
8239 for (i
= 0; i
< TYPE_NFIELDS (type
); i
+= 1)
8241 if (v
== TYPE_FIELD_BITPOS (type
, i
))
8244 error ("enumeration value is invalid: can't find 'POS");
8247 return value_as_long (arg
);
8250 static struct value
*
8251 value_pos_atr (struct value
*arg
)
8253 return value_from_longest (builtin_type_ada_int
, pos_atr (arg
));
8256 /* Evaluate the TYPE'VAL attribute applied to ARG. */
8258 static struct value
*
8259 value_val_atr (struct type
*type
, struct value
*arg
)
8261 if (!discrete_type_p (type
))
8262 error ("'VAL only defined on discrete types");
8263 if (!integer_type_p (VALUE_TYPE (arg
)))
8264 error ("'VAL requires integral argument");
8266 if (TYPE_CODE (type
) == TYPE_CODE_ENUM
)
8268 long pos
= value_as_long (arg
);
8269 if (pos
< 0 || pos
>= TYPE_NFIELDS (type
))
8270 error ("argument to 'VAL out of range");
8271 return value_from_longest (type
, TYPE_FIELD_BITPOS (type
, pos
));
8274 return value_from_longest (type
, value_as_long (arg
));
8280 /* True if TYPE appears to be an Ada character type.
8281 [At the moment, this is true only for Character and Wide_Character;
8282 It is a heuristic test that could stand improvement]. */
8285 ada_is_character_type (struct type
*type
)
8287 const char *name
= ada_type_name (type
);
8290 && (TYPE_CODE (type
) == TYPE_CODE_CHAR
8291 || TYPE_CODE (type
) == TYPE_CODE_INT
8292 || TYPE_CODE (type
) == TYPE_CODE_RANGE
)
8293 && (strcmp (name
, "character") == 0
8294 || strcmp (name
, "wide_character") == 0
8295 || strcmp (name
, "unsigned char") == 0);
8298 /* True if TYPE appears to be an Ada string type. */
8301 ada_is_string_type (struct type
*type
)
8303 CHECK_TYPEDEF (type
);
8305 && TYPE_CODE (type
) != TYPE_CODE_PTR
8306 && (ada_is_simple_array_type (type
) || ada_is_array_descriptor_type (type
))
8307 && ada_array_arity (type
) == 1)
8309 struct type
*elttype
= ada_array_element_type (type
, 1);
8311 return ada_is_character_type (elttype
);
8318 /* True if TYPE is a struct type introduced by the compiler to force the
8319 alignment of a value. Such types have a single field with a
8320 distinctive name. */
8323 ada_is_aligner_type (struct type
*type
)
8325 CHECK_TYPEDEF (type
);
8326 return (TYPE_CODE (type
) == TYPE_CODE_STRUCT
8327 && TYPE_NFIELDS (type
) == 1
8328 && strcmp (TYPE_FIELD_NAME (type
, 0), "F") == 0);
8331 /* If there is an ___XVS-convention type parallel to SUBTYPE, return
8332 the parallel type. */
8335 ada_get_base_type (struct type
*raw_type
)
8337 struct type
*real_type_namer
;
8338 struct type
*raw_real_type
;
8340 if (raw_type
== NULL
|| TYPE_CODE (raw_type
) != TYPE_CODE_STRUCT
)
8343 real_type_namer
= ada_find_parallel_type (raw_type
, "___XVS");
8344 if (real_type_namer
== NULL
8345 || TYPE_CODE (real_type_namer
) != TYPE_CODE_STRUCT
8346 || TYPE_NFIELDS (real_type_namer
) != 1)
8349 raw_real_type
= ada_find_any_type (TYPE_FIELD_NAME (real_type_namer
, 0));
8350 if (raw_real_type
== NULL
)
8353 return raw_real_type
;
8356 /* The type of value designated by TYPE, with all aligners removed. */
8359 ada_aligned_type (struct type
*type
)
8361 if (ada_is_aligner_type (type
))
8362 return ada_aligned_type (TYPE_FIELD_TYPE (type
, 0));
8364 return ada_get_base_type (type
);
8368 /* The address of the aligned value in an object at address VALADDR
8369 having type TYPE. Assumes ada_is_aligner_type (TYPE). */
8372 ada_aligned_value_addr (struct type
*type
, char *valaddr
)
8374 if (ada_is_aligner_type (type
))
8375 return ada_aligned_value_addr (TYPE_FIELD_TYPE (type
, 0),
8377 TYPE_FIELD_BITPOS (type
,
8378 0) / TARGET_CHAR_BIT
);
8385 /* The printed representation of an enumeration literal with encoded
8386 name NAME. The value is good to the next call of ada_enum_name. */
8388 ada_enum_name (const char *name
)
8390 static char *result
;
8391 static size_t result_len
= 0;
8394 /* First, unqualify the enumeration name:
8395 1. Search for the last '.' character. If we find one, then skip
8396 all the preceeding characters, the unqualified name starts
8397 right after that dot.
8398 2. Otherwise, we may be debugging on a target where the compiler
8399 translates dots into "__". Search forward for double underscores,
8400 but stop searching when we hit an overloading suffix, which is
8401 of the form "__" followed by digits. */
8403 if ((tmp
= strrchr (name
, '.')) != NULL
)
8407 while ((tmp
= strstr (name
, "__")) != NULL
)
8409 if (isdigit (tmp
[2]))
8419 if (name
[1] == 'U' || name
[1] == 'W')
8421 if (sscanf (name
+ 2, "%x", &v
) != 1)
8427 GROW_VECT (result
, result_len
, 16);
8428 if (isascii (v
) && isprint (v
))
8429 sprintf (result
, "'%c'", v
);
8430 else if (name
[1] == 'U')
8431 sprintf (result
, "[\"%02x\"]", v
);
8433 sprintf (result
, "[\"%04x\"]", v
);
8439 if ((tmp
= strstr (name
, "__")) != NULL
8440 || (tmp
= strstr (name
, "$")) != NULL
)
8442 GROW_VECT (result
, result_len
, tmp
- name
+ 1);
8443 strncpy (result
, name
, tmp
- name
);
8444 result
[tmp
- name
] = '\0';
8452 static struct value
*
8453 evaluate_subexp (struct type
*expect_type
, struct expression
*exp
, int *pos
,
8456 return (*exp
->language_defn
->la_exp_desc
->evaluate_exp
)
8457 (expect_type
, exp
, pos
, noside
);
8460 /* Evaluate the subexpression of EXP starting at *POS as for
8461 evaluate_type, updating *POS to point just past the evaluated
8464 static struct value
*
8465 evaluate_subexp_type (struct expression
*exp
, int *pos
)
8467 return (*exp
->language_defn
->la_exp_desc
->evaluate_exp
)
8468 (NULL_TYPE
, exp
, pos
, EVAL_AVOID_SIDE_EFFECTS
);
8471 /* If VAL is wrapped in an aligner or subtype wrapper, return the
8474 static struct value
*
8475 unwrap_value (struct value
*val
)
8477 struct type
*type
= check_typedef (VALUE_TYPE (val
));
8478 if (ada_is_aligner_type (type
))
8480 struct value
*v
= value_struct_elt (&val
, NULL
, "F",
8481 NULL
, "internal structure");
8482 struct type
*val_type
= check_typedef (VALUE_TYPE (v
));
8483 if (ada_type_name (val_type
) == NULL
)
8484 TYPE_NAME (val_type
) = ada_type_name (type
);
8486 return unwrap_value (v
);
8490 struct type
*raw_real_type
=
8491 ada_completed_type (ada_get_base_type (type
));
8493 if (type
== raw_real_type
)
8497 coerce_unspec_val_to_type
8498 (val
, ada_to_fixed_type (raw_real_type
, 0,
8499 VALUE_ADDRESS (val
) + VALUE_OFFSET (val
),
8504 static struct value
*
8505 cast_to_fixed (struct type
*type
, struct value
*arg
)
8509 if (type
== VALUE_TYPE (arg
))
8511 else if (ada_is_fixed_point_type (VALUE_TYPE (arg
)))
8512 val
= ada_float_to_fixed (type
,
8513 ada_fixed_to_float (VALUE_TYPE (arg
),
8514 value_as_long (arg
)));
8518 value_as_double (value_cast (builtin_type_double
, value_copy (arg
)));
8519 val
= ada_float_to_fixed (type
, argd
);
8522 return value_from_longest (type
, val
);
8525 static struct value
*
8526 cast_from_fixed_to_double (struct value
*arg
)
8528 DOUBLEST val
= ada_fixed_to_float (VALUE_TYPE (arg
),
8529 value_as_long (arg
));
8530 return value_from_double (builtin_type_double
, val
);
8533 /* Coerce VAL as necessary for assignment to an lval of type TYPE, and
8534 return the converted value. */
8536 static struct value
*
8537 coerce_for_assign (struct type
*type
, struct value
*val
)
8539 struct type
*type2
= VALUE_TYPE (val
);
8543 CHECK_TYPEDEF (type2
);
8544 CHECK_TYPEDEF (type
);
8546 if (TYPE_CODE (type2
) == TYPE_CODE_PTR
8547 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
)
8549 val
= ada_value_ind (val
);
8550 type2
= VALUE_TYPE (val
);
8553 if (TYPE_CODE (type2
) == TYPE_CODE_ARRAY
8554 && TYPE_CODE (type
) == TYPE_CODE_ARRAY
)
8556 if (TYPE_LENGTH (type2
) != TYPE_LENGTH (type
)
8557 || TYPE_LENGTH (TYPE_TARGET_TYPE (type2
))
8558 != TYPE_LENGTH (TYPE_TARGET_TYPE (type2
)))
8559 error ("Incompatible types in assignment");
8560 VALUE_TYPE (val
) = type
;
8565 static struct value
*
8566 ada_value_binop (struct value
*arg1
, struct value
*arg2
, enum exp_opcode op
)
8569 struct type
*type1
, *type2
;
8574 type1
= base_type (check_typedef (VALUE_TYPE (arg1
)));
8575 type2
= base_type (check_typedef (VALUE_TYPE (arg2
)));
8577 if (TYPE_CODE (type1
) != TYPE_CODE_INT
|| TYPE_CODE (type2
) != TYPE_CODE_INT
)
8578 return value_binop (arg1
, arg2
, op
);
8587 return value_binop (arg1
, arg2
, op
);
8590 v2
= value_as_long (arg2
);
8592 error ("second operand of %s must not be zero.", op_string (op
));
8594 if (TYPE_UNSIGNED (type1
) || op
== BINOP_MOD
)
8595 return value_binop (arg1
, arg2
, op
);
8597 v1
= value_as_long (arg1
);
8602 if (! TRUNCATION_TOWARDS_ZERO
&& v1
* (v1
%v2
) < 0)
8603 v
+= v
> 0 ? -1 : 1;
8611 /* Should not reach this point. */
8615 val
= allocate_value (type1
);
8616 store_unsigned_integer (VALUE_CONTENTS_RAW (val
),
8617 TYPE_LENGTH (VALUE_TYPE (val
)),
8623 ada_value_equal (struct value
*arg1
, struct value
*arg2
)
8625 if (ada_is_direct_array_type (VALUE_TYPE (arg1
))
8626 || ada_is_direct_array_type (VALUE_TYPE (arg2
)))
8628 arg1
= ada_coerce_to_simple_array (arg1
);
8629 arg2
= ada_coerce_to_simple_array (arg2
);
8630 if (TYPE_CODE (VALUE_TYPE (arg1
)) != TYPE_CODE_ARRAY
8631 || TYPE_CODE (VALUE_TYPE (arg2
)) != TYPE_CODE_ARRAY
)
8632 error ("Attempt to compare array with non-array");
8633 /* FIXME: The following works only for types whose
8634 representations use all bits (no padding or undefined bits)
8635 and do not have user-defined equality. */
8637 TYPE_LENGTH (VALUE_TYPE (arg1
)) == TYPE_LENGTH (VALUE_TYPE (arg2
))
8638 && memcmp (VALUE_CONTENTS (arg1
), VALUE_CONTENTS (arg2
),
8639 TYPE_LENGTH (VALUE_TYPE (arg1
))) == 0;
8641 return value_equal (arg1
, arg2
);
8645 ada_evaluate_subexp (struct type
*expect_type
, struct expression
*exp
,
8646 int *pos
, enum noside noside
)
8649 int tem
, tem2
, tem3
;
8651 struct value
*arg1
= NULL
, *arg2
= NULL
, *arg3
;
8654 struct value
**argvec
;
8658 op
= exp
->elts
[pc
].opcode
;
8665 unwrap_value (evaluate_subexp_standard
8666 (expect_type
, exp
, pos
, noside
));
8670 struct value
*result
;
8672 result
= evaluate_subexp_standard (expect_type
, exp
, pos
, noside
);
8673 /* The result type will have code OP_STRING, bashed there from
8674 OP_ARRAY. Bash it back. */
8675 if (TYPE_CODE (VALUE_TYPE (result
)) == TYPE_CODE_STRING
)
8676 TYPE_CODE (VALUE_TYPE (result
)) = TYPE_CODE_ARRAY
;
8682 type
= exp
->elts
[pc
+ 1].type
;
8683 arg1
= evaluate_subexp (type
, exp
, pos
, noside
);
8684 if (noside
== EVAL_SKIP
)
8686 if (type
!= check_typedef (VALUE_TYPE (arg1
)))
8688 if (ada_is_fixed_point_type (type
))
8689 arg1
= cast_to_fixed (type
, arg1
);
8690 else if (ada_is_fixed_point_type (VALUE_TYPE (arg1
)))
8691 arg1
= value_cast (type
, cast_from_fixed_to_double (arg1
));
8692 else if (VALUE_LVAL (arg1
) == lval_memory
)
8694 /* This is in case of the really obscure (and undocumented,
8695 but apparently expected) case of (Foo) Bar.all, where Bar
8696 is an integer constant and Foo is a dynamic-sized type.
8697 If we don't do this, ARG1 will simply be relabeled with
8699 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
8700 return value_zero (to_static_fixed_type (type
), not_lval
);
8702 ada_to_fixed_value_create
8703 (type
, VALUE_ADDRESS (arg1
) + VALUE_OFFSET (arg1
), 0);
8706 arg1
= value_cast (type
, arg1
);
8712 type
= exp
->elts
[pc
+ 1].type
;
8713 return ada_evaluate_subexp (type
, exp
, pos
, noside
);
8716 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
8717 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
8718 if (noside
== EVAL_SKIP
|| noside
== EVAL_AVOID_SIDE_EFFECTS
)
8720 if (ada_is_fixed_point_type (VALUE_TYPE (arg1
)))
8721 arg2
= cast_to_fixed (VALUE_TYPE (arg1
), arg2
);
8722 else if (ada_is_fixed_point_type (VALUE_TYPE (arg2
)))
8724 ("Fixed-point values must be assigned to fixed-point variables");
8726 arg2
= coerce_for_assign (VALUE_TYPE (arg1
), arg2
);
8727 return ada_value_assign (arg1
, arg2
);
8730 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
8731 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
8732 if (noside
== EVAL_SKIP
)
8734 if ((ada_is_fixed_point_type (VALUE_TYPE (arg1
))
8735 || ada_is_fixed_point_type (VALUE_TYPE (arg2
)))
8736 && VALUE_TYPE (arg1
) != VALUE_TYPE (arg2
))
8738 ("Operands of fixed-point addition must have the same type");
8739 return value_cast (VALUE_TYPE (arg1
), value_add (arg1
, arg2
));
8742 arg1
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
8743 arg2
= evaluate_subexp_with_coercion (exp
, pos
, noside
);
8744 if (noside
== EVAL_SKIP
)
8746 if ((ada_is_fixed_point_type (VALUE_TYPE (arg1
))
8747 || ada_is_fixed_point_type (VALUE_TYPE (arg2
)))
8748 && VALUE_TYPE (arg1
) != VALUE_TYPE (arg2
))
8750 ("Operands of fixed-point subtraction must have the same type");
8751 return value_cast (VALUE_TYPE (arg1
), value_sub (arg1
, arg2
));
8755 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
8756 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
8757 if (noside
== EVAL_SKIP
)
8759 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
8760 && (op
== BINOP_DIV
|| op
== BINOP_REM
|| op
== BINOP_MOD
))
8761 return value_zero (VALUE_TYPE (arg1
), not_lval
);
8764 if (ada_is_fixed_point_type (VALUE_TYPE (arg1
)))
8765 arg1
= cast_from_fixed_to_double (arg1
);
8766 if (ada_is_fixed_point_type (VALUE_TYPE (arg2
)))
8767 arg2
= cast_from_fixed_to_double (arg2
);
8768 return ada_value_binop (arg1
, arg2
, op
);
8773 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
8774 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
8775 if (noside
== EVAL_SKIP
)
8777 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
8778 && (op
== BINOP_DIV
|| op
== BINOP_REM
|| op
== BINOP_MOD
))
8779 return value_zero (VALUE_TYPE (arg1
), not_lval
);
8781 return ada_value_binop (arg1
, arg2
, op
);
8784 case BINOP_NOTEQUAL
:
8785 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
8786 arg2
= evaluate_subexp (VALUE_TYPE (arg1
), exp
, pos
, noside
);
8787 if (noside
== EVAL_SKIP
)
8789 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
8792 tem
= ada_value_equal (arg1
, arg2
);
8793 if (op
== BINOP_NOTEQUAL
)
8795 return value_from_longest (LA_BOOL_TYPE
, (LONGEST
) tem
);
8798 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
8799 if (noside
== EVAL_SKIP
)
8801 else if (ada_is_fixed_point_type (VALUE_TYPE (arg1
)))
8802 return value_cast (VALUE_TYPE (arg1
), value_neg (arg1
));
8804 return value_neg (arg1
);
8808 if (noside
== EVAL_SKIP
)
8813 else if (SYMBOL_DOMAIN (exp
->elts
[pc
+ 2].symbol
) == UNDEF_DOMAIN
)
8814 /* Only encountered when an unresolved symbol occurs in a
8815 context other than a function call, in which case, it is
8817 error ("Unexpected unresolved symbol, %s, during evaluation",
8818 SYMBOL_PRINT_NAME (exp
->elts
[pc
+ 2].symbol
));
8819 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
8823 (to_static_fixed_type
8824 (static_unwrap_type (SYMBOL_TYPE (exp
->elts
[pc
+ 2].symbol
))),
8830 unwrap_value (evaluate_subexp_standard
8831 (expect_type
, exp
, pos
, noside
));
8832 return ada_to_fixed_value (arg1
);
8838 /* Allocate arg vector, including space for the function to be
8839 called in argvec[0] and a terminating NULL. */
8840 nargs
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
8842 (struct value
**) alloca (sizeof (struct value
*) * (nargs
+ 2));
8844 if (exp
->elts
[*pos
].opcode
== OP_VAR_VALUE
8845 && SYMBOL_DOMAIN (exp
->elts
[pc
+ 5].symbol
) == UNDEF_DOMAIN
)
8846 error ("Unexpected unresolved symbol, %s, during evaluation",
8847 SYMBOL_PRINT_NAME (exp
->elts
[pc
+ 5].symbol
));
8850 for (tem
= 0; tem
<= nargs
; tem
+= 1)
8851 argvec
[tem
] = evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
8854 if (noside
== EVAL_SKIP
)
8858 if (ada_is_packed_array_type (desc_base_type (VALUE_TYPE (argvec
[0]))))
8859 argvec
[0] = ada_coerce_to_simple_array (argvec
[0]);
8860 else if (TYPE_CODE (VALUE_TYPE (argvec
[0])) == TYPE_CODE_REF
8861 || (TYPE_CODE (VALUE_TYPE (argvec
[0])) == TYPE_CODE_ARRAY
8862 && VALUE_LVAL (argvec
[0]) == lval_memory
))
8863 argvec
[0] = value_addr (argvec
[0]);
8865 type
= check_typedef (VALUE_TYPE (argvec
[0]));
8866 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
8868 switch (TYPE_CODE (check_typedef (TYPE_TARGET_TYPE (type
))))
8870 case TYPE_CODE_FUNC
:
8871 type
= check_typedef (TYPE_TARGET_TYPE (type
));
8873 case TYPE_CODE_ARRAY
:
8875 case TYPE_CODE_STRUCT
:
8876 if (noside
!= EVAL_AVOID_SIDE_EFFECTS
)
8877 argvec
[0] = ada_value_ind (argvec
[0]);
8878 type
= check_typedef (TYPE_TARGET_TYPE (type
));
8881 error ("cannot subscript or call something of type `%s'",
8882 ada_type_name (VALUE_TYPE (argvec
[0])));
8887 switch (TYPE_CODE (type
))
8889 case TYPE_CODE_FUNC
:
8890 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
8891 return allocate_value (TYPE_TARGET_TYPE (type
));
8892 return call_function_by_hand (argvec
[0], nargs
, argvec
+ 1);
8893 case TYPE_CODE_STRUCT
:
8897 /* Make sure to use the parallel ___XVS type if any.
8898 Otherwise, we won't be able to find the array arity
8899 and element type. */
8900 type
= ada_get_base_type (type
);
8902 arity
= ada_array_arity (type
);
8903 type
= ada_array_element_type (type
, nargs
);
8905 error ("cannot subscript or call a record");
8907 error ("wrong number of subscripts; expecting %d", arity
);
8908 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
8909 return allocate_value (ada_aligned_type (type
));
8911 unwrap_value (ada_value_subscript
8912 (argvec
[0], nargs
, argvec
+ 1));
8914 case TYPE_CODE_ARRAY
:
8915 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
8917 type
= ada_array_element_type (type
, nargs
);
8919 error ("element type of array unknown");
8921 return allocate_value (ada_aligned_type (type
));
8924 unwrap_value (ada_value_subscript
8925 (ada_coerce_to_simple_array (argvec
[0]),
8926 nargs
, argvec
+ 1));
8927 case TYPE_CODE_PTR
: /* Pointer to array */
8928 type
= to_fixed_array_type (TYPE_TARGET_TYPE (type
), NULL
, 1);
8929 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
8931 type
= ada_array_element_type (type
, nargs
);
8933 error ("element type of array unknown");
8935 return allocate_value (ada_aligned_type (type
));
8938 unwrap_value (ada_value_ptr_subscript (argvec
[0], type
,
8939 nargs
, argvec
+ 1));
8942 error ("Internal error in evaluate_subexp");
8947 struct value
*array
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
8948 struct value
*low_bound_val
=
8949 evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
8950 LONGEST low_bound
= pos_atr (low_bound_val
);
8952 = pos_atr (evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
));
8953 if (noside
== EVAL_SKIP
)
8956 /* If this is a reference type or a pointer type, and
8957 the target type has an XVS parallel type, then get
8958 the real target type. */
8959 if (TYPE_CODE (VALUE_TYPE (array
)) == TYPE_CODE_REF
8960 || TYPE_CODE (VALUE_TYPE (array
)) == TYPE_CODE_PTR
)
8961 TYPE_TARGET_TYPE (VALUE_TYPE (array
)) =
8962 ada_get_base_type (TYPE_TARGET_TYPE (VALUE_TYPE (array
)));
8964 /* If this is a reference to an aligner type, then remove all
8966 if (TYPE_CODE (VALUE_TYPE (array
)) == TYPE_CODE_REF
8967 && ada_is_aligner_type (TYPE_TARGET_TYPE (VALUE_TYPE (array
))))
8968 TYPE_TARGET_TYPE (VALUE_TYPE (array
)) =
8969 ada_aligned_type (TYPE_TARGET_TYPE (VALUE_TYPE (array
)));
8971 if (ada_is_packed_array_type (VALUE_TYPE (array
)))
8972 error ("cannot slice a packed array");
8974 /* If this is a reference to an array or an array lvalue,
8975 convert to a pointer. */
8976 if (TYPE_CODE (VALUE_TYPE (array
)) == TYPE_CODE_REF
8977 || (TYPE_CODE (VALUE_TYPE (array
)) == TYPE_CODE_ARRAY
8978 && VALUE_LVAL (array
) == lval_memory
))
8979 array
= value_addr (array
);
8981 if (noside
== EVAL_AVOID_SIDE_EFFECTS
&&
8982 ada_is_array_descriptor_type (check_typedef (VALUE_TYPE (array
))))
8984 /* Try dereferencing the array, in case it is an access
8986 struct type
*arrType
= ada_type_of_array (array
, 0);
8987 if (arrType
!= NULL
)
8988 array
= value_at_lazy (arrType
, 0, NULL
);
8991 array
= ada_coerce_to_simple_array_ptr (array
);
8993 /* When EVAL_AVOID_SIDE_EFFECTS, we may get the bounds wrong,
8994 but only in contexts where the value is not being requested
8996 if (TYPE_CODE (VALUE_TYPE (array
)) == TYPE_CODE_PTR
)
8998 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
8999 return ada_value_ind (array
);
9000 else if (high_bound
< low_bound
)
9001 return empty_array (TYPE_TARGET_TYPE (VALUE_TYPE (array
)),
9005 struct type
*arr_type0
=
9006 to_fixed_array_type (TYPE_TARGET_TYPE (VALUE_TYPE (array
)),
9008 struct value
*item0
=
9009 ada_value_ptr_subscript (array
, arr_type0
, 1,
9011 struct value
*slice
=
9012 value_repeat (item0
, high_bound
- low_bound
+ 1);
9013 struct type
*arr_type1
= VALUE_TYPE (slice
);
9014 TYPE_LOW_BOUND (TYPE_INDEX_TYPE (arr_type1
)) = low_bound
;
9015 TYPE_HIGH_BOUND (TYPE_INDEX_TYPE (arr_type1
)) += low_bound
;
9019 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
9021 else if (high_bound
< low_bound
)
9022 return empty_array (VALUE_TYPE (array
), low_bound
);
9024 return value_slice (array
, low_bound
, high_bound
- low_bound
+ 1);
9029 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
9030 type
= exp
->elts
[pc
+ 1].type
;
9032 if (noside
== EVAL_SKIP
)
9035 switch (TYPE_CODE (type
))
9038 lim_warning ("Membership test incompletely implemented; "
9039 "always returns true", 0);
9040 return value_from_longest (builtin_type_int
, (LONGEST
) 1);
9042 case TYPE_CODE_RANGE
:
9043 arg2
= value_from_longest (builtin_type_int
,
9044 TYPE_LOW_BOUND (type
));
9045 arg3
= value_from_longest (builtin_type_int
,
9046 TYPE_HIGH_BOUND (type
));
9048 value_from_longest (builtin_type_int
,
9049 (value_less (arg1
, arg3
)
9050 || value_equal (arg1
, arg3
))
9051 && (value_less (arg2
, arg1
)
9052 || value_equal (arg2
, arg1
)));
9055 case BINOP_IN_BOUNDS
:
9057 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
9058 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
9060 if (noside
== EVAL_SKIP
)
9063 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
9064 return value_zero (builtin_type_int
, not_lval
);
9066 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
9068 if (tem
< 1 || tem
> ada_array_arity (VALUE_TYPE (arg2
)))
9069 error ("invalid dimension number to '%s", "range");
9071 arg3
= ada_array_bound (arg2
, tem
, 1);
9072 arg2
= ada_array_bound (arg2
, tem
, 0);
9075 value_from_longest (builtin_type_int
,
9076 (value_less (arg1
, arg3
)
9077 || value_equal (arg1
, arg3
))
9078 && (value_less (arg2
, arg1
)
9079 || value_equal (arg2
, arg1
)));
9081 case TERNOP_IN_RANGE
:
9082 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
9083 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
9084 arg3
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
9086 if (noside
== EVAL_SKIP
)
9090 value_from_longest (builtin_type_int
,
9091 (value_less (arg1
, arg3
)
9092 || value_equal (arg1
, arg3
))
9093 && (value_less (arg2
, arg1
)
9094 || value_equal (arg2
, arg1
)));
9100 struct type
*type_arg
;
9101 if (exp
->elts
[*pos
].opcode
== OP_TYPE
)
9103 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
9105 type_arg
= exp
->elts
[pc
+ 2].type
;
9109 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
9113 if (exp
->elts
[*pos
].opcode
!= OP_LONG
)
9114 error ("illegal operand to '%s", ada_attribute_name (op
));
9115 tem
= longest_to_int (exp
->elts
[*pos
+ 2].longconst
);
9118 if (noside
== EVAL_SKIP
)
9121 if (type_arg
== NULL
)
9123 arg1
= ada_coerce_ref (arg1
);
9125 if (ada_is_packed_array_type (VALUE_TYPE (arg1
)))
9126 arg1
= ada_coerce_to_simple_array (arg1
);
9128 if (tem
< 1 || tem
> ada_array_arity (VALUE_TYPE (arg1
)))
9129 error ("invalid dimension number to '%s",
9130 ada_attribute_name (op
));
9132 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
9134 type
= ada_index_type (VALUE_TYPE (arg1
), tem
);
9137 ("attempt to take bound of something that is not an array");
9138 return allocate_value (type
);
9143 default: /* Should never happen. */
9144 error ("unexpected attribute encountered");
9146 return ada_array_bound (arg1
, tem
, 0);
9148 return ada_array_bound (arg1
, tem
, 1);
9150 return ada_array_length (arg1
, tem
);
9153 else if (discrete_type_p (type_arg
))
9155 struct type
*range_type
;
9156 char *name
= ada_type_name (type_arg
);
9158 if (name
!= NULL
&& TYPE_CODE (type_arg
) != TYPE_CODE_ENUM
)
9160 to_fixed_range_type (name
, NULL
, TYPE_OBJFILE (type_arg
));
9161 if (range_type
== NULL
)
9162 range_type
= type_arg
;
9166 error ("unexpected attribute encountered");
9168 return discrete_type_low_bound (range_type
);
9170 return discrete_type_high_bound (range_type
);
9172 error ("the 'length attribute applies only to array types");
9175 else if (TYPE_CODE (type_arg
) == TYPE_CODE_FLT
)
9176 error ("unimplemented type attribute");
9181 if (ada_is_packed_array_type (type_arg
))
9182 type_arg
= decode_packed_array_type (type_arg
);
9184 if (tem
< 1 || tem
> ada_array_arity (type_arg
))
9185 error ("invalid dimension number to '%s",
9186 ada_attribute_name (op
));
9188 type
= ada_index_type (type_arg
, tem
);
9190 error ("attempt to take bound of something that is not an array");
9191 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
9192 return allocate_value (type
);
9197 error ("unexpected attribute encountered");
9199 low
= ada_array_bound_from_type (type_arg
, tem
, 0, &type
);
9200 return value_from_longest (type
, low
);
9203 ada_array_bound_from_type (type_arg
, tem
, 1, &type
);
9204 return value_from_longest (type
, high
);
9206 low
= ada_array_bound_from_type (type_arg
, tem
, 0, &type
);
9207 high
= ada_array_bound_from_type (type_arg
, tem
, 1, NULL
);
9208 return value_from_longest (type
, high
- low
+ 1);
9214 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
9215 if (noside
== EVAL_SKIP
)
9218 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
9219 return value_zero (ada_tag_type (arg1
), not_lval
);
9221 return ada_value_tag (arg1
);
9225 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
9226 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
9227 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
9228 if (noside
== EVAL_SKIP
)
9230 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
9231 return value_zero (VALUE_TYPE (arg1
), not_lval
);
9233 return value_binop (arg1
, arg2
,
9234 op
== OP_ATR_MIN
? BINOP_MIN
: BINOP_MAX
);
9236 case OP_ATR_MODULUS
:
9238 struct type
*type_arg
= exp
->elts
[pc
+ 2].type
;
9239 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
9241 if (noside
== EVAL_SKIP
)
9244 if (!ada_is_modular_type (type_arg
))
9245 error ("'modulus must be applied to modular type");
9247 return value_from_longest (TYPE_TARGET_TYPE (type_arg
),
9248 ada_modulus (type_arg
));
9253 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
9254 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
9255 if (noside
== EVAL_SKIP
)
9257 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
9258 return value_zero (builtin_type_ada_int
, not_lval
);
9260 return value_pos_atr (arg1
);
9263 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
9264 if (noside
== EVAL_SKIP
)
9266 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
9267 return value_zero (builtin_type_ada_int
, not_lval
);
9269 return value_from_longest (builtin_type_ada_int
,
9271 * TYPE_LENGTH (VALUE_TYPE (arg1
)));
9274 evaluate_subexp (NULL_TYPE
, exp
, pos
, EVAL_SKIP
);
9275 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
9276 type
= exp
->elts
[pc
+ 2].type
;
9277 if (noside
== EVAL_SKIP
)
9279 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
9280 return value_zero (type
, not_lval
);
9282 return value_val_atr (type
, arg1
);
9285 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
9286 arg2
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
9287 if (noside
== EVAL_SKIP
)
9289 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
9290 return value_zero (VALUE_TYPE (arg1
), not_lval
);
9292 return value_binop (arg1
, arg2
, op
);
9295 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
9296 if (noside
== EVAL_SKIP
)
9302 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
9303 if (noside
== EVAL_SKIP
)
9305 if (value_less (arg1
, value_zero (VALUE_TYPE (arg1
), not_lval
)))
9306 return value_neg (arg1
);
9311 if (expect_type
&& TYPE_CODE (expect_type
) == TYPE_CODE_PTR
)
9312 expect_type
= TYPE_TARGET_TYPE (check_typedef (expect_type
));
9313 arg1
= evaluate_subexp (expect_type
, exp
, pos
, noside
);
9314 if (noside
== EVAL_SKIP
)
9316 type
= check_typedef (VALUE_TYPE (arg1
));
9317 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
9319 if (ada_is_array_descriptor_type (type
))
9320 /* GDB allows dereferencing GNAT array descriptors. */
9322 struct type
*arrType
= ada_type_of_array (arg1
, 0);
9323 if (arrType
== NULL
)
9324 error ("Attempt to dereference null array pointer.");
9325 return value_at_lazy (arrType
, 0, NULL
);
9327 else if (TYPE_CODE (type
) == TYPE_CODE_PTR
9328 || TYPE_CODE (type
) == TYPE_CODE_REF
9329 /* In C you can dereference an array to get the 1st elt. */
9330 || TYPE_CODE (type
) == TYPE_CODE_ARRAY
)
9333 (to_static_fixed_type
9334 (ada_aligned_type (check_typedef (TYPE_TARGET_TYPE (type
)))),
9336 else if (TYPE_CODE (type
) == TYPE_CODE_INT
)
9337 /* GDB allows dereferencing an int. */
9338 return value_zero (builtin_type_int
, lval_memory
);
9340 error ("Attempt to take contents of a non-pointer value.");
9342 arg1
= ada_coerce_ref (arg1
); /* FIXME: What is this for?? */
9343 type
= check_typedef (VALUE_TYPE (arg1
));
9345 if (ada_is_array_descriptor_type (type
))
9346 /* GDB allows dereferencing GNAT array descriptors. */
9347 return ada_coerce_to_simple_array (arg1
);
9349 return ada_value_ind (arg1
);
9351 case STRUCTOP_STRUCT
:
9352 tem
= longest_to_int (exp
->elts
[pc
+ 1].longconst
);
9353 (*pos
) += 3 + BYTES_TO_EXP_ELEM (tem
+ 1);
9354 arg1
= evaluate_subexp (NULL_TYPE
, exp
, pos
, noside
);
9355 if (noside
== EVAL_SKIP
)
9357 if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
9359 struct type
*type1
= VALUE_TYPE (arg1
);
9360 if (ada_is_tagged_type (type1
, 1))
9362 type
= ada_lookup_struct_elt_type (type1
,
9363 &exp
->elts
[pc
+ 2].string
,
9366 /* In this case, we assume that the field COULD exist
9367 in some extension of the type. Return an object of
9368 "type" void, which will match any formal
9369 (see ada_type_match). */
9370 return value_zero (builtin_type_void
, lval_memory
);
9373 type
= ada_lookup_struct_elt_type (type1
, &exp
->elts
[pc
+ 2].string
,
9376 return value_zero (ada_aligned_type (type
), lval_memory
);
9380 ada_to_fixed_value (unwrap_value
9381 (ada_value_struct_elt
9382 (arg1
, &exp
->elts
[pc
+ 2].string
, "record")));
9384 /* The value is not supposed to be used. This is here to make it
9385 easier to accommodate expressions that contain types. */
9387 if (noside
== EVAL_SKIP
)
9389 else if (noside
== EVAL_AVOID_SIDE_EFFECTS
)
9390 return allocate_value (builtin_type_void
);
9392 error ("Attempt to use a type name as an expression");
9396 return value_from_longest (builtin_type_long
, (LONGEST
) 1);
9402 /* If TYPE encodes an Ada fixed-point type, return the suffix of the
9403 type name that encodes the 'small and 'delta information.
9404 Otherwise, return NULL. */
9407 fixed_type_info (struct type
*type
)
9409 const char *name
= ada_type_name (type
);
9410 enum type_code code
= (type
== NULL
) ? TYPE_CODE_UNDEF
: TYPE_CODE (type
);
9412 if ((code
== TYPE_CODE_INT
|| code
== TYPE_CODE_RANGE
) && name
!= NULL
)
9414 const char *tail
= strstr (name
, "___XF_");
9420 else if (code
== TYPE_CODE_RANGE
&& TYPE_TARGET_TYPE (type
) != type
)
9421 return fixed_type_info (TYPE_TARGET_TYPE (type
));
9426 /* Returns non-zero iff TYPE represents an Ada fixed-point type. */
9429 ada_is_fixed_point_type (struct type
*type
)
9431 return fixed_type_info (type
) != NULL
;
9434 /* Return non-zero iff TYPE represents a System.Address type. */
9437 ada_is_system_address_type (struct type
*type
)
9439 return (TYPE_NAME (type
)
9440 && strcmp (TYPE_NAME (type
), "system__address") == 0);
9443 /* Assuming that TYPE is the representation of an Ada fixed-point
9444 type, return its delta, or -1 if the type is malformed and the
9445 delta cannot be determined. */
9448 ada_delta (struct type
*type
)
9450 const char *encoding
= fixed_type_info (type
);
9453 if (sscanf (encoding
, "_%ld_%ld", &num
, &den
) < 2)
9456 return (DOUBLEST
) num
/ (DOUBLEST
) den
;
9459 /* Assuming that ada_is_fixed_point_type (TYPE), return the scaling
9460 factor ('SMALL value) associated with the type. */
9463 scaling_factor (struct type
*type
)
9465 const char *encoding
= fixed_type_info (type
);
9466 unsigned long num0
, den0
, num1
, den1
;
9469 n
= sscanf (encoding
, "_%lu_%lu_%lu_%lu", &num0
, &den0
, &num1
, &den1
);
9474 return (DOUBLEST
) num1
/ (DOUBLEST
) den1
;
9476 return (DOUBLEST
) num0
/ (DOUBLEST
) den0
;
9480 /* Assuming that X is the representation of a value of fixed-point
9481 type TYPE, return its floating-point equivalent. */
9484 ada_fixed_to_float (struct type
*type
, LONGEST x
)
9486 return (DOUBLEST
) x
*scaling_factor (type
);
9489 /* The representation of a fixed-point value of type TYPE
9490 corresponding to the value X. */
9493 ada_float_to_fixed (struct type
*type
, DOUBLEST x
)
9495 return (LONGEST
) (x
/ scaling_factor (type
) + 0.5);
9499 /* VAX floating formats */
9501 /* Non-zero iff TYPE represents one of the special VAX floating-point
9505 ada_is_vax_floating_type (struct type
*type
)
9508 (ada_type_name (type
) == NULL
) ? 0 : strlen (ada_type_name (type
));
9511 && (TYPE_CODE (type
) == TYPE_CODE_INT
9512 || TYPE_CODE (type
) == TYPE_CODE_RANGE
)
9513 && strncmp (ada_type_name (type
) + name_len
- 6, "___XF", 5) == 0;
9516 /* The type of special VAX floating-point type this is, assuming
9517 ada_is_vax_floating_point. */
9520 ada_vax_float_type_suffix (struct type
*type
)
9522 return ada_type_name (type
)[strlen (ada_type_name (type
)) - 1];
9525 /* A value representing the special debugging function that outputs
9526 VAX floating-point values of the type represented by TYPE. Assumes
9527 ada_is_vax_floating_type (TYPE). */
9530 ada_vax_float_print_function (struct type
*type
)
9532 switch (ada_vax_float_type_suffix (type
))
9535 return get_var_value ("DEBUG_STRING_F", 0);
9537 return get_var_value ("DEBUG_STRING_D", 0);
9539 return get_var_value ("DEBUG_STRING_G", 0);
9541 error ("invalid VAX floating-point type");
9548 /* Scan STR beginning at position K for a discriminant name, and
9549 return the value of that discriminant field of DVAL in *PX. If
9550 PNEW_K is not null, put the position of the character beyond the
9551 name scanned in *PNEW_K. Return 1 if successful; return 0 and do
9552 not alter *PX and *PNEW_K if unsuccessful. */
9555 scan_discrim_bound (char *str
, int k
, struct value
*dval
, LONGEST
* px
,
9558 static char *bound_buffer
= NULL
;
9559 static size_t bound_buffer_len
= 0;
9562 struct value
*bound_val
;
9564 if (dval
== NULL
|| str
== NULL
|| str
[k
] == '\0')
9567 pend
= strstr (str
+ k
, "__");
9571 k
+= strlen (bound
);
9575 GROW_VECT (bound_buffer
, bound_buffer_len
, pend
- (str
+ k
) + 1);
9576 bound
= bound_buffer
;
9577 strncpy (bound_buffer
, str
+ k
, pend
- (str
+ k
));
9578 bound
[pend
- (str
+ k
)] = '\0';
9582 bound_val
= ada_search_struct_field (bound
, dval
, 0, VALUE_TYPE (dval
));
9583 if (bound_val
== NULL
)
9586 *px
= value_as_long (bound_val
);
9592 /* Value of variable named NAME in the current environment. If
9593 no such variable found, then if ERR_MSG is null, returns 0, and
9594 otherwise causes an error with message ERR_MSG. */
9596 static struct value
*
9597 get_var_value (char *name
, char *err_msg
)
9599 struct ada_symbol_info
*syms
;
9602 nsyms
= ada_lookup_symbol_list (name
, get_selected_block (0), VAR_DOMAIN
,
9607 if (err_msg
== NULL
)
9610 error ("%s", err_msg
);
9613 return value_of_variable (syms
[0].sym
, syms
[0].block
);
9616 /* Value of integer variable named NAME in the current environment. If
9617 no such variable found, returns 0, and sets *FLAG to 0. If
9618 successful, sets *FLAG to 1. */
9621 get_int_var_value (char *name
, int *flag
)
9623 struct value
*var_val
= get_var_value (name
, 0);
9635 return value_as_long (var_val
);
9640 /* Return a range type whose base type is that of the range type named
9641 NAME in the current environment, and whose bounds are calculated
9642 from NAME according to the GNAT range encoding conventions.
9643 Extract discriminant values, if needed, from DVAL. If a new type
9644 must be created, allocate in OBJFILE's space. The bounds
9645 information, in general, is encoded in NAME, the base type given in
9646 the named range type. */
9648 static struct type
*
9649 to_fixed_range_type (char *name
, struct value
*dval
, struct objfile
*objfile
)
9651 struct type
*raw_type
= ada_find_any_type (name
);
9652 struct type
*base_type
;
9655 if (raw_type
== NULL
)
9656 base_type
= builtin_type_int
;
9657 else if (TYPE_CODE (raw_type
) == TYPE_CODE_RANGE
)
9658 base_type
= TYPE_TARGET_TYPE (raw_type
);
9660 base_type
= raw_type
;
9662 subtype_info
= strstr (name
, "___XD");
9663 if (subtype_info
== NULL
)
9667 static char *name_buf
= NULL
;
9668 static size_t name_len
= 0;
9669 int prefix_len
= subtype_info
- name
;
9675 GROW_VECT (name_buf
, name_len
, prefix_len
+ 5);
9676 strncpy (name_buf
, name
, prefix_len
);
9677 name_buf
[prefix_len
] = '\0';
9680 bounds_str
= strchr (subtype_info
, '_');
9683 if (*subtype_info
== 'L')
9685 if (!ada_scan_number (bounds_str
, n
, &L
, &n
)
9686 && !scan_discrim_bound (bounds_str
, n
, dval
, &L
, &n
))
9688 if (bounds_str
[n
] == '_')
9690 else if (bounds_str
[n
] == '.') /* FIXME? SGI Workshop kludge. */
9697 strcpy (name_buf
+ prefix_len
, "___L");
9698 L
= get_int_var_value (name_buf
, &ok
);
9701 lim_warning ("Unknown lower bound, using 1.", 1);
9706 if (*subtype_info
== 'U')
9708 if (!ada_scan_number (bounds_str
, n
, &U
, &n
)
9709 && !scan_discrim_bound (bounds_str
, n
, dval
, &U
, &n
))
9715 strcpy (name_buf
+ prefix_len
, "___U");
9716 U
= get_int_var_value (name_buf
, &ok
);
9719 lim_warning ("Unknown upper bound, using %ld.", (long) L
);
9724 if (objfile
== NULL
)
9725 objfile
= TYPE_OBJFILE (base_type
);
9726 type
= create_range_type (alloc_type (objfile
), base_type
, L
, U
);
9727 TYPE_NAME (type
) = name
;
9732 /* True iff NAME is the name of a range type. */
9735 ada_is_range_type_name (const char *name
)
9737 return (name
!= NULL
&& strstr (name
, "___XD"));
9743 /* True iff TYPE is an Ada modular type. */
9746 ada_is_modular_type (struct type
*type
)
9748 struct type
*subranged_type
= base_type (type
);
9750 return (subranged_type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_RANGE
9751 && TYPE_CODE (subranged_type
) != TYPE_CODE_ENUM
9752 && TYPE_UNSIGNED (subranged_type
));
9755 /* Assuming ada_is_modular_type (TYPE), the modulus of TYPE. */
9758 ada_modulus (struct type
* type
)
9760 return TYPE_HIGH_BOUND (type
) + 1;
9764 /* Information about operators given special treatment in functions
9766 /* Format: OP_DEFN (<operator>, <operator length>, <# args>, <binop>). */
9768 #define ADA_OPERATORS \
9769 OP_DEFN (OP_VAR_VALUE, 4, 0, 0) \
9770 OP_DEFN (BINOP_IN_BOUNDS, 3, 2, 0) \
9771 OP_DEFN (TERNOP_IN_RANGE, 1, 3, 0) \
9772 OP_DEFN (OP_ATR_FIRST, 1, 2, 0) \
9773 OP_DEFN (OP_ATR_LAST, 1, 2, 0) \
9774 OP_DEFN (OP_ATR_LENGTH, 1, 2, 0) \
9775 OP_DEFN (OP_ATR_IMAGE, 1, 2, 0) \
9776 OP_DEFN (OP_ATR_MAX, 1, 3, 0) \
9777 OP_DEFN (OP_ATR_MIN, 1, 3, 0) \
9778 OP_DEFN (OP_ATR_MODULUS, 1, 1, 0) \
9779 OP_DEFN (OP_ATR_POS, 1, 2, 0) \
9780 OP_DEFN (OP_ATR_SIZE, 1, 1, 0) \
9781 OP_DEFN (OP_ATR_TAG, 1, 1, 0) \
9782 OP_DEFN (OP_ATR_VAL, 1, 2, 0) \
9783 OP_DEFN (UNOP_QUAL, 3, 1, 0) \
9784 OP_DEFN (UNOP_IN_RANGE, 3, 1, 0)
9787 ada_operator_length (struct expression
*exp
, int pc
, int *oplenp
, int *argsp
)
9789 switch (exp
->elts
[pc
- 1].opcode
)
9792 operator_length_standard (exp
, pc
, oplenp
, argsp
);
9795 #define OP_DEFN(op, len, args, binop) \
9796 case op: *oplenp = len; *argsp = args; break;
9803 ada_op_name (enum exp_opcode opcode
)
9808 return op_name_standard (opcode
);
9809 #define OP_DEFN(op, len, args, binop) case op: return #op;
9815 /* As for operator_length, but assumes PC is pointing at the first
9816 element of the operator, and gives meaningful results only for the
9817 Ada-specific operators. */
9820 ada_forward_operator_length (struct expression
*exp
, int pc
,
9821 int *oplenp
, int *argsp
)
9823 switch (exp
->elts
[pc
].opcode
)
9826 *oplenp
= *argsp
= 0;
9828 #define OP_DEFN(op, len, args, binop) \
9829 case op: *oplenp = len; *argsp = args; break;
9836 ada_dump_subexp_body (struct expression
*exp
, struct ui_file
*stream
, int elt
)
9838 enum exp_opcode op
= exp
->elts
[elt
].opcode
;
9843 ada_forward_operator_length (exp
, elt
, &oplen
, &nargs
);
9847 /* Ada attributes ('Foo). */
9854 case OP_ATR_MODULUS
:
9863 fprintf_filtered (stream
, "Type @");
9864 gdb_print_host_address (exp
->elts
[pc
+ 1].type
, stream
);
9865 fprintf_filtered (stream
, " (");
9866 type_print (exp
->elts
[pc
+ 1].type
, NULL
, stream
, 0);
9867 fprintf_filtered (stream
, ")");
9869 case BINOP_IN_BOUNDS
:
9870 fprintf_filtered (stream
, " (%d)", (int) exp
->elts
[pc
+ 2].longconst
);
9872 case TERNOP_IN_RANGE
:
9876 return dump_subexp_body_standard (exp
, stream
, elt
);
9880 for (i
= 0; i
< nargs
; i
+= 1)
9881 elt
= dump_subexp (exp
, stream
, elt
);
9886 /* The Ada extension of print_subexp (q.v.). */
9889 ada_print_subexp (struct expression
*exp
, int *pos
,
9890 struct ui_file
*stream
, enum precedence prec
)
9894 enum exp_opcode op
= exp
->elts
[pc
].opcode
;
9896 ada_forward_operator_length (exp
, pc
, &oplen
, &nargs
);
9901 print_subexp_standard (exp
, pos
, stream
, prec
);
9906 fputs_filtered (SYMBOL_NATURAL_NAME (exp
->elts
[pc
+ 2].symbol
), stream
);
9909 case BINOP_IN_BOUNDS
:
9911 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
9912 fputs_filtered (" in ", stream
);
9913 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
9914 fputs_filtered ("'range", stream
);
9915 if (exp
->elts
[pc
+ 1].longconst
> 1)
9916 fprintf_filtered (stream
, "(%ld)", (long) exp
->elts
[pc
+ 1].longconst
);
9919 case TERNOP_IN_RANGE
:
9921 if (prec
>= PREC_EQUAL
)
9922 fputs_filtered ("(", stream
);
9923 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
9924 fputs_filtered (" in ", stream
);
9925 print_subexp (exp
, pos
, stream
, PREC_EQUAL
);
9926 fputs_filtered (" .. ", stream
);
9927 print_subexp (exp
, pos
, stream
, PREC_EQUAL
);
9928 if (prec
>= PREC_EQUAL
)
9929 fputs_filtered (")", stream
);
9938 case OP_ATR_MODULUS
:
9944 if (exp
->elts
[*pos
].opcode
== OP_TYPE
)
9946 if (TYPE_CODE (exp
->elts
[*pos
+ 1].type
) != TYPE_CODE_VOID
)
9947 LA_PRINT_TYPE (exp
->elts
[*pos
+ 1].type
, "", stream
, 0, 0);
9951 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
9952 fprintf_filtered (stream
, "'%s", ada_attribute_name (op
));
9956 for (tem
= 1; tem
< nargs
; tem
+= 1)
9958 fputs_filtered ( (tem
== 1) ? " (" : ", ", stream
);
9959 print_subexp (exp
, pos
, stream
, PREC_ABOVE_COMMA
);
9961 fputs_filtered (")", stream
);
9967 type_print (exp
->elts
[pc
+ 1].type
, "", stream
, 0);
9968 fputs_filtered ("'(", stream
);
9969 print_subexp (exp
, pos
, stream
, PREC_PREFIX
);
9970 fputs_filtered (")", stream
);
9975 print_subexp (exp
, pos
, stream
, PREC_SUFFIX
);
9976 fputs_filtered (" in ", stream
);
9977 LA_PRINT_TYPE (exp
->elts
[pc
+ 1].type
, "", stream
, 1, 0);
9982 /* Table mapping opcodes into strings for printing operators
9983 and precedences of the operators. */
9985 static const struct op_print ada_op_print_tab
[] = {
9986 {":=", BINOP_ASSIGN
, PREC_ASSIGN
, 1},
9987 {"or else", BINOP_LOGICAL_OR
, PREC_LOGICAL_OR
, 0},
9988 {"and then", BINOP_LOGICAL_AND
, PREC_LOGICAL_AND
, 0},
9989 {"or", BINOP_BITWISE_IOR
, PREC_BITWISE_IOR
, 0},
9990 {"xor", BINOP_BITWISE_XOR
, PREC_BITWISE_XOR
, 0},
9991 {"and", BINOP_BITWISE_AND
, PREC_BITWISE_AND
, 0},
9992 {"=", BINOP_EQUAL
, PREC_EQUAL
, 0},
9993 {"/=", BINOP_NOTEQUAL
, PREC_EQUAL
, 0},
9994 {"<=", BINOP_LEQ
, PREC_ORDER
, 0},
9995 {">=", BINOP_GEQ
, PREC_ORDER
, 0},
9996 {">", BINOP_GTR
, PREC_ORDER
, 0},
9997 {"<", BINOP_LESS
, PREC_ORDER
, 0},
9998 {">>", BINOP_RSH
, PREC_SHIFT
, 0},
9999 {"<<", BINOP_LSH
, PREC_SHIFT
, 0},
10000 {"+", BINOP_ADD
, PREC_ADD
, 0},
10001 {"-", BINOP_SUB
, PREC_ADD
, 0},
10002 {"&", BINOP_CONCAT
, PREC_ADD
, 0},
10003 {"*", BINOP_MUL
, PREC_MUL
, 0},
10004 {"/", BINOP_DIV
, PREC_MUL
, 0},
10005 {"rem", BINOP_REM
, PREC_MUL
, 0},
10006 {"mod", BINOP_MOD
, PREC_MUL
, 0},
10007 {"**", BINOP_EXP
, PREC_REPEAT
, 0},
10008 {"@", BINOP_REPEAT
, PREC_REPEAT
, 0},
10009 {"-", UNOP_NEG
, PREC_PREFIX
, 0},
10010 {"+", UNOP_PLUS
, PREC_PREFIX
, 0},
10011 {"not ", UNOP_LOGICAL_NOT
, PREC_PREFIX
, 0},
10012 {"not ", UNOP_COMPLEMENT
, PREC_PREFIX
, 0},
10013 {"abs ", UNOP_ABS
, PREC_PREFIX
, 0},
10014 {".all", UNOP_IND
, PREC_SUFFIX
, 1},
10015 {"'access", UNOP_ADDR
, PREC_SUFFIX
, 1},
10016 {"'size", OP_ATR_SIZE
, PREC_SUFFIX
, 1},
10020 /* Assorted Types and Interfaces */
10022 struct type
*builtin_type_ada_int
;
10023 struct type
*builtin_type_ada_short
;
10024 struct type
*builtin_type_ada_long
;
10025 struct type
*builtin_type_ada_long_long
;
10026 struct type
*builtin_type_ada_char
;
10027 struct type
*builtin_type_ada_float
;
10028 struct type
*builtin_type_ada_double
;
10029 struct type
*builtin_type_ada_long_double
;
10030 struct type
*builtin_type_ada_natural
;
10031 struct type
*builtin_type_ada_positive
;
10032 struct type
*builtin_type_ada_system_address
;
10034 struct type
**const (ada_builtin_types
[]) =
10036 &builtin_type_ada_int
,
10037 &builtin_type_ada_long
,
10038 &builtin_type_ada_short
,
10039 &builtin_type_ada_char
,
10040 &builtin_type_ada_float
,
10041 &builtin_type_ada_double
,
10042 &builtin_type_ada_long_long
,
10043 &builtin_type_ada_long_double
,
10044 &builtin_type_ada_natural
, &builtin_type_ada_positive
,
10045 /* The following types are carried over from C for convenience. */
10047 &builtin_type_long
,
10048 &builtin_type_short
,
10049 &builtin_type_char
,
10050 &builtin_type_float
,
10051 &builtin_type_double
,
10052 &builtin_type_long_long
,
10053 &builtin_type_void
,
10054 &builtin_type_signed_char
,
10055 &builtin_type_unsigned_char
,
10056 &builtin_type_unsigned_short
,
10057 &builtin_type_unsigned_int
,
10058 &builtin_type_unsigned_long
,
10059 &builtin_type_unsigned_long_long
,
10060 &builtin_type_long_double
,
10061 &builtin_type_complex
,
10062 &builtin_type_double_complex
,
10066 /* Not really used, but needed in the ada_language_defn. */
10069 emit_char (int c
, struct ui_file
*stream
, int quoter
)
10071 ada_emit_char (c
, stream
, quoter
, 1);
10077 warnings_issued
= 0;
10078 return ada_parse ();
10081 static const struct exp_descriptor ada_exp_descriptor
=
10084 ada_operator_length
,
10086 ada_dump_subexp_body
,
10087 ada_evaluate_subexp
10090 const struct language_defn ada_language_defn
= {
10091 "ada", /* Language name */
10096 case_sensitive_on
, /* Yes, Ada is case-insensitive, but
10097 that's not quite what this means. */
10100 ada_lookup_minimal_symbol
,
10102 &ada_exp_descriptor
,
10106 ada_printchar
, /* Print a character constant */
10107 ada_printstr
, /* Function to print string constant */
10108 emit_char
, /* Function to print single char (not used) */
10109 ada_create_fundamental_type
, /* Create fundamental type in this language */
10110 ada_print_type
, /* Print a type using appropriate syntax */
10111 ada_val_print
, /* Print a value using appropriate syntax */
10112 ada_value_print
, /* Print a top-level value */
10113 NULL
, /* Language specific skip_trampoline */
10114 NULL
, /* value_of_this */
10115 ada_lookup_symbol_nonlocal
, /* Looking up non-local symbols. */
10116 basic_lookup_transparent_type
,/* lookup_transparent_type */
10117 ada_la_decode
, /* Language specific symbol demangler */
10118 {"", "", "", ""}, /* Binary format info */
10120 {"8#%lo#", "8#", "o", "#"}, /* Octal format info */
10121 {"%ld", "", "d", ""}, /* Decimal format info */
10122 {"16#%lx#", "16#", "x", "#"}, /* Hex format info */
10124 /* Copied from c-lang.c. */
10125 {"0%lo", "0", "o", ""}, /* Octal format info */
10126 {"%ld", "", "d", ""}, /* Decimal format info */
10127 {"0x%lx", "0x", "x", ""}, /* Hex format info */
10129 ada_op_print_tab
, /* expression operators for printing */
10130 0, /* c-style arrays */
10131 1, /* String lower bound */
10132 &builtin_type_ada_char
,
10133 ada_get_gdb_completer_word_break_characters
,
10135 ada_translate_error_message
, /* Substitute Ada-specific terminology
10136 in errors and warnings. */
10142 build_ada_types (void) {
10143 builtin_type_ada_int
=
10144 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
10145 0, "integer", (struct objfile
*) NULL
);
10146 builtin_type_ada_long
=
10147 init_type (TYPE_CODE_INT
, TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
10148 0, "long_integer", (struct objfile
*) NULL
);
10149 builtin_type_ada_short
=
10150 init_type (TYPE_CODE_INT
, TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
10151 0, "short_integer", (struct objfile
*) NULL
);
10152 builtin_type_ada_char
=
10153 init_type (TYPE_CODE_INT
, TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
10154 0, "character", (struct objfile
*) NULL
);
10155 builtin_type_ada_float
=
10156 init_type (TYPE_CODE_FLT
, TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
,
10157 0, "float", (struct objfile
*) NULL
);
10158 builtin_type_ada_double
=
10159 init_type (TYPE_CODE_FLT
, TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
10160 0, "long_float", (struct objfile
*) NULL
);
10161 builtin_type_ada_long_long
=
10162 init_type (TYPE_CODE_INT
, TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
10163 0, "long_long_integer", (struct objfile
*) NULL
);
10164 builtin_type_ada_long_double
=
10165 init_type (TYPE_CODE_FLT
, TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
10166 0, "long_long_float", (struct objfile
*) NULL
);
10167 builtin_type_ada_natural
=
10168 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
10169 0, "natural", (struct objfile
*) NULL
);
10170 builtin_type_ada_positive
=
10171 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
10172 0, "positive", (struct objfile
*) NULL
);
10175 builtin_type_ada_system_address
=
10176 lookup_pointer_type (init_type (TYPE_CODE_VOID
, 1, 0, "void",
10177 (struct objfile
*) NULL
));
10178 TYPE_NAME (builtin_type_ada_system_address
) = "system__address";
10182 _initialize_ada_language (void)
10185 build_ada_types ();
10186 deprecated_register_gdbarch_swap (NULL
, 0, build_ada_types
);
10187 add_language (&ada_language_defn
);
10191 (add_set_cmd ("varsize-limit", class_support
, var_uinteger
,
10192 (char *) &varsize_limit
,
10193 "Set maximum bytes in dynamic-sized object.",
10194 &setlist
), &showlist
);
10196 varsize_limit
= 65536;
10198 obstack_init (&symbol_list_obstack
);
10199 obstack_init (&cache_space
);
10201 decoded_names_store
= htab_create_alloc_ex
10202 (256, htab_hash_string
, (int (*) (const void *, const void *)) streq
,
10203 NULL
, NULL
, xmcalloc
, xmfree
);
10206 /* Create a fundamental Ada type using default reasonable for the current
10209 Some object/debugging file formats (DWARF version 1, COFF, etc) do not
10210 define fundamental types such as "int" or "double". Others (stabs or
10211 DWARF version 2, etc) do define fundamental types. For the formats which
10212 don't provide fundamental types, gdb can create such types using this
10215 FIXME: Some compilers distinguish explicitly signed integral types
10216 (signed short, signed int, signed long) from "regular" integral types
10217 (short, int, long) in the debugging information. There is some dis-
10218 agreement as to how useful this feature is. In particular, gcc does
10219 not support this. Also, only some debugging formats allow the
10220 distinction to be passed on to a debugger. For now, we always just
10221 use "short", "int", or "long" as the type name, for both the implicit
10222 and explicitly signed types. This also makes life easier for the
10223 gdb test suite since we don't have to account for the differences
10224 in output depending upon what the compiler and debugging format
10225 support. We will probably have to re-examine the issue when gdb
10226 starts taking it's fundamental type information directly from the
10227 debugging information supplied by the compiler. fnf@cygnus.com */
10229 static struct type
*
10230 ada_create_fundamental_type (struct objfile
*objfile
, int typeid)
10232 struct type
*type
= NULL
;
10237 /* FIXME: For now, if we are asked to produce a type not in this
10238 language, create the equivalent of a C integer type with the
10239 name "<?type?>". When all the dust settles from the type
10240 reconstruction work, this should probably become an error. */
10241 type
= init_type (TYPE_CODE_INT
,
10242 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
10243 0, "<?type?>", objfile
);
10244 warning ("internal error: no Ada fundamental type %d", typeid);
10247 type
= init_type (TYPE_CODE_VOID
,
10248 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
10249 0, "void", objfile
);
10252 type
= init_type (TYPE_CODE_INT
,
10253 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
10254 0, "character", objfile
);
10256 case FT_SIGNED_CHAR
:
10257 type
= init_type (TYPE_CODE_INT
,
10258 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
10259 0, "signed char", objfile
);
10261 case FT_UNSIGNED_CHAR
:
10262 type
= init_type (TYPE_CODE_INT
,
10263 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
10264 TYPE_FLAG_UNSIGNED
, "unsigned char", objfile
);
10267 type
= init_type (TYPE_CODE_INT
,
10268 TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
10269 0, "short_integer", objfile
);
10271 case FT_SIGNED_SHORT
:
10272 type
= init_type (TYPE_CODE_INT
,
10273 TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
10274 0, "short_integer", objfile
);
10276 case FT_UNSIGNED_SHORT
:
10277 type
= init_type (TYPE_CODE_INT
,
10278 TARGET_SHORT_BIT
/ TARGET_CHAR_BIT
,
10279 TYPE_FLAG_UNSIGNED
, "unsigned short", objfile
);
10282 type
= init_type (TYPE_CODE_INT
,
10283 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
10284 0, "integer", objfile
);
10286 case FT_SIGNED_INTEGER
:
10287 type
= init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
, 0, "integer", objfile
); /* FIXME -fnf */
10289 case FT_UNSIGNED_INTEGER
:
10290 type
= init_type (TYPE_CODE_INT
,
10291 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
10292 TYPE_FLAG_UNSIGNED
, "unsigned int", objfile
);
10295 type
= init_type (TYPE_CODE_INT
,
10296 TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
10297 0, "long_integer", objfile
);
10299 case FT_SIGNED_LONG
:
10300 type
= init_type (TYPE_CODE_INT
,
10301 TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
10302 0, "long_integer", objfile
);
10304 case FT_UNSIGNED_LONG
:
10305 type
= init_type (TYPE_CODE_INT
,
10306 TARGET_LONG_BIT
/ TARGET_CHAR_BIT
,
10307 TYPE_FLAG_UNSIGNED
, "unsigned long", objfile
);
10310 type
= init_type (TYPE_CODE_INT
,
10311 TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
10312 0, "long_long_integer", objfile
);
10314 case FT_SIGNED_LONG_LONG
:
10315 type
= init_type (TYPE_CODE_INT
,
10316 TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
10317 0, "long_long_integer", objfile
);
10319 case FT_UNSIGNED_LONG_LONG
:
10320 type
= init_type (TYPE_CODE_INT
,
10321 TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
,
10322 TYPE_FLAG_UNSIGNED
, "unsigned long long", objfile
);
10325 type
= init_type (TYPE_CODE_FLT
,
10326 TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
,
10327 0, "float", objfile
);
10329 case FT_DBL_PREC_FLOAT
:
10330 type
= init_type (TYPE_CODE_FLT
,
10331 TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
10332 0, "long_float", objfile
);
10334 case FT_EXT_PREC_FLOAT
:
10335 type
= init_type (TYPE_CODE_FLT
,
10336 TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
10337 0, "long_long_float", objfile
);
10344 ada_dump_symtab (struct symtab
*s
)
10347 fprintf (stderr
, "New symtab: [\n");
10348 fprintf (stderr
, " Name: %s/%s;\n",
10349 s
->dirname
? s
->dirname
: "?", s
->filename
? s
->filename
: "?");
10350 fprintf (stderr
, " Format: %s;\n", s
->debugformat
);
10351 if (s
->linetable
!= NULL
)
10353 fprintf (stderr
, " Line table (section %d):\n", s
->block_line_section
);
10354 for (i
= 0; i
< s
->linetable
->nitems
; i
+= 1)
10356 struct linetable_entry
*e
= s
->linetable
->item
+ i
;
10357 fprintf (stderr
, " %4ld: %8lx\n", (long) e
->line
, (long) e
->pc
);
10360 fprintf (stderr
, "]\n");