This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH 1/8] Add new test, gdb.base/loop-break.exp
- From: Kevin Buettner <kevinb at redhat dot com>
- To: gdb-patches at sourceware dot org
- Date: Tue, 18 Aug 2015 23:57:56 -0700
- Subject: [PATCH 1/8] Add new test, gdb.base/loop-break.exp
- Authentication-results: sourceware.org; auth=none
- References: <20150818235334 dot 1afb0c85 at pinnacle dot lan>
This test places breakpoints at various points on several different
looping constructs, making sure that GDB behaves as expected.
gdb/testsuite/ChangeLog:
* gdb.base/loop-break.c, gdb.base/loop-break.exp: New files.
---
gdb/testsuite/gdb.base/loop-break.c | 42 +++++++++++++
gdb/testsuite/gdb.base/loop-break.exp | 113 ++++++++++++++++++++++++++++++++++
2 files changed, 155 insertions(+)
diff --git a/gdb/testsuite/gdb.base/loop-break.c b/gdb/testsuite/gdb.base/loop-break.c
new file mode 100644
index 0000000..3e4b5ca
--- /dev/null
+++ b/gdb/testsuite/gdb.base/loop-break.c
@@ -0,0 +1,42 @@
+volatile int v;
+volatile int w;
+
+void
+loop_test (void)
+{
+ v = 0;
+
+ while (v < 3) /* Loop 1 condition */
+ {
+ v++; /* Loop 1 increment */
+ }
+
+ v = -42;
+
+ for (v = 0; v < 3; ) /* Loop 2 */
+ {
+ v++; /* Loop 2 increment */
+ }
+
+ v = -42;
+ w = 42;
+
+ for (v = 0; /* Loop 3 initialization */
+ v < 3; /* Loop 3 condition */
+ v++) /* Loop 3 increment */
+ {
+ w = w - v;
+ }
+
+ v = 0;
+ goto b; /* Loop 4 initial goto */
+a: v++;
+b: if (v < 3) goto a; /* Loop 4 condition */
+}
+
+int main (int argc, char **argv)
+{
+ loop_test ();
+
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.base/loop-break.exp b/gdb/testsuite/gdb.base/loop-break.exp
new file mode 100644
index 0000000..fef3fcb
--- /dev/null
+++ b/gdb/testsuite/gdb.base/loop-break.exp
@@ -0,0 +1,113 @@
+# 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/>.
+
+# Place breakpoints at various points on several different looping
+# constructs. Make sure that GDB correctly runs to each of these
+# breakpoints and that computed values are correct at each point along
+# the way.
+
+standard_testfile
+
+if {[prepare_for_testing $testfile.exp $testfile $srcfile debug]} {
+ return -1
+}
+
+if ![runto_main] then { fail "loop-break tests suppressed" }
+
+proc break_at { search_string } {
+ global srcfile
+ set bp_location [gdb_get_line_number $search_string]
+ gdb_test "break $bp_location" \
+ "Breakpoint.*at.* file .*$srcfile, line $bp_location\\." \
+ "break $search_string"
+
+ return $bp_location;
+}
+
+proc continue_to { linenum testname iter } {
+ global srcfile
+ global gdb_prompt
+ set full_name "continue to $testname, $iter"
+
+ send_gdb "continue\n"
+ gdb_expect {
+ -re "Continuing.*Breakpoint.*$srcfile:$linenum\r\n.*\r\n$gdb_prompt $" {
+ pass $full_name
+ }
+ -re ".*$gdb_prompt $" {
+ fail $full_name
+ }
+ timeout {
+ fail "$full_name (timeout)"
+ }
+ }
+}
+
+set bp_location1a [break_at "Loop 1 condition"]
+set bp_location1b [break_at "Loop 1 increment"]
+set bp_location2a [break_at "Loop 2"]
+set bp_location2b [break_at "Loop 2 increment"]
+set bp_location3a [break_at "Loop 3 initialization"]
+set bp_location3b [break_at "Loop 3 condition"]
+set bp_location3c [break_at "Loop 3 increment"]
+set bp_location4a [break_at "Loop 4 initial goto"]
+set bp_location4b [break_at "Loop 4 condition"]
+
+continue_to $bp_location1a "Loop 1 condition" 0
+gdb_test "p v" "= 0" "Loop 1 value check at condition 0"
+continue_to $bp_location1b "Loop 1 increment" 0
+gdb_test "p v" "= 0" "Loop 1 value check at increment 0"
+
+continue_to $bp_location1a "Loop 1 condition" 1
+gdb_test "p v" "= 1" "Loop 1 value check at condition 1"
+continue_to $bp_location1b "Loop 1 increment" 1
+gdb_test "p v" "= 1" "Loop 1 value check at increment 1"
+
+continue_to $bp_location1a "Loop 1 condition" 2
+continue_to $bp_location1b "Loop 1 increment" 2
+
+continue_to $bp_location1a "Loop 1 condition" 3
+
+continue_to $bp_location2a "Loop 2" 0
+gdb_test "p v" "= -42" "Loop 2 value check at loop start"
+continue_to $bp_location2b "Loop 2 increment" 0
+gdb_test "p v" "= 0" "Loop 2 value check at increment 0"
+continue_to $bp_location2b "Loop 2 increment" 1
+gdb_test "p v" "= 1" "Loop 2 value check at increment 1"
+continue_to $bp_location2b "Loop 2 increment" 2
+gdb_test "p v" "= 2" "Loop 2 value check at increment 2"
+
+continue_to $bp_location3a "Loop 3 initialization" 0
+gdb_test "p v" "= -42" "Loop 3 value check at initialization"
+continue_to $bp_location3b "Loop 3 condition" 0
+gdb_test "p v" "= 0" "Loop 3 value check at condition 0"
+continue_to $bp_location3c "Loop 3 increment" 0
+gdb_test "p v" "= 0" "Loop 3 value check at increment 0"
+continue_to $bp_location3b "Loop 3 condition" 1
+continue_to $bp_location3c "Loop 3 increment" 1
+continue_to $bp_location3b "Loop 3 condition" 2
+continue_to $bp_location3c "Loop 3 increment" 2
+continue_to $bp_location3b "Loop 3 condition" 3
+
+continue_to $bp_location4a "Loop 4 initial goto" 0
+gdb_test "p v" "= 0" "Loop 4 value check at initial goto"
+continue_to $bp_location4b "Loop 4 condition" 0
+gdb_test "p v" "= 0" "Loop 4 value check at condition 0"
+continue_to $bp_location4b "Loop 4 condition" 1
+gdb_test "p v" "= 1" "Loop 4 value check at condition 1"
+continue_to $bp_location4b "Loop 4 condition" 2
+gdb_test "p v" "= 2" "Loop 4 value check at condition 2"
+continue_to $bp_location4b "Loop 4 condition" 3
+gdb_test "p v" "= 3" "Loop 4 value check at condition 3"