aboutsummaryrefslogtreecommitdiff
path: root/gdb/ada-lang.c
diff options
context:
space:
mode:
authorJoel Brobecker <brobecker@gnat.com>2012-03-02 19:29:01 +0000
committerJoel Brobecker <brobecker@gnat.com>2012-03-02 19:29:01 +0000
commita5ee536be2c16fcbe223490358dbe4d1914f0e1a (patch)
treef12b46a7e65a78cd75c0ea488ab154ea25e6d765 /gdb/ada-lang.c
parentf59f708a4b12a347cb003c750b96336822481900 (diff)
downloadgdb-a5ee536be2c16fcbe223490358dbe4d1914f0e1a.zip
gdb-a5ee536be2c16fcbe223490358dbe4d1914f0e1a.tar.gz
gdb-a5ee536be2c16fcbe223490358dbe4d1914f0e1a.tar.bz2
language-specific read_var_value for Ada renamings
The purpose of this patch is to better support renamings in the "info locals" command. Consider ... procedure Foo is GV : Integer renames Pck.Global_Variable; begin Increment (GV); -- STOP end Foo; ... Pck.Global_Variable is just an integer. After having stopped at the "STOP" line, "info locals" yields: (gdb) info locals gv = <error reading variable gv (Cannot access memory at address 0xffffffffffffffff)> In reality, two things are happening: (1) Variable "GV" does not exist, which is normal, since there is "GV" the renaming of another variable; (2) But to allow the user access to that renaming the same way the code has, the compiler produces an artificial variable whose name encodes the renaming: gv___XR_pck__global_variable___XE For practical reasons, the artificial variable itself is given irrelevant types and addresses. But the "info locals" command does not act as if it was a short-cut of "foreach VAR in locals, print VAR". Instead it gets the value of each VAR directly, which does not work in this case, since the variable is artificial and needs to be decoded first. This patch makes the "read_var_value" routine language-specific. The old implementation of "read_var_value" gets renamed to "default_read_var_value" and all languages now use it (unchanged behavior), except for Ada. In Ada, the new function ada_read_var_value checks if we have a renaming, and if so, evaluates its value, or else defers to default_read_var_value. gdb/ChangeLog: * language.h (struct language_defn): New "method" la_read_var_value. * findvar.c: #include "language.h". (default_read_var_value): Renames read_var_value. Rewrite function description. (read_var_value): New function. * value.h (default_read_var_value): Add prototype. * ada-lang.c (ada_read_renaming_var_value, ada_read_var_value): New functions. (ada_language_defn): Add entry for la_read_var_value. * c-lang.c, d-lang.c, f-lang.c, jv-lang.c, language.c, * m2-lang.c, objc-lang.c, opencl-lang.c, p-lang.c: Update language_defn structures to add entry for new la_read_var_value field.
Diffstat (limited to 'gdb/ada-lang.c')
-rw-r--r--gdb/ada-lang.c47
1 files changed, 46 insertions, 1 deletions
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 4c17eaa..040d606 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -4041,8 +4041,30 @@ parse_old_style_renaming (struct type *type,
if (len != NULL)
*len = suffix - info;
return kind;
-}
+}
+
+/* Compute the value of the given RENAMING_SYM, which is expected to
+ be a symbol encoding a renaming expression. BLOCK is the block
+ used to evaluate the renaming. */
+static struct value *
+ada_read_renaming_var_value (struct symbol *renaming_sym,
+ struct block *block)
+{
+ char *sym_name;
+ struct expression *expr;
+ struct value *value;
+ struct cleanup *old_chain = NULL;
+
+ sym_name = xstrdup (SYMBOL_LINKAGE_NAME (renaming_sym));
+ old_chain = make_cleanup (xfree, sym_name);
+ expr = parse_exp_1 (&sym_name, block, 0);
+ make_cleanup (free_current_contents, &expr);
+ value = evaluate_expression (expr);
+
+ do_cleanups (old_chain);
+ return value;
+}
/* Evaluation: Function Calls */
@@ -12437,6 +12459,28 @@ ada_get_symbol_name_cmp (const char *lookup_name)
return compare_names;
}
+/* 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)
+{
+ struct block *frame_block = NULL;
+ struct symbol *renaming_sym = NULL;
+
+ /* The only case where default_read_var_value is not sufficient
+ is when VAR is a renaming... */
+ if (frame)
+ frame_block = get_frame_block (frame, NULL);
+ if (frame_block)
+ renaming_sym = ada_find_renaming_symbol (var, frame_block);
+ if (renaming_sym != NULL)
+ return ada_read_renaming_var_value (renaming_sym, frame_block);
+
+ /* This is a typical case where we expect the default_read_var_value
+ function to work. */
+ return default_read_var_value (var, frame);
+}
+
const struct language_defn ada_language_defn = {
"ada", /* Language name */
language_ada,
@@ -12457,6 +12501,7 @@ const struct language_defn ada_language_defn = {
ada_print_typedef, /* Print a typedef using appropriate syntax */
ada_val_print, /* Print a value using appropriate syntax */
ada_value_print, /* Print a top-level value */
+ ada_read_var_value, /* la_read_var_value */
NULL, /* Language specific skip_trampoline */
NULL, /* name_of_this */
ada_lookup_symbol_nonlocal, /* Looking up non-local symbols. */