Differential D17719 Diff 223584 lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
Changeset View
Changeset View
Standalone View
Standalone View
lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
Show First 20 Lines • Show All 151 Lines • ▼ Show 20 Lines | ClangExpressionParser::ClangExpressionParser (ExecutionContextScope *exe_scope, | ||||
m_compiler (), | m_compiler (), | ||||
m_code_generator (), | m_code_generator (), | ||||
m_pp_callbacks(nullptr) | m_pp_callbacks(nullptr) | ||||
{ | { | ||||
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); | ||||
// 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 = expr.Language(); // defaults to lldb::eLanguageTypeUnknown | m_language = 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; | ||||
lldb::TargetSP target_sp; | lldb::TargetSP target_sp; | ||||
if (exe_scope) | if (exe_scope) | ||||
target_sp = exe_scope->CalculateTarget(); | target_sp = exe_scope->CalculateTarget(); | ||||
ArchSpec target_arch; | ArchSpec target_arch; | ||||
if (target_sp) | if (target_sp) | ||||
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. | ||||
auto frame = exe_scope->CalculateStackFrame(); | auto frame = exe_scope->CalculateStackFrame(); | ||||
// 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 && frame_lang == lldb::eLanguageTypeUnknown) | if (frame && m_language == lldb::eLanguageTypeUnknown) | ||||
frame_lang = frame->GetLanguage(); | m_language = frame->GetLanguage(); | ||||
if (frame_lang != lldb::eLanguageTypeUnknown) | if (m_language != lldb::eLanguageTypeUnknown) | ||||
{ | { | ||||
lang_rt = exe_scope->CalculateProcess()->GetLanguageRuntime(frame_lang); | lang_rt = exe_scope->CalculateProcess()->GetLanguageRuntime(m_language); | ||||
if (log) | if (log) | ||||
log->Printf("Frame has language of type %s", Language::GetNameForLanguageType(frame_lang)); | log->Printf("Frame has language of type %s", Language::GetNameForLanguageType(m_language)); | ||||
} | } | ||||
// 2. Configure the compiler with a set of default options that are appropriate | // 2. Configure the compiler with a set of default options that are appropriate | ||||
// for most situations. | // for most situations. | ||||
if (target_sp && target_arch.IsValid()) | if (target_sp && 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 63 Lines • ▼ Show 20 Lines | if (log) | ||||
log->Printf("Target ABI: '%s'", target_info->getABI().str().c_str()); | log->Printf("Target ABI: '%s'", target_info->getABI().str().c_str()); | ||||
log->Printf("Target vector alignment: %d", target_info->getMaxVectorAlign()); | log->Printf("Target vector alignment: %d", 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 | ||||
▲ Show 20 Lines • Show All 427 Lines • Show Last 20 Lines |