]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.threads/attach-stopped.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.threads / attach-stopped.exp
1 # Copyright 2008-2024 Free Software Foundation, Inc.
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
21 require !use_gdb_stub isnative
22 require {!is_remote host}
23 require {istarget *-linux*}
24
25 standard_testfile
26 set escapedbinfile [string_to_regexp $binfile]
27
28 #execute_anywhere "rm -f ${binfile}"
29 remote_exec build "rm -f ${binfile}"
30 # For debugging this test
31 #
32 #log_user 1
33
34 proc corefunc { threadtype } {
35 global binfile
36 global escapedbinfile
37 global gdb_prompt
38
39 set test_spawn_id [spawn_wait_for_attach $binfile]
40 set testpid [spawn_id_get_pid $test_spawn_id]
41
42 # Stop the program
43 remote_exec build "kill -s STOP ${testpid}"
44
45 clean_restart $binfile
46
47 # Verify that we can attach to the stopped process.
48
49 set test "$threadtype: attach2 to stopped, after setting file"
50 gdb_test_multiple "attach $testpid" "$test" {
51 -re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*$gdb_prompt $" {
52 pass "$test"
53 }
54 }
55
56 # ".*sleep.*clone.*" would fail on s390x as bt stops at START_THREAD there.
57 if {[string equal $threadtype threaded]} {
58 gdb_test "thread apply all bt" ".*sleep.*start_thread.*" "$threadtype: attach2 to stopped bt"
59 } else {
60 gdb_test "bt" ".*sleep.*main.*" "$threadtype: attach2 to stopped bt"
61 }
62
63 gdb_exit
64
65 # Avoid some race:
66 sleep 2
67
68 # At this point, the process may be sleeping or T (Stopped) depending on
69 # the Linux kernel version. The behavior is not tested as it is not
70 # dependent on GDB.
71
72 kill_wait_spawned_process $test_spawn_id
73 }
74
75 # build the test case first without threads
76 #
77 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
78 untested "attach-stopped.exp (unthreaded)"
79 return -1
80 }
81
82 corefunc nonthreaded
83
84 # build the test case first without threads
85 #
86 if { [gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DUSE_THREADS}] != "" } {
87 untested "attach-stopped.exp (threaded)"
88 return -1
89 }
90
91 corefunc threaded