gdbstub.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <map>
  5. #include <memory>
  6. #include <optional>
  7. #include <string_view>
  8. #include <vector>
  9. #include "core/debugger/debugger_interface.h"
  10. #include "core/debugger/gdbstub_arch.h"
  11. namespace Kernel {
  12. class KProcess;
  13. }
  14. namespace Core::Memory {
  15. class Memory;
  16. }
  17. namespace Core {
  18. class System;
  19. class GDBStub : public DebuggerFrontend {
  20. public:
  21. explicit GDBStub(DebuggerBackend& backend, Core::System& system,
  22. Kernel::KProcess* debug_process);
  23. ~GDBStub() override;
  24. void Connected() override;
  25. void Stopped(Kernel::KThread* thread) override;
  26. void ShuttingDown() override;
  27. void Watchpoint(Kernel::KThread* thread, const Kernel::DebugWatchpoint& watch) override;
  28. std::vector<DebuggerAction> ClientData(std::span<const u8> data) override;
  29. private:
  30. void ProcessData(std::vector<DebuggerAction>& actions);
  31. void ExecuteCommand(std::string_view packet, std::vector<DebuggerAction>& actions);
  32. void HandleVCont(std::string_view command, std::vector<DebuggerAction>& actions);
  33. void HandleQuery(std::string_view command);
  34. void HandleRcmd(const std::vector<u8>& command);
  35. void HandleBreakpointInsert(std::string_view command);
  36. void HandleBreakpointRemove(std::string_view command);
  37. std::vector<char>::const_iterator CommandEnd() const;
  38. std::optional<std::string> DetachCommand();
  39. Kernel::KThread* GetThreadByID(u64 thread_id);
  40. void SendReply(std::string_view data);
  41. void SendStatus(char status);
  42. Kernel::KProcess* GetProcess();
  43. Core::Memory::Memory& GetMemory();
  44. private:
  45. Core::System& system;
  46. Kernel::KProcess* debug_process;
  47. std::unique_ptr<GDBStubArch> arch;
  48. std::vector<char> current_command;
  49. std::map<VAddr, u32> replaced_instructions;
  50. bool no_ack{};
  51. };
  52. } // namespace Core