"""
Test lldb-dap setBreakpoints request
"""
import dap_server
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
import lldbdap_testcase
class TestDAP_setFunctionBreakpoints(lldbdap_testcase.DAPTestCaseBase):
@skipIfWindows
def test_set_and_clear(self):
"""Tests setting and clearing function breakpoints.
This packet is a bit tricky on the debug adaptor side since there
is no "clearFunction Breakpoints" packet. Function breakpoints
are set by sending a "setFunctionBreakpoints" packet with zero or
more function names. If function breakpoints have been set before,
any existing breakpoints must remain set, and any new breakpoints
must be created, and any breakpoints that were in previous requests
and are not in the current request must be removed. This function
tests this setting and clearing and makes sure things happen
correctly. It doesn't test hitting breakpoints and the functionality
of each breakpoint, like 'conditions' and 'hitCondition' settings.
"""
program = self.getBuildArtifact("a.out")
self.build_and_launch(program)
bp_id_12 = None
functions = ["twelve"]
response = self.dap_server.request_setFunctionBreakpoints(functions)
if response:
breakpoints = response["body"]["breakpoints"]
self.assertEqual(
len(breakpoints),
len(functions),
"expect %u source breakpoints" % (len(functions)),
)
for breakpoint in breakpoints:
bp_id_12 = breakpoint["id"]
self.assertTrue(breakpoint["verified"], "expect breakpoint verified")
functions.append("thirteen")
response = self.dap_server.request_setFunctionBreakpoints(functions)
if response:
breakpoints = response["body"]["breakpoints"]
self.assertEqual(
len(breakpoints),
len(functions),
"expect %u source breakpoints" % (len(functions)),
)
for breakpoint in breakpoints:
self.assertTrue(breakpoint["verified"], "expect breakpoint verified")
functions.remove("thirteen")
response = self.dap_server.request_setFunctionBreakpoints(functions)
if response:
breakpoints = response["body"]["breakpoints"]
self.assertEqual(
len(breakpoints),
len(functions),
"expect %u source breakpoints" % (len(functions)),
)
for breakpoint in breakpoints:
bp_id = breakpoint["id"]
self.assertEqual(
bp_id, bp_id_12, 'verify "twelve" breakpoint ID is same'
)
self.assertTrue(
breakpoint["verified"], "expect breakpoint still verified"
)
response = self.dap_server.request_testGetTargetBreakpoints()
if response:
breakpoints = response["body"]["breakpoints"]
self.assertEqual(
len(breakpoints),
len(functions),
"expect %u source breakpoints" % (len(functions)),
)
for breakpoint in breakpoints:
bp_id = breakpoint["id"]
self.assertEqual(
bp_id, bp_id_12, 'verify "twelve" breakpoint ID is same'
)
self.assertTrue(
breakpoint["verified"], "expect breakpoint still verified"
)
functions = []
response = self.dap_server.request_setFunctionBreakpoints(functions)
if response:
breakpoints = response["body"]["breakpoints"]
self.assertEqual(
len(breakpoints),
len(functions),
"expect %u source breakpoints" % (len(functions)),
)
response = self.dap_server.request_testGetTargetBreakpoints()
if response:
breakpoints = response["body"]["breakpoints"]
self.assertEqual(
len(breakpoints),
len(functions),
"expect %u source breakpoints" % (len(functions)),
)
@skipIfWindows
def test_functionality(self):
"""Tests hitting breakpoints and the functionality of a single
breakpoint, like 'conditions' and 'hitCondition' settings."""
program = self.getBuildArtifact("a.out")
self.build_and_launch(program)
functions = ["twelve"]
breakpoint_ids = self.set_function_breakpoints(functions)
self.assertEqual(len(breakpoint_ids), len(functions), "expect one breakpoint")
self.continue_to_breakpoints(breakpoint_ids)
i = int(self.dap_server.get_local_variable_value("i"))
self.assertEqual(i, 0, "i != 0 after hitting breakpoint")
new_breakpoint_ids = self.set_function_breakpoints(functions, condition="i==4")
self.assertEqual(
breakpoint_ids,
new_breakpoint_ids,
"existing breakpoint should have its condition " "updated",
)
self.continue_to_breakpoints(breakpoint_ids)
i = int(self.dap_server.get_local_variable_value("i"))
self.assertEqual(i, 4, "i != 4 showing conditional works")
new_breakpoint_ids = self.set_function_breakpoints(functions, hitCondition="2")
self.assertEqual(
breakpoint_ids,
new_breakpoint_ids,
"existing breakpoint should have its condition " "updated",
)
self.continue_to_breakpoints(breakpoint_ids)
i = int(self.dap_server.get_local_variable_value("i"))
self.assertEqual(i, 6, "i != 6 showing hitCondition works")
self.continue_to_breakpoints(breakpoint_ids)
i = int(self.dap_server.get_local_variable_value("i"))
self.assertEqual(i, 7, "i != 7 showing post hitCondition hits every time")