Home | History | Annotate | Line # | Download | only in gdb.base
      1 # Copyright (C) 2021-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 that we can access memory while the inferior is running.
     17 
     18 standard_testfile
     19 
     20 if {[build_executable "failed to prepare" $testfile $srcfile {debug}] == -1} {
     21     return -1
     22 }
     23 
     24 # The test proper.  NON_STOP indicates whether we're testing in
     25 # non-stop, or all-stop mode.
     26 
     27 proc test { non_stop } {
     28     global srcfile binfile
     29     global gdb_prompt
     30     global GDBFLAGS
     31     global decimal
     32 
     33     save_vars { GDBFLAGS } {
     34       append GDBFLAGS " -ex \"set non-stop $non_stop\""
     35       clean_restart ${binfile}
     36     }
     37 
     38     if ![runto_main] {
     39 	return -1
     40     }
     41 
     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.
     44     if {!$non_stop
     45 	&& [target_info exists gdb_protocol]
     46 	&& ([target_info gdb_protocol] == "remote"
     47 	    || [target_info gdb_protocol] == "extended-remote")} {
     48 
     49 	if {![is_target_non_stop]} {
     50 	    unsupported "can't issue commands while target is running"
     51 	    return 0
     52 	}
     53     }
     54 
     55     delete_breakpoints
     56 
     57     if {$non_stop == "off"} {
     58 	set cmd "continue &"
     59     } else {
     60 	set cmd "continue -a &"
     61     }
     62     gdb_test_multiple $cmd "continuing" {
     63 	-re "Continuing\.\r\n$gdb_prompt " {
     64 	    pass $gdb_test_name
     65 	}
     66     }
     67 
     68     # Check we can read/write variables.
     69 
     70     # Check that we can read the counter variable, and that the
     71     # counter is increasing, meaning the process really is running.
     72 
     73     sleep 1
     74     set global_counter1 \
     75 	[get_integer_valueof "global_counter" 0 \
     76 	     "get global_counter once"]
     77 
     78     sleep 1
     79     set global_counter2 \
     80 	[get_integer_valueof "global_counter" 0 \
     81 	     "get global_counter twice"]
     82 
     83     gdb_assert {$global_counter1 != 0 \
     84 		    && $global_counter2 != 0 \
     85 		    && $global_counter1 != $global_counter2} \
     86 	"value changed"
     87 
     88     # Check that we can write variables.
     89 
     90     gdb_test "print global_var" " = 123" \
     91 	"print global_var before writing"
     92     gdb_test "print global_var = 321" " = 321" \
     93 	"write to global_var"
     94     gdb_test "print global_var" " = 321" \
     95 	"print global_var after writing"
     96     gdb_test "print global_var = 123" " = 123" \
     97 	"write to global_var again"
     98 
     99     # Check we can set a breakpoint while the process is running.  The
    100     # breakpoint should hit immediately.
    101     set any "\[^\r\n\]*"
    102 
    103     gdb_test_multiple "b maybe_stop_here" "" {
    104 	-re "Breakpoint $decimal at $any: file $any${srcfile}, line $decimal.\r\n$gdb_prompt " {
    105 	    pass $gdb_test_name
    106 	}
    107     }
    108     gdb_test_multiple "" "breakpoint hits" {
    109 	-re "Breakpoint $decimal, maybe_stop_here \\(\\) at $any${srcfile}:$decimal\r\n" {
    110 	    pass "$gdb_test_name"
    111 	}
    112     }
    113 }
    114 
    115 foreach non_stop { "off" "on" } {
    116     set stop_mode [expr ($non_stop=="off")?"all-stop":"non-stop"]
    117     with_test_prefix "$stop_mode" {
    118 	test $non_stop
    119     }
    120 }
    121