forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 341
Fix swift async frames unwinding unwinding #9025
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
adrian-prantl
merged 4 commits into
swiftlang:swift/release/6.0
from
felipepiovezan:felipe/unwinding_pc_patches_to_release
Aug 1, 2024
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2672795
[LLDB] Add constant value mode for RegisterLocation
felipepiovezan bffca2b
[LLDB][swift][nfc] Make unwind method a member
felipepiovezan 4e5e68f
[LLDB][swift] Add test demonstrating failed async variable inspection
felipepiovezan 85069c8
[LLDB][swift] Skip prologue when unwiding virtual frames
felipepiovezan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
3 changes: 3 additions & 0 deletions
3
lldb/test/API/lang/swift/async/frame/variables_multiple_frames/Makefile
This file contains hidden or 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,3 @@ | ||
SWIFT_SOURCES := main.swift | ||
SWIFTFLAGS_EXTRAS := -parse-as-library | ||
include Makefile.rules |
78 changes: 78 additions & 0 deletions
78
.../lang/swift/async/frame/variables_multiple_frames/TestSwiftAsyncFrameVarMultipleFrames.py
This file contains hidden or 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,78 @@ | ||
import lldb | ||
from lldbsuite.test.decorators import * | ||
import lldbsuite.test.lldbtest as lldbtest | ||
import lldbsuite.test.lldbutil as lldbutil | ||
|
||
|
||
class TestCase(lldbtest.TestBase): | ||
|
||
mydir = lldbtest.TestBase.compute_mydir(__file__) | ||
|
||
# Check that the CFA chain is correctly built | ||
def check_cfas(self, async_frames, process): | ||
async_cfas = list(map(lambda frame: frame.GetCFA(), async_frames)) | ||
expected_cfas = [async_cfas[0]] | ||
# The CFA chain ends in nullptr. | ||
while expected_cfas[-1] != 0: | ||
error = lldb.SBError() | ||
expected_cfas.append( | ||
process.ReadPointerFromMemory(expected_cfas[-1], error) | ||
) | ||
self.assertSuccess(error, "Managed to read cfa memory") | ||
|
||
self.assertEqual(async_cfas, expected_cfas[:-1]) | ||
|
||
def check_pcs(self, async_frames, process, target): | ||
for idx, frame in enumerate(async_frames[:-1]): | ||
# Read the continuation pointer from the second field of the CFA. | ||
error = lldb.SBError() | ||
continuation_ptr = process.ReadPointerFromMemory( | ||
frame.GetCFA() + target.addr_size, error | ||
) | ||
self.assertSuccess(error, "Managed to read context memory") | ||
|
||
# The PC of the previous frame should be the continuation pointer | ||
# with the funclet's prologue skipped. | ||
parent_frame = async_frames[idx + 1] | ||
prologue_to_skip = parent_frame.GetFunction().GetPrologueByteSize() | ||
self.assertEqual(continuation_ptr + prologue_to_skip, parent_frame.GetPC()) | ||
|
||
|
||
def check_variables(self, async_frames, expected_values): | ||
for (frame, expected_value) in zip(async_frames, expected_values): | ||
myvar = frame.FindVariable("myvar") | ||
lldbutil.check_variable(self, myvar, False, value=expected_value) | ||
|
||
@swiftTest | ||
@skipIf(oslist=["windows", "linux"]) | ||
def test(self): | ||
"""Test `frame variable` in async functions""" | ||
self.build() | ||
|
||
source_file = lldb.SBFileSpec("main.swift") | ||
target, process, _, _ = lldbutil.run_to_source_breakpoint( | ||
self, "breakpoint1", source_file | ||
) | ||
|
||
async_frames = process.GetSelectedThread().frames | ||
self.check_cfas(async_frames, process) | ||
self.check_pcs(async_frames, process, target) | ||
self.check_variables(async_frames, ["222", "333", "444", "555"]) | ||
|
||
target.DeleteAllBreakpoints() | ||
target.BreakpointCreateBySourceRegex("breakpoint2", source_file) | ||
process.Continue() | ||
# First frame is from a synchronous function | ||
frames = process.GetSelectedThread().frames | ||
async_frames = frames[1:] | ||
self.check_cfas(async_frames, process) | ||
self.check_pcs(async_frames, process, target) | ||
self.check_variables(async_frames, ["111", "222", "333", "444", "555"]) | ||
|
||
target.DeleteAllBreakpoints() | ||
target.BreakpointCreateBySourceRegex("breakpoint3", source_file) | ||
process.Continue() | ||
async_frames = process.GetSelectedThread().frames | ||
self.check_cfas(async_frames, process) | ||
self.check_pcs(async_frames, process, target) | ||
self.check_variables(async_frames, ["222", "333", "444", "555"]) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.