summaryrefslogtreecommitdiff
path: root/gdb-simultaneous-step-resume-breakpoint-test.patch
blob: 5e1315b77e9809e81742d6596d419fc963577a06 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
From: Fedora GDB patches <invalid@email.com>
Date: Fri, 27 Oct 2017 21:07:50 +0200
Subject: gdb-simultaneous-step-resume-breakpoint-test.patch

;; New test for step-resume breakpoint placed in multiple threads at once.
;;=fedoratest

diff --git a/gdb/testsuite/gdb.threads/simultaneous-step-resume-breakpoint.c b/gdb/testsuite/gdb.threads/simultaneous-step-resume-breakpoint.c
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.threads/simultaneous-step-resume-breakpoint.c
@@ -0,0 +1,79 @@
+/* Copyright 2009 Free Software Foundation, Inc.
+
+   Written by Fred Fish of Cygnus Support
+   Contributed by Cygnus Support
+
+   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/>.  */
+
+/* Test multiple threads stepping into a .debug_line-less function with
+   a breakpoint placed on its return-to-caller point.  */
+
+#include <pthread.h>
+#include <assert.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdio.h>
+
+#define THREADS 3
+
+static void *
+func (void *unused)
+{
+  int i;
+
+  errno = 0;
+  i = 0xdeadf00d;
+  i = sleep (THREADS);	/* sleep-call */
+  if (errno != 0)	/* sleep-after */
+    perror ("sleep");
+
+  /* The GDB bug with forgotten step-resume breakpoint could leave stale
+     breakpoint on the I assignment making it a nop.  */
+  if (i == 0xdeadf00d)
+    assert (0);
+
+  assert (i == 0);
+
+  pthread_exit (NULL);
+}
+
+int
+main (void)
+{
+  pthread_t threads[THREADS];
+  int threadi;
+
+  for (threadi = 0; threadi < THREADS; threadi++)
+    {
+      int i;
+
+      i = pthread_create (&threads[threadi], NULL, func, NULL);
+      assert (i == 0);
+
+      i = sleep (1);
+      assert (i == 0);
+    }
+
+  for (threadi = 0; threadi < THREADS; threadi++)
+    {
+      int i;
+
+      i = pthread_join (threads[threadi], NULL);
+      assert (i == 0);
+    }
+
+  return 0;	/* final-exit */
+}
diff --git a/gdb/testsuite/gdb.threads/simultaneous-step-resume-breakpoint.exp b/gdb/testsuite/gdb.threads/simultaneous-step-resume-breakpoint.exp
new file mode 100644
--- /dev/null
+++ b/gdb/testsuite/gdb.threads/simultaneous-step-resume-breakpoint.exp
@@ -0,0 +1,65 @@
+# Copyright (C) 2009 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/>.  */
+
+# Test multiple threads stepping into a .debug_line-less function with
+# a breakpoint placed on its return-to-caller point.
+
+set testfile simultaneous-step-resume-breakpoint
+set srcfile ${testfile}.c
+set binfile [standard_output_file ${testfile}]
+
+if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
+    return -1
+}
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+
+# Ensure we have no debuginfo for the `sleep' call itself (=for libc).
+gdb_test "set debug-file-directory /DoesNotExist"
+
+gdb_load ${binfile}
+if ![runto_main] {
+   return -1
+}
+
+# Red Hat vendor patch does set it to "step" by default.
+gdb_test "set scheduler-locking off"
+
+gdb_breakpoint [gdb_get_line_number "final-exit"]
+
+gdb_breakpoint [gdb_get_line_number "sleep-call"]
+gdb_continue_to_breakpoint "sleep-call"
+
+gdb_test "step" "sleep-call.*" "step thread 1"
+gdb_test "step" "sleep-call.*" "step thread 2"
+gdb_test "step" "sleep-after.*" "step thread 3"
+
+set test "first continue"
+gdb_test_multiple "continue" $test {
+    -re "final-exit.*$gdb_prompt $" {
+	# gdb-7.0.
+	pass $test
+	return
+    }
+    -re "sleep-after.*$gdb_prompt $" {
+	# Fedora/RHEL branch.
+	pass $test
+    }
+}
+
+gdb_test "continue" "sleep-after.*" "second continue"
+gdb_test "continue" "final-exit.*" "third continue"