Home | History | Annotate | Line # | Download | only in gdb.base
access-mem-running.exp revision 1.1
      1 # Copyright (C) 2021-2023 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 	gdb_test_multiple "maint show target-non-stop" "" {
     50 	    -wrap -re "(is|currently) on.*" {
     51 	    }
     52 	    -wrap -re "(is|currently) off.*" {
     53 		unsupported "can't issue commands while target is running"
     54 		return 0
     55 	    }
     56 	}
     57     }
     58 
     59     delete_breakpoints
     60 
     61     if {$non_stop == "off"} {
     62 	set cmd "continue &"
     63     } else {
     64 	set cmd "continue -a &"
     65     }
     66     gdb_test_multiple $cmd "continuing" {
     67 	-re "Continuing\.\r\n$gdb_prompt " {
     68 	    pass $gdb_test_name
     69 	}
     70     }
     71 
     72     # Check we can read/write variables.
     73 
     74     # Check that we can read the counter variable, and that the
     75     # counter is increasing, meaning the process really is running.
     76 
     77     sleep 1
     78     set global_counter1 \
     79 	[get_integer_valueof "global_counter" 0 \
     80 	     "get global_counter once"]
     81 
     82     sleep 1
     83     set global_counter2 \
     84 	[get_integer_valueof "global_counter" 0 \
     85 	     "get global_counter twice"]
     86 
     87     gdb_assert {$global_counter1 != 0 \
     88 		    && $global_counter2 != 0 \
     89 		    && $global_counter1 != $global_counter2} \
     90 	"value changed"
     91 
     92     # Check that we can write variables.
     93 
     94     gdb_test "print global_var" " = 123" \
     95 	"print global_var before writing"
     96     gdb_test "print global_var = 321" " = 321" \
     97 	"write to global_var"
     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"
    102 
    103     # Check we can set a breakpoint while the process is running.  The
    104     # breakpoint should hit immediately.
    105     set any "\[^\r\n\]*"
    106 
    107     gdb_test_multiple "b maybe_stop_here" "" {
    108 	-re "Breakpoint $decimal at $any: file $any${srcfile}, line $decimal.\r\n$gdb_prompt " {
    109 	    pass $gdb_test_name
    110 	}
    111     }
    112     gdb_test_multiple "" "breakpoint hits" {
    113 	-re "Breakpoint $decimal, maybe_stop_here \\(\\) at $any${srcfile}:$decimal\r\n" {
    114 	    pass "$gdb_test_name"
    115 	}
    116     }
    117 }
    118 
    119 foreach non_stop { "off" "on" } {
    120     set stop_mode [expr ($non_stop=="off")?"all-stop":"non-stop"]
    121     with_test_prefix "$stop_mode" {
    122 	test $non_stop
    123     }
    124 }
    125