1 | //===-- Watchpoint.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 "Watchpoint.h" |
10 | #include "DAP.h" |
11 | #include "JSONUtils.h" |
12 | #include "llvm/ADT/StringExtras.h" |
13 | |
14 | namespace lldb_dap { |
15 | Watchpoint::Watchpoint(const llvm::json::Object &obj) : BreakpointBase(obj) { |
16 | llvm::StringRef dataId = GetString(obj, key: "dataId" ); |
17 | std::string accessType = GetString(obj, key: "accessType" ).str(); |
18 | auto [addr_str, size_str] = dataId.split(Separator: '/'); |
19 | llvm::to_integer(S: addr_str, Num&: addr, Base: 16); |
20 | llvm::to_integer(S: size_str, Num&: size); |
21 | options.SetWatchpointTypeRead(accessType != "write" ); |
22 | if (accessType != "read" ) |
23 | options.SetWatchpointTypeWrite(lldb::eWatchpointWriteTypeOnModify); |
24 | } |
25 | |
26 | void Watchpoint::SetCondition() { wp.SetCondition(condition.c_str()); } |
27 | |
28 | void Watchpoint::SetHitCondition() { |
29 | uint64_t hitCount = 0; |
30 | if (llvm::to_integer(S: hitCondition, Num&: hitCount)) |
31 | wp.SetIgnoreCount(hitCount - 1); |
32 | } |
33 | |
34 | void Watchpoint::CreateJsonObject(llvm::json::Object &object) { |
35 | if (!error.IsValid() || error.Fail()) { |
36 | object.try_emplace(K: "verified" , Args: false); |
37 | if (error.Fail()) |
38 | EmplaceSafeString(obj&: object, key: "message" , str: error.GetCString()); |
39 | } else { |
40 | object.try_emplace(K: "verified" , Args: true); |
41 | } |
42 | } |
43 | |
44 | void Watchpoint::SetWatchpoint() { |
45 | wp = g_dap.target.WatchpointCreateByAddress(addr, size, options, error); |
46 | if (!condition.empty()) |
47 | SetCondition(); |
48 | if (!hitCondition.empty()) |
49 | SetHitCondition(); |
50 | } |
51 | } // namespace lldb_dap |
52 | |