From: Joel Brobecker <brobecker@adacore.com>
To: gdb-patches@sourceware.org
Subject: [RFA] Need post-processing of parameters for function calls in Ada
Date: Tue, 08 Jan 2008 14:37:00 -0000 [thread overview]
Message-ID: <20080108143622.GG24614@adacore.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1433 bytes --]
Hello,
Currently, calling an Ada function that takes an array does not work.
Let's take an example that uses a String:
(gdb) call call_me ("bonjour")
Invalid cast.
The problem in our case is that there are many different possible
representations for an array, and the representation that is passed
during the function call does not match what the function expects.
So we try a conversion and kaboum!
Because the conversion is so Ada specific (conversion from one form
of array to another), the conversion needs to be performed by the
Ada language. The attached patch adds a call to ada_convert_actuals()
inside call_function_by_hand when doing the call in Ada. We need
to do the conversion there rather than ahead of calling call_function_
by_hand because some conversions need to allocate some memory in
the inferior, and we do it in the stack area that this function sets up.
2008-01-08 Joel Brobecker <brobecker@adacore.com>
* infcall.c: #include "ada-lang.h".
(call_function_by_hand): Add post processing of function arguments
for Ada function calls.
* Makefile.in (infcall.o): Update dependencies.
I was able to write a testcase that reproduces the problem:
2008-01-08 Joel Brobecker <brobecker@adacore.com>
* gdb.ada/arrayparam: New test program.
* gdb.ada/arrayparam.exp: New testcase.
Tested on x86-linux, no regression.
OK to commit?
Thanks,
--
Joel
[-- Attachment #2: arrayparam.diff --]
[-- Type: text/plain, Size: 1317 bytes --]
Index: infcall.c
===================================================================
--- infcall.c (revision 98)
+++ infcall.c (revision 99)
@@ -34,6 +34,7 @@
#include "gdb_string.h"
#include "infcall.h"
#include "dummy-frame.h"
+#include "ada-lang.h"
/* NOTE: cagney/2003-04-16: What's the future of this code?
@@ -556,6 +557,9 @@ call_function_by_hand (struct value *fun
if (nargs < TYPE_NFIELDS (ftype))
error (_("too few arguments in function call"));
+ if (current_language->la_language == language_ada)
+ ada_convert_actuals (function, nargs, args, &sp);
+
{
int i;
for (i = nargs - 1; i >= 0; i--)
Index: Makefile.in
===================================================================
--- Makefile.in (revision 98)
+++ Makefile.in (revision 99)
@@ -2271,7 +2271,7 @@ ia64-tdep.o: ia64-tdep.c $(defs_h) $(inf
infcall.o: infcall.c $(defs_h) $(breakpoint_h) $(target_h) $(regcache_h) \
$(inferior_h) $(gdb_assert_h) $(block_h) $(gdbcore_h) $(language_h) \
$(objfiles_h) $(gdbcmd_h) $(command_h) $(gdb_string_h) $(infcall_h) \
- $(dummy_frame_h)
+ $(dummy_frame_h) $(ada_lang_h)
inf-child.o: inf-child.c $(defs_h) $(regcache_h) $(memattr_h) $(symtab_h) \
$(target_h) $(inferior_h) $(gdb_string_h)
infcmd.o: infcmd.c $(defs_h) $(gdb_string_h) $(symtab_h) $(gdbtypes_h) \
[-- Attachment #3: arrayparam-tc.diff --]
[-- Type: text/plain, Size: 5467 bytes --]
Index: gdb.ada/arrayparam.exp
===================================================================
--- gdb.ada/arrayparam.exp (revision 0)
+++ gdb.ada/arrayparam.exp (revision 100)
@@ -0,0 +1,61 @@
+# 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 "arrayparam"
+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"
+
+# Verify that a call to a function that takes an array as a parameter
+# works without problem.
+
+gdb_test "print call_me (\"bonjour\")" \
+ "void" \
+ "print call_me (\"bonjour\")"
+
+# Verify that the array was passed properly by checking the global
+# variables that Call_Me sets as side-effects.
+
+gdb_test "print first" \
+ "98 'b'" \
+ "print first after function call"
+
+gdb_test "print last" \
+ "114 'r'" \
+ "print lasta after function call"
+
+gdb_test "print length" \
+ "7" \
+ "print length after function call"
+
Index: gdb.ada/arrayparam/pck.adb
===================================================================
--- gdb.ada/arrayparam/pck.adb (revision 0)
+++ gdb.ada/arrayparam/pck.adb (revision 100)
@@ -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
+
+ procedure Call_Me (Str : String) is
+ begin
+ Length := Str'Length;
+ if Length > 0 then
+ First := Str (Str'First);
+ Last := Str (Str'Last);
+ end if;
+ end Call_Me;
+
+end Pck;
+
Index: gdb.ada/arrayparam/pck.ads
===================================================================
--- gdb.ada/arrayparam/pck.ads (revision 0)
+++ gdb.ada/arrayparam/pck.ads (revision 100)
@@ -0,0 +1,25 @@
+-- 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
+
+ First : Character := ASCII.NUL;
+ Last : Character := ASCII.NUL;
+ Length : Integer := 0;
+
+ procedure Call_Me (Str : String);
+
+end Pck;
+
Index: gdb.ada/arrayparam/foo.adb
===================================================================
--- gdb.ada/arrayparam/foo.adb (revision 0)
+++ gdb.ada/arrayparam/foo.adb (revision 100)
@@ -0,0 +1,26 @@
+-- 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_String : constant String := "Hello World";
+begin
+ First := ASCII.NUL;
+ Last := ASCII.NUL;
+ Length := -1;
+ Call_Me (My_String); -- STOP
+end Foo;
+
next reply other threads:[~2008-01-08 14:37 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-01-08 14:37 Joel Brobecker [this message]
2008-01-08 15:02 ` Daniel Jacobowitz
2008-01-08 15:29 ` Joel Brobecker
2008-01-08 15:37 ` Daniel Jacobowitz
2008-01-08 15:50 ` Joel Brobecker
2008-01-08 15:57 ` Daniel Jacobowitz
2008-01-08 16:14 ` Joel Brobecker
2008-01-08 16:19 ` Daniel Jacobowitz
2008-01-08 18:53 ` [RFA] Fix parameter coercing for Ada function calls (take 2) Joel Brobecker
2008-01-08 18:56 ` Daniel Jacobowitz
2008-01-08 19:34 ` Joel Brobecker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080108143622.GG24614@adacore.com \
--to=brobecker@adacore.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox