]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/info-program.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / info-program.exp
1 # Copyright 1997-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 # Test "info program".
17 #
18 # We build both single-threaded and multi-threaded programs so that if
19 # the target doesn't support multi-threading, we still exercise the
20 # command.
21 #
22 # With the multi-threaded program, we test that in all-stop mode, GDB
23 # prints information about the last thread that stopped, not the
24 # current thread. In non-stop mode, the command always prints info
25 # about the selected thread, so we test that.
26
27 standard_testfile
28
29 # Run the test with the given parameters:
30 #
31 # - THREADS: threads flavor, either single-threaded or
32 # multi-threaded.
33 # - NON-STOP: "set non-stop" value, "on" or "off".
34
35 proc do_test { threads non-stop } {
36 save_vars { ::GDBFLAGS } {
37 append ::GDBFLAGS " -ex \"set non-stop ${non-stop}\""
38 clean_restart $::binfile-$threads
39 }
40
41 gdb_test "info program" \
42 "The program being debugged is not being run." \
43 "info program before run"
44
45 if { ![runto done] } {
46 return -1
47 }
48
49 if {${non-stop} == "on"} {
50 set thread_line "Selected"
51 } else {
52 set thread_line "Last stopped for"
53 }
54
55 gdb_test "info program" \
56 [multi_line \
57 "$thread_line thread 1 (\[^\r\n\]+)\\." \
58 ".*" \
59 "Program stopped at $::hex\." \
60 "It stopped at breakpoint $::decimal\." \
61 "Type \"info stack\" or \"info registers\" for more information\."] \
62 "info program after run to main"
63
64 # We don't really care where this step lands, so long as GDB reports
65 # that the inferior stopped due to a step in the subsequent test.
66 gdb_test "next" ".*" "step before info program"
67
68 gdb_test "info program" \
69 [multi_line \
70 "$thread_line thread 1 (\[^\r\n\]+)\\." \
71 ".*" \
72 "Program stopped at $::hex\." \
73 "It stopped after being stepped\." \
74 "Type \"info stack\" or \"info registers\" for more information\."] \
75 "info program after next"
76
77 if {$threads == "mt"} {
78 gdb_test "thread 2" "\\\[Switching to thread 2 .*"
79
80 if {${non-stop} == "on"} {
81 gdb_test "info program" \
82 [multi_line \
83 "$thread_line thread 2 (\[^\r\n\]+)\\." \
84 "Selected thread is running\\."] \
85 "info program after next, other thread"
86 } else {
87 gdb_test "info program" \
88 [multi_line \
89 "$thread_line thread 1 (\[^\r\n\]+)\\." \
90 ".*" \
91 "Program stopped at $::hex\." \
92 "It stopped after being stepped\." \
93 "Type \"info stack\" or \"info registers\" for more information\."] \
94 "info program after next, other thread"
95 }
96 }
97
98 gdb_test "kill" "" "kill program" \
99 "Kill the program being debugged.*y or n. $" "y"
100
101 gdb_test "info program" "The program being debugged is not being run." \
102 "info program, after kill"
103
104 if { ![runto done] } {
105 return -1
106 }
107
108 delete_breakpoints
109
110 gdb_test "info program" \
111 [multi_line \
112 "$thread_line thread 1 (\[^\r\n\]+)\\." \
113 ".*" \
114 "Program stopped at $::hex\." \
115 "It stopped at a breakpoint that has since been deleted\." \
116 "Type \"info stack\" or \"info registers\" for more information\."] \
117 "info program after deleting all breakpoints"
118 }
119
120 # Build executables and test them, one for each
121 # single-thread/multi-thread flavor.
122 foreach_with_prefix threads {st mt} {
123 set opts {debug}
124 if {$threads == "mt"} {
125 lappend opts pthreads "additional_flags=-DUSE_THREADS"
126 }
127
128 if { [build_executable "failed to prepare $threads" \
129 ${testfile}-${threads} ${srcfile} $opts] } {
130 continue
131 }
132
133 foreach_with_prefix non-stop {on off} {
134 do_test ${threads} ${non-stop}
135 }
136 }