1 1.1.1.2 christos # Copyright (C) 2021-2024 Free Software Foundation, Inc. 2 1.1 christos 3 1.1 christos # This program is free software; you can redistribute it and/or modify 4 1.1 christos # it under the terms of the GNU General Public License as published by 5 1.1 christos # the Free Software Foundation; either version 3 of the License, or 6 1.1 christos # (at your option) any later version. 7 1.1 christos # 8 1.1 christos # This program is distributed in the hope that it will be useful, 9 1.1 christos # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 1.1 christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 1.1 christos # GNU General Public License for more details. 12 1.1 christos # 13 1.1 christos # You should have received a copy of the GNU General Public License 14 1.1 christos # along with this program. If not, see <http://www.gnu.org/licenses/>. 15 1.1 christos 16 1.1 christos # Test that we can access memory while the inferior is running. 17 1.1 christos 18 1.1 christos standard_testfile 19 1.1 christos 20 1.1 christos if {[build_executable "failed to prepare" $testfile $srcfile {debug}] == -1} { 21 1.1 christos return -1 22 1.1 christos } 23 1.1 christos 24 1.1 christos # The test proper. NON_STOP indicates whether we're testing in 25 1.1 christos # non-stop, or all-stop mode. 26 1.1 christos 27 1.1 christos proc test { non_stop } { 28 1.1 christos global srcfile binfile 29 1.1 christos global gdb_prompt 30 1.1 christos global GDBFLAGS 31 1.1 christos global decimal 32 1.1 christos 33 1.1 christos save_vars { GDBFLAGS } { 34 1.1 christos append GDBFLAGS " -ex \"set non-stop $non_stop\"" 35 1.1 christos clean_restart ${binfile} 36 1.1 christos } 37 1.1 christos 38 1.1 christos if ![runto_main] { 39 1.1 christos return -1 40 1.1 christos } 41 1.1 christos 42 1.1 christos # If debugging with target remote, check whether the all-stop variant 43 1.1 christos # of the RSP is being used. If so, we can't run the background tests. 44 1.1 christos if {!$non_stop 45 1.1 christos && [target_info exists gdb_protocol] 46 1.1 christos && ([target_info gdb_protocol] == "remote" 47 1.1 christos || [target_info gdb_protocol] == "extended-remote")} { 48 1.1 christos 49 1.1.1.2 christos if {![is_target_non_stop]} { 50 1.1.1.2 christos unsupported "can't issue commands while target is running" 51 1.1.1.2 christos return 0 52 1.1 christos } 53 1.1 christos } 54 1.1 christos 55 1.1 christos delete_breakpoints 56 1.1 christos 57 1.1 christos if {$non_stop == "off"} { 58 1.1 christos set cmd "continue &" 59 1.1 christos } else { 60 1.1 christos set cmd "continue -a &" 61 1.1 christos } 62 1.1 christos gdb_test_multiple $cmd "continuing" { 63 1.1 christos -re "Continuing\.\r\n$gdb_prompt " { 64 1.1 christos pass $gdb_test_name 65 1.1 christos } 66 1.1 christos } 67 1.1 christos 68 1.1 christos # Check we can read/write variables. 69 1.1 christos 70 1.1 christos # Check that we can read the counter variable, and that the 71 1.1 christos # counter is increasing, meaning the process really is running. 72 1.1 christos 73 1.1 christos sleep 1 74 1.1 christos set global_counter1 \ 75 1.1 christos [get_integer_valueof "global_counter" 0 \ 76 1.1 christos "get global_counter once"] 77 1.1 christos 78 1.1 christos sleep 1 79 1.1 christos set global_counter2 \ 80 1.1 christos [get_integer_valueof "global_counter" 0 \ 81 1.1 christos "get global_counter twice"] 82 1.1 christos 83 1.1 christos gdb_assert {$global_counter1 != 0 \ 84 1.1 christos && $global_counter2 != 0 \ 85 1.1 christos && $global_counter1 != $global_counter2} \ 86 1.1 christos "value changed" 87 1.1 christos 88 1.1 christos # Check that we can write variables. 89 1.1 christos 90 1.1 christos gdb_test "print global_var" " = 123" \ 91 1.1 christos "print global_var before writing" 92 1.1 christos gdb_test "print global_var = 321" " = 321" \ 93 1.1 christos "write to global_var" 94 1.1 christos gdb_test "print global_var" " = 321" \ 95 1.1 christos "print global_var after writing" 96 1.1 christos gdb_test "print global_var = 123" " = 123" \ 97 1.1 christos "write to global_var again" 98 1.1 christos 99 1.1 christos # Check we can set a breakpoint while the process is running. The 100 1.1 christos # breakpoint should hit immediately. 101 1.1 christos set any "\[^\r\n\]*" 102 1.1 christos 103 1.1 christos gdb_test_multiple "b maybe_stop_here" "" { 104 1.1 christos -re "Breakpoint $decimal at $any: file $any${srcfile}, line $decimal.\r\n$gdb_prompt " { 105 1.1 christos pass $gdb_test_name 106 1.1 christos } 107 1.1 christos } 108 1.1 christos gdb_test_multiple "" "breakpoint hits" { 109 1.1 christos -re "Breakpoint $decimal, maybe_stop_here \\(\\) at $any${srcfile}:$decimal\r\n" { 110 1.1 christos pass "$gdb_test_name" 111 1.1 christos } 112 1.1 christos } 113 1.1 christos } 114 1.1 christos 115 1.1 christos foreach non_stop { "off" "on" } { 116 1.1 christos set stop_mode [expr ($non_stop=="off")?"all-stop":"non-stop"] 117 1.1 christos with_test_prefix "$stop_mode" { 118 1.1 christos test $non_stop 119 1.1 christos } 120 1.1 christos } 121