Commit | Line | Data |
---|---|---|
32d0add0 | 1 | # Copyright 2008-2015 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 | ||
0efbbabc TT |
26 | standard_testfile |
27 | set escapedbinfile [string_to_regexp $binfile] | |
a0ef4274 DJ |
28 | |
29 | #execute_anywhere "rm -f ${binfile}" | |
30 | remote_exec build "rm -f ${binfile}" | |
31 | # For debugging this test | |
32 | # | |
33 | #log_user 1 | |
34 | ||
35 | proc corefunc { threadtype } { | |
36 | global srcfile | |
37 | global binfile | |
38 | global escapedbinfile | |
39 | global srcdir | |
40 | global subdir | |
41 | global gdb_prompt | |
42 | ||
4c93b1db | 43 | if [get_compiler_info] { |
a0ef4274 DJ |
44 | return -1 |
45 | } | |
46 | ||
47 | # Start the program running and then wait for a bit, to be sure | |
48 | # that it can be attached to. | |
49 | ||
50 | set testpid [eval exec $binfile &] | |
51 | ||
52 | # Avoid some race: | |
53 | sleep 2 | |
54 | ||
55 | # Stop the program | |
56 | remote_exec build "kill -s STOP ${testpid}" | |
57 | ||
58 | # Start with clean gdb | |
59 | gdb_exit | |
60 | gdb_start | |
61 | gdb_reinitialize_dir $srcdir/$subdir | |
62 | gdb_load ${binfile} | |
63 | ||
64 | # Verify that we can attach to the stopped process. | |
65 | ||
66 | set test "$threadtype: attach2 to stopped, after setting file" | |
67 | gdb_test_multiple "attach $testpid" "$test" { | |
68 | -re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*$gdb_prompt $" { | |
69 | pass "$test" | |
70 | } | |
71 | } | |
72 | ||
73 | # ".*sleep.*clone.*" would fail on s390x as bt stops at START_THREAD there. | |
74 | if {[string equal $threadtype threaded]} { | |
75 | gdb_test "thread apply all bt" ".*sleep.*start_thread.*" "$threadtype: attach2 to stopped bt" | |
76 | } else { | |
77 | gdb_test "bt" ".*sleep.*main.*" "$threadtype: attach2 to stopped bt" | |
78 | } | |
a0ef4274 DJ |
79 | |
80 | gdb_exit | |
81 | ||
82 | # Avoid some race: | |
83 | sleep 2 | |
84 | ||
049682ba JK |
85 | # At this point, the process may be sleeping or T (Stopped) depending on |
86 | # the Linux kernel version. The behavior is not tested as it is not | |
87 | # dependent on GDB. | |
a0ef4274 | 88 | |
a0ef4274 DJ |
89 | remote_exec build "kill -9 ${testpid}" |
90 | } | |
91 | ||
92 | # build the test case first without threads | |
93 | # | |
94 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { | |
c7a6ca08 PA |
95 | untested "attach-stopped.exp (unthreaded)" |
96 | return -1 | |
a0ef4274 DJ |
97 | } |
98 | ||
99 | corefunc nonthreaded | |
100 | ||
101 | # build the test case first without threads | |
102 | # | |
103 | if { [gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DUSE_THREADS}] != "" } { | |
c7a6ca08 PA |
104 | untested "attach-stopped.exp (threaded)" |
105 | return -1 | |
a0ef4274 DJ |
106 | } |
107 | ||
108 | corefunc threaded | |
109 | ||
110 | return 0 |