[Lldb-commits] [lldb] r131154 - in /lldb/trunk/test: expression_command/two-files/ expression_command/two-files/Makefile expression_command/two-files/TestObjCTypeQueryFromOtherCompileUnit.py expression_command/two-files/foo.m expression_command/two-files/main.c foundation/Makefile

Johnny Chen johnny.chen at apple.com
Tue May 10 14:36:11 PDT 2011


Author: johnny
Date: Tue May 10 16:36:11 2011
New Revision: 131154

URL: http://llvm.org/viewvc/llvm-project?rev=131154&view=rev
Log:
Add TestObjCTypeQueryFromOtherCompileUnit.py to test that when stopped in the 'main.c'
compile unit, which has an external reference to symbols defined in foo.m, the type query:

    in this case, 'expression (NSArray*)array_token'

continues to work.

This test is to accompany http://llvm.org/viewvc/llvm-project?rev=131145&view=rev.

Added:
    lldb/trunk/test/expression_command/two-files/
    lldb/trunk/test/expression_command/two-files/Makefile
    lldb/trunk/test/expression_command/two-files/TestObjCTypeQueryFromOtherCompileUnit.py
    lldb/trunk/test/expression_command/two-files/foo.m
    lldb/trunk/test/expression_command/two-files/main.c
Modified:
    lldb/trunk/test/foundation/Makefile

Added: lldb/trunk/test/expression_command/two-files/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/expression_command/two-files/Makefile?rev=131154&view=auto
==============================================================================
--- lldb/trunk/test/expression_command/two-files/Makefile (added)
+++ lldb/trunk/test/expression_command/two-files/Makefile Tue May 10 16:36:11 2011
@@ -0,0 +1,8 @@
+LEVEL = ../../make
+
+C_SOURCES := main.c
+OBJC_SOURCES := foo.m
+
+include $(LEVEL)/Makefile.rules
+
+LDFLAGS += -framework Foundation
\ No newline at end of file

Added: lldb/trunk/test/expression_command/two-files/TestObjCTypeQueryFromOtherCompileUnit.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/expression_command/two-files/TestObjCTypeQueryFromOtherCompileUnit.py?rev=131154&view=auto
==============================================================================
--- lldb/trunk/test/expression_command/two-files/TestObjCTypeQueryFromOtherCompileUnit.py (added)
+++ lldb/trunk/test/expression_command/two-files/TestObjCTypeQueryFromOtherCompileUnit.py Tue May 10 16:36:11 2011
@@ -0,0 +1,54 @@
+"""
+Regression test for <rdar://problem/8981098>:
+
+The expression parser's type search only looks in the current compilation unit for types.
+"""
+
+import unittest2
+import lldb
+from lldbtest import *
+
+class ObjCTypeQueryTestCase(TestBase):
+
+    mydir = os.path.join("expression_command", "two-files")
+
+    def setUp(self):
+        # Call super's setUp().
+        TestBase.setUp(self)
+        # Find the line number to break for main.c.
+        self.line = line_number('main.c',
+                                "// Set breakpoint here, then do 'expr (NSArray*)array_token'.")
+
+    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+    def test_with_dsym(self):
+        """The expression parser's type search should be wider than the current compilation unit."""
+        self.buildDsym()
+        self.type_query_from_other_cu()
+
+    def test_with_dwarf(self):
+        """The expression parser's type search should be wider than the current compilation unit."""
+        self.buildDwarf()
+        self.type_query_from_other_cu()
+
+    def type_query_from_other_cu(self):
+        """The expression parser's type search should be wider than the current compilation unit."""
+        self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
+
+        self.expect("breakpoint set -f main.c -l %d" % self.line,
+                    BREAKPOINT_CREATED,
+            startstr = "Breakpoint created: 1: file ='main.c', line = %d" %
+                        self.line)
+
+        self.runCmd("run", RUN_SUCCEEDED)
+
+        # Now do a NSArry type query from the 'main.c' compile uint.
+        self.expect("expression (NSArray*)array_token",
+            substrs = ['(NSArray *) $0 ='])
+        # (NSArray *) $0 = 0x00007fff70118398
+
+
+if __name__ == '__main__':
+    import atexit
+    lldb.SBDebugger.Initialize()
+    atexit.register(lambda: lldb.SBDebugger.Terminate())
+    unittest2.main()

Added: lldb/trunk/test/expression_command/two-files/foo.m
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/expression_command/two-files/foo.m?rev=131154&view=auto
==============================================================================
--- lldb/trunk/test/expression_command/two-files/foo.m (added)
+++ lldb/trunk/test/expression_command/two-files/foo.m Tue May 10 16:36:11 2011
@@ -0,0 +1,28 @@
+#import <Foundation/Foundation.h>
+
+NSMutableArray *
+GetArray ()
+{
+  static NSMutableArray *the_array = NULL;
+  if (the_array == NULL)
+    the_array = [[NSMutableArray alloc] init];
+  return the_array;
+}
+
+int 
+AddElement (char *value)
+{
+  NSString *element = [NSString stringWithUTF8String: value];
+  int cur_elem = [GetArray() count];
+  [GetArray() addObject: element];
+  return cur_elem;
+}
+
+const char *
+GetElement (int idx)
+{
+  if (idx >= [GetArray() count])
+    return NULL;
+  else
+    return [[GetArray() objectAtIndex: idx] UTF8String];
+}

Added: lldb/trunk/test/expression_command/two-files/main.c
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/expression_command/two-files/main.c?rev=131154&view=auto
==============================================================================
--- lldb/trunk/test/expression_command/two-files/main.c (added)
+++ lldb/trunk/test/expression_command/two-files/main.c Tue May 10 16:36:11 2011
@@ -0,0 +1,19 @@
+#include <stdio.h>
+
+extern int AddElement (char *value);
+extern char *GetElement (int idx);
+extern void *GetArray();
+
+int
+main ()
+{
+
+  int idx = AddElement ("some string");
+  void *array_token = GetArray();
+
+  char *string = GetElement (0); // Set breakpoint here, then do 'expr (NSArray*)array_token'.
+  if (string)
+    printf ("This: %s.\n", string);
+
+  return 0;
+}  

Modified: lldb/trunk/test/foundation/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/foundation/Makefile?rev=131154&r1=131153&r2=131154&view=diff
==============================================================================
--- lldb/trunk/test/foundation/Makefile (original)
+++ lldb/trunk/test/foundation/Makefile Tue May 10 16:36:11 2011
@@ -3,6 +3,6 @@
 OBJC_SOURCES := main.m my-base.m
 #OBJC_SOURCES := const-strings.m
 
-LDFLAGS = $(CFLAGS) -lobjc -framework Foundation
-
 include $(LEVEL)/Makefile.rules
+
+LDFLAGS += -framework Foundation





More information about the lldb-commits mailing list