[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
|
|
|
//===-- BreakpointSiteList.cpp --------------------------------------------===//
|
2010-06-09 00:52:24 +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
|
2010-06-09 00:52:24 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/Breakpoint/BreakpointSiteList.h"
|
|
|
|
|
2017-02-03 05:39:50 +08:00
|
|
|
#include "lldb/Utility/Stream.h"
|
2010-06-09 15:47:43 +08:00
|
|
|
#include <algorithm>
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2016-05-18 09:59:10 +08:00
|
|
|
BreakpointSiteList::BreakpointSiteList() : m_mutex(), m_bp_site_list() {}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
BreakpointSiteList::~BreakpointSiteList() {}
|
|
|
|
|
|
|
|
// Add breakpoint site to the list. However, if the element already exists in
|
2018-05-01 00:49:04 +08:00
|
|
|
// the list, then we don't add it, and return LLDB_INVALID_BREAK_ID.
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
lldb::break_id_t BreakpointSiteList::Add(const BreakpointSiteSP &bp) {
|
|
|
|
lldb::addr_t bp_site_load_addr = bp->GetLoadAddress();
|
2016-05-18 09:59:10 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2010-06-09 00:52:24 +08:00
|
|
|
collection::iterator iter = m_bp_site_list.find(bp_site_load_addr);
|
|
|
|
|
2010-08-04 09:40:35 +08:00
|
|
|
if (iter == m_bp_site_list.end()) {
|
|
|
|
m_bp_site_list.insert(iter, collection::value_type(bp_site_load_addr, bp));
|
2010-06-09 00:52:24 +08:00
|
|
|
return bp->GetID();
|
|
|
|
} else {
|
|
|
|
return LLDB_INVALID_BREAK_ID;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-04 09:40:35 +08:00
|
|
|
bool BreakpointSiteList::ShouldStop(StoppointCallbackContext *context,
|
2012-03-09 12:10:47 +08:00
|
|
|
lldb::break_id_t site_id) {
|
2010-08-04 09:40:35 +08:00
|
|
|
BreakpointSiteSP site_sp(FindByID(site_id));
|
|
|
|
if (site_sp) {
|
2010-06-09 00:52:24 +08:00
|
|
|
// Let the BreakpointSite decide if it should stop here (could not have
|
2018-05-01 00:49:04 +08:00
|
|
|
// reached it's target hit count yet, or it could have a callback that
|
|
|
|
// decided it shouldn't stop (shared library loads/unloads).
|
2010-08-04 09:40:35 +08:00
|
|
|
return site_sp->ShouldStop(context);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
// We should stop here since this BreakpointSite isn't valid anymore or it
|
|
|
|
// doesn't exist.
|
|
|
|
return true;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
lldb::break_id_t BreakpointSiteList::FindIDByAddress(lldb::addr_t addr) {
|
|
|
|
BreakpointSiteSP bp = FindByAddress(addr);
|
2016-09-07 04:57:50 +08:00
|
|
|
if (bp) {
|
2012-11-30 05:49:15 +08:00
|
|
|
// DBLogIf(PD_LOG_BREAKPOINTS, "BreakpointSiteList::%s ( addr = 0x%8.8"
|
|
|
|
// PRIx64 " ) => %u", __FUNCTION__, (uint64_t)addr, bp->GetID());
|
2010-06-09 00:52:24 +08:00
|
|
|
return bp.get()->GetID();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2018-05-01 00:49:04 +08:00
|
|
|
// DBLogIf(PD_LOG_BREAKPOINTS, "BreakpointSiteList::%s ( addr = 0x%8.8"
|
|
|
|
// PRIx64
|
2012-11-30 05:49:15 +08:00
|
|
|
// " ) => NONE", __FUNCTION__, (uint64_t)addr);
|
2010-06-09 00:52:24 +08:00
|
|
|
return LLDB_INVALID_BREAK_ID;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2010-07-10 04:39:50 +08:00
|
|
|
bool BreakpointSiteList::Remove(lldb::break_id_t break_id) {
|
2016-05-18 09:59:10 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2010-06-09 00:52:24 +08:00
|
|
|
collection::iterator pos = GetIDIterator(break_id); // Predicate
|
|
|
|
if (pos != m_bp_site_list.end()) {
|
|
|
|
m_bp_site_list.erase(pos);
|
|
|
|
return true;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-07-10 04:39:50 +08:00
|
|
|
bool BreakpointSiteList::RemoveByAddress(lldb::addr_t address) {
|
2016-05-18 09:59:10 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2010-06-09 00:52:24 +08:00
|
|
|
collection::iterator pos = m_bp_site_list.find(address);
|
|
|
|
if (pos != m_bp_site_list.end()) {
|
|
|
|
m_bp_site_list.erase(pos);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
class BreakpointSiteIDMatches {
|
|
|
|
public:
|
2010-07-10 04:39:50 +08:00
|
|
|
BreakpointSiteIDMatches(lldb::break_id_t break_id) : m_break_id(break_id) {}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
bool operator()(std::pair<lldb::addr_t, BreakpointSiteSP> val_pair) const {
|
2019-02-12 11:47:39 +08:00
|
|
|
return m_break_id == val_pair.second->GetID();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2010-07-10 04:39:50 +08:00
|
|
|
const lldb::break_id_t m_break_id;
|
2010-06-09 00:52:24 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
BreakpointSiteList::collection::iterator
|
2010-07-10 04:39:50 +08:00
|
|
|
BreakpointSiteList::GetIDIterator(lldb::break_id_t break_id) {
|
2016-05-18 09:59:10 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2010-06-09 00:52:24 +08:00
|
|
|
return std::find_if(m_bp_site_list.begin(),
|
|
|
|
m_bp_site_list.end(), // Search full range
|
|
|
|
BreakpointSiteIDMatches(break_id)); // Predicate
|
|
|
|
}
|
|
|
|
|
|
|
|
BreakpointSiteList::collection::const_iterator
|
2010-07-10 04:39:50 +08:00
|
|
|
BreakpointSiteList::GetIDConstIterator(lldb::break_id_t break_id) const {
|
2016-05-18 09:59:10 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2010-06-09 00:52:24 +08:00
|
|
|
return std::find_if(m_bp_site_list.begin(),
|
|
|
|
m_bp_site_list.end(), // Search full range
|
|
|
|
BreakpointSiteIDMatches(break_id)); // Predicate
|
|
|
|
}
|
|
|
|
|
2010-07-10 04:39:50 +08:00
|
|
|
BreakpointSiteSP BreakpointSiteList::FindByID(lldb::break_id_t break_id) {
|
2016-05-18 09:59:10 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2010-06-09 00:52:24 +08:00
|
|
|
BreakpointSiteSP stop_sp;
|
|
|
|
collection::iterator pos = GetIDIterator(break_id);
|
|
|
|
if (pos != m_bp_site_list.end())
|
|
|
|
stop_sp = pos->second;
|
|
|
|
|
|
|
|
return stop_sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
const BreakpointSiteSP
|
2010-07-10 04:39:50 +08:00
|
|
|
BreakpointSiteList::FindByID(lldb::break_id_t break_id) const {
|
2016-05-18 09:59:10 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2010-06-09 00:52:24 +08:00
|
|
|
BreakpointSiteSP stop_sp;
|
|
|
|
collection::const_iterator pos = GetIDConstIterator(break_id);
|
|
|
|
if (pos != m_bp_site_list.end())
|
|
|
|
stop_sp = pos->second;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
return stop_sp;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
BreakpointSiteSP BreakpointSiteList::FindByAddress(lldb::addr_t addr) {
|
|
|
|
BreakpointSiteSP found_sp;
|
2016-05-18 09:59:10 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2010-06-09 00:52:24 +08:00
|
|
|
collection::iterator iter = m_bp_site_list.find(addr);
|
|
|
|
if (iter != m_bp_site_list.end())
|
|
|
|
found_sp = iter->second;
|
2010-08-04 09:40:35 +08:00
|
|
|
return found_sp;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2011-06-30 03:42:28 +08:00
|
|
|
bool BreakpointSiteList::BreakpointSiteContainsBreakpoint(
|
|
|
|
lldb::break_id_t bp_site_id, lldb::break_id_t bp_id) {
|
2016-05-18 09:59:10 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2010-06-09 00:52:24 +08:00
|
|
|
collection::const_iterator pos = GetIDConstIterator(bp_site_id);
|
|
|
|
if (pos != m_bp_site_list.end())
|
|
|
|
return pos->second->IsBreakpointAtThisSite(bp_id);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
return false;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-03-09 12:10:47 +08:00
|
|
|
void BreakpointSiteList::Dump(Stream *s) const {
|
|
|
|
s->Printf("%p: ", static_cast<const void *>(this));
|
2011-03-19 09:12:21 +08:00
|
|
|
// s->Indent();
|
2012-03-09 12:10:47 +08:00
|
|
|
s->Printf("BreakpointSiteList with %u BreakpointSites:\n",
|
|
|
|
(uint32_t)m_bp_site_list.size());
|
|
|
|
s->IndentMore();
|
|
|
|
collection::const_iterator pos;
|
|
|
|
collection::const_iterator end = m_bp_site_list.end();
|
2010-06-09 00:52:24 +08:00
|
|
|
for (pos = m_bp_site_list.begin(); pos != end; ++pos)
|
2019-02-12 11:47:39 +08:00
|
|
|
pos->second->Dump(s);
|
2010-06-09 00:52:24 +08:00
|
|
|
s->IndentLess();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2012-03-09 12:10:47 +08:00
|
|
|
void BreakpointSiteList::ForEach(
|
|
|
|
std::function<void(BreakpointSite *)> const &callback) {
|
2016-05-18 09:59:10 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
2012-03-09 12:10:47 +08:00
|
|
|
for (auto pair : m_bp_site_list)
|
2013-02-14 11:04:50 +08:00
|
|
|
callback(pair.second.get());
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2013-02-14 11:04:50 +08:00
|
|
|
bool BreakpointSiteList::FindInRange(lldb::addr_t lower_bound,
|
2011-06-30 03:42:28 +08:00
|
|
|
lldb::addr_t upper_bound,
|
2013-02-14 11:04:50 +08:00
|
|
|
BreakpointSiteList &bp_site_list) const {
|
|
|
|
if (lower_bound > upper_bound)
|
2012-03-09 12:10:47 +08:00
|
|
|
return false;
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
|
|
|
collection::const_iterator lower, upper, pos;
|
|
|
|
lower = m_bp_site_list.lower_bound(lower_bound);
|
|
|
|
if (lower == m_bp_site_list.end() || (*lower).first >= upper_bound)
|
2013-06-12 08:46:38 +08:00
|
|
|
return false;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// This is one tricky bit. The breakpoint might overlap the bottom end of
|
|
|
|
// the range. So we grab the breakpoint prior to the lower bound, and check
|
|
|
|
// that that + its byte size isn't in our range.
|
2011-06-30 03:42:28 +08:00
|
|
|
if (lower != m_bp_site_list.begin()) {
|
|
|
|
collection::const_iterator prev_pos = lower;
|
|
|
|
prev_pos--;
|
|
|
|
const BreakpointSiteSP &prev_bp = (*prev_pos).second;
|
|
|
|
if (prev_bp->GetLoadAddress() + prev_bp->GetByteSize() > lower_bound)
|
|
|
|
bp_site_list.Add(prev_bp);
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-06-30 03:42:28 +08:00
|
|
|
upper = m_bp_site_list.upper_bound(upper_bound);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-06-30 03:42:28 +08:00
|
|
|
for (pos = lower; pos != upper; pos++) {
|
|
|
|
bp_site_list.Add((*pos).second);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|