diff options
author | Adrian Vogelsgesang <avogelsgesang@salesforce.com> | 2025-07-04 10:44:35 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-07-04 10:44:35 +0200 |
commit | de3c8410d87fa784bc97430ed759809cb942f894 (patch) | |
tree | b6baacab0edfc3fb86782872e8efacbabc7a9b27 /llvm/lib/IR/DebugInfoMetadata.cpp | |
parent | 2fcf1f8279b846930203fa05f71c6ade293709b1 (diff) | |
download | llvm-de3c8410d87fa784bc97430ed759809cb942f894.zip llvm-de3c8410d87fa784bc97430ed759809cb942f894.tar.gz llvm-de3c8410d87fa784bc97430ed759809cb942f894.tar.bz2 |
[debuginfo][coro] Emit debug info labels for coroutine resume points (#141937)
RFC on discourse:
https://discourse.llvm.org/t/rfc-debug-info-for-coroutine-suspension-locations-take-2/86606
With this commit, we add `DILabel` debug infos to the resume points of a
coroutine. Those labels can be used by debugging scripts to figure out
the exact line and column at which a coroutine was suspended by looking
up current `__coro_index` value inside the coroutines frame, and then
searching for the corresponding label inside the coroutine's resume
function.
The DWARF information generated for such a label looks like:
```
0x00000f71: DW_TAG_label
DW_AT_name ("__coro_resume_1")
DW_AT_decl_file ("generator-example.cpp")
DW_AT_decl_line (5)
DW_AT_decl_column (3)
DW_AT_artificial (true)
DW_AT_LLVM_coro_suspend_idx (0x01)
DW_AT_low_pc (0x00000000000019be)
```
The labels can be mapped to their corresponding `__coro_idx` values
either via their naming convention `__coro_resume_<N>` or using the new
`DW_AT_LLVM_coro_suspend_idx` attribute. In gdb, those line numebrs can
be looked up using `info line -function my_coroutine -label
__coro_resume_1`. LLDB unfortunately does not understand DW_TAG_label
debug information, yet.
Given this is an artificial compiler-generated label, I did apply the
DW_AT_artificial tag to it. The DWARFv5 standard only allows that tag on
type and variable definitions, but this is a natural extension and was
also blessed in the RFC on discourse.
Also, this commit adds `DW_AT_decl_column` to labels, not only for
coroutines but also for normal C and C++ labels. While not strictly
necessary, I am doing so now because it would be harder to do so later
without breaking the binary LLVM-IR format
Drive-by fixes: While reading the existing test cases to understand how
to write my own test case, I did a couple of small typo fixes and
comment improvements
Diffstat (limited to 'llvm/lib/IR/DebugInfoMetadata.cpp')
-rw-r--r-- | llvm/lib/IR/DebugInfoMetadata.cpp | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/llvm/lib/IR/DebugInfoMetadata.cpp b/llvm/lib/IR/DebugInfoMetadata.cpp index 8bfdb7d..2270923 100644 --- a/llvm/lib/IR/DebugInfoMetadata.cpp +++ b/llvm/lib/IR/DebugInfoMetadata.cpp @@ -1617,18 +1617,27 @@ std::optional<uint64_t> DIVariable::getSizeInBits() const { } DILabel::DILabel(LLVMContext &C, StorageType Storage, unsigned Line, + unsigned Column, bool IsArtificial, + std::optional<unsigned> CoroSuspendIdx, ArrayRef<Metadata *> Ops) : DINode(C, DILabelKind, Storage, dwarf::DW_TAG_label, Ops) { - SubclassData32 = Line; + this->SubclassData32 = Line; + this->Column = Column; + this->IsArtificial = IsArtificial; + this->CoroSuspendIdx = CoroSuspendIdx; } DILabel *DILabel::getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name, - Metadata *File, unsigned Line, StorageType Storage, - bool ShouldCreate) { + Metadata *File, unsigned Line, unsigned Column, + bool IsArtificial, + std::optional<unsigned> CoroSuspendIdx, + StorageType Storage, bool ShouldCreate) { assert(Scope && "Expected scope"); assert(isCanonical(Name) && "Expected canonical MDString"); - DEFINE_GETIMPL_LOOKUP(DILabel, (Scope, Name, File, Line)); + DEFINE_GETIMPL_LOOKUP( + DILabel, (Scope, Name, File, Line, Column, IsArtificial, CoroSuspendIdx)); Metadata *Ops[] = {Scope, Name, File}; - DEFINE_GETIMPL_STORE(DILabel, (Line), Ops); + DEFINE_GETIMPL_STORE(DILabel, (Line, Column, IsArtificial, CoroSuspendIdx), + Ops); } DIExpression *DIExpression::getImpl(LLVMContext &Context, |