[Lldb-commits] [lldb] r227271 - Added test case to make sure we don't regress on settings breakpoints by selector and with the various partially specified ObjC specified breakpoints.

Greg Clayton gclayton at apple.com
Tue Jan 27 15:45:57 PST 2015


Author: gclayton
Date: Tue Jan 27 17:45:56 2015
New Revision: 227271

URL: http://llvm.org/viewvc/llvm-project?rev=227271&view=rev
Log:
Added test case to make sure we don't regress on settings breakpoints by selector and with the various partially specified ObjC specified breakpoints.

This test tests the equivalent of:
    breakpoint set --name count
    breakpoint set --selector count
    breakpoint set --name isEqual:
    breakpoint set --selector isEqual:
    breakpoint set --name "-[MyClass(MyCategory) myCategoryFunction]"
    breakpoint set --name "-[MyClass myCategoryFunction]"
    breakpoint set --name "[MyClass myCategoryFunction]"


Added:
    lldb/trunk/test/functionalities/breakpoint/objc/
    lldb/trunk/test/functionalities/breakpoint/objc/Makefile
    lldb/trunk/test/functionalities/breakpoint/objc/TestObjCBreakpoints.py
    lldb/trunk/test/functionalities/breakpoint/objc/main.m

Added: lldb/trunk/test/functionalities/breakpoint/objc/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/breakpoint/objc/Makefile?rev=227271&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/breakpoint/objc/Makefile (added)
+++ lldb/trunk/test/functionalities/breakpoint/objc/Makefile Tue Jan 27 17:45:56 2015
@@ -0,0 +1,7 @@
+LEVEL = ../../../make
+
+OBJC_SOURCES := main.m
+
+include $(LEVEL)/Makefile.rules
+
+LDFLAGS += -framework Foundation

Added: lldb/trunk/test/functionalities/breakpoint/objc/TestObjCBreakpoints.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/breakpoint/objc/TestObjCBreakpoints.py?rev=227271&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/breakpoint/objc/TestObjCBreakpoints.py (added)
+++ lldb/trunk/test/functionalities/breakpoint/objc/TestObjCBreakpoints.py Tue Jan 27 17:45:56 2015
@@ -0,0 +1,105 @@
+"""
+Test that objective-c constant strings are generated correctly by the expression
+parser.
+"""
+
+import os, time
+import unittest2
+import lldb
+from lldbtest import *
+import lldbutil
+import shutil
+import subprocess
+
+ at unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+class TestObjCBreakpoints(TestBase):
+
+    mydir = TestBase.compute_mydir(__file__)
+
+    @dsym_test
+    def test_break_with_dsym(self):
+        """Test setting Objective C specific breakpoints (dSYM)."""
+        self.buildDsym()
+        self.setTearDownCleanup()
+        self.check_objc_breakpoints(True)
+
+    @dwarf_test
+    def test_break_with_dwarf(self):
+        """Test setting Objective C specific breakpoints (DWARF in .o files)."""
+        self.buildDwarf()
+        self.setTearDownCleanup()
+        self.check_objc_breakpoints(False)
+
+    def setUp(self):
+        # Call super's setUp().
+        TestBase.setUp(self)
+        # Find the line number to break inside main().
+        self.main_source = "main.m"
+        self.line = line_number(self.main_source, '// Set breakpoint here')
+
+    def check_category_breakpoints(self):
+        name_bp = self.target.BreakpointCreateByName ("myCategoryFunction")
+        selector_bp = self.target.BreakpointCreateByName ("myCategoryFunction", lldb.eFunctionNameTypeSelector, lldb.SBFileSpecList(), lldb.SBFileSpecList())
+        self.assertTrue(name_bp.GetNumLocations() == selector_bp.GetNumLocations(), 'Make sure setting a breakpoint by name "myCategoryFunction" sets a breakpoint even though it is in a category')
+        for bp_loc in selector_bp:
+            function_name = bp_loc.GetAddress().GetSymbol().GetName()
+            self.assertTrue(" myCategoryFunction]" in function_name, 'Make sure all function names have " myCategoryFunction]" in their names')
+            
+        category_bp = self.target.BreakpointCreateByName ("-[MyClass(MyCategory) myCategoryFunction]")
+        stripped_bp = self.target.BreakpointCreateByName ("-[MyClass myCategoryFunction]")
+        stripped2_bp = self.target.BreakpointCreateByName ("[MyClass myCategoryFunction]")
+        self.assertTrue(category_bp.GetNumLocations() == 1, "Make sure we can set a breakpoint using a full objective C function name with the category included (-[MyClass(MyCategory) myCategoryFunction])")
+        self.assertTrue(stripped_bp.GetNumLocations() == 1, "Make sure we can set a breakpoint using a full objective C function name without the category included (-[MyClass myCategoryFunction])")
+        self.assertTrue(stripped2_bp.GetNumLocations() == 1, "Make sure we can set a breakpoint using a full objective C function name without the category included ([MyClass myCategoryFunction])")
+        
+    def check_objc_breakpoints(self, have_dsym):
+        """Test constant string generation amd comparison by the expression parser."""
+
+        # Set debugger into synchronous mode
+        self.dbg.SetAsync(False)
+
+        # Create a target by the debugger.
+        exe = os.path.join(os.getcwd(), "a.out")
+        self.target = self.dbg.CreateTarget(exe)
+        self.assertTrue(self.target, VALID_TARGET)
+
+        #----------------------------------------------------------------------
+        # Set breakpoints on all selectors whose name is "count". This should 
+        # catch breakpoints that are both C functions _and_ anything whose 
+        # selector is "count" because just looking at "count" we can't tell
+        # definitively if the name is a selector or a C function
+        #----------------------------------------------------------------------
+        name_bp = self.target.BreakpointCreateByName ("count")
+        selector_bp = self.target.BreakpointCreateByName ("count", lldb.eFunctionNameTypeSelector, lldb.SBFileSpecList(), lldb.SBFileSpecList())
+        self.assertTrue(name_bp.GetNumLocations() >= selector_bp.GetNumLocations(), 'Make sure we get at least the same amount of breakpoints if not more when setting by name "count"')
+        self.assertTrue(selector_bp.GetNumLocations() > 50, 'Make sure we find a lot of "count" selectors') # There are 93 on the latest MacOSX
+        for bp_loc in selector_bp:
+            function_name = bp_loc.GetAddress().GetSymbol().GetName()
+            self.assertTrue(" count]" in function_name, 'Make sure all function names have " count]" in their names')
+
+        #----------------------------------------------------------------------
+        # Set breakpoints on all selectors whose name is "isEqual:". This should
+        # catch breakpoints that are only ObjC selectors because no C function
+        # can end with a :
+        #----------------------------------------------------------------------
+        name_bp = self.target.BreakpointCreateByName ("isEqual:")
+        selector_bp = self.target.BreakpointCreateByName ("isEqual:", lldb.eFunctionNameTypeSelector, lldb.SBFileSpecList(), lldb.SBFileSpecList())
+        self.assertTrue(name_bp.GetNumLocations() == selector_bp.GetNumLocations(), 'Make sure setting a breakpoint by name "isEqual:" only sets selector breakpoints')
+        for bp_loc in selector_bp:
+            function_name = bp_loc.GetAddress().GetSymbol().GetName()
+            self.assertTrue(" isEqual:]" in function_name, 'Make sure all function names have " isEqual:]" in their names')
+    
+        self.check_category_breakpoints()
+        
+        if have_dsym:
+            shutil.rmtree(exe + ".dSYM")
+        self.assertTrue(subprocess.call(['/usr/bin/strip', '-Sx', exe]) == 0, 'stripping dylib succeeded')
+        
+        # Check breakpoints again, this time using the symbol table only
+        self.check_category_breakpoints()
+        
+if __name__ == '__main__':
+    import atexit
+    lldb.SBDebugger.Initialize()
+    atexit.register(lambda: lldb.SBDebugger.Terminate())
+    unittest2.main()

Added: lldb/trunk/test/functionalities/breakpoint/objc/main.m
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/breakpoint/objc/main.m?rev=227271&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/breakpoint/objc/main.m (added)
+++ lldb/trunk/test/functionalities/breakpoint/objc/main.m Tue Jan 27 17:45:56 2015
@@ -0,0 +1,98 @@
+#import <Foundation/Foundation.h>
+#include <unistd.h>
+
+ at interface MyClass : NSObject
+ at end
+
+ at implementation MyClass : NSObject
+ at end
+
+ at implementation MyClass (MyCategory)
+
+
+- (void) myCategoryFunction {
+    NSLog (@"myCategoryFunction");
+}
+
+ at end
+
+
+    
+int
+Test_Selector ()
+{
+    SEL sel = @selector(length);
+    printf("sel = %p\n", sel);
+    // Expressions to test here for selector: 
+    // expression (char *)sel_getName(sel)
+    //      The expression above should return "sel" as it should be just
+    //      a uniqued C string pointer. We were seeing the result pointer being
+    //      truncated with recent LLDBs.
+    return 0; // Break here for selector: tests
+}
+
+int
+Test_NSString (const char *program)
+{
+    NSString *str = [NSString stringWithFormat:@"Hello from '%s'", program];
+    NSLog(@"NSString instance: %@", str);
+    printf("str = '%s'\n", [str cStringUsingEncoding: [NSString defaultCStringEncoding]]);
+    printf("[str length] = %zu\n", (size_t)[str length]);
+    printf("[str description] = %s\n", [[str description] UTF8String]);
+    id str_id = str;
+    // Expressions to test here for NSString:
+    // expression (char *)sel_getName(sel)
+    // expression [str length]
+    // expression [str_id length]
+    // expression [str description]
+    // expression [str_id description]
+    // expression str.length
+    // expression str.description
+    // expression str = @"new"
+    // expression str = [NSString stringWithFormat: @"%cew", 'N']
+    return 0; // Break here for NSString tests
+}
+
+NSString *my_global_str = NULL;
+
+int
+Test_NSArray ()
+{
+    NSMutableArray *nil_mutable_array = nil;
+    NSArray *array1 = [NSArray arrayWithObjects: @"array1 object1", @"array1 object2", @"array1 object3", nil];
+    NSArray *array2 = [NSArray arrayWithObjects: array1, @"array2 object2", @"array2 object3", nil];
+    // Expressions to test here for NSArray:
+    // expression [nil_mutable_array count]
+    // expression [array1 count]
+    // expression array1.count
+    // expression [array2 count]
+    // expression array2.count
+    id obj;
+    // After each object at index call, use expression and validate object
+    obj = [array1 objectAtIndex: 0]; // Break here for NSArray tests
+    obj = [array1 objectAtIndex: 1];
+    obj = [array1 objectAtIndex: 2];
+
+    obj = [array2 objectAtIndex: 0];
+    obj = [array2 objectAtIndex: 1];
+    obj = [array2 objectAtIndex: 2];
+    NSUInteger count = [nil_mutable_array count];
+    return 0;
+}
+
+
+int main (int argc, char const *argv[])
+{
+    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
+    Test_Selector(); // Set breakpoint here
+    Test_NSArray ();
+    Test_NSString (argv[0]);
+    MyClass *my_class = [[MyClass alloc] init];
+    [my_class myCategoryFunction];
+    printf("sizeof(id) = %zu\n", sizeof(id));
+    printf("sizeof(Class) = %zu\n", sizeof(Class));
+    printf("sizeof(SEL) = %zu\n", sizeof(SEL));
+
+    [pool release];
+    return 0;
+}





More information about the lldb-commits mailing list