Replace the block_found global with explicit data-flow

As Pedro suggested on gdb-patches@ (see
https://sourceware.org/ml/gdb-patches/2015-05/msg00714.html), this
change makes symbol lookup functions return a structure that includes
both the symbol found and the block in which it was found.  This makes
it possible to get rid of the block_found global variable and thus makes
block hunting explicit.

gdb/

	* ada-exp.y (write_object_renaming): Replace struct
	ada_symbol_info with struct block_symbol.  Update field
	references accordingly.
	(block_lookup, select_possible_type_sym): Likewise.
	(find_primitive_type): Likewise.  Also update call to
	ada_lookup_symbol to extract the symbol itself.
	(write_var_or_type, write_name_assoc): Likewise.
	* ada-lang.h (struct ada_symbol_info): Remove.
	(ada_lookup_symbol_list): Replace struct ada_symbol_info with
	struct block_symbol.
	(ada_lookup_encoded_symbol, user_select_syms): Likewise.
	(ada_lookup_symbol): Return struct block_symbol instead of a
	mere symbol.
	* ada-lang.c (defns_collected): Replace struct ada_symbol_info
	with struct block_symbol.
	(resolve_subexp, ada_resolve_function, sort_choices,
	user_select_syms, is_nonfunction, add_defn_to_vec,
	num_defns_collected, defns_collected,
	symbols_are_identical_enums, remove_extra_symbols,
	remove_irrelevant_renamings, add_lookup_symbol_list_worker,
	ada_lookup_symbol_list, ada_iterate_over_symbols,
	ada_lookup_encoded_symbol, get_var_value): Likewise.
	(ada_lookup_symbol): Return a block_symbol instead of a mere
	symbol.  Replace struct ada_symbol_info with struct
	block_symbol.
	(ada_lookup_symbol_nonlocal): Likewise.
	(standard_lookup): Make block passing explicit through
	lookup_symbol_in_language.
	* ada-tasks.c (get_tcb_types_info): Update the calls to
	lookup_symbol_in_language to extract the mere symbol out of the
	returned value.
	(ada_tasks_inferior_data_sniffer): Likewise.
	* ax-gdb.c (gen_static_field): Likewise for the call to
	lookup_symbol.
	(gen_maybe_namespace_elt): Deal with struct symbol_in_block from
	lookup functions.
	(gen_expr): Likewise.
	* c-exp.y: Likewise.  Remove uses of block_found.
	(lex_one_token, classify_inner_name, c_print_token): Likewise.
	(classify_name): Likewise.  Rename the "sym" local variable to
	"bsym".
	* c-valprint.c (print_unpacked_pointer): Likewise.
	* compile/compile-c-symbols.c (convert_symbol_sym): Promote the
	"sym" parameter from struct symbol * to struct block_symbol.
	Use it to remove uses of block_found.  Deal with struct
	symbol_in_block from lookup functions.
	(gcc_convert_symbol): Likewise.  Update the call to
	convert_symbol_sym.
	* compile/compile-object-load.c (compile_object_load): Deal with
	struct symbol_in_block from lookup functions.
	* cp-namespace.c (cp_lookup_nested_symbol_1,
	cp_lookup_nested_symbol, cp_lookup_bare_symbol,
	cp_search_static_and_baseclasses,
	cp_lookup_symbol_in_namespace, cp_lookup_symbol_via_imports,
	cp_lookup_symbol_imports_or_template,
	cp_lookup_symbol_via_all_imports, cp_lookup_symbol_namespace,
	lookup_namespace_scope, cp_lookup_nonlocal,
	find_symbol_in_baseclass): Return struct symbol_in_block instead
	of mere symbols and deal with struct symbol_in_block from lookup
	functions.
	* cp-support.c (inspect_type, replace_typedefs,
	cp_lookup_rtti_type): Deal with struct symbol_in_block from
	lookup functions.
	* cp-support.h (cp_lookup_symbol_nonlocal,
	cp_lookup_symbol_from_namespace,
	cp_lookup_symbol_imports_or_template, cp_lookup_nested_symbol):
	Return struct symbol_in_block instead of mere symbols.
	* d-exp.y (d_type_from_name, d_module_from_name, push_variable,
	push_module_name):
	Deal with struct symbol_in_block from lookup functions.  Remove
	uses of block_found.
	* eval.c (evaluate_subexp_standard): Update call to
	cp_lookup_symbol_namespace.
	* f-exp.y: Deal with struct symbol_in_block from lookup
	functions.  Remove uses of block_found.
	(yylex): Likewise.
	* gdbtypes.c (lookup_typename, lookup_struct, lookup_union,
	lookup_enum, lookup_template_type, check_typedef): Deal with
	struct symbol_in_block from lookup functions.
	* guile/scm-frame.c (gdbscm_frame_read_var): Likewise.
	* guile/scm-symbol.c (gdbscm_lookup_symbol): Likewise.
	(gdbscm_lookup_global_symbol): Likewise.
	* gnu-v3-abi.c (gnuv3_get_typeid_type): Likewise.
	* go-exp.y: Likewise.  Remove uses of block_found.
	(package_name_p, classify_packaged_name, classify_name):
	Likewise.
	* infrun.c (insert_exception_resume_breakpoint): Likewise.
	* jv-exp.y (push_variable): Likewise.
	* jv-lang.c (java_lookup_class, get_java_object_type): Likewise.
	* language.c (language_bool_type): Likewise.
	* language.h (struct language_defn): Update
	la_lookup_symbol_nonlocal to return a struct symbol_in_block
	rather than a mere symbol.
	* linespec.c (find_label_symbols): Deal with struct
	symbol_in_block from lookup functions.
	* m2-exp.y: Likewise.  Remove uses of block_found.
	(yylex): Likewise.
	* mi/mi-cmd-stack.c (list_args_or_locals): Likewise.
	* objc-lang.c (lookup_struct_typedef, find_imps): Likewise.
	* p-exp.y: Likewise.  Remove uses of block_found.
	(yylex): Likewise.
	* p-valprint.c (pascal_val_print): Likewise.
	* parse.c (write_dollar_variable): Likewise.  Remove uses of
	block_found.
	* parser-defs.h (struct symtoken): Turn the SYM field into a
	struct symbol_in_block.
	* printcmd.c (address_info): Deal with struct symbol_in_block
	from lookup functions.
	* python/py-frame.c (frapy_read_var): Likewise.
	* python/py-symbol.c (gdbpy_lookup_symbol,
	gdbpy_lookup_global_symbol): Likewise.
	* skip.c (skip_function_command): Likewise.
	* solib-darwin.c (darwin_lookup_lib_symbol): Return a struct
	symbol_in_block instead of a mere symbol.
	* solib-spu.c (spu_lookup_lib_symbol): Likewise.
	* solib-svr4.c (elf_lookup_lib_symbol): Likewise.
	* solib.c (solib_global_lookup): Likewise.
	* solist.h (solib_global_lookup): Likewise.
	(struct target_so_ops): Update lookup_lib_global_symbol to
	return a struct symbol_in_block rather than a mere symbol.
	* source.c (select_source_symtab): Deal with struct
	symbol_in_block from lookup functions.
	* stack.c (print_frame_args, iterate_over_block_arg_vars):
	Likewise.
	* symfile.c (set_initial_language): Likewise.
	* symtab.c (SYMBOL_LOOKUP_FAILED): Turn into a struct
	symbol_in_block.
	(SYMBOL_LOOKUP_FAILED_P): New predicate as a macro.
	(struct symbol_cache_slot): Turn the FOUND field into a struct
	symbol_in_block.
	(block_found): Remove.
	(eq_symbol_entry): Update to deal with struct symbol_in_block in
	cache slots.
	(symbol_cache_lookup): Return a struct symbol_in_block rather
	than a mere symbol.
	(symbol_cache_mark_found): Add a BLOCK parameter to fill
	appropriately the cache slots.  Update callers.
	(symbol_cache_dump): Update cache slots handling to the type
	change.
	(lookup_symbol_in_language, lookup_symbol, lookup_language_this,
	lookup_symbol_aux, lookup_local_symbol,
	lookup_symbol_in_objfile, lookup_global_symbol_from_objfile,
	lookup_symbol_in_objfile_symtabs,
	lookup_symbol_in_objfile_from_linkage_name,
	lookup_symbol_via_quick_fns, basic_lookup_symbol_nonlocal,
	lookup_symbol_in_static_block, lookup_static_symbol,
	lookup_global_symbol):
	Return a struct symbol_in_block rather than a mere symbol.  Deal
	with struct symbol_in_block from other lookup functions.  Remove
	uses of block_found.
	(lookup_symbol_in_block): Remove uses of block_found.
	(struct global_sym_lookup_data): Turn the RESULT field into a
	struct symbol_in_block.
	(lookup_symbol_global_iterator_cb): Update references to the
	RESULT field.
	(search_symbols): Deal with struct symbol_in_block from lookup
	functions.
	* symtab.h (struct symbol_in_block): New structure.
	(block_found): Remove.
	(lookup_symbol_in_language, lookup_symbol,
	basic_lookup_symbol_nonlocal, lookup_symbol_in_static_block,
	looku_static_symbol, lookup_global_symbol,
	lookup_symbol_in_block, lookup_language_this,
	lookup_global_symbol_from_objfile): Return a struct
	symbol_in_block rather than just a mere symbol.  Update comments
	to remove mentions of block_found.
	* valops.c (find_function_in_inferior,
	value_struct_elt_for_reference, value_maybe_namespace_elt,
	value_of_this):  Deal with struct symbol_in_block from lookup
	functions.
	* value.c (value_static_field, value_fn_field): Likewise.
This commit is contained in:
Pierre-Marie de Rodat 2015-07-21 17:02:15 +02:00
parent 5efafabf7b
commit d12307c199
50 changed files with 910 additions and 697 deletions

View file

@ -868,7 +868,7 @@ write_object_renaming (struct parser_state *par_state,
{
char *name;
enum { SIMPLE_INDEX, LOWER_BOUND, UPPER_BOUND } slice_state;
struct ada_symbol_info sym_info;
struct block_symbol sym_info;
if (max_depth <= 0)
error (_("Could not find renamed symbol"));
@ -878,9 +878,9 @@ write_object_renaming (struct parser_state *par_state,
name = obstack_copy0 (&temp_parse_space, renamed_entity, renamed_entity_len);
ada_lookup_encoded_symbol (name, orig_left_context, VAR_DOMAIN, &sym_info);
if (sym_info.sym == NULL)
if (sym_info.symbol == NULL)
error (_("Could not find renamed variable: %s"), ada_decode (name));
else if (SYMBOL_CLASS (sym_info.sym) == LOC_TYPEDEF)
else if (SYMBOL_CLASS (sym_info.symbol) == LOC_TYPEDEF)
/* We have a renaming of an old-style renaming symbol. Don't
trust the block information. */
sym_info.block = orig_left_context;
@ -890,13 +890,13 @@ write_object_renaming (struct parser_state *par_state,
int inner_renamed_entity_len;
const char *inner_renaming_expr;
switch (ada_parse_renaming (sym_info.sym, &inner_renamed_entity,
switch (ada_parse_renaming (sym_info.symbol, &inner_renamed_entity,
&inner_renamed_entity_len,
&inner_renaming_expr))
{
case ADA_NOT_RENAMING:
write_var_from_sym (par_state, orig_left_context, sym_info.block,
sym_info.sym);
sym_info.symbol);
break;
case ADA_OBJECT_RENAMING:
write_object_renaming (par_state, sym_info.block,
@ -939,7 +939,7 @@ write_object_renaming (struct parser_state *par_state,
{
const char *end;
char *index_name;
struct ada_symbol_info index_sym_info;
struct block_symbol index_sym_info;
end = strchr (renaming_expr, 'X');
if (end == NULL)
@ -952,13 +952,13 @@ write_object_renaming (struct parser_state *par_state,
ada_lookup_encoded_symbol (index_name, NULL, VAR_DOMAIN,
&index_sym_info);
if (index_sym_info.sym == NULL)
if (index_sym_info.symbol == NULL)
error (_("Could not find %s"), index_name);
else if (SYMBOL_CLASS (index_sym_info.sym) == LOC_TYPEDEF)
else if (SYMBOL_CLASS (index_sym_info.symbol) == LOC_TYPEDEF)
/* Index is an old-style renaming symbol. */
index_sym_info.block = orig_left_context;
write_var_from_sym (par_state, NULL, index_sym_info.block,
index_sym_info.sym);
index_sym_info.symbol);
}
if (slice_state == SIMPLE_INDEX)
{
@ -1013,7 +1013,7 @@ static const struct block*
block_lookup (const struct block *context, const char *raw_name)
{
const char *name;
struct ada_symbol_info *syms;
struct block_symbol *syms;
int nsyms;
struct symtab *symtab;
@ -1027,14 +1027,14 @@ block_lookup (const struct block *context, const char *raw_name)
nsyms = ada_lookup_symbol_list (name, context, VAR_DOMAIN, &syms);
if (context == NULL
&& (nsyms == 0 || SYMBOL_CLASS (syms[0].sym) != LOC_BLOCK))
&& (nsyms == 0 || SYMBOL_CLASS (syms[0].symbol) != LOC_BLOCK))
symtab = lookup_symtab (name);
else
symtab = NULL;
if (symtab != NULL)
return BLOCKVECTOR_BLOCK (SYMTAB_BLOCKVECTOR (symtab), STATIC_BLOCK);
else if (nsyms == 0 || SYMBOL_CLASS (syms[0].sym) != LOC_BLOCK)
else if (nsyms == 0 || SYMBOL_CLASS (syms[0].symbol) != LOC_BLOCK)
{
if (context == NULL)
error (_("No file or function \"%s\"."), raw_name);
@ -1045,12 +1045,12 @@ block_lookup (const struct block *context, const char *raw_name)
{
if (nsyms > 1)
warning (_("Function name \"%s\" ambiguous here"), raw_name);
return SYMBOL_BLOCK_VALUE (syms[0].sym);
return SYMBOL_BLOCK_VALUE (syms[0].symbol);
}
}
static struct symbol*
select_possible_type_sym (struct ada_symbol_info *syms, int nsyms)
select_possible_type_sym (struct block_symbol *syms, int nsyms)
{
int i;
int preferred_index;
@ -1058,13 +1058,13 @@ select_possible_type_sym (struct ada_symbol_info *syms, int nsyms)
preferred_index = -1; preferred_type = NULL;
for (i = 0; i < nsyms; i += 1)
switch (SYMBOL_CLASS (syms[i].sym))
switch (SYMBOL_CLASS (syms[i].symbol))
{
case LOC_TYPEDEF:
if (ada_prefer_type (SYMBOL_TYPE (syms[i].sym), preferred_type))
if (ada_prefer_type (SYMBOL_TYPE (syms[i].symbol), preferred_type))
{
preferred_index = i;
preferred_type = SYMBOL_TYPE (syms[i].sym);
preferred_type = SYMBOL_TYPE (syms[i].symbol);
}
break;
case LOC_REGISTER:
@ -1079,7 +1079,7 @@ select_possible_type_sym (struct ada_symbol_info *syms, int nsyms)
}
if (preferred_type == NULL)
return NULL;
return syms[preferred_index].sym;
return syms[preferred_index].symbol;
}
static struct type*
@ -1101,7 +1101,7 @@ find_primitive_type (struct parser_state *par_state, char *name)
(char *) alloca (strlen (name) + sizeof ("standard__"));
strcpy (expanded_name, "standard__");
strcat (expanded_name, name);
sym = ada_lookup_symbol (expanded_name, NULL, VAR_DOMAIN, NULL);
sym = ada_lookup_symbol (expanded_name, NULL, VAR_DOMAIN, NULL).symbol;
if (sym != NULL && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
type = SYMBOL_TYPE (sym);
}
@ -1274,7 +1274,7 @@ write_var_or_type (struct parser_state *par_state,
while (tail_index > 0)
{
int nsyms;
struct ada_symbol_info *syms;
struct block_symbol *syms;
struct symbol *type_sym;
struct symbol *renaming_sym;
const char* renaming;
@ -1294,10 +1294,10 @@ write_var_or_type (struct parser_state *par_state,
if (nsyms == 1)
{
struct symbol *ren_sym =
ada_find_renaming_symbol (syms[0].sym, syms[0].block);
ada_find_renaming_symbol (syms[0].symbol, syms[0].block);
if (ren_sym != NULL)
syms[0].sym = ren_sym;
syms[0].symbol = ren_sym;
}
type_sym = select_possible_type_sym (syms, nsyms);
@ -1305,7 +1305,7 @@ write_var_or_type (struct parser_state *par_state,
if (type_sym != NULL)
renaming_sym = type_sym;
else if (nsyms == 1)
renaming_sym = syms[0].sym;
renaming_sym = syms[0].symbol;
else
renaming_sym = NULL;
@ -1367,7 +1367,7 @@ write_var_or_type (struct parser_state *par_state,
if (nsyms == 1)
{
write_var_from_sym (par_state, block, syms[0].block,
syms[0].sym);
syms[0].symbol);
write_selectors (par_state, encoded_name + tail_index);
return NULL;
}
@ -1433,13 +1433,14 @@ write_name_assoc (struct parser_state *par_state, struct stoken name)
{
if (strchr (name.ptr, '.') == NULL)
{
struct ada_symbol_info *syms;
struct block_symbol *syms;
int nsyms = ada_lookup_symbol_list (name.ptr, expression_context_block,
VAR_DOMAIN, &syms);
if (nsyms != 1 || SYMBOL_CLASS (syms[0].sym) == LOC_TYPEDEF)
if (nsyms != 1 || SYMBOL_CLASS (syms[0].symbol) == LOC_TYPEDEF)
write_exp_op_with_string (par_state, OP_NAME, name);
else
write_var_from_sym (par_state, NULL, syms[0].block, syms[0].sym);
write_var_from_sym (par_state, NULL, syms[0].block, syms[0].symbol);
}
else
if (write_var_or_type (par_state, NULL, name) != NULL)