(Ada) problem printing renaming which references a subprogram parameter
authorJoel Brobecker <brobecker@adacore.com>
Fri, 5 Jan 2018 09:29:54 +0000 (04:29 -0500)
committerJoel Brobecker <brobecker@adacore.com>
Fri, 5 Jan 2018 09:29:54 +0000 (04:29 -0500)
commit342f82403949c74517a6353baec73b94d18549ad
treecfb5a6f2c1a52386f9ba17ebf6d66e977ea86b26
parent7150d33cda60fd543e9d9d68eb58d4e6155fb878
(Ada) problem printing renaming which references a subprogram parameter

Consider the following code, which creates a local variable B
which is a renaming whose expression references a subprogram
parameter:

   procedure Flip (Bits : in out Bits_Type; I : Natural) is
   begin
      declare
         B : Boolean renames Bits (I);
      begin
         B := not B; -- BREAK
      end;
   end Flip;

Trying to print the value of B when at the "BREAK" line currently
does not work:

    (gdb) p b
    Could not find i

What happens is the following: For the renaming, GNAT generates
a variable whose name is encoded as follow:

    b___XR_bits___XEXSi

GDB properly detects that variable, determines that, to compute
the variable's value, we start from the symbol "Bits", which
we then have to subscript (XS) using 'i' as the index. The error
occurs while trying to find 'i'.

This is because we forgot to pass the block in the call to
ada_lookup_encoded_symbol, which this patch fixes.

gdb/ChangeLog:

        * ada-exp.y (write_object_renaming): When subscripting an array
        using a symbol as the index, pass the block in call to
        ada_lookup_encoded_symbol when looking that symbol up.

gdb/testsuite/ChangeLog:

        * gdb.ada/rename_subscript_param: New testcase.

Tested on x86_64-linux.

Note: This requires the following GCC patch:

  | 2017-04-25  Pierre-Marie de Rodat  <derodat@adacore.com>
  |
  | * exp_dbug.adb: In Debug_Renaming_Declaration,
  | when dealing with indexed component, accept to produce a renaming
  | symbol when the index is an IN parameter or when it is a name
  | defined in an outer scope.
gdb/ChangeLog
gdb/ada-exp.y
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.ada/rename_subscript_param.exp [new file with mode: 0644]
gdb/testsuite/gdb.ada/rename_subscript_param/pb30_012.adb [new file with mode: 0644]
gdb/testsuite/gdb.ada/rename_subscript_param/pck.adb [new file with mode: 0644]
gdb/testsuite/gdb.ada/rename_subscript_param/pck.ads [new file with mode: 0644]
gdb/testsuite/gdb.ada/rename_subscript_param/pkg.adb [new file with mode: 0644]
gdb/testsuite/gdb.ada/rename_subscript_param/pkg.ads [new file with mode: 0644]