Adjust PC for abort trap (s_trap 2) to improve __builtin_verbose_trap support#199
Adjust PC for abort trap (s_trap 2) to improve __builtin_verbose_trap support#199amd-bfilipov wants to merge 2 commits into
Conversation
| 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. |
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,30 @@ | |||
| # Test that __builtin_trap PC is correctly adjusted | |||
There was a problem hiding this comment.
The file should have a copyright notice.
| gdb_test "x/i \$pc" \ | ||
| ".*s_trap.*" \ | ||
| "PC points to trap instruction" | ||
| } |
There was a problem hiding this comment.
If the core of GDB has some logic for single stepping & s_trap, we should probably test for it.
| program counter needs to be adjusted so that it points to the | ||
| breakpoint instruction. | ||
| /* If the wave is stopped because of a software breakpoint or an abort | ||
| trap (s_trap 2, used by __builtin_verbose_trap), the program counter |
There was a problem hiding this comment.
The test is not exercising __builtin_verbose_trap, it probably should.
| @@ -0,0 +1,12 @@ | |||
| #include <hip/hip_runtime.h> | |||
There was a problem hiding this comment.
Missing copyright header.
| { | ||
| test_trap_kernel<<<1, 1>>>(); | ||
| return hipDeviceSynchronize() != hipSuccess ? 1 : 0; | ||
| } |
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;
}| int main() | ||
| { | ||
| test_trap_kernel<<<1, 1>>>(); | ||
| return hipDeviceSynchronize() != hipSuccess ? 1 : 0; |
There was a problem hiding this comment.
not a big fan of the (foo ? 1 : 0). The 1 if true 0 otherwise is tautologic, this is how foo would convert to int anyway.
| return | ||
| } | ||
|
|
||
| # Continue to the trap |
There was a problem hiding this comment.
Missing period at the end of the sentence.
| "received trap signal" | ||
|
|
||
| # Check PC points to trap instruction | ||
| # If PC adjustment is working, PC should be at the s_trap instruction |
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
Test that __builtin_trap() correctly stops with PC pointing at the trap instruction. Related: ROCM-22957
37f9101 to
998fd18
Compare
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().