summaryrefslogtreecommitdiffstats
path: root/lldb/packages/Python/lldbsuite/test/commands/breakpoint
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test/commands/breakpoint')
-rw-r--r--lldb/packages/Python/lldbsuite/test/commands/breakpoint/basic/Makefile5
-rw-r--r--lldb/packages/Python/lldbsuite/test/commands/breakpoint/basic/TestBreakpointCommand.py285
-rw-r--r--lldb/packages/Python/lldbsuite/test/commands/breakpoint/basic/TestBreakpointCommandsFromPython.py99
-rw-r--r--lldb/packages/Python/lldbsuite/test/commands/breakpoint/basic/TestRegexpBreakCommand.py71
-rw-r--r--lldb/packages/Python/lldbsuite/test/commands/breakpoint/basic/a.c9
-rw-r--r--lldb/packages/Python/lldbsuite/test/commands/breakpoint/basic/b.c9
-rw-r--r--lldb/packages/Python/lldbsuite/test/commands/breakpoint/basic/bktptcmd.py5
-rw-r--r--lldb/packages/Python/lldbsuite/test/commands/breakpoint/basic/main.c16
-rw-r--r--lldb/packages/Python/lldbsuite/test/commands/breakpoint/basic/side_effect.py5
9 files changed, 504 insertions, 0 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/commands/breakpoint/basic/Makefile b/lldb/packages/Python/lldbsuite/test/commands/breakpoint/basic/Makefile
new file mode 100644
index 00000000000..a6376f9b165
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/commands/breakpoint/basic/Makefile
@@ -0,0 +1,5 @@
+LEVEL = ../../../make
+
+C_SOURCES := main.c a.c b.c
+
+include $(LEVEL)/Makefile.rules
diff --git a/lldb/packages/Python/lldbsuite/test/commands/breakpoint/basic/TestBreakpointCommand.py b/lldb/packages/Python/lldbsuite/test/commands/breakpoint/basic/TestBreakpointCommand.py
new file mode 100644
index 00000000000..b75a6db6e80
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/commands/breakpoint/basic/TestBreakpointCommand.py
@@ -0,0 +1,285 @@
+"""
+Test lldb breakpoint command add/list/delete.
+"""
+
+from __future__ import print_function
+
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+import side_effect
+
+
+class BreakpointCommandTestCase(TestBase):
+
+ NO_DEBUG_INFO_TESTCASE = True
+ mydir = TestBase.compute_mydir(__file__)
+
+ @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24528")
+ def test_breakpoint_command_sequence(self):
+ """Test a sequence of breakpoint command add, list, and delete."""
+ self.build()
+ self.breakpoint_command_sequence()
+
+ def test_script_parameters(self):
+ """Test a sequence of breakpoint command add, list, and delete."""
+ self.build()
+ self.breakpoint_command_script_parameters()
+
+ def test_commands_on_creation(self):
+ self.build()
+ self.breakpoint_commands_on_creation()
+
+ def setUp(self):
+ # Call super's setUp().
+ TestBase.setUp(self)
+ # Find the line number to break inside main().
+ 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"))
+
+ def test_delete_all_breakpoints(self):
+ """Test that deleting all breakpoints works."""
+ self.build()
+ exe = self.getBuildArtifact("a.out")
+ self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
+
+ lldbutil.run_break_set_by_symbol(self, "main")
+ lldbutil.run_break_set_by_file_and_line(
+ self, "main.c", self.line, num_expected_locations=1, loc_exact=True)
+
+ self.runCmd("run", RUN_SUCCEEDED)
+
+ self.runCmd("breakpoint delete")
+ self.runCmd("process continue")
+ self.expect("process status", PROCESS_STOPPED,
+ patterns=['Process .* exited with status = 0'])
+
+
+ def breakpoint_command_sequence(self):
+ """Test a sequence of breakpoint command add, list, and delete."""
+ exe = self.getBuildArtifact("a.out")
+ self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
+
+ # 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)
+ # Make sure relative path source breakpoints work as expected. We test
+ # with partial paths with and without "./" prefixes.
+ 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, "breakpoint_command/main.c", self.line,
+ num_expected_locations=1, loc_exact=True)
+ lldbutil.run_break_set_by_file_and_line(
+ self, "./breakpoint_command/main.c", self.line,
+ num_expected_locations=1, loc_exact=True)
+ lldbutil.run_break_set_by_file_and_line(
+ self, "breakpoint/breakpoint_command/main.c", self.line,
+ num_expected_locations=1, loc_exact=True)
+ lldbutil.run_break_set_by_file_and_line(
+ self, "./breakpoint/breakpoint_command/main.c", self.line,
+ num_expected_locations=1, loc_exact=True)
+ # Test relative breakpoints with incorrect paths and make sure we get
+ # no breakpoint locations
+ lldbutil.run_break_set_by_file_and_line(
+ self, "invalid/main.c", self.line,
+ num_expected_locations=0, loc_exact=True)
+ lldbutil.run_break_set_by_file_and_line(
+ self, "./invalid/main.c", self.line,
+ num_expected_locations=0, 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 'import side_effect; side_effect.one_liner = \"one liner was here\"' 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:?[0-9]*, .+unresolved, hit count = 0" %
+ self.line,
+ "2.1: .+at main.c:%d:?[0-9]*, .+unresolved, hit count = 0" %
+ self.line])
+
+ self.expect("breakpoint command list 1", "Breakpoint 1 command ok",
+ substrs=["Breakpoint commands:",
+ "frame variable --show-types --scope"])
+ self.expect("breakpoint command list 2", "Breakpoint 2 command ok",
+ substrs=["Breakpoint commands (Python):",
+ "import side_effect",
+ "side_effect.one_liner"])
+ self.expect("breakpoint command list 3", "Breakpoint 3 command ok",
+ 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"])
+
+ self.runCmd("breakpoint delete 4")
+
+ self.runCmd("command script import --allow-reload ./bktptcmd.py")
+
+ # Next lets try some other breakpoint kinds. First break with a regular expression
+ # 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)
+
+ # 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)
+
+ # Reset our canary variables and run the program.
+ side_effect.one_liner = None
+ side_effect.bktptcmd = None
+ self.runCmd("run", RUN_SUCCEEDED)
+
+ # Check the value of canary variables.
+ self.assertEquals("one liner was here", side_effect.one_liner)
+ self.assertEquals("function was here", side_effect.bktptcmd)
+
+ # Finish the program.
+ self.runCmd("process continue")
+
+ # Remove the breakpoint command associated with breakpoint 1.
+ self.runCmd("breakpoint command delete 1")
+
+ # 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.")
+
+ # 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"])
+
+ # 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])
+
+ # Run the program again, with breakpoint 1 remaining.
+ self.runCmd("run", RUN_SUCCEEDED)
+
+ # We should be stopped again due to breakpoint 1.
+
+ # The stop reason of the thread should be breakpoint.
+ self.expect("thread list", STOPPED_DUE_TO_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'])
+
+ def breakpoint_command_script_parameters(self):
+ """Test that the frame and breakpoint location are being properly passed to the script breakpoint command function."""
+ exe = self.getBuildArtifact("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)
+
+ # Now add callbacks for the breakpoints just created.
+ self.runCmd("breakpoint command add -s python -o 'import side_effect; side_effect.frame = str(frame); side_effect.bp_loc = str(bp_loc)' 1")
+
+ # Reset canary variables and run.
+ side_effect.frame = None
+ side_effect.bp_loc = None
+ self.runCmd("run", RUN_SUCCEEDED)
+
+ self.expect(side_effect.frame, exe=False, startstr="frame #0:")
+ self.expect(side_effect.bp_loc, exe=False,
+ patterns=["1.* where = .*main .* resolved, hit count = 1"])
+
+ def breakpoint_commands_on_creation(self):
+ """Test that setting breakpoint commands when creating the breakpoint works"""
+ exe = self.getBuildArtifact("a.out")
+ target = self.dbg.CreateTarget(exe)
+ self.assertTrue(target.IsValid(), "Created an invalid target.")
+
+ # Add a breakpoint.
+ lldbutil.run_break_set_by_file_and_line(
+ self, "main.c", self.line, num_expected_locations=1, loc_exact=True,
+ extra_options='-C bt -C "thread list" -C continue')
+
+ bkpt = target.FindBreakpointByID(1)
+ self.assertTrue(bkpt.IsValid(), "Couldn't find breakpoint 1")
+ com_list = lldb.SBStringList()
+ bkpt.GetCommandLineCommands(com_list)
+ self.assertEqual(com_list.GetSize(), 3, "Got the wrong number of commands")
+ self.assertEqual(com_list.GetStringAtIndex(0), "bt", "First bt")
+ self.assertEqual(com_list.GetStringAtIndex(1), "thread list", "Next thread list")
+ self.assertEqual(com_list.GetStringAtIndex(2), "continue", "Last continue")
diff --git a/lldb/packages/Python/lldbsuite/test/commands/breakpoint/basic/TestBreakpointCommandsFromPython.py b/lldb/packages/Python/lldbsuite/test/commands/breakpoint/basic/TestBreakpointCommandsFromPython.py
new file mode 100644
index 00000000000..962728a324e
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/commands/breakpoint/basic/TestBreakpointCommandsFromPython.py
@@ -0,0 +1,99 @@
+"""
+Test that you can set breakpoint commands successfully with the Python API's:
+"""
+
+from __future__ import print_function
+
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+import side_effect
+
+
+class PythonBreakpointCommandSettingTestCase(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+ NO_DEBUG_INFO_TESTCASE = True
+
+ @add_test_categories(['pyapi'])
+ def test_step_out_python(self):
+ """Test stepping out using avoid-no-debug with dsyms."""
+ self.build()
+ self.do_set_python_command_from_python()
+
+ 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):
+ exe = self.getBuildArtifact("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)
+ self.assertTrue(body_bkpt, VALID_BREAKPOINT)
+
+ 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())
+ self.assertTrue(no_files_bkpt, VALID_BREAKPOINT)
+ num_locations = no_files_bkpt.GetNumLocations()
+ 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()
+ print("Got comp unit: ", comp_unit.GetFilename())
+ if comp_unit.GetFilename() == "a.c":
+ got_one_in_A = True
+ elif comp_unit.GetFilename() == "b.c":
+ got_one_in_B = True
+
+ self.assertTrue(got_one_in_A, "Failed to match the pattern in A")
+ self.assertTrue(got_one_in_B, "Failed to match the pattern in B")
+ self.target.BreakpointDelete(no_files_bkpt.GetID())
+
+ error = lldb.SBError()
+ error = body_bkpt.SetScriptCallbackBody(
+ "import side_effect; side_effect.callback = 'callback was here'")
+ self.assertTrue(
+ error.Success(),
+ "Failed to set the script callback body: %s." %
+ (error.GetCString()))
+
+ self.dbg.HandleCommand(
+ "command script import --allow-reload ./bktptcmd.py")
+ func_bkpt.SetScriptCallbackFunction("bktptcmd.function")
+
+ # Clear out canary variables
+ side_effect.bktptcmd = None
+ side_effect.callback = None
+
+ # Now launch the process, and do not stop at entry point.
+ 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)
+ self.assertTrue(len(threads) == 1, "Stopped at inner breakpoint.")
+ self.thread = threads[0]
+
+ self.assertEquals("callback was here", side_effect.callback)
+ self.assertEquals("function was here", side_effect.bktptcmd)
diff --git a/lldb/packages/Python/lldbsuite/test/commands/breakpoint/basic/TestRegexpBreakCommand.py b/lldb/packages/Python/lldbsuite/test/commands/breakpoint/basic/TestRegexpBreakCommand.py
new file mode 100644
index 00000000000..8774d3763a6
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/commands/breakpoint/basic/TestRegexpBreakCommand.py
@@ -0,0 +1,71 @@
+"""
+Test _regexp-break command which uses regular expression matching to dispatch to other built in breakpoint commands.
+"""
+
+from __future__ import print_function
+
+
+import os
+import lldb
+from lldbsuite.test.lldbtest import *
+import lldbsuite.test.lldbutil as lldbutil
+
+
+class RegexpBreakCommandTestCase(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ def test(self):
+ """Test _regexp-break command."""
+ self.build()
+ self.regexp_break_command()
+
+ def setUp(self):
+ # Call super's setUp().
+ 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.')
+
+ def regexp_break_command(self):
+ """Test the super consie "b" command, which is analias for _regexp-break."""
+ exe = self.getBuildArtifact("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 %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(self.getSourceDir(), 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)
+
+ 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'])
diff --git a/lldb/packages/Python/lldbsuite/test/commands/breakpoint/basic/a.c b/lldb/packages/Python/lldbsuite/test/commands/breakpoint/basic/a.c
new file mode 100644
index 00000000000..870e4a6ab16
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/commands/breakpoint/basic/a.c
@@ -0,0 +1,9 @@
+#include <stdio.h>
+
+int
+a_MyFunction ()
+{
+ // Set a breakpoint here.
+ printf ("a is about to return 10.\n");
+ return 10;
+}
diff --git a/lldb/packages/Python/lldbsuite/test/commands/breakpoint/basic/b.c b/lldb/packages/Python/lldbsuite/test/commands/breakpoint/basic/b.c
new file mode 100644
index 00000000000..02b78e7bd85
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/commands/breakpoint/basic/b.c
@@ -0,0 +1,9 @@
+#include <stdio.h>
+
+int
+b_MyFunction ()
+{
+ // Set a breakpoint here.
+ printf ("b is about to return 20.\n");
+ return 20;
+}
diff --git a/lldb/packages/Python/lldbsuite/test/commands/breakpoint/basic/bktptcmd.py b/lldb/packages/Python/lldbsuite/test/commands/breakpoint/basic/bktptcmd.py
new file mode 100644
index 00000000000..ac0f753ccd8
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/commands/breakpoint/basic/bktptcmd.py
@@ -0,0 +1,5 @@
+from __future__ import print_function
+import side_effect
+
+def function(frame, bp_loc, dict):
+ side_effect.bktptcmd = "function was here"
diff --git a/lldb/packages/Python/lldbsuite/test/commands/breakpoint/basic/main.c b/lldb/packages/Python/lldbsuite/test/commands/breakpoint/basic/main.c
new file mode 100644
index 00000000000..8bebb9455a6
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/commands/breakpoint/basic/main.c
@@ -0,0 +1,16 @@
+//===-- main.c --------------------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+int main (int argc, char const *argv[])
+{
+ // Add a body to the function, so we can set more than one
+ // breakpoint in it.
+ static volatile int var = 0;
+ var++;
+ return 0; // Set break point at this line.
+}
diff --git a/lldb/packages/Python/lldbsuite/test/commands/breakpoint/basic/side_effect.py b/lldb/packages/Python/lldbsuite/test/commands/breakpoint/basic/side_effect.py
new file mode 100644
index 00000000000..ef4ab2b159c
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/commands/breakpoint/basic/side_effect.py
@@ -0,0 +1,5 @@
+"""
+A dummy module for testing the execution of various breakpoint commands. A
+command will modify a global variable in this module and test will check its
+value.
+"""
OpenPOWER on IntegriCloud