Changeset View
Changeset View
Standalone View
Standalone View
source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
Show First 20 Lines • Show All 247 Lines • ▼ Show 20 Lines | if (!target_sp) { | ||||
lldb_assert(target_sp.get(), | lldb_assert(target_sp.get(), | ||||
"Can't make an expression parser with a null target.", | "Can't make an expression parser with a null target.", | ||||
__FUNCTION__, __FILE__, __LINE__); | __FUNCTION__, __FILE__, __LINE__); | ||||
return; | return; | ||||
} | } | ||||
// 1. Create a new compiler instance. | // 1. Create a new compiler instance. | ||||
m_compiler.reset(new CompilerInstance()); | m_compiler.reset(new CompilerInstance()); | ||||
lldb::LanguageType frame_lang = | m_language = expr.Language(); // defaults to lldb::eLanguageTypeUnknown | ||||
expr.Language(); // defaults to lldb::eLanguageTypeUnknown | |||||
bool overridden_target_opts = false; | bool overridden_target_opts = false; | ||||
lldb_private::LanguageRuntime *lang_rt = nullptr; | lldb_private::LanguageRuntime *lang_rt = nullptr; | ||||
std::string abi; | std::string abi; | ||||
ArchSpec target_arch; | ArchSpec target_arch; | ||||
target_arch = target_sp->GetArchitecture(); | target_arch = target_sp->GetArchitecture(); | ||||
const auto target_machine = target_arch.GetMachine(); | const auto target_machine = target_arch.GetMachine(); | ||||
// If the expression is being evaluated in the context of an existing | // If the expression is being evaluated in the context of an existing | ||||
// stack frame, we introspect to see if the language runtime is available. | // stack frame, we introspect to see if the language runtime is available. | ||||
lldb::StackFrameSP frame_sp = exe_scope->CalculateStackFrame(); | lldb::StackFrameSP frame_sp = exe_scope->CalculateStackFrame(); | ||||
lldb::ProcessSP process_sp = exe_scope->CalculateProcess(); | lldb::ProcessSP process_sp = exe_scope->CalculateProcess(); | ||||
// Make sure the user hasn't provided a preferred execution language | // Make sure the user hasn't provided a preferred execution language | ||||
// with `expression --language X -- ...` | // with `expression --language X -- ...` | ||||
if (frame_sp && frame_lang == lldb::eLanguageTypeUnknown) | if (frame_sp && m_language == lldb::eLanguageTypeUnknown) | ||||
frame_lang = frame_sp->GetLanguage(); | m_language = frame_sp->GetLanguage(); | ||||
if (process_sp && frame_lang != lldb::eLanguageTypeUnknown) { | if (process_sp && m_language != lldb::eLanguageTypeUnknown) { | ||||
lang_rt = process_sp->GetLanguageRuntime(frame_lang); | lang_rt = process_sp->GetLanguageRuntime(m_language); | ||||
if (log) | if (log) | ||||
log->Printf("Frame has language of type %s", | log->Printf("Frame has language of type %s", | ||||
Language::GetNameForLanguageType(frame_lang)); | Language::GetNameForLanguageType(m_language)); | ||||
} | } | ||||
// 2. Configure the compiler with a set of default options that are | // 2. Configure the compiler with a set of default options that are | ||||
// appropriate | // appropriate | ||||
// for most situations. | // for most situations. | ||||
if (target_arch.IsValid()) { | if (target_arch.IsValid()) { | ||||
std::string triple = target_arch.GetTriple().str(); | std::string triple = target_arch.GetTriple().str(); | ||||
m_compiler->getTargetOpts().Triple = triple; | m_compiler->getTargetOpts().Triple = triple; | ||||
▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | if (log) { | ||||
log->Printf("Target vector alignment: %d", | log->Printf("Target vector alignment: %d", | ||||
target_info->getMaxVectorAlign()); | target_info->getMaxVectorAlign()); | ||||
} | } | ||||
m_compiler->setTarget(target_info); | m_compiler->setTarget(target_info); | ||||
assert(m_compiler->hasTarget()); | assert(m_compiler->hasTarget()); | ||||
// 5. Set language options. | // 5. Set language options. | ||||
lldb::LanguageType language = expr.Language(); | switch (m_language) { | ||||
switch (language) { | |||||
case lldb::eLanguageTypeC: | case lldb::eLanguageTypeC: | ||||
case lldb::eLanguageTypeC89: | case lldb::eLanguageTypeC89: | ||||
case lldb::eLanguageTypeC99: | case lldb::eLanguageTypeC99: | ||||
case lldb::eLanguageTypeC11: | case lldb::eLanguageTypeC11: | ||||
// FIXME: the following language option is a temporary workaround, | // FIXME: the following language option is a temporary workaround, | ||||
// to "ask for C, get C++." | // to "ask for C, get C++." | ||||
// For now, the expression parser must use C++ anytime the | // For now, the expression parser must use C++ anytime the | ||||
// language is a C family language, because the expression parser | // language is a C family language, because the expression parser | ||||
▲ Show 20 Lines • Show All 413 Lines • ▼ Show 20 Lines | lldb_private::Error ClangExpressionParser::PrepareForExecution( | ||||
if (lldb::StackFrameSP frame_sp = exe_ctx.GetFrameSP()) { | if (lldb::StackFrameSP frame_sp = exe_ctx.GetFrameSP()) { | ||||
sc = frame_sp->GetSymbolContext(lldb::eSymbolContextEverything); | sc = frame_sp->GetSymbolContext(lldb::eSymbolContextEverything); | ||||
} else if (lldb::TargetSP target_sp = exe_ctx.GetTargetSP()) { | } else if (lldb::TargetSP target_sp = exe_ctx.GetTargetSP()) { | ||||
sc.target_sp = target_sp; | sc.target_sp = target_sp; | ||||
} | } | ||||
LLVMUserExpression::IRPasses custom_passes; | LLVMUserExpression::IRPasses custom_passes; | ||||
{ | { | ||||
auto lang = m_expr.Language(); | |||||
if (log) | if (log) | ||||
log->Printf("%s - Currrent expression language is %s\n", __FUNCTION__, | log->Printf("%s - Currrent expression language is %s\n", __FUNCTION__, | ||||
Language::GetNameForLanguageType(lang)); | Language::GetNameForLanguageType(m_language)); | ||||
lldb::ProcessSP process_sp = exe_ctx.GetProcessSP(); | lldb::ProcessSP process_sp = exe_ctx.GetProcessSP(); | ||||
if (process_sp && lang != lldb::eLanguageTypeUnknown) { | if (process_sp && m_language != lldb::eLanguageTypeUnknown) { | ||||
auto runtime = process_sp->GetLanguageRuntime(lang); | auto runtime = process_sp->GetLanguageRuntime(m_language); | ||||
if (runtime) | if (runtime) | ||||
runtime->GetIRPasses(custom_passes); | runtime->GetIRPasses(custom_passes); | ||||
} | } | ||||
} | } | ||||
if (custom_passes.EarlyPasses) { | if (custom_passes.EarlyPasses) { | ||||
if (log) | if (log) | ||||
log->Printf("%s - Running Early IR Passes from LanguageRuntime on " | log->Printf("%s - Running Early IR Passes from LanguageRuntime on " | ||||
▲ Show 20 Lines • Show All 166 Lines • Show Last 20 Lines |