This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFC] New language-method to print local symbol?


Hello,

This is another change that we made a while ago and that I wished
we started discussing earlier. Suppose we are stopped inside the
following procedure Foo (say at the "STOP" marker):

    procedure Foo is
       S : String := "1234";
       R : String renames S;
    begin
       S (S'First) := 'A';  -- STOP
    end Foo;

Here is what currently happens when a user does an "info locals":

    (gdb) info locals
    s = "1234"
    r = 72

Variable "R" is a renaming of S, and so R should have the same
value as "S"!. The problem is that renamings are encoded using
a bogus integer variable whose name tell us how to compute the
actual variable value.  For instance, if you look at exp_dbug.ads
in the gcc/ada sources, you'll see that the variable name has
an ___XR suffix followed by a codified string (XA means "dereference",
XR<field> means "select <field> component", etc). It's like a string-
ified version of a program.

Going back to our problem, the renaming above results in the following
actual variables to be defined:

    S : String;
    r___XR_s___XE : Integer;

The code that prints all the locals just treats all variables as plain
variable, and thus calls read_variable followed by a call to
print_variable_value.  Unfortunately, that doesn't work in this case
for Ada.

For AdaCore's local tree, it was easy enough to just hook in an Ada
routine that does the printing if we detect an Ada renaming, or else
let the standard symbol printing do the work:

@@ -1371,6 +1377,8 @@ print_block_frame_locals (struct block *
            fputs_filtered ("\t", stream);
          fputs_filtered (SYMBOL_PRINT_NAME (sym), stream);
          fputs_filtered (" = ", stream);
+          if (ada_print_value_if_ada_object_renaming (sym, b, frame, stream))
+            continue;
          print_variable_value (sym, frame, stream);
          fprintf_filtered (stream, "\n");
          break;

However, this isn't very clean, in my opinion, and cries out for
a new language method.  The alternative, is to have print_variable_value
do the right thing, but I don't think this would be as interesting.
Right now, all it does is:

  struct value *val = read_var_value (var, frame);
  value_print (val, stream, 0, Val_pretty_default);

We can't improve value_print since we have already lost the symbol
(and therefore the symbol name) by then, and I don't think we should
change read_var_value to become language­sensitive. I've always seen
this routine as low-level language-insensitive...

My suggestion is to define a new language method called

  la_print_block_frame_local_sym (struct symbol *sym,
                                  struct block *b,
                                  struct frame_info *frame,
                                  struct ui_file *stream)

I would define a "default_print_block_frame_local_sym" that simply
calls "print_variable_value" while the Ada version would check for
renamings first, and fallback on the default print version if not.

Given that we use the current_language to print variables, regardless
of whether the language matches the frame or not, I think we want to
do the same here.

Would the addition of that language method be OK? Better suggestions?
Attached is the current patch (some changes in ada-lang are also
necessary due to uncovered bugs), just for your information.

Thanks,
-- 
Joel

Attachment: renaming-local.diff
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]