1 # Copyright 1997-2024 Free Software Foundation, Inc.
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.
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.
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/>.
16 # Test "info program".
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
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.
29 # Run the test with the given parameters:
31 # - THREADS: threads flavor, either single-threaded or
33 # - NON-STOP: "set non-stop" value, "on" or "off".
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
41 gdb_test "info program" \
42 "The program being debugged is not being run." \
43 "info program before run"
45 if { ![runto done] } {
49 if {${non-stop} == "on"} {
50 set thread_line "Selected"
52 set thread_line "Last stopped for"
55 gdb_test "info program" \
57 "$thread_line thread 1 (\[^\r\n\]+)\\." \
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"
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"
68 gdb_test "info program" \
70 "$thread_line thread 1 (\[^\r\n\]+)\\." \
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"
77 if {$threads == "mt"} {
78 gdb_test "thread 2" "\\\[Switching to thread 2 .*"
80 if {${non-stop} == "on"} {
81 gdb_test "info program" \
83 "$thread_line thread 2 (\[^\r\n\]+)\\." \
84 "Selected thread is running\\."] \
85 "info program after next, other thread"
87 gdb_test "info program" \
89 "$thread_line thread 1 (\[^\r\n\]+)\\." \
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"
98 gdb_test "kill" "" "kill program" \
99 "Kill the program being debugged.*y or n. $" "y"
101 gdb_test "info program" "The program being debugged is not being run." \
102 "info program, after kill"
104 if { ![runto done] } {
110 gdb_test "info program" \
112 "$thread_line thread 1 (\[^\r\n\]+)\\." \
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"
120 # Build executables and test them, one for each
121 # single-thread/multi-thread flavor.
122 foreach_with_prefix threads {st mt} {
124 if {$threads == "mt"} {
125 lappend opts pthreads "additional_flags=-DUSE_THREADS"
128 if { [build_executable "failed to prepare $threads" \
129 ${testfile}-${threads} ${srcfile} $opts] } {
133 foreach_with_prefix non-stop {on off} {
134 do_test ${threads} ${non-stop}