| 1 | //===-- ExceptionBreakpoint.cpp ---------------------------------*- C++ -*-===// |
|---|---|
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "ExceptionBreakpoint.h" |
| 10 | #include "BreakpointBase.h" |
| 11 | #include "DAP.h" |
| 12 | #include "Protocol/ProtocolTypes.h" |
| 13 | #include "lldb/API/SBMutex.h" |
| 14 | #include "lldb/API/SBTarget.h" |
| 15 | #include <mutex> |
| 16 | |
| 17 | using namespace llvm; |
| 18 | using namespace lldb_dap::protocol; |
| 19 | |
| 20 | namespace lldb_dap { |
| 21 | |
| 22 | protocol::Breakpoint ExceptionBreakpoint::SetBreakpoint(StringRef condition) { |
| 23 | lldb::SBMutex lock = m_dap.GetAPIMutex(); |
| 24 | std::lock_guard<lldb::SBMutex> guard(lock); |
| 25 | |
| 26 | if (!m_bp.IsValid()) { |
| 27 | m_bp = m_dap.target.BreakpointCreateForException( |
| 28 | language: m_language, catch_bp: m_kind == eExceptionKindCatch, |
| 29 | throw_bp: m_kind == eExceptionKindThrow); |
| 30 | m_bp.AddName(new_name: BreakpointBase::kDAPBreakpointLabel); |
| 31 | } |
| 32 | |
| 33 | m_bp.SetCondition(condition.data()); |
| 34 | |
| 35 | protocol::Breakpoint breakpoint; |
| 36 | breakpoint.id = m_bp.GetID(); |
| 37 | breakpoint.verified = m_bp.IsValid(); |
| 38 | return breakpoint; |
| 39 | } |
| 40 | |
| 41 | void ExceptionBreakpoint::ClearBreakpoint() { |
| 42 | if (!m_bp.IsValid()) |
| 43 | return; |
| 44 | m_dap.target.BreakpointDelete(break_id: m_bp.GetID()); |
| 45 | m_bp = lldb::SBBreakpoint(); |
| 46 | } |
| 47 | |
| 48 | } // namespace lldb_dap |
| 49 |
