xref: /openbsd-src/gnu/llvm/lldb/tools/lldb-vscode/BreakpointBase.cpp (revision fcde59b201a29a2b4570b00b71e7aa25d61cb5c1)
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 
14 BreakpointBase::BreakpointBase(const llvm::json::Object &obj)
15     : condition(GetString(obj, "condition")),
16       hitCondition(GetString(obj, "hitCondition")),
17       logMessage(GetString(obj, "logMessage")) {}
18 
19 void BreakpointBase::SetCondition() { bp.SetCondition(condition.c_str()); }
20 
21 void BreakpointBase::SetHitCondition() {
22   uint64_t hitCount = 0;
23   if (llvm::to_integer(hitCondition, hitCount))
24     bp.SetIgnoreCount(hitCount - 1);
25 }
26 
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