@@ -128,104 +128,89 @@ DAP::DAP(Log *log, const ReplMode default_repl_mode,
128128DAP::~DAP () = default ;
129129
130130void DAP::PopulateExceptionBreakpoints () {
131- llvm::call_once (init_exception_breakpoints_flag, [this ]() {
132- exception_breakpoints = std::vector<ExceptionBreakpoint>{};
133-
134- if (lldb::SBDebugger::SupportsLanguage (lldb::eLanguageTypeC_plus_plus)) {
135- exception_breakpoints->emplace_back (*this , " cpp_catch" , " C++ Catch" ,
136- lldb::eLanguageTypeC_plus_plus);
137- exception_breakpoints->emplace_back (*this , " cpp_throw" , " C++ Throw" ,
138- lldb::eLanguageTypeC_plus_plus);
139- }
140- if (lldb::SBDebugger::SupportsLanguage (lldb::eLanguageTypeObjC)) {
141- exception_breakpoints->emplace_back (
142- *this , " objc_catch" , " Objective-C Catch" , lldb::eLanguageTypeObjC);
143- exception_breakpoints->emplace_back (
144- *this , " objc_throw" , " Objective-C Throw" , lldb::eLanguageTypeObjC);
145- }
146- if (lldb::SBDebugger::SupportsLanguage (lldb::eLanguageTypeSwift)) {
147- exception_breakpoints->emplace_back (*this , " swift_catch" , " Swift Catch" ,
148- lldb::eLanguageTypeSwift);
149- exception_breakpoints->emplace_back (*this , " swift_throw" , " Swift Throw" ,
150- lldb::eLanguageTypeSwift);
131+ if (lldb::SBDebugger::SupportsLanguage (lldb::eLanguageTypeC_plus_plus)) {
132+ exception_breakpoints.emplace_back (*this , " cpp_catch" , " C++ Catch" ,
133+ lldb::eLanguageTypeC_plus_plus,
134+ /* is_throw=*/ false , /* is_catch=*/ true );
135+ exception_breakpoints.emplace_back (*this , " cpp_throw" , " C++ Throw" ,
136+ lldb::eLanguageTypeC_plus_plus,
137+ /* is_throw=*/ true , /* is_catch=*/ false );
138+ }
139+
140+ if (lldb::SBDebugger::SupportsLanguage (lldb::eLanguageTypeObjC)) {
141+ exception_breakpoints.emplace_back (*this , " objc_catch" , " Objective-C Catch" ,
142+ lldb::eLanguageTypeObjC,
143+ /* is_throw=*/ false , /* is_catch=*/ true );
144+ exception_breakpoints.emplace_back (*this , " objc_throw" , " Objective-C Throw" ,
145+ lldb::eLanguageTypeObjC,
146+ /* is_throw=*/ true , /* is_catch=*/ false );
147+ }
148+
149+ if (lldb::SBDebugger::SupportsLanguage (lldb::eLanguageTypeSwift)) {
150+ exception_breakpoints.emplace_back (*this , " swift_catch" , " Swift Catch" ,
151+ lldb::eLanguageTypeSwift,
152+ /* is_throw=*/ false , /* is_catch=*/ true );
153+ exception_breakpoints.emplace_back (*this , " swift_throw" , " Swift Throw" ,
154+ lldb::eLanguageTypeSwift,
155+ /* is_throw=*/ true , /* is_catch=*/ false );
156+ }
157+
158+ // Besides handling the hardcoded list of languages from above, we try to find
159+ // any other languages that support exception breakpoints using the SB API.
160+ for (int raw_lang = lldb::eLanguageTypeUnknown;
161+ raw_lang < lldb::eNumLanguageTypes; ++raw_lang) {
162+ lldb::LanguageType lang = static_cast <lldb::LanguageType>(raw_lang);
163+
164+ // We first discard any languages already handled above.
165+ if (lldb::SBLanguageRuntime::LanguageIsCFamily (lang) ||
166+ lang == lldb::eLanguageTypeSwift)
167+ continue ;
168+
169+ if (!lldb::SBDebugger::SupportsLanguage (lang))
170+ continue ;
171+
172+ const char *name = lldb::SBLanguageRuntime::GetNameForLanguageType (lang);
173+ if (!name)
174+ continue ;
175+ std::string raw_lang_name = name;
176+ std::string capitalized_lang_name = capitalize (name);
177+
178+ if (lldb::SBLanguageRuntime::SupportsExceptionBreakpointsOnThrow (lang)) {
179+ const char *raw_throw_keyword =
180+ lldb::SBLanguageRuntime::GetThrowKeywordForLanguage (lang);
181+ std::string throw_keyword =
182+ raw_throw_keyword ? raw_throw_keyword : " throw" ;
183+
184+ exception_breakpoints.emplace_back (
185+ *this , raw_lang_name + " _" + throw_keyword,
186+ capitalized_lang_name + " " + capitalize (throw_keyword), lang,
187+ /* is_throw=*/ true , /* is_catch=*/ false );
151188 }
152- // Besides handling the hardcoded list of languages from above, we try to
153- // find any other languages that support exception breakpoints using the
154- // SB API.
155- for (int raw_lang = lldb::eLanguageTypeUnknown;
156- raw_lang < lldb::eNumLanguageTypes; ++raw_lang) {
157- lldb::LanguageType lang = static_cast <lldb::LanguageType>(raw_lang);
158-
159- // We first discard any languages already handled above.
160- if (lldb::SBLanguageRuntime::LanguageIsCFamily (lang) ||
161- lang == lldb::eLanguageTypeSwift)
162- continue ;
163-
164- if (!lldb::SBDebugger::SupportsLanguage (lang))
165- continue ;
166-
167- const char *name = lldb::SBLanguageRuntime::GetNameForLanguageType (lang);
168- if (!name)
169- continue ;
170- std::string raw_lang_name = name;
171- std::string capitalized_lang_name = capitalize (name);
172-
173- if (lldb::SBLanguageRuntime::SupportsExceptionBreakpointsOnThrow (lang)) {
174- const char *raw_throw_keyword =
175- lldb::SBLanguageRuntime::GetThrowKeywordForLanguage (lang);
176- std::string throw_keyword =
177- raw_throw_keyword ? raw_throw_keyword : " throw" ;
178-
179- exception_breakpoints->emplace_back (
180- *this , raw_lang_name + " _" + throw_keyword,
181- capitalized_lang_name + " " + capitalize (throw_keyword), lang);
182- }
183189
184- if (lldb::SBLanguageRuntime::SupportsExceptionBreakpointsOnCatch (lang)) {
185- const char *raw_catch_keyword =
186- lldb::SBLanguageRuntime::GetCatchKeywordForLanguage (lang);
187- std::string catch_keyword =
188- raw_catch_keyword ? raw_catch_keyword : " catch" ;
190+ if (lldb::SBLanguageRuntime::SupportsExceptionBreakpointsOnCatch (lang)) {
191+ const char *raw_catch_keyword =
192+ lldb::SBLanguageRuntime::GetCatchKeywordForLanguage (lang);
193+ std::string catch_keyword =
194+ raw_catch_keyword ? raw_catch_keyword : " catch" ;
189195
190- exception_breakpoints-> emplace_back (
191- *this , raw_lang_name + " _" + catch_keyword,
192- capitalized_lang_name + " " + capitalize (catch_keyword), lang);
193- }
196+ exception_breakpoints. emplace_back (
197+ *this , raw_lang_name + " _" + catch_keyword,
198+ capitalized_lang_name + " " + capitalize (catch_keyword), lang,
199+ /* is_throw= */ true , /* is_catch= */ false );
194200 }
195- assert (!exception_breakpoints->empty () && " should not be empty" );
196- });
201+ }
197202}
198203
199204ExceptionBreakpoint *DAP::GetExceptionBreakpoint (llvm::StringRef filter) {
200- // PopulateExceptionBreakpoints() is called after g_dap.debugger is created
201- // in a request-initialize.
202- //
203- // But this GetExceptionBreakpoint() method may be called before attaching, in
204- // which case, we may not have populated the filter yet.
205- //
206- // We also cannot call PopulateExceptionBreakpoints() in DAP::DAP() because
207- // we need SBDebugger::Initialize() to have been called before this.
208- //
209- // So just calling PopulateExceptionBreakoints(),which does lazy-populating
210- // seems easiest. Two other options include:
211- // + call g_dap.PopulateExceptionBreakpoints() in lldb-dap.cpp::main()
212- // right after the call to SBDebugger::Initialize()
213- // + Just call PopulateExceptionBreakpoints() to get a fresh list everytime
214- // we query (a bit overkill since it's not likely to change?)
215- PopulateExceptionBreakpoints ();
216-
217- for (auto &bp : *exception_breakpoints) {
205+ for (auto &bp : exception_breakpoints) {
218206 if (bp.GetFilter () == filter)
219207 return &bp;
220208 }
221209 return nullptr ;
222210}
223211
224212ExceptionBreakpoint *DAP::GetExceptionBreakpoint (const lldb::break_id_t bp_id) {
225- // See comment in the other GetExceptionBreakpoint().
226- PopulateExceptionBreakpoints ();
227-
228- for (auto &bp : *exception_breakpoints) {
213+ for (auto &bp : exception_breakpoints) {
229214 if (bp.GetID () == bp_id)
230215 return &bp;
231216 }
@@ -1117,8 +1102,9 @@ protocol::Capabilities DAP::GetCapabilities() {
11171102 }
11181103
11191104 // Available filters or options for the setExceptionBreakpoints request.
1105+ PopulateExceptionBreakpoints ();
11201106 std::vector<protocol::ExceptionBreakpointsFilter> filters;
1121- for (const auto &exc_bp : * exception_breakpoints)
1107+ for (const auto &exc_bp : exception_breakpoints)
11221108 filters.emplace_back (CreateExceptionBreakpointFilter (exc_bp));
11231109 capabilities.exceptionBreakpointFilters = std::move (filters);
11241110
0 commit comments