]> git.pld-linux.org Git - packages/gdb.git/blame - gdb-bz592031-siginfo-lost-3of5.patch
- updated (performance fixes).
[packages/gdb.git] / gdb-bz592031-siginfo-lost-3of5.patch
CommitLineData
51a5ef0f
PS
1http://sourceware.org/ml/gdb-patches/2010-09/msg00438.html
2http://sourceware.org/ml/gdb-cvs/2010-09/msg00156.html
3
4### src/gdb/ChangeLog 2010/09/24 16:11:44 1.12203
5### src/gdb/ChangeLog 2010/09/24 18:35:20 1.12204
6## -1,3 +1,16 @@
7+2010-09-24 Jan Kratochvil <jan.kratochvil@redhat.com>
8+
9+ Fix lost siginfo_t for inferior calls.
10+ * infrun.c
11+ (struct inferior_thread_state) <siginfo_gdbarch, siginfo_data>: New.
12+ (save_inferior_thread_state): New variables regcache, gdbarch and
13+ siginfo_data. Initialize SIGINFO_DATA if gdbarch_get_siginfo_type_p.
14+ Move INF_STATE allocation later, pre-clear it. Initialize REGISTERS
15+ using REGCACHE.
16+ (restore_inferior_thread_state): New variables regcache and gdbarch.
17+ Restore SIGINFO_DATA for matching GDBARCH. Restore REGISTERS using
18+ REGCACHE. Free also SIGINFO_DATA.
19+
20 2010-09-24 Tom Tromey <tromey@redhat.com>
21
22 * dwarf2read.c (dw2_expand_symtabs_matching): Add missing
23--- src/gdb/infrun.c 2010/09/06 14:22:07 1.450
24+++ src/gdb/infrun.c 2010/09/24 18:35:27 1.451
25@@ -6037,18 +6037,57 @@
26 enum target_signal stop_signal;
27 CORE_ADDR stop_pc;
28 struct regcache *registers;
29+
30+ /* Format of SIGINFO or NULL if it is not present. */
31+ struct gdbarch *siginfo_gdbarch;
32+
33+ /* The inferior format depends on SIGINFO_GDBARCH and it has a length of
34+ TYPE_LENGTH (gdbarch_get_siginfo_type ()). For different gdbarch the
35+ content would be invalid. */
36+ gdb_byte *siginfo_data;
37 };
38
39 struct inferior_thread_state *
40 save_inferior_thread_state (void)
41 {
42- struct inferior_thread_state *inf_state = XMALLOC (struct inferior_thread_state);
43+ struct inferior_thread_state *inf_state;
44 struct thread_info *tp = inferior_thread ();
45+ struct regcache *regcache = get_current_regcache ();
46+ struct gdbarch *gdbarch = get_regcache_arch (regcache);
47+ gdb_byte *siginfo_data = NULL;
48+
49+ if (gdbarch_get_siginfo_type_p (gdbarch))
50+ {
51+ struct type *type = gdbarch_get_siginfo_type (gdbarch);
52+ size_t len = TYPE_LENGTH (type);
53+ struct cleanup *back_to;
54+
55+ siginfo_data = xmalloc (len);
56+ back_to = make_cleanup (xfree, siginfo_data);
57+
58+ if (target_read (&current_target, TARGET_OBJECT_SIGNAL_INFO, NULL,
59+ siginfo_data, 0, len) == len)
60+ discard_cleanups (back_to);
61+ else
62+ {
63+ /* Errors ignored. */
64+ do_cleanups (back_to);
65+ siginfo_data = NULL;
66+ }
67+ }
68+
69+ inf_state = XZALLOC (struct inferior_thread_state);
70+
71+ if (siginfo_data)
72+ {
73+ inf_state->siginfo_gdbarch = gdbarch;
74+ inf_state->siginfo_data = siginfo_data;
75+ }
76
77 inf_state->stop_signal = tp->stop_signal;
78 inf_state->stop_pc = stop_pc;
79
80- inf_state->registers = regcache_dup (get_current_regcache ());
81+ inf_state->registers = regcache_dup (regcache);
82
83 return inf_state;
84 }
85@@ -6059,16 +6098,29 @@
86 restore_inferior_thread_state (struct inferior_thread_state *inf_state)
87 {
88 struct thread_info *tp = inferior_thread ();
89+ struct regcache *regcache = get_current_regcache ();
90+ struct gdbarch *gdbarch = get_regcache_arch (regcache);
91
92 tp->stop_signal = inf_state->stop_signal;
93 stop_pc = inf_state->stop_pc;
94
95+ if (inf_state->siginfo_gdbarch == gdbarch)
96+ {
97+ struct type *type = gdbarch_get_siginfo_type (gdbarch);
98+ size_t len = TYPE_LENGTH (type);
99+
100+ /* Errors ignored. */
101+ target_write (&current_target, TARGET_OBJECT_SIGNAL_INFO, NULL,
102+ inf_state->siginfo_data, 0, len);
103+ }
104+
105 /* The inferior can be gone if the user types "print exit(0)"
106 (and perhaps other times). */
107 if (target_has_execution)
108 /* NB: The register write goes through to the target. */
109- regcache_cpy (get_current_regcache (), inf_state->registers);
110+ regcache_cpy (regcache, inf_state->registers);
111 regcache_xfree (inf_state->registers);
112+ xfree (inf_state->siginfo_data);
113 xfree (inf_state);
114 }
115
116### src/gdb/testsuite/ChangeLog 2010/09/22 20:08:04 1.2456
117### src/gdb/testsuite/ChangeLog 2010/09/24 18:35:28 1.2457
118## -1,3 +1,9 @@
119+2010-09-24 Jan Kratochvil <jan.kratochvil@redhat.com>
120+
121+ Fix lost siginfo_t for inferior calls.
122+ * gdb.base/siginfo-infcall.exp: New file.
123+ * gdb.base/siginfo-infcall.c: New file.
124+
125 2010-09-22 Joel Brobecker <brobecker@adacore.com>
126
127 * gdb.dwarf2/dw2-const.S: Minor (space) reformatting.
128--- src/gdb/testsuite/gdb.base/siginfo-infcall.c
129+++ src/gdb/testsuite/gdb.base/siginfo-infcall.c 2010-09-25 13:25:25.007169000 +0000
130@@ -0,0 +1,79 @@
131+/* This testcase is part of GDB, the GNU debugger.
132+
133+ Copyright 2010 Free Software Foundation, Inc.
134+
135+ This program is free software; you can redistribute it and/or modify
136+ it under the terms of the GNU General Public License as published by
137+ the Free Software Foundation; either version 3 of the License, or
138+ (at your option) any later version.
139+
140+ This program is distributed in the hope that it will be useful,
141+ but WITHOUT ANY WARRANTY; without even the implied warranty of
142+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
143+ GNU General Public License for more details.
144+
145+ You should have received a copy of the GNU General Public License
146+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
147+
148+#include <signal.h>
149+#include <assert.h>
150+#include <string.h>
151+#include <unistd.h>
152+
153+#ifndef SA_SIGINFO
154+# error "SA_SIGINFO is required for this test"
155+#endif
156+
157+static int
158+callme (void)
159+{
160+ return 42;
161+}
162+
163+static int
164+pass (void)
165+{
166+ return 1;
167+}
168+
169+static int
170+fail (void)
171+{
172+ return 1;
173+}
174+
175+static void
176+handler (int sig, siginfo_t *siginfo, void *context)
177+{
178+ assert (sig == SIGUSR1);
179+ assert (siginfo->si_signo == SIGUSR1);
180+ if (siginfo->si_pid == getpid ())
181+ pass ();
182+ else
183+ fail ();
184+}
185+
186+int
187+main (void)
188+{
189+ struct sigaction sa;
190+ int i;
191+
192+ callme ();
193+
194+ memset (&sa, 0, sizeof (sa));
195+ sa.sa_sigaction = handler;
196+ sa.sa_flags = SA_SIGINFO;
197+
198+ i = sigemptyset (&sa.sa_mask);
199+ assert (i == 0);
200+
201+ i = sigaction (SIGUSR1, &sa, NULL);
202+ assert (i == 0);
203+
204+ i = raise (SIGUSR1);
205+ assert (i == 0);
206+
207+ sleep (600);
208+ return 0;
209+}
210--- src/gdb/testsuite/gdb.base/siginfo-infcall.exp
211+++ src/gdb/testsuite/gdb.base/siginfo-infcall.exp 2010-09-25 13:25:25.357724000 +0000
212@@ -0,0 +1,47 @@
213+# Copyright 2010 Free Software Foundation, Inc.
214+
215+# This program is free software; you can redistribute it and/or modify
216+# it under the terms of the GNU General Public License as published by
217+# the Free Software Foundation; either version 3 of the License, or
218+# (at your option) any later version.
219+#
220+# This program is distributed in the hope that it will be useful,
221+# but WITHOUT ANY WARRANTY; without even the implied warranty of
222+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
223+# GNU General Public License for more details.
224+#
225+# You should have received a copy of the GNU General Public License
226+# along with this program. If not, see <http://www.gnu.org/licenses/>.
227+
228+if [target_info exists gdb,nosignals] {
229+ verbose "Skipping siginfo-infcall.exp because of nosignals."
230+ continue
231+}
232+
233+set testfile siginfo-infcall
234+set srcfile ${testfile}.c
235+set executable ${testfile}
236+if { [prepare_for_testing ${testfile}.exp $executable] } {
237+ return -1
238+}
239+
240+if ![runto_main] {
241+ return -1
242+}
243+
244+gdb_breakpoint "pass"
245+gdb_breakpoint "fail"
246+
247+gdb_test "continue" "Program received signal SIGUSR1, .*" "continue to SIGUSR1"
248+
249+gdb_test "p callme ()" " = 42"
250+
251+set test "continue to the handler"
252+gdb_test_multiple "continue" $test {
253+ -re "Breakpoint \[0-9\]+,\[^\r\n\]* pass .*\r\n$gdb_prompt $" {
254+ pass $test
255+ }
256+ -re "Breakpoint \[0-9\]+,\[^\r\n\]* fail .*\r\n$gdb_prompt $" {
257+ fail $test
258+ }
259+}
This page took 0.09829 seconds and 4 git commands to generate.