[clang] [Clang][CodeGen] Emit “trap reasons” on UBSan traps (PR #145967)
Michael Buch via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 9 02:33:08 PDT 2025
Michael137 wrote:
Yea I think what we need is to just set the current DebugLocation. We usually do this using `ApplyDebugLocation::CreateArtificial` so that the artificial function we're generating has some artificial debug-location.
When I do this in `EmitCfiCheckFail` the crash disappears and we generate reasonable looking debug-info:
```
0x00000061: DW_TAG_subprogram
DW_AT_name ("__clang_trap_msg$Undefined Behavior Sanitizer$Control flow integrity check failed")
DW_AT_artificial (true)
DW_AT_external (true)
DW_AT_inline (DW_INL_inlined)
0x00000067: DW_TAG_subprogram
DW_AT_low_pc (0x0000000000000000)
DW_AT_high_pc (0x0000000000000043)
DW_AT_frame_base (DW_OP_reg7 RSP)
DW_AT_linkage_name ("__cfi_check_fail")
DW_AT_artificial (true)
DW_AT_external (true)
0x0000007a: DW_TAG_formal_parameter
DW_AT_location (DW_OP_reg5 RDI)
DW_AT_type (0x0000009a "void *")
DW_AT_artificial (true)
0x00000081: DW_TAG_formal_parameter
DW_AT_location (DW_OP_reg4 RSI)
DW_AT_type (0x0000009a "void *")
DW_AT_artificial (true)
0x00000088: DW_TAG_inlined_subroutine
DW_AT_abstract_origin (0x00000061 "__clang_trap_msg$Undefined Behavior Sanitizer$Control flow integrity check failed")
DW_AT_ranges (0x00000030
[0x0000000000000029, 0x0000000000000033)
[0x000000000000003e, 0x0000000000000043))
DW_AT_call_file ("clang/test/CodeGen/<stdin>")
DW_AT_call_line (0)
0x00000093: NULL
```
I.e., the artificial ubsan trap frame is inlined into `__cfi_check_fail`. We should probably follow-up on how this looks in LLDB. But off the top I think this should Just Work.
https://github.com/llvm/llvm-project/pull/145967
More information about the cfe-commits
mailing list