* [RFA/commit] DWARF: Mark all Ada functions as prototyped.
@ 2013-05-13 10:17 Joel Brobecker
2013-05-13 15:31 ` Tom Tromey
0 siblings, 1 reply; 15+ messages in thread
From: Joel Brobecker @ 2013-05-13 10:17 UTC (permalink / raw)
To: gdb-patches
Hello,
This makes sure that the types of the arguments are taken into account
when performing an inferior function call, and in particular
appropriatly converted to the correct type.
For instance, on x86_64-linux, with the following code:
procedure Set_Float (F : Float) is
begin
Global_Float := F;
end Set_Float;
The following sequence shows that Float arguments are incorrectly
passed (Ada's Float type is the equivalent of type "float" in C):
(gdb) call set_float (2.0)
(gdb) print global_float
$1 = 0.0
Putting a breakpoint inside set_float to inspect the value of
register xmm0 gives the first hint of the problem:
(gdb) p $xmm0
$2 = (v4_float => (0 => 0.0, 2.0, 0.0, 0.0),
v2_double => (0 => 2.0, 0.0),
[...]
It shows that the argument was passed as a double.
The code responsible for doing appropriate type conversions
for the arguments (value_arg_coerce) found that our function
was not prototyped, and thus could not use typing information
for the arguments. Instead, it defaulted to the value of "set
coerce-float-to-double", which by default is true, to determine
the argument type.
All functions in Ada are always prototyped, so there is no reason
to wait for the DW_AT_prototyped flag to be set. This patch adjusts
the dwarf2 function reader to follow what is already being done for
C++, Pascal, etc, and makes sure that all Ada functions are always
marked as prototyped.
gdb/ChangeLog:
* dwarf2read.c (read_subroutine_type): Mark all Ada functions
as prototyped.
gdb/testsuite/ChangeLog:
* gdb.ada/float_param: New testcase.
Tested on x86_64-linux, no regression. Fixes:
FAIL: gdb.ada/float_param.exp: print global_float
It seems relatively straightforward, but I will wait a couple of days
or approval before checking in...
Thank you,
--
Joel
---
gdb/dwarf2read.c | 3 +-
gdb/testsuite/gdb.ada/float_param.exp | 43 +++++++++++++++++++++++++++++
gdb/testsuite/gdb.ada/float_param/foo.adb | 23 +++++++++++++++
gdb/testsuite/gdb.ada/float_param/pck.adb | 35 +++++++++++++++++++++++
gdb/testsuite/gdb.ada/float_param/pck.ads | 31 +++++++++++++++++++++
5 files changed, 134 insertions(+), 1 deletion(-)
create mode 100644 gdb/testsuite/gdb.ada/float_param.exp
create mode 100644 gdb/testsuite/gdb.ada/float_param/foo.adb
create mode 100644 gdb/testsuite/gdb.ada/float_param/pck.adb
create mode 100644 gdb/testsuite/gdb.ada/float_param/pck.ads
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 2a5acf0..803e3ff 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -12626,9 +12626,10 @@ read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
ftype = lookup_function_type (type);
- /* All functions in C++, Pascal and Java have prototypes. */
+ /* All functions in Ada, C++, Pascal and Java have prototypes. */
attr = dwarf2_attr (die, DW_AT_prototyped, cu);
if ((attr && (DW_UNSND (attr) != 0))
+ || cu->language == language_ada
|| cu->language == language_cplus
|| cu->language == language_java
|| cu->language == language_pascal)
diff --git a/gdb/testsuite/gdb.ada/float_param.exp b/gdb/testsuite/gdb.ada/float_param.exp
new file mode 100644
index 0000000..f0a7eac
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/float_param.exp
@@ -0,0 +1,43 @@
+# Copyright 2013 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/>.
+
+load_lib "ada.exp"
+
+if { [skip_ada_tests] } { return -1 }
+
+standard_ada_testfile foo
+
+if {[gdb_compile_ada "${srcfile}" "${binfile}" executable {debug}] != ""} {
+ return -1
+}
+
+clean_restart ${testfile}
+
+set bp_location [gdb_get_line_number "START" ${testdir}/foo.adb]
+runto "foo.adb:$bp_location"
+
+gdb_test_no_output "call set_float(2.0)"
+gdb_test "print global_float" \
+ " = 2\\.0"
+
+gdb_test_no_output "call set_double(1, 3.0)"
+gdb_test "print global_double" \
+ " = 3\\.0"
+
+gdb_test_no_output "call set_long_double(1, global_small_struct, 4.0)"
+gdb_test "print global_long_double" \
+ " = 4\\.0"
+
+
diff --git a/gdb/testsuite/gdb.ada/float_param/foo.adb b/gdb/testsuite/gdb.ada/float_param/foo.adb
new file mode 100644
index 0000000..2b08681
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/float_param/foo.adb
@@ -0,0 +1,23 @@
+-- Copyright 2013 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
+begin
+ Set_Float (1.0); -- START
+ Set_Double (1, 1.0);
+ Set_Long_Double (1, (I => 2), 1.0);
+end Foo;
diff --git a/gdb/testsuite/gdb.ada/float_param/pck.adb b/gdb/testsuite/gdb.ada/float_param/pck.adb
new file mode 100644
index 0000000..18967e4
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/float_param/pck.adb
@@ -0,0 +1,35 @@
+-- Copyright 2013 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 Set_Float (F : Float) is
+ begin
+ Global_Float := F;
+ end Set_Float;
+
+ procedure Set_Double (Dummy : Integer; D : Long_Float) is
+ begin
+ Global_Double := D;
+ end Set_Double;
+
+ procedure Set_Long_Double (Dummy : Integer;
+ DS : Small_Struct;
+ LD : Long_Long_Float) is
+ begin
+ Global_Long_Double := LD;
+ end Set_Long_Double;
+
+end Pck;
diff --git a/gdb/testsuite/gdb.ada/float_param/pck.ads b/gdb/testsuite/gdb.ada/float_param/pck.ads
new file mode 100644
index 0000000..093a32d
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/float_param/pck.ads
@@ -0,0 +1,31 @@
+-- Copyright 2013 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
+ Global_Float : Float := 0.0;
+ Global_Double : Long_Float := 0.0;
+ Global_Long_Double : Long_Long_Float := 0.0;
+
+ type Small_Struct is record
+ I : Integer;
+ end record;
+ Global_Small_Struct : Small_Struct := (I => 0);
+
+ procedure Set_Float (F : Float);
+ procedure Set_Double (Dummy : Integer; D : Long_Float);
+ procedure Set_Long_Double (Dummy : Integer;
+ DS: Small_Struct;
+ LD : Long_Long_Float);
+end Pck;
--
1.7.10.4
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: [RFA/commit] DWARF: Mark all Ada functions as prototyped. 2013-05-13 10:17 [RFA/commit] DWARF: Mark all Ada functions as prototyped Joel Brobecker @ 2013-05-13 15:31 ` Tom Tromey 2013-05-15 13:19 ` Joel Brobecker 0 siblings, 1 reply; 15+ messages in thread From: Tom Tromey @ 2013-05-13 15:31 UTC (permalink / raw) To: Joel Brobecker; +Cc: gdb-patches >>>>> "Joel" == Joel Brobecker <brobecker@adacore.com> writes: Joel> This makes sure that the types of the arguments are taken into account Joel> when performing an inferior function call, and in particular Joel> appropriatly converted to the correct type. DWARF implies that this attribute is only meaningful for C. And GCC emits it only for C89 (though GCC pretends that all variants of C are C89... oops): static inline void add_prototyped_attribute (dw_die_ref die, tree func_type) { if (get_AT_unsigned (comp_unit_die (), DW_AT_language) == DW_LANG_C89 && prototype_p (func_type)) add_AT_flag (die, DW_AT_prototyped, 1); } Joel> - /* All functions in C++, Pascal and Java have prototypes. */ Joel> + /* All functions in Ada, C++, Pascal and Java have prototypes. */ Joel> attr = dwarf2_attr (die, DW_AT_prototyped, cu); Joel> if ((attr && (DW_UNSND (attr) != 0)) Joel> + || cu->language == language_ada Joel> || cu->language == language_cplus Joel> || cu->language == language_java Joel> || cu->language == language_pascal) ... so I suggest instead inverting the sense here and rewriting it to check just for languages that are "C-like" -- DW_LANG_C89, DW_LANG_C, DW_LANG_ObjC, DW_LANG_C99, and DW_LANG_UPC. What do you think? Tom ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [RFA/commit] DWARF: Mark all Ada functions as prototyped. 2013-05-13 15:31 ` Tom Tromey @ 2013-05-15 13:19 ` Joel Brobecker 2013-05-15 13:20 ` [RFA/dwarf 1/2]: Add DW_LANG_UPC support in set_cu_language Joel Brobecker 2013-05-15 13:20 ` [RFA/dwarf 2/2] Mark all functions as prototyped except C functions Joel Brobecker 0 siblings, 2 replies; 15+ messages in thread From: Joel Brobecker @ 2013-05-15 13:19 UTC (permalink / raw) To: gdb-patches; +Cc: Tom Tromey Hi Tom, > DWARF implies that this attribute is only meaningful for C. And GCC > emits it only for C89 [...] Indeed, upon double-checking the DWARF standard, it does seem so. > ... so I suggest instead inverting the sense here and rewriting it to > check just for languages that are "C-like" -- DW_LANG_C89, DW_LANG_C, > DW_LANG_ObjC, DW_LANG_C99, and DW_LANG_UPC. > > What do you think? I hesitated a bit before doing so, because I think that the concept of prototyped-or-not might be language-dependent. But, in the end, I think that language other than C are rarely going to be in the same category as C (or so I hope!), and we can always adjust the logic accordingly anyway. I don't know if we have access to the CU's DW_AT_language attribute at this point anymore, but it seems simpler to test for language_c in any case. There is still the question of language_minimal, auto, etc, and even maybe asm. For now, I just put them in the same bag as non-C languages, but it's easy to adjust the patch. I reviewed the list of languages from the DWARF 4 standard, and noticed that we did not set the language for DW_LANG_UPC, so I added that as a first patch. Hence this RFA now becomes a two-patches RFA: [dwarf]: Add DW_LANG_UPC support in set_cu_language. [dwarf] Mark all functions as prototyped except C Let me know what you think... Thanks, -- Joel ^ permalink raw reply [flat|nested] 15+ messages in thread
* [RFA/dwarf 1/2]: Add DW_LANG_UPC support in set_cu_language. 2013-05-15 13:19 ` Joel Brobecker @ 2013-05-15 13:20 ` Joel Brobecker 2013-05-15 15:04 ` Tom Tromey 2013-05-15 13:20 ` [RFA/dwarf 2/2] Mark all functions as prototyped except C functions Joel Brobecker 1 sibling, 1 reply; 15+ messages in thread From: Joel Brobecker @ 2013-05-15 13:20 UTC (permalink / raw) To: gdb-patches; +Cc: Tom Tromey Hello, Pretty straightforward patch that could probably be checked in as obvious, but since 2/2 is an RFA, no real harm in getting more eyes on it. gdb/ChangeLog: * dwarf2read.c (set_cu_language): Add DW_LANG_UPC handling. Tested on x86_64-linux. No regression. OK to commit? Thanks, -- Joel --- gdb/dwarf2read.c | 1 + 1 file changed, 1 insertion(+) diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index ed5aea3..a17cd9d 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -14983,6 +14983,7 @@ set_cu_language (unsigned int lang, struct dwarf2_cu *cu) case DW_LANG_C89: case DW_LANG_C99: case DW_LANG_C: + case DW_LANG_UPC: cu->language = language_c; break; case DW_LANG_C_plus_plus: -- 1.7.10.4 ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [RFA/dwarf 1/2]: Add DW_LANG_UPC support in set_cu_language. 2013-05-15 13:20 ` [RFA/dwarf 1/2]: Add DW_LANG_UPC support in set_cu_language Joel Brobecker @ 2013-05-15 15:04 ` Tom Tromey 2013-05-16 7:40 ` Checked in: " Joel Brobecker 0 siblings, 1 reply; 15+ messages in thread From: Tom Tromey @ 2013-05-15 15:04 UTC (permalink / raw) To: Joel Brobecker; +Cc: gdb-patches >>>>> "Joel" == Joel Brobecker <brobecker@adacore.com> writes: Joel> * dwarf2read.c (set_cu_language): Add DW_LANG_UPC handling. Joel> Tested on x86_64-linux. No regression. OK to commit? Looks good to me. Tom ^ permalink raw reply [flat|nested] 15+ messages in thread
* Checked in: [RFA/dwarf 1/2]: Add DW_LANG_UPC support in set_cu_language. 2013-05-15 15:04 ` Tom Tromey @ 2013-05-16 7:40 ` Joel Brobecker 0 siblings, 0 replies; 15+ messages in thread From: Joel Brobecker @ 2013-05-16 7:40 UTC (permalink / raw) To: Tom Tromey; +Cc: gdb-patches > Joel> * dwarf2read.c (set_cu_language): Add DW_LANG_UPC handling. > > Joel> Tested on x86_64-linux. No regression. OK to commit? > > Looks good to me. Thanks, Tom. Checked in. -- Joel ^ permalink raw reply [flat|nested] 15+ messages in thread
* [RFA/dwarf 2/2] Mark all functions as prototyped except C functions. 2013-05-15 13:19 ` Joel Brobecker 2013-05-15 13:20 ` [RFA/dwarf 1/2]: Add DW_LANG_UPC support in set_cu_language Joel Brobecker @ 2013-05-15 13:20 ` Joel Brobecker 2013-05-15 15:11 ` Tom Tromey 1 sibling, 1 reply; 15+ messages in thread From: Joel Brobecker @ 2013-05-15 13:20 UTC (permalink / raw) To: gdb-patches; +Cc: Tom Tromey Hello, This is the part of the patch series that inverts the logic determining whether or not a function should be marked as prototyped. I took this opportunity to factorize a bit the code setting the PROTOTYPED flag. Although the gain is very marginal, I think it helps because a large block now becomes very small, thus showing its intent a little more clearly. Below is the adjusted problem description which will be part of the commit RH. ---- This makes sure that the types of the arguments are taken into account when performing an inferior function call to a non-C function. In particular, this makes sure that the arguments are appropriatly converted to the correct type. For instance, on x86_64-linux, with the following Ada code: procedure Set_Float (F : Float) is begin Global_Float := F; end Set_Float; The following sequence shows that Float arguments are incorrectly passed (Ada's Float type is the equivalent of type "float" in C): (gdb) call set_float (2.0) (gdb) print global_float $1 = 0.0 Putting a breakpoint inside set_float to inspect the value of register xmm0 gives the first hint of the problem: (gdb) p $xmm0 $2 = (v4_float => (0 => 0.0, 2.0, 0.0, 0.0), v2_double => (0 => 2.0, 0.0), [...] It shows that the argument was passed as a double. The code responsible for doing appropriate type conversions for the arguments (value_arg_coerce) found that our function was not prototyped, and thus could not use typing information for the arguments. Instead, it defaulted to the value of "set coerce-float-to-double", which by default is true, to determine the argument type. The DWARF standard implies that the DW_AT_prototyped is only meaningful for C. So there is no reason to expect this flag to be set for any other language. We assume, instead, that functions are always prototyped for all non-C languages... gdb/ChangeLog: * dwarf2read.c (prototyped_function_p): New function. (read_subroutine_type): Use it. gdb/testsuite/ChangeLog: * gdb.ada/float_param: New testcase. Tested on x86_64-linux. No regression. OK to commit? -- Joel --- gdb/dwarf2read.c | 41 +++++++++++++++++++-------- gdb/testsuite/gdb.ada/float_param.exp | 43 +++++++++++++++++++++++++++++ gdb/testsuite/gdb.ada/float_param/foo.adb | 23 +++++++++++++++ gdb/testsuite/gdb.ada/float_param/pck.adb | 35 +++++++++++++++++++++++ gdb/testsuite/gdb.ada/float_param/pck.ads | 31 +++++++++++++++++++++ 5 files changed, 161 insertions(+), 12 deletions(-) create mode 100644 gdb/testsuite/gdb.ada/float_param.exp create mode 100644 gdb/testsuite/gdb.ada/float_param/foo.adb create mode 100644 gdb/testsuite/gdb.ada/float_param/pck.adb create mode 100644 gdb/testsuite/gdb.ada/float_param/pck.ads diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index a17cd9d..be6644b 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -12600,6 +12600,34 @@ read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu) return set_die_type (die, type, cu); } +/* Assuming that DIE corresponds to a function, returns nonzero + if the function is prototyped. */ + +static int +prototyped_function_p (struct die_info *die, struct dwarf2_cu *cu) +{ + struct attribute *attr; + + attr = dwarf2_attr (die, DW_AT_prototyped, cu); + if (attr && (DW_UNSND (attr) != 0)) + return 1; + + /* The DWARF standard implies that the DW_AT_prototyped attribute + is only meaninful to C. So assume that non-C functions are + always prototyped. */ + if (cu->language != language_c) + return 1; + + /* RealView does not emit DW_AT_prototyped. We can not distinguish + prototyped and unprototyped functions; default to prototyped, + since that is more common in modern code (and RealView warns + about unprototyped functions). */ + if (producer_is_realview (cu->producer)) + return 1; + + return 0; +} + /* Handle DIES due to C code like: struct foo @@ -12627,18 +12655,7 @@ read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu) ftype = lookup_function_type (type); - /* All functions in C++, Pascal and Java have prototypes. */ - attr = dwarf2_attr (die, DW_AT_prototyped, cu); - if ((attr && (DW_UNSND (attr) != 0)) - || cu->language == language_cplus - || cu->language == language_java - || cu->language == language_pascal) - TYPE_PROTOTYPED (ftype) = 1; - else if (producer_is_realview (cu->producer)) - /* RealView does not emit DW_AT_prototyped. We can not - distinguish prototyped and unprototyped functions; default to - prototyped, since that is more common in modern code (and - RealView warns about unprototyped functions). */ + if (prototyped_function_p (die, cu)) TYPE_PROTOTYPED (ftype) = 1; /* Store the calling convention in the type if it's available in diff --git a/gdb/testsuite/gdb.ada/float_param.exp b/gdb/testsuite/gdb.ada/float_param.exp new file mode 100644 index 0000000..f0a7eac --- /dev/null +++ b/gdb/testsuite/gdb.ada/float_param.exp @@ -0,0 +1,43 @@ +# Copyright 2013 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/>. + +load_lib "ada.exp" + +if { [skip_ada_tests] } { return -1 } + +standard_ada_testfile foo + +if {[gdb_compile_ada "${srcfile}" "${binfile}" executable {debug}] != ""} { + return -1 +} + +clean_restart ${testfile} + +set bp_location [gdb_get_line_number "START" ${testdir}/foo.adb] +runto "foo.adb:$bp_location" + +gdb_test_no_output "call set_float(2.0)" +gdb_test "print global_float" \ + " = 2\\.0" + +gdb_test_no_output "call set_double(1, 3.0)" +gdb_test "print global_double" \ + " = 3\\.0" + +gdb_test_no_output "call set_long_double(1, global_small_struct, 4.0)" +gdb_test "print global_long_double" \ + " = 4\\.0" + + diff --git a/gdb/testsuite/gdb.ada/float_param/foo.adb b/gdb/testsuite/gdb.ada/float_param/foo.adb new file mode 100644 index 0000000..2b08681 --- /dev/null +++ b/gdb/testsuite/gdb.ada/float_param/foo.adb @@ -0,0 +1,23 @@ +-- Copyright 2013 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 +begin + Set_Float (1.0); -- START + Set_Double (1, 1.0); + Set_Long_Double (1, (I => 2), 1.0); +end Foo; diff --git a/gdb/testsuite/gdb.ada/float_param/pck.adb b/gdb/testsuite/gdb.ada/float_param/pck.adb new file mode 100644 index 0000000..18967e4 --- /dev/null +++ b/gdb/testsuite/gdb.ada/float_param/pck.adb @@ -0,0 +1,35 @@ +-- Copyright 2013 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 Set_Float (F : Float) is + begin + Global_Float := F; + end Set_Float; + + procedure Set_Double (Dummy : Integer; D : Long_Float) is + begin + Global_Double := D; + end Set_Double; + + procedure Set_Long_Double (Dummy : Integer; + DS : Small_Struct; + LD : Long_Long_Float) is + begin + Global_Long_Double := LD; + end Set_Long_Double; + +end Pck; diff --git a/gdb/testsuite/gdb.ada/float_param/pck.ads b/gdb/testsuite/gdb.ada/float_param/pck.ads new file mode 100644 index 0000000..093a32d --- /dev/null +++ b/gdb/testsuite/gdb.ada/float_param/pck.ads @@ -0,0 +1,31 @@ +-- Copyright 2013 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 + Global_Float : Float := 0.0; + Global_Double : Long_Float := 0.0; + Global_Long_Double : Long_Long_Float := 0.0; + + type Small_Struct is record + I : Integer; + end record; + Global_Small_Struct : Small_Struct := (I => 0); + + procedure Set_Float (F : Float); + procedure Set_Double (Dummy : Integer; D : Long_Float); + procedure Set_Long_Double (Dummy : Integer; + DS: Small_Struct; + LD : Long_Long_Float); +end Pck; -- 1.7.10.4 ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [RFA/dwarf 2/2] Mark all functions as prototyped except C functions. 2013-05-15 13:20 ` [RFA/dwarf 2/2] Mark all functions as prototyped except C functions Joel Brobecker @ 2013-05-15 15:11 ` Tom Tromey 2013-05-16 7:38 ` Joel Brobecker 0 siblings, 1 reply; 15+ messages in thread From: Tom Tromey @ 2013-05-15 15:11 UTC (permalink / raw) To: Joel Brobecker; +Cc: gdb-patches >>>>> "Joel" == Joel Brobecker <brobecker@adacore.com> writes: Joel> + /* The DWARF standard implies that the DW_AT_prototyped attribute Joel> + is only meaninful to C. So assume that non-C functions are Joel> + always prototyped. */ Joel> + if (cu->language != language_c) Joel> + return 1; Can Objective C have un-prototyped functions? I don't know. But if it can, then it should be checked here. Tom ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [RFA/dwarf 2/2] Mark all functions as prototyped except C functions. 2013-05-15 15:11 ` Tom Tromey @ 2013-05-16 7:38 ` Joel Brobecker 2013-05-16 8:14 ` Joel Brobecker 2013-05-16 17:52 ` Stan Shebs 0 siblings, 2 replies; 15+ messages in thread From: Joel Brobecker @ 2013-05-16 7:38 UTC (permalink / raw) To: Tom Tromey; +Cc: gdb-patches [-- Attachment #1: Type: text/plain, Size: 825 bytes --] > Joel> + /* The DWARF standard implies that the DW_AT_prototyped attribute > Joel> + is only meaninful to C. So assume that non-C functions are > Joel> + always prototyped. */ > Joel> + if (cu->language != language_c) > Joel> + return 1; > > Can Objective C have un-prototyped functions? > I don't know. But if it can, then it should be checked here. Hmmm, I am not 100% sure, but some internet searches suggest that this is probably true. Thanks! Attached is the updated patch, just adding language_objc to the condition, and adjusting the comment accordingly. gdb/ChangeLog: * dwarf2read.c (prototyped_function_p): New function. (read_subroutine_type): Use it. gdb/testsuite/ChangeLog: * gdb.ada/float_param: New testcase. Re-tested on x86_64-linux, no regression. -- Joel [-- Attachment #2: 0001-dwarf-Mark-all-functions-as-prototyped-except-C-func.patch --] [-- Type: text/x-diff, Size: 10245 bytes --] From 0dd7ad8c588f4a2fdf47616c06c320ed56685fd4 Mon Sep 17 00:00:00 2001 From: Joel Brobecker <brobecker@adacore.com> Date: Tue, 15 Jan 2013 11:51:39 +0400 Subject: [PATCH] [dwarf] Mark all functions as prototyped except C functions. This makes sure that the types of the arguments are taken into account when performing an inferior function call to a non-C (or C-like) function. In particular, this makes sure that the arguments are appropriatly converted to the correct type. For instance, on x86_64-linux, with the following Ada code: procedure Set_Float (F : Float) is begin Global_Float := F; end Set_Float; The following sequence shows that Float arguments are incorrectly passed (Ada's Float type is the equivalent of type "float" in C): (gdb) call set_float (2.0) (gdb) print global_float $1 = 0.0 Putting a breakpoint inside set_float to inspect the value of register xmm0 gives the first hint of the problem: (gdb) p $xmm0 $2 = (v4_float => (0 => 0.0, 2.0, 0.0, 0.0), v2_double => (0 => 2.0, 0.0), [...] It shows that the argument was passed as a double. The code responsible for doing appropriate type conversions for the arguments (value_arg_coerce) found that our function was not prototyped, and thus could not use typing information for the arguments. Instead, it defaulted to the value of "set coerce-float-to-double", which by default is true, to determine the argument type. This patch fixes the problem by setting the PROTOTYPE flag for all functions of any language except C and Objective C. gdb/ChangeLog: * dwarf2read.c (prototyped_function_p): New function. (read_subroutine_type): Use it. gdb/testsuite/ChangeLog: * gdb.ada/float_param: New testcase. --- gdb/dwarf2read.c | 44 +++++++++++++++++++++-------- gdb/testsuite/gdb.ada/float_param.exp | 43 ++++++++++++++++++++++++++++ gdb/testsuite/gdb.ada/float_param/foo.adb | 23 +++++++++++++++ gdb/testsuite/gdb.ada/float_param/pck.adb | 35 +++++++++++++++++++++++ gdb/testsuite/gdb.ada/float_param/pck.ads | 31 ++++++++++++++++++++ 5 files changed, 164 insertions(+), 12 deletions(-) create mode 100644 gdb/testsuite/gdb.ada/float_param.exp create mode 100644 gdb/testsuite/gdb.ada/float_param/foo.adb create mode 100644 gdb/testsuite/gdb.ada/float_param/pck.adb create mode 100644 gdb/testsuite/gdb.ada/float_param/pck.ads diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index a17cd9d..748d892 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -12600,6 +12600,37 @@ read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu) return set_die_type (die, type, cu); } +/* Assuming that DIE corresponds to a function, returns nonzero + if the function is prototyped. */ + +static int +prototyped_function_p (struct die_info *die, struct dwarf2_cu *cu) +{ + struct attribute *attr; + + attr = dwarf2_attr (die, DW_AT_prototyped, cu); + if (attr && (DW_UNSND (attr) != 0)) + return 1; + + /* The DWARF standard implies that the DW_AT_prototyped attribute + is only meaninful for C, but the concept also extends to other + languages that allow unprototyped functions (Eg: Objective C). + For all other languages, asssume that functions are always + prototyped. */ + if (cu->language != language_c + && cu->language != language_objc) + return 1; + + /* RealView does not emit DW_AT_prototyped. We can not distinguish + prototyped and unprototyped functions; default to prototyped, + since that is more common in modern code (and RealView warns + about unprototyped functions). */ + if (producer_is_realview (cu->producer)) + return 1; + + return 0; +} + /* Handle DIES due to C code like: struct foo @@ -12627,18 +12658,7 @@ read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu) ftype = lookup_function_type (type); - /* All functions in C++, Pascal and Java have prototypes. */ - attr = dwarf2_attr (die, DW_AT_prototyped, cu); - if ((attr && (DW_UNSND (attr) != 0)) - || cu->language == language_cplus - || cu->language == language_java - || cu->language == language_pascal) - TYPE_PROTOTYPED (ftype) = 1; - else if (producer_is_realview (cu->producer)) - /* RealView does not emit DW_AT_prototyped. We can not - distinguish prototyped and unprototyped functions; default to - prototyped, since that is more common in modern code (and - RealView warns about unprototyped functions). */ + if (prototyped_function_p (die, cu)) TYPE_PROTOTYPED (ftype) = 1; /* Store the calling convention in the type if it's available in diff --git a/gdb/testsuite/gdb.ada/float_param.exp b/gdb/testsuite/gdb.ada/float_param.exp new file mode 100644 index 0000000..f0a7eac --- /dev/null +++ b/gdb/testsuite/gdb.ada/float_param.exp @@ -0,0 +1,43 @@ +# Copyright 2013 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/>. + +load_lib "ada.exp" + +if { [skip_ada_tests] } { return -1 } + +standard_ada_testfile foo + +if {[gdb_compile_ada "${srcfile}" "${binfile}" executable {debug}] != ""} { + return -1 +} + +clean_restart ${testfile} + +set bp_location [gdb_get_line_number "START" ${testdir}/foo.adb] +runto "foo.adb:$bp_location" + +gdb_test_no_output "call set_float(2.0)" +gdb_test "print global_float" \ + " = 2\\.0" + +gdb_test_no_output "call set_double(1, 3.0)" +gdb_test "print global_double" \ + " = 3\\.0" + +gdb_test_no_output "call set_long_double(1, global_small_struct, 4.0)" +gdb_test "print global_long_double" \ + " = 4\\.0" + + diff --git a/gdb/testsuite/gdb.ada/float_param/foo.adb b/gdb/testsuite/gdb.ada/float_param/foo.adb new file mode 100644 index 0000000..2b08681 --- /dev/null +++ b/gdb/testsuite/gdb.ada/float_param/foo.adb @@ -0,0 +1,23 @@ +-- Copyright 2013 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 +begin + Set_Float (1.0); -- START + Set_Double (1, 1.0); + Set_Long_Double (1, (I => 2), 1.0); +end Foo; diff --git a/gdb/testsuite/gdb.ada/float_param/pck.adb b/gdb/testsuite/gdb.ada/float_param/pck.adb new file mode 100644 index 0000000..18967e4 --- /dev/null +++ b/gdb/testsuite/gdb.ada/float_param/pck.adb @@ -0,0 +1,35 @@ +-- Copyright 2013 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 Set_Float (F : Float) is + begin + Global_Float := F; + end Set_Float; + + procedure Set_Double (Dummy : Integer; D : Long_Float) is + begin + Global_Double := D; + end Set_Double; + + procedure Set_Long_Double (Dummy : Integer; + DS : Small_Struct; + LD : Long_Long_Float) is + begin + Global_Long_Double := LD; + end Set_Long_Double; + +end Pck; diff --git a/gdb/testsuite/gdb.ada/float_param/pck.ads b/gdb/testsuite/gdb.ada/float_param/pck.ads new file mode 100644 index 0000000..093a32d --- /dev/null +++ b/gdb/testsuite/gdb.ada/float_param/pck.ads @@ -0,0 +1,31 @@ +-- Copyright 2013 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 + Global_Float : Float := 0.0; + Global_Double : Long_Float := 0.0; + Global_Long_Double : Long_Long_Float := 0.0; + + type Small_Struct is record + I : Integer; + end record; + Global_Small_Struct : Small_Struct := (I => 0); + + procedure Set_Float (F : Float); + procedure Set_Double (Dummy : Integer; D : Long_Float); + procedure Set_Long_Double (Dummy : Integer; + DS: Small_Struct; + LD : Long_Long_Float); +end Pck; -- 1.7.10.4 ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [RFA/dwarf 2/2] Mark all functions as prototyped except C functions. 2013-05-16 7:38 ` Joel Brobecker @ 2013-05-16 8:14 ` Joel Brobecker 2013-05-16 13:22 ` Tom Tromey 2013-05-16 17:52 ` Stan Shebs 1 sibling, 1 reply; 15+ messages in thread From: Joel Brobecker @ 2013-05-16 8:14 UTC (permalink / raw) To: Tom Tromey; +Cc: gdb-patches [-- Attachment #1: Type: text/plain, Size: 591 bytes --] > Hmmm, I am not 100% sure, but some internet searches suggest > that this is probably true. Thanks! Attached is the updated patch, > just adding language_objc to the condition, and adjusting the > comment accordingly. > > gdb/ChangeLog: > > * dwarf2read.c (prototyped_function_p): New function. > (read_subroutine_type): Use it. > > gdb/testsuite/ChangeLog: > > * gdb.ada/float_param: New testcase. > > Re-tested on x86_64-linux, no regression. Pierre noticed a small typo in "asssume" (thank you!), so here is a new version with the typo corrected. -- Joel [-- Attachment #2: 0001-dwarf-Mark-all-functions-as-prototyped-except-C-func.patch --] [-- Type: text/x-diff, Size: 10244 bytes --] From 81149f0929162c08bbaa0686ca5d9285542a1e87 Mon Sep 17 00:00:00 2001 From: Joel Brobecker <brobecker@adacore.com> Date: Tue, 15 Jan 2013 11:51:39 +0400 Subject: [PATCH] [dwarf] Mark all functions as prototyped except C functions. This makes sure that the types of the arguments are taken into account when performing an inferior function call to a non-C (or C-like) function. In particular, this makes sure that the arguments are appropriatly converted to the correct type. For instance, on x86_64-linux, with the following Ada code: procedure Set_Float (F : Float) is begin Global_Float := F; end Set_Float; The following sequence shows that Float arguments are incorrectly passed (Ada's Float type is the equivalent of type "float" in C): (gdb) call set_float (2.0) (gdb) print global_float $1 = 0.0 Putting a breakpoint inside set_float to inspect the value of register xmm0 gives the first hint of the problem: (gdb) p $xmm0 $2 = (v4_float => (0 => 0.0, 2.0, 0.0, 0.0), v2_double => (0 => 2.0, 0.0), [...] It shows that the argument was passed as a double. The code responsible for doing appropriate type conversions for the arguments (value_arg_coerce) found that our function was not prototyped, and thus could not use typing information for the arguments. Instead, it defaulted to the value of "set coerce-float-to-double", which by default is true, to determine the argument type. This patch fixes the problem by setting the PROTOTYPE flag for all functions of any language except C and Objective C. gdb/ChangeLog: * dwarf2read.c (prototyped_function_p): New function. (read_subroutine_type): Use it. gdb/testsuite/ChangeLog: * gdb.ada/float_param: New testcase. --- gdb/dwarf2read.c | 44 +++++++++++++++++++++-------- gdb/testsuite/gdb.ada/float_param.exp | 43 ++++++++++++++++++++++++++++ gdb/testsuite/gdb.ada/float_param/foo.adb | 23 +++++++++++++++ gdb/testsuite/gdb.ada/float_param/pck.adb | 35 +++++++++++++++++++++++ gdb/testsuite/gdb.ada/float_param/pck.ads | 31 ++++++++++++++++++++ 5 files changed, 164 insertions(+), 12 deletions(-) create mode 100644 gdb/testsuite/gdb.ada/float_param.exp create mode 100644 gdb/testsuite/gdb.ada/float_param/foo.adb create mode 100644 gdb/testsuite/gdb.ada/float_param/pck.adb create mode 100644 gdb/testsuite/gdb.ada/float_param/pck.ads diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index a17cd9d..6a12093 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -12600,6 +12600,37 @@ read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu) return set_die_type (die, type, cu); } +/* Assuming that DIE corresponds to a function, returns nonzero + if the function is prototyped. */ + +static int +prototyped_function_p (struct die_info *die, struct dwarf2_cu *cu) +{ + struct attribute *attr; + + attr = dwarf2_attr (die, DW_AT_prototyped, cu); + if (attr && (DW_UNSND (attr) != 0)) + return 1; + + /* The DWARF standard implies that the DW_AT_prototyped attribute + is only meaninful for C, but the concept also extends to other + languages that allow unprototyped functions (Eg: Objective C). + For all other languages, assume that functions are always + prototyped. */ + if (cu->language != language_c + && cu->language != language_objc) + return 1; + + /* RealView does not emit DW_AT_prototyped. We can not distinguish + prototyped and unprototyped functions; default to prototyped, + since that is more common in modern code (and RealView warns + about unprototyped functions). */ + if (producer_is_realview (cu->producer)) + return 1; + + return 0; +} + /* Handle DIES due to C code like: struct foo @@ -12627,18 +12658,7 @@ read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu) ftype = lookup_function_type (type); - /* All functions in C++, Pascal and Java have prototypes. */ - attr = dwarf2_attr (die, DW_AT_prototyped, cu); - if ((attr && (DW_UNSND (attr) != 0)) - || cu->language == language_cplus - || cu->language == language_java - || cu->language == language_pascal) - TYPE_PROTOTYPED (ftype) = 1; - else if (producer_is_realview (cu->producer)) - /* RealView does not emit DW_AT_prototyped. We can not - distinguish prototyped and unprototyped functions; default to - prototyped, since that is more common in modern code (and - RealView warns about unprototyped functions). */ + if (prototyped_function_p (die, cu)) TYPE_PROTOTYPED (ftype) = 1; /* Store the calling convention in the type if it's available in diff --git a/gdb/testsuite/gdb.ada/float_param.exp b/gdb/testsuite/gdb.ada/float_param.exp new file mode 100644 index 0000000..f0a7eac --- /dev/null +++ b/gdb/testsuite/gdb.ada/float_param.exp @@ -0,0 +1,43 @@ +# Copyright 2013 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/>. + +load_lib "ada.exp" + +if { [skip_ada_tests] } { return -1 } + +standard_ada_testfile foo + +if {[gdb_compile_ada "${srcfile}" "${binfile}" executable {debug}] != ""} { + return -1 +} + +clean_restart ${testfile} + +set bp_location [gdb_get_line_number "START" ${testdir}/foo.adb] +runto "foo.adb:$bp_location" + +gdb_test_no_output "call set_float(2.0)" +gdb_test "print global_float" \ + " = 2\\.0" + +gdb_test_no_output "call set_double(1, 3.0)" +gdb_test "print global_double" \ + " = 3\\.0" + +gdb_test_no_output "call set_long_double(1, global_small_struct, 4.0)" +gdb_test "print global_long_double" \ + " = 4\\.0" + + diff --git a/gdb/testsuite/gdb.ada/float_param/foo.adb b/gdb/testsuite/gdb.ada/float_param/foo.adb new file mode 100644 index 0000000..2b08681 --- /dev/null +++ b/gdb/testsuite/gdb.ada/float_param/foo.adb @@ -0,0 +1,23 @@ +-- Copyright 2013 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 +begin + Set_Float (1.0); -- START + Set_Double (1, 1.0); + Set_Long_Double (1, (I => 2), 1.0); +end Foo; diff --git a/gdb/testsuite/gdb.ada/float_param/pck.adb b/gdb/testsuite/gdb.ada/float_param/pck.adb new file mode 100644 index 0000000..18967e4 --- /dev/null +++ b/gdb/testsuite/gdb.ada/float_param/pck.adb @@ -0,0 +1,35 @@ +-- Copyright 2013 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 Set_Float (F : Float) is + begin + Global_Float := F; + end Set_Float; + + procedure Set_Double (Dummy : Integer; D : Long_Float) is + begin + Global_Double := D; + end Set_Double; + + procedure Set_Long_Double (Dummy : Integer; + DS : Small_Struct; + LD : Long_Long_Float) is + begin + Global_Long_Double := LD; + end Set_Long_Double; + +end Pck; diff --git a/gdb/testsuite/gdb.ada/float_param/pck.ads b/gdb/testsuite/gdb.ada/float_param/pck.ads new file mode 100644 index 0000000..093a32d --- /dev/null +++ b/gdb/testsuite/gdb.ada/float_param/pck.ads @@ -0,0 +1,31 @@ +-- Copyright 2013 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 + Global_Float : Float := 0.0; + Global_Double : Long_Float := 0.0; + Global_Long_Double : Long_Long_Float := 0.0; + + type Small_Struct is record + I : Integer; + end record; + Global_Small_Struct : Small_Struct := (I => 0); + + procedure Set_Float (F : Float); + procedure Set_Double (Dummy : Integer; D : Long_Float); + procedure Set_Long_Double (Dummy : Integer; + DS: Small_Struct; + LD : Long_Long_Float); +end Pck; -- 1.7.10.4 ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [RFA/dwarf 2/2] Mark all functions as prototyped except C functions. 2013-05-16 8:14 ` Joel Brobecker @ 2013-05-16 13:22 ` Tom Tromey 2013-05-17 5:07 ` Joel Brobecker 0 siblings, 1 reply; 15+ messages in thread From: Tom Tromey @ 2013-05-16 13:22 UTC (permalink / raw) To: Joel Brobecker; +Cc: gdb-patches >>>>> "Joel" == Joel Brobecker <brobecker@adacore.com> writes: Joel> Pierre noticed a small typo in "asssume" (thank you!), so here is Joel> a new version with the typo corrected. Sorry, one last question -- do we need an exclusion for OpenCL as well? OpenCL is based on C99. Tom ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [RFA/dwarf 2/2] Mark all functions as prototyped except C functions. 2013-05-16 13:22 ` Tom Tromey @ 2013-05-17 5:07 ` Joel Brobecker 2013-05-17 15:06 ` Tom Tromey 0 siblings, 1 reply; 15+ messages in thread From: Joel Brobecker @ 2013-05-17 5:07 UTC (permalink / raw) To: Tom Tromey; +Cc: gdb-patches > Joel> Pierre noticed a small typo in "asssume" (thank you!), so here is > Joel> a new version with the typo corrected. > > Sorry, one last question -- do we need an exclusion for OpenCL as well? > OpenCL is based on C99. I couldn't really find an answer via quick googling. I am happy excluding opencl as well - that would preserve the existing behavior for this language. Or said differently, it would change the behavior for the following languages: D, Go, Fortran, M2, Asm, Ada, and "minimal". -- Joel ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [RFA/dwarf 2/2] Mark all functions as prototyped except C functions. 2013-05-17 5:07 ` Joel Brobecker @ 2013-05-17 15:06 ` Tom Tromey 2013-05-20 9:48 ` Checked in: " Joel Brobecker 0 siblings, 1 reply; 15+ messages in thread From: Tom Tromey @ 2013-05-17 15:06 UTC (permalink / raw) To: Joel Brobecker; +Cc: gdb-patches >>>>> "Joel" == Joel Brobecker <brobecker@adacore.com> writes: Joel> Pierre noticed a small typo in "asssume" (thank you!), so here is Joel> a new version with the typo corrected. >> >> Sorry, one last question -- do we need an exclusion for OpenCL as well? >> OpenCL is based on C99. Joel> I couldn't really find an answer via quick googling. I am happy Joel> excluding opencl as well - that would preserve the existing behavior Joel> for this language. Or said differently, it would change the behavior Joel> for the following languages: D, Go, Fortran, M2, Asm, Ada, and Joel> "minimal". Yeah, I think that is the way to go. Tom ^ permalink raw reply [flat|nested] 15+ messages in thread
* Checked in: [RFA/dwarf 2/2] Mark all functions as prototyped except C functions. 2013-05-17 15:06 ` Tom Tromey @ 2013-05-20 9:48 ` Joel Brobecker 0 siblings, 0 replies; 15+ messages in thread From: Joel Brobecker @ 2013-05-20 9:48 UTC (permalink / raw) To: Tom Tromey; +Cc: gdb-patches [-- Attachment #1: Type: text/plain, Size: 773 bytes --] > Joel> I couldn't really find an answer via quick googling. I am happy > Joel> excluding opencl as well - that would preserve the existing behavior > Joel> for this language. Or said differently, it would change the behavior > Joel> for the following languages: D, Go, Fortran, M2, Asm, Ada, and > Joel> "minimal". > > Yeah, I think that is the way to go. OK. Attached is what I checked in after doing another round of testing. I hope we got the list right, but I'll handle adjustments as followup patches... gdb/ChangeLog: * dwarf2read.c (prototyped_function_p): New function. (read_subroutine_type): Use it. gdb/testsuite/ChangeLog: * gdb.ada/float_param: New testcase. Thanks for taking the time to work with me on this patch... -- Joel [-- Attachment #2: 0001-dwarf-Mark-all-functions-as-prototyped-except-C-func.patch --] [-- Type: text/x-diff, Size: 11176 bytes --] From d0d59ce24a9423a51ad1a683c5c94acb2de404bd Mon Sep 17 00:00:00 2001 From: Joel Brobecker <brobecker@adacore.com> Date: Tue, 15 Jan 2013 11:51:39 +0400 Subject: [PATCH] [dwarf] Mark all functions as prototyped except C functions. This makes sure that the types of the arguments are taken into account when performing an inferior function call to a non-C (or C-like) function. In particular, this makes sure that the arguments are appropriatly converted to the correct type. For instance, on x86_64-linux, with the following Ada code: procedure Set_Float (F : Float) is begin Global_Float := F; end Set_Float; The following sequence shows that Float arguments are incorrectly passed (Ada's Float type is the equivalent of type "float" in C): (gdb) call set_float (2.0) (gdb) print global_float $1 = 0.0 Putting a breakpoint inside set_float to inspect the value of register xmm0 gives the first hint of the problem: (gdb) p $xmm0 $2 = (v4_float => (0 => 0.0, 2.0, 0.0, 0.0), v2_double => (0 => 2.0, 0.0), [...] It shows that the argument was passed as a double. The code responsible for doing appropriate type conversions for the arguments (value_arg_coerce) found that our function was not prototyped, and thus could not use typing information for the arguments. Instead, it defaulted to the value of "set coerce-float-to-double", which by default is true, to determine the argument type. This patch fixes the problem by setting the PROTOTYPE flag for all functions of any language except C and Objective C. gdb/ChangeLog: * dwarf2read.c (prototyped_function_p): New function. (read_subroutine_type): Use it. gdb/testsuite/ChangeLog: * gdb.ada/float_param: New testcase. --- gdb/ChangeLog | 5 ++++ gdb/dwarf2read.c | 45 +++++++++++++++++++++-------- gdb/testsuite/ChangeLog | 4 +++ gdb/testsuite/gdb.ada/float_param.exp | 43 +++++++++++++++++++++++++++ gdb/testsuite/gdb.ada/float_param/foo.adb | 23 +++++++++++++++ gdb/testsuite/gdb.ada/float_param/pck.adb | 35 ++++++++++++++++++++++ gdb/testsuite/gdb.ada/float_param/pck.ads | 31 ++++++++++++++++++++ 7 files changed, 174 insertions(+), 12 deletions(-) create mode 100644 gdb/testsuite/gdb.ada/float_param.exp create mode 100644 gdb/testsuite/gdb.ada/float_param/foo.adb create mode 100644 gdb/testsuite/gdb.ada/float_param/pck.adb create mode 100644 gdb/testsuite/gdb.ada/float_param/pck.ads diff --git a/gdb/ChangeLog b/gdb/ChangeLog index e536b15..ba4c83e 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,10 @@ 2013-05-20 Joel Brobecker <brobecker@adacore.com> + * dwarf2read.c (prototyped_function_p): New function. + (read_subroutine_type): Use it. + +2013-05-20 Joel Brobecker <brobecker@adacore.com> + * rs6000-aix-tdep.c: De-indent some example code provided as a comment. diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index a17cd9d..036ccfe 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -12600,6 +12600,38 @@ read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu) return set_die_type (die, type, cu); } +/* Assuming that DIE corresponds to a function, returns nonzero + if the function is prototyped. */ + +static int +prototyped_function_p (struct die_info *die, struct dwarf2_cu *cu) +{ + struct attribute *attr; + + attr = dwarf2_attr (die, DW_AT_prototyped, cu); + if (attr && (DW_UNSND (attr) != 0)) + return 1; + + /* The DWARF standard implies that the DW_AT_prototyped attribute + is only meaninful for C, but the concept also extends to other + languages that allow unprototyped functions (Eg: Objective C). + For all other languages, assume that functions are always + prototyped. */ + if (cu->language != language_c + && cu->language != language_objc + && cu->language != language_opencl) + return 1; + + /* RealView does not emit DW_AT_prototyped. We can not distinguish + prototyped and unprototyped functions; default to prototyped, + since that is more common in modern code (and RealView warns + about unprototyped functions). */ + if (producer_is_realview (cu->producer)) + return 1; + + return 0; +} + /* Handle DIES due to C code like: struct foo @@ -12627,18 +12659,7 @@ read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu) ftype = lookup_function_type (type); - /* All functions in C++, Pascal and Java have prototypes. */ - attr = dwarf2_attr (die, DW_AT_prototyped, cu); - if ((attr && (DW_UNSND (attr) != 0)) - || cu->language == language_cplus - || cu->language == language_java - || cu->language == language_pascal) - TYPE_PROTOTYPED (ftype) = 1; - else if (producer_is_realview (cu->producer)) - /* RealView does not emit DW_AT_prototyped. We can not - distinguish prototyped and unprototyped functions; default to - prototyped, since that is more common in modern code (and - RealView warns about unprototyped functions). */ + if (prototyped_function_p (die, cu)) TYPE_PROTOTYPED (ftype) = 1; /* Store the calling convention in the type if it's available in diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index cb940e1..f944fc4 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2013-05-20 Joel Brobecker <brobecker@adacore.com> + + * gdb.ada/float_param: New testcase. + 2013-05-17 Doug Evans <dje@google.com> * gdb.base/maint.exp: Update test for "maint check-psymtabs". diff --git a/gdb/testsuite/gdb.ada/float_param.exp b/gdb/testsuite/gdb.ada/float_param.exp new file mode 100644 index 0000000..f0a7eac --- /dev/null +++ b/gdb/testsuite/gdb.ada/float_param.exp @@ -0,0 +1,43 @@ +# Copyright 2013 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/>. + +load_lib "ada.exp" + +if { [skip_ada_tests] } { return -1 } + +standard_ada_testfile foo + +if {[gdb_compile_ada "${srcfile}" "${binfile}" executable {debug}] != ""} { + return -1 +} + +clean_restart ${testfile} + +set bp_location [gdb_get_line_number "START" ${testdir}/foo.adb] +runto "foo.adb:$bp_location" + +gdb_test_no_output "call set_float(2.0)" +gdb_test "print global_float" \ + " = 2\\.0" + +gdb_test_no_output "call set_double(1, 3.0)" +gdb_test "print global_double" \ + " = 3\\.0" + +gdb_test_no_output "call set_long_double(1, global_small_struct, 4.0)" +gdb_test "print global_long_double" \ + " = 4\\.0" + + diff --git a/gdb/testsuite/gdb.ada/float_param/foo.adb b/gdb/testsuite/gdb.ada/float_param/foo.adb new file mode 100644 index 0000000..2b08681 --- /dev/null +++ b/gdb/testsuite/gdb.ada/float_param/foo.adb @@ -0,0 +1,23 @@ +-- Copyright 2013 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 +begin + Set_Float (1.0); -- START + Set_Double (1, 1.0); + Set_Long_Double (1, (I => 2), 1.0); +end Foo; diff --git a/gdb/testsuite/gdb.ada/float_param/pck.adb b/gdb/testsuite/gdb.ada/float_param/pck.adb new file mode 100644 index 0000000..18967e4 --- /dev/null +++ b/gdb/testsuite/gdb.ada/float_param/pck.adb @@ -0,0 +1,35 @@ +-- Copyright 2013 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 Set_Float (F : Float) is + begin + Global_Float := F; + end Set_Float; + + procedure Set_Double (Dummy : Integer; D : Long_Float) is + begin + Global_Double := D; + end Set_Double; + + procedure Set_Long_Double (Dummy : Integer; + DS : Small_Struct; + LD : Long_Long_Float) is + begin + Global_Long_Double := LD; + end Set_Long_Double; + +end Pck; diff --git a/gdb/testsuite/gdb.ada/float_param/pck.ads b/gdb/testsuite/gdb.ada/float_param/pck.ads new file mode 100644 index 0000000..093a32d --- /dev/null +++ b/gdb/testsuite/gdb.ada/float_param/pck.ads @@ -0,0 +1,31 @@ +-- Copyright 2013 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 + Global_Float : Float := 0.0; + Global_Double : Long_Float := 0.0; + Global_Long_Double : Long_Long_Float := 0.0; + + type Small_Struct is record + I : Integer; + end record; + Global_Small_Struct : Small_Struct := (I => 0); + + procedure Set_Float (F : Float); + procedure Set_Double (Dummy : Integer; D : Long_Float); + procedure Set_Long_Double (Dummy : Integer; + DS: Small_Struct; + LD : Long_Long_Float); +end Pck; -- 1.7.10.4 ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [RFA/dwarf 2/2] Mark all functions as prototyped except C functions. 2013-05-16 7:38 ` Joel Brobecker 2013-05-16 8:14 ` Joel Brobecker @ 2013-05-16 17:52 ` Stan Shebs 1 sibling, 0 replies; 15+ messages in thread From: Stan Shebs @ 2013-05-16 17:52 UTC (permalink / raw) To: gdb-patches On 5/16/13 12:38 AM, Joel Brobecker wrote: >> Joel> + /* The DWARF standard implies that the DW_AT_prototyped attribute >> Joel> + is only meaninful to C. So assume that non-C functions are >> Joel> + always prototyped. */ >> Joel> + if (cu->language != language_c) >> Joel> + return 1; >> >> Can Objective C have un-prototyped functions? >> I don't know. But if it can, then it should be checked here. > > Hmmm, I am not 100% sure, but some internet searches suggest > that this is probably true. Thanks! Attached is the updated patch, > just adding language_objc to the condition, and adjusting the > comment accordingly. Objective-C (1.0 or 2.0) doesn't require prototypes; in general ObjC tries to be purely an extension to C, and orthogonal to C dialect. Stan stan@codesourcery.com ^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2013-05-20 9:48 UTC | newest] Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2013-05-13 10:17 [RFA/commit] DWARF: Mark all Ada functions as prototyped Joel Brobecker 2013-05-13 15:31 ` Tom Tromey 2013-05-15 13:19 ` Joel Brobecker 2013-05-15 13:20 ` [RFA/dwarf 1/2]: Add DW_LANG_UPC support in set_cu_language Joel Brobecker 2013-05-15 15:04 ` Tom Tromey 2013-05-16 7:40 ` Checked in: " Joel Brobecker 2013-05-15 13:20 ` [RFA/dwarf 2/2] Mark all functions as prototyped except C functions Joel Brobecker 2013-05-15 15:11 ` Tom Tromey 2013-05-16 7:38 ` Joel Brobecker 2013-05-16 8:14 ` Joel Brobecker 2013-05-16 13:22 ` Tom Tromey 2013-05-17 5:07 ` Joel Brobecker 2013-05-17 15:06 ` Tom Tromey 2013-05-20 9:48 ` Checked in: " Joel Brobecker 2013-05-16 17:52 ` Stan Shebs
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox