diff options
author | Frederic Riss <friss@apple.com> | 2018-04-06 04:28:12 +0000 |
---|---|---|
committer | Frederic Riss <friss@apple.com> | 2018-04-06 04:28:12 +0000 |
commit | cd90f878d4156ef1a732cdd64bc67aa88e7ac2ec (patch) | |
tree | d3f7ce21fce68fe4c55bb70b8556b8a6f93fdd0b /lldb/packages/Python/lldbsuite | |
parent | 1e989deadd26698a3c6f463aad8d636533835cd2 (diff) | |
download | bcm5719-llvm-cd90f878d4156ef1a732cdd64bc67aa88e7ac2ec.tar.gz bcm5719-llvm-cd90f878d4156ef1a732cdd64bc67aa88e7ac2ec.zip |
[debugserver] Fix LC_BUILD_VERSION load command handling.
Summary:
In one of the 2 places the LC_BUILD_VERSION load command is handled, there
is a bug preventing us from actually handling them (the address where to
read the load command was not updated). This patch factors reading the
deployment target load commands into a helper and adds testing for the 2
code paths calling the helper.
The testing is a little bit complicated because the only times those load
commands matter is when debugging a simulator process. I added a new
decorator to check that a specific SDK is available. The actual testing was
fairly easy once I knew how to run a simulated process.
Reviewers: jasonmolenda, labath
Subscribers: lldb-commits
Differential Revision: https://reviews.llvm.org/D45298
llvm-svn: 329374
Diffstat (limited to 'lldb/packages/Python/lldbsuite')
3 files changed, 142 insertions, 0 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/decorators.py b/lldb/packages/Python/lldbsuite/test/decorators.py index aad78043a0d..e91f3ff65ba 100644 --- a/lldb/packages/Python/lldbsuite/test/decorators.py +++ b/lldb/packages/Python/lldbsuite/test/decorators.py @@ -344,6 +344,28 @@ def no_debug_info_test(func): wrapper.__no_debug_info_test__ = True return wrapper +def apple_simulator_test(platform): + """ + Decorate the test as a test requiring a simulator for a specific platform. + + Consider that a simulator is available if you have the corresponding SDK installed. + The SDK identifiers for simulators are iphonesimulator, appletvsimulator, watchsimulator + """ + def should_skip_simulator_test(): + if lldbplatformutil.getHostPlatform() != 'darwin': + return "simulator tests are run only on darwin hosts" + try: + DEVNULL = open(os.devnull, 'w') + output = subprocess.check_output(["xcodebuild", "-showsdks"], stderr=DEVNULL) + if re.search('%ssimulator' % platform, output): + return None + else: + return "%s simulator is not supported on this system." % platform + except subprocess.CalledProcessError: + return "%s is not supported on this system (xcodebuild failed)." % feature + + return skipTestIfFn(should_skip_simulator_test) + def debugserver_test(func): """Decorate the item as a debugserver test.""" diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestAppleSimulatorOSType.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestAppleSimulatorOSType.py new file mode 100644 index 00000000000..e5589ca4f0b --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestAppleSimulatorOSType.py @@ -0,0 +1,112 @@ +from __future__ import print_function + + +import gdbremote_testcase +import lldbgdbserverutils +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +import json + +class TestAppleSimulatorOSType(gdbremote_testcase.GdbRemoteTestCaseBase): + + mydir = TestBase.compute_mydir(__file__) + + def check_simulator_ostype(self, sdk, platform_names, arch='x86_64'): + sim_devices_str = subprocess.check_output(['xcrun', 'simctl', 'list', + '-j', 'devices']) + sim_devices = json.loads(sim_devices_str)['devices'] + # Find an available simulator for the requested platform + deviceUDID = None + for (runtime,devices) in sim_devices.items(): + if not any(p in runtime.lower() for p in platform_names): + continue + for device in devices: + if device['availability'] != '(available)': + continue + deviceUDID = device['udid'] + break + if deviceUDID != None: + break + + # Launch the process using simctl + self.assertIsNotNone(deviceUDID) + exe_name = 'test_simulator_platform_{}'.format(platform_names[0]) + sdkroot = subprocess.check_output(['xcrun', '--show-sdk-path', '--sdk', + sdk]) + self.build(dictionary={ 'EXE': exe_name, 'SDKROOT': sdkroot.strip(), + 'ARCH': arch }) + exe_path = self.getBuildArtifact(exe_name) + sim_launcher = subprocess.Popen(['xcrun', 'simctl', 'spawn', + deviceUDID, exe_path, + 'print-pid', 'sleep:10'], + stderr=subprocess.PIPE) + # Get the PID from the process output + pid = None + while not pid: + stderr = sim_launcher.stderr.readline() + if stderr == '': + continue + m = re.match(r"PID: (.*)", stderr) + self.assertIsNotNone(m) + pid = int(m.group(1)) + + # Launch debug monitor attaching to the simulated process + self.init_debugserver_test() + server = self.connect_to_debug_monitor(attach_pid=pid) + + # Setup packet sequences + self.add_no_ack_remote_stream() + self.add_process_info_collection_packets() + self.test_sequence.add_log_lines( + ["read packet: " + + "$jGetLoadedDynamicLibrariesInfos:{\"fetch_all_solibs\" : true}]#ce", + {"direction": "send", "regex": r"^\$(.+)#[0-9a-fA-F]{2}$", + "capture": {1: "dylib_info_raw"}}], + True) + + # Run the stream + context = self.expect_gdbremote_sequence() + self.assertIsNotNone(context) + + # Gather process info response + process_info = self.parse_process_info_response(context) + self.assertIsNotNone(process_info) + + # Check that ostype is correct + self.assertTrue(process_info['ostype'] in platform_names) + + # Now for dylibs + dylib_info_raw = context.get("dylib_info_raw") + dylib_info = json.loads(self.decode_gdbremote_binary(dylib_info_raw)) + images = dylib_info['images'] + + image_info = None + for image in images: + if image['pathname'] != exe_path: + continue + image_info = image + break + + self.assertIsNotNone(image_info) + self.assertTrue(image['min_version_os_name'] in platform_names) + + + @apple_simulator_test('iphone') + @debugserver_test + def test_simulator_ostype_ios(self): + self.check_simulator_ostype(sdk='iphonesimulator', + platform_names=['iphoneos', 'ios']) + + @apple_simulator_test('appletv') + @debugserver_test + def test_simulator_ostype_tvos(self): + self.check_simulator_ostype(sdk='appletvsimulator', + platform_names=['tvos']) + + @apple_simulator_test('watch') + @debugserver_test + def test_simulator_ostype_watchos(self): + self.check_simulator_ostype(sdk='watchsimulator', + platform_names=['watchos'], arch='i386') diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/main.cpp b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/main.cpp index 399c1d35ae6..ca032c120be 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/main.cpp +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/main.cpp @@ -48,6 +48,8 @@ static const char *const THREAD_COMMAND_NEW = "new"; static const char *const THREAD_COMMAND_PRINT_IDS = "print-ids"; static const char *const THREAD_COMMAND_SEGFAULT = "segfault"; +static const char *const PRINT_PID_COMMAND = "print-pid"; + static bool g_print_thread_ids = false; static pthread_mutex_t g_print_mutex = PTHREAD_MUTEX_INITIALIZER; static bool g_threads_do_segfault = false; @@ -61,6 +63,10 @@ static char g_message[256]; static volatile char g_c1 = '0'; static volatile char g_c2 = '1'; +static void print_pid() { + fprintf(stderr, "PID: %d\n", getpid()); +} + static void print_thread_id() { // Put in the right magic here for your platform to spit out the thread id (tid) // that debugserver/lldb-gdbserver would see as a TID. Otherwise, let the else @@ -349,6 +355,8 @@ int main(int argc, char **argv) { // At this point we don't do anything else with threads. // Later use thread index and send command to thread. } + } else if (std::strstr(argv[i], PRINT_PID_COMMAND)) { + print_pid(); } else { // Treat the argument as text for stdout. printf("%s\n", argv[i]); |