Index: include/lldb/Target/StackFrame.h =================================================================== --- include/lldb/Target/StackFrame.h +++ include/lldb/Target/StackFrame.h @@ -466,6 +466,16 @@ TrackGlobalVariable (const lldb::VariableSP &variable_sp, lldb::DynamicValueType use_dynamic); //------------------------------------------------------------------ + /// Query this frame to determine what the default language should be + /// when parsing expressions given the execution context. + /// + /// @return + /// The language of the frame if known, else lldb::eLanguageTypeUnknown. + //------------------------------------------------------------------ + lldb::LanguageType + GetDefaultExpressionLanguage (); + + //------------------------------------------------------------------ // lldb::ExecutionContextScope pure virtual functions //------------------------------------------------------------------ virtual lldb::TargetSP Index: source/Commands/CommandObjectExpression.cpp =================================================================== --- source/Commands/CommandObjectExpression.cpp +++ source/Commands/CommandObjectExpression.cpp @@ -289,8 +289,8 @@ if (target) { lldb::ValueObjectSP result_valobj_sp; - bool keep_in_memory = true; + StackFrame *frame = exe_ctx.GetFramePtr(); EvaluateExpressionOptions options; options.SetCoerceToId(m_varobj_options.use_objc); @@ -301,11 +301,15 @@ options.SetTryAllThreads(m_command_options.try_all_threads); options.SetDebug(m_command_options.debug); - // If the language was not specified, set it from target's properties + // If the language was not specified in the expression command, + // set it to the language in the target's properties if + // specified, else default to the langage for the frame. if (m_command_options.language != eLanguageTypeUnknown) options.SetLanguage(m_command_options.language); - else + else if (target->GetLanguage() != eLanguageTypeUnknown) options.SetLanguage(target->GetLanguage()); + else if (frame) + options.SetLanguage(frame->GetDefaultExpressionLanguage()); // If there is any chance we are going to stop and want to see // what went wrong with our expression, we should generate debug info @@ -318,8 +322,7 @@ else options.SetTimeoutUsec(0); - target->EvaluateExpression(expr, exe_ctx.GetFramePtr(), - result_valobj_sp, options); + target->EvaluateExpression(expr, frame, result_valobj_sp, options); if (result_valobj_sp) { Index: source/Expression/ClangExpressionParser.cpp =================================================================== --- source/Expression/ClangExpressionParser.cpp +++ source/Expression/ClangExpressionParser.cpp @@ -214,11 +214,29 @@ case lldb::eLanguageTypeObjC: m_compiler->getLangOpts().ObjC1 = true; m_compiler->getLangOpts().ObjC2 = true; + // FIXME: the following 2 language options are a temporary workaround, + // to "ask for ObjC, get ObjC++." + // + // In http://reviews.llvm.org/D11482 Jim writes "Sean doesn't have a DESIRE to + // have the expression parser use ObjC++ anytime the language is a C family + // language. Rather he MUST right now, because the expression parser uses + // features of C++ to capture values. We could switch to using C++ in C/C++ + // situations, and ObjC++ in others, but there wasn't sufficient motivation to + // add that. Sometime when we get some spare cycles we'll try to relax the need + // for C++, and then we'll truly be able to follow the frame language. For now, + // we do "Want C -> get ObjC++", "Want ObjC -> get ObjC++" etc... But again, + // that is not a fundamental choice, it is an implementation necessity. + m_compiler->getLangOpts().CPlusPlus = true; + m_compiler->getLangOpts().CPlusPlus11 = true; break; case lldb::eLanguageTypeC_plus_plus: m_compiler->getLangOpts().CPlusPlus = true; m_compiler->getLangOpts().CPlusPlus11 = true; m_compiler->getHeaderSearchOpts().UseLibcxx = true; + // FIXME: the following 2 language options are a temporary workaround, + // to "ask for C++, for now get ObjC++" (see comment above). + m_compiler->getLangOpts().ObjC1 = true; + m_compiler->getLangOpts().ObjC2 = true; break; case lldb::eLanguageTypeObjC_plus_plus: default: Index: source/Target/StackFrame.cpp =================================================================== --- source/Target/StackFrame.cpp +++ source/Target/StackFrame.cpp @@ -1316,6 +1316,15 @@ return false; } +lldb::LanguageType +StackFrame::GetDefaultExpressionLanguage () +{ + CompileUnit *cu = GetSymbolContext(eSymbolContextCompUnit).comp_unit; + if (cu) + return cu->GetLanguage(); + return lldb::eLanguageTypeUnknown; +} + TargetSP StackFrame::CalculateTarget () {