1 # Copyright 2012-2023 Free Software Foundation, Inc.
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.
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.
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/>.
16 # Test the "print symbol-loading" option.
18 if {[skip_shlib_tests]} {
22 standard_testfile print-symbol-loading-main.c
23 set libfile print-symbol-loading-lib
24 set srcfile_lib ${libfile}.c
25 set binfile_lib [standard_output_file ${libfile}.so]
26 set gcorefile ${binfile}.gcore
27 set objfile [standard_output_file ${testfile}.o]
29 if { [gdb_compile_shlib ${srcdir}/${subdir}/${srcfile_lib} ${binfile_lib} {debug}] != ""
30 || [gdb_compile ${srcdir}/${subdir}/${srcfile} ${objfile} object {debug}] != "" } {
31 untested "failed to compile"
34 set opts [list debug shlib=${binfile_lib}]
35 if { [gdb_compile ${objfile} ${binfile} executable $opts] != "" } {
36 untested "failed to compile"
40 clean_restart ${binfile}
41 gdb_load_shlib ${binfile_lib}
47 if {![gdb_gcore_cmd $gcorefile "save a corefile"]} {
51 proc test_load_core { print_symbol_loading } {
52 global binfile binfile_lib gcorefile srcdir subdir
53 with_test_prefix "core ${print_symbol_loading}" {
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"
61 gdb_test_no_output "file $binfile" "file"
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
69 remote_exec host "mv -f ${binfile_lib}.save ${binfile_lib}"
70 set test_name "load shared-lib"
71 switch "${print_symbol_loading}" {
73 gdb_test_no_output "set solib-search-path [file dirname ${binfile_lib}]" \
77 gdb_test "set solib-search-path [file dirname ${binfile_lib}]" \
78 "Loading symbols for shared libraries\\." \
82 gdb_test "set solib-search-path [file dirname ${binfile_lib}]" \
83 "Reading symbols from.*" \
87 gdb_test "frame" "#0 \[^\r\n\]* lib .*" "library got loaded"
95 # Now test the sharedlibrary command.
97 proc test_load_shlib { print_symbol_loading } {
100 with_test_prefix "shlib ${print_symbol_loading}" {
101 clean_restart ${binfile}
102 gdb_test_no_output "set auto-solib-add off"
106 gdb_test_no_output "set print symbol-loading $print_symbol_loading"
107 set test_name "load shared-lib"
110 "Symbols already loaded for\[^\r\n\]*\\/libc\\.\[^\r\n\]*(" \
111 "Symbols already loaded for\[^\r\n\]*\\/libpthread\\.\[^\r\n\]*)?"]
112 switch ${print_symbol_loading} {
114 set cmd "sharedlibrary .*"
115 set cmd_regex [string_to_regexp $cmd]
116 gdb_test_multiple $cmd $test_name {
117 -re "^$cmd_regex\r\n$gdb_prompt $" {
120 -re "^$cmd_regex\r\n$libc_re\r\n$gdb_prompt $" {
126 gdb_test "sharedlibrary .*" \
127 "Loading symbols for shared libraries: \\.\\*.*?(?:Symbols already loaded for .*?libc)?" \
131 gdb_test "sharedlibrary .*" \
132 "Reading symbols from.*" \
137 gdb_continue_to_breakpoint "lib"
138 gdb_test "frame" "#0 \[^\r\n\]* lib .*" "library got loaded"
143 test_load_shlib brief