Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / catch-load.exp
CommitLineData
88b9d363 1# Copyright 2012-2022 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
4c93b1db 21if {[get_compiler_info]} {
edcc5120 22 warning "Could not get compiler info"
5b362f04 23 untested "no compiler info"
edcc5120
TT
24 return -1
25}
26
f76495c8 27standard_testfile .c
edcc5120 28if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug shlib_load}] != "" } {
5b362f04 29 untested "failed to compile"
edcc5120
TT
30 return -1
31}
32
33set testfile2 catch-load-so
34set srcfile2 ${testfile2}.c
f76495c8 35set binfile2 [standard_output_file ${testfile2}.so]
edcc5120
TT
36set binfile2_dlopen [shlib_target_file ${testfile2}.so]
37if { [gdb_compile_shlib "${srcdir}/${subdir}/${srcfile2}" ${binfile2} {debug}] != "" } {
5b362f04 38 untested "failed to compile shared library"
edcc5120
TT
39 return -1
40}
41
42# Run one set of tests.
43# SCENARIO is the name of the test scenario, it is just used in test
44# names.
45# KIND is passed to the "catch" command.
46# MATCH is a boolean saying whether we expect the catchpoint to be hit.
0a251e08
YQ
47proc one_catch_load_test {scenario kind match sostop} {
48 with_test_prefix "${scenario}" {
3608f86c 49 global testfile testfile2 binfile2 binfile2_dlopen
0a251e08 50 global decimal gdb_prompt
edcc5120 51
0a251e08 52 clean_restart $testfile
d9019901 53 gdb_load_shlib $binfile2
edcc5120 54
0a251e08
YQ
55 if {![runto_main]} {
56 fail "can't run to main"
57 return
58 }
edcc5120 59
0a251e08
YQ
60 gdb_breakpoint [gdb_get_line_number "final breakpoint here"]
61 gdb_test_no_output "set var libname = \"$binfile2_dlopen\""
62 gdb_test_no_output "set stop-on-solib-events $sostop"
63 gdb_test "catch $kind" "Catchpoint $decimal \\(.*\\)"
edcc5120 64
0a251e08 65 gdb_test_multiple "continue" "continue" {
57b0d98e 66 -re "Catchpoint $decimal\r\n.*loaded .*(\\\\|/)$testfile2.*\r\n.*$gdb_prompt $" {
0a251e08
YQ
67 if {$match} {
68 pass "continue"
69 } else {
70 fail "continue"
71 }
edcc5120 72 }
edcc5120 73
0a251e08
YQ
74 -re "Stopped due to shared library event.*\r\n$gdb_prompt $" {
75 if {$sostop} {
76 pass "continue"
77 } else {
78 fail "continue"
79 }
edcc5120 80 }
edcc5120 81
0a251e08
YQ
82 -re "Breakpoint $decimal, .*\r\n$gdb_prompt $" {
83 if {!$match} {
84 pass "continue"
85 } else {
86 fail "continue"
87 }
edcc5120 88 }
edcc5120 89
0a251e08
YQ
90 -re ".*$gdb_prompt $" {
91 fail "continue"
92 }
edcc5120
TT
93 }
94 }
0a251e08 95}
edcc5120
TT
96
97one_catch_load_test "plain load" "load" 1 0
98one_catch_load_test "plain load with stop-on-solib-events" "load" 1 1
99one_catch_load_test "rx load" "load $testfile2" 1 0
100one_catch_load_test "rx load with stop-on-solib-events" "load $testfile2" 1 1
101one_catch_load_test "non-matching load" "load zardoz" 0 0
102one_catch_load_test "non-matching load with stop-on-solib-events" \
103 "load zardoz" 0 1
104
105one_catch_load_test "plain unload" "unload" 1 0
106one_catch_load_test "plain unload with stop-on-solib-events" "unload" 1 1
107one_catch_load_test "rx unload" "unload $testfile2" 1 0
108one_catch_load_test "rx unload with stop-on-solib-events" \
109 "unload $testfile2" 1 1
110one_catch_load_test "non-matching unload" "unload zardoz" 0 0
111one_catch_load_test "non-matching unload with stop-on-solib-events" \
112 "unload zardoz" 0 1
This page took 1.40365 seconds and 4 git commands to generate.