[Lldb-commits] [lldb] r136801 - in /lldb/trunk/test/functionalities/load_unload: Makefile TestLoadUnload.py hidden/

Jim Ingham jingham at apple.com
Wed Aug 3 12:32:42 PDT 2011


Author: jingham
Date: Wed Aug  3 14:32:42 2011
New Revision: 136801

URL: http://llvm.org/viewvc/llvm-project?rev=136801&view=rev
Log:
Add a directory to make the second copy of libd.dylib in, so we don't have
to make & delete directories in the test case.  Make a real copy of libd.dylib
in that directory so the two libraries are actually different.  Use (and remove)
the DYLD_LIBRARY_PATH to point to the new library.

Added:
    lldb/trunk/test/functionalities/load_unload/hidden/
Modified:
    lldb/trunk/test/functionalities/load_unload/Makefile
    lldb/trunk/test/functionalities/load_unload/TestLoadUnload.py

Modified: lldb/trunk/test/functionalities/load_unload/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/load_unload/Makefile?rev=136801&r1=136800&r2=136801&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/load_unload/Makefile (original)
+++ lldb/trunk/test/functionalities/load_unload/Makefile Wed Aug  3 14:32:42 2011
@@ -7,12 +7,18 @@
 CFLAGS ?=-arch x86_64 -gdwarf-2 -O0
 CWD := $(shell pwd)
 
+all: a.out hidden/libd.dylib
+
 a.out: main.o libd.dylib
 	$(CC) $(CFLAGS) -o a.out main.o -L. -ld
 
 main.o: main.c
 	$(CC) $(CFLAGS) -c main.c
 
+hidden/libd.dylib: b.o
+	$(CC) $(CFLAGS) -dynamiclib -o hidden/libd.dylib d.o
+	dsymutil -o hidden/libd.dylib.dSYM hidden/libd.dylib
+
 liba.dylib: a.o libb.dylib
 	$(CC) $(CFLAGS) -dynamiclib -install_name "@executable_path/liba.dylib" -o liba.dylib a.o -L. -lb
 	dsymutil liba.dylib
@@ -42,4 +48,4 @@
 	$(CC) $(CFLAGS) -c d.c
 
 clean:
-	rm -rf *.o *~ *.dylib a.out *.dSYM
+	rm -rf *.o *~ *.dylib a.out *.dSYM hidden/*

Modified: lldb/trunk/test/functionalities/load_unload/TestLoadUnload.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/load_unload/TestLoadUnload.py?rev=136801&r1=136800&r2=136801&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/load_unload/TestLoadUnload.py (original)
+++ lldb/trunk/test/functionalities/load_unload/TestLoadUnload.py Wed Aug  3 14:32:42 2011
@@ -23,7 +23,7 @@
 
     @unittest2.expectedFailure
     def test_modules_search_paths(self):
-        """Test target modules list after moving libd.dylib, and verifies that it works with 'target modules search-paths add'."""
+        """Test target modules list after loading a different copy of the library libd.dylib, and verifies that it works with 'target modules search-paths add'."""
 
         # Invoke the default build rule.
         self.buildDefault()
@@ -31,23 +31,12 @@
         if sys.platform.startswith("darwin"):
             dylibName = 'libd.dylib'
 
-        # Now let's move the dynamic library to a different directory than $CWD.
-
-        # The directory to relocate the dynamic library to.
-        new_dir = os.path.join(os.getcwd(), "dyld_path")
-
-        # This is the function to remove the dyld_path directory after the test.
-        def remove_dyld_dir():
-            import shutil
-            shutil.rmtree(new_dir)
+        # The directory with the the dynamic library we did not link to.
+        new_dir = os.path.join(os.getcwd(), "hidden")
 
         old_dylib = os.path.join(os.getcwd(), dylibName)
         new_dylib = os.path.join(new_dir, dylibName)
 
-        os.mkdir(new_dir)
-        os.rename(old_dylib, new_dylib)
-        self.addTearDownHook(remove_dyld_dir)
-
         exe = os.path.join(os.getcwd(), "a.out")
         self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
 
@@ -65,62 +54,64 @@
         self.expect("target modules list", "LLDB successfully locates the relocated dynamic library",
             substrs = [new_dylib])
 
-    @unittest2.skip("debugserver crashes?")
+        
     def test_dyld_library_path(self):
         """Test DYLD_LIBRARY_PATH after moving libd.dylib, which defines d_function, somewhere else."""
 
         # Invoke the default build rule.
         self.buildDefault()
 
+        exe = os.path.join(os.getcwd(), "a.out")
+        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
+
         if sys.platform.startswith("darwin"):
             dylibName = 'libd.dylib'
             dsymName = 'libd.dylib.dSYM'
             dylibPath = 'DYLD_LIBRARY_PATH'
 
-        # Now let's move the dynamic library to a different directory than $CWD.
-
         # The directory to relocate the dynamic library and its debugging info.
-        new_dir = os.path.join(os.getcwd(), "dyld_path")
-
-        # This is the function to remove the dyld_path directory after the test.
-        def remove_dyld_dir():
-            import shutil
-            shutil.rmtree(new_dir)
+        new_dir = os.path.join(os.getcwd(), "hidden")
 
         old_dylib = os.path.join(os.getcwd(), dylibName)
         new_dylib = os.path.join(new_dir, dylibName)
         old_dSYM = os.path.join(os.getcwd(), dsymName)
         new_dSYM = os.path.join(new_dir, dsymName)
-        #system(["ls", "-lR", "."])
-        os.mkdir(new_dir)
-        os.rename(old_dylib, new_dylib)
-        if dsymName:
-            os.rename(old_dSYM, new_dSYM)
-        self.addTearDownHook(remove_dyld_dir)
+
         #system(["ls", "-lR", "."])
 
-        # With libd.dylib moved, a.out run should fail.
-        exe = os.path.join(os.getcwd(), "a.out")
-        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
-        # Set breakpoint by function name d_function.
-        self.expect("breakpoint set -n d_function", BREAKPOINT_CREATED,
-            substrs = ["Breakpoint created",
-                       "name = 'd_function'",
-                       "locations = 0 (pending)"])
-        self.runCmd("run")
-        self.expect("process status", "Not expected to hit the d_function breakpoint",
-                    matching=False,
-            substrs = ["stop reason = breakpoint"])
-        # Kill the inferior process.
-        self.runCmd("process kill")
+        # Try running with the DYLD_LIBRARY_PATH environment variable set, make sure
+        # we pick up the hidden dylib.
 
-        # Try again with the DYLD_LIBRARY_PATH environment variable properly set.
-        env_cmd_string = 'settings set target.process.env-vars ["%s"]=%s' % (dylibPath, new_dir)
+        env_cmd_string = "settings set target.process.env-vars " + dylibPath + "=" + new_dir
+        print "Set environment to: ", env_cmd_string
         self.runCmd(env_cmd_string)
+        self.runCmd("settings show target.process.env-vars")
+
+        remove_dyld_path_cmd = "settings remove target.process.env-vars " + dylibPath
+        self.addTearDownHook(lambda: self.runCmd(remove_dyld_path_cmd))
+
+        self.expect("breakpoint set -f d.c -l %d" % self.line_d_function,
+                    BREAKPOINT_CREATED,
+                    startstr = "Breakpoint created: 1: file ='d.c', line = %d" %
+                        self.line_d_function)
+        # For now we don't track DYLD_LIBRARY_PATH, so the old library will be in
+        # the modules list.
+        self.expect("target modules list",
+            substrs = [old_dylib],
+            matching=True)
+
         self.runCmd("run")
         self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT,
             patterns = ["frame #0.*d_function.*at d.c:%d" % self.line_d_function])
 
+        # After run, make sure the hidden library is present, and the one we didn't 
+        # load is not.
+        self.expect("target modules list",
+            substrs = [new_dylib])
+        self.expect("target modules list",
+            substrs = [old_dylib],
+            matching=False)
+
     def test_lldb_process_load_and_unload_commands(self):
         """Test that lldb process load/unload command work correctly."""
 





More information about the lldb-commits mailing list