1 # Copyright (C) 2019-2020 Free Software Foundation, Inc.
2 # Copyright (C) 2019-2020 Advanced Micro Devices, Inc. All rights reserved.
4 # This file is part of GDB.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 set testfile "devicecode-breakpoint"
22 set srcfile ${srcdir}/${subdir}/${testfile}.cpp
23 set objfile [standard_output_file ${testfile}.o]
24 set binfile [standard_output_file ${testfile}]
27 set wave_id {(0,0,0)/2}
28 set rocm_threadno {1.3}
31 # Check if skip hip tests
32 if [skip_hipcc_tests] {
33 verbose "Skipping hip test: ${testfile}."
37 # Compile the hip program
38 if {[prepare_for_testing "failed to prepare ${testfile}" $testfile $srcfile {debug hip}]} {
44 # Load the hip program
45 if {[gdb_load ${binfile}] == -1} {
46 verbose "failed to load program ${testfile}."
50 # Run to main and break
52 fail "can't run to main and break in program ${testfile}."
57 #break <device_function_name>
58 #break bit_extract_kernel
59 # Set breakpoing in device code
60 gdb_breakpoint "bit_extract_kernel" "allow-pending"
62 # Do continue to check the breakpoint is created at device
63 gdb_test "c" {.+hit\sBreakpoint\s[\d].+\sbit_extract_kernel\s\(.*\)\sat.*}
65 clean_restart ${binfile}
69 #tbreak <device_function_name>
70 #tbreak bit_extract_kernel
71 gdb_breakpoint "bit_extract_kernel" "allow-pending" "temporary"
72 gdb_test "run" {.+hit\sTemporary\sbreakpoint\s[\d].+\sbit_extract_kernel\s\(.*\)\sat.*}
73 #controlling the timeout of the test as continue on device thread taking around 20-30s
75 gdb_test "continue" {.+Inferior\s[\d].+\sexited\snormally.+}
77 clean_restart ${binfile}
80 #break <file>:<lineNO>
81 #e.g. break bit_extract_compile:35
82 gdb_test_no_output "set environment HIP_ENABLE_DEFERRED_LOADING=0"
83 gdb_test "break $srcfile:$breakpoint_loc" "Breakpoint .* at .*${testfile}.*"
84 gdb_test "run" {.+hit\sBreakpoint\s[\d].+\sbit_extract_kernel\s\(.*\)\sat.*}
86 clean_restart ${binfile}
91 gdb_test_no_output "set environment HIP_ENABLE_DEFERRED_LOADING=0"
92 gdb_test "break $breakpoint_loc" "Breakpoint .* at .*${testfile}.*"
93 gdb_test "run" {.+hit\sBreakpoint\s[\d].+\sbit_extract_kernel\s\(.*\)\sat.*}
95 clean_restart ${binfile}
97 #Code to fetch threadno and corresponding wave_id
98 #Set breakpoing in device code
99 gdb_breakpoint "bit_extract_kernel" "allow-pending"
100 gdb_test "run" {.+hit\sBreakpoint\s\d+.+\sbit_extract_kernel\s\(.*\)\sat.*}
101 send_gdb "info threads\n"
102 gdb_expect -re "\\s+(\\d+)\\s+AMDGPU Thread\\s+(\\d+\.\\d+)\\s+(\\(\\d+,\\d+,\\d+\\)/\\d+).*$gdb_prompt $" {
103 set threadid "$expect_out(1,string)"
104 set rocm_threadno "$expect_out(2,string)"
105 set wave_id "$expect_out(3,string)"
108 verbose $rocm_threadno
111 regsub -all {[]*+.|()^$\[\\]} $wave_id {\\&} wave_id_re
114 clean_restart ${binfile}
118 #break <file>:<lineNO> <device thread condition>
119 #e.g. break bit_extract_compile:35 if $_thread==<threadno>
120 gdb_test_no_output "set environment HIP_ENABLE_DEFERRED_LOADING=0"
121 gdb_test "break $srcfile:$breakpoint_loc if \$_thread==$threadid" "Breakpoint .* at .*${testfile}.*"
122 gdb_test "run" ".+Thread.+$threadid.+hit.+Breakpoint.+${testfile}.cpp:$breakpoint_loc.*"
123 gdb_test "continue" {.+Inferior\s[\d].+\sexited\snormally.+}
126 clean_restart ${binfile}
128 #break <file>:<lineNO> <device thread condition>
129 #e.g. break bit_extract_compile:35 if $_streq($_wave_id,(0,0,1)/2)
130 gdb_test_no_output "set environment HIP_ENABLE_DEFERRED_LOADING=0"
131 gdb_test "break $srcfile:$breakpoint_loc if \$_streq(\$_wave_id,\"$wave_id\")" "Breakpoint .* at .*${testfile}.*"
132 gdb_test "run" ".+$wave_id_re.+Thread.+hit.+Breakpoint.+${testfile}.cpp:$breakpoint_loc.*"
133 gdb_test "continue" {.+Inferior\s[\d].+\sexited\snormally.+}
137 clean_restart ${binfile}
140 #enable\disable the breakpoint in device thread
141 #break <device_function_name>
142 #break bit_extract_kernel
143 #run //to hit the breakpoint in device thread
144 #disable <breakpoint no>
145 #continue //to exit inferior normally
146 #run //to check that test running without hitting any breakpoint as it disabled
147 #enable <breakpoint no>
148 ##run //to hit the breakpoint in device thread after enabling the breakpoint
150 # Set breakpoing in device code
151 gdb_breakpoint "bit_extract_kernel" "allow-pending"
153 # Do continue to check the breakpoint is created at device
154 gdb_test "run" {.+hit\sBreakpoint\s[\d].+\sbit_extract_kernel\s\(.*\)\sat.*}
156 gdb_test "continue" {.+Inferior\s[\d].+\sexited\snormally.+}
157 gdb_test "run" {.+Inferior\s[\d].+\sexited\snormally.+}
159 gdb_test "run" {.+hit\sBreakpoint\s[\d].+\sbit_extract_kernel\s\(.*\)\sat.*}
161 clean_restart ${binfile}
164 #clear the breakpoint in device thread
165 #break <file>:<lineNO>
166 #e.g. break bit_extract_compile:35
167 gdb_test_no_output "set environment HIP_ENABLE_DEFERRED_LOADING=0"
168 gdb_test "break $srcfile:$breakpoint_loc" "Breakpoint .* at .*${testfile}.*"
169 gdb_test "run" {.+hit\sBreakpoint\s[\d].+\sbit_extract_kernel\s\(.*\)\sat.*}
170 gdb_test "continue" {.+hit\sBreakpoint\s[\d].+\sbit_extract_kernel\s\(.*\)\sat.*}
171 gdb_test "clear $breakpoint_loc"
172 gdb_test "continue" {.+Inferior\s[\d].+\sexited\snormally.+}
175 clean_restart ${binfile}
177 #delete all the breakpoints in device thread
178 #break <file>:<lineNO>
179 #e.g. break bit_extract_compile:35
180 gdb_test_no_output "set environment HIP_ENABLE_DEFERRED_LOADING=0"
181 gdb_test "break $srcfile:$breakpoint_loc" "Breakpoint .* at .*${testfile}.*"
182 gdb_test "run" {.+hit\sBreakpoint\s[\d].+\sbit_extract_kernel\s\(.*\)\sat.*}
183 gdb_test "continue" {.+hit\sBreakpoint\s[\d].+\sbit_extract_kernel\s\(.*\)\sat.*}
186 gdb_test "continue" {.+Inferior\s[\d].+\sexited\snormally.+}
188 clean_restart ${binfile}
190 #delete single breakpoint in device thread
191 #break <file>:<lineNO>
192 #e.g. break bit_extract_compile:35
193 gdb_test_no_output "set environment HIP_ENABLE_DEFERRED_LOADING=0"
194 gdb_test "break $srcfile:$breakpoint_loc" "Breakpoint .* at .*${testfile}.*"
195 gdb_test "run" {.+hit\sBreakpoint\s[\d].+\sbit_extract_kernel\s\(.*\)\sat.*}
196 gdb_test "continue" {.+hit\sBreakpoint\s[\d].+\sbit_extract_kernel\s\(.*\)\sat.*}
198 gdb_test "continue" {.+Inferior\s[\d].+\sexited\snormally.+}
200 clean_restart ${binfile}
202 #disable the breakpoint in device thread and then delete_breakpoints
203 #break <device_function_name>
204 #break bit_extract_kernel
205 #run //to hit the breakpoint in device thread
206 #disable <breakpoint no>
207 #continue //to exit inferior normally
209 ##run //to hit the breakpoint in device thread after enabling the breakpoint
211 # Set breakpoing in device code
212 gdb_breakpoint "bit_extract_kernel" "allow-pending"
214 # Do continue to check the breakpoint is created at device
215 gdb_test "run" {.+hit\sBreakpoint\s[\d].+\sbit_extract_kernel\s\(.*\)\sat.*}
217 gdb_test "continue" {.+Inferior\s[\d].+\sexited\snormally.+}
219 gdb_test "run" {.+Inferior\s[\d].+\sexited\snormally.+}