1 /* Ada language support routines for GDB, the GNU debugger. Copyright
2 1992, 1993, 1994, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
29 #include "expression.h"
30 #include "parser-defs.h"
36 #include "breakpoint.h"
43 struct cleanup* unresolved_names;
45 void extract_string (CORE_ADDR addr, char *buf);
47 static struct type * ada_create_fundamental_type (struct objfile *, int);
49 static void modify_general_field (char *, LONGEST, int, int);
51 static struct type* desc_base_type (struct type*);
53 static struct type* desc_bounds_type (struct type*);
55 static struct value* desc_bounds (struct value*);
57 static int fat_pntr_bounds_bitpos (struct type*);
59 static int fat_pntr_bounds_bitsize (struct type*);
61 static struct type* desc_data_type (struct type*);
63 static struct value* desc_data (struct value*);
65 static int fat_pntr_data_bitpos (struct type*);
67 static int fat_pntr_data_bitsize (struct type*);
69 static struct value* desc_one_bound (struct value*, int, int);
71 static int desc_bound_bitpos (struct type*, int, int);
73 static int desc_bound_bitsize (struct type*, int, int);
75 static struct type* desc_index_type (struct type*, int);
77 static int desc_arity (struct type*);
79 static int ada_type_match (struct type*, struct type*, int);
81 static int ada_args_match (struct symbol*, struct value**, int);
83 static struct value* place_on_stack (struct value*, CORE_ADDR*);
85 static struct value* convert_actual (struct value*, struct type*, CORE_ADDR*);
87 static struct value* make_array_descriptor (struct type*, struct value*, CORE_ADDR*);
89 static void ada_add_block_symbols (struct block*, const char*,
90 namespace_enum, struct objfile*, int);
92 static void fill_in_ada_prototype (struct symbol*);
94 static int is_nonfunction (struct symbol**, int);
96 static void add_defn_to_vec (struct symbol*, struct block*);
98 static struct partial_symbol*
99 ada_lookup_partial_symbol (struct partial_symtab*, const char*,
100 int, namespace_enum, int);
102 static struct symtab* symtab_for_sym (struct symbol*);
104 static struct value* ada_resolve_subexp (struct expression**, int*, int, struct type*);
106 static void replace_operator_with_call (struct expression**, int, int, int,
107 struct symbol*, struct block*);
109 static int possible_user_operator_p (enum exp_opcode, struct value**);
111 static const char* ada_op_name (enum exp_opcode);
113 static int numeric_type_p (struct type*);
115 static int integer_type_p (struct type*);
117 static int scalar_type_p (struct type*);
119 static int discrete_type_p (struct type*);
121 static char* extended_canonical_line_spec (struct symtab_and_line, const char*);
123 static struct value* evaluate_subexp (struct type*, struct expression*, int*, enum noside);
125 static struct value* evaluate_subexp_type (struct expression*, int*);
127 static struct type * ada_create_fundamental_type (struct objfile*, int);
129 static int is_dynamic_field (struct type *, int);
132 to_fixed_variant_branch_type (struct type*, char*, CORE_ADDR, struct value*);
134 static struct type* to_fixed_range_type (char*, struct value*, struct objfile*);
136 static struct type* to_static_fixed_type (struct type*);
138 static struct value* unwrap_value (struct value*);
140 static struct type* packed_array_type (struct type*, long*);
142 static struct type* decode_packed_array_type (struct type*);
144 static struct value* decode_packed_array (struct value*);
146 static struct value* value_subscript_packed (struct value*, int, struct value**);
148 static struct value* coerce_unspec_val_to_type (struct value*, long, struct type*);
150 static struct value* get_var_value (char*, char*);
152 static int lesseq_defined_than (struct symbol*, struct symbol*);
154 static int equiv_types (struct type*, struct type*);
156 static int is_name_suffix (const char*);
158 static int wild_match (const char*, int, const char*);
160 static struct symtabs_and_lines find_sal_from_funcs_and_line (const char*, int, struct symbol**, int);
163 find_line_in_linetable (struct linetable*, int, struct symbol**, int, int*);
165 static int find_next_line_in_linetable (struct linetable*, int, int, int);
167 static struct symtabs_and_lines all_sals_for_line (const char*, int, char***);
169 static void read_all_symtabs (const char*);
171 static int is_plausible_func_for_line (struct symbol*, int);
173 static struct value* ada_coerce_ref (struct value*);
175 static struct value* value_pos_atr (struct value*);
177 static struct value* value_val_atr (struct type*, struct value*);
179 static struct symbol* standard_lookup (const char*, namespace_enum);
181 extern void markTimeStart (int index);
182 extern void markTimeStop (int index);
186 /* Maximum-sized dynamic type. */
187 static unsigned int varsize_limit;
189 static const char* ada_completer_word_break_characters =
190 " \t\n!@#$%^&*()+=|~`}{[]\";:?/,-";
192 /* The name of the symbol to use to get the name of the main subprogram */
193 #define ADA_MAIN_PROGRAM_SYMBOL_NAME "__gnat_ada_main_program_name"
199 * read the string located at ADDR from the inferior and store the
203 extract_string (CORE_ADDR addr, char *buf)
207 /* Loop, reading one byte at a time, until we reach the '\000'
208 end-of-string marker */
211 target_read_memory (addr + char_index * sizeof (char),
212 buf + char_index * sizeof (char),
216 while (buf[char_index - 1] != '\000');
219 /* Assuming *OLD_VECT points to an array of *SIZE objects of size
220 ELEMENT_SIZE, grow it to contain at least MIN_SIZE objects,
221 updating *OLD_VECT and *SIZE as necessary. */
224 grow_vect (old_vect, size, min_size, element_size)
230 if (*size < min_size) {
232 if (*size < min_size)
234 *old_vect = xrealloc (*old_vect, *size * element_size);
238 /* True (non-zero) iff TARGET matches FIELD_NAME up to any trailing
239 suffix of FIELD_NAME beginning "___" */
242 field_name_match (field_name, target)
243 const char *field_name;
246 int len = strlen (target);
248 STREQN (field_name, target, len)
249 && (field_name[len] == '\0'
250 || (STREQN (field_name + len, "___", 3)
251 && ! STREQ (field_name + strlen (field_name) - 6, "___XVN")));
255 /* The length of the prefix of NAME prior to any "___" suffix. */
258 ada_name_prefix_len (name)
265 const char* p = strstr (name, "___");
267 return strlen (name);
273 /* SUFFIX is a suffix of STR. False if STR is null. */
275 is_suffix (const char* str, const char* suffix)
281 len2 = strlen (suffix);
282 return (len1 >= len2 && STREQ (str + len1 - len2, suffix));
285 /* Create a value of type TYPE whose contents come from VALADDR, if it
286 * is non-null, and whose memory address (in the inferior) is
289 value_from_contents_and_address (type, valaddr, address)
294 struct value* v = allocate_value (type);
298 memcpy (VALUE_CONTENTS_RAW (v), valaddr, TYPE_LENGTH (type));
299 VALUE_ADDRESS (v) = address;
301 VALUE_LVAL (v) = lval_memory;
305 /* The contents of value VAL, beginning at offset OFFSET, treated as a
306 value of type TYPE. The result is an lval in memory if VAL is. */
309 coerce_unspec_val_to_type (val, offset, type)
314 CHECK_TYPEDEF (type);
315 if (VALUE_LVAL (val) == lval_memory)
316 return value_at_lazy (type,
317 VALUE_ADDRESS (val) + VALUE_OFFSET (val) + offset, NULL);
320 struct value* result = allocate_value (type);
321 VALUE_LVAL (result) = not_lval;
322 if (VALUE_ADDRESS (val) == 0)
323 memcpy (VALUE_CONTENTS_RAW (result), VALUE_CONTENTS (val) + offset,
324 TYPE_LENGTH (type) > TYPE_LENGTH (VALUE_TYPE (val))
325 ? TYPE_LENGTH (VALUE_TYPE (val)) : TYPE_LENGTH (type));
328 VALUE_ADDRESS (result) =
329 VALUE_ADDRESS (val) + VALUE_OFFSET (val) + offset;
330 VALUE_LAZY (result) = 1;
337 cond_offset_host (valaddr, offset)
344 return valaddr + offset;
348 cond_offset_target (address, offset)
355 return address + offset;
358 /* Perform execute_command on the result of concatenating all
359 arguments up to NULL. */
361 do_command (const char* arg, ...)
372 for (; s != NULL; s = va_arg (ap, const char*))
376 cmd1 = alloca (len+1);
382 execute_command (cmd, 0);
386 /* Language Selection */
388 /* If the main program is in Ada, return language_ada, otherwise return LANG
389 (the main program is in Ada iif the adainit symbol is found).
391 MAIN_PST is not used. */
394 ada_update_initial_language (lang, main_pst)
396 struct partial_symtab* main_pst;
398 if (lookup_minimal_symbol ("adainit", (const char*) NULL,
399 (struct objfile*) NULL) != NULL)
400 /* return language_ada; */
401 /* FIXME: language_ada should be defined in defs.h */
402 return language_unknown;
410 /* Table of Ada operators and their GNAT-mangled names. Last entry is pair
413 const struct ada_opname_map ada_opname_table[] =
415 { "Oadd", "\"+\"", BINOP_ADD },
416 { "Osubtract", "\"-\"", BINOP_SUB },
417 { "Omultiply", "\"*\"", BINOP_MUL },
418 { "Odivide", "\"/\"", BINOP_DIV },
419 { "Omod", "\"mod\"", BINOP_MOD },
420 { "Orem", "\"rem\"", BINOP_REM },
421 { "Oexpon", "\"**\"", BINOP_EXP },
422 { "Olt", "\"<\"", BINOP_LESS },
423 { "Ole", "\"<=\"", BINOP_LEQ },
424 { "Ogt", "\">\"", BINOP_GTR },
425 { "Oge", "\">=\"", BINOP_GEQ },
426 { "Oeq", "\"=\"", BINOP_EQUAL },
427 { "One", "\"/=\"", BINOP_NOTEQUAL },
428 { "Oand", "\"and\"", BINOP_BITWISE_AND },
429 { "Oor", "\"or\"", BINOP_BITWISE_IOR },
430 { "Oxor", "\"xor\"", BINOP_BITWISE_XOR },
431 { "Oconcat", "\"&\"", BINOP_CONCAT },
432 { "Oabs", "\"abs\"", UNOP_ABS },
433 { "Onot", "\"not\"", UNOP_LOGICAL_NOT },
434 { "Oadd", "\"+\"", UNOP_PLUS },
435 { "Osubtract", "\"-\"", UNOP_NEG },
439 /* True if STR should be suppressed in info listings. */
441 is_suppressed_name (str)
444 if (STREQN (str, "_ada_", 5))
446 if (str[0] == '_' || str[0] == '\000')
451 const char* suffix = strstr (str, "___");
452 if (suffix != NULL && suffix[3] != 'X')
455 suffix = str + strlen (str);
456 for (p = suffix-1; p != str; p -= 1)
460 if (p[0] == 'X' && p[-1] != '_')
464 for (i = 0; ada_opname_table[i].mangled != NULL; i += 1)
465 if (STREQN (ada_opname_table[i].mangled, p,
466 strlen (ada_opname_table[i].mangled)))
475 /* The "mangled" form of DEMANGLED, according to GNAT conventions.
476 * The result is valid until the next call to ada_mangle. */
478 ada_mangle (demangled)
479 const char* demangled;
481 static char* mangling_buffer = NULL;
482 static size_t mangling_buffer_size = 0;
486 if (demangled == NULL)
489 GROW_VECT (mangling_buffer, mangling_buffer_size, 2*strlen (demangled) + 10);
492 for (p = demangled; *p != '\0'; p += 1)
496 mangling_buffer[k] = mangling_buffer[k+1] = '_';
501 const struct ada_opname_map* mapping;
503 for (mapping = ada_opname_table;
504 mapping->mangled != NULL &&
505 ! STREQN (mapping->demangled, p, strlen (mapping->demangled));
508 if (mapping->mangled == NULL)
509 error ("invalid Ada operator name: %s", p);
510 strcpy (mangling_buffer+k, mapping->mangled);
511 k += strlen (mapping->mangled);
516 mangling_buffer[k] = *p;
521 mangling_buffer[k] = '\0';
522 return mangling_buffer;
525 /* Return NAME folded to lower case, or, if surrounded by single
526 * quotes, unfolded, but with the quotes stripped away. Result good
529 ada_fold_name (const char* name)
531 static char* fold_buffer = NULL;
532 static size_t fold_buffer_size = 0;
534 int len = strlen (name);
535 GROW_VECT (fold_buffer, fold_buffer_size, len+1);
539 strncpy (fold_buffer, name+1, len-2);
540 fold_buffer[len-2] = '\000';
545 for (i = 0; i <= len; i += 1)
546 fold_buffer[i] = tolower (name[i]);
553 1. Discard final __{DIGIT}+ or ${DIGIT}+
554 2. Convert other instances of embedded "__" to `.'.
555 3. Discard leading _ada_.
556 4. Convert operator names to the appropriate quoted symbols.
557 5. Remove everything after first ___ if it is followed by
559 6. Replace TK__ with __, and a trailing B or TKB with nothing.
560 7. Put symbols that should be suppressed in <...> brackets.
561 8. Remove trailing X[bn]* suffix (indicating names in package bodies).
562 The resulting string is valid until the next call of ada_demangle.
566 ada_demangle (mangled)
574 static char* demangling_buffer = NULL;
575 static size_t demangling_buffer_size = 0;
577 if (STREQN (mangled, "_ada_", 5))
580 if (mangled[0] == '_' || mangled[0] == '<')
583 p = strstr (mangled, "___");
585 len0 = strlen (mangled);
593 if (len0 > 3 && STREQ (mangled + len0 - 3, "TKB"))
595 if (len0 > 1 && STREQ (mangled + len0 - 1, "B"))
598 /* Make demangled big enough for possible expansion by operator name. */
599 GROW_VECT (demangling_buffer, demangling_buffer_size, 2*len0+1);
600 demangled = demangling_buffer;
602 if (isdigit (mangled[len0 - 1])) {
603 for (i = len0-2; i >= 0 && isdigit (mangled[i]); i -= 1)
605 if (i > 1 && mangled[i] == '_' && mangled[i-1] == '_')
607 else if (mangled[i] == '$')
611 for (i = 0, j = 0; i < len0 && ! isalpha (mangled[i]); i += 1, j += 1)
612 demangled[j] = mangled[i];
617 if (at_start_name && mangled[i] == 'O')
620 for (k = 0; ada_opname_table[k].mangled != NULL; k += 1)
622 int op_len = strlen (ada_opname_table[k].mangled);
623 if (STREQN (ada_opname_table[k].mangled+1, mangled+i+1, op_len-1)
624 && ! isalnum (mangled[i + op_len]))
626 strcpy (demangled + j, ada_opname_table[k].demangled);
629 j += strlen (ada_opname_table[k].demangled);
633 if (ada_opname_table[k].mangled != NULL)
638 if (i < len0-4 && STREQN (mangled+i, "TK__", 4))
640 if (mangled[i] == 'X' && i != 0 && isalnum (mangled[i-1]))
644 while (i < len0 && (mangled[i] == 'b' || mangled[i] == 'n'));
648 else if (i < len0-2 && mangled[i] == '_' && mangled[i+1] == '_')
656 demangled[j] = mangled[i];
660 demangled[j] = '\000';
662 for (i = 0; demangled[i] != '\0'; i += 1)
663 if (isupper (demangled[i]) || demangled[i] == ' ')
669 GROW_VECT (demangling_buffer, demangling_buffer_size,
670 strlen (mangled) + 3);
671 demangled = demangling_buffer;
672 if (mangled[0] == '<')
673 strcpy (demangled, mangled);
675 sprintf (demangled, "<%s>", mangled);
680 /* Returns non-zero iff SYM_NAME matches NAME, ignoring any trailing
681 * suffixes that encode debugging information or leading _ada_ on
682 * SYM_NAME (see is_name_suffix commentary for the debugging
683 * information that is ignored). If WILD, then NAME need only match a
684 * suffix of SYM_NAME minus the same suffixes. Also returns 0 if
685 * either argument is NULL. */
688 ada_match_name (sym_name, name, wild)
689 const char* sym_name;
693 if (sym_name == NULL || name == NULL)
696 return wild_match (name, strlen (name), sym_name);
698 int len_name = strlen (name);
699 return (STREQN (sym_name, name, len_name)
700 && is_name_suffix (sym_name+len_name))
701 || (STREQN (sym_name, "_ada_", 5)
702 && STREQN (sym_name+5, name, len_name)
703 && is_name_suffix (sym_name+len_name+5));
707 /* True (non-zero) iff in Ada mode, the symbol SYM should be
708 suppressed in info listings. */
711 ada_suppress_symbol_printing (sym)
714 if (SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE)
717 return is_suppressed_name (SYMBOL_NAME (sym));
723 /* Names of MAX_ADA_DIMENS bounds in P_BOUNDS fields of
724 array descriptors. */
726 static char* bound_name[] = {
727 "LB0", "UB0", "LB1", "UB1", "LB2", "UB2", "LB3", "UB3",
728 "LB4", "UB4", "LB5", "UB5", "LB6", "UB6", "LB7", "UB7"
731 /* Maximum number of array dimensions we are prepared to handle. */
733 #define MAX_ADA_DIMENS (sizeof(bound_name) / (2*sizeof(char*)))
735 /* Like modify_field, but allows bitpos > wordlength. */
738 modify_general_field (addr, fieldval, bitpos, bitsize)
743 modify_field (addr + sizeof (LONGEST) * bitpos / (8 * sizeof (LONGEST)),
744 fieldval, bitpos % (8 * sizeof (LONGEST)),
749 /* The desc_* routines return primitive portions of array descriptors
752 /* The descriptor or array type, if any, indicated by TYPE; removes
753 level of indirection, if needed. */
755 desc_base_type (type)
760 CHECK_TYPEDEF (type);
761 if (type != NULL && TYPE_CODE (type) == TYPE_CODE_PTR)
762 return check_typedef (TYPE_TARGET_TYPE (type));
767 /* True iff TYPE indicates a "thin" array pointer type. */
769 is_thin_pntr (struct type* type)
772 is_suffix (ada_type_name (desc_base_type (type)), "___XUT")
773 || is_suffix (ada_type_name (desc_base_type (type)), "___XUT___XVE");
776 /* The descriptor type for thin pointer type TYPE. */
778 thin_descriptor_type (struct type* type)
780 struct type* base_type = desc_base_type (type);
781 if (base_type == NULL)
783 if (is_suffix (ada_type_name (base_type), "___XVE"))
787 struct type* alt_type =
788 ada_find_parallel_type (base_type, "___XVE");
789 if (alt_type == NULL)
796 /* A pointer to the array data for thin-pointer value VAL. */
798 thin_data_pntr (struct value* val)
800 struct type* type = VALUE_TYPE (val);
801 if (TYPE_CODE (type) == TYPE_CODE_PTR)
802 return value_cast (desc_data_type (thin_descriptor_type (type)),
805 return value_from_longest (desc_data_type (thin_descriptor_type (type)),
806 VALUE_ADDRESS (val) + VALUE_OFFSET (val));
809 /* True iff TYPE indicates a "thick" array pointer type. */
811 is_thick_pntr (struct type* type)
813 type = desc_base_type (type);
814 return (type != NULL && TYPE_CODE (type) == TYPE_CODE_STRUCT
815 && lookup_struct_elt_type (type, "P_BOUNDS", 1) != NULL);
818 /* If TYPE is the type of an array descriptor (fat or thin pointer) or a
819 pointer to one, the type of its bounds data; otherwise, NULL. */
821 desc_bounds_type (type)
826 type = desc_base_type (type);
830 else if (is_thin_pntr (type))
832 type = thin_descriptor_type (type);
835 r = lookup_struct_elt_type (type, "BOUNDS", 1);
837 return check_typedef (r);
839 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
841 r = lookup_struct_elt_type (type, "P_BOUNDS", 1);
843 return check_typedef (TYPE_TARGET_TYPE (check_typedef (r)));
848 /* If ARR is an array descriptor (fat or thin pointer), or pointer to
849 one, a pointer to its bounds data. Otherwise NULL. */
854 struct type* type = check_typedef (VALUE_TYPE (arr));
855 if (is_thin_pntr (type))
857 struct type* bounds_type = desc_bounds_type (thin_descriptor_type (type));
860 if (desc_bounds_type == NULL)
861 error ("Bad GNAT array descriptor");
863 /* NOTE: The following calculation is not really kosher, but
864 since desc_type is an XVE-encoded type (and shouldn't be),
865 the correct calculation is a real pain. FIXME (and fix GCC). */
866 if (TYPE_CODE (type) == TYPE_CODE_PTR)
867 addr = value_as_long (arr);
869 addr = VALUE_ADDRESS (arr) + VALUE_OFFSET (arr);
872 value_from_longest (lookup_pointer_type (bounds_type),
873 addr - TYPE_LENGTH (bounds_type));
876 else if (is_thick_pntr (type))
877 return value_struct_elt (&arr, NULL, "P_BOUNDS", NULL,
878 "Bad GNAT array descriptor");
883 /* If TYPE is the type of an array-descriptor (fat pointer), the bit
884 position of the field containing the address of the bounds data. */
886 fat_pntr_bounds_bitpos (type)
889 return TYPE_FIELD_BITPOS (desc_base_type (type), 1);
892 /* If TYPE is the type of an array-descriptor (fat pointer), the bit
893 size of the field containing the address of the bounds data. */
895 fat_pntr_bounds_bitsize (type)
898 type = desc_base_type (type);
900 if (TYPE_FIELD_BITSIZE (type, 1) > 0)
901 return TYPE_FIELD_BITSIZE (type, 1);
903 return 8 * TYPE_LENGTH (check_typedef (TYPE_FIELD_TYPE (type, 1)));
906 /* If TYPE is the type of an array descriptor (fat or thin pointer) or a
907 pointer to one, the type of its array data (a
908 pointer-to-array-with-no-bounds type); otherwise, NULL. Use
909 ada_type_of_array to get an array type with bounds data. */
911 desc_data_type (type)
914 type = desc_base_type (type);
916 /* NOTE: The following is bogus; see comment in desc_bounds. */
917 if (is_thin_pntr (type))
918 return lookup_pointer_type
919 (desc_base_type (TYPE_FIELD_TYPE (thin_descriptor_type (type),1)));
920 else if (is_thick_pntr (type))
921 return lookup_struct_elt_type (type, "P_ARRAY", 1);
926 /* If ARR is an array descriptor (fat or thin pointer), a pointer to
932 struct type* type = VALUE_TYPE (arr);
933 if (is_thin_pntr (type))
934 return thin_data_pntr (arr);
935 else if (is_thick_pntr (type))
936 return value_struct_elt (&arr, NULL, "P_ARRAY", NULL,
937 "Bad GNAT array descriptor");
943 /* If TYPE is the type of an array-descriptor (fat pointer), the bit
944 position of the field containing the address of the data. */
946 fat_pntr_data_bitpos (type)
949 return TYPE_FIELD_BITPOS (desc_base_type (type), 0);
952 /* If TYPE is the type of an array-descriptor (fat pointer), the bit
953 size of the field containing the address of the data. */
955 fat_pntr_data_bitsize (type)
958 type = desc_base_type (type);
960 if (TYPE_FIELD_BITSIZE (type, 0) > 0)
961 return TYPE_FIELD_BITSIZE (type, 0);
963 return TARGET_CHAR_BIT * TYPE_LENGTH (TYPE_FIELD_TYPE (type, 0));
966 /* If BOUNDS is an array-bounds structure (or pointer to one), return
967 the Ith lower bound stored in it, if WHICH is 0, and the Ith upper
968 bound, if WHICH is 1. The first bound is I=1. */
970 desc_one_bound (bounds, i, which)
971 struct value* bounds;
975 return value_struct_elt (&bounds, NULL, bound_name[2*i+which-2], NULL,
976 "Bad GNAT array descriptor bounds");
979 /* If BOUNDS is an array-bounds structure type, return the bit position
980 of the Ith lower bound stored in it, if WHICH is 0, and the Ith upper
981 bound, if WHICH is 1. The first bound is I=1. */
983 desc_bound_bitpos (type, i, which)
988 return TYPE_FIELD_BITPOS (desc_base_type (type), 2*i+which-2);
991 /* If BOUNDS is an array-bounds structure type, return the bit field size
992 of the Ith lower bound stored in it, if WHICH is 0, and the Ith upper
993 bound, if WHICH is 1. The first bound is I=1. */
995 desc_bound_bitsize (type, i, which)
1000 type = desc_base_type (type);
1002 if (TYPE_FIELD_BITSIZE (type, 2*i+which-2) > 0)
1003 return TYPE_FIELD_BITSIZE (type, 2*i+which-2);
1005 return 8 * TYPE_LENGTH (TYPE_FIELD_TYPE (type, 2*i+which-2));
1008 /* If TYPE is the type of an array-bounds structure, the type of its
1009 Ith bound (numbering from 1). Otherwise, NULL. */
1011 desc_index_type (type, i)
1015 type = desc_base_type (type);
1017 if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
1018 return lookup_struct_elt_type (type, bound_name[2*i-2], 1);
1023 /* The number of index positions in the array-bounds type TYPE. 0
1029 type = desc_base_type (type);
1032 return TYPE_NFIELDS (type) / 2;
1037 /* Non-zero iff type is a simple array type (or pointer to one). */
1039 ada_is_simple_array (type)
1044 CHECK_TYPEDEF (type);
1045 return (TYPE_CODE (type) == TYPE_CODE_ARRAY
1046 || (TYPE_CODE (type) == TYPE_CODE_PTR
1047 && TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_ARRAY));
1050 /* Non-zero iff type belongs to a GNAT array descriptor. */
1052 ada_is_array_descriptor (type)
1055 struct type* data_type = desc_data_type (type);
1059 CHECK_TYPEDEF (type);
1062 && ((TYPE_CODE (data_type) == TYPE_CODE_PTR
1063 && TYPE_TARGET_TYPE (data_type) != NULL
1064 && TYPE_CODE (TYPE_TARGET_TYPE (data_type)) == TYPE_CODE_ARRAY)
1066 TYPE_CODE (data_type) == TYPE_CODE_ARRAY)
1067 && desc_arity (desc_bounds_type (type)) > 0;
1070 /* Non-zero iff type is a partially mal-formed GNAT array
1071 descriptor. (FIXME: This is to compensate for some problems with
1072 debugging output from GNAT. Re-examine periodically to see if it
1075 ada_is_bogus_array_descriptor (type)
1080 && TYPE_CODE (type) == TYPE_CODE_STRUCT
1081 && (lookup_struct_elt_type (type, "P_BOUNDS", 1) != NULL
1082 || lookup_struct_elt_type (type, "P_ARRAY", 1) != NULL)
1083 && ! ada_is_array_descriptor (type);
1087 /* If ARR has a record type in the form of a standard GNAT array descriptor,
1088 (fat pointer) returns the type of the array data described---specifically,
1089 a pointer-to-array type. If BOUNDS is non-zero, the bounds data are filled
1090 in from the descriptor; otherwise, they are left unspecified. If
1091 the ARR denotes a null array descriptor and BOUNDS is non-zero,
1092 returns NULL. The result is simply the type of ARR if ARR is not
1095 ada_type_of_array (arr, bounds)
1099 if (ada_is_packed_array_type (VALUE_TYPE (arr)))
1100 return decode_packed_array_type (VALUE_TYPE (arr));
1102 if (! ada_is_array_descriptor (VALUE_TYPE (arr)))
1103 return VALUE_TYPE (arr);
1106 return check_typedef (TYPE_TARGET_TYPE (desc_data_type (VALUE_TYPE (arr))));
1109 struct type* elt_type;
1111 struct value* descriptor;
1112 struct objfile *objf = TYPE_OBJFILE (VALUE_TYPE (arr));
1114 elt_type = ada_array_element_type (VALUE_TYPE (arr), -1);
1115 arity = ada_array_arity (VALUE_TYPE (arr));
1117 if (elt_type == NULL || arity == 0)
1118 return check_typedef (VALUE_TYPE (arr));
1120 descriptor = desc_bounds (arr);
1121 if (value_as_long (descriptor) == 0)
1124 struct type* range_type = alloc_type (objf);
1125 struct type* array_type = alloc_type (objf);
1126 struct value* low = desc_one_bound (descriptor, arity, 0);
1127 struct value* high = desc_one_bound (descriptor, arity, 1);
1130 create_range_type (range_type, VALUE_TYPE (low),
1131 (int) value_as_long (low),
1132 (int) value_as_long (high));
1133 elt_type = create_array_type (array_type, elt_type, range_type);
1136 return lookup_pointer_type (elt_type);
1140 /* If ARR does not represent an array, returns ARR unchanged.
1141 Otherwise, returns either a standard GDB array with bounds set
1142 appropriately or, if ARR is a non-null fat pointer, a pointer to a standard
1143 GDB array. Returns NULL if ARR is a null fat pointer. */
1145 ada_coerce_to_simple_array_ptr (arr)
1148 if (ada_is_array_descriptor (VALUE_TYPE (arr)))
1150 struct type* arrType = ada_type_of_array (arr, 1);
1151 if (arrType == NULL)
1153 return value_cast (arrType, value_copy (desc_data (arr)));
1155 else if (ada_is_packed_array_type (VALUE_TYPE (arr)))
1156 return decode_packed_array (arr);
1161 /* If ARR does not represent an array, returns ARR unchanged.
1162 Otherwise, returns a standard GDB array describing ARR (which may
1163 be ARR itself if it already is in the proper form). */
1165 ada_coerce_to_simple_array (arr)
1168 if (ada_is_array_descriptor (VALUE_TYPE (arr)))
1170 struct value* arrVal = ada_coerce_to_simple_array_ptr (arr);
1172 error ("Bounds unavailable for null array pointer.");
1173 return value_ind (arrVal);
1175 else if (ada_is_packed_array_type (VALUE_TYPE (arr)))
1176 return decode_packed_array (arr);
1181 /* If TYPE represents a GNAT array type, return it translated to an
1182 ordinary GDB array type (possibly with BITSIZE fields indicating
1183 packing). For other types, is the identity. */
1185 ada_coerce_to_simple_array_type (type)
1188 struct value* mark = value_mark ();
1189 struct value* dummy = value_from_longest (builtin_type_long, 0);
1190 struct type* result;
1191 VALUE_TYPE (dummy) = type;
1192 result = ada_type_of_array (dummy, 0);
1193 value_free_to_mark (dummy);
1197 /* Non-zero iff TYPE represents a standard GNAT packed-array type. */
1199 ada_is_packed_array_type (type)
1204 CHECK_TYPEDEF (type);
1206 ada_type_name (type) != NULL
1207 && strstr (ada_type_name (type), "___XP") != NULL;
1210 /* Given that TYPE is a standard GDB array type with all bounds filled
1211 in, and that the element size of its ultimate scalar constituents
1212 (that is, either its elements, or, if it is an array of arrays, its
1213 elements' elements, etc.) is *ELT_BITS, return an identical type,
1214 but with the bit sizes of its elements (and those of any
1215 constituent arrays) recorded in the BITSIZE components of its
1216 TYPE_FIELD_BITSIZE values, and with *ELT_BITS set to its total size
1219 packed_array_type (type, elt_bits)
1223 struct type* new_elt_type;
1224 struct type* new_type;
1225 LONGEST low_bound, high_bound;
1227 CHECK_TYPEDEF (type);
1228 if (TYPE_CODE (type) != TYPE_CODE_ARRAY)
1231 new_type = alloc_type (TYPE_OBJFILE (type));
1232 new_elt_type = packed_array_type (check_typedef (TYPE_TARGET_TYPE (type)),
1234 create_array_type (new_type, new_elt_type, TYPE_FIELD_TYPE (type, 0));
1235 TYPE_FIELD_BITSIZE (new_type, 0) = *elt_bits;
1236 TYPE_NAME (new_type) = ada_type_name (type);
1238 if (get_discrete_bounds (TYPE_FIELD_TYPE (type, 0),
1239 &low_bound, &high_bound) < 0)
1240 low_bound = high_bound = 0;
1241 if (high_bound < low_bound)
1242 *elt_bits = TYPE_LENGTH (new_type) = 0;
1245 *elt_bits *= (high_bound - low_bound + 1);
1246 TYPE_LENGTH (new_type) =
1247 (*elt_bits + HOST_CHAR_BIT - 1) / HOST_CHAR_BIT;
1250 /* TYPE_FLAGS (new_type) |= TYPE_FLAG_FIXED_INSTANCE; */
1251 /* FIXME: TYPE_FLAG_FIXED_INSTANCE should be defined in gdbtypes.h */
1255 /* The array type encoded by TYPE, where ada_is_packed_array_type (TYPE).
1258 decode_packed_array_type (type)
1261 struct symbol** syms;
1262 struct block** blocks;
1263 const char* raw_name = ada_type_name (check_typedef (type));
1264 char* name = (char*) alloca (strlen (raw_name) + 1);
1265 char* tail = strstr (raw_name, "___XP");
1266 struct type* shadow_type;
1270 memcpy (name, raw_name, tail - raw_name);
1271 name[tail - raw_name] = '\000';
1273 /* NOTE: Use ada_lookup_symbol_list because of bug in some versions
1274 * of gcc (Solaris, e.g.). FIXME when compiler is fixed. */
1275 n = ada_lookup_symbol_list (name, get_selected_block (NULL),
1276 VAR_NAMESPACE, &syms, &blocks);
1277 for (i = 0; i < n; i += 1)
1278 if (syms[i] != NULL && SYMBOL_CLASS (syms[i]) == LOC_TYPEDEF
1279 && STREQ (name, ada_type_name (SYMBOL_TYPE (syms[i]))))
1283 warning ("could not find bounds information on packed array");
1286 shadow_type = SYMBOL_TYPE (syms[i]);
1288 if (TYPE_CODE (shadow_type) != TYPE_CODE_ARRAY)
1290 warning ("could not understand bounds information on packed array");
1294 if (sscanf (tail + sizeof ("___XP") - 1, "%ld", &bits) != 1)
1296 warning ("could not understand bit size information on packed array");
1300 return packed_array_type (shadow_type, &bits);
1303 /* Given that ARR is a struct value* indicating a GNAT packed array,
1304 returns a simple array that denotes that array. Its type is a
1305 standard GDB array type except that the BITSIZEs of the array
1306 target types are set to the number of bits in each element, and the
1307 type length is set appropriately. */
1309 static struct value*
1310 decode_packed_array (arr)
1313 struct type* type = decode_packed_array_type (VALUE_TYPE (arr));
1317 error ("can't unpack array");
1321 return coerce_unspec_val_to_type (arr, 0, type);
1325 /* The value of the element of packed array ARR at the ARITY indices
1326 given in IND. ARR must be a simple array. */
1328 static struct value*
1329 value_subscript_packed (arr, arity, ind)
1335 int bits, elt_off, bit_off;
1336 long elt_total_bit_offset;
1337 struct type* elt_type;
1341 elt_total_bit_offset = 0;
1342 elt_type = check_typedef (VALUE_TYPE (arr));
1343 for (i = 0; i < arity; i += 1)
1345 if (TYPE_CODE (elt_type) != TYPE_CODE_ARRAY
1346 || TYPE_FIELD_BITSIZE (elt_type, 0) == 0)
1347 error ("attempt to do packed indexing of something other than a packed array");
1350 struct type *range_type = TYPE_INDEX_TYPE (elt_type);
1351 LONGEST lowerbound, upperbound;
1354 if (get_discrete_bounds (range_type, &lowerbound,
1357 warning ("don't know bounds of array");
1358 lowerbound = upperbound = 0;
1361 idx = value_as_long (value_pos_atr (ind[i]));
1362 if (idx < lowerbound || idx > upperbound)
1363 warning ("packed array index %ld out of bounds", (long) idx);
1364 bits = TYPE_FIELD_BITSIZE (elt_type, 0);
1365 elt_total_bit_offset += (idx - lowerbound) * bits;
1366 elt_type = check_typedef (TYPE_TARGET_TYPE (elt_type));
1369 elt_off = elt_total_bit_offset / HOST_CHAR_BIT;
1370 bit_off = elt_total_bit_offset % HOST_CHAR_BIT;
1372 v = ada_value_primitive_packed_val (arr, NULL, elt_off, bit_off,
1374 if (VALUE_LVAL (arr) == lval_internalvar)
1375 VALUE_LVAL (v) = lval_internalvar_component;
1377 VALUE_LVAL (v) = VALUE_LVAL (arr);
1381 /* Non-zero iff TYPE includes negative integer values. */
1384 has_negatives (type)
1387 switch (TYPE_CODE (type)) {
1391 return ! TYPE_UNSIGNED (type);
1392 case TYPE_CODE_RANGE:
1393 return TYPE_LOW_BOUND (type) < 0;
1398 /* Create a new value of type TYPE from the contents of OBJ starting
1399 at byte OFFSET, and bit offset BIT_OFFSET within that byte,
1400 proceeding for BIT_SIZE bits. If OBJ is an lval in memory, then
1401 assigning through the result will set the field fetched from. OBJ
1402 may also be NULL, in which case, VALADDR+OFFSET must address the
1403 start of storage containing the packed value. The value returned
1404 in this case is never an lval.
1405 Assumes 0 <= BIT_OFFSET < HOST_CHAR_BIT. */
1408 ada_value_primitive_packed_val (obj, valaddr, offset, bit_offset,
1418 int src, /* Index into the source area. */
1419 targ, /* Index into the target area. */
1421 srcBitsLeft, /* Number of source bits left to move. */
1422 nsrc, ntarg, /* Number of source and target bytes. */
1423 unusedLS, /* Number of bits in next significant
1424 * byte of source that are unused. */
1425 accumSize; /* Number of meaningful bits in accum */
1426 unsigned char* bytes; /* First byte containing data to unpack. */
1427 unsigned char* unpacked;
1428 unsigned long accum; /* Staging area for bits being transferred */
1430 int len = (bit_size + bit_offset + HOST_CHAR_BIT - 1) / 8;
1431 /* Transmit bytes from least to most significant; delta is the
1432 * direction the indices move. */
1433 int delta = BITS_BIG_ENDIAN ? -1 : 1;
1435 CHECK_TYPEDEF (type);
1439 v = allocate_value (type);
1440 bytes = (unsigned char*) (valaddr + offset);
1442 else if (VALUE_LAZY (obj))
1445 VALUE_ADDRESS (obj) + VALUE_OFFSET (obj) + offset, NULL);
1446 bytes = (unsigned char*) alloca (len);
1447 read_memory (VALUE_ADDRESS (v), bytes, len);
1451 v = allocate_value (type);
1452 bytes = (unsigned char*) VALUE_CONTENTS (obj) + offset;
1457 VALUE_LVAL (v) = VALUE_LVAL (obj);
1458 if (VALUE_LVAL (obj) == lval_internalvar)
1459 VALUE_LVAL (v) = lval_internalvar_component;
1460 VALUE_ADDRESS (v) = VALUE_ADDRESS (obj) + VALUE_OFFSET (obj) + offset;
1461 VALUE_BITPOS (v) = bit_offset + VALUE_BITPOS (obj);
1462 VALUE_BITSIZE (v) = bit_size;
1463 if (VALUE_BITPOS (v) >= HOST_CHAR_BIT)
1465 VALUE_ADDRESS (v) += 1;
1466 VALUE_BITPOS (v) -= HOST_CHAR_BIT;
1470 VALUE_BITSIZE (v) = bit_size;
1471 unpacked = (unsigned char*) VALUE_CONTENTS (v);
1473 srcBitsLeft = bit_size;
1475 ntarg = TYPE_LENGTH (type);
1479 memset (unpacked, 0, TYPE_LENGTH (type));
1482 else if (BITS_BIG_ENDIAN)
1485 if (has_negatives (type) &&
1486 ((bytes[0] << bit_offset) & (1 << (HOST_CHAR_BIT-1))))
1490 (HOST_CHAR_BIT - (bit_size + bit_offset) % HOST_CHAR_BIT)
1493 switch (TYPE_CODE (type))
1495 case TYPE_CODE_ARRAY:
1496 case TYPE_CODE_UNION:
1497 case TYPE_CODE_STRUCT:
1498 /* Non-scalar values must be aligned at a byte boundary. */
1500 (HOST_CHAR_BIT - bit_size % HOST_CHAR_BIT) % HOST_CHAR_BIT;
1501 /* And are placed at the beginning (most-significant) bytes
1507 targ = TYPE_LENGTH (type) - 1;
1513 int sign_bit_offset = (bit_size + bit_offset - 1) % 8;
1516 unusedLS = bit_offset;
1519 if (has_negatives (type) && (bytes[len-1] & (1 << sign_bit_offset)))
1526 /* Mask for removing bits of the next source byte that are not
1527 * part of the value. */
1528 unsigned int unusedMSMask =
1529 (1 << (srcBitsLeft >= HOST_CHAR_BIT ? HOST_CHAR_BIT : srcBitsLeft))-1;
1530 /* Sign-extend bits for this byte. */
1531 unsigned int signMask = sign & ~unusedMSMask;
1533 (((bytes[src] >> unusedLS) & unusedMSMask) | signMask) << accumSize;
1534 accumSize += HOST_CHAR_BIT - unusedLS;
1535 if (accumSize >= HOST_CHAR_BIT)
1537 unpacked[targ] = accum & ~(~0L << HOST_CHAR_BIT);
1538 accumSize -= HOST_CHAR_BIT;
1539 accum >>= HOST_CHAR_BIT;
1543 srcBitsLeft -= HOST_CHAR_BIT - unusedLS;
1550 accum |= sign << accumSize;
1551 unpacked[targ] = accum & ~(~0L << HOST_CHAR_BIT);
1552 accumSize -= HOST_CHAR_BIT;
1553 accum >>= HOST_CHAR_BIT;
1561 /* Move N bits from SOURCE, starting at bit offset SRC_OFFSET to
1562 TARGET, starting at bit offset TARG_OFFSET. SOURCE and TARGET must
1565 move_bits (char* target, int targ_offset, char* source, int src_offset, int n)
1567 unsigned int accum, mask;
1568 int accum_bits, chunk_size;
1570 target += targ_offset / HOST_CHAR_BIT;
1571 targ_offset %= HOST_CHAR_BIT;
1572 source += src_offset / HOST_CHAR_BIT;
1573 src_offset %= HOST_CHAR_BIT;
1574 if (BITS_BIG_ENDIAN)
1576 accum = (unsigned char) *source;
1578 accum_bits = HOST_CHAR_BIT - src_offset;
1583 accum = (accum << HOST_CHAR_BIT) + (unsigned char) *source;
1584 accum_bits += HOST_CHAR_BIT;
1586 chunk_size = HOST_CHAR_BIT - targ_offset;
1589 unused_right = HOST_CHAR_BIT - (chunk_size + targ_offset);
1590 mask = ((1 << chunk_size) - 1) << unused_right;
1593 | ((accum >> (accum_bits - chunk_size - unused_right)) & mask);
1595 accum_bits -= chunk_size;
1602 accum = (unsigned char) *source >> src_offset;
1604 accum_bits = HOST_CHAR_BIT - src_offset;
1608 accum = accum + ((unsigned char) *source << accum_bits);
1609 accum_bits += HOST_CHAR_BIT;
1611 chunk_size = HOST_CHAR_BIT - targ_offset;
1614 mask = ((1 << chunk_size) - 1) << targ_offset;
1616 (*target & ~mask) | ((accum << targ_offset) & mask);
1618 accum_bits -= chunk_size;
1619 accum >>= chunk_size;
1627 /* Store the contents of FROMVAL into the location of TOVAL.
1628 Return a new value with the location of TOVAL and contents of
1629 FROMVAL. Handles assignment into packed fields that have
1630 floating-point or non-scalar types. */
1632 static struct value*
1633 ada_value_assign (struct value* toval, struct value* fromval)
1635 struct type* type = VALUE_TYPE (toval);
1636 int bits = VALUE_BITSIZE (toval);
1638 if (!toval->modifiable)
1639 error ("Left operand of assignment is not a modifiable lvalue.");
1643 if (VALUE_LVAL (toval) == lval_memory
1645 && (TYPE_CODE (type) == TYPE_CODE_FLT
1646 || TYPE_CODE (type) == TYPE_CODE_STRUCT))
1649 (VALUE_BITPOS (toval) + bits + HOST_CHAR_BIT - 1)
1651 char* buffer = (char*) alloca (len);
1654 if (TYPE_CODE (type) == TYPE_CODE_FLT)
1655 fromval = value_cast (type, fromval);
1657 read_memory (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval), buffer, len);
1658 if (BITS_BIG_ENDIAN)
1659 move_bits (buffer, VALUE_BITPOS (toval),
1660 VALUE_CONTENTS (fromval),
1661 TYPE_LENGTH (VALUE_TYPE (fromval)) * TARGET_CHAR_BIT - bits,
1664 move_bits (buffer, VALUE_BITPOS (toval), VALUE_CONTENTS (fromval),
1666 write_memory (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval), buffer, len);
1668 val = value_copy (toval);
1669 memcpy (VALUE_CONTENTS_RAW (val), VALUE_CONTENTS (fromval),
1670 TYPE_LENGTH (type));
1671 VALUE_TYPE (val) = type;
1676 return value_assign (toval, fromval);
1680 /* The value of the element of array ARR at the ARITY indices given in IND.
1681 ARR may be either a simple array, GNAT array descriptor, or pointer
1685 ada_value_subscript (arr, arity, ind)
1692 struct type* elt_type;
1694 elt = ada_coerce_to_simple_array (arr);
1696 elt_type = check_typedef (VALUE_TYPE (elt));
1697 if (TYPE_CODE (elt_type) == TYPE_CODE_ARRAY
1698 && TYPE_FIELD_BITSIZE (elt_type, 0) > 0)
1699 return value_subscript_packed (elt, arity, ind);
1701 for (k = 0; k < arity; k += 1)
1703 if (TYPE_CODE (elt_type) != TYPE_CODE_ARRAY)
1704 error("too many subscripts (%d expected)", k);
1705 elt = value_subscript (elt, value_pos_atr (ind[k]));
1710 /* Assuming ARR is a pointer to a standard GDB array of type TYPE, the
1711 value of the element of *ARR at the ARITY indices given in
1712 IND. Does not read the entire array into memory. */
1715 ada_value_ptr_subscript (arr, type, arity, ind)
1723 for (k = 0; k < arity; k += 1)
1728 if (TYPE_CODE (type) != TYPE_CODE_ARRAY)
1729 error("too many subscripts (%d expected)", k);
1730 arr = value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
1732 get_discrete_bounds (TYPE_INDEX_TYPE (type), &lwb, &upb);
1736 idx = value_sub (ind[k], value_from_longest (builtin_type_int, lwb));
1737 arr = value_add (arr, idx);
1738 type = TYPE_TARGET_TYPE (type);
1741 return value_ind (arr);
1744 /* If type is a record type in the form of a standard GNAT array
1745 descriptor, returns the number of dimensions for type. If arr is a
1746 simple array, returns the number of "array of"s that prefix its
1747 type designation. Otherwise, returns 0. */
1750 ada_array_arity (type)
1758 type = desc_base_type (type);
1761 if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
1762 return desc_arity (desc_bounds_type (type));
1764 while (TYPE_CODE (type) == TYPE_CODE_ARRAY)
1767 type = check_typedef (TYPE_TARGET_TYPE (type));
1773 /* If TYPE is a record type in the form of a standard GNAT array
1774 descriptor or a simple array type, returns the element type for
1775 TYPE after indexing by NINDICES indices, or by all indices if
1776 NINDICES is -1. Otherwise, returns NULL. */
1779 ada_array_element_type (type, nindices)
1783 type = desc_base_type (type);
1785 if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
1788 struct type* p_array_type;
1790 p_array_type = desc_data_type (type);
1792 k = ada_array_arity (type);
1796 /* Initially p_array_type = elt_type(*)[]...(k times)...[] */
1797 if (nindices >= 0 && k > nindices)
1799 p_array_type = TYPE_TARGET_TYPE (p_array_type);
1800 while (k > 0 && p_array_type != NULL)
1802 p_array_type = check_typedef (TYPE_TARGET_TYPE (p_array_type));
1805 return p_array_type;
1807 else if (TYPE_CODE (type) == TYPE_CODE_ARRAY)
1809 while (nindices != 0 && TYPE_CODE (type) == TYPE_CODE_ARRAY)
1811 type = TYPE_TARGET_TYPE (type);
1820 /* The type of nth index in arrays of given type (n numbering from 1). Does
1821 not examine memory. */
1824 ada_index_type (type, n)
1828 type = desc_base_type (type);
1830 if (n > ada_array_arity (type))
1833 if (ada_is_simple_array (type))
1837 for (i = 1; i < n; i += 1)
1838 type = TYPE_TARGET_TYPE (type);
1840 return TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, 0));
1843 return desc_index_type (desc_bounds_type (type), n);
1846 /* Given that arr is an array type, returns the lower bound of the
1847 Nth index (numbering from 1) if WHICH is 0, and the upper bound if
1848 WHICH is 1. This returns bounds 0 .. -1 if ARR_TYPE is an
1849 array-descriptor type. If TYPEP is non-null, *TYPEP is set to the
1850 bounds type. It works for other arrays with bounds supplied by
1851 run-time quantities other than discriminants. */
1854 ada_array_bound_from_type (arr_type, n, which, typep)
1855 struct type* arr_type;
1858 struct type** typep;
1861 struct type* index_type_desc;
1863 if (ada_is_packed_array_type (arr_type))
1864 arr_type = decode_packed_array_type (arr_type);
1866 if (arr_type == NULL || ! ada_is_simple_array (arr_type))
1869 *typep = builtin_type_int;
1870 return (LONGEST) -which;
1873 if (TYPE_CODE (arr_type) == TYPE_CODE_PTR)
1874 type = TYPE_TARGET_TYPE (arr_type);
1878 index_type_desc = ada_find_parallel_type (type, "___XA");
1879 if (index_type_desc == NULL)
1881 struct type* range_type;
1882 struct type* index_type;
1886 type = TYPE_TARGET_TYPE (type);
1890 range_type = TYPE_INDEX_TYPE (type);
1891 index_type = TYPE_TARGET_TYPE (range_type);
1892 if (TYPE_CODE (index_type) == TYPE_CODE_UNDEF)
1893 index_type = builtin_type_long;
1895 *typep = index_type;
1897 (LONGEST) (which == 0
1898 ? TYPE_LOW_BOUND (range_type)
1899 : TYPE_HIGH_BOUND (range_type));
1903 struct type* index_type =
1904 to_fixed_range_type (TYPE_FIELD_NAME (index_type_desc, n-1),
1905 NULL, TYPE_OBJFILE (arr_type));
1907 *typep = TYPE_TARGET_TYPE (index_type);
1909 (LONGEST) (which == 0
1910 ? TYPE_LOW_BOUND (index_type)
1911 : TYPE_HIGH_BOUND (index_type));
1915 /* Given that arr is an array value, returns the lower bound of the
1916 nth index (numbering from 1) if which is 0, and the upper bound if
1917 which is 1. This routine will also work for arrays with bounds
1918 supplied by run-time quantities other than discriminants. */
1921 ada_array_bound (arr, n, which)
1926 struct type* arr_type = VALUE_TYPE (arr);
1928 if (ada_is_packed_array_type (arr_type))
1929 return ada_array_bound (decode_packed_array (arr), n, which);
1930 else if (ada_is_simple_array (arr_type))
1933 LONGEST v = ada_array_bound_from_type (arr_type, n, which, &type);
1934 return value_from_longest (type, v);
1937 return desc_one_bound (desc_bounds (arr), n, which);
1940 /* Given that arr is an array value, returns the length of the
1941 nth index. This routine will also work for arrays with bounds
1942 supplied by run-time quantities other than discriminants. Does not
1943 work for arrays indexed by enumeration types with representation
1944 clauses at the moment. */
1947 ada_array_length (arr, n)
1951 struct type* arr_type = check_typedef (VALUE_TYPE (arr));
1952 struct type* index_type_desc;
1954 if (ada_is_packed_array_type (arr_type))
1955 return ada_array_length (decode_packed_array (arr), n);
1957 if (ada_is_simple_array (arr_type))
1961 ada_array_bound_from_type (arr_type, n, 1, &type) -
1962 ada_array_bound_from_type (arr_type, n, 0, NULL) + 1;
1963 return value_from_longest (type, v);
1967 value_from_longest (builtin_type_ada_int,
1968 value_as_long (desc_one_bound (desc_bounds (arr),
1970 - value_as_long (desc_one_bound (desc_bounds (arr),
1976 /* Name resolution */
1978 /* The "demangled" name for the user-definable Ada operator corresponding
1987 for (i = 0; ada_opname_table[i].mangled != NULL; i += 1)
1989 if (ada_opname_table[i].op == op)
1990 return ada_opname_table[i].demangled;
1992 error ("Could not find operator name for opcode");
1996 /* Same as evaluate_type (*EXP), but resolves ambiguous symbol
1997 references (OP_UNRESOLVED_VALUES) and converts operators that are
1998 user-defined into appropriate function calls. If CONTEXT_TYPE is
1999 non-null, it provides a preferred result type [at the moment, only
2000 type void has any effect---causing procedures to be preferred over
2001 functions in calls]. A null CONTEXT_TYPE indicates that a non-void
2002 return type is preferred. The variable unresolved_names contains a list
2003 of character strings referenced by expout that should be freed.
2004 May change (expand) *EXP. */
2007 ada_resolve (expp, context_type)
2008 struct expression** expp;
2009 struct type* context_type;
2013 ada_resolve_subexp (expp, &pc, 1, context_type);
2016 /* Resolve the operator of the subexpression beginning at
2017 position *POS of *EXPP. "Resolving" consists of replacing
2018 OP_UNRESOLVED_VALUE with an appropriate OP_VAR_VALUE, replacing
2019 built-in operators with function calls to user-defined operators,
2020 where appropriate, and (when DEPROCEDURE_P is non-zero), converting
2021 function-valued variables into parameterless calls. May expand
2022 EXP. The CONTEXT_TYPE functions as in ada_resolve, above. */
2024 static struct value*
2025 ada_resolve_subexp (expp, pos, deprocedure_p, context_type)
2026 struct expression** expp;
2029 struct type* context_type;
2033 struct expression* exp; /* Convenience: == *expp */
2034 enum exp_opcode op = (*expp)->elts[pc].opcode;
2035 struct value** argvec; /* Vector of operand types (alloca'ed). */
2036 int nargs; /* Number of operands */
2042 /* Pass one: resolve operands, saving their types and updating *pos. */
2046 /* case OP_UNRESOLVED_VALUE:*/
2047 /* FIXME: OP_UNRESOLVED_VALUE should be defined in expression.h */
2052 nargs = longest_to_int (exp->elts[pc + 1].longconst) + 1;
2053 /* FIXME: OP_UNRESOLVED_VALUE should be defined in expression.h */
2054 /* if (exp->elts[pc+3].opcode == OP_UNRESOLVED_VALUE)
2058 argvec = (struct value* *) alloca (sizeof (struct value*) * (nargs + 1));
2059 for (i = 0; i < nargs-1; i += 1)
2060 argvec[i] = ada_resolve_subexp (expp, pos, 1, NULL);
2066 ada_resolve_subexp (expp, pos, 0, NULL);
2067 for (i = 1; i < nargs; i += 1)
2068 ada_resolve_subexp (expp, pos, 1, NULL);
2074 /* FIXME: UNOP_QUAL should be defined in expression.h */
2078 ada_resolve_subexp (expp, pos, 1, exp->elts[pc + 1].type);
2082 /* FIXME: OP_ATTRIBUTE should be defined in expression.h */
2083 /* case OP_ATTRIBUTE:
2084 nargs = longest_to_int (exp->elts[pc + 1].longconst) + 1;
2086 for (i = 0; i < nargs; i += 1)
2087 ada_resolve_subexp (expp, pos, 1, NULL);
2094 ada_resolve_subexp (expp, pos, 0, NULL);
2103 arg1 = ada_resolve_subexp (expp, pos, 0, NULL);
2105 ada_resolve_subexp (expp, pos, 1, NULL);
2107 ada_resolve_subexp (expp, pos, 1, VALUE_TYPE (arg1));
2115 error ("Unexpected operator during name resolution");
2130 case BINOP_LOGICAL_AND:
2131 case BINOP_LOGICAL_OR:
2132 case BINOP_BITWISE_AND:
2133 case BINOP_BITWISE_IOR:
2134 case BINOP_BITWISE_XOR:
2137 case BINOP_NOTEQUAL:
2144 case BINOP_SUBSCRIPT:
2152 case UNOP_LOGICAL_NOT:
2169 case OP_INTERNALVAR:
2178 case STRUCTOP_STRUCT:
2181 *pos += 4 + BYTES_TO_EXP_ELEM (exp->elts[pc + 1].longconst + 1);
2186 nargs = longest_to_int (exp->elts[pc + 2].longconst) + 1;
2187 nargs -= longest_to_int (exp->elts[pc + 1].longconst);
2188 /* A null array contains one dummy element to give the type. */
2194 /* FIXME: TERNOP_MBR should be defined in expression.h */
2200 /* FIXME: BINOP_MBR should be defined in expression.h */
2207 argvec = (struct value* *) alloca (sizeof (struct value*) * (nargs + 1));
2208 for (i = 0; i < nargs; i += 1)
2209 argvec[i] = ada_resolve_subexp (expp, pos, 1, NULL);
2215 /* Pass two: perform any resolution on principal operator. */
2221 /* FIXME: OP_UNRESOLVED_VALUE should be defined in expression.h */
2222 /* case OP_UNRESOLVED_VALUE:
2224 struct symbol** candidate_syms;
2225 struct block** candidate_blocks;
2228 n_candidates = ada_lookup_symbol_list (exp->elts[pc + 2].name,
2229 exp->elts[pc + 1].block,
2234 if (n_candidates > 1)
2236 /* Types tend to get re-introduced locally, so if there
2237 are any local symbols that are not types, first filter
2240 for (j = 0; j < n_candidates; j += 1)
2241 switch (SYMBOL_CLASS (candidate_syms[j]))
2247 case LOC_REGPARM_ADDR:
2251 case LOC_BASEREG_ARG:
2257 if (j < n_candidates)
2260 while (j < n_candidates)
2262 if (SYMBOL_CLASS (candidate_syms[j]) == LOC_TYPEDEF)
2264 candidate_syms[j] = candidate_syms[n_candidates-1];
2265 candidate_blocks[j] = candidate_blocks[n_candidates-1];
2274 if (n_candidates == 0)
2275 error ("No definition found for %s",
2276 ada_demangle (exp->elts[pc + 2].name));
2277 else if (n_candidates == 1)
2279 else if (deprocedure_p
2280 && ! is_nonfunction (candidate_syms, n_candidates))
2282 i = ada_resolve_function (candidate_syms, candidate_blocks,
2283 n_candidates, NULL, 0,
2284 exp->elts[pc + 2].name, context_type);
2286 error ("Could not find a match for %s",
2287 ada_demangle (exp->elts[pc + 2].name));
2291 printf_filtered ("Multiple matches for %s\n",
2292 ada_demangle (exp->elts[pc+2].name));
2293 user_select_syms (candidate_syms, candidate_blocks,
2298 exp->elts[pc].opcode = exp->elts[pc + 3].opcode = OP_VAR_VALUE;
2299 exp->elts[pc + 1].block = candidate_blocks[i];
2300 exp->elts[pc + 2].symbol = candidate_syms[i];
2301 if (innermost_block == NULL ||
2302 contained_in (candidate_blocks[i], innermost_block))
2303 innermost_block = candidate_blocks[i];
2308 if (deprocedure_p &&
2309 TYPE_CODE (SYMBOL_TYPE (exp->elts[pc+2].symbol)) == TYPE_CODE_FUNC)
2311 replace_operator_with_call (expp, pc, 0, 0,
2312 exp->elts[pc+2].symbol,
2313 exp->elts[pc+1].block);
2320 /* FIXME: OP_UNRESOLVED_VALUE should be defined in expression.h */
2321 /* if (exp->elts[pc+3].opcode == OP_UNRESOLVED_VALUE)
2323 struct symbol** candidate_syms;
2324 struct block** candidate_blocks;
2327 n_candidates = ada_lookup_symbol_list (exp->elts[pc + 5].name,
2328 exp->elts[pc + 4].block,
2332 if (n_candidates == 1)
2336 i = ada_resolve_function (candidate_syms, candidate_blocks,
2337 n_candidates, argvec, nargs-1,
2338 exp->elts[pc + 5].name, context_type);
2340 error ("Could not find a match for %s",
2341 ada_demangle (exp->elts[pc + 5].name));
2344 exp->elts[pc + 3].opcode = exp->elts[pc + 6].opcode = OP_VAR_VALUE;
2345 exp->elts[pc + 4].block = candidate_blocks[i];
2346 exp->elts[pc + 5].symbol = candidate_syms[i];
2347 if (innermost_block == NULL ||
2348 contained_in (candidate_blocks[i], innermost_block))
2349 innermost_block = candidate_blocks[i];
2361 case BINOP_BITWISE_AND:
2362 case BINOP_BITWISE_IOR:
2363 case BINOP_BITWISE_XOR:
2365 case BINOP_NOTEQUAL:
2373 case UNOP_LOGICAL_NOT:
2375 if (possible_user_operator_p (op, argvec))
2377 struct symbol** candidate_syms;
2378 struct block** candidate_blocks;
2381 n_candidates = ada_lookup_symbol_list (ada_mangle (ada_op_name (op)),
2382 (struct block*) NULL,
2386 i = ada_resolve_function (candidate_syms, candidate_blocks,
2387 n_candidates, argvec, nargs,
2388 ada_op_name (op), NULL);
2392 replace_operator_with_call (expp, pc, nargs, 1,
2393 candidate_syms[i], candidate_blocks[i]);
2400 return evaluate_subexp_type (exp, pos);
2403 /* Return non-zero if formal type FTYPE matches actual type ATYPE. If
2404 MAY_DEREF is non-zero, the formal may be a pointer and the actual
2406 /* The term "match" here is rather loose. The match is heuristic and
2407 liberal. FIXME: TOO liberal, in fact. */
2410 ada_type_match (ftype, atype, may_deref)
2415 CHECK_TYPEDEF (ftype);
2416 CHECK_TYPEDEF (atype);
2418 if (TYPE_CODE (ftype) == TYPE_CODE_REF)
2419 ftype = TYPE_TARGET_TYPE (ftype);
2420 if (TYPE_CODE (atype) == TYPE_CODE_REF)
2421 atype = TYPE_TARGET_TYPE (atype);
2423 if (TYPE_CODE (ftype) == TYPE_CODE_VOID
2424 || TYPE_CODE (atype) == TYPE_CODE_VOID)
2427 switch (TYPE_CODE (ftype))
2432 if (TYPE_CODE (atype) == TYPE_CODE_PTR)
2433 return ada_type_match (TYPE_TARGET_TYPE (ftype),
2434 TYPE_TARGET_TYPE (atype), 0);
2435 else return (may_deref &&
2436 ada_type_match (TYPE_TARGET_TYPE (ftype), atype, 0));
2438 case TYPE_CODE_ENUM:
2439 case TYPE_CODE_RANGE:
2440 switch (TYPE_CODE (atype))
2443 case TYPE_CODE_ENUM:
2444 case TYPE_CODE_RANGE:
2450 case TYPE_CODE_ARRAY:
2451 return (TYPE_CODE (atype) == TYPE_CODE_ARRAY
2452 || ada_is_array_descriptor (atype));
2454 case TYPE_CODE_STRUCT:
2455 if (ada_is_array_descriptor (ftype))
2456 return (TYPE_CODE (atype) == TYPE_CODE_ARRAY
2457 || ada_is_array_descriptor (atype));
2459 return (TYPE_CODE (atype) == TYPE_CODE_STRUCT
2460 && ! ada_is_array_descriptor (atype));
2462 case TYPE_CODE_UNION:
2464 return (TYPE_CODE (atype) == TYPE_CODE (ftype));
2468 /* Return non-zero if the formals of FUNC "sufficiently match" the
2469 vector of actual argument types ACTUALS of size N_ACTUALS. FUNC
2470 may also be an enumeral, in which case it is treated as a 0-
2471 argument function. */
2474 ada_args_match (func, actuals, n_actuals)
2475 struct symbol* func;
2476 struct value** actuals;
2480 struct type* func_type = SYMBOL_TYPE (func);
2482 if (SYMBOL_CLASS (func) == LOC_CONST &&
2483 TYPE_CODE (func_type) == TYPE_CODE_ENUM)
2484 return (n_actuals == 0);
2485 else if (func_type == NULL || TYPE_CODE (func_type) != TYPE_CODE_FUNC)
2488 if (TYPE_NFIELDS (func_type) != n_actuals)
2491 for (i = 0; i < n_actuals; i += 1)
2493 struct type* ftype = check_typedef (TYPE_FIELD_TYPE (func_type, i));
2494 struct type* atype = check_typedef (VALUE_TYPE (actuals[i]));
2496 if (! ada_type_match (TYPE_FIELD_TYPE (func_type, i),
2497 VALUE_TYPE (actuals[i]), 1))
2503 /* False iff function type FUNC_TYPE definitely does not produce a value
2504 compatible with type CONTEXT_TYPE. Conservatively returns 1 if
2505 FUNC_TYPE is not a valid function type with a non-null return type
2506 or an enumerated type. A null CONTEXT_TYPE indicates any non-void type. */
2509 return_match (func_type, context_type)
2510 struct type* func_type;
2511 struct type* context_type;
2513 struct type* return_type;
2515 if (func_type == NULL)
2518 /* FIXME: base_type should be declared in gdbtypes.h, implemented in valarith.c */
2519 /* if (TYPE_CODE (func_type) == TYPE_CODE_FUNC)
2520 return_type = base_type (TYPE_TARGET_TYPE (func_type));
2522 return_type = base_type (func_type);*/
2523 if (return_type == NULL)
2526 /* FIXME: base_type should be declared in gdbtypes.h, implemented in valarith.c */
2527 /* context_type = base_type (context_type);*/
2529 if (TYPE_CODE (return_type) == TYPE_CODE_ENUM)
2530 return context_type == NULL || return_type == context_type;
2531 else if (context_type == NULL)
2532 return TYPE_CODE (return_type) != TYPE_CODE_VOID;
2534 return TYPE_CODE (return_type) == TYPE_CODE (context_type);
2538 /* Return the index in SYMS[0..NSYMS-1] of symbol for the
2539 function (if any) that matches the types of the NARGS arguments in
2540 ARGS. If CONTEXT_TYPE is non-null, and there is at least one match
2541 that returns type CONTEXT_TYPE, then eliminate other matches. If
2542 CONTEXT_TYPE is null, prefer a non-void-returning function.
2543 Asks the user if there is more than one match remaining. Returns -1
2544 if there is no such symbol or none is selected. NAME is used
2545 solely for messages. May re-arrange and modify SYMS in
2546 the process; the index returned is for the modified vector. BLOCKS
2547 is modified in parallel to SYMS. */
2550 ada_resolve_function (syms, blocks, nsyms, args, nargs, name, context_type)
2551 struct symbol* syms[];
2552 struct block* blocks[];
2553 struct value** args;
2556 struct type* context_type;
2559 int m; /* Number of hits */
2560 struct type* fallback;
2561 struct type* return_type;
2563 return_type = context_type;
2564 if (context_type == NULL)
2565 fallback = builtin_type_void;
2572 for (k = 0; k < nsyms; k += 1)
2574 struct type* type = check_typedef (SYMBOL_TYPE (syms[k]));
2576 if (ada_args_match (syms[k], args, nargs)
2577 && return_match (SYMBOL_TYPE (syms[k]), return_type))
2581 blocks[m] = blocks[k];
2585 if (m > 0 || return_type == fallback)
2588 return_type = fallback;
2595 printf_filtered ("Multiple matches for %s\n", name);
2596 user_select_syms (syms, blocks, m, 1);
2602 /* Returns true (non-zero) iff demangled name N0 should appear before N1 */
2603 /* in a listing of choices during disambiguation (see sort_choices, below). */
2604 /* The idea is that overloadings of a subprogram name from the */
2605 /* same package should sort in their source order. We settle for ordering */
2606 /* such symbols by their trailing number (__N or $N). */
2608 mangled_ordered_before (char* N0, char* N1)
2612 else if (N0 == NULL)
2617 for (k0 = strlen (N0)-1; k0 > 0 && isdigit (N0[k0]); k0 -= 1)
2619 for (k1 = strlen (N1)-1; k1 > 0 && isdigit (N1[k1]); k1 -= 1)
2621 if ((N0[k0] == '_' || N0[k0] == '$') && N0[k0+1] != '\000'
2622 && (N1[k1] == '_' || N1[k1] == '$') && N1[k1+1] != '\000')
2626 while (N0[n0] == '_' && n0 > 0 && N0[n0-1] == '_')
2629 while (N1[n1] == '_' && n1 > 0 && N1[n1-1] == '_')
2631 if (n0 == n1 && STREQN (N0, N1, n0))
2632 return (atoi (N0+k0+1) < atoi (N1+k1+1));
2634 return (strcmp (N0, N1) < 0);
2638 /* Sort SYMS[0..NSYMS-1] to put the choices in a canonical order by their */
2639 /* mangled names, rearranging BLOCKS[0..NSYMS-1] according to the same */
2642 sort_choices (syms, blocks, nsyms)
2643 struct symbol* syms[];
2644 struct block* blocks[];
2648 for (i = 1; i < nsyms; i += 1)
2650 struct symbol* sym = syms[i];
2651 struct block* block = blocks[i];
2654 for (j = i-1; j >= 0; j -= 1)
2656 if (mangled_ordered_before (SYMBOL_NAME (syms[j]),
2659 syms[j+1] = syms[j];
2660 blocks[j+1] = blocks[j];
2663 blocks[j+1] = block;
2667 /* Given a list of NSYMS symbols in SYMS and corresponding blocks in */
2668 /* BLOCKS, select up to MAX_RESULTS>0 by asking the user (if */
2669 /* necessary), returning the number selected, and setting the first */
2670 /* elements of SYMS and BLOCKS to the selected symbols and */
2671 /* corresponding blocks. Error if no symbols selected. BLOCKS may */
2672 /* be NULL, in which case it is ignored. */
2674 /* NOTE: Adapted from decode_line_2 in symtab.c, with which it ought
2675 to be re-integrated one of these days. */
2678 user_select_syms (syms, blocks, nsyms, max_results)
2679 struct symbol* syms[];
2680 struct block* blocks[];
2685 int* chosen = (int*) alloca (sizeof(int) * nsyms);
2687 int first_choice = (max_results == 1) ? 1 : 2;
2689 if (max_results < 1)
2690 error ("Request to select 0 symbols!");
2694 printf_unfiltered("[0] cancel\n");
2695 if (max_results > 1)
2696 printf_unfiltered("[1] all\n");
2698 sort_choices (syms, blocks, nsyms);
2700 for (i = 0; i < nsyms; i += 1)
2702 if (syms[i] == NULL)
2705 if (SYMBOL_CLASS (syms[i]) == LOC_BLOCK)
2707 struct symtab_and_line sal = find_function_start_sal (syms[i], 1);
2708 printf_unfiltered ("[%d] %s at %s:%d\n",
2710 SYMBOL_SOURCE_NAME (syms[i]),
2712 ? "<no source file available>"
2713 : sal.symtab->filename,
2720 (SYMBOL_CLASS (syms[i]) == LOC_CONST
2721 && SYMBOL_TYPE (syms[i]) != NULL
2722 && TYPE_CODE (SYMBOL_TYPE (syms[i]))
2724 struct symtab* symtab = symtab_for_sym (syms[i]);
2726 if (SYMBOL_LINE (syms[i]) != 0 && symtab != NULL)
2727 printf_unfiltered ("[%d] %s at %s:%d\n",
2729 SYMBOL_SOURCE_NAME (syms[i]),
2730 symtab->filename, SYMBOL_LINE (syms[i]));
2731 else if (is_enumeral &&
2732 TYPE_NAME (SYMBOL_TYPE (syms[i])) != NULL)
2734 printf_unfiltered ("[%d] ", i + first_choice);
2735 ada_print_type (SYMBOL_TYPE (syms[i]), NULL, gdb_stdout, -1, 0);
2736 printf_unfiltered ("'(%s) (enumeral)\n",
2737 SYMBOL_SOURCE_NAME (syms[i]));
2739 else if (symtab != NULL)
2740 printf_unfiltered (is_enumeral
2741 ? "[%d] %s in %s (enumeral)\n"
2742 : "[%d] %s at %s:?\n",
2744 SYMBOL_SOURCE_NAME (syms[i]),
2747 printf_unfiltered (is_enumeral
2748 ? "[%d] %s (enumeral)\n"
2750 i + first_choice, SYMBOL_SOURCE_NAME (syms[i]));
2754 n_chosen = get_selections (chosen, nsyms, max_results, max_results > 1,
2757 for (i = 0; i < n_chosen; i += 1)
2759 syms[i] = syms[chosen[i]];
2761 blocks[i] = blocks[chosen[i]];
2767 /* Read and validate a set of numeric choices from the user in the
2768 range 0 .. N_CHOICES-1. Place the results in increasing
2769 order in CHOICES[0 .. N-1], and return N.
2771 The user types choices as a sequence of numbers on one line
2772 separated by blanks, encoding them as follows:
2774 + A choice of 0 means to cancel the selection, throwing an error.
2775 + If IS_ALL_CHOICE, a choice of 1 selects the entire set 0 .. N_CHOICES-1.
2776 + The user chooses k by typing k+IS_ALL_CHOICE+1.
2778 The user is not allowed to choose more than MAX_RESULTS values.
2780 ANNOTATION_SUFFIX, if present, is used to annotate the input
2781 prompts (for use with the -f switch). */
2784 get_selections (choices, n_choices, max_results, is_all_choice,
2790 char* annotation_suffix;
2796 int first_choice = is_all_choice ? 2 : 1;
2798 prompt = getenv ("PS2");
2802 printf_unfiltered ("%s ", prompt);
2803 gdb_flush (gdb_stdout);
2805 args = command_line_input ((char *) NULL, 0, annotation_suffix);
2808 error_no_arg ("one or more choice numbers");
2812 /* Set choices[0 .. n_chosen-1] to the users' choices in ascending
2813 order, as given in args. Choices are validated. */
2819 while (isspace (*args))
2821 if (*args == '\0' && n_chosen == 0)
2822 error_no_arg ("one or more choice numbers");
2823 else if (*args == '\0')
2826 choice = strtol (args, &args2, 10);
2827 if (args == args2 || choice < 0 || choice > n_choices + first_choice - 1)
2828 error ("Argument must be choice number");
2832 error ("cancelled");
2834 if (choice < first_choice)
2836 n_chosen = n_choices;
2837 for (j = 0; j < n_choices; j += 1)
2841 choice -= first_choice;
2843 for (j = n_chosen-1; j >= 0 && choice < choices[j]; j -= 1)
2846 if (j < 0 || choice != choices[j])
2849 for (k = n_chosen-1; k > j; k -= 1)
2850 choices[k+1] = choices[k];
2851 choices[j+1] = choice;
2856 if (n_chosen > max_results)
2857 error ("Select no more than %d of the above", max_results);
2862 /* Replace the operator of length OPLEN at position PC in *EXPP with a call */
2863 /* on the function identified by SYM and BLOCK, and taking NARGS */
2864 /* arguments. Update *EXPP as needed to hold more space. */
2867 replace_operator_with_call (expp, pc, nargs, oplen, sym, block)
2868 struct expression** expp;
2869 int pc, nargs, oplen;
2871 struct block* block;
2873 /* A new expression, with 6 more elements (3 for funcall, 4 for function
2874 symbol, -oplen for operator being replaced). */
2875 struct expression* newexp = (struct expression*)
2876 xmalloc (sizeof (struct expression)
2877 + EXP_ELEM_TO_BYTES ((*expp)->nelts + 7 - oplen));
2878 struct expression* exp = *expp;
2880 newexp->nelts = exp->nelts + 7 - oplen;
2881 newexp->language_defn = exp->language_defn;
2882 memcpy (newexp->elts, exp->elts, EXP_ELEM_TO_BYTES (pc));
2883 memcpy (newexp->elts + pc + 7, exp->elts + pc + oplen,
2884 EXP_ELEM_TO_BYTES (exp->nelts - pc - oplen));
2886 newexp->elts[pc].opcode = newexp->elts[pc + 2].opcode = OP_FUNCALL;
2887 newexp->elts[pc + 1].longconst = (LONGEST) nargs;
2889 newexp->elts[pc + 3].opcode = newexp->elts[pc + 6].opcode = OP_VAR_VALUE;
2890 newexp->elts[pc + 4].block = block;
2891 newexp->elts[pc + 5].symbol = sym;
2897 /* Type-class predicates */
2899 /* True iff TYPE is numeric (i.e., an INT, RANGE (of numeric type), or */
2903 numeric_type_p (type)
2909 switch (TYPE_CODE (type))
2914 case TYPE_CODE_RANGE:
2915 return (type == TYPE_TARGET_TYPE (type)
2916 || numeric_type_p (TYPE_TARGET_TYPE (type)));
2923 /* True iff TYPE is integral (an INT or RANGE of INTs). */
2926 integer_type_p (type)
2932 switch (TYPE_CODE (type))
2936 case TYPE_CODE_RANGE:
2937 return (type == TYPE_TARGET_TYPE (type)
2938 || integer_type_p (TYPE_TARGET_TYPE (type)));
2945 /* True iff TYPE is scalar (INT, RANGE, FLOAT, ENUM). */
2948 scalar_type_p (type)
2954 switch (TYPE_CODE (type))
2957 case TYPE_CODE_RANGE:
2958 case TYPE_CODE_ENUM:
2967 /* True iff TYPE is discrete (INT, RANGE, ENUM). */
2970 discrete_type_p (type)
2976 switch (TYPE_CODE (type))
2979 case TYPE_CODE_RANGE:
2980 case TYPE_CODE_ENUM:
2988 /* Returns non-zero if OP with operatands in the vector ARGS could be
2989 a user-defined function. Errs on the side of pre-defined operators
2990 (i.e., result 0). */
2993 possible_user_operator_p (op, args)
2995 struct value* args[];
2997 struct type* type0 = check_typedef (VALUE_TYPE (args[0]));
2998 struct type* type1 =
2999 (args[1] == NULL) ? NULL : check_typedef (VALUE_TYPE (args[1]));
3010 return (! (numeric_type_p (type0) && numeric_type_p (type1)));
3014 case BINOP_BITWISE_AND:
3015 case BINOP_BITWISE_IOR:
3016 case BINOP_BITWISE_XOR:
3017 return (! (integer_type_p (type0) && integer_type_p (type1)));
3020 case BINOP_NOTEQUAL:
3025 return (! (scalar_type_p (type0) && scalar_type_p (type1)));
3028 return ((TYPE_CODE (type0) != TYPE_CODE_ARRAY &&
3029 (TYPE_CODE (type0) != TYPE_CODE_PTR ||
3030 TYPE_CODE (TYPE_TARGET_TYPE (type0))
3031 != TYPE_CODE_ARRAY))
3032 || (TYPE_CODE (type1) != TYPE_CODE_ARRAY &&
3033 (TYPE_CODE (type1) != TYPE_CODE_PTR ||
3034 TYPE_CODE (TYPE_TARGET_TYPE (type1))
3035 != TYPE_CODE_ARRAY)));
3038 return (! (numeric_type_p (type0) && integer_type_p (type1)));
3042 case UNOP_LOGICAL_NOT:
3044 return (! numeric_type_p (type0));
3051 /** NOTE: In the following, we assume that a renaming type's name may
3052 * have an ___XD suffix. It would be nice if this went away at some
3055 /* If TYPE encodes a renaming, returns the renaming suffix, which
3056 * is XR for an object renaming, XRP for a procedure renaming, XRE for
3057 * an exception renaming, and XRS for a subprogram renaming. Returns
3058 * NULL if NAME encodes none of these. */
3060 ada_renaming_type (type)
3063 if (type != NULL && TYPE_CODE (type) == TYPE_CODE_ENUM)
3065 const char* name = type_name_no_tag (type);
3066 const char* suffix = (name == NULL) ? NULL : strstr (name, "___XR");
3068 || (suffix[5] != '\000' && strchr ("PES_", suffix[5]) == NULL))
3077 /* Return non-zero iff SYM encodes an object renaming. */
3079 ada_is_object_renaming (sym)
3082 const char* renaming_type = ada_renaming_type (SYMBOL_TYPE (sym));
3083 return renaming_type != NULL
3084 && (renaming_type[2] == '\0' || renaming_type[2] == '_');
3087 /* Assuming that SYM encodes a non-object renaming, returns the original
3088 * name of the renamed entity. The name is good until the end of
3091 ada_simple_renamed_entity (sym)
3095 const char* raw_name;
3099 type = SYMBOL_TYPE (sym);
3100 if (type == NULL || TYPE_NFIELDS (type) < 1)
3101 error ("Improperly encoded renaming.");
3103 raw_name = TYPE_FIELD_NAME (type, 0);
3104 len = (raw_name == NULL ? 0 : strlen (raw_name)) - 5;
3106 error ("Improperly encoded renaming.");
3108 result = xmalloc (len + 1);
3109 /* FIXME: add_name_string_cleanup should be defined in parse.c */
3110 /* add_name_string_cleanup (result);*/
3111 strncpy (result, raw_name, len);
3112 result[len] = '\000';
3117 /* Evaluation: Function Calls */
3119 /* Copy VAL onto the stack, using and updating *SP as the stack
3120 pointer. Return VAL as an lvalue. */
3122 static struct value*
3123 place_on_stack (val, sp)
3127 CORE_ADDR old_sp = *sp;
3130 *sp = push_bytes (*sp, VALUE_CONTENTS_RAW (val),
3131 STACK_ALIGN (TYPE_LENGTH (check_typedef (VALUE_TYPE (val)))));
3133 *sp = push_bytes (*sp, VALUE_CONTENTS_RAW (val),
3134 TYPE_LENGTH (check_typedef (VALUE_TYPE (val))));
3137 VALUE_LVAL (val) = lval_memory;
3138 if (INNER_THAN (1, 2))
3139 VALUE_ADDRESS (val) = *sp;
3141 VALUE_ADDRESS (val) = old_sp;
3146 /* Return the value ACTUAL, converted to be an appropriate value for a
3147 formal of type FORMAL_TYPE. Use *SP as a stack pointer for
3148 allocating any necessary descriptors (fat pointers), or copies of
3149 values not residing in memory, updating it as needed. */
3151 static struct value*
3152 convert_actual (actual, formal_type0, sp)
3153 struct value* actual;
3154 struct type* formal_type0;
3157 struct type* actual_type = check_typedef (VALUE_TYPE (actual));
3158 struct type* formal_type = check_typedef (formal_type0);
3159 struct type* formal_target =
3160 TYPE_CODE (formal_type) == TYPE_CODE_PTR
3161 ? check_typedef (TYPE_TARGET_TYPE (formal_type)) : formal_type;
3162 struct type* actual_target =
3163 TYPE_CODE (actual_type) == TYPE_CODE_PTR
3164 ? check_typedef (TYPE_TARGET_TYPE (actual_type)) : actual_type;
3166 if (ada_is_array_descriptor (formal_target)
3167 && TYPE_CODE (actual_target) == TYPE_CODE_ARRAY)
3168 return make_array_descriptor (formal_type, actual, sp);
3169 else if (TYPE_CODE (formal_type) == TYPE_CODE_PTR)
3171 if (TYPE_CODE (formal_target) == TYPE_CODE_ARRAY
3172 && ada_is_array_descriptor (actual_target))
3173 return desc_data (actual);
3174 else if (TYPE_CODE (actual_type) != TYPE_CODE_PTR)
3176 if (VALUE_LVAL (actual) != lval_memory)
3179 actual_type = check_typedef (VALUE_TYPE (actual));
3180 val = allocate_value (actual_type);
3181 memcpy ((char*) VALUE_CONTENTS_RAW (val),
3182 (char*) VALUE_CONTENTS (actual),
3183 TYPE_LENGTH (actual_type));
3184 actual = place_on_stack (val, sp);
3186 return value_addr (actual);
3189 else if (TYPE_CODE (actual_type) == TYPE_CODE_PTR)
3190 return ada_value_ind (actual);
3196 /* Push a descriptor of type TYPE for array value ARR on the stack at
3197 *SP, updating *SP to reflect the new descriptor. Return either
3198 an lvalue representing the new descriptor, or (if TYPE is a pointer-
3199 to-descriptor type rather than a descriptor type), a struct value*
3200 representing a pointer to this descriptor. */
3202 static struct value*
3203 make_array_descriptor (type, arr, sp)
3208 struct type* bounds_type = desc_bounds_type (type);
3209 struct type* desc_type = desc_base_type (type);
3210 struct value* descriptor = allocate_value (desc_type);
3211 struct value* bounds = allocate_value (bounds_type);
3212 CORE_ADDR bounds_addr;
3215 for (i = ada_array_arity (check_typedef (VALUE_TYPE (arr))); i > 0; i -= 1)
3217 modify_general_field (VALUE_CONTENTS (bounds),
3218 value_as_long (ada_array_bound (arr, i, 0)),
3219 desc_bound_bitpos (bounds_type, i, 0),
3220 desc_bound_bitsize (bounds_type, i, 0));
3221 modify_general_field (VALUE_CONTENTS (bounds),
3222 value_as_long (ada_array_bound (arr, i, 1)),
3223 desc_bound_bitpos (bounds_type, i, 1),
3224 desc_bound_bitsize (bounds_type, i, 1));
3227 bounds = place_on_stack (bounds, sp);
3229 modify_general_field (VALUE_CONTENTS (descriptor),
3231 fat_pntr_data_bitpos (desc_type),
3232 fat_pntr_data_bitsize (desc_type));
3233 modify_general_field (VALUE_CONTENTS (descriptor),
3234 VALUE_ADDRESS (bounds),
3235 fat_pntr_bounds_bitpos (desc_type),
3236 fat_pntr_bounds_bitsize (desc_type));
3238 descriptor = place_on_stack (descriptor, sp);
3240 if (TYPE_CODE (type) == TYPE_CODE_PTR)
3241 return value_addr (descriptor);
3247 /* Assuming a dummy frame has been established on the target, perform any
3248 conversions needed for calling function FUNC on the NARGS actual
3249 parameters in ARGS, other than standard C conversions. Does
3250 nothing if FUNC does not have Ada-style prototype data, or if NARGS
3251 does not match the number of arguments expected. Use *SP as a
3252 stack pointer for additional data that must be pushed, updating its
3256 ada_convert_actuals (func, nargs, args, sp)
3259 struct value* args[];
3264 if (TYPE_NFIELDS (VALUE_TYPE (func)) == 0
3265 || nargs != TYPE_NFIELDS (VALUE_TYPE (func)))
3268 for (i = 0; i < nargs; i += 1)
3270 convert_actual (args[i],
3271 TYPE_FIELD_TYPE (VALUE_TYPE (func), i),
3279 /* The vectors of symbols and blocks ultimately returned from */
3280 /* ada_lookup_symbol_list. */
3282 /* Current size of defn_symbols and defn_blocks */
3283 static size_t defn_vector_size = 0;
3285 /* Current number of symbols found. */
3286 static int ndefns = 0;
3288 static struct symbol** defn_symbols = NULL;
3289 static struct block** defn_blocks = NULL;
3291 /* Return the result of a standard (literal, C-like) lookup of NAME in
3292 * given NAMESPACE. */
3294 static struct symbol*
3295 standard_lookup (name, namespace)
3297 namespace_enum namespace;
3300 struct symtab* symtab;
3301 sym = lookup_symbol (name, (struct block*) NULL, namespace, 0, &symtab);
3306 /* Non-zero iff there is at least one non-function/non-enumeral symbol */
3307 /* in SYMS[0..N-1]. We treat enumerals as functions, since they */
3308 /* contend in overloading in the same way. */
3310 is_nonfunction (syms, n)
3311 struct symbol* syms[];
3316 for (i = 0; i < n; i += 1)
3317 if (TYPE_CODE (SYMBOL_TYPE (syms[i])) != TYPE_CODE_FUNC
3318 && TYPE_CODE (SYMBOL_TYPE (syms[i])) != TYPE_CODE_ENUM)
3324 /* If true (non-zero), then TYPE0 and TYPE1 represent equivalent
3325 struct types. Otherwise, they may not. */
3328 equiv_types (type0, type1)
3334 if (type0 == NULL || type1 == NULL
3335 || TYPE_CODE (type0) != TYPE_CODE (type1))
3337 if ((TYPE_CODE (type0) == TYPE_CODE_STRUCT
3338 || TYPE_CODE (type0) == TYPE_CODE_ENUM)
3339 && ada_type_name (type0) != NULL && ada_type_name (type1) != NULL
3340 && STREQ (ada_type_name (type0), ada_type_name (type1)))
3346 /* True iff SYM0 represents the same entity as SYM1, or one that is
3347 no more defined than that of SYM1. */
3350 lesseq_defined_than (sym0, sym1)
3351 struct symbol* sym0;
3352 struct symbol* sym1;
3356 if (SYMBOL_NAMESPACE (sym0) != SYMBOL_NAMESPACE (sym1)
3357 || SYMBOL_CLASS (sym0) != SYMBOL_CLASS (sym1))
3360 switch (SYMBOL_CLASS (sym0))
3366 struct type* type0 = SYMBOL_TYPE (sym0);
3367 struct type* type1 = SYMBOL_TYPE (sym1);
3368 char* name0 = SYMBOL_NAME (sym0);
3369 char* name1 = SYMBOL_NAME (sym1);
3370 int len0 = strlen (name0);
3372 TYPE_CODE (type0) == TYPE_CODE (type1)
3373 && (equiv_types (type0, type1)
3374 || (len0 < strlen (name1) && STREQN (name0, name1, len0)
3375 && STREQN (name1 + len0, "___XV", 5)));
3378 return SYMBOL_VALUE (sym0) == SYMBOL_VALUE (sym1)
3379 && equiv_types (SYMBOL_TYPE (sym0), SYMBOL_TYPE (sym1));
3385 /* Append SYM to the end of defn_symbols, and BLOCK to the end of
3386 defn_blocks, updating ndefns, and expanding defn_symbols and
3387 defn_blocks as needed. Do not include SYM if it is a duplicate. */
3390 add_defn_to_vec (sym, block)
3392 struct block* block;
3397 if (SYMBOL_TYPE (sym) != NULL)
3398 CHECK_TYPEDEF (SYMBOL_TYPE (sym));
3399 for (i = 0; i < ndefns; i += 1)
3401 if (lesseq_defined_than (sym, defn_symbols[i]))
3403 else if (lesseq_defined_than (defn_symbols[i], sym))
3405 defn_symbols[i] = sym;
3406 defn_blocks[i] = block;
3411 tmp = defn_vector_size;
3412 GROW_VECT (defn_symbols, tmp, ndefns+2);
3413 GROW_VECT (defn_blocks, defn_vector_size, ndefns+2);
3415 defn_symbols[ndefns] = sym;
3416 defn_blocks[ndefns] = block;
3420 /* Look, in partial_symtab PST, for symbol NAME in given namespace.
3421 Check the global symbols if GLOBAL, the static symbols if not. Do
3422 wild-card match if WILD. */
3424 static struct partial_symbol *
3425 ada_lookup_partial_symbol (pst, name, global, namespace, wild)
3426 struct partial_symtab *pst;
3429 namespace_enum namespace;
3432 struct partial_symbol **start;
3433 int name_len = strlen (name);
3434 int length = (global ? pst->n_global_syms : pst->n_static_syms);
3443 pst->objfile->global_psymbols.list + pst->globals_offset :
3444 pst->objfile->static_psymbols.list + pst->statics_offset );
3448 for (i = 0; i < length; i += 1)
3450 struct partial_symbol* psym = start[i];
3452 if (SYMBOL_NAMESPACE (psym) == namespace &&
3453 wild_match (name, name_len, SYMBOL_NAME (psym)))
3463 i = 0; U = length-1;
3467 struct partial_symbol* psym = start[M];
3468 if (SYMBOL_NAME (psym)[0] < name[0])
3470 else if (SYMBOL_NAME (psym)[0] > name[0])
3472 else if (strcmp (SYMBOL_NAME (psym), name) < 0)
3483 struct partial_symbol *psym = start[i];
3485 if (SYMBOL_NAMESPACE (psym) == namespace)
3487 int cmp = strncmp (name, SYMBOL_NAME (psym), name_len);
3495 && is_name_suffix (SYMBOL_NAME (psym) + name_len))
3504 i = 0; U = length-1;
3508 struct partial_symbol *psym = start[M];
3509 if (SYMBOL_NAME (psym)[0] < '_')
3511 else if (SYMBOL_NAME (psym)[0] > '_')
3513 else if (strcmp (SYMBOL_NAME (psym), "_ada_") < 0)
3524 struct partial_symbol* psym = start[i];
3526 if (SYMBOL_NAMESPACE (psym) == namespace)
3530 cmp = (int) '_' - (int) SYMBOL_NAME (psym)[0];
3533 cmp = strncmp ("_ada_", SYMBOL_NAME (psym), 5);
3535 cmp = strncmp (name, SYMBOL_NAME (psym) + 5, name_len);
3544 && is_name_suffix (SYMBOL_NAME (psym) + name_len + 5))
3555 /* Find a symbol table containing symbol SYM or NULL if none. */
3556 static struct symtab*
3557 symtab_for_sym (sym)
3561 struct objfile *objfile;
3563 struct symbol *tmp_sym;
3566 ALL_SYMTABS (objfile, s)
3568 switch (SYMBOL_CLASS (sym))
3576 case LOC_CONST_BYTES:
3577 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK);
3578 ALL_BLOCK_SYMBOLS (b, i, tmp_sym)
3581 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK);
3582 ALL_BLOCK_SYMBOLS (b, i, tmp_sym)
3589 switch (SYMBOL_CLASS (sym))
3595 case LOC_REGPARM_ADDR:
3600 case LOC_BASEREG_ARG:
3601 for (j = FIRST_LOCAL_BLOCK;
3602 j < BLOCKVECTOR_NBLOCKS (BLOCKVECTOR (s)); j += 1)
3604 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), j);
3605 ALL_BLOCK_SYMBOLS (b, i, tmp_sym)
3617 /* Return a minimal symbol matching NAME according to Ada demangling
3618 rules. Returns NULL if there is no such minimal symbol. */
3620 struct minimal_symbol*
3621 ada_lookup_minimal_symbol (name)
3624 struct objfile* objfile;
3625 struct minimal_symbol* msymbol;
3626 int wild_match = (strstr (name, "__") == NULL);
3628 ALL_MSYMBOLS (objfile, msymbol)
3630 if (ada_match_name (SYMBOL_NAME (msymbol), name, wild_match)
3631 && MSYMBOL_TYPE (msymbol) != mst_solib_trampoline)
3638 /* For all subprograms that statically enclose the subprogram of the
3639 * selected frame, add symbols matching identifier NAME in NAMESPACE
3640 * and their blocks to vectors *defn_symbols and *defn_blocks, as for
3641 * ada_add_block_symbols (q.v.). If WILD, treat as NAME with a
3642 * wildcard prefix. At the moment, this function uses a heuristic to
3643 * find the frames of enclosing subprograms: it treats the
3644 * pointer-sized value at location 0 from the local-variable base of a
3645 * frame as a static link, and then searches up the call stack for a
3646 * frame with that same local-variable base. */
3648 add_symbols_from_enclosing_procs (name, namespace, wild_match)
3650 namespace_enum namespace;
3654 static struct symbol static_link_sym;
3655 static struct symbol *static_link;
3657 struct cleanup* old_chain = make_cleanup (null_cleanup, NULL);
3658 struct frame_info* frame;
3659 struct frame_info* target_frame;
3661 if (static_link == NULL)
3663 /* Initialize the local variable symbol that stands for the
3664 * static link (when it exists). */
3665 static_link = &static_link_sym;
3666 SYMBOL_NAME (static_link) = "";
3667 SYMBOL_LANGUAGE (static_link) = language_unknown;
3668 SYMBOL_CLASS (static_link) = LOC_LOCAL;
3669 SYMBOL_NAMESPACE (static_link) = VAR_NAMESPACE;
3670 SYMBOL_TYPE (static_link) = lookup_pointer_type (builtin_type_void);
3671 SYMBOL_VALUE (static_link) =
3672 - (long) TYPE_LENGTH (SYMBOL_TYPE (static_link));
3675 frame = selected_frame;
3676 while (frame != NULL && ndefns == 0)
3678 struct block* block;
3679 struct value* target_link_val = read_var_value (static_link, frame);
3680 CORE_ADDR target_link;
3682 if (target_link_val == NULL)
3686 target_link = target_link_val;
3689 frame = get_prev_frame (frame);
3690 } while (frame != NULL && FRAME_LOCALS_ADDRESS (frame) != target_link);
3695 block = get_frame_block (frame, 0);
3696 while (block != NULL && block_function (block) != NULL && ndefns == 0)
3698 ada_add_block_symbols (block, name, namespace, NULL, wild_match);
3700 block = BLOCK_SUPERBLOCK (block);
3704 do_cleanups (old_chain);
3708 /* True if TYPE is definitely an artificial type supplied to a symbol
3709 * for which no debugging information was given in the symbol file. */
3711 is_nondebugging_type (type)
3714 char* name = ada_type_name (type);
3715 return (name != NULL && STREQ (name, "<variable, no debug info>"));
3718 /* Remove any non-debugging symbols in SYMS[0 .. NSYMS-1] that definitely
3719 * duplicate other symbols in the list. (The only case I know of where
3720 * this happens is when object files containing stabs-in-ecoff are
3721 * linked with files containing ordinary ecoff debugging symbols (or no
3722 * debugging symbols)). Modifies SYMS to squeeze out deleted symbols,
3723 * and applies the same modification to BLOCKS to maintain the
3724 * correspondence between SYMS[i] and BLOCKS[i]. Returns the number
3725 * of symbols in the modified list. */
3727 remove_extra_symbols (syms, blocks, nsyms)
3728 struct symbol** syms;
3729 struct block** blocks;
3737 if (SYMBOL_NAME (syms[i]) != NULL && SYMBOL_CLASS (syms[i]) == LOC_STATIC
3738 && is_nondebugging_type (SYMBOL_TYPE (syms[i])))
3740 for (j = 0; j < nsyms; j += 1)
3743 && SYMBOL_NAME (syms[j]) != NULL
3744 && STREQ (SYMBOL_NAME (syms[i]), SYMBOL_NAME (syms[j]))
3745 && SYMBOL_CLASS (syms[i]) == SYMBOL_CLASS (syms[j])
3746 && SYMBOL_VALUE_ADDRESS (syms[i])
3747 == SYMBOL_VALUE_ADDRESS (syms[j]))
3750 for (k = i+1; k < nsyms; k += 1)
3752 syms[k-1] = syms[k];
3753 blocks[k-1] = blocks[k];
3767 /* Find symbols in NAMESPACE matching NAME, in BLOCK0 and enclosing
3768 scope and in global scopes, returning the number of matches. Sets
3769 *SYMS to point to a vector of matching symbols, with *BLOCKS
3770 pointing to the vector of corresponding blocks in which those
3771 symbols reside. These two vectors are transient---good only to the
3772 next call of ada_lookup_symbol_list. Any non-function/non-enumeral symbol
3773 match within the nest of blocks whose innermost member is BLOCK0,
3774 is the outermost match returned (no other matches in that or
3775 enclosing blocks is returned). If there are any matches in or
3776 surrounding BLOCK0, then these alone are returned. */
3779 ada_lookup_symbol_list (name, block0, namespace, syms, blocks)
3781 struct block *block0;
3782 namespace_enum namespace;
3783 struct symbol*** syms;
3784 struct block*** blocks;
3788 struct partial_symtab *ps;
3789 struct blockvector *bv;
3790 struct objfile *objfile;
3792 struct block *block;
3793 struct minimal_symbol *msymbol;
3794 int wild_match = (strstr (name, "__") == NULL);
3804 /* Search specified block and its superiors. */
3807 while (block != NULL)
3809 ada_add_block_symbols (block, name, namespace, NULL, wild_match);
3811 /* If we found a non-function match, assume that's the one. */
3812 if (is_nonfunction (defn_symbols, ndefns))
3815 block = BLOCK_SUPERBLOCK (block);
3818 /* If we found ANY matches in the specified BLOCK, we're done. */
3825 /* Now add symbols from all global blocks: symbol tables, minimal symbol
3826 tables, and psymtab's */
3828 ALL_SYMTABS (objfile, s)
3833 bv = BLOCKVECTOR (s);
3834 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
3835 ada_add_block_symbols (block, name, namespace, objfile, wild_match);
3838 if (namespace == VAR_NAMESPACE)
3840 ALL_MSYMBOLS (objfile, msymbol)
3842 if (ada_match_name (SYMBOL_NAME (msymbol), name, wild_match))
3844 switch (MSYMBOL_TYPE (msymbol))
3846 case mst_solib_trampoline:
3849 s = find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol));
3852 int old_ndefns = ndefns;
3854 bv = BLOCKVECTOR (s);
3855 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
3856 ada_add_block_symbols (block,
3857 SYMBOL_NAME (msymbol),
3858 namespace, objfile, wild_match);
3859 if (ndefns == old_ndefns)
3861 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
3862 ada_add_block_symbols (block,
3863 SYMBOL_NAME (msymbol),
3873 ALL_PSYMTABS (objfile, ps)
3877 && ada_lookup_partial_symbol (ps, name, 1, namespace, wild_match))
3879 s = PSYMTAB_TO_SYMTAB (ps);
3882 bv = BLOCKVECTOR (s);
3883 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
3884 ada_add_block_symbols (block, name, namespace, objfile, wild_match);
3888 /* Now add symbols from all per-file blocks if we've gotten no hits.
3889 (Not strictly correct, but perhaps better than an error).
3890 Do the symtabs first, then check the psymtabs */
3895 ALL_SYMTABS (objfile, s)
3900 bv = BLOCKVECTOR (s);
3901 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
3902 ada_add_block_symbols (block, name, namespace, objfile, wild_match);
3905 ALL_PSYMTABS (objfile, ps)
3909 && ada_lookup_partial_symbol (ps, name, 0, namespace, wild_match))
3911 s = PSYMTAB_TO_SYMTAB(ps);
3912 bv = BLOCKVECTOR (s);
3915 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
3916 ada_add_block_symbols (block, name, namespace,
3917 objfile, wild_match);
3922 /* Finally, we try to find NAME as a local symbol in some lexically
3923 enclosing block. We do this last, expecting this case to be
3927 add_symbols_from_enclosing_procs (name, namespace, wild_match);
3933 ndefns = remove_extra_symbols (defn_symbols, defn_blocks, ndefns);
3936 *syms = defn_symbols;
3937 *blocks = defn_blocks;
3944 /* Return a symbol in NAMESPACE matching NAME, in BLOCK0 and enclosing
3945 * scope and in global scopes, or NULL if none. NAME is folded to
3946 * lower case first, unless it is surrounded in single quotes.
3947 * Otherwise, the result is as for ada_lookup_symbol_list, but is
3948 * disambiguated by user query if needed. */
3951 ada_lookup_symbol (name, block0, namespace)
3953 struct block *block0;
3954 namespace_enum namespace;
3956 struct symbol** candidate_syms;
3957 struct block** candidate_blocks;
3960 n_candidates = ada_lookup_symbol_list (name,
3962 &candidate_syms, &candidate_blocks);
3964 if (n_candidates == 0)
3966 else if (n_candidates != 1)
3967 user_select_syms (candidate_syms, candidate_blocks, n_candidates, 1);
3969 return candidate_syms[0];
3973 /* True iff STR is a possible encoded suffix of a normal Ada name
3974 * that is to be ignored for matching purposes. Suffixes of parallel
3975 * names (e.g., XVE) are not included here. Currently, the possible suffixes
3976 * are given by the regular expression:
3977 * (X[nb]*)?(__[0-9]+|\$[0-9]+|___(LJM|X([FDBUP].*|R[^T]?)))?$
3981 is_name_suffix (str)
3988 while (str[0] != '_' && str[0] != '\0')
3990 if (str[0] != 'n' && str[0] != 'b')
3995 if (str[0] == '\000')
3999 if (str[1] != '_' || str[2] == '\000')
4003 if (STREQ (str+3, "LJM"))
4007 if (str[4] == 'F' || str[4] == 'D' || str[4] == 'B' ||
4008 str[4] == 'U' || str[4] == 'P')
4010 if (str[4] == 'R' && str[5] != 'T')
4014 for (k = 2; str[k] != '\0'; k += 1)
4015 if (!isdigit (str[k]))
4019 if (str[0] == '$' && str[1] != '\000')
4021 for (k = 1; str[k] != '\0'; k += 1)
4022 if (!isdigit (str[k]))
4029 /* True if NAME represents a name of the form A1.A2....An, n>=1 and
4030 * PATN[0..PATN_LEN-1] = Ak.Ak+1.....An for some k >= 1. Ignores
4031 * informational suffixes of NAME (i.e., for which is_name_suffix is
4034 wild_match (patn, patn_len, name)
4042 name_len = strlen (name);
4043 if (name_len >= patn_len+5 && STREQN (name, "_ada_", 5)
4044 && STREQN (patn, name+5, patn_len)
4045 && is_name_suffix (name+patn_len+5))
4048 while (name_len >= patn_len)
4050 if (STREQN (patn, name, patn_len)
4051 && is_name_suffix (name+patn_len))
4054 name += 1; name_len -= 1;
4055 } while (name_len > 0
4056 && name[0] != '.' && (name[0] != '_' || name[1] != '_'));
4061 if (! islower (name[2]))
4063 name += 2; name_len -= 2;
4067 if (! islower (name[1]))
4069 name += 1; name_len -= 1;
4077 /* Add symbols from BLOCK matching identifier NAME in NAMESPACE to
4078 vector *defn_symbols, updating *defn_symbols (if necessary), *SZ (the size of
4079 the vector *defn_symbols), and *ndefns (the number of symbols
4080 currently stored in *defn_symbols). If WILD, treat as NAME with a
4081 wildcard prefix. OBJFILE is the section containing BLOCK. */
4084 ada_add_block_symbols (block, name, namespace, objfile, wild)
4085 struct block* block;
4087 namespace_enum namespace;
4088 struct objfile* objfile;
4092 int name_len = strlen (name);
4093 /* A matching argument symbol, if any. */
4094 struct symbol *arg_sym;
4095 /* Set true when we find a matching non-argument symbol */
4097 int is_sorted = BLOCK_SHOULD_SORT (block);
4100 arg_sym = NULL; found_sym = 0;
4104 ALL_BLOCK_SYMBOLS (block, i, sym)
4106 if (SYMBOL_NAMESPACE (sym) == namespace &&
4107 wild_match (name, name_len, SYMBOL_NAME (sym)))
4109 switch (SYMBOL_CLASS (sym))
4115 case LOC_REGPARM_ADDR:
4116 case LOC_BASEREG_ARG:
4119 case LOC_UNRESOLVED:
4123 fill_in_ada_prototype (sym);
4124 add_defn_to_vec (fixup_symbol_section (sym, objfile), block);
4135 i = 0; U = BLOCK_NSYMS (block)-1;
4139 struct symbol *sym = BLOCK_SYM (block, M);
4140 if (SYMBOL_NAME (sym)[0] < name[0])
4142 else if (SYMBOL_NAME (sym)[0] > name[0])
4144 else if (strcmp (SYMBOL_NAME (sym), name) < 0)
4153 for (; i < BLOCK_BUCKETS (block); i += 1)
4154 for (sym = BLOCK_BUCKET (block, i); sym != NULL; sym = sym->hash_next)
4156 if (SYMBOL_NAMESPACE (sym) == namespace)
4158 int cmp = strncmp (name, SYMBOL_NAME (sym), name_len);
4164 i = BLOCK_BUCKETS (block);
4169 && is_name_suffix (SYMBOL_NAME (sym) + name_len))
4171 switch (SYMBOL_CLASS (sym))
4177 case LOC_REGPARM_ADDR:
4178 case LOC_BASEREG_ARG:
4181 case LOC_UNRESOLVED:
4185 fill_in_ada_prototype (sym);
4186 add_defn_to_vec (fixup_symbol_section (sym, objfile),
4195 if (! found_sym && arg_sym != NULL)
4197 fill_in_ada_prototype (arg_sym);
4198 add_defn_to_vec (fixup_symbol_section (arg_sym, objfile), block);
4203 arg_sym = NULL; found_sym = 0;
4207 i = 0; U = BLOCK_NSYMS (block)-1;
4211 struct symbol *sym = BLOCK_SYM (block, M);
4212 if (SYMBOL_NAME (sym)[0] < '_')
4214 else if (SYMBOL_NAME (sym)[0] > '_')
4216 else if (strcmp (SYMBOL_NAME (sym), "_ada_") < 0)
4225 for (; i < BLOCK_BUCKETS (block); i += 1)
4226 for (sym = BLOCK_BUCKET (block, i); sym != NULL; sym = sym->hash_next)
4228 struct symbol *sym = BLOCK_SYM (block, i);
4230 if (SYMBOL_NAMESPACE (sym) == namespace)
4234 cmp = (int) '_' - (int) SYMBOL_NAME (sym)[0];
4237 cmp = strncmp ("_ada_", SYMBOL_NAME (sym), 5);
4239 cmp = strncmp (name, SYMBOL_NAME (sym) + 5, name_len);
4246 i = BLOCK_BUCKETS (block);
4251 && is_name_suffix (SYMBOL_NAME (sym) + name_len + 5))
4253 switch (SYMBOL_CLASS (sym))
4259 case LOC_REGPARM_ADDR:
4260 case LOC_BASEREG_ARG:
4263 case LOC_UNRESOLVED:
4267 fill_in_ada_prototype (sym);
4268 add_defn_to_vec (fixup_symbol_section (sym, objfile),
4276 /* NOTE: This really shouldn't be needed for _ada_ symbols.
4277 They aren't parameters, right? */
4278 if (! found_sym && arg_sym != NULL)
4280 fill_in_ada_prototype (arg_sym);
4281 add_defn_to_vec (fixup_symbol_section (arg_sym, objfile), block);
4287 /* Function Types */
4289 /* Assuming that SYM is the symbol for a function, fill in its type
4290 with prototype information, if it is not already there. */
4293 fill_in_ada_prototype (func)
4294 struct symbol* func;
4305 || TYPE_CODE (SYMBOL_TYPE (func)) != TYPE_CODE_FUNC
4306 || TYPE_FIELDS (SYMBOL_TYPE (func)) != NULL)
4309 /* We make each function type unique, so that each may have its own */
4310 /* parameter types. This particular way of doing so wastes space: */
4311 /* it would be nicer to build the argument types while the original */
4312 /* function type is being built (FIXME). */
4313 rtype = check_typedef (TYPE_TARGET_TYPE (SYMBOL_TYPE (func)));
4314 ftype = alloc_type (TYPE_OBJFILE (SYMBOL_TYPE (func)));
4315 make_function_type (rtype, &ftype);
4316 SYMBOL_TYPE (func) = ftype;
4318 b = SYMBOL_BLOCK_VALUE (func);
4322 TYPE_FIELDS (ftype) =
4323 (struct field*) xmalloc (sizeof (struct field) * max_fields);
4324 ALL_BLOCK_SYMBOLS (b, i, sym)
4326 GROW_VECT (TYPE_FIELDS (ftype), max_fields, nargs+1);
4328 switch (SYMBOL_CLASS (sym))
4331 case LOC_REGPARM_ADDR:
4332 TYPE_FIELD_BITPOS (ftype, nargs) = nargs;
4333 TYPE_FIELD_BITSIZE (ftype, nargs) = 0;
4334 TYPE_FIELD_TYPE (ftype, nargs) =
4335 lookup_pointer_type (check_typedef (SYMBOL_TYPE (sym)));
4336 TYPE_FIELD_NAME (ftype, nargs) = SYMBOL_NAME (sym);
4344 case LOC_BASEREG_ARG:
4345 TYPE_FIELD_BITPOS (ftype, nargs) = nargs;
4346 TYPE_FIELD_BITSIZE (ftype, nargs) = 0;
4347 TYPE_FIELD_TYPE (ftype, nargs) = check_typedef (SYMBOL_TYPE (sym));
4348 TYPE_FIELD_NAME (ftype, nargs) = SYMBOL_NAME (sym);
4358 /* Re-allocate fields vector; if there are no fields, make the */
4359 /* fields pointer non-null anyway, to mark that this function type */
4360 /* has been filled in. */
4362 TYPE_NFIELDS (ftype) = nargs;
4365 static struct field dummy_field = {0, 0, 0, 0};
4366 free (TYPE_FIELDS (ftype));
4367 TYPE_FIELDS (ftype) = &dummy_field;
4371 struct field* fields =
4372 (struct field*) TYPE_ALLOC (ftype, nargs * sizeof (struct field));
4373 memcpy ((char*) fields,
4374 (char*) TYPE_FIELDS (ftype),
4375 nargs * sizeof (struct field));
4376 free (TYPE_FIELDS (ftype));
4377 TYPE_FIELDS (ftype) = fields;
4382 /* Breakpoint-related */
4384 char no_symtab_msg[] = "No symbol table is loaded. Use the \"file\" command.";
4386 /* Assuming that LINE is pointing at the beginning of an argument to
4387 'break', return a pointer to the delimiter for the initial segment
4388 of that name. This is the first ':', ' ', or end of LINE.
4391 ada_start_decode_line_1 (line)
4394 /* [NOTE: strpbrk would be more elegant, but I am reluctant to be
4395 the first to use such a library function in GDB code.] */
4397 for (p = line; *p != '\000' && *p != ' ' && *p != ':'; p += 1)
4402 /* *SPEC points to a function and line number spec (as in a break
4403 command), following any initial file name specification.
4405 Return all symbol table/line specfications (sals) consistent with the
4406 information in *SPEC and FILE_TABLE in the
4408 + FILE_TABLE is null, or the sal refers to a line in the file
4409 named by FILE_TABLE.
4410 + If *SPEC points to an argument with a trailing ':LINENUM',
4411 then the sal refers to that line (or one following it as closely as
4413 + If *SPEC does not start with '*', the sal is in a function with
4416 Returns with 0 elements if no matching non-minimal symbols found.
4418 If *SPEC begins with a function name of the form <NAME>, then NAME
4419 is taken as a literal name; otherwise the function name is subject
4420 to the usual mangling.
4422 *SPEC is updated to point after the function/line number specification.
4424 FUNFIRSTLINE is non-zero if we desire the first line of real code
4425 in each function (this is ignored in the presence of a LINENUM spec.).
4427 If CANONICAL is non-NULL, and if any of the sals require a
4428 'canonical line spec', then *CANONICAL is set to point to an array
4429 of strings, corresponding to and equal in length to the returned
4430 list of sals, such that (*CANONICAL)[i] is non-null and contains a
4431 canonical line spec for the ith returned sal, if needed. If no
4432 canonical line specs are required and CANONICAL is non-null,
4433 *CANONICAL is set to NULL.
4435 A 'canonical line spec' is simply a name (in the format of the
4436 breakpoint command) that uniquely identifies a breakpoint position,
4437 with no further contextual information or user selection. It is
4438 needed whenever the file name, function name, and line number
4439 information supplied is insufficient for this unique
4440 identification. Currently overloaded functions, the name '*',
4441 or static functions without a filename yield a canonical line spec.
4442 The array and the line spec strings are allocated on the heap; it
4443 is the caller's responsibility to free them. */
4445 struct symtabs_and_lines
4446 ada_finish_decode_line_1 (spec, file_table, funfirstline, canonical)
4448 struct symtab* file_table;
4452 struct symbol** symbols;
4453 struct block** blocks;
4454 struct block* block;
4455 int n_matches, i, line_num;
4456 struct symtabs_and_lines selected;
4457 struct cleanup* old_chain = make_cleanup (null_cleanup, NULL);
4462 char* unquoted_name;
4464 if (file_table == NULL)
4465 block = get_selected_block (NULL);
4467 block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (file_table), STATIC_BLOCK);
4469 if (canonical != NULL)
4470 *canonical = (char**) NULL;
4477 while (**spec != '\000' &&
4478 ! strchr (ada_completer_word_break_characters, **spec))
4484 if (file_table != NULL && (*spec)[0] == ':' && isdigit ((*spec)[1]))
4486 line_num = strtol (*spec + 1, spec, 10);
4487 while (**spec == ' ' || **spec == '\t')
4494 error ("Wild-card function with no line number or file name.");
4496 return all_sals_for_line (file_table->filename, line_num, canonical);
4499 if (name[0] == '\'')
4507 unquoted_name = (char*) alloca (len-1);
4508 memcpy (unquoted_name, name+1, len-2);
4509 unquoted_name[len-2] = '\000';
4514 unquoted_name = (char*) alloca (len+1);
4515 memcpy (unquoted_name, name, len);
4516 unquoted_name[len] = '\000';
4517 lower_name = (char*) alloca (len + 1);
4518 for (i = 0; i < len; i += 1)
4519 lower_name[i] = tolower (name[i]);
4520 lower_name[len] = '\000';
4524 if (lower_name != NULL)
4525 n_matches = ada_lookup_symbol_list (ada_mangle (lower_name), block,
4526 VAR_NAMESPACE, &symbols, &blocks);
4528 n_matches = ada_lookup_symbol_list (unquoted_name, block,
4529 VAR_NAMESPACE, &symbols, &blocks);
4530 if (n_matches == 0 && line_num >= 0)
4531 error ("No line number information found for %s.", unquoted_name);
4532 else if (n_matches == 0)
4534 #ifdef HPPA_COMPILER_BUG
4535 /* FIXME: See comment in symtab.c::decode_line_1 */
4537 volatile struct symtab_and_line val;
4538 #define volatile /*nothing*/
4540 struct symtab_and_line val;
4542 struct minimal_symbol* msymbol;
4547 if (lower_name != NULL)
4548 msymbol = ada_lookup_minimal_symbol (ada_mangle (lower_name));
4549 if (msymbol == NULL)
4550 msymbol = ada_lookup_minimal_symbol (unquoted_name);
4551 if (msymbol != NULL)
4553 val.pc = SYMBOL_VALUE_ADDRESS (msymbol);
4554 val.section = SYMBOL_BFD_SECTION (msymbol);
4557 val.pc += FUNCTION_START_OFFSET;
4558 SKIP_PROLOGUE (val.pc);
4560 selected.sals = (struct symtab_and_line *)
4561 xmalloc (sizeof (struct symtab_and_line));
4562 selected.sals[0] = val;
4567 if (!have_full_symbols () &&
4568 !have_partial_symbols () && !have_minimal_symbols ())
4569 error (no_symtab_msg);
4571 error ("Function \"%s\" not defined.", unquoted_name);
4572 return selected; /* for lint */
4578 find_sal_from_funcs_and_line (file_table->filename, line_num,
4579 symbols, n_matches);
4583 selected.nelts = user_select_syms (symbols, blocks, n_matches, n_matches);
4586 selected.sals = (struct symtab_and_line*)
4587 xmalloc (sizeof (struct symtab_and_line) * selected.nelts);
4588 memset (selected.sals, 0, selected.nelts * sizeof (selected.sals[i]));
4589 make_cleanup (free, selected.sals);
4592 while (i < selected.nelts)
4594 if (SYMBOL_CLASS (symbols[i]) == LOC_BLOCK)
4595 selected.sals[i] = find_function_start_sal (symbols[i], funfirstline);
4596 else if (SYMBOL_LINE (symbols[i]) != 0)
4598 selected.sals[i].symtab = symtab_for_sym (symbols[i]);
4599 selected.sals[i].line = SYMBOL_LINE (symbols[i]);
4601 else if (line_num >= 0)
4603 /* Ignore this choice */
4604 symbols[i] = symbols[selected.nelts-1];
4605 blocks[i] = blocks[selected.nelts-1];
4606 selected.nelts -= 1;
4610 error ("Line number not known for symbol \"%s\"", unquoted_name);
4614 if (canonical != NULL && (line_num >= 0 || n_matches > 1))
4616 *canonical = (char**) xmalloc (sizeof(char*) * selected.nelts);
4617 for (i = 0; i < selected.nelts; i += 1)
4619 extended_canonical_line_spec (selected.sals[i],
4620 SYMBOL_SOURCE_NAME (symbols[i]));
4623 discard_cleanups (old_chain);
4627 /* The (single) sal corresponding to line LINE_NUM in a symbol table
4628 with file name FILENAME that occurs in one of the functions listed
4629 in SYMBOLS[0 .. NSYMS-1]. */
4630 static struct symtabs_and_lines
4631 find_sal_from_funcs_and_line (filename, line_num, symbols, nsyms)
4632 const char* filename;
4634 struct symbol** symbols;
4637 struct symtabs_and_lines sals;
4638 int best_index, best;
4639 struct linetable* best_linetable;
4640 struct objfile* objfile;
4642 struct symtab* best_symtab;
4644 read_all_symtabs (filename);
4646 best_index = 0; best_linetable = NULL; best_symtab = NULL;
4648 ALL_SYMTABS (objfile, s)
4650 struct linetable *l;
4655 if (!STREQ (filename, s->filename))
4658 ind = find_line_in_linetable (l, line_num, symbols, nsyms, &exact);
4668 if (best == 0 || l->item[ind].line < best)
4670 best = l->item[ind].line;
4679 error ("Line number not found in designated function.");
4684 sals.sals = (struct symtab_and_line*) xmalloc (sizeof (sals.sals[0]));
4686 INIT_SAL (&sals.sals[0]);
4688 sals.sals[0].line = best_linetable->item[best_index].line;
4689 sals.sals[0].pc = best_linetable->item[best_index].pc;
4690 sals.sals[0].symtab = best_symtab;
4695 /* Return the index in LINETABLE of the best match for LINE_NUM whose
4696 pc falls within one of the functions denoted by SYMBOLS[0..NSYMS-1].
4697 Set *EXACTP to the 1 if the match is exact, and 0 otherwise. */
4699 find_line_in_linetable (linetable, line_num, symbols, nsyms, exactp)
4700 struct linetable* linetable;
4702 struct symbol** symbols;
4706 int i, len, best_index, best;
4708 if (line_num <= 0 || linetable == NULL)
4711 len = linetable->nitems;
4712 for (i = 0, best_index = -1, best = 0; i < len; i += 1)
4715 struct linetable_entry* item = &(linetable->item[i]);
4717 for (k = 0; k < nsyms; k += 1)
4719 if (symbols[k] != NULL && SYMBOL_CLASS (symbols[k]) == LOC_BLOCK
4720 && item->pc >= BLOCK_START (SYMBOL_BLOCK_VALUE (symbols[k]))
4721 && item->pc < BLOCK_END (SYMBOL_BLOCK_VALUE (symbols[k])))
4728 if (item->line == line_num)
4734 if (item->line > line_num && (best == 0 || item->line < best))
4745 /* Find the smallest k >= LINE_NUM such that k is a line number in
4746 LINETABLE, and k falls strictly within a named function that begins at
4747 or before LINE_NUM. Return -1 if there is no such k. */
4749 nearest_line_number_in_linetable (linetable, line_num)
4750 struct linetable* linetable;
4755 if (line_num <= 0 || linetable == NULL || linetable->nitems == 0)
4757 len = linetable->nitems;
4759 i = 0; best = INT_MAX;
4763 struct linetable_entry* item = &(linetable->item[i]);
4765 if (item->line >= line_num && item->line < best)
4768 CORE_ADDR start, end;
4771 find_pc_partial_function (item->pc, &func_name, &start, &end);
4773 if (func_name != NULL && item->pc < end)
4775 if (item->line == line_num)
4779 struct symbol* sym =
4780 standard_lookup (func_name, VAR_NAMESPACE);
4781 if (is_plausible_func_for_line (sym, line_num))
4787 while (i < len && linetable->item[i].pc < end);
4797 return (best == INT_MAX) ? -1 : best;
4801 /* Return the next higher index, k, into LINETABLE such that k > IND,
4802 entry k in LINETABLE has a line number equal to LINE_NUM, k
4803 corresponds to a PC that is in a function different from that
4804 corresponding to IND, and falls strictly within a named function
4805 that begins at a line at or preceding STARTING_LINE.
4806 Return -1 if there is no such k.
4807 IND == -1 corresponds to no function. */
4810 find_next_line_in_linetable (linetable, line_num, starting_line, ind)
4811 struct linetable* linetable;
4818 if (line_num <= 0 || linetable == NULL || ind >= linetable->nitems)
4820 len = linetable->nitems;
4824 CORE_ADDR start, end;
4826 if (find_pc_partial_function (linetable->item[ind].pc,
4827 (char**) NULL, &start, &end))
4829 while (ind < len && linetable->item[ind].pc < end)
4842 struct linetable_entry* item = &(linetable->item[i]);
4844 if (item->line >= line_num)
4847 CORE_ADDR start, end;
4850 find_pc_partial_function (item->pc, &func_name, &start, &end);
4852 if (func_name != NULL && item->pc < end)
4854 if (item->line == line_num)
4856 struct symbol* sym =
4857 standard_lookup (func_name, VAR_NAMESPACE);
4858 if (is_plausible_func_for_line (sym, starting_line))
4862 while ((i+1) < len && linetable->item[i+1].pc < end)
4874 /* True iff function symbol SYM starts somewhere at or before line #
4877 is_plausible_func_for_line (sym, line_num)
4881 struct symtab_and_line start_sal;
4886 start_sal = find_function_start_sal (sym, 0);
4888 return (start_sal.line != 0 && line_num >= start_sal.line);
4892 debug_print_lines (lt)
4893 struct linetable* lt;
4900 fprintf (stderr, "\t");
4901 for (i = 0; i < lt->nitems; i += 1)
4902 fprintf (stderr, "(%d->%p) ", lt->item[i].line, (void *) lt->item[i].pc);
4903 fprintf (stderr, "\n");
4907 debug_print_block (b)
4913 fprintf (stderr, "Block: %p; [0x%lx, 0x%lx]",
4914 b, BLOCK_START(b), BLOCK_END(b));
4915 if (BLOCK_FUNCTION(b) != NULL)
4916 fprintf (stderr, " Function: %s", SYMBOL_NAME (BLOCK_FUNCTION(b)));
4917 fprintf (stderr, "\n");
4918 fprintf (stderr, "\t Superblock: %p\n", BLOCK_SUPERBLOCK(b));
4919 fprintf (stderr, "\t Symbols:");
4920 ALL_BLOCK_SYMBOLS (b, i, sym)
4922 if (i > 0 && i % 4 == 0)
4923 fprintf (stderr, "\n\t\t ");
4924 fprintf (stderr, " %s", SYMBOL_NAME (sym));
4926 fprintf (stderr, "\n");
4930 debug_print_blocks (bv)
4931 struct blockvector* bv;
4937 for (i = 0; i < BLOCKVECTOR_NBLOCKS (bv); i += 1) {
4938 fprintf (stderr, "%6d. ", i);
4939 debug_print_block (BLOCKVECTOR_BLOCK (bv, i));
4944 debug_print_symtab (s)
4947 fprintf (stderr, "Symtab %p\n File: %s; Dir: %s\n", s,
4948 s->filename, s->dirname);
4949 fprintf (stderr, " Blockvector: %p, Primary: %d\n",
4950 BLOCKVECTOR(s), s->primary);
4951 debug_print_blocks (BLOCKVECTOR(s));
4952 fprintf (stderr, " Line table: %p\n", LINETABLE (s));
4953 debug_print_lines (LINETABLE(s));
4956 /* Read in all symbol tables corresponding to partial symbol tables
4957 with file name FILENAME. */
4959 read_all_symtabs (filename)
4960 const char* filename;
4962 struct partial_symtab* ps;
4963 struct objfile* objfile;
4965 ALL_PSYMTABS (objfile, ps)
4969 if (STREQ (filename, ps->filename))
4970 PSYMTAB_TO_SYMTAB (ps);
4974 /* All sals corresponding to line LINE_NUM in a symbol table from file
4975 FILENAME, as filtered by the user. If CANONICAL is not null, set
4976 it to a corresponding array of canonical line specs. */
4977 static struct symtabs_and_lines
4978 all_sals_for_line (filename, line_num, canonical)
4979 const char* filename;
4983 struct symtabs_and_lines result;
4984 struct objfile* objfile;
4986 struct cleanup* old_chain = make_cleanup (null_cleanup, NULL);
4989 read_all_symtabs (filename);
4991 result.sals = (struct symtab_and_line*) xmalloc (4 * sizeof (result.sals[0]));
4994 make_cleanup (free_current_contents, &result.sals);
4996 ALL_SYMTABS (objfile, s)
4998 int ind, target_line_num;
5002 if (!STREQ (s->filename, filename))
5006 nearest_line_number_in_linetable (LINETABLE (s), line_num);
5007 if (target_line_num == -1)
5014 find_next_line_in_linetable (LINETABLE (s),
5015 target_line_num, line_num, ind);
5020 GROW_VECT (result.sals, len, result.nelts+1);
5021 INIT_SAL (&result.sals[result.nelts]);
5022 result.sals[result.nelts].line = LINETABLE(s)->item[ind].line;
5023 result.sals[result.nelts].pc = LINETABLE(s)->item[ind].pc;
5024 result.sals[result.nelts].symtab = s;
5029 if (canonical != NULL || result.nelts > 1)
5032 char** func_names = (char**) alloca (result.nelts * sizeof (char*));
5033 int first_choice = (result.nelts > 1) ? 2 : 1;
5035 int* choices = (int*) alloca (result.nelts * sizeof (int));
5037 for (k = 0; k < result.nelts; k += 1)
5039 find_pc_partial_function (result.sals[k].pc, &func_names[k],
5040 (CORE_ADDR*) NULL, (CORE_ADDR*) NULL);
5041 if (func_names[k] == NULL)
5042 error ("Could not find function for one or more breakpoints.");
5045 if (result.nelts > 1)
5047 printf_unfiltered("[0] cancel\n");
5048 if (result.nelts > 1)
5049 printf_unfiltered("[1] all\n");
5050 for (k = 0; k < result.nelts; k += 1)
5051 printf_unfiltered ("[%d] %s\n", k + first_choice,
5052 ada_demangle (func_names[k]));
5054 n = get_selections (choices, result.nelts, result.nelts,
5055 result.nelts > 1, "instance-choice");
5057 for (k = 0; k < n; k += 1)
5059 result.sals[k] = result.sals[choices[k]];
5060 func_names[k] = func_names[choices[k]];
5065 if (canonical != NULL)
5067 *canonical = (char**) xmalloc (result.nelts * sizeof (char**));
5068 make_cleanup (free, *canonical);
5069 for (k = 0; k < result.nelts; k += 1)
5072 extended_canonical_line_spec (result.sals[k], func_names[k]);
5073 if ((*canonical)[k] == NULL)
5074 error ("Could not locate one or more breakpoints.");
5075 make_cleanup (free, (*canonical)[k]);
5080 discard_cleanups (old_chain);
5085 /* A canonical line specification of the form FILE:NAME:LINENUM for
5086 symbol table and line data SAL. NULL if insufficient
5087 information. The caller is responsible for releasing any space
5091 extended_canonical_line_spec (sal, name)
5092 struct symtab_and_line sal;
5097 if (sal.symtab == NULL || sal.symtab->filename == NULL ||
5101 r = (char*) xmalloc (strlen (name) + strlen (sal.symtab->filename)
5102 + sizeof(sal.line)*3 + 3);
5103 sprintf (r, "%s:'%s':%d", sal.symtab->filename, name, sal.line);
5108 int begin_bnum = -1;
5110 int begin_annotate_level = 0;
5113 begin_cleanup (void* dummy)
5115 begin_annotate_level = 0;
5119 begin_command (args, from_tty)
5123 struct minimal_symbol *msym;
5124 CORE_ADDR main_program_name_addr;
5125 char main_program_name[1024];
5126 struct cleanup* old_chain = make_cleanup (begin_cleanup, NULL);
5127 begin_annotate_level = 2;
5129 /* Check that there is a program to debug */
5130 if (!have_full_symbols () && !have_partial_symbols ())
5131 error ("No symbol table is loaded. Use the \"file\" command.");
5133 /* Check that we are debugging an Ada program */
5134 /* if (ada_update_initial_language (language_unknown, NULL) != language_ada)
5135 error ("Cannot find the Ada initialization procedure. Is this an Ada main program?");
5137 /* FIXME: language_ada should be defined in defs.h */
5139 /* Get the address of the name of the main procedure */
5140 msym = lookup_minimal_symbol (ADA_MAIN_PROGRAM_SYMBOL_NAME, NULL, NULL);
5144 main_program_name_addr = SYMBOL_VALUE_ADDRESS (msym);
5145 if (main_program_name_addr == 0)
5146 error ("Invalid address for Ada main program name.");
5148 /* Read the name of the main procedure */
5149 extract_string (main_program_name_addr, main_program_name);
5151 /* Put a temporary breakpoint in the Ada main program and run */
5152 do_command ("tbreak ", main_program_name, 0);
5153 do_command ("run ", args, 0);
5157 /* If we could not find the symbol containing the name of the
5158 main program, that means that the compiler that was used to build
5159 was not recent enough. In that case, we fallback to the previous
5160 mechanism, which is a little bit less reliable, but has proved to work
5161 in most cases. The only cases where it will fail is when the user
5162 has set some breakpoints which will be hit before the end of the
5163 begin command processing (eg in the initialization code).
5165 The begining of the main Ada subprogram is located by breaking
5166 on the adainit procedure. Since we know that the binder generates
5167 the call to this procedure exactly 2 calls before the call to the
5168 Ada main subprogram, it is then easy to put a breakpoint on this
5169 Ada main subprogram once we hit adainit.
5171 do_command ("tbreak adainit", 0);
5172 do_command ("run ", args, 0);
5173 do_command ("up", 0);
5174 do_command ("tbreak +2", 0);
5175 do_command ("continue", 0);
5176 do_command ("step", 0);
5179 do_cleanups (old_chain);
5183 is_ada_runtime_file (filename)
5186 return (STREQN (filename, "s-", 2) ||
5187 STREQN (filename, "a-", 2) ||
5188 STREQN (filename, "g-", 2) ||
5189 STREQN (filename, "i-", 2));
5192 /* find the first frame that contains debugging information and that is not
5193 part of the Ada run-time, starting from fi and moving upward. */
5196 find_printable_frame (fi, level)
5197 struct frame_info *fi;
5200 struct symtab_and_line sal;
5202 for (; fi != NULL; level += 1, fi = get_prev_frame (fi))
5204 /* If fi is not the innermost frame, that normally means that fi->pc
5205 points to *after* the call instruction, and we want to get the line
5206 containing the call, never the next line. But if the next frame is
5207 a signal_handler_caller or a dummy frame, then the next frame was
5208 not entered as the result of a call, and we want to get the line
5209 containing fi->pc. */
5211 find_pc_line (fi->pc,
5213 && !fi->next->signal_handler_caller
5214 && !frame_in_dummy (fi->next));
5215 if (sal.symtab && !is_ada_runtime_file (sal.symtab->filename))
5217 #if defined(__alpha__) && defined(__osf__) && !defined(VXWORKS_TARGET)
5218 /* libpthread.so contains some debugging information that prevents us
5219 from finding the right frame */
5221 if (sal.symtab->objfile &&
5222 STREQ (sal.symtab->objfile->name, "/usr/shlib/libpthread.so"))
5225 selected_frame = fi;
5234 ada_report_exception_break (b)
5235 struct breakpoint *b;
5238 /* FIXME: break_on_exception should be defined in breakpoint.h */
5239 /* if (b->break_on_exception == 1)
5241 /* Assume that cond has 16 elements, the 15th
5242 being the exception */ /*
5243 if (b->cond && b->cond->nelts == 16)
5245 ui_out_text (uiout, "on ");
5246 ui_out_field_string (uiout, "exception",
5247 SYMBOL_NAME (b->cond->elts[14].symbol));
5250 ui_out_text (uiout, "on all exceptions");
5252 else if (b->break_on_exception == 2)
5253 ui_out_text (uiout, "on unhandled exception");
5254 else if (b->break_on_exception == 3)
5255 ui_out_text (uiout, "on assert failure");
5257 if (b->break_on_exception == 1)
5259 /* Assume that cond has 16 elements, the 15th
5260 being the exception */ /*
5261 if (b->cond && b->cond->nelts == 16)
5263 fputs_filtered ("on ", gdb_stdout);
5264 fputs_filtered (SYMBOL_NAME
5265 (b->cond->elts[14].symbol), gdb_stdout);
5268 fputs_filtered ("on all exceptions", gdb_stdout);
5270 else if (b->break_on_exception == 2)
5271 fputs_filtered ("on unhandled exception", gdb_stdout);
5272 else if (b->break_on_exception == 3)
5273 fputs_filtered ("on assert failure", gdb_stdout);
5279 ada_is_exception_sym (struct symbol* sym)
5281 char *type_name = type_name_no_tag (SYMBOL_TYPE (sym));
5283 return (SYMBOL_CLASS (sym) != LOC_TYPEDEF
5284 && SYMBOL_CLASS (sym) != LOC_BLOCK
5285 && SYMBOL_CLASS (sym) != LOC_CONST
5286 && type_name != NULL
5287 && STREQ (type_name, "exception"));
5291 ada_maybe_exception_partial_symbol (struct partial_symbol* sym)
5293 return (SYMBOL_CLASS (sym) != LOC_TYPEDEF
5294 && SYMBOL_CLASS (sym) != LOC_BLOCK
5295 && SYMBOL_CLASS (sym) != LOC_CONST);
5298 /* If ARG points to an Ada exception or assert breakpoint, rewrite
5299 into equivalent form. Return resulting argument string. Set
5300 *BREAK_ON_EXCEPTIONP to 1 for ordinary break on exception, 2 for
5301 break on unhandled, 3 for assert, 0 otherwise. */
5302 char* ada_breakpoint_rewrite (char* arg, int* break_on_exceptionp)
5306 *break_on_exceptionp = 0;
5307 /* FIXME: language_ada should be defined in defs.h */
5308 /* if (current_language->la_language == language_ada
5309 && STREQN (arg, "exception", 9) &&
5310 (arg[9] == ' ' || arg[9] == '\t' || arg[9] == '\0'))
5312 char *tok, *end_tok;
5315 *break_on_exceptionp = 1;
5318 while (*tok == ' ' || *tok == '\t')
5323 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
5326 toklen = end_tok - tok;
5328 arg = (char*) xmalloc (sizeof ("__gnat_raise_nodefer_with_msg if "
5329 "long_integer(e) = long_integer(&)")
5331 make_cleanup (free, arg);
5333 strcpy (arg, "__gnat_raise_nodefer_with_msg");
5334 else if (STREQN (tok, "unhandled", toklen))
5336 *break_on_exceptionp = 2;
5337 strcpy (arg, "__gnat_unhandled_exception");
5341 sprintf (arg, "__gnat_raise_nodefer_with_msg if "
5342 "long_integer(e) = long_integer(&%.*s)",
5346 else if (current_language->la_language == language_ada
5347 && STREQN (arg, "assert", 6) &&
5348 (arg[6] == ' ' || arg[6] == '\t' || arg[6] == '\0'))
5350 char *tok = arg + 6;
5352 *break_on_exceptionp = 3;
5355 xmalloc (sizeof ("system__assertions__raise_assert_failure")
5356 + strlen (tok) + 1);
5357 make_cleanup (free, arg);
5358 sprintf (arg, "system__assertions__raise_assert_failure%s", tok);
5367 /* True if field number FIELD_NUM in struct or union type TYPE is supposed
5368 to be invisible to users. */
5371 ada_is_ignored_field (type, field_num)
5375 if (field_num < 0 || field_num > TYPE_NFIELDS (type))
5379 const char* name = TYPE_FIELD_NAME (type, field_num);
5380 return (name == NULL
5381 || (name[0] == '_' && ! STREQN (name, "_parent", 7)));
5385 /* True iff structure type TYPE has a tag field. */
5388 ada_is_tagged_type (type)
5391 if (type == NULL || TYPE_CODE (type) != TYPE_CODE_STRUCT)
5394 return (ada_lookup_struct_elt_type (type, "_tag", 1, NULL) != NULL);
5397 /* The type of the tag on VAL. */
5403 return ada_lookup_struct_elt_type (VALUE_TYPE (val), "_tag", 0, NULL);
5406 /* The value of the tag on VAL. */
5412 return ada_value_struct_elt (val, "_tag", "record");
5415 /* The parent type of TYPE, or NULL if none. */
5418 ada_parent_type (type)
5423 CHECK_TYPEDEF (type);
5425 if (type == NULL || TYPE_CODE (type) != TYPE_CODE_STRUCT)
5428 for (i = 0; i < TYPE_NFIELDS (type); i += 1)
5429 if (ada_is_parent_field (type, i))
5430 return check_typedef (TYPE_FIELD_TYPE (type, i));
5435 /* True iff field number FIELD_NUM of structure type TYPE contains the
5436 parent-type (inherited) fields of a derived type. Assumes TYPE is
5437 a structure type with at least FIELD_NUM+1 fields. */
5440 ada_is_parent_field (type, field_num)
5444 const char* name = TYPE_FIELD_NAME (check_typedef (type), field_num);
5445 return (name != NULL &&
5446 (STREQN (name, "PARENT", 6) || STREQN (name, "_parent", 7)));
5449 /* True iff field number FIELD_NUM of structure type TYPE is a
5450 transparent wrapper field (which should be silently traversed when doing
5451 field selection and flattened when printing). Assumes TYPE is a
5452 structure type with at least FIELD_NUM+1 fields. Such fields are always
5456 ada_is_wrapper_field (type, field_num)
5460 const char* name = TYPE_FIELD_NAME (type, field_num);
5461 return (name != NULL
5462 && (STREQN (name, "PARENT", 6) || STREQ (name, "REP")
5463 || STREQN (name, "_parent", 7)
5464 || name[0] == 'S' || name[0] == 'R' || name[0] == 'O'));
5467 /* True iff field number FIELD_NUM of structure or union type TYPE
5468 is a variant wrapper. Assumes TYPE is a structure type with at least
5469 FIELD_NUM+1 fields. */
5472 ada_is_variant_part (type, field_num)
5476 struct type* field_type = TYPE_FIELD_TYPE (type, field_num);
5477 return (TYPE_CODE (field_type) == TYPE_CODE_UNION
5478 || (is_dynamic_field (type, field_num)
5479 && TYPE_CODE (TYPE_TARGET_TYPE (field_type)) == TYPE_CODE_UNION));
5482 /* Assuming that VAR_TYPE is a variant wrapper (type of the variant part)
5483 whose discriminants are contained in the record type OUTER_TYPE,
5484 returns the type of the controlling discriminant for the variant. */
5487 ada_variant_discrim_type (var_type, outer_type)
5488 struct type *var_type;
5489 struct type *outer_type;
5491 char* name = ada_variant_discrim_name (var_type);
5493 ada_lookup_struct_elt_type (outer_type, name, 1, NULL);
5495 return builtin_type_int;
5500 /* Assuming that TYPE is the type of a variant wrapper, and FIELD_NUM is a
5501 valid field number within it, returns 1 iff field FIELD_NUM of TYPE
5502 represents a 'when others' clause; otherwise 0. */
5505 ada_is_others_clause (type, field_num)
5509 const char* name = TYPE_FIELD_NAME (type, field_num);
5510 return (name != NULL && name[0] == 'O');
5513 /* Assuming that TYPE0 is the type of the variant part of a record,
5514 returns the name of the discriminant controlling the variant. The
5515 value is valid until the next call to ada_variant_discrim_name. */
5518 ada_variant_discrim_name (type0)
5521 static char* result = NULL;
5522 static size_t result_len = 0;
5525 const char* discrim_end;
5526 const char* discrim_start;
5528 if (TYPE_CODE (type0) == TYPE_CODE_PTR)
5529 type = TYPE_TARGET_TYPE (type0);
5533 name = ada_type_name (type);
5535 if (name == NULL || name[0] == '\000')
5538 for (discrim_end = name + strlen (name) - 6; discrim_end != name;
5541 if (STREQN (discrim_end, "___XVN", 6))
5544 if (discrim_end == name)
5547 for (discrim_start = discrim_end; discrim_start != name+3;
5550 if (discrim_start == name+1)
5552 if ((discrim_start > name+3 && STREQN (discrim_start-3, "___", 3))
5553 || discrim_start[-1] == '.')
5557 GROW_VECT (result, result_len, discrim_end - discrim_start + 1);
5558 strncpy (result, discrim_start, discrim_end - discrim_start);
5559 result[discrim_end-discrim_start] = '\0';
5563 /* Scan STR for a subtype-encoded number, beginning at position K. Put the
5564 position of the character just past the number scanned in *NEW_K,
5565 if NEW_K!=NULL. Put the scanned number in *R, if R!=NULL. Return 1
5566 if there was a valid number at the given position, and 0 otherwise. A
5567 "subtype-encoded" number consists of the absolute value in decimal,
5568 followed by the letter 'm' to indicate a negative number. Assumes 0m
5572 ada_scan_number (str, k, R, new_k)
5580 if (! isdigit (str[k]))
5583 /* Do it the hard way so as not to make any assumption about
5584 the relationship of unsigned long (%lu scan format code) and
5587 while (isdigit (str[k]))
5589 RU = RU*10 + (str[k] - '0');
5596 *R = (- (LONGEST) (RU-1)) - 1;
5602 /* NOTE on the above: Technically, C does not say what the results of
5603 - (LONGEST) RU or (LONGEST) -RU are for RU == largest positive
5604 number representable as a LONGEST (although either would probably work
5605 in most implementations). When RU>0, the locution in the then branch
5606 above is always equivalent to the negative of RU. */
5613 /* Assuming that TYPE is a variant part wrapper type (a VARIANTS field),
5614 and FIELD_NUM is a valid field number within it, returns 1 iff VAL is
5615 in the range encoded by field FIELD_NUM of TYPE; otherwise 0. */
5618 ada_in_variant (val, type, field_num)
5623 const char* name = TYPE_FIELD_NAME (type, field_num);
5636 if (! ada_scan_number (name, p + 1, &W, &p))
5645 if (! ada_scan_number (name, p + 1, &L, &p)
5647 || ! ada_scan_number (name, p + 1, &U, &p))
5649 if (val >= L && val <= U)
5661 /* Given a value ARG1 (offset by OFFSET bytes)
5662 of a struct or union type ARG_TYPE,
5663 extract and return the value of one of its (non-static) fields.
5664 FIELDNO says which field. Differs from value_primitive_field only
5665 in that it can handle packed values of arbitrary type. */
5668 ada_value_primitive_field (arg1, offset, fieldno, arg_type)
5672 struct type *arg_type;
5677 CHECK_TYPEDEF (arg_type);
5678 type = TYPE_FIELD_TYPE (arg_type, fieldno);
5680 /* Handle packed fields */
5682 if (TYPE_FIELD_BITSIZE (arg_type, fieldno) != 0)
5684 int bit_pos = TYPE_FIELD_BITPOS (arg_type, fieldno);
5685 int bit_size = TYPE_FIELD_BITSIZE (arg_type, fieldno);
5687 return ada_value_primitive_packed_val (arg1, VALUE_CONTENTS (arg1),
5688 offset + bit_pos/8, bit_pos % 8,
5692 return value_primitive_field (arg1, offset, fieldno, arg_type);
5696 /* Look for a field NAME in ARG. Adjust the address of ARG by OFFSET bytes,
5697 and search in it assuming it has (class) type TYPE.
5698 If found, return value, else return NULL.
5700 Searches recursively through wrapper fields (e.g., '_parent'). */
5703 ada_search_struct_field (name, arg, offset, type)
5710 CHECK_TYPEDEF (type);
5712 for (i = TYPE_NFIELDS (type)-1; i >= 0; i -= 1)
5714 char *t_field_name = TYPE_FIELD_NAME (type, i);
5716 if (t_field_name == NULL)
5719 else if (field_name_match (t_field_name, name))
5720 return ada_value_primitive_field (arg, offset, i, type);
5722 else if (ada_is_wrapper_field (type, i))
5725 ada_search_struct_field (name, arg,
5726 offset + TYPE_FIELD_BITPOS (type, i) / 8,
5727 TYPE_FIELD_TYPE (type, i));
5732 else if (ada_is_variant_part (type, i))
5735 struct type *field_type = check_typedef (TYPE_FIELD_TYPE (type, i));
5736 int var_offset = offset + TYPE_FIELD_BITPOS (type, i) / 8;
5738 for (j = TYPE_NFIELDS (field_type) - 1; j >= 0; j -= 1)
5741 ada_search_struct_field (name, arg,
5743 + TYPE_FIELD_BITPOS (field_type, j)/8,
5744 TYPE_FIELD_TYPE (field_type, j));
5753 /* Given ARG, a value of type (pointer to a)* structure/union,
5754 extract the component named NAME from the ultimate target structure/union
5755 and return it as a value with its appropriate type.
5757 The routine searches for NAME among all members of the structure itself
5758 and (recursively) among all members of any wrapper members
5761 ERR is a name (for use in error messages) that identifies the class
5762 of entity that ARG is supposed to be. */
5765 ada_value_struct_elt (arg, name, err)
5773 arg = ada_coerce_ref (arg);
5774 t = check_typedef (VALUE_TYPE (arg));
5776 /* Follow pointers until we get to a non-pointer. */
5778 while (TYPE_CODE (t) == TYPE_CODE_PTR || TYPE_CODE (t) == TYPE_CODE_REF)
5780 arg = ada_value_ind (arg);
5781 t = check_typedef (VALUE_TYPE (arg));
5784 if ( TYPE_CODE (t) != TYPE_CODE_STRUCT
5785 && TYPE_CODE (t) != TYPE_CODE_UNION)
5786 error ("Attempt to extract a component of a value that is not a %s.", err);
5788 v = ada_search_struct_field (name, arg, 0, t);
5790 error ("There is no member named %s.", name);
5795 /* Given a type TYPE, look up the type of the component of type named NAME.
5796 If DISPP is non-null, add its byte displacement from the beginning of a
5797 structure (pointed to by a value) of type TYPE to *DISPP (does not
5798 work for packed fields).
5800 Matches any field whose name has NAME as a prefix, possibly
5803 TYPE can be either a struct or union, or a pointer or reference to
5804 a struct or union. If it is a pointer or reference, its target
5805 type is automatically used.
5807 Looks recursively into variant clauses and parent types.
5809 If NOERR is nonzero, return NULL if NAME is not suitably defined. */
5812 ada_lookup_struct_elt_type (type, name, noerr, dispp)
5825 CHECK_TYPEDEF (type);
5826 if (TYPE_CODE (type) != TYPE_CODE_PTR
5827 && TYPE_CODE (type) != TYPE_CODE_REF)
5829 type = TYPE_TARGET_TYPE (type);
5832 if (TYPE_CODE (type) != TYPE_CODE_STRUCT &&
5833 TYPE_CODE (type) != TYPE_CODE_UNION)
5835 target_terminal_ours ();
5836 gdb_flush (gdb_stdout);
5837 fprintf_unfiltered (gdb_stderr, "Type ");
5838 type_print (type, "", gdb_stderr, -1);
5839 error (" is not a structure or union type");
5842 type = to_static_fixed_type (type);
5844 for (i = 0; i < TYPE_NFIELDS (type); i += 1)
5846 char *t_field_name = TYPE_FIELD_NAME (type, i);
5850 if (t_field_name == NULL)
5853 else if (field_name_match (t_field_name, name))
5856 *dispp += TYPE_FIELD_BITPOS (type, i) / 8;
5857 return check_typedef (TYPE_FIELD_TYPE (type, i));
5860 else if (ada_is_wrapper_field (type, i))
5863 t = ada_lookup_struct_elt_type (TYPE_FIELD_TYPE (type, i), name,
5868 *dispp += disp + TYPE_FIELD_BITPOS (type, i) / 8;
5873 else if (ada_is_variant_part (type, i))
5876 struct type *field_type = check_typedef (TYPE_FIELD_TYPE (type, i));
5878 for (j = TYPE_NFIELDS (field_type) - 1; j >= 0; j -= 1)
5881 t = ada_lookup_struct_elt_type (TYPE_FIELD_TYPE (field_type, j),
5886 *dispp += disp + TYPE_FIELD_BITPOS (type, i) / 8;
5897 target_terminal_ours ();
5898 gdb_flush (gdb_stdout);
5899 fprintf_unfiltered (gdb_stderr, "Type ");
5900 type_print (type, "", gdb_stderr, -1);
5901 fprintf_unfiltered (gdb_stderr, " has no component named ");
5902 error ("%s", name == NULL ? "<null>" : name);
5908 /* Assuming that VAR_TYPE is the type of a variant part of a record (a union),
5909 within a value of type OUTER_TYPE that is stored in GDB at
5910 OUTER_VALADDR, determine which variant clause (field number in VAR_TYPE,
5911 numbering from 0) is applicable. Returns -1 if none are. */
5914 ada_which_variant_applies (var_type, outer_type, outer_valaddr)
5915 struct type *var_type;
5916 struct type *outer_type;
5917 char* outer_valaddr;
5922 struct type* discrim_type;
5923 char* discrim_name = ada_variant_discrim_name (var_type);
5924 LONGEST discrim_val;
5928 ada_lookup_struct_elt_type (outer_type, discrim_name, 1, &disp);
5929 if (discrim_type == NULL)
5931 discrim_val = unpack_long (discrim_type, outer_valaddr + disp);
5934 for (i = 0; i < TYPE_NFIELDS (var_type); i += 1)
5936 if (ada_is_others_clause (var_type, i))
5938 else if (ada_in_variant (discrim_val, var_type, i))
5942 return others_clause;
5947 /* Dynamic-Sized Records */
5949 /* Strategy: The type ostensibly attached to a value with dynamic size
5950 (i.e., a size that is not statically recorded in the debugging
5951 data) does not accurately reflect the size or layout of the value.
5952 Our strategy is to convert these values to values with accurate,
5953 conventional types that are constructed on the fly. */
5955 /* There is a subtle and tricky problem here. In general, we cannot
5956 determine the size of dynamic records without its data. However,
5957 the 'struct value' data structure, which GDB uses to represent
5958 quantities in the inferior process (the target), requires the size
5959 of the type at the time of its allocation in order to reserve space
5960 for GDB's internal copy of the data. That's why the
5961 'to_fixed_xxx_type' routines take (target) addresses as parameters,
5962 rather than struct value*s.
5964 However, GDB's internal history variables ($1, $2, etc.) are
5965 struct value*s containing internal copies of the data that are not, in
5966 general, the same as the data at their corresponding addresses in
5967 the target. Fortunately, the types we give to these values are all
5968 conventional, fixed-size types (as per the strategy described
5969 above), so that we don't usually have to perform the
5970 'to_fixed_xxx_type' conversions to look at their values.
5971 Unfortunately, there is one exception: if one of the internal
5972 history variables is an array whose elements are unconstrained
5973 records, then we will need to create distinct fixed types for each
5974 element selected. */
5976 /* The upshot of all of this is that many routines take a (type, host
5977 address, target address) triple as arguments to represent a value.
5978 The host address, if non-null, is supposed to contain an internal
5979 copy of the relevant data; otherwise, the program is to consult the
5980 target at the target address. */
5982 /* Assuming that VAL0 represents a pointer value, the result of
5983 dereferencing it. Differs from value_ind in its treatment of
5984 dynamic-sized types. */
5987 ada_value_ind (val0)
5990 struct value* val = unwrap_value (value_ind (val0));
5991 return ada_to_fixed_value (VALUE_TYPE (val), 0,
5992 VALUE_ADDRESS (val) + VALUE_OFFSET (val),
5996 /* The value resulting from dereferencing any "reference to"
5997 * qualifiers on VAL0. */
5998 static struct value*
5999 ada_coerce_ref (val0)
6002 if (TYPE_CODE (VALUE_TYPE (val0)) == TYPE_CODE_REF) {
6003 struct value* val = val0;
6005 val = unwrap_value (val);
6006 return ada_to_fixed_value (VALUE_TYPE (val), 0,
6007 VALUE_ADDRESS (val) + VALUE_OFFSET (val),
6013 /* Return OFF rounded upward if necessary to a multiple of
6014 ALIGNMENT (a power of 2). */
6017 align_value (off, alignment)
6019 unsigned int alignment;
6021 return (off + alignment - 1) & ~(alignment - 1);
6024 /* Return the additional bit offset required by field F of template
6028 field_offset (type, f)
6032 int n = TYPE_FIELD_BITPOS (type, f);
6033 /* Kludge (temporary?) to fix problem with dwarf output. */
6035 return (unsigned int) n & 0xffff;
6041 /* Return the bit alignment required for field #F of template type TYPE. */
6044 field_alignment (type, f)
6048 const char* name = TYPE_FIELD_NAME (type, f);
6049 int len = (name == NULL) ? 0 : strlen (name);
6052 if (len < 8 || ! isdigit (name[len-1]))
6053 return TARGET_CHAR_BIT;
6055 if (isdigit (name[len-2]))
6056 align_offset = len - 2;
6058 align_offset = len - 1;
6060 if (align_offset < 7 || ! STREQN ("___XV", name+align_offset-6, 5))
6061 return TARGET_CHAR_BIT;
6063 return atoi (name+align_offset) * TARGET_CHAR_BIT;
6066 /* Find a type named NAME. Ignores ambiguity. */
6068 ada_find_any_type (name)
6073 sym = standard_lookup (name, VAR_NAMESPACE);
6074 if (sym != NULL && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
6075 return SYMBOL_TYPE (sym);
6077 sym = standard_lookup (name, STRUCT_NAMESPACE);
6079 return SYMBOL_TYPE (sym);
6084 /* Because of GNAT encoding conventions, several GDB symbols may match a
6085 given type name. If the type denoted by TYPE0 is to be preferred to
6086 that of TYPE1 for purposes of type printing, return non-zero;
6087 otherwise return 0. */
6089 ada_prefer_type (type0, type1)
6095 else if (type0 == NULL)
6097 else if (TYPE_CODE (type1) == TYPE_CODE_VOID)
6099 else if (TYPE_CODE (type0) == TYPE_CODE_VOID)
6101 else if (ada_is_packed_array_type (type0))
6103 else if (ada_is_array_descriptor (type0) && ! ada_is_array_descriptor (type1))
6105 else if (ada_renaming_type (type0) != NULL
6106 && ada_renaming_type (type1) == NULL)
6111 /* The name of TYPE, which is either its TYPE_NAME, or, if that is
6112 null, its TYPE_TAG_NAME. Null if TYPE is null. */
6114 ada_type_name (type)
6119 else if (TYPE_NAME (type) != NULL)
6120 return TYPE_NAME (type);
6122 return TYPE_TAG_NAME (type);
6125 /* Find a parallel type to TYPE whose name is formed by appending
6126 SUFFIX to the name of TYPE. */
6129 ada_find_parallel_type (type, suffix)
6134 static size_t name_len = 0;
6135 struct symbol** syms;
6136 struct block** blocks;
6139 char* typename = ada_type_name (type);
6141 if (typename == NULL)
6144 len = strlen (typename);
6146 GROW_VECT (name, name_len, len+strlen (suffix)+1);
6148 strcpy (name, typename);
6149 strcpy (name + len, suffix);
6151 return ada_find_any_type (name);
6155 /* If TYPE is a variable-size record type, return the corresponding template
6156 type describing its fields. Otherwise, return NULL. */
6159 dynamic_template_type (type)
6162 CHECK_TYPEDEF (type);
6164 if (type == NULL || TYPE_CODE (type) != TYPE_CODE_STRUCT
6165 || ada_type_name (type) == NULL)
6169 int len = strlen (ada_type_name (type));
6170 if (len > 6 && STREQ (ada_type_name (type) + len - 6, "___XVE"))
6173 return ada_find_parallel_type (type, "___XVE");
6177 /* Assuming that TEMPL_TYPE is a union or struct type, returns
6178 non-zero iff field FIELD_NUM of TEMPL_TYPE has dynamic size. */
6181 is_dynamic_field (templ_type, field_num)
6182 struct type* templ_type;
6185 const char *name = TYPE_FIELD_NAME (templ_type, field_num);
6187 && TYPE_CODE (TYPE_FIELD_TYPE (templ_type, field_num)) == TYPE_CODE_PTR
6188 && strstr (name, "___XVL") != NULL;
6191 /* Assuming that TYPE is a struct type, returns non-zero iff TYPE
6192 contains a variant part. */
6195 contains_variant_part (type)
6200 if (type == NULL || TYPE_CODE (type) != TYPE_CODE_STRUCT
6201 || TYPE_NFIELDS (type) <= 0)
6203 return ada_is_variant_part (type, TYPE_NFIELDS (type) - 1);
6206 /* A record type with no fields, . */
6208 empty_record (objfile)
6209 struct objfile* objfile;
6211 struct type* type = alloc_type (objfile);
6212 TYPE_CODE (type) = TYPE_CODE_STRUCT;
6213 TYPE_NFIELDS (type) = 0;
6214 TYPE_FIELDS (type) = NULL;
6215 TYPE_NAME (type) = "<empty>";
6216 TYPE_TAG_NAME (type) = NULL;
6217 TYPE_FLAGS (type) = 0;
6218 TYPE_LENGTH (type) = 0;
6222 /* An ordinary record type (with fixed-length fields) that describes
6223 the value of type TYPE at VALADDR or ADDRESS (see comments at
6224 the beginning of this section) VAL according to GNAT conventions.
6225 DVAL0 should describe the (portion of a) record that contains any
6226 necessary discriminants. It should be NULL if VALUE_TYPE (VAL) is
6227 an outer-level type (i.e., as opposed to a branch of a variant.) A
6228 variant field (unless unchecked) is replaced by a particular branch
6230 /* NOTE: Limitations: For now, we assume that dynamic fields and
6231 * variants occupy whole numbers of bytes. However, they need not be
6235 template_to_fixed_record_type (type, valaddr, address, dval0)
6239 struct value* dval0;
6242 struct value* mark = value_mark();
6245 int nfields, bit_len;
6249 nfields = TYPE_NFIELDS (type);
6250 rtype = alloc_type (TYPE_OBJFILE (type));
6251 TYPE_CODE (rtype) = TYPE_CODE_STRUCT;
6252 INIT_CPLUS_SPECIFIC (rtype);
6253 TYPE_NFIELDS (rtype) = nfields;
6254 TYPE_FIELDS (rtype) = (struct field*)
6255 TYPE_ALLOC (rtype, nfields * sizeof (struct field));
6256 memset (TYPE_FIELDS (rtype), 0, sizeof (struct field) * nfields);
6257 TYPE_NAME (rtype) = ada_type_name (type);
6258 TYPE_TAG_NAME (rtype) = NULL;
6259 /* FIXME: TYPE_FLAG_FIXED_INSTANCE should be defined in
6261 /* TYPE_FLAGS (rtype) |= TYPE_FLAG_FIXED_INSTANCE;*/
6263 off = 0; bit_len = 0;
6264 for (f = 0; f < nfields; f += 1)
6266 int fld_bit_len, bit_incr;
6268 align_value (off, field_alignment (type, f))+TYPE_FIELD_BITPOS (type,f);
6269 /* NOTE: used to use field_offset above, but that causes
6270 * problems with really negative bit positions. So, let's
6271 * rediscover why we needed field_offset and fix it properly. */
6272 TYPE_FIELD_BITPOS (rtype, f) = off;
6273 TYPE_FIELD_BITSIZE (rtype, f) = 0;
6275 if (ada_is_variant_part (type, f))
6277 struct type *branch_type;
6281 value_from_contents_and_address (rtype, valaddr, address);
6286 to_fixed_variant_branch_type
6287 (TYPE_FIELD_TYPE (type, f),
6288 cond_offset_host (valaddr, off / TARGET_CHAR_BIT),
6289 cond_offset_target (address, off / TARGET_CHAR_BIT),
6291 if (branch_type == NULL)
6292 TYPE_NFIELDS (rtype) -= 1;
6295 TYPE_FIELD_TYPE (rtype, f) = branch_type;
6296 TYPE_FIELD_NAME (rtype, f) = "S";
6300 TYPE_LENGTH (TYPE_FIELD_TYPE (rtype, f)) * TARGET_CHAR_BIT;
6302 else if (is_dynamic_field (type, f))
6306 value_from_contents_and_address (rtype, valaddr, address);
6310 TYPE_FIELD_TYPE (rtype, f) =
6313 (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, f))),
6314 cond_offset_host (valaddr, off / TARGET_CHAR_BIT),
6315 cond_offset_target (address, off / TARGET_CHAR_BIT),
6317 TYPE_FIELD_NAME (rtype, f) = TYPE_FIELD_NAME (type, f);
6318 bit_incr = fld_bit_len =
6319 TYPE_LENGTH (TYPE_FIELD_TYPE (rtype, f)) * TARGET_CHAR_BIT;
6323 TYPE_FIELD_TYPE (rtype, f) = TYPE_FIELD_TYPE (type, f);
6324 TYPE_FIELD_NAME (rtype, f) = TYPE_FIELD_NAME (type, f);
6325 if (TYPE_FIELD_BITSIZE (type, f) > 0)
6326 bit_incr = fld_bit_len =
6327 TYPE_FIELD_BITSIZE (rtype, f) = TYPE_FIELD_BITSIZE (type, f);
6329 bit_incr = fld_bit_len =
6330 TYPE_LENGTH (TYPE_FIELD_TYPE (type, f)) * TARGET_CHAR_BIT;
6332 if (off + fld_bit_len > bit_len)
6333 bit_len = off + fld_bit_len;
6335 TYPE_LENGTH (rtype) = bit_len / TARGET_CHAR_BIT;
6337 TYPE_LENGTH (rtype) = align_value (TYPE_LENGTH (rtype), TYPE_LENGTH (type));
6339 value_free_to_mark (mark);
6340 if (TYPE_LENGTH (rtype) > varsize_limit)
6341 error ("record type with dynamic size is larger than varsize-limit");
6345 /* As for template_to_fixed_record_type, but uses no run-time values.
6346 As a result, this type can only be approximate, but that's OK,
6347 since it is used only for type determinations. Works on both
6349 Representation note: to save space, we memoize the result of this
6350 function in the TYPE_TARGET_TYPE of the template type. */
6353 template_to_static_fixed_type (templ_type)
6354 struct type* templ_type;
6360 if (TYPE_TARGET_TYPE (templ_type) != NULL)
6361 return TYPE_TARGET_TYPE (templ_type);
6363 nfields = TYPE_NFIELDS (templ_type);
6364 TYPE_TARGET_TYPE (templ_type) = type = alloc_type (TYPE_OBJFILE (templ_type));
6365 TYPE_CODE (type) = TYPE_CODE (templ_type);
6366 INIT_CPLUS_SPECIFIC (type);
6367 TYPE_NFIELDS (type) = nfields;
6368 TYPE_FIELDS (type) = (struct field*)
6369 TYPE_ALLOC (type, nfields * sizeof (struct field));
6370 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
6371 TYPE_NAME (type) = ada_type_name (templ_type);
6372 TYPE_TAG_NAME (type) = NULL;
6373 /* FIXME: TYPE_FLAG_FIXED_INSTANCE should be defined in gdbtypes.h */
6374 /* TYPE_FLAGS (type) |= TYPE_FLAG_FIXED_INSTANCE; */
6375 TYPE_LENGTH (type) = 0;
6377 for (f = 0; f < nfields; f += 1)
6379 TYPE_FIELD_BITPOS (type, f) = 0;
6380 TYPE_FIELD_BITSIZE (type, f) = 0;
6382 if (is_dynamic_field (templ_type, f))
6384 TYPE_FIELD_TYPE (type, f) =
6385 to_static_fixed_type (TYPE_TARGET_TYPE
6386 (TYPE_FIELD_TYPE (templ_type, f)));
6387 TYPE_FIELD_NAME (type, f) = TYPE_FIELD_NAME (templ_type, f);
6391 TYPE_FIELD_TYPE (type, f) =
6392 check_typedef (TYPE_FIELD_TYPE (templ_type, f));
6393 TYPE_FIELD_NAME (type, f) = TYPE_FIELD_NAME (templ_type, f);
6400 /* A revision of TYPE0 -- a non-dynamic-sized record with a variant
6401 part -- in which the variant part is replaced with the appropriate
6404 to_record_with_fixed_variant_part (type, valaddr, address, dval)
6410 struct value* mark = value_mark();
6412 struct type *branch_type;
6413 int nfields = TYPE_NFIELDS (type);
6418 rtype = alloc_type (TYPE_OBJFILE (type));
6419 TYPE_CODE (rtype) = TYPE_CODE_STRUCT;
6420 INIT_CPLUS_SPECIFIC (type);
6421 TYPE_NFIELDS (rtype) = TYPE_NFIELDS (type);
6422 TYPE_FIELDS (rtype) =
6423 (struct field*) TYPE_ALLOC (rtype, nfields * sizeof (struct field));
6424 memcpy (TYPE_FIELDS (rtype), TYPE_FIELDS (type),
6425 sizeof (struct field) * nfields);
6426 TYPE_NAME (rtype) = ada_type_name (type);
6427 TYPE_TAG_NAME (rtype) = NULL;
6428 /* FIXME: TYPE_FLAG_FIXED_INSTANCE should be defined in gdbtypes.h */
6429 /* TYPE_FLAGS (rtype) |= TYPE_FLAG_FIXED_INSTANCE; */
6430 TYPE_LENGTH (rtype) = TYPE_LENGTH (type);
6433 to_fixed_variant_branch_type
6434 (TYPE_FIELD_TYPE (type, nfields - 1),
6435 cond_offset_host (valaddr,
6436 TYPE_FIELD_BITPOS (type, nfields-1) / TARGET_CHAR_BIT),
6437 cond_offset_target (address,
6438 TYPE_FIELD_BITPOS (type, nfields-1) / TARGET_CHAR_BIT),
6440 if (branch_type == NULL)
6442 TYPE_NFIELDS (rtype) -= 1;
6443 TYPE_LENGTH (rtype) -= TYPE_LENGTH (TYPE_FIELD_TYPE (type, nfields - 1));
6447 TYPE_FIELD_TYPE (rtype, nfields-1) = branch_type;
6448 TYPE_FIELD_NAME (rtype, nfields-1) = "S";
6449 TYPE_FIELD_BITSIZE (rtype, nfields-1) = 0;
6450 TYPE_LENGTH (rtype) += TYPE_LENGTH (branch_type);
6451 - TYPE_LENGTH (TYPE_FIELD_TYPE (type, nfields - 1));
6457 /* An ordinary record type (with fixed-length fields) that describes
6458 the value at (TYPE0, VALADDR, ADDRESS) [see explanation at
6459 beginning of this section]. Any necessary discriminants' values
6460 should be in DVAL, a record value; it should be NULL if the object
6461 at ADDR itself contains any necessary discriminant values. A
6462 variant field (unless unchecked) is replaced by a particular branch
6466 to_fixed_record_type (type0, valaddr, address, dval)
6472 struct type* templ_type;
6474 /* FIXME: TYPE_FLAG_FIXED_INSTANCE should be defined in gdbtypes.h */
6475 /* if (TYPE_FLAGS (type0) & TYPE_FLAG_FIXED_INSTANCE)
6478 templ_type = dynamic_template_type (type0);
6480 if (templ_type != NULL)
6481 return template_to_fixed_record_type (templ_type, valaddr, address, dval);
6482 else if (contains_variant_part (type0))
6483 return to_record_with_fixed_variant_part (type0, valaddr, address, dval);
6486 /* FIXME: TYPE_FLAG_FIXED_INSTANCE should be defined in gdbtypes.h */
6487 /* TYPE_FLAGS (type0) |= TYPE_FLAG_FIXED_INSTANCE; */
6493 /* An ordinary record type (with fixed-length fields) that describes
6494 the value at (VAR_TYPE0, VALADDR, ADDRESS), where VAR_TYPE0 is a
6495 union type. Any necessary discriminants' values should be in DVAL,
6496 a record value. That is, this routine selects the appropriate
6497 branch of the union at ADDR according to the discriminant value
6498 indicated in the union's type name. */
6501 to_fixed_variant_branch_type (var_type0, valaddr, address, dval)
6502 struct type* var_type0;
6508 struct type* templ_type;
6509 struct type* var_type;
6511 if (TYPE_CODE (var_type0) == TYPE_CODE_PTR)
6512 var_type = TYPE_TARGET_TYPE (var_type0);
6514 var_type = var_type0;
6516 templ_type = ada_find_parallel_type (var_type, "___XVU");
6518 if (templ_type != NULL)
6519 var_type = templ_type;
6522 ada_which_variant_applies (var_type,
6523 VALUE_TYPE (dval), VALUE_CONTENTS (dval));
6526 return empty_record (TYPE_OBJFILE (var_type));
6527 else if (is_dynamic_field (var_type, which))
6529 to_fixed_record_type
6530 (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (var_type, which)),
6531 valaddr, address, dval);
6532 else if (contains_variant_part (TYPE_FIELD_TYPE (var_type, which)))
6534 to_fixed_record_type
6535 (TYPE_FIELD_TYPE (var_type, which), valaddr, address, dval);
6537 return TYPE_FIELD_TYPE (var_type, which);
6540 /* Assuming that TYPE0 is an array type describing the type of a value
6541 at ADDR, and that DVAL describes a record containing any
6542 discriminants used in TYPE0, returns a type for the value that
6543 contains no dynamic components (that is, no components whose sizes
6544 are determined by run-time quantities). Unless IGNORE_TOO_BIG is
6545 true, gives an error message if the resulting type's size is over
6550 to_fixed_array_type (type0, dval, ignore_too_big)
6555 struct type* index_type_desc;
6556 struct type* result;
6558 /* FIXME: TYPE_FLAG_FIXED_INSTANCE should be defined in gdbtypes.h */
6559 /* if (ada_is_packed_array_type (type0) /* revisit? */ /*
6560 || (TYPE_FLAGS (type0) & TYPE_FLAG_FIXED_INSTANCE))
6563 index_type_desc = ada_find_parallel_type (type0, "___XA");
6564 if (index_type_desc == NULL)
6566 struct type *elt_type0 = check_typedef (TYPE_TARGET_TYPE (type0));
6567 /* NOTE: elt_type---the fixed version of elt_type0---should never
6568 * depend on the contents of the array in properly constructed
6569 * debugging data. */
6570 struct type *elt_type =
6571 ada_to_fixed_type (elt_type0, 0, 0, dval);
6573 if (elt_type0 == elt_type)
6576 result = create_array_type (alloc_type (TYPE_OBJFILE (type0)),
6577 elt_type, TYPE_INDEX_TYPE (type0));
6582 struct type *elt_type0;
6585 for (i = TYPE_NFIELDS (index_type_desc); i > 0; i -= 1)
6586 elt_type0 = TYPE_TARGET_TYPE (elt_type0);
6588 /* NOTE: result---the fixed version of elt_type0---should never
6589 * depend on the contents of the array in properly constructed
6590 * debugging data. */
6592 ada_to_fixed_type (check_typedef (elt_type0), 0, 0, dval);
6593 for (i = TYPE_NFIELDS (index_type_desc) - 1; i >= 0; i -= 1)
6595 struct type *range_type =
6596 to_fixed_range_type (TYPE_FIELD_NAME (index_type_desc, i),
6597 dval, TYPE_OBJFILE (type0));
6598 result = create_array_type (alloc_type (TYPE_OBJFILE (type0)),
6599 result, range_type);
6601 if (! ignore_too_big && TYPE_LENGTH (result) > varsize_limit)
6602 error ("array type with dynamic size is larger than varsize-limit");
6605 /* FIXME: TYPE_FLAG_FIXED_INSTANCE should be defined in gdbtypes.h */
6606 /* TYPE_FLAGS (result) |= TYPE_FLAG_FIXED_INSTANCE; */
6611 /* A standard type (containing no dynamically sized components)
6612 corresponding to TYPE for the value (TYPE, VALADDR, ADDRESS)
6613 DVAL describes a record containing any discriminants used in TYPE0,
6614 and may be NULL if there are none. */
6617 ada_to_fixed_type (type, valaddr, address, dval)
6623 CHECK_TYPEDEF (type);
6624 switch (TYPE_CODE (type)) {
6627 case TYPE_CODE_STRUCT:
6628 return to_fixed_record_type (type, valaddr, address, NULL);
6629 case TYPE_CODE_ARRAY:
6630 return to_fixed_array_type (type, dval, 0);
6631 case TYPE_CODE_UNION:
6635 return to_fixed_variant_branch_type (type, valaddr, address, dval);
6639 /* A standard (static-sized) type corresponding as well as possible to
6640 TYPE0, but based on no runtime data. */
6643 to_static_fixed_type (type0)
6651 /* FIXME: TYPE_FLAG_FIXED_INSTANCE should be defined in gdbtypes.h */
6652 /* if (TYPE_FLAGS (type0) & TYPE_FLAG_FIXED_INSTANCE)
6655 CHECK_TYPEDEF (type0);
6657 switch (TYPE_CODE (type0))
6661 case TYPE_CODE_STRUCT:
6662 type = dynamic_template_type (type0);
6664 return template_to_static_fixed_type (type);
6666 case TYPE_CODE_UNION:
6667 type = ada_find_parallel_type (type0, "___XVU");
6669 return template_to_static_fixed_type (type);
6674 /* A static approximation of TYPE with all type wrappers removed. */
6676 static_unwrap_type (type)
6679 if (ada_is_aligner_type (type))
6681 struct type* type1 = TYPE_FIELD_TYPE (check_typedef (type), 0);
6682 if (ada_type_name (type1) == NULL)
6683 TYPE_NAME (type1) = ada_type_name (type);
6685 return static_unwrap_type (type1);
6689 struct type* raw_real_type = ada_get_base_type (type);
6690 if (raw_real_type == type)
6693 return to_static_fixed_type (raw_real_type);
6697 /* In some cases, incomplete and private types require
6698 cross-references that are not resolved as records (for example,
6700 type FooP is access Foo;
6702 type Foo is array ...;
6703 ). In these cases, since there is no mechanism for producing
6704 cross-references to such types, we instead substitute for FooP a
6705 stub enumeration type that is nowhere resolved, and whose tag is
6706 the name of the actual type. Call these types "non-record stubs". */
6708 /* A type equivalent to TYPE that is not a non-record stub, if one
6709 exists, otherwise TYPE. */
6711 ada_completed_type (type)
6714 CHECK_TYPEDEF (type);
6715 if (type == NULL || TYPE_CODE (type) != TYPE_CODE_ENUM
6716 || (TYPE_FLAGS (type) & TYPE_FLAG_STUB) == 0
6717 || TYPE_TAG_NAME (type) == NULL)
6721 char* name = TYPE_TAG_NAME (type);
6722 struct type* type1 = ada_find_any_type (name);
6723 return (type1 == NULL) ? type : type1;
6727 /* A value representing the data at VALADDR/ADDRESS as described by
6728 type TYPE0, but with a standard (static-sized) type that correctly
6729 describes it. If VAL0 is not NULL and TYPE0 already is a standard
6730 type, then return VAL0 [this feature is simply to avoid redundant
6731 creation of struct values]. */
6734 ada_to_fixed_value (type0, valaddr, address, val0)
6740 struct type* type = ada_to_fixed_type (type0, valaddr, address, NULL);
6741 if (type == type0 && val0 != NULL)
6743 else return value_from_contents_and_address (type, valaddr, address);
6746 /* A value representing VAL, but with a standard (static-sized) type
6747 chosen to approximate the real type of VAL as well as possible, but
6748 without consulting any runtime values. For Ada dynamic-sized
6749 types, therefore, the type of the result is likely to be inaccurate. */
6752 ada_to_static_fixed_value (val)
6756 to_static_fixed_type (static_unwrap_type (VALUE_TYPE (val)));
6757 if (type == VALUE_TYPE (val))
6760 return coerce_unspec_val_to_type (val, 0, type);
6769 /* Table mapping attribute numbers to names */
6770 /* NOTE: Keep up to date with enum ada_attribute definition in ada-lang.h */
6772 static const char* attribute_names[] = {
6790 ada_attribute_name (n)
6793 if (n > 0 && n < (int) ATR_END)
6794 return attribute_names[n];
6796 return attribute_names[0];
6799 /* Evaluate the 'POS attribute applied to ARG. */
6801 static struct value*
6805 struct type *type = VALUE_TYPE (arg);
6807 if (! discrete_type_p (type))
6808 error ("'POS only defined on discrete types");
6810 if (TYPE_CODE (type) == TYPE_CODE_ENUM)
6813 LONGEST v = value_as_long (arg);
6815 for (i = 0; i < TYPE_NFIELDS (type); i += 1)
6817 if (v == TYPE_FIELD_BITPOS (type, i))
6818 return value_from_longest (builtin_type_ada_int, i);
6820 error ("enumeration value is invalid: can't find 'POS");
6823 return value_from_longest (builtin_type_ada_int, value_as_long (arg));
6826 /* Evaluate the TYPE'VAL attribute applied to ARG. */
6828 static struct value*
6829 value_val_atr (type, arg)
6833 if (! discrete_type_p (type))
6834 error ("'VAL only defined on discrete types");
6835 if (! integer_type_p (VALUE_TYPE (arg)))
6836 error ("'VAL requires integral argument");
6838 if (TYPE_CODE (type) == TYPE_CODE_ENUM)
6840 long pos = value_as_long (arg);
6841 if (pos < 0 || pos >= TYPE_NFIELDS (type))
6842 error ("argument to 'VAL out of range");
6844 value_from_longest (type, TYPE_FIELD_BITPOS (type, pos));
6847 return value_from_longest (type, value_as_long (arg));
6853 /* True if TYPE appears to be an Ada character type.
6854 * [At the moment, this is true only for Character and Wide_Character;
6855 * It is a heuristic test that could stand improvement]. */
6858 ada_is_character_type (type)
6861 const char* name = ada_type_name (type);
6864 && (TYPE_CODE (type) == TYPE_CODE_CHAR
6865 || TYPE_CODE (type) == TYPE_CODE_INT
6866 || TYPE_CODE (type) == TYPE_CODE_RANGE)
6867 && (STREQ (name, "character") || STREQ (name, "wide_character")
6868 || STREQ (name, "unsigned char"));
6871 /* True if TYPE appears to be an Ada string type. */
6874 ada_is_string_type (type)
6877 CHECK_TYPEDEF (type);
6879 && TYPE_CODE (type) != TYPE_CODE_PTR
6880 && (ada_is_simple_array (type) || ada_is_array_descriptor (type))
6881 && ada_array_arity (type) == 1)
6883 struct type *elttype = ada_array_element_type (type, 1);
6885 return ada_is_character_type (elttype);
6892 /* True if TYPE is a struct type introduced by the compiler to force the
6893 alignment of a value. Such types have a single field with a
6894 distinctive name. */
6897 ada_is_aligner_type (type)
6900 CHECK_TYPEDEF (type);
6901 return (TYPE_CODE (type) == TYPE_CODE_STRUCT
6902 && TYPE_NFIELDS (type) == 1
6903 && STREQ (TYPE_FIELD_NAME (type, 0), "F"));
6906 /* If there is an ___XVS-convention type parallel to SUBTYPE, return
6907 the parallel type. */
6910 ada_get_base_type (raw_type)
6911 struct type* raw_type;
6913 struct type* real_type_namer;
6914 struct type* raw_real_type;
6915 struct type* real_type;
6917 if (raw_type == NULL || TYPE_CODE (raw_type) != TYPE_CODE_STRUCT)
6920 real_type_namer = ada_find_parallel_type (raw_type, "___XVS");
6921 if (real_type_namer == NULL
6922 || TYPE_CODE (real_type_namer) != TYPE_CODE_STRUCT
6923 || TYPE_NFIELDS (real_type_namer) != 1)
6926 raw_real_type = ada_find_any_type (TYPE_FIELD_NAME (real_type_namer, 0));
6927 if (raw_real_type == NULL)
6930 return raw_real_type;
6933 /* The type of value designated by TYPE, with all aligners removed. */
6936 ada_aligned_type (type)
6939 if (ada_is_aligner_type (type))
6940 return ada_aligned_type (TYPE_FIELD_TYPE (type, 0));
6942 return ada_get_base_type (type);
6946 /* The address of the aligned value in an object at address VALADDR
6947 having type TYPE. Assumes ada_is_aligner_type (TYPE). */
6950 ada_aligned_value_addr (type, valaddr)
6954 if (ada_is_aligner_type (type))
6955 return ada_aligned_value_addr (TYPE_FIELD_TYPE (type, 0),
6957 TYPE_FIELD_BITPOS (type, 0)/TARGET_CHAR_BIT);
6962 /* The printed representation of an enumeration literal with encoded
6963 name NAME. The value is good to the next call of ada_enum_name. */
6965 ada_enum_name (name)
6972 if ((tmp = strstr (name, "__")) != NULL)
6974 else if ((tmp = strchr (name, '.')) != NULL)
6982 static char result[16];
6984 if (name[1] == 'U' || name[1] == 'W')
6986 if (sscanf (name+2, "%x", &v) != 1)
6992 if (isascii (v) && isprint (v))
6993 sprintf (result, "'%c'", v);
6994 else if (name[1] == 'U')
6995 sprintf (result, "[\"%02x\"]", v);
6997 sprintf (result, "[\"%04x\"]", v);
7005 static struct value*
7006 evaluate_subexp (expect_type, exp, pos, noside)
7007 struct type *expect_type;
7008 struct expression *exp;
7012 return (*exp->language_defn->evaluate_exp) (expect_type, exp, pos, noside);
7015 /* Evaluate the subexpression of EXP starting at *POS as for
7016 evaluate_type, updating *POS to point just past the evaluated
7019 static struct value*
7020 evaluate_subexp_type (exp, pos)
7021 struct expression* exp;
7024 return (*exp->language_defn->evaluate_exp)
7025 (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
7028 /* If VAL is wrapped in an aligner or subtype wrapper, return the
7031 static struct value*
7035 struct type* type = check_typedef (VALUE_TYPE (val));
7036 if (ada_is_aligner_type (type))
7038 struct value* v = value_struct_elt (&val, NULL, "F",
7039 NULL, "internal structure");
7040 struct type* val_type = check_typedef (VALUE_TYPE (v));
7041 if (ada_type_name (val_type) == NULL)
7042 TYPE_NAME (val_type) = ada_type_name (type);
7044 return unwrap_value (v);
7048 struct type* raw_real_type =
7049 ada_completed_type (ada_get_base_type (type));
7051 if (type == raw_real_type)
7055 coerce_unspec_val_to_type
7056 (val, 0, ada_to_fixed_type (raw_real_type, 0,
7057 VALUE_ADDRESS (val) + VALUE_OFFSET (val),
7062 static struct value*
7063 cast_to_fixed (type, arg)
7069 if (type == VALUE_TYPE (arg))
7071 else if (ada_is_fixed_point_type (VALUE_TYPE (arg)))
7072 val = ada_float_to_fixed (type,
7073 ada_fixed_to_float (VALUE_TYPE (arg),
7074 value_as_long (arg)));
7078 value_as_double (value_cast (builtin_type_double, value_copy (arg)));
7079 val = ada_float_to_fixed (type, argd);
7082 return value_from_longest (type, val);
7085 static struct value*
7086 cast_from_fixed_to_double (arg)
7089 DOUBLEST val = ada_fixed_to_float (VALUE_TYPE (arg),
7090 value_as_long (arg));
7091 return value_from_double (builtin_type_double, val);
7094 /* Coerce VAL as necessary for assignment to an lval of type TYPE, and
7095 * return the converted value. */
7096 static struct value*
7097 coerce_for_assign (type, val)
7101 struct type* type2 = VALUE_TYPE (val);
7105 CHECK_TYPEDEF (type2);
7106 CHECK_TYPEDEF (type);
7108 if (TYPE_CODE (type2) == TYPE_CODE_PTR && TYPE_CODE (type) == TYPE_CODE_ARRAY)
7110 val = ada_value_ind (val);
7111 type2 = VALUE_TYPE (val);
7114 if (TYPE_CODE (type2) == TYPE_CODE_ARRAY
7115 && TYPE_CODE (type) == TYPE_CODE_ARRAY)
7117 if (TYPE_LENGTH (type2) != TYPE_LENGTH (type)
7118 || TYPE_LENGTH (TYPE_TARGET_TYPE (type2))
7119 != TYPE_LENGTH (TYPE_TARGET_TYPE (type2)))
7120 error ("Incompatible types in assignment");
7121 VALUE_TYPE (val) = type;
7127 ada_evaluate_subexp (expect_type, exp, pos, noside)
7128 struct type *expect_type;
7129 struct expression *exp;
7134 enum ada_attribute atr;
7135 int tem, tem2, tem3;
7137 struct value *arg1 = NULL, *arg2 = NULL, *arg3;
7140 struct value* *argvec;
7142 pc = *pos; *pos += 1;
7143 op = exp->elts[pc].opcode;
7149 return unwrap_value (evaluate_subexp_standard (expect_type, exp, pos, noside));
7153 type = exp->elts[pc + 1].type;
7154 arg1 = evaluate_subexp (type, exp, pos, noside);
7155 if (noside == EVAL_SKIP)
7157 if (type != check_typedef (VALUE_TYPE (arg1)))
7159 if (ada_is_fixed_point_type (type))
7160 arg1 = cast_to_fixed (type, arg1);
7161 else if (ada_is_fixed_point_type (VALUE_TYPE (arg1)))
7162 arg1 = value_cast (type, cast_from_fixed_to_double (arg1));
7163 else if (VALUE_LVAL (arg1) == lval_memory)
7165 /* This is in case of the really obscure (and undocumented,
7166 but apparently expected) case of (Foo) Bar.all, where Bar
7167 is an integer constant and Foo is a dynamic-sized type.
7168 If we don't do this, ARG1 will simply be relabeled with
7170 if (noside == EVAL_AVOID_SIDE_EFFECTS)
7171 return value_zero (to_static_fixed_type (type), not_lval);
7174 (type, 0, VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1), 0);
7177 arg1 = value_cast (type, arg1);
7181 /* FIXME: UNOP_QUAL should be defined in expression.h */
7184 type = exp->elts[pc + 1].type;
7185 return ada_evaluate_subexp (type, exp, pos, noside);
7188 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
7189 arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside);
7190 if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
7192 if (binop_user_defined_p (op, arg1, arg2))
7193 return value_x_binop (arg1, arg2, op, OP_NULL, EVAL_NORMAL);
7196 if (ada_is_fixed_point_type (VALUE_TYPE (arg1)))
7197 arg2 = cast_to_fixed (VALUE_TYPE (arg1), arg2);
7198 else if (ada_is_fixed_point_type (VALUE_TYPE (arg2)))
7199 error ("Fixed-point values must be assigned to fixed-point variables");
7201 arg2 = coerce_for_assign (VALUE_TYPE (arg1), arg2);
7202 return ada_value_assign (arg1, arg2);
7206 arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
7207 arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
7208 if (noside == EVAL_SKIP)
7210 if (binop_user_defined_p (op, arg1, arg2))
7211 return value_x_binop (arg1, arg2, op, OP_NULL, EVAL_NORMAL);
7214 if ((ada_is_fixed_point_type (VALUE_TYPE (arg1))
7215 || ada_is_fixed_point_type (VALUE_TYPE (arg2)))
7216 && VALUE_TYPE (arg1) != VALUE_TYPE (arg2))
7217 error ("Operands of fixed-point addition must have the same type");
7218 return value_cast (VALUE_TYPE (arg1), value_add (arg1, arg2));
7222 arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
7223 arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
7224 if (noside == EVAL_SKIP)
7226 if (binop_user_defined_p (op, arg1, arg2))
7227 return value_x_binop (arg1, arg2, op, OP_NULL, EVAL_NORMAL);
7230 if ((ada_is_fixed_point_type (VALUE_TYPE (arg1))
7231 || ada_is_fixed_point_type (VALUE_TYPE (arg2)))
7232 && VALUE_TYPE (arg1) != VALUE_TYPE (arg2))
7233 error ("Operands of fixed-point subtraction must have the same type");
7234 return value_cast (VALUE_TYPE (arg1), value_sub (arg1, arg2));
7239 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
7240 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
7241 if (noside == EVAL_SKIP)
7243 if (binop_user_defined_p (op, arg1, arg2))
7244 return value_x_binop (arg1, arg2, op, OP_NULL, EVAL_NORMAL);
7246 if (noside == EVAL_AVOID_SIDE_EFFECTS
7247 && (op == BINOP_DIV || op == BINOP_REM || op == BINOP_MOD))
7248 return value_zero (VALUE_TYPE (arg1), not_lval);
7251 if (ada_is_fixed_point_type (VALUE_TYPE (arg1)))
7252 arg1 = cast_from_fixed_to_double (arg1);
7253 if (ada_is_fixed_point_type (VALUE_TYPE (arg2)))
7254 arg2 = cast_from_fixed_to_double (arg2);
7255 return value_binop (arg1, arg2, op);
7259 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
7260 if (noside == EVAL_SKIP)
7262 if (unop_user_defined_p (op, arg1))
7263 return value_x_unop (arg1, op, EVAL_NORMAL);
7264 else if (ada_is_fixed_point_type (VALUE_TYPE (arg1)))
7265 return value_cast (VALUE_TYPE (arg1), value_neg (arg1));
7267 return value_neg (arg1);
7269 /* FIXME: OP_UNRESOLVED_VALUE should be defined in expression.h */
7270 /* case OP_UNRESOLVED_VALUE:
7271 /* Only encountered when an unresolved symbol occurs in a
7272 context other than a function call, in which case, it is
7275 if (noside == EVAL_SKIP)
7278 error ("Unexpected unresolved symbol, %s, during evaluation",
7279 ada_demangle (exp->elts[pc + 2].name));
7283 if (noside == EVAL_SKIP)
7288 else if (noside == EVAL_AVOID_SIDE_EFFECTS)
7292 (to_static_fixed_type
7293 (static_unwrap_type (SYMBOL_TYPE (exp->elts[pc+2].symbol))),
7298 arg1 = unwrap_value (evaluate_subexp_standard (expect_type, exp, pos,
7300 return ada_to_fixed_value (VALUE_TYPE (arg1), 0,
7301 VALUE_ADDRESS (arg1) + VALUE_OFFSET(arg1),
7307 tem2 = longest_to_int (exp->elts[pc + 1].longconst);
7308 tem3 = longest_to_int (exp->elts[pc + 2].longconst);
7309 nargs = tem3 - tem2 + 1;
7310 type = expect_type ? check_typedef (expect_type) : NULL_TYPE;
7312 argvec = (struct value* *) alloca (sizeof (struct value*) * (nargs + 1));
7313 for (tem = 0; tem == 0 || tem < nargs; tem += 1)
7314 /* At least one element gets inserted for the type */
7316 /* Ensure that array expressions are coerced into pointer objects. */
7317 argvec[tem] = evaluate_subexp_with_coercion (exp, pos, noside);
7319 if (noside == EVAL_SKIP)
7321 return value_array (tem2, tem3, argvec);
7326 /* Allocate arg vector, including space for the function to be
7327 called in argvec[0] and a terminating NULL */
7328 nargs = longest_to_int (exp->elts[pc + 1].longconst);
7329 argvec = (struct value* *) alloca (sizeof (struct value*) * (nargs + 2));
7331 /* FIXME: OP_UNRESOLVED_VALUE should be defined in expression.h */
7332 /* FIXME: name should be defined in expresion.h */
7333 /* if (exp->elts[*pos].opcode == OP_UNRESOLVED_VALUE)
7334 error ("Unexpected unresolved symbol, %s, during evaluation",
7335 ada_demangle (exp->elts[pc + 5].name));
7339 error ("unexpected code path, FIXME");
7343 for (tem = 0; tem <= nargs; tem += 1)
7344 argvec[tem] = evaluate_subexp (NULL_TYPE, exp, pos, noside);
7347 if (noside == EVAL_SKIP)
7351 if (TYPE_CODE (VALUE_TYPE (argvec[0])) == TYPE_CODE_REF)
7352 argvec[0] = value_addr (argvec[0]);
7354 if (ada_is_packed_array_type (VALUE_TYPE (argvec[0])))
7355 argvec[0] = ada_coerce_to_simple_array (argvec[0]);
7357 type = check_typedef (VALUE_TYPE (argvec[0]));
7358 if (TYPE_CODE (type) == TYPE_CODE_PTR)
7360 switch (TYPE_CODE (check_typedef (TYPE_TARGET_TYPE (type))))
7362 case TYPE_CODE_FUNC:
7363 type = check_typedef (TYPE_TARGET_TYPE (type));
7365 case TYPE_CODE_ARRAY:
7367 case TYPE_CODE_STRUCT:
7368 if (noside != EVAL_AVOID_SIDE_EFFECTS)
7369 argvec[0] = ada_value_ind (argvec[0]);
7370 type = check_typedef (TYPE_TARGET_TYPE (type));
7373 error ("cannot subscript or call something of type `%s'",
7374 ada_type_name (VALUE_TYPE (argvec[0])));
7379 switch (TYPE_CODE (type))
7381 case TYPE_CODE_FUNC:
7382 if (noside == EVAL_AVOID_SIDE_EFFECTS)
7383 return allocate_value (TYPE_TARGET_TYPE (type));
7384 return call_function_by_hand (argvec[0], nargs, argvec + 1);
7385 case TYPE_CODE_STRUCT:
7387 int arity = ada_array_arity (type);
7388 type = ada_array_element_type (type, nargs);
7390 error ("cannot subscript or call a record");
7392 error ("wrong number of subscripts; expecting %d", arity);
7393 if (noside == EVAL_AVOID_SIDE_EFFECTS)
7394 return allocate_value (ada_aligned_type (type));
7395 return unwrap_value (ada_value_subscript (argvec[0], nargs, argvec+1));
7397 case TYPE_CODE_ARRAY:
7398 if (noside == EVAL_AVOID_SIDE_EFFECTS)
7400 type = ada_array_element_type (type, nargs);
7402 error ("element type of array unknown");
7404 return allocate_value (ada_aligned_type (type));
7407 unwrap_value (ada_value_subscript
7408 (ada_coerce_to_simple_array (argvec[0]),
7410 case TYPE_CODE_PTR: /* Pointer to array */
7411 type = to_fixed_array_type (TYPE_TARGET_TYPE (type), NULL, 1);
7412 if (noside == EVAL_AVOID_SIDE_EFFECTS)
7414 type = ada_array_element_type (type, nargs);
7416 error ("element type of array unknown");
7418 return allocate_value (ada_aligned_type (type));
7421 unwrap_value (ada_value_ptr_subscript (argvec[0], type,
7425 error ("Internal error in evaluate_subexp");
7430 struct value* array = evaluate_subexp (NULL_TYPE, exp, pos, noside);
7432 = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
7434 = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
7435 if (noside == EVAL_SKIP)
7438 /* If this is a reference to an array, then dereference it */
7439 if (TYPE_CODE (VALUE_TYPE (array)) == TYPE_CODE_REF
7440 && TYPE_TARGET_TYPE (VALUE_TYPE (array)) != NULL
7441 && TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (array))) ==
7443 && !ada_is_array_descriptor (check_typedef (VALUE_TYPE
7446 array = ada_coerce_ref (array);
7449 if (noside == EVAL_AVOID_SIDE_EFFECTS &&
7450 ada_is_array_descriptor (check_typedef (VALUE_TYPE (array))))
7452 /* Try to dereference the array, in case it is an access to array */
7453 struct type * arrType = ada_type_of_array (array, 0);
7454 if (arrType != NULL)
7455 array = value_at_lazy (arrType, 0, NULL);
7457 if (ada_is_array_descriptor (VALUE_TYPE (array)))
7458 array = ada_coerce_to_simple_array (array);
7460 /* If at this point we have a pointer to an array, it means that
7461 it is a pointer to a simple (non-ada) array. We just then
7463 if (TYPE_CODE (VALUE_TYPE (array)) == TYPE_CODE_PTR
7464 && TYPE_TARGET_TYPE (VALUE_TYPE (array)) != NULL
7465 && TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (array))) ==
7468 array = ada_value_ind (array);
7471 if (noside == EVAL_AVOID_SIDE_EFFECTS)
7472 /* The following will get the bounds wrong, but only in contexts
7473 where the value is not being requested (FIXME?). */
7476 return value_slice (array, lowbound, upper - lowbound + 1);
7479 /* FIXME: UNOP_MBR should be defined in expression.h */
7482 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
7483 type = exp->elts[pc + 1].type;
7485 if (noside == EVAL_SKIP)
7488 switch (TYPE_CODE (type))
7491 warning ("Membership test incompletely implemented; always returns true");
7492 return value_from_longest (builtin_type_int, (LONGEST) 1);
7494 case TYPE_CODE_RANGE:
7495 arg2 = value_from_longest (builtin_type_int,
7496 (LONGEST) TYPE_LOW_BOUND (type));
7497 arg3 = value_from_longest (builtin_type_int,
7498 (LONGEST) TYPE_HIGH_BOUND (type));
7500 value_from_longest (builtin_type_int,
7501 (value_less (arg1,arg3)
7502 || value_equal (arg1,arg3))
7503 && (value_less (arg2,arg1)
7504 || value_equal (arg2,arg1)));
7507 /* FIXME: BINOP_MBR should be defined in expression.h */
7510 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
7511 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
7513 if (noside == EVAL_SKIP)
7516 if (noside == EVAL_AVOID_SIDE_EFFECTS)
7517 return value_zero (builtin_type_int, not_lval);
7519 tem = longest_to_int (exp->elts[pc + 1].longconst);
7521 if (tem < 1 || tem > ada_array_arity (VALUE_TYPE (arg2)))
7522 error ("invalid dimension number to '%s", "range");
7524 arg3 = ada_array_bound (arg2, tem, 1);
7525 arg2 = ada_array_bound (arg2, tem, 0);
7528 value_from_longest (builtin_type_int,
7529 (value_less (arg1,arg3)
7530 || value_equal (arg1,arg3))
7531 && (value_less (arg2,arg1)
7532 || value_equal (arg2,arg1)));
7534 /* FIXME: TERNOP_MBR should be defined in expression.h */
7536 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
7537 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
7538 arg3 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
7540 if (noside == EVAL_SKIP)
7544 value_from_longest (builtin_type_int,
7545 (value_less (arg1,arg3)
7546 || value_equal (arg1,arg3))
7547 && (value_less (arg2,arg1)
7548 || value_equal (arg2,arg1)));
7550 /* FIXME: OP_ATTRIBUTE should be defined in expression.h */
7551 /* case OP_ATTRIBUTE:
7553 atr = (enum ada_attribute) longest_to_int (exp->elts[pc + 2].longconst);
7557 error ("unexpected attribute encountered");
7563 struct type* type_arg;
7564 if (exp->elts[*pos].opcode == OP_TYPE)
7566 evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
7568 type_arg = exp->elts[pc + 5].type;
7572 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
7576 if (exp->elts[*pos].opcode != OP_LONG)
7577 error ("illegal operand to '%s", ada_attribute_name (atr));
7578 tem = longest_to_int (exp->elts[*pos+2].longconst);
7581 if (noside == EVAL_SKIP)
7584 if (type_arg == NULL)
7586 arg1 = ada_coerce_ref (arg1);
7588 if (ada_is_packed_array_type (VALUE_TYPE (arg1)))
7589 arg1 = ada_coerce_to_simple_array (arg1);
7591 if (tem < 1 || tem > ada_array_arity (VALUE_TYPE (arg1)))
7592 error ("invalid dimension number to '%s",
7593 ada_attribute_name (atr));
7595 if (noside == EVAL_AVOID_SIDE_EFFECTS)
7597 type = ada_index_type (VALUE_TYPE (arg1), tem);
7599 error ("attempt to take bound of something that is not an array");
7600 return allocate_value (type);
7606 error ("unexpected attribute encountered");
7608 return ada_array_bound (arg1, tem, 0);
7610 return ada_array_bound (arg1, tem, 1);
7612 return ada_array_length (arg1, tem);
7615 else if (TYPE_CODE (type_arg) == TYPE_CODE_RANGE
7616 || TYPE_CODE (type_arg) == TYPE_CODE_INT)
7618 struct type* range_type;
7619 char* name = ada_type_name (type_arg);
7622 if (TYPE_CODE (type_arg) == TYPE_CODE_RANGE)
7623 range_type = type_arg;
7625 error ("unimplemented type attribute");
7629 to_fixed_range_type (name, NULL, TYPE_OBJFILE (type_arg));
7633 error ("unexpected attribute encountered");
7635 return value_from_longest (TYPE_TARGET_TYPE (range_type),
7636 TYPE_LOW_BOUND (range_type));
7638 return value_from_longest (TYPE_TARGET_TYPE (range_type),
7639 TYPE_HIGH_BOUND (range_type));
7642 else if (TYPE_CODE (type_arg) == TYPE_CODE_ENUM)
7647 error ("unexpected attribute encountered");
7649 return value_from_longest
7650 (type_arg, TYPE_FIELD_BITPOS (type_arg, 0));
7652 return value_from_longest
7654 TYPE_FIELD_BITPOS (type_arg,
7655 TYPE_NFIELDS (type_arg) - 1));
7658 else if (TYPE_CODE (type_arg) == TYPE_CODE_FLT)
7659 error ("unimplemented type attribute");
7664 if (ada_is_packed_array_type (type_arg))
7665 type_arg = decode_packed_array_type (type_arg);
7667 if (tem < 1 || tem > ada_array_arity (type_arg))
7668 error ("invalid dimension number to '%s",
7669 ada_attribute_name (atr));
7671 if (noside == EVAL_AVOID_SIDE_EFFECTS)
7673 type = ada_index_type (type_arg, tem);
7675 error ("attempt to take bound of something that is not an array");
7676 return allocate_value (type);
7682 error ("unexpected attribute encountered");
7684 low = ada_array_bound_from_type (type_arg, tem, 0, &type);
7685 return value_from_longest (type, low);
7687 high = ada_array_bound_from_type (type_arg, tem, 1, &type);
7688 return value_from_longest (type, high);
7690 low = ada_array_bound_from_type (type_arg, tem, 0, &type);
7691 high = ada_array_bound_from_type (type_arg, tem, 1, NULL);
7692 return value_from_longest (type, high-low+1);
7698 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
7699 if (noside == EVAL_SKIP)
7702 if (noside == EVAL_AVOID_SIDE_EFFECTS)
7704 value_zero (ada_tag_type (arg1), not_lval);
7706 return ada_value_tag (arg1);
7710 evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
7711 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
7712 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
7713 if (noside == EVAL_SKIP)
7715 else if (noside == EVAL_AVOID_SIDE_EFFECTS)
7716 return value_zero (VALUE_TYPE (arg1), not_lval);
7718 return value_binop (arg1, arg2,
7719 atr == ATR_MIN ? BINOP_MIN : BINOP_MAX);
7723 struct type* type_arg = exp->elts[pc + 5].type;
7724 evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
7727 if (noside == EVAL_SKIP)
7730 if (! ada_is_modular_type (type_arg))
7731 error ("'modulus must be applied to modular type");
7733 return value_from_longest (TYPE_TARGET_TYPE (type_arg),
7734 ada_modulus (type_arg));
7739 evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
7740 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
7741 if (noside == EVAL_SKIP)
7743 else if (noside == EVAL_AVOID_SIDE_EFFECTS)
7744 return value_zero (builtin_type_ada_int, not_lval);
7746 return value_pos_atr (arg1);
7749 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
7750 if (noside == EVAL_SKIP)
7752 else if (noside == EVAL_AVOID_SIDE_EFFECTS)
7753 return value_zero (builtin_type_ada_int, not_lval);
7755 return value_from_longest (builtin_type_ada_int,
7757 * TYPE_LENGTH (VALUE_TYPE (arg1)));
7760 evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
7761 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
7762 type = exp->elts[pc + 5].type;
7763 if (noside == EVAL_SKIP)
7765 else if (noside == EVAL_AVOID_SIDE_EFFECTS)
7766 return value_zero (type, not_lval);
7768 return value_val_atr (type, arg1);
7771 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
7772 arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
7773 if (noside == EVAL_SKIP)
7775 if (binop_user_defined_p (op, arg1, arg2))
7776 return unwrap_value (value_x_binop (arg1, arg2, op, OP_NULL,
7779 if (noside == EVAL_AVOID_SIDE_EFFECTS)
7780 return value_zero (VALUE_TYPE (arg1), not_lval);
7782 return value_binop (arg1, arg2, op);
7785 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
7786 if (noside == EVAL_SKIP)
7788 if (unop_user_defined_p (op, arg1))
7789 return unwrap_value (value_x_unop (arg1, op, EVAL_NORMAL));
7794 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
7795 if (noside == EVAL_SKIP)
7797 if (value_less (arg1, value_zero (VALUE_TYPE (arg1), not_lval)))
7798 return value_neg (arg1);
7803 if (expect_type && TYPE_CODE (expect_type) == TYPE_CODE_PTR)
7804 expect_type = TYPE_TARGET_TYPE (check_typedef (expect_type));
7805 arg1 = evaluate_subexp (expect_type, exp, pos, noside);
7806 if (noside == EVAL_SKIP)
7808 type = check_typedef (VALUE_TYPE (arg1));
7809 if (noside == EVAL_AVOID_SIDE_EFFECTS)
7811 if (ada_is_array_descriptor (type))
7812 /* GDB allows dereferencing GNAT array descriptors. */
7814 struct type* arrType = ada_type_of_array (arg1, 0);
7815 if (arrType == NULL)
7816 error ("Attempt to dereference null array pointer.");
7817 return value_at_lazy (arrType, 0, NULL);
7819 else if (TYPE_CODE (type) == TYPE_CODE_PTR
7820 || TYPE_CODE (type) == TYPE_CODE_REF
7821 /* In C you can dereference an array to get the 1st elt. */
7822 || TYPE_CODE (type) == TYPE_CODE_ARRAY
7826 (to_static_fixed_type
7827 (ada_aligned_type (check_typedef (TYPE_TARGET_TYPE (type)))),
7829 else if (TYPE_CODE (type) == TYPE_CODE_INT)
7830 /* GDB allows dereferencing an int. */
7831 return value_zero (builtin_type_int, lval_memory);
7833 error ("Attempt to take contents of a non-pointer value.");
7835 arg1 = ada_coerce_ref (arg1);
7836 type = check_typedef (VALUE_TYPE (arg1));
7838 if (ada_is_array_descriptor (type))
7839 /* GDB allows dereferencing GNAT array descriptors. */
7840 return ada_coerce_to_simple_array (arg1);
7842 return ada_value_ind (arg1);
7844 case STRUCTOP_STRUCT:
7845 tem = longest_to_int (exp->elts[pc + 1].longconst);
7846 (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
7847 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
7848 if (noside == EVAL_SKIP)
7850 if (noside == EVAL_AVOID_SIDE_EFFECTS)
7851 return value_zero (ada_aligned_type
7852 (ada_lookup_struct_elt_type (VALUE_TYPE (arg1),
7853 &exp->elts[pc + 2].string,
7857 return unwrap_value (ada_value_struct_elt (arg1,
7858 &exp->elts[pc + 2].string,
7861 /* The value is not supposed to be used. This is here to make it
7862 easier to accommodate expressions that contain types. */
7864 if (noside == EVAL_SKIP)
7866 else if (noside == EVAL_AVOID_SIDE_EFFECTS)
7867 return allocate_value (builtin_type_void);
7869 error ("Attempt to use a type name as an expression");
7872 tem = longest_to_int (exp->elts[pc + 1].longconst);
7873 (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
7874 arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
7875 if (noside == EVAL_SKIP)
7877 if (noside == EVAL_AVOID_SIDE_EFFECTS)
7878 return value_zero (ada_aligned_type
7879 (ada_lookup_struct_elt_type (VALUE_TYPE (arg1),
7880 &exp->elts[pc + 2].string,
7884 return unwrap_value (ada_value_struct_elt (arg1,
7885 &exp->elts[pc + 2].string,
7890 return value_from_longest (builtin_type_long, (LONGEST) 1);
7896 /* If TYPE encodes an Ada fixed-point type, return the suffix of the
7897 type name that encodes the 'small and 'delta information.
7898 Otherwise, return NULL. */
7901 fixed_type_info (type)
7904 const char* name = ada_type_name (type);
7905 enum type_code code = (type == NULL) ? TYPE_CODE_UNDEF : TYPE_CODE (type);
7907 if ((code == TYPE_CODE_INT || code == TYPE_CODE_RANGE)
7910 const char *tail = strstr (name, "___XF_");
7916 else if (code == TYPE_CODE_RANGE && TYPE_TARGET_TYPE (type) != type)
7917 return fixed_type_info (TYPE_TARGET_TYPE (type));
7922 /* Returns non-zero iff TYPE represents an Ada fixed-point type. */
7925 ada_is_fixed_point_type (type)
7928 return fixed_type_info (type) != NULL;
7931 /* Assuming that TYPE is the representation of an Ada fixed-point
7932 type, return its delta, or -1 if the type is malformed and the
7933 delta cannot be determined. */
7939 const char *encoding = fixed_type_info (type);
7942 if (sscanf (encoding, "_%ld_%ld", &num, &den) < 2)
7945 return (DOUBLEST) num / (DOUBLEST) den;
7948 /* Assuming that ada_is_fixed_point_type (TYPE), return the scaling
7949 factor ('SMALL value) associated with the type. */
7952 scaling_factor (type)
7955 const char *encoding = fixed_type_info (type);
7956 unsigned long num0, den0, num1, den1;
7959 n = sscanf (encoding, "_%lu_%lu_%lu_%lu", &num0, &den0, &num1, &den1);
7964 return (DOUBLEST) num1 / (DOUBLEST) den1;
7966 return (DOUBLEST) num0 / (DOUBLEST) den0;
7970 /* Assuming that X is the representation of a value of fixed-point
7971 type TYPE, return its floating-point equivalent. */
7974 ada_fixed_to_float (type, x)
7978 return (DOUBLEST) x * scaling_factor (type);
7981 /* The representation of a fixed-point value of type TYPE
7982 corresponding to the value X. */
7985 ada_float_to_fixed (type, x)
7989 return (LONGEST) (x / scaling_factor (type) + 0.5);
7993 /* VAX floating formats */
7995 /* Non-zero iff TYPE represents one of the special VAX floating-point
7998 ada_is_vax_floating_type (type)
8002 (ada_type_name (type) == NULL) ? 0 : strlen (ada_type_name (type));
8005 && (TYPE_CODE (type) == TYPE_CODE_INT
8006 || TYPE_CODE (type) == TYPE_CODE_RANGE)
8007 && STREQN (ada_type_name (type) + name_len - 6, "___XF", 5);
8010 /* The type of special VAX floating-point type this is, assuming
8011 ada_is_vax_floating_point */
8013 ada_vax_float_type_suffix (type)
8016 return ada_type_name (type)[strlen (ada_type_name (type))-1];
8019 /* A value representing the special debugging function that outputs
8020 VAX floating-point values of the type represented by TYPE. Assumes
8021 ada_is_vax_floating_type (TYPE). */
8023 ada_vax_float_print_function (type)
8027 switch (ada_vax_float_type_suffix (type)) {
8030 get_var_value ("DEBUG_STRING_F", 0);
8033 get_var_value ("DEBUG_STRING_D", 0);
8036 get_var_value ("DEBUG_STRING_G", 0);
8038 error ("invalid VAX floating-point type");
8045 /* Scan STR beginning at position K for a discriminant name, and
8046 return the value of that discriminant field of DVAL in *PX. If
8047 PNEW_K is not null, put the position of the character beyond the
8048 name scanned in *PNEW_K. Return 1 if successful; return 0 and do
8049 not alter *PX and *PNEW_K if unsuccessful. */
8052 scan_discrim_bound (str, k, dval, px, pnew_k)
8059 static char *bound_buffer = NULL;
8060 static size_t bound_buffer_len = 0;
8063 struct value* bound_val;
8065 if (dval == NULL || str == NULL || str[k] == '\0')
8068 pend = strstr (str+k, "__");
8072 k += strlen (bound);
8076 GROW_VECT (bound_buffer, bound_buffer_len, pend - (str+k) + 1);
8077 bound = bound_buffer;
8078 strncpy (bound_buffer, str+k, pend-(str+k));
8079 bound[pend-(str+k)] = '\0';
8084 ada_search_struct_field (bound, dval, 0, VALUE_TYPE (dval));
8085 if (bound_val == NULL)
8088 *px = value_as_long (bound_val);
8094 /* Value of variable named NAME in the current environment. If
8095 no such variable found, then if ERR_MSG is null, returns 0, and
8096 otherwise causes an error with message ERR_MSG. */
8097 static struct value*
8098 get_var_value (name, err_msg)
8102 struct symbol** syms;
8103 struct block** blocks;
8106 nsyms = ada_lookup_symbol_list (name, get_selected_block (NULL), VAR_NAMESPACE,
8111 if (err_msg == NULL)
8114 error ("%s", err_msg);
8117 return value_of_variable (syms[0], blocks[0]);
8120 /* Value of integer variable named NAME in the current environment. If
8121 no such variable found, then if ERR_MSG is null, returns 0, and sets
8122 *FLAG to 0. If successful, sets *FLAG to 1. */
8124 get_int_var_value (name, err_msg, flag)
8129 struct value* var_val = get_var_value (name, err_msg);
8141 return value_as_long (var_val);
8146 /* Return a range type whose base type is that of the range type named
8147 NAME in the current environment, and whose bounds are calculated
8148 from NAME according to the GNAT range encoding conventions.
8149 Extract discriminant values, if needed, from DVAL. If a new type
8150 must be created, allocate in OBJFILE's space. The bounds
8151 information, in general, is encoded in NAME, the base type given in
8152 the named range type. */
8155 to_fixed_range_type (name, dval, objfile)
8158 struct objfile *objfile;
8160 struct type *raw_type = ada_find_any_type (name);
8161 struct type *base_type;
8165 if (raw_type == NULL)
8166 base_type = builtin_type_int;
8167 else if (TYPE_CODE (raw_type) == TYPE_CODE_RANGE)
8168 base_type = TYPE_TARGET_TYPE (raw_type);
8170 base_type = raw_type;
8172 subtype_info = strstr (name, "___XD");
8173 if (subtype_info == NULL)
8177 static char *name_buf = NULL;
8178 static size_t name_len = 0;
8179 int prefix_len = subtype_info - name;
8185 GROW_VECT (name_buf, name_len, prefix_len + 5);
8186 strncpy (name_buf, name, prefix_len);
8187 name_buf[prefix_len] = '\0';
8190 bounds_str = strchr (subtype_info, '_');
8193 if (*subtype_info == 'L')
8195 if (! ada_scan_number (bounds_str, n, &L, &n)
8196 && ! scan_discrim_bound (bounds_str, n, dval, &L, &n))
8198 if (bounds_str[n] == '_')
8200 else if (bounds_str[n] == '.') /* FIXME? SGI Workshop kludge. */
8206 strcpy (name_buf+prefix_len, "___L");
8207 L = get_int_var_value (name_buf, "Index bound unknown.", NULL);
8210 if (*subtype_info == 'U')
8212 if (! ada_scan_number (bounds_str, n, &U, &n)
8213 && !scan_discrim_bound (bounds_str, n, dval, &U, &n))
8218 strcpy (name_buf+prefix_len, "___U");
8219 U = get_int_var_value (name_buf, "Index bound unknown.", NULL);
8222 if (objfile == NULL)
8223 objfile = TYPE_OBJFILE (base_type);
8224 type = create_range_type (alloc_type (objfile), base_type, L, U);
8225 TYPE_NAME (type) = name;
8230 /* True iff NAME is the name of a range type. */
8232 ada_is_range_type_name (name)
8235 return (name != NULL && strstr (name, "___XD"));
8241 /* True iff TYPE is an Ada modular type. */
8243 ada_is_modular_type (type)
8246 /* FIXME: base_type should be declared in gdbtypes.h, implemented in
8248 struct type* subranged_type; /* = base_type (type);*/
8250 return (subranged_type != NULL && TYPE_CODE (type) == TYPE_CODE_RANGE
8251 && TYPE_CODE (subranged_type) != TYPE_CODE_ENUM
8252 && TYPE_UNSIGNED (subranged_type));
8255 /* Assuming ada_is_modular_type (TYPE), the modulus of TYPE. */
8260 return TYPE_HIGH_BOUND (type) + 1;
8267 /* Table mapping opcodes into strings for printing operators
8268 and precedences of the operators. */
8270 static const struct op_print ada_op_print_tab[] =
8272 {":=", BINOP_ASSIGN, PREC_ASSIGN, 1},
8273 {"or else", BINOP_LOGICAL_OR, PREC_LOGICAL_OR, 0},
8274 {"and then", BINOP_LOGICAL_AND, PREC_LOGICAL_AND, 0},
8275 {"or", BINOP_BITWISE_IOR, PREC_BITWISE_IOR, 0},
8276 {"xor", BINOP_BITWISE_XOR, PREC_BITWISE_XOR, 0},
8277 {"and", BINOP_BITWISE_AND, PREC_BITWISE_AND, 0},
8278 {"=", BINOP_EQUAL, PREC_EQUAL, 0},
8279 {"/=", BINOP_NOTEQUAL, PREC_EQUAL, 0},
8280 {"<=", BINOP_LEQ, PREC_ORDER, 0},
8281 {">=", BINOP_GEQ, PREC_ORDER, 0},
8282 {">", BINOP_GTR, PREC_ORDER, 0},
8283 {"<", BINOP_LESS, PREC_ORDER, 0},
8284 {">>", BINOP_RSH, PREC_SHIFT, 0},
8285 {"<<", BINOP_LSH, PREC_SHIFT, 0},
8286 {"+", BINOP_ADD, PREC_ADD, 0},
8287 {"-", BINOP_SUB, PREC_ADD, 0},
8288 {"&", BINOP_CONCAT, PREC_ADD, 0},
8289 {"*", BINOP_MUL, PREC_MUL, 0},
8290 {"/", BINOP_DIV, PREC_MUL, 0},
8291 {"rem", BINOP_REM, PREC_MUL, 0},
8292 {"mod", BINOP_MOD, PREC_MUL, 0},
8293 {"**", BINOP_EXP, PREC_REPEAT, 0 },
8294 {"@", BINOP_REPEAT, PREC_REPEAT, 0},
8295 {"-", UNOP_NEG, PREC_PREFIX, 0},
8296 {"+", UNOP_PLUS, PREC_PREFIX, 0},
8297 {"not ", UNOP_LOGICAL_NOT, PREC_PREFIX, 0},
8298 {"not ", UNOP_COMPLEMENT, PREC_PREFIX, 0},
8299 {"abs ", UNOP_ABS, PREC_PREFIX, 0},
8300 {".all", UNOP_IND, PREC_SUFFIX, 1}, /* FIXME: postfix .ALL */
8301 {"'access", UNOP_ADDR, PREC_SUFFIX, 1}, /* FIXME: postfix 'ACCESS */
8305 /* Assorted Types and Interfaces */
8307 struct type* builtin_type_ada_int;
8308 struct type* builtin_type_ada_short;
8309 struct type* builtin_type_ada_long;
8310 struct type* builtin_type_ada_long_long;
8311 struct type* builtin_type_ada_char;
8312 struct type* builtin_type_ada_float;
8313 struct type* builtin_type_ada_double;
8314 struct type* builtin_type_ada_long_double;
8315 struct type* builtin_type_ada_natural;
8316 struct type* builtin_type_ada_positive;
8317 struct type* builtin_type_ada_system_address;
8319 struct type ** const (ada_builtin_types[]) =
8322 &builtin_type_ada_int,
8323 &builtin_type_ada_long,
8324 &builtin_type_ada_short,
8325 &builtin_type_ada_char,
8326 &builtin_type_ada_float,
8327 &builtin_type_ada_double,
8328 &builtin_type_ada_long_long,
8329 &builtin_type_ada_long_double,
8330 &builtin_type_ada_natural,
8331 &builtin_type_ada_positive,
8333 /* The following types are carried over from C for convenience. */
8336 &builtin_type_short,
8338 &builtin_type_float,
8339 &builtin_type_double,
8340 &builtin_type_long_long,
8342 &builtin_type_signed_char,
8343 &builtin_type_unsigned_char,
8344 &builtin_type_unsigned_short,
8345 &builtin_type_unsigned_int,
8346 &builtin_type_unsigned_long,
8347 &builtin_type_unsigned_long_long,
8348 &builtin_type_long_double,
8349 &builtin_type_complex,
8350 &builtin_type_double_complex,
8354 /* Not really used, but needed in the ada_language_defn. */
8355 static void emit_char (int c, struct ui_file* stream, int quoter)
8357 ada_emit_char (c, stream, quoter, 1);
8360 const struct language_defn ada_language_defn = {
8361 "ada", /* Language name */
8364 /* FIXME: language_ada should be defined in defs.h */
8368 case_sensitive_on, /* Yes, Ada is case-insensitive, but
8369 * that's not quite what this means. */
8372 ada_evaluate_subexp,
8373 ada_printchar, /* Print a character constant */
8374 ada_printstr, /* Function to print string constant */
8375 emit_char, /* Function to print single char (not used) */
8376 ada_create_fundamental_type, /* Create fundamental type in this language */
8377 ada_print_type, /* Print a type using appropriate syntax */
8378 ada_val_print, /* Print a value using appropriate syntax */
8379 ada_value_print, /* Print a top-level value */
8380 {"", "", "", ""}, /* Binary format info */
8382 {"8#%lo#", "8#", "o", "#"}, /* Octal format info */
8383 {"%ld", "", "d", ""}, /* Decimal format info */
8384 {"16#%lx#", "16#", "x", "#"}, /* Hex format info */
8386 /* Copied from c-lang.c. */
8387 {"0%lo", "0", "o", ""}, /* Octal format info */
8388 {"%ld", "", "d", ""}, /* Decimal format info */
8389 {"0x%lx", "0x", "x", ""}, /* Hex format info */
8391 ada_op_print_tab, /* expression operators for printing */
8392 1, /* c-style arrays (FIXME?) */
8393 0, /* String lower bound (FIXME?) */
8394 &builtin_type_ada_char,
8399 _initialize_ada_language ()
8401 builtin_type_ada_int =
8402 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
8404 "integer", (struct objfile *) NULL);
8405 builtin_type_ada_long =
8406 init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT,
8408 "long_integer", (struct objfile *) NULL);
8409 builtin_type_ada_short =
8410 init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT,
8412 "short_integer", (struct objfile *) NULL);
8413 builtin_type_ada_char =
8414 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
8416 "character", (struct objfile *) NULL);
8417 builtin_type_ada_float =
8418 init_type (TYPE_CODE_FLT, TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
8420 "float", (struct objfile *) NULL);
8421 builtin_type_ada_double =
8422 init_type (TYPE_CODE_FLT, TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
8424 "long_float", (struct objfile *) NULL);
8425 builtin_type_ada_long_long =
8426 init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
8428 "long_long_integer", (struct objfile *) NULL);
8429 builtin_type_ada_long_double =
8430 init_type (TYPE_CODE_FLT, TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT,
8432 "long_long_float", (struct objfile *) NULL);
8433 builtin_type_ada_natural =
8434 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
8436 "natural", (struct objfile *) NULL);
8437 builtin_type_ada_positive =
8438 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
8440 "positive", (struct objfile *) NULL);
8443 builtin_type_ada_system_address =
8444 lookup_pointer_type (init_type (TYPE_CODE_VOID, 1, 0, "void",
8445 (struct objfile *) NULL));
8446 TYPE_NAME (builtin_type_ada_system_address) = "system__address";
8448 add_language (&ada_language_defn);
8451 (add_set_cmd ("varsize-limit", class_support, var_uinteger,
8452 (char*) &varsize_limit,
8453 "Set maximum bytes in dynamic-sized object.",
8456 varsize_limit = 65536;
8458 add_com ("begin", class_breakpoint, begin_command,
8459 "Start the debugged program, stopping at the beginning of the\n\
8460 main program. You may specify command-line arguments to give it, as for\n\
8461 the \"run\" command (q.v.).");
8465 /* Create a fundamental Ada type using default reasonable for the current
8468 Some object/debugging file formats (DWARF version 1, COFF, etc) do not
8469 define fundamental types such as "int" or "double". Others (stabs or
8470 DWARF version 2, etc) do define fundamental types. For the formats which
8471 don't provide fundamental types, gdb can create such types using this
8474 FIXME: Some compilers distinguish explicitly signed integral types
8475 (signed short, signed int, signed long) from "regular" integral types
8476 (short, int, long) in the debugging information. There is some dis-
8477 agreement as to how useful this feature is. In particular, gcc does
8478 not support this. Also, only some debugging formats allow the
8479 distinction to be passed on to a debugger. For now, we always just
8480 use "short", "int", or "long" as the type name, for both the implicit
8481 and explicitly signed types. This also makes life easier for the
8482 gdb test suite since we don't have to account for the differences
8483 in output depending upon what the compiler and debugging format
8484 support. We will probably have to re-examine the issue when gdb
8485 starts taking it's fundamental type information directly from the
8488 static struct type *
8489 ada_create_fundamental_type (objfile, typeid)
8490 struct objfile *objfile;
8493 struct type *type = NULL;
8498 /* FIXME: For now, if we are asked to produce a type not in this
8499 language, create the equivalent of a C integer type with the
8500 name "<?type?>". When all the dust settles from the type
8501 reconstruction work, this should probably become an error. */
8502 type = init_type (TYPE_CODE_INT,
8503 TARGET_INT_BIT / TARGET_CHAR_BIT,
8504 0, "<?type?>", objfile);
8505 warning ("internal error: no Ada fundamental type %d", typeid);
8508 type = init_type (TYPE_CODE_VOID,
8509 TARGET_CHAR_BIT / TARGET_CHAR_BIT,
8510 0, "void", objfile);
8513 type = init_type (TYPE_CODE_INT,
8514 TARGET_CHAR_BIT / TARGET_CHAR_BIT,
8515 0, "character", objfile);
8517 case FT_SIGNED_CHAR:
8518 type = init_type (TYPE_CODE_INT,
8519 TARGET_CHAR_BIT / TARGET_CHAR_BIT,
8520 0, "signed char", objfile);
8522 case FT_UNSIGNED_CHAR:
8523 type = init_type (TYPE_CODE_INT,
8524 TARGET_CHAR_BIT / TARGET_CHAR_BIT,
8525 TYPE_FLAG_UNSIGNED, "unsigned char", objfile);
8528 type = init_type (TYPE_CODE_INT,
8529 TARGET_SHORT_BIT / TARGET_CHAR_BIT,
8530 0, "short_integer", objfile);
8532 case FT_SIGNED_SHORT:
8533 type = init_type (TYPE_CODE_INT,
8534 TARGET_SHORT_BIT / TARGET_CHAR_BIT,
8535 0, "short_integer", objfile);
8537 case FT_UNSIGNED_SHORT:
8538 type = init_type (TYPE_CODE_INT,
8539 TARGET_SHORT_BIT / TARGET_CHAR_BIT,
8540 TYPE_FLAG_UNSIGNED, "unsigned short", objfile);
8543 type = init_type (TYPE_CODE_INT,
8544 TARGET_INT_BIT / TARGET_CHAR_BIT,
8545 0, "integer", objfile);
8547 case FT_SIGNED_INTEGER:
8548 type = init_type (TYPE_CODE_INT,
8549 TARGET_INT_BIT / TARGET_CHAR_BIT,
8550 0, "integer", objfile); /* FIXME -fnf */
8552 case FT_UNSIGNED_INTEGER:
8553 type = init_type (TYPE_CODE_INT,
8554 TARGET_INT_BIT / TARGET_CHAR_BIT,
8555 TYPE_FLAG_UNSIGNED, "unsigned int", objfile);
8558 type = init_type (TYPE_CODE_INT,
8559 TARGET_LONG_BIT / TARGET_CHAR_BIT,
8560 0, "long_integer", objfile);
8562 case FT_SIGNED_LONG:
8563 type = init_type (TYPE_CODE_INT,
8564 TARGET_LONG_BIT / TARGET_CHAR_BIT,
8565 0, "long_integer", objfile);
8567 case FT_UNSIGNED_LONG:
8568 type = init_type (TYPE_CODE_INT,
8569 TARGET_LONG_BIT / TARGET_CHAR_BIT,
8570 TYPE_FLAG_UNSIGNED, "unsigned long", objfile);
8573 type = init_type (TYPE_CODE_INT,
8574 TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
8575 0, "long_long_integer", objfile);
8577 case FT_SIGNED_LONG_LONG:
8578 type = init_type (TYPE_CODE_INT,
8579 TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
8580 0, "long_long_integer", objfile);
8582 case FT_UNSIGNED_LONG_LONG:
8583 type = init_type (TYPE_CODE_INT,
8584 TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
8585 TYPE_FLAG_UNSIGNED, "unsigned long long", objfile);
8588 type = init_type (TYPE_CODE_FLT,
8589 TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
8590 0, "float", objfile);
8592 case FT_DBL_PREC_FLOAT:
8593 type = init_type (TYPE_CODE_FLT,
8594 TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
8595 0, "long_float", objfile);
8597 case FT_EXT_PREC_FLOAT:
8598 type = init_type (TYPE_CODE_FLT,
8599 TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT,
8600 0, "long_long_float", objfile);
8606 void ada_dump_symtab (struct symtab* s)
8609 fprintf (stderr, "New symtab: [\n");
8610 fprintf (stderr, " Name: %s/%s;\n",
8611 s->dirname ? s->dirname : "?",
8612 s->filename ? s->filename : "?");
8613 fprintf (stderr, " Format: %s;\n", s->debugformat);
8614 if (s->linetable != NULL)
8616 fprintf (stderr, " Line table (section %d):\n", s->block_line_section);
8617 for (i = 0; i < s->linetable->nitems; i += 1)
8619 struct linetable_entry* e = s->linetable->item + i;
8620 fprintf (stderr, " %4ld: %8lx\n", (long) e->line, (long) e->pc);
8623 fprintf (stderr, "]\n");