Don't access the process in expressions w/o checking that
authorJim Ingham <jingham@apple.com>
Thu, 3 Nov 2016 23:42:09 +0000 (23:42 +0000)
committerJim Ingham <jingham@apple.com>
Thu, 3 Nov 2016 23:42:09 +0000 (23:42 +0000)
the process exists.

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

<rdar://problem/29083321>

llvm-svn: 285974

lldb/packages/Python/lldbsuite/test/expression_command/calculator_mode/TestCalculatorMode.py [new file with mode: 0644]
lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp

diff --git a/lldb/packages/Python/lldbsuite/test/expression_command/calculator_mode/TestCalculatorMode.py b/lldb/packages/Python/lldbsuite/test/expression_command/calculator_mode/TestCalculatorMode.py
new file mode 100644 (file)
index 0000000..46ea111
--- /dev/null
@@ -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"])
+
index 95efb5c..1df6246 100644 (file)
@@ -808,9 +808,9 @@ lldb_private::Error ClangExpressionParser::PrepareForExecution(
     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);
     }