[Lldb-commits] [lldb] r285974 - Don't access the process in expressions w/o checking that

Jim Ingham via lldb-commits lldb-commits at lists.llvm.org
Thu Nov 3 16:42:10 PDT 2016


Author: jingham
Date: Thu Nov  3 18:42:09 2016
New Revision: 285974

URL: http://llvm.org/viewvc/llvm-project?rev=285974&view=rev
Log:
Don't access the process in expressions w/o checking that
the process exists.

I also added some tests that crash before this fix, and work correctly after.

<rdar://problem/29083321>

Added:
    lldb/trunk/packages/Python/lldbsuite/test/expression_command/calculator_mode/
    lldb/trunk/packages/Python/lldbsuite/test/expression_command/calculator_mode/TestCalculatorMode.py
Modified:
    lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp

Added: lldb/trunk/packages/Python/lldbsuite/test/expression_command/calculator_mode/TestCalculatorMode.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/expression_command/calculator_mode/TestCalculatorMode.py?rev=285974&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/expression_command/calculator_mode/TestCalculatorMode.py (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/calculator_mode/TestCalculatorMode.py Thu Nov  3 18:42:09 2016
@@ -0,0 +1,27 @@
+"""
+Test calling an expression without a target.
+"""
+
+from __future__ import print_function
+
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class TestCalculatorMode(TestBase):
+
+    mydir = TestBase.compute_mydir(__file__)
+
+    def setUp(self):
+        # Call super's setUp().
+        TestBase.setUp(self)
+
+    def test__calculator_mode(self):
+        """Test calling expressions in the dummy target."""
+        self.expect("expression 11 + 22", "11 + 22 didn't get the expected result", substrs=["33"])
+        # Now try it with a specific language:
+        self.expect("expression -l c -- 11 + 22", "11 + 22 didn't get the expected result", substrs=["33"])
+

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=285974&r1=285973&r2=285974&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp Thu Nov  3 18:42:09 2016
@@ -808,9 +808,9 @@ lldb_private::Error ClangExpressionParse
     if (log)
       log->Printf("%s - Currrent expression language is %s\n", __FUNCTION__,
                   Language::GetNameForLanguageType(lang));
-
-    if (lang != lldb::eLanguageTypeUnknown) {
-      auto runtime = exe_ctx.GetProcessSP()->GetLanguageRuntime(lang);
+    lldb::ProcessSP process_sp = exe_ctx.GetProcessSP();
+    if (process_sp && lang != lldb::eLanguageTypeUnknown) {
+      auto runtime = process_sp->GetLanguageRuntime(lang);
       if (runtime)
         runtime->GetIRPasses(custom_passes);
     }




More information about the lldb-commits mailing list