]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
language-specific read_var_value for Ada renamings
authorJoel Brobecker <brobecker@gnat.com>
Fri, 2 Mar 2012 19:29:01 +0000 (19:29 +0000)
committerJoel Brobecker <brobecker@gnat.com>
Fri, 2 Mar 2012 19:29:01 +0000 (19:29 +0000)
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.

14 files changed:
gdb/ChangeLog
gdb/ada-lang.c
gdb/c-lang.c
gdb/d-lang.c
gdb/f-lang.c
gdb/findvar.c
gdb/jv-lang.c
gdb/language.c
gdb/language.h
gdb/m2-lang.c
gdb/objc-lang.c
gdb/opencl-lang.c
gdb/p-lang.c
gdb/value.h

index 41d0277a53ffbc8e1c690774cbf1938cd6e054a5..a26e69423ddb1b09d770c9de62dab3abb849127c 100644 (file)
@@ -1,3 +1,19 @@
+2012-03-02  Joel Brobecker  <brobecker@adacore.com>
+
+       * 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.
+
 2012-03-02  Tom Tromey  <tromey@redhat.com>
            Pedro Alves  <palves@redhat.com>
 
index 4c17eaaae390a3682fd19b70a5a332bca8be0872..040d606165d20645f701d63133f68b8c508ee7e4 100644 (file)
@@ -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;
+}
 \f
 
                                 /* 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.  */
index 767d13acaf9d13ee22642038d16b957e4d37f605..28dce8df6bd18b1f205279dde6fc8c075d716761 100644 (file)
@@ -847,6 +847,7 @@ const struct language_defn c_language_defn =
   c_print_typedef,             /* Print a typedef using appropriate syntax */
   c_val_print,                 /* Print a value using appropriate syntax */
   c_value_print,               /* Print a top-level value */
+  default_read_var_value,      /* la_read_var_value */
   NULL,                                /* Language specific skip_trampoline */
   NULL,                                /* name_of_this */
   basic_lookup_symbol_nonlocal,        /* lookup_symbol_nonlocal */
@@ -970,6 +971,7 @@ const struct language_defn cplus_language_defn =
   c_print_typedef,             /* Print a typedef using appropriate syntax */
   c_val_print,                 /* Print a value using appropriate syntax */
   c_value_print,               /* Print a top-level value */
+  default_read_var_value,      /* la_read_var_value */
   cplus_skip_trampoline,       /* Language specific skip_trampoline */
   "this",                       /* name_of_this */
   cp_lookup_symbol_nonlocal,   /* lookup_symbol_nonlocal */
@@ -1011,6 +1013,7 @@ const struct language_defn asm_language_defn =
   c_print_typedef,             /* Print a typedef using appropriate syntax */
   c_val_print,                 /* Print a value using appropriate syntax */
   c_value_print,               /* Print a top-level value */
+  default_read_var_value,      /* la_read_var_value */
   NULL,                                /* Language specific skip_trampoline */
   NULL,                                /* name_of_this */
   basic_lookup_symbol_nonlocal,        /* lookup_symbol_nonlocal */
@@ -1057,6 +1060,7 @@ const struct language_defn minimal_language_defn =
   c_print_typedef,             /* Print a typedef using appropriate syntax */
   c_val_print,                 /* Print a value using appropriate syntax */
   c_value_print,               /* Print a top-level value */
+  default_read_var_value,      /* la_read_var_value */
   NULL,                                /* Language specific skip_trampoline */
   NULL,                                /* name_of_this */
   basic_lookup_symbol_nonlocal,        /* lookup_symbol_nonlocal */
index 202820ef2d42910e2c7bf7aebeb842b25f7d9dcd..9a8cf522c3651340299d9849ef3b67096986bf50 100644 (file)
@@ -256,6 +256,7 @@ static const struct language_defn d_language_defn =
                                   syntax.  */
   d_val_print,                 /* Print a value using appropriate syntax.  */
   c_value_print,               /* Print a top-level value.  */
+  default_read_var_value,      /* la_read_var_value */
   NULL,                                /* Language specific skip_trampoline.  */
   "this",
   basic_lookup_symbol_nonlocal, 
