]>
Commit | Line | Data |
---|---|---|
618f726f | 1 | # Copyright 2015-2016 Free Software Foundation, Inc. |
df8411da SDJ |
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 | standard_testfile | |
17 | ||
7578d5f7 LM |
18 | # This test is Linux-only. |
19 | if ![istarget *-*-linux*] then { | |
20 | untested "coredump-filter.exp" | |
21 | return -1 | |
22 | } | |
23 | ||
df8411da | 24 | if { [prepare_for_testing "failed to prepare" $testfile $srcfile debug] } { |
df8411da SDJ |
25 | return -1 |
26 | } | |
27 | ||
28 | if { ![runto_main] } { | |
29 | untested "could not run to main" | |
30 | return -1 | |
31 | } | |
32 | ||
33 | gdb_breakpoint [gdb_get_line_number "break-here"] | |
34 | gdb_continue_to_breakpoint "break-here" ".* break-here .*" | |
35 | ||
422349a3 YQ |
36 | proc do_save_core { filter_flag core } { |
37 | verbose -log "writing $filter_flag to /proc/<inferior pid>/coredump_filter" | |
df8411da | 38 | |
422349a3 | 39 | gdb_test "p set_coredump_filter ($filter_flag)" " = 0" |
df8411da SDJ |
40 | |
41 | # Generate a corefile. | |
42 | gdb_gcore_cmd "$core" "save corefile" | |
43 | } | |
44 | ||
45 | proc do_load_and_test_core { core var working_var working_value } { | |
8cd8f2f8 | 46 | global hex decimal coredump_var_addr |
df8411da SDJ |
47 | |
48 | set core_loaded [gdb_core_cmd "$core" "load core"] | |
49 | if { $core_loaded == -1 } { | |
50 | fail "loading $core" | |
51 | return | |
52 | } | |
53 | ||
54 | # Access the memory the addresses point to. | |
8cd8f2f8 | 55 | gdb_test "print/x *(char *) $coredump_var_addr($var)" "\(\\\$$decimal = <error: \)?Cannot access memory at address $hex\(>\)?" \ |
df8411da | 56 | "printing $var when core is loaded (should not work)" |
8cd8f2f8 | 57 | gdb_test "print/x *(char *) $coredump_var_addr($working_var)" " = $working_value.*" \ |
df8411da SDJ |
58 | "print/x *$working_var ( = $working_value)" |
59 | } | |
60 | ||
61 | # We do not do file-backed mappings in the test program, but it is | |
62 | # important to test this anyway. One way of performing the test is to | |
63 | # load GDB with a corefile but without a binary, and then ask for the | |
64 | # disassemble of a function (i.e., the binary's .text section). GDB | |
65 | # should fail in this case. However, it must succeed if the binary is | |
66 | # provided along with the corefile. This is what we test here. | |
67 | ||
68 | proc test_disasm { core address should_fail } { | |
69 | global testfile hex | |
70 | ||
71 | # Restart GDB without loading the binary. | |
72 | with_test_prefix "no binary" { | |
73 | gdb_exit | |
74 | gdb_start | |
75 | ||
76 | set core_loaded [gdb_core_cmd "$core" "load core"] | |
77 | if { $core_loaded == -1 } { | |
78 | fail "loading $core" | |
79 | return | |
80 | } | |
81 | ||
82 | if { $should_fail == 1 } { | |
83 | gdb_test "x/i \$pc" "=> $hex:\tCannot access memory at address $hex" \ | |
84 | "disassemble function with corefile and without a binary" | |
85 | } else { | |
86 | gdb_test "x/i \$pc" "=> $hex:\t\[^C\].*" \ | |
87 | "disassemble function with corefile and without a binary" | |
88 | } | |
89 | } | |
90 | ||
91 | with_test_prefix "with binary" { | |
92 | clean_restart $testfile | |
93 | ||
94 | set core_loaded [gdb_core_cmd "$core" "load core"] | |
95 | if { $core_loaded == -1 } { | |
96 | fail "loading $core" | |
97 | return | |
98 | } | |
99 | ||
100 | gdb_test "disassemble $address" "Dump of assembler code for function.*" \ | |
101 | "disassemble function with corefile and with a binary" | |
102 | } | |
103 | } | |
104 | ||
105 | set non_private_anon_core [standard_output_file non-private-anon.gcore] | |
106 | set non_shared_anon_core [standard_output_file non-shared-anon.gcore] | |
107 | # A corefile without {private,shared} {anonymous,file-backed} pages | |
108 | set non_private_shared_anon_file_core [standard_output_file non-private-shared-anon-file.gcore] | |
109 | set dont_dump_core [standard_output_file dont-dump.gcore] | |
110 | ||
111 | # We will generate a few corefiles. | |
112 | # | |
113 | # This list is composed by sub-lists, and their elements are (in | |
114 | # order): | |
115 | # | |
116 | # - name of the test | |
117 | # - hexadecimal value to be put in the /proc/PID/coredump_filter file | |
118 | # - name of the variable that contains the name of the corefile to be | |
119 | # generated (including the initial $). | |
120 | # - name of the variable in the C source code that points to the | |
121 | # memory mapping that will NOT be present in the corefile. | |
122 | # - name of a variable in the C source code that points to a memory | |
123 | # mapping that WILL be present in the corefile | |
124 | # - corresponding value expected for the above variable | |
125 | # | |
126 | # This list refers to the corefiles generated by MAP_ANONYMOUS in the | |
127 | # test program. | |
128 | ||
129 | set all_anon_corefiles { { "non-Private-Anonymous" "0x7e" \ | |
130 | $non_private_anon_core \ | |
131 | "private_anon" \ | |
132 | "shared_anon" "0x22" } | |
133 | { "non-Shared-Anonymous" "0x7d" \ | |
134 | $non_shared_anon_core "shared_anon" \ | |
135 | "private_anon" "0x11" } | |
136 | { "DoNotDump" "0x33" \ | |
137 | $dont_dump_core "dont_dump" \ | |
138 | "shared_anon" "0x22" } } | |
139 | ||
140 | # If corefile loading is not supported, we do not even try to run the | |
141 | # tests. | |
142 | set core_supported [gdb_gcore_cmd "$non_private_anon_core" "save a corefile"] | |
143 | if { !$core_supported } { | |
144 | untested "corefile generation is not supported" | |
145 | return -1 | |
146 | } | |
147 | ||
df8411da | 148 | gdb_test_multiple "info inferiors" "getting inferior pid" { |
422349a3 | 149 | -re "process $decimal.*\r\n$gdb_prompt $" { |
df8411da | 150 | } |
7578d5f7 LM |
151 | -re "Remote target.*$gdb_prompt $" { |
152 | # If the target does not provide PID information (like usermode QEMU), | |
153 | # just bail out as the rest of the test may rely on it, giving spurious | |
154 | # failures. | |
155 | return -1 | |
156 | } | |
df8411da SDJ |
157 | } |
158 | ||
159 | # Get the main function's address. | |
160 | set main_addr "" | |
161 | gdb_test_multiple "print/x &main" "getting main's address" { | |
162 | -re "$decimal = \($hex\)\r\n$gdb_prompt $" { | |
163 | set main_addr $expect_out(1,string) | |
164 | } | |
165 | } | |
166 | ||
167 | # Obtain the address of each variable that will be checked on each | |
168 | # case. | |
f7797074 | 169 | unset -nocomplain coredump_var_addr |
df8411da SDJ |
170 | foreach item $all_anon_corefiles { |
171 | foreach name [list [lindex $item 3] [lindex $item 4]] { | |
172 | set test "print/x $name" | |
173 | gdb_test_multiple $test $test { | |
174 | -re " = \($hex\)\r\n$gdb_prompt $" { | |
8cd8f2f8 | 175 | set coredump_var_addr($name) $expect_out(1,string) |
df8411da SDJ |
176 | } |
177 | } | |
178 | } | |
179 | } | |
180 | ||
181 | # Generate corefiles for the "anon" case. | |
182 | foreach item $all_anon_corefiles { | |
183 | with_test_prefix "saving corefile for [lindex $item 0]" { | |
422349a3 | 184 | do_save_core [lindex $item 1] [subst [lindex $item 2]] |
df8411da SDJ |
185 | } |
186 | } | |
187 | ||
188 | with_test_prefix "saving corefile for non-Private-Shared-Anon-File" { | |
422349a3 | 189 | do_save_core "0x60" $non_private_shared_anon_file_core |
df8411da SDJ |
190 | } |
191 | ||
192 | clean_restart $testfile | |
193 | ||
194 | foreach item $all_anon_corefiles { | |
195 | with_test_prefix "loading and testing corefile for [lindex $item 0]" { | |
196 | do_load_and_test_core [subst [lindex $item 2]] [lindex $item 3] \ | |
197 | [lindex $item 4] [lindex $item 5] | |
198 | } | |
199 | ||
200 | with_test_prefix "disassembling function main for [lindex $item 0]" { | |
201 | test_disasm [subst [lindex $item 2]] $main_addr 0 | |
202 | } | |
203 | } | |
204 | ||
205 | with_test_prefix "loading and testing corefile for non-Private-Shared-Anon-File" { | |
206 | test_disasm $non_private_shared_anon_file_core $main_addr 1 | |
207 | } |