cmDebuggerExceptionManager.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file LICENSE.rst or https://cmake.org/licensing for details. */
  3. #pragma once
  4. #include "cmConfigure.h" // IWYU pragma: keep
  5. #include <cstddef>
  6. #include <functional>
  7. #include <mutex>
  8. #include <string>
  9. #include <unordered_map>
  10. #include <cm/optional>
  11. #include <cm3p/cppdap/protocol.h>
  12. #include "cmMessageType.h" // IWYU pragma: keep
  13. namespace dap {
  14. class Session;
  15. struct CMakeInitializeResponse;
  16. }
  17. namespace cmDebugger {
  18. struct cmDebuggerException
  19. {
  20. std::string Id;
  21. std::string Description;
  22. };
  23. struct cmDebuggerExceptionFilter
  24. {
  25. std::string Filter;
  26. std::string Label;
  27. };
  28. /** The exception manager. */
  29. class cmDebuggerExceptionManager
  30. {
  31. // Some older C++ standard libraries cannot hash an enum class by default.
  32. struct MessageTypeHash
  33. {
  34. std::size_t operator()(MessageType t) const
  35. {
  36. return std::hash<int>{}(static_cast<int>(t));
  37. }
  38. };
  39. dap::Session* DapSession;
  40. std::mutex Mutex;
  41. std::unordered_map<std::string, bool> RaiseExceptions;
  42. std::unordered_map<MessageType, cmDebuggerExceptionFilter, MessageTypeHash>
  43. ExceptionMap;
  44. cm::optional<cmDebuggerException> TheException;
  45. dap::SetExceptionBreakpointsResponse HandleSetExceptionBreakpointsRequest(
  46. dap::SetExceptionBreakpointsRequest const& request);
  47. dap::ExceptionInfoResponse HandleExceptionInfoRequest();
  48. public:
  49. cmDebuggerExceptionManager(dap::Session* dapSession);
  50. void HandleInitializeRequest(dap::CMakeInitializeResponse& response);
  51. cm::optional<dap::StoppedEvent> RaiseExceptionIfAny(MessageType t,
  52. std::string const& text);
  53. void ClearAll();
  54. };
  55. } // namespace cmDebugger