(Ada/MI) Fix -var-evaluate-expression for access to unconstrained arrays
authorXavier Roirand <roirand@adacore.com>
Mon, 10 Sep 2018 15:33:32 +0000 (10:33 -0500)
committerJoel Brobecker <brobecker@adacore.com>
Mon, 10 Sep 2018 15:33:32 +0000 (11:33 -0400)
commitb9c50e9a9ac48662b2132583c52d46976efb3512
tree9e7d7a2e2692a79eeb6278ffe4f21a34f9dc50d1
parent736ade86ea3dd3df31120b6c617d64c88bcc86c1
(Ada/MI) Fix -var-evaluate-expression for access to unconstrained arrays

Using this Ada code:

   type String_Access is access String;
   type Array_Of_String is array (1 .. 2) of String_Access;
   Aos : Array_Of_String := (new String'("ab"), new String'("cd"));

In GDB/MI mode, create a variable which type is Aos, evaluate it:

(gdb) -var-create var1 * Aos
^done,name="var1",numchild="2",value="[2]",type="bar.array_of_string",thread-id="1",has_more="0"

Now print it:

(gdb) -var-list-children 1 var1
^done,numchild="2",children=[child={name="var1.1",exp="1",numchild="1",value="[2] \"ab\"", type="bar.string_access",thread-id="1"},child={name="var1.2",exp="2",numchild="1",value="[2] \"cd\"", type="bar.string_access",thread-id="1"}],has_more="0"

But printed fields "value" are wrong, since it should be:

^done,numchild="2",children=[child={name="var1.1",exp="1",numchild="1",value="0x634018",type="bar.string_access",thread-id="1"},child={name="var1.2",exp="2",numchild="1",value="0x634038",type="bar.string_access",thread-id="1"}],has_more="0"^M

Print each child of var1:

(gdb) -var-evaluate-expression var1.1
^done,value="[2] \"ab\""
(gdb) -var-evaluate-expression var1.2
^done,value="[2] \"cd\""

Whereas it should be

(gdb) -var-evaluate-expression var1.1
^done,value="0x635018"
(gdb) -var-evaluate-expression var1.2
^done,value="0x635038"

This patch fixes this.

gdb/ChangeLog:

        * ada-lang.c (ada_value_subscript): Handle case when parameter is
        an array of access to unconstrained array.

testsuite/ChangeLog

        * gdb.ada/mi_string_access.exp: New testcase.
        * gdb.ada/mi_string_access/bar.adb: New file.
        * gdb.ada/mi_string_access/pck.adb: New file.
        * gdb.ada/mi_string_access/pck.asd: New file.

Tested on x86_64-linux.
gdb/ChangeLog
gdb/ada-lang.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.ada/mi_string_access.exp [new file with mode: 0644]
gdb/testsuite/gdb.ada/mi_string_access/bar.adb [new file with mode: 0644]
gdb/testsuite/gdb.ada/mi_string_access/pck.adb [new file with mode: 0644]
gdb/testsuite/gdb.ada/mi_string_access/pck.ads [new file with mode: 0644]