[commit/Ada] Fix error when dereferencing an integer

Joel Brobecker brobecker@adacore.com
Sun Nov 16 08:16:00 GMT 2008


Hello,

I noticed that the current GDB fails when trying to dereference
an integer.  This is a regression that appeared after we changed
value_ind to stop accepting TYPE_CODE_INT values...

For example, if "watch" is a variable:

    (gdb) print *integer(watch'address)
    Attempt to take contents of a non-pointer value.
    (gdb) print integer(watch'address).all
    Attempt to take contents of a non-pointer value.

gdb/:
2008-11-15  Joel Brobecker  <brobecker@adacore.com>

        * ada-lang.c (ada_evaluate_subexp): Improve handling of integer
        type dereferencing.

gdb/testsuite/:
2008-11-15  Joel Brobecker  <brobecker@adacore.com>

        * gdb.ada/int_deref.exp: New testcase.

Tested on x86-linux. Checked in.

-- 
Joel
-------------- next part --------------
Index: ada-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/ada-lang.c,v
retrieving revision 1.182
diff -u -p -r1.182 ada-lang.c
--- ada-lang.c	28 Oct 2008 17:19:55 -0000	1.182
+++ ada-lang.c	15 Nov 2008 17:58:12 -0000
@@ -9204,12 +9204,18 @@ ada_evaluate_subexp (struct type *expect
       arg1 = ada_coerce_ref (arg1);     /* FIXME: What is this for?? */
       type = ada_check_typedef (value_type (arg1));
 
-      if (TYPE_CODE (type) == TYPE_CODE_INT && expect_type != NULL)
-	  /* GDB allows dereferencing an int.  We give it the expected
-	     type (which will be set in the case of a coercion or
-	     qualification). */
-	return ada_value_ind (value_cast (lookup_pointer_type (expect_type),
-					  arg1));
+      if (TYPE_CODE (type) == TYPE_CODE_INT)
+          /* GDB allows dereferencing an int.  If we were given
+             the expect_type, then use that as the target type.
+             Otherwise, assume that the target type is an int.  */
+        {
+          if (expect_type != NULL)
+	    return ada_value_ind (value_cast (lookup_pointer_type (expect_type),
+					      arg1));
+	  else
+	    return value_at_lazy (builtin_type (exp->gdbarch)->builtin_int,
+				  (CORE_ADDR) value_as_address (arg1));
+        }
 
       if (ada_is_array_descriptor_type (type))
         /* GDB allows dereferencing GNAT array descriptors.  */
-------------- next part --------------
diff -x CVS -Nrup gdb.ada.ref/int_deref/foo.adb gdb.ada/int_deref/foo.adb
--- gdb.ada.ref/int_deref/foo.adb	1969-12-31 16:00:00.000000000 -0800
+++ gdb.ada/int_deref/foo.adb	2008-11-15 10:28:01.000000000 -0800
@@ -0,0 +1,21 @@
+--  Copyright 2008 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 Pck;
+
+procedure Foo is
+begin
+   Pck.Watch := Pck.Watch + 1;
+end Foo;
diff -x CVS -Nrup gdb.ada.ref/int_deref/pck.ads gdb.ada/int_deref/pck.ads
--- gdb.ada.ref/int_deref/pck.ads	1969-12-31 16:00:00.000000000 -0800
+++ gdb.ada/int_deref/pck.ads	2008-11-15 10:28:01.000000000 -0800
@@ -0,0 +1,20 @@
+--  Copyright 2008 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 Pck is
+
+   Watch : Integer := 4874;
+
+end Pck;
diff -x CVS -Nrup gdb.ada.ref/int_deref.exp gdb.ada/int_deref.exp
--- gdb.ada.ref/int_deref.exp	1969-12-31 16:00:00.000000000 -0800
+++ gdb.ada/int_deref.exp	2008-11-15 10:28:01.000000000 -0800
@@ -0,0 +1,45 @@
+# Copyright 2008 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 "int_deref"
+set testfile "${testdir}/foo"
+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
+}
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+gdb_load ${binfile}
+
+set bp_location [gdb_get_line_number "Pck.Watch" ${testdir}/foo.adb]
+runto "foo.adb:$bp_location"
+
+gdb_test "print *integer(watch'address)" \
+         " = 4874"
+
+gdb_test "print integer(watch'address).all" \
+         " = 4874"
+


More information about the Gdb-patches mailing list