1 # Copyright (C) 2021-2023 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 that we can access memory while the inferior is running.
20 if {[build_executable "failed to prepare" $testfile $srcfile {debug}] == -1} {
24 # The test proper. NON_STOP indicates whether we're testing in
25 # non-stop, or all-stop mode.
27 proc test { non_stop } {
28 global srcfile binfile
33 save_vars { GDBFLAGS } {
34 append GDBFLAGS " -ex \"set non-stop $non_stop\""
35 clean_restart ${binfile}
42 # If debugging with target remote, check whether the all-stop variant
43 # of the RSP is being used. If so, we can't run the background tests.
45 && [target_info exists gdb_protocol]
46 && ([target_info gdb_protocol] == "remote"
47 || [target_info gdb_protocol] == "extended-remote")} {
49 gdb_test_multiple "maint show target-non-stop" "" {
50 -wrap -re "(is|currently) on.*" {
52 -wrap -re "(is|currently) off.*" {
53 unsupported "can't issue commands while target is running"
61 if {$non_stop == "off"} {
64 set cmd "continue -a &"
66 gdb_test_multiple $cmd "continuing" {
67 -re "Continuing\.\r\n$gdb_prompt " {
72 # Check we can read/write variables.
74 # Check that we can read the counter variable, and that the
75 # counter is increasing, meaning the process really is running.
79 [get_integer_valueof "global_counter" 0 \
80 "get global_counter once"]
84 [get_integer_valueof "global_counter" 0 \
85 "get global_counter twice"]
87 gdb_assert {$global_counter1 != 0 \
88 && $global_counter2 != 0 \
89 && $global_counter1 != $global_counter2} \
92 # Check that we can write variables.
94 gdb_test "print global_var" " = 123" \
95 "print global_var before writing"
96 gdb_test "print global_var = 321" " = 321" \
98 gdb_test "print global_var" " = 321" \
99 "print global_var after writing"
100 gdb_test "print global_var = 123" " = 123" \
101 "write to global_var again"
103 # Check we can set a breakpoint while the process is running. The
104 # breakpoint should hit immediately.
107 gdb_test_multiple "b maybe_stop_here" "" {
108 -re "Breakpoint $decimal at $any: file $any${srcfile}, line $decimal.\r\n$gdb_prompt " {
112 gdb_test_multiple "" "breakpoint hits" {
113 -re "Breakpoint $decimal, maybe_stop_here \\(\\) at $any${srcfile}:$decimal\r\n" {
114 pass "$gdb_test_name"
119 foreach non_stop { "off" "on" } {
120 set stop_mode [expr ($non_stop=="off")?"all-stop":"non-stop"]
121 with_test_prefix "$stop_mode" {