#include "stack.h"
#include "gdb_vecs.h"
#include "typeprint.h"
+#include "namespace.h"
#include "psymtab.h"
#include "value.h"
const struct block *, const char *,
domain_enum, struct objfile *, int);
+static void ada_add_all_symbols (struct obstack *, const struct block *,
+ const char *, domain_enum, int, int *);
+
static int is_nonfunction (struct block_symbol *, int);
static void add_defn_to_vec (struct obstack *, struct symbol *,
static struct symbol *standard_lookup (const char *, const struct block *,
domain_enum);
-static struct value *ada_search_struct_field (char *, struct value *, int,
+static struct value *ada_search_struct_field (const char *, struct value *, int,
struct type *);
static struct value *ada_value_primitive_field (struct value *, int, int,
/* Assuming ARR is a pointer to a GDB array, the value of the element
of *ARR at the ARITY indices given in IND.
- Does not read the entire array into memory. */
+ Does not read the entire array into memory.
+
+ Note: Unlike what one would expect, this function is used instead of
+ ada_value_subscript for basically all non-packed array types. The reason
+ for this is that a side effect of doing our own pointer arithmetics instead
+ of relying on value_subscript is that there is no implicit typedef peeling.
+ This is important for arrays of array accesses, where it allows us to
+ preserve the fact that the array's element is an array access, where the
+ access part os encoded in a typedef layer. */
static struct value *
ada_value_ptr_subscript (struct value *arr, int arity, struct value **ind)
{
int k;
+ struct value *array_ind = ada_value_ind (arr);
struct type *type
- = check_typedef (value_enclosing_type (ada_value_ind (arr)));
+ = check_typedef (value_enclosing_type (array_ind));
+
+ if (TYPE_CODE (type) == TYPE_CODE_ARRAY
+ && TYPE_FIELD_BITSIZE (type, 0) > 0)
+ return value_subscript_packed (array_ind, arity, ind);
for (k = 0; k < arity; k += 1)
{
error (_("Unexpected operator during name resolution"));
}
- argvec = (struct value * *) alloca (sizeof (struct value *) * (nargs + 1));
+ argvec = XALLOCAVEC (struct value *, nargs + 1);
for (i = 0; i < nargs; i += 1)
argvec[i] = resolve_subexp (expp, pos, 1, NULL);
argvec[i] = NULL;
}
}
+ /* If we got multiple matches, ask the user which one to use. Don't do this
+ interactive thing during completion, though, as the purpose of the
+ completion is providing a list of all possible matches. Prompting the
+ user to filter it down would be completely unexpected in this case. */
if (m == 0)
return -1;
- else if (m > 1)
+ else if (m > 1 && !parse_completion)
{
printf_filtered (_("Multiple matches for %s\n"), name);
user_select_syms (syms, m, 1);
user_select_syms (struct block_symbol *syms, int nsyms, int max_results)
{
int i;
- int *chosen = (int *) alloca (sizeof (int) * nsyms);
+ int *chosen = XALLOCAVEC (int , nsyms);
int n_chosen;
int first_choice = (max_results == 1) ? 1 : 2;
const char *select_mode = multiple_symbols_select_mode ();
and then backtrack until we find the first "__". */
const char *name = type_name_no_tag (renaming_type);
- char *suffix = strstr (name, "___XR");
- char *last;
+ const char *suffix = strstr (name, "___XR");
+ const char *last;
int scope_len;
char *scope;
int found_sym;
};
-/* A callback for add_matching_symbols that adds SYM, found in BLOCK,
+/* A callback for add_nonlocal_symbols that adds SYM, found in BLOCK,
to a list of symbols. DATA0 is a pointer to a struct match_data *
containing the obstack that collects the symbol list, the file that SYM
must come from, a flag indicating whether a non-argument symbol has
return 0;
}
+/* Helper for add_nonlocal_symbols. Find symbols in DOMAIN which are targetted
+ by renamings matching NAME in BLOCK. Add these symbols to OBSTACKP. If
+ WILD_MATCH_P is nonzero, perform the naming matching in "wild" mode (see
+ function "wild_match" for more information). Return whether we found such
+ symbols. */
+
+static int
+ada_add_block_renamings (struct obstack *obstackp,
+ const struct block *block,
+ const char *name,
+ domain_enum domain,
+ int wild_match_p)
+{
+ struct using_direct *renaming;
+ int defns_mark = num_defns_collected (obstackp);
+
+ for (renaming = block_using (block);
+ renaming != NULL;
+ renaming = renaming->next)
+ {
+ const char *r_name;
+ int name_match;
+
+ /* Avoid infinite recursions: skip this renaming if we are actually
+ already traversing it.
+
+ Currently, symbol lookup in Ada don't use the namespace machinery from
+ C++/Fortran support: skip namespace imports that use them. */
+ if (renaming->searched
+ || (renaming->import_src != NULL
+ && renaming->import_src[0] != '\0')
+ || (renaming->import_dest != NULL
+ && renaming->import_dest[0] != '\0'))
+ continue;
+ renaming->searched = 1;
+
+ /* TODO: here, we perform another name-based symbol lookup, which can
+ pull its own multiple overloads. In theory, we should be able to do
+ better in this case since, in DWARF, DW_AT_import is a DIE reference,
+ not a simple name. But in order to do this, we would need to enhance
+ the DWARF reader to associate a symbol to this renaming, instead of a
+ name. So, for now, we do something simpler: re-use the C++/Fortran
+ namespace machinery. */
+ r_name = (renaming->alias != NULL
+ ? renaming->alias
+ : renaming->declaration);
+ name_match
+ = wild_match_p ? wild_match (r_name, name) : strcmp (r_name, name);
+ if (name_match == 0)
+ ada_add_all_symbols (obstackp, block, renaming->declaration, domain,
+ 1, NULL);
+ renaming->searched = 0;
+ }
+ return num_defns_collected (obstackp) != defns_mark;
+}
+
/* Implements compare_names, but only applying the comparision using
the given CASING. */
int is_wild_match)
{
struct objfile *objfile;
+ struct compunit_symtab *cu;
struct match_data data;
memset (&data, 0, sizeof data);
objfile->sf->qf->map_matching_symbols (objfile, name, domain, global,
aux_add_nonlocal_symbols, &data,
full_match, compare_names);
+
+ ALL_OBJFILE_COMPUNITS (objfile, cu)
+ {
+ const struct block *global_block
+ = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cu), GLOBAL_BLOCK);
+
+ if (ada_add_block_renamings (obstackp, global_block , name, domain,
+ is_wild_match))
+ data.found_sym = 1;
+ }
}
if (num_defns_collected (obstackp) == 0 && global && !is_wild_match)
}
}
-/* Find symbols in DOMAIN matching NAME0, in BLOCK0 and, if full_search is
+/* Find symbols in DOMAIN matching NAME, in BLOCK and, if FULL_SEARCH is
non-zero, enclosing scope and in global scopes, returning the number of
- matches.
- Sets *RESULTS to point to a vector of (SYM,BLOCK) tuples,
- indicating the symbols found and the blocks and symbol tables (if
- any) in which they were found. This vector is transient---good only to
- the next call of ada_lookup_symbol_list.
+ matches. Add these to OBSTACKP.
- When full_search is non-zero, any non-function/non-enumeral
- symbol match within the nest of blocks whose innermost member is BLOCK0,
+ When FULL_SEARCH is non-zero, any non-function/non-enumeral
+ symbol match within the nest of blocks whose innermost member is BLOCK,
is the one match returned (no other matches in that or
enclosing blocks is returned). If there are any matches in or
- surrounding BLOCK0, then these alone are returned.
+ surrounding BLOCK, then these alone are returned.
Names prefixed with "standard__" are handled specially: "standard__"
- is first stripped off, and only static and global symbols are searched. */
+ is first stripped off, and only static and global symbols are searched.
-static int
-ada_lookup_symbol_list_worker (const char *name0, const struct block *block0,
- domain_enum domain,
- struct block_symbol **results,
- int full_search)
+ If MADE_GLOBAL_LOOKUP_P is non-null, set it before return to whether we had
+ to lookup global symbols. */
+
+static void
+ada_add_all_symbols (struct obstack *obstackp,
+ const struct block *block,
+ const char *name,
+ domain_enum domain,
+ int full_search,
+ int *made_global_lookup_p)
{
struct symbol *sym;
- const struct block *block;
- const char *name;
- const int wild_match_p = should_use_wild_match (name0);
- int syms_from_global_search = 0;
- int ndefns;
-
- obstack_free (&symbol_list_obstack, NULL);
- obstack_init (&symbol_list_obstack);
-
- /* Search specified block and its superiors. */
+ const int wild_match_p = should_use_wild_match (name);
- name = name0;
- block = block0;
+ if (made_global_lookup_p)
+ *made_global_lookup_p = 0;
/* Special case: If the user specifies a symbol name inside package
Standard, do a non-wild matching of the symbol name without
using, for instance, Standard.Constraint_Error when Constraint_Error
is ambiguous (due to the user defining its own Constraint_Error
entity inside its program). */
- if (startswith (name0, "standard__"))
+ if (startswith (name, "standard__"))
{
block = NULL;
- name = name0 + sizeof ("standard__") - 1;
+ name = name + sizeof ("standard__") - 1;
}
/* Check the non-global symbols. If we have ANY match, then we're done. */
if (block != NULL)
{
if (full_search)
- {
- ada_add_local_symbols (&symbol_list_obstack, name, block,
- domain, wild_match_p);
- }
+ ada_add_local_symbols (obstackp, name, block, domain, wild_match_p);
else
{
/* In the !full_search case we're are being called by
ada_iterate_over_symbols, and we don't want to search
superblocks. */
- ada_add_block_symbols (&symbol_list_obstack, block, name,
- domain, NULL, wild_match_p);
+ ada_add_block_symbols (obstackp, block, name, domain, NULL,
+ wild_match_p);
}
- if (num_defns_collected (&symbol_list_obstack) > 0 || !full_search)
- goto done;
+ if (num_defns_collected (obstackp) > 0 || !full_search)
+ return;
}
/* No non-global symbols found. Check our cache to see if we have
already performed this search before. If we have, then return
the same result. */
- if (lookup_cached_symbol (name0, domain, &sym, &block))
+ if (lookup_cached_symbol (name, domain, &sym, &block))
{
if (sym != NULL)
- add_defn_to_vec (&symbol_list_obstack, sym, block);
- goto done;
+ add_defn_to_vec (obstackp, sym, block);
+ return;
}
- syms_from_global_search = 1;
+ if (made_global_lookup_p)
+ *made_global_lookup_p = 1;
/* Search symbols from all global blocks. */
- add_nonlocal_symbols (&symbol_list_obstack, name, domain, 1,
- wild_match_p);
+ add_nonlocal_symbols (obstackp, name, domain, 1, wild_match_p);
/* Now add symbols from all per-file blocks if we've gotten no hits
(not strictly correct, but perhaps better than an error). */
- if (num_defns_collected (&symbol_list_obstack) == 0)
- add_nonlocal_symbols (&symbol_list_obstack, name, domain, 0,
- wild_match_p);
+ if (num_defns_collected (obstackp) == 0)
+ add_nonlocal_symbols (obstackp, name, domain, 0, wild_match_p);
+}
+
+/* Find symbols in DOMAIN matching NAME, in BLOCK and, if full_search is
+ non-zero, enclosing scope and in global scopes, returning the number of
+ matches.
+ Sets *RESULTS to point to a vector of (SYM,BLOCK) tuples,
+ indicating the symbols found and the blocks and symbol tables (if
+ any) in which they were found. This vector is transient---good only to
+ the next call of ada_lookup_symbol_list.
+
+ When full_search is non-zero, any non-function/non-enumeral
+ symbol match within the nest of blocks whose innermost member is BLOCK,
+ is the one match returned (no other matches in that or
+ enclosing blocks is returned). If there are any matches in or
+ surrounding BLOCK, then these alone are returned.
+
+ Names prefixed with "standard__" are handled specially: "standard__"
+ is first stripped off, and only static and global symbols are searched. */
+
+static int
+ada_lookup_symbol_list_worker (const char *name, const struct block *block,
+ domain_enum domain,
+ struct block_symbol **results,
+ int full_search)
+{
+ const int wild_match_p = should_use_wild_match (name);
+ int syms_from_global_search;
+ int ndefns;
+
+ obstack_free (&symbol_list_obstack, NULL);
+ obstack_init (&symbol_list_obstack);
+ ada_add_all_symbols (&symbol_list_obstack, block, name, domain,
+ full_search, &syms_from_global_search);
-done:
ndefns = num_defns_collected (&symbol_list_obstack);
*results = defns_collected (&symbol_list_obstack, 1);
ndefns = remove_extra_symbols (*results, ndefns);
if (ndefns == 0 && full_search && syms_from_global_search)
- cache_symbol (name0, domain, NULL, NULL);
+ cache_symbol (name, domain, NULL, NULL);
if (ndefns == 1 && full_search && syms_from_global_search)
- cache_symbol (name0, domain, (*results)[0].symbol, (*results)[0].block);
-
- ndefns = remove_irrelevant_renamings (*results, ndefns, block0);
+ cache_symbol (name, domain, (*results)[0].symbol, (*results)[0].block);
+ ndefns = remove_irrelevant_renamings (*results, ndefns, block);
return ndefns;
}
}
}
+ /* Handle renamings. */
+
+ if (ada_add_block_renamings (obstackp, block, name, domain, wild))
+ found_sym = 1;
+
if (!found_sym && arg_sym != NULL)
{
add_defn_to_vec (obstackp,
Searches recursively through wrapper fields (e.g., '_parent'). */
static struct value *
-ada_search_struct_field (char *name, struct value *arg, int offset,
+ada_search_struct_field (const char *name, struct value *arg, int offset,
struct type *type)
{
int i;
struct type *encoding_type)
{
struct type *fixed_range_type;
- char *bounds_str;
+ const char *bounds_str;
int n;
LONGEST lo, hi;
num_specs = num_component_specs (exp, *pos - 3);
max_indices = 4 * num_specs + 4;
- indices = alloca (max_indices * sizeof (indices[0]));
+ indices = XALLOCAVEC (LONGEST, max_indices);
indices[0] = indices[1] = low_index - 1;
indices[2] = indices[3] = high_index + 1;
num_indices = 4;
/* Allocate arg vector, including space for the function to be
called in argvec[0] and a terminating NULL. */
nargs = longest_to_int (exp->elts[pc + 1].longconst);
- argvec =
- (struct value **) alloca (sizeof (struct value *) * (nargs + 2));
+ argvec = XALLOCAVEC (struct value *, nargs + 2);
if (exp->elts[*pos].opcode == OP_VAR_VALUE
&& SYMBOL_DOMAIN (exp->elts[pc + 5].symbol) == UNDEF_DOMAIN)
not alter *PX and *PNEW_K if unsuccessful. */
static int
-scan_discrim_bound (char *str, int k, struct value *dval, LONGEST * px,
+scan_discrim_bound (const char *str, int k, struct value *dval, LONGEST * px,
int *pnew_k)
{
static char *bound_buffer = NULL;
static size_t bound_buffer_len = 0;
- char *bound;
- char *pend;
+ const char *pstart, *pend, *bound;
struct value *bound_val;
if (dval == NULL || str == NULL || str[k] == '\0')
return 0;
- pend = strstr (str + k, "__");
+ pstart = str + k;
+ pend = strstr (pstart, "__");
if (pend == NULL)
{
- bound = str + k;
+ bound = pstart;
k += strlen (bound);
}
else
{
- GROW_VECT (bound_buffer, bound_buffer_len, pend - (str + k) + 1);
+ int len = pend - pstart;
+
+ /* Strip __ and beyond. */
+ GROW_VECT (bound_buffer, bound_buffer_len, len + 1);
+ strncpy (bound_buffer, pstart, len);
+ bound_buffer[len] = '\0';
+
bound = bound_buffer;
- strncpy (bound_buffer, str + k, pend - (str + k));
- bound[pend - (str + k)] = '\0';
k = pend - str;
}
{
const char *name;
struct type *base_type;
- char *subtype_info;
+ const char *subtype_info;
gdb_assert (raw_type != NULL);
gdb_assert (TYPE_NAME (raw_type) != NULL);
int prefix_len = subtype_info - name;
LONGEST L, U;
struct type *type;
- char *bounds_str;
+ const char *bounds_str;
int n;
GROW_VECT (name_buf, name_len, prefix_len + 5);
0, "short_integer");
lai->string_char_type
= lai->primitive_type_vector [ada_primitive_type_char]
- = arch_integer_type (gdbarch, TARGET_CHAR_BIT, 0, "character");
+ = arch_character_type (gdbarch, TARGET_CHAR_BIT, 0, "character");
lai->primitive_type_vector [ada_primitive_type_float]
= arch_float_type (gdbarch, gdbarch_float_bit (gdbarch),
"float", NULL);
/* Implement the "la_read_var_value" language_defn method for Ada. */
static struct value *
-ada_read_var_value (struct symbol *var, struct frame_info *frame)
+ada_read_var_value (struct symbol *var, const struct block *var_block,
+ struct frame_info *frame)
{
const struct block *frame_block = NULL;
struct symbol *renaming_sym = NULL;
/* This is a typical case where we expect the default_read_var_value
function to work. */
- return default_read_var_value (var, frame);
+ return default_read_var_value (var, var_block, frame);
}
const struct language_defn ada_language_defn = {