]>
Commit | Line | Data |
---|---|---|
c5a57081 | 1 | # Copyright 2008-2012 Free Software Foundation, Inc. |
a0ef4274 DJ |
2 | |
3 | # This program is free software; you can redistribute it and/or modify | |
4 | # it under the terms of the GNU General Public License as published by | |
5 | # the Free Software Foundation; either version 3 of the License, or | |
6 | # (at your option) any later version. | |
7 | # | |
8 | # This program is distributed in the hope that it will be useful, | |
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | # GNU General Public License for more details. | |
12 | # | |
13 | # You should have received a copy of the GNU General Public License | |
14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
15 | ||
16 | # This test was created by modifying attach.exp. | |
17 | # This file was created by Jeff Johnston <jjohnstn@redhat.com>. | |
18 | # This file was updated by Jan Kratochvil <jan.kratochvil@redhat.com>. | |
19 | ||
20 | # This test only works on Linux | |
3a3dad98 JK |
21 | if { ![isnative] || [is_remote host] || [target_info exists use_gdb_stub] |
22 | || ![istarget *-linux*] } { | |
a0ef4274 DJ |
23 | continue |
24 | } | |
25 | ||
26 | set testfile "attach-stopped" | |
27 | set srcfile ${testfile}.c | |
28 | set binfile ${objdir}/${subdir}/${testfile} | |
29 | set escapedbinfile [string_to_regexp ${objdir}/${subdir}/${testfile}] | |
30 | ||
31 | #execute_anywhere "rm -f ${binfile}" | |
32 | remote_exec build "rm -f ${binfile}" | |
33 | # For debugging this test | |
34 | # | |
35 | #log_user 1 | |
36 | ||
37 | proc corefunc { threadtype } { | |
38 | global srcfile | |
39 | global binfile | |
40 | global escapedbinfile | |
41 | global srcdir | |
42 | global subdir | |
43 | global gdb_prompt | |
44 | ||
45 | if [get_compiler_info ${binfile}] { | |
46 | return -1 | |
47 | } | |
48 | ||
49 | # Start the program running and then wait for a bit, to be sure | |
50 | # that it can be attached to. | |
51 | ||
52 | set testpid [eval exec $binfile &] | |
53 | ||
54 | # Avoid some race: | |
55 | sleep 2 | |
56 | ||
57 | # Stop the program | |
58 | remote_exec build "kill -s STOP ${testpid}" | |
59 | ||
60 | # Start with clean gdb | |
61 | gdb_exit | |
62 | gdb_start | |
63 | gdb_reinitialize_dir $srcdir/$subdir | |
64 | gdb_load ${binfile} | |
65 | ||
66 | # Verify that we can attach to the stopped process. | |
67 | ||
68 | set test "$threadtype: attach2 to stopped, after setting file" | |
69 | gdb_test_multiple "attach $testpid" "$test" { | |
70 | -re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*$gdb_prompt $" { | |
71 | pass "$test" | |
72 | } | |
73 | } | |
74 | ||
75 | # ".*sleep.*clone.*" would fail on s390x as bt stops at START_THREAD there. | |
76 | if {[string equal $threadtype threaded]} { | |
77 | gdb_test "thread apply all bt" ".*sleep.*start_thread.*" "$threadtype: attach2 to stopped bt" | |
78 | } else { | |
79 | gdb_test "bt" ".*sleep.*main.*" "$threadtype: attach2 to stopped bt" | |
80 | } | |
a0ef4274 DJ |
81 | |
82 | gdb_exit | |
83 | ||
84 | # Avoid some race: | |
85 | sleep 2 | |
86 | ||
049682ba JK |
87 | # At this point, the process may be sleeping or T (Stopped) depending on |
88 | # the Linux kernel version. The behavior is not tested as it is not | |
89 | # dependent on GDB. | |
a0ef4274 | 90 | |
a0ef4274 DJ |
91 | remote_exec build "kill -9 ${testpid}" |
92 | } | |
93 | ||
94 | # build the test case first without threads | |
95 | # | |
96 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { | |
c7a6ca08 PA |
97 | untested "attach-stopped.exp (unthreaded)" |
98 | return -1 | |
a0ef4274 DJ |
99 | } |
100 | ||
101 | corefunc nonthreaded | |
102 | ||
103 | # build the test case first without threads | |
104 | # | |
105 | if { [gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DUSE_THREADS}] != "" } { | |
c7a6ca08 PA |
106 | untested "attach-stopped.exp (threaded)" |
107 | return -1 | |
a0ef4274 DJ |
108 | } |
109 | ||
110 | corefunc threaded | |
111 | ||
112 | return 0 |