1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
|
# Copyright 2021-2024 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Test 'info sources' when the test file makes use of a shared
# library.
require allow_shlib_tests
set is_remote_target [is_remote target]
standard_testfile -test.c -lib.c
set solib_name [standard_output_file ${testfile}-lib.so]
if { [gdb_compile_shlib ${srcdir}/${subdir}/${srcfile2} ${solib_name} \
{debug}] != "" } {
untested "failed to compile shared library"
return -1
}
if {[gdb_compile ${srcdir}/${subdir}/${srcfile} ${binfile} executable \
[list debug shlib=${solib_name} ]] != ""} {
untested "failed to compile executable"
return -1
}
clean_restart ${binfile}
set solib_name [gdb_load_shlib $solib_name]
if ![runto foo] {
untested "failed to run to function foo"
return -1
}
# Invoke 'info sources EXTRA_ARGS' and extract the results.
# The results are then compared to the list ARGS.
#
# The list ARGS should consist of pairs of values, the first item being the
# path to an object file, and the second item being the name of a source file.
# This proc checks that source file was listed as being a source file for the
# given object file.
#
# If the name of the source file starts with the character "!" (exclamation
# character, without the quotes) then the check is inverted, that the source
# file is NOT listed for the given object file.
proc run_info_sources { extra_args args } {
global gdb_prompt srcdir subdir
global is_remote_target
with_test_prefix "args: ${extra_args}" {
# The results of running info sources will be placed into this local.
array set info_sources {}
# The command we are going to run.
set cmd "info sources ${extra_args}"
set command_regex [string_to_regexp $cmd]
# Run the command and extract the results into INFO_SOURCES.
set objfile_name ""
set source_files {}
set files {}
gdb_test_multiple $cmd "" {
-re "${command_regex}\r\n" {
exp_continue
}
-re "^(\[^\r\n\]+):\r\n" {
set objfile_name $expect_out(1,string)
if { $is_remote_target } {
set objfile_name [file tail $objfile_name]
}
exp_continue
}
-re "^\\(Full debug information has not yet been read for this file\\.\\)\r\n" {
exp_continue
}
-re "^\\(Objfile has no debug information\\.\\)\r\n" {
exp_continue
}
-re "^\r\n" {
exp_continue
}
-re "^$gdb_prompt $" {
pass $gdb_test_name
}
-re "^(\[^,\r\n\]+), " {
set f $expect_out(1,string)
lappend files $f
exp_continue
}
-re "^(\[^\r\n\]+)\r\n" {
if { $objfile_name == "" } {
fail "${gdb_test_name} (no objfile name)"
return
}
set f $expect_out(1,string)
lappend files $f
set info_sources($objfile_name) $files
set $objfile_name ""
set files {}
exp_continue
}
}
# Now check ARGS against the values held in INFO_SOURCES map.
foreach {objfile sourcefile} $args {
# First, figure out if we're expecting SOURCEFILE to be present,
# or not.
set present True
set match_type "is"
if {[string index $sourcefile 0] == "!"} {
set present False
set match_type "is not"
set sourcefile [string range $sourcefile 1 end]
}
# Figure out the path for SOURCEFILE that we're looking for.
set sourcepath [file normalize ${srcdir}/${subdir}/${sourcefile}]
if { $is_remote_target } {
set objfile [file tail $objfile]
}
# Make sure we handle the case where there are no source files
# associated with a particular objfile.
set source_list {}
if [info exists info_sources($objfile)] {
set source_list $info_sources($objfile)
}
# Now perform the search, and check the results.
set idx [lsearch -exact $source_list $sourcepath]
gdb_assert {($present && $idx >= 0) || (!$present && $idx == -1)} \
"source file '$sourcefile' ${match_type} present for '[file tail $objfile]'"
}
}
}
# The actual tests.
run_info_sources "" \
${binfile} ${srcfile} \
${binfile} ${testfile}-header.h \
${solib_name} ${srcfile2} \
${solib_name} ${testfile}-header.h
run_info_sources "-basename info_sources_2" \
${binfile} ${srcfile} \
${binfile} ${testfile}-header.h \
${solib_name} ${srcfile2} \
${solib_name} ${testfile}-header.h
run_info_sources "-basename \\.c" \
${binfile} ${srcfile} \
${binfile} !${testfile}-header.h \
${solib_name} ${srcfile2} \
${solib_name} !${testfile}-header.h
run_info_sources "-basename -- -test\\.c" \
${binfile} ${srcfile} \
${binfile} !${testfile}-header.h \
${solib_name} !${srcfile2} \
${solib_name} !${testfile}-header.h
run_info_sources "-basename -- -lib\\.c" \
${binfile} !${srcfile} \
${binfile} !${testfile}-header.h \
${solib_name} ${srcfile2} \
${solib_name} !${testfile}-header.h
|