Skip to content

Commit cfb209b

Browse files
authored
[lldb][lldb-dap] Cleanup breakpoint filters. (#87550)
Details: - remove Swift breakpoint filter because this version of LLDB does not support Swift. - only return objc filters when working on macos.
1 parent c9c2444 commit cfb209b

File tree

7 files changed

+54
-13
lines changed

7 files changed

+54
-13
lines changed

lldb/include/lldb/API/SBDebugger.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ class LLDB_API SBDebugger {
5757

5858
static const char *GetBroadcasterClass();
5959

60+
static bool SupportsLanguage(lldb::LanguageType language);
61+
6062
lldb::SBBroadcaster GetBroadcaster();
6163

6264
/// Get progress data from a SBEvent whose type is eBroadcastBitProgress.

lldb/include/lldb/Symbol/TypeSystem.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ class TypeSystem : public PluginInterface,
209209
// TypeSystems can support more than one language
210210
virtual bool SupportsLanguage(lldb::LanguageType language) = 0;
211211

212+
static bool SupportsLanguageStatic(lldb::LanguageType language);
212213
// Type Completion
213214

214215
virtual bool GetCompleteType(lldb::opaque_compiler_type_t type) = 0;

lldb/source/API/SBDebugger.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1742,3 +1742,7 @@ bool SBDebugger::InterruptRequested() {
17421742
return m_opaque_sp->InterruptRequested();
17431743
return false;
17441744
}
1745+
1746+
bool SBDebugger::SupportsLanguage(lldb::LanguageType language) {
1747+
return TypeSystem::SupportsLanguageStatic(language);
1748+
}

lldb/source/Symbol/TypeSystem.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,3 +335,14 @@ TypeSystemMap::GetTypeSystemForLanguage(lldb::LanguageType language,
335335
}
336336
return GetTypeSystemForLanguage(language);
337337
}
338+
339+
bool TypeSystem::SupportsLanguageStatic(lldb::LanguageType language) {
340+
if (language == eLanguageTypeUnknown)
341+
return false;
342+
343+
LanguageSet languages =
344+
PluginManager::GetAllTypeSystemSupportedLanguagesForTypes();
345+
if (languages.Empty())
346+
return false;
347+
return languages[language];
348+
}

lldb/tools/lldb-dap/DAP.cpp

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,7 @@ namespace lldb_dap {
3232
DAP g_dap;
3333

3434
DAP::DAP()
35-
: broadcaster("lldb-dap"),
36-
exception_breakpoints(
37-
{{"cpp_catch", "C++ Catch", lldb::eLanguageTypeC_plus_plus},
38-
{"cpp_throw", "C++ Throw", lldb::eLanguageTypeC_plus_plus},
39-
{"objc_catch", "Objective-C Catch", lldb::eLanguageTypeObjC},
40-
{"objc_throw", "Objective-C Throw", lldb::eLanguageTypeObjC},
41-
{"swift_catch", "Swift Catch", lldb::eLanguageTypeSwift},
42-
{"swift_throw", "Swift Throw", lldb::eLanguageTypeSwift}}),
35+
: broadcaster("lldb-dap"), exception_breakpoints(),
4336
focus_tid(LLDB_INVALID_THREAD_ID), stop_at_entry(false), is_attach(false),
4437
enable_auto_variable_summaries(false),
4538
enable_synthetic_child_debugging(false),
@@ -65,16 +58,42 @@ DAP::DAP()
6558

6659
DAP::~DAP() = default;
6760

61+
void DAP::PopulateExceptionBreakpoints() {
62+
exception_breakpoints = {};
63+
if (debugger.SupportsLanguage(lldb::eLanguageTypeC_plus_plus)) {
64+
exception_breakpoints->emplace_back("cpp_catch", "C++ Catch",
65+
lldb::eLanguageTypeC_plus_plus);
66+
exception_breakpoints->emplace_back("cpp_throw", "C++ Throw",
67+
lldb::eLanguageTypeC_plus_plus);
68+
}
69+
if (debugger.SupportsLanguage(lldb::eLanguageTypeObjC)) {
70+
exception_breakpoints->emplace_back("objc_catch", "Objective-C Catch",
71+
lldb::eLanguageTypeObjC);
72+
exception_breakpoints->emplace_back("objc_throw", "Objective-C Throw",
73+
lldb::eLanguageTypeObjC);
74+
}
75+
if (debugger.SupportsLanguage(lldb::eLanguageTypeSwift)) {
76+
exception_breakpoints->emplace_back("swift_catch", "Swift Catch",
77+
lldb::eLanguageTypeSwift);
78+
exception_breakpoints->emplace_back("swift_throw", "Swift Throw",
79+
lldb::eLanguageTypeSwift);
80+
}
81+
}
82+
6883
ExceptionBreakpoint *DAP::GetExceptionBreakpoint(const std::string &filter) {
69-
for (auto &bp : exception_breakpoints) {
84+
assert(exception_breakpoints.has_value() &&
85+
"PopulateExceptionBreakpoints must be called first");
86+
for (auto &bp : *exception_breakpoints) {
7087
if (bp.filter == filter)
7188
return &bp;
7289
}
7390
return nullptr;
7491
}
7592

7693
ExceptionBreakpoint *DAP::GetExceptionBreakpoint(const lldb::break_id_t bp_id) {
77-
for (auto &bp : exception_breakpoints) {
94+
assert(exception_breakpoints.has_value() &&
95+
"PopulateExceptionBreakpoints must be called first");
96+
for (auto &bp : *exception_breakpoints) {
7897
if (bp.bp.GetID() == bp_id)
7998
return &bp;
8099
}

lldb/tools/lldb-dap/DAP.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ struct DAP {
156156
std::unique_ptr<std::ofstream> log;
157157
llvm::StringMap<SourceBreakpointMap> source_breakpoints;
158158
FunctionBreakpointMap function_breakpoints;
159-
std::vector<ExceptionBreakpoint> exception_breakpoints;
159+
std::optional<std::vector<ExceptionBreakpoint>> exception_breakpoints;
160160
std::vector<std::string> init_commands;
161161
std::vector<std::string> pre_run_commands;
162162
std::vector<std::string> post_run_commands;
@@ -228,6 +228,8 @@ struct DAP {
228228

229229
llvm::json::Value CreateTopLevelScopes();
230230

231+
void PopulateExceptionBreakpoints();
232+
231233
/// \return
232234
/// Attempt to determine if an expression is a variable expression or
233235
/// lldb command using a hueristic based on the first term of the

lldb/tools/lldb-dap/lldb-dap.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <cstdio>
1717
#include <cstdlib>
1818
#include <cstring>
19+
#include <optional>
1920
#include <sys/stat.h>
2021
#include <sys/types.h>
2122
#if defined(_WIN32)
@@ -1586,6 +1587,7 @@ void request_initialize(const llvm::json::Object &request) {
15861587
bool source_init_file = GetBoolean(arguments, "sourceInitFile", true);
15871588

15881589
g_dap.debugger = lldb::SBDebugger::Create(source_init_file, log_cb, nullptr);
1590+
g_dap.PopulateExceptionBreakpoints();
15891591
auto cmd = g_dap.debugger.GetCommandInterpreter().AddMultiwordCommand(
15901592
"lldb-dap", "Commands for managing lldb-dap.");
15911593
if (GetBoolean(arguments, "supportsStartDebuggingRequest", false)) {
@@ -1621,7 +1623,7 @@ void request_initialize(const llvm::json::Object &request) {
16211623
body.try_emplace("supportsEvaluateForHovers", true);
16221624
// Available filters or options for the setExceptionBreakpoints request.
16231625
llvm::json::Array filters;
1624-
for (const auto &exc_bp : g_dap.exception_breakpoints) {
1626+
for (const auto &exc_bp : *g_dap.exception_breakpoints) {
16251627
filters.emplace_back(CreateExceptionBreakpointFilter(exc_bp));
16261628
}
16271629
body.try_emplace("exceptionBreakpointFilters", std::move(filters));
@@ -2476,7 +2478,7 @@ void request_setExceptionBreakpoints(const llvm::json::Object &request) {
24762478
// Keep a list of any exception breakpoint filter names that weren't set
24772479
// so we can clear any exception breakpoints if needed.
24782480
std::set<std::string> unset_filters;
2479-
for (const auto &bp : g_dap.exception_breakpoints)
2481+
for (const auto &bp : *g_dap.exception_breakpoints)
24802482
unset_filters.insert(bp.filter);
24812483

24822484
for (const auto &value : *filters) {

0 commit comments

Comments
 (0)