index ef78bc3295ba5728197310739889d623db3d1926..3368d01c105ee0c3a8b5e9258c13a4afeb29297d 100644 (file)
@@ -289,6 +289,7 @@ const struct language_defn f_language_defn =
   default_print_typedef,       /* Print a typedef using appropriate syntax */
   f_val_print,                 /* Print a value using appropriate syntax */
   c_value_print,               /* FIXME */
+  default_read_var_value,      /* la_read_var_value */
   NULL,                                /* Language specific skip_trampoline */
   NULL,                        /* name_of_this */
   cp_lookup_symbol_nonlocal,   /* lookup_symbol_nonlocal */
index 79c4221f73624b37100743390cdbd1c8aab46ad3..9009e6f324be2ae80984546281c665aba35c3ef2 100644 (file)
@@ -34,6 +34,7 @@
 #include "user-regs.h"
 #include "block.h"
 #include "objfiles.h"
+#include "language.h"
 
 /* Basic byte-swapping routines.  All 'extract' functions return a
    host-format integer from a target-format integer at ADDR which is
@@ -405,13 +406,11 @@ symbol_read_needs_frame (struct symbol *sym)
   return 1;
 }
 
-/* Given a struct symbol for a variable,
-   and a stack frame id, read the value of the variable
-   and return a (pointer to a) struct value containing the value.
-   If the variable cannot be found, throw error.  */
+/* A default implementation for the "la_read_var_value" hook in
+   the language vector which should work in most situations.  */
 
 struct value *
-read_var_value (struct symbol *var, struct frame_info *frame)
+default_read_var_value (struct symbol *var, struct frame_info *frame)
 {
   struct value *v;
   struct type *type = SYMBOL_TYPE (var);
@@ -594,6 +593,19 @@ read_var_value (struct symbol *var, struct frame_info *frame)
   return v;
 }
 
+/* Calls VAR's language la_read_var_value hook with the given arguments.  */
+
+struct value *
+read_var_value (struct symbol *var, struct frame_info *frame)
+{
+  const struct language_defn *lang = language_def (SYMBOL_LANGUAGE (var));
+
+  gdb_assert (lang != NULL);
+  gdb_assert (lang->la_read_var_value != NULL);
+
+  return lang->la_read_var_value (var, frame);
+}
+
 /* Install default attributes for register values.  */
 
 struct value *
index 18a7c195993062e6405747ae72d944fe03bc366e..08ecf5f54eed03d865f84571f852a0c4ed1e5380 100644 (file)
@@ -1181,6 +1181,7 @@ const struct language_defn java_language_defn =
   default_print_typedef,       /* Print a typedef using appropriate syntax */
   java_val_print,              /* Print a value using appropriate syntax */
   java_value_print,            /* Print a top-level value */
+  default_read_var_value,      /* la_read_var_value */
   NULL,                                /* Language specific skip_trampoline */
   "this",                      /* name_of_this */
   basic_lookup_symbol_nonlocal,        /* lookup_symbol_nonlocal */
index ae3410861136332eec47fc8d119f8420ae6429a1..f0a8697998fcec71d8cc75df62a274e6b45ca2aa 100644 (file)
@@ -917,6 +917,7 @@ const struct language_defn unknown_language_defn =
   default_print_typedef,       /* Print a typedef using appropriate syntax */
   unk_lang_val_print,          /* Print a value using appropriate syntax */
   unk_lang_value_print,                /* Print a top-level value */
+  default_read_var_value,      /* la_read_var_value */
   unk_lang_trampoline,         /* Language specific skip_trampoline */
   "this",                      /* name_of_this */
   basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
@@ -960,6 +961,7 @@ const struct language_defn auto_language_defn =
   default_print_typedef,       /* Print a typedef using appropriate syntax */
   unk_lang_val_print,          /* Print a value using appropriate syntax */
   unk_lang_value_print,                /* Print a top-level value */
+  default_read_var_value,      /* la_read_var_value */
   unk_lang_trampoline,         /* Language specific skip_trampoline */
   "this",                      /* name_of_this */
   basic_lookup_symbol_nonlocal,        /* lookup_symbol_nonlocal */
@@ -1001,6 +1003,7 @@ const struct language_defn local_language_defn =
   default_print_typedef,       /* Print a typedef using appropriate syntax */
   unk_lang_val_print,          /* Print a value using appropriate syntax */
   unk_lang_value_print,                /* Print a top-level value */
