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
36 return m_watch_write;
37}
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 const auto &it =
60 std::find(m_constituents.begin(), m_constituents.end(), wp_sp);
61 if (it != m_constituents.end())
62 m_constituents.erase(it);
63}
64
66 std::lock_guard<std::mutex> guard(m_constituents_mutex);
67 return m_constituents.size();
68}
69
71 return ConstituentsContains(wp_sp.get());
72}
73
75 std::lock_guard<std::mutex> guard(m_constituents_mutex);
76 WatchpointCollection::const_iterator match =
77 std::find_if(m_constituents.begin(), m_constituents.end(),
78 [&wp](const WatchpointSP &x) { return x.get() == wp; });
79 return match != m_constituents.end();
80}
81
83 std::lock_guard<std::mutex> guard(m_constituents_mutex);
84 assert(idx < m_constituents.size());
85 if (idx >= m_constituents.size())
86 return {};
87
88 return m_constituents[idx];
89}
90
93 std::lock_guard<std::mutex> guard(m_constituents_mutex);
94 return m_constituents;
95}
96
98 // LWP_TODO: Need to poll all Watchpoint constituents and see if
99 // we should stop, like BreakpointSites do.
100#if 0
101 m_hit_counter.Increment();
102 // ShouldStop can do a lot of work, and might even come back and hit
103 // this breakpoint site again. So don't hold the m_constituents_mutex the
104 // whole while. Instead make a local copy of the collection and call
105 // ShouldStop on the copy.
106 WatchpointResourceCollection constituents_copy;
107 {
108 std::lock_guard<std::recursive_mutex> guard(m_constituents_mutex);
109 constituents_copy = m_constituents;
110 }
111 return constituents_copy.ShouldStop(context);
112#endif
113 return true;
114}
115
117 s->Printf("addr = 0x%8.8" PRIx64 " size = %zu", m_addr, m_size);
118}
119
121 static wp_resource_id_t g_next_id = 0;
122 return ++g_next_id;
123}
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.
Definition: SBAttachInfo.h:14
Definition: SBAddress.h:15
std::shared_ptr< lldb_private::Watchpoint > WatchpointSP
Definition: lldb-forward.h:477
uint64_t addr_t
Definition: lldb-types.h:79
uint32_t wp_resource_id_t
Definition: lldb-types.h:86