Skip to content

VERY experimental Nintendo Switch 2 emulator

C++
1.9 KB
Raw Blame
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later

// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include <map>
#include <memory>
#include <optional>
#include <string_view>
#include <vector>

#include "core/debugger/debugger_interface.h"
#include "core/debugger/gdbstub_arch.h"

namespace Kernel {
class KProcess;
}

namespace Core::Memory {
class Memory;
}

namespace Core {

class System;

struct GDBStub : public DebuggerFrontend {
    explicit GDBStub(DebuggerBackend& backend, Core::System& system, Kernel::KProcess* debug_process);
    ~GDBStub() override;
    void Connected() override;
    void Stopped(Kernel::KThread* thread) override;
    void ShuttingDown() override;
    void Watchpoint(Kernel::KThread* thread, const Kernel::DebugWatchpoint& watch) override;
    std::vector<DebuggerAction> ClientData(std::span<const u8> data) override;
    void ProcessData(std::vector<DebuggerAction>& actions);
    void ExecuteCommand(std::string_view packet, std::vector<DebuggerAction>& actions);
    void HandleVCont(std::string_view command, std::vector<DebuggerAction>& actions);
    void HandleQuery(std::string_view command);
    void HandleRcmd(const std::vector<u8>& command);
    void HandleBreakpointInsert(std::string_view command);
    void HandleBreakpointRemove(std::string_view command);
    std::vector<char>::const_iterator CommandEnd() const;
    std::optional<std::string> DetachCommand();
    Kernel::KThread* GetThreadByID(u64 thread_id);
    void SendReply(std::string_view data);
    void SendStatus(char status);
    Core::System& system;
    Kernel::KProcess* debug_process;
    std::unique_ptr<GDBStubArch> arch;
    std::vector<char> current_command;
    std::map<VAddr, u32> replaced_instructions;
    std::vector<Kernel::KThread*> resume_threads;
    bool no_ack{};
};

} // namespace Core