Fix __builtin_verbose_trap support for GPU and CPU - #199
Conversation
998fd18 to
f65ff67
Compare
aktemur
left a comment
There was a problem hiding this comment.
Please squash the second patch to the second, so that the test accompanies the fix.
| # You should have received a copy of the GNU General Public License | ||
| # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
|
||
| # Test that __builtin_trap PC is correctly adjusted |
There was a problem hiding this comment.
The test is now using __builtin_verbose_trap, this test is about that.
| # If PC adjustment is working, PC should be at the s_trap instruction. | ||
| gdb_test "x/i \$pc" \ | ||
| ".*s_trap.*" \ | ||
| "PC points to trap instruction" |
There was a problem hiding this comment.
The main thing we'd want to test here is wether the current frame gives us the trap, i.e. does your message show un bt or similar message.
The expectation is to see that in the message with the SIGABRT signal, saying where we stopped.
f65ff67 to
994a6fa
Compare
c9f8030 to
60cbb93
Compare
lancesix
left a comment
There was a problem hiding this comment.
The test should exercise the stepping as well. And since you add host support, I suppose this should have a test as well.
87123a0 to
7e59e5d
Compare
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 Add test for s_trap 2 PC adjustment Test that __builtin_verbose_trap() correctly stops with PC pointing at the trap instruction. Related: ROCM-22957
7e59e5d to
a36876d
Compare
Implement architecture-specific control over inline frame visibility
for verbose trap scenarios using the gdbarch pattern.
Add new gdbarch method `show_verbose_trap_inline_frame` that allows
architectures to prevent skipping of compiler-generated inline frames
containing diagnostic information (e.g., __builtin_verbose_trap).
Changes:
- gdbarch_components.py: Define new Method `show_verbose_trap_inline_frame`
- arch-utils.{c,h}: Provide default implementation (returns false)
- amdgpu-tdep.c: Implement AMD GPU-specific version that detects
__clang_trap_msg$... frames by name pattern
- inline-frame.c: Call gdbarch hook in skip_inline_frames() loop
- gdbarch-gen.{c,h}: Regenerated from gdbarch_components.py
This approach keeps architecture-specific logic (GPU vs CPU) in
architecture-specific files, following GDB's design patterns.
Ticket: ROCM-22957 / AIROCGDB-558
a36876d to
1b9efda
Compare
__builtin_verbose_trap is a Clang builtin that allows embedding custom trap messages in the binary for better crash diagnostics. Add test for CPU (x86_64) __builtin_verbose_trap inline frame display. This complements the GPU test in gdb.rocm/builtin_verbose_trap.exp. The test verifies that: - Normal inline frames (add_numbers) are hidden during stepping - Verbose trap inline frame IS shown when trap fires with SIGILL - CPU uses ud2 instruction which generates SIGILL (unlike GPU s_trap which generates SIGABRT) Both GPU and CPU share the same DWARF pattern for verbose trap: __clang_trap_msg$<category>$<message>
Ok. Added another inline function to the test, so the test steps over it and checks whether regular inline frames stay hidden. |
|
I'm not intimately familiar with gdb, but the |
|
|
||
| When dealing with a corefile, it is expected that the PC has | ||
| been adjusted before generating the corefile, so no need to | ||
| re-do it now. */ | ||
| if ((stop_reason & AMD_DBGAPI_WAVE_STOP_REASON_BREAKPOINT) != 0 | ||
| if (((stop_reason & AMD_DBGAPI_WAVE_STOP_REASON_BREAKPOINT) != 0 | ||
| || (stop_reason & AMD_DBGAPI_WAVE_STOP_REASON_ASSERT_TRAP) != 0) |
There was a problem hiding this comment.
FYI, I am not sure this should be the way to go.
I have ROCm/rocm-systems#9776 to change the trap handler behaviour so this is not necessary. Such change would fix other issues reported independent to this PR.
There was a problem hiding this comment.
Re. the "gdb: Add gdbarch hook to show verbose trap inline frames" patch:
The commit log needs to be turned upside down.
This adds the gdbarch hook, yes, but it needs to begin by stating what the problem is, talk about __builtin_verbose_trap, show what goes wrong today without the fix.
I.e., establish rationale for why a change is needed.
Explain that this affects both CPU and GPU.
Then state how we're fixing this. The new gdbarch hook.
Ticket: AIROCGDB-558
Summary
Implements complete support for
__builtin_verbose_trapon both AMD GPU and CPU (x86_64), making verbose trap diagnostic messages visible in backtraces.Problem
When
__builtin_verbose_trapfired, the diagnostic inline frames were not visible in backtraces, making it impossible to see the trap category and message. Two issues prevented this:skip_inline_frames()intentionally hides inline frames to improve stepping experience, but this also hid the verbose trap framesSolution
This PR provides a two-part fix:
1. PC Adjustment for s_trap 2 (GPU)
Rewind PC by 4 bytes when a wave stops with s_trap 2, similar to breakpoint handling. This ensures the PC remains in the inlined DWARF frame containing
__builtin_verbose_trapdebug info.Files changed:
gdb/amd-dbgapi-target.c- PC adjustment logicgdb/testsuite/gdb.rocm/builtin_verbose_trap.{cpp,exp}- Test coverage2. gdbarch Hook for Inline Frame Control (GPU + CPU)
Adds architecture-specific control over inline frame visibility using GDB's gdbarch pattern. Architectures can now prevent skipping of compiler-generated inline frames containing diagnostic information.
Changes:
gdb/gdbarch_components.py- Defineshow_verbose_trap_inline_framemethodgdb/arch-utils.{c,h}- Default implementation (preserves current behavior)gdb/amdgpu-tdep.c- AMD GPU implementation (checksSIGABRT+ name pattern)gdb/amd64-linux-tdep.c- CPU x86_64 implementation (checksSIGILL+ name pattern)gdb/inline-frame.c- Call gdbarch hook in skip loopgdb/gdbarch-gen.{c,h}- Auto-generatedDetection logic:
SIGABRTfor GPU s_trap 2,SIGILLfor CPU ud2)__clang_trap_msg$<category>$<message>Results
Before:
After (GPU):
After (CPU):