+  default_read_var_value,      /* la_read_var_value */
   unk_lang_trampoline,         /* Language specific skip_trampoline */
   "this",                      /* name_of_this */
   basic_lookup_symbol_nonlocal,        /* lookup_symbol_nonlocal */
index 76dad325b5b740a9c73fd007a5bb669db13d589d..d612c70523a3654d01e37a44d976d85771d8a67c 100644 (file)
@@ -252,6 +252,15 @@ struct language_defn
     void (*la_value_print) (struct value *, struct ui_file *,
                            const struct value_print_options *);
 
+    /* Given a symbol VAR, and a stack frame id FRAME, read the value
+       of the variable an return (pointer to a) struct value containing
+       the value.
+
+       Throw an error if the variable cannot be found.  */
+
+    struct value *(*la_read_var_value) (struct symbol *var,
+                                       struct frame_info *frame);
+
     /* PC is possibly an unknown languages trampoline.
        If that PC falls in a trampoline belonging to this language,
        return the address of the first pc in the real function, or 0
index 9cd27c9ea929cb9b2576a4760e43e51e0e675e4a..8faa6c1465b439ee09eecc47b4a243c32797e52e 100644 (file)
@@ -385,6 +385,7 @@ const struct language_defn m2_language_defn =
   m2_print_typedef,            /* Print a typedef using appropriate syntax */
   m2_val_print,                        /* Print a value using appropriate syntax */
   c_value_print,               /* Print a top-level value */
+  default_read_var_value,      /* la_read_var_value */
   NULL,                                /* Language specific skip_trampoline */
   NULL,                                /* name_of_this */
   basic_lookup_symbol_nonlocal,        /* lookup_symbol_nonlocal */
index 74528c8b913e78f3c0d1d5eb4740bdda64986c0f..15bf792bc34f7bc14fa20b4ea9289a60467b9846 100644 (file)
@@ -524,6 +524,7 @@ const struct language_defn objc_language_defn = {
   c_print_typedef,             /* Print a typedef using appropriate syntax */
   c_val_print,                 /* Print a value using appropriate syntax */
   c_value_print,               /* Print a top-level value */
+  default_read_var_value,      /* la_read_var_value */
   objc_skip_trampoline,        /* Language specific skip_trampoline */
   "self",                      /* name_of_this */
   basic_lookup_symbol_nonlocal,        /* lookup_symbol_nonlocal */
index 3554d182a75fc2f9d445f60c9e886366f54b28a3..54075a4194757fa36a222fdafd9c52050a9198a5 100644 (file)
@@ -1008,6 +1008,7 @@ const struct language_defn opencl_language_defn =
   c_print_typedef,             /* Print a typedef using appropriate syntax */
   c_val_print,                 /* Print a value using appropriate syntax */
   c_value_print,               /* Print a top-level value */
+  default_read_var_value,      /* la_read_var_value */
   NULL,                                /* Language specific skip_trampoline */
   NULL,                         /* name_of_this */
   basic_lookup_symbol_nonlocal,        /* lookup_symbol_nonlocal */
index 826d24fee169544f66a853d779f3038b9c396238..c59ba0bd71d165a2ec18a23e5f043eb25addbea9 100644 (file)
@@ -444,6 +444,7 @@ const struct language_defn pascal_language_defn =
   pascal_print_typedef,                /* Print a typedef using appropriate syntax */
   pascal_val_print,            /* Print a value using appropriate syntax */
   pascal_value_print,          /* Print a top-level value */
+  default_read_var_value,      /* la_read_var_value */
   NULL,                                /* Language specific skip_trampoline */
   "this",                      /* name_of_this */
   basic_lookup_symbol_nonlocal,        /* lookup_symbol_nonlocal */
index f0fdb4cac3baeb7991a8e460cfc548b29fb4696f..3ce0f88138317546636c3058511334595268172c 100644 (file)
@@ -536,6 +536,9 @@ extern int symbol_read_needs_frame (struct symbol *);
 extern struct value *read_var_value (struct symbol *var,
                                     struct frame_info *frame);
 
+extern struct value *default_read_var_value (struct symbol *var,
+                                            struct frame_info *frame);
+
 extern struct value *allocate_value (struct type *type);
 extern struct value *allocate_value_lazy (struct type *type);
 extern void allocate_value_contents (struct value *value);