[Lldb-commits] [lldb] [LLDB] Display artificial __promise and __coro_frame variables. (PR #71928)

Haojian Wu via lldb-commits lldb-commits at lists.llvm.org
Fri Nov 10 06:16:43 PST 2023


https://github.com/hokein updated https://github.com/llvm/llvm-project/pull/71928

>From 1ac7e612bf6917af4e347407fb98affa9bb296c6 Mon Sep 17 00:00:00 2001
From: Haojian Wu <hokein.wu at gmail.com>
Date: Fri, 10 Nov 2023 12:35:10 +0100
Subject: [PATCH 1/2] [LLDB] Display artificial __promise and __coro_frame
 variables.

See the discussion in #69309.
---
 .../CPlusPlus/CPPLanguageRuntime.cpp                |  6 +++++-
 .../generic/coroutine_handle/TestCoroutineHandle.py | 13 ++++++++++++-
 .../generic/coroutine_handle/main.cpp               |  2 +-
 3 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.cpp b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.cpp
index c2488eaa9f5b50d..b5dfd07bdff2453 100644
--- a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.cpp
+++ b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.cpp
@@ -41,7 +41,11 @@ CPPLanguageRuntime::CPPLanguageRuntime(Process *process)
     : LanguageRuntime(process) {}
 
 bool CPPLanguageRuntime::IsAllowedRuntimeValue(ConstString name) {
-  return name == g_this;
+  // FIXME: use a list when the list grows more.
+  return name == g_this ||
+  // Artificial coroutine-related variables emitted by clang.
+         name == ConstString("__promise") ||
+         name == ConstString("__coro_frame");
 }
 
 bool CPPLanguageRuntime::GetObjectDescription(Stream &str,
diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/coroutine_handle/TestCoroutineHandle.py b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/coroutine_handle/TestCoroutineHandle.py
index 42ee32f9ccca58d..bcb1da6dc3838c8 100644
--- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/coroutine_handle/TestCoroutineHandle.py
+++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/coroutine_handle/TestCoroutineHandle.py
@@ -78,8 +78,19 @@ def do_test(self, stdlib_type):
                 ],
             )
 
-        # Run until after the `co_yield`
         process = self.process()
+
+        # Break at a coroutine body
+        lldbutil.continue_to_source_breakpoint(
+          self, process, "// Break at co_yield", lldb.SBFileSpec("main.cpp", False)
+        )
+        # Expect artificial variables to be displayed
+        self.expect(
+          "frame variable",
+          substrs=['__promise', '__coro_frame']
+        )
+
+        # Run until after the `co_yield`
         lldbutil.continue_to_source_breakpoint(
             self, process, "// Break after co_yield", lldb.SBFileSpec("main.cpp", False)
         )
diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/coroutine_handle/main.cpp b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/coroutine_handle/main.cpp
index 8cb81c3bc9f4c4e..4523b7c7baf80aa 100644
--- a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/coroutine_handle/main.cpp
+++ b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/coroutine_handle/main.cpp
@@ -33,7 +33,7 @@ struct int_generator {
   ~int_generator() { hdl.destroy(); }
 };
 
-int_generator my_generator_func() { co_yield 42; }
+int_generator my_generator_func() { co_yield 42; } // Break at co_yield
 
 // This is an empty function which we call just so the debugger has
 // a place to reliably set a breakpoint on.

>From d67d907cedbf20d656a4db0658f918e156714170 Mon Sep 17 00:00:00 2001
From: Haojian Wu <hokein.wu at gmail.com>
Date: Fri, 10 Nov 2023 15:16:08 +0100
Subject: [PATCH 2/2] Remove an unneeded FIXME.

---
 .../Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.cpp   | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.cpp b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.cpp
index b5dfd07bdff2453..2d14cf0d7a62add 100644
--- a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.cpp
+++ b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.cpp
@@ -41,9 +41,8 @@ CPPLanguageRuntime::CPPLanguageRuntime(Process *process)
     : LanguageRuntime(process) {}
 
 bool CPPLanguageRuntime::IsAllowedRuntimeValue(ConstString name) {
-  // FIXME: use a list when the list grows more.
   return name == g_this ||
-  // Artificial coroutine-related variables emitted by clang.
+         // Artificial coroutine-related variables emitted by clang.
          name == ConstString("__promise") ||
          name == ConstString("__coro_frame");
 }



More information about the lldb-commits mailing list