[Lldb-commits] [lldb] r257242 - Writing a test case for r257234 I found another place that was

Jim Ingham via lldb-commits lldb-commits at lists.llvm.org
Fri Jan 8 17:20:31 PST 2016


Author: jingham
Date: Fri Jan  8 19:20:30 2016
New Revision: 257242

URL: http://llvm.org/viewvc/llvm-project?rev=257242&view=rev
Log:
Writing a test case for r257234 I found another place that was
assuming a ValueObject always has a process.  So this is that fix
and the test case.

Added:
    lldb/trunk/packages/Python/lldbsuite/test/lang/objc/global_ptrs/
    lldb/trunk/packages/Python/lldbsuite/test/lang/objc/global_ptrs/Makefile
    lldb/trunk/packages/Python/lldbsuite/test/lang/objc/global_ptrs/TestGlobalObjects.py
    lldb/trunk/packages/Python/lldbsuite/test/lang/objc/global_ptrs/main.m
Modified:
    lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp

Added: lldb/trunk/packages/Python/lldbsuite/test/lang/objc/global_ptrs/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/objc/global_ptrs/Makefile?rev=257242&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/objc/global_ptrs/Makefile (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/objc/global_ptrs/Makefile Fri Jan  8 19:20:30 2016
@@ -0,0 +1,6 @@
+LEVEL = ../../../make
+
+OBJC_SOURCES := main.m
+LDFLAGS = $(CFLAGS) -lobjc -framework Foundation
+
+include $(LEVEL)/Makefile.rules

Added: lldb/trunk/packages/Python/lldbsuite/test/lang/objc/global_ptrs/TestGlobalObjects.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/objc/global_ptrs/TestGlobalObjects.py?rev=257242&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/objc/global_ptrs/TestGlobalObjects.py (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/objc/global_ptrs/TestGlobalObjects.py Fri Jan  8 19:20:30 2016
@@ -0,0 +1,53 @@
+"""Test that a global ObjC object found before the process is started updates correctly."""
+
+from __future__ import print_function
+
+
+
+import os, time
+import lldb
+import lldbsuite.test.lldbutil as lldbutil
+from lldbsuite.test.lldbtest import *
+
+class TestObjCGlobalVar(TestBase):
+
+    mydir = TestBase.compute_mydir(__file__)
+
+    def setUp(self):
+        # Call super's setUp().
+        TestBase.setUp(self)
+        self.main_source = lldb.SBFileSpec("main.m")
+
+    @skipUnlessDarwin
+    @add_test_categories(['pyapi'])
+    def test_with_python_api(self):
+        """Test that a global ObjC object found before the process is started updates correctly."""
+        self.build()
+        exe = os.path.join(os.getcwd(), "a.out")
+
+        target = self.dbg.CreateTarget(exe)
+        self.assertTrue(target, VALID_TARGET)
+
+        bkpt = target.BreakpointCreateBySourceRegex ('NSLog', self.main_source)
+        self.assertTrue(bkpt, VALID_BREAKPOINT)
+
+        # Before we launch, make an SBValue for our global object pointer:
+        g_obj_ptr = target.FindFirstGlobalVariable("g_obj_ptr")
+        self.assertTrue(g_obj_ptr.GetError().Success(), "Made the g_obj_ptr")
+        self.assertTrue(g_obj_ptr.GetValueAsUnsigned(10) == 0, "g_obj_ptr is initially null")
+
+        # Now launch the process, and do not stop at entry point.
+        process = target.LaunchSimple (None, None, self.get_process_working_directory())
+
+        self.assertTrue(process, PROCESS_IS_VALID)
+
+        # The stop reason of the thread should be breakpoint.
+        threads = lldbutil.get_threads_stopped_at_breakpoint (process, bkpt)
+        if len(threads) != 1:
+            self.fail ("Failed to stop at breakpoint 1.")
+
+        thread = threads[0]
+
+        dyn_value = g_obj_ptr.GetDynamicValue(lldb.eDynamicCanRunTarget)
+        self.assertTrue(dyn_value.GetError().Success(), "Dynamic value is valid")
+        self.assertTrue(dyn_value.GetObjectDescription() == "Some NSString")

Added: lldb/trunk/packages/Python/lldbsuite/test/lang/objc/global_ptrs/main.m
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/objc/global_ptrs/main.m?rev=257242&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/objc/global_ptrs/main.m (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/objc/global_ptrs/main.m Fri Jan  8 19:20:30 2016
@@ -0,0 +1,11 @@
+#import <Foundation/Foundation.h>
+
+id g_obj_ptr = nil;
+
+int
+main()
+{
+  g_obj_ptr = @"Some NSString";
+  NSLog(@"My string was %@.", g_obj_ptr);
+  return 0;
+}

Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp?rev=257242&r1=257241&r2=257242&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp Fri Jan  8 19:20:30 2016
@@ -69,7 +69,20 @@ AppleObjCRuntime::GetObjectDescription (
     if (!valobj.ResolveValue(val.GetScalar()))
         return false;
     
-    ExecutionContext exe_ctx (valobj.GetExecutionContextRef());
+    // Value Objects may not have a process in their ExecutionContextRef.  But we need to have one
+    // in the ref we pass down to eventually call description.  Get it from the target if it isn't
+    // present.
+    ExecutionContext exe_ctx;
+    if (valobj.GetProcessSP())
+    {
+        exe_ctx = ExecutionContext(valobj.GetExecutionContextRef());
+    }
+    else
+    {
+        exe_ctx.SetContext(valobj.GetTargetSP(), true);
+        if (!exe_ctx.HasProcessScope())
+            return false;
+    }
     return GetObjectDescription(str, val, exe_ctx.GetBestExecutionContextScope());
                    
 }




More information about the lldb-commits mailing list