[Lldb-commits] [lldb] Reapply PR/87550 (PR #94625)
Vy Nguyen via lldb-commits
lldb-commits at lists.llvm.org
Fri Jun 7 08:19:47 PDT 2024
https://github.com/oontvoo updated https://github.com/llvm/llvm-project/pull/94625
>From bbaa8ef4434a1d97a31a5dd7cbfc3cdfebcbe41d Mon Sep 17 00:00:00 2001
From: Vy Nguyen <vyng at google.com>
Date: Thu, 6 Jun 2024 10:17:06 -0400
Subject: [PATCH 1/5] Reapply "[lldb][lldb-dap] Cleanup breakpoint filters."
(#93739)
This reverts commit 6595e7fa1b5588f860aa057aac47c43623169584.
---
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 | 39 ++++++++++++++++++++-------
lldb/tools/lldb-dap/DAP.h | 4 ++-
lldb/tools/lldb-dap/lldb-dap.cpp | 6 +++--
7 files changed, 54 insertions(+), 13 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..5d56d9b1829da 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 languages =
+ PluginManager::GetAllTypeSystemSupportedLanguagesForTypes();
+ if (languages.Empty())
+ return false;
+ return languages[language];
+}
diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp
index d419f821999e6..807d27c2c869d 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),
@@ -65,8 +58,32 @@ DAP::DAP()
DAP::~DAP() = default;
+void DAP::PopulateExceptionBreakpoints() {
+ exception_breakpoints = {};
+ 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);
+ }
+}
+
ExceptionBreakpoint *DAP::GetExceptionBreakpoint(const std::string &filter) {
- for (auto &bp : exception_breakpoints) {
+ assert(exception_breakpoints.has_value() &&
+ "PopulateExceptionBreakpoints must be called first");
+ for (auto &bp : *exception_breakpoints) {
if (bp.filter == filter)
return &bp;
}
@@ -74,7 +91,9 @@ ExceptionBreakpoint *DAP::GetExceptionBreakpoint(const std::string &filter) {
}
ExceptionBreakpoint *DAP::GetExceptionBreakpoint(const lldb::break_id_t bp_id) {
- for (auto &bp : exception_breakpoints) {
+ assert(exception_breakpoints.has_value() &&
+ "PopulateExceptionBreakpoints must be called first");
+ 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..d114b886a1597 100644
--- a/lldb/tools/lldb-dap/DAP.h
+++ b/lldb/tools/lldb-dap/DAP.h
@@ -156,7 +156,7 @@ struct DAP {
std::unique_ptr<std::ofstream> log;
llvm::StringMap<SourceBreakpointMap> source_breakpoints;
FunctionBreakpointMap function_breakpoints;
- std::vector<ExceptionBreakpoint> exception_breakpoints;
+ std::optional<std::vector<ExceptionBreakpoint>> exception_breakpoints;
std::vector<std::string> init_commands;
std::vector<std::string> pre_run_commands;
std::vector<std::string> post_run_commands;
@@ -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
diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp
index 7746afb6cbbf3..470c9f84c6a20 100644
--- a/lldb/tools/lldb-dap/lldb-dap.cpp
+++ b/lldb/tools/lldb-dap/lldb-dap.cpp
@@ -16,6 +16,7 @@
#include <cstdio>
#include <cstdlib>
#include <cstring>
+#include <optional>
#include <sys/stat.h>
#include <sys/types.h>
#if defined(_WIN32)
@@ -1586,6 +1587,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)) {
@@ -1621,7 +1623,7 @@ void request_initialize(const llvm::json::Object &request) {
body.try_emplace("supportsEvaluateForHovers", true);
// Available filters or options for the setExceptionBreakpoints request.
llvm::json::Array filters;
- for (const auto &exc_bp : g_dap.exception_breakpoints) {
+ for (const auto &exc_bp : *g_dap.exception_breakpoints) {
filters.emplace_back(CreateExceptionBreakpointFilter(exc_bp));
}
body.try_emplace("exceptionBreakpointFilters", std::move(filters));
@@ -2476,7 +2478,7 @@ void request_setExceptionBreakpoints(const llvm::json::Object &request) {
// Keep a list of any exception breakpoint filter names that weren't set
// so we can clear any exception breakpoints if needed.
std::set<std::string> unset_filters;
- for (const auto &bp : g_dap.exception_breakpoints)
+ for (const auto &bp : *g_dap.exception_breakpoints)
unset_filters.insert(bp.filter);
for (const auto &value : *filters) {
>From 33edc9e1296a4ace7a3236819e4b637efad7d78a Mon Sep 17 00:00:00 2001
From: Vy Nguyen <vyng at google.com>
Date: Thu, 6 Jun 2024 10:36:20 -0400
Subject: [PATCH 2/5] removed assertion checks
---
lldb/tools/lldb-dap/DAP.cpp | 32 +++++++++++++++++++++++++-------
1 file changed, 25 insertions(+), 7 deletions(-)
diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp
index 807d27c2c869d..55196d041a88c 100644
--- a/lldb/tools/lldb-dap/DAP.cpp
+++ b/lldb/tools/lldb-dap/DAP.cpp
@@ -60,19 +60,19 @@ DAP::~DAP() = default;
void DAP::PopulateExceptionBreakpoints() {
exception_breakpoints = {};
- if (debugger.SupportsLanguage(lldb::eLanguageTypeC_plus_plus)) {
+ if (SBDebugger::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)) {
+ if (SBDebugger::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)) {
+ if (SBDebugger::SupportsLanguage(lldb::eLanguageTypeSwift)) {
exception_breakpoints->emplace_back("swift_catch", "Swift Catch",
lldb::eLanguageTypeSwift);
exception_breakpoints->emplace_back("swift_throw", "Swift Throw",
@@ -81,8 +81,24 @@ void DAP::PopulateExceptionBreakpoints() {
}
ExceptionBreakpoint *DAP::GetExceptionBreakpoint(const std::string &filter) {
- assert(exception_breakpoints.has_value() &&
- "PopulateExceptionBreakpoints must be called first");
+ // PopulateExceptionBreakpoints() is called after g_dap.debugger is created
+ // in a request-initialize.
+ //
+ // But this GetExceptionBreakpoint() method may be called before attaching, in
+ // which case, we may not have populated the filter yet.
+ //
+ // We also cannot call PopulateExceptionBreakpoints() in DAP::DAP() because
+ // we need SBDebugger::Initialize() to have been called before this.
+ //
+ // So just checking the filter list and do lazy-populating seems easiest.
+ // Two other options include:
+ // + call g_dap.PopulateExceptionBreakpoints() in lldb-dap.cpp::main()
+ // right after the call to SBDebugger::Initialize()
+ // + Just call PopulateExceptionBreakpoints() to get a fresh list everytime
+ // we query (a bit overkill since it's not likely to change?)
+ if (!exception_breakpoints.has_value)
+ PopulateExceptionBreakpoints();
+
for (auto &bp : *exception_breakpoints) {
if (bp.filter == filter)
return &bp;
@@ -91,8 +107,10 @@ ExceptionBreakpoint *DAP::GetExceptionBreakpoint(const std::string &filter) {
}
ExceptionBreakpoint *DAP::GetExceptionBreakpoint(const lldb::break_id_t bp_id) {
- assert(exception_breakpoints.has_value() &&
- "PopulateExceptionBreakpoints must be called first");
+ // See comment in the other GetExceptionBreakpoint().
+ if (!exception_breakpoints.has_value)
+ PopulateExceptionBreakpoints();
+
for (auto &bp : *exception_breakpoints) {
if (bp.bp.GetID() == bp_id)
return &bp;
>From e16b56aa5685853ceb76ab894dc46ce7e018b547 Mon Sep 17 00:00:00 2001
From: Vy Nguyen <vyng at google.com>
Date: Thu, 6 Jun 2024 10:42:41 -0400
Subject: [PATCH 3/5] typo
---
lldb/tools/lldb-dap/DAP.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp
index 55196d041a88c..b6f5cbc919dc7 100644
--- a/lldb/tools/lldb-dap/DAP.cpp
+++ b/lldb/tools/lldb-dap/DAP.cpp
@@ -96,7 +96,7 @@ ExceptionBreakpoint *DAP::GetExceptionBreakpoint(const std::string &filter) {
// right after the call to SBDebugger::Initialize()
// + Just call PopulateExceptionBreakpoints() to get a fresh list everytime
// we query (a bit overkill since it's not likely to change?)
- if (!exception_breakpoints.has_value)
+ if (!exception_breakpoints.has_value())
PopulateExceptionBreakpoints();
for (auto &bp : *exception_breakpoints) {
@@ -108,7 +108,7 @@ ExceptionBreakpoint *DAP::GetExceptionBreakpoint(const std::string &filter) {
ExceptionBreakpoint *DAP::GetExceptionBreakpoint(const lldb::break_id_t bp_id) {
// See comment in the other GetExceptionBreakpoint().
- if (!exception_breakpoints.has_value)
+ if (!exception_breakpoints.has_value())
PopulateExceptionBreakpoints();
for (auto &bp : *exception_breakpoints) {
>From 92d09cd0fa9b06135d282f415b33bb1ab71d5ed8 Mon Sep 17 00:00:00 2001
From: Vy Nguyen <vyng at google.com>
Date: Thu, 6 Jun 2024 12:34:38 -0400
Subject: [PATCH 4/5] added ns
---
lldb/tools/lldb-dap/DAP.cpp | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp
index b6f5cbc919dc7..f8e5e25a966ca 100644
--- a/lldb/tools/lldb-dap/DAP.cpp
+++ b/lldb/tools/lldb-dap/DAP.cpp
@@ -60,19 +60,19 @@ DAP::~DAP() = default;
void DAP::PopulateExceptionBreakpoints() {
exception_breakpoints = {};
- if (SBDebugger::SupportsLanguage(lldb::eLanguageTypeC_plus_plus)) {
+ if (lldb::SBDebugger::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 (SBDebugger::SupportsLanguage(lldb::eLanguageTypeObjC)) {
+ if (lldb::SBDebugger::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 (SBDebugger::SupportsLanguage(lldb::eLanguageTypeSwift)) {
+ if (lldb::SBDebugger::SupportsLanguage(lldb::eLanguageTypeSwift)) {
exception_breakpoints->emplace_back("swift_catch", "Swift Catch",
lldb::eLanguageTypeSwift);
exception_breakpoints->emplace_back("swift_throw", "Swift Throw",
>From 38cd558693040d0af5f473ac682dc3e7c7549d8f Mon Sep 17 00:00:00 2001
From: Vy Nguyen <vyng at google.com>
Date: Fri, 7 Jun 2024 11:19:35 -0400
Subject: [PATCH 5/5] wrap the population of exception_breakpoints in a
call_once for safety
---
lldb/tools/lldb-dap/DAP.cpp | 56 ++++++++++++++++++++-----------------
lldb/tools/lldb-dap/DAP.h | 1 +
2 files changed, 32 insertions(+), 25 deletions(-)
diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp
index f8e5e25a966ca..53a2120fc6565 100644
--- a/lldb/tools/lldb-dap/DAP.cpp
+++ b/lldb/tools/lldb-dap/DAP.cpp
@@ -59,25 +59,29 @@ DAP::DAP()
DAP::~DAP() = default;
void DAP::PopulateExceptionBreakpoints() {
- exception_breakpoints = {};
- if (lldb::SBDebugger::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 (lldb::SBDebugger::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 (lldb::SBDebugger::SupportsLanguage(lldb::eLanguageTypeSwift)) {
- exception_breakpoints->emplace_back("swift_catch", "Swift Catch",
- lldb::eLanguageTypeSwift);
- exception_breakpoints->emplace_back("swift_throw", "Swift Throw",
- lldb::eLanguageTypeSwift);
- }
+ if (exception_breakpoints.has_value())
+ return;
+ llvm::call_once(initExceptionBreakpoints, [this]() {
+ exception_breakpoints = {};
+ if (lldb::SBDebugger::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 (lldb::SBDebugger::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 (lldb::SBDebugger::SupportsLanguage(lldb::eLanguageTypeSwift)) {
+ exception_breakpoints->emplace_back("swift_catch", "Swift Catch",
+ lldb::eLanguageTypeSwift);
+ exception_breakpoints->emplace_back("swift_throw", "Swift Throw",
+ lldb::eLanguageTypeSwift);
+ }
+ });
}
ExceptionBreakpoint *DAP::GetExceptionBreakpoint(const std::string &filter) {
@@ -90,14 +94,15 @@ ExceptionBreakpoint *DAP::GetExceptionBreakpoint(const std::string &filter) {
// We also cannot call PopulateExceptionBreakpoints() in DAP::DAP() because
// we need SBDebugger::Initialize() to have been called before this.
//
- // So just checking the filter list and do lazy-populating seems easiest.
- // Two other options include:
+ // So just calling PopulateExceptionBreakoints(),which does lazy-populating
+ // seems easiest. Two other options include:
// + call g_dap.PopulateExceptionBreakpoints() in lldb-dap.cpp::main()
// right after the call to SBDebugger::Initialize()
// + Just call PopulateExceptionBreakpoints() to get a fresh list everytime
// we query (a bit overkill since it's not likely to change?)
- if (!exception_breakpoints.has_value())
- PopulateExceptionBreakpoints();
+ PopulateExceptionBreakpoints();
+ assert(exception_breakpoints.has_value() &&
+ "exception_breakpoints must have been populated");
for (auto &bp : *exception_breakpoints) {
if (bp.filter == filter)
@@ -108,8 +113,9 @@ ExceptionBreakpoint *DAP::GetExceptionBreakpoint(const std::string &filter) {
ExceptionBreakpoint *DAP::GetExceptionBreakpoint(const lldb::break_id_t bp_id) {
// See comment in the other GetExceptionBreakpoint().
- if (!exception_breakpoints.has_value())
- PopulateExceptionBreakpoints();
+ PopulateExceptionBreakpoints();
+ assert(exception_breakpoints.has_value() &&
+ "exception_breakpoints must have been populated");
for (auto &bp : *exception_breakpoints) {
if (bp.bp.GetID() == bp_id)
diff --git a/lldb/tools/lldb-dap/DAP.h b/lldb/tools/lldb-dap/DAP.h
index d114b886a1597..daa0d9f1aa7f0 100644
--- a/lldb/tools/lldb-dap/DAP.h
+++ b/lldb/tools/lldb-dap/DAP.h
@@ -157,6 +157,7 @@ struct DAP {
llvm::StringMap<SourceBreakpointMap> source_breakpoints;
FunctionBreakpointMap function_breakpoints;
std::optional<std::vector<ExceptionBreakpoint>> exception_breakpoints;
+ llvm::once_flag initExceptionBreakpoints;
std::vector<std::string> init_commands;
std::vector<std::string> pre_run_commands;
std::vector<std::string> post_run_commands;
More information about the lldb-commits
mailing list