diff options
author | Tom Tromey <tromey@adacore.com> | 2022-12-16 13:36:45 -0700 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2023-05-12 13:25:28 -0600 |
commit | d5acae9e9f16521e1d9886f74418cd2e48f01364 (patch) | |
tree | 1adec256dadc28425b89160d07818be015040399 /gdb/testsuite | |
parent | 36ed3d84e0ac1b6f21e68c742d72061ff51cb76b (diff) | |
download | binutils-d5acae9e9f16521e1d9886f74418cd2e48f01364.zip binutils-d5acae9e9f16521e1d9886f74418cd2e48f01364.tar.gz binutils-d5acae9e9f16521e1d9886f74418cd2e48f01364.tar.bz2 |
Handle Ada Pragma Import and Pragma Export
Ada can import C APIs and also export Ada constructs to C via Pragma
Import and Pragma Export. This patch adds support for these to gdb,
by arranging to either defer some aspects of a symbol to the
underlying C symbol (for Import) or by introducing a second symbol
(for Export). A somewhat tricky approach is needed, both because gdb
doesn't generally handle symbol aliasing, and because Ada treats
symbol names in an unusual way (as compared to the rest of gdb).
Diffstat (limited to 'gdb/testsuite')
-rw-r--r-- | gdb/testsuite/gdb.ada/complete.exp | 2 | ||||
-rw-r--r-- | gdb/testsuite/gdb.ada/complete/pck.ads | 4 | ||||
-rw-r--r-- | gdb/testsuite/gdb.ada/import.exp | 58 | ||||
-rw-r--r-- | gdb/testsuite/gdb.ada/import/inc.c | 27 | ||||
-rw-r--r-- | gdb/testsuite/gdb.ada/import/pkg.adb | 28 | ||||
-rw-r--r-- | gdb/testsuite/gdb.ada/import/pkg.ads | 33 | ||||
-rw-r--r-- | gdb/testsuite/gdb.ada/import/prog.adb | 31 | ||||
-rw-r--r-- | gdb/testsuite/gdb.ada/info_auto_lang.exp | 10 |
8 files changed, 189 insertions, 4 deletions
diff --git a/gdb/testsuite/gdb.ada/complete.exp b/gdb/testsuite/gdb.ada/complete.exp index 57b6546..9e92505 100644 --- a/gdb/testsuite/gdb.ada/complete.exp +++ b/gdb/testsuite/gdb.ada/complete.exp @@ -160,6 +160,7 @@ test_gdb_complete "pck" \ "p pck.ambiguous_func" \ "p pck.external_identical_one" \ "p pck.inner.inside_variable" \ + "p pck.internal_capitalized" \ "p pck.local_identical_one" \ "p pck.local_identical_two" \ "p pck.my_global_variable" \ @@ -172,6 +173,7 @@ test_gdb_complete "pck." \ "p pck.ambiguous_func" \ "p pck.external_identical_one" \ "p pck.inner.inside_variable" \ + "p pck.internal_capitalized" \ "p pck.local_identical_one" \ "p pck.local_identical_two" \ "p pck.my_global_variable" \ diff --git a/gdb/testsuite/gdb.ada/complete/pck.ads b/gdb/testsuite/gdb.ada/complete/pck.ads index 77f8967..034c142 100644 --- a/gdb/testsuite/gdb.ada/complete/pck.ads +++ b/gdb/testsuite/gdb.ada/complete/pck.ads @@ -17,8 +17,8 @@ package Pck is My_Global_Variable : Integer := 1; - Exported_Capitalized : Integer := 2; - pragma Export (C, Exported_Capitalized, "Exported_Capitalized"); + Internal_Capitalized : Integer := 2; + pragma Export (C, Internal_Capitalized, "Exported_Capitalized"); Local_Identical_One : Integer := 4; Local_Identical_Two : Integer := 8; diff --git a/gdb/testsuite/gdb.ada/import.exp b/gdb/testsuite/gdb.ada/import.exp new file mode 100644 index 0000000..866b431 --- /dev/null +++ b/gdb/testsuite/gdb.ada/import.exp @@ -0,0 +1,58 @@ +# Copyright 2023 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" + +require allow_ada_tests + +standard_ada_testfile prog + +set cfile "inc" +set csrcfile ${srcdir}/${subdir}/${testdir}/${cfile}.c +set cobject [standard_output_file ${cfile}.o] + +if {[gdb_compile "${csrcfile}" "${cobject}" object debug] != ""} { + untested "could not compile C file" + return +} +if {[gdb_compile_ada "${srcfile}" "${binfile}" executable \ + [list debug additional_flags=-largs \ + additional_flags=${cobject} additional_flags=-margs]] != ""} { + return -1 +} + +clean_restart ${testfile} + +set bp_location [gdb_get_line_number "BREAK" ${testdir}/prog.adb] +runto "prog.adb:$bp_location" + +gdb_test "print ordinary_var" " = 78" + +gdb_test "print imported_var" " = 42" +gdb_test "print imported_var_ada" " = 42" +gdb_test "print local_imported_var" " = 42" +gdb_test "print pkg.imported_var_ada" " = 42" + +gdb_test "print pkg.exported_var_ada" " = 99" +gdb_test "print exported_var_ada" " = 99" + +gdb_breakpoint "pkg.imported_func_ada" message +gdb_breakpoint "imported_func" message +gdb_breakpoint "imported_func_ada" message + +gdb_breakpoint "local_imported_func" message +gdb_breakpoint "pkg.exported_func_ada" message +gdb_breakpoint "exported_func_ada" message +gdb_breakpoint "exported_func" message diff --git a/gdb/testsuite/gdb.ada/import/inc.c b/gdb/testsuite/gdb.ada/import/inc.c new file mode 100644 index 0000000..c3a1ea1 --- /dev/null +++ b/gdb/testsuite/gdb.ada/import/inc.c @@ -0,0 +1,27 @@ +/* Copyright 2023 Free Software Foundation, Inc. + + This file is part of GDB. + + 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/>. */ + +extern int exported_var; +extern int exported_func (void); + +int imported_var = 42; + +int +imported_func (void) +{ + return exported_var + exported_func (); +} diff --git a/gdb/testsuite/gdb.ada/import/pkg.adb b/gdb/testsuite/gdb.ada/import/pkg.adb new file mode 100644 index 0000000..e4f1c1a --- /dev/null +++ b/gdb/testsuite/gdb.ada/import/pkg.adb @@ -0,0 +1,28 @@ +-- Copyright 2023 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 Pkg is + + function Exported_Func_Ada return Integer is + begin + return Imported_Var_Ada; + end Exported_Func_Ada; + + procedure Do_Nothing (A : System.Address) is + begin + null; + end Do_Nothing; + +end Pkg; diff --git a/gdb/testsuite/gdb.ada/import/pkg.ads b/gdb/testsuite/gdb.ada/import/pkg.ads new file mode 100644 index 0000000..5576d1b --- /dev/null +++ b/gdb/testsuite/gdb.ada/import/pkg.ads @@ -0,0 +1,33 @@ +-- Copyright 2023 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 System; +package Pkg is + + Imported_Var_Ada : Integer; + pragma Import (C, Imported_Var_Ada, "imported_var"); + + function Imported_Func_Ada return Integer; + pragma Import (C, Imported_Func_Ada, "imported_func"); + + Exported_Var_Ada : Integer := 99; + pragma Export (C, Exported_Var_Ada, "exported_var"); + + function Exported_Func_Ada return Integer; + pragma Export (C, Exported_Func_Ada, "exported_func"); + + procedure Do_Nothing (A : System.Address); + +end Pkg; diff --git a/gdb/testsuite/gdb.ada/import/prog.adb b/gdb/testsuite/gdb.ada/import/prog.adb new file mode 100644 index 0000000..77f2073 --- /dev/null +++ b/gdb/testsuite/gdb.ada/import/prog.adb @@ -0,0 +1,31 @@ +-- Copyright 2023 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 Pkg; + +procedure Prog is + Ordinary_Var : Integer := 78; + + Local_Imported_Var : Integer; + pragma Import (C, Local_Imported_Var, "imported_var"); + + function Local_Imported_Func return Integer; + pragma Import (C, Local_Imported_Func, "imported_func"); +begin + Local_Imported_Var := Local_Imported_Func; -- BREAK + Pkg.Imported_Var_Ada := Pkg.Imported_Func_Ada; + Pkg.Do_Nothing (Pkg.Imported_Func_Ada'Address); + Pkg.Do_Nothing (Pkg.Exported_Func_Ada'Address); +end Prog; diff --git a/gdb/testsuite/gdb.ada/info_auto_lang.exp b/gdb/testsuite/gdb.ada/info_auto_lang.exp index 5202605..5134643 100644 --- a/gdb/testsuite/gdb.ada/info_auto_lang.exp +++ b/gdb/testsuite/gdb.ada/info_auto_lang.exp @@ -51,8 +51,14 @@ if {![runto "some_c.c:$bp_location"]} { set func_in_c(c_syntax) "${decimal}: void proc_in_c\\\(void\\\);" set func_in_c(ada_syntax) "${decimal}: procedure proc_in_c;" -set func_in_ada(c_syntax) "${decimal}: void proc_in_ada\\\(void\\\);" -set func_in_ada(ada_syntax) "${decimal}: procedure proc_in_ada;" +set func_in_ada(c_syntax) \ + [string cat \ + "${decimal}: void proc_in_ada\\\(void\\\);\r\n" \ + "${decimal}: void proc_in_ada.something_in_c\\\(void\\\);"] +set func_in_ada(ada_syntax) \ + [string cat \ + "${decimal}: procedure proc_in_ada;\r\n" \ + "${decimal}: procedure proc_in_ada.something_in_c;"] set type_in_c(c_syntax) "${decimal}: typedef struct {\\.\\.\\.} some_type_in_c;" set type_in_c(ada_syntax) [multi_line \ |