[Lldb-commits] [lldb] r160181 - in /lldb/trunk: examples/summaries/objc.py source/Core/FormatManager.cpp test/functionalities/data-formatter/rdar-11773899/ test/functionalities/data-formatter/rdar-11773899/Makefile test/functionalities/data-formatter/rdar-11773899/TestFormattersBoolRefPtr.py test/functionalities/data-formatter/rdar-11773899/main.mm

Enrico Granata egranata at apple.com
Fri Jul 13 11:55:41 PDT 2012


Author: enrico
Date: Fri Jul 13 13:55:41 2012
New Revision: 160181

URL: http://llvm.org/viewvc/llvm-project?rev=160181&view=rev
Log:
<rdar://problem/11773899> Formatters for BOOL* and BOOL&

Added:
    lldb/trunk/test/functionalities/data-formatter/rdar-11773899/
    lldb/trunk/test/functionalities/data-formatter/rdar-11773899/Makefile
    lldb/trunk/test/functionalities/data-formatter/rdar-11773899/TestFormattersBoolRefPtr.py
    lldb/trunk/test/functionalities/data-formatter/rdar-11773899/main.mm
Modified:
    lldb/trunk/examples/summaries/objc.py
    lldb/trunk/source/Core/FormatManager.cpp

Modified: lldb/trunk/examples/summaries/objc.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/examples/summaries/objc.py?rev=160181&r1=160180&r2=160181&view=diff
==============================================================================
--- lldb/trunk/examples/summaries/objc.py (original)
+++ lldb/trunk/examples/summaries/objc.py Fri Jul 13 13:55:41 2012
@@ -2,8 +2,15 @@
 # to be generated fit into this file
 
 def BOOL_SummaryProvider (valobj,dict):
+	if  not (valobj.IsValid()):
+		return "<invalid>"
 	if valobj.GetValueAsUnsigned() == 0:
 		return "NO"
 	else:
 		return "YES"
-		
+
+def BOOLRef_SummaryProvider (valobj, dict):
+	return  BOOL_SummaryProvider (valobj.GetChildAtIndex(0),dict)
+
+def BOOLPtr_SummaryProvider (valobj,dict):
+	return BOOL_SummaryProvider (valobj.Dereference(),dict)

