• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- BreakpointBase.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 "BreakpointBase.h"
10 #include "llvm/ADT/StringExtras.h"
11 
12 using namespace lldb_vscode;
13 
BreakpointBase(const llvm::json::Object & obj)14 BreakpointBase::BreakpointBase(const llvm::json::Object &obj)
15     : condition(std::string(GetString(obj, "condition"))),
16       hitCondition(std::string(GetString(obj, "hitCondition"))),
17       logMessage(std::string(GetString(obj, "logMessage"))) {}
18 
SetCondition()19 void BreakpointBase::SetCondition() { bp.SetCondition(condition.c_str()); }
20 
SetHitCondition()21 void BreakpointBase::SetHitCondition() {
22   uint64_t hitCount = 0;
23   if (llvm::to_integer(hitCondition, hitCount))
24     bp.SetIgnoreCount(hitCount - 1);
25 }
26 
UpdateBreakpoint(const BreakpointBase & request_bp)27 void BreakpointBase::UpdateBreakpoint(const BreakpointBase &request_bp) {
28   if (condition != request_bp.condition) {
29     condition = request_bp.condition;
30     SetCondition();
31   }
32   if (hitCondition != request_bp.hitCondition) {
33     hitCondition = request_bp.hitCondition;
34     SetHitCondition();
35   }
36 }
37 
GetBreakpointLabel()38 const char *BreakpointBase::GetBreakpointLabel() {
39   // Breakpoints in LLDB can have names added to them which are kind of like
40   // labels or categories. All breakpoints that are set through the IDE UI get
41   // sent through the various VS code DAP set*Breakpoint packets, and these
42   // breakpoints will be labeled with this name so if breakpoint update events
43   // come in for breakpoints that the IDE doesn't know about, like if a
44   // breakpoint is set manually using the debugger console, we won't report any
45   // updates on them and confused the IDE. This function gets called by all of
46   // the breakpoint classes after they set breakpoints to mark a breakpoint as
47   // a UI breakpoint. We can later check a lldb::SBBreakpoint object that comes
48   // in via LLDB breakpoint changed events and check the breakpoint by calling
49   // "bool lldb::SBBreakpoint::MatchesName(const char *)" to check if a
50   // breakpoint in one of the UI breakpoints that we should report changes for.
51   return "vscode";
52 }
53