diff options
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test/tools/lldb-server')
20 files changed, 1236 insertions, 626 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemoteAttach.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemoteAttach.py index 5460b21382e..e53d80b48f9 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemoteAttach.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemoteAttach.py @@ -1,35 +1,40 @@ 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 + class TestGdbRemoteAttach(gdbremote_testcase.GdbRemoteTestCaseBase): mydir = TestBase.compute_mydir(__file__) def attach_with_vAttach(self): # Start the inferior, start the debug monitor, nothing is attached yet. - procs = self.prep_debug_monitor_and_inferior(inferior_args=["sleep:60"]) + procs = self.prep_debug_monitor_and_inferior( + inferior_args=["sleep:60"]) self.assertIsNotNone(procs) # Make sure the target process has been launched. inferior = procs.get("inferior") self.assertIsNotNone(inferior) self.assertTrue(inferior.pid > 0) - self.assertTrue(lldbgdbserverutils.process_is_running(inferior.pid, True)) + self.assertTrue( + lldbgdbserverutils.process_is_running( + inferior.pid, True)) # Add attach packets. self.test_sequence.add_log_lines([ # Do the attach. "read packet: $vAttach;{:x}#00".format(inferior.pid), # Expect a stop notification from the attach. - { "direction":"send", "regex":r"^\$T([0-9a-fA-F]{2})[^#]*#[0-9a-fA-F]{2}$", "capture":{1:"stop_signal_hex"} }, - ], True) + {"direction": "send", + "regex": r"^\$T([0-9a-fA-F]{2})[^#]*#[0-9a-fA-F]{2}$", + "capture": {1: "stop_signal_hex"}}, + ], True) self.add_process_info_collection_packets() # Run the stream diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemoteAuxvSupport.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemoteAuxvSupport.py index e70ad5f570a..ffabefc70f8 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemoteAuxvSupport.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemoteAuxvSupport.py @@ -1,12 +1,12 @@ from __future__ import print_function - import gdbremote_testcase from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * from lldbsuite.test import lldbutil + class TestGdbRemoteAuxvSupport(gdbremote_testcase.GdbRemoteTestCaseBase): mydir = TestBase.compute_mydir(__file__) @@ -15,7 +15,8 @@ class TestGdbRemoteAuxvSupport(gdbremote_testcase.GdbRemoteTestCaseBase): def has_auxv_support(self): inferior_args = ["message:main entered", "sleep:5"] - procs = self.prep_debug_monitor_and_inferior(inferior_args=inferior_args) + procs = self.prep_debug_monitor_and_inferior( + inferior_args=inferior_args) # Don't do anything until we match the launched inferior main entry output. # Then immediately interrupt the process. @@ -25,8 +26,9 @@ class TestGdbRemoteAuxvSupport(gdbremote_testcase.GdbRemoteTestCaseBase): # Start the inferior... "read packet: $c#63", # ... match output.... - { "type":"output_match", "regex":self.maybe_strict_output_regex(r"message:main entered\r\n") }, - ], True) + {"type": "output_match", "regex": self.maybe_strict_output_regex( + r"message:main entered\r\n")}, + ], True) # ... then interrupt. self.add_interrupt_packets() self.add_qSupported_packets() @@ -35,7 +37,8 @@ class TestGdbRemoteAuxvSupport(gdbremote_testcase.GdbRemoteTestCaseBase): self.assertIsNotNone(context) features = self.parse_qSupported_response(context) - return self.AUXV_SUPPORT_FEATURE_NAME in features and features[self.AUXV_SUPPORT_FEATURE_NAME] == "+" + return self.AUXV_SUPPORT_FEATURE_NAME in features and features[ + self.AUXV_SUPPORT_FEATURE_NAME] == "+" def get_raw_auxv_data(self): # Start up llgs and inferior, and check for auxv support. @@ -60,10 +63,20 @@ class TestGdbRemoteAuxvSupport(gdbremote_testcase.GdbRemoteTestCaseBase): # Grab the auxv data. self.reset_test_sequence() - self.test_sequence.add_log_lines([ - "read packet: $qXfer:auxv:read::{:x},{:x}:#00".format(OFFSET, LENGTH), - {"direction":"send", "regex":re.compile(r"^\$([^E])(.*)#[0-9a-fA-F]{2}$", re.MULTILINE|re.DOTALL), "capture":{1:"response_type", 2:"content_raw"} } - ], True) + self.test_sequence.add_log_lines( + [ + "read packet: $qXfer:auxv:read::{:x},{:x}:#00".format( + OFFSET, + LENGTH), + { + "direction": "send", + "regex": re.compile( + r"^\$([^E])(.*)#[0-9a-fA-F]{2}$", + re.MULTILINE | re.DOTALL), + "capture": { + 1: "response_type", + 2: "content_raw"}}], + True) context = self.expect_gdbremote_sequence() self.assertIsNotNone(context) @@ -101,8 +114,9 @@ class TestGdbRemoteAuxvSupport(gdbremote_testcase.GdbRemoteTestCaseBase): (word_size, auxv_data) = self.get_raw_auxv_data() self.assertIsNotNone(auxv_data) - # Ensure auxv data is a multiple of 2*word_size (there should be two unsigned long fields per auxv entry). - self.assertEqual(len(auxv_data) % (2*word_size), 0) + # Ensure auxv data is a multiple of 2*word_size (there should be two + # unsigned long fields per auxv entry). + self.assertEqual(len(auxv_data) % (2 * word_size), 0) # print("auxv contains {} entries".format(len(auxv_data) / (2*word_size))) @debugserver_test @@ -179,10 +193,12 @@ class TestGdbRemoteAuxvSupport(gdbremote_testcase.GdbRemoteTestCaseBase): auxv_dict = self.build_auxv_dict(endian, word_size, auxv_data) self.assertIsNotNone(auxv_dict) - iterated_auxv_data = self.read_binary_data_in_chunks("qXfer:auxv:read::", 2*word_size) + iterated_auxv_data = self.read_binary_data_in_chunks( + "qXfer:auxv:read::", 2 * word_size) self.assertIsNotNone(iterated_auxv_data) - auxv_dict_iterated = self.build_auxv_dict(endian, word_size, iterated_auxv_data) + auxv_dict_iterated = self.build_auxv_dict( + endian, word_size, iterated_auxv_data) self.assertIsNotNone(auxv_dict_iterated) # Verify both types of data collection returned same content. diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemoteExpeditedRegisters.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemoteExpeditedRegisters.py index 7daae871caf..dc2b99f54bd 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemoteExpeditedRegisters.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemoteExpeditedRegisters.py @@ -1,13 +1,14 @@ from __future__ import print_function - import gdbremote_testcase from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * from lldbsuite.test import lldbutil -class TestGdbRemoteExpeditedRegisters(gdbremote_testcase.GdbRemoteTestCaseBase): + +class TestGdbRemoteExpeditedRegisters( + gdbremote_testcase.GdbRemoteTestCaseBase): mydir = TestBase.compute_mydir(__file__) @@ -19,8 +20,11 @@ class TestGdbRemoteExpeditedRegisters(gdbremote_testcase.GdbRemoteTestCaseBase): "read packet: $c#63", # Immediately tell it to stop. We want to see what it reports. "read packet: {}".format(chr(3)), - {"direction":"send", "regex":r"^\$T([0-9a-fA-F]+)([^#]+)#[0-9a-fA-F]{2}$", "capture":{1:"stop_result", 2:"key_vals_text"} }, - ], True) + {"direction": "send", + "regex": r"^\$T([0-9a-fA-F]+)([^#]+)#[0-9a-fA-F]{2}$", + "capture": {1: "stop_result", + 2: "key_vals_text"}}, + ], True) # Run the gdb remote command stream. context = self.expect_gdbremote_sequence() @@ -30,13 +34,16 @@ class TestGdbRemoteExpeditedRegisters(gdbremote_testcase.GdbRemoteTestCaseBase): key_vals_text = context.get("key_vals_text") self.assertIsNotNone(key_vals_text) - expedited_registers = self.extract_registers_from_stop_notification(key_vals_text) + expedited_registers = self.extract_registers_from_stop_notification( + key_vals_text) self.assertIsNotNone(expedited_registers) return expedited_registers - def stop_notification_contains_generic_register(self, generic_register_name): - # Generate a stop reply, parse out expedited registers from stop notification. + def stop_notification_contains_generic_register( + self, generic_register_name): + # Generate a stop reply, parse out expedited registers from stop + # notification. expedited_registers = self.gather_expedited_registers() self.assertIsNotNone(expedited_registers) self.assertTrue(len(expedited_registers) > 0) @@ -45,7 +52,8 @@ class TestGdbRemoteExpeditedRegisters(gdbremote_testcase.GdbRemoteTestCaseBase): reg_infos = self.gather_register_infos() # Find the generic register. - reg_info = self.find_generic_register_with_name(reg_infos, generic_register_name) + reg_info = self.find_generic_register_with_name( + reg_infos, generic_register_name) self.assertIsNotNone(reg_info) # Ensure the expedited registers contained it. @@ -53,7 +61,8 @@ class TestGdbRemoteExpeditedRegisters(gdbremote_testcase.GdbRemoteTestCaseBase): # print("{} reg_info:{}".format(generic_register_name, reg_info)) def stop_notification_contains_any_registers(self): - # Generate a stop reply, parse out expedited registers from stop notification. + # Generate a stop reply, parse out expedited registers from stop + # notification. expedited_registers = self.gather_expedited_registers() # Verify we have at least one expedited register. self.assertTrue(len(expedited_registers) > 0) @@ -73,15 +82,19 @@ class TestGdbRemoteExpeditedRegisters(gdbremote_testcase.GdbRemoteTestCaseBase): self.stop_notification_contains_any_registers() def stop_notification_contains_no_duplicate_registers(self): - # Generate a stop reply, parse out expedited registers from stop notification. + # Generate a stop reply, parse out expedited registers from stop + # notification. expedited_registers = self.gather_expedited_registers() # Verify no expedited register was specified multiple times. for (reg_num, value) in list(expedited_registers.items()): - if (type(value) == list) and (len(value) > 0): - self.fail("expedited register number {} specified more than once ({} times)".format(reg_num, len(value))) + if (isinstance(value, list)) and (len(value) > 0): + self.fail( + "expedited register number {} specified more than once ({} times)".format( + reg_num, len(value))) @debugserver_test - def test_stop_notification_contains_no_duplicate_registers_debugserver(self): + def test_stop_notification_contains_no_duplicate_registers_debugserver( + self): self.init_debugserver_test() self.build() self.set_inferior_startup_launch() diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemoteKill.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemoteKill.py index 560da9d4142..c3ecf5bc24d 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemoteKill.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemoteKill.py @@ -1,13 +1,13 @@ 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 + class TestGdbRemoteKill(gdbremote_testcase.GdbRemoteTestCaseBase): mydir = TestBase.compute_mydir(__file__) @@ -16,18 +16,20 @@ class TestGdbRemoteKill(gdbremote_testcase.GdbRemoteTestCaseBase): procs = self.prep_debug_monitor_and_inferior() self.test_sequence.add_log_lines([ "read packet: $k#6b", - {"direction":"send", "regex":r"^\$X[0-9a-fA-F]+([^#]*)#[0-9A-Fa-f]{2}" }, - ], True) + {"direction": "send", "regex": r"^\$X[0-9a-fA-F]+([^#]*)#[0-9A-Fa-f]{2}"}, + ], True) if self.stub_sends_two_stop_notifications_on_kill: - # Add an expectation for a second X result for stubs that send two of these. + # Add an expectation for a second X result for stubs that send two + # of these. self.test_sequence.add_log_lines([ - {"direction":"send", "regex":r"^\$X[0-9a-fA-F]+([^#]*)#[0-9A-Fa-f]{2}" }, - ], True) + {"direction": "send", "regex": r"^\$X[0-9a-fA-F]+([^#]*)#[0-9A-Fa-f]{2}"}, + ], True) self.expect_gdbremote_sequence() - # Wait a moment for completed and now-detached inferior process to clear. + # Wait a moment for completed and now-detached inferior process to + # clear. time.sleep(1) if not lldb.remote_platform: @@ -35,8 +37,11 @@ class TestGdbRemoteKill(gdbremote_testcase.GdbRemoteTestCaseBase): poll_result = procs["inferior"].poll() self.assertIsNotNone(poll_result) - # Where possible, verify at the system level that the process is not running. - self.assertFalse(lldbgdbserverutils.process_is_running(procs["inferior"].pid, False)) + # Where possible, verify at the system level that the process is not + # running. + self.assertFalse( + lldbgdbserverutils.process_is_running( + procs["inferior"].pid, False)) @debugserver_test def test_attach_commandline_kill_after_initial_stop_debugserver(self): @@ -51,4 +56,3 @@ class TestGdbRemoteKill(gdbremote_testcase.GdbRemoteTestCaseBase): self.build() self.set_inferior_startup_attach() self.attach_commandline_kill_after_initial_stop() - diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemoteProcessInfo.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemoteProcessInfo.py index fd89ddfa28f..21af255cfd9 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemoteProcessInfo.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemoteProcessInfo.py @@ -9,6 +9,7 @@ from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * from lldbsuite.test import lldbutil + class TestGdbRemoteProcessInfo(gdbremote_testcase.GdbRemoteTestCaseBase): mydir = TestBase.compute_mydir(__file__) @@ -52,7 +53,7 @@ class TestGdbRemoteProcessInfo(gdbremote_testcase.GdbRemoteTestCaseBase): self.add_process_info_collection_packets() # Run the stream - context = self.expect_gdbremote_sequence(timeout_seconds = 8) + context = self.expect_gdbremote_sequence(timeout_seconds=8) self.assertIsNotNone(context) # Gather process info response @@ -66,7 +67,8 @@ class TestGdbRemoteProcessInfo(gdbremote_testcase.GdbRemoteTestCaseBase): self.assertEqual(reported_pid, procs["inferior"].pid) @debugserver_test - def test_attach_commandline_qProcessInfo_reports_correct_pid_debugserver(self): + def test_attach_commandline_qProcessInfo_reports_correct_pid_debugserver( + self): self.init_debugserver_test() self.build() self.set_inferior_startup_attach() @@ -120,13 +122,17 @@ class TestGdbRemoteProcessInfo(gdbremote_testcase.GdbRemoteTestCaseBase): process_info = self.parse_process_info_response(context) self.assertIsNotNone(process_info) - # Ensure the expected keys are present and non-None within the process info. + # Ensure the expected keys are present and non-None within the process + # info. missing_key_set = set() for expected_key in expected_key_set: if expected_key not in process_info: missing_key_set.add(expected_key) - self.assertEqual(missing_key_set, set(), "the listed keys are missing in the qProcessInfo result") + self.assertEqual( + missing_key_set, + set(), + "the listed keys are missing in the qProcessInfo result") def qProcessInfo_does_not_contain_keys(self, absent_key_set): procs = self.prep_debug_monitor_and_inferior() @@ -146,7 +152,10 @@ class TestGdbRemoteProcessInfo(gdbremote_testcase.GdbRemoteTestCaseBase): if unexpected_key in process_info: unexpected_key_set.add(unexpected_key) - self.assertEqual(unexpected_key_set, set(), "the listed keys were present but unexpected in qProcessInfo result") + self.assertEqual( + unexpected_key_set, + set(), + "the listed keys were present but unexpected in qProcessInfo result") @skipUnlessDarwin @debugserver_test diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemoteRegisterState.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemoteRegisterState.py index 63a8995c672..b484bdcc4d5 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemoteRegisterState.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemoteRegisterState.py @@ -1,12 +1,12 @@ from __future__ import print_function - import gdbremote_testcase from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * from lldbsuite.test import lldbutil + class TestGdbRemoteRegisterState(gdbremote_testcase.GdbRemoteTestCaseBase): """Test QSaveRegisterState/QRestoreRegisterState support.""" @@ -15,7 +15,8 @@ class TestGdbRemoteRegisterState(gdbremote_testcase.GdbRemoteTestCaseBase): def grp_register_save_restore_works(self, with_suffix): # Start up the process, use thread suffix, grab main thread id. inferior_args = ["message:main entered", "sleep:5"] - procs = self.prep_debug_monitor_and_inferior(inferior_args=inferior_args) + procs = self.prep_debug_monitor_and_inferior( + inferior_args=inferior_args) self.add_process_info_collection_packets() self.add_register_info_collection_packets() @@ -26,8 +27,9 @@ class TestGdbRemoteRegisterState(gdbremote_testcase.GdbRemoteTestCaseBase): # Start the inferior... "read packet: $c#63", # ... match output.... - { "type":"output_match", "regex":self.maybe_strict_output_regex(r"message:main entered\r\n") }, - ], True) + {"type": "output_match", "regex": self.maybe_strict_output_regex( + r"message:main entered\r\n")}, + ], True) # ... then interrupt. self.add_interrupt_packets() @@ -44,8 +46,10 @@ class TestGdbRemoteRegisterState(gdbremote_testcase.GdbRemoteTestCaseBase): self.assertIsNotNone(reg_infos) self.add_lldb_register_index(reg_infos) - # Pull out the register infos that we think we can bit flip successfully. - gpr_reg_infos = [reg_info for reg_info in reg_infos if self.is_bit_flippable_register(reg_info)] + # Pull out the register infos that we think we can bit flip + # successfully. + gpr_reg_infos = [ + reg_info for reg_info in reg_infos if self.is_bit_flippable_register(reg_info)] self.assertTrue(len(gpr_reg_infos) > 0) # Gather thread info. @@ -71,15 +75,18 @@ class TestGdbRemoteRegisterState(gdbremote_testcase.GdbRemoteTestCaseBase): # print("saved register state id: {}".format(state_id)) # Remember initial register values. - initial_reg_values = self.read_register_values(gpr_reg_infos, endian, thread_id=thread_id) + initial_reg_values = self.read_register_values( + gpr_reg_infos, endian, thread_id=thread_id) # print("initial_reg_values: {}".format(initial_reg_values)) # Flip gpr register values. - (successful_writes, failed_writes) = self.flip_all_bits_in_each_register_value(gpr_reg_infos, endian, thread_id=thread_id) + (successful_writes, failed_writes) = self.flip_all_bits_in_each_register_value( + gpr_reg_infos, endian, thread_id=thread_id) # print("successful writes: {}, failed writes: {}".format(successful_writes, failed_writes)) self.assertTrue(successful_writes > 0) - flipped_reg_values = self.read_register_values(gpr_reg_infos, endian, thread_id=thread_id) + flipped_reg_values = self.read_register_values( + gpr_reg_infos, endian, thread_id=thread_id) # print("flipped_reg_values: {}".format(flipped_reg_values)) # Restore register values. @@ -90,7 +97,8 @@ class TestGdbRemoteRegisterState(gdbremote_testcase.GdbRemoteTestCaseBase): self.assertIsNotNone(context) # Verify registers match initial register values. - final_reg_values = self.read_register_values(gpr_reg_infos, endian, thread_id=thread_id) + final_reg_values = self.read_register_values( + gpr_reg_infos, endian, thread_id=thread_id) # print("final_reg_values: {}".format(final_reg_values)) self.assertIsNotNone(final_reg_values) self.assertEqual(final_reg_values, initial_reg_values) diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemoteSingleStep.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemoteSingleStep.py index 31d53bed259..f3a18786b03 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemoteSingleStep.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemoteSingleStep.py @@ -1,12 +1,12 @@ from __future__ import print_function - import gdbremote_testcase from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * from lldbsuite.test import lldbutil + class TestGdbRemoteSingleStep(gdbremote_testcase.GdbRemoteTestCaseBase): mydir = TestBase.compute_mydir(__file__) @@ -16,13 +16,24 @@ class TestGdbRemoteSingleStep(gdbremote_testcase.GdbRemoteTestCaseBase): self.init_debugserver_test() self.build() self.set_inferior_startup_launch() - self.single_step_only_steps_one_instruction(use_Hc_packet=True, step_instruction="s") + self.single_step_only_steps_one_instruction( + use_Hc_packet=True, step_instruction="s") @llgs_test - @expectedFailureAndroid(bugnumber="llvm.org/pr24739", archs=["arm", "aarch64"]) - @expectedFailureAll(oslist=["linux"], archs=["arm", "aarch64"], bugnumber="llvm.org/pr24739") + @expectedFailureAndroid( + bugnumber="llvm.org/pr24739", + archs=[ + "arm", + "aarch64"]) + @expectedFailureAll( + oslist=["linux"], + archs=[ + "arm", + "aarch64"], + bugnumber="llvm.org/pr24739") def test_single_step_only_steps_one_instruction_with_s_llgs(self): self.init_llgs_test() self.build() self.set_inferior_startup_launch() - self.single_step_only_steps_one_instruction(use_Hc_packet=True, step_instruction="s") + self.single_step_only_steps_one_instruction( + use_Hc_packet=True, step_instruction="s") diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemoteThreadsInStopReply.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemoteThreadsInStopReply.py index d55416569ac..57d4d5ab4bb 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemoteThreadsInStopReply.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemoteThreadsInStopReply.py @@ -5,7 +5,9 @@ from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * from lldbsuite.test import lldbutil -class TestGdbRemoteThreadsInStopReply(gdbremote_testcase.GdbRemoteTestCaseBase): + +class TestGdbRemoteThreadsInStopReply( + gdbremote_testcase.GdbRemoteTestCaseBase): mydir = TestBase.compute_mydir(__file__) @@ -16,11 +18,12 @@ class TestGdbRemoteThreadsInStopReply(gdbremote_testcase.GdbRemoteTestCaseBase): def gather_stop_reply_threads(self, post_startup_log_lines, thread_count): # Set up the inferior args. - inferior_args=[] + inferior_args = [] for i in range(thread_count - 1): inferior_args.append("thread:new") inferior_args.append("sleep:10") - procs = self.prep_debug_monitor_and_inferior(inferior_args=inferior_args) + procs = self.prep_debug_monitor_and_inferior( + inferior_args=inferior_args) # Assumes test_sequence has anything added needed to setup the initial state. # (Like optionally enabling QThreadsInStopReply.) @@ -28,17 +31,25 @@ class TestGdbRemoteThreadsInStopReply(gdbremote_testcase.GdbRemoteTestCaseBase): self.test_sequence.add_log_lines(post_startup_log_lines, True) self.test_sequence.add_log_lines([ "read packet: $c#63" - ], True) + ], True) context = self.expect_gdbremote_sequence() self.assertIsNotNone(context) # Give threads time to start up, then break. time.sleep(1) self.reset_test_sequence() - self.test_sequence.add_log_lines([ - "read packet: {}".format(chr(3)), - {"direction":"send", "regex":r"^\$T([0-9a-fA-F]+)([^#]+)#[0-9a-fA-F]{2}$", "capture":{1:"stop_result", 2:"key_vals_text"} }, - ], True) + self.test_sequence.add_log_lines( + [ + "read packet: {}".format( + chr(3)), + { + "direction": "send", + "regex": r"^\$T([0-9a-fA-F]+)([^#]+)#[0-9a-fA-F]{2}$", + "capture": { + 1: "stop_result", + 2: "key_vals_text"}}, + ], + True) context = self.expect_gdbremote_sequence() self.assertIsNotNone(context) @@ -49,11 +60,14 @@ class TestGdbRemoteThreadsInStopReply(gdbremote_testcase.GdbRemoteTestCaseBase): # Run, then stop the process, grab the stop reply content. self.reset_test_sequence() - self.test_sequence.add_log_lines([ - "read packet: $c#63", - "read packet: {}".format(chr(3)), - {"direction":"send", "regex":r"^\$T([0-9a-fA-F]+)([^#]+)#[0-9a-fA-F]{2}$", "capture":{1:"stop_result", 2:"key_vals_text"} }, - ], True) + self.test_sequence.add_log_lines(["read packet: $c#63", + "read packet: {}".format(chr(3)), + {"direction": "send", + "regex": r"^\$T([0-9a-fA-F]+)([^#]+)#[0-9a-fA-F]{2}$", + "capture": {1: "stop_result", + 2: "key_vals_text"}}, + ], + True) context = self.expect_gdbremote_sequence() self.assertIsNotNone(context) @@ -66,13 +80,15 @@ class TestGdbRemoteThreadsInStopReply(gdbremote_testcase.GdbRemoteTestCaseBase): # Pull out threads from stop response. stop_reply_threads_text = kv_dict.get("threads") if stop_reply_threads_text: - return [int(thread_id, 16) for thread_id in stop_reply_threads_text.split(",")] + return [int(thread_id, 16) + for thread_id in stop_reply_threads_text.split(",")] else: return [] def QListThreadsInStopReply_supported(self): procs = self.prep_debug_monitor_and_inferior() - self.test_sequence.add_log_lines(self.ENABLE_THREADS_IN_STOP_REPLY_ENTRIES, True) + self.test_sequence.add_log_lines( + self.ENABLE_THREADS_IN_STOP_REPLY_ENTRIES, True) context = self.expect_gdbremote_sequence() self.assertIsNotNone(context) @@ -92,8 +108,10 @@ class TestGdbRemoteThreadsInStopReply(gdbremote_testcase.GdbRemoteTestCaseBase): self.QListThreadsInStopReply_supported() def stop_reply_reports_multiple_threads(self, thread_count): - # Gather threads from stop notification when QThreadsInStopReply is enabled. - stop_reply_threads = self.gather_stop_reply_threads(self.ENABLE_THREADS_IN_STOP_REPLY_ENTRIES, thread_count) + # Gather threads from stop notification when QThreadsInStopReply is + # enabled. + stop_reply_threads = self.gather_stop_reply_threads( + self.ENABLE_THREADS_IN_STOP_REPLY_ENTRIES, thread_count) self.assertEqual(len(stop_reply_threads), thread_count) @debugserver_test @@ -111,7 +129,8 @@ class TestGdbRemoteThreadsInStopReply(gdbremote_testcase.GdbRemoteTestCaseBase): self.stop_reply_reports_multiple_threads(5) def no_QListThreadsInStopReply_supplies_no_threads(self, thread_count): - # Gather threads from stop notification when QThreadsInStopReply is not enabled. + # Gather threads from stop notification when QThreadsInStopReply is not + # enabled. stop_reply_threads = self.gather_stop_reply_threads(None, thread_count) self.assertEqual(len(stop_reply_threads), 0) @@ -130,8 +149,10 @@ class TestGdbRemoteThreadsInStopReply(gdbremote_testcase.GdbRemoteTestCaseBase): self.no_QListThreadsInStopReply_supplies_no_threads(5) def stop_reply_reports_correct_threads(self, thread_count): - # Gather threads from stop notification when QThreadsInStopReply is enabled. - stop_reply_threads = self.gather_stop_reply_threads(self.ENABLE_THREADS_IN_STOP_REPLY_ENTRIES, thread_count) + # Gather threads from stop notification when QThreadsInStopReply is + # enabled. + stop_reply_threads = self.gather_stop_reply_threads( + self.ENABLE_THREADS_IN_STOP_REPLY_ENTRIES, thread_count) self.assertEqual(len(stop_reply_threads), thread_count) # Gather threads from q{f,s}ThreadInfo. @@ -144,7 +165,7 @@ class TestGdbRemoteThreadsInStopReply(gdbremote_testcase.GdbRemoteTestCaseBase): threads = self.parse_threadinfo_packets(context) self.assertIsNotNone(threads) self.assertEqual(len(threads), thread_count) - + # Ensure each thread in q{f,s}ThreadInfo appears in stop reply threads for tid in threads: self.assertTrue(tid in stop_reply_threads) diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemote_qThreadStopInfo.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemote_qThreadStopInfo.py index b2b54e3f039..74e4849b0cb 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemote_qThreadStopInfo.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemote_qThreadStopInfo.py @@ -1,7 +1,6 @@ from __future__ import print_function - import sys import unittest2 @@ -10,6 +9,7 @@ from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * from lldbsuite.test import lldbutil + class TestGdbRemote_qThreadStopInfo(gdbremote_testcase.GdbRemoteTestCaseBase): mydir = TestBase.compute_mydir(__file__) @@ -17,27 +17,36 @@ class TestGdbRemote_qThreadStopInfo(gdbremote_testcase.GdbRemoteTestCaseBase): def gather_stop_replies_via_qThreadStopInfo(self, thread_count): # Set up the inferior args. - inferior_args=[] + inferior_args = [] for i in range(thread_count - 1): inferior_args.append("thread:new") inferior_args.append("sleep:10") - procs = self.prep_debug_monitor_and_inferior(inferior_args=inferior_args) + procs = self.prep_debug_monitor_and_inferior( + inferior_args=inferior_args) # Assumes test_sequence has anything added needed to setup the initial state. # (Like optionally enabling QThreadsInStopReply.) self.test_sequence.add_log_lines([ "read packet: $c#63" - ], True) + ], True) context = self.expect_gdbremote_sequence() self.assertIsNotNone(context) # Give threads time to start up, then break. time.sleep(1) self.reset_test_sequence() - self.test_sequence.add_log_lines([ - "read packet: {}".format(chr(3)), - {"direction":"send", "regex":r"^\$T([0-9a-fA-F]+)([^#]+)#[0-9a-fA-F]{2}$", "capture":{1:"stop_result", 2:"key_vals_text"} }, - ], True) + self.test_sequence.add_log_lines( + [ + "read packet: {}".format( + chr(3)), + { + "direction": "send", + "regex": r"^\$T([0-9a-fA-F]+)([^#]+)#[0-9a-fA-F]{2}$", + "capture": { + 1: "stop_result", + 2: "key_vals_text"}}, + ], + True) context = self.expect_gdbremote_sequence() self.assertIsNotNone(context) @@ -52,10 +61,17 @@ class TestGdbRemote_qThreadStopInfo(gdbremote_testcase.GdbRemoteTestCaseBase): for thread in threads: # Run the qThreadStopInfo command. self.reset_test_sequence() - self.test_sequence.add_log_lines([ - "read packet: $qThreadStopInfo{:x}#00".format(thread), - {"direction":"send", "regex":r"^\$T([0-9a-fA-F]+)([^#]+)#[0-9a-fA-F]{2}$", "capture":{1:"stop_result", 2:"key_vals_text"} }, - ], True) + self.test_sequence.add_log_lines( + [ + "read packet: $qThreadStopInfo{:x}#00".format(thread), + { + "direction": "send", + "regex": r"^\$T([0-9a-fA-F]+)([^#]+)#[0-9a-fA-F]{2}$", + "capture": { + 1: "stop_result", + 2: "key_vals_text"}}, + ], + True) context = self.expect_gdbremote_sequence() self.assertIsNotNone(context) @@ -65,7 +81,8 @@ class TestGdbRemote_qThreadStopInfo(gdbremote_testcase.GdbRemoteTestCaseBase): kv_dict = self.parse_key_val_dict(key_vals_text) self.assertIsNotNone(kv_dict) - # Verify there is a thread and that it matches the expected thread id. + # Verify there is a thread and that it matches the expected thread + # id. kv_thread = kv_dict.get("thread") self.assertIsNotNone(kv_thread) kv_thread_id = int(kv_thread, 16) @@ -99,12 +116,17 @@ class TestGdbRemote_qThreadStopInfo(gdbremote_testcase.GdbRemoteTestCaseBase): self.set_inferior_startup_launch() self.qThreadStopInfo_works_for_multiple_threads(self.THREAD_COUNT) - def qThreadStopInfo_only_reports_one_thread_stop_reason_during_interrupt(self, thread_count): + def qThreadStopInfo_only_reports_one_thread_stop_reason_during_interrupt( + self, thread_count): (stop_replies, _) = self.gather_stop_replies_via_qThreadStopInfo(thread_count) self.assertIsNotNone(stop_replies) - no_stop_reason_count = sum(1 for stop_reason in list(stop_replies.values()) if stop_reason == 0) - with_stop_reason_count = sum(1 for stop_reason in list(stop_replies.values()) if stop_reason != 0) + no_stop_reason_count = sum( + 1 for stop_reason in list( + stop_replies.values()) if stop_reason == 0) + with_stop_reason_count = sum( + 1 for stop_reason in list( + stop_replies.values()) if stop_reason != 0) # All but one thread should report no stop reason. self.assertEqual(no_stop_reason_count, thread_count - 1) @@ -113,20 +135,25 @@ class TestGdbRemote_qThreadStopInfo(gdbremote_testcase.GdbRemoteTestCaseBase): self.assertEqual(with_stop_reason_count, 1) @debugserver_test - def test_qThreadStopInfo_only_reports_one_thread_stop_reason_during_interrupt_debugserver(self): + def test_qThreadStopInfo_only_reports_one_thread_stop_reason_during_interrupt_debugserver( + self): self.init_debugserver_test() self.build() self.set_inferior_startup_launch() - self.qThreadStopInfo_only_reports_one_thread_stop_reason_during_interrupt(self.THREAD_COUNT) + self.qThreadStopInfo_only_reports_one_thread_stop_reason_during_interrupt( + self.THREAD_COUNT) @llgs_test - def test_qThreadStopInfo_only_reports_one_thread_stop_reason_during_interrupt_llgs(self): + def test_qThreadStopInfo_only_reports_one_thread_stop_reason_during_interrupt_llgs( + self): self.init_llgs_test() self.build() self.set_inferior_startup_launch() - self.qThreadStopInfo_only_reports_one_thread_stop_reason_during_interrupt(self.THREAD_COUNT) + self.qThreadStopInfo_only_reports_one_thread_stop_reason_during_interrupt( + self.THREAD_COUNT) - def qThreadStopInfo_has_valid_thread_names(self, thread_count, expected_thread_name): + def qThreadStopInfo_has_valid_thread_names( + self, thread_count, expected_thread_name): (_, thread_dicts) = self.gather_stop_replies_via_qThreadStopInfo(thread_count) self.assertIsNotNone(thread_dicts) @@ -143,7 +170,8 @@ class TestGdbRemote_qThreadStopInfo(gdbremote_testcase.GdbRemoteTestCaseBase): self.set_inferior_startup_launch() self.qThreadStopInfo_has_valid_thread_names(self.THREAD_COUNT, "a.out") - @skipUnlessPlatform(["linux"]) # test requires OS with set, equal thread names by default. + # test requires OS with set, equal thread names by default. + @skipUnlessPlatform(["linux"]) @llgs_test def test_qThreadStopInfo_has_valid_thread_names_llgs(self): self.init_llgs_test() diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemote_vCont.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemote_vCont.py index 335d96c2b07..1d98b9279f4 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemote_vCont.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestGdbRemote_vCont.py @@ -5,13 +5,15 @@ from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * from lldbsuite.test import lldbutil + class TestGdbRemote_vCont(gdbremote_testcase.GdbRemoteTestCaseBase): mydir = TestBase.compute_mydir(__file__) def vCont_supports_mode(self, mode, inferior_args=None): # Setup the stub and set the gdb remote command stream. - procs = self.prep_debug_monitor_and_inferior(inferior_args=inferior_args) + procs = self.prep_debug_monitor_and_inferior( + inferior_args=inferior_args) self.add_vCont_query_packets() # Run the gdb remote command stream. @@ -86,33 +88,58 @@ class TestGdbRemote_vCont(gdbremote_testcase.GdbRemoteTestCaseBase): self.vCont_supports_S() @debugserver_test - def test_single_step_only_steps_one_instruction_with_Hc_vCont_s_debugserver(self): + def test_single_step_only_steps_one_instruction_with_Hc_vCont_s_debugserver( + self): self.init_debugserver_test() self.build() self.set_inferior_startup_launch() - self.single_step_only_steps_one_instruction(use_Hc_packet=True, step_instruction="vCont;s") + self.single_step_only_steps_one_instruction( + use_Hc_packet=True, step_instruction="vCont;s") @llgs_test - @expectedFailureAndroid(bugnumber="llvm.org/pr24739", archs=["arm", "aarch64"]) - @expectedFailureAll(oslist=["linux"], archs=["arm", "aarch64"], bugnumber="llvm.org/pr24739") + @expectedFailureAndroid( + bugnumber="llvm.org/pr24739", + archs=[ + "arm", + "aarch64"]) + @expectedFailureAll( + oslist=["linux"], + archs=[ + "arm", + "aarch64"], + bugnumber="llvm.org/pr24739") def test_single_step_only_steps_one_instruction_with_Hc_vCont_s_llgs(self): self.init_llgs_test() self.build() self.set_inferior_startup_launch() - self.single_step_only_steps_one_instruction(use_Hc_packet=True, step_instruction="vCont;s") + self.single_step_only_steps_one_instruction( + use_Hc_packet=True, step_instruction="vCont;s") @debugserver_test - def test_single_step_only_steps_one_instruction_with_vCont_s_thread_debugserver(self): + def test_single_step_only_steps_one_instruction_with_vCont_s_thread_debugserver( + self): self.init_debugserver_test() self.build() self.set_inferior_startup_launch() - self.single_step_only_steps_one_instruction(use_Hc_packet=False, step_instruction="vCont;s:{thread}") + self.single_step_only_steps_one_instruction( + use_Hc_packet=False, step_instruction="vCont;s:{thread}") @llgs_test - @expectedFailureAndroid(bugnumber="llvm.org/pr24739", archs=["arm", "aarch64"]) - @expectedFailureAll(oslist=["linux"], archs=["arm", "aarch64"], bugnumber="llvm.org/pr24739") - def test_single_step_only_steps_one_instruction_with_vCont_s_thread_llgs(self): + @expectedFailureAndroid( + bugnumber="llvm.org/pr24739", + archs=[ + "arm", + "aarch64"]) + @expectedFailureAll( + oslist=["linux"], + archs=[ + "arm", + "aarch64"], + bugnumber="llvm.org/pr24739") + def test_single_step_only_steps_one_instruction_with_vCont_s_thread_llgs( + self): self.init_llgs_test() self.build() self.set_inferior_startup_launch() - self.single_step_only_steps_one_instruction(use_Hc_packet=False, step_instruction="vCont;s:{thread}") + self.single_step_only_steps_one_instruction( + use_Hc_packet=False, step_instruction="vCont;s:{thread}") diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestLldbGdbServer.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestLldbGdbServer.py index 9cc20c11f74..1ba49f33940 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestLldbGdbServer.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/TestLldbGdbServer.py @@ -13,7 +13,6 @@ the initial set of tests implemented. from __future__ import print_function - import unittest2 import gdbremote_testcase import lldbgdbserverutils @@ -23,6 +22,7 @@ from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * from lldbsuite.test import lldbutil + class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase): mydir = TestBase.compute_mydir(__file__) @@ -137,7 +137,7 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase): self.add_verified_launch_packets(launch_args) self.test_sequence.add_log_lines( ["read packet: $vCont;c#a8", - {"type":"output_match", "regex": self.maybe_strict_output_regex(r"hello, world\r\n")}, + {"type": "output_match", "regex": self.maybe_strict_output_regex(r"hello, world\r\n")}, "send packet: $W00#00"], True) @@ -168,12 +168,15 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase): self.add_no_ack_remote_stream() self.add_verified_launch_packets(launch_args) - self.test_sequence.add_log_lines( - ["read packet: $qC#00", - { "direction":"send", "regex":r"^\$QC([0-9a-fA-F]+)#", "capture":{1:"thread_id"} }, - "read packet: $?#00", - { "direction":"send", "regex":r"^\$T[0-9a-fA-F]{2}thread:([0-9a-fA-F]+)", "expect_captures":{1:"thread_id"} }], - True) + self.test_sequence.add_log_lines(["read packet: $qC#00", + {"direction": "send", + "regex": r"^\$QC([0-9a-fA-F]+)#", + "capture": {1: "thread_id"}}, + "read packet: $?#00", + {"direction": "send", + "regex": r"^\$T[0-9a-fA-F]{2}thread:([0-9a-fA-F]+)", + "expect_captures": {1: "thread_id"}}], + True) self.expect_gdbremote_sequence() @debugserver_test @@ -196,7 +199,8 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase): True) self.expect_gdbremote_sequence() - # Wait a moment for completed and now-detached inferior process to clear. + # Wait a moment for completed and now-detached inferior process to + # clear. time.sleep(1) if not lldb.remote_platform: @@ -204,8 +208,11 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase): poll_result = procs["inferior"].poll() self.assertIsNotNone(poll_result) - # Where possible, verify at the system level that the process is not running. - self.assertFalse(lldbgdbserverutils.process_is_running(procs["inferior"].pid, False)) + # Where possible, verify at the system level that the process is not + # running. + self.assertFalse( + lldbgdbserverutils.process_is_running( + procs["inferior"].pid, False)) @debugserver_test def test_attach_commandline_continue_app_exits_debugserver(self): @@ -232,7 +239,7 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase): self.add_verified_launch_packets(launch_args) self.test_sequence.add_log_lines( ["read packet: $qRegisterInfo0#00", - { "direction":"send", "regex":r"^\$(.+);#[0-9A-Fa-f]{2}", "capture":{1:"reginfo_0"} }], + {"direction": "send", "regex": r"^\$(.+);#[0-9A-Fa-f]{2}", "capture": {1: "reginfo_0"}}], True) # Run the stream @@ -241,7 +248,8 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase): reg_info_packet = context.get("reginfo_0") self.assertIsNotNone(reg_info_packet) - self.assert_valid_reg_info(lldbgdbserverutils.parse_reg_info_response(reg_info_packet)) + self.assert_valid_reg_info( + lldbgdbserverutils.parse_reg_info_response(reg_info_packet)) @debugserver_test @expectedFailureDarwin("llvm.org/pr25486") @@ -307,7 +315,8 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase): reg_infos = self.parse_register_info_packets(context) # Collect all generic registers found. - generic_regs = { reg_info['generic']:1 for reg_info in reg_infos if 'generic' in reg_info } + generic_regs = { + reg_info['generic']: 1 for reg_info in reg_infos if 'generic' in reg_info} # Ensure we have a program counter register. self.assertTrue('pc' in generic_regs) @@ -352,11 +361,13 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase): reg_infos = self.parse_register_info_packets(context) # Collect all register sets found. - register_sets = { reg_info['set']:1 for reg_info in reg_infos if 'set' in reg_info } + register_sets = { + reg_info['set']: 1 for reg_info in reg_infos if 'set' in reg_info} self.assertTrue(len(register_sets) >= 1) @debugserver_test - def test_qRegisterInfo_contains_at_least_one_register_set_debugserver(self): + def test_qRegisterInfo_contains_at_least_one_register_set_debugserver( + self): self.init_debugserver_test() self.build() self.qRegisterInfo_contains_at_least_one_register_set() @@ -406,8 +417,11 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase): reg_infos = self.parse_register_info_packets(context) # Collect all generics found. - register_sets = { reg_info['set']:1 for reg_info in reg_infos if 'set' in reg_info } - self.assertEqual(self.targetHasAVX(), "Advanced Vector Extensions" in register_sets) + register_sets = { + reg_info['set']: 1 for reg_info in reg_infos if 'set' in reg_info} + self.assertEqual( + self.targetHasAVX(), + "Advanced Vector Extensions" in register_sets) @llgs_test def test_qRegisterInfo_contains_avx_registers_llgs(self): @@ -464,7 +478,7 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase): self.add_threadinfo_collection_packets() self.test_sequence.add_log_lines( ["read packet: $qC#00", - { "direction":"send", "regex":r"^\$QC([0-9a-fA-F]+)#", "capture":{1:"thread_id"} } + {"direction": "send", "regex": r"^\$QC([0-9a-fA-F]+)#", "capture": {1: "thread_id"}} ], True) # Run the packet stream. @@ -532,7 +546,8 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase): for reg_info in reg_infos: # Skip registers that don't have a register set. For x86, these are # the DRx registers, which have no LLDB-kind register number and thus - # cannot be read via normal NativeRegisterContext::ReadRegister(reg_info,...) calls. + # cannot be read via normal + # NativeRegisterContext::ReadRegister(reg_info,...) calls. if not "set" in reg_info: continue @@ -542,7 +557,7 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase): # Run the register query self.test_sequence.add_log_lines( ["read packet: $p{0:x}#00".format(reg_index), - { "direction":"send", "regex":r"^\$([0-9a-fA-F]+)#", "capture":{1:"p_response"} }], + {"direction": "send", "regex": r"^\$([0-9a-fA-F]+)#", "capture": {1: "p_response"}}], True) context = self.expect_gdbremote_sequence() self.assertIsNotNone(context) @@ -556,28 +571,32 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase): reg_index += 1 @debugserver_test - def test_p_returns_correct_data_size_for_each_qRegisterInfo_launch_debugserver(self): + def test_p_returns_correct_data_size_for_each_qRegisterInfo_launch_debugserver( + self): self.init_debugserver_test() self.build() self.set_inferior_startup_launch() self.p_returns_correct_data_size_for_each_qRegisterInfo() @llgs_test - def test_p_returns_correct_data_size_for_each_qRegisterInfo_launch_llgs(self): + def test_p_returns_correct_data_size_for_each_qRegisterInfo_launch_llgs( + self): self.init_llgs_test() self.build() self.set_inferior_startup_launch() self.p_returns_correct_data_size_for_each_qRegisterInfo() @debugserver_test - def test_p_returns_correct_data_size_for_each_qRegisterInfo_attach_debugserver(self): + def test_p_returns_correct_data_size_for_each_qRegisterInfo_attach_debugserver( + self): self.init_debugserver_test() self.build() self.set_inferior_startup_attach() self.p_returns_correct_data_size_for_each_qRegisterInfo() @llgs_test - def test_p_returns_correct_data_size_for_each_qRegisterInfo_attach_llgs(self): + def test_p_returns_correct_data_size_for_each_qRegisterInfo_attach_llgs( + self): self.init_llgs_test() self.build() self.set_inferior_startup_attach() @@ -585,9 +604,12 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase): def Hg_switches_to_3_threads(self): # Startup the inferior with three threads (main + 2 new ones). - procs = self.prep_debug_monitor_and_inferior(inferior_args=["thread:new", "thread:new"]) + procs = self.prep_debug_monitor_and_inferior( + inferior_args=["thread:new", "thread:new"]) - # Let the inferior process have a few moments to start up the thread when launched. (The launch scenario has no time to run, so threads won't be there yet.) + # Let the inferior process have a few moments to start up the thread + # when launched. (The launch scenario has no time to run, so threads + # won't be there yet.) self.run_process_then_stop(run_seconds=1) # Wait at most x seconds for 3 threads to be present. @@ -602,7 +624,7 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase): ["read packet: $Hg{0:x}#00".format(thread), # Set current thread. "send packet: $OK#00", "read packet: $qC#00", - { "direction":"send", "regex":r"^\$QC([0-9a-fA-F]+)#", "capture":{1:"thread_id"} }], + {"direction": "send", "regex": r"^\$QC([0-9a-fA-F]+)#", "capture": {1: "thread_id"}}], True) context = self.expect_gdbremote_sequence() @@ -648,7 +670,7 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase): # Startup the inferior with three threads (main + NUM_THREADS-1 worker threads). # inferior_args=["thread:print-ids"] - inferior_args=["thread:segfault"] + inferior_args = ["thread:segfault"] for i in range(NUM_THREADS - 1): # if i > 0: # Give time between thread creation/segfaulting for the handler to work. @@ -656,8 +678,10 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase): inferior_args.append("thread:new") inferior_args.append("sleep:10") - # Launch/attach. (In our case, this should only ever be launched since we need inferior stdout/stderr). - procs = self.prep_debug_monitor_and_inferior(inferior_args=inferior_args) + # Launch/attach. (In our case, this should only ever be launched since + # we need inferior stdout/stderr). + procs = self.prep_debug_monitor_and_inferior( + inferior_args=inferior_args) self.test_sequence.add_log_lines(["read packet: $c#63"], True) context = self.expect_gdbremote_sequence() @@ -675,9 +699,11 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase): for i in range(NUM_THREADS - 1): # Run until SIGSEGV comes in. self.reset_test_sequence() - self.test_sequence.add_log_lines( - [{"direction":"send", "regex":r"^\$T([0-9a-fA-F]{2})thread:([0-9a-fA-F]+);", "capture":{1:"signo", 2:"thread_id"} } - ], True) + self.test_sequence.add_log_lines([{"direction": "send", + "regex": r"^\$T([0-9a-fA-F]{2})thread:([0-9a-fA-F]+);", + "capture": {1: "signo", + 2: "thread_id"}}], + True) context = self.expect_gdbremote_sequence(timeout_seconds=10) self.assertIsNotNone(context) @@ -693,23 +719,24 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase): self.reset_test_sequence() self.test_sequence.add_log_lines( [ - # Set the continue thread. - "read packet: $Hc{0:x}#00".format(thread_id), # Set current thread. - "send packet: $OK#00", - - # Continue sending the signal number to the continue thread. - # The commented out packet is a way to do this same operation without using - # a $Hc (but this test is testing $Hc, so we'll stick with the former). - "read packet: $C{0:x}#00".format(lldbutil.get_signal_number('SIGUSR1')), - # "read packet: $vCont;C{0:x}:{1:x};c#00".format(lldbutil.get_signal_number('SIGUSR1'), thread_id), - - # FIXME: Linux does not report the thread stop on the delivered signal (SIGUSR1 here). MacOSX debugserver does. - # But MacOSX debugserver isn't guaranteeing the thread the signal handler runs on, so currently its an XFAIL. - # Need to rectify behavior here. The linux behavior is more intuitive to me since we're essentially swapping out - # an about-to-be-delivered signal (for which we already sent a stop packet) to a different signal. - # {"direction":"send", "regex":r"^\$T([0-9a-fA-F]{2})thread:([0-9a-fA-F]+);", "capture":{1:"stop_signo", 2:"stop_thread_id"} }, - # "read packet: $c#63", - { "type":"output_match", "regex":r"^received SIGUSR1 on thread id: ([0-9a-fA-F]+)\r\nthread ([0-9a-fA-F]+): past SIGSEGV\r\n", "capture":{ 1:"print_thread_id", 2:"post_handle_thread_id" } }, + # Set the continue thread. + # Set current thread. + "read packet: $Hc{0:x}#00".format(thread_id), + "send packet: $OK#00", + + # Continue sending the signal number to the continue thread. + # The commented out packet is a way to do this same operation without using + # a $Hc (but this test is testing $Hc, so we'll stick with the former). + "read packet: $C{0:x}#00".format(lldbutil.get_signal_number('SIGUSR1')), + # "read packet: $vCont;C{0:x}:{1:x};c#00".format(lldbutil.get_signal_number('SIGUSR1'), thread_id), + + # FIXME: Linux does not report the thread stop on the delivered signal (SIGUSR1 here). MacOSX debugserver does. + # But MacOSX debugserver isn't guaranteeing the thread the signal handler runs on, so currently its an XFAIL. + # Need to rectify behavior here. The linux behavior is more intuitive to me since we're essentially swapping out + # an about-to-be-delivered signal (for which we already sent a stop packet) to a different signal. + # {"direction":"send", "regex":r"^\$T([0-9a-fA-F]{2})thread:([0-9a-fA-F]+);", "capture":{1:"stop_signo", 2:"stop_thread_id"} }, + # "read packet: $c#63", + {"type": "output_match", "regex": r"^received SIGUSR1 on thread id: ([0-9a-fA-F]+)\r\nthread ([0-9a-fA-F]+): past SIGSEGV\r\n", "capture": {1: "print_thread_id", 2: "post_handle_thread_id"}}, ], True) @@ -727,16 +754,20 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase): # self.assertIsNotNone(stop_thread_id) # self.assertEquals(int(stop_thread_id,16), thread_id) - # Ensure we haven't seen this thread id yet. The inferior's self-obtained thread ids are not guaranteed to match the stub tids (at least on MacOSX). + # Ensure we haven't seen this thread id yet. The inferior's + # self-obtained thread ids are not guaranteed to match the stub + # tids (at least on MacOSX). print_thread_id = context.get("print_thread_id") self.assertIsNotNone(print_thread_id) print_thread_id = int(print_thread_id, 16) self.assertFalse(print_thread_id in print_thread_ids) - - # Now remember this print (i.e. inferior-reflected) thread id and ensure we don't hit it again. + + # Now remember this print (i.e. inferior-reflected) thread id and + # ensure we don't hit it again. print_thread_ids[print_thread_id] = 1 - # Ensure post signal-handle thread id matches the thread that initially raised the SIGSEGV. + # Ensure post signal-handle thread id matches the thread that + # initially raised the SIGSEGV. post_handle_thread_id = context.get("post_handle_thread_id") self.assertIsNotNone(post_handle_thread_id) post_handle_thread_id = int(post_handle_thread_id, 16) @@ -748,7 +779,8 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase): self.init_debugserver_test() self.build() self.set_inferior_startup_launch() - # Darwin debugserver translates some signals like SIGSEGV into some gdb expectations about fixed signal numbers. + # Darwin debugserver translates some signals like SIGSEGV into some gdb + # expectations about fixed signal numbers. self.Hc_then_Csignal_signals_correct_thread(self.TARGET_EXC_BAD_ACCESS) @llgs_test @@ -756,29 +788,35 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase): self.init_llgs_test() self.build() self.set_inferior_startup_launch() - self.Hc_then_Csignal_signals_correct_thread(lldbutil.get_signal_number('SIGSEGV')) + self.Hc_then_Csignal_signals_correct_thread( + lldbutil.get_signal_number('SIGSEGV')) def m_packet_reads_memory(self): - # This is the memory we will write into the inferior and then ensure we can read back with $m. + # This is the memory we will write into the inferior and then ensure we + # can read back with $m. MEMORY_CONTENTS = "Test contents 0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz" # Start up the inferior. procs = self.prep_debug_monitor_and_inferior( - inferior_args=["set-message:%s" % MEMORY_CONTENTS, "get-data-address-hex:g_message", "sleep:5"]) + inferior_args=[ + "set-message:%s" % + MEMORY_CONTENTS, + "get-data-address-hex:g_message", + "sleep:5"]) # Run the process self.test_sequence.add_log_lines( [ - # Start running after initial stop. - "read packet: $c#63", - # Match output line that prints the memory address of the message buffer within the inferior. - # Note we require launch-only testing so we can get inferior otuput. - { "type":"output_match", "regex":self.maybe_strict_output_regex(r"data address: 0x([0-9a-fA-F]+)\r\n"), - "capture":{ 1:"message_address"} }, - # Now stop the inferior. - "read packet: {}".format(chr(3)), - # And wait for the stop notification. - {"direction":"send", "regex":r"^\$T([0-9a-fA-F]{2})thread:([0-9a-fA-F]+);", "capture":{1:"stop_signo", 2:"stop_thread_id"} }], + # Start running after initial stop. + "read packet: $c#63", + # Match output line that prints the memory address of the message buffer within the inferior. + # Note we require launch-only testing so we can get inferior otuput. + {"type": "output_match", "regex": self.maybe_strict_output_regex(r"data address: 0x([0-9a-fA-F]+)\r\n"), + "capture": {1: "message_address"}}, + # Now stop the inferior. + "read packet: {}".format(chr(3)), + # And wait for the stop notification. + {"direction": "send", "regex": r"^\$T([0-9a-fA-F]{2})thread:([0-9a-fA-F]+);", "capture": {1: "stop_signo", 2: "stop_thread_id"}}], True) # Run the packet stream. @@ -793,7 +831,7 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase): self.reset_test_sequence() self.test_sequence.add_log_lines( ["read packet: $m{0:x},{1:x}#00".format(message_address, len(MEMORY_CONTENTS)), - {"direction":"send", "regex":r"^\$(.+)#[0-9a-fA-F]{2}$", "capture":{1:"read_contents"} }], + {"direction": "send", "regex": r"^\$(.+)#[0-9a-fA-F]{2}$", "capture": {1: "read_contents"}}], True) # Run the packet stream. @@ -852,16 +890,16 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase): # Run the process self.test_sequence.add_log_lines( [ - # Start running after initial stop. - "read packet: $c#63", - # Match output line that prints the memory address of the message buffer within the inferior. - # Note we require launch-only testing so we can get inferior otuput. - { "type":"output_match", "regex":self.maybe_strict_output_regex(r"code address: 0x([0-9a-fA-F]+)\r\n"), - "capture":{ 1:"code_address"} }, - # Now stop the inferior. - "read packet: {}".format(chr(3)), - # And wait for the stop notification. - {"direction":"send", "regex":r"^\$T([0-9a-fA-F]{2})thread:([0-9a-fA-F]+);", "capture":{1:"stop_signo", 2:"stop_thread_id"} }], + # Start running after initial stop. + "read packet: $c#63", + # Match output line that prints the memory address of the message buffer within the inferior. + # Note we require launch-only testing so we can get inferior otuput. + {"type": "output_match", "regex": self.maybe_strict_output_regex(r"code address: 0x([0-9a-fA-F]+)\r\n"), + "capture": {1: "code_address"}}, + # Now stop the inferior. + "read packet: {}".format(chr(3)), + # And wait for the stop notification. + {"direction": "send", "regex": r"^\$T([0-9a-fA-F]{2})thread:([0-9a-fA-F]+);", "capture": {1: "stop_signo", 2: "stop_thread_id"}}], True) # Run the packet stream. @@ -893,7 +931,8 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase): self.assert_address_within_memory_region(code_address, mem_region_dict) @debugserver_test - def test_qMemoryRegionInfo_reports_code_address_as_executable_debugserver(self): + def test_qMemoryRegionInfo_reports_code_address_as_executable_debugserver( + self): self.init_debugserver_test() self.build() self.set_inferior_startup_launch() @@ -914,16 +953,16 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase): # Run the process self.test_sequence.add_log_lines( [ - # Start running after initial stop. - "read packet: $c#63", - # Match output line that prints the memory address of the message buffer within the inferior. - # Note we require launch-only testing so we can get inferior otuput. - { "type":"output_match", "regex":self.maybe_strict_output_regex(r"stack address: 0x([0-9a-fA-F]+)\r\n"), - "capture":{ 1:"stack_address"} }, - # Now stop the inferior. - "read packet: {}".format(chr(3)), - # And wait for the stop notification. - {"direction":"send", "regex":r"^\$T([0-9a-fA-F]{2})thread:([0-9a-fA-F]+);", "capture":{1:"stop_signo", 2:"stop_thread_id"} }], + # Start running after initial stop. + "read packet: $c#63", + # Match output line that prints the memory address of the message buffer within the inferior. + # Note we require launch-only testing so we can get inferior otuput. + {"type": "output_match", "regex": self.maybe_strict_output_regex(r"stack address: 0x([0-9a-fA-F]+)\r\n"), + "capture": {1: "stack_address"}}, + # Now stop the inferior. + "read packet: {}".format(chr(3)), + # And wait for the stop notification. + {"direction": "send", "regex": r"^\$T([0-9a-fA-F]{2})thread:([0-9a-fA-F]+);", "capture": {1: "stop_signo", 2: "stop_thread_id"}}], True) # Run the packet stream. @@ -952,17 +991,20 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase): self.assertTrue("w" in mem_region_dict["permissions"]) # Ensure the start address and size encompass the address we queried. - self.assert_address_within_memory_region(stack_address, mem_region_dict) + self.assert_address_within_memory_region( + stack_address, mem_region_dict) @debugserver_test - def test_qMemoryRegionInfo_reports_stack_address_as_readable_writeable_debugserver(self): + def test_qMemoryRegionInfo_reports_stack_address_as_readable_writeable_debugserver( + self): self.init_debugserver_test() self.build() self.set_inferior_startup_launch() self.qMemoryRegionInfo_reports_stack_address_as_readable_writeable() @llgs_test - def test_qMemoryRegionInfo_reports_stack_address_as_readable_writeable_llgs(self): + def test_qMemoryRegionInfo_reports_stack_address_as_readable_writeable_llgs( + self): self.init_llgs_test() self.build() self.set_inferior_startup_launch() @@ -976,16 +1018,16 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase): # Run the process self.test_sequence.add_log_lines( [ - # Start running after initial stop. - "read packet: $c#63", - # Match output line that prints the memory address of the message buffer within the inferior. - # Note we require launch-only testing so we can get inferior otuput. - { "type":"output_match", "regex":self.maybe_strict_output_regex(r"heap address: 0x([0-9a-fA-F]+)\r\n"), - "capture":{ 1:"heap_address"} }, - # Now stop the inferior. - "read packet: {}".format(chr(3)), - # And wait for the stop notification. - {"direction":"send", "regex":r"^\$T([0-9a-fA-F]{2})thread:([0-9a-fA-F]+);", "capture":{1:"stop_signo", 2:"stop_thread_id"} }], + # Start running after initial stop. + "read packet: $c#63", + # Match output line that prints the memory address of the message buffer within the inferior. + # Note we require launch-only testing so we can get inferior otuput. + {"type": "output_match", "regex": self.maybe_strict_output_regex(r"heap address: 0x([0-9a-fA-F]+)\r\n"), + "capture": {1: "heap_address"}}, + # Now stop the inferior. + "read packet: {}".format(chr(3)), + # And wait for the stop notification. + {"direction": "send", "regex": r"^\$T([0-9a-fA-F]{2})thread:([0-9a-fA-F]+);", "capture": {1: "stop_signo", 2: "stop_thread_id"}}], True) # Run the packet stream. @@ -1016,16 +1058,17 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase): # Ensure the start address and size encompass the address we queried. self.assert_address_within_memory_region(heap_address, mem_region_dict) - @debugserver_test - def test_qMemoryRegionInfo_reports_heap_address_as_readable_writeable_debugserver(self): + def test_qMemoryRegionInfo_reports_heap_address_as_readable_writeable_debugserver( + self): self.init_debugserver_test() self.build() self.set_inferior_startup_launch() self.qMemoryRegionInfo_reports_heap_address_as_readable_writeable() @llgs_test - def test_qMemoryRegionInfo_reports_heap_address_as_readable_writeable_llgs(self): + def test_qMemoryRegionInfo_reports_heap_address_as_readable_writeable_llgs( + self): self.init_llgs_test() self.build() self.set_inferior_startup_launch() @@ -1034,29 +1077,33 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase): def software_breakpoint_set_and_remove_work(self): # Start up the inferior. procs = self.prep_debug_monitor_and_inferior( - inferior_args=["get-code-address-hex:hello", "sleep:1", "call-function:hello"]) + inferior_args=[ + "get-code-address-hex:hello", + "sleep:1", + "call-function:hello"]) # Run the process self.add_register_info_collection_packets() self.add_process_info_collection_packets() self.test_sequence.add_log_lines( - [# Start running after initial stop. - "read packet: $c#63", - # Match output line that prints the memory address of the function call entry point. - # Note we require launch-only testing so we can get inferior otuput. - { "type":"output_match", "regex":self.maybe_strict_output_regex(r"code address: 0x([0-9a-fA-F]+)\r\n"), - "capture":{ 1:"function_address"} }, - # Now stop the inferior. - "read packet: {}".format(chr(3)), - # And wait for the stop notification. - {"direction":"send", "regex":r"^\$T([0-9a-fA-F]{2})thread:([0-9a-fA-F]+);", "capture":{1:"stop_signo", 2:"stop_thread_id"} }], + [ # Start running after initial stop. + "read packet: $c#63", + # Match output line that prints the memory address of the function call entry point. + # Note we require launch-only testing so we can get inferior otuput. + {"type": "output_match", "regex": self.maybe_strict_output_regex(r"code address: 0x([0-9a-fA-F]+)\r\n"), + "capture": {1: "function_address"}}, + # Now stop the inferior. + "read packet: {}".format(chr(3)), + # And wait for the stop notification. + {"direction": "send", "regex": r"^\$T([0-9a-fA-F]{2})thread:([0-9a-fA-F]+);", "capture": {1: "stop_signo", 2: "stop_thread_id"}}], True) # Run the packet stream. context = self.expect_gdbremote_sequence() self.assertIsNotNone(context) - # Gather process info - we need endian of target to handle register value conversions. + # Gather process info - we need endian of target to handle register + # value conversions. process_info = self.parse_process_info_response(context) endian = process_info.get("endian") self.assertIsNotNone(endian) @@ -1078,7 +1125,10 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase): else: BREAKPOINT_KIND = 1 self.reset_test_sequence() - self.add_set_breakpoint_packets(function_address, do_continue=True, breakpoint_kind=BREAKPOINT_KIND) + self.add_set_breakpoint_packets( + function_address, + do_continue=True, + breakpoint_kind=BREAKPOINT_KIND) # Run the packet stream. context = self.expect_gdbremote_sequence() @@ -1087,7 +1137,8 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase): # Verify the stop signal reported was the breakpoint signal number. stop_signo = context.get("stop_signo") self.assertIsNotNone(stop_signo) - self.assertEqual(int(stop_signo,16), lldbutil.get_signal_number('SIGTRAP')) + self.assertEqual(int(stop_signo, 16), + lldbutil.get_signal_number('SIGTRAP')) # Ensure we did not receive any output. If the breakpoint was not set, we would # see output (from a launched process with captured stdio) printing a hello, world message. @@ -1099,37 +1150,43 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase): self.reset_test_sequence() self.test_sequence.add_log_lines( [ - # Print the PC. This should match the breakpoint address. - "read packet: $p{0:x}#00".format(pc_lldb_reg_index), - # Capture $p results. - { "direction":"send", "regex":r"^\$([0-9a-fA-F]+)#", "capture":{1:"p_response"} }, - ], True) - + # Print the PC. This should match the breakpoint address. + "read packet: $p{0:x}#00".format(pc_lldb_reg_index), + # Capture $p results. + {"direction": "send", + "regex": r"^\$([0-9a-fA-F]+)#", + "capture": {1: "p_response"}}, + ], True) + context = self.expect_gdbremote_sequence() self.assertIsNotNone(context) - - # Verify the PC is where we expect. Note response is in endianness of the inferior. + + # Verify the PC is where we expect. Note response is in endianness of + # the inferior. p_response = context.get("p_response") self.assertIsNotNone(p_response) # Convert from target endian to int. - returned_pc = lldbgdbserverutils.unpack_register_hex_unsigned(endian, p_response) + returned_pc = lldbgdbserverutils.unpack_register_hex_unsigned( + endian, p_response) self.assertEqual(returned_pc, function_address) - # Verify that a breakpoint remove and continue gets us the expected output. + # Verify that a breakpoint remove and continue gets us the expected + # output. self.reset_test_sequence() self.test_sequence.add_log_lines( [ - # Remove the breakpoint. - "read packet: $z0,{0:x},{1}#00".format(function_address, BREAKPOINT_KIND), - # Verify the stub could unset it. - "send packet: $OK#00", - # Continue running. - "read packet: $c#63", - # We should now receive the output from the call. - { "type":"output_match", "regex":r"^hello, world\r\n$" }, - # And wait for program completion. - {"direction":"send", "regex":r"^\$W00(.*)#[0-9a-fA-F]{2}$" }, + # Remove the breakpoint. + "read packet: $z0,{0:x},{1}#00".format( + function_address, BREAKPOINT_KIND), + # Verify the stub could unset it. + "send packet: $OK#00", + # Continue running. + "read packet: $c#63", + # We should now receive the output from the call. + {"type": "output_match", "regex": r"^hello, world\r\n$"}, + # And wait for program completion. + {"direction": "send", "regex": r"^\$W00(.*)#[0-9a-fA-F]{2}$"}, ], True) context = self.expect_gdbremote_sequence() @@ -1190,19 +1247,24 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase): TEST_MESSAGE = "Hello, memory" # Start up the stub and start/prep the inferior. - procs = self.prep_debug_monitor_and_inferior(inferior_args=["set-message:xxxxxxxxxxxxxX", "get-data-address-hex:g_message", "sleep:1", "print-message:"]) + procs = self.prep_debug_monitor_and_inferior( + inferior_args=[ + "set-message:xxxxxxxxxxxxxX", + "get-data-address-hex:g_message", + "sleep:1", + "print-message:"]) self.test_sequence.add_log_lines( [ - # Start running after initial stop. - "read packet: $c#63", - # Match output line that prints the memory address of the message buffer within the inferior. - # Note we require launch-only testing so we can get inferior otuput. - { "type":"output_match", "regex":self.maybe_strict_output_regex(r"data address: 0x([0-9a-fA-F]+)\r\n"), - "capture":{ 1:"message_address"} }, - # Now stop the inferior. - "read packet: {}".format(chr(3)), - # And wait for the stop notification. - {"direction":"send", "regex":r"^\$T([0-9a-fA-F]{2})thread:([0-9a-fA-F]+);", "capture":{1:"stop_signo", 2:"stop_thread_id"} }], + # Start running after initial stop. + "read packet: $c#63", + # Match output line that prints the memory address of the message buffer within the inferior. + # Note we require launch-only testing so we can get inferior otuput. + {"type": "output_match", "regex": self.maybe_strict_output_regex(r"data address: 0x([0-9a-fA-F]+)\r\n"), + "capture": {1: "message_address"}}, + # Now stop the inferior. + "read packet: {}".format(chr(3)), + # And wait for the stop notification. + {"direction": "send", "regex": r"^\$T([0-9a-fA-F]{2})thread:([0-9a-fA-F]+);", "capture": {1: "stop_signo", 2: "stop_thread_id"}}], True) context = self.expect_gdbremote_sequence() self.assertIsNotNone(context) @@ -1229,9 +1291,9 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase): "read packet: $x{0:x},4#00".format(message_address), "send packet: ${0}#00".format(TEST_MESSAGE[0:4]), "read packet: $c#63", - { "type":"output_match", "regex":r"^message: (.+)\r\n$", "capture":{ 1:"printed_message"} }, + {"type": "output_match", "regex": r"^message: (.+)\r\n$", "capture": {1: "printed_message"}}, "send packet: $W00#00", - ], True) + ], True) context = self.expect_gdbremote_sequence() self.assertIsNotNone(context) @@ -1274,17 +1336,21 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase): endian = process_info.get("endian") self.assertIsNotNone(endian) - # Pull out the register infos that we think we can bit flip successfully,. - gpr_reg_infos = [reg_info for reg_info in reg_infos if self.is_bit_flippable_register(reg_info)] + # Pull out the register infos that we think we can bit flip + # successfully,. + gpr_reg_infos = [ + reg_info for reg_info in reg_infos if self.is_bit_flippable_register(reg_info)] self.assertTrue(len(gpr_reg_infos) > 0) # Write flipped bit pattern of existing value to each register. - (successful_writes, failed_writes) = self.flip_all_bits_in_each_register_value(gpr_reg_infos, endian) + (successful_writes, failed_writes) = self.flip_all_bits_in_each_register_value( + gpr_reg_infos, endian) # print("successful writes: {}, failed writes: {}".format(successful_writes, failed_writes)) self.assertTrue(successful_writes > 0) # Note: as of this moment, a hefty number of the GPR writes are failing with E32 (everything except rax-rdx, rdi, rsi, rbp). - # Come back to this. I have the test rigged to verify that at least some of the bit-flip writes work. + # Come back to this. I have the test rigged to verify that at least some + # of the bit-flip writes work. @debugserver_test def test_P_writes_all_gpr_registers_debugserver(self): self.init_debugserver_test() @@ -1301,7 +1367,8 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase): def P_and_p_thread_suffix_work(self): # Startup the inferior with three threads. - procs = self.prep_debug_monitor_and_inferior(inferior_args=["thread:new", "thread:new"]) + procs = self.prep_debug_monitor_and_inferior( + inferior_args=["thread:new", "thread:new"]) self.add_thread_suffix_request_packets() self.add_register_info_collection_packets() self.add_process_info_collection_packets() @@ -1323,7 +1390,8 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase): reg_byte_size = int(reg_infos[reg_index]["bitsize"]) / 8 self.assertTrue(reg_byte_size > 0) - # Run the process a bit so threads can start up, and collect register info. + # Run the process a bit so threads can start up, and collect register + # info. context = self.run_process_then_stop(run_seconds=1) self.assertIsNotNone(context) @@ -1338,59 +1406,75 @@ class LldbGdbServerTestCase(gdbremote_testcase.GdbRemoteTestCaseBase): # Set the same register in each of 3 threads to a different value. # Verify each one has the unique value. for thread in threads: - # If we don't have a next value yet, start it with the initial read value + 1 + # If we don't have a next value yet, start it with the initial read + # value + 1 if not next_value: # Read pre-existing register value. self.reset_test_sequence() self.test_sequence.add_log_lines( ["read packet: $p{0:x};thread:{1:x}#00".format(reg_index, thread), - { "direction":"send", "regex":r"^\$([0-9a-fA-F]+)#", "capture":{1:"p_response"} }, - ], True) + {"direction": "send", "regex": r"^\$([0-9a-fA-F]+)#", "capture": {1: "p_response"}}, + ], True) context = self.expect_gdbremote_sequence() self.assertIsNotNone(context) - # Set the next value to use for writing as the increment plus current value. + # Set the next value to use for writing as the increment plus + # current value. p_response = context.get("p_response") self.assertIsNotNone(p_response) - next_value = lldbgdbserverutils.unpack_register_hex_unsigned(endian, p_response) + next_value = lldbgdbserverutils.unpack_register_hex_unsigned( + endian, p_response) # Set new value using P and thread suffix. self.reset_test_sequence() self.test_sequence.add_log_lines( - ["read packet: $P{0:x}={1};thread:{2:x}#00".format(reg_index, lldbgdbserverutils.pack_register_hex(endian, next_value, byte_size=reg_byte_size), thread), - "send packet: $OK#00", - ], True) + [ + "read packet: $P{0:x}={1};thread:{2:x}#00".format( + reg_index, + lldbgdbserverutils.pack_register_hex( + endian, + next_value, + byte_size=reg_byte_size), + thread), + "send packet: $OK#00", + ], + True) context = self.expect_gdbremote_sequence() self.assertIsNotNone(context) # Save the value we set. expected_reg_values.append(next_value) - # Increment value for next thread to use (we want them all different so we can verify they wrote to each thread correctly next.) + # Increment value for next thread to use (we want them all + # different so we can verify they wrote to each thread correctly + # next.) next_value += register_increment - # Revisit each thread and verify they have the expected value set for the register we wrote. + # Revisit each thread and verify they have the expected value set for + # the register we wrote. thread_index = 0 for thread in threads: # Read pre-existing register value. self.reset_test_sequence() self.test_sequence.add_log_lines( ["read packet: $p{0:x};thread:{1:x}#00".format(reg_index, thread), - { "direction":"send", "regex":r"^\$([0-9a-fA-F]+)#", "capture":{1:"p_response"} }, - ], True) + {"direction": "send", "regex": r"^\$([0-9a-fA-F]+)#", "capture": {1: "p_response"}}, + ], True) context = self.expect_gdbremote_sequence() self.assertIsNotNone(context) # Get the register value. p_response = context.get("p_response") self.assertIsNotNone(p_response) - read_value = lldbgdbserverutils.unpack_register_hex_unsigned(endian, p_response) + read_value = lldbgdbserverutils.unpack_register_hex_unsigned( + endian, p_response) # Make sure we read back what we wrote. self.assertEqual(read_value, expected_reg_values[thread_index]) thread_index += 1 - # Note: as of this moment, a hefty number of the GPR writes are failing with E32 (everything except rax-rdx, rdi, rsi, rbp). + # Note: as of this moment, a hefty number of the GPR writes are failing + # with E32 (everything except rax-rdx, rdi, rsi, rbp). @debugserver_test def test_P_and_p_thread_suffix_work_debugserver(self): self.init_debugserver_test() diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/commandline/TestStubReverseConnect.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/commandline/TestStubReverseConnect.py index 6894d1ceacc..c1a63af5424 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/commandline/TestStubReverseConnect.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/commandline/TestStubReverseConnect.py @@ -10,6 +10,7 @@ from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * from lldbsuite.test import lldbutil + class TestStubReverseConnect(gdbremote_testcase.GdbRemoteTestCaseBase): mydir = TestBase.compute_mydir(__file__) @@ -30,7 +31,7 @@ class TestStubReverseConnect(gdbremote_testcase.GdbRemoteTestCaseBase): self.assertIsNotNone(sock) sock.settimeout(timeout_seconds) - sock.bind(("127.0.0.1",0)) + sock.bind(("127.0.0.1", 0)) sock.listen(1) def tear_down_listener(): @@ -56,18 +57,25 @@ class TestStubReverseConnect(gdbremote_testcase.GdbRemoteTestCaseBase): triple = self.dbg.GetSelectedPlatform().GetTriple() if re.match(".*-.*-.*-android", triple): - self.forward_adb_port(self.port, self.port, "reverse", self.stub_device) + self.forward_adb_port( + self.port, + self.port, + "reverse", + self.stub_device) # Start the stub. server = self.launch_debug_monitor(logfile=sys.stdout) self.assertIsNotNone(server) - self.assertTrue(lldbgdbserverutils.process_is_running(server.pid, True)) + self.assertTrue( + lldbgdbserverutils.process_is_running( + server.pid, True)) # Listen for the stub's connection to us. (stub_socket, address) = self.listener_socket.accept() self.assertIsNotNone(stub_socket) self.assertIsNotNone(address) - print("connected to stub {} on {}".format(address, stub_socket.getsockname())) + print("connected to stub {} on {}".format( + address, stub_socket.getsockname())) # Verify we can do the handshake. If that works, we'll call it good. self.do_handshake(stub_socket, timeout_seconds=self._DEFAULT_TIMEOUT) @@ -82,7 +90,7 @@ class TestStubReverseConnect(gdbremote_testcase.GdbRemoteTestCaseBase): self.reverse_connect_works() @llgs_test - @skipIfRemote # reverse connect is not a supported use case for now + @skipIfRemote # reverse connect is not a supported use case for now def test_reverse_connect_works_llgs(self): self.init_llgs_test(use_named_pipe=False) self.set_inferior_startup_launch() diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/commandline/TestStubSetSID.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/commandline/TestStubSetSID.py index bda93155d27..27daf30f189 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/commandline/TestStubSetSID.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/commandline/TestStubSetSID.py @@ -1,7 +1,6 @@ from __future__ import print_function - import gdbremote_testcase import lldbgdbserverutils import os @@ -12,6 +11,7 @@ from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * from lldbsuite.test import lldbutil + class TestStubSetSIDTestCase(gdbremote_testcase.GdbRemoteTestCaseBase): mydir = TestBase.compute_mydir(__file__) @@ -23,7 +23,9 @@ class TestStubSetSIDTestCase(gdbremote_testcase.GdbRemoteTestCaseBase): server = self.launch_debug_monitor() self.assertIsNotNone(server) - self.assertTrue(lldbgdbserverutils.process_is_running(server.pid, True)) + self.assertTrue( + lldbgdbserverutils.process_is_running( + server.pid, True)) # Get the process id for the stub. return os.getsid(server.pid) @@ -41,14 +43,14 @@ class TestStubSetSIDTestCase(gdbremote_testcase.GdbRemoteTestCaseBase): self.assertNotEqual(stub_sid, os.getsid(0)) @debugserver_test - @skipIfRemote # --setsid not used on remote platform and currently it is also impossible to get the sid of lldb-platform running on a remote target + @skipIfRemote # --setsid not used on remote platform and currently it is also impossible to get the sid of lldb-platform running on a remote target def test_sid_is_same_without_setsid_debugserver(self): self.init_debugserver_test() self.set_inferior_startup_launch() self.sid_is_same_without_setsid() @llgs_test - @skipIfRemote # --setsid not used on remote platform and currently it is also impossible to get the sid of lldb-platform running on a remote target + @skipIfRemote # --setsid not used on remote platform and currently it is also impossible to get the sid of lldb-platform running on a remote target @expectedFailureAll(oslist=['freebsd']) def test_sid_is_same_without_setsid_llgs(self): self.init_llgs_test() @@ -56,28 +58,28 @@ class TestStubSetSIDTestCase(gdbremote_testcase.GdbRemoteTestCaseBase): self.sid_is_same_without_setsid() @debugserver_test - @skipIfRemote # --setsid not used on remote platform and currently it is also impossible to get the sid of lldb-platform running on a remote target + @skipIfRemote # --setsid not used on remote platform and currently it is also impossible to get the sid of lldb-platform running on a remote target def test_sid_is_different_with_setsid_debugserver(self): self.init_debugserver_test() self.set_inferior_startup_launch() self.sid_is_different_with_setsid() @llgs_test - @skipIfRemote # --setsid not used on remote platform and currently it is also impossible to get the sid of lldb-platform running on a remote target + @skipIfRemote # --setsid not used on remote platform and currently it is also impossible to get the sid of lldb-platform running on a remote target def test_sid_is_different_with_setsid_llgs(self): self.init_llgs_test() self.set_inferior_startup_launch() self.sid_is_different_with_setsid() @debugserver_test - @skipIfRemote # --setsid not used on remote platform and currently it is also impossible to get the sid of lldb-platform running on a remote target + @skipIfRemote # --setsid not used on remote platform and currently it is also impossible to get the sid of lldb-platform running on a remote target def test_sid_is_different_with_S_debugserver(self): self.init_debugserver_test() self.set_inferior_startup_launch() self.sid_is_different_with_S() @llgs_test - @skipIfRemote # --setsid not used on remote platform and currently it is also impossible to get the sid of lldb-platform running on a remote target + @skipIfRemote # --setsid not used on remote platform and currently it is also impossible to get the sid of lldb-platform running on a remote target def test_sid_is_different_with_S_llgs(self): self.init_llgs_test() self.set_inferior_startup_launch() 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 12c1033cba1..7fc25807435 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 @@ -5,7 +5,6 @@ Base class for gdb-remote test cases. from __future__ import print_function - import errno import os import os.path @@ -24,9 +23,11 @@ from lldbsuite.test.lldbtest import * from lldbgdbserverutils import * import logging + class _ConnectionRefused(IOError): pass + class GdbRemoteTestCaseBase(TestBase): NO_DEBUG_INFO_TESTCASE = True @@ -35,29 +36,34 @@ class GdbRemoteTestCaseBase(TestBase): _GDBREMOTE_KILL_PACKET = "$k#6b" - # Start the inferior separately, attach to the inferior on the stub command line. + # Start the inferior separately, attach to the inferior on the stub + # command line. _STARTUP_ATTACH = "attach" - # Start the inferior separately, start the stub without attaching, allow the test to attach to the inferior however it wants (e.g. $vAttach;pid). + # Start the inferior separately, start the stub without attaching, allow + # the test to attach to the inferior however it wants (e.g. $vAttach;pid). _STARTUP_ATTACH_MANUALLY = "attach_manually" - # Start the stub, and launch the inferior with an $A packet via the initial packet stream. + # Start the stub, and launch the inferior with an $A packet via the + # initial packet stream. _STARTUP_LAUNCH = "launch" - # GDB Signal numbers that are not target-specific used for common exceptions - TARGET_EXC_BAD_ACCESS = 0x91 + # GDB Signal numbers that are not target-specific used for common + # exceptions + TARGET_EXC_BAD_ACCESS = 0x91 TARGET_EXC_BAD_INSTRUCTION = 0x92 - TARGET_EXC_ARITHMETIC = 0x93 - TARGET_EXC_EMULATION = 0x94 - TARGET_EXC_SOFTWARE = 0x95 - TARGET_EXC_BREAKPOINT = 0x96 + TARGET_EXC_ARITHMETIC = 0x93 + TARGET_EXC_EMULATION = 0x94 + TARGET_EXC_SOFTWARE = 0x95 + TARGET_EXC_BREAKPOINT = 0x96 _verbose_log_handler = None - _log_formatter = logging.Formatter(fmt='%(asctime)-15s %(levelname)-8s %(message)s') + _log_formatter = logging.Formatter( + fmt='%(asctime)-15s %(levelname)-8s %(message)s') def setUpBaseLogging(self): self.logger = logging.getLogger(__name__) if len(self.logger.handlers) > 0: - return # We have set up this handler already + return # We have set up this handler already self.logger.propagate = False self.logger.setLevel(logging.DEBUG) @@ -68,11 +74,11 @@ class GdbRemoteTestCaseBase(TestBase): handler.setFormatter(self._log_formatter) self.logger.addHandler(handler) - def isVerboseLoggingRequested(self): # We will report our detailed logs if the user requested that the "gdb-remote" channel is # logged. - return any(("gdb-remote" in channel) for channel in lldbtest_config.channels) + return any(("gdb-remote" in channel) + for channel in lldbtest_config.channels) def setUp(self): TestBase.setUp(self) @@ -83,7 +89,8 @@ class GdbRemoteTestCaseBase(TestBase): if self.isVerboseLoggingRequested(): # If requested, full logs go to a log file - self._verbose_log_handler = logging.FileHandler(self.log_basename + "-host.log") + self._verbose_log_handler = logging.FileHandler( + self.log_basename + "-host.log") self._verbose_log_handler.setFormatter(self._log_formatter) self._verbose_log_handler.setLevel(logging.DEBUG) self.logger.addHandler(self._verbose_log_handler) @@ -100,7 +107,8 @@ class GdbRemoteTestCaseBase(TestBase): url_pattern = '(.+)://\[?(.+?)\]?/.*' else: url_pattern = '(.+)://(.+):\d+' - scheme, host = re.match(url_pattern, configuration.lldb_platform_url).groups() + scheme, host = re.match( + url_pattern, configuration.lldb_platform_url).groups() if configuration.lldb_platform_name == 'remote-android' and host != 'localhost': self.stub_device = host self.stub_hostname = 'localhost' @@ -122,21 +130,24 @@ class GdbRemoteTestCaseBase(TestBase): def setUpServerLogging(self, is_llgs): if len(lldbtest_config.channels) == 0: - return # No logging requested + return # No logging requested if lldb.remote_platform: - log_file = lldbutil.join_remote_paths(lldb.remote_platform.GetWorkingDirectory(), "server.log") + log_file = lldbutil.join_remote_paths( + lldb.remote_platform.GetWorkingDirectory(), "server.log") else: log_file = self.getLocalServerLogFile() if is_llgs: self.debug_monitor_extra_args.append("--log-file=" + log_file) - self.debug_monitor_extra_args.append("--log-channels={}".format(":".join(lldbtest_config.channels))) + self.debug_monitor_extra_args.append( + "--log-channels={}".format(":".join(lldbtest_config.channels))) else: - self.debug_monitor_extra_args = ["--log-file=" + log_file, "--log-flags=0x800000"] + self.debug_monitor_extra_args = [ + "--log-file=" + log_file, "--log-flags=0x800000"] def get_next_port(self): - return 12000 + random.randint(0,3999) + return 12000 + random.randint(0, 3999) def reset_test_sequence(self): self.test_sequence = GdbRemoteTestSequence(self.logger) @@ -149,7 +160,8 @@ class GdbRemoteTestCaseBase(TestBase): # Create the named pipe. os.mkfifo(named_pipe_path) - # Open the read side of the pipe in non-blocking mode. This will return right away, ready or not. + # Open the read side of the pipe in non-blocking mode. This will + # return right away, ready or not. named_pipe_fd = os.open(named_pipe_path, os.O_RDONLY | os.O_NONBLOCK) # Create the file for the named pipe. Note this will follow semantics of @@ -177,7 +189,9 @@ class GdbRemoteTestCaseBase(TestBase): try: os.rmdir(temp_dir) except: - print("failed to delete temp dir: {}, directory contents: '{}'".format(temp_dir, os.listdir(temp_dir))) + print( + "failed to delete temp dir: {}, directory contents: '{}'".format( + temp_dir, os.listdir(temp_dir))) None # Add the shutdown hook to clean up the named pipe. @@ -190,14 +204,23 @@ class GdbRemoteTestCaseBase(TestBase): def get_stub_port_from_named_socket(self, read_timeout_seconds=5): # Wait for something to read with a max timeout. - (ready_readers, _, _) = select.select([self.named_pipe_fd], [], [], read_timeout_seconds) - self.assertIsNotNone(ready_readers, "write side of pipe has not written anything - stub isn't writing to pipe.") - self.assertNotEqual(len(ready_readers), 0, "write side of pipe has not written anything - stub isn't writing to pipe.") + (ready_readers, _, _) = select.select( + [self.named_pipe_fd], [], [], read_timeout_seconds) + self.assertIsNotNone( + ready_readers, + "write side of pipe has not written anything - stub isn't writing to pipe.") + self.assertNotEqual( + len(ready_readers), + 0, + "write side of pipe has not written anything - stub isn't writing to pipe.") # Read the port from the named pipe. stub_port_raw = self.named_pipe.read() self.assertIsNotNone(stub_port_raw) - self.assertNotEqual(len(stub_port_raw), 0, "no content to read on pipe") + self.assertNotEqual( + len(stub_port_raw), + 0, + "no content to read on pipe") # Trim null byte, convert to int. stub_port_raw = stub_port_raw[:-1] @@ -212,15 +235,24 @@ class GdbRemoteTestCaseBase(TestBase): use_named_pipe = False # Grab the ppid from /proc/[shell pid]/stat - err, retcode, shell_stat = self.run_platform_command("cat /proc/$$/stat") - self.assertTrue(err.Success() and retcode == 0, - "Failed to read file /proc/$$/stat: %s, retcode: %d" % (err.GetCString(), retcode)) + err, retcode, shell_stat = self.run_platform_command( + "cat /proc/$$/stat") + self.assertTrue( + err.Success() and retcode == 0, + "Failed to read file /proc/$$/stat: %s, retcode: %d" % + (err.GetCString(), + retcode)) # [pid] ([executable]) [state] [*ppid*] pid = re.match(r"^\d+ \(.+\) . (\d+)", shell_stat).group(1) - err, retcode, ls_output = self.run_platform_command("ls -l /proc/%s/exe" % pid) - self.assertTrue(err.Success() and retcode == 0, - "Failed to read file /proc/%s/exe: %s, retcode: %d" % (pid, err.GetCString(), retcode)) + err, retcode, ls_output = self.run_platform_command( + "ls -l /proc/%s/exe" % pid) + self.assertTrue( + err.Success() and retcode == 0, + "Failed to read file /proc/%s/exe: %s, retcode: %d" % + (pid, + err.GetCString(), + retcode)) exe = ls_output.split()[-1] # If the binary has been deleted, the link name has " (deleted)" appended. @@ -235,7 +267,8 @@ class GdbRemoteTestCaseBase(TestBase): self.setUpServerLogging(is_llgs=True) if use_named_pipe: - (self.named_pipe_path, self.named_pipe, self.named_pipe_fd) = self.create_named_pipe() + (self.named_pipe_path, self.named_pipe, + self.named_pipe_fd) = self.create_named_pipe() def init_debugserver_test(self, use_named_pipe=True): self.debug_monitor_exe = get_debugserver_exe() @@ -243,17 +276,19 @@ class GdbRemoteTestCaseBase(TestBase): self.skipTest("debugserver exe not found") self.setUpServerLogging(is_llgs=False) if use_named_pipe: - (self.named_pipe_path, self.named_pipe, self.named_pipe_fd) = self.create_named_pipe() + (self.named_pipe_path, self.named_pipe, + self.named_pipe_fd) = self.create_named_pipe() # The debugserver stub has a race on handling the 'k' command, so it sends an X09 right away, then sends the real X notification # when the process truly dies. self.stub_sends_two_stop_notifications_on_kill = True def forward_adb_port(self, source, target, direction, device): - adb = [ 'adb' ] + ([ '-s', device ] if device else []) + [ direction ] + adb = ['adb'] + (['-s', device] if device else []) + [direction] + def remove_port_forward(): - subprocess.call(adb + [ "--remove", "tcp:%d" % source]) + subprocess.call(adb + ["--remove", "tcp:%d" % source]) - subprocess.call(adb + [ "tcp:%d" % source, "tcp:%d" % target]) + subprocess.call(adb + ["tcp:%d" % source, "tcp:%d" % target]) self.addTearDownHook(remove_port_forward) def _verify_socket(self, sock): @@ -265,12 +300,12 @@ class GdbRemoteTestCaseBase(TestBase): # connection again. triple = self.dbg.GetSelectedPlatform().GetTriple() if not re.match(".*-.*-.*-android", triple): - return # Not android. + return # Not android. can_read, _, _ = select.select([sock], [], [], 0.1) if sock not in can_read: - return # Data is not available, but the connection is alive. + return # Data is not available, but the connection is alive. if len(sock.recv(1, socket.MSG_PEEK)) == 0: - raise _ConnectionRefused() # Got EOF, connection dropped. + raise _ConnectionRefused() # Got EOF, connection dropped. def create_socket(self): sock = socket.socket() @@ -278,9 +313,16 @@ class GdbRemoteTestCaseBase(TestBase): triple = self.dbg.GetSelectedPlatform().GetTriple() if re.match(".*-.*-.*-android", triple): - self.forward_adb_port(self.port, self.port, "forward", self.stub_device) - - logger.info("Connecting to debug monitor on %s:%d", self.stub_hostname, self.port) + self.forward_adb_port( + self.port, + self.port, + "forward", + self.stub_device) + + logger.info( + "Connecting to debug monitor on %s:%d", + self.stub_hostname, + self.port) connect_info = (self.stub_hostname, self.port) try: sock.connect(connect_info) @@ -295,12 +337,16 @@ class GdbRemoteTestCaseBase(TestBase): # send the kill packet so lldb-server shuts down gracefully sock.sendall(GdbRemoteTestCaseBase._GDBREMOTE_KILL_PACKET) except: - logger.warning("failed to send kill packet to debug monitor: {}; ignoring".format(sys.exc_info()[0])) + logger.warning( + "failed to send kill packet to debug monitor: {}; ignoring".format( + sys.exc_info()[0])) try: sock.close() except: - logger.warning("failed to close socket to debug monitor: {}; ignoring".format(sys.exc_info()[0])) + logger.warning( + "failed to close socket to debug monitor: {}; ignoring".format( + sys.exc_info()[0])) self.addTearDownHook(shutdown_socket) @@ -319,9 +365,11 @@ class GdbRemoteTestCaseBase(TestBase): def get_debug_monitor_command_line_args(self, attach_pid=None): if lldb.remote_platform: - commandline_args = self.debug_monitor_extra_args + ["*:{}".format(self.port)] + commandline_args = self.debug_monitor_extra_args + \ + ["*:{}".format(self.port)] else: - commandline_args = self.debug_monitor_extra_args + ["localhost:{}".format(self.port)] + commandline_args = self.debug_monitor_extra_args + \ + ["localhost:{}".format(self.port)] if attach_pid: commandline_args += ["--attach=%d" % attach_pid] @@ -331,14 +379,19 @@ class GdbRemoteTestCaseBase(TestBase): def launch_debug_monitor(self, attach_pid=None, logfile=None): # Create the command line. - commandline_args = self.get_debug_monitor_command_line_args(attach_pid=attach_pid) + commandline_args = self.get_debug_monitor_command_line_args( + attach_pid=attach_pid) # Start the server. - server = self.spawnSubprocess(self.debug_monitor_exe, commandline_args, install_remote=False) + server = self.spawnSubprocess( + self.debug_monitor_exe, + commandline_args, + install_remote=False) self.addTearDownHook(self.cleanupSubprocesses) self.assertIsNotNone(server) - # If we're receiving the stub's listening port from the named pipe, do that here. + # If we're receiving the stub's listening port from the named pipe, do + # that here. if self.named_pipe: self.port = self.get_stub_port_from_named_socket() @@ -354,7 +407,9 @@ class GdbRemoteTestCaseBase(TestBase): try: server.terminate() except: - logger.warning("failed to terminate server for debug monitor: {}; ignoring".format(sys.exc_info()[0])) + logger.warning( + "failed to terminate server for debug monitor: {}; ignoring".format( + sys.exc_info()[0])) self.addTearDownHook(shutdown_debug_monitor) # Schedule debug monitor to be shut down during teardown. @@ -374,11 +429,14 @@ class GdbRemoteTestCaseBase(TestBase): # Schedule debug monitor to be shut down during teardown. logger = self.logger + def shutdown_debug_monitor(): try: server.terminate() except: - logger.warning("failed to terminate server for debug monitor: {}; ignoring".format(sys.exc_info()[0])) + logger.warning( + "failed to terminate server for debug monitor: {}; ignoring".format( + sys.exc_info()[0])) self.addTearDownHook(shutdown_debug_monitor) connect_attemps = 0 @@ -387,7 +445,7 @@ class GdbRemoteTestCaseBase(TestBase): while connect_attemps < MAX_CONNECT_ATTEMPTS: # Create a socket to talk to the server try: - logger.info("Connect attempt %d", connect_attemps+1) + logger.info("Connect attempt %d", connect_attemps + 1) self.sock = self.create_socket() return server except _ConnectionRefused as serr: @@ -400,18 +458,27 @@ class GdbRemoteTestCaseBase(TestBase): server.terminate() # Increment attempts. - print("connect to debug monitor on port %d failed, attempt #%d of %d" % (self.port, attempts + 1, MAX_ATTEMPTS)) + print( + "connect to debug monitor on port %d failed, attempt #%d of %d" % + (self.port, attempts + 1, MAX_ATTEMPTS)) attempts += 1 - # And wait a random length of time before next attempt, to avoid collisions. - time.sleep(random.randint(1,5)) - + # And wait a random length of time before next attempt, to avoid + # collisions. + time.sleep(random.randint(1, 5)) + # Now grab a new port number. self.port = self.get_next_port() - raise Exception("failed to create a socket to the launched debug monitor after %d tries" % attempts) + raise Exception( + "failed to create a socket to the launched debug monitor after %d tries" % + attempts) - def launch_process_for_attach(self, inferior_args=None, sleep_seconds=3, exe_path=None): + def launch_process_for_attach( + self, + inferior_args=None, + sleep_seconds=3, + exe_path=None): # We're going to start a child process that the debug monitor stub can later attach to. # This process needs to be started so that it just hangs around for a while. We'll # have it sleep. @@ -425,15 +492,22 @@ class GdbRemoteTestCaseBase(TestBase): args.append("sleep:%d" % sleep_seconds) inferior = self.spawnSubprocess(exe_path, args) + def shutdown_process_for_attach(): try: inferior.terminate() except: - logger.warning("failed to terminate inferior process for attach: {}; ignoring".format(sys.exc_info()[0])) + logger.warning( + "failed to terminate inferior process for attach: {}; ignoring".format( + sys.exc_info()[0])) self.addTearDownHook(shutdown_process_for_attach) return inferior - def prep_debug_monitor_and_inferior(self, inferior_args=None, inferior_sleep_seconds=3, inferior_exe_path=None): + def prep_debug_monitor_and_inferior( + self, + inferior_args=None, + inferior_sleep_seconds=3, + inferior_exe_path=None): """Prep the debug monitor, the inferior, and the expected packet stream. Handle the separate cases of using the debug monitor in attach-to-inferior mode @@ -458,11 +532,15 @@ class GdbRemoteTestCaseBase(TestBase): if self._inferior_startup == self._STARTUP_ATTACH or self._inferior_startup == self._STARTUP_ATTACH_MANUALLY: # Launch the process that we'll use as the inferior. - inferior = self.launch_process_for_attach(inferior_args=inferior_args, sleep_seconds=inferior_sleep_seconds, exe_path=inferior_exe_path) + inferior = self.launch_process_for_attach( + inferior_args=inferior_args, + sleep_seconds=inferior_sleep_seconds, + exe_path=inferior_exe_path) self.assertIsNotNone(inferior) self.assertTrue(inferior.pid > 0) if self._inferior_startup == self._STARTUP_ATTACH: - # In this case, we want the stub to attach via the command line, so set the command line attach pid here. + # In this case, we want the stub to attach via the command + # line, so set the command line attach pid here. attach_pid = inferior.pid if self._inferior_startup == self._STARTUP_LAUNCH: @@ -471,11 +549,15 @@ class GdbRemoteTestCaseBase(TestBase): inferior_exe_path = os.path.abspath("a.out") if lldb.remote_platform: - remote_path = lldbutil.append_to_process_working_directory(os.path.basename(inferior_exe_path)) + remote_path = lldbutil.append_to_process_working_directory( + os.path.basename(inferior_exe_path)) remote_file_spec = lldb.SBFileSpec(remote_path, False) - err = lldb.remote_platform.Install(lldb.SBFileSpec(inferior_exe_path, True), remote_file_spec) + err = lldb.remote_platform.Install(lldb.SBFileSpec( + inferior_exe_path, True), remote_file_spec) if err.Fail(): - raise Exception("remote_platform.Install('%s', '%s') failed: %s" % (inferior_exe_path, remote_path, err)) + raise Exception( + "remote_platform.Install('%s', '%s') failed: %s" % + (inferior_exe_path, remote_path, err)) inferior_exe_path = remote_path launch_args = [inferior_exe_path] @@ -491,13 +573,18 @@ class GdbRemoteTestCaseBase(TestBase): if self._inferior_startup == self._STARTUP_LAUNCH: self.add_verified_launch_packets(launch_args) - return {"inferior":inferior, "server":server} + return {"inferior": inferior, "server": server} - def expect_socket_recv(self, sock, expected_content_regex, timeout_seconds): + def expect_socket_recv( + self, + sock, + expected_content_regex, + timeout_seconds): response = "" timeout_time = time.time() + timeout_seconds - while not expected_content_regex.match(response) and time.time() < timeout_time: + while not expected_content_regex.match( + response) and time.time() < timeout_time: can_read, _, _ = select.select([sock], [], [], timeout_seconds) if can_read and sock in can_read: recv_bytes = sock.recv(4096) @@ -514,7 +601,8 @@ class GdbRemoteTestCaseBase(TestBase): _, can_write, _ = select.select([], [sock], [], timeout_seconds) if can_write and sock in can_write: written_byte_count = sock.send(request_bytes_remaining) - request_bytes_remaining = request_bytes_remaining[written_byte_count:] + request_bytes_remaining = request_bytes_remaining[ + written_byte_count:] self.assertEqual(len(request_bytes_remaining), 0) def do_handshake(self, stub_socket, timeout_seconds=5): @@ -527,7 +615,8 @@ class GdbRemoteTestCaseBase(TestBase): self.assertEqual(bytes_sent, len(NO_ACK_MODE_REQUEST)) # Receive the ack and "OK" - self.expect_socket_recv(stub_socket, re.compile(r"^\+\$OK#[0-9a-fA-F]{2}$"), timeout_seconds) + self.expect_socket_recv(stub_socket, re.compile( + r"^\+\$OK#[0-9a-fA-F]{2}$"), timeout_seconds) # Send the final ack. self.expect_socket_send(stub_socket, "+", timeout_seconds) @@ -553,12 +642,12 @@ class GdbRemoteTestCaseBase(TestBase): self.test_sequence.add_log_lines( ["read packet: $QThreadSuffixSupported#e4", "send packet: $OK#00", - ], True) + ], True) def add_process_info_collection_packets(self): self.test_sequence.add_log_lines( ["read packet: $qProcessInfo#dc", - { "direction":"send", "regex":r"^\$(.+)#[0-9a-fA-F]{2}$", "capture":{1:"process_info_raw"} }], + {"direction": "send", "regex": r"^\$(.+)#[0-9a-fA-F]{2}$", "capture": {1: "process_info_raw"}}], True) _KNOWN_PROCESS_INFO_KEYS = [ @@ -575,7 +664,7 @@ class GdbRemoteTestCaseBase(TestBase): "vendor", "endian", "ptrsize" - ] + ] def parse_process_info_response(self, context): # Ensure we have a process info response. @@ -584,7 +673,9 @@ class GdbRemoteTestCaseBase(TestBase): self.assertIsNotNone(process_info_raw) # Pull out key:value; pairs. - process_info_dict = { match.group(1):match.group(2) for match in re.finditer(r"([^:]+):([^;]+);", process_info_raw) } + process_info_dict = { + match.group(1): match.group(2) for match in re.finditer( + r"([^:]+):([^;]+);", process_info_raw)} # Validate keys are known. for (key, val) in list(process_info_dict.items()): @@ -595,9 +686,9 @@ class GdbRemoteTestCaseBase(TestBase): def add_register_info_collection_packets(self): self.test_sequence.add_log_lines( - [ { "type":"multi_response", "query":"qRegisterInfo", "append_iteration_suffix":True, - "end_regex":re.compile(r"^\$(E\d+)?#[0-9a-fA-F]{2}$"), - "save_key":"reg_info_responses" } ], + [{"type": "multi_response", "query": "qRegisterInfo", "append_iteration_suffix": True, + "end_regex": re.compile(r"^\$(E\d+)?#[0-9a-fA-F]{2}$"), + "save_key": "reg_info_responses"}], True) def parse_register_info_packets(self, context): @@ -606,13 +697,19 @@ class GdbRemoteTestCaseBase(TestBase): self.assertIsNotNone(reg_info_responses) # Parse register infos. - return [parse_reg_info_response(reg_info_response) for reg_info_response in reg_info_responses] + return [parse_reg_info_response(reg_info_response) + for reg_info_response in reg_info_responses] def expect_gdbremote_sequence(self, timeout_seconds=None): if not timeout_seconds: timeout_seconds = self._TIMEOUT_SECONDS - return expect_lldb_gdbserver_replay(self, self.sock, self.test_sequence, - self._pump_queues, timeout_seconds, self.logger) + return expect_lldb_gdbserver_replay( + self, + self.sock, + self.test_sequence, + self._pump_queues, + timeout_seconds, + self.logger) _KNOWN_REGINFO_KEYS = [ "name", @@ -667,7 +764,7 @@ class GdbRemoteTestCaseBase(TestBase): def add_query_memory_region_packets(self, address): self.test_sequence.add_log_lines( ["read packet: $qMemoryRegionInfo:{0:x}#00".format(address), - {"direction":"send", "regex":r"^\$(.+)#[0-9a-fA-F]{2}$", "capture":{1:"memory_region_response"} }], + {"direction": "send", "regex": r"^\$(.+)#[0-9a-fA-F]{2}$", "capture": {1: "memory_region_response"}}], True) def parse_key_val_dict(self, key_val_text, allow_dupes=True): @@ -678,13 +775,15 @@ class GdbRemoteTestCaseBase(TestBase): val = match.group(2) if key in kv_dict: if allow_dupes: - if type(kv_dict[key]) == list: + if isinstance(kv_dict[key], list): kv_dict[key].append(val) else: # Promote to list kv_dict[key] = [kv_dict[key], val] else: - self.fail("key '{}' already present when attempting to add value '{}' (text='{}', dict={})".format(key, val, key_val_text, kv_dict)) + self.fail( + "key '{}' already present when attempting to add value '{}' (text='{}', dict={})".format( + key, val, key_val_text, kv_dict)) else: kv_dict[key] = val return kv_dict @@ -694,17 +793,25 @@ class GdbRemoteTestCaseBase(TestBase): self.assertIsNotNone(context.get("memory_region_response")) # Pull out key:value; pairs. - mem_region_dict = self.parse_key_val_dict(context.get("memory_region_response")) + mem_region_dict = self.parse_key_val_dict( + context.get("memory_region_response")) # Validate keys are known. for (key, val) in list(mem_region_dict.items()): - self.assertTrue(key in ["start", "size", "permissions", "name", "error"]) + self.assertTrue( + key in [ + "start", + "size", + "permissions", + "name", + "error"]) self.assertIsNotNone(val) # Return the dictionary of key-value pairs for the memory region. return mem_region_dict - def assert_address_within_memory_region(self, test_address, mem_region_dict): + def assert_address_within_memory_region( + self, test_address, mem_region_dict): self.assertIsNotNone(mem_region_dict) self.assertTrue("start" in mem_region_dict) self.assertTrue("size" in mem_region_dict) @@ -714,15 +821,25 @@ class GdbRemoteTestCaseBase(TestBase): range_end = range_start + range_size if test_address < range_start: - self.fail("address 0x{0:x} comes before range 0x{1:x} - 0x{2:x} (size 0x{3:x})".format(test_address, range_start, range_end, range_size)) + self.fail( + "address 0x{0:x} comes before range 0x{1:x} - 0x{2:x} (size 0x{3:x})".format( + test_address, + range_start, + range_end, + range_size)) elif test_address >= range_end: - self.fail("address 0x{0:x} comes after range 0x{1:x} - 0x{2:x} (size 0x{3:x})".format(test_address, range_start, range_end, range_size)) + self.fail( + "address 0x{0:x} comes after range 0x{1:x} - 0x{2:x} (size 0x{3:x})".format( + test_address, + range_start, + range_end, + range_size)) def add_threadinfo_collection_packets(self): self.test_sequence.add_log_lines( - [ { "type":"multi_response", "first_query":"qfThreadInfo", "next_query":"qsThreadInfo", - "append_iteration_suffix":False, "end_regex":re.compile(r"^\$(l)?#[0-9a-fA-F]{2}$"), - "save_key":"threadinfo_responses" } ], + [{"type": "multi_response", "first_query": "qfThreadInfo", "next_query": "qsThreadInfo", + "append_iteration_suffix": False, "end_regex": re.compile(r"^\$(l)?#[0-9a-fA-F]{2}$"), + "save_key": "threadinfo_responses"}], True) def parse_threadinfo_packets(self, context): @@ -760,35 +877,44 @@ class GdbRemoteTestCaseBase(TestBase): return threads - def add_set_breakpoint_packets(self, address, do_continue=True, breakpoint_kind=1): + def add_set_breakpoint_packets( + self, + address, + do_continue=True, + breakpoint_kind=1): self.test_sequence.add_log_lines( - [# Set the breakpoint. - "read packet: $Z0,{0:x},{1}#00".format(address, breakpoint_kind), - # Verify the stub could set it. - "send packet: $OK#00", - ], True) + [ # Set the breakpoint. + "read packet: $Z0,{0:x},{1}#00".format( + address, breakpoint_kind), + # Verify the stub could set it. + "send packet: $OK#00", + ], True) if (do_continue): self.test_sequence.add_log_lines( - [# Continue the inferior. - "read packet: $c#63", - # Expect a breakpoint stop report. - {"direction":"send", "regex":r"^\$T([0-9a-fA-F]{2})thread:([0-9a-fA-F]+);", "capture":{1:"stop_signo", 2:"stop_thread_id"} }, - ], True) + [ # Continue the inferior. + "read packet: $c#63", + # Expect a breakpoint stop report. + {"direction": "send", + "regex": r"^\$T([0-9a-fA-F]{2})thread:([0-9a-fA-F]+);", + "capture": {1: "stop_signo", + 2: "stop_thread_id"}}, + ], True) def add_remove_breakpoint_packets(self, address, breakpoint_kind=1): self.test_sequence.add_log_lines( - [# Remove the breakpoint. - "read packet: $z0,{0:x},{1}#00".format(address, breakpoint_kind), - # Verify the stub could unset it. - "send packet: $OK#00", + [ # Remove the breakpoint. + "read packet: $z0,{0:x},{1}#00".format( + address, breakpoint_kind), + # Verify the stub could unset it. + "send packet: $OK#00", ], True) def add_qSupported_packets(self): self.test_sequence.add_log_lines( ["read packet: $qSupported#00", - {"direction":"send", "regex":r"^\$(.*)#[0-9a-fA-F]{2}", "capture":{1: "qSupported_response"}}, - ], True) + {"direction": "send", "regex": r"^\$(.*)#[0-9a-fA-F]{2}", "capture": {1: "qSupported_response"}}, + ], True) _KNOWN_QSUPPORTED_STUB_FEATURES = [ "augmented-libraries-svr4-read", @@ -821,23 +947,27 @@ class GdbRemoteTestCaseBase(TestBase): supported_dict[key] = val else: if len(key) < 2: - raise Exception("singular stub feature is too short: must be stub_feature{+,-,?}") + raise Exception( + "singular stub feature is too short: must be stub_feature{+,-,?}") supported_type = key[-1] key = key[:-1] if not supported_type in ["+", "-", "?"]: - raise Exception("malformed stub feature: final character {} not in expected set (+,-,?)".format(supported_type)) - supported_dict[key] = supported_type + raise Exception( + "malformed stub feature: final character {} not in expected set (+,-,?)".format(supported_type)) + supported_dict[key] = supported_type # Ensure we know the supported element - if not key in self._KNOWN_QSUPPORTED_STUB_FEATURES: - raise Exception("unknown qSupported stub feature reported: %s" % key) + if key not in self._KNOWN_QSUPPORTED_STUB_FEATURES: + raise Exception( + "unknown qSupported stub feature reported: %s" % + key) return supported_dict def run_process_then_stop(self, run_seconds=1): # Tell the stub to continue. self.test_sequence.add_log_lines( - ["read packet: $vCont;c#a8"], - True) + ["read packet: $vCont;c#a8"], + True) context = self.expect_gdbremote_sequence() # Wait for run_seconds. @@ -847,7 +977,7 @@ class GdbRemoteTestCaseBase(TestBase): self.reset_test_sequence() self.test_sequence.add_log_lines( ["read packet: {}".format(chr(3)), - {"direction":"send", "regex":r"^\$T([0-9a-fA-F]+)([^#]+)#[0-9a-fA-F]{2}$", "capture":{1:"stop_result"} }], + {"direction": "send", "regex": r"^\$T([0-9a-fA-F]+)([^#]+)#[0-9a-fA-F]{2}$", "capture": {1: "stop_result"}}], True) context = self.expect_gdbremote_sequence() self.assertIsNotNone(context) @@ -857,18 +987,21 @@ class GdbRemoteTestCaseBase(TestBase): def select_modifiable_register(self, reg_infos): """Find a register that can be read/written freely.""" - PREFERRED_REGISTER_NAMES = set(["rax",]) + PREFERRED_REGISTER_NAMES = set(["rax", ]) - # First check for the first register from the preferred register name set. + # First check for the first register from the preferred register name + # set. alternative_register_index = None self.assertIsNotNone(reg_infos) for reg_info in reg_infos: - if ("name" in reg_info) and (reg_info["name"] in PREFERRED_REGISTER_NAMES): + if ("name" in reg_info) and ( + reg_info["name"] in PREFERRED_REGISTER_NAMES): # We found a preferred register. Use it. return reg_info["lldb_register_index"] if ("generic" in reg_info) and (reg_info["generic"] == "fp"): - # A frame pointer register will do as a register to modify temporarily. + # A frame pointer register will do as a register to modify + # temporarily. alternative_register_index = reg_info["lldb_register_index"] # We didn't find a preferred register. Return whatever alternative register @@ -901,7 +1034,8 @@ class GdbRemoteTestCaseBase(TestBase): def find_generic_register_with_name(self, reg_infos, generic_name): self.assertIsNotNone(reg_infos) for reg_info in reg_infos: - if ("generic" in reg_info) and (reg_info["generic"] == generic_name): + if ("generic" in reg_info) and ( + reg_info["generic"] == generic_name): return reg_info return None @@ -912,13 +1046,13 @@ class GdbRemoteTestCaseBase(TestBase): if encoded_bytes[i] == "}": # Handle escaped char. self.assertTrue(i + 1 < len(encoded_bytes)) - decoded_bytes += chr(ord(encoded_bytes[i+1]) ^ 0x20) - i +=2 + decoded_bytes += chr(ord(encoded_bytes[i + 1]) ^ 0x20) + i += 2 elif encoded_bytes[i] == "*": # Handle run length encoding. self.assertTrue(len(decoded_bytes) > 0) self.assertTrue(i + 1 < len(encoded_bytes)) - repeat_count = ord(encoded_bytes[i+1]) - 29 + repeat_count = ord(encoded_bytes[i + 1]) - 29 decoded_bytes += decoded_bytes[-1] * repeat_count i += 2 else: @@ -955,7 +1089,8 @@ class GdbRemoteTestCaseBase(TestBase): self.assertFalse(key in auxv_dict) auxv_dict[key] = value - self.fail("should not reach here - implies required double zero entry not found") + self.fail( + "should not reach here - implies required double zero entry not found") return auxv_dict def read_binary_data_in_chunks(self, command_prefix, chunk_length): @@ -967,10 +1102,21 @@ class GdbRemoteTestCaseBase(TestBase): while not done: # Grab the next iteration of data. self.reset_test_sequence() - self.test_sequence.add_log_lines([ - "read packet: ${}{:x},{:x}:#00".format(command_prefix, offset, chunk_length), - {"direction":"send", "regex":re.compile(r"^\$([^E])(.*)#[0-9a-fA-F]{2}$", re.MULTILINE|re.DOTALL), "capture":{1:"response_type", 2:"content_raw"} } - ], True) + self.test_sequence.add_log_lines( + [ + "read packet: ${}{:x},{:x}:#00".format( + command_prefix, + offset, + chunk_length), + { + "direction": "send", + "regex": re.compile( + r"^\$([^E])(.*)#[0-9a-fA-F]{2}$", + re.MULTILINE | re.DOTALL), + "capture": { + 1: "response_type", + 2: "content_raw"}}], + True) context = self.expect_gdbremote_sequence() self.assertIsNotNone(context) @@ -997,25 +1143,32 @@ class GdbRemoteTestCaseBase(TestBase): # Send the intterupt. "read packet: {}".format(chr(3)), # And wait for the stop notification. - {"direction":"send", "regex":r"^\$T([0-9a-fA-F]{2})(.*)#[0-9a-fA-F]{2}$", "capture":{1:"stop_signo", 2:"stop_key_val_text" } }, - ], True) + {"direction": "send", + "regex": r"^\$T([0-9a-fA-F]{2})(.*)#[0-9a-fA-F]{2}$", + "capture": {1: "stop_signo", + 2: "stop_key_val_text"}}, + ], True) def parse_interrupt_packets(self, context): self.assertIsNotNone(context.get("stop_signo")) self.assertIsNotNone(context.get("stop_key_val_text")) - return (int(context["stop_signo"], 16), self.parse_key_val_dict(context["stop_key_val_text"])) + return (int(context["stop_signo"], 16), self.parse_key_val_dict( + context["stop_key_val_text"])) def add_QSaveRegisterState_packets(self, thread_id): if thread_id: # Use the thread suffix form. - request = "read packet: $QSaveRegisterState;thread:{:x}#00".format(thread_id) + request = "read packet: $QSaveRegisterState;thread:{:x}#00".format( + thread_id) else: request = "read packet: $QSaveRegisterState#00" - - self.test_sequence.add_log_lines([ - request, - {"direction":"send", "regex":r"^\$(E?.*)#[0-9a-fA-F]{2}$", "capture":{1:"save_response" } }, - ], True) + + self.test_sequence.add_log_lines([request, + {"direction": "send", + "regex": r"^\$(E?.*)#[0-9a-fA-F]{2}$", + "capture": {1: "save_response"}}, + ], + True) def parse_QSaveRegisterState_response(self, context): self.assertIsNotNone(context) @@ -1032,16 +1185,19 @@ class GdbRemoteTestCaseBase(TestBase): def add_QRestoreRegisterState_packets(self, save_id, thread_id=None): if thread_id: # Use the thread suffix form. - request = "read packet: $QRestoreRegisterState:{};thread:{:x}#00".format(save_id, thread_id) + request = "read packet: $QRestoreRegisterState:{};thread:{:x}#00".format( + save_id, thread_id) else: - request = "read packet: $QRestoreRegisterState:{}#00".format(save_id) + request = "read packet: $QRestoreRegisterState:{}#00".format( + save_id) self.test_sequence.add_log_lines([ request, "send packet: $OK#00" - ], True) + ], True) - def flip_all_bits_in_each_register_value(self, reg_infos, endian, thread_id=None): + def flip_all_bits_in_each_register_value( + self, reg_infos, endian, thread_id=None): self.assertIsNotNone(reg_infos) successful_writes = 0 @@ -1049,16 +1205,18 @@ class GdbRemoteTestCaseBase(TestBase): for reg_info in reg_infos: # Use the lldb register index added to the reg info. We're not necessarily - # working off a full set of register infos, so an inferred register index could be wrong. + # working off a full set of register infos, so an inferred register + # index could be wrong. reg_index = reg_info["lldb_register_index"] self.assertIsNotNone(reg_index) - reg_byte_size = int(reg_info["bitsize"])/8 + reg_byte_size = int(reg_info["bitsize"]) / 8 self.assertTrue(reg_byte_size > 0) # Handle thread suffix. if thread_id: - p_request = "read packet: $p{:x};thread:{:x}#00".format(reg_index, thread_id) + p_request = "read packet: $p{:x};thread:{:x}#00".format( + reg_index, thread_id) else: p_request = "read packet: $p{:x}#00".format(reg_index) @@ -1066,15 +1224,16 @@ class GdbRemoteTestCaseBase(TestBase): self.reset_test_sequence() self.test_sequence.add_log_lines([ p_request, - { "direction":"send", "regex":r"^\$([0-9a-fA-F]+)#", "capture":{1:"p_response"} }, - ], True) + {"direction": "send", "regex": r"^\$([0-9a-fA-F]+)#", "capture": {1: "p_response"}}, + ], True) context = self.expect_gdbremote_sequence() self.assertIsNotNone(context) # Verify the response length. p_response = context.get("p_response") self.assertIsNotNone(p_response) - initial_reg_value = unpack_register_hex_unsigned(endian, p_response) + initial_reg_value = unpack_register_hex_unsigned( + endian, p_response) # Flip the value by xoring with all 1s all_one_bits_raw = "ff" * (int(reg_info["bitsize"]) / 8) @@ -1083,16 +1242,22 @@ class GdbRemoteTestCaseBase(TestBase): # Handle thread suffix for P. if thread_id: - P_request = "read packet: $P{:x}={};thread:{:x}#00".format(reg_index, pack_register_hex(endian, flipped_bits_int, byte_size=reg_byte_size), thread_id) + P_request = "read packet: $P{:x}={};thread:{:x}#00".format( + reg_index, pack_register_hex( + endian, flipped_bits_int, byte_size=reg_byte_size), thread_id) else: - P_request = "read packet: $P{:x}={}#00".format(reg_index, pack_register_hex(endian, flipped_bits_int, byte_size=reg_byte_size)) + P_request = "read packet: $P{:x}={}#00".format( + reg_index, pack_register_hex( + endian, flipped_bits_int, byte_size=reg_byte_size)) # Write the flipped value to the register. self.reset_test_sequence() - self.test_sequence.add_log_lines([ - P_request, - { "direction":"send", "regex":r"^\$(OK|E[0-9a-fA-F]+)#[0-9a-fA-F]{2}", "capture":{1:"P_response"} }, - ], True) + self.test_sequence.add_log_lines([P_request, + {"direction": "send", + "regex": r"^\$(OK|E[0-9a-fA-F]+)#[0-9a-fA-F]{2}", + "capture": {1: "P_response"}}, + ], + True) context = self.expect_gdbremote_sequence() self.assertIsNotNone(context) @@ -1107,25 +1272,27 @@ class GdbRemoteTestCaseBase(TestBase): failed_writes += 1 # print("reg (index={}, name={}) write FAILED (error: {})".format(reg_index, reg_info["name"], P_response)) - # Read back the register value, ensure it matches the flipped value. + # Read back the register value, ensure it matches the flipped + # value. if P_response == "OK": self.reset_test_sequence() self.test_sequence.add_log_lines([ p_request, - { "direction":"send", "regex":r"^\$([0-9a-fA-F]+)#", "capture":{1:"p_response"} }, - ], True) + {"direction": "send", "regex": r"^\$([0-9a-fA-F]+)#", "capture": {1: "p_response"}}, + ], True) context = self.expect_gdbremote_sequence() self.assertIsNotNone(context) verify_p_response_raw = context.get("p_response") self.assertIsNotNone(verify_p_response_raw) - verify_bits = unpack_register_hex_unsigned(endian, verify_p_response_raw) + verify_bits = unpack_register_hex_unsigned( + endian, verify_p_response_raw) if verify_bits != flipped_bits_int: # Some registers, like mxcsrmask and others, will permute what's written. Adjust succeed/fail counts. # print("reg (index={}, name={}): read verify FAILED: wrote {:x}, verify read back {:x}".format(reg_index, reg_info["name"], flipped_bits_int, verify_bits)) successful_writes -= 1 - failed_writes +=1 + failed_writes += 1 return (successful_writes, failed_writes) @@ -1136,7 +1303,8 @@ class GdbRemoteTestCaseBase(TestBase): return False if reg_info["set"] != "General Purpose Registers": return False - if ("container-regs" in reg_info) and (len(reg_info["container-regs"]) > 0): + if ("container-regs" in reg_info) and ( + len(reg_info["container-regs"]) > 0): # Don't try to bit flip registers contained in another register. return False if re.match("^.s$", reg_info["name"]): @@ -1154,13 +1322,15 @@ class GdbRemoteTestCaseBase(TestBase): values = {} for reg_info in reg_infos: - # We append a register index when load reg infos so we can work with subsets. + # We append a register index when load reg infos so we can work + # with subsets. reg_index = reg_info.get("lldb_register_index") self.assertIsNotNone(reg_index) # Handle thread suffix. if thread_id: - p_request = "read packet: $p{:x};thread:{:x}#00".format(reg_index, thread_id) + p_request = "read packet: $p{:x};thread:{:x}#00".format( + reg_index, thread_id) else: p_request = "read packet: $p{:x}#00".format(reg_index) @@ -1168,8 +1338,8 @@ class GdbRemoteTestCaseBase(TestBase): self.reset_test_sequence() self.test_sequence.add_log_lines([ p_request, - { "direction":"send", "regex":r"^\$([0-9a-fA-F]+)#", "capture":{1:"p_response"} }, - ], True) + {"direction": "send", "regex": r"^\$([0-9a-fA-F]+)#", "capture": {1: "p_response"}}, + ], True) context = self.expect_gdbremote_sequence() self.assertIsNotNone(context) @@ -1178,58 +1348,75 @@ class GdbRemoteTestCaseBase(TestBase): self.assertIsNotNone(p_response) self.assertTrue(len(p_response) > 0) self.assertFalse(p_response[0] == "E") - - values[reg_index] = unpack_register_hex_unsigned(endian, p_response) - + + values[reg_index] = unpack_register_hex_unsigned( + endian, p_response) + return values def add_vCont_query_packets(self): - self.test_sequence.add_log_lines([ - "read packet: $vCont?#49", - {"direction":"send", "regex":r"^\$(vCont)?(.*)#[0-9a-fA-F]{2}$", "capture":{2:"vCont_query_response" } }, - ], True) + self.test_sequence.add_log_lines(["read packet: $vCont?#49", + {"direction": "send", + "regex": r"^\$(vCont)?(.*)#[0-9a-fA-F]{2}$", + "capture": {2: "vCont_query_response"}}, + ], + True) def parse_vCont_query_response(self, context): self.assertIsNotNone(context) vCont_query_response = context.get("vCont_query_response") - # Handle case of no vCont support at all - in which case the capture group will be none or zero length. + # Handle case of no vCont support at all - in which case the capture + # group will be none or zero length. if not vCont_query_response or len(vCont_query_response) == 0: return {} - return {key:1 for key in vCont_query_response.split(";") if key and len(key) > 0} - - def count_single_steps_until_true(self, thread_id, predicate, args, max_step_count=100, use_Hc_packet=True, step_instruction="s"): + return {key: 1 for key in vCont_query_response.split( + ";") if key and len(key) > 0} + + def count_single_steps_until_true( + self, + thread_id, + predicate, + args, + max_step_count=100, + use_Hc_packet=True, + step_instruction="s"): """Used by single step test that appears in a few different contexts.""" single_step_count = 0 while single_step_count < max_step_count: self.assertIsNotNone(thread_id) - # Build the packet for the single step instruction. We replace {thread}, if present, with the thread_id. - step_packet = "read packet: ${}#00".format(re.sub(r"{thread}", "{:x}".format(thread_id), step_instruction)) + # Build the packet for the single step instruction. We replace + # {thread}, if present, with the thread_id. + step_packet = "read packet: ${}#00".format( + re.sub(r"{thread}", "{:x}".format(thread_id), step_instruction)) # print("\nstep_packet created: {}\n".format(step_packet)) # Single step. self.reset_test_sequence() if use_Hc_packet: self.test_sequence.add_log_lines( - [# Set the continue thread. - "read packet: $Hc{0:x}#00".format(thread_id), - "send packet: $OK#00", - ], True) + [ # Set the continue thread. + "read packet: $Hc{0:x}#00".format(thread_id), + "send packet: $OK#00", + ], True) self.test_sequence.add_log_lines([ - # Single step. - step_packet, - # "read packet: $vCont;s:{0:x}#00".format(thread_id), - # Expect a breakpoint stop report. - {"direction":"send", "regex":r"^\$T([0-9a-fA-F]{2})thread:([0-9a-fA-F]+);", "capture":{1:"stop_signo", 2:"stop_thread_id"} }, - ], True) + # Single step. + step_packet, + # "read packet: $vCont;s:{0:x}#00".format(thread_id), + # Expect a breakpoint stop report. + {"direction": "send", + "regex": r"^\$T([0-9a-fA-F]{2})thread:([0-9a-fA-F]+);", + "capture": {1: "stop_signo", + 2: "stop_thread_id"}}, + ], True) context = self.expect_gdbremote_sequence() self.assertIsNotNone(context) self.assertIsNotNone(context.get("stop_signo")) self.assertEqual(int(context.get("stop_signo"), 16), - lldbutil.get_signal_number('SIGTRAP')) + lldbutil.get_signal_number('SIGTRAP')) single_step_count += 1 @@ -1251,9 +1438,9 @@ class GdbRemoteTestCaseBase(TestBase): self.reset_test_sequence() self.test_sequence.add_log_lines( ["read packet: $m{0:x},{1:x}#00".format(g_c1_address, 1), - {"direction":"send", "regex":r"^\$(.+)#[0-9a-fA-F]{2}$", "capture":{1:"g_c1_contents"} }, + {"direction": "send", "regex": r"^\$(.+)#[0-9a-fA-F]{2}$", "capture": {1: "g_c1_contents"}}, "read packet: $m{0:x},{1:x}#00".format(g_c2_address, 1), - {"direction":"send", "regex":r"^\$(.+)#[0-9a-fA-F]{2}$", "capture":{1:"g_c2_contents"} }], + {"direction": "send", "regex": r"^\$(.+)#[0-9a-fA-F]{2}$", "capture": {1: "g_c2_contents"}}], True) # Run the packet stream. @@ -1264,26 +1451,34 @@ class GdbRemoteTestCaseBase(TestBase): self.assertIsNotNone(context.get("g_c1_contents")) self.assertIsNotNone(context.get("g_c2_contents")) - return (context.get("g_c1_contents").decode("hex") == expected_g_c1) and (context.get("g_c2_contents").decode("hex") == expected_g_c2) + return (context.get("g_c1_contents").decode("hex") == expected_g_c1) and ( + context.get("g_c2_contents").decode("hex") == expected_g_c2) - def single_step_only_steps_one_instruction(self, use_Hc_packet=True, step_instruction="s"): + def single_step_only_steps_one_instruction( + self, use_Hc_packet=True, step_instruction="s"): """Used by single step test that appears in a few different contexts.""" # Start up the inferior. procs = self.prep_debug_monitor_and_inferior( - inferior_args=["get-code-address-hex:swap_chars", "get-data-address-hex:g_c1", "get-data-address-hex:g_c2", "sleep:1", "call-function:swap_chars", "sleep:5"]) + inferior_args=[ + "get-code-address-hex:swap_chars", + "get-data-address-hex:g_c1", + "get-data-address-hex:g_c2", + "sleep:1", + "call-function:swap_chars", + "sleep:5"]) # Run the process self.test_sequence.add_log_lines( - [# Start running after initial stop. - "read packet: $c#63", - # Match output line that prints the memory address of the function call entry point. - # Note we require launch-only testing so we can get inferior otuput. - { "type":"output_match", "regex":r"^code address: 0x([0-9a-fA-F]+)\r\ndata address: 0x([0-9a-fA-F]+)\r\ndata address: 0x([0-9a-fA-F]+)\r\n$", - "capture":{ 1:"function_address", 2:"g_c1_address", 3:"g_c2_address"} }, - # Now stop the inferior. - "read packet: {}".format(chr(3)), - # And wait for the stop notification. - {"direction":"send", "regex":r"^\$T([0-9a-fA-F]{2})thread:([0-9a-fA-F]+);", "capture":{1:"stop_signo", 2:"stop_thread_id"} }], + [ # Start running after initial stop. + "read packet: $c#63", + # Match output line that prints the memory address of the function call entry point. + # Note we require launch-only testing so we can get inferior otuput. + {"type": "output_match", "regex": r"^code address: 0x([0-9a-fA-F]+)\r\ndata address: 0x([0-9a-fA-F]+)\r\ndata address: 0x([0-9a-fA-F]+)\r\n$", + "capture": {1: "function_address", 2: "g_c1_address", 3: "g_c2_address"}}, + # Now stop the inferior. + "read packet: {}".format(chr(3)), + # And wait for the stop notification. + {"direction": "send", "regex": r"^\$T([0-9a-fA-F]{2})thread:([0-9a-fA-F]+);", "capture": {1: "stop_signo", 2: "stop_thread_id"}}], True) # Run the packet stream. @@ -1312,13 +1507,17 @@ class GdbRemoteTestCaseBase(TestBase): else: BREAKPOINT_KIND = 1 self.reset_test_sequence() - self.add_set_breakpoint_packets(function_address, do_continue=True, breakpoint_kind=BREAKPOINT_KIND) + self.add_set_breakpoint_packets( + function_address, + do_continue=True, + breakpoint_kind=BREAKPOINT_KIND) context = self.expect_gdbremote_sequence() self.assertIsNotNone(context) # Remove the breakpoint. self.reset_test_sequence() - self.add_remove_breakpoint_packets(function_address, breakpoint_kind=BREAKPOINT_KIND) + self.add_remove_breakpoint_packets( + function_address, breakpoint_kind=BREAKPOINT_KIND) context = self.expect_gdbremote_sequence() self.assertIsNotNone(context) @@ -1331,44 +1530,72 @@ class GdbRemoteTestCaseBase(TestBase): self.assertTrue(self.g_c1_c2_contents_are(args)) - # Verify we take only a small number of steps to hit the first state. Might need to work through function entry prologue code. + # Verify we take only a small number of steps to hit the first state. + # Might need to work through function entry prologue code. args["expected_g_c1"] = "1" args["expected_g_c2"] = "1" - (state_reached, step_count) = self.count_single_steps_until_true(main_thread_id, self.g_c1_c2_contents_are, args, max_step_count=25, use_Hc_packet=use_Hc_packet, step_instruction=step_instruction) + (state_reached, + step_count) = self.count_single_steps_until_true(main_thread_id, + self.g_c1_c2_contents_are, + args, + max_step_count=25, + use_Hc_packet=use_Hc_packet, + step_instruction=step_instruction) self.assertTrue(state_reached) # Verify we hit the next state. args["expected_g_c1"] = "1" args["expected_g_c2"] = "0" - (state_reached, step_count) = self.count_single_steps_until_true(main_thread_id, self.g_c1_c2_contents_are, args, max_step_count=5, use_Hc_packet=use_Hc_packet, step_instruction=step_instruction) + (state_reached, + step_count) = self.count_single_steps_until_true(main_thread_id, + self.g_c1_c2_contents_are, + args, + max_step_count=5, + use_Hc_packet=use_Hc_packet, + step_instruction=step_instruction) self.assertTrue(state_reached) expected_step_count = 1 arch = self.getArchitecture() - #MIPS required "3" (ADDIU, SB, LD) machine instructions for updation of variable value - if re.match("mips",arch): - expected_step_count = 3 - #S390X requires "2" (LARL, MVI) machine instructions for updation of variable value - if re.match("s390x",arch): - expected_step_count = 2 + # MIPS required "3" (ADDIU, SB, LD) machine instructions for updation + # of variable value + if re.match("mips", arch): + expected_step_count = 3 + # S390X requires "2" (LARL, MVI) machine instructions for updation of + # variable value + if re.match("s390x", arch): + expected_step_count = 2 self.assertEqual(step_count, expected_step_count) # Verify we hit the next state. args["expected_g_c1"] = "0" args["expected_g_c2"] = "0" - (state_reached, step_count) = self.count_single_steps_until_true(main_thread_id, self.g_c1_c2_contents_are, args, max_step_count=5, use_Hc_packet=use_Hc_packet, step_instruction=step_instruction) + (state_reached, + step_count) = self.count_single_steps_until_true(main_thread_id, + self.g_c1_c2_contents_are, + args, + max_step_count=5, + use_Hc_packet=use_Hc_packet, + step_instruction=step_instruction) self.assertTrue(state_reached) self.assertEqual(step_count, expected_step_count) # Verify we hit the next state. args["expected_g_c1"] = "0" args["expected_g_c2"] = "1" - (state_reached, step_count) = self.count_single_steps_until_true(main_thread_id, self.g_c1_c2_contents_are, args, max_step_count=5, use_Hc_packet=use_Hc_packet, step_instruction=step_instruction) + (state_reached, + step_count) = self.count_single_steps_until_true(main_thread_id, + self.g_c1_c2_contents_are, + args, + max_step_count=5, + use_Hc_packet=use_Hc_packet, + step_instruction=step_instruction) self.assertTrue(state_reached) self.assertEqual(step_count, expected_step_count) def maybe_strict_output_regex(self, regex): - return '.*'+regex+'.*' if lldbplatformutil.hasChattyStderr(self) else '^'+regex+'$' + return '.*' + regex + \ + '.*' if lldbplatformutil.hasChattyStderr(self) else '^' + regex + '$' def install_and_create_launch_args(self): exe_path = os.path.abspath('a.out') diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/inferior-crash/TestGdbRemoteAbort.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/inferior-crash/TestGdbRemoteAbort.py index 8bd00a3f1b2..b417b3292e7 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/inferior-crash/TestGdbRemoteAbort.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/inferior-crash/TestGdbRemoteAbort.py @@ -1,13 +1,13 @@ from __future__ import print_function - import gdbremote_testcase import signal from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * from lldbsuite.test import lldbutil + class TestGdbRemoteAbort(gdbremote_testcase.GdbRemoteTestCaseBase): mydir = TestBase.compute_mydir(__file__) @@ -15,10 +15,12 @@ class TestGdbRemoteAbort(gdbremote_testcase.GdbRemoteTestCaseBase): procs = self.prep_debug_monitor_and_inferior(inferior_args=["abort"]) self.assertIsNotNone(procs) - self.test_sequence.add_log_lines([ - "read packet: $vCont;c#a8", - {"direction":"send", "regex":r"^\$T([0-9a-fA-F]{2}).*#[0-9a-fA-F]{2}$", "capture":{ 1:"hex_exit_code"} }, - ], True) + self.test_sequence.add_log_lines(["read packet: $vCont;c#a8", + {"direction": "send", + "regex": r"^\$T([0-9a-fA-F]{2}).*#[0-9a-fA-F]{2}$", + "capture": {1: "hex_exit_code"}}, + ], + True) context = self.expect_gdbremote_sequence() self.assertIsNotNone(context) @@ -26,7 +28,7 @@ class TestGdbRemoteAbort(gdbremote_testcase.GdbRemoteTestCaseBase): hex_exit_code = context.get("hex_exit_code") self.assertIsNotNone(hex_exit_code) self.assertEqual(int(hex_exit_code, 16), - lldbutil.get_signal_number('SIGABRT')) + lldbutil.get_signal_number('SIGABRT')) @debugserver_test def test_inferior_abort_received_debugserver(self): @@ -41,4 +43,3 @@ class TestGdbRemoteAbort(gdbremote_testcase.GdbRemoteTestCaseBase): self.init_llgs_test() self.build() self.inferior_abort_received() - diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/inferior-crash/TestGdbRemoteSegFault.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/inferior-crash/TestGdbRemoteSegFault.py index 949b00b0f61..5bbca3c146d 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/inferior-crash/TestGdbRemoteSegFault.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/inferior-crash/TestGdbRemoteSegFault.py @@ -1,26 +1,29 @@ from __future__ import print_function - import gdbremote_testcase import signal from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * from lldbsuite.test import lldbutil + class TestGdbRemoteSegFault(gdbremote_testcase.GdbRemoteTestCaseBase): mydir = TestBase.compute_mydir(__file__) GDB_REMOTE_STOP_CODE_BAD_ACCESS = 0x91 def inferior_seg_fault_received(self, expected_signo): - procs = self.prep_debug_monitor_and_inferior(inferior_args=["segfault"]) + procs = self.prep_debug_monitor_and_inferior( + inferior_args=["segfault"]) self.assertIsNotNone(procs) - self.test_sequence.add_log_lines([ - "read packet: $vCont;c#a8", - {"direction":"send", "regex":r"^\$T([0-9a-fA-F]{2}).*#[0-9a-fA-F]{2}$", "capture":{ 1:"hex_exit_code"} }, - ], True) + self.test_sequence.add_log_lines(["read packet: $vCont;c#a8", + {"direction": "send", + "regex": r"^\$T([0-9a-fA-F]{2}).*#[0-9a-fA-F]{2}$", + "capture": {1: "hex_exit_code"}}, + ], + True) context = self.expect_gdbremote_sequence() self.assertIsNotNone(context) diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/lldbgdbserverutils.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/lldbgdbserverutils.py index 0c73bed9ea0..c89cd301899 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/lldbgdbserverutils.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/lldbgdbserverutils.py @@ -4,7 +4,6 @@ from __future__ import print_function - import os import os.path import platform @@ -17,6 +16,7 @@ from lldbsuite.test.lldbtest import * from six.moves import queue + def _get_debug_monitor_from_lldb(lldb_exe, debug_monitor_basename): """Return the debug monitor exe path given the lldb exe path. @@ -55,7 +55,10 @@ def _get_debug_monitor_from_lldb(lldb_exe, debug_monitor_basename): if os.path.exists(debug_monitor_exe): return debug_monitor_exe - new_base = regex.sub( 'LLDB.framework/Versions/A/Resources/' + debug_monitor_basename, exe_base) + new_base = regex.sub( + 'LLDB.framework/Versions/A/Resources/' + + debug_monitor_basename, + exe_base) debug_monitor_exe = os.path.join(exe_dir, new_base) if os.path.exists(debug_monitor_exe): return debug_monitor_exe @@ -73,7 +76,9 @@ def get_lldb_server_exe(): if "LLDB_DEBUGSERVER_PATH" in os.environ: return os.environ["LLDB_DEBUGSERVER_PATH"] - return _get_debug_monitor_from_lldb(lldbtest_config.lldbExec, "lldb-server") + return _get_debug_monitor_from_lldb( + lldbtest_config.lldbExec, "lldb-server") + def get_debugserver_exe(): """Return the debugserver exe path. @@ -85,10 +90,11 @@ def get_debugserver_exe(): if "LLDB_DEBUGSERVER_PATH" in os.environ: return os.environ["LLDB_DEBUGSERVER_PATH"] - return _get_debug_monitor_from_lldb(lldbtest_config.lldbExec, "debugserver") + return _get_debug_monitor_from_lldb( + lldbtest_config.lldbExec, "debugserver") _LOG_LINE_REGEX = re.compile(r'^(lldb-server|debugserver)\s+<\s*(\d+)>' + - '\s+(read|send)\s+packet:\s+(.+)$') + '\s+(read|send)\s+packet:\s+(.+)$') def _is_packet_lldb_gdbserver_input(packet_type, llgs_input_is_read): @@ -131,10 +137,12 @@ def handle_O_packet(context, packet_contents, logger): new_text = gdbremote_hex_decode_string(packet_contents[1:]) context["O_content"] += new_text context["O_count"] += 1 - + if logger: - logger.debug("text: new \"{}\", cumulative: \"{}\"".format(new_text, context["O_content"])) - + logger.debug( + "text: new \"{}\", cumulative: \"{}\"".format( + new_text, context["O_content"])) + return True _STRIP_CHECKSUM_REGEX = re.compile(r'#[0-9a-fA-F]{2}$') @@ -150,13 +158,14 @@ def assert_packets_equal(asserter, actual_packet, expected_packet): expected_stripped = _STRIP_CHECKSUM_REGEX.sub('', expected_packet) asserter.assertEqual(actual_stripped, expected_stripped) + def expect_lldb_gdbserver_replay( - asserter, - sock, - test_sequence, - pump_queues, - timeout_seconds, - logger=None): + asserter, + sock, + test_sequence, + pump_queues, + timeout_seconds, + logger=None): """Replay socket communication with lldb-gdbserver and verify responses. Args: @@ -188,16 +197,16 @@ def expect_lldb_gdbserver_replay( context["O_count"] will contain an integer of the number of O packets received. """ - + # Ensure we have some work to do. if len(test_sequence.entries) < 1: return {} - context = {"O_count":0, "O_content":""} + context = {"O_count": 0, "O_content": ""} with socket_packet_pump.SocketPacketPump(sock, pump_queues, logger) as pump: # Grab the first sequence entry. sequence_entry = test_sequence.entries.pop(0) - + # While we have an active sequence entry, send messages # destined for the stub and collect/match/process responses # expected from the stub. @@ -210,10 +219,12 @@ def expect_lldb_gdbserver_replay( packet_desc = "^C" else: packet_desc = send_packet - logger.info("sending packet to remote: {}".format(packet_desc)) + logger.info( + "sending packet to remote: {}".format(packet_desc)) sock.sendall(send_packet) else: - # This is an entry expecting to receive content from the remote debug monitor. + # This is an entry expecting to receive content from the remote + # debug monitor. # We'll pull from (and wait on) the queue appropriate for the type of matcher. # We keep separate queues for process output (coming from non-deterministic @@ -224,51 +235,65 @@ def expect_lldb_gdbserver_replay( content = pump_queues.output_queue().get(True, timeout_seconds) except queue.Empty: if logger: - logger.warning("timeout waiting for stub output (accumulated output:{})".format(pump.get_accumulated_output())) - raise Exception("timed out while waiting for output match (accumulated output: {})".format(pump.get_accumulated_output())) + logger.warning( + "timeout waiting for stub output (accumulated output:{})".format( + pump.get_accumulated_output())) + raise Exception( + "timed out while waiting for output match (accumulated output: {})".format( + pump.get_accumulated_output())) else: try: content = pump_queues.packet_queue().get(True, timeout_seconds) except queue.Empty: if logger: - logger.warning("timeout waiting for packet match (receive buffer: {})".format(pump.get_receive_buffer())) - raise Exception("timed out while waiting for packet match (receive buffer: {})".format(pump.get_receive_buffer())) - + logger.warning( + "timeout waiting for packet match (receive buffer: {})".format( + pump.get_receive_buffer())) + raise Exception( + "timed out while waiting for packet match (receive buffer: {})".format( + pump.get_receive_buffer())) + # Give the sequence entry the opportunity to match the content. # Output matchers might match or pass after more output accumulates. # Other packet types generally must match. asserter.assertIsNotNone(content) - context = sequence_entry.assert_match(asserter, content, context=context) + context = sequence_entry.assert_match( + asserter, content, context=context) # Move on to next sequence entry as needed. Some sequence entries support executing multiple - # times in different states (for looping over query/response packets). + # times in different states (for looping over query/response + # packets). if sequence_entry.is_consumed(): if len(test_sequence.entries) > 0: sequence_entry = test_sequence.entries.pop(0) else: sequence_entry = None - + # Fill in the O_content entries. context["O_count"] = 1 context["O_content"] = pump.get_accumulated_output() - + return context + def gdbremote_hex_encode_string(str): output = '' for c in str: output += '{0:02x}'.format(ord(c)) return output + def gdbremote_hex_decode_string(str): return str.decode("hex") + def gdbremote_packet_encode_string(str): checksum = 0 for c in str: checksum += ord(c) return '$' + str + '#{0:02x}'.format(checksum % 256) + def build_gdbremote_A_packet(args_list): """Given a list of args, create a properly-formed $A packet containing each arg. """ @@ -322,7 +347,9 @@ def parse_threadinfo_response(response_packet): response_packet = _STRIP_CHECKSUM_REGEX.sub("", response_packet) # Return list of thread ids - return [int(thread_id_hex,16) for thread_id_hex in response_packet.split(",") if len(thread_id_hex) > 0] + return [int(thread_id_hex, 16) for thread_id_hex in response_packet.split( + ",") if len(thread_id_hex) > 0] + def unpack_endian_binary_string(endian, value_string): """Unpack a gdb-remote binary (post-unescaped, i.e. not escaped) response to an unsigned int given endianness of the inferior.""" @@ -349,6 +376,7 @@ def unpack_endian_binary_string(endian, value_string): # pdp is valid but need to add parse code once needed. raise Exception("unsupported endian:{}".format(endian)) + def unpack_register_hex_unsigned(endian, value_string): """Unpack a gdb-remote $p-style response to an unsigned int given endianness of inferior.""" if not endian: @@ -370,6 +398,7 @@ def unpack_register_hex_unsigned(endian, value_string): # pdp is valid but need to add parse code once needed. raise Exception("unsupported endian:{}".format(endian)) + def pack_register_hex(endian, value, byte_size=None): """Unpack a gdb-remote $p-style response to an unsigned int given endianness of inferior.""" if not endian: @@ -383,7 +412,7 @@ def pack_register_hex(endian, value, byte_size=None): value = value >> 8 if byte_size: # Add zero-fill to the right/end (MSB side) of the value. - retval += "00" * (byte_size - len(retval)/2) + retval += "00" * (byte_size - len(retval) / 2) return retval elif endian == 'big': @@ -393,20 +422,29 @@ def pack_register_hex(endian, value, byte_size=None): value = value >> 8 if byte_size: # Add zero-fill to the left/front (MSB side) of the value. - retval = ("00" * (byte_size - len(retval)/2)) + retval + retval = ("00" * (byte_size - len(retval) / 2)) + retval return retval else: # pdp is valid but need to add parse code once needed. raise Exception("unsupported endian:{}".format(endian)) + class GdbRemoteEntryBase(object): + def is_output_matcher(self): return False + class GdbRemoteEntry(GdbRemoteEntryBase): - def __init__(self, is_send_to_remote=True, exact_payload=None, regex=None, capture=None, expect_captures=None): + def __init__( + self, + is_send_to_remote=True, + exact_payload=None, + regex=None, + capture=None, + expect_captures=None): """Create an entry representing one piece of the I/O to/from a gdb remote debug monitor. Args: @@ -469,9 +507,11 @@ class GdbRemoteEntry(GdbRemoteEntryBase): def get_send_packet(self): if not self.is_send_to_remote(): - raise Exception("get_send_packet() called on GdbRemoteEntry that is not a send-to-remote packet") + raise Exception( + "get_send_packet() called on GdbRemoteEntry that is not a send-to-remote packet") if not self.exact_payload: - raise Exception("get_send_packet() called on GdbRemoteEntry but it doesn't have an exact payload") + raise Exception( + "get_send_packet() called on GdbRemoteEntry but it doesn't have an exact payload") return self.exact_payload def _assert_exact_payload_match(self, asserter, actual_packet): @@ -482,14 +522,17 @@ class GdbRemoteEntry(GdbRemoteEntryBase): # Ensure the actual packet matches from the start of the actual packet. match = self.regex.match(actual_packet) if not match: - asserter.fail("regex '{}' failed to match against content '{}'".format(self.regex.pattern, actual_packet)) + asserter.fail( + "regex '{}' failed to match against content '{}'".format( + self.regex.pattern, actual_packet)) if self.capture: # Handle captures. for group_index, var_name in list(self.capture.items()): capture_text = match.group(group_index) # It is okay for capture text to be None - which it will be if it is a group that can match nothing. - # The user must be okay with it since the regex itself matched above. + # The user must be okay with it since the regex itself matched + # above. context[var_name] = capture_text if self.expect_captures: @@ -497,7 +540,8 @@ class GdbRemoteEntry(GdbRemoteEntryBase): for group_index, var_name in list(self.expect_captures.items()): capture_text = match.group(group_index) if not capture_text: - raise Exception("No content to expect for group index {}".format(group_index)) + raise Exception( + "No content to expect for group index {}".format(group_index)) asserter.assertEqual(capture_text, context[var_name]) return context @@ -506,7 +550,8 @@ class GdbRemoteEntry(GdbRemoteEntryBase): # This only makes sense for matching lines coming from the # remote debug monitor. if self.is_send_to_remote(): - raise Exception("Attempted to match a packet being sent to the remote debug monitor, doesn't make sense.") + raise Exception( + "Attempted to match a packet being sent to the remote debug monitor, doesn't make sense.") # Create a new context if needed. if not context: @@ -521,16 +566,18 @@ class GdbRemoteEntry(GdbRemoteEntryBase): elif self.regex: return self._assert_regex_match(asserter, actual_packet, context) else: - raise Exception("Don't know how to match a remote-sent packet when exact_payload isn't specified.") + raise Exception( + "Don't know how to match a remote-sent packet when exact_payload isn't specified.") + class MultiResponseGdbRemoteEntry(GdbRemoteEntryBase): """Represents a query/response style packet. - + Assumes the first item is sent to the gdb remote. An end sequence regex indicates the end of the query/response packet sequence. All responses up through (but not including) the end response are stored in a context variable. - + Settings accepted from params: next_query or query: required. The typical query packet without the $ prefix or #xx suffix. @@ -557,17 +604,20 @@ class MultiResponseGdbRemoteEntry(GdbRemoteEntryBase): assume there is something wrong with either the response collection or the ending detection regex and throw an exception. """ + def __init__(self, params): self._next_query = params.get("next_query", params.get("query")) if not self._next_query: raise "either next_query or query key must be specified for MultiResponseGdbRemoteEntry" - + self._first_query = params.get("first_query", self._next_query) - self._append_iteration_suffix = params.get("append_iteration_suffix", False) + self._append_iteration_suffix = params.get( + "append_iteration_suffix", False) self._iteration = 0 self._end_regex = params["end_regex"] self._save_key = params["save_key"] - self._runaway_response_count = params.get("runaway_response_count", 10000) + self._runaway_response_count = params.get( + "runaway_response_count", 10000) self._is_send_to_remote = True self._end_matched = False @@ -576,9 +626,11 @@ class MultiResponseGdbRemoteEntry(GdbRemoteEntryBase): def get_send_packet(self): if not self.is_send_to_remote(): - raise Exception("get_send_packet() called on MultiResponseGdbRemoteEntry that is not in the send state") + raise Exception( + "get_send_packet() called on MultiResponseGdbRemoteEntry that is not in the send state") if self._end_matched: - raise Exception("get_send_packet() called on MultiResponseGdbRemoteEntry but end of query/response sequence has already been seen.") + raise Exception( + "get_send_packet() called on MultiResponseGdbRemoteEntry but end of query/response sequence has already been seen.") # Choose the first or next query for the base payload. if self._iteration == 0 and self._first_query: @@ -593,7 +645,8 @@ class MultiResponseGdbRemoteEntry(GdbRemoteEntryBase): # Keep track of the iteration. self._iteration += 1 - # Now that we've given the query packet, flip the mode to receive/match. + # Now that we've given the query packet, flip the mode to + # receive/match. self._is_send_to_remote = False # Return the result, converted to packet form. @@ -603,12 +656,15 @@ class MultiResponseGdbRemoteEntry(GdbRemoteEntryBase): return self._end_matched def assert_match(self, asserter, actual_packet, context=None): - # This only makes sense for matching lines coming from the remote debug monitor. + # This only makes sense for matching lines coming from the remote debug + # monitor. if self.is_send_to_remote(): - raise Exception("assert_match() called on MultiResponseGdbRemoteEntry but state is set to send a query packet.") + raise Exception( + "assert_match() called on MultiResponseGdbRemoteEntry but state is set to send a query packet.") if self._end_matched: - raise Exception("assert_match() called on MultiResponseGdbRemoteEntry but end of query/response sequence has already been seen.") + raise Exception( + "assert_match() called on MultiResponseGdbRemoteEntry but end of query/response sequence has already been seen.") # Set up a context as needed. if not context: @@ -627,21 +683,27 @@ class MultiResponseGdbRemoteEntry(GdbRemoteEntryBase): # Check for a runaway response cycle. if len(context[self._save_key]) >= self._runaway_response_count: - raise Exception("runaway query/response cycle detected: %d responses captured so far. Last response: %s" % - (len(context[self._save_key]), context[self._save_key][-1])) + raise Exception( + "runaway query/response cycle detected: %d responses captured so far. Last response: %s" % + (len( + context[ + self._save_key]), context[ + self._save_key][ + -1])) # Flip the mode to send for generating the query. self._is_send_to_remote = True return context + class MatchRemoteOutputEntry(GdbRemoteEntryBase): """Waits for output from the debug monitor to match a regex or time out. - + This entry type tries to match each time new gdb remote output is accumulated using a provided regex. If the output does not match the regex within the given timeframe, the command fails the playback session. If the regex does match, any capture fields are recorded in the context. - + Settings accepted from params: regex: required. Specifies a compiled regex object that must either succeed @@ -653,7 +715,7 @@ class MatchRemoteOutputEntry(GdbRemoteEntryBase): must match starting somewhere within the output text accumulated thus far. Default: "match" (i.e. the regex must match the entirety of the accumulated output buffer, so unexpected text will generally fail the match). - + capture: optional. If specified, is a dictionary of regex match group indices (should start with 1) to variable names that will store the capture group indicated by the index. For example, {1:"thread_id"} will store capture group 1's content in the @@ -661,6 +723,7 @@ class MatchRemoteOutputEntry(GdbRemoteEntryBase): the value. The value stored off can be used later in a expect_captures expression. This arg only makes sense when regex is specified. """ + def __init__(self, regex=None, regex_mode="match", capture=None): self._regex = regex self._regex_mode = regex_mode @@ -671,7 +734,9 @@ class MatchRemoteOutputEntry(GdbRemoteEntryBase): raise Exception("regex cannot be None") if not self._regex_mode in ["match", "search"]: - raise Exception("unsupported regex mode \"{}\": must be \"match\" or \"search\"".format(self._regex_mode)) + raise Exception( + "unsupported regex mode \"{}\": must be \"match\" or \"search\"".format( + self._regex_mode)) def is_output_matcher(self): return True @@ -692,7 +757,8 @@ class MatchRemoteOutputEntry(GdbRemoteEntryBase): # Validate that we haven't already matched. if self._matched: - raise Exception("invalid state - already matched, attempting to match again") + raise Exception( + "invalid state - already matched, attempting to match again") # If we don't have any content yet, we don't match. if len(accumulated_output) < 1: @@ -704,9 +770,12 @@ class MatchRemoteOutputEntry(GdbRemoteEntryBase): elif self._regex_mode == "search": match = self._regex.search(accumulated_output) else: - raise Exception("Unexpected regex mode: {}".format(self._regex_mode)) + raise Exception( + "Unexpected regex mode: {}".format( + self._regex_mode)) - # If we don't match, wait to try again after next $O content, or time out. + # If we don't match, wait to try again after next $O content, or time + # out. if not match: # print("re pattern \"{}\" did not match against \"{}\"".format(self._regex.pattern, accumulated_output)) return context @@ -721,7 +790,8 @@ class MatchRemoteOutputEntry(GdbRemoteEntryBase): for group_index, var_name in list(self._capture.items()): capture_text = match.group(group_index) if not capture_text: - raise Exception("No content for group index {}".format(group_index)) + raise Exception( + "No content for group index {}".format(group_index)) context[var_name] = capture_text return context @@ -737,7 +807,7 @@ class GdbRemoteTestSequence(object): def add_log_lines(self, log_lines, remote_input_is_read): for line in log_lines: - if type(line) == str: + if isinstance(line, str): # Handle log line import # if self.logger: # self.logger.debug("processing log line: {}".format(line)) @@ -745,19 +815,27 @@ class GdbRemoteTestSequence(object): if match: playback_packet = match.group(2) direction = match.group(1) - if _is_packet_lldb_gdbserver_input(direction, remote_input_is_read): + if _is_packet_lldb_gdbserver_input( + direction, remote_input_is_read): # Handle as something to send to the remote debug monitor. # if self.logger: # self.logger.info("processed packet to send to remote: {}".format(playback_packet)) - self.entries.append(GdbRemoteEntry(is_send_to_remote=True, exact_payload=playback_packet)) + self.entries.append( + GdbRemoteEntry( + is_send_to_remote=True, + exact_payload=playback_packet)) else: # Log line represents content to be expected from the remote debug monitor. # if self.logger: # self.logger.info("receiving packet from llgs, should match: {}".format(playback_packet)) - self.entries.append(GdbRemoteEntry(is_send_to_remote=False,exact_payload=playback_packet)) + self.entries.append( + GdbRemoteEntry( + is_send_to_remote=False, + exact_payload=playback_packet)) else: - raise Exception("failed to interpret log line: {}".format(line)) - elif type(line) == dict: + raise Exception( + "failed to interpret log line: {}".format(line)) + elif isinstance(line, dict): entry_type = line.get("type", "regex_capture") if entry_type == "regex_capture": # Handle more explicit control over details via dictionary. @@ -767,34 +845,50 @@ class GdbRemoteTestSequence(object): expect_captures = line.get("expect_captures", None) # Compile the regex. - if regex and (type(regex) == str): + if regex and (isinstance(regex, str)): regex = re.compile(regex) - if _is_packet_lldb_gdbserver_input(direction, remote_input_is_read): + if _is_packet_lldb_gdbserver_input( + direction, remote_input_is_read): # Handle as something to send to the remote debug monitor. # if self.logger: # self.logger.info("processed dict sequence to send to remote") - self.entries.append(GdbRemoteEntry(is_send_to_remote=True, regex=regex, capture=capture, expect_captures=expect_captures)) + self.entries.append( + GdbRemoteEntry( + is_send_to_remote=True, + regex=regex, + capture=capture, + expect_captures=expect_captures)) else: # Log line represents content to be expected from the remote debug monitor. # if self.logger: # self.logger.info("processed dict sequence to match receiving from remote") - self.entries.append(GdbRemoteEntry(is_send_to_remote=False, regex=regex, capture=capture, expect_captures=expect_captures)) + self.entries.append( + GdbRemoteEntry( + is_send_to_remote=False, + regex=regex, + capture=capture, + expect_captures=expect_captures)) elif entry_type == "multi_response": self.entries.append(MultiResponseGdbRemoteEntry(line)) elif entry_type == "output_match": regex = line.get("regex", None) # Compile the regex. - if regex and (type(regex) == str): + if regex and (isinstance(regex, str)): regex = re.compile(regex, re.DOTALL) regex_mode = line.get("regex_mode", "match") capture = line.get("capture", None) - self.entries.append(MatchRemoteOutputEntry(regex=regex, regex_mode=regex_mode, capture=capture)) + self.entries.append( + MatchRemoteOutputEntry( + regex=regex, + regex_mode=regex_mode, + capture=capture)) else: raise Exception("unknown entry type \"%s\"" % entry_type) + def process_is_running(pid, unknown_value=True): """If possible, validate that the given pid represents a running process on the local system. @@ -814,7 +908,9 @@ def process_is_running(pid, unknown_value=True): return the value provided by the unknown_value arg. """ if not isinstance(pid, six.integer_types): - raise Exception("pid must be an integral type (actual type: %s)" % str(type(pid))) + raise Exception( + "pid must be an integral type (actual type: %s)" % str( + type(pid))) process_ids = [] @@ -824,10 +920,12 @@ def process_is_running(pid, unknown_value=True): return unknown_value elif platform.system() in ['Darwin', 'Linux', 'FreeBSD', 'NetBSD']: # Build the list of running process ids - output = subprocess.check_output("ps ax | awk '{ print $1; }'", shell=True) + output = subprocess.check_output( + "ps ax | awk '{ print $1; }'", shell=True) text_process_ids = output.split('\n')[1:] # Convert text pids to ints - process_ids = [int(text_pid) for text_pid in text_process_ids if text_pid != ''] + process_ids = [int(text_pid) + for text_pid in text_process_ids if text_pid != ''] # elif {your_platform_here}: # fill in process_ids as a list of int type process IDs running on # the local system. diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/platform-process-connect/TestPlatformProcessConnect.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/platform-process-connect/TestPlatformProcessConnect.py index 5c28d288db5..7e4190b7fe9 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/platform-process-connect/TestPlatformProcessConnect.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/platform-process-connect/TestPlatformProcessConnect.py @@ -7,6 +7,7 @@ from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * from lldbsuite.test import lldbutil + class TestPlatformProcessConnect(gdbremote_testcase.GdbRemoteTestCaseBase): mydir = TestBase.compute_mydir(__file__) @@ -19,10 +20,16 @@ class TestPlatformProcessConnect(gdbremote_testcase.GdbRemoteTestCaseBase): self.init_llgs_test(False) working_dir = lldb.remote_platform.GetWorkingDirectory() - err = lldb.remote_platform.Put(lldb.SBFileSpec(os.path.join(os.getcwd(), "a.out")), - lldb.SBFileSpec(os.path.join(working_dir, "a.out"))) + err = lldb.remote_platform.Put( + lldb.SBFileSpec( + os.path.join( + os.getcwd(), "a.out")), lldb.SBFileSpec( + os.path.join( + working_dir, "a.out"))) if err.Fail(): - raise RuntimeError("Unable copy '%s' to '%s'.\n>>> %s" % (f, wd, err.GetCString())) + raise RuntimeError( + "Unable copy '%s' to '%s'.\n>>> %s" % + (f, wd, err.GetCString())) m = re.search("^(.*)://([^:/]*)", configuration.lldb_platform_url) protocol = m.group(1) @@ -30,19 +37,34 @@ class TestPlatformProcessConnect(gdbremote_testcase.GdbRemoteTestCaseBase): unix_protocol = protocol.startswith("unix-") if unix_protocol: p = re.search("^(.*)-connect", protocol) - listen_url = "%s://%s" % (p.group(1), os.path.join(working_dir, "platform-%d.sock" % int(time.time()))) + listen_url = "%s://%s" % (p.group(1), + os.path.join(working_dir, + "platform-%d.sock" % int(time.time()))) else: listen_url = "*:0" port_file = "%s/port" % working_dir - commandline_args = ["platform", "--listen", listen_url, "--socket-file", port_file, "--", "%s/a.out" % working_dir, "foo"] - self.spawnSubprocess(self.debug_monitor_exe, commandline_args, install_remote=False) + commandline_args = [ + "platform", + "--listen", + listen_url, + "--socket-file", + port_file, + "--", + "%s/a.out" % + working_dir, + "foo"] + self.spawnSubprocess( + self.debug_monitor_exe, + commandline_args, + install_remote=False) self.addTearDownHook(self.cleanupSubprocesses) socket_id = lldbutil.wait_for_file_on_target(self, port_file) new_debugger = lldb.SBDebugger.Create() new_debugger.SetAsync(False) + def del_debugger(new_debugger=new_debugger): del new_debugger self.addTearDownHook(del_debugger) @@ -59,7 +81,10 @@ class TestPlatformProcessConnect(gdbremote_testcase.GdbRemoteTestCaseBase): command = "platform connect %s" % (connect_url) result = lldb.SBCommandReturnObject() new_interpreter.HandleCommand(command, result) - self.assertTrue(result.Succeeded(), "platform process connect failed: %s" % result.GetOutput()) + self.assertTrue( + result.Succeeded(), + "platform process connect failed: %s" % + result.GetOutput()) target = new_debugger.GetSelectedTarget() process = target.GetProcess() diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/socket_packet_pump.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/socket_packet_pump.py index 9f594b7df73..6f32dcacd35 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/socket_packet_pump.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/socket_packet_pump.py @@ -2,7 +2,6 @@ from __future__ import print_function - import re import select import threading @@ -11,6 +10,7 @@ import codecs from six.moves import queue + def _handle_output_packet_string(packet_contents): if (not packet_contents) or (len(packet_contents) < 1): return None @@ -21,12 +21,15 @@ def _handle_output_packet_string(packet_contents): else: return packet_contents[1:].decode("hex") + def _dump_queue(the_queue): while not the_queue.empty(): print(codecs.encode(the_queue.get(True), "string_escape")) print("\n") + class PumpQueues(object): + def __init__(self): self._output_queue = queue.Queue() self._packet_queue = queue.Queue() @@ -179,7 +182,8 @@ class SocketPacketPump(object): # Likely a closed socket. Done with the pump thread. if self._logger: self._logger.debug( - "socket read failed, stopping pump read thread\n" + traceback.format_exc(3)) + "socket read failed, stopping pump read thread\n" + + traceback.format_exc(3)) break self._process_new_bytes(new_bytes) diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/test/test_lldbgdbserverutils.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/test/test_lldbgdbserverutils.py index 8b3b6b68cf0..dc52f244aa4 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/test/test_lldbgdbserverutils.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/test/test_lldbgdbserverutils.py @@ -1,7 +1,6 @@ from __future__ import print_function - import unittest2 import os.path import re @@ -11,6 +10,7 @@ from lldbgdbserverutils import * class TestLldbGdbServerUtils(unittest2.TestCase): + def test_entry_exact_payload_match(self): entry = GdbRemoteEntry(is_send_to_remote=False, exact_payload="$OK#9a") entry.assert_match(self, "$OK#9a") @@ -25,22 +25,38 @@ class TestLldbGdbServerUtils(unittest2.TestCase): self.assertIsNotNone(context) def test_entry_regex_matches(self): - entry = GdbRemoteEntry(is_send_to_remote=False, regex=re.compile(r"^\$QC([0-9a-fA-F]+)#"), capture={ 1:"thread_id" }) + entry = GdbRemoteEntry( + is_send_to_remote=False, + regex=re.compile(r"^\$QC([0-9a-fA-F]+)#"), + capture={ + 1: "thread_id"}) context = entry.assert_match(self, "$QC980#00") def test_entry_regex_saves_match(self): - entry = GdbRemoteEntry(is_send_to_remote=False, regex=re.compile(r"^\$QC([0-9a-fA-F]+)#"), capture={ 1:"thread_id" }) + entry = GdbRemoteEntry( + is_send_to_remote=False, + regex=re.compile(r"^\$QC([0-9a-fA-F]+)#"), + capture={ + 1: "thread_id"}) context = entry.assert_match(self, "$QC980#00") self.assertEqual(context["thread_id"], "980") def test_entry_regex_expect_captures_success(self): - context = { "thread_id":"980" } - entry = GdbRemoteEntry(is_send_to_remote=False, regex=re.compile(r"^\$T([0-9a-fA-F]{2})thread:([0-9a-fA-F]+)"), expect_captures={ 2:"thread_id" }) + context = {"thread_id": "980"} + entry = GdbRemoteEntry( + is_send_to_remote=False, + regex=re.compile(r"^\$T([0-9a-fA-F]{2})thread:([0-9a-fA-F]+)"), + expect_captures={ + 2: "thread_id"}) entry.assert_match(self, "$T11thread:980;", context=context) def test_entry_regex_expect_captures_raises_on_fail(self): - context = { "thread_id":"980" } - entry = GdbRemoteEntry(is_send_to_remote=False, regex=re.compile(r"^\$T([0-9a-fA-F]{2})thread:([0-9a-fA-F]+)"), expect_captures={ 2:"thread_id" }) + context = {"thread_id": "980"} + entry = GdbRemoteEntry( + is_send_to_remote=False, + regex=re.compile(r"^\$T([0-9a-fA-F]{2})thread:([0-9a-fA-F]+)"), + expect_captures={ + 2: "thread_id"}) try: entry.assert_match(self, "$T11thread:970;", context=context) self.fail() |