summaryrefslogtreecommitdiffstats
path: root/Tests/CMakeLib/testDebugger.h
diff options
context:
space:
mode:
authorGlen Chung <kuchung@microsoft.com>2023-03-16 00:50:08 (GMT)
committerBrad King <brad.king@kitware.com>2023-05-30 13:46:12 (GMT)
commita9a592f96e6498da302f8e968be1db0ad3c32123 (patch)
tree0d75f16ee2eae99b1a3f063e575b3f5f8f2ee931 /Tests/CMakeLib/testDebugger.h
parentb0d1ddb7234950374977b83f8dbded806c15b356 (diff)
downloadCMake-a9a592f96e6498da302f8e968be1db0ad3c32123.zip
CMake-a9a592f96e6498da302f8e968be1db0ad3c32123.tar.gz
CMake-a9a592f96e6498da302f8e968be1db0ad3c32123.tar.bz2
cmake: Add debugger
- Depends on cppdap and jsoncpp. - Add --debugger argument to enable the Debugger. - Add --debugger-pipe argument for DAP traffics over named pipes. - Support breakpoints by filenames and line numbers. - Support exception breakpoints. - Call stack shows filenames and line numbers. - Show Cache Variables. - Show the state of currently defined targets, tests and directories with their properties. - Add cmakeVersion to DAP initialize response. - Include unit tests. Co-authored-by: Ben McMorran <bemcmorr@microsoft.com>
Diffstat (limited to 'Tests/CMakeLib/testDebugger.h')
-rw-r--r--Tests/CMakeLib/testDebugger.h99
1 files changed, 99 insertions, 0 deletions
diff --git a/Tests/CMakeLib/testDebugger.h b/Tests/CMakeLib/testDebugger.h
new file mode 100644
index 0000000..8ba21f6
--- /dev/null
+++ b/Tests/CMakeLib/testDebugger.h
@@ -0,0 +1,99 @@
+/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
+ file Copyright.txt or https://cmake.org/licensing for details. */
+#pragma once
+
+#include <memory>
+#include <vector>
+
+#include "cmDebuggerAdapter.h"
+#include "cmDebuggerProtocol.h"
+#include "cmListFileCache.h"
+#include "cmMessenger.h"
+#include <cmcppdap/include/dap/io.h>
+#include <cmcppdap/include/dap/session.h>
+#include <cmcppdap/include/dap/types.h>
+
+#include "testCommon.h"
+
+#define ASSERT_VARIABLE(x, expectedName, expectedValue, expectedType) \
+ do { \
+ ASSERT_TRUE(x.name == expectedName); \
+ ASSERT_TRUE(x.value == expectedValue); \
+ ASSERT_TRUE(x.type.value() == expectedType); \
+ ASSERT_TRUE(x.evaluateName.has_value() == false); \
+ if (std::string(expectedType) == "collection") { \
+ ASSERT_TRUE(x.variablesReference != 0); \
+ } \
+ } while (false)
+
+#define ASSERT_VARIABLE_REFERENCE(x, expectedName, expectedValue, \
+ expectedType, expectedReference) \
+ do { \
+ ASSERT_VARIABLE(x, expectedName, expectedValue, expectedType); \
+ ASSERT_TRUE(x.variablesReference == (expectedReference)); \
+ } while (false)
+
+#define ASSERT_VARIABLE_REFERENCE_NOT_ZERO(x, expectedName, expectedValue, \
+ expectedType) \
+ do { \
+ ASSERT_VARIABLE(x, expectedName, expectedValue, expectedType); \
+ ASSERT_TRUE(x.variablesReference != 0); \
+ } while (false)
+
+#define ASSERT_BREAKPOINT(x, expectedId, expectedLine, sourcePath, \
+ isVerified) \
+ do { \
+ ASSERT_TRUE(x.id.has_value()); \
+ ASSERT_TRUE(x.id.value() == expectedId); \
+ ASSERT_TRUE(x.line.has_value()); \
+ ASSERT_TRUE(x.line.value() == expectedLine); \
+ ASSERT_TRUE(x.source.has_value()); \
+ ASSERT_TRUE(x.source.value().path.has_value()); \
+ ASSERT_TRUE(x.source.value().path.value() == sourcePath); \
+ ASSERT_TRUE(x.verified == isVerified); \
+ } while (false)
+
+class DebuggerTestHelper
+{
+ std::shared_ptr<dap::ReaderWriter> Client2Debugger = dap::pipe();
+ std::shared_ptr<dap::ReaderWriter> Debugger2Client = dap::pipe();
+
+public:
+ std::unique_ptr<dap::Session> Client = dap::Session::create();
+ std::unique_ptr<dap::Session> Debugger = dap::Session::create();
+ void bind()
+ {
+ auto client2server = dap::pipe();
+ auto server2client = dap::pipe();
+ Client->bind(server2client, client2server);
+ Debugger->bind(client2server, server2client);
+ }
+ std::vector<cmListFileFunction> CreateListFileFunctions(const char* str,
+ const char* filename)
+ {
+ cmMessenger messenger;
+ cmListFileBacktrace backtrace;
+ cmListFile listfile;
+ listfile.ParseString(str, filename, &messenger, backtrace);
+ return listfile.Functions;
+ }
+};
+
+class ScopedThread
+{
+public:
+ template <class... Args>
+ explicit ScopedThread(Args&&... args)
+ : Thread(std::forward<Args>(args)...)
+ {
+ }
+
+ ~ScopedThread()
+ {
+ if (Thread.joinable())
+ Thread.join();
+ }
+
+private:
+ std::thread Thread;
+};