[Lldb-commits] [lldb] Reapply PR/87550 (again) (PR #95571)
Vy Nguyen via lldb-commits
lldb-commits at lists.llvm.org
Mon Jun 24 12:21:46 PDT 2024
================
@@ -65,16 +58,67 @@ DAP::DAP()
DAP::~DAP() = default;
+void DAP::PopulateExceptionBreakpoints() {
+ llvm::call_once(initExceptionBreakpoints, [this]() {
+ exception_breakpoints = std::vector<ExceptionBreakpoint> {};
+
+ 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);
+ }
+ assert(exception_breakpoints.has_value() && "should have been initted");
+ assert(!exception_breakpoints->empty() && "should not be empty");
+ });
+}
+
ExceptionBreakpoint *DAP::GetExceptionBreakpoint(const std::string &filter) {
- for (auto &bp : exception_breakpoints) {
+ // 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 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?)
+ PopulateExceptionBreakpoints();
+ assert(exception_breakpoints.has_value() &&
+ "exception_breakpoints must have been populated");
----------------
oontvoo wrote:
done - i've removed the unnecessary asserts(but keeping the method name to make it clearer that this function's job is to popualte the list)
https://github.com/llvm/llvm-project/pull/95571
More information about the lldb-commits
mailing list