xref: /netbsd-src/external/gpl3/gdb/dist/gdb/testsuite/gdb.base/skip-solib.exp (revision 8e33eff89e26cf71871ead62f0d5063e1313c33a)
1#   Copyright 2011-2024 Free Software Foundation, Inc.
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 was written by Justin Lebar. (justin.lebar@gmail.com)
17
18#
19# Tests skipping shared libraries.
20#
21
22# This only works on GNU/Linux.
23require isnative allow_shlib_tests
24require {!is_remote host}
25require {istarget *-linux*}
26
27set test "skip-solib"
28set srcfile_main "${test}-main.c"
29set executable_main ${test}-test
30set binfile_main [standard_output_file ${executable_main}]
31set srcfile_lib "${test}-lib.c"
32set libname "lib${test}"
33set binfile_lib [standard_output_file ${libname}.so]
34
35#
36# Compile our program under test.  The main program references a shared library
37# libskip-solib.so, which contains two functions, square(), which is
38# referenced by the main program, and multiply(), which is not referenced by
39# the main program.
40#
41
42if {[gdb_compile_shlib ${srcdir}/${subdir}/${srcfile_lib} ${binfile_lib} \
43	 [list debug]] != ""} {
44    return -1
45}
46
47if {[gdb_compile "${srcdir}/${subdir}/${srcfile_main}" "${binfile_main}.o" \
48	 object debug] != ""} {
49    return -1
50}
51
52set testobjdir [standard_output_file {}]
53if {[gdb_compile "${binfile_main}.o" "${binfile_main}" executable \
54	 [list debug shlib=$binfile_lib]] != ""} {
55    return -1
56}
57
58#
59# Test ignoring of a file inside a solib.
60#
61with_test_prefix "ignoring solib file" {
62
63    clean_restart ${executable_main}
64    gdb_load_shlib $binfile_lib
65
66    gdb_test "skip file ${srcfile_lib}" \
67	"File ${srcfile_lib} will be skipped when stepping." \
68	"skip file"
69
70    gdb_test "info skip" \
71	[multi_line \
72	     "Num\\s+Enb\\s+Glob\\s+File\\s+RE\\s+Function\\s*" \
73	     "1\\s+y\\s+n\\s+${srcfile_lib}\\s+n\\s+<none>\\s*"]
74
75    if ![runto_main] {
76	return
77    }
78
79    #
80    # We shouldn't step into square(), since we skipped skip-solib-lib.c.
81    #
82    gdb_test "step" ""
83    gdb_test "bt" "#0\\s+main.*"
84}
85
86#
87# Now test ignoring of a function inside a solib.
88#
89with_test_prefix "ignoring solib function" {
90    clean_restart ${executable_main}
91    gdb_load_shlib $binfile_lib
92
93    gdb_test "skip function multiply" \
94	"Function multiply will be skipped when stepping\\." \
95	"skip function"
96
97    if ![runto_main] {
98	return
99    }
100
101    #
102    # Our first step should take us into square.
103    #
104    gdb_test "step" "square.*" "step into other function"
105
106    gdb_test "info skip" \
107	[multi_line \
108	     "Num\\s+Enb\\s+Glob\\s+File\\s+RE\\s+Function\\s*" \
109	     "1\\s+y\\s+n\\s+<none>\\s+n\\s+multiply\\s*"]
110
111    #
112    # This step shouldn't go into multiply -- we should skip it and go on to
113    # the last line of square.
114    #
115    gdb_test "step" ""
116    gdb_test "bt" "#0\\s+square.*"
117}
118