[Lldb-commits] [lldb] r144042 - in /lldb/trunk: include/lldb/Expression/ClangExpression.h include/lldb/Expression/ClangUserExpression.h source/Breakpoint/BreakpointOptions.cpp source/Breakpoint/Watchpoint.cpp source/Expression/ClangExpressionParser.cpp source/Expression/ClangUserExpression.cpp source/Target/Process.cpp source/Target/StopInfo.cpp source/Target/Target.cpp

Sean Callanan scallanan at apple.com
Mon Nov 7 15:35:40 PST 2011


Author: spyffe
Date: Mon Nov  7 17:35:40 2011
New Revision: 144042

URL: http://llvm.org/viewvc/llvm-project?rev=144042&view=rev
Log:
Added a language parameter to the expression parser,
which will in the future allow expressions to be
compiled as C, C++, and Objective-C instead of the
current default Objective-C++.  This feature requires
some additional support from Clang -- specifically, it
requires reference types in the parser regardless of
language -- so it is not yet exposed to the user.

Modified:
    lldb/trunk/include/lldb/Expression/ClangExpression.h
    lldb/trunk/include/lldb/Expression/ClangUserExpression.h
    lldb/trunk/source/Breakpoint/BreakpointOptions.cpp
    lldb/trunk/source/Breakpoint/Watchpoint.cpp
    lldb/trunk/source/Expression/ClangExpressionParser.cpp
    lldb/trunk/source/Expression/ClangUserExpression.cpp
    lldb/trunk/source/Target/Process.cpp
    lldb/trunk/source/Target/StopInfo.cpp
    lldb/trunk/source/Target/Target.cpp

Modified: lldb/trunk/include/lldb/Expression/ClangExpression.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangExpression.h?rev=144042&r1=144041&r2=144042&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/ClangExpression.h (original)
+++ lldb/trunk/include/lldb/Expression/ClangExpression.h Mon Nov  7 17:35:40 2011
@@ -73,6 +73,16 @@
     FunctionName () = 0;
     
     //------------------------------------------------------------------
+    /// Return the language that should be used when parsing.  To use
+    /// the default, return eLanguageTypeUnknown.
+    //------------------------------------------------------------------
+    virtual lldb::LanguageType
+    Language ()
+    {
+        return lldb::eLanguageTypeUnknown;
+    }
+    
+    //------------------------------------------------------------------
     /// Return the object that the parser should use when resolving external
     /// values.  May be NULL if everything should be self-contained.
     //------------------------------------------------------------------

Modified: lldb/trunk/include/lldb/Expression/ClangUserExpression.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangUserExpression.h?rev=144042&r1=144041&r2=144042&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/ClangUserExpression.h (original)
+++ lldb/trunk/include/lldb/Expression/ClangUserExpression.h Mon Nov  7 17:35:40 2011
@@ -58,9 +58,15 @@
     /// @param[in] expr_prefix
     ///     If non-NULL, a C string containing translation-unit level
     ///     definitions to be included when the expression is parsed.
+    ///
+    /// @param[in] language
+    ///     If not eLanguageTypeUnknown, a language to use when parsing
+    ///     the expression.  Currently restricted to those languages 
+    ///     supported by Clang.
     //------------------------------------------------------------------
     ClangUserExpression (const char *expr,
-                         const char *expr_prefix);
+                         const char *expr_prefix,
+                         lldb::LanguageType language);
     
     //------------------------------------------------------------------
     /// Destructor
@@ -200,6 +206,16 @@
     }
     
     //------------------------------------------------------------------
+    /// Return the language that should be used when parsing.  To use
+    /// the default, return eLanguageTypeUnknown.
+    //------------------------------------------------------------------
+    virtual lldb::LanguageType
+    Language ()
+    {
+        return m_language;
+    }
+    
+    //------------------------------------------------------------------
     /// Return the object that the parser should use when resolving external
     /// values.  May be NULL if everything should be self-contained.
     //------------------------------------------------------------------
@@ -260,6 +276,11 @@
     ///     Determines whether or not to try using the IR interpreter to
     ///     avoid running the expression on the parser.
     ///
+    /// @param[in] language
+    ///     If not eLanguageTypeUnknown, a language to use when parsing
+    ///     the expression.  Currently restricted to those languages 
+    ///     supported by Clang.
+    ///
     /// @param[in] discard_on_error
     ///     True if the thread's state should be restored in the case 
     ///     of an error.
@@ -280,6 +301,7 @@
     static ExecutionResults
     Evaluate (ExecutionContext &exe_ctx,
               lldb_private::ExecutionPolicy execution_policy,
+              lldb::LanguageType language,
               bool discard_on_error,
               const char *expr_cstr,
               const char *expr_prefix,
@@ -288,6 +310,7 @@
     static ExecutionResults
     EvaluateWithError (ExecutionContext &exe_ctx,
                        lldb_private::ExecutionPolicy execution_policy,
+                       lldb::LanguageType language,
                        bool discard_on_error,
                        const char *expr_cstr,
                        const char *expr_prefix,
@@ -319,6 +342,9 @@
     
     std::string                                 m_expr_text;            ///< The text of the expression, as typed by the user
     std::string                                 m_expr_prefix;          ///< The text of the translation-level definitions, as provided by the user
+    lldb::LanguageType                          m_language;             ///< The language to use when parsing (eLanguageTypeUnknown means use defaults)
+    bool                                        m_allow_cxx;            ///< True if the language allows C++.
+    bool                                        m_allow_objc;           ///< True if the language allows Objective-C.
     std::string                                 m_transformed_text;     ///< The text of the expression, as send to the parser
     TypeFromUser                                m_desired_type;         ///< The type to coerce the expression's result to.  If NULL, inferred from the expression.
     

Modified: lldb/trunk/source/Breakpoint/BreakpointOptions.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/BreakpointOptions.cpp?rev=144042&r1=144041&r2=144042&view=diff
==============================================================================
--- lldb/trunk/source/Breakpoint/BreakpointOptions.cpp (original)
+++ lldb/trunk/source/Breakpoint/BreakpointOptions.cpp Mon Nov  7 17:35:40 2011
@@ -60,7 +60,7 @@
     if (rhs.m_thread_spec_ap.get() != NULL)
         m_thread_spec_ap.reset (new ThreadSpec(*rhs.m_thread_spec_ap.get()));
     if (rhs.m_condition_ap.get())
-        m_condition_ap.reset (new ClangUserExpression (rhs.m_condition_ap->GetUserText(), NULL));
+        m_condition_ap.reset (new ClangUserExpression (rhs.m_condition_ap->GetUserText(), NULL, lldb::eLanguageTypeUnknown));
 }
 
 //----------------------------------------------------------------------
@@ -77,7 +77,7 @@
     if (rhs.m_thread_spec_ap.get() != NULL)
         m_thread_spec_ap.reset(new ThreadSpec(*rhs.m_thread_spec_ap.get()));
     if (rhs.m_condition_ap.get())
-        m_condition_ap.reset (new ClangUserExpression (rhs.m_condition_ap->GetUserText(), NULL));
+        m_condition_ap.reset (new ClangUserExpression (rhs.m_condition_ap->GetUserText(), NULL, lldb::eLanguageTypeUnknown));
     return *this;
 }
 
@@ -166,7 +166,7 @@
     }
     else
     {
-        m_condition_ap.reset(new ClangUserExpression (condition, NULL));
+        m_condition_ap.reset(new ClangUserExpression (condition, NULL, lldb::eLanguageTypeUnknown));
     }
 }
 

Modified: lldb/trunk/source/Breakpoint/Watchpoint.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/Watchpoint.cpp?rev=144042&r1=144041&r2=144042&view=diff
==============================================================================
--- lldb/trunk/source/Breakpoint/Watchpoint.cpp (original)
+++ lldb/trunk/source/Breakpoint/Watchpoint.cpp Mon Nov  7 17:35:40 2011
@@ -212,7 +212,7 @@
     else
     {
         // Pass NULL for expr_prefix (no translation-unit level definitions).
-        m_condition_ap.reset(new ClangUserExpression (condition, NULL));
+        m_condition_ap.reset(new ClangUserExpression (condition, NULL, lldb::eLanguageTypeUnknown));
     }
 }
 

Modified: lldb/trunk/source/Expression/ClangExpressionParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpressionParser.cpp?rev=144042&r1=144041&r2=144042&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangExpressionParser.cpp (original)
+++ lldb/trunk/source/Expression/ClangExpressionParser.cpp Mon Nov  7 17:35:40 2011
@@ -204,19 +204,32 @@
     
     // 2. Set options.
     
-    // Parse expressions as Objective C++ regardless of context.
-    // Our hook into Clang's lookup mechanism only works in C++.
-    m_compiler->getLangOpts().CPlusPlus = true;
-    
-    // Setup objective C
-    m_compiler->getLangOpts().ObjC1 = true;
-    m_compiler->getLangOpts().ObjC2 = true;
+    lldb::LanguageType language = expr.Language();
+    
+    switch (language)
+    {
+    case lldb::eLanguageTypeC:
+        break;
+    case lldb::eLanguageTypeObjC:
+        m_compiler->getLangOpts().ObjC1 = true;
+        m_compiler->getLangOpts().ObjC2 = true;
+        break;
+    case lldb::eLanguageTypeC_plus_plus:
+        m_compiler->getLangOpts().CPlusPlus = true;
+        break;
+    case lldb::eLanguageTypeObjC_plus_plus:
+    default:
+        m_compiler->getLangOpts().ObjC1 = true;
+        m_compiler->getLangOpts().ObjC2 = true;
+        m_compiler->getLangOpts().CPlusPlus = true;
+        break;
+    }
     
     Process *process = NULL;
     if (exe_scope)
         process = exe_scope->CalculateProcess();
 
-    if (process)
+    if (process && m_compiler->getLangOpts().ObjC1)
     {
         if (process->GetObjCLanguageRuntime())
         {

Modified: lldb/trunk/source/Expression/ClangUserExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangUserExpression.cpp?rev=144042&r1=144041&r2=144042&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangUserExpression.cpp (original)
+++ lldb/trunk/source/Expression/ClangUserExpression.cpp Mon Nov  7 17:35:40 2011
@@ -44,10 +44,12 @@
 using namespace lldb_private;
 
 ClangUserExpression::ClangUserExpression (const char *expr,
-                                          const char *expr_prefix) :
+                                          const char *expr_prefix,
+                                          lldb::LanguageType language) :
     ClangExpression (),
     m_expr_text (expr),
     m_expr_prefix (expr_prefix ? expr_prefix : ""),
+    m_language (language),
     m_transformed_text (),
     m_desired_type (NULL, NULL),
     m_cplusplus (false),
@@ -58,6 +60,20 @@
     m_evaluated_statically (false),
     m_const_result ()
 {
+    switch (m_language)
+    {
+    case lldb::eLanguageTypeC_plus_plus:
+        m_allow_cxx = true;
+        break;
+    case lldb::eLanguageTypeObjC:
+        m_allow_objc = true;
+        break;
+    case lldb::eLanguageTypeObjC_plus_plus:
+    default:
+        m_allow_cxx = true;
+        m_allow_objc = true;
+        break;
+    }
 }
 
 ClangUserExpression::~ClangUserExpression ()
@@ -86,6 +102,9 @@
 {
     m_target = exe_ctx.GetTargetPtr();
     
+    if (!(m_allow_cxx || m_allow_objc))
+        return;
+    
     StackFrame *frame = exe_ctx.GetFramePtr();
     if (frame == NULL)
         return;
@@ -107,7 +126,7 @@
             
     if (clang::CXXMethodDecl *method_decl = llvm::dyn_cast<clang::CXXMethodDecl>(decl_context))
     {
-        if (method_decl->isInstance())
+        if (m_allow_cxx && method_decl->isInstance())
         {
             VariableList *vars = frame->GetVariableList(false);
             
@@ -148,7 +167,7 @@
     }
     else if (clang::ObjCMethodDecl *method_decl = llvm::dyn_cast<clang::ObjCMethodDecl>(decl_context))
     {        
-        if (method_decl->isInstanceMethod())
+        if (m_allow_objc && method_decl->isInstanceMethod())
         {
             VariableList *vars = frame->GetVariableList(false);
             
@@ -602,18 +621,20 @@
 ExecutionResults
 ClangUserExpression::Evaluate (ExecutionContext &exe_ctx,
                                lldb_private::ExecutionPolicy execution_policy,
+                               lldb::LanguageType language,
                                bool discard_on_error,
                                const char *expr_cstr,
                                const char *expr_prefix,
                                lldb::ValueObjectSP &result_valobj_sp)
 {
     Error error;
-    return EvaluateWithError (exe_ctx, execution_policy, discard_on_error, expr_cstr, expr_prefix, result_valobj_sp, error);
+    return EvaluateWithError (exe_ctx, execution_policy, language, discard_on_error, expr_cstr, expr_prefix, result_valobj_sp, error);
 }
 
 ExecutionResults
 ClangUserExpression::EvaluateWithError (ExecutionContext &exe_ctx,
                                         lldb_private::ExecutionPolicy execution_policy,
+                                        lldb::LanguageType language,
                                         bool discard_on_error,
                                         const char *expr_cstr,
                                         const char *expr_prefix,
@@ -642,7 +663,7 @@
     if (process == NULL || !process->CanJIT())
         execution_policy = eExecutionPolicyNever;
     
-    ClangUserExpressionSP user_expression_sp (new ClangUserExpression (expr_cstr, expr_prefix));
+    ClangUserExpressionSP user_expression_sp (new ClangUserExpression (expr_cstr, expr_prefix, language));
 
     StreamString error_stream;
         

Modified: lldb/trunk/source/Target/Process.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=144042&r1=144041&r2=144042&view=diff
==============================================================================
--- lldb/trunk/source/Target/Process.cpp (original)
+++ lldb/trunk/source/Target/Process.cpp Mon Nov  7 17:35:40 2011
@@ -1190,7 +1190,7 @@
                 expr.Printf("dlopen (\"%s\", 2)", path);
                 const char *prefix = "extern \"C\" void* dlopen (const char *path, int mode);\n";
                 lldb::ValueObjectSP result_valobj_sp;
-                ClangUserExpression::Evaluate (exe_ctx, eExecutionPolicyAlways, unwind_on_error, expr.GetData(), prefix, result_valobj_sp);
+                ClangUserExpression::Evaluate (exe_ctx, eExecutionPolicyAlways, lldb::eLanguageTypeUnknown, unwind_on_error, expr.GetData(), prefix, result_valobj_sp);
                 error = result_valobj_sp->GetError();
                 if (error.Success())
                 {
@@ -1254,7 +1254,7 @@
                         expr.Printf("dlclose ((void *)0x%llx)", image_addr);
                         const char *prefix = "extern \"C\" int dlclose(void* handle);\n";
                         lldb::ValueObjectSP result_valobj_sp;
-                        ClangUserExpression::Evaluate (exe_ctx, eExecutionPolicyAlways, unwind_on_error, expr.GetData(), prefix, result_valobj_sp);
+                        ClangUserExpression::Evaluate (exe_ctx, eExecutionPolicyAlways, lldb::eLanguageTypeUnknown, unwind_on_error, expr.GetData(), prefix, result_valobj_sp);
                         if (result_valobj_sp->GetError().Success())
                         {
                             Scalar scalar;

Modified: lldb/trunk/source/Target/StopInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/StopInfo.cpp?rev=144042&r1=144041&r2=144042&view=diff
==============================================================================
--- lldb/trunk/source/Target/StopInfo.cpp (original)
+++ lldb/trunk/source/Target/StopInfo.cpp Mon Nov  7 17:35:40 2011
@@ -208,6 +208,7 @@
                         Error error;
                         result_code = ClangUserExpression::EvaluateWithError (context.exe_ctx,
                                                                               eExecutionPolicyAlways,
+                                                                              lldb::eLanguageTypeUnknown,
                                                                               discard_on_error,
                                                                               bp_loc_sp->GetConditionText(),
                                                                               NULL,
@@ -446,6 +447,7 @@
                 Error error;
                 result_code = ClangUserExpression::EvaluateWithError (context.exe_ctx,
                                                                       eExecutionPolicyAlways,
+                                                                      lldb::eLanguageTypeUnknown,
                                                                       discard_on_error,
                                                                       wp_sp->GetConditionText(),
                                                                       NULL,

Modified: lldb/trunk/source/Target/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Target.cpp?rev=144042&r1=144041&r2=144042&view=diff
==============================================================================
--- lldb/trunk/source/Target/Target.cpp (original)
+++ lldb/trunk/source/Target/Target.cpp Mon Nov  7 17:35:40 2011
@@ -1544,6 +1544,7 @@
                     
             execution_results = ClangUserExpression::Evaluate (exe_ctx, 
                                                                execution_policy,
+                                                               lldb::eLanguageTypeUnknown,
                                                                unwind_on_error,
                                                                expr_cstr, 
                                                                prefix, 





More information about the lldb-commits mailing list