[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
|
|
|
//===-- BreakpointSite.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
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2015-03-05 01:43:00 +08:00
|
|
|
#include <inttypes.h>
|
|
|
|
|
2015-10-31 02:50:12 +08:00
|
|
|
#include "lldb/Breakpoint/BreakpointSite.h"
|
|
|
|
|
2010-11-19 02:52:36 +08:00
|
|
|
#include "lldb/Breakpoint/Breakpoint.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Breakpoint/BreakpointLocation.h"
|
|
|
|
#include "lldb/Breakpoint/BreakpointSiteList.h"
|
2017-02-03 05:39:50 +08:00
|
|
|
#include "lldb/Utility/Stream.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2016-05-18 09:59:10 +08:00
|
|
|
BreakpointSite::BreakpointSite(BreakpointSiteList *list,
|
|
|
|
const BreakpointLocationSP &owner,
|
|
|
|
lldb::addr_t addr, bool use_hardware)
|
|
|
|
: StoppointLocation(GetNextID(), addr, 0, use_hardware),
|
|
|
|
m_type(eSoftware), // Process subclasses need to set this correctly using
|
|
|
|
// SetType()
|
|
|
|
m_saved_opcode(), m_trap_opcode(),
|
|
|
|
m_enabled(false), // Need to create it disabled, so the first enable turns
|
|
|
|
// it on.
|
|
|
|
m_owners(), m_owners_mutex() {
|
2010-06-09 00:52:24 +08:00
|
|
|
m_owners.Add(owner);
|
|
|
|
}
|
|
|
|
|
|
|
|
BreakpointSite::~BreakpointSite() {
|
|
|
|
BreakpointLocationSP bp_loc_sp;
|
2010-07-10 04:39:50 +08:00
|
|
|
const size_t owner_count = m_owners.GetSize();
|
|
|
|
for (size_t i = 0; i < owner_count; i++) {
|
2010-06-09 00:52:24 +08:00
|
|
|
m_owners.GetByIndex(i)->ClearBreakpointSite();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break_id_t BreakpointSite::GetNextID() {
|
|
|
|
static break_id_t g_next_id = 0;
|
|
|
|
return ++g_next_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
// RETURNS - true if we should stop at this breakpoint, false if we
|
|
|
|
// should continue.
|
|
|
|
|
|
|
|
bool BreakpointSite::ShouldStop(StoppointCallbackContext *context) {
|
2012-01-24 07:03:59 +08:00
|
|
|
IncrementHitCount();
|
2019-03-28 09:51:33 +08:00
|
|
|
// ShouldStop can do a lot of work, and might even come come back and hit
|
|
|
|
// this breakpoint site again. So don't hold the m_owners_mutex the whole
|
|
|
|
// while. Instead make a local copy of the collection and call ShouldStop on
|
|
|
|
// the copy.
|
|
|
|
BreakpointLocationCollection owners_copy;
|
|
|
|
{
|
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_owners_mutex);
|
|
|
|
owners_copy = m_owners;
|
|
|
|
}
|
|
|
|
return owners_copy.ShouldStop(context);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool BreakpointSite::IsBreakpointAtThisSite(lldb::break_id_t bp_id) {
|
2016-05-18 09:59:10 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_owners_mutex);
|
2010-07-10 04:39:50 +08:00
|
|
|
const size_t owner_count = m_owners.GetSize();
|
|
|
|
for (size_t i = 0; i < owner_count; i++) {
|
2010-06-09 00:52:24 +08:00
|
|
|
if (m_owners.GetByIndex(i)->GetBreakpoint().GetID() == bp_id)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BreakpointSite::Dump(Stream *s) const {
|
2015-10-31 02:50:12 +08:00
|
|
|
if (s == nullptr)
|
2010-06-09 00:52:24 +08:00
|
|
|
return;
|
|
|
|
|
2012-11-30 05:49:15 +08:00
|
|
|
s->Printf("BreakpointSite %u: addr = 0x%8.8" PRIx64
|
|
|
|
" type = %s breakpoint hw_index = %i hit_count = %-4u",
|
2010-06-09 00:52:24 +08:00
|
|
|
GetID(), (uint64_t)m_addr, IsHardware() ? "hardware" : "software",
|
|
|
|
GetHardwareIndex(), GetHitCount());
|
|
|
|
}
|
|
|
|
|
|
|
|
void BreakpointSite::GetDescription(Stream *s, lldb::DescriptionLevel level) {
|
2016-05-18 09:59:10 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_owners_mutex);
|
2010-06-09 00:52:24 +08:00
|
|
|
if (level != lldb::eDescriptionLevelBrief)
|
2012-11-30 05:49:15 +08:00
|
|
|
s->Printf("breakpoint site: %d at 0x%8.8" PRIx64, GetID(),
|
|
|
|
GetLoadAddress());
|
2010-06-09 00:52:24 +08:00
|
|
|
m_owners.GetDescription(s, level);
|
|
|
|
}
|
|
|
|
|
2013-01-26 10:19:28 +08:00
|
|
|
bool BreakpointSite::IsInternal() const { return m_owners.IsInternal(); }
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
uint8_t *BreakpointSite::GetTrapOpcodeBytes() { return &m_trap_opcode[0]; }
|
|
|
|
|
|
|
|
const uint8_t *BreakpointSite::GetTrapOpcodeBytes() const {
|
|
|
|
return &m_trap_opcode[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t BreakpointSite::GetTrapOpcodeMaxByteSize() const {
|
|
|
|
return sizeof(m_trap_opcode);
|
|
|
|
}
|
|
|
|
|
2013-01-26 02:06:21 +08:00
|
|
|
bool BreakpointSite::SetTrapOpcode(const uint8_t *trap_opcode,
|
|
|
|
uint32_t trap_opcode_size) {
|
2010-06-09 00:52:24 +08:00
|
|
|
if (trap_opcode_size > 0 && trap_opcode_size <= sizeof(m_trap_opcode)) {
|
|
|
|
m_byte_size = trap_opcode_size;
|
|
|
|
::memcpy(m_trap_opcode, trap_opcode, trap_opcode_size);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
m_byte_size = 0;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t *BreakpointSite::GetSavedOpcodeBytes() { return &m_saved_opcode[0]; }
|
|
|
|
|
|
|
|
const uint8_t *BreakpointSite::GetSavedOpcodeBytes() const {
|
|
|
|
return &m_saved_opcode[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BreakpointSite::IsEnabled() const { return m_enabled; }
|
|
|
|
|
|
|
|
void BreakpointSite::SetEnabled(bool enabled) { m_enabled = enabled; }
|
|
|
|
|
2012-01-30 04:56:30 +08:00
|
|
|
void BreakpointSite::AddOwner(const BreakpointLocationSP &owner) {
|
2016-05-18 09:59:10 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_owners_mutex);
|
2010-06-09 00:52:24 +08:00
|
|
|
m_owners.Add(owner);
|
|
|
|
}
|
|
|
|
|
2010-07-10 04:39:50 +08:00
|
|
|
size_t BreakpointSite::RemoveOwner(lldb::break_id_t break_id,
|
|
|
|
lldb::break_id_t break_loc_id) {
|
2016-05-18 09:59:10 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_owners_mutex);
|
2010-06-09 00:52:24 +08:00
|
|
|
m_owners.Remove(break_id, break_loc_id);
|
|
|
|
return m_owners.GetSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t BreakpointSite::GetNumberOfOwners() {
|
2016-05-18 09:59:10 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_owners_mutex);
|
2010-06-09 00:52:24 +08:00
|
|
|
return m_owners.GetSize();
|
|
|
|
}
|
|
|
|
|
2013-01-26 02:06:21 +08:00
|
|
|
BreakpointLocationSP BreakpointSite::GetOwnerAtIndex(size_t index) {
|
2016-05-18 09:59:10 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_owners_mutex);
|
2010-06-09 00:52:24 +08:00
|
|
|
return m_owners.GetByIndex(index);
|
|
|
|
}
|
|
|
|
|
2010-06-16 10:00:15 +08:00
|
|
|
bool BreakpointSite::ValidForThisThread(Thread *thread) {
|
2016-05-18 09:59:10 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_owners_mutex);
|
2010-06-16 10:00:15 +08:00
|
|
|
return m_owners.ValidForThisThread(thread);
|
|
|
|
}
|
|
|
|
|
2014-10-22 09:54:17 +08:00
|
|
|
void BreakpointSite::BumpHitCounts() {
|
2016-05-18 09:59:10 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_owners_mutex);
|
2014-10-22 09:54:17 +08:00
|
|
|
for (BreakpointLocationSP loc_sp : m_owners.BreakpointLocations()) {
|
|
|
|
loc_sp->BumpHitCount();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-25 10:49:44 +08:00
|
|
|
void BreakpointSite::SetHardwareIndex(uint32_t index) {
|
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_owners_mutex);
|
|
|
|
for (BreakpointLocationSP loc_sp : m_owners.BreakpointLocations()) {
|
|
|
|
loc_sp->SetHardwareIndex(index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
bool BreakpointSite::IntersectsRange(lldb::addr_t addr, size_t size,
|
|
|
|
lldb::addr_t *intersect_addr,
|
|
|
|
size_t *intersect_size,
|
|
|
|
size_t *opcode_offset) const {
|
2020-07-22 19:45:10 +08:00
|
|
|
// The function should be called only for software breakpoints.
|
|
|
|
lldbassert(GetType() == Type::eSoftware);
|
|
|
|
|
2020-07-30 02:52:40 +08:00
|
|
|
if (m_byte_size == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const lldb::addr_t bp_end_addr = m_addr + m_byte_size;
|
|
|
|
const lldb::addr_t end_addr = addr + size;
|
|
|
|
// Is the breakpoint end address before the passed in start address?
|
|
|
|
if (bp_end_addr <= addr)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Is the breakpoint start address after passed in end address?
|
|
|
|
if (end_addr <= m_addr)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (intersect_addr || intersect_size || opcode_offset) {
|
|
|
|
if (m_addr < addr) {
|
|
|
|
if (intersect_addr)
|
|
|
|
*intersect_addr = addr;
|
|
|
|
if (intersect_size)
|
|
|
|
*intersect_size =
|
|
|
|
std::min<lldb::addr_t>(bp_end_addr, end_addr) - addr;
|
|
|
|
if (opcode_offset)
|
|
|
|
*opcode_offset = addr - m_addr;
|
|
|
|
} else {
|
|
|
|
if (intersect_addr)
|
|
|
|
*intersect_addr = m_addr;
|
|
|
|
if (intersect_size)
|
|
|
|
*intersect_size =
|
|
|
|
std::min<lldb::addr_t>(bp_end_addr, end_addr) - m_addr;
|
|
|
|
if (opcode_offset)
|
|
|
|
*opcode_offset = 0;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2020-07-30 02:52:40 +08:00
|
|
|
return true;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2015-07-30 01:51:36 +08:00
|
|
|
|
|
|
|
size_t
|
|
|
|
BreakpointSite::CopyOwnersList(BreakpointLocationCollection &out_collection) {
|
2016-05-18 09:59:10 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_owners_mutex);
|
2015-07-30 01:51:36 +08:00
|
|
|
for (BreakpointLocationSP loc_sp : m_owners.BreakpointLocations()) {
|
|
|
|
out_collection.Add(loc_sp);
|
|
|
|
}
|
|
|
|
return out_collection.GetSize();
|
|
|
|
}
|