[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
|
|
|
//===-- LanguageRuntime.cpp -----------------------------------------------===//
|
2010-09-23 10:01:19 +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-09-23 10:01:19 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/Target/LanguageRuntime.h"
|
|
|
|
#include "lldb/Core/PluginManager.h"
|
2014-12-06 09:28:03 +08:00
|
|
|
#include "lldb/Core/SearchFilter.h"
|
2015-05-05 02:39:38 +08:00
|
|
|
#include "lldb/Interpreter/CommandInterpreter.h"
|
2019-05-17 06:01:25 +08:00
|
|
|
#include "lldb/Target/Language.h"
|
2012-03-05 12:47:34 +08:00
|
|
|
#include "lldb/Target/Target.h"
|
2010-09-23 10:01:19 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2019-06-09 02:45:00 +08:00
|
|
|
char LanguageRuntime::ID = 0;
|
|
|
|
|
2016-09-13 07:10:56 +08:00
|
|
|
ExceptionSearchFilter::ExceptionSearchFilter(const lldb::TargetSP &target_sp,
|
|
|
|
lldb::LanguageType language,
|
|
|
|
bool update_module_list)
|
|
|
|
: SearchFilter(target_sp, FilterTy::Exception), m_language(language),
|
|
|
|
m_language_runtime(nullptr), m_filter_sp() {
|
|
|
|
if (update_module_list)
|
2013-03-12 02:42:51 +08:00
|
|
|
UpdateModuleListIfNeeded();
|
2016-09-13 07:10:56 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-09-13 07:10:56 +08:00
|
|
|
bool ExceptionSearchFilter::ModulePasses(const lldb::ModuleSP &module_sp) {
|
|
|
|
UpdateModuleListIfNeeded();
|
|
|
|
if (m_filter_sp)
|
|
|
|
return m_filter_sp->ModulePasses(module_sp);
|
|
|
|
return false;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-09-13 07:10:56 +08:00
|
|
|
bool ExceptionSearchFilter::ModulePasses(const FileSpec &spec) {
|
|
|
|
UpdateModuleListIfNeeded();
|
|
|
|
if (m_filter_sp)
|
|
|
|
return m_filter_sp->ModulePasses(spec);
|
|
|
|
return false;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-09-13 07:10:56 +08:00
|
|
|
void ExceptionSearchFilter::Search(Searcher &searcher) {
|
|
|
|
UpdateModuleListIfNeeded();
|
|
|
|
if (m_filter_sp)
|
|
|
|
m_filter_sp->Search(searcher);
|
|
|
|
}
|
2013-03-12 02:42:51 +08:00
|
|
|
|
2016-09-13 07:10:56 +08:00
|
|
|
void ExceptionSearchFilter::GetDescription(Stream *s) {
|
|
|
|
UpdateModuleListIfNeeded();
|
|
|
|
if (m_filter_sp)
|
|
|
|
m_filter_sp->GetDescription(s);
|
|
|
|
}
|
2014-12-06 09:28:03 +08:00
|
|
|
|
2016-09-13 07:10:56 +08:00
|
|
|
void ExceptionSearchFilter::UpdateModuleListIfNeeded() {
|
|
|
|
ProcessSP process_sp(m_target_sp->GetProcessSP());
|
|
|
|
if (process_sp) {
|
|
|
|
bool refreash_filter = !m_filter_sp;
|
|
|
|
if (m_language_runtime == nullptr) {
|
|
|
|
m_language_runtime = process_sp->GetLanguageRuntime(m_language);
|
|
|
|
refreash_filter = true;
|
|
|
|
} else {
|
|
|
|
LanguageRuntime *language_runtime =
|
|
|
|
process_sp->GetLanguageRuntime(m_language);
|
|
|
|
if (m_language_runtime != language_runtime) {
|
|
|
|
m_language_runtime = language_runtime;
|
2013-03-12 02:42:51 +08:00
|
|
|
refreash_filter = true;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2016-09-13 07:10:56 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-09-13 07:10:56 +08:00
|
|
|
if (refreash_filter && m_language_runtime) {
|
|
|
|
m_filter_sp = m_language_runtime->CreateExceptionSearchFilter();
|
2013-03-12 02:42:51 +08:00
|
|
|
}
|
2016-09-13 07:10:56 +08:00
|
|
|
} else {
|
|
|
|
m_filter_sp.reset();
|
|
|
|
m_language_runtime = nullptr;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2016-09-13 07:10:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SearchFilterSP
|
|
|
|
ExceptionSearchFilter::DoCopyForBreakpoint(Breakpoint &breakpoint) {
|
|
|
|
return SearchFilterSP(
|
|
|
|
new ExceptionSearchFilter(TargetSP(), m_language, false));
|
|
|
|
}
|
|
|
|
|
|
|
|
SearchFilter *ExceptionSearchFilter::CreateFromStructuredData(
|
2017-05-12 12:51:55 +08:00
|
|
|
Target &target, const StructuredData::Dictionary &data_dict,
|
|
|
|
Status &error) {
|
2016-09-13 07:10:56 +08:00
|
|
|
SearchFilter *result = nullptr;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
StructuredData::ObjectSP ExceptionSearchFilter::SerializeToStructuredData() {
|
|
|
|
StructuredData::ObjectSP result_sp;
|
|
|
|
|
|
|
|
return result_sp;
|
|
|
|
}
|
2013-03-12 02:42:51 +08:00
|
|
|
|
|
|
|
// The Target is the one that knows how to create breakpoints, so this function
|
|
|
|
// is meant to be used either by the target or internally in
|
|
|
|
// Set/ClearExceptionBreakpoints.
|
|
|
|
class ExceptionBreakpointResolver : public BreakpointResolver {
|
|
|
|
public:
|
|
|
|
ExceptionBreakpointResolver(lldb::LanguageType language, bool catch_bp,
|
|
|
|
bool throw_bp)
|
2016-02-18 08:10:17 +08:00
|
|
|
: BreakpointResolver(nullptr, BreakpointResolver::ExceptionResolver),
|
|
|
|
m_language(language), m_language_runtime(nullptr), m_catch_bp(catch_bp),
|
|
|
|
m_throw_bp(throw_bp) {}
|
2013-03-12 02:42:51 +08:00
|
|
|
|
2015-12-18 10:14:04 +08:00
|
|
|
~ExceptionBreakpointResolver() override = default;
|
2013-03-12 02:42:51 +08:00
|
|
|
|
|
|
|
Searcher::CallbackReturn SearchCallback(SearchFilter &filter,
|
2019-10-10 19:26:51 +08:00
|
|
|
SymbolContext &context,
|
|
|
|
Address *addr) override {
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-03-12 02:42:51 +08:00
|
|
|
if (SetActualResolver())
|
2019-10-10 19:26:51 +08:00
|
|
|
return m_actual_resolver_sp->SearchCallback(filter, context, addr);
|
2016-09-07 04:57:50 +08:00
|
|
|
else
|
2013-03-12 02:42:51 +08:00
|
|
|
return eCallbackReturnStop;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2018-09-08 02:43:04 +08:00
|
|
|
lldb::SearchDepth GetDepth() override {
|
2013-03-12 02:42:51 +08:00
|
|
|
if (SetActualResolver())
|
|
|
|
return m_actual_resolver_sp->GetDepth();
|
2016-09-07 04:57:50 +08:00
|
|
|
else
|
2018-09-08 02:43:04 +08:00
|
|
|
return lldb::eSearchDepthTarget;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2014-12-11 06:29:58 +08:00
|
|
|
void GetDescription(Stream *s) override {
|
2015-12-18 10:14:04 +08:00
|
|
|
Language *language_plugin = Language::FindPlugin(m_language);
|
2014-12-11 06:29:58 +08:00
|
|
|
if (language_plugin)
|
2015-12-18 10:14:04 +08:00
|
|
|
language_plugin->GetExceptionResolverDescription(m_catch_bp, m_throw_bp,
|
2016-09-07 04:57:50 +08:00
|
|
|
*s);
|
|
|
|
else
|
2015-12-18 10:14:04 +08:00
|
|
|
Language::GetDefaultExceptionResolverDescription(m_catch_bp, m_throw_bp,
|
2016-09-07 04:57:50 +08:00
|
|
|
*s);
|
|
|
|
|
2013-03-12 02:42:51 +08:00
|
|
|
SetActualResolver();
|
|
|
|
if (m_actual_resolver_sp) {
|
|
|
|
s->Printf(" using: ");
|
|
|
|
m_actual_resolver_sp->GetDescription(s);
|
2016-09-07 04:57:50 +08:00
|
|
|
} else
|
2013-03-12 02:42:51 +08:00
|
|
|
s->Printf(" the correct runtime exception handler will be determined "
|
|
|
|
"when you run");
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2014-12-11 06:29:58 +08:00
|
|
|
void Dump(Stream *s) const override {}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-03-12 02:42:51 +08:00
|
|
|
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const BreakpointResolverName *) { return true; }
|
|
|
|
static inline bool classof(const BreakpointResolver *V) {
|
|
|
|
return V->getResolverID() == BreakpointResolver::ExceptionResolver;
|
|
|
|
}
|
2015-10-24 02:39:37 +08:00
|
|
|
|
2013-03-12 02:42:51 +08:00
|
|
|
protected:
|
2014-12-06 09:28:03 +08:00
|
|
|
BreakpointResolverSP CopyForBreakpoint(Breakpoint &breakpoint) override {
|
2019-11-22 18:18:47 +08:00
|
|
|
BreakpointResolverSP ret_sp(
|
2014-12-06 09:28:03 +08:00
|
|
|
new ExceptionBreakpointResolver(m_language, m_catch_bp, m_throw_bp));
|
2019-11-22 18:18:47 +08:00
|
|
|
ret_sp->SetBreakpoint(&breakpoint);
|
|
|
|
return ret_sp;
|
2014-12-06 09:28:03 +08:00
|
|
|
}
|
|
|
|
|
2013-03-12 02:42:51 +08:00
|
|
|
bool SetActualResolver() {
|
|
|
|
ProcessSP process_sp;
|
|
|
|
if (m_breakpoint) {
|
|
|
|
process_sp = m_breakpoint->GetTarget().GetProcessSP();
|
|
|
|
if (process_sp) {
|
|
|
|
bool refreash_resolver = !m_actual_resolver_sp;
|
2016-02-18 08:10:17 +08:00
|
|
|
if (m_language_runtime == nullptr) {
|
2013-03-12 02:42:51 +08:00
|
|
|
m_language_runtime = process_sp->GetLanguageRuntime(m_language);
|
|
|
|
refreash_resolver = true;
|
|
|
|
} else {
|
|
|
|
LanguageRuntime *language_runtime =
|
|
|
|
process_sp->GetLanguageRuntime(m_language);
|
|
|
|
if (m_language_runtime != language_runtime) {
|
|
|
|
m_language_runtime = language_runtime;
|
|
|
|
refreash_resolver = true;
|
|
|
|
}
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-02-18 08:10:17 +08:00
|
|
|
if (refreash_resolver && m_language_runtime) {
|
|
|
|
m_actual_resolver_sp = m_language_runtime->CreateExceptionResolver(
|
|
|
|
m_breakpoint, m_catch_bp, m_throw_bp);
|
2013-03-12 02:42:51 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2013-03-12 02:42:51 +08:00
|
|
|
m_actual_resolver_sp.reset();
|
2016-02-18 08:10:17 +08:00
|
|
|
m_language_runtime = nullptr;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
} else {
|
2013-03-12 02:42:51 +08:00
|
|
|
m_actual_resolver_sp.reset();
|
2016-02-18 08:10:17 +08:00
|
|
|
m_language_runtime = nullptr;
|
2013-03-12 02:42:51 +08:00
|
|
|
}
|
|
|
|
return (bool)m_actual_resolver_sp;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2016-02-18 08:10:17 +08:00
|
|
|
|
2013-03-12 02:42:51 +08:00
|
|
|
lldb::BreakpointResolverSP m_actual_resolver_sp;
|
|
|
|
lldb::LanguageType m_language;
|
|
|
|
LanguageRuntime *m_language_runtime;
|
|
|
|
bool m_catch_bp;
|
|
|
|
bool m_throw_bp;
|
|
|
|
};
|
|
|
|
|
2010-09-23 10:01:19 +08:00
|
|
|
LanguageRuntime *LanguageRuntime::FindPlugin(Process *process,
|
|
|
|
lldb::LanguageType language) {
|
2019-02-13 14:25:41 +08:00
|
|
|
std::unique_ptr<LanguageRuntime> language_runtime_up;
|
2010-09-23 10:01:19 +08:00
|
|
|
LanguageRuntimeCreateInstance create_callback;
|
|
|
|
|
|
|
|
for (uint32_t idx = 0;
|
2016-02-18 08:10:17 +08:00
|
|
|
(create_callback =
|
|
|
|
PluginManager::GetLanguageRuntimeCreateCallbackAtIndex(idx)) !=
|
|
|
|
nullptr;
|
2010-09-23 10:01:19 +08:00
|
|
|
++idx) {
|
2019-02-13 14:25:41 +08:00
|
|
|
language_runtime_up.reset(create_callback(process, language));
|
2010-09-23 10:01:19 +08:00
|
|
|
|
2019-02-13 14:25:41 +08:00
|
|
|
if (language_runtime_up)
|
|
|
|
return language_runtime_up.release();
|
2010-09-23 10:01:19 +08:00
|
|
|
}
|
|
|
|
|
2016-02-18 08:10:17 +08:00
|
|
|
return nullptr;
|
2010-09-23 10:01:19 +08:00
|
|
|
}
|
|
|
|
|
2010-09-28 09:25:32 +08:00
|
|
|
LanguageRuntime::LanguageRuntime(Process *process) : m_process(process) {}
|
2010-09-23 10:01:19 +08:00
|
|
|
|
2015-10-24 02:39:37 +08:00
|
|
|
LanguageRuntime::~LanguageRuntime() = default;
|
2012-03-05 12:47:34 +08:00
|
|
|
|
2019-06-22 03:43:07 +08:00
|
|
|
BreakpointPreconditionSP
|
|
|
|
LanguageRuntime::GetExceptionPrecondition(LanguageType language,
|
|
|
|
bool throw_bp) {
|
|
|
|
LanguageRuntimeCreateInstance create_callback;
|
|
|
|
for (uint32_t idx = 0;
|
|
|
|
(create_callback =
|
|
|
|
PluginManager::GetLanguageRuntimeCreateCallbackAtIndex(idx)) !=
|
|
|
|
nullptr;
|
|
|
|
idx++) {
|
|
|
|
if (auto precondition_callback =
|
|
|
|
PluginManager::GetLanguageRuntimeGetExceptionPreconditionAtIndex(
|
|
|
|
idx)) {
|
|
|
|
if (BreakpointPreconditionSP precond =
|
|
|
|
precondition_callback(language, throw_bp))
|
|
|
|
return precond;
|
|
|
|
}
|
2015-04-23 03:42:18 +08:00
|
|
|
}
|
2019-06-22 03:43:07 +08:00
|
|
|
return BreakpointPreconditionSP();
|
2015-04-23 03:42:18 +08:00
|
|
|
}
|
|
|
|
|
2013-03-12 02:42:51 +08:00
|
|
|
BreakpointSP LanguageRuntime::CreateExceptionBreakpoint(
|
|
|
|
Target &target, lldb::LanguageType language, bool catch_bp, bool throw_bp,
|
|
|
|
bool is_internal) {
|
|
|
|
BreakpointResolverSP resolver_sp(
|
|
|
|
new ExceptionBreakpointResolver(language, catch_bp, throw_bp));
|
|
|
|
SearchFilterSP filter_sp(
|
|
|
|
new ExceptionSearchFilter(target.shared_from_this(), language));
|
2013-10-12 03:48:25 +08:00
|
|
|
bool hardware = false;
|
2014-01-11 07:46:59 +08:00
|
|
|
bool resolve_indirect_functions = false;
|
|
|
|
BreakpointSP exc_breakpt_sp(
|
|
|
|
target.CreateBreakpoint(filter_sp, resolver_sp, is_internal, hardware,
|
|
|
|
resolve_indirect_functions));
|
2015-04-23 03:42:18 +08:00
|
|
|
if (exc_breakpt_sp) {
|
2019-06-22 03:43:07 +08:00
|
|
|
if (auto precond = GetExceptionPrecondition(language, throw_bp))
|
|
|
|
exc_breakpt_sp->SetPrecondition(precond);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-04-23 03:42:18 +08:00
|
|
|
if (is_internal)
|
|
|
|
exc_breakpt_sp->SetBreakpointKind("exception");
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-03-05 12:47:34 +08:00
|
|
|
return exc_breakpt_sp;
|
|
|
|
}
|
|
|
|
|
2015-05-05 02:39:38 +08:00
|
|
|
void LanguageRuntime::InitializeCommands(CommandObject *parent) {
|
|
|
|
if (!parent)
|
|
|
|
return;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-05-05 02:39:38 +08:00
|
|
|
if (!parent->IsMultiwordObject())
|
|
|
|
return;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-05-05 02:39:38 +08:00
|
|
|
LanguageRuntimeCreateInstance create_callback;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-05-05 02:39:38 +08:00
|
|
|
for (uint32_t idx = 0;
|
|
|
|
(create_callback =
|
|
|
|
PluginManager::GetLanguageRuntimeCreateCallbackAtIndex(idx)) !=
|
|
|
|
nullptr;
|
|
|
|
++idx) {
|
|
|
|
if (LanguageRuntimeGetCommandObject command_callback =
|
|
|
|
PluginManager::GetLanguageRuntimeGetCommandObjectAtIndex(idx)) {
|
|
|
|
CommandObjectSP command =
|
|
|
|
command_callback(parent->GetCommandInterpreter());
|
|
|
|
if (command) {
|
2016-02-06 08:43:07 +08:00
|
|
|
// the CommandObject vended by a Language plugin cannot be created once
|
2016-10-06 05:14:38 +08:00
|
|
|
// and cached because we may create multiple debuggers and need one
|
|
|
|
// instance of the command each - the implementing function is meant to
|
|
|
|
// create a new instance of the command each time it is invoked.
|
|
|
|
parent->LoadSubCommand(command->GetCommandName().str().c_str(), command);
|
2015-05-05 02:39:38 +08:00
|
|
|
}
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2015-05-05 02:39:38 +08:00
|
|
|
}
|