debugger_interface.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <functional>
  5. #include <span>
  6. #include <vector>
  7. #include "common/common_types.h"
  8. namespace Kernel {
  9. class KThread;
  10. struct DebugWatchpoint;
  11. } // namespace Kernel
  12. namespace Core {
  13. enum class DebuggerAction {
  14. Interrupt, ///< Stop emulation as soon as possible.
  15. Continue, ///< Resume emulation.
  16. StepThreadLocked, ///< Step the currently-active thread without resuming others.
  17. StepThreadUnlocked, ///< Step the currently-active thread and resume others.
  18. ShutdownEmulation, ///< Shut down the emulator.
  19. };
  20. class DebuggerBackend {
  21. public:
  22. virtual ~DebuggerBackend() = default;
  23. /**
  24. * Can be invoked from a callback to synchronously wait for more data.
  25. * Will return as soon as least one byte is received. Reads up to 4096 bytes.
  26. */
  27. virtual std::span<const u8> ReadFromClient() = 0;
  28. /**
  29. * Can be invoked from a callback to write data to the client.
  30. * Returns immediately after the data is sent.
  31. */
  32. virtual void WriteToClient(std::span<const u8> data) = 0;
  33. /**
  34. * Gets the currently active thread when the debugger is stopped.
  35. */
  36. virtual Kernel::KThread* GetActiveThread() = 0;
  37. /**
  38. * Sets the currently active thread when the debugger is stopped.
  39. */
  40. virtual void SetActiveThread(Kernel::KThread* thread) = 0;
  41. };
  42. class DebuggerFrontend {
  43. public:
  44. explicit DebuggerFrontend(DebuggerBackend& backend_) : backend{backend_} {}
  45. virtual ~DebuggerFrontend() = default;
  46. /**
  47. * Called after the client has successfully connected to the port.
  48. */
  49. virtual void Connected() = 0;
  50. /**
  51. * Called when emulation has stopped.
  52. */
  53. virtual void Stopped(Kernel::KThread* thread) = 0;
  54. /**
  55. * Called when emulation is shutting down.
  56. */
  57. virtual void ShuttingDown() = 0;
  58. /*
  59. * Called when emulation has stopped on a watchpoint.
  60. */
  61. virtual void Watchpoint(Kernel::KThread* thread, const Kernel::DebugWatchpoint& watch) = 0;
  62. /**
  63. * Called when new data is asynchronously received on the client socket.
  64. * A list of actions to perform is returned.
  65. */
  66. [[nodiscard]] virtual std::vector<DebuggerAction> ClientData(std::span<const u8> data) = 0;
  67. protected:
  68. DebuggerBackend& backend;
  69. };
  70. } // namespace Core