[Lldb-commits] [lldb] [LLDB] Display artificial __promise and __coro_frame variables. (PR #71928)
Haojian Wu via lldb-commits
lldb-commits at lists.llvm.org
Mon Nov 13 06:25:24 PST 2023
https://github.com/hokein updated https://github.com/llvm/llvm-project/pull/71928
>From 08c3b1a40b508d360f47bed6d7d42050c18b01a0 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/4] [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 f684e1972eb3dc600603c67bf4a755d07971d7d2 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/4] 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");
}
>From 43ab6022f2a63a57d8195dcdd83b0c54ae66b1f6 Mon Sep 17 00:00:00 2001
From: Haojian Wu <hokein.wu at gmail.com>
Date: Mon, 13 Nov 2023 09:29:59 +0100
Subject: [PATCH 3/4] Use static constants for builtin variables.
---
.../LanguageRuntime/CPlusPlus/CPPLanguageRuntime.cpp | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.cpp b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.cpp
index 2d14cf0d7a62add..e65b99f44be6dc4 100644
--- a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.cpp
+++ b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.cpp
@@ -34,6 +34,9 @@ using namespace lldb;
using namespace lldb_private;
static ConstString g_this = ConstString("this");
+// Artificial coroutine-related variables emitted by clang.
+static ConstString g_promise = ConstString("__promise");
+static ConstString g_coro_frame = ConstString("__coro_frame");
char CPPLanguageRuntime::ID = 0;
@@ -41,10 +44,7 @@ CPPLanguageRuntime::CPPLanguageRuntime(Process *process)
: LanguageRuntime(process) {}
bool CPPLanguageRuntime::IsAllowedRuntimeValue(ConstString name) {
- return name == g_this ||
- // Artificial coroutine-related variables emitted by clang.
- name == ConstString("__promise") ||
- name == ConstString("__coro_frame");
+ return name == g_this || name == g_promise || name == g_coro_frame;
}
bool CPPLanguageRuntime::GetObjectDescription(Stream &str,
>From d77afeecd96941ca88ebd267ba65230313ac5357 Mon Sep 17 00:00:00 2001
From: Haojian Wu <hokein.wu at gmail.com>
Date: Mon, 13 Nov 2023 15:23:31 +0100
Subject: [PATCH 4/4] Break on the coroutine function, per a review comment.
---
.../generic/coroutine_handle/TestCoroutineHandle.py | 4 +++-
.../data-formatter-stl/generic/coroutine_handle/main.cpp | 2 +-
2 files changed, 4 insertions(+), 2 deletions(-)
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 bcb1da6dc3838c8..3659f97c4c9fb9c 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
@@ -82,8 +82,10 @@ def do_test(self, stdlib_type):
# Break at a coroutine body
lldbutil.continue_to_source_breakpoint(
- self, process, "// Break at co_yield", lldb.SBFileSpec("main.cpp", False)
+ self, process, "int_generator my_generator_func",
+ lldb.SBFileSpec("main.cpp", False)
)
+
# Expect artificial variables to be displayed
self.expect(
"frame variable",
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 4523b7c7baf80aa..8cb81c3bc9f4c4e 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; } // Break at co_yield
+int_generator my_generator_func() { co_yield 42; }
// This is an empty function which we call just so the debugger has
// a place to reliably set a breakpoint on.
More information about the lldb-commits
mailing list