[Lldb-commits] [lldb] 8bac18b - [lldb] Reduce code duplication around inferior building
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Tue Oct 19 03:09:54 PDT 2021
Author: Pavel Labath
Date: 2021-10-19T12:09:41+02:00
New Revision: 8bac18be0e45adc7b096375bf4f65635fb994df0
URL: https://github.com/llvm/llvm-project/commit/8bac18be0e45adc7b096375bf4f65635fb994df0
DIFF: https://github.com/llvm/llvm-project/commit/8bac18be0e45adc7b096375bf4f65635fb994df0.diff
LOG: [lldb] Reduce code duplication around inferior building
We had two sets of build<flavour> methods, whose bodies were largely
identical. This makes any kind of modification in their vicinity
repetitive and error-prone.
Replace each set with a single method taking an optional debug_info
parameter.
Differential Revision: https://reviews.llvm.org/D111989
Added:
Modified:
lldb/docs/testsuite/a-detailed-walkthrough.txt
lldb/packages/Python/lldbsuite/test/README-TestSuite
lldb/packages/Python/lldbsuite/test/builders/builder.py
lldb/packages/Python/lldbsuite/test/builders/darwin.py
lldb/packages/Python/lldbsuite/test/lldbtest.py
lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py
lldb/test/API/commands/add-dsym/uuid/TestAddDsymCommand.py
lldb/test/API/functionalities/breakpoint/comp_dir_symlink/TestCompDirSymLink.py
lldb/test/API/macosx/add-dsym/TestAddDsymDownload.py
lldb/test/API/macosx/add-dsym/TestAddDsymMidExecutionCommand.py
Removed:
################################################################################
diff --git a/lldb/docs/testsuite/a-detailed-walkthrough.txt b/lldb/docs/testsuite/a-detailed-walkthrough.txt
index fff5a40d1da77..8d374d5d81ea0 100644
--- a/lldb/docs/testsuite/a-detailed-walkthrough.txt
+++ b/lldb/docs/testsuite/a-detailed-walkthrough.txt
@@ -73,7 +73,7 @@ Now let's look inside the test method:
def test_set_output_path(self):
"""Test that setting target.process.output-path for the launched process works."""
- self.buildDefault()
+ self.build()
exe = os.path.join(os.getcwd(), "a.out")
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
@@ -96,49 +96,12 @@ Now let's look inside the test method:
self.expect(output, exe=False,
startstr = "This message should go to standard out.")
-The self.buildDefault() statement is used to build a default binary for this
-test instance. For this particular test case, since we don't really care what
-debugging format is used, we instruct the build subsystem to build the default
-binary for us. The base class TestBase has defined three instance methods:
-
- def buildDefault(self, architecture=None, compiler=None, dictionary=None):
- """Platform specific way to build the default binaries."""
- module = __import__(sys.platform)
- if not module.buildDefault(self, architecture, compiler, dictionary):
- raise Exception("Don't know how to build default binary")
-
- def buildDsym(self, architecture=None, compiler=None, dictionary=None):
- """Platform specific way to build binaries with dsym info."""
- module = __import__(sys.platform)
- if not module.buildDsym(self, architecture, compiler, dictionary):
- raise Exception("Don't know how to build binary with dsym")
-
- def buildDwarf(self, architecture=None, compiler=None, dictionary=None):
- """Platform specific way to build binaries with dwarf maps."""
- module = __import__(sys.platform)
- if not module.buildDwarf(self, architecture, compiler, dictionary):
- raise Exception("Don't know how to build binary with dwarf")
-
-And the test/plugins/darwin.py provides the implementation for all three build
-methods using the makefile mechanism. We envision that linux plugin can use a
-similar approach to accomplish the task of building the binaries.
-
-macOS provides an additional way to manipulate archived DWARF debug symbol
-files and produces dSYM files. The buildDsym() instance method is used by the
-test method to build the binary with dsym info. For an example of this,
-see test/array_types/TestArrayTypes.py:
-
- @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
- def test_with_dsym_and_run_command(self):
- """Test 'frame variable var_name' on some variables with array types."""
- self.buildDsym()
- self.array_types()
-
-This method is decorated with a skipUnless decorator so that it will only gets
-included into the test suite if the platform it is running on is 'darwin', a.k.a.
-macOS.
-
-Type 'man dsymutil' for more details.
+The self.build() statement is used to build a binary for this
+test instance. This will build the binary for the current debug info format. If
+we wanted to avoid running the test for every supported debug info format we
+could annotate it with @no_debug_info_test. The test would then only be run for
+the default format. The logic for building a test binary resides in the builder
+modules (packages/Python/lldbsuite/test/builders/builder.py)
After the binary is built, it is time to specify the file to be used as the main
executable by lldb:
diff --git a/lldb/packages/Python/lldbsuite/test/README-TestSuite b/lldb/packages/Python/lldbsuite/test/README-TestSuite
index 8ea64c0aa3d56..b29b5a3320cf3 100644
--- a/lldb/packages/Python/lldbsuite/test/README-TestSuite
+++ b/lldb/packages/Python/lldbsuite/test/README-TestSuite
@@ -69,19 +69,12 @@ to the Python test suite under the current 'test' directory.
Python test script. An example of the latter can be found in
test/lang/objc/radar-9691614/TestObjCMethodReturningBOOL.py, where:
- def test_method_ret_BOOL_with_dsym(self):
+ def test_method_ret_BOOL(self):
"""Test that objective-c method returning BOOL works correctly."""
d = {'EXE': self.exe_name}
- self.buildDsym(dictionary=d)
+ self.build(dictionary=d)
self.setTearDownCleanup(dictionary=d)
- self.objc_method_ret_BOOL(self.exe_name)
-
- def test_method_ret_BOOL_with_dwarf(self):
- """Test that objective-c method returning BOOL works correctly."""
- d = {'EXE': self.exe_name}
- self.buildDwarf(dictionary=d)
- self.setTearDownCleanup(dictionary=d)
- self.objc_method_ret_BOOL(self.exe_name)
+ ...
def setUp(self):
# Call super's setUp().
diff --git a/lldb/packages/Python/lldbsuite/test/builders/builder.py b/lldb/packages/Python/lldbsuite/test/builders/builder.py
index 6c9584224f4a9..b49c6324c8ca8 100644
--- a/lldb/packages/Python/lldbsuite/test/builders/builder.py
+++ b/lldb/packages/Python/lldbsuite/test/builders/builder.py
@@ -127,94 +127,27 @@ def getModuleCacheSpec(self):
configuration.clang_module_cache_dir)
return ""
- def buildDefault(self,
- sender=None,
- architecture=None,
- compiler=None,
- dictionary=None,
- testdir=None,
- testname=None):
- """Build the binaries the default way."""
- commands = []
- commands.append(
- self.getMake(testdir, testname) + [
- "all",
- self.getArchCFlags(architecture),
- self.getArchSpec(architecture),
- self.getCCSpec(compiler),
- self.getExtraMakeArgs(),
- self.getSDKRootSpec(),
- self.getModuleCacheSpec(),
- self.getCmdLine(dictionary)
- ])
+ def _getDebugInfoArgs(self, debug_info):
+ if debug_info is None:
+ return []
+ if debug_info == "dwarf":
+ return ["MAKE_DSYM=NO"]
+ if debug_info == "dwo":
+ return ["MAKE_DSYM=NO", "MAKE_DWO=YES"]
+ if debug_info == "gmodules":
+ return ["MAKE_DSYM=NO", "MAKE_GMODULES=YES"]
+ return None
+
+ def build(self, debug_info, sender=None, architecture=None, compiler=None,
+ dictionary=None, testdir=None, testname=None):
+ debug_info_args = self._getDebugInfoArgs(debug_info)
+ if debug_info_args is None:
+ return False
- self.runBuildCommands(commands, sender=sender)
-
- # True signifies that we can handle building default.
- return True
-
- def buildDwarf(self,
- sender=None,
- architecture=None,
- compiler=None,
- dictionary=None,
- testdir=None,
- testname=None):
- """Build the binaries with dwarf debug info."""
commands = []
commands.append(
- self.getMake(testdir, testname) + [
- "MAKE_DSYM=NO",
- self.getArchCFlags(architecture),
- self.getArchSpec(architecture),
- self.getCCSpec(compiler),
- self.getExtraMakeArgs(),
- self.getSDKRootSpec(),
- self.getModuleCacheSpec(),
- self.getCmdLine(dictionary)
- ])
-
- self.runBuildCommands(commands, sender=sender)
- # True signifies that we can handle building dwarf.
- return True
-
- def buildDwo(self,
- sender=None,
- architecture=None,
- compiler=None,
- dictionary=None,
- testdir=None,
- testname=None):
- """Build the binaries with dwarf debug info."""
- commands = []
- commands.append(
- self.getMake(testdir, testname) + [
- "MAKE_DSYM=NO", "MAKE_DWO=YES",
- self.getArchCFlags(architecture),
- self.getArchSpec(architecture),
- self.getCCSpec(compiler),
- self.getExtraMakeArgs(),
- self.getSDKRootSpec(),
- self.getModuleCacheSpec(),
- self.getCmdLine(dictionary)
- ])
-
- self.runBuildCommands(commands, sender=sender)
- # True signifies that we can handle building dwo.
- return True
-
- def buildGModules(self,
- sender=None,
- architecture=None,
- compiler=None,
- dictionary=None,
- testdir=None,
- testname=None):
- """Build the binaries with dwarf debug info."""
- commands = []
- commands.append(
- self.getMake(testdir, testname) + [
- "MAKE_DSYM=NO", "MAKE_GMODULES=YES",
+ self.getMake(testdir, testname) + debug_info_args + [
+ "all",
self.getArchCFlags(architecture),
self.getArchSpec(architecture),
self.getCCSpec(compiler),
@@ -225,19 +158,8 @@ def buildGModules(self,
])
self.runBuildCommands(commands, sender=sender)
- # True signifies that we can handle building with gmodules.
return True
- def buildDsym(self,
- sender=None,
- architecture=None,
- compiler=None,
- dictionary=None,
- testdir=None,
- testname=None):
- # False signifies that we cannot handle building with dSYM.
- return False
-
def cleanup(self, sender=None, dictionary=None):
"""Perform a platform-specific cleanup after the test."""
return True
diff --git a/lldb/packages/Python/lldbsuite/test/builders/darwin.py b/lldb/packages/Python/lldbsuite/test/builders/darwin.py
index 4cd31a6a8033f..9fbd344824226 100644
--- a/lldb/packages/Python/lldbsuite/test/builders/darwin.py
+++ b/lldb/packages/Python/lldbsuite/test/builders/darwin.py
@@ -103,28 +103,7 @@ def getArchCFlags(self, arch):
return "ARCH_CFLAGS=\"-target {} {}\"".format(triple, version_min)
- def buildDsym(self,
- sender=None,
- architecture=None,
- compiler=None,
- dictionary=None,
- testdir=None,
- testname=None):
- """Build the binaries with dsym debug info."""
- commands = []
- commands.append(
- self.getMake(testdir, testname) + [
- "MAKE_DSYM=YES",
- self.getArchCFlags(architecture),
- self.getArchSpec(architecture),
- self.getCCSpec(compiler),
- self.getExtraMakeArgs(),
- self.getSDKRootSpec(),
- self.getModuleCacheSpec(), "all",
- self.getCmdLine(dictionary)
- ])
-
- self.runBuildCommands(commands, sender=sender)
-
- # True signifies that we can handle building dsym.
- return True
+ def _getDebugInfoArgs(self, debug_info):
+ if debug_info == "dsym":
+ return ["MAKE_DSYM=YES"]
+ return super(BuilderDarwin, self)._getDebugInfoArgs(debug_info)
diff --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py b/lldb/packages/Python/lldbsuite/test/lldbtest.py
index d32b960ecd492..c2d4f47d0a86f 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -1454,6 +1454,29 @@ def getDebugInfo(self):
method = getattr(self, self.testMethodName)
return getattr(method, "debug_info", None)
+ def build(
+ self,
+ debug_info=None,
+ architecture=None,
+ compiler=None,
+ dictionary=None):
+ """Platform specific way to build binaries."""
+ if not architecture and configuration.arch:
+ architecture = configuration.arch
+
+ if debug_info is None:
+ debug_info = self.getDebugInfo()
+
+ dictionary = lldbplatformutil.finalize_build_dictionary(dictionary)
+
+ testdir = self.mydir
+ testname = self.getBuildDirBasename()
+
+ module = builder_module()
+ if not module.build(debug_info, self, architecture, compiler,
+ dictionary, testdir, testname):
+ raise Exception("Don't know how to build binary")
+
# ==================================================
# Build methods supported through a plugin interface
# ==================================================
@@ -1514,7 +1537,7 @@ def buildDriver(self, sources, exe_name):
"Building LLDB Driver (%s) from sources %s" %
(exe_name, sources))
- self.buildDefault(dictionary=d)
+ self.build(dictionary=d)
def buildLibrary(self, sources, lib_name):
"""Platform specific way to build a default library. """
@@ -1552,101 +1575,13 @@ def buildLibrary(self, sources, lib_name):
"Building LLDB Library (%s) from sources %s" %
(lib_name, sources))
- self.buildDefault(dictionary=d)
+ self.build(dictionary=d)
def buildProgram(self, sources, exe_name):
""" Platform specific way to build an executable from C/C++ sources. """
d = {'CXX_SOURCES': sources,
'EXE': exe_name}
- self.buildDefault(dictionary=d)
-
- def buildDefault(
- self,
- architecture=None,
- compiler=None,
- dictionary=None):
- """Platform specific way to build the default binaries."""
- testdir = self.mydir
- testname = self.getBuildDirBasename()
-
- if not architecture and configuration.arch:
- architecture = configuration.arch
-
- if self.getDebugInfo():
- raise Exception("buildDefault tests must set NO_DEBUG_INFO_TESTCASE")
- module = builder_module()
- dictionary = lldbplatformutil.finalize_build_dictionary(dictionary)
- if not module.buildDefault(self, architecture, compiler,
- dictionary, testdir, testname):
- raise Exception("Don't know how to build default binary")
-
- def buildDsym(
- self,
- architecture=None,
- compiler=None,
- dictionary=None):
- """Platform specific way to build binaries with dsym info."""
- testdir = self.mydir
- testname = self.getBuildDirBasename()
- if self.getDebugInfo() != "dsym":
- raise Exception("NO_DEBUG_INFO_TESTCASE must build with buildDefault")
-
- module = builder_module()
- dictionary = lldbplatformutil.finalize_build_dictionary(dictionary)
- if not module.buildDsym(self, architecture, compiler,
- dictionary, testdir, testname):
- raise Exception("Don't know how to build binary with dsym")
-
- def buildDwarf(
- self,
- architecture=None,
- compiler=None,
- dictionary=None):
- """Platform specific way to build binaries with dwarf maps."""
- testdir = self.mydir
- testname = self.getBuildDirBasename()
- if self.getDebugInfo() != "dwarf":
- raise Exception("NO_DEBUG_INFO_TESTCASE must build with buildDefault")
-
- module = builder_module()
- dictionary = lldbplatformutil.finalize_build_dictionary(dictionary)
- if not module.buildDwarf(self, architecture, compiler,
- dictionary, testdir, testname):
- raise Exception("Don't know how to build binary with dwarf")
-
- def buildDwo(
- self,
- architecture=None,
- compiler=None,
- dictionary=None):
- """Platform specific way to build binaries with dwarf maps."""
- testdir = self.mydir
- testname = self.getBuildDirBasename()
- if self.getDebugInfo() != "dwo":
- raise Exception("NO_DEBUG_INFO_TESTCASE must build with buildDefault")
-
- module = builder_module()
- dictionary = lldbplatformutil.finalize_build_dictionary(dictionary)
- if not module.buildDwo(self, architecture, compiler,
- dictionary, testdir, testname):
- raise Exception("Don't know how to build binary with dwo")
-
- def buildGModules(
- self,
- architecture=None,
- compiler=None,
- dictionary=None):
- """Platform specific way to build binaries with gmodules info."""
- testdir = self.mydir
- testname = self.getBuildDirBasename()
- if self.getDebugInfo() != "gmodules":
- raise Exception("NO_DEBUG_INFO_TESTCASE must build with buildDefault")
-
- module = builder_module()
- dictionary = lldbplatformutil.finalize_build_dictionary(dictionary)
- if not module.buildGModules(self, architecture, compiler,
- dictionary, testdir, testname):
- raise Exception("Don't know how to build binary with gmodules")
+ self.build(dictionary=d)
def signBinary(self, binary_path):
if sys.platform.startswith("darwin"):
@@ -1888,10 +1823,10 @@ class TestBase(Base):
expect method also provides a mode to peform string/pattern matching
without running a command.
- - The build methods buildDefault, buildDsym, and buildDwarf are used to
- build the binaries used during a particular test scenario. A plugin
- should be provided for the sys.platform running the test suite. The
- Mac OS X implementation is located in builders/darwin.py.
+ - The build method is used to build the binaries used during a
+ particular test scenario. A plugin should be provided for the
+ sys.platform running the test suite. The Mac OS X implementation is
+ located in builders/darwin.py.
"""
# Subclasses can set this to true (if they don't depend on debug info) to avoid running the
@@ -2614,31 +2549,6 @@ def expect_var_path(
value_check.check_value(self, eval_result, str(eval_result))
return eval_result
- def build(
- self,
- architecture=None,
- compiler=None,
- dictionary=None):
- """Platform specific way to build the default binaries."""
- module = builder_module()
-
- if not architecture and configuration.arch:
- architecture = configuration.arch
-
- dictionary = lldbplatformutil.finalize_build_dictionary(dictionary)
- if self.getDebugInfo() is None:
- return self.buildDefault(architecture, compiler, dictionary)
- elif self.getDebugInfo() == "dsym":
- return self.buildDsym(architecture, compiler, dictionary)
- elif self.getDebugInfo() == "dwarf":
- return self.buildDwarf(architecture, compiler, dictionary)
- elif self.getDebugInfo() == "dwo":
- return self.buildDwo(architecture, compiler, dictionary)
- elif self.getDebugInfo() == "gmodules":
- return self.buildGModules(architecture, compiler, dictionary)
- else:
- self.fail("Can't build for debug info: %s" % self.getDebugInfo())
-
"""Assert that an lldb.SBError is in the "success" state."""
def assertSuccess(self, obj, msg=None):
if not obj.Success():
diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py
index fd157a4b5c675..1aaba6fcfb7fb 100644
--- a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py
+++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py
@@ -162,9 +162,6 @@ def tearDown(self):
self._verbose_log_handler = None
TestBase.tearDown(self)
- def build(self, *args, **kwargs):
- self.buildDefault(*args, **kwargs)
-
def getLocalServerLogFile(self):
return self.getLogBasenameForCurrentTest() + "-server.log"
diff --git a/lldb/test/API/commands/add-dsym/uuid/TestAddDsymCommand.py b/lldb/test/API/commands/add-dsym/uuid/TestAddDsymCommand.py
index 8a0fe377f268e..803f44a5dfded 100644
--- a/lldb/test/API/commands/add-dsym/uuid/TestAddDsymCommand.py
+++ b/lldb/test/API/commands/add-dsym/uuid/TestAddDsymCommand.py
@@ -27,14 +27,14 @@ def test_add_dsym_command_with_error(self):
# Call the program generator to produce main.cpp, version 1.
self.generate_main_cpp(version=1)
- self.buildDefault(dictionary={'MAKE_DSYM':'YES'})
+ self.build(debug_info="dsym")
# Insert some delay and then call the program generator to produce
# main.cpp, version 2.
time.sleep(5)
self.generate_main_cpp(version=101)
# Now call make again, but this time don't generate the dSYM.
- self.buildDefault(dictionary={'MAKE_DSYM':'NO'})
+ self.build(debug_info="dwarf")
self.exe_name = 'a.out'
self.do_add_dsym_with_error(self.exe_name)
@@ -45,7 +45,7 @@ def test_add_dsym_command_with_success(self):
# Call the program generator to produce main.cpp, version 1.
self.generate_main_cpp(version=1)
- self.buildDefault(dictionary={'MAKE_DSYM':'YES'})
+ self.build(debug_info="dsym")
self.exe_name = 'a.out'
self.do_add_dsym_with_success(self.exe_name)
@@ -56,7 +56,7 @@ def test_add_dsym_with_dSYM_bundle(self):
# Call the program generator to produce main.cpp, version 1.
self.generate_main_cpp(version=1)
- self.buildDefault(dictionary={'MAKE_DSYM':'YES'})
+ self.build(debug_info="dsym")
self.exe_name = 'a.out'
self.do_add_dsym_with_dSYM_bundle(self.exe_name)
diff --git a/lldb/test/API/functionalities/breakpoint/comp_dir_symlink/TestCompDirSymLink.py b/lldb/test/API/functionalities/breakpoint/comp_dir_symlink/TestCompDirSymLink.py
index 7735bdaf459ca..a5605aebe192b 100644
--- a/lldb/test/API/functionalities/breakpoint/comp_dir_symlink/TestCompDirSymLink.py
+++ b/lldb/test/API/functionalities/breakpoint/comp_dir_symlink/TestCompDirSymLink.py
@@ -77,7 +77,7 @@ def create_src_symlink(self):
return pwd_symlink
def doBuild(self, pwd_symlink, setting_value):
- self.build(None, None, {'PWD': pwd_symlink})
+ self.build(dictionary={'PWD': pwd_symlink})
if setting_value:
cmd = "settings set %s '%s'" % (_COMP_DIR_SYM_LINK_PROP, setting_value)
diff --git a/lldb/test/API/macosx/add-dsym/TestAddDsymDownload.py b/lldb/test/API/macosx/add-dsym/TestAddDsymDownload.py
index c83d923b3e387..9c5d5fee0d635 100644
--- a/lldb/test/API/macosx/add-dsym/TestAddDsymDownload.py
+++ b/lldb/test/API/macosx/add-dsym/TestAddDsymDownload.py
@@ -54,7 +54,7 @@ def setUp(self):
os.path.basename(self.exe))
self.dsym_for_uuid = self.getBuildArtifact("dsym-for-uuid.sh")
- self.buildDefault(dictionary={'MAKE_DSYM': 'YES'})
+ self.build(debug_info="dsym")
self.assertTrue(os.path.exists(self.exe))
self.assertTrue(os.path.exists(self.dsym))
diff --git a/lldb/test/API/macosx/add-dsym/TestAddDsymMidExecutionCommand.py b/lldb/test/API/macosx/add-dsym/TestAddDsymMidExecutionCommand.py
index 3c98a6bccd9b4..6488ed6b9872d 100644
--- a/lldb/test/API/macosx/add-dsym/TestAddDsymMidExecutionCommand.py
+++ b/lldb/test/API/macosx/add-dsym/TestAddDsymMidExecutionCommand.py
@@ -21,7 +21,7 @@ def setUp(self):
@no_debug_info_test # Prevent the genaration of the dwarf version of this test
def test_add_dsym_mid_execution(self):
"""Test that add-dsym mid-execution loads the symbols at the right place for a slid binary."""
- self.buildDefault(dictionary={'MAKE_DSYM':'YES'})
+ self.build(debug_info="dsym")
exe = self.getBuildArtifact("a.out")
self.target = self.dbg.CreateTarget(exe)
More information about the lldb-commits
mailing list