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/CPlusPlus/CPlusPlusLanguage.h"
|
|
|
|
#include "Plugins/Language/ObjC/ObjCLanguage.h"
|
2015-04-23 03:42:18 +08:00
|
|
|
#include "lldb/Target/ObjCLanguageRuntime.h"
|
2012-03-05 12:47:34 +08:00
|
|
|
#include "lldb/Target/Target.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"
|
2010-09-23 10:01:19 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2013-03-12 02:42:51 +08:00
|
|
|
class ExceptionSearchFilter : public SearchFilter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ExceptionSearchFilter (const lldb::TargetSP &target_sp,
|
2014-12-06 09:28:03 +08:00
|
|
|
lldb::LanguageType language,
|
|
|
|
bool update_module_list = true) :
|
2016-02-18 08:10:17 +08:00
|
|
|
SearchFilter(target_sp),
|
|
|
|
m_language(language),
|
|
|
|
m_language_runtime(nullptr),
|
|
|
|
m_filter_sp()
|
2013-03-12 02:42:51 +08:00
|
|
|
{
|
2014-12-06 09:28:03 +08:00
|
|
|
if (update_module_list)
|
|
|
|
UpdateModuleListIfNeeded ();
|
2013-03-12 02:42:51 +08:00
|
|
|
}
|
2014-12-06 09:28:03 +08:00
|
|
|
|
2015-10-24 02:39:37 +08:00
|
|
|
~ExceptionSearchFilter() override = default;
|
2014-12-06 09:28:03 +08:00
|
|
|
|
2014-12-11 06:29:58 +08:00
|
|
|
bool
|
|
|
|
ModulePasses (const lldb::ModuleSP &module_sp) override
|
2013-03-12 02:42:51 +08:00
|
|
|
{
|
|
|
|
UpdateModuleListIfNeeded ();
|
|
|
|
if (m_filter_sp)
|
|
|
|
return m_filter_sp->ModulePasses (module_sp);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-12-11 06:29:58 +08:00
|
|
|
bool
|
|
|
|
ModulePasses (const FileSpec &spec) override
|
2013-03-12 02:42:51 +08:00
|
|
|
{
|
|
|
|
UpdateModuleListIfNeeded ();
|
|
|
|
if (m_filter_sp)
|
|
|
|
return m_filter_sp->ModulePasses (spec);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-12-11 06:29:58 +08:00
|
|
|
void
|
|
|
|
Search (Searcher &searcher) override
|
2013-03-12 02:42:51 +08:00
|
|
|
{
|
|
|
|
UpdateModuleListIfNeeded ();
|
|
|
|
if (m_filter_sp)
|
|
|
|
m_filter_sp->Search (searcher);
|
|
|
|
}
|
|
|
|
|
2014-12-11 06:29:58 +08:00
|
|
|
void
|
|
|
|
GetDescription (Stream *s) override
|
2013-03-12 02:42:51 +08:00
|
|
|
{
|
|
|
|
UpdateModuleListIfNeeded ();
|
|
|
|
if (m_filter_sp)
|
|
|
|
m_filter_sp->GetDescription (s);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
LanguageType m_language;
|
|
|
|
LanguageRuntime *m_language_runtime;
|
|
|
|
SearchFilterSP m_filter_sp;
|
|
|
|
|
2014-12-06 09:28:03 +08:00
|
|
|
SearchFilterSP
|
|
|
|
DoCopyForBreakpoint(Breakpoint &breakpoint) override
|
|
|
|
{
|
|
|
|
return SearchFilterSP(new ExceptionSearchFilter(TargetSP(), m_language, false));
|
|
|
|
}
|
|
|
|
|
2013-03-12 02:42:51 +08:00
|
|
|
void
|
|
|
|
UpdateModuleListIfNeeded ()
|
|
|
|
{
|
|
|
|
ProcessSP process_sp (m_target_sp->GetProcessSP());
|
|
|
|
if (process_sp)
|
|
|
|
{
|
|
|
|
bool refreash_filter = !m_filter_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_filter = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LanguageRuntime *language_runtime = process_sp->GetLanguageRuntime(m_language);
|
|
|
|
if (m_language_runtime != language_runtime)
|
|
|
|
{
|
|
|
|
m_language_runtime = language_runtime;
|
|
|
|
refreash_filter = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (refreash_filter && m_language_runtime)
|
|
|
|
{
|
|
|
|
m_filter_sp = m_language_runtime->CreateExceptionSearchFilter ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_filter_sp.reset();
|
2016-02-18 08:10:17 +08:00
|
|
|
m_language_runtime = nullptr;
|
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-10-24 02:39:37 +08:00
|
|
|
~ExceptionBreakpointResolver() override = default;
|
|
|
|
|
2014-12-11 06:29:58 +08:00
|
|
|
Searcher::CallbackReturn
|
2013-03-12 02:42:51 +08:00
|
|
|
SearchCallback (SearchFilter &filter,
|
|
|
|
SymbolContext &context,
|
|
|
|
Address *addr,
|
2014-12-11 06:29:58 +08:00
|
|
|
bool containing) override
|
2013-03-12 02:42:51 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
if (SetActualResolver())
|
|
|
|
return m_actual_resolver_sp->SearchCallback (filter, context, addr, containing);
|
|
|
|
else
|
|
|
|
return eCallbackReturnStop;
|
|
|
|
}
|
|
|
|
|
2014-12-11 06:29:58 +08:00
|
|
|
Searcher::Depth
|
|
|
|
GetDepth () override
|
2013-03-12 02:42:51 +08:00
|
|
|
{
|
|
|
|
if (SetActualResolver())
|
|
|
|
return m_actual_resolver_sp->GetDepth();
|
|
|
|
else
|
|
|
|
return eDepthTarget;
|
|
|
|
}
|
|
|
|
|
2014-12-11 06:29:58 +08:00
|
|
|
void
|
|
|
|
GetDescription (Stream *s) override
|
2013-03-12 02:42:51 +08:00
|
|
|
{
|
2015-12-18 10:14:04 +08:00
|
|
|
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);
|
|
|
|
|
2013-03-12 02:42:51 +08:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
2014-12-11 06:29:58 +08:00
|
|
|
void
|
|
|
|
Dump (Stream *s) const override
|
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
|
|
|
|
{
|
|
|
|
return BreakpointResolverSP(new ExceptionBreakpointResolver(m_language, m_catch_bp, m_throw_bp));
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (refreash_resolver && m_language_runtime)
|
|
|
|
{
|
|
|
|
m_actual_resolver_sp = m_language_runtime->CreateExceptionResolver (m_breakpoint, m_catch_bp, m_throw_bp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
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-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)
|
|
|
|
{
|
2013-04-19 06:45:39 +08:00
|
|
|
std::unique_ptr<LanguageRuntime> language_runtime_ap;
|
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)
|
|
|
|
{
|
|
|
|
language_runtime_ap.reset (create_callback(process, language));
|
|
|
|
|
2016-02-18 08:10:17 +08:00
|
|
|
if (language_runtime_ap)
|
2010-09-23 10:01:19 +08:00
|
|
|
return language_runtime_ap.release();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2015-04-23 03:42:18 +08:00
|
|
|
Breakpoint::BreakpointPreconditionSP
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2012-03-05 12:47:34 +08:00
|
|
|
BreakpointSP
|
2013-03-12 02:42:51 +08:00
|
|
|
LanguageRuntime::CreateExceptionBreakpoint (Target &target,
|
|
|
|
lldb::LanguageType language,
|
|
|
|
bool catch_bp,
|
|
|
|
bool throw_bp,
|
|
|
|
bool is_internal)
|
2012-03-05 12:47:34 +08:00
|
|
|
{
|
2013-03-12 02:42:51 +08:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
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");
|
|
|
|
}
|
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;
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2016-02-06 08:43:07 +08:00
|
|
|
// the CommandObject vended by a Language plugin cannot be created once 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
|
2015-05-05 02:39:38 +08:00
|
|
|
parent->LoadSubCommand(command->GetCommandName(), command);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-12 02:42:51 +08:00
|
|
|
lldb::SearchFilterSP
|
|
|
|
LanguageRuntime::CreateExceptionSearchFilter ()
|
|
|
|
{
|
2016-02-18 08:10:17 +08:00
|
|
|
return m_process->GetTarget().GetSearchFilterForModule(nullptr);
|
2013-03-12 02:42:51 +08:00
|
|
|
}
|