xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.base/print-symbol-loading.exp (revision 8e33eff89e26cf71871ead62f0d5063e1313c33a)
1# Copyright 2012-2023 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# Test the "print symbol-loading" option.
17
18if {[skip_shlib_tests]} {
19    return 0
20}
21
22standard_testfile print-symbol-loading-main.c
23set libfile print-symbol-loading-lib
24set srcfile_lib ${libfile}.c
25set binfile_lib [standard_output_file ${libfile}.so]
26set gcorefile ${binfile}.gcore
27set objfile [standard_output_file ${testfile}.o]
28
29if { [gdb_compile_shlib ${srcdir}/${subdir}/${srcfile_lib} ${binfile_lib} {debug}] != ""
30     || [gdb_compile ${srcdir}/${subdir}/${srcfile} ${objfile} object {debug}] != "" } {
31    untested "failed to compile"
32    return -1
33}
34set opts [list debug shlib=${binfile_lib}]
35if { [gdb_compile ${objfile} ${binfile} executable $opts] != "" } {
36    untested "failed to compile"
37    return -1
38}
39
40clean_restart ${binfile}
41gdb_load_shlib ${binfile_lib}
42
43if ![runto lib] {
44    return -1
45}
46
47if {![gdb_gcore_cmd $gcorefile "save a corefile"]} {
48    return -1
49}
50
51proc test_load_core { print_symbol_loading } {
52    global binfile binfile_lib gcorefile srcdir subdir
53    with_test_prefix "core ${print_symbol_loading}" {
54	gdb_exit
55	gdb_start
56	gdb_reinitialize_dir $srcdir/$subdir
57	gdb_test_no_output "set print symbol-loading $print_symbol_loading"
58	if { ${print_symbol_loading} != "off" } {
59	    gdb_test "file $binfile" "Reading symbols from.*" "file"
60	} else {
61	    gdb_test_no_output "file $binfile" "file"
62	}
63	# Rename the shared lib so gdb can't find it.
64	remote_exec host "mv -f ${binfile_lib} ${binfile_lib}.save"
65	gdb_test "core ${gcorefile}" "Core was generated by .*" \
66	    "re-load generated corefile"
67	# Now put it back and use "set solib-search-path" to trigger
68	# loading of symbols.
69	remote_exec host "mv -f ${binfile_lib}.save ${binfile_lib}"
70	set test_name "load shared-lib"
71	switch "${print_symbol_loading}" {
72	    "off" {
73		gdb_test_no_output "set solib-search-path [file dirname ${binfile_lib}]" \
74		    ${test_name}
75	    }
76	    "brief" {
77		gdb_test "set solib-search-path [file dirname ${binfile_lib}]" \
78		    "Loading symbols for shared libraries\\." \
79		    ${test_name}
80	    }
81	    "full" {
82		gdb_test "set solib-search-path [file dirname ${binfile_lib}]" \
83		    "Reading symbols from.*" \
84		    ${test_name}
85	    }
86	}
87	gdb_test "frame" "#0 \[^\r\n\]* lib .*" "library got loaded"
88    }
89}
90
91test_load_core off
92test_load_core brief
93test_load_core full
94
95# Now test the sharedlibrary command.
96
97proc test_load_shlib { print_symbol_loading } {
98    global binfile
99    global gdb_prompt
100    with_test_prefix "shlib ${print_symbol_loading}" {
101	clean_restart ${binfile}
102	gdb_test_no_output "set auto-solib-add off"
103	if ![runto_main] {
104	    return -1
105	}
106	gdb_test_no_output "set print symbol-loading $print_symbol_loading"
107	set test_name "load shared-lib"
108	switch ${print_symbol_loading} {
109	    "off" {
110		set cmd "sharedlibrary .*"
111		set cmd_regex [string_to_regexp $cmd]
112		gdb_test_multiple $cmd $test_name {
113		    -re "^$cmd_regex\r\n$gdb_prompt $" {
114			pass $test_name
115		    }
116		    -re "^$cmd_regex\r\nSymbols already loaded for\[^\r\n\]*\\/libc\\.\[^\r\n\]*\r\n$gdb_prompt $" {
117			pass $test_name
118		    }
119		}
120	    }
121	    "brief" {
122		gdb_test "sharedlibrary .*" \
123		    "Loading symbols for shared libraries: \\.\\*.*?(?:Symbols already loaded for .*?libc)?" \
124		    ${test_name}
125	    }
126	    "full" {
127		gdb_test "sharedlibrary .*" \
128		    "Reading symbols from.*" \
129		    ${test_name}
130	    }
131	}
132	gdb_breakpoint "lib"
133	gdb_continue_to_breakpoint "lib"
134	gdb_test "frame" "#0 \[^\r\n\]* lib .*" "library got loaded"
135    }
136}
137
138test_load_shlib off
139test_load_shlib brief
140test_load_shlib full
141