2010-09-23 10:01:19 +08:00
|
|
|
//===-- LanguageRuntime.cpp -------------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/Target/LanguageRuntime.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"
|
|
|
|
|
|
|
|
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,
|
|
|
|
lldb::LanguageType language) :
|
|
|
|
SearchFilter (target_sp),
|
|
|
|
m_language (language),
|
|
|
|
m_language_runtime (NULL),
|
|
|
|
m_filter_sp ()
|
|
|
|
{
|
|
|
|
UpdateModuleListIfNeeded ();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool
|
|
|
|
ModulePasses (const lldb::ModuleSP &module_sp)
|
|
|
|
{
|
|
|
|
UpdateModuleListIfNeeded ();
|
|
|
|
if (m_filter_sp)
|
|
|
|
return m_filter_sp->ModulePasses (module_sp);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool
|
|
|
|
ModulePasses (const FileSpec &spec)
|
|
|
|
{
|
|
|
|
UpdateModuleListIfNeeded ();
|
|
|
|
if (m_filter_sp)
|
|
|
|
return m_filter_sp->ModulePasses (spec);
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void
|
|
|
|
Search (Searcher &searcher)
|
|
|
|
{
|
|
|
|
UpdateModuleListIfNeeded ();
|
|
|
|
if (m_filter_sp)
|
|
|
|
m_filter_sp->Search (searcher);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void
|
|
|
|
GetDescription (Stream *s)
|
|
|
|
{
|
|
|
|
UpdateModuleListIfNeeded ();
|
|
|
|
if (m_filter_sp)
|
|
|
|
m_filter_sp->GetDescription (s);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
LanguageType m_language;
|
|
|
|
LanguageRuntime *m_language_runtime;
|
|
|
|
SearchFilterSP m_filter_sp;
|
|
|
|
|
|
|
|
void
|
|
|
|
UpdateModuleListIfNeeded ()
|
|
|
|
{
|
|
|
|
ProcessSP process_sp (m_target_sp->GetProcessSP());
|
|
|
|
if (process_sp)
|
|
|
|
{
|
|
|
|
bool refreash_filter = !m_filter_sp;
|
|
|
|
if (m_language_runtime == NULL)
|
|
|
|
{
|
|
|
|
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();
|
|
|
|
m_language_runtime = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// 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) :
|
|
|
|
BreakpointResolver (NULL, BreakpointResolver::ExceptionResolver),
|
|
|
|
m_language (language),
|
|
|
|
m_language_runtime (NULL),
|
|
|
|
m_catch_bp (catch_bp),
|
|
|
|
m_throw_bp (throw_bp)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual
|
|
|
|
~ExceptionBreakpointResolver()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual Searcher::CallbackReturn
|
|
|
|
SearchCallback (SearchFilter &filter,
|
|
|
|
SymbolContext &context,
|
|
|
|
Address *addr,
|
|
|
|
bool containing)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (SetActualResolver())
|
|
|
|
return m_actual_resolver_sp->SearchCallback (filter, context, addr, containing);
|
|
|
|
else
|
|
|
|
return eCallbackReturnStop;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual Searcher::Depth
|
|
|
|
GetDepth ()
|
|
|
|
{
|
|
|
|
if (SetActualResolver())
|
|
|
|
return m_actual_resolver_sp->GetDepth();
|
|
|
|
else
|
|
|
|
return eDepthTarget;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void
|
|
|
|
GetDescription (Stream *s)
|
|
|
|
{
|
|
|
|
s->Printf ("Exception breakpoint (catch: %s throw: %s)",
|
|
|
|
m_catch_bp ? "on" : "off",
|
|
|
|
m_throw_bp ? "on" : "off");
|
|
|
|
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void
|
|
|
|
Dump (Stream *s) const
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/// 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;
|
|
|
|
}
|
|
|
|
protected:
|
|
|
|
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 == NULL)
|
|
|
|
{
|
|
|
|
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();
|
|
|
|
m_language_runtime = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_actual_resolver_sp.reset();
|
|
|
|
m_language_runtime = NULL;
|
|
|
|
}
|
|
|
|
return (bool)m_actual_resolver_sp;
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
(create_callback = PluginManager::GetLanguageRuntimeCreateCallbackAtIndex(idx)) != NULL;
|
|
|
|
++idx)
|
|
|
|
{
|
|
|
|
language_runtime_ap.reset (create_callback(process, language));
|
|
|
|
|
|
|
|
if (language_runtime_ap.get())
|
|
|
|
return language_runtime_ap.release();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Constructor
|
|
|
|
//----------------------------------------------------------------------
|
2010-09-28 09:25:32 +08:00
|
|
|
LanguageRuntime::LanguageRuntime(Process *process) :
|
|
|
|
m_process (process)
|
2010-09-23 10:01:19 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Destructor
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
LanguageRuntime::~LanguageRuntime()
|
|
|
|
{
|
|
|
|
}
|
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));
|
2013-01-26 10:19:28 +08:00
|
|
|
if (is_internal)
|
|
|
|
exc_breakpt_sp->SetBreakpointKind("exception");
|
2012-03-05 12:47:34 +08:00
|
|
|
|
|
|
|
return exc_breakpt_sp;
|
|
|
|
}
|
|
|
|
|
2012-10-23 08:50:09 +08:00
|
|
|
struct language_name_pair {
|
|
|
|
const char *name;
|
|
|
|
LanguageType type;
|
2012-03-06 08:37:27 +08:00
|
|
|
};
|
2012-10-23 08:50:09 +08:00
|
|
|
|
|
|
|
struct language_name_pair language_names[] =
|
|
|
|
{
|
|
|
|
// To allow GetNameForLanguageType to be a simple array lookup, the first
|
|
|
|
// part of this array must follow enum LanguageType exactly.
|
|
|
|
{ "unknown", eLanguageTypeUnknown },
|
|
|
|
{ "c89", eLanguageTypeC89 },
|
|
|
|
{ "c", eLanguageTypeC },
|
|
|
|
{ "ada83", eLanguageTypeAda83 },
|
|
|
|
{ "c++", eLanguageTypeC_plus_plus },
|
|
|
|
{ "cobol74", eLanguageTypeCobol74 },
|
|
|
|
{ "cobol85", eLanguageTypeCobol85 },
|
|
|
|
{ "fortran77", eLanguageTypeFortran77 },
|
|
|
|
{ "fortran90", eLanguageTypeFortran90 },
|
|
|
|
{ "pascal83", eLanguageTypePascal83 },
|
|
|
|
{ "modula2", eLanguageTypeModula2 },
|
|
|
|
{ "java", eLanguageTypeJava },
|
|
|
|
{ "c99", eLanguageTypeC99 },
|
|
|
|
{ "ada95", eLanguageTypeAda95 },
|
|
|
|
{ "fortran95", eLanguageTypeFortran95 },
|
|
|
|
{ "pli", eLanguageTypePLI },
|
|
|
|
{ "objective-c", eLanguageTypeObjC },
|
|
|
|
{ "objective-c++", eLanguageTypeObjC_plus_plus },
|
|
|
|
{ "upc", eLanguageTypeUPC },
|
|
|
|
{ "d", eLanguageTypeD },
|
|
|
|
{ "python", eLanguageTypePython },
|
2014-07-03 08:49:08 +08:00
|
|
|
{ "opencl", eLanguageTypeOpenCL },
|
|
|
|
{ "go", eLanguageTypeGo },
|
|
|
|
{ "modula3", eLanguageTypeModula3 },
|
|
|
|
{ "haskell", eLanguageTypeHaskell },
|
|
|
|
{ "c++03", eLanguageTypeC_plus_plus_03 },
|
|
|
|
{ "c++11", eLanguageTypeC_plus_plus_11 },
|
|
|
|
{ "ocaml", eLanguageTypeOCaml },
|
|
|
|
{ "rust", eLanguageTypeRust },
|
|
|
|
{ "c11", eLanguageTypeC11 },
|
2014-08-27 05:22:49 +08:00
|
|
|
{ "swift", eLanguageTypeSwift },
|
|
|
|
{ "julia", eLanguageTypeJulia },
|
|
|
|
{ "dylan", eLanguageTypeDylan },
|
2012-10-23 08:50:09 +08:00
|
|
|
// Now synonyms, in arbitrary order
|
|
|
|
{ "objc", eLanguageTypeObjC },
|
|
|
|
{ "objc++", eLanguageTypeObjC_plus_plus }
|
|
|
|
};
|
|
|
|
|
|
|
|
static uint32_t num_languages = sizeof(language_names) / sizeof (struct language_name_pair);
|
2012-03-06 08:37:27 +08:00
|
|
|
|
|
|
|
LanguageType
|
|
|
|
LanguageRuntime::GetLanguageTypeFromString (const char *string)
|
|
|
|
{
|
|
|
|
for (uint32_t i = 0; i < num_languages; i++)
|
|
|
|
{
|
2012-10-23 08:50:09 +08:00
|
|
|
if (strcasecmp (language_names[i].name, string) == 0)
|
|
|
|
return (LanguageType) language_names[i].type;
|
2012-03-06 08:37:27 +08:00
|
|
|
}
|
|
|
|
return eLanguageTypeUnknown;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
LanguageRuntime::GetNameForLanguageType (LanguageType language)
|
|
|
|
{
|
|
|
|
if (language < num_languages)
|
2012-10-23 08:50:09 +08:00
|
|
|
return language_names[language].name;
|
2012-03-06 08:37:27 +08:00
|
|
|
else
|
2012-10-23 08:50:09 +08:00
|
|
|
return language_names[eLanguageTypeUnknown].name;
|
2012-03-06 08:37:27 +08:00
|
|
|
}
|
2013-03-12 02:42:51 +08:00
|
|
|
|
|
|
|
lldb::SearchFilterSP
|
|
|
|
LanguageRuntime::CreateExceptionSearchFilter ()
|
|
|
|
{
|
|
|
|
return m_process->GetTarget().GetSearchFilterForModule(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|