[Lldb-commits] [lldb] r157190 - in /lldb/trunk: include/lldb/Core/ValueObject.h include/lldb/Target/Process.h source/Core/ValueObject.cpp source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp source/Target/Process.cpp test/lang/objc/rdar-11355592/ test/lang/objc/rdar-11355592/Makefile test/lang/objc/rdar-11355592/TestRdar11355592.py test/lang/objc/rdar-11355592/main.m

Enrico Granata egranata at apple.com
Mon May 21 09:51:35 PDT 2012


Author: enrico
Date: Mon May 21 11:51:35 2012
New Revision: 157190

URL: http://llvm.org/viewvc/llvm-project?rev=157190&view=rev
Log:
<rdar://problem/11355592> Fixing a bug where we would incorrectly try and determine a dynamic type for a variable of a pointer type that is not a valid generic type for dynamic pointers.

Added:
    lldb/trunk/test/lang/objc/rdar-11355592/
    lldb/trunk/test/lang/objc/rdar-11355592/Makefile
    lldb/trunk/test/lang/objc/rdar-11355592/TestRdar11355592.py
    lldb/trunk/test/lang/objc/rdar-11355592/main.m
Modified:
    lldb/trunk/include/lldb/Core/ValueObject.h
    lldb/trunk/include/lldb/Target/Process.h
    lldb/trunk/source/Core/ValueObject.cpp
    lldb/trunk/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp
    lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
    lldb/trunk/source/Target/Process.cpp

Modified: lldb/trunk/include/lldb/Core/ValueObject.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ValueObject.h?rev=157190&r1=157189&r2=157190&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ValueObject.h (original)
+++ lldb/trunk/include/lldb/Core/ValueObject.h Mon May 21 11:51:35 2012
@@ -600,9 +600,6 @@
     IsPointerOrReferenceType ();
     
     virtual bool
-    IsPossibleCPlusPlusDynamicType ();
-    
-    virtual bool
     IsPossibleDynamicType ();
 
     virtual bool

Modified: lldb/trunk/include/lldb/Target/Process.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Process.h?rev=157190&r1=157189&r2=157190&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Process.h (original)
+++ lldb/trunk/include/lldb/Target/Process.h Mon May 21 11:51:35 2012
@@ -3088,6 +3088,9 @@
     GetObjCLanguageRuntime (bool retry_if_null = true);
     
     bool
+    IsPossibleDynamicValue (ValueObject& in_value);
+    
+    bool
     IsRunning () const;
     
     DynamicCheckerFunctions *GetDynamicCheckers()

Modified: lldb/trunk/source/Core/ValueObject.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObject.cpp?rev=157190&r1=157189&r2=157190&view=diff
==============================================================================
--- lldb/trunk/source/Core/ValueObject.cpp (original)
+++ lldb/trunk/source/Core/ValueObject.cpp Mon May 21 11:51:35 2012
@@ -1766,15 +1766,14 @@
 }
 
 bool
-ValueObject::IsPossibleCPlusPlusDynamicType ()
-{
-    return ClangASTContext::IsPossibleCPlusPlusDynamicType (GetClangAST (), GetClangType());
-}
-
-bool
 ValueObject::IsPossibleDynamicType ()
 {
-    return ClangASTContext::IsPossibleDynamicType (GetClangAST (), GetClangType());
+    ExecutionContext exe_ctx (GetExecutionContextRef());
+    Process *process = exe_ctx.GetProcessPtr();
+    if (process)
+        return process->IsPossibleDynamicValue(*this);
+    else
+        return ClangASTContext::IsPossibleDynamicType (GetClangAST (), GetClangType());
 }
 
 ValueObjectSP
@@ -2058,37 +2057,8 @@
     {
         ExecutionContext exe_ctx (GetExecutionContextRef());
         Process *process = exe_ctx.GetProcessPtr();
-        if (process)
-        {
-            bool worth_having_dynamic_value = false;
-            
-            
-            // FIXME: Process should have some kind of "map over Runtimes" so we don't have to
-            // hard code this everywhere.
-            LanguageType known_type = GetObjectRuntimeLanguage();
-            if (known_type != eLanguageTypeUnknown && known_type != eLanguageTypeC)
-            {
-                LanguageRuntime *runtime = process->GetLanguageRuntime (known_type);
-                if (runtime)
-                    worth_having_dynamic_value = runtime->CouldHaveDynamicValue(*this);
-            }
-            else
-            {
-                LanguageRuntime *cpp_runtime = process->GetLanguageRuntime (eLanguageTypeC_plus_plus);
-                if (cpp_runtime)
-                    worth_having_dynamic_value = cpp_runtime->CouldHaveDynamicValue(*this);
-                
-                if (!worth_having_dynamic_value)
-                {
-                    LanguageRuntime *objc_runtime = process->GetLanguageRuntime (eLanguageTypeObjC);
-                    if (objc_runtime)
-                        worth_having_dynamic_value = objc_runtime->CouldHaveDynamicValue(*this);
-                }
-            }
-            
-            if (worth_having_dynamic_value)
-                m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
-        }
+        if (process && process->IsPossibleDynamicValue(*this))
+            m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
     }
 }
 

