aboutsummaryrefslogtreecommitdiff
path: root/gdb/dwarf2loc.c
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/dwarf2loc.c
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/dwarf2loc.c')
-rw-r--r--gdb/dwarf2loc.c57
1 files changed, 49 insertions, 8 deletions
diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c
index d8e432e..efe4357 100644
--- a/gdb/dwarf2loc.c
+++ b/gdb/dwarf2loc.c
@@ -381,12 +381,47 @@ locexpr_find_frame_base_location (struct symbol *framefunc, CORE_ADDR pc,
*start = symbaton->data;
}
+/* Implement the struct symbol_block_ops::get_frame_base method. */
+
+static CORE_ADDR
+block_op_get_frame_base (struct symbol *framefunc, struct frame_info *frame)
+{
+ struct gdbarch *gdbarch;
+ struct type *type;
+ struct dwarf2_locexpr_baton *dlbaton;
+ const gdb_byte *start;
+ size_t length;
+ struct value *result;
+
+ /* If this method is called, then FRAMEFUNC is supposed to be a DWARF block.
+ Thus, it's supposed to provide the find_frame_base_location method as
+ well. */
+ gdb_assert (SYMBOL_BLOCK_OPS (framefunc)->find_frame_base_location != NULL);
+
+ gdbarch = get_frame_arch (frame);
+ type = builtin_type (gdbarch)->builtin_data_ptr;
+ dlbaton = SYMBOL_LOCATION_BATON (framefunc);
+
+ SYMBOL_BLOCK_OPS (framefunc)->find_frame_base_location
+ (framefunc, get_frame_pc (frame), &start, &length);
+ result = dwarf2_evaluate_loc_desc (type, frame, start, length,
+ dlbaton->per_cu);
+
+ /* The DW_AT_frame_base attribute contains a location description which
+ computes the base address itself. However, the call to
+ dwarf2_evaluate_loc_desc returns a value representing a variable at
+ that address. The frame base address is thus this variable's
+ address. */
+ return value_address (result);
+}
+
/* Vector for inferior functions as represented by LOC_BLOCK, if the inferior
function uses DWARF expression for its DW_AT_frame_base. */
const struct symbol_block_ops dwarf2_block_frame_base_locexpr_funcs =
{
- locexpr_find_frame_base_location
+ locexpr_find_frame_base_location,
+ block_op_get_frame_base
};
/* Implement find_frame_base_location method for LOC_BLOCK functions using
@@ -406,7 +441,8 @@ loclist_find_frame_base_location (struct symbol *framefunc, CORE_ADDR pc,
const struct symbol_block_ops dwarf2_block_frame_base_loclist_funcs =
{
- loclist_find_frame_base_location
+ loclist_find_frame_base_location,
+ block_op_get_frame_base
};
/* See dwarf2loc.h. */
@@ -2396,13 +2432,14 @@ dwarf2_evaluate_loc_desc (struct type *type, struct frame_info *frame,
}
/* Evaluates a dwarf expression and stores the result in VAL, expecting
- that the dwarf expression only produces a single CORE_ADDR. ADDR is a
- context (location of a variable) and might be needed to evaluate the
- location expression.
+ that the dwarf expression only produces a single CORE_ADDR. FRAME is the
+ frame in which the expression is evaluated. ADDR is a context (location of
+ a variable) and might be needed to evaluate the location expression.
Returns 1 on success, 0 otherwise. */
static int
dwarf2_locexpr_baton_eval (const struct dwarf2_locexpr_baton *dlbaton,
+ struct frame_info *frame,
CORE_ADDR addr,
CORE_ADDR *valp)
{
@@ -2417,7 +2454,7 @@ dwarf2_locexpr_baton_eval (const struct dwarf2_locexpr_baton *dlbaton,
ctx = new_dwarf_expr_context ();
cleanup = make_cleanup_free_dwarf_expr_context (ctx);
- baton.frame = get_selected_frame (NULL);
+ baton.frame = frame;
baton.per_cu = dlbaton->per_cu;
baton.obj_address = addr;
@@ -2461,19 +2498,24 @@ dwarf2_locexpr_baton_eval (const struct dwarf2_locexpr_baton *dlbaton,
int
dwarf2_evaluate_property (const struct dynamic_prop *prop,
+ struct frame_info *frame,
struct property_addr_info *addr_stack,
CORE_ADDR *value)
{
if (prop == NULL)
return 0;
+ if (frame == NULL && has_stack_frames ())
+ frame = get_selected_frame (NULL);
+
switch (prop->kind)
{
case PROP_LOCEXPR:
{
const struct dwarf2_property_baton *baton = prop->data.baton;
- if (dwarf2_locexpr_baton_eval (&baton->locexpr, addr_stack->addr,
+ if (dwarf2_locexpr_baton_eval (&baton->locexpr, frame,
+ addr_stack ? addr_stack->addr : 0,
value))
{
if (baton->referenced_type)
@@ -2490,7 +2532,6 @@ dwarf2_evaluate_property (const struct dynamic_prop *prop,
case PROP_LOCLIST:
{
struct dwarf2_property_baton *baton = prop->data.baton;
- struct frame_info *frame = get_selected_frame (NULL);
CORE_ADDR pc = get_frame_address_in_block (frame);
const gdb_byte *data;
struct value *val;