Skip to content

[lldb] Let languages see all SymbolContexts at once when filtering breakpoints #129937

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

Conversation

felipepiovezan
Copy link
Contributor

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.

…eakpoints

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.

// 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.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assumption above comes from the docstring for BreakpointResolver::SetSCMatchesByLine

@llvmbot
Copy link
Member

llvmbot commented Mar 5, 2025

@llvm/pr-subscribers-lldb

Author: Felipe de Azevedo Piovezan (felipepiovezan)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/129937.diff

2 Files Affected:

  • (modified) lldb/include/lldb/Target/Language.h (+7-8)
  • (modified) lldb/source/Breakpoint/BreakpointResolver.cpp (+9-10)
diff --git a/lldb/include/lldb/Target/Language.h b/lldb/include/lldb/Target/Language.h
index 38ca458159edc..b699a90aff8e4 100644
--- a/lldb/include/lldb/Target/Language.h
+++ b/lldb/include/lldb/Target/Language.h
@@ -354,14 +354,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
diff --git a/lldb/source/Breakpoint/BreakpointResolver.cpp b/lldb/source/Breakpoint/BreakpointResolver.cpp
index 5fe544908c39e..91fdff4a455da 100644
--- a/lldb/source/Breakpoint/BreakpointResolver.cpp
+++ b/lldb/source/Breakpoint/BreakpointResolver.cpp
@@ -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;

Copy link
Collaborator

@jimingham jimingham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't see how this would hurt, and there no guarantee anywhere that these potential hits will be treated strictly independently.

So this LGTM.

/// that create split a single source-line into many functions (e.g. call
/// sites transformed by CoroSplitter).
virtual void
FilterForLineBreakpoints(llvm::SmallVectorImpl<SymbolContext> &) const {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this take a SymbolContextList instead?

Copy link
Contributor Author

@felipepiovezan felipepiovezan Mar 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The callsite doesn't use that, I suspect because it intends to manipulate the contents of the list heavily (like this method will)

@felipepiovezan felipepiovezan merged commit fef0b8a into llvm:main Mar 12, 2025
12 checks passed
@felipepiovezan felipepiovezan deleted the felipe/filter_breakpoints_update branch March 12, 2025 10:22
felipepiovezan added a commit to felipepiovezan/llvm-project that referenced this pull request Mar 12, 2025
…eakpoints (llvm#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.

(cherry picked from commit fef0b8a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants