Adjust PC for abort trap (s_trap 2) to improve __builtin_verbose_trap support#199
Open
amd-bfilipov wants to merge 2 commits into
Open
Adjust PC for abort trap (s_trap 2) to improve __builtin_verbose_trap support#199amd-bfilipov wants to merge 2 commits into
amd-bfilipov wants to merge 2 commits into
Conversation
lancesix
reviewed
Jul 10, 2026
| containing DWARF debug info for verbose trap messages. | ||
|
|
||
| Do not adjust PC for abort traps when single-stepping, as stepping | ||
| has its own PC management logic. |
Collaborator
There was a problem hiding this comment.
The real question is: should we allow to single step past an abort? Is __builtin_verbose_trap marked noreturn?
| @@ -0,0 +1,12 @@ | |||
| #include <hip/hip_runtime.h> | |||
Collaborator
There was a problem hiding this comment.
Missing copyright header.
| { | ||
| test_trap_kernel<<<1, 1>>>(); | ||
| return hipDeviceSynchronize() != hipSuccess ? 1 : 0; | ||
| } |
Collaborator
There was a problem hiding this comment.
Coding style.
Should be
__global__ void
test_trap_kernel ()
{
__builtin_trap ();
}
int
main ()
{
test_trap_kernel<<<1, 1>>> ();
return hipDeviceSynchronize () != hipSuccess;
}When a wave stops with s_trap 2, rewind the PC by 4 bytes to point at the trap instruction, similar to breakpoint handling. This ensures the PC remains in the inlined DWARF frame containing debug info for __builtin_verbose_trap messages. Fixes: ROCM-22957
37f9101 to
998fd18
Compare
Test that __builtin_verbose_trap() correctly stops with PC pointing at the trap instruction. Related: ROCM-22957
998fd18 to
f65ff67
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ticket: AIROCGDB-558
Problem
When __builtin_verbose_trap() executes on AMD GPU, it generates an s_trap 2 instruction. After the trap, the
hardware increments the PC past the trap instruction, causing it to exit the inlined DWARF frame containing the
verbose trap message. This makes the error message invisible to the debugger.
Solution
Extend PC adjustment to include AMD_DBGAPI_WAVE_STOP_REASON_ASSERT_TRAP (s_trap 2), similar to existing breakpoint
handling. When a wave stops due to an abort trap, rewind the PC by 4 bytes to point at the trap instruction.
Rationale
We only apply PC adjustment to abort traps (s_trap 2) because:
Debug traps (s_trap 3) are intentionally excluded as they may have different resume semantics.
Testing
Added test case gdb.rocm/builtin_trap.exp to verify PC points to the trap instruction after stopping at
__builtin_trap().