From 26ba928214273cba2d1fb951bd395e6fa74896bb Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Thu, 20 Sep 2018 09:09:13 +0000 Subject: [target] Change target create's behavior wrt loading dependent files. When creating a target, lldb loads all dependent files (i.e. libs in LC_LOAD_DYLIB for Mach-O). This can be confusing, especially when two versions of the same library end up in the shared cache. It's possible to change this behavior, by specifying target create -d these dependents are not loaded. This patch changes the default behavior to only load dependent files only when the target is an executable. When creating a target for a library, it is now no longer necessary to pass -d. The user can still override this behavior by specifying the -d option to change this behavior. rdar://problem/43721382 Differential revision: https://reviews.llvm.org/D51934 llvm-svn: 342634 --- .../functionalities/target_create_deps/Makefile | 16 ++++ .../target_create_deps/TestTargetCreateDeps.py | 96 ++++++++++++++++++++++ .../test/functionalities/target_create_deps/a.cpp | 13 +++ .../test/functionalities/target_create_deps/a.mk | 9 ++ .../functionalities/target_create_deps/main.cpp | 17 ++++ 5 files changed, 151 insertions(+) create mode 100644 lldb/packages/Python/lldbsuite/test/functionalities/target_create_deps/Makefile create mode 100644 lldb/packages/Python/lldbsuite/test/functionalities/target_create_deps/TestTargetCreateDeps.py create mode 100644 lldb/packages/Python/lldbsuite/test/functionalities/target_create_deps/a.cpp create mode 100644 lldb/packages/Python/lldbsuite/test/functionalities/target_create_deps/a.mk create mode 100644 lldb/packages/Python/lldbsuite/test/functionalities/target_create_deps/main.cpp (limited to 'lldb/packages/Python/lldbsuite/test/functionalities/target_create_deps') diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/target_create_deps/Makefile b/lldb/packages/Python/lldbsuite/test/functionalities/target_create_deps/Makefile new file mode 100644 index 00000000000..15cb0b64f21 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/functionalities/target_create_deps/Makefile @@ -0,0 +1,16 @@ +LEVEL := ../../make + +LIB_PREFIX := load_ + +LD_EXTRAS := -L. -l$(LIB_PREFIX)a +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules + +a.out: lib_a + +lib_%: + $(MAKE) VPATH=$(SRCDIR) -I $(SRCDIR) -f $(SRCDIR)/$*.mk + +clean:: + $(MAKE) -f $(SRCDIR)/a.mk clean diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/target_create_deps/TestTargetCreateDeps.py b/lldb/packages/Python/lldbsuite/test/functionalities/target_create_deps/TestTargetCreateDeps.py new file mode 100644 index 00000000000..a6886da7c68 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/functionalities/target_create_deps/TestTargetCreateDeps.py @@ -0,0 +1,96 @@ +""" +Test that loading of dependents works correctly for all the potential +combinations. +""" + +from __future__ import print_function + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class TargetDependentsTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + NO_DEBUG_INFO_TESTCASE = True + + def setUp(self): + TestBase.setUp(self) + self.build() + + def has_exactly_one_image(self, matching, msg=""): + self.expect( + "image list", + "image list should contain at least one image", + substrs=['[ 0]']) + should_match = not matching + self.expect( + "image list", msg, matching=should_match, substrs=['[ 1]']) + + def test_dependents_implicit_default_exe(self): + """Test default behavior""" + exe = self.getBuildArtifact("a.out") + self.runCmd("target create " + exe, CURRENT_EXECUTABLE_SET) + self.has_exactly_one_image(False) + + def test_dependents_explicit_default_exe(self): + """Test default behavior""" + exe = self.getBuildArtifact("a.out") + self.runCmd("target create -ddefault " + exe, CURRENT_EXECUTABLE_SET) + self.has_exactly_one_image(False) + + def test_dependents_explicit_true_exe(self): + """Test default behavior""" + exe = self.getBuildArtifact("a.out") + self.runCmd("target create -dtrue " + exe, CURRENT_EXECUTABLE_SET) + self.has_exactly_one_image(True) + + def test_dependents_explicit_false_exe(self): + """Test default behavior""" + exe = self.getBuildArtifact("a.out") + self.runCmd("target create -dfalse " + exe, CURRENT_EXECUTABLE_SET) + self.has_exactly_one_image(False) + + def test_dependents_implicit_false_exe(self): + """Test default behavior""" + exe = self.getBuildArtifact("a.out") + self.runCmd("target create -d " + exe, CURRENT_EXECUTABLE_SET) + self.has_exactly_one_image(True) + + def test_dependents_implicit_default_lib(self): + ctx = self.platformContext + dylibName = ctx.shlib_prefix + 'load_a.' + ctx.shlib_extension + lib = self.getBuildArtifact(dylibName) + self.runCmd("target create " + lib, CURRENT_EXECUTABLE_SET) + self.has_exactly_one_image(True) + + def test_dependents_explicit_default_lib(self): + ctx = self.platformContext + dylibName = ctx.shlib_prefix + 'load_a.' + ctx.shlib_extension + lib = self.getBuildArtifact(dylibName) + self.runCmd("target create -ddefault " + lib, CURRENT_EXECUTABLE_SET) + self.has_exactly_one_image(True) + + def test_dependents_explicit_true_lib(self): + ctx = self.platformContext + dylibName = ctx.shlib_prefix + 'load_a.' + ctx.shlib_extension + lib = self.getBuildArtifact(dylibName) + self.runCmd("target create -dtrue " + lib, CURRENT_EXECUTABLE_SET) + self.has_exactly_one_image(True) + + def test_dependents_explicit_false_lib(self): + ctx = self.platformContext + dylibName = ctx.shlib_prefix + 'load_a.' + ctx.shlib_extension + lib = self.getBuildArtifact(dylibName) + self.runCmd("target create -dfalse " + lib, CURRENT_EXECUTABLE_SET) + self.has_exactly_one_image(False) + + def test_dependents_implicit_false_lib(self): + ctx = self.platformContext + dylibName = ctx.shlib_prefix + 'load_a.' + ctx.shlib_extension + lib = self.getBuildArtifact(dylibName) + self.runCmd("target create -d " + lib, CURRENT_EXECUTABLE_SET) + self.has_exactly_one_image(True) diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/target_create_deps/a.cpp b/lldb/packages/Python/lldbsuite/test/functionalities/target_create_deps/a.cpp new file mode 100644 index 00000000000..c0dac40d0ee --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/functionalities/target_create_deps/a.cpp @@ -0,0 +1,13 @@ +//===-- b.c -----------------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int a_function () +{ + return 500; +} diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/target_create_deps/a.mk b/lldb/packages/Python/lldbsuite/test/functionalities/target_create_deps/a.mk new file mode 100644 index 00000000000..f199bfed5b0 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/functionalities/target_create_deps/a.mk @@ -0,0 +1,9 @@ +LEVEL := ../../make + +LIB_PREFIX := load_ + +DYLIB_NAME := $(LIB_PREFIX)a +DYLIB_CXX_SOURCES := a.cpp +DYLIB_ONLY := YES + +include $(LEVEL)/Makefile.rules diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/target_create_deps/main.cpp b/lldb/packages/Python/lldbsuite/test/functionalities/target_create_deps/main.cpp new file mode 100644 index 00000000000..08fbb59d8a5 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/functionalities/target_create_deps/main.cpp @@ -0,0 +1,17 @@ +//===-- main.c --------------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +extern int a_function (); +extern int b_function (); + +int +main (int argc, char const *argv[]) +{ + return a_function(); +} -- cgit v1.2.3