Skip to content

[lldb][swift] Filter Q funclets when setting breakpoints #9112

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lldb/source/Plugins/Language/Swift/SwiftLanguage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1814,6 +1814,17 @@ SwiftLanguage::GetDemangledFunctionNameWithoutArguments(Mangled mangled) const {
return mangled_name;
}

bool SwiftLanguage::IgnoreForLineBreakpoints(const SymbolContext &sc) const {
// If we don't have a function, conservatively return false.
if (!sc.function)
return false;
StringRef name = sc.function->GetMangled().GetMangledName().GetStringRef();
// In async functions, ignore await resume ("Q") funclets, these only
// deallocate the async context and task_switch back to user code.
return SwiftLanguageRuntime::IsSwiftAsyncAwaitResumePartialFunctionSymbol(
name);
}

//------------------------------------------------------------------
// Static Functions
//------------------------------------------------------------------
Expand Down
3 changes: 3 additions & 0 deletions lldb/source/Plugins/Language/Swift/SwiftLanguage.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ class SwiftLanguage : public Language {

llvm::StringRef GetInstanceVariableName() override { return "self"; }

/// Override that skips breakpoints inside await resume ("Q") async funclets.
bool IgnoreForLineBreakpoints(const SymbolContext &sc) const override;

//------------------------------------------------------------------
// PluginInterface protocol
//------------------------------------------------------------------
Expand Down
3 changes: 3 additions & 0 deletions lldb/test/API/lang/swift/async_breakpoints/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SWIFT_SOURCES := main.swift

include Makefile.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import lldb
from lldbsuite.test.decorators import *
import lldbsuite.test.lldbtest as lldbtest
import lldbsuite.test.lldbutil as lldbutil


class TestSwiftAsyncBreakpoints(lldbtest.TestBase):
@swiftTest
@skipIfWindows
@skipIfLinux
@skipIf(archs=no_match(["arm64", "arm64e", "x86_64"]))
def test(self):
"""Test async breakpoints"""
self.build()
filespec = lldb.SBFileSpec("main.swift")
target, process, thread, breakpoint1 = lldbutil.run_to_source_breakpoint(
self, "Breakpoint1", filespec
)
breakpoint2 = target.BreakpointCreateBySourceRegex("Breakpoint2", filespec)
breakpoint3 = target.BreakpointCreateBySourceRegex("Breakpoint3", filespec)
self.assertEquals(breakpoint1.GetNumLocations(), 2)
self.assertEquals(breakpoint2.GetNumLocations(), 1)
self.assertEquals(breakpoint3.GetNumLocations(), 2)

location11 = breakpoint1.GetLocationAtIndex(0)
location12 = breakpoint1.GetLocationAtIndex(1)
self.assertEquals(location11.GetHitCount(), 1)
self.assertEquals(location12.GetHitCount(), 0)

self.assertEquals(thread.GetStopDescription(128), "breakpoint 1.1")
process.Continue()
self.assertEquals(thread.GetStopDescription(128), "breakpoint 1.2")

thread.StepOver()
self.assertEquals(thread.GetStopDescription(128), "breakpoint 2.1")
self.expect("expr timestamp1", substrs=["42"])

thread.StepOver()
self.assertIn("breakpoint 3.1", thread.GetStopDescription(128))
self.expect("expr timestamp1", substrs=["42"])

process.Continue()
self.assertIn("breakpoint 3.2", thread.GetStopDescription(128))
self.expect("expr timestamp1", substrs=["42"])

thread.StepOver()
self.expect("expr timestamp1", substrs=["42"])
self.expect("expr timestamp2", substrs=["43"])

self.runCmd("settings set language.enable-filter-for-line-breakpoints false")
breakpoint1_no_filter = target.BreakpointCreateBySourceRegex(
"Breakpoint1", filespec
)
self.assertEquals(breakpoint1_no_filter.GetNumLocations(), 3)
15 changes: 15 additions & 0 deletions lldb/test/API/lang/swift/async_breakpoints/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
func getTimestamp(i:Int) async -> Int {
return i
}

func work() {}

func foo() async {
work()
let timestamp1 = await getTimestamp(i:42) // Breakpoint1
work() // Breakpoint2
let timestamp2 = await getTimestamp(i:43) // Breakpoint3
work()
}

await foo()