Commit | Line | Data |
---|---|---|
b811d2c2 | 1 | # Copyright (C) 2010-2020 Free Software Foundation, Inc. |
8a1ea21f DE |
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 | # This file is part of the GDB testsuite. It tests automagic loading of | |
17 | # scripts specified in the .debug_gdb_scripts section. | |
18 | ||
19 | # This test can only be run on targets which support ELF and use gas. | |
20 | # For now pick a sampling of likely targets. | |
21 | if {![istarget *-*-linux*] | |
22 | && ![istarget *-*-gnu*] | |
23 | && ![istarget *-*-elf*] | |
24 | && ![istarget *-*-openbsd*] | |
810cfdbb YQ |
25 | && ![istarget arm*-*-eabi*] |
26 | && ![istarget arm*-*-symbianelf*] | |
8a1ea21f DE |
27 | && ![istarget powerpc-*-eabi*]} { |
28 | verbose "Skipping py-section-script.exp because of lack of support." | |
29 | return | |
30 | } | |
31 | ||
b4a58790 TT |
32 | standard_testfile |
33 | ||
8448e842 TT |
34 | # Make this available to gdb before the program starts, it is |
35 | # automagically loaded by gdb. | |
36 | set remote_python_file [gdb_remote_download host \ | |
37 | ${srcdir}/${subdir}/${testfile}.py] | |
38 | ||
39 | set quoted_name "\"$remote_python_file\"" | |
40 | ||
41 | if {[build_executable $testfile.exp $testfile $srcfile \ | |
9f050062 DE |
42 | [list debug \ |
43 | additional_flags=-I${srcdir}/../../include \ | |
44 | additional_flags=-DSCRIPT_FILE=$quoted_name]] == -1} { | |
8a1ea21f DE |
45 | return -1 |
46 | } | |
47 | ||
ce77046a UW |
48 | # Start with a fresh gdb. |
49 | gdb_exit | |
50 | gdb_start | |
51 | ||
52 | # Skip all tests if Python scripting is not enabled. | |
53 | if { [skip_python_tests] } { continue } | |
54 | ||
8a1ea21f | 55 | gdb_reinitialize_dir $srcdir/$subdir |
9f050062 DE |
56 | |
57 | # Try first with a restrictive safe-path. | |
58 | ||
59 | gdb_test_no_output "set auto-load safe-path /restricted" \ | |
60 | "set restricted auto-load safe-path" | |
8a1ea21f DE |
61 | gdb_load ${binfile} |
62 | ||
9f050062 DE |
63 | # Verify gdb did not load the scripts. |
64 | set test_name "verify scripts not loaded" | |
65 | gdb_test_multiple "info auto-load python-scripts" "$test_name" { | |
66 | -re "Yes.*${testfile}.py.*Yes.*inlined-script.*$gdb_prompt $" { | |
67 | fail "$test_name" | |
68 | } | |
69 | -re "No.*${testfile}.py.*No.*inlined-script.*$gdb_prompt $" { | |
70 | pass "$test_name" | |
71 | } | |
72 | } | |
73 | ||
74 | # Try again with a working safe-path. | |
75 | ||
76 | gdb_exit | |
77 | gdb_start | |
78 | gdb_reinitialize_dir $srcdir/$subdir | |
79 | ||
74c2c1f4 SL |
80 | # Get the name of the binfile on the host; on a remote host this means |
81 | # stripping off any directory prefix. | |
82 | if [is_remote host] { | |
83 | set remote_binfile [file tail ${binfile}] | |
84 | } else { | |
85 | set remote_binfile ${binfile} | |
86 | } | |
87 | ||
88 | if [ishost *-*-mingw*] { | |
89 | set remote_pathsep ";" | |
90 | } else { | |
91 | set remote_pathsep ":" | |
92 | } | |
93 | gdb_test_no_output "set auto-load safe-path ${remote_python_file}${remote_pathsep}${remote_binfile}" \ | |
9f050062 DE |
94 | "set auto-load safe-path" |
95 | gdb_load ${binfile} | |
96 | ||
97 | # Verify gdb loaded each script and they appear once in the list. | |
98 | set test_name "verify scripts loaded" | |
99 | gdb_test_multiple "info auto-load python-scripts" "$test_name" { | |
74c2c1f4 SL |
100 | -re "Yes.*${testfile}.py.*Yes.*inlined-script.*$gdb_prompt $" { |
101 | pass "$test_name" | |
102 | } | |
9f050062 DE |
103 | -re "${testfile}.py.*${testfile}.py.*$gdb_prompt $" { |
104 | fail "$test_name" | |
105 | } | |
106 | -re "inlined-script.*inlined-script.*$gdb_prompt $" { | |
107 | fail "$test_name" | |
108 | } | |
9f050062 DE |
109 | } |
110 | ||
dbaefcf7 | 111 | # Again, with a regexp this time. |
8448e842 | 112 | gdb_test "info auto-load python-scripts ${testfile}" "Yes.*${testfile}.py.*" |
9f050062 | 113 | |
dbaefcf7 | 114 | # Again, with a regexp that matches no scripts. |
bf88dd68 | 115 | gdb_test "info auto-load python-scripts no-script-matches-this" \ |
dbaefcf7 DE |
116 | "No auto-load scripts matching no-script-matches-this." |
117 | ||
8a1ea21f DE |
118 | if ![runto_main] { |
119 | perror "couldn't run to main" | |
120 | return | |
121 | } | |
122 | ||
123 | gdb_test "b [gdb_get_line_number {break to inspect} ${testfile}.c ]" \ | |
124 | ".*Breakpoint.*" | |
125 | gdb_test "continue" ".*Breakpoint.*" | |
126 | ||
127 | gdb_test "print ss" " = a=<1> b=<2>" | |
9f050062 DE |
128 | |
129 | gdb_test "test-cmd 1 2 3" "test-cmd output, arg = 1 2 3" | |
ec13808e JK |
130 | |
131 | ||
132 | # eu-strip creates NOBITS .debug_gdb_scripts sections in the debug files. | |
133 | # Make sure those are ignored silently. | |
134 | ||
135 | with_test_prefix "sepdebug" { | |
136 | gdb_exit | |
137 | ||
138 | set result [catch "exec eu-strip -g -f ${binfile}.debug ${binfile}" output] | |
139 | verbose "result is $result" | |
140 | verbose "output is $output" | |
141 | if {$result != 0 || $output != ""} { | |
142 | unsupported "cannot produce separate debug info files" | |
143 | return | |
144 | } | |
145 | ||
146 | gdb_start | |
147 | gdb_reinitialize_dir $srcdir/$subdir | |
148 | ||
149 | gdb_test_no_output "set auto-load safe-path ${remote_python_file}:${binfile}" \ | |
150 | "set auto-load safe-path" | |
151 | set test "load sepdebug" | |
152 | gdb_test_multiple "file $binfile" $test { | |
153 | -re "\r\nwarning: Invalid entry in \\.debug_gdb_scripts section.*\r\n$gdb_prompt $" { | |
154 | fail $test | |
155 | } | |
3453e7e4 | 156 | -re "\r\n$gdb_prompt $" { |
ec13808e JK |
157 | pass $test |
158 | } | |
159 | } | |
160 | ||
161 | # Again, with a regexp this time. | |
162 | gdb_test "info auto-load python-scripts ${testfile}" "Yes.*${testfile}.py.*" | |
163 | ||
164 | # Again, with a regexp that matches no scripts. | |
165 | gdb_test "info auto-load python-scripts no-script-matches-this" \ | |
166 | "No auto-load scripts matching no-script-matches-this." | |
167 | } |