1# Copyright 2008-2020 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 tests setting breakpoints according to the full path of a
17# source file.
18
19standard_testfile
20
21# We rely on being able to copy things around.
22
23if { [is_remote host] } {
24    untested "setting breakpoints by full path"
25    return -1
26}
27
28# Create a temporary file in the build directory.  Use a different
29# filename in case ${srcdir} == ${objdir}.
30if { [catch {file copy -force ${srcdir}/${subdir}/${srcfile} \
31			      [standard_output_file tmp-${srcfile}]}] != 0 } {
32    error "Could not create temporary file"
33    return -1
34}
35
36# Build the test executable using an absolute path.
37if  { [gdb_compile [standard_output_file tmp-${srcfile}] "${binfile}" executable {debug}] != "" } {
38    return -1
39}
40
41# Unlike most GDB tests, we do not use gdb_reinitialize_dir in this script.
42# We're testing GDB's ability to find files in other ways.
43
44# Get the line number.
45
46set line [gdb_get_line_number "set breakpoint 1 here"]
47
48# Initialize GDB after getting the line number, to make sure
49# symbols aren't loaded.
50
51gdb_exit
52gdb_start
53gdb_load ${binfile}
54
55set msg "set breakpoint by full path before loading symbols - built absolute"
56if { [gdb_breakpoint [standard_output_file tmp-${srcfile}]:${line} {no-message}] != 0 } {
57    pass $msg
58} else {
59    fail $msg
60}
61
62gdb_test "break main" \
63	 "Breakpoint.*at.*line.*" "set breakpoint at main - built absolute"
64
65set msg "set breakpoint by full path after loading symbols - built absolute"
66if { [gdb_breakpoint [standard_output_file tmp-${srcfile}]:${line} {no-message}] != 0 } {
67    pass $msg
68} else {
69    fail $msg
70}
71
72# Build the test executable using a relative path.
73if  { [gdb_compile [relative_filename [pwd] [standard_output_file tmp-${srcfile}]] \
74	   "${binfile}" executable {debug}] != "" } {
75    return -1
76}
77
78gdb_exit
79gdb_start
80gdb_load ${binfile}
81
82set msg "set breakpoint by full path before loading symbols - built relative"
83if { [gdb_breakpoint [standard_output_file tmp-${srcfile}]:${line} {no-message}] != 0 } {
84    pass $msg
85} else {
86    fail $msg
87}
88
89gdb_test "break main" \
90	 "Breakpoint.*at.*line.*" "set breakpoint at main - built relative"
91
92set msg "set breakpoint by full path after loading symbols - built relative"
93if { [gdb_breakpoint [standard_output_file tmp-${srcfile}]:${line} {no-message}] != 0 } {
94    pass $msg
95} else {
96    fail $msg
97}
98
99# Build the test executable using relative paths not relative to the directory
100# we'll run GDB from.
101
102set save_pwd [pwd]
103cd [standard_output_file {}]
104if  { [gdb_compile [standard_output_file tmp-${srcfile}] "${testfile}" \
105	   executable {debug}] != "" } {
106    cd $save_pwd
107    return -1
108}
109cd $save_pwd
110
111gdb_exit
112gdb_start
113gdb_load ${binfile}
114
115set msg "set breakpoint by full path before loading symbols - built other"
116if { [gdb_breakpoint [standard_output_file tmp-${srcfile}]:${line} {no-message}] != 0 } {
117    pass $msg
118} else {
119    fail $msg
120}
121
122gdb_test "break main" \
123	 "Breakpoint.*at.*line.*" "set breakpoint at main - built other"
124
125set msg "set breakpoint by full path after loading symbols - built other"
126if { [gdb_breakpoint [standard_output_file tmp-${srcfile}]:${line} {no-message}] != 0 } {
127    pass $msg
128} else {
129    fail $msg
130}
131