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