aboutsummaryrefslogtreecommitdiff
path: root/gdb/compile
diff options
context:
space:
mode:
authorPierre-Marie de Rodat <derodat@adacore.com>2015-02-05 17:00:06 +0100
committerPierre-Marie de Rodat <derodat@adacore.com>2015-08-25 08:13:28 -0400
commit63e43d3aedb8b1112899c2d0ad74cbbee687e5d6 (patch)
tree9e35fea0ccd74ee5d2d27bc7fe957ec19c360dbb /gdb/compile
parent7c2bea1ad1c779b893eb9cad4c92732583ae0eb5 (diff)
downloadgdb-63e43d3aedb8b1112899c2d0ad74cbbee687e5d6.zip
gdb-63e43d3aedb8b1112899c2d0ad74cbbee687e5d6.tar.gz
gdb-63e43d3aedb8b1112899c2d0ad74cbbee687e5d6.tar.bz2
DWARF: handle non-local references in nested functions
GDB's current behavior when dealing with non-local references in the context of nested fuctions is approximative: - code using valops.c:value_of_variable read the first available stack frame that holds the corresponding variable (whereas there can be multiple candidates for this); - code directly relying on read_var_value will instead read non-local variables in frames where they are not even defined. This change adds the necessary context to symbol reads (to get the block they belong to) and to blocks (the static link property, if any) so that GDB can make the proper decisions when dealing with non-local varibale references. gdb/ChangeLog: * ada-lang.c (ada_read_var_value): Add a var_block argument and pass it to default_read_var_value. * block.c (block_static_link): New accessor. * block.h (block_static_link): Declare it. * buildsym.c (finish_block_internal): Add a static_link argument. If there is a static link, associate it to the new block. (finish_block): Add a static link argument and pass it to finish_block_internal. (end_symtab_get_static_block): Update calls to finish_block and to finish_block_internal. (end_symtab_with_blockvector): Update call to finish_block_internal. * buildsym.h: Forward-declare struct dynamic_prop. (struct context_stack): Add a static_link field. (finish_block): Add a static link argument. * c-exp.y: Remove an obsolete comment (evaluation of variables already start from the selected frame, and now they climb *up* the call stack) and propagate the block information to the produced expression. * d-exp.y: Likewise. * f-exp.y: Likewise. * go-exp.y: Likewise. * jv-exp.y: Likewise. * m2-exp.y: Likewise. * p-exp.y: Likewise. * coffread.c (coff_symtab_read): Update calls to finish_block. * dbxread.c (process_one_symbol): Likewise. * xcoffread.c (read_xcoff_symtab): Likewise. * compile/compile-c-symbols.c (convert_one_symbol): Promote the "sym" parameter to struct block_symbol, update its uses and pass its block to calls to read_var_value. (convert_symbol_sym): Update the calls to convert_one_symbol. * compile/compile-loc2c.c (do_compile_dwarf_expr_to_c): Update call to read_var_value. * dwarf2loc.c (block_op_get_frame_base): New. (dwarf2_block_frame_base_locexpr_funcs): Implement the get_frame_base method. (dwarf2_block_frame_base_loclist_funcs): Likewise. (dwarf2locexpr_baton_eval): Add a frame argument and use it instead of the selected frame in order to evaluate the expression. (dwarf2_evaluate_property): Add a frame argument. Update call to dwarf2_locexpr_baton_eval to provide a frame in available and to handle the absence of address stack. * dwarf2loc.h (dwarf2_evaluate_property): Add a frame argument. * dwarf2read.c (attr_to_dynamic_prop): Add a forward declaration. (read_func_scope): Record any available static link description. Update call to finish_block. (read_lexical_block_scope): Update call to finish_block. * findvar.c (follow_static_link): New. (get_hosting_frame): New. (default_read_var_value): Add a var_block argument. Use get_hosting_frame to handle non-local references. (read_var_value): Add a var_block argument and pass it to the LA_READ_VAR_VALUE method. * gdbtypes.c (resolve_dynamic_range): Update calls to dwarf2_evaluate_property. (resolve_dynamic_type_internal): Likewise. * guile/scm-frame.c (gdbscm_frame_read_var): Update call to read_var_value, passing it the block coming from symbol lookup. * guile/scm-symbol.c (gdbscm_symbol_value): Update call to read_var_value (TODO). * infcmd.c (finish_command_continuation): Update call to read_var_value, passing it the block coming from symbol lookup. * infrun.c (insert_exception_resume_breakpoint): Likewise. * language.h (struct language_defn): Add a var_block argument to the LA_READ_VAR_VALUE method. * objfiles.c (struct static_link_htab_entry): New. (static_link_htab_entry_hash): New. (static_link_htab_entry_eq): New. (objfile_register_static_link): New. (objfile_lookup_static_link): New. (free_objfile): Free the STATIC_LINKS hashed map if needed. * objfiles.h: Include hashtab.h. (struct objfile): Add a static_links field. (objfile_register_static_link): New. (objfile_lookup_static_link): New. * printcmd.c (print_variable_and_value): Update call to read_var_value. * python/py-finishbreakpoint.c (bpfinishpy_init): Likewise. * python/py-frame.c (frapy_read_var): Update call to read_var_value, passing it the block coming from symbol lookup. * python/py-framefilter.c (extract_sym): Add a sym_block parameter and set the pointed value to NULL (TODO). (enumerate_args): Update call to extract_sym. (enumerate_locals): Update calls to extract_sym and to read_var_value. * python/py-symbol.c (sympy_value): Update call to read_var_value (TODO). * stack.c (read_frame_local): Update call to read_var_value. (read_frame_arg): Likewise. (return_command): Likewise. * symtab.h (struct symbol_block_ops): Add a get_frame_base method. (struct symbol): Add a block field. (SYMBOL_BLOCK): New accessor. * valops.c (value_of_variable): Remove frame/block handling and pass the block argument to read_var_value, which does this job now. (value_struct_elt_for_reference): Update calls to read_var_value. (value_of_this): Pass the block found to read_var_value. * value.h (read_var_value): Add a var_block argument. (default_read_var_value): Likewise. gdb/testsuite/ChangeLog: * gdb.base/nested-subp1.exp: New file. * gdb.base/nested-subp1.c: New file. * gdb.base/nested-subp2.exp: New file. * gdb.base/nested-subp2.c: New file. * gdb.base/nested-subp3.exp: New file. * gdb.base/nested-subp3.c: New file.
Diffstat (limited to 'gdb/compile')
-rw-r--r--gdb/compile/compile-c-symbols.c74
-rw-r--r--gdb/compile/compile-loc2c.c2
2 files changed, 39 insertions, 37 deletions
diff --git a/gdb/compile/compile-c-symbols.c b/gdb/compile/compile-c-symbols.c
index 21ce655..355b063 100644
--- a/gdb/compile/compile-c-symbols.c
+++ b/gdb/compile/compile-c-symbols.c
@@ -143,26 +143,26 @@ symbol_substitution_name (struct symbol *sym)
static void
convert_one_symbol (struct compile_c_instance *context,
- struct symbol *sym,
+ struct block_symbol sym,
int is_global,
int is_local)
{
gcc_type sym_type;
- const char *filename = symbol_symtab (sym)->filename;
- unsigned short line = SYMBOL_LINE (sym);
+ const char *filename = symbol_symtab (sym.symbol)->filename;
+ unsigned short line = SYMBOL_LINE (sym.symbol);
- error_symbol_once (context, sym);
+ error_symbol_once (context, sym.symbol);
- if (SYMBOL_CLASS (sym) == LOC_LABEL)
+ if (SYMBOL_CLASS (sym.symbol) == LOC_LABEL)
sym_type = 0;
else
- sym_type = convert_type (context, SYMBOL_TYPE (sym));
+ sym_type = convert_type (context, SYMBOL_TYPE (sym.symbol));
- if (SYMBOL_DOMAIN (sym) == STRUCT_DOMAIN)
+ if (SYMBOL_DOMAIN (sym.symbol) == STRUCT_DOMAIN)
{
/* Binding a tag, so we don't need to build a decl. */
C_CTX (context)->c_ops->tagbind (C_CTX (context),
- SYMBOL_NATURAL_NAME (sym),
+ SYMBOL_NATURAL_NAME (sym.symbol),
sym_type, filename, line);
}
else
@@ -172,7 +172,7 @@ convert_one_symbol (struct compile_c_instance *context,
CORE_ADDR addr = 0;
char *symbol_name = NULL;
- switch (SYMBOL_CLASS (sym))
+ switch (SYMBOL_CLASS (sym.symbol))
{
case LOC_TYPEDEF:
kind = GCC_C_SYMBOL_TYPEDEF;
@@ -180,45 +180,46 @@ convert_one_symbol (struct compile_c_instance *context,
case LOC_LABEL:
kind = GCC_C_SYMBOL_LABEL;
- addr = SYMBOL_VALUE_ADDRESS (sym);
+ addr = SYMBOL_VALUE_ADDRESS (sym.symbol);
break;
case LOC_BLOCK:
kind = GCC_C_SYMBOL_FUNCTION;
- addr = BLOCK_START (SYMBOL_BLOCK_VALUE (sym));
- if (is_global && TYPE_GNU_IFUNC (SYMBOL_TYPE (sym)))
+ addr = BLOCK_START (SYMBOL_BLOCK_VALUE (sym.symbol));
+ if (is_global && TYPE_GNU_IFUNC (SYMBOL_TYPE (sym.symbol)))
addr = gnu_ifunc_resolve_addr (target_gdbarch (), addr);
break;
case LOC_CONST:
- if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_ENUM)
+ if (TYPE_CODE (SYMBOL_TYPE (sym.symbol)) == TYPE_CODE_ENUM)
{
/* Already handled by convert_enum. */
return;
}
- C_CTX (context)->c_ops->build_constant (C_CTX (context), sym_type,
- SYMBOL_NATURAL_NAME (sym),
- SYMBOL_VALUE (sym),
- filename, line);
+ C_CTX (context)->c_ops->build_constant
+ (C_CTX (context),
+ sym_type, SYMBOL_NATURAL_NAME (sym.symbol),
+ SYMBOL_VALUE (sym.symbol),
+ filename, line);
return;
case LOC_CONST_BYTES:
error (_("Unsupported LOC_CONST_BYTES for symbol \"%s\"."),
- SYMBOL_PRINT_NAME (sym));
+ SYMBOL_PRINT_NAME (sym.symbol));
case LOC_UNDEF:
internal_error (__FILE__, __LINE__, _("LOC_UNDEF found for \"%s\"."),
- SYMBOL_PRINT_NAME (sym));
+ SYMBOL_PRINT_NAME (sym.symbol));
case LOC_COMMON_BLOCK:
error (_("Fortran common block is unsupported for compilation "
"evaluaton of symbol \"%s\"."),
- SYMBOL_PRINT_NAME (sym));
+ SYMBOL_PRINT_NAME (sym.symbol));
case LOC_OPTIMIZED_OUT:
error (_("Symbol \"%s\" cannot be used for compilation evaluation "
"as it is optimized out."),
- SYMBOL_PRINT_NAME (sym));
+ SYMBOL_PRINT_NAME (sym.symbol));
case LOC_COMPUTED:
if (is_local)
@@ -227,7 +228,7 @@ convert_one_symbol (struct compile_c_instance *context,
warning (_("Symbol \"%s\" is thread-local and currently can only "
"be referenced from the current thread in "
"compiled code."),
- SYMBOL_PRINT_NAME (sym));
+ SYMBOL_PRINT_NAME (sym.symbol));
/* FALLTHROUGH */
case LOC_UNRESOLVED:
/* 'symbol_name' cannot be used here as that one is used only for
@@ -238,20 +239,20 @@ convert_one_symbol (struct compile_c_instance *context,
struct value *val;
struct frame_info *frame = NULL;
- if (symbol_read_needs_frame (sym))
+ if (symbol_read_needs_frame (sym.symbol))
{
frame = get_selected_frame (NULL);
if (frame == NULL)
error (_("Symbol \"%s\" cannot be used because "
"there is no selected frame"),
- SYMBOL_PRINT_NAME (sym));
+ SYMBOL_PRINT_NAME (sym.symbol));
}
- val = read_var_value (sym, frame);
+ val = read_var_value (sym.symbol, sym.block, frame);
if (VALUE_LVAL (val) != lval_memory)
error (_("Symbol \"%s\" cannot be used for compilation "
"evaluation as its address has not been found."),
- SYMBOL_PRINT_NAME (sym));
+ SYMBOL_PRINT_NAME (sym.symbol));
kind = GCC_C_SYMBOL_VARIABLE;
addr = value_address (val);
@@ -266,12 +267,12 @@ convert_one_symbol (struct compile_c_instance *context,
case LOC_LOCAL:
substitution:
kind = GCC_C_SYMBOL_VARIABLE;
- symbol_name = symbol_substitution_name (sym);
+ symbol_name = symbol_substitution_name (sym.symbol);
break;
case LOC_STATIC:
kind = GCC_C_SYMBOL_VARIABLE;
- addr = SYMBOL_VALUE_ADDRESS (sym);
+ addr = SYMBOL_VALUE_ADDRESS (sym.symbol);
break;
case LOC_FINAL_VALUE:
@@ -284,12 +285,13 @@ convert_one_symbol (struct compile_c_instance *context,
if (context->base.scope != COMPILE_I_RAW_SCOPE
|| symbol_name == NULL)
{
- decl = C_CTX (context)->c_ops->build_decl (C_CTX (context),
- SYMBOL_NATURAL_NAME (sym),
- kind,
- sym_type,
- symbol_name, addr,
- filename, line);
+ decl = C_CTX (context)->c_ops->build_decl
+ (C_CTX (context),
+ SYMBOL_NATURAL_NAME (sym.symbol),
+ kind,
+ sym_type,
+ symbol_name, addr,
+ filename, line);
C_CTX (context)->c_ops->bind (C_CTX (context), decl, is_global);
}
@@ -338,7 +340,7 @@ convert_symbol_sym (struct compile_c_instance *context, const char *identifier,
fprintf_unfiltered (gdb_stdlog,
"gcc_convert_symbol \"%s\": global symbol\n",
identifier);
- convert_one_symbol (context, global_sym.symbol, 1, 0);
+ convert_one_symbol (context, global_sym, 1, 0);
}
}
@@ -346,7 +348,7 @@ convert_symbol_sym (struct compile_c_instance *context, const char *identifier,
fprintf_unfiltered (gdb_stdlog,
"gcc_convert_symbol \"%s\": local symbol\n",
identifier);
- convert_one_symbol (context, sym.symbol, 0, is_local_symbol);
+ convert_one_symbol (context, sym, 0, is_local_symbol);
}
/* Convert a minimal symbol to its gcc form. CONTEXT is the compiler
diff --git a/gdb/compile/compile-loc2c.c b/gdb/compile/compile-loc2c.c
index b201d13..8058cbd 100644
--- a/gdb/compile/compile-loc2c.c
+++ b/gdb/compile/compile-loc2c.c
@@ -636,7 +636,7 @@ do_compile_dwarf_expr_to_c (int indent, struct ui_file *stream,
"there is no selected frame"),
SYMBOL_PRINT_NAME (sym));
- val = read_var_value (sym, frame);
+ val = read_var_value (sym, NULL, frame);
if (VALUE_LVAL (val) != lval_memory)
error (_("Symbol \"%s\" cannot be used for compilation evaluation "
"as its address has not been found."),