Modified: lldb/trunk/source/Core/FormatManager.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/FormatManager.cpp?rev=160181&r1=160180&r2=160181&view=diff
==============================================================================
--- lldb/trunk/source/Core/FormatManager.cpp (original)
+++ lldb/trunk/source/Core/FormatManager.cpp Fri Jul 13 13:55:41 2012
@@ -884,8 +884,8 @@
 {
     TypeSummaryImpl::Flags objc_flags;
     objc_flags.SetCascades(false)
-    .SetSkipPointers(false)
-    .SetSkipReferences(false)
+    .SetSkipPointers(true)
+    .SetSkipReferences(true)
     .SetDontShowChildren(true)
     .SetDontShowValue(true)
     .SetShowMembersOneLiner(false)
@@ -897,6 +897,18 @@
     TypeCategoryImpl::SharedPointer objc_category_sp = GetCategory(m_objc_category_name);
     objc_category_sp->GetSummaryNavigator()->Add(ConstString("BOOL"),
                                                  ObjC_BOOL_summary);
+
+    lldb::TypeSummaryImplSP ObjC_BOOLRef_summary(new ScriptSummaryFormat(objc_flags,
+                                                                      "lldb.formatters.objc.objc.BOOLRef_SummaryProvider",
+                                                                      ""));
+    objc_category_sp->GetSummaryNavigator()->Add(ConstString("BOOL &"),
+                                                 ObjC_BOOLRef_summary);
+    lldb::TypeSummaryImplSP ObjC_BOOLPtr_summary(new ScriptSummaryFormat(objc_flags,
+                                                                      "lldb.formatters.objc.objc.BOOLPtr_SummaryProvider",
+                                                                      ""));
+    objc_category_sp->GetSummaryNavigator()->Add(ConstString("BOOL *"),
+                                                 ObjC_BOOLPtr_summary);
+
     
     // we need to skip pointers here since we are special casing a SEL* when retrieving its value
     objc_flags.SetSkipPointers(true);

Added: lldb/trunk/test/functionalities/data-formatter/rdar-11773899/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/rdar-11773899/Makefile?rev=160181&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/data-formatter/rdar-11773899/Makefile (added)
+++ lldb/trunk/test/functionalities/data-formatter/rdar-11773899/Makefile Fri Jul 13 13:55:41 2012
@@ -0,0 +1,9 @@
+LEVEL = ../../../make
+
+OBJCXX_SOURCES := main.mm
+
+CFLAGS_EXTRAS += -w
+
+include $(LEVEL)/Makefile.rules
+
+LDFLAGS += -framework Foundation

Added: lldb/trunk/test/functionalities/data-formatter/rdar-11773899/TestFormattersBoolRefPtr.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/rdar-11773899/TestFormattersBoolRefPtr.py?rev=160181&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/data-formatter/rdar-11773899/TestFormattersBoolRefPtr.py (added)
+++ lldb/trunk/test/functionalities/data-formatter/rdar-11773899/TestFormattersBoolRefPtr.py Fri Jul 13 13:55:41 2012
@@ -0,0 +1,86 @@
+"""
+Test lldb data formatter subsystem.
+"""
+
+import os, time
+import unittest2
+import lldb
+from lldbtest import *
+import datetime
+
+class DataFormatterBoolRefPtr(TestBase):
+
+    mydir = os.path.join("functionalities", "data-formatter", "rdar-11773899")
+
+    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+    @dsym_test
+    def test_boolrefptr_with_dsym_and_run_command(self):
+        """Test the formatters we use for BOOL& and BOOL* in Objective-C."""
+        self.buildDsym()
+        self.boolrefptr_data_formatter_commands()
+
+    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+    @dwarf_test
+    def test_boolrefptr_with_dwarf_and_run_command(self):
+        """Test the formatters we use for BOOL& and BOOL* in Objective-C."""
+        self.buildDwarf()
+        self.boolrefptr_data_formatter_commands()
+
+    def setUp(self):
+        # Call super's setUp().
+        TestBase.setUp(self)
+        # Find the line number to break at.
+        self.line = line_number('main.mm', '// Set break point at this line.')
+
+    def boolrefptr_data_formatter_commands(self):
+        """Test the formatters we use for BOOL& and BOOL* in Objective-C."""
+        self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
+
+        self.expect("breakpoint set -f main.mm -l %d" % self.line,
+                    BREAKPOINT_CREATED,
+            startstr = "Breakpoint created: 1: file ='main.mm', line = %d, locations = 1" %
+                        self.line)
+
+        self.runCmd("run", RUN_SUCCEEDED)
+
+        # The stop reason of the thread should be breakpoint.
+        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
+            substrs = ['stopped',
+                       'stop reason = breakpoint'])
+
+        # This is the function to remove the custom formats in order to have a
+        # clean slate for the next test case.
+        def cleanup():
+            self.runCmd('type format clear', check=False)
+            self.runCmd('type summary clear', check=False)
+            self.runCmd('type synth clear', check=False)
+
+        # Execute the cleanup function during test case tear down.
+        self.addTearDownHook(cleanup)
+
+        # Now check that we use the right summary for BOOL&
+        self.expect('frame variable yes_ref',
+                    substrs = ['YES'])
+        self.expect('frame variable no_ref',
+                    substrs = ['NO'])
+
+
+        # Now check that we use the right summary for BOOL*
+        self.expect('frame variable yes_ptr',
+                    substrs = ['YES'])
+        self.expect('frame variable no_ptr',
+                    substrs = ['NO'])
+
+
+        # Now check that we use the right summary for BOOL
+        self.expect('frame variable yes',
+                    substrs = ['YES'])
+        self.expect('frame variable no',
+                    substrs = ['NO'])
+
+
+if __name__ == '__main__':
+    import atexit
+    lldb.SBDebugger.Initialize()
+    atexit.register(lambda: lldb.SBDebugger.Terminate())
+    unittest2.main()

Added: lldb/trunk/test/functionalities/data-formatter/rdar-11773899/main.mm
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/rdar-11773899/main.mm?rev=160181&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/data-formatter/rdar-11773899/main.mm (added)
+++ lldb/trunk/test/functionalities/data-formatter/rdar-11773899/main.mm Fri Jul 13 13:55:41 2012
@@ -0,0 +1,29 @@
+//===-- main.m ------------------------------------------------*- ObjC -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#import <Foundation/Foundation.h>
+
+int main (int argc, const char * argv[])
+{
+    
+    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
+
+	BOOL yes  = YES;
+	BOOL no = NO;
+	
+	BOOL &yes_ref = yes;
+	BOOL &no_ref = no;
+	
+	BOOL* yes_ptr = &yes;
+	BOOL* no_ptr = &no;
+
+    [pool drain];// Set break point at this line.
+    return 0;
+}
+





More information about the lldb-commits mailing list