Skip to content

Commit fef0b8a

Browse files
[lldb] Let languages see all SymbolContexts at once when filtering breakpoints (#129937)
This allows languages to make decisions based on the whole set of symbol contexts, giving them strictly more power than when they are only allowed to see one at a time.
1 parent 5ec884e commit fef0b8a

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

lldb/include/lldb/Target/Language.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -354,14 +354,13 @@ class Language : public PluginInterface {
354354

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

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

366365
/// Returns a boolean indicating whether two symbol contexts are equal for the
367366
/// purposes of frame comparison. If the plugin has no opinion, it should

lldb/source/Breakpoint/BreakpointResolver.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -207,16 +207,15 @@ bool operator<(const SourceLoc lhs, const SourceLoc rhs) {
207207
void BreakpointResolver::SetSCMatchesByLine(
208208
SearchFilter &filter, SymbolContextList &sc_list, bool skip_prologue,
209209
llvm::StringRef log_ident, uint32_t line, std::optional<uint16_t> column) {
210-
llvm::SmallVector<SymbolContext, 16> all_scs;
211-
212-
for (const auto &sc : sc_list) {
213-
if (Language::GetGlobalLanguageProperties()
214-
.GetEnableFilterForLineBreakpoints())
215-
if (Language *lang = Language::FindPlugin(sc.GetLanguage());
216-
lang && lang->IgnoreForLineBreakpoints(sc))
217-
continue;
218-
all_scs.push_back(sc);
219-
}
210+
llvm::SmallVector<SymbolContext, 16> all_scs(sc_list.begin(), sc_list.end());
211+
212+
// Let the language plugin filter `sc_list`. Because all symbol contexts in
213+
// sc_list are assumed to belong to the same File, Line and CU, the code below
214+
// assumes they have the same language.
215+
if (!sc_list.IsEmpty() && Language::GetGlobalLanguageProperties()
216+
.GetEnableFilterForLineBreakpoints())
217+
if (Language *lang = Language::FindPlugin(sc_list[0].GetLanguage()))
218+
lang->FilterForLineBreakpoints(all_scs);
220219

221220
while (all_scs.size()) {
222221
uint32_t closest_line = UINT32_MAX;

0 commit comments

Comments
 (0)