summaryrefslogtreecommitdiff
path: root/packages/Python/lldbsuite/test/functionalities/breakpoint
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2017-12-18 20:12:36 +0000
committerDimitry Andric <dim@FreeBSD.org>2017-12-18 20:12:36 +0000
commitef5d0b5e97ec8e6fa395d377b09aa7755e345b4f (patch)
tree27916256fdeeb57d10d2f3d6948be5d71a703215 /packages/Python/lldbsuite/test/functionalities/breakpoint
parent76e0736e7fcfeb179779e49c05604464b1ccd704 (diff)
Notes
Diffstat (limited to 'packages/Python/lldbsuite/test/functionalities/breakpoint')
-rw-r--r--packages/Python/lldbsuite/test/functionalities/breakpoint/auto_continue/Makefile6
-rw-r--r--packages/Python/lldbsuite/test/functionalities/breakpoint/auto_continue/TestBreakpointAutoContinue.py104
-rw-r--r--packages/Python/lldbsuite/test/functionalities/breakpoint/auto_continue/main.c19
-rw-r--r--packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py31
-rw-r--r--packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_hit_count/Makefile5
-rw-r--r--packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_hit_count/TestBreakpointHitCount.py109
-rw-r--r--packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_hit_count/main.cpp27
-rw-r--r--packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_locations/TestBreakpointLocations.py108
-rw-r--r--packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_names/TestBreakpointNames.py264
-rw-r--r--packages/Python/lldbsuite/test/functionalities/breakpoint/global_constructor/Makefile8
-rw-r--r--packages/Python/lldbsuite/test/functionalities/breakpoint/global_constructor/TestBreakpointInGlobalConstructor.py46
-rw-r--r--packages/Python/lldbsuite/test/functionalities/breakpoint/global_constructor/foo.cpp7
-rw-r--r--packages/Python/lldbsuite/test/functionalities/breakpoint/global_constructor/foo.h11
-rw-r--r--packages/Python/lldbsuite/test/functionalities/breakpoint/global_constructor/main.cpp14
14 files changed, 732 insertions, 27 deletions
diff --git a/packages/Python/lldbsuite/test/functionalities/breakpoint/auto_continue/Makefile b/packages/Python/lldbsuite/test/functionalities/breakpoint/auto_continue/Makefile
new file mode 100644
index 0000000000000..6067ee45e9848
--- /dev/null
+++ b/packages/Python/lldbsuite/test/functionalities/breakpoint/auto_continue/Makefile
@@ -0,0 +1,6 @@
+LEVEL = ../../../make
+
+C_SOURCES := main.c
+CFLAGS_EXTRAS += -std=c99
+
+include $(LEVEL)/Makefile.rules
diff --git a/packages/Python/lldbsuite/test/functionalities/breakpoint/auto_continue/TestBreakpointAutoContinue.py b/packages/Python/lldbsuite/test/functionalities/breakpoint/auto_continue/TestBreakpointAutoContinue.py
new file mode 100644
index 0000000000000..9630e39e01429
--- /dev/null
+++ b/packages/Python/lldbsuite/test/functionalities/breakpoint/auto_continue/TestBreakpointAutoContinue.py
@@ -0,0 +1,104 @@
+"""
+Test that the breakpoint auto-continue flag works correctly.
+"""
+
+from __future__ import print_function
+
+
+import os
+import time
+import re
+import lldb
+import lldbsuite.test.lldbutil as lldbutil
+from lldbsuite.test.lldbtest import *
+
+
+class BreakpointAutoContinue(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ NO_DEBUG_INFO_TESTCASE = True
+
+ def test_breakpoint_auto_continue(self):
+ """Make sure the auto continue continues with no other complications"""
+ self.build()
+ self.simple_auto_continue()
+
+ def test_auto_continue_with_command(self):
+ """Add a command, make sure the command gets run"""
+ self.build()
+ self.auto_continue_with_command()
+
+ def test_auto_continue_on_location(self):
+ """Set auto-continue on a location and make sure only that location continues"""
+ self.build()
+ self.auto_continue_location()
+
+ def make_target_and_bkpt(self, additional_options=None, num_expected_loc=1,
+ pattern="Set a breakpoint here"):
+ exe = os.path.join(os.getcwd(), "a.out")
+ self.target = self.dbg.CreateTarget(exe)
+ self.assertTrue(self.target.IsValid(), "Target is not valid")
+
+ extra_options_txt = "--auto-continue 1 "
+ if additional_options:
+ extra_options_txt += additional_options
+ bpno = lldbutil.run_break_set_by_source_regexp(self, pattern,
+ extra_options = extra_options_txt,
+ num_expected_locations = num_expected_loc)
+ return bpno
+
+ def launch_it (self, expected_state):
+ error = lldb.SBError()
+ launch_info = lldb.SBLaunchInfo(None)
+ launch_info.SetWorkingDirectory(self.get_process_working_directory())
+
+ process = self.target.Launch(launch_info, error)
+ self.assertTrue(error.Success(), "Launch failed.")
+
+ state = process.GetState()
+ self.assertEqual(state, expected_state, "Didn't get expected state")
+
+ return process
+
+ def setUp(self):
+ # Call super's setUp().
+ TestBase.setUp(self)
+
+ def simple_auto_continue(self):
+ bpno = self.make_target_and_bkpt()
+ process = self.launch_it(lldb.eStateExited)
+
+ bkpt = self.target.FindBreakpointByID(bpno)
+ self.assertEqual(bkpt.GetHitCount(), 2, "Should have run through the breakpoint twice")
+
+ def auto_continue_with_command(self):
+ bpno = self.make_target_and_bkpt("-N BKPT -C 'break modify --auto-continue 0 BKPT'")
+ process = self.launch_it(lldb.eStateStopped)
+ state = process.GetState()
+ self.assertEqual(state, lldb.eStateStopped, "Process should be stopped")
+ bkpt = self.target.FindBreakpointByID(bpno)
+ threads = lldbutil.get_threads_stopped_at_breakpoint(process, bkpt)
+ self.assertEqual(len(threads), 1, "There was a thread stopped at our breakpoint")
+ self.assertEqual(bkpt.GetHitCount(), 2, "Should have hit the breakpoint twice")
+
+ def auto_continue_location(self):
+ bpno = self.make_target_and_bkpt(pattern="Set a[^ ]* breakpoint here", num_expected_loc=2)
+ bkpt = self.target.FindBreakpointByID(bpno)
+ bkpt.SetAutoContinue(False)
+
+ loc = lldb.SBBreakpointLocation()
+ for i in range(0,2):
+ func_name = bkpt.location[i].GetAddress().function.name
+ if func_name == "main":
+ loc = bkpt.location[i]
+
+ self.assertTrue(loc.IsValid(), "Didn't find a location in main")
+ loc.SetAutoContinue(True)
+
+ process = self.launch_it(lldb.eStateStopped)
+
+ threads = lldbutil.get_threads_stopped_at_breakpoint(process, bkpt)
+ self.assertEqual(len(threads), 1, "Didn't get one thread stopped at our breakpoint")
+ func_name = threads[0].frame[0].function.name
+ self.assertEqual(func_name, "call_me")
diff --git a/packages/Python/lldbsuite/test/functionalities/breakpoint/auto_continue/main.c b/packages/Python/lldbsuite/test/functionalities/breakpoint/auto_continue/main.c
new file mode 100644
index 0000000000000..a37f05e0290a9
--- /dev/null
+++ b/packages/Python/lldbsuite/test/functionalities/breakpoint/auto_continue/main.c
@@ -0,0 +1,19 @@
+#include <stdio.h>
+
+void
+call_me()
+{
+ printf("Set another breakpoint here.\n");
+}
+
+int
+main()
+{
+ int change_me = 0;
+ for (int i = 0; i < 2; i++)
+ {
+ printf ("Set a breakpoint here: %d with: %d.\n", i, change_me);
+ }
+ call_me();
+ return 0;
+}
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 e67a6332d9d20..386eafbb0b60a 100644
--- a/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py
+++ b/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py
@@ -24,12 +24,21 @@ class BreakpointCommandTestCase(TestBase):
cls.RemoveTempFile("output2.txt")
@expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24528")
- def test(self):
+ def test_breakpoint_command_sequence(self):
"""Test a sequence of breakpoint command add, list, and delete."""
self.build()
self.breakpoint_command_sequence()
+
+ @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24528")
+ 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)
@@ -268,3 +277,23 @@ class BreakpointCommandTestCase(TestBase):
# Now remove 'output-2.txt'
os.remove('output-2.txt')
+
+ def breakpoint_commands_on_creation(self):
+ """Test that setting breakpoint commands when creating the breakpoint works"""
+ exe = os.path.join(os.getcwd(), "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/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_hit_count/Makefile b/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_hit_count/Makefile
new file mode 100644
index 0000000000000..314f1cb2f077b
--- /dev/null
+++ b/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_hit_count/Makefile
@@ -0,0 +1,5 @@
+LEVEL = ../../../make
+
+CXX_SOURCES := main.cpp
+
+include $(LEVEL)/Makefile.rules
diff --git a/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_hit_count/TestBreakpointHitCount.py b/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_hit_count/TestBreakpointHitCount.py
new file mode 100644
index 0000000000000..5d7b6f9169ad8
--- /dev/null
+++ b/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_hit_count/TestBreakpointHitCount.py
@@ -0,0 +1,109 @@
+"""
+Test breakpoint hit count features.
+"""
+
+from __future__ import print_function
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class BreakpointHitCountTestCase(TestBase):
+
+ NO_DEBUG_INFO_TESTCASE = True
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ @add_test_categories(['pyapi'])
+ def test_breakpoint_location_hit_count(self):
+ """Use Python APIs to check breakpoint hit count."""
+ self.build()
+ self.do_test_breakpoint_location_hit_count()
+
+ def setUp(self):
+ # Call super's setUp().
+ TestBase.setUp(self)
+ self.a_int_body_line_no = line_number(
+ 'main.cpp', '// Breakpoint Location 1')
+ self.a_float_body_line_no = line_number(
+ 'main.cpp', '// Breakpoint Location 2')
+
+ def do_test_breakpoint_location_hit_count(self):
+ """Use Python APIs to check breakpoint hit count."""
+ exe = os.path.join(os.getcwd(), "a.out")
+
+ target = self.dbg.CreateTarget(exe)
+ self.assertTrue(target, VALID_TARGET)
+
+ # Create a breakpoint in main.cpp by name 'a',
+ # there should be two locations.
+ breakpoint = target.BreakpointCreateByName('a', 'a.out')
+ self.assertTrue(breakpoint and
+ breakpoint.GetNumLocations() == 2,
+ VALID_BREAKPOINT)
+
+ # Verify all breakpoint locations are enabled.
+ location1 = breakpoint.GetLocationAtIndex(0)
+ self.assertTrue(location1 and
+ location1.IsEnabled(),
+ VALID_BREAKPOINT_LOCATION)
+
+ location2 = breakpoint.GetLocationAtIndex(1)
+ self.assertTrue(location2 and
+ location2.IsEnabled(),
+ VALID_BREAKPOINT_LOCATION)
+
+ # Launch the process, and do not stop at entry point.
+ process = target.LaunchSimple(
+ None, None, self.get_process_working_directory())
+ self.assertTrue(process, PROCESS_IS_VALID)
+
+ # Verify 1st breakpoint location is hit.
+ from lldbsuite.test.lldbutil import get_stopped_thread
+ thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint)
+ self.assertTrue(
+ thread.IsValid(),
+ "There should be a thread stopped due to breakpoint")
+
+ frame0 = thread.GetFrameAtIndex(0)
+ location1 = breakpoint.FindLocationByAddress(frame0.GetPC())
+ self.assertTrue(
+ frame0.GetLineEntry().GetLine() == self.a_int_body_line_no,
+ "Stopped in int a(int)")
+ self.assertTrue(location1)
+ self.assertEqual(location1.GetHitCount(), 1)
+ self.assertEqual(breakpoint.GetHitCount(), 1)
+
+ process.Continue()
+
+ # Verify 2nd breakpoint location is hit.
+ thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint)
+ self.assertTrue(
+ thread.IsValid(),
+ "There should be a thread stopped due to breakpoint")
+
+ frame0 = thread.GetFrameAtIndex(0)
+ location2 = breakpoint.FindLocationByAddress(frame0.GetPC())
+ self.assertTrue(
+ frame0.GetLineEntry().GetLine() == self.a_float_body_line_no,
+ "Stopped in float a(float)")
+ self.assertTrue(location2)
+ self.assertEqual(location2.GetHitCount(), 1)
+ self.assertEqual(location1.GetHitCount(), 1)
+ self.assertEqual(breakpoint.GetHitCount(), 2)
+
+ process.Continue()
+
+ # Verify 2nd breakpoint location is hit again.
+ thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint)
+ self.assertTrue(
+ thread.IsValid(),
+ "There should be a thread stopped due to breakpoint")
+
+ self.assertEqual(location2.GetHitCount(), 2)
+ self.assertEqual(location1.GetHitCount(), 1)
+ self.assertEqual(breakpoint.GetHitCount(), 3)
+
+ process.Continue()
diff --git a/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_hit_count/main.cpp b/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_hit_count/main.cpp
new file mode 100644
index 0000000000000..333e9b6405a74
--- /dev/null
+++ b/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_hit_count/main.cpp
@@ -0,0 +1,27 @@
+//===-- main.cpp ------------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+int a(int val)
+{
+ return val; // Breakpoint Location 1
+}
+
+float a(float val)
+{
+ return val; // Breakpoint Location 2
+}
+
+int main (int argc, char const *argv[])
+{
+ int A1 = a(1);
+ float A2 = a(2.0f);
+ float A3 = a(3.0f);
+
+ return 0;
+}
diff --git a/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_locations/TestBreakpointLocations.py b/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_locations/TestBreakpointLocations.py
index fdbd622f767b4..de24d8b002d7c 100644
--- a/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_locations/TestBreakpointLocations.py
+++ b/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_locations/TestBreakpointLocations.py
@@ -18,27 +18,40 @@ class BreakpointLocationsTestCase(TestBase):
mydir = TestBase.compute_mydir(__file__)
@expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24528")
- def test(self):
+ def test_enable(self):
"""Test breakpoint enable/disable for a breakpoint ID with multiple locations."""
self.build()
self.breakpoint_locations_test()
+ def test_shadowed_cond_options(self):
+ """Test that options set on the breakpoint and location behave correctly."""
+ self.build()
+ self.shadowed_bkpt_cond_test()
+
+
+ def test_shadowed_command_options(self):
+ """Test that options set on the breakpoint and location behave correctly."""
+ self.build()
+ self.shadowed_bkpt_command_test()
+
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.')
- def breakpoint_locations_test(self):
- """Test breakpoint enable/disable for a breakpoint ID with multiple locations."""
+ def set_breakpoint (self):
exe = os.path.join(os.getcwd(), "a.out")
- self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
+ target = self.dbg.CreateTarget(exe)
+ self.assertTrue(target, "Target %s is not valid"%(exe))
# This should create a breakpoint with 3 locations.
- lldbutil.run_break_set_by_file_and_line(
- self, "main.c", self.line, num_expected_locations=3)
+
+ bkpt = target.BreakpointCreateByLocation("main.c", self.line)
# The breakpoint list should show 3 locations.
+ self.assertEqual(bkpt.GetNumLocations(), 3, "Wrong number of locations")
+
self.expect(
"breakpoint list -f",
"Breakpoint locations shown correctly",
@@ -49,6 +62,87 @@ class BreakpointLocationsTestCase(TestBase):
"where = a.out`func_inlined .+unresolved, hit count = 0",
"where = a.out`main .+\[inlined\].+unresolved, hit count = 0"])
+ return bkpt
+
+ def shadowed_bkpt_cond_test(self):
+ """Test that options set on the breakpoint and location behave correctly."""
+ # Breakpoint option propagation from bkpt to loc used to be done the first time
+ # a breakpoint location option was specifically set. After that the other options
+ # on that location would stop tracking the breakpoint. That got fixed, and this test
+ # makes sure only the option touched is affected.
+
+ bkpt = self.set_breakpoint()
+ bkpt_cond = "1 == 0"
+ bkpt.SetCondition(bkpt_cond)
+ self.assertEqual(bkpt.GetCondition(), bkpt_cond,"Successfully set condition")
+ self.assertTrue(bkpt.location[0].GetCondition() == bkpt.GetCondition(), "Conditions are the same")
+
+ # Now set a condition on the locations, make sure that this doesn't effect the bkpt:
+ bkpt_loc_1_cond = "1 == 1"
+ bkpt.location[0].SetCondition(bkpt_loc_1_cond)
+ self.assertEqual(bkpt.location[0].GetCondition(), bkpt_loc_1_cond, "Successfully changed location condition")
+ self.assertNotEqual(bkpt.GetCondition(), bkpt_loc_1_cond, "Changed location changed Breakpoint condition")
+ self.assertEqual(bkpt.location[1].GetCondition(), bkpt_cond, "Changed another location's condition")
+
+ # Now make sure that setting one options doesn't fix the value of another:
+ bkpt.SetIgnoreCount(10)
+ self.assertEqual(bkpt.GetIgnoreCount(), 10, "Set the ignore count successfully")
+ self.assertEqual(bkpt.location[0].GetIgnoreCount(), 10, "Location doesn't track top-level bkpt.")
+
+ # Now make sure resetting the condition to "" resets the tracking:
+ bkpt.location[0].SetCondition("")
+ bkpt_new_cond = "1 == 3"
+ bkpt.SetCondition(bkpt_new_cond)
+ self.assertEqual(bkpt.location[0].GetCondition(), bkpt_new_cond, "Didn't go back to tracking condition")
+
+ def shadowed_bkpt_command_test(self):
+ """Test that options set on the breakpoint and location behave correctly."""
+ # Breakpoint option propagation from bkpt to loc used to be done the first time
+ # a breakpoint location option was specifically set. After that the other options
+ # on that location would stop tracking the breakpoint. That got fixed, and this test
+ # makes sure only the option touched is affected.
+
+ bkpt = self.set_breakpoint()
+ commands = ["AAAAAA", "BBBBBB", "CCCCCC"]
+ str_list = lldb.SBStringList()
+ str_list.AppendList(commands, len(commands))
+
+ bkpt.SetCommandLineCommands(str_list)
+ cmd_list = lldb.SBStringList()
+ bkpt.GetCommandLineCommands(cmd_list)
+ list_size = str_list.GetSize()
+ self.assertEqual(cmd_list.GetSize() , list_size, "Added the right number of commands")
+ for i in range(0,list_size):
+ self.assertEqual(str_list.GetStringAtIndex(i), cmd_list.GetStringAtIndex(i), "Mismatched commands.")
+
+ commands = ["DDDDDD", "EEEEEE", "FFFFFF", "GGGGGG"]
+ loc_list = lldb.SBStringList()
+ loc_list.AppendList(commands, len(commands))
+ bkpt.location[1].SetCommandLineCommands(loc_list)
+ loc_cmd_list = lldb.SBStringList()
+ bkpt.location[1].GetCommandLineCommands(loc_cmd_list)
+
+ loc_list_size = loc_list.GetSize()
+
+ # Check that the location has the right commands:
+ self.assertEqual(loc_cmd_list.GetSize() , loc_list_size, "Added the right number of commands to location")
+ for i in range(0,loc_list_size):
+ self.assertEqual(loc_list.GetStringAtIndex(i), loc_cmd_list.GetStringAtIndex(i), "Mismatched commands.")
+
+ # Check that we didn't mess up the breakpoint level commands:
+ self.assertEqual(cmd_list.GetSize() , list_size, "Added the right number of commands")
+ for i in range(0,list_size):
+ self.assertEqual(str_list.GetStringAtIndex(i), cmd_list.GetStringAtIndex(i), "Mismatched commands.")
+
+ # And check we didn't mess up another location:
+ untouched_loc_cmds = lldb.SBStringList()
+ bkpt.location[0].GetCommandLineCommands(untouched_loc_cmds)
+ self.assertEqual(untouched_loc_cmds.GetSize() , 0, "Changed the wrong location")
+
+ def breakpoint_locations_test(self):
+ """Test breakpoint enable/disable for a breakpoint ID with multiple locations."""
+ self.set_breakpoint()
+
# The 'breakpoint disable 3.*' command should fail gracefully.
self.expect("breakpoint disable 3.*",
"Disabling an invalid breakpoint should fail gracefully",
@@ -80,7 +174,7 @@ class BreakpointLocationsTestCase(TestBase):
"1 breakpoint locatons disabled correctly",
startstr="1 breakpoints disabled.")
- # Run the program againt. We should stop on the two breakpoint
+ # Run the program again. We should stop on the two breakpoint
# locations.
self.runCmd("run", RUN_SUCCEEDED)
diff --git a/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_names/TestBreakpointNames.py b/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_names/TestBreakpointNames.py
index cc31ef80e8a32..b95d2cea550ab 100644
--- a/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_names/TestBreakpointNames.py
+++ b/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_names/TestBreakpointNames.py
@@ -17,6 +17,7 @@ from lldbsuite.test import lldbutil
class BreakpointNames(TestBase):
mydir = TestBase.compute_mydir(__file__)
+ NO_DEBUG_INFO_TESTCASE = True
@add_test_categories(['pyapi'])
def test_setting_names(self):
@@ -37,6 +38,25 @@ class BreakpointNames(TestBase):
self.setup_target()
self.do_check_using_names()
+ def test_configuring_names(self):
+ """Use Python APIs to test that configuring options on breakpoint names works correctly."""
+ self.build()
+ self.make_a_dummy_name()
+ self.setup_target()
+ self.do_check_configuring_names()
+
+ def test_configuring_permissions_sb(self):
+ """Use Python APIs to test that configuring permissions on names works correctly."""
+ self.build()
+ self.setup_target()
+ self.do_check_configuring_permissions_sb()
+
+ def test_configuring_permissions_cli(self):
+ """Use Python APIs to test that configuring permissions on names works correctly."""
+ self.build()
+ self.setup_target()
+ self.do_check_configuring_permissions_cli()
+
def setup_target(self):
exe = os.path.join(os.getcwd(), "a.out")
@@ -45,10 +65,36 @@ class BreakpointNames(TestBase):
self.assertTrue(self.target, VALID_TARGET)
self.main_file_spec = lldb.SBFileSpec(os.path.join(os.getcwd(), "main.c"))
+ def check_name_in_target(self, bkpt_name):
+ name_list = lldb.SBStringList()
+ self.target.GetBreakpointNames(name_list)
+ found_it = False
+ for name in name_list:
+ if name == bkpt_name:
+ found_it = True
+ break
+ self.assertTrue(found_it, "Didn't find the name %s in the target's name list:"%(bkpt_name))
+
def setUp(self):
# Call super's setUp().
TestBase.setUp(self)
+ # These are the settings we're going to be putting into names & breakpoints:
+ self.bp_name_string = "ABreakpoint"
+ self.is_one_shot = True
+ self.ignore_count = 1000
+ self.condition = "1 == 2"
+ self.auto_continue = True
+ self.tid = 0xaaaa
+ self.tidx = 10
+ self.thread_name = "Fooey"
+ self.queue_name = "Blooey"
+ self.cmd_list = lldb.SBStringList()
+ self.cmd_list.AppendString("frame var")
+ self.cmd_list.AppendString("bt")
+ self.help_string = "I do something interesting"
+
+
def do_check_names(self):
"""Use Python APIs to check that we can set & retrieve breakpoint names"""
bkpt = self.target.BreakpointCreateByLocation(self.main_file_spec, 10)
@@ -66,11 +112,15 @@ class BreakpointNames(TestBase):
matches = bkpt.MatchesName("NotABreakpoint")
self.assertTrue(not matches, "We matched a name we didn't set.")
+ # Make sure the name is also in the target:
+ self.check_name_in_target(bkpt_name)
+
# Add another name, make sure that works too:
bkpt.AddName(other_bkpt_name)
matches = bkpt.MatchesName(bkpt_name)
self.assertTrue(matches, "Adding a name means we didn't match the name we just set")
+ self.check_name_in_target(other_bkpt_name)
# Remove the name and make sure we no longer match it:
bkpt.RemoveName(bkpt_name)
@@ -89,26 +139,21 @@ class BreakpointNames(TestBase):
def do_check_illegal_names(self):
"""Use Python APIs to check that we reject illegal names."""
bkpt = self.target.BreakpointCreateByLocation(self.main_file_spec, 10)
- success = bkpt.AddName("-CantStartWithADash")
- self.assertTrue(not success,"We allowed a name starting with a dash.")
-
- success = bkpt.AddName("1CantStartWithANumber")
- self.assertTrue(not success, "We allowed a name starting with a number.")
-
- success = bkpt.AddName("^CantStartWithNonAlpha")
- self.assertTrue(not success, "We allowed a name starting with an ^.")
+ bad_names = ["-CantStartWithADash",
+ "1CantStartWithANumber",
+ "^CantStartWithNonAlpha",
+ "CantHave-ADash",
+ "Cant Have Spaces"]
+ for bad_name in bad_names:
+ success = bkpt.AddName(bad_name)
+ self.assertTrue(not success,"We allowed an illegal name: %s"%(bad_name))
+ bp_name = lldb.SBBreakpointName(self.target, bad_name)
+ self.assertFalse(bp_name.IsValid(), "We made a breakpoint name with an illegal name: %s"%(bad_name));
- success = bkpt.AddName("CantHave-ADash")
- self.assertTrue(not success, "We allowed a name with a dash in it.")
+ retval =lldb.SBCommandReturnObject()
+ self.dbg.GetCommandInterpreter().HandleCommand("break set -n whatever -N '%s'"%(bad_name), retval)
+ self.assertTrue(not retval.Succeeded(), "break set succeeded with: illegal name: %s"%(bad_name))
- success = bkpt.AddName("Cant Have Spaces")
- self.assertTrue(not success, "We allowed a name with spaces.")
-
- # Check from the command line as well:
- retval =lldb.SBCommandReturnObject()
- self.dbg.GetCommandInterpreter().HandleCommand("break set -n whatever -N has-dashes", retval)
- self.assertTrue(not retval.Succeeded(), "break set succeeded with: illegal name")
-
def do_check_using_names(self):
"""Use Python APIs to check names work in place of breakpoint ID's."""
@@ -133,9 +178,190 @@ class BreakpointNames(TestBase):
self.assertTrue(not bkpt.IsEnabled(), "We didn't disable the breakpoint.")
# Also make sure we don't apply commands to non-matching names:
- self.dbg.GetCommandInterpreter().HandleCommand("break modify --one-shot 1 %s"%(bkpt_name), retval)
+ self.dbg.GetCommandInterpreter().HandleCommand("break modify --one-shot 1 %s"%(other_bkpt_name), retval)
self.assertTrue(retval.Succeeded(), "break modify failed with: %s."%(retval.GetError()))
self.assertTrue(not bkpt.IsOneShot(), "We applied one-shot to the wrong breakpoint.")
+ def check_option_values(self, bp_object):
+ self.assertEqual(bp_object.IsOneShot(), self.is_one_shot, "IsOneShot")
+ self.assertEqual(bp_object.GetIgnoreCount(), self.ignore_count, "IgnoreCount")
+ self.assertEqual(bp_object.GetCondition(), self.condition, "Condition")
+ self.assertEqual(bp_object.GetAutoContinue(), self.auto_continue, "AutoContinue")
+ self.assertEqual(bp_object.GetThreadID(), self.tid, "Thread ID")
+ self.assertEqual(bp_object.GetThreadIndex(), self.tidx, "Thread Index")
+ self.assertEqual(bp_object.GetThreadName(), self.thread_name, "Thread Name")
+ self.assertEqual(bp_object.GetQueueName(), self.queue_name, "Queue Name")
+ set_cmds = lldb.SBStringList()
+ bp_object.GetCommandLineCommands(set_cmds)
+ self.assertEqual(set_cmds.GetSize(), self.cmd_list.GetSize(), "Size of command line commands")
+ for idx in range(0, set_cmds.GetSize()):
+ self.assertEqual(self.cmd_list.GetStringAtIndex(idx), set_cmds.GetStringAtIndex(idx), "Command %d"%(idx))
+
+ def make_a_dummy_name(self):
+ "This makes a breakpoint name in the dummy target to make sure it gets copied over"
+
+ dummy_target = self.dbg.GetDummyTarget()
+ self.assertTrue(dummy_target.IsValid(), "Dummy target was not valid.")
+
+ def cleanup ():
+ self.dbg.GetDummyTarget().DeleteBreakpointName(self.bp_name_string)
+
+ # Execute the cleanup function during test case tear down.
+ self.addTearDownHook(cleanup)
+
+ # Now find it in the dummy target, and make sure these settings took:
+ bp_name = lldb.SBBreakpointName(dummy_target, self.bp_name_string)
+ # Make sure the name is right:
+ self.assertTrue (bp_name.GetName() == self.bp_name_string, "Wrong bp_name: %s"%(bp_name.GetName()))
+ bp_name.SetOneShot(self.is_one_shot)
+ bp_name.SetIgnoreCount(self.ignore_count)
+ bp_name.SetCondition(self.condition)
+ bp_name.SetAutoContinue(self.auto_continue)
+ bp_name.SetThreadID(self.tid)
+ bp_name.SetThreadIndex(self.tidx)
+ bp_name.SetThreadName(self.thread_name)
+ bp_name.SetQueueName(self.queue_name)
+ bp_name.SetCommandLineCommands(self.cmd_list)
+
+ # Now look it up again, and make sure it got set correctly.
+ bp_name = lldb.SBBreakpointName(dummy_target, self.bp_name_string)
+ self.assertTrue(bp_name.IsValid(), "Failed to make breakpoint name.")
+ self.check_option_values(bp_name)
+
+ def do_check_configuring_names(self):
+ """Use Python APIs to check that configuring breakpoint names works correctly."""
+ other_bp_name_string = "AnotherBreakpointName"
+ cl_bp_name_string = "CLBreakpointName"
+
+ # Now find the version copied in from the dummy target, and make sure these settings took:
+ bp_name = lldb.SBBreakpointName(self.target, self.bp_name_string)
+ self.assertTrue(bp_name.IsValid(), "Failed to make breakpoint name.")
+ self.check_option_values(bp_name)
+
+ # Now add this name to a breakpoint, and make sure it gets configured properly
+ bkpt = self.target.BreakpointCreateByLocation(self.main_file_spec, 10)
+ success = bkpt.AddName(self.bp_name_string)
+ self.assertTrue(success, "Couldn't add this name to the breakpoint")
+ self.check_option_values(bkpt)
+
+ # Now make a name from this breakpoint, and make sure the new name is properly configured:
+ new_name = lldb.SBBreakpointName(bkpt, other_bp_name_string)
+ self.assertTrue(new_name.IsValid(), "Couldn't make a valid bp_name from a breakpoint.")
+ self.check_option_values(bkpt)
+
+ # Now change the name's option and make sure it gets propagated to
+ # the breakpoint:
+ new_auto_continue = not self.auto_continue
+ bp_name.SetAutoContinue(new_auto_continue)
+ self.assertEqual(bp_name.GetAutoContinue(), new_auto_continue, "Couldn't change auto-continue on the name")
+ self.assertEqual(bkpt.GetAutoContinue(), new_auto_continue, "Option didn't propagate to the breakpoint.")
+ # Now make this same breakpoint name - but from the command line
+ cmd_str = "breakpoint name configure %s -o %d -i %d -c '%s' -G %d -t %d -x %d -T '%s' -q '%s' -H '%s'"%(cl_bp_name_string,
+ self.is_one_shot,
+ self.ignore_count,
+ self.condition,
+ self.auto_continue,
+ self.tid,
+ self.tidx,
+ self.thread_name,
+ self.queue_name,
+ self.help_string)
+ for cmd in self.cmd_list:
+ cmd_str += " -C '%s'"%(cmd)
+
+ self.runCmd(cmd_str, check=True)
+ # Now look up this name again and check its options:
+ cl_name = lldb.SBBreakpointName(self.target, cl_bp_name_string)
+ self.check_option_values(cl_name)
+ # Also check the help string:
+ self.assertEqual(self.help_string, cl_name.GetHelpString(), "Help string didn't match")
+ # Change the name and make sure that works:
+ new_help = "I do something even more interesting"
+ cl_name.SetHelpString(new_help)
+ self.assertEqual(new_help, cl_name.GetHelpString(), "SetHelpString didn't")
+
+ # We should have three names now, make sure the target can list them:
+ name_list = lldb.SBStringList()
+ self.target.GetBreakpointNames(name_list)
+ for name_string in [self.bp_name_string, other_bp_name_string, cl_bp_name_string]:
+ self.assertTrue(name_string in name_list, "Didn't find %s in names"%(name_string))
+
+ # Delete the name from the current target. Make sure that works and deletes the
+ # name from the breakpoint as well:
+ self.target.DeleteBreakpointName(self.bp_name_string)
+ name_list.Clear()
+ self.target.GetBreakpointNames(name_list)
+ self.assertTrue(self.bp_name_string not in name_list, "Didn't delete %s from a real target"%(self.bp_name_string))
+ # Also make sure the name got removed from breakpoints holding it:
+ self.assertFalse(bkpt.MatchesName(self.bp_name_string), "Didn't remove the name from the breakpoint.")
+
+ # Test that deleting the name we injected into the dummy target works (there's also a
+ # cleanup that will do this, but that won't test the result...
+ dummy_target = self.dbg.GetDummyTarget()
+ dummy_target.DeleteBreakpointName(self.bp_name_string)
+ name_list.Clear()
+ dummy_target.GetBreakpointNames(name_list)
+ self.assertTrue(self.bp_name_string not in name_list, "Didn't delete %s from the dummy target"%(self.bp_name_string))
+ # Also make sure the name got removed from breakpoints holding it:
+ self.assertFalse(bkpt.MatchesName(self.bp_name_string), "Didn't remove the name from the breakpoint.")
+ def check_permission_results(self, bp_name):
+ self.assertEqual(bp_name.GetAllowDelete(), False, "Didn't set allow delete.")
+ protected_bkpt = self.target.BreakpointCreateByLocation(self.main_file_spec, 10)
+ protected_id = protected_bkpt.GetID()
+
+ unprotected_bkpt = self.target.BreakpointCreateByLocation(self.main_file_spec, 10)
+ unprotected_id = unprotected_bkpt.GetID()
+
+ success = protected_bkpt.AddName(self.bp_name_string)
+ self.assertTrue(success, "Couldn't add this name to the breakpoint")
+
+ self.target.DisableAllBreakpoints()
+ self.assertEqual(protected_bkpt.IsEnabled(), True, "Didnt' keep breakpoint from being disabled")
+ self.assertEqual(unprotected_bkpt.IsEnabled(), False, "Protected too many breakpoints from disabling.")
+
+ # Try from the command line too:
+ unprotected_bkpt.SetEnabled(True)
+ result = lldb.SBCommandReturnObject()
+ self.dbg.GetCommandInterpreter().HandleCommand("break disable", result)
+ self.assertTrue(result.Succeeded())
+ self.assertEqual(protected_bkpt.IsEnabled(), True, "Didnt' keep breakpoint from being disabled")
+ self.assertEqual(unprotected_bkpt.IsEnabled(), False, "Protected too many breakpoints from disabling.")
+
+ self.target.DeleteAllBreakpoints()
+ bkpt = self.target.FindBreakpointByID(protected_id)
+ self.assertTrue(bkpt.IsValid(), "Didn't keep the breakpoint from being deleted.")
+ bkpt = self.target.FindBreakpointByID(unprotected_id)
+ self.assertFalse(bkpt.IsValid(), "Protected too many breakpoints from deletion.")
+
+ # Remake the unprotected breakpoint and try again from the command line:
+ unprotected_bkpt = self.target.BreakpointCreateByLocation(self.main_file_spec, 10)
+ unprotected_id = unprotected_bkpt.GetID()
+
+ self.dbg.GetCommandInterpreter().HandleCommand("break delete -f", result)
+ self.assertTrue(result.Succeeded())
+ bkpt = self.target.FindBreakpointByID(protected_id)
+ self.assertTrue(bkpt.IsValid(), "Didn't keep the breakpoint from being deleted.")
+ bkpt = self.target.FindBreakpointByID(unprotected_id)
+ self.assertFalse(bkpt.IsValid(), "Protected too many breakpoints from deletion.")
+
+ def do_check_configuring_permissions_sb(self):
+ bp_name = lldb.SBBreakpointName(self.target, self.bp_name_string)
+
+ # Make a breakpoint name with delete disallowed:
+ bp_name = lldb.SBBreakpointName(self.target, self.bp_name_string)
+ self.assertTrue(bp_name.IsValid(), "Failed to make breakpoint name for valid name.")
+
+ bp_name.SetAllowDelete(False)
+ bp_name.SetAllowDisable(False)
+ bp_name.SetAllowList(False)
+ self.check_permission_results(bp_name)
+
+ def do_check_configuring_permissions_cli(self):
+ # Make the name with the right options using the command line:
+ self.runCmd("breakpoint name configure -L 0 -D 0 -A 0 %s"%(self.bp_name_string), check=True)
+ # Now look up the breakpoint we made, and check that it works.
+ bp_name = lldb.SBBreakpointName(self.target, self.bp_name_string)
+ self.assertTrue(bp_name.IsValid(), "Didn't make a breakpoint name we could find.")
+ self.check_permission_results(bp_name)
diff --git a/packages/Python/lldbsuite/test/functionalities/breakpoint/global_constructor/Makefile b/packages/Python/lldbsuite/test/functionalities/breakpoint/global_constructor/Makefile
new file mode 100644
index 0000000000000..801c1041bbe16
--- /dev/null
+++ b/packages/Python/lldbsuite/test/functionalities/breakpoint/global_constructor/Makefile
@@ -0,0 +1,8 @@
+LEVEL = ../../../make
+
+DYLIB_NAME := foo
+DYLIB_CXX_SOURCES := foo.cpp
+CXX_SOURCES := main.cpp
+CFLAGS_EXTRAS := -fPIC
+
+include $(LEVEL)/Makefile.rules
diff --git a/packages/Python/lldbsuite/test/functionalities/breakpoint/global_constructor/TestBreakpointInGlobalConstructor.py b/packages/Python/lldbsuite/test/functionalities/breakpoint/global_constructor/TestBreakpointInGlobalConstructor.py
new file mode 100644
index 0000000000000..4dfa03d5fab4e
--- /dev/null
+++ b/packages/Python/lldbsuite/test/functionalities/breakpoint/global_constructor/TestBreakpointInGlobalConstructor.py
@@ -0,0 +1,46 @@
+"""
+Test that we can hit breakpoints in global constructors
+"""
+
+from __future__ import print_function
+
+
+import os
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class TestBreakpointInGlobalConstructors(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+ NO_DEBUG_INFO_TESTCASE = True
+
+ def setUp(self):
+ TestBase.setUp(self)
+ self.line_foo = line_number('foo.cpp', '// !BR_foo')
+ self.line_main = line_number('main.cpp', '// !BR_main')
+
+ @expectedFailureAll(bugnumber="llvm.org/pr35480", oslist=["linux"])
+ def test(self):
+ self.build()
+ exe = os.path.join(os.getcwd(), "a.out")
+ self.runCmd("file %s" % exe)
+
+ bp_main = lldbutil.run_break_set_by_file_and_line(
+ self, 'main.cpp', self.line_main)
+ bp_foo = lldbutil.run_break_set_by_file_and_line(
+ self, 'foo.cpp', self.line_foo)
+
+ self.runCmd("run")
+
+ self.assertIsNotNone(
+ lldbutil.get_one_thread_stopped_at_breakpoint_id(
+ self.process(), bp_foo))
+
+ self.runCmd("continue")
+
+ self.assertIsNotNone(
+ lldbutil.get_one_thread_stopped_at_breakpoint_id(
+ self.process(), bp_main))
diff --git a/packages/Python/lldbsuite/test/functionalities/breakpoint/global_constructor/foo.cpp b/packages/Python/lldbsuite/test/functionalities/breakpoint/global_constructor/foo.cpp
new file mode 100644
index 0000000000000..f959a295467f7
--- /dev/null
+++ b/packages/Python/lldbsuite/test/functionalities/breakpoint/global_constructor/foo.cpp
@@ -0,0 +1,7 @@
+#include "foo.h"
+
+Foo::Foo() : x(42) {
+ bool some_code = x == 42; // !BR_foo
+}
+
+Foo FooObj;
diff --git a/packages/Python/lldbsuite/test/functionalities/breakpoint/global_constructor/foo.h b/packages/Python/lldbsuite/test/functionalities/breakpoint/global_constructor/foo.h
new file mode 100644
index 0000000000000..3bc63fed7555b
--- /dev/null
+++ b/packages/Python/lldbsuite/test/functionalities/breakpoint/global_constructor/foo.h
@@ -0,0 +1,11 @@
+#ifndef FOO_H
+#define FOO_H
+
+struct LLDB_TEST_API Foo {
+ Foo();
+ int x;
+};
+
+extern LLDB_TEST_API Foo FooObj;
+
+#endif
diff --git a/packages/Python/lldbsuite/test/functionalities/breakpoint/global_constructor/main.cpp b/packages/Python/lldbsuite/test/functionalities/breakpoint/global_constructor/main.cpp
new file mode 100644
index 0000000000000..d1c8038dfadbd
--- /dev/null
+++ b/packages/Python/lldbsuite/test/functionalities/breakpoint/global_constructor/main.cpp
@@ -0,0 +1,14 @@
+#include "foo.h"
+
+struct Main {
+ Main();
+ int x;
+};
+
+Main::Main() : x(47) {
+ bool some_code = x == 47; // !BR_main
+}
+
+Main MainObj;
+
+int main() { return MainObj.x + FooObj.x; }