diff options
author | Joel Brobecker <brobecker@gnat.com> | 2010-04-20 22:26:57 +0000 |
---|---|---|
committer | Joel Brobecker <brobecker@gnat.com> | 2010-04-20 22:26:57 +0000 |
commit | 0c3acc092379d8b0c9d74a47c9cc03375dbad5fc (patch) | |
tree | 9e2defc0cfb6cf3c456579c6659ed110fda94792 /gdb/testsuite | |
parent | 418205099be3d614ad92c8c78486b1a60b498916 (diff) | |
download | gdb-0c3acc092379d8b0c9d74a47c9cc03375dbad5fc.zip gdb-0c3acc092379d8b0c9d74a47c9cc03375dbad5fc.tar.gz gdb-0c3acc092379d8b0c9d74a47c9cc03375dbad5fc.tar.bz2 |
Wrong value printed by info locals for dynamic object.
The problem is printing the wrong value for dynamic local variables
when using the "info locals" command. Consider the following code:
procedure Print (I1 : Positive; I2 : Positive) is
type My_String is array (I1 .. I2) of Character;
I : My_String := (others => 'A');
S : String (1 .. I2 + 3) := (others => ' ');
begin
S (I1 .. I2) := String (I); -- BREAK
Put_Line (S);
end Print;
After the debugger stopped at BREAK, we try printing all local variables.
Here is what we get:
(gdb) info locals
i = "["00"]["00"]"
s = "["00"]["00"]["00"]["00"]["00"]["00"]["00"]["00"]"
Curiously, printing their value using the "print" command works:
(gdb) print i
$1 = "AA"
(gdb) print s
$2 = " "
We traced the problem to trying to get the contents of a variable
(call to value_contents) before "fix'ing" it. For those not familiar
with the Ada language support, "fixing" a value consists of swapping
the value's dynamic type with a static version that is appropriate
for our actual value. As a result, the dynamic type was used to
determine the value size, which is zero, and thus the value contents
was empty.
gdb/ChangeLog:
* valprint.c (common_val_print): Fix the value before extracting
its contents.
* ada-lang.c (ada_to_fixed_value): Make this function extern.
* ada-lang.h (ada_to_fixed_value): New function declaration.
* ada-valprint.c (ada_value_print): Use ada_to_fixed_value
to avoid code duplication and fix a bug in the handling of
fixed types contents.
gdb/testsuite/ChangeLog:
* gdb.ada/dyn_loc: New testcase.
Diffstat (limited to 'gdb/testsuite')
-rw-r--r-- | gdb/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gdb/testsuite/gdb.ada/dyn_loc.exp | 53 | ||||
-rw-r--r-- | gdb/testsuite/gdb.ada/dyn_loc/p.adb | 21 | ||||
-rw-r--r-- | gdb/testsuite/gdb.ada/dyn_loc/pack.adb | 29 | ||||
-rw-r--r-- | gdb/testsuite/gdb.ada/dyn_loc/pack.ads | 20 |
5 files changed, 127 insertions, 0 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index d1aa33b..8913d89 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2010-04-20 Joel Brobecker <brobecker@adacore.com> + + * gdb.ada/dyn_loc: New testcase. + 2010-04-20 Chris Moller <cmoller@redhat.com> PR 10867 diff --git a/gdb/testsuite/gdb.ada/dyn_loc.exp b/gdb/testsuite/gdb.ada/dyn_loc.exp new file mode 100644 index 0000000..953bd5f --- /dev/null +++ b/gdb/testsuite/gdb.ada/dyn_loc.exp @@ -0,0 +1,53 @@ +# Copyright 2010 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +if $tracelevel then { + strace $tracelevel +} + +load_lib "ada.exp" + +set testdir "dyn_loc" +set testfile "${testdir}/p" +set srcfile ${srcdir}/${subdir}/${testfile}.adb +set binfile ${objdir}/${subdir}/${testfile} + +file mkdir ${objdir}/${subdir}/${testdir} +if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug ]] != "" } { + return -1 +} + +clean_restart ${testfile} + +set bp_location [gdb_get_line_number "BREAK" ${testdir}/pack.adb] +if ![runto "pack.adb:$bp_location" ] then { + return -1 +} + +set eol "\[\r\n\]+" + +set test "info locals" +gdb_test_multiple "$test" "$test" { + -re "i = \"AA\"${eol}s = \" \"" { + pass $test + } + -re "i = \"AA\"${eol}.*${eol}s = \" \"" { + # The debugger printed the two local variable correctly, but + # it probably failed to NOT print some variables internally + # generated by the compiler. This is a known issue. + xfail $test + } +} + diff --git a/gdb/testsuite/gdb.ada/dyn_loc/p.adb b/gdb/testsuite/gdb.ada/dyn_loc/p.adb new file mode 100644 index 0000000..f8fd801 --- /dev/null +++ b/gdb/testsuite/gdb.ada/dyn_loc/p.adb @@ -0,0 +1,21 @@ +-- Copyright 2010 Free Software Foundation, Inc. +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see <http://www.gnu.org/licenses/>. + +with Pack; use Pack; + +procedure P is +begin + Print (4, 5); +end P; diff --git a/gdb/testsuite/gdb.ada/dyn_loc/pack.adb b/gdb/testsuite/gdb.ada/dyn_loc/pack.adb new file mode 100644 index 0000000..deb3d06 --- /dev/null +++ b/gdb/testsuite/gdb.ada/dyn_loc/pack.adb @@ -0,0 +1,29 @@ +-- Copyright 2010 Free Software Foundation, Inc. +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see <http://www.gnu.org/licenses/>. + +with Ada.Text_IO; use Ada.Text_IO; + +package body Pack is + + procedure Print (I1 : Positive; I2 : Positive) is + type My_String is array (I1 .. I2) of Character; + I : My_String := (others => 'A'); + S : String (1 .. I2 + 3) := (others => ' '); + begin + S (I1 .. I2) := String (I); -- BREAK + Put_Line (S); + end Print; + +end Pack; diff --git a/gdb/testsuite/gdb.ada/dyn_loc/pack.ads b/gdb/testsuite/gdb.ada/dyn_loc/pack.ads new file mode 100644 index 0000000..8925c79 --- /dev/null +++ b/gdb/testsuite/gdb.ada/dyn_loc/pack.ads @@ -0,0 +1,20 @@ +-- Copyright 2010 Free Software Foundation, Inc. +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see <http://www.gnu.org/licenses/>. + +package Pack is + + procedure Print (I1 : Positive; I2 : Positive); + +end Pack; |