[Coroutines] Use dbg.declare for frame variables
authorBrian Gesiak <modocache@gmail.com>
Wed, 26 Feb 2020 23:08:00 +0000 (18:08 -0500)
committerBrian Gesiak <modocache@gmail.com>
Tue, 3 Mar 2020 22:13:46 +0000 (17:13 -0500)
commitaa85b437a970a12b74a8793cbd98dbb2f95afb6d
tree67db116348a1bd53737d76adcfe67fa7b0aa1660
parent90e40a0bdab6ab50402235f88941a4b10f5a17da
[Coroutines] Use dbg.declare for frame variables

Summary:
https://gist.github.com/modocache/ed7c62f6e570766c0f39b35dad675c2f
is an example of a small C++ program that uses C++20 coroutines that
is difficult to debug, due to the loss of debug info for variables that
"spill" across coroutine suspension boundaries. This patch addresses
that issue by inserting 'llvm.dbg.declare' intrinsics that point the
debugger to the variables' location at an offset to the coroutine frame.

With this patch, I confirmed that running the 'frame variable' commands in
https://gist.github.com/modocache/ed7c62f6e570766c0f39b35dad675c2f at
the specified breakpoints results in the correct values being printed
for coroutine frame variables 'i' and 'j' when using an lldb built from
trunk, as well as with gdb 8.3 (lldb 9.0.1, however, could not print the
values). The added test case also verifies this improved behavior.

The existing coro-debug.ll test case is also modified to reflect the
locations at which Clang actually places calls to 'dbg.declare', and
additional checks are added to ensure this patch works as intended in that
example as well.

Reviewers: vsk, jmorse, GorNishanov, lewissbaker, wenlei

Subscribers: EricWF, aprantl, hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D75338
llvm/include/llvm/Transforms/Utils/Local.h
llvm/lib/Transforms/Coroutines/CoroFrame.cpp
llvm/lib/Transforms/Utils/Local.cpp
llvm/test/Transforms/Coroutines/coro-debug-frame-variable.ll [new file with mode: 0644]
llvm/test/Transforms/Coroutines/coro-debug.ll