Skip to content

[lldb][nfc] Adjust language plugin to changes in FilterForLineBreakpoints #10238

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
15 changes: 7 additions & 8 deletions lldb/include/lldb/Target/Language.h
Original file line number Diff line number Diff line change
Expand Up @@ -356,14 +356,13 @@ class Language : public PluginInterface {

virtual llvm::StringRef GetInstanceVariableName() { return {}; }

/// Returns true if this SymbolContext should be ignored when setting
/// breakpoints by line (number or regex). Helpful for languages that create
/// artificial functions without meaningful user code associated with them
/// (e.g. code that gets expanded in late compilation stages, like by
/// CoroSplitter).
virtual bool IgnoreForLineBreakpoints(const SymbolContext &) const {
return false;
}
/// Given a symbol context list of matches which supposedly represent the
/// same file and line number in a CU, erases those that should be ignored
/// when setting breakpoints by line (number or regex). Helpful for languages
/// that create split a single source-line into many functions (e.g. call
/// sites transformed by CoroSplitter).
virtual void
FilterForLineBreakpoints(llvm::SmallVectorImpl<SymbolContext> &) const {}

/// Returns a boolean indicating whether two symbol contexts are equal for the
/// purposes of frame comparison. If the plugin has no opinion, it should
Expand Down
19 changes: 9 additions & 10 deletions lldb/source/Breakpoint/BreakpointResolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,16 +207,15 @@ bool operator<(const SourceLoc lhs, const SourceLoc rhs) {
void BreakpointResolver::SetSCMatchesByLine(
SearchFilter &filter, SymbolContextList &sc_list, bool skip_prologue,
llvm::StringRef log_ident, uint32_t line, std::optional<uint16_t> column) {
llvm::SmallVector<SymbolContext, 16> all_scs;

for (const auto &sc : sc_list) {
if (Language::GetGlobalLanguageProperties()
.GetEnableFilterForLineBreakpoints())
if (Language *lang = Language::FindPlugin(sc.GetLanguage());
lang && lang->IgnoreForLineBreakpoints(sc))
continue;
all_scs.push_back(sc);
}
llvm::SmallVector<SymbolContext, 16> all_scs(sc_list.begin(), sc_list.end());

// Let the language plugin filter `sc_list`. Because all symbol contexts in
// sc_list are assumed to belong to the same File, Line and CU, the code below
// assumes they have the same language.
if (!sc_list.IsEmpty() && Language::GetGlobalLanguageProperties()
.GetEnableFilterForLineBreakpoints())
if (Language *lang = Language::FindPlugin(sc_list[0].GetLanguage()))
lang->FilterForLineBreakpoints(all_scs);

while (all_scs.size()) {
uint32_t closest_line = UINT32_MAX;
Expand Down
24 changes: 14 additions & 10 deletions lldb/source/Plugins/Language/Swift/SwiftLanguage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1832,16 +1832,20 @@ 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;
llvm::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);
void SwiftLanguage::FilterForLineBreakpoints(
llvm::SmallVectorImpl<SymbolContext> &sc_list) const {
llvm::erase_if(sc_list, [](const SymbolContext &sc) {
// If we don't have a function, conservatively keep this sc.
if (!sc.function)
return false;

// In async functions, ignore await resume ("Q") funclets, these only
// deallocate the async context and task_switch back to user code.
llvm::StringRef name =
sc.function->GetMangled().GetMangledName().GetStringRef();
return SwiftLanguageRuntime::IsSwiftAsyncAwaitResumePartialFunctionSymbol(
name);
});
}

std::optional<bool>
Expand Down
3 changes: 2 additions & 1 deletion lldb/source/Plugins/Language/Swift/SwiftLanguage.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ 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;
void FilterForLineBreakpoints(
llvm::SmallVectorImpl<SymbolContext> &) const override;

//------------------------------------------------------------------
// PluginInterface protocol
Expand Down