-
Notifications
You must be signed in to change notification settings - Fork 11.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[lldb-dap] Add frame recognizers for libc++
std::invoke
With this commit, we also hide the implementation details of `std::invoke`. To do so, the `LibCXXFrameRecognizer` got a couple more regular expressions. The regular expression passed into the `AddRecognizer` became problematic, as it was evaluated on the demangled name. Those names also included result types for C++ symbols. For `std::__invoke` the return type is a huge `decltype(...)`, making the regular expresison really hard to write. Instead, I added support for `AddRecognizer` to match on the demangled names without result type and argument types. By hiding the implementation details of `invoke`, also the back traces for `std::function` become even nicer, because `std::function` is using `__invoke` internally.
- Loading branch information
1 parent
b765fdd
commit 1836531
Showing
8 changed files
with
173 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
CXX_SOURCES := main.cpp | ||
USE_LIBCPP := 1 | ||
CXXFLAGS_EXTRAS := -std=c++17 | ||
|
||
include Makefile.rules |
28 changes: 28 additions & 0 deletions
28
lldb/test/API/lang/cpp/std-invoke-recognizer/TestStdInvokeRecognizer.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import lldb | ||
from lldbsuite.test.decorators import * | ||
from lldbsuite.test.lldbtest import * | ||
from lldbsuite.test import lldbutil | ||
|
||
|
||
class LibCxxStdFunctionRecognizerTestCase(TestBase): | ||
NO_DEBUG_INFO_TESTCASE = True | ||
|
||
@add_test_categories(["libc++"]) | ||
def test_frame_recognizer(self): | ||
"""Test that implementation details details of `std::invoke`""" | ||
self.build() | ||
(target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint( | ||
self, "// break here", lldb.SBFileSpec("main.cpp") | ||
) | ||
|
||
while process.GetState() != lldb.eStateExited: | ||
self.assertIn("print_num", thread.GetFrameAtIndex(0).GetFunctionName()) | ||
self.process.Continue() | ||
# # Skip all hidden frames | ||
# frame_id = 1 | ||
# while frame_id < thread.GetNumFrames() and thread.GetFrameAtIndex(frame_id).IsHidden(): | ||
# frame_id = frame_id + 1 | ||
# # Expect `std::function<...>::operator()` to be the direct parent of `foo` | ||
# self.assertIn("::operator()", thread.GetFrameAtIndex(frame_id).GetFunctionName()) | ||
# # And right above that, there should be the `main` frame | ||
# self.assertIn("main", thread.GetFrameAtIndex(frame_id + 1).GetFunctionName()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include <functional> | ||
#include <iostream> | ||
|
||
void print_num(int i) { | ||
// break here | ||
std::cout << i << '\n'; | ||
} | ||
|
||
int add(int i, int j) { | ||
// break here | ||
return i + j; | ||
} | ||
|
||
struct PrintAdder { | ||
PrintAdder(int num) : num_(num) {} | ||
void operator()(int i) const { | ||
// break here | ||
std::cout << i << '\n'; | ||
} | ||
void print_add(int i) const { | ||
// break here | ||
std::cout << num_ + i << '\n'; | ||
} | ||
int num_; | ||
}; | ||
|
||
int main() { | ||
// Invoke a void-returning function | ||
std::invoke(print_num, -9); | ||
|
||
// Invoke a non-void-returning function | ||
std::cout << std::invoke(add, 1, 10) << '\n'; | ||
|
||
// Invoke a member function | ||
const PrintAdder foo(314159); | ||
std::invoke(&PrintAdder::print_add, foo, 1); | ||
|
||
// Invoke a function object | ||
std::invoke(PrintAdder(12), 18); | ||
} |