summaryrefslogtreecommitdiffstats
path: root/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command
diff options
context:
space:
mode:
Diffstat (limited to 'packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command')
-rw-r--r--packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/Makefile5
-rw-r--r--packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py206
-rw-r--r--packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/TestBreakpointCommandsFromPython.py95
-rw-r--r--packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/TestRegexpBreakCommand.py51
-rw-r--r--packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/a.c9
-rw-r--r--packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/b.c9
-rw-r--r--packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/bktptcmd.py6
-rw-r--r--packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/main.c13
8 files changed, 394 insertions, 0 deletions
diff --git a/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/Makefile b/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/Makefile
new file mode 100644
index 0000000..a6376f9
--- /dev/null
+++ b/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/Makefile
@@ -0,0 +1,5 @@
+LEVEL = ../../../make
+
+C_SOURCES := main.c a.c b.c
+
+include $(LEVEL)/Makefile.rules
diff --git a/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py b/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py
new file mode 100644
index 0000000..8cf7539
--- /dev/null
+++ b/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py
@@ -0,0 +1,206 @@
+"""
+Test lldb breakpoint command add/list/delete.
+"""
+
+from __future__ import print_function
+
+
+
+import os, time
+import lldb
+from lldbsuite.test.lldbtest import *
+import lldbsuite.test.lldbutil as lldbutil
+
+class BreakpointCommandTestCase(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ @classmethod
+ def classCleanup(cls):
+ """Cleanup the test byproduct of breakpoint_command_sequence(self)."""
+ cls.RemoveTempFile("output.txt")
+ cls.RemoveTempFile("output2.txt")
+
+ @expectedFailureWindows("llvm.org/pr24528")
+ def test(self):
+ """Test a sequence of breakpoint command add, list, and delete."""
+ self.build()
+ self.breakpoint_command_sequence()
+ self.breakpoint_command_script_parameters ()
+
+ 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 breakpoint_command_sequence(self):
+ """Test a sequence of breakpoint command add, list, and delete."""
+ exe = os.path.join(os.getcwd(), "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)
+
+ # 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")
+
+ # 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 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:",
+ "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)"])
+
+ 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)
+
+ # 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".
+
+ # 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.")
+
+ # 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")
+
+ with open('output2.txt', 'r') as f:
+ output = f.read()
+
+ self.expect(output, "File 'output2.txt' and the content matches", exe=False,
+ startstr = "lldb")
+
+
+ # 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 = 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)
+
+ # 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")
+
+ # Remove 'output-2.txt' if it already exists.
+
+ if (os.path.exists('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)
+
+ # 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.")
+
+ # 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" ])
+
+ # Now 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
new file mode 100644
index 0000000..7a9cc74
--- /dev/null
+++ b/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/TestBreakpointCommandsFromPython.py
@@ -0,0 +1,95 @@
+"""
+Test that you can set breakpoint commands successfully with the Python API's:
+"""
+
+from __future__ import print_function
+
+
+
+import os
+import re
+import lldb
+import lldbsuite.test.lldbutil as lldbutil
+import sys
+from lldbsuite.test.lldbtest import *
+
+class PythonBreakpointCommandSettingTestCase(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+ my_var = 10
+
+ @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 = 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)
+ 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())
+
+ PythonBreakpointCommandSettingTestCase.my_var = 10
+ error = lldb.SBError()
+ error = body_bkpt.SetScriptCallbackBody("\
+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.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:
+ 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.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.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.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
new file mode 100644
index 0000000..1ea71cb
--- /dev/null
+++ b/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/TestRegexpBreakCommand.py
@@ -0,0 +1,51 @@
+"""
+Test _regexp-break command which uses regular expression matching to dispatch to other built in breakpoint commands.
+"""
+
+from __future__ import print_function
+
+
+
+import os, time
+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 = 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 %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)
+
+ 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/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/a.c b/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/a.c
new file mode 100644
index 0000000..870e4a6
--- /dev/null
+++ b/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/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/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/b.c b/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/b.c
new file mode 100644
index 0000000..02b78e7
--- /dev/null
+++ b/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/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/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/bktptcmd.py b/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/bktptcmd.py
new file mode 100644
index 0000000..4bbb032
--- /dev/null
+++ b/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/bktptcmd.py
@@ -0,0 +1,6 @@
+from __future__ import print_function
+
+def function(frame, bp_loc, dict):
+ there = open("output2.txt", "w");
+ print("lldb", file=there)
+ there.close()
diff --git a/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/main.c b/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/main.c
new file mode 100644
index 0000000..62ec97f
--- /dev/null
+++ b/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/main.c
@@ -0,0 +1,13 @@
+//===-- main.c --------------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+int main (int argc, char const *argv[])
+{
+ return 0; // Set break point at this line.
+}
OpenPOWER on IntegriCloud