LLDB mainline
WatchpointResource.cpp
Go to the documentation of this file.
1//===-- WatchpointResource.cpp --------------------------------------------===//
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 <assert.h>
10
12#include "lldb/Utility/Stream.h"
13
14#include <algorithm>
15
16using namespace lldb;
17using namespace lldb_private;
18
20 bool read, bool write)
21 : m_id(GetNextID()), m_addr(addr), m_size(size),
22 m_watch_read(read), m_watch_write(write) {}
23
25 std::lock_guard<std::mutex> guard(m_constituents_mutex);
26 m_constituents.clear();
27}
28
30
31size_t WatchpointResource::GetByteSize() const { return m_size; }
32
34
38
39void WatchpointResource::SetType(bool read, bool write) {
40 m_watch_read = read;
41 m_watch_write = write;
42}
43
45
47 if (addr >= m_addr && addr < m_addr + m_size)
48 return true;
49 return false;
50}
51
53 std::lock_guard<std::mutex> guard(m_constituents_mutex);
54 m_constituents.push_back(wp_sp);
55}
56
58 std::lock_guard<std::mutex> guard(m_constituents_mutex);
59 auto it = llvm::find(m_constituents, wp_sp);
60 if (it != m_constituents.end())
61 m_constituents.erase(it);
62}
63
65 std::lock_guard<std::mutex> guard(m_constituents_mutex);
66 return m_constituents.size();
67}
68
70 return ConstituentsContains(wp_sp.get());
71}
72
74 std::lock_guard<std::mutex> guard(m_constituents_mutex);
75 return llvm::any_of(m_constituents,
76 [&wp](const WatchpointSP &x) { return x.get() == wp; });
77}
78
80 std::lock_guard<std::mutex> guard(m_constituents_mutex);
81 assert(idx < m_constituents.size());
82 if (idx >= m_constituents.size())
83 return {};
84
85 return m_constituents[idx];
86}
87
90 std::lock_guard<std::mutex> guard(m_constituents_mutex);
91 return m_constituents;
92}
93
95 // LWP_TODO: Need to poll all Watchpoint constituents and see if
96 // we should stop, like BreakpointSites do.
97#if 0
98 m_hit_counter.Increment();
99 // ShouldStop can do a lot of work, and might even come back and hit
100 // this breakpoint site again. So don't hold the m_constituents_mutex the
101 // whole while. Instead make a local copy of the collection and call
102 // ShouldStop on the copy.
103 WatchpointResourceCollection constituents_copy;
104 {
105 std::lock_guard<std::recursive_mutex> guard(m_constituents_mutex);
106 constituents_copy = m_constituents;
107 }
108 return constituents_copy.ShouldStop(context);
109#endif
110 return true;
111}
112
114 s->Printf("addr = 0x%8.8" PRIx64 " size = %zu", m_addr, m_size);
115}
116
118 static wp_resource_id_t g_next_id = 0;
119 return ++g_next_id;
120}
General Outline: When we hit a breakpoint we need to package up whatever information is needed to eva...
A stream class that can stream formatted output to a file.
Definition Stream.h:28
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition Stream.cpp:134
bool ShouldStop(StoppointCallbackContext *context)
Enquires of the atchpoints that produced this watchpoint resource whether we should stop at this loca...
size_t GetNumberOfConstituents()
This method returns the number of Watchpoints currently using watchpoint resource.
WatchpointCollection CopyConstituentsList()
This method copies the watchpoint resource's constituents into a new collection.
void AddConstituent(const lldb::WatchpointSP &constituent)
The "Constituents" are the watchpoints that share this resource.
WatchpointCollection m_constituents
The Watchpoints which own this resource.
bool ConstituentsContains(const lldb::WatchpointSP &wp_sp)
Check if the constituents includes a watchpoint.
lldb::WatchpointSP GetConstituentAtIndex(size_t idx)
This method returns the Watchpoint at index index using this Resource.
lldb::wp_resource_id_t GetID() const
static lldb::wp_resource_id_t GetNextID()
void SetType(bool read, bool write)
void Dump(Stream *s) const
Standard Dump method.
std::mutex m_constituents_mutex
This mutex protects the constituents collection.
WatchpointResource(lldb::addr_t addr, size_t size, bool read, bool write)
void RemoveConstituent(lldb::WatchpointSP &constituent)
The method removes the constituent at constituent from this watchpoint resource.
std::vector< lldb::WatchpointSP > WatchpointCollection
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::Watchpoint > WatchpointSP
uint64_t addr_t
Definition lldb-types.h:80
uint32_t wp_resource_id_t
Definition lldb-types.h:88