aboutsummaryrefslogtreecommitdiff
path: root/lldb/tools/lldb-dap/ExceptionBreakpoint.cpp
blob: 5bf06268a5af2576d6b81d5cf7ef856d2a827e87 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//===-- ExceptionBreakpoint.cpp ---------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "ExceptionBreakpoint.h"
#include "BreakpointBase.h"
#include "DAP.h"
#include "Protocol/ProtocolTypes.h"
#include "lldb/API/SBMutex.h"
#include "lldb/API/SBTarget.h"
#include <mutex>

using namespace llvm;
using namespace lldb_dap::protocol;

namespace lldb_dap {

protocol::Breakpoint ExceptionBreakpoint::SetBreakpoint(StringRef condition) {
  lldb::SBMutex lock = m_dap.GetAPIMutex();
  std::lock_guard<lldb::SBMutex> guard(lock);

  if (!m_bp.IsValid()) {
    m_bp = m_dap.target.BreakpointCreateForException(
        m_language, m_kind == eExceptionKindCatch,
        m_kind == eExceptionKindThrow);
    m_bp.AddName(BreakpointBase::kDAPBreakpointLabel);
  }

  m_bp.SetCondition(condition.data());

  protocol::Breakpoint breakpoint;
  breakpoint.id = m_bp.GetID();
  breakpoint.verified = m_bp.IsValid();
  return breakpoint;
}

void ExceptionBreakpoint::ClearBreakpoint() {
  if (!m_bp.IsValid())
    return;
  m_dap.target.BreakpointDelete(m_bp.GetID());
  m_bp = lldb::SBBreakpoint();
}

} // namespace lldb_dap