Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

187 lines
6.0 KiB
Python
Raw Normal View History

""" This module contains functions used by the test cases to hide the
architecture and/or the platform dependent nature of the tests. """
# System modules
import itertools
import re
import subprocess
import sys
import os
from urllib.parse import urlparse
# LLDB modules
from . import configuration
import lldb
import lldbsuite.test.lldbplatform as lldbplatform
def check_first_register_readable(test_case):
arch = test_case.getArchitecture()
if arch in ["x86_64", "i386"]:
test_case.expect("register read eax", substrs=["eax = 0x"])
elif arch in ["arm", "armv7", "armv7k", "armv8l", "armv7l"]:
test_case.expect("register read r0", substrs=["r0 = 0x"])
elif arch in ["aarch64", "arm64", "arm64e", "arm64_32"]:
test_case.expect("register read x0", substrs=["x0 = 0x"])
elif re.match("mips", arch):
test_case.expect("register read zero", substrs=["zero = 0x"])
Support Linux on SystemZ as platform This patch adds support for Linux on SystemZ: - A new ArchSpec value of eCore_s390x_generic - A new directory Plugins/ABI/SysV-s390x providing an ABI implementation - Register context support - Native Linux support including watchpoint support - ELF core file support - Misc. support throughout the code base (e.g. breakpoint opcodes) - Test case updates to support the platform This should provide complete support for debugging the SystemZ platform. Not yet supported are optional features like transaction support (zEC12) or SIMD vector support (z13). There is no instruction emulation, since our ABI requires that all code provide correct DWARF CFI at all PC locations in .eh_frame to support unwinding (i.e. -fasynchronous-unwind-tables is on by default). The implementation follows existing platforms in a mostly straightforward manner. A couple of things that are different: - We do not use PTRACE_PEEKUSER / PTRACE_POKEUSER to access single registers, since some registers (access register) reside at offsets in the user area that are multiples of 4, but the PTRACE_PEEKUSER interface only allows accessing aligned 8-byte blocks in the user area. Instead, we use a s390 specific ptrace interface PTRACE_PEEKUSR_AREA / PTRACE_POKEUSR_AREA that allows accessing a whole block of the user area in one go, so in effect allowing to treat parts of the user area as register sets. - SystemZ hardware does not provide any means to implement read watchpoints, only write watchpoints. In fact, we can only support a *single* write watchpoint (but this can span a range of arbitrary size). In LLDB this means we support only a single watchpoint. I've set all test cases that require read watchpoints (or multiple watchpoints) to expected failure on the platform. [ Note that there were two test cases that install a read/write watchpoint even though they nowhere rely on the "read" property. I've changed those to simply use plain write watchpoints. ] Differential Revision: http://reviews.llvm.org/D18978 llvm-svn: 266308
2016-04-14 14:28:34 +00:00
elif arch in ["s390x"]:
test_case.expect("register read r0", substrs=["r0 = 0x"])
elif arch in ["powerpc64le"]:
test_case.expect("register read r0", substrs=["r0 = 0x"])
else:
# TODO: Add check for other architectures
test_case.fail(
"Unsupported architecture for test case (arch: %s)"
% test_case.getArchitecture()
)
def _run_adb_command(cmd, device_id):
device_id_args = []
if device_id:
device_id_args = ["-s", device_id]
full_cmd = ["adb"] + device_id_args + cmd
p = subprocess.Popen(full_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = p.communicate()
return p.returncode, stdout, stderr
def target_is_android():
return configuration.lldb_platform_name == "remote-android"
def android_device_api():
if not hasattr(android_device_api, "result"):
assert configuration.lldb_platform_url is not None
device_id = None
parsed_url = urlparse(configuration.lldb_platform_url)
host_name = parsed_url.netloc.split(":")[0]
if host_name != "localhost":
device_id = host_name
if device_id.startswith("[") and device_id.endswith("]"):
device_id = device_id[1:-1]
retcode, stdout, stderr = _run_adb_command(
["shell", "getprop", "ro.build.version.sdk"], device_id
)
if retcode == 0:
android_device_api.result = int(stdout)
else:
raise LookupError(
">>> Unable to determine the API level of the Android device.\n"
">>> stdout:\n%s\n"
">>> stderr:\n%s\n" % (stdout, stderr)
)
return android_device_api.result
def match_android_device(device_arch, valid_archs=None, valid_api_levels=None):
if not target_is_android():
return False
if valid_archs is not None and device_arch not in valid_archs:
return False
if valid_api_levels is not None and android_device_api() not in valid_api_levels:
return False
return True
def finalize_build_dictionary(dictionary):
if target_is_android():
if dictionary is None:
dictionary = {}
dictionary["OS"] = "Android"
dictionary["PIE"] = 1
return dictionary
def _get_platform_os(p):
# Use the triple to determine the platform if set.
triple = p.GetTriple()
if triple:
platform = triple.split("-")[2]
if platform.startswith("freebsd"):
platform = "freebsd"
elif platform.startswith("netbsd"):
platform = "netbsd"
return platform
return ""
def getHostPlatform():
"""Returns the host platform running the test suite."""
return _get_platform_os(lldb.SBPlatform("host"))
def getDarwinOSTriples():
return lldbplatform.translate(lldbplatform.darwin_all)
def getPlatform():
"""Returns the target platform which the tests are running on."""
# Use the Apple SDK to determine the platform if set.
if configuration.apple_sdk:
platform = configuration.apple_sdk
dot = platform.find(".")
if dot != -1:
platform = platform[:dot]
if platform == "iphoneos":
platform = "ios"
return platform
return _get_platform_os(lldb.selected_platform)
def platformIsDarwin():
"""Returns true if the OS triple for the selected platform is any valid apple OS"""
return getPlatform() in getDarwinOSTriples()
def findMainThreadCheckerDylib():
if not platformIsDarwin():
return ""
if getPlatform() in lldbplatform.translate(lldbplatform.darwin_embedded):
return "/Developer/usr/lib/libMainThreadChecker.dylib"
with os.popen("xcode-select -p") as output:
xcode_developer_path = output.read().strip()
mtc_dylib_path = "%s/usr/lib/libMainThreadChecker.dylib" % xcode_developer_path
if os.path.isfile(mtc_dylib_path):
return mtc_dylib_path
return ""
class _PlatformContext(object):
"""Value object class which contains platform-specific options."""
[lldb/test] Make TestLoadUnload compatible with windows Summary: This patch introduces a header "dylib.h" which can be used in tests to handle shared libraries semi-portably. The shared library APIs on windows and posix systems look very different, but their underlying functionality is relatively similar, so the mapping is not difficult. It also introduces two new macros to wrap the functinality necessary to export/import function across the dll boundary on windows. Previously we had the LLDB_TEST_API macro for this purpose, which automagically changed meaning depending on whether we were building the shared library or the executable. While convenient for simple cases, this approach was not sufficient for the more complicated setups where one deals with multiple shared libraries. Lastly it rewrites TestLoadUnload, to make use of the new APIs. The trickiest aspect there is the handling of DYLD_LIBRARY_PATH on macos -- previously setting this variable was not needed as the test used @executable_path-relative dlopens, but the new generic api does not support that. Other systems do not support such dlopens either so the test already contained support for setting the appropriate path variable, and this patch just makes that logic more generic. In doesn't seem that the purpose of this test was to exercise @executable_path imports, so this should not be a problem. These changes are sufficient to make some of the TestLoadUnload tests pass on windows. Two other tests will start to pass once D77287 lands. Reviewers: amccarth, jingham, JDevlieghere, compnerd Subscribers: lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D77662
2020-04-06 22:24:51 +02:00
def __init__(
self, shlib_environment_var, shlib_path_separator, shlib_prefix, shlib_extension
):
self.shlib_environment_var = shlib_environment_var
[lldb/test] Make TestLoadUnload compatible with windows Summary: This patch introduces a header "dylib.h" which can be used in tests to handle shared libraries semi-portably. The shared library APIs on windows and posix systems look very different, but their underlying functionality is relatively similar, so the mapping is not difficult. It also introduces two new macros to wrap the functinality necessary to export/import function across the dll boundary on windows. Previously we had the LLDB_TEST_API macro for this purpose, which automagically changed meaning depending on whether we were building the shared library or the executable. While convenient for simple cases, this approach was not sufficient for the more complicated setups where one deals with multiple shared libraries. Lastly it rewrites TestLoadUnload, to make use of the new APIs. The trickiest aspect there is the handling of DYLD_LIBRARY_PATH on macos -- previously setting this variable was not needed as the test used @executable_path-relative dlopens, but the new generic api does not support that. Other systems do not support such dlopens either so the test already contained support for setting the appropriate path variable, and this patch just makes that logic more generic. In doesn't seem that the purpose of this test was to exercise @executable_path imports, so this should not be a problem. These changes are sufficient to make some of the TestLoadUnload tests pass on windows. Two other tests will start to pass once D77287 lands. Reviewers: amccarth, jingham, JDevlieghere, compnerd Subscribers: lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D77662
2020-04-06 22:24:51 +02:00
self.shlib_path_separator = shlib_path_separator
self.shlib_prefix = shlib_prefix
self.shlib_extension = shlib_extension
def createPlatformContext():
if platformIsDarwin():
[lldb/test] Make TestLoadUnload compatible with windows Summary: This patch introduces a header "dylib.h" which can be used in tests to handle shared libraries semi-portably. The shared library APIs on windows and posix systems look very different, but their underlying functionality is relatively similar, so the mapping is not difficult. It also introduces two new macros to wrap the functinality necessary to export/import function across the dll boundary on windows. Previously we had the LLDB_TEST_API macro for this purpose, which automagically changed meaning depending on whether we were building the shared library or the executable. While convenient for simple cases, this approach was not sufficient for the more complicated setups where one deals with multiple shared libraries. Lastly it rewrites TestLoadUnload, to make use of the new APIs. The trickiest aspect there is the handling of DYLD_LIBRARY_PATH on macos -- previously setting this variable was not needed as the test used @executable_path-relative dlopens, but the new generic api does not support that. Other systems do not support such dlopens either so the test already contained support for setting the appropriate path variable, and this patch just makes that logic more generic. In doesn't seem that the purpose of this test was to exercise @executable_path imports, so this should not be a problem. These changes are sufficient to make some of the TestLoadUnload tests pass on windows. Two other tests will start to pass once D77287 lands. Reviewers: amccarth, jingham, JDevlieghere, compnerd Subscribers: lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D77662
2020-04-06 22:24:51 +02:00
return _PlatformContext("DYLD_LIBRARY_PATH", ":", "lib", "dylib")
elif getPlatform() in ("freebsd", "linux", "netbsd"):
[lldb/test] Make TestLoadUnload compatible with windows Summary: This patch introduces a header "dylib.h" which can be used in tests to handle shared libraries semi-portably. The shared library APIs on windows and posix systems look very different, but their underlying functionality is relatively similar, so the mapping is not difficult. It also introduces two new macros to wrap the functinality necessary to export/import function across the dll boundary on windows. Previously we had the LLDB_TEST_API macro for this purpose, which automagically changed meaning depending on whether we were building the shared library or the executable. While convenient for simple cases, this approach was not sufficient for the more complicated setups where one deals with multiple shared libraries. Lastly it rewrites TestLoadUnload, to make use of the new APIs. The trickiest aspect there is the handling of DYLD_LIBRARY_PATH on macos -- previously setting this variable was not needed as the test used @executable_path-relative dlopens, but the new generic api does not support that. Other systems do not support such dlopens either so the test already contained support for setting the appropriate path variable, and this patch just makes that logic more generic. In doesn't seem that the purpose of this test was to exercise @executable_path imports, so this should not be a problem. These changes are sufficient to make some of the TestLoadUnload tests pass on windows. Two other tests will start to pass once D77287 lands. Reviewers: amccarth, jingham, JDevlieghere, compnerd Subscribers: lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D77662
2020-04-06 22:24:51 +02:00
return _PlatformContext("LD_LIBRARY_PATH", ":", "lib", "so")
else:
[lldb/test] Make TestLoadUnload compatible with windows Summary: This patch introduces a header "dylib.h" which can be used in tests to handle shared libraries semi-portably. The shared library APIs on windows and posix systems look very different, but their underlying functionality is relatively similar, so the mapping is not difficult. It also introduces two new macros to wrap the functinality necessary to export/import function across the dll boundary on windows. Previously we had the LLDB_TEST_API macro for this purpose, which automagically changed meaning depending on whether we were building the shared library or the executable. While convenient for simple cases, this approach was not sufficient for the more complicated setups where one deals with multiple shared libraries. Lastly it rewrites TestLoadUnload, to make use of the new APIs. The trickiest aspect there is the handling of DYLD_LIBRARY_PATH on macos -- previously setting this variable was not needed as the test used @executable_path-relative dlopens, but the new generic api does not support that. Other systems do not support such dlopens either so the test already contained support for setting the appropriate path variable, and this patch just makes that logic more generic. In doesn't seem that the purpose of this test was to exercise @executable_path imports, so this should not be a problem. These changes are sufficient to make some of the TestLoadUnload tests pass on windows. Two other tests will start to pass once D77287 lands. Reviewers: amccarth, jingham, JDevlieghere, compnerd Subscribers: lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D77662
2020-04-06 22:24:51 +02:00
return _PlatformContext("PATH", ";", "", "dll")
def hasChattyStderr(test_case):
"""Some targets produce garbage on the standard error output. This utility function
determines whether the tests can be strict about the expected stderr contents."""
if match_android_device(
test_case.getArchitecture(), ["aarch64"], range(22, 25 + 1)
):
return True # The dynamic linker on the device will complain about unknown DT entries
return False