[Lldb-commits] [lldb] [lldb] Allow languages to filter breakpoints set by line (PR #83908)
Felipe de Azevedo Piovezan via lldb-commits
lldb-commits at lists.llvm.org
Thu Mar 7 09:32:19 PST 2024
https://github.com/felipepiovezan updated https://github.com/llvm/llvm-project/pull/83908
>From 51307b548d09c34ee06037ccf459110e451970a9 Mon Sep 17 00:00:00 2001
From: Felipe de Azevedo Piovezan <fpiovezan at apple.com>
Date: Mon, 4 Mar 2024 09:56:18 -0800
Subject: [PATCH 1/4] [lldb] Allow languages to filter breakpoints set by line
Some languages may create artificial functions that have no real user code, even
though there is line table information for them. One such case is with coroutine
code that receives the CoroSplitter transformation in LLVM IR. That code
transformation creates many different Functions, cloning one Instruction into
many Instructions in many different Functions and copying the associated debug
locations.
It would be difficult to make that pass delete debug locations of cloned
instructions in a language agnostic way (is it even possible?), but LLDB can
ignore certain locations by querying its Language APIs and having it decide
based on, for example, mangling information.
---
lldb/include/lldb/Target/Language.h | 4 ++++
lldb/source/Breakpoint/BreakpointResolver.cpp | 12 ++++++++++++
2 files changed, 16 insertions(+)
diff --git a/lldb/include/lldb/Target/Language.h b/lldb/include/lldb/Target/Language.h
index 0cbd8a32dccd54..957c40eb7c0772 100644
--- a/lldb/include/lldb/Target/Language.h
+++ b/lldb/include/lldb/Target/Language.h
@@ -339,6 +339,10 @@ class Language : public PluginInterface {
virtual llvm::StringRef GetInstanceVariableName() { return {}; }
+ virtual bool IsInterestingCtxForLineBreakpoint(const SymbolContext &) const {
+ return true;
+ }
+
protected:
// Classes that inherit from Language can see and modify these
diff --git a/lldb/source/Breakpoint/BreakpointResolver.cpp b/lldb/source/Breakpoint/BreakpointResolver.cpp
index bc6348716ef418..876b30c6d76d55 100644
--- a/lldb/source/Breakpoint/BreakpointResolver.cpp
+++ b/lldb/source/Breakpoint/BreakpointResolver.cpp
@@ -23,6 +23,7 @@
#include "lldb/Symbol/CompileUnit.h"
#include "lldb/Symbol/Function.h"
#include "lldb/Symbol/SymbolContext.h"
+#include "lldb/Target/Language.h"
#include "lldb/Target/Target.h"
#include "lldb/Utility/LLDBLog.h"
#include "lldb/Utility/Log.h"
@@ -199,6 +200,15 @@ bool operator<(const SourceLoc lhs, const SourceLoc rhs) {
}
} // namespace
+static void
+ApplyLanguageFilters(llvm::SmallVectorImpl<SymbolContext> &sc_list) {
+ llvm::erase_if(sc_list, [](SymbolContext &sc) {
+ if (Language *lang = Language::FindPlugin(sc.GetLanguage()))
+ return !lang->IsInterestingCtxForLineBreakpoint(sc);
+ return false;
+ });
+}
+
void BreakpointResolver::SetSCMatchesByLine(
SearchFilter &filter, SymbolContextList &sc_list, bool skip_prologue,
llvm::StringRef log_ident, uint32_t line, std::optional<uint16_t> column) {
@@ -206,6 +216,8 @@ void BreakpointResolver::SetSCMatchesByLine(
for (uint32_t i = 0; i < sc_list.GetSize(); ++i)
all_scs.push_back(sc_list[i]);
+ ApplyLanguageFilters(all_scs);
+
while (all_scs.size()) {
uint32_t closest_line = UINT32_MAX;
>From 7ea76d6c04d063d50da52756179639f2037aa793 Mon Sep 17 00:00:00 2001
From: Felipe de Azevedo Piovezan <fpiovezan at apple.com>
Date: Tue, 5 Mar 2024 18:47:51 -0800
Subject: [PATCH 2/4] fixup! add target option
---
lldb/include/lldb/Target/Language.h | 9 ++++++--
lldb/include/lldb/Target/Target.h | 2 ++
lldb/source/Breakpoint/BreakpointResolver.cpp | 23 +++++++++----------
lldb/source/Target/Target.cpp | 8 +++++++
lldb/source/Target/TargetProperties.td | 3 +++
5 files changed, 31 insertions(+), 14 deletions(-)
diff --git a/lldb/include/lldb/Target/Language.h b/lldb/include/lldb/Target/Language.h
index 957c40eb7c0772..9db9f4e297e114 100644
--- a/lldb/include/lldb/Target/Language.h
+++ b/lldb/include/lldb/Target/Language.h
@@ -339,8 +339,13 @@ class Language : public PluginInterface {
virtual llvm::StringRef GetInstanceVariableName() { return {}; }
- virtual bool IsInterestingCtxForLineBreakpoint(const SymbolContext &) const {
- return true;
+ // Returns true if this SymbolContext should be used when setting breakpoints
+ // by line (number or regex). This is useful for languages that create
+ // artificial functions without any meaningful user code associated with them
+ // (e.g. code that gets expanded in late compilation stages, like by
+ // CoroSplitter).
+ virtual bool IsArtificialCtxForLineBreakpoint(const SymbolContext &) const {
+ return false;
}
protected:
diff --git a/lldb/include/lldb/Target/Target.h b/lldb/include/lldb/Target/Target.h
index 8f57358981d4d2..ab04aa57f17300 100644
--- a/lldb/include/lldb/Target/Target.h
+++ b/lldb/include/lldb/Target/Target.h
@@ -258,6 +258,8 @@ class TargetProperties : public Properties {
bool GetDebugUtilityExpression() const;
+ bool GetIgnoreBreakpointsFromLanguageArtificialLocations() const;
+
private:
// Callbacks for m_launch_info.
void Arg0ValueChangedCallback();
diff --git a/lldb/source/Breakpoint/BreakpointResolver.cpp b/lldb/source/Breakpoint/BreakpointResolver.cpp
index 876b30c6d76d55..03f10f876ee1db 100644
--- a/lldb/source/Breakpoint/BreakpointResolver.cpp
+++ b/lldb/source/Breakpoint/BreakpointResolver.cpp
@@ -200,23 +200,22 @@ bool operator<(const SourceLoc lhs, const SourceLoc rhs) {
}
} // namespace
-static void
-ApplyLanguageFilters(llvm::SmallVectorImpl<SymbolContext> &sc_list) {
- llvm::erase_if(sc_list, [](SymbolContext &sc) {
- if (Language *lang = Language::FindPlugin(sc.GetLanguage()))
- return !lang->IsInterestingCtxForLineBreakpoint(sc);
- return false;
- });
-}
-
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 (uint32_t i = 0; i < sc_list.GetSize(); ++i)
+ const bool ShouldQueryLanguageFilter =
+ GetBreakpoint()
+ ->GetTarget()
+ .GetIgnoreBreakpointsFromLanguageArtificialLocations();
+
+ for (uint32_t i = 0; i < sc_list.GetSize(); ++i) {
+ if (ShouldQueryLanguageFilter)
+ if (Language *lang = Language::FindPlugin(sc_list[i].GetLanguage());
+ lang && lang->IsArtificialCtxForLineBreakpoint(sc_list[i]))
+ continue;
all_scs.push_back(sc_list[i]);
-
- ApplyLanguageFilters(all_scs);
+ }
while (all_scs.size()) {
uint32_t closest_line = UINT32_MAX;
diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index e982a30a3ae4ff..ba533ad440ff19 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -4896,6 +4896,14 @@ void TargetProperties::SetDebugUtilityExpression(bool debug) {
SetPropertyAtIndex(idx, debug);
}
+bool TargetProperties::GetIgnoreBreakpointsFromLanguageArtificialLocations()
+ const {
+ const uint32_t idx =
+ ePropertyIgnoreBreakpointsFromLanguageArtificialLocations;
+ return GetPropertyAtIndexAs<bool>(
+ idx, g_target_properties[idx].default_uint_value != 0);
+}
+
// Target::TargetEventData
Target::TargetEventData::TargetEventData(const lldb::TargetSP &target_sp)
diff --git a/lldb/source/Target/TargetProperties.td b/lldb/source/Target/TargetProperties.td
index d2fccdb7b9b39c..6151d2e6524a86 100644
--- a/lldb/source/Target/TargetProperties.td
+++ b/lldb/source/Target/TargetProperties.td
@@ -104,6 +104,9 @@ let Definition = "target" in {
def BreakpointUseAvoidList: Property<"breakpoints-use-platform-avoid-list", "Boolean">,
DefaultTrue,
Desc<"Consult the platform module avoid list when setting non-module specific breakpoints.">;
+ def IgnoreBreakpointsFromLanguageArtificialLocations: Property<"ignore-breakpoints-from-language-artificial-locations", "Boolean">,
+ DefaultTrue,
+ Desc<"If true, locations that are considered artificial by the source Language plugin will be ignored when setting breakpoints by line number or regex.">;
def Arg0: Property<"arg0", "String">,
DefaultStringValue<"">,
Desc<"The first argument passed to the program in the argument array which can be different from the executable itself.">;
>From 838c9f2c46478802839e7dae0887d90608325908 Mon Sep 17 00:00:00 2001
From: Felipe de Azevedo Piovezan <fpiovezan at apple.com>
Date: Thu, 7 Mar 2024 09:30:28 -0800
Subject: [PATCH 3/4] fixup! rename property
---
lldb/include/lldb/Target/Language.h | 12 ++++++------
lldb/include/lldb/Target/Target.h | 2 +-
lldb/source/Breakpoint/BreakpointResolver.cpp | 6 ++----
lldb/source/Target/Target.cpp | 6 ++----
lldb/source/Target/TargetProperties.td | 4 ++--
5 files changed, 13 insertions(+), 17 deletions(-)
diff --git a/lldb/include/lldb/Target/Language.h b/lldb/include/lldb/Target/Language.h
index 9db9f4e297e114..1dbd9ba9fb14ef 100644
--- a/lldb/include/lldb/Target/Language.h
+++ b/lldb/include/lldb/Target/Language.h
@@ -339,12 +339,12 @@ class Language : public PluginInterface {
virtual llvm::StringRef GetInstanceVariableName() { return {}; }
- // Returns true if this SymbolContext should be used when setting breakpoints
- // by line (number or regex). This is useful for languages that create
- // artificial functions without any meaningful user code associated with them
- // (e.g. code that gets expanded in late compilation stages, like by
- // CoroSplitter).
- virtual bool IsArtificialCtxForLineBreakpoint(const SymbolContext &) const {
+ /// Returns true if this SymbolContext should be ignored when setting
+ /// breakpoints by line (number or regex). This is useful for languages that
+ /// create artificial functions without any 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;
}
diff --git a/lldb/include/lldb/Target/Target.h b/lldb/include/lldb/Target/Target.h
index ab04aa57f17300..f28cb6dc2ccba8 100644
--- a/lldb/include/lldb/Target/Target.h
+++ b/lldb/include/lldb/Target/Target.h
@@ -258,7 +258,7 @@ class TargetProperties : public Properties {
bool GetDebugUtilityExpression() const;
- bool GetIgnoreBreakpointsFromLanguageArtificialLocations() const;
+ bool GetEnableLanguageFilterForLineBreakpoints() const;
private:
// Callbacks for m_launch_info.
diff --git a/lldb/source/Breakpoint/BreakpointResolver.cpp b/lldb/source/Breakpoint/BreakpointResolver.cpp
index 03f10f876ee1db..e620da1877bd3c 100644
--- a/lldb/source/Breakpoint/BreakpointResolver.cpp
+++ b/lldb/source/Breakpoint/BreakpointResolver.cpp
@@ -205,14 +205,12 @@ void BreakpointResolver::SetSCMatchesByLine(
llvm::StringRef log_ident, uint32_t line, std::optional<uint16_t> column) {
llvm::SmallVector<SymbolContext, 16> all_scs;
const bool ShouldQueryLanguageFilter =
- GetBreakpoint()
- ->GetTarget()
- .GetIgnoreBreakpointsFromLanguageArtificialLocations();
+ GetBreakpoint()->GetTarget().GetEnableLanguageFilterForLineBreakpoints();
for (uint32_t i = 0; i < sc_list.GetSize(); ++i) {
if (ShouldQueryLanguageFilter)
if (Language *lang = Language::FindPlugin(sc_list[i].GetLanguage());
- lang && lang->IsArtificialCtxForLineBreakpoint(sc_list[i]))
+ lang && lang->IgnoreForLineBreakpoints(sc_list[i]))
continue;
all_scs.push_back(sc_list[i]);
}
diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index ba533ad440ff19..a8c2b28a8524da 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -4896,10 +4896,8 @@ void TargetProperties::SetDebugUtilityExpression(bool debug) {
SetPropertyAtIndex(idx, debug);
}
-bool TargetProperties::GetIgnoreBreakpointsFromLanguageArtificialLocations()
- const {
- const uint32_t idx =
- ePropertyIgnoreBreakpointsFromLanguageArtificialLocations;
+bool TargetProperties::GetEnableLanguageFilterForLineBreakpoints() const {
+ const uint32_t idx = ePropertyEnableLanguageFilterForLineBreakpoints;
return GetPropertyAtIndexAs<bool>(
idx, g_target_properties[idx].default_uint_value != 0);
}
diff --git a/lldb/source/Target/TargetProperties.td b/lldb/source/Target/TargetProperties.td
index 6151d2e6524a86..2f59087555c1bf 100644
--- a/lldb/source/Target/TargetProperties.td
+++ b/lldb/source/Target/TargetProperties.td
@@ -104,9 +104,9 @@ let Definition = "target" in {
def BreakpointUseAvoidList: Property<"breakpoints-use-platform-avoid-list", "Boolean">,
DefaultTrue,
Desc<"Consult the platform module avoid list when setting non-module specific breakpoints.">;
- def IgnoreBreakpointsFromLanguageArtificialLocations: Property<"ignore-breakpoints-from-language-artificial-locations", "Boolean">,
+ def EnableLanguageFilterForLineBreakpoints: Property<"enable-language-filter-for-line-breakpoints", "Boolean">,
DefaultTrue,
- Desc<"If true, locations that are considered artificial by the source Language plugin will be ignored when setting breakpoints by line number or regex.">;
+ Desc<"If true, allow Language plugins to filter locations when setting breakpoints by line number or regex.">;
def Arg0: Property<"arg0", "String">,
DefaultStringValue<"">,
Desc<"The first argument passed to the program in the argument array which can be different from the executable itself.">;
>From 0c8e475e586d54fe2b83bda10c0619ff51b31052 Mon Sep 17 00:00:00 2001
From: Felipe de Azevedo Piovezan <fpiovezan at apple.com>
Date: Thu, 7 Mar 2024 09:32:07 -0800
Subject: [PATCH 4/4] fixup! use range-based for for sc_list
---
lldb/source/Breakpoint/BreakpointResolver.cpp | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/lldb/source/Breakpoint/BreakpointResolver.cpp b/lldb/source/Breakpoint/BreakpointResolver.cpp
index e620da1877bd3c..531101b7cd853f 100644
--- a/lldb/source/Breakpoint/BreakpointResolver.cpp
+++ b/lldb/source/Breakpoint/BreakpointResolver.cpp
@@ -207,12 +207,12 @@ void BreakpointResolver::SetSCMatchesByLine(
const bool ShouldQueryLanguageFilter =
GetBreakpoint()->GetTarget().GetEnableLanguageFilterForLineBreakpoints();
- for (uint32_t i = 0; i < sc_list.GetSize(); ++i) {
+ for (const auto &sc : sc_list) {
if (ShouldQueryLanguageFilter)
- if (Language *lang = Language::FindPlugin(sc_list[i].GetLanguage());
- lang && lang->IgnoreForLineBreakpoints(sc_list[i]))
+ if (Language *lang = Language::FindPlugin(sc.GetLanguage());
+ lang && lang->IgnoreForLineBreakpoints(sc))
continue;
- all_scs.push_back(sc_list[i]);
+ all_scs.push_back(sc);
}
while (all_scs.size()) {
More information about the lldb-commits
mailing list