[Lldb-commits] [lldb] r146891 - in /lldb/trunk: source/Expression/ClangASTSource.cpp test/lang/objc/objc-builtin-types/ test/lang/objc/objc-builtin-types/Makefile test/lang/objc/objc-builtin-types/TestObjCBuiltinTypes.py test/lang/objc/objc-builtin-types/main.cpp

Sean Callanan scallanan at apple.com
Mon Dec 19 11:38:39 PST 2011


Author: spyffe
Date: Mon Dec 19 13:38:39 2011
New Revision: 146891

URL: http://llvm.org/viewvc/llvm-project?rev=146891&view=rev
Log:
Added some strength to the checks that prevent
"id" from being found by the parser as an
externally-defined type.  Before, "id" would
sometimes make it through if it was defined in
a namespace, but this sometimes caused
confusion, for example when it conflicted with
std::locale::id.

Added:
    lldb/trunk/test/lang/objc/objc-builtin-types/
    lldb/trunk/test/lang/objc/objc-builtin-types/Makefile
    lldb/trunk/test/lang/objc/objc-builtin-types/TestObjCBuiltinTypes.py
    lldb/trunk/test/lang/objc/objc-builtin-types/main.cpp
Modified:
    lldb/trunk/source/Expression/ClangASTSource.cpp

Modified: lldb/trunk/source/Expression/ClangASTSource.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangASTSource.cpp?rev=146891&r1=146890&r2=146891&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangASTSource.cpp (original)
+++ lldb/trunk/source/Expression/ClangASTSource.cpp Mon Dec 19 13:38:39 2011
@@ -574,12 +574,13 @@
         TypeList types;
         SymbolContext null_sc;
         
+        if (name == id_name || name == Class_name)
+            break;
+      
         if (module_sp && namespace_decl)
             module_sp->FindTypes(null_sc, name, &namespace_decl, true, 1, types);
-        else if(name != id_name && name != Class_name)
+        else 
             m_target->GetImages().FindTypes(null_sc, name, true, 1, types);
-        else
-            break;
         
         if (types.GetSize())
         {

Added: lldb/trunk/test/lang/objc/objc-builtin-types/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lang/objc/objc-builtin-types/Makefile?rev=146891&view=auto
==============================================================================
--- lldb/trunk/test/lang/objc/objc-builtin-types/Makefile (added)
+++ lldb/trunk/test/lang/objc/objc-builtin-types/Makefile Mon Dec 19 13:38:39 2011
@@ -0,0 +1,5 @@
+LEVEL = ../../../make
+
+CXX_SOURCES := main.cpp
+
+include $(LEVEL)/Makefile.rules

Added: lldb/trunk/test/lang/objc/objc-builtin-types/TestObjCBuiltinTypes.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lang/objc/objc-builtin-types/TestObjCBuiltinTypes.py?rev=146891&view=auto
==============================================================================
--- lldb/trunk/test/lang/objc/objc-builtin-types/TestObjCBuiltinTypes.py (added)
+++ lldb/trunk/test/lang/objc/objc-builtin-types/TestObjCBuiltinTypes.py Mon Dec 19 13:38:39 2011
@@ -0,0 +1,69 @@
+"""Test that the expression parser doesn't get confused by 'id' and 'Class'"""
+
+import os, time
+import unittest2
+import lldb
+import lldbutil
+from lldbtest import *
+
+class TestObjCBuiltinTypes(TestBase):
+
+    mydir = os.path.join("lang", "objc", "objc-builtin-types")
+
+    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+    @python_api_test
+
+    def test_with_dsym_and_python_api(self):
+        """Test expression parser respect for ObjC built-in types."""
+        self.buildDsym()
+        self.objc_builtin_types()
+
+    @python_api_test
+    def test_with_dwarf_and_python_api(self):
+        """Test expression parser respect for ObjC built-in types."""
+        self.buildDwarf()
+        self.objc_builtin_types()
+
+    def setUp(self):
+        # Call super's setUp().
+        TestBase.setUp(self)
+        # Find the line numbers to break inside main().
+        self.main_source = "main.cpp"
+        self.break_line = line_number(self.main_source, '// Set breakpoint here.')
+
+    #<rdar://problem/10591460> [regression] Can't print ivar value: error: reference to 'id' is ambiguous
+    def objc_builtin_types(self):
+        """Test expression parser respect for ObjC built-in types."""
+        exe = os.path.join(os.getcwd(), "a.out")
+
+        target = self.dbg.CreateTarget(exe)
+        self.assertTrue(target, VALID_TARGET)
+
+        bpt = target.BreakpointCreateByLocation(self.main_source, self.break_line)
+        self.assertTrue(bpt, VALID_BREAKPOINT)
+
+        # Now launch the process, and do not stop at entry point.
+        process = target.LaunchSimple (None, None, os.getcwd())
+
+        self.assertTrue(process, PROCESS_IS_VALID)
+
+        # The stop reason of the thread should be breakpoint.
+        thread_list = lldbutil.get_threads_stopped_at_breakpoint (process, bpt)
+
+        # Make sure we stopped at the first breakpoint.
+        self.assertTrue (len(thread_list) != 0, "No thread stopped at our breakpoint.")
+        self.assertTrue (len(thread_list) == 1, "More than one thread stopped at our breakpoint.")
+            
+        # Now make sure we can call a function in the class method we've stopped in.
+        frame = thread_list[0].GetFrameAtIndex(0)
+        self.assertTrue (frame, "Got a valid frame 0 frame.")
+
+        self.expect("expr (foo)", patterns = ["\(ns::id\) \$.* = 0"])
+
+        self.expect("expr id my_id = 0; my_id", patterns = ["\(id\) \$.* = 0x0"])
+
+if __name__ == '__main__':
+    import atexit
+    lldb.SBDebugger.Initialize()
+    atexit.register(lambda: lldb.SBDebugger.Terminate())
+    unittest2.main()

Added: lldb/trunk/test/lang/objc/objc-builtin-types/main.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lang/objc/objc-builtin-types/main.cpp?rev=146891&view=auto
==============================================================================
--- lldb/trunk/test/lang/objc/objc-builtin-types/main.cpp (added)
+++ lldb/trunk/test/lang/objc/objc-builtin-types/main.cpp Mon Dec 19 13:38:39 2011
@@ -0,0 +1,9 @@
+namespace ns {
+  typedef int id;
+};
+
+int main()
+{
+  ns::id foo = 0;
+  return foo; // Set breakpoint here.
+}





More information about the lldb-commits mailing list