[lldb][NFC] Fix all formatting errors in .cpp file headers
Summary:
A *.cpp file header in LLDB (and in LLDB) should like this:
```
//===-- TestUtilities.cpp -------------------------------------------------===//
```
However in LLDB most of our source files have arbitrary changes to this format and
these changes are spreading through LLDB as folks usually just use the existing
source files as templates for their new files (most notably the unnecessary
editor language indicator `-*- C++ -*-` is spreading and in every review
someone is pointing out that this is wrong, resulting in people pointing out that this
is done in the same way in other files).
This patch removes most of these inconsistencies including the editor language indicators,
all the different missing/additional '-' characters, files that center the file name, missing
trailing `===//` (mostly caused by clang-format breaking the line).
Reviewers: aprantl, espindola, jfb, shafik, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: dexonsmith, wuzish, emaste, sdardis, nemanjai, kbarton, MaskRay, atanasyan, arphaman, jfb, abidh, jsji, JDevlieghere, usaxena95, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D73258
2020-01-24 15:23:27 +08:00
|
|
|
//===-- WatchpointList.cpp ------------------------------------------------===//
|
2011-10-14 08:42:25 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2011-10-14 08:42:25 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/Breakpoint/WatchpointList.h"
|
|
|
|
#include "lldb/Breakpoint/Watchpoint.h"
|
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2022-02-07 02:54:46 +08:00
|
|
|
WatchpointList::WatchpointList() = default;
|
2011-10-14 08:42:25 +08:00
|
|
|
|
2021-07-03 02:27:37 +08:00
|
|
|
WatchpointList::~WatchpointList() = default;
|
2011-10-14 08:42:25 +08:00
|
|
|
|
2012-02-25 14:44:30 +08:00
|
|
|
// Add a watchpoint to the list.
|
2012-12-18 10:03:49 +08:00
|
|
|
lldb::watch_id_t WatchpointList::Add(const WatchpointSP &wp_sp, bool notify) {
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2012-02-25 14:44:30 +08:00
|
|
|
wp_sp->SetID(++m_next_wp_id);
|
|
|
|
m_watchpoints.push_back(wp_sp);
|
2012-12-18 10:03:49 +08:00
|
|
|
if (notify) {
|
|
|
|
if (wp_sp->GetTarget().EventTypeHasListeners(
|
|
|
|
Target::eBroadcastBitWatchpointChanged))
|
|
|
|
wp_sp->GetTarget().BroadcastEvent(Target::eBroadcastBitWatchpointChanged,
|
|
|
|
new Watchpoint::WatchpointEventData(
|
|
|
|
eWatchpointEventTypeAdded, wp_sp));
|
|
|
|
}
|
2011-10-14 08:42:25 +08:00
|
|
|
return wp_sp->GetID();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WatchpointList::Dump(Stream *s) const {
|
|
|
|
DumpWithLevel(s, lldb::eDescriptionLevelBrief);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WatchpointList::DumpWithLevel(
|
|
|
|
Stream *s, lldb::DescriptionLevel description_level) const {
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2014-04-04 12:06:10 +08:00
|
|
|
s->Printf("%p: ", static_cast<const void *>(this));
|
2011-10-14 08:42:25 +08:00
|
|
|
// s->Indent();
|
2012-11-30 05:49:15 +08:00
|
|
|
s->Printf("WatchpointList with %" PRIu64 " Watchpoints:\n",
|
2012-09-19 02:04:04 +08:00
|
|
|
(uint64_t)m_watchpoints.size());
|
2011-10-14 08:42:25 +08:00
|
|
|
s->IndentMore();
|
2012-02-25 14:44:30 +08:00
|
|
|
wp_collection::const_iterator pos, end = m_watchpoints.end();
|
|
|
|
for (pos = m_watchpoints.begin(); pos != end; ++pos)
|
|
|
|
(*pos)->DumpWithLevel(s, description_level);
|
2011-10-14 08:42:25 +08:00
|
|
|
s->IndentLess();
|
|
|
|
}
|
|
|
|
|
|
|
|
const WatchpointSP WatchpointList::FindByAddress(lldb::addr_t addr) const {
|
|
|
|
WatchpointSP wp_sp;
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2012-02-25 14:44:30 +08:00
|
|
|
if (!m_watchpoints.empty()) {
|
|
|
|
wp_collection::const_iterator pos, end = m_watchpoints.end();
|
|
|
|
for (pos = m_watchpoints.begin(); pos != end; ++pos) {
|
2015-12-08 03:38:58 +08:00
|
|
|
lldb::addr_t wp_addr = (*pos)->GetLoadAddress();
|
|
|
|
uint32_t wp_bytesize = (*pos)->GetByteSize();
|
|
|
|
if ((wp_addr <= addr) && ((wp_addr + wp_bytesize) > addr)) {
|
2012-02-25 14:44:30 +08:00
|
|
|
wp_sp = *pos;
|
|
|
|
break;
|
2015-12-08 03:38:58 +08:00
|
|
|
}
|
2012-02-25 14:44:30 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2012-02-25 14:44:30 +08:00
|
|
|
|
|
|
|
return wp_sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
const WatchpointSP WatchpointList::FindBySpec(std::string spec) const {
|
|
|
|
WatchpointSP wp_sp;
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2012-02-25 14:44:30 +08:00
|
|
|
if (!m_watchpoints.empty()) {
|
|
|
|
wp_collection::const_iterator pos, end = m_watchpoints.end();
|
|
|
|
for (pos = m_watchpoints.begin(); pos != end; ++pos)
|
|
|
|
if ((*pos)->GetWatchSpec() == spec) {
|
|
|
|
wp_sp = *pos;
|
|
|
|
break;
|
|
|
|
}
|
2011-10-14 08:42:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return wp_sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
class WatchpointIDMatches {
|
|
|
|
public:
|
|
|
|
WatchpointIDMatches(lldb::watch_id_t watch_id) : m_watch_id(watch_id) {}
|
|
|
|
|
2012-02-25 14:44:30 +08:00
|
|
|
bool operator()(const WatchpointSP &wp) const {
|
|
|
|
return m_watch_id == wp->GetID();
|
2011-10-14 08:42:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const lldb::watch_id_t m_watch_id;
|
|
|
|
};
|
|
|
|
|
2012-02-25 14:44:30 +08:00
|
|
|
WatchpointList::wp_collection::iterator
|
2011-10-14 08:42:25 +08:00
|
|
|
WatchpointList::GetIDIterator(lldb::watch_id_t watch_id) {
|
2012-02-25 14:44:30 +08:00
|
|
|
return std::find_if(m_watchpoints.begin(),
|
|
|
|
m_watchpoints.end(), // Search full range
|
|
|
|
WatchpointIDMatches(watch_id)); // Predicate
|
2011-10-14 08:42:25 +08:00
|
|
|
}
|
|
|
|
|
2012-02-25 14:44:30 +08:00
|
|
|
WatchpointList::wp_collection::const_iterator
|
2011-10-14 08:42:25 +08:00
|
|
|
WatchpointList::GetIDConstIterator(lldb::watch_id_t watch_id) const {
|
2012-02-25 14:44:30 +08:00
|
|
|
return std::find_if(m_watchpoints.begin(),
|
|
|
|
m_watchpoints.end(), // Search full range
|
|
|
|
WatchpointIDMatches(watch_id)); // Predicate
|
2011-10-14 08:42:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
WatchpointSP WatchpointList::FindByID(lldb::watch_id_t watch_id) const {
|
|
|
|
WatchpointSP wp_sp;
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2012-02-25 14:44:30 +08:00
|
|
|
wp_collection::const_iterator pos = GetIDConstIterator(watch_id);
|
|
|
|
if (pos != m_watchpoints.end())
|
|
|
|
wp_sp = *pos;
|
2011-10-14 08:42:25 +08:00
|
|
|
|
|
|
|
return wp_sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
lldb::watch_id_t WatchpointList::FindIDByAddress(lldb::addr_t addr) {
|
|
|
|
WatchpointSP wp_sp = FindByAddress(addr);
|
|
|
|
if (wp_sp) {
|
|
|
|
return wp_sp->GetID();
|
|
|
|
}
|
|
|
|
return LLDB_INVALID_WATCH_ID;
|
|
|
|
}
|
|
|
|
|
2012-02-25 14:44:30 +08:00
|
|
|
lldb::watch_id_t WatchpointList::FindIDBySpec(std::string spec) {
|
|
|
|
WatchpointSP wp_sp = FindBySpec(spec);
|
|
|
|
if (wp_sp) {
|
|
|
|
return wp_sp->GetID();
|
|
|
|
}
|
|
|
|
return LLDB_INVALID_WATCH_ID;
|
|
|
|
}
|
|
|
|
|
2011-10-14 08:42:25 +08:00
|
|
|
WatchpointSP WatchpointList::GetByIndex(uint32_t i) {
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2011-10-14 08:42:25 +08:00
|
|
|
WatchpointSP wp_sp;
|
2012-02-25 14:44:30 +08:00
|
|
|
if (i < m_watchpoints.size()) {
|
|
|
|
wp_collection::const_iterator pos = m_watchpoints.begin();
|
2011-10-14 08:42:25 +08:00
|
|
|
std::advance(pos, i);
|
2012-02-25 14:44:30 +08:00
|
|
|
wp_sp = *pos;
|
2011-10-14 08:42:25 +08:00
|
|
|
}
|
|
|
|
return wp_sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
const WatchpointSP WatchpointList::GetByIndex(uint32_t i) const {
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2011-10-14 08:42:25 +08:00
|
|
|
WatchpointSP wp_sp;
|
2012-02-25 14:44:30 +08:00
|
|
|
if (i < m_watchpoints.size()) {
|
|
|
|
wp_collection::const_iterator pos = m_watchpoints.begin();
|
2011-10-14 08:42:25 +08:00
|
|
|
std::advance(pos, i);
|
2012-02-25 14:44:30 +08:00
|
|
|
wp_sp = *pos;
|
2011-10-14 08:42:25 +08:00
|
|
|
}
|
|
|
|
return wp_sp;
|
|
|
|
}
|
|
|
|
|
2012-02-25 14:44:30 +08:00
|
|
|
std::vector<lldb::watch_id_t> WatchpointList::GetWatchpointIDs() const {
|
|
|
|
std::vector<lldb::watch_id_t> IDs;
|
|
|
|
wp_collection::const_iterator pos, end = m_watchpoints.end();
|
|
|
|
for (pos = m_watchpoints.begin(); pos != end; ++pos)
|
|
|
|
IDs.push_back((*pos)->GetID());
|
|
|
|
return IDs;
|
|
|
|
}
|
|
|
|
|
2012-12-18 10:03:49 +08:00
|
|
|
bool WatchpointList::Remove(lldb::watch_id_t watch_id, bool notify) {
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2012-02-25 14:44:30 +08:00
|
|
|
wp_collection::iterator pos = GetIDIterator(watch_id);
|
|
|
|
if (pos != m_watchpoints.end()) {
|
2012-12-18 10:03:49 +08:00
|
|
|
WatchpointSP wp_sp = *pos;
|
|
|
|
if (notify) {
|
|
|
|
if (wp_sp->GetTarget().EventTypeHasListeners(
|
|
|
|
Target::eBroadcastBitWatchpointChanged))
|
|
|
|
wp_sp->GetTarget().BroadcastEvent(
|
|
|
|
Target::eBroadcastBitWatchpointChanged,
|
|
|
|
new Watchpoint::WatchpointEventData(eWatchpointEventTypeRemoved,
|
|
|
|
wp_sp));
|
2011-10-14 08:42:25 +08:00
|
|
|
}
|
2012-02-25 14:44:30 +08:00
|
|
|
m_watchpoints.erase(pos);
|
2011-10-14 08:42:25 +08:00
|
|
|
return true;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2011-10-14 08:42:25 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t WatchpointList::GetHitCount() const {
|
|
|
|
uint32_t hit_count = 0;
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2012-02-25 14:44:30 +08:00
|
|
|
wp_collection::const_iterator pos, end = m_watchpoints.end();
|
|
|
|
for (pos = m_watchpoints.begin(); pos != end; ++pos)
|
|
|
|
hit_count += (*pos)->GetHitCount();
|
2011-10-14 08:42:25 +08:00
|
|
|
return hit_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WatchpointList::ShouldStop(StoppointCallbackContext *context,
|
|
|
|
lldb::watch_id_t watch_id) {
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-10-14 08:42:25 +08:00
|
|
|
WatchpointSP wp_sp = FindByID(watch_id);
|
|
|
|
if (wp_sp) {
|
2018-05-01 00:49:04 +08:00
|
|
|
// Let the Watchpoint decide if it should stop here (could not have reached
|
|
|
|
// it's target hit count yet, or it could have a callback that decided it
|
|
|
|
// shouldn't stop.
|
2011-10-14 08:42:25 +08:00
|
|
|
return wp_sp->ShouldStop(context);
|
|
|
|
}
|
|
|
|
// We should stop here since this Watchpoint isn't valid anymore or it
|
|
|
|
// doesn't exist.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WatchpointList::GetDescription(Stream *s, lldb::DescriptionLevel level) {
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2012-02-25 14:44:30 +08:00
|
|
|
wp_collection::iterator pos, end = m_watchpoints.end();
|
2011-10-14 08:42:25 +08:00
|
|
|
|
2012-02-25 14:44:30 +08:00
|
|
|
for (pos = m_watchpoints.begin(); pos != end; ++pos) {
|
2011-10-14 08:42:25 +08:00
|
|
|
s->Printf(" ");
|
2012-02-25 14:44:30 +08:00
|
|
|
(*pos)->Dump(s);
|
2011-10-14 08:42:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WatchpointList::SetEnabledAll(bool enabled) {
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2011-10-14 08:42:25 +08:00
|
|
|
|
2012-02-25 14:44:30 +08:00
|
|
|
wp_collection::iterator pos, end = m_watchpoints.end();
|
|
|
|
for (pos = m_watchpoints.begin(); pos != end; ++pos)
|
|
|
|
(*pos)->SetEnabled(enabled);
|
2011-10-14 08:42:25 +08:00
|
|
|
}
|
|
|
|
|
2012-12-18 10:03:49 +08:00
|
|
|
void WatchpointList::RemoveAll(bool notify) {
|
2016-05-19 13:13:57 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2012-12-18 10:03:49 +08:00
|
|
|
if (notify) {
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-12-18 10:03:49 +08:00
|
|
|
{
|
|
|
|
wp_collection::iterator pos, end = m_watchpoints.end();
|
|
|
|
for (pos = m_watchpoints.begin(); pos != end; ++pos) {
|
|
|
|
if ((*pos)->GetTarget().EventTypeHasListeners(
|
|
|
|
Target::eBroadcastBitBreakpointChanged)) {
|
|
|
|
(*pos)->GetTarget().BroadcastEvent(
|
|
|
|
Target::eBroadcastBitWatchpointChanged,
|
|
|
|
new Watchpoint::WatchpointEventData(eWatchpointEventTypeRemoved,
|
|
|
|
*pos));
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2012-12-18 10:03:49 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2012-02-25 14:44:30 +08:00
|
|
|
m_watchpoints.clear();
|
2011-10-14 08:42:25 +08:00
|
|
|
}
|
|
|
|
|
2016-05-19 13:13:57 +08:00
|
|
|
void WatchpointList::GetListMutex(
|
|
|
|
std::unique_lock<std::recursive_mutex> &lock) {
|
|
|
|
lock = std::unique_lock<std::recursive_mutex>(m_mutex);
|
2011-10-14 08:42:25 +08:00
|
|
|
}
|