* [commit/Ada] result of function call as a parameter to another function call
@ 2008-01-08 17:51 Joel Brobecker
2008-01-08 19:41 ` Joel Brobecker
0 siblings, 1 reply; 2+ messages in thread
From: Joel Brobecker @ 2008-01-08 17:51 UTC (permalink / raw)
To: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 1385 bytes --]
Hello,
As I hinted a littler earlier, there is a problem in the debugger
where we use a the result from a function call as parameter to another
function call. The problem arises when the parameter is a reference
type.
Assuming My_Parameter is a variable of type Parameter which is
defined as a record (the equivalent of a C "struct"):
(gdb) p ident (ident (my_parameter))
Attempt to take address of value not located in memory.
There were a couple of issues: One was an omission during the
construction of a value (inside ada-lang.c:ensure_lval), where
we forgot to set the value->lval; And another in the handling
of formals that are reference types.
Paul fixed the problem as follow:
2008-01-08 Paul Hilfinger <hilfinger@adacore.com>
* ada-lang.c (ensure_lval): Fix value lval kind.
(convert_actual): Add handling for arguments passed by reference.
I also wrote a testcase:
2008-01-08 Joel Brobecker <brobecker@adacore.com>
* gdb.ada/funcall_param: New test program.
* gdb.ada/funcall_param.exp: New testcase.
Tested on x86-linux, no regression.
I checked the ada-lang.c change in, but I will defer a bit the checkin
of the testcase because the testcase itself depends on another change
that I need to make (Ada parameter coercion, see
http://www.sourceware.org/ml/gdb-patches/2008-01/msg00129.html) in order
to pass.
--
Joel
[-- Attachment #2: ref_args.diff --]
[-- Type: text/plain, Size: 1621 bytes --]
Index: ada-lang.c
===================================================================
--- ada-lang.c (revision 101)
+++ ada-lang.c (revision 102)
@@ -3929,6 +3929,7 @@ ensure_lval (struct value *val, CORE_ADD
if (gdbarch_frame_align_p (current_gdbarch))
*sp = gdbarch_frame_align (current_gdbarch, *sp);
}
+ VALUE_LVAL (val) = lval_memory;
write_memory (VALUE_ADDRESS (val), value_contents_raw (val), len);
}
@@ -3957,11 +3958,13 @@ convert_actual (struct value *actual, st
if (ada_is_array_descriptor_type (formal_target)
&& TYPE_CODE (actual_target) == TYPE_CODE_ARRAY)
return make_array_descriptor (formal_type, actual, sp);
- else if (TYPE_CODE (formal_type) == TYPE_CODE_PTR)
+ else if (TYPE_CODE (formal_type) == TYPE_CODE_PTR
+ || TYPE_CODE (formal_type) == TYPE_CODE_REF)
{
+ struct value *result;
if (TYPE_CODE (formal_target) == TYPE_CODE_ARRAY
&& ada_is_array_descriptor_type (actual_target))
- return desc_data (actual);
+ result = desc_data (actual);
else if (TYPE_CODE (actual_type) != TYPE_CODE_PTR)
{
if (VALUE_LVAL (actual) != lval_memory)
@@ -3974,8 +3977,11 @@ convert_actual (struct value *actual, st
TYPE_LENGTH (actual_type));
actual = ensure_lval (val, sp);
}
- return value_addr (actual);
+ result = value_addr (actual);
}
+ else
+ return actual;
+ return value_cast_pointers (formal_type, result);
}
else if (TYPE_CODE (actual_type) == TYPE_CODE_PTR)
return ada_value_ind (actual);
[-- Attachment #3: ref_args-tc.diff --]
[-- Type: text/plain, Size: 5140 bytes --]
Index: gdb.ada/funcall_param.exp
===================================================================
--- gdb.ada/funcall_param.exp (revision 0)
+++ gdb.ada/funcall_param.exp (revision 103)
@@ -0,0 +1,46 @@
+# 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 "funcall_param"
+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 "STOP" ${testdir}/foo.adb]
+runto "foo.adb:$bp_location"
+
+# Test printing and type-printing of a tagged type that is not
+# class-wide.
+
+gdb_test "p ident (ident (my_parameter))" \
+ "\\(one => 1, two => 2, three => 3\\)" \
+ "p ident (ident (my_parameter))"
+
Index: gdb.ada/funcall_param/pck.adb
===================================================================
--- gdb.ada/funcall_param/pck.adb (revision 0)
+++ gdb.ada/funcall_param/pck.adb (revision 103)
@@ -0,0 +1,28 @@
+-- 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 body Pck is
+
+ function Ident (P : Parameter) return Parameter is
+ begin
+ return P;
+ end Ident;
+
+ procedure Do_Nothing (P : in out Parameter) is
+ begin
+ null;
+ end Do_Nothing;
+
+end Pck;
Index: gdb.ada/funcall_param/pck.ads
===================================================================
--- gdb.ada/funcall_param/pck.ads (revision 0)
+++ gdb.ada/funcall_param/pck.ads (revision 103)
@@ -0,0 +1,28 @@
+-- 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
+
+ type Parameter is record
+ One : Integer;
+ Two : Integer;
+ Three : Integer;
+ end record;
+
+ function Ident (P : Parameter) return Parameter;
+
+ procedure Do_Nothing (P : in out Parameter);
+
+end Pck;
Index: gdb.ada/funcall_param/foo.adb
===================================================================
--- gdb.ada/funcall_param/foo.adb (revision 0)
+++ gdb.ada/funcall_param/foo.adb (revision 103)
@@ -0,0 +1,22 @@
+-- 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; use Pck;
+
+procedure Foo is
+ My_Parameter : Parameter := Ident (P => (1, 2, 3));
+begin
+ Do_Nothing (My_Parameter); -- STOP
+end Foo;
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [commit/Ada] result of function call as a parameter to another function call
2008-01-08 17:51 [commit/Ada] result of function call as a parameter to another function call Joel Brobecker
@ 2008-01-08 19:41 ` Joel Brobecker
0 siblings, 0 replies; 2+ messages in thread
From: Joel Brobecker @ 2008-01-08 19:41 UTC (permalink / raw)
To: gdb-patches
> 2008-01-08 Joel Brobecker <brobecker@adacore.com>
>
> * gdb.ada/funcall_param: New test program.
> * gdb.ada/funcall_param.exp: New testcase.
>
> Tested on x86-linux, no regression.
>
> I checked the ada-lang.c change in, but I will defer a bit the checkin
> of the testcase because the testcase itself depends on another change
> that I need to make (Ada parameter coercion, see
> http://www.sourceware.org/ml/gdb-patches/2008-01/msg00129.html) in order
> to pass.
All conditions are now met, so I committed the testcase as well.
--
Joel
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2008-01-08 19:41 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-08 17:51 [commit/Ada] result of function call as a parameter to another function call Joel Brobecker
2008-01-08 19:41 ` Joel Brobecker
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox