Commit | Line | Data |
---|---|---|
7b6bb8da | 1 | # Copyright 2008, 2009, 2010, 2011 Free Software Foundation, Inc. |
10568435 JK |
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 | set testfile randomize | |
17 | set srcfile ${testfile}.c | |
18 | set binfile ${objdir}/${subdir}/${testfile} | |
19 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { | |
20 | untested "Couldn't compile test program" | |
21 | return -1 | |
22 | } | |
23 | ||
24 | # Get things started. | |
25 | ||
26 | gdb_exit | |
27 | gdb_start | |
28 | gdb_reinitialize_dir $srcdir/$subdir | |
29 | gdb_load ${binfile} | |
30 | ||
31 | proc address_get { testname } { | |
32 | global gdb_prompt | |
33 | ||
34 | if {![runto_main]} { | |
35 | return -1 | |
36 | } | |
37 | ||
38 | # Do not rely on printf; some test configurations don't work with stdio. | |
39 | ||
40 | gdb_breakpoint [gdb_get_line_number "print p"] | |
41 | gdb_continue_to_breakpoint "$testname - address set" | |
42 | ||
43 | gdb_test_multiple "print/x p" $testname { | |
44 | -re "\\$\[0-9\]+ = (0x\[0-9a-f\]*)\r?\n$gdb_prompt $" { | |
45 | pass $testname | |
46 | return $expect_out(1,string) | |
47 | } | |
48 | } | |
49 | } | |
50 | ||
51 | set test "set disable-randomization off" | |
52 | gdb_test_multiple "${test}" "${test}" { | |
53 | -re "Disabling randomization .* unsupported .*$gdb_prompt $" { | |
b432ffe3 JK |
54 | untested "Disabling randomization is not supported on this Linux GDB" |
55 | return -1 | |
56 | } | |
57 | -re "No symbol .* in current context.*$gdb_prompt $" { | |
58 | untested "Disabling randomization is not supported on this GDB platform" | |
10568435 JK |
59 | return -1 |
60 | } | |
61 | -re "$gdb_prompt $" { | |
62 | pass $test | |
63 | } | |
64 | } | |
65 | gdb_test "show disable-randomization" \ | |
66 | "Disabling randomization .* is off." \ | |
67 | "show disable-randomization off" | |
68 | ||
69 | set addr1 [address_get "randomized first address"] | |
70 | set addr2 [address_get "randomized second address"] | |
71 | set test "randomized addresses should not match" | |
981505ef | 72 | if [string equal $addr1 $addr2] { |
10568435 JK |
73 | untested "No randomization detected on this system" |
74 | return -1 | |
75 | } else { | |
76 | pass $test | |
77 | } | |
78 | ||
27d3a1a2 | 79 | gdb_test_no_output "set disable-randomization on" |
10568435 JK |
80 | gdb_test "show disable-randomization" \ |
81 | "Disabling randomization .* is on." \ | |
82 | "show disable-randomization on" | |
83 | ||
84 | set addr1 [address_get "fixed first address"] | |
85 | set addr2 [address_get "fixed second address"] | |
86 | set test "fixed addresses should match" | |
981505ef | 87 | if [string equal $addr1 $addr2] { |
10568435 JK |
88 | pass $test |
89 | } else { | |
90 | fail $test | |
91 | } |