Skip to content

[LLDB] Display artificial __promise and __coro_frame variables. #71928

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 14, 2023

Conversation

hokein
Copy link
Collaborator

@hokein hokein commented Nov 10, 2023

See the discussion in #69309.

@hokein hokein requested a review from Michael137 November 10, 2023 11:46
@hokein
Copy link
Collaborator Author

hokein commented Nov 10, 2023

Is there a way to run the tests under lldb/test/API/ directory? ninja check-lldb doesn't seem to run these tests on my linux machine.

 ./bin/llvm-lit -sv  <llvm-project-path>/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/coroutine_handle/    

Testing Time: 0.02s

Total Discovered Tests: 1
  Unsupported: 1 (100.00%)

@hokein hokein marked this pull request as ready for review November 10, 2023 11:56
@hokein hokein requested a review from JDevlieghere as a code owner November 10, 2023 11:56
@llvmbot llvmbot added the lldb label Nov 10, 2023
@llvmbot
Copy link
Member

llvmbot commented Nov 10, 2023

@llvm/pr-subscribers-lldb

Author: Haojian Wu (hokein)

Changes

See the discussion in #69309.


Full diff: https://github.com/llvm/llvm-project/pull/71928.diff

3 Files Affected:

  • (modified) lldb/source/Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.cpp (+5-1)
  • (modified) lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/coroutine_handle/TestCoroutineHandle.py (+12-1)
  • (modified) lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/coroutine_handle/main.cpp (+1-1)
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.

Copy link

github-actions bot commented Nov 10, 2023

✅ With the latest revision this PR passed the Python code formatter.

Copy link

github-actions bot commented Nov 10, 2023

✅ With the latest revision this PR passed the C/C++ code formatter.

@Michael137
Copy link
Member

Is there a way to run the tests under lldb/test/API/ directory? ninja check-lldb doesn't seem to run these tests on my linux machine.

 ./bin/llvm-lit -sv  <llvm-project-path>/lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/coroutine_handle/    

Testing Time: 0.02s

Total Discovered Tests: 1
  Unsupported: 1 (100.00%)

Did you configure your build with LLDB_INCLUDE_TESTS=ON and LLDB_INCLUDE_PYTHON=ON? Those CMake variables are necessary to get the API tests to run

@@ -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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think we need this FIXME

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, removed.

@hokein
Copy link
Collaborator Author

hokein commented Nov 10, 2023

Did you configure your build with LLDB_INCLUDE_TESTS=ON and LLDB_INCLUDE_PYTHON=ON? Those CMake variables are necessary to get the API tests to run

Thanks! I was able to run the test locally now with -DLLDB_INCLUDE_TESTS=On, -DLLDB_ENABLE_PYTHON=On, and all deps installed (sudo apt-get install build-essential swig python3-dev libedit-dev).

@hokein hokein force-pushed the lldb-display-coroutines branch from d67d907 to 43ab602 Compare November 13, 2023 08:31
Copy link
Collaborator Author

@hokein hokein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the comments.

Copy link
Member

@Michael137 Michael137 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (once bots are happy). I think you may need to run git clang-format or python's black formatter

@hokein
Copy link
Collaborator Author

hokein commented Nov 14, 2023

Thanks for the review.

@hokein hokein merged commit b837361 into llvm:main Nov 14, 2023
@hokein hokein deleted the lldb-display-coroutines branch November 14, 2023 08:06
zahiraam pushed a commit to zahiraam/llvm-project that referenced this pull request Nov 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants