[Lldb-commits] [lldb] [lldb][lldb-dap] Cleanup breakpoint filters. (PR #87550)
Vy Nguyen via lldb-commits
lldb-commits at lists.llvm.org
Fri May 24 06:20:54 PDT 2024
https://github.com/oontvoo updated https://github.com/llvm/llvm-project/pull/87550
>From e86d5f95f74a0b2b5f8ec334d8fd4ff519fe7b27 Mon Sep 17 00:00:00 2001
From: Vy Nguyen <vyng at google.com>
Date: Fri, 24 May 2024 09:19:12 -0400
Subject: [PATCH] [lldb]Clean up breakpoint filters - added util function for
querying whether a language is supported by the type system - populate the
breakpoint filters table based on the supported language(s)
---
lldb/include/lldb/API/SBDebugger.h | 2 ++
lldb/include/lldb/Symbol/TypeSystem.h | 1 +
lldb/source/API/SBDebugger.cpp | 4 +++
lldb/source/Symbol/TypeSystem.cpp | 11 ++++++++
lldb/tools/lldb-dap/DAP.cpp | 36 +++++++++++++++++++++------
lldb/tools/lldb-dap/DAP.h | 3 +++
lldb/tools/lldb-dap/lldb-dap.cpp | 1 +
7 files changed, 50 insertions(+), 8 deletions(-)
diff --git a/lldb/include/lldb/API/SBDebugger.h b/lldb/include/lldb/API/SBDebugger.h
index af19b1faf3bf5..84ea9c0f772e1 100644
--- a/lldb/include/lldb/API/SBDebugger.h
+++ b/lldb/include/lldb/API/SBDebugger.h
@@ -57,6 +57,8 @@ class LLDB_API SBDebugger {
static const char *GetBroadcasterClass();
+ static bool SupportsLanguage(lldb::LanguageType language);
+
lldb::SBBroadcaster GetBroadcaster();
/// Get progress data from a SBEvent whose type is eBroadcastBitProgress.
diff --git a/lldb/include/lldb/Symbol/TypeSystem.h b/lldb/include/lldb/Symbol/TypeSystem.h
index b4025c173a186..7d48f9b316138 100644
--- a/lldb/include/lldb/Symbol/TypeSystem.h
+++ b/lldb/include/lldb/Symbol/TypeSystem.h
@@ -209,6 +209,7 @@ class TypeSystem : public PluginInterface,
// TypeSystems can support more than one language
virtual bool SupportsLanguage(lldb::LanguageType language) = 0;
+ static bool SupportsLanguageStatic(lldb::LanguageType language);
// Type Completion
virtual bool GetCompleteType(lldb::opaque_compiler_type_t type) = 0;
diff --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp
index 7ef0d6efd4aaa..29da7d33dd80b 100644
--- a/lldb/source/API/SBDebugger.cpp
+++ b/lldb/source/API/SBDebugger.cpp
@@ -1742,3 +1742,7 @@ bool SBDebugger::InterruptRequested() {
return m_opaque_sp->InterruptRequested();
return false;
}
+
+bool SBDebugger::SupportsLanguage(lldb::LanguageType language) {
+ return TypeSystem::SupportsLanguageStatic(language);
+}
diff --git a/lldb/source/Symbol/TypeSystem.cpp b/lldb/source/Symbol/TypeSystem.cpp
index 4956f10a0b0a7..f7d14420fba69 100644
--- a/lldb/source/Symbol/TypeSystem.cpp
+++ b/lldb/source/Symbol/TypeSystem.cpp
@@ -335,3 +335,14 @@ TypeSystemMap::GetTypeSystemForLanguage(lldb::LanguageType language,
}
return GetTypeSystemForLanguage(language);
}
+
+bool TypeSystem::SupportsLanguageStatic(lldb::LanguageType language) {
+ if (language == eLanguageTypeUnknown)
+ return false;
+
+ LanguageSet plugins =
+ PluginManager::GetAllTypeSystemSupportedLanguagesForTypes();
+ if (plugins.Empty())
+ return false;
+ return plugins[language];
+}
diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp
index c7eb3db4304a9..81aabc55b08da 100644
--- a/lldb/tools/lldb-dap/DAP.cpp
+++ b/lldb/tools/lldb-dap/DAP.cpp
@@ -32,14 +32,7 @@ namespace lldb_dap {
DAP g_dap;
DAP::DAP()
- : broadcaster("lldb-dap"),
- exception_breakpoints(
- {{"cpp_catch", "C++ Catch", lldb::eLanguageTypeC_plus_plus},
- {"cpp_throw", "C++ Throw", lldb::eLanguageTypeC_plus_plus},
- {"objc_catch", "Objective-C Catch", lldb::eLanguageTypeObjC},
- {"objc_throw", "Objective-C Throw", lldb::eLanguageTypeObjC},
- {"swift_catch", "Swift Catch", lldb::eLanguageTypeSwift},
- {"swift_throw", "Swift Throw", lldb::eLanguageTypeSwift}}),
+ : broadcaster("lldb-dap"), exception_breakpoints(),
focus_tid(LLDB_INVALID_THREAD_ID), stop_at_entry(false), is_attach(false),
enable_auto_variable_summaries(false),
enable_synthetic_child_debugging(false),
@@ -61,11 +54,37 @@ DAP::DAP()
#endif
if (log_file_path)
log.reset(new std::ofstream(log_file_path));
+
+ bp_initted = false;
}
DAP::~DAP() = default;
+void DAP::PopulateExceptionBreakpoints() {
+ if (debugger.SupportsLanguage(lldb::eLanguageTypeC_plus_plus)) {
+ exception_breakpoints.emplace_back(
+ {"cpp_catch", "C++ Catch", lldb::eLanguageTypeC_plus_plus});
+ exception_breakpoints.emplace_back(
+ {"cpp_throw", "C++ Throw", lldb::eLanguageTypeC_plus_plus});
+ }
+ if (debugger.SupportsLanguage(lldb::eLanguageTypeObjC)) {
+ exception_breakpoints.emplace_back(
+ {"objc_catch", "Objective-C Catch", lldb::eLanguageTypeObjC});
+ exception_breakpoints.emplace_back(
+ {"objc_throw", "Objective-C Throw", lldb::eLanguageTypeObjC});
+ }
+ if (debugger.SupportsLanguage(lldb::eLanguageTypeSwift)) {
+ exception_breakpoints.emplace_back(
+ {"swift_catch", "Swift Catch", lldb::eLanguageTypeSwift});
+ exception_breakpoints.emplace_back(
+ {"swift_throw", "Swift Throw", lldb::eLanguageTypeSwift});
+ }
+
+ bp_initted = true;
+}
+
ExceptionBreakpoint *DAP::GetExceptionBreakpoint(const std::string &filter) {
+ assert(bp_initted);
for (auto &bp : exception_breakpoints) {
if (bp.filter == filter)
return &bp;
@@ -74,6 +93,7 @@ ExceptionBreakpoint *DAP::GetExceptionBreakpoint(const std::string &filter) {
}
ExceptionBreakpoint *DAP::GetExceptionBreakpoint(const lldb::break_id_t bp_id) {
+ assert(bp_initted);
for (auto &bp : exception_breakpoints) {
if (bp.bp.GetID() == bp_id)
return &bp;
diff --git a/lldb/tools/lldb-dap/DAP.h b/lldb/tools/lldb-dap/DAP.h
index a88ee3e1dec6b..90922edf3d099 100644
--- a/lldb/tools/lldb-dap/DAP.h
+++ b/lldb/tools/lldb-dap/DAP.h
@@ -228,6 +228,8 @@ struct DAP {
llvm::json::Value CreateTopLevelScopes();
+ void PopulateExceptionBreakpoints();
+
/// \return
/// Attempt to determine if an expression is a variable expression or
/// lldb command using a hueristic based on the first term of the
@@ -331,6 +333,7 @@ struct DAP {
// "Content-Length:" field followed by the length, followed by the raw
// JSON bytes.
void SendJSON(const std::string &json_str);
+ bool bp_initted;
};
extern DAP g_dap;
diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp
index 7746afb6cbbf3..fba7c233e2cad 100644
--- a/lldb/tools/lldb-dap/lldb-dap.cpp
+++ b/lldb/tools/lldb-dap/lldb-dap.cpp
@@ -1586,6 +1586,7 @@ void request_initialize(const llvm::json::Object &request) {
bool source_init_file = GetBoolean(arguments, "sourceInitFile", true);
g_dap.debugger = lldb::SBDebugger::Create(source_init_file, log_cb, nullptr);
+ g_dap.PopulateExceptionBreakpoints();
auto cmd = g_dap.debugger.GetCommandInterpreter().AddMultiwordCommand(
"lldb-dap", "Commands for managing lldb-dap.");
if (GetBoolean(arguments, "supportsStartDebuggingRequest", false)) {
More information about the lldb-commits
mailing list