"""
Test breakpoint commands for a breakpoint ID with multiple locations.
"""
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
class BreakpointLocationsTestCase(TestBase):
@expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24528")
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):
TestBase.setUp(self)
self.line = line_number("main.c", "// Set break point at this line.")
def set_breakpoint(self):
exe = self.getBuildArtifact("a.out")
target = self.dbg.CreateTarget(exe)
self.assertTrue(target, "Target %s is not valid" % (exe))
bkpt = target.BreakpointCreateByLocation("main.c", self.line)
self.assertEqual(bkpt.GetNumLocations(), 3, "Wrong number of locations")
self.expect(
"breakpoint list -f",
"Breakpoint locations shown correctly",
substrs=[
"1: file = 'main.c', line = %d, exact_match = 0, locations = 3"
% self.line
],
patterns=[
"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."""
bkpt = self.set_breakpoint()
bkpt_cond = "1 == 0"
bkpt.SetCondition(bkpt_cond)
self.assertEqual(bkpt.GetCondition(), bkpt_cond, "Successfully set condition")
self.assertEqual(
bkpt.location[0].GetCondition(),
bkpt.GetCondition(),
"Conditions are the same",
)
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",
)
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.",
)
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",
)
bkpt_loc = bkpt.GetLocationAtIndex(0)
value = "MyQueue"
bkpt_loc.SetQueueName(value)
self.assertEqual(
bkpt_loc.GetQueueName(), value, "Successfully set/get bp location QueueName"
)
value = 5
bkpt_loc.SetThreadID(value)
self.assertEqual(
bkpt_loc.GetThreadID(), value, "Successfully set/get bp location ThreadID"
)
value = "1 == 0"
bkpt_loc.SetCondition(value)
self.assertEqual(
bkpt_loc.GetCondition(), value, "Successfully set/get bp location Condition"
)
value = 6
bkpt_loc.SetThreadIndex(value)
self.assertEqual(
bkpt_loc.GetThreadIndex(),
value,
"Successfully set/get bp location ThreadIndex",
)
value = "MyThread"
bkpt_loc.SetThreadName(value)
self.assertEqual(
bkpt_loc.GetThreadName(),
value,
"Successfully set/get bp location ThreadName",
)
value = 5
bkpt_loc.SetIgnoreCount(value)
self.assertEqual(
bkpt_loc.GetIgnoreCount(),
value,
"Successfully set/get bp location IgnoreCount",
)
for value in [True, False]:
bkpt_loc.SetAutoContinue(value)
self.assertEqual(
bkpt_loc.GetAutoContinue(),
value,
"Successfully set/get bp location AutoContinue",
)
for value in [True, False]:
bkpt_loc.SetEnabled(value)
self.assertEqual(
bkpt_loc.IsEnabled(),
value,
"Successfully set/get bp location SetEnabled",
)
set_cmds = lldb.SBStringList()
set_cmds.AppendString("frame var")
set_cmds.AppendString("bt")
bkpt_loc.SetCommandLineCommands(set_cmds)
get_cmds = lldb.SBStringList()
bkpt_loc.GetCommandLineCommands(get_cmds)
self.assertEqual(
set_cmds.GetSize(), get_cmds.GetSize(), "Size of command line commands"
)
for idx, _ in enumerate(set_cmds):
self.assertEqual(
set_cmds.GetStringAtIndex(idx),
get_cmds.GetStringAtIndex(idx),
"Command %d" % (idx),
)
def shadowed_bkpt_command_test(self):
"""Test that options set on the breakpoint and location behave correctly."""
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()
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.",
)
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.",
)
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()
self.expect(
"breakpoint disable 3.*",
"Disabling an invalid breakpoint should fail gracefully",
error=True,
startstr="error: '3' is not a valid breakpoint ID.",
)
self.expect(
"breakpoint disable 1.*",
"All 3 breakpoint locatons disabled correctly",
startstr="3 breakpoints disabled.",
)
self.runCmd("run", RUN_SUCCEEDED)
self.expect(
"process status",
"No stopping on any disabled breakpoint",
patterns=["^Process [0-9]+ exited with status = 0"],
)
self.expect(
"breakpoint enable 1.*",
"All 3 breakpoint locatons enabled correctly",
startstr="3 breakpoints enabled.",
)
self.expect(
"breakpoint enable 1.",
startstr="0 breakpoints enabled.",
)
self.expect(
"breakpoint disable 1.1",
"1 breakpoint locatons disabled correctly",
startstr="1 breakpoints disabled.",
)
self.runCmd("run", RUN_SUCCEEDED)
self.expect(
"thread backtrace",
STOPPED_DUE_TO_BREAKPOINT,
substrs=["stop reason = breakpoint 1."],
)
self.runCmd("process continue")
self.expect(
"thread backtrace",
STOPPED_DUE_TO_BREAKPOINT,
substrs=["stop reason = breakpoint 1."],
)
lldbutil.check_breakpoint(
self,
bpno=1,
expected_locations=3,
expected_resolved_count=2,
expected_hit_count=2,
)
lldbutil.check_breakpoint(
self,
bpno=1,
location_id=1,
expected_location_resolved=False,
expected_location_hit_count=0,
)
lldbutil.check_breakpoint(
self,
bpno=1,
location_id=2,
expected_location_resolved=True,
expected_location_hit_count=1,
)
lldbutil.check_breakpoint(
self,
bpno=1,
location_id=3,
expected_location_resolved=True,
expected_location_hit_count=1,
)