# Copyright (C) 2019-2024 Free Software Foundation, Inc. # Copyright (C) 2019-2024 Advanced Micro Devices, Inc. All rights reserved. # This file is part of GDB. # 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 . load_lib rocm.exp require allow_hip_tests standard_testfile .cpp set breakpoint_loc [gdb_get_line_number "location line"] set threadid 16 set num_waves 16 # Some GPUs have 32 lanes per wave, while others have 64. Use 32 # threads per block so that we can control number of waves using the # number of blocks on all GPUs. set options [list \ debug \ hip \ additional_flags=-DGRID_DIM=$num_waves \ additional_flags=-DBLOCK_DIM=32 \ ] if {[prepare_for_testing "failed to prepare ${testfile}" \ $testfile $srcfile $options]} { return -1 } with_rocm_gpu_lock { if ![runto_main] { fail "can't run to main" return -1 } # Set breakpoint in device code function in hip. gdb_breakpoint "bit_extract_kernel" "allow-pending" gdb_test "c" {.+hit\sBreakpoint\s[\d].+\sbit_extract_kernel\s\(.*\)\sat.*} # Until tests and other tests after turning on scheduler-locking. with_test_prefix "until with scheduler-locking on" { gdb_test_no_output "set scheduler-locking on" gdb_test "info line" "Line $breakpoint_loc.*" gdb_test "until [expr $breakpoint_loc+3]" \ "bit_extract_kernel.+${testfile}.cpp:[expr $breakpoint_loc+3].+[expr $breakpoint_loc+3].*" gdb_test "info line" "Line [expr $breakpoint_loc+3].*" \ "info line at breakpoint_loc + 3" gdb_test_no_output "set scheduler-locking off" gdb_test "clear bit_extract_kernel" gdb_test "continue" {.+Inferior\s[\d].+\sexited\snormally.+} } # Until tests without specifying location. with_test_prefix "until without location; scheduler-locking on" { clean_restart ${binfile} gdb_breakpoint "bit_extract_kernel" "allow-pending" gdb_test "run" {.+hit\sBreakpoint\s[\d].+\sbit_extract_kernel\s\(.*\)\sat.*} gdb_test_no_output "set scheduler-locking on" gdb_test "info line" "Line $breakpoint_loc.*" # Under optimization the compiler may merge or reorder statements, # so "until" can land one line further than at -O0. Use the # no_optimized_code predicate (rather than a hand-written flag # check) so any optimization level relaxes the expected line range. if {![no_optimized_code]} { set pattern "([expr {$breakpoint_loc + 1}]|[expr {$breakpoint_loc + 2}])" set test_name "info line at breakpoint_loc + 1 or 2 lines" } else { set pattern "[expr {$breakpoint_loc + 1}]" set test_name "info line at breakpoint_loc + 1" } # Anchor the matched line number with a non-digit so a two-digit # number does not accidentally match a longer one (e.g. line 43 # matching line 430). gdb_test "until" "\[^\r\n\]*$pattern\[^0-9\].*" gdb_test "info line" "Line $pattern\[^0-9\].*" $test_name gdb_test_no_output "set scheduler-locking off" gdb_test "clear bit_extract_kernel" gdb_test "continue" {.+Inferior\s[\d].+\sexited\snormally.+} } # Until tests and other tests after setting conditional breakpoint on AMDGPU thread. with_test_prefix "until after conditional breakpoint" { clean_restart ${binfile} gdb_breakpoint "$srcfile:$breakpoint_loc if \$_thread==$threadid" allow-pending gdb_test "run" \ ".+Thread.+$threadid.+hit.+Breakpoint.+${testfile}.cpp:$breakpoint_loc.*" gdb_test "info line" "Line $breakpoint_loc.*" gdb_test "until [expr $breakpoint_loc+3]" \ "bit_extract_kernel.+${testfile}.cpp:[expr $breakpoint_loc+3].+[expr $breakpoint_loc+3].*" gdb_test "info line" "Line [expr $breakpoint_loc+3].*" \ "info line at breakppoint_loc + 3" gdb_test "continue" {.+Inferior\s[\d].+\sexited\snormally.+} } # Run and wait until all threads/waves report a breakpoint hit. proc run_and_wait {test} { global gdb_prompt global num_waves set hits 0 # Use background "run" so that we get the prompt immediately. gdb_test_multiple "run&" $test { -re "$gdb_prompt" { gdb_test_multiple "" $test { -re "hit Breakpoint \[1-9\]" { incr hits if {$hits < $num_waves} { exp_continue } else { pass $gdb_test_name } } } } } } # Until and other tests in non-stop mode. with_test_prefix "until with non-stop on" { clean_restart ${binfile} gdb_test_no_output "set non-stop on" gdb_breakpoint "bit_extract_kernel" "allow-pending" run_and_wait "run to bit_extract_kernel Breakpoint" gdb_test "thread $threadid" \ "Switching to thread $threadid, lane 0 \\(AMDGPU Lane .*" gdb_test "info line" "Line $breakpoint_loc.*" gdb_test "until [expr $breakpoint_loc+3]" \ "bit_extract_kernel.+${testfile}.cpp:[expr $breakpoint_loc+3].+[expr $breakpoint_loc+3].*" gdb_test "info line" "Line [expr $breakpoint_loc+3].*" \ "info line at breakpoint_loc + 3" gdb_test "continue -a" {.+Inferior\s[\d].+\sexited\snormally.+} } }