aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite
diff options
context:
space:
mode:
authorMark Wielaard <mjw@redhat.com>2014-12-09 11:45:41 +0100
committerMark Wielaard <mjw@redhat.com>2015-01-23 17:29:19 +0100
commit743649fd80776de922475362bf3ac8b44511bb24 (patch)
treebb0e90750f05a5d2840cbfca16aab939b703b283 /gdb/testsuite
parent198297aafb4f7a9717be8370581b048ae9107c14 (diff)
downloadgdb-743649fd80776de922475362bf3ac8b44511bb24.zip
gdb-743649fd80776de922475362bf3ac8b44511bb24.tar.gz
gdb-743649fd80776de922475362bf3ac8b44511bb24.tar.bz2
Use GCC5/DWARF5 DW_AT_noreturn to mark functions that don't return normally.
Add a flag field is_noreturn to struct func_type. Make calling_convention a small bit field to not increase the size of the struct. Set is_noreturn if the new GCC5/DWARF5 DW_AT_noreturn is set on a DW_TAG_subprogram. Use this information to warn the user before doing a finish or return from a function that does not return normally to its caller. (gdb) finish warning: Function endless does not return normally. Try to finish anyway? (y or n) (gdb) return warning: Function does not return normally to caller. Make endless return now? (y or n) gdb/ChangeLog * dwarf2read.c (read_subroutine_type): Set TYPE_NO_RETURN from DW_AT_noreturn. * gdbtypes.h (struct func_type): Add is_noreturn field flag. Make calling_convention an 8 bit bit field. (TYPE_NO_RETURN): New macro. * infcmd.c (finish_command): Query if function does not return normally. * stack.c (return_command): Likewise. gdb/testsuite/ChangeLog * gdb.base/noreturn-return.c: New file. * gdb.base/noreturn-return.exp: New file. * gdb.base/noreturn-finish.c: New file. * gdb.base/noreturn-finish.exp: New file. include/ChangeLog * dwarf2.def (DW_AT_noreturn): New DWARF5 attribute. The dwarf2.h addition and the code to emit the new attribute is already in the gcc tree.
Diffstat (limited to 'gdb/testsuite')
-rw-r--r--gdb/testsuite/ChangeLog7
-rw-r--r--gdb/testsuite/gdb.base/noreturn-finish.c31
-rw-r--r--gdb/testsuite/gdb.base/noreturn-finish.exp51
-rw-r--r--gdb/testsuite/gdb.base/noreturn-return.c31
-rw-r--r--gdb/testsuite/gdb.base/noreturn-return.exp51
5 files changed, 171 insertions, 0 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 1a17ba4..5b53cdd 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,10 @@
+2015-01-15 Mark Wielaard <mjw@redhat.com>
+
+ * gdb.base/noreturn-return.c: New file.
+ * gdb.base/noreturn-return.exp: New file.
+ * gdb.base/noreturn-finish.c: New file.
+ * gdb.base/noreturn-finish.exp: New file.
+
2015-01-23 Pedro Alves <palves@redhat.com>
* gdb.threads/continue-pending-after-query.c: New file.
diff --git a/gdb/testsuite/gdb.base/noreturn-finish.c b/gdb/testsuite/gdb.base/noreturn-finish.c
new file mode 100644
index 0000000..3ec48cd
--- /dev/null
+++ b/gdb/testsuite/gdb.base/noreturn-finish.c
@@ -0,0 +1,31 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2015 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/>. */
+
+#include <stdlib.h>
+
+void __attribute__((noreturn))
+noreturn_func (void)
+{
+ abort ();
+}
+
+int
+main (void)
+{
+ noreturn_func ();
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.base/noreturn-finish.exp b/gdb/testsuite/gdb.base/noreturn-finish.exp
new file mode 100644
index 0000000..a2ae0db
--- /dev/null
+++ b/gdb/testsuite/gdb.base/noreturn-finish.exp
@@ -0,0 +1,51 @@
+# Copyright 2015 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/>.
+
+standard_testfile
+
+if [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} {debug}] {
+ return -1
+}
+
+proc noreturn_finish_test { } {
+ global gdb_prompt
+
+ if { ! [ runto_main ] } then {
+ untested ${testfile}.exp
+ return -1
+ }
+
+ gdb_breakpoint "noreturn_func"
+ gdb_continue_to_breakpoint "noreturn_func"
+
+ set test "cancel finish from noreturn_func"
+ gdb_test_multiple "finish" $test {
+ -re "warning: Function noreturn_func does not return normally" {
+ verbose -log "saw warning"
+ exp_continue
+ }
+ -re "Try to finish anyway.*y or n.* $" {
+ send_gdb "n\n"
+ exp_continue
+ }
+ -re ".*$gdb_prompt $" {
+ pass $test
+ }
+ }
+}
+
+clean_restart ${binfile}
+
+noreturn_finish_test
diff --git a/gdb/testsuite/gdb.base/noreturn-return.c b/gdb/testsuite/gdb.base/noreturn-return.c
new file mode 100644
index 0000000..3ec48cd
--- /dev/null
+++ b/gdb/testsuite/gdb.base/noreturn-return.c
@@ -0,0 +1,31 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2015 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/>. */
+
+#include <stdlib.h>
+
+void __attribute__((noreturn))
+noreturn_func (void)
+{
+ abort ();
+}
+
+int
+main (void)
+{
+ noreturn_func ();
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.base/noreturn-return.exp b/gdb/testsuite/gdb.base/noreturn-return.exp
new file mode 100644
index 0000000..8a64a3e
--- /dev/null
+++ b/gdb/testsuite/gdb.base/noreturn-return.exp
@@ -0,0 +1,51 @@
+# Copyright 2015 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/>.
+
+standard_testfile
+
+if [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} {debug}] {
+ return -1
+}
+
+proc noreturn_test { } {
+ global gdb_prompt
+
+ if { ! [ runto_main ] } then {
+ untested ${testfile}.exp
+ return -1
+ }
+
+ gdb_breakpoint "noreturn_func"
+ gdb_continue_to_breakpoint "noreturn_func"
+
+ set test "cancel return from noreturn_func"
+ gdb_test_multiple "return" $test {
+ -re "warning: Function does not return normally to caller" {
+ verbose -log "saw warning"
+ exp_continue
+ }
+ -re "Make noreturn_func return now.*y or n. $" {
+ send_gdb "n\n"
+ exp_continue
+ }
+ -re "Not confirmed.*$gdb_prompt $" {
+ pass $test
+ }
+ }
+}
+
+clean_restart ${binfile}
+
+noreturn_test