From 7791b3320bcd7aff800fc436b62bceb52b584259 Mon Sep 17 00:00:00 2001 From: Johnny Chen Date: Thu, 3 Feb 2011 00:30:19 +0000 Subject: [PATCH] Add a test case test_image_search_paths() to test lldb's ability to do image search paths substitutions in order to achieve file mappings. Modify CommandObjectTarget.cpp to properly set the status of the return object to make scripting like this: self.runCmd("target image-search-paths add %s %s" % (os.getcwd(), new_dir)) works. llvm-svn: 124762 --- lldb/source/Commands/CommandObjectTarget.cpp | 6 ++++ lldb/test/load_unload/TestLoadUnload.py | 35 ++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp index ecbbb729047a..01bdfa9a2610 100644 --- a/lldb/source/Commands/CommandObjectTarget.cpp +++ b/lldb/source/Commands/CommandObjectTarget.cpp @@ -92,6 +92,7 @@ public: target->GetImageSearchPathList().Append (ConstString(from), ConstString(to), last_pair); // Notify if this is the last pair + result.SetStatus (eReturnStatusSuccessFinishNoResult); } else { @@ -138,6 +139,7 @@ public: { bool notify = true; target->GetImageSearchPathList().Clear(notify); + result.SetStatus (eReturnStatusSuccessFinishNoResult); } else { @@ -233,6 +235,7 @@ public: ConstString(to), insert_idx, last_pair); + result.SetStatus (eReturnStatusSuccessFinishNoResult); } else { @@ -293,6 +296,7 @@ public: } target->GetImageSearchPathList().Dump(&result.GetOutputStream()); + result.SetStatus (eReturnStatusSuccessFinishResult); } else { @@ -351,6 +355,8 @@ public: result.GetOutputStream().Printf("%s\n", transformed.GetCString()); else result.GetOutputStream().Printf("%s\n", orig.GetCString()); + + result.SetStatus (eReturnStatusSuccessFinishResult); } else { diff --git a/lldb/test/load_unload/TestLoadUnload.py b/lldb/test/load_unload/TestLoadUnload.py index 98487d880fe8..f4db75c961f2 100644 --- a/lldb/test/load_unload/TestLoadUnload.py +++ b/lldb/test/load_unload/TestLoadUnload.py @@ -21,6 +21,41 @@ class LoadUnloadTestCase(TestBase): self.line_d_function = line_number('d.c', '// Find this line number within d_dunction().') + def test_image_search_paths(self): + """Test image list after moving libd.dylib, and verifies that it works with 'target image-search-paths add'.""" + + # Invoke the default build rule. + self.buildDefault() + + 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) + + 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) + self.expect("image list", + substrs = [old_dylib]) + self.runCmd("target image-search-paths add %s %s" % (os.getcwd(), new_dir)) + self.expect("image list", "LLDB successfully locates the relocated dynamic library", + substrs = [new_dylib]) + + def test_dyld_library_path(self): """Test DYLD_LIBRARY_PATH after moving libd.dylib, which defines d_function, somewhere else."""