summaryrefslogtreecommitdiffstats
path: root/lldb/packages/Python/lldbsuite/test/functionalities/load_using_paths
diff options
context:
space:
mode:
authorJim Ingham <jingham@apple.com>2018-06-28 20:02:11 +0000
committerJim Ingham <jingham@apple.com>2018-06-28 20:02:11 +0000
commit0d231f7161272cb46e1ea04326da1cbdfec06923 (patch)
tree46677075abea44f0990f019434e669c4f3d47a6d /lldb/packages/Python/lldbsuite/test/functionalities/load_using_paths
parent3cabf73270c450050d7d07be8f80cb97600d5af3 (diff)
downloadbcm5719-llvm-0d231f7161272cb46e1ea04326da1cbdfec06923.tar.gz
bcm5719-llvm-0d231f7161272cb46e1ea04326da1cbdfec06923.zip
Add a way to load an image using a library name and list of paths.
This provides an efficient (at least on Posix platforms) way to offload to the target process the search & loading of a library when all we have are the library name and a set of potential candidate locations. <rdar://problem/40905971> llvm-svn: 335912
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test/functionalities/load_using_paths')
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/load_using_paths/.categories1
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/load_using_paths/Makefile13
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/load_using_paths/TestLoadUsingPaths.py126
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/load_using_paths/hidden/Makefile7
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/load_using_paths/hidden/d.cpp21
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/load_using_paths/main.cpp16
6 files changed, 184 insertions, 0 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/load_using_paths/.categories b/lldb/packages/Python/lldbsuite/test/functionalities/load_using_paths/.categories
new file mode 100644
index 00000000000..c00c25822e4
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/load_using_paths/.categories
@@ -0,0 +1 @@
+basic_process
diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/load_using_paths/Makefile b/lldb/packages/Python/lldbsuite/test/functionalities/load_using_paths/Makefile
new file mode 100644
index 00000000000..5ec8f23a1cb
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/load_using_paths/Makefile
@@ -0,0 +1,13 @@
+LEVEL := ../../make
+
+CXX_SOURCES := main.cpp
+
+include $(LEVEL)/Makefile.rules
+
+all: hidden_lib a.out
+
+hidden_lib:
+ $(MAKE) VPATH=$(SRCDIR)/hidden -I $(SRCDIR)/hidden -C hidden -f $(SRCDIR)/hidden/Makefile
+
+clean::
+ $(MAKE) -I $(SRCDIR)/hidden -C hidden -f $(SRCDIR)/hidden/Makefile clean
diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/load_using_paths/TestLoadUsingPaths.py b/lldb/packages/Python/lldbsuite/test/functionalities/load_using_paths/TestLoadUsingPaths.py
new file mode 100644
index 00000000000..ba85039be8b
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/load_using_paths/TestLoadUsingPaths.py
@@ -0,0 +1,126 @@
+"""
+Test that SBProcess.LoadImageUsingPaths works correctly.
+"""
+
+from __future__ import print_function
+
+
+import os
+import time
+import re
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+@skipIfWindows # The Windows platform doesn't implement DoLoadImage.
+class LoadUsingPathsTestCase(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ NO_DEBUG_INFO_TESTCASE = True
+
+ def setUp(self):
+ # Call super's setUp().
+ TestBase.setUp(self)
+ # Make the hidden directory in the build hierarchy:
+ lldbutil.mkdir_p(self.getBuildArtifact("hidden"))
+
+ # Invoke the default build rule.
+ self.build()
+
+ ext = 'so'
+ if self.platformIsDarwin():
+ ext = 'dylib'
+ self.lib_name = 'libloadunload.' + ext
+
+ self.wd = self.getBuildDir()
+ self.hidden_dir = os.path.join(self.wd, 'hidden')
+ self.hidden_lib = os.path.join(self.hidden_dir, self.lib_name)
+
+ @skipIfFreeBSD # llvm.org/pr14424 - missing FreeBSD Makefiles/testcase support
+ @not_remote_testsuite_ready
+ @skipIfWindows # Windows doesn't have dlopen and friends, dynamic libraries work differently
+ def test_load_using_paths(self):
+ """Test that we can load a module by providing a set of search paths."""
+ if self.platformIsDarwin():
+ dylibName = 'libloadunload_d.dylib'
+ else:
+ dylibName = 'libloadunload_d.so'
+
+ # The directory with the dynamic library we did not link to.
+ path_dir = os.path.join(self.getBuildDir(), "hidden")
+
+ (target, process, thread,
+ _) = lldbutil.run_to_source_breakpoint(self,
+ "Break here to do the load using paths",
+ lldb.SBFileSpec("main.cpp"))
+ error = lldb.SBError()
+ lib_spec = lldb.SBFileSpec(self.lib_name)
+ paths = lldb.SBStringList()
+ paths.AppendString(self.wd)
+ paths.AppendString(os.path.join(self.wd, "no_such_dir"))
+
+ out_spec = lldb.SBFileSpec()
+
+ # First try with no correct directories on the path, and make sure that doesn't blow up:
+ token = process.LoadImageUsingPaths(lib_spec, paths, out_spec, error)
+ self.assertEqual(token, lldb.LLDB_INVALID_IMAGE_TOKEN, "Only looked on the provided path.")
+
+ # Now add the correct dir to the paths list and try again:
+ paths.AppendString(self.hidden_dir)
+ token = process.LoadImageUsingPaths(lib_spec, paths, out_spec, error)
+
+ self.assertNotEqual(token, lldb.LLDB_INVALID_IMAGE_TOKEN, "Got a valid token")
+ self.assertEqual(out_spec, lldb.SBFileSpec(self.hidden_lib), "Found the expected library")
+
+ # Make sure this really is in the image list:
+ loaded_module = target.FindModule(out_spec)
+
+ self.assertTrue(loaded_module.IsValid(), "The loaded module is in the image list.")
+
+ # Now see that we can call a function in the loaded module.
+ value = thread.frames[0].EvaluateExpression("d_function()", lldb.SBExpressionOptions())
+ self.assertTrue(value.GetError().Success(), "Got a value from the expression")
+ ret_val = value.GetValueAsSigned()
+ self.assertEqual(ret_val, 12345, "Got the right value")
+
+ # Make sure the token works to unload it:
+ process.UnloadImage(token)
+
+ # Make sure this really is no longer in the image list:
+ loaded_module = target.FindModule(out_spec)
+
+ self.assertFalse(loaded_module.IsValid(), "The unloaded module is no longer in the image list.")
+
+ # Make sure a relative path also works:
+ paths.Clear()
+ paths.AppendString(os.path.join(self.wd, "no_such_dir"))
+ paths.AppendString(self.wd)
+ relative_spec = lldb.SBFileSpec(os.path.join("hidden", self.lib_name))
+
+ out_spec = lldb.SBFileSpec()
+ token = process.LoadImageUsingPaths(relative_spec, paths, out_spec, error)
+
+ self.assertNotEqual(token, lldb.LLDB_INVALID_IMAGE_TOKEN, "Got a valid token")
+ self.assertEqual(out_spec, lldb.SBFileSpec(self.hidden_lib), "Found the expected library")
+
+ process.UnloadImage(token)
+
+ # Finally, passing in an absolute path should work like the basename:
+ # This should NOT work because we've taken hidden_dir off the paths:
+ abs_spec = lldb.SBFileSpec(os.path.join(self.hidden_dir, self.lib_name))
+
+ token = process.LoadImageUsingPaths(lib_spec, paths, out_spec, error)
+ self.assertEqual(token, lldb.LLDB_INVALID_IMAGE_TOKEN, "Only looked on the provided path.")
+
+ # But it should work when we add the dir:
+ # Now add the correct dir to the paths list and try again:
+ paths.AppendString(self.hidden_dir)
+ token = process.LoadImageUsingPaths(lib_spec, paths, out_spec, error)
+
+ self.assertNotEqual(token, lldb.LLDB_INVALID_IMAGE_TOKEN, "Got a valid token")
+ self.assertEqual(out_spec, lldb.SBFileSpec(self.hidden_lib), "Found the expected library")
+
+
diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/load_using_paths/hidden/Makefile b/lldb/packages/Python/lldbsuite/test/functionalities/load_using_paths/hidden/Makefile
new file mode 100644
index 00000000000..bebfa92ecfb
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/load_using_paths/hidden/Makefile
@@ -0,0 +1,7 @@
+LEVEL := ../../../make
+
+DYLIB_NAME := loadunload
+DYLIB_CXX_SOURCES := d.cpp
+DYLIB_ONLY := YES
+
+include $(LEVEL)/Makefile.rules
diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/load_using_paths/hidden/d.cpp b/lldb/packages/Python/lldbsuite/test/functionalities/load_using_paths/hidden/d.cpp
new file mode 100644
index 00000000000..6a7642c08b9
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/load_using_paths/hidden/d.cpp
@@ -0,0 +1,21 @@
+//===-- c.c -----------------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+int d_init()
+{
+ return 456;
+}
+
+int d_global = d_init();
+
+int
+d_function ()
+{ // Find this line number within d_dunction().
+ return 12345;
+}
diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/load_using_paths/main.cpp b/lldb/packages/Python/lldbsuite/test/functionalities/load_using_paths/main.cpp
new file mode 100644
index 00000000000..4b3320479c2
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/load_using_paths/main.cpp
@@ -0,0 +1,16 @@
+//===-- main.c --------------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+#include <stdio.h>
+
+int
+main (int argc, char const *argv[])
+{
+ printf("Break here to do the load using paths.");
+ return 0;
+}
OpenPOWER on IntegriCloud