diff options
Diffstat (limited to 'packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command')
4 files changed, 208 insertions, 109 deletions
diff --git a/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py b/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py index 78d14b7d7705..e67a6332d9d2 100644 --- a/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py +++ b/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py @@ -5,13 +5,14 @@ Test lldb breakpoint command add/list/delete. from __future__ import print_function - -import os, time +import os +import time import lldb from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * from lldbsuite.test import lldbutil + class BreakpointCommandTestCase(TestBase): mydir = TestBase.compute_mydir(__file__) @@ -27,7 +28,7 @@ class BreakpointCommandTestCase(TestBase): """Test a sequence of breakpoint command add, list, and delete.""" self.build() self.breakpoint_command_sequence() - self.breakpoint_command_script_parameters () + self.breakpoint_command_script_parameters() def setUp(self): # Call super's setUp(). @@ -36,7 +37,8 @@ class BreakpointCommandTestCase(TestBase): self.line = line_number('main.c', '// Set break point at this line.') # disable "There is a running process, kill it and restart?" prompt self.runCmd("settings set auto-confirm true") - self.addTearDownHook(lambda: self.runCmd("settings clear auto-confirm")) + self.addTearDownHook( + lambda: self.runCmd("settings clear auto-confirm")) def breakpoint_command_sequence(self): """Test a sequence of breakpoint command add, list, and delete.""" @@ -45,45 +47,64 @@ class BreakpointCommandTestCase(TestBase): # Add three breakpoints on the same line. The first time we don't specify the file, # since the default file is the one containing main: - lldbutil.run_break_set_by_file_and_line (self, None, self.line, num_expected_locations=1, loc_exact=True) - lldbutil.run_break_set_by_file_and_line (self, "main.c", self.line, num_expected_locations=1, loc_exact=True) - lldbutil.run_break_set_by_file_and_line (self, "main.c", self.line, num_expected_locations=1, loc_exact=True) - # Breakpoint 4 - set at the same location as breakpoint 1 to test setting breakpoint commands on two breakpoints at a time - lldbutil.run_break_set_by_file_and_line (self, None, self.line, num_expected_locations=1, loc_exact=True) + lldbutil.run_break_set_by_file_and_line( + self, None, self.line, num_expected_locations=1, loc_exact=True) + lldbutil.run_break_set_by_file_and_line( + self, "main.c", self.line, num_expected_locations=1, loc_exact=True) + lldbutil.run_break_set_by_file_and_line( + self, "main.c", self.line, num_expected_locations=1, loc_exact=True) + # Breakpoint 4 - set at the same location as breakpoint 1 to test + # setting breakpoint commands on two breakpoints at a time + lldbutil.run_break_set_by_file_and_line( + self, None, self.line, num_expected_locations=1, loc_exact=True) # Now add callbacks for the breakpoints just created. - self.runCmd("breakpoint command add -s command -o 'frame variable --show-types --scope' 1 4") - self.runCmd("breakpoint command add -s python -o 'here = open(\"output.txt\", \"w\"); here.write(\"lldb\\n\"); here.close()' 2") - self.runCmd("breakpoint command add --python-function bktptcmd.function 3") + self.runCmd( + "breakpoint command add -s command -o 'frame variable --show-types --scope' 1 4") + self.runCmd( + "breakpoint command add -s python -o 'here = open(\"output.txt\", \"w\"); here.write(\"lldb\\n\"); here.close()' 2") + self.runCmd( + "breakpoint command add --python-function bktptcmd.function 3") # Check that the breakpoint commands are correctly set. # The breakpoint list now only contains breakpoint 1. - self.expect("breakpoint list", "Breakpoints 1 & 2 created", - substrs = ["2: file = 'main.c', line = %d, exact_match = 0, locations = 1" % self.line], - patterns = ["1: file = '.*main.c', line = %d, exact_match = 0, locations = 1" % self.line] ) - - self.expect("breakpoint list -f", "Breakpoints 1 & 2 created", - substrs = ["2: file = 'main.c', line = %d, exact_match = 0, locations = 1" % self.line], - patterns = ["1: file = '.*main.c', line = %d, exact_match = 0, locations = 1" % self.line, - "1.1: .+at main.c:%d, .+unresolved, hit count = 0" % self.line, - "2.1: .+at main.c:%d, .+unresolved, hit count = 0" % self.line]) + self.expect( + "breakpoint list", "Breakpoints 1 & 2 created", substrs=[ + "2: file = 'main.c', line = %d, exact_match = 0, locations = 1" % + self.line], patterns=[ + "1: file = '.*main.c', line = %d, exact_match = 0, locations = 1" % + self.line]) + + self.expect( + "breakpoint list -f", + "Breakpoints 1 & 2 created", + substrs=[ + "2: file = 'main.c', line = %d, exact_match = 0, locations = 1" % + self.line], + patterns=[ + "1: file = '.*main.c', line = %d, exact_match = 0, locations = 1" % + self.line, + "1.1: .+at main.c:%d, .+unresolved, hit count = 0" % + self.line, + "2.1: .+at main.c:%d, .+unresolved, hit count = 0" % + self.line]) self.expect("breakpoint command list 1", "Breakpoint 1 command ok", - substrs = ["Breakpoint commands:", - "frame variable --show-types --scope"]) + substrs=["Breakpoint commands:", + "frame variable --show-types --scope"]) self.expect("breakpoint command list 2", "Breakpoint 2 command ok", - substrs = ["Breakpoint commands:", - "here = open", - "here.write", - "here.close()"]) + substrs=["Breakpoint commands (Python):", + "here = open", + "here.write", + "here.close()"]) self.expect("breakpoint command list 3", "Breakpoint 3 command ok", - substrs = ["Breakpoint commands:", - "bktptcmd.function(frame, bp_loc, internal_dict)"]) + substrs=["Breakpoint commands (Python):", + "bktptcmd.function(frame, bp_loc, internal_dict)"]) self.expect("breakpoint command list 4", "Breakpoint 4 command ok", - substrs = ["Breakpoint commands:", - "frame variable --show-types --scope"]) + substrs=["Breakpoint commands:", + "frame variable --show-types --scope"]) self.runCmd("breakpoint delete 4") @@ -93,43 +114,68 @@ class BreakpointCommandTestCase(TestBase): # and then specify only one file. The first time we should get two locations, # the second time only one: - lldbutil.run_break_set_by_regexp (self, r"._MyFunction", num_expected_locations=2) - - lldbutil.run_break_set_by_regexp (self, r"._MyFunction", extra_options="-f a.c", num_expected_locations=1) - - lldbutil.run_break_set_by_regexp (self, r"._MyFunction", extra_options="-f a.c -f b.c", num_expected_locations=2) + lldbutil.run_break_set_by_regexp( + self, r"._MyFunction", num_expected_locations=2) + + lldbutil.run_break_set_by_regexp( + self, + r"._MyFunction", + extra_options="-f a.c", + num_expected_locations=1) + + lldbutil.run_break_set_by_regexp( + self, + r"._MyFunction", + extra_options="-f a.c -f b.c", + num_expected_locations=2) # Now try a source regex breakpoint: - lldbutil.run_break_set_by_source_regexp (self, r"is about to return [12]0", extra_options="-f a.c -f b.c", num_expected_locations=2) - - lldbutil.run_break_set_by_source_regexp (self, r"is about to return [12]0", extra_options="-f a.c", num_expected_locations=1) - + lldbutil.run_break_set_by_source_regexp( + self, + r"is about to return [12]0", + extra_options="-f a.c -f b.c", + num_expected_locations=2) + + lldbutil.run_break_set_by_source_regexp( + self, + r"is about to return [12]0", + extra_options="-f a.c", + num_expected_locations=1) + # Run the program. Remove 'output.txt' if it exists. self.RemoveTempFile("output.txt") self.RemoveTempFile("output2.txt") self.runCmd("run", RUN_SUCCEEDED) - # Check that the file 'output.txt' exists and contains the string "lldb". + # Check that the file 'output.txt' exists and contains the string + # "lldb". # The 'output.txt' file should now exist. - self.assertTrue(os.path.isfile("output.txt"), - "'output.txt' exists due to breakpoint command for breakpoint 2.") - self.assertTrue(os.path.isfile("output2.txt"), - "'output2.txt' exists due to breakpoint command for breakpoint 3.") + self.assertTrue( + os.path.isfile("output.txt"), + "'output.txt' exists due to breakpoint command for breakpoint 2.") + self.assertTrue( + os.path.isfile("output2.txt"), + "'output2.txt' exists due to breakpoint command for breakpoint 3.") # Read the output file produced by running the program. with open('output.txt', 'r') as f: output = f.read() - self.expect(output, "File 'output.txt' and the content matches", exe=False, - startstr = "lldb") + self.expect( + output, + "File 'output.txt' and the content matches", + exe=False, + startstr="lldb") with open('output2.txt', 'r') as f: output = f.read() - self.expect(output, "File 'output2.txt' and the content matches", exe=False, - startstr = "lldb") - + self.expect( + output, + "File 'output2.txt' and the content matches", + exe=False, + startstr="lldb") # Finish the program. self.runCmd("process continue") @@ -140,21 +186,31 @@ class BreakpointCommandTestCase(TestBase): # Remove breakpoint 2. self.runCmd("breakpoint delete 2") - self.expect("breakpoint command list 1", - startstr = "Breakpoint 1 does not have an associated command.") - self.expect("breakpoint command list 2", error=True, - startstr = "error: '2' is not a currently valid breakpoint ID.") + self.expect( + "breakpoint command list 1", + startstr="Breakpoint 1 does not have an associated command.") + self.expect( + "breakpoint command list 2", + error=True, + startstr="error: '2' is not a currently valid breakpoint ID.") # The breakpoint list now only contains breakpoint 1. - self.expect("breakpoint list -f", "Breakpoint 1 exists", - patterns = ["1: file = '.*main.c', line = %d, exact_match = 0, locations = 1, resolved = 1" % - self.line, - "hit count = 1"]) + self.expect( + "breakpoint list -f", + "Breakpoint 1 exists", + patterns=[ + "1: file = '.*main.c', line = %d, exact_match = 0, locations = 1, resolved = 1" % + self.line, + "hit count = 1"]) # Not breakpoint 2. - self.expect("breakpoint list -f", "No more breakpoint 2", matching=False, - substrs = ["2: file = 'main.c', line = %d, exact_match = 0, locations = 1, resolved = 1" % - self.line]) + self.expect( + "breakpoint list -f", + "No more breakpoint 2", + matching=False, + substrs=[ + "2: file = 'main.c', line = %d, exact_match = 0, locations = 1, resolved = 1" % + self.line]) # Run the program again, with breakpoint 1 remaining. self.runCmd("run", RUN_SUCCEEDED) @@ -163,20 +219,21 @@ class BreakpointCommandTestCase(TestBase): # The stop reason of the thread should be breakpoint. self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, - substrs = ['stopped', - 'stop reason = breakpoint']) + substrs=['stopped', + 'stop reason = breakpoint']) # The breakpoint should have a hit count of 2. self.expect("breakpoint list -f", BREAKPOINT_HIT_TWICE, - substrs = ['resolved, hit count = 2']) + substrs=['resolved, hit count = 2']) - def breakpoint_command_script_parameters (self): + def breakpoint_command_script_parameters(self): """Test that the frame and breakpoint location are being properly passed to the script breakpoint command function.""" exe = os.path.join(os.getcwd(), "a.out") self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) # Add a breakpoint. - lldbutil.run_break_set_by_file_and_line (self, "main.c", self.line, num_expected_locations=1, loc_exact=True) + lldbutil.run_break_set_by_file_and_line( + self, "main.c", self.line, num_expected_locations=1, loc_exact=True) # Now add callbacks for the breakpoints just created. self.runCmd("breakpoint command add -s python -o 'here = open(\"output-2.txt\", \"w\"); here.write(str(frame) + \"\\n\"); here.write(str(bp_loc) + \"\\n\"); here.close()' 1") @@ -184,24 +241,30 @@ class BreakpointCommandTestCase(TestBase): # Remove 'output-2.txt' if it already exists. if (os.path.exists('output-2.txt')): - os.remove ('output-2.txt') + os.remove('output-2.txt') - # Run program, hit breakpoint, and hopefully write out new version of 'output-2.txt' - self.runCmd ("run", RUN_SUCCEEDED) + # Run program, hit breakpoint, and hopefully write out new version of + # 'output-2.txt' + self.runCmd("run", RUN_SUCCEEDED) - # Check that the file 'output.txt' exists and contains the string "lldb". + # Check that the file 'output.txt' exists and contains the string + # "lldb". # The 'output-2.txt' file should now exist. - self.assertTrue(os.path.isfile("output-2.txt"), - "'output-2.txt' exists due to breakpoint command for breakpoint 1.") + self.assertTrue( + os.path.isfile("output-2.txt"), + "'output-2.txt' exists due to breakpoint command for breakpoint 1.") # Read the output file produced by running the program. with open('output-2.txt', 'r') as f: output = f.read() - self.expect (output, "File 'output-2.txt' and the content matches", exe=False, - startstr = "frame #0:", - patterns = ["1.* where = .*main .* resolved, hit count = 1" ]) + self.expect( + output, + "File 'output-2.txt' and the content matches", + exe=False, + startstr="frame #0:", + patterns=["1.* where = .*main .* resolved, hit count = 1"]) # Now remove 'output-2.txt' - os.remove ('output-2.txt') + os.remove('output-2.txt') diff --git a/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/TestBreakpointCommandsFromPython.py b/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/TestBreakpointCommandsFromPython.py index 4f8ab9e115de..01af8369aaf1 100644 --- a/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/TestBreakpointCommandsFromPython.py +++ b/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/TestBreakpointCommandsFromPython.py @@ -5,7 +5,6 @@ Test that you can set breakpoint commands successfully with the Python API's: from __future__ import print_function - import os import re import sys @@ -14,6 +13,7 @@ from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * from lldbsuite.test import lldbutil + class PythonBreakpointCommandSettingTestCase(TestBase): mydir = TestBase.compute_mydir(__file__) @@ -23,36 +23,42 @@ class PythonBreakpointCommandSettingTestCase(TestBase): def test_step_out_python(self): """Test stepping out using avoid-no-debug with dsyms.""" self.build() - self.do_set_python_command_from_python () + self.do_set_python_command_from_python() - def setUp (self): + def setUp(self): TestBase.setUp(self) self.main_source = "main.c" self.main_source_spec = lldb.SBFileSpec(self.main_source) - - def do_set_python_command_from_python (self): + def do_set_python_command_from_python(self): exe = os.path.join(os.getcwd(), "a.out") error = lldb.SBError() self.target = self.dbg.CreateTarget(exe) self.assertTrue(self.target, VALID_TARGET) - body_bkpt = self.target.BreakpointCreateBySourceRegex("Set break point at this line.", self.main_source_spec) + body_bkpt = self.target.BreakpointCreateBySourceRegex( + "Set break point at this line.", self.main_source_spec) self.assertTrue(body_bkpt, VALID_BREAKPOINT) - func_bkpt = self.target.BreakpointCreateBySourceRegex("Set break point at this line.", self.main_source_spec) + func_bkpt = self.target.BreakpointCreateBySourceRegex( + "Set break point at this line.", self.main_source_spec) self.assertTrue(func_bkpt, VALID_BREAKPOINT) - # Also test that setting a source regex breakpoint with an empty file spec list sets it on all files: - no_files_bkpt = self.target.BreakpointCreateBySourceRegex("Set a breakpoint here", lldb.SBFileSpecList(), lldb.SBFileSpecList()) + # Also test that setting a source regex breakpoint with an empty file + # spec list sets it on all files: + no_files_bkpt = self.target.BreakpointCreateBySourceRegex( + "Set a breakpoint here", lldb.SBFileSpecList(), lldb.SBFileSpecList()) self.assertTrue(no_files_bkpt, VALID_BREAKPOINT) num_locations = no_files_bkpt.GetNumLocations() - self.assertTrue(num_locations >= 2, "Got at least two breakpoint locations") + self.assertTrue( + num_locations >= 2, + "Got at least two breakpoint locations") got_one_in_A = False got_one_in_B = False for idx in range(0, num_locations): - comp_unit = no_files_bkpt.GetLocationAtIndex(idx).GetAddress().GetSymbolContext(lldb.eSymbolContextCompUnit).GetCompileUnit().GetFileSpec() + comp_unit = no_files_bkpt.GetLocationAtIndex(idx).GetAddress().GetSymbolContext( + lldb.eSymbolContextCompUnit).GetCompileUnit().GetFileSpec() print("Got comp unit: ", comp_unit.GetFilename()) if comp_unit.GetFilename() == "a.c": got_one_in_A = True @@ -69,28 +75,36 @@ class PythonBreakpointCommandSettingTestCase(TestBase): import TestBreakpointCommandsFromPython\n\ TestBreakpointCommandsFromPython.PythonBreakpointCommandSettingTestCase.my_var = 20\n\ print('Hit breakpoint')") - self.assertTrue (error.Success(), "Failed to set the script callback body: %s."%(error.GetCString())) + self.assertTrue( + error.Success(), + "Failed to set the script callback body: %s." % + (error.GetCString())) - self.dbg.HandleCommand("command script import --allow-reload ./bktptcmd.py") + self.dbg.HandleCommand( + "command script import --allow-reload ./bktptcmd.py") func_bkpt.SetScriptCallbackFunction("bktptcmd.function") - # We will use the function that touches a text file, so remove it first: + # We will use the function that touches a text file, so remove it + # first: self.RemoveTempFile("output2.txt") # Now launch the process, and do not stop at entry point. - self.process = self.target.LaunchSimple (None, None, self.get_process_working_directory()) + self.process = self.target.LaunchSimple( + None, None, self.get_process_working_directory()) self.assertTrue(self.process, PROCESS_IS_VALID) # Now finish, and make sure the return value is correct. - threads = lldbutil.get_threads_stopped_at_breakpoint (self.process, body_bkpt) + threads = lldbutil.get_threads_stopped_at_breakpoint( + self.process, body_bkpt) self.assertTrue(len(threads) == 1, "Stopped at inner breakpoint.") self.thread = threads[0] - + self.assertTrue(PythonBreakpointCommandSettingTestCase.my_var == 20) # Check for the function version as well, which produced this file: # Remember to clean up after ourselves... - self.assertTrue(os.path.isfile("output2.txt"), - "'output2.txt' exists due to breakpoint command for breakpoint function.") + self.assertTrue( + os.path.isfile("output2.txt"), + "'output2.txt' exists due to breakpoint command for breakpoint function.") self.RemoveTempFile("output2.txt") diff --git a/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/TestRegexpBreakCommand.py b/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/TestRegexpBreakCommand.py index 1ea71cbde45c..baf237bf0764 100644 --- a/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/TestRegexpBreakCommand.py +++ b/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/TestRegexpBreakCommand.py @@ -5,12 +5,13 @@ Test _regexp-break command which uses regular expression matching to dispatch to from __future__ import print_function - -import os, time +import os +import time import lldb from lldbsuite.test.lldbtest import * import lldbsuite.test.lldbutil as lldbutil + class RegexpBreakCommandTestCase(TestBase): mydir = TestBase.compute_mydir(__file__) @@ -25,27 +26,47 @@ class RegexpBreakCommandTestCase(TestBase): TestBase.setUp(self) # Find the line number to break inside main(). self.source = 'main.c' - self.line = line_number(self.source, '// Set break point at this line.') + self.line = line_number( + self.source, '// Set break point at this line.') def regexp_break_command(self): """Test the super consie "b" command, which is analias for _regexp-break.""" exe = os.path.join(os.getcwd(), "a.out") self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) - break_results = lldbutil.run_break_set_command (self, "b %d" % self.line) - lldbutil.check_breakpoint_result (self, break_results, file_name='main.c', line_number=self.line, num_locations=1) + break_results = lldbutil.run_break_set_command( + self, "b %d" % + self.line) + lldbutil.check_breakpoint_result( + self, + break_results, + file_name='main.c', + line_number=self.line, + num_locations=1) - break_results = lldbutil.run_break_set_command (self, "b %s:%d" % (self.source, self.line)) - lldbutil.check_breakpoint_result (self, break_results, file_name='main.c', line_number=self.line, num_locations=1) + break_results = lldbutil.run_break_set_command( + self, "b %s:%d" % (self.source, self.line)) + lldbutil.check_breakpoint_result( + self, + break_results, + file_name='main.c', + line_number=self.line, + num_locations=1) # Check breakpoint with full file path. full_path = os.path.join(os.getcwd(), self.source) - break_results = lldbutil.run_break_set_command (self, "b %s:%d" % (full_path, self.line)) - lldbutil.check_breakpoint_result (self, break_results, file_name='main.c', line_number=self.line, num_locations=1) + break_results = lldbutil.run_break_set_command( + self, "b %s:%d" % (full_path, self.line)) + lldbutil.check_breakpoint_result( + self, + break_results, + file_name='main.c', + line_number=self.line, + num_locations=1) self.runCmd("run", RUN_SUCCEEDED) # The stop reason of the thread should be breakpoint. self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, - substrs = ['stopped', - 'stop reason = breakpoint']) + substrs=['stopped', + 'stop reason = breakpoint']) diff --git a/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/bktptcmd.py b/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/bktptcmd.py index 4bbb0327eacd..cf1fc2cf02c9 100644 --- a/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/bktptcmd.py +++ b/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/bktptcmd.py @@ -1,6 +1,7 @@ from __future__ import print_function + def function(frame, bp_loc, dict): - there = open("output2.txt", "w"); - print("lldb", file=there) - there.close() + there = open("output2.txt", "w") + print("lldb", file=there) + there.close() |