Debugger: Always clear existing breakpoints on setBreakpoints

Fixes: #25063
This commit is contained in:
Ben McMorran
2023-07-12 11:25:12 -07:00
committed by Brad King
parent d769c59d78
commit 60b6383993
3 changed files with 31 additions and 5 deletions

View File

@@ -6,6 +6,7 @@
#include <cstddef>
#include <cstdint>
#include <memory>
#include <utility>
#include <cm3p/cppdap/optional.h>
#include <cm3p/cppdap/session.h>
@@ -78,12 +79,14 @@ cmDebuggerBreakpointManager::HandleSetBreakpointsRequest(
cmSystemTools::GetActualCaseForPath(request.source.path.value());
const dap::array<dap::SourceBreakpoint> defaultValue{};
const auto& breakpoints = request.breakpoints.value(defaultValue);
if (Breakpoints.find(sourcePath) != Breakpoints.end()) {
Breakpoints[sourcePath].clear();
}
response.breakpoints.resize(breakpoints.size());
if (ListFileFunctionLines.find(sourcePath) != ListFileFunctionLines.end()) {
// The file has loaded, we can validate breakpoints.
if (Breakpoints.find(sourcePath) != Breakpoints.end()) {
Breakpoints[sourcePath].clear();
}
response.breakpoints.resize(breakpoints.size());
for (size_t i = 0; i < breakpoints.size(); i++) {
int64_t correctedLine =
CalibrateBreakpointLine(sourcePath, breakpoints[i].line);
@@ -106,7 +109,6 @@ cmDebuggerBreakpointManager::HandleSetBreakpointsRequest(
// The file has not loaded, validate breakpoints later.
ListFilePendingValidations.emplace(sourcePath);
response.breakpoints.resize(breakpoints.size());
for (size_t i = 0; i < breakpoints.size(); i++) {
Breakpoints[sourcePath].emplace_back(NextBreakpointId++,
breakpoints[i].line);
@@ -191,6 +193,15 @@ std::vector<int64_t> cmDebuggerBreakpointManager::GetBreakpoints(
return breakpoints;
}
size_t cmDebuggerBreakpointManager::GetBreakpointCount() const
{
size_t count = 0;
for (auto const& pair : Breakpoints) {
count += pair.second.size();
}
return count;
}
void cmDebuggerBreakpointManager::ClearAll()
{
std::unique_lock<std::mutex> lock(Mutex);

View File

@@ -4,6 +4,7 @@
#include "cmConfigure.h" // IWYU pragma: keep
#include <cstddef>
#include <cstdint>
#include <mutex>
#include <string>
@@ -55,6 +56,7 @@ public:
std::vector<cmListFileFunction> const& functions);
std::vector<int64_t> GetBreakpoints(std::string const& sourcePath,
int64_t line);
size_t GetBreakpointCount() const;
void ClearAll();
};

View File

@@ -51,6 +51,13 @@ static bool testHandleBreakpointRequestBeforeFileIsLoaded()
sourcePath, false);
ASSERT_BREAKPOINT(response.breakpoints[2], 2, sourceBreakpoints[2].line,
sourcePath, false);
ASSERT_TRUE(breakpointManager.GetBreakpointCount() == 3);
// setBreakpoints should override any existing breakpoints
setBreakpointRequest.breakpoints.value().clear();
helper.Client->send(setBreakpointRequest).get();
ASSERT_TRUE(breakpointManager.GetBreakpointCount() == 0);
return true;
}
@@ -103,6 +110,12 @@ static bool testHandleBreakpointRequestAfterFileIsLoaded()
sourcePath, true);
ASSERT_TRUE(notExpectBreakpointEvents.load());
ASSERT_TRUE(breakpointManager.GetBreakpointCount() == 5);
// setBreakpoints should override any existing breakpoints
setBreakpointRequest.breakpoints.value().clear();
helper.Client->send(setBreakpointRequest).get();
ASSERT_TRUE(breakpointManager.GetBreakpointCount() == 0);
return true;
}