summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2023-07-14 12:34:02 (GMT)
committerKitware Robot <kwrobot@kitware.com>2023-07-14 12:34:29 (GMT)
commit78363b4d3cdf354d2ea036241a980c40c5099087 (patch)
tree7264035553e75067af76a03a3458908ca0258810
parentdbbbedb3af7203c36d457450071ee0e195eaf994 (diff)
parent60b6383993013e720092025032a5844caac03111 (diff)
downloadCMake-78363b4d3cdf354d2ea036241a980c40c5099087.zip
CMake-78363b4d3cdf354d2ea036241a980c40c5099087.tar.gz
CMake-78363b4d3cdf354d2ea036241a980c40c5099087.tar.bz2
Merge topic 'debugger-breakpoints' into release-3.27
60b6383993 Debugger: Always clear existing breakpoints on setBreakpoints Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: buildbot <buildbot@kitware.com> Merge-request: !8624
-rw-r--r--Source/cmDebuggerBreakpointManager.cxx21
-rw-r--r--Source/cmDebuggerBreakpointManager.h2
-rw-r--r--Tests/CMakeLib/testDebuggerBreakpointManager.cxx13
3 files changed, 31 insertions, 5 deletions
diff --git a/Source/cmDebuggerBreakpointManager.cxx b/Source/cmDebuggerBreakpointManager.cxx
index 152f0f5..4ae6728 100644
--- a/Source/cmDebuggerBreakpointManager.cxx
+++ b/Source/cmDebuggerBreakpointManager.cxx
@@ -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);
diff --git a/Source/cmDebuggerBreakpointManager.h b/Source/cmDebuggerBreakpointManager.h
index a4e5df5..747722f 100644
--- a/Source/cmDebuggerBreakpointManager.h
+++ b/Source/cmDebuggerBreakpointManager.h
@@ -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();
};
diff --git a/Tests/CMakeLib/testDebuggerBreakpointManager.cxx b/Tests/CMakeLib/testDebuggerBreakpointManager.cxx
index 83734ea..f654442 100644
--- a/Tests/CMakeLib/testDebuggerBreakpointManager.cxx
+++ b/Tests/CMakeLib/testDebuggerBreakpointManager.cxx
@@ -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;
}