Skip to content

Commit 88fc996

Browse files
committed
* thread.c (do_restore_current_thread_cleanup): Redo test for
whether to restore old->inferior_ptid. * gdb.mi/mi-nonstop-exit.exp: New file. * gdb.mi/non-stop-exit.c: New file.
1 parent d34b500 commit 88fc996

File tree

5 files changed

+173
-4
lines changed

5 files changed

+173
-4
lines changed

Diff for: gdb/ChangeLog

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2009-03-26 Doug Evans <[email protected]>
2+
3+
* thread.c (do_restore_current_thread_cleanup): Redo test for
4+
whether to restore old->inferior_ptid.
5+
16
2009-03-26 Tom Tromey <[email protected]>
27

38
* breakpoint.c (resolve_sal_pc): Preserve original line number

Diff for: gdb/testsuite/ChangeLog

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2009-03-26 Doug Evans <[email protected]>
2+
3+
* gdb.mi/mi-nonstop-exit.exp: New file.
4+
* gdb.mi/non-stop-exit.c: New file.
5+
16
2009-03-26 Tom Tromey <[email protected]>
27

38
Update for change to prologue skipping:

Diff for: gdb/testsuite/gdb.mi/mi-nonstop-exit.exp

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# Copyright 2009
2+
# Free Software Foundation, Inc.
3+
4+
# This program is free software; you can redistribute it and/or modify
5+
# it under the terms of the GNU General Public License as published by
6+
# the Free Software Foundation; either version 3 of the License, or
7+
# (at your option) any later version.
8+
#
9+
# This program is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
# GNU General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU General Public License
15+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
17+
# This only works with native configurations
18+
if {![isnative]} {
19+
return
20+
}
21+
22+
load_lib mi-support.exp
23+
set MIFLAGS "-i=mi"
24+
25+
gdb_exit
26+
if {[mi_gdb_start]} {
27+
continue
28+
}
29+
30+
#
31+
# Start here
32+
#
33+
set testfile "non-stop-exit"
34+
set srcfile "$testfile.c"
35+
set binfile "$objdir/$subdir/mi-$testfile"
36+
37+
set options [list debug incdir=$objdir]
38+
if {[gdb_compile_pthreads "$srcdir/$subdir/$srcfile" $binfile executable $options] != "" } {
39+
return -1
40+
}
41+
42+
mi_gdb_reinitialize_dir $srcdir/$subdir
43+
mi_gdb_load $binfile
44+
45+
set supported 0
46+
send_gdb "-gdb-show non-stop\n"
47+
gdb_expect {
48+
-re ".*\\^done,value=\"off\",supported=\"(\[^\"\]+)\"\r\n$mi_gdb_prompt$" {
49+
if { $expect_out(1,string) == "1" } {
50+
set supported 1
51+
}
52+
}
53+
-re ".$mi_gdb_prompt$" {
54+
}
55+
}
56+
57+
mi_gdb_test "-gdb-set non-stop 1" ".*"
58+
mi_gdb_test "-gdb-set target-async 1" ".*"
59+
detect_async
60+
61+
mi_gdb_test "200-break-insert -t main" ".*"
62+
63+
set created "=thread-created,id=\"$decimal\"\r\n"
64+
set running "\\*running,thread-id=\"$decimal\"\r\n"
65+
66+
set notifs "($created)*($running)*($library_loaded_re)*"
67+
68+
# Note: presently, we skip this test on non-native targets,
69+
# so 'run' is OK. As soon as we start to run this on remote
70+
# target, the logic from mi_run_cmd will have to be refactored.
71+
send_gdb "-exec-run\n"
72+
gdb_expect {
73+
-re "\\^running\r\n$notifs$mi_gdb_prompt" {
74+
}
75+
-re "\\^error,msg=\"The target does not support running in non-stop mode.\"" {
76+
verbose -log "Non-stop mode not supported, skipping all tests"
77+
return
78+
}
79+
-re "\r\n$mi_gdb_prompt" {
80+
perror "Cannot start target (unknown output after running)"
81+
return -1
82+
}
83+
timeout {
84+
perror "Cannot start target (timeout)"
85+
return -1
86+
}
87+
}
88+
mi_expect_stop "breakpoint-hit" main ".*" ".*" "\[0-9\]+" { "" "disp=\"del\"" } "run to main"
89+
90+
mi_send_resuming_command "exec-continue" "continue"
91+
92+
mi_expect_stop "exited-normally" "" "" "" "" "" "finished exec continue"
93+
94+
# Run the program again.
95+
96+
mi_gdb_test "200-break-insert -t main" ".*"
97+
98+
mi_send_resuming_command "exec-run" "run (2)"
99+
100+
mi_expect_stop "breakpoint-hit" main ".*" ".*" "\[0-9\]+" { "" "disp=\"del\"" } "run to main (2)"
101+
102+
mi_send_resuming_command "exec-continue" "continue (2)"
103+
104+
mi_expect_stop "exited-normally" "" "" "" "" "" "finished exec continue (2)"
105+
106+
mi_gdb_exit

Diff for: gdb/testsuite/gdb.mi/non-stop-exit.c

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/* Test program exit in non-stop mode.
2+
Copyright 2009 Free Software Foundation, Inc.
3+
4+
This file is part of GDB.
5+
6+
This program is free software; you can redistribute it and/or modify
7+
it under the terms of the GNU General Public License as published by
8+
the Free Software Foundation; either version 3 of the License, or
9+
(at your option) any later version.
10+
11+
This program is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU General Public License for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with this program. If not, see <http://www.gnu.org/licenses/>. */
18+
19+
#include <pthread.h>
20+
#include <stdio.h>
21+
22+
#define NTHREADS 4
23+
void* thread_function (void*);
24+
25+
void *
26+
thread_function (void *arg)
27+
{
28+
int x = * (int *) arg;
29+
30+
printf ("Thread <%d> executing\n", x);
31+
32+
return NULL;
33+
}
34+
35+
int
36+
main ()
37+
{
38+
pthread_t thread_id[NTHREADS];
39+
int args[NTHREADS];
40+
int i;
41+
42+
for (i = 0; i < NTHREADS; ++i)
43+
{
44+
args[i] = i;
45+
pthread_create (&thread_id[i], NULL, thread_function, &args[i]);
46+
}
47+
48+
for (i = 0; i < NTHREADS; ++i)
49+
{
50+
pthread_join (thread_id[i], NULL);
51+
}
52+
53+
return 0;
54+
}

Diff for: gdb/thread.c

+3-4
Original file line numberDiff line numberDiff line change
@@ -924,11 +924,10 @@ do_restore_current_thread_cleanup (void *arg)
924924
then don't revert back to it, but instead simply drop back to no
925925
thread selected. */
926926
if (tp
927-
&& is_exited (tp->ptid)
928-
&& find_inferior_pid (ptid_get_pid (tp->ptid)) == NULL)
929-
restore_current_thread (null_ptid);
930-
else
927+
&& find_inferior_pid (ptid_get_pid (tp->ptid)) != NULL)
931928
restore_current_thread (old->inferior_ptid);
929+
else
930+
restore_current_thread (null_ptid);
932931

933932
/* The running state of the originally selected thread may have
934933
changed, so we have to recheck it here. */

0 commit comments

Comments
 (0)