From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12462 invoked by alias); 8 Jan 2008 17:51:05 -0000 Received: (qmail 12447 invoked by uid 22791); 8 Jan 2008 17:51:03 -0000 X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 08 Jan 2008 17:50:33 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 7DF9F2A96B4 for ; Tue, 8 Jan 2008 12:50:31 -0500 (EST) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id jOOG4-oZeZ9p for ; Tue, 8 Jan 2008 12:50:31 -0500 (EST) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id 5B8C42A96B8 for ; Tue, 8 Jan 2008 12:50:29 -0500 (EST) Received: by joel.gnat.com (Postfix, from userid 1000) id 0AF75E7ACB; Tue, 8 Jan 2008 09:50:21 -0800 (PST) Date: Tue, 08 Jan 2008 17:51:00 -0000 From: Joel Brobecker To: gdb-patches@sourceware.org Subject: [commit/Ada] result of function call as a parameter to another function call Message-ID: <20080108175021.GJ24614@adacore.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="lc9FT7cWel8HagAv" Content-Disposition: inline User-Agent: Mutt/1.4.2.2i Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2008-01/txt/msg00149.txt.bz2 --lc9FT7cWel8HagAv Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 1385 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 * 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 * 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 --lc9FT7cWel8HagAv Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="ref_args.diff" Content-length: 1621 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); --lc9FT7cWel8HagAv Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="ref_args-tc.diff" Content-length: 5140 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 . + +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 . + +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 . + +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 . + +with Pck; use Pck; + +procedure Foo is + My_Parameter : Parameter := Ident (P => (1, 2, 3)); +begin + Do_Nothing (My_Parameter); -- STOP +end Foo; --lc9FT7cWel8HagAv--