[Lldb-commits] [lldb] r348240 - [Expr] Check the language before ignoring Objective C keywords

Aleksandr Urakov via lldb-commits lldb-commits at lists.llvm.org
Tue Dec 4 01:51:30 PST 2018


Author: aleksandr.urakov
Date: Tue Dec  4 01:51:29 2018
New Revision: 348240

URL: http://llvm.org/viewvc/llvm-project?rev=348240&view=rev
Log:
[Expr] Check the language before ignoring Objective C keywords

Summary:
This patch adds the check of the language before ignoring names like `id` or
`Class`, which are reserved in Objective C, but are allowed in C++. It is needed
to make it possible to evaluate expressions in a C++ program containing names
like `id` or `Class`.

Reviewers: jingham, zturner, labath, clayborg

Reviewed By: jingham, clayborg

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D54843

Modified:
    lldb/trunk/packages/Python/lldbsuite/test/expression_command/options/TestExprOptions.py
    lldb/trunk/packages/Python/lldbsuite/test/expression_command/options/main.cpp
    lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
    lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp

Modified: lldb/trunk/packages/Python/lldbsuite/test/expression_command/options/TestExprOptions.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/expression_command/options/TestExprOptions.py?rev=348240&r1=348239&r2=348240&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/expression_command/options/TestExprOptions.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/options/TestExprOptions.py Tue Dec  4 01:51:29 2018
@@ -63,3 +63,16 @@ class ExprOptionsTestCase(TestBase):
         val = frame.EvaluateExpression('foo != nullptr', options)
         self.assertTrue(val.IsValid())
         self.assertFalse(val.GetError().Success())
+
+        # Make sure we can retrieve `id` variable if language is set to C++11:
+        options.SetLanguage(lldb.eLanguageTypeC_plus_plus_11)
+        val = frame.EvaluateExpression('id == 0', options)
+        self.assertTrue(val.IsValid())
+        self.assertTrue(val.GetError().Success())
+        self.DebugSBValue(val)
+
+        # Make sure we can't retrieve `id` variable if language is set to ObjC:
+        options.SetLanguage(lldb.eLanguageTypeObjC)
+        val = frame.EvaluateExpression('id == 0', options)
+        self.assertTrue(val.IsValid())
+        self.assertFalse(val.GetError().Success())

Modified: lldb/trunk/packages/Python/lldbsuite/test/expression_command/options/main.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/expression_command/options/main.cpp?rev=348240&r1=348239&r2=348240&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/expression_command/options/main.cpp (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/options/main.cpp Tue Dec  4 01:51:29 2018
@@ -1,11 +1,13 @@
 extern "C" int foo(void);
 static int static_value = 0;
+static int id = 1234;
 
 int
 bar()
 {
     static_value++;
-    return static_value;
+    id++;
+    return static_value + id;
 }
 
 int main (int argc, char const *argv[])

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp?rev=348240&r1=348239&r2=348240&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp Tue Dec  4 01:51:29 2018
@@ -771,8 +771,9 @@ bool ClangASTSource::IgnoreName(const Co
   static const ConstString id_name("id");
   static const ConstString Class_name("Class");
 
-  if (name == id_name || name == Class_name)
-    return true;
+  if (m_ast_context->getLangOpts().ObjC)
+    if (name == id_name || name == Class_name)
+      return true;
 
   StringRef name_string_ref = name.GetStringRef();
 

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp?rev=348240&r1=348239&r2=348240&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp Tue Dec  4 01:51:29 2018
@@ -398,10 +398,9 @@ ClangExpressionParser::ClangExpressionPa
     LLVM_FALLTHROUGH;
   case lldb::eLanguageTypeC_plus_plus_03:
     m_compiler->getLangOpts().CPlusPlus = true;
-    // FIXME: the following language option is a temporary workaround,
-    // to "ask for C++, get ObjC++".  Apple hopes to remove this requirement on
-    // non-Apple platforms, but for now it is needed.
-    m_compiler->getLangOpts().ObjC = true;
+    if (process_sp)
+      m_compiler->getLangOpts().ObjC =
+          process_sp->GetLanguageRuntime(lldb::eLanguageTypeObjC) != nullptr;
     break;
   case lldb::eLanguageTypeObjC_plus_plus:
   case lldb::eLanguageTypeUnknown:




More information about the lldb-commits mailing list