]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/catch-load.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / catch-load.exp
CommitLineData
213516ef 1# Copyright 2012-2023 Free Software Foundation, Inc.
edcc5120
TT
2# This program is free software; you can redistribute it and/or modify
3# it under the terms of the GNU General Public License as published by
4# the Free Software Foundation; either version 3 of the License, or
5# (at your option) any later version.
6#
7# This program is distributed in the hope that it will be useful,
8# but WITHOUT ANY WARRANTY; without even the implied warranty of
9# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10# GNU General Public License for more details.
11#
12# You should have received a copy of the GNU General Public License
13# along with this program. If not, see <http://www.gnu.org/licenses/>.
14#
15
16if {[skip_shlib_tests]} {
5b362f04 17 untested "skipping shared library tests"
edcc5120
TT
18 return -1
19}
20
f76495c8 21standard_testfile .c
edcc5120 22if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug shlib_load}] != "" } {
5b362f04 23 untested "failed to compile"
edcc5120
TT
24 return -1
25}
26
27set testfile2 catch-load-so
28set srcfile2 ${testfile2}.c
f76495c8 29set binfile2 [standard_output_file ${testfile2}.so]
edcc5120
TT
30set binfile2_dlopen [shlib_target_file ${testfile2}.so]
31if { [gdb_compile_shlib "${srcdir}/${subdir}/${srcfile2}" ${binfile2} {debug}] != "" } {
5b362f04 32 untested "failed to compile shared library"
edcc5120
TT
33 return -1
34}
35
36# Run one set of tests.
37# SCENARIO is the name of the test scenario, it is just used in test
38# names.
39# KIND is passed to the "catch" command.
40# MATCH is a boolean saying whether we expect the catchpoint to be hit.
0a251e08
YQ
41proc one_catch_load_test {scenario kind match sostop} {
42 with_test_prefix "${scenario}" {
3608f86c 43 global testfile testfile2 binfile2 binfile2_dlopen
0a251e08 44 global decimal gdb_prompt
edcc5120 45
0a251e08 46 clean_restart $testfile
d9019901 47 gdb_load_shlib $binfile2
edcc5120 48
0a251e08 49 if {![runto_main]} {
0a251e08
YQ
50 return
51 }
edcc5120 52
0a251e08
YQ
53 gdb_breakpoint [gdb_get_line_number "final breakpoint here"]
54 gdb_test_no_output "set var libname = \"$binfile2_dlopen\""
55 gdb_test_no_output "set stop-on-solib-events $sostop"
56 gdb_test "catch $kind" "Catchpoint $decimal \\(.*\\)"
edcc5120 57
0a251e08 58 gdb_test_multiple "continue" "continue" {
57b0d98e 59 -re "Catchpoint $decimal\r\n.*loaded .*(\\\\|/)$testfile2.*\r\n.*$gdb_prompt $" {
0a251e08
YQ
60 if {$match} {
61 pass "continue"
62 } else {
63 fail "continue"
64 }
edcc5120 65 }
edcc5120 66
0a251e08
YQ
67 -re "Stopped due to shared library event.*\r\n$gdb_prompt $" {
68 if {$sostop} {
69 pass "continue"
70 } else {
71 fail "continue"
72 }
edcc5120 73 }
edcc5120 74
0a251e08
YQ
75 -re "Breakpoint $decimal, .*\r\n$gdb_prompt $" {
76 if {!$match} {
77 pass "continue"
78 } else {
79 fail "continue"
80 }
edcc5120 81 }
edcc5120 82
0a251e08
YQ
83 -re ".*$gdb_prompt $" {
84 fail "continue"
85 }
edcc5120
TT
86 }
87 }
0a251e08 88}
edcc5120
TT
89
90one_catch_load_test "plain load" "load" 1 0
91one_catch_load_test "plain load with stop-on-solib-events" "load" 1 1
92one_catch_load_test "rx load" "load $testfile2" 1 0
93one_catch_load_test "rx load with stop-on-solib-events" "load $testfile2" 1 1
94one_catch_load_test "non-matching load" "load zardoz" 0 0
95one_catch_load_test "non-matching load with stop-on-solib-events" \
96 "load zardoz" 0 1
97
98one_catch_load_test "plain unload" "unload" 1 0
99one_catch_load_test "plain unload with stop-on-solib-events" "unload" 1 1
100one_catch_load_test "rx unload" "unload $testfile2" 1 0
101one_catch_load_test "rx unload with stop-on-solib-events" \
102 "unload $testfile2" 1 1
103one_catch_load_test "non-matching unload" "unload zardoz" 0 0
104one_catch_load_test "non-matching unload with stop-on-solib-events" \
105 "unload zardoz" 0 1