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