diff options
author | Pierre-Marie de Rodat <derodat@adacore.com> | 2015-07-21 17:02:15 +0200 |
---|---|---|
committer | Pierre-Marie de Rodat <derodat@adacore.com> | 2015-08-01 10:55:44 +0200 |
commit | d12307c199dfdb9cad1ea79d2626224e705089a3 (patch) | |
tree | 2570d5d3e984c98be045a33d6ec10ced866ee0bd /gdb/c-exp.y | |
parent | 5efafabf7be800069e02f84589c9462e99079c4d (diff) | |
download | gdb-d12307c199dfdb9cad1ea79d2626224e705089a3.zip gdb-d12307c199dfdb9cad1ea79d2626224e705089a3.tar.gz gdb-d12307c199dfdb9cad1ea79d2626224e705089a3.tar.bz2 |
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.
Diffstat (limited to 'gdb/c-exp.y')
-rw-r--r-- | gdb/c-exp.y | 105 |
1 files changed, 55 insertions, 50 deletions
diff --git a/gdb/c-exp.y b/gdb/c-exp.y index 3ea544d..59cecb5 100644 --- a/gdb/c-exp.y +++ b/gdb/c-exp.y @@ -923,8 +923,8 @@ exp : FALSEKEYWORD block : BLOCKNAME { - if ($1.sym) - $$ = SYMBOL_BLOCK_VALUE ($1.sym); + if ($1.sym.symbol) + $$ = SYMBOL_BLOCK_VALUE ($1.sym.symbol); else error (_("No file or function \"%s\"."), copy_name ($1.stoken)); @@ -938,7 +938,8 @@ block : BLOCKNAME block : block COLONCOLON name { struct symbol *tem = lookup_symbol (copy_name ($3), $1, - VAR_DOMAIN, NULL); + VAR_DOMAIN, NULL).symbol; + if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK) error (_("No function \"%s\" in specified context."), copy_name ($3)); @@ -946,7 +947,7 @@ block : block COLONCOLON name ; variable: name_not_typename ENTRY - { struct symbol *sym = $1.sym; + { struct symbol *sym = $1.sym.symbol; if (sym == NULL || !SYMBOL_IS_ARGUMENT (sym) || !symbol_read_needs_frame (sym)) @@ -961,24 +962,24 @@ variable: name_not_typename ENTRY ; variable: block COLONCOLON name - { struct symbol *sym; - sym = lookup_symbol (copy_name ($3), $1, - VAR_DOMAIN, NULL); - if (sym == 0) + { struct block_symbol sym + = lookup_symbol (copy_name ($3), $1, + VAR_DOMAIN, NULL); + + if (sym.symbol == 0) error (_("No symbol \"%s\" in specified context."), copy_name ($3)); - if (symbol_read_needs_frame (sym)) + if (symbol_read_needs_frame (sym.symbol)) { if (innermost_block == 0 - || contained_in (block_found, + || contained_in (sym.block, innermost_block)) - innermost_block = block_found; + innermost_block = sym.block; } write_exp_elt_opcode (pstate, OP_VAR_VALUE); - /* block_found is set by lookup_symbol. */ - write_exp_elt_block (pstate, block_found); - write_exp_elt_sym (pstate, sym); + write_exp_elt_block (pstate, sym.block); + write_exp_elt_sym (pstate, sym.symbol); write_exp_elt_opcode (pstate, OP_VAR_VALUE); } ; @@ -1035,9 +1036,9 @@ variable: qualified_name struct symbol *sym; struct bound_minimal_symbol msymbol; - sym = - lookup_symbol (name, (const struct block *) NULL, - VAR_DOMAIN, NULL); + sym + = lookup_symbol (name, (const struct block *) NULL, + VAR_DOMAIN, NULL).symbol; if (sym) { write_exp_elt_opcode (pstate, OP_VAR_VALUE); @@ -1058,16 +1059,16 @@ variable: qualified_name ; variable: name_not_typename - { struct symbol *sym = $1.sym; + { struct block_symbol sym = $1.sym; - if (sym) + if (sym.symbol) { - if (symbol_read_needs_frame (sym)) + if (symbol_read_needs_frame (sym.symbol)) { if (innermost_block == 0 - || contained_in (block_found, + || contained_in (sym.block, innermost_block)) - innermost_block = block_found; + innermost_block = sym.block; } write_exp_elt_opcode (pstate, OP_VAR_VALUE); @@ -1075,7 +1076,7 @@ variable: name_not_typename another more inner frame which happens to be in the same block. */ write_exp_elt_block (pstate, NULL); - write_exp_elt_sym (pstate, sym); + write_exp_elt_sym (pstate, sym.symbol); write_exp_elt_opcode (pstate, OP_VAR_VALUE); } else if ($1.is_a_field_of_this) @@ -1084,9 +1085,9 @@ variable: name_not_typename not inadvertently convert from a method call to data ref. */ if (innermost_block == 0 - || contained_in (block_found, + || contained_in (sym.block, innermost_block)) - innermost_block = block_found; + innermost_block = sym.block; write_exp_elt_opcode (pstate, OP_THIS); write_exp_elt_opcode (pstate, OP_THIS); write_exp_elt_opcode (pstate, STRUCTOP_PTR); @@ -2817,7 +2818,7 @@ lex_one_token (struct parser_state *par_state, int *is_quoted_name) VAR_DOMAIN, (parse_language (par_state)->la_language == language_cplus ? &is_a_field_of_this - : NULL)) + : NULL)).symbol != NULL) { /* The keyword is shadowed. */ @@ -2838,7 +2839,8 @@ lex_one_token (struct parser_state *par_state, int *is_quoted_name) saw_name_at_eof = 1; yylval.ssym.stoken = yylval.sval; - yylval.ssym.sym = NULL; + yylval.ssym.sym.symbol = NULL; + yylval.ssym.sym.block = NULL; yylval.ssym.is_a_field_of_this = 0; return NAME; } @@ -2873,7 +2875,7 @@ static int classify_name (struct parser_state *par_state, const struct block *block, int is_quoted_name) { - struct symbol *sym; + struct block_symbol bsym; char *copy; struct field_of_this_result is_a_field_of_this; @@ -2883,17 +2885,17 @@ classify_name (struct parser_state *par_state, const struct block *block, we can refer to it unconditionally below. */ memset (&is_a_field_of_this, 0, sizeof (is_a_field_of_this)); - sym = lookup_symbol (copy, block, VAR_DOMAIN, - parse_language (par_state)->la_name_of_this - ? &is_a_field_of_this : NULL); + bsym = lookup_symbol (copy, block, VAR_DOMAIN, + parse_language (par_state)->la_name_of_this + ? &is_a_field_of_this : NULL); - if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK) + if (bsym.symbol && SYMBOL_CLASS (bsym.symbol) == LOC_BLOCK) { - yylval.ssym.sym = sym; + yylval.ssym.sym = bsym; yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL; return BLOCKNAME; } - else if (!sym) + else if (!bsym.symbol) { /* If we found a field of 'this', we might have erroneously found a constructor where we wanted a type name. Handle this @@ -2906,11 +2908,11 @@ classify_name (struct parser_state *par_state, const struct block *block, { struct field_of_this_result inner_is_a_field_of_this; - sym = lookup_symbol (copy, block, STRUCT_DOMAIN, - &inner_is_a_field_of_this); - if (sym != NULL) + bsym = lookup_symbol (copy, block, STRUCT_DOMAIN, + &inner_is_a_field_of_this); + if (bsym.symbol != NULL) { - yylval.tsym.type = SYMBOL_TYPE (sym); + yylval.tsym.type = SYMBOL_TYPE (bsym.symbol); return TYPENAME; } } @@ -2934,18 +2936,20 @@ classify_name (struct parser_state *par_state, const struct block *block, } } - if (sym && SYMBOL_CLASS (sym) == LOC_TYPEDEF) + if (bsym.symbol && SYMBOL_CLASS (bsym.symbol) == LOC_TYPEDEF) { - yylval.tsym.type = SYMBOL_TYPE (sym); + yylval.tsym.type = SYMBOL_TYPE (bsym.symbol); return TYPENAME; } /* See if it's an ObjC classname. */ - if (parse_language (par_state)->la_language == language_objc && !sym) + if (parse_language (par_state)->la_language == language_objc && !bsym.symbol) { CORE_ADDR Class = lookup_objc_class (parse_gdbarch (par_state), copy); if (Class) { + struct symbol *sym; + yylval.theclass.theclass = Class; sym = lookup_struct_typedef (copy, expression_context_block, 1); if (sym) @@ -2957,26 +2961,27 @@ classify_name (struct parser_state *par_state, const struct block *block, /* Input names that aren't symbols but ARE valid hex numbers, when the input radix permits them, can be names or numbers depending on the parse. Note we support radixes > 16 here. */ - if (!sym + if (!bsym.symbol && ((copy[0] >= 'a' && copy[0] < 'a' + input_radix - 10) || (copy[0] >= 'A' && copy[0] < 'A' + input_radix - 10))) { YYSTYPE newlval; /* Its value is ignored. */ int hextype = parse_number (par_state, copy, yylval.sval.length, 0, &newlval); + if (hextype == INT) { - yylval.ssym.sym = sym; + yylval.ssym.sym = bsym; yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL; return NAME_OR_INT; } } /* Any other kind of symbol */ - yylval.ssym.sym = sym; + yylval.ssym.sym = bsym; yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL; - if (sym == NULL + if (bsym.symbol == NULL && parse_language (par_state)->la_language == language_cplus && is_a_field_of_this.type == NULL && lookup_minimal_symbol (copy, NULL, NULL).minsym == NULL) @@ -3010,7 +3015,7 @@ classify_inner_name (struct parser_state *par_state, /* If no symbol was found, search for a matching base class named COPY. This will allow users to enter qualified names of class members relative to the `this' pointer. */ - if (yylval.ssym.sym == NULL) + if (yylval.ssym.sym.symbol == NULL) { struct type *base_type = cp_find_type_baseclass_by_name (type, copy); @@ -3023,7 +3028,7 @@ classify_inner_name (struct parser_state *par_state, return ERROR; } - switch (SYMBOL_CLASS (yylval.ssym.sym)) + switch (SYMBOL_CLASS (yylval.ssym.sym.symbol)) { case LOC_BLOCK: case LOC_LABEL: @@ -3042,7 +3047,7 @@ classify_inner_name (struct parser_state *par_state, return ERROR; case LOC_TYPEDEF: - yylval.tsym.type = SYMBOL_TYPE (yylval.ssym.sym); + yylval.tsym.type = SYMBOL_TYPE (yylval.ssym.sym.symbol); return TYPENAME; default: @@ -3302,8 +3307,8 @@ c_print_token (FILE *file, int type, YYSTYPE value) case BLOCKNAME: fprintf (file, "ssym<name=%s, sym=%s, field_of_this=%d>", copy_name (value.ssym.stoken), - (value.ssym.sym == NULL - ? "(null)" : SYMBOL_PRINT_NAME (value.ssym.sym)), + (value.ssym.sym.symbol == NULL + ? "(null)" : SYMBOL_PRINT_NAME (value.ssym.sym.symbol)), value.ssym.is_a_field_of_this); break; |