Modified: lldb/trunk/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp?rev=157190&r1=157189&r2=157190&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp Mon May 21 11:51:35 2012
@@ -38,7 +38,9 @@
 bool
 ItaniumABILanguageRuntime::CouldHaveDynamicValue (ValueObject &in_value)
 {
-    return in_value.IsPossibleCPlusPlusDynamicType();
+    return ClangASTContext::IsPossibleDynamicType(in_value.GetClangAST(), in_value.GetClangType(), NULL,
+                                                  true, // check for C++
+                                                  false); // do not check for ObjC
 }
 
 bool

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=157190&r1=157189&r2=157190&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp Mon May 21 11:51:35 2012
@@ -193,11 +193,10 @@
 bool
 AppleObjCRuntime::CouldHaveDynamicValue (ValueObject &in_value)
 {
-    lldb::LanguageType known_type = in_value.GetObjectRuntimeLanguage();
-    if (known_type == lldb::eLanguageTypeObjC)
-        return in_value.IsPossibleDynamicType ();
-    else
-        return in_value.IsPointerType();
+    return ClangASTContext::IsPossibleDynamicType(in_value.GetClangAST(), in_value.GetClangType(),
+                                                  NULL,
+                                                  false, // do not check C++
+                                                  true); // check ObjC
 }
 
 bool

Modified: lldb/trunk/source/Target/Process.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=157190&r1=157189&r2=157190&view=diff
==============================================================================
--- lldb/trunk/source/Target/Process.cpp (original)
+++ lldb/trunk/source/Target/Process.cpp Mon May 21 11:51:35 2012
@@ -1573,6 +1573,27 @@
     return NULL;
 }
 
+bool
+Process::IsPossibleDynamicValue (ValueObject& in_value)
+{
+    if (in_value.IsDynamic())
+        return false;
+    LanguageType known_type = in_value.GetObjectRuntimeLanguage();
+
+    if (known_type != eLanguageTypeUnknown && known_type != eLanguageTypeC)
+    {
+        LanguageRuntime *runtime = GetLanguageRuntime (known_type);
+        return runtime ? runtime->CouldHaveDynamicValue(in_value) : false;
+    }
+
+    LanguageRuntime *cpp_runtime = GetLanguageRuntime (eLanguageTypeC_plus_plus);
+    if (cpp_runtime && cpp_runtime->CouldHaveDynamicValue(in_value))
+        return true;
+    
+    LanguageRuntime *objc_runtime = GetLanguageRuntime (eLanguageTypeObjC);
+    return objc_runtime ? objc_runtime->CouldHaveDynamicValue(in_value) : false;
+}
+
 BreakpointSiteList &
 Process::GetBreakpointSiteList()
 {

Added: lldb/trunk/test/lang/objc/rdar-11355592/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lang/objc/rdar-11355592/Makefile?rev=157190&view=auto
==============================================================================
--- lldb/trunk/test/lang/objc/rdar-11355592/Makefile (added)
+++ lldb/trunk/test/lang/objc/rdar-11355592/Makefile Mon May 21 11:51:35 2012
@@ -0,0 +1,7 @@
+LEVEL = ../../../make
+
+OBJC_SOURCES := main.m
+
+include $(LEVEL)/Makefile.rules
+
+LDFLAGS += -framework Foundation

Added: lldb/trunk/test/lang/objc/rdar-11355592/TestRdar11355592.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lang/objc/rdar-11355592/TestRdar11355592.py?rev=157190&view=auto
==============================================================================
--- lldb/trunk/test/lang/objc/rdar-11355592/TestRdar11355592.py (added)
+++ lldb/trunk/test/lang/objc/rdar-11355592/TestRdar11355592.py Mon May 21 11:51:35 2012
@@ -0,0 +1,82 @@
+"""
+Test that we do not attempt to make a dynamic type for a 'const char*'
+"""
+
+import os, time
+import unittest2
+import lldb
+from lldbtest import *
+
+ at unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+class Rdar10967107TestCase(TestBase):
+
+    mydir = os.path.join("lang", "objc", "rdar-11355592")
+
+    @dsym_test
+    def test_charstar_dyntype_with_dsym(self):
+        """Test that we do not attempt to make a dynamic type for a 'const char*'"""
+        d = {'EXE': self.exe_name}
+        self.buildDsym(dictionary=d)
+        self.setTearDownCleanup(dictionary=d)
+        self.charstar_dyntype(self.exe_name)
+
+    @dwarf_test
+    def test_charstar_dyntype_with_dwarf(self):
+        """Test that we do not attempt to make a dynamic type for a 'const char*'"""
+        d = {'EXE': self.exe_name}
+        self.buildDwarf(dictionary=d)
+        self.setTearDownCleanup(dictionary=d)
+        self.charstar_dyntype(self.exe_name)
+
+    def setUp(self):
+        # Call super's setUp().
+        TestBase.setUp(self)
+        # We'll use the test method name as the exe_name.
+        self.exe_name = self.testMethodName
+        # Find the line number to break inside main().
+        self.main_source = "main.m"
+        self.line = line_number(self.main_source, '// Set breakpoint here.')
+
+    def charstar_dyntype(self, exe_name):
+        """Test that we do not attempt to make a dynamic type for a 'const char*'"""
+        exe = os.path.join(os.getcwd(), exe_name)
+        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
+
+        self.expect("breakpoint set -f %s -l %d" % (self.main_source, self.line),
+                    BREAKPOINT_CREATED,
+            startstr = "Breakpoint created: 1: file ='%s', line = %d, locations = 1" %
+                        (self.main_source, self.line))
+
+        self.runCmd("run", RUN_SUCCEEDED)
+        # check that we correctly see the const char*, even with dynamic types on
+        self.expect("frame variable my_string", substrs = ['const char *'])
+        self.expect("frame variable my_string -d run-target", substrs = ['const char *'])
+        # check that expr also gets it right
+        self.expect("expr my_string", substrs = ['const char *'])
+        self.expect("expr -d true -- my_string", substrs = ['const char *'])
+        # but check that we get the real Foolie as such
+        self.expect("frame variable my_foolie", substrs = ['FoolMeOnce *'])
+        self.expect("frame variable my_foolie -d run-target", substrs = ['FoolMeOnce *'])
+        # check that expr also gets it right
+        self.expect("expr my_foolie", substrs = ['FoolMeOnce *'])
+        self.expect("expr -d true -- my_foolie", substrs = ['FoolMeOnce *'])
+        # now check that assigning a true string does not break anything
+        self.runCmd("next")
+        # check that we correctly see the const char*, even with dynamic types on
+        self.expect("frame variable my_string", substrs = ['const char *'])
+        self.expect("frame variable my_string -d run-target", substrs = ['const char *'])
+        # check that expr also gets it right
+        self.expect("expr my_string", substrs = ['const char *'])
+        self.expect("expr -d true -- my_string", substrs = ['const char *'])
+        # but check that we get the real Foolie as such
+        self.expect("frame variable my_foolie", substrs = ['FoolMeOnce *'])
+        self.expect("frame variable my_foolie -d run-target", substrs = ['FoolMeOnce *'])
+        # check that expr also gets it right
+        self.expect("expr my_foolie", substrs = ['FoolMeOnce *'])
+        self.expect("expr -d true -- my_foolie", substrs = ['FoolMeOnce *'])
+
+if __name__ == '__main__':
+    import atexit
+    lldb.SBDebugger.Initialize()
+    atexit.register(lambda: lldb.SBDebugger.Terminate())
+    unittest2.main()

Added: lldb/trunk/test/lang/objc/rdar-11355592/main.m
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lang/objc/rdar-11355592/main.m?rev=157190&view=auto
==============================================================================
--- lldb/trunk/test/lang/objc/rdar-11355592/main.m (added)
+++ lldb/trunk/test/lang/objc/rdar-11355592/main.m Mon May 21 11:51:35 2012
@@ -0,0 +1,37 @@
+#import <Foundation/Foundation.h>
+
+ at interface FoolMeOnce : NSObject
+{
+	int32_t value_one; // ivars needed to make 32-bit happy
+	int32_t value_two;
+}
+- (FoolMeOnce *) initWithFirst: (int32_t) first andSecond: (int32_t) second;
+
+ at property int32_t value_one;
+ at property int32_t value_two;
+
+ at end
+
+ at implementation FoolMeOnce
+ at synthesize value_one;
+ at synthesize value_two;
+- (FoolMeOnce *) initWithFirst: (int32_t) first andSecond: (int32_t) second
+{
+  value_one = first;
+  value_two = second;
+  return self;
+}
+ at end
+
+int main (int argc, char const *argv[])
+{
+    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
+
+    FoolMeOnce *my_foolie = [[FoolMeOnce alloc] initWithFirst: 20 andSecond: 55];
+    const char *my_string = (char *) my_foolie;
+// Set breakpoint here.
+    my_string = "Now this is a REAL string...";
+
+    [pool release];
+    return 0;
+}





More information about the lldb-commits mailing list