gdbstub.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 Core {
  12. class System;
  13. class GDBStub : public DebuggerFrontend {
  14. public:
  15. explicit GDBStub(DebuggerBackend& backend, Core::System& system);
  16. ~GDBStub() override;
  17. void Connected() override;
  18. void Stopped(Kernel::KThread* thread) override;
  19. void ShuttingDown() override;
  20. void Watchpoint(Kernel::KThread* thread, const Kernel::DebugWatchpoint& watch) override;
  21. std::vector<DebuggerAction> ClientData(std::span<const u8> data) override;
  22. private:
  23. void ProcessData(std::vector<DebuggerAction>& actions);
  24. void ExecuteCommand(std::string_view packet, std::vector<DebuggerAction>& actions);
  25. void HandleVCont(std::string_view command, std::vector<DebuggerAction>& actions);
  26. void HandleQuery(std::string_view command);
  27. void HandleRcmd(const std::vector<u8>& command);
  28. void HandleBreakpointInsert(std::string_view command);
  29. void HandleBreakpointRemove(std::string_view command);
  30. std::vector<char>::const_iterator CommandEnd() const;
  31. std::optional<std::string> DetachCommand();
  32. Kernel::KThread* GetThreadByID(u64 thread_id);
  33. void SendReply(std::string_view data);
  34. void SendStatus(char status);
  35. private:
  36. Core::System& system;
  37. std::unique_ptr<GDBStubArch> arch;
  38. std::vector<char> current_command;
  39. std::map<VAddr, u32> replaced_instructions;
  40. bool no_ack{};
  41. };
  42. } // namespace Core