[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
|
|
|
//===-- BreakpointResolverAddress.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/BreakpointResolverAddress.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include "lldb/Breakpoint/BreakpointLocation.h"
|
2015-11-17 11:39:13 +08:00
|
|
|
#include "lldb/Core/Module.h"
|
2016-09-13 07:10:56 +08:00
|
|
|
#include "lldb/Core/Section.h"
|
2015-03-05 01:43:00 +08:00
|
|
|
#include "lldb/Target/Process.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Target/Target.h"
|
2017-03-04 04:56:28 +08:00
|
|
|
#include "lldb/Utility/Log.h"
|
2017-02-03 05:39:50 +08:00
|
|
|
#include "lldb/Utility/StreamString.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
// BreakpointResolverAddress:
|
2015-11-17 11:39:13 +08:00
|
|
|
BreakpointResolverAddress::BreakpointResolverAddress(
|
2020-03-03 18:29:12 +08:00
|
|
|
const BreakpointSP &bkpt, const Address &addr, const FileSpec &module_spec)
|
2010-10-29 01:27:46 +08:00
|
|
|
: BreakpointResolver(bkpt, BreakpointResolver::AddressResolver),
|
2015-11-17 11:39:13 +08:00
|
|
|
m_addr(addr), m_resolved_addr(LLDB_INVALID_ADDRESS),
|
|
|
|
m_module_filespec(module_spec) {}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2020-03-03 18:29:12 +08:00
|
|
|
BreakpointResolverAddress::BreakpointResolverAddress(const BreakpointSP &bkpt,
|
2015-11-17 11:39:13 +08:00
|
|
|
const Address &addr)
|
|
|
|
: BreakpointResolver(bkpt, BreakpointResolver::AddressResolver),
|
|
|
|
m_addr(addr), m_resolved_addr(LLDB_INVALID_ADDRESS), m_module_filespec() {
|
|
|
|
}
|
|
|
|
|
2016-09-13 07:10:56 +08:00
|
|
|
BreakpointResolver *BreakpointResolverAddress::CreateFromStructuredData(
|
2020-03-03 18:29:12 +08:00
|
|
|
const BreakpointSP &bkpt, const StructuredData::Dictionary &options_dict,
|
2017-05-12 12:51:55 +08:00
|
|
|
Status &error) {
|
2017-05-12 13:49:54 +08:00
|
|
|
llvm::StringRef module_name;
|
2016-09-13 07:10:56 +08:00
|
|
|
lldb::addr_t addr_offset;
|
|
|
|
FileSpec module_filespec;
|
|
|
|
bool success;
|
|
|
|
|
|
|
|
success = options_dict.GetValueForKeyAsInteger(
|
|
|
|
GetKey(OptionNames::AddressOffset), addr_offset);
|
|
|
|
if (!success) {
|
|
|
|
error.SetErrorString("BRFL::CFSD: Couldn't find address offset entry.");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
Address address(addr_offset);
|
|
|
|
|
|
|
|
success = options_dict.HasKey(GetKey(OptionNames::ModuleName));
|
|
|
|
if (success) {
|
|
|
|
success = options_dict.GetValueForKeyAsString(
|
|
|
|
GetKey(OptionNames::ModuleName), module_name);
|
|
|
|
if (!success) {
|
|
|
|
error.SetErrorString("BRA::CFSD: Couldn't read module name entry.");
|
|
|
|
return nullptr;
|
|
|
|
}
|
2018-11-02 05:05:36 +08:00
|
|
|
module_filespec.SetFile(module_name, FileSpec::Style::native);
|
2016-09-13 07:10:56 +08:00
|
|
|
}
|
|
|
|
return new BreakpointResolverAddress(bkpt, address, module_filespec);
|
|
|
|
}
|
|
|
|
|
|
|
|
StructuredData::ObjectSP
|
|
|
|
BreakpointResolverAddress::SerializeToStructuredData() {
|
|
|
|
StructuredData::DictionarySP options_dict_sp(
|
|
|
|
new StructuredData::Dictionary());
|
|
|
|
SectionSP section_sp = m_addr.GetSection();
|
|
|
|
if (section_sp) {
|
|
|
|
ModuleSP module_sp = section_sp->GetModule();
|
|
|
|
ConstString module_name;
|
|
|
|
if (module_sp)
|
|
|
|
module_name.SetCString(module_name.GetCString());
|
|
|
|
|
|
|
|
options_dict_sp->AddStringItem(GetKey(OptionNames::ModuleName),
|
|
|
|
module_name.GetCString());
|
|
|
|
options_dict_sp->AddIntegerItem(GetKey(OptionNames::AddressOffset),
|
|
|
|
m_addr.GetOffset());
|
|
|
|
} else {
|
|
|
|
options_dict_sp->AddIntegerItem(GetKey(OptionNames::AddressOffset),
|
|
|
|
m_addr.GetOffset());
|
|
|
|
if (m_module_filespec) {
|
|
|
|
options_dict_sp->AddStringItem(GetKey(OptionNames::ModuleName),
|
|
|
|
m_module_filespec.GetPath());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return WrapOptionsDict(options_dict_sp);
|
|
|
|
}
|
|
|
|
|
2010-10-29 01:27:46 +08:00
|
|
|
void BreakpointResolverAddress::ResolveBreakpoint(SearchFilter &filter) {
|
2018-05-01 00:49:04 +08:00
|
|
|
// If the address is not section relative, then we should not try to re-
|
|
|
|
// resolve it, it is just some random address and we wouldn't know what to do
|
|
|
|
// on reload. But if it is section relative, we need to re-resolve it since
|
|
|
|
// the section it's in may have shifted on re-run.
|
2015-11-17 11:39:13 +08:00
|
|
|
bool re_resolve = false;
|
|
|
|
if (m_addr.GetSection() || m_module_filespec)
|
|
|
|
re_resolve = true;
|
2020-03-03 18:29:12 +08:00
|
|
|
else if (GetBreakpoint()->GetNumLocations() == 0)
|
2015-11-17 11:39:13 +08:00
|
|
|
re_resolve = true;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-11-17 11:39:13 +08:00
|
|
|
if (re_resolve)
|
2010-06-09 00:52:24 +08:00
|
|
|
BreakpointResolver::ResolveBreakpoint(filter);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BreakpointResolverAddress::ResolveBreakpointInModules(
|
|
|
|
SearchFilter &filter, ModuleList &modules) {
|
2015-11-17 11:39:13 +08:00
|
|
|
// See comment in ResolveBreakpoint.
|
|
|
|
bool re_resolve = false;
|
|
|
|
if (m_addr.GetSection())
|
|
|
|
re_resolve = true;
|
2020-03-03 18:29:12 +08:00
|
|
|
else if (GetBreakpoint()->GetNumLocations() == 0)
|
2015-11-17 11:39:13 +08:00
|
|
|
re_resolve = true;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-11-17 11:39:13 +08:00
|
|
|
if (re_resolve)
|
2010-06-09 00:52:24 +08:00
|
|
|
BreakpointResolver::ResolveBreakpointInModules(filter, modules);
|
|
|
|
}
|
|
|
|
|
2019-10-10 19:26:51 +08:00
|
|
|
Searcher::CallbackReturn BreakpointResolverAddress::SearchCallback(
|
|
|
|
SearchFilter &filter, SymbolContext &context, Address *addr) {
|
2020-03-03 18:29:12 +08:00
|
|
|
BreakpointSP breakpoint_sp = GetBreakpoint();
|
|
|
|
Breakpoint &breakpoint = *breakpoint_sp;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (filter.AddressPasses(m_addr)) {
|
2020-03-03 18:29:12 +08:00
|
|
|
if (breakpoint.GetNumLocations() == 0) {
|
2015-11-17 11:39:13 +08:00
|
|
|
// If the address is just an offset, and we're given a module, see if we
|
2018-05-01 00:49:04 +08:00
|
|
|
// can find the appropriate module loaded in the binary, and fix up
|
|
|
|
// m_addr to use that.
|
2015-11-17 11:39:13 +08:00
|
|
|
if (!m_addr.IsSectionOffset() && m_module_filespec) {
|
2020-03-03 18:29:12 +08:00
|
|
|
Target &target = breakpoint.GetTarget();
|
2015-11-17 11:39:13 +08:00
|
|
|
ModuleSpec module_spec(m_module_filespec);
|
|
|
|
ModuleSP module_sp = target.GetImages().FindFirstModule(module_spec);
|
|
|
|
if (module_sp) {
|
|
|
|
Address tmp_address;
|
|
|
|
if (module_sp->ResolveFileAddress(m_addr.GetOffset(), tmp_address))
|
|
|
|
m_addr = tmp_address;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2020-03-03 18:29:12 +08:00
|
|
|
m_resolved_addr = m_addr.GetLoadAddress(&breakpoint.GetTarget());
|
2016-03-10 02:59:13 +08:00
|
|
|
BreakpointLocationSP bp_loc_sp(AddLocation(m_addr));
|
2020-03-03 18:29:12 +08:00
|
|
|
if (bp_loc_sp && !breakpoint.IsInternal()) {
|
2015-11-17 11:39:13 +08:00
|
|
|
StreamString s;
|
|
|
|
bp_loc_sp->GetDescription(&s, lldb::eDescriptionLevelVerbose);
|
2016-09-07 04:57:50 +08:00
|
|
|
Log *log(
|
2015-11-17 11:39:13 +08:00
|
|
|
lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_BREAKPOINTS));
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log, "Added location: %s\n", s.GetData());
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
} else {
|
2020-03-03 18:29:12 +08:00
|
|
|
BreakpointLocationSP loc_sp = breakpoint.GetLocationAtIndex(0);
|
2015-11-17 11:39:13 +08:00
|
|
|
lldb::addr_t cur_load_location =
|
2020-03-03 18:29:12 +08:00
|
|
|
m_addr.GetLoadAddress(&breakpoint.GetTarget());
|
2015-11-17 11:39:13 +08:00
|
|
|
if (cur_load_location != m_resolved_addr) {
|
|
|
|
m_resolved_addr = cur_load_location;
|
|
|
|
loc_sp->ClearBreakpointSite();
|
|
|
|
loc_sp->ResolveBreakpointSite();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
return Searcher::eCallbackReturnStop;
|
|
|
|
}
|
|
|
|
|
2018-09-08 02:43:04 +08:00
|
|
|
lldb::SearchDepth BreakpointResolverAddress::GetDepth() {
|
|
|
|
return lldb::eSearchDepthTarget;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void BreakpointResolverAddress::GetDescription(Stream *s) {
|
2010-06-29 05:30:43 +08:00
|
|
|
s->PutCString("address = ");
|
2020-03-03 18:29:12 +08:00
|
|
|
m_addr.Dump(s, GetBreakpoint()->GetTarget().GetProcessSP().get(),
|
2015-11-17 11:39:13 +08:00
|
|
|
Address::DumpStyleModuleWithFileAddress,
|
|
|
|
Address::DumpStyleLoadAddress);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void BreakpointResolverAddress::Dump(Stream *s) const {}
|
2014-12-06 09:28:03 +08:00
|
|
|
|
|
|
|
lldb::BreakpointResolverSP
|
2020-03-03 18:29:12 +08:00
|
|
|
BreakpointResolverAddress::CopyForBreakpoint(BreakpointSP &breakpoint) {
|
2014-12-06 09:28:03 +08:00
|
|
|
lldb::BreakpointResolverSP ret_sp(
|
2020-03-03 18:29:12 +08:00
|
|
|
new BreakpointResolverAddress(breakpoint, m_addr));
|
2014-12-06 09:28:03 +08:00
|
|
|
return ret_sp;
|
|
|
|
}
|