2015-10-24 02:39:37 +08:00
|
|
|
//===-- LanguageRuntime.cpp -------------------------------------*- C++ -*-===//
|
2010-09-23 10:01:19 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2015-10-24 02:39:37 +08:00
|
|
|
// C Includes
|
|
|
|
// C++ Includes
|
|
|
|
// Other libraries and framework includes
|
|
|
|
// Project includes
|
2010-09-23 10:01:19 +08:00
|
|
|
#include "lldb/Target/LanguageRuntime.h"
|
2015-11-07 06:48:59 +08:00
|
|
|
#include "Plugins/Language/ObjC/ObjCLanguage.h"
|
2010-09-23 10:01:19 +08:00
|
|
|
#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"
|
2016-09-07 04:57:50 +08:00
|
|
|
#include "lldb/Target/ObjCLanguageRuntime.h"
|
|
|
|
#include "lldb/Target/Target.h"
|
2010-09-23 10:01:19 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
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)
|
2016-09-07 04:57:50 +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;
|
2016-09-07 04:57:50 +08:00
|
|
|
refreash_filter = true;
|
|
|
|
}
|
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
|
2016-09-07 04:57:50 +08:00
|
|
|
// is meant to be used either by the target or internally in
|
|
|
|
// Set/ClearExceptionBreakpoints.
|
|
|
|
class ExceptionBreakpointResolver : public BreakpointResolver {
|
2013-03-12 02:42:51 +08:00
|
|
|
public:
|
2016-09-07 04:57:50 +08:00
|
|
|
ExceptionBreakpointResolver(lldb::LanguageType language, bool catch_bp,
|
|
|
|
bool throw_bp)
|
|
|
|
: 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
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
~ExceptionBreakpointResolver() override = default;
|
2013-03-12 02:42:51 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
Searcher::CallbackReturn SearchCallback(SearchFilter &filter,
|
|
|
|
SymbolContext &context, Address *addr,
|
|
|
|
bool containing) override {
|
|
|
|
|
|
|
|
if (SetActualResolver())
|
|
|
|
return m_actual_resolver_sp->SearchCallback(filter, context, addr,
|
|
|
|
containing);
|
|
|
|
else
|
|
|
|
return eCallbackReturnStop;
|
|
|
|
}
|
|
|
|
|
|
|
|
Searcher::Depth GetDepth() override {
|
|
|
|
if (SetActualResolver())
|
|
|
|
return m_actual_resolver_sp->GetDepth();
|
|
|
|
else
|
|
|
|
return eDepthTarget;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GetDescription(Stream *s) override {
|
|
|
|
Language *language_plugin = Language::FindPlugin(m_language);
|
|
|
|
if (language_plugin)
|
|
|
|
language_plugin->GetExceptionResolverDescription(m_catch_bp, m_throw_bp,
|
|
|
|
*s);
|
|
|
|
else
|
|
|
|
Language::GetDefaultExceptionResolverDescription(m_catch_bp, m_throw_bp,
|
|
|
|
*s);
|
|
|
|
|
|
|
|
SetActualResolver();
|
|
|
|
if (m_actual_resolver_sp) {
|
|
|
|
s->Printf(" using: ");
|
|
|
|
m_actual_resolver_sp->GetDescription(s);
|
|
|
|
} else
|
|
|
|
s->Printf(" the correct runtime exception handler will be determined "
|
|
|
|
"when you run");
|
|
|
|
}
|
|
|
|
|
|
|
|
void Dump(Stream *s) const override {}
|
|
|
|
|
|
|
|
/// 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:
|
2016-09-07 04:57:50 +08:00
|
|
|
BreakpointResolverSP CopyForBreakpoint(Breakpoint &breakpoint) override {
|
|
|
|
return BreakpointResolverSP(
|
|
|
|
new ExceptionBreakpointResolver(m_language, m_catch_bp, m_throw_bp));
|
|
|
|
}
|
2014-12-06 09:28:03 +08:00
|
|
|
|
2016-09-07 04:57:50 +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;
|
|
|
|
if (m_language_runtime == nullptr) {
|
|
|
|
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;
|
|
|
|
}
|
2013-03-12 02:42:51 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +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 {
|
|
|
|
m_actual_resolver_sp.reset();
|
|
|
|
m_language_runtime = nullptr;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
m_actual_resolver_sp.reset();
|
|
|
|
m_language_runtime = nullptr;
|
2013-03-12 02:42:51 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
return (bool)m_actual_resolver_sp;
|
|
|
|
}
|
2016-02-18 08:10:17 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
lldb::BreakpointResolverSP m_actual_resolver_sp;
|
|
|
|
lldb::LanguageType m_language;
|
|
|
|
LanguageRuntime *m_language_runtime;
|
|
|
|
bool m_catch_bp;
|
|
|
|
bool m_throw_bp;
|
2013-03-12 02:42:51 +08:00
|
|
|
};
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
LanguageRuntime *LanguageRuntime::FindPlugin(Process *process,
|
|
|
|
lldb::LanguageType language) {
|
|
|
|
std::unique_ptr<LanguageRuntime> language_runtime_ap;
|
|
|
|
LanguageRuntimeCreateInstance create_callback;
|
2010-09-23 10:01:19 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
for (uint32_t idx = 0;
|
|
|
|
(create_callback =
|
|
|
|
PluginManager::GetLanguageRuntimeCreateCallbackAtIndex(idx)) !=
|
|
|
|
nullptr;
|
|
|
|
++idx) {
|
|
|
|
language_runtime_ap.reset(create_callback(process, language));
|
2010-09-23 10:01:19 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (language_runtime_ap)
|
|
|
|
return language_runtime_ap.release();
|
|
|
|
}
|
2010-09-23 10:01:19 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
return nullptr;
|
2010-09-23 10:01:19 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +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
|
|
|
|
2015-04-23 03:42:18 +08:00
|
|
|
Breakpoint::BreakpointPreconditionSP
|
2016-09-07 04:57:50 +08:00
|
|
|
LanguageRuntime::CreateExceptionPrecondition(lldb::LanguageType language,
|
|
|
|
bool catch_bp, bool throw_bp) {
|
|
|
|
switch (language) {
|
|
|
|
case eLanguageTypeObjC:
|
|
|
|
if (throw_bp)
|
|
|
|
return Breakpoint::BreakpointPreconditionSP(
|
|
|
|
new ObjCLanguageRuntime::ObjCExceptionPrecondition());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return Breakpoint::BreakpointPreconditionSP();
|
2015-04-23 03:42:18 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +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));
|
|
|
|
bool hardware = false;
|
|
|
|
bool resolve_indirect_functions = false;
|
|
|
|
BreakpointSP exc_breakpt_sp(
|
|
|
|
target.CreateBreakpoint(filter_sp, resolver_sp, is_internal, hardware,
|
|
|
|
resolve_indirect_functions));
|
|
|
|
if (exc_breakpt_sp) {
|
|
|
|
Breakpoint::BreakpointPreconditionSP precondition_sp =
|
|
|
|
CreateExceptionPrecondition(language, catch_bp, throw_bp);
|
|
|
|
if (precondition_sp)
|
|
|
|
exc_breakpt_sp->SetPrecondition(precondition_sp);
|
|
|
|
|
|
|
|
if (is_internal)
|
|
|
|
exc_breakpt_sp->SetBreakpointKind("exception");
|
|
|
|
}
|
|
|
|
|
|
|
|
return exc_breakpt_sp;
|
2012-03-05 12:47:34 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void LanguageRuntime::InitializeCommands(CommandObject *parent) {
|
|
|
|
if (!parent)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!parent->IsMultiwordObject())
|
|
|
|
return;
|
|
|
|
|
|
|
|
LanguageRuntimeCreateInstance create_callback;
|
|
|
|
|
|
|
|
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) {
|
|
|
|
// 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);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2015-05-05 02:39:38 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2015-05-05 02:39:38 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
lldb::SearchFilterSP LanguageRuntime::CreateExceptionSearchFilter() {
|
|
|
|
return m_process->GetTarget().GetSearchFilterForModule(nullptr);
|
2013-03-12 02:42:51 +08:00
|
|
|
}
|