2026-06-04 05:49:23 +02:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
2025-10-27 20:55:01 +01:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
2022-05-30 19:35:01 -04:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
|
#include <span>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
#include "common/common_types.h"
|
|
|
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
class KThread;
|
2022-06-06 12:56:01 -04:00
|
|
|
struct DebugWatchpoint;
|
|
|
|
|
} // namespace Kernel
|
2022-05-30 19:35:01 -04:00
|
|
|
|
|
|
|
|
namespace Core {
|
|
|
|
|
|
|
|
|
|
enum class DebuggerAction {
|
2026-06-04 05:49:23 +02:00
|
|
|
Interrupt, ///< Stop emulation as soon as possible.
|
|
|
|
|
Continue, ///< Resume emulation.
|
|
|
|
|
ContinueThreads, ///< Resume only specific threads (listed in frontend).
|
|
|
|
|
StepThread, ///< Step the active thread and resume only threads listed in frontend.
|
|
|
|
|
ShutdownEmulation, ///< Shut down the emulator.
|
2022-05-30 19:35:01 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class DebuggerBackend {
|
|
|
|
|
public:
|
2022-06-01 02:27:48 -04:00
|
|
|
virtual ~DebuggerBackend() = default;
|
|
|
|
|
|
2025-10-27 20:55:01 +01:00
|
|
|
/// Can be invoked from a callback to synchronously wait for more data.
|
|
|
|
|
/// Will return as soon as least one byte is received. Reads up to 4096 bytes.
|
2022-05-30 19:35:01 -04:00
|
|
|
virtual std::span<const u8> ReadFromClient() = 0;
|
|
|
|
|
|
2025-10-27 20:55:01 +01:00
|
|
|
/// Can be invoked from a callback to write data to the client.
|
|
|
|
|
/// Returns immediately after the data is sent.
|
2022-05-30 19:35:01 -04:00
|
|
|
virtual void WriteToClient(std::span<const u8> data) = 0;
|
|
|
|
|
|
2025-10-27 20:55:01 +01:00
|
|
|
/// Gets the currently active thread when the debugger is stopped.
|
2022-05-30 19:35:01 -04:00
|
|
|
virtual Kernel::KThread* GetActiveThread() = 0;
|
|
|
|
|
|
2025-10-27 20:55:01 +01:00
|
|
|
/// Sets the currently active thread when the debugger is stopped.
|
2022-05-30 19:35:01 -04:00
|
|
|
virtual void SetActiveThread(Kernel::KThread* thread) = 0;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class DebuggerFrontend {
|
|
|
|
|
public:
|
|
|
|
|
explicit DebuggerFrontend(DebuggerBackend& backend_) : backend{backend_} {}
|
|
|
|
|
|
2022-06-01 02:27:48 -04:00
|
|
|
virtual ~DebuggerFrontend() = default;
|
|
|
|
|
|
2025-10-27 20:55:01 +01:00
|
|
|
/// Called after the client has successfully connected to the port.
|
2022-05-30 19:35:01 -04:00
|
|
|
virtual void Connected() = 0;
|
|
|
|
|
|
2025-10-27 20:55:01 +01:00
|
|
|
/// Called when emulation has stopped.
|
2022-05-30 19:35:01 -04:00
|
|
|
virtual void Stopped(Kernel::KThread* thread) = 0;
|
|
|
|
|
|
2025-10-27 20:55:01 +01:00
|
|
|
/// Called when emulation is shutting down.
|
2022-06-10 09:17:12 -04:00
|
|
|
virtual void ShuttingDown() = 0;
|
|
|
|
|
|
2025-10-27 20:55:01 +01:00
|
|
|
/// Called when emulation has stopped on a watchpoint.
|
2022-06-06 12:56:01 -04:00
|
|
|
virtual void Watchpoint(Kernel::KThread* thread, const Kernel::DebugWatchpoint& watch) = 0;
|
|
|
|
|
|
2025-10-27 20:55:01 +01:00
|
|
|
/// Called when new data is asynchronously received on the client socket.
|
|
|
|
|
/// A list of actions to perform is returned.
|
2022-05-30 19:35:01 -04:00
|
|
|
[[nodiscard]] virtual std::vector<DebuggerAction> ClientData(std::span<const u8> data) = 0;
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
DebuggerBackend& backend;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace Core
|