summaryrefslogtreecommitdiffstats
path: root/src/core/debugger/gdbstub.h
blob: 1bb638187da815f7b965e1ead0fe16eead48ff2e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// 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 Core {

class System;

class GDBStub : public DebuggerFrontend {
public:
    explicit GDBStub(DebuggerBackend& backend, Core::System& system);
    ~GDBStub() override;

    void Connected() override;
    void Stopped(Kernel::KThread* thread) override;
    std::vector<DebuggerAction> ClientData(std::span<const u8> data) override;

private:
    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);
    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);

private:
    Core::System& system;
    std::unique_ptr<GDBStubArch> arch;
    std::vector<char> current_command;
    std::map<VAddr, u32> replaced_instructions;
    bool no_ack{};
};

} // namespace Core