[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
|
|
|
//===-- AddressRange.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/Core/AddressRange.h"
|
2010-09-10 09:30:46 +08:00
|
|
|
#include "lldb/Core/Module.h"
|
2010-09-15 07:36:40 +08:00
|
|
|
#include "lldb/Target/Target.h"
|
2018-11-12 07:16:43 +08:00
|
|
|
#include "lldb/Utility/ConstString.h"
|
|
|
|
#include "lldb/Utility/FileSpec.h"
|
2017-02-03 05:39:50 +08:00
|
|
|
#include "lldb/Utility/Stream.h"
|
2018-11-12 07:16:43 +08:00
|
|
|
#include "lldb/lldb-defines.h"
|
2017-04-07 05:28:29 +08:00
|
|
|
|
2018-11-12 07:16:43 +08:00
|
|
|
#include "llvm/Support/Compiler.h"
|
2017-04-07 05:28:29 +08:00
|
|
|
|
2018-11-12 07:16:43 +08:00
|
|
|
#include <memory>
|
2017-04-07 05:28:29 +08:00
|
|
|
|
2018-11-12 07:16:43 +08:00
|
|
|
#include <inttypes.h>
|
2017-04-07 05:28:29 +08:00
|
|
|
|
|
|
|
namespace lldb_private {
|
|
|
|
class SectionList;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
AddressRange::AddressRange() : m_base_addr(), m_byte_size(0) {}
|
|
|
|
|
|
|
|
AddressRange::AddressRange(addr_t file_addr, addr_t byte_size,
|
|
|
|
const SectionList *section_list)
|
|
|
|
: m_base_addr(file_addr, section_list), m_byte_size(byte_size) {}
|
|
|
|
|
2012-02-24 09:59:29 +08:00
|
|
|
AddressRange::AddressRange(const lldb::SectionSP §ion, addr_t offset,
|
|
|
|
addr_t byte_size)
|
2010-06-09 00:52:24 +08:00
|
|
|
: m_base_addr(section, offset), m_byte_size(byte_size) {}
|
|
|
|
|
|
|
|
AddressRange::AddressRange(const Address &so_addr, addr_t byte_size)
|
|
|
|
: m_base_addr(so_addr), m_byte_size(byte_size) {}
|
|
|
|
|
|
|
|
AddressRange::~AddressRange() {}
|
|
|
|
|
|
|
|
// bool
|
|
|
|
// AddressRange::Contains (const Address &addr) const
|
|
|
|
//{
|
|
|
|
// const addr_t byte_size = GetByteSize();
|
|
|
|
// if (byte_size)
|
|
|
|
// return addr.GetSection() == m_base_addr.GetSection() &&
|
|
|
|
// (addr.GetOffset() - m_base_addr.GetOffset()) < byte_size;
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
// bool
|
|
|
|
// AddressRange::Contains (const Address *addr) const
|
|
|
|
//{
|
|
|
|
// if (addr)
|
|
|
|
// return Contains (*addr);
|
|
|
|
// return false;
|
|
|
|
//}
|
|
|
|
|
|
|
|
bool AddressRange::ContainsFileAddress(const Address &addr) const {
|
|
|
|
if (addr.GetSection() == m_base_addr.GetSection())
|
|
|
|
return (addr.GetOffset() - m_base_addr.GetOffset()) < GetByteSize();
|
|
|
|
addr_t file_base_addr = GetBaseAddress().GetFileAddress();
|
|
|
|
if (file_base_addr == LLDB_INVALID_ADDRESS)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
addr_t file_addr = addr.GetFileAddress();
|
|
|
|
if (file_addr == LLDB_INVALID_ADDRESS)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (file_base_addr <= file_addr)
|
|
|
|
return (file_addr - file_base_addr) < GetByteSize();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AddressRange::ContainsFileAddress(addr_t file_addr) const {
|
|
|
|
if (file_addr == LLDB_INVALID_ADDRESS)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
addr_t file_base_addr = GetBaseAddress().GetFileAddress();
|
|
|
|
if (file_base_addr == LLDB_INVALID_ADDRESS)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (file_base_addr <= file_addr)
|
|
|
|
return (file_addr - file_base_addr) < GetByteSize();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-09-15 07:36:40 +08:00
|
|
|
bool AddressRange::ContainsLoadAddress(const Address &addr,
|
|
|
|
Target *target) const {
|
2010-06-09 00:52:24 +08:00
|
|
|
if (addr.GetSection() == m_base_addr.GetSection())
|
|
|
|
return (addr.GetOffset() - m_base_addr.GetOffset()) < GetByteSize();
|
2010-09-15 07:36:40 +08:00
|
|
|
addr_t load_base_addr = GetBaseAddress().GetLoadAddress(target);
|
2010-06-09 00:52:24 +08:00
|
|
|
if (load_base_addr == LLDB_INVALID_ADDRESS)
|
|
|
|
return false;
|
|
|
|
|
2010-09-15 07:36:40 +08:00
|
|
|
addr_t load_addr = addr.GetLoadAddress(target);
|
2010-06-09 00:52:24 +08:00
|
|
|
if (load_addr == LLDB_INVALID_ADDRESS)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (load_base_addr <= load_addr)
|
|
|
|
return (load_addr - load_base_addr) < GetByteSize();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-09-15 07:36:40 +08:00
|
|
|
bool AddressRange::ContainsLoadAddress(addr_t load_addr, Target *target) const {
|
2010-06-09 00:52:24 +08:00
|
|
|
if (load_addr == LLDB_INVALID_ADDRESS)
|
|
|
|
return false;
|
|
|
|
|
2010-09-15 07:36:40 +08:00
|
|
|
addr_t load_base_addr = GetBaseAddress().GetLoadAddress(target);
|
2010-06-09 00:52:24 +08:00
|
|
|
if (load_base_addr == LLDB_INVALID_ADDRESS)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (load_base_addr <= load_addr)
|
|
|
|
return (load_addr - load_base_addr) < GetByteSize();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-05-07 04:01:21 +08:00
|
|
|
bool AddressRange::Extend(const AddressRange &rhs_range) {
|
|
|
|
addr_t lhs_end_addr = GetBaseAddress().GetFileAddress() + GetByteSize();
|
|
|
|
addr_t rhs_base_addr = rhs_range.GetBaseAddress().GetFileAddress();
|
|
|
|
|
|
|
|
if (!ContainsFileAddress(rhs_range.GetBaseAddress()) &&
|
|
|
|
lhs_end_addr != rhs_base_addr)
|
|
|
|
// The ranges don't intersect at all on the right side of this range.
|
|
|
|
return false;
|
|
|
|
|
|
|
|
addr_t rhs_end_addr = rhs_base_addr + rhs_range.GetByteSize();
|
|
|
|
if (lhs_end_addr >= rhs_end_addr)
|
|
|
|
// The rhs range totally overlaps this one, nothing to add.
|
|
|
|
return false;
|
|
|
|
|
|
|
|
m_byte_size += rhs_end_addr - lhs_end_addr;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
void AddressRange::Clear() {
|
|
|
|
m_base_addr.Clear();
|
|
|
|
m_byte_size = 0;
|
|
|
|
}
|
|
|
|
|
2010-09-15 07:36:40 +08:00
|
|
|
bool AddressRange::Dump(Stream *s, Target *target, Address::DumpStyle style,
|
|
|
|
Address::DumpStyle fallback_style) const {
|
2010-06-09 00:52:24 +08:00
|
|
|
addr_t vmaddr = LLDB_INVALID_ADDRESS;
|
|
|
|
int addr_size = sizeof(addr_t);
|
2011-02-16 05:59:32 +08:00
|
|
|
if (target)
|
|
|
|
addr_size = target->GetArchitecture().GetAddressByteSize();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-09-10 09:30:46 +08:00
|
|
|
bool show_module = false;
|
2010-06-09 00:52:24 +08:00
|
|
|
switch (style) {
|
2010-07-10 04:39:50 +08:00
|
|
|
default:
|
|
|
|
break;
|
2010-06-09 00:52:24 +08:00
|
|
|
case Address::DumpStyleSectionNameOffset:
|
|
|
|
case Address::DumpStyleSectionPointerOffset:
|
|
|
|
s->PutChar('[');
|
2010-09-15 07:36:40 +08:00
|
|
|
m_base_addr.Dump(s, target, style, fallback_style);
|
2010-06-09 00:52:24 +08:00
|
|
|
s->PutChar('-');
|
2019-12-05 21:41:09 +08:00
|
|
|
DumpAddress(s->AsRawOstream(), m_base_addr.GetOffset() + GetByteSize(),
|
|
|
|
addr_size);
|
2010-06-09 00:52:24 +08:00
|
|
|
s->PutChar(')');
|
|
|
|
return true;
|
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-09-10 09:30:46 +08:00
|
|
|
case Address::DumpStyleModuleWithFileAddress:
|
|
|
|
show_module = true;
|
2016-02-16 12:14:33 +08:00
|
|
|
LLVM_FALLTHROUGH;
|
2010-06-09 00:52:24 +08:00
|
|
|
case Address::DumpStyleFileAddress:
|
|
|
|
vmaddr = m_base_addr.GetFileAddress();
|
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
case Address::DumpStyleLoadAddress:
|
2010-09-15 07:36:40 +08:00
|
|
|
vmaddr = m_base_addr.GetLoadAddress(target);
|
2010-06-09 00:52:24 +08:00
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (vmaddr != LLDB_INVALID_ADDRESS) {
|
2010-09-10 09:30:46 +08:00
|
|
|
if (show_module) {
|
2012-02-24 09:59:29 +08:00
|
|
|
ModuleSP module_sp(GetBaseAddress().GetModule());
|
|
|
|
if (module_sp)
|
2014-12-20 03:20:44 +08:00
|
|
|
s->Printf("%s", module_sp->GetFileSpec().GetFilename().AsCString(
|
|
|
|
"<Unknown>"));
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2019-12-05 21:41:09 +08:00
|
|
|
DumpAddressRange(s->AsRawOstream(), vmaddr, vmaddr + GetByteSize(),
|
|
|
|
addr_size);
|
2010-06-09 00:52:24 +08:00
|
|
|
return true;
|
2010-09-10 09:30:46 +08:00
|
|
|
} else if (fallback_style != Address::DumpStyleInvalid) {
|
2010-09-15 07:36:40 +08:00
|
|
|
return Dump(s, target, fallback_style, Address::DumpStyleInvalid);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddressRange::DumpDebug(Stream *s) const {
|
2014-04-04 12:06:10 +08:00
|
|
|
s->Printf("%p: AddressRange section = %p, offset = 0x%16.16" PRIx64
|
|
|
|
", byte_size = 0x%16.16" PRIx64 "\n",
|
|
|
|
static_cast<const void *>(this),
|
|
|
|
static_cast<void *>(m_base_addr.GetSection().get()),
|
|
|
|
m_base_addr.GetOffset(), GetByteSize());
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
//
|
|
|
|
// bool
|
|
|
|
// lldb::operator== (const AddressRange& lhs, const AddressRange& rhs)
|
|
|
|
//{
|
|
|
|
// if (lhs.GetBaseAddress() == rhs.GetBaseAddress())
|
|
|
|
// return lhs.GetByteSize() == rhs.GetByteSize();
|
|
|
|
// return false;
|
|
|
|
//}
|