1# Copyright 2008-2020 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
16standard_testfile
17
18if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
19    return -1
20}
21
22proc address_get { testname } {
23    global gdb_prompt
24
25    if {![runto_main]} {
26	return -1
27    }
28
29    # Do not rely on printf; some test configurations don't work with stdio.
30
31    gdb_breakpoint [gdb_get_line_number "print p"]
32    gdb_continue_to_breakpoint "$testname - address set"
33
34    gdb_test_multiple "print/x p" $testname {
35	-re "\\$\[0-9\]+ = (0x\[0-9a-f\]*)\r?\n$gdb_prompt $" {
36	    pass $testname
37	    return $expect_out(1,string)
38	}
39    }
40}
41
42set test "set disable-randomization off"
43gdb_test_multiple "${test}" "${test}" {
44    -re "Disabling randomization .* unsupported .*$gdb_prompt $" {
45	untested "disabling randomization is not supported on this Linux GDB"
46	return -1
47    }
48    -re "No symbol .* in current context.*$gdb_prompt $" {
49	untested "disabling randomization is not supported on this GDB platform"
50	return -1
51    }
52    -re "$gdb_prompt $" {
53	pass $test
54    }
55}
56gdb_test "show disable-randomization"	      \
57         "Disabling randomization .* is off." \
58         "show disable-randomization off"
59
60set addr1 [address_get "randomized first address"]
61set addr2 [address_get "randomized second address"]
62set test "randomized addresses should not match"
63if [string equal $addr1 $addr2] {
64    untested "no randomization detected on this system"
65    return -1
66} else {
67    pass $test
68}
69
70gdb_test_no_output "set disable-randomization on"
71gdb_test "show disable-randomization"	      \
72         "Disabling randomization .* is on." \
73         "show disable-randomization on"
74
75set addr1 [address_get "fixed first address"]
76set addr2 [address_get "fixed second address"]
77set test "fixed addresses should match"
78if [string equal $addr1 $addr2] {
79    pass $test
80} else {
81    fail $test
82}
83