cmDebuggerExceptionManager.h 1.7 